12a58b312SMartin Matuska /* 22a58b312SMartin Matuska * CDDL HEADER START 32a58b312SMartin Matuska * 42a58b312SMartin Matuska * The contents of this file are subject to the terms of the 52a58b312SMartin Matuska * Common Development and Distribution License (the "License"). 62a58b312SMartin Matuska * You may not use this file except in compliance with the License. 72a58b312SMartin Matuska * 82a58b312SMartin Matuska * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92a58b312SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0. 102a58b312SMartin Matuska * See the License for the specific language governing permissions 112a58b312SMartin Matuska * and limitations under the License. 122a58b312SMartin Matuska * 132a58b312SMartin Matuska * When distributing Covered Code, include this CDDL HEADER in each 142a58b312SMartin Matuska * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152a58b312SMartin Matuska * If applicable, add the following below this CDDL HEADER, with the 162a58b312SMartin Matuska * fields enclosed by brackets "[]" replaced with your own identifying 172a58b312SMartin Matuska * information: Portions Copyright [yyyy] [name of copyright owner] 182a58b312SMartin Matuska * 192a58b312SMartin Matuska * CDDL HEADER END 202a58b312SMartin Matuska */ 212a58b312SMartin Matuska 222a58b312SMartin Matuska /* 232a58b312SMartin Matuska * Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de> 242a58b312SMartin Matuska */ 252a58b312SMartin Matuska 262a58b312SMartin Matuska /* 272a58b312SMartin Matuska * USER API: 282a58b312SMartin Matuska * 292a58b312SMartin Matuska * Kernel fpu methods: 302a58b312SMartin Matuska * kfpu_allowed() 312a58b312SMartin Matuska * kfpu_begin() 322a58b312SMartin Matuska * kfpu_end() 332a58b312SMartin Matuska * kfpu_init() 342a58b312SMartin Matuska * kfpu_fini() 352a58b312SMartin Matuska * 362a58b312SMartin Matuska * SIMD support: 372a58b312SMartin Matuska * 382a58b312SMartin Matuska * Following functions should be called to determine whether CPU feature 392a58b312SMartin Matuska * is supported. All functions are usable in kernel and user space. 402a58b312SMartin Matuska * If a SIMD algorithm is using more than one instruction set 412a58b312SMartin Matuska * all relevant feature test functions should be called. 422a58b312SMartin Matuska * 432a58b312SMartin Matuska * Supported features: 442a58b312SMartin Matuska * zfs_neon_available() 452a58b312SMartin Matuska * zfs_sha256_available() 462a58b312SMartin Matuska */ 472a58b312SMartin Matuska 482a58b312SMartin Matuska #ifndef _LINUX_SIMD_ARM_H 492a58b312SMartin Matuska #define _LINUX_SIMD_ARM_H 502a58b312SMartin Matuska 512a58b312SMartin Matuska #include <sys/types.h> 522a58b312SMartin Matuska #include <asm/neon.h> 532a58b312SMartin Matuska #include <asm/elf.h> 542a58b312SMartin Matuska #include <asm/hwcap.h> 552a58b312SMartin Matuska 56*f552d7adSMartin Matuska #if (defined(HAVE_KERNEL_NEON) && defined(CONFIG_KERNEL_MODE_NEON)) 572a58b312SMartin Matuska #define kfpu_allowed() 1 582a58b312SMartin Matuska #define kfpu_begin() kernel_neon_begin() 592a58b312SMartin Matuska #define kfpu_end() kernel_neon_end() 60*f552d7adSMartin Matuska #else 61*f552d7adSMartin Matuska #define kfpu_allowed() 0 62*f552d7adSMartin Matuska #define kfpu_begin() do {} while (0) 63*f552d7adSMartin Matuska #define kfpu_end() do {} while (0) 64*f552d7adSMartin Matuska #endif 652a58b312SMartin Matuska #define kfpu_init() (0) 662a58b312SMartin Matuska #define kfpu_fini() do {} while (0) 672a58b312SMartin Matuska 682a58b312SMartin Matuska /* 692a58b312SMartin Matuska * Check if NEON is available 702a58b312SMartin Matuska */ 712a58b312SMartin Matuska static inline boolean_t zfs_neon_available(void)722a58b312SMartin Matuskazfs_neon_available(void) 732a58b312SMartin Matuska { 742a58b312SMartin Matuska return (elf_hwcap & HWCAP_NEON); 752a58b312SMartin Matuska } 762a58b312SMartin Matuska 772a58b312SMartin Matuska /* 782a58b312SMartin Matuska * Check if SHA256 is available 792a58b312SMartin Matuska */ 802a58b312SMartin Matuska static inline boolean_t zfs_sha256_available(void)812a58b312SMartin Matuskazfs_sha256_available(void) 822a58b312SMartin Matuska { 832a58b312SMartin Matuska return (elf_hwcap2 & HWCAP2_SHA2); 842a58b312SMartin Matuska } 852a58b312SMartin Matuska 862a58b312SMartin Matuska #endif /* _LINUX_SIMD_ARM_H */ 87