blob: 446d0addb7b754e9e8d7040a341114d8339951ee [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Manish V Badarkhe173c2962022-05-09 21:55:19 +01002 * Copyright (c) 2015-2022, 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
Claus Pedersen785e66c2022-09-12 22:42:58 +000015#include <platform_def.h>
16
Soby Mathew50f6fe42016-02-01 17:59:22 +000017#include "../common/gic_common_private.h"
Achin Gupta92712a52015-09-03 14:18:02 +010018#include "gicv3_private.h"
19
Achin Gupta92712a52015-09-03 14:18:02 +010020/******************************************************************************
21 * This function marks the core as awake in the re-distributor and
22 * ensures that the interface is active.
23 *****************************************************************************/
24void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base)
25{
26 /*
27 * The WAKER_PS_BIT should be changed to 0
28 * only when WAKER_CA_BIT is 1.
29 */
Antonio Nino Diazca994e72018-08-21 10:02:33 +010030 assert((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U);
Achin Gupta92712a52015-09-03 14:18:02 +010031
32 /* Mark the connected core as awake */
33 gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) & ~WAKER_PS_BIT);
34
35 /* Wait till the WAKER_CA_BIT changes to 0 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010036 while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U) {
37 }
Achin Gupta92712a52015-09-03 14:18:02 +010038}
39
Achin Gupta92712a52015-09-03 14:18:02 +010040/******************************************************************************
41 * This function marks the core as asleep in the re-distributor and ensures
42 * that the interface is quiescent.
43 *****************************************************************************/
44void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base)
45{
46 /* Mark the connected core as asleep */
47 gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) | WAKER_PS_BIT);
48
49 /* Wait till the WAKER_CA_BIT changes to 1 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010050 while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) == 0U) {
51 }
Achin Gupta92712a52015-09-03 14:18:02 +010052}
53
Achin Gupta92712a52015-09-03 14:18:02 +010054/*******************************************************************************
55 * This function probes the Redistributor frames when the driver is initialised
56 * and saves their base addresses. These base addresses are used later to
57 * initialise each Redistributor interface.
58 ******************************************************************************/
59void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
60 unsigned int rdistif_num,
61 uintptr_t gicr_base,
62 mpidr_hash_fn mpidr_to_core_pos)
63{
Soby Mathewa0fedc42016-06-16 14:52:04 +010064 u_register_t mpidr;
Achin Gupta92712a52015-09-03 14:18:02 +010065 unsigned int proc_num;
Antonio Nino Diazca994e72018-08-21 10:02:33 +010066 uint64_t typer_val;
Achin Gupta92712a52015-09-03 14:18:02 +010067 uintptr_t rdistif_base = gicr_base;
68
Antonio Nino Diazca994e72018-08-21 10:02:33 +010069 assert(rdistif_base_addrs != NULL);
Achin Gupta92712a52015-09-03 14:18:02 +010070
71 /*
72 * Iterate over the Redistributor frames. Store the base address of each
73 * frame in the platform provided array. Use the "Processor Number"
74 * field to index into the array if the platform has not provided a hash
75 * function to convert an MPIDR (obtained from the "Affinity Value"
76 * field into a linear index.
77 */
78 do {
79 typer_val = gicr_read_typer(rdistif_base);
Antonio Nino Diazca994e72018-08-21 10:02:33 +010080 if (mpidr_to_core_pos != NULL) {
Achin Gupta92712a52015-09-03 14:18:02 +010081 mpidr = mpidr_from_gicr_typer(typer_val);
82 proc_num = mpidr_to_core_pos(mpidr);
83 } else {
84 proc_num = (typer_val >> TYPER_PROC_NUM_SHIFT) &
85 TYPER_PROC_NUM_MASK;
86 }
Soby Mathewd1463bd2019-01-17 14:57:54 +000087
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010088 if (proc_num < rdistif_num) {
Soby Mathewd1463bd2019-01-17 14:57:54 +000089 rdistif_base_addrs[proc_num] = rdistif_base;
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010090 }
Andre Przywaraf70f4b92021-05-18 15:51:06 +010091 rdistif_base += gicv3_redist_size(typer_val);
Antonio Nino Diazca994e72018-08-21 10:02:33 +010092 } while ((typer_val & TYPER_LAST_BIT) == 0U);
Achin Gupta92712a52015-09-03 14:18:02 +010093}
94
95/*******************************************************************************
Heyi Guo06f85b42021-01-20 18:50:16 +080096 * Helper function to get the maximum SPI INTID + 1.
97 ******************************************************************************/
98unsigned int gicv3_get_spi_limit(uintptr_t gicd_base)
99{
100 unsigned int spi_limit;
101 unsigned int typer_reg = gicd_read_typer(gicd_base);
102
103 /* (maximum SPI INTID + 1) is equal to 32 * (GICD_TYPER.ITLinesNumber+1) */
104 spi_limit = ((typer_reg & TYPER_IT_LINES_NO_MASK) + 1U) << 5;
105
106 /* Filter out special INTIDs 1020-1023 */
107 if (spi_limit > (MAX_SPI_ID + 1U)) {
108 return MAX_SPI_ID + 1U;
109 }
110
111 return spi_limit;
112}
113
Heyi Guo60ce8252021-01-20 18:50:16 +0800114#if GIC_EXT_INTID
115/*******************************************************************************
116 * Helper function to get the maximum ESPI INTID + 1.
117 ******************************************************************************/
118unsigned int gicv3_get_espi_limit(uintptr_t gicd_base)
119{
120 unsigned int typer_reg = gicd_read_typer(gicd_base);
121
122 /* Check if extended SPI range is implemented */
123 if ((typer_reg & TYPER_ESPI) != 0U) {
124 /*
125 * (maximum ESPI INTID + 1) is equal to
126 * 32 * (GICD_TYPER.ESPI_range + 1) + 4096
127 */
128 return ((((typer_reg >> TYPER_ESPI_RANGE_SHIFT) &
129 TYPER_ESPI_RANGE_MASK) + 1U) << 5) + MIN_ESPI_ID;
130 }
131
132 return 0U;
133}
134#endif /* GIC_EXT_INTID */
135
Heyi Guo06f85b42021-01-20 18:50:16 +0800136/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100137 * Helper function to configure the default attributes of (E)SPIs.
Achin Gupta92712a52015-09-03 14:18:02 +0100138 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100139void gicv3_spis_config_defaults(uintptr_t gicd_base)
Achin Gupta92712a52015-09-03 14:18:02 +0100140{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100141 unsigned int i, num_ints;
142#if GIC_EXT_INTID
143 unsigned int num_eints;
144#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100145
Heyi Guo79bc7a72021-01-20 19:05:51 +0800146 num_ints = gicv3_get_spi_limit(gicd_base);
Heyi Guoce380252021-01-21 10:34:00 +0800147 INFO("Maximum SPI INTID supported: %u\n", num_ints - 1);
Heyi Guo0d5d24d2020-05-19 15:41:14 +0800148
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100149 /* Treat all (E)SPIs as G1NS by default. We do 32 at a time. */
150 for (i = MIN_SPI_ID; i < num_ints; i += (1U << IGROUPR_SHIFT)) {
151 gicd_write_igroupr(gicd_base, i, ~0U);
152 }
Achin Gupta92712a52015-09-03 14:18:02 +0100153
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100154#if GIC_EXT_INTID
Heyi Guo79bc7a72021-01-20 19:05:51 +0800155 num_eints = gicv3_get_espi_limit(gicd_base);
156 if (num_eints != 0U) {
Heyi Guoce380252021-01-21 10:34:00 +0800157 INFO("Maximum ESPI INTID supported: %u\n", num_eints - 1);
Achin Gupta92712a52015-09-03 14:18:02 +0100158
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100159 for (i = MIN_ESPI_ID; i < num_eints;
160 i += (1U << IGROUPR_SHIFT)) {
161 gicd_write_igroupr(gicd_base, i, ~0U);
162 }
163 } else {
Heyi Guoce380252021-01-21 10:34:00 +0800164 INFO("ESPI range is not implemented.\n");
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100165 }
166#endif
167
168 /* Setup the default (E)SPI priorities doing four at a time */
169 for (i = MIN_SPI_ID; i < num_ints; i += (1U << IPRIORITYR_SHIFT)) {
170 gicd_write_ipriorityr(gicd_base, i, GICD_IPRIORITYR_DEF_VAL);
171 }
172
173#if GIC_EXT_INTID
174 for (i = MIN_ESPI_ID; i < num_eints;
175 i += (1U << IPRIORITYR_SHIFT)) {
176 gicd_write_ipriorityr(gicd_base, i, GICD_IPRIORITYR_DEF_VAL);
177 }
178#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100179 /*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100180 * Treat all (E)SPIs as level triggered by default, write 16 at a time
Achin Gupta92712a52015-09-03 14:18:02 +0100181 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100182 for (i = MIN_SPI_ID; i < num_ints; i += (1U << ICFGR_SHIFT)) {
183 gicd_write_icfgr(gicd_base, i, 0U);
184 }
185
186#if GIC_EXT_INTID
187 for (i = MIN_ESPI_ID; i < num_eints; i += (1U << ICFGR_SHIFT)) {
188 gicd_write_icfgr(gicd_base, i, 0U);
189 }
190#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100191}
192
Achin Gupta92712a52015-09-03 14:18:02 +0100193/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100194 * Helper function to configure properties of secure (E)SPIs
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100195 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100196unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100197 const interrupt_prop_t *interrupt_props,
198 unsigned int interrupt_props_num)
199{
200 unsigned int i;
201 const interrupt_prop_t *current_prop;
202 unsigned long long gic_affinity_val;
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100203 unsigned int ctlr_enable = 0U;
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100204
205 /* Make sure there's a valid property array */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100206 if (interrupt_props_num > 0U) {
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100207 assert(interrupt_props != NULL);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100208 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100209
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100210 for (i = 0U; i < interrupt_props_num; i++) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100211 current_prop = &interrupt_props[i];
212
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100213 unsigned int intr_num = current_prop->intr_num;
214
215 /* Skip SGI, (E)PPI and LPI interrupts */
216 if (!IS_SPI(intr_num)) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100217 continue;
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100218 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100219
220 /* Configure this interrupt as a secure interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100221 gicd_clr_igroupr(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100222
223 /* Configure this interrupt as G0 or a G1S interrupt */
224 assert((current_prop->intr_grp == INTR_GROUP0) ||
225 (current_prop->intr_grp == INTR_GROUP1S));
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100226
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100227 if (current_prop->intr_grp == INTR_GROUP1S) {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100228 gicd_set_igrpmodr(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100229 ctlr_enable |= CTLR_ENABLE_G1S_BIT;
230 } else {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100231 gicd_clr_igrpmodr(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100232 ctlr_enable |= CTLR_ENABLE_G0_BIT;
233 }
234
235 /* Set interrupt configuration */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100236 gicd_set_icfgr(gicd_base, intr_num, current_prop->intr_cfg);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100237
238 /* Set the priority of this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100239 gicd_set_ipriorityr(gicd_base, intr_num,
240 current_prop->intr_pri);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100241
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100242 /* Target (E)SPIs to the primary CPU */
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100243 gic_affinity_val =
244 gicd_irouter_val_from_mpidr(read_mpidr(), 0U);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100245 gicd_write_irouter(gicd_base, intr_num,
246 gic_affinity_val);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100247
248 /* Enable this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100249 gicd_set_isenabler(gicd_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100250 }
251
252 return ctlr_enable;
253}
254
255/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100256 * Helper function to configure the default attributes of (E)SPIs
Achin Gupta92712a52015-09-03 14:18:02 +0100257 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100258void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base)
Achin Gupta92712a52015-09-03 14:18:02 +0100259{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100260 unsigned int i, ppi_regs_num, regs_num;
Achin Gupta92712a52015-09-03 14:18:02 +0100261
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100262#if GIC_EXT_INTID
263 /* Calculate number of PPI registers */
264 ppi_regs_num = (unsigned int)((gicr_read_typer(gicr_base) >>
265 TYPER_PPI_NUM_SHIFT) & TYPER_PPI_NUM_MASK) + 1;
266 /* All other values except PPInum [0-2] are reserved */
267 if (ppi_regs_num > 3U) {
268 ppi_regs_num = 1U;
269 }
270#else
271 ppi_regs_num = 1U;
272#endif
Achin Gupta92712a52015-09-03 14:18:02 +0100273 /*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100274 * Disable all SGIs (imp. def.)/(E)PPIs before configuring them.
275 * This is a more scalable approach as it avoids clearing
276 * the enable bits in the GICD_CTLR.
Achin Gupta92712a52015-09-03 14:18:02 +0100277 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100278 for (i = 0U; i < ppi_regs_num; ++i) {
279 gicr_write_icenabler(gicr_base, i, ~0U);
280 }
281
282 /* Wait for pending writes to GICR_ICENABLER */
Achin Gupta92712a52015-09-03 14:18:02 +0100283 gicr_wait_for_pending_write(gicr_base);
284
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100285 /* 32 interrupt IDs per GICR_IGROUPR register */
286 for (i = 0U; i < ppi_regs_num; ++i) {
287 /* Treat all SGIs/(E)PPIs as G1NS by default */
288 gicr_write_igroupr(gicr_base, i, ~0U);
289 }
Achin Gupta92712a52015-09-03 14:18:02 +0100290
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100291 /* 4 interrupt IDs per GICR_IPRIORITYR register */
292 regs_num = ppi_regs_num << 3;
293 for (i = 0U; i < regs_num; ++i) {
294 /* Setup the default (E)PPI/SGI priorities doing 4 at a time */
295 gicr_write_ipriorityr(gicr_base, i, GICD_IPRIORITYR_DEF_VAL);
296 }
Achin Gupta92712a52015-09-03 14:18:02 +0100297
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100298 /* 16 interrupt IDs per GICR_ICFGR register */
299 regs_num = ppi_regs_num << 1;
300 for (i = (MIN_PPI_ID >> ICFGR_SHIFT); i < regs_num; ++i) {
301 /* Configure all (E)PPIs as level triggered by default */
302 gicr_write_icfgr(gicr_base, i, 0U);
303 }
Achin Gupta92712a52015-09-03 14:18:02 +0100304}
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100305
306/*******************************************************************************
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100307 * Helper function to configure properties of secure G0 and G1S (E)PPIs and SGIs
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100308 ******************************************************************************/
Daniel Boulby4e83abb2018-05-01 15:15:34 +0100309unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100310 const interrupt_prop_t *interrupt_props,
311 unsigned int interrupt_props_num)
312{
313 unsigned int i;
314 const interrupt_prop_t *current_prop;
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100315 unsigned int ctlr_enable = 0U;
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100316
317 /* Make sure there's a valid property array */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100318 if (interrupt_props_num > 0U) {
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100319 assert(interrupt_props != NULL);
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100320 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100321
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100322 for (i = 0U; i < interrupt_props_num; i++) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100323 current_prop = &interrupt_props[i];
324
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100325 unsigned int intr_num = current_prop->intr_num;
326
327 /* Skip (E)SPI interrupt */
328 if (!IS_SGI_PPI(intr_num)) {
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100329 continue;
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100330 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100331
332 /* Configure this interrupt as a secure interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100333 gicr_clr_igroupr(gicr_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100334
335 /* Configure this interrupt as G0 or a G1S interrupt */
336 assert((current_prop->intr_grp == INTR_GROUP0) ||
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100337 (current_prop->intr_grp == INTR_GROUP1S));
338
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000339 if (current_prop->intr_grp == INTR_GROUP1S) {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100340 gicr_set_igrpmodr(gicr_base, intr_num);
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000341 ctlr_enable |= CTLR_ENABLE_G1S_BIT;
342 } else {
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100343 gicr_clr_igrpmodr(gicr_base, intr_num);
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000344 ctlr_enable |= CTLR_ENABLE_G0_BIT;
345 }
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100346
347 /* Set the priority of this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100348 gicr_set_ipriorityr(gicr_base, intr_num,
349 current_prop->intr_pri);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100350
351 /*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100352 * Set interrupt configuration for (E)PPIs.
353 * Configurations for SGIs 0-15 are ignored.
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100354 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100355 if (intr_num >= MIN_PPI_ID) {
356 gicr_set_icfgr(gicr_base, intr_num,
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100357 current_prop->intr_cfg);
358 }
359
360 /* Enable this interrupt */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100361 gicr_set_isenabler(gicr_base, intr_num);
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100362 }
Jeenu Viswambharan88d8f452017-11-07 08:38:23 +0000363
364 return ctlr_enable;
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +0100365}
Andre Przywara95581b42020-09-07 14:53:58 +0100366
367/**
368 * gicv3_rdistif_get_number_frames() - determine size of GICv3 GICR region
369 * @gicr_frame: base address of the GICR region to check
370 *
371 * This iterates over the GICR_TYPER registers of multiple GICR frames in
372 * a GICR region, to find the instance which has the LAST bit set. For most
373 * systems this corresponds to the number of cores handled by a redistributor,
374 * but there could be disabled cores among them.
375 * It assumes that each GICR region is fully accessible (till the LAST bit
376 * marks the end of the region).
377 * If a platform has multiple GICR regions, this function would need to be
378 * called multiple times, providing the respective GICR base address each time.
379 *
380 * Return: number of valid GICR frames (at least 1, up to PLATFORM_CORE_COUNT)
381 ******************************************************************************/
382unsigned int gicv3_rdistif_get_number_frames(const uintptr_t gicr_frame)
383{
384 uintptr_t rdistif_base = gicr_frame;
385 unsigned int count;
386
Andre Przywaraf70f4b92021-05-18 15:51:06 +0100387 for (count = 1U; count < PLATFORM_CORE_COUNT; count++) {
388 uint64_t typer_val = gicr_read_typer(rdistif_base);
389
390 if ((typer_val & TYPER_LAST_BIT) != 0U) {
Andre Przywara95581b42020-09-07 14:53:58 +0100391 break;
392 }
Andre Przywaraf70f4b92021-05-18 15:51:06 +0100393 rdistif_base += gicv3_redist_size(typer_val);
Andre Przywara95581b42020-09-07 14:53:58 +0100394 }
395
396 return count;
397}
Andre Przywarab8da1c62021-08-24 10:03:57 +0100398
399unsigned int gicv3_get_component_partnum(const uintptr_t gic_frame)
400{
401 unsigned int part_id;
402
403 /*
404 * The lower 8 bits of PIDR0, complemented by the lower 4 bits of
405 * PIDR1 contain a part number identifying the GIC component at a
406 * particular base address.
407 */
408 part_id = mmio_read_32(gic_frame + GICD_PIDR0_GICV3) & 0xff;
409 part_id |= (mmio_read_32(gic_frame + GICD_PIDR1_GICV3) << 8) & 0xf00;
410
411 return part_id;
412}
Manish V Badarkhe173c2962022-05-09 21:55:19 +0100413
414/*******************************************************************************
415 * Helper function to return product ID and revision of GIC
416 * @gicd_base: base address of the GIC distributor
417 * @gic_prod_id: retrieved product id of GIC
418 * @gic_rev: retrieved revision of GIC
419 ******************************************************************************/
420void gicv3_get_component_prodid_rev(const uintptr_t gicd_base,
421 unsigned int *gic_prod_id,
422 uint8_t *gic_rev)
423{
424 unsigned int gicd_iidr;
425 uint8_t gic_variant;
426
427 gicd_iidr = gicd_read_iidr(gicd_base);
428 *gic_prod_id = gicd_iidr >> IIDR_PRODUCT_ID_SHIFT;
429 *gic_prod_id &= IIDR_PRODUCT_ID_MASK;
430
431 gic_variant = gicd_iidr >> IIDR_VARIANT_SHIFT;
432 gic_variant &= IIDR_VARIANT_MASK;
433
434 *gic_rev = gicd_iidr >> IIDR_REV_SHIFT;
435 *gic_rev &= IIDR_REV_MASK;
436
437 /*
438 * pack gic variant and gic_rev in 1 byte
439 * gic_rev = gic_variant[7:4] and gic_rev[0:3]
440 */
441 *gic_rev = *gic_rev | gic_variant << 0x4;
442
443}