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