All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Disable M-mode IMSIC and APLIC nodes in DT passed to next stage in S mode
@ 2026-11-18 18:00 Anirudh Srinivasan
  2026-11-18 21:05 ` E Shattow
  0 siblings, 1 reply; 4+ messages in thread
From: Anirudh Srinivasan @ 2026-11-18 18:00 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 and is used to boot linux, the DT passed
to linux can either be the bundled in DT U-Boot and OpenSBI use, or be
loaded by U-Boot from some boot media. In the former case, OpenSBI fixes
up the DT to disable the M-mode IMSIC and APLIC nodes on an AIA system.
These controllers are to be managed by M-mode software, so this is done
to prevent linux 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 similar to OpenSBI.
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

Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
---
 arch/riscv/lib/fdt_fixup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c
index 6dfd1a2d5b8..ce8c18a7b92 100644
--- a/arch/riscv/lib/fdt_fixup.c
+++ b/arch/riscv/lib/fdt_fixup.c
@@ -117,6 +117,80 @@ 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);
+	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_mmode_imsic_aplic_fixup() - Disable M-mode APLIC and IMSIC nodes in DT
+ * @fdt: Pointer to the device tree in which nodes are to be disabled
+ *
+ * On RISC-V AIA systems, M-mode software manages the M-mode APLIC and 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 disable these nodes before passing
+ * it to the next S-mode stage.
+ *
+ * Return: 0 on success or error otherwise.
+ */
+static int riscv_aia_mmode_imsic_aplic_fixup(void *fdt)
+{
+	int offset, err;
+
+	/* Disable M-IMSIC in APLIC-IMSIC configuration */
+	fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,imsics") {
+		if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
+			err = fdt_status_disabled(fdt, offset);
+			if (err < 0)
+				return err;
+		}
+	}
+
+	/* Disable M-APLIC in APLIC only configuration */
+	fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
+		if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
+			err = fdt_status_disabled(fdt, offset);
+			if (err < 0)
+				return err;
+		}
+	}
+
+	/* Disable M-APLIC in APLIC-IMSIC configuration */
+	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)) {
+				err = fdt_status_disabled(fdt, offset);
+				if (err < 0)
+					return err;
+			}
+		}
+	}
+
+	return 0;
+}
+
 #ifdef CONFIG_OF_BOARD_FIXUP
 int board_fix_fdt(void *fdt)
 {
@@ -165,5 +239,15 @@ int arch_fixup_fdt(void *blob)
 	if (err < 0)
 		return err;
 
+	/*
+	 * Disable M-mode APLIC and IMSIC nodes in DT passed
+	 * to next stage if we're in S mode
+	 */
+	if (!CONFIG_IS_ENABLED(RISCV_MMODE)) {
+		err = riscv_aia_mmode_imsic_aplic_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] 4+ messages in thread

* Re: [PATCH] riscv: Disable M-mode IMSIC and APLIC nodes in DT passed to next stage in S mode
  2026-11-18 18:00 [PATCH] riscv: Disable M-mode IMSIC and APLIC nodes in DT passed to next stage in S mode Anirudh Srinivasan
@ 2026-11-18 21:05 ` E Shattow
  2026-11-18 22:21   ` Anirudh Srinivasan
  0 siblings, 1 reply; 4+ messages in thread
From: E Shattow @ 2026-11-18 21:05 UTC (permalink / raw)
  To: Anirudh Srinivasan, Yao Zi, u-boot
  Cc: Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell

Hi Anirudh,

On 11/18/26 10:00, Anirudh Srinivasan wrote:
> When U-Boot is running in S mode and is used to boot linux, the DT passed
> to linux can either be the bundled in DT U-Boot and OpenSBI use, or be
> loaded by U-Boot from some boot media. In the former case, OpenSBI fixes
> up the DT to disable the M-mode IMSIC and APLIC nodes on an AIA system.
> These controllers are to be managed by M-mode software, so this is done
> to prevent linux 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 similar to OpenSBI.
> This gets rid of prints like this during linux boots.
> 

I think it is not necessary to mention specific software (U-Boot or
OpenSBI) in the lede paragraph of the commit message. That description
of Linux is a testing scenario (which is fine to also mention, in
secondary paragraph(s), or just omit from the commit mesage and leave it
to mailing list replies for cover letter and T-by tags). It would apply
equally to any S-mode kernel including U-Boot main app itself being
S-mode, GRUB EFI, *BSD, etc.

Essentially we accept that for RISC-V there is other third-party
software which may integrate with U-Boot and we cannot know the
consistency of device tree state in this context, even when we have
provided some of these modifications in the form of device tree
overrides to that software. It makes good sense to do some fixup in
these likely situations. The important thing I'm reading for in this
description is, "what is it about the RISC-V platform M-mode / S-mode in
U-Boot that requires consistency checks of device tree properties at
runtime?"

Are these the only consistency checks that we foresee?

> [    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
> 
> Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
> ---
>  arch/riscv/lib/fdt_fixup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 84 insertions(+)
> 
> diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c
> index 6dfd1a2d5b8..ce8c18a7b92 100644
> --- a/arch/riscv/lib/fdt_fixup.c
> +++ b/arch/riscv/lib/fdt_fixup.c
> @@ -117,6 +117,80 @@ 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);
> +	if (!interrupts_extended || !len || len % (2 * sizeof(u32)))
> +		return false;
> +	for (i = 1; i < len / sizeof(u32); i += 2) {

Read the size-cells property, or comment why this is assumed to be
size-cells=<2> (and what happens on non-64-bit platform if this is
applicable or not).

> +		if (fdt32_to_cpu(interrupts_extended[i]) == IRQ_M_EXT)
> +			return true;
> +	}
> +	return false;
> +}
> +
> +/**
> + * riscv_aia_mmode_imsic_aplic_fixup() - Disable M-mode APLIC and IMSIC nodes in DT
> + * @fdt: Pointer to the device tree in which nodes are to be disabled
> + *
> + * On RISC-V AIA systems, M-mode software manages the M-mode APLIC and 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 disable these nodes before passing
> + * it to the next S-mode stage.
> + *
> + * Return: 0 on success or error otherwise.
> + */
> +static int riscv_aia_mmode_imsic_aplic_fixup(void *fdt)
> +{

Critically this fixup routine does not *enable* the nodes *for* M-mode.
I cannot think of a better name for it than you have here, however.

Is this not an S-mode fixup routine?

Maybe... "riscv_aia_exit_mmode_imsic_aplic_fixup"

> +	int offset, err;
> +
> +	/* Disable M-IMSIC in APLIC-IMSIC configuration */
> +	fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,imsics") {
> +		if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
> +			err = fdt_status_disabled(fdt, offset);
> +			if (err < 0)
> +				return err;
> +		}
> +	}
> +
> +	/* Disable M-APLIC in APLIC only configuration */
> +	fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
> +		if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
> +			err = fdt_status_disabled(fdt, offset);
> +			if (err < 0)
> +				return err;
> +		}
> +	}
> +
> +	/* Disable M-APLIC in APLIC-IMSIC configuration */
> +	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)) {
> +				err = fdt_status_disabled(fdt, offset);
> +				if (err < 0)
> +					return err;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  #ifdef CONFIG_OF_BOARD_FIXUP
>  int board_fix_fdt(void *fdt)
>  {
> @@ -165,5 +239,15 @@ int arch_fixup_fdt(void *blob)
>  	if (err < 0)
>  		return err;
>  

> +	/*
> +	 * Disable M-mode APLIC and IMSIC nodes in DT passed
> +	 * to next stage if we're in S mode
> +	 */
> +	if (!CONFIG_IS_ENABLED(RISCV_MMODE)) {
> +		err = riscv_aia_mmode_imsic_aplic_fixup(blob);

This could be clearer to say "When not in M-mode then disable M-mode
APLIC and IMSIC nodes"

The subroutine name is already very descriptive but this comment would
be fully redundant if the function name is clearer about its
functionality, and would not need a comment. (See previous suggestion
about function name).

> +		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>
> 

Overall looks good to me, I want to know why we're not reading the
size-cells, and then refine the descriptions to be clearer about what I
am looking at in front of me so that a function name does not need a
comment to explain what it is doing.

It is a level of technical detail I am not familiar with, so if you can
make it make sense to me then it will be clear for everyone.

Thanks,

-E

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] riscv: Disable M-mode IMSIC and APLIC nodes in DT passed to next stage in S mode
  2026-11-18 21:05 ` E Shattow
