diff mbox series

[v1,1/1] riscv: Add boot hartid to Device tree

Message ID 20200227210035.6246-2-atish.patra@wdc.com
State Superseded
Delegated to: Andes
Headers show
Series Add boot hartid to a Device tree | expand

Commit Message

Atish Patra Feb. 27, 2020, 9 p.m. UTC
Linux booting protocol mandates that register "a0" contains the hartid.
However, U-boot can not pass the hartid via a0 during via standard UEFI
protocol. DT nodes are commonly used to pass such information to the OS.

Add a DT node under chosen node to indicate the boot hartid. EFI stub
in Linux kernel will parse this node and pass it to the real kernel
in "a0" before jumping to it.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
---
 arch/riscv/lib/bootm.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Rick Chen March 4, 2020, 7:58 a.m. UTC | #1
Hi Atish

> From: U-Boot [mailto:u-boot-bounces@lists.denx.de] On Behalf Of Atish Patra
> Sent: Friday, February 28, 2020 5:01 AM
> To: u-boot@lists.denx.de
> Cc: Atish Patra; Alexander Graf; Anup Patel; Bin Meng; Joe Hershberger; Loic Pallardy; Lukas Auer; Marek BehĂșn; Marek Vasut; Patrick Delaunay; Peng Fan; Philippe Reynes; Simon Glass; Simon Goldschmidt; Stefano Babic; Thierry Reding; trini@konsulko.com; Heinrich Schuchardt; Ard Biesheuvel; leif@nuviainc.com; abner.chang@hpe.com; daniel.schaefer@hpe.com
> Subject: [v1 PATCH 1/1] riscv: Add boot hartid to Device tree
>
> Linux booting protocol mandates that register "a0" contains the hartid.
> However, U-boot can not pass the hartid via a0 during via standard UEFI protocol. DT nodes are commonly used to pass such information to the OS.
>
> Add a DT node under chosen node to indicate the boot hartid. EFI stub in Linux kernel will parse this node and pass it to the real kernel in "a0" before jumping to it.
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> ---
>  arch/riscv/lib/bootm.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index fad16901c5f2..dd359a45c2e1 100644
> --- a/arch/riscv/lib/bootm.c
> +++ b/arch/riscv/lib/bootm.c
> @@ -28,6 +28,19 @@ __weak void board_quiesce_devices(void)
>
>  int arch_fixup_fdt(void *blob)
>  {
> +       u32 size;
> +       int chosen_offset, err;
> +
> +       size = fdt_totalsize(blob);
> +       err  = fdt_open_into(blob, blob, size + 32);
> +       if (err < 0) {
> +               printf("Device Tree can't be expanded to accommodate new node");
> +               return -1;
> +       }
> +       chosen_offset = fdt_path_offset(blob, "/chosen");
> +       fdt_setprop_u32(blob, chosen_offset, "boot-hartid",
> +                          gd->arch.boot_hart);

Is it also OK for RV64 ?

Other than that,
Reviewed-by: Rick Chen <rick@andestech.com>

> +
>         return 0;
>  }
>
> --
> 2.24.0
>
Atish Patra March 4, 2020, 6:53 p.m. UTC | #2
On Tue, Mar 3, 2020 at 11:59 PM Rick Chen <rickchen36@gmail.com> wrote:
>
> Hi Atish
>
> > From: U-Boot [mailto:u-boot-bounces@lists.denx.de] On Behalf Of Atish Patra
> > Sent: Friday, February 28, 2020 5:01 AM
> > To: u-boot@lists.denx.de
> > Cc: Atish Patra; Alexander Graf; Anup Patel; Bin Meng; Joe Hershberger; Loic Pallardy; Lukas Auer; Marek BehĂșn; Marek Vasut; Patrick Delaunay; Peng Fan; Philippe Reynes; Simon Glass; Simon Goldschmidt; Stefano Babic; Thierry Reding; trini@konsulko.com; Heinrich Schuchardt; Ard Biesheuvel; leif@nuviainc.com; abner.chang@hpe.com; daniel.schaefer@hpe.com
> > Subject: [v1 PATCH 1/1] riscv: Add boot hartid to Device tree
> >
> > Linux booting protocol mandates that register "a0" contains the hartid.
> > However, U-boot can not pass the hartid via a0 during via standard UEFI protocol. DT nodes are commonly used to pass such information to the OS.
> >
> > Add a DT node under chosen node to indicate the boot hartid. EFI stub in Linux kernel will parse this node and pass it to the real kernel in "a0" before jumping to it.
> >
> > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > ---
> >  arch/riscv/lib/bootm.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index fad16901c5f2..dd359a45c2e1 100644
> > --- a/arch/riscv/lib/bootm.c
> > +++ b/arch/riscv/lib/bootm.c
> > @@ -28,6 +28,19 @@ __weak void board_quiesce_devices(void)
> >
> >  int arch_fixup_fdt(void *blob)
> >  {
> > +       u32 size;
> > +       int chosen_offset, err;
> > +
> > +       size = fdt_totalsize(blob);
> > +       err  = fdt_open_into(blob, blob, size + 32);
> > +       if (err < 0) {
> > +               printf("Device Tree can't be expanded to accommodate new node");
> > +               return -1;
> > +       }
> > +       chosen_offset = fdt_path_offset(blob, "/chosen");
> > +       fdt_setprop_u32(blob, chosen_offset, "boot-hartid",
> > +                          gd->arch.boot_hart);
>
> Is it also OK for RV64 ?
>

Yes. I have tested it. To make it compatible for both 32 bit & 64 bit,
I have chosen a 32bit property
which allows the max hartid to be 2^32-1 which should be sufficient.

> Other than that,
> Reviewed-by: Rick Chen <rick@andestech.com>
>
> > +
> >         return 0;
> >  }
> >
> > --
> > 2.24.0
> >
diff mbox series

Patch

diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index fad16901c5f2..dd359a45c2e1 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -28,6 +28,19 @@  __weak void board_quiesce_devices(void)
 
 int arch_fixup_fdt(void *blob)
 {
+	u32 size;
+	int chosen_offset, err;
+
+	size = fdt_totalsize(blob);
+	err  = fdt_open_into(blob, blob, size + 32);
+	if (err < 0) {
+		printf("Device Tree can't be expanded to accommodate new node");
+		return -1;
+	}
+	chosen_offset = fdt_path_offset(blob, "/chosen");
+	fdt_setprop_u32(blob, chosen_offset, "boot-hartid",
+			   gd->arch.boot_hart);
+
 	return 0;
 }