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
13#include "sw/device/lib/testing/test_framework/check.h"
14
15void isr_testutils_adc_ctrl_isr(
16 plic_isr_ctx_t plic_ctx, adc_ctrl_isr_ctx_t adc_ctrl_ctx,
17 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
18 dif_adc_ctrl_irq_t *irq_serviced) {
19
20 // Claim the IRQ at the PLIC.
21 dif_rv_plic_irq_id_t plic_irq_id;
22 CHECK_DIF_OK(
23 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
24
25 // Get the peripheral the IRQ belongs to.
26 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
27 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
28
29 // Get the IRQ that was fired from the PLIC IRQ ID.
30 dif_adc_ctrl_irq_t irq =
31 (dif_adc_ctrl_irq_t)(plic_irq_id -
32 adc_ctrl_ctx.plic_adc_ctrl_start_irq_id);
33 *irq_serviced = irq;
34
35 // Check if it is supposed to be the only IRQ fired.
36 if (adc_ctrl_ctx.is_only_irq) {
38 CHECK_DIF_OK(dif_adc_ctrl_irq_get_state(adc_ctrl_ctx.adc_ctrl, &snapshot));
39 CHECK(snapshot == (dif_adc_ctrl_irq_state_snapshot_t)(1 << irq),
40 "Only adc_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
41 snapshot);
42 }
43
44 // TODO(lowRISC/opentitan:#11354): future releases of the ADC Controller HW
45 // should hide the need to also clear the cause CSRs. At which point, this can
46 // be removed.
47 CHECK_DIF_OK(dif_adc_ctrl_irq_clear_causes(adc_ctrl_ctx.adc_ctrl,
49
50 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
51 dif_irq_type_t type;
52 CHECK_DIF_OK(dif_adc_ctrl_irq_get_type(adc_ctrl_ctx.adc_ctrl, irq, &type));
53 if (type == kDifIrqTypeEvent) {
54 CHECK_DIF_OK(dif_adc_ctrl_irq_acknowledge(adc_ctrl_ctx.adc_ctrl, irq));
55 } else if (mute_status_irq) {
56 CHECK_DIF_OK(dif_adc_ctrl_irq_set_enabled(adc_ctrl_ctx.adc_ctrl, irq,
58 }
59
60 // Complete the IRQ at the PLIC.
61 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
62 plic_irq_id));
63}
64
65void isr_testutils_alert_handler_isr(
66 plic_isr_ctx_t plic_ctx, alert_handler_isr_ctx_t alert_handler_ctx,
67 top_earlgrey_plic_peripheral_t *peripheral_serviced,
68 dif_alert_handler_irq_t *irq_serviced) {
69
70 // Claim the IRQ at the PLIC.
71 dif_rv_plic_irq_id_t plic_irq_id;
72 CHECK_DIF_OK(
73 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
74
75 // Get the peripheral the IRQ belongs to.
76 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
77 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
78
79 // Get the IRQ that was fired from the PLIC IRQ ID.
80 dif_alert_handler_irq_t irq =
81 (dif_alert_handler_irq_t)(plic_irq_id -
82 alert_handler_ctx
83 .plic_alert_handler_start_irq_id);
84 *irq_serviced = irq;
85
86 // Check if it is supposed to be the only IRQ fired.
87 if (alert_handler_ctx.is_only_irq) {
89 CHECK_DIF_OK(dif_alert_handler_irq_get_state(
90 alert_handler_ctx.alert_handler, &snapshot));
91 CHECK(snapshot == (dif_alert_handler_irq_state_snapshot_t)(1 << irq),
92 "Only alert_handler IRQ %d expected to fire. Actual IRQ state = %x",
93 irq, snapshot);
94 }
95
96 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
97 dif_irq_type_t type;
98 CHECK_DIF_OK(dif_alert_handler_irq_get_type(alert_handler_ctx.alert_handler,
99 irq, &type));
100 if (type == kDifIrqTypeEvent) {
101 CHECK_DIF_OK(dif_alert_handler_irq_acknowledge(
102 alert_handler_ctx.alert_handler, irq));
103 }
104
105 // Complete the IRQ at the PLIC.
106 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
107 plic_irq_id));
108}
109
110void isr_testutils_aon_timer_isr(
111 plic_isr_ctx_t plic_ctx, aon_timer_isr_ctx_t aon_timer_ctx,
112 top_earlgrey_plic_peripheral_t *peripheral_serviced,
113 dif_aon_timer_irq_t *irq_serviced) {
114
115 // Claim the IRQ at the PLIC.
116 dif_rv_plic_irq_id_t plic_irq_id;
117 CHECK_DIF_OK(
118 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
119
120 // Get the peripheral the IRQ belongs to.
121 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
122 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
123
124 // Get the IRQ that was fired from the PLIC IRQ ID.
125 dif_aon_timer_irq_t irq =
126 (dif_aon_timer_irq_t)(plic_irq_id -
127 aon_timer_ctx.plic_aon_timer_start_irq_id);
128 *irq_serviced = irq;
129
130 // Check if it is supposed to be the only IRQ fired.
131 if (aon_timer_ctx.is_only_irq) {
133 CHECK_DIF_OK(
134 dif_aon_timer_irq_get_state(aon_timer_ctx.aon_timer, &snapshot));
135 CHECK(snapshot == (dif_aon_timer_irq_state_snapshot_t)(1 << irq),
136 "Only aon_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
137 snapshot);
138 }
139
140 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
141 dif_irq_type_t type;
142 CHECK_DIF_OK(dif_aon_timer_irq_get_type(aon_timer_ctx.aon_timer, irq, &type));
143 if (type == kDifIrqTypeEvent) {
144 CHECK_DIF_OK(dif_aon_timer_irq_acknowledge(aon_timer_ctx.aon_timer, irq));
145 }
146
147 // Complete the IRQ at the PLIC.
148 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
149 plic_irq_id));
150}
151
152void isr_testutils_cheriot_mem_sys_isr(
153 plic_isr_ctx_t plic_ctx, cheriot_mem_sys_isr_ctx_t cheriot_mem_sys_ctx,
154 top_earlgrey_plic_peripheral_t *peripheral_serviced,
155 dif_cheriot_mem_sys_irq_t *irq_serviced) {
156
157 // Claim the IRQ at the PLIC.
158 dif_rv_plic_irq_id_t plic_irq_id;
159 CHECK_DIF_OK(
160 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
161
162 // Get the peripheral the IRQ belongs to.
163 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
164 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
165
166 // Get the IRQ that was fired from the PLIC IRQ ID.
167 dif_cheriot_mem_sys_irq_t irq =
168 (dif_cheriot_mem_sys_irq_t)(plic_irq_id -
169 cheriot_mem_sys_ctx
170 .plic_cheriot_mem_sys_start_irq_id);
171 *irq_serviced = irq;
172
173 // Check if it is supposed to be the only IRQ fired.
174 if (cheriot_mem_sys_ctx.is_only_irq) {
176 CHECK_DIF_OK(dif_cheriot_mem_sys_irq_get_state(
177 cheriot_mem_sys_ctx.cheriot_mem_sys, &snapshot));
178 CHECK(snapshot == (dif_cheriot_mem_sys_irq_state_snapshot_t)(1 << irq),
179 "Only cheriot_mem_sys IRQ %d expected to fire. Actual IRQ state = %x",
180 irq, snapshot);
181 }
182
183 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
184 dif_irq_type_t type;
185 CHECK_DIF_OK(dif_cheriot_mem_sys_irq_get_type(
186 cheriot_mem_sys_ctx.cheriot_mem_sys, irq, &type));
187 if (type == kDifIrqTypeEvent) {
188 CHECK_DIF_OK(dif_cheriot_mem_sys_irq_acknowledge(
189 cheriot_mem_sys_ctx.cheriot_mem_sys, irq));
190 }
191
192 // Complete the IRQ at the PLIC.
193 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
194 plic_irq_id));
195}
196
197void isr_testutils_csrng_isr(
198 plic_isr_ctx_t plic_ctx, csrng_isr_ctx_t csrng_ctx,
199 top_earlgrey_plic_peripheral_t *peripheral_serviced,
200 dif_csrng_irq_t *irq_serviced) {
201
202 // Claim the IRQ at the PLIC.
203 dif_rv_plic_irq_id_t plic_irq_id;
204 CHECK_DIF_OK(
205 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
206
207 // Get the peripheral the IRQ belongs to.
208 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
209 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
210
211 // Get the IRQ that was fired from the PLIC IRQ ID.
212 dif_csrng_irq_t irq =
213 (dif_csrng_irq_t)(plic_irq_id - csrng_ctx.plic_csrng_start_irq_id);
214 *irq_serviced = irq;
215
216 // Check if it is supposed to be the only IRQ fired.
217 if (csrng_ctx.is_only_irq) {
219 CHECK_DIF_OK(dif_csrng_irq_get_state(csrng_ctx.csrng, &snapshot));
220 CHECK(snapshot == (dif_csrng_irq_state_snapshot_t)(1 << irq),
221 "Only csrng IRQ %d expected to fire. Actual IRQ state = %x", irq,
222 snapshot);
223 }
224
225 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
226 dif_irq_type_t type;
227 CHECK_DIF_OK(dif_csrng_irq_get_type(csrng_ctx.csrng, irq, &type));
228 if (type == kDifIrqTypeEvent) {
229 CHECK_DIF_OK(dif_csrng_irq_acknowledge(csrng_ctx.csrng, irq));
230 }
231
232 // Complete the IRQ at the PLIC.
233 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
234 plic_irq_id));
235}
236
237void isr_testutils_edn_isr(plic_isr_ctx_t plic_ctx, edn_isr_ctx_t edn_ctx,
238 top_earlgrey_plic_peripheral_t *peripheral_serviced,
239 dif_edn_irq_t *irq_serviced) {
240
241 // Claim the IRQ at the PLIC.
242 dif_rv_plic_irq_id_t plic_irq_id;
243 CHECK_DIF_OK(
244 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
245
246 // Get the peripheral the IRQ belongs to.
247 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
248 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
249
250 // Get the IRQ that was fired from the PLIC IRQ ID.
251 dif_edn_irq_t irq =
252 (dif_edn_irq_t)(plic_irq_id - edn_ctx.plic_edn_start_irq_id);
253 *irq_serviced = irq;
254
255 // Check if it is supposed to be the only IRQ fired.
256 if (edn_ctx.is_only_irq) {
258 CHECK_DIF_OK(dif_edn_irq_get_state(edn_ctx.edn, &snapshot));
259 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
260 "Only edn IRQ %d expected to fire. Actual IRQ state = %x", irq,
261 snapshot);
262 }
263
264 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
265 dif_irq_type_t type;
266 CHECK_DIF_OK(dif_edn_irq_get_type(edn_ctx.edn, irq, &type));
267 if (type == kDifIrqTypeEvent) {
268 CHECK_DIF_OK(dif_edn_irq_acknowledge(edn_ctx.edn, irq));
269 }
270
271 // Complete the IRQ at the PLIC.
272 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
273 plic_irq_id));
274}
275
276void isr_testutils_entropy_src_isr(
277 plic_isr_ctx_t plic_ctx, entropy_src_isr_ctx_t entropy_src_ctx,
278 top_earlgrey_plic_peripheral_t *peripheral_serviced,
279 dif_entropy_src_irq_t *irq_serviced) {
280
281 // Claim the IRQ at the PLIC.
282 dif_rv_plic_irq_id_t plic_irq_id;
283 CHECK_DIF_OK(
284 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
285
286 // Get the peripheral the IRQ belongs to.
287 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
288 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
289
290 // Get the IRQ that was fired from the PLIC IRQ ID.
291 dif_entropy_src_irq_t irq =
292 (dif_entropy_src_irq_t)(plic_irq_id -
293 entropy_src_ctx.plic_entropy_src_start_irq_id);
294 *irq_serviced = irq;
295
296 // Check if it is supposed to be the only IRQ fired.
297 if (entropy_src_ctx.is_only_irq) {
299 CHECK_DIF_OK(
300 dif_entropy_src_irq_get_state(entropy_src_ctx.entropy_src, &snapshot));
301 CHECK(snapshot == (dif_entropy_src_irq_state_snapshot_t)(1 << irq),
302 "Only entropy_src IRQ %d expected to fire. Actual IRQ state = %x",
303 irq, snapshot);
304 }
305
306 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
307 dif_irq_type_t type;
308 CHECK_DIF_OK(
309 dif_entropy_src_irq_get_type(entropy_src_ctx.entropy_src, irq, &type));
310 if (type == kDifIrqTypeEvent) {
311 CHECK_DIF_OK(
312 dif_entropy_src_irq_acknowledge(entropy_src_ctx.entropy_src, irq));
313 }
314
315 // Complete the IRQ at the PLIC.
316 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
317 plic_irq_id));
318}
319
320void isr_testutils_gpio_isr(plic_isr_ctx_t plic_ctx, gpio_isr_ctx_t gpio_ctx,
321 top_earlgrey_plic_peripheral_t *peripheral_serviced,
322 dif_gpio_irq_t *irq_serviced) {
323
324 // Claim the IRQ at the PLIC.
325 dif_rv_plic_irq_id_t plic_irq_id;
326 CHECK_DIF_OK(
327 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
328
329 // Get the peripheral the IRQ belongs to.
330 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
331 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
332
333 // Get the IRQ that was fired from the PLIC IRQ ID.
334 dif_gpio_irq_t irq =
335 (dif_gpio_irq_t)(plic_irq_id - gpio_ctx.plic_gpio_start_irq_id);
336 *irq_serviced = irq;
337
338 // Check if it is supposed to be the only IRQ fired.
339 if (gpio_ctx.is_only_irq) {
341 CHECK_DIF_OK(dif_gpio_irq_get_state(gpio_ctx.gpio, &snapshot));
342 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
343 "Only gpio IRQ %d expected to fire. Actual IRQ state = %x", irq,
344 snapshot);
345 }
346
347 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
348 dif_irq_type_t type;
349 CHECK_DIF_OK(dif_gpio_irq_get_type(gpio_ctx.gpio, irq, &type));
350 if (type == kDifIrqTypeEvent) {
351 CHECK_DIF_OK(dif_gpio_irq_acknowledge(gpio_ctx.gpio, irq));
352 }
353
354 // Complete the IRQ at the PLIC.
355 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
356 plic_irq_id));
357}
358
359void isr_testutils_hmac_isr(plic_isr_ctx_t plic_ctx, hmac_isr_ctx_t hmac_ctx,
360 bool mute_status_irq,
361 top_earlgrey_plic_peripheral_t *peripheral_serviced,
362 dif_hmac_irq_t *irq_serviced) {
363
364 // Claim the IRQ at the PLIC.
365 dif_rv_plic_irq_id_t plic_irq_id;
366 CHECK_DIF_OK(
367 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
368
369 // Get the peripheral the IRQ belongs to.
370 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
371 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
372
373 // Get the IRQ that was fired from the PLIC IRQ ID.
374 dif_hmac_irq_t irq =
375 (dif_hmac_irq_t)(plic_irq_id - hmac_ctx.plic_hmac_start_irq_id);
376 *irq_serviced = irq;
377
378 // Check if it is supposed to be the only IRQ fired.
379 if (hmac_ctx.is_only_irq) {
381 CHECK_DIF_OK(dif_hmac_irq_get_state(hmac_ctx.hmac, &snapshot));
382 CHECK(snapshot == (dif_hmac_irq_state_snapshot_t)(1 << irq),
383 "Only hmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
384 snapshot);
385 }
386
387 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
388 dif_irq_type_t type;
389 CHECK_DIF_OK(dif_hmac_irq_get_type(hmac_ctx.hmac, irq, &type));
390 if (type == kDifIrqTypeEvent) {
391 CHECK_DIF_OK(dif_hmac_irq_acknowledge(hmac_ctx.hmac, irq));
392 } else if (mute_status_irq) {
393 CHECK_DIF_OK(
394 dif_hmac_irq_set_enabled(hmac_ctx.hmac, irq, kDifToggleDisabled));
395 }
396
397 // Complete the IRQ at the PLIC.
398 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
399 plic_irq_id));
400}
401
402void isr_testutils_i2c_isr(plic_isr_ctx_t plic_ctx, i2c_isr_ctx_t i2c_ctx,
403 bool mute_status_irq,
404 top_earlgrey_plic_peripheral_t *peripheral_serviced,
405 dif_i2c_irq_t *irq_serviced) {
406
407 // Claim the IRQ at the PLIC.
408 dif_rv_plic_irq_id_t plic_irq_id;
409 CHECK_DIF_OK(
410 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
411
412 // Get the peripheral the IRQ belongs to.
413 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
414 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
415
416 // Get the IRQ that was fired from the PLIC IRQ ID.
417 dif_i2c_irq_t irq =
418 (dif_i2c_irq_t)(plic_irq_id - i2c_ctx.plic_i2c_start_irq_id);
419 *irq_serviced = irq;
420
421 // Check if it is supposed to be the only IRQ fired.
422 if (i2c_ctx.is_only_irq) {
424 CHECK_DIF_OK(dif_i2c_irq_get_state(i2c_ctx.i2c, &snapshot));
425 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
426 "Only i2c IRQ %d expected to fire. Actual IRQ state = %x", irq,
427 snapshot);
428 }
429
430 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
431 dif_irq_type_t type;
432 CHECK_DIF_OK(dif_i2c_irq_get_type(i2c_ctx.i2c, irq, &type));
433 if (type == kDifIrqTypeEvent) {
434 CHECK_DIF_OK(dif_i2c_irq_acknowledge(i2c_ctx.i2c, irq));
435 } else if (mute_status_irq) {
436 CHECK_DIF_OK(dif_i2c_irq_set_enabled(i2c_ctx.i2c, irq, kDifToggleDisabled));
437 }
438
439 // Complete the IRQ at the PLIC.
440 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
441 plic_irq_id));
442}
443
444void isr_testutils_i3c_isr(plic_isr_ctx_t plic_ctx, i3c_isr_ctx_t i3c_ctx,
445 bool mute_status_irq,
446 top_earlgrey_plic_peripheral_t *peripheral_serviced,
447 dif_i3c_irq_t *irq_serviced) {
448
449 // Claim the IRQ at the PLIC.
450 dif_rv_plic_irq_id_t plic_irq_id;
451 CHECK_DIF_OK(
452 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
453
454 // Get the peripheral the IRQ belongs to.
455 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
456 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
457
458 // Get the IRQ that was fired from the PLIC IRQ ID.
459 dif_i3c_irq_t irq =
460 (dif_i3c_irq_t)(plic_irq_id - i3c_ctx.plic_i3c_start_irq_id);
461 *irq_serviced = irq;
462
463 // Check if it is supposed to be the only IRQ fired.
464 if (i3c_ctx.is_only_irq) {
466 CHECK_DIF_OK(dif_i3c_irq_get_state(i3c_ctx.i3c, &snapshot));
467 CHECK(snapshot == (dif_i3c_irq_state_snapshot_t)(1 << irq),
468 "Only i3c IRQ %d expected to fire. Actual IRQ state = %x", irq,
469 snapshot);
470 }
471
472 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
473 dif_irq_type_t type;
474 CHECK_DIF_OK(dif_i3c_irq_get_type(i3c_ctx.i3c, irq, &type));
475 if (type == kDifIrqTypeEvent) {
476 CHECK_DIF_OK(dif_i3c_irq_acknowledge(i3c_ctx.i3c, irq));
477 } else if (mute_status_irq) {
478 CHECK_DIF_OK(dif_i3c_irq_set_enabled(i3c_ctx.i3c, irq, kDifToggleDisabled));
479 }
480
481 // Complete the IRQ at the PLIC.
482 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
483 plic_irq_id));
484}
485
486void isr_testutils_keymgr_dpe_isr(
487 plic_isr_ctx_t plic_ctx, keymgr_dpe_isr_ctx_t keymgr_dpe_ctx,
488 top_earlgrey_plic_peripheral_t *peripheral_serviced,
489 dif_keymgr_dpe_irq_t *irq_serviced) {
490
491 // Claim the IRQ at the PLIC.
492 dif_rv_plic_irq_id_t plic_irq_id;
493 CHECK_DIF_OK(
494 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
495
496 // Get the peripheral the IRQ belongs to.
497 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
498 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
499
500 // Get the IRQ that was fired from the PLIC IRQ ID.
501 dif_keymgr_dpe_irq_t irq =
502 (dif_keymgr_dpe_irq_t)(plic_irq_id -
503 keymgr_dpe_ctx.plic_keymgr_dpe_start_irq_id);
504 *irq_serviced = irq;
505
506 // Check if it is supposed to be the only IRQ fired.
507 if (keymgr_dpe_ctx.is_only_irq) {
509 CHECK_DIF_OK(
510 dif_keymgr_dpe_irq_get_state(keymgr_dpe_ctx.keymgr_dpe, &snapshot));
511 CHECK(snapshot == (dif_keymgr_dpe_irq_state_snapshot_t)(1 << irq),
512 "Only keymgr_dpe IRQ %d expected to fire. Actual IRQ state = %x", irq,
513 snapshot);
514 }
515
516 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
517 dif_irq_type_t type;
518 CHECK_DIF_OK(
519 dif_keymgr_dpe_irq_get_type(keymgr_dpe_ctx.keymgr_dpe, irq, &type));
520 if (type == kDifIrqTypeEvent) {
521 CHECK_DIF_OK(
522 dif_keymgr_dpe_irq_acknowledge(keymgr_dpe_ctx.keymgr_dpe, irq));
523 }
524
525 // Complete the IRQ at the PLIC.
526 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
527 plic_irq_id));
528}
529
530void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
531 bool mute_status_irq,
532 top_earlgrey_plic_peripheral_t *peripheral_serviced,
533 dif_kmac_irq_t *irq_serviced) {
534
535 // Claim the IRQ at the PLIC.
536 dif_rv_plic_irq_id_t plic_irq_id;
537 CHECK_DIF_OK(
538 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
539
540 // Get the peripheral the IRQ belongs to.
541 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
542 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
543
544 // Get the IRQ that was fired from the PLIC IRQ ID.
545 dif_kmac_irq_t irq =
546 (dif_kmac_irq_t)(plic_irq_id - kmac_ctx.plic_kmac_start_irq_id);
547 *irq_serviced = irq;
548
549 // Check if it is supposed to be the only IRQ fired.
550 if (kmac_ctx.is_only_irq) {
552 CHECK_DIF_OK(dif_kmac_irq_get_state(kmac_ctx.kmac, &snapshot));
553 CHECK(snapshot == (dif_kmac_irq_state_snapshot_t)(1 << irq),
554 "Only kmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
555 snapshot);
556 }
557
558 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
559 dif_irq_type_t type;
560 CHECK_DIF_OK(dif_kmac_irq_get_type(kmac_ctx.kmac, irq, &type));
561 if (type == kDifIrqTypeEvent) {
562 CHECK_DIF_OK(dif_kmac_irq_acknowledge(kmac_ctx.kmac, irq));
563 } else if (mute_status_irq) {
564 CHECK_DIF_OK(
565 dif_kmac_irq_set_enabled(kmac_ctx.kmac, irq, kDifToggleDisabled));
566 }
567
568 // Complete the IRQ at the PLIC.
569 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
570 plic_irq_id));
571}
572
573void isr_testutils_otbn_isr(plic_isr_ctx_t plic_ctx, otbn_isr_ctx_t otbn_ctx,
574 top_earlgrey_plic_peripheral_t *peripheral_serviced,
575 dif_otbn_irq_t *irq_serviced) {
576
577 // Claim the IRQ at the PLIC.
578 dif_rv_plic_irq_id_t plic_irq_id;
579 CHECK_DIF_OK(
580 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
581
582 // Get the peripheral the IRQ belongs to.
583 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
584 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
585
586 // Get the IRQ that was fired from the PLIC IRQ ID.
587 dif_otbn_irq_t irq =
588 (dif_otbn_irq_t)(plic_irq_id - otbn_ctx.plic_otbn_start_irq_id);
589 *irq_serviced = irq;
590
591 // Check if it is supposed to be the only IRQ fired.
592 if (otbn_ctx.is_only_irq) {
594 CHECK_DIF_OK(dif_otbn_irq_get_state(otbn_ctx.otbn, &snapshot));
595 CHECK(snapshot == (dif_otbn_irq_state_snapshot_t)(1 << irq),
596 "Only otbn IRQ %d expected to fire. Actual IRQ state = %x", irq,
597 snapshot);
598 }
599
600 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
601 dif_irq_type_t type;
602 CHECK_DIF_OK(dif_otbn_irq_get_type(otbn_ctx.otbn, irq, &type));
603 if (type == kDifIrqTypeEvent) {
604 CHECK_DIF_OK(dif_otbn_irq_acknowledge(otbn_ctx.otbn, irq));
605 }
606
607 // Complete the IRQ at the PLIC.
608 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
609 plic_irq_id));
610}
611
612void isr_testutils_otp_ctrl_isr(
613 plic_isr_ctx_t plic_ctx, otp_ctrl_isr_ctx_t otp_ctrl_ctx,
614 top_earlgrey_plic_peripheral_t *peripheral_serviced,
615 dif_otp_ctrl_irq_t *irq_serviced) {
616
617 // Claim the IRQ at the PLIC.
618 dif_rv_plic_irq_id_t plic_irq_id;
619 CHECK_DIF_OK(
620 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
621
622 // Get the peripheral the IRQ belongs to.
623 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
624 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
625
626 // Get the IRQ that was fired from the PLIC IRQ ID.
627 dif_otp_ctrl_irq_t irq =
628 (dif_otp_ctrl_irq_t)(plic_irq_id -
629 otp_ctrl_ctx.plic_otp_ctrl_start_irq_id);
630 *irq_serviced = irq;
631
632 // Check if it is supposed to be the only IRQ fired.
633 if (otp_ctrl_ctx.is_only_irq) {
635 CHECK_DIF_OK(dif_otp_ctrl_irq_get_state(otp_ctrl_ctx.otp_ctrl, &snapshot));
636 CHECK(snapshot == (dif_otp_ctrl_irq_state_snapshot_t)(1 << irq),
637 "Only otp_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
638 snapshot);
639 }
640
641 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
642 dif_irq_type_t type;
643 CHECK_DIF_OK(dif_otp_ctrl_irq_get_type(otp_ctrl_ctx.otp_ctrl, irq, &type));
644 if (type == kDifIrqTypeEvent) {
645 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge(otp_ctrl_ctx.otp_ctrl, irq));
646 }
647
648 // Complete the IRQ at the PLIC.
649 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
650 plic_irq_id));
651}
652
653void isr_testutils_pwrmgr_isr(
654 plic_isr_ctx_t plic_ctx, pwrmgr_isr_ctx_t pwrmgr_ctx,
655 top_earlgrey_plic_peripheral_t *peripheral_serviced,
656 dif_pwrmgr_irq_t *irq_serviced) {
657
658 // Claim the IRQ at the PLIC.
659 dif_rv_plic_irq_id_t plic_irq_id;
660 CHECK_DIF_OK(
661 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
662
663 // Get the peripheral the IRQ belongs to.
664 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
665 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
666
667 // Get the IRQ that was fired from the PLIC IRQ ID.
668 dif_pwrmgr_irq_t irq =
669 (dif_pwrmgr_irq_t)(plic_irq_id - pwrmgr_ctx.plic_pwrmgr_start_irq_id);
670 *irq_serviced = irq;
671
672 // Check if it is supposed to be the only IRQ fired.
673 if (pwrmgr_ctx.is_only_irq) {
675 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(pwrmgr_ctx.pwrmgr, &snapshot));
676 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
677 "Only pwrmgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
678 snapshot);
679 }
680
681 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
682 dif_irq_type_t type;
683 CHECK_DIF_OK(dif_pwrmgr_irq_get_type(pwrmgr_ctx.pwrmgr, irq, &type));
684 if (type == kDifIrqTypeEvent) {
685 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(pwrmgr_ctx.pwrmgr, irq));
686 }
687
688 // Complete the IRQ at the PLIC.
689 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
690 plic_irq_id));
691}
692
693void isr_testutils_rram_ctrl_isr(
694 plic_isr_ctx_t plic_ctx, rram_ctrl_isr_ctx_t rram_ctrl_ctx,
695 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
696 dif_rram_ctrl_irq_t *irq_serviced) {
697
698 // Claim the IRQ at the PLIC.
699 dif_rv_plic_irq_id_t plic_irq_id;
700 CHECK_DIF_OK(
701 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
702
703 // Get the peripheral the IRQ belongs to.
704 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
705 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
706
707 // Get the IRQ that was fired from the PLIC IRQ ID.
708 dif_rram_ctrl_irq_t irq =
709 (dif_rram_ctrl_irq_t)(plic_irq_id -
710 rram_ctrl_ctx.plic_rram_ctrl_start_irq_id);
711 *irq_serviced = irq;
712
713 // Check if it is supposed to be the only IRQ fired.
714 if (rram_ctrl_ctx.is_only_irq) {
716 CHECK_DIF_OK(
717 dif_rram_ctrl_irq_get_state(rram_ctrl_ctx.rram_ctrl, &snapshot));
718 CHECK(snapshot == (dif_rram_ctrl_irq_state_snapshot_t)(1 << irq),
719 "Only rram_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
720 snapshot);
721 }
722
723 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
724 dif_irq_type_t type;
725 CHECK_DIF_OK(dif_rram_ctrl_irq_get_type(rram_ctrl_ctx.rram_ctrl, irq, &type));
726 if (type == kDifIrqTypeEvent) {
727 CHECK_DIF_OK(dif_rram_ctrl_irq_acknowledge(rram_ctrl_ctx.rram_ctrl, irq));
728 } else if (mute_status_irq) {
729 CHECK_DIF_OK(dif_rram_ctrl_irq_set_enabled(rram_ctrl_ctx.rram_ctrl, irq,
731 }
732
733 // Complete the IRQ at the PLIC.
734 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
735 plic_irq_id));
736}
737
738void isr_testutils_rv_timer_isr(
739 plic_isr_ctx_t plic_ctx, rv_timer_isr_ctx_t rv_timer_ctx,
740 top_earlgrey_plic_peripheral_t *peripheral_serviced,
741 dif_rv_timer_irq_t *irq_serviced) {
742
743 // Claim the IRQ at the PLIC.
744 dif_rv_plic_irq_id_t plic_irq_id;
745 CHECK_DIF_OK(
746 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
747
748 // Get the peripheral the IRQ belongs to.
749 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
750 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
751
752 // Get the IRQ that was fired from the PLIC IRQ ID.
753 dif_rv_timer_irq_t irq =
754 (dif_rv_timer_irq_t)(plic_irq_id -
755 rv_timer_ctx.plic_rv_timer_start_irq_id);
756 *irq_serviced = irq;
757
758 // Check if it is supposed to be the only IRQ fired.
759 if (rv_timer_ctx.is_only_irq) {
761 CHECK_DIF_OK(dif_rv_timer_irq_get_state(rv_timer_ctx.rv_timer,
762 plic_ctx.hart_id, &snapshot));
763 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
764 "Only rv_timer IRQ %d expected to fire. Actual IRQ state = %x", irq,
765 snapshot);
766 }
767
768 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
769 dif_irq_type_t type;
770 CHECK_DIF_OK(dif_rv_timer_irq_get_type(rv_timer_ctx.rv_timer, irq, &type));
771 if (type == kDifIrqTypeEvent) {
772 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(rv_timer_ctx.rv_timer, irq));
773 }
774
775 // Complete the IRQ at the PLIC.
776 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
777 plic_irq_id));
778}
779
780void isr_testutils_sensor_ctrl_isr(
781 plic_isr_ctx_t plic_ctx, sensor_ctrl_isr_ctx_t sensor_ctrl_ctx,
782 top_earlgrey_plic_peripheral_t *peripheral_serviced,
783 dif_sensor_ctrl_irq_t *irq_serviced) {
784
785 // Claim the IRQ at the PLIC.
786 dif_rv_plic_irq_id_t plic_irq_id;
787 CHECK_DIF_OK(
788 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
789
790 // Get the peripheral the IRQ belongs to.
791 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
792 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
793
794 // Get the IRQ that was fired from the PLIC IRQ ID.
795 dif_sensor_ctrl_irq_t irq =
796 (dif_sensor_ctrl_irq_t)(plic_irq_id -
797 sensor_ctrl_ctx.plic_sensor_ctrl_start_irq_id);
798 *irq_serviced = irq;
799
800 // Check if it is supposed to be the only IRQ fired.
801 if (sensor_ctrl_ctx.is_only_irq) {
803 CHECK_DIF_OK(
804 dif_sensor_ctrl_irq_get_state(sensor_ctrl_ctx.sensor_ctrl, &snapshot));
805 CHECK(snapshot == (dif_sensor_ctrl_irq_state_snapshot_t)(1 << irq),
806 "Only sensor_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
807 irq, snapshot);
808 }
809
810 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
811 dif_irq_type_t type;
812 CHECK_DIF_OK(
813 dif_sensor_ctrl_irq_get_type(sensor_ctrl_ctx.sensor_ctrl, irq, &type));
814 if (type == kDifIrqTypeEvent) {
815 CHECK_DIF_OK(
816 dif_sensor_ctrl_irq_acknowledge(sensor_ctrl_ctx.sensor_ctrl, irq));
817 }
818
819 // Complete the IRQ at the PLIC.
820 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
821 plic_irq_id));
822}
823
824void isr_testutils_spi_device_isr(
825 plic_isr_ctx_t plic_ctx, spi_device_isr_ctx_t spi_device_ctx,
826 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
827 dif_spi_device_irq_t *irq_serviced) {
828
829 // Claim the IRQ at the PLIC.
830 dif_rv_plic_irq_id_t plic_irq_id;
831 CHECK_DIF_OK(
832 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
833
834 // Get the peripheral the IRQ belongs to.
835 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
836 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
837
838 // Get the IRQ that was fired from the PLIC IRQ ID.
839 dif_spi_device_irq_t irq =
840 (dif_spi_device_irq_t)(plic_irq_id -
841 spi_device_ctx.plic_spi_device_start_irq_id);
842 *irq_serviced = irq;
843
844 // Check if it is supposed to be the only IRQ fired.
845 if (spi_device_ctx.is_only_irq) {
847 CHECK_DIF_OK(
848 dif_spi_device_irq_get_state(spi_device_ctx.spi_device, &snapshot));
849 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
850 "Only spi_device IRQ %d expected to fire. Actual IRQ state = %x", irq,
851 snapshot);
852 }
853
854 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
855 dif_irq_type_t type;
856 CHECK_DIF_OK(
857 dif_spi_device_irq_get_type(spi_device_ctx.spi_device, irq, &type));
858 if (type == kDifIrqTypeEvent) {
859 CHECK_DIF_OK(
860 dif_spi_device_irq_acknowledge(spi_device_ctx.spi_device, irq));
861 } else if (mute_status_irq) {
862 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(spi_device_ctx.spi_device, irq,
864 }
865
866 // Complete the IRQ at the PLIC.
867 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
868 plic_irq_id));
869}
870
871void isr_testutils_spi_host_isr(
872 plic_isr_ctx_t plic_ctx, spi_host_isr_ctx_t spi_host_ctx,
873 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
874 dif_spi_host_irq_t *irq_serviced) {
875
876 // Claim the IRQ at the PLIC.
877 dif_rv_plic_irq_id_t plic_irq_id;
878 CHECK_DIF_OK(
879 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
880
881 // Get the peripheral the IRQ belongs to.
882 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
883 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
884
885 // Get the IRQ that was fired from the PLIC IRQ ID.
886 dif_spi_host_irq_t irq =
887 (dif_spi_host_irq_t)(plic_irq_id -
888 spi_host_ctx.plic_spi_host_start_irq_id);
889 *irq_serviced = irq;
890
891 // Check if it is supposed to be the only IRQ fired.
892 if (spi_host_ctx.is_only_irq) {
894 CHECK_DIF_OK(dif_spi_host_irq_get_state(spi_host_ctx.spi_host, &snapshot));
895 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
896 "Only spi_host IRQ %d expected to fire. Actual IRQ state = %x", irq,
897 snapshot);
898 }
899
900 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
901 dif_irq_type_t type;
902 CHECK_DIF_OK(dif_spi_host_irq_get_type(spi_host_ctx.spi_host, irq, &type));
903 if (type == kDifIrqTypeEvent) {
904 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(spi_host_ctx.spi_host, irq));
905 } else if (mute_status_irq) {
906 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(spi_host_ctx.spi_host, irq,
908 }
909
910 // Complete the IRQ at the PLIC.
911 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
912 plic_irq_id));
913}
914
915void isr_testutils_sysrst_ctrl_isr(
916 plic_isr_ctx_t plic_ctx, sysrst_ctrl_isr_ctx_t sysrst_ctrl_ctx,
917 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
918 dif_sysrst_ctrl_irq_t *irq_serviced) {
919
920 // Claim the IRQ at the PLIC.
921 dif_rv_plic_irq_id_t plic_irq_id;
922 CHECK_DIF_OK(
923 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
924
925 // Get the peripheral the IRQ belongs to.
926 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
927 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
928
929 // Get the IRQ that was fired from the PLIC IRQ ID.
930 dif_sysrst_ctrl_irq_t irq =
931 (dif_sysrst_ctrl_irq_t)(plic_irq_id -
932 sysrst_ctrl_ctx.plic_sysrst_ctrl_start_irq_id);
933 *irq_serviced = irq;
934
935 // Check if it is supposed to be the only IRQ fired.
936 if (sysrst_ctrl_ctx.is_only_irq) {
938 CHECK_DIF_OK(
939 dif_sysrst_ctrl_irq_get_state(sysrst_ctrl_ctx.sysrst_ctrl, &snapshot));
940 CHECK(snapshot == (dif_sysrst_ctrl_irq_state_snapshot_t)(1 << irq),
941 "Only sysrst_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
942 irq, snapshot);
943 }
944
945 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
946 dif_irq_type_t type;
947 CHECK_DIF_OK(
948 dif_sysrst_ctrl_irq_get_type(sysrst_ctrl_ctx.sysrst_ctrl, irq, &type));
949 if (type == kDifIrqTypeEvent) {
950 CHECK_DIF_OK(
951 dif_sysrst_ctrl_irq_acknowledge(sysrst_ctrl_ctx.sysrst_ctrl, irq));
952 } else if (mute_status_irq) {
953 CHECK_DIF_OK(dif_sysrst_ctrl_irq_set_enabled(sysrst_ctrl_ctx.sysrst_ctrl,
954 irq, kDifToggleDisabled));
955 }
956
957 // Complete the IRQ at the PLIC.
958 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
959 plic_irq_id));
960}
961
962void isr_testutils_uart_isr(plic_isr_ctx_t plic_ctx, uart_isr_ctx_t uart_ctx,
963 bool mute_status_irq,
964 top_earlgrey_plic_peripheral_t *peripheral_serviced,
965 dif_uart_irq_t *irq_serviced) {
966
967 // Claim the IRQ at the PLIC.
968 dif_rv_plic_irq_id_t plic_irq_id;
969 CHECK_DIF_OK(
970 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
971
972 // Get the peripheral the IRQ belongs to.
973 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
974 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
975
976 // Get the IRQ that was fired from the PLIC IRQ ID.
977 dif_uart_irq_t irq =
978 (dif_uart_irq_t)(plic_irq_id - uart_ctx.plic_uart_start_irq_id);
979 *irq_serviced = irq;
980
981 // Check if it is supposed to be the only IRQ fired.
982 if (uart_ctx.is_only_irq) {
984 CHECK_DIF_OK(dif_uart_irq_get_state(uart_ctx.uart, &snapshot));
985 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)(1 << irq),
986 "Only uart IRQ %d expected to fire. Actual IRQ state = %x", irq,
987 snapshot);
988 }
989
990 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
991 dif_irq_type_t type;
992 CHECK_DIF_OK(dif_uart_irq_get_type(uart_ctx.uart, irq, &type));
993 if (type == kDifIrqTypeEvent) {
994 CHECK_DIF_OK(dif_uart_irq_acknowledge(uart_ctx.uart, irq));
995 } else if (mute_status_irq) {
996 CHECK_DIF_OK(
997 dif_uart_irq_set_enabled(uart_ctx.uart, irq, kDifToggleDisabled));
998 }
999
1000 // Complete the IRQ at the PLIC.
1001 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
1002 plic_irq_id));
1003}
1004
1005void isr_testutils_usbdev_isr(
1006 plic_isr_ctx_t plic_ctx, usbdev_isr_ctx_t usbdev_ctx, bool mute_status_irq,
1007 top_earlgrey_plic_peripheral_t *peripheral_serviced,
1008 dif_usbdev_irq_t *irq_serviced) {
1009
1010 // Claim the IRQ at the PLIC.
1011 dif_rv_plic_irq_id_t plic_irq_id;
1012 CHECK_DIF_OK(
1013 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
1014
1015 // Get the peripheral the IRQ belongs to.
1016 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
1017 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
1018
1019 // Get the IRQ that was fired from the PLIC IRQ ID.
1020 dif_usbdev_irq_t irq =
1021 (dif_usbdev_irq_t)(plic_irq_id - usbdev_ctx.plic_usbdev_start_irq_id);
1022 *irq_serviced = irq;
1023
1024 // Check if it is supposed to be the only IRQ fired.
1025 if (usbdev_ctx.is_only_irq) {
1027 CHECK_DIF_OK(dif_usbdev_irq_get_state(usbdev_ctx.usbdev, &snapshot));
1028 CHECK(snapshot == (dif_usbdev_irq_state_snapshot_t)(1 << irq),
1029 "Only usbdev IRQ %d expected to fire. Actual IRQ state = %x", irq,
1030 snapshot);
1031 }
1032
1033 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
1034 dif_irq_type_t type;
1035 CHECK_DIF_OK(dif_usbdev_irq_get_type(usbdev_ctx.usbdev, irq, &type));
1036 if (type == kDifIrqTypeEvent) {
1037 CHECK_DIF_OK(dif_usbdev_irq_acknowledge(usbdev_ctx.usbdev, irq));
1038 } else if (mute_status_irq) {
1039 CHECK_DIF_OK(
1040 dif_usbdev_irq_set_enabled(usbdev_ctx.usbdev, irq, kDifToggleDisabled));
1041 }
1042
1043 // Complete the IRQ at the PLIC.
1044 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
1045 plic_irq_id));
1046}