xref: /rk3399_ARM-atf/include/drivers/arm/gicv3.h (revision 8782922c259dab929a0a9b930e5f1bca55f506ca)
1df373737SAchin Gupta /*
2dc6aad2eSRoberto Vargas  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3df373737SAchin Gupta  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5df373737SAchin Gupta  */
6df373737SAchin Gupta 
7df373737SAchin Gupta #ifndef __GICV3_H__
8df373737SAchin Gupta #define __GICV3_H__
9df373737SAchin Gupta 
10df373737SAchin Gupta /*******************************************************************************
11df373737SAchin Gupta  * GICv3 miscellaneous definitions
12df373737SAchin Gupta  ******************************************************************************/
13df373737SAchin Gupta /* Interrupt group definitions */
14*8782922cSAntonio Nino Diaz #define INTR_GROUP1S		U(0)
15*8782922cSAntonio Nino Diaz #define INTR_GROUP0		U(1)
16*8782922cSAntonio Nino Diaz #define INTR_GROUP1NS		U(2)
17df373737SAchin Gupta 
18df373737SAchin Gupta /* Interrupt IDs reported by the HPPIR and IAR registers */
19*8782922cSAntonio Nino Diaz #define PENDING_G1S_INTID	U(1020)
20*8782922cSAntonio Nino Diaz #define PENDING_G1NS_INTID	U(1021)
21df373737SAchin Gupta 
22df373737SAchin Gupta /* Constant to categorize LPI interrupt */
23*8782922cSAntonio Nino Diaz #define MIN_LPI_ID		U(8192)
24df373737SAchin Gupta 
258db978b5SJeenu Viswambharan /* GICv3 can only target up to 16 PEs with SGI */
26*8782922cSAntonio Nino Diaz #define GICV3_MAX_SGI_TARGETS	U(16)
278db978b5SJeenu Viswambharan 
28df373737SAchin Gupta /*******************************************************************************
29df373737SAchin Gupta  * GICv3 specific Distributor interface register offsets and constants.
30df373737SAchin Gupta  ******************************************************************************/
31*8782922cSAntonio Nino Diaz #define GICD_STATUSR		U(0x10)
32*8782922cSAntonio Nino Diaz #define GICD_SETSPI_NSR		U(0x40)
33*8782922cSAntonio Nino Diaz #define GICD_CLRSPI_NSR		U(0x48)
34*8782922cSAntonio Nino Diaz #define GICD_SETSPI_SR		U(0x50)
35*8782922cSAntonio Nino Diaz #define GICD_CLRSPI_SR		U(0x50)
36*8782922cSAntonio Nino Diaz #define GICD_IGRPMODR		U(0xd00)
3761e30277SSoby Mathew /*
3861e30277SSoby Mathew  * GICD_IROUTER<n> register is at 0x6000 + 8n, where n is the interrupt id and
3961e30277SSoby Mathew  * n >= 32, making the effective offset as 0x6100.
4061e30277SSoby Mathew  */
41*8782922cSAntonio Nino Diaz #define GICD_IROUTER		U(0x6000)
42*8782922cSAntonio Nino Diaz #define GICD_PIDR2_GICV3	U(0xffe8)
43df373737SAchin Gupta 
44df373737SAchin Gupta #define IGRPMODR_SHIFT		5
45df373737SAchin Gupta 
46df373737SAchin Gupta /* GICD_CTLR bit definitions */
47df373737SAchin Gupta #define CTLR_ENABLE_G1NS_SHIFT		1
48df373737SAchin Gupta #define CTLR_ENABLE_G1S_SHIFT		2
49df373737SAchin Gupta #define CTLR_ARE_S_SHIFT		4
50df373737SAchin Gupta #define CTLR_ARE_NS_SHIFT		5
51df373737SAchin Gupta #define CTLR_DS_SHIFT			6
52df373737SAchin Gupta #define CTLR_E1NWF_SHIFT		7
53df373737SAchin Gupta #define GICD_CTLR_RWP_SHIFT		31
54df373737SAchin Gupta 
55*8782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1NS_MASK		U(0x1)
56*8782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1S_MASK		U(0x1)
57*8782922cSAntonio Nino Diaz #define CTLR_ARE_S_MASK			U(0x1)
58*8782922cSAntonio Nino Diaz #define CTLR_ARE_NS_MASK		U(0x1)
59*8782922cSAntonio Nino Diaz #define CTLR_DS_MASK			U(0x1)
60*8782922cSAntonio Nino Diaz #define CTLR_E1NWF_MASK			U(0x1)
61*8782922cSAntonio Nino Diaz #define GICD_CTLR_RWP_MASK		U(0x1)
62df373737SAchin Gupta 
63*8782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1NS_BIT		BIT_32(CTLR_ENABLE_G1NS_SHIFT)
64*8782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1S_BIT		BIT_32(CTLR_ENABLE_G1S_SHIFT)
65*8782922cSAntonio Nino Diaz #define CTLR_ARE_S_BIT			BIT_32(CTLR_ARE_S_SHIFT)
66*8782922cSAntonio Nino Diaz #define CTLR_ARE_NS_BIT			BIT_32(CTLR_ARE_NS_SHIFT)
67*8782922cSAntonio Nino Diaz #define CTLR_DS_BIT			BIT_32(CTLR_DS_SHIFT)
68*8782922cSAntonio Nino Diaz #define CTLR_E1NWF_BIT			BIT_32(CTLR_E1NWF_SHIFT)
69*8782922cSAntonio Nino Diaz #define GICD_CTLR_RWP_BIT		BIT_32(GICD_CTLR_RWP_SHIFT)
70df373737SAchin Gupta 
71df373737SAchin Gupta /* GICD_IROUTER shifts and masks */
72ebf1ca10SSoby Mathew #define IROUTER_SHIFT		0
73df373737SAchin Gupta #define IROUTER_IRM_SHIFT	31
74*8782922cSAntonio Nino Diaz #define IROUTER_IRM_MASK	U(0x1)
75df373737SAchin Gupta 
76*8782922cSAntonio Nino Diaz #define GICV3_IRM_PE		U(0)
77*8782922cSAntonio Nino Diaz #define GICV3_IRM_ANY		U(1)
78fc529feeSJeenu Viswambharan 
79ebf1ca10SSoby Mathew #define NUM_OF_DIST_REGS	30
80ebf1ca10SSoby Mathew 
81df373737SAchin Gupta /*******************************************************************************
82df373737SAchin Gupta  * GICv3 Re-distributor interface registers & constants
83df373737SAchin Gupta  ******************************************************************************/
84df373737SAchin Gupta #define GICR_PCPUBASE_SHIFT	0x11
85*8782922cSAntonio Nino Diaz #define GICR_SGIBASE_OFFSET	U(65536)	/* 64 KB */
86*8782922cSAntonio Nino Diaz #define GICR_CTLR		U(0x0)
87*8782922cSAntonio Nino Diaz #define GICR_TYPER		U(0x08)
88*8782922cSAntonio Nino Diaz #define GICR_WAKER		U(0x14)
89*8782922cSAntonio Nino Diaz #define GICR_PROPBASER		U(0x70)
90*8782922cSAntonio Nino Diaz #define GICR_PENDBASER		U(0x78)
91*8782922cSAntonio Nino Diaz #define GICR_IGROUPR0		(GICR_SGIBASE_OFFSET + U(0x80))
92*8782922cSAntonio Nino Diaz #define GICR_ISENABLER0		(GICR_SGIBASE_OFFSET + U(0x100))
93*8782922cSAntonio Nino Diaz #define GICR_ICENABLER0		(GICR_SGIBASE_OFFSET + U(0x180))
94*8782922cSAntonio Nino Diaz #define GICR_ISPENDR0		(GICR_SGIBASE_OFFSET + U(0x200))
95*8782922cSAntonio Nino Diaz #define GICR_ICPENDR0		(GICR_SGIBASE_OFFSET + U(0x280))
96*8782922cSAntonio Nino Diaz #define GICR_ISACTIVER0		(GICR_SGIBASE_OFFSET + U(0x300))
97*8782922cSAntonio Nino Diaz #define GICR_ICACTIVER0		(GICR_SGIBASE_OFFSET + U(0x380))
98*8782922cSAntonio Nino Diaz #define GICR_IPRIORITYR		(GICR_SGIBASE_OFFSET + U(0x400))
99*8782922cSAntonio Nino Diaz #define GICR_ICFGR0		(GICR_SGIBASE_OFFSET + U(0xc00))
100*8782922cSAntonio Nino Diaz #define GICR_ICFGR1		(GICR_SGIBASE_OFFSET + U(0xc04))
101*8782922cSAntonio Nino Diaz #define GICR_IGRPMODR0		(GICR_SGIBASE_OFFSET + U(0xd00))
102*8782922cSAntonio Nino Diaz #define GICR_NSACR		(GICR_SGIBASE_OFFSET + U(0xe00))
103df373737SAchin Gupta 
104df373737SAchin Gupta /* GICR_CTLR bit definitions */
105ebf1ca10SSoby Mathew #define GICR_CTLR_UWP_SHIFT	31
106*8782922cSAntonio Nino Diaz #define GICR_CTLR_UWP_MASK	U(0x1)
107*8782922cSAntonio Nino Diaz #define GICR_CTLR_UWP_BIT	BIT_32(GICR_CTLR_UWP_SHIFT)
108df373737SAchin Gupta #define GICR_CTLR_RWP_SHIFT	3
109*8782922cSAntonio Nino Diaz #define GICR_CTLR_RWP_MASK	U(0x1)
110*8782922cSAntonio Nino Diaz #define GICR_CTLR_RWP_BIT	BIT_32(GICR_CTLR_RWP_SHIFT)
111*8782922cSAntonio Nino Diaz #define GICR_CTLR_EN_LPIS_BIT	BIT_32(0)
112df373737SAchin Gupta 
113df373737SAchin Gupta /* GICR_WAKER bit definitions */
114df373737SAchin Gupta #define WAKER_CA_SHIFT		2
115df373737SAchin Gupta #define WAKER_PS_SHIFT		1
116df373737SAchin Gupta 
117*8782922cSAntonio Nino Diaz #define WAKER_CA_MASK		U(0x1)
118*8782922cSAntonio Nino Diaz #define WAKER_PS_MASK		U(0x1)
119df373737SAchin Gupta 
120*8782922cSAntonio Nino Diaz #define WAKER_CA_BIT		BIT_32(WAKER_CA_SHIFT)
121*8782922cSAntonio Nino Diaz #define WAKER_PS_BIT		BIT_32(WAKER_PS_SHIFT)
122df373737SAchin Gupta 
123df373737SAchin Gupta /* GICR_TYPER bit definitions */
124df373737SAchin Gupta #define TYPER_AFF_VAL_SHIFT	32
125df373737SAchin Gupta #define TYPER_PROC_NUM_SHIFT	8
126df373737SAchin Gupta #define TYPER_LAST_SHIFT	4
127df373737SAchin Gupta 
128*8782922cSAntonio Nino Diaz #define TYPER_AFF_VAL_MASK	U(0xffffffff)
129*8782922cSAntonio Nino Diaz #define TYPER_PROC_NUM_MASK	U(0xffff)
130*8782922cSAntonio Nino Diaz #define TYPER_LAST_MASK		U(0x1)
131df373737SAchin Gupta 
132*8782922cSAntonio Nino Diaz #define TYPER_LAST_BIT		BIT_32(TYPER_LAST_SHIFT)
133df373737SAchin Gupta 
134ebf1ca10SSoby Mathew #define NUM_OF_REDIST_REGS	30
135ebf1ca10SSoby Mathew 
136df373737SAchin Gupta /*******************************************************************************
137df373737SAchin Gupta  * GICv3 CPU interface registers & constants
138df373737SAchin Gupta  ******************************************************************************/
139df373737SAchin Gupta /* ICC_SRE bit definitions*/
140*8782922cSAntonio Nino Diaz #define ICC_SRE_EN_BIT		BIT_32(3)
141*8782922cSAntonio Nino Diaz #define ICC_SRE_DIB_BIT		BIT_32(2)
142*8782922cSAntonio Nino Diaz #define ICC_SRE_DFB_BIT		BIT_32(1)
143*8782922cSAntonio Nino Diaz #define ICC_SRE_SRE_BIT		BIT_32(0)
144df373737SAchin Gupta 
145df373737SAchin Gupta /* ICC_IGRPEN1_EL3 bit definitions */
146df373737SAchin Gupta #define IGRPEN1_EL3_ENABLE_G1NS_SHIFT	0
147df373737SAchin Gupta #define IGRPEN1_EL3_ENABLE_G1S_SHIFT	1
148df373737SAchin Gupta 
149*8782922cSAntonio Nino Diaz #define IGRPEN1_EL3_ENABLE_G1NS_BIT	BIT_32(IGRPEN1_EL3_ENABLE_G1NS_SHIFT)
150*8782922cSAntonio Nino Diaz #define IGRPEN1_EL3_ENABLE_G1S_BIT	BIT_32(IGRPEN1_EL3_ENABLE_G1S_SHIFT)
151df373737SAchin Gupta 
152df373737SAchin Gupta /* ICC_IGRPEN0_EL1 bit definitions */
153df373737SAchin Gupta #define IGRPEN1_EL1_ENABLE_G0_SHIFT	0
154*8782922cSAntonio Nino Diaz #define IGRPEN1_EL1_ENABLE_G0_BIT	BIT_32(IGRPEN1_EL1_ENABLE_G0_SHIFT)
155df373737SAchin Gupta 
156df373737SAchin Gupta /* ICC_HPPIR0_EL1 bit definitions */
157df373737SAchin Gupta #define HPPIR0_EL1_INTID_SHIFT		0
158*8782922cSAntonio Nino Diaz #define HPPIR0_EL1_INTID_MASK		U(0xffffff)
159df373737SAchin Gupta 
160df373737SAchin Gupta /* ICC_HPPIR1_EL1 bit definitions */
161df373737SAchin Gupta #define HPPIR1_EL1_INTID_SHIFT		0
162*8782922cSAntonio Nino Diaz #define HPPIR1_EL1_INTID_MASK		U(0xffffff)
163df373737SAchin Gupta 
164df373737SAchin Gupta /* ICC_IAR0_EL1 bit definitions */
165df373737SAchin Gupta #define IAR0_EL1_INTID_SHIFT		0
166*8782922cSAntonio Nino Diaz #define IAR0_EL1_INTID_MASK		U(0xffffff)
167df373737SAchin Gupta 
168df373737SAchin Gupta /* ICC_IAR1_EL1 bit definitions */
169df373737SAchin Gupta #define IAR1_EL1_INTID_SHIFT		0
170*8782922cSAntonio Nino Diaz #define IAR1_EL1_INTID_MASK		U(0xffffff)
171df373737SAchin Gupta 
1728db978b5SJeenu Viswambharan /* ICC SGI macros */
173*8782922cSAntonio Nino Diaz #define SGIR_TGT_MASK			ULL(0xffff)
1748db978b5SJeenu Viswambharan #define SGIR_AFF1_SHIFT			16
1758db978b5SJeenu Viswambharan #define SGIR_INTID_SHIFT		24
176*8782922cSAntonio Nino Diaz #define SGIR_INTID_MASK			ULL(0xf)
1778db978b5SJeenu Viswambharan #define SGIR_AFF2_SHIFT			32
1788db978b5SJeenu Viswambharan #define SGIR_IRM_SHIFT			40
179*8782922cSAntonio Nino Diaz #define SGIR_IRM_MASK			ULL(0x1)
1808db978b5SJeenu Viswambharan #define SGIR_AFF3_SHIFT			48
181*8782922cSAntonio Nino Diaz #define SGIR_AFF_MASK			ULL(0xf)
1828db978b5SJeenu Viswambharan 
183*8782922cSAntonio Nino Diaz #define SGIR_IRM_TO_AFF			U(0)
1848db978b5SJeenu Viswambharan 
185*8782922cSAntonio Nino Diaz #define GICV3_SGIR_VALUE(_aff3, _aff2, _aff1, _intid, _irm, _tgt)	\
186*8782922cSAntonio Nino Diaz 	((((uint64_t) (_aff3) & SGIR_AFF_MASK) << SGIR_AFF3_SHIFT) |	\
187*8782922cSAntonio Nino Diaz 	 (((uint64_t) (_irm) & SGIR_IRM_MASK) << SGIR_IRM_SHIFT) |	\
188*8782922cSAntonio Nino Diaz 	 (((uint64_t) (_aff2) & SGIR_AFF_MASK) << SGIR_AFF2_SHIFT) |	\
189*8782922cSAntonio Nino Diaz 	 (((_intid) & SGIR_INTID_MASK) << SGIR_INTID_SHIFT) |		\
190*8782922cSAntonio Nino Diaz 	 (((_aff1) & SGIR_AFF_MASK) << SGIR_AFF1_SHIFT) |		\
191*8782922cSAntonio Nino Diaz 	 ((_tgt) & SGIR_TGT_MASK))
1928db978b5SJeenu Viswambharan 
193b258278eSSoby Mathew /*****************************************************************************
194b258278eSSoby Mathew  * GICv3 ITS registers and constants
195b258278eSSoby Mathew  *****************************************************************************/
196b258278eSSoby Mathew 
197*8782922cSAntonio Nino Diaz #define GITS_CTLR			U(0x0)
198*8782922cSAntonio Nino Diaz #define GITS_IIDR			U(0x4)
199*8782922cSAntonio Nino Diaz #define GITS_TYPER			U(0x8)
200*8782922cSAntonio Nino Diaz #define GITS_CBASER			U(0x80)
201*8782922cSAntonio Nino Diaz #define GITS_CWRITER			U(0x88)
202*8782922cSAntonio Nino Diaz #define GITS_CREADR			U(0x90)
203*8782922cSAntonio Nino Diaz #define GITS_BASER			U(0x100)
204b258278eSSoby Mathew 
205b258278eSSoby Mathew /* GITS_CTLR bit definitions */
206*8782922cSAntonio Nino Diaz #define GITS_CTLR_ENABLED_BIT		BIT_32(0)
207b258278eSSoby Mathew #define GITS_CTLR_QUIESCENT_SHIFT	31
208*8782922cSAntonio Nino Diaz #define GITS_CTLR_QUIESCENT_BIT		BIT_32(GITS_CTLR_QUIESCENT_SHIFT)
209b258278eSSoby Mathew 
210df373737SAchin Gupta #ifndef __ASSEMBLY__
211df373737SAchin Gupta 
212b9f68dfbSAntonio Nino Diaz #include <arch_helpers.h>
213ebf1ca10SSoby Mathew #include <gic_common.h>
214c639e8ebSJeenu Viswambharan #include <interrupt_props.h>
215b9f68dfbSAntonio Nino Diaz #include <stdbool.h>
216df373737SAchin Gupta #include <stdint.h>
217ebf1ca10SSoby Mathew #include <utils_def.h>
218df373737SAchin Gupta 
219b9f68dfbSAntonio Nino Diaz static inline bool gicv3_is_intr_id_special_identifier(unsigned int id)
220b9f68dfbSAntonio Nino Diaz {
221b9f68dfbSAntonio Nino Diaz 	return (id >= PENDING_G1S_INTID) && (id <= GIC_SPURIOUS_INTERRUPT);
222b9f68dfbSAntonio Nino Diaz }
223df373737SAchin Gupta 
224df373737SAchin Gupta /*******************************************************************************
225df373737SAchin Gupta  * Helper GICv3 macros for SEL1
226df373737SAchin Gupta  ******************************************************************************/
227b9f68dfbSAntonio Nino Diaz static inline uint32_t gicv3_acknowledge_interrupt_sel1(void)
228b9f68dfbSAntonio Nino Diaz {
229b9f68dfbSAntonio Nino Diaz 	return (uint32_t)read_icc_iar1_el1() & IAR1_EL1_INTID_MASK;
230b9f68dfbSAntonio Nino Diaz }
231df373737SAchin Gupta 
232b9f68dfbSAntonio Nino Diaz static inline uint32_t gicv3_get_pending_interrupt_id_sel1(void)
233b9f68dfbSAntonio Nino Diaz {
234b9f68dfbSAntonio Nino Diaz 	return (uint32_t)read_icc_hppir1_el1() & HPPIR1_EL1_INTID_MASK;
235b9f68dfbSAntonio Nino Diaz }
236b9f68dfbSAntonio Nino Diaz 
237b9f68dfbSAntonio Nino Diaz static inline void gicv3_end_of_interrupt_sel1(unsigned int id)
238b9f68dfbSAntonio Nino Diaz {
239b9f68dfbSAntonio Nino Diaz 	write_icc_eoir1_el1(id);
240b9f68dfbSAntonio Nino Diaz }
241df373737SAchin Gupta 
242df373737SAchin Gupta /*******************************************************************************
243df373737SAchin Gupta  * Helper GICv3 macros for EL3
244df373737SAchin Gupta  ******************************************************************************/
245b9f68dfbSAntonio Nino Diaz static inline uint32_t gicv3_acknowledge_interrupt(void)
246b9f68dfbSAntonio Nino Diaz {
247b9f68dfbSAntonio Nino Diaz 	return (uint32_t)read_icc_iar0_el1() & IAR0_EL1_INTID_MASK;
248b9f68dfbSAntonio Nino Diaz }
249b9f68dfbSAntonio Nino Diaz 
250b9f68dfbSAntonio Nino Diaz static inline void gicv3_end_of_interrupt(unsigned int id)
251b9f68dfbSAntonio Nino Diaz {
252b9f68dfbSAntonio Nino Diaz 	return write_icc_eoir0_el1(id);
253b9f68dfbSAntonio Nino Diaz }
254df373737SAchin Gupta 
255ebf1ca10SSoby Mathew /*
256ebf1ca10SSoby Mathew  * This macro returns the total number of GICD registers corresponding to
257ebf1ca10SSoby Mathew  * the name.
258ebf1ca10SSoby Mathew  */
259ebf1ca10SSoby Mathew #define GICD_NUM_REGS(reg_name)	\
260ebf1ca10SSoby Mathew 	DIV_ROUND_UP_2EVAL(TOTAL_SPI_INTR_NUM, (1 << reg_name ## _SHIFT))
261ebf1ca10SSoby Mathew 
262ebf1ca10SSoby Mathew #define GICR_NUM_REGS(reg_name)	\
263ebf1ca10SSoby Mathew 	DIV_ROUND_UP_2EVAL(TOTAL_PCPU_INTR_NUM, (1 << reg_name ## _SHIFT))
264ebf1ca10SSoby Mathew 
2654ee8d0beSJeenu Viswambharan /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
266*8782922cSAntonio Nino Diaz #define INT_ID_MASK	U(0xffffff)
2674ee8d0beSJeenu Viswambharan 
268df373737SAchin Gupta /*******************************************************************************
269df373737SAchin Gupta  * This structure describes some of the implementation defined attributes of the
270df373737SAchin Gupta  * GICv3 IP. It is used by the platform port to specify these attributes in order
271df373737SAchin Gupta  * to initialise the GICV3 driver. The attributes are described below.
272df373737SAchin Gupta  *
273c639e8ebSJeenu Viswambharan  * The 'gicd_base' field contains the base address of the Distributor interface
274c639e8ebSJeenu Viswambharan  * programmer's view.
275c639e8ebSJeenu Viswambharan  *
276c639e8ebSJeenu Viswambharan  * The 'gicr_base' field contains the base address of the Re-distributor
277df373737SAchin Gupta  * interface programmer's view.
278df373737SAchin Gupta  *
279c639e8ebSJeenu Viswambharan  * The 'g0_interrupt_array' field is a pointer to an array in which each entry
280c639e8ebSJeenu Viswambharan  * corresponds to an ID of a Group 0 interrupt. This field is ignored when
281c639e8ebSJeenu Viswambharan  * 'interrupt_props' field is used. This field is deprecated.
282df373737SAchin Gupta  *
283c639e8ebSJeenu Viswambharan  * The 'g0_interrupt_num' field contains the number of entries in the
284c639e8ebSJeenu Viswambharan  * 'g0_interrupt_array'. This field is ignored when 'interrupt_props' field is
285c639e8ebSJeenu Viswambharan  * used. This field is deprecated.
286df373737SAchin Gupta  *
287c639e8ebSJeenu Viswambharan  * The 'g1s_interrupt_array' field is a pointer to an array in which each entry
288c639e8ebSJeenu Viswambharan  * corresponds to an ID of a Group 1 interrupt. This field is ignored when
289c639e8ebSJeenu Viswambharan  * 'interrupt_props' field is used. This field is deprecated.
290df373737SAchin Gupta  *
291c639e8ebSJeenu Viswambharan  * The 'g1s_interrupt_num' field contains the number of entries in the
292c639e8ebSJeenu Viswambharan  * 'g1s_interrupt_array'. This field must be 0 if 'interrupt_props' field is
293c639e8ebSJeenu Viswambharan  * used. This field is ignored when 'interrupt_props' field is used. This field
294c639e8ebSJeenu Viswambharan  * is deprecated.
295df373737SAchin Gupta  *
296c639e8ebSJeenu Viswambharan  * The 'interrupt_props' field is a pointer to an array that enumerates secure
297c639e8ebSJeenu Viswambharan  * interrupts and their properties. If this field is not NULL, both
298c639e8ebSJeenu Viswambharan  * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
299df373737SAchin Gupta  *
300c639e8ebSJeenu Viswambharan  * The 'interrupt_props_num' field contains the number of entries in the
301c639e8ebSJeenu Viswambharan  * 'interrupt_props' array. If this field is non-zero, both 'g0_interrupt_num'
302c639e8ebSJeenu Viswambharan  * and 'g1s_interrupt_num' are ignored.
303c639e8ebSJeenu Viswambharan  *
304c639e8ebSJeenu Viswambharan  * The 'rdistif_num' field contains the number of Redistributor interfaces the
305c639e8ebSJeenu Viswambharan  * GIC implements. This is equal to the number of CPUs or CPU interfaces
306df373737SAchin Gupta  * instantiated in the GIC.
307df373737SAchin Gupta  *
308c639e8ebSJeenu Viswambharan  * The 'rdistif_base_addrs' field is a pointer to an array that has an entry for
309c639e8ebSJeenu Viswambharan  * storing the base address of the Redistributor interface frame of each CPU in
310c639e8ebSJeenu Viswambharan  * the system. The size of the array = 'rdistif_num'. The base addresses are
311c639e8ebSJeenu Viswambharan  * detected during driver initialisation.
312df373737SAchin Gupta  *
313c639e8ebSJeenu Viswambharan  * The 'mpidr_to_core_pos' field is a pointer to a hash function which the
314c639e8ebSJeenu Viswambharan  * driver will use to convert an MPIDR value to a linear core index. This index
315c639e8ebSJeenu Viswambharan  * will be used for accessing the 'rdistif_base_addrs' array. This is an
316c639e8ebSJeenu Viswambharan  * optional field. A GICv3 implementation maps each MPIDR to a linear core index
317c639e8ebSJeenu Viswambharan  * as well. This mapping can be found by reading the "Affinity Value" and
318c639e8ebSJeenu Viswambharan  * "Processor Number" fields in the GICR_TYPER. It is IMP. DEF. if the
319df373737SAchin Gupta  * "Processor Numbers" are suitable to index into an array to access core
320c639e8ebSJeenu Viswambharan  * specific information. If this not the case, the platform port must provide a
321c639e8ebSJeenu Viswambharan  * hash function. Otherwise, the "Processor Number" field will be used to access
322c639e8ebSJeenu Viswambharan  * the array elements.
323df373737SAchin Gupta  ******************************************************************************/
3244c0d0390SSoby Mathew typedef unsigned int (*mpidr_hash_fn)(u_register_t mpidr);
325df373737SAchin Gupta 
326df373737SAchin Gupta typedef struct gicv3_driver_data {
327df373737SAchin Gupta 	uintptr_t gicd_base;
328df373737SAchin Gupta 	uintptr_t gicr_base;
329c639e8ebSJeenu Viswambharan #if !ERROR_DEPRECATED
330dcf01a0aSDan Handley 	unsigned int g0_interrupt_num __deprecated;
331dcf01a0aSDan Handley 	unsigned int g1s_interrupt_num __deprecated;
332dcf01a0aSDan Handley 	const unsigned int *g0_interrupt_array __deprecated;
333dcf01a0aSDan Handley 	const unsigned int *g1s_interrupt_array __deprecated;
334c639e8ebSJeenu Viswambharan #endif
335c639e8ebSJeenu Viswambharan 	const interrupt_prop_t *interrupt_props;
336c639e8ebSJeenu Viswambharan 	unsigned int interrupt_props_num;
337df373737SAchin Gupta 	unsigned int rdistif_num;
338df373737SAchin Gupta 	uintptr_t *rdistif_base_addrs;
339df373737SAchin Gupta 	mpidr_hash_fn mpidr_to_core_pos;
340df373737SAchin Gupta } gicv3_driver_data_t;
341df373737SAchin Gupta 
342ebf1ca10SSoby Mathew typedef struct gicv3_redist_ctx {
343ebf1ca10SSoby Mathew 	/* 64 bits registers */
344ebf1ca10SSoby Mathew 	uint64_t gicr_propbaser;
345ebf1ca10SSoby Mathew 	uint64_t gicr_pendbaser;
346ebf1ca10SSoby Mathew 
347ebf1ca10SSoby Mathew 	/* 32 bits registers */
348ebf1ca10SSoby Mathew 	uint32_t gicr_ctlr;
349ebf1ca10SSoby Mathew 	uint32_t gicr_igroupr0;
350ebf1ca10SSoby Mathew 	uint32_t gicr_isenabler0;
351ebf1ca10SSoby Mathew 	uint32_t gicr_ispendr0;
352ebf1ca10SSoby Mathew 	uint32_t gicr_isactiver0;
353ebf1ca10SSoby Mathew 	uint32_t gicr_ipriorityr[GICR_NUM_REGS(IPRIORITYR)];
354ebf1ca10SSoby Mathew 	uint32_t gicr_icfgr0;
355ebf1ca10SSoby Mathew 	uint32_t gicr_icfgr1;
356ebf1ca10SSoby Mathew 	uint32_t gicr_igrpmodr0;
357ebf1ca10SSoby Mathew 	uint32_t gicr_nsacr;
358ebf1ca10SSoby Mathew } gicv3_redist_ctx_t;
359ebf1ca10SSoby Mathew 
360ebf1ca10SSoby Mathew typedef struct gicv3_dist_ctx {
361ebf1ca10SSoby Mathew 	/* 64 bits registers */
362ebf1ca10SSoby Mathew 	uint64_t gicd_irouter[TOTAL_SPI_INTR_NUM];
363ebf1ca10SSoby Mathew 
364ebf1ca10SSoby Mathew 	/* 32 bits registers */
365ebf1ca10SSoby Mathew 	uint32_t gicd_ctlr;
366ebf1ca10SSoby Mathew 	uint32_t gicd_igroupr[GICD_NUM_REGS(IGROUPR)];
367ebf1ca10SSoby Mathew 	uint32_t gicd_isenabler[GICD_NUM_REGS(ISENABLER)];
368ebf1ca10SSoby Mathew 	uint32_t gicd_ispendr[GICD_NUM_REGS(ISPENDR)];
369ebf1ca10SSoby Mathew 	uint32_t gicd_isactiver[GICD_NUM_REGS(ISACTIVER)];
370ebf1ca10SSoby Mathew 	uint32_t gicd_ipriorityr[GICD_NUM_REGS(IPRIORITYR)];
371ebf1ca10SSoby Mathew 	uint32_t gicd_icfgr[GICD_NUM_REGS(ICFGR)];
372ebf1ca10SSoby Mathew 	uint32_t gicd_igrpmodr[GICD_NUM_REGS(IGRPMODR)];
373ebf1ca10SSoby Mathew 	uint32_t gicd_nsacr[GICD_NUM_REGS(NSACR)];
374ebf1ca10SSoby Mathew } gicv3_dist_ctx_t;
375ebf1ca10SSoby Mathew 
376b258278eSSoby Mathew typedef struct gicv3_its_ctx {
377b258278eSSoby Mathew 	/* 64 bits registers */
378b258278eSSoby Mathew 	uint64_t gits_cbaser;
379b258278eSSoby Mathew 	uint64_t gits_cwriter;
380b258278eSSoby Mathew 	uint64_t gits_baser[8];
381b258278eSSoby Mathew 
382b258278eSSoby Mathew 	/* 32 bits registers */
383b258278eSSoby Mathew 	uint32_t gits_ctlr;
384b258278eSSoby Mathew } gicv3_its_ctx_t;
385b258278eSSoby Mathew 
386df373737SAchin Gupta /*******************************************************************************
387df373737SAchin Gupta  * GICv3 EL3 driver API
388df373737SAchin Gupta  ******************************************************************************/
389df373737SAchin Gupta void gicv3_driver_init(const gicv3_driver_data_t *plat_driver_data);
390df373737SAchin Gupta void gicv3_distif_init(void);
391df373737SAchin Gupta void gicv3_rdistif_init(unsigned int proc_num);
392d780699bSJeenu Viswambharan void gicv3_rdistif_on(unsigned int proc_num);
393d780699bSJeenu Viswambharan void gicv3_rdistif_off(unsigned int proc_num);
394df373737SAchin Gupta void gicv3_cpuif_enable(unsigned int proc_num);
395df373737SAchin Gupta void gicv3_cpuif_disable(unsigned int proc_num);
396df373737SAchin Gupta unsigned int gicv3_get_pending_interrupt_type(void);
397df373737SAchin Gupta unsigned int gicv3_get_pending_interrupt_id(void);
398df373737SAchin Gupta unsigned int gicv3_get_interrupt_type(unsigned int id,
399df373737SAchin Gupta 					  unsigned int proc_num);
400ebf1ca10SSoby Mathew void gicv3_distif_init_restore(const gicv3_dist_ctx_t * const dist_ctx);
401ebf1ca10SSoby Mathew void gicv3_distif_save(gicv3_dist_ctx_t * const dist_ctx);
402ebf1ca10SSoby Mathew /*
403ebf1ca10SSoby Mathew  * gicv3_distif_post_restore and gicv3_distif_pre_save must be implemented if
404ebf1ca10SSoby Mathew  * gicv3_distif_save and gicv3_rdistif_init_restore are used. If no
405ebf1ca10SSoby Mathew  * implementation-defined sequence is needed at these steps, an empty function
406ebf1ca10SSoby Mathew  * can be provided.
407ebf1ca10SSoby Mathew  */
408ebf1ca10SSoby Mathew void gicv3_distif_post_restore(unsigned int proc_num);
409ebf1ca10SSoby Mathew void gicv3_distif_pre_save(unsigned int proc_num);
410ebf1ca10SSoby Mathew void gicv3_rdistif_init_restore(unsigned int proc_num, const gicv3_redist_ctx_t * const rdist_ctx);
411ebf1ca10SSoby Mathew void gicv3_rdistif_save(unsigned int proc_num, gicv3_redist_ctx_t * const rdist_ctx);
412b258278eSSoby Mathew void gicv3_its_save_disable(uintptr_t gits_base, gicv3_its_ctx_t * const its_ctx);
413b258278eSSoby Mathew void gicv3_its_restore(uintptr_t gits_base, const gicv3_its_ctx_t * const its_ctx);
414df373737SAchin Gupta 
415eb68ea9bSJeenu Viswambharan unsigned int gicv3_get_running_priority(void);
416cbd3f370SJeenu Viswambharan unsigned int gicv3_get_interrupt_active(unsigned int id, unsigned int proc_num);
417979225f4SJeenu Viswambharan void gicv3_enable_interrupt(unsigned int id, unsigned int proc_num);
418979225f4SJeenu Viswambharan void gicv3_disable_interrupt(unsigned int id, unsigned int proc_num);
419f3a86600SJeenu Viswambharan void gicv3_set_interrupt_priority(unsigned int id, unsigned int proc_num,
420f3a86600SJeenu Viswambharan 		unsigned int priority);
42174dce7faSJeenu Viswambharan void gicv3_set_interrupt_type(unsigned int id, unsigned int proc_num,
422dc6aad2eSRoberto Vargas 		unsigned int type);
4238db978b5SJeenu Viswambharan void gicv3_raise_secure_g0_sgi(int sgi_num, u_register_t target);
424fc529feeSJeenu Viswambharan void gicv3_set_spi_routing(unsigned int id, unsigned int irm,
425fc529feeSJeenu Viswambharan 		u_register_t mpidr);
426a2816a16SJeenu Viswambharan void gicv3_set_interrupt_pending(unsigned int id, unsigned int proc_num);
427a2816a16SJeenu Viswambharan void gicv3_clear_interrupt_pending(unsigned int id, unsigned int proc_num);
428d55a4450SJeenu Viswambharan unsigned int gicv3_set_pmr(unsigned int mask);
429eb68ea9bSJeenu Viswambharan 
430df373737SAchin Gupta #endif /* __ASSEMBLY__ */
431df373737SAchin Gupta #endif /* __GICV3_H__ */
432