* [kvm-unit-tests PATCH v2 0/8] riscv: ACPI boot and BRS-I SBI tests
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
This series lets RISC-V kvm-unit-tests boot on BRS-I platforms that
describe the system with UEFI + ACPI instead of a device tree, and adds
a first unit test for the SBI rules in the RISC-V Boot and Runtime
Services specification [1].
The RISC-V port currently assumes a DT for CPU bring-up, timer
frequency, ISA-string parsing and console setup. BRS-I firmware
typically does not provide a usable DT, and often has no MMIO UART
either. Without these changes the existing tests abort in setup before
they can exercise SBI.
Patches 1-4 teach the RISC-V library to initialize from ACPI when a DT
is absent:
- locate the ACPI 2.0 RSDP via the EFI configuration table
- parse MADT RINTC entries for hart / CPU bring-up
- read the timebase frequency from RHCT
- parse the ISA string from RHCT Hart Info nodes (match by ACPI UID)
Patch 5 prefers the SBI DBCN console when available and falls back to
the UART path otherwise, so ACPI guests without an MMIO UART can still
print. Patch 6 drops the early exit in the EFI runner that previously
rejected EFI_USE_ACPI=y.
Patch 7 moves isa_init() into cpu_init() so that every hart's ISA
extensions are parsed once the CPU list is known, rather than only for
the hart that first reaches thread_info_init().
Patch 8 adds riscv-brs, a unit test that checks the SBI requirements
from the BRS specification (version, HSM, TIME/Sstc, IPI/IMSIC,
RFENCE/IMSIC, PMU/Sscsrind+Ssccfg, and DBCN when SPCR type is 0x15).
v2 changes:
- Address review comments from Andrew Jones
- Prefer SBI DBCN with UART fallback instead of making SBI console
exclusive (patch 5)
- Initialize ISA extensions for all harts in cpu_init (new patch 7)
- Check Ssaia + S-level IMSIC presence for the IPI/RFENCE skip
conditions, and note the M-mode extension limitation for PMU
Tested with QEMU virt:
EFI_USE_ACPI=y EFI_UEFI=/path/to/RISCV_VIRT_CODE.fd \
./riscv/efi/run riscv/riscv-brs.efi
[1] https://github.com/riscv-non-isa/riscv-brs
Xiang W (8):
riscv: Initialize the ACPI RSDP from the EFI system table
riscv: Add ACPI support for CPU initialization
riscv: Add ACPI support for timer frequency discovery
riscv: Add ACPI support for ISA string discovery
riscv: Prefer SBI DBCN console with UART fallback
riscv: efi: Allow ACPI boots
riscv: initialize ISA extensions for all harts in cpu_init
riscv: Add BRS SBI requirement tests
lib/acpi.h | 64 ++++++++-
lib/riscv/asm/isa.h | 3 +
lib/riscv/asm/processor.h | 1 +
lib/riscv/asm/sbi.h | 2 +
lib/riscv/io.c | 41 +++---
lib/riscv/isa.c | 93 +++++++++++--
lib/riscv/processor.c | 1 -
lib/riscv/setup.c | 59 +++++++++
lib/riscv/timer.c | 38 ++++--
riscv/Makefile | 1 +
riscv/efi/run | 5 -
riscv/riscv-brs.c | 265 ++++++++++++++++++++++++++++++++++++++
riscv/unittests.cfg | 4 +
13 files changed, 532 insertions(+), 45 deletions(-)
create mode 100644 riscv/riscv-brs.c
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 0/8] riscv: ACPI boot and BRS-I SBI tests
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
This series lets RISC-V kvm-unit-tests boot on BRS-I platforms that
describe the system with UEFI + ACPI instead of a device tree, and adds
a first unit test for the SBI rules in the RISC-V Boot and Runtime
Services specification [1].
The RISC-V port currently assumes a DT for CPU bring-up, timer
frequency, ISA-string parsing and console setup. BRS-I firmware
typically does not provide a usable DT, and often has no MMIO UART
either. Without these changes the existing tests abort in setup before
they can exercise SBI.
Patches 1-4 teach the RISC-V library to initialize from ACPI when a DT
is absent:
- locate the ACPI 2.0 RSDP via the EFI configuration table
- parse MADT RINTC entries for hart / CPU bring-up
- read the timebase frequency from RHCT
- parse the ISA string from RHCT Hart Info nodes (match by ACPI UID)
Patch 5 prefers the SBI DBCN console when available and falls back to
the UART path otherwise, so ACPI guests without an MMIO UART can still
print. Patch 6 drops the early exit in the EFI runner that previously
rejected EFI_USE_ACPI=y.
Patch 7 moves isa_init() into cpu_init() so that every hart's ISA
extensions are parsed once the CPU list is known, rather than only for
the hart that first reaches thread_info_init().
Patch 8 adds riscv-brs, a unit test that checks the SBI requirements
from the BRS specification (version, HSM, TIME/Sstc, IPI/IMSIC,
RFENCE/IMSIC, PMU/Sscsrind+Ssccfg, and DBCN when SPCR type is 0x15).
v2 changes:
- Address review comments from Andrew Jones
- Prefer SBI DBCN with UART fallback instead of making SBI console
exclusive (patch 5)
- Initialize ISA extensions for all harts in cpu_init (new patch 7)
- Check Ssaia + S-level IMSIC presence for the IPI/RFENCE skip
conditions, and note the M-mode extension limitation for PMU
Tested with QEMU virt:
EFI_USE_ACPI=y EFI_UEFI=/path/to/RISCV_VIRT_CODE.fd \
./riscv/efi/run riscv/riscv-brs.efi
[1] https://github.com/riscv-non-isa/riscv-brs
Xiang W (8):
riscv: Initialize the ACPI RSDP from the EFI system table
riscv: Add ACPI support for CPU initialization
riscv: Add ACPI support for timer frequency discovery
riscv: Add ACPI support for ISA string discovery
riscv: Prefer SBI DBCN console with UART fallback
riscv: efi: Allow ACPI boots
riscv: initialize ISA extensions for all harts in cpu_init
riscv: Add BRS SBI requirement tests
lib/acpi.h | 64 ++++++++-
lib/riscv/asm/isa.h | 3 +
lib/riscv/asm/processor.h | 1 +
lib/riscv/asm/sbi.h | 2 +
lib/riscv/io.c | 41 +++---
lib/riscv/isa.c | 93 +++++++++++--
lib/riscv/processor.c | 1 -
lib/riscv/setup.c | 59 +++++++++
lib/riscv/timer.c | 38 ++++--
riscv/Makefile | 1 +
riscv/efi/run | 5 -
riscv/riscv-brs.c | 265 ++++++++++++++++++++++++++++++++++++++
riscv/unittests.cfg | 4 +
13 files changed, 532 insertions(+), 45 deletions(-)
create mode 100644 riscv/riscv-brs.c
--
2.47.3
^ permalink raw reply [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 1/8] riscv: Initialize the ACPI RSDP from the EFI system table
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
On EFI boots without a DT, ACPI table lookup needs a valid RSDP.
Fetch the ACPI 2.0 table from the EFI configuration table and
register it with set_efi_rsdp() before cpu_init() and
timer_get_frequency().
The RSDP lives in EFI_ACPI_RECLAIM_MEMORY, which the RISC-V
allocator does not reuse, so there is no need to copy it aside.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/setup.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index a30aa0c4..8c22120d 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -226,10 +226,31 @@ void setup(const void *fdt, phys_addr_t freemem_start)
#ifdef CONFIG_EFI
#include <efi.h>
+#include <acpi.h>
extern unsigned long exception_vectors;
extern unsigned long boot_hartid;
+static efi_status_t setup_rsdp(efi_bootinfo_t *efi_bootinfo __unused)
+{
+ efi_status_t status;
+ struct acpi_table_rsdp *rsdp;
+
+ /*
+ * RSDP resides in an EFI_ACPI_RECLAIM_MEMORY region, which is not used
+ * by kvm-unit-tests RISC-V memory allocator. So it is not necessary to
+ * copy the data structure to another memory region to prevent
+ * unintentional overwrite.
+ */
+ status = efi_get_system_config_table(ACPI_20_TABLE_GUID, (void **)&rsdp);
+ if (status != EFI_SUCCESS)
+ return status;
+
+ set_efi_rsdp(rsdp);
+
+ return EFI_SUCCESS;
+}
+
static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
{
struct mem_region *freemem_mr = NULL, *code, *data;
@@ -273,6 +294,14 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
return status;
}
+ if (!dt_available()) {
+ status = setup_rsdp(efi_bootinfo);
+ if (status != EFI_SUCCESS) {
+ printf("Cannot find RSDP in EFI system table\n");
+ return status;
+ }
+ }
+
cpu_init();
timer_get_frequency();
thread_info_init();
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 1/8] riscv: Initialize the ACPI RSDP from the EFI system table
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
On EFI boots without a DT, ACPI table lookup needs a valid RSDP.
Fetch the ACPI 2.0 table from the EFI configuration table and
register it with set_efi_rsdp() before cpu_init() and
timer_get_frequency().
The RSDP lives in EFI_ACPI_RECLAIM_MEMORY, which the RISC-V
allocator does not reuse, so there is no need to copy it aside.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/setup.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index a30aa0c4..8c22120d 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -226,10 +226,31 @@ void setup(const void *fdt, phys_addr_t freemem_start)
#ifdef CONFIG_EFI
#include <efi.h>
+#include <acpi.h>
extern unsigned long exception_vectors;
extern unsigned long boot_hartid;
+static efi_status_t setup_rsdp(efi_bootinfo_t *efi_bootinfo __unused)
+{
+ efi_status_t status;
+ struct acpi_table_rsdp *rsdp;
+
+ /*
+ * RSDP resides in an EFI_ACPI_RECLAIM_MEMORY region, which is not used
+ * by kvm-unit-tests RISC-V memory allocator. So it is not necessary to
+ * copy the data structure to another memory region to prevent
+ * unintentional overwrite.
+ */
+ status = efi_get_system_config_table(ACPI_20_TABLE_GUID, (void **)&rsdp);
+ if (status != EFI_SUCCESS)
+ return status;
+
+ set_efi_rsdp(rsdp);
+
+ return EFI_SUCCESS;
+}
+
static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
{
struct mem_region *freemem_mr = NULL, *code, *data;
@@ -273,6 +294,14 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
return status;
}
+ if (!dt_available()) {
+ status = setup_rsdp(efi_bootinfo);
+ if (status != EFI_SUCCESS) {
+ printf("Cannot find RSDP in EFI system table\n");
+ return status;
+ }
+ }
+
cpu_init();
timer_get_frequency();
thread_info_init();
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 2/8] riscv: Add ACPI support for CPU initialization
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
When a DT is not provided, discover harts from the MADT RINTC
subtables (ACPI 6.6 type 24) instead of aborting in cpu_init_acpi().
Parse each RINTC entry for hart_id and ACPI UID, record them in
thread_info, and mark the CPU present only if it is Enabled in
the RINTC flags and SBI reports the hart as available.
Also add the RINTC MADT structure and the MADT types introduced
after GENERIC_TRANSLATOR so the RISC-V interrupt controller
entries can be identified.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/acpi.h | 27 ++++++++++++++++++++++++++-
lib/riscv/asm/processor.h | 1 +
lib/riscv/setup.c | 28 +++++++++++++++++++++++++++-
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/lib/acpi.h b/lib/acpi.h
index a62cd3a9..f6c92d28 100644
--- a/lib/acpi.h
+++ b/lib/acpi.h
@@ -226,6 +226,19 @@ struct acpi_madt_generic_translator {
u32 reserved2;
};
+/* 24: RISC-V Interrupt Controller (RINTC) Structure (ACPI 6.6) */
+struct acpi_madt_rintc {
+ struct acpi_subtable_header header;
+ u8 version;
+ u8 reserved; /* reserved - must be zero */
+ u32 flags;
+ u64 hart_id;
+ u32 uid;
+ u32 ext_intc_id;
+ u64 imsic_addr;
+ u32 imsic_size;
+};
+
/* Values for MADT subtable type in struct acpi_subtable_header */
enum acpi_madt_type {
@@ -245,7 +258,19 @@ enum acpi_madt_type {
ACPI_MADT_TYPE_GENERIC_MSI_FRAME = 13,
ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR = 14,
ACPI_MADT_TYPE_GENERIC_TRANSLATOR = 15,
- ACPI_MADT_TYPE_RESERVED = 16 /* 16 and greater are reserved */
+ ACPI_MADT_TYPE_MULTIPROC_WAKEUP = 16,
+ ACPI_MADT_TYPE_CORE_PIC = 17,
+ ACPI_MADT_TYPE_LIO_PIC = 18,
+ ACPI_MADT_TYPE_HT_PIC = 19,
+ ACPI_MADT_TYPE_EIO_PIC = 20,
+ ACPI_MADT_TYPE_MSI_PIC = 21,
+ ACPI_MADT_TYPE_BIO_PIC = 22,
+ ACPI_MADT_TYPE_LPC_PIC = 23,
+ ACPI_MADT_TYPE_RINTC = 24,
+ ACPI_MADT_TYPE_IMSIC = 25,
+ ACPI_MADT_TYPE_APLIC = 26,
+ ACPI_MADT_TYPE_PLIC = 27,
+ ACPI_MADT_TYPE_RESERVED = 28 /* 28 and greater are reserved */
};
/* MADT Local APIC flags */
diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h
index a3dab064..5a1df355 100644
--- a/lib/riscv/asm/processor.h
+++ b/lib/riscv/asm/processor.h
@@ -14,6 +14,7 @@ typedef void (*exception_fn)(struct pt_regs *);
struct thread_info {
int cpu;
unsigned long hartid;
+ unsigned long uid;
unsigned long isa[1];
unsigned long sp;
exception_fn exception_handlers[EXCEPTION_CAUSE_MAX];
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index 8c22120d..f1121573 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -48,6 +48,29 @@ uint64_t timebase_frequency;
static struct mem_region riscv_mem_regions[NR_MEM_REGIONS + 1];
+#ifdef CONFIG_EFI
+#include <acpi.h>
+
+static int cpu_set_acpi(struct acpi_subtable_header *header)
+{
+ int cpu = nr_cpus++;
+ struct acpi_madt_rintc *intc = (void *)header;
+
+ assert_msg(cpu < NR_CPUS, "Number cpus exceeds maximum supported (%d).", NR_CPUS);
+
+ cpus[cpu].cpu = cpu;
+ cpus[cpu].hartid = intc->hart_id;
+ cpus[cpu].uid = intc->uid;
+
+ if (intc->flags & ACPI_MADT_ENABLED) {
+ if (!sbi_hart_get_status(cpus[cpu].hartid).error)
+ set_cpu_present(cpu, true);
+ }
+
+ return 0;
+}
+#endif
+
static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused)
{
int cpu = nr_cpus++;
@@ -63,7 +86,11 @@ static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused)
static void cpu_init_acpi(void)
{
+#ifdef CONFIG_EFI
+ acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, cpu_set_acpi);
+#else
assert_msg(false, "ACPI not available");
+#endif
}
static void cpu_init(void)
@@ -226,7 +253,6 @@ void setup(const void *fdt, phys_addr_t freemem_start)
#ifdef CONFIG_EFI
#include <efi.h>
-#include <acpi.h>
extern unsigned long exception_vectors;
extern unsigned long boot_hartid;
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 2/8] riscv: Add ACPI support for CPU initialization
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
When a DT is not provided, discover harts from the MADT RINTC
subtables (ACPI 6.6 type 24) instead of aborting in cpu_init_acpi().
Parse each RINTC entry for hart_id and ACPI UID, record them in
thread_info, and mark the CPU present only if it is Enabled in
the RINTC flags and SBI reports the hart as available.
Also add the RINTC MADT structure and the MADT types introduced
after GENERIC_TRANSLATOR so the RISC-V interrupt controller
entries can be identified.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/acpi.h | 27 ++++++++++++++++++++++++++-
lib/riscv/asm/processor.h | 1 +
lib/riscv/setup.c | 28 +++++++++++++++++++++++++++-
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/lib/acpi.h b/lib/acpi.h
index a62cd3a9..f6c92d28 100644
--- a/lib/acpi.h
+++ b/lib/acpi.h
@@ -226,6 +226,19 @@ struct acpi_madt_generic_translator {
u32 reserved2;
};
+/* 24: RISC-V Interrupt Controller (RINTC) Structure (ACPI 6.6) */
+struct acpi_madt_rintc {
+ struct acpi_subtable_header header;
+ u8 version;
+ u8 reserved; /* reserved - must be zero */
+ u32 flags;
+ u64 hart_id;
+ u32 uid;
+ u32 ext_intc_id;
+ u64 imsic_addr;
+ u32 imsic_size;
+};
+
/* Values for MADT subtable type in struct acpi_subtable_header */
enum acpi_madt_type {
@@ -245,7 +258,19 @@ enum acpi_madt_type {
ACPI_MADT_TYPE_GENERIC_MSI_FRAME = 13,
ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR = 14,
ACPI_MADT_TYPE_GENERIC_TRANSLATOR = 15,
- ACPI_MADT_TYPE_RESERVED = 16 /* 16 and greater are reserved */
+ ACPI_MADT_TYPE_MULTIPROC_WAKEUP = 16,
+ ACPI_MADT_TYPE_CORE_PIC = 17,
+ ACPI_MADT_TYPE_LIO_PIC = 18,
+ ACPI_MADT_TYPE_HT_PIC = 19,
+ ACPI_MADT_TYPE_EIO_PIC = 20,
+ ACPI_MADT_TYPE_MSI_PIC = 21,
+ ACPI_MADT_TYPE_BIO_PIC = 22,
+ ACPI_MADT_TYPE_LPC_PIC = 23,
+ ACPI_MADT_TYPE_RINTC = 24,
+ ACPI_MADT_TYPE_IMSIC = 25,
+ ACPI_MADT_TYPE_APLIC = 26,
+ ACPI_MADT_TYPE_PLIC = 27,
+ ACPI_MADT_TYPE_RESERVED = 28 /* 28 and greater are reserved */
};
/* MADT Local APIC flags */
diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h
index a3dab064..5a1df355 100644
--- a/lib/riscv/asm/processor.h
+++ b/lib/riscv/asm/processor.h
@@ -14,6 +14,7 @@ typedef void (*exception_fn)(struct pt_regs *);
struct thread_info {
int cpu;
unsigned long hartid;
+ unsigned long uid;
unsigned long isa[1];
unsigned long sp;
exception_fn exception_handlers[EXCEPTION_CAUSE_MAX];
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index 8c22120d..f1121573 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -48,6 +48,29 @@ uint64_t timebase_frequency;
static struct mem_region riscv_mem_regions[NR_MEM_REGIONS + 1];
+#ifdef CONFIG_EFI
+#include <acpi.h>
+
+static int cpu_set_acpi(struct acpi_subtable_header *header)
+{
+ int cpu = nr_cpus++;
+ struct acpi_madt_rintc *intc = (void *)header;
+
+ assert_msg(cpu < NR_CPUS, "Number cpus exceeds maximum supported (%d).", NR_CPUS);
+
+ cpus[cpu].cpu = cpu;
+ cpus[cpu].hartid = intc->hart_id;
+ cpus[cpu].uid = intc->uid;
+
+ if (intc->flags & ACPI_MADT_ENABLED) {
+ if (!sbi_hart_get_status(cpus[cpu].hartid).error)
+ set_cpu_present(cpu, true);
+ }
+
+ return 0;
+}
+#endif
+
static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused)
{
int cpu = nr_cpus++;
@@ -63,7 +86,11 @@ static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused)
static void cpu_init_acpi(void)
{
+#ifdef CONFIG_EFI
+ acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, cpu_set_acpi);
+#else
assert_msg(false, "ACPI not available");
+#endif
}
static void cpu_init(void)
@@ -226,7 +253,6 @@ void setup(const void *fdt, phys_addr_t freemem_start)
#ifdef CONFIG_EFI
#include <efi.h>
-#include <acpi.h>
extern unsigned long exception_vectors;
extern unsigned long boot_hartid;
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 3/8] riscv: Add ACPI support for timer frequency discovery
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
When a DT is not provided, read the system time base frequency from
the RHCT instead of aborting in timer_get_frequency().
RHCT Time Base Frequency is the ACPI equivalent of the DT
/cpus timebase-frequency property and is the same for all harts.
Keep DT as the preferred path when one is available.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/acpi.h | 9 +++++++++
lib/riscv/timer.c | 38 ++++++++++++++++++++++++++------------
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/lib/acpi.h b/lib/acpi.h
index f6c92d28..0589669b 100644
--- a/lib/acpi.h
+++ b/lib/acpi.h
@@ -20,6 +20,7 @@
#define MADT_SIGNATURE ACPI_SIGNATURE('A','P','I','C')
#define SPCR_SIGNATURE ACPI_SIGNATURE('S','P','C','R')
#define GTDT_SIGNATURE ACPI_SIGNATURE('G','T','D','T')
+#define RHCT_SIGNATURE ACPI_SIGNATURE('R','H','C','T')
#define ACPI_SIGNATURE_8BYTE(c1, c2, c3, c4, c5, c6, c7, c8) \
(((uint64_t)(ACPI_SIGNATURE(c1, c2, c3, c4))) | \
@@ -325,6 +326,14 @@ struct acpi_table_gtdt {
u32 virtual_el2_timer_flags;
};
+struct acpi_table_rhct {
+ ACPI_TABLE_HEADER_DEF
+ u32 flags;
+ u64 time_base_freq;
+ u32 node_count;
+ u32 node_offset;
+};
+
/* Reset to default packing */
#pragma pack()
diff --git a/lib/riscv/timer.c b/lib/riscv/timer.c
index 18063b7e..a3af7e2b 100644
--- a/lib/riscv/timer.c
+++ b/lib/riscv/timer.c
@@ -13,24 +13,38 @@
#include <asm/smp.h>
#include <asm/timer.h>
+#ifdef CONFIG_EFI
+#include <acpi.h>
+#endif
+
void timer_get_frequency(void)
{
- const struct fdt_property *prop;
- u32 *data;
- int cpus, len;
-
- assert_msg(dt_available(), "ACPI not yet supported");
+ if (dt_available()) {
+ const struct fdt_property *prop;
+ const void *fdt;
+ u32 *data;
+ int cpus, len;
- const void *fdt = dt_fdt();
+ fdt = dt_fdt();
+ cpus = fdt_path_offset(fdt, "/cpus");
+ assert(cpus >= 0);
- cpus = fdt_path_offset(fdt, "/cpus");
- assert(cpus >= 0);
+ prop = fdt_get_property(fdt, cpus, "timebase-frequency", &len);
+ assert(prop != NULL && len == 4);
- prop = fdt_get_property(fdt, cpus, "timebase-frequency", &len);
- assert(prop != NULL && len == 4);
+ data = (u32 *)prop->data;
+ timebase_frequency = fdt32_to_cpu(*data);
+ } else {
+#ifdef CONFIG_EFI
+ struct acpi_table_rhct *rhct;
- data = (u32 *)prop->data;
- timebase_frequency = fdt32_to_cpu(*data);
+ rhct = find_acpi_table_addr(RHCT_SIGNATURE);
+ assert_msg(rhct, "Cannot find ACPI RHCT");
+ timebase_frequency = rhct->time_base_freq;
+#else
+ assert_msg(false, "ACPI not available");
+#endif
+ }
}
void timer_start(unsigned long duration_us)
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 3/8] riscv: Add ACPI support for timer frequency discovery
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
When a DT is not provided, read the system time base frequency from
the RHCT instead of aborting in timer_get_frequency().
RHCT Time Base Frequency is the ACPI equivalent of the DT
/cpus timebase-frequency property and is the same for all harts.
Keep DT as the preferred path when one is available.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/acpi.h | 9 +++++++++
lib/riscv/timer.c | 38 ++++++++++++++++++++++++++------------
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/lib/acpi.h b/lib/acpi.h
index f6c92d28..0589669b 100644
--- a/lib/acpi.h
+++ b/lib/acpi.h
@@ -20,6 +20,7 @@
#define MADT_SIGNATURE ACPI_SIGNATURE('A','P','I','C')
#define SPCR_SIGNATURE ACPI_SIGNATURE('S','P','C','R')
#define GTDT_SIGNATURE ACPI_SIGNATURE('G','T','D','T')
+#define RHCT_SIGNATURE ACPI_SIGNATURE('R','H','C','T')
#define ACPI_SIGNATURE_8BYTE(c1, c2, c3, c4, c5, c6, c7, c8) \
(((uint64_t)(ACPI_SIGNATURE(c1, c2, c3, c4))) | \
@@ -325,6 +326,14 @@ struct acpi_table_gtdt {
u32 virtual_el2_timer_flags;
};
+struct acpi_table_rhct {
+ ACPI_TABLE_HEADER_DEF
+ u32 flags;
+ u64 time_base_freq;
+ u32 node_count;
+ u32 node_offset;
+};
+
/* Reset to default packing */
#pragma pack()
diff --git a/lib/riscv/timer.c b/lib/riscv/timer.c
index 18063b7e..a3af7e2b 100644
--- a/lib/riscv/timer.c
+++ b/lib/riscv/timer.c
@@ -13,24 +13,38 @@
#include <asm/smp.h>
#include <asm/timer.h>
+#ifdef CONFIG_EFI
+#include <acpi.h>
+#endif
+
void timer_get_frequency(void)
{
- const struct fdt_property *prop;
- u32 *data;
- int cpus, len;
-
- assert_msg(dt_available(), "ACPI not yet supported");
+ if (dt_available()) {
+ const struct fdt_property *prop;
+ const void *fdt;
+ u32 *data;
+ int cpus, len;
- const void *fdt = dt_fdt();
+ fdt = dt_fdt();
+ cpus = fdt_path_offset(fdt, "/cpus");
+ assert(cpus >= 0);
- cpus = fdt_path_offset(fdt, "/cpus");
- assert(cpus >= 0);
+ prop = fdt_get_property(fdt, cpus, "timebase-frequency", &len);
+ assert(prop != NULL && len == 4);
- prop = fdt_get_property(fdt, cpus, "timebase-frequency", &len);
- assert(prop != NULL && len == 4);
+ data = (u32 *)prop->data;
+ timebase_frequency = fdt32_to_cpu(*data);
+ } else {
+#ifdef CONFIG_EFI
+ struct acpi_table_rhct *rhct;
- data = (u32 *)prop->data;
- timebase_frequency = fdt32_to_cpu(*data);
+ rhct = find_acpi_table_addr(RHCT_SIGNATURE);
+ assert_msg(rhct, "Cannot find ACPI RHCT");
+ timebase_frequency = rhct->time_base_freq;
+#else
+ assert_msg(false, "ACPI not available");
+#endif
+ }
}
void timer_start(unsigned long duration_us)
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
When a DT is not provided, walk the RHCT Hart Info nodes and parse
the referenced ISA String node instead of aborting in isa_init()
and cpu_has_extension_name().
Match the current hart by ACPI UID (DT still matches by hartid)
and feed the ISA string into the existing isa_parse() helper so
extension detection is shared by both firmware descriptions.
Rename isa_info.hartid to isa_info.id so the same iterator state
can hold either identifier.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/acpi.h | 28 +++++++++++++++++
lib/riscv/isa.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 102 insertions(+), 7 deletions(-)
diff --git a/lib/acpi.h b/lib/acpi.h
index 0589669b..d5e238a9 100644
--- a/lib/acpi.h
+++ b/lib/acpi.h
@@ -334,6 +334,34 @@ struct acpi_table_rhct {
u32 node_offset;
};
+#define ACPI_RHCT_NODE_HEADER_DEF \
+ u16 type; \
+ u16 length; \
+ u16 revision; \
+
+struct acpi_rhct_node {
+ ACPI_RHCT_NODE_HEADER_DEF
+ char data[];
+};
+
+enum acpi_rhct_node_type {
+ ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0,
+ ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF
+};
+
+struct acpi_rhct_node_isa_string {
+ ACPI_RHCT_NODE_HEADER_DEF
+ u16 isa_length;
+ char isa[];
+};
+
+struct acpi_rhct_node_hart_info {
+ ACPI_RHCT_NODE_HEADER_DEF
+ u16 num_offsets;
+ u32 uid;
+ u32 nodes[];
+};
+
/* Reset to default packing */
#pragma pack()
diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
index bc1c9c72..91c7302c 100644
--- a/lib/riscv/isa.c
+++ b/lib/riscv/isa.c
@@ -12,7 +12,7 @@
typedef void (*isa_func_t)(const char *, int, void *);
struct isa_info {
- unsigned long hartid;
+ unsigned long id;
isa_func_t func;
void *data;
};
@@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
const struct fdt_property *prop;
int len;
- if (hartid != info->hartid)
+ if (hartid != info->id)
return;
prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
@@ -83,32 +83,92 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
isa_parse(prop->data, len, info);
}
-static void isa_init_acpi(void)
+#ifdef CONFIG_EFI
+#include <acpi.h>
+
+static void isa_parse_acpi(struct acpi_table_rhct *rhct,
+ struct acpi_rhct_node_hart_info *hart_info, void *data)
{
- assert_msg(false, "ACPI not available");
+ u32 offset;
+ struct acpi_rhct_node *node;
+ struct acpi_rhct_node_isa_string *isa_string;
+ struct isa_info *info = (struct isa_info *)data;
+
+ if (hart_info->uid != info->id)
+ return;
+
+ for (int i = 0; i < hart_info->num_offsets; i++) {
+ offset = hart_info->nodes[i];
+ if (offset >= rhct->length)
+ break;
+ node = (void *)rhct + offset;
+ if (node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) {
+ isa_string = (void *) node;
+ isa_parse(isa_string->isa, isa_string->isa_length, info);
+ }
+ }
+}
+
+static int acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
+ struct acpi_rhct_node_hart_info *,
+ void *), void *data)
+{
+ u32 offset;
+ struct acpi_table_rhct *rhct;
+ struct acpi_rhct_node *node;
+ struct acpi_rhct_node_hart_info *hart_info;
+
+ rhct = find_acpi_table_addr(RHCT_SIGNATURE);
+ if (rhct == NULL)
+ return -1;
+
+ offset = rhct->node_offset;
+ for (int i = 0; i < rhct->node_count; i++) {
+ if (offset >= rhct->length)
+ return -1;
+
+ node = (void *)rhct + offset;
+ if (node->length < sizeof(*node))
+ return -1;
+
+ if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) {
+ hart_info = (void *)node;
+ func(rhct, hart_info, data);
+ }
+
+ offset += node->length;
+ }
+
+ return 0;
}
+#endif
void isa_init(struct thread_info *ti)
{
struct isa_info info = {
- .hartid = ti->hartid,
.func = isa_bit,
.data = ti,
};
int ret;
if (dt_available()) {
+ info.id = ti->hartid;
ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
assert(ret == 0);
} else {
- isa_init_acpi();
+#ifdef CONFIG_EFI
+ info.id = ti->uid;
+ ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
+ assert(ret == 0);
+#else
+ assert_msg(false, "ACPI not available");
+#endif
}
}
bool cpu_has_extension_name(int cpu, const char *ext)
{
struct isa_info info = {
- .hartid = cpus[cpu].hartid,
.func = isa_name,
.data = &(struct isa_check){ .ext = ext, },
};
@@ -116,10 +176,17 @@ bool cpu_has_extension_name(int cpu, const char *ext)
int ret;
if (dt_available()) {
+ info.id = cpus[cpu].hartid;
ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
assert(ret == 0);
} else {
+#ifdef CONFIG_EFI
+ info.id = cpus[cpu].uid;
+ ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
+ assert(ret == 0);
+#else
assert_msg(false, "ACPI not available");
+#endif
}
return check->found;
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
When a DT is not provided, walk the RHCT Hart Info nodes and parse
the referenced ISA String node instead of aborting in isa_init()
and cpu_has_extension_name().
Match the current hart by ACPI UID (DT still matches by hartid)
and feed the ISA string into the existing isa_parse() helper so
extension detection is shared by both firmware descriptions.
Rename isa_info.hartid to isa_info.id so the same iterator state
can hold either identifier.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/acpi.h | 28 +++++++++++++++++
lib/riscv/isa.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 102 insertions(+), 7 deletions(-)
diff --git a/lib/acpi.h b/lib/acpi.h
index 0589669b..d5e238a9 100644
--- a/lib/acpi.h
+++ b/lib/acpi.h
@@ -334,6 +334,34 @@ struct acpi_table_rhct {
u32 node_offset;
};
+#define ACPI_RHCT_NODE_HEADER_DEF \
+ u16 type; \
+ u16 length; \
+ u16 revision; \
+
+struct acpi_rhct_node {
+ ACPI_RHCT_NODE_HEADER_DEF
+ char data[];
+};
+
+enum acpi_rhct_node_type {
+ ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0,
+ ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF
+};
+
+struct acpi_rhct_node_isa_string {
+ ACPI_RHCT_NODE_HEADER_DEF
+ u16 isa_length;
+ char isa[];
+};
+
+struct acpi_rhct_node_hart_info {
+ ACPI_RHCT_NODE_HEADER_DEF
+ u16 num_offsets;
+ u32 uid;
+ u32 nodes[];
+};
+
/* Reset to default packing */
#pragma pack()
diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
index bc1c9c72..91c7302c 100644
--- a/lib/riscv/isa.c
+++ b/lib/riscv/isa.c
@@ -12,7 +12,7 @@
typedef void (*isa_func_t)(const char *, int, void *);
struct isa_info {
- unsigned long hartid;
+ unsigned long id;
isa_func_t func;
void *data;
};
@@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
const struct fdt_property *prop;
int len;
- if (hartid != info->hartid)
+ if (hartid != info->id)
return;
prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
@@ -83,32 +83,92 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
isa_parse(prop->data, len, info);
}
-static void isa_init_acpi(void)
+#ifdef CONFIG_EFI
+#include <acpi.h>
+
+static void isa_parse_acpi(struct acpi_table_rhct *rhct,
+ struct acpi_rhct_node_hart_info *hart_info, void *data)
{
- assert_msg(false, "ACPI not available");
+ u32 offset;
+ struct acpi_rhct_node *node;
+ struct acpi_rhct_node_isa_string *isa_string;
+ struct isa_info *info = (struct isa_info *)data;
+
+ if (hart_info->uid != info->id)
+ return;
+
+ for (int i = 0; i < hart_info->num_offsets; i++) {
+ offset = hart_info->nodes[i];
+ if (offset >= rhct->length)
+ break;
+ node = (void *)rhct + offset;
+ if (node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) {
+ isa_string = (void *) node;
+ isa_parse(isa_string->isa, isa_string->isa_length, info);
+ }
+ }
+}
+
+static int acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
+ struct acpi_rhct_node_hart_info *,
+ void *), void *data)
+{
+ u32 offset;
+ struct acpi_table_rhct *rhct;
+ struct acpi_rhct_node *node;
+ struct acpi_rhct_node_hart_info *hart_info;
+
+ rhct = find_acpi_table_addr(RHCT_SIGNATURE);
+ if (rhct == NULL)
+ return -1;
+
+ offset = rhct->node_offset;
+ for (int i = 0; i < rhct->node_count; i++) {
+ if (offset >= rhct->length)
+ return -1;
+
+ node = (void *)rhct + offset;
+ if (node->length < sizeof(*node))
+ return -1;
+
+ if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) {
+ hart_info = (void *)node;
+ func(rhct, hart_info, data);
+ }
+
+ offset += node->length;
+ }
+
+ return 0;
}
+#endif
void isa_init(struct thread_info *ti)
{
struct isa_info info = {
- .hartid = ti->hartid,
.func = isa_bit,
.data = ti,
};
int ret;
if (dt_available()) {
+ info.id = ti->hartid;
ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
assert(ret == 0);
} else {
- isa_init_acpi();
+#ifdef CONFIG_EFI
+ info.id = ti->uid;
+ ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
+ assert(ret == 0);
+#else
+ assert_msg(false, "ACPI not available");
+#endif
}
}
bool cpu_has_extension_name(int cpu, const char *ext)
{
struct isa_info info = {
- .hartid = cpus[cpu].hartid,
.func = isa_name,
.data = &(struct isa_check){ .ext = ext, },
};
@@ -116,10 +176,17 @@ bool cpu_has_extension_name(int cpu, const char *ext)
int ret;
if (dt_available()) {
+ info.id = cpus[cpu].hartid;
ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
assert(ret == 0);
} else {
+#ifdef CONFIG_EFI
+ info.id = cpus[cpu].uid;
+ ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
+ assert(ret == 0);
+#else
assert_msg(false, "ACPI not available");
+#endif
}
return check->found;
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 5/8] riscv: Prefer SBI DBCN console with UART fallback
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
CONFIG_SBI_CONSOLE already routes output through SBI DBCN, but console
setup still always went through the UART init path. uart0_init_fdt()
could skip a missing UART while uart0_init_acpi() aborted, so EFI/ACPI
guests without a described MMIO UART could not print.
Probe SBI_EXT_DBCN first. When it is available, use
SBI_EXT_DBCN_CONSOLE_WRITE and skip UART setup. Otherwise fall back to
the existing FDT or ACPI UART path. This keeps a UART fallback (as
required by the server platform spec on ACPI systems) while allowing
pure SBI-console environments to boot without an MMIO UART.
Rename the lock from uart_lock to console_lock since it now protects
both console backends.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/io.c | 41 ++++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/lib/riscv/io.c b/lib/riscv/io.c
index b1163404..af38a540 100644
--- a/lib/riscv/io.c
+++ b/lib/riscv/io.c
@@ -28,7 +28,10 @@
static volatile u8 *uart0_base = UART_EARLY_BASE;
static u32 uart0_reg_width = 1;
static u32 uart0_reg_shift;
-static struct spinlock uart_lock;
+static struct spinlock console_lock;
+#ifdef CONFIG_SBI_CONSOLE
+static bool has_dbcn;
+#endif
static u32 uart0_read(u32 num)
{
@@ -71,16 +74,11 @@ static void uart0_init_fdt(void)
break;
}
-#ifdef CONFIG_SBI_CONSOLE
- uart0_base = NULL;
- return;
-#else
if (ret) {
printf("%s: Compatible uart not found in the device tree, aborting...\n",
__func__);
abort();
}
-#endif
} else {
const fdt32_t *val;
int len;
@@ -107,6 +105,12 @@ static void uart0_init_acpi(void)
void io_init(void)
{
+#ifdef CONFIG_SBI_CONSOLE
+ if (sbi_probe(SBI_EXT_DBCN)) {
+ has_dbcn = true;
+ return;
+ }
+#endif
if (dt_available())
uart0_init_fdt();
else
@@ -119,38 +123,41 @@ void io_init(void)
}
}
-void sbi_puts(const char *s);
-void sbi_puts(const char *s)
+#ifdef CONFIG_SBI_CONSOLE
+static void sbi_puts(const char *s)
{
phys_addr_t addr = virt_to_phys((void *)s);
unsigned long hi = upper_32_bits(addr);
unsigned long lo = lower_32_bits(addr);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, strlen(s), lo, hi, 0, 0, 0);
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
+#endif
-void uart0_puts(const char *s);
-void uart0_puts(const char *s)
+static void uart0_puts(const char *s)
{
assert(uart0_base);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
while (*s) {
while (!(uart0_read(UART_LSR_OFFSET) & UART_LSR_THRE))
;
uart0_write(0, *s++);
}
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
void puts(const char *s)
{
#ifdef CONFIG_SBI_CONSOLE
- sbi_puts(s);
-#else
- uart0_puts(s);
+ if (has_dbcn) {
+ sbi_puts(s);
+ return;
+ }
#endif
+
+ uart0_puts(s);
}
/*
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 5/8] riscv: Prefer SBI DBCN console with UART fallback
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
CONFIG_SBI_CONSOLE already routes output through SBI DBCN, but console
setup still always went through the UART init path. uart0_init_fdt()
could skip a missing UART while uart0_init_acpi() aborted, so EFI/ACPI
guests without a described MMIO UART could not print.
Probe SBI_EXT_DBCN first. When it is available, use
SBI_EXT_DBCN_CONSOLE_WRITE and skip UART setup. Otherwise fall back to
the existing FDT or ACPI UART path. This keeps a UART fallback (as
required by the server platform spec on ACPI systems) while allowing
pure SBI-console environments to boot without an MMIO UART.
Rename the lock from uart_lock to console_lock since it now protects
both console backends.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/io.c | 41 ++++++++++++++++++++++++-----------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/lib/riscv/io.c b/lib/riscv/io.c
index b1163404..af38a540 100644
--- a/lib/riscv/io.c
+++ b/lib/riscv/io.c
@@ -28,7 +28,10 @@
static volatile u8 *uart0_base = UART_EARLY_BASE;
static u32 uart0_reg_width = 1;
static u32 uart0_reg_shift;
-static struct spinlock uart_lock;
+static struct spinlock console_lock;
+#ifdef CONFIG_SBI_CONSOLE
+static bool has_dbcn;
+#endif
static u32 uart0_read(u32 num)
{
@@ -71,16 +74,11 @@ static void uart0_init_fdt(void)
break;
}
-#ifdef CONFIG_SBI_CONSOLE
- uart0_base = NULL;
- return;
-#else
if (ret) {
printf("%s: Compatible uart not found in the device tree, aborting...\n",
__func__);
abort();
}
-#endif
} else {
const fdt32_t *val;
int len;
@@ -107,6 +105,12 @@ static void uart0_init_acpi(void)
void io_init(void)
{
+#ifdef CONFIG_SBI_CONSOLE
+ if (sbi_probe(SBI_EXT_DBCN)) {
+ has_dbcn = true;
+ return;
+ }
+#endif
if (dt_available())
uart0_init_fdt();
else
@@ -119,38 +123,41 @@ void io_init(void)
}
}
-void sbi_puts(const char *s);
-void sbi_puts(const char *s)
+#ifdef CONFIG_SBI_CONSOLE
+static void sbi_puts(const char *s)
{
phys_addr_t addr = virt_to_phys((void *)s);
unsigned long hi = upper_32_bits(addr);
unsigned long lo = lower_32_bits(addr);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, strlen(s), lo, hi, 0, 0, 0);
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
+#endif
-void uart0_puts(const char *s);
-void uart0_puts(const char *s)
+static void uart0_puts(const char *s)
{
assert(uart0_base);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
while (*s) {
while (!(uart0_read(UART_LSR_OFFSET) & UART_LSR_THRE))
;
uart0_write(0, *s++);
}
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
void puts(const char *s)
{
#ifdef CONFIG_SBI_CONSOLE
- sbi_puts(s);
-#else
- uart0_puts(s);
+ if (has_dbcn) {
+ sbi_puts(s);
+ return;
+ }
#endif
+
+ uart0_puts(s);
}
/*
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 6/8] riscv: efi: Allow ACPI boots
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
riscv/efi/run rejected EFI_USE_ACPI=y because CPU, timer and ISA
discovery aborted without a DT. Those paths can now walk MADT and
RHCT, so drop the early exit.
The existing runner already omits -machine acpi=off when
EFI_USE_ACPI!=y. QEMU virt defaults to ACPI enabled, so no extra
acpi=on flag is required. DT boots are unchanged: they still pass
acpi=off.
Tested with:
EFI_USE_ACPI=y EFI_UEFI=/path/to/RISCV_VIRT_CODE.fd \
./riscv/efi/run riscv/riscv-brs.efi
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
riscv/efi/run | 5 -----
1 file changed, 5 deletions(-)
diff --git a/riscv/efi/run b/riscv/efi/run
index b9b75440..a53b3a2c 100755
--- a/riscv/efi/run
+++ b/riscv/efi/run
@@ -39,11 +39,6 @@ if [ ! -f "$EFI_UEFI" ]; then
exit 2
fi
-if [ "$EFI_USE_ACPI" = "y" ]; then
- echo "ACPI not available"
- exit 2
-fi
-
# Remove the TEST_CASE from $@
shift 1
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 6/8] riscv: efi: Allow ACPI boots
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
riscv/efi/run rejected EFI_USE_ACPI=y because CPU, timer and ISA
discovery aborted without a DT. Those paths can now walk MADT and
RHCT, so drop the early exit.
The existing runner already omits -machine acpi=off when
EFI_USE_ACPI!=y. QEMU virt defaults to ACPI enabled, so no extra
acpi=on flag is required. DT boots are unchanged: they still pass
acpi=off.
Tested with:
EFI_USE_ACPI=y EFI_UEFI=/path/to/RISCV_VIRT_CODE.fd \
./riscv/efi/run riscv/riscv-brs.efi
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
riscv/efi/run | 5 -----
1 file changed, 5 deletions(-)
diff --git a/riscv/efi/run b/riscv/efi/run
index b9b75440..a53b3a2c 100755
--- a/riscv/efi/run
+++ b/riscv/efi/run
@@ -39,11 +39,6 @@ if [ ! -f "$EFI_UEFI" ]; then
exit 2
fi
-if [ "$EFI_USE_ACPI" = "y" ]; then
- echo "ACPI not available"
- exit 2
-fi
-
# Remove the TEST_CASE from $@
shift 1
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
Move `isa_init()` from `thread_info_init()` to `cpu_init()`.
Previously it only ran for the current hart; now it is called for every
hart so that ISA extensions are parsed for the whole system.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/processor.c | 1 -
lib/riscv/setup.c | 4 ++++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c
index b055acc9..ddecc25e 100644
--- a/lib/riscv/processor.c
+++ b/lib/riscv/processor.c
@@ -81,7 +81,6 @@ void thread_info_init(void)
unsigned long hartid = csr_read(CSR_SSCRATCH);
int cpu = hartid_to_cpu(hartid);
- isa_init(&cpus[cpu]);
csr_write(CSR_SSCRATCH, &cpus[cpu]);
}
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index f1121573..8c16686f 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -16,6 +16,7 @@
#include <on-cpus.h>
#include <vmalloc.h>
#include <asm/csr.h>
+#include <asm/isa.h>
#include <asm/mmu.h>
#include <asm/page.h>
#include <asm/processor.h>
@@ -105,6 +106,9 @@ static void cpu_init(void)
cpu_init_acpi();
}
+ for (int cpu = 0; cpu < nr_cpus; cpu++)
+ isa_init(&cpus[cpu]);
+
me = hartid_to_cpu(csr_read(CSR_SSCRATCH));
assert(cpu_present(me));
set_cpu_online(me, true);
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
Move `isa_init()` from `thread_info_init()` to `cpu_init()`.
Previously it only ran for the current hart; now it is called for every
hart so that ISA extensions are parsed for the whole system.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/processor.c | 1 -
lib/riscv/setup.c | 4 ++++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c
index b055acc9..ddecc25e 100644
--- a/lib/riscv/processor.c
+++ b/lib/riscv/processor.c
@@ -81,7 +81,6 @@ void thread_info_init(void)
unsigned long hartid = csr_read(CSR_SSCRATCH);
int cpu = hartid_to_cpu(hartid);
- isa_init(&cpus[cpu]);
csr_write(CSR_SSCRATCH, &cpus[cpu]);
}
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index f1121573..8c16686f 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -16,6 +16,7 @@
#include <on-cpus.h>
#include <vmalloc.h>
#include <asm/csr.h>
+#include <asm/isa.h>
#include <asm/mmu.h>
#include <asm/page.h>
#include <asm/processor.h>
@@ -105,6 +106,9 @@ static void cpu_init(void)
cpu_init_acpi();
}
+ for (int cpu = 0; cpu < nr_cpus; cpu++)
+ isa_init(&cpus[cpu]);
+
me = hartid_to_cpu(csr_read(CSR_SSCRATCH));
assert(cpu_present(me));
set_cpu_online(me, true);
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 8/8] riscv: Add BRS SBI requirement tests
2026-11-05 8:20 ` Xiang W
@ 2026-11-05 8:20 ` Xiang W
-1 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
Add a riscv-brs unit test for the SBI rules in the RISC-V Boot and
Runtime Services specification:
SBI_010 spec version must be v2.0 or later
SBI_020 HSM must be implemented
SBI_030 TIME is required unless Sstc is present
SBI_040 IPI is required unless IMSIC is present
SBI_050 RFENCE is required unless IMSIC is present
SBI_060 PMU is required unless Sscsrind and Ssccfg are all present
SBI_070 DBCN is required when ACPI SPCR Interface Type is 0x15
Parse the extra ISA names used as skip conditions, and add the RFNC
and PMU extension IDs needed to probe those extensions.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/asm/isa.h | 3 +
lib/riscv/asm/sbi.h | 2 +
lib/riscv/isa.c | 12 +-
riscv/Makefile | 1 +
riscv/riscv-brs.c | 265 ++++++++++++++++++++++++++++++++++++++++++++
riscv/unittests.cfg | 4 +
6 files changed, 285 insertions(+), 2 deletions(-)
create mode 100644 riscv/riscv-brs.c
diff --git a/lib/riscv/asm/isa.h b/lib/riscv/asm/isa.h
index fb3af67d..6516c869 100644
--- a/lib/riscv/asm/isa.h
+++ b/lib/riscv/asm/isa.h
@@ -13,6 +13,9 @@
* by name not tracked here with cpu_has_extension_name()
*/
enum {
+ ISA_SSAIA,
+ ISA_SSCCFG,
+ ISA_SSCSRIND,
ISA_SSTC,
ISA_MAX,
};
diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h
index 289a6a24..c92a66dc 100644
--- a/lib/riscv/asm/sbi.h
+++ b/lib/riscv/asm/sbi.h
@@ -45,8 +45,10 @@ enum sbi_ext_id {
SBI_EXT_BASE = 0x10,
SBI_EXT_TIME = 0x54494d45,
SBI_EXT_IPI = 0x735049,
+ SBI_EXT_RFNC = 0x52464E43,
SBI_EXT_HSM = 0x48534d,
SBI_EXT_SRST = 0x53525354,
+ SBI_EXT_PMU = 0x504D55,
SBI_EXT_DBCN = 0x4442434E,
SBI_EXT_SUSP = 0x53555350,
SBI_EXT_FWFT = 0x46574654,
diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
index 91c7302c..6aa27948 100644
--- a/lib/riscv/isa.c
+++ b/lib/riscv/isa.c
@@ -39,8 +39,16 @@ static void isa_bit(const char *name, int len, void *data)
{
struct thread_info *info = (struct thread_info *)data;
- if (isa_match("sstc", name, len))
- set_bit(ISA_SSTC, info->isa);
+#define ISA_MATCH_AND_SET(ext) \
+ if (isa_match(#ext, name, len)) \
+ set_bit(ISA_##ext, info->isa)
+
+ ISA_MATCH_AND_SET(SSAIA);
+ ISA_MATCH_AND_SET(SSCCFG);
+ ISA_MATCH_AND_SET(SSCSRIND);
+ ISA_MATCH_AND_SET(SSTC);
+
+#undef ISA_MATCH_AND_SET
}
static void isa_parse(const char *isa_string, int len, struct isa_info *info)
diff --git a/riscv/Makefile b/riscv/Makefile
index 348a30a7..7da7526f 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -15,6 +15,7 @@ tests += $(TEST_DIR)/sbi.$(exe)
tests += $(TEST_DIR)/selftest.$(exe)
tests += $(TEST_DIR)/sieve.$(exe)
tests += $(TEST_DIR)/isa-dbltrp.$(exe)
+tests += $(TEST_DIR)/riscv-brs.$(exe)
all: $(tests)
diff --git a/riscv/riscv-brs.c b/riscv/riscv-brs.c
new file mode 100644
index 00000000..2813fa73
--- /dev/null
+++ b/riscv/riscv-brs.c
@@ -0,0 +1,265 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * RISC-V BRS SBI requirement tests
+ *
+ * Copyright (C) 2026, Institute of Software, CAS., Xiang W <wangxiang@iscas.ac.cn>
+ */
+
+#include <libcflat.h>
+#include <devicetree.h>
+#include <asm/sbi.h>
+#include <asm/isa.h>
+#include <asm/smp.h>
+
+#ifdef CONFIG_EFI
+#include <acpi.h>
+#endif
+
+static void check_sbi_010(void)
+{
+ struct sbiret ret;
+ unsigned long major, minor;
+
+ report_prefix_push("SBI_010");
+
+ ret = sbi_get_spec_version();
+ if (ret.error)
+ report_fail("sbi_get_spec_version failed with %ld", ret.error);
+ else {
+ major = ret.value >> SBI_SPEC_VERSION_MAJOR_SHIFT;
+ major = major & SBI_SPEC_VERSION_MAJOR_MASK;
+ minor = ret.value & SBI_SPEC_VERSION_MINOR_MASK;
+
+ report(ret.value >= sbi_mk_version(2, 0),
+ "SBI spec version is v2.0 or later (current %lu.%lu)", major, minor);
+ }
+
+ report_prefix_pop();
+}
+
+static void check_sbi_020(void)
+{
+ report_prefix_push("SBI_020");
+ report(sbi_probe(SBI_EXT_HSM), "HSM extension is implemented");
+ report_prefix_pop();
+}
+
+static void check_sbi_030(void)
+{
+ report_prefix_push("SBI_030");
+
+ if (cpu_has_extension(smp_processor_id(), ISA_SSTC))
+ report_skip("Sstc is present, TIME is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_TIME), "TIME extension is implemented");
+
+ report_prefix_pop();
+}
+
+#define IMSIC_SLEVEL_IRQ 9
+static bool hart_has_imsic[NR_CPUS];
+
+#ifdef CONFIG_EFI
+static int acpi_collect_imsic(struct acpi_subtable_header *header)
+{
+ struct acpi_madt_rintc *rintc = (void *)header;
+ int cpu;
+
+ if (!rintc->imsic_size)
+ return 0;
+
+ cpu = hartid_to_cpu(rintc->hart_id);
+ if (cpu >= 0 && cpu < nr_cpus)
+ hart_has_imsic[cpu] = true;
+
+ return 0;
+}
+#endif
+
+static int dt_intc_phandle_to_cpu(const void *fdt, uint32_t phandle)
+{
+ int intc_node, cpu_node, cpus_node, ret, i;
+ struct dt_reg raw_reg;
+ u32 nac, nsc;
+ u64 hartid;
+
+ intc_node = fdt_node_offset_by_phandle(fdt, phandle);
+ if (intc_node < 0)
+ return -1;
+
+ /* cpu-intc -> cpu node -> /cpus */
+ cpu_node = fdt_parent_offset(fdt, intc_node);
+ if (cpu_node < 0)
+ return -1;
+
+ cpus_node = fdt_parent_offset(fdt, cpu_node);
+ if (cpus_node < 0)
+ return -1;
+
+ /* #address-cells / #size-cells live on /cpus, not on the cpu node */
+ ret = dt_get_nr_cells(cpus_node, &nac, &nsc);
+ if (ret < 0)
+ return -1;
+
+ dt_reg_init(&raw_reg, nac, nsc);
+ ret = dt_get_reg(cpu_node, 0, &raw_reg);
+ if (ret < 0)
+ return -1;
+
+ hartid = raw_reg.address_cells[0];
+ if (nac == 2)
+ hartid = (hartid << 32) | raw_reg.address_cells[1];
+
+ for (i = 0; i < nr_cpus; i++) {
+ if (cpus[i].hartid == hartid)
+ return i;
+ }
+ return -1;
+}
+
+static void dt_collect_imsic(void)
+{
+ const void *fdt = dt_fdt();
+ const fdt32_t *prop;
+ int node, len, ncells, i, cpu;
+ uint32_t phandle, irq;
+
+ node = -1;
+ while ((node = fdt_node_offset_by_compatible(fdt, node, "riscv,imsics")) >= 0) {
+ prop = fdt_getprop(fdt, node, "interrupts-extended", &len);
+ if (!prop || len < 0)
+ continue;
+
+ /* Each entry is <phandle irq> (cpu-intc #interrupt-cells = 1) */
+ ncells = len / (int)sizeof(fdt32_t);
+ for (i = 0; i + 1 < ncells; i += 2) {
+ phandle = fdt32_to_cpu(prop[i]);
+ irq = fdt32_to_cpu(prop[i + 1]);
+
+ if (irq != IMSIC_SLEVEL_IRQ)
+ continue;
+
+ cpu = dt_intc_phandle_to_cpu(fdt, phandle);
+ if (cpu >= 0 && cpu < nr_cpus)
+ hart_has_imsic[cpu] = true;
+ }
+ }
+}
+
+static bool all_harts_have_imsic(void)
+{
+ int cpu;
+
+ memset(hart_has_imsic, 0, sizeof(hart_has_imsic));
+
+ if (dt_available())
+ dt_collect_imsic();
+#ifdef CONFIG_EFI
+ else
+ acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_collect_imsic);
+#endif
+
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
+ if (!cpu_present(cpu))
+ continue;
+ if (!cpu_has_extension(cpu, ISA_SSAIA)) {
+ report_info("CPU %d (hartid %lu) has no Ssaia",
+ cpu, cpus[cpu].hartid);
+ return false;
+ }
+ if (!hart_has_imsic[cpu]) {
+ report_info("CPU %d (hartid %lu) has no S-level IMSIC",
+ cpu, cpus[cpu].hartid);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static void check_sbi_040(void)
+{
+ report_prefix_push("SBI_040");
+
+ if (all_harts_have_imsic())
+ report_skip("IMSIC is present, IPI is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_IPI), "IPI extension is implemented");
+
+ report_prefix_pop();
+}
+
+static void check_sbi_050(void)
+{
+ report_prefix_push("SBI_050");
+
+ if (all_harts_have_imsic())
+ report_skip("IMSIC is present, RFENCE is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_RFNC), "RFENCE extension is implemented");
+
+ report_prefix_pop();
+}
+
+static void check_sbi_060(void)
+{
+ int cpu = smp_processor_id();
+
+ report_prefix_push("SBI_060");
+
+ if (cpu_has_extension(cpu, ISA_SSCSRIND) && cpu_has_extension(cpu, ISA_SSCCFG))
+ /*
+ * TODO: OE_SBI_060_010 also requires Smcsrind and Smcdeleg,
+ * but they are M-mode extensions and not present in the S-mode
+ * ISA string (DT or RHCT). Revisit if BRS clarifies how to detect them.
+ */
+ report_skip("Sscsrind and Ssccfg are present, PMU is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_PMU), "PMU extension is implemented");
+
+ report_prefix_pop();
+}
+
+static void check_sbi_070(void)
+{
+ report_prefix_push("SBI_070");
+
+ if (dt_available())
+ report_skip("ACPI not available, DBCN is not mandated");
+ else {
+#ifdef CONFIG_EFI
+ struct spcr_descriptor *spcr;
+
+ spcr = find_acpi_table_addr(SPCR_SIGNATURE);
+ if (spcr == NULL)
+ report_skip("SPCR is not present, DBCN is not mandated");
+ else {
+ if (spcr->interface_type == 0x15)
+ report(sbi_probe(SBI_EXT_DBCN), "DBCN extension is implemented");
+ else
+ report_skip(
+ "SPCR interface type is %#x (not 0x15), DBCN is not mandated",
+ spcr->interface_type);
+ }
+#else
+ report_skip("ACPI not available, DBCN is not mandated");
+#endif
+ }
+
+ report_prefix_pop();
+}
+
+int main(int argc, char **argv)
+{
+ report_prefix_push("riscv-brs");
+
+ check_sbi_010();
+ check_sbi_020();
+ check_sbi_030();
+ check_sbi_040();
+ check_sbi_050();
+ check_sbi_060();
+ check_sbi_070();
+
+ return report_summary();
+}
diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
index 9e9f58d9..990f03db 100644
--- a/riscv/unittests.cfg
+++ b/riscv/unittests.cfg
@@ -22,3 +22,7 @@ groups = sbi
[dbltrp]
file = isa-dbltrp.flat
groups = isa sbi
+
+[riscv-brs]
+file = riscv-brs.flat
+groups = riscv-brs nodefault
--
2.47.3
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [kvm-unit-tests PATCH v2 8/8] riscv: Add BRS SBI requirement tests
@ 2026-11-05 8:20 ` Xiang W
0 siblings, 0 replies; 36+ messages in thread
From: Xiang W @ 2026-11-05 8:20 UTC (permalink / raw)
To: kvm, kvm-riscv; +Cc: andrew.jones, Xiang W, pbonzini, thuth
Add a riscv-brs unit test for the SBI rules in the RISC-V Boot and
Runtime Services specification:
SBI_010 spec version must be v2.0 or later
SBI_020 HSM must be implemented
SBI_030 TIME is required unless Sstc is present
SBI_040 IPI is required unless IMSIC is present
SBI_050 RFENCE is required unless IMSIC is present
SBI_060 PMU is required unless Sscsrind and Ssccfg are all present
SBI_070 DBCN is required when ACPI SPCR Interface Type is 0x15
Parse the extra ISA names used as skip conditions, and add the RFNC
and PMU extension IDs needed to probe those extensions.
Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
---
lib/riscv/asm/isa.h | 3 +
lib/riscv/asm/sbi.h | 2 +
lib/riscv/isa.c | 12 +-
riscv/Makefile | 1 +
riscv/riscv-brs.c | 265 ++++++++++++++++++++++++++++++++++++++++++++
riscv/unittests.cfg | 4 +
6 files changed, 285 insertions(+), 2 deletions(-)
create mode 100644 riscv/riscv-brs.c
diff --git a/lib/riscv/asm/isa.h b/lib/riscv/asm/isa.h
index fb3af67d..6516c869 100644
--- a/lib/riscv/asm/isa.h
+++ b/lib/riscv/asm/isa.h
@@ -13,6 +13,9 @@
* by name not tracked here with cpu_has_extension_name()
*/
enum {
+ ISA_SSAIA,
+ ISA_SSCCFG,
+ ISA_SSCSRIND,
ISA_SSTC,
ISA_MAX,
};
diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h
index 289a6a24..c92a66dc 100644
--- a/lib/riscv/asm/sbi.h
+++ b/lib/riscv/asm/sbi.h
@@ -45,8 +45,10 @@ enum sbi_ext_id {
SBI_EXT_BASE = 0x10,
SBI_EXT_TIME = 0x54494d45,
SBI_EXT_IPI = 0x735049,
+ SBI_EXT_RFNC = 0x52464E43,
SBI_EXT_HSM = 0x48534d,
SBI_EXT_SRST = 0x53525354,
+ SBI_EXT_PMU = 0x504D55,
SBI_EXT_DBCN = 0x4442434E,
SBI_EXT_SUSP = 0x53555350,
SBI_EXT_FWFT = 0x46574654,
diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
index 91c7302c..6aa27948 100644
--- a/lib/riscv/isa.c
+++ b/lib/riscv/isa.c
@@ -39,8 +39,16 @@ static void isa_bit(const char *name, int len, void *data)
{
struct thread_info *info = (struct thread_info *)data;
- if (isa_match("sstc", name, len))
- set_bit(ISA_SSTC, info->isa);
+#define ISA_MATCH_AND_SET(ext) \
+ if (isa_match(#ext, name, len)) \
+ set_bit(ISA_##ext, info->isa)
+
+ ISA_MATCH_AND_SET(SSAIA);
+ ISA_MATCH_AND_SET(SSCCFG);
+ ISA_MATCH_AND_SET(SSCSRIND);
+ ISA_MATCH_AND_SET(SSTC);
+
+#undef ISA_MATCH_AND_SET
}
static void isa_parse(const char *isa_string, int len, struct isa_info *info)
diff --git a/riscv/Makefile b/riscv/Makefile
index 348a30a7..7da7526f 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -15,6 +15,7 @@ tests += $(TEST_DIR)/sbi.$(exe)
tests += $(TEST_DIR)/selftest.$(exe)
tests += $(TEST_DIR)/sieve.$(exe)
tests += $(TEST_DIR)/isa-dbltrp.$(exe)
+tests += $(TEST_DIR)/riscv-brs.$(exe)
all: $(tests)
diff --git a/riscv/riscv-brs.c b/riscv/riscv-brs.c
new file mode 100644
index 00000000..2813fa73
--- /dev/null
+++ b/riscv/riscv-brs.c
@@ -0,0 +1,265 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * RISC-V BRS SBI requirement tests
+ *
+ * Copyright (C) 2026, Institute of Software, CAS., Xiang W <wangxiang@iscas.ac.cn>
+ */
+
+#include <libcflat.h>
+#include <devicetree.h>
+#include <asm/sbi.h>
+#include <asm/isa.h>
+#include <asm/smp.h>
+
+#ifdef CONFIG_EFI
+#include <acpi.h>
+#endif
+
+static void check_sbi_010(void)
+{
+ struct sbiret ret;
+ unsigned long major, minor;
+
+ report_prefix_push("SBI_010");
+
+ ret = sbi_get_spec_version();
+ if (ret.error)
+ report_fail("sbi_get_spec_version failed with %ld", ret.error);
+ else {
+ major = ret.value >> SBI_SPEC_VERSION_MAJOR_SHIFT;
+ major = major & SBI_SPEC_VERSION_MAJOR_MASK;
+ minor = ret.value & SBI_SPEC_VERSION_MINOR_MASK;
+
+ report(ret.value >= sbi_mk_version(2, 0),
+ "SBI spec version is v2.0 or later (current %lu.%lu)", major, minor);
+ }
+
+ report_prefix_pop();
+}
+
+static void check_sbi_020(void)
+{
+ report_prefix_push("SBI_020");
+ report(sbi_probe(SBI_EXT_HSM), "HSM extension is implemented");
+ report_prefix_pop();
+}
+
+static void check_sbi_030(void)
+{
+ report_prefix_push("SBI_030");
+
+ if (cpu_has_extension(smp_processor_id(), ISA_SSTC))
+ report_skip("Sstc is present, TIME is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_TIME), "TIME extension is implemented");
+
+ report_prefix_pop();
+}
+
+#define IMSIC_SLEVEL_IRQ 9
+static bool hart_has_imsic[NR_CPUS];
+
+#ifdef CONFIG_EFI
+static int acpi_collect_imsic(struct acpi_subtable_header *header)
+{
+ struct acpi_madt_rintc *rintc = (void *)header;
+ int cpu;
+
+ if (!rintc->imsic_size)
+ return 0;
+
+ cpu = hartid_to_cpu(rintc->hart_id);
+ if (cpu >= 0 && cpu < nr_cpus)
+ hart_has_imsic[cpu] = true;
+
+ return 0;
+}
+#endif
+
+static int dt_intc_phandle_to_cpu(const void *fdt, uint32_t phandle)
+{
+ int intc_node, cpu_node, cpus_node, ret, i;
+ struct dt_reg raw_reg;
+ u32 nac, nsc;
+ u64 hartid;
+
+ intc_node = fdt_node_offset_by_phandle(fdt, phandle);
+ if (intc_node < 0)
+ return -1;
+
+ /* cpu-intc -> cpu node -> /cpus */
+ cpu_node = fdt_parent_offset(fdt, intc_node);
+ if (cpu_node < 0)
+ return -1;
+
+ cpus_node = fdt_parent_offset(fdt, cpu_node);
+ if (cpus_node < 0)
+ return -1;
+
+ /* #address-cells / #size-cells live on /cpus, not on the cpu node */
+ ret = dt_get_nr_cells(cpus_node, &nac, &nsc);
+ if (ret < 0)
+ return -1;
+
+ dt_reg_init(&raw_reg, nac, nsc);
+ ret = dt_get_reg(cpu_node, 0, &raw_reg);
+ if (ret < 0)
+ return -1;
+
+ hartid = raw_reg.address_cells[0];
+ if (nac == 2)
+ hartid = (hartid << 32) | raw_reg.address_cells[1];
+
+ for (i = 0; i < nr_cpus; i++) {
+ if (cpus[i].hartid == hartid)
+ return i;
+ }
+ return -1;
+}
+
+static void dt_collect_imsic(void)
+{
+ const void *fdt = dt_fdt();
+ const fdt32_t *prop;
+ int node, len, ncells, i, cpu;
+ uint32_t phandle, irq;
+
+ node = -1;
+ while ((node = fdt_node_offset_by_compatible(fdt, node, "riscv,imsics")) >= 0) {
+ prop = fdt_getprop(fdt, node, "interrupts-extended", &len);
+ if (!prop || len < 0)
+ continue;
+
+ /* Each entry is <phandle irq> (cpu-intc #interrupt-cells = 1) */
+ ncells = len / (int)sizeof(fdt32_t);
+ for (i = 0; i + 1 < ncells; i += 2) {
+ phandle = fdt32_to_cpu(prop[i]);
+ irq = fdt32_to_cpu(prop[i + 1]);
+
+ if (irq != IMSIC_SLEVEL_IRQ)
+ continue;
+
+ cpu = dt_intc_phandle_to_cpu(fdt, phandle);
+ if (cpu >= 0 && cpu < nr_cpus)
+ hart_has_imsic[cpu] = true;
+ }
+ }
+}
+
+static bool all_harts_have_imsic(void)
+{
+ int cpu;
+
+ memset(hart_has_imsic, 0, sizeof(hart_has_imsic));
+
+ if (dt_available())
+ dt_collect_imsic();
+#ifdef CONFIG_EFI
+ else
+ acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_collect_imsic);
+#endif
+
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
+ if (!cpu_present(cpu))
+ continue;
+ if (!cpu_has_extension(cpu, ISA_SSAIA)) {
+ report_info("CPU %d (hartid %lu) has no Ssaia",
+ cpu, cpus[cpu].hartid);
+ return false;
+ }
+ if (!hart_has_imsic[cpu]) {
+ report_info("CPU %d (hartid %lu) has no S-level IMSIC",
+ cpu, cpus[cpu].hartid);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static void check_sbi_040(void)
+{
+ report_prefix_push("SBI_040");
+
+ if (all_harts_have_imsic())
+ report_skip("IMSIC is present, IPI is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_IPI), "IPI extension is implemented");
+
+ report_prefix_pop();
+}
+
+static void check_sbi_050(void)
+{
+ report_prefix_push("SBI_050");
+
+ if (all_harts_have_imsic())
+ report_skip("IMSIC is present, RFENCE is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_RFNC), "RFENCE extension is implemented");
+
+ report_prefix_pop();
+}
+
+static void check_sbi_060(void)
+{
+ int cpu = smp_processor_id();
+
+ report_prefix_push("SBI_060");
+
+ if (cpu_has_extension(cpu, ISA_SSCSRIND) && cpu_has_extension(cpu, ISA_SSCCFG))
+ /*
+ * TODO: OE_SBI_060_010 also requires Smcsrind and Smcdeleg,
+ * but they are M-mode extensions and not present in the S-mode
+ * ISA string (DT or RHCT). Revisit if BRS clarifies how to detect them.
+ */
+ report_skip("Sscsrind and Ssccfg are present, PMU is not mandated");
+ else
+ report(sbi_probe(SBI_EXT_PMU), "PMU extension is implemented");
+
+ report_prefix_pop();
+}
+
+static void check_sbi_070(void)
+{
+ report_prefix_push("SBI_070");
+
+ if (dt_available())
+ report_skip("ACPI not available, DBCN is not mandated");
+ else {
+#ifdef CONFIG_EFI
+ struct spcr_descriptor *spcr;
+
+ spcr = find_acpi_table_addr(SPCR_SIGNATURE);
+ if (spcr == NULL)
+ report_skip("SPCR is not present, DBCN is not mandated");
+ else {
+ if (spcr->interface_type == 0x15)
+ report(sbi_probe(SBI_EXT_DBCN), "DBCN extension is implemented");
+ else
+ report_skip(
+ "SPCR interface type is %#x (not 0x15), DBCN is not mandated",
+ spcr->interface_type);
+ }
+#else
+ report_skip("ACPI not available, DBCN is not mandated");
+#endif
+ }
+
+ report_prefix_pop();
+}
+
+int main(int argc, char **argv)
+{
+ report_prefix_push("riscv-brs");
+
+ check_sbi_010();
+ check_sbi_020();
+ check_sbi_030();
+ check_sbi_040();
+ check_sbi_050();
+ check_sbi_060();
+ check_sbi_070();
+
+ return report_summary();
+}
diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
index 9e9f58d9..990f03db 100644
--- a/riscv/unittests.cfg
+++ b/riscv/unittests.cfg
@@ -22,3 +22,7 @@ groups = sbi
[dbltrp]
file = isa-dbltrp.flat
groups = isa sbi
+
+[riscv-brs]
+file = riscv-brs.flat
+groups = riscv-brs nodefault
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 8:54 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 8:54 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:31PM +0800, Xiang W wrote:
> When a DT is not provided, walk the RHCT Hart Info nodes and parse
> the referenced ISA String node instead of aborting in isa_init()
> and cpu_has_extension_name().
>
> Match the current hart by ACPI UID (DT still matches by hartid)
> and feed the ISA string into the existing isa_parse() helper so
> extension detection is shared by both firmware descriptions.
>
> Rename isa_info.hartid to isa_info.id so the same iterator state
> can hold either identifier.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/acpi.h | 28 +++++++++++++++++
> lib/riscv/isa.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 102 insertions(+), 7 deletions(-)
>
> diff --git a/lib/acpi.h b/lib/acpi.h
> index 0589669b..d5e238a9 100644
> --- a/lib/acpi.h
> +++ b/lib/acpi.h
> @@ -334,6 +334,34 @@ struct acpi_table_rhct {
> u32 node_offset;
> };
>
> +#define ACPI_RHCT_NODE_HEADER_DEF \
> + u16 type; \
> + u16 length; \
> + u16 revision; \
> +
> +struct acpi_rhct_node {
> + ACPI_RHCT_NODE_HEADER_DEF
> + char data[];
> +};
> +
> +enum acpi_rhct_node_type {
> + ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0,
> + ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF
> +};
> +
> +struct acpi_rhct_node_isa_string {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 isa_length;
> + char isa[];
> +};
> +
> +struct acpi_rhct_node_hart_info {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 num_offsets;
> + u32 uid;
> + u32 nodes[];
> +};
> +
> /* Reset to default packing */
> #pragma pack()
>
> diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> index bc1c9c72..91c7302c 100644
> --- a/lib/riscv/isa.c
> +++ b/lib/riscv/isa.c
> @@ -12,7 +12,7 @@
> typedef void (*isa_func_t)(const char *, int, void *);
>
> struct isa_info {
> - unsigned long hartid;
> + unsigned long id;
> isa_func_t func;
> void *data;
> };
> @@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> const struct fdt_property *prop;
> int len;
>
> - if (hartid != info->hartid)
> + if (hartid != info->id)
> return;
>
> prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
> @@ -83,32 +83,92 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> isa_parse(prop->data, len, info);
> }
>
> -static void isa_init_acpi(void)
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +
> +static void isa_parse_acpi(struct acpi_table_rhct *rhct,
> + struct acpi_rhct_node_hart_info *hart_info, void *data)
> {
> - assert_msg(false, "ACPI not available");
> + u32 offset;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_isa_string *isa_string;
> + struct isa_info *info = (struct isa_info *)data;
> +
> + if (hart_info->uid != info->id)
> + return;
> +
> + for (int i = 0; i < hart_info->num_offsets; i++) {
> + offset = hart_info->nodes[i];
> + if (offset >= rhct->length)
> + break;
> + node = (void *)rhct + offset;
> + if (node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) {
> + isa_string = (void *) node;
(void *)node
Thanks,
drew
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
@ 2026-11-20 8:54 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 8:54 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:31PM +0800, Xiang W wrote:
> When a DT is not provided, walk the RHCT Hart Info nodes and parse
> the referenced ISA String node instead of aborting in isa_init()
> and cpu_has_extension_name().
>
> Match the current hart by ACPI UID (DT still matches by hartid)
> and feed the ISA string into the existing isa_parse() helper so
> extension detection is shared by both firmware descriptions.
>
> Rename isa_info.hartid to isa_info.id so the same iterator state
> can hold either identifier.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/acpi.h | 28 +++++++++++++++++
> lib/riscv/isa.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 102 insertions(+), 7 deletions(-)
>
> diff --git a/lib/acpi.h b/lib/acpi.h
> index 0589669b..d5e238a9 100644
> --- a/lib/acpi.h
> +++ b/lib/acpi.h
> @@ -334,6 +334,34 @@ struct acpi_table_rhct {
> u32 node_offset;
> };
>
> +#define ACPI_RHCT_NODE_HEADER_DEF \
> + u16 type; \
> + u16 length; \
> + u16 revision; \
> +
> +struct acpi_rhct_node {
> + ACPI_RHCT_NODE_HEADER_DEF
> + char data[];
> +};
> +
> +enum acpi_rhct_node_type {
> + ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0,
> + ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF
> +};
> +
> +struct acpi_rhct_node_isa_string {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 isa_length;
> + char isa[];
> +};
> +
> +struct acpi_rhct_node_hart_info {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 num_offsets;
> + u32 uid;
> + u32 nodes[];
> +};
> +
> /* Reset to default packing */
> #pragma pack()
>
> diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> index bc1c9c72..91c7302c 100644
> --- a/lib/riscv/isa.c
> +++ b/lib/riscv/isa.c
> @@ -12,7 +12,7 @@
> typedef void (*isa_func_t)(const char *, int, void *);
>
> struct isa_info {
> - unsigned long hartid;
> + unsigned long id;
> isa_func_t func;
> void *data;
> };
> @@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> const struct fdt_property *prop;
> int len;
>
> - if (hartid != info->hartid)
> + if (hartid != info->id)
> return;
>
> prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
> @@ -83,32 +83,92 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> isa_parse(prop->data, len, info);
> }
>
> -static void isa_init_acpi(void)
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +
> +static void isa_parse_acpi(struct acpi_table_rhct *rhct,
> + struct acpi_rhct_node_hart_info *hart_info, void *data)
> {
> - assert_msg(false, "ACPI not available");
> + u32 offset;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_isa_string *isa_string;
> + struct isa_info *info = (struct isa_info *)data;
> +
> + if (hart_info->uid != info->id)
> + return;
> +
> + for (int i = 0; i < hart_info->num_offsets; i++) {
> + offset = hart_info->nodes[i];
> + if (offset >= rhct->length)
> + break;
> + node = (void *)rhct + offset;
> + if (node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) {
> + isa_string = (void *) node;
(void *)node
Thanks,
drew
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 9:14 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 9:14 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:31PM +0800, Xiang W wrote:
...
> +static int acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
> + struct acpi_rhct_node_hart_info *,
> + void *), void *data)
Check the alignment of these parameters. There's an extra space.
> +{
> + u32 offset;
> + struct acpi_table_rhct *rhct;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_hart_info *hart_info;
> +
> + rhct = find_acpi_table_addr(RHCT_SIGNATURE);
> + if (rhct == NULL)
> + return -1;
> +
> + offset = rhct->node_offset;
> + for (int i = 0; i < rhct->node_count; i++) {
> + if (offset >= rhct->length)
> + return -1;
> +
> + node = (void *)rhct + offset;
> + if (node->length < sizeof(*node))
> + return -1;
> +
> + if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) {
> + hart_info = (void *)node;
> + func(rhct, hart_info, data);
> + }
> +
> + offset += node->length;
> + }
> +
> + return 0;
> }
> +#endif
>
> void isa_init(struct thread_info *ti)
> {
> struct isa_info info = {
> - .hartid = ti->hartid,
> .func = isa_bit,
> .data = ti,
> };
> int ret;
>
> if (dt_available()) {
> + info.id = ti->hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
> } else {
> - isa_init_acpi();
> +#ifdef CONFIG_EFI
> + info.id = ti->uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
assert_msg(ret == 0, "ACPI: Failed to parse RHCT");
> +#else
> + assert_msg(false, "ACPI not available");
> +#endif
> }
> }
>
> bool cpu_has_extension_name(int cpu, const char *ext)
> {
> struct isa_info info = {
> - .hartid = cpus[cpu].hartid,
> .func = isa_name,
> .data = &(struct isa_check){ .ext = ext, },
> };
> @@ -116,10 +176,17 @@ bool cpu_has_extension_name(int cpu, const char *ext)
> int ret;
>
> if (dt_available()) {
> + info.id = cpus[cpu].hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
> } else {
> +#ifdef CONFIG_EFI
> + info.id = cpus[cpu].uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
assert_msg(ret == 0, "ACPI: Failed to parse RHCT");
> +#else
> assert_msg(false, "ACPI not available");
> +#endif
> }
>
> return check->found;
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
@ 2026-11-20 9:14 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 9:14 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:31PM +0800, Xiang W wrote:
...
> +static int acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
> + struct acpi_rhct_node_hart_info *,
> + void *), void *data)
Check the alignment of these parameters. There's an extra space.
> +{
> + u32 offset;
> + struct acpi_table_rhct *rhct;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_hart_info *hart_info;
> +
> + rhct = find_acpi_table_addr(RHCT_SIGNATURE);
> + if (rhct == NULL)
> + return -1;
> +
> + offset = rhct->node_offset;
> + for (int i = 0; i < rhct->node_count; i++) {
> + if (offset >= rhct->length)
> + return -1;
> +
> + node = (void *)rhct + offset;
> + if (node->length < sizeof(*node))
> + return -1;
> +
> + if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) {
> + hart_info = (void *)node;
> + func(rhct, hart_info, data);
> + }
> +
> + offset += node->length;
> + }
> +
> + return 0;
> }
> +#endif
>
> void isa_init(struct thread_info *ti)
> {
> struct isa_info info = {
> - .hartid = ti->hartid,
> .func = isa_bit,
> .data = ti,
> };
> int ret;
>
> if (dt_available()) {
> + info.id = ti->hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
> } else {
> - isa_init_acpi();
> +#ifdef CONFIG_EFI
> + info.id = ti->uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
assert_msg(ret == 0, "ACPI: Failed to parse RHCT");
> +#else
> + assert_msg(false, "ACPI not available");
> +#endif
> }
> }
>
> bool cpu_has_extension_name(int cpu, const char *ext)
> {
> struct isa_info info = {
> - .hartid = cpus[cpu].hartid,
> .func = isa_name,
> .data = &(struct isa_check){ .ext = ext, },
> };
> @@ -116,10 +176,17 @@ bool cpu_has_extension_name(int cpu, const char *ext)
> int ret;
>
> if (dt_available()) {
> + info.id = cpus[cpu].hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
> } else {
> +#ifdef CONFIG_EFI
> + info.id = cpus[cpu].uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
assert_msg(ret == 0, "ACPI: Failed to parse RHCT");
> +#else
> assert_msg(false, "ACPI not available");
> +#endif
> }
>
> return check->found;
> --
> 2.47.3
>
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 5/8] riscv: Prefer SBI DBCN console with UART fallback
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 10:08 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 10:08 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:32PM +0800, Xiang W wrote:
> CONFIG_SBI_CONSOLE already routes output through SBI DBCN, but console
> setup still always went through the UART init path. uart0_init_fdt()
> could skip a missing UART while uart0_init_acpi() aborted, so EFI/ACPI
> guests without a described MMIO UART could not print.
>
> Probe SBI_EXT_DBCN first. When it is available, use
> SBI_EXT_DBCN_CONSOLE_WRITE and skip UART setup. Otherwise fall back to
> the existing FDT or ACPI UART path. This keeps a UART fallback (as
> required by the server platform spec on ACPI systems) while allowing
Your patch actually didn't support the fallback for early prints.
Let's go with the following approach instead.
diff --git a/lib/riscv/io.c b/lib/riscv/io.c
index b11634046b8f..e92c9288b3ad 100644
--- a/lib/riscv/io.c
+++ b/lib/riscv/io.c
@@ -28,7 +28,12 @@
static volatile u8 *uart0_base = UART_EARLY_BASE;
static u32 uart0_reg_width = 1;
static u32 uart0_reg_shift;
-static struct spinlock uart_lock;
+static struct spinlock console_lock;
+#ifdef CONFIG_SBI_CONSOLE
+static bool prefer_dbcn = true;
+#else
+static bool prefer_dbcn = false;
+#endif
static u32 uart0_read(u32 num)
{
@@ -71,16 +76,15 @@ static void uart0_init_fdt(void)
break;
}
-#ifdef CONFIG_SBI_CONSOLE
- uart0_base = NULL;
- return;
-#else
if (ret) {
+ if (prefer_dbcn) {
+ uart0_base = NULL;
+ return;
+ }
printf("%s: Compatible uart not found in the device tree, aborting...\n",
__func__);
abort();
}
-#endif
} else {
const fdt32_t *val;
int len;
@@ -102,17 +106,23 @@ static void uart0_init_fdt(void)
static void uart0_init_acpi(void)
{
- assert_msg(false, "ACPI not available");
+ if (prefer_dbcn)
+ uart0_base = NULL;
+ else
+ assert_msg(false, "ACPI UART not supported");
}
void io_init(void)
{
+ if (prefer_dbcn && !sbi_probe(SBI_EXT_DBCN))
+ prefer_dbcn = false;
+
if (dt_available())
uart0_init_fdt();
else
uart0_init_acpi();
- if (uart0_base != UART_EARLY_BASE) {
+ if (!prefer_dbcn && uart0_base != UART_EARLY_BASE) {
printf("WARNING: early print support may not work. "
"Found uart at %p, but early base is %p.\n",
uart0_base, UART_EARLY_BASE);
@@ -126,31 +136,30 @@ void sbi_puts(const char *s)
unsigned long hi = upper_32_bits(addr);
unsigned long lo = lower_32_bits(addr);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, strlen(s), lo, hi, 0, 0, 0);
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
void uart0_puts(const char *s);
void uart0_puts(const char *s)
{
assert(uart0_base);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
while (*s) {
while (!(uart0_read(UART_LSR_OFFSET) & UART_LSR_THRE))
;
uart0_write(0, *s++);
}
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
void puts(const char *s)
{
-#ifdef CONFIG_SBI_CONSOLE
- sbi_puts(s);
-#else
- uart0_puts(s);
-#endif
+ if (prefer_dbcn)
+ sbi_puts(s);
+ else
+ uart0_puts(s);
}
/*
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 5/8] riscv: Prefer SBI DBCN console with UART fallback
@ 2026-11-20 10:08 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 10:08 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:32PM +0800, Xiang W wrote:
> CONFIG_SBI_CONSOLE already routes output through SBI DBCN, but console
> setup still always went through the UART init path. uart0_init_fdt()
> could skip a missing UART while uart0_init_acpi() aborted, so EFI/ACPI
> guests without a described MMIO UART could not print.
>
> Probe SBI_EXT_DBCN first. When it is available, use
> SBI_EXT_DBCN_CONSOLE_WRITE and skip UART setup. Otherwise fall back to
> the existing FDT or ACPI UART path. This keeps a UART fallback (as
> required by the server platform spec on ACPI systems) while allowing
Your patch actually didn't support the fallback for early prints.
Let's go with the following approach instead.
diff --git a/lib/riscv/io.c b/lib/riscv/io.c
index b11634046b8f..e92c9288b3ad 100644
--- a/lib/riscv/io.c
+++ b/lib/riscv/io.c
@@ -28,7 +28,12 @@
static volatile u8 *uart0_base = UART_EARLY_BASE;
static u32 uart0_reg_width = 1;
static u32 uart0_reg_shift;
-static struct spinlock uart_lock;
+static struct spinlock console_lock;
+#ifdef CONFIG_SBI_CONSOLE
+static bool prefer_dbcn = true;
+#else
+static bool prefer_dbcn = false;
+#endif
static u32 uart0_read(u32 num)
{
@@ -71,16 +76,15 @@ static void uart0_init_fdt(void)
break;
}
-#ifdef CONFIG_SBI_CONSOLE
- uart0_base = NULL;
- return;
-#else
if (ret) {
+ if (prefer_dbcn) {
+ uart0_base = NULL;
+ return;
+ }
printf("%s: Compatible uart not found in the device tree, aborting...\n",
__func__);
abort();
}
-#endif
} else {
const fdt32_t *val;
int len;
@@ -102,17 +106,23 @@ static void uart0_init_fdt(void)
static void uart0_init_acpi(void)
{
- assert_msg(false, "ACPI not available");
+ if (prefer_dbcn)
+ uart0_base = NULL;
+ else
+ assert_msg(false, "ACPI UART not supported");
}
void io_init(void)
{
+ if (prefer_dbcn && !sbi_probe(SBI_EXT_DBCN))
+ prefer_dbcn = false;
+
if (dt_available())
uart0_init_fdt();
else
uart0_init_acpi();
- if (uart0_base != UART_EARLY_BASE) {
+ if (!prefer_dbcn && uart0_base != UART_EARLY_BASE) {
printf("WARNING: early print support may not work. "
"Found uart at %p, but early base is %p.\n",
uart0_base, UART_EARLY_BASE);
@@ -126,31 +136,30 @@ void sbi_puts(const char *s)
unsigned long hi = upper_32_bits(addr);
unsigned long lo = lower_32_bits(addr);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, strlen(s), lo, hi, 0, 0, 0);
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
void uart0_puts(const char *s);
void uart0_puts(const char *s)
{
assert(uart0_base);
- spin_lock(&uart_lock);
+ spin_lock(&console_lock);
while (*s) {
while (!(uart0_read(UART_LSR_OFFSET) & UART_LSR_THRE))
;
uart0_write(0, *s++);
}
- spin_unlock(&uart_lock);
+ spin_unlock(&console_lock);
}
void puts(const char *s)
{
-#ifdef CONFIG_SBI_CONSOLE
- sbi_puts(s);
-#else
- uart0_puts(s);
-#endif
+ if (prefer_dbcn)
+ sbi_puts(s);
+ else
+ uart0_puts(s);
}
/*
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 6/8] riscv: efi: Allow ACPI boots
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 10:12 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 10:12 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:33PM +0800, Xiang W wrote:
> riscv/efi/run rejected EFI_USE_ACPI=y because CPU, timer and ISA
> discovery aborted without a DT. Those paths can now walk MADT and
> RHCT, so drop the early exit.
>
> The existing runner already omits -machine acpi=off when
s/omits/adds/
> EFI_USE_ACPI!=y. QEMU virt defaults to ACPI enabled, so no extra
> acpi=on flag is required. DT boots are unchanged: they still pass
> acpi=off.
>
> Tested with:
>
> EFI_USE_ACPI=y EFI_UEFI=/path/to/RISCV_VIRT_CODE.fd \
> ./riscv/efi/run riscv/riscv-brs.efi
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> riscv/efi/run | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/riscv/efi/run b/riscv/efi/run
> index b9b75440..a53b3a2c 100755
> --- a/riscv/efi/run
> +++ b/riscv/efi/run
> @@ -39,11 +39,6 @@ if [ ! -f "$EFI_UEFI" ]; then
> exit 2
> fi
>
> -if [ "$EFI_USE_ACPI" = "y" ]; then
> - echo "ACPI not available"
> - exit 2
> -fi
> -
> # Remove the TEST_CASE from $@
> shift 1
>
> --
> 2.47.3
>
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 6/8] riscv: efi: Allow ACPI boots
@ 2026-11-20 10:12 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 10:12 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:33PM +0800, Xiang W wrote:
> riscv/efi/run rejected EFI_USE_ACPI=y because CPU, timer and ISA
> discovery aborted without a DT. Those paths can now walk MADT and
> RHCT, so drop the early exit.
>
> The existing runner already omits -machine acpi=off when
s/omits/adds/
> EFI_USE_ACPI!=y. QEMU virt defaults to ACPI enabled, so no extra
> acpi=on flag is required. DT boots are unchanged: they still pass
> acpi=off.
>
> Tested with:
>
> EFI_USE_ACPI=y EFI_UEFI=/path/to/RISCV_VIRT_CODE.fd \
> ./riscv/efi/run riscv/riscv-brs.efi
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> riscv/efi/run | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/riscv/efi/run b/riscv/efi/run
> index b9b75440..a53b3a2c 100755
> --- a/riscv/efi/run
> +++ b/riscv/efi/run
> @@ -39,11 +39,6 @@ if [ ! -f "$EFI_UEFI" ]; then
> exit 2
> fi
>
> -if [ "$EFI_USE_ACPI" = "y" ]; then
> - echo "ACPI not available"
> - exit 2
> -fi
> -
> # Remove the TEST_CASE from $@
> shift 1
>
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 11:20 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 11:20 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:31PM +0800, Xiang W wrote:
> When a DT is not provided, walk the RHCT Hart Info nodes and parse
> the referenced ISA String node instead of aborting in isa_init()
> and cpu_has_extension_name().
>
> Match the current hart by ACPI UID (DT still matches by hartid)
> and feed the ISA string into the existing isa_parse() helper so
> extension detection is shared by both firmware descriptions.
>
> Rename isa_info.hartid to isa_info.id so the same iterator state
> can hold either identifier.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/acpi.h | 28 +++++++++++++++++
> lib/riscv/isa.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 102 insertions(+), 7 deletions(-)
>
> diff --git a/lib/acpi.h b/lib/acpi.h
> index 0589669b..d5e238a9 100644
> --- a/lib/acpi.h
> +++ b/lib/acpi.h
> @@ -334,6 +334,34 @@ struct acpi_table_rhct {
> u32 node_offset;
> };
>
> +#define ACPI_RHCT_NODE_HEADER_DEF \
> + u16 type; \
> + u16 length; \
> + u16 revision; \
> +
> +struct acpi_rhct_node {
> + ACPI_RHCT_NODE_HEADER_DEF
> + char data[];
> +};
> +
> +enum acpi_rhct_node_type {
> + ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0,
> + ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF
> +};
> +
> +struct acpi_rhct_node_isa_string {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 isa_length;
> + char isa[];
> +};
> +
> +struct acpi_rhct_node_hart_info {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 num_offsets;
> + u32 uid;
> + u32 nodes[];
> +};
> +
> /* Reset to default packing */
> #pragma pack()
>
> diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> index bc1c9c72..91c7302c 100644
> --- a/lib/riscv/isa.c
> +++ b/lib/riscv/isa.c
> @@ -12,7 +12,7 @@
> typedef void (*isa_func_t)(const char *, int, void *);
>
> struct isa_info {
> - unsigned long hartid;
> + unsigned long id;
> isa_func_t func;
> void *data;
> };
> @@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> const struct fdt_property *prop;
> int len;
>
> - if (hartid != info->hartid)
> + if (hartid != info->id)
> return;
>
> prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
> @@ -83,32 +83,92 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> isa_parse(prop->data, len, info);
> }
>
> -static void isa_init_acpi(void)
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +
> +static void isa_parse_acpi(struct acpi_table_rhct *rhct,
> + struct acpi_rhct_node_hart_info *hart_info, void *data)
> {
> - assert_msg(false, "ACPI not available");
> + u32 offset;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_isa_string *isa_string;
> + struct isa_info *info = (struct isa_info *)data;
nit: I prefer reverse fir tree
> +
> + if (hart_info->uid != info->id)
> + return;
> +
> + for (int i = 0; i < hart_info->num_offsets; i++) {
> + offset = hart_info->nodes[i];
> + if (offset >= rhct->length)
> + break;
Shouldn't this be an assert instead of a silent return?
> + node = (void *)rhct + offset;
> + if (node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) {
> + isa_string = (void *) node;
> + isa_parse(isa_string->isa, isa_string->isa_length, info);
> + }
> + }
> +}
> +
> +static int acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
> + struct acpi_rhct_node_hart_info *,
> + void *), void *data)
> +{
> + u32 offset;
> + struct acpi_table_rhct *rhct;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_hart_info *hart_info;
same fir tree nit (and likely elsewhere in the series)
> +
> + rhct = find_acpi_table_addr(RHCT_SIGNATURE);
> + if (rhct == NULL)
> + return -1;
> +
> + offset = rhct->node_offset;
> + for (int i = 0; i < rhct->node_count; i++) {
> + if (offset >= rhct->length)
> + return -1;
> +
> + node = (void *)rhct + offset;
> + if (node->length < sizeof(*node))
> + return -1;
> +
> + if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) {
> + hart_info = (void *)node;
> + func(rhct, hart_info, data);
> + }
> +
> + offset += node->length;
> + }
> +
> + return 0;
> }
> +#endif
>
> void isa_init(struct thread_info *ti)
> {
> struct isa_info info = {
> - .hartid = ti->hartid,
> .func = isa_bit,
> .data = ti,
> };
> int ret;
>
> if (dt_available()) {
> + info.id = ti->hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
While touching this code you can add assert_msg here too like I suggested
for your asserts below in my other reply.
> } else {
> - isa_init_acpi();
> +#ifdef CONFIG_EFI
> + info.id = ti->uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
> +#else
> + assert_msg(false, "ACPI not available");
> +#endif
> }
> }
>
> bool cpu_has_extension_name(int cpu, const char *ext)
> {
> struct isa_info info = {
> - .hartid = cpus[cpu].hartid,
> .func = isa_name,
> .data = &(struct isa_check){ .ext = ext, },
> };
> @@ -116,10 +176,17 @@ bool cpu_has_extension_name(int cpu, const char *ext)
> int ret;
>
> if (dt_available()) {
> + info.id = cpus[cpu].hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
and assert_msg here too, please
> } else {
> +#ifdef CONFIG_EFI
> + info.id = cpus[cpu].uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
> +#else
> assert_msg(false, "ACPI not available");
> +#endif
> }
>
> return check->found;
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery
@ 2026-11-20 11:20 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 11:20 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:31PM +0800, Xiang W wrote:
> When a DT is not provided, walk the RHCT Hart Info nodes and parse
> the referenced ISA String node instead of aborting in isa_init()
> and cpu_has_extension_name().
>
> Match the current hart by ACPI UID (DT still matches by hartid)
> and feed the ISA string into the existing isa_parse() helper so
> extension detection is shared by both firmware descriptions.
>
> Rename isa_info.hartid to isa_info.id so the same iterator state
> can hold either identifier.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/acpi.h | 28 +++++++++++++++++
> lib/riscv/isa.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 102 insertions(+), 7 deletions(-)
>
> diff --git a/lib/acpi.h b/lib/acpi.h
> index 0589669b..d5e238a9 100644
> --- a/lib/acpi.h
> +++ b/lib/acpi.h
> @@ -334,6 +334,34 @@ struct acpi_table_rhct {
> u32 node_offset;
> };
>
> +#define ACPI_RHCT_NODE_HEADER_DEF \
> + u16 type; \
> + u16 length; \
> + u16 revision; \
> +
> +struct acpi_rhct_node {
> + ACPI_RHCT_NODE_HEADER_DEF
> + char data[];
> +};
> +
> +enum acpi_rhct_node_type {
> + ACPI_RHCT_NODE_TYPE_ISA_STRING = 0x0,
> + ACPI_RHCT_NODE_TYPE_HART_INFO = 0xFFFF
> +};
> +
> +struct acpi_rhct_node_isa_string {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 isa_length;
> + char isa[];
> +};
> +
> +struct acpi_rhct_node_hart_info {
> + ACPI_RHCT_NODE_HEADER_DEF
> + u16 num_offsets;
> + u32 uid;
> + u32 nodes[];
> +};
> +
> /* Reset to default packing */
> #pragma pack()
>
> diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> index bc1c9c72..91c7302c 100644
> --- a/lib/riscv/isa.c
> +++ b/lib/riscv/isa.c
> @@ -12,7 +12,7 @@
> typedef void (*isa_func_t)(const char *, int, void *);
>
> struct isa_info {
> - unsigned long hartid;
> + unsigned long id;
> isa_func_t func;
> void *data;
> };
> @@ -74,7 +74,7 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> const struct fdt_property *prop;
> int len;
>
> - if (hartid != info->hartid)
> + if (hartid != info->id)
> return;
>
> prop = fdt_get_property(dt_fdt(), cpu_node, "riscv,isa", &len);
> @@ -83,32 +83,92 @@ static void isa_parse_fdt(int cpu_node, u64 hartid, void *data)
> isa_parse(prop->data, len, info);
> }
>
> -static void isa_init_acpi(void)
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +
> +static void isa_parse_acpi(struct acpi_table_rhct *rhct,
> + struct acpi_rhct_node_hart_info *hart_info, void *data)
> {
> - assert_msg(false, "ACPI not available");
> + u32 offset;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_isa_string *isa_string;
> + struct isa_info *info = (struct isa_info *)data;
nit: I prefer reverse fir tree
> +
> + if (hart_info->uid != info->id)
> + return;
> +
> + for (int i = 0; i < hart_info->num_offsets; i++) {
> + offset = hart_info->nodes[i];
> + if (offset >= rhct->length)
> + break;
Shouldn't this be an assert instead of a silent return?
> + node = (void *)rhct + offset;
> + if (node->type == ACPI_RHCT_NODE_TYPE_ISA_STRING) {
> + isa_string = (void *) node;
> + isa_parse(isa_string->isa, isa_string->isa_length, info);
> + }
> + }
> +}
> +
> +static int acpi_rhct_for_each_hart(void (*func)(struct acpi_table_rhct *,
> + struct acpi_rhct_node_hart_info *,
> + void *), void *data)
> +{
> + u32 offset;
> + struct acpi_table_rhct *rhct;
> + struct acpi_rhct_node *node;
> + struct acpi_rhct_node_hart_info *hart_info;
same fir tree nit (and likely elsewhere in the series)
> +
> + rhct = find_acpi_table_addr(RHCT_SIGNATURE);
> + if (rhct == NULL)
> + return -1;
> +
> + offset = rhct->node_offset;
> + for (int i = 0; i < rhct->node_count; i++) {
> + if (offset >= rhct->length)
> + return -1;
> +
> + node = (void *)rhct + offset;
> + if (node->length < sizeof(*node))
> + return -1;
> +
> + if (node->type == ACPI_RHCT_NODE_TYPE_HART_INFO) {
> + hart_info = (void *)node;
> + func(rhct, hart_info, data);
> + }
> +
> + offset += node->length;
> + }
> +
> + return 0;
> }
> +#endif
>
> void isa_init(struct thread_info *ti)
> {
> struct isa_info info = {
> - .hartid = ti->hartid,
> .func = isa_bit,
> .data = ti,
> };
> int ret;
>
> if (dt_available()) {
> + info.id = ti->hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
While touching this code you can add assert_msg here too like I suggested
for your asserts below in my other reply.
> } else {
> - isa_init_acpi();
> +#ifdef CONFIG_EFI
> + info.id = ti->uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
> +#else
> + assert_msg(false, "ACPI not available");
> +#endif
> }
> }
>
> bool cpu_has_extension_name(int cpu, const char *ext)
> {
> struct isa_info info = {
> - .hartid = cpus[cpu].hartid,
> .func = isa_name,
> .data = &(struct isa_check){ .ext = ext, },
> };
> @@ -116,10 +176,17 @@ bool cpu_has_extension_name(int cpu, const char *ext)
> int ret;
>
> if (dt_available()) {
> + info.id = cpus[cpu].hartid;
> ret = dt_for_each_cpu_node(isa_parse_fdt, &info);
> assert(ret == 0);
and assert_msg here too, please
> } else {
> +#ifdef CONFIG_EFI
> + info.id = cpus[cpu].uid;
> + ret = acpi_rhct_for_each_hart(isa_parse_acpi, &info);
> + assert(ret == 0);
> +#else
> assert_msg(false, "ACPI not available");
> +#endif
> }
>
> return check->found;
> --
> 2.47.3
>
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 11:37 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 11:37 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:34PM +0800, Xiang W wrote:
> Move `isa_init()` from `thread_info_init()` to `cpu_init()`.
>
> Previously it only ran for the current hart; now it is called for every
> hart so that ISA extensions are parsed for the whole system.
It was already run on every hart. The boot hart at boot time, the
secondaries at secondary start time. However, I see in the next patch
that you want to query ISA extensions on secondaries that haven't run
secondary start. Since we already initialize some thread info in cpu init
then I think it's reasonable to also init ISA there as you do, but let's
do it like in the following diff instead of anding the loop
diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c
index b055acc94e41..ddecc25e940d 100644
--- a/lib/riscv/processor.c
+++ b/lib/riscv/processor.c
@@ -81,7 +81,6 @@ void thread_info_init(void)
unsigned long hartid = csr_read(CSR_SSCRATCH);
int cpu = hartid_to_cpu(hartid);
- isa_init(&cpus[cpu]);
csr_write(CSR_SSCRATCH, &cpus[cpu]);
}
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index f1121573e81c..547851f532c3 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -16,6 +16,7 @@
#include <on-cpus.h>
#include <vmalloc.h>
#include <asm/csr.h>
+#include <asm/isa.h>
#include <asm/mmu.h>
#include <asm/page.h>
#include <asm/processor.h>
@@ -61,6 +62,7 @@ static int cpu_set_acpi(struct acpi_subtable_header *header)
cpus[cpu].cpu = cpu;
cpus[cpu].hartid = intc->hart_id;
cpus[cpu].uid = intc->uid;
+ isa_init(&cpus[cpu]);
if (intc->flags & ACPI_MADT_ENABLED) {
if (!sbi_hart_get_status(cpus[cpu].hartid).error)
@@ -79,6 +81,7 @@ static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused)
cpus[cpu].cpu = cpu;
cpus[cpu].hartid = regval;
+ isa_init(&cpus[cpu]);
if (!sbi_hart_get_status(cpus[cpu].hartid).error)
set_cpu_present(cpu, true);
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init
@ 2026-11-20 11:37 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 11:37 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:34PM +0800, Xiang W wrote:
> Move `isa_init()` from `thread_info_init()` to `cpu_init()`.
>
> Previously it only ran for the current hart; now it is called for every
> hart so that ISA extensions are parsed for the whole system.
It was already run on every hart. The boot hart at boot time, the
secondaries at secondary start time. However, I see in the next patch
that you want to query ISA extensions on secondaries that haven't run
secondary start. Since we already initialize some thread info in cpu init
then I think it's reasonable to also init ISA there as you do, but let's
do it like in the following diff instead of anding the loop
diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c
index b055acc94e41..ddecc25e940d 100644
--- a/lib/riscv/processor.c
+++ b/lib/riscv/processor.c
@@ -81,7 +81,6 @@ void thread_info_init(void)
unsigned long hartid = csr_read(CSR_SSCRATCH);
int cpu = hartid_to_cpu(hartid);
- isa_init(&cpus[cpu]);
csr_write(CSR_SSCRATCH, &cpus[cpu]);
}
diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
index f1121573e81c..547851f532c3 100644
--- a/lib/riscv/setup.c
+++ b/lib/riscv/setup.c
@@ -16,6 +16,7 @@
#include <on-cpus.h>
#include <vmalloc.h>
#include <asm/csr.h>
+#include <asm/isa.h>
#include <asm/mmu.h>
#include <asm/page.h>
#include <asm/processor.h>
@@ -61,6 +62,7 @@ static int cpu_set_acpi(struct acpi_subtable_header *header)
cpus[cpu].cpu = cpu;
cpus[cpu].hartid = intc->hart_id;
cpus[cpu].uid = intc->uid;
+ isa_init(&cpus[cpu]);
if (intc->flags & ACPI_MADT_ENABLED) {
if (!sbi_hart_get_status(cpus[cpu].hartid).error)
@@ -79,6 +81,7 @@ static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused)
cpus[cpu].cpu = cpu;
cpus[cpu].hartid = regval;
+ isa_init(&cpus[cpu]);
if (!sbi_hart_get_status(cpus[cpu].hartid).error)
set_cpu_present(cpu, true);
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 13:49 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 13:49 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
"initialize" should be capitalized in the patch summary.
On Thu, Nov 05, 2026 at 04:20:34PM +0800, Xiang W wrote:
> Move `isa_init()` from `thread_info_init()` to `cpu_init()`.
>
> Previously it only ran for the current hart; now it is called for every
> hart so that ISA extensions are parsed for the whole system.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/riscv/processor.c | 1 -
> lib/riscv/setup.c | 4 ++++
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c
> index b055acc9..ddecc25e 100644
> --- a/lib/riscv/processor.c
> +++ b/lib/riscv/processor.c
> @@ -81,7 +81,6 @@ void thread_info_init(void)
> unsigned long hartid = csr_read(CSR_SSCRATCH);
> int cpu = hartid_to_cpu(hartid);
>
> - isa_init(&cpus[cpu]);
> csr_write(CSR_SSCRATCH, &cpus[cpu]);
> }
>
> diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
> index f1121573..8c16686f 100644
> --- a/lib/riscv/setup.c
> +++ b/lib/riscv/setup.c
> @@ -16,6 +16,7 @@
> #include <on-cpus.h>
> #include <vmalloc.h>
> #include <asm/csr.h>
> +#include <asm/isa.h>
> #include <asm/mmu.h>
> #include <asm/page.h>
> #include <asm/processor.h>
> @@ -105,6 +106,9 @@ static void cpu_init(void)
> cpu_init_acpi();
> }
>
> + for (int cpu = 0; cpu < nr_cpus; cpu++)
> + isa_init(&cpus[cpu]);
> +
> me = hartid_to_cpu(csr_read(CSR_SSCRATCH));
> assert(cpu_present(me));
> set_cpu_online(me, true);
> --
> 2.47.3
>
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init
@ 2026-11-20 13:49 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 13:49 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
"initialize" should be capitalized in the patch summary.
On Thu, Nov 05, 2026 at 04:20:34PM +0800, Xiang W wrote:
> Move `isa_init()` from `thread_info_init()` to `cpu_init()`.
>
> Previously it only ran for the current hart; now it is called for every
> hart so that ISA extensions are parsed for the whole system.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/riscv/processor.c | 1 -
> lib/riscv/setup.c | 4 ++++
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c
> index b055acc9..ddecc25e 100644
> --- a/lib/riscv/processor.c
> +++ b/lib/riscv/processor.c
> @@ -81,7 +81,6 @@ void thread_info_init(void)
> unsigned long hartid = csr_read(CSR_SSCRATCH);
> int cpu = hartid_to_cpu(hartid);
>
> - isa_init(&cpus[cpu]);
> csr_write(CSR_SSCRATCH, &cpus[cpu]);
> }
>
> diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c
> index f1121573..8c16686f 100644
> --- a/lib/riscv/setup.c
> +++ b/lib/riscv/setup.c
> @@ -16,6 +16,7 @@
> #include <on-cpus.h>
> #include <vmalloc.h>
> #include <asm/csr.h>
> +#include <asm/isa.h>
> #include <asm/mmu.h>
> #include <asm/page.h>
> #include <asm/processor.h>
> @@ -105,6 +106,9 @@ static void cpu_init(void)
> cpu_init_acpi();
> }
>
> + for (int cpu = 0; cpu < nr_cpus; cpu++)
> + isa_init(&cpus[cpu]);
> +
> me = hartid_to_cpu(csr_read(CSR_SSCRATCH));
> assert(cpu_present(me));
> set_cpu_online(me, true);
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 3/8] riscv: Add ACPI support for timer frequency discovery
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 13:51 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 13:51 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:30PM +0800, Xiang W wrote:
> When a DT is not provided, read the system time base frequency from
> the RHCT instead of aborting in timer_get_frequency().
>
> RHCT Time Base Frequency is the ACPI equivalent of the DT
> /cpus timebase-frequency property and is the same for all harts.
> Keep DT as the preferred path when one is available.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/acpi.h | 9 +++++++++
> lib/riscv/timer.c | 38 ++++++++++++++++++++++++++------------
> 2 files changed, 35 insertions(+), 12 deletions(-)
>
> diff --git a/lib/acpi.h b/lib/acpi.h
> index f6c92d28..0589669b 100644
> --- a/lib/acpi.h
> +++ b/lib/acpi.h
> @@ -20,6 +20,7 @@
> #define MADT_SIGNATURE ACPI_SIGNATURE('A','P','I','C')
> #define SPCR_SIGNATURE ACPI_SIGNATURE('S','P','C','R')
> #define GTDT_SIGNATURE ACPI_SIGNATURE('G','T','D','T')
> +#define RHCT_SIGNATURE ACPI_SIGNATURE('R','H','C','T')
>
> #define ACPI_SIGNATURE_8BYTE(c1, c2, c3, c4, c5, c6, c7, c8) \
> (((uint64_t)(ACPI_SIGNATURE(c1, c2, c3, c4))) | \
> @@ -325,6 +326,14 @@ struct acpi_table_gtdt {
> u32 virtual_el2_timer_flags;
> };
>
> +struct acpi_table_rhct {
> + ACPI_TABLE_HEADER_DEF
> + u32 flags;
> + u64 time_base_freq;
> + u32 node_count;
> + u32 node_offset;
> +};
> +
> /* Reset to default packing */
> #pragma pack()
>
> diff --git a/lib/riscv/timer.c b/lib/riscv/timer.c
> index 18063b7e..a3af7e2b 100644
> --- a/lib/riscv/timer.c
> +++ b/lib/riscv/timer.c
> @@ -13,24 +13,38 @@
> #include <asm/smp.h>
> #include <asm/timer.h>
>
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +#endif
No need for this EFI guard.
Thanks,
drew
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 3/8] riscv: Add ACPI support for timer frequency discovery
@ 2026-11-20 13:51 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 13:51 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:30PM +0800, Xiang W wrote:
> When a DT is not provided, read the system time base frequency from
> the RHCT instead of aborting in timer_get_frequency().
>
> RHCT Time Base Frequency is the ACPI equivalent of the DT
> /cpus timebase-frequency property and is the same for all harts.
> Keep DT as the preferred path when one is available.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/acpi.h | 9 +++++++++
> lib/riscv/timer.c | 38 ++++++++++++++++++++++++++------------
> 2 files changed, 35 insertions(+), 12 deletions(-)
>
> diff --git a/lib/acpi.h b/lib/acpi.h
> index f6c92d28..0589669b 100644
> --- a/lib/acpi.h
> +++ b/lib/acpi.h
> @@ -20,6 +20,7 @@
> #define MADT_SIGNATURE ACPI_SIGNATURE('A','P','I','C')
> #define SPCR_SIGNATURE ACPI_SIGNATURE('S','P','C','R')
> #define GTDT_SIGNATURE ACPI_SIGNATURE('G','T','D','T')
> +#define RHCT_SIGNATURE ACPI_SIGNATURE('R','H','C','T')
>
> #define ACPI_SIGNATURE_8BYTE(c1, c2, c3, c4, c5, c6, c7, c8) \
> (((uint64_t)(ACPI_SIGNATURE(c1, c2, c3, c4))) | \
> @@ -325,6 +326,14 @@ struct acpi_table_gtdt {
> u32 virtual_el2_timer_flags;
> };
>
> +struct acpi_table_rhct {
> + ACPI_TABLE_HEADER_DEF
> + u32 flags;
> + u64 time_base_freq;
> + u32 node_count;
> + u32 node_offset;
> +};
> +
> /* Reset to default packing */
> #pragma pack()
>
> diff --git a/lib/riscv/timer.c b/lib/riscv/timer.c
> index 18063b7e..a3af7e2b 100644
> --- a/lib/riscv/timer.c
> +++ b/lib/riscv/timer.c
> @@ -13,24 +13,38 @@
> #include <asm/smp.h>
> #include <asm/timer.h>
>
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +#endif
No need for this EFI guard.
Thanks,
drew
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 8/8] riscv: Add BRS SBI requirement tests
2026-11-05 8:20 ` Xiang W
@ 2026-11-20 14:09 ` Andrew Jones
-1 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 14:09 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:35PM +0800, Xiang W wrote:
> Add a riscv-brs unit test for the SBI rules in the RISC-V Boot and
> Runtime Services specification:
>
> SBI_010 spec version must be v2.0 or later
> SBI_020 HSM must be implemented
> SBI_030 TIME is required unless Sstc is present
> SBI_040 IPI is required unless IMSIC is present
> SBI_050 RFENCE is required unless IMSIC is present
> SBI_060 PMU is required unless Sscsrind and Ssccfg are all present
> SBI_070 DBCN is required when ACPI SPCR Interface Type is 0x15
>
> Parse the extra ISA names used as skip conditions, and add the RFNC
> and PMU extension IDs needed to probe those extensions.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/riscv/asm/isa.h | 3 +
> lib/riscv/asm/sbi.h | 2 +
> lib/riscv/isa.c | 12 +-
> riscv/Makefile | 1 +
> riscv/riscv-brs.c | 265 ++++++++++++++++++++++++++++++++++++++++++++
> riscv/unittests.cfg | 4 +
> 6 files changed, 285 insertions(+), 2 deletions(-)
> create mode 100644 riscv/riscv-brs.c
>
> diff --git a/lib/riscv/asm/isa.h b/lib/riscv/asm/isa.h
> index fb3af67d..6516c869 100644
> --- a/lib/riscv/asm/isa.h
> +++ b/lib/riscv/asm/isa.h
> @@ -13,6 +13,9 @@
> * by name not tracked here with cpu_has_extension_name()
> */
> enum {
> + ISA_SSAIA,
> + ISA_SSCCFG,
> + ISA_SSCSRIND,
> ISA_SSTC,
> ISA_MAX,
> };
> diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h
> index 289a6a24..c92a66dc 100644
> --- a/lib/riscv/asm/sbi.h
> +++ b/lib/riscv/asm/sbi.h
> @@ -45,8 +45,10 @@ enum sbi_ext_id {
> SBI_EXT_BASE = 0x10,
> SBI_EXT_TIME = 0x54494d45,
> SBI_EXT_IPI = 0x735049,
> + SBI_EXT_RFNC = 0x52464E43,
> SBI_EXT_HSM = 0x48534d,
> SBI_EXT_SRST = 0x53525354,
> + SBI_EXT_PMU = 0x504D55,
While adding another three char name line it and all the other three char
names up so the '=' are aligned, i.e. add an extra space before the =.
> SBI_EXT_DBCN = 0x4442434E,
> SBI_EXT_SUSP = 0x53555350,
> SBI_EXT_FWFT = 0x46574654,
> diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> index 91c7302c..6aa27948 100644
> --- a/lib/riscv/isa.c
> +++ b/lib/riscv/isa.c
> @@ -39,8 +39,16 @@ static void isa_bit(const char *name, int len, void *data)
> {
> struct thread_info *info = (struct thread_info *)data;
>
> - if (isa_match("sstc", name, len))
> - set_bit(ISA_SSTC, info->isa);
> +#define ISA_MATCH_AND_SET(ext) \
> + if (isa_match(#ext, name, len)) \
> + set_bit(ISA_##ext, info->isa)
> +
> + ISA_MATCH_AND_SET(SSAIA);
> + ISA_MATCH_AND_SET(SSCCFG);
> + ISA_MATCH_AND_SET(SSCSRIND);
> + ISA_MATCH_AND_SET(SSTC);
> +
> +#undef ISA_MATCH_AND_SET
> }
>
> static void isa_parse(const char *isa_string, int len, struct isa_info *info)
> diff --git a/riscv/Makefile b/riscv/Makefile
> index 348a30a7..7da7526f 100644
> --- a/riscv/Makefile
> +++ b/riscv/Makefile
> @@ -15,6 +15,7 @@ tests += $(TEST_DIR)/sbi.$(exe)
> tests += $(TEST_DIR)/selftest.$(exe)
> tests += $(TEST_DIR)/sieve.$(exe)
> tests += $(TEST_DIR)/isa-dbltrp.$(exe)
> +tests += $(TEST_DIR)/riscv-brs.$(exe)
>
> all: $(tests)
>
> diff --git a/riscv/riscv-brs.c b/riscv/riscv-brs.c
> new file mode 100644
> index 00000000..2813fa73
> --- /dev/null
> +++ b/riscv/riscv-brs.c
> @@ -0,0 +1,265 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * RISC-V BRS SBI requirement tests
^
^ extra space
> + *
> + * Copyright (C) 2026, Institute of Software, CAS., Xiang W <wangxiang@iscas.ac.cn>
> + */
> +
> +#include <libcflat.h>
> +#include <devicetree.h>
> +#include <asm/sbi.h>
> +#include <asm/isa.h>
> +#include <asm/smp.h>
> +
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +#endif
No need for the CONFIG_EFI guard.
> +
> +static void check_sbi_010(void)
> +{
> + struct sbiret ret;
> + unsigned long major, minor;
> +
> + report_prefix_push("SBI_010");
> +
> + ret = sbi_get_spec_version();
> + if (ret.error)
> + report_fail("sbi_get_spec_version failed with %ld", ret.error);
> + else {
The else has {} so the if needs them too.
> + major = ret.value >> SBI_SPEC_VERSION_MAJOR_SHIFT;
> + major = major & SBI_SPEC_VERSION_MAJOR_MASK;
> + minor = ret.value & SBI_SPEC_VERSION_MINOR_MASK;
> +
> + report(ret.value >= sbi_mk_version(2, 0),
ret.value & SBI_SPEC_VERSION_MASK
> + "SBI spec version is v2.0 or later (current %lu.%lu)", major, minor);
> + }
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_020(void)
> +{
> + report_prefix_push("SBI_020");
> + report(sbi_probe(SBI_EXT_HSM), "HSM extension is implemented");
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_030(void)
> +{
> + report_prefix_push("SBI_030");
> +
> + if (cpu_has_extension(smp_processor_id(), ISA_SSTC))
> + report_skip("Sstc is present, TIME is not mandated");
> + else
> + report(sbi_probe(SBI_EXT_TIME), "TIME extension is implemented");
> +
Shouldn't all harts be checked?
> + report_prefix_pop();
> +}
> +
> +#define IMSIC_SLEVEL_IRQ 9
We already have IRQ_S_EXT.
> +static bool hart_has_imsic[NR_CPUS];
> +
> +#ifdef CONFIG_EFI
> +static int acpi_collect_imsic(struct acpi_subtable_header *header)
> +{
> + struct acpi_madt_rintc *rintc = (void *)header;
> + int cpu;
> +
> + if (!rintc->imsic_size)
> + return 0;
> +
> + cpu = hartid_to_cpu(rintc->hart_id);
> + if (cpu >= 0 && cpu < nr_cpus)
> + hart_has_imsic[cpu] = true;
> +
> + return 0;
> +}
> +#endif
> +
> +static int dt_intc_phandle_to_cpu(const void *fdt, uint32_t phandle)
> +{
> + int intc_node, cpu_node, cpus_node, ret, i;
> + struct dt_reg raw_reg;
> + u32 nac, nsc;
> + u64 hartid;
> +
> + intc_node = fdt_node_offset_by_phandle(fdt, phandle);
> + if (intc_node < 0)
> + return -1;
> +
> + /* cpu-intc -> cpu node -> /cpus */
> + cpu_node = fdt_parent_offset(fdt, intc_node);
> + if (cpu_node < 0)
> + return -1;
> +
> + cpus_node = fdt_parent_offset(fdt, cpu_node);
> + if (cpus_node < 0)
> + return -1;
> +
> + /* #address-cells / #size-cells live on /cpus, not on the cpu node */
> + ret = dt_get_nr_cells(cpus_node, &nac, &nsc);
> + if (ret < 0)
> + return -1;
> +
> + dt_reg_init(&raw_reg, nac, nsc);
> + ret = dt_get_reg(cpu_node, 0, &raw_reg);
> + if (ret < 0)
> + return -1;
> +
> + hartid = raw_reg.address_cells[0];
> + if (nac == 2)
> + hartid = (hartid << 32) | raw_reg.address_cells[1];
> +
> + for (i = 0; i < nr_cpus; i++) {
> + if (cpus[i].hartid == hartid)
> + return i;
> + }
> + return -1;
> +}
> +
> +static void dt_collect_imsic(void)
> +{
> + const void *fdt = dt_fdt();
> + const fdt32_t *prop;
> + int node, len, ncells, i, cpu;
> + uint32_t phandle, irq;
> +
> + node = -1;
> + while ((node = fdt_node_offset_by_compatible(fdt, node, "riscv,imsics")) >= 0) {
> + prop = fdt_getprop(fdt, node, "interrupts-extended", &len);
> + if (!prop || len < 0)
> + continue;
> +
> + /* Each entry is <phandle irq> (cpu-intc #interrupt-cells = 1) */
> + ncells = len / (int)sizeof(fdt32_t);
> + for (i = 0; i + 1 < ncells; i += 2) {
> + phandle = fdt32_to_cpu(prop[i]);
> + irq = fdt32_to_cpu(prop[i + 1]);
> +
> + if (irq != IMSIC_SLEVEL_IRQ)
> + continue;
> +
> + cpu = dt_intc_phandle_to_cpu(fdt, phandle);
> + if (cpu >= 0 && cpu < nr_cpus)
> + hart_has_imsic[cpu] = true;
> + }
> + }
> +}
I've sent https://lore.kernel.org/all/20261120135613.1388647-1-andrew.jones@linux.dev/
to avoid having to do all this DT parsing in the test code. Your next
version should add a patch that adds the ACPI support for setting
thread_info.imsic_addr and then this patch should use it.
> +
> +static bool all_harts_have_imsic(void)
> +{
> + int cpu;
> +
> + memset(hart_has_imsic, 0, sizeof(hart_has_imsic));
I see you call all_harts_have_imsic() twice. So instead of zeroing this
you should have a way to know that it's already been set once and then
the second time can just return true/false.
> +
> + if (dt_available())
> + dt_collect_imsic();
> +#ifdef CONFIG_EFI
> + else
> + acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_collect_imsic);
> +#endif
> +
> + for (cpu = 0; cpu < nr_cpus; cpu++) {
> + if (!cpu_present(cpu))
> + continue;
> + if (!cpu_has_extension(cpu, ISA_SSAIA)) {
> + report_info("CPU %d (hartid %lu) has no Ssaia",
> + cpu, cpus[cpu].hartid);
> + return false;
> + }
> + if (!hart_has_imsic[cpu]) {
> + report_info("CPU %d (hartid %lu) has no S-level IMSIC",
> + cpu, cpus[cpu].hartid);
> + return false;
> + }
> + }
> +
> + return true;
> +}
> +
> +static void check_sbi_040(void)
> +{
> + report_prefix_push("SBI_040");
> +
> + if (all_harts_have_imsic())
> + report_skip("IMSIC is present, IPI is not mandated");
> + else
> + report(sbi_probe(SBI_EXT_IPI), "IPI extension is implemented");
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_050(void)
> +{
> + report_prefix_push("SBI_050");
> +
> + if (all_harts_have_imsic())
> + report_skip("IMSIC is present, RFENCE is not mandated");
> + else
> + report(sbi_probe(SBI_EXT_RFNC), "RFENCE extension is implemented");
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_060(void)
> +{
> + int cpu = smp_processor_id();
> +
> + report_prefix_push("SBI_060");
> +
> + if (cpu_has_extension(cpu, ISA_SSCSRIND) && cpu_has_extension(cpu, ISA_SSCCFG))
Shouldn't all harts be checked?
> + /*
> + * TODO: OE_SBI_060_010 also requires Smcsrind and Smcdeleg,
> + * but they are M-mode extensions and not present in the S-mode
> + * ISA string (DT or RHCT). Revisit if BRS clarifies how to detect them.
> + */
> + report_skip("Sscsrind and Ssccfg are present, PMU is not mandated");
More than one line (even when they're comments means the if should have
{}, which means the else too.
> + else
> + report(sbi_probe(SBI_EXT_PMU), "PMU extension is implemented");
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_070(void)
> +{
> + report_prefix_push("SBI_070");
> +
> + if (dt_available())
> + report_skip("ACPI not available, DBCN is not mandated");
> + else {
The else has {} so the if needs them too.
> +#ifdef CONFIG_EFI
> + struct spcr_descriptor *spcr;
> +
> + spcr = find_acpi_table_addr(SPCR_SIGNATURE);
> + if (spcr == NULL)
> + report_skip("SPCR is not present, DBCN is not mandated");
> + else {
> + if (spcr->interface_type == 0x15)
> + report(sbi_probe(SBI_EXT_DBCN), "DBCN extension is implemented");
> + else
> + report_skip(
> + "SPCR interface type is %#x (not 0x15), DBCN is not mandated",
This line goes past 100 anyway, so put it on the same line as the
report_skip(
> + spcr->interface_type);
> + }
> +#else
> + report_skip("ACPI not available, DBCN is not mandated");
> +#endif
> + }
> +
> + report_prefix_pop();
> +}
> +
> +int main(int argc, char **argv)
> +{
> + report_prefix_push("riscv-brs");
> +
> + check_sbi_010();
> + check_sbi_020();
> + check_sbi_030();
> + check_sbi_040();
> + check_sbi_050();
> + check_sbi_060();
> + check_sbi_070();
> +
> + return report_summary();
> +}
> diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
> index 9e9f58d9..990f03db 100644
> --- a/riscv/unittests.cfg
> +++ b/riscv/unittests.cfg
> @@ -22,3 +22,7 @@ groups = sbi
> [dbltrp]
> file = isa-dbltrp.flat
> groups = isa sbi
> +
> +[riscv-brs]
> +file = riscv-brs.flat
> +groups = riscv-brs nodefault
> --
> 2.47.3
>
Thanks,
drew
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [kvm-unit-tests PATCH v2 8/8] riscv: Add BRS SBI requirement tests
@ 2026-11-20 14:09 ` Andrew Jones
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Jones @ 2026-11-20 14:09 UTC (permalink / raw)
To: Xiang W; +Cc: kvm, kvm-riscv, pbonzini, thuth
On Thu, Nov 05, 2026 at 04:20:35PM +0800, Xiang W wrote:
> Add a riscv-brs unit test for the SBI rules in the RISC-V Boot and
> Runtime Services specification:
>
> SBI_010 spec version must be v2.0 or later
> SBI_020 HSM must be implemented
> SBI_030 TIME is required unless Sstc is present
> SBI_040 IPI is required unless IMSIC is present
> SBI_050 RFENCE is required unless IMSIC is present
> SBI_060 PMU is required unless Sscsrind and Ssccfg are all present
> SBI_070 DBCN is required when ACPI SPCR Interface Type is 0x15
>
> Parse the extra ISA names used as skip conditions, and add the RFNC
> and PMU extension IDs needed to probe those extensions.
>
> Signed-off-by: Xiang W <wangxiang@iscas.ac.cn>
> ---
> lib/riscv/asm/isa.h | 3 +
> lib/riscv/asm/sbi.h | 2 +
> lib/riscv/isa.c | 12 +-
> riscv/Makefile | 1 +
> riscv/riscv-brs.c | 265 ++++++++++++++++++++++++++++++++++++++++++++
> riscv/unittests.cfg | 4 +
> 6 files changed, 285 insertions(+), 2 deletions(-)
> create mode 100644 riscv/riscv-brs.c
>
> diff --git a/lib/riscv/asm/isa.h b/lib/riscv/asm/isa.h
> index fb3af67d..6516c869 100644
> --- a/lib/riscv/asm/isa.h
> +++ b/lib/riscv/asm/isa.h
> @@ -13,6 +13,9 @@
> * by name not tracked here with cpu_has_extension_name()
> */
> enum {
> + ISA_SSAIA,
> + ISA_SSCCFG,
> + ISA_SSCSRIND,
> ISA_SSTC,
> ISA_MAX,
> };
> diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h
> index 289a6a24..c92a66dc 100644
> --- a/lib/riscv/asm/sbi.h
> +++ b/lib/riscv/asm/sbi.h
> @@ -45,8 +45,10 @@ enum sbi_ext_id {
> SBI_EXT_BASE = 0x10,
> SBI_EXT_TIME = 0x54494d45,
> SBI_EXT_IPI = 0x735049,
> + SBI_EXT_RFNC = 0x52464E43,
> SBI_EXT_HSM = 0x48534d,
> SBI_EXT_SRST = 0x53525354,
> + SBI_EXT_PMU = 0x504D55,
While adding another three char name line it and all the other three char
names up so the '=' are aligned, i.e. add an extra space before the =.
> SBI_EXT_DBCN = 0x4442434E,
> SBI_EXT_SUSP = 0x53555350,
> SBI_EXT_FWFT = 0x46574654,
> diff --git a/lib/riscv/isa.c b/lib/riscv/isa.c
> index 91c7302c..6aa27948 100644
> --- a/lib/riscv/isa.c
> +++ b/lib/riscv/isa.c
> @@ -39,8 +39,16 @@ static void isa_bit(const char *name, int len, void *data)
> {
> struct thread_info *info = (struct thread_info *)data;
>
> - if (isa_match("sstc", name, len))
> - set_bit(ISA_SSTC, info->isa);
> +#define ISA_MATCH_AND_SET(ext) \
> + if (isa_match(#ext, name, len)) \
> + set_bit(ISA_##ext, info->isa)
> +
> + ISA_MATCH_AND_SET(SSAIA);
> + ISA_MATCH_AND_SET(SSCCFG);
> + ISA_MATCH_AND_SET(SSCSRIND);
> + ISA_MATCH_AND_SET(SSTC);
> +
> +#undef ISA_MATCH_AND_SET
> }
>
> static void isa_parse(const char *isa_string, int len, struct isa_info *info)
> diff --git a/riscv/Makefile b/riscv/Makefile
> index 348a30a7..7da7526f 100644
> --- a/riscv/Makefile
> +++ b/riscv/Makefile
> @@ -15,6 +15,7 @@ tests += $(TEST_DIR)/sbi.$(exe)
> tests += $(TEST_DIR)/selftest.$(exe)
> tests += $(TEST_DIR)/sieve.$(exe)
> tests += $(TEST_DIR)/isa-dbltrp.$(exe)
> +tests += $(TEST_DIR)/riscv-brs.$(exe)
>
> all: $(tests)
>
> diff --git a/riscv/riscv-brs.c b/riscv/riscv-brs.c
> new file mode 100644
> index 00000000..2813fa73
> --- /dev/null
> +++ b/riscv/riscv-brs.c
> @@ -0,0 +1,265 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * RISC-V BRS SBI requirement tests
^
^ extra space
> + *
> + * Copyright (C) 2026, Institute of Software, CAS., Xiang W <wangxiang@iscas.ac.cn>
> + */
> +
> +#include <libcflat.h>
> +#include <devicetree.h>
> +#include <asm/sbi.h>
> +#include <asm/isa.h>
> +#include <asm/smp.h>
> +
> +#ifdef CONFIG_EFI
> +#include <acpi.h>
> +#endif
No need for the CONFIG_EFI guard.
> +
> +static void check_sbi_010(void)
> +{
> + struct sbiret ret;
> + unsigned long major, minor;
> +
> + report_prefix_push("SBI_010");
> +
> + ret = sbi_get_spec_version();
> + if (ret.error)
> + report_fail("sbi_get_spec_version failed with %ld", ret.error);
> + else {
The else has {} so the if needs them too.
> + major = ret.value >> SBI_SPEC_VERSION_MAJOR_SHIFT;
> + major = major & SBI_SPEC_VERSION_MAJOR_MASK;
> + minor = ret.value & SBI_SPEC_VERSION_MINOR_MASK;
> +
> + report(ret.value >= sbi_mk_version(2, 0),
ret.value & SBI_SPEC_VERSION_MASK
> + "SBI spec version is v2.0 or later (current %lu.%lu)", major, minor);
> + }
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_020(void)
> +{
> + report_prefix_push("SBI_020");
> + report(sbi_probe(SBI_EXT_HSM), "HSM extension is implemented");
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_030(void)
> +{
> + report_prefix_push("SBI_030");
> +
> + if (cpu_has_extension(smp_processor_id(), ISA_SSTC))
> + report_skip("Sstc is present, TIME is not mandated");
> + else
> + report(sbi_probe(SBI_EXT_TIME), "TIME extension is implemented");
> +
Shouldn't all harts be checked?
> + report_prefix_pop();
> +}
> +
> +#define IMSIC_SLEVEL_IRQ 9
We already have IRQ_S_EXT.
> +static bool hart_has_imsic[NR_CPUS];
> +
> +#ifdef CONFIG_EFI
> +static int acpi_collect_imsic(struct acpi_subtable_header *header)
> +{
> + struct acpi_madt_rintc *rintc = (void *)header;
> + int cpu;
> +
> + if (!rintc->imsic_size)
> + return 0;
> +
> + cpu = hartid_to_cpu(rintc->hart_id);
> + if (cpu >= 0 && cpu < nr_cpus)
> + hart_has_imsic[cpu] = true;
> +
> + return 0;
> +}
> +#endif
> +
> +static int dt_intc_phandle_to_cpu(const void *fdt, uint32_t phandle)
> +{
> + int intc_node, cpu_node, cpus_node, ret, i;
> + struct dt_reg raw_reg;
> + u32 nac, nsc;
> + u64 hartid;
> +
> + intc_node = fdt_node_offset_by_phandle(fdt, phandle);
> + if (intc_node < 0)
> + return -1;
> +
> + /* cpu-intc -> cpu node -> /cpus */
> + cpu_node = fdt_parent_offset(fdt, intc_node);
> + if (cpu_node < 0)
> + return -1;
> +
> + cpus_node = fdt_parent_offset(fdt, cpu_node);
> + if (cpus_node < 0)
> + return -1;
> +
> + /* #address-cells / #size-cells live on /cpus, not on the cpu node */
> + ret = dt_get_nr_cells(cpus_node, &nac, &nsc);
> + if (ret < 0)
> + return -1;
> +
> + dt_reg_init(&raw_reg, nac, nsc);
> + ret = dt_get_reg(cpu_node, 0, &raw_reg);
> + if (ret < 0)
> + return -1;
> +
> + hartid = raw_reg.address_cells[0];
> + if (nac == 2)
> + hartid = (hartid << 32) | raw_reg.address_cells[1];
> +
> + for (i = 0; i < nr_cpus; i++) {
> + if (cpus[i].hartid == hartid)
> + return i;
> + }
> + return -1;
> +}
> +
> +static void dt_collect_imsic(void)
> +{
> + const void *fdt = dt_fdt();
> + const fdt32_t *prop;
> + int node, len, ncells, i, cpu;
> + uint32_t phandle, irq;
> +
> + node = -1;
> + while ((node = fdt_node_offset_by_compatible(fdt, node, "riscv,imsics")) >= 0) {
> + prop = fdt_getprop(fdt, node, "interrupts-extended", &len);
> + if (!prop || len < 0)
> + continue;
> +
> + /* Each entry is <phandle irq> (cpu-intc #interrupt-cells = 1) */
> + ncells = len / (int)sizeof(fdt32_t);
> + for (i = 0; i + 1 < ncells; i += 2) {
> + phandle = fdt32_to_cpu(prop[i]);
> + irq = fdt32_to_cpu(prop[i + 1]);
> +
> + if (irq != IMSIC_SLEVEL_IRQ)
> + continue;
> +
> + cpu = dt_intc_phandle_to_cpu(fdt, phandle);
> + if (cpu >= 0 && cpu < nr_cpus)
> + hart_has_imsic[cpu] = true;
> + }
> + }
> +}
I've sent https://lore.kernel.org/all/20261120135613.1388647-1-andrew.jones@linux.dev/
to avoid having to do all this DT parsing in the test code. Your next
version should add a patch that adds the ACPI support for setting
thread_info.imsic_addr and then this patch should use it.
> +
> +static bool all_harts_have_imsic(void)
> +{
> + int cpu;
> +
> + memset(hart_has_imsic, 0, sizeof(hart_has_imsic));
I see you call all_harts_have_imsic() twice. So instead of zeroing this
you should have a way to know that it's already been set once and then
the second time can just return true/false.
> +
> + if (dt_available())
> + dt_collect_imsic();
> +#ifdef CONFIG_EFI
> + else
> + acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_collect_imsic);
> +#endif
> +
> + for (cpu = 0; cpu < nr_cpus; cpu++) {
> + if (!cpu_present(cpu))
> + continue;
> + if (!cpu_has_extension(cpu, ISA_SSAIA)) {
> + report_info("CPU %d (hartid %lu) has no Ssaia",
> + cpu, cpus[cpu].hartid);
> + return false;
> + }
> + if (!hart_has_imsic[cpu]) {
> + report_info("CPU %d (hartid %lu) has no S-level IMSIC",
> + cpu, cpus[cpu].hartid);
> + return false;
> + }
> + }
> +
> + return true;
> +}
> +
> +static void check_sbi_040(void)
> +{
> + report_prefix_push("SBI_040");
> +
> + if (all_harts_have_imsic())
> + report_skip("IMSIC is present, IPI is not mandated");
> + else
> + report(sbi_probe(SBI_EXT_IPI), "IPI extension is implemented");
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_050(void)
> +{
> + report_prefix_push("SBI_050");
> +
> + if (all_harts_have_imsic())
> + report_skip("IMSIC is present, RFENCE is not mandated");
> + else
> + report(sbi_probe(SBI_EXT_RFNC), "RFENCE extension is implemented");
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_060(void)
> +{
> + int cpu = smp_processor_id();
> +
> + report_prefix_push("SBI_060");
> +
> + if (cpu_has_extension(cpu, ISA_SSCSRIND) && cpu_has_extension(cpu, ISA_SSCCFG))
Shouldn't all harts be checked?
> + /*
> + * TODO: OE_SBI_060_010 also requires Smcsrind and Smcdeleg,
> + * but they are M-mode extensions and not present in the S-mode
> + * ISA string (DT or RHCT). Revisit if BRS clarifies how to detect them.
> + */
> + report_skip("Sscsrind and Ssccfg are present, PMU is not mandated");
More than one line (even when they're comments means the if should have
{}, which means the else too.
> + else
> + report(sbi_probe(SBI_EXT_PMU), "PMU extension is implemented");
> +
> + report_prefix_pop();
> +}
> +
> +static void check_sbi_070(void)
> +{
> + report_prefix_push("SBI_070");
> +
> + if (dt_available())
> + report_skip("ACPI not available, DBCN is not mandated");
> + else {
The else has {} so the if needs them too.
> +#ifdef CONFIG_EFI
> + struct spcr_descriptor *spcr;
> +
> + spcr = find_acpi_table_addr(SPCR_SIGNATURE);
> + if (spcr == NULL)
> + report_skip("SPCR is not present, DBCN is not mandated");
> + else {
> + if (spcr->interface_type == 0x15)
> + report(sbi_probe(SBI_EXT_DBCN), "DBCN extension is implemented");
> + else
> + report_skip(
> + "SPCR interface type is %#x (not 0x15), DBCN is not mandated",
This line goes past 100 anyway, so put it on the same line as the
report_skip(
> + spcr->interface_type);
> + }
> +#else
> + report_skip("ACPI not available, DBCN is not mandated");
> +#endif
> + }
> +
> + report_prefix_pop();
> +}
> +
> +int main(int argc, char **argv)
> +{
> + report_prefix_push("riscv-brs");
> +
> + check_sbi_010();
> + check_sbi_020();
> + check_sbi_030();
> + check_sbi_040();
> + check_sbi_050();
> + check_sbi_060();
> + check_sbi_070();
> +
> + return report_summary();
> +}
> diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
> index 9e9f58d9..990f03db 100644
> --- a/riscv/unittests.cfg
> +++ b/riscv/unittests.cfg
> @@ -22,3 +22,7 @@ groups = sbi
> [dbltrp]
> file = isa-dbltrp.flat
> groups = isa sbi
> +
> +[riscv-brs]
> +file = riscv-brs.flat
> +groups = riscv-brs nodefault
> --
> 2.47.3
>
Thanks,
drew
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2026-11-20 14:10 UTC | newest]
Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 8:20 [kvm-unit-tests PATCH v2 0/8] riscv: ACPI boot and BRS-I SBI tests Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 1/8] riscv: Initialize the ACPI RSDP from the EFI system table Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 2/8] riscv: Add ACPI support for CPU initialization Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 3/8] riscv: Add ACPI support for timer frequency discovery Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-20 13:51 ` Andrew Jones
2026-11-20 13:51 ` Andrew Jones
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 4/8] riscv: Add ACPI support for ISA string discovery Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-20 8:54 ` Andrew Jones
2026-11-20 8:54 ` Andrew Jones
2026-11-20 9:14 ` Andrew Jones
2026-11-20 9:14 ` Andrew Jones
2026-11-20 11:20 ` Andrew Jones
2026-11-20 11:20 ` Andrew Jones
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 5/8] riscv: Prefer SBI DBCN console with UART fallback Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-20 10:08 ` Andrew Jones
2026-11-20 10:08 ` Andrew Jones
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 6/8] riscv: efi: Allow ACPI boots Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-20 10:12 ` Andrew Jones
2026-11-20 10:12 ` Andrew Jones
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 7/8] riscv: initialize ISA extensions for all harts in cpu_init Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-20 11:37 ` Andrew Jones
2026-11-20 11:37 ` Andrew Jones
2026-11-20 13:49 ` Andrew Jones
2026-11-20 13:49 ` Andrew Jones
2026-11-05 8:20 ` [kvm-unit-tests PATCH v2 8/8] riscv: Add BRS SBI requirement tests Xiang W
2026-11-05 8:20 ` Xiang W
2026-11-20 14:09 ` Andrew Jones
2026-11-20 14:09 ` Andrew Jones
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.