xref: /rk3399_ARM-atf/include/drivers/arm/gicv2.h (revision a7521bd5d887bfd69d99a55a81416e38ba9ebc97)
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 
7c3cf06f1SAntonio Nino Diaz #ifndef GICV2_H
8c3cf06f1SAntonio Nino Diaz #define GICV2_H
9464ce2bbSSoby Mathew 
1009d40e0eSAntonio Nino Diaz #include <drivers/arm/gic_common.h>
11*a7521bd5SStephan Gerhold #include <platform_def.h>
12f9ed3cb6SAntonio Nino Diaz 
13464ce2bbSSoby Mathew /*******************************************************************************
14464ce2bbSSoby Mathew  * GICv2 miscellaneous definitions
15464ce2bbSSoby Mathew  ******************************************************************************/
1674dce7faSJeenu Viswambharan 
1774dce7faSJeenu Viswambharan /* Interrupt group definitions */
188782922cSAntonio Nino Diaz #define GICV2_INTR_GROUP0	U(0)
198782922cSAntonio Nino Diaz #define GICV2_INTR_GROUP1	U(1)
2074dce7faSJeenu Viswambharan 
21464ce2bbSSoby Mathew /* Interrupt IDs reported by the HPPIR and IAR registers */
228782922cSAntonio Nino Diaz #define PENDING_G1_INTID	U(1022)
23464ce2bbSSoby Mathew 
24fa9db423SJeenu Viswambharan /* GICv2 can only target up to 8 PEs */
258782922cSAntonio Nino Diaz #define GICV2_MAX_TARGET_PE	U(8)
26fa9db423SJeenu Viswambharan 
27464ce2bbSSoby Mathew /*******************************************************************************
28464ce2bbSSoby Mathew  * GICv2 specific Distributor interface register offsets and constants.
29464ce2bbSSoby Mathew  ******************************************************************************/
308782922cSAntonio Nino Diaz #define GICD_ITARGETSR		U(0x800)
318782922cSAntonio Nino Diaz #define GICD_SGIR		U(0xF00)
328782922cSAntonio Nino Diaz #define GICD_CPENDSGIR		U(0xF10)
338782922cSAntonio Nino Diaz #define GICD_SPENDSGIR		U(0xF20)
34*a7521bd5SStephan Gerhold 
35*a7521bd5SStephan Gerhold /*
36*a7521bd5SStephan Gerhold  * Some GICv2 implementations violate the specification and have this register
37*a7521bd5SStephan Gerhold  * at a different address. Allow overriding it in platform_def.h as workaround.
38*a7521bd5SStephan Gerhold  */
39*a7521bd5SStephan Gerhold #ifndef GICD_PIDR2_GICV2
408782922cSAntonio Nino Diaz #define GICD_PIDR2_GICV2	U(0xFE8)
41*a7521bd5SStephan Gerhold #endif
42464ce2bbSSoby Mathew 
43464ce2bbSSoby Mathew #define ITARGETSR_SHIFT		2
448782922cSAntonio Nino Diaz #define GIC_TARGET_CPU_MASK	U(0xff)
45464ce2bbSSoby Mathew 
46464ce2bbSSoby Mathew #define CPENDSGIR_SHIFT		2
47464ce2bbSSoby Mathew #define SPENDSGIR_SHIFT		CPENDSGIR_SHIFT
48464ce2bbSSoby Mathew 
498db978b5SJeenu Viswambharan #define SGIR_TGTLSTFLT_SHIFT	24
508782922cSAntonio Nino Diaz #define SGIR_TGTLSTFLT_MASK	U(0x3)
518db978b5SJeenu Viswambharan #define SGIR_TGTLST_SHIFT	16
528782922cSAntonio Nino Diaz #define SGIR_TGTLST_MASK	U(0xff)
538782922cSAntonio Nino Diaz #define SGIR_INTID_MASK		ULL(0xf)
548db978b5SJeenu Viswambharan 
558782922cSAntonio Nino Diaz #define SGIR_TGT_SPECIFIC	U(0)
568db978b5SJeenu Viswambharan 
578db978b5SJeenu Viswambharan #define GICV2_SGIR_VALUE(tgt_lst_flt, tgt, intid) \
588db978b5SJeenu Viswambharan 	((((tgt_lst_flt) & SGIR_TGTLSTFLT_MASK) << SGIR_TGTLSTFLT_SHIFT) | \
598db978b5SJeenu Viswambharan 	 (((tgt) & SGIR_TGTLST_MASK) << SGIR_TGTLST_SHIFT) | \
608db978b5SJeenu Viswambharan 	 ((intid) & SGIR_INTID_MASK))
618db978b5SJeenu Viswambharan 
62464ce2bbSSoby Mathew /*******************************************************************************
63464ce2bbSSoby Mathew  * GICv2 specific CPU interface register offsets and constants.
64464ce2bbSSoby Mathew  ******************************************************************************/
65464ce2bbSSoby Mathew /* Physical CPU Interface registers */
668782922cSAntonio Nino Diaz #define GICC_CTLR		U(0x0)
678782922cSAntonio Nino Diaz #define GICC_PMR		U(0x4)
688782922cSAntonio Nino Diaz #define GICC_BPR		U(0x8)
698782922cSAntonio Nino Diaz #define GICC_IAR		U(0xC)
708782922cSAntonio Nino Diaz #define GICC_EOIR		U(0x10)
718782922cSAntonio Nino Diaz #define GICC_RPR		U(0x14)
728782922cSAntonio Nino Diaz #define GICC_HPPIR		U(0x18)
738782922cSAntonio Nino Diaz #define GICC_AHPPIR		U(0x28)
748782922cSAntonio Nino Diaz #define GICC_IIDR		U(0xFC)
758782922cSAntonio Nino Diaz #define GICC_DIR		U(0x1000)
76464ce2bbSSoby Mathew #define GICC_PRIODROP		GICC_EOIR
77464ce2bbSSoby Mathew 
78464ce2bbSSoby Mathew /* GICC_CTLR bit definitions */
798782922cSAntonio Nino Diaz #define EOI_MODE_NS		BIT_32(10)
808782922cSAntonio Nino Diaz #define EOI_MODE_S		BIT_32(9)
818782922cSAntonio Nino Diaz #define IRQ_BYP_DIS_GRP1	BIT_32(8)
828782922cSAntonio Nino Diaz #define FIQ_BYP_DIS_GRP1	BIT_32(7)
838782922cSAntonio Nino Diaz #define IRQ_BYP_DIS_GRP0	BIT_32(6)
848782922cSAntonio Nino Diaz #define FIQ_BYP_DIS_GRP0	BIT_32(5)
858782922cSAntonio Nino Diaz #define CBPR			BIT_32(4)
86464ce2bbSSoby Mathew #define FIQ_EN_SHIFT		3
878782922cSAntonio Nino Diaz #define FIQ_EN_BIT		BIT_32(FIQ_EN_SHIFT)
888782922cSAntonio Nino Diaz #define ACK_CTL			BIT_32(2)
89464ce2bbSSoby Mathew 
90464ce2bbSSoby Mathew /* GICC_IIDR bit masks and shifts */
91464ce2bbSSoby Mathew #define GICC_IIDR_PID_SHIFT	20
92464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_SHIFT	16
93464ce2bbSSoby Mathew #define GICC_IIDR_REV_SHIFT	12
94464ce2bbSSoby Mathew #define GICC_IIDR_IMP_SHIFT	0
95464ce2bbSSoby Mathew 
968782922cSAntonio Nino Diaz #define GICC_IIDR_PID_MASK	U(0xfff)
978782922cSAntonio Nino Diaz #define GICC_IIDR_ARCH_MASK	U(0xf)
988782922cSAntonio Nino Diaz #define GICC_IIDR_REV_MASK	U(0xf)
998782922cSAntonio Nino Diaz #define GICC_IIDR_IMP_MASK	U(0xfff)
100464ce2bbSSoby Mathew 
101464ce2bbSSoby Mathew /* HYP view virtual CPU Interface registers */
1028782922cSAntonio Nino Diaz #define GICH_CTL		U(0x0)
1038782922cSAntonio Nino Diaz #define GICH_VTR		U(0x4)
1048782922cSAntonio Nino Diaz #define GICH_ELRSR0		U(0x30)
1058782922cSAntonio Nino Diaz #define GICH_ELRSR1		U(0x34)
1068782922cSAntonio Nino Diaz #define GICH_APR0		U(0xF0)
1078782922cSAntonio Nino Diaz #define GICH_LR_BASE		U(0x100)
108464ce2bbSSoby Mathew 
109464ce2bbSSoby Mathew /* Virtual CPU Interface registers */
1108782922cSAntonio Nino Diaz #define GICV_CTL		U(0x0)
1118782922cSAntonio Nino Diaz #define GICV_PRIMASK		U(0x4)
1128782922cSAntonio Nino Diaz #define GICV_BP			U(0x8)
1138782922cSAntonio Nino Diaz #define GICV_INTACK		U(0xC)
1148782922cSAntonio Nino Diaz #define GICV_EOI		U(0x10)
1158782922cSAntonio Nino Diaz #define GICV_RUNNINGPRI		U(0x14)
1168782922cSAntonio Nino Diaz #define GICV_HIGHESTPEND	U(0x18)
1178782922cSAntonio Nino Diaz #define GICV_DEACTIVATE		U(0x1000)
118464ce2bbSSoby Mathew 
119464ce2bbSSoby Mathew /* GICD_CTLR bit definitions */
120464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_SHIFT		1
1218782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1_MASK		U(0x1)
1228782922cSAntonio Nino Diaz #define CTLR_ENABLE_G1_BIT		BIT_32(CTLR_ENABLE_G1_SHIFT)
123464ce2bbSSoby Mathew 
124464ce2bbSSoby Mathew /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
1258782922cSAntonio Nino Diaz #define INT_ID_MASK		U(0x3ff)
126464ce2bbSSoby Mathew 
127d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
128464ce2bbSSoby Mathew 
12993c78ed2SAntonio Nino Diaz #include <cdefs.h>
130464ce2bbSSoby Mathew #include <stdint.h>
131464ce2bbSSoby Mathew 
13209d40e0eSAntonio Nino Diaz #include <common/interrupt_props.h>
13309d40e0eSAntonio Nino Diaz 
134464ce2bbSSoby Mathew /*******************************************************************************
135464ce2bbSSoby Mathew  * This structure describes some of the implementation defined attributes of
136464ce2bbSSoby Mathew  * the GICv2 IP. It is used by the platform port to specify these attributes
137464ce2bbSSoby Mathew  * in order to initialize the GICv2 driver. The attributes are described
138464ce2bbSSoby Mathew  * below.
139464ce2bbSSoby Mathew  *
140fa9db423SJeenu Viswambharan  * The 'gicd_base' field contains the base address of the Distributor interface
141464ce2bbSSoby Mathew  * programmer's view.
142464ce2bbSSoby Mathew  *
143fa9db423SJeenu Viswambharan  * The 'gicc_base' field contains the base address of the CPU Interface
144fa9db423SJeenu Viswambharan  * programmer's view.
145fa9db423SJeenu Viswambharan  *
146fa9db423SJeenu Viswambharan  * The 'target_masks' is a pointer to an array containing 'target_masks_num'
147fa9db423SJeenu Viswambharan  * elements. The GIC driver will populate the array with per-PE target mask to
148fa9db423SJeenu Viswambharan  * use to when targeting interrupts.
149c639e8ebSJeenu Viswambharan  *
150c639e8ebSJeenu Viswambharan  * The 'interrupt_props' field is a pointer to an array that enumerates secure
151c639e8ebSJeenu Viswambharan  * interrupts and their properties. If this field is not NULL, both
152c639e8ebSJeenu Viswambharan  * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
153c639e8ebSJeenu Viswambharan  *
154c639e8ebSJeenu Viswambharan  * The 'interrupt_props_num' field contains the number of entries in the
155c639e8ebSJeenu Viswambharan  * 'interrupt_props' array. If this field is non-zero, 'g0_interrupt_num' is
156c639e8ebSJeenu Viswambharan  * ignored.
157464ce2bbSSoby Mathew  ******************************************************************************/
158464ce2bbSSoby Mathew typedef struct gicv2_driver_data {
159464ce2bbSSoby Mathew 	uintptr_t gicd_base;
160464ce2bbSSoby Mathew 	uintptr_t gicc_base;
161fa9db423SJeenu Viswambharan 	unsigned int *target_masks;
162fa9db423SJeenu Viswambharan 	unsigned int target_masks_num;
163c639e8ebSJeenu Viswambharan 	const interrupt_prop_t *interrupt_props;
164c639e8ebSJeenu Viswambharan 	unsigned int interrupt_props_num;
165464ce2bbSSoby Mathew } gicv2_driver_data_t;
166464ce2bbSSoby Mathew 
167464ce2bbSSoby Mathew /*******************************************************************************
168464ce2bbSSoby Mathew  * Function prototypes
169464ce2bbSSoby Mathew  ******************************************************************************/
170464ce2bbSSoby Mathew void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
171464ce2bbSSoby Mathew void gicv2_distif_init(void);
172464ce2bbSSoby Mathew void gicv2_pcpu_distif_init(void);
173464ce2bbSSoby Mathew void gicv2_cpuif_enable(void);
174464ce2bbSSoby Mathew void gicv2_cpuif_disable(void);
175464ce2bbSSoby Mathew unsigned int gicv2_is_fiq_enabled(void);
176464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_type(void);
177464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_id(void);
178464ce2bbSSoby Mathew unsigned int gicv2_acknowledge_interrupt(void);
179464ce2bbSSoby Mathew void gicv2_end_of_interrupt(unsigned int id);
180464ce2bbSSoby Mathew unsigned int gicv2_get_interrupt_group(unsigned int id);
181eb68ea9bSJeenu Viswambharan unsigned int gicv2_get_running_priority(void);
182fa9db423SJeenu Viswambharan void gicv2_set_pe_target_mask(unsigned int proc_num);
183cbd3f370SJeenu Viswambharan unsigned int gicv2_get_interrupt_active(unsigned int id);
184979225f4SJeenu Viswambharan void gicv2_enable_interrupt(unsigned int id);
185979225f4SJeenu Viswambharan void gicv2_disable_interrupt(unsigned int id);
186f3a86600SJeenu Viswambharan void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority);
18774dce7faSJeenu Viswambharan void gicv2_set_interrupt_type(unsigned int id, unsigned int type);
1888db978b5SJeenu Viswambharan void gicv2_raise_sgi(int sgi_num, int proc_num);
189fc529feeSJeenu Viswambharan void gicv2_set_spi_routing(unsigned int id, int proc_num);
190a2816a16SJeenu Viswambharan void gicv2_set_interrupt_pending(unsigned int id);
191a2816a16SJeenu Viswambharan void gicv2_clear_interrupt_pending(unsigned int id);
192d55a4450SJeenu Viswambharan unsigned int gicv2_set_pmr(unsigned int mask);
1934acd900dSMarcin Wojtas void gicv2_interrupt_set_cfg(unsigned int id, unsigned int cfg);
194464ce2bbSSoby Mathew 
195d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
196c3cf06f1SAntonio Nino Diaz #endif /* GICV2_H */
197