1 // SPDX-License-Identifier: GPL-2.0-only 2 3 #include "../hwprobe/hwprobe.h" 4 #include <asm/vendor/thead.h> 5 #include <stdbool.h> 6 #include <stdlib.h> 7 #include <stdio.h> 8 #include <unistd.h> 9 #include <sys/wait.h> 10 11 bool is_xtheadvector_supported(void) 12 { 13 struct riscv_hwprobe pair; 14 15 pair.key = RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0; 16 riscv_hwprobe(&pair, 1, 0, NULL, 0); 17 return pair.value & RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR; 18 } 19 20 bool is_vector_supported(void) 21 { 22 struct riscv_hwprobe pair; 23 24 pair.key = RISCV_HWPROBE_KEY_IMA_EXT_0; 25 riscv_hwprobe(&pair, 1, 0, NULL, 0); 26 return pair.value & RISCV_HWPROBE_EXT_ZVE32X; 27 } 28 29 int launch_test(char *next_program, int test_inherit, int xtheadvector) 30 { 31 char *exec_argv[4], *exec_envp[1]; 32 int rc, pid, status; 33 34 pid = fork(); 35 if (pid < 0) { 36 printf("fork failed %d", pid); 37 return -1; 38 } 39 40 if (!pid) { 41 exec_argv[0] = next_program; 42 exec_argv[1] = test_inherit != 0 ? "x" : NULL; 43 exec_argv[2] = xtheadvector != 0 ? "x" : NULL; 44 exec_argv[3] = NULL; 45 exec_envp[0] = NULL; 46 /* launch the program again to check inherit */ 47 rc = execve(next_program, exec_argv, exec_envp); 48 if (rc) { 49 perror("execve"); 50 printf("child execve failed %d\n", rc); 51 exit(-1); 52 } 53 } 54 55 rc = waitpid(-1, &status, 0); 56 if (rc < 0) { 57 printf("waitpid failed\n"); 58 return -3; 59 } 60 61 if ((WIFEXITED(status) && WEXITSTATUS(status) == -1) || 62 WIFSIGNALED(status)) { 63 printf("child exited abnormally\n"); 64 return -4; 65 } 66 67 return WEXITSTATUS(status); 68 } 69