Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | ab2d31e | 2013-12-02 19:25:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +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 | #include <gic.h> |
| 32 | #include <mmio.h> |
| 33 | |
| 34 | /******************************************************************************* |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 35 | * GIC Distributor interface accessors for reading entire registers |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 36 | ******************************************************************************/ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | |
| 38 | unsigned int gicd_read_igroupr(unsigned int base, unsigned int id) |
| 39 | { |
| 40 | unsigned n = id >> IGROUPR_SHIFT; |
| 41 | return mmio_read_32(base + GICD_IGROUPR + (n << 2)); |
| 42 | } |
| 43 | |
| 44 | unsigned int gicd_read_isenabler(unsigned int base, unsigned int id) |
| 45 | { |
| 46 | unsigned n = id >> ISENABLER_SHIFT; |
| 47 | return mmio_read_32(base + GICD_ISENABLER + (n << 2)); |
| 48 | } |
| 49 | |
| 50 | unsigned int gicd_read_icenabler(unsigned int base, unsigned int id) |
| 51 | { |
| 52 | unsigned n = id >> ICENABLER_SHIFT; |
| 53 | return mmio_read_32(base + GICD_ICENABLER + (n << 2)); |
| 54 | } |
| 55 | |
| 56 | unsigned int gicd_read_ispendr(unsigned int base, unsigned int id) |
| 57 | { |
| 58 | unsigned n = id >> ISPENDR_SHIFT; |
| 59 | return mmio_read_32(base + GICD_ISPENDR + (n << 2)); |
| 60 | } |
| 61 | |
| 62 | unsigned int gicd_read_icpendr(unsigned int base, unsigned int id) |
| 63 | { |
| 64 | unsigned n = id >> ICPENDR_SHIFT; |
| 65 | return mmio_read_32(base + GICD_ICPENDR + (n << 2)); |
| 66 | } |
| 67 | |
| 68 | unsigned int gicd_read_isactiver(unsigned int base, unsigned int id) |
| 69 | { |
| 70 | unsigned n = id >> ISACTIVER_SHIFT; |
| 71 | return mmio_read_32(base + GICD_ISACTIVER + (n << 2)); |
| 72 | } |
| 73 | |
| 74 | unsigned int gicd_read_icactiver(unsigned int base, unsigned int id) |
| 75 | { |
| 76 | unsigned n = id >> ICACTIVER_SHIFT; |
| 77 | return mmio_read_32(base + GICD_ICACTIVER + (n << 2)); |
| 78 | } |
| 79 | |
| 80 | unsigned int gicd_read_ipriorityr(unsigned int base, unsigned int id) |
| 81 | { |
| 82 | unsigned n = id >> IPRIORITYR_SHIFT; |
| 83 | return mmio_read_32(base + GICD_IPRIORITYR + (n << 2)); |
| 84 | } |
| 85 | |
| 86 | unsigned int gicd_read_itargetsr(unsigned int base, unsigned int id) |
| 87 | { |
| 88 | unsigned n = id >> ITARGETSR_SHIFT; |
| 89 | return mmio_read_32(base + GICD_ITARGETSR + (n << 2)); |
| 90 | } |
| 91 | |
| 92 | unsigned int gicd_read_icfgr(unsigned int base, unsigned int id) |
| 93 | { |
| 94 | unsigned n = id >> ICFGR_SHIFT; |
| 95 | return mmio_read_32(base + GICD_ICFGR + (n << 2)); |
| 96 | } |
| 97 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 98 | unsigned int gicd_read_cpendsgir(unsigned int base, unsigned int id) |
| 99 | { |
| 100 | unsigned n = id >> CPENDSGIR_SHIFT; |
| 101 | return mmio_read_32(base + GICD_CPENDSGIR + (n << 2)); |
| 102 | } |
| 103 | |
| 104 | unsigned int gicd_read_spendsgir(unsigned int base, unsigned int id) |
| 105 | { |
| 106 | unsigned n = id >> SPENDSGIR_SHIFT; |
| 107 | return mmio_read_32(base + GICD_SPENDSGIR + (n << 2)); |
| 108 | } |
| 109 | |
| 110 | /******************************************************************************* |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 111 | * GIC Distributor interface accessors for writing entire registers |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 112 | ******************************************************************************/ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 113 | |
| 114 | void gicd_write_igroupr(unsigned int base, unsigned int id, unsigned int val) |
| 115 | { |
| 116 | unsigned n = id >> IGROUPR_SHIFT; |
| 117 | mmio_write_32(base + GICD_IGROUPR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void gicd_write_isenabler(unsigned int base, unsigned int id, unsigned int val) |
| 121 | { |
| 122 | unsigned n = id >> ISENABLER_SHIFT; |
| 123 | mmio_write_32(base + GICD_ISENABLER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void gicd_write_icenabler(unsigned int base, unsigned int id, unsigned int val) |
| 127 | { |
| 128 | unsigned n = id >> ICENABLER_SHIFT; |
| 129 | mmio_write_32(base + GICD_ICENABLER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void gicd_write_ispendr(unsigned int base, unsigned int id, unsigned int val) |
| 133 | { |
| 134 | unsigned n = id >> ISPENDR_SHIFT; |
| 135 | mmio_write_32(base + GICD_ISPENDR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void gicd_write_icpendr(unsigned int base, unsigned int id, unsigned int val) |
| 139 | { |
| 140 | unsigned n = id >> ICPENDR_SHIFT; |
| 141 | mmio_write_32(base + GICD_ICPENDR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void gicd_write_isactiver(unsigned int base, unsigned int id, unsigned int val) |
| 145 | { |
| 146 | unsigned n = id >> ISACTIVER_SHIFT; |
| 147 | mmio_write_32(base + GICD_ISACTIVER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void gicd_write_icactiver(unsigned int base, unsigned int id, unsigned int val) |
| 151 | { |
| 152 | unsigned n = id >> ICACTIVER_SHIFT; |
| 153 | mmio_write_32(base + GICD_ICACTIVER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void gicd_write_ipriorityr(unsigned int base, unsigned int id, unsigned int val) |
| 157 | { |
| 158 | unsigned n = id >> IPRIORITYR_SHIFT; |
| 159 | mmio_write_32(base + GICD_IPRIORITYR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void gicd_write_itargetsr(unsigned int base, unsigned int id, unsigned int val) |
| 163 | { |
| 164 | unsigned n = id >> ITARGETSR_SHIFT; |
| 165 | mmio_write_32(base + GICD_ITARGETSR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void gicd_write_icfgr(unsigned int base, unsigned int id, unsigned int val) |
| 169 | { |
| 170 | unsigned n = id >> ICFGR_SHIFT; |
| 171 | mmio_write_32(base + GICD_ICFGR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void gicd_write_cpendsgir(unsigned int base, unsigned int id, unsigned int val) |
| 175 | { |
| 176 | unsigned n = id >> CPENDSGIR_SHIFT; |
| 177 | mmio_write_32(base + GICD_CPENDSGIR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void gicd_write_spendsgir(unsigned int base, unsigned int id, unsigned int val) |
| 181 | { |
| 182 | unsigned n = id >> SPENDSGIR_SHIFT; |
| 183 | mmio_write_32(base + GICD_SPENDSGIR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /******************************************************************************* |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 187 | * GIC Distributor interface accessors for individual interrupt manipulation |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 188 | ******************************************************************************/ |
| 189 | unsigned int gicd_get_igroupr(unsigned int base, unsigned int id) |
| 190 | { |
| 191 | unsigned bit_num = id & ((1 << IGROUPR_SHIFT) - 1); |
| 192 | unsigned int reg_val = gicd_read_igroupr(base, id); |
| 193 | |
| 194 | return (reg_val >> bit_num) & 0x1; |
| 195 | } |
| 196 | |
| 197 | void gicd_set_igroupr(unsigned int base, unsigned int id) |
| 198 | { |
| 199 | unsigned bit_num = id & ((1 << IGROUPR_SHIFT) - 1); |
| 200 | unsigned int reg_val = gicd_read_igroupr(base, id); |
| 201 | |
| 202 | gicd_write_igroupr(base, id, reg_val | (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void gicd_clr_igroupr(unsigned int base, unsigned int id) |
| 206 | { |
| 207 | unsigned bit_num = id & ((1 << IGROUPR_SHIFT) - 1); |
| 208 | unsigned int reg_val = gicd_read_igroupr(base, id); |
| 209 | |
| 210 | gicd_write_igroupr(base, id, reg_val & ~(1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void gicd_set_isenabler(unsigned int base, unsigned int id) |
| 214 | { |
| 215 | unsigned bit_num = id & ((1 << ISENABLER_SHIFT) - 1); |
| 216 | unsigned int reg_val = gicd_read_isenabler(base, id); |
| 217 | |
| 218 | gicd_write_isenabler(base, id, reg_val | (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void gicd_set_icenabler(unsigned int base, unsigned int id) |
| 222 | { |
| 223 | unsigned bit_num = id & ((1 << ICENABLER_SHIFT) - 1); |
| 224 | unsigned int reg_val = gicd_read_icenabler(base, id); |
| 225 | |
| 226 | gicd_write_icenabler(base, id, reg_val & ~(1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void gicd_set_ispendr(unsigned int base, unsigned int id) |
| 230 | { |
| 231 | unsigned bit_num = id & ((1 << ISPENDR_SHIFT) - 1); |
| 232 | unsigned int reg_val = gicd_read_ispendr(base, id); |
| 233 | |
| 234 | gicd_write_ispendr(base, id, reg_val | (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void gicd_set_icpendr(unsigned int base, unsigned int id) |
| 238 | { |
| 239 | unsigned bit_num = id & ((1 << ICPENDR_SHIFT) - 1); |
| 240 | unsigned int reg_val = gicd_read_icpendr(base, id); |
| 241 | |
| 242 | gicd_write_icpendr(base, id, reg_val & ~(1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void gicd_set_isactiver(unsigned int base, unsigned int id) |
| 246 | { |
| 247 | unsigned bit_num = id & ((1 << ISACTIVER_SHIFT) - 1); |
| 248 | unsigned int reg_val = gicd_read_isactiver(base, id); |
| 249 | |
| 250 | gicd_write_isactiver(base, id, reg_val | (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void gicd_set_icactiver(unsigned int base, unsigned int id) |
| 254 | { |
| 255 | unsigned bit_num = id & ((1 << ICACTIVER_SHIFT) - 1); |
| 256 | unsigned int reg_val = gicd_read_icactiver(base, id); |
| 257 | |
| 258 | gicd_write_icactiver(base, id, reg_val & ~(1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Make sure that the interrupt's group is set before expecting |
| 263 | * this function to do its job correctly. |
| 264 | */ |
| 265 | void gicd_set_ipriorityr(unsigned int base, unsigned int id, unsigned int pri) |
| 266 | { |
| 267 | unsigned byte_off = id & ((1 << ICACTIVER_SHIFT) - 1); |
| 268 | unsigned int reg_val = gicd_read_icactiver(base, id); |
| 269 | |
| 270 | /* |
| 271 | * Enforce ARM recommendation to manage priority values such |
| 272 | * that group1 interrupts always have a lower priority than |
| 273 | * group0 interrupts |
| 274 | */ |
| 275 | if (gicd_get_igroupr(base, id) == GRP1) |
| 276 | pri |= 1 << 7; |
| 277 | else |
| 278 | pri &= ~(1 << 7); |
| 279 | |
| 280 | gicd_write_icactiver(base, id, reg_val & ~(pri << (byte_off << 3))); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void gicd_set_itargetsr(unsigned int base, unsigned int id, unsigned int iface) |
| 284 | { |
| 285 | unsigned byte_off = id & ((1 << ITARGETSR_SHIFT) - 1); |
| 286 | unsigned int reg_val = gicd_read_itargetsr(base, id); |
| 287 | |
| 288 | gicd_write_itargetsr(base, id, reg_val | |
| 289 | (1 << iface) << (byte_off << 3)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 290 | } |
| 291 | |