Interrupt handling - Linux

Arun KS getarunks at gmail.com
Thu Nov 29 06:14:34 EST 2012


Hello Manty,

On Wed, Nov 28, 2012 at 8:10 PM, manty kuma <mantykuma at gmail.com> wrote:
>
> In linux interrupt programming, we do request_irq(...) in this function, the first argument is irq number. If i am not wrong, this is the interrupt line that we are requesting from kernel. For one particular hardware, is this IRQ line fixed or can it register on any line based on the availability? The concept is not clear. Kindly explain. Also, when i do interrupt programming for AVR or ARM, all the peripherals are having fixed IRQ numbers. and they are having handlers. There is no concept of interrupt lines as such. So my second question is how are IRQ lines and IRQ numbers related?

Interrupt controller(GIC in case of ARM) are capable of handling
certain number of interrupt lines(say 0 to n_hw_irq). Let’s call
n_hw_irq as hardware irq numbers.
Whenever an interrupt comes from any peripherals, GIC receives the
interrupt. And GIC interrupts the ARM through IRQ line.
ARM will jump into its interrupt vector. ARM will jump to the same
vector if interrupted through irq line,even if interrupt comes from
UART, GPIO or whatever hardware peripheral it is.

Now ARM will read GIC's register(Interrupt Acknowledge Register) to
find out the n_hw_irq number. And call the registered ISR(done through
request_irq).
Till here your irq number passed to the request_irq() matches with
interrupt line number of gic.

There are software interrupt numbers as well.
Consider the scenario of gpio. There can be more than 100 gpios in a
system. Each gpio does not have their own hardware interrupt number(ie
n_hw_irq). But a gpio bank will have one. There can be 32 gpios in a
bank. So for total of 128 gpios we have 4 interrupt lines to GIC.
But all the 128 gpios have “virtual” irq numbers “in software”.

So how does software irq numbers work then?
There should be a software logic to decode which gpio was actually
interrupted by reading the GPIO controller registers.

Every interrupt number in Linux has an struct irq_desc.
struct irq_desc {
         irq_flow_handler_t      handle_irq;
         struct irqaction        *action;
         .............
};

struct irqaction {
        irq_handler_t           handler;
        int                     irq;

        ...................

 };

handle_irq will be called by the gic driver whenever one interrupt
line is activated.

File: "arch/arm/common/gic.c"

handle_IRQ(irqnr, regs);

 This function finds out if it has any software interrupt number to
decode or not and call the corresponding handler in its irqaction.


Lets take the example of a gpio interrupt 5 in bank 2.

handle_irq of the bank 2 will be called. Now handle_irq read the GPIO
controller registers to find out which gpio in the bank has caused the
interrupt. And convert the gpio number into irq number(this is what
you registered through request_irq).  Then call the handler in its
irqaction.


Hope this gives some clue.

Thanks,
Arun


>
> Thanks,
> Sandeep
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



More information about the Kernelnewbies mailing list