gicv2_main.c 20.5 KB
Newer Older
Soby Mathew's avatar
Soby Mathew committed
1
/*
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Soby Mathew's avatar
Soby Mathew committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew's avatar
Soby Mathew committed
5
6
7
8
9
10
11
12
 */

#include <arch.h>
#include <arch_helpers.h>
#include <assert.h>
#include <debug.h>
#include <gic_common.h>
#include <gicv2.h>
13
#include <interrupt_props.h>
14
#include <spinlock.h>
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
15
16
#include <stdbool.h>

17
#include "../common/gic_common_private.h"
Soby Mathew's avatar
Soby Mathew committed
18
19
20
21
#include "gicv2_private.h"

static const gicv2_driver_data_t *driver_data;

22
23
24
25
26
/*
 * Spinlock to guard registers needing read-modify-write. APIs protected by this
 * spinlock are used either at boot time (when only a single CPU is active), or
 * when the system is fully coherent.
 */
27
static spinlock_t gic_lock;
28

Soby Mathew's avatar
Soby Mathew committed
29
30
31
32
33
34
35
36
/*******************************************************************************
 * Enable secure interrupts and use FIQs to route them. Disable legacy bypass
 * and set the priority mask register to allow all interrupts to trickle in.
 ******************************************************************************/
void gicv2_cpuif_enable(void)
{
	unsigned int val;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
37
38
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

	/*
	 * Enable the Group 0 interrupts, FIQEn and disable Group 0/1
	 * bypass.
	 */
	val = CTLR_ENABLE_G0_BIT | FIQ_EN_BIT | FIQ_BYP_DIS_GRP0;
	val |= IRQ_BYP_DIS_GRP0 | FIQ_BYP_DIS_GRP1 | IRQ_BYP_DIS_GRP1;

	/* Program the idle priority in the PMR */
	gicc_write_pmr(driver_data->gicc_base, GIC_PRI_MASK);
	gicc_write_ctlr(driver_data->gicc_base, val);
}

/*******************************************************************************
 * Place the cpu interface in a state where it can never make a cpu exit wfi as
 * as result of an asserted interrupt. This is critical for powering down a cpu
 ******************************************************************************/
void gicv2_cpuif_disable(void)
{
	unsigned int val;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
60
61
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

	/* Disable secure, non-secure interrupts and disable their bypass */
	val = gicc_read_ctlr(driver_data->gicc_base);
	val &= ~(CTLR_ENABLE_G0_BIT | CTLR_ENABLE_G1_BIT);
	val |= FIQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP0;
	val |= IRQ_BYP_DIS_GRP0 | IRQ_BYP_DIS_GRP1;
	gicc_write_ctlr(driver_data->gicc_base, val);
}

/*******************************************************************************
 * Per cpu gic distributor setup which will be done by all cpus after a cold
 * boot/hotplug. This marks out the secure SPIs and PPIs & enables them.
 ******************************************************************************/
void gicv2_pcpu_distif_init(void)
{
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
77
78
	unsigned int ctlr;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
79
80
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
81

82
83
84
85
86
87
88
89
#if !ERROR_DEPRECATED
	if (driver_data->interrupt_props != NULL) {
#endif
		gicv2_secure_ppi_sgi_setup_props(driver_data->gicd_base,
				driver_data->interrupt_props,
				driver_data->interrupt_props_num);
#if !ERROR_DEPRECATED
	} else {
90
91
92
93
94
95
		/*
		 * Suppress deprecated declaration warnings in compatibility
		 * function
		 */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
96
97
98
99
		assert(driver_data->g0_interrupt_array);
		gicv2_secure_ppi_sgi_setup(driver_data->gicd_base,
				driver_data->g0_interrupt_num,
				driver_data->g0_interrupt_array);
100
#pragma GCC diagnostic pop
101
102
	}
#endif
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
103
104
105

	/* Enable G0 interrupts if not already */
	ctlr = gicd_read_ctlr(driver_data->gicd_base);
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
106
	if ((ctlr & CTLR_ENABLE_G0_BIT) == 0U) {
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
107
108
109
		gicd_write_ctlr(driver_data->gicd_base,
				ctlr | CTLR_ENABLE_G0_BIT);
	}
Soby Mathew's avatar
Soby Mathew committed
110
111
112
113
114
115
116
117
118
119
120
}

/*******************************************************************************
 * Global gic distributor init which will be done by the primary cpu after a
 * cold boot. It marks out the secure SPIs, PPIs & SGIs and enables them. It
 * then enables the secure GIC distributor interface.
 ******************************************************************************/
