1 /* Public domain. */ 2 3 #ifndef _ASM_CPUFEATURE_H 4 #define _ASM_CPUFEATURE_H 5 6 #if defined(__amd64__) || defined(__i386__) 7 8 #include <sys/param.h> 9 10 #define X86_FEATURE_CLFLUSH 1 11 #define X86_FEATURE_XMM4_1 2 12 #define X86_FEATURE_PAT 3 13 #define X86_FEATURE_HYPERVISOR 4 14 15 static inline bool 16 static_cpu_has(uint16_t f) 17 { 18 switch (f) { 19 case X86_FEATURE_CLFLUSH: 20 return curcpu()->ci_cflushsz != 0; 21 case X86_FEATURE_XMM4_1: 22 return (cpu_ecxfeature & CPUIDECX_SSE41) != 0; 23 case X86_FEATURE_PAT: 24 return (curcpu()->ci_feature_flags & CPUID_PAT) != 0; 25 case X86_FEATURE_HYPERVISOR: 26 return (cpu_ecxfeature & CPUIDECX_HV) != 0; 27 default: 28 return false; 29 } 30 } 31 32 static inline bool 33 pat_enabled(void) 34 { 35 return ((curcpu()->ci_feature_flags & CPUID_PAT) != 0); 36 } 37 38 #define boot_cpu_has(x) static_cpu_has(x) 39 40 static inline void 41 clflushopt(volatile void *addr) 42 { 43 if (curcpu()->ci_feature_sefflags_ebx & SEFF0EBX_CLFLUSHOPT) 44 __asm volatile("clflushopt %0" : "+m" (*(volatile char *)addr)); 45 else 46 __asm volatile("clflush %0" : "+m" (*(volatile char *)addr)); 47 } 48 49 #endif 50 51 #endif 52