18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------- * 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * ----------------------------------------------------------------------- */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci * raid6/x86.h 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Definitions common to x86 and x86-64 RAID-6 code only 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#ifndef LINUX_RAID_RAID6X86_H 158c2ecf20Sopenharmony_ci#define LINUX_RAID_RAID6X86_H 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#ifdef __KERNEL__ /* Real code */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include <asm/fpu/api.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#else /* Dummy code for user space testing */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic inline void kernel_fpu_begin(void) 268c2ecf20Sopenharmony_ci{ 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic inline void kernel_fpu_end(void) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define __aligned(x) __attribute__((aligned(x))) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */ 368c2ecf20Sopenharmony_ci#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions 378c2ecf20Sopenharmony_ci * (fast save and restore) */ 388c2ecf20Sopenharmony_ci#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */ 398c2ecf20Sopenharmony_ci#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */ 408c2ecf20Sopenharmony_ci#define X86_FEATURE_XMM3 (4*32+ 0) /* "pni" SSE-3 */ 418c2ecf20Sopenharmony_ci#define X86_FEATURE_SSSE3 (4*32+ 9) /* Supplemental SSE-3 */ 428c2ecf20Sopenharmony_ci#define X86_FEATURE_AVX (4*32+28) /* Advanced Vector Extensions */ 438c2ecf20Sopenharmony_ci#define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */ 448c2ecf20Sopenharmony_ci#define X86_FEATURE_AVX512F (9*32+16) /* AVX-512 Foundation */ 458c2ecf20Sopenharmony_ci#define X86_FEATURE_AVX512DQ (9*32+17) /* AVX-512 DQ (Double/Quad granular) 468c2ecf20Sopenharmony_ci * Instructions 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci#define X86_FEATURE_AVX512BW (9*32+30) /* AVX-512 BW (Byte/Word granular) 498c2ecf20Sopenharmony_ci * Instructions 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_ci#define X86_FEATURE_AVX512VL (9*32+31) /* AVX-512 VL (128/256 Vector Length) 528c2ecf20Sopenharmony_ci * Extensions 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_ci#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */ 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* Should work well enough on modern CPUs for testing */ 578c2ecf20Sopenharmony_cistatic inline int boot_cpu_has(int flag) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci u32 eax, ebx, ecx, edx; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci eax = (flag & 0x100) ? 7 : 628c2ecf20Sopenharmony_ci (flag & 0x20) ? 0x80000001 : 1; 638c2ecf20Sopenharmony_ci ecx = 0; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci asm volatile("cpuid" 668c2ecf20Sopenharmony_ci : "+a" (eax), "=b" (ebx), "=d" (edx), "+c" (ecx)); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci return ((flag & 0x100 ? ebx : 698c2ecf20Sopenharmony_ci (flag & 0x80) ? ecx : edx) >> (flag & 31)) & 1; 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#endif /* ndef __KERNEL__ */ 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#endif 758c2ecf20Sopenharmony_ci#endif 76