gicv3_helpers.c 17.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2018, 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
9
10
11
 */

#include <arch.h>
#include <arch_helpers.h>
#include <assert.h>
#include <debug.h>
#include <gic_common.h>
12
#include <interrupt_props.h>
13
#include "../common/gic_common_private.h"
14
15
16
17
18
19
20
21
#include "gicv3_private.h"

/*
 * Accessor to read the GIC Distributor IGRPMODR corresponding to the
 * interrupt `id`, 32 interrupt IDs at a time.
 */
unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
22
23
	unsigned int n = id >> IGRPMODR_SHIFT;

24
25
26
27
28
29
30
31
32
	return mmio_read_32(base + GICD_IGRPMODR + (n << 2));
}

/*
 * Accessor to write the GIC Distributor IGRPMODR corresponding to the
 * interrupt `id`, 32 interrupt IDs at a time.
 */
void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
33
34
	unsigned int n = id >> IGRPMODR_SHIFT;

35
36
37
38
39
40
41
42
43
	mmio_write_32(base + GICD_IGRPMODR + (n << 2), val);
}

/*
 * Accessor to get the bit corresponding to interrupt ID
 * in GIC Distributor IGRPMODR.
 */
unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
44
	unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U);
45
46
	unsigned int reg_val = gicd_read_igrpmodr(base, id);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
47
	return (reg_val >> bit_num) & 0x1U;
48
49
50
51
52
53
54
55
}

/*
 * Accessor to set the bit corresponding to interrupt ID
 * in GIC Distributor IGRPMODR.
 */
void gicd_set_igrpmodr(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
56
	unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U);
57
58
	unsigned int reg_val = gicd_read_igrpmodr(base, id);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
59
	gicd_write_igrpmodr(base, id, reg_val | (1U << bit_num));
60
61
62
63
64
65
66
67
}

/*
 * Accessor to clear the bit corresponding to interrupt ID
 * in GIC Distributor IGRPMODR.
 */
void gicd_clr_igrpmodr(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
68
	unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U);
69
70
	unsigned int reg_val = gicd_read_igrpmodr(base, id);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
71
	gicd_write_igrpmodr(base, id, reg_val & ~(1U << bit_num));
72
73
74
75
76
77
78
79
}

/*
 * Accessor to read the GIC Re-distributor IPRIORITYR corresponding to the
 * interrupt `id`, 4 interrupts IDs at a time.
 */
unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
80
81
	unsigned int n = id >> IPRIORITYR_SHIFT;

82
83
84
85
86
87
88
89
90
	return mmio_read_32(base + GICR_IPRIORITYR + (n << 2));
}

/*
 * Accessor to write the GIC Re-distributor IPRIORITYR corresponding to the
 * interrupt `id`, 4 interrupts IDs at a time.
 */
void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
91
92
	unsigned int n = id >> IPRIORITYR_SHIFT;

93
94
95
96
97
98
99
100
101
	mmio_write_32(base + GICR_IPRIORITYR + (n << 2), val);
}

/*
 * Accessor to get the bit corresponding to interrupt ID
 * from GIC Re-distributor IGROUPR0.
 */
unsigned int gicr_get_igroupr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
102
	unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
103
104
	unsigned int reg_val = gicr_read_igroupr0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
105
	return (reg_val >> bit_num) & 0x1U;
106
107
108
109
110
111
112
113
}

/*
 * Accessor to set the bit corresponding to interrupt ID
 * in GIC Re-distributor IGROUPR0.
 */
void gicr_set_igroupr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
114
	unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
115
116
	unsigned int reg_val = gicr_read_igroupr0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
117
	gicr_write_igroupr0(base, reg_val | (1U << bit_num));
118
119
120
121
122
123
124
125
}

/*
 * Accessor to clear the bit corresponding to interrupt ID
 * in GIC Re-distributor IGROUPR0.
 */
void gicr_clr_igroupr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
126
	unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
127
128
	unsigned int reg_val = gicr_read_igroupr0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
129
	gicr_write_igroupr0(base, reg_val & ~(1U << bit_num));
130
131
132
133
134
135
136
137
}

/*
 * Accessor to get the bit corresponding to interrupt ID
 * from GIC Re-distributor IGRPMODR0.
 */
unsigned int gicr_get_igrpmodr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
138
	unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U);
139
140
	unsigned int reg_val = gicr_read_igrpmodr0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
141
	return (reg_val >> bit_num) & 0x1U;
142
143
144
145
146
147
148
149
}

