Hello Xiang Wang,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/31179
to review the following change.
Change subject: riscv: Simplify payload handling
......................................................................
riscv: Simplify payload handling
1. Simplify payload code and convert it to C
2. Save the FDT pointer to HLS (hart-local storage).
3. Don't use mscratch to pass FDT pointer as it is used for exception handling.
Change-Id: I32bf2a99e07a65358a7f19b899259f0816eb45e8
Signed-off-by: Xiang Wang <wxjstz(a)126.com>
Signed-off-by: Philipp Hug <philipp(a)hug.cx>
---
M src/arch/riscv/Makefile.inc
M src/arch/riscv/boot.c
M src/arch/riscv/bootblock.S
M src/arch/riscv/include/arch/boot.h
M src/arch/riscv/include/arch/stages.h
M src/arch/riscv/include/mcall.h
M src/arch/riscv/mcall.c
D src/arch/riscv/payload.S
A src/arch/riscv/payload.c
M src/arch/riscv/stages.c
10 files changed, 87 insertions(+), 57 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/31179/1
diff --git a/src/arch/riscv/Makefile.inc b/src/arch/riscv/Makefile.inc
index e4c8468..9d91f0c 100644
--- a/src/arch/riscv/Makefile.inc
+++ b/src/arch/riscv/Makefile.inc
@@ -137,7 +137,7 @@
ramstage-y += smp.c
ramstage-y += boot.c
ramstage-y += tables.c
-ramstage-y += payload.S
+ramstage-y += payload.c
ramstage-$(ARCH_RISCV_PMP) += pmp.c
ramstage-y += \
$(top)/src/lib/memchr.c \
diff --git a/src/arch/riscv/boot.c b/src/arch/riscv/boot.c
index 3d8d5d6..dab4e09 100644
--- a/src/arch/riscv/boot.c
+++ b/src/arch/riscv/boot.c
@@ -19,6 +19,7 @@
#include <arch/encoding.h>
#include <console/console.h>
#include <arch/smp/smp.h>
+#include <mcall.h>
/*
* A pointer to the Flattened Device Tree passed to coreboot by the boot ROM.
@@ -26,27 +27,27 @@
*
* This pointer is only used in ramstage!
*/
-const void *rom_fdt;
static void do_arch_prog_run(struct prog *prog)
{
- void (*doit)(void *) = prog_entry(prog);
- void riscvpayload(const void *fdt, void *payload);
+ void (*doit)(int hart_id, void *fdt);
+ int hart_id;
+ void *fdt = prog_entry_arg(prog);
if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) {
/*
- * FIXME: This is wrong and will crash. Linux can't (in early
- * boot) access memory that's before its own loading address.
- * We need to copy the FDT to a place where Linux can access it.
+ * If prog_entry_arg is not set (e.g. by fit_payload), use fdt from HLS instead.
*/
- const void *fdt = rom_fdt;
-
- printk(BIOS_SPEW, "FDT is at %p\n", fdt);
- printk(BIOS_SPEW, "OK, let's go\n");
- riscvpayload(fdt, doit);
+ if (fdt == NULL)
+ fdt = HLS()->fdt;
+ run_payload(prog, fdt, RISCV_PAYLOAD_MODE_S);
+ return;
}
- doit(prog_entry_arg(prog));
+ doit = prog_entry(prog);
+ hart_id = HLS()->hart_id;
+
+ doit(hart_id, fdt);
}
void arch_prog_run(struct prog *prog)
diff --git a/src/arch/riscv/bootblock.S b/src/arch/riscv/bootblock.S
index 7f84215..d4b8be7 100644
--- a/src/arch/riscv/bootblock.S
+++ b/src/arch/riscv/bootblock.S
@@ -50,6 +50,7 @@
# initialize hart-local storage
csrr a0, mhartid
+ csrrw a1, mscratch, zero
call hls_init
li a0, CONFIG_RISCV_WORKING_HARTID
diff --git a/src/arch/riscv/include/arch/boot.h b/src/arch/riscv/include/arch/boot.h
index 24c1bed..34a507e 100644
--- a/src/arch/riscv/include/arch/boot.h
+++ b/src/arch/riscv/include/arch/boot.h
@@ -16,6 +16,12 @@
#ifndef ARCH_RISCV_INCLUDE_ARCH_BOOT_H
#define ARCH_RISCV_INCLUDE_ARCH_BOOT_H
-extern const void *rom_fdt;
+#include <program_loading.h>
+
+#define RISCV_PAYLOAD_MODE_U 0
+#define RISCV_PAYLOAD_MODE_S 1
+#define RISCV_PAYLOAD_MODE_M 3
+
+void run_payload(struct prog *prog, void *fdt, int payload_mode);
#endif
diff --git a/src/arch/riscv/include/arch/stages.h b/src/arch/riscv/include/arch/stages.h
index 90bd60b..138298f 100644
--- a/src/arch/riscv/include/arch/stages.h
+++ b/src/arch/riscv/include/arch/stages.h
@@ -18,6 +18,7 @@
#include <main_decl.h>
-void stage_entry(void) __attribute__((section(".text.stage_entry")));
+void stage_entry(int hart_id, void *fdt)
+ __attribute__((section(".text.stage_entry")));
#endif
diff --git a/src/arch/riscv/include/mcall.h b/src/arch/riscv/include/mcall.h
index 29df736..cd1ed6d 100644
--- a/src/arch/riscv/include/mcall.h
+++ b/src/arch/riscv/include/mcall.h
@@ -52,9 +52,14 @@
int ipi_pending;
uint64_t *timecmp;
uint64_t *time;
+ void *fdt;
struct blocker entry;
} hls_t;
+_Static_assert(
+ sizeof(hls_t) == HLS_SIZE,
+ "HLS_SIZE must equal to sizeof(hls_t)");
+
#define MACHINE_STACK_TOP() ({ \
/* coverity[uninit_use] : FALSE */ \
register uintptr_t sp asm ("sp"); \
@@ -66,7 +71,8 @@
#define MACHINE_STACK_SIZE RISCV_PGSIZE
-void hls_init(uint32_t hart_id); // need to call this before launching linux
+// need to call this before launching linux
+void hls_init(uint32_t hart_id, void *fdt);
/* This function is used to initialize HLS()->time/HLS()->timecmp */
void mtime_init(void);
diff --git a/src/arch/riscv/mcall.c b/src/arch/riscv/mcall.c
index 47cdd88..eaef644 100644
--- a/src/arch/riscv/mcall.c
+++ b/src/arch/riscv/mcall.c
@@ -34,10 +34,11 @@
int mcalldebug; // set this interactively for copious debug.
-void hls_init(uint32_t hart_id)
+void hls_init(uint32_t hart_id, void *fdt)
{
printk(BIOS_SPEW, "hart %d: HLS is %p\n", hart_id, HLS());
memset(HLS(), 0, sizeof(*HLS()));
+ HLS()->fdt = fdt;
HLS()->hart_id = hart_id;
mtime_init();
diff --git a/src/arch/riscv/payload.S b/src/arch/riscv/payload.S
deleted file mode 100644
index 1b8cb96..0000000
--- a/src/arch/riscv/payload.S
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2016 Google Inc
- * Copyright (C) 2018 Jonathan Neuschäfer
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-// "return" to a payload. a0: FDT, a1: entry point
- .global riscvpayload
-riscvpayload:
- /* Load the entry point */
- mv t0, a1
- csrw mepc, t0
- csrr t0, mstatus
-
- /* Set mstatus.MPP (the previous privilege mode) to supervisor mode */
- li t1, ~(3<<11)
- and t0, t0, t1
- li t2, (1<<11)
- or t0, t0, t2
- csrw mstatus, t0
-
- /* Pass the right arguments and jump! */
- mv a1, a0
- csrr a0, mhartid
- mret
diff --git a/src/arch/riscv/payload.c b/src/arch/riscv/payload.c
new file mode 100644
index 0000000..af2542f
--- /dev/null
+++ b/src/arch/riscv/payload.c
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2016 Google Inc
+ * Copyright (C) 2018 HardenedLinux
+ * Copyright (C) 2018 Jonathan Neuschäfer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdint.h>
+#include <arch/boot.h>
+#include <arch/encoding.h>
+#include <console/console.h>
+
+void run_payload(struct prog *prog, void *fdt, int payload_mode)
+{
+ void (*doit)(int hart_id, void *fdt) = prog_entry(prog);
+ int hart_id = read_csr(mhartid);
+ uintptr_t status = read_csr(mstatus);
+ status &= ~MSTATUS_MPIE;
+ status &= ~MSTATUS_MPP;
+ switch (payload_mode) {
+ case RISCV_PAYLOAD_MODE_U:
+ break;
+ case RISCV_PAYLOAD_MODE_S:
+ status |= MSTATUS_SPP;
+ break;
+ case RISCV_PAYLOAD_MODE_M:
+ doit(hart_id, fdt);
+ return;
+ default:
+ die("wrong privilege level for payload");
+ break;
+ }
+ write_csr(mstatus, status);
+ write_csr(mepc, doit);
+ asm volatile("mv a0, %0"::"r"(hart_id):"a0");
+ asm volatile("mv a1, %0"::"r"(fdt):"a1");
+ asm volatile("mret");
+}
diff --git a/src/arch/riscv/stages.c b/src/arch/riscv/stages.c
index 5e7fa4f..07b898f 100644
--- a/src/arch/riscv/stages.c
+++ b/src/arch/riscv/stages.c
@@ -28,18 +28,19 @@
#include <arch/encoding.h>
#include <arch/stages.h>
#include <arch/smp/smp.h>
+#include <rules.h>
+#include <mcall.h>
-void stage_entry(void)
+void stage_entry(int hart_id, void *fdt)
{
- smp_pause(CONFIG_RISCV_WORKING_HARTID);
-
/*
* Save the FDT pointer before entering ramstage, because mscratch
* might be overwritten in the trap handler, and there is code in
* ramstage that generates misaligned access faults.
*/
- if (ENV_RAMSTAGE)
- rom_fdt = (const void *)read_csr(mscratch);
+ HLS()->hart_id = hart_id;
+ HLS()->fdt = fdt;
+ smp_pause(CONFIG_RISCV_WORKING_HARTID);
main();
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/31179
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I32bf2a99e07a65358a7f19b899259f0816eb45e8
Gerrit-Change-Number: 31179
Gerrit-PatchSet: 1
Gerrit-Owner: Philipp Hug <philipp(a)hug.cx>
Gerrit-Reviewer: Xiang Wang <wxjstz(a)126.com>
Gerrit-MessageType: newchange
Duncan Laurie has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31080
Change subject: vendorcode/google/chromeos: Add option for using ACPI GPIO pin
......................................................................
vendorcode/google/chromeos: Add option for using ACPI GPIO pin
This new option will have the generated Chrome OS ACPI GPIO table
provide the ACPI GPIO pin number instead of the raw GPIO number.
This is necessary if the OS uses a different numbering for GPIOs
that are reported in ACPI than the actual underlying GPIO number.
For example, if the SOC OS driver declares more pins in an ACPI GPIO
bank than there are actual pins in the hardware it will have gaps in
the number space.
This is a reworked version of 6217e9beff16d805ca833e79a2931bcdb3d02a44
which uses a new option instead of just relying on GENERIC_GPIO_LIB.
BUG=b:120686247
TEST=pass firmware_WriteProtect test on Sarien
Change-Id: I3ad5099b7f2f871c7e516988f60a54eb2a75bef7
Signed-off-by: Duncan Laurie <dlaurie(a)google.com>
---
M src/vendorcode/google/chromeos/Kconfig
M src/vendorcode/google/chromeos/acpi.c
2 files changed, 19 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/80/31080/1
diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig
index 26ee31e..2edb46f 100644
--- a/src/vendorcode/google/chromeos/Kconfig
+++ b/src/vendorcode/google/chromeos/Kconfig
@@ -89,5 +89,17 @@
on normal boot as well as resume and coreboot is only involved
in the resume piece w.r.t. the platform hierarchy.
+config CHROMEOS_ACPI_GPIO_GENERATE_PIN
+ bool
+ default n
+ depends on HAVE_ACPI_TABLES && GENERIC_GPIO_LIB
+ help
+ This option will have the generated Chrome OS ACPI GPIO table
+ provide the ACPI GPIO pin number instead of the raw GPIO number.
+ This is necessary if the OS uses a different numbering for GPIOs
+ that are reported in ACPI. For example, if the SOC declares more
+ pins in an ACPI GPIO bank than there are actual pins in the hardware
+ it will have gaps in the number space.
+
endif # CHROMEOS
endmenu
diff --git a/src/vendorcode/google/chromeos/acpi.c b/src/vendorcode/google/chromeos/acpi.c
index 6605809..849f4c3 100644
--- a/src/vendorcode/google/chromeos/acpi.c
+++ b/src/vendorcode/google/chromeos/acpi.c
@@ -15,6 +15,9 @@
#include <arch/acpigen.h>
#include "chromeos.h"
+#if IS_ENABLED(CONFIG_CHROMEOS_ACPI_GPIO_GENERATE_PIN)
+#include <gpio.h>
+#endif
void chromeos_acpi_gpio_generate(const struct cros_gpio *gpios, size_t num)
{
@@ -28,7 +31,11 @@
acpigen_write_package(4);
acpigen_write_integer(gpios[i].type);
acpigen_write_integer(gpios[i].polarity);
+#if IS_ENABLED(CONFIG_CHROMEOS_ACPI_GPIO_GENERATE_PIN)
+ acpigen_write_integer(gpio_acpi_pin(gpios[i].gpio_num));
+#else
acpigen_write_integer(gpios[i].gpio_num);
+#endif
acpigen_write_string(gpios[i].device);
acpigen_pop_len();
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/31080
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I3ad5099b7f2f871c7e516988f60a54eb2a75bef7
Gerrit-Change-Number: 31080
Gerrit-PatchSet: 1
Gerrit-Owner: Duncan Laurie <dlaurie(a)chromium.org>
Gerrit-MessageType: newchange
Kyösti Mälkki has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30762
Change subject: arch/x86: Remove weak tsc_freq_mhz() implementation
......................................................................
arch/x86: Remove weak tsc_freq_mhz() implementation
Build with TSC_CONSTANT_RATE must fail when this function
is not implemented for the platform. Weak implementation
causes division by zero in timer_monotonic_get() and
turns udelay() into no delay.
Change-Id: Id3b105ea3aac37cd0cba18ce2fb06d87a055486f
Signed-off-by: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
---
M src/arch/x86/timestamp.c
1 file changed, 3 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/62/30762/1
diff --git a/src/arch/x86/timestamp.c b/src/arch/x86/timestamp.c
index 928d7d7..cbc7bac 100644
--- a/src/arch/x86/timestamp.c
+++ b/src/arch/x86/timestamp.c
@@ -21,15 +21,10 @@
return rdtscll();
}
-unsigned long __weak tsc_freq_mhz(void)
-{
- /* Default to not knowing TSC frequency. cbmem will have to fallback
- * on trying to determine it in userspace. */
- return 0;
-}
-
int timestamp_tick_freq_mhz(void)
{
/* Chipsets that have a constant TSC provide this value correctly. */
- return tsc_freq_mhz();
+ if (IS_ENABLED(CONFIG_TSC_CONSTANT_RATE))
+ return tsc_freq_mhz();
+ return 0;
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/30762
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Id3b105ea3aac37cd0cba18ce2fb06d87a055486f
Gerrit-Change-Number: 30762
Gerrit-PatchSet: 1
Gerrit-Owner: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
Gerrit-MessageType: newchange
Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31159
Change subject: soc/amd/stoneyridge: Add generic PM1 register clear function
......................................................................
soc/amd/stoneyridge: Add generic PM1 register clear function
Convert vboot_platform_prepare_reboot() to call a function in
soc//stoneyridge. A subsequent patch will add another call to
the new function, and this change removes any inference of a
dependency on vboot.
BUG=b:122725586
Change-Id: I634fcd030e206c790bda697a3dbef4e8cc21b3a8
Signed-off-by: Marshall Dawson <marshalldawson3rd(a)gmail.com>
---
M src/soc/amd/stoneyridge/include/soc/southbridge.h
M src/soc/amd/stoneyridge/pmutil.c
2 files changed, 14 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/59/31159/1
diff --git a/src/soc/amd/stoneyridge/include/soc/southbridge.h b/src/soc/amd/stoneyridge/include/soc/southbridge.h
index 1652bbc..3ae6b4a 100644
--- a/src/soc/amd/stoneyridge/include/soc/southbridge.h
+++ b/src/soc/amd/stoneyridge/include/soc/southbridge.h
@@ -604,4 +604,10 @@
/* Initialize all the i2c buses that are not marked with early init. */
void i2c_soc_init(void);
+/*
+ * If a system reset is about to be requested, modify the PM1 register so it
+ * will never be misinterpreted as an S3 resume.
+ */
+void set_pm1cnt_s5(void);
+
#endif /* __STONEYRIDGE_H__ */
diff --git a/src/soc/amd/stoneyridge/pmutil.c b/src/soc/amd/stoneyridge/pmutil.c
index d2b3ac7..bfb5f42 100644
--- a/src/soc/amd/stoneyridge/pmutil.c
+++ b/src/soc/amd/stoneyridge/pmutil.c
@@ -34,9 +34,9 @@
return acpi_sleep_from_pm1(pm_cnt) == ACPI_S3;
}
-/* If vboot requests a system reset, modify the PM1 register so it will never be
- * misinterpreted as an S3 resume. */
-void vboot_platform_prepare_reboot(void)
+/* If a system reset is about to be requested, modify the PM1 register so it
+ * will never be misinterpreted as an S3 resume. */
+void set_pm1cnt_s5(void)
{
uint16_t pm1;
@@ -45,3 +45,8 @@
pm1 |= SLP_TYP_S5 << SLP_TYP_SHIFT;
acpi_write16(MMIO_ACPI_PM1_CNT_BLK, pm1);
}
+
+void vboot_platform_prepare_reboot(void)
+{
+ set_pm1cnt_s5();
+}
--
To view, visit https://review.coreboot.org/c/coreboot/+/31159
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I634fcd030e206c790bda697a3dbef4e8cc21b3a8
Gerrit-Change-Number: 31159
Gerrit-PatchSet: 1
Gerrit-Owner: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Gerrit-MessageType: newchange
Aaron Durbin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31181
Change subject: cbmem: use aligned_memcpy for reading cbmem address information
......................................................................
cbmem: use aligned_memcpy for reading cbmem address information
The coreboot table entry containing the memory entries can have
fields unnaturally aligned in memory. Therefore one needs to perform
an aligned_memcpy() so that it doesn't cause faults on certain
architectures that assume naturally aligned accesses.
chromium:925961
Change-Id: I28365b204962ac89d65d046076d862b6f9374c06
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
M util/cbmem/cbmem.c
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/81/31181/1
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index 8e73d9c..fc2dcdc 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -302,7 +302,7 @@
continue;
debug(" LB_MEM_TABLE found.\n");
/* The last one found is CBMEM */
- cbmem = mem->map[i];
+ aligned_memcpy(&cbmem, &mem->map[i], sizeof(cbmem));
}
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/31181
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I28365b204962ac89d65d046076d862b6f9374c06
Gerrit-Change-Number: 31181
Gerrit-PatchSet: 1
Gerrit-Owner: Aaron Durbin <adurbin(a)chromium.org>
Gerrit-MessageType: newchange