xref: /rk3399_ARM-atf/include/drivers/arm/gicv2.h (revision 464ce2bbaa95a95f773a639c47e14bdffa21d75a)
1*464ce2bbSSoby Mathew /*
2*464ce2bbSSoby Mathew  * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3*464ce2bbSSoby Mathew  *
4*464ce2bbSSoby Mathew  * Redistribution and use in source and binary forms, with or without
5*464ce2bbSSoby Mathew  * modification, are permitted provided that the following conditions are met:
6*464ce2bbSSoby Mathew  *
7*464ce2bbSSoby Mathew  * Redistributions of source code must retain the above copyright notice, this
8*464ce2bbSSoby Mathew  * list of conditions and the following disclaimer.
9*464ce2bbSSoby Mathew  *
10*464ce2bbSSoby Mathew  * Redistributions in binary form must reproduce the above copyright notice,
11*464ce2bbSSoby Mathew  * this list of conditions and the following disclaimer in the documentation
12*464ce2bbSSoby Mathew  * and/or other materials provided with the distribution.
13*464ce2bbSSoby Mathew  *
14*464ce2bbSSoby Mathew  * Neither the name of ARM nor the names of its contributors may be used
15*464ce2bbSSoby Mathew  * to endorse or promote products derived from this software without specific
16*464ce2bbSSoby Mathew  * prior written permission.
17*464ce2bbSSoby Mathew  *
18*464ce2bbSSoby Mathew  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*464ce2bbSSoby Mathew  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*464ce2bbSSoby Mathew  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*464ce2bbSSoby Mathew  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*464ce2bbSSoby Mathew  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*464ce2bbSSoby Mathew  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*464ce2bbSSoby Mathew  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*464ce2bbSSoby Mathew  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*464ce2bbSSoby Mathew  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*464ce2bbSSoby Mathew  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*464ce2bbSSoby Mathew  * POSSIBILITY OF SUCH DAMAGE.
29*464ce2bbSSoby Mathew  */
30*464ce2bbSSoby Mathew 
31*464ce2bbSSoby Mathew #ifndef __GICV2_H__
32*464ce2bbSSoby Mathew #define __GICV2_H__
33*464ce2bbSSoby Mathew 
34*464ce2bbSSoby Mathew /*******************************************************************************
35*464ce2bbSSoby Mathew  * GICv2 miscellaneous definitions
36*464ce2bbSSoby Mathew  ******************************************************************************/
37*464ce2bbSSoby Mathew /* Interrupt IDs reported by the HPPIR and IAR registers */
38*464ce2bbSSoby Mathew #define PENDING_G1_INTID	1022
39*464ce2bbSSoby Mathew 
40*464ce2bbSSoby Mathew /*******************************************************************************
41*464ce2bbSSoby Mathew  * GICv2 specific Distributor interface register offsets and constants.
42*464ce2bbSSoby Mathew  ******************************************************************************/
43*464ce2bbSSoby Mathew #define GICD_ITARGETSR		0x800
44*464ce2bbSSoby Mathew #define GICD_SGIR		0xF00
45*464ce2bbSSoby Mathew #define GICD_CPENDSGIR		0xF10
46*464ce2bbSSoby Mathew #define GICD_SPENDSGIR		0xF20
47*464ce2bbSSoby Mathew #define GICD_PIDR2_GICV2	0xFE8
48*464ce2bbSSoby Mathew 
49*464ce2bbSSoby Mathew #define ITARGETSR_SHIFT		2
50*464ce2bbSSoby Mathew #define GIC_TARGET_CPU_MASK	0xff
51*464ce2bbSSoby Mathew 
52*464ce2bbSSoby Mathew #define CPENDSGIR_SHIFT		2
53*464ce2bbSSoby Mathew #define SPENDSGIR_SHIFT		CPENDSGIR_SHIFT
54*464ce2bbSSoby Mathew 
55*464ce2bbSSoby Mathew /*******************************************************************************
56*464ce2bbSSoby Mathew  * GICv2 specific CPU interface register offsets and constants.
57*464ce2bbSSoby Mathew  ******************************************************************************/
58*464ce2bbSSoby Mathew /* Physical CPU Interface registers */
59*464ce2bbSSoby Mathew #define GICC_CTLR		0x0
60*464ce2bbSSoby Mathew #define GICC_PMR		0x4
61*464ce2bbSSoby Mathew #define GICC_BPR		0x8
62*464ce2bbSSoby Mathew #define GICC_IAR		0xC
63*464ce2bbSSoby Mathew #define GICC_EOIR		0x10
64*464ce2bbSSoby Mathew #define GICC_RPR		0x14
65*464ce2bbSSoby Mathew #define GICC_HPPIR		0x18
66*464ce2bbSSoby Mathew #define GICC_AHPPIR		0x28
67*464ce2bbSSoby Mathew #define GICC_IIDR		0xFC
68*464ce2bbSSoby Mathew #define GICC_DIR		0x1000
69*464ce2bbSSoby Mathew #define GICC_PRIODROP		GICC_EOIR
70*464ce2bbSSoby Mathew 
71*464ce2bbSSoby Mathew /* GICC_CTLR bit definitions */
72*464ce2bbSSoby Mathew #define EOI_MODE_NS		(1 << 10)
73*464ce2bbSSoby Mathew #define EOI_MODE_S		(1 << 9)
74*464ce2bbSSoby Mathew #define IRQ_BYP_DIS_GRP1	(1 << 8)
75*464ce2bbSSoby Mathew #define FIQ_BYP_DIS_GRP1	(1 << 7)
76*464ce2bbSSoby Mathew #define IRQ_BYP_DIS_GRP0	(1 << 6)
77*464ce2bbSSoby Mathew #define FIQ_BYP_DIS_GRP0	(1 << 5)
78*464ce2bbSSoby Mathew #define CBPR			(1 << 4)
79*464ce2bbSSoby Mathew #define FIQ_EN_SHIFT		3
80*464ce2bbSSoby Mathew #define FIQ_EN_BIT		(1 << FIQ_EN_SHIFT)
81*464ce2bbSSoby Mathew #define ACK_CTL			(1 << 2)
82*464ce2bbSSoby Mathew 
83*464ce2bbSSoby Mathew /* GICC_IIDR bit masks and shifts */
84*464ce2bbSSoby Mathew #define GICC_IIDR_PID_SHIFT	20
85*464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_SHIFT	16
86*464ce2bbSSoby Mathew #define GICC_IIDR_REV_SHIFT	12
87*464ce2bbSSoby Mathew #define GICC_IIDR_IMP_SHIFT	0
88*464ce2bbSSoby Mathew 
89*464ce2bbSSoby Mathew #define GICC_IIDR_PID_MASK	0xfff
90*464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_MASK	0xf
91*464ce2bbSSoby Mathew #define GICC_IIDR_REV_MASK	0xf
92*464ce2bbSSoby Mathew #define GICC_IIDR_IMP_MASK	0xfff
93*464ce2bbSSoby Mathew 
94*464ce2bbSSoby Mathew /* HYP view virtual CPU Interface registers */
95*464ce2bbSSoby Mathew #define GICH_CTL		0x0
96*464ce2bbSSoby Mathew #define GICH_VTR		0x4
97*464ce2bbSSoby Mathew #define GICH_ELRSR0		0x30
98*464ce2bbSSoby Mathew #define GICH_ELRSR1		0x34
99*464ce2bbSSoby Mathew #define GICH_APR0		0xF0
100*464ce2bbSSoby Mathew #define GICH_LR_BASE		0x100
101*464ce2bbSSoby Mathew 
102*464ce2bbSSoby Mathew /* Virtual CPU Interface registers */
103*464ce2bbSSoby Mathew #define GICV_CTL		0x0
104*464ce2bbSSoby Mathew #define GICV_PRIMASK		0x4
105*464ce2bbSSoby Mathew #define GICV_BP			0x8
106*464ce2bbSSoby Mathew #define GICV_INTACK		0xC
107*464ce2bbSSoby Mathew #define GICV_EOI		0x10
108*464ce2bbSSoby Mathew #define GICV_RUNNINGPRI		0x14
109*464ce2bbSSoby Mathew #define GICV_HIGHESTPEND	0x18
110*464ce2bbSSoby Mathew #define GICV_DEACTIVATE		0x1000
111*464ce2bbSSoby Mathew 
112*464ce2bbSSoby Mathew /* GICD_CTLR bit definitions */
113*464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_SHIFT		1
114*464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_MASK		0x1
115*464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_BIT		(1 << CTLR_ENABLE_G1_SHIFT)
116*464ce2bbSSoby Mathew 
117*464ce2bbSSoby Mathew /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
118*464ce2bbSSoby Mathew #define INT_ID_MASK		0x3ff
119*464ce2bbSSoby Mathew 
120*464ce2bbSSoby Mathew #ifndef __ASSEMBLY__
121*464ce2bbSSoby Mathew 
122*464ce2bbSSoby Mathew #include <stdint.h>
123*464ce2bbSSoby Mathew 
124*464ce2bbSSoby Mathew /*******************************************************************************
125*464ce2bbSSoby Mathew  * This structure describes some of the implementation defined attributes of
126*464ce2bbSSoby Mathew  * the GICv2 IP. It is used by the platform port to specify these attributes
127*464ce2bbSSoby Mathew  * in order to initialize the GICv2 driver. The attributes are described
128*464ce2bbSSoby Mathew  * below.
129*464ce2bbSSoby Mathew  *
130*464ce2bbSSoby Mathew  * 1. The 'gicd_base' field contains the base address of the Distributor
131*464ce2bbSSoby Mathew  *    interface programmer's view.
132*464ce2bbSSoby Mathew  *
133*464ce2bbSSoby Mathew  * 2. The 'gicc_base' field contains the base address of the CPU Interface
134*464ce2bbSSoby Mathew  *    programmer's view.
135*464ce2bbSSoby Mathew  *
136*464ce2bbSSoby Mathew  * 3. The 'g0_interrupt_array' field is a pointer to an array in which each
137*464ce2bbSSoby Mathew  *    entry corresponds to an ID of a Group 0 interrupt.
138*464ce2bbSSoby Mathew  *
139*464ce2bbSSoby Mathew  * 4. The 'g0_interrupt_num' field contains the number of entries in the
140*464ce2bbSSoby Mathew  *    'g0_interrupt_array'.
141*464ce2bbSSoby Mathew  ******************************************************************************/
142*464ce2bbSSoby Mathew typedef struct gicv2_driver_data {
143*464ce2bbSSoby Mathew 	uintptr_t gicd_base;
144*464ce2bbSSoby Mathew 	uintptr_t gicc_base;
145*464ce2bbSSoby Mathew 	unsigned int g0_interrupt_num;
146*464ce2bbSSoby Mathew 	const unsigned int *g0_interrupt_array;
147*464ce2bbSSoby Mathew } gicv2_driver_data_t;
148*464ce2bbSSoby Mathew 
149*464ce2bbSSoby Mathew /*******************************************************************************
150*464ce2bbSSoby Mathew  * Function prototypes
151*464ce2bbSSoby Mathew  ******************************************************************************/
152*464ce2bbSSoby Mathew void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
153*464ce2bbSSoby Mathew void gicv2_distif_init(void);
154*464ce2bbSSoby Mathew void gicv2_pcpu_distif_init(void);
155*464ce2bbSSoby Mathew void gicv2_cpuif_enable(void);
156*464ce2bbSSoby Mathew void gicv2_cpuif_disable(void);
157*464ce2bbSSoby Mathew unsigned int gicv2_is_fiq_enabled(void);
158*464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_type(void);
159*464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_id(void);
160*464ce2bbSSoby Mathew unsigned int gicv2_acknowledge_interrupt(void);
161*464ce2bbSSoby Mathew void gicv2_end_of_interrupt(unsigned int id);
162*464ce2bbSSoby Mathew unsigned int gicv2_get_interrupt_group(unsigned int id);
163*464ce2bbSSoby Mathew 
164*464ce2bbSSoby Mathew #endif /* __ASSEMBLY__ */
165*464ce2bbSSoby Mathew #endif /* __GICV2_H__ */
166