xref: /rk3399_ARM-atf/include/drivers/arm/gicv2.h (revision 8782922c259dab929a0a9b930e5f1bca55f506ca)
1464ce2bbSSoby Mathew /*
293c78ed2SAntonio Nino Diaz  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3464ce2bbSSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5464ce2bbSSoby Mathew  */
6464ce2bbSSoby Mathew 
7464ce2bbSSoby Mathew #ifndef __GICV2_H__
8464ce2bbSSoby Mathew #define __GICV2_H__
9464ce2bbSSoby Mathew 
10464ce2bbSSoby Mathew /*******************************************************************************
11464ce2bbSSoby Mathew  * GICv2 miscellaneous definitions
12464ce2bbSSoby Mathew  ******************************************************************************/
1374dce7faSJeenu Viswambharan 
1474dce7faSJeenu Viswambharan /* Interrupt group definitions */
15*8782922cSAntonio Nino Diaz #define GICV2_INTR_GROUP0	U(0)
16*8782922cSAntonio Nino Diaz #define GICV2_INTR_GROUP1	U(1)
1774dce7faSJeenu Viswambharan 
18464ce2bbSSoby Mathew /* Interrupt IDs reported by the HPPIR and IAR registers */
19*8782922cSAntonio Nino Diaz #define PENDING_G1_INTID	U(1022)
20464ce2bbSSoby Mathew 
21fa9db423SJeenu Viswambharan /* GICv2 can only target up to 8 PEs */
22*8782922cSAntonio Nino Diaz #define GICV2_MAX_TARGET_PE	U(8)
23fa9db423SJeenu Viswambharan 
24464ce2bbSSoby Mathew /*******************************************************************************
25464ce2bbSSoby Mathew  * GICv2 specific Distributor interface register offsets and constants.
26464ce2bbSSoby Mathew  ******************************************************************************/
27*8782922cSAntonio Nino Diaz #define GICD_ITARGETSR		U(0x800)
28*8782922cSAntonio Nino Diaz #define GICD_SGIR		U(0xF00)
29*8782922cSAntonio Nino Diaz #define GICD_CPENDSGIR		U(0xF10)
30*8782922cSAntonio Nino Diaz #define GICD_SPENDSGIR		U(0xF20)
31*8782922cSAntonio Nino Diaz #define GICD_PIDR2_GICV2	U(0xFE8)
32464ce2bbSSoby Mathew 
33464ce2bbSSoby Mathew #define ITARGETSR_SHIFT		2
34*8782922cSAntonio Nino Diaz #define GIC_TARGET_CPU_MASK	U(0xff)
35464ce2bbSSoby Mathew 
36464ce2bbSSoby Mathew #define CPENDSGIR_SHIFT		2
37464ce2bbSSoby Mathew #define SPENDSGIR_SHIFT		CPENDSGIR_SHIFT
38464ce2bbSSoby Mathew 
398db978b5SJeenu Viswambharan #define SGIR_TGTLSTFLT_SHIFT	24
40*8782922cSAntonio Nino Diaz #define SGIR_TGTLSTFLT_MASK	U(0x3)
418db978b5SJeenu Viswambharan #define SGIR_TGTLST_SHIFT	16
42*8782922cSAntonio Nino Diaz #define SGIR_TGTLST_MASK	U(0xff)
43*8782922cSAntonio Nino Diaz #define SGIR_INTID_MASK		ULL(0xf)
448db978b5SJeenu Viswambharan 
45*8782922cSAntonio Nino Diaz #define SGIR_TGT_SPECIFIC	U(0)
468db978b5SJeenu Viswambharan 
478db978b5SJeenu Viswambharan #define GICV2_SGIR_VALUE(tgt_lst_flt, tgt, intid) \
488db978b5SJeenu Viswambharan 	((((tgt_lst_flt) & SGIR_TGTLSTFLT_MASK) << SGIR_TGTLSTFLT_SHIFT) | \
498db978b5SJeenu Viswambharan 	 (((tgt) & SGIR_TGTLST_MASK) << SGIR_TGTLST_SHIFT) | \
508db978b5SJeenu Viswambharan 	 ((intid) & SGIR_INTID_MASK))
518db978b5SJeenu Viswambharan 
52464ce2bbSSoby Mathew /*******************************************************************************
53464ce2bbSSoby Mathew  * GICv2 specific CPU interface register offsets and constants.
54464ce2bbSSoby Mathew  ******************************************************************************/
55464ce2bbSSoby Mathew /* Physical CPU Interface registers */
56*8782922cSAntonio Nino Diaz #define GICC_CTLR		U(0x0)
57*8782922cSAntonio Nino Diaz #define GICC_PMR		U(0x4)
58*8782922cSAntonio Nino Diaz #define GICC_BPR		U(0x8)
59*8782922cSAntonio Nino Diaz #define GICC_IAR		U(0xC)
60*8782922cSAntonio Nino Diaz #define GICC_EOIR		U(0x10)
61*8782922cSAntonio Nino Diaz #define GICC_RPR		U(0x14)
62*8782922cSAntonio Nino Diaz #define GICC_HPPIR		U(0x18)
63*8782922cSAntonio Nino Diaz #define GICC_AHPPIR		U(0x28)
64*8782922cSAntonio Nino Diaz #define GICC_IIDR		U(0xFC)
65*8782922cSAntonio Nino Diaz #define GICC_DIR		U(0x1000)
66464ce2bbSSoby Mathew #define GICC_PRIODROP		GICC_EOIR
67464ce2bbSSoby Mathew 
68464ce2bbSSoby Mathew /* GICC_CTLR bit definitions */
69*8782922cSAntonio Nino Diaz #define EOI_MODE_NS		BIT_32(10)
70*8782922cSAntonio Nino Diaz #define EOI_MODE_S		BIT_32(9)
71*8782922cSAntonio Nino Diaz #define IRQ_BYP_DIS_GRP1	BIT_32(8)
72*8782922cSAntonio Nino Diaz #define FIQ_BYP_DIS_GRP1	BIT_32(7)
73*8782922cSAntonio Nino Diaz #define IRQ_BYP_DIS_GRP0	BIT_32(6)
74*8782922cSAntonio Nino Diaz #define FIQ_BYP_DIS_GRP0	BIT_32(5)
75*8782922cSAntonio Nino Diaz #define CBPR			BIT_32(4)
76464ce2bbSSoby Mathew #define FIQ_EN_SHIFT		3
77*8782922cSAntonio Nino Diaz #define FIQ_EN_BIT		BIT_32(FIQ_EN_SHIFT)
78*8782922cSAntonio Nino Diaz #define ACK_CTL			BIT_32(2)
79464ce2bbSSoby Mathew 
80464ce2bbSSoby Mathew /* GICC_IIDR bit masks and shifts */
81464ce2bbSSoby Mathew #define GICC_IIDR_PID_SHIFT	20
82464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_SHIFT	16
83464ce2bbSSoby Mathew #define GICC_IIDR_REV_SHIFT	12
84464ce2bbSSoby Mathew #define GICC_IIDR_IMP_SHIFT	0
85464ce2bbSSoby Mathew 
86*8782922cSAntonio Nino Diaz #define GICC_IIDR_PID_MASK	U(0xfff)
87*8782922cSAntonio Nino Diaz #define GICC_IIDR_ARCH_MASK	U(0xf)
88*8782922cSAntonio Nino Diaz #define GICC_IIDR_REV_MASK	U(0xf)
89*8782922cSAntonio Nino Diaz #define GICC_IIDR_IMP_MASK	U(0xfff)
90464ce2bbSSoby Mathew 
91464ce2bbSSoby Mathew /* HYP view virtual CPU Interface registers */
92*8782922cSAntonio Nino Diaz #define GICH_CTL		U(0x0)
93*8782922cSAntonio Nino Diaz #define GICH_VTR		U(0x4)
94*8782922cSAntonio Nino Diaz #define GICH_ELRSR0		U(0x30)
95*8782922cSAntonio Nino Diaz #define GICH_ELRSR1		U(0x34)
96*8782922cSAntonio Nino Diaz #define GICH_APR0		U(0xF0)
97*8782922cSAntonio Nino Diaz #define GICH_LR_BASE		U(0x100)
98464ce2bbSSoby Mathew 
99464ce2bbSSoby Mathew /* Virtual CPU Interface registers */
100*8782922cSAntonio Nino Diaz #define GICV_CTL		U(0x0)
101*8782922cSAntonio Nino Diaz #define GICV_PRIMASK		U(0x4)
102*8782922cSAntonio Nino Diaz #define GICV_BP			U(0x8)
103*8782922cSAntonio Nino Diaz #define GICV_INTACK		U(0xC)
104*8782922cSAntonio Nino Diaz #define GICV_EOI		U(0x10)
105*8782922cSAntonio Nino Diaz #define GICV_RUNNINGPRI		U(0x14)
106*8782922cSAntonio Nino Diaz #define GICV_HIGHESTPEND	U(0x18)
107*8782922cSAntonio Nino Diaz #define GICV_DEACTIVATE		U(0x1000)
108464ce2bbSSoby Mathew 
109464ce2bbSSoby Mathew /* GICD_CTLR bit definitions */
110464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_SHIFT		1
111*8782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1_MASK		U(0x1)
112*8782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1_BIT		BIT_32(CTLR_ENABLE_G1_SHIFT)
113464ce2bbSSoby Mathew 
114464ce2bbSSoby Mathew /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
115*8782922cSAntonio Nino Diaz #define INT_ID_MASK		U(0x3ff)
116464ce2bbSSoby Mathew 
117464ce2bbSSoby Mathew #ifndef __ASSEMBLY__
118464ce2bbSSoby Mathew 
11993c78ed2SAntonio Nino Diaz #include <cdefs.h>
120c639e8ebSJeenu Viswambharan #include <interrupt_props.h>
121464ce2bbSSoby Mathew #include <stdint.h>
122464ce2bbSSoby Mathew 
123464ce2bbSSoby Mathew /*******************************************************************************
124464ce2bbSSoby Mathew  * This structure describes some of the implementation defined attributes of
125464ce2bbSSoby Mathew  * the GICv2 IP. It is used by the platform port to specify these attributes
126464ce2bbSSoby Mathew  * in order to initialize the GICv2 driver. The attributes are described
127464ce2bbSSoby Mathew  * below.
128464ce2bbSSoby Mathew  *
129fa9db423SJeenu Viswambharan  * The 'gicd_base' field contains the base address of the Distributor interface
130464ce2bbSSoby Mathew  * programmer's view.
131464ce2bbSSoby Mathew  *
132fa9db423SJeenu Viswambharan  * The 'gicc_base' field contains the base address of the CPU Interface
133fa9db423SJeenu Viswambharan  * programmer's view.
134fa9db423SJeenu Viswambharan  *
135c639e8ebSJeenu Viswambharan  * The 'g0_interrupt_array' field is a pointer to an array in which each entry
136c639e8ebSJeenu Viswambharan  * corresponds to an ID of a Group 0 interrupt. This field is ignored when
137c639e8ebSJeenu Viswambharan  * 'interrupt_props' field is used. This field is deprecated.
138464ce2bbSSoby Mathew  *
139fa9db423SJeenu Viswambharan  * The 'g0_interrupt_num' field contains the number of entries in the
140c639e8ebSJeenu Viswambharan  * 'g0_interrupt_array'. This field is ignored when 'interrupt_props' field is
141c639e8ebSJeenu Viswambharan  * used. This field is deprecated.
142fa9db423SJeenu Viswambharan  *
143fa9db423SJeenu Viswambharan  * The 'target_masks' is a pointer to an array containing 'target_masks_num'
144fa9db423SJeenu Viswambharan  * elements. The GIC driver will populate the array with per-PE target mask to
145fa9db423SJeenu Viswambharan  * use to when targeting interrupts.
146c639e8ebSJeenu Viswambharan  *
147c639e8ebSJeenu Viswambharan  * The 'interrupt_props' field is a pointer to an array that enumerates secure
148c639e8ebSJeenu Viswambharan  * interrupts and their properties. If this field is not NULL, both
149c639e8ebSJeenu Viswambharan  * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
150c639e8ebSJeenu Viswambharan  *
151c639e8ebSJeenu Viswambharan  * The 'interrupt_props_num' field contains the number of entries in the
152c639e8ebSJeenu Viswambharan  * 'interrupt_props' array. If this field is non-zero, 'g0_interrupt_num' is
153c639e8ebSJeenu Viswambharan  * ignored.
154464ce2bbSSoby Mathew  ******************************************************************************/
155464ce2bbSSoby Mathew typedef struct gicv2_driver_data {
156464ce2bbSSoby Mathew 	uintptr_t gicd_base;
157464ce2bbSSoby Mathew 	uintptr_t gicc_base;
158c639e8ebSJeenu Viswambharan #if !ERROR_DEPRECATED
159dcf01a0aSDan Handley 	unsigned int g0_interrupt_num __deprecated;
160dcf01a0aSDan Handley 	const unsigned int *g0_interrupt_array __deprecated;
161c639e8ebSJeenu Viswambharan #endif
162fa9db423SJeenu Viswambharan 	unsigned int *target_masks;
163fa9db423SJeenu Viswambharan 	unsigned int target_masks_num;
164c639e8ebSJeenu Viswambharan 	const interrupt_prop_t *interrupt_props;
165c639e8ebSJeenu Viswambharan 	unsigned int interrupt_props_num;
166464ce2bbSSoby Mathew } gicv2_driver_data_t;
167464ce2bbSSoby Mathew 
168464ce2bbSSoby Mathew /*******************************************************************************
169464ce2bbSSoby Mathew  * Function prototypes
170464ce2bbSSoby Mathew  ******************************************************************************/
171464ce2bbSSoby Mathew void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
172464ce2bbSSoby Mathew void gicv2_distif_init(void);
173464ce2bbSSoby Mathew void gicv2_pcpu_distif_init(void);
174464ce2bbSSoby Mathew void gicv2_cpuif_enable(void);
175464ce2bbSSoby Mathew void gicv2_cpuif_disable(void);
176464ce2bbSSoby Mathew unsigned int gicv2_is_fiq_enabled(void);
177464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_type(void);
178464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_id(void);
179464ce2bbSSoby Mathew unsigned int gicv2_acknowledge_interrupt(void);
180464ce2bbSSoby Mathew void gicv2_end_of_interrupt(unsigned int id);
181464ce2bbSSoby Mathew unsigned int gicv2_get_interrupt_group(unsigned int id);
182eb68ea9bSJeenu Viswambharan unsigned int gicv2_get_running_priority(void);
183fa9db423SJeenu Viswambharan void gicv2_set_pe_target_mask(unsigned int proc_num);
184cbd3f370SJeenu Viswambharan unsigned int gicv2_get_interrupt_active(unsigned int id);
185979225f4SJeenu Viswambharan void gicv2_enable_interrupt(unsigned int id);
186979225f4SJeenu Viswambharan void gicv2_disable_interrupt(unsigned int id);
187f3a86600SJeenu Viswambharan void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority);
18874dce7faSJeenu Viswambharan void gicv2_set_interrupt_type(unsigned int id, unsigned int type);
1898db978b5SJeenu Viswambharan void gicv2_raise_sgi(int sgi_num, int proc_num);
190fc529feeSJeenu Viswambharan void gicv2_set_spi_routing(unsigned int id, int proc_num);
191a2816a16SJeenu Viswambharan void gicv2_set_interrupt_pending(unsigned int id);
192a2816a16SJeenu Viswambharan void gicv2_clear_interrupt_pending(unsigned int id);
193d55a4450SJeenu Viswambharan unsigned int gicv2_set_pmr(unsigned int mask);
194464ce2bbSSoby Mathew 
195464ce2bbSSoby Mathew #endif /* __ASSEMBLY__ */
196464ce2bbSSoby Mathew #endif /* __GICV2_H__ */
197