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