From 1f3ce24ef52f2ec4473801a4bf49f86f0936b4c2 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Sat, 19 Jun 2021 06:50:31 +0200 Subject: RISC-V: S-Mode: propagate Hart ID Unlike other architectures we support, Linux must apparently be booted on all cores by the bootloader. To achieve this, the bootloaders running on the multiple cores synchronize via IPIs. We will get there eventually, but for now, let's restrict barebox to boot Linux on a single core. S-Mode firmware is passed hart (core) id in a0. This is propagated via the thread pointer register, which is unused by GCC and made available as: - cpuinfo output when running in S-Mode - $global.hartid - a0 when booting via bootm - /chosen/boot-hartid fixup: will come in handy when we gain EFI loading support - single /cpus/*/reg: All other CPU nodes are deleted via fixup For M-Mode, we can query hart id via CSR. It's unknown whether erizo supports it and we don't yet have exception support to handle it not being available, so changes are only done for S-Mode for now. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20210619045055.779-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- common/globalvar.c | 21 +++++++++++++++++++++ common/oftree.c | 19 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/globalvar.c b/common/globalvar.c index 8bb5015ce4..9e5a99f793 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -565,6 +565,27 @@ int globalvar_add_simple_int(const char *name, int *value, return 0; } +int globalvar_add_simple_uint64(const char *name, u64 *value, + const char *format) +{ + struct param_d *p; + int ret; + + ret = globalvar_remove_unqualified(name); + if (ret) + return ret; + + p = dev_add_param_uint64(&global_device, name, NULL, NULL, + value, format, NULL); + + if (IS_ERR(p)) + return PTR_ERR(p); + + globalvar_nv_sync(name); + + return 0; +} + int globalvar_add_bool(const char *name, int (*set)(struct param_d *, void *), int *value, void *priv) diff --git a/common/oftree.c b/common/oftree.c index 5eaa63ad7e..1fcc5277c5 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -232,7 +232,24 @@ static int of_fixup_bootargs(struct device_node *root, void *unused) return err; } - return of_fixup_bootargs_bootsource(root, node); + err = of_fixup_bootargs_bootsource(root, node); + if (err) + return err; + + if (IS_ENABLED(CONFIG_RISCV)) { + const char *hartid; + + hartid = getenv("global.hartid"); + if (hartid) { + unsigned long id; + + err = kstrtoul(hartid, 10, &id); + if (!err) + err = of_property_write_u32(node, "boot-hartid", id); + } + } + + return err; } static int of_register_bootargs_fixup(void) -- cgit v1.2.3