Interrupt handlers occur asynchronously and hence cannot be called by other functions. Then, why do interrupt handle开发者_开发百科rs in the linux kernel return a value ? How are the input arguments passed to it ?
Interrupt handlers have a return value for a couple of reasons.
- 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.
- 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.
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
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.
精彩评论