blob: dae01cb1ed516080b27a7b10ce3742944dc3d5b0 [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +00002 * Copyright (c) 2015-2020, 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) \
29 ((id) & ((1U << REG##_SHIFT) - 1U))
30
31/* Calculate 8-bit GICD register offset corresponding to its interrupt ID */
32#define GICD_OFFSET_8(REG, id) \
33 GICD_##REG + (id)
34
35/* Calculate 32-bit GICD register offset corresponding to its interrupt ID */
36#define GICD_OFFSET(REG, id) \
37 GICD_##REG + (((id) >> REG##_SHIFT) << 2)
38
39/* Calculate 64-bit GICD register offset corresponding to its interrupt ID */
40#define GICD_OFFSET_64(REG, id) \
41 GICD_##REG + (((id) >> REG##_SHIFT) << 3)
42
43/* Read 32-bit GIC Distributor register corresponding to its interrupt ID */
44#define GICD_READ(REG, base, id) \
45 mmio_read_32((base) + GICD_OFFSET(REG, (id)))
46
47/* Read 64-bit GIC Distributor register corresponding to its interrupt ID */
48#define GICD_READ_64(REG, base, id) \
49 mmio_read_64((base) + GICD_OFFSET_64(REG, (id)))
50
51/* Write to 64-bit GIC Distributor register corresponding to its interrupt ID */
52#define GICD_WRITE_64(REG, base, id, val) \
53 mmio_write_64((base) + GICD_OFFSET_64(REG, (id)), (val))
54
55/* Write to 32-bit GIC Distributor register corresponding to its interrupt ID */
56#define GICD_WRITE(REG, base, id, val) \
57 mmio_write_32((base) + GICD_OFFSET(REG, (id)), (val))
58
59/* Write to 8-bit GIC Distributor register corresponding to its interrupt ID */
60#define GICD_WRITE_8(REG, base, id, val) \
61 mmio_write_8((base) + GICD_OFFSET_8(REG, (id)), (val))
62
63/*
64 * Bit operations on GIC Distributor register corresponding
65 * to its interrupt ID
66 */
67/* Get bit in GIC Distributor register */
68#define GICD_GET_BIT(REG, base, id) \
69 ((mmio_read_32((base) + GICD_OFFSET(REG, (id))) >> \
70 BIT_NUM(REG, (id))) & 1U)
71
72/* Set bit in GIC Distributor register */
73#define GICD_SET_BIT(REG, base, id) \
74 mmio_setbits_32((base) + GICD_OFFSET(REG, (id)), \
75 ((uint32_t)1 << BIT_NUM(REG, (id))))
76
77/* Clear bit in GIC Distributor register */
78#define GICD_CLR_BIT(REG, base, id) \
79 mmio_clrbits_32((base) + GICD_OFFSET(REG, (id)), \
80 ((uint32_t)1 << BIT_NUM(REG, (id))))
81
82/* Write bit in GIC Distributor register */
83#define GICD_WRITE_BIT(REG, base, id) \
84 mmio_write_32((base) + GICD_OFFSET(REG, (id)), \
85 ((uint32_t)1 << BIT_NUM(REG, (id))))
86
87/*
88 * Calculate GICv3 GICR register offset
89 */
90#define GICR_OFFSET(REG, id) \
91 GICR_##REG + (((id) >> REG##_SHIFT) << 2)
92
93/* Write to GIC Redistributor register corresponding to its interrupt ID */
94#define GICR_WRITE_8(REG, base, id, val) \
95 mmio_write_8((base) + GICR_##REG + (id), (val))
96
97/*
98 * Bit operations on GIC Redistributor register
99 * corresponding to its interrupt ID
100 */
101/* Get bit in GIC Redistributor register */
102#define GICR_GET_BIT(REG, base, id) \
103 ((mmio_read_32((base) + GICR_OFFSET(REG, (id))) >> \
104 BIT_NUM(REG, (id))) & 1U)
105
106/* Write bit in GIC Redistributor register */
107#define GICR_WRITE_BIT(REG, base, id) \
108 mmio_write_32((base) + GICR_OFFSET(REG, (id)), \
109 ((uint32_t)1 << BIT_NUM(REG, (id))))
110
111/* Set bit in GIC Redistributor register */
112#define GICR_SET_BIT(REG, base, id) \
113 mmio_setbits_32((base) + GICR_OFFSET(REG, (id)), \
114 ((uint32_t)1 << BIT_NUM(REG, (id))))
115
116/* Clear bit in GIC Redistributor register */
117#define GICR_CLR_BIT(REG, base, id) \
118 mmio_clrbits_32((base) + GICR_OFFSET(REG, (id)), \
119 ((uint32_t)1 << BIT_NUM(REG, (id))))
120
Achin Gupta92712a52015-09-03 14:18:02 +0100121/*
Achin Gupta92712a52015-09-03 14:18:02 +0100122 * Macro to convert an mpidr to a value suitable for programming into a
123 * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
124 * to GICv3.
125 */
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100126static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr,
127 unsigned int irm)
128{
129 return (mpidr & ~(U(0xff) << 24)) |
130 ((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT);
131}
Achin Gupta92712a52015-09-03 14:18:02 +0100132
133/*
Achin Gupta92712a52015-09-03 14:18:02 +0100134 * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
135 * are zeroes.
136 */
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700137#ifdef __aarch64__
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100138static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
139{
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700140 return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) |
141 ((typer_val >> 32) & U(0xffffff));
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100142}
Soby Mathewd6452322016-05-05 13:59:07 +0100143#else
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100144static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
145{
Julius Werner8e0ef0f2019-07-09 14:02:43 -0700146 return (((typer_val) >> 32) & U(0xffffff));
Antonio Nino Diazdd4e59e2018-08-13 15:29:29 +0100147}
Soby Mathewd6452322016-05-05 13:59:07 +0100148#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100149
150/*******************************************************************************
Soby Mathew327548c2017-07-13 15:19:51 +0100151 * GICv3 private global variables declarations
152 ******************************************************************************/
153extern const gicv3_driver_data_t *gicv3_driver_data;
154
155/*******************************************************************************
Soby Mathew50f6fe42016-02-01 17:59:22 +0000156 * Private GICv3 function prototypes for accessing entire registers.
157 * Note: The raw register values correspond to multiple interrupt IDs and
158 * the number of interrupt IDs involved depends on the register accessed.
Achin Gupta92712a52015-09-03 14:18:02 +0100159 ******************************************************************************/
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000160uint32_t gicd_read_igrpmodr(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +0100161unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000162void gicd_write_igrpmodr(uintptr_t base, unsigned int id, uint32_t val);
Soby Mathew50f6fe42016-02-01 17:59:22 +0000163void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);
164
165/*******************************************************************************
166 * Private GICv3 function prototypes for accessing the GIC registers
167 * corresponding to a single interrupt ID. These functions use bitwise
168 * operations or appropriate register accesses to modify or return
169 * the bit-field corresponding the single interrupt ID.
170 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100171unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
172unsigned int gicr_get_igrpmodr0(uintptr_t base, unsigned int id);
173unsigned int gicr_get_igroupr0(uintptr_t base, unsigned int id);
Jeenu Viswambharan24e70292017-09-22 08:32:09 +0100174unsigned int gicr_get_isactiver0(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +0100175void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
176void gicr_set_igrpmodr0(uintptr_t base, unsigned int id);
177void gicr_set_isenabler0(uintptr_t base, unsigned int id);
Jeenu Viswambharan0fcdfff2017-09-22 08:32:09 +0100178void gicr_set_icenabler0(uintptr_t base, unsigned int id);
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100179void gicr_set_ispendr0(uintptr_t base, unsigned int id);
180void gicr_set_icpendr0(uintptr_t base, unsigned int id);
Achin Gupta92712a52015-09-03 14:18:02 +0100181void gicr_set_igroupr0(uintptr_t base, unsigned int id);
182void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
183void gicr_clr_igrpmodr0(uintptr_t base, unsigned int id);
184void gicr_clr_igroupr0(uintptr_t base, unsigned int id);
Soby Mathew50f6fe42016-02-01 17:59:22 +0000185void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
Roberto Vargas2ca18d92018-02-12 12:36:17 +0000186void gicr_set_icfgr0(uintptr_t base, unsigned int id, unsigned int cfg);
187void gicr_set_icfgr1(uintptr_t base, unsigned int id, unsigned int cfg);
Soby Mathew50f6fe42016-02-01 17:59:22 +0000188
189/*******************************************************************************
190 * Private GICv3 helper function prototypes
191 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100192void gicv3_spis_config_defaults(uintptr_t gicd_base);
193void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100194unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100195 const interrupt_prop_t *interrupt_props,
196 unsigned int interrupt_props_num);
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100197unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100198 const interrupt_prop_t *interrupt_props,
199 unsigned int interrupt_props_num);
Achin Gupta92712a52015-09-03 14:18:02 +0100200void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
201 unsigned int rdistif_num,
202 uintptr_t gicr_base,
203 mpidr_hash_fn mpidr_to_core_pos);
204void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
205void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);
206
207/*******************************************************************************
208 * GIC Distributor interface accessors
209 ******************************************************************************/
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100210/*
211 * Wait for updates to :
212 * GICD_CTLR[2:0] - the Group Enables
213 * GICD_CTLR[5:4] - the ARE bits
214 * GICD_ICENABLERn - the clearing of enable state for SPIs
215 */
216static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
217{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000218 while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U) {
219 }
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100220}
221
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000222static inline uint32_t gicd_read_pidr2(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100223{
224 return mmio_read_32(base + GICD_PIDR2_GICV3);
225}
226
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000227static inline uint64_t gicd_read_irouter(uintptr_t base, unsigned int id)
Achin Gupta92712a52015-09-03 14:18:02 +0100228{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100229 assert(id >= MIN_SPI_ID);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000230 return GICD_READ_64(IROUTER, base, id);
Achin Gupta92712a52015-09-03 14:18:02 +0100231}
232
233static inline void gicd_write_irouter(uintptr_t base,
234 unsigned int id,
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000235 uint64_t affinity)
Achin Gupta92712a52015-09-03 14:18:02 +0100236{
Soby Mathewaaf71c82016-07-26 17:46:56 +0100237 assert(id >= MIN_SPI_ID);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000238 GICD_WRITE_64(IROUTER, base, id, affinity);
Achin Gupta92712a52015-09-03 14:18:02 +0100239}
240
241static inline void gicd_clr_ctlr(uintptr_t base,
242 unsigned int bitmap,
243 unsigned int rwp)
244{
245 gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000246 if (rwp != 0U) {
Achin Gupta92712a52015-09-03 14:18:02 +0100247 gicd_wait_for_pending_write(base);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000248 }
Achin Gupta92712a52015-09-03 14:18:02 +0100249}
250
251static inline void gicd_set_ctlr(uintptr_t base,
252 unsigned int bitmap,
253 unsigned int rwp)
254{
255 gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000256 if (rwp != 0U) {
Achin Gupta92712a52015-09-03 14:18:02 +0100257 gicd_wait_for_pending_write(base);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000258 }
Achin Gupta92712a52015-09-03 14:18:02 +0100259}
260
261/*******************************************************************************
262 * GIC Redistributor interface accessors
263 ******************************************************************************/
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100264static inline uint32_t gicr_read_ctlr(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100265{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100266 return mmio_read_32(base + GICR_CTLR);
Achin Gupta92712a52015-09-03 14:18:02 +0100267}
268
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100269static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100270{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100271 mmio_write_32(base + GICR_CTLR, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100272}
273
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000274static inline uint64_t gicr_read_typer(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100275{
276 return mmio_read_64(base + GICR_TYPER);
277}
278
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000279static inline uint32_t gicr_read_waker(uintptr_t base)
Achin Gupta92712a52015-09-03 14:18:02 +0100280{
281 return mmio_read_32(base + GICR_WAKER);
282}
283
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000284static inline void gicr_write_waker(uintptr_t base, uint32_t val)
Achin Gupta92712a52015-09-03 14:18:02 +0100285{
286 mmio_write_32(base + GICR_WAKER, val);
287}
288
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100289/*
290 * Wait for updates to :
291 * GICR_ICENABLER0
292 * GICR_CTLR.DPG1S
293 * GICR_CTLR.DPG1NS
294 * GICR_CTLR.DPG0
295 */
296static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
297{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000298 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U) {
299 }
Douglas Raillarda1b1da82017-07-26 13:51:00 +0100300}
301
Soby Mathew327548c2017-07-13 15:19:51 +0100302static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
303{
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000304 while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U) {
305 }
Soby Mathew327548c2017-07-13 15:19:51 +0100306}
307
308/* Private implementation of Distributor power control hooks */
309void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
310void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);
311
Soby Mathew50f6fe42016-02-01 17:59:22 +0000312/*******************************************************************************
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000313 * GIC Redistributor functions for accessing entire registers.
Soby Mathew50f6fe42016-02-01 17:59:22 +0000314 * Note: The raw register values correspond to multiple interrupt IDs and
315 * the number of interrupt IDs involved depends on the register accessed.
316 ******************************************************************************/
Achin Gupta92712a52015-09-03 14:18:02 +0100317static inline unsigned int gicr_read_icenabler0(uintptr_t base)
318{
319 return mmio_read_32(base + GICR_ICENABLER0);
320}
321
322static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
323{
324 mmio_write_32(base + GICR_ICENABLER0, val);
325}
326
327static inline unsigned int gicr_read_isenabler0(uintptr_t base)
328{
329 return mmio_read_32(base + GICR_ISENABLER0);
330}
331
Jeenu Viswambharaneb1c12c2017-09-22 08:32:09 +0100332static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
333{
334 mmio_write_32(base + GICR_ICPENDR0, val);
335}
336
Achin Gupta92712a52015-09-03 14:18:02 +0100337static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
338{
339 mmio_write_32(base + GICR_ISENABLER0, val);
340}
341
342static inline unsigned int gicr_read_igroupr0(uintptr_t base)
343{
344 return mmio_read_32(base + GICR_IGROUPR0);
345}
346
Soby Mathew327548c2017-07-13 15:19:51 +0100347static inline unsigned int gicr_read_ispendr0(uintptr_t base)
348{
349 return mmio_read_32(base + GICR_ISPENDR0);
350}
351
352static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
353{
354 mmio_write_32(base + GICR_ISPENDR0, val);
355}
356
Achin Gupta92712a52015-09-03 14:18:02 +0100357static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
358{
359 mmio_write_32(base + GICR_IGROUPR0, val);
360}
361
362static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
363{
364 return mmio_read_32(base + GICR_IGRPMODR0);
365}
366
367static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
368{
369 mmio_write_32(base + GICR_IGRPMODR0, val);
370}
371
Soby Mathew327548c2017-07-13 15:19:51 +0100372static inline unsigned int gicr_read_nsacr(uintptr_t base)
373{
374 return mmio_read_32(base + GICR_NSACR);
375}
376
377static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
378{
379 mmio_write_32(base + GICR_NSACR, val);
380}
381
382static inline unsigned int gicr_read_isactiver0(uintptr_t base)
383{
384 return mmio_read_32(base + GICR_ISACTIVER0);
385}
386
387static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
388{
389 mmio_write_32(base + GICR_ISACTIVER0, val);
390}
391
392static inline unsigned int gicr_read_icfgr0(uintptr_t base)
393{
394 return mmio_read_32(base + GICR_ICFGR0);
395}
396
Achin Gupta92712a52015-09-03 14:18:02 +0100397static inline unsigned int gicr_read_icfgr1(uintptr_t base)
398{
399 return mmio_read_32(base + GICR_ICFGR1);
400}
401
Soby Mathew327548c2017-07-13 15:19:51 +0100402static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
403{
404 mmio_write_32(base + GICR_ICFGR0, val);
405}
406
Achin Gupta92712a52015-09-03 14:18:02 +0100407static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
408{
409 mmio_write_32(base + GICR_ICFGR1, val);
410}
411
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100412static inline uint64_t gicr_read_propbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100413{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100414 return mmio_read_64(base + GICR_PROPBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100415}
416
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100417static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100418{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100419 mmio_write_64(base + GICR_PROPBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100420}
421
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100422static inline uint64_t gicr_read_pendbaser(uintptr_t base)
Soby Mathew327548c2017-07-13 15:19:51 +0100423{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100424 return mmio_read_64(base + GICR_PENDBASER);
Soby Mathew327548c2017-07-13 15:19:51 +0100425}
426
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100427static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
Soby Mathew327548c2017-07-13 15:19:51 +0100428{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100429 mmio_write_64(base + GICR_PENDBASER, val);
Soby Mathew327548c2017-07-13 15:19:51 +0100430}
431
Soby Mathewf6f1a322017-07-18 16:12:45 +0100432/*******************************************************************************
433 * GIC ITS functions to read and write entire ITS registers.
434 ******************************************************************************/
435static inline uint32_t gits_read_ctlr(uintptr_t base)
436{
437 return mmio_read_32(base + GITS_CTLR);
438}
439
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000440static inline void gits_write_ctlr(uintptr_t base, uint32_t val)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100441{
442 mmio_write_32(base + GITS_CTLR, val);
443}
444
445static inline uint64_t gits_read_cbaser(uintptr_t base)
446{
447 return mmio_read_64(base + GITS_CBASER);
448}
449
450static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
451{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100452 mmio_write_64(base + GITS_CBASER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100453}
454
455static inline uint64_t gits_read_cwriter(uintptr_t base)
456{
457 return mmio_read_64(base + GITS_CWRITER);
458}
459
460static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
461{
Antonio Nino Diazbab39e82018-08-21 10:03:07 +0100462 mmio_write_64(base + GITS_CWRITER, val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100463}
464
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000465static inline uint64_t gits_read_baser(uintptr_t base,
466 unsigned int its_table_id)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100467{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100468 assert(its_table_id < 8U);
469 return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
Soby Mathewf6f1a322017-07-18 16:12:45 +0100470}
471
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000472static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id,
473 uint64_t val)
Soby Mathewf6f1a322017-07-18 16:12:45 +0100474{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100475 assert(its_table_id < 8U);
476 mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
Soby Mathewf6f1a322017-07-18 16:12:45 +0100477}
478
479/*
480 * Wait for Quiescent bit when GIC ITS is disabled
481 */
482static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
483{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100484 assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000485 while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U) {
486 }
Soby Mathewf6f1a322017-07-18 16:12:45 +0100487}
488
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000489#endif /* GICV3_PRIVATE_H */