Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/libsaio/platform.h

1/*
2 * platform.h
3 * AsereBLN: reworked and extended
4 *
5 */
6
7#ifndef __LIBSAIO_PLATFORM_H
8#define __LIBSAIO_PLATFORM_H
9
10//#include "libsaio.h"
11
12extern bool platformCPUFeature(uint32_t);
13extern void scan_platform(void);
14extern void dumpPhysAddr(const char * title, void * a, int len);
15
16
17#define CPU_MODEL_PRESCOTT0x03// Celeron D, Pentium 4 (90nm)
18#define CPU_MODEL_NOCONA0x04// Xeon Nocona/Paxville, Irwindale (90nm)
19#define CPU_MODEL_PRESLER0x06// Pentium 4, Pentium D (65nm)
20#define CPU_MODEL_PENTIUM_M0x09// Banias Pentium M (130nm)
21#define CPU_MODEL_DOTHAN0x0D// Dothan Pentium M, Celeron M (90nm)
22#define CPU_MODEL_YONAH0x0E// Sossaman, Yonah
23#define CPU_MODEL_MEROM0x0F// Allendale, Conroe, Kentsfield, Woodcrest, Clovertown, Tigerton, Merom
24#define CPU_MODEL_CONROE0x0F//
25#define CPU_MODEL_CELERON0x16// Merom, Conroe (65nm)
26#define CPU_MODEL_PENRYN0x17// Wolfdale, Yorkfield, Harpertown, Penryn
27#define CPU_MODEL_WOLFDALE0x17//
28#define CPU_MODEL_NEHALEM0x1A// Bloomfield. Nehalem-EP, Nehalem-WS, Gainestown
29#define CPU_MODEL_ATOM0x1C// Pineview
30#define CPU_MODEL_XEON_MP0x1D// MP 7400
31#define CPU_MODEL_FIELDS0x1E// Lynnfield, Clarksfield, Jasper Forest
32#define CPU_MODEL_DALES0x1F// Havendale, Auburndale
33#define CPU_MODEL_DALES_32NM0x25// Clarkdale, Arrandale
34#define CPU_MODEL_ATOM_SAN0x26// Lincroft
35#define CPU_MODEL_LINCROFT0x27//
36#define CPU_MODEL_SANDYBRIDGE0x2A// Sandy Bridge
37#define CPU_MODEL_WESTMERE0x2C// Gulftown, Westmere-EP, Westmere-WS
38#define CPU_MODEL_JAKETOWN0x2D// Sandy Bridge-E, Sandy Bridge-EP
39#define CPU_MODEL_NEHALEM_EX0x2E// Beckton
40#define CPU_MODEL_WESTMERE_EX0x2F// Westmere-EX
41#define CPU_MODEL_ATOM_20000x36// Cedarview
42#define CPU_MODEL_IVYBRIDGE0x3A// Ivy Bridge
43#define CPU_MODEL_HASWELL0x3C// Haswell DT
44#define CPU_MODEL_IVYBRIDGE_XEON0x3E// Ivy Bridge Xeon
45#define CPU_MODEL_HASWELL_SVR0x3F// Haswell MB
46//#define CPU_MODEL_HASWELL_H0x??// Haswell H
47#define CPU_MODEL_HASWELL_ULT0x45// Haswell ULT
48#define CPU_MODEL_CRYSTALWELL0x46// Haswell ULX
49
50/* CPUID Vendor */
51#define CPUID_VENDOR_INTEL 0x756E6547
52#define CPUID_VENDOR_AMD 0x68747541
53
54/* Unknown CPU */
55#define CPU_STRING_UNKNOWN"Unknown CPU Type"
56#define bit(n)(1ULL << (n))
57#define bitmask(h,l)((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
58#define bitfield(x,h,l)(((x) & bitmask(h,l)) >> l)
59
60
61/*
62 * The CPUID_FEATURE_XXX values define 64-bit values
63 * returned in %ecx:%edx to a CPUID request with %eax of 1:
64 */
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 */
94
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 */
106#define CPUID_FEATURE_SEGLIM64 _HBit(11) /* 64-bit segment limit checking */
107#define CPUID_FEATURE_FMA _HBit(12) /* Fused-Multiply-Add support */
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
112#define CPUID_FEATURE_PCID _HBit(17) /* ASID-PCID support */
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 */
116#define CPUID_FEATURE_x2APIC _HBit(21) /* Extended APIC Mode */
117#define CPUID_FEATURE_MOVBE _HBit(22) /* MOVBE instruction */
118#define CPUID_FEATURE_POPCNT _HBit(23) /* POPCNT instruction */
119#define CPUID_FEATURE_TSCTMR _HBit(24) /* TSC deadline timer */
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 */
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 */
126#define CPUID_FEATURE_VMM _HBit(31) /* VMM (Hypervisor) present */
127
128/*
129 * Leaf 7, subleaf 0 additional features.
130 * Bits returned in %ebx to a CPUID request with {%eax,%ecx} of (0x7,0x0}:
131 */
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_BMI1 _Bit(3)/* Bit Manipulation Instrs, set 1 */
135#define CPUID_LEAF7_FEATURE_HLE _Bit(4)/* Hardware Lock Elision*/
136#define CPUID_LEAF7_FEATURE_AVX2 _Bit(5)/* AVX2 Instructions */
137#define CPUID_LEAF7_FEATURE_SMEP _Bit(7)/* Supervisor Mode Execute Protect */
138#define CPUID_LEAF7_FEATURE_BMI2 _Bit(8)/* Bit Manipulation Instrs, set 2 */
139#define CPUID_LEAF7_FEATURE_ENFSTRG _Bit(9)/* ENhanced Fast STRinG copy */
140#define CPUID_LEAF7_FEATURE_INVPCID _Bit(10)/* INVPCID intruction, TDB */
141#define CPUID_LEAF7_FEATURE_RTM _Bit(11)/* TBD */
142
143/*
144 * The CPUID_EXTFEATURE_XXX values define 64-bit values
145 * returned in %ecx:%edx to a CPUID request with %eax of 0x80000001:
146 */
147#define CPUID_EXTFEATURE_SYSCALL _Bit(11)/* SYSCALL/sysret */
148#define CPUID_EXTFEATURE_XD _Bit(20)/* eXecute Disable */
149
150#define CPUID_EXTFEATURE_1GBPAGE _Bit(26)/* 1GB pages */
151#define CPUID_EXTFEATURE_RDTSCP _Bit(27)/* RDTSCP */
152#define CPUID_EXTFEATURE_EM64T _Bit(29)/* Extended Mem 64 Technology */
153
154#define CPUID_EXTFEATURE_LAHF _HBit(0)/* LAFH/SAHF instructions */
155
156/*
157 * The CPUID_EXTFEATURE_XXX values define 64-bit values
158 * returned in %ecx:%edx to a CPUID request with %eax of 0x80000007:
159 */
160#define CPUID_EXTFEATURE_TSCI _Bit(8)/* TSC Invariant */
161
162#defineCPUID_CACHE_SIZE16/* Number of descriptor values */
163
164#define CPUID_MWAIT_EXTENSION_Bit(0)/* enumeration of WMAIT extensions */
165#define CPUID_MWAIT_BREAK_Bit(1)/* interrupts are break events */
166
167//-- processor type -> p_type:
168#define PT_OEM0x00// Intel Original OEM Processor;
169#define PT_OD0x01 // Intel Over Drive Processor;
170#define PT_DUAL0x02// Intel Dual Processor;
171#define PT_RES0x03// Intel Reserved;
172
173/* Known MSR registers */
174#define MSR_IA32_PLATFORM_ID 0x0017
175#define MSR_CORE_THREAD_COUNT 0x0035/* limited use - not for Penryn or older */
176#define IA32_TSC_ADJUST 0x003B
177#define MSR_IA32_BIOS_SIGN_ID 0x008B/* microcode version */
178#define MSR_FSB_FREQ 0x00CD/* limited use - not for i7 */
179#defineMSR_PLATFORM_INFO 0x00CE/* limited use - MinRatio for i7 but Max for Yonah*/
180/* turbo for penryn */
181#define MSR_PKG_CST_CONFIG_CONTROL 0x00E2/* sandy and ivy */
182#define MSR_PMG_IO_CAPTURE_BASE 0x00E4
183#define IA32_MPERF 0x00E7/* TSC in C0 only */
184#define IA32_APERF 0x00E8/* actual clocks in C0 */
185#define MSR_IA32_EXT_CONFIG 0x00EE/* limited use - not for i7 */
186#define MSR_FLEX_RATIO 0x0194/* limited use - not for Penryn or older */
187//see no value on most CPUs
188#defineMSR_IA32_PERF_STATUS 0x0198
189#define MSR_IA32_PERF_CONTROL 0x0199
190#define MSR_IA32_CLOCK_MODULATION 0x019A
191#define MSR_THERMAL_STATUS 0x019C
192#define MSR_IA32_MISC_ENABLE 0x01A0
193#define MSR_THERMAL_TARGET 0x01A2 /* TjMax limited use - not for Penryn or older*/
194#define MSR_MISC_PWR_MGMT 0x01AA
195#define MSR_TURBO_RATIO_LIMIT 0x01AD /* limited use - not for Penryn or older */
196
197#define IA32_ENERGY_PERF_BIAS0x01B0
198#define MSR_PACKAGE_THERM_STATUS0x01B1
199#define IA32_PLATFORM_DCA_CAP0x01F8
200#define MSR_POWER_CTL0x01FC // MSR 000001FC 0000-0000-0004-005F
201
202// Sandy Bridge & JakeTown specific 'Running Average Power Limit' MSR's.
203#define MSR_RAPL_POWER_UNIT0x606 /* R/O */
204//MSR 00000606 0000-0000-000A-1003
205#define MSR_PKGC3_IRTL 0x60A /* RW time limit to go C3 */
206// bit 15 = 1 -- the value valid for C-state PM
207#define MSR_PKGC6_IRTL 0x60B /* RW time limit to go C6 */
208//MSR 0000060B 0000-0000-0000-8854
209//Valid + 010=1024ns + 0x54=84mks
210#define MSR_PKGC7_IRTL 0x60C /* RW time limit to go C7 */
211//MSR 0000060C 0000-0000-0000-8854
212#define MSR_PKG_C2_RESIDENCY 0x60D /* same as TSC but in C2 only */
213
214#define MSR_PKG_RAPL_POWER_LIMIT0x610 //MSR 00000610 0000-A580-0000-8960
215#define MSR_PKG_ENERGY_STATUS0x611 //MSR 00000611 0000-0000-3212-A857
216#define MSR_PKG_POWER_INFO0x614 //MSR 00000614 0000-0000-01E0-02F8
217
218//AMD
219#define K8_FIDVID_STATUS 0xC0010042
220#define K10_COFVID_LIMIT 0xC0010061
221#define K10_PSTATE_STATUS 0xC0010064
222#define K10_COFVID_STATUS 0xC0010071
223
224#define MSR_AMD_MPERF 0x000000E7
225#define MSR_AMD_APERF 0x000000E8
226
227#define DEFAULT_FSB100000 /* for now, hardcoding 100MHz for old CPUs */
228
229// DFE: This constant comes from older xnu:
230#define CLKNUM1193182/* formerly 1193167 */
231
232/* CPUID index into cpuid_raw */
233#define CPUID_00
234#define CPUID_11
235#define CPUID_22
236#define CPUID_33
237#define CPUID_44
238#define CPUID_55
239#define CPUID_66
240#define CPUID_807
241#define CPUID_818
242#define CPUID_889
243#define CPUID_MAX10
244
245/* CPU Features */
246#define CPU_FEATURE_MMX0x00000001// MMX Instruction Set
247#define CPU_FEATURE_SSE0x00000002// SSE Instruction Set
248#define CPU_FEATURE_SSE20x00000004// SSE2 Instruction Set
249#define CPU_FEATURE_SSE30x00000008// SSE3 Instruction Set
250#define CPU_FEATURE_SSE410x00000010// SSE41 Instruction Set
251#define CPU_FEATURE_SSE420x00000020// SSE42 Instruction Set
252#define CPU_FEATURE_EM64T0x00000040// 64Bit Support
253#define CPU_FEATURE_HTT0x00000080// HyperThreading
254#define CPU_FEATURE_MOBILE0x00000100// Mobile CPU
255#define CPU_FEATURE_MSR0x00000200// MSR Support
256
257/* SMBIOS Memory Types */
258#define SMB_MEM_TYPE_UNDEFINED0
259#define SMB_MEM_TYPE_OTHER1
260#define SMB_MEM_TYPE_UNKNOWN2
261#define SMB_MEM_TYPE_DRAM3
262#define SMB_MEM_TYPE_EDRAM4
263#define SMB_MEM_TYPE_VRAM5
264#define SMB_MEM_TYPE_SRAM6
265#define SMB_MEM_TYPE_RAM7
266#define SMB_MEM_TYPE_ROM8
267#define SMB_MEM_TYPE_FLASH9
268#define SMB_MEM_TYPE_EEPROM10
269#define SMB_MEM_TYPE_FEPROM11
270#define SMB_MEM_TYPE_EPROM12
271#define SMB_MEM_TYPE_CDRAM13
272#define SMB_MEM_TYPE_3DRAM14
273#define SMB_MEM_TYPE_SDRAM15
274#define SMB_MEM_TYPE_SGRAM16
275#define SMB_MEM_TYPE_RDRAM17
276#define SMB_MEM_TYPE_DDR18
277#define SMB_MEM_TYPE_DDR219
278#define SMB_MEM_TYPE_FBDIMM20
279#define SMB_MEM_TYPE_DDR324// Supported in 10.5.6+ AppleSMBIOS
280
281/* Memory Configuration Types */
282#define SMB_MEM_CHANNEL_UNKNOWN0
283#define SMB_MEM_CHANNEL_SINGLE1
284#define SMB_MEM_CHANNEL_DUAL2
285#define SMB_MEM_CHANNEL_TRIPLE3
286
287/* Maximum number of ram slots */
288#define MAX_RAM_SLOTS8
289#define RAM_SLOT_ENUMERATOR{0, 2, 4, 1, 3, 5, 6, 8, 10, 7, 9, 11}
290
291/* Maximum number of SPD bytes */
292#define MAX_SPD_SIZE256
293
294/* Size of SMBIOS UUID in bytes */
295#define UUID_LEN16
296
297typedef struct _RamSlotInfo_t
298{
299uint32_tModuleSize;// Size of Module in MB
300uint32_tFrequency;// in Mhz
301const char*Vendor;
302const char*PartNo;
303const char*SerialNo;
304char*spd;// SPD Dump
305boolInUse;
306uint8_tType;
307uint8_tBankConnections;// table type 6, see (3.3.7)
308uint8_tBankConnCnt;
309} RamSlotInfo_t;
310
311//==============================================================================
312
313typedef struct _PlatformInfo_t {
314struct CPU {
315uint32_tVendor;// Vendor - char Vendor[16];
316charBrandString[48];// 48 Byte Branding String
317//uint16_tType;// Type
318uint8_tFamily;// Family
319uint8_tModel;// Model
320uint8_tExtModel;// Extended Model
321uint8_tExtFamily;// Extended Family
322uint8_tStepping;// Stepping
323uint64_tFeatures;// CPU Features like MMX, SSE2, VT, MobileCPU
324uint64_tExtFeatures;
325uint32_tCoresPerPackage;
326uint32_tLogicalPerPackage;
327uint32_tSignature;// Processor Signature
328//uint8_tBrand;
329//uint8_tProcessorFlag;
330
331uint32_tNoCores;// No Cores per Package
332uint32_tNoThreads;// Threads per Package
333
334//uint32_tCacheSize[LCACHE_MAX];
335//uint32_tCacheLineSize;
336
337//uint8_tcache_info[64];// list of cache descriptors
338
339uint8_tMaxCoef;// Max Multiplier
340uint8_tMaxDiv;// Min Multiplier
341uint8_tCurrCoef;// Current Multiplier
342uint8_tCurrDiv;
343uint64_tTSCFrequency;// TSC Frequency Hz
344uint64_tFSBFrequency;// FSB Frequency Hz
345uint64_tCPUFrequency;// CPU Frequency Hz
346uint32_tMaxRatio;// Max Bus Ratio
347uint32_tMinRatio;// Min Bus Ratio
348uint32_tCPUID[CPUID_MAX][4];// CPUID 0..4, 80..81 Raw Values
349
350uint32_tMCodeVersion; // CPU Microcode version
351} CPU;
352
353struct RAM {
354uint64_tFrequency;// Ram Frequency
355uint32_tDivider;// Memory divider
356uint8_tCAS;// CAS 1/2/2.5/3/4/5/6/7
357uint8_tTRC;
358uint8_tTRP;
359uint8_tRAS;
360uint8_tChannels;// Channel Configuration Single,Dual or Triple
361uint8_tNoSlots;// Maximum no of slots available
362uint8_tType;// Standard SMBIOS v2.5 Memory Type
363RamSlotInfo_tDIMM[MAX_RAM_SLOTS];// Information about each slot
364} RAM;
365
366struct DMI {
367intMaxMemorySlots;// number of memory slots populated by SMBIOS
368intCntMemorySlots;// number of memory slots counted
369intMemoryModules;// number of memory modules installed
370intDIMM[MAX_RAM_SLOTS];// Information and SPD mapping for each slot
371} DMI;
372
373uint8_tType;// System Type: 1=Desktop, 2=Portable, 3=Workstation... according ACPI2.0 (FACP: PM_Profile)
374uint8_t*UUID;
375} PlatformInfo_t;
376
377extern PlatformInfo_t Platform;
378
379#endif /* !__LIBSAIO_PLATFORM_H */
380

Archive Download this file

Revision: 2385