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