0

I am trying to identify the interrupt used for the USB keyboard in Linux Debian. After pulling out my USB keyboad then plugging it back in dmesg shows me this:

[11614.703111] usb 3-5: new low-speed USB device number 6 using xhci_hcd
[11614.865981] usb 3-5: New USB device found, idVendor=03f0, idProduct=0024, bcdDevice= 1.30
[11614.865986] usb 3-5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[11614.865987] usb 3-5: Product: HP Basic USB Keyboard
[11614.865988] usb 3-5: Manufacturer: CHICONY
[11614.874343] input: CHICONY HP Basic USB Keyboard as /devices/pci0000:00/0000:00:14.0/usb3/3-5/3-5:1.0/0003:03F0:0024.0004/input/input18
[11614.931239] hid-generic 0003:03F0:0024.0004: input,hidraw0: USB HID v1.11 Keyboard [CHICONY HP Basic USB Keyboard] on usb-0000:00:14.0-5/input0

So the first line:

[11614.703111] usb 3-5: new low-speed USB device number 6 using xhci_hcd

tells me it is using xhci_hcd

cat /proc/interrupts shows me:

           CPU0       CPU1       CPU2       CPU3       
  0:          8          0          0          0   IO-APIC   2-edge      timer
  8:          0          1          0          0   IO-APIC   8-edge      rtc0
  9:          0        162          0          0   IO-APIC   9-fasteoi   acpi
 18:          0          0          0          2   IO-APIC  18-fasteoi   i801_smbus
 20:          0          0         64          0   IO-APIC  20-fasteoi   ehci_hcd:usb1
 23:         82          0          0          0   IO-APIC  23-fasteoi   ehci_hcd:usb2
 27:          0     650883          0          0  PCI-MSI-0000:00:14.0   0-edge      xhci_hcd
 28:          0          0      66605          0  PCI-MSI-0000:00:1f.2   0-edge      ahci[0000:00:1f.2]
 29:          0          0          0     159157  PCI-MSIX-0000:03:00.0   0-edge      enp3s0
 30:          0          0          0     322094  PCI-MSI-0000:00:02.0   0-edge      i915
 31:         16          0          0          0  PCI-MSI-0000:00:16.0   0-edge      mei_me
 32:          0        178          0          0  PCI-MSI-0000:00:03.0   0-edge      snd_hda_intel:card0
 33:          0          0        534          0  PCI-MSI-0000:00:1b.0   0-edge      snd_hda_intel:card1
NMI:         94         96         89        108   Non-maskable interrupts
LOC:    5368769    1507714    1256607   10547240   Local timer interrupts
SPU:          0          0          0          0   Spurious interrupts
PMI:         94         96         89        108   Performance monitoring interrupts
IWI:      36845      36878      37537     325227   IRQ work interrupts
RTR:          0          0          0          0   APIC ICR read retries
RES:     204443     205158     195796     182874   Rescheduling interrupts
CAL:     692129     737982     706767     684310   Function call interrupts
TLB:     512214     552127     541894     518037   TLB shootdowns
TRM:          0          0          0          0   Thermal event interrupts
THR:          0          0          0          0   Threshold APIC interrupts
DFR:          0          0          0          0   Deferred Error APIC interrupts
MCE:          0          0          0          0   Machine check exceptions
MCP:         47         48         48         48   Machine check polls
ERR:          0
MIS:          0
PIN:          0          0          0          0   Posted-interrupt notification event
NPI:          0          0          0          0   Nested posted-interrupt event
PIW:          0          0          0          0   Posted-interrupt wakeup event

So is interrupt 27 being used for the USB keyboard? If it is why am I unable to:

    int ret = request_irq(irq_number, my_interrupt_handler, irq_flags, devname, dev_id);

Full code is below:

#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/delay.h>

static int counter = 0;

// Define your interrupt handler function irqreturn_t my_interrupt_handler(int irq, void *dev_id) { // Your interrupt handling code here //printk(KERN_INFO "key pressed\n")
pr_info("Keypress Counter:%d\n", counter++); return IRQ_HANDLED; }

// Module initialization function static int __init my_init(void) { int irq_number = 27; // IRQ number const char devname = "my_device"; // Device name, can be used for identifying the interrupt source unsigned long irq_flags = IRQF_SHARED; // Flags for interrupt handling, modify as needed void dev_id = NULL; // Device identification, can be a pointer to device-specific data

// Register the interrupt handler
int ret = request_irq(irq_number, my_interrupt_handler, irq_flags, devname, dev_id);
if (ret) {
    printk(KERN_ERR &quot;Failed to register IRQ %d\n&quot;, irq_number);
    pr_info(&quot;%s: In init\n&quot;, __func__);
    return ret;
}

printk(KERN_INFO &quot;Interrupt handler registered successfully\n&quot;);
return 0;

}

// Module exit function static void __exit my_exit(void) { int irq_number = 27; // IRQ number void *dev_id = NULL; // Device identification

// Unregister the interrupt handler
free_irq(irq_number, dev_id);

printk(KERN_INFO &quot;Interrupt handler unregistered\n&quot;);

}

// Module initialization and exit macros module_init(my_init); module_exit(my_exit);

// Module metadata MODULE_LICENSE("GPL");

u1686_grawity request_irq is a function in the Linux kernel used to request an interrupt line. It can be used with both legacy IRQs and MSI-X (Message Signaled Interrupts Extended).

For legacy IRQs, you typically specify the IRQ number directly. For MSI-X interrupts, you usually specify the MSI-X vector number, which is used to request the corresponding interrupt line.

The request_irq function has been adapted to work with modern interrupt mechanisms like MSI-X to accommodate the evolving hardware architectures and support newer features efficiently.

So, yes, request_irq does work with MSI-X interrupts along with legacy IRQs in the Linux kernel.

0 Answers0