Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __GIC_V2_H__ |
| 8 | #define __GIC_V2_H__ |
| 9 | |
Soby Mathew | 3ddc972 | 2015-10-26 14:32:09 +0000 | [diff] [blame] | 10 | /****************************************************************************** |
| 11 | * THIS DRIVER IS DEPRECATED. For GICv2 systems, use the driver in gicv2.h |
| 12 | * and for GICv3 systems, use the driver in gicv3.h. |
| 13 | *****************************************************************************/ |
| 14 | #if ERROR_DEPRECATED |
| 15 | #error " The legacy ARM GIC driver is deprecated." |
| 16 | #endif |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 17 | |
| 18 | #define GIC400_NUM_SPIS 480 |
| 19 | #define MAX_PPIS 14 |
| 20 | #define MAX_SGIS 16 |
| 21 | |
Dan Handley | fb42b12 | 2014-06-20 09:43:15 +0100 | [diff] [blame] | 22 | #define MIN_SGI_ID 0 |
| 23 | #define MIN_PPI_ID 16 |
| 24 | #define MIN_SPI_ID 32 |
| 25 | |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 26 | #define GRP0 0 |
| 27 | #define GRP1 1 |
| 28 | #define GIC_PRI_MASK 0xff |
| 29 | #define GIC_HIGHEST_SEC_PRIORITY 0 |
| 30 | #define GIC_LOWEST_SEC_PRIORITY 127 |
| 31 | #define GIC_HIGHEST_NS_PRIORITY 128 |
| 32 | #define GIC_LOWEST_NS_PRIORITY 254 /* 255 would disable an interrupt */ |
Achin Gupta | 02d3628 | 2014-05-04 19:02:52 +0100 | [diff] [blame] | 33 | #define GIC_SPURIOUS_INTERRUPT 1023 |
Juan Castillo | 8231295 | 2014-10-20 12:27:28 +0100 | [diff] [blame] | 34 | #define GIC_TARGET_CPU_MASK 0xff |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 35 | |
| 36 | #define ENABLE_GRP0 (1 << 0) |
| 37 | #define ENABLE_GRP1 (1 << 1) |
| 38 | |
| 39 | /* Distributor interface definitions */ |
| 40 | #define GICD_CTLR 0x0 |
| 41 | #define GICD_TYPER 0x4 |
| 42 | #define GICD_IGROUPR 0x80 |
| 43 | #define GICD_ISENABLER 0x100 |
| 44 | #define GICD_ICENABLER 0x180 |
| 45 | #define GICD_ISPENDR 0x200 |
| 46 | #define GICD_ICPENDR 0x280 |
| 47 | #define GICD_ISACTIVER 0x300 |
| 48 | #define GICD_ICACTIVER 0x380 |
| 49 | #define GICD_IPRIORITYR 0x400 |
| 50 | #define GICD_ITARGETSR 0x800 |
| 51 | #define GICD_ICFGR 0xC00 |
| 52 | #define GICD_SGIR 0xF00 |
| 53 | #define GICD_CPENDSGIR 0xF10 |
| 54 | #define GICD_SPENDSGIR 0xF20 |
| 55 | |
| 56 | #define IGROUPR_SHIFT 5 |
| 57 | #define ISENABLER_SHIFT 5 |
| 58 | #define ICENABLER_SHIFT ISENABLER_SHIFT |
| 59 | #define ISPENDR_SHIFT 5 |
| 60 | #define ICPENDR_SHIFT ISPENDR_SHIFT |
| 61 | #define ISACTIVER_SHIFT 5 |
| 62 | #define ICACTIVER_SHIFT ISACTIVER_SHIFT |
| 63 | #define IPRIORITYR_SHIFT 2 |
| 64 | #define ITARGETSR_SHIFT 2 |
| 65 | #define ICFGR_SHIFT 4 |
| 66 | #define CPENDSGIR_SHIFT 2 |
| 67 | #define SPENDSGIR_SHIFT CPENDSGIR_SHIFT |
| 68 | |
| 69 | /* GICD_TYPER bit definitions */ |
| 70 | #define IT_LINES_NO_MASK 0x1f |
| 71 | |
| 72 | /* Physical CPU Interface registers */ |
| 73 | #define GICC_CTLR 0x0 |
| 74 | #define GICC_PMR 0x4 |
| 75 | #define GICC_BPR 0x8 |
| 76 | #define GICC_IAR 0xC |
| 77 | #define GICC_EOIR 0x10 |
| 78 | #define GICC_RPR 0x14 |
| 79 | #define GICC_HPPIR 0x18 |
Achin Gupta | 02d3628 | 2014-05-04 19:02:52 +0100 | [diff] [blame] | 80 | #define GICC_AHPPIR 0x28 |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 81 | #define GICC_IIDR 0xFC |
| 82 | #define GICC_DIR 0x1000 |
| 83 | #define GICC_PRIODROP GICC_EOIR |
| 84 | |
Achin Gupta | 966b952 | 2015-05-18 10:56:47 +0100 | [diff] [blame] | 85 | /* Common CPU Interface definitions */ |
| 86 | #define INT_ID_MASK 0x3ff |
| 87 | |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 88 | /* GICC_CTLR bit definitions */ |
| 89 | #define EOI_MODE_NS (1 << 10) |
| 90 | #define EOI_MODE_S (1 << 9) |
| 91 | #define IRQ_BYP_DIS_GRP1 (1 << 8) |
| 92 | #define FIQ_BYP_DIS_GRP1 (1 << 7) |
| 93 | #define IRQ_BYP_DIS_GRP0 (1 << 6) |
| 94 | #define FIQ_BYP_DIS_GRP0 (1 << 5) |
| 95 | #define CBPR (1 << 4) |
| 96 | #define FIQ_EN (1 << 3) |
| 97 | #define ACK_CTL (1 << 2) |
| 98 | |
| 99 | /* GICC_IIDR bit masks and shifts */ |
| 100 | #define GICC_IIDR_PID_SHIFT 20 |
| 101 | #define GICC_IIDR_ARCH_SHIFT 16 |
| 102 | #define GICC_IIDR_REV_SHIFT 12 |
| 103 | #define GICC_IIDR_IMP_SHIFT 0 |
| 104 | |
| 105 | #define GICC_IIDR_PID_MASK 0xfff |
| 106 | #define GICC_IIDR_ARCH_MASK 0xf |
| 107 | #define GICC_IIDR_REV_MASK 0xf |
| 108 | #define GICC_IIDR_IMP_MASK 0xfff |
| 109 | |
| 110 | /* HYP view virtual CPU Interface registers */ |
| 111 | #define GICH_CTL 0x0 |
| 112 | #define GICH_VTR 0x4 |
| 113 | #define GICH_ELRSR0 0x30 |
| 114 | #define GICH_ELRSR1 0x34 |
| 115 | #define GICH_APR0 0xF0 |
| 116 | #define GICH_LR_BASE 0x100 |
| 117 | |
| 118 | /* Virtual CPU Interface registers */ |
| 119 | #define GICV_CTL 0x0 |
| 120 | #define GICV_PRIMASK 0x4 |
| 121 | #define GICV_BP 0x8 |
| 122 | #define GICV_INTACK 0xC |
| 123 | #define GICV_EOI 0x10 |
| 124 | #define GICV_RUNNINGPRI 0x14 |
| 125 | #define GICV_HIGHESTPEND 0x18 |
| 126 | #define GICV_DEACTIVATE 0x1000 |
| 127 | |
| 128 | #ifndef __ASSEMBLY__ |
| 129 | |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 130 | #include <mmio.h> |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 131 | #include <stdint.h> |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 132 | |
| 133 | /******************************************************************************* |
| 134 | * GIC Distributor function prototypes |
| 135 | ******************************************************************************/ |
| 136 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 137 | unsigned int gicd_read_igroupr(uintptr_t, unsigned int); |
| 138 | unsigned int gicd_read_isenabler(uintptr_t, unsigned int); |
| 139 | unsigned int gicd_read_icenabler(uintptr_t, unsigned int); |
| 140 | unsigned int gicd_read_ispendr(uintptr_t, unsigned int); |
| 141 | unsigned int gicd_read_icpendr(uintptr_t, unsigned int); |
| 142 | unsigned int gicd_read_isactiver(uintptr_t, unsigned int); |
| 143 | unsigned int gicd_read_icactiver(uintptr_t, unsigned int); |
| 144 | unsigned int gicd_read_ipriorityr(uintptr_t, unsigned int); |
| 145 | unsigned int gicd_read_itargetsr(uintptr_t, unsigned int); |
| 146 | unsigned int gicd_read_icfgr(uintptr_t, unsigned int); |
| 147 | unsigned int gicd_read_cpendsgir(uintptr_t, unsigned int); |
| 148 | unsigned int gicd_read_spendsgir(uintptr_t, unsigned int); |
| 149 | void gicd_write_igroupr(uintptr_t, unsigned int, unsigned int); |
| 150 | void gicd_write_isenabler(uintptr_t, unsigned int, unsigned int); |
| 151 | void gicd_write_icenabler(uintptr_t, unsigned int, unsigned int); |
| 152 | void gicd_write_ispendr(uintptr_t, unsigned int, unsigned int); |
| 153 | void gicd_write_icpendr(uintptr_t, unsigned int, unsigned int); |
| 154 | void gicd_write_isactiver(uintptr_t, unsigned int, unsigned int); |
| 155 | void gicd_write_icactiver(uintptr_t, unsigned int, unsigned int); |
| 156 | void gicd_write_ipriorityr(uintptr_t, unsigned int, unsigned int); |
| 157 | void gicd_write_itargetsr(uintptr_t, unsigned int, unsigned int); |
| 158 | void gicd_write_icfgr(uintptr_t, unsigned int, unsigned int); |
| 159 | void gicd_write_cpendsgir(uintptr_t, unsigned int, unsigned int); |
| 160 | void gicd_write_spendsgir(uintptr_t, unsigned int, unsigned int); |
| 161 | unsigned int gicd_get_igroupr(uintptr_t, unsigned int); |
| 162 | void gicd_set_igroupr(uintptr_t, unsigned int); |
| 163 | void gicd_clr_igroupr(uintptr_t, unsigned int); |
| 164 | void gicd_set_isenabler(uintptr_t, unsigned int); |
| 165 | void gicd_set_icenabler(uintptr_t, unsigned int); |
| 166 | void gicd_set_ispendr(uintptr_t, unsigned int); |
| 167 | void gicd_set_icpendr(uintptr_t, unsigned int); |
| 168 | void gicd_set_isactiver(uintptr_t, unsigned int); |
| 169 | void gicd_set_icactiver(uintptr_t, unsigned int); |
| 170 | void gicd_set_ipriorityr(uintptr_t, unsigned int, unsigned int); |
| 171 | void gicd_set_itargetsr(uintptr_t, unsigned int, unsigned int); |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 172 | |
| 173 | |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 174 | /******************************************************************************* |
| 175 | * GIC Distributor interface accessors for reading entire registers |
| 176 | ******************************************************************************/ |
| 177 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 178 | static inline unsigned int gicd_read_ctlr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 179 | { |
| 180 | return mmio_read_32(base + GICD_CTLR); |
| 181 | } |
| 182 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 183 | static inline unsigned int gicd_read_typer(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 184 | { |
| 185 | return mmio_read_32(base + GICD_TYPER); |
| 186 | } |
| 187 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 188 | static inline unsigned int gicd_read_sgir(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 189 | { |
| 190 | return mmio_read_32(base + GICD_SGIR); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /******************************************************************************* |
| 195 | * GIC Distributor interface accessors for writing entire registers |
| 196 | ******************************************************************************/ |
| 197 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 198 | static inline void gicd_write_ctlr(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 199 | { |
| 200 | mmio_write_32(base + GICD_CTLR, val); |
| 201 | } |
| 202 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 203 | static inline void gicd_write_sgir(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 204 | { |
| 205 | mmio_write_32(base + GICD_SGIR, val); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /******************************************************************************* |
| 210 | * GIC CPU interface accessors for reading entire registers |
| 211 | ******************************************************************************/ |
| 212 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 213 | static inline unsigned int gicc_read_ctlr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 214 | { |
| 215 | return mmio_read_32(base + GICC_CTLR); |
| 216 | } |
| 217 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 218 | static inline unsigned int gicc_read_pmr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 219 | { |
| 220 | return mmio_read_32(base + GICC_PMR); |
| 221 | } |
| 222 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 223 | static inline unsigned int gicc_read_BPR(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 224 | { |
| 225 | return mmio_read_32(base + GICC_BPR); |
| 226 | } |
| 227 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 228 | static inline unsigned int gicc_read_IAR(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 229 | { |
| 230 | return mmio_read_32(base + GICC_IAR); |
| 231 | } |
| 232 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 233 | static inline unsigned int gicc_read_EOIR(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 234 | { |
| 235 | return mmio_read_32(base + GICC_EOIR); |
| 236 | } |
| 237 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 238 | static inline unsigned int gicc_read_hppir(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 239 | { |
| 240 | return mmio_read_32(base + GICC_HPPIR); |
| 241 | } |
| 242 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 243 | static inline unsigned int gicc_read_ahppir(uintptr_t base) |
Achin Gupta | 02d3628 | 2014-05-04 19:02:52 +0100 | [diff] [blame] | 244 | { |
| 245 | return mmio_read_32(base + GICC_AHPPIR); |
| 246 | } |
| 247 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 248 | static inline unsigned int gicc_read_dir(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 249 | { |
| 250 | return mmio_read_32(base + GICC_DIR); |
| 251 | } |
| 252 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 253 | static inline unsigned int gicc_read_iidr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 254 | { |
| 255 | return mmio_read_32(base + GICC_IIDR); |
| 256 | } |
| 257 | |
| 258 | |
| 259 | /******************************************************************************* |
| 260 | * GIC CPU interface accessors for writing entire registers |
| 261 | ******************************************************************************/ |
| 262 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 263 | static inline void gicc_write_ctlr(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 264 | { |
| 265 | mmio_write_32(base + GICC_CTLR, val); |
| 266 | } |
| 267 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 268 | static inline void gicc_write_pmr(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 269 | { |
| 270 | mmio_write_32(base + GICC_PMR, val); |
| 271 | } |
| 272 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 273 | static inline void gicc_write_BPR(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 274 | { |
| 275 | mmio_write_32(base + GICC_BPR, val); |
| 276 | } |
| 277 | |
| 278 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 279 | static inline void gicc_write_IAR(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 280 | { |
| 281 | mmio_write_32(base + GICC_IAR, val); |
| 282 | } |
| 283 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 284 | static inline void gicc_write_EOIR(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 285 | { |
| 286 | mmio_write_32(base + GICC_EOIR, val); |
| 287 | } |
| 288 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 289 | static inline void gicc_write_hppir(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 290 | { |
| 291 | mmio_write_32(base + GICC_HPPIR, val); |
| 292 | } |
| 293 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 294 | static inline void gicc_write_dir(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 295 | { |
| 296 | mmio_write_32(base + GICC_DIR, val); |
| 297 | } |
| 298 | |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 299 | /******************************************************************************* |
| 300 | * Prototype of function to map an interrupt type to the interrupt line used to |
| 301 | * signal it. |
| 302 | ******************************************************************************/ |
| 303 | uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type); |
| 304 | |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 305 | #endif /*__ASSEMBLY__*/ |
| 306 | |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 307 | #endif /* __GIC_V2_H__ */ |