January 3, 2017

Interrupts - the ARM GIC (Generic Interrupt Controller)

The Allwinner H3 contains an ARM GIC (version 2). This has two sections. There is the "distributor" and a possibly "banked" per CPU section. By "banked" what is meant is that each core has its own CPU section, but it appears at the same address for each CPU. Parts of the distributor are banked (the control registers for SGI and PPI. The Allwinner H3 docs simply list the numbering of the interrupt sources feeding the GIC. There are 157 of these, numbered 0-156. A few of interest:
0-15  SGI 0-15
16-31 PPI 0-15
32   UART 0
50   Timer 0
114  Ethernet (Emac)
SGI are used for interprocessor communication and are generated by writing to the SGIR ("soft").

Don't forget about ARM interrupt basics

Some vital things are: The LR register is banked, but this does not mean you are free to trash it! The banked copy holds PC+4 for the return, so you must save it. Similarly the banked copy of SP is switched to, but you had better have placed a value there previously or put one there on each interrupt (which hardly seems like a good idea). So set up SP prior to the interrupt.

Interrupts under linux (Armbian)

In the 3.4.113 linux sources, the GIC is handled by: More modern linux distributions use irq-gic.c and other files in drivers/irq.
root@orangepipc:/proc# uname -a
Linux orangepipc 3.4.112-sun8i #14 SMP PREEMPT Wed Sep 14 20:29:31 CEST 2016 armv7l GNU/Linux
root@orangepipc:/proc# cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3       
  3:          1          0          0          0  sunxi_gpio_irq_chip  gk_EINT
 29:      19360       6036      16253       7441       GIC  arch_timer
 30:          0          0          0          0       GIC  arch_timer
 32:       2131          0          0          0       GIC  uart0
 38:         18          0          0          0       GIC  twi0
 39:         18          0          0          0       GIC  twi1
 43:          0          0          0          0       GIC  PA
 49:          0          0          0          0       GIC  PG
 50:          0          0          0          0       GIC  sunxi_timer0
 63:          0          0          0          0       GIC  Thermal
 69:          0          0          0          0       GIC  sunxi-ir
 72:          0          0          0          0       GIC  sunxi-rtc alarm
 77:          1          0          0          0       GIC  PL
 81:          0          0          0          0       GIC  arisc_hwmsgbox_irq
 82:          0          0          0          0       GIC  sunxi_dmac
 90:          0          0          0          0       GIC  cedar_dev
 92:      88311          0          0          0       GIC  sunxi-mmc
 93:         52          0          0          0       GIC  sunxi-mmc
 97:          0          0          0          0       GIC  spi0
104:          0          0          0          0       GIC  ehci_hcd:usb1
105:          0          0          0          0       GIC  ohci_hcd:usb5
106:          0          0          0          0       GIC  ehci_hcd:usb2
107:          0          0          0          0       GIC  ohci_hcd:usb6
108:          0          0          0          0       GIC  ehci_hcd:usb3
109:          0          0          0          0       GIC  ohci_hcd:usb7
110:          0          0          0          0       GIC  ehci_hcd:usb4
111:          0          0          0          0       GIC  ohci_hcd:usb8
114:        758          0          0          0       GIC  gmac0
118:      64408          0          0          0       GIC  dispaly
IPI0:          0          0          0          0  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:       5125       7910       6163       4200  Rescheduling interrupts
IPI3:        140        171         36        169  Function call interrupts
IPI4:          1          3          1          0  Single function call interrupts
IPI5:          0          0          0          0  CPU stop interrupts
IPI6:          0          0          0          0  CPU backtrace
IPI7:          0          0          0          0  completion interrupts
Err:          0

root@orangepipc:/proc# cat iomem
01c00000-01c00030 : geth_extclk
01c02000-01c024dc : sunxi_dmac
01c0f000-01c0ffff : sunxi-mmc
01c10000-01c10fff : sunxi-mmc
01c16000-01c165ff : hdmi
01c20ca0-01c20cbf : sunxi_wdt
  01c20ca0-01c20cbf : sunxi_wdt
01c28000-01c283ff : uart
01c2ac00-01c2afff : twi.0
  01c2ac00-01c2afff : twi.0
01c2b000-01c2b3ff : twi.1
  01c2b000-01c2b3ff : twi.1
01c30000-01c31054 : geth_io
  01c30000-01c31054 : gmac0
01c62000-01c620c4 : MBUS_PMU
  01c62000-01c620c4 : MBUS_PMU
01c68000-01c68fff : spi.0
  01c68000-01c68fff : spi
40000000-7fffffff : System RAM
  40008000-4095bce7 : Kernel code
  409b0000-40b5cf8f : Kernel data
f1000000-f1400000 : de
f1c0c000-f1c0c3fc : lcd0
f1c0d000-f1c0d3fc : lcd1

cat kallsyms | grep gic
c00084f0 T gic_handle_irq
c0019c40 T cluster_to_logical_mask
c001e884 t gic_mask_irq
c001e8f4 t gic_unmask_irq
c001e964 t gic_eoi_irq
c001e9c0 t gic_set_type
c001eab8 t gic_retrigger
c001eaf0 t gic_set_wake
c001eb28 t gic_irq_domain_xlate
c001eba0 t gic_notifier
c001ee24 t gic_handle_cascade_irq
c001ef24 t gic_set_affinity
c001efcc t gic_irq_domain_map
c001f054 T gic_cpu_exit
c001f088 T gic_raise_softirq
c001f18c T gic_pending_irq
c0034b48 t cap_validate_magic
c02b0db4 t udf_load_logicalvolint
c033a2c0 T extent_from_logical
c033a980 T iterate_inodes_from_logical
c0367094 t queue_logical_block_size_show
c0367ec8 T blk_queue_logical_block_size
c037e4f8 T __csum_ipv6_magic
c0479484 t hub_port_logical_disconnect
c04eabe8 t validate_hardware_logical_block_alignment
c05d741c t fib_magic
c0684bf0 t gic_cpu_init
c0684ca4 T gic_secondary_init
c068c1f8 t ms_lib_set_logicalpair
c068c2b0 t ms_lib_free_logicalmap
c068c458 t ms_lib_scan_logicalblocknumber
c0693c8c R gic_irq_domain_ops
c069823c r vermagic
c089c0d8 r __ksymtab___csum_ipv6_magic
c089d0b8 r __ksymtab_blk_queue_logical_block_size
c08a80a8 r __kcrctab___csum_ipv6_magic
c08a8898 r __kcrctab_blk_queue_logical_block_size
c08ae41a r __kstrtab___csum_ipv6_magic
c08b8324 r __kstrtab_blk_queue_logical_block_size
c096322c T gic_cascade_irq
c0963278 T gic_init_bases
c09638ac t sun8i_gic_init


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org