Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 173c296 | 2022-05-09 21:55:19 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved. |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 3 | * Copyright (c) 2023, NVIDIA Corporation. All rights reserved. |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 4 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <assert.h> |
| 9 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 10 | #include <arch.h> |
| 11 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <common/debug.h> |
| 13 | #include <common/interrupt_props.h> |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 14 | #include <drivers/arm/gic600_multichip.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <drivers/arm/gicv3.h> |
| 16 | #include <lib/spinlock.h> |
Channagoud kadabi | a037d97 | 2022-11-29 16:03:47 -0800 | [diff] [blame] | 17 | #include <plat/common/platform.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 18 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 19 | #include "gicv3_private.h" |
| 20 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 21 | const gicv3_driver_data_t *gicv3_driver_data; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 22 | |
Jeenu Viswambharan | 76647d5 | 2016-12-09 11:03:15 +0000 | [diff] [blame] | 23 | /* |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 24 | * Spinlock to guard registers needing read-modify-write. APIs protected by this |
| 25 | * spinlock are used either at boot time (when only a single CPU is active), or |
| 26 | * when the system is fully coherent. |
| 27 | */ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 28 | static spinlock_t gic_lock; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 29 | |
| 30 | /* |
Jeenu Viswambharan | 76647d5 | 2016-12-09 11:03:15 +0000 | [diff] [blame] | 31 | * Redistributor power operations are weakly bound so that they can be |
| 32 | * overridden |
| 33 | */ |
| 34 | #pragma weak gicv3_rdistif_off |
| 35 | #pragma weak gicv3_rdistif_on |
| 36 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 37 | /* Check interrupt ID for SGI/(E)PPI and (E)SPIs */ |
| 38 | static bool is_sgi_ppi(unsigned int id); |
| 39 | |
| 40 | /* |
| 41 | * Helper macros to save and restore GICR and GICD registers |
| 42 | * corresponding to their numbers to and from the context |
| 43 | */ |
| 44 | #define RESTORE_GICR_REG(base, ctx, name, i) \ |
| 45 | gicr_write_##name((base), (i), (ctx)->gicr_##name[(i)]) |
| 46 | |
| 47 | #define SAVE_GICR_REG(base, ctx, name, i) \ |
| 48 | (ctx)->gicr_##name[(i)] = gicr_read_##name((base), (i)) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 49 | |
| 50 | /* Helper macros to save and restore GICD registers to and from the context */ |
| 51 | #define RESTORE_GICD_REGS(base, ctx, intr_num, reg, REG) \ |
| 52 | do { \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 53 | for (unsigned int int_id = MIN_SPI_ID; int_id < (intr_num);\ |
| 54 | int_id += (1U << REG##R_SHIFT)) { \ |
| 55 | gicd_write_##reg((base), int_id, \ |
| 56 | (ctx)->gicd_##reg[(int_id - MIN_SPI_ID) >> \ |
| 57 | REG##R_SHIFT]); \ |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 58 | } \ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 59 | } while (false) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 60 | |
| 61 | #define SAVE_GICD_REGS(base, ctx, intr_num, reg, REG) \ |
| 62 | do { \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 63 | for (unsigned int int_id = MIN_SPI_ID; int_id < (intr_num);\ |
| 64 | int_id += (1U << REG##R_SHIFT)) { \ |
| 65 | (ctx)->gicd_##reg[(int_id - MIN_SPI_ID) >> \ |
| 66 | REG##R_SHIFT] = gicd_read_##reg((base), int_id); \ |
| 67 | } \ |
| 68 | } while (false) |
| 69 | |
| 70 | #if GIC_EXT_INTID |
| 71 | #define RESTORE_GICD_EREGS(base, ctx, intr_num, reg, REG) \ |
| 72 | do { \ |
| 73 | for (unsigned int int_id = MIN_ESPI_ID; int_id < (intr_num);\ |
| 74 | int_id += (1U << REG##R_SHIFT)) { \ |
| 75 | gicd_write_##reg((base), int_id, \ |
Heyi Guo | efa2107 | 2021-01-14 22:16:18 +0800 | [diff] [blame] | 76 | (ctx)->gicd_##reg[(int_id - (MIN_ESPI_ID - \ |
| 77 | round_up(TOTAL_SPI_INTR_NUM, 1U << REG##R_SHIFT)))\ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 78 | >> REG##R_SHIFT]); \ |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 79 | } \ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 80 | } while (false) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 81 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 82 | #define SAVE_GICD_EREGS(base, ctx, intr_num, reg, REG) \ |
| 83 | do { \ |
| 84 | for (unsigned int int_id = MIN_ESPI_ID; int_id < (intr_num);\ |
| 85 | int_id += (1U << REG##R_SHIFT)) { \ |
Heyi Guo | efa2107 | 2021-01-14 22:16:18 +0800 | [diff] [blame] | 86 | (ctx)->gicd_##reg[(int_id - (MIN_ESPI_ID - \ |
| 87 | round_up(TOTAL_SPI_INTR_NUM, 1U << REG##R_SHIFT)))\ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 88 | >> REG##R_SHIFT] = gicd_read_##reg((base), int_id);\ |
| 89 | } \ |
| 90 | } while (false) |
| 91 | #else |
| 92 | #define SAVE_GICD_EREGS(base, ctx, intr_num, reg, REG) |
| 93 | #define RESTORE_GICD_EREGS(base, ctx, intr_num, reg, REG) |
| 94 | #endif /* GIC_EXT_INTID */ |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 95 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 96 | /******************************************************************************* |
| 97 | * This function initialises the ARM GICv3 driver in EL3 with provided platform |
| 98 | * inputs. |
| 99 | ******************************************************************************/ |
Daniel Boulby | 844b487 | 2018-09-18 13:36:39 +0100 | [diff] [blame] | 100 | void __init gicv3_driver_init(const gicv3_driver_data_t *plat_driver_data) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 101 | { |
| 102 | unsigned int gic_version; |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 103 | unsigned int gicv2_compat; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 104 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 105 | assert(plat_driver_data != NULL); |
| 106 | assert(plat_driver_data->gicd_base != 0U); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 107 | assert(plat_driver_data->rdistif_num != 0U); |
| 108 | assert(plat_driver_data->rdistif_base_addrs != NULL); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 109 | |
| 110 | assert(IS_IN_EL3()); |
| 111 | |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 112 | assert((plat_driver_data->interrupt_props_num != 0U) ? |
| 113 | (plat_driver_data->interrupt_props != NULL) : 1); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 114 | |
| 115 | /* Check for system register support */ |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 116 | #ifndef __aarch64__ |
| 117 | assert((read_id_pfr1() & |
| 118 | (ID_PFR1_GIC_MASK << ID_PFR1_GIC_SHIFT)) != 0U); |
| 119 | #else |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 120 | assert((read_id_aa64pfr0_el1() & |
| 121 | (ID_AA64PFR0_GIC_MASK << ID_AA64PFR0_GIC_SHIFT)) != 0U); |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 122 | #endif /* !__aarch64__ */ |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 123 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 124 | gic_version = gicd_read_pidr2(plat_driver_data->gicd_base); |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 125 | gic_version >>= PIDR2_ARCH_REV_SHIFT; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 126 | gic_version &= PIDR2_ARCH_REV_MASK; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 127 | |
Alexei Fedorov | 1970593 | 2020-04-06 19:00:35 +0100 | [diff] [blame] | 128 | /* Check GIC version */ |
Andre Przywara | f70f4b9 | 2021-05-18 15:51:06 +0100 | [diff] [blame] | 129 | #if !GIC_ENABLE_V4_EXTN |
Alexei Fedorov | 1970593 | 2020-04-06 19:00:35 +0100 | [diff] [blame] | 130 | assert(gic_version == ARCH_REV_GICV3); |
| 131 | #endif |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 132 | /* |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 133 | * Find out whether the GIC supports the GICv2 compatibility mode. |
| 134 | * The ARE_S bit resets to 0 if supported |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 135 | */ |
| 136 | gicv2_compat = gicd_read_ctlr(plat_driver_data->gicd_base); |
| 137 | gicv2_compat >>= CTLR_ARE_S_SHIFT; |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 138 | gicv2_compat = gicv2_compat & CTLR_ARE_S_MASK; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 139 | |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 140 | if (plat_driver_data->gicr_base != 0U) { |
| 141 | /* |
| 142 | * Find the base address of each implemented Redistributor interface. |
| 143 | * The number of interfaces should be equal to the number of CPUs in the |
| 144 | * system. The memory for saving these addresses has to be allocated by |
| 145 | * the platform port |
| 146 | */ |
| 147 | gicv3_rdistif_base_addrs_probe(plat_driver_data->rdistif_base_addrs, |
| 148 | plat_driver_data->rdistif_num, |
| 149 | plat_driver_data->gicr_base, |
| 150 | plat_driver_data->mpidr_to_core_pos); |
| 151 | #if !HW_ASSISTED_COHERENCY |
| 152 | /* |
| 153 | * Flush the rdistif_base_addrs[] contents linked to the GICv3 driver. |
| 154 | */ |
| 155 | flush_dcache_range((uintptr_t)(plat_driver_data->rdistif_base_addrs), |
| 156 | plat_driver_data->rdistif_num * |
| 157 | sizeof(*(plat_driver_data->rdistif_base_addrs))); |
| 158 | #endif |
| 159 | } |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 160 | gicv3_driver_data = plat_driver_data; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 161 | |
Soby Mathew | 7264513 | 2017-02-14 10:11:52 +0000 | [diff] [blame] | 162 | /* |
| 163 | * The GIC driver data is initialized by the primary CPU with caches |
| 164 | * enabled. When the secondary CPU boots up, it initializes the |
| 165 | * GICC/GICR interface with the caches disabled. Hence flush the |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 166 | * driver data to ensure coherency. This is not required if the |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 167 | * platform has HW_ASSISTED_COHERENCY enabled. |
Soby Mathew | 7264513 | 2017-02-14 10:11:52 +0000 | [diff] [blame] | 168 | */ |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 169 | #if !HW_ASSISTED_COHERENCY |
| 170 | flush_dcache_range((uintptr_t)&gicv3_driver_data, |
| 171 | sizeof(gicv3_driver_data)); |
| 172 | flush_dcache_range((uintptr_t)gicv3_driver_data, |
| 173 | sizeof(*gicv3_driver_data)); |
Soby Mathew | 7264513 | 2017-02-14 10:11:52 +0000 | [diff] [blame] | 174 | #endif |
Manish V Badarkhe | 173c296 | 2022-05-09 21:55:19 +0100 | [diff] [blame] | 175 | gicv3_check_erratas_applies(plat_driver_data->gicd_base); |
| 176 | |
Alexei Fedorov | 1970593 | 2020-04-06 19:00:35 +0100 | [diff] [blame] | 177 | INFO("GICv%u with%s legacy support detected.\n", gic_version, |
| 178 | (gicv2_compat == 0U) ? "" : "out"); |
| 179 | INFO("ARM GICv%u driver initialized in EL3\n", gic_version); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /******************************************************************************* |
| 183 | * This function initialises the GIC distributor interface based upon the data |
| 184 | * provided by the platform while initialising the driver. |
| 185 | ******************************************************************************/ |
Daniel Boulby | 844b487 | 2018-09-18 13:36:39 +0100 | [diff] [blame] | 186 | void __init gicv3_distif_init(void) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 187 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 188 | unsigned int bitmap; |
Yatharth Kochar | 3f00a89 | 2016-09-06 11:48:05 +0100 | [diff] [blame] | 189 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 190 | assert(gicv3_driver_data != NULL); |
| 191 | assert(gicv3_driver_data->gicd_base != 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 192 | |
| 193 | assert(IS_IN_EL3()); |
| 194 | |
| 195 | /* |
| 196 | * Clear the "enable" bits for G0/G1S/G1NS interrupts before configuring |
| 197 | * the ARE_S bit. The Distributor might generate a system error |
| 198 | * otherwise. |
| 199 | */ |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 200 | gicd_clr_ctlr(gicv3_driver_data->gicd_base, |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 201 | CTLR_ENABLE_G0_BIT | |
| 202 | CTLR_ENABLE_G1S_BIT | |
| 203 | CTLR_ENABLE_G1NS_BIT, |
| 204 | RWP_TRUE); |
| 205 | |
| 206 | /* Set the ARE_S and ARE_NS bit now that interrupts have been disabled */ |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 207 | gicd_set_ctlr(gicv3_driver_data->gicd_base, |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 208 | CTLR_ARE_S_BIT | CTLR_ARE_NS_BIT, RWP_TRUE); |
| 209 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 210 | /* Set the default attribute of all (E)SPIs */ |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 211 | gicv3_spis_config_defaults(gicv3_driver_data->gicd_base); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 212 | |
Antonio Nino Diaz | 29b9f5b | 2018-09-24 17:23:24 +0100 | [diff] [blame] | 213 | bitmap = gicv3_secure_spis_config_props( |
| 214 | gicv3_driver_data->gicd_base, |
| 215 | gicv3_driver_data->interrupt_props, |
| 216 | gicv3_driver_data->interrupt_props_num); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 217 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 218 | /* Enable the secure (E)SPIs now that they have been configured */ |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 219 | gicd_set_ctlr(gicv3_driver_data->gicd_base, bitmap, RWP_TRUE); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /******************************************************************************* |
| 223 | * This function initialises the GIC Redistributor interface of the calling CPU |
| 224 | * (identified by the 'proc_num' parameter) based upon the data provided by the |
| 225 | * platform while initialising the driver. |
| 226 | ******************************************************************************/ |
| 227 | void gicv3_rdistif_init(unsigned int proc_num) |
| 228 | { |
| 229 | uintptr_t gicr_base; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 230 | unsigned int bitmap; |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 231 | uint32_t ctlr; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 232 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 233 | assert(gicv3_driver_data != NULL); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 234 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 235 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
| 236 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 237 | |
| 238 | ctlr = gicd_read_ctlr(gicv3_driver_data->gicd_base); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 239 | assert((ctlr & CTLR_ARE_S_BIT) != 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 240 | |
| 241 | assert(IS_IN_EL3()); |
| 242 | |
Jeenu Viswambharan | 76647d5 | 2016-12-09 11:03:15 +0000 | [diff] [blame] | 243 | /* Power on redistributor */ |
| 244 | gicv3_rdistif_on(proc_num); |
| 245 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 246 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 247 | assert(gicr_base != 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 248 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 249 | /* Set the default attribute of all SGIs and (E)PPIs */ |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 250 | gicv3_ppi_sgi_config_defaults(gicr_base); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 251 | |
Antonio Nino Diaz | 29b9f5b | 2018-09-24 17:23:24 +0100 | [diff] [blame] | 252 | bitmap = gicv3_secure_ppi_sgi_config_props(gicr_base, |
| 253 | gicv3_driver_data->interrupt_props, |
| 254 | gicv3_driver_data->interrupt_props_num); |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 255 | |
| 256 | /* Enable interrupt groups as required, if not already */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 257 | if ((ctlr & bitmap) != bitmap) { |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 258 | gicd_set_ctlr(gicv3_driver_data->gicd_base, bitmap, RWP_TRUE); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 259 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /******************************************************************************* |
Jeenu Viswambharan | 76647d5 | 2016-12-09 11:03:15 +0000 | [diff] [blame] | 263 | * Functions to perform power operations on GIC Redistributor |
| 264 | ******************************************************************************/ |
| 265 | void gicv3_rdistif_off(unsigned int proc_num) |
| 266 | { |
Jeenu Viswambharan | 76647d5 | 2016-12-09 11:03:15 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void gicv3_rdistif_on(unsigned int proc_num) |
| 270 | { |
Jeenu Viswambharan | 76647d5 | 2016-12-09 11:03:15 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /******************************************************************************* |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 274 | * This function enables the GIC CPU interface of the calling CPU using only |
| 275 | * system register accesses. |
| 276 | ******************************************************************************/ |
| 277 | void gicv3_cpuif_enable(unsigned int proc_num) |
| 278 | { |
| 279 | uintptr_t gicr_base; |
Louis Mayencourt | 1c819c3 | 2020-01-24 13:30:28 +0000 | [diff] [blame] | 280 | u_register_t scr_el3; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 281 | unsigned int icc_sre_el3; |
| 282 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 283 | assert(gicv3_driver_data != NULL); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 284 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 285 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 286 | assert(IS_IN_EL3()); |
| 287 | |
| 288 | /* Mark the connected core as awake */ |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 289 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 290 | gicv3_rdistif_mark_core_awake(gicr_base); |
| 291 | |
| 292 | /* Disable the legacy interrupt bypass */ |
| 293 | icc_sre_el3 = ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT; |
| 294 | |
| 295 | /* |
| 296 | * Enable system register access for EL3 and allow lower exception |
| 297 | * levels to configure the same for themselves. If the legacy mode is |
| 298 | * not supported, the SRE bit is RAO/WI |
| 299 | */ |
| 300 | icc_sre_el3 |= (ICC_SRE_EN_BIT | ICC_SRE_SRE_BIT); |
| 301 | write_icc_sre_el3(read_icc_sre_el3() | icc_sre_el3); |
| 302 | |
Louis Mayencourt | 1c819c3 | 2020-01-24 13:30:28 +0000 | [diff] [blame] | 303 | scr_el3 = read_scr_el3(); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 304 | |
| 305 | /* |
| 306 | * Switch to NS state to write Non secure ICC_SRE_EL1 and |
| 307 | * ICC_SRE_EL2 registers. |
| 308 | */ |
| 309 | write_scr_el3(scr_el3 | SCR_NS_BIT); |
| 310 | isb(); |
| 311 | |
| 312 | write_icc_sre_el2(read_icc_sre_el2() | icc_sre_el3); |
| 313 | write_icc_sre_el1(ICC_SRE_SRE_BIT); |
| 314 | isb(); |
| 315 | |
| 316 | /* Switch to secure state. */ |
| 317 | write_scr_el3(scr_el3 & (~SCR_NS_BIT)); |
| 318 | isb(); |
| 319 | |
James kung | 05403eb | 2019-05-31 15:40:05 +0800 | [diff] [blame] | 320 | /* Write the secure ICC_SRE_EL1 register */ |
| 321 | write_icc_sre_el1(ICC_SRE_SRE_BIT); |
| 322 | isb(); |
| 323 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 324 | /* Program the idle priority in the PMR */ |
| 325 | write_icc_pmr_el1(GIC_PRI_MASK); |
| 326 | |
| 327 | /* Enable Group0 interrupts */ |
| 328 | write_icc_igrpen0_el1(IGRPEN1_EL1_ENABLE_G0_BIT); |
| 329 | |
| 330 | /* Enable Group1 Secure interrupts */ |
| 331 | write_icc_igrpen1_el3(read_icc_igrpen1_el3() | |
| 332 | IGRPEN1_EL3_ENABLE_G1S_BIT); |
Boyan Karatotev | ada21dc | 2023-03-23 12:46:53 +0000 | [diff] [blame^] | 333 | /* and restore the original */ |
| 334 | write_scr_el3(scr_el3); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 335 | isb(); |
Ming Huang | 94e1976 | 2021-06-04 16:23:22 +0800 | [diff] [blame] | 336 | /* Add DSB to ensure visibility of System register writes */ |
| 337 | dsb(); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /******************************************************************************* |
| 341 | * This function disables the GIC CPU interface of the calling CPU using |
| 342 | * only system register accesses. |
| 343 | ******************************************************************************/ |
| 344 | void gicv3_cpuif_disable(unsigned int proc_num) |
| 345 | { |
| 346 | uintptr_t gicr_base; |
| 347 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 348 | assert(gicv3_driver_data != NULL); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 349 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 350 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 351 | |
| 352 | assert(IS_IN_EL3()); |
| 353 | |
| 354 | /* Disable legacy interrupt bypass */ |
| 355 | write_icc_sre_el3(read_icc_sre_el3() | |
| 356 | (ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT)); |
| 357 | |
| 358 | /* Disable Group0 interrupts */ |
| 359 | write_icc_igrpen0_el1(read_icc_igrpen0_el1() & |
| 360 | ~IGRPEN1_EL1_ENABLE_G0_BIT); |
| 361 | |
Sudeep Holla | 869e3db | 2016-08-04 16:14:50 +0100 | [diff] [blame] | 362 | /* Disable Group1 Secure and Non-Secure interrupts */ |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 363 | write_icc_igrpen1_el3(read_icc_igrpen1_el3() & |
Sudeep Holla | 869e3db | 2016-08-04 16:14:50 +0100 | [diff] [blame] | 364 | ~(IGRPEN1_EL3_ENABLE_G1NS_BIT | |
| 365 | IGRPEN1_EL3_ENABLE_G1S_BIT)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 366 | |
| 367 | /* Synchronise accesses to group enable registers */ |
| 368 | isb(); |
Ming Huang | 94e1976 | 2021-06-04 16:23:22 +0800 | [diff] [blame] | 369 | /* Add DSB to ensure visibility of System register writes */ |
| 370 | dsb(); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 371 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 372 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
Manish V Badarkhe | 173c296 | 2022-05-09 21:55:19 +0100 | [diff] [blame] | 373 | assert(gicr_base != 0UL); |
| 374 | |
| 375 | /* |
| 376 | * dsb() already issued previously after clearing the CPU group |
| 377 | * enabled, apply below workaround to toggle the "DPG*" |
| 378 | * bits of GICR_CTLR register for unblocking event. |
| 379 | */ |
| 380 | gicv3_apply_errata_wa_2384374(gicr_base); |
| 381 | |
| 382 | /* Mark the connected core as asleep */ |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 383 | gicv3_rdistif_mark_core_asleep(gicr_base); |
| 384 | } |
| 385 | |
| 386 | /******************************************************************************* |
| 387 | * This function returns the id of the highest priority pending interrupt at |
| 388 | * the GIC cpu interface. |
| 389 | ******************************************************************************/ |
| 390 | unsigned int gicv3_get_pending_interrupt_id(void) |
| 391 | { |
| 392 | unsigned int id; |
| 393 | |
| 394 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 395 | id = (uint32_t)read_icc_hppir0_el1() & HPPIR0_EL1_INTID_MASK; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 396 | |
| 397 | /* |
| 398 | * If the ID is special identifier corresponding to G1S or G1NS |
| 399 | * interrupt, then read the highest pending group 1 interrupt. |
| 400 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 401 | if ((id == PENDING_G1S_INTID) || (id == PENDING_G1NS_INTID)) { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 402 | return (uint32_t)read_icc_hppir1_el1() & HPPIR1_EL1_INTID_MASK; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 403 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 404 | |
| 405 | return id; |
| 406 | } |
| 407 | |
| 408 | /******************************************************************************* |
| 409 | * This function returns the type of the highest priority pending interrupt at |
| 410 | * the GIC cpu interface. The return values can be one of the following : |
| 411 | * PENDING_G1S_INTID : The interrupt type is secure Group 1. |
| 412 | * PENDING_G1NS_INTID : The interrupt type is non secure Group 1. |
| 413 | * 0 - 1019 : The interrupt type is secure Group 0. |
| 414 | * GIC_SPURIOUS_INTERRUPT : there is no pending interrupt with |
| 415 | * sufficient priority to be signaled |
| 416 | ******************************************************************************/ |
| 417 | unsigned int gicv3_get_pending_interrupt_type(void) |
| 418 | { |
| 419 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 420 | return (uint32_t)read_icc_hppir0_el1() & HPPIR0_EL1_INTID_MASK; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /******************************************************************************* |
| 424 | * This function returns the type of the interrupt id depending upon the group |
| 425 | * this interrupt has been configured under by the interrupt controller i.e. |
| 426 | * group0 or group1 Secure / Non Secure. The return value can be one of the |
| 427 | * following : |
Soby Mathew | 5c5c36b | 2015-12-03 14:12:54 +0000 | [diff] [blame] | 428 | * INTR_GROUP0 : The interrupt type is a Secure Group 0 interrupt |
| 429 | * INTR_GROUP1S : The interrupt type is a Secure Group 1 secure interrupt |
| 430 | * INTR_GROUP1NS: The interrupt type is a Secure Group 1 non secure |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 431 | * interrupt. |
| 432 | ******************************************************************************/ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 433 | unsigned int gicv3_get_interrupt_type(unsigned int id, unsigned int proc_num) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 434 | { |
| 435 | unsigned int igroup, grpmodr; |
| 436 | uintptr_t gicr_base; |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 437 | uintptr_t gicd_base; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 438 | |
| 439 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 440 | assert(gicv3_driver_data != NULL); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 441 | |
| 442 | /* Ensure the parameters are valid */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 443 | assert((id < PENDING_G1S_INTID) || (id >= MIN_LPI_ID)); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 444 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 445 | |
| 446 | /* All LPI interrupts are Group 1 non secure */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 447 | if (id >= MIN_LPI_ID) { |
Soby Mathew | 5c5c36b | 2015-12-03 14:12:54 +0000 | [diff] [blame] | 448 | return INTR_GROUP1NS; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 449 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 450 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 451 | /* Check interrupt ID */ |
| 452 | if (is_sgi_ppi(id)) { |
| 453 | /* SGIs: 0-15, PPIs: 16-31, EPPIs: 1056-1119 */ |
Andrew F. Davis | 25a17a2 | 2018-08-30 14:30:54 -0500 | [diff] [blame] | 454 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 455 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 456 | igroup = gicr_get_igroupr(gicr_base, id); |
| 457 | grpmodr = gicr_get_igrpmodr(gicr_base, id); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 458 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 459 | /* SPIs: 32-1019, ESPIs: 4096-5119 */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 460 | assert(gicv3_driver_data->gicd_base != 0U); |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 461 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 462 | igroup = gicd_get_igroupr(gicd_base, id); |
| 463 | grpmodr = gicd_get_igrpmodr(gicd_base, id); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* |
| 467 | * If the IGROUP bit is set, then it is a Group 1 Non secure |
| 468 | * interrupt |
| 469 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 470 | if (igroup != 0U) { |
Soby Mathew | 5c5c36b | 2015-12-03 14:12:54 +0000 | [diff] [blame] | 471 | return INTR_GROUP1NS; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 472 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 473 | |
| 474 | /* If the GRPMOD bit is set, then it is a Group 1 Secure interrupt */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 475 | if (grpmodr != 0U) { |
Soby Mathew | 5c5c36b | 2015-12-03 14:12:54 +0000 | [diff] [blame] | 476 | return INTR_GROUP1S; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 477 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 478 | |
| 479 | /* Else it is a Group 0 Secure interrupt */ |
Soby Mathew | 5c5c36b | 2015-12-03 14:12:54 +0000 | [diff] [blame] | 480 | return INTR_GROUP0; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 481 | } |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 482 | |
| 483 | /***************************************************************************** |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 484 | * Function to save and disable the GIC ITS register context. The power |
| 485 | * management of GIC ITS is implementation-defined and this function doesn't |
| 486 | * save any memory structures required to support ITS. As the sequence to save |
| 487 | * this state is implementation defined, it should be executed in platform |
| 488 | * specific code. Calling this function alone and then powering down the GIC and |
| 489 | * ITS without implementing the aforementioned platform specific code will |
| 490 | * corrupt the ITS state. |
| 491 | * |
| 492 | * This function must be invoked after the GIC CPU interface is disabled. |
| 493 | *****************************************************************************/ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 494 | void gicv3_its_save_disable(uintptr_t gits_base, |
| 495 | gicv3_its_ctx_t * const its_ctx) |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 496 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 497 | unsigned int i; |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 498 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 499 | assert(gicv3_driver_data != NULL); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 500 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 501 | assert(its_ctx != NULL); |
| 502 | assert(gits_base != 0U); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 503 | |
| 504 | its_ctx->gits_ctlr = gits_read_ctlr(gits_base); |
| 505 | |
| 506 | /* Disable the ITS */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 507 | gits_write_ctlr(gits_base, its_ctx->gits_ctlr & ~GITS_CTLR_ENABLED_BIT); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 508 | |
| 509 | /* Wait for quiescent state */ |
| 510 | gits_wait_for_quiescent_bit(gits_base); |
| 511 | |
| 512 | its_ctx->gits_cbaser = gits_read_cbaser(gits_base); |
| 513 | its_ctx->gits_cwriter = gits_read_cwriter(gits_base); |
| 514 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 515 | for (i = 0U; i < ARRAY_SIZE(its_ctx->gits_baser); i++) { |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 516 | its_ctx->gits_baser[i] = gits_read_baser(gits_base, i); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 517 | } |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /***************************************************************************** |
| 521 | * Function to restore the GIC ITS register context. The power |
| 522 | * management of GIC ITS is implementation defined and this function doesn't |
| 523 | * restore any memory structures required to support ITS. The assumption is |
| 524 | * that these structures are in memory and are retained during system suspend. |
| 525 | * |
| 526 | * This must be invoked before the GIC CPU interface is enabled. |
| 527 | *****************************************************************************/ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 528 | void gicv3_its_restore(uintptr_t gits_base, |
| 529 | const gicv3_its_ctx_t * const its_ctx) |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 530 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 531 | unsigned int i; |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 532 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 533 | assert(gicv3_driver_data != NULL); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 534 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 535 | assert(its_ctx != NULL); |
| 536 | assert(gits_base != 0U); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 537 | |
| 538 | /* Assert that the GITS is disabled and quiescent */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 539 | assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U); |
| 540 | assert((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) != 0U); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 541 | |
| 542 | gits_write_cbaser(gits_base, its_ctx->gits_cbaser); |
| 543 | gits_write_cwriter(gits_base, its_ctx->gits_cwriter); |
| 544 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 545 | for (i = 0U; i < ARRAY_SIZE(its_ctx->gits_baser); i++) { |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 546 | gits_write_baser(gits_base, i, its_ctx->gits_baser[i]); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 547 | } |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 548 | |
| 549 | /* Restore the ITS CTLR but leave the ITS disabled */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 550 | gits_write_ctlr(gits_base, its_ctx->gits_ctlr & ~GITS_CTLR_ENABLED_BIT); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /***************************************************************************** |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 554 | * Function to save the GIC Redistributor register context. This function |
| 555 | * must be invoked after CPU interface disable and prior to Distributor save. |
| 556 | *****************************************************************************/ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 557 | void gicv3_rdistif_save(unsigned int proc_num, |
| 558 | gicv3_redist_ctx_t * const rdist_ctx) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 559 | { |
| 560 | uintptr_t gicr_base; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 561 | unsigned int i, ppi_regs_num, regs_num; |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 562 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 563 | assert(gicv3_driver_data != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 564 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 565 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 566 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 567 | assert(rdist_ctx != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 568 | |
| 569 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
| 570 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 571 | #if GIC_EXT_INTID |
| 572 | /* Calculate number of PPI registers */ |
| 573 | ppi_regs_num = (unsigned int)((gicr_read_typer(gicr_base) >> |
| 574 | TYPER_PPI_NUM_SHIFT) & TYPER_PPI_NUM_MASK) + 1; |
| 575 | /* All other values except PPInum [0-2] are reserved */ |
| 576 | if (ppi_regs_num > 3U) { |
| 577 | ppi_regs_num = 1U; |
| 578 | } |
| 579 | #else |
| 580 | ppi_regs_num = 1U; |
| 581 | #endif |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 582 | /* |
| 583 | * Wait for any write to GICR_CTLR to complete before trying to save any |
| 584 | * state. |
| 585 | */ |
| 586 | gicr_wait_for_pending_write(gicr_base); |
| 587 | |
| 588 | rdist_ctx->gicr_ctlr = gicr_read_ctlr(gicr_base); |
| 589 | |
| 590 | rdist_ctx->gicr_propbaser = gicr_read_propbaser(gicr_base); |
| 591 | rdist_ctx->gicr_pendbaser = gicr_read_pendbaser(gicr_base); |
| 592 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 593 | /* 32 interrupt IDs per register */ |
| 594 | for (i = 0U; i < ppi_regs_num; ++i) { |
| 595 | SAVE_GICR_REG(gicr_base, rdist_ctx, igroupr, i); |
| 596 | SAVE_GICR_REG(gicr_base, rdist_ctx, isenabler, i); |
| 597 | SAVE_GICR_REG(gicr_base, rdist_ctx, ispendr, i); |
| 598 | SAVE_GICR_REG(gicr_base, rdist_ctx, isactiver, i); |
| 599 | SAVE_GICR_REG(gicr_base, rdist_ctx, igrpmodr, i); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 600 | } |
| 601 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 602 | /* 16 interrupt IDs per GICR_ICFGR register */ |
| 603 | regs_num = ppi_regs_num << 1; |
| 604 | for (i = 0U; i < regs_num; ++i) { |
| 605 | SAVE_GICR_REG(gicr_base, rdist_ctx, icfgr, i); |
| 606 | } |
| 607 | |
| 608 | rdist_ctx->gicr_nsacr = gicr_read_nsacr(gicr_base); |
| 609 | |
| 610 | /* 4 interrupt IDs per GICR_IPRIORITYR register */ |
| 611 | regs_num = ppi_regs_num << 3; |
| 612 | for (i = 0U; i < regs_num; ++i) { |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 613 | rdist_ctx->gicr_ipriorityr[i] = |
| 614 | gicr_ipriorityr_read(gicr_base, i); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 615 | } |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 616 | |
| 617 | /* |
| 618 | * Call the pre-save hook that implements the IMP DEF sequence that may |
| 619 | * be required on some GIC implementations. As this may need to access |
| 620 | * the Redistributor registers, we pass it proc_num. |
| 621 | */ |
| 622 | gicv3_distif_pre_save(proc_num); |
| 623 | } |
| 624 | |
| 625 | /***************************************************************************** |
| 626 | * Function to restore the GIC Redistributor register context. We disable |
| 627 | * LPI and per-cpu interrupts before we start restore of the Redistributor. |
| 628 | * This function must be invoked after Distributor restore but prior to |
| 629 | * CPU interface enable. The pending and active interrupts are restored |
| 630 | * after the interrupts are fully configured and enabled. |
| 631 | *****************************************************************************/ |
| 632 | void gicv3_rdistif_init_restore(unsigned int proc_num, |
| 633 | const gicv3_redist_ctx_t * const rdist_ctx) |
| 634 | { |
| 635 | uintptr_t gicr_base; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 636 | unsigned int i, ppi_regs_num, regs_num; |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 637 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 638 | assert(gicv3_driver_data != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 639 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 640 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 641 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 642 | assert(rdist_ctx != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 643 | |
| 644 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
| 645 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 646 | #if GIC_EXT_INTID |
| 647 | /* Calculate number of PPI registers */ |
| 648 | ppi_regs_num = (unsigned int)((gicr_read_typer(gicr_base) >> |
| 649 | TYPER_PPI_NUM_SHIFT) & TYPER_PPI_NUM_MASK) + 1; |
| 650 | /* All other values except PPInum [0-2] are reserved */ |
| 651 | if (ppi_regs_num > 3U) { |
| 652 | ppi_regs_num = 1U; |
| 653 | } |
| 654 | #else |
| 655 | ppi_regs_num = 1U; |
| 656 | #endif |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 657 | /* Power on redistributor */ |
| 658 | gicv3_rdistif_on(proc_num); |
| 659 | |
| 660 | /* |
| 661 | * Call the post-restore hook that implements the IMP DEF sequence that |
| 662 | * may be required on some GIC implementations. As this may need to |
| 663 | * access the Redistributor registers, we pass it proc_num. |
| 664 | */ |
| 665 | gicv3_distif_post_restore(proc_num); |
| 666 | |
| 667 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 668 | * Disable all SGIs (imp. def.)/(E)PPIs before configuring them. |
| 669 | * This is a more scalable approach as it avoids clearing the enable |
| 670 | * bits in the GICD_CTLR. |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 671 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 672 | for (i = 0U; i < ppi_regs_num; ++i) { |
| 673 | gicr_write_icenabler(gicr_base, i, ~0U); |
| 674 | } |
| 675 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 676 | /* Wait for pending writes to GICR_ICENABLER */ |
| 677 | gicr_wait_for_pending_write(gicr_base); |
| 678 | |
| 679 | /* |
| 680 | * Disable the LPIs to avoid unpredictable behavior when writing to |
| 681 | * GICR_PROPBASER and GICR_PENDBASER. |
| 682 | */ |
| 683 | gicr_write_ctlr(gicr_base, |
| 684 | rdist_ctx->gicr_ctlr & ~(GICR_CTLR_EN_LPIS_BIT)); |
| 685 | |
| 686 | /* Restore registers' content */ |
| 687 | gicr_write_propbaser(gicr_base, rdist_ctx->gicr_propbaser); |
| 688 | gicr_write_pendbaser(gicr_base, rdist_ctx->gicr_pendbaser); |
| 689 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 690 | /* 32 interrupt IDs per register */ |
| 691 | for (i = 0U; i < ppi_regs_num; ++i) { |
| 692 | RESTORE_GICR_REG(gicr_base, rdist_ctx, igroupr, i); |
| 693 | RESTORE_GICR_REG(gicr_base, rdist_ctx, igrpmodr, i); |
| 694 | } |
| 695 | |
| 696 | /* 4 interrupt IDs per GICR_IPRIORITYR register */ |
| 697 | regs_num = ppi_regs_num << 3; |
| 698 | for (i = 0U; i < regs_num; ++i) { |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 699 | gicr_ipriorityr_write(gicr_base, i, |
| 700 | rdist_ctx->gicr_ipriorityr[i]); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 701 | } |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 702 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 703 | /* 16 interrupt IDs per GICR_ICFGR register */ |
| 704 | regs_num = ppi_regs_num << 1; |
| 705 | for (i = 0U; i < regs_num; ++i) { |
| 706 | RESTORE_GICR_REG(gicr_base, rdist_ctx, icfgr, i); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 707 | } |
| 708 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 709 | gicr_write_nsacr(gicr_base, rdist_ctx->gicr_nsacr); |
| 710 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 711 | /* Restore after group and priorities are set. |
| 712 | * 32 interrupt IDs per register |
| 713 | */ |
| 714 | for (i = 0U; i < ppi_regs_num; ++i) { |
| 715 | RESTORE_GICR_REG(gicr_base, rdist_ctx, ispendr, i); |
| 716 | RESTORE_GICR_REG(gicr_base, rdist_ctx, isactiver, i); |
| 717 | } |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 718 | |
| 719 | /* |
| 720 | * Wait for all writes to the Distributor to complete before enabling |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 721 | * the SGI and (E)PPIs. |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 722 | */ |
| 723 | gicr_wait_for_upstream_pending_write(gicr_base); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 724 | |
| 725 | /* 32 interrupt IDs per GICR_ISENABLER register */ |
| 726 | for (i = 0U; i < ppi_regs_num; ++i) { |
| 727 | RESTORE_GICR_REG(gicr_base, rdist_ctx, isenabler, i); |
| 728 | } |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 729 | |
| 730 | /* |
| 731 | * Restore GICR_CTLR.Enable_LPIs bit and wait for pending writes in case |
| 732 | * the first write to GICR_CTLR was still in flight (this write only |
| 733 | * restores GICR_CTLR.Enable_LPIs and no waiting is required for this |
| 734 | * bit). |
| 735 | */ |
| 736 | gicr_write_ctlr(gicr_base, rdist_ctx->gicr_ctlr); |
| 737 | gicr_wait_for_pending_write(gicr_base); |
| 738 | } |
| 739 | |
| 740 | /***************************************************************************** |
| 741 | * Function to save the GIC Distributor register context. This function |
| 742 | * must be invoked after CPU interface disable and Redistributor save. |
| 743 | *****************************************************************************/ |
| 744 | void gicv3_distif_save(gicv3_dist_ctx_t * const dist_ctx) |
| 745 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 746 | assert(gicv3_driver_data != NULL); |
| 747 | assert(gicv3_driver_data->gicd_base != 0U); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 748 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 749 | assert(dist_ctx != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 750 | |
| 751 | uintptr_t gicd_base = gicv3_driver_data->gicd_base; |
Heyi Guo | 79bc7a7 | 2021-01-20 19:05:51 +0800 | [diff] [blame] | 752 | unsigned int num_ints = gicv3_get_spi_limit(gicd_base); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 753 | #if GIC_EXT_INTID |
Heyi Guo | 79bc7a7 | 2021-01-20 19:05:51 +0800 | [diff] [blame] | 754 | unsigned int num_eints = gicv3_get_espi_limit(gicd_base); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 755 | #endif |
Heyi Guo | 79bc7a7 | 2021-01-20 19:05:51 +0800 | [diff] [blame] | 756 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 757 | /* Wait for pending write to complete */ |
| 758 | gicd_wait_for_pending_write(gicd_base); |
| 759 | |
| 760 | /* Save the GICD_CTLR */ |
| 761 | dist_ctx->gicd_ctlr = gicd_read_ctlr(gicd_base); |
| 762 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 763 | /* Save GICD_IGROUPR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 764 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, igroupr, IGROUP); |
| 765 | |
| 766 | /* Save GICD_IGROUPRE for INTIDs 4096 - 5119 */ |
| 767 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, igroupr, IGROUP); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 768 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 769 | /* Save GICD_ISENABLER for INT_IDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 770 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, isenabler, ISENABLE); |
| 771 | |
| 772 | /* Save GICD_ISENABLERE for INT_IDs 4096 - 5119 */ |
| 773 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, isenabler, ISENABLE); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 774 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 775 | /* Save GICD_ISPENDR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 776 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, ispendr, ISPEND); |
| 777 | |
| 778 | /* Save GICD_ISPENDRE for INTIDs 4096 - 5119 */ |
| 779 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, ispendr, ISPEND); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 780 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 781 | /* Save GICD_ISACTIVER for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 782 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, isactiver, ISACTIVE); |
| 783 | |
| 784 | /* Save GICD_ISACTIVERE for INTIDs 4096 - 5119 */ |
| 785 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, isactiver, ISACTIVE); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 786 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 787 | /* Save GICD_IPRIORITYR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 788 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, ipriorityr, IPRIORITY); |
| 789 | |
| 790 | /* Save GICD_IPRIORITYRE for INTIDs 4096 - 5119 */ |
| 791 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, ipriorityr, IPRIORITY); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 792 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 793 | /* Save GICD_ICFGR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 794 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, icfgr, ICFG); |
| 795 | |
| 796 | /* Save GICD_ICFGRE for INTIDs 4096 - 5119 */ |
| 797 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, icfgr, ICFG); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 798 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 799 | /* Save GICD_IGRPMODR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 800 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, igrpmodr, IGRPMOD); |
| 801 | |
| 802 | /* Save GICD_IGRPMODRE for INTIDs 4096 - 5119 */ |
| 803 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, igrpmodr, IGRPMOD); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 804 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 805 | /* Save GICD_NSACR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 806 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, nsacr, NSAC); |
| 807 | |
| 808 | /* Save GICD_NSACRE for INTIDs 4096 - 5119 */ |
| 809 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, nsacr, NSAC); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 810 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 811 | /* Save GICD_IROUTER for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 812 | SAVE_GICD_REGS(gicd_base, dist_ctx, num_ints, irouter, IROUTE); |
| 813 | |
| 814 | /* Save GICD_IROUTERE for INTIDs 4096 - 5119 */ |
| 815 | SAVE_GICD_EREGS(gicd_base, dist_ctx, num_eints, irouter, IROUTE); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 816 | |
| 817 | /* |
| 818 | * GICD_ITARGETSR<n> and GICD_SPENDSGIR<n> are RAZ/WI when |
| 819 | * GICD_CTLR.ARE_(S|NS) bits are set which is the case for our GICv3 |
| 820 | * driver. |
| 821 | */ |
| 822 | } |
| 823 | |
| 824 | /***************************************************************************** |
| 825 | * Function to restore the GIC Distributor register context. We disable G0, G1S |
| 826 | * and G1NS interrupt groups before we start restore of the Distributor. This |
| 827 | * function must be invoked prior to Redistributor restore and CPU interface |
| 828 | * enable. The pending and active interrupts are restored after the interrupts |
| 829 | * are fully configured and enabled. |
| 830 | *****************************************************************************/ |
| 831 | void gicv3_distif_init_restore(const gicv3_dist_ctx_t * const dist_ctx) |
| 832 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 833 | assert(gicv3_driver_data != NULL); |
| 834 | assert(gicv3_driver_data->gicd_base != 0U); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 835 | assert(IS_IN_EL3()); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 836 | assert(dist_ctx != NULL); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 837 | |
| 838 | uintptr_t gicd_base = gicv3_driver_data->gicd_base; |
| 839 | |
| 840 | /* |
| 841 | * Clear the "enable" bits for G0/G1S/G1NS interrupts before configuring |
| 842 | * the ARE_S bit. The Distributor might generate a system error |
| 843 | * otherwise. |
| 844 | */ |
| 845 | gicd_clr_ctlr(gicd_base, |
| 846 | CTLR_ENABLE_G0_BIT | |
| 847 | CTLR_ENABLE_G1S_BIT | |
| 848 | CTLR_ENABLE_G1NS_BIT, |
| 849 | RWP_TRUE); |
| 850 | |
| 851 | /* Set the ARE_S and ARE_NS bit now that interrupts have been disabled */ |
| 852 | gicd_set_ctlr(gicd_base, CTLR_ARE_S_BIT | CTLR_ARE_NS_BIT, RWP_TRUE); |
| 853 | |
Heyi Guo | 79bc7a7 | 2021-01-20 19:05:51 +0800 | [diff] [blame] | 854 | unsigned int num_ints = gicv3_get_spi_limit(gicd_base); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 855 | #if GIC_EXT_INTID |
Heyi Guo | 79bc7a7 | 2021-01-20 19:05:51 +0800 | [diff] [blame] | 856 | unsigned int num_eints = gicv3_get_espi_limit(gicd_base); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 857 | #endif |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 858 | /* Restore GICD_IGROUPR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 859 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, igroupr, IGROUP); |
| 860 | |
| 861 | /* Restore GICD_IGROUPRE for INTIDs 4096 - 5119 */ |
| 862 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, igroupr, IGROUP); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 863 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 864 | /* Restore GICD_IPRIORITYR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 865 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, ipriorityr, IPRIORITY); |
| 866 | |
| 867 | /* Restore GICD_IPRIORITYRE for INTIDs 4096 - 5119 */ |
| 868 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, ipriorityr, IPRIORITY); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 869 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 870 | /* Restore GICD_ICFGR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 871 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, icfgr, ICFG); |
| 872 | |
| 873 | /* Restore GICD_ICFGRE for INTIDs 4096 - 5119 */ |
| 874 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, icfgr, ICFG); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 875 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 876 | /* Restore GICD_IGRPMODR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 877 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, igrpmodr, IGRPMOD); |
| 878 | |
| 879 | /* Restore GICD_IGRPMODRE for INTIDs 4096 - 5119 */ |
| 880 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, igrpmodr, IGRPMOD); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 881 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 882 | /* Restore GICD_NSACR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 883 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, nsacr, NSAC); |
| 884 | |
| 885 | /* Restore GICD_NSACRE for INTIDs 4096 - 5119 */ |
| 886 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, nsacr, NSAC); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 887 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 888 | /* Restore GICD_IROUTER for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 889 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, irouter, IROUTE); |
| 890 | |
| 891 | /* Restore GICD_IROUTERE for INTIDs 4096 - 5119 */ |
| 892 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, irouter, IROUTE); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 893 | |
| 894 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 895 | * Restore ISENABLER(E), ISPENDR(E) and ISACTIVER(E) after |
| 896 | * the interrupts are configured. |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 897 | */ |
| 898 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 899 | /* Restore GICD_ISENABLER for INT_IDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 900 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, isenabler, ISENABLE); |
| 901 | |
| 902 | /* Restore GICD_ISENABLERE for INT_IDs 4096 - 5119 */ |
| 903 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, isenabler, ISENABLE); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 904 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 905 | /* Restore GICD_ISPENDR for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 906 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, ispendr, ISPEND); |
| 907 | |
| 908 | /* Restore GICD_ISPENDRE for INTIDs 4096 - 5119 */ |
| 909 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, ispendr, ISPEND); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 910 | |
Alexei Fedorov | 68f2688 | 2019-09-13 15:47:13 +0100 | [diff] [blame] | 911 | /* Restore GICD_ISACTIVER for INTIDs 32 - 1019 */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 912 | RESTORE_GICD_REGS(gicd_base, dist_ctx, num_ints, isactiver, ISACTIVE); |
| 913 | |
| 914 | /* Restore GICD_ISACTIVERE for INTIDs 4096 - 5119 */ |
| 915 | RESTORE_GICD_EREGS(gicd_base, dist_ctx, num_eints, isactiver, ISACTIVE); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 916 | |
| 917 | /* Restore the GICD_CTLR */ |
| 918 | gicd_write_ctlr(gicd_base, dist_ctx->gicd_ctlr); |
| 919 | gicd_wait_for_pending_write(gicd_base); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 920 | } |
Jeenu Viswambharan | b1e957e | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 921 | |
| 922 | /******************************************************************************* |
| 923 | * This function gets the priority of the interrupt the processor is currently |
| 924 | * servicing. |
| 925 | ******************************************************************************/ |
| 926 | unsigned int gicv3_get_running_priority(void) |
| 927 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 928 | return (unsigned int)read_icc_rpr_el1(); |
Jeenu Viswambharan | b1e957e | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 929 | } |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 930 | |
| 931 | /******************************************************************************* |
| 932 | * This function checks if the interrupt identified by id is active (whether the |
| 933 | * state is either active, or active and pending). The proc_num is used if the |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 934 | * interrupt is SGI or (E)PPI and programs the corresponding Redistributor |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 935 | * interface. |
| 936 | ******************************************************************************/ |
| 937 | unsigned int gicv3_get_interrupt_active(unsigned int id, unsigned int proc_num) |
| 938 | { |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 939 | uintptr_t gicd_base; |
| 940 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 941 | assert(gicv3_driver_data != NULL); |
| 942 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 943 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 944 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 945 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 946 | /* Check interrupt ID */ |
| 947 | if (is_sgi_ppi(id)) { |
| 948 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
| 949 | return gicr_get_isactiver( |
| 950 | gicv3_driver_data->rdistif_base_addrs[proc_num], id); |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 953 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 954 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 955 | return gicd_get_isactiver(gicd_base, id); |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 956 | } |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 957 | |
| 958 | /******************************************************************************* |
| 959 | * This function enables the interrupt identified by id. The proc_num |
| 960 | * is used if the interrupt is SGI or PPI, and programs the corresponding |
| 961 | * Redistributor interface. |
| 962 | ******************************************************************************/ |
| 963 | void gicv3_enable_interrupt(unsigned int id, unsigned int proc_num) |
| 964 | { |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 965 | uintptr_t gicd_base; |
| 966 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 967 | assert(gicv3_driver_data != NULL); |
| 968 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 969 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 970 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 971 | |
| 972 | /* |
| 973 | * Ensure that any shared variable updates depending on out of band |
| 974 | * interrupt trigger are observed before enabling interrupt. |
| 975 | */ |
| 976 | dsbishst(); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 977 | |
| 978 | /* Check interrupt ID */ |
| 979 | if (is_sgi_ppi(id)) { |
| 980 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
| 981 | gicr_set_isenabler( |
| 982 | gicv3_driver_data->rdistif_base_addrs[proc_num], id); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 983 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 984 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 985 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 986 | gicd_set_isenabler(gicd_base, id); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
| 990 | /******************************************************************************* |
| 991 | * This function disables the interrupt identified by id. The proc_num |
| 992 | * is used if the interrupt is SGI or PPI, and programs the corresponding |
| 993 | * Redistributor interface. |
| 994 | ******************************************************************************/ |
| 995 | void gicv3_disable_interrupt(unsigned int id, unsigned int proc_num) |
| 996 | { |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 997 | uintptr_t gicd_base; |
| 998 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 999 | assert(gicv3_driver_data != NULL); |
| 1000 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1001 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1002 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1003 | |
| 1004 | /* |
| 1005 | * Disable interrupt, and ensure that any shared variable updates |
| 1006 | * depending on out of band interrupt trigger are observed afterwards. |
| 1007 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1008 | |
| 1009 | /* Check interrupt ID */ |
| 1010 | if (is_sgi_ppi(id)) { |
| 1011 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
| 1012 | gicr_set_icenabler( |
| 1013 | gicv3_driver_data->rdistif_base_addrs[proc_num], id); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1014 | |
| 1015 | /* Write to clear enable requires waiting for pending writes */ |
| 1016 | gicr_wait_for_pending_write( |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1017 | gicv3_driver_data->rdistif_base_addrs[proc_num]); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1018 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1019 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1020 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 1021 | gicd_set_icenabler(gicd_base, id); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1022 | |
| 1023 | /* Write to clear enable requires waiting for pending writes */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1024 | gicd_wait_for_pending_write(gicd_base); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | dsbishst(); |
| 1028 | } |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1029 | |
| 1030 | /******************************************************************************* |
| 1031 | * This function sets the interrupt priority as supplied for the given interrupt |
| 1032 | * id. |
| 1033 | ******************************************************************************/ |
| 1034 | void gicv3_set_interrupt_priority(unsigned int id, unsigned int proc_num, |
| 1035 | unsigned int priority) |
| 1036 | { |
| 1037 | uintptr_t gicr_base; |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1038 | uintptr_t gicd_base; |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1039 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1040 | assert(gicv3_driver_data != NULL); |
| 1041 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1042 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1043 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1044 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1045 | /* Check interrupt ID */ |
| 1046 | if (is_sgi_ppi(id)) { |
| 1047 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1048 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
| 1049 | gicr_set_ipriorityr(gicr_base, id, priority); |
| 1050 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1051 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1052 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 1053 | gicd_set_ipriorityr(gicd_base, id, priority); |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1054 | } |
| 1055 | } |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1056 | |
| 1057 | /******************************************************************************* |
| 1058 | * This function assigns group for the interrupt identified by id. The proc_num |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1059 | * is used if the interrupt is SGI or (E)PPI, and programs the corresponding |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1060 | * Redistributor interface. The group can be any of GICV3_INTR_GROUP* |
| 1061 | ******************************************************************************/ |
| 1062 | void gicv3_set_interrupt_type(unsigned int id, unsigned int proc_num, |
| 1063 | unsigned int type) |
| 1064 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1065 | bool igroup = false, grpmod = false; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1066 | uintptr_t gicr_base; |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1067 | uintptr_t gicd_base; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1068 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1069 | assert(gicv3_driver_data != NULL); |
| 1070 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1071 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1072 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1073 | |
| 1074 | switch (type) { |
| 1075 | case INTR_GROUP1S: |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1076 | igroup = false; |
| 1077 | grpmod = true; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1078 | break; |
| 1079 | case INTR_GROUP0: |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1080 | igroup = false; |
| 1081 | grpmod = false; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1082 | break; |
| 1083 | case INTR_GROUP1NS: |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1084 | igroup = true; |
| 1085 | grpmod = false; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1086 | break; |
| 1087 | default: |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1088 | assert(false); |
Jonathan Wright | 39b4221 | 2018-03-13 15:24:29 +0000 | [diff] [blame] | 1089 | break; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1092 | /* Check interrupt ID */ |
| 1093 | if (is_sgi_ppi(id)) { |
| 1094 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1095 | gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num]; |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1096 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1097 | igroup ? gicr_set_igroupr(gicr_base, id) : |
| 1098 | gicr_clr_igroupr(gicr_base, id); |
| 1099 | grpmod ? gicr_set_igrpmodr(gicr_base, id) : |
| 1100 | gicr_clr_igrpmodr(gicr_base, id); |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1101 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1102 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
| 1103 | |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1104 | /* Serialize read-modify-write to Distributor registers */ |
| 1105 | spin_lock(&gic_lock); |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1106 | |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1107 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 1108 | |
| 1109 | igroup ? gicd_set_igroupr(gicd_base, id) : |
| 1110 | gicd_clr_igroupr(gicd_base, id); |
| 1111 | grpmod ? gicd_set_igrpmodr(gicd_base, id) : |
| 1112 | gicd_clr_igrpmodr(gicd_base, id); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1113 | |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1114 | spin_unlock(&gic_lock); |
| 1115 | } |
| 1116 | } |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1117 | |
| 1118 | /******************************************************************************* |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 1119 | * This function raises the specified SGI of the specified group. |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1120 | * |
| 1121 | * The target parameter must be a valid MPIDR in the system. |
| 1122 | ******************************************************************************/ |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 1123 | void gicv3_raise_sgi(unsigned int sgi_num, gicv3_irq_group_t group, |
| 1124 | u_register_t target) |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1125 | { |
| 1126 | unsigned int tgt, aff3, aff2, aff1, aff0; |
| 1127 | uint64_t sgi_val; |
| 1128 | |
| 1129 | /* Verify interrupt number is in the SGI range */ |
| 1130 | assert((sgi_num >= MIN_SGI_ID) && (sgi_num < MIN_PPI_ID)); |
| 1131 | |
| 1132 | /* Extract affinity fields from target */ |
| 1133 | aff0 = MPIDR_AFFLVL0_VAL(target); |
| 1134 | aff1 = MPIDR_AFFLVL1_VAL(target); |
| 1135 | aff2 = MPIDR_AFFLVL2_VAL(target); |
| 1136 | aff3 = MPIDR_AFFLVL3_VAL(target); |
| 1137 | |
| 1138 | /* |
| 1139 | * Make target list from affinity 0, and ensure GICv3 SGI can target |
| 1140 | * this PE. |
| 1141 | */ |
| 1142 | assert(aff0 < GICV3_MAX_SGI_TARGETS); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1143 | tgt = BIT_32(aff0); |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1144 | |
| 1145 | /* Raise SGI to PE specified by its affinity */ |
| 1146 | sgi_val = GICV3_SGIR_VALUE(aff3, aff2, aff1, sgi_num, SGIR_IRM_TO_AFF, |
| 1147 | tgt); |
| 1148 | |
| 1149 | /* |
| 1150 | * Ensure that any shared variable updates depending on out of band |
| 1151 | * interrupt trigger are observed before raising SGI. |
| 1152 | */ |
| 1153 | dsbishst(); |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 1154 | |
| 1155 | switch (group) { |
| 1156 | case GICV3_G0: |
| 1157 | write_icc_sgi0r_el1(sgi_val); |
| 1158 | break; |
| 1159 | case GICV3_G1NS: |
| 1160 | write_icc_asgi1r(sgi_val); |
| 1161 | break; |
| 1162 | case GICV3_G1S: |
| 1163 | write_icc_sgi1r(sgi_val); |
| 1164 | break; |
| 1165 | default: |
| 1166 | assert(false); |
| 1167 | break; |
| 1168 | } |
| 1169 | |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1170 | isb(); |
| 1171 | } |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1172 | |
| 1173 | /******************************************************************************* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1174 | * This function sets the interrupt routing for the given (E)SPI interrupt id. |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1175 | * The interrupt routing is specified in routing mode and mpidr. |
| 1176 | * |
| 1177 | * The routing mode can be either of: |
| 1178 | * - GICV3_IRM_ANY |
| 1179 | * - GICV3_IRM_PE |
| 1180 | * |
| 1181 | * The mpidr is the affinity of the PE to which the interrupt will be routed, |
| 1182 | * and is ignored for routing mode GICV3_IRM_ANY. |
| 1183 | ******************************************************************************/ |
| 1184 | void gicv3_set_spi_routing(unsigned int id, unsigned int irm, u_register_t mpidr) |
| 1185 | { |
| 1186 | unsigned long long aff; |
| 1187 | uint64_t router; |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1188 | uintptr_t gicd_base; |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1189 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1190 | assert(gicv3_driver_data != NULL); |
| 1191 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1192 | |
| 1193 | assert((irm == GICV3_IRM_ANY) || (irm == GICV3_IRM_PE)); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1194 | |
| 1195 | assert(IS_SPI(id)); |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1196 | |
| 1197 | aff = gicd_irouter_val_from_mpidr(mpidr, irm); |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1198 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 1199 | gicd_write_irouter(gicd_base, id, aff); |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1200 | |
| 1201 | /* |
| 1202 | * In implementations that do not require 1 of N distribution of SPIs, |
| 1203 | * IRM might be RAZ/WI. Read back and verify IRM bit. |
| 1204 | */ |
| 1205 | if (irm == GICV3_IRM_ANY) { |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1206 | router = gicd_read_irouter(gicd_base, id); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1207 | if (((router >> IROUTER_IRM_SHIFT) & IROUTER_IRM_MASK) == 0U) { |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1208 | ERROR("GICv3 implementation doesn't support routing ANY\n"); |
| 1209 | panic(); |
| 1210 | } |
| 1211 | } |
| 1212 | } |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1213 | |
| 1214 | /******************************************************************************* |
| 1215 | * This function clears the pending status of an interrupt identified by id. |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1216 | * The proc_num is used if the interrupt is SGI or (E)PPI, and programs the |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1217 | * corresponding Redistributor interface. |
| 1218 | ******************************************************************************/ |
| 1219 | void gicv3_clear_interrupt_pending(unsigned int id, unsigned int proc_num) |
| 1220 | { |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1221 | uintptr_t gicd_base; |
| 1222 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1223 | assert(gicv3_driver_data != NULL); |
| 1224 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1225 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1226 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1227 | |
| 1228 | /* |
| 1229 | * Clear pending interrupt, and ensure that any shared variable updates |
| 1230 | * depending on out of band interrupt trigger are observed afterwards. |
| 1231 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1232 | |
| 1233 | /* Check interrupt ID */ |
| 1234 | if (is_sgi_ppi(id)) { |
| 1235 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
| 1236 | gicr_set_icpendr( |
| 1237 | gicv3_driver_data->rdistif_base_addrs[proc_num], id); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1238 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1239 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1240 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 1241 | gicd_set_icpendr(gicd_base, id); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1242 | } |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1243 | |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1244 | dsbishst(); |
| 1245 | } |
| 1246 | |
| 1247 | /******************************************************************************* |
| 1248 | * This function sets the pending status of an interrupt identified by id. |
| 1249 | * The proc_num is used if the interrupt is SGI or PPI and programs the |
| 1250 | * corresponding Redistributor interface. |
| 1251 | ******************************************************************************/ |
| 1252 | void gicv3_set_interrupt_pending(unsigned int id, unsigned int proc_num) |
| 1253 | { |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1254 | uintptr_t gicd_base; |
| 1255 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1256 | assert(gicv3_driver_data != NULL); |
| 1257 | assert(gicv3_driver_data->gicd_base != 0U); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1258 | assert(proc_num < gicv3_driver_data->rdistif_num); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 1259 | assert(gicv3_driver_data->rdistif_base_addrs != NULL); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1260 | |
| 1261 | /* |
| 1262 | * Ensure that any shared variable updates depending on out of band |
| 1263 | * interrupt trigger are observed before setting interrupt pending. |
| 1264 | */ |
| 1265 | dsbishst(); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1266 | |
| 1267 | /* Check interrupt ID */ |
| 1268 | if (is_sgi_ppi(id)) { |
| 1269 | /* For SGIs: 0-15, PPIs: 16-31 and EPPIs: 1056-1119 */ |
| 1270 | gicr_set_ispendr( |
| 1271 | gicv3_driver_data->rdistif_base_addrs[proc_num], id); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1272 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1273 | /* For SPIs: 32-1019 and ESPIs: 4096-5119 */ |
Varun Wadekar | 61286d2 | 2023-03-08 16:47:38 +0000 | [diff] [blame] | 1274 | gicd_base = gicv3_get_multichip_base(id, gicv3_driver_data->gicd_base); |
| 1275 | gicd_set_ispendr(gicd_base, id); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1276 | } |
| 1277 | } |
Jeenu Viswambharan | 6250507 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1278 | |
| 1279 | /******************************************************************************* |
| 1280 | * This function sets the PMR register with the supplied value. Returns the |
| 1281 | * original PMR. |
| 1282 | ******************************************************************************/ |
| 1283 | unsigned int gicv3_set_pmr(unsigned int mask) |
| 1284 | { |
| 1285 | unsigned int old_mask; |
| 1286 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1287 | old_mask = (unsigned int)read_icc_pmr_el1(); |
Jeenu Viswambharan | 6250507 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 1288 | |
| 1289 | /* |
| 1290 | * Order memory updates w.r.t. PMR write, and ensure they're visible |
| 1291 | * before potential out of band interrupt trigger because of PMR update. |
| 1292 | * PMR system register writes are self-synchronizing, so no ISB required |
| 1293 | * thereafter. |
| 1294 | */ |
| 1295 | dsbishst(); |
| 1296 | write_icc_pmr_el1(mask); |
| 1297 | |
| 1298 | return old_mask; |
| 1299 | } |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1300 | |
| 1301 | /******************************************************************************* |
| 1302 | * This function delegates the responsibility of discovering the corresponding |
| 1303 | * Redistributor frames to each CPU itself. It is a modified version of |
| 1304 | * gicv3_rdistif_base_addrs_probe() and is executed by each CPU in the platform |
| 1305 | * unlike the previous way in which only the Primary CPU did the discovery of |
| 1306 | * all the Redistributor frames for every CPU. It also handles the scenario in |
| 1307 | * which the frames of various CPUs are not contiguous in physical memory. |
| 1308 | ******************************************************************************/ |
| 1309 | int gicv3_rdistif_probe(const uintptr_t gicr_frame) |
| 1310 | { |
Heyi Guo | 3a579ae | 2020-05-19 11:50:40 +0800 | [diff] [blame] | 1311 | u_register_t mpidr, mpidr_self; |
| 1312 | unsigned int proc_num; |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1313 | uint64_t typer_val; |
| 1314 | uintptr_t rdistif_base; |
| 1315 | bool gicr_frame_found = false; |
| 1316 | |
| 1317 | assert(gicv3_driver_data->gicr_base == 0U); |
| 1318 | |
Channagoud kadabi | a037d97 | 2022-11-29 16:03:47 -0800 | [diff] [blame] | 1319 | if (plat_can_cmo()) { |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1320 | /* Ensure this function is called with Data Cache enabled */ |
| 1321 | #ifndef __aarch64__ |
Channagoud kadabi | a037d97 | 2022-11-29 16:03:47 -0800 | [diff] [blame] | 1322 | assert((read_sctlr() & SCTLR_C_BIT) != 0U); |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1323 | #else |
Channagoud kadabi | a037d97 | 2022-11-29 16:03:47 -0800 | [diff] [blame] | 1324 | assert((read_sctlr_el3() & SCTLR_C_BIT) != 0U); |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1325 | #endif /* !__aarch64__ */ |
Channagoud kadabi | a037d97 | 2022-11-29 16:03:47 -0800 | [diff] [blame] | 1326 | } |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1327 | |
Heyi Guo | 3a579ae | 2020-05-19 11:50:40 +0800 | [diff] [blame] | 1328 | mpidr_self = read_mpidr_el1() & MPIDR_AFFINITY_MASK; |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1329 | rdistif_base = gicr_frame; |
| 1330 | do { |
| 1331 | typer_val = gicr_read_typer(rdistif_base); |
Heyi Guo | 3a579ae | 2020-05-19 11:50:40 +0800 | [diff] [blame] | 1332 | mpidr = mpidr_from_gicr_typer(typer_val); |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1333 | if (gicv3_driver_data->mpidr_to_core_pos != NULL) { |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1334 | proc_num = gicv3_driver_data->mpidr_to_core_pos(mpidr); |
| 1335 | } else { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1336 | proc_num = (unsigned int)(typer_val >> |
| 1337 | TYPER_PROC_NUM_SHIFT) & TYPER_PROC_NUM_MASK; |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1338 | } |
Heyi Guo | 3a579ae | 2020-05-19 11:50:40 +0800 | [diff] [blame] | 1339 | if (mpidr == mpidr_self) { |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1340 | /* The base address doesn't need to be initialized on |
| 1341 | * every warm boot. |
| 1342 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1343 | if (gicv3_driver_data->rdistif_base_addrs[proc_num] |
| 1344 | != 0U) { |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1345 | return 0; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1346 | } |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1347 | gicv3_driver_data->rdistif_base_addrs[proc_num] = |
| 1348 | rdistif_base; |
| 1349 | gicr_frame_found = true; |
| 1350 | break; |
| 1351 | } |
Andre Przywara | f70f4b9 | 2021-05-18 15:51:06 +0100 | [diff] [blame] | 1352 | rdistif_base += gicv3_redist_size(typer_val); |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1353 | } while ((typer_val & TYPER_LAST_BIT) == 0U); |
| 1354 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1355 | if (!gicr_frame_found) { |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1356 | return -1; |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1357 | } |
Madhukar Pappireddy | 5fd1f9d | 2019-05-15 18:25:41 -0500 | [diff] [blame] | 1358 | |
| 1359 | /* |
| 1360 | * Flush the driver data to ensure coherency. This is |
| 1361 | * not required if platform has HW_ASSISTED_COHERENCY |
| 1362 | * enabled. |
| 1363 | */ |
| 1364 | #if !HW_ASSISTED_COHERENCY |
| 1365 | /* |
| 1366 | * Flush the rdistif_base_addrs[] contents linked to the GICv3 driver. |
| 1367 | */ |
| 1368 | flush_dcache_range((uintptr_t)&(gicv3_driver_data->rdistif_base_addrs[proc_num]), |
| 1369 | sizeof(*(gicv3_driver_data->rdistif_base_addrs))); |
| 1370 | #endif |
| 1371 | return 0; /* Found matching GICR frame */ |
| 1372 | } |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 1373 | |
| 1374 | /****************************************************************************** |
| 1375 | * This function checks the interrupt ID and returns true for SGIs and (E)PPIs |
| 1376 | * and false for (E)SPIs IDs. |
| 1377 | *****************************************************************************/ |
| 1378 | static bool is_sgi_ppi(unsigned int id) |
| 1379 | { |
| 1380 | /* SGIs: 0-15, PPIs: 16-31, EPPIs: 1056-1119 */ |
| 1381 | if (IS_SGI_PPI(id)) { |
| 1382 | return true; |
| 1383 | } |
| 1384 | |
| 1385 | /* SPIs: 32-1019, ESPIs: 4096-5119 */ |
| 1386 | if (IS_SPI(id)) { |
| 1387 | return false; |
| 1388 | } |
| 1389 | |
| 1390 | assert(false); |
| 1391 | panic(); |
| 1392 | } |