gicv3_private.h 20.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
8
#ifndef GICV3_PRIVATE_H
#define GICV3_PRIVATE_H
9

10
#include <assert.h>
11
#include <stdint.h>
12
13
14
15
16

#include <drivers/arm/gic_common.h>
#include <drivers/arm/gicv3.h>
#include <lib/mmio.h>

17
#include "../common/gic_common_private.h"
18
19
20
21
22
23

/*******************************************************************************
 * GICv3 private macro definitions
 ******************************************************************************/

/* Constants to indicate the status of the RWP bit */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
24
25
#define RWP_TRUE		U(1)
#define RWP_FALSE		U(0)
26

27
28
/* Calculate GIC register bit number corresponding to its interrupt ID */
#define	BIT_NUM(REG, id)	\
29
	((id) & ((1U << REG##R_SHIFT) - 1U))
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Calculate 8, 32 and 64-bit GICD register offset
 * corresponding to its interrupt ID
 */
#if GIC_EXT_INTID
	/* GICv3.1 */
#define	GICD_OFFSET_8(REG, id)				\
	(((id) <= MAX_SPI_ID) ?				\
	GICD_##REG##R + (uintptr_t)(id) :		\
	GICD_##REG##RE + (uintptr_t)(id) - MIN_ESPI_ID)

#define	GICD_OFFSET(REG, id)						\
	(((id) <= MAX_SPI_ID) ?						\
	GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) :	\
	GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >>		\
					REG##R_SHIFT) << 2))

#define	GICD_OFFSET_64(REG, id)						\
	(((id) <= MAX_SPI_ID) ?						\
	GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3) :	\
51
52
	GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >>		\
					REG##R_SHIFT) << 3))
53
54

#else	/* GICv3 */
55
#define	GICD_OFFSET_8(REG, id)	\
56
	(GICD_##REG##R + (uintptr_t)(id))
57
58

#define	GICD_OFFSET(REG, id)	\
59
	(GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2))
60
61

#define	GICD_OFFSET_64(REG, id)	\
62
63
	(GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3))
#endif	/* GIC_EXT_INTID */
64

65
66
67
68
/*
 * Read/Write 8, 32 and 64-bit GIC Distributor register
 * corresponding to its interrupt ID
 */
69
70
71
72
73
74
#define GICD_READ(REG, base, id)	\
	mmio_read_32((base) + GICD_OFFSET(REG, (id)))

#define GICD_READ_64(REG, base, id)	\
	mmio_read_64((base) + GICD_OFFSET_64(REG, (id)))

75
76
#define GICD_WRITE_8(REG, base, id, val)	\
	mmio_write_8((base) + GICD_OFFSET_8(REG, (id)), (val))
77

78
#define GICD_WRITE(REG, base, id, val)	\
79
80
	mmio_write_32((base) + GICD_OFFSET(REG, (id)), (val))

81
82
#define GICD_WRITE_64(REG, base, id, val)	\
	mmio_write_64((base) + GICD_OFFSET_64(REG, (id)), (val))
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

/*
 * Bit operations on GIC Distributor register corresponding
 * to its interrupt ID
 */
/* Get bit in GIC Distributor register */
#define GICD_GET_BIT(REG, base, id)				\
	((mmio_read_32((base) + GICD_OFFSET(REG, (id))) >>	\
		BIT_NUM(REG, (id))) & 1U)

/* Set bit in GIC Distributor register */
#define GICD_SET_BIT(REG, base, id)				\
	mmio_setbits_32((base) + GICD_OFFSET(REG, (id)),	\
		((uint32_t)1 << BIT_NUM(REG, (id))))

/* Clear bit in GIC Distributor register */
#define GICD_CLR_BIT(REG, base, id)				\
	mmio_clrbits_32((base) + GICD_OFFSET(REG, (id)),	\
		((uint32_t)1 << BIT_NUM(REG, (id))))

/* Write bit in GIC Distributor register */
104
#define	GICD_WRITE_BIT(REG, base, id)			\
105
106
107
108
	mmio_write_32((base) + GICD_OFFSET(REG, (id)),	\
		((uint32_t)1 << BIT_NUM(REG, (id))))

/*
109
110
 * Calculate 8 and 32-bit GICR register offset
 * corresponding to its interrupt ID
111
 */
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#if GIC_EXT_INTID
	/* GICv3.1 */
#define	GICR_OFFSET_8(REG, id)				\
	(((id) <= MAX_PPI_ID) ?				\
	GICR_##REG##R + (uintptr_t)(id) :		\
	GICR_##REG##R + (uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))

#define GICR_OFFSET(REG, id)						\
	(((id) <= MAX_PPI_ID) ?						\
	GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) :	\
	GICR_##REG##R + ((((uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))\
						>> REG##R_SHIFT) << 2))
#else	/* GICv3 */
#define	GICR_OFFSET_8(REG, id)	\
	(GICR_##REG##R + (uintptr_t)(id))

128
#define GICR_OFFSET(REG, id)	\
129
	(GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2))
130
#endif /* GIC_EXT_INTID */
131

132
133
134
135
136
137
138
139
/* Read/Write GIC Redistributor register corresponding to its interrupt ID */
#define GICR_READ(REG, base, id)			\
	mmio_read_32((base) + GICR_OFFSET(REG, (id)))

#define GICR_WRITE_8(REG, base, id, val)		\
	mmio_write_8((base) + GICR_OFFSET_8(REG, (id)), (val))

#define GICR_WRITE(REG, base, id, val)			\
140
	mmio_write_32((base) + GICR_OFFSET(REG, (id)), (val))
141
142
143
144
145
146
147
148
149
150
151
152

/*
 * Bit operations on GIC Redistributor register
 * corresponding to its interrupt ID
 */
/* Get bit in GIC Redistributor register */
#define GICR_GET_BIT(REG, base, id)				\
	((mmio_read_32((base) + GICR_OFFSET(REG, (id))) >>	\
		BIT_NUM(REG, (id))) & 1U)

/* Write bit in GIC Redistributor register */
#define	GICR_WRITE_BIT(REG, base, id)				\
153
	mmio_write_32((base) + GICR_OFFSET(REG, (id)),		\
154
155
156
157
158
159
160
161
162
163
164
165
		((uint32_t)1 << BIT_NUM(REG, (id))))

/* Set bit in GIC Redistributor register */
#define	GICR_SET_BIT(REG, base, id)				\
	mmio_setbits_32((base) + GICR_OFFSET(REG, (id)),	\
		((uint32_t)1 << BIT_NUM(REG, (id))))

/* Clear bit in GIC Redistributor register */
#define	GICR_CLR_BIT(REG, base, id)				\
	mmio_clrbits_32((base) + GICR_OFFSET(REG, (id)),	\
		((uint32_t)1 << BIT_NUM(REG, (id))))

166
167
168
169
170
/*
 * Macro to convert an mpidr to a value suitable for programming into a
 * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
 * to GICv3.
 */
171
172
173
174
175
176
static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr,
						       unsigned int irm)
{
	return (mpidr & ~(U(0xff) << 24)) |
		((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT);
}
177
178
179
180
181

/*
 * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
 * are zeroes.
 */
182
#ifdef __aarch64__
183
184
static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
{
185
186
	return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) |
		((typer_val >> 32) & U(0xffffff));
187
}
188
#else
189
190
static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
{
191
	return (((typer_val) >> 32) & U(0xffffff));
192
}
193
#endif
194

195
196
197
198
199
/*******************************************************************************
 * GICv3 private global variables declarations
 ******************************************************************************/
extern const gicv3_driver_data_t *gicv3_driver_data;

200
/*******************************************************************************
201
202
203
 * Private GICv3 function prototypes for accessing entire registers.
 * Note: The raw register values correspond to multiple interrupt IDs and
 * the number of interrupt IDs involved depends on the register accessed.
204
 ******************************************************************************/
205
unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id);
206
unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
207
void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val);
208
void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);
209
210
211
212
213
214
215

