blob: 7965f409182d75c10e2f509c3b0b0e1f3f98205f [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Heyi Guo691b49d2020-05-19 16:45:17 +08002 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
Achin Gupta92712a52015-09-03 14:18:02 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta92712a52015-09-03 14:18:02 +01005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef GICV3_PRIVATE_H
8#define GICV3_PRIVATE_H
Achin Gupta92712a52015-09-03 14:18:02 +01009
Soby Mathew327548c2017-07-13 15:19:51 +010010#include <assert.h>
Achin Gupta92712a52015-09-03 14:18:02 +010011#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
13#include <drivers/arm/gic_common.h>
14#include <drivers/arm/gicv3.h>
15#include <lib/mmio.h>
16
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000017#include "../common/gic_common_private.h"
Achin Gupta92712a52015-09-03 14:18:02 +010018
19/*******************************************************************************
20 * GICv3 private macro definitions
21 ******************************************************************************/
22
23/* Constants to indicate the status of the RWP bit */
Antonio Nino Diaz2e590712018-08-24 11:46:33 +010024#define RWP_TRUE U(1)
25#define RWP_FALSE U(0)
Achin Gupta92712a52015-09-03 14:18:02 +010026
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000027/* Calculate GIC register bit number corresponding to its interrupt ID */
28#define BIT_NUM(REG, id) \
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010029 ((id) & ((1U << REG##R_SHIFT) - 1U))
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000030
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010031/*
32 * Calculate 8, 32 and 64-bit GICD register offset
33 * corresponding to its interrupt ID
34 */
35#if GIC_EXT_INTID
36 /* GICv3.1 */
37#define GICD_OFFSET_8(REG, id) \
38 (((id) <= MAX_SPI_ID) ? \
39 GICD_##REG##R + (uintptr_t)(id) : \
40 GICD_##REG##RE + (uintptr_t)(id) - MIN_ESPI_ID)
41
42#define GICD_OFFSET(REG, id) \
43 (((id) <= MAX_SPI_ID) ? \
44 GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) : \
45 GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >> \
46 REG##R_SHIFT) << 2))
47
48#define GICD_OFFSET_64(REG, id) \
49 (((id) <= MAX_SPI_ID) ? \
50 GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3) : \
Heyi Guo691b49d2020-05-19 16:45:17 +080051 GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >> \
52 REG##R_SHIFT) << 3))
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010053
54#else /* GICv3 */
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000055#define GICD_OFFSET_8(REG, id) \
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010056 (GICD_##REG##R + (uintptr_t)(id))
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000057
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000058#define GICD_OFFSET(REG, id) \
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010059 (GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2))
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000060
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000061#define GICD_OFFSET_64(REG, id) \
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010062 (GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3))
63#endif /* GIC_EXT_INTID */
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000064
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010065/*
66 * Read/Write 8, 32 and 64-bit GIC Distributor register
67 * corresponding to its interrupt ID
68 */
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000069#define GICD_READ(REG, base, id) \
70 mmio_read_32((base) + GICD_OFFSET(REG, (id)))
71
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000072#define GICD_READ_64(REG, base, id) \
73 mmio_read_64((base) + GICD_OFFSET_64(REG, (id)))
74
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010075#define GICD_WRITE_8(REG, base, id, val) \
76 mmio_write_8((base) + GICD_OFFSET_8(REG, (id)), (val))
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000077
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010078#define GICD_WRITE(REG, base, id, val) \
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000079 mmio_write_32((base) + GICD_OFFSET(REG, (id)), (val))
80
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010081#define GICD_WRITE_64(REG, base, id, val) \
82 mmio_write_64((base) + GICD_OFFSET_64(REG, (id)), (val))
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000083
84/*
85 * Bit operations on GIC Distributor register corresponding
86 * to its interrupt ID
87 */
88/* Get bit in GIC Distributor register */
89#define GICD_GET_BIT(REG, base, id) \
90 ((mmio_read_32((base) + GICD_OFFSET(REG, (id))) >> \
91 BIT_NUM(REG, (id))) & 1U)
92
93/* Set bit in GIC Distributor register */
94#define GICD_SET_BIT(REG, base, id) \
95 mmio_setbits_32((base) + GICD_OFFSET(REG, (id)), \
96 ((uint32_t)1 << BIT_NUM(REG, (id))))
97
98/* Clear bit in GIC Distributor register */
99#define GICD_CLR_BIT(REG, base, id) \
100 mmio_clrbits_32((base) + GICD_OFFSET(REG, (id)), \
101 ((uint32_t)1 << BIT_NUM(REG, (id))))
102
103/* Write bit in GIC Distributor register */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100104#define GICD_WRITE_BIT(REG, base, id) \
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000105 mmio_write_32((base) + GICD_OFFSET(REG, (id)), \
106 ((uint32_t)1 << BIT_NUM(REG, (id))))
107
108/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100109 * Calculate 8 and 32-bit GICR register offset
110 * corresponding to its interrupt ID
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000111 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100112#if GIC_EXT_INTID
113 /* GICv3.1 */
114#define GICR_OFFSET_8(REG, id) \
115 (((id) <= MAX_PPI_ID) ? \
116 GICR_##REG##R + (uintptr_t)(id) : \
117 GICR_##REG##R + (uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))
118
119#define GICR_OFFSET(REG, id) \
120 (((id) <= MAX_PPI_ID) ? \
121 GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) : \
122 GICR_##REG##R + ((((uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))\
123 >> REG##R_SHIFT) << 2))
124#else /* GICv3 */
125#define GICR_OFFSET_8(REG, id) \
126 (GICR_##REG##R + (uintptr_t)(id))
127
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000128#define GICR_OFFSET(REG, id) \
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100129 (GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2))
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100130#endif /* GIC_EXT_INTID */
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000131
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100132/* Read/Write GIC Redistributor register corresponding to its interrupt ID */
133#define GICR_READ(REG, base, id) \
134 mmio_read_32((base) + GICR_OFFSET(REG, (id)))
135
136#define GICR_WRITE_8(REG, base, id, val) \
137 mmio_write_8((base) + GICR_OFFSET_8(REG, (id)), (val))
138
139#define GICR_WRITE(REG, base, id, val) \
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100140 mmio_write_32((base) + GICR_OFFSET(REG, (id)), (val))
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000141
142/*
143 * Bit operations on GIC Redistributor register
144 * corresponding to its interrupt ID
145 */
146/* Get bit in GIC Redistributor register */
147#define GICR_GET_BIT(REG, base, id) \
148 ((mmio_read_32((base) + GICR_OFFSET(REG, (id))) >> \
149 BIT_NUM(REG, (id))) & 1U)
150
151/* Write bit in GIC Redistributor register */
152#define GICR_WRITE_BIT(REG, base, id) \
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100153 mmio_write_32((base) + GICR_OFFSET(REG, (id)), \
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000154 ((uint32_t)1 << BIT_NUM(REG, (id))))
155
156/* Set bit in GIC Redistributor register */
157#define GICR_SET_BIT(REG, base, id) \
158 mmio_setbits_32((base) + GICR_OFFSET(REG, (id)), \
159 ((uint32_t)1 << BIT_NUM(REG, (id))))
160
161/* Clear bit in GIC Redistributor register */
162#define GICR_CLR_BIT(REG, base, id) \
163 mmio_clrbits_32((base) + GICR_OFFSET(REG, (id)), \
164 ((uint32_t)1 << BIT_NUM(REG, (id))))
165
Achin Gupta92712a52015-09-03 14:18:02 +0100166/*
Achin Gupta92712a52015-09-03 14:18:02 +0100167 * Macro to convert an mpidr to a value suitable for programming into a
168 * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
169 * to GICv3.
170 */
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100171static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr,
172 unsigned int irm)
173{
174 return (mpidr & ~(U(0xff) << 24)) |
175 ((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT);
176}
Achin Gupta92712a52015-09-03 14:18:02 +0100177
178/*
Achin Gupta92712a52015-09-03 14:18:02 +0100179 * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
180 * are zeroes.
181 */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700182#ifdef __aarch64__
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100183static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
184{
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700185 return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) |
186 ((typer_val >> 32) & U(0xffffff));
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100187}
Soby Mathewd6452322016-05-05 13:59:07 +0100188#else
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100189static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
190{
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700191 return (((typer_val) >> 32) & U(0xffffff));
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100192}
Soby Mathewd6452322016-05-05 13:59:07 +0100193#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100194
195/*******************************************************************************
Soby Mathew327548c2017-07-13 15:19:51 +0100196 * GICv3 private global variables declarations
197 ******************************************************************************/
198extern const gicv3_driver_data_t *gicv3_driver_data;
199
200/*******************************************************************************
Soby Mathew50f6fe42016-02-01 17:59:22 +0000201 * Private GICv3 function prototypes for accessing entire registers.
202 * Note: The raw register values correspond to multiple interrupt IDs and
203 * the number of interrupt IDs involved depends on the register accessed.
Achin Gupta92712a52015-09-03 14:18:02 +0100204 ******************************************************************************/
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100205unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id);
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100206unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100207void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val);
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100208void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);
Soby Mathew50f6fe42016-02-01 17:59:22 +0000209
210/*******************************************************************************
211 * Private GICv3 function prototypes for accessing the GIC registers
212 * corresponding to a single interrupt ID. These functions use bitwise
213 * operations or appropriate register accesses to modify or return
214 * the bit-field corresponding the single interrupt ID.
215 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100216unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100217unsigned int gicr_get_igrpmodr(uintptr_t base, unsigned int id);
218unsigned int gicr_get_igroupr(uintptr_t base, unsigned int id);
219unsigned int gicr_get_isactiver(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +0100220void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100221void gicr_set_igrpmodr(uintptr_t base, unsigned int id);
222void gicr_set_isenabler(uintptr_t base, unsigned int id);
223void gicr_set_icenabler(uintptr_t base, unsigned int id);
224void gicr_set_ispendr(uintptr_t base, unsigned int id);
225void gicr_set_icpendr(uintptr_t base, unsigned int id);
226void gicr_set_igroupr(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +0100227void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100228void gicr_clr_igrpmodr(uintptr_t base, unsigned int id);
229void gicr_clr_igroupr(uintptr_t base, unsigned int id);
Soby Mathew50f6fe42016-02-01 17:59:22 +0000230void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100231void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg);
Soby Mathew50f6fe42016-02-01 17:59:22 +0000232
233/*******************************************************************************
234 * Private GICv3 helper function prototypes
235 ******************************************************************************/
Heyi Guo06f85b42021-01-20 18:50:16 +0800236unsigned int gicv3_get_spi_limit(uintptr_t gicd_base);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100237void gicv3_spis_config_defaults(uintptr_t gicd_base);
238void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100239unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100240 const interrupt_prop_t *interrupt_props,
241 unsigned int interrupt_props_num);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100242unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100243 const interrupt_prop_t *interrupt_props,
244 unsigned int interrupt_props_num);
Achin Gupta92712a52015-09-03 14:18:02 +0100245void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
246 unsigned int rdistif_num,
247 uintptr_t gicr_base,
248 mpidr_hash_fn mpidr_to_core_pos);
249void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
250void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);
251
252/*******************************************************************************
253 * GIC Distributor interface accessors
254 ******************************************************************************/
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100255/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100256 * Wait for updates to:
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100257 * GICD_CTLR[2:0] - the Group Enables
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100258 * GICD_CTLR[7:4] - the ARE bits, E1NWF bit and DS bit
259 * GICD_ICENABLER<n> - the clearing of enable state for SPIs
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100260 */
261static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
262{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000263 while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U) {
264 }
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100265}
266
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000267static inline uint32_t gicd_read_pidr2(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100268{
269 return mmio_read_32(base + GICD_PIDR2_GICV3);
270}
271
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000272static inline uint64_t gicd_read_irouter(uintptr_t base, unsigned int id)
Achin Gupta92712a52015-09-03 14:18:02 +0100273{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100274 assert(id >= MIN_SPI_ID);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100275 return GICD_READ_64(IROUTE, base, id);
Achin Gupta92712a52015-09-03 14:18:02 +0100276}
277
278static inline void gicd_write_irouter(uintptr_t base,
279 unsigned int id,
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000280 uint64_t affinity)
Achin Gupta92712a52015-09-03 14:18:02 +0100281{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100282 assert(id >= MIN_SPI_ID);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100283 GICD_WRITE_64(IROUTE, base, id, affinity);
Achin Gupta92712a52015-09-03 14:18:02 +0100284}
285
286static inline void gicd_clr_ctlr(uintptr_t base,
287 unsigned int bitmap,
288 unsigned int rwp)
289{
290 gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000291 if (rwp != 0U) {
Achin Gupta92712a52015-09-03 14:18:02 +0100292 gicd_wait_for_pending_write(base);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000293 }
Achin Gupta92712a52015-09-03 14:18:02 +0100294}
295
296static inline void gicd_set_ctlr(uintptr_t base,
297 unsigned int bitmap,
298 unsigned int rwp)
299{
300 gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000301 if (rwp != 0U) {
Achin Gupta92712a52015-09-03 14:18:02 +0100302 gicd_wait_for_pending_write(base);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000303 }
Achin Gupta92712a52015-09-03 14:18:02 +0100304}
305
306/*******************************************************************************
307 * GIC Redistributor interface accessors
308 ******************************************************************************/
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100309static inline uint32_t gicr_read_ctlr(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100310{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100311 return mmio_read_32(base + GICR_CTLR);
Achin Gupta92712a52015-09-03 14:18:02 +0100312}
313
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100314static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100315{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100316 mmio_write_32(base + GICR_CTLR, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100317}
318
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000319static inline uint64_t gicr_read_typer(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100320{
321 return mmio_read_64(base + GICR_TYPER);
322}
323
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000324static inline uint32_t gicr_read_waker(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100325{
326 return mmio_read_32(base + GICR_WAKER);
327}
328
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000329static inline void gicr_write_waker(uintptr_t base, uint32_t val)
Achin Gupta92712a52015-09-03 14:18:02 +0100330{
331 mmio_write_32(base + GICR_WAKER, val);
332}
333
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100334/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100335 * Wait for updates to:
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100336 * GICR_ICENABLER0
337 * GICR_CTLR.DPG1S
338 * GICR_CTLR.DPG1NS
339 * GICR_CTLR.DPG0
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100340 * GICR_CTLR, which clears EnableLPIs from 1 to 0
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100341 */
342static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
343{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000344 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U) {
345 }
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100346}
347
Soby Mathew327548c2017-07-13 15:19:51 +0100348static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
349{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000350 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U) {
351 }
Soby Mathew327548c2017-07-13 15:19:51 +0100352}
353
354/* Private implementation of Distributor power control hooks */
355void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
356void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);
357
Soby Mathew50f6fe42016-02-01 17:59:22 +0000358/*******************************************************************************
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000359 * GIC Redistributor functions for accessing entire registers.
Soby Mathew50f6fe42016-02-01 17:59:22 +0000360 * Note: The raw register values correspond to multiple interrupt IDs and
361 * the number of interrupt IDs involved depends on the register accessed.
362 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100363
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100364/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100365 * Accessors to read/write GIC Redistributor ICENABLER0 register
366 */
367static inline unsigned int gicr_read_icenabler0(uintptr_t base)
368{
369 return mmio_read_32(base + GICR_ICENABLER0);
370}
371
372static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
373{
374 mmio_write_32(base + GICR_ICENABLER0, val);
375}
376
377/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100378 * Accessors to read/write GIC Redistributor ICENABLER0 and ICENABLERE
379 * register corresponding to its number
380 */
381static inline unsigned int gicr_read_icenabler(uintptr_t base,
382 unsigned int reg_num)
Achin Gupta92712a52015-09-03 14:18:02 +0100383{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100384 return mmio_read_32(base + GICR_ICENABLER + (reg_num << 2));
Achin Gupta92712a52015-09-03 14:18:02 +0100385}
386
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100387static inline void gicr_write_icenabler(uintptr_t base, unsigned int reg_num,
388 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100389{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100390 mmio_write_32(base + GICR_ICENABLER + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100391}
392
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100393/*
394 * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 registers
395 */
396static inline unsigned int gicr_read_icfgr0(uintptr_t base)
397{
398 return mmio_read_32(base + GICR_ICFGR0);
399}
400
401static inline unsigned int gicr_read_icfgr1(uintptr_t base)
402{
403 return mmio_read_32(base + GICR_ICFGR1);
404}
405
406static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
407{
408 mmio_write_32(base + GICR_ICFGR0, val);
409}
410
411static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
412{
413 mmio_write_32(base + GICR_ICFGR1, val);
414}
415
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100416/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100417 * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 and ICFGRE
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100418 * register corresponding to its number
419 */
420static inline unsigned int gicr_read_icfgr(uintptr_t base, unsigned int reg_num)
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100421{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100422 return mmio_read_32(base + GICR_ICFGR + (reg_num << 2));
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100423}
424
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100425static inline void gicr_write_icfgr(uintptr_t base, unsigned int reg_num,
426 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100427{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100428 mmio_write_32(base + GICR_ICFGR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100429}
430
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100431/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100432 * Accessor to write GIC Redistributor ICPENDR0 register
433 */
434static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
435{
436 mmio_write_32(base + GICR_ICPENDR0, val);
437}
438
439/*
440 * Accessor to write GIC Redistributor ICPENDR0 and ICPENDRE
441 * register corresponding to its number
442 */
443static inline void gicr_write_icpendr(uintptr_t base, unsigned int reg_num,
444 unsigned int val)
445{
446 mmio_write_32(base + GICR_ICPENDR + (reg_num << 2), val);
447}
448
449/*
450 * Accessors to read/write GIC Redistributor IGROUPR0 register
451 */
452static inline unsigned int gicr_read_igroupr0(uintptr_t base)
453{
454 return mmio_read_32(base + GICR_IGROUPR0);
455}
456
457static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
458{
459 mmio_write_32(base + GICR_IGROUPR0, val);
460}
461
462/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100463 * Accessors to read/write GIC Redistributor IGROUPR0 and IGROUPRE
464 * register corresponding to its number
465 */
466static inline unsigned int gicr_read_igroupr(uintptr_t base,
467 unsigned int reg_num)
Achin Gupta92712a52015-09-03 14:18:02 +0100468{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100469 return mmio_read_32(base + GICR_IGROUPR + (reg_num << 2));
Achin Gupta92712a52015-09-03 14:18:02 +0100470}
471
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100472static inline void gicr_write_igroupr(uintptr_t base, unsigned int reg_num,
473 unsigned int val)
Soby Mathew327548c2017-07-13 15:19:51 +0100474{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100475 mmio_write_32(base + GICR_IGROUPR + (reg_num << 2), val);
Soby Mathew327548c2017-07-13 15:19:51 +0100476}
477
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100478/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100479 * Accessors to read/write GIC Redistributor IGRPMODR0 register
480 */
481static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
482{
483 return mmio_read_32(base + GICR_IGRPMODR0);
484}
485
486static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
487{
488 mmio_write_32(base + GICR_IGRPMODR0, val);
489}
490
491/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100492 * Accessors to read/write GIC Redistributor IGRPMODR0 and IGRPMODRE
493 * register corresponding to its number
494 */
495static inline unsigned int gicr_read_igrpmodr(uintptr_t base,
496 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100497{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100498 return mmio_read_32(base + GICR_IGRPMODR + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100499}
500
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100501static inline void gicr_write_igrpmodr(uintptr_t base, unsigned int reg_num,
502 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100503{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100504 mmio_write_32(base + GICR_IGRPMODR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100505}
506
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100507/*
508 * Accessors to read/write the GIC Redistributor IPRIORITYR(E) register
509 * corresponding to its number, 4 interrupts IDs at a time.
510 */
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100511static inline unsigned int gicr_ipriorityr_read(uintptr_t base,
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100512 unsigned int reg_num)
Achin Gupta92712a52015-09-03 14:18:02 +0100513{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100514 return mmio_read_32(base + GICR_IPRIORITYR + (reg_num << 2));
Achin Gupta92712a52015-09-03 14:18:02 +0100515}
516
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100517static inline void gicr_ipriorityr_write(uintptr_t base, unsigned int reg_num,
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100518 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100519{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100520 mmio_write_32(base + GICR_IPRIORITYR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100521}
522
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100523/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100524 * Accessors to read/write GIC Redistributor ISACTIVER0 register
525 */
526static inline unsigned int gicr_read_isactiver0(uintptr_t base)
527{
528 return mmio_read_32(base + GICR_ISACTIVER0);
529}
530
531static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
532{
533 mmio_write_32(base + GICR_ISACTIVER0, val);
534}
535
536/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100537 * Accessors to read/write GIC Redistributor ISACTIVER0 and ISACTIVERE
538 * register corresponding to its number
539 */
540static inline unsigned int gicr_read_isactiver(uintptr_t base,
541 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100542{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100543 return mmio_read_32(base + GICR_ISACTIVER + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100544}
545
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100546static inline void gicr_write_isactiver(uintptr_t base, unsigned int reg_num,
547 unsigned int val)
Soby Mathew327548c2017-07-13 15:19:51 +0100548{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100549 mmio_write_32(base + GICR_ISACTIVER + (reg_num << 2), val);
Soby Mathew327548c2017-07-13 15:19:51 +0100550}
551
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100552/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100553 * Accessors to read/write GIC Redistributor ISENABLER0 register
554 */
555static inline unsigned int gicr_read_isenabler0(uintptr_t base)
556{
557 return mmio_read_32(base + GICR_ISENABLER0);
558}
559
560static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
561{
562 mmio_write_32(base + GICR_ISENABLER0, val);
563}
564
565/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100566 * Accessors to read/write GIC Redistributor ISENABLER0 and ISENABLERE
567 * register corresponding to its number
568 */
569static inline unsigned int gicr_read_isenabler(uintptr_t base,
570 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100571{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100572 return mmio_read_32(base + GICR_ISENABLER + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100573}
574
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100575static inline void gicr_write_isenabler(uintptr_t base, unsigned int reg_num,
576 unsigned int val)
Soby Mathew327548c2017-07-13 15:19:51 +0100577{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100578 mmio_write_32(base + GICR_ISENABLER + (reg_num << 2), val);
Soby Mathew327548c2017-07-13 15:19:51 +0100579}
580
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100581/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100582 * Accessors to read/write GIC Redistributor ISPENDR0 register
583 */
584static inline unsigned int gicr_read_ispendr0(uintptr_t base)
585{
586 return mmio_read_32(base + GICR_ISPENDR0);
587}
588
589static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
590{
591 mmio_write_32(base + GICR_ISPENDR0, val);
592}
593
594/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100595 * Accessors to read/write GIC Redistributor ISPENDR0 and ISPENDRE
596 * register corresponding to its number
597 */
598static inline unsigned int gicr_read_ispendr(uintptr_t base,
599 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100600{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100601 return mmio_read_32(base + GICR_ISPENDR + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100602}
603
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100604static inline void gicr_write_ispendr(uintptr_t base, unsigned int reg_num,
605 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100606{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100607 mmio_write_32(base + GICR_ISPENDR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100608}
609
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100610/*
611 * Accessors to read/write GIC Redistributor NSACR register
612 */
613static inline unsigned int gicr_read_nsacr(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100614{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100615 return mmio_read_32(base + GICR_NSACR);
Soby Mathew327548c2017-07-13 15:19:51 +0100616}
617
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100618static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100619{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100620 mmio_write_32(base + GICR_NSACR, val);
Achin Gupta92712a52015-09-03 14:18:02 +0100621}
622
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100623/*
624 * Accessors to read/write GIC Redistributor PROPBASER register
625 */
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100626static inline uint64_t gicr_read_propbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100627{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100628 return mmio_read_64(base + GICR_PROPBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100629}
630
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100631static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100632{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100633 mmio_write_64(base + GICR_PROPBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100634}
635
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100636/*
637 * Accessors to read/write GIC Redistributor PENDBASER register
638 */
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100639static inline uint64_t gicr_read_pendbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100640{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100641 return mmio_read_64(base + GICR_PENDBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100642}
643
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100644static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100645{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100646 mmio_write_64(base + GICR_PENDBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100647}
648
Soby Mathewf6f1a322017-07-18 16:12:45 +0100649/*******************************************************************************
650 * GIC ITS functions to read and write entire ITS registers.
651 ******************************************************************************/
652static inline uint32_t gits_read_ctlr(uintptr_t base)
653{
654 return mmio_read_32(base + GITS_CTLR);
655}
656
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000657static inline void gits_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100658{
659 mmio_write_32(base + GITS_CTLR, val);
660}
661
662static inline uint64_t gits_read_cbaser(uintptr_t base)
663{
664 return mmio_read_64(base + GITS_CBASER);
665}
666
667static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
668{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100669 mmio_write_64(base + GITS_CBASER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100670}
671
672static inline uint64_t gits_read_cwriter(uintptr_t base)
673{
674 return mmio_read_64(base + GITS_CWRITER);
675}
676
677static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
678{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100679 mmio_write_64(base + GITS_CWRITER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100680}
681
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000682static inline uint64_t gits_read_baser(uintptr_t base,
683 unsigned int its_table_id)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100684{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100685 assert(its_table_id < 8U);
686 return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
Soby Mathewf6f1a322017-07-18 16:12:45 +0100687}
688
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000689static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id,
690 uint64_t val)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100691{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100692 assert(its_table_id < 8U);
693 mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100694}
695
696/*
697 * Wait for Quiescent bit when GIC ITS is disabled
698 */
699static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
700{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100701 assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000702 while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U) {
703 }
Soby Mathewf6f1a322017-07-18 16:12:45 +0100704}
705
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000706#endif /* GICV3_PRIVATE_H */