Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 1 | /* |
Heyi Guo | 691b49d | 2020-05-19 16:45:17 +0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2021, 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 | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef GICV3_PRIVATE_H |
| 8 | #define GICV3_PRIVATE_H |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 9 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 10 | #include <assert.h> |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 11 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
| 13 | #include <drivers/arm/gic_common.h> |
| 14 | #include <drivers/arm/gicv3.h> |
| 15 | #include <lib/mmio.h> |
| 16 | |
Jeenu Viswambharan | d7a901e | 2016-12-06 16:15:22 +0000 | [diff] [blame] | 17 | #include "../common/gic_common_private.h" |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 18 | |
| 19 | /******************************************************************************* |
| 20 | * GICv3 private macro definitions |
| 21 | ******************************************************************************/ |
| 22 | |
| 23 | /* Constants to indicate the status of the RWP bit */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 24 | #define RWP_TRUE U(1) |
| 25 | #define RWP_FALSE U(0) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 26 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 27 | /* Calculate GIC register bit number corresponding to its interrupt ID */ |
| 28 | #define BIT_NUM(REG, id) \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 29 | ((id) & ((1U << REG##R_SHIFT) - 1U)) |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 30 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 31 | /* |
| 32 | * Calculate 8, 32 and 64-bit GICD register offset |
| 33 | * corresponding to its interrupt ID |
| 34 | */ |
| 35 | #if GIC_EXT_INTID |
| 36 | /* GICv3.1 */ |
| 37 | #define GICD_OFFSET_8(REG, id) \ |
| 38 | (((id) <= MAX_SPI_ID) ? \ |
| 39 | GICD_##REG##R + (uintptr_t)(id) : \ |
| 40 | GICD_##REG##RE + (uintptr_t)(id) - MIN_ESPI_ID) |
| 41 | |
| 42 | #define GICD_OFFSET(REG, id) \ |
| 43 | (((id) <= MAX_SPI_ID) ? \ |
| 44 | GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) : \ |
| 45 | GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >> \ |
| 46 | REG##R_SHIFT) << 2)) |
| 47 | |
| 48 | #define GICD_OFFSET_64(REG, id) \ |
| 49 | (((id) <= MAX_SPI_ID) ? \ |
| 50 | GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3) : \ |
Heyi Guo | 691b49d | 2020-05-19 16:45:17 +0800 | [diff] [blame] | 51 | GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >> \ |
| 52 | REG##R_SHIFT) << 3)) |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 53 | |
| 54 | #else /* GICv3 */ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 55 | #define GICD_OFFSET_8(REG, id) \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 56 | (GICD_##REG##R + (uintptr_t)(id)) |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 57 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 58 | #define GICD_OFFSET(REG, id) \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 59 | (GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2)) |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 60 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 61 | #define GICD_OFFSET_64(REG, id) \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 62 | (GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3)) |
| 63 | #endif /* GIC_EXT_INTID */ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 64 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 65 | /* |
| 66 | * Read/Write 8, 32 and 64-bit GIC Distributor register |
| 67 | * corresponding to its interrupt ID |
| 68 | */ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 69 | #define GICD_READ(REG, base, id) \ |
| 70 | mmio_read_32((base) + GICD_OFFSET(REG, (id))) |
| 71 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 72 | #define GICD_READ_64(REG, base, id) \ |
| 73 | mmio_read_64((base) + GICD_OFFSET_64(REG, (id))) |
| 74 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 75 | #define GICD_WRITE_8(REG, base, id, val) \ |
| 76 | mmio_write_8((base) + GICD_OFFSET_8(REG, (id)), (val)) |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 77 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 78 | #define GICD_WRITE(REG, base, id, val) \ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 79 | mmio_write_32((base) + GICD_OFFSET(REG, (id)), (val)) |
| 80 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 81 | #define GICD_WRITE_64(REG, base, id, val) \ |
| 82 | mmio_write_64((base) + GICD_OFFSET_64(REG, (id)), (val)) |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Bit operations on GIC Distributor register corresponding |
| 86 | * to its interrupt ID |
| 87 | */ |
| 88 | /* Get bit in GIC Distributor register */ |
| 89 | #define GICD_GET_BIT(REG, base, id) \ |
| 90 | ((mmio_read_32((base) + GICD_OFFSET(REG, (id))) >> \ |
| 91 | BIT_NUM(REG, (id))) & 1U) |
| 92 | |
| 93 | /* Set bit in GIC Distributor register */ |
| 94 | #define GICD_SET_BIT(REG, base, id) \ |
| 95 | mmio_setbits_32((base) + GICD_OFFSET(REG, (id)), \ |
| 96 | ((uint32_t)1 << BIT_NUM(REG, (id)))) |
| 97 | |
| 98 | /* Clear bit in GIC Distributor register */ |
| 99 | #define GICD_CLR_BIT(REG, base, id) \ |
| 100 | mmio_clrbits_32((base) + GICD_OFFSET(REG, (id)), \ |
| 101 | ((uint32_t)1 << BIT_NUM(REG, (id)))) |
| 102 | |
| 103 | /* Write bit in GIC Distributor register */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 104 | #define GICD_WRITE_BIT(REG, base, id) \ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 105 | mmio_write_32((base) + GICD_OFFSET(REG, (id)), \ |
| 106 | ((uint32_t)1 << BIT_NUM(REG, (id)))) |
| 107 | |
| 108 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 109 | * Calculate 8 and 32-bit GICR register offset |
| 110 | * corresponding to its interrupt ID |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 111 | */ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 112 | #if GIC_EXT_INTID |
| 113 | /* GICv3.1 */ |
| 114 | #define GICR_OFFSET_8(REG, id) \ |
| 115 | (((id) <= MAX_PPI_ID) ? \ |
| 116 | GICR_##REG##R + (uintptr_t)(id) : \ |
| 117 | GICR_##REG##R + (uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID)) |
| 118 | |
| 119 | #define GICR_OFFSET(REG, id) \ |
| 120 | (((id) <= MAX_PPI_ID) ? \ |
| 121 | GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) : \ |
| 122 | GICR_##REG##R + ((((uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))\ |
| 123 | >> REG##R_SHIFT) << 2)) |
| 124 | #else /* GICv3 */ |
| 125 | #define GICR_OFFSET_8(REG, id) \ |
| 126 | (GICR_##REG##R + (uintptr_t)(id)) |
| 127 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 128 | #define GICR_OFFSET(REG, id) \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 129 | (GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2)) |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 130 | #endif /* GIC_EXT_INTID */ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 131 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 132 | /* Read/Write GIC Redistributor register corresponding to its interrupt ID */ |
| 133 | #define GICR_READ(REG, base, id) \ |
| 134 | mmio_read_32((base) + GICR_OFFSET(REG, (id))) |
| 135 | |
| 136 | #define GICR_WRITE_8(REG, base, id, val) \ |
| 137 | mmio_write_8((base) + GICR_OFFSET_8(REG, (id)), (val)) |
| 138 | |
| 139 | #define GICR_WRITE(REG, base, id, val) \ |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 140 | mmio_write_32((base) + GICR_OFFSET(REG, (id)), (val)) |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Bit operations on GIC Redistributor register |
| 144 | * corresponding to its interrupt ID |
| 145 | */ |
| 146 | /* Get bit in GIC Redistributor register */ |
| 147 | #define GICR_GET_BIT(REG, base, id) \ |
| 148 | ((mmio_read_32((base) + GICR_OFFSET(REG, (id))) >> \ |
| 149 | BIT_NUM(REG, (id))) & 1U) |
| 150 | |
| 151 | /* Write bit in GIC Redistributor register */ |
| 152 | #define GICR_WRITE_BIT(REG, base, id) \ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 153 | mmio_write_32((base) + GICR_OFFSET(REG, (id)), \ |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 154 | ((uint32_t)1 << BIT_NUM(REG, (id)))) |
| 155 | |
| 156 | /* Set bit in GIC Redistributor register */ |
| 157 | #define GICR_SET_BIT(REG, base, id) \ |
| 158 | mmio_setbits_32((base) + GICR_OFFSET(REG, (id)), \ |
| 159 | ((uint32_t)1 << BIT_NUM(REG, (id)))) |
| 160 | |
| 161 | /* Clear bit in GIC Redistributor register */ |
| 162 | #define GICR_CLR_BIT(REG, base, id) \ |
| 163 | mmio_clrbits_32((base) + GICR_OFFSET(REG, (id)), \ |
| 164 | ((uint32_t)1 << BIT_NUM(REG, (id)))) |
| 165 | |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 166 | /* |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 167 | * Macro to convert an mpidr to a value suitable for programming into a |
| 168 | * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant |
| 169 | * to GICv3. |
| 170 | */ |
Antonio Nino Diaz | dd4e59e | 2018-08-13 15:29:29 +0100 | [diff] [blame] | 171 | static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr, |
| 172 | unsigned int irm) |
| 173 | { |
| 174 | return (mpidr & ~(U(0xff) << 24)) | |
| 175 | ((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT); |
| 176 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 177 | |
| 178 | /* |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 179 | * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24] |
| 180 | * are zeroes. |
| 181 | */ |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 182 | #ifdef __aarch64__ |
Antonio Nino Diaz | dd4e59e | 2018-08-13 15:29:29 +0100 | [diff] [blame] | 183 | static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val) |
| 184 | { |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 185 | return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) | |
| 186 | ((typer_val >> 32) & U(0xffffff)); |
Antonio Nino Diaz | dd4e59e | 2018-08-13 15:29:29 +0100 | [diff] [blame] | 187 | } |
Soby Mathew | d645232 | 2016-05-05 13:59:07 +0100 | [diff] [blame] | 188 | #else |
Antonio Nino Diaz | dd4e59e | 2018-08-13 15:29:29 +0100 | [diff] [blame] | 189 | static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val) |
| 190 | { |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 191 | return (((typer_val) >> 32) & U(0xffffff)); |
Antonio Nino Diaz | dd4e59e | 2018-08-13 15:29:29 +0100 | [diff] [blame] | 192 | } |
Soby Mathew | d645232 | 2016-05-05 13:59:07 +0100 | [diff] [blame] | 193 | #endif |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 194 | |
| 195 | /******************************************************************************* |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 196 | * GICv3 private global variables declarations |
| 197 | ******************************************************************************/ |
| 198 | extern const gicv3_driver_data_t *gicv3_driver_data; |
| 199 | |
| 200 | /******************************************************************************* |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 201 | * Private GICv3 function prototypes for accessing entire registers. |
| 202 | * Note: The raw register values correspond to multiple interrupt IDs and |
| 203 | * the number of interrupt IDs involved depends on the register accessed. |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 204 | ******************************************************************************/ |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 205 | unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id); |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 206 | unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 207 | void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val); |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 208 | void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val); |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 209 | |
| 210 | /******************************************************************************* |
| 211 | * Private GICv3 function prototypes for accessing the GIC registers |
| 212 | * corresponding to a single interrupt ID. These functions use bitwise |
| 213 | * operations or appropriate register accesses to modify or return |
| 214 | * the bit-field corresponding the single interrupt ID. |
| 215 | ******************************************************************************/ |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 216 | unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 217 | unsigned int gicr_get_igrpmodr(uintptr_t base, unsigned int id); |
| 218 | unsigned int gicr_get_igroupr(uintptr_t base, unsigned int id); |
| 219 | unsigned int gicr_get_isactiver(uintptr_t base, unsigned int id); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 220 | void gicd_set_igrpmodr(uintptr_t base, unsigned int id); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 221 | void gicr_set_igrpmodr(uintptr_t base, unsigned int id); |
| 222 | void gicr_set_isenabler(uintptr_t base, unsigned int id); |
| 223 | void gicr_set_icenabler(uintptr_t base, unsigned int id); |
| 224 | void gicr_set_ispendr(uintptr_t base, unsigned int id); |
| 225 | void gicr_set_icpendr(uintptr_t base, unsigned int id); |
| 226 | void gicr_set_igroupr(uintptr_t base, unsigned int id); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 227 | void gicd_clr_igrpmodr(uintptr_t base, unsigned int id); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 228 | void gicr_clr_igrpmodr(uintptr_t base, unsigned int id); |
| 229 | void gicr_clr_igroupr(uintptr_t base, unsigned int id); |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 230 | void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 231 | void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg); |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 232 | |
| 233 | /******************************************************************************* |
| 234 | * Private GICv3 helper function prototypes |
| 235 | ******************************************************************************/ |
Heyi Guo | 06f85b4 | 2021-01-20 18:50:16 +0800 | [diff] [blame] | 236 | unsigned int gicv3_get_spi_limit(uintptr_t gicd_base); |
Heyi Guo | 60ce825 | 2021-01-20 18:50:16 +0800 | [diff] [blame^] | 237 | unsigned int gicv3_get_espi_limit(uintptr_t gicd_base); |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 238 | void gicv3_spis_config_defaults(uintptr_t gicd_base); |
| 239 | void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base); |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 240 | unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base, |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 241 | const interrupt_prop_t *interrupt_props, |
| 242 | unsigned int interrupt_props_num); |
Daniel Boulby | 4e83abb | 2018-05-01 15:15:34 +0100 | [diff] [blame] | 243 | unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base, |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 244 | const interrupt_prop_t *interrupt_props, |
| 245 | unsigned int interrupt_props_num); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 246 | void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs, |
| 247 | unsigned int rdistif_num, |
| 248 | uintptr_t gicr_base, |
| 249 | mpidr_hash_fn mpidr_to_core_pos); |
| 250 | void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base); |
| 251 | void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base); |
| 252 | |
| 253 | /******************************************************************************* |
| 254 | * GIC Distributor interface accessors |
| 255 | ******************************************************************************/ |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 256 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 257 | * Wait for updates to: |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 258 | * GICD_CTLR[2:0] - the Group Enables |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 259 | * GICD_CTLR[7:4] - the ARE bits, E1NWF bit and DS bit |
| 260 | * GICD_ICENABLER<n> - the clearing of enable state for SPIs |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 261 | */ |
| 262 | static inline void gicd_wait_for_pending_write(uintptr_t gicd_base) |
| 263 | { |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 264 | while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U) { |
| 265 | } |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 268 | static inline uint32_t gicd_read_pidr2(uintptr_t base) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 269 | { |
| 270 | return mmio_read_32(base + GICD_PIDR2_GICV3); |
| 271 | } |
| 272 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 273 | static inline uint64_t gicd_read_irouter(uintptr_t base, unsigned int id) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 274 | { |
Soby Mathew | aaf71c8 | 2016-07-26 17:46:56 +0100 | [diff] [blame] | 275 | assert(id >= MIN_SPI_ID); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 276 | return GICD_READ_64(IROUTE, base, id); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static inline void gicd_write_irouter(uintptr_t base, |
| 280 | unsigned int id, |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 281 | uint64_t affinity) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 282 | { |
Soby Mathew | aaf71c8 | 2016-07-26 17:46:56 +0100 | [diff] [blame] | 283 | assert(id >= MIN_SPI_ID); |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 284 | GICD_WRITE_64(IROUTE, base, id, affinity); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | static inline void gicd_clr_ctlr(uintptr_t base, |
| 288 | unsigned int bitmap, |
| 289 | unsigned int rwp) |
| 290 | { |
| 291 | gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap); |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 292 | if (rwp != 0U) { |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 293 | gicd_wait_for_pending_write(base); |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 294 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static inline void gicd_set_ctlr(uintptr_t base, |
| 298 | unsigned int bitmap, |
| 299 | unsigned int rwp) |
| 300 | { |
| 301 | gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap); |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 302 | if (rwp != 0U) { |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 303 | gicd_wait_for_pending_write(base); |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 304 | } |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /******************************************************************************* |
| 308 | * GIC Redistributor interface accessors |
| 309 | ******************************************************************************/ |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 310 | static inline uint32_t gicr_read_ctlr(uintptr_t base) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 311 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 312 | return mmio_read_32(base + GICR_CTLR); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 313 | } |
| 314 | |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 315 | static inline void gicr_write_ctlr(uintptr_t base, uint32_t val) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 316 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 317 | mmio_write_32(base + GICR_CTLR, val); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 320 | static inline uint64_t gicr_read_typer(uintptr_t base) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 321 | { |
| 322 | return mmio_read_64(base + GICR_TYPER); |
| 323 | } |
| 324 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 325 | static inline uint32_t gicr_read_waker(uintptr_t base) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 326 | { |
| 327 | return mmio_read_32(base + GICR_WAKER); |
| 328 | } |
| 329 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 330 | static inline void gicr_write_waker(uintptr_t base, uint32_t val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 331 | { |
| 332 | mmio_write_32(base + GICR_WAKER, val); |
| 333 | } |
| 334 | |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 335 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 336 | * Wait for updates to: |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 337 | * GICR_ICENABLER0 |
| 338 | * GICR_CTLR.DPG1S |
| 339 | * GICR_CTLR.DPG1NS |
| 340 | * GICR_CTLR.DPG0 |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 341 | * GICR_CTLR, which clears EnableLPIs from 1 to 0 |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 342 | */ |
| 343 | static inline void gicr_wait_for_pending_write(uintptr_t gicr_base) |
| 344 | { |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 345 | while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U) { |
| 346 | } |
Douglas Raillard | a1b1da8 | 2017-07-26 13:51:00 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 349 | static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base) |
| 350 | { |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 351 | while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U) { |
| 352 | } |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /* Private implementation of Distributor power control hooks */ |
| 356 | void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num); |
| 357 | void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num); |
| 358 | |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 359 | /******************************************************************************* |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 360 | * GIC Redistributor functions for accessing entire registers. |
Soby Mathew | 50f6fe4 | 2016-02-01 17:59:22 +0000 | [diff] [blame] | 361 | * Note: The raw register values correspond to multiple interrupt IDs and |
| 362 | * the number of interrupt IDs involved depends on the register accessed. |
| 363 | ******************************************************************************/ |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 364 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 365 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 366 | * Accessors to read/write GIC Redistributor ICENABLER0 register |
| 367 | */ |
| 368 | static inline unsigned int gicr_read_icenabler0(uintptr_t base) |
| 369 | { |
| 370 | return mmio_read_32(base + GICR_ICENABLER0); |
| 371 | } |
| 372 | |
| 373 | static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val) |
| 374 | { |
| 375 | mmio_write_32(base + GICR_ICENABLER0, val); |
| 376 | } |
| 377 | |
| 378 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 379 | * Accessors to read/write GIC Redistributor ICENABLER0 and ICENABLERE |
| 380 | * register corresponding to its number |
| 381 | */ |
| 382 | static inline unsigned int gicr_read_icenabler(uintptr_t base, |
| 383 | unsigned int reg_num) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 384 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 385 | return mmio_read_32(base + GICR_ICENABLER + (reg_num << 2)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 388 | static inline void gicr_write_icenabler(uintptr_t base, unsigned int reg_num, |
| 389 | unsigned int val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 390 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 391 | mmio_write_32(base + GICR_ICENABLER + (reg_num << 2), val); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 394 | /* |
| 395 | * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 registers |
| 396 | */ |
| 397 | static inline unsigned int gicr_read_icfgr0(uintptr_t base) |
| 398 | { |
| 399 | return mmio_read_32(base + GICR_ICFGR0); |
| 400 | } |
| 401 | |
| 402 | static inline unsigned int gicr_read_icfgr1(uintptr_t base) |
| 403 | { |
| 404 | return mmio_read_32(base + GICR_ICFGR1); |
| 405 | } |
| 406 | |
| 407 | static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val) |
| 408 | { |
| 409 | mmio_write_32(base + GICR_ICFGR0, val); |
| 410 | } |
| 411 | |
| 412 | static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val) |
| 413 | { |
| 414 | mmio_write_32(base + GICR_ICFGR1, val); |
| 415 | } |
| 416 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 417 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 418 | * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 and ICFGRE |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 419 | * register corresponding to its number |
| 420 | */ |
| 421 | static inline unsigned int gicr_read_icfgr(uintptr_t base, unsigned int reg_num) |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 422 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 423 | return mmio_read_32(base + GICR_ICFGR + (reg_num << 2)); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 426 | static inline void gicr_write_icfgr(uintptr_t base, unsigned int reg_num, |
| 427 | unsigned int val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 428 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 429 | mmio_write_32(base + GICR_ICFGR + (reg_num << 2), val); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 430 | } |
| 431 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 432 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 433 | * Accessor to write GIC Redistributor ICPENDR0 register |
| 434 | */ |
| 435 | static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val) |
| 436 | { |
| 437 | mmio_write_32(base + GICR_ICPENDR0, val); |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Accessor to write GIC Redistributor ICPENDR0 and ICPENDRE |
| 442 | * register corresponding to its number |
| 443 | */ |
| 444 | static inline void gicr_write_icpendr(uintptr_t base, unsigned int reg_num, |
| 445 | unsigned int val) |
| 446 | { |
| 447 | mmio_write_32(base + GICR_ICPENDR + (reg_num << 2), val); |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Accessors to read/write GIC Redistributor IGROUPR0 register |
| 452 | */ |
| 453 | static inline unsigned int gicr_read_igroupr0(uintptr_t base) |
| 454 | { |
| 455 | return mmio_read_32(base + GICR_IGROUPR0); |
| 456 | } |
| 457 | |
| 458 | static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val) |
| 459 | { |
| 460 | mmio_write_32(base + GICR_IGROUPR0, val); |
| 461 | } |
| 462 | |
| 463 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 464 | * Accessors to read/write GIC Redistributor IGROUPR0 and IGROUPRE |
| 465 | * register corresponding to its number |
| 466 | */ |
| 467 | static inline unsigned int gicr_read_igroupr(uintptr_t base, |
| 468 | unsigned int reg_num) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 469 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 470 | return mmio_read_32(base + GICR_IGROUPR + (reg_num << 2)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 473 | static inline void gicr_write_igroupr(uintptr_t base, unsigned int reg_num, |
| 474 | unsigned int val) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 475 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 476 | mmio_write_32(base + GICR_IGROUPR + (reg_num << 2), val); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 479 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 480 | * Accessors to read/write GIC Redistributor IGRPMODR0 register |
| 481 | */ |
| 482 | static inline unsigned int gicr_read_igrpmodr0(uintptr_t base) |
| 483 | { |
| 484 | return mmio_read_32(base + GICR_IGRPMODR0); |
| 485 | } |
| 486 | |
| 487 | static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val) |
| 488 | { |
| 489 | mmio_write_32(base + GICR_IGRPMODR0, val); |
| 490 | } |
| 491 | |
| 492 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 493 | * Accessors to read/write GIC Redistributor IGRPMODR0 and IGRPMODRE |
| 494 | * register corresponding to its number |
| 495 | */ |
| 496 | static inline unsigned int gicr_read_igrpmodr(uintptr_t base, |
| 497 | unsigned int reg_num) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 498 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 499 | return mmio_read_32(base + GICR_IGRPMODR + (reg_num << 2)); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 500 | } |
| 501 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 502 | static inline void gicr_write_igrpmodr(uintptr_t base, unsigned int reg_num, |
| 503 | unsigned int val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 504 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 505 | mmio_write_32(base + GICR_IGRPMODR + (reg_num << 2), val); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 508 | /* |
| 509 | * Accessors to read/write the GIC Redistributor IPRIORITYR(E) register |
| 510 | * corresponding to its number, 4 interrupts IDs at a time. |
| 511 | */ |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 512 | static inline unsigned int gicr_ipriorityr_read(uintptr_t base, |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 513 | unsigned int reg_num) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 514 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 515 | return mmio_read_32(base + GICR_IPRIORITYR + (reg_num << 2)); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 518 | static inline void gicr_ipriorityr_write(uintptr_t base, unsigned int reg_num, |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 519 | unsigned int val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 520 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 521 | mmio_write_32(base + GICR_IPRIORITYR + (reg_num << 2), val); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 524 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 525 | * Accessors to read/write GIC Redistributor ISACTIVER0 register |
| 526 | */ |
| 527 | static inline unsigned int gicr_read_isactiver0(uintptr_t base) |
| 528 | { |
| 529 | return mmio_read_32(base + GICR_ISACTIVER0); |
| 530 | } |
| 531 | |
| 532 | static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val) |
| 533 | { |
| 534 | mmio_write_32(base + GICR_ISACTIVER0, val); |
| 535 | } |
| 536 | |
| 537 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 538 | * Accessors to read/write GIC Redistributor ISACTIVER0 and ISACTIVERE |
| 539 | * register corresponding to its number |
| 540 | */ |
| 541 | static inline unsigned int gicr_read_isactiver(uintptr_t base, |
| 542 | unsigned int reg_num) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 543 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 544 | return mmio_read_32(base + GICR_ISACTIVER + (reg_num << 2)); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 547 | static inline void gicr_write_isactiver(uintptr_t base, unsigned int reg_num, |
| 548 | unsigned int val) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 549 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 550 | mmio_write_32(base + GICR_ISACTIVER + (reg_num << 2), val); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 551 | } |
| 552 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 553 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 554 | * Accessors to read/write GIC Redistributor ISENABLER0 register |
| 555 | */ |
| 556 | static inline unsigned int gicr_read_isenabler0(uintptr_t base) |
| 557 | { |
| 558 | return mmio_read_32(base + GICR_ISENABLER0); |
| 559 | } |
| 560 | |
| 561 | static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val) |
| 562 | { |
| 563 | mmio_write_32(base + GICR_ISENABLER0, val); |
| 564 | } |
| 565 | |
| 566 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 567 | * Accessors to read/write GIC Redistributor ISENABLER0 and ISENABLERE |
| 568 | * register corresponding to its number |
| 569 | */ |
| 570 | static inline unsigned int gicr_read_isenabler(uintptr_t base, |
| 571 | unsigned int reg_num) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 572 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 573 | return mmio_read_32(base + GICR_ISENABLER + (reg_num << 2)); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 574 | } |
| 575 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 576 | static inline void gicr_write_isenabler(uintptr_t base, unsigned int reg_num, |
| 577 | unsigned int val) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 578 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 579 | mmio_write_32(base + GICR_ISENABLER + (reg_num << 2), val); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 580 | } |
| 581 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 582 | /* |
Alexei Fedorov | c7510c5 | 2020-04-07 18:16:18 +0100 | [diff] [blame] | 583 | * Accessors to read/write GIC Redistributor ISPENDR0 register |
| 584 | */ |
| 585 | static inline unsigned int gicr_read_ispendr0(uintptr_t base) |
| 586 | { |
| 587 | return mmio_read_32(base + GICR_ISPENDR0); |
| 588 | } |
| 589 | |
| 590 | static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val) |
| 591 | { |
| 592 | mmio_write_32(base + GICR_ISPENDR0, val); |
| 593 | } |
| 594 | |
| 595 | /* |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 596 | * Accessors to read/write GIC Redistributor ISPENDR0 and ISPENDRE |
| 597 | * register corresponding to its number |
| 598 | */ |
| 599 | static inline unsigned int gicr_read_ispendr(uintptr_t base, |
| 600 | unsigned int reg_num) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 601 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 602 | return mmio_read_32(base + GICR_ISPENDR + (reg_num << 2)); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 605 | static inline void gicr_write_ispendr(uintptr_t base, unsigned int reg_num, |
| 606 | unsigned int val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 607 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 608 | mmio_write_32(base + GICR_ISPENDR + (reg_num << 2), val); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 611 | /* |
| 612 | * Accessors to read/write GIC Redistributor NSACR register |
| 613 | */ |
| 614 | static inline unsigned int gicr_read_nsacr(uintptr_t base) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 615 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 616 | return mmio_read_32(base + GICR_NSACR); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 617 | } |
| 618 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 619 | static inline void gicr_write_nsacr(uintptr_t base, unsigned int val) |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 620 | { |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 621 | mmio_write_32(base + GICR_NSACR, val); |
Achin Gupta | 92712a5 | 2015-09-03 14:18:02 +0100 | [diff] [blame] | 622 | } |
| 623 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 624 | /* |
| 625 | * Accessors to read/write GIC Redistributor PROPBASER register |
| 626 | */ |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 627 | static inline uint64_t gicr_read_propbaser(uintptr_t base) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 628 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 629 | return mmio_read_64(base + GICR_PROPBASER); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 632 | static inline void gicr_write_propbaser(uintptr_t base, uint64_t val) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 633 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 634 | mmio_write_64(base + GICR_PROPBASER, val); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 635 | } |
| 636 | |
Alexei Fedorov | a6e6ae0 | 2020-04-06 16:27:54 +0100 | [diff] [blame] | 637 | /* |
| 638 | * Accessors to read/write GIC Redistributor PENDBASER register |
| 639 | */ |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 640 | static inline uint64_t gicr_read_pendbaser(uintptr_t base) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 641 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 642 | return mmio_read_64(base + GICR_PENDBASER); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 643 | } |
| 644 | |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 645 | static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val) |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 646 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 647 | mmio_write_64(base + GICR_PENDBASER, val); |
Soby Mathew | 327548c | 2017-07-13 15:19:51 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 650 | /******************************************************************************* |
| 651 | * GIC ITS functions to read and write entire ITS registers. |
| 652 | ******************************************************************************/ |
| 653 | static inline uint32_t gits_read_ctlr(uintptr_t base) |
| 654 | { |
| 655 | return mmio_read_32(base + GITS_CTLR); |
| 656 | } |
| 657 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 658 | static inline void gits_write_ctlr(uintptr_t base, uint32_t val) |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 659 | { |
| 660 | mmio_write_32(base + GITS_CTLR, val); |
| 661 | } |
| 662 | |
| 663 | static inline uint64_t gits_read_cbaser(uintptr_t base) |
| 664 | { |
| 665 | return mmio_read_64(base + GITS_CBASER); |
| 666 | } |
| 667 | |
| 668 | static inline void gits_write_cbaser(uintptr_t base, uint64_t val) |
| 669 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 670 | mmio_write_64(base + GITS_CBASER, val); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | static inline uint64_t gits_read_cwriter(uintptr_t base) |
| 674 | { |
| 675 | return mmio_read_64(base + GITS_CWRITER); |
| 676 | } |
| 677 | |
| 678 | static inline void gits_write_cwriter(uintptr_t base, uint64_t val) |
| 679 | { |
Antonio Nino Diaz | bab39e8 | 2018-08-21 10:03:07 +0100 | [diff] [blame] | 680 | mmio_write_64(base + GITS_CWRITER, val); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 683 | static inline uint64_t gits_read_baser(uintptr_t base, |
| 684 | unsigned int its_table_id) |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 685 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 686 | assert(its_table_id < 8U); |
| 687 | return mmio_read_64(base + GITS_BASER + (8U * its_table_id)); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 690 | static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id, |
| 691 | uint64_t val) |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 692 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 693 | assert(its_table_id < 8U); |
| 694 | mmio_write_64(base + GITS_BASER + (8U * its_table_id), val); |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /* |
| 698 | * Wait for Quiescent bit when GIC ITS is disabled |
| 699 | */ |
| 700 | static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base) |
| 701 | { |
Antonio Nino Diaz | ca994e7 | 2018-08-21 10:02:33 +0100 | [diff] [blame] | 702 | assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U); |
Alexei Fedorov | 2f13d6c | 2020-02-21 10:17:26 +0000 | [diff] [blame] | 703 | while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U) { |
| 704 | } |
Soby Mathew | f6f1a32 | 2017-07-18 16:12:45 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 707 | #endif /* GICV3_PRIVATE_H */ |