Pavona Software APIs
isr_testutils.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// THIS FILE HAS BEEN GENERATED, DO NOT EDIT MANUALLY. COMMAND:
6// util/autogen_testutils.py
7
8#include "sw/device/lib/testing/autogen/isr_testutils.h"
10
12#include "sw/device/lib/testing/test_framework/check.h"
13
14void isr_testutils_ac_range_check_isr(
15 plic_isr_ctx_t plic_ctx, ac_range_check_isr_ctx_t ac_range_check_ctx,
16 bool mute_status_irq, top_dragonfly_plic_peripheral_t *peripheral_serviced,
17 dif_ac_range_check_irq_t *irq_serviced) {
18
19 // Claim the IRQ at the PLIC.
20 dif_rv_plic_irq_id_t plic_irq_id;
21 CHECK_DIF_OK(
22 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
23
24 // Get the peripheral the IRQ belongs to.
25 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
26 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
27
28 // Get the IRQ that was fired from the PLIC IRQ ID.
29 dif_ac_range_check_irq_t irq =
30 (dif_ac_range_check_irq_t)(plic_irq_id -
31 ac_range_check_ctx
32 .plic_ac_range_check_start_irq_id);
33 *irq_serviced = irq;
34
35 // Check if it is supposed to be the only IRQ fired.
36 if (ac_range_check_ctx.is_only_irq) {
38 CHECK_DIF_OK(dif_ac_range_check_irq_get_state(
39 ac_range_check_ctx.ac_range_check, &snapshot));
40 CHECK(snapshot == (dif_ac_range_check_irq_state_snapshot_t)(1 << irq),
41 "Only ac_range_check IRQ %d expected to fire. Actual IRQ state = %x",
42 irq, snapshot);
43 }
44
45 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
46 dif_irq_type_t type;
47 CHECK_DIF_OK(dif_ac_range_check_irq_get_type(
48 ac_range_check_ctx.ac_range_check, irq, &type));
49 if (type == kDifIrqTypeEvent) {
50 CHECK_DIF_OK(dif_ac_range_check_irq_acknowledge(
51 ac_range_check_ctx.ac_range_check, irq));
52 } else if (mute_status_irq) {
53 CHECK_DIF_OK(dif_ac_range_check_irq_set_enabled(
54 ac_range_check_ctx.ac_range_check, irq, kDifToggleDisabled));
55 }
56
57 // Complete the IRQ at the PLIC.
58 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
59 plic_irq_id));
60}
61
62void isr_testutils_acc_isr(plic_isr_ctx_t plic_ctx, acc_isr_ctx_t acc_ctx,
63 top_dragonfly_plic_peripheral_t *peripheral_serviced,
64 dif_acc_irq_t *irq_serviced) {
65
66 // Claim the IRQ at the PLIC.
67 dif_rv_plic_irq_id_t plic_irq_id;
68 CHECK_DIF_OK(
69 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
70
71 // Get the peripheral the IRQ belongs to.
72 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
73 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
74
75 // Get the IRQ that was fired from the PLIC IRQ ID.
76 dif_acc_irq_t irq =
77 (dif_acc_irq_t)(plic_irq_id - acc_ctx.plic_acc_start_irq_id);
78 *irq_serviced = irq;
79
80 // Check if it is supposed to be the only IRQ fired.
81 if (acc_ctx.is_only_irq) {
83 CHECK_DIF_OK(dif_acc_irq_get_state(acc_ctx.acc, &snapshot));
84 CHECK(snapshot == (dif_acc_irq_state_snapshot_t)(1 << irq),
85 "Only acc IRQ %d expected to fire. Actual IRQ state = %x", irq,
86 snapshot);
87 }
88
89 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
90 dif_irq_type_t type;
91 CHECK_DIF_OK(dif_acc_irq_get_type(acc_ctx.acc, irq, &type));
92 if (type == kDifIrqTypeEvent) {
93 CHECK_DIF_OK(dif_acc_irq_acknowledge(acc_ctx.acc, irq));
94 }
95
96 // Complete the IRQ at the PLIC.
97 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
98 plic_irq_id));
99}
100
101void isr_testutils_alert_handler_isr(
102 plic_isr_ctx_t plic_ctx, alert_handler_isr_ctx_t alert_handler_ctx,
103 top_dragonfly_plic_peripheral_t *peripheral_serviced,
104 dif_alert_handler_irq_t *irq_serviced) {
105
106 // Claim the IRQ at the PLIC.
107 dif_rv_plic_irq_id_t plic_irq_id;
108 CHECK_DIF_OK(
109 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
110
111 // Get the peripheral the IRQ belongs to.
112 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
113 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
114
115 // Get the IRQ that was fired from the PLIC IRQ ID.
116 dif_alert_handler_irq_t irq =
117 (dif_alert_handler_irq_t)(plic_irq_id -
118 alert_handler_ctx
119 .plic_alert_handler_start_irq_id);
120 *irq_serviced = irq;
121
122 // Check if it is supposed to be the only IRQ fired.
123 if (alert_handler_ctx.is_only_irq) {
125 CHECK_DIF_OK(dif_alert_handler_irq_get_state(
126 alert_handler_ctx.alert_handler, &snapshot));
127 CHECK(snapshot == (dif_alert_handler_irq_state_snapshot_t)(1 << irq),
128 "Only alert_handler IRQ %d expected to fire. Actual IRQ state = %x",
129 irq, snapshot);
130 }
131
132 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
133 dif_irq_type_t type;
134 CHECK_DIF_OK(dif_alert_handler_irq_get_type(alert_handler_ctx.alert_handler,
135 irq, &type));
136 if (type == kDifIrqTypeEvent) {
137 CHECK_DIF_OK(dif_alert_handler_irq_acknowledge(
138 alert_handler_ctx.alert_handler, irq));
139 }
140
141 // Complete the IRQ at the PLIC.
142 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
143 plic_irq_id));
144}
145
146void isr_testutils_aon_timer_isr(
147 plic_isr_ctx_t plic_ctx, aon_timer_isr_ctx_t aon_timer_ctx,
148 top_dragonfly_plic_peripheral_t *peripheral_serviced,
149 dif_aon_timer_irq_t *irq_serviced) {
150
151 // Claim the IRQ at the PLIC.
152 dif_rv_plic_irq_id_t plic_irq_id;
153 CHECK_DIF_OK(
154 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
155
156 // Get the peripheral the IRQ belongs to.
157 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
158 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
159
160 // Get the IRQ that was fired from the PLIC IRQ ID.
161 dif_aon_timer_irq_t irq =
162 (dif_aon_timer_irq_t)(plic_irq_id -
163 aon_timer_ctx.plic_aon_timer_start_irq_id);
164 *irq_serviced = irq;
165
166 // Check if it is supposed to be the only IRQ fired.
167 if (aon_timer_ctx.is_only_irq) {
169 CHECK_DIF_OK(
170 dif_aon_timer_irq_get_state(aon_timer_ctx.aon_timer, &snapshot));
171 CHECK(snapshot == (dif_aon_timer_irq_state_snapshot_t)(1 << irq),
172 "Only aon_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
173 snapshot);
174 }
175
176 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
177 dif_irq_type_t type;
178 CHECK_DIF_OK(dif_aon_timer_irq_get_type(aon_timer_ctx.aon_timer, irq, &type));
179 if (type == kDifIrqTypeEvent) {
180 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge(aon_timer_ctx.aon_timer, irq));
181 }
182
183 // Complete the IRQ at the PLIC.
184 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
185 plic_irq_id));
186}
187
188void isr_testutils_csrng_isr(
189 plic_isr_ctx_t plic_ctx, csrng_isr_ctx_t csrng_ctx,
190 top_dragonfly_plic_peripheral_t *peripheral_serviced,
191 dif_csrng_irq_t *irq_serviced) {
192
193 // Claim the IRQ at the PLIC.
194 dif_rv_plic_irq_id_t plic_irq_id;
195 CHECK_DIF_OK(
196 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
197
198 // Get the peripheral the IRQ belongs to.
199 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
200 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
201
202 // Get the IRQ that was fired from the PLIC IRQ ID.
203 dif_csrng_irq_t irq =
204 (dif_csrng_irq_t)(plic_irq_id - csrng_ctx.plic_csrng_start_irq_id);
205 *irq_serviced = irq;
206
207 // Check if it is supposed to be the only IRQ fired.
208 if (csrng_ctx.is_only_irq) {
210 CHECK_DIF_OK(dif_csrng_irq_get_state(csrng_ctx.csrng, &snapshot));
211 CHECK(snapshot == (dif_csrng_irq_state_snapshot_t)(1 << irq),
212 "Only csrng IRQ %d expected to fire. Actual IRQ state = %x", irq,
213 snapshot);
214 }
215
216 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
217 dif_irq_type_t type;
218 CHECK_DIF_OK(dif_csrng_irq_get_type(csrng_ctx.csrng, irq, &type));
219 if (type == kDifIrqTypeEvent) {
220 CHECK_DIF_OK(dif_csrng_irq_acknowledge(csrng_ctx.csrng, irq));
221 }
222
223 // Complete the IRQ at the PLIC.
224 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
225 plic_irq_id));
226}
227
228void isr_testutils_dma_isr(plic_isr_ctx_t plic_ctx, dma_isr_ctx_t dma_ctx,
229 bool mute_status_irq,
230 top_dragonfly_plic_peripheral_t *peripheral_serviced,
231 dif_dma_irq_t *irq_serviced) {
232
233 // Claim the IRQ at the PLIC.
234 dif_rv_plic_irq_id_t plic_irq_id;
235 CHECK_DIF_OK(
236 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
237
238 // Get the peripheral the IRQ belongs to.
239 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
240 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
241
242 // Get the IRQ that was fired from the PLIC IRQ ID.
243 dif_dma_irq_t irq =
244 (dif_dma_irq_t)(plic_irq_id - dma_ctx.plic_dma_start_irq_id);
245 *irq_serviced = irq;
246
247 // Check if it is supposed to be the only IRQ fired.
248 if (dma_ctx.is_only_irq) {
250 CHECK_DIF_OK(dif_dma_irq_get_state(dma_ctx.dma, &snapshot));
251 CHECK(snapshot == (dif_dma_irq_state_snapshot_t)(1 << irq),
252 "Only dma IRQ %d expected to fire. Actual IRQ state = %x", irq,
253 snapshot);
254 }
255
256 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
257 dif_irq_type_t type;
258 CHECK_DIF_OK(dif_dma_irq_get_type(dma_ctx.dma, irq, &type));
259 if (type == kDifIrqTypeEvent) {
260 CHECK_DIF_OK(dif_dma_irq_acknowledge(dma_ctx.dma, irq));
261 } else if (mute_status_irq) {
262 CHECK_DIF_OK(dif_dma_irq_set_enabled(dma_ctx.dma, irq, kDifToggleDisabled));
263 }
264
265 // Complete the IRQ at the PLIC.
266 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
267 plic_irq_id));
268}
269
270void isr_testutils_edn_isr(plic_isr_ctx_t plic_ctx, edn_isr_ctx_t edn_ctx,
271 top_dragonfly_plic_peripheral_t *peripheral_serviced,
272 dif_edn_irq_t *irq_serviced) {
273
274 // Claim the IRQ at the PLIC.
275 dif_rv_plic_irq_id_t plic_irq_id;
276 CHECK_DIF_OK(
277 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
278
279 // Get the peripheral the IRQ belongs to.
280 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
281 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
282
283 // Get the IRQ that was fired from the PLIC IRQ ID.
284 dif_edn_irq_t irq =
285 (dif_edn_irq_t)(plic_irq_id - edn_ctx.plic_edn_start_irq_id);
286 *irq_serviced = irq;
287
288 // Check if it is supposed to be the only IRQ fired.
289 if (edn_ctx.is_only_irq) {
291 CHECK_DIF_OK(dif_edn_irq_get_state(edn_ctx.edn, &snapshot));
292 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
293 "Only edn IRQ %d expected to fire. Actual IRQ state = %x", irq,
294 snapshot);
295 }
296
297 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
298 dif_irq_type_t type;
299 CHECK_DIF_OK(dif_edn_irq_get_type(edn_ctx.edn, irq, &type));
300 if (type == kDifIrqTypeEvent) {
301 CHECK_DIF_OK(dif_edn_irq_acknowledge(edn_ctx.edn, irq));
302 }
303
304 // Complete the IRQ at the PLIC.
305 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
306 plic_irq_id));
307}
308
309void isr_testutils_entropy_src_isr(
310 plic_isr_ctx_t plic_ctx, entropy_src_isr_ctx_t entropy_src_ctx,
311 top_dragonfly_plic_peripheral_t *peripheral_serviced,
312 dif_entropy_src_irq_t *irq_serviced) {
313
314 // Claim the IRQ at the PLIC.
315 dif_rv_plic_irq_id_t plic_irq_id;
316 CHECK_DIF_OK(
317 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
318
319 // Get the peripheral the IRQ belongs to.
320 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
321 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
322
323 // Get the IRQ that was fired from the PLIC IRQ ID.
324 dif_entropy_src_irq_t irq =
325 (dif_entropy_src_irq_t)(plic_irq_id -
326 entropy_src_ctx.plic_entropy_src_start_irq_id);
327 *irq_serviced = irq;
328
329 // Check if it is supposed to be the only IRQ fired.
330 if (entropy_src_ctx.is_only_irq) {
332 CHECK_DIF_OK(
333 dif_entropy_src_irq_get_state(entropy_src_ctx.entropy_src, &snapshot));
334 CHECK(snapshot == (dif_entropy_src_irq_state_snapshot_t)(1 << irq),
335 "Only entropy_src IRQ %d expected to fire. Actual IRQ state = %x",
336 irq, snapshot);
337 }
338
339 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
340 dif_irq_type_t type;
341 CHECK_DIF_OK(
342 dif_entropy_src_irq_get_type(entropy_src_ctx.entropy_src, irq, &type));
343 if (type == kDifIrqTypeEvent) {
344 CHECK_DIF_OK(
345 dif_entropy_src_irq_acknowledge(entropy_src_ctx.entropy_src, irq));
346 }
347
348 // Complete the IRQ at the PLIC.
349 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
350 plic_irq_id));
351}
352
353void isr_testutils_gpio_isr(
354 plic_isr_ctx_t plic_ctx, gpio_isr_ctx_t gpio_ctx,
355 top_dragonfly_plic_peripheral_t *peripheral_serviced,
356 dif_gpio_irq_t *irq_serviced) {
357
358 // Claim the IRQ at the PLIC.
359 dif_rv_plic_irq_id_t plic_irq_id;
360 CHECK_DIF_OK(
361 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
362
363 // Get the peripheral the IRQ belongs to.
364 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
365 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
366
367 // Get the IRQ that was fired from the PLIC IRQ ID.
368 dif_gpio_irq_t irq =
369 (dif_gpio_irq_t)(plic_irq_id - gpio_ctx.plic_gpio_start_irq_id);
370 *irq_serviced = irq;
371
372 // Check if it is supposed to be the only IRQ fired.
373 if (gpio_ctx.is_only_irq) {
375 CHECK_DIF_OK(dif_gpio_irq_get_state(gpio_ctx.gpio, &snapshot));
376 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
377 "Only gpio IRQ %d expected to fire. Actual IRQ state = %x", irq,
378 snapshot);
379 }
380
381 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
382 dif_irq_type_t type;
383 CHECK_DIF_OK(dif_gpio_irq_get_type(gpio_ctx.gpio, irq, &type));
384 if (type == kDifIrqTypeEvent) {
385 CHECK_DIF_OK(dif_gpio_irq_acknowledge(gpio_ctx.gpio, irq));
386 }
387
388 // Complete the IRQ at the PLIC.
389 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
390 plic_irq_id));
391}
392
393void isr_testutils_hmac_isr(
394 plic_isr_ctx_t plic_ctx, hmac_isr_ctx_t hmac_ctx, bool mute_status_irq,
395 top_dragonfly_plic_peripheral_t *peripheral_serviced,
396 dif_hmac_irq_t *irq_serviced) {
397
398 // Claim the IRQ at the PLIC.
399 dif_rv_plic_irq_id_t plic_irq_id;
400 CHECK_DIF_OK(
401 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
402
403 // Get the peripheral the IRQ belongs to.
404 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
405 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
406
407 // Get the IRQ that was fired from the PLIC IRQ ID.
408 dif_hmac_irq_t irq =
409 (dif_hmac_irq_t)(plic_irq_id - hmac_ctx.plic_hmac_start_irq_id);
410 *irq_serviced = irq;
411
412 // Check if it is supposed to be the only IRQ fired.
413 if (hmac_ctx.is_only_irq) {
415 CHECK_DIF_OK(dif_hmac_irq_get_state(hmac_ctx.hmac, &snapshot));
416 CHECK(snapshot == (dif_hmac_irq_state_snapshot_t)(1 << irq),
417 "Only hmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
418 snapshot);
419 }
420
421 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
422 dif_irq_type_t type;
423 CHECK_DIF_OK(dif_hmac_irq_get_type(hmac_ctx.hmac, irq, &type));
424 if (type == kDifIrqTypeEvent) {
425 CHECK_DIF_OK(dif_hmac_irq_acknowledge(hmac_ctx.hmac, irq));
426 } else if (mute_status_irq) {
427 CHECK_DIF_OK(
428 dif_hmac_irq_set_enabled(hmac_ctx.hmac, irq, kDifToggleDisabled));
429 }
430
431 // Complete the IRQ at the PLIC.
432 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
433 plic_irq_id));
434}
435
436void isr_testutils_i2c_isr(plic_isr_ctx_t plic_ctx, i2c_isr_ctx_t i2c_ctx,
437 bool mute_status_irq,
438 top_dragonfly_plic_peripheral_t *peripheral_serviced,
439 dif_i2c_irq_t *irq_serviced) {
440
441 // Claim the IRQ at the PLIC.
442 dif_rv_plic_irq_id_t plic_irq_id;
443 CHECK_DIF_OK(
444 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
445
446 // Get the peripheral the IRQ belongs to.
447 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
448 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
449
450 // Get the IRQ that was fired from the PLIC IRQ ID.
451 dif_i2c_irq_t irq =
452 (dif_i2c_irq_t)(plic_irq_id - i2c_ctx.plic_i2c_start_irq_id);
453 *irq_serviced = irq;
454
455 // Check if it is supposed to be the only IRQ fired.
456 if (i2c_ctx.is_only_irq) {
458 CHECK_DIF_OK(dif_i2c_irq_get_state(i2c_ctx.i2c, &snapshot));
459 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
460 "Only i2c IRQ %d expected to fire. Actual IRQ state = %x", irq,
461 snapshot);
462 }
463
464 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
465 dif_irq_type_t type;
466 CHECK_DIF_OK(dif_i2c_irq_get_type(i2c_ctx.i2c, irq, &type));
467 if (type == kDifIrqTypeEvent) {
468 CHECK_DIF_OK(dif_i2c_irq_acknowledge(i2c_ctx.i2c, irq));
469 } else if (mute_status_irq) {
470 CHECK_DIF_OK(dif_i2c_irq_set_enabled(i2c_ctx.i2c, irq, kDifToggleDisabled));
471 }
472
473 // Complete the IRQ at the PLIC.
474 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
475 plic_irq_id));
476}
477
478void isr_testutils_keymgr_dpe_isr(
479 plic_isr_ctx_t plic_ctx, keymgr_dpe_isr_ctx_t keymgr_dpe_ctx,
480 top_dragonfly_plic_peripheral_t *peripheral_serviced,
481 dif_keymgr_dpe_irq_t *irq_serviced) {
482
483 // Claim the IRQ at the PLIC.
484 dif_rv_plic_irq_id_t plic_irq_id;
485 CHECK_DIF_OK(
486 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
487
488 // Get the peripheral the IRQ belongs to.
489 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
490 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
491
492 // Get the IRQ that was fired from the PLIC IRQ ID.
493 dif_keymgr_dpe_irq_t irq =
494 (dif_keymgr_dpe_irq_t)(plic_irq_id -
495 keymgr_dpe_ctx.plic_keymgr_dpe_start_irq_id);
496 *irq_serviced = irq;
497
498 // Check if it is supposed to be the only IRQ fired.
499 if (keymgr_dpe_ctx.is_only_irq) {
501 CHECK_DIF_OK(
502 dif_keymgr_dpe_irq_get_state(keymgr_dpe_ctx.keymgr_dpe, &snapshot));
503 CHECK(snapshot == (dif_keymgr_dpe_irq_state_snapshot_t)(1 << irq),
504 "Only keymgr_dpe IRQ %d expected to fire. Actual IRQ state = %x", irq,
505 snapshot);
506 }
507
508 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
509 dif_irq_type_t type;
510 CHECK_DIF_OK(
511 dif_keymgr_dpe_irq_get_type(keymgr_dpe_ctx.keymgr_dpe, irq, &type));
512 if (type == kDifIrqTypeEvent) {
513 CHECK_DIF_OK(
514 dif_keymgr_dpe_irq_acknowledge(keymgr_dpe_ctx.keymgr_dpe, irq));
515 }
516
517 // Complete the IRQ at the PLIC.
518 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
519 plic_irq_id));
520}
521
522void isr_testutils_kmac_isr(
523 plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx, bool mute_status_irq,
524 top_dragonfly_plic_peripheral_t *peripheral_serviced,
525 dif_kmac_irq_t *irq_serviced) {
526
527 // Claim the IRQ at the PLIC.
528 dif_rv_plic_irq_id_t plic_irq_id;
529 CHECK_DIF_OK(
530 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
531
532 // Get the peripheral the IRQ belongs to.
533 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
534 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
535
536 // Get the IRQ that was fired from the PLIC IRQ ID.
537 dif_kmac_irq_t irq =
538 (dif_kmac_irq_t)(plic_irq_id - kmac_ctx.plic_kmac_start_irq_id);
539 *irq_serviced = irq;
540
541 // Check if it is supposed to be the only IRQ fired.
542 if (kmac_ctx.is_only_irq) {
544 CHECK_DIF_OK(dif_kmac_irq_get_state(kmac_ctx.kmac, &snapshot));
545 CHECK(snapshot == (dif_kmac_irq_state_snapshot_t)(1 << irq),
546 "Only kmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
547 snapshot);
548 }
549
550 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
551 dif_irq_type_t type;
552 CHECK_DIF_OK(dif_kmac_irq_get_type(kmac_ctx.kmac, irq, &type));
553 if (type == kDifIrqTypeEvent) {
554 CHECK_DIF_OK(dif_kmac_irq_acknowledge(kmac_ctx.kmac, irq));
555 } else if (mute_status_irq) {
556 CHECK_DIF_OK(
557 dif_kmac_irq_set_enabled(kmac_ctx.kmac, irq, kDifToggleDisabled));
558 }
559
560 // Complete the IRQ at the PLIC.
561 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
562 plic_irq_id));
563}
564
565void isr_testutils_mbx_isr(plic_isr_ctx_t plic_ctx, mbx_isr_ctx_t mbx_ctx,
566 top_dragonfly_plic_peripheral_t *peripheral_serviced,
567 dif_mbx_irq_t *irq_serviced) {
568
569 // Claim the IRQ at the PLIC.
570 dif_rv_plic_irq_id_t plic_irq_id;
571 CHECK_DIF_OK(
572 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
573
574 // Get the peripheral the IRQ belongs to.
575 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
576 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
577
578 // Get the IRQ that was fired from the PLIC IRQ ID.
579 dif_mbx_irq_t irq =
580 (dif_mbx_irq_t)(plic_irq_id - mbx_ctx.plic_mbx_start_irq_id);
581 *irq_serviced = irq;
582
583 // Check if it is supposed to be the only IRQ fired.
584 if (mbx_ctx.is_only_irq) {
586 CHECK_DIF_OK(dif_mbx_irq_get_state(mbx_ctx.mbx, &snapshot));
587 CHECK(snapshot == (dif_mbx_irq_state_snapshot_t)(1 << irq),
588 "Only mbx IRQ %d expected to fire. Actual IRQ state = %x", irq,
589 snapshot);
590 }
591
592 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
593 dif_irq_type_t type;
594 CHECK_DIF_OK(dif_mbx_irq_get_type(mbx_ctx.mbx, irq, &type));
595 if (type == kDifIrqTypeEvent) {
596 CHECK_DIF_OK(dif_mbx_irq_acknowledge(mbx_ctx.mbx, irq));
597 }
598
599 // Complete the IRQ at the PLIC.
600 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
601 plic_irq_id));
602}
603
604void isr_testutils_otp_ctrl_isr(
605 plic_isr_ctx_t plic_ctx, otp_ctrl_isr_ctx_t otp_ctrl_ctx,
606 top_dragonfly_plic_peripheral_t *peripheral_serviced,
607 dif_otp_ctrl_irq_t *irq_serviced) {
608
609 // Claim the IRQ at the PLIC.
610 dif_rv_plic_irq_id_t plic_irq_id;
611 CHECK_DIF_OK(
612 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
613
614 // Get the peripheral the IRQ belongs to.
615 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
616 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
617
618 // Get the IRQ that was fired from the PLIC IRQ ID.
619 dif_otp_ctrl_irq_t irq =
620 (dif_otp_ctrl_irq_t)(plic_irq_id -
621 otp_ctrl_ctx.plic_otp_ctrl_start_irq_id);
622 *irq_serviced = irq;
623
624 // Check if it is supposed to be the only IRQ fired.
625 if (otp_ctrl_ctx.is_only_irq) {
627 CHECK_DIF_OK(dif_otp_ctrl_irq_get_state(otp_ctrl_ctx.otp_ctrl, &snapshot));
628 CHECK(snapshot == (dif_otp_ctrl_irq_state_snapshot_t)(1 << irq),
629 "Only otp_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
630 snapshot);
631 }
632
633 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
634 dif_irq_type_t type;
635 CHECK_DIF_OK(dif_otp_ctrl_irq_get_type(otp_ctrl_ctx.otp_ctrl, irq, &type));
636 if (type == kDifIrqTypeEvent) {
637 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge(otp_ctrl_ctx.otp_ctrl, irq));
638 }
639
640 // Complete the IRQ at the PLIC.
641 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
642 plic_irq_id));
643}
644
645void isr_testutils_pwrmgr_isr(
646 plic_isr_ctx_t plic_ctx, pwrmgr_isr_ctx_t pwrmgr_ctx,
647 top_dragonfly_plic_peripheral_t *peripheral_serviced,
648 dif_pwrmgr_irq_t *irq_serviced) {
649
650 // Claim the IRQ at the PLIC.
651 dif_rv_plic_irq_id_t plic_irq_id;
652 CHECK_DIF_OK(
653 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
654
655 // Get the peripheral the IRQ belongs to.
656 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
657 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
658
659 // Get the IRQ that was fired from the PLIC IRQ ID.
660 dif_pwrmgr_irq_t irq =
661 (dif_pwrmgr_irq_t)(plic_irq_id - pwrmgr_ctx.plic_pwrmgr_start_irq_id);
662 *irq_serviced = irq;
663
664 // Check if it is supposed to be the only IRQ fired.
665 if (pwrmgr_ctx.is_only_irq) {
667 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(pwrmgr_ctx.pwrmgr, &snapshot));
668 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
669 "Only pwrmgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
670 snapshot);
671 }
672
673 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
674 dif_irq_type_t type;
675 CHECK_DIF_OK(dif_pwrmgr_irq_get_type(pwrmgr_ctx.pwrmgr, irq, &type));
676 if (type == kDifIrqTypeEvent) {
677 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(pwrmgr_ctx.pwrmgr, irq));
678 }
679
680 // Complete the IRQ at the PLIC.
681 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
682 plic_irq_id));
683}
684
685void isr_testutils_racl_ctrl_isr(
686 plic_isr_ctx_t plic_ctx, racl_ctrl_isr_ctx_t racl_ctrl_ctx,
687 bool mute_status_irq, top_dragonfly_plic_peripheral_t *peripheral_serviced,
688 dif_racl_ctrl_irq_t *irq_serviced) {
689
690 // Claim the IRQ at the PLIC.
691 dif_rv_plic_irq_id_t plic_irq_id;
692 CHECK_DIF_OK(
693 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
694
695 // Get the peripheral the IRQ belongs to.
696 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
697 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
698
699 // Get the IRQ that was fired from the PLIC IRQ ID.
700 dif_racl_ctrl_irq_t irq =
701 (dif_racl_ctrl_irq_t)(plic_irq_id -
702 racl_ctrl_ctx.plic_racl_ctrl_start_irq_id);
703 *irq_serviced = irq;
704
705 // Check if it is supposed to be the only IRQ fired.
706 if (racl_ctrl_ctx.is_only_irq) {
708 CHECK_DIF_OK(
709 dif_racl_ctrl_irq_get_state(racl_ctrl_ctx.racl_ctrl, &snapshot));
710 CHECK(snapshot == (dif_racl_ctrl_irq_state_snapshot_t)(1 << irq),
711 "Only racl_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
712 snapshot);
713 }
714
715 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
716 dif_irq_type_t type;
717 CHECK_DIF_OK(dif_racl_ctrl_irq_get_type(racl_ctrl_ctx.racl_ctrl, irq, &type));
718 if (type == kDifIrqTypeEvent) {
719 CHECK_DIF_OK(dif_racl_ctrl_irq_acknowledge(racl_ctrl_ctx.racl_ctrl, irq));
720 } else if (mute_status_irq) {
721 CHECK_DIF_OK(dif_racl_ctrl_irq_set_enabled(racl_ctrl_ctx.racl_ctrl, irq,
723 }
724
725 // Complete the IRQ at the PLIC.
726 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
727 plic_irq_id));
728}
729
730void isr_testutils_rv_timer_isr(
731 plic_isr_ctx_t plic_ctx, rv_timer_isr_ctx_t rv_timer_ctx,
732 top_dragonfly_plic_peripheral_t *peripheral_serviced,
733 dif_rv_timer_irq_t *irq_serviced) {
734
735 // Claim the IRQ at the PLIC.
736 dif_rv_plic_irq_id_t plic_irq_id;
737 CHECK_DIF_OK(
738 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
739
740 // Get the peripheral the IRQ belongs to.
741 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
742 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
743
744 // Get the IRQ that was fired from the PLIC IRQ ID.
745 dif_rv_timer_irq_t irq =
746 (dif_rv_timer_irq_t)(plic_irq_id -
747 rv_timer_ctx.plic_rv_timer_start_irq_id);
748 *irq_serviced = irq;
749
750 // Check if it is supposed to be the only IRQ fired.
751 if (rv_timer_ctx.is_only_irq) {
753 CHECK_DIF_OK(dif_rv_timer_irq_get_state(rv_timer_ctx.rv_timer,
754 plic_ctx.hart_id, &snapshot));
755 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
756 "Only rv_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
757 snapshot);
758 }
759
760 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
761 dif_irq_type_t type;
762 CHECK_DIF_OK(dif_rv_timer_irq_get_type(rv_timer_ctx.rv_timer, irq, &type));
763 if (type == kDifIrqTypeEvent) {
764 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(rv_timer_ctx.rv_timer, irq));
765 }
766
767 // Complete the IRQ at the PLIC.
768 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
769 plic_irq_id));
770}
771
772void isr_testutils_spi_device_isr(
773 plic_isr_ctx_t plic_ctx, spi_device_isr_ctx_t spi_device_ctx,
774 bool mute_status_irq, top_dragonfly_plic_peripheral_t *peripheral_serviced,
775 dif_spi_device_irq_t *irq_serviced) {
776
777 // Claim the IRQ at the PLIC.
778 dif_rv_plic_irq_id_t plic_irq_id;
779 CHECK_DIF_OK(
780 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
781
782 // Get the peripheral the IRQ belongs to.
783 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
784 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
785
786 // Get the IRQ that was fired from the PLIC IRQ ID.
787 dif_spi_device_irq_t irq =
788 (dif_spi_device_irq_t)(plic_irq_id -
789 spi_device_ctx.plic_spi_device_start_irq_id);
790 *irq_serviced = irq;
791
792 // Check if it is supposed to be the only IRQ fired.
793 if (spi_device_ctx.is_only_irq) {
795 CHECK_DIF_OK(
796 dif_spi_device_irq_get_state(spi_device_ctx.spi_device, &snapshot));
797 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
798 "Only spi_device IRQ %d expected to fire. Actual IRQ state = %x", irq,
799 snapshot);
800 }
801
802 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
803 dif_irq_type_t type;
804 CHECK_DIF_OK(
805 dif_spi_device_irq_get_type(spi_device_ctx.spi_device, irq, &type));
806 if (type == kDifIrqTypeEvent) {
807 CHECK_DIF_OK(
808 dif_spi_device_irq_acknowledge(spi_device_ctx.spi_device, irq));
809 } else if (mute_status_irq) {
810 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(spi_device_ctx.spi_device, irq,
812 }
813
814 // Complete the IRQ at the PLIC.
815 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
816 plic_irq_id));
817}
818
819void isr_testutils_spi_host_isr(
820 plic_isr_ctx_t plic_ctx, spi_host_isr_ctx_t spi_host_ctx,
821 bool mute_status_irq, top_dragonfly_plic_peripheral_t *peripheral_serviced,
822 dif_spi_host_irq_t *irq_serviced) {
823
824 // Claim the IRQ at the PLIC.
825 dif_rv_plic_irq_id_t plic_irq_id;
826 CHECK_DIF_OK(
827 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
828
829 // Get the peripheral the IRQ belongs to.
830 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
831 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
832
833 // Get the IRQ that was fired from the PLIC IRQ ID.
834 dif_spi_host_irq_t irq =
835 (dif_spi_host_irq_t)(plic_irq_id -
836 spi_host_ctx.plic_spi_host_start_irq_id);
837 *irq_serviced = irq;
838
839 // Check if it is supposed to be the only IRQ fired.
840 if (spi_host_ctx.is_only_irq) {
842 CHECK_DIF_OK(dif_spi_host_irq_get_state(spi_host_ctx.spi_host, &snapshot));
843 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
844 "Only spi_host IRQ %d expected to fire. Actual IRQ state = %x", irq,
845 snapshot);
846 }
847
848 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
849 dif_irq_type_t type;
850 CHECK_DIF_OK(dif_spi_host_irq_get_type(spi_host_ctx.spi_host, irq, &type));
851 if (type == kDifIrqTypeEvent) {
852 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(spi_host_ctx.spi_host, irq));
853 } else if (mute_status_irq) {
854 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(spi_host_ctx.spi_host, irq,
856 }
857
858 // Complete the IRQ at the PLIC.
859 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
860 plic_irq_id));
861}
862
863void isr_testutils_uart_isr(
864 plic_isr_ctx_t plic_ctx, uart_isr_ctx_t uart_ctx, bool mute_status_irq,
865 top_dragonfly_plic_peripheral_t *peripheral_serviced,
866 dif_uart_irq_t *irq_serviced) {
867
868 // Claim the IRQ at the PLIC.
869 dif_rv_plic_irq_id_t plic_irq_id;
870 CHECK_DIF_OK(
871 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
872
873 // Get the peripheral the IRQ belongs to.
874 *peripheral_serviced = (top_dragonfly_plic_peripheral_t)
875 top_dragonfly_plic_interrupt_for_peripheral[plic_irq_id];
876
877 // Get the IRQ that was fired from the PLIC IRQ ID.
878 dif_uart_irq_t irq =
879 (dif_uart_irq_t)(plic_irq_id - uart_ctx.plic_uart_start_irq_id);
880 *irq_serviced = irq;
881
882 // Check if it is supposed to be the only IRQ fired.
883 if (uart_ctx.is_only_irq) {
885 CHECK_DIF_OK(dif_uart_irq_get_state(uart_ctx.uart, &snapshot));
886 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)(1 << irq),
887 "Only uart IRQ %d expected to fire. Actual IRQ state = %x", irq,
888 snapshot);
889 }
890
891 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
892 dif_irq_type_t type;
893 CHECK_DIF_OK(dif_uart_irq_get_type(uart_ctx.uart, irq, &type));
894 if (type == kDifIrqTypeEvent) {
895 CHECK_DIF_OK(dif_uart_irq_acknowledge(uart_ctx.uart, irq));
896 } else if (mute_status_irq) {
897 CHECK_DIF_OK(
898 dif_uart_irq_set_enabled(uart_ctx.uart, irq, kDifToggleDisabled));
899 }
900
901 // Complete the IRQ at the PLIC.
902 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
903 plic_irq_id));
904}