riscv: add SBI SSE extension tests
Subsystems (3)
v5 cover riscv: add SBI SSE extension tests
This series adds an individual test for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
---
V5:
- Update event ranges based on latest spec
- Rename asm-offset-test.c to sbi-asm-offset.c
V4:
- Fix typo sbi_ext_ss_fid -> sbi_ext_sse_fid
- Add proper asm-offset generation for tests
- Move SSE specific file from lib/riscv to riscv/
V3:
- Add -deps variable for test specific dependencies
- Fix formatting errors/typo in sbi.h
- Add missing double trap event
- Alphabetize sbi-sse.c includes
- Fix a6 content after unmasking event
- Add SSE HART_MASK/UNMASK test
- Use mv instead of move
- move sbi_check_sse() definition in sbi.c
- Remove sbi_sse test from unitests.cfg
V2:
- Rebased on origin/master and integrate it into sbi.c tests
Clément Léger (5):
kbuild: allow multiple asm-offsets file to be generated
riscv: use asm-offsets to generate SBI_EXT_HSM values
riscv: Add "-deps" handling for tests
riscv: lib: Add SBI SSE extension definitions
riscv: sbi: Add SSE extension tests
scripts/asm-offsets.mak | 22 +- riscv/Makefile | 10 +- lib/riscv/asm/csr.h | 2 + lib/riscv/asm/sbi.h | 89 ++++ riscv/sbi-tests.h | 12 + riscv/sbi-asm.S | 96 +++- riscv/sbi-asm-offsets.c | 19 + riscv/sbi-sse.c | 1060 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 3 + riscv/.gitignore | 1 + 10 files changed, 1301 insertions(+), 13 deletions(-) create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/sbi-sse.c create mode 100644 riscv/.gitignore
Signature · 1 line
2.47.1
PATCH v5 1/5 kbuild: allow multiple asm-offsets file to be generated
In order to allow multiple asm-offsets files to generated the include guard need to be different between these file. Add a asm_offset_name makefile macro to obtain an uppercase name matching the original asm offsets file.
--- scripts/asm-offsets.mak | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
scripts/asm-offsets.mak +15 -7
@@ -15,10 +15,14 @@ define sed-y s:->::; p;}' endef +define asm_offset_name + $(shell echo $(notdir $(1)) | tr [:lower:]- [:upper:]_) +endef + define make_asm_offsets (set -e; \ - echo "#ifndef __ASM_OFFSETS_H__"; \ - echo "#define __ASM_OFFSETS_H__"; \ + echo "#ifndef __$(strip $(asm_offset_name))_H__"; \ + echo "#define __$(strip $(asm_offset_name))_H__"; \ echo "/*"; \ echo " * Generated file. DO NOT MODIFY."; \ echo " *"; \
@@ -29,12 +33,16 @@ define make_asm_offsets echo "#endif" ) > $@ endef -$(asm-offsets:.h=.s): $(asm-offsets:.h=.c) - $(CC) $(CFLAGS) -fverbose-asm -S -o $@ $< +define gen_asm_offsets_rules +$(1).s: $(1).c + $(CC) $(CFLAGS) -fverbose-asm -S -o $$@ $$< + +$(1).h: $(1).s + $$(call make_asm_offsets,$(1)) + cp -f $$@ lib/generated/ +endef -$(asm-offsets): $(asm-offsets:.h=.s) - $(call make_asm_offsets) - cp -f $(asm-offsets) lib/generated/ +$(foreach o,$(asm-offsets),$(eval $(call gen_asm_offsets_rules, $(o:.h=)))) OBJDIRS += lib/generated
Signature · 1 line
2.47.1
PATCH v5 2/5 riscv: use asm-offsets to generate SBI_EXT_HSM values
In reply to Clément LégerReplace hardcoded values with generated ones using sbi-asm-offset. This allows to directly use ASM_SBI_EXT_HSM and ASM_SBI_EXT_HSM_STOP in assembly.
--- riscv/Makefile | 2 +- riscv/sbi-asm.S | 6 ++++-- riscv/sbi-asm-offsets.c | 12 ++++++++++++ riscv/.gitignore | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/.gitignore
riscv/Makefile +1 -1
@@ -86,7 +86,7 @@ CFLAGS += -ffreestanding CFLAGS += -O2 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -I $(SRCDIR)/riscv -asm-offsets = lib/riscv/asm-offsets.h +asm-offsets = lib/riscv/asm-offsets.h riscv/sbi-asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak %.aux.o: $(SRCDIR)/lib/auxinfo.c
riscv/sbi-asm.S +4 -2
@@ -7,6 +7,8 @@ #define __ASSEMBLY__ #include <asm/asm.h> #include <asm/csr.h> +#include <asm/asm-offsets.h> +#include <generated/sbi-asm-offsets.h> #include "sbi-tests.h"
@@ -58,8 +60,8 @@ sbi_hsm_check: 7: lb t0, 0(t1) pause beqz t0, 7b - li a7, 0x48534d /* SBI_EXT_HSM */ - li a6, 1 /* SBI_EXT_HSM_HART_STOP */ + li a7, ASM_SBI_EXT_HSM + li a6, ASM_SBI_EXT_HSM_HART_STOP ecall 8: pause j 8b
riscv/sbi-asm-offsets.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <kbuild.h> +#include <asm/sbi.h> +#include "sbi-tests.h" + +int main (void ) +{ +DEFINE (ASM_SBI_EXT_HSM ,SBI_EXT_HSM ); +DEFINE (ASM_SBI_EXT_HSM_HART_STOP ,SBI_EXT_HSM_HART_STOP ); + +return 0 ; +}
riscv/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/*-asm-offsets.[hs]
Signature · 1 line
2.47.1
PATCH v5 3/5 riscv: Add "-deps" handling for tests
In reply to Clément LégerSome tests uses additional files that needs to be linked in the final binary. This is the case for asm-sbi.S which is only used by the sbi test. Add a "-deps" per test variable that allows to designate additional .o files.
--- riscv/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
riscv/Makefile +5 -3
@@ -17,6 +17,8 @@ tests += $(TEST_DIR)/sieve.$(exe) all: $(tests) +$(TEST_DIR)/sbi-deps = $(TEST_DIR)/sbi-asm.o + # When built for EFI sieve needs extra memory, run with e.g. '-m 256' on QEMU $(TEST_DIR)/sieve.$(exe): AUXFLAGS = 0x1
@@ -44,7 +46,6 @@ cflatobjs += lib/riscv/timer.o ifeq ($(ARCH),riscv32) cflatobjs += lib/ldiv32.o endif -cflatobjs += riscv/sbi-asm.o ########################################
@@ -93,6 +94,7 @@ include $(SRCDIR)/scripts/asm-offsets.mak $(CC) $(CFLAGS) -c -o $@ $< \ -DPROGNAME=\"$(notdir $(@:.aux.o=.$(exe)))\" -DAUXFLAGS=$(AUXFLAGS) +.SECONDEXPANSION: ifeq ($(CONFIG_EFI),y) # avoid jump tables before all relocations have been processed riscv/efi/reloc_riscv64.o: CFLAGS += -fno-jump-tables
@@ -103,7 +105,7 @@ cflatobjs += lib/efi.o .PRECIOUS: %.so %.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined -%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) %.aux.o +%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) %.aux.o $$($$*-deps) $(LD) $(EFI_LDFLAGS) -o $@ -T $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds \ $(filter %.o, $^) $(FLATLIBS) $(EFI_LIBS)
@@ -119,7 +121,7 @@ cflatobjs += lib/efi.o -O binary $^ $@ else %.elf: LDFLAGS += -pie -n -z notext -%.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) %.aux.o +%.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) %.aux.o $$($$*-deps) $(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/riscv/flat.lds \ $(filter %.o, $^) $(FLATLIBS) @chmod a-x $@
Signature · 1 line
2.47.1
PATCH v5 4/5 riscv: lib: Add SBI SSE extension definitions
In reply to Clément LégerAdd SBI SSE extension definitions in sbi.h
--- lib/riscv/asm/sbi.h | 89 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
lib/riscv/asm/sbi.h +89 -0
@@ -11,6 +11,11 @@#define SBI_ERR_ALREADY_AVAILABLE -6#define SBI_ERR_ALREADY_STARTED -7#define SBI_ERR_ALREADY_STOPPED -8 +#define SBI_ERR_NO_SHMEM -9 +#define SBI_ERR_INVALID_STATE -10 +#define SBI_ERR_BAD_RANGE -11 +#define SBI_ERR_TIMEOUT -12 +#define SBI_ERR_IO -13#ifndef __ASSEMBLY__#include <cpumask.h>
@@ -23,6 +28,7 @@ enum sbi_ext_id {SBI_EXT_SRST =0x53525354 ,SBI_EXT_DBCN =0x4442434E ,SBI_EXT_SUSP =0x53555350 , + SBI_EXT_SSE = 0x535345, }; enum sbi_ext_base_fid {
@@ -71,6 +77,89 @@ enum sbi_ext_dbcn_fid { SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, }; +enum sbi_ext_sse_fid { +SBI_EXT_SSE_READ_ATTRS =0 , +SBI_EXT_SSE_WRITE_ATTRS , +SBI_EXT_SSE_REGISTER , +SBI_EXT_SSE_UNREGISTER , +SBI_EXT_SSE_ENABLE , +SBI_EXT_SSE_DISABLE , +SBI_EXT_SSE_COMPLETE , +SBI_EXT_SSE_INJECT , +SBI_EXT_SSE_HART_UNMASK , +SBI_EXT_SSE_HART_MASK , +}; + +/* SBI SSE Event Attributes. */ +enum sbi_sse_attr_id { +SBI_SSE_ATTR_STATUS =0x00000000 , +SBI_SSE_ATTR_PRIORITY =0x00000001 , +SBI_SSE_ATTR_CONFIG =0x00000002 , +SBI_SSE_ATTR_PREFERRED_HART =0x00000003 , +SBI_SSE_ATTR_ENTRY_PC =0x00000004 , +SBI_SSE_ATTR_ENTRY_ARG =0x00000005 , +SBI_SSE_ATTR_INTERRUPTED_SEPC =0x00000006 , +SBI_SSE_ATTR_INTERRUPTED_FLAGS =0x00000007 , +SBI_SSE_ATTR_INTERRUPTED_A6 =0x00000008 , +SBI_SSE_ATTR_INTERRUPTED_A7 =0x00000009 , +}; + +#define SBI_SSE_ATTR_STATUS_STATE_OFFSET 0 +#define SBI_SSE_ATTR_STATUS_STATE_MASK 0x3 +#define SBI_SSE_ATTR_STATUS_PENDING_OFFSET 2 +#define SBI_SSE_ATTR_STATUS_INJECT_OFFSET 3 + +#define SBI_SSE_ATTR_CONFIG_ONESHOT BIT(0) + +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPP BIT(0) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SSTATUS_SPIE BIT(1) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV BIT(2) +#define SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP BIT(3) + +enum sbi_sse_state { +SBI_SSE_STATE_UNUSED =0 , +SBI_SSE_STATE_REGISTERED =1 , +SBI_SSE_STATE_ENABLED =2 , +SBI_SSE_STATE_RUNNING =3 , +}; + +/* SBI SSE Event IDs. */ +/* Range 0x00000000 - 0x0000ffff */ +#define SBI_SSE_EVENT_LOCAL_HIGH_PRIO_RAS 0x00000000 +#define SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP 0x00000001 +#define SBI_SSE_EVENT_LOCAL_PLAT_0_START 0x00004000 +#define SBI_SSE_EVENT_LOCAL_PLAT_0_END 0x00007fff + +#define SBI_SSE_EVENT_GLOBAL_HIGH_PRIO_RAS 0x00008000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_0_START 0x0000c000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_0_END 0x0000ffff + +/* Range 0x00010000 - 0x0001ffff */ +#define SBI_SSE_EVENT_LOCAL_PMU_OVERFLOW 0x00010000 +#define SBI_SSE_EVENT_LOCAL_PLAT_1_START 0x00014000 +#define SBI_SSE_EVENT_LOCAL_PLAT_1_END 0x00017fff +#define SBI_SSE_EVENT_GLOBAL_PLAT_1_START 0x0001c000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_1_END 0x0001ffff + +/* Range 0x00100000 - 0x0010ffff */ +#define SBI_SSE_EVENT_LOCAL_LOW_PRIO_RAS 0x00100000 +#define SBI_SSE_EVENT_LOCAL_PLAT_2_START 0x00104000 +#define SBI_SSE_EVENT_LOCAL_PLAT_2_END 0x00107fff +#define SBI_SSE_EVENT_GLOBAL_LOW_PRIO_RAS 0x00108000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_2_START 0x0010c000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_2_END 0x0010ffff + +/* Range 0xffff0000 - 0xffffffff */ +#define SBI_SSE_EVENT_LOCAL_SOFTWARE 0xffff0000 +#define SBI_SSE_EVENT_LOCAL_PLAT_3_START 0xffff4000 +#define SBI_SSE_EVENT_LOCAL_PLAT_3_END 0xffff7fff +#define SBI_SSE_EVENT_GLOBAL_SOFTWARE 0xffff8000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_3_START 0xffffc000 +#define SBI_SSE_EVENT_GLOBAL_PLAT_3_END 0xffffffff + +#define SBI_SSE_EVENT_PLATFORM_BIT BIT(14) +#define SBI_SSE_EVENT_GLOBAL_BIT BIT(15) +struct sbiret {long error;long value;
Signature · 1 line
2.47.1
PATCH v5 5/5 riscv: sbi: Add SSE extension tests
In reply to Clément LégerAdd SBI SSE extension tests for the following features:
- Test attributes errors (invalid values, RO, etc)
- Registration errors
- Simple events (register, enable, inject)
- Events with different priorities
- Global events dispatch on different harts
- Local events on all harts
- Hart mask/unmask events
--- riscv/Makefile | 2 +- lib/riscv/asm/csr.h | 2 + riscv/sbi-tests.h | 12 + riscv/sbi-asm.S | 90 ++++ riscv/sbi-asm-offsets.c | 7 + riscv/sbi-sse.c | 1060 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 3 + 7 files changed, 1175 insertions(+), 1 deletion(-) create mode 100644 riscv/sbi-sse.c
riscv/Makefile +1 -1
@@ -17,7 +17,7 @@ tests += $(TEST_DIR)/sieve.$(exe) all: $(tests) -$(TEST_DIR)/sbi-deps = $(TEST_DIR)/sbi-asm.o +$(TEST_DIR)/sbi-deps = $(TEST_DIR)/sbi-asm.o $(TEST_DIR)/sbi-sse.o # When built for EFI sieve needs extra memory, run with e.g. '-m 256' on QEMU $(TEST_DIR)/sieve.$(exe): AUXFLAGS = 0x1
lib/riscv/asm/csr.h +2 -0
@@ -21,6 +21,8 @@/* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1)) +#define SSTATUS_SPP _AC(0x00000100, UL)/* Previously Supervisor */ +/* Exception causes */ #define EXC_INST_MISALIGNED 0#define EXC_INST_ACCESS 1
riscv/sbi-tests.h +12 -0
@@ -33,4 +33,16 @@#define SBI_SUSP_TEST_HARTID (1 << 2)#define SBI_SUSP_TEST_MASK 7 +#ifndef __ASSEMBLY__ + +typedef void (*sse_handler_fn )(void *data,struct pt_regs *regs,unsigned int hartid); + +struct sse_handler_arg { +unsigned long reg_tmp; +sse_handler_fn handler; +void *handler_data; +void *stack; +}; + +#endif /* !__ASSEMBLY__ */ #endif /* _RISCV_SBI_TESTS_H_ */
riscv/sbi-asm.S +90 -0
94 lines not on this page · raw message
riscv/sbi-asm-offsets.c +7 -0
@@ -7,6 +7,13 @@ int main(void) {DEFINE (ASM_SBI_EXT_HSM ,SBI_EXT_HSM );DEFINE (ASM_SBI_EXT_HSM_HART_STOP ,SBI_EXT_HSM_HART_STOP ); +DEFINE (ASM_SBI_EXT_SSE ,SBI_EXT_SSE ); +DEFINE (ASM_SBI_EXT_SSE_COMPLETE ,SBI_EXT_SSE_COMPLETE ); + +OFFSET (SBI_SSE_REG_TMP , sse_handler_arg, reg_tmp); +OFFSET (SBI_SSE_HANDLER , sse_handler_arg, handler); +OFFSET (SBI_SSE_HANDLER_DATA , sse_handler_arg, handler_data); +OFFSET (SBI_SSE_HANDLER_STACK , sse_handler_arg, stack);return 0 ; }
riscv/sbi-sse.c new file +1060 -0
1,060 lines not on this page · raw message
riscv/sbi.c +3 -0
@@ -32,6 +32,8 @@#define HIGH_ADDR_BOUNDARY ((phys_addr_t)1 << 32) +void check_sse (void ); +static long __labs (long a) {return __builtin_labs (a);
@@ -1451,6 +1453,7 @@ int main(int argc, char **argv)check_hsm ();check_dbcn ();check_susp (); +check_sse ();return report_summary (); }
Signature · 1 line
2.47.1
After testing with a clean build, it seems like asm-offset.h generation is broken.
Sorry for that, I'll fix it and sent another version.
Thanks,
Clément
Quoted 52 lines · Clément Léger
This series adds an individual test for SBI SSE extension as well as needed infrastructure for SSE support. It also adds test specific asm-offsets generation to use custom OFFSET and DEFINE from the test directory.
---
V5:
- Update event ranges based on latest spec
- Renameasm-offset-test.ctosbi-asm-offset.cV4:
- Fix typosbi_ext_ss_fid->sbi_ext_sse_fid
- Add proper asm-offset generation for tests
- Move SSE specific file from lib/riscv to riscv/V3:
- Add -deps variable for test specific dependencies
- Fix formatting errors/typo insbi.h
- Add missing double trap event
- Alphabetizesbi-sse.cincludes
- Fix a6 content after unmasking event
- Add SSE HART_MASK/UNMASK test
- Use mv instead of move
- movesbi_check_sse()definition insbi.c
- Removesbi_ssetest from unitests.cfgV2:
- Rebased on origin/master and integrate it intosbi.ctestsClément Léger (5):
kbuild: allow multiple asm-offsets file to be generated
riscv: use asm-offsets to generateSBI_EXT_HSMvalues
riscv: Add "-deps" handling for tests
riscv: lib: Add SBI SSE extension definitions
riscv: sbi: Add SSE extension testsscripts/asm-offsets.mak | 22 +- riscv/Makefile | 10 +- lib/riscv/asm/csr.h | 2 + lib/riscv/asm/sbi.h | 89 ++++ riscv/sbi-tests.h | 12 + riscv/sbi-asm.S | 96 +++- riscv/sbi-asm-offsets.c | 19 + riscv/sbi-sse.c | 1060 +++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 3 + riscv/.gitignore | 1 + 10 files changed, 1301 insertions(+), 13 deletions(-) create mode 100644 riscv/sbi-asm-offsets.c create mode 100644 riscv/sbi-sse.c create mode 100644 riscv/.gitignore