xref: /rk3399_ARM-atf/plat/common/plat_gicv3.c (revision dcb31ff79096fc88b45df8068e5de83b93f833ed)
1f14d1886SSoby Mathew /*
2e0ced7a9SAntonio Nino Diaz  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3*dcb31ff7SFlorian Lugou  * Portions copyright (c) 2021-2022, ProvenRun S.A.S. All rights reserved.
4f14d1886SSoby Mathew  *
582cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
6f14d1886SSoby Mathew  */
709d40e0eSAntonio Nino Diaz 
8f14d1886SSoby Mathew #include <assert.h>
9e0ced7a9SAntonio Nino Diaz #include <stdbool.h>
10f14d1886SSoby Mathew 
1109d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1209d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1309d40e0eSAntonio Nino Diaz #include <bl31/interrupt_mgmt.h>
1409d40e0eSAntonio Nino Diaz #include <drivers/arm/gic_common.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/arm/gicv3.h>
1609d40e0eSAntonio Nino Diaz #include <lib/cassert.h>
1709d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
1809d40e0eSAntonio Nino Diaz 
193d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
20f14d1886SSoby Mathew 
21f14d1886SSoby Mathew /*
22f14d1886SSoby Mathew  * The following platform GIC functions are weakly defined. They
23f14d1886SSoby Mathew  * provide typical implementations that may be re-used by multiple
24f14d1886SSoby Mathew  * platforms but may also be overridden by a platform if required.
25f14d1886SSoby Mathew  */
26f14d1886SSoby Mathew #pragma weak plat_ic_get_pending_interrupt_id
27f14d1886SSoby Mathew #pragma weak plat_ic_get_pending_interrupt_type
28f14d1886SSoby Mathew #pragma weak plat_ic_acknowledge_interrupt
29f14d1886SSoby Mathew #pragma weak plat_ic_get_interrupt_type
30f14d1886SSoby Mathew #pragma weak plat_ic_end_of_interrupt
31f14d1886SSoby Mathew #pragma weak plat_interrupt_type_to_line
32f14d1886SSoby Mathew 
33eb68ea9bSJeenu Viswambharan #pragma weak plat_ic_get_running_priority
34ca43b55dSJeenu Viswambharan #pragma weak plat_ic_is_spi
35ca43b55dSJeenu Viswambharan #pragma weak plat_ic_is_ppi
36ca43b55dSJeenu Viswambharan #pragma weak plat_ic_is_sgi
37cbd3f370SJeenu Viswambharan #pragma weak plat_ic_get_interrupt_active
38979225f4SJeenu Viswambharan #pragma weak plat_ic_enable_interrupt
39979225f4SJeenu Viswambharan #pragma weak plat_ic_disable_interrupt
40f3a86600SJeenu Viswambharan #pragma weak plat_ic_set_interrupt_priority
4174dce7faSJeenu Viswambharan #pragma weak plat_ic_set_interrupt_type
428db978b5SJeenu Viswambharan #pragma weak plat_ic_raise_el3_sgi
43*dcb31ff7SFlorian Lugou #pragma weak plat_ic_raise_ns_sgi
44*dcb31ff7SFlorian Lugou #pragma weak plat_ic_raise_s_el1_sgi
45fc529feeSJeenu Viswambharan #pragma weak plat_ic_set_spi_routing
46a2816a16SJeenu Viswambharan #pragma weak plat_ic_set_interrupt_pending
47a2816a16SJeenu Viswambharan #pragma weak plat_ic_clear_interrupt_pending
48eb68ea9bSJeenu Viswambharan 
49f14d1886SSoby Mathew CASSERT((INTR_TYPE_S_EL1 == INTR_GROUP1S) &&
50f14d1886SSoby Mathew 	(INTR_TYPE_NS == INTR_GROUP1NS) &&
51f14d1886SSoby Mathew 	(INTR_TYPE_EL3 == INTR_GROUP0), assert_interrupt_type_mismatch);
52f14d1886SSoby Mathew 
53f14d1886SSoby Mathew /*
54f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
55f14d1886SSoby Mathew  * the Interrupt controller
56f14d1886SSoby Mathew  */
57f14d1886SSoby Mathew uint32_t plat_ic_get_pending_interrupt_id(void)
58f14d1886SSoby Mathew {
59f14d1886SSoby Mathew 	unsigned int irqnr;
60f14d1886SSoby Mathew 
61f14d1886SSoby Mathew 	assert(IS_IN_EL3());
62f14d1886SSoby Mathew 	irqnr = gicv3_get_pending_interrupt_id();
63e0ced7a9SAntonio Nino Diaz 	return gicv3_is_intr_id_special_identifier(irqnr) ?
64f14d1886SSoby Mathew 				INTR_ID_UNAVAILABLE : irqnr;
65f14d1886SSoby Mathew }
66f14d1886SSoby Mathew 
67f14d1886SSoby Mathew /*
68f14d1886SSoby Mathew  * This function returns the type of the highest priority pending interrupt
69f14d1886SSoby Mathew  * at the Interrupt controller. In the case of GICv3, the Highest Priority
70f14d1886SSoby Mathew  * Pending interrupt system register (`ICC_HPPIR0_EL1`) is read to determine
71f14d1886SSoby Mathew  * the id of the pending interrupt. The type of interrupt depends upon the
72f14d1886SSoby Mathew  * id value as follows.
73f14d1886SSoby Mathew  *   1. id = PENDING_G1S_INTID (1020) is reported as a S-EL1 interrupt
74f14d1886SSoby Mathew  *   2. id = PENDING_G1NS_INTID (1021) is reported as a Non-secure interrupt.
75f14d1886SSoby Mathew  *   3. id = GIC_SPURIOUS_INTERRUPT (1023) is reported as an invalid interrupt
76f14d1886SSoby Mathew  *           type.
77f14d1886SSoby Mathew  *   4. All other interrupt id's are reported as EL3 interrupt.
78f14d1886SSoby Mathew  */
79f14d1886SSoby Mathew uint32_t plat_ic_get_pending_interrupt_type(void)
80f14d1886SSoby Mathew {
81f14d1886SSoby Mathew 	unsigned int irqnr;
82e0ced7a9SAntonio Nino Diaz 	uint32_t type;
83f14d1886SSoby Mathew 
84f14d1886SSoby Mathew 	assert(IS_IN_EL3());
85f14d1886SSoby Mathew 	irqnr = gicv3_get_pending_interrupt_type();
86f14d1886SSoby Mathew 
87f14d1886SSoby Mathew 	switch (irqnr) {
88f14d1886SSoby Mathew 	case PENDING_G1S_INTID:
89e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_S_EL1;
90e0ced7a9SAntonio Nino Diaz 		break;
91f14d1886SSoby Mathew 	case PENDING_G1NS_INTID:
92e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_NS;
93e0ced7a9SAntonio Nino Diaz 		break;
94f14d1886SSoby Mathew 	case GIC_SPURIOUS_INTERRUPT:
95e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_INVAL;
96e0ced7a9SAntonio Nino Diaz 		break;
97f14d1886SSoby Mathew 	default:
98e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_EL3;
99e0ced7a9SAntonio Nino Diaz 		break;
100f14d1886SSoby Mathew 	}
101e0ced7a9SAntonio Nino Diaz 
102e0ced7a9SAntonio Nino Diaz 	return type;
103f14d1886SSoby Mathew }
104f14d1886SSoby Mathew 
105f14d1886SSoby Mathew /*
106f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
107f14d1886SSoby Mathew  * the Interrupt controller and indicates to the Interrupt controller
108f14d1886SSoby Mathew  * that the interrupt processing has started.
109f14d1886SSoby Mathew  */
110f14d1886SSoby Mathew uint32_t plat_ic_acknowledge_interrupt(void)
111f14d1886SSoby Mathew {
112f14d1886SSoby Mathew 	assert(IS_IN_EL3());
113f14d1886SSoby Mathew 	return gicv3_acknowledge_interrupt();
114f14d1886SSoby Mathew }
115f14d1886SSoby Mathew 
116f14d1886SSoby Mathew /*
117f14d1886SSoby Mathew  * This function returns the type of the interrupt `id`, depending on how
118f14d1886SSoby Mathew  * the interrupt has been configured in the interrupt controller
119f14d1886SSoby Mathew  */
120f14d1886SSoby Mathew uint32_t plat_ic_get_interrupt_type(uint32_t id)
121f14d1886SSoby Mathew {
122f14d1886SSoby Mathew 	assert(IS_IN_EL3());
123f14d1886SSoby Mathew 	return gicv3_get_interrupt_type(id, plat_my_core_pos());
124f14d1886SSoby Mathew }
125f14d1886SSoby Mathew 
126f14d1886SSoby Mathew /*
127f14d1886SSoby Mathew  * This functions is used to indicate to the interrupt controller that
128f14d1886SSoby Mathew  * the processing of the interrupt corresponding to the `id` has
129f14d1886SSoby Mathew  * finished.
130f14d1886SSoby Mathew  */
131f14d1886SSoby Mathew void plat_ic_end_of_interrupt(uint32_t id)
132f14d1886SSoby Mathew {
133f14d1886SSoby Mathew 	assert(IS_IN_EL3());
134f14d1886SSoby Mathew 	gicv3_end_of_interrupt(id);
135f14d1886SSoby Mathew }
136f14d1886SSoby Mathew 
137f14d1886SSoby Mathew /*
138f14d1886SSoby Mathew  * An ARM processor signals interrupt exceptions through the IRQ and FIQ pins.
139f14d1886SSoby Mathew  * The interrupt controller knows which pin/line it uses to signal a type of
140f14d1886SSoby Mathew  * interrupt. It lets the interrupt management framework determine for a type of
141f14d1886SSoby Mathew  * interrupt and security state, which line should be used in the SCR_EL3 to
142f14d1886SSoby Mathew  * control its routing to EL3. The interrupt line is represented as the bit
143f14d1886SSoby Mathew  * position of the IRQ or FIQ bit in the SCR_EL3.
144f14d1886SSoby Mathew  */
145f14d1886SSoby Mathew uint32_t plat_interrupt_type_to_line(uint32_t type,
146f14d1886SSoby Mathew 				uint32_t security_state)
147f14d1886SSoby Mathew {
148e0ced7a9SAntonio Nino Diaz 	assert((type == INTR_TYPE_S_EL1) ||
149e0ced7a9SAntonio Nino Diaz 	       (type == INTR_TYPE_EL3) ||
150e0ced7a9SAntonio Nino Diaz 	       (type == INTR_TYPE_NS));
151f14d1886SSoby Mathew 
152f14d1886SSoby Mathew 	assert(sec_state_is_valid(security_state));
153f14d1886SSoby Mathew 	assert(IS_IN_EL3());
154f14d1886SSoby Mathew 
155f14d1886SSoby Mathew 	switch (type) {
156f14d1886SSoby Mathew 	case INTR_TYPE_S_EL1:
157f14d1886SSoby Mathew 		/*
158f14d1886SSoby Mathew 		 * The S-EL1 interrupts are signaled as IRQ in S-EL0/1 contexts
159f14d1886SSoby Mathew 		 * and as FIQ in the NS-EL0/1/2 contexts
160f14d1886SSoby Mathew 		 */
161f14d1886SSoby Mathew 		if (security_state == SECURE)
162f14d1886SSoby Mathew 			return __builtin_ctz(SCR_IRQ_BIT);
163f14d1886SSoby Mathew 		else
164f14d1886SSoby Mathew 			return __builtin_ctz(SCR_FIQ_BIT);
165a08a2014SDaniel Boulby 		assert(0); /* Unreachable */
166f14d1886SSoby Mathew 	case INTR_TYPE_NS:
167f14d1886SSoby Mathew 		/*
168f14d1886SSoby Mathew 		 * The Non secure interrupts will be signaled as FIQ in S-EL0/1
169f14d1886SSoby Mathew 		 * contexts and as IRQ in the NS-EL0/1/2 contexts.
170f14d1886SSoby Mathew 		 */
171f14d1886SSoby Mathew 		if (security_state == SECURE)
172f14d1886SSoby Mathew 			return __builtin_ctz(SCR_FIQ_BIT);
173f14d1886SSoby Mathew 		else
174f14d1886SSoby Mathew 			return __builtin_ctz(SCR_IRQ_BIT);
175a08a2014SDaniel Boulby 		assert(0); /* Unreachable */
176f14d1886SSoby Mathew 	case INTR_TYPE_EL3:
177f14d1886SSoby Mathew 		/*
178f14d1886SSoby Mathew 		 * The EL3 interrupts are signaled as FIQ in both S-EL0/1 and
179f14d1886SSoby Mathew 		 * NS-EL0/1/2 contexts
180f14d1886SSoby Mathew 		 */
181f14d1886SSoby Mathew 		return __builtin_ctz(SCR_FIQ_BIT);
1828ae0df93SJonathan Wright 	default:
1838ae0df93SJonathan Wright 		panic();
184f14d1886SSoby Mathew 	}
185f14d1886SSoby Mathew }
186eb68ea9bSJeenu Viswambharan 
187eb68ea9bSJeenu Viswambharan unsigned int plat_ic_get_running_priority(void)
188eb68ea9bSJeenu Viswambharan {
189eb68ea9bSJeenu Viswambharan 	return gicv3_get_running_priority();
190eb68ea9bSJeenu Viswambharan }
191eb68ea9bSJeenu Viswambharan 
192ca43b55dSJeenu Viswambharan int plat_ic_is_spi(unsigned int id)
193ca43b55dSJeenu Viswambharan {
194ca43b55dSJeenu Viswambharan 	return (id >= MIN_SPI_ID) && (id <= MAX_SPI_ID);
195ca43b55dSJeenu Viswambharan }
196ca43b55dSJeenu Viswambharan 
197ca43b55dSJeenu Viswambharan int plat_ic_is_ppi(unsigned int id)
198ca43b55dSJeenu Viswambharan {
199ca43b55dSJeenu Viswambharan 	return (id >= MIN_PPI_ID) && (id < MIN_SPI_ID);
200ca43b55dSJeenu Viswambharan }
201ca43b55dSJeenu Viswambharan 
202ca43b55dSJeenu Viswambharan int plat_ic_is_sgi(unsigned int id)
203ca43b55dSJeenu Viswambharan {
204ca43b55dSJeenu Viswambharan 	return (id >= MIN_SGI_ID) && (id < MIN_PPI_ID);
205ca43b55dSJeenu Viswambharan }
206cbd3f370SJeenu Viswambharan 
207cbd3f370SJeenu Viswambharan unsigned int plat_ic_get_interrupt_active(unsigned int id)
208cbd3f370SJeenu Viswambharan {
209cbd3f370SJeenu Viswambharan 	return gicv3_get_interrupt_active(id, plat_my_core_pos());
210cbd3f370SJeenu Viswambharan }
211979225f4SJeenu Viswambharan 
212979225f4SJeenu Viswambharan void plat_ic_enable_interrupt(unsigned int id)
213979225f4SJeenu Viswambharan {
214979225f4SJeenu Viswambharan 	gicv3_enable_interrupt(id, plat_my_core_pos());
215979225f4SJeenu Viswambharan }
216979225f4SJeenu Viswambharan 
217979225f4SJeenu Viswambharan void plat_ic_disable_interrupt(unsigned int id)
218979225f4SJeenu Viswambharan {
219979225f4SJeenu Viswambharan 	gicv3_disable_interrupt(id, plat_my_core_pos());
220979225f4SJeenu Viswambharan }
221f3a86600SJeenu Viswambharan 
222f3a86600SJeenu Viswambharan void plat_ic_set_interrupt_priority(unsigned int id, unsigned int priority)
223f3a86600SJeenu Viswambharan {
224f3a86600SJeenu Viswambharan 	gicv3_set_interrupt_priority(id, plat_my_core_pos(), priority);
225f3a86600SJeenu Viswambharan }
22674dce7faSJeenu Viswambharan 
22774dce7faSJeenu Viswambharan int plat_ic_has_interrupt_type(unsigned int type)
22874dce7faSJeenu Viswambharan {
22974dce7faSJeenu Viswambharan 	assert((type == INTR_TYPE_EL3) || (type == INTR_TYPE_S_EL1) ||
23074dce7faSJeenu Viswambharan 			(type == INTR_TYPE_NS));
23174dce7faSJeenu Viswambharan 	return 1;
23274dce7faSJeenu Viswambharan }
23374dce7faSJeenu Viswambharan 
23474dce7faSJeenu Viswambharan void plat_ic_set_interrupt_type(unsigned int id, unsigned int type)
23574dce7faSJeenu Viswambharan {
23674dce7faSJeenu Viswambharan 	gicv3_set_interrupt_type(id, plat_my_core_pos(), type);
23774dce7faSJeenu Viswambharan }
2388db978b5SJeenu Viswambharan 
2398db978b5SJeenu Viswambharan void plat_ic_raise_el3_sgi(int sgi_num, u_register_t target)
2408db978b5SJeenu Viswambharan {
2418db978b5SJeenu Viswambharan 	/* Target must be a valid MPIDR in the system */
2428db978b5SJeenu Viswambharan 	assert(plat_core_pos_by_mpidr(target) >= 0);
2438db978b5SJeenu Viswambharan 
2448db978b5SJeenu Viswambharan 	/* Verify that this is a secure EL3 SGI */
245e0ced7a9SAntonio Nino Diaz 	assert(plat_ic_get_interrupt_type((unsigned int)sgi_num) ==
246e0ced7a9SAntonio Nino Diaz 					  INTR_TYPE_EL3);
2478db978b5SJeenu Viswambharan 
248*dcb31ff7SFlorian Lugou 	gicv3_raise_sgi((unsigned int)sgi_num, GICV3_G0, target);
249*dcb31ff7SFlorian Lugou }
250*dcb31ff7SFlorian Lugou 
251*dcb31ff7SFlorian Lugou void plat_ic_raise_ns_sgi(int sgi_num, u_register_t target)
252*dcb31ff7SFlorian Lugou {
253*dcb31ff7SFlorian Lugou 	/* Target must be a valid MPIDR in the system */
254*dcb31ff7SFlorian Lugou 	assert(plat_core_pos_by_mpidr(target) >= 0);
255*dcb31ff7SFlorian Lugou 
256*dcb31ff7SFlorian Lugou 	/* Verify that this is a non-secure SGI */
257*dcb31ff7SFlorian Lugou 	assert(plat_ic_get_interrupt_type((unsigned int)sgi_num) ==
258*dcb31ff7SFlorian Lugou 					  INTR_TYPE_NS);
259*dcb31ff7SFlorian Lugou 
260*dcb31ff7SFlorian Lugou 	gicv3_raise_sgi((unsigned int)sgi_num, GICV3_G1NS, target);
261*dcb31ff7SFlorian Lugou }
262*dcb31ff7SFlorian Lugou 
263*dcb31ff7SFlorian Lugou void plat_ic_raise_s_el1_sgi(int sgi_num, u_register_t target)
264*dcb31ff7SFlorian Lugou {
265*dcb31ff7SFlorian Lugou 	/* Target must be a valid MPIDR in the system */
266*dcb31ff7SFlorian Lugou 	assert(plat_core_pos_by_mpidr(target) >= 0);
267*dcb31ff7SFlorian Lugou 
268*dcb31ff7SFlorian Lugou 	/* Verify that this is a secure EL1 SGI */
269*dcb31ff7SFlorian Lugou 	assert(plat_ic_get_interrupt_type((unsigned int)sgi_num) ==
270*dcb31ff7SFlorian Lugou 					  INTR_TYPE_S_EL1);
271*dcb31ff7SFlorian Lugou 
272*dcb31ff7SFlorian Lugou 	gicv3_raise_sgi((unsigned int)sgi_num, GICV3_G1S, target);
2738db978b5SJeenu Viswambharan }
274fc529feeSJeenu Viswambharan 
275fc529feeSJeenu Viswambharan void plat_ic_set_spi_routing(unsigned int id, unsigned int routing_mode,
276fc529feeSJeenu Viswambharan 		u_register_t mpidr)
277fc529feeSJeenu Viswambharan {
278fc529feeSJeenu Viswambharan 	unsigned int irm = 0;
279fc529feeSJeenu Viswambharan 
280fc529feeSJeenu Viswambharan 	switch (routing_mode) {
281fc529feeSJeenu Viswambharan 	case INTR_ROUTING_MODE_PE:
282fc529feeSJeenu Viswambharan 		assert(plat_core_pos_by_mpidr(mpidr) >= 0);
283fc529feeSJeenu Viswambharan 		irm = GICV3_IRM_PE;
284fc529feeSJeenu Viswambharan 		break;
285fc529feeSJeenu Viswambharan 	case INTR_ROUTING_MODE_ANY:
286fc529feeSJeenu Viswambharan 		irm = GICV3_IRM_ANY;
287fc529feeSJeenu Viswambharan 		break;
288fc529feeSJeenu Viswambharan 	default:
289a08a2014SDaniel Boulby 		assert(0); /* Unreachable */
290649c48f5SJonathan Wright 		break;
291fc529feeSJeenu Viswambharan 	}
292fc529feeSJeenu Viswambharan 
293fc529feeSJeenu Viswambharan 	gicv3_set_spi_routing(id, irm, mpidr);
294fc529feeSJeenu Viswambharan }
295a2816a16SJeenu Viswambharan 
296a2816a16SJeenu Viswambharan void plat_ic_set_interrupt_pending(unsigned int id)
297a2816a16SJeenu Viswambharan {
298a2816a16SJeenu Viswambharan 	/* Disallow setting SGIs pending */
299a2816a16SJeenu Viswambharan 	assert(id >= MIN_PPI_ID);
300a2816a16SJeenu Viswambharan 	gicv3_set_interrupt_pending(id, plat_my_core_pos());
301a2816a16SJeenu Viswambharan }
302a2816a16SJeenu Viswambharan 
303a2816a16SJeenu Viswambharan void plat_ic_clear_interrupt_pending(unsigned int id)
304a2816a16SJeenu Viswambharan {
305a2816a16SJeenu Viswambharan 	/* Disallow setting SGIs pending */
306a2816a16SJeenu Viswambharan 	assert(id >= MIN_PPI_ID);
307a2816a16SJeenu Viswambharan 	gicv3_clear_interrupt_pending(id, plat_my_core_pos());
308a2816a16SJeenu Viswambharan }
309d55a4450SJeenu Viswambharan 
310d55a4450SJeenu Viswambharan unsigned int plat_ic_set_priority_mask(unsigned int mask)
311d55a4450SJeenu Viswambharan {
312d55a4450SJeenu Viswambharan 	return gicv3_set_pmr(mask);
313d55a4450SJeenu Viswambharan }
3144ee8d0beSJeenu Viswambharan 
3154ee8d0beSJeenu Viswambharan unsigned int plat_ic_get_interrupt_id(unsigned int raw)
3164ee8d0beSJeenu Viswambharan {
317e0ced7a9SAntonio Nino Diaz 	unsigned int id = raw & INT_ID_MASK;
3184ee8d0beSJeenu Viswambharan 
319e0ced7a9SAntonio Nino Diaz 	return gicv3_is_intr_id_special_identifier(id) ?
320e0ced7a9SAntonio Nino Diaz 			INTR_ID_UNAVAILABLE : id;
3214ee8d0beSJeenu Viswambharan }
322f14d1886SSoby Mathew #endif
3233d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
324f14d1886SSoby Mathew 
325f14d1886SSoby Mathew #pragma weak plat_ic_get_pending_interrupt_id
326f14d1886SSoby Mathew #pragma weak plat_ic_acknowledge_interrupt
327f14d1886SSoby Mathew #pragma weak plat_ic_end_of_interrupt
328f14d1886SSoby Mathew 
329877cf3ffSSoby Mathew /* In AArch32, the secure group1 interrupts are targeted to Secure PL1 */
330402b3cf8SJulius Werner #ifndef __aarch64__
331877cf3ffSSoby Mathew #define IS_IN_EL1()	IS_IN_SECURE()
332877cf3ffSSoby Mathew #endif
333877cf3ffSSoby Mathew 
334f14d1886SSoby Mathew /*
335f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
336f14d1886SSoby Mathew  * the Interrupt controller
337f14d1886SSoby Mathew  */
338f14d1886SSoby Mathew uint32_t plat_ic_get_pending_interrupt_id(void)
339f14d1886SSoby Mathew {
340f14d1886SSoby Mathew 	unsigned int irqnr;
341f14d1886SSoby Mathew 
342f14d1886SSoby Mathew 	assert(IS_IN_EL1());
343f14d1886SSoby Mathew 	irqnr = gicv3_get_pending_interrupt_id_sel1();
344f14d1886SSoby Mathew 	return (irqnr == GIC_SPURIOUS_INTERRUPT) ?
345f14d1886SSoby Mathew 				INTR_ID_UNAVAILABLE : irqnr;
346f14d1886SSoby Mathew }
347f14d1886SSoby Mathew 
348f14d1886SSoby Mathew /*
349f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
350f14d1886SSoby Mathew  * the Interrupt controller and indicates to the Interrupt controller
351f14d1886SSoby Mathew  * that the interrupt processing has started.
352f14d1886SSoby Mathew  */
353f14d1886SSoby Mathew uint32_t plat_ic_acknowledge_interrupt(void)
354f14d1886SSoby Mathew {
355f14d1886SSoby Mathew 	assert(IS_IN_EL1());
356f14d1886SSoby Mathew 	return gicv3_acknowledge_interrupt_sel1();
357f14d1886SSoby Mathew }
358f14d1886SSoby Mathew 
359f14d1886SSoby Mathew /*
360f14d1886SSoby Mathew  * This functions is used to indicate to the interrupt controller that
361f14d1886SSoby Mathew  * the processing of the interrupt corresponding to the `id` has
362f14d1886SSoby Mathew  * finished.
363f14d1886SSoby Mathew  */
364f14d1886SSoby Mathew void plat_ic_end_of_interrupt(uint32_t id)
365f14d1886SSoby Mathew {
366f14d1886SSoby Mathew 	assert(IS_IN_EL1());
367f14d1886SSoby Mathew 	gicv3_end_of_interrupt_sel1(id);
368f14d1886SSoby Mathew }
369f14d1886SSoby Mathew #endif
370