1
2
3
4#ifndef _ASM_X86_CPUFEATURE_H
5#define _ASM_X86_CPUFEATURE_H
6
7#ifndef _ASM_X86_REQUIRED_FEATURES_H
8#include <asm/required-features.h>
9#endif
10
11#ifndef _ASM_X86_DISABLED_FEATURES_H
12#include <asm/disabled-features.h>
13#endif
14
15#define NCAPINTS 11
16#define NBUGINTS 1
17
18
19
20
21
22
23
24
25#define X86_FEATURE_FPU ( 0*32+ 0)
26#define X86_FEATURE_VME ( 0*32+ 1)
27#define X86_FEATURE_DE ( 0*32+ 2)
28#define X86_FEATURE_PSE ( 0*32+ 3)
29#define X86_FEATURE_TSC ( 0*32+ 4)
30#define X86_FEATURE_MSR ( 0*32+ 5)
31#define X86_FEATURE_PAE ( 0*32+ 6)
32#define X86_FEATURE_MCE ( 0*32+ 7)
33#define X86_FEATURE_CX8 ( 0*32+ 8)
34#define X86_FEATURE_APIC ( 0*32+ 9)
35#define X86_FEATURE_SEP ( 0*32+11)
36#define X86_FEATURE_MTRR ( 0*32+12)
37#define X86_FEATURE_PGE ( 0*32+13)
38#define X86_FEATURE_MCA ( 0*32+14)
39#define X86_FEATURE_CMOV ( 0*32+15)
40
41#define X86_FEATURE_PAT ( 0*32+16)
42#define X86_FEATURE_PSE36 ( 0*32+17)
43#define X86_FEATURE_PN ( 0*32+18)
44#define X86_FEATURE_CLFLUSH ( 0*32+19)
45#define X86_FEATURE_DS ( 0*32+21)
46#define X86_FEATURE_ACPI ( 0*32+22)
47#define X86_FEATURE_MMX ( 0*32+23)
48#define X86_FEATURE_FXSR ( 0*32+24)
49#define X86_FEATURE_XMM ( 0*32+25)
50#define X86_FEATURE_XMM2 ( 0*32+26)
51#define X86_FEATURE_SELFSNOOP ( 0*32+27)
52#define X86_FEATURE_HT ( 0*32+28)
53#define X86_FEATURE_ACC ( 0*32+29)
54#define X86_FEATURE_IA64 ( 0*32+30)
55#define X86_FEATURE_PBE ( 0*32+31)
56
57
58
59#define X86_FEATURE_SYSCALL ( 1*32+11)
60#define X86_FEATURE_MP ( 1*32+19)
61#define X86_FEATURE_NX ( 1*32+20)
62#define X86_FEATURE_MMXEXT ( 1*32+22)
63#define X86_FEATURE_FXSR_OPT ( 1*32+25)
64#define X86_FEATURE_GBPAGES ( 1*32+26)
65#define X86_FEATURE_RDTSCP ( 1*32+27)
66#define X86_FEATURE_LM ( 1*32+29)
67#define X86_FEATURE_3DNOWEXT ( 1*32+30)
68#define X86_FEATURE_3DNOW ( 1*32+31)
69
70
71#define X86_FEATURE_RECOVERY ( 2*32+ 0)
72#define X86_FEATURE_LONGRUN ( 2*32+ 1)
73#define X86_FEATURE_LRTI ( 2*32+ 3)
74
75
76
77#define X86_FEATURE_CXMMX ( 3*32+ 0)
78#define X86_FEATURE_K6_MTRR ( 3*32+ 1)
79#define X86_FEATURE_CYRIX_ARR ( 3*32+ 2)
80#define X86_FEATURE_CENTAUR_MCR ( 3*32+ 3)
81
82#define X86_FEATURE_K8 ( 3*32+ 4)
83#define X86_FEATURE_K7 ( 3*32+ 5)
84#define X86_FEATURE_P3 ( 3*32+ 6)
85#define X86_FEATURE_P4 ( 3*32+ 7)
86#define X86_FEATURE_CONSTANT_TSC ( 3*32+ 8)
87#define X86_FEATURE_UP ( 3*32+ 9)
88
89#define X86_FEATURE_ARCH_PERFMON ( 3*32+11)
90#define X86_FEATURE_PEBS ( 3*32+12)
91#define X86_FEATURE_BTS ( 3*32+13)
92#define X86_FEATURE_SYSCALL32 ( 3*32+14)
93#define X86_FEATURE_SYSENTER32 ( 3*32+15)
94#define X86_FEATURE_REP_GOOD ( 3*32+16)
95#define X86_FEATURE_MFENCE_RDTSC ( 3*32+17)
96#define X86_FEATURE_LFENCE_RDTSC ( 3*32+18)
97
98#define X86_FEATURE_NOPL ( 3*32+20)
99#define X86_FEATURE_ALWAYS ( 3*32+21)
100#define X86_FEATURE_XTOPOLOGY ( 3*32+22)
101#define X86_FEATURE_TSC_RELIABLE ( 3*32+23)
102#define X86_FEATURE_NONSTOP_TSC ( 3*32+24)
103
104#define X86_FEATURE_EXTD_APICID ( 3*32+26)
105#define X86_FEATURE_AMD_DCM ( 3*32+27)
106#define X86_FEATURE_APERFMPERF ( 3*32+28)
107#define X86_FEATURE_EAGER_FPU ( 3*32+29)
108#define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30)
109
110
111#define X86_FEATURE_XMM3 ( 4*32+ 0)
112#define X86_FEATURE_PCLMULQDQ ( 4*32+ 1)
113#define X86_FEATURE_DTES64 ( 4*32+ 2)
114#define X86_FEATURE_MWAIT ( 4*32+ 3)
115#define X86_FEATURE_DSCPL ( 4*32+ 4)
116#define X86_FEATURE_VMX ( 4*32+ 5)
117#define X86_FEATURE_SMX ( 4*32+ 6)
118#define X86_FEATURE_EST ( 4*32+ 7)
119#define X86_FEATURE_TM2 ( 4*32+ 8)
120#define X86_FEATURE_SSSE3 ( 4*32+ 9)
121#define X86_FEATURE_CID ( 4*32+10)
122#define X86_FEATURE_FMA ( 4*32+12)
123#define X86_FEATURE_CX16 ( 4*32+13)
124#define X86_FEATURE_XTPR ( 4*32+14)
125#define X86_FEATURE_PDCM ( 4*32+15)
126#define X86_FEATURE_PCID ( 4*32+17)
127#define X86_FEATURE_DCA ( 4*32+18)
128#define X86_FEATURE_XMM4_1 ( 4*32+19)
129#define X86_FEATURE_XMM4_2 ( 4*32+20)
130#define X86_FEATURE_X2APIC ( 4*32+21)
131#define X86_FEATURE_MOVBE ( 4*32+22)
132#define X86_FEATURE_POPCNT ( 4*32+23)
133#define X86_FEATURE_TSC_DEADLINE_TIMER ( 4*32+24)
134#define X86_FEATURE_AES ( 4*32+25)
135#define X86_FEATURE_XSAVE ( 4*32+26)
136#define X86_FEATURE_OSXSAVE ( 4*32+27)
137#define X86_FEATURE_AVX ( 4*32+28)
138#define X86_FEATURE_F16C ( 4*32+29)
139#define X86_FEATURE_RDRAND ( 4*32+30)
140#define X86_FEATURE_HYPERVISOR ( 4*32+31)
141
142
143#define X86_FEATURE_XSTORE ( 5*32+ 2)
144#define X86_FEATURE_XSTORE_EN ( 5*32+ 3)
145#define X86_FEATURE_XCRYPT ( 5*32+ 6)
146#define X86_FEATURE_XCRYPT_EN ( 5*32+ 7)
147#define X86_FEATURE_ACE2 ( 5*32+ 8)
148#define X86_FEATURE_ACE2_EN ( 5*32+ 9)
149#define X86_FEATURE_PHE ( 5*32+10)
150#define X86_FEATURE_PHE_EN ( 5*32+11)
151#define X86_FEATURE_PMM ( 5*32+12)
152#define X86_FEATURE_PMM_EN ( 5*32+13)
153
154
155#define X86_FEATURE_LAHF_LM ( 6*32+ 0)
156#define X86_FEATURE_CMP_LEGACY ( 6*32+ 1)
157#define X86_FEATURE_SVM ( 6*32+ 2)
158#define X86_FEATURE_EXTAPIC ( 6*32+ 3)
159#define X86_FEATURE_CR8_LEGACY ( 6*32+ 4)
160#define X86_FEATURE_ABM ( 6*32+ 5)
161#define X86_FEATURE_SSE4A ( 6*32+ 6)
162#define X86_FEATURE_MISALIGNSSE ( 6*32+ 7)
163#define X86_FEATURE_3DNOWPREFETCH ( 6*32+ 8)
164#define X86_FEATURE_OSVW ( 6*32+ 9)
165#define X86_FEATURE_IBS ( 6*32+10)
166#define X86_FEATURE_XOP ( 6*32+11)
167#define X86_FEATURE_SKINIT ( 6*32+12)
168#define X86_FEATURE_WDT ( 6*32+13)
169#define X86_FEATURE_LWP ( 6*32+15)
170#define X86_FEATURE_FMA4 ( 6*32+16)
171#define X86_FEATURE_TCE ( 6*32+17)
172#define X86_FEATURE_NODEID_MSR ( 6*32+19)
173#define X86_FEATURE_TBM ( 6*32+21)
174#define X86_FEATURE_TOPOEXT ( 6*32+22)
175#define X86_FEATURE_PERFCTR_CORE ( 6*32+23)
176#define X86_FEATURE_PERFCTR_NB ( 6*32+24)
177#define X86_FEATURE_PERFCTR_L2 ( 6*32+28)
178
179
180
181
182
183#define X86_FEATURE_IDA ( 7*32+ 0)
184#define X86_FEATURE_ARAT ( 7*32+ 1)
185#define X86_FEATURE_CPB ( 7*32+ 2)
186#define X86_FEATURE_EPB ( 7*32+ 3)
187#define X86_FEATURE_PLN ( 7*32+ 5)
188#define X86_FEATURE_PTS ( 7*32+ 6)
189#define X86_FEATURE_DTHERM ( 7*32+ 7)
190#define X86_FEATURE_HW_PSTATE ( 7*32+ 8)
191#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9)
192#define X86_FEATURE_HWP ( 7*32+ 10)
193#define X86_FEATURE_HWP_NOITFY ( 7*32+ 11)
194#define X86_FEATURE_HWP_ACT_WINDOW ( 7*32+ 12)
195#define X86_FEATURE_HWP_EPP ( 7*32+13)
196#define X86_FEATURE_HWP_PKG_REQ ( 7*32+14)
197
198
199#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0)
200#define X86_FEATURE_VNMI ( 8*32+ 1)
201#define X86_FEATURE_FLEXPRIORITY ( 8*32+ 2)
202#define X86_FEATURE_EPT ( 8*32+ 3)
203#define X86_FEATURE_VPID ( 8*32+ 4)
204#define X86_FEATURE_NPT ( 8*32+ 5)
205#define X86_FEATURE_LBRV ( 8*32+ 6)
206#define X86_FEATURE_SVML ( 8*32+ 7)
207#define X86_FEATURE_NRIPS ( 8*32+ 8)
208#define X86_FEATURE_TSCRATEMSR ( 8*32+ 9)
209#define X86_FEATURE_VMCBCLEAN ( 8*32+10)
210#define X86_FEATURE_FLUSHBYASID ( 8*32+11)
211#define X86_FEATURE_DECODEASSISTS ( 8*32+12)
212#define X86_FEATURE_PAUSEFILTER ( 8*32+13)
213#define X86_FEATURE_PFTHRESHOLD ( 8*32+14)
214#define X86_FEATURE_VMMCALL ( 8*32+15)
215
216
217
218#define X86_FEATURE_FSGSBASE ( 9*32+ 0)
219#define X86_FEATURE_TSC_ADJUST ( 9*32+ 1)
220#define X86_FEATURE_BMI1 ( 9*32+ 3)
221#define X86_FEATURE_HLE ( 9*32+ 4)
222#define X86_FEATURE_AVX2 ( 9*32+ 5)
223#define X86_FEATURE_SMEP ( 9*32+ 7)
224#define X86_FEATURE_BMI2 ( 9*32+ 8)
225#define X86_FEATURE_ERMS ( 9*32+ 9)
226#define X86_FEATURE_INVPCID ( 9*32+10)
227#define X86_FEATURE_RTM ( 9*32+11)
228#define X86_FEATURE_MPX ( 9*32+14)
229#define X86_FEATURE_AVX512F ( 9*32+16)
230#define X86_FEATURE_RDSEED ( 9*32+18)
231#define X86_FEATURE_ADX ( 9*32+19)
232#define X86_FEATURE_SMAP ( 9*32+20)
233#define X86_FEATURE_CLFLUSHOPT ( 9*32+23)
234#define X86_FEATURE_AVX512PF ( 9*32+26)
235#define X86_FEATURE_AVX512ER ( 9*32+27)
236#define X86_FEATURE_AVX512CD ( 9*32+28)
237
238
239#define X86_FEATURE_XSAVEOPT (10*32+ 0)
240#define X86_FEATURE_XSAVEC (10*32+ 1)
241#define X86_FEATURE_XGETBV1 (10*32+ 2)
242#define X86_FEATURE_XSAVES (10*32+ 3)
243
244
245
246
247#define X86_BUG(x) (NCAPINTS*32 + (x))
248
249#define X86_BUG_F00F X86_BUG(0)
250#define X86_BUG_FDIV X86_BUG(1)
251#define X86_BUG_COMA X86_BUG(2)
252#define X86_BUG_AMD_TLB_MMATCH X86_BUG(3)
253#define X86_BUG_AMD_APIC_C1E X86_BUG(4)
254#define X86_BUG_11AP X86_BUG(5)
255#define X86_BUG_FXSAVE_LEAK X86_BUG(6)
256#define X86_BUG_CLFLUSH_MONITOR X86_BUG(7)
257
258#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
259
260#include <asm/asm.h>
261#include <linux/bitops.h>
262
263#ifdef CONFIG_X86_FEATURE_NAMES
264extern const char * const x86_cap_flags[NCAPINTS*32];
265extern const char * const x86_power_flags[32];
266#define X86_CAP_FMT "%s"
267#define x86_cap_flag(flag) x86_cap_flags[flag]
268#else
269#define X86_CAP_FMT "%d:%d"
270#define x86_cap_flag(flag) ((flag) >> 5), ((flag) & 31)
271#endif
272
273
274
275
276
277extern const char * const x86_bug_flags[NBUGINTS*32];
278
279#define test_cpu_cap(c, bit) \
280 test_bit(bit, (unsigned long *)((c)->x86_capability))
281
282#define REQUIRED_MASK_BIT_SET(bit) \
283 ( (((bit)>>5)==0 && (1UL<<((bit)&31) & REQUIRED_MASK0)) || \
284 (((bit)>>5)==1 && (1UL<<((bit)&31) & REQUIRED_MASK1)) || \
285 (((bit)>>5)==2 && (1UL<<((bit)&31) & REQUIRED_MASK2)) || \
286 (((bit)>>5)==3 && (1UL<<((bit)&31) & REQUIRED_MASK3)) || \
287 (((bit)>>5)==4 && (1UL<<((bit)&31) & REQUIRED_MASK4)) || \
288 (((bit)>>5)==5 && (1UL<<((bit)&31) & REQUIRED_MASK5)) || \
289 (((bit)>>5)==6 && (1UL<<((bit)&31) & REQUIRED_MASK6)) || \
290 (((bit)>>5)==7 && (1UL<<((bit)&31) & REQUIRED_MASK7)) || \
291 (((bit)>>5)==8 && (1UL<<((bit)&31) & REQUIRED_MASK8)) || \
292 (((bit)>>5)==9 && (1UL<<((bit)&31) & REQUIRED_MASK9)) )
293
294#define DISABLED_MASK_BIT_SET(bit) \
295 ( (((bit)>>5)==0 && (1UL<<((bit)&31) & DISABLED_MASK0)) || \
296 (((bit)>>5)==1 && (1UL<<((bit)&31) & DISABLED_MASK1)) || \
297 (((bit)>>5)==2 && (1UL<<((bit)&31) & DISABLED_MASK2)) || \
298 (((bit)>>5)==3 && (1UL<<((bit)&31) & DISABLED_MASK3)) || \
299 (((bit)>>5)==4 && (1UL<<((bit)&31) & DISABLED_MASK4)) || \
300 (((bit)>>5)==5 && (1UL<<((bit)&31) & DISABLED_MASK5)) || \
301 (((bit)>>5)==6 && (1UL<<((bit)&31) & DISABLED_MASK6)) || \
302 (((bit)>>5)==7 && (1UL<<((bit)&31) & DISABLED_MASK7)) || \
303 (((bit)>>5)==8 && (1UL<<((bit)&31) & DISABLED_MASK8)) || \
304 (((bit)>>5)==9 && (1UL<<((bit)&31) & DISABLED_MASK9)) )
305
306#define cpu_has(c, bit) \
307 (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
308 test_cpu_cap(c, bit))
309
310#define this_cpu_has(bit) \
311 (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
312 x86_this_cpu_test_bit(bit, (unsigned long *)&cpu_info.x86_capability))
313
314
315
316
317
318
319
320
321
322#define cpu_feature_enabled(bit) \
323 (__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 : \
324 cpu_has(&boot_cpu_data, bit))
325
326#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
327
328#define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capability))
329#define clear_cpu_cap(c, bit) clear_bit(bit, (unsigned long *)((c)->x86_capability))
330#define setup_clear_cpu_cap(bit) do { \
331 clear_cpu_cap(&boot_cpu_data, bit); \
332 set_bit(bit, (unsigned long *)cpu_caps_cleared); \
333} while (0)
334#define setup_force_cpu_cap(bit) do { \
335 set_cpu_cap(&boot_cpu_data, bit); \
336 set_bit(bit, (unsigned long *)cpu_caps_set); \
337} while (0)
338
339#define cpu_has_fpu boot_cpu_has(X86_FEATURE_FPU)
340#define cpu_has_de boot_cpu_has(X86_FEATURE_DE)
341#define cpu_has_pse boot_cpu_has(X86_FEATURE_PSE)
342#define cpu_has_tsc boot_cpu_has(X86_FEATURE_TSC)
343#define cpu_has_pge boot_cpu_has(X86_FEATURE_PGE)
344#define cpu_has_apic boot_cpu_has(X86_FEATURE_APIC)
345#define cpu_has_sep boot_cpu_has(X86_FEATURE_SEP)
346#define cpu_has_mtrr boot_cpu_has(X86_FEATURE_MTRR)
347#define cpu_has_mmx boot_cpu_has(X86_FEATURE_MMX)
348#define cpu_has_fxsr boot_cpu_has(X86_FEATURE_FXSR)
349#define cpu_has_xmm boot_cpu_has(X86_FEATURE_XMM)
350#define cpu_has_xmm2 boot_cpu_has(X86_FEATURE_XMM2)
351#define cpu_has_xmm3 boot_cpu_has(X86_FEATURE_XMM3)
352#define cpu_has_ssse3 boot_cpu_has(X86_FEATURE_SSSE3)
353#define cpu_has_aes boot_cpu_has(X86_FEATURE_AES)
354#define cpu_has_avx boot_cpu_has(X86_FEATURE_AVX)
355#define cpu_has_avx2 boot_cpu_has(X86_FEATURE_AVX2)
356#define cpu_has_ht boot_cpu_has(X86_FEATURE_HT)
357#define cpu_has_nx boot_cpu_has(X86_FEATURE_NX)
358#define cpu_has_xstore boot_cpu_has(X86_FEATURE_XSTORE)
359#define cpu_has_xstore_enabled boot_cpu_has(X86_FEATURE_XSTORE_EN)
360#define cpu_has_xcrypt boot_cpu_has(X86_FEATURE_XCRYPT)
361#define cpu_has_xcrypt_enabled boot_cpu_has(X86_FEATURE_XCRYPT_EN)
362#define cpu_has_ace2 boot_cpu_has(X86_FEATURE_ACE2)
363#define cpu_has_ace2_enabled boot_cpu_has(X86_FEATURE_ACE2_EN)
364#define cpu_has_phe boot_cpu_has(X86_FEATURE_PHE)
365#define cpu_has_phe_enabled boot_cpu_has(X86_FEATURE_PHE_EN)
366#define cpu_has_pmm boot_cpu_has(X86_FEATURE_PMM)
367#define cpu_has_pmm_enabled boot_cpu_has(X86_FEATURE_PMM_EN)
368#define cpu_has_ds boot_cpu_has(X86_FEATURE_DS)
369#define cpu_has_pebs boot_cpu_has(X86_FEATURE_PEBS)
370#define cpu_has_clflush boot_cpu_has(X86_FEATURE_CLFLUSH)
371#define cpu_has_bts boot_cpu_has(X86_FEATURE_BTS)
372#define cpu_has_gbpages boot_cpu_has(X86_FEATURE_GBPAGES)
373#define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
374#define cpu_has_pat boot_cpu_has(X86_FEATURE_PAT)
375#define cpu_has_xmm4_1 boot_cpu_has(X86_FEATURE_XMM4_1)
376#define cpu_has_xmm4_2 boot_cpu_has(X86_FEATURE_XMM4_2)
377#define cpu_has_x2apic boot_cpu_has(X86_FEATURE_X2APIC)
378#define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
379#define cpu_has_xsaveopt boot_cpu_has(X86_FEATURE_XSAVEOPT)
380#define cpu_has_xsaves boot_cpu_has(X86_FEATURE_XSAVES)
381#define cpu_has_osxsave boot_cpu_has(X86_FEATURE_OSXSAVE)
382#define cpu_has_hypervisor boot_cpu_has(X86_FEATURE_HYPERVISOR)
383#define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ)
384#define cpu_has_perfctr_core boot_cpu_has(X86_FEATURE_PERFCTR_CORE)
385#define cpu_has_perfctr_nb boot_cpu_has(X86_FEATURE_PERFCTR_NB)
386#define cpu_has_perfctr_l2 boot_cpu_has(X86_FEATURE_PERFCTR_L2)
387#define cpu_has_cx8 boot_cpu_has(X86_FEATURE_CX8)
388#define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
389#define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
390#define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
391
392#if __GNUC__ >= 4
393extern void warn_pre_alternatives(void);
394extern bool __static_cpu_has_safe(u16 bit);
395
396
397
398
399
400
401static __always_inline __pure bool __static_cpu_has(u16 bit)
402{
403#ifdef CC_HAVE_ASM_GOTO
404
405#ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
406
407
408
409
410
411 asm_volatile_goto("1: jmp %l[t_warn]\n"
412 "2:\n"
413 ".section .altinstructions,\"a\"\n"
414 " .long 1b - .\n"
415 " .long 0\n"
416 " .word %P0\n"
417 " .byte 2b - 1b\n"
418 " .byte 0\n"
419 ".previous\n"
420
421 : : "i" (X86_FEATURE_ALWAYS) : : t_warn);
422
423#endif
424
425 asm_volatile_goto("1: jmp %l[t_no]\n"
426 "2:\n"
427 ".section .altinstructions,\"a\"\n"
428 " .long 1b - .\n"
429 " .long 0\n"
430 " .word %P0\n"
431 " .byte 2b - 1b\n"
432 " .byte 0\n"
433 ".previous\n"
434
435 : : "i" (bit) : : t_no);
436 return true;
437 t_no:
438 return false;
439
440#ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
441 t_warn:
442 warn_pre_alternatives();
443 return false;
444#endif
445
446#else
447
448 u8 flag;
449
450 asm volatile("1: movb $0,%0\n"
451 "2:\n"
452 ".section .altinstructions,\"a\"\n"
453 " .long 1b - .\n"
454 " .long 3f - .\n"
455 " .word %P1\n"
456 " .byte 2b - 1b\n"
457 " .byte 4f - 3f\n"
458 ".previous\n"
459 ".section .discard,\"aw\",@progbits\n"
460 " .byte 0xff + (4f-3f) - (2b-1b)\n"
461 ".previous\n"
462 ".section .altinstr_replacement,\"ax\"\n"
463 "3: movb $1,%0\n"
464 "4:\n"
465 ".previous\n"
466 : "=qm" (flag) : "i" (bit));
467 return flag;
468
469#endif
470}
471
472#define static_cpu_has(bit) \
473( \
474 __builtin_constant_p(boot_cpu_has(bit)) ? \
475 boot_cpu_has(bit) : \
476 __builtin_constant_p(bit) ? \
477 __static_cpu_has(bit) : \
478 boot_cpu_has(bit) \
479)
480
481static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
482{
483#ifdef CC_HAVE_ASM_GOTO
484
485
486
487
488
489
490 asm_volatile_goto("1: .byte 0xe9\n .long %l[t_dynamic] - 2f\n"
491 "2:\n"
492 ".section .altinstructions,\"a\"\n"
493 " .long 1b - .\n"
494 " .long 3f - .\n"
495 " .word %P1\n"
496 " .byte 2b - 1b\n"
497 " .byte 4f - 3f\n"
498 ".previous\n"
499 ".section .altinstr_replacement,\"ax\"\n"
500 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
501 "4:\n"
502 ".previous\n"
503 ".section .altinstructions,\"a\"\n"
504 " .long 1b - .\n"
505 " .long 0\n"
506 " .word %P0\n"
507 " .byte 2b - 1b\n"
508 " .byte 0\n"
509 ".previous\n"
510 : : "i" (bit), "i" (X86_FEATURE_ALWAYS)
511 : : t_dynamic, t_no);
512 return true;
513 t_no:
514 return false;
515 t_dynamic:
516 return __static_cpu_has_safe(bit);
517#else
518 u8 flag;
519
520 asm volatile("1: movb $2,%0\n"
521 "2:\n"
522 ".section .altinstructions,\"a\"\n"
523 " .long 1b - .\n"
524 " .long 3f - .\n"
525 " .word %P2\n"
526 " .byte 2b - 1b\n"
527 " .byte 4f - 3f\n"
528 ".previous\n"
529 ".section .discard,\"aw\",@progbits\n"
530 " .byte 0xff + (4f-3f) - (2b-1b)\n"
531 ".previous\n"
532 ".section .altinstr_replacement,\"ax\"\n"
533 "3: movb $0,%0\n"
534 "4:\n"
535 ".previous\n"
536 ".section .altinstructions,\"a\"\n"
537 " .long 1b - .\n"
538 " .long 5f - .\n"
539 " .word %P1\n"
540 " .byte 4b - 3b\n"
541 " .byte 6f - 5f\n"
542 ".previous\n"
543 ".section .discard,\"aw\",@progbits\n"
544 " .byte 0xff + (6f-5f) - (4b-3b)\n"
545 ".previous\n"
546 ".section .altinstr_replacement,\"ax\"\n"
547 "5: movb $1,%0\n"
548 "6:\n"
549 ".previous\n"
550 : "=qm" (flag)
551 : "i" (bit), "i" (X86_FEATURE_ALWAYS));
552 return (flag == 2 ? __static_cpu_has_safe(bit) : flag);
553#endif
554}
555
556#define static_cpu_has_safe(bit) \
557( \
558 __builtin_constant_p(boot_cpu_has(bit)) ? \
559 boot_cpu_has(bit) : \
560 _static_cpu_has_safe(bit) \
561)
562#else
563
564
565
566#define static_cpu_has(bit) boot_cpu_has(bit)
567#define static_cpu_has_safe(bit) boot_cpu_has(bit)
568#endif
569
570#define cpu_has_bug(c, bit) cpu_has(c, (bit))
571#define set_cpu_bug(c, bit) set_cpu_cap(c, (bit))
572#define clear_cpu_bug(c, bit) clear_cpu_cap(c, (bit))
573
574#define static_cpu_has_bug(bit) static_cpu_has((bit))
575#define static_cpu_has_bug_safe(bit) static_cpu_has_safe((bit))
576#define boot_cpu_has_bug(bit) cpu_has_bug(&boot_cpu_data, (bit))
577
578#define MAX_CPU_FEATURES (NCAPINTS * 32)
579#define cpu_have_feature boot_cpu_has
580
581#define CPU_FEATURE_TYPEFMT "x86,ven%04Xfam%04Xmod%04X"
582#define CPU_FEATURE_TYPEVAL boot_cpu_data.x86_vendor, boot_cpu_data.x86, \
583 boot_cpu_data.x86_model
584
585#endif
586#endif
587