/*
 * Accessor to set the bit corresponding to interrupt ID
 * in GIC Re-distributor IGRPMODR0.
 */
void gicr_set_igrpmodr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
150
	unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U);
151
152
	unsigned int reg_val = gicr_read_igrpmodr0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
153
	gicr_write_igrpmodr0(base, reg_val | (1U << bit_num));
154
155
156
157
158
159
160
161
}

/*
 * Accessor to clear the bit corresponding to interrupt ID
 * in GIC Re-distributor IGRPMODR0.
 */
void gicr_clr_igrpmodr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
162
	unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U);
163
164
	unsigned int reg_val = gicr_read_igrpmodr0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
165
	gicr_write_igrpmodr0(base, reg_val & ~(1U << bit_num));
166
167
168
169
170
171
172
173
}

/*
 * Accessor to set the bit corresponding to interrupt ID
 * in GIC Re-distributor ISENABLER0.
 */
void gicr_set_isenabler0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
174
	unsigned int bit_num = id & ((1U << ISENABLER_SHIFT) - 1U);
175

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
176
	gicr_write_isenabler0(base, (1U << bit_num));
177
178
}

179
180
181
182
183
184
/*
 * Accessor to set the bit corresponding to interrupt ID in GIC Re-distributor
 * ICENABLER0.
 */
void gicr_set_icenabler0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
185
	unsigned int bit_num = id & ((1U << ICENABLER_SHIFT) - 1U);
186

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
187
	gicr_write_icenabler0(base, (1U << bit_num));
188
189
}

190
191
192
193
194
195
/*
 * Accessor to set the bit corresponding to interrupt ID in GIC Re-distributor
 * ISACTIVER0.
 */
unsigned int gicr_get_isactiver0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
196
	unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U);
197
198
	unsigned int reg_val = gicr_read_isactiver0(base);

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
199
	return (reg_val >> bit_num) & 0x1U;
200
201
}

202
203
204
205
206
207
/*
 * Accessor to clear the bit corresponding to interrupt ID in GIC Re-distributor
 * ICPENDRR0.
 */
void gicr_set_icpendr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
208
	unsigned int bit_num = id & ((1U << ICPENDR_SHIFT) - 1U);
209

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
210
	gicr_write_icpendr0(base, (1U << bit_num));
211
212
213
214
215
216
217
218
}

/*
 * Accessor to set the bit corresponding to interrupt ID in GIC Re-distributor
 * ISPENDR0.
 */
void gicr_set_ispendr0(uintptr_t base, unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
219
	unsigned int bit_num = id & ((1U << ISPENDR_SHIFT) - 1U);
220

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
221
	gicr_write_ispendr0(base, (1U << bit_num));
222
223
}

224
225
226
227
228
229
/*
 * Accessor to set the byte corresponding to interrupt ID
 * in GIC Re-distributor IPRIORITYR.
 */
void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
230
231
232
	uint8_t val = pri & GIC_PRI_MASK;

	mmio_write_8(base + GICR_IPRIORITYR + id, val);
233
234
}

235
236
237
238
239
240
/*
 * Accessor to set the bit fields corresponding to interrupt ID
 * in GIC Re-distributor ICFGR0.
 */
void gicr_set_icfgr0(uintptr_t base, unsigned int id, unsigned int cfg)
{
241
	/* Interrupt configuration is a 2-bit field */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
242
243
	unsigned int bit_num = id & ((1U << ICFGR_SHIFT) - 1U);
	unsigned int bit_shift = bit_num << 1U;
244

245
246
247
	uint32_t reg_val = gicr_read_icfgr0(base);

	/* Clear the field, and insert required configuration */
248
249
	reg_val &= ~(GIC_CFG_MASK << bit_shift);
	reg_val |= ((cfg & GIC_CFG_MASK) << bit_shift);
250
251
252
253
254
255
256
257
258
259

	gicr_write_icfgr0(base, reg_val);
}

/*
 * Accessor to set the bit fields corresponding to interrupt ID
 * in GIC Re-distributor ICFGR1.
 */
void gicr_set_icfgr1(uintptr_t base, unsigned int id, unsigned int cfg)
{
260
	/* Interrupt configuration is a 2-bit field */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
261
262
	unsigned int bit_num = id & ((1U << ICFGR_SHIFT) - 1U);
	unsigned int bit_shift = bit_num << 1U;
263

264
265
266
	uint32_t reg_val = gicr_read_icfgr1(base);

	/* Clear the field, and insert required configuration */
267
268
	reg_val &= ~(GIC_CFG_MASK << bit_shift);
	reg_val |= ((cfg & GIC_CFG_MASK) << bit_shift);
269
270
271
272

	gicr_write_icfgr1(base, reg_val);
}

