1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de> 24 */ 25 26 /* 27 * USER API: 28 * 29 * Kernel fpu methods: 30 * kfpu_allowed() 31 * kfpu_begin() 32 * kfpu_end() 33 * kfpu_init() 34 * kfpu_fini() 35 * 36 * SIMD support: 37 * 38 * Following functions should be called to determine whether CPU feature 39 * is supported. All functions are usable in kernel and user space. 40 * If a SIMD algorithm is using more than one instruction set 41 * all relevant feature test functions should be called. 42 * 43 * Supported features: 44 * zfs_neon_available() 45 * zfs_sha256_available() 46 */ 47 48 #ifndef _LINUX_SIMD_ARM_H 49 #define _LINUX_SIMD_ARM_H 50 51 #include <sys/types.h> 52 #include <asm/neon.h> 53 #include <asm/elf.h> 54 #include <asm/hwcap.h> 55 56 #if (defined(HAVE_KERNEL_NEON) && defined(CONFIG_KERNEL_MODE_NEON)) 57 #define kfpu_allowed() 1 58 #define kfpu_begin() kernel_neon_begin() 59 #define kfpu_end() kernel_neon_end() 60 #else 61 #define kfpu_allowed() 0 62 #define kfpu_begin() do {} while (0) 63 #define kfpu_end() do {} while (0) 64 #endif 65 #define kfpu_init() (0) 66 #define kfpu_fini() do {} while (0) 67 68 /* 69 * Check if NEON is available 70 */ 71 static inline boolean_t zfs_neon_available(void)72zfs_neon_available(void) 73 { 74 return (elf_hwcap & HWCAP_NEON); 75 } 76 77 /* 78 * Check if SHA256 is available 79 */ 80 static inline boolean_t zfs_sha256_available(void)81zfs_sha256_available(void) 82 { 83 return (elf_hwcap2 & HWCAP2_SHA2); 84 } 85 86 #endif /* _LINUX_SIMD_ARM_H */ 87