gicv2.h 6.39 KB
Newer Older
Soby Mathew's avatar
Soby Mathew committed
1
/*
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Soby Mathew's avatar
Soby Mathew committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew's avatar
Soby Mathew committed
5
6
 */

7
8
#ifndef GICV2_H
#define GICV2_H
Soby Mathew's avatar
Soby Mathew committed
9

10
#include <drivers/arm/gic_common.h>
11

Soby Mathew's avatar
Soby Mathew committed
12
13
14
/*******************************************************************************
 * GICv2 miscellaneous definitions
 ******************************************************************************/
15
16

/* Interrupt group definitions */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
17
18
#define GICV2_INTR_GROUP0	U(0)
#define GICV2_INTR_GROUP1	U(1)
19

Soby Mathew's avatar
Soby Mathew committed
20
/* Interrupt IDs reported by the HPPIR and IAR registers */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
21
#define PENDING_G1_INTID	U(1022)
Soby Mathew's avatar
Soby Mathew committed
22

23
/* GICv2 can only target up to 8 PEs */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
24
#define GICV2_MAX_TARGET_PE	U(8)
25

Soby Mathew's avatar
Soby Mathew committed
26
27
28
/*******************************************************************************
 * GICv2 specific Distributor interface register offsets and constants.
 ******************************************************************************/
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
29
30
31
32
33
#define GICD_ITARGETSR		U(0x800)
#define GICD_SGIR		U(0xF00)
#define GICD_CPENDSGIR		U(0xF10)
#define GICD_SPENDSGIR		U(0xF20)
#define GICD_PIDR2_GICV2	U(0xFE8)
Soby Mathew's avatar
Soby Mathew committed
34
35

#define ITARGETSR_SHIFT		2
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
36
#define GIC_TARGET_CPU_MASK	U(0xff)
Soby Mathew's avatar
Soby Mathew committed
37
38
39
40

#define CPENDSGIR_SHIFT		2
#define SPENDSGIR_SHIFT		CPENDSGIR_SHIFT

41
#define SGIR_TGTLSTFLT_SHIFT	24
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
42
#define SGIR_TGTLSTFLT_MASK	U(0x3)
43
#define SGIR_TGTLST_SHIFT	16
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
44
45
#define SGIR_TGTLST_MASK	U(0xff)
#define SGIR_INTID_MASK		ULL(0xf)
46

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
47
#define SGIR_TGT_SPECIFIC	U(0)
48
49
50
51
52
53

#define GICV2_SGIR_VALUE(tgt_lst_flt, tgt, intid) \
	((((tgt_lst_flt) & SGIR_TGTLSTFLT_MASK) << SGIR_TGTLSTFLT_SHIFT) | \
	 (((tgt) & SGIR_TGTLST_MASK) << SGIR_TGTLST_SHIFT) | \
	 ((intid) & SGIR_INTID_MASK))

Soby Mathew's avatar
Soby Mathew committed
54
55
56
57
/*******************************************************************************
 * GICv2 specific CPU interface register offsets and constants.
 ******************************************************************************/
/* Physical CPU Interface registers */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
58
59
60
61
62
63
64
65
66
67
#define GICC_CTLR		U(0x0)
#define GICC_PMR		U(0x4)
#define GICC_BPR		U(0x8)
#define GICC_IAR		U(0xC)
#define GICC_EOIR		U(0x10)
#define GICC_RPR		U(0x14)
#define GICC_HPPIR		U(0x18)
#define GICC_AHPPIR		U(0x28)
#define GICC_IIDR		U(0xFC)
#define GICC_DIR		U(0x1000)
Soby Mathew's avatar
Soby Mathew committed
68
69
70
#define GICC_PRIODROP		GICC_EOIR

/* GICC_CTLR bit definitions */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
71
72
73
74
75
76
77
#define EOI_MODE_NS		BIT_32(10)
#define EOI_MODE_S		BIT_32(9)
#define IRQ_BYP_DIS_GRP1	BIT_32(8)
#define FIQ_BYP_DIS_GRP1	BIT_32(7)
#define IRQ_BYP_DIS_GRP0	BIT_32(6)
#define FIQ_BYP_DIS_GRP0	BIT_32(5)
#define CBPR			BIT_32(4)
Soby Mathew's avatar
Soby Mathew committed
78
#define FIQ_EN_SHIFT		3
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
79
80
#define FIQ_EN_BIT		BIT_32(FIQ_EN_SHIFT)
#define ACK_CTL			BIT_32(2)
Soby Mathew's avatar
Soby Mathew committed
81
82
83
84
85
86
87

/* GICC_IIDR bit masks and shifts */
#define GICC_IIDR_PID_SHIFT	20
#define GICC_IIDR_ARCH_SHIFT	16
#define GICC_IIDR_REV_SHIFT	12
#define GICC_IIDR_IMP_SHIFT	0

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
88
89
90
91
#define GICC_IIDR_PID_MASK	U(0xfff)
#define GICC_IIDR_ARCH_MASK	U(0xf)
#define GICC_IIDR_REV_MASK	U(0xf)
#define GICC_IIDR_IMP_MASK	U(0xfff)
Soby Mathew's avatar
Soby Mathew committed
92
93

