2

Interrupt handlers occur asynchronously and hence cannot be called by other functions. Then, why do interrupt handlers in the linux kernel return a value ? How are the input arguments passed to it ?

Bandicoot
  • 3,811
  • 7
  • 35
  • 39

3 Answers3

4

Interrupt handlers have a return value for a couple of reasons.

  1. Interrupt vectors can be shared between multiple devices. By returning IRQ_NONE/IRQ_HANDLED, an interrupt handler can indicate that the interrupt was/was not from the device it is specifically interested in. If IRQ_NONE is returned, the next handler in the list should be called.
  2. Even if the IRQ is not shared, an interrupt handler can indicate to the interrupt subsystem that there were problems handling the interrupt and that it should be disabled to prevent system hangs from an irq loop.
MikeK
  • 702
  • 4
  • 11
  • `IRQ_WAKE_THREAD` may also be used for deferred handling on more recent Linux kernel. Ie, it indicates that the current process may be interrupted to do a *slow* portion of an interrupt. – artless noise Nov 19 '14 at 20:57
  • Is it that returning IRQ_HANDLED from the irq handler will result in aknowledge of the interrupt, i.e. clearing the irq line ? – ransh Dec 02 '19 at 06:07
1

Interrupt handlers are not interrupt vector. Interrupt vector is the code the processor jumps to when an interrupt is triggered. This is a gross simplification, but here is how it looks :

  interrupt_vector {
    num = check_interrupt_number()
    f = get_interrupt_handler_func(num);
    d = get_interrupt_handler_data(num);
    /* call interrupt handler */
    ret = f(d);
  }

So handler and data are registered together, and the interrupt vector code call the registererd handler, passing the registered data, and checks the return value. Of course, here we have a single level of handler, but you can have several, with for example one handler for all PCI Irq, that in turns checks for registered handler for a specific PCI irq and eventually calls itn passing registered data etc...

Of course, real code tends to be much more complicated. You can try this lxr link to navigate through the linux kernel sources

shodanex
  • 14,975
  • 11
  • 57
  • 91
0

Interrupt vector code vs. multiple attached interrupt handlers (OS-specific) to an interrupt—handlers can return a value (which typically goes into a register like EAX on x86), so that vector code can manage a chain of handlers.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574