Interrupt handling on an SMP ARM system with a GIC
Asked Answered
R

1

1

I wanted to know how interrupt handling works from the point any device is interrupted.I know of interrupt handling in bits and pieces and would like to have clear end to end picture of interrupt handing.Let me put across what little I know about interrupt handling.

Suppose an FPGA device is interrupted through electrical lines and get some data .Device driver for this FPGA device already had code (Interrupt handler) registered using request_irq function.

So now FPGA device have an IRQ line which it get after to call request_irq ,using this IRQ line device send data to the General Interrupt controller and GIC will do many to one translation of IRQ lines and send the signal to CPU core which then call below minimal code

IRQ_handler
SUB       lr, lr, #4       ; modify LR
SRSFD     #0x12!           ; store SPSR and LR to IRQ mode stack
PUSH      {r0-r3, r12}     ; store AAPCS registers on to the IRQ mode stack
BL        IRQ_handler_to_specific_device
POP       {r0-r3, r12}     ; restore registers
RFEFD     sp!              ; and return from the exception using pre-modified LR 

IRQ_handler_to_specific_device is nothing is what we registered in Device driver using request_irq() call.

I still don't how CPU core comes to know about the interrupt source?(from which device interrupt is coming)

Also what is role of call like do_irq and shared interrupts works?

Need some help in understanding end to end picture on how interrupts are handled on ARM architecture?

Readus answered 16/4, 2014 at 11:17 Comment(2)
Cortex A Series's programmer guide has a nice section about handling IRQs, plus you would probably either need to read GIC spec or vendors' own implementation of IRQ block's docs. (like you may find on cortex-A8s)Diep
Thanks @artlessnoise couldn't ask much but honestly saying I would simply looking for simple end to end interrupt handling.Figure in given link would better suggest it what I'm looking for makelinux.net/books/lkd2/ch06lev1sec6 .Also,Please let me know is whatever understanding I put in question correct?Readus
J
4

The GIC is divided into two sections. The first is called the distributor. This is global to the system. It has several interrupt sources physically routed to it; although it maybe within an SOC package. The second section is replicated per-CPU and it called the cpu interface. The distributor has logic on how to distribute the shared peripheral interrupts or SPI. These are the type of interrupt your question is asking about. They are global hardware interrupts.

In the context of Linux, this is implemented in irq-gic.c. There is some documentation in gic.txt. Of specific interest,

  • reg : Specifies base physical address(s) and size of the GIC registers. The first region is the GIC distributor register base and size. The 2nd region is the GIC cpu interface register base and size.

The distributor must be accessed globally, so care must be taken to manage it's registers. The CPU interface has the same physical address for each CPU, but each CPU has a separate implementation. The distributor can be set up to route interrupts to specific CPUs (including multiples). See: gic_set_affinity() for example. It is also possible for any CPU to handle the interrupt. The ACK register will allocate IRQ; the first CPU to read it, gets the interrupt. If multiple IRQs pend and there are two ACK reads from different CPUs, then each will get a different interrupt. A third CPU reading would get a spurious IRQ.

As well, each CPU interface has some private interrupt sources, that are used for CPU-to-CPU interrupts as well as private timers and the like. But I believe the focus of the question is how a physical peripheral (unique to a system) gets routed to a CPU in an SMP system.

Jamey answered 16/4, 2014 at 18:29 Comment(4)
@artness with your answer and this link linuxburps.blogspot.in/2013/10/linux-interrupt-handling.html able to map interrupt handling on Linux and I guess handle_irq_event_percpu() is fucntion from GIC.Readus
The Linuxburps blogspot is a better link than the other one. There are different irqchip drivers and some ARM specific code and then Linux generic code; the irq-gic.c is the GIC irqchip driver. Some of the generic code is specialized depending on the CPU features (ARM).Jamey
I have tried to go through GIC specs but I couldn't find out how any device is interfaced with GIC and How GIC will capture interrupt coming from any device on physical electrical lines.Could you provide me the link of docs for the same?Readus
The GIC is a soft hardware. An SOC implementer will hook up the physical lines. You have to read the specific chip documentation to put this together. Ie, what particular CPU/Chip is used will define this, not the GIC. The GIC is even configurable by the SOC implementer, so the number of interrupts, etc. can vary. Really, people need to know VHDL or Verilog to understand some of the ARM documentation. I feel your pain.Jamey

© 2022 - 2024 — McMap. All rights reserved.