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 http://www.opensolaris.org/os/licensing. 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 * Copyright (C) 2019 Romain Dolbeau 23 * <romain.dolbeau@european-processor-initiative.eu> 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_altivec_available() 45 */ 46 47 #ifndef _LINUX_SIMD_POWERPC_H 48 #define _LINUX_SIMD_POWERPC_H 49 50 /* only for __powerpc__ */ 51 #if defined(__powerpc__) 52 53 #include <linux/preempt.h> 54 #include <linux/export.h> 55 #include <linux/sched.h> 56 #include <asm/switch_to.h> 57 #include <sys/types.h> 58 #include <linux/version.h> 59 60 #define kfpu_allowed() 1 61 #define kfpu_begin() \ 62 { \ 63 preempt_disable(); \ 64 enable_kernel_altivec(); \ 65 } 66 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) 67 #define kfpu_end() \ 68 { \ 69 disable_kernel_altivec(); \ 70 preempt_enable(); \ 71 } 72 #else 73 /* seems that before 4.5 no-one bothered disabling ... */ 74 #define kfpu_end() preempt_enable() 75 #endif 76 #define kfpu_init() 0 77 #define kfpu_fini() ((void) 0) 78 79 /* 80 * Check if AltiVec instruction set is available 81 */ 82 static inline boolean_t 83 zfs_altivec_available(void) 84 { 85 boolean_t res; 86 /* suggested by macallan at netbsd dot org */ 87 #if defined(__powerpc64__) 88 u64 msr; 89 #else 90 u32 msr; 91 #endif 92 kfpu_begin(); 93 __asm volatile("mfmsr %0" : "=r"(msr)); 94 /* 95 * 64 bits -> need to check bit 38 96 * Power ISA Version 3.0B 97 * p944 98 * 32 bits -> Need to check bit 6 99 * AltiVec Technology Programming Environments Manual 100 * p49 (2-9) 101 * They are the same, as ppc counts 'backward' ... 102 */ 103 res = (msr & 0x2000000) != 0; 104 kfpu_end(); 105 return (res); 106 } 107 #endif /* defined(__powerpc) */ 108 109 #endif /* _LINUX_SIMD_POWERPC_H */ 110