RTEMS 6.1-rc2
Loading...
Searching...
No Matches
arm-gic.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2013, 2019 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef LIBBSP_ARM_SHARED_ARM_GIC_H
37#define LIBBSP_ARM_SHARED_ARM_GIC_H
38
40
41#include <stdbool.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46
55#define GIC_ID_TO_ONE_BIT_REG_INDEX(id) ((id) >> 5)
56#define GIC_ID_TO_ONE_BIT_REG_BIT(id) (1U << ((id) & 0x1fU))
57
58#define GIC_ID_TO_TWO_BITS_REG_INDEX(id) ((id) >> 4)
59#define GIC_ID_TO_TWO_BITS_REG_OFFSET(id) (((id) & 0xfU) << 1)
60
61static inline bool gic_id_is_enabled(volatile gic_dist *dist, uint32_t id)
62{
63 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
64 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
65
66 return (dist->icdiser[i] & bit) != 0;
67}
68
69static inline void gic_id_enable(volatile gic_dist *dist, uint32_t id)
70{
71 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
72 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
73
74 dist->icdiser[i] = bit;
75}
76
77static inline void gic_id_disable(volatile gic_dist *dist, uint32_t id)
78{
79 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
80 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
81
82 dist->icdicer[i] = bit;
83}
84
85static inline bool gic_id_is_pending(volatile gic_dist *dist, uint32_t id)
86{
87 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
88 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
89
90 return (dist->icdispr[i] & bit) != 0;
91}
92
93static inline void gic_id_set_pending(volatile gic_dist *dist, uint32_t id)
94{
95 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
96 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
97
98 dist->icdispr[i] = bit;
99}
100
101static inline void gic_id_clear_pending(volatile gic_dist *dist, uint32_t id)
102{
103 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
104 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
105
106 dist->icdicpr[i] = bit;
107}
108
109static inline bool gic_id_is_active(volatile gic_dist *dist, uint32_t id)
110{
111 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
112 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
113
114 return (dist->icdabr[i] & bit) != 0;
115}
116
117typedef enum {
118 GIC_GROUP_0,
119 GIC_GROUP_1
120} gic_group;
121
122static inline gic_group gic_id_get_group(
123 volatile gic_dist *dist,
124 uint32_t id
125)
126{
127 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
128 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
129
130 return (dist->icdigr[i] & bit) != 0 ? GIC_GROUP_1 : GIC_GROUP_0;
131}
132
133static inline void gic_id_set_group(
134 volatile gic_dist *dist,
135 uint32_t id,
136 gic_group group
137)
138{
139 uint32_t i = GIC_ID_TO_ONE_BIT_REG_INDEX(id);
140 uint32_t bit = GIC_ID_TO_ONE_BIT_REG_BIT(id);
141 uint32_t icdigr = dist->icdigr[i];
142
143 icdigr &= ~bit;
144
145 if (group == GIC_GROUP_1) {
146 icdigr |= bit;
147 }
148
149 dist->icdigr[i] = icdigr;
150}
151
152static inline void gic_id_set_priority(
153 volatile gic_dist *dist,
154 uint32_t id,
155 uint8_t priority
156)
157{
158 dist->icdipr[id] = priority;
159}
160
161static inline uint8_t gic_id_get_priority(volatile gic_dist *dist, uint32_t id)
162{
163 return dist->icdipr[id];
164}
165
166static inline void gic_id_set_targets(
167 volatile gic_dist *dist,
168 uint32_t id,
169 uint8_t targets
170)
171{
172 dist->icdiptr[id] = targets;
173}
174
175static inline uint8_t gic_id_get_targets(volatile gic_dist *dist, uint32_t id)
176{
177 return dist->icdiptr[id];
178}
179
180typedef enum {
181 GIC_LEVEL_SENSITIVE,
182 GIC_EDGE_TRIGGERED
183} gic_trigger_mode;
184
185static inline gic_trigger_mode gic_id_get_trigger_mode(
186 volatile gic_dist *dist,
187 uint32_t id
188)
189{
190 uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
191 uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id) + 1;
192 uint32_t bit = 1U << o;
193
194 return (dist->icdicfr[i] & bit) != 0 ?
195 GIC_EDGE_TRIGGERED : GIC_LEVEL_SENSITIVE;
196}
197
198static inline void gic_id_set_trigger_mode(
199 volatile gic_dist *dist,
200 uint32_t id,
201 gic_trigger_mode mode
202)
203{
204 uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
205 uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id) + 1;
206 uint32_t bit = mode << o;
207 uint32_t mask = 1U << o;
208 uint32_t icdicfr = dist->icdicfr[i];
209
210 icdicfr &= ~mask;
211 icdicfr |= bit;
212
213 dist->icdicfr[i] = icdicfr;
214}
215
216typedef enum {
217 GIC_N_TO_N,
218 GIC_1_TO_N
219} gic_handling_model;
220
221static inline gic_handling_model gic_id_get_handling_model(
222 volatile gic_dist *dist,
223 uint32_t id
224)
225{
226 uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
227 uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id);
228 uint32_t bit = 1U << o;
229
230 return (dist->icdicfr[i] & bit) != 0 ? GIC_1_TO_N : GIC_N_TO_N;
231}
232
233static inline void gic_id_set_handling_model(
234 volatile gic_dist *dist,
235 uint32_t id,
236 gic_handling_model model
237)
238{
239 uint32_t i = GIC_ID_TO_TWO_BITS_REG_INDEX(id);
240 uint32_t o = GIC_ID_TO_TWO_BITS_REG_OFFSET(id);
241 uint32_t bit = model << o;
242 uint32_t mask = 1U << o;
243 uint32_t icdicfr = dist->icdicfr[i];
244
245 icdicfr &= ~mask;
246 icdicfr |= bit;
247
248 dist->icdicfr[i] = icdicfr;
249}
250
251#ifdef __cplusplus
252}
253#endif /* __cplusplus */
254
255#endif /* LIBBSP_ARM_SHARED_ARM_GIC_H */
ARM GIC Register definitions.
Definition: arm-gic-regs.h:101