| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#ifndef _ARCH_CPUID_H |
| 30 |
#define _ARCH_CPUID_H |
| 31 |
|
| 32 |
#define cpuid(fn, eax, ebx, ecx, edx) \ |
| 33 |
asm("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "0"(fn)) |
| 34 |
|
| 35 |
#define _declare_cpuid(reg) \ |
| 36 |
static inline unsigned int cpuid_##reg(unsigned int fn) \ |
| 37 |
{ \ |
| 38 |
unsigned int eax, ebx, ecx, edx; \ |
| 39 |
cpuid(fn, eax, ebx, ecx, edx); \ |
| 40 |
return reg; \ |
| 41 |
} |
| 42 |
|
| 43 |
_declare_cpuid(eax) |
| 44 |
_declare_cpuid(ebx) |
| 45 |
_declare_cpuid(ecx) |
| 46 |
_declare_cpuid(edx) |
| 47 |
|
| 48 |
#undef _declare_cpuid |
| 49 |
|
| 50 |
#define cpuid_sub_leaf(fn, sub_leaf, eax, ebx, ecx, edx) \ |
| 51 |
asm("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "0"(fn), "1"(sub_leaf)) |
| 52 |
|
| 53 |
#define _declare_cpuid_sub_leaf(reg) \ |
| 54 |
static inline unsigned int cpuid_sub_leaf_##reg( \ |
| 55 |
unsigned int fn, unsigned int sub_leaf) \ |
| 56 |
{ \ |
| 57 |
unsigned int eax, ebx, ecx, edx; \ |
| 58 |
cpuid_sub_leaf(fn, sub_leaf, eax, ebx, ecx, edx); \ |
| 59 |
return reg; \ |
| 60 |
} |
| 61 |
|
| 62 |
_declare_cpuid_sub_leaf(eax) |
| 63 |
_declare_cpuid_sub_leaf(ebx) |
| 64 |
_declare_cpuid_sub_leaf(ecx) |
| 65 |
_declare_cpuid_sub_leaf(edx) |
| 66 |
|
| 67 |
#undef _declare_cpuid_sub_leaf |
| 68 |
|
| 69 |
static inline unsigned int cpuid_max(void) |
| 70 |
{ |
| 71 |
return cpuid_eax(0); |
| 72 |
} |
| 73 |
|
| 74 |
static inline unsigned int cpuid_family(void) |
| 75 |
{ |
| 76 |
const unsigned int eax = cpuid_eax(1); |
| 77 |
return (eax & 0xff00000) >> (20 - 4) | (eax & 0xf00) >> 8; |
| 78 |
} |
| 79 |
|
| 80 |
static inline unsigned int cpuid_model(void) |
| 81 |
{ |
| 82 |
const unsigned int eax = cpuid_eax(1); |
| 83 |
return (eax & 0xf0000) >> (16 - 4) | (eax & 0xf0) >> 4; |
| 84 |
} |
| 85 |
|
| 86 |
enum intel_fam6_model { |
| 87 |
NEHALEM = 0x25, |
| 88 |
SANDYBRIDGE = 0x2a, |
| 89 |
IVYBRIDGE = 0x3a, |
| 90 |
HASWELL = 0x3c, |
| 91 |
BROADWELL_U = 0x3d, |
| 92 |
HASWELL_U = 0x45, |
| 93 |
HASWELL_GT3E = 0x46, |
| 94 |
BROADWELL = 0x47, |
| 95 |
SKYLAKE_U_Y = 0x4e, |
| 96 |
APOLLOLAKE = 0x5c, |
| 97 |
SKYLAKE_S_H = 0x5e, |
| 98 |
KABYLAKE_U_Y = 0x8e, |
| 99 |
KABYLAKE_S_H = 0x9e, |
| 100 |
}; |
| 101 |
|
| 102 |
#endif |