@ 2026-11-18 22:21   ` Anirudh Srinivasan
  2026-11-19  1:10     ` E Shattow
  0 siblings, 1 reply; 4+ messages in thread
From: Anirudh Srinivasan @ 2026-11-18 22:21 UTC (permalink / raw)
  To: E Shattow; +Cc: Yao Zi, u-boot, Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell

Hi E,

On Wed, Nov 18, 2026 at 3:05 PM E Shattow <e@freeshell.de> wrote:
>
> Hi Anirudh,
>
> On 11/18/26 10:00, Anirudh Srinivasan wrote:
> > When U-Boot is running in S mode and is used to boot linux, the DT passed
> > to linux can either be the bundled in DT U-Boot and OpenSBI use, or be
> > loaded by U-Boot from some boot media. In the former case, OpenSBI fixes
> > up the DT to disable the M-mode IMSIC and APLIC nodes on an AIA system.
> > These controllers are to be managed by M-mode software, so this is done
> > to prevent linux 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 similar to OpenSBI.
> > This gets rid of prints like this during linux boots.
> >
>
> I think it is not necessary to mention specific software (U-Boot or
> OpenSBI) in the lede paragraph of the commit message. That description
> of Linux is a testing scenario (which is fine to also mention, in
> secondary paragraph(s), or just omit from the commit mesage and leave it
> to mailing list replies for cover letter and T-by tags). It would apply
> equally to any S-mode kernel including U-Boot main app itself being
> S-mode, GRUB EFI, *BSD, etc.
>
> Essentially we accept that for RISC-V there is other third-party
> software which may integrate with U-Boot and we cannot know the
> consistency of device tree state in this context, even when we have
> provided some of these modifications in the form of device tree
> overrides to that software. It makes good sense to do some fixup in
> these likely situations. The important thing I'm reading for in this
> description is, "what is it about the RISC-V platform M-mode / S-mode in
> U-Boot that requires consistency checks of device tree properties at
> runtime?"