/*******************************************************************************
 * Private GICv3 function prototypes for accessing the GIC registers
 * corresponding to a single interrupt ID. These functions use bitwise
 * operations or appropriate register accesses to modify or return
 * the bit-field corresponding the single interrupt ID.
 ******************************************************************************/
216
unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
217
218
219
unsigned int gicr_get_igrpmodr(uintptr_t base, unsigned int id);
unsigned int gicr_get_igroupr(uintptr_t base, unsigned int id);
unsigned int gicr_get_isactiver(uintptr_t base, unsigned int id);
220
void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
221
222
223
224
225
226
void gicr_set_igrpmodr(uintptr_t base, unsigned int id);
void gicr_set_isenabler(uintptr_t base, unsigned int id);
void gicr_set_icenabler(uintptr_t base, unsigned int id);
void gicr_set_ispendr(uintptr_t base, unsigned int id);
void gicr_set_icpendr(uintptr_t base, unsigned int id);
void gicr_set_igroupr(uintptr_t base, unsigned int id);
227
void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
228
229
void gicr_clr_igrpmodr(uintptr_t base, unsigned int id);
void gicr_clr_igroupr(uintptr_t base, unsigned int id);
230
void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
231
void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg);
232
233
234
235

/*******************************************************************************
 * Private GICv3 helper function prototypes
 ******************************************************************************/
