1*1b8adde7SWilliam Kucharski #ifndef I386_BITS_CPU_H 2*1b8adde7SWilliam Kucharski #define I386_BITS_CPU_H 3*1b8adde7SWilliam Kucharski 4*1b8adde7SWilliam Kucharski 5*1b8adde7SWilliam Kucharski /* Sample usage: CPU_FEATURE_P(cpu.x86_capability, FPU) */ 6*1b8adde7SWilliam Kucharski #define CPU_FEATURE_P(CAP, FEATURE) \ 7*1b8adde7SWilliam Kucharski (!!(CAP[(X86_FEATURE_##FEATURE)/32] & ((X86_FEATURE_##FEATURE) & 0x1f))) 8*1b8adde7SWilliam Kucharski 9*1b8adde7SWilliam Kucharski #define NCAPINTS 4 /* Currently we have 4 32-bit words worth of info */ 10*1b8adde7SWilliam Kucharski 11*1b8adde7SWilliam Kucharski /* Intel-defined CPU features, CPUID level 0x00000001, word 0 */ 12*1b8adde7SWilliam Kucharski #define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */ 13*1b8adde7SWilliam Kucharski #define X86_FEATURE_VME (0*32+ 1) /* Virtual Mode Extensions */ 14*1b8adde7SWilliam Kucharski #define X86_FEATURE_DE (0*32+ 2) /* Debugging Extensions */ 15*1b8adde7SWilliam Kucharski #define X86_FEATURE_PSE (0*32+ 3) /* Page Size Extensions */ 16*1b8adde7SWilliam Kucharski #define X86_FEATURE_TSC (0*32+ 4) /* Time Stamp Counter */ 17*1b8adde7SWilliam Kucharski #define X86_FEATURE_MSR (0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */ 18*1b8adde7SWilliam Kucharski #define X86_FEATURE_PAE (0*32+ 6) /* Physical Address Extensions */ 19*1b8adde7SWilliam Kucharski #define X86_FEATURE_MCE (0*32+ 7) /* Machine Check Architecture */ 20*1b8adde7SWilliam Kucharski #define X86_FEATURE_CX8 (0*32+ 8) /* CMPXCHG8 instruction */ 21*1b8adde7SWilliam Kucharski #define X86_FEATURE_APIC (0*32+ 9) /* Onboard APIC */ 22*1b8adde7SWilliam Kucharski #define X86_FEATURE_SEP (0*32+11) /* SYSENTER/SYSEXIT */ 23*1b8adde7SWilliam Kucharski #define X86_FEATURE_MTRR (0*32+12) /* Memory Type Range Registers */ 24*1b8adde7SWilliam Kucharski #define X86_FEATURE_PGE (0*32+13) /* Page Global Enable */ 25*1b8adde7SWilliam Kucharski #define X86_FEATURE_MCA (0*32+14) /* Machine Check Architecture */ 26*1b8adde7SWilliam Kucharski #define X86_FEATURE_CMOV (0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */ 27*1b8adde7SWilliam Kucharski #define X86_FEATURE_PAT (0*32+16) /* Page Attribute Table */ 28*1b8adde7SWilliam Kucharski #define X86_FEATURE_PSE36 (0*32+17) /* 36-bit PSEs */ 29*1b8adde7SWilliam Kucharski #define X86_FEATURE_PN (0*32+18) /* Processor serial number */ 30*1b8adde7SWilliam Kucharski #define X86_FEATURE_CLFLSH (0*32+19) /* Supports the CLFLUSH instruction */ 31*1b8adde7SWilliam Kucharski #define X86_FEATURE_DTES (0*32+21) /* Debug Trace Store */ 32*1b8adde7SWilliam Kucharski #define X86_FEATURE_ACPI (0*32+22) /* ACPI via MSR */ 33*1b8adde7SWilliam Kucharski #define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */ 34*1b8adde7SWilliam Kucharski #define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */ 35*1b8adde7SWilliam Kucharski /* of FPU context), and CR4.OSFXSR available */ 36*1b8adde7SWilliam Kucharski #define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */ 37*1b8adde7SWilliam Kucharski #define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */ 38*1b8adde7SWilliam Kucharski #define X86_FEATURE_SELFSNOOP (0*32+27) /* CPU self snoop */ 39*1b8adde7SWilliam Kucharski #define X86_FEATURE_HT (0*32+28) /* Hyper-Threading */ 40*1b8adde7SWilliam Kucharski #define X86_FEATURE_ACC (0*32+29) /* Automatic clock control */ 41*1b8adde7SWilliam Kucharski #define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */ 42*1b8adde7SWilliam Kucharski 43*1b8adde7SWilliam Kucharski /* AMD-defined CPU features, CPUID level 0x80000001, word 1 */ 44*1b8adde7SWilliam Kucharski /* Don't duplicate feature flags which are redundant with Intel! */ 45*1b8adde7SWilliam Kucharski #define X86_FEATURE_SYSCALL (1*32+11) /* SYSCALL/SYSRET */ 46*1b8adde7SWilliam Kucharski #define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */ 47*1b8adde7SWilliam Kucharski #define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */ 48*1b8adde7SWilliam Kucharski #define X86_FEATURE_3DNOWEXT (1*32+30) /* AMD 3DNow! extensions */ 49*1b8adde7SWilliam Kucharski #define X86_FEATURE_3DNOW (1*32+31) /* 3DNow! */ 50*1b8adde7SWilliam Kucharski 51*1b8adde7SWilliam Kucharski /* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */ 52*1b8adde7SWilliam Kucharski #define X86_FEATURE_RECOVERY (2*32+ 0) /* CPU in recovery mode */ 53*1b8adde7SWilliam Kucharski #define X86_FEATURE_LONGRUN (2*32+ 1) /* Longrun power control */ 54*1b8adde7SWilliam Kucharski #define X86_FEATURE_LRTI (2*32+ 3) /* LongRun table interface */ 55*1b8adde7SWilliam Kucharski 56*1b8adde7SWilliam Kucharski /* Other features, Linux-defined mapping, word 3 */ 57*1b8adde7SWilliam Kucharski /* This range is used for feature bits which conflict or are synthesized */ 58*1b8adde7SWilliam Kucharski #define X86_FEATURE_CXMMX (3*32+ 0) /* Cyrix MMX extensions */ 59*1b8adde7SWilliam Kucharski #define X86_FEATURE_K6_MTRR (3*32+ 1) /* AMD K6 nonstandard MTRRs */ 60*1b8adde7SWilliam Kucharski #define X86_FEATURE_CYRIX_ARR (3*32+ 2) /* Cyrix ARRs (= MTRRs) */ 61*1b8adde7SWilliam Kucharski #define X86_FEATURE_CENTAUR_MCR (3*32+ 3) /* Centaur MCRs (= MTRRs) */ 62*1b8adde7SWilliam Kucharski 63*1b8adde7SWilliam Kucharski #define MAX_X86_VENDOR_ID 16 64*1b8adde7SWilliam Kucharski struct cpuinfo_x86 { 65*1b8adde7SWilliam Kucharski uint8_t x86; /* CPU family */ 66*1b8adde7SWilliam Kucharski uint8_t x86_model; 67*1b8adde7SWilliam Kucharski uint8_t x86_mask; 68*1b8adde7SWilliam Kucharski 69*1b8adde7SWilliam Kucharski int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */ 70*1b8adde7SWilliam Kucharski unsigned x86_capability[NCAPINTS]; 71*1b8adde7SWilliam Kucharski char x86_vendor_id[MAX_X86_VENDOR_ID]; 72*1b8adde7SWilliam Kucharski }; 73*1b8adde7SWilliam Kucharski 74*1b8adde7SWilliam Kucharski 75*1b8adde7SWilliam Kucharski #define X86_VENDOR_INTEL 0 76*1b8adde7SWilliam Kucharski #define X86_VENDOR_CYRIX 1 77*1b8adde7SWilliam Kucharski #define X86_VENDOR_AMD 2 78*1b8adde7SWilliam Kucharski #define X86_VENDOR_UMC 3 79*1b8adde7SWilliam Kucharski #define X86_VENDOR_NEXGEN 4 80*1b8adde7SWilliam Kucharski #define X86_VENDOR_CENTAUR 5 81*1b8adde7SWilliam Kucharski #define X86_VENDOR_RISE 6 82*1b8adde7SWilliam Kucharski #define X86_VENDOR_TRANSMETA 7 83*1b8adde7SWilliam Kucharski #define X86_VENDOR_NSC 8 84*1b8adde7SWilliam Kucharski #define X86_VENDOR_UNKNOWN 0xff 85*1b8adde7SWilliam Kucharski 86*1b8adde7SWilliam Kucharski /* 87*1b8adde7SWilliam Kucharski * EFLAGS bits 88*1b8adde7SWilliam Kucharski */ 89*1b8adde7SWilliam Kucharski #define X86_EFLAGS_CF 0x00000001 /* Carry Flag */ 90*1b8adde7SWilliam Kucharski #define X86_EFLAGS_PF 0x00000004 /* Parity Flag */ 91*1b8adde7SWilliam Kucharski #define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */ 92*1b8adde7SWilliam Kucharski #define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */ 93*1b8adde7SWilliam Kucharski #define X86_EFLAGS_SF 0x00000080 /* Sign Flag */ 94*1b8adde7SWilliam Kucharski #define X86_EFLAGS_TF 0x00000100 /* Trap Flag */ 95*1b8adde7SWilliam Kucharski #define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */ 96*1b8adde7SWilliam Kucharski #define X86_EFLAGS_DF 0x00000400 /* Direction Flag */ 97*1b8adde7SWilliam Kucharski #define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */ 98*1b8adde7SWilliam Kucharski #define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */ 99*1b8adde7SWilliam Kucharski #define X86_EFLAGS_NT 0x00004000 /* Nested Task */ 100*1b8adde7SWilliam Kucharski #define X86_EFLAGS_RF 0x00010000 /* Resume Flag */ 101*1b8adde7SWilliam Kucharski #define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */ 102*1b8adde7SWilliam Kucharski #define X86_EFLAGS_AC 0x00040000 /* Alignment Check */ 103*1b8adde7SWilliam Kucharski #define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */ 104*1b8adde7SWilliam Kucharski #define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */ 105*1b8adde7SWilliam Kucharski #define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */ 106*1b8adde7SWilliam Kucharski 107*1b8adde7SWilliam Kucharski /* 108*1b8adde7SWilliam Kucharski * Generic CPUID function 109*1b8adde7SWilliam Kucharski */ 110*1b8adde7SWilliam Kucharski static inline void cpuid(int op, 111*1b8adde7SWilliam Kucharski unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) 112*1b8adde7SWilliam Kucharski { 113*1b8adde7SWilliam Kucharski __asm__("cpuid" 114*1b8adde7SWilliam Kucharski : "=a" (*eax), 115*1b8adde7SWilliam Kucharski "=b" (*ebx), 116*1b8adde7SWilliam Kucharski "=c" (*ecx), 117*1b8adde7SWilliam Kucharski "=d" (*edx) 118*1b8adde7SWilliam Kucharski : "0" (op)); 119*1b8adde7SWilliam Kucharski } 120*1b8adde7SWilliam Kucharski 121*1b8adde7SWilliam Kucharski /* 122*1b8adde7SWilliam Kucharski * CPUID functions returning a single datum 123*1b8adde7SWilliam Kucharski */ 124*1b8adde7SWilliam Kucharski static inline unsigned int cpuid_eax(unsigned int op) 125*1b8adde7SWilliam Kucharski { 126*1b8adde7SWilliam Kucharski unsigned int eax; 127*1b8adde7SWilliam Kucharski 128*1b8adde7SWilliam Kucharski __asm__("cpuid" 129*1b8adde7SWilliam Kucharski : "=a" (eax) 130*1b8adde7SWilliam Kucharski : "0" (op) 131*1b8adde7SWilliam Kucharski : "bx", "cx", "dx"); 132*1b8adde7SWilliam Kucharski return eax; 133*1b8adde7SWilliam Kucharski } 134*1b8adde7SWilliam Kucharski static inline unsigned int cpuid_ebx(unsigned int op) 135*1b8adde7SWilliam Kucharski { 136*1b8adde7SWilliam Kucharski unsigned int eax, ebx; 137*1b8adde7SWilliam Kucharski 138*1b8adde7SWilliam Kucharski __asm__("cpuid" 139*1b8adde7SWilliam Kucharski : "=a" (eax), "=b" (ebx) 140*1b8adde7SWilliam Kucharski : "0" (op) 141*1b8adde7SWilliam Kucharski : "cx", "dx" ); 142*1b8adde7SWilliam Kucharski return ebx; 143*1b8adde7SWilliam Kucharski } 144*1b8adde7SWilliam Kucharski static inline unsigned int cpuid_ecx(unsigned int op) 145*1b8adde7SWilliam Kucharski { 146*1b8adde7SWilliam Kucharski unsigned int eax, ecx; 147*1b8adde7SWilliam Kucharski 148*1b8adde7SWilliam Kucharski __asm__("cpuid" 149*1b8adde7SWilliam Kucharski : "=a" (eax), "=c" (ecx) 150*1b8adde7SWilliam Kucharski : "0" (op) 151*1b8adde7SWilliam Kucharski : "bx", "dx" ); 152*1b8adde7SWilliam Kucharski return ecx; 153*1b8adde7SWilliam Kucharski } 154*1b8adde7SWilliam Kucharski static inline unsigned int cpuid_edx(unsigned int op) 155*1b8adde7SWilliam Kucharski { 156*1b8adde7SWilliam Kucharski unsigned int eax, edx; 157*1b8adde7SWilliam Kucharski 158*1b8adde7SWilliam Kucharski __asm__("cpuid" 159*1b8adde7SWilliam Kucharski : "=a" (eax), "=d" (edx) 160*1b8adde7SWilliam Kucharski : "0" (op) 161*1b8adde7SWilliam Kucharski : "bx", "cx"); 162*1b8adde7SWilliam Kucharski return edx; 163*1b8adde7SWilliam Kucharski } 164*1b8adde7SWilliam Kucharski 165*1b8adde7SWilliam Kucharski /* 166*1b8adde7SWilliam Kucharski * Intel CPU features in CR4 167*1b8adde7SWilliam Kucharski */ 168*1b8adde7SWilliam Kucharski #define X86_CR4_VME 0x0001 /* enable vm86 extensions */ 169*1b8adde7SWilliam Kucharski #define X86_CR4_PVI 0x0002 /* virtual interrupts flag enable */ 170*1b8adde7SWilliam Kucharski #define X86_CR4_TSD 0x0004 /* disable time stamp at ipl 3 */ 171*1b8adde7SWilliam Kucharski #define X86_CR4_DE 0x0008 /* enable debugging extensions */ 172*1b8adde7SWilliam Kucharski #define X86_CR4_PSE 0x0010 /* enable page size extensions */ 173*1b8adde7SWilliam Kucharski #define X86_CR4_PAE 0x0020 /* enable physical address extensions */ 174*1b8adde7SWilliam Kucharski #define X86_CR4_MCE 0x0040 /* Machine check enable */ 175*1b8adde7SWilliam Kucharski #define X86_CR4_PGE 0x0080 /* enable global pages */ 176*1b8adde7SWilliam Kucharski #define X86_CR4_PCE 0x0100 /* enable performance counters at ipl 3 */ 177*1b8adde7SWilliam Kucharski #define X86_CR4_OSFXSR 0x0200 /* enable fast FPU save and restore */ 178*1b8adde7SWilliam Kucharski #define X86_CR4_OSXMMEXCPT 0x0400 /* enable unmasked SSE exceptions */ 179*1b8adde7SWilliam Kucharski 180*1b8adde7SWilliam Kucharski 181*1b8adde7SWilliam Kucharski #define MSR_K6_EFER 0xC0000080 182*1b8adde7SWilliam Kucharski /* EFER bits: */ 183*1b8adde7SWilliam Kucharski #define _EFER_SCE 0 /* SYSCALL/SYSRET */ 184*1b8adde7SWilliam Kucharski #define _EFER_LME 8 /* Long mode enable */ 185*1b8adde7SWilliam Kucharski #define _EFER_LMA 10 /* Long mode active (read-only) */ 186*1b8adde7SWilliam Kucharski #define _EFER_NX 11 /* No execute enable */ 187*1b8adde7SWilliam Kucharski 188*1b8adde7SWilliam Kucharski #define EFER_SCE (1<<_EFER_SCE) 189*1b8adde7SWilliam Kucharski #define EFER_LME (1<<EFER_LME) 190*1b8adde7SWilliam Kucharski #define EFER_LMA (1<<EFER_LMA) 191*1b8adde7SWilliam Kucharski #define EFER_NX (1<<_EFER_NX) 192*1b8adde7SWilliam Kucharski 193*1b8adde7SWilliam Kucharski #define rdmsr(msr,val1,val2) \ 194*1b8adde7SWilliam Kucharski __asm__ __volatile__("rdmsr" \ 195*1b8adde7SWilliam Kucharski : "=a" (val1), "=d" (val2) \ 196*1b8adde7SWilliam Kucharski : "c" (msr)) 197*1b8adde7SWilliam Kucharski 198*1b8adde7SWilliam Kucharski #define wrmsr(msr,val1,val2) \ 199*1b8adde7SWilliam Kucharski __asm__ __volatile__("wrmsr" \ 200*1b8adde7SWilliam Kucharski : /* no outputs */ \ 201*1b8adde7SWilliam Kucharski : "c" (msr), "a" (val1), "d" (val2)) 202*1b8adde7SWilliam Kucharski 203*1b8adde7SWilliam Kucharski 204*1b8adde7SWilliam Kucharski #define read_cr0() ({ \ 205*1b8adde7SWilliam Kucharski unsigned int __dummy; \ 206*1b8adde7SWilliam Kucharski __asm__( \ 207*1b8adde7SWilliam Kucharski "movl %%cr0, %0\n\t" \ 208*1b8adde7SWilliam Kucharski :"=r" (__dummy)); \ 209*1b8adde7SWilliam Kucharski __dummy; \ 210*1b8adde7SWilliam Kucharski }) 211*1b8adde7SWilliam Kucharski #define write_cr0(x) \ 212*1b8adde7SWilliam Kucharski __asm__("movl %0,%%cr0": :"r" (x)); 213*1b8adde7SWilliam Kucharski 214*1b8adde7SWilliam Kucharski #define read_cr3() ({ \ 215*1b8adde7SWilliam Kucharski unsigned int __dummy; \ 216*1b8adde7SWilliam Kucharski __asm__( \ 217*1b8adde7SWilliam Kucharski "movl %%cr3, %0\n\t" \ 218*1b8adde7SWilliam Kucharski :"=r" (__dummy)); \ 219*1b8adde7SWilliam Kucharski __dummy; \ 220*1b8adde7SWilliam Kucharski }) 221*1b8adde7SWilliam Kucharski #define write_cr3x(x) \ 222*1b8adde7SWilliam Kucharski __asm__("movl %0,%%cr3": :"r" (x)); 223*1b8adde7SWilliam Kucharski 224*1b8adde7SWilliam Kucharski 225*1b8adde7SWilliam Kucharski #define read_cr4() ({ \ 226*1b8adde7SWilliam Kucharski unsigned int __dummy; \ 227*1b8adde7SWilliam Kucharski __asm__( \ 228*1b8adde7SWilliam Kucharski "movl %%cr4, %0\n\t" \ 229*1b8adde7SWilliam Kucharski :"=r" (__dummy)); \ 230*1b8adde7SWilliam Kucharski __dummy; \ 231*1b8adde7SWilliam Kucharski }) 232*1b8adde7SWilliam Kucharski #define write_cr4x(x) \ 233*1b8adde7SWilliam Kucharski __asm__("movl %0,%%cr4": :"r" (x)); 234*1b8adde7SWilliam Kucharski 235*1b8adde7SWilliam Kucharski 236*1b8adde7SWilliam Kucharski extern struct cpuinfo_x86 cpu_info; 237*1b8adde7SWilliam Kucharski #ifdef CONFIG_X86_64 238*1b8adde7SWilliam Kucharski extern void cpu_setup(void); 239*1b8adde7SWilliam Kucharski #else 240*1b8adde7SWilliam Kucharski #define cpu_setup() do {} while(0) 241*1b8adde7SWilliam Kucharski #endif 242*1b8adde7SWilliam Kucharski 243*1b8adde7SWilliam Kucharski #endif /* I386_BITS_CPU_H */ 244