void gicv2_distif_init(void)
{
	unsigned int ctlr;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
121
122
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
123
124
125
126
127
128
129
130
131

	/* Disable the distributor before going further */
	ctlr = gicd_read_ctlr(driver_data->gicd_base);
	gicd_write_ctlr(driver_data->gicd_base,
			ctlr & ~(CTLR_ENABLE_G0_BIT | CTLR_ENABLE_G1_BIT));

	/* Set the default attribute of all SPIs */
	gicv2_spis_configure_defaults(driver_data->gicd_base);

132
133
134
135
136
137
138
139
#if !ERROR_DEPRECATED
	if (driver_data->interrupt_props != NULL) {
#endif
		gicv2_secure_spis_configure_props(driver_data->gicd_base,
				driver_data->interrupt_props,
				driver_data->interrupt_props_num);
#if !ERROR_DEPRECATED
	} else {
140
141
142
143
144
145
146
		/*
		 * Suppress deprecated declaration warnings in compatibility
		 * function
		 */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

147
148
149
150
151
152
		assert(driver_data->g0_interrupt_array);

		/* Configure the G0 SPIs */
		gicv2_secure_spis_configure(driver_data->gicd_base,
				driver_data->g0_interrupt_num,
				driver_data->g0_interrupt_array);
153
#pragma GCC diagnostic pop
154
155
	}
#endif
Soby Mathew's avatar
Soby Mathew committed
156
157
158
159
160
161
162
163
164
165
166

	/* Re-enable the secure SPIs now that they have been configured */
	gicd_write_ctlr(driver_data->gicd_base, ctlr | CTLR_ENABLE_G0_BIT);
}

/*******************************************************************************
 * Initialize the ARM GICv2 driver with the provided platform inputs
 ******************************************************************************/
void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data)
{
	unsigned int gic_version;
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
167
168
169
170

	assert(plat_driver_data != NULL);
	assert(plat_driver_data->gicd_base != 0U);
	assert(plat_driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
171

172
173
174
175
176
#if !ERROR_DEPRECATED
	if (plat_driver_data->interrupt_props == NULL) {
		/* Interrupt properties array size must be 0 */
		assert(plat_driver_data->interrupt_props_num == 0);

177
178
179
180
181
182
183
		/*
		 * Suppress deprecated declaration warnings in compatibility
		 * function
		 */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

184
185
186
187
188
189
190
		/*
		 * If there are no interrupts of a particular type, then the
		 * number of interrupts of that type should be 0 and vice-versa.
		 */
		assert(plat_driver_data->g0_interrupt_array ?
				plat_driver_data->g0_interrupt_num :
				plat_driver_data->g0_interrupt_num == 0);
191
192
193
194
195
#pragma GCC diagnostic pop

		WARN("Using deprecated integer interrupt array in "
		     "gicv2_driver_data_t\n");
		WARN("Please migrate to using an interrupt_prop_t array\n");
196
197
	}
#else
198
199
	assert(plat_driver_data->interrupt_props_num > 0 ?
			plat_driver_data->interrupt_props != NULL : 1);
200
#endif
Soby Mathew's avatar
Soby Mathew committed
201
202
203
204
205

	/* Ensure that this is a GICv2 system */
	gic_version = gicd_read_pidr2(plat_driver_data->gicd_base);
	gic_version = (gic_version >> PIDR2_ARCH_REV_SHIFT)
					& PIDR2_ARCH_REV_MASK;
206
207
208
209
210
211
212
213
214
215
216
217

	/*
	 * GICv1 with security extension complies with trusted firmware
	 * GICv2 driver as far as virtualization and few tricky power
	 * features are not used. GICv2 features that are not supported
	 * by GICv1 with Security Extensions are:
	 * - virtual interrupt support.
	 * - wake up events.
	 * - writeable GIC state register (for power sequences)
	 * - interrupt priority drop.
	 * - interrupt signal bypass.
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
218
219
	assert((gic_version == ARCH_REV_GICV2) ||
	       (gic_version == ARCH_REV_GICV1));
Soby Mathew's avatar
Soby Mathew committed
220
221
222

	driver_data = plat_driver_data;

223
224
225
226
227
	/*
	 * The GIC driver data is initialized by the primary CPU with caches
	 * enabled. When the secondary CPU boots up, it initializes the
	 * GICC/GICR interface with the caches disabled. Hence flush the
	 * driver_data to ensure coherency. This is not required if the
228
229
	 * platform has HW_ASSISTED_COHERENCY or WARMBOOT_ENABLE_DCACHE_EARLY
	 * enabled.
230
	 */
231
#if !(HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY)
232
233
234
	flush_dcache_range((uintptr_t) &driver_data, sizeof(driver_data));
	flush_dcache_range((uintptr_t) driver_data, sizeof(*driver_data));
#endif
Soby Mathew's avatar
Soby Mathew committed
235
236
237
238
239
240
241
242
243
244
	INFO("ARM GICv2 driver initialized\n");
}

/******************************************************************************
 * This function returns whether FIQ is enabled in the GIC CPU interface.
 *****************************************************************************/
unsigned int gicv2_is_fiq_enabled(void)
{
	unsigned int gicc_ctlr;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
245
246
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
247
248

	gicc_ctlr = gicc_read_ctlr(driver_data->gicc_base);
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
249
	return (gicc_ctlr >> FIQ_EN_SHIFT) & 0x1U;
Soby Mathew's avatar
Soby Mathew committed
250
251
252
253
254
255
256
257
258
259
260
261
}

/*******************************************************************************
 * This function returns the type of the highest priority pending interrupt at
 * the GIC cpu interface. The return values can be one of the following :
 *   PENDING_G1_INTID   : The interrupt type is non secure Group 1.
 *   0 - 1019           : The interrupt type is secure Group 0.
 *   GIC_SPURIOUS_INTERRUPT : there is no pending interrupt with
 *                            sufficient priority to be signaled
 ******************************************************************************/
unsigned int gicv2_get_pending_interrupt_type(void)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
262
263
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
264
265
266
267
268
269
270
271
272
273
274
275
276

	return gicc_read_hppir(driver_data->gicc_base) & INT_ID_MASK;
}