236
unsigned int gicv3_get_spi_limit(uintptr_t gicd_base);
Daniel Boulby's avatar
Daniel Boulby committed
237
238
239
void gicv3_spis_config_defaults(uintptr_t gicd_base);
void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
240
241
		const interrupt_prop_t *interrupt_props,
		unsigned int interrupt_props_num);
Daniel Boulby's avatar
Daniel Boulby committed
242
unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
243
244
		const interrupt_prop_t *interrupt_props,
		unsigned int interrupt_props_num);
245
246
247
248
249
250
251
252
253
254
void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
					unsigned int rdistif_num,
					uintptr_t gicr_base,
					mpidr_hash_fn mpidr_to_core_pos);
void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);

/*******************************************************************************
 * GIC Distributor interface accessors
 ******************************************************************************/
255
/*
256
 * Wait for updates to:
257
 * GICD_CTLR[2:0] - the Group Enables
258
259
 * GICD_CTLR[7:4] - the ARE bits, E1NWF bit and DS bit
 * GICD_ICENABLER<n> - the clearing of enable state for SPIs
260
261
262
 */
static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
{
263
264
	while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U) {
	}
265
266
}

267
static inline uint32_t gicd_read_pidr2(uintptr_t base)
268
269
270
271
{
	return mmio_read_32(base + GICD_PIDR2_GICV3);
}

272
static inline uint64_t gicd_read_irouter(uintptr_t base, unsigned int id)
273
{
274
	assert(id >= MIN_SPI_ID);
275
	return GICD_READ_64(IROUTE, base, id);
276
277
278
279
}

static inline void gicd_write_irouter(uintptr_t base,
				      unsigned int id,
280
				      uint64_t affinity)
281
{
282
	assert(id >= MIN_SPI_ID);
283
	GICD_WRITE_64(IROUTE, base, id, affinity);
284
285
286
287
288
289
290
}

static inline void gicd_clr_ctlr(uintptr_t base,
				 unsigned int bitmap,
				 unsigned int rwp)
{
	gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
291
	if (rwp != 0U) {
292
		gicd_wait_for_pending_write(base);
293
	}
294
295
296
297
298
299
300
}

