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_csrng_isr(
153 plic_isr_ctx_t plic_ctx, csrng_isr_ctx_t csrng_ctx,
154 top_earlgrey_plic_peripheral_t *peripheral_serviced,
155 dif_csrng_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_csrng_irq_t irq =
168 (dif_csrng_irq_t)(plic_irq_id - csrng_ctx.plic_csrng_start_irq_id);
169 *irq_serviced = irq;
170
171 // Check if it is supposed to be the only IRQ fired.
172 if (csrng_ctx.is_only_irq) {
174 CHECK_DIF_OK(dif_csrng_irq_get_state(csrng_ctx.csrng, &snapshot));
175 CHECK(snapshot == (dif_csrng_irq_state_snapshot_t)(1 << irq),
176 "Only csrng IRQ %d expected to fire. Actual IRQ state = %x", irq,
177 snapshot);
178 }
179
180 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
181 dif_irq_type_t type;
182 CHECK_DIF_OK(dif_csrng_irq_get_type(csrng_ctx.csrng, irq, &type));
183 if (type == kDifIrqTypeEvent) {
184 CHECK_DIF_OK(dif_csrng_irq_acknowledge(csrng_ctx.csrng, irq));
185 }
186
187 // Complete the IRQ at the PLIC.
188 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
189 plic_irq_id));
190}
191
192void isr_testutils_edn_isr(plic_isr_ctx_t plic_ctx, edn_isr_ctx_t edn_ctx,
193 top_earlgrey_plic_peripheral_t *peripheral_serviced,
194 dif_edn_irq_t *irq_serviced) {
195
196 // Claim the IRQ at the PLIC.
197 dif_rv_plic_irq_id_t plic_irq_id;
198 CHECK_DIF_OK(
199 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
200
201 // Get the peripheral the IRQ belongs to.
202 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
203 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
204
205 // Get the IRQ that was fired from the PLIC IRQ ID.
206 dif_edn_irq_t irq =
207 (dif_edn_irq_t)(plic_irq_id - edn_ctx.plic_edn_start_irq_id);
208 *irq_serviced = irq;
209
210 // Check if it is supposed to be the only IRQ fired.
211 if (edn_ctx.is_only_irq) {
213 CHECK_DIF_OK(dif_edn_irq_get_state(edn_ctx.edn, &snapshot));
214 CHECK(snapshot == (dif_edn_irq_state_snapshot_t)(1 << irq),
215 "Only edn IRQ %d expected to fire. Actual IRQ state = %x", irq,
216 snapshot);
217 }
218
219 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
220 dif_irq_type_t type;
221 CHECK_DIF_OK(dif_edn_irq_get_type(edn_ctx.edn, irq, &type));
222 if (type == kDifIrqTypeEvent) {
223 CHECK_DIF_OK(dif_edn_irq_acknowledge(edn_ctx.edn, irq));
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_entropy_src_isr(
232 plic_isr_ctx_t plic_ctx, entropy_src_isr_ctx_t entropy_src_ctx,
233 top_earlgrey_plic_peripheral_t *peripheral_serviced,
234 dif_entropy_src_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_earlgrey_plic_peripheral_t)
243 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
244
245 // Get the IRQ that was fired from the PLIC IRQ ID.
246 dif_entropy_src_irq_t irq =
247 (dif_entropy_src_irq_t)(plic_irq_id -
248 entropy_src_ctx.plic_entropy_src_start_irq_id);
249 *irq_serviced = irq;
250
251 // Check if it is supposed to be the only IRQ fired.
252 if (entropy_src_ctx.is_only_irq) {
254 CHECK_DIF_OK(
255 dif_entropy_src_irq_get_state(entropy_src_ctx.entropy_src, &snapshot));
256 CHECK(snapshot == (dif_entropy_src_irq_state_snapshot_t)(1 << irq),
257 "Only entropy_src IRQ %d expected to fire. Actual IRQ state = %x",
258 irq, snapshot);
259 }
260
261 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
262 dif_irq_type_t type;
263 CHECK_DIF_OK(
264 dif_entropy_src_irq_get_type(entropy_src_ctx.entropy_src, irq, &type));
265 if (type == kDifIrqTypeEvent) {
266 CHECK_DIF_OK(
267 dif_entropy_src_irq_acknowledge(entropy_src_ctx.entropy_src, irq));
268 }
269
270 // Complete the IRQ at the PLIC.
271 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
272 plic_irq_id));
273}
274
275void isr_testutils_gpio_isr(plic_isr_ctx_t plic_ctx, gpio_isr_ctx_t gpio_ctx,
276 top_earlgrey_plic_peripheral_t *peripheral_serviced,
277 dif_gpio_irq_t *irq_serviced) {
278
279 // Claim the IRQ at the PLIC.
280 dif_rv_plic_irq_id_t plic_irq_id;
281 CHECK_DIF_OK(
282 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
283
284 // Get the peripheral the IRQ belongs to.
285 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
286 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
287
288 // Get the IRQ that was fired from the PLIC IRQ ID.
289 dif_gpio_irq_t irq =
290 (dif_gpio_irq_t)(plic_irq_id - gpio_ctx.plic_gpio_start_irq_id);
291 *irq_serviced = irq;
292
293 // Check if it is supposed to be the only IRQ fired.
294 if (gpio_ctx.is_only_irq) {
296 CHECK_DIF_OK(dif_gpio_irq_get_state(gpio_ctx.gpio, &snapshot));
297 CHECK(snapshot == (dif_gpio_irq_state_snapshot_t)(1 << irq),
298 "Only gpio IRQ %d expected to fire. Actual IRQ state = %x", irq,
299 snapshot);
300 }
301
302 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
303 dif_irq_type_t type;
304 CHECK_DIF_OK(dif_gpio_irq_get_type(gpio_ctx.gpio, irq, &type));
305 if (type == kDifIrqTypeEvent) {
306 CHECK_DIF_OK(dif_gpio_irq_acknowledge(gpio_ctx.gpio, irq));
307 }
308
309 // Complete the IRQ at the PLIC.
310 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
311 plic_irq_id));
312}
313
314void isr_testutils_hmac_isr(plic_isr_ctx_t plic_ctx, hmac_isr_ctx_t hmac_ctx,
315 bool mute_status_irq,
316 top_earlgrey_plic_peripheral_t *peripheral_serviced,
317 dif_hmac_irq_t *irq_serviced) {
318
319 // Claim the IRQ at the PLIC.
320 dif_rv_plic_irq_id_t plic_irq_id;
321 CHECK_DIF_OK(
322 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
323
324 // Get the peripheral the IRQ belongs to.
325 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
326 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
327
328 // Get the IRQ that was fired from the PLIC IRQ ID.
329 dif_hmac_irq_t irq =
330 (dif_hmac_irq_t)(plic_irq_id - hmac_ctx.plic_hmac_start_irq_id);
331 *irq_serviced = irq;
332
333 // Check if it is supposed to be the only IRQ fired.
334 if (hmac_ctx.is_only_irq) {
336 CHECK_DIF_OK(dif_hmac_irq_get_state(hmac_ctx.hmac, &snapshot));
337 CHECK(snapshot == (dif_hmac_irq_state_snapshot_t)(1 << irq),
338 "Only hmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
339 snapshot);
340 }
341
342 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
343 dif_irq_type_t type;
344 CHECK_DIF_OK(dif_hmac_irq_get_type(hmac_ctx.hmac, irq, &type));
345 if (type == kDifIrqTypeEvent) {
346 CHECK_DIF_OK(dif_hmac_irq_acknowledge(hmac_ctx.hmac, irq));
347 } else if (mute_status_irq) {
348 CHECK_DIF_OK(
349 dif_hmac_irq_set_enabled(hmac_ctx.hmac, irq, kDifToggleDisabled));
350 }
351
352 // Complete the IRQ at the PLIC.
353 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
354 plic_irq_id));
355}
356
357void isr_testutils_i2c_isr(plic_isr_ctx_t plic_ctx, i2c_isr_ctx_t i2c_ctx,
358 bool mute_status_irq,
359 top_earlgrey_plic_peripheral_t *peripheral_serviced,
360 dif_i2c_irq_t *irq_serviced) {
361
362 // Claim the IRQ at the PLIC.
363 dif_rv_plic_irq_id_t plic_irq_id;
364 CHECK_DIF_OK(
365 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
366
367 // Get the peripheral the IRQ belongs to.
368 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
369 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
370
371 // Get the IRQ that was fired from the PLIC IRQ ID.
372 dif_i2c_irq_t irq =
373 (dif_i2c_irq_t)(plic_irq_id - i2c_ctx.plic_i2c_start_irq_id);
374 *irq_serviced = irq;
375
376 // Check if it is supposed to be the only IRQ fired.
377 if (i2c_ctx.is_only_irq) {
379 CHECK_DIF_OK(dif_i2c_irq_get_state(i2c_ctx.i2c, &snapshot));
380 CHECK(snapshot == (dif_i2c_irq_state_snapshot_t)(1 << irq),
381 "Only i2c IRQ %d expected to fire. Actual IRQ state = %x", irq,
382 snapshot);
383 }
384
385 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
386 dif_irq_type_t type;
387 CHECK_DIF_OK(dif_i2c_irq_get_type(i2c_ctx.i2c, irq, &type));
388 if (type == kDifIrqTypeEvent) {
389 CHECK_DIF_OK(dif_i2c_irq_acknowledge(i2c_ctx.i2c, irq));
390 } else if (mute_status_irq) {
391 CHECK_DIF_OK(dif_i2c_irq_set_enabled(i2c_ctx.i2c, irq, kDifToggleDisabled));
392 }
393
394 // Complete the IRQ at the PLIC.
395 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
396 plic_irq_id));
397}
398
399void isr_testutils_keymgr_dpe_isr(
400 plic_isr_ctx_t plic_ctx, keymgr_dpe_isr_ctx_t keymgr_dpe_ctx,
401 top_earlgrey_plic_peripheral_t *peripheral_serviced,
402 dif_keymgr_dpe_irq_t *irq_serviced) {
403
404 // Claim the IRQ at the PLIC.
405 dif_rv_plic_irq_id_t plic_irq_id;
406 CHECK_DIF_OK(
407 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
408
409 // Get the peripheral the IRQ belongs to.
410 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
411 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
412
413 // Get the IRQ that was fired from the PLIC IRQ ID.
414 dif_keymgr_dpe_irq_t irq =
415 (dif_keymgr_dpe_irq_t)(plic_irq_id -
416 keymgr_dpe_ctx.plic_keymgr_dpe_start_irq_id);
417 *irq_serviced = irq;
418
419 // Check if it is supposed to be the only IRQ fired.
420 if (keymgr_dpe_ctx.is_only_irq) {
422 CHECK_DIF_OK(
423 dif_keymgr_dpe_irq_get_state(keymgr_dpe_ctx.keymgr_dpe, &snapshot));
424 CHECK(snapshot == (dif_keymgr_dpe_irq_state_snapshot_t)(1 << irq),
425 "Only keymgr_dpe IRQ %d expected to fire. Actual IRQ state = %x", irq,
426 snapshot);
427 }
428
429 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
430 dif_irq_type_t type;
431 CHECK_DIF_OK(
432 dif_keymgr_dpe_irq_get_type(keymgr_dpe_ctx.keymgr_dpe, irq, &type));
433 if (type == kDifIrqTypeEvent) {
434 CHECK_DIF_OK(
435 dif_keymgr_dpe_irq_acknowledge(keymgr_dpe_ctx.keymgr_dpe, irq));
436 }
437
438 // Complete the IRQ at the PLIC.
439 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
440 plic_irq_id));
441}
442
443void isr_testutils_kmac_isr(plic_isr_ctx_t plic_ctx, kmac_isr_ctx_t kmac_ctx,
444 bool mute_status_irq,
445 top_earlgrey_plic_peripheral_t *peripheral_serviced,
446 dif_kmac_irq_t *irq_serviced) {
447
448 // Claim the IRQ at the PLIC.
449 dif_rv_plic_irq_id_t plic_irq_id;
450 CHECK_DIF_OK(
451 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
452
453 // Get the peripheral the IRQ belongs to.
454 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
455 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
456
457 // Get the IRQ that was fired from the PLIC IRQ ID.
458 dif_kmac_irq_t irq =
459 (dif_kmac_irq_t)(plic_irq_id - kmac_ctx.plic_kmac_start_irq_id);
460 *irq_serviced = irq;
461
462 // Check if it is supposed to be the only IRQ fired.
463 if (kmac_ctx.is_only_irq) {
465 CHECK_DIF_OK(dif_kmac_irq_get_state(kmac_ctx.kmac, &snapshot));
466 CHECK(snapshot == (dif_kmac_irq_state_snapshot_t)(1 << irq),
467 "Only kmac IRQ %d expected to fire. Actual IRQ state = %x", irq,
468 snapshot);
469 }
470
471 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
472 dif_irq_type_t type;
473 CHECK_DIF_OK(dif_kmac_irq_get_type(kmac_ctx.kmac, irq, &type));
474 if (type == kDifIrqTypeEvent) {
475 CHECK_DIF_OK(dif_kmac_irq_acknowledge(kmac_ctx.kmac, irq));
476 } else if (mute_status_irq) {
477 CHECK_DIF_OK(
478 dif_kmac_irq_set_enabled(kmac_ctx.kmac, 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_otbn_isr(plic_isr_ctx_t plic_ctx, otbn_isr_ctx_t otbn_ctx,
487 top_earlgrey_plic_peripheral_t *peripheral_serviced,
488 dif_otbn_irq_t *irq_serviced) {
489
490 // Claim the IRQ at the PLIC.
491 dif_rv_plic_irq_id_t plic_irq_id;
492 CHECK_DIF_OK(
493 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
494
495 // Get the peripheral the IRQ belongs to.
496 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
497 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
498
499 // Get the IRQ that was fired from the PLIC IRQ ID.
500 dif_otbn_irq_t irq =
501 (dif_otbn_irq_t)(plic_irq_id - otbn_ctx.plic_otbn_start_irq_id);
502 *irq_serviced = irq;
503
504 // Check if it is supposed to be the only IRQ fired.
505 if (otbn_ctx.is_only_irq) {
507 CHECK_DIF_OK(dif_otbn_irq_get_state(otbn_ctx.otbn, &snapshot));
508 CHECK(snapshot == (dif_otbn_irq_state_snapshot_t)(1 << irq),
509 "Only otbn IRQ %d expected to fire. Actual IRQ state = %x", irq,
510 snapshot);
511 }
512
513 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
514 dif_irq_type_t type;
515 CHECK_DIF_OK(dif_otbn_irq_get_type(otbn_ctx.otbn, irq, &type));
516 if (type == kDifIrqTypeEvent) {
517 CHECK_DIF_OK(dif_otbn_irq_acknowledge(otbn_ctx.otbn, irq));
518 }
519
520 // Complete the IRQ at the PLIC.
521 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
522 plic_irq_id));
523}
524
525void isr_testutils_otp_ctrl_isr(
526 plic_isr_ctx_t plic_ctx, otp_ctrl_isr_ctx_t otp_ctrl_ctx,
527 top_earlgrey_plic_peripheral_t *peripheral_serviced,
528 dif_otp_ctrl_irq_t *irq_serviced) {
529
530 // Claim the IRQ at the PLIC.
531 dif_rv_plic_irq_id_t plic_irq_id;
532 CHECK_DIF_OK(
533 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
534
535 // Get the peripheral the IRQ belongs to.
536 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
537 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
538
539 // Get the IRQ that was fired from the PLIC IRQ ID.
540 dif_otp_ctrl_irq_t irq =
541 (dif_otp_ctrl_irq_t)(plic_irq_id -
542 otp_ctrl_ctx.plic_otp_ctrl_start_irq_id);
543 *irq_serviced = irq;
544
545 // Check if it is supposed to be the only IRQ fired.
546 if (otp_ctrl_ctx.is_only_irq) {
548 CHECK_DIF_OK(dif_otp_ctrl_irq_get_state(otp_ctrl_ctx.otp_ctrl, &snapshot));
549 CHECK(snapshot == (dif_otp_ctrl_irq_state_snapshot_t)(1 << irq),
550 "Only otp_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
551 snapshot);
552 }
553
554 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
555 dif_irq_type_t type;
556 CHECK_DIF_OK(dif_otp_ctrl_irq_get_type(otp_ctrl_ctx.otp_ctrl, irq, &type));
557 if (type == kDifIrqTypeEvent) {
558 CHECK_DIF_OK(dif_otp_ctrl_irq_acknowledge(otp_ctrl_ctx.otp_ctrl, irq));
559 }
560
561 // Complete the IRQ at the PLIC.
562 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
563 plic_irq_id));
564}
565
566void isr_testutils_pwrmgr_isr(
567 plic_isr_ctx_t plic_ctx, pwrmgr_isr_ctx_t pwrmgr_ctx,
568 top_earlgrey_plic_peripheral_t *peripheral_serviced,
569 dif_pwrmgr_irq_t *irq_serviced) {
570
571 // Claim the IRQ at the PLIC.
572 dif_rv_plic_irq_id_t plic_irq_id;
573 CHECK_DIF_OK(
574 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
575
576 // Get the peripheral the IRQ belongs to.
577 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
578 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
579
580 // Get the IRQ that was fired from the PLIC IRQ ID.
581 dif_pwrmgr_irq_t irq =
582 (dif_pwrmgr_irq_t)(plic_irq_id - pwrmgr_ctx.plic_pwrmgr_start_irq_id);
583 *irq_serviced = irq;
584
585 // Check if it is supposed to be the only IRQ fired.
586 if (pwrmgr_ctx.is_only_irq) {
588 CHECK_DIF_OK(dif_pwrmgr_irq_get_state(pwrmgr_ctx.pwrmgr, &snapshot));
589 CHECK(snapshot == (dif_pwrmgr_irq_state_snapshot_t)(1 << irq),
590 "Only pwrmgr IRQ %d expected to fire. Actual IRQ state = %x", irq,
591 snapshot);
592 }
593
594 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
595 dif_irq_type_t type;
596 CHECK_DIF_OK(dif_pwrmgr_irq_get_type(pwrmgr_ctx.pwrmgr, irq, &type));
597 if (type == kDifIrqTypeEvent) {
598 CHECK_DIF_OK(dif_pwrmgr_irq_acknowledge(pwrmgr_ctx.pwrmgr, irq));
599 }
600
601 // Complete the IRQ at the PLIC.
602 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
603 plic_irq_id));
604}
605
606void isr_testutils_rram_ctrl_isr(
607 plic_isr_ctx_t plic_ctx, rram_ctrl_isr_ctx_t rram_ctrl_ctx,
608 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
609 dif_rram_ctrl_irq_t *irq_serviced) {
610
611 // Claim the IRQ at the PLIC.
612 dif_rv_plic_irq_id_t plic_irq_id;
613 CHECK_DIF_OK(
614 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
615
616 // Get the peripheral the IRQ belongs to.
617 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
618 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
619
620 // Get the IRQ that was fired from the PLIC IRQ ID.
621 dif_rram_ctrl_irq_t irq =
622 (dif_rram_ctrl_irq_t)(plic_irq_id -
623 rram_ctrl_ctx.plic_rram_ctrl_start_irq_id);
624 *irq_serviced = irq;
625
626 // Check if it is supposed to be the only IRQ fired.
627 if (rram_ctrl_ctx.is_only_irq) {
629 CHECK_DIF_OK(
630 dif_rram_ctrl_irq_get_state(rram_ctrl_ctx.rram_ctrl, &snapshot));
631 CHECK(snapshot == (dif_rram_ctrl_irq_state_snapshot_t)(1 << irq),
632 "Only rram_ctrl IRQ %d expected to fire. Actual IRQ state = %x", irq,
633 snapshot);
634 }
635
636 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
637 dif_irq_type_t type;
638 CHECK_DIF_OK(dif_rram_ctrl_irq_get_type(rram_ctrl_ctx.rram_ctrl, irq, &type));
639 if (type == kDifIrqTypeEvent) {
640 CHECK_DIF_OK(dif_rram_ctrl_irq_acknowledge(rram_ctrl_ctx.rram_ctrl, irq));
641 } else if (mute_status_irq) {
642 CHECK_DIF_OK(dif_rram_ctrl_irq_set_enabled(rram_ctrl_ctx.rram_ctrl, irq,
644 }
645
646 // Complete the IRQ at the PLIC.
647 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
648 plic_irq_id));
649}
650
651void isr_testutils_rv_timer_isr(
652 plic_isr_ctx_t plic_ctx, rv_timer_isr_ctx_t rv_timer_ctx,
653 top_earlgrey_plic_peripheral_t *peripheral_serviced,
654 dif_rv_timer_irq_t *irq_serviced) {
655
656 // Claim the IRQ at the PLIC.
657 dif_rv_plic_irq_id_t plic_irq_id;
658 CHECK_DIF_OK(
659 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
660
661 // Get the peripheral the IRQ belongs to.
662 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
663 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
664
665 // Get the IRQ that was fired from the PLIC IRQ ID.
666 dif_rv_timer_irq_t irq =
667 (dif_rv_timer_irq_t)(plic_irq_id -
668 rv_timer_ctx.plic_rv_timer_start_irq_id);
669 *irq_serviced = irq;
670
671 // Check if it is supposed to be the only IRQ fired.
672 if (rv_timer_ctx.is_only_irq) {
674 CHECK_DIF_OK(dif_rv_timer_irq_get_state(rv_timer_ctx.rv_timer,
675 plic_ctx.hart_id, &snapshot));
676 CHECK(snapshot == (dif_rv_timer_irq_state_snapshot_t)(1 << irq),
677 "Only rv_timer 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_rv_timer_irq_get_type(rv_timer_ctx.rv_timer, irq, &type));
684 if (type == kDifIrqTypeEvent) {
685 CHECK_DIF_OK(dif_rv_timer_irq_acknowledge(rv_timer_ctx.rv_timer, 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_sensor_ctrl_isr(
694 plic_isr_ctx_t plic_ctx, sensor_ctrl_isr_ctx_t sensor_ctrl_ctx,
695 top_earlgrey_plic_peripheral_t *peripheral_serviced,
696 dif_sensor_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_sensor_ctrl_irq_t irq =
709 (dif_sensor_ctrl_irq_t)(plic_irq_id -
710 sensor_ctrl_ctx.plic_sensor_ctrl_start_irq_id);
711 *irq_serviced = irq;
712
713 // Check if it is supposed to be the only IRQ fired.
714 if (sensor_ctrl_ctx.is_only_irq) {
716 CHECK_DIF_OK(
717 dif_sensor_ctrl_irq_get_state(sensor_ctrl_ctx.sensor_ctrl, &snapshot));
718 CHECK(snapshot == (dif_sensor_ctrl_irq_state_snapshot_t)(1 << irq),
719 "Only sensor_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
720 irq, 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(
726 dif_sensor_ctrl_irq_get_type(sensor_ctrl_ctx.sensor_ctrl, irq, &type));
727 if (type == kDifIrqTypeEvent) {
728 CHECK_DIF_OK(
729 dif_sensor_ctrl_irq_acknowledge(sensor_ctrl_ctx.sensor_ctrl, irq));
730 }
731
732 // Complete the IRQ at the PLIC.
733 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
734 plic_irq_id));
735}
736
737void isr_testutils_spi_device_isr(
738 plic_isr_ctx_t plic_ctx, spi_device_isr_ctx_t spi_device_ctx,
739 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
740 dif_spi_device_irq_t *irq_serviced) {
741
742 // Claim the IRQ at the PLIC.
743 dif_rv_plic_irq_id_t plic_irq_id;
744 CHECK_DIF_OK(
745 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
746
747 // Get the peripheral the IRQ belongs to.
748 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
749 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
750
751 // Get the IRQ that was fired from the PLIC IRQ ID.
752 dif_spi_device_irq_t irq =
753 (dif_spi_device_irq_t)(plic_irq_id -
754 spi_device_ctx.plic_spi_device_start_irq_id);
755 *irq_serviced = irq;
756
757 // Check if it is supposed to be the only IRQ fired.
758 if (spi_device_ctx.is_only_irq) {
760 CHECK_DIF_OK(
761 dif_spi_device_irq_get_state(spi_device_ctx.spi_device, &snapshot));
762 CHECK(snapshot == (dif_spi_device_irq_state_snapshot_t)(1 << irq),
763 "Only spi_device IRQ %d expected to fire. Actual IRQ state = %x", irq,
764 snapshot);
765 }
766
767 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
768 dif_irq_type_t type;
769 CHECK_DIF_OK(
770 dif_spi_device_irq_get_type(spi_device_ctx.spi_device, irq, &type));
771 if (type == kDifIrqTypeEvent) {
772 CHECK_DIF_OK(
773 dif_spi_device_irq_acknowledge(spi_device_ctx.spi_device, irq));
774 } else if (mute_status_irq) {
775 CHECK_DIF_OK(dif_spi_device_irq_set_enabled(spi_device_ctx.spi_device, irq,
777 }
778
779 // Complete the IRQ at the PLIC.
780 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
781 plic_irq_id));
782}
783
784void isr_testutils_spi_host_isr(
785 plic_isr_ctx_t plic_ctx, spi_host_isr_ctx_t spi_host_ctx,
786 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
787 dif_spi_host_irq_t *irq_serviced) {
788
789 // Claim the IRQ at the PLIC.
790 dif_rv_plic_irq_id_t plic_irq_id;
791 CHECK_DIF_OK(
792 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
793
794 // Get the peripheral the IRQ belongs to.
795 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
796 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
797
798 // Get the IRQ that was fired from the PLIC IRQ ID.
799 dif_spi_host_irq_t irq =
800 (dif_spi_host_irq_t)(plic_irq_id -
801 spi_host_ctx.plic_spi_host_start_irq_id);
802 *irq_serviced = irq;
803
804 // Check if it is supposed to be the only IRQ fired.
805 if (spi_host_ctx.is_only_irq) {
807 CHECK_DIF_OK(dif_spi_host_irq_get_state(spi_host_ctx.spi_host, &snapshot));
808 CHECK(snapshot == (dif_spi_host_irq_state_snapshot_t)(1 << irq),
809 "Only spi_host IRQ %d expected to fire. Actual IRQ state = %x", irq,
810 snapshot);
811 }
812
813 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
814 dif_irq_type_t type;
815 CHECK_DIF_OK(dif_spi_host_irq_get_type(spi_host_ctx.spi_host, irq, &type));
816 if (type == kDifIrqTypeEvent) {
817 CHECK_DIF_OK(dif_spi_host_irq_acknowledge(spi_host_ctx.spi_host, irq));
818 } else if (mute_status_irq) {
819 CHECK_DIF_OK(dif_spi_host_irq_set_enabled(spi_host_ctx.spi_host, irq,
821 }
822
823 // Complete the IRQ at the PLIC.
824 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
825 plic_irq_id));
826}
827
828void isr_testutils_sysrst_ctrl_isr(
829 plic_isr_ctx_t plic_ctx, sysrst_ctrl_isr_ctx_t sysrst_ctrl_ctx,
830 bool mute_status_irq, top_earlgrey_plic_peripheral_t *peripheral_serviced,
831 dif_sysrst_ctrl_irq_t *irq_serviced) {
832
833 // Claim the IRQ at the PLIC.
834 dif_rv_plic_irq_id_t plic_irq_id;
835 CHECK_DIF_OK(
836 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
837
838 // Get the peripheral the IRQ belongs to.
839 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
840 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
841
842 // Get the IRQ that was fired from the PLIC IRQ ID.
843 dif_sysrst_ctrl_irq_t irq =
844 (dif_sysrst_ctrl_irq_t)(plic_irq_id -
845 sysrst_ctrl_ctx.plic_sysrst_ctrl_start_irq_id);
846 *irq_serviced = irq;
847
848 // Check if it is supposed to be the only IRQ fired.
849 if (sysrst_ctrl_ctx.is_only_irq) {
851 CHECK_DIF_OK(
852 dif_sysrst_ctrl_irq_get_state(sysrst_ctrl_ctx.sysrst_ctrl, &snapshot));
853 CHECK(snapshot == (dif_sysrst_ctrl_irq_state_snapshot_t)(1 << irq),
854 "Only sysrst_ctrl IRQ %d expected to fire. Actual IRQ state = %x",
855 irq, snapshot);
856 }
857
858 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
859 dif_irq_type_t type;
860 CHECK_DIF_OK(
861 dif_sysrst_ctrl_irq_get_type(sysrst_ctrl_ctx.sysrst_ctrl, irq, &type));
862 if (type == kDifIrqTypeEvent) {
863 CHECK_DIF_OK(
864 dif_sysrst_ctrl_irq_acknowledge(sysrst_ctrl_ctx.sysrst_ctrl, irq));
865 } else if (mute_status_irq) {
866 CHECK_DIF_OK(dif_sysrst_ctrl_irq_set_enabled(sysrst_ctrl_ctx.sysrst_ctrl,
867 irq, kDifToggleDisabled));
868 }
869
870 // Complete the IRQ at the PLIC.
871 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
872 plic_irq_id));
873}
874
875void isr_testutils_uart_isr(plic_isr_ctx_t plic_ctx, uart_isr_ctx_t uart_ctx,
876 bool mute_status_irq,
877 top_earlgrey_plic_peripheral_t *peripheral_serviced,
878 dif_uart_irq_t *irq_serviced) {
879
880 // Claim the IRQ at the PLIC.
881 dif_rv_plic_irq_id_t plic_irq_id;
882 CHECK_DIF_OK(
883 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
884
885 // Get the peripheral the IRQ belongs to.
886 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
887 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
888
889 // Get the IRQ that was fired from the PLIC IRQ ID.
890 dif_uart_irq_t irq =
891 (dif_uart_irq_t)(plic_irq_id - uart_ctx.plic_uart_start_irq_id);
892 *irq_serviced = irq;
893
894 // Check if it is supposed to be the only IRQ fired.
895 if (uart_ctx.is_only_irq) {
897 CHECK_DIF_OK(dif_uart_irq_get_state(uart_ctx.uart, &snapshot));
898 CHECK(snapshot == (dif_uart_irq_state_snapshot_t)(1 << irq),
899 "Only uart IRQ %d expected to fire. Actual IRQ state = %x", irq,
900 snapshot);
901 }
902
903 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
904 dif_irq_type_t type;
905 CHECK_DIF_OK(dif_uart_irq_get_type(uart_ctx.uart, irq, &type));
906 if (type == kDifIrqTypeEvent) {
907 CHECK_DIF_OK(dif_uart_irq_acknowledge(uart_ctx.uart, irq));
908 } else if (mute_status_irq) {
909 CHECK_DIF_OK(
910 dif_uart_irq_set_enabled(uart_ctx.uart, irq, kDifToggleDisabled));
911 }
912
913 // Complete the IRQ at the PLIC.
914 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
915 plic_irq_id));
916}
917
918void isr_testutils_usbdev_isr(
919 plic_isr_ctx_t plic_ctx, usbdev_isr_ctx_t usbdev_ctx, bool mute_status_irq,
920 top_earlgrey_plic_peripheral_t *peripheral_serviced,
921 dif_usbdev_irq_t *irq_serviced) {
922
923 // Claim the IRQ at the PLIC.
924 dif_rv_plic_irq_id_t plic_irq_id;
925 CHECK_DIF_OK(
926 dif_rv_plic_irq_claim(plic_ctx.rv_plic, plic_ctx.hart_id, &plic_irq_id));
927
928 // Get the peripheral the IRQ belongs to.
929 *peripheral_serviced = (top_earlgrey_plic_peripheral_t)
930 top_earlgrey_plic_interrupt_for_peripheral[plic_irq_id];
931
932 // Get the IRQ that was fired from the PLIC IRQ ID.
933 dif_usbdev_irq_t irq =
934 (dif_usbdev_irq_t)(plic_irq_id - usbdev_ctx.plic_usbdev_start_irq_id);
935 *irq_serviced = irq;
936
937 // Check if it is supposed to be the only IRQ fired.
938 if (usbdev_ctx.is_only_irq) {
940 CHECK_DIF_OK(dif_usbdev_irq_get_state(usbdev_ctx.usbdev, &snapshot));
941 CHECK(snapshot == (dif_usbdev_irq_state_snapshot_t)(1 << irq),
942 "Only usbdev IRQ %d expected to fire. Actual IRQ state = %x", irq,
943 snapshot);
944 }
945
946 // Acknowledge the IRQ at the peripheral if IRQ is of the event type.
947 dif_irq_type_t type;
948 CHECK_DIF_OK(dif_usbdev_irq_get_type(usbdev_ctx.usbdev, irq, &type));
949 if (type == kDifIrqTypeEvent) {
950 CHECK_DIF_OK(dif_usbdev_irq_acknowledge(usbdev_ctx.usbdev, irq));
951 } else if (mute_status_irq) {
952 CHECK_DIF_OK(
953 dif_usbdev_irq_set_enabled(usbdev_ctx.usbdev, irq, kDifToggleDisabled));
954 }
955
956 // Complete the IRQ at the PLIC.
957 CHECK_DIF_OK(dif_rv_plic_irq_complete(plic_ctx.rv_plic, plic_ctx.hart_id,
958 plic_irq_id));
959}