riscv: ACPI boot and BRS-I SBI tests
Subsystems (4)
v3 cover riscv: ACPI boot and BRS-I SBI tests
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/[email protected]/
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
Signature · 1 line
2.47.3
PATCH v3 1/9 riscv: Initialize the ACPI RSDP from the EFI system table
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.
--- lib/riscv/setup.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
lib/riscv/setup.c +29 -0
@@ -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 ();
Signature · 1 line
2.47.3
PATCH v3 2/9 riscv: Add ACPI support for CPU initialization
In reply to Xiang WWhen 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.
--- lib/acpi.h | 27 ++++++++++++++++++++++++++- lib/riscv/asm/processor.h | 1 + lib/riscv/setup.c | 28 +++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-)
lib/acpi.h +26 -1
@@ -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 */
lib/riscv/asm/processor.h +1 -0
@@ -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 ];
lib/riscv/setup.c +27 -1
@@ -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;
Signature · 1 line
2.47.3
PATCH v3 3/9 riscv: Add ACPI support for timer frequency discovery
In reply to Xiang WWhen 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.
--- lib/acpi.h | 9 +++++++++ lib/riscv/timer.c | 35 +++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-)
lib/acpi.h +9 -0
@@ -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()
lib/riscv/timer.c +23 -12
@@ -12,25 +12,36 @@#include <asm/setup.h> #include <asm/smp.h> #include <asm/timer.h> +#include <acpi.h> void timer_get_frequency (void ) { -const struct fdt_property *prop; -u32 *data; -int cpus, len; +if (dt_available ()) { +const struct fdt_property *prop; +const void *fdt; +u32 *data; +int cpus, len; -assert_msg (dt_available (),"ACPI not yet supported" ); + fdt =dt_fdt (); + cpus =fdt_path_offset (fdt,"/cpus" ); +assert (cpus >=0 ); -const void *fdt =dt_fdt (); + prop =fdt_get_property (fdt, cpus,"timebase-frequency" , &len); +assert (prop !=NULL && len ==4 ); - cpus =fdt_path_offset (fdt,"/cpus" ); -assert (cpus >=0 ); - - 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)
Signature · 7 lines
2.47.3 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v3 4/9 riscv: Add ACPI support for ISA string discovery
In reply to Xiang WWhen 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.
--- lib/acpi.h | 28 +++++++++++++++++ lib/riscv/isa.c | 84 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 9 deletions(-)
lib/acpi.h +28 -0
@@ -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()
lib/riscv/isa.c +75 -9
131 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v3 5/9 riscv: Fall back to SBI DBCN when no UART is available
In reply to Xiang WConsole setup currently relies on UART initialization. On EFI/ACPI systems without a supported MMIO UART, initialization fails even when the SBI DBCN console is available.
Probe SBI_EXT_DBCN during console initialization. Use the UART when it is successfully initialized; if no UART is available, fall back to SBI_EXT_DBCN_CONSOLE_WRITE when DBCN is supported. Report when early printing may not work because the initialized UART differs from the early UART base, or because DBCN is used instead.
Rename uart_lock to console_lock, since it protects both console backends.
--- lib/riscv/io.c | 52 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-)
lib/riscv/io.c +33 -19
@@ -28,7 +28,8 @@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; +static bool prefer_dbcn;static u32 uart0_read (u32 num) {
@@ -71,16 +72,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,20 +102,33 @@ 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 ) { + prefer_dbcn =sbi_probe (SBI_EXT_DBCN ); +if (dt_available ())uart0_init_fdt ();else uart0_init_acpi (); +if (!uart0_base && !prefer_dbcn) +assert_msg (false,"No console available" ); +if (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 ); +if (uart0_base) +printf ("WARNING: early print support may not work. " +"Found uart at %p, but early base is %p.\n" , + uart0_base,UART_EARLY_BASE ); +else +printf ("WARNING: early print support may not work. " +"Found DBCN console, but early base is %p.\n" , +UART_EARLY_BASE ); } }
@@ -126,31 +139,32 @@ 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 (uart0_base) +uart0_puts (s); +else if (prefer_dbcn) +sbi_puts (s); +else +assert_msg (false,"No console available" ); }/*
Signature · 1 line
2.47.3
PATCH v3 6/9 riscv: efi: Allow ACPI boots
In reply to Xiang Wriscv/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 adds -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--- riscv/efi/run | 5 ----- 1 file changed, 5 deletions(-)
riscv/efi/run +0 -5
@@ -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
Signature · 1 line
2.47.3
PATCH v3 7/9 riscv: Initialize ISA extensions for all harts at CPU setup
In reply to Xiang WMove isa_init() from thread_info_init() into cpu_set_fdt() and cpu_set_acpi().
thread_info_init() only promotes sscratch to the current hart's thread_info. cpu_has_extension() reads cpus[].isa from the boot hart, including for secondaries that have not started yet, so ISA parsing has to happen while enumerating CPUs.
--- lib/riscv/processor.c | 1 - lib/riscv/setup.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-)
lib/riscv/processor.c +0 -1
@@ -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]); }
lib/riscv/setup.c +3 -0
@@ -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);
Signature · 1 line
2.47.3
PATCH v3 8/9 riscv: Capture IMSIC addresses at boot time
In reply to Xiang WTests may want to use the IMSICs for MSIs and the upcoming BRS tests want to confirm IMSICs are present. Provide those tests the S-mode interrupt file addresses at boot time. Parse DT IMSIC nodes from cpu_set_fdt() via imsic_init(). On ACPI, copy imsic_addr from the MADT RINTC entry only when an IMSIC structure is present; ACPI requires OSPM to ignore RINTC.imsic_addr otherwise.
--- lib/riscv/asm/imsic.h | 8 ++++ lib/riscv/asm/processor.h | 1 + lib/riscv/imsic.c | 86 +++++++++++++++++++++++++++++++++++++++ lib/riscv/setup.c | 13 ++++++ riscv/Makefile | 1 + 5 files changed, 109 insertions(+) create mode 100644 lib/riscv/asm/imsic.h create mode 100644 lib/riscv/imsic.c
lib/riscv/asm/imsic.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMRISCV_IMSIC_H_ +#define _ASMRISCV_IMSIC_H_ +#include <asm/processor.h> + +void imsic_init (struct thread_info *ti); + +#endif /* _ASMRISCV_IMSIC_H_ */
lib/riscv/asm/processor.h +1 -0
@@ -16,6 +16,7 @@ struct thread_info {unsigned long hartid;unsigned long uid;unsigned long isa[1 ]; +phys_addr_t imsic_pa;/* S-level interrupt file, INVALID_PHYS_ADDR if none */ unsigned long sp;exception_fn exception_handlers[EXCEPTION_CAUSE_MAX ];exception_fn interrupt_handlers[INTERRUPT_CAUSE_MAX ];
lib/riscv/imsic.c new file +86 -0
86 lines not on this page · raw message
lib/riscv/setup.c +13 -0
@@ -16,6 +16,7 @@#include <on-cpus.h> #include <vmalloc.h> #include <asm/csr.h> +#include <asm/imsic.h> #include <asm/isa.h> #include <asm/mmu.h> #include <asm/page.h>
@@ -52,6 +53,14 @@ static struct mem_region riscv_mem_regions[NR_MEM_REGIONS + 1];#ifdef CONFIG_EFI #include <acpi.h> +static bool has_imsic = false; + +static int acpi_find_imsic (struct acpi_subtable_header *header) +{ + has_imsic = true; +return 0 ; +} +static int cpu_set_acpi (struct acpi_subtable_header *header) {int cpu = nr_cpus++;
@@ -62,6 +71,8 @@ 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; +/* RINTC.imsic_addr is ignored unless an IMSIC MADT structure is present. */ + cpus[cpu].imsic_pa = has_imsic ? intc->imsic_addr :INVALID_PHYS_ADDR ;isa_init (&cpus[cpu]);if (intc->flags &ACPI_MADT_ENABLED ) {
@@ -81,6 +92,7 @@ static void cpu_set_fdt(int fdtnode __unused, u64 regval, void *info __unused) cpus[cpu].cpu = cpu; cpus[cpu].hartid = regval; +imsic_init (&cpus[cpu]);isa_init (&cpus[cpu]);if (!sbi_hart_get_status (cpus[cpu].hartid).error)
@@ -90,6 +102,7 @@ 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_IMSIC , acpi_find_imsic);acpi_table_parse_madt (ACPI_MADT_TYPE_RINTC , cpu_set_acpi);#else assert_msg (false,"ACPI not available" );
riscv/Makefile +1 -0
@@ -39,6 +39,7 @@ cflatobjs += lib/on-cpus.o cflatobjs += lib/vmalloc.o cflatobjs += lib/riscv/bitops.o cflatobjs += lib/riscv/delay.o +cflatobjs += lib/riscv/imsic.o cflatobjs += lib/riscv/io.o cflatobjs += lib/riscv/isa.o cflatobjs += lib/riscv/mmu.o
Signature · 1 line
2.47.3
PATCH v3 9/9 riscv: Add BRS SBI requirement tests
In reply to Xiang WAdd 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.
--- lib/riscv/asm/isa.h | 3 + lib/riscv/asm/sbi.h | 8 +- lib/riscv/isa.c | 12 ++- riscv/Makefile | 1 + riscv/riscv-brs.c | 192 ++++++++++++++++++++++++++++++++++++++++++++ riscv/unittests.cfg | 4 + 6 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 riscv/riscv-brs.c
lib/riscv/asm/isa.h +3 -0
@@ -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 , };
lib/riscv/asm/sbi.h +5 -3
@@ -44,13 +44,15 @@enum sbi_ext_id {SBI_EXT_BASE =0x10 ,SBI_EXT_TIME =0x54494d45 , -SBI_EXT_IPI =0x735049 , -SBI_EXT_HSM =0x48534d , +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 , -SBI_EXT_SSE =0x535345 , +SBI_EXT_SSE =0x535345 ,SBI_EXT_DBTR =0x44425452 , };
lib/riscv/isa.c +10 -2
@@ -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)
riscv/Makefile +1 -0
@@ -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)
riscv/riscv-brs.c new file +192 -0
192 lines not on this page · raw message
riscv/unittests.cfg +4 -0
@@ -22,3 +22,7 @@ groups = sbi [dbltrp] file = isa-dbltrp.flat groups = isa sbi + +[riscv-brs] +file = riscv-brs.flat +groups = riscv-brs nodefault
Signature · 1 line
2.47.3