static inline void gicd_set_ctlr(uintptr_t base,
				 unsigned int bitmap,
				 unsigned int rwp)
{
	gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
301
	if (rwp != 0U) {
302
		gicd_wait_for_pending_write(base);
303
	}
304
305
306
307
308
}

/*******************************************************************************
 * GIC Redistributor interface accessors
 ******************************************************************************/
309
static inline uint32_t gicr_read_ctlr(uintptr_t base)
310
{
311
	return mmio_read_32(base + GICR_CTLR);
312
313
}

314
static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
315
{
316
	mmio_write_32(base + GICR_CTLR, val);
317
318
}

319
static inline uint64_t gicr_read_typer(uintptr_t base)
320
321
322
323
{
	return mmio_read_64(base + GICR_TYPER);
}

324
static inline uint32_t gicr_read_waker(uintptr_t base)
325
326
327
328
{
	return mmio_read_32(base + GICR_WAKER);
}

329
static inline void gicr_write_waker(uintptr_t base, uint32_t val)
330
331
332
333
{
	mmio_write_32(base + GICR_WAKER, val);
}

334
/*
335
 * Wait for updates to:
336
337
338
339
 * GICR_ICENABLER0
 * GICR_CTLR.DPG1S
 * GICR_CTLR.DPG1NS
 * GICR_CTLR.DPG0
340
 * GICR_CTLR, which clears EnableLPIs from 1 to 0
341
342
343
 */
static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
{
344
345
	while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U) {
	}
346
347
}

348
349
static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
{
350
351
	while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U) {
	}
352
353
354
355
356
357
}

/* Private implementation of Distributor power control hooks */
void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);

358
/*******************************************************************************
359
 * GIC Redistributor functions for accessing entire registers.
360
361
362
 * Note: The raw register values correspond to multiple interrupt IDs and
 * the number of interrupt IDs involved depends on the register accessed.
 ******************************************************************************/
363

364
365
366
367
368
369
370
371
372
373
374
375
376
/*
 * Accessors to read/write GIC Redistributor ICENABLER0 register
 */
static inline unsigned int gicr_read_icenabler0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ICENABLER0);
}

static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICENABLER0, val);
}

377
378
379
380
381
382
/*
 * Accessors to read/write GIC Redistributor ICENABLER0 and ICENABLERE
 * register corresponding to its number
 */
static inline unsigned int gicr_read_icenabler(uintptr_t base,
						unsigned int reg_num)
383
{
384
	return mmio_read_32(base + GICR_ICENABLER + (reg_num << 2));
385
386
}

387
388
static inline void gicr_write_icenabler(uintptr_t base, unsigned int reg_num,
					unsigned int val)
389
{
390
	mmio_write_32(base + GICR_ICENABLER + (reg_num << 2), val);
391
392
}

393
/*
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
 * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 registers
 */
static inline unsigned int gicr_read_icfgr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ICFGR0);
}

static inline unsigned int gicr_read_icfgr1(uintptr_t base)
{
	return mmio_read_32(base + GICR_ICFGR1);
}

static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICFGR0, val);
}

static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICFGR1, val);
}

/*
 * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 and ICFGRE
418
419
420
 * register corresponding to its number
 */
static inline unsigned int gicr_read_icfgr(uintptr_t base, unsigned int reg_num)
421
{
422
	return mmio_read_32(base + GICR_ICFGR + (reg_num << 2));
423
424
}

425
426
static inline void gicr_write_icfgr(uintptr_t base, unsigned int reg_num,
					unsigned int val)
427
{
428
	mmio_write_32(base + GICR_ICFGR + (reg_num << 2), val);
429
430
}

431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/*
 * Accessor to write GIC Redistributor ICPENDR0 register
 */
static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ICPENDR0, val);
}

/*
 * Accessor to write GIC Redistributor ICPENDR0 and ICPENDRE
 * register corresponding to its number
 */
static inline void gicr_write_icpendr(uintptr_t base, unsigned int reg_num,
					unsigned int val)
{
	mmio_write_32(base + GICR_ICPENDR + (reg_num << 2), val);
}

