blob: bf6405f7f12612b9795740aea2a8682bc7d83132 [file] [log] [blame]
Achin Gupta92712a52015-09-03 14:18:02 +01001/*
Alexei Fedorovcaa18022020-07-14 10:47:25 +01002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Achin Gupta92712a52015-09-03 14:18:02 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta92712a52015-09-03 14:18:02 +01005 */
6
Alexei Fedorovcaa18022020-07-14 10:47:25 +01007#pragma message __FILE__ " is deprecated, use gicv2.mk instead"
8
Achin Gupta92712a52015-09-03 14:18:02 +01009#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <drivers/arm/gic_common.h>
12#include <lib/mmio.h>
13
Soby Mathew50f6fe42016-02-01 17:59:22 +000014#include "gic_common_private.h"
Achin Gupta92712a52015-09-03 14:18:02 +010015
16/*******************************************************************************
17 * GIC Distributor interface accessors for reading entire registers
18 ******************************************************************************/
19/*
20 * Accessor to read the GIC Distributor IGROUPR corresponding to the interrupt
21 * `id`, 32 interrupt ids at a time.
22 */
23unsigned int gicd_read_igroupr(uintptr_t base, unsigned int id)
24{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010025 unsigned int n = id >> IGROUPR_SHIFT;
26
Achin Gupta92712a52015-09-03 14:18:02 +010027 return mmio_read_32(base + GICD_IGROUPR + (n << 2));
28}
29
30/*
31 * Accessor to read the GIC Distributor ISENABLER corresponding to the
32 * interrupt `id`, 32 interrupt ids at a time.
33 */
34unsigned int gicd_read_isenabler(uintptr_t base, unsigned int id)
35{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010036 unsigned int n = id >> ISENABLER_SHIFT;
37
Achin Gupta92712a52015-09-03 14:18:02 +010038 return mmio_read_32(base + GICD_ISENABLER + (n << 2));
39}
40
41/*
42 * Accessor to read the GIC Distributor ICENABLER corresponding to the
43 * interrupt `id`, 32 interrupt IDs at a time.
44 */
45unsigned int gicd_read_icenabler(uintptr_t base, unsigned int id)
46{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010047 unsigned int n = id >> ICENABLER_SHIFT;
48
Achin Gupta92712a52015-09-03 14:18:02 +010049 return mmio_read_32(base + GICD_ICENABLER + (n << 2));
50}
51
52/*
53 * Accessor to read the GIC Distributor ISPENDR corresponding to the
54 * interrupt `id`, 32 interrupt IDs at a time.
55 */
56unsigned int gicd_read_ispendr(uintptr_t base, unsigned int id)
57{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010058 unsigned int n = id >> ISPENDR_SHIFT;
59
Achin Gupta92712a52015-09-03 14:18:02 +010060 return mmio_read_32(base + GICD_ISPENDR + (n << 2));
61}
62
63/*
64 * Accessor to read the GIC Distributor ICPENDR corresponding to the
65 * interrupt `id`, 32 interrupt IDs at a time.
66 */
67unsigned int gicd_read_icpendr(uintptr_t base, unsigned int id)
68{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010069 unsigned int n = id >> ICPENDR_SHIFT;
70
Achin Gupta92712a52015-09-03 14:18:02 +010071 return mmio_read_32(base + GICD_ICPENDR + (n << 2));
72}
73
74/*
75 * Accessor to read the GIC Distributor ISACTIVER corresponding to the
76 * interrupt `id`, 32 interrupt IDs at a time.
77 */
78unsigned int gicd_read_isactiver(uintptr_t base, unsigned int id)
79{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010080 unsigned int n = id >> ISACTIVER_SHIFT;
81
Achin Gupta92712a52015-09-03 14:18:02 +010082 return mmio_read_32(base + GICD_ISACTIVER + (n << 2));
83}
84
85/*
86 * Accessor to read the GIC Distributor ICACTIVER corresponding to the
87 * interrupt `id`, 32 interrupt IDs at a time.
88 */
89unsigned int gicd_read_icactiver(uintptr_t base, unsigned int id)
90{
Antonio Nino Diazca994e72018-08-21 10:02:33 +010091 unsigned int n = id >> ICACTIVER_SHIFT;
92
Achin Gupta92712a52015-09-03 14:18:02 +010093 return mmio_read_32(base + GICD_ICACTIVER + (n << 2));
94}
95
96/*
97 * Accessor to read the GIC Distributor IPRIORITYR corresponding to the
98 * interrupt `id`, 4 interrupt IDs at a time.
99 */
100unsigned int gicd_read_ipriorityr(uintptr_t base, unsigned int id)
101{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100102 unsigned int n = id >> IPRIORITYR_SHIFT;
103
Achin Gupta92712a52015-09-03 14:18:02 +0100104 return mmio_read_32(base + GICD_IPRIORITYR + (n << 2));
105}
106
107/*
108 * Accessor to read the GIC Distributor ICGFR corresponding to the
109 * interrupt `id`, 16 interrupt IDs at a time.
110 */
111unsigned int gicd_read_icfgr(uintptr_t base, unsigned int id)
112{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100113 unsigned int n = id >> ICFGR_SHIFT;
114
Achin Gupta92712a52015-09-03 14:18:02 +0100115 return mmio_read_32(base + GICD_ICFGR + (n << 2));
116}
117
118/*
119 * Accessor to read the GIC Distributor NSACR corresponding to the
120 * interrupt `id`, 16 interrupt IDs at a time.
121 */
122unsigned int gicd_read_nsacr(uintptr_t base, unsigned int id)
123{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100124 unsigned int n = id >> NSACR_SHIFT;
125
Achin Gupta92712a52015-09-03 14:18:02 +0100126 return mmio_read_32(base + GICD_NSACR + (n << 2));
127}
128
129/*******************************************************************************
130 * GIC Distributor interface accessors for writing entire registers
131 ******************************************************************************/
132/*
133 * Accessor to write the GIC Distributor IGROUPR corresponding to the
134 * interrupt `id`, 32 interrupt IDs at a time.
135 */
136void gicd_write_igroupr(uintptr_t base, unsigned int id, unsigned int val)
137{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100138 unsigned int n = id >> IGROUPR_SHIFT;
139
Achin Gupta92712a52015-09-03 14:18:02 +0100140 mmio_write_32(base + GICD_IGROUPR + (n << 2), val);
141}
142
143/*
144 * Accessor to write the GIC Distributor ISENABLER corresponding to the
145 * interrupt `id`, 32 interrupt IDs at a time.
146 */
147void gicd_write_isenabler(uintptr_t base, unsigned int id, unsigned int val)
148{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100149 unsigned int n = id >> ISENABLER_SHIFT;
150
Achin Gupta92712a52015-09-03 14:18:02 +0100151 mmio_write_32(base + GICD_ISENABLER + (n << 2), val);
152}
153
154/*
155 * Accessor to write the GIC Distributor ICENABLER corresponding to the
156 * interrupt `id`, 32 interrupt IDs at a time.
157 */
158void gicd_write_icenabler(uintptr_t base, unsigned int id, unsigned int val)
159{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100160 unsigned int n = id >> ICENABLER_SHIFT;
161
Achin Gupta92712a52015-09-03 14:18:02 +0100162 mmio_write_32(base + GICD_ICENABLER + (n << 2), val);
163}
164
165/*
166 * Accessor to write the GIC Distributor ISPENDR corresponding to the
167 * interrupt `id`, 32 interrupt IDs at a time.
168 */
169void gicd_write_ispendr(uintptr_t base, unsigned int id, unsigned int val)
170{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100171 unsigned int n = id >> ISPENDR_SHIFT;
172
Achin Gupta92712a52015-09-03 14:18:02 +0100173 mmio_write_32(base + GICD_ISPENDR + (n << 2), val);
174}
175
176/*
177 * Accessor to write the GIC Distributor ICPENDR corresponding to the
178 * interrupt `id`, 32 interrupt IDs at a time.
179 */
180void gicd_write_icpendr(uintptr_t base, unsigned int id, unsigned int val)
181{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100182 unsigned int n = id >> ICPENDR_SHIFT;
183
Achin Gupta92712a52015-09-03 14:18:02 +0100184 mmio_write_32(base + GICD_ICPENDR + (n << 2), val);
185}
186
187/*
188 * Accessor to write the GIC Distributor ISACTIVER corresponding to the
189 * interrupt `id`, 32 interrupt IDs at a time.
190 */
191void gicd_write_isactiver(uintptr_t base, unsigned int id, unsigned int val)
192{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100193 unsigned int n = id >> ISACTIVER_SHIFT;
194
Achin Gupta92712a52015-09-03 14:18:02 +0100195 mmio_write_32(base + GICD_ISACTIVER + (n << 2), val);
196}
197
198/*
199 * Accessor to write the GIC Distributor ICACTIVER corresponding to the
200 * interrupt `id`, 32 interrupt IDs at a time.
201 */
202void gicd_write_icactiver(uintptr_t base, unsigned int id, unsigned int val)
203{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100204 unsigned int n = id >> ICACTIVER_SHIFT;
205
Achin Gupta92712a52015-09-03 14:18:02 +0100206 mmio_write_32(base + GICD_ICACTIVER + (n << 2), val);
207}
208
209/*
210 * Accessor to write the GIC Distributor IPRIORITYR corresponding to the
211 * interrupt `id`, 4 interrupt IDs at a time.
212 */
213void gicd_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val)
214{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100215 unsigned int n = id >> IPRIORITYR_SHIFT;
216
Achin Gupta92712a52015-09-03 14:18:02 +0100217 mmio_write_32(base + GICD_IPRIORITYR + (n << 2), val);
218}
219
220/*
221 * Accessor to write the GIC Distributor ICFGR corresponding to the
222 * interrupt `id`, 16 interrupt IDs at a time.
223 */
224void gicd_write_icfgr(uintptr_t base, unsigned int id, unsigned int val)
225{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100226 unsigned int n = id >> ICFGR_SHIFT;
227
Achin Gupta92712a52015-09-03 14:18:02 +0100228 mmio_write_32(base + GICD_ICFGR + (n << 2), val);
229}
230
231/*
232 * Accessor to write the GIC Distributor NSACR corresponding to the
233 * interrupt `id`, 16 interrupt IDs at a time.
234 */
235void gicd_write_nsacr(uintptr_t base, unsigned int id, unsigned int val)
236{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100237 unsigned int n = id >> NSACR_SHIFT;
238
Achin Gupta92712a52015-09-03 14:18:02 +0100239 mmio_write_32(base + GICD_NSACR + (n << 2), val);
240}
241
242/*******************************************************************************
Soby Mathew50f6fe42016-02-01 17:59:22 +0000243 * GIC Distributor functions for accessing the GIC registers
244 * corresponding to a single interrupt ID. These functions use bitwise
245 * operations or appropriate register accesses to modify or return
246 * the bit-field corresponding the single interrupt ID.
Achin Gupta92712a52015-09-03 14:18:02 +0100247 ******************************************************************************/
248unsigned int gicd_get_igroupr(uintptr_t base, unsigned int id)
249{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100250 unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100251 unsigned int reg_val = gicd_read_igroupr(base, id);
252
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100253 return (reg_val >> bit_num) & 0x1U;
Achin Gupta92712a52015-09-03 14:18:02 +0100254}
255
256void gicd_set_igroupr(uintptr_t base, unsigned int id)
257{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100258 unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100259 unsigned int reg_val = gicd_read_igroupr(base, id);
260
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100261 gicd_write_igroupr(base, id, reg_val | (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100262}
263
264void gicd_clr_igroupr(uintptr_t base, unsigned int id)
265{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100266 unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100267 unsigned int reg_val = gicd_read_igroupr(base, id);
268
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100269 gicd_write_igroupr(base, id, reg_val & ~(1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100270}
271
272void gicd_set_isenabler(uintptr_t base, unsigned int id)
273{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100274 unsigned int bit_num = id & ((1U << ISENABLER_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100275
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100276 gicd_write_isenabler(base, id, (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100277}
278
279void gicd_set_icenabler(uintptr_t base, unsigned int id)
280{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100281 unsigned int bit_num = id & ((1U << ICENABLER_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100282
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100283 gicd_write_icenabler(base, id, (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100284}
285
286void gicd_set_ispendr(uintptr_t base, unsigned int id)
287{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100288 unsigned int bit_num = id & ((1U << ISPENDR_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100289
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100290 gicd_write_ispendr(base, id, (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100291}
292
293void gicd_set_icpendr(uintptr_t base, unsigned int id)
294{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100295 unsigned int bit_num = id & ((1U << ICPENDR_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100296
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100297 gicd_write_icpendr(base, id, (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100298}
299
Jeenu Viswambharan24e70292017-09-22 08:32:09 +0100300unsigned int gicd_get_isactiver(uintptr_t base, unsigned int id)
301{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100302 unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U);
Jeenu Viswambharan24e70292017-09-22 08:32:09 +0100303 unsigned int reg_val = gicd_read_isactiver(base, id);
304
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100305 return (reg_val >> bit_num) & 0x1U;
Jeenu Viswambharan24e70292017-09-22 08:32:09 +0100306}
307
Achin Gupta92712a52015-09-03 14:18:02 +0100308void gicd_set_isactiver(uintptr_t base, unsigned int id)
309{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100310 unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100311
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100312 gicd_write_isactiver(base, id, (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100313}
314
315void gicd_set_icactiver(uintptr_t base, unsigned int id)
316{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100317 unsigned int bit_num = id & ((1U << ICACTIVER_SHIFT) - 1U);
Achin Gupta92712a52015-09-03 14:18:02 +0100318
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100319 gicd_write_icactiver(base, id, (1U << bit_num));
Achin Gupta92712a52015-09-03 14:18:02 +0100320}
Soby Mathew421259e2016-01-15 14:20:57 +0000321
322void gicd_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri)
323{
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100324 uint8_t val = pri & GIC_PRI_MASK;
325
326 mmio_write_8(base + GICD_IPRIORITYR + id, val);
Soby Mathew421259e2016-01-15 14:20:57 +0000327}
Jeenu Viswambharan4684bce2017-09-22 08:32:09 +0100328
329void gicd_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg)
330{
Jeenu Viswambharanb6982c02018-03-22 08:57:52 +0000331 /* Interrupt configuration is a 2-bit field */
Antonio Nino Diazca994e72018-08-21 10:02:33 +0100332 unsigned int bit_num = id & ((1U << ICFGR_SHIFT) - 1U);
Jeenu Viswambharanb6982c02018-03-22 08:57:52 +0000333 unsigned int bit_shift = bit_num << 1;
334
Jeenu Viswambharan4684bce2017-09-22 08:32:09 +0100335 uint32_t reg_val = gicd_read_icfgr(base, id);
336
337 /* Clear the field, and insert required configuration */
Jeenu Viswambharanb6982c02018-03-22 08:57:52 +0000338 reg_val &= ~(GIC_CFG_MASK << bit_shift);
339 reg_val |= ((cfg & GIC_CFG_MASK) << bit_shift);
Jeenu Viswambharan4684bce2017-09-22 08:32:09 +0100340
341 gicd_write_icfgr(base, id, reg_val);
342}