diff mbox series

[RESEND,v5,1/6] riscv: Add boot hartid to Device tree

Message ID 20200418060758.4839-2-atish.patra@wdc.com
State Superseded
Headers show
Series RISC-V DT related fixes for reserved memory & UEFI | expand

Commit Message

Atish Patra April 18, 2020, 6:07 a.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 at wdc.com>
Reviewed-by: Rick Chen <rick at andestech.com>
Tested-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 arch/riscv/lib/bootm.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Bin Meng April 18, 2020, 12:24 p.m. UTC | #1
On Sat, Apr 18, 2020 at 2:10 PM Atish Patra <atish.patra at wdc.com> wrote:
>

nits: Device => device in the commit title

> Linux booting protocol mandates that register "a0" contains the hartid.
> However, U-boot can not pass the hartid via a0 during via standard UEFI

nits: U-boot => U-Boot

> 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 at wdc.com>
> Reviewed-by: Rick Chen <rick at andestech.com>
> Tested-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> ---
>  arch/riscv/lib/bootm.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
Andreas Schwab April 19, 2020, 4:52 p.m. UTC | #2
On Apr 17 2020, Atish Patra wrote:

> Linux booting protocol mandates that register "a0" contains the hartid.
> However, U-boot can not pass the hartid via a0 during via standard UEFI

s/during via/during/

Andreas.
diff mbox series

Patch

diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index fad16901c5f2..87cadad5016d 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -28,6 +28,28 @@  __weak void board_quiesce_devices(void)
 
 int arch_fixup_fdt(void *blob)
 {
+#ifdef CONFIG_EFI_LOADER
+	int err;
+	u32 size;
+	int chosen_offset;
+
+	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 err;
+	}
+	chosen_offset = fdt_path_offset(blob, "/chosen");
+	if (chosen_offset < 0) {
+		err = fdt_add_subnode(blob, 0, "chosen");
+		if (err < 0) {
+			printf("chosen node can not be added\n");
+			return err;
+		}
+	}
+	/* Overwrite the boot-hartid as U-Boot is the last stage BL */
+	fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart);
+#endif
 	return 0;
 }