xref: /openbsd/sys/dev/pci/drm/include/asm/cpufeature.h (revision c4219eb2)
1c349dbc7Sjsg /* Public domain. */
2c349dbc7Sjsg 
3c349dbc7Sjsg #ifndef _ASM_CPUFEATURE_H
4c349dbc7Sjsg #define _ASM_CPUFEATURE_H
5c349dbc7Sjsg 
6c349dbc7Sjsg #if defined(__amd64__) || defined(__i386__)
7c349dbc7Sjsg 
81bb76ff1Sjsg #include <sys/param.h>
91bb76ff1Sjsg 
10c349dbc7Sjsg #define X86_FEATURE_CLFLUSH	1
11c349dbc7Sjsg #define X86_FEATURE_XMM4_1	2
12c349dbc7Sjsg #define X86_FEATURE_PAT		3
13c349dbc7Sjsg #define X86_FEATURE_HYPERVISOR	4
14c349dbc7Sjsg 
15c349dbc7Sjsg static inline bool
static_cpu_has(uint16_t f)16c349dbc7Sjsg static_cpu_has(uint16_t f)
17c349dbc7Sjsg {
18c349dbc7Sjsg 	switch (f) {
19c349dbc7Sjsg 	case X86_FEATURE_XMM4_1:
20c349dbc7Sjsg 		return (cpu_ecxfeature & CPUIDECX_SSE41) != 0;
21*c4219eb2Sguenther #ifdef __amd64__
22*c4219eb2Sguenther 	case X86_FEATURE_CLFLUSH:
23*c4219eb2Sguenther 	case X86_FEATURE_PAT:
24*c4219eb2Sguenther 		return true;
25*c4219eb2Sguenther #else
26*c4219eb2Sguenther 	case X86_FEATURE_CLFLUSH:
27*c4219eb2Sguenther 		return curcpu()->ci_cflushsz != 0;
28c349dbc7Sjsg 	case X86_FEATURE_PAT:
29c349dbc7Sjsg 		return (curcpu()->ci_feature_flags & CPUID_PAT) != 0;
30*c4219eb2Sguenther #endif
31c349dbc7Sjsg 	case X86_FEATURE_HYPERVISOR:
32c349dbc7Sjsg 		return (cpu_ecxfeature & CPUIDECX_HV) != 0;
33c349dbc7Sjsg 	default:
34c349dbc7Sjsg 		return false;
35c349dbc7Sjsg 	}
36c349dbc7Sjsg }
37c349dbc7Sjsg 
381bb76ff1Sjsg static inline bool
pat_enabled(void)391bb76ff1Sjsg pat_enabled(void)
401bb76ff1Sjsg {
41*c4219eb2Sguenther 	return static_cpu_has(X86_FEATURE_PAT);
421bb76ff1Sjsg }
431bb76ff1Sjsg 
44c349dbc7Sjsg #define boot_cpu_has(x) static_cpu_has(x)
45c349dbc7Sjsg 
46252e0799Sjsg static inline void
clflushopt(volatile void * addr)47252e0799Sjsg clflushopt(volatile void *addr)
48252e0799Sjsg {
49252e0799Sjsg 	if (curcpu()->ci_feature_sefflags_ebx & SEFF0EBX_CLFLUSHOPT)
50252e0799Sjsg 		__asm volatile("clflushopt %0" : "+m" (*(volatile char *)addr));
51252e0799Sjsg 	else
52252e0799Sjsg 		__asm volatile("clflush %0" : "+m" (*(volatile char *)addr));
53252e0799Sjsg }
54252e0799Sjsg 
55c349dbc7Sjsg #endif
56c349dbc7Sjsg 
57c349dbc7Sjsg #endif
58