]>
Commit | Line | Data |
---|---|---|
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 A |
46 | |
47 | #define CPUID_STRING_UNKNOWN "Unknown CPU Typ" | |
1c79356b | 48 | |
0c530ab8 A |
49 | #define _Bit(n) (1ULL << n) |
50 | #define _HBit(n) (1ULL << ((n)+32)) | |
51 | ||
52 | /* | |
53 | * The CPUID_FEATURE_XXX values define 64-bit values | |
54 | * returned in %ecx:%edx to a CPUID request with %eax of 1: | |
55 | */ | |
56 | #define CPUID_FEATURE_FPU _Bit(0) /* Floating point unit on-chip */ | |
57 | #define CPUID_FEATURE_VME _Bit(1) /* Virtual Mode Extension */ | |
58 | #define CPUID_FEATURE_DE _Bit(2) /* Debugging Extension */ | |
59 | #define CPUID_FEATURE_PSE _Bit(3) /* Page Size Extension */ | |
60 | #define CPUID_FEATURE_TSC _Bit(4) /* Time Stamp Counter */ | |
61 | #define CPUID_FEATURE_MSR _Bit(5) /* Model Specific Registers */ | |
62 | #define CPUID_FEATURE_PAE _Bit(6) /* Physical Address Extension */ | |
63 | #define CPUID_FEATURE_MCE _Bit(7) /* Machine Check Exception */ | |
64 | #define CPUID_FEATURE_CX8 _Bit(8) /* CMPXCHG8B */ | |
65 | #define CPUID_FEATURE_APIC _Bit(9) /* On-chip APIC */ | |
66 | #define CPUID_FEATURE_SEP _Bit(11) /* Fast System Call */ | |
67 | #define CPUID_FEATURE_MTRR _Bit(12) /* Memory Type Range Register */ | |
68 | #define CPUID_FEATURE_PGE _Bit(13) /* Page Global Enable */ | |
69 | #define CPUID_FEATURE_MCA _Bit(14) /* Machine Check Architecture */ | |
70 | #define CPUID_FEATURE_CMOV _Bit(15) /* Conditional Move Instruction */ | |
71 | #define CPUID_FEATURE_PAT _Bit(16) /* Page Attribute Table */ | |
72 | #define CPUID_FEATURE_PSE36 _Bit(17) /* 36-bit Page Size Extension */ | |
73 | #define CPUID_FEATURE_PSN _Bit(18) /* Processor Serial Number */ | |
74 | #define CPUID_FEATURE_CLFSH _Bit(19) /* CLFLUSH Instruction supported */ | |
75 | #define CPUID_FEATURE_DS _Bit(21) /* Debug Store */ | |
76 | #define CPUID_FEATURE_ACPI _Bit(22) /* Thermal monitor and Clock Ctrl */ | |
77 | #define CPUID_FEATURE_MMX _Bit(23) /* MMX supported */ | |
78 | #define CPUID_FEATURE_FXSR _Bit(24) /* Fast floating pt save/restore */ | |
79 | #define CPUID_FEATURE_SSE _Bit(25) /* Streaming SIMD extensions */ | |
80 | #define CPUID_FEATURE_SSE2 _Bit(26) /* Streaming SIMD extensions 2 */ | |
81 | #define CPUID_FEATURE_SS _Bit(27) /* Self-Snoop */ | |
82 | #define CPUID_FEATURE_HTT _Bit(28) /* Hyper-Threading Technology */ | |
83 | #define CPUID_FEATURE_TM _Bit(29) /* Thermal Monitor (TM1) */ | |
84 | #define CPUID_FEATURE_PBE _Bit(31) /* Pend Break Enable */ | |
85 | ||
2d21ac55 | 86 | #define CPUID_FEATURE_SSE3 _HBit(0) /* Streaming SIMD extensions 3 */ |
0c530ab8 A |
87 | #define CPUID_FEATURE_MONITOR _HBit(3) /* Monitor/mwait */ |
88 | #define CPUID_FEATURE_DSCPL _HBit(4) /* Debug Store CPL */ | |
89 | #define CPUID_FEATURE_VMX _HBit(5) /* VMX */ | |
90 | #define CPUID_FEATURE_SMX _HBit(6) /* SMX */ | |
91 | #define CPUID_FEATURE_EST _HBit(7) /* Enhanced SpeedsTep (GV3) */ | |
92 | #define CPUID_FEATURE_TM2 _HBit(8) /* Thermal Monitor 2 */ | |
93 | #define CPUID_FEATURE_SSSE3 _HBit(9) /* Supplemental SSE3 instructions */ | |
0c530ab8 A |
94 | #define CPUID_FEATURE_CID _HBit(10) /* L1 Context ID */ |
95 | #define CPUID_FEATURE_CX16 _HBit(13) /* CmpXchg16b instruction */ | |
96 | #define CPUID_FEATURE_xTPR _HBit(14) /* Send Task PRiority msgs */ | |
97 | #define CPUID_FEATURE_PDCM _HBit(15) /* Perf/Debug Capability MSR */ | |
593a1d5f | 98 | #define CPUID_FEATURE_DCA _HBit(18) /* Direct Cache Access */ |
0c530ab8 | 99 | #define CPUID_FEATURE_SSE4_1 _HBit(19) /* Streaming SIMD extensions 4.1 */ |
593a1d5f A |
100 | #define CPUID_FEATURE_SSE4_2 _HBit(20) /* Streaming SIMD extensions 4.2 */ |
101 | #define CPUID_FEATURE_xAPIC _HBit(21) /* Extended APIC Mode */ | |
0c530ab8 | 102 | #define CPUID_FEATURE_POPCNT _HBit(23) /* POPCNT instruction */ |
b0d623f7 | 103 | #define CPUID_FEATURE_VMM _HBit(31) /* VMM (Hypervisor) present */ |
0c530ab8 A |
104 | |
105 | /* | |
106 | * The CPUID_EXTFEATURE_XXX values define 64-bit values | |
107 | * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001: | |
108 | */ | |
109 | #define CPUID_EXTFEATURE_SYSCALL _Bit(11) /* SYSCALL/sysret */ | |
110 | #define CPUID_EXTFEATURE_XD _Bit(20) /* eXecute Disable */ | |
c910b4d9 | 111 | #define CPUID_EXTFEATURE_RDTSCP _Bit(27) /* RDTSCP */ |
0c530ab8 A |
112 | #define CPUID_EXTFEATURE_EM64T _Bit(29) /* Extended Mem 64 Technology */ |
113 | ||
114 | #define CPUID_EXTFEATURE_LAHF _HBit(20) /* LAFH/SAHF instructions */ | |
115 | ||
c910b4d9 A |
116 | /* |
117 | * The CPUID_EXTFEATURE_XXX values define 64-bit values | |
118 | * returned in %ecx:%edx to a CPUID request with %eax of 0x80000007: | |
119 | */ | |
120 | #define CPUID_EXTFEATURE_TSCI _Bit(8) /* TSC Invariant */ | |
121 | ||
b0d623f7 | 122 | #define CPUID_CACHE_SIZE 16 /* Number of descriptor values */ |
1c79356b | 123 | |
2d21ac55 A |
124 | #define CPUID_MWAIT_EXTENSION _Bit(0) /* enumeration of WMAIT extensions */ |
125 | #define CPUID_MWAIT_BREAK _Bit(1) /* interrupts are break events */ | |
126 | ||
593a1d5f A |
127 | #define CPUID_MODEL_YONAH 14 |
128 | #define CPUID_MODEL_MEROM 15 | |
129 | #define CPUID_MODEL_PENRYN 23 | |
130 | #define CPUID_MODEL_NEHALEM 26 | |
7e4a7d39 A |
131 | #define CPUID_MODEL_ATOM 28 |
132 | #define CPUID_MODEL_FIELDS 30 /* Lynnfield, Clarksfield, Jasper */ | |
133 | #define CPUID_MODEL_DALES 31 /* Havendale, Auburndale */ | |
134 | #define CPUID_MODEL_NEHALEM_EX 46 | |
593a1d5f | 135 | |
1c79356b | 136 | #ifndef ASSEMBLER |
55e303ae A |
137 | #include <stdint.h> |
138 | #include <mach/mach_types.h> | |
139 | #include <kern/kern_types.h> | |
1c79356b A |
140 | #include <mach/machine.h> |
141 | ||
1c79356b | 142 | |
0c530ab8 A |
143 | typedef enum { eax, ebx, ecx, edx } cpuid_register_t; |
144 | static inline void | |
145 | cpuid(uint32_t *data) | |
146 | { | |
147 | asm("cpuid" | |
148 | : "=a" (data[eax]), | |
149 | "=b" (data[ebx]), | |
150 | "=c" (data[ecx]), | |
151 | "=d" (data[edx]) | |
152 | : "a" (data[eax]), | |
153 | "b" (data[ebx]), | |
154 | "c" (data[ecx]), | |
155 | "d" (data[edx])); | |
156 | } | |
55e303ae A |
157 | static inline void |
158 | do_cpuid(uint32_t selector, uint32_t *data) | |
159 | { | |
160 | asm("cpuid" | |
161 | : "=a" (data[0]), | |
162 | "=b" (data[1]), | |
163 | "=c" (data[2]), | |
164 | "=d" (data[3]) | |
165 | : "a"(selector)); | |
166 | } | |
1c79356b A |
167 | |
168 | /* | |
2d21ac55 A |
169 | * Cache ID descriptor structure, used to parse CPUID leaf 2. |
170 | * Note: not used in kernel. | |
1c79356b | 171 | */ |
91447636 | 172 | typedef enum { Lnone, L1I, L1D, L2U, L3U, LCACHE_MAX } cache_type_t ; |
55e303ae A |
173 | typedef struct { |
174 | unsigned char value; /* Descriptor value */ | |
175 | cache_type_t type; /* Cache type */ | |
176 | unsigned int size; /* Cache size */ | |
177 | unsigned int linesize; /* Cache line size */ | |
178 | #ifdef KERNEL | |
91447636 | 179 | const char *description; /* Cache description */ |
55e303ae A |
180 | #endif /* KERNEL */ |
181 | } cpuid_cache_desc_t; | |
182 | ||
183 | #ifdef KERNEL | |
184 | #define CACHE_DESC(value,type,size,linesize,text) \ | |
185 | { value, type, size, linesize, text } | |
186 | #else | |
187 | #define CACHE_DESC(value,type,size,linesize,text) \ | |
188 | { value, type, size, linesize } | |
189 | #endif /* KERNEL */ | |
190 | ||
7e4a7d39 A |
191 | /* Monitor/mwait Leaf: */ |
192 | typedef struct { | |
193 | uint32_t linesize_min; | |
194 | uint32_t linesize_max; | |
195 | uint32_t extensions; | |
196 | uint32_t sub_Cstates; | |
197 | } cpuid_mwait_leaf_t; | |
198 | ||
199 | /* Thermal and Power Management Leaf: */ | |
200 | typedef struct { | |
201 | boolean_t sensor; | |
202 | boolean_t dynamic_acceleration; | |
203 | uint32_t thresholds; | |
204 | boolean_t ACNT_MCNT; | |
205 | } cpuid_thermal_leaf_t; | |
206 | ||
207 | /* Architectural Performance Monitoring Leaf: */ | |
208 | typedef struct { | |
209 | uint8_t version; | |
210 | uint8_t number; | |
211 | uint8_t width; | |
212 | uint8_t events_number; | |
213 | uint32_t events; | |
214 | uint8_t fixed_number; | |
215 | uint8_t fixed_width; | |
216 | } cpuid_arch_perf_leaf_t; | |
217 | ||
0c530ab8 | 218 | /* Physical CPU info - this is exported out of the kernel (kexts), so be wary of changes */ |
55e303ae A |
219 | typedef struct { |
220 | char cpuid_vendor[16]; | |
221 | char cpuid_brand_string[48]; | |
91447636 | 222 | const char *cpuid_model_string; |
55e303ae | 223 | |
7e4a7d39 | 224 | cpu_type_t cpuid_type; /* this is *not* a cpu_type_t in our <mach/machine.h> */ |
55e303ae A |
225 | uint8_t cpuid_family; |
226 | uint8_t cpuid_model; | |
227 | uint8_t cpuid_extmodel; | |
228 | uint8_t cpuid_extfamily; | |
229 | uint8_t cpuid_stepping; | |
0c530ab8 A |
230 | uint64_t cpuid_features; |
231 | uint64_t cpuid_extfeatures; | |
55e303ae A |
232 | uint32_t cpuid_signature; |
233 | uint8_t cpuid_brand; | |
234 | ||
235 | uint32_t cache_size[LCACHE_MAX]; | |
236 | uint32_t cache_linesize; | |
237 | ||
55e303ae A |
238 | uint8_t cache_info[64]; /* list of cache descriptors */ |
239 | ||
0c530ab8 A |
240 | uint32_t cpuid_cores_per_package; |
241 | uint32_t cpuid_logical_per_package; | |
242 | uint32_t cache_sharing[LCACHE_MAX]; | |
2d21ac55 | 243 | uint32_t cache_partitions[LCACHE_MAX]; |
0c530ab8 | 244 | |
2d21ac55 | 245 | cpu_type_t cpuid_cpu_type; /* <mach/machine.h> */ |
0c530ab8 | 246 | cpu_subtype_t cpuid_cpu_subtype; /* <mach/machine.h> */ |
2d21ac55 | 247 | |
7e4a7d39 A |
248 | /* Per-vendor info */ |
249 | cpuid_mwait_leaf_t cpuid_mwait_leaf; | |
250 | #define cpuid_mwait_linesize_max cpuid_mwait_leaf.linesize_max | |
251 | #define cpuid_mwait_linesize_min cpuid_mwait_leaf.linesize_min | |
252 | #define cpuid_mwait_extensions cpuid_mwait_leaf.extensions | |
253 | #define cpuid_mwait_sub_Cstates cpuid_mwait_leaf.sub_Cstates | |
254 | cpuid_thermal_leaf_t cpuid_thermal_leaf; | |
255 | cpuid_arch_perf_leaf_t cpuid_arch_perf_leaf; | |
256 | ||
2d21ac55 A |
257 | /* Cache details: */ |
258 | uint32_t cpuid_cache_linesize; | |
259 | uint32_t cpuid_cache_L2_associativity; | |
260 | uint32_t cpuid_cache_size; | |
261 | ||
262 | /* Virtual and physical address aize: */ | |
263 | uint32_t cpuid_address_bits_physical; | |
264 | uint32_t cpuid_address_bits_virtual; | |
593a1d5f A |
265 | |
266 | uint32_t cpuid_microcode_version; | |
267 | ||
b0d623f7 A |
268 | /* Numbers of tlbs per processor [i|d, small|large, level0|level1] */ |
269 | uint32_t cpuid_tlb[2][2][2]; | |
270 | #define TLB_INST 0 | |
271 | #define TLB_DATA 1 | |
272 | #define TLB_SMALL 0 | |
273 | #define TLB_LARGE 1 | |
274 | uint32_t cpuid_stlb; | |
593a1d5f A |
275 | |
276 | uint32_t core_count; | |
277 | uint32_t thread_count; | |
278 | ||
b0d623f7 A |
279 | /* Max leaf ids available from CPUID */ |
280 | uint32_t cpuid_max_basic; | |
281 | uint32_t cpuid_max_ext; | |
7e4a7d39 A |
282 | |
283 | /* Family-specific info links */ | |
284 | uint32_t cpuid_cpufamily; | |
285 | cpuid_mwait_leaf_t *cpuid_mwait_leafp; | |
286 | cpuid_thermal_leaf_t *cpuid_thermal_leafp; | |
287 | cpuid_arch_perf_leaf_t *cpuid_arch_perf_leafp; | |
288 | ||
55e303ae | 289 | } i386_cpu_info_t; |
1c79356b | 290 | |
91447636 A |
291 | #ifdef __cplusplus |
292 | extern "C" { | |
293 | #endif | |
1c79356b A |
294 | |
295 | /* | |
296 | * External declarations | |
297 | */ | |
0c530ab8 A |
298 | extern cpu_type_t cpuid_cputype(void); |
299 | extern cpu_subtype_t cpuid_cpusubtype(void); | |
300 | extern void cpuid_cpu_display(const char *); | |
301 | extern void cpuid_feature_display(const char *); | |
302 | extern void cpuid_extfeature_display(const char *); | |
303 | extern char * cpuid_get_feature_names(uint64_t, char *, unsigned); | |
304 | extern char * cpuid_get_extfeature_names(uint64_t, char *, unsigned); | |
305 | ||
306 | extern uint64_t cpuid_features(void); | |
307 | extern uint64_t cpuid_extfeatures(void); | |
55e303ae | 308 | extern uint32_t cpuid_family(void); |
7e4a7d39 | 309 | extern uint32_t cpuid_cpufamily(void); |
91447636 A |
310 | |
311 | extern void cpuid_get_info(i386_cpu_info_t *info_p); | |
312 | extern i386_cpu_info_t *cpuid_info(void); | |
55e303ae | 313 | |
0c530ab8 | 314 | extern void cpuid_set_info(void); |
1c79356b | 315 | |
91447636 A |
316 | #ifdef __cplusplus |
317 | } | |
318 | #endif | |
55e303ae | 319 | |
1c79356b | 320 | #endif /* ASSEMBLER */ |
55e303ae A |
321 | |
322 | #endif /* __APPLE_API_PRIVATE */ | |
1c79356b | 323 | #endif /* _MACHINE_CPUID_H_ */ |