xref: /rk3399_ARM-atf/include/drivers/arm/gicv2.h (revision a2816a16440d9eb1223ba505bc30faf6cd31b0ee)
1464ce2bbSSoby Mathew /*
2eb68ea9bSJeenu Viswambharan  * Copyright (c) 2015-2017, 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 */
1574dce7faSJeenu Viswambharan #define GICV2_INTR_GROUP0	0
1674dce7faSJeenu Viswambharan #define GICV2_INTR_GROUP1	1
1774dce7faSJeenu Viswambharan 
18464ce2bbSSoby Mathew /* Interrupt IDs reported by the HPPIR and IAR registers */
19464ce2bbSSoby Mathew #define PENDING_G1_INTID	1022
20464ce2bbSSoby Mathew 
21fa9db423SJeenu Viswambharan /* GICv2 can only target up to 8 PEs */
22fa9db423SJeenu Viswambharan #define GICV2_MAX_TARGET_PE	8
23fa9db423SJeenu Viswambharan 
24464ce2bbSSoby Mathew /*******************************************************************************
25464ce2bbSSoby Mathew  * GICv2 specific Distributor interface register offsets and constants.
26464ce2bbSSoby Mathew  ******************************************************************************/
27464ce2bbSSoby Mathew #define GICD_ITARGETSR		0x800
28464ce2bbSSoby Mathew #define GICD_SGIR		0xF00
29464ce2bbSSoby Mathew #define GICD_CPENDSGIR		0xF10
30464ce2bbSSoby Mathew #define GICD_SPENDSGIR		0xF20
31464ce2bbSSoby Mathew #define GICD_PIDR2_GICV2	0xFE8
32464ce2bbSSoby Mathew 
33464ce2bbSSoby Mathew #define ITARGETSR_SHIFT		2
34464ce2bbSSoby Mathew #define GIC_TARGET_CPU_MASK	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
408db978b5SJeenu Viswambharan #define SGIR_TGTLSTFLT_MASK	0x3
418db978b5SJeenu Viswambharan #define SGIR_TGTLST_SHIFT	16
428db978b5SJeenu Viswambharan #define SGIR_TGTLST_MASK	0xff
438db978b5SJeenu Viswambharan #define SGIR_INTID_MASK		0xf
448db978b5SJeenu Viswambharan 
458db978b5SJeenu Viswambharan #define SGIR_TGT_SPECIFIC	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 */
56464ce2bbSSoby Mathew #define GICC_CTLR		0x0
57464ce2bbSSoby Mathew #define GICC_PMR		0x4
58464ce2bbSSoby Mathew #define GICC_BPR		0x8
59464ce2bbSSoby Mathew #define GICC_IAR		0xC
60464ce2bbSSoby Mathew #define GICC_EOIR		0x10
61464ce2bbSSoby Mathew #define GICC_RPR		0x14
62464ce2bbSSoby Mathew #define GICC_HPPIR		0x18
63464ce2bbSSoby Mathew #define GICC_AHPPIR		0x28
64464ce2bbSSoby Mathew #define GICC_IIDR		0xFC
65464ce2bbSSoby Mathew #define GICC_DIR		0x1000
66464ce2bbSSoby Mathew #define GICC_PRIODROP		GICC_EOIR
67464ce2bbSSoby Mathew 
68464ce2bbSSoby Mathew /* GICC_CTLR bit definitions */
69464ce2bbSSoby Mathew #define EOI_MODE_NS		(1 << 10)
70464ce2bbSSoby Mathew #define EOI_MODE_S		(1 << 9)
71464ce2bbSSoby Mathew #define IRQ_BYP_DIS_GRP1	(1 << 8)
72464ce2bbSSoby Mathew #define FIQ_BYP_DIS_GRP1	(1 << 7)
73464ce2bbSSoby Mathew #define IRQ_BYP_DIS_GRP0	(1 << 6)
74464ce2bbSSoby Mathew #define FIQ_BYP_DIS_GRP0	(1 << 5)
75464ce2bbSSoby Mathew #define CBPR			(1 << 4)
76464ce2bbSSoby Mathew #define FIQ_EN_SHIFT		3
77464ce2bbSSoby Mathew #define FIQ_EN_BIT		(1 << FIQ_EN_SHIFT)
78464ce2bbSSoby Mathew #define ACK_CTL			(1 << 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 
86464ce2bbSSoby Mathew #define GICC_IIDR_PID_MASK	0xfff
87464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_MASK	0xf
88464ce2bbSSoby Mathew #define GICC_IIDR_REV_MASK	0xf
89464ce2bbSSoby Mathew #define GICC_IIDR_IMP_MASK	0xfff
90464ce2bbSSoby Mathew 
91464ce2bbSSoby Mathew /* HYP view virtual CPU Interface registers */
92464ce2bbSSoby Mathew #define GICH_CTL		0x0
93464ce2bbSSoby Mathew #define GICH_VTR		0x4
94464ce2bbSSoby Mathew #define GICH_ELRSR0		0x30
95464ce2bbSSoby Mathew #define GICH_ELRSR1		0x34
96464ce2bbSSoby Mathew #define GICH_APR0		0xF0
97464ce2bbSSoby Mathew #define GICH_LR_BASE		0x100
98464ce2bbSSoby Mathew 
99464ce2bbSSoby Mathew /* Virtual CPU Interface registers */
100464ce2bbSSoby Mathew #define GICV_CTL		0x0
101464ce2bbSSoby Mathew #define GICV_PRIMASK		0x4
102464ce2bbSSoby Mathew #define GICV_BP			0x8
103464ce2bbSSoby Mathew #define GICV_INTACK		0xC
104464ce2bbSSoby Mathew #define GICV_EOI		0x10
105464ce2bbSSoby Mathew #define GICV_RUNNINGPRI		0x14
106464ce2bbSSoby Mathew #define GICV_HIGHESTPEND	0x18
107464ce2bbSSoby Mathew #define GICV_DEACTIVATE		0x1000
108464ce2bbSSoby Mathew 
109464ce2bbSSoby Mathew /* GICD_CTLR bit definitions */
110464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_SHIFT		1
111464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_MASK		0x1
112464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_BIT		(1 << CTLR_ENABLE_G1_SHIFT)
113464ce2bbSSoby Mathew 
114464ce2bbSSoby Mathew /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
115464ce2bbSSoby Mathew #define INT_ID_MASK		0x3ff
116464ce2bbSSoby Mathew 
117464ce2bbSSoby Mathew #ifndef __ASSEMBLY__
118464ce2bbSSoby Mathew 
119464ce2bbSSoby Mathew #include <stdint.h>
120464ce2bbSSoby Mathew 
121464ce2bbSSoby Mathew /*******************************************************************************
122464ce2bbSSoby Mathew  * This structure describes some of the implementation defined attributes of
123464ce2bbSSoby Mathew  * the GICv2 IP. It is used by the platform port to specify these attributes
124464ce2bbSSoby Mathew  * in order to initialize the GICv2 driver. The attributes are described
125464ce2bbSSoby Mathew  * below.
126464ce2bbSSoby Mathew  *
127fa9db423SJeenu Viswambharan  * The 'gicd_base' field contains the base address of the Distributor interface
128464ce2bbSSoby Mathew  * programmer's view.
129464ce2bbSSoby Mathew  *
130fa9db423SJeenu Viswambharan  * The 'gicc_base' field contains the base address of the CPU Interface
131fa9db423SJeenu Viswambharan  * programmer's view.
132fa9db423SJeenu Viswambharan  *
133fa9db423SJeenu Viswambharan  * The 'g0_interrupt_array' field is a pointer to an array in which each
134464ce2bbSSoby Mathew  * entry corresponds to an ID of a Group 0 interrupt.
135464ce2bbSSoby Mathew  *
136fa9db423SJeenu Viswambharan  * The 'g0_interrupt_num' field contains the number of entries in the
137464ce2bbSSoby Mathew  * 'g0_interrupt_array'.
138fa9db423SJeenu Viswambharan  *
139fa9db423SJeenu Viswambharan  * The 'target_masks' is a pointer to an array containing 'target_masks_num'
140fa9db423SJeenu Viswambharan  * elements. The GIC driver will populate the array with per-PE target mask to
141fa9db423SJeenu Viswambharan  * use to when targeting interrupts.
142464ce2bbSSoby Mathew  ******************************************************************************/
143464ce2bbSSoby Mathew typedef struct gicv2_driver_data {
144464ce2bbSSoby Mathew 	uintptr_t gicd_base;
145464ce2bbSSoby Mathew 	uintptr_t gicc_base;
146464ce2bbSSoby Mathew 	unsigned int g0_interrupt_num;
147464ce2bbSSoby Mathew 	const unsigned int *g0_interrupt_array;
148fa9db423SJeenu Viswambharan 	unsigned int *target_masks;
149fa9db423SJeenu Viswambharan 	unsigned int target_masks_num;
150464ce2bbSSoby Mathew } gicv2_driver_data_t;
151464ce2bbSSoby Mathew 
152464ce2bbSSoby Mathew /*******************************************************************************
153464ce2bbSSoby Mathew  * Function prototypes
154464ce2bbSSoby Mathew  ******************************************************************************/
155464ce2bbSSoby Mathew void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
156464ce2bbSSoby Mathew void gicv2_distif_init(void);
157464ce2bbSSoby Mathew void gicv2_pcpu_distif_init(void);
158464ce2bbSSoby Mathew void gicv2_cpuif_enable(void);
159464ce2bbSSoby Mathew void gicv2_cpuif_disable(void);
160464ce2bbSSoby Mathew unsigned int gicv2_is_fiq_enabled(void);
161464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_type(void);
162464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_id(void);
163464ce2bbSSoby Mathew unsigned int gicv2_acknowledge_interrupt(void);
164464ce2bbSSoby Mathew void gicv2_end_of_interrupt(unsigned int id);
165464ce2bbSSoby Mathew unsigned int gicv2_get_interrupt_group(unsigned int id);
166eb68ea9bSJeenu Viswambharan unsigned int gicv2_get_running_priority(void);
167fa9db423SJeenu Viswambharan void gicv2_set_pe_target_mask(unsigned int proc_num);
168cbd3f370SJeenu Viswambharan unsigned int gicv2_get_interrupt_active(unsigned int id);
169979225f4SJeenu Viswambharan void gicv2_enable_interrupt(unsigned int id);
170979225f4SJeenu Viswambharan void gicv2_disable_interrupt(unsigned int id);
171f3a86600SJeenu Viswambharan void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority);
17274dce7faSJeenu Viswambharan void gicv2_set_interrupt_type(unsigned int id, unsigned int type);
1738db978b5SJeenu Viswambharan void gicv2_raise_sgi(int sgi_num, int proc_num);
174fc529feeSJeenu Viswambharan void gicv2_set_spi_routing(unsigned int id, int proc_num);
175*a2816a16SJeenu Viswambharan void gicv2_set_interrupt_pending(unsigned int id);
176*a2816a16SJeenu Viswambharan void gicv2_clear_interrupt_pending(unsigned int id);
177464ce2bbSSoby Mathew 
178464ce2bbSSoby Mathew #endif /* __ASSEMBLY__ */
179464ce2bbSSoby Mathew #endif /* __GICV2_H__ */
180