Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 1 | /* |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 9 | #include <arch.h> |
| 10 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <common/debug.h> |
| 12 | #include <common/interrupt_props.h> |
| 13 | #include <drivers/arm/gic_common.h> |
| 14 | |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 15 | #include "../common/gic_common_private.h" |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 16 | #include "gicv3_private.h" |
| 17 | |
| 18 | /* |
| 19 | * Accessor to read the GIC Distributor IGRPMODR corresponding to the |
| 20 | * interrupt `id`, 32 interrupt IDs at a time. |
| 21 | */ |
| 22 | unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id) |
| 23 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 24 | unsigned int n = id >> IGRPMODR_SHIFT; |
| 25 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 26 | return mmio_read_32(base + GICD_IGRPMODR + (n << 2)); |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * Accessor to write the GIC Distributor IGRPMODR corresponding to the |
| 31 | * interrupt `id`, 32 interrupt IDs at a time. |
| 32 | */ |
| 33 | void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val) |
| 34 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 35 | unsigned int n = id >> IGRPMODR_SHIFT; |
| 36 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 37 | mmio_write_32(base + GICD_IGRPMODR + (n << 2), val); |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * Accessor to get the bit corresponding to interrupt ID |
| 42 | * in GIC Distributor IGRPMODR. |
| 43 | */ |
| 44 | unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id) |
| 45 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 46 | unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 47 | unsigned int reg_val = gicd_read_igrpmodr(base, id); |
| 48 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 49 | return (reg_val >> bit_num) & 0x1U; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Accessor to set the bit corresponding to interrupt ID |
| 54 | * in GIC Distributor IGRPMODR. |
| 55 | */ |
| 56 | void gicd_set_igrpmodr(uintptr_t base, unsigned int id) |
| 57 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 58 | unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 59 | unsigned int reg_val = gicd_read_igrpmodr(base, id); |
| 60 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 61 | gicd_write_igrpmodr(base, id, reg_val | (1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Accessor to clear the bit corresponding to interrupt ID |
| 66 | * in GIC Distributor IGRPMODR. |
| 67 | */ |
| 68 | void gicd_clr_igrpmodr(uintptr_t base, unsigned int id) |
| 69 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 70 | unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 71 | unsigned int reg_val = gicd_read_igrpmodr(base, id); |
| 72 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 73 | gicd_write_igrpmodr(base, id, reg_val & ~(1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Accessor to read the GIC Re-distributor IPRIORITYR corresponding to the |
| 78 | * interrupt `id`, 4 interrupts IDs at a time. |
| 79 | */ |
| 80 | unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id) |
| 81 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 82 | unsigned int n = id >> IPRIORITYR_SHIFT; |
| 83 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 84 | return mmio_read_32(base + GICR_IPRIORITYR + (n << 2)); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Accessor to write the GIC Re-distributor IPRIORITYR corresponding to the |
| 89 | * interrupt `id`, 4 interrupts IDs at a time. |
| 90 | */ |
| 91 | void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val) |
| 92 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 93 | unsigned int n = id >> IPRIORITYR_SHIFT; |
| 94 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 95 | mmio_write_32(base + GICR_IPRIORITYR + (n << 2), val); |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Accessor to get the bit corresponding to interrupt ID |
| 100 | * from GIC Re-distributor IGROUPR0. |
| 101 | */ |
| 102 | unsigned int gicr_get_igroupr0(uintptr_t base, unsigned int id) |
| 103 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 104 | unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 105 | unsigned int reg_val = gicr_read_igroupr0(base); |
| 106 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 107 | return (reg_val >> bit_num) & 0x1U; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Accessor to set the bit corresponding to interrupt ID |
| 112 | * in GIC Re-distributor IGROUPR0. |
| 113 | */ |
| 114 | void gicr_set_igroupr0(uintptr_t base, unsigned int id) |
| 115 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 116 | unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 117 | unsigned int reg_val = gicr_read_igroupr0(base); |
| 118 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 119 | gicr_write_igroupr0(base, reg_val | (1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Accessor to clear the bit corresponding to interrupt ID |
| 124 | * in GIC Re-distributor IGROUPR0. |
| 125 | */ |
| 126 | void gicr_clr_igroupr0(uintptr_t base, unsigned int id) |
| 127 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 128 | unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 129 | unsigned int reg_val = gicr_read_igroupr0(base); |
| 130 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 131 | gicr_write_igroupr0(base, reg_val & ~(1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Accessor to get the bit corresponding to interrupt ID |
| 136 | * from GIC Re-distributor IGRPMODR0. |
| 137 | */ |
| 138 | unsigned int gicr_get_igrpmodr0(uintptr_t base, unsigned int id) |
| 139 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 140 | unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 141 | unsigned int reg_val = gicr_read_igrpmodr0(base); |
| 142 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 143 | return (reg_val >> bit_num) & 0x1U; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Accessor to set the bit corresponding to interrupt ID |
| 148 | * in GIC Re-distributor IGRPMODR0. |
| 149 | */ |
| 150 | void gicr_set_igrpmodr0(uintptr_t base, unsigned int id) |
| 151 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 152 | unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 153 | unsigned int reg_val = gicr_read_igrpmodr0(base); |
| 154 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 155 | gicr_write_igrpmodr0(base, reg_val | (1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Accessor to clear the bit corresponding to interrupt ID |
| 160 | * in GIC Re-distributor IGRPMODR0. |
| 161 | */ |
| 162 | void gicr_clr_igrpmodr0(uintptr_t base, unsigned int id) |
| 163 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 164 | unsigned int bit_num = id & ((1U << IGRPMODR_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 165 | unsigned int reg_val = gicr_read_igrpmodr0(base); |
| 166 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 167 | gicr_write_igrpmodr0(base, reg_val & ~(1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Accessor to set the bit corresponding to interrupt ID |
| 172 | * in GIC Re-distributor ISENABLER0. |
| 173 | */ |
| 174 | void gicr_set_isenabler0(uintptr_t base, unsigned int id) |
| 175 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 176 | unsigned int bit_num = id & ((1U << ISENABLER_SHIFT) - 1U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 177 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 178 | gicr_write_isenabler0(base, (1U << bit_num)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Soby Mathew | 421259e | 2016-01-15 14:20:57 +0000 | [diff] [blame] | 181 | /* |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 182 | * Accessor to set the bit corresponding to interrupt ID in GIC Re-distributor |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 183 | * ICENABLER0. |
| 184 | */ |
| 185 | void gicr_set_icenabler0(uintptr_t base, unsigned int id) |
| 186 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 187 | unsigned int bit_num = id & ((1U << ICENABLER_SHIFT) - 1U); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 188 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 189 | gicr_write_icenabler0(base, (1U << bit_num)); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Accessor to set the bit corresponding to interrupt ID in GIC Re-distributor |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 194 | * ISACTIVER0. |
| 195 | */ |
| 196 | unsigned int gicr_get_isactiver0(uintptr_t base, unsigned int id) |
| 197 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 198 | unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U); |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 199 | unsigned int reg_val = gicr_read_isactiver0(base); |
| 200 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 201 | return (reg_val >> bit_num) & 0x1U; |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 205 | * Accessor to clear the bit corresponding to interrupt ID in GIC Re-distributor |
| 206 | * ICPENDRR0. |
| 207 | */ |
| 208 | void gicr_set_icpendr0(uintptr_t base, unsigned int id) |
| 209 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 210 | unsigned int bit_num = id & ((1U << ICPENDR_SHIFT) - 1U); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 211 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 212 | gicr_write_icpendr0(base, (1U << bit_num)); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Accessor to set the bit corresponding to interrupt ID in GIC Re-distributor |
| 217 | * ISPENDR0. |
| 218 | */ |
| 219 | void gicr_set_ispendr0(uintptr_t base, unsigned int id) |
| 220 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 221 | unsigned int bit_num = id & ((1U << ISPENDR_SHIFT) - 1U); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 222 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 223 | gicr_write_ispendr0(base, (1U << bit_num)); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /* |
Soby Mathew | 421259e | 2016-01-15 14:20:57 +0000 | [diff] [blame] | 227 | * Accessor to set the byte corresponding to interrupt ID |
| 228 | * in GIC Re-distributor IPRIORITYR. |
| 229 | */ |
| 230 | void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri) |
| 231 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 232 | uint8_t val = pri & GIC_PRI_MASK; |
| 233 | |
| 234 | mmio_write_8(base + GICR_IPRIORITYR + id, val); |
Soby Mathew | 421259e | 2016-01-15 14:20:57 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Jeenu Viswambharan | 4684bce | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 237 | /* |
| 238 | * Accessor to set the bit fields corresponding to interrupt ID |
| 239 | * in GIC Re-distributor ICFGR0. |
| 240 | */ |
| 241 | void gicr_set_icfgr0(uintptr_t base, unsigned int id, unsigned int cfg) |
| 242 | { |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 243 | /* Interrupt configuration is a 2-bit field */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 244 | unsigned int bit_num = id & ((1U << ICFGR_SHIFT) - 1U); |
| 245 | unsigned int bit_shift = bit_num << 1U; |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 246 | |
Jeenu Viswambharan | 4684bce | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 247 | uint32_t reg_val = gicr_read_icfgr0(base); |
| 248 | |
| 249 | /* Clear the field, and insert required configuration */ |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 250 | reg_val &= ~(GIC_CFG_MASK << bit_shift); |
| 251 | reg_val |= ((cfg & GIC_CFG_MASK) << bit_shift); |
Jeenu Viswambharan | 4684bce | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 252 | |
| 253 | gicr_write_icfgr0(base, reg_val); |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | * Accessor to set the bit fields corresponding to interrupt ID |
| 258 | * in GIC Re-distributor ICFGR1. |
| 259 | */ |
| 260 | void gicr_set_icfgr1(uintptr_t base, unsigned int id, unsigned int cfg) |
| 261 | { |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 262 | /* Interrupt configuration is a 2-bit field */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 263 | unsigned int bit_num = id & ((1U << ICFGR_SHIFT) - 1U); |
| 264 | unsigned int bit_shift = bit_num << 1U; |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 265 | |
Jeenu Viswambharan | 4684bce | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 266 | uint32_t reg_val = gicr_read_icfgr1(base); |
| 267 | |
| 268 | /* Clear the field, and insert required configuration */ |
Jeenu Viswambharan | b6982c0 | 2018-03-22 08:57:52 +0000 | [diff] [blame] | 269 | reg_val &= ~(GIC_CFG_MASK << bit_shift); |
| 270 | reg_val |= ((cfg & GIC_CFG_MASK) << bit_shift); |
Jeenu Viswambharan | 4684bce | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 271 | |
| 272 | gicr_write_icfgr1(base, reg_val); |
| 273 | } |
| 274 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 275 | /****************************************************************************** |
| 276 | * This function marks the core as awake in the re-distributor and |
| 277 | * ensures that the interface is active. |
| 278 | *****************************************************************************/ |
| 279 | void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base) |
| 280 | { |
| 281 | /* |
| 282 | * The WAKER_PS_BIT should be changed to 0 |
| 283 | * only when WAKER_CA_BIT is 1. |
| 284 | */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 285 | assert((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 286 | |
| 287 | /* Mark the connected core as awake */ |
| 288 | gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) & ~WAKER_PS_BIT); |
| 289 | |
| 290 | /* Wait till the WAKER_CA_BIT changes to 0 */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 291 | while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) != 0U) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 292 | ; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /****************************************************************************** |
| 297 | * This function marks the core as asleep in the re-distributor and ensures |
| 298 | * that the interface is quiescent. |
| 299 | *****************************************************************************/ |
| 300 | void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base) |
| 301 | { |
| 302 | /* Mark the connected core as asleep */ |
| 303 | gicr_write_waker(gicr_base, gicr_read_waker(gicr_base) | WAKER_PS_BIT); |
| 304 | |
| 305 | /* Wait till the WAKER_CA_BIT changes to 1 */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 306 | while ((gicr_read_waker(gicr_base) & WAKER_CA_BIT) == 0U) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 307 | ; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | /******************************************************************************* |
| 312 | * This function probes the Redistributor frames when the driver is initialised |
| 313 | * and saves their base addresses. These base addresses are used later to |
| 314 | * initialise each Redistributor interface. |
| 315 | ******************************************************************************/ |
| 316 | void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs, |
| 317 | unsigned int rdistif_num, |
| 318 | uintptr_t gicr_base, |
| 319 | mpidr_hash_fn mpidr_to_core_pos) |
| 320 | { |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 321 | u_register_t mpidr; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 322 | unsigned int proc_num; |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 323 | uint64_t typer_val; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 324 | uintptr_t rdistif_base = gicr_base; |
| 325 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 326 | assert(rdistif_base_addrs != NULL); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * Iterate over the Redistributor frames. Store the base address of each |
| 330 | * frame in the platform provided array. Use the "Processor Number" |
| 331 | * field to index into the array if the platform has not provided a hash |
| 332 | * function to convert an MPIDR (obtained from the "Affinity Value" |
| 333 | * field into a linear index. |
| 334 | */ |
| 335 | do { |
| 336 | typer_val = gicr_read_typer(rdistif_base); |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 337 | if (mpidr_to_core_pos != NULL) { |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 338 | mpidr = mpidr_from_gicr_typer(typer_val); |
| 339 | proc_num = mpidr_to_core_pos(mpidr); |
| 340 | } else { |
| 341 | proc_num = (typer_val >> TYPER_PROC_NUM_SHIFT) & |
| 342 | TYPER_PROC_NUM_MASK; |
| 343 | } |
Soby Mathew | d1463bd | 2019-01-17 14:57:54 +0000 | [diff] [blame^] | 344 | |
| 345 | if (proc_num < rdistif_num) |
| 346 | rdistif_base_addrs[proc_num] = rdistif_base; |
| 347 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 348 | rdistif_base += (1U << GICR_PCPUBASE_SHIFT); |
| 349 | } while ((typer_val & TYPER_LAST_BIT) == 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /******************************************************************************* |
| 353 | * Helper function to configure the default attributes of SPIs. |
| 354 | ******************************************************************************/ |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 355 | void gicv3_spis_config_defaults(uintptr_t gicd_base) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 356 | { |
| 357 | unsigned int index, num_ints; |
| 358 | |
| 359 | num_ints = gicd_read_typer(gicd_base); |
| 360 | num_ints &= TYPER_IT_LINES_NO_MASK; |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 361 | num_ints = (num_ints + 1U) << 5; |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 362 | |
| 363 | /* |
| 364 | * Treat all SPIs as G1NS by default. The number of interrupts is |
| 365 | * calculated as 32 * (IT_LINES + 1). We do 32 at a time. |
| 366 | */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 367 | for (index = MIN_SPI_ID; index < num_ints; index += 32U) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 368 | gicd_write_igroupr(gicd_base, index, ~0U); |
| 369 | |
| 370 | /* Setup the default SPI priorities doing four at a time */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 371 | for (index = MIN_SPI_ID; index < num_ints; index += 4U) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 372 | gicd_write_ipriorityr(gicd_base, |
| 373 | index, |
| 374 | GICD_IPRIORITYR_DEF_VAL); |
| 375 | |
| 376 | /* |
| 377 | * Treat all SPIs as level triggered by default, write 16 at |
| 378 | * a time |
| 379 | */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 380 | for (index = MIN_SPI_ID; index < num_ints; index += 16U) |
| 381 | gicd_write_icfgr(gicd_base, index, 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 384 | /******************************************************************************* |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 385 | * Helper function to configure properties of secure SPIs |
| 386 | ******************************************************************************/ |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 387 | unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base, |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 388 | const interrupt_prop_t *interrupt_props, |
| 389 | unsigned int interrupt_props_num) |
| 390 | { |
| 391 | unsigned int i; |
| 392 | const interrupt_prop_t *current_prop; |
| 393 | unsigned long long gic_affinity_val; |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 394 | unsigned int ctlr_enable = 0U; |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 395 | |
| 396 | /* Make sure there's a valid property array */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 397 | if (interrupt_props_num > 0U) |
| 398 | assert(interrupt_props != NULL); |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 399 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 400 | for (i = 0U; i < interrupt_props_num; i++) { |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 401 | current_prop = &interrupt_props[i]; |
| 402 | |
| 403 | if (current_prop->intr_num < MIN_SPI_ID) |
| 404 | continue; |
| 405 | |
| 406 | /* Configure this interrupt as a secure interrupt */ |
| 407 | gicd_clr_igroupr(gicd_base, current_prop->intr_num); |
| 408 | |
| 409 | /* Configure this interrupt as G0 or a G1S interrupt */ |
| 410 | assert((current_prop->intr_grp == INTR_GROUP0) || |
| 411 | (current_prop->intr_grp == INTR_GROUP1S)); |
| 412 | if (current_prop->intr_grp == INTR_GROUP1S) { |
| 413 | gicd_set_igrpmodr(gicd_base, current_prop->intr_num); |
| 414 | ctlr_enable |= CTLR_ENABLE_G1S_BIT; |
| 415 | } else { |
| 416 | gicd_clr_igrpmodr(gicd_base, current_prop->intr_num); |
| 417 | ctlr_enable |= CTLR_ENABLE_G0_BIT; |
| 418 | } |
| 419 | |
| 420 | /* Set interrupt configuration */ |
| 421 | gicd_set_icfgr(gicd_base, current_prop->intr_num, |
| 422 | current_prop->intr_cfg); |
| 423 | |
| 424 | /* Set the priority of this interrupt */ |
| 425 | gicd_set_ipriorityr(gicd_base, current_prop->intr_num, |
| 426 | current_prop->intr_pri); |
| 427 | |
| 428 | /* Target SPIs to the primary CPU */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 429 | gic_affinity_val = |
| 430 | gicd_irouter_val_from_mpidr(read_mpidr(), 0U); |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 431 | gicd_write_irouter(gicd_base, current_prop->intr_num, |
| 432 | gic_affinity_val); |
| 433 | |
| 434 | /* Enable this interrupt */ |
| 435 | gicd_set_isenabler(gicd_base, current_prop->intr_num); |
| 436 | } |
| 437 | |
| 438 | return ctlr_enable; |
| 439 | } |
| 440 | |
| 441 | /******************************************************************************* |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 442 | * Helper function to configure the default attributes of SPIs. |
| 443 | ******************************************************************************/ |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 444 | void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 445 | { |
| 446 | unsigned int index; |
| 447 | |
| 448 | /* |
| 449 | * Disable all SGIs (imp. def.)/PPIs before configuring them. This is a |
| 450 | * more scalable approach as it avoids clearing the enable bits in the |
| 451 | * GICD_CTLR |
| 452 | */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 453 | gicr_write_icenabler0(gicr_base, ~0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 454 | gicr_wait_for_pending_write(gicr_base); |
| 455 | |
| 456 | /* Treat all SGIs/PPIs as G1NS by default. */ |
| 457 | gicr_write_igroupr0(gicr_base, ~0U); |
| 458 | |
| 459 | /* Setup the default PPI/SGI priorities doing four at a time */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 460 | for (index = 0U; index < MIN_SPI_ID; index += 4U) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 461 | gicr_write_ipriorityr(gicr_base, |
| 462 | index, |
| 463 | GICD_IPRIORITYR_DEF_VAL); |
| 464 | |
| 465 | /* Configure all PPIs as level triggered by default */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 466 | gicr_write_icfgr1(gicr_base, 0U); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 467 | } |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 468 | |
| 469 | /******************************************************************************* |
| 470 | * Helper function to configure properties of secure G0 and G1S PPIs and SGIs. |
| 471 | ******************************************************************************/ |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 472 | unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base, |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 473 | const interrupt_prop_t *interrupt_props, |
| 474 | unsigned int interrupt_props_num) |
| 475 | { |
| 476 | unsigned int i; |
| 477 | const interrupt_prop_t *current_prop; |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 478 | unsigned int ctlr_enable = 0U; |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 479 | |
| 480 | /* Make sure there's a valid property array */ |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 481 | if (interrupt_props_num > 0U) |
| 482 | assert(interrupt_props != NULL); |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 483 | |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 484 | for (i = 0U; i < interrupt_props_num; i++) { |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 485 | current_prop = &interrupt_props[i]; |
| 486 | |
| 487 | if (current_prop->intr_num >= MIN_SPI_ID) |
| 488 | continue; |
| 489 | |
| 490 | /* Configure this interrupt as a secure interrupt */ |
| 491 | gicr_clr_igroupr0(gicr_base, current_prop->intr_num); |
| 492 | |
| 493 | /* Configure this interrupt as G0 or a G1S interrupt */ |
| 494 | assert((current_prop->intr_grp == INTR_GROUP0) || |
| 495 | (current_prop->intr_grp == INTR_GROUP1S)); |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 496 | if (current_prop->intr_grp == INTR_GROUP1S) { |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 497 | gicr_set_igrpmodr0(gicr_base, current_prop->intr_num); |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 498 | ctlr_enable |= CTLR_ENABLE_G1S_BIT; |
| 499 | } else { |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 500 | gicr_clr_igrpmodr0(gicr_base, current_prop->intr_num); |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 501 | ctlr_enable |= CTLR_ENABLE_G0_BIT; |
| 502 | } |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 503 | |
| 504 | /* Set the priority of this interrupt */ |
| 505 | gicr_set_ipriorityr(gicr_base, current_prop->intr_num, |
| 506 | current_prop->intr_pri); |
| 507 | |
| 508 | /* |
| 509 | * Set interrupt configuration for PPIs. Configuration for SGIs |
| 510 | * are ignored. |
| 511 | */ |
| 512 | if ((current_prop->intr_num >= MIN_PPI_ID) && |
| 513 | (current_prop->intr_num < MIN_SPI_ID)) { |
| 514 | gicr_set_icfgr1(gicr_base, current_prop->intr_num, |
| 515 | current_prop->intr_cfg); |
| 516 | } |
| 517 | |
| 518 | /* Enable this interrupt */ |
| 519 | gicr_set_isenabler0(gicr_base, current_prop->intr_num); |
| 520 | } |
Jeenu Viswambharan | 88d8f45 | 2017-11-07 08:38:23 +0000 | [diff] [blame] | 521 | |
| 522 | return ctlr_enable; |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 523 | } |