Yes, I'll drop references to OpenSBI/Linux and just say M-mode and
S-mode software.

>
> Are these the only consistency checks that we foresee?

These are the same as what OpenSBI does (maplic and mimsic).

>
> > [    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
> >
> > Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
> > ---
> >  arch/riscv/lib/fdt_fixup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 84 insertions(+)
> >
> > diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c
> > index 6dfd1a2d5b8..ce8c18a7b92 100644
> > --- a/arch/riscv/lib/fdt_fixup.c
> > +++ b/arch/riscv/lib/fdt_fixup.c
> > @@ -117,6 +117,80 @@ 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);
> > +     if (!interrupts_extended || !len || len % (2 * sizeof(u32)))
> > +             return false;
> > +     for (i = 1; i < len / sizeof(u32); i += 2) {
>
> Read the size-cells property, or comment why this is assumed to be
> size-cells=<2> (and what happens on non-64-bit platform if this is
> applicable or not).

We aren't reading a reg cell here. The 32/64 bit discrepancy comes
here only then. interrupts-extended is always 2 u32s per hart, for
both 32 and 64 bit systems.

>
> > +             if (fdt32_to_cpu(interrupts_extended[i]) == IRQ_M_EXT)
> > +                     return true;
> > +     }
> > +     return false;
> > +}
> > +
> > +/**
> > + * riscv_aia_mmode_imsic_aplic_fixup() - Disable M-mode APLIC and IMSIC nodes in DT
> > + * @fdt: Pointer to the device tree in which nodes are to be disabled
> > + *
> > + * On RISC-V AIA systems, M-mode software manages the M-mode APLIC and 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 disable these nodes before passing
> > + * it to the next S-mode stage.
> > + *
> > + * Return: 0 on success or error otherwise.
> > + */
> > +static int riscv_aia_mmode_imsic_aplic_fixup(void *fdt)
> > +{
>
> Critically this fixup routine does not *enable* the nodes *for* M-mode.
> I cannot think of a better name for it than you have here, however.
>
> Is this not an S-mode fixup routine?
>
> Maybe... "riscv_aia_exit_mmode_imsic_aplic_fixup"

How about "riscv_aia_mimsic_maplic_fixup"? It clearly states which
nodes are being fixed up.

>
> > +     int offset, err;
> > +
> > +     /* Disable M-IMSIC in APLIC-IMSIC configuration */
> > +     fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,imsics") {
> > +             if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
> > +                     err = fdt_status_disabled(fdt, offset);
> > +                     if (err < 0)
> > +                             return err;
> > +             }
> > +     }
> > +
> > +     /* Disable M-APLIC in APLIC only configuration */
> > +     fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
> > +             if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
> > +                     err = fdt_status_disabled(fdt, offset);
> > +                     if (err < 0)
> > +                             return err;
> > +             }
> > +     }
> > +
> > +     /* Disable M-APLIC in APLIC-IMSIC configuration */
> > +     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)) {
> > +                             err = fdt_status_disabled(fdt, offset);
> > +                             if (err < 0)
> > +                                     return err;
> > +                     }
> > +             }
> > +     }
> > +
> > +     return 0;
> > +}
> > +
> >  #ifdef CONFIG_OF_BOARD_FIXUP
> >  int board_fix_fdt(void *fdt)
> >  {
> > @@ -165,5 +239,15 @@ int arch_fixup_fdt(void *blob)
> >       if (err < 0)
> >               return err;
> >
>
> > +     /*
> > +      * Disable M-mode APLIC and IMSIC nodes in DT passed
> > +      * to next stage if we're in S mode
> > +      */
> > +     if (!CONFIG_IS_ENABLED(RISCV_MMODE)) {
> > +             err = riscv_aia_mmode_imsic_aplic_fixup(blob);
>
> This could be clearer to say "When not in M-mode then disable M-mode
> APLIC and IMSIC nodes"
>
> The subroutine name is already very descriptive but this comment would
> be fully redundant if the function name is clearer about its
> functionality, and would not need a comment. (See previous suggestion
> about function name).

I'll use M-APLIC and M-IMSIC so there is no confusion about s-mode/m-mode.

>
> > +             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>
> >
>
> Overall looks good to me, I want to know why we're not reading the
> size-cells, and then refine the descriptions to be clearer about what I
> am looking at in front of me so that a function name does not need a
> comment to explain what it is doing.
>
> It is a level of technical detail I am not familiar with, so if you can
> make it make sense to me then it will be clear for everyone.
>
> Thanks,
>
> -E

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] riscv: Disable M-mode IMSIC and APLIC nodes in DT passed to next stage in S mode
  2026-11-18 22:21   ` Anirudh Srinivasan
@ 2026-11-19  1:10     ` E Shattow
  0 siblings, 0 replies; 4+ messages in thread
From: E Shattow @ 2026-11-19  1:10 UTC (permalink / raw)
  To: Anirudh Srinivasan
  Cc: Yao Zi, u-boot, Tim Ouyang, Leo Liang, Tom Rini, Troy Mitchell

On 11/18/26 14:21, Anirudh Srinivasan wrote:
> Hi E,
> 
> On Wed, Nov 18, 2026 at 3:05 PM E Shattow <e@freeshell.de> wrote:
>>
>> Hi Anirudh,
>>
>> On 11/18/26 10:00, Anirudh Srinivasan wrote:
>>> When U-Boot is running in S mode and is used to boot linux, the DT passed
>>> to linux can either be the bundled in DT U-Boot and OpenSBI use, or be
>>> loaded by U-Boot from some boot media. In the former case, OpenSBI fixes
>>> up the DT to disable the M-mode IMSIC and APLIC nodes on an AIA system.
>>> These controllers are to be managed by M-mode software, so this is done
>>> to prevent linux 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 similar to OpenSBI.
>>> This gets rid of prints like this during linux boots.
>>>
>>
>> I think it is not necessary to mention specific software (U-Boot or
>> OpenSBI) in the lede paragraph of the commit message. That description
>> of Linux is a testing scenario (which is fine to also mention, in
>> secondary paragraph(s), or just omit from the commit mesage and leave it
>> to mailing list replies for cover letter and T-by tags). It would apply
>> equally to any S-mode kernel including U-Boot main app itself being
>> S-mode, GRUB EFI, *BSD, etc.
>>
>> Essentially we accept that for RISC-V there is other third-party
>> software which may integrate with U-Boot and we cannot know the
>> consistency of device tree state in this context, even when we have
>> provided some of these modifications in the form of device tree
>> overrides to that software. It makes good sense to do some fixup in
>> these likely situations. The important thing I'm reading for in this
>> description is, "what is it about the RISC-V platform M-mode / S-mode in
>> U-Boot that requires consistency checks of device tree properties at
>> runtime?"
> 
> Yes, I'll drop references to OpenSBI/Linux and just say M-mode and
> S-mode software.
> 
>>
>> Are these the only consistency checks that we foresee?
> 
> These are the same as what OpenSBI does (maplic and mimsic).
> 
>>
>>> [    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
>>>
>>> Signed-off-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
>>> ---
>>>  arch/riscv/lib/fdt_fixup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++
>>>  1 file changed, 84 insertions(+)
>>>
>>> diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c
>>> index 6dfd1a2d5b8..ce8c18a7b92 100644
>>> --- a/arch/riscv/lib/fdt_fixup.c
>>> +++ b/arch/riscv/lib/fdt_fixup.c
>>> @@ -117,6 +117,80 @@ 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);
>>> +     if (!interrupts_extended || !len || len % (2 * sizeof(u32)))
>>> +             return false;
>>> +     for (i = 1; i < len / sizeof(u32); i += 2) {
>>
>> Read the size-cells property, or comment why this is assumed to be
>> size-cells=<2> (and what happens on non-64-bit platform if this is
>> applicable or not).
> 
> We aren't reading a reg cell here. The 32/64 bit discrepancy comes
> here only then. interrupts-extended is always 2 u32s per hart, for
> both 32 and 64 bit systems.
> 

Okay, thanks for explaining. I think it would helpful to keep this
explanation as a short comment saying this and whether it is specified
by the RISC-V or the device tree specification(s) that
interrupts-extended list items are always always 2*u32. I can see the
code implements that 2*u32 interval, but the implementation does not
itself explain the question of why it is doing so.

>>
>>> +             if (fdt32_to_cpu(interrupts_extended[i]) == IRQ_M_EXT)
>>> +                     return true;
>>> +     }
>>> +     return false;
>>> +}
>>> +
>>> +/**
>>> + * riscv_aia_mmode_imsic_aplic_fixup() - Disable M-mode APLIC and IMSIC nodes in DT
>>> + * @fdt: Pointer to the device tree in which nodes are to be disabled
>>> + *
>>> + * On RISC-V AIA systems, M-mode software manages the M-mode APLIC and 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 disable these nodes before passing
>>> + * it to the next S-mode stage.
>>> + *
>>> + * Return: 0 on success or error otherwise.
>>> + */
>>> +static int riscv_aia_mmode_imsic_aplic_fixup(void *fdt)
>>> +{
>>
>> Critically this fixup routine does not *enable* the nodes *for* M-mode.
>> I cannot think of a better name for it than you have here, however.
>>
>> Is this not an S-mode fixup routine?
>>
>> Maybe... "riscv_aia_exit_mmode_imsic_aplic_fixup"
> 
> How about "riscv_aia_mimsic_maplic_fixup"? It clearly states which
> nodes are being fixed up.
> 

That sounds good to me, yes.

>>
>>> +     int offset, err;
>>> +
>>> +     /* Disable M-IMSIC in APLIC-IMSIC configuration */
>>> +     fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,imsics") {
>>> +             if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
>>> +                     err = fdt_status_disabled(fdt, offset);
>>> +                     if (err < 0)
>>> +                             return err;
>>> +             }
>>> +     }
>>> +
>>> +     /* Disable M-APLIC in APLIC only configuration */
>>> +     fdt_for_each_node_by_compatible(offset, fdt, -1, "riscv,aplic") {
>>> +             if (riscv_node_handles_mmode_external_interrupts(fdt, offset)) {
>>> +                     err = fdt_status_disabled(fdt, offset);
>>> +                     if (err < 0)
>>> +                             return err;
>>> +             }
>>> +     }
>>> +
>>> +     /* Disable M-APLIC in APLIC-IMSIC configuration */
>>> +     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)) {
>>> +                             err = fdt_status_disabled(fdt, offset);
>>> +                             if (err < 0)
>>> +                                     return err;
>>> +                     }
>>> +             }
>>> +     }
>>> +
>>> +     return 0;
>>> +}
>>> +
>>>  #ifdef CONFIG_OF_BOARD_FIXUP
>>>  int board_fix_fdt(void *fdt)
>>>  {
>>> @@ -165,5 +239,15 @@ int arch_fixup_fdt(void *blob)
>>>       if (err < 0)
>>>               return err;
>>>
>>
>>> +     /*
>>> +      * Disable M-mode APLIC and IMSIC nodes in DT passed
>>> +      * to next stage if we're in S mode
>>> +      */
>>> +     if (!CONFIG_IS_ENABLED(RISCV_MMODE)) {
>>> +             err = riscv_aia_mmode_imsic_aplic_fixup(blob);
>>
>> This could be clearer to say "When not in M-mode then disable M-mode
>> APLIC and IMSIC nodes"
>>
>> The subroutine name is already very descriptive but this comment would
>> be fully redundant if the function name is clearer about its
>> functionality, and would not need a comment. (See previous suggestion
>> about function name).
> 
> I'll use M-APLIC and M-IMSIC so there is no confusion about s-mode/m-mode.
> 

Sure, or, drop the comment here with the function being named instead
riscv_aia_imsic_aplic_fixup()

If it doesn't tell me why we're doing this, then the code is anyway
self-evident what we're doing so that if we're not in M-mode then this
riscv_aia_imsic_aplic_fixup() is called. It is not too much trouble to
then further read the description of that function itself where it is
defined.

It would be confusing if the code continues to read that when we're not
in M-mode to then do an "M-mode fixup". The revised function name
doesn't raise this question to me, it looks okay.

[...]

With that,

Reviewed-by: E Shattow <e@freeshell.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19  1:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 18:00 [PATCH] riscv: Disable M-mode IMSIC and APLIC nodes in DT passed to next stage in S mode Anirudh Srinivasan
2026-11-18 21:05 ` E Shattow
2026-11-18 22:21   ` Anirudh Srinivasan
2026-11-19  1:10     ` 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.