linux: remove kernel version checks for unsupported kernels
[zfs.git] / include / os / linux / kernel / linux / simd_aarch64.h
blobe580fbe23ea59492352f9e8af0df911145eebd7a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (C) 2016 Romain Dolbeau <romain@dolbeau.org>.
24 * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
25 * Copyright (C) 2022 Sebastian Gottschall <s.gottschall@dd-wrt.com>
29 * USER API:
31 * Kernel fpu methods:
32 * kfpu_allowed()
33 * kfpu_begin()
34 * kfpu_end()
35 * kfpu_init()
36 * kfpu_fini()
38 * SIMD support:
40 * Following functions should be called to determine whether CPU feature
41 * is supported. All functions are usable in kernel and user space.
42 * If a SIMD algorithm is using more than one instruction set
43 * all relevant feature test functions should be called.
45 * Supported features:
46 * zfs_neon_available()
47 * zfs_sha256_available()
48 * zfs_sha512_available()
51 #ifndef _LINUX_SIMD_AARCH64_H
52 #define _LINUX_SIMD_AARCH64_H
54 #include <sys/types.h>
55 #include <asm/neon.h>
56 #include <asm/elf.h>
57 #include <asm/hwcap.h>
58 #include <linux/version.h>
59 #include <asm/sysreg.h>
61 #define ID_AA64PFR0_EL1 sys_reg(3, 0, 0, 1, 0)
62 #define ID_AA64ISAR0_EL1 sys_reg(3, 0, 0, 6, 0)
64 #if (defined(HAVE_KERNEL_NEON) && defined(CONFIG_KERNEL_MODE_NEON))
65 #define kfpu_allowed() 1
66 #define kfpu_begin() kernel_neon_begin()
67 #define kfpu_end() kernel_neon_end()
68 #else
69 #define kfpu_allowed() 0
70 #define kfpu_begin() do {} while (0)
71 #define kfpu_end() do {} while (0)
72 #endif
73 #define kfpu_init() (0)
74 #define kfpu_fini() do {} while (0)
76 #define get_ftr(id) { \
77 unsigned long __val; \
78 asm("mrs %0, "#id : "=r" (__val)); \
79 __val; \
83 * Check if NEON is available
85 static inline boolean_t
86 zfs_neon_available(void)
88 unsigned long ftr = ((get_ftr(ID_AA64PFR0_EL1)) >> 16) & 0xf;
89 return (ftr == 0 || ftr == 1);
93 * Check if SHA256 is available
95 static inline boolean_t
96 zfs_sha256_available(void)
98 unsigned long ftr = ((get_ftr(ID_AA64ISAR0_EL1)) >> 12) & 0x3;
99 return (ftr & 0x1);
103 * Check if SHA512 is available
105 static inline boolean_t
106 zfs_sha512_available(void)
108 unsigned long ftr = ((get_ftr(ID_AA64ISAR0_EL1)) >> 12) & 0x3;
109 return (ftr & 0x2);
112 #endif /* _LINUX_SIMD_AARCH64_H */