Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2337