xref: /rk3399_ARM-atf/include/drivers/arm/gicv2.h (revision e9398e46bc67464ca4882df953bd71850f451530)
1464ce2bbSSoby Mathew /*
2ab80cf35SMadhukar Pappireddy  * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
3dcb31ff7SFlorian Lugou  * Portions copyright (c) 2021-2022, ProvenRun S.A.S. All rights reserved.
4464ce2bbSSoby Mathew  *
582cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
6464ce2bbSSoby Mathew  */
7464ce2bbSSoby Mathew 
8c3cf06f1SAntonio Nino Diaz #ifndef GICV2_H
9c3cf06f1SAntonio Nino Diaz #define GICV2_H
10464ce2bbSSoby Mathew 
1109d40e0eSAntonio Nino Diaz #include <drivers/arm/gic_common.h>
12a7521bd5SStephan Gerhold #include <platform_def.h>
13f9ed3cb6SAntonio Nino Diaz 
14464ce2bbSSoby Mathew /*******************************************************************************
15464ce2bbSSoby Mathew  * GICv2 miscellaneous definitions
16464ce2bbSSoby Mathew  ******************************************************************************/
1774dce7faSJeenu Viswambharan 
1874dce7faSJeenu Viswambharan /* Interrupt group definitions */
198782922cSAntonio Nino Diaz #define GICV2_INTR_GROUP0	U(0)
208782922cSAntonio Nino Diaz #define GICV2_INTR_GROUP1	U(1)
2174dce7faSJeenu Viswambharan 
22464ce2bbSSoby Mathew /* Interrupt IDs reported by the HPPIR and IAR registers */
238782922cSAntonio Nino Diaz #define PENDING_G1_INTID	U(1022)
24464ce2bbSSoby Mathew 
25fa9db423SJeenu Viswambharan /* GICv2 can only target up to 8 PEs */
268782922cSAntonio Nino Diaz #define GICV2_MAX_TARGET_PE	U(8)
27fa9db423SJeenu Viswambharan 
28464ce2bbSSoby Mathew /*******************************************************************************
29464ce2bbSSoby Mathew  * GICv2 specific Distributor interface register offsets and constants.
30464ce2bbSSoby Mathew  ******************************************************************************/
318782922cSAntonio Nino Diaz #define GICD_ITARGETSR		U(0x800)
328782922cSAntonio Nino Diaz #define GICD_SGIR		U(0xF00)
338782922cSAntonio Nino Diaz #define GICD_CPENDSGIR		U(0xF10)
348782922cSAntonio Nino Diaz #define GICD_SPENDSGIR		U(0xF20)
35a7521bd5SStephan Gerhold 
36a7521bd5SStephan Gerhold /*
37a7521bd5SStephan Gerhold  * Some GICv2 implementations violate the specification and have this register
38a7521bd5SStephan Gerhold  * at a different address. Allow overriding it in platform_def.h as workaround.
39a7521bd5SStephan Gerhold  */
40a7521bd5SStephan Gerhold #ifndef GICD_PIDR2_GICV2
418782922cSAntonio Nino Diaz #define GICD_PIDR2_GICV2	U(0xFE8)
42a7521bd5SStephan Gerhold #endif
43464ce2bbSSoby Mathew 
44464ce2bbSSoby Mathew #define ITARGETSR_SHIFT		2
458782922cSAntonio Nino Diaz #define GIC_TARGET_CPU_MASK	U(0xff)
46464ce2bbSSoby Mathew 
47464ce2bbSSoby Mathew #define CPENDSGIR_SHIFT		2
48464ce2bbSSoby Mathew #define SPENDSGIR_SHIFT		CPENDSGIR_SHIFT
49464ce2bbSSoby Mathew 
508db978b5SJeenu Viswambharan #define SGIR_TGTLSTFLT_SHIFT	24
518782922cSAntonio Nino Diaz #define SGIR_TGTLSTFLT_MASK	U(0x3)
528db978b5SJeenu Viswambharan #define SGIR_TGTLST_SHIFT	16
538782922cSAntonio Nino Diaz #define SGIR_TGTLST_MASK	U(0xff)
54*eef240cfSJacob Kroon #define SGIR_NSATT		(U(0x1) << 15)
558782922cSAntonio Nino Diaz #define SGIR_INTID_MASK		ULL(0xf)
568db978b5SJeenu Viswambharan 
578782922cSAntonio Nino Diaz #define SGIR_TGT_SPECIFIC	U(0)
588db978b5SJeenu Viswambharan 
59dcb31ff7SFlorian Lugou #define GICV2_SGIR_VALUE(tgt_lst_flt, tgt, nsatt, intid) \
608db978b5SJeenu Viswambharan 	((((tgt_lst_flt) & SGIR_TGTLSTFLT_MASK) << SGIR_TGTLSTFLT_SHIFT) | \
618db978b5SJeenu Viswambharan 	 (((tgt) & SGIR_TGTLST_MASK) << SGIR_TGTLST_SHIFT) | \
62dcb31ff7SFlorian Lugou 	 ((nsatt) ? SGIR_NSATT : U(0)) | \
638db978b5SJeenu Viswambharan 	 ((intid) & SGIR_INTID_MASK))
648db978b5SJeenu Viswambharan 
65464ce2bbSSoby Mathew /*******************************************************************************
66464ce2bbSSoby Mathew  * GICv2 specific CPU interface register offsets and constants.
67464ce2bbSSoby Mathew  ******************************************************************************/
68464ce2bbSSoby Mathew /* Physical CPU Interface registers */
698782922cSAntonio Nino Diaz #define GICC_CTLR		U(0x0)
708782922cSAntonio Nino Diaz #define GICC_PMR		U(0x4)
718782922cSAntonio Nino Diaz #define GICC_BPR		U(0x8)
728782922cSAntonio Nino Diaz #define GICC_IAR		U(0xC)
738782922cSAntonio Nino Diaz #define GICC_EOIR		U(0x10)
748782922cSAntonio Nino Diaz #define GICC_RPR		U(0x14)
758782922cSAntonio Nino Diaz #define GICC_HPPIR		U(0x18)
768782922cSAntonio Nino Diaz #define GICC_AHPPIR		U(0x28)
778782922cSAntonio Nino Diaz #define GICC_IIDR		U(0xFC)
788782922cSAntonio Nino Diaz #define GICC_DIR		U(0x1000)
79464ce2bbSSoby Mathew #define GICC_PRIODROP		GICC_EOIR
80464ce2bbSSoby Mathew 
81464ce2bbSSoby Mathew /* GICC_CTLR bit definitions */
828782922cSAntonio Nino Diaz #define EOI_MODE_NS		BIT_32(10)
838782922cSAntonio Nino Diaz #define EOI_MODE_S		BIT_32(9)
848782922cSAntonio Nino Diaz #define IRQ_BYP_DIS_GRP1	BIT_32(8)
858782922cSAntonio Nino Diaz #define FIQ_BYP_DIS_GRP1	BIT_32(7)
868782922cSAntonio Nino Diaz #define IRQ_BYP_DIS_GRP0	BIT_32(6)
878782922cSAntonio Nino Diaz #define FIQ_BYP_DIS_GRP0	BIT_32(5)
888782922cSAntonio Nino Diaz #define CBPR			BIT_32(4)
89464ce2bbSSoby Mathew #define FIQ_EN_SHIFT		3
908782922cSAntonio Nino Diaz #define FIQ_EN_BIT		BIT_32(FIQ_EN_SHIFT)
918782922cSAntonio Nino Diaz #define ACK_CTL			BIT_32(2)
92464ce2bbSSoby Mathew 
93464ce2bbSSoby Mathew /* GICC_IIDR bit masks and shifts */
94464ce2bbSSoby Mathew #define GICC_IIDR_PID_SHIFT	20
95464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_SHIFT	16
96464ce2bbSSoby Mathew #define GICC_IIDR_REV_SHIFT	12
97464ce2bbSSoby Mathew #define GICC_IIDR_IMP_SHIFT	0
98464ce2bbSSoby Mathew 
998782922cSAntonio Nino Diaz #define GICC_IIDR_PID_MASK	U(0xfff)
1008782922cSAntonio Nino Diaz #define GICC_IIDR_ARCH_MASK	U(0xf)
1018782922cSAntonio Nino Diaz #define GICC_IIDR_REV_MASK	U(0xf)
1028782922cSAntonio Nino Diaz #define GICC_IIDR_IMP_MASK	U(0xfff)
103464ce2bbSSoby Mathew 
104464ce2bbSSoby Mathew /* HYP view virtual CPU Interface registers */
1058782922cSAntonio Nino Diaz #define GICH_CTL		U(0x0)
1068782922cSAntonio Nino Diaz #define GICH_VTR		U(0x4)
1078782922cSAntonio Nino Diaz #define GICH_ELRSR0		U(0x30)
1088782922cSAntonio Nino Diaz #define GICH_ELRSR1		U(0x34)
1098782922cSAntonio Nino Diaz #define GICH_APR0		U(0xF0)
1108782922cSAntonio Nino Diaz #define GICH_LR_BASE		U(0x100)
111464ce2bbSSoby Mathew 
112464ce2bbSSoby Mathew /* Virtual CPU Interface registers */
1138782922cSAntonio Nino Diaz #define GICV_CTL		U(0x0)
1148782922cSAntonio Nino Diaz #define GICV_PRIMASK		U(0x4)
1158782922cSAntonio Nino Diaz #define GICV_BP			U(0x8)
1168782922cSAntonio Nino Diaz #define GICV_INTACK		U(0xC)
1178782922cSAntonio Nino Diaz #define GICV_EOI		U(0x10)
1188782922cSAntonio Nino Diaz #define GICV_RUNNINGPRI		U(0x14)
1198782922cSAntonio Nino Diaz #define GICV_HIGHESTPEND	U(0x18)
1208782922cSAntonio Nino Diaz #define GICV_DEACTIVATE		U(0x1000)
121464ce2bbSSoby Mathew 
122464ce2bbSSoby Mathew /* GICD_CTLR bit definitions */
123464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_SHIFT		1
1248782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1_MASK		U(0x1)
1258782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1_BIT		BIT_32(CTLR_ENABLE_G1_SHIFT)
126464ce2bbSSoby Mathew 
127464ce2bbSSoby Mathew /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
1288782922cSAntonio Nino Diaz #define INT_ID_MASK		U(0x3ff)
129464ce2bbSSoby Mathew 
130d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
131464ce2bbSSoby Mathew 
13293c78ed2SAntonio Nino Diaz #include <cdefs.h>
133dcb31ff7SFlorian Lugou #include <stdbool.h>
134464ce2bbSSoby Mathew #include <stdint.h>
135464ce2bbSSoby Mathew 
13609d40e0eSAntonio Nino Diaz #include <common/interrupt_props.h>
13709d40e0eSAntonio Nino Diaz 
138464ce2bbSSoby Mathew /*******************************************************************************
139464ce2bbSSoby Mathew  * This structure describes some of the implementation defined attributes of
140464ce2bbSSoby Mathew  * the GICv2 IP. It is used by the platform port to specify these attributes
141464ce2bbSSoby Mathew  * in order to initialize the GICv2 driver. The attributes are described
142464ce2bbSSoby Mathew  * below.
143464ce2bbSSoby Mathew  *
144fa9db423SJeenu Viswambharan  * The 'gicd_base' field contains the base address of the Distributor interface
145464ce2bbSSoby Mathew  * programmer's view.
146464ce2bbSSoby Mathew  *
147fa9db423SJeenu Viswambharan  * The 'gicc_base' field contains the base address of the CPU Interface
148fa9db423SJeenu Viswambharan  * programmer's view.
149fa9db423SJeenu Viswambharan  *
150fa9db423SJeenu Viswambharan  * The 'target_masks' is a pointer to an array containing 'target_masks_num'
151fa9db423SJeenu Viswambharan  * elements. The GIC driver will populate the array with per-PE target mask to
152fa9db423SJeenu Viswambharan  * use to when targeting interrupts.
153c639e8ebSJeenu Viswambharan  *
154c639e8ebSJeenu Viswambharan  * The 'interrupt_props' field is a pointer to an array that enumerates secure
155c639e8ebSJeenu Viswambharan  * interrupts and their properties. If this field is not NULL, both
156c639e8ebSJeenu Viswambharan  * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
157c639e8ebSJeenu Viswambharan  *
158c639e8ebSJeenu Viswambharan  * The 'interrupt_props_num' field contains the number of entries in the
159c639e8ebSJeenu Viswambharan  * 'interrupt_props' array. If this field is non-zero, 'g0_interrupt_num' is
160c639e8ebSJeenu Viswambharan  * ignored.
161464ce2bbSSoby Mathew  ******************************************************************************/
162464ce2bbSSoby Mathew typedef struct gicv2_driver_data {
163464ce2bbSSoby Mathew 	uintptr_t gicd_base;
164464ce2bbSSoby Mathew 	uintptr_t gicc_base;
165fa9db423SJeenu Viswambharan 	unsigned int *target_masks;
166fa9db423SJeenu Viswambharan 	unsigned int target_masks_num;
167c639e8ebSJeenu Viswambharan 	const interrupt_prop_t *interrupt_props;
168c639e8ebSJeenu Viswambharan 	unsigned int interrupt_props_num;
169464ce2bbSSoby Mathew } gicv2_driver_data_t;
170464ce2bbSSoby Mathew 
171464ce2bbSSoby Mathew /*******************************************************************************
172464ce2bbSSoby Mathew  * Function prototypes
173464ce2bbSSoby Mathew  ******************************************************************************/
174464ce2bbSSoby Mathew void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
175464ce2bbSSoby Mathew void gicv2_distif_init(void);
176464ce2bbSSoby Mathew void gicv2_pcpu_distif_init(void);
177464ce2bbSSoby Mathew void gicv2_cpuif_enable(void);
178464ce2bbSSoby Mathew void gicv2_cpuif_disable(void);
179464ce2bbSSoby Mathew unsigned int gicv2_is_fiq_enabled(void);
180464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_type(void);
181464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_id(void);
182464ce2bbSSoby Mathew unsigned int gicv2_acknowledge_interrupt(void);
183464ce2bbSSoby Mathew void gicv2_end_of_interrupt(unsigned int id);
184464ce2bbSSoby Mathew unsigned int gicv2_get_interrupt_group(unsigned int id);
185eb68ea9bSJeenu Viswambharan unsigned int gicv2_get_running_priority(void);
186fa9db423SJeenu Viswambharan void gicv2_set_pe_target_mask(unsigned int proc_num);
187cbd3f370SJeenu Viswambharan unsigned int gicv2_get_interrupt_active(unsigned int id);
188979225f4SJeenu Viswambharan void gicv2_enable_interrupt(unsigned int id);
189979225f4SJeenu Viswambharan void gicv2_disable_interrupt(unsigned int id);
190f3a86600SJeenu Viswambharan void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority);
191ab80cf35SMadhukar Pappireddy void gicv2_set_interrupt_group(unsigned int id, unsigned int group);
192dcb31ff7SFlorian Lugou void gicv2_raise_sgi(int sgi_num, bool ns, int proc_num);
193fc529feeSJeenu Viswambharan void gicv2_set_spi_routing(unsigned int id, int proc_num);
194a2816a16SJeenu Viswambharan void gicv2_set_interrupt_pending(unsigned int id);
195a2816a16SJeenu Viswambharan void gicv2_clear_interrupt_pending(unsigned int id);
196d55a4450SJeenu Viswambharan unsigned int gicv2_set_pmr(unsigned int mask);
1974acd900dSMarcin Wojtas void gicv2_interrupt_set_cfg(unsigned int id, unsigned int cfg);
198464ce2bbSSoby Mathew 
199d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
200c3cf06f1SAntonio Nino Diaz #endif /* GICV2_H */
201