blob: ad7ff22d5f915fcffffc97b0a156caeb1b352cc6 [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Heyi Guoc5bd63c2020-05-19 14:01:49 +08002 * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
Achin Gupta92712a52015-09-03 14:18:02 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta92712a52015-09-03 14:18:02 +01005 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <assert.h>
8
Achin Gupta92712a52015-09-03 14:18:02 +01009#include <arch.h>
10#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <common/debug.h>
12#include <common/interrupt_props.h>
13#include <drivers/arm/gic_common.h>
14
Soby Mathew50f6fe42016-02-01 17:59:22 +000015#include "../common/gic_common_private.h"
Achin Gupta92712a52015-09-03 14:18:02 +010016#include "gicv3_private.h"
17
Achin Gupta92712a52015-09-03 14:18:02 +010018/******************************************************************************
19 * This function marks the core as awake in the re-distributor and
20 * ensures that the interface is active.
21 *****************************************************************************/
22void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base)
23{
24 /*
25 * The WAKER_PS_BIT should be changed to 0
26 * only when WAKER_CA_BIT is 1.
27 */
Antonio Nino Diazca994e72018-08-21 10:02:33 +010028 assert((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U);
Achin Gupta92712a52015-09-03 14:18:02 +010029
30 /* Mark the connected core as awake */
31 gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) & ~WAKER_PS_BIT);
32
33 /* Wait till the WAKER_CA_BIT changes to 0 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010034 while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U) {
35 }
Achin Gupta92712a52015-09-03 14:18:02 +010036}
37
Achin Gupta92712a52015-09-03 14:18:02 +010038/******************************************************************************
39 * This function marks the core as asleep in the re-distributor and ensures
40 * that the interface is quiescent.
41 *****************************************************************************/
42void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base)
43{
44 /* Mark the connected core as asleep */
45 gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) | WAKER_PS_BIT);
46
47 /* Wait till the WAKER_CA_BIT changes to 1 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010048 while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) == 0U) {
49 }
Achin Gupta92712a52015-09-03 14:18:02 +010050}
51
Achin Gupta92712a52015-09-03 14:18:02 +010052/*******************************************************************************
53 * This function probes the Redistributor frames when the driver is initialised
54 * and saves their base addresses. These base addresses are used later to
55 * initialise each Redistributor interface.
56 ******************************************************************************/
57void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
58 unsigned int rdistif_num,
59 uintptr_t gicr_base,
60 mpidr_hash_fn mpidr_to_core_pos)
61{
Soby Mathewa0fedc42016-06-16 14:52:04 +010062 u_register_t mpidr;
Achin Gupta92712a52015-09-03 14:18:02 +010063 unsigned int proc_num;
Antonio Nino Diazca994e72018-08-21 10:02:33 +010064 uint64_t typer_val;
Achin Gupta92712a52015-09-03 14:18:02 +010065 uintptr_t rdistif_base = gicr_base;
66
Antonio Nino Diazca994e72018-08-21 10:02:33 +010067 assert(rdistif_base_addrs != NULL);
Achin Gupta92712a52015-09-03 14:18:02 +010068
69 /*
70 * Iterate over the Redistributor frames. Store the base address of each
71 * frame in the platform provided array. Use the "Processor Number"
72 * field to index into the array if the platform has not provided a hash
73 * function to convert an MPIDR (obtained from the "Affinity Value"
74 * field into a linear index.
75 */
76 do {
77 typer_val = gicr_read_typer(rdistif_base);
Antonio Nino Diazca994e72018-08-21 10:02:33 +010078 if (mpidr_to_core_pos != NULL) {
Achin Gupta92712a52015-09-03 14:18:02 +010079 mpidr = mpidr_from_gicr_typer(typer_val);
80 proc_num = mpidr_to_core_pos(mpidr);
81 } else {
82 proc_num = (typer_val >> TYPER_PROC_NUM_SHIFT) &
83 TYPER_PROC_NUM_MASK;
84 }
Soby Mathewd1463bd2019-01-17 14:57:54 +000085
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010086 if (proc_num < rdistif_num) {
Soby Mathewd1463bd2019-01-17 14:57:54 +000087 rdistif_base_addrs[proc_num] = rdistif_base;
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010088 }
Soby Mathewd1463bd2019-01-17 14:57:54 +000089
Antonio Nino Diazca994e72018-08-21 10:02:33 +010090 rdistif_base += (1U << GICR_PCPUBASE_SHIFT);
91 } while ((typer_val & TYPER_LAST_BIT) == 0U);
Achin Gupta92712a52015-09-03 14:18:02 +010092}
93
94/*******************************************************************************
Heyi Guo06f85b42021-01-20 18:50:16 +080095 * Helper function to get the maximum SPI INTID + 1.
96 ******************************************************************************/
97unsigned int gicv3_get_spi_limit(uintptr_t gicd_base)
98{
99 unsigned int spi_limit;
100 unsigned int typer_reg = gicd_read_typer(gicd_base);
101
102 /* (maximum SPI INTID + 1) is equal to 32 * (GICD_TYPER.ITLinesNumber+1) */
103 spi_limit = ((typer_reg & TYPER_IT_LINES_NO_MASK) + 1U) << 5;
104
105 /* Filter out special INTIDs 1020-1023 */
106 if (spi_limit > (MAX_SPI_ID + 1U)) {
107 return MAX_SPI_ID + 1U;
108 }
109
110 return spi_limit;
111}
112
Heyi Guo60ce8252021-01-20 18:50:16 +0800113#if GIC_EXT_INTID
114/*******************************************************************************
115 * Helper function to get the maximum ESPI INTID + 1.
116 ******************************************************************************/
117unsigned int gicv3_get_espi_limit(uintptr_t gicd_base)
118{
119 unsigned int typer_reg = gicd_read_typer(gicd_base);
120
121 /* Check if extended SPI range is implemented */
122 if ((typer_reg & TYPER_ESPI) != 0U) {
123 /*
124 * (maximum ESPI INTID + 1) is equal to
125 * 32 * (GICD_TYPER.ESPI_range + 1) + 4096
126 */
127 return ((((typer_reg >> TYPER_ESPI_RANGE_SHIFT) &
128 TYPER_ESPI_RANGE_MASK) + 1U) << 5) + MIN_ESPI_ID;
129 }
130
131 return 0U;
132}
133#endif /* GIC_EXT_INTID */
134
Heyi Guo06f85b42021-01-20 18:50:16 +0800135/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100136 * Helper function to configure the default attributes of (E)SPIs.
Achin Gupta92712a52015-09-03 14:18:02 +0100137 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100138void gicv3_spis_config_defaults(uintptr_t gicd_base)
Achin Gupta92712a52015-09-03 14:18:02 +0100139{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100140 unsigned int i, num_ints;
141#if GIC_EXT_INTID
142 unsigned int num_eints;
143#endif
144 unsigned int typer_reg = gicd_read_typer(gicd_base);
Achin Gupta92712a52015-09-03 14:18:02 +0100145
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100146 /* Maximum SPI INTID is 32 * (GICD_TYPER.ITLinesNumber + 1) - 1 */
147 num_ints = ((typer_reg & TYPER_IT_LINES_NO_MASK) + 1U) << 5;
Achin Gupta92712a52015-09-03 14:18:02 +0100148
Heyi Guo0d5d24d2020-05-19 15:41:14 +0800149 /*
150 * The GICv3 architecture allows GICD_TYPER.ITLinesNumber to be 31, so
151 * the maximum possible value for num_ints is 1024. Limit the value to
152 * MAX_SPI_ID + 1 to avoid getting wrong address in GICD_OFFSET() macro.
153 */
154 if (num_ints > MAX_SPI_ID + 1U) {
155 num_ints = MAX_SPI_ID + 1U;
156 }
Heyi Guoce380252021-01-21 10:34:00 +0800157 INFO("Maximum SPI INTID supported: %u\n", num_ints - 1);
Heyi Guo0d5d24d2020-05-19 15:41:14 +0800158
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100159 /* Treat all (E)SPIs as G1NS by default. We do 32 at a time. */
160 for (i = MIN_SPI_ID; i < num_ints; i += (1U << IGROUPR_SHIFT)) {
161 gicd_write_igroupr(gicd_base, i, ~0U);
162 }
Achin Gupta92712a52015-09-03 14:18:02 +0100163
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100164#if GIC_EXT_INTID
165 /* Check if extended SPI range is implemented */
166 if ((typer_reg & TYPER_ESPI) != 0U) {
167 /*
168 * Maximum ESPI INTID is 32 * (GICD_TYPER.ESPI_range + 1) + 4095
169 */
170 num_eints = ((((typer_reg >> TYPER_ESPI_RANGE_SHIFT) &
Heyi Guoc5bd63c2020-05-19 14:01:49 +0800171 TYPER_ESPI_RANGE_MASK) + 1U) << 5) + MIN_ESPI_ID;
Heyi Guoce380252021-01-21 10:34:00 +0800172 INFO("Maximum ESPI INTID supported: %u\n", num_eints - 1);
Achin Gupta92712a52015-09-03 14:18:02 +0100173
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100174 for (i = MIN_ESPI_ID; i < num_eints;
175 i += (1U << IGROUPR_SHIFT)) {
176 gicd_write_igroupr(gicd_base, i, ~0U);
177 }
178 } else {
179 num_eints = 0U;
Heyi Guoce380252021-01-21 10:34:00 +0800180 INFO("ESPI range is not implemented.\n");
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100181 }
182#endif
183
184 /* Setup the default (E)SPI priorities doing four at a time */
185 for (i = MIN_SPI_ID; i < num_ints; i += (1U << IPRIORITYR_SHIFT)) {
186 gicd_write_ipriorityr(gicd_base, i, GICD_IPRIORITYR_DEF_VAL);
187 }
188
189#if GIC_EXT_INTID
190 for (i = MIN_ESPI_ID; i < num_eints;
191 i += (1U << IPRIORITYR_SHIFT)) {
192 gicd_write_ipriorityr(gicd_base, i, GICD_IPRIORITYR_DEF_VAL);
193 }
194#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100195 /*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100196 * Treat all (E)SPIs as level triggered by default, write 16 at a time
Achin Gupta92712a52015-09-03 14:18:02 +0100197 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100198 for (i = MIN_SPI_ID; i < num_ints; i += (1U << ICFGR_SHIFT)) {
199 gicd_write_icfgr(gicd_base, i, 0U);
200 }
201
202#if GIC_EXT_INTID
203 for (i = MIN_ESPI_ID; i < num_eints; i += (1U << ICFGR_SHIFT)) {
204 gicd_write_icfgr(gicd_base, i, 0U);
205 }
206#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100207}
208
Achin Gupta92712a52015-09-03 14:18:02 +0100209/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100210 * Helper function to configure properties of secure (E)SPIs
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100211 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100212unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100213 const interrupt_prop_t *interrupt_props,
214 unsigned int interrupt_props_num)
215{
216 unsigned int i;
217 const interrupt_prop_t *current_prop;
218 unsigned long long gic_affinity_val;
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100219 unsigned int ctlr_enable = 0U;
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100220
221 /* Make sure there's a valid property array */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100222 if (interrupt_props_num > 0U) {
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100223 assert(interrupt_props != NULL);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100224 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100225
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100226 for (i = 0U; i < interrupt_props_num; i++) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100227 current_prop = &interrupt_props[i];
228
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100229 unsigned int intr_num = current_prop->intr_num;
230
231 /* Skip SGI, (E)PPI and LPI interrupts */
232 if (!IS_SPI(intr_num)) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100233 continue;
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100234 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100235
236 /* Configure this interrupt as a secure interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100237 gicd_clr_igroupr(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100238
239 /* Configure this interrupt as G0 or a G1S interrupt */
240 assert((current_prop->intr_grp == INTR_GROUP0) ||
241 (current_prop->intr_grp == INTR_GROUP1S));
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100242
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100243 if (current_prop->intr_grp == INTR_GROUP1S) {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100244 gicd_set_igrpmodr(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100245 ctlr_enable |= CTLR_ENABLE_G1S_BIT;
246 } else {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100247 gicd_clr_igrpmodr(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100248 ctlr_enable |= CTLR_ENABLE_G0_BIT;
249 }
250
251 /* Set interrupt configuration */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100252 gicd_set_icfgr(gicd_base, intr_num, current_prop->intr_cfg);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100253
254 /* Set the priority of this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100255 gicd_set_ipriorityr(gicd_base, intr_num,
256 current_prop->intr_pri);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100257
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100258 /* Target (E)SPIs to the primary CPU */
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100259 gic_affinity_val =
260 gicd_irouter_val_from_mpidr(read_mpidr(), 0U);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100261 gicd_write_irouter(gicd_base, intr_num,
262 gic_affinity_val);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100263
264 /* Enable this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100265 gicd_set_isenabler(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100266 }
267
268 return ctlr_enable;
269}
270
271/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100272 * Helper function to configure the default attributes of (E)SPIs
Achin Gupta92712a52015-09-03 14:18:02 +0100273 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100274void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base)
Achin Gupta92712a52015-09-03 14:18:02 +0100275{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100276 unsigned int i, ppi_regs_num, regs_num;
Achin Gupta92712a52015-09-03 14:18:02 +0100277
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100278#if GIC_EXT_INTID
279 /* Calculate number of PPI registers */
280 ppi_regs_num = (unsigned int)((gicr_read_typer(gicr_base) >>
281 TYPER_PPI_NUM_SHIFT) & TYPER_PPI_NUM_MASK) + 1;
282 /* All other values except PPInum [0-2] are reserved */
283 if (ppi_regs_num > 3U) {
284 ppi_regs_num = 1U;
285 }
286#else
287 ppi_regs_num = 1U;
288#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100289 /*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100290 * Disable all SGIs (imp. def.)/(E)PPIs before configuring them.
291 * This is a more scalable approach as it avoids clearing
292 * the enable bits in the GICD_CTLR.
Achin Gupta92712a52015-09-03 14:18:02 +0100293 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100294 for (i = 0U; i < ppi_regs_num; ++i) {
295 gicr_write_icenabler(gicr_base, i, ~0U);
296 }
297
298 /* Wait for pending writes to GICR_ICENABLER */
Achin Gupta92712a52015-09-03 14:18:02 +0100299 gicr_wait_for_pending_write(gicr_base);
300
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100301 /* 32 interrupt IDs per GICR_IGROUPR register */
302 for (i = 0U; i < ppi_regs_num; ++i) {
303 /* Treat all SGIs/(E)PPIs as G1NS by default */
304 gicr_write_igroupr(gicr_base, i, ~0U);
305 }
Achin Gupta92712a52015-09-03 14:18:02 +0100306
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100307 /* 4 interrupt IDs per GICR_IPRIORITYR register */
308 regs_num = ppi_regs_num << 3;
309 for (i = 0U; i < regs_num; ++i) {
310 /* Setup the default (E)PPI/SGI priorities doing 4 at a time */
311 gicr_write_ipriorityr(gicr_base, i, GICD_IPRIORITYR_DEF_VAL);
312 }
Achin Gupta92712a52015-09-03 14:18:02 +0100313
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100314 /* 16 interrupt IDs per GICR_ICFGR register */
315 regs_num = ppi_regs_num << 1;
316 for (i = (MIN_PPI_ID >> ICFGR_SHIFT); i < regs_num; ++i) {
317 /* Configure all (E)PPIs as level triggered by default */
318 gicr_write_icfgr(gicr_base, i, 0U);
319 }
Achin Gupta92712a52015-09-03 14:18:02 +0100320}
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100321
322/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100323 * Helper function to configure properties of secure G0 and G1S (E)PPIs and SGIs
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100324 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100325unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100326 const interrupt_prop_t *interrupt_props,
327 unsigned int interrupt_props_num)
328{
329 unsigned int i;
330 const interrupt_prop_t *current_prop;
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100331 unsigned int ctlr_enable = 0U;
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100332
333 /* Make sure there's a valid property array */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100334 if (interrupt_props_num > 0U) {
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100335 assert(interrupt_props != NULL);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100336 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100337
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100338 for (i = 0U; i < interrupt_props_num; i++) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100339 current_prop = &interrupt_props[i];
340
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100341 unsigned int intr_num = current_prop->intr_num;
342
343 /* Skip (E)SPI interrupt */
344 if (!IS_SGI_PPI(intr_num)) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100345 continue;
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100346 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100347
348 /* Configure this interrupt as a secure interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100349 gicr_clr_igroupr(gicr_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100350
351 /* Configure this interrupt as G0 or a G1S interrupt */
352 assert((current_prop->intr_grp == INTR_GROUP0) ||
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100353 (current_prop->intr_grp == INTR_GROUP1S));
354
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000355 if (current_prop->intr_grp == INTR_GROUP1S) {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100356 gicr_set_igrpmodr(gicr_base, intr_num);
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000357 ctlr_enable |= CTLR_ENABLE_G1S_BIT;
358 } else {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100359 gicr_clr_igrpmodr(gicr_base, intr_num);
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000360 ctlr_enable |= CTLR_ENABLE_G0_BIT;
361 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100362
363 /* Set the priority of this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100364 gicr_set_ipriorityr(gicr_base, intr_num,
365 current_prop->intr_pri);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100366
367 /*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100368 * Set interrupt configuration for (E)PPIs.
369 * Configurations for SGIs 0-15 are ignored.
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100370 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100371 if (intr_num >= MIN_PPI_ID) {
372 gicr_set_icfgr(gicr_base, intr_num,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100373 current_prop->intr_cfg);
374 }
375
376 /* Enable this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100377 gicr_set_isenabler(gicr_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100378 }
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000379
380 return ctlr_enable;
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100381}
Andre Przywara95581b42020-09-07 14:53:58 +0100382
383/**
384 * gicv3_rdistif_get_number_frames() - determine size of GICv3 GICR region
385 * @gicr_frame: base address of the GICR region to check
386 *
387 * This iterates over the GICR_TYPER registers of multiple GICR frames in
388 * a GICR region, to find the instance which has the LAST bit set. For most
389 * systems this corresponds to the number of cores handled by a redistributor,
390 * but there could be disabled cores among them.
391 * It assumes that each GICR region is fully accessible (till the LAST bit
392 * marks the end of the region).
393 * If a platform has multiple GICR regions, this function would need to be
394 * called multiple times, providing the respective GICR base address each time.
395 *
396 * Return: number of valid GICR frames (at least 1, up to PLATFORM_CORE_COUNT)
397 ******************************************************************************/
398unsigned int gicv3_rdistif_get_number_frames(const uintptr_t gicr_frame)
399{
400 uintptr_t rdistif_base = gicr_frame;
401 unsigned int count;
402
403 for (count = 1; count < PLATFORM_CORE_COUNT; count++) {
404 if ((gicr_read_typer(rdistif_base) & TYPER_LAST_BIT) != 0U) {
405 break;
406 }
407 rdistif_base += (1U << GICR_PCPUBASE_SHIFT);
408 }
409
410 return count;
411}