/*******************************************************************************
 * This function returns the id of the highest priority pending interrupt at
 * the GIC cpu interface. GIC_SPURIOUS_INTERRUPT is returned when there is no
 * interrupt pending.
 ******************************************************************************/
unsigned int gicv2_get_pending_interrupt_id(void)
{
	unsigned int id;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
277
278
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

	id = gicc_read_hppir(driver_data->gicc_base) & INT_ID_MASK;

	/*
	 * Find out which non-secure interrupt it is under the assumption that
	 * the GICC_CTLR.AckCtl bit is 0.
	 */
	if (id == PENDING_G1_INTID)
		id = gicc_read_ahppir(driver_data->gicc_base) & INT_ID_MASK;

	return id;
}

/*******************************************************************************
 * This functions reads the GIC cpu interface Interrupt Acknowledge register
 * to start handling the pending secure 0 interrupt. It returns the
 * contents of the IAR.
 ******************************************************************************/
unsigned int gicv2_acknowledge_interrupt(void)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
299
300
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
301
302
303
304
305
306
307
308
309
310

	return gicc_read_IAR(driver_data->gicc_base);
}

/*******************************************************************************
 * This functions writes the GIC cpu interface End Of Interrupt register with
 * the passed value to finish handling the active secure group 0 interrupt.
 ******************************************************************************/
void gicv2_end_of_interrupt(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
311
312
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
313
314
315
316
317
318
319
320
321
322
323
324

	gicc_write_EOIR(driver_data->gicc_base, id);
}

/*******************************************************************************
 * This function returns the type of the interrupt id depending upon the group
 * this interrupt has been configured under by the interrupt controller i.e.
 * group0 secure or group1 non secure. It returns zero for Group 0 secure and
 * one for Group 1 non secure interrupt.
 ******************************************************************************/
unsigned int gicv2_get_interrupt_group(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
325
326
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
Soby Mathew's avatar
Soby Mathew committed
327
328
329

	return gicd_get_igroupr(driver_data->gicd_base, id);
}
330
331
332
333
334
335
336

/*******************************************************************************
 * This function returns the priority of the interrupt the processor is
 * currently servicing.
 ******************************************************************************/
unsigned int gicv2_get_running_priority(void)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
337
338
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
339
340
341

	return gicc_read_rpr(driver_data->gicc_base);
}
342
343
344
345
346
347
348
349
350

/*******************************************************************************
 * This function sets the GICv2 target mask pattern for the current PE. The PE
 * target mask is used to translate linear PE index (returned by platform core
 * position) to a bit mask used when targeting interrupts to a PE, viz. when
 * raising SGIs and routing SPIs.
 ******************************************************************************/
