Arjan van de Ven <arjan@xxxxxxxxxxxxx> wrote:
On Sun, 2006-01-08 at 23:03 -0800, Rajaram Suryanarayanan wrote:
> Hi,
>
> I am confused about the mapping between devices, IRQs and the
> handlers. I am following Robert Love's "Linux Kernel Development"
> book.
>
> 1. I see that different handlers can share the same IRQ with SA_SHIRQ
> flag. So does it mean there can be different interrupt handlers for
> the same device...?
No...
> As I think each device has a unique IRQ ( strict 1-to-1 mapping
> between device and its IRQ ).
> 2. Related to the first question, can different devices share the same
> IRQ ?
... because the answer to this is yes.
Shared irq means that multiple physical devices can share the same irq
number, and the cpu cannot distinguish which of the devices caused the
irq when the irq arrives, so the kernel has to call all known handlers
for that specific IRQ number to be safe.
For example, a serial card and a IDE controller both share IRQ number
11. When IRQ number 11 comes in, the cpu can't know if the irq came from
the serial card or the IDE controller. The core kernel thus can't know
either, so to be sure the kernel will call both the serial drivers irq
handler AND the IDE controller IRQ handler.
To deal with this in your IRQ handler, you need to first test if the IRQ
was actually for you, by asking your device if there was an event. (how
to do that is different for each device, otherwise the kernel could have
done it ;)
><Raja>Thanks for the informative response. I have few more questions.My question is based on the paragraph from Robert Love book. Please find the paragraph given below."static irqreturn_t intr_handler(int irq, void *dev_id, struct pt_regs *regs)<snip>The second parameter dev_id, is a generic pointer to the same dev_id that was given to request_irq() when the handler was registered. If this value is unique ( which is recommended to support sharing ), it can act as a cookie to differentiate between multiple devices potentially using the same interrupt handler. <snip> Because the device structure is both unique to each device and potentially useful to have within the handler, it is typically passed for dev_id."Now my questions.Suppose two devices A ( IRQ1 ) and B ( IRQ2 ) share the same handler handler1.Then according to the above description, handler1 distinguishes between the devices by the dev_id passed to it. And also it is the same dev_id that was passed to request_irq() when the handler was registered.1. But handler1 would have been registered by calling request_irq() with dev_id as NULL ( because NULL would be passed if the line is not shared with another handler ). So how handler1 will differentiate between the devices if NULL was passed to it ?Or is it like handler1 should be registered twice ( one for each device ) with the corresponding dev_id in each call to request_irq() , and the kernel will call the handler with the correct dev_id ?2. Also as the dev_id is passed to the interrupt handler when it is invoked , why should the kernel call all handlers on a particular IRQ ? Rather, it can call the handler which has registered for that device ?Please explain.Thanks.<Raja>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Yahoo! DSL Something to write home about. Just $16.99/mo. or less