blob: e1641038f931660df05563467f352e52c2742f66 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +00002 * Copyright (c) 2018-2023, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __GIC_V3_H__
8#define __GIC_V3_H__
9
10/***************************************************************************
11 * Defines and prototypes specific to GIC v3.
12 *************************************************************************/
13
14/* GICD register offsets */
15#define GICD_IROUTER 0x6000
16
17/* GICD_CTLR bit definitions */
18#define GICD_CTLR_ENABLE_GRP1A (1 << 1)
19#define GICD_CTLR_ARE_NS_SHIFT 4
20#define GICD_CTLR_ARE_NS_MASK 0x1
21
22/* GICR_TYPER bit definitions */
23#define TYPER_AFF_VAL_SHIFT 32
24#define TYPER_PROC_NUM_SHIFT 8
25#define TYPER_LAST_SHIFT 4
26
27#define TYPER_AFF_VAL_MASK 0xffffffff
28#define TYPER_PROC_NUM_MASK 0xffff
29#define TYPER_LAST_MASK 0x1
30
31#define TYPER_LAST_BIT (1 << TYPER_LAST_SHIFT)
32
33/* GICD_IROUTER shifts and masks */
34#define IROUTER_IRM_SHIFT 31
35#define IROUTER_IRM_MASK 0x1
36
37/*******************************************************************************
38 * GICv3 Re-distributor interface registers & constants
39 ******************************************************************************/
40#define GICR_PCPUBASE_SHIFT 0x11
41#define GICR_SGIBASE_OFFSET (1 << 0x10) /* 64 KB */
42#define GICR_CTLR 0x0
43#define GICR_TYPER 0x08
44#define GICR_WAKER 0x14
45#define GICR_IGROUPR0 (GICR_SGIBASE_OFFSET + 0x80)
46#define GICR_ISENABLER0 (GICR_SGIBASE_OFFSET + 0x100)
47#define GICR_ICENABLER0 (GICR_SGIBASE_OFFSET + 0x180)
48#define GICR_ISPENDR0 (GICR_SGIBASE_OFFSET + 0x200)
49#define GICR_ICPENDR0 (GICR_SGIBASE_OFFSET + 0x280)
50#define GICR_IPRIORITYR (GICR_SGIBASE_OFFSET + 0x400)
51#define GICR_ICFGR0 (GICR_SGIBASE_OFFSET + 0xc00)
52#define GICR_ICFGR1 (GICR_SGIBASE_OFFSET + 0xc04)
53#define GICR_IGRPMODR0 (GICR_SGIBASE_OFFSET + 0xd00)
54
55/*******************************************************************************
56 * GICv3 CPU interface registers & constants
57 ******************************************************************************/
58/* ICC_SRE bit definitions*/
59#define ICC_SRE_EN_BIT (1 << 3)
60#define ICC_SRE_DIB_BIT (1 << 2)
61#define ICC_SRE_DFB_BIT (1 << 1)
62#define ICC_SRE_SRE_BIT (1 << 0)
63
64/* ICC_IAR1_EL1 bit definitions */
65#define IAR1_EL1_INTID_SHIFT 0
66#define IAR1_EL1_INTID_MASK 0xffffff
67
68/* ICC_SGI1R bit definitions */
69#define SGI1R_TARGET_LIST_MASK 0xffff
70#define SGI1R_TARGET_LIST_SHIFT 0x0
71#define SGI1R_AFF_MASK 0xff
72#define SGI1R_AFF1_SHIFT 16ULL
73#define SGI1R_AFF2_SHIFT 32ULL
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -060074#ifdef __aarch64__
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020075#define SGI1R_AFF3_SHIFT 48ULL
76#endif
77#define SGI1R_INTID_MASK 0xf
78#define SGI1R_INTID_SHIFT 24
79#define SGI1R_IRM_MASK 0x1
80#define SGI1R_IRM_SHIFT 0x40
81
82/* ICC_IGRPEN1_EL1 bit definitions */
83#define IGRPEN1_EL1_ENABLE_SHIFT 0
84#define IGRPEN1_EL1_ENABLE_BIT (1 << IGRPEN1_EL1_ENABLE_SHIFT)
85
AlexeiFedorov2f30f102023-03-13 19:37:46 +000086/* ICH_ICH_LR<n>_EL2 definitions */
87#define ICH_LRn_EL2_STATE_Invalid (0UL << 62)
88#define ICH_LRn_EL2_STATE_Pending (1UL << 62)
89#define ICH_LRn_EL2_STATE_Active (2UL << 62)
90#define ICH_LRn_EL2_STATE_Pending_Active (3UL << 62)
91#define ICH_LRn_EL2_Group_0 (0UL << 60)
92#define ICH_LRn_EL2_Group_1 (1UL << 60)
93#define ICH_LRn_EL2_Priority_SHIFT 48
94#define ICH_LRn_EL2_Priority_MASK 0xFF
95#define ICH_LRn_EL2_vINTID_SHIFT 0
96#define ICH_LRn_EL2_vINTID_MASK 0xFFFF
97
98/* ICV_CTLR_EL1 definitions */
99#define ICV_CTLR_EL1_PRIbits_SHIFT 8
100#define ICV_CTLR_EL1_PRIbits_MASK 7
101
102/* ICV_IGRPEN1_EL1 definition */
103#define ICV_IGRPEN1_EL1_Enable 1UL
104
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200105/* The highest affinity 0 that can be a SGI target*/
106#define SGI_TARGET_MAX_AFF0 16
107
108#ifndef ASSEMBLY
109
110/*******************************************************************************
111 * Helper GICv3 macros
112 ******************************************************************************/
113#define gicv3_acknowledge_interrupt() read_icc_iar1_el1() &\
114 IAR1_EL1_INTID_MASK
115#define gicv3_end_of_interrupt(id) write_icc_eoir1_el1(id)
116
117#define is_sre_enabled() \
118 (IS_IN_EL2() ? (read_icc_sre_el2() & ICC_SRE_SRE_BIT) :\
119 (read_icc_sre_el1() & ICC_SRE_SRE_BIT))
120
121/******************************************************************************
122 * GICv3 public driver API
123 *****************************************************************************/
124 /*
125 * Initialize the GICv3 driver. The base addresses of GIC Re-distributor
126 * interface `gicr_base` and the Distributor interface `gicd_base` must
127 * be provided as arguments.
128 */
129void gicv3_init(uintptr_t gicr_base, uintptr_t gicd_base);
130
131/*
132 * Setup the GIC Distributor interface.
133 */
134void gicv3_setup_distif(void);
135
136/*
137 * Probe the Re-distributor base corresponding to this core.
138 * This function is required to be invoked on successful boot of a core.
139 * The base address will be stored internally by the driver and will be
140 * used when accessing the Re-distributor interface.
141 */
142void gicv3_probe_redistif_addr(void);
143
144/*
145 * Set the bit corresponding to `interrupt_id` in the ICPENDR register
146 * at either Distributor or Re-distributor depending on the interrupt.
147 */
148void gicv3_set_icpendr(unsigned int interrupt_id);
149
150/*
151 * Get the bit corresponding to `interrupt_id` in the ISPENDR register
152 * at either Distributor or Re-distributor depending on the interrupt.
153 */
154unsigned int gicv3_get_ispendr(unsigned int interrupt_id);
155
156/*
157 * Set the bit corresponding to `interrupt_id` in the ICENABLER register
158 * at either Distributor or Re-distributor depending on the interrupt.
159 */
160void gicv3_set_icenabler(unsigned int interrupt_id);
161
162/*
163 * Get the bit corresponding to `interrupt_id` in the ISENABLER register
164 * at either Distributor or Re-distributor depending on the interrupt.
165 */
166unsigned int gicv3_get_isenabler(unsigned int interrupt_id);
167
168/*
169 * Set the bit corresponding to `interrupt_id` in the ISENABLER register
170 * at either Distributor or Re-distributor depending on the interrupt.
171 */
172void gicv3_set_isenabler(unsigned int interrupt_id);
173
174/*
175 * Set the `route` corresponding to `interrupt_id` in the IROUTER register
176 * at Distributor.
177 */
178void gicv3_set_intr_route(unsigned int interrupt_id, unsigned int core_pos);
179
180/*
181 * Send SGI with ID `sgi_id` to core with index `core_pos`.
182 */
183void gicv3_send_sgi(unsigned int sgi_id, unsigned int core_pos);
184
185/*
186 * Get the priority of the interrupt `interrupt_id`.
187 */
188unsigned int gicv3_get_ipriorityr(unsigned int interrupt_id);
189
190/*
191 * Set the priority of the interrupt `interrupt_id` to `priority`.
192 */
193void gicv3_set_ipriorityr(unsigned int interrupt_id, unsigned int priority);
194
195/*
196 * Restore the GICv3 SGI and PPI context after powering up the
197 * GIC Re-distributor.
198 */
199void gicv3_restore_sgi_ppi_context(void);
200
201/*
202 * Save the GICv3 SGI and PPI context prior to powering down the
203 * GIC Re-distributor.
204 */
205void gicv3_save_sgi_ppi_context(void);
206
207/*
208 * Restore the GICv3 CPU interface after powering up the CPU interface.
209 */
210void gicv3_restore_cpuif_context(void);
211
212/*
213 * Save the GICv3 CPU interface prior to powering down the CPU interface.
214 */
215void gicv3_save_cpuif_context(void);
216
217/*
218 * Disable the GIC CPU interface.
219 */
220void gicv3_disable_cpuif(void);
221
222/*
223 * Setup the GIC CPU interface.
224 */
225void gicv3_setup_cpuif(void);
226
227/*
228 * Enable the GIC CPU interface.
229 */
230void gicv3_enable_cpuif(void);
231
232
233#endif /*__ASSEMBLY__*/
234#endif /* __GIC_V3_H__ */