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