blob: e040e0aca97da2c82e4705aafcef550e4f28529e [file] [log] [blame]
Ian Spray84687392014-01-02 16:57:12 +00001/*
Soby Mathew4f968382016-06-07 17:06:27 +01002 * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved.
Ian Spray84687392014-01-02 16:57:12 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Ian Spray84687392014-01-02 16:57:12 +00005 */
6
Dan Handleyfb42b122014-06-20 09:43:15 +01007#include <arch.h>
Ian Spray84687392014-01-02 16:57:12 +00008#include <arch_helpers.h>
Dan Handleyfb42b122014-06-20 09:43:15 +01009#include <arm_gic.h>
Achin Gupta191e86e2014-05-09 10:03:15 +010010#include <assert.h>
11#include <bl_common.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010012#include <debug.h>
Dan Handley930ee2e2014-04-17 17:48:52 +010013#include <gic_v2.h>
14#include <gic_v3.h>
Achin Gupta191e86e2014-05-09 10:03:15 +010015#include <interrupt_mgmt.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010016#include <platform.h>
17#include <stdint.h>
Dan Handleyfb42b122014-06-20 09:43:15 +010018
Juan Castillo82312952014-10-20 12:27:28 +010019/* Value used to initialize Non-Secure IRQ priorities four at a time */
20#define GICD_IPRIORITYR_DEF_VAL \
21 (GIC_HIGHEST_NS_PRIORITY | \
22 (GIC_HIGHEST_NS_PRIORITY << 8) | \
23 (GIC_HIGHEST_NS_PRIORITY << 16) | \
24 (GIC_HIGHEST_NS_PRIORITY << 24))
Dan Handleyfb42b122014-06-20 09:43:15 +010025
Juan Castillo7f1f0622014-09-09 09:49:23 +010026static uintptr_t g_gicc_base;
27static uintptr_t g_gicd_base;
28static uintptr_t g_gicr_base;
Dan Handleyfb42b122014-06-20 09:43:15 +010029static const unsigned int *g_irq_sec_ptr;
30static unsigned int g_num_irqs;
31
Ian Spray84687392014-01-02 16:57:12 +000032
Ian Spray84687392014-01-02 16:57:12 +000033/*******************************************************************************
34 * This function does some minimal GICv3 configuration. The Firmware itself does
35 * not fully support GICv3 at this time and relies on GICv2 emulation as
36 * provided by GICv3. This function allows software (like Linux) in later stages
37 * to use full GICv3 features.
38 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +010039static void gicv3_cpuif_setup(void)
Ian Spray84687392014-01-02 16:57:12 +000040{
Vikram Kanigiri29f7cbc2015-06-26 10:13:22 +010041 unsigned int val;
Harry Liebeleaec5902013-12-12 13:00:29 +000042 uintptr_t base;
Ian Spray84687392014-01-02 16:57:12 +000043
44 /*
45 * When CPUs come out of reset they have their GICR_WAKER.ProcessorSleep
46 * bit set. In order to allow interrupts to get routed to the CPU we
47 * need to clear this bit if set and wait for GICR_WAKER.ChildrenAsleep
48 * to clear (GICv3 Architecture specification 5.4.23).
49 * GICR_WAKER is NOT banked per CPU, compute the correct base address
50 * per CPU.
Ian Spray84687392014-01-02 16:57:12 +000051 */
Dan Handleyfb42b122014-06-20 09:43:15 +010052 assert(g_gicr_base);
53 base = gicv3_get_rdist(g_gicr_base, read_mpidr());
Harry Liebeleaec5902013-12-12 13:00:29 +000054 if (base == (uintptr_t)NULL) {
55 /* No re-distributor base address. This interface cannot be
56 * configured.
57 */
58 panic();
59 }
60
Ian Spray84687392014-01-02 16:57:12 +000061 val = gicr_read_waker(base);
62
63 val &= ~WAKER_PS;
64 gicr_write_waker(base, val);
65 dsb();
66
67 /* We need to wait for ChildrenAsleep to clear. */
68 val = gicr_read_waker(base);
Dan Handleyfb42b122014-06-20 09:43:15 +010069 while (val & WAKER_CA)
Ian Spray84687392014-01-02 16:57:12 +000070 val = gicr_read_waker(base);
Ian Spray84687392014-01-02 16:57:12 +000071
Ian Spray84687392014-01-02 16:57:12 +000072 val = read_icc_sre_el3();
73 write_icc_sre_el3(val | ICC_SRE_EN | ICC_SRE_SRE);
Vikram Kanigiri29f7cbc2015-06-26 10:13:22 +010074 isb();
Ian Spray84687392014-01-02 16:57:12 +000075}
76
77/*******************************************************************************
78 * This function does some minimal GICv3 configuration when cores go
79 * down.
80 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +010081static void gicv3_cpuif_deactivate(void)
Ian Spray84687392014-01-02 16:57:12 +000082{
Harry Liebeleaec5902013-12-12 13:00:29 +000083 unsigned int val;
84 uintptr_t base;
Ian Spray84687392014-01-02 16:57:12 +000085
86 /*
87 * When taking CPUs down we need to set GICR_WAKER.ProcessorSleep and
88 * wait for GICR_WAKER.ChildrenAsleep to get set.
89 * (GICv3 Architecture specification 5.4.23).
90 * GICR_WAKER is NOT banked per CPU, compute the correct base address
91 * per CPU.
Ian Spray84687392014-01-02 16:57:12 +000092 */
Dan Handleyfb42b122014-06-20 09:43:15 +010093 assert(g_gicr_base);
94 base = gicv3_get_rdist(g_gicr_base, read_mpidr());
Harry Liebeleaec5902013-12-12 13:00:29 +000095 if (base == (uintptr_t)NULL) {
96 /* No re-distributor base address. This interface cannot be
97 * configured.
98 */
99 panic();
100 }
101
Ian Spray84687392014-01-02 16:57:12 +0000102 val = gicr_read_waker(base);
103 val |= WAKER_PS;
104 gicr_write_waker(base, val);
105 dsb();
106
107 /* We need to wait for ChildrenAsleep to set. */
108 val = gicr_read_waker(base);
Dan Handleyfb42b122014-06-20 09:43:15 +0100109 while ((val & WAKER_CA) == 0)
Ian Spray84687392014-01-02 16:57:12 +0000110 val = gicr_read_waker(base);
Ian Spray84687392014-01-02 16:57:12 +0000111}
112
113
114/*******************************************************************************
115 * Enable secure interrupts and use FIQs to route them. Disable legacy bypass
116 * and set the priority mask register to allow all interrupts to trickle in.
117 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100118void arm_gic_cpuif_setup(void)
Ian Spray84687392014-01-02 16:57:12 +0000119{
120 unsigned int val;
121
Dan Handleyfb42b122014-06-20 09:43:15 +0100122 assert(g_gicc_base);
123 val = gicc_read_iidr(g_gicc_base);
Ian Spray84687392014-01-02 16:57:12 +0000124
125 /*
126 * If GICv3 we need to do a bit of additional setup. We want to
127 * allow default GICv2 behaviour but allow the next stage to
128 * enable full gicv3 features.
129 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100130 if (((val >> GICC_IIDR_ARCH_SHIFT) & GICC_IIDR_ARCH_MASK) >= 3)
Ian Spray84687392014-01-02 16:57:12 +0000131 gicv3_cpuif_setup();
Ian Spray84687392014-01-02 16:57:12 +0000132
133 val = ENABLE_GRP0 | FIQ_EN | FIQ_BYP_DIS_GRP0;
134 val |= IRQ_BYP_DIS_GRP0 | FIQ_BYP_DIS_GRP1 | IRQ_BYP_DIS_GRP1;
135
Dan Handleyfb42b122014-06-20 09:43:15 +0100136 gicc_write_pmr(g_gicc_base, GIC_PRI_MASK);
137 gicc_write_ctlr(g_gicc_base, val);
Ian Spray84687392014-01-02 16:57:12 +0000138}
139
140/*******************************************************************************
141 * Place the cpu interface in a state where it can never make a cpu exit wfi as
142 * as result of an asserted interrupt. This is critical for powering down a cpu
143 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100144void arm_gic_cpuif_deactivate(void)
Ian Spray84687392014-01-02 16:57:12 +0000145{
146 unsigned int val;
147
148 /* Disable secure, non-secure interrupts and disable their bypass */
Dan Handleyfb42b122014-06-20 09:43:15 +0100149 assert(g_gicc_base);
150 val = gicc_read_ctlr(g_gicc_base);
Ian Spray84687392014-01-02 16:57:12 +0000151 val &= ~(ENABLE_GRP0 | ENABLE_GRP1);
152 val |= FIQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP0;
153 val |= IRQ_BYP_DIS_GRP0 | IRQ_BYP_DIS_GRP1;
Dan Handleyfb42b122014-06-20 09:43:15 +0100154 gicc_write_ctlr(g_gicc_base, val);
Ian Spray84687392014-01-02 16:57:12 +0000155
Dan Handleyfb42b122014-06-20 09:43:15 +0100156 val = gicc_read_iidr(g_gicc_base);
Ian Spray84687392014-01-02 16:57:12 +0000157
158 /*
159 * If GICv3 we need to do a bit of additional setup. Make sure the
160 * RDIST is put to sleep.
161 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100162 if (((val >> GICC_IIDR_ARCH_SHIFT) & GICC_IIDR_ARCH_MASK) >= 3)
Ian Spray84687392014-01-02 16:57:12 +0000163 gicv3_cpuif_deactivate();
Ian Spray84687392014-01-02 16:57:12 +0000164}
165
166/*******************************************************************************
167 * Per cpu gic distributor setup which will be done by all cpus after a cold
168 * boot/hotplug. This marks out the secure interrupts & enables them.
169 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100170void arm_gic_pcpu_distif_setup(void)
Ian Spray84687392014-01-02 16:57:12 +0000171{
Achin Gupta897333d2015-03-09 21:54:40 +0000172 unsigned int index, irq_num, sec_ppi_sgi_mask;
Ian Spray84687392014-01-02 16:57:12 +0000173
Dan Handleyfb42b122014-06-20 09:43:15 +0100174 assert(g_gicd_base);
Juan Castillo82312952014-10-20 12:27:28 +0100175
Juan Castillo82312952014-10-20 12:27:28 +0100176 /* Setup PPI priorities doing four at a time */
177 for (index = 0; index < 32; index += 4) {
178 gicd_write_ipriorityr(g_gicd_base, index,
179 GICD_IPRIORITYR_DEF_VAL);
180 }
181
Dan Handleyfb42b122014-06-20 09:43:15 +0100182 assert(g_irq_sec_ptr);
Achin Gupta897333d2015-03-09 21:54:40 +0000183 sec_ppi_sgi_mask = 0;
Soby Mathew4f968382016-06-07 17:06:27 +0100184
185 /* Ensure all SGIs and PPIs are Group0 to begin with */
186 gicd_write_igroupr(g_gicd_base, 0, 0);
187
Dan Handleyfb42b122014-06-20 09:43:15 +0100188 for (index = 0; index < g_num_irqs; index++) {
189 irq_num = g_irq_sec_ptr[index];
190 if (irq_num < MIN_SPI_ID) {
Soby Mathew4f968382016-06-07 17:06:27 +0100191 /* We have an SGI or a PPI */
Achin Gupta897333d2015-03-09 21:54:40 +0000192 sec_ppi_sgi_mask |= 1U << irq_num;
Dan Handleyfb42b122014-06-20 09:43:15 +0100193 gicd_set_ipriorityr(g_gicd_base, irq_num,
194 GIC_HIGHEST_SEC_PRIORITY);
195 gicd_set_isenabler(g_gicd_base, irq_num);
196 }
197 }
Achin Gupta897333d2015-03-09 21:54:40 +0000198
199 /*
200 * Invert the bitmask to create a mask for non-secure PPIs and
201 * SGIs. Program the GICD_IGROUPR0 with this bit mask. This write will
202 * update the GICR_IGROUPR0 as well in case we are running on a GICv3
203 * system. This is critical if GICD_CTLR.ARE_NS=1.
204 */
205 gicd_write_igroupr(g_gicd_base, 0, ~sec_ppi_sgi_mask);
Ian Spray84687392014-01-02 16:57:12 +0000206}
207
208/*******************************************************************************
Juan Castillo82312952014-10-20 12:27:28 +0100209 * Get the current CPU bit mask from GICD_ITARGETSR0
210 ******************************************************************************/
211static unsigned int arm_gic_get_cpuif_id(void)
212{
213 unsigned int val;
214
215 val = gicd_read_itargetsr(g_gicd_base, 0);
216 return val & GIC_TARGET_CPU_MASK;
217}
218
219/*******************************************************************************
Ian Spray84687392014-01-02 16:57:12 +0000220 * Global gic distributor setup which will be done by the primary cpu after a
221 * cold boot. It marks out the secure SPIs, PPIs & SGIs and enables them. It
222 * then enables the secure GIC distributor interface.
223 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100224static void arm_gic_distif_setup(void)
Ian Spray84687392014-01-02 16:57:12 +0000225{
Dan Handleyfb42b122014-06-20 09:43:15 +0100226 unsigned int num_ints, ctlr, index, irq_num;
Juan Castillo82312952014-10-20 12:27:28 +0100227 uint8_t target_cpu;
Ian Spray84687392014-01-02 16:57:12 +0000228
229 /* Disable the distributor before going further */
Dan Handleyfb42b122014-06-20 09:43:15 +0100230 assert(g_gicd_base);
231 ctlr = gicd_read_ctlr(g_gicd_base);
Ian Spray84687392014-01-02 16:57:12 +0000232 ctlr &= ~(ENABLE_GRP0 | ENABLE_GRP1);
Dan Handleyfb42b122014-06-20 09:43:15 +0100233 gicd_write_ctlr(g_gicd_base, ctlr);
Ian Spray84687392014-01-02 16:57:12 +0000234
235 /*
Juan Castillo82312952014-10-20 12:27:28 +0100236 * Mark out non-secure SPI interrupts. The number of interrupts is
237 * calculated as 32 * (IT_LINES + 1). We do 32 at a time.
Ian Spray84687392014-01-02 16:57:12 +0000238 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100239 num_ints = gicd_read_typer(g_gicd_base) & IT_LINES_NO_MASK;
Juan Castillo82312952014-10-20 12:27:28 +0100240 num_ints = (num_ints + 1) << 5;
241 for (index = MIN_SPI_ID; index < num_ints; index += 32)
242 gicd_write_igroupr(g_gicd_base, index, ~0);
243
244 /* Setup SPI priorities doing four at a time */
245 for (index = MIN_SPI_ID; index < num_ints; index += 4) {
246 gicd_write_ipriorityr(g_gicd_base, index,
247 GICD_IPRIORITYR_DEF_VAL);
248 }
Ian Spray84687392014-01-02 16:57:12 +0000249
Juan Castillo82312952014-10-20 12:27:28 +0100250 /* Read the target CPU mask */
251 target_cpu = arm_gic_get_cpuif_id();
252
253 /* Configure SPI secure interrupts now */
Dan Handleyfb42b122014-06-20 09:43:15 +0100254 assert(g_irq_sec_ptr);
255 for (index = 0; index < g_num_irqs; index++) {
256 irq_num = g_irq_sec_ptr[index];
257 if (irq_num >= MIN_SPI_ID) {
258 /* We have an SPI */
259 gicd_clr_igroupr(g_gicd_base, irq_num);
260 gicd_set_ipriorityr(g_gicd_base, irq_num,
261 GIC_HIGHEST_SEC_PRIORITY);
Juan Castillo82312952014-10-20 12:27:28 +0100262 gicd_set_itargetsr(g_gicd_base, irq_num, target_cpu);
Dan Handleyfb42b122014-06-20 09:43:15 +0100263 gicd_set_isenabler(g_gicd_base, irq_num);
264 }
265 }
Juan Castillo82312952014-10-20 12:27:28 +0100266
267 /*
268 * Configure the SGI and PPI. This is done in a separated function
269 * because each CPU is responsible for initializing its own private
270 * interrupts.
271 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100272 arm_gic_pcpu_distif_setup();
273
274 gicd_write_ctlr(g_gicd_base, ctlr | ENABLE_GRP0);
275}
Ian Spray84687392014-01-02 16:57:12 +0000276
Dan Handleyfb42b122014-06-20 09:43:15 +0100277/*******************************************************************************
278 * Initialize the ARM GIC driver with the provided platform inputs
279******************************************************************************/
Juan Castillo7f1f0622014-09-09 09:49:23 +0100280void arm_gic_init(uintptr_t gicc_base,
281 uintptr_t gicd_base,
282 uintptr_t gicr_base,
283 const unsigned int *irq_sec_ptr,
284 unsigned int num_irqs)
Dan Handleyfb42b122014-06-20 09:43:15 +0100285{
Juan Castillo82312952014-10-20 12:27:28 +0100286 unsigned int val;
287
Dan Handleyfb42b122014-06-20 09:43:15 +0100288 assert(gicc_base);
289 assert(gicd_base);
Dan Handleyfb42b122014-06-20 09:43:15 +0100290 assert(irq_sec_ptr);
Juan Castillo82312952014-10-20 12:27:28 +0100291
Dan Handleyfb42b122014-06-20 09:43:15 +0100292 g_gicc_base = gicc_base;
293 g_gicd_base = gicd_base;
Juan Castillo82312952014-10-20 12:27:28 +0100294
295 val = gicc_read_iidr(g_gicc_base);
296
297 if (((val >> GICC_IIDR_ARCH_SHIFT) & GICC_IIDR_ARCH_MASK) >= 3) {
298 assert(gicr_base);
299 g_gicr_base = gicr_base;
300 }
301
Dan Handleyfb42b122014-06-20 09:43:15 +0100302 g_irq_sec_ptr = irq_sec_ptr;
303 g_num_irqs = num_irqs;
Ian Spray84687392014-01-02 16:57:12 +0000304}
305
Dan Handleyfb42b122014-06-20 09:43:15 +0100306/*******************************************************************************
307 * Setup the ARM GIC CPU and distributor interfaces.
308******************************************************************************/
309void arm_gic_setup(void)
Ian Spray84687392014-01-02 16:57:12 +0000310{
Dan Handleyfb42b122014-06-20 09:43:15 +0100311 arm_gic_cpuif_setup();
312 arm_gic_distif_setup();
Ian Spray84687392014-01-02 16:57:12 +0000313}
Achin Gupta191e86e2014-05-09 10:03:15 +0100314
315/*******************************************************************************
316 * An ARM processor signals interrupt exceptions through the IRQ and FIQ pins.
317 * The interrupt controller knows which pin/line it uses to signal a type of
Dan Handleyfb42b122014-06-20 09:43:15 +0100318 * interrupt. This function provides a common implementation of
319 * plat_interrupt_type_to_line() in an ARM GIC environment for optional re-use
320 * across platforms. It lets the interrupt management framework determine
321 * for a type of interrupt and security state, which line should be used in the
322 * SCR_EL3 to control its routing to EL3. The interrupt line is represented as
323 * the bit position of the IRQ or FIQ bit in the SCR_EL3.
Achin Gupta191e86e2014-05-09 10:03:15 +0100324 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100325uint32_t arm_gic_interrupt_type_to_line(uint32_t type,
326 uint32_t security_state)
Achin Gupta191e86e2014-05-09 10:03:15 +0100327{
Achin Gupta191e86e2014-05-09 10:03:15 +0100328 assert(type == INTR_TYPE_S_EL1 ||
329 type == INTR_TYPE_EL3 ||
330 type == INTR_TYPE_NS);
331
Juan Castillof558cac2014-06-05 09:45:36 +0100332 assert(sec_state_is_valid(security_state));
Achin Gupta191e86e2014-05-09 10:03:15 +0100333
334 /*
335 * We ignore the security state parameter under the assumption that
336 * both normal and secure worlds are using ARM GICv2. This parameter
337 * will be used when the secure world starts using GICv3.
338 */
Dan Handleyfb42b122014-06-20 09:43:15 +0100339#if ARM_GIC_ARCH == 2
340 return gicv2_interrupt_type_to_line(g_gicc_base, type);
Achin Gupta191e86e2014-05-09 10:03:15 +0100341#else
Dan Handleyfb42b122014-06-20 09:43:15 +0100342#error "Invalid ARM GIC architecture version specified for platform port"
343#endif /* ARM_GIC_ARCH */
Achin Gupta191e86e2014-05-09 10:03:15 +0100344}
345
Dan Handleyfb42b122014-06-20 09:43:15 +0100346#if ARM_GIC_ARCH == 2
Achin Gupta02d36282014-05-04 19:02:52 +0100347/*******************************************************************************
348 * This function returns the type of the highest priority pending interrupt at
349 * the GIC cpu interface. INTR_TYPE_INVAL is returned when there is no
350 * interrupt pending.
351 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100352uint32_t arm_gic_get_pending_interrupt_type(void)
Achin Gupta02d36282014-05-04 19:02:52 +0100353{
Dan Handley1c54d972014-06-20 12:02:01 +0100354 uint32_t id;
Achin Gupta02d36282014-05-04 19:02:52 +0100355
Dan Handleyfb42b122014-06-20 09:43:15 +0100356 assert(g_gicc_base);
Achin Gupta966b9522015-05-18 10:56:47 +0100357 id = gicc_read_hppir(g_gicc_base) & INT_ID_MASK;
Achin Gupta02d36282014-05-04 19:02:52 +0100358
359 /* Assume that all secure interrupts are S-EL1 interrupts */
360 if (id < 1022)
361 return INTR_TYPE_S_EL1;
362
363 if (id == GIC_SPURIOUS_INTERRUPT)
364 return INTR_TYPE_INVAL;
365
366 return INTR_TYPE_NS;
367}
368
369/*******************************************************************************
370 * This function returns the id of the highest priority pending interrupt at
371 * the GIC cpu interface. INTR_ID_UNAVAILABLE is returned when there is no
372 * interrupt pending.
373 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100374uint32_t arm_gic_get_pending_interrupt_id(void)
Achin Gupta02d36282014-05-04 19:02:52 +0100375{
Dan Handleyfb42b122014-06-20 09:43:15 +0100376 uint32_t id;
Achin Gupta02d36282014-05-04 19:02:52 +0100377
Dan Handleyfb42b122014-06-20 09:43:15 +0100378 assert(g_gicc_base);
Achin Gupta966b9522015-05-18 10:56:47 +0100379 id = gicc_read_hppir(g_gicc_base) & INT_ID_MASK;
Achin Gupta02d36282014-05-04 19:02:52 +0100380
381 if (id < 1022)
382 return id;
383
384 if (id == 1023)
385 return INTR_ID_UNAVAILABLE;
386
387 /*
388 * Find out which non-secure interrupt it is under the assumption that
389 * the GICC_CTLR.AckCtl bit is 0.
390 */
Achin Gupta966b9522015-05-18 10:56:47 +0100391 return gicc_read_ahppir(g_gicc_base) & INT_ID_MASK;
Achin Gupta02d36282014-05-04 19:02:52 +0100392}
393
394/*******************************************************************************
395 * This functions reads the GIC cpu interface Interrupt Acknowledge register
396 * to start handling the pending interrupt. It returns the contents of the IAR.
397 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100398uint32_t arm_gic_acknowledge_interrupt(void)
Achin Gupta02d36282014-05-04 19:02:52 +0100399{
Dan Handleyfb42b122014-06-20 09:43:15 +0100400 assert(g_gicc_base);
401 return gicc_read_IAR(g_gicc_base);
Achin Gupta02d36282014-05-04 19:02:52 +0100402}
403
404/*******************************************************************************
405 * This functions writes the GIC cpu interface End Of Interrupt register with
406 * the passed value to finish handling the active interrupt
407 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100408void arm_gic_end_of_interrupt(uint32_t id)
Achin Gupta02d36282014-05-04 19:02:52 +0100409{
Dan Handleyfb42b122014-06-20 09:43:15 +0100410 assert(g_gicc_base);
411 gicc_write_EOIR(g_gicc_base, id);
Achin Gupta02d36282014-05-04 19:02:52 +0100412}
413
414/*******************************************************************************
415 * This function returns the type of the interrupt id depending upon the group
416 * this interrupt has been configured under by the interrupt controller i.e.
417 * group0 or group1.
418 ******************************************************************************/
Dan Handleyfb42b122014-06-20 09:43:15 +0100419uint32_t arm_gic_get_interrupt_type(uint32_t id)
Achin Gupta02d36282014-05-04 19:02:52 +0100420{
421 uint32_t group;
422
Dan Handleyfb42b122014-06-20 09:43:15 +0100423 assert(g_gicd_base);
424 group = gicd_get_igroupr(g_gicd_base, id);
Achin Gupta02d36282014-05-04 19:02:52 +0100425
426 /* Assume that all secure interrupts are S-EL1 interrupts */
427 if (group == GRP0)
428 return INTR_TYPE_S_EL1;
429 else
430 return INTR_TYPE_NS;
431}
432
433#else
Dan Handleyfb42b122014-06-20 09:43:15 +0100434#error "Invalid ARM GIC architecture version specified for platform port"
435#endif /* ARM_GIC_ARCH */