/*
 * Accessors to read/write GIC Redistributor IGROUPR0 register
 */
static inline unsigned int gicr_read_igroupr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_IGROUPR0);
}

static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_IGROUPR0, val);
}

462
463
464
465
466
467
/*
 * Accessors to read/write GIC Redistributor IGROUPR0 and IGROUPRE
 * register corresponding to its number
 */
static inline unsigned int gicr_read_igroupr(uintptr_t base,
						unsigned int reg_num)
468
{
469
	return mmio_read_32(base + GICR_IGROUPR + (reg_num << 2));
470
471
}

472
473
static inline void gicr_write_igroupr(uintptr_t base, unsigned int reg_num,
						unsigned int val)
474
{
475
	mmio_write_32(base + GICR_IGROUPR + (reg_num << 2), val);
476
477
}

478
479
480
481
482
483
484
485
486
487
488
489
490
/*
 * Accessors to read/write GIC Redistributor IGRPMODR0 register
 */
static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_IGRPMODR0);
}

static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_IGRPMODR0, val);
}

491
492
493
494
495
496
/*
 * Accessors to read/write GIC Redistributor IGRPMODR0 and IGRPMODRE
 * register corresponding to its number
 */
static inline unsigned int gicr_read_igrpmodr(uintptr_t base,
						unsigned int reg_num)
497
{
498
	return mmio_read_32(base + GICR_IGRPMODR + (reg_num << 2));
499
500
}

501
502
static inline void gicr_write_igrpmodr(uintptr_t base, unsigned int reg_num,
				       unsigned int val)
503
{
504
	mmio_write_32(base + GICR_IGRPMODR + (reg_num << 2), val);
505
506
}

507
508
509
510
/*
 * Accessors to read/write the GIC Redistributor IPRIORITYR(E) register
 * corresponding to its number, 4 interrupts IDs at a time.
 */
511
static inline unsigned int gicr_ipriorityr_read(uintptr_t base,
512
						unsigned int reg_num)
513
{
514
	return mmio_read_32(base + GICR_IPRIORITYR + (reg_num << 2));
515
516
}

517
static inline void gicr_ipriorityr_write(uintptr_t base, unsigned int reg_num,
518
						unsigned int val)
519
{
520
	mmio_write_32(base + GICR_IPRIORITYR + (reg_num << 2), val);
521
522
}

523
524
525
526
527
528
529
530
531
532
533
534
535
/*
 * Accessors to read/write GIC Redistributor ISACTIVER0 register
 */
static inline unsigned int gicr_read_isactiver0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ISACTIVER0);
}

static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ISACTIVER0, val);
}

536
537
538
539
540
541
/*
 * Accessors to read/write GIC Redistributor ISACTIVER0 and ISACTIVERE
 * register corresponding to its number
 */
static inline unsigned int gicr_read_isactiver(uintptr_t base,
						unsigned int reg_num)
542
{
543
	return mmio_read_32(base + GICR_ISACTIVER + (reg_num << 2));
544
545
}

546
547
static inline void gicr_write_isactiver(uintptr_t base, unsigned int reg_num,
					unsigned int val)
548
{
549
	mmio_write_32(base + GICR_ISACTIVER + (reg_num << 2), val);
550
551
}

552
553
554
555
556
557
558
559
560
561
562
563
564
/*
 * Accessors to read/write GIC Redistributor ISENABLER0 register
 */
static inline unsigned int gicr_read_isenabler0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ISENABLER0);
}

static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ISENABLER0, val);
}

565
566
567
568
569
570
/*
 * Accessors to read/write GIC Redistributor ISENABLER0 and ISENABLERE
 * register corresponding to its number
 */
static inline unsigned int gicr_read_isenabler(uintptr_t base,
						unsigned int reg_num)
571
{
572
	return mmio_read_32(base + GICR_ISENABLER + (reg_num << 2));
573
574
}

