Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/libsaio/cpuid.h

1/*
2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31
32/*
33 * x86 CPU identification
34 *
35 */
36
37#ifndef _MACHINE_CPUID_H_
38#define _MACHINE_CPUID_H_
39
40#include <stdint.h>
41
42#defineCPUID_VID_INTEL"GenuineIntel"
43#defineCPUID_VID_AMD"AuthenticAMD"
44
45#define CPUID_STRING_UNKNOWN "Unknown CPU Typ"
46
47#define _Bit(n)(1ULL << n)
48#define _HBit(n)(1ULL << ((n)+32))
49
50/*
51 * The CPUID_FEATURE_XXX values define 64-bit values
52 * returned in %ecx:%edx to a CPUID request with %eax of 1:
53 */
54#define CPUID_FEATURE_FPU _Bit(0) /* Floating point unit on-chip */
55#define CPUID_FEATURE_VME _Bit(1) /* Virtual Mode Extension */
56#define CPUID_FEATURE_DE _Bit(2) /* Debugging Extension */
57#define CPUID_FEATURE_PSE _Bit(3) /* Page Size Extension */
58#define CPUID_FEATURE_TSC _Bit(4) /* Time Stamp Counter */
59#define CPUID_FEATURE_MSR _Bit(5) /* Model Specific Registers */
60#define CPUID_FEATURE_PAE _Bit(6) /* Physical Address Extension */
61#define CPUID_FEATURE_MCE _Bit(7) /* Machine Check Exception */
62#define CPUID_FEATURE_CX8 _Bit(8) /* CMPXCHG8B */
63#define CPUID_FEATURE_APIC _Bit(9) /* On-chip APIC */
64#define CPUID_FEATURE_SEP _Bit(11) /* Fast System Call */
65#define CPUID_FEATURE_MTRR _Bit(12) /* Memory Type Range Register */
66#define CPUID_FEATURE_PGE _Bit(13) /* Page Global Enable */
67#define CPUID_FEATURE_MCA _Bit(14) /* Machine Check Architecture */
68#define CPUID_FEATURE_CMOV _Bit(15) /* Conditional Move Instruction */
69#define CPUID_FEATURE_PAT _Bit(16) /* Page Attribute Table */
70#define CPUID_FEATURE_PSE36 _Bit(17) /* 36-bit Page Size Extension */
71#define CPUID_FEATURE_PSN _Bit(18) /* Processor Serial Number */
72#define CPUID_FEATURE_CLFSH _Bit(19) /* CLFLUSH Instruction supported */
73#define CPUID_FEATURE_DS _Bit(21) /* Debug Store */
74#define CPUID_FEATURE_ACPI _Bit(22) /* Thermal monitor and Clock Ctrl */
75#define CPUID_FEATURE_MMX _Bit(23) /* MMX supported */
76#define CPUID_FEATURE_FXSR _Bit(24) /* Fast floating pt save/restore */
77#define CPUID_FEATURE_SSE _Bit(25) /* Streaming SIMD extensions */
78#define CPUID_FEATURE_SSE2 _Bit(26) /* Streaming SIMD extensions 2 */
79#define CPUID_FEATURE_SS _Bit(27) /* Self-Snoop */
80#define CPUID_FEATURE_HTT _Bit(28) /* Hyper-Threading Technology */
81#define CPUID_FEATURE_TM _Bit(29) /* Thermal Monitor (TM1) */
82#define CPUID_FEATURE_PBE _Bit(31) /* Pend Break Enable */
83
84#define CPUID_FEATURE_SSE3 _HBit(0) /* Streaming SIMD extensions 3 */
85#define CPUID_FEATURE_PCLMULQDQ _HBit(1) /* PCLMULQDQ instruction */
86#define CPUID_FEATURE_DTES64 _HBit(2) /* 64-bit DS layout */
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 */
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 */
98
99#define CPUID_FEATURE_DCA _HBit(18) /* Direct Cache Access */
100#define CPUID_FEATURE_SSE4_1 _HBit(19) /* Streaming SIMD extensions 4.1 */
101#define CPUID_FEATURE_SSE4_2 _HBit(20) /* Streaming SIMD extensions 4.2 */
102#define CPUID_FEATURE_xAPIC _HBit(21) /* Extended APIC Mode */
103#define CPUID_FEATURE_MOVBE _HBit(22) /* MOVBE instruction */
104#define CPUID_FEATURE_POPCNT _HBit(23) /* POPCNT instruction */
105#define CPUID_FEATURE_AES _HBit(25) /* AES instructions */
106#define CPUID_FEATURE_XSAVE _HBit(26) /* XSAVE instructions */
107#define CPUID_FEATURE_OSXSAVE _HBit(27) /* XGETBV/XSETBV instructions */
108#define CPUID_FEATURE_VMM _HBit(31) /* VMM (Hypervisor) present */
109#define CPUID_FEATURE_SEGLIM64 _HBit(11) /* 64-bit segment limit checking */
110#define CPUID_FEATURE_PCID _HBit(17) /* ASID-PCID support */
111#define CPUID_FEATURE_TSCTMR _HBit(24) /* TSC deadline timer */
112#define CPUID_FEATURE_AVX1_0_HBit(28) /* AVX 1.0 instructions */
113
114/*
115 * The CPUID_EXTFEATURE_XXX values define 64-bit values
116 * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001:
117 */
118#define CPUID_EXTFEATURE_SYSCALL _Bit(11)/* SYSCALL/sysret */
119#define CPUID_EXTFEATURE_XD _Bit(20)/* eXecute Disable */
120
121#define CPUID_EXTFEATURE_1GBPAGE _Bit(26)/* 1GB pages */
122#define CPUID_EXTFEATURE_RDTSCP _Bit(27)/* RDTSCP */
123#define CPUID_EXTFEATURE_EM64T _Bit(29)/* Extended Mem 64 Technology */
124
125#define CPUID_EXTFEATURE_LAHF _HBit(0)/* LAFH/SAHF instructions */
126
127/*
128 * The CPUID_EXTFEATURE_XXX values define 64-bit values
129 * returned in %ecx:%edx to a CPUID request with %eax of 0x80000007:
130 */
131#define CPUID_EXTFEATURE_TSCI _Bit(8)/* TSC Invariant */
132
133#defineCPUID_CACHE_SIZE16/* Number of descriptor values */
134
135#define CPUID_MWAIT_EXTENSION_Bit(0)/* enumeration of WMAIT extensions */
136#define CPUID_MWAIT_BREAK_Bit(1)/* interrupts are break events */
137
138#define CPUID_MODEL_YONAH0x0E
139#define CPUID_MODEL_MEROM0x0F
140#define CPUID_MODEL_PENRYN0x17
141#define CPUID_MODEL_NEHALEM0x1A
142#define CPUID_MODEL_FIELDS0x1E/* Lynnfield, Clarksfield, Jasper */
143#define CPUID_MODEL_DALES0x1F/* Havendale, Auburndale */
144#define CPUID_MODEL_NEHALEM_EX0x2E
145#define CPUID_MODEL_DALES_32NM0x25/* Clarkdale, Arrandale */
146#define CPUID_MODEL_WESTMERE0x2C/* Gulftown, Westmere-EP, Westmere-WS */
147#define CPUID_MODEL_WESTMERE_EX0x2F
148/* Additional internal models go here */
149#define CPUID_MODEL_SANDYBRIDGE0x2A
150#define CPUID_MODEL_JAKETOWN0x2D
151
152typedef enum { eax, ebx, ecx, edx } cpuid_register_t;
153
154#if UNUSED
155static inline void
156cpuid(uint32_t *data)
157{
158asm("cpuid"
159: "=a" (data[eax]),
160 "=b" (data[ebx]),
161 "=c" (data[ecx]),
162 "=d" (data[edx])
163: "a" (data[eax]),
164 "b" (data[ebx]),
165 "c" (data[ecx]),
166 "d" (data[edx]));
167}
168#endif
169
170static inline void
171do_cpuid(uint32_t selector, uint32_t *data)
172{
173asm("cpuid"
174: "=a" (data[0]),
175 "=b" (data[1]),
176 "=c" (data[2]),
177 "=d" (data[3])
178: "a"(selector),
179 "b" (0),
180 "c" (0),
181 "d" (0));
182}
183
184/*
185 * Cache ID descriptor structure, used to parse CPUID leaf 2.
186 * Note: not used in kernel.
187 */
188typedef enum { Lnone, L1I, L1D, L2U, L3U, LCACHE_MAX } cache_type_t ;
189typedef struct {
190unsigned charvalue; /* Descriptor value */
191cache_type_t type; /* Cache type */
192unsigned int size; /* Cache size */
193unsigned int linesize; /* Cache line size */
194#ifdef KERNEL
195const char*description; /* Cache description */
196#endif /* KERNEL */
197} cpuid_cache_desc_t;
198
199#ifdef KERNEL
200#define CACHE_DESC(value,type,size,linesize,text) \
201{ value, type, size, linesize, text }
202#else
203#define CACHE_DESC(value,type,size,linesize,text) \
204{ value, type, size, linesize }
205#endif /* KERNEL */
206
207/* Monitor/mwait Leaf: */
208typedef struct {
209uint32_tlinesize_min;
210uint32_tlinesize_max;
211uint32_textensions;
212uint32_tsub_Cstates;
213} cpuid_mwait_leaf_t;
214
215/* Thermal and Power Management Leaf: */
216typedef struct {
217boolean_tsensor;
218boolean_tdynamic_acceleration;
219boolean_tinvariant_APIC_timer;
220boolean_tcore_power_limits;
221boolean_tfine_grain_clock_mod;
222boolean_tpackage_thermal_intr;
223uint32_tthresholds;
224boolean_tACNT_MCNT;
225boolean_thardware_feedback;
226boolean_tenergy_policy;
227} cpuid_thermal_leaf_t;
228
229
230/* XSAVE Feature Leaf: */
231typedef struct {
232uint32_textended_state[4];/* eax .. edx */
233} cpuid_xsave_leaf_t;
234
235
236/* Architectural Performance Monitoring Leaf: */
237typedef struct {
238uint8_tversion;
239uint8_tnumber;
240uint8_twidth;
241uint8_tevents_number;
242uint32_tevents;
243uint8_tfixed_number;
244uint8_tfixed_width;
245} cpuid_arch_perf_leaf_t;
246
247/* Physical CPU info - this is exported out of the kernel (kexts), so be wary of changes */
248typedef struct {
249charcpuid_vendor[16];
250charcpuid_brand_string[48];
251const char*cpuid_model_string;
252
253cpu_type_tcpuid_type;/* this is *not* a cpu_type_t in our <mach/machine.h> */
254uint8_tcpuid_family;
255uint8_tcpuid_model;
256uint8_tcpuid_extmodel;
257uint8_tcpuid_extfamily;
258uint8_tcpuid_stepping;
259uint64_tcpuid_features;
260uint64_tcpuid_extfeatures;
261uint32_tcpuid_signature;
262uint8_t cpuid_brand;
263
264uint32_tcache_size[LCACHE_MAX];
265uint32_tcache_linesize;
266
267uint8_tcache_info[64]; /* list of cache descriptors */
268
269uint32_tcpuid_cores_per_package;
270uint32_tcpuid_logical_per_package;
271uint32_tcache_sharing[LCACHE_MAX];
272uint32_tcache_partitions[LCACHE_MAX];
273
274cpu_type_tcpuid_cpu_type;/* <mach/machine.h> */
275cpu_subtype_tcpuid_cpu_subtype;/* <mach/machine.h> */
276
277/* Per-vendor info */
278cpuid_mwait_leaf_tcpuid_mwait_leaf;
279#define cpuid_mwait_linesize_maxcpuid_mwait_leaf.linesize_max
280#define cpuid_mwait_linesize_mincpuid_mwait_leaf.linesize_min
281#define cpuid_mwait_extensionscpuid_mwait_leaf.extensions
282#define cpuid_mwait_sub_Cstatescpuid_mwait_leaf.sub_Cstates
283cpuid_thermal_leaf_tcpuid_thermal_leaf;
284cpuid_arch_perf_leaf_tcpuid_arch_perf_leaf;
285cpuid_xsave_leaf_tcpuid_xsave_leaf;
286
287/* Cache details: */
288uint32_tcpuid_cache_linesize;
289uint32_tcpuid_cache_L2_associativity;
290uint32_tcpuid_cache_size;
291
292/* Virtual and physical address aize: */
293uint32_tcpuid_address_bits_physical;
294uint32_tcpuid_address_bits_virtual;
295
296uint32_tcpuid_microcode_version;
297
298/* Numbers of tlbs per processor [i|d, small|large, level0|level1] */
299uint32_tcpuid_tlb[2][2][2];
300#defineTLB_INST0
301#defineTLB_DATA1
302#defineTLB_SMALL0
303#defineTLB_LARGE1
304uint32_tcpuid_stlb;
305
306uint32_tcore_count;
307uint32_tthread_count;
308
309/* Max leaf ids available from CPUID */
310uint32_tcpuid_max_basic;
311uint32_tcpuid_max_ext;
312
313/* Family-specific info links */
314uint32_tcpuid_cpufamily;
315cpuid_mwait_leaf_t*cpuid_mwait_leafp;
316cpuid_thermal_leaf_t*cpuid_thermal_leafp;
317cpuid_arch_perf_leaf_t*cpuid_arch_perf_leafp;
318cpuid_xsave_leaf_t*cpuid_xsave_leafp;
319} i386_cpu_info_t;
320
321
322#endif /* _MACHINE_CPUID_H_ */
323

Archive Download this file

Revision: 2006