[kvm-unit-tests PATCH v3 0/9] riscv: ACPI boot and BRS-I SBI tests

Xiang W wangxiang at iscas.ac.cn
Tue Nov 24 17:44:00 PST 2026


Hi,

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 falls back to the SBI DBCN console when UART initialization
fails, 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_set_fdt() and cpu_set_acpi() so
cpu_has_extension() can read every hart's ISA bits from the boot hart,
including secondaries that have not started yet.

Patch 8 captures S-mode IMSIC interrupt file addresses at boot time.
The DT path is Andrew's posted patch [2]; the ACPI path copies
RINTC.imsic_addr only when an IMSIC structure is present in the MADT,
as ACPI requires OSPM to ignore that field otherwise.

Patch 9 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).

v3 changes
==========
Address review comments from Andrew Jones on v2, except the three
points in the next section.

- call isa_init() from cpu_set_fdt() / cpu_set_acpi() rather than
  looping in cpu_init()
- RHCT parsing: (void *)node, reverse fir tree, assert_msg, treat a
  bad offset as an assert
- drop unnecessary CONFIG_EFI guards around <acpi.h>
- check Sstc and Sscsrind+Ssccfg on all present harts
- use thread_info.imsic_addr instead of parsing IMSIC in the test
- ACPI IMSIC: ignore RINTC.imsic_addr unless an IMSIC MADT structure
  is present
- coding-style nits (braces, SBI enum alignment, report_skip wrapping,
  "Initialize" capitalization)

Differences from the v2 review
==============================
1. Console policy (patch 5)

   The suggested diff prefers SBI DBCN whenever CONFIG_SBI_CONSOLE is
   set and DBCN probes successfully, with UART as a fallback.

   This version keeps UART when initialization succeeds and uses DBCN
   only if there is no usable UART. Each DBCN write is an SBI ecall,
   which is slower than an MMIO UART store, so the fast path should
   stay on UART when one is present. Guests without an MMIO UART still
   print via DBCN.

2. SBI_010 version comparison (patch 9)

   The review asked to compare (ret.value & SBI_SPEC_VERSION_MASK)
   against sbi_mk_version(2, 0). The test already decodes major and
   minor for the report string, so it compares
   sbi_mk_version(major, minor) instead. That drops the reserved bit
   the same way and avoids encoding the version a second time.

3. SBI_040 / SBI_050 IMSIC check (patch 9)

   v2 parsed DT/ACPI on every call, and the review asked to cache
   all_harts_have_imsic(). After patch 8 the check is a walk of
   cpus[].isa and cpus[].imsic_pa, so the two tests keep their own
   loops rather than sharing a cached helper.

Tested with QEMU virt:

  ./configure --arch=riscv64 \
              --cross-prefix=riscv64-linux-gnu- \
              --console=sbi --enable-efi && make

  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
[2] https://lore.kernel.org/all/20261120135613.1388647-1-andrew.jones@linux.dev/


Xiang W (9):
  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: Fall back to SBI DBCN when no UART is available
  riscv: efi: Allow ACPI boots
  riscv: Initialize ISA extensions for all harts at CPU setup
  riscv: Capture IMSIC addresses at boot time
  riscv: Add BRS SBI requirement tests

 lib/acpi.h                |  64 ++++++++++++-
 lib/riscv/asm/imsic.h     |   8 ++
 lib/riscv/asm/isa.h       |   3 +
 lib/riscv/asm/processor.h |   2 +
 lib/riscv/asm/sbi.h       |   8 +-
 lib/riscv/imsic.c         |  86 +++++++++++++++++
 lib/riscv/io.c            |  52 +++++++----
 lib/riscv/isa.c           |  96 ++++++++++++++++---
 lib/riscv/processor.c     |   1 -
 lib/riscv/setup.c         |  71 ++++++++++++++
 lib/riscv/timer.c         |  35 ++++---
 riscv/Makefile            |   2 +
 riscv/efi/run             |   5 -
 riscv/riscv-brs.c         | 192 ++++++++++++++++++++++++++++++++++++++
 riscv/unittests.cfg       |   4 +
 15 files changed, 577 insertions(+), 52 deletions(-)
 create mode 100644 lib/riscv/asm/imsic.h
 create mode 100644 lib/riscv/imsic.c
 create mode 100644 riscv/riscv-brs.c

-- 
2.47.3




More information about the kvm-riscv mailing list