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