xref: /rk3399_ARM-atf/include/drivers/arm/gicv2.h (revision eb68ea9b10c190c237216dee92166f9e7b2ce3d4)
1464ce2bbSSoby Mathew /*
2*eb68ea9bSJeenu 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  ******************************************************************************/
13464ce2bbSSoby Mathew /* Interrupt IDs reported by the HPPIR and IAR registers */
14464ce2bbSSoby Mathew #define PENDING_G1_INTID	1022
15464ce2bbSSoby Mathew 
16464ce2bbSSoby Mathew /*******************************************************************************
17464ce2bbSSoby Mathew  * GICv2 specific Distributor interface register offsets and constants.
18464ce2bbSSoby Mathew  ******************************************************************************/
19464ce2bbSSoby Mathew #define GICD_ITARGETSR		0x800
20464ce2bbSSoby Mathew #define GICD_SGIR		0xF00
21464ce2bbSSoby Mathew #define GICD_CPENDSGIR		0xF10
22464ce2bbSSoby Mathew #define GICD_SPENDSGIR		0xF20
23464ce2bbSSoby Mathew #define GICD_PIDR2_GICV2	0xFE8
24464ce2bbSSoby Mathew 
25464ce2bbSSoby Mathew #define ITARGETSR_SHIFT		2
26464ce2bbSSoby Mathew #define GIC_TARGET_CPU_MASK	0xff
27464ce2bbSSoby Mathew 
28464ce2bbSSoby Mathew #define CPENDSGIR_SHIFT		2
29464ce2bbSSoby Mathew #define SPENDSGIR_SHIFT		CPENDSGIR_SHIFT
30464ce2bbSSoby Mathew 
31464ce2bbSSoby Mathew /*******************************************************************************
32464ce2bbSSoby Mathew  * GICv2 specific CPU interface register offsets and constants.
33464ce2bbSSoby Mathew  ******************************************************************************/
34464ce2bbSSoby Mathew /* Physical CPU Interface registers */
35464ce2bbSSoby Mathew #define GICC_CTLR		0x0
36464ce2bbSSoby Mathew #define GICC_PMR		0x4
37464ce2bbSSoby Mathew #define GICC_BPR		0x8
38464ce2bbSSoby Mathew #define GICC_IAR		0xC
39464ce2bbSSoby Mathew #define GICC_EOIR		0x10
40464ce2bbSSoby Mathew #define GICC_RPR		0x14
41464ce2bbSSoby Mathew #define GICC_HPPIR		0x18
42464ce2bbSSoby Mathew #define GICC_AHPPIR		0x28
43464ce2bbSSoby Mathew #define GICC_IIDR		0xFC
44464ce2bbSSoby Mathew #define GICC_DIR		0x1000
45464ce2bbSSoby Mathew #define GICC_PRIODROP		GICC_EOIR
46464ce2bbSSoby Mathew 
47464ce2bbSSoby Mathew /* GICC_CTLR bit definitions */
48464ce2bbSSoby Mathew #define EOI_MODE_NS		(1 << 10)
49464ce2bbSSoby Mathew #define EOI_MODE_S		(1 << 9)
50464ce2bbSSoby Mathew #define IRQ_BYP_DIS_GRP1	(1 << 8)
51464ce2bbSSoby Mathew #define FIQ_BYP_DIS_GRP1	(1 << 7)
52464ce2bbSSoby Mathew #define IRQ_BYP_DIS_GRP0	(1 << 6)
53464ce2bbSSoby Mathew #define FIQ_BYP_DIS_GRP0	(1 << 5)
54464ce2bbSSoby Mathew #define CBPR			(1 << 4)
55464ce2bbSSoby Mathew #define FIQ_EN_SHIFT		3
56464ce2bbSSoby Mathew #define FIQ_EN_BIT		(1 << FIQ_EN_SHIFT)
57464ce2bbSSoby Mathew #define ACK_CTL			(1 << 2)
58464ce2bbSSoby Mathew 
59464ce2bbSSoby Mathew /* GICC_IIDR bit masks and shifts */
60464ce2bbSSoby Mathew #define GICC_IIDR_PID_SHIFT	20
61464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_SHIFT	16
62464ce2bbSSoby Mathew #define GICC_IIDR_REV_SHIFT	12
63464ce2bbSSoby Mathew #define GICC_IIDR_IMP_SHIFT	0
64464ce2bbSSoby Mathew 
65464ce2bbSSoby Mathew #define GICC_IIDR_PID_MASK	0xfff
66464ce2bbSSoby Mathew #define GICC_IIDR_ARCH_MASK	0xf
67464ce2bbSSoby Mathew #define GICC_IIDR_REV_MASK	0xf
68464ce2bbSSoby Mathew #define GICC_IIDR_IMP_MASK	0xfff
69464ce2bbSSoby Mathew 
70464ce2bbSSoby Mathew /* HYP view virtual CPU Interface registers */
71464ce2bbSSoby Mathew #define GICH_CTL		0x0
72464ce2bbSSoby Mathew #define GICH_VTR		0x4
73464ce2bbSSoby Mathew #define GICH_ELRSR0		0x30
74464ce2bbSSoby Mathew #define GICH_ELRSR1		0x34
75464ce2bbSSoby Mathew #define GICH_APR0		0xF0
76464ce2bbSSoby Mathew #define GICH_LR_BASE		0x100
77464ce2bbSSoby Mathew 
78464ce2bbSSoby Mathew /* Virtual CPU Interface registers */
79464ce2bbSSoby Mathew #define GICV_CTL		0x0
80464ce2bbSSoby Mathew #define GICV_PRIMASK		0x4
81464ce2bbSSoby Mathew #define GICV_BP			0x8
82464ce2bbSSoby Mathew #define GICV_INTACK		0xC
83464ce2bbSSoby Mathew #define GICV_EOI		0x10
84464ce2bbSSoby Mathew #define GICV_RUNNINGPRI		0x14
85464ce2bbSSoby Mathew #define GICV_HIGHESTPEND	0x18
86464ce2bbSSoby Mathew #define GICV_DEACTIVATE		0x1000
87464ce2bbSSoby Mathew 
88464ce2bbSSoby Mathew /* GICD_CTLR bit definitions */
89464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_SHIFT		1
90464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_MASK		0x1
91464ce2bbSSoby Mathew #define CTLR_ENABLE_G1_BIT		(1 << CTLR_ENABLE_G1_SHIFT)
92464ce2bbSSoby Mathew 
93464ce2bbSSoby Mathew /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
94464ce2bbSSoby Mathew #define INT_ID_MASK		0x3ff
95464ce2bbSSoby Mathew 
96464ce2bbSSoby Mathew #ifndef __ASSEMBLY__
97464ce2bbSSoby Mathew 
98464ce2bbSSoby Mathew #include <stdint.h>
99464ce2bbSSoby Mathew 
100464ce2bbSSoby Mathew /*******************************************************************************
101464ce2bbSSoby Mathew  * This structure describes some of the implementation defined attributes of
102464ce2bbSSoby Mathew  * the GICv2 IP. It is used by the platform port to specify these attributes
103464ce2bbSSoby Mathew  * in order to initialize the GICv2 driver. The attributes are described
104464ce2bbSSoby Mathew  * below.
105464ce2bbSSoby Mathew  *
106464ce2bbSSoby Mathew  * 1. The 'gicd_base' field contains the base address of the Distributor
107464ce2bbSSoby Mathew  *    interface programmer's view.
108464ce2bbSSoby Mathew  *
109464ce2bbSSoby Mathew  * 2. The 'gicc_base' field contains the base address of the CPU Interface
110464ce2bbSSoby Mathew  *    programmer's view.
111464ce2bbSSoby Mathew  *
112464ce2bbSSoby Mathew  * 3. The 'g0_interrupt_array' field is a pointer to an array in which each
113464ce2bbSSoby Mathew  *    entry corresponds to an ID of a Group 0 interrupt.
114464ce2bbSSoby Mathew  *
115464ce2bbSSoby Mathew  * 4. The 'g0_interrupt_num' field contains the number of entries in the
116464ce2bbSSoby Mathew  *    'g0_interrupt_array'.
117464ce2bbSSoby Mathew  ******************************************************************************/
118464ce2bbSSoby Mathew typedef struct gicv2_driver_data {
119464ce2bbSSoby Mathew 	uintptr_t gicd_base;
120464ce2bbSSoby Mathew 	uintptr_t gicc_base;
121464ce2bbSSoby Mathew 	unsigned int g0_interrupt_num;
122464ce2bbSSoby Mathew 	const unsigned int *g0_interrupt_array;
123464ce2bbSSoby Mathew } gicv2_driver_data_t;
124464ce2bbSSoby Mathew 
125464ce2bbSSoby Mathew /*******************************************************************************
126464ce2bbSSoby Mathew  * Function prototypes
127464ce2bbSSoby Mathew  ******************************************************************************/
128464ce2bbSSoby Mathew void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
129464ce2bbSSoby Mathew void gicv2_distif_init(void);
130464ce2bbSSoby Mathew void gicv2_pcpu_distif_init(void);
131464ce2bbSSoby Mathew void gicv2_cpuif_enable(void);
132464ce2bbSSoby Mathew void gicv2_cpuif_disable(void);
133464ce2bbSSoby Mathew unsigned int gicv2_is_fiq_enabled(void);
134464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_type(void);
135464ce2bbSSoby Mathew unsigned int gicv2_get_pending_interrupt_id(void);
136464ce2bbSSoby Mathew unsigned int gicv2_acknowledge_interrupt(void);
137464ce2bbSSoby Mathew void gicv2_end_of_interrupt(unsigned int id);
138464ce2bbSSoby Mathew unsigned int gicv2_get_interrupt_group(unsigned int id);
139*eb68ea9bSJeenu Viswambharan unsigned int gicv2_get_running_priority(void);
140464ce2bbSSoby Mathew 
141464ce2bbSSoby Mathew #endif /* __ASSEMBLY__ */
142464ce2bbSSoby Mathew #endif /* __GICV2_H__ */
143