Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Soby Mathew | 73f9299 | 2016-01-15 14:05:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2016, 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 | |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 31 | #include <arch.h> |
Jon Medhurst | d0212c2 | 2014-02-11 14:48:56 +0000 | [diff] [blame] | 32 | #include <assert.h> |
Dan Handley | 930ee2e | 2014-04-17 17:48:52 +0100 | [diff] [blame] | 33 | #include <gic_v2.h> |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 34 | #include <interrupt_mgmt.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 35 | #include <mmio.h> |
| 36 | |
| 37 | /******************************************************************************* |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 38 | * GIC Distributor interface accessors for reading entire registers |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 39 | ******************************************************************************/ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 40 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 41 | unsigned int gicd_read_igroupr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 42 | { |
| 43 | unsigned n = id >> IGROUPR_SHIFT; |
| 44 | return mmio_read_32(base + GICD_IGROUPR + (n << 2)); |
| 45 | } |
| 46 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 47 | unsigned int gicd_read_isenabler(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 48 | { |
| 49 | unsigned n = id >> ISENABLER_SHIFT; |
| 50 | return mmio_read_32(base + GICD_ISENABLER + (n << 2)); |
| 51 | } |
| 52 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 53 | unsigned int gicd_read_icenabler(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 54 | { |
| 55 | unsigned n = id >> ICENABLER_SHIFT; |
| 56 | return mmio_read_32(base + GICD_ICENABLER + (n << 2)); |
| 57 | } |
| 58 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 59 | unsigned int gicd_read_ispendr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 60 | { |
| 61 | unsigned n = id >> ISPENDR_SHIFT; |
| 62 | return mmio_read_32(base + GICD_ISPENDR + (n << 2)); |
| 63 | } |
| 64 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 65 | unsigned int gicd_read_icpendr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 66 | { |
| 67 | unsigned n = id >> ICPENDR_SHIFT; |
| 68 | return mmio_read_32(base + GICD_ICPENDR + (n << 2)); |
| 69 | } |
| 70 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 71 | unsigned int gicd_read_isactiver(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 72 | { |
| 73 | unsigned n = id >> ISACTIVER_SHIFT; |
| 74 | return mmio_read_32(base + GICD_ISACTIVER + (n << 2)); |
| 75 | } |
| 76 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 77 | unsigned int gicd_read_icactiver(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 78 | { |
| 79 | unsigned n = id >> ICACTIVER_SHIFT; |
| 80 | return mmio_read_32(base + GICD_ICACTIVER + (n << 2)); |
| 81 | } |
| 82 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 83 | unsigned int gicd_read_ipriorityr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 84 | { |
| 85 | unsigned n = id >> IPRIORITYR_SHIFT; |
| 86 | return mmio_read_32(base + GICD_IPRIORITYR + (n << 2)); |
| 87 | } |
| 88 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 89 | unsigned int gicd_read_itargetsr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 90 | { |
| 91 | unsigned n = id >> ITARGETSR_SHIFT; |
| 92 | return mmio_read_32(base + GICD_ITARGETSR + (n << 2)); |
| 93 | } |
| 94 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 95 | unsigned int gicd_read_icfgr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 96 | { |
| 97 | unsigned n = id >> ICFGR_SHIFT; |
| 98 | return mmio_read_32(base + GICD_ICFGR + (n << 2)); |
| 99 | } |
| 100 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 101 | unsigned int gicd_read_cpendsgir(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 102 | { |
| 103 | unsigned n = id >> CPENDSGIR_SHIFT; |
| 104 | return mmio_read_32(base + GICD_CPENDSGIR + (n << 2)); |
| 105 | } |
| 106 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 107 | unsigned int gicd_read_spendsgir(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 108 | { |
| 109 | unsigned n = id >> SPENDSGIR_SHIFT; |
| 110 | return mmio_read_32(base + GICD_SPENDSGIR + (n << 2)); |
| 111 | } |
| 112 | |
| 113 | /******************************************************************************* |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 114 | * GIC Distributor interface accessors for writing entire registers |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | ******************************************************************************/ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 116 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 117 | void gicd_write_igroupr(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 118 | { |
| 119 | unsigned n = id >> IGROUPR_SHIFT; |
| 120 | mmio_write_32(base + GICD_IGROUPR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 123 | void gicd_write_isenabler(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 124 | { |
| 125 | unsigned n = id >> ISENABLER_SHIFT; |
| 126 | mmio_write_32(base + GICD_ISENABLER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 129 | void gicd_write_icenabler(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 130 | { |
| 131 | unsigned n = id >> ICENABLER_SHIFT; |
| 132 | mmio_write_32(base + GICD_ICENABLER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 135 | void gicd_write_ispendr(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 136 | { |
| 137 | unsigned n = id >> ISPENDR_SHIFT; |
| 138 | mmio_write_32(base + GICD_ISPENDR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 141 | void gicd_write_icpendr(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 142 | { |
| 143 | unsigned n = id >> ICPENDR_SHIFT; |
| 144 | mmio_write_32(base + GICD_ICPENDR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 147 | void gicd_write_isactiver(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 148 | { |
| 149 | unsigned n = id >> ISACTIVER_SHIFT; |
| 150 | mmio_write_32(base + GICD_ISACTIVER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 153 | void gicd_write_icactiver(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 154 | { |
| 155 | unsigned n = id >> ICACTIVER_SHIFT; |
| 156 | mmio_write_32(base + GICD_ICACTIVER + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 159 | void gicd_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | { |
| 161 | unsigned n = id >> IPRIORITYR_SHIFT; |
| 162 | mmio_write_32(base + GICD_IPRIORITYR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 165 | void gicd_write_itargetsr(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 166 | { |
| 167 | unsigned n = id >> ITARGETSR_SHIFT; |
| 168 | mmio_write_32(base + GICD_ITARGETSR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 171 | void gicd_write_icfgr(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 172 | { |
| 173 | unsigned n = id >> ICFGR_SHIFT; |
| 174 | mmio_write_32(base + GICD_ICFGR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 177 | void gicd_write_cpendsgir(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 178 | { |
| 179 | unsigned n = id >> CPENDSGIR_SHIFT; |
| 180 | mmio_write_32(base + GICD_CPENDSGIR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 183 | void gicd_write_spendsgir(uintptr_t base, unsigned int id, unsigned int val) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 184 | { |
| 185 | unsigned n = id >> SPENDSGIR_SHIFT; |
| 186 | mmio_write_32(base + GICD_SPENDSGIR + (n << 2), val); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /******************************************************************************* |
Sandrine Bailleux | 27866d8 | 2013-10-25 15:33:39 +0100 | [diff] [blame] | 190 | * GIC Distributor interface accessors for individual interrupt manipulation |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 191 | ******************************************************************************/ |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 192 | unsigned int gicd_get_igroupr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 193 | { |
| 194 | unsigned bit_num = id & ((1 << IGROUPR_SHIFT) - 1); |
| 195 | unsigned int reg_val = gicd_read_igroupr(base, id); |
| 196 | |
| 197 | return (reg_val >> bit_num) & 0x1; |
| 198 | } |
| 199 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 200 | void gicd_set_igroupr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 201 | { |
| 202 | unsigned bit_num = id & ((1 << IGROUPR_SHIFT) - 1); |
| 203 | unsigned int reg_val = gicd_read_igroupr(base, id); |
| 204 | |
| 205 | gicd_write_igroupr(base, id, reg_val | (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 208 | void gicd_clr_igroupr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 209 | { |
| 210 | unsigned bit_num = id & ((1 << IGROUPR_SHIFT) - 1); |
| 211 | unsigned int reg_val = gicd_read_igroupr(base, id); |
| 212 | |
| 213 | gicd_write_igroupr(base, id, reg_val & ~(1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 216 | void gicd_set_isenabler(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 217 | { |
| 218 | unsigned bit_num = id & ((1 << ISENABLER_SHIFT) - 1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 219 | |
Juan Castillo | 969bdb2 | 2014-04-28 12:48:40 +0100 | [diff] [blame] | 220 | gicd_write_isenabler(base, id, (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 223 | void gicd_set_icenabler(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 224 | { |
| 225 | unsigned bit_num = id & ((1 << ICENABLER_SHIFT) - 1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 226 | |
Juan Castillo | 969bdb2 | 2014-04-28 12:48:40 +0100 | [diff] [blame] | 227 | gicd_write_icenabler(base, id, (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 230 | void gicd_set_ispendr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 231 | { |
| 232 | unsigned bit_num = id & ((1 << ISPENDR_SHIFT) - 1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 233 | |
Juan Castillo | 969bdb2 | 2014-04-28 12:48:40 +0100 | [diff] [blame] | 234 | gicd_write_ispendr(base, id, (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 237 | void gicd_set_icpendr(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 238 | { |
| 239 | unsigned bit_num = id & ((1 << ICPENDR_SHIFT) - 1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 240 | |
Juan Castillo | 969bdb2 | 2014-04-28 12:48:40 +0100 | [diff] [blame] | 241 | gicd_write_icpendr(base, id, (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 244 | void gicd_set_isactiver(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 245 | { |
| 246 | unsigned bit_num = id & ((1 << ISACTIVER_SHIFT) - 1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 247 | |
Juan Castillo | 969bdb2 | 2014-04-28 12:48:40 +0100 | [diff] [blame] | 248 | gicd_write_isactiver(base, id, (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 251 | void gicd_set_icactiver(uintptr_t base, unsigned int id) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 252 | { |
| 253 | unsigned bit_num = id & ((1 << ICACTIVER_SHIFT) - 1); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 254 | |
Juan Castillo | 969bdb2 | 2014-04-28 12:48:40 +0100 | [diff] [blame] | 255 | gicd_write_icactiver(base, id, (1 << bit_num)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Make sure that the interrupt's group is set before expecting |
| 260 | * this function to do its job correctly. |
| 261 | */ |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 262 | void gicd_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 263 | { |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 264 | /* |
| 265 | * Enforce ARM recommendation to manage priority values such |
| 266 | * that group1 interrupts always have a lower priority than |
Jon Medhurst | d0212c2 | 2014-02-11 14:48:56 +0000 | [diff] [blame] | 267 | * group0 interrupts. |
| 268 | * Note, lower numerical values are higher priorities so the comparison |
| 269 | * checks below are reversed from what might be expected. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 270 | */ |
Jon Medhurst | d0212c2 | 2014-02-11 14:48:56 +0000 | [diff] [blame] | 271 | assert(gicd_get_igroupr(base, id) == GRP1 ? |
| 272 | pri >= GIC_HIGHEST_NS_PRIORITY && |
| 273 | pri <= GIC_LOWEST_NS_PRIORITY : |
| 274 | pri >= GIC_HIGHEST_SEC_PRIORITY && |
| 275 | pri <= GIC_LOWEST_SEC_PRIORITY); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 276 | |
Soby Mathew | 73f9299 | 2016-01-15 14:05:37 +0000 | [diff] [blame] | 277 | mmio_write_8(base + GICD_IPRIORITYR + id, pri & GIC_PRI_MASK); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 278 | } |
| 279 | |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 280 | void gicd_set_itargetsr(uintptr_t base, unsigned int id, unsigned int target) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | { |
Soby Mathew | 73f9299 | 2016-01-15 14:05:37 +0000 | [diff] [blame] | 282 | mmio_write_8(base + GICD_ITARGETSR + id, target & GIC_TARGET_CPU_MASK); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 285 | /******************************************************************************* |
| 286 | * This function allows the interrupt management framework to determine (through |
| 287 | * the platform) which interrupt line (IRQ/FIQ) to use for an interrupt type to |
| 288 | * route it to EL3. The interrupt line is represented as the bit position of the |
| 289 | * IRQ or FIQ bit in the SCR_EL3. |
| 290 | ******************************************************************************/ |
| 291 | uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type) |
| 292 | { |
| 293 | uint32_t gicc_ctlr; |
| 294 | |
| 295 | /* Non-secure interrupts are signalled on the IRQ line always */ |
| 296 | if (type == INTR_TYPE_NS) |
| 297 | return __builtin_ctz(SCR_IRQ_BIT); |
| 298 | |
| 299 | /* |
| 300 | * Secure interrupts are signalled using the IRQ line if the FIQ_EN |
| 301 | * bit is not set else they are signalled using the FIQ line. |
| 302 | */ |
| 303 | gicc_ctlr = gicc_read_ctlr(cpuif_base); |
| 304 | if (gicc_ctlr & FIQ_EN) |
| 305 | return __builtin_ctz(SCR_FIQ_BIT); |
| 306 | else |
| 307 | return __builtin_ctz(SCR_IRQ_BIT); |
| 308 | } |