Files
linux/lib/raid6/rvv.h
Chunyan Zhang 3c58d7a513 raid6: riscv: Allow code to be compiled in userspace
To support userspace raid6test, this patch adds __KERNEL__ ifdef for kernel
header inclusions also userspace wrapper definitions to allow code to be
compiled in userspace.

This patch also drops the NSIZE macro, instead of using the vector length,
which can work for both kernel and user space.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn>
Link: https://patch.msgid.link/20250718072711.3865118-5-zhangchunyan@iscas.ac.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>
2025-11-19 09:19:28 -07:00

57 lines
1.4 KiB
C

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright 2024 Institute of Software, CAS.
*
* raid6/rvv.h
*
* Definitions for RISC-V RAID-6 code
*/
#ifdef __KERNEL__
#include <asm/vector.h>
#else
#define kernel_vector_begin()
#define kernel_vector_end()
#include <sys/auxv.h>
#include <asm/hwcap.h>
#define has_vector() (getauxval(AT_HWCAP) & COMPAT_HWCAP_ISA_V)
#endif
#include <linux/raid/pq.h>
static int rvv_has_vector(void)
{
return has_vector();
}
#define RAID6_RVV_WRAPPER(_n) \
static void raid6_rvv ## _n ## _gen_syndrome(int disks, \
size_t bytes, void **ptrs) \
{ \
void raid6_rvv ## _n ## _gen_syndrome_real(int d, \
unsigned long b, void **p); \
kernel_vector_begin(); \
raid6_rvv ## _n ## _gen_syndrome_real(disks, \
(unsigned long)bytes, ptrs); \
kernel_vector_end(); \
} \
static void raid6_rvv ## _n ## _xor_syndrome(int disks, \
int start, int stop, \
size_t bytes, void **ptrs) \
{ \
void raid6_rvv ## _n ## _xor_syndrome_real(int d, \
int s1, int s2, \
unsigned long b, void **p); \
kernel_vector_begin(); \
raid6_rvv ## _n ## _xor_syndrome_real(disks, \
start, stop, (unsigned long)bytes, ptrs); \
kernel_vector_end(); \
} \
struct raid6_calls const raid6_rvvx ## _n = { \
raid6_rvv ## _n ## _gen_syndrome, \
raid6_rvv ## _n ## _xor_syndrome, \
rvv_has_vector, \
"rvvx" #_n, \
0 \
}