blob: 416cdd01838c25ca039af9bf914240a2e01cb75f [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 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100236void gicv3_spis_config_defaults(uintptr_t gicd_base);
237void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100238unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100239 const interrupt_prop_t *interrupt_props,
240 unsigned int interrupt_props_num);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100241unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100242 const interrupt_prop_t *interrupt_props,
243 unsigned int interrupt_props_num);
Achin Gupta92712a52015-09-03 14:18:02 +0100244void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
245 unsigned int rdistif_num,
246 uintptr_t gicr_base,
247 mpidr_hash_fn mpidr_to_core_pos);
248void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
249void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);
250
251/*******************************************************************************
252 * GIC Distributor interface accessors
253 ******************************************************************************/
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100254/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100255 * Wait for updates to:
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100256 * GICD_CTLR[2:0] - the Group Enables
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100257 * GICD_CTLR[7:4] - the ARE bits, E1NWF bit and DS bit
258 * GICD_ICENABLER<n> - the clearing of enable state for SPIs
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100259 */
260static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
261{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000262 while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U) {
263 }
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100264}
265
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000266static inline uint32_t gicd_read_pidr2(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100267{
268 return mmio_read_32(base + GICD_PIDR2_GICV3);
269}
270
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000271static inline uint64_t gicd_read_irouter(uintptr_t base, unsigned int id)
Achin Gupta92712a52015-09-03 14:18:02 +0100272{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100273 assert(id >= MIN_SPI_ID);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100274 return GICD_READ_64(IROUTE, base, id);
Achin Gupta92712a52015-09-03 14:18:02 +0100275}
276
277static inline void gicd_write_irouter(uintptr_t base,
278 unsigned int id,
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000279 uint64_t affinity)
Achin Gupta92712a52015-09-03 14:18:02 +0100280{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100281 assert(id >= MIN_SPI_ID);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100282 GICD_WRITE_64(IROUTE, base, id, affinity);
Achin Gupta92712a52015-09-03 14:18:02 +0100283}
284
285static inline void gicd_clr_ctlr(uintptr_t base,
286 unsigned int bitmap,
287 unsigned int rwp)
288{
289 gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000290 if (rwp != 0U) {
Achin Gupta92712a52015-09-03 14:18:02 +0100291 gicd_wait_for_pending_write(base);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000292 }
Achin Gupta92712a52015-09-03 14:18:02 +0100293}
294
295static inline void gicd_set_ctlr(uintptr_t base,
296 unsigned int bitmap,
297 unsigned int rwp)
298{
299 gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000300 if (rwp != 0U) {
Achin Gupta92712a52015-09-03 14:18:02 +0100301 gicd_wait_for_pending_write(base);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000302 }
Achin Gupta92712a52015-09-03 14:18:02 +0100303}
304
305/*******************************************************************************
306 * GIC Redistributor interface accessors
307 ******************************************************************************/
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100308static inline uint32_t gicr_read_ctlr(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100309{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100310 return mmio_read_32(base + GICR_CTLR);
Achin Gupta92712a52015-09-03 14:18:02 +0100311}
312
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100313static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100314{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100315 mmio_write_32(base + GICR_CTLR, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100316}
317
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000318static inline uint64_t gicr_read_typer(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100319{
320 return mmio_read_64(base + GICR_TYPER);
321}
322
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000323static inline uint32_t gicr_read_waker(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100324{
325 return mmio_read_32(base + GICR_WAKER);
326}
327
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000328static inline void gicr_write_waker(uintptr_t base, uint32_t val)
Achin Gupta92712a52015-09-03 14:18:02 +0100329{
330 mmio_write_32(base + GICR_WAKER, val);
331}
332
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100333/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100334 * Wait for updates to:
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100335 * GICR_ICENABLER0
336 * GICR_CTLR.DPG1S
337 * GICR_CTLR.DPG1NS
338 * GICR_CTLR.DPG0
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100339 * GICR_CTLR, which clears EnableLPIs from 1 to 0
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100340 */
341static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
342{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000343 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U) {
344 }
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100345}
346
Soby Mathew327548c2017-07-13 15:19:51 +0100347static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
348{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000349 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U) {
350 }
Soby Mathew327548c2017-07-13 15:19:51 +0100351}
352
353/* Private implementation of Distributor power control hooks */
354void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
355void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);
356
Soby Mathew50f6fe42016-02-01 17:59:22 +0000357/*******************************************************************************
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000358 * GIC Redistributor functions for accessing entire registers.
Soby Mathew50f6fe42016-02-01 17:59:22 +0000359 * Note: The raw register values correspond to multiple interrupt IDs and
360 * the number of interrupt IDs involved depends on the register accessed.
361 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100362
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100363/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100364 * Accessors to read/write GIC Redistributor ICENABLER0 register
365 */
366static inline unsigned int gicr_read_icenabler0(uintptr_t base)
367{
368 return mmio_read_32(base + GICR_ICENABLER0);
369}
370
371static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
372{
373 mmio_write_32(base + GICR_ICENABLER0, val);
374}
375
376/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100377 * Accessors to read/write GIC Redistributor ICENABLER0 and ICENABLERE
378 * register corresponding to its number
379 */
380static inline unsigned int gicr_read_icenabler(uintptr_t base,
381 unsigned int reg_num)
Achin Gupta92712a52015-09-03 14:18:02 +0100382{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100383 return mmio_read_32(base + GICR_ICENABLER + (reg_num << 2));
Achin Gupta92712a52015-09-03 14:18:02 +0100384}
385
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100386static inline void gicr_write_icenabler(uintptr_t base, unsigned int reg_num,
387 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100388{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100389 mmio_write_32(base + GICR_ICENABLER + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100390}
391
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100392/*
393 * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 registers
394 */
395static inline unsigned int gicr_read_icfgr0(uintptr_t base)
396{
397 return mmio_read_32(base + GICR_ICFGR0);
398}
399
400static inline unsigned int gicr_read_icfgr1(uintptr_t base)
401{
402 return mmio_read_32(base + GICR_ICFGR1);
403}
404
405static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
406{
407 mmio_write_32(base + GICR_ICFGR0, val);
408}
409
410static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
411{
412 mmio_write_32(base + GICR_ICFGR1, val);
413}
414
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100415/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100416 * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 and ICFGRE
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100417 * register corresponding to its number
418 */
419static inline unsigned int gicr_read_icfgr(uintptr_t base, unsigned int reg_num)
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100420{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100421 return mmio_read_32(base + GICR_ICFGR + (reg_num << 2));
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100422}
423
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100424static inline void gicr_write_icfgr(uintptr_t base, unsigned int reg_num,
425 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100426{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100427 mmio_write_32(base + GICR_ICFGR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100428}
429
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100430/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100431 * Accessor to write GIC Redistributor ICPENDR0 register
432 */
433static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
434{
435 mmio_write_32(base + GICR_ICPENDR0, val);
436}
437
438/*
439 * Accessor to write GIC Redistributor ICPENDR0 and ICPENDRE
440 * register corresponding to its number
441 */
442static inline void gicr_write_icpendr(uintptr_t base, unsigned int reg_num,
443 unsigned int val)
444{
445 mmio_write_32(base + GICR_ICPENDR + (reg_num << 2), val);
446}
447
448/*
449 * Accessors to read/write GIC Redistributor IGROUPR0 register
450 */
451static inline unsigned int gicr_read_igroupr0(uintptr_t base)
452{
453 return mmio_read_32(base + GICR_IGROUPR0);
454}
455
456static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
457{
458 mmio_write_32(base + GICR_IGROUPR0, val);
459}
460
461/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100462 * Accessors to read/write GIC Redistributor IGROUPR0 and IGROUPRE
463 * register corresponding to its number
464 */
465static inline unsigned int gicr_read_igroupr(uintptr_t base,
466 unsigned int reg_num)
Achin Gupta92712a52015-09-03 14:18:02 +0100467{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100468 return mmio_read_32(base + GICR_IGROUPR + (reg_num << 2));
Achin Gupta92712a52015-09-03 14:18:02 +0100469}
470
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100471static inline void gicr_write_igroupr(uintptr_t base, unsigned int reg_num,
472 unsigned int val)
Soby Mathew327548c2017-07-13 15:19:51 +0100473{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100474 mmio_write_32(base + GICR_IGROUPR + (reg_num << 2), val);
Soby Mathew327548c2017-07-13 15:19:51 +0100475}
476
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100477/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100478 * Accessors to read/write GIC Redistributor IGRPMODR0 register
479 */
480static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
481{
482 return mmio_read_32(base + GICR_IGRPMODR0);
483}
484
485static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
486{
487 mmio_write_32(base + GICR_IGRPMODR0, val);
488}
489
490/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100491 * Accessors to read/write GIC Redistributor IGRPMODR0 and IGRPMODRE
492 * register corresponding to its number
493 */
494static inline unsigned int gicr_read_igrpmodr(uintptr_t base,
495 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100496{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100497 return mmio_read_32(base + GICR_IGRPMODR + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100498}
499
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100500static inline void gicr_write_igrpmodr(uintptr_t base, unsigned int reg_num,
501 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100502{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100503 mmio_write_32(base + GICR_IGRPMODR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100504}
505
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100506/*
507 * Accessors to read/write the GIC Redistributor IPRIORITYR(E) register
508 * corresponding to its number, 4 interrupts IDs at a time.
509 */
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100510static inline unsigned int gicr_ipriorityr_read(uintptr_t base,
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100511 unsigned int reg_num)
Achin Gupta92712a52015-09-03 14:18:02 +0100512{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100513 return mmio_read_32(base + GICR_IPRIORITYR + (reg_num << 2));
Achin Gupta92712a52015-09-03 14:18:02 +0100514}
515
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100516static inline void gicr_ipriorityr_write(uintptr_t base, unsigned int reg_num,
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100517 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100518{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100519 mmio_write_32(base + GICR_IPRIORITYR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100520}
521
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100522/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100523 * Accessors to read/write GIC Redistributor ISACTIVER0 register
524 */
525static inline unsigned int gicr_read_isactiver0(uintptr_t base)
526{
527 return mmio_read_32(base + GICR_ISACTIVER0);
528}
529
530static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
531{
532 mmio_write_32(base + GICR_ISACTIVER0, val);
533}
534
535/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100536 * Accessors to read/write GIC Redistributor ISACTIVER0 and ISACTIVERE
537 * register corresponding to its number
538 */
539static inline unsigned int gicr_read_isactiver(uintptr_t base,
540 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100541{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100542 return mmio_read_32(base + GICR_ISACTIVER + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100543}
544
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100545static inline void gicr_write_isactiver(uintptr_t base, unsigned int reg_num,
546 unsigned int val)
Soby Mathew327548c2017-07-13 15:19:51 +0100547{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100548 mmio_write_32(base + GICR_ISACTIVER + (reg_num << 2), val);
Soby Mathew327548c2017-07-13 15:19:51 +0100549}
550
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100551/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100552 * Accessors to read/write GIC Redistributor ISENABLER0 register
553 */
554static inline unsigned int gicr_read_isenabler0(uintptr_t base)
555{
556 return mmio_read_32(base + GICR_ISENABLER0);
557}
558
559static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
560{
561 mmio_write_32(base + GICR_ISENABLER0, val);
562}
563
564/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100565 * Accessors to read/write GIC Redistributor ISENABLER0 and ISENABLERE
566 * register corresponding to its number
567 */
568static inline unsigned int gicr_read_isenabler(uintptr_t base,
569 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100570{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100571 return mmio_read_32(base + GICR_ISENABLER + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100572}
573
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100574static inline void gicr_write_isenabler(uintptr_t base, unsigned int reg_num,
575 unsigned int val)
Soby Mathew327548c2017-07-13 15:19:51 +0100576{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100577 mmio_write_32(base + GICR_ISENABLER + (reg_num << 2), val);
Soby Mathew327548c2017-07-13 15:19:51 +0100578}
579
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100580/*
Alexei Fedorovc7510c52020-04-07 18:16:18 +0100581 * Accessors to read/write GIC Redistributor ISPENDR0 register
582 */
583static inline unsigned int gicr_read_ispendr0(uintptr_t base)
584{
585 return mmio_read_32(base + GICR_ISPENDR0);
586}
587
588static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
589{
590 mmio_write_32(base + GICR_ISPENDR0, val);
591}
592
593/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100594 * Accessors to read/write GIC Redistributor ISPENDR0 and ISPENDRE
595 * register corresponding to its number
596 */
597static inline unsigned int gicr_read_ispendr(uintptr_t base,
598 unsigned int reg_num)
Soby Mathew327548c2017-07-13 15:19:51 +0100599{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100600 return mmio_read_32(base + GICR_ISPENDR + (reg_num << 2));
Soby Mathew327548c2017-07-13 15:19:51 +0100601}
602
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100603static inline void gicr_write_ispendr(uintptr_t base, unsigned int reg_num,
604 unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100605{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100606 mmio_write_32(base + GICR_ISPENDR + (reg_num << 2), val);
Achin Gupta92712a52015-09-03 14:18:02 +0100607}
608
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100609/*
610 * Accessors to read/write GIC Redistributor NSACR register
611 */
612static inline unsigned int gicr_read_nsacr(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100613{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100614 return mmio_read_32(base + GICR_NSACR);
Soby Mathew327548c2017-07-13 15:19:51 +0100615}
616
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100617static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
Achin Gupta92712a52015-09-03 14:18:02 +0100618{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100619 mmio_write_32(base + GICR_NSACR, val);
Achin Gupta92712a52015-09-03 14:18:02 +0100620}
621
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100622/*
623 * Accessors to read/write GIC Redistributor PROPBASER register
624 */
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100625static inline uint64_t gicr_read_propbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100626{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100627 return mmio_read_64(base + GICR_PROPBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100628}
629
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100630static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100631{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100632 mmio_write_64(base + GICR_PROPBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100633}
634
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100635/*
636 * Accessors to read/write GIC Redistributor PENDBASER register
637 */
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100638static inline uint64_t gicr_read_pendbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100639{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100640 return mmio_read_64(base + GICR_PENDBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100641}
642
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100643static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100644{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100645 mmio_write_64(base + GICR_PENDBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100646}
647
Soby Mathewf6f1a322017-07-18 16:12:45 +0100648/*******************************************************************************
649 * GIC ITS functions to read and write entire ITS registers.
650 ******************************************************************************/
651static inline uint32_t gits_read_ctlr(uintptr_t base)
652{
653 return mmio_read_32(base + GITS_CTLR);
654}
655
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000656static inline void gits_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100657{
658 mmio_write_32(base + GITS_CTLR, val);
659}
660
661static inline uint64_t gits_read_cbaser(uintptr_t base)
662{
663 return mmio_read_64(base + GITS_CBASER);
664}
665
666static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
667{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100668 mmio_write_64(base + GITS_CBASER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100669}
670
671static inline uint64_t gits_read_cwriter(uintptr_t base)
672{
673 return mmio_read_64(base + GITS_CWRITER);
674}
675
676static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
677{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100678 mmio_write_64(base + GITS_CWRITER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100679}
680
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000681static inline uint64_t gits_read_baser(uintptr_t base,
682 unsigned int its_table_id)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100683{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100684 assert(its_table_id < 8U);
685 return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
Soby Mathewf6f1a322017-07-18 16:12:45 +0100686}
687
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000688static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id,
689 uint64_t val)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100690{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100691 assert(its_table_id < 8U);
692 mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100693}
694
695/*
696 * Wait for Quiescent bit when GIC ITS is disabled
697 */
698static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
699{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100700 assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000701 while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U) {
702 }
Soby Mathewf6f1a322017-07-18 16:12:45 +0100703}
704
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000705#endif /* GICV3_PRIVATE_H */