* [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
@ 2026-12-03 16:56 Anirudh Srinivasan
2026-12-04 11:10 ` E Shattow
0 siblings, 1 reply; 6+ messages in thread
From: Anirudh Srinivasan @ 2026-12-03 16:56 UTC (permalink / raw)
To: Yao Zi, u-boot
Cc: Tim Ouyang, Leo Liang, Tom Rini, E Shattow, Troy Mitchell,
Anirudh Srinivasan
When U-Boot is running in S mode, the DT passed to the next S mode stage
can either be the bundled in DT U-Boot and the previous M mode stage
use, or be loaded by U-Boot from some boot media. In the former case,
the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
nodes on an AIA system (for example, OpenSBI does this fixup). These
controllers are to be managed by M-mode software, so this is done to
prevent S mode software from trying to probe them.
This fixup doesn't happen in the latter case because U-Boot loads a
fresh DT from boot media. Add a fdt fixup to do this, marking these
nodes as reserved. This gets rid of prints like this during linux boots.
[ 0.000000] riscv-imsic: interrupt-controller@a0000000: no parent irqs available
[ 0.000000] riscv-imsic: interrupt-controller@a0000000: failed to setup state (error -22)
[ 0.000000] OF: of_irq_init: Failed to init /soc/interrupt-controller@a0000000 ((____ptrval____)), parent (____ptrval____)
[ 10.727605] platform cc000000.interrupt-controller: deferred probe pending: platform: supplier a0000000.interrupt-controller not ready
Reviewed-by: E Shattow <e@freeshell.de>
Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
---
Changes in v4:
- Mark nodes as reserved instead of disabled
- Added blank lines for readability
- Check if APLIC/IMSIC nodes are enabled before reserving them
- Reorder node disabling blocks so that APLIC-only config is disabled at the end
- Checkpath warning about fdtdec_get_is_enabled() can be ignored as we aren't modifying
the live DT that u-boot is using
- Link to v3: https://patch.msgid.link/20261119-mimsic_maplic_fixup-v3-1-e028e28fb958@oss.tenstorrent.com
Changes in v3:
- Reword commit title to say M-APLIC/M-IMSIC and drop references to M Mode to avoid any confusion
- Link to v2: https://patch.msgid.link/20261119-mimsic_maplic_fixup-v2-1-e29e04bf1b76@oss.tenstorrent.com
Changes in v2:
- Rename riscv_aia_mmode_aplic_imsic_fixup to riscv_aia_mimsic_maplic_fixup
- Drop most references to OpenSBI/Linux in commit message and just use M-mode/s-mode software
- Link to v1: https://patch.msgid.link/20261118-mimsic_maplic_fixup-v1-1-52dea8f39779@oss.tenstorrent.com
---
arch/riscv/lib/fdt_fixup.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c
index 6dfd1a2d5b8..09b6e122cb2 100644
--- a/arch/riscv/lib/fdt_fixup.c
+++ b/arch/riscv/lib/fdt_fixup.c
@@ -117,6 +117,93 @@ int riscv_board_reserved_mem_fixup(void *fdt)
return 0;
}
+/**
+ * riscv_node_handles_mmode_external_interrupts() - Check if interrupt controller handles M-mode
+ * external interrupts
+ * @fdt: Pointer to the device tree
+ * @offset: Offset of node in DT to check
+ *
+ * Return: true if controller handles M-mode external interrupts IRQ_M_EXT (11), else false
+ */
+static bool riscv_node_handles_mmode_external_interrupts(void *fdt, int offset)
+{
+ int i, len;
+ const fdt32_t *interrupts_extended = fdt_getprop(fdt, offset, "interrupts-extended", &len);
+
+ /*
+ * Each entry is <phandle irq>. The phandle points to a riscv,cpu-intc
+ * node, whose DT binding sets #interrupt-cells = <1>, so each entry is
+ * 2 cells.
+ */
+ if (!interrupts_extended || !len || len % (2 * sizeof(u32)))
+ return false;
+
+ for (i = 1; i < len / sizeof(u32); i += 2) {
+ if (fdt32_to_cpu(interrupts_extended[i]) == IRQ_M_EXT)
+ return true;
+ }
+
+ return false;
+}
+
+/**
+ * riscv_aia_mimsic_maplic_fixup() - Mark M-APLIC and M-IMSIC nodes in DT as reserved
+ * @fdt: Pointer to the device tree in which nodes are to be fixed up
+ *
+ * On RISC-V AIA systems, M-mode software manages the M-APLIC and M-IMSIC.
+ * If S-mode U-Boot loads a device tree from boot media, the DT nodes for these
+ * could still be enabled, so fixup the DT to mark these nodes as reserved before passing
+ * it to the next S-mode stage.
+ *
+ * Return: 0 on success or error otherwise.
+ */
+static int riscv_aia_mimsic_maplic_fixup(void *fdt)
+{
+ int offset, err;
+
+ /* Mark M-IMSIC in APLIC-IMSIC configuration as reserved */
+ fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,imsics") {
+ if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
+ if (fdtdec_get_is_enabled(fdt, offset)) {
+ err = fdt_setprop_string(fdt, offset, "status", "reserved");
+ if (err < 0)
+ return err;
+ }
+ }
+ }
+
+ /* Mark M-APLIC in APLIC-IMSIC configuration as reserved */
+ fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
+ int len, imsic_offset;
+ const fdt32_t *msi_parent = fdt_getprop(fdt, offset, "msi-parent", &len);
+
+ if (msi_parent && len >= sizeof(fdt32_t)) {
+ imsic_offset = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*msi_parent));
+ if (imsic_offset >= 0 &&
+ riscv_node_handles_mmode_external_interrupts(fdt, imsic_offset)) {
+ if (fdtdec_get_is_enabled(fdt, offset)) {
+ err = fdt_setprop_string(fdt, offset, "status", "reserved");
+ if (err < 0)
+ return err;
+ }
+ }
+ }
+ }
+
+ /* Mark M-APLIC in APLIC only configuration as reserved */
+ fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
+ if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
+ if (fdtdec_get_is_enabled(fdt, offset)) {
+ err = fdt_setprop_string(fdt, offset, "status", "reserved");
+ if (err < 0)
+ return err;
+ }
+ }
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_OF_BOARD_FIXUP
int board_fix_fdt(void *fdt)
{
@@ -165,5 +252,12 @@ int arch_fixup_fdt(void *blob)
if (err < 0)
return err;
+ /* Mark M-IMSIC and M-APLIC nodes as reserved when we're not in M-mode */
+ if (!CONFIG_IS_ENABLED(RISCV_MMODE)) {
+ err = riscv_aia_mimsic_maplic_fixup(blob);
+ if (err < 0)
+ return err;
+ }
+
return 0;
}
---
base-commit: 83b1ec64ede9998566e6a82b22848c20a33f4aff
change-id: 20261118-mimsic_maplic_fixup-051bd38d0985
Best regards,
--
Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
2026-12-03 16:56 [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode Anirudh Srinivasan
@ 2026-12-04 11:10 ` E Shattow
2026-12-04 14:25 ` Anirudh Srinivasan
0 siblings, 1 reply; 6+ messages in thread
From: E Shattow @ 2026-12-04 11:10 UTC (permalink / raw)
To: Anirudh Srinivasan, Yao Zi, u-boot
Cc: Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell
Hi Anirudh,
On 12/3/26 08:56, Anirudh Srinivasan wrote:
> When U-Boot is running in S mode, the DT passed to the next S mode stage
> can either be the bundled in DT U-Boot and the previous M mode stage
> use, or be loaded by U-Boot from some boot media. In the former case,
> the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
> nodes on an AIA system (for example, OpenSBI does this fixup). These
> controllers are to be managed by M-mode software, so this is done to
> prevent S mode software from trying to probe them.
>
The way it reads now (in my point of view) is as:
"M-IMSIC and M-APLIC controllers are to be managed by M-mode software,
and so enforce any M-mode M-IMSIC and M-APLIC nodes are effectively
status 'reserved' in S-mode U-Boot with a fixup to the received control
Fdt from preceding M-Mode software (e.g. OpenSBI). Enforce again this
same fixup when entering the next S-mode kernel to prevent S-mode
software from trying to probe them."
Is my reading of this an accurate description of the fixup after your
changes?
> This fixup doesn't happen in the latter case because U-Boot loads a
> fresh DT from boot media. Add a fdt fixup to do this, marking these
> nodes as reserved. This gets rid of prints like this during linux boots.
>
> [ 0.000000] riscv-imsic: interrupt-controller@a0000000: no parent irqs available
> [ 0.000000] riscv-imsic: interrupt-controller@a0000000: failed to setup state (error -22)
> [ 0.000000] OF: of_irq_init: Failed to init /soc/interrupt-controller@a0000000 ((____ptrval____)), parent (____ptrval____)
>
> [ 10.727605] platform cc000000.interrupt-controller: deferred probe pending: platform: supplier a0000000.interrupt-controller not ready
>
> Reviewed-by: E Shattow <e@freeshell.de>
> Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
> ---
> Changes in v4:
> - Mark nodes as reserved instead of disabled
> - Added blank lines for readability
> - Check if APLIC/IMSIC nodes are enabled before reserving them
> - Reorder node disabling blocks so that APLIC-only config is disabled at the end
> - Checkpath warning about fdtdec_get_is_enabled() can be ignored as we aren't modifying
> the live DT that u-boot is using
> - Link to v3: https://patch.msgid.link/20261119-mimsic_maplic_fixup-v3-1-e028e28fb958@oss.tenstorrent.com
>
> Changes in v3:
> - Reword commit title to say M-APLIC/M-IMSIC and drop references to M Mode to avoid any confusion
> - Link to v2: https://patch.msgid.link/20261119-mimsic_maplic_fixup-v2-1-e29e04bf1b76@oss.tenstorrent.com
>
> Changes in v2:
> - Rename riscv_aia_mmode_aplic_imsic_fixup to riscv_aia_mimsic_maplic_fixup
> - Drop most references to OpenSBI/Linux in commit message and just use M-mode/s-mode software
> - Link to v1: https://patch.msgid.link/20261118-mimsic_maplic_fixup-v1-1-52dea8f39779@oss.tenstorrent.com
> ---
> arch/riscv/lib/fdt_fixup.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 94 insertions(+)
>
> diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c
> index 6dfd1a2d5b8..09b6e122cb2 100644
> --- a/arch/riscv/lib/fdt_fixup.c
> +++ b/arch/riscv/lib/fdt_fixup.c
> @@ -117,6 +117,93 @@ int riscv_board_reserved_mem_fixup(void *fdt)
> return 0;
> }
>
> +/**
> + * riscv_node_handles_mmode_external_interrupts() - Check if interrupt controller handles M-mode
> + * external interrupts
> + * @fdt: Pointer to the device tree
> + * @offset: Offset of node in DT to check
> + *
> + * Return: true if controller handles M-mode external interrupts IRQ_M_EXT (11), else false
> + */
> +static bool riscv_node_handles_mmode_external_interrupts(void *fdt, int offset)
> +{
> + int i, len;
> + const fdt32_t *interrupts_extended = fdt_getprop(fdt, offset, "interrupts-extended", &len);
> +
> + /*
> + * Each entry is <phandle irq>. The phandle points to a riscv,cpu-intc
> + * node, whose DT binding sets #interrupt-cells = <1>, so each entry is
> + * 2 cells.
> + */
> + if (!interrupts_extended || !len || len % (2 * sizeof(u32)))
> + return false;
> +
> + for (i = 1; i < len / sizeof(u32); i += 2) {
> + if (fdt32_to_cpu(interrupts_extended[i]) == IRQ_M_EXT)
> + return true;
> + }
> +
> + return false;
> +}
> +
> +/**
> + * riscv_aia_mimsic_maplic_fixup() - Mark M-APLIC and M-IMSIC nodes in DT as reserved
> + * @fdt: Pointer to the device tree in which nodes are to be fixed up
> + *
> + * On RISC-V AIA systems, M-mode software manages the M-APLIC and M-IMSIC.
> + * If S-mode U-Boot loads a device tree from boot media, the DT nodes for these
> + * could still be enabled, so fixup the DT to mark these nodes as reserved before passing
> + * it to the next S-mode stage.
> + *
> + * Return: 0 on success or error otherwise.
> + */
> +static int riscv_aia_mimsic_maplic_fixup(void *fdt)
> +{
> + int offset, err;
> +
> + /* Mark M-IMSIC in APLIC-IMSIC configuration as reserved */
> + fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,imsics") {
> + if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
> + if (fdtdec_get_is_enabled(fdt, offset)) {
> + err = fdt_setprop_string(fdt, offset, "status", "reserved");
> + if (err < 0)
> + return err;
> + }
> + }
> + }
> +
> + /* Mark M-APLIC in APLIC-IMSIC configuration as reserved */
> + fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
> + int len, imsic_offset;
> + const fdt32_t *msi_parent = fdt_getprop(fdt, offset, "msi-parent", &len);
> +
> + if (msi_parent && len >= sizeof(fdt32_t)) {
> + imsic_offset = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*msi_parent));
> + if (imsic_offset >= 0 &&
> + riscv_node_handles_mmode_external_interrupts(fdt, imsic_offset)) {
> + if (fdtdec_get_is_enabled(fdt, offset)) {
> + err = fdt_setprop_string(fdt, offset, "status", "reserved");
> + if (err < 0)
> + return err;
> + }
> + }
> + }
> + }
> +
> + /* Mark M-APLIC in APLIC only configuration as reserved */
> + fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
> + if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
> + if (fdtdec_get_is_enabled(fdt, offset)) {
> + err = fdt_setprop_string(fdt, offset, "status", "reserved");
> + if (err < 0)
> + return err;
> + }
> + }
> + }
> +
> + return 0;
> +}
> +
> #ifdef CONFIG_OF_BOARD_FIXUP
> int board_fix_fdt(void *fdt)
> {
> @@ -165,5 +252,12 @@ int arch_fixup_fdt(void *blob)
> if (err < 0)
> return err;
>
> + /* Mark M-IMSIC and M-APLIC nodes as reserved when we're not in M-mode */
> + if (!CONFIG_IS_ENABLED(RISCV_MMODE)) {
> + err = riscv_aia_mimsic_maplic_fixup(blob);
> + if (err < 0)
> + return err;
> + }
> +
> return 0;
> }
>
> ---
> base-commit: 83b1ec64ede9998566e6a82b22848c20a33f4aff
> change-id: 20261118-mimsic_maplic_fixup-051bd38d0985
>
> Best regards,
> --
> Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
>
-E
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
2026-12-04 11:10 ` E Shattow
@ 2026-12-04 14:25 ` Anirudh Srinivasan
2026-12-05 17:40 ` E Shattow
0 siblings, 1 reply; 6+ messages in thread
From: Anirudh Srinivasan @ 2026-12-04 14:25 UTC (permalink / raw)
To: E Shattow; +Cc: Yao Zi, u-boot, Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell
Hi E,
On Fri, Dec 4, 2026 at 5:10 AM E Shattow <e@freeshell.de> wrote:
>
> Hi Anirudh,
>
> On 12/3/26 08:56, Anirudh Srinivasan wrote:
> > When U-Boot is running in S mode, the DT passed to the next S mode stage
> > can either be the bundled in DT U-Boot and the previous M mode stage
> > use, or be loaded by U-Boot from some boot media. In the former case,
> > the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
> > nodes on an AIA system (for example, OpenSBI does this fixup). These
> > controllers are to be managed by M-mode software, so this is done to
> > prevent S mode software from trying to probe them.
> >
>
> The way it reads now (in my point of view) is as:
>
> "M-IMSIC and M-APLIC controllers are to be managed by M-mode software,
> and so enforce any M-mode M-IMSIC and M-APLIC nodes are effectively
> status 'reserved' in S-mode U-Boot with a fixup to the received control
This is what OpenSBI does.
> Fdt from preceding M-Mode software (e.g. OpenSBI). Enforce again this
> same fixup when entering the next S-mode kernel to prevent S-mode
> software from trying to probe them.
We're doing this again here cause we may possibly not use the DT
passed by OpenSBI and use a fresh DT from boot media.
Regards
Anirudh srinivasan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
2026-12-04 14:25 ` Anirudh Srinivasan
@ 2026-12-05 17:40 ` E Shattow
2026-12-05 21:54 ` Yao Zi
0 siblings, 1 reply; 6+ messages in thread
From: E Shattow @ 2026-12-05 17:40 UTC (permalink / raw)
To: Anirudh Srinivasan
Cc: Yao Zi, u-boot, Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell
Hi Anirudh,
Thanks for your patience :) replying my questions.
On 12/4/26 06:25, Anirudh Srinivasan wrote:
> Hi E,
>
> On Fri, Dec 4, 2026 at 5:10 AM E Shattow <e@freeshell.de> wrote:
>>
>> Hi Anirudh,
>>
>> On 12/3/26 08:56, Anirudh Srinivasan wrote:
>>> When U-Boot is running in S mode, the DT passed to the next S mode stage
>>> can either be the bundled in DT U-Boot and the previous M mode stage
>>> use, or be loaded by U-Boot from some boot media. In the former case,
>>> the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
>>> nodes on an AIA system (for example, OpenSBI does this fixup). These
>>> controllers are to be managed by M-mode software, so this is done to
>>> prevent S mode software from trying to probe them.
>>>
>>
>> The way it reads now (in my point of view) is as:
>>
>> "M-IMSIC and M-APLIC controllers are to be managed by M-mode software,
>> and so enforce any M-mode M-IMSIC and M-APLIC nodes are effectively
>> status 'reserved' in S-mode U-Boot with a fixup to the received control
>
> This is what OpenSBI does.
>
>> Fdt from preceding M-Mode software (e.g. OpenSBI). Enforce again this
>> same fixup when entering the next S-mode kernel to prevent S-mode
>> software from trying to probe them.
>
> We're doing this again here cause we may possibly not use the DT
> passed by OpenSBI and use a fresh DT from boot media.
>
> Regards
> Anirudh srinivasan
If we did not call out to an M-Mode SBI for the transition to S-Mode
then we would be managing these with a fix-up at M-Mode U-Boot SPL when
handing off to S-Mode U-Boot main app; I see the problem now, M-Mode
U-Boot SPL loads U-Boot main multi-fit image which begins code execution
with M-Mode SBI (e.g. OpenSBI or RustSBI, etc.) and we have no domain
over the Fdt control state as S-Mode U-Boot main app is loaded and
begins code execution because that is done by the 3rd party M-Mode SBI.
We again incur this problem exiting from S-Mode U-Boot Main app because
there are provisions for a user to again load data to the Fdt for
hand-off to the next boot phase.
I think it would be appropriate to log a warning (or even log "info"
level) that this particular M-mode <=> S-Mode fix-up consistency
enforcement is being done, as for example:
"Enforce reserved M-mode Fdt property status for handoff to S-Mode kernel:
* M-IMSIC okay => reserved
* M-APLIC okay => reserved"
or when the fix-up is activated but no nodes are changed then as:
"Enforce reserved M-mode Fdt property status for handoff to S-Mode
kernel: (n/a)"
Also for consistency we should enforce this twice, at both S-Mode U-Boot
main app initialization and at hand-off exiting S-Mode U-Boot main app.
I would like an explicit opt-in / opt-out strategy for the M-mode <=>
S-mode Fdt fix-up. A compile-time option is fine, here, and to make this
implicit for all RISC-V makes sense to me unless disabled explicitly
with "=n".... something so it appears in the .config but that it is a
sensible default so we don't require an opt-in. Presumably this is only
applicable to RISC-V platform?
I think this also would apply to U-Boot SPL, in terms of consistency
this fix-up should be instrumented so that you can require it to run
when exiting the SPL (but this would of course be disabled when there is
an SBI). This should not incur any code size overhead as a config option
it would simply not be compiled-in. This gives it an explicit
application at build time and be visible in the .config
With the above suggestions implemented, I think the commit message does
not require to mention "OpenSBI" at all. It simply becomes a matter of
informing the user and being a consistency enforcement SPL and Main app
boot phases.
-E
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
2026-12-05 17:40 ` E Shattow
@ 2026-12-05 21:54 ` Yao Zi
2026-12-05 22:34 ` E Shattow
0 siblings, 1 reply; 6+ messages in thread
From: Yao Zi @ 2026-12-05 21:54 UTC (permalink / raw)
To: E Shattow, Anirudh Srinivasan
Cc: Yao Zi, u-boot, Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell
On Sat, Dec 05, 2026 at 09:40:16AM -0800, E Shattow wrote:
> Hi Anirudh,
>
> Thanks for your patience :) replying my questions.
>
> On 12/4/26 06:25, Anirudh Srinivasan wrote:
> > Hi E,
> >
> > On Fri, Dec 4, 2026 at 5:10 AM E Shattow <e@freeshell.de> wrote:
> >>
> >> Hi Anirudh,
> >>
> >> On 12/3/26 08:56, Anirudh Srinivasan wrote:
> >>> When U-Boot is running in S mode, the DT passed to the next S mode stage
> >>> can either be the bundled in DT U-Boot and the previous M mode stage
> >>> use, or be loaded by U-Boot from some boot media. In the former case,
> >>> the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
> >>> nodes on an AIA system (for example, OpenSBI does this fixup). These
> >>> controllers are to be managed by M-mode software, so this is done to
> >>> prevent S mode software from trying to probe them.
> >>>
> >>
> >> The way it reads now (in my point of view) is as:
> >>
> >> "M-IMSIC and M-APLIC controllers are to be managed by M-mode software,
> >> and so enforce any M-mode M-IMSIC and M-APLIC nodes are effectively
> >> status 'reserved' in S-mode U-Boot with a fixup to the received control
> >
> > This is what OpenSBI does.
> >
> >> Fdt from preceding M-Mode software (e.g. OpenSBI). Enforce again this
> >> same fixup when entering the next S-mode kernel to prevent S-mode
> >> software from trying to probe them.
> >
> > We're doing this again here cause we may possibly not use the DT
> > passed by OpenSBI and use a fresh DT from boot media.
> >
> > Regards
> > Anirudh srinivasan
>
> If we did not call out to an M-Mode SBI for the transition to S-Mode
> then we would be managing these with a fix-up at M-Mode U-Boot SPL when
> handing off to S-Mode U-Boot main app; I see the problem now, M-Mode
> U-Boot SPL loads U-Boot main multi-fit image which begins code execution
> with M-Mode SBI (e.g. OpenSBI or RustSBI, etc.) and we have no domain
> over the Fdt control state as S-Mode U-Boot main app is loaded and
> begins code execution because that is done by the 3rd party M-Mode SBI.
> We again incur this problem exiting from S-Mode U-Boot Main app because
> there are provisions for a user to again load data to the Fdt for
> hand-off to the next boot phase.
>
> I think it would be appropriate to log a warning (or even log "info"
> level) that this particular M-mode <=> S-Mode fix-up consistency
> enforcement is being done, as for example:
>
> "Enforce reserved M-mode Fdt property status for handoff to S-Mode kernel:
> * M-IMSIC okay => reserved
> * M-APLIC okay => reserved"
>
> or when the fix-up is activated but no nodes are changed then as:
>
> "Enforce reserved M-mode Fdt property status for handoff to S-Mode
> kernel: (n/a)"
A message at warning or info level sounds too verbose. A message at
debug level would indeed help debugging when problems occur.
> Also for consistency we should enforce this twice, at both S-Mode U-Boot
> main app initialization and at hand-off exiting S-Mode U-Boot main app.
What do you mean by "enforce this twice"? Do you mean to fix up the FDT
both on entry of the U-Boot proper and on hand-off to the OS?
If my understanding is correct, this doesn't make sense. U-Boot makes no
use of interrupts, thus imsic/aplic means nothing to it.
> I would like an explicit opt-in / opt-out strategy for the M-mode <=>
> S-mode Fdt fix-up. A compile-time option is fine, here, and to make this
> implicit for all RISC-V makes sense to me unless disabled explicitly
> with "=n".... something so it appears in the .config but that it is a
> sensible default so we don't require an opt-in. Presumably this is only
> applicable to RISC-V platform?
It makes sense to have a configurable option, but it should probably be
off by default. At the time of writing, we don't have a lot of RISC-V
SoCs implementing IMSIC/APLIC. AFAIK all in-tree RISC-V platforms except
SpacemiT K3 don't require this fixup, so disabling it by default would
avoid increase their binary size while keeping the code change minimal.
> I think this also would apply to U-Boot SPL, in terms of consistency
> this fix-up should be instrumented so that you can require it to run
> when exiting the SPL (but this would of course be disabled when there is
> an SBI). This should not incur any code size overhead as a config option
> it would simply not be compiled-in. This gives it an explicit
> application at build time and be visible in the .config
arch_fixup_fdt() is already invoked in SPL when transferring control to
Linux. We should probably also do so when transferring control to
OpenSBI, but this has nothing to do with this patch. Code included in
this patch only gets executed in S-mode, in which case OpenSBI couldn't
be invoked at all.
> With the above suggestions implemented, I think the commit message does
> not require to mention "OpenSBI" at all. It simply becomes a matter of
> informing the user and being a consistency enforcement SPL and Main app
> boot phases.
No, introducing this fixup to both SPL and U-Boot proper has nothing to
do with the issue it solves. The original problem is that fixups
performed by M-mode firmware are lost when loading a fresh devicetree,
and it's good to describe the issue clearly in the commit message. I'm
fine with this commit message.
> -E
--
Thanks,
Yao Zi
Meow-mrrp-mrow, I'm a cat.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
2026-12-05 21:54 ` Yao Zi
@ 2026-12-05 22:34 ` E Shattow
0 siblings, 0 replies; 6+ messages in thread
From: E Shattow @ 2026-12-05 22:34 UTC (permalink / raw)
To: Yao Zi, Anirudh Srinivasan
Cc: u-boot, Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell
On 12/5/26 13:54, Yao Zi wrote:
> On Sat, Dec 05, 2026 at 09:40:16AM -0800, E Shattow wrote:
>> Hi Anirudh,
>>
>> Thanks for your patience :) replying my questions.
>>
>> On 12/4/26 06:25, Anirudh Srinivasan wrote:
>>> Hi E,
>>>
>>> On Fri, Dec 4, 2026 at 5:10 AM E Shattow <e@freeshell.de> wrote:
>>>>
>>>> Hi Anirudh,
>>>>
>>>> On 12/3/26 08:56, Anirudh Srinivasan wrote:
>>>>> When U-Boot is running in S mode, the DT passed to the next S mode stage
>>>>> can either be the bundled in DT U-Boot and the previous M mode stage
>>>>> use, or be loaded by U-Boot from some boot media. In the former case,
>>>>> the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
>>>>> nodes on an AIA system (for example, OpenSBI does this fixup). These
>>>>> controllers are to be managed by M-mode software, so this is done to
>>>>> prevent S mode software from trying to probe them.
>>>>>
>>>>
>>>> The way it reads now (in my point of view) is as:
>>>>
>>>> "M-IMSIC and M-APLIC controllers are to be managed by M-mode software,
>>>> and so enforce any M-mode M-IMSIC and M-APLIC nodes are effectively
>>>> status 'reserved' in S-mode U-Boot with a fixup to the received control
>>>
>>> This is what OpenSBI does.
>>>
>>>> Fdt from preceding M-Mode software (e.g. OpenSBI). Enforce again this
>>>> same fixup when entering the next S-mode kernel to prevent S-mode
>>>> software from trying to probe them.
>>>
>>> We're doing this again here cause we may possibly not use the DT
>>> passed by OpenSBI and use a fresh DT from boot media.
>>>
>>> Regards
>>> Anirudh srinivasan
>>
>> If we did not call out to an M-Mode SBI for the transition to S-Mode
>> then we would be managing these with a fix-up at M-Mode U-Boot SPL when
>> handing off to S-Mode U-Boot main app; I see the problem now, M-Mode
>> U-Boot SPL loads U-Boot main multi-fit image which begins code execution
>> with M-Mode SBI (e.g. OpenSBI or RustSBI, etc.) and we have no domain
>> over the Fdt control state as S-Mode U-Boot main app is loaded and
>> begins code execution because that is done by the 3rd party M-Mode SBI.
>> We again incur this problem exiting from S-Mode U-Boot Main app because
>> there are provisions for a user to again load data to the Fdt for
>> hand-off to the next boot phase.
>>
>> I think it would be appropriate to log a warning (or even log "info"
>> level) that this particular M-mode <=> S-Mode fix-up consistency
>> enforcement is being done, as for example:
>>
>> "Enforce reserved M-mode Fdt property status for handoff to S-Mode kernel:
>> * M-IMSIC okay => reserved
>> * M-APLIC okay => reserved"
>>
>> or when the fix-up is activated but no nodes are changed then as:
>>
>> "Enforce reserved M-mode Fdt property status for handoff to S-Mode
>> kernel: (n/a)"
>
> A message at warning or info level sounds too verbose. A message at
> debug level would indeed help debugging when problems occur.
>
>> Also for consistency we should enforce this twice, at both S-Mode U-Boot
>> main app initialization and at hand-off exiting S-Mode U-Boot main app.
>
> What do you mean by "enforce this twice"? Do you mean to fix up the FDT
> both on entry of the U-Boot proper and on hand-off to the OS?
>
> If my understanding is correct, this doesn't make sense. U-Boot makes no
> use of interrupts, thus imsic/aplic means nothing to it.
>
Also running the fix-up at the entry of S-mode U-Boot Main app serves as
a user-facing warning when the Fdt is not consistent for the S-mode
operation. That is a hint that the SBI did not do its job. We don't know
all the possible things a user-defined SBI might do so just posture this
as input validation on both the entry to S-mode U-Boot and the hand-off
to exit from S-mode U-Boot. It's not relevant that U-Boot itself has no
interaction with interrupts or what the particular node is, only that it
is a fix-up that enforces M-mode <=> S-mode changeover.
>> I would like an explicit opt-in / opt-out strategy for the M-mode <=>
>> S-mode Fdt fix-up. A compile-time option is fine, here, and to make this
>> implicit for all RISC-V makes sense to me unless disabled explicitly
>> with "=n".... something so it appears in the .config but that it is a
>> sensible default so we don't require an opt-in. Presumably this is only
>> applicable to RISC-V platform?
>
> It makes sense to have a configurable option, but it should probably be
> off by default. At the time of writing, we don't have a lot of RISC-V
> SoCs implementing IMSIC/APLIC. AFAIK all in-tree RISC-V platforms except
> SpacemiT K3 don't require this fixup, so disabling it by default would
> avoid increase their binary size while keeping the code change minimal.
>
I consider this as belonging to a group of M-mode <=> S-mode domain
specific Fdt properties that need to be input validated... not specific
to the peripherals or SoC features implemented by those.
>> I think this also would apply to U-Boot SPL, in terms of consistency
>> this fix-up should be instrumented so that you can require it to run
>> when exiting the SPL (but this would of course be disabled when there is
>> an SBI). This should not incur any code size overhead as a config option
>> it would simply not be compiled-in. This gives it an explicit
>> application at build time and be visible in the .config
>
> arch_fixup_fdt() is already invoked in SPL when transferring control to
> Linux. We should probably also do so when transferring control to
> OpenSBI, but this has nothing to do with this patch. Code included in
> this patch only gets executed in S-mode, in which case OpenSBI couldn't
> be invoked at all.
>
Okay fine with me to keep the scope narrower, but I see nothing here
that restricts this to IMSIC/APLIC hardware features, or to "OpenSBI".
This is logically just input and output validation.
>> With the above suggestions implemented, I think the commit message does
>> not require to mention "OpenSBI" at all. It simply becomes a matter of
>> informing the user and being a consistency enforcement SPL and Main app
>> boot phases.
>
> No, introducing this fixup to both SPL and U-Boot proper has nothing to
> do with the issue it solves. The original problem is that fixups
> performed by M-mode firmware are lost when loading a fresh devicetree,
> and it's good to describe the issue clearly in the commit message. I'm
> fine with this commit message.
>
The issue IMO is not being addressed by this patch as it is; as-is this
is merely a workaround for a specific circumstance that depends on what
OpenSBI is or is not doing. Look at it from the view of M-mode <=>
S-mode input validation and it's clear what to do, and the explanation
doesn't have to be so "what-about-..." explaining what OpenSBI does,
what U-Boot does, when and where. It is simply on every edge where
U-Boot goes M-mode <=> S-Mode we validate and enforce Fdt properties
that need to be adjusted for the new mode, no exceptions or inconsistencies.
-E
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-05 22:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:56 [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode Anirudh Srinivasan
2026-12-04 11:10 ` E Shattow
2026-12-04 14:25 ` Anirudh Srinivasan
2026-12-05 17:40 ` E Shattow
2026-12-05 21:54 ` Yao Zi
2026-12-05 22:34 ` E Shattow
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.