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 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __GIC_V2_H__ |
| 32 | #define __GIC_V2_H__ |
| 33 | |
Soby Mathew | 3ddc972 | 2015-10-26 14:32:09 +0000 | [diff] [blame] | 34 | /****************************************************************************** |
| 35 | * THIS DRIVER IS DEPRECATED. For GICv2 systems, use the driver in gicv2.h |
| 36 | * and for GICv3 systems, use the driver in gicv3.h. |
| 37 | *****************************************************************************/ |
| 38 | #if ERROR_DEPRECATED |
| 39 | #error " The legacy ARM GIC driver is deprecated." |
| 40 | #endif |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 41 | |
| 42 | #define GIC400_NUM_SPIS 480 |
| 43 | #define MAX_PPIS 14 |
| 44 | #define MAX_SGIS 16 |
| 45 | |
Dan Handley | fb42b12 | 2014-06-20 09:43:15 +0100 | [diff] [blame] | 46 | #define MIN_SGI_ID 0 |
| 47 | #define MIN_PPI_ID 16 |
| 48 | #define MIN_SPI_ID 32 |
| 49 | |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 50 | #define GRP0 0 |
| 51 | #define GRP1 1 |
| 52 | #define GIC_PRI_MASK 0xff |
| 53 | #define GIC_HIGHEST_SEC_PRIORITY 0 |
| 54 | #define GIC_LOWEST_SEC_PRIORITY 127 |
| 55 | #define GIC_HIGHEST_NS_PRIORITY 128 |
| 56 | #define GIC_LOWEST_NS_PRIORITY 254 /* 255 would disable an interrupt */ |
Achin Gupta | 02d3628 | 2014-05-04 19:02:52 +0100 | [diff] [blame] | 57 | #define GIC_SPURIOUS_INTERRUPT 1023 |
Juan Castillo | 8231295 | 2014-10-20 12:27:28 +0100 | [diff] [blame] | 58 | #define GIC_TARGET_CPU_MASK 0xff |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 59 | |
| 60 | #define ENABLE_GRP0 (1 << 0) |
| 61 | #define ENABLE_GRP1 (1 << 1) |
| 62 | |
| 63 | /* Distributor interface definitions */ |
| 64 | #define GICD_CTLR 0x0 |
| 65 | #define GICD_TYPER 0x4 |
| 66 | #define GICD_IGROUPR 0x80 |
| 67 | #define GICD_ISENABLER 0x100 |
| 68 | #define GICD_ICENABLER 0x180 |
| 69 | #define GICD_ISPENDR 0x200 |
| 70 | #define GICD_ICPENDR 0x280 |
| 71 | #define GICD_ISACTIVER 0x300 |
| 72 | #define GICD_ICACTIVER 0x380 |
| 73 | #define GICD_IPRIORITYR 0x400 |
| 74 | #define GICD_ITARGETSR 0x800 |
| 75 | #define GICD_ICFGR 0xC00 |
| 76 | #define GICD_SGIR 0xF00 |
| 77 | #define GICD_CPENDSGIR 0xF10 |
| 78 | #define GICD_SPENDSGIR 0xF20 |
| 79 | |
| 80 | #define IGROUPR_SHIFT 5 |
| 81 | #define ISENABLER_SHIFT 5 |
| 82 | #define ICENABLER_SHIFT ISENABLER_SHIFT |
| 83 | #define ISPENDR_SHIFT 5 |
| 84 | #define ICPENDR_SHIFT ISPENDR_SHIFT |
| 85 | #define ISACTIVER_SHIFT 5 |
| 86 | #define ICACTIVER_SHIFT ISACTIVER_SHIFT |
| 87 | #define IPRIORITYR_SHIFT 2 |
| 88 | #define ITARGETSR_SHIFT 2 |
| 89 | #define ICFGR_SHIFT 4 |
| 90 | #define CPENDSGIR_SHIFT 2 |
| 91 | #define SPENDSGIR_SHIFT CPENDSGIR_SHIFT |
| 92 | |
| 93 | /* GICD_TYPER bit definitions */ |
| 94 | #define IT_LINES_NO_MASK 0x1f |
| 95 | |
| 96 | /* Physical CPU Interface registers */ |
| 97 | #define GICC_CTLR 0x0 |
| 98 | #define GICC_PMR 0x4 |
| 99 | #define GICC_BPR 0x8 |
| 100 | #define GICC_IAR 0xC |
| 101 | #define GICC_EOIR 0x10 |
| 102 | #define GICC_RPR 0x14 |
| 103 | #define GICC_HPPIR 0x18 |
Achin Gupta | 02d3628 | 2014-05-04 19:02:52 +0100 | [diff] [blame] | 104 | #define GICC_AHPPIR 0x28 |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 105 | #define GICC_IIDR 0xFC |
| 106 | #define GICC_DIR 0x1000 |
| 107 | #define GICC_PRIODROP GICC_EOIR |
| 108 | |
Achin Gupta | 966b952 | 2015-05-18 10:56:47 +0100 | [diff] [blame] | 109 | /* Common CPU Interface definitions */ |
| 110 | #define INT_ID_MASK 0x3ff |
| 111 | |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 112 | /* GICC_CTLR bit definitions */ |
| 113 | #define EOI_MODE_NS (1 << 10) |
| 114 | #define EOI_MODE_S (1 << 9) |
| 115 | #define IRQ_BYP_DIS_GRP1 (1 << 8) |
| 116 | #define FIQ_BYP_DIS_GRP1 (1 << 7) |
| 117 | #define IRQ_BYP_DIS_GRP0 (1 << 6) |
| 118 | #define FIQ_BYP_DIS_GRP0 (1 << 5) |
| 119 | #define CBPR (1 << 4) |
| 120 | #define FIQ_EN (1 << 3) |
| 121 | #define ACK_CTL (1 << 2) |
| 122 | |
| 123 | /* GICC_IIDR bit masks and shifts */ |
| 124 | #define GICC_IIDR_PID_SHIFT 20 |
| 125 | #define GICC_IIDR_ARCH_SHIFT 16 |
| 126 | #define GICC_IIDR_REV_SHIFT 12 |
| 127 | #define GICC_IIDR_IMP_SHIFT 0 |
| 128 | |
| 129 | #define GICC_IIDR_PID_MASK 0xfff |
| 130 | #define GICC_IIDR_ARCH_MASK 0xf |
| 131 | #define GICC_IIDR_REV_MASK 0xf |
| 132 | #define GICC_IIDR_IMP_MASK 0xfff |
| 133 | |
| 134 | /* HYP view virtual CPU Interface registers */ |
| 135 | #define GICH_CTL 0x0 |
| 136 | #define GICH_VTR 0x4 |
| 137 | #define GICH_ELRSR0 0x30 |
| 138 | #define GICH_ELRSR1 0x34 |
| 139 | #define GICH_APR0 0xF0 |
| 140 | #define GICH_LR_BASE 0x100 |
| 141 | |
| 142 | /* Virtual CPU Interface registers */ |
| 143 | #define GICV_CTL 0x0 |
| 144 | #define GICV_PRIMASK 0x4 |
| 145 | #define GICV_BP 0x8 |
| 146 | #define GICV_INTACK 0xC |
| 147 | #define GICV_EOI 0x10 |
| 148 | #define GICV_RUNNINGPRI 0x14 |
| 149 | #define GICV_HIGHESTPEND 0x18 |
| 150 | #define GICV_DEACTIVATE 0x1000 |
| 151 | |
| 152 | #ifndef __ASSEMBLY__ |
| 153 | |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 154 | #include <mmio.h> |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 155 | #include <stdint.h> |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 156 | |
| 157 | /******************************************************************************* |
| 158 | * GIC Distributor function prototypes |
| 159 | ******************************************************************************/ |
| 160 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 161 | unsigned int gicd_read_igroupr(uintptr_t, unsigned int); |
| 162 | unsigned int gicd_read_isenabler(uintptr_t, unsigned int); |
| 163 | unsigned int gicd_read_icenabler(uintptr_t, unsigned int); |
| 164 | unsigned int gicd_read_ispendr(uintptr_t, unsigned int); |
| 165 | unsigned int gicd_read_icpendr(uintptr_t, unsigned int); |
| 166 | unsigned int gicd_read_isactiver(uintptr_t, unsigned int); |
| 167 | unsigned int gicd_read_icactiver(uintptr_t, unsigned int); |
| 168 | unsigned int gicd_read_ipriorityr(uintptr_t, unsigned int); |
| 169 | unsigned int gicd_read_itargetsr(uintptr_t, unsigned int); |
| 170 | unsigned int gicd_read_icfgr(uintptr_t, unsigned int); |
| 171 | unsigned int gicd_read_cpendsgir(uintptr_t, unsigned int); |
| 172 | unsigned int gicd_read_spendsgir(uintptr_t, unsigned int); |
| 173 | void gicd_write_igroupr(uintptr_t, unsigned int, unsigned int); |
| 174 | void gicd_write_isenabler(uintptr_t, unsigned int, unsigned int); |
| 175 | void gicd_write_icenabler(uintptr_t, unsigned int, unsigned int); |
| 176 | void gicd_write_ispendr(uintptr_t, unsigned int, unsigned int); |
| 177 | void gicd_write_icpendr(uintptr_t, unsigned int, unsigned int); |
| 178 | void gicd_write_isactiver(uintptr_t, unsigned int, unsigned int); |
| 179 | void gicd_write_icactiver(uintptr_t, unsigned int, unsigned int); |
| 180 | void gicd_write_ipriorityr(uintptr_t, unsigned int, unsigned int); |
| 181 | void gicd_write_itargetsr(uintptr_t, unsigned int, unsigned int); |
| 182 | void gicd_write_icfgr(uintptr_t, unsigned int, unsigned int); |
| 183 | void gicd_write_cpendsgir(uintptr_t, unsigned int, unsigned int); |
| 184 | void gicd_write_spendsgir(uintptr_t, unsigned int, unsigned int); |
| 185 | unsigned int gicd_get_igroupr(uintptr_t, unsigned int); |
| 186 | void gicd_set_igroupr(uintptr_t, unsigned int); |
| 187 | void gicd_clr_igroupr(uintptr_t, unsigned int); |
| 188 | void gicd_set_isenabler(uintptr_t, unsigned int); |
| 189 | void gicd_set_icenabler(uintptr_t, unsigned int); |
| 190 | void gicd_set_ispendr(uintptr_t, unsigned int); |
| 191 | void gicd_set_icpendr(uintptr_t, unsigned int); |
| 192 | void gicd_set_isactiver(uintptr_t, unsigned int); |
| 193 | void gicd_set_icactiver(uintptr_t, unsigned int); |
| 194 | void gicd_set_ipriorityr(uintptr_t, unsigned int, unsigned int); |
| 195 | void gicd_set_itargetsr(uintptr_t, unsigned int, unsigned int); |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 196 | |
| 197 | |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 198 | /******************************************************************************* |
| 199 | * GIC Distributor interface accessors for reading entire registers |
| 200 | ******************************************************************************/ |
| 201 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 202 | static inline unsigned int gicd_read_ctlr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 203 | { |
| 204 | return mmio_read_32(base + GICD_CTLR); |
| 205 | } |
| 206 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 207 | static inline unsigned int gicd_read_typer(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 208 | { |
| 209 | return mmio_read_32(base + GICD_TYPER); |
| 210 | } |
| 211 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 212 | static inline unsigned int gicd_read_sgir(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 213 | { |
| 214 | return mmio_read_32(base + GICD_SGIR); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /******************************************************************************* |
| 219 | * GIC Distributor interface accessors for writing entire registers |
| 220 | ******************************************************************************/ |
| 221 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 222 | static inline void gicd_write_ctlr(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 223 | { |
| 224 | mmio_write_32(base + GICD_CTLR, val); |
| 225 | } |
| 226 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 227 | static inline void gicd_write_sgir(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 228 | { |
| 229 | mmio_write_32(base + GICD_SGIR, val); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /******************************************************************************* |
| 234 | * GIC CPU interface accessors for reading entire registers |
| 235 | ******************************************************************************/ |
| 236 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 237 | static inline unsigned int gicc_read_ctlr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 238 | { |
| 239 | return mmio_read_32(base + GICC_CTLR); |
| 240 | } |
| 241 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 242 | static inline unsigned int gicc_read_pmr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 243 | { |
| 244 | return mmio_read_32(base + GICC_PMR); |
| 245 | } |
| 246 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 247 | static inline unsigned int gicc_read_BPR(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 248 | { |
| 249 | return mmio_read_32(base + GICC_BPR); |
| 250 | } |
| 251 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 252 | static inline unsigned int gicc_read_IAR(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 253 | { |
| 254 | return mmio_read_32(base + GICC_IAR); |
| 255 | } |
| 256 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 257 | static inline unsigned int gicc_read_EOIR(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 258 | { |
| 259 | return mmio_read_32(base + GICC_EOIR); |
| 260 | } |
| 261 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 262 | static inline unsigned int gicc_read_hppir(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 263 | { |
| 264 | return mmio_read_32(base + GICC_HPPIR); |
| 265 | } |
| 266 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 267 | static inline unsigned int gicc_read_ahppir(uintptr_t base) |
Achin Gupta | 02d3628 | 2014-05-04 19:02:52 +0100 | [diff] [blame] | 268 | { |
| 269 | return mmio_read_32(base + GICC_AHPPIR); |
| 270 | } |
| 271 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 272 | static inline unsigned int gicc_read_dir(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 273 | { |
| 274 | return mmio_read_32(base + GICC_DIR); |
| 275 | } |
| 276 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 277 | static inline unsigned int gicc_read_iidr(uintptr_t base) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 278 | { |
| 279 | return mmio_read_32(base + GICC_IIDR); |
| 280 | } |
| 281 | |
| 282 | |
| 283 | /******************************************************************************* |
| 284 | * GIC CPU interface accessors for writing entire registers |
| 285 | ******************************************************************************/ |
| 286 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 287 | static inline void gicc_write_ctlr(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 288 | { |
| 289 | mmio_write_32(base + GICC_CTLR, val); |
| 290 | } |
| 291 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 292 | static inline void gicc_write_pmr(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 293 | { |
| 294 | mmio_write_32(base + GICC_PMR, val); |
| 295 | } |
| 296 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 297 | static inline void gicc_write_BPR(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 298 | { |
| 299 | mmio_write_32(base + GICC_BPR, val); |
| 300 | } |
| 301 | |
| 302 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 303 | static inline void gicc_write_IAR(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 304 | { |
| 305 | mmio_write_32(base + GICC_IAR, val); |
| 306 | } |
| 307 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 308 | static inline void gicc_write_EOIR(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 309 | { |
| 310 | mmio_write_32(base + GICC_EOIR, val); |
| 311 | } |
| 312 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 313 | static inline void gicc_write_hppir(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 314 | { |
| 315 | mmio_write_32(base + GICC_HPPIR, val); |
| 316 | } |
| 317 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 318 | static inline void gicc_write_dir(uintptr_t base, unsigned int val) |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 319 | { |
| 320 | mmio_write_32(base + GICC_DIR, val); |
| 321 | } |
| 322 | |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 323 | /******************************************************************************* |
| 324 | * Prototype of function to map an interrupt type to the interrupt line used to |
| 325 | * signal it. |
| 326 | ******************************************************************************/ |
| 327 | uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type); |
| 328 | |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 329 | #endif /*__ASSEMBLY__*/ |
| 330 | |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 331 | #endif /* __GIC_V2_H__ */ |