Chameleon

Chameleon Svn Source Tree

Root/branches/Bungo/i386/libsaio/smbios_getters.c

1/*
2 * Add (c) here
3 *
4 * Copyright .... All rights reserved.
5 *
6 */
7
8#include "smbios_getters.h"
9#include "bootstruct.h"
10
11#ifndef DEBUG_SMBIOS
12#define DEBUG_SMBIOS 0
13#endif
14
15#if DEBUG_SMBIOS
16#define DBG(x...)printf(x)
17#else
18#define DBG(x...)
19#endif
20
21
22bool getProcessorInformationExternalClock(returnType *value)
23{
24if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
25switch (Platform.CPU.Family) {
26case 0x06:
27{
28switch (Platform.CPU.Model)
29{
30// set external clock to 0 for SANDY
31// removes FSB info from system profiler as on real mac's.
32case CPU_MODEL_SANDYBRIDGE:
33case CPU_MODEL_IVYBRIDGE_XEON:
34case CPU_MODEL_IVYBRIDGE:
35case CPU_MODEL_HASWELL:
36case CPU_MODEL_HASWELL_SVR:
37case CPU_MODEL_HASWELL_ULT:
38case CPU_MODEL_CRYSTALWELL:
39
40value->word = 0;
41break;
42default:
43value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
44}
45}
46break;
47
48default:
49value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
50}
51} else {
52value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
53}
54
55return true;
56}
57
58bool getProcessorInformationMaximumClock(returnType *value)
59{
60value->word = (uint16_t)(Platform.CPU.CPUFrequency/1000000LL);
61return true;
62}
63
64bool getSMBOemProcessorBusSpeed(returnType *value)
65{
66if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
67switch (Platform.CPU.Family) {
68case 0x06:
69{
70switch (Platform.CPU.Model) {
71case CPU_MODEL_PENTIUM_M:
72case CPU_MODEL_DOTHAN:// Intel Pentium M
73case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
74case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
75case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
76case CPU_MODEL_ATOM:// Intel Atom (45nm)
77return false;
78
79case 0x19:
80case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
81case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
82case CPU_MODEL_DALES:
83case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
84case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
85case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
86case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
87case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
88case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
89case CPU_MODEL_IVYBRIDGE_XEON:
90case CPU_MODEL_HASWELL:
91case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
92{
93// thanks to dgobe for i3/i5/i7 bus speed detection
94int nhm_bus = 0x3F;
95static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
96unsigned long did, vid;
97unsigned int i;
98
99// Nehalem supports Scrubbing
100// First, locate the PCI bus where the MCH is located
101for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) {
102vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
103did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
104vid &= 0xFFFF;
105did &= 0xFF00;
106
107if(vid == 0x8086 && did >= 0x2C00) {
108nhm_bus = possible_nhm_bus[i];
109}
110}
111
112unsigned long qpimult, qpibusspeed;
113qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
114qpimult &= 0x7F;
115DBG("qpimult %d\n", qpimult);
116qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000LL));
117// Rek: rounding decimals to match original mac profile info
118if (qpibusspeed%100 != 0) {
119qpibusspeed = ((qpibusspeed+50)/100)*100;
120}
121DBG("qpibusspeed %d\n", qpibusspeed);
122value->word = qpibusspeed;
123return true;
124}
125default:
126break; //Unsupported CPU type
127}
128}
129default:
130break;
131}
132}
133return false;
134}
135
136uint16_t simpleGetSMBOemProcessorType(void)
137{
138if (Platform.CPU.NoCores >= 4) {
139return 0x0501;// 1281 - Quad-Core Xeon
140} else if (Platform.CPU.NoCores == 1) {
141return 0x0201;// // 513 - Core Duo
142};
143
144return 0x0301;// 769 - Core 2 Duo
145}
146
147bool getSMBOemProcessorType(returnType *value)
148{
149static bool done = false;
150
151value->word = simpleGetSMBOemProcessorType();
152
153if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
154if (!done) {
155verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model);
156done = true;
157}
158// Bungo: fixes Oem Processor Type - better matching IMHO, needs testing
159switch (Platform.CPU.Family) {
160 case 0x0F:
161case 0x06:
162{
163switch (Platform.CPU.Model) {
164 case CPU_MODEL_PENTIUM_M:
165case CPU_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
166 case CPU_MODEL_PRESCOTT:
167 case CPU_MODEL_NOCONA:
168 return true;
169
170case CPU_MODEL_PRESLER:
171 case CPU_MODEL_CELERON:
172 case CPU_MODEL_YONAH:// 0x0E - Intel Mobile Core Solo, Duo
173value->word = 0x201; // 513
174return true;
175
176case CPU_MODEL_MEROM:// 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
177 case CPU_MODEL_XEON_MP:// 0x1D - Six-Core Xeon 7400, "Dunnington", 45nm
178case CPU_MODEL_PENRYN:// 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
179if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
180value->word = 0x402;// 1026 - Xeon
181 return true;
182}
183 if (Platform.CPU.NoCores <= 2) {
184value->word = 0x301;// 769 - Core 2 Duo
185} else {
186 value->word = 0x402;// 1026 - Core 2 Quad as Xeon
187 }
188return true;
189
190case CPU_MODEL_LINCROFT:// 0x27 - Intel Atom, "Lincroft", 45nm
191case CPU_MODEL_ATOM:// 0x1C - Intel Atom (45nm)
192return true;
193
194case CPU_MODEL_NEHALEM_EX:// 0x2E - Nehalem-ex, "Beckton", 45nm
195case CPU_MODEL_NEHALEM:// 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
196case CPU_MODEL_FIELDS:// 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
197case CPU_MODEL_DALES:// 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
198 if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
199value->word = 0x501;// // 1281 - Lynnfiled Quad-Core Xeon
200 return true;
201}
202if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
203value->word = 0x901;// 2305 - Core i3
204 return true;
205}
206if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
207value->word = 0x601;// 1537 - Core i5
208 return true;
209}
210if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
211value->word = 0x701;// 1793 - Core i7
212 return true;
213}
214if (Platform.CPU.NoCores <= 2) {
215value->word = 0x901;// 1537 - Core i3
216}
217return true;
218
219case CPU_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
220 case CPU_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
221 case CPU_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
222 if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
223value->word = 0x501;// Xeon
224 return true;
225}
226if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
227value->word = 0x901;// Core i3
228 return true;
229}
230if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
231value->word = 0x602;// 1538 - Core i5
232 return true;
233}
234if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
235value->word = 0x702;// 1794 - Core i7
236 return true;
237}
238if (Platform.CPU.NoCores <= 2) {
239value->word = 0x901;// 1538 - Core i3
240}
241return true;
242
243case CPU_MODEL_JAKETOWN:// 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
244case CPU_MODEL_SANDYBRIDGE:// 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm)
245if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
246value->word = 0x501;// Xeon
247 return true;
248}
249if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
250value->word = 0x902;// 2306 - Core i3
251 return true;
252}
253if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
254value->word = 0x603;// 1539 - Core i5
255 return true;
256}
257if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
258value->word = 0x703;// 1795 - Core i7
259 return true;
260}
261if (Platform.CPU.NoCores <= 2) {
262value->word = 0x902;// 1539 - Core i3
263}
264return true;
265
266case CPU_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
267 if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
268value->word = 0xA01;// 2561 - Xeon
269 return true;
270}
271if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
272value->word = 0x903;// 2307 - Core i3 - Apple doesn't use it - but we yes:-)
273 return true;
274}
275if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
276value->word = 0x604;// 1540 - Core i5
277 return true;
278}
279if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
280value->word = 0x704;// 1796 - Core i7
281 return true;
282}
283if (Platform.CPU.NoCores <= 2) {
284value->word = 0x903;// 1540 - Core i3
285}
286return true;
287
288case CPU_MODEL_IVYBRIDGE_XEON:// 0x3E - Mac Pro 6,1
289value->word = 0xA01; // 2561 - Xeon
290return true;
291
292case CPU_MODEL_HASWELL:// 0x3C -
293case CPU_MODEL_HASWELL_SVR:// 0x3F -
294case CPU_MODEL_HASWELL_ULT:// 0x45 -
295case CPU_MODEL_CRYSTALWELL:// 0x46
296 if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
297value->word = 0xA01;// 2561 - Xeon
298 return true;
299}
300if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
301value->word = 0x904;// 2308 - Core i3 - Apple doesn't use it - but we yes:-)
302 return true;
303}
304if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
305value->word = 0x605;// 1541 - Core i5
306 return true;
307}
308if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
309value->word = 0x705;// 1797 - Core i7
310 return true;
311}
312if (Platform.CPU.NoCores <= 2) {
313value->word = 0x904;// 1541 - Core i3
314}
315return true;
316
317case 0x15: // EP80579 integrated processor
318value->word = 0x301;// 769
319return true;
320
321case 0x13: // Core i5, Xeon MP, "Havendale", "Auburndale", 45nm
322case 0x19: // Intel Core i5 650 @3.20 Ghz
323value->word = 0x601;// 1537 - Core i5
324return true;
325default:
326break; // Unsupported CPU type
327}
328}
329default:
330break;
331}
332}
333
334return false;
335}
336
337bool getSMBMemoryDeviceMemoryType(returnType *value)
338{
339static int idx = -1;
340intmap;
341
342 if (!bootInfo->memDetect) {
343return false;
344}
345
346idx++;
347if (idx < MAX_RAM_SLOTS) {
348map = Platform.DMI.DIMM[idx];
349if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {
350DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
351value->byte = Platform.RAM.DIMM[map].Type;
352return true;
353}
354}
355
356 value->byte = 2; // means Unknown
357return true;
358//value->byte = SMB_MEM_TYPE_DDR2;
359//return true;
360}
361
362bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
363{
364value->word = 0xFFFF;
365return true;
366}
367
368bool getSMBMemoryDeviceMemorySpeed(returnType *value)
369{
370static int idx = -1;
371intmap;
372
373 if (!bootInfo->memDetect) {
374return false;
375}
376
377idx++;
378if (idx < MAX_RAM_SLOTS) {
379map = Platform.DMI.DIMM[idx];
380if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {
381DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
382value->dword = Platform.RAM.DIMM[map].Frequency;
383return true;
384}
385}
386
387 value->dword = 0; // means Unknown
388return true;
389//value->dword = 800;
390//return true;
391}
392
393bool getSMBMemoryDeviceManufacturer(returnType *value)
394{
395static int idx = -1;
396intmap;
397
398 if (!bootInfo->memDetect) {
399return false;
400}
401
402idx++;
403if (idx < MAX_RAM_SLOTS) {
404map = Platform.DMI.DIMM[idx];
405if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) {
406DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
407value->string = Platform.RAM.DIMM[map].Vendor;
408return true;
409}
410}
411
412value->string = NOT_AVAILABLE;
413return true;
414}
415
416bool getSMBMemoryDeviceSerialNumber(returnType *value)
417{
418static int idx = -1;
419intmap;
420
421 if (!bootInfo->memDetect) {
422return false;
423}
424
425idx++;
426// DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
427if (idx < MAX_RAM_SLOTS) {
428map = Platform.DMI.DIMM[idx];
429if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
430DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
431value->string = Platform.RAM.DIMM[map].SerialNo;
432return true;
433}
434}
435
436value->string = NOT_AVAILABLE;
437return true;
438}
439
440bool getSMBMemoryDevicePartNumber(returnType *value)
441{
442static int idx = -1;
443intmap;
444
445 if (!bootInfo->memDetect) {
446return false;
447}
448
449idx++;
450if (idx < MAX_RAM_SLOTS) {
451map = Platform.DMI.DIMM[idx];
452if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
453DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
454value->string = Platform.RAM.DIMM[map].PartNo;
455return true;
456}
457}
458
459value->string = NOT_AVAILABLE;
460return true;
461}
462
463
464// getting smbios addr with fast compare ops, late checksum testing ...
465#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
466static const char * const SMTAG = "_SM_";
467static const char* const DMITAG = "_DMI_";
468
469SMBEntryPoint *getAddressOfSmbiosTable(void)
470{
471SMBEntryPoint*smbios;
472/*
473 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
474 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
475 */
476smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
477while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
478if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
479COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
480smbios->dmi.anchor[4] == DMITAG[4] &&
481checksum8(smbios, sizeof(SMBEntryPoint)) == 0) {
482return smbios;
483 }
484smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
485}
486printf("ERROR: Unable to find SMBIOS!\n");
487pause();
488return NULL;
489}
490
491

Archive Download this file

Revision: 2363