* Interrupt handling - Linux
@ 2012-11-28 14:40 manty kuma
2012-11-29 10:15 ` anish kumar
2012-11-29 11:14 ` Arun KS
0 siblings, 2 replies; 4+ messages in thread
From: manty kuma @ 2012-11-28 14:40 UTC (permalink / raw)
To: kernelnewbies
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?
Thanks,
Sandeep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20121128/04f2e526/attachment.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Interrupt handling - Linux
2012-11-28 14:40 Interrupt handling - Linux manty kuma
@ 2012-11-29 10:15 ` anish kumar
2012-11-29 11:18 ` Lee Jones
2012-11-29 11:14 ` Arun KS
1 sibling, 1 reply; 4+ messages in thread
From: anish kumar @ 2012-11-29 10:15 UTC (permalink / raw)
To: manty kuma
Cc: kernelnewbies, Linus Walleij, linux-kernel, Thomas Gleixner,
Rob Herring, Paul Mundt, Russell King, Linus Walleij, Lee Jones,
Anmar Oueja
On Wed, 2012-11-28 at 20:10 +0530, manty kuma 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
Right.
> particular hardware, is this IRQ line fixed or can it register on any
> line based on the availability? The concept is not clear. Kindly
In linux there are two concepts related to interrupt which is never
clearly mentioned anywhere(at least not that I know of) and that is why
let me clarify.
1. Hardware interrupt number.Given by your irq controller or the
hardware which is capable of generating the interrupts.
2. Software interrupt number assigned by linux interrupt handling core.
So the first question which arises in mind is: why does linux generates
the software interrupt number?Won't hardware interrupt number be enough
to keep everyone happy?
Simple reason is just for book keeping as the software interrupt numbers
generated would be linear as we are in control of what numbers to
allocate and if we start using the numbers generated by irq controller
which can generate random numbers then searching and indexing would
require expensive operations as compared to working in linear
domain(experts can add more here if I am not to the point).
However if your irq controller is capable of choosing the interrupt
numbers then linux irq number will be same as hardware interrupt number.
So let's come back to the question.So for a particular hardware the
hardware interrupt line would be always fixed as well as the software
interrupt numbers generated by the linux irq core.
> 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?
IRQ lines are connected to irq controller and you should have a look at
the driver of your irq controller as to how does it assign the hardware
irq numbers(probably by reading some registers).All the peripherals are
connected to the irq controller such as keyboard and mouse and they have
fixed irq lines.Once a signal is asserted the irq controller raises an
interrupt to arm core and arm core in turn raises a hardware
interrupt.This hardware interrupt will call into linux irq handling
code.Which interrupt handler to be called is already decided by the
individual drivers, remember they have called request_irq with an
interrupt number.
This interrupt number would be a software interrupt number as explained
before and this number to hardware interrupt number association is done
by the interrupt controller or the chip driver which is capable of
taking(handling) one interrupt and calling individual interrupt handlers
after reading the corresponding registers(read handle_nested_irq).
This conversion of hardware interrupt number to software interrupt
number is done in /kernel/irq/irqdomain.c file.
PS:I may be wrong but this description is from what I have read in the
code.Please do point out any mistakes.
>
>
> Thanks,
> Sandeep
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 4+ messages in thread
* Interrupt handling - Linux
2012-11-28 14:40 Interrupt handling - Linux manty kuma
2012-11-29 10:15 ` anish kumar
@ 2012-11-29 11:14 ` Arun KS
1 sibling, 0 replies; 4+ messages in thread
From: Arun KS @ 2012-11-29 11:14 UTC (permalink / raw)
To: kernelnewbies
Hello Manty,
On Wed, Nov 28, 2012 at 8:10 PM, manty kuma <mantykuma@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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Interrupt handling - Linux
2012-11-29 10:15 ` anish kumar
@ 2012-11-29 11:18 ` Lee Jones
0 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2012-11-29 11:18 UTC (permalink / raw)
To: anish kumar
Cc: manty kuma, kernelnewbies, Linus Walleij, linux-kernel,
Thomas Gleixner, Rob Herring, Paul Mundt, Russell King,
Linus Walleij, Anmar Oueja
On Thu, 29 Nov 2012, anish kumar wrote:
> On Wed, 2012-11-28 at 20:10 +0530, manty kuma 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
> Right.
> > particular hardware, is this IRQ line fixed or can it register on any
> > line based on the availability? The concept is not clear. Kindly
> In linux there are two concepts related to interrupt which is never
> clearly mentioned anywhere(at least not that I know of) and that is why
> let me clarify.
Documentation/IRQ-domain.txt
> 1. Hardware interrupt number.Given by your irq controller or the
> hardware which is capable of generating the interrupts.
> 2. Software interrupt number assigned by linux interrupt handling core.
>
> So the first question which arises in mind is: why does linux generates
> the software interrupt number?Won't hardware interrupt number be enough
> to keep everyone happy?
>
> Simple reason is just for book keeping as the software interrupt numbers
> generated would be linear as we are in control of what numbers to
> allocate and if we start using the numbers generated by irq controller
> which can generate random numbers then searching and indexing would
> require expensive operations as compared to working in linear
> domain(experts can add more here if I am not to the point).
>
> However if your irq controller is capable of choosing the interrupt
> numbers then linux irq number will be same as hardware interrupt number.
>
> So let's come back to the question.So for a particular hardware the
> hardware interrupt line would be always fixed as well as the software
> interrupt numbers generated by the linux irq core.
>
> > 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?
> IRQ lines are connected to irq controller and you should have a look at
> the driver of your irq controller as to how does it assign the hardware
> irq numbers(probably by reading some registers).All the peripherals are
> connected to the irq controller such as keyboard and mouse and they have
> fixed irq lines.Once a signal is asserted the irq controller raises an
> interrupt to arm core and arm core in turn raises a hardware
> interrupt.This hardware interrupt will call into linux irq handling
> code.Which interrupt handler to be called is already decided by the
> individual drivers, remember they have called request_irq with an
> interrupt number.
> This interrupt number would be a software interrupt number as explained
> before and this number to hardware interrupt number association is done
> by the interrupt controller or the chip driver which is capable of
> taking(handling) one interrupt and calling individual interrupt handlers
> after reading the corresponding registers(read handle_nested_irq).
> This conversion of hardware interrupt number to software interrupt
> number is done in /kernel/irq/irqdomain.c file.
>
> PS:I may be wrong but this description is from what I have read in the
> code.Please do point out any mistakes.
> >
> >
> > Thanks,
> > Sandeep
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
--
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-29 11:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-28 14:40 Interrupt handling - Linux manty kuma
2012-11-29 10:15 ` anish kumar
2012-11-29 11:18 ` Lee Jones
2012-11-29 11:14 ` Arun KS
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.