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...)msglog(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 0x501;// 1281 - Quad-Core Xeon
141} else if (Platform.CPU.NoCores == 1) {
142return 0x201;// 513 - Core Duo
143};
144
145return 0x301;// 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) {
156//DBG("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) {
161case 0x0F:
162case 0x06:
163{
164switch (Platform.CPU.Model) {
165case CPU_MODEL_PENTIUM_M:
166case CPU_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
167case CPU_MODEL_PRESCOTT:
168case CPU_MODEL_NOCONA:
169if (strstr(Platform.CPU.BrandString, "Xeon")) {
170value->word = 0x402;// 1026 - Xeon
171}
172return true;
173
174case CPU_MODEL_PRESLER:
175case CPU_MODEL_CELERON:
176case 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
181case 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}
187if (Platform.CPU.NoCores <= 2) {
188value->word = 0x301;// 769 - Core 2 Duo , Pentium Dual Core etc.
189} else {
190value->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)
202if (strstr(Platform.CPU.BrandString, "Xeon")) {
203value->word = 0x501;// 1281 - Lynnfiled Quad-Core Xeon
204return true;
205}
206if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
207value->word = 0x901;// 2305 - Core i3
208return true;
209}
210if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
211value->word = 0x601;// Core i5
212return true;
213}
214if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
215value->word = 0x701;// 1793 - Core i7
216return true;
217}
218if (Platform.CPU.NoCores <= 2) {
219value->word = 0x901;// - Pentium Dual Core as Core i3
220}
221return true;
222
223case CPU_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
224case CPU_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
225case CPU_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
226if (strstr(Platform.CPU.BrandString, "Xeon")) {
227value->word = 0x501;// 1281 - Xeon
228return true;
229}
230if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
231value->word = 0x901;// 2305 - Core i3
232return true;
233}
234if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
235value->word = 0x602;// 1538 - Core i5
236return true;
237}
238if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
239value->word = 0x702;// 1794 -Core i7
240return true;
241}
242if (Platform.CPU.NoCores <= 2) {
243value->word = 0x901;// - Pentium Dual Core as 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;// 1281 - Xeon
251return true;
252}
253if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
254value->word = 0x902;// 2306 -Core i3
255return true;
256}
257if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
258value->word = 0x603;// 1539 - Core i5
259return true;
260}
261if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
262value->word = 0x703;// 1795 - Core i7
263return true;
264}
265if (Platform.CPU.NoCores <= 2) {
266value->word = 0x902;// - Pentium Dual Core as Core i3
267}
268return true;
269
270case CPU_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
271if (strstr(Platform.CPU.BrandString, "Xeon")) {
272value->word = 0xA01;// 2561 - Xeon
273return true;
274}
275if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
276value->word = 0x903;// 2307 - Core i3 - Apple doesn't use it
277return true;
278}
279if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
280value->word = 0x604;// 1540 - Core i5
281return true;
282}
283if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
284value->word = 0x704;// 1796 - Core i7
285return true;
286}
287if (Platform.CPU.NoCores <= 2) {
288value->word = 0x903;// - Pentium Dual Core as 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
300if (strstr(Platform.CPU.BrandString, "Xeon")) {
301value->word = 0xA01;// 2561 - Xeon
302return true;
303}
304if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
305value->word = 0x904;// 2308 - Core i3 - Apple doesn't use it - but we yes:-)
306return true;
307}
308if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
309value->word = 0x605;// 1541 - Core i5
310return true;
311}
312if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
313value->word = 0x705;// 1797 - Core i7
314return true;
315}
316if (Platform.CPU.NoCores <= 2) {
317value->word = 0x904;// - Pentium Dual Core as 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
346if (!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
360value->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
377if (!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
391value->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
402if (!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
425if (!bootInfo->memDetect) {
426return false;
427}
428
429idx++;
430
431//DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
432
433if (idx < MAX_RAM_SLOTS) {
434map = Platform.DMI.DIMM[idx];
435if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
436DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
437value->string = Platform.RAM.DIMM[map].SerialNo;
438return true;
439}
440}
441
442value->string = NOT_AVAILABLE;
443return true;
444}
445
446bool getSMBMemoryDevicePartNumber(returnType *value)
447{
448static int idx = -1;
449intmap;
450
451if (!bootInfo->memDetect) {
452return false;
453}
454
455idx++;
456if (idx < MAX_RAM_SLOTS) {
457map = Platform.DMI.DIMM[idx];
458if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
459DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
460value->string = Platform.RAM.DIMM[map].PartNo;
461return true;
462}
463}
464
465value->string = NOT_AVAILABLE;
466return true;
467}
468
469
470// getting smbios addr with fast compare ops, late checksum testing ...
471#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
472static const char * const SMTAG = "_SM_";
473static const char* const DMITAG = "_DMI_";
474
475SMBEntryPoint *getAddressOfSmbiosTable(void)
476{
477SMBEntryPoint*smbios;
478/*
479 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
480 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
481 */
482smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
483while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
484if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
485COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
486smbios->dmi.anchor[4] == DMITAG[4] &&
487checksum8(smbios, sizeof(SMBEntryPoint)) == 0) {
488return smbios;
489 }
490smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
491}
492DBG("ERROR: Unable to find SMBIOS!\n");
493pause();
494return NULL;
495}
496
497

Archive Download this file

Revision: 2469