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 "hw/top/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 ((int)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 // Keep the alert test enabled: writing 0 to the regwen bit locks the register.
84 alert_test_reg = bitfield_bit32_write(
85 alert_test_reg, RACL_CTRL_ALERT_TEST_REGWEN_BIT, true);
86 mmio_region_write32(
87 racl_ctrl->base_addr,
88 (ptrdiff_t)RACL_CTRL_ALERT_TEST_REG_OFFSET,
89 alert_test_reg);
90
91
92 return kDifOk;
93}
94
95
96 /**
97 * Get the corresponding interrupt register bit offset of the IRQ.
98 */
99 static bool racl_ctrl_get_irq_bit_index(
100 dif_racl_ctrl_irq_t irq,
101 bitfield_bit32_index_t *index_out) {
102
103 switch (irq) {
105 *index_out = RACL_CTRL_INTR_STATE_RACL_ERROR_BIT;
106 break;
107 default:
108 return false;
109 }
110
111 return true;
112 }
113
114 static dif_irq_type_t irq_types[] = {
116 };
117
119 dif_result_t dif_racl_ctrl_irq_get_type(
120 const dif_racl_ctrl_t *racl_ctrl,
121 dif_racl_ctrl_irq_t irq,
122 dif_irq_type_t *type) {
123
124
125 if (racl_ctrl == NULL ||
126 type == NULL ||
129 return kDifBadArg;
130 }
131
132 *type = irq_types[irq];
133
134 return kDifOk;
135 }
136
138 dif_result_t dif_racl_ctrl_irq_get_state(
139 const dif_racl_ctrl_t *racl_ctrl,
141
142 if (racl_ctrl == NULL || snapshot == NULL) {
143 return kDifBadArg;
144 }
145
146 *snapshot = mmio_region_read32(
147 racl_ctrl->base_addr,
148 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET);
149
150
151 return kDifOk;
152 }
153
155 dif_result_t dif_racl_ctrl_irq_acknowledge_state(
156 const dif_racl_ctrl_t *racl_ctrl,
158 if (racl_ctrl == NULL) {
159 return kDifBadArg;
160 }
161
162 mmio_region_write32(
163 racl_ctrl->base_addr,
164 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET,
165 snapshot);
166
167
168 return kDifOk;
169 }
170
172 dif_result_t dif_racl_ctrl_irq_is_pending(
173 const dif_racl_ctrl_t *racl_ctrl,
174 dif_racl_ctrl_irq_t irq,
175 bool *is_pending) {
176
177 if (racl_ctrl == NULL || is_pending == NULL) {
178 return kDifBadArg;
179 }
180
182 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
183 return kDifBadArg;
184 }
185
186 uint32_t intr_state_reg = mmio_region_read32(
187 racl_ctrl->base_addr,
188 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET);
189
190
191 *is_pending = bitfield_bit32_read(intr_state_reg, index);
192
193 return kDifOk;
194 }
195
197 dif_result_t dif_racl_ctrl_irq_acknowledge_all(
198 const dif_racl_ctrl_t *racl_ctrl
199 ) {
200
201 if (racl_ctrl == NULL) {
202 return kDifBadArg;
203 }
204
205 // Writing to the register clears the corresponding bits (Write-one clear).
206 mmio_region_write32(
207 racl_ctrl->base_addr,
208 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET,
209 UINT32_MAX);
210
211
212 return kDifOk;
213 }
214
216 dif_result_t dif_racl_ctrl_irq_acknowledge(
217 const dif_racl_ctrl_t *racl_ctrl,
218 dif_racl_ctrl_irq_t irq) {
219
220 if (racl_ctrl == NULL) {
221 return kDifBadArg;
222 }
223
225 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
226 return kDifBadArg;
227 }
228
229 // Writing to the register clears the corresponding bits (Write-one clear).
230 uint32_t intr_state_reg = bitfield_bit32_write(0, index, true);
231 mmio_region_write32(
232 racl_ctrl->base_addr,
233 (ptrdiff_t)RACL_CTRL_INTR_STATE_REG_OFFSET,
234 intr_state_reg);
235
236
237 return kDifOk;
238 }
239
241 dif_result_t dif_racl_ctrl_irq_force(
242 const dif_racl_ctrl_t *racl_ctrl,
243 dif_racl_ctrl_irq_t irq,
244 const bool val) {
245
246 if (racl_ctrl == NULL) {
247 return kDifBadArg;
248 }
249
251 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
252 return kDifBadArg;
253 }
254
255 uint32_t intr_test_reg = bitfield_bit32_write(0, index, val);
256 mmio_region_write32(
257 racl_ctrl->base_addr,
258 (ptrdiff_t)RACL_CTRL_INTR_TEST_REG_OFFSET,
259 intr_test_reg);
260
261
262 return kDifOk;
263 }
264
266 dif_result_t dif_racl_ctrl_irq_get_enabled(
267 const dif_racl_ctrl_t *racl_ctrl,
268 dif_racl_ctrl_irq_t irq,
269 dif_toggle_t *state) {
270
271 if (racl_ctrl == NULL || state == NULL) {
272 return kDifBadArg;
273 }
274
276 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
277 return kDifBadArg;
278 }
279
280 uint32_t intr_enable_reg = mmio_region_read32(
281 racl_ctrl->base_addr,
282 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET);
283
284
285 bool is_enabled = bitfield_bit32_read(intr_enable_reg, index);
286 *state = is_enabled ?
288
289 return kDifOk;
290 }
291
293 dif_result_t dif_racl_ctrl_irq_set_enabled(
294 const dif_racl_ctrl_t *racl_ctrl,
295 dif_racl_ctrl_irq_t irq,
296 dif_toggle_t state) {
297
298 if (racl_ctrl == NULL) {
299 return kDifBadArg;
300 }
301
303 if (!racl_ctrl_get_irq_bit_index(irq, &index)) {
304 return kDifBadArg;
305 }
306
307 uint32_t intr_enable_reg = mmio_region_read32(
308 racl_ctrl->base_addr,
309 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET);
310
311
312 bool enable_bit = (state == kDifToggleEnabled) ? true : false;
313 intr_enable_reg = bitfield_bit32_write(intr_enable_reg, index, enable_bit);
314 mmio_region_write32(
315 racl_ctrl->base_addr,
316 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET,
317 intr_enable_reg);
318
319
320 return kDifOk;
321 }
322
324 dif_result_t dif_racl_ctrl_irq_disable_all(
325 const dif_racl_ctrl_t *racl_ctrl,
327
328 if (racl_ctrl == NULL) {
329 return kDifBadArg;
330 }
331
332 // Pass the current interrupt state to the caller, if requested.
333 if (snapshot != NULL) {
334 *snapshot = mmio_region_read32(
335 racl_ctrl->base_addr,
336 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET);
337
338 }
339
340 // Disable all interrupts.
341 mmio_region_write32(
342 racl_ctrl->base_addr,
343 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET,
344 0u);
345
346
347 return kDifOk;
348 }
349
351 dif_result_t dif_racl_ctrl_irq_restore_all(
352 const dif_racl_ctrl_t *racl_ctrl,
353 const dif_racl_ctrl_irq_enable_snapshot_t *snapshot) {
354
355 if (racl_ctrl == NULL || snapshot == NULL) {
356 return kDifBadArg;
357 }
358
359 mmio_region_write32(
360 racl_ctrl->base_addr,
361 (ptrdiff_t)RACL_CTRL_INTR_ENABLE_REG_OFFSET,
362 *snapshot);
363
364
365 return kDifOk;
366 }
367