xref: /rk3399_ARM-atf/plat/common/plat_gicv3.c (revision 24a4a0a5ec25e179f2e567a6e13a9b5c87db1b81)
1f14d1886SSoby Mathew /*
2*24a4a0a5SArvind Ram Prakash  * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
3dcb31ff7SFlorian 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>
13885e2683SClaus Pedersen #include <common/debug.h>
1409d40e0eSAntonio Nino Diaz #include <bl31/interrupt_mgmt.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/arm/gic_common.h>
1609d40e0eSAntonio Nino Diaz #include <drivers/arm/gicv3.h>
1709d40e0eSAntonio Nino Diaz #include <lib/cassert.h>
1809d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
1909d40e0eSAntonio Nino Diaz 
203d8256b2SMasahiro Yamada #ifdef IMAGE_BL31
21f14d1886SSoby Mathew 
22f14d1886SSoby Mathew /*
23f14d1886SSoby Mathew  * The following platform GIC functions are weakly defined. They
24f14d1886SSoby Mathew  * provide typical implementations that may be re-used by multiple
25f14d1886SSoby Mathew  * platforms but may also be overridden by a platform if required.
26f14d1886SSoby Mathew  */
27f14d1886SSoby Mathew #pragma weak plat_ic_get_pending_interrupt_id
28f14d1886SSoby Mathew #pragma weak plat_ic_get_pending_interrupt_type
29f14d1886SSoby Mathew #pragma weak plat_ic_acknowledge_interrupt
30f14d1886SSoby Mathew #pragma weak plat_ic_get_interrupt_type
31f14d1886SSoby Mathew #pragma weak plat_ic_end_of_interrupt
32f14d1886SSoby Mathew #pragma weak plat_interrupt_type_to_line
33f14d1886SSoby Mathew 
34eb68ea9bSJeenu Viswambharan #pragma weak plat_ic_get_running_priority
35ca43b55dSJeenu Viswambharan #pragma weak plat_ic_is_spi
36ca43b55dSJeenu Viswambharan #pragma weak plat_ic_is_ppi
37ca43b55dSJeenu Viswambharan #pragma weak plat_ic_is_sgi
38cbd3f370SJeenu Viswambharan #pragma weak plat_ic_get_interrupt_active
39979225f4SJeenu Viswambharan #pragma weak plat_ic_enable_interrupt
40979225f4SJeenu Viswambharan #pragma weak plat_ic_disable_interrupt
41f3a86600SJeenu Viswambharan #pragma weak plat_ic_set_interrupt_priority
4274dce7faSJeenu Viswambharan #pragma weak plat_ic_set_interrupt_type
438db978b5SJeenu Viswambharan #pragma weak plat_ic_raise_el3_sgi
44dcb31ff7SFlorian Lugou #pragma weak plat_ic_raise_ns_sgi
45dcb31ff7SFlorian Lugou #pragma weak plat_ic_raise_s_el1_sgi
46fc529feeSJeenu Viswambharan #pragma weak plat_ic_set_spi_routing
47a2816a16SJeenu Viswambharan #pragma weak plat_ic_set_interrupt_pending
48a2816a16SJeenu Viswambharan #pragma weak plat_ic_clear_interrupt_pending
49eb68ea9bSJeenu Viswambharan 
50f14d1886SSoby Mathew /*
51f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
52f14d1886SSoby Mathew  * the Interrupt controller
53f14d1886SSoby Mathew  */
54f14d1886SSoby Mathew uint32_t plat_ic_get_pending_interrupt_id(void)
55f14d1886SSoby Mathew {
56f14d1886SSoby Mathew 	unsigned int irqnr;
57f14d1886SSoby Mathew 
58f14d1886SSoby Mathew 	assert(IS_IN_EL3());
59f14d1886SSoby Mathew 	irqnr = gicv3_get_pending_interrupt_id();
60e0ced7a9SAntonio Nino Diaz 	return gicv3_is_intr_id_special_identifier(irqnr) ?
61f14d1886SSoby Mathew 				INTR_ID_UNAVAILABLE : irqnr;
62f14d1886SSoby Mathew }
63f14d1886SSoby Mathew 
64f14d1886SSoby Mathew /*
65f14d1886SSoby Mathew  * This function returns the type of the highest priority pending interrupt
66f14d1886SSoby Mathew  * at the Interrupt controller. In the case of GICv3, the Highest Priority
67f14d1886SSoby Mathew  * Pending interrupt system register (`ICC_HPPIR0_EL1`) is read to determine
68f14d1886SSoby Mathew  * the id of the pending interrupt. The type of interrupt depends upon the
69f14d1886SSoby Mathew  * id value as follows.
70f14d1886SSoby Mathew  *   1. id = PENDING_G1S_INTID (1020) is reported as a S-EL1 interrupt
71f14d1886SSoby Mathew  *   2. id = PENDING_G1NS_INTID (1021) is reported as a Non-secure interrupt.
72f14d1886SSoby Mathew  *   3. id = GIC_SPURIOUS_INTERRUPT (1023) is reported as an invalid interrupt
73f14d1886SSoby Mathew  *           type.
74f14d1886SSoby Mathew  *   4. All other interrupt id's are reported as EL3 interrupt.
75f14d1886SSoby Mathew  */
76f14d1886SSoby Mathew uint32_t plat_ic_get_pending_interrupt_type(void)
77f14d1886SSoby Mathew {
78f14d1886SSoby Mathew 	unsigned int irqnr;
79e0ced7a9SAntonio Nino Diaz 	uint32_t type;
80f14d1886SSoby Mathew 
81f14d1886SSoby Mathew 	assert(IS_IN_EL3());
82f14d1886SSoby Mathew 	irqnr = gicv3_get_pending_interrupt_type();
83f14d1886SSoby Mathew 
84f14d1886SSoby Mathew 	switch (irqnr) {
85f14d1886SSoby Mathew 	case PENDING_G1S_INTID:
86e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_S_EL1;
87e0ced7a9SAntonio Nino Diaz 		break;
88f14d1886SSoby Mathew 	case PENDING_G1NS_INTID:
89e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_NS;
90e0ced7a9SAntonio Nino Diaz 		break;
91f14d1886SSoby Mathew 	case GIC_SPURIOUS_INTERRUPT:
92e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_INVAL;
93e0ced7a9SAntonio Nino Diaz 		break;
94f14d1886SSoby Mathew 	default:
95e0ced7a9SAntonio Nino Diaz 		type = INTR_TYPE_EL3;
96e0ced7a9SAntonio Nino Diaz 		break;
97f14d1886SSoby Mathew 	}
98e0ced7a9SAntonio Nino Diaz 
99e0ced7a9SAntonio Nino Diaz 	return type;
100f14d1886SSoby Mathew }
101f14d1886SSoby Mathew 
102f14d1886SSoby Mathew /*
103f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
104f14d1886SSoby Mathew  * the Interrupt controller and indicates to the Interrupt controller
105f14d1886SSoby Mathew  * that the interrupt processing has started.
106f14d1886SSoby Mathew  */
107f14d1886SSoby Mathew uint32_t plat_ic_acknowledge_interrupt(void)
108f14d1886SSoby Mathew {
109f14d1886SSoby Mathew 	assert(IS_IN_EL3());
110f14d1886SSoby Mathew 	return gicv3_acknowledge_interrupt();
111f14d1886SSoby Mathew }
112f14d1886SSoby Mathew 
113f14d1886SSoby Mathew /*
114f14d1886SSoby Mathew  * This function returns the type of the interrupt `id`, depending on how
115632e5ffeSMadhukar Pappireddy  * the interrupt has been configured in the interrupt controller.
116f14d1886SSoby Mathew  */
117f14d1886SSoby Mathew uint32_t plat_ic_get_interrupt_type(uint32_t id)
118f14d1886SSoby Mathew {
119632e5ffeSMadhukar Pappireddy 	unsigned int group;
120632e5ffeSMadhukar Pappireddy 
121f14d1886SSoby Mathew 	assert(IS_IN_EL3());
122632e5ffeSMadhukar Pappireddy 	group = gicv3_get_interrupt_group(id, plat_my_core_pos());
123632e5ffeSMadhukar Pappireddy 
124632e5ffeSMadhukar Pappireddy 	switch (group) {
125632e5ffeSMadhukar Pappireddy 	case INTR_GROUP0:
126632e5ffeSMadhukar Pappireddy 		return INTR_TYPE_EL3;
127632e5ffeSMadhukar Pappireddy 	case INTR_GROUP1S:
128632e5ffeSMadhukar Pappireddy 		return INTR_TYPE_S_EL1;
129632e5ffeSMadhukar Pappireddy 	case INTR_GROUP1NS:
130632e5ffeSMadhukar Pappireddy 		return INTR_TYPE_NS;
131632e5ffeSMadhukar Pappireddy 	default:
132632e5ffeSMadhukar Pappireddy 		assert(false); /* Unreachable */
133632e5ffeSMadhukar Pappireddy 		return INTR_TYPE_EL3;
134632e5ffeSMadhukar Pappireddy 	}
135f14d1886SSoby Mathew }
136f14d1886SSoby Mathew 
137f14d1886SSoby Mathew /*
138f14d1886SSoby Mathew  * This functions is used to indicate to the interrupt controller that
139f14d1886SSoby Mathew  * the processing of the interrupt corresponding to the `id` has
140f14d1886SSoby Mathew  * finished.
141f14d1886SSoby Mathew  */
142f14d1886SSoby Mathew void plat_ic_end_of_interrupt(uint32_t id)
143f14d1886SSoby Mathew {
144f14d1886SSoby Mathew 	assert(IS_IN_EL3());
145f14d1886SSoby Mathew 	gicv3_end_of_interrupt(id);
146f14d1886SSoby Mathew }
147f14d1886SSoby Mathew 
148f14d1886SSoby Mathew /*
149f14d1886SSoby Mathew  * An ARM processor signals interrupt exceptions through the IRQ and FIQ pins.
150f14d1886SSoby Mathew  * The interrupt controller knows which pin/line it uses to signal a type of
151f14d1886SSoby Mathew  * interrupt. It lets the interrupt management framework determine for a type of
152f14d1886SSoby Mathew  * interrupt and security state, which line should be used in the SCR_EL3 to
153f14d1886SSoby Mathew  * control its routing to EL3. The interrupt line is represented as the bit
154f14d1886SSoby Mathew  * position of the IRQ or FIQ bit in the SCR_EL3.
155f14d1886SSoby Mathew  */
156f14d1886SSoby Mathew uint32_t plat_interrupt_type_to_line(uint32_t type,
157f14d1886SSoby Mathew 				uint32_t security_state)
158f14d1886SSoby Mathew {
159e0ced7a9SAntonio Nino Diaz 	assert((type == INTR_TYPE_S_EL1) ||
160e0ced7a9SAntonio Nino Diaz 	       (type == INTR_TYPE_EL3) ||
161e0ced7a9SAntonio Nino Diaz 	       (type == INTR_TYPE_NS));
162f14d1886SSoby Mathew 
163f14d1886SSoby Mathew 	assert(sec_state_is_valid(security_state));
164f14d1886SSoby Mathew 	assert(IS_IN_EL3());
165f14d1886SSoby Mathew 
166f14d1886SSoby Mathew 	switch (type) {
167f14d1886SSoby Mathew 	case INTR_TYPE_S_EL1:
168f14d1886SSoby Mathew 		/*
169f14d1886SSoby Mathew 		 * The S-EL1 interrupts are signaled as IRQ in S-EL0/1 contexts
170f14d1886SSoby Mathew 		 * and as FIQ in the NS-EL0/1/2 contexts
171f14d1886SSoby Mathew 		 */
172f14d1886SSoby Mathew 		if (security_state == SECURE)
173f14d1886SSoby Mathew 			return __builtin_ctz(SCR_IRQ_BIT);
174f14d1886SSoby Mathew 		else
175f14d1886SSoby Mathew 			return __builtin_ctz(SCR_FIQ_BIT);
176a08a2014SDaniel Boulby 		assert(0); /* Unreachable */
177f14d1886SSoby Mathew 	case INTR_TYPE_NS:
178f14d1886SSoby Mathew 		/*
179f14d1886SSoby Mathew 		 * The Non secure interrupts will be signaled as FIQ in S-EL0/1
180f14d1886SSoby Mathew 		 * contexts and as IRQ in the NS-EL0/1/2 contexts.
181f14d1886SSoby Mathew 		 */
182f14d1886SSoby Mathew 		if (security_state == SECURE)
183f14d1886SSoby Mathew 			return __builtin_ctz(SCR_FIQ_BIT);
184f14d1886SSoby Mathew 		else
185f14d1886SSoby Mathew 			return __builtin_ctz(SCR_IRQ_BIT);
186a08a2014SDaniel Boulby 		assert(0); /* Unreachable */
187f14d1886SSoby Mathew 	case INTR_TYPE_EL3:
188f14d1886SSoby Mathew 		/*
189f14d1886SSoby Mathew 		 * The EL3 interrupts are signaled as FIQ in both S-EL0/1 and
190f14d1886SSoby Mathew 		 * NS-EL0/1/2 contexts
191f14d1886SSoby Mathew 		 */
192f14d1886SSoby Mathew 		return __builtin_ctz(SCR_FIQ_BIT);
1938ae0df93SJonathan Wright 	default:
1948ae0df93SJonathan Wright 		panic();
195f14d1886SSoby Mathew 	}
196f14d1886SSoby Mathew }
197eb68ea9bSJeenu Viswambharan 
198eb68ea9bSJeenu Viswambharan unsigned int plat_ic_get_running_priority(void)
199eb68ea9bSJeenu Viswambharan {
200eb68ea9bSJeenu Viswambharan 	return gicv3_get_running_priority();
201eb68ea9bSJeenu Viswambharan }
202eb68ea9bSJeenu Viswambharan 
203ca43b55dSJeenu Viswambharan int plat_ic_is_spi(unsigned int id)
204ca43b55dSJeenu Viswambharan {
205ca43b55dSJeenu Viswambharan 	return (id >= MIN_SPI_ID) && (id <= MAX_SPI_ID);
206ca43b55dSJeenu Viswambharan }
207ca43b55dSJeenu Viswambharan 
208ca43b55dSJeenu Viswambharan int plat_ic_is_ppi(unsigned int id)
209ca43b55dSJeenu Viswambharan {
210ca43b55dSJeenu Viswambharan 	return (id >= MIN_PPI_ID) && (id < MIN_SPI_ID);
211ca43b55dSJeenu Viswambharan }
212ca43b55dSJeenu Viswambharan 
213ca43b55dSJeenu Viswambharan int plat_ic_is_sgi(unsigned int id)
214ca43b55dSJeenu Viswambharan {
215ca43b55dSJeenu Viswambharan 	return (id >= MIN_SGI_ID) && (id < MIN_PPI_ID);
216ca43b55dSJeenu Viswambharan }
217cbd3f370SJeenu Viswambharan 
218cbd3f370SJeenu Viswambharan unsigned int plat_ic_get_interrupt_active(unsigned int id)
219cbd3f370SJeenu Viswambharan {
220cbd3f370SJeenu Viswambharan 	return gicv3_get_interrupt_active(id, plat_my_core_pos());
221cbd3f370SJeenu Viswambharan }
222979225f4SJeenu Viswambharan 
223979225f4SJeenu Viswambharan void plat_ic_enable_interrupt(unsigned int id)
224979225f4SJeenu Viswambharan {
225979225f4SJeenu Viswambharan 	gicv3_enable_interrupt(id, plat_my_core_pos());
226979225f4SJeenu Viswambharan }
227979225f4SJeenu Viswambharan 
228979225f4SJeenu Viswambharan void plat_ic_disable_interrupt(unsigned int id)
229979225f4SJeenu Viswambharan {
230979225f4SJeenu Viswambharan 	gicv3_disable_interrupt(id, plat_my_core_pos());
231979225f4SJeenu Viswambharan }
232f3a86600SJeenu Viswambharan 
233f3a86600SJeenu Viswambharan void plat_ic_set_interrupt_priority(unsigned int id, unsigned int priority)
234f3a86600SJeenu Viswambharan {
235f3a86600SJeenu Viswambharan 	gicv3_set_interrupt_priority(id, plat_my_core_pos(), priority);
236f3a86600SJeenu Viswambharan }
23774dce7faSJeenu Viswambharan 
2381f6bb41dSMadhukar Pappireddy bool plat_ic_has_interrupt_type(unsigned int type)
23974dce7faSJeenu Viswambharan {
24007f867b1SMadhukar Pappireddy 	if ((type == INTR_TYPE_EL3) || (type == INTR_TYPE_S_EL1) ||
24107f867b1SMadhukar Pappireddy 			(type == INTR_TYPE_NS)) {
2421f6bb41dSMadhukar Pappireddy 		return true;
24374dce7faSJeenu Viswambharan 	}
24474dce7faSJeenu Viswambharan 
2451f6bb41dSMadhukar Pappireddy 	return false;
24607f867b1SMadhukar Pappireddy }
24707f867b1SMadhukar Pappireddy 
24874dce7faSJeenu Viswambharan void plat_ic_set_interrupt_type(unsigned int id, unsigned int type)
24974dce7faSJeenu Viswambharan {
250632e5ffeSMadhukar Pappireddy 	unsigned int group;
251632e5ffeSMadhukar Pappireddy 
252632e5ffeSMadhukar Pappireddy 	switch (type) {
253632e5ffeSMadhukar Pappireddy 	case INTR_TYPE_EL3:
254632e5ffeSMadhukar Pappireddy 		group = INTR_GROUP0;
255632e5ffeSMadhukar Pappireddy 		break;
256632e5ffeSMadhukar Pappireddy 	case INTR_TYPE_S_EL1:
257632e5ffeSMadhukar Pappireddy 		group = INTR_GROUP1S;
258632e5ffeSMadhukar Pappireddy 		break;
259632e5ffeSMadhukar Pappireddy 	case INTR_TYPE_NS:
260632e5ffeSMadhukar Pappireddy 		group = INTR_GROUP1NS;
261632e5ffeSMadhukar Pappireddy 		break;
262632e5ffeSMadhukar Pappireddy 	default:
263632e5ffeSMadhukar Pappireddy 		assert(false); /* Unreachable */
264632e5ffeSMadhukar Pappireddy 		group = INTR_GROUP0;
265632e5ffeSMadhukar Pappireddy 		break;
266632e5ffeSMadhukar Pappireddy 	}
267632e5ffeSMadhukar Pappireddy 
268632e5ffeSMadhukar Pappireddy 	gicv3_set_interrupt_group(id, plat_my_core_pos(), group);
26974dce7faSJeenu Viswambharan }
2708db978b5SJeenu Viswambharan 
2718db978b5SJeenu Viswambharan void plat_ic_raise_el3_sgi(int sgi_num, u_register_t target)
2728db978b5SJeenu Viswambharan {
2738db978b5SJeenu Viswambharan 	/* Target must be a valid MPIDR in the system */
2748db978b5SJeenu Viswambharan 	assert(plat_core_pos_by_mpidr(target) >= 0);
2758db978b5SJeenu Viswambharan 
2768db978b5SJeenu Viswambharan 	/* Verify that this is a secure EL3 SGI */
277e0ced7a9SAntonio Nino Diaz 	assert(plat_ic_get_interrupt_type((unsigned int)sgi_num) ==
278e0ced7a9SAntonio Nino Diaz 					  INTR_TYPE_EL3);
2798db978b5SJeenu Viswambharan 
280dcb31ff7SFlorian Lugou 	gicv3_raise_sgi((unsigned int)sgi_num, GICV3_G0, target);
281dcb31ff7SFlorian Lugou }
282dcb31ff7SFlorian Lugou 
283dcb31ff7SFlorian Lugou void plat_ic_raise_ns_sgi(int sgi_num, u_register_t target)
284dcb31ff7SFlorian Lugou {
285dcb31ff7SFlorian Lugou 	/* Target must be a valid MPIDR in the system */
286dcb31ff7SFlorian Lugou 	assert(plat_core_pos_by_mpidr(target) >= 0);
287dcb31ff7SFlorian Lugou 
288dcb31ff7SFlorian Lugou 	/* Verify that this is a non-secure SGI */
289dcb31ff7SFlorian Lugou 	assert(plat_ic_get_interrupt_type((unsigned int)sgi_num) ==
290dcb31ff7SFlorian Lugou 					  INTR_TYPE_NS);
291dcb31ff7SFlorian Lugou 
292dcb31ff7SFlorian Lugou 	gicv3_raise_sgi((unsigned int)sgi_num, GICV3_G1NS, target);
293dcb31ff7SFlorian Lugou }
294dcb31ff7SFlorian Lugou 
295dcb31ff7SFlorian Lugou void plat_ic_raise_s_el1_sgi(int sgi_num, u_register_t target)
296dcb31ff7SFlorian Lugou {
297dcb31ff7SFlorian Lugou 	/* Target must be a valid MPIDR in the system */
298dcb31ff7SFlorian Lugou 	assert(plat_core_pos_by_mpidr(target) >= 0);
299dcb31ff7SFlorian Lugou 
300dcb31ff7SFlorian Lugou 	/* Verify that this is a secure EL1 SGI */
301dcb31ff7SFlorian Lugou 	assert(plat_ic_get_interrupt_type((unsigned int)sgi_num) ==
302dcb31ff7SFlorian Lugou 					  INTR_TYPE_S_EL1);
303dcb31ff7SFlorian Lugou 
304dcb31ff7SFlorian Lugou 	gicv3_raise_sgi((unsigned int)sgi_num, GICV3_G1S, target);
3058db978b5SJeenu Viswambharan }
306fc529feeSJeenu Viswambharan 
307fc529feeSJeenu Viswambharan void plat_ic_set_spi_routing(unsigned int id, unsigned int routing_mode,
308fc529feeSJeenu Viswambharan 		u_register_t mpidr)
309fc529feeSJeenu Viswambharan {
310fc529feeSJeenu Viswambharan 	unsigned int irm = 0;
311fc529feeSJeenu Viswambharan 
312fc529feeSJeenu Viswambharan 	switch (routing_mode) {
313fc529feeSJeenu Viswambharan 	case INTR_ROUTING_MODE_PE:
314fc529feeSJeenu Viswambharan 		assert(plat_core_pos_by_mpidr(mpidr) >= 0);
315fc529feeSJeenu Viswambharan 		irm = GICV3_IRM_PE;
316fc529feeSJeenu Viswambharan 		break;
317fc529feeSJeenu Viswambharan 	case INTR_ROUTING_MODE_ANY:
318fc529feeSJeenu Viswambharan 		irm = GICV3_IRM_ANY;
319fc529feeSJeenu Viswambharan 		break;
320fc529feeSJeenu Viswambharan 	default:
321a08a2014SDaniel Boulby 		assert(0); /* Unreachable */
322649c48f5SJonathan Wright 		break;
323fc529feeSJeenu Viswambharan 	}
324fc529feeSJeenu Viswambharan 
325fc529feeSJeenu Viswambharan 	gicv3_set_spi_routing(id, irm, mpidr);
326fc529feeSJeenu Viswambharan }
327a2816a16SJeenu Viswambharan 
328a2816a16SJeenu Viswambharan void plat_ic_set_interrupt_pending(unsigned int id)
329a2816a16SJeenu Viswambharan {
330a2816a16SJeenu Viswambharan 	/* Disallow setting SGIs pending */
331a2816a16SJeenu Viswambharan 	assert(id >= MIN_PPI_ID);
332a2816a16SJeenu Viswambharan 	gicv3_set_interrupt_pending(id, plat_my_core_pos());
333a2816a16SJeenu Viswambharan }
334a2816a16SJeenu Viswambharan 
335a2816a16SJeenu Viswambharan void plat_ic_clear_interrupt_pending(unsigned int id)
336a2816a16SJeenu Viswambharan {
337a2816a16SJeenu Viswambharan 	/* Disallow setting SGIs pending */
338a2816a16SJeenu Viswambharan 	assert(id >= MIN_PPI_ID);
339a2816a16SJeenu Viswambharan 	gicv3_clear_interrupt_pending(id, plat_my_core_pos());
340a2816a16SJeenu Viswambharan }
341d55a4450SJeenu Viswambharan 
342d55a4450SJeenu Viswambharan unsigned int plat_ic_set_priority_mask(unsigned int mask)
343d55a4450SJeenu Viswambharan {
344d55a4450SJeenu Viswambharan 	return gicv3_set_pmr(mask);
345d55a4450SJeenu Viswambharan }
3464ee8d0beSJeenu Viswambharan 
347*24a4a0a5SArvind Ram Prakash unsigned int plat_ic_deactivate_priority(unsigned int mask)
348*24a4a0a5SArvind Ram Prakash {
349*24a4a0a5SArvind Ram Prakash 	return gicv3_deactivate_priority(mask);
350*24a4a0a5SArvind Ram Prakash }
351*24a4a0a5SArvind Ram Prakash 
3524ee8d0beSJeenu Viswambharan unsigned int plat_ic_get_interrupt_id(unsigned int raw)
3534ee8d0beSJeenu Viswambharan {
354e0ced7a9SAntonio Nino Diaz 	unsigned int id = raw & INT_ID_MASK;
3554ee8d0beSJeenu Viswambharan 
356e0ced7a9SAntonio Nino Diaz 	return gicv3_is_intr_id_special_identifier(id) ?
357e0ced7a9SAntonio Nino Diaz 			INTR_ID_UNAVAILABLE : id;
3584ee8d0beSJeenu Viswambharan }
359f14d1886SSoby Mathew #endif
3603d8256b2SMasahiro Yamada #ifdef IMAGE_BL32
361f14d1886SSoby Mathew 
362f14d1886SSoby Mathew #pragma weak plat_ic_get_pending_interrupt_id
363f14d1886SSoby Mathew #pragma weak plat_ic_acknowledge_interrupt
364f14d1886SSoby Mathew #pragma weak plat_ic_end_of_interrupt
365f14d1886SSoby Mathew 
366877cf3ffSSoby Mathew /* In AArch32, the secure group1 interrupts are targeted to Secure PL1 */
367402b3cf8SJulius Werner #ifndef __aarch64__
368877cf3ffSSoby Mathew #define IS_IN_EL1()	IS_IN_SECURE()
369877cf3ffSSoby Mathew #endif
370877cf3ffSSoby Mathew 
371f14d1886SSoby Mathew /*
372f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
373f14d1886SSoby Mathew  * the Interrupt controller
374f14d1886SSoby Mathew  */
375f14d1886SSoby Mathew uint32_t plat_ic_get_pending_interrupt_id(void)
376f14d1886SSoby Mathew {
377f14d1886SSoby Mathew 	unsigned int irqnr;
378f14d1886SSoby Mathew 
379f14d1886SSoby Mathew 	assert(IS_IN_EL1());
380f14d1886SSoby Mathew 	irqnr = gicv3_get_pending_interrupt_id_sel1();
381f14d1886SSoby Mathew 	return (irqnr == GIC_SPURIOUS_INTERRUPT) ?
382f14d1886SSoby Mathew 				INTR_ID_UNAVAILABLE : irqnr;
383f14d1886SSoby Mathew }
384f14d1886SSoby Mathew 
385f14d1886SSoby Mathew /*
386f14d1886SSoby Mathew  * This function returns the highest priority pending interrupt at
387f14d1886SSoby Mathew  * the Interrupt controller and indicates to the Interrupt controller
388f14d1886SSoby Mathew  * that the interrupt processing has started.
389f14d1886SSoby Mathew  */
390f14d1886SSoby Mathew uint32_t plat_ic_acknowledge_interrupt(void)
391f14d1886SSoby Mathew {
392f14d1886SSoby Mathew 	assert(IS_IN_EL1());
393f14d1886SSoby Mathew 	return gicv3_acknowledge_interrupt_sel1();
394f14d1886SSoby Mathew }
395f14d1886SSoby Mathew 
396f14d1886SSoby Mathew /*
397f14d1886SSoby Mathew  * This functions is used to indicate to the interrupt controller that
398f14d1886SSoby Mathew  * the processing of the interrupt corresponding to the `id` has
399f14d1886SSoby Mathew  * finished.
400f14d1886SSoby Mathew  */
401f14d1886SSoby Mathew void plat_ic_end_of_interrupt(uint32_t id)
402f14d1886SSoby Mathew {
403f14d1886SSoby Mathew 	assert(IS_IN_EL1());
404f14d1886SSoby Mathew 	gicv3_end_of_interrupt_sel1(id);
405f14d1886SSoby Mathew }
406f14d1886SSoby Mathew #endif
407