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