273
274
275
276
277
278
279
280
281
282
/******************************************************************************
 * This function marks the core as awake in the re-distributor and
 * ensures that the interface is active.
 *****************************************************************************/
void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base)
{
	/*
	 * The WAKER_PS_BIT should be changed to 0
	 * only when WAKER_CA_BIT is 1.
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
283
	assert((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U);
284
285
286
287
288

	/* Mark the connected core as awake */
	gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) & ~WAKER_PS_BIT);

	/* Wait till the WAKER_CA_BIT changes to 0 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
289
	while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U)
290
291
292
293
294
295
296
297
298
299
300
301
302
303
		;
}


/******************************************************************************
 * This function marks the core as asleep in the re-distributor and ensures
 * that the interface is quiescent.
 *****************************************************************************/
void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base)
{
	/* Mark the connected core as asleep */
	gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) | WAKER_PS_BIT);

	/* Wait till the WAKER_CA_BIT changes to 1 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
304
	while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) == 0U)
305
306
307
308
309
310
311
312
313
314
315
316
317
318
		;
}


/*******************************************************************************
 * This function probes the Redistributor frames when the driver is initialised
 * and saves their base addresses. These base addresses are used later to
 * initialise each Redistributor interface.
 ******************************************************************************/
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)
{
319
	u_register_t mpidr;
320
	unsigned int proc_num;
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
321
	uint64_t typer_val;
322
323
	uintptr_t rdistif_base = gicr_base;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
324
	assert(rdistif_base_addrs != NULL);
325
326
327
328
329
330
331
332
333
334

	/*
	 * Iterate over the Redistributor frames. Store the base address of each
	 * frame in the platform provided array. Use the "Processor Number"
	 * field to index into the array if the platform has not provided a hash
	 * function to convert an MPIDR (obtained from the "Affinity Value"
	 * field into a linear index.
	 */
	do {
		typer_val = gicr_read_typer(rdistif_base);
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
335
		if (mpidr_to_core_pos != NULL) {
336
337
338
339
340
341
342
343
			mpidr = mpidr_from_gicr_typer(typer_val);
			proc_num = mpidr_to_core_pos(mpidr);
		} else {
			proc_num = (typer_val >> TYPER_PROC_NUM_SHIFT) &
				TYPER_PROC_NUM_MASK;
		}
		assert(proc_num < rdistif_num);
		rdistif_base_addrs[proc_num] = rdistif_base;
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
344
345
		rdistif_base += (1U << GICR_PCPUBASE_SHIFT);
	} while ((typer_val & TYPER_LAST_BIT) == 0U);
346
347
348
349
350
}

/*******************************************************************************
 * Helper function to configure the default attributes of SPIs.
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
351
void gicv3_spis_config_defaults(uintptr_t gicd_base)
352
353
354
355
356
{
	unsigned int index, num_ints;

	num_ints = gicd_read_typer(gicd_base);
	num_ints &= TYPER_IT_LINES_NO_MASK;
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
357
	num_ints = (num_ints + 1U) << 5;
358
359
360
361
362

	/*
	 * Treat all SPIs as G1NS by default. The number of interrupts is
	 * calculated as 32 * (IT_LINES + 1). We do 32 at a time.
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
363
	for (index = MIN_SPI_ID; index < num_ints; index += 32U)
364
365
366
		gicd_write_igroupr(gicd_base, index, ~0U);

	/* Setup the default SPI priorities doing four at a time */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
367
	for (index = MIN_SPI_ID; index < num_ints; index += 4U)
368
369
370
371
372
373
374
375
		gicd_write_ipriorityr(gicd_base,
				      index,
				      GICD_IPRIORITYR_DEF_VAL);

	/*
	 * Treat all SPIs as level triggered by default, write 16 at
	 * a time
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
376
377
	for (index = MIN_SPI_ID; index < num_ints; index += 16U)
		gicd_write_icfgr(gicd_base, index, 0U);
378
379
}

380
#if !ERROR_DEPRECATED
381
382
383
/*******************************************************************************
 * Helper function to configure secure G0 and G1S SPIs.
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
384
void gicv3_secure_spis_config(uintptr_t gicd_base,
385
386
387
388
389
				     unsigned int num_ints,
				     const unsigned int *sec_intr_list,
				     unsigned int int_grp)
{
	unsigned int index, irq_num;
390
	unsigned long long gic_affinity_val;
391

392
	assert((int_grp == INTR_GROUP1S) || (int_grp == INTR_GROUP0));
393
	/* If `num_ints` is not 0, ensure that `sec_intr_list` is not NULL */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