void gicv2_set_pe_target_mask(unsigned int proc_num)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
351
352
353
354
355
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
	assert(driver_data->target_masks != NULL);
	assert((unsigned int)proc_num < GICV2_MAX_TARGET_PE);
	assert((unsigned int)proc_num < driver_data->target_masks_num);
356
357

	/* Return if the target mask is already populated */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
358
	if (driver_data->target_masks[proc_num] != 0U)
359
360
		return;

361
362
363
364
	/*
	 * Update target register corresponding to this CPU and flush for it to
	 * be visible to other CPUs.
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
365
	if (driver_data->target_masks[proc_num] == 0U) {
366
367
		driver_data->target_masks[proc_num] =
			gicv2_get_cpuif_id(driver_data->gicd_base);
368
#if !(HW_ASSISTED_COHERENCY || WARMBOOT_ENABLE_DCACHE_EARLY)
369
370
371
372
373
374
375
376
377
378
379
380
		/*
		 * PEs only update their own masks. Primary updates it with
		 * caches on. But because secondaries does it with caches off,
		 * all updates go to memory directly, and there's no danger of
		 * secondaries overwriting each others' mask, despite
		 * target_masks[] not being cache line aligned.
		 */
		flush_dcache_range((uintptr_t)
				&driver_data->target_masks[proc_num],
				sizeof(driver_data->target_masks[proc_num]));
#endif
	}
381
}
382
383
384
385
386
387
388

/*******************************************************************************
 * This function returns the active status of the interrupt (either because the
 * state is active, or active and pending).
 ******************************************************************************/
unsigned int gicv2_get_interrupt_active(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
389
390
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
391
392
393
394
	assert(id <= MAX_SPI_ID);

	return gicd_get_isactiver(driver_data->gicd_base, id);
}
395
396
397
398
399
400

/*******************************************************************************
 * This function enables the interrupt identified by id.
 ******************************************************************************/
void gicv2_enable_interrupt(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
401
402
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
	assert(id <= MAX_SPI_ID);

	/*
	 * Ensure that any shared variable updates depending on out of band
	 * interrupt trigger are observed before enabling interrupt.
	 */
	dsbishst();
	gicd_set_isenabler(driver_data->gicd_base, id);
}

/*******************************************************************************
 * This function disables the interrupt identified by id.
 ******************************************************************************/
void gicv2_disable_interrupt(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
418
419
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
420
421
422
423
424
425
426
427
428
	assert(id <= MAX_SPI_ID);

	/*
	 * Disable interrupt, and ensure that any shared variable updates
	 * depending on out of band interrupt trigger are observed afterwards.
	 */
	gicd_set_icenabler(driver_data->gicd_base, id);
	dsbishst();
}
429
430
431
432
433
434
435

/*******************************************************************************
 * This function sets the interrupt priority as supplied for the given interrupt
 * id.
 ******************************************************************************/
void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
436
437
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
438
439
440
441
	assert(id <= MAX_SPI_ID);

	gicd_set_ipriorityr(driver_data->gicd_base, id, priority);
}
442
443
444
445
446
447
448

/*******************************************************************************
 * This function assigns group for the interrupt identified by id. The group can
 * be any of GICV2_INTR_GROUP*
 ******************************************************************************/
void gicv2_set_interrupt_type(unsigned int id, unsigned int type)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
449
450
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
451
452
453
454
455
456
457
458
459
460
461
462
	assert(id <= MAX_SPI_ID);

	/* Serialize read-modify-write to Distributor registers */
	spin_lock(&gic_lock);
	switch (type) {
	case GICV2_INTR_GROUP1:
		gicd_set_igroupr(driver_data->gicd_base, id);
		break;
	case GICV2_INTR_GROUP0:
		gicd_clr_igroupr(driver_data->gicd_base, id);
		break;
	default:
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
463
		assert(false);
464
		break;
465
466
467
	}
	spin_unlock(&gic_lock);
}
468
469
470
471
472
473
474
475
476
477
478

/*******************************************************************************
 * This function raises the specified SGI to requested targets.
 *
 * The proc_num parameter must be the linear index of the target PE in the
 * system.
 ******************************************************************************/
