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

Archive Download this file

Revision: 2379