riscv: sbi: Add SUSP tests
Subsystems (4)
cover riscv: sbi: Add SUSP tests
Add tests for the SBI SUSP extension.
Based-on: https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv/sbi
Andrew Jones (3):
riscv: Implement setjmp/longjmp
riscv: sbi: Clean up env checking
riscv: sbi: Add SUSP tests
lib/riscv/asm/asm.h | 3 + lib/riscv/asm/sbi.h | 1 + lib/riscv/setjmp.S | 50 +++++++ lib/setjmp.h | 4 + riscv/Makefile | 1 + riscv/sbi-asm.S | 55 ++++++++ riscv/sbi-tests.h | 19 +++ riscv/sbi.c | 308 ++++++++++++++++++++++++++++++++++++++++---- 8 files changed, 417 insertions(+), 24 deletions(-) create mode 100644 lib/riscv/setjmp.S
Signature · 1 line
2.47.0
PATCH 1/3 riscv: Implement setjmp/longjmp
Being able to do setjmp and longjmp can be quite useful for tests. Implement the functions for riscv.
--- lib/riscv/setjmp.S | 50 ++++++++++++++++++++++++++++++++++++++++++++++ lib/setjmp.h | 4 ++++ riscv/Makefile | 1 + 3 files changed, 55 insertions(+) create mode 100644 lib/riscv/setjmp.S
lib/riscv/setjmp.S new file +50 -0
@@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#define __ASSEMBLY__ +#include <asm/asm.h> + +.section .text + +.balign 4 +.global setjmp +setjmp: + REG_S ra, (0 * SZREG)(a0) + REG_S s0, (1 * SZREG)(a0) + REG_S s1, (2 * SZREG)(a0) + REG_S s2, (3 * SZREG)(a0) + REG_S s3, (4 * SZREG)(a0) + REG_S s4, (5 * SZREG)(a0) + REG_S s5, (6 * SZREG)(a0) + REG_S s6, (7 * SZREG)(a0) + REG_S s7, (8 * SZREG)(a0) + REG_S s8, (9 * SZREG)(a0) + REG_S s9, (10 * SZREG)(a0) + REG_S s10, (11 * SZREG)(a0) + REG_S s11, (12 * SZREG)(a0) + REG_S sp, (13 * SZREG)(a0) + REG_S gp, (14 * SZREG)(a0) + REG_S tp, (15 * SZREG)(a0) + li a0, 0 + ret + +.balign 4 +.global longjmp +longjmp: + REG_L ra, (0 * SZREG)(a0) + REG_L s0, (1 * SZREG)(a0) + REG_L s1, (2 * SZREG)(a0) + REG_L s2, (3 * SZREG)(a0) + REG_L s3, (4 * SZREG)(a0) + REG_L s4, (5 * SZREG)(a0) + REG_L s5, (6 * SZREG)(a0) + REG_L s6, (7 * SZREG)(a0) + REG_L s7, (8 * SZREG)(a0) + REG_L s8, (9 * SZREG)(a0) + REG_L s9, (10 * SZREG)(a0) + REG_L s10, (11 * SZREG)(a0) + REG_L s11, (12 * SZREG)(a0) + REG_L sp, (13 * SZREG)(a0) + REG_L gp, (14 * SZREG)(a0) + REG_L tp, (15 * SZREG)(a0) + seqz a0, a1 + add a0, a0, a1 + ret
lib/setjmp.h +4 -0
@@ -8,7 +8,11 @@#define _LIBCFLAT_SETJMP_H_typedef struct jmp_buf_tag { +#if defined(__i386__) || defined(__x86_64__)long int regs[8 ]; +#elif defined(__riscv) +long int regs[16 ]; +#endif }jmp_buf [1 ];extern int setjmp (struct jmp_buf_tag env[1 ]);
riscv/Makefile +1 -0
@@ -36,6 +36,7 @@ cflatobjs += lib/riscv/isa.o cflatobjs += lib/riscv/mmu.o cflatobjs += lib/riscv/processor.o cflatobjs += lib/riscv/sbi.o +cflatobjs += lib/riscv/setjmp.o cflatobjs += lib/riscv/setup.o cflatobjs += lib/riscv/smp.o cflatobjs += lib/riscv/stack.o
Signature · 1 line
2.47.0
PATCH 2/3 riscv: sbi: Clean up env checking
In reply to Andrew JonesAdd a couple helpers to cleanup checking of test configuration environment variables.
--- riscv/sbi.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
riscv/sbi.c +19 -13
@@ -74,6 +74,20 @@ static phys_addr_t get_highest_addr(void)return highest_end -1 ; } +static bool env_enabled (const char *env) +{ +char *s =getenv (env); + +return s && (*s =='1' || *s =='y' || *s =='Y' ); +} + +static bool env_disabled (const char *env) +{ +char *s =getenv (env); + +return !(s && (*s =='0' || *s =='n' || *s =='N' )); +} +static bool env_or_skip (const char *env) {if (!getenv (env)) {
@@ -348,7 +362,6 @@ static void check_dbcn(void)bool highmem_supported = true;phys_addr_t paddr;struct sbiret ret; -const char *tmp;char *buf;report_prefix_push ("dbcn" );
@@ -371,13 +384,11 @@ static void check_dbcn(void)dbcn_write_test (&buf[PAGE_SIZE - num_bytes /2 ], num_bytes, false);report_prefix_pop (); - tmp =getenv ("SBI_HIGHMEM_NOT_SUPPORTED" ); -if (tmp &&atol (tmp) !=0 ) +if (env_enabled ("SBI_HIGHMEM_NOT_SUPPORTED" )) highmem_supported = false;report_prefix_push ("high boundary" ); - tmp =getenv ("SBI_DBCN_SKIP_HIGH_BOUNDARY" ); -if (!tmp ||atol (tmp) ==0 ) +if (env_disabled ("SBI_DBCN_SKIP_HIGH_BOUNDARY" ))dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes,HIGH_ADDR_BOUNDARY -PAGE_SIZE ,PAGE_SIZE - num_bytes /2 , highmem_supported);
@@ -386,12 +397,8 @@ static void check_dbcn(void)report_prefix_pop ();report_prefix_push ("high page" ); - tmp =getenv ("SBI_DBCN_SKIP_HIGH_PAGE" ); -if (!tmp ||atol (tmp) ==0 ) { - paddr =HIGH_ADDR_BOUNDARY ; - tmp =getenv ("HIGH_PAGE" ); -if (tmp) - paddr =strtoull (tmp,NULL ,0 ); +if (env_disabled ("SBI_DBCN_SKIP_HIGH_PAGE" )) { + paddr =getenv ("HIGH_PAGE" ) ?strtoull (getenv ("HIGH_PAGE" ),NULL ,0 ) :HIGH_ADDR_BOUNDARY ;dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes, paddr,0 , highmem_supported); }else {report_skip ("user disabled" );
@@ -400,8 +407,7 @@ static void check_dbcn(void)/* Bytes are read from memory and written to the console */ report_prefix_push ("invalid parameter" ); - tmp =getenv ("INVALID_ADDR_AUTO" ); -if (tmp &&atol (tmp) ==1 ) { +if (env_enabled ("INVALID_ADDR_AUTO" )) { paddr =get_highest_addr () +1 ; do_invalid_addr = true; }else if (env_or_skip ("INVALID_ADDR" )) {
Signature · 1 line
2.47.0
Re: [kvm-unit-tests PATCH 2/3] riscv: sbi: Clean up env checking
Quoted 19 lines · Andrew Jones
Add a couple helpers to cleanup checking of test configuration environment variables.
Signed-off-by Andrew Jones <[email protected]>--- riscv/sbi.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)riscv/sbi.c +3
-0@@ -74,6 +74,20 @@ static phys_addr_t get_highest_addr(void)return highest_end -1 ; } +static bool env_enabled (const char *env) +{ +char *s =getenv (env);
riscv/sbi.c static phys_addr_t get_highest_addr(void) · line 89
Quoted 10 lines
riscv/sbi.c +10
-0+ +return s && (*s =='1' || *s =='y' || *s =='Y' ); +} + +static bool env_disabled (const char *env) +{ +char *s =getenv (env); + +return !(s && (*s =='0' || *s =='n' || *s =='N' )); +}
I've dropped env_disabled() since what I really want is !env_enabled()
Quoted 61 lines
riscv/sbi.c +6
-13+static bool env_or_skip (const char *env) {if (!getenv (env)) {@@ -348,7 +362,6 @@ static void check_dbcn(void)bool highmem_supported = true;phys_addr_t paddr;struct sbiret ret; -const char *tmp;char *buf;report_prefix_push ("dbcn" );@@ -371,13 +384,11 @@ static void check_dbcn(void)dbcn_write_test (&buf[PAGE_SIZE - num_bytes /2 ], num_bytes, false);report_prefix_pop (); - tmp =getenv ("SBI_HIGHMEM_NOT_SUPPORTED" ); -if (tmp &&atol (tmp) !=0 ) +if (env_enabled ("SBI_HIGHMEM_NOT_SUPPORTED" )) highmem_supported = false;report_prefix_push ("high boundary" ); - tmp =getenv ("SBI_DBCN_SKIP_HIGH_BOUNDARY" ); -if (!tmp ||atol (tmp) ==0 ) +if (env_disabled ("SBI_DBCN_SKIP_HIGH_BOUNDARY" ))dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes,HIGH_ADDR_BOUNDARY -PAGE_SIZE ,PAGE_SIZE - num_bytes /2 , highmem_supported);@@ -386,12 +397,8 @@ static void check_dbcn(void)report_prefix_pop ();report_prefix_push ("high page" ); - tmp =getenv ("SBI_DBCN_SKIP_HIGH_PAGE" ); -if (!tmp ||atol (tmp) ==0 ) { - paddr =HIGH_ADDR_BOUNDARY ; - tmp =getenv ("HIGH_PAGE" ); -if (tmp) - paddr =strtoull (tmp,NULL ,0 ); +if (env_disabled ("SBI_DBCN_SKIP_HIGH_PAGE" )) { + paddr =getenv ("HIGH_PAGE" ) ?strtoull (getenv ("HIGH_PAGE" ),NULL ,0 ) :HIGH_ADDR_BOUNDARY ;dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes, paddr,0 , highmem_supported); }else {report_skip ("user disabled" );@@ -400,8 +407,7 @@ static void check_dbcn(void)/* Bytes are read from memory and written to the console */ report_prefix_push ("invalid parameter" ); - tmp =getenv ("INVALID_ADDR_AUTO" ); -if (tmp &&atol (tmp) ==1 ) { +if (env_enabled ("INVALID_ADDR_AUTO" )) { paddr =get_highest_addr () +1 ; do_invalid_addr = true; }else if (env_or_skip ("INVALID_ADDR" )) {Signature · 7 lines
2.47.0 -- kvm-riscv mailing list kvm-riscv at lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH 3/3 riscv: sbi: Add SUSP tests
In reply to Andrew JonesIntroduce tests for SBI system suspend. The basic test makes sure it works and other tests make sure it fails as expected with invalid entry criteria.
To test on QEMU or hardware the firmware needs to support system suspend. For QEMU, OpenSBI can be told to enable its system suspend test mode by creating a new DTB which has
opensbi-config {
compatible = "opensbi,config";
system-suspend-test;
};added to the 'chosen' node. Then, run with '-dtb susp.dtb'.
--- lib/riscv/asm/asm.h | 3 + lib/riscv/asm/sbi.h | 1 + riscv/sbi-asm.S | 55 +++++++++ riscv/sbi-tests.h | 19 +++ riscv/sbi.c | 278 ++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 344 insertions(+), 12 deletions(-)
lib/riscv/asm/asm.h +3 -0
@@ -14,6 +14,9 @@#define REG_S __REG_SEL(sd, sw)#define SZREG __REG_SEL(8, 4) +/* ASMARR() may be used with arrays of longs */ +#define ASMARR (reg, idx) ((idx) * SZREG)(reg) +#define FP_SIZE 16#endif /* _ASMRISCV_ASM_H_ */
lib/riscv/asm/sbi.h +1 -0
@@ -22,6 +22,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534d ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_DBCN =0x4442434E , + SBI_EXT_SUSP = 0x53555350, }; enum sbi_ext_base_fid {
riscv/sbi-asm.S +55 -0
64 lines not on this page · raw message
riscv/sbi-tests.h +19 -0
@@ -2,9 +2,28 @@#ifndef _RISCV_SBI_TESTS_H_#define _RISCV_SBI_TESTS_H_ +#define SBI_CSR_SSTATUS_IDX 0 +#define SBI_CSR_SIE_IDX 1 +#define SBI_CSR_STVEC_IDX 2 +#define SBI_CSR_SSCRATCH_IDX 3 +#define SBI_CSR_SATP_IDX 4 +#define SBI_HSM_TEST_DONE (1 << 0)#define SBI_HSM_TEST_HARTID_A1 (1 << 1)#define SBI_HSM_TEST_SATP (1 << 2)#define SBI_HSM_TEST_SIE (1 << 3) +#define SBI_SUSP_TEST_SATP (1 << 0) +#define SBI_SUSP_TEST_SIE (1 << 1) +#define SBI_SUSP_TEST_HARTID (1 << 2) +#define SBI_SUSP_TEST_MASK 7 + +#define SBI_SUSP_MAGIC 0x505b + +#define SBI_SUSP_MAGIC_IDX 0 +#define SBI_SUSP_CSRS_IDX 1 +#define SBI_SUSP_HARTID_IDX 2 +#define SBI_SUSP_TESTNUM_IDX 3 +#define SBI_SUSP_RESULTS_IDX 4 +#endif /* _RISCV_SBI_TESTS_H_ */
riscv/sbi.c +266 -12
329 lines not on this page · raw message
Signature · 1 line
2.47.0
Quoted 9 lines · Andrew Jones
Add tests for the SBI SUSP extension.
Based-on: https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv/sbi
Andrew Jones (3):
riscv: Implement setjmp/longjmp
riscv: sbi: Clean up env checking
riscv: sbi: Add SUSP tests
Quoted 14 lines
lib/riscv/asm/asm.h | 3 + lib/riscv/asm/sbi.h | 1 + lib/riscv/setjmp.S | 50 +++++++ lib/setjmp.h | 4 + riscv/Makefile | 1 + riscv/sbi-asm.S | 55 ++++++++ riscv/sbi-tests.h | 19 +++ riscv/sbi.c | 308 ++++++++++++++++++++++++++++++++++++++++---- 8 files changed, 417 insertions(+), 24 deletions(-) create mode 100644 lib/riscv/setjmp.SSignature · 1 line
2.47.0
Merged through riscv/sbi.
Thanks,
drew