575
576
static inline void gicr_write_isenabler(uintptr_t base, unsigned int reg_num,
					unsigned int val)
577
{
578
	mmio_write_32(base + GICR_ISENABLER + (reg_num << 2), val);
579
580
}

581
582
583
584
585
586
587
588
589
590
591
592
593
/*
 * Accessors to read/write GIC Redistributor ISPENDR0 register
 */
static inline unsigned int gicr_read_ispendr0(uintptr_t base)
{
	return mmio_read_32(base + GICR_ISPENDR0);
}

static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
{
	mmio_write_32(base + GICR_ISPENDR0, val);
}

594
595
596
597
598
599
/*
 * Accessors to read/write GIC Redistributor ISPENDR0 and ISPENDRE
 * register corresponding to its number
 */
static inline unsigned int gicr_read_ispendr(uintptr_t base,
						unsigned int reg_num)
600
{
601
	return mmio_read_32(base + GICR_ISPENDR + (reg_num << 2));
602
603
}

604
605
static inline void gicr_write_ispendr(uintptr_t base, unsigned int reg_num,
						unsigned int val)
606
{
607
	mmio_write_32(base + GICR_ISPENDR + (reg_num << 2), val);
608
609
}

610
611
612
613
/*
 * Accessors to read/write GIC Redistributor NSACR register
 */
static inline unsigned int gicr_read_nsacr(uintptr_t base)
614
{
615
	return mmio_read_32(base + GICR_NSACR);
616
617
}

618
static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
619
{
620
	mmio_write_32(base + GICR_NSACR, val);
621
622
}

623
624
625
/*
 * Accessors to read/write GIC Redistributor PROPBASER register
 */
626
static inline uint64_t gicr_read_propbaser(uintptr_t base)
627
{
628
	return mmio_read_64(base + GICR_PROPBASER);
629
630
}

631
static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
632
{
633
	mmio_write_64(base + GICR_PROPBASER, val);
634
635
}

636
637
638
/*
 * Accessors to read/write GIC Redistributor PENDBASER register
 */
639
static inline uint64_t gicr_read_pendbaser(uintptr_t base)
640
{
641
	return mmio_read_64(base + GICR_PENDBASER);
642
643
}

644
static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
645
{
646
	mmio_write_64(base + GICR_PENDBASER, val);
647
648
}

649
650
651
652
653
654
655
656
/*******************************************************************************
 * GIC ITS functions to read and write entire ITS registers.
 ******************************************************************************/
static inline uint32_t gits_read_ctlr(uintptr_t base)
{
	return mmio_read_32(base + GITS_CTLR);
}

657
static inline void gits_write_ctlr(uintptr_t base, uint32_t val)
658
659
660
661
662
663
664
665
666
667
668
{
	mmio_write_32(base + GITS_CTLR, val);
}

static inline uint64_t gits_read_cbaser(uintptr_t base)
{
	return mmio_read_64(base + GITS_CBASER);
}

static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
{
669
	mmio_write_64(base + GITS_CBASER, val);
670
671
672
673
674
675
676
677
678
}

static inline uint64_t gits_read_cwriter(uintptr_t base)
{
	return mmio_read_64(base + GITS_CWRITER);
}

static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
{
679
	mmio_write_64(base + GITS_CWRITER, val);
680
681
}

682
683
static inline uint64_t gits_read_baser(uintptr_t base,
					unsigned int its_table_id)
684
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
685
686
	assert(its_table_id < 8U);
	return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
687
688
}

689
690
static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id,
					uint64_t val)
691
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
692
693
	assert(its_table_id < 8U);
	mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
694
695
696
697
698
699
700
}

/*
 * Wait for Quiescent bit when GIC ITS is disabled
 */
static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
701
	assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
702
703
	while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U) {
	}
704
705
}

706
#endif /* GICV3_PRIVATE_H */