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