lowRISC / lowRISC/opentitan

[dtgen] Add support for several PLICs

Open
#27,925 3 comments 0 reactions 1 assignee View on GitHub

@pamaury is already working on this.

Since Aug 15, 2025.

Dominant language
SystemVerilog
Stars
3.6k
Forks
1.1k
Avg merge
2d 22h
Merged PRs (30d)
141

Description

### Description

Currently `dtgen` assumes that there is only one PLIC. In order to support several PLICs, the code needs to updated. Here is a proposal to do so:
- change the type `dt_plic_irq_id_t`: instead of being alias to `top___irq_id_t`, it should be a structure:
```c
typedef struct dt_plic_irq_id {
dt_instance_id_t plic; // Instance of the PLIC.
union {
top___irq_id_t _id;
...
top___irq_id_t _id;
uint32_t value;
} id;
} dt_plic_irq_id_t;
```
- rv_plic DIF functions should gain a DT version that manipulates `dt_plic_irq_id_t` directly. For example, the following common code becomes incorrect:
```c
rv_plic_testutils_irq_range_enable(
&plic, kPlicTarget,
dt_aon_timer_irq_to_plic_id(kAonTimerDt, kDtAonTimerIrqWkupTimerExpired),
dt_aon_timer_irq_to_plic_id(kAonTimerDt, kDtAonTimerIrqWdogTimerBark));
```
since `dt_aon_timer_irq_to_plic_id` returns a `dt_plic_irq_id_t` and not a `top___irq_id_t`. Fortunately, it's just a matter to create a function with the same name and suffix `_dt`. The compiler will catch all errors automatically because a struct is not convertible to a scalar. The fix is trivial and just needs to replicated in all files (that's a nontrivial amount but the fix is trivial)

An important feature of this design is that `dt_plic_irq_id_t` carries the instance of the PLIC. Thefore if a user tries to call `rv_plic_irq_enable()` on a PLIC which does not correspond to the given `dt_plic_irq_id_t`, this can be detected easily by comparing the PLIC instance IDs, and return an error. Therefore there is no risk of PLIC confusion for code ported to the DT.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.