394
395
	if (num_ints != 0U)
		assert(sec_intr_list != NULL);
396

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
397
	for (index = 0U; index < num_ints; index++) {
398
399
400
401
402
403
404
		irq_num = sec_intr_list[index];
		if (irq_num >= MIN_SPI_ID) {

			/* Configure this interrupt as a secure interrupt */
			gicd_clr_igroupr(gicd_base, irq_num);

			/* Configure this interrupt as G0 or a G1S interrupt */
405
			if (int_grp == INTR_GROUP1S)
406
407
408
409
410
				gicd_set_igrpmodr(gicd_base, irq_num);
			else
				gicd_clr_igrpmodr(gicd_base, irq_num);

			/* Set the priority of this interrupt */
411
			gicd_set_ipriorityr(gicd_base,
412
413
414
415
416
					      irq_num,
					      GIC_HIGHEST_SEC_PRIORITY);

			/* Target SPIs to the primary CPU */
			gic_affinity_val =
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
417
				gicd_irouter_val_from_mpidr(read_mpidr(), 0U);
418
419
420
421
422
423
424
425
426
427
			gicd_write_irouter(gicd_base,
					   irq_num,
					   gic_affinity_val);

			/* Enable this interrupt */
			gicd_set_isenabler(gicd_base, irq_num);
		}
	}

}
428
429
430
431
432
#endif

/*******************************************************************************
 * Helper function to configure properties of secure SPIs
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
433
unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
434
435
436
437
438
439
		const interrupt_prop_t *interrupt_props,
		unsigned int interrupt_props_num)
{
	unsigned int i;
	const interrupt_prop_t *current_prop;
	unsigned long long gic_affinity_val;
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
440
	unsigned int ctlr_enable = 0U;
441
442

	/* Make sure there's a valid property array */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
443
444
	if (interrupt_props_num > 0U)
		assert(interrupt_props != NULL);
445

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
446
	for (i = 0U; i < interrupt_props_num; i++) {
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
		current_prop = &interrupt_props[i];

		if (current_prop->intr_num < MIN_SPI_ID)
			continue;

		/* Configure this interrupt as a secure interrupt */
		gicd_clr_igroupr(gicd_base, current_prop->intr_num);

		/* Configure this interrupt as G0 or a G1S interrupt */
		assert((current_prop->intr_grp == INTR_GROUP0) ||
				(current_prop->intr_grp == INTR_GROUP1S));
		if (current_prop->intr_grp == INTR_GROUP1S) {
			gicd_set_igrpmodr(gicd_base, current_prop->intr_num);
			ctlr_enable |= CTLR_ENABLE_G1S_BIT;
		} else {
			gicd_clr_igrpmodr(gicd_base, current_prop->intr_num);
			ctlr_enable |= CTLR_ENABLE_G0_BIT;
		}

		/* Set interrupt configuration */
		gicd_set_icfgr(gicd_base, current_prop->intr_num,
				current_prop->intr_cfg);

		/* Set the priority of this interrupt */
		gicd_set_ipriorityr(gicd_base, current_prop->intr_num,
				current_prop->intr_pri);

		/* Target SPIs to the primary CPU */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
475
476
		gic_affinity_val =
			gicd_irouter_val_from_mpidr(read_mpidr(), 0U);
477
478
479
480
481
482
483
484
485
		gicd_write_irouter(gicd_base, current_prop->intr_num,
				gic_affinity_val);

		/* Enable this interrupt */
		gicd_set_isenabler(gicd_base, current_prop->intr_num);
	}

	return ctlr_enable;
}
486
487
488
489

/*******************************************************************************
 * Helper function to configure the default attributes of SPIs.
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
490
void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base)
491
492
493
494
495
496
497
498
{
	unsigned int index;

	/*
	 * Disable all SGIs (imp. def.)/PPIs before configuring them. This is a
	 * more scalable approach as it avoids clearing the enable bits in the
	 * GICD_CTLR
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
499
	gicr_write_icenabler0(gicr_base, ~0U);
500
501
502
503
504
505
	gicr_wait_for_pending_write(gicr_base);

	/* Treat all SGIs/PPIs as G1NS by default. */
	gicr_write_igroupr0(gicr_base, ~0U);

	/* Setup the default PPI/SGI priorities doing four at a time */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
