1 /* 2 * cpufeature.h 3 * 4 * Defines x86 CPU feature bits 5 */ 6 #ifndef __ASM_I386_CPUFEATURE_H 7 #define __ASM_I386_CPUFEATURE_H 8 9 #include <xen/const.h> 10 #include <asm/cpuid.h> 11 12 #define cpufeat_word(idx) ((idx) / 32) 13 #define cpufeat_bit(idx) ((idx) % 32) 14 #define cpufeat_mask(idx) (_AC(1, U) << cpufeat_bit(idx)) 15 16 /* An alias of a feature we know is always going to be present. */ 17 #define X86_FEATURE_ALWAYS X86_FEATURE_LM 18 19 #ifndef __ASSEMBLY__ 20 #include <xen/bitops.h> 21 22 #define cpu_has(c, bit) test_bit(bit, (c)->x86_capability) 23 #define boot_cpu_has(bit) test_bit(bit, boot_cpu_data.x86_capability) 24 25 #define CPUID_MWAIT_LEAF 5 26 #define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1 27 #define CPUID5_ECX_INTERRUPT_BREAK 0x2 28 29 #define CPUID_PM_LEAF 6 30 #define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 31 32 /* CPUID level 0x00000001.edx */ 33 #define cpu_has_fpu 1 34 #define cpu_has_de 1 35 #define cpu_has_pse 1 36 #define cpu_has_apic boot_cpu_has(X86_FEATURE_APIC) 37 #define cpu_has_sep boot_cpu_has(X86_FEATURE_SEP) 38 #define cpu_has_mtrr 1 39 #define cpu_has_pge 1 40 #define cpu_has_pse36 boot_cpu_has(X86_FEATURE_PSE36) 41 #define cpu_has_clflush boot_cpu_has(X86_FEATURE_CLFLUSH) 42 #define cpu_has_mmx 1 43 #define cpu_has_htt boot_cpu_has(X86_FEATURE_HTT) 44 45 /* CPUID level 0x00000001.ecx */ 46 #define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3) 47 #define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ) 48 #define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) 49 #define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) 50 #define cpu_has_eist boot_cpu_has(X86_FEATURE_EIST) 51 #define cpu_has_ssse3 boot_cpu_has(X86_FEATURE_SSSE3) 52 #define cpu_has_fma boot_cpu_has(X86_FEATURE_FMA) 53 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16) 54 #define cpu_has_pdcm boot_cpu_has(X86_FEATURE_PDCM) 55 #define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID) 56 #define cpu_has_sse4_1 boot_cpu_has(X86_FEATURE_SSE4_1) 57 #define cpu_has_sse4_2 boot_cpu_has(X86_FEATURE_SSE4_2) 58 #define cpu_has_x2apic boot_cpu_has(X86_FEATURE_X2APIC) 59 #define cpu_has_popcnt boot_cpu_has(X86_FEATURE_POPCNT) 60 #define cpu_has_aesni boot_cpu_has(X86_FEATURE_AESNI) 61 #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE) 62 #define cpu_has_avx boot_cpu_has(X86_FEATURE_AVX) 63 #define cpu_has_f16c boot_cpu_has(X86_FEATURE_F16C) 64 #define cpu_has_rdrand boot_cpu_has(X86_FEATURE_RDRAND) 65 #define cpu_has_hypervisor boot_cpu_has(X86_FEATURE_HYPERVISOR) 66 67 /* CPUID level 0x80000001.edx */ 68 #define cpu_has_nx boot_cpu_has(X86_FEATURE_NX) 69 #define cpu_has_page1gb boot_cpu_has(X86_FEATURE_PAGE1GB) 70 #define cpu_has_rdtscp boot_cpu_has(X86_FEATURE_RDTSCP) 71 #define cpu_has_3dnow_ext boot_cpu_has(X86_FEATURE_3DNOWEXT) 72 #define cpu_has_3dnow boot_cpu_has(X86_FEATURE_3DNOW) 73 74 /* CPUID level 0x80000001.ecx */ 75 #define cpu_has_cmp_legacy boot_cpu_has(X86_FEATURE_CMP_LEGACY) 76 #define cpu_has_svm boot_cpu_has(X86_FEATURE_SVM) 77 #define cpu_has_sse4a boot_cpu_has(X86_FEATURE_SSE4A) 78 #define cpu_has_xop boot_cpu_has(X86_FEATURE_XOP) 79 #define cpu_has_fma4 boot_cpu_has(X86_FEATURE_FMA4) 80 #define cpu_has_tbm boot_cpu_has(X86_FEATURE_TBM) 81 82 /* CPUID level 0x0000000D:1.eax */ 83 #define cpu_has_xsaveopt boot_cpu_has(X86_FEATURE_XSAVEOPT) 84 #define cpu_has_xsavec boot_cpu_has(X86_FEATURE_XSAVEC) 85 #define cpu_has_xgetbv1 boot_cpu_has(X86_FEATURE_XGETBV1) 86 #define cpu_has_xsaves boot_cpu_has(X86_FEATURE_XSAVES) 87 88 /* CPUID level 0x00000007:0.ebx */ 89 #define cpu_has_bmi1 boot_cpu_has(X86_FEATURE_BMI1) 90 #define cpu_has_hle boot_cpu_has(X86_FEATURE_HLE) 91 #define cpu_has_avx2 boot_cpu_has(X86_FEATURE_AVX2) 92 #define cpu_has_smep boot_cpu_has(X86_FEATURE_SMEP) 93 #define cpu_has_bmi2 boot_cpu_has(X86_FEATURE_BMI2) 94 #define cpu_has_invpcid boot_cpu_has(X86_FEATURE_INVPCID) 95 #define cpu_has_rtm boot_cpu_has(X86_FEATURE_RTM) 96 #define cpu_has_fpu_sel (!boot_cpu_has(X86_FEATURE_NO_FPU_SEL)) 97 #define cpu_has_mpx boot_cpu_has(X86_FEATURE_MPX) 98 #define cpu_has_avx512f boot_cpu_has(X86_FEATURE_AVX512F) 99 #define cpu_has_avx512dq boot_cpu_has(X86_FEATURE_AVX512DQ) 100 #define cpu_has_rdseed boot_cpu_has(X86_FEATURE_RDSEED) 101 #define cpu_has_smap boot_cpu_has(X86_FEATURE_SMAP) 102 #define cpu_has_avx512_ifma boot_cpu_has(X86_FEATURE_AVX512_IFMA) 103 #define cpu_has_clflushopt boot_cpu_has(X86_FEATURE_CLFLUSHOPT) 104 #define cpu_has_clwb boot_cpu_has(X86_FEATURE_CLWB) 105 #define cpu_has_avx512er boot_cpu_has(X86_FEATURE_AVX512ER) 106 #define cpu_has_avx512cd boot_cpu_has(X86_FEATURE_AVX512CD) 107 #define cpu_has_sha boot_cpu_has(X86_FEATURE_SHA) 108 #define cpu_has_avx512bw boot_cpu_has(X86_FEATURE_AVX512BW) 109 #define cpu_has_avx512vl boot_cpu_has(X86_FEATURE_AVX512VL) 110 111 /* CPUID level 0x00000007:0.ecx */ 112 #define cpu_has_avx512_vbmi boot_cpu_has(X86_FEATURE_AVX512_VBMI) 113 #define cpu_has_avx512_vbmi2 boot_cpu_has(X86_FEATURE_AVX512_VBMI2) 114 #define cpu_has_gfni boot_cpu_has(X86_FEATURE_GFNI) 115 #define cpu_has_vaes boot_cpu_has(X86_FEATURE_VAES) 116 #define cpu_has_vpclmulqdq boot_cpu_has(X86_FEATURE_VPCLMULQDQ) 117 #define cpu_has_avx512_vnni boot_cpu_has(X86_FEATURE_AVX512_VNNI) 118 #define cpu_has_avx512_bitalg boot_cpu_has(X86_FEATURE_AVX512_BITALG) 119 #define cpu_has_avx512_vpopcntdq boot_cpu_has(X86_FEATURE_AVX512_VPOPCNTDQ) 120 #define cpu_has_rdpid boot_cpu_has(X86_FEATURE_RDPID) 121 #define cpu_has_movdiri boot_cpu_has(X86_FEATURE_MOVDIRI) 122 #define cpu_has_movdir64b boot_cpu_has(X86_FEATURE_MOVDIR64B) 123 #define cpu_has_enqcmd boot_cpu_has(X86_FEATURE_ENQCMD) 124 125 /* CPUID level 0x80000007.edx */ 126 #define cpu_has_itsc boot_cpu_has(X86_FEATURE_ITSC) 127 128 /* CPUID level 0x00000007:0.edx */ 129 #define cpu_has_avx512_4vnniw boot_cpu_has(X86_FEATURE_AVX512_4VNNIW) 130 #define cpu_has_avx512_4fmaps boot_cpu_has(X86_FEATURE_AVX512_4FMAPS) 131 #define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT) 132 #define cpu_has_serialize boot_cpu_has(X86_FEATURE_SERIALIZE) 133 134 /* CPUID level 0x00000007:1.eax */ 135 #define cpu_has_avx512_bf16 boot_cpu_has(X86_FEATURE_AVX512_BF16) 136 137 /* Synthesized. */ 138 #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON) 139 #define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING) 140 #define cpu_has_aperfmperf boot_cpu_has(X86_FEATURE_APERFMPERF) 141 #define cpu_has_lfence_dispatch boot_cpu_has(X86_FEATURE_LFENCE_DISPATCH) 142 #define cpu_has_xen_lbr boot_cpu_has(X86_FEATURE_XEN_LBR) 143 #define cpu_has_xen_shstk boot_cpu_has(X86_FEATURE_XEN_SHSTK) 144 145 #define cpu_has_msr_tsc_aux (cpu_has_rdtscp || cpu_has_rdpid) 146 147 /* Bugs. */ 148 #define cpu_bug_fpu_ptrs boot_cpu_has(X86_BUG_FPU_PTRS) 149 150 enum _cache_type { 151 CACHE_TYPE_NULL = 0, 152 CACHE_TYPE_DATA = 1, 153 CACHE_TYPE_INST = 2, 154 CACHE_TYPE_UNIFIED = 3 155 }; 156 157 union _cpuid4_leaf_eax { 158 struct { 159 enum _cache_type type:5; 160 unsigned int level:3; 161 unsigned int is_self_initializing:1; 162 unsigned int is_fully_associative:1; 163 unsigned int reserved:4; 164 unsigned int num_threads_sharing:12; 165 unsigned int num_cores_on_die:6; 166 } split; 167 u32 full; 168 }; 169 170 union _cpuid4_leaf_ebx { 171 struct { 172 unsigned int coherency_line_size:12; 173 unsigned int physical_line_partition:10; 174 unsigned int ways_of_associativity:10; 175 } split; 176 u32 full; 177 }; 178 179 union _cpuid4_leaf_ecx { 180 struct { 181 unsigned int number_of_sets:32; 182 } split; 183 u32 full; 184 }; 185 186 struct cpuid4_info { 187 union _cpuid4_leaf_eax eax; 188 union _cpuid4_leaf_ebx ebx; 189 union _cpuid4_leaf_ecx ecx; 190 unsigned long size; 191 }; 192 193 int cpuid4_cache_lookup(int index, struct cpuid4_info *this_leaf); 194 #endif /* !__ASSEMBLY__ */ 195 196 #endif /* __ASM_I386_CPUFEATURE_H */ 197 198 /* 199 * Local Variables: 200 * mode:c 201 * comment-column:42 202 * End: 203 */ 204