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