506
	for (index = 0U; index < MIN_SPI_ID; index += 4U)
507
508
509
510
511
		gicr_write_ipriorityr(gicr_base,
				      index,
				      GICD_IPRIORITYR_DEF_VAL);

	/* Configure all PPIs as level triggered by default */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
512
	gicr_write_icfgr1(gicr_base, 0U);
513
514
}

515
#if !ERROR_DEPRECATED
516
517
518
/*******************************************************************************
 * Helper function to configure secure G0 and G1S SPIs.
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
519
void gicv3_secure_ppi_sgi_config(uintptr_t gicr_base,
520
521
522
523
524
525
					unsigned int num_ints,
					const unsigned int *sec_intr_list,
					unsigned int int_grp)
{
	unsigned int index, irq_num;

526
	assert((int_grp == INTR_GROUP1S) || (int_grp == INTR_GROUP0));
527
	/* If `num_ints` is not 0, ensure that `sec_intr_list` is not NULL */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
528
529
	if (num_ints != 0U)
		assert(sec_intr_list != NULL);
530
531
532
533
534
535
536
537
538

	for (index = 0; index < num_ints; index++) {
		irq_num = sec_intr_list[index];
		if (irq_num < MIN_SPI_ID) {

			/* Configure this interrupt as a secure interrupt */
			gicr_clr_igroupr0(gicr_base, irq_num);

			/* Configure this interrupt as G0 or a G1S interrupt */
539
			if (int_grp == INTR_GROUP1S)
540
541
542
543
544
				gicr_set_igrpmodr0(gicr_base, irq_num);
			else
				gicr_clr_igrpmodr0(gicr_base, irq_num);

			/* Set the priority of this interrupt */
545
			gicr_set_ipriorityr(gicr_base,
546
547
548
549
550
551
552
553
					    irq_num,
					    GIC_HIGHEST_SEC_PRIORITY);

			/* Enable this interrupt */
			gicr_set_isenabler0(gicr_base, irq_num);
		}
	}
}
554
555
556
557
558
#endif

/*******************************************************************************
 * Helper function to configure properties of secure G0 and G1S PPIs and SGIs.
 ******************************************************************************/
Daniel Boulby's avatar
Daniel Boulby committed
559
unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
560
561
562
563
564
		const interrupt_prop_t *interrupt_props,
		unsigned int interrupt_props_num)
{
	unsigned int i;
	const interrupt_prop_t *current_prop;
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
565
	unsigned int ctlr_enable = 0U;
566
567

	/* Make sure there's a valid property array */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
568
569
	if (interrupt_props_num > 0U)
		assert(interrupt_props != NULL);
570

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
571
	for (i = 0U; i < interrupt_props_num; i++) {
572
573
574
575
576
577
578
579
580
581
582
		current_prop = &interrupt_props[i];

		if (current_prop->intr_num >= MIN_SPI_ID)
			continue;

		/* Configure this interrupt as a secure interrupt */
		gicr_clr_igroupr0(gicr_base, current_prop->intr_num);

		/* Configure this interrupt as G0 or a G1S interrupt */
		assert((current_prop->intr_grp == INTR_GROUP0) ||
				(current_prop->intr_grp == INTR_GROUP1S));
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
583
		if (current_prop->intr_grp == INTR_GROUP1S) {
584
			gicr_set_igrpmodr0(gicr_base, current_prop->intr_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
585
586
			ctlr_enable |= CTLR_ENABLE_G1S_BIT;
		} else {
587
			gicr_clr_igrpmodr0(gicr_base, current_prop->intr_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
588
589
			ctlr_enable |= CTLR_ENABLE_G0_BIT;
		}
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

		/* Set the priority of this interrupt */
		gicr_set_ipriorityr(gicr_base, current_prop->intr_num,
				current_prop->intr_pri);

		/*
		 * Set interrupt configuration for PPIs. Configuration for SGIs
		 * are ignored.
		 */
		if ((current_prop->intr_num >= MIN_PPI_ID) &&
				(current_prop->intr_num < MIN_SPI_ID)) {
			gicr_set_icfgr1(gicr_base, current_prop->intr_num,
					current_prop->intr_cfg);
		}

		/* Enable this interrupt */
		gicr_set_isenabler0(gicr_base, current_prop->intr_num);
	}
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
608
609

	return ctlr_enable;
610
}