/* HYP view virtual CPU Interface registers */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
94
95
96
97
98
99
#define GICH_CTL		U(0x0)
#define GICH_VTR		U(0x4)
#define GICH_ELRSR0		U(0x30)
#define GICH_ELRSR1		U(0x34)
#define GICH_APR0		U(0xF0)
#define GICH_LR_BASE		U(0x100)
Soby Mathew's avatar
Soby Mathew committed
100
101

/* Virtual CPU Interface registers */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
102
103
104
105
106
107
108
109
#define GICV_CTL		U(0x0)
#define GICV_PRIMASK		U(0x4)
#define GICV_BP			U(0x8)
#define GICV_INTACK		U(0xC)
#define GICV_EOI		U(0x10)
#define GICV_RUNNINGPRI		U(0x14)
#define GICV_HIGHESTPEND	U(0x18)
#define GICV_DEACTIVATE		U(0x1000)
Soby Mathew's avatar
Soby Mathew committed
110
111
112

/* GICD_CTLR bit definitions */
#define CTLR_ENABLE_G1_SHIFT		1
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
113
114
#define CTLR_ENABLE_G1_MASK		U(0x1)
#define CTLR_ENABLE_G1_BIT		BIT_32(CTLR_ENABLE_G1_SHIFT)
Soby Mathew's avatar
Soby Mathew committed
115
116

/* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
117
#define INT_ID_MASK		U(0x3ff)
Soby Mathew's avatar
Soby Mathew committed
118
119
120

#ifndef __ASSEMBLY__

121
#include <cdefs.h>
Soby Mathew's avatar
Soby Mathew committed
122
123
#include <stdint.h>

124
125
#include <common/interrupt_props.h>

Soby Mathew's avatar
Soby Mathew committed
126
127
128
129
130
131
/*******************************************************************************
 * This structure describes some of the implementation defined attributes of
 * the GICv2 IP. It is used by the platform port to specify these attributes
 * in order to initialize the GICv2 driver. The attributes are described
 * below.
 *
132
133
134
135
136
 * The 'gicd_base' field contains the base address of the Distributor interface
 * programmer's view.
 *
 * The 'gicc_base' field contains the base address of the CPU Interface
 * programmer's view.
Soby Mathew's avatar
Soby Mathew committed
137
 *
138
139
140
 * The 'target_masks' is a pointer to an array containing 'target_masks_num'
 * elements. The GIC driver will populate the array with per-PE target mask to
 * use to when targeting interrupts.
141
142
143
144
145
146
147
148
 *
 * The 'interrupt_props' field is a pointer to an array that enumerates secure
 * interrupts and their properties. If this field is not NULL, both
 * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
 *
 * The 'interrupt_props_num' field contains the number of entries in the
 * 'interrupt_props' array. If this field is non-zero, 'g0_interrupt_num' is
 * ignored.
Soby Mathew's avatar
Soby Mathew committed
149
150
151
152
 ******************************************************************************/
typedef struct gicv2_driver_data {
	uintptr_t gicd_base;
	uintptr_t gicc_base;
153
154
	unsigned int *target_masks;
	unsigned int target_masks_num;
155
156
	const interrupt_prop_t *interrupt_props;
	unsigned int interrupt_props_num;
Soby Mathew's avatar
Soby Mathew committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
} gicv2_driver_data_t;

/*******************************************************************************
 * Function prototypes
 ******************************************************************************/
void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
void gicv2_distif_init(void);
void gicv2_pcpu_distif_init(void);
void gicv2_cpuif_enable(void);
void gicv2_cpuif_disable(void);
unsigned int gicv2_is_fiq_enabled(void);
unsigned int gicv2_get_pending_interrupt_type(void);
unsigned int gicv2_get_pending_interrupt_id(void);
unsigned int gicv2_acknowledge_interrupt(void);
void gicv2_end_of_interrupt(unsigned int id);
unsigned int gicv2_get_interrupt_group(unsigned int id);
173
unsigned int gicv2_get_running_priority(void);
174
void gicv2_set_pe_target_mask(unsigned int proc_num);
175
unsigned int gicv2_get_interrupt_active(unsigned int id);
176
177
void gicv2_enable_interrupt(unsigned int id);
void gicv2_disable_interrupt(unsigned int id);
178
void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority);
179
void gicv2_set_interrupt_type(unsigned int id, unsigned int type);
180
void gicv2_raise_sgi(int sgi_num, int proc_num);
181
void gicv2_set_spi_routing(unsigned int id, int proc_num);
182
183
void gicv2_set_interrupt_pending(unsigned int id);
void gicv2_clear_interrupt_pending(unsigned int id);
184
unsigned int gicv2_set_pmr(unsigned int mask);
185
void gicv2_interrupt_set_cfg(unsigned int id, unsigned int cfg);
Soby Mathew's avatar
Soby Mathew committed
186
187

#endif /* __ASSEMBLY__ */
188
#endif /* GICV2_H */