void gicv2_raise_sgi(int sgi_num, int proc_num)
{
	unsigned int sgir_val, target;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
479
480
481
	assert(driver_data != NULL);
	assert((unsigned int)proc_num < GICV2_MAX_TARGET_PE);
	assert(driver_data->gicd_base != 0U);
482
483
484
485
486

	/*
	 * Target masks array must have been supplied, and the core position
	 * should be valid.
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
487
488
	assert(driver_data->target_masks != NULL);
	assert((unsigned int)proc_num < driver_data->target_masks_num);
489
490
491

	/* Don't raise SGI if the mask hasn't been populated */
	target = driver_data->target_masks[proc_num];
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
492
	assert(target != 0U);
493
494
495
496
497
498
499
500
501
502

	sgir_val = GICV2_SGIR_VALUE(SGIR_TGT_SPECIFIC, target, sgi_num);

	/*
	 * Ensure that any shared variable updates depending on out of band
	 * interrupt trigger are observed before raising SGI.
	 */
	dsbishst();
	gicd_write_sgir(driver_data->gicd_base, sgir_val);
}
503
504
505
506
507
508
509
510
511

/*******************************************************************************
 * This function sets the interrupt routing for the given SPI interrupt id.
 * The interrupt routing is specified in routing mode. The proc_num parameter is
 * linear index of the PE to target SPI. When proc_num < 0, the SPI may target
 * all PEs.
 ******************************************************************************/
void gicv2_set_spi_routing(unsigned int id, int proc_num)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
512
	unsigned int target;
513

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
514
515
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
516

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
517
	assert((id >= MIN_SPI_ID) && (id <= MAX_SPI_ID));
518
519
520
521
522

	/*
	 * Target masks array must have been supplied, and the core position
	 * should be valid.
	 */
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
523
524
525
	assert(driver_data->target_masks != NULL);
	assert((unsigned int)proc_num < GICV2_MAX_TARGET_PE);
	assert((unsigned int)proc_num < driver_data->target_masks_num);
526
527
528
529
530
531
532

	if (proc_num < 0) {
		/* Target all PEs */
		target = GIC_TARGET_CPU_MASK;
	} else {
		/* Don't route interrupt if the mask hasn't been populated */
		target = driver_data->target_masks[proc_num];
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
533
		assert(target != 0U);
534
535
536
537
	}

	gicd_set_itargetsr(driver_data->gicd_base, id, target);
}
538
539
540
541
542
543

/*******************************************************************************
 * This function clears the pending status of an interrupt identified by id.
 ******************************************************************************/
void gicv2_clear_interrupt_pending(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
544
545
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562

	/* SGIs can't be cleared pending */
	assert(id >= MIN_PPI_ID);

	/*
	 * Clear pending interrupt, and ensure that any shared variable updates
	 * depending on out of band interrupt trigger are observed afterwards.
	 */
	gicd_set_icpendr(driver_data->gicd_base, id);
	dsbishst();
}

/*******************************************************************************
 * This function sets the pending status of an interrupt identified by id.
 ******************************************************************************/
void gicv2_set_interrupt_pending(unsigned int id)
{
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
563
564
	assert(driver_data != NULL);
	assert(driver_data->gicd_base != 0U);
565
566
567
568
569
570
571
572
573
574
575

	/* SGIs can't be cleared pending */
	assert(id >= MIN_PPI_ID);

	/*
	 * Ensure that any shared variable updates depending on out of band
	 * interrupt trigger are observed before setting interrupt pending.
	 */
	dsbishst();
	gicd_set_ispendr(driver_data->gicd_base, id);
}
576
577
578
579
580
581
582
583
584

/*******************************************************************************
 * This function sets the PMR register with the supplied value. Returns the
 * original PMR.
 ******************************************************************************/
unsigned int gicv2_set_pmr(unsigned int mask)
{
	unsigned int old_mask;

Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
585
586
	assert(driver_data != NULL);
	assert(driver_data->gicc_base != 0U);
587
588
589
590
591
592
593
594
595
596
597
598
599

	old_mask = gicc_read_pmr(driver_data->gicc_base);

	/*
	 * Order memory updates w.r.t. PMR write, and ensure they're visible
	 * before potential out of band interrupt trigger because of PMR update.
	 */
	dmbishst();
	gicc_write_pmr(driver_data->gicc_base, mask);
	dsbishst();

	return old_mask;
}
600
601
602
603
604
605
606
607
608

/*******************************************************************************
 * This function updates single interrupt configuration to be level/edge
 * triggered
 ******************************************************************************/
void gicv2_interrupt_set_cfg(unsigned int id, unsigned int cfg)
{
	gicd_set_icfgr(driver_data->gicd_base, id, cfg);
}