Software APIs
dif_racl_ctrl_autogen.c
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5
6
7
8
9
10
11// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
12// util/autogen_dif.py -i
13// hw/top_darjeeling/ip_autogen/racl_ctrl/data/racl_ctrl.hjson -o
14// bazel-out/k8-fastbuild-ST-ae23cdef058d/bin/sw/device/lib/dif/autogen
15
16
17#include <stdint.h>
18
21
22#include "racl_ctrl_regs.h" // Generated.
23
24
26dif_result_t dif_racl_ctrl_init(
27 mmio_region_t base_addr,
28 dif_racl_ctrl_t *racl_ctrl) {
29 if (racl_ctrl == NULL) {
30 return kDifBadArg;
31 }
32
33 racl_ctrl->dt = kDtRaclCtrlCount;
34 racl_ctrl->base_addr = base_addr;
35
36 return kDifOk;
37}
38
40dif_result_t dif_racl_ctrl_init_from_dt(
42 dif_racl_ctrl_t *racl_ctrl) {
43 if (racl_ctrl == NULL) {
44 return kDifBadArg;
45 }
46
47 racl_ctrl->dt = dt;
48 racl_ctrl->base_addr = mmio_region_from_addr(dt_racl_ctrl_primary_reg_block(dt));
49
50 return kDifOk;
51}
52
53dif_result_t dif_racl_ctrl_get_dt(
54 const dif_racl_ctrl_t *racl_ctrl,
55 dt_racl_ctrl_t *dt) {
56 if (racl_ctrl->dt == kDtRaclCtrlCount || dt == NULL) {
57 return kDifBadArg;
58 }
59 *dt = racl_ctrl->dt;
60 return kDifOk;
61}
62
63 dif_result_t dif_racl_ctrl_alert_force(
64 const dif_racl_ctrl_t *racl_ctrl,
66 if (racl_ctrl == NULL) {
67 return kDifBadArg;
68 }
69
70 bitfield_bit32_index_t alert_idx;
71 switch (alert) {
73 alert_idx = RACL_CTRL_ALERT_TEST_FATAL_FAULT_BIT;
74 break;
76 alert_idx = RACL_CTRL_ALERT_TEST_RECOV_CTRL_UPDATE_ERR_BIT;
77 break;
78 default:
79 return kDifBadArg;
80 }
81
82 uint32_t alert_test_reg = bitfield_bit32_write(0, alert_idx, true);
83 mmio_region_write32(
84 racl_ctrl->base_addr,
85 (ptrdiff_t)RACL_CTRL_ALERT_TEST_REG_OFFSET,
86 alert_test_reg);
87
88
89 return kDifOk;
90}
91
92
93 /**
94 * Get the corresponding interrupt register bit offset of the IRQ.
95 */
96 static bool racl_ctrl_get_irq_bit_index(
97 dif_racl_ctrl_irq_t irq,
98 bitfield_bit32_index_t *index_out) {
99
100 switch (irq) {
102 *index_out = RACL_CTRL_INTR_STATE_RACL_ERROR_BIT;
103 break;
104 default:
105 return false;
106 }
107
108 return true;
109 }
110
111 static dif_irq_type_t irq_types[] = {
113 };
114
116 dif_result_t dif_racl_ctrl_irq_get_type(
117 const dif_racl_ctrl_t *racl_ctrl,
118 dif_racl_ctrl_irq_t irq,
119 dif_irq_type_t *type) {
120
121
122 if (racl_ctrl == NULL ||
123 type == NULL ||
126 return kDifBadArg;
127 }
128
129 *type = irq_types[irq];
130
131 return kDifOk;
132 }
133
135 dif_result_t dif_racl_ctrl_irq_get_state(
136 const dif_racl_ctrl_t *racl_ctrl,
138
139 if (racl_ctrl == NULL || snapshot == NULL) {
140 return kDifBadArg;
141 }
142
143 *snapshot = mmio_region_read32(
144 racl_ctrl->base_addr,
145 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET);
146
147
148 return kDifOk;
149 }
150
152 dif_result_t dif_racl_ctrl_irq_acknowledge_state(
153 const dif_racl_ctrl_t *racl_ctrl,
155 if (racl_ctrl == NULL) {
156 return kDifBadArg;
157 }
158
159 mmio_region_write32(
160 racl_ctrl->base_addr,
161 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET,
162 snapshot);
163
164
165 return kDifOk;
166 }
167
169 dif_result_t dif_racl_ctrl_irq_is_pending(
170 const dif_racl_ctrl_t *racl_ctrl,
171 dif_racl_ctrl_irq_t irq,
172 bool *is_pending) {
173
174 if (racl_ctrl == NULL || is_pending == NULL) {
175 return kDifBadArg;
176 }
177
179 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
180 return kDifBadArg;
181 }
182
183 uint32_t intr_state_reg = mmio_region_read32(
184 racl_ctrl->base_addr,
185 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET);
186
187
188 *is_pending = bitfield_bit32_read(intr_state_reg, index);
189
190 return kDifOk;
191 }
192
194 dif_result_t dif_racl_ctrl_irq_acknowledge_all(
195 const dif_racl_ctrl_t *racl_ctrl
196 ) {
197
198 if (racl_ctrl == NULL) {
199 return kDifBadArg;
200 }
201
202 // Writing to the register clears the corresponding bits (Write-one clear).
203 mmio_region_write32(
204 racl_ctrl->base_addr,
205 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET,
206 UINT32_MAX);
207
208
209 return kDifOk;
210 }
211
213 dif_result_t dif_racl_ctrl_irq_acknowledge(
214 const dif_racl_ctrl_t *racl_ctrl,
215 dif_racl_ctrl_irq_t irq) {
216
217 if (racl_ctrl == NULL) {
218 return kDifBadArg;
219 }
220
222 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
223 return kDifBadArg;
224 }
225
226 // Writing to the register clears the corresponding bits (Write-one clear).
227 uint32_t intr_state_reg = bitfield_bit32_write(0, index, true);
228 mmio_region_write32(
229 racl_ctrl->base_addr,
230 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET,
231 intr_state_reg);
232
233
234 return kDifOk;
235 }
236
238 dif_result_t dif_racl_ctrl_irq_force(
239 const dif_racl_ctrl_t *racl_ctrl,
240 dif_racl_ctrl_irq_t irq,
241 const bool val) {
242
243 if (racl_ctrl == NULL) {
244 return kDifBadArg;
245 }
246
248 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
249 return kDifBadArg;
250 }
251
252 uint32_t intr_test_reg = bitfield_bit32_write(0, index, val);
253 mmio_region_write32(
254 racl_ctrl->base_addr,
255 (ptrdiff_t)RACL_CTRL_INTR_TEST_REG_OFFSET,
256 intr_test_reg);
257
258
259 return kDifOk;
260 }
261
263 dif_result_t dif_racl_ctrl_irq_get_enabled(
264 const dif_racl_ctrl_t *racl_ctrl,
265 dif_racl_ctrl_irq_t irq,
266 dif_toggle_t *state) {
267
268 if (racl_ctrl == NULL || state == NULL) {
269 return kDifBadArg;
270 }
271
273 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
274 return kDifBadArg;
275 }
276
277 uint32_t intr_enable_reg = mmio_region_read32(
278 racl_ctrl->base_addr,
279 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET);
280
281
282 bool is_enabled = bitfield_bit32_read(intr_enable_reg, index);
283 *state = is_enabled ?
285
286 return kDifOk;
287 }
288
290 dif_result_t dif_racl_ctrl_irq_set_enabled(
291 const dif_racl_ctrl_t *racl_ctrl,
292 dif_racl_ctrl_irq_t irq,
293 dif_toggle_t state) {
294
295 if (racl_ctrl == NULL) {
296 return kDifBadArg;
297 }
298
300 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
301 return kDifBadArg;
302 }
303
304 uint32_t intr_enable_reg = mmio_region_read32(
305 racl_ctrl->base_addr,
306 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET);
307
308
309 bool enable_bit = (state == kDifToggleEnabled) ? true : false;
310 intr_enable_reg = bitfield_bit32_write(intr_enable_reg, index, enable_bit);
311 mmio_region_write32(
312 racl_ctrl->base_addr,
313 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET,
314 intr_enable_reg);
315
316
317 return kDifOk;
318 }
319
321 dif_result_t dif_racl_ctrl_irq_disable_all(
322 const dif_racl_ctrl_t *racl_ctrl,
324
325 if (racl_ctrl == NULL) {
326 return kDifBadArg;
327 }
328
329 // Pass the current interrupt state to the caller, if requested.
330 if (snapshot != NULL) {
331 *snapshot = mmio_region_read32(
332 racl_ctrl->base_addr,
333 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET);
334
335 }
336
337 // Disable all interrupts.
338 mmio_region_write32(
339 racl_ctrl->base_addr,
340 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET,
341 0u);
342
343
344 return kDifOk;
345 }
346
348 dif_result_t dif_racl_ctrl_irq_restore_all(
349 const dif_racl_ctrl_t *racl_ctrl,
350 const dif_racl_ctrl_irq_enable_snapshot_t *snapshot) {
351
352 if (racl_ctrl == NULL || snapshot == NULL) {
353 return kDifBadArg;
354 }
355
356 mmio_region_write32(
357 racl_ctrl->base_addr,
358 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET,
359 *snapshot);
360
361
362 return kDifOk;
363 }
364