]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cpuid.h
xnu-2050.22.13.tar.gz
[apple/xnu.git] / osfmk / i386 / cpuid.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 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.
8f6c56a5 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.
17 *
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.
8f6c56a5 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
42#ifdef __APPLE_API_PRIVATE
43
1c79356b 44#define CPUID_VID_INTEL "GenuineIntel"
1c79356b 45#define CPUID_VID_AMD "AuthenticAMD"
91447636 46
316670eb
A
47#define CPUID_VMM_ID_VMWARE "VMwareVMware"
48
91447636 49#define CPUID_STRING_UNKNOWN "Unknown CPU Typ"
1c79356b 50
0c530ab8
A
51#define _Bit(n) (1ULL << n)
52#define _HBit(n) (1ULL << ((n)+32))
53
54/*
55 * The CPUID_FEATURE_XXX values define 64-bit values
56 * returned in %ecx:%edx to a CPUID request with %eax of 1:
57 */
060df5ea
A
58#define CPUID_FEATURE_FPU _Bit(0) /* Floating point unit on-chip */
59#define CPUID_FEATURE_VME _Bit(1) /* Virtual Mode Extension */
60#define CPUID_FEATURE_DE _Bit(2) /* Debugging Extension */
61#define CPUID_FEATURE_PSE _Bit(3) /* Page Size Extension */
62#define CPUID_FEATURE_TSC _Bit(4) /* Time Stamp Counter */
63#define CPUID_FEATURE_MSR _Bit(5) /* Model Specific Registers */
64#define CPUID_FEATURE_PAE _Bit(6) /* Physical Address Extension */
65#define CPUID_FEATURE_MCE _Bit(7) /* Machine Check Exception */
66#define CPUID_FEATURE_CX8 _Bit(8) /* CMPXCHG8B */
67#define CPUID_FEATURE_APIC _Bit(9) /* On-chip APIC */
68#define CPUID_FEATURE_SEP _Bit(11) /* Fast System Call */
69#define CPUID_FEATURE_MTRR _Bit(12) /* Memory Type Range Register */
70#define CPUID_FEATURE_PGE _Bit(13) /* Page Global Enable */
71#define CPUID_FEATURE_MCA _Bit(14) /* Machine Check Architecture */
72#define CPUID_FEATURE_CMOV _Bit(15) /* Conditional Move Instruction */
73#define CPUID_FEATURE_PAT _Bit(16) /* Page Attribute Table */
74#define CPUID_FEATURE_PSE36 _Bit(17) /* 36-bit Page Size Extension */
75#define CPUID_FEATURE_PSN _Bit(18) /* Processor Serial Number */
76#define CPUID_FEATURE_CLFSH _Bit(19) /* CLFLUSH Instruction supported */
77#define CPUID_FEATURE_DS _Bit(21) /* Debug Store */
78#define CPUID_FEATURE_ACPI _Bit(22) /* Thermal monitor and Clock Ctrl */
79#define CPUID_FEATURE_MMX _Bit(23) /* MMX supported */
80#define CPUID_FEATURE_FXSR _Bit(24) /* Fast floating pt save/restore */
81#define CPUID_FEATURE_SSE _Bit(25) /* Streaming SIMD extensions */
82#define CPUID_FEATURE_SSE2 _Bit(26) /* Streaming SIMD extensions 2 */
83#define CPUID_FEATURE_SS _Bit(27) /* Self-Snoop */
84#define CPUID_FEATURE_HTT _Bit(28) /* Hyper-Threading Technology */
85#define CPUID_FEATURE_TM _Bit(29) /* Thermal Monitor (TM1) */
86#define CPUID_FEATURE_PBE _Bit(31) /* Pend Break Enable */
87
88#define CPUID_FEATURE_SSE3 _HBit(0) /* Streaming SIMD extensions 3 */
89#define CPUID_FEATURE_PCLMULQDQ _HBit(1) /* PCLMULQDQ instruction */
90#define CPUID_FEATURE_DTES64 _HBit(2) /* 64-bit DS layout */
91#define CPUID_FEATURE_MONITOR _HBit(3) /* Monitor/mwait */
92#define CPUID_FEATURE_DSCPL _HBit(4) /* Debug Store CPL */
93#define CPUID_FEATURE_VMX _HBit(5) /* VMX */
94#define CPUID_FEATURE_SMX _HBit(6) /* SMX */
95#define CPUID_FEATURE_EST _HBit(7) /* Enhanced SpeedsTep (GV3) */
96#define CPUID_FEATURE_TM2 _HBit(8) /* Thermal Monitor 2 */
97#define CPUID_FEATURE_SSSE3 _HBit(9) /* Supplemental SSE3 instructions */
98#define CPUID_FEATURE_CID _HBit(10) /* L1 Context ID */
7ddcb079 99#define CPUID_FEATURE_SEGLIM64 _HBit(11) /* 64-bit segment limit checking */
060df5ea
A
100#define CPUID_FEATURE_CX16 _HBit(13) /* CmpXchg16b instruction */
101#define CPUID_FEATURE_xTPR _HBit(14) /* Send Task PRiority msgs */
102#define CPUID_FEATURE_PDCM _HBit(15) /* Perf/Debug Capability MSR */
103
7ddcb079 104#define CPUID_FEATURE_PCID _HBit(17) /* ASID-PCID support */
060df5ea
A
105#define CPUID_FEATURE_DCA _HBit(18) /* Direct Cache Access */
106#define CPUID_FEATURE_SSE4_1 _HBit(19) /* Streaming SIMD extensions 4.1 */
107#define CPUID_FEATURE_SSE4_2 _HBit(20) /* Streaming SIMD extensions 4.2 */
108#define CPUID_FEATURE_xAPIC _HBit(21) /* Extended APIC Mode */
109#define CPUID_FEATURE_MOVBE _HBit(22) /* MOVBE instruction */
110#define CPUID_FEATURE_POPCNT _HBit(23) /* POPCNT instruction */
7ddcb079 111#define CPUID_FEATURE_TSCTMR _HBit(24) /* TSC deadline timer */
060df5ea
A
112#define CPUID_FEATURE_AES _HBit(25) /* AES instructions */
113#define CPUID_FEATURE_XSAVE _HBit(26) /* XSAVE instructions */
114#define CPUID_FEATURE_OSXSAVE _HBit(27) /* XGETBV/XSETBV instructions */
060df5ea 115#define CPUID_FEATURE_AVX1_0 _HBit(28) /* AVX 1.0 instructions */
7ddcb079 116#define CPUID_FEATURE_VMM _HBit(31) /* VMM (Hypervisor) present */
316670eb
A
117#define CPUID_FEATURE_SEGLIM64 _HBit(11) /* 64-bit segment limit checking */
118#define CPUID_FEATURE_PCID _HBit(17) /* ASID-PCID support */
119#define CPUID_FEATURE_TSCTMR _HBit(24) /* TSC deadline timer */
120#define CPUID_FEATURE_AVX1_0 _HBit(28) /* AVX 1.0 instructions */
121#define CPUID_FEATURE_F16C _HBit(29) /* Float16 convert instructions */
122#define CPUID_FEATURE_RDRAND _HBit(30) /* RDRAND instruction */
7ddcb079
A
123
124/*
125 * Leaf 7, subleaf 0 additional features.
126 * Bits returned in %ebx to a CPUID request with {%eax,%ecx} of (0x7,0x0}:
127 */
128#define CPUID_LEAF7_FEATURE_RDWRFSGS _Bit(0) /* FS/GS base read/write */
129#define CPUID_LEAF7_FEATURE_SMEP _Bit(7) /* Supervisor Mode Execute Protect */
130#define CPUID_LEAF7_FEATURE_ENFSTRG _Bit(9) /* ENhanced Fast STRinG copy */
0c530ab8
A
131
132/*
133 * The CPUID_EXTFEATURE_XXX values define 64-bit values
134 * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001:
135 */
136#define CPUID_EXTFEATURE_SYSCALL _Bit(11) /* SYSCALL/sysret */
137#define CPUID_EXTFEATURE_XD _Bit(20) /* eXecute Disable */
b7266188 138
060df5ea 139#define CPUID_EXTFEATURE_1GBPAGE _Bit(26) /* 1GB pages */
c910b4d9 140#define CPUID_EXTFEATURE_RDTSCP _Bit(27) /* RDTSCP */
0c530ab8
A
141#define CPUID_EXTFEATURE_EM64T _Bit(29) /* Extended Mem 64 Technology */
142
060df5ea 143#define CPUID_EXTFEATURE_LAHF _HBit(0) /* LAFH/SAHF instructions */
0c530ab8 144
c910b4d9
A
145/*
146 * The CPUID_EXTFEATURE_XXX values define 64-bit values
147 * returned in %ecx:%edx to a CPUID request with %eax of 0x80000007:
148 */
149#define CPUID_EXTFEATURE_TSCI _Bit(8) /* TSC Invariant */
150
b0d623f7 151#define CPUID_CACHE_SIZE 16 /* Number of descriptor values */
1c79356b 152
2d21ac55
A
153#define CPUID_MWAIT_EXTENSION _Bit(0) /* enumeration of WMAIT extensions */
154#define CPUID_MWAIT_BREAK _Bit(1) /* interrupts are break events */
155
060df5ea
A
156#define CPUID_MODEL_YONAH 0x0E
157#define CPUID_MODEL_MEROM 0x0F
158#define CPUID_MODEL_PENRYN 0x17
159#define CPUID_MODEL_NEHALEM 0x1A
160#define CPUID_MODEL_FIELDS 0x1E /* Lynnfield, Clarksfield, Jasper */
161#define CPUID_MODEL_DALES 0x1F /* Havendale, Auburndale */
162#define CPUID_MODEL_NEHALEM_EX 0x2E
163#define CPUID_MODEL_DALES_32NM 0x25 /* Clarkdale, Arrandale */
164#define CPUID_MODEL_WESTMERE 0x2C /* Gulftown, Westmere-EP, Westmere-WS */
165#define CPUID_MODEL_WESTMERE_EX 0x2F
060df5ea
A
166#define CPUID_MODEL_SANDYBRIDGE 0x2A
167#define CPUID_MODEL_JAKETOWN 0x2D
13f56ec4 168#define CPUID_MODEL_IVYBRIDGE 0x3A
593a1d5f 169
7ddcb079 170
316670eb
A
171#define CPUID_VMM_FAMILY_UNKNOWN 0x0
172#define CPUID_VMM_FAMILY_VMWARE 0x1
173
1c79356b 174#ifndef ASSEMBLER
55e303ae
A
175#include <stdint.h>
176#include <mach/mach_types.h>
177#include <kern/kern_types.h>
1c79356b
A
178#include <mach/machine.h>
179
1c79356b 180
0c530ab8
A
181typedef enum { eax, ebx, ecx, edx } cpuid_register_t;
182static inline void
183cpuid(uint32_t *data)
184{
185 asm("cpuid"
186 : "=a" (data[eax]),
187 "=b" (data[ebx]),
188 "=c" (data[ecx]),
189 "=d" (data[edx])
190 : "a" (data[eax]),
191 "b" (data[ebx]),
192 "c" (data[ecx]),
193 "d" (data[edx]));
194}
060df5ea 195
55e303ae
A
196static inline void
197do_cpuid(uint32_t selector, uint32_t *data)
198{
199 asm("cpuid"
200 : "=a" (data[0]),
201 "=b" (data[1]),
202 "=c" (data[2]),
203 "=d" (data[3])
060df5ea
A
204 : "a"(selector),
205 "b" (0),
206 "c" (0),
207 "d" (0));
55e303ae 208}
1c79356b
A
209
210/*
2d21ac55
A
211 * Cache ID descriptor structure, used to parse CPUID leaf 2.
212 * Note: not used in kernel.
1c79356b 213 */
91447636 214typedef enum { Lnone, L1I, L1D, L2U, L3U, LCACHE_MAX } cache_type_t ;
55e303ae
A
215typedef struct {
216 unsigned char value; /* Descriptor value */
217 cache_type_t type; /* Cache type */
218 unsigned int size; /* Cache size */
219 unsigned int linesize; /* Cache line size */
220#ifdef KERNEL
91447636 221 const char *description; /* Cache description */
55e303ae
A
222#endif /* KERNEL */
223} cpuid_cache_desc_t;
224
225#ifdef KERNEL
226#define CACHE_DESC(value,type,size,linesize,text) \
227 { value, type, size, linesize, text }
228#else
229#define CACHE_DESC(value,type,size,linesize,text) \
230 { value, type, size, linesize }
231#endif /* KERNEL */
232
7e4a7d39
A
233/* Monitor/mwait Leaf: */
234typedef struct {
235 uint32_t linesize_min;
236 uint32_t linesize_max;
237 uint32_t extensions;
238 uint32_t sub_Cstates;
239} cpuid_mwait_leaf_t;
240
241/* Thermal and Power Management Leaf: */
242typedef struct {
243 boolean_t sensor;
244 boolean_t dynamic_acceleration;
b7266188 245 boolean_t invariant_APIC_timer;
060df5ea
A
246 boolean_t core_power_limits;
247 boolean_t fine_grain_clock_mod;
248 boolean_t package_thermal_intr;
7e4a7d39
A
249 uint32_t thresholds;
250 boolean_t ACNT_MCNT;
060df5ea
A
251 boolean_t hardware_feedback;
252 boolean_t energy_policy;
7e4a7d39
A
253} cpuid_thermal_leaf_t;
254
060df5ea
A
255
256/* XSAVE Feature Leaf: */
257typedef struct {
258 uint32_t extended_state[4]; /* eax .. edx */
259} cpuid_xsave_leaf_t;
260
261
7e4a7d39
A
262/* Architectural Performance Monitoring Leaf: */
263typedef struct {
264 uint8_t version;
265 uint8_t number;
266 uint8_t width;
267 uint8_t events_number;
268 uint32_t events;
269 uint8_t fixed_number;
270 uint8_t fixed_width;
271} cpuid_arch_perf_leaf_t;
272
0c530ab8 273/* Physical CPU info - this is exported out of the kernel (kexts), so be wary of changes */
55e303ae
A
274typedef struct {
275 char cpuid_vendor[16];
276 char cpuid_brand_string[48];
91447636 277 const char *cpuid_model_string;
55e303ae 278
7e4a7d39 279 cpu_type_t cpuid_type; /* this is *not* a cpu_type_t in our <mach/machine.h> */
55e303ae
A
280 uint8_t cpuid_family;
281 uint8_t cpuid_model;
282 uint8_t cpuid_extmodel;
283 uint8_t cpuid_extfamily;
284 uint8_t cpuid_stepping;
0c530ab8
A
285 uint64_t cpuid_features;
286 uint64_t cpuid_extfeatures;
55e303ae
A
287 uint32_t cpuid_signature;
288 uint8_t cpuid_brand;
6d2010ae 289 uint8_t cpuid_processor_flag;
55e303ae
A
290
291 uint32_t cache_size[LCACHE_MAX];
292 uint32_t cache_linesize;
293
55e303ae
A
294 uint8_t cache_info[64]; /* list of cache descriptors */
295
0c530ab8
A
296 uint32_t cpuid_cores_per_package;
297 uint32_t cpuid_logical_per_package;
298 uint32_t cache_sharing[LCACHE_MAX];
2d21ac55 299 uint32_t cache_partitions[LCACHE_MAX];
0c530ab8 300
2d21ac55 301 cpu_type_t cpuid_cpu_type; /* <mach/machine.h> */
0c530ab8 302 cpu_subtype_t cpuid_cpu_subtype; /* <mach/machine.h> */
2d21ac55 303
7e4a7d39
A
304 /* Per-vendor info */
305 cpuid_mwait_leaf_t cpuid_mwait_leaf;
306#define cpuid_mwait_linesize_max cpuid_mwait_leaf.linesize_max
307#define cpuid_mwait_linesize_min cpuid_mwait_leaf.linesize_min
308#define cpuid_mwait_extensions cpuid_mwait_leaf.extensions
309#define cpuid_mwait_sub_Cstates cpuid_mwait_leaf.sub_Cstates
310 cpuid_thermal_leaf_t cpuid_thermal_leaf;
311 cpuid_arch_perf_leaf_t cpuid_arch_perf_leaf;
060df5ea 312 cpuid_xsave_leaf_t cpuid_xsave_leaf;
7e4a7d39 313
2d21ac55
A
314 /* Cache details: */
315 uint32_t cpuid_cache_linesize;
316 uint32_t cpuid_cache_L2_associativity;
317 uint32_t cpuid_cache_size;
318
319 /* Virtual and physical address aize: */
320 uint32_t cpuid_address_bits_physical;
321 uint32_t cpuid_address_bits_virtual;
593a1d5f
A
322
323 uint32_t cpuid_microcode_version;
324
b0d623f7
A
325 /* Numbers of tlbs per processor [i|d, small|large, level0|level1] */
326 uint32_t cpuid_tlb[2][2][2];
327 #define TLB_INST 0
328 #define TLB_DATA 1
329 #define TLB_SMALL 0
330 #define TLB_LARGE 1
331 uint32_t cpuid_stlb;
593a1d5f
A
332
333 uint32_t core_count;
334 uint32_t thread_count;
335
b0d623f7
A
336 /* Max leaf ids available from CPUID */
337 uint32_t cpuid_max_basic;
338 uint32_t cpuid_max_ext;
7e4a7d39
A
339
340 /* Family-specific info links */
341 uint32_t cpuid_cpufamily;
342 cpuid_mwait_leaf_t *cpuid_mwait_leafp;
343 cpuid_thermal_leaf_t *cpuid_thermal_leafp;
344 cpuid_arch_perf_leaf_t *cpuid_arch_perf_leafp;
060df5ea 345 cpuid_xsave_leaf_t *cpuid_xsave_leafp;
7ddcb079 346 uint32_t cpuid_leaf7_features;
55e303ae 347} i386_cpu_info_t;
1c79356b 348
316670eb
A
349#ifdef MACH_KERNEL_PRIVATE
350typedef struct {
351 char cpuid_vmm_vendor[16];
352 uint32_t cpuid_vmm_family;
353 uint32_t cpuid_vmm_bus_frequency;
354 uint32_t cpuid_vmm_tsc_frequency;
355} i386_vmm_info_t;
356#endif
357
91447636
A
358#ifdef __cplusplus
359extern "C" {
360#endif
1c79356b
A
361
362/*
363 * External declarations
364 */
0c530ab8
A
365extern cpu_type_t cpuid_cputype(void);
366extern cpu_subtype_t cpuid_cpusubtype(void);
367extern void cpuid_cpu_display(const char *);
368extern void cpuid_feature_display(const char *);
369extern void cpuid_extfeature_display(const char *);
370extern char * cpuid_get_feature_names(uint64_t, char *, unsigned);
371extern char * cpuid_get_extfeature_names(uint64_t, char *, unsigned);
7ddcb079 372extern char * cpuid_get_leaf7_feature_names(uint64_t, char *, unsigned);
0c530ab8
A
373
374extern uint64_t cpuid_features(void);
375extern uint64_t cpuid_extfeatures(void);
7ddcb079 376extern uint64_t cpuid_leaf7_features(void);
55e303ae 377extern uint32_t cpuid_family(void);
7e4a7d39 378extern uint32_t cpuid_cpufamily(void);
91447636
A
379
380extern void cpuid_get_info(i386_cpu_info_t *info_p);
381extern i386_cpu_info_t *cpuid_info(void);
55e303ae 382
0c530ab8 383extern void cpuid_set_info(void);
1c79356b 384
316670eb
A
385#ifdef MACH_KERNEL_PRIVATE
386extern boolean_t cpuid_vmm_present(void);
387extern i386_vmm_info_t *cpuid_vmm_info(void);
388extern uint32_t cpuid_vmm_family(void);
389#endif
390
91447636
A
391#ifdef __cplusplus
392}
393#endif
55e303ae 394
1c79356b 395#endif /* ASSEMBLER */
55e303ae
A
396
397#endif /* __APPLE_API_PRIVATE */
1c79356b 398#endif /* _MACHINE_CPUID_H_ */