xref: /optee_os/core/include/drivers/gic.h (revision c95d740ab3604844575dc99dad8bd512781c5d07)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2016, Linaro Limited
4  * Copyright (c) 2014, STMicroelectronics International N.V.
5  */
6 
7 #ifndef __DRIVERS_GIC_H
8 #define __DRIVERS_GIC_H
9 #include <types_ext.h>
10 #include <kernel/interrupt.h>
11 
12 #if defined(CFG_ARM_GICV3)
13 #define GIC_DIST_REG_SIZE	0x10000
14 #define GIC_CPU_REG_SIZE	0x10000
15 #else
16 #define GIC_DIST_REG_SIZE	0x1000
17 #define GIC_CPU_REG_SIZE	0x1000
18 #endif
19 
20 #define GIC_PPI_BASE		U(16)
21 #define GIC_SPI_BASE		U(32)
22 
23 #define GIC_SGI_TO_ITNUM(x)	(x)
24 #define GIC_PPI_TO_ITNUM(x)	((x) + GIC_PPI_BASE)
25 #define GIC_SPI_TO_ITNUM(x)	((x) + GIC_SPI_BASE)
26 
27 /*
28  * Default lowest ID for secure SGIs, note that this does not account for
29  * interrupts donated to non-secure world with gic_init_donate_sgi_to_ns().
30  */
31 #define GIC_SGI_SEC_BASE	8
32 /* Max ID for secure SGIs */
33 #define GIC_SGI_SEC_MAX		15
34 /* Default IRQ priority for SPIs in Non-Sec EL1 */
35 #define GIC_SPI_PRI_NS_EL1	0x50
36 
37 /*
38  * The two gic_init() and gic_init_v3() functions initializes the struct
39  * gic_data which is then used by the other functions. These two functions
40  * also initializes the GIC and are only supposed to be called from the
41  * primary boot CPU.
42  */
43 void gic_init_v3(paddr_t gicc_base_pa, paddr_t gicd_base_pa,
44 		 paddr_t gicr_base_pa);
45 static inline void gic_init(paddr_t gicc_base_pa, paddr_t gicd_base_pa)
46 {
47 	gic_init_v3(gicc_base_pa, gicd_base_pa, 0);
48 }
49 
50 /* Donates one of the secure SGIs to normal world */
51 void gic_init_donate_sgi_to_ns(size_t it);
52 
53 /*
54  * Does per-CPU specific GIC initialization, should be called by all
55  * secondary CPUs when booting.
56  */
57 void gic_init_per_cpu(void);
58 
59 /* Print GIC state to console */
60 void gic_dump_state(void);
61 
62 /*
63  * Reassign one of the SPIs to normal world and set its priority to
64  * GIC_SPI_PRI_NS_EL1. Ensure that the interrupt is currently
65  * assigned to secure world and disabled when this function is called.
66  */
67 TEE_Result gic_spi_release_to_ns(size_t it);
68 #endif /*__DRIVERS_GIC_H*/
69