]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
0a7de745 | 2 | * Copyright (c) 2000-2019 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | ||
32 | /* | |
33 | * x86 CPU identification | |
34 | * | |
1c79356b A |
35 | */ |
36 | ||
37 | #ifndef _MACHINE_CPUID_H_ | |
38 | #define _MACHINE_CPUID_H_ | |
39 | ||
55e303ae A |
40 | #include <sys/appleapiopts.h> |
41 | ||
0a7de745 A |
42 | #if defined(MACH_KERNEL_PRIVATE) && !defined(ASSEMBLER) |
43 | #include <i386/hw_defs.h> | |
44 | #include <i386/pio.h> | |
45 | #include <i386/machine_routines.h> | |
46 | #endif | |
47 | ||
55e303ae A |
48 | #ifdef __APPLE_API_PRIVATE |
49 | ||
0a7de745 A |
50 | #define CPUID_VID_INTEL "GenuineIntel" |
51 | #define CPUID_VID_AMD "AuthenticAMD" | |
91447636 | 52 | |
0a7de745 A |
53 | #define CPUID_VMM_ID_VMWARE "VMwareVMware" |
54 | #define CPUID_VMM_ID_PARALLELS "Parallels\0\0\0" | |
316670eb | 55 | |
91447636 | 56 | #define CPUID_STRING_UNKNOWN "Unknown CPU Typ" |
1c79356b | 57 | |
0a7de745 A |
58 | #define _Bit(n) (1ULL << n) |
59 | #define _HBit(n) (1ULL << ((n)+32)) | |
0c530ab8 A |
60 | |
61 | /* | |
62 | * The CPUID_FEATURE_XXX values define 64-bit values | |
0a7de745 | 63 | * returned in %ecx:%edx to a CPUID request with %eax of 1: |
0c530ab8 | 64 | */ |
060df5ea A |
65 | #define CPUID_FEATURE_FPU _Bit(0) /* Floating point unit on-chip */ |
66 | #define CPUID_FEATURE_VME _Bit(1) /* Virtual Mode Extension */ | |
67 | #define CPUID_FEATURE_DE _Bit(2) /* Debugging Extension */ | |
68 | #define CPUID_FEATURE_PSE _Bit(3) /* Page Size Extension */ | |
69 | #define CPUID_FEATURE_TSC _Bit(4) /* Time Stamp Counter */ | |
70 | #define CPUID_FEATURE_MSR _Bit(5) /* Model Specific Registers */ | |
71 | #define CPUID_FEATURE_PAE _Bit(6) /* Physical Address Extension */ | |
72 | #define CPUID_FEATURE_MCE _Bit(7) /* Machine Check Exception */ | |
73 | #define CPUID_FEATURE_CX8 _Bit(8) /* CMPXCHG8B */ | |
74 | #define CPUID_FEATURE_APIC _Bit(9) /* On-chip APIC */ | |
75 | #define CPUID_FEATURE_SEP _Bit(11) /* Fast System Call */ | |
76 | #define CPUID_FEATURE_MTRR _Bit(12) /* Memory Type Range Register */ | |
77 | #define CPUID_FEATURE_PGE _Bit(13) /* Page Global Enable */ | |
78 | #define CPUID_FEATURE_MCA _Bit(14) /* Machine Check Architecture */ | |
79 | #define CPUID_FEATURE_CMOV _Bit(15) /* Conditional Move Instruction */ | |
80 | #define CPUID_FEATURE_PAT _Bit(16) /* Page Attribute Table */ | |
81 | #define CPUID_FEATURE_PSE36 _Bit(17) /* 36-bit Page Size Extension */ | |
82 | #define CPUID_FEATURE_PSN _Bit(18) /* Processor Serial Number */ | |
83 | #define CPUID_FEATURE_CLFSH _Bit(19) /* CLFLUSH Instruction supported */ | |
84 | #define CPUID_FEATURE_DS _Bit(21) /* Debug Store */ | |
85 | #define CPUID_FEATURE_ACPI _Bit(22) /* Thermal monitor and Clock Ctrl */ | |
86 | #define CPUID_FEATURE_MMX _Bit(23) /* MMX supported */ | |
87 | #define CPUID_FEATURE_FXSR _Bit(24) /* Fast floating pt save/restore */ | |
88 | #define CPUID_FEATURE_SSE _Bit(25) /* Streaming SIMD extensions */ | |
89 | #define CPUID_FEATURE_SSE2 _Bit(26) /* Streaming SIMD extensions 2 */ | |
90 | #define CPUID_FEATURE_SS _Bit(27) /* Self-Snoop */ | |
91 | #define CPUID_FEATURE_HTT _Bit(28) /* Hyper-Threading Technology */ | |
92 | #define CPUID_FEATURE_TM _Bit(29) /* Thermal Monitor (TM1) */ | |
93 | #define CPUID_FEATURE_PBE _Bit(31) /* Pend Break Enable */ | |
0a7de745 | 94 | |
060df5ea A |
95 | #define CPUID_FEATURE_SSE3 _HBit(0) /* Streaming SIMD extensions 3 */ |
96 | #define CPUID_FEATURE_PCLMULQDQ _HBit(1) /* PCLMULQDQ instruction */ | |
97 | #define CPUID_FEATURE_DTES64 _HBit(2) /* 64-bit DS layout */ | |
98 | #define CPUID_FEATURE_MONITOR _HBit(3) /* Monitor/mwait */ | |
99 | #define CPUID_FEATURE_DSCPL _HBit(4) /* Debug Store CPL */ | |
100 | #define CPUID_FEATURE_VMX _HBit(5) /* VMX */ | |
101 | #define CPUID_FEATURE_SMX _HBit(6) /* SMX */ | |
102 | #define CPUID_FEATURE_EST _HBit(7) /* Enhanced SpeedsTep (GV3) */ | |
103 | #define CPUID_FEATURE_TM2 _HBit(8) /* Thermal Monitor 2 */ | |
104 | #define CPUID_FEATURE_SSSE3 _HBit(9) /* Supplemental SSE3 instructions */ | |
105 | #define CPUID_FEATURE_CID _HBit(10) /* L1 Context ID */ | |
7ddcb079 | 106 | #define CPUID_FEATURE_SEGLIM64 _HBit(11) /* 64-bit segment limit checking */ |
bd504ef0 | 107 | #define CPUID_FEATURE_FMA _HBit(12) /* Fused-Multiply-Add support */ |
060df5ea A |
108 | #define CPUID_FEATURE_CX16 _HBit(13) /* CmpXchg16b instruction */ |
109 | #define CPUID_FEATURE_xTPR _HBit(14) /* Send Task PRiority msgs */ | |
110 | #define CPUID_FEATURE_PDCM _HBit(15) /* Perf/Debug Capability MSR */ | |
111 | ||
7ddcb079 | 112 | #define CPUID_FEATURE_PCID _HBit(17) /* ASID-PCID support */ |
060df5ea A |
113 | #define CPUID_FEATURE_DCA _HBit(18) /* Direct Cache Access */ |
114 | #define CPUID_FEATURE_SSE4_1 _HBit(19) /* Streaming SIMD extensions 4.1 */ | |
115 | #define CPUID_FEATURE_SSE4_2 _HBit(20) /* Streaming SIMD extensions 4.2 */ | |
bd504ef0 | 116 | #define CPUID_FEATURE_x2APIC _HBit(21) /* Extended APIC Mode */ |
060df5ea A |
117 | #define CPUID_FEATURE_MOVBE _HBit(22) /* MOVBE instruction */ |
118 | #define CPUID_FEATURE_POPCNT _HBit(23) /* POPCNT instruction */ | |
7ddcb079 | 119 | #define CPUID_FEATURE_TSCTMR _HBit(24) /* TSC deadline timer */ |
060df5ea A |
120 | #define CPUID_FEATURE_AES _HBit(25) /* AES instructions */ |
121 | #define CPUID_FEATURE_XSAVE _HBit(26) /* XSAVE instructions */ | |
122 | #define CPUID_FEATURE_OSXSAVE _HBit(27) /* XGETBV/XSETBV instructions */ | |
0a7de745 A |
123 | #define CPUID_FEATURE_AVX1_0 _HBit(28) /* AVX 1.0 instructions */ |
124 | #define CPUID_FEATURE_F16C _HBit(29) /* Float16 convert instructions */ | |
125 | #define CPUID_FEATURE_RDRAND _HBit(30) /* RDRAND instruction */ | |
fe8ab488 | 126 | #define CPUID_FEATURE_VMM _HBit(31) /* VMM (Hypervisor) present */ |
7ddcb079 A |
127 | |
128 | /* | |
129 | * Leaf 7, subleaf 0 additional features. | |
a1c7dba1 | 130 | * Bits returned in %ebx:%ecx to a CPUID request with {%eax,%ecx} of (0x7,0x0}: |
7ddcb079 | 131 | */ |
cb323159 A |
132 | #define CPUID_LEAF7_FEATURE_RDWRFSGS _Bit(0) /* FS/GS base read/write */ |
133 | #define CPUID_LEAF7_FEATURE_TSCOFF _Bit(1) /* TSC thread offset */ | |
134 | #define CPUID_LEAF7_FEATURE_SGX _Bit(2) /* Software Guard eXtensions */ | |
135 | #define CPUID_LEAF7_FEATURE_BMI1 _Bit(3) /* Bit Manipulation Instrs, set 1 */ | |
136 | #define CPUID_LEAF7_FEATURE_HLE _Bit(4) /* Hardware Lock Elision*/ | |
137 | #define CPUID_LEAF7_FEATURE_AVX2 _Bit(5) /* AVX2 Instructions */ | |
138 | #define CPUID_LEAF7_FEATURE_FDPEO _Bit(6) /* x87 FPU Data Pointer updated only on x87 exceptions */ | |
139 | #define CPUID_LEAF7_FEATURE_SMEP _Bit(7) /* Supervisor Mode Execute Protect */ | |
140 | #define CPUID_LEAF7_FEATURE_BMI2 _Bit(8) /* Bit Manipulation Instrs, set 2 */ | |
141 | #define CPUID_LEAF7_FEATURE_ERMS _Bit(9) /* Enhanced Rep Movsb/Stosb */ | |
142 | #define CPUID_LEAF7_FEATURE_INVPCID _Bit(10) /* INVPCID intruction, TDB */ | |
143 | #define CPUID_LEAF7_FEATURE_RTM _Bit(11) /* RTM */ | |
144 | #define CPUID_LEAF7_FEATURE_PQM _Bit(12) /* Platform Qos Monitoring */ | |
145 | #define CPUID_LEAF7_FEATURE_FPU_CSDS _Bit(13) /* FPU CS/DS deprecation */ | |
146 | #define CPUID_LEAF7_FEATURE_MPX _Bit(14) /* Memory Protection eXtensions */ | |
147 | #define CPUID_LEAF7_FEATURE_PQE _Bit(15) /* Platform Qos Enforcement */ | |
148 | #define CPUID_LEAF7_FEATURE_AVX512F _Bit(16) /* AVX512F instructions */ | |
149 | #define CPUID_LEAF7_FEATURE_AVX512DQ _Bit(17) /* AVX512DQ instructions */ | |
150 | #define CPUID_LEAF7_FEATURE_RDSEED _Bit(18) /* RDSEED Instruction */ | |
151 | #define CPUID_LEAF7_FEATURE_ADX _Bit(19) /* ADX Instructions */ | |
152 | #define CPUID_LEAF7_FEATURE_SMAP _Bit(20) /* Supervisor Mode Access Protect */ | |
153 | #define CPUID_LEAF7_FEATURE_AVX512IFMA _Bit(21) /* AVX512IFMA instructions */ | |
154 | #define CPUID_LEAF7_FEATURE_CLFSOPT _Bit(23) /* CLFSOPT */ | |
155 | #define CPUID_LEAF7_FEATURE_CLWB _Bit(24) /* CLWB */ | |
156 | #define CPUID_LEAF7_FEATURE_IPT _Bit(25) /* Intel Processor Trace */ | |
157 | #define CPUID_LEAF7_FEATURE_AVX512CD _Bit(28) /* AVX512CD instructions */ | |
158 | #define CPUID_LEAF7_FEATURE_SHA _Bit(29) /* SHA instructions */ | |
159 | #define CPUID_LEAF7_FEATURE_AVX512BW _Bit(30) /* AVX512BW instructions */ | |
160 | #define CPUID_LEAF7_FEATURE_AVX512VL _Bit(31) /* AVX512VL instructions */ | |
2dced7af | 161 | |
cb323159 A |
162 | #define CPUID_LEAF7_FEATURE_PREFETCHWT1 _HBit(0) /* Prefetch Write/T1 hint */ |
163 | #define CPUID_LEAF7_FEATURE_AVX512VBMI _HBit(1) /* AVX512VBMI instructions */ | |
164 | #define CPUID_LEAF7_FEATURE_UMIP _HBit(2) /* User Mode Instruction Prevention */ | |
165 | #define CPUID_LEAF7_FEATURE_PKU _HBit(3) /* Protection Keys for Usermode */ | |
166 | #define CPUID_LEAF7_FEATURE_OSPKE _HBit(4) /* OS has enabled PKE */ | |
167 | #define CPUID_LEAF7_FEATURE_WAITPKG _HBit(5) /* WAITPKG instructions */ | |
168 | #define CPUID_LEAF7_FEATURE_GFNI _HBit(8) /* Galois Field New Instructions */ | |
169 | #define CPUID_LEAF7_FEATURE_VAES _HBit(9) /* Vector-encoded AES */ | |
170 | #define CPUID_LEAF7_FEATURE_VPCLMULQDQ _HBit(10) /* Vector Carryless-multiply */ | |
171 | #define CPUID_LEAF7_FEATURE_AVX512VNNI _HBit(11) /* AVX512 Vector Neural Net Instructions */ | |
172 | #define CPUID_LEAF7_FEATURE_AVX512BITALG _HBit(12) /* AVX512 VPOPCNT{B,W} and VPSHUFBITQMB */ | |
173 | #define CPUID_LEAF7_FEATURE_AVX512VPCDQ _HBit(14) /* AVX512 VPOPCNTDQ instruction */ | |
174 | #define CPUID_LEAF7_FEATURE_RDPID _HBit(22) /* RDPID and IA32_TSC_AUX */ | |
175 | #define CPUID_LEAF7_FEATURE_CLDEMOTE _HBit(25) /* Cache line demote */ | |
176 | #define CPUID_LEAF7_FEATURE_MOVDIRI _HBit(27) /* MOVDIRI instruction */ | |
177 | #define CPUID_LEAF7_FEATURE_MOVDIRI64B _HBit(28) /* MOVDIRI64B instruction */ | |
178 | #define CPUID_LEAF7_FEATURE_SGXLC _HBit(30) /* SGX Launch Configuration */ | |
0a7de745 A |
179 | |
180 | /* | |
181 | * Values in EDX returned by CPUID Leaf 7, subleaf 0 | |
182 | */ | |
183 | #define CPUID_LEAF7_EXTFEATURE_AVX5124VNNIW _Bit(2) /* AVX512_4VNNIW */ | |
184 | #define CPUID_LEAF7_EXTFEATURE_AVX5124FMAPS _Bit(3) /* AVX512_4FMAPS */ | |
cb323159 | 185 | #define CPUID_LEAF7_EXTFEATURE_FSREPMOV _Bit(4) /* Fast Short REP MOV */ |
0a7de745 A |
186 | #define CPUID_LEAF7_EXTFEATURE_MDCLEAR _Bit(10) /* Overloaded VERW / L1D_FLUSH */ |
187 | #define CPUID_LEAF7_EXTFEATURE_TSXFA _Bit(13) /* TSX RTM_FORCE_ABORT MSR */ | |
188 | #define CPUID_LEAF7_EXTFEATURE_IBRS _Bit(26) /* IBRS / IBPB */ | |
189 | #define CPUID_LEAF7_EXTFEATURE_STIBP _Bit(27) /* Single Thread Indirect Branch Predictors */ | |
190 | #define CPUID_LEAF7_EXTFEATURE_L1DF _Bit(28) /* L1D_FLUSH MSR */ | |
191 | #define CPUID_LEAF7_EXTFEATURE_ACAPMSR _Bit(29) /* ARCH_CAP MSR */ | |
192 | #define CPUID_LEAF7_EXTFEATURE_CCAPMSR _Bit(30) /* CORE_CAP MSR */ | |
193 | #define CPUID_LEAF7_EXTFEATURE_SSBD _Bit(31) /* Speculative Store Bypass Disable */ | |
0c530ab8 A |
194 | |
195 | /* | |
196 | * The CPUID_EXTFEATURE_XXX values define 64-bit values | |
0a7de745 | 197 | * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001: |
0c530ab8 | 198 | */ |
0a7de745 A |
199 | #define CPUID_EXTFEATURE_SYSCALL _Bit(11) /* SYSCALL/sysret */ |
200 | #define CPUID_EXTFEATURE_XD _Bit(20) /* eXecute Disable */ | |
b7266188 | 201 | |
0a7de745 A |
202 | #define CPUID_EXTFEATURE_1GBPAGE _Bit(26) /* 1GB pages */ |
203 | #define CPUID_EXTFEATURE_RDTSCP _Bit(27) /* RDTSCP */ | |
204 | #define CPUID_EXTFEATURE_EM64T _Bit(29) /* Extended Mem 64 Technology */ | |
0c530ab8 | 205 | |
0a7de745 A |
206 | #define CPUID_EXTFEATURE_LAHF _HBit(0) /* LAFH/SAHF instructions */ |
207 | #define CPUID_EXTFEATURE_LZCNT _HBit(5) /* LZCNT instruction */ | |
208 | #define CPUID_EXTFEATURE_PREFETCHW _HBit(8) /* PREFETCHW instruction */ | |
0c530ab8 | 209 | |
c910b4d9 A |
210 | /* |
211 | * The CPUID_EXTFEATURE_XXX values define 64-bit values | |
0a7de745 | 212 | * returned in %ecx:%edx to a CPUID request with %eax of 0x80000007: |
c910b4d9 | 213 | */ |
0a7de745 | 214 | #define CPUID_EXTFEATURE_TSCI _Bit(8) /* TSC Invariant */ |
c910b4d9 | 215 | |
fe8ab488 A |
216 | /* |
217 | * CPUID_X86_64_H_FEATURE_SUBSET and CPUID_X86_64_H_LEAF7_FEATURE_SUBSET | |
218 | * indicate the bitmask of features that must be present before the system | |
219 | * is eligible to run the "x86_64h" "Haswell feature subset" slice. | |
220 | */ | |
221 | #define CPUID_X86_64_H_FEATURE_SUBSET ( CPUID_FEATURE_FMA | \ | |
0a7de745 A |
222 | CPUID_FEATURE_SSE4_2 | \ |
223 | CPUID_FEATURE_MOVBE | \ | |
224 | CPUID_FEATURE_POPCNT | \ | |
225 | CPUID_FEATURE_AVX1_0 \ | |
226 | ) | |
fe8ab488 A |
227 | |
228 | #define CPUID_X86_64_H_EXTFEATURE_SUBSET ( CPUID_EXTFEATURE_LZCNT \ | |
0a7de745 | 229 | ) |
fe8ab488 A |
230 | |
231 | #define CPUID_X86_64_H_LEAF7_FEATURE_SUBSET ( CPUID_LEAF7_FEATURE_BMI1 | \ | |
0a7de745 A |
232 | CPUID_LEAF7_FEATURE_AVX2 | \ |
233 | CPUID_LEAF7_FEATURE_BMI2 \ | |
234 | ) | |
235 | ||
236 | #define CPUID_CACHE_SIZE 16 /* Number of descriptor values */ | |
237 | ||
238 | #define CPUID_MWAIT_EXTENSION _Bit(0) /* enumeration of WMAIT extensions */ | |
239 | #define CPUID_MWAIT_BREAK _Bit(1) /* interrupts are break events */ | |
240 | ||
241 | #define CPUID_MODEL_PENRYN 0x17 | |
242 | #define CPUID_MODEL_NEHALEM 0x1A | |
243 | #define CPUID_MODEL_FIELDS 0x1E /* Lynnfield, Clarksfield */ | |
244 | #define CPUID_MODEL_DALES 0x1F /* Havendale, Auburndale */ | |
245 | #define CPUID_MODEL_NEHALEM_EX 0x2E | |
246 | #define CPUID_MODEL_DALES_32NM 0x25 /* Clarkdale, Arrandale */ | |
247 | #define CPUID_MODEL_WESTMERE 0x2C /* Gulftown, Westmere-EP/-WS */ | |
248 | #define CPUID_MODEL_WESTMERE_EX 0x2F | |
249 | #define CPUID_MODEL_SANDYBRIDGE 0x2A | |
250 | #define CPUID_MODEL_JAKETOWN 0x2D | |
251 | #define CPUID_MODEL_IVYBRIDGE 0x3A | |
252 | #define CPUID_MODEL_IVYBRIDGE_EP 0x3E | |
253 | #define CPUID_MODEL_CRYSTALWELL 0x46 | |
254 | #define CPUID_MODEL_HASWELL 0x3C | |
255 | #define CPUID_MODEL_HASWELL_EP 0x3F | |
256 | #define CPUID_MODEL_HASWELL_ULT 0x45 | |
257 | #define CPUID_MODEL_BROADWELL 0x3D | |
258 | #define CPUID_MODEL_BROADWELL_ULX 0x3D | |
259 | #define CPUID_MODEL_BROADWELL_ULT 0x3D | |
260 | #define CPUID_MODEL_BRYSTALWELL 0x47 | |
261 | #define CPUID_MODEL_SKYLAKE 0x4E | |
262 | #define CPUID_MODEL_SKYLAKE_ULT 0x4E | |
263 | #define CPUID_MODEL_SKYLAKE_ULX 0x4E | |
264 | #define CPUID_MODEL_SKYLAKE_DT 0x5E | |
0a7de745 A |
265 | #define CPUID_MODEL_SKYLAKE_W 0x55 |
266 | #define PLATID_XEON_SP_1 0x00 | |
267 | #define PLATID_XEON_SP_2 0x07 | |
268 | #define PLATID_MAYBE_XEON_SP 0x01 | |
5ba3f43e A |
269 | #define CPUID_MODEL_KABYLAKE 0x8E |
270 | #define CPUID_MODEL_KABYLAKE_ULT 0x8E | |
271 | #define CPUID_MODEL_KABYLAKE_ULX 0x8E | |
272 | #define CPUID_MODEL_KABYLAKE_DT 0x9E | |
7ddcb079 | 273 | |
0a7de745 A |
274 | #define CPUID_VMM_FAMILY_UNKNOWN 0x0 |
275 | #define CPUID_VMM_FAMILY_VMWARE 0x1 | |
276 | #define CPUID_VMM_FAMILY_PARALLELS 0x2 | |
316670eb | 277 | |
1c79356b | 278 | #ifndef ASSEMBLER |
55e303ae A |
279 | #include <stdint.h> |
280 | #include <mach/mach_types.h> | |
281 | #include <kern/kern_types.h> | |
1c79356b A |
282 | #include <mach/machine.h> |
283 | ||
1c79356b | 284 | |
0c530ab8 A |
285 | typedef enum { eax, ebx, ecx, edx } cpuid_register_t; |
286 | static inline void | |
287 | cpuid(uint32_t *data) | |
288 | { | |
fe8ab488 | 289 | __asm__ volatile ("cpuid" |
0a7de745 A |
290 | : "=a" (data[eax]), |
291 | "=b" (data[ebx]), | |
292 | "=c" (data[ecx]), | |
293 | "=d" (data[edx]) | |
294 | : "a" (data[eax]), | |
295 | "b" (data[ebx]), | |
296 | "c" (data[ecx]), | |
297 | "d" (data[edx])); | |
0c530ab8 | 298 | } |
060df5ea | 299 | |
55e303ae A |
300 | static inline void |
301 | do_cpuid(uint32_t selector, uint32_t *data) | |
302 | { | |
fe8ab488 | 303 | __asm__ volatile ("cpuid" |
0a7de745 A |
304 | : "=a" (data[0]), |
305 | "=b" (data[1]), | |
306 | "=c" (data[2]), | |
307 | "=d" (data[3]) | |
308 | : "a"(selector), | |
309 | "b" (0), | |
310 | "c" (0), | |
311 | "d" (0)); | |
55e303ae | 312 | } |
1c79356b A |
313 | |
314 | /* | |
2d21ac55 A |
315 | * Cache ID descriptor structure, used to parse CPUID leaf 2. |
316 | * Note: not used in kernel. | |
1c79356b | 317 | */ |
0a7de745 | 318 | typedef enum { Lnone, L1I, L1D, L2U, L3U, LCACHE_MAX } cache_type_t; |
55e303ae | 319 | typedef struct { |
0a7de745 A |
320 | unsigned char value; /* Descriptor value */ |
321 | cache_type_t type; /* Cache type */ | |
322 | unsigned int size; /* Cache size */ | |
323 | unsigned int linesize; /* Cache line size */ | |
55e303ae | 324 | #ifdef KERNEL |
0a7de745 | 325 | const char *description; /* Cache description */ |
55e303ae | 326 | #endif /* KERNEL */ |
0a7de745 | 327 | } cpuid_cache_desc_t; |
55e303ae A |
328 | |
329 | #ifdef KERNEL | |
0a7de745 | 330 | #define CACHE_DESC(value, type, size, linesize, text) \ |
55e303ae A |
331 | { value, type, size, linesize, text } |
332 | #else | |
0a7de745 | 333 | #define CACHE_DESC(value, type, size, linesize, text) \ |
55e303ae A |
334 | { value, type, size, linesize } |
335 | #endif /* KERNEL */ | |
336 | ||
7e4a7d39 A |
337 | /* Monitor/mwait Leaf: */ |
338 | typedef struct { | |
0a7de745 A |
339 | uint32_t linesize_min; |
340 | uint32_t linesize_max; | |
341 | uint32_t extensions; | |
342 | uint32_t sub_Cstates; | |
7e4a7d39 A |
343 | } cpuid_mwait_leaf_t; |
344 | ||
345 | /* Thermal and Power Management Leaf: */ | |
346 | typedef struct { | |
0a7de745 A |
347 | boolean_t sensor; |
348 | boolean_t dynamic_acceleration; | |
349 | boolean_t invariant_APIC_timer; | |
350 | boolean_t core_power_limits; | |
351 | boolean_t fine_grain_clock_mod; | |
352 | boolean_t package_thermal_intr; | |
353 | uint32_t thresholds; | |
354 | boolean_t ACNT_MCNT; | |
355 | boolean_t hardware_feedback; | |
356 | boolean_t energy_policy; | |
7e4a7d39 A |
357 | } cpuid_thermal_leaf_t; |
358 | ||
060df5ea A |
359 | |
360 | /* XSAVE Feature Leaf: */ | |
361 | typedef struct { | |
0a7de745 | 362 | uint32_t extended_state[4]; /* eax .. edx */ |
060df5ea A |
363 | } cpuid_xsave_leaf_t; |
364 | ||
365 | ||
7e4a7d39 A |
366 | /* Architectural Performance Monitoring Leaf: */ |
367 | typedef struct { | |
0a7de745 A |
368 | uint8_t version; |
369 | uint8_t number; | |
370 | uint8_t width; | |
371 | uint8_t events_number; | |
372 | uint32_t events; | |
373 | uint8_t fixed_number; | |
374 | uint8_t fixed_width; | |
7e4a7d39 A |
375 | } cpuid_arch_perf_leaf_t; |
376 | ||
2dced7af A |
377 | /* The TSC to Core Crystal (RefCLK) Clock Information leaf */ |
378 | typedef struct { | |
0a7de745 A |
379 | uint32_t numerator; |
380 | uint32_t denominator; | |
2dced7af A |
381 | } cpuid_tsc_leaf_t; |
382 | ||
0c530ab8 | 383 | /* Physical CPU info - this is exported out of the kernel (kexts), so be wary of changes */ |
55e303ae | 384 | typedef struct { |
0a7de745 A |
385 | char cpuid_vendor[16]; |
386 | char cpuid_brand_string[48]; | |
387 | const char *cpuid_model_string; | |
388 | ||
389 | cpu_type_t cpuid_type; /* this is *not* a cpu_type_t in our <mach/machine.h> */ | |
390 | uint8_t cpuid_family; | |
391 | uint8_t cpuid_model; | |
392 | uint8_t cpuid_extmodel; | |
393 | uint8_t cpuid_extfamily; | |
394 | uint8_t cpuid_stepping; | |
395 | uint64_t cpuid_features; | |
396 | uint64_t cpuid_extfeatures; | |
397 | uint32_t cpuid_signature; | |
398 | uint8_t cpuid_brand; | |
399 | uint8_t cpuid_processor_flag; | |
400 | ||
401 | uint32_t cache_size[LCACHE_MAX]; | |
402 | uint32_t cache_linesize; | |
403 | ||
404 | uint8_t cache_info[64]; /* list of cache descriptors */ | |
405 | ||
406 | uint32_t cpuid_cores_per_package; | |
407 | uint32_t cpuid_logical_per_package; | |
408 | uint32_t cache_sharing[LCACHE_MAX]; | |
409 | uint32_t cache_partitions[LCACHE_MAX]; | |
410 | ||
411 | cpu_type_t cpuid_cpu_type; /* <mach/machine.h> */ | |
412 | cpu_subtype_t cpuid_cpu_subtype; /* <mach/machine.h> */ | |
2d21ac55 | 413 | |
7e4a7d39 | 414 | /* Per-vendor info */ |
0a7de745 A |
415 | cpuid_mwait_leaf_t cpuid_mwait_leaf; |
416 | #define cpuid_mwait_linesize_max cpuid_mwait_leaf.linesize_max | |
417 | #define cpuid_mwait_linesize_min cpuid_mwait_leaf.linesize_min | |
418 | #define cpuid_mwait_extensions cpuid_mwait_leaf.extensions | |
419 | #define cpuid_mwait_sub_Cstates cpuid_mwait_leaf.sub_Cstates | |
420 | cpuid_thermal_leaf_t cpuid_thermal_leaf; | |
421 | cpuid_arch_perf_leaf_t cpuid_arch_perf_leaf; | |
422 | uint32_t unused[4]; /* cpuid_xsave_leaf */ | |
7e4a7d39 | 423 | |
2d21ac55 | 424 | /* Cache details: */ |
0a7de745 A |
425 | uint32_t cpuid_cache_linesize; |
426 | uint32_t cpuid_cache_L2_associativity; | |
427 | uint32_t cpuid_cache_size; | |
2d21ac55 A |
428 | |
429 | /* Virtual and physical address aize: */ | |
0a7de745 A |
430 | uint32_t cpuid_address_bits_physical; |
431 | uint32_t cpuid_address_bits_virtual; | |
593a1d5f | 432 | |
0a7de745 | 433 | uint32_t cpuid_microcode_version; |
593a1d5f | 434 | |
b0d623f7 | 435 | /* Numbers of tlbs per processor [i|d, small|large, level0|level1] */ |
0a7de745 A |
436 | uint32_t cpuid_tlb[2][2][2]; |
437 | #define TLB_INST 0 | |
438 | #define TLB_DATA 1 | |
439 | #define TLB_SMALL 0 | |
440 | #define TLB_LARGE 1 | |
441 | uint32_t cpuid_stlb; | |
593a1d5f | 442 | |
0a7de745 A |
443 | uint32_t core_count; |
444 | uint32_t thread_count; | |
593a1d5f | 445 | |
b0d623f7 | 446 | /* Max leaf ids available from CPUID */ |
0a7de745 A |
447 | uint32_t cpuid_max_basic; |
448 | uint32_t cpuid_max_ext; | |
7e4a7d39 A |
449 | |
450 | /* Family-specific info links */ | |
0a7de745 A |
451 | uint32_t cpuid_cpufamily; |
452 | cpuid_mwait_leaf_t *cpuid_mwait_leafp; | |
453 | cpuid_thermal_leaf_t *cpuid_thermal_leafp; | |
454 | cpuid_arch_perf_leaf_t *cpuid_arch_perf_leafp; | |
455 | cpuid_xsave_leaf_t *cpuid_xsave_leafp; | |
456 | uint64_t cpuid_leaf7_features; | |
457 | uint64_t cpuid_leaf7_extfeatures; | |
458 | cpuid_tsc_leaf_t cpuid_tsc_leaf; | |
459 | cpuid_xsave_leaf_t cpuid_xsave_leaf[2]; | |
55e303ae | 460 | } i386_cpu_info_t; |
1c79356b | 461 | |
0a7de745 A |
462 | #if defined(MACH_KERNEL_PRIVATE) && !defined(ASSEMBLER) |
463 | /* Only for 32bit values */ | |
464 | #define bit32(n) (1U << (n)) | |
465 | #define bitmask32(h, l) ((bit32(h)|(bit32(h)-1)) & ~(bit32(l)-1)) | |
466 | #define bitfield32(x, h, l) ((((x) & bitmask32(h,l)) >> l)) | |
467 | ||
316670eb | 468 | typedef struct { |
0a7de745 A |
469 | char cpuid_vmm_vendor[16]; |
470 | uint32_t cpuid_vmm_family; | |
471 | uint32_t cpuid_vmm_bus_frequency; | |
472 | uint32_t cpuid_vmm_tsc_frequency; | |
316670eb | 473 | } i386_vmm_info_t; |
0a7de745 A |
474 | |
475 | typedef enum { | |
476 | CPU_INTEL_SEGCHK = 1, | |
94ff46dc | 477 | CPU_INTEL_TSXFA = 2 |
0a7de745 A |
478 | } cpu_wa_e; |
479 | ||
480 | typedef enum { | |
481 | CWA_ON = 2, | |
482 | CWA_FORCE_ON = 3, /* FORCE_ON shares bit 1 so consumers can test that for ON */ | |
483 | CWA_OFF = 4, | |
484 | CWA_FORCE_OFF = 5 /* Similarly for FORCE_OFF sharing bit 2 */ | |
485 | } cwa_classifier_e; | |
486 | ||
487 | static inline int | |
488 | is_xeon_sp(uint8_t platid) | |
489 | { | |
490 | if (platid == PLATID_XEON_SP_1 || platid == PLATID_XEON_SP_2) { | |
491 | return 1; | |
492 | } | |
493 | if (platid != PLATID_MAYBE_XEON_SP) { | |
494 | return 0; | |
495 | } | |
496 | boolean_t intrs = ml_set_interrupts_enabled(FALSE); | |
497 | outl(cfgAdr, XeonCapID5); | |
498 | uint32_t cap5reg = inl(cfgDat); | |
499 | ml_set_interrupts_enabled(intrs); | |
500 | /* Read from PCI config space 1:30:3:0x98 [bits 13:9] */ | |
501 | if (bitfield32(cap5reg, 13, 9) == 3) { | |
502 | return 1; | |
503 | } | |
504 | return 0; | |
505 | } | |
506 | ||
507 | extern int force_tecs_at_idle; | |
508 | ||
509 | #endif /* defined(MACH_KERNEL_PRIVATE) && !defined(ASSEMBLER) */ | |
316670eb | 510 | |
91447636 A |
511 | #ifdef __cplusplus |
512 | extern "C" { | |
513 | #endif | |
1c79356b A |
514 | |
515 | /* | |
516 | * External declarations | |
517 | */ | |
0a7de745 A |
518 | extern cpu_type_t cpuid_cputype(void); |
519 | extern cpu_subtype_t cpuid_cpusubtype(void); | |
520 | extern void cpuid_cpu_display(const char *); | |
521 | extern void cpuid_feature_display(const char *); | |
522 | extern void cpuid_extfeature_display(const char *); | |
523 | extern char * cpuid_get_feature_names(uint64_t, char *, unsigned); | |
524 | extern char * cpuid_get_extfeature_names(uint64_t, char *, unsigned); | |
525 | extern char * cpuid_get_leaf7_feature_names(uint64_t, char *, unsigned); | |
526 | extern char * cpuid_get_leaf7_extfeature_names(uint64_t, char *, unsigned); | |
527 | ||
528 | extern uint64_t cpuid_features(void); | |
529 | extern uint64_t cpuid_extfeatures(void); | |
530 | extern uint64_t cpuid_leaf7_features(void); | |
531 | extern uint64_t cpuid_leaf7_extfeatures(void); | |
532 | extern uint32_t cpuid_family(void); | |
533 | extern uint32_t cpuid_cpufamily(void); | |
534 | ||
535 | extern i386_cpu_info_t *cpuid_info(void); | |
536 | extern void cpuid_set_info(void); | |
1c79356b | 537 | |
316670eb | 538 | #ifdef MACH_KERNEL_PRIVATE |
0a7de745 A |
539 | extern boolean_t cpuid_vmm_present(void); |
540 | extern i386_vmm_info_t *cpuid_vmm_info(void); | |
541 | extern uint32_t cpuid_vmm_family(void); | |
542 | extern cwa_classifier_e cpuid_wa_required(cpu_wa_e wa); | |
543 | extern void cpuid_do_was(void); | |
316670eb A |
544 | #endif |
545 | ||
91447636 A |
546 | #ifdef __cplusplus |
547 | } | |
548 | #endif | |
55e303ae | 549 | |
1c79356b | 550 | #endif /* ASSEMBLER */ |
55e303ae A |
551 | |
552 | #endif /* __APPLE_API_PRIVATE */ | |
1c79356b | 553 | #endif /* _MACHINE_CPUID_H_ */ |