1*2a58b312SMartin Matuska /*
2*2a58b312SMartin Matuska  * CDDL HEADER START
3*2a58b312SMartin Matuska  *
4*2a58b312SMartin Matuska  * The contents of this file are subject to the terms of the
5*2a58b312SMartin Matuska  * Common Development and Distribution License (the "License").
6*2a58b312SMartin Matuska  * You may not use this file except in compliance with the License.
7*2a58b312SMartin Matuska  *
8*2a58b312SMartin Matuska  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2a58b312SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10*2a58b312SMartin Matuska  * See the License for the specific language governing permissions
11*2a58b312SMartin Matuska  * and limitations under the License.
12*2a58b312SMartin Matuska  *
13*2a58b312SMartin Matuska  * When distributing Covered Code, include this CDDL HEADER in each
14*2a58b312SMartin Matuska  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2a58b312SMartin Matuska  * If applicable, add the following below this CDDL HEADER, with the
16*2a58b312SMartin Matuska  * fields enclosed by brackets "[]" replaced with your own identifying
17*2a58b312SMartin Matuska  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2a58b312SMartin Matuska  *
19*2a58b312SMartin Matuska  * CDDL HEADER END
20*2a58b312SMartin Matuska  */
21*2a58b312SMartin Matuska 
22*2a58b312SMartin Matuska /*
23*2a58b312SMartin Matuska  * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
24*2a58b312SMartin Matuska  */
25*2a58b312SMartin Matuska 
26*2a58b312SMartin Matuska /*
27*2a58b312SMartin Matuska  * USER API:
28*2a58b312SMartin Matuska  *
29*2a58b312SMartin Matuska  * Kernel fpu methods:
30*2a58b312SMartin Matuska  *	kfpu_allowed()
31*2a58b312SMartin Matuska  *	kfpu_begin()
32*2a58b312SMartin Matuska  *	kfpu_end()
33*2a58b312SMartin Matuska  *	kfpu_init()
34*2a58b312SMartin Matuska  *	kfpu_fini()
35*2a58b312SMartin Matuska  *
36*2a58b312SMartin Matuska  * SIMD support:
37*2a58b312SMartin Matuska  *
38*2a58b312SMartin Matuska  * Following functions should be called to determine whether CPU feature
39*2a58b312SMartin Matuska  * is supported. All functions are usable in kernel and user space.
40*2a58b312SMartin Matuska  * If a SIMD algorithm is using more than one instruction set
41*2a58b312SMartin Matuska  * all relevant feature test functions should be called.
42*2a58b312SMartin Matuska  *
43*2a58b312SMartin Matuska  * Supported features:
44*2a58b312SMartin Matuska  *   zfs_neon_available()
45*2a58b312SMartin Matuska  *   zfs_sha256_available()
46*2a58b312SMartin Matuska  */
47*2a58b312SMartin Matuska 
48*2a58b312SMartin Matuska #ifndef _LINUX_SIMD_ARM_H
49*2a58b312SMartin Matuska #define	_LINUX_SIMD_ARM_H
50*2a58b312SMartin Matuska 
51*2a58b312SMartin Matuska #include <sys/types.h>
52*2a58b312SMartin Matuska #include <asm/neon.h>
53*2a58b312SMartin Matuska #include <asm/elf.h>
54*2a58b312SMartin Matuska #include <asm/hwcap.h>
55*2a58b312SMartin Matuska 
56*2a58b312SMartin Matuska #define	kfpu_allowed()		1
57*2a58b312SMartin Matuska #define	kfpu_begin()		kernel_neon_begin()
58*2a58b312SMartin Matuska #define	kfpu_end()		kernel_neon_end()
59*2a58b312SMartin Matuska #define	kfpu_init()		(0)
60*2a58b312SMartin Matuska #define	kfpu_fini()		do {} while (0)
61*2a58b312SMartin Matuska 
62*2a58b312SMartin Matuska /*
63*2a58b312SMartin Matuska  * Check if NEON is available
64*2a58b312SMartin Matuska  */
65*2a58b312SMartin Matuska static inline boolean_t
66*2a58b312SMartin Matuska zfs_neon_available(void)
67*2a58b312SMartin Matuska {
68*2a58b312SMartin Matuska 	return (elf_hwcap & HWCAP_NEON);
69*2a58b312SMartin Matuska }
70*2a58b312SMartin Matuska 
71*2a58b312SMartin Matuska /*
72*2a58b312SMartin Matuska  * Check if SHA256 is available
73*2a58b312SMartin Matuska  */
74*2a58b312SMartin Matuska static inline boolean_t
75*2a58b312SMartin Matuska zfs_sha256_available(void)
76*2a58b312SMartin Matuska {
77*2a58b312SMartin Matuska 	return (elf_hwcap2 & HWCAP2_SHA2);
78*2a58b312SMartin Matuska }
79*2a58b312SMartin Matuska 
80*2a58b312SMartin Matuska #endif /* _LINUX_SIMD_ARM_H */
81