Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/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 CPUID_MODEL_SANDYBRIDGE:
33case CPUID_MODEL_JAKETOWN:
34case CPUID_MODEL_IVYBRIDGE_XEON:
35case CPUID_MODEL_IVYBRIDGE:
36case CPUID_MODEL_HASWELL:
37case CPUID_MODEL_HASWELL_SVR:
38case CPUID_MODEL_HASWELL_ULT:
39case CPUID_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
68{
69switch (Platform.CPU.Family)
70{
71case 0x06:
72{
73switch (Platform.CPU.Model)
74{
75case CPUID_MODEL_PENTIUM_M:
76case CPUID_MODEL_DOTHAN:// Intel Pentium M
77case CPUID_MODEL_YONAH:// Intel Mobile Core Solo, Duo
78case CPUID_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
79case CPUID_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
80case CPUID_MODEL_ATOM:// Intel Atom (45nm)
81return false;
82
83case 0x19:
84case CPUID_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
85case CPUID_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
86case CPUID_MODEL_DALES:
87case CPUID_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
88case CPUID_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
89case CPUID_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
90case CPUID_MODEL_WESTMERE_EX:// Intel Xeon E7
91case CPUID_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
92case CPUID_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
93case CPUID_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
94case CPUID_MODEL_IVYBRIDGE_XEON:
95case CPUID_MODEL_HASWELL:
96{
97// thanks to dgobe for i3/i5/i7 bus speed detection
98int nhm_bus = 0x3F;
99static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
100unsigned long did, vid;
101unsigned int i;
102
103// Nehalem supports Scrubbing
104// First, locate the PCI bus where the MCH is located
105for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) {
106vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
107did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
108vid &= 0xFFFF;
109did &= 0xFF00;
110
111if(vid == 0x8086 && did >= 0x2C00) {
112nhm_bus = possible_nhm_bus[i];
113}
114}
115
116unsigned long qpimult, qpibusspeed;
117qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
118qpimult &= 0x7F;
119DBG("qpimult %d\n", qpimult);
120qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000LL));
121// Rek: rounding decimals to match original mac profile info
122if (qpibusspeed%100 != 0) {
123qpibusspeed = ((qpibusspeed+50)/100)*100;
124}
125DBG("qpibusspeed %d\n", qpibusspeed);
126value->word = qpibusspeed;
127return true;
128}
129default:
130break; //Unsupported CPU type
131}
132}
133default:
134break;
135}
136}
137return false;
138}
139
140uint16_t simpleGetSMBOemProcessorType(void)
141{
142if (Platform.CPU.NoCores >= 4) {
143return 0x501;// 1281 - Quad-Core Xeon
144} else if (Platform.CPU.NoCores == 1) {
145return 0x201;// 513 - Core Duo
146};
147
148return 0x301;// 769 - Core 2 Duo
149}
150
151bool getSMBOemProcessorType(returnType *value)
152{
153static bool done = false;
154
155value->word = simpleGetSMBOemProcessorType();
156
157if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
158if (!done) {
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, needs testing
163switch (Platform.CPU.Family) {
164case 0x0F:
165case 0x06:
166{
167switch (Platform.CPU.Model)
168{
169case CPUID_MODEL_PENTIUM_M:
170case CPUID_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
171case CPUID_MODEL_PRESCOTT:
172case CPUID_MODEL_NOCONA:
173if (strstr(Platform.CPU.BrandString, "Xeon"))
174{
175value->word = 0x402;// 1026 - Xeon
176}
177return true;
178
179case CPUID_MODEL_PRESLER:
180case CPUID_MODEL_CELERON:
181case CPUID_MODEL_YONAH:// 0x0E - Intel Mobile Core Solo, Duo
182value->word = 0x201;// 513
183return true;
184
185case CPUID_MODEL_MEROM:// 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
186case CPUID_MODEL_XEON_MP:// 0x1D - Six-Core Xeon 7400, "Dunnington", 45nm
187case CPUID_MODEL_PENRYN:// 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
188if (strstr(Platform.CPU.BrandString, "Xeon"))
189{
190value->word = 0x402;// 1026 - Xeon
191return true;
192}
193if (Platform.CPU.NoCores <= 2) {
194value->word = 0x301;// 769 - Core 2 Duo
195} else {
196value->word = 0x402;// 1026 - Core 2 Quad as Xeon
197}
198return true;
199
200case CPUID_MODEL_LINCROFT:// 0x27 - Intel Atom, "Lincroft", 45nm
201case CPUID_MODEL_ATOM:// 0x1C - Intel Atom (45nm)
202return true;
203
204case CPUID_MODEL_NEHALEM_EX:// 0x2E - Nehalem-ex, "Beckton", 45nm
205case CPUID_MODEL_NEHALEM:// 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
206case CPUID_MODEL_FIELDS:// 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
207case CPUID_MODEL_DALES:// 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
208if (strstr(Platform.CPU.BrandString, "Xeon"))
209{
210value->word = 0x501;// 1281 - Lynnfiled Quad-Core Xeon
211return true;
212}
213if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
214value->word = 0x901;// 2305 - Core i3
215return true;
216}
217if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
218value->word = 0x601;// Core i5
219return true;
220}
221if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
222value->word = 0x701;// 1793 - Core i7
223return true;
224}
225if (Platform.CPU.NoCores <= 2) {
226value->word = 0x901;// - Core i3
227}
228return true;
229
230case CPUID_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
231case CPUID_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
232case CPUID_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
233if (strstr(Platform.CPU.BrandString, "Xeon"))
234{
235value->word = 0x501;// 1281 - Xeon
236return true;
237}
238if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
239value->word = 0x901;// 2305 - Core i3
240return true;
241}
242if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
243value->word = 0x602;// 1538 - Core i5
244return true;
245}
246if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
247value->word = 0x702;// 1794 -Core i7
248return true;
249}
250if (Platform.CPU.NoCores <= 2) {
251value->word = 0x901;// - Core i3
252}
253return true;
254
255case CPUID_MODEL_JAKETOWN:// 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
256case CPUID_MODEL_SANDYBRIDGE:// 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm)
257if (strstr(Platform.CPU.BrandString, "Xeon"))
258{
259value->word = 0x501;// 1281 - Xeon
260return true;
261}
262if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
263value->word = 0x902;// 2306 -Core i3
264return true;
265}
266if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
267value->word = 0x603;// 1539 - Core i5
268return true;
269}
270if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
271value->word = 0x703;// 1795 - Core i7
272return true;
273}
274if (Platform.CPU.NoCores <= 2) {
275value->word = 0x902;// - Core i5
276}
277return true;
278
279case CPUID_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
280if (strstr(Platform.CPU.BrandString, "Xeon"))
281{
282value->word = 0xA01;// 2561 - Xeon
283return true;
284}
285if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
286value->word = 0x903;// 2307 - Core i3 - Apple doesn't use it
287return true;
288}
289if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
290value->word = 0x604;// 1540 - Core i5
291return true;
292}
293if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
294value->word = 0x704;// 1796 - Core i7
295return true;
296}
297if (Platform.CPU.NoCores <= 2) {
298value->word = 0x903;// - Core i5
299}
300return true;
301
302case CPUID_MODEL_IVYBRIDGE_XEON:// 0x3E - Mac Pro 6,1
303value->word = 0xA01;// 2561 - Xeon
304return true;
305
306case CPUID_MODEL_HASWELL:// 0x3C -
307case CPUID_MODEL_HASWELL_SVR:// 0x3F -
308case CPUID_MODEL_HASWELL_ULT:// 0x45 -
309case CPUID_MODEL_CRYSTALWELL:// 0x46
310if (strstr(Platform.CPU.BrandString, "Xeon"))
311{
312value->word = 0xA01;// 2561 - Xeon
313return true;
314}
315if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
316value->word = 0x904;// 2308 - Core i3 - Apple doesn't use it - but we yes:-)
317return true;
318}
319if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
320value->word = 0x605;// 1541 - Core i5
321return true;
322}
323if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
324value->word = 0x705;// 1797 - Core i7
325return true;
326}
327if (Platform.CPU.NoCores <= 2) {
328value->word = 0x904;// - Core i3
329}
330return true;
331
332case 0x15:// EP80579 integrated processor
333value->word = 0x301;// 769
334return true;
335
336case 0x13:// Core i5, Xeon MP, "Havendale", "Auburndale", 45nm
337case 0x19:// Intel Core i5 650 @3.20 Ghz
338value->word = 0x601;// 1537 - Core i5
339return true;
340default:
341break; //Unsupported CPU type
342}
343}
344default:
345break;
346}
347}
348
349return false;
350}
351
352bool getSMBMemoryDeviceMemoryType(returnType *value)
353{
354static int idx = -1;
355intmap;
356
357if (!bootInfo->memDetect) {
358return false;
359}
360
361idx++;
362if (idx < MAX_RAM_SLOTS) {
363map = Platform.DMI.DIMM[idx];
364if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {
365DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
366value->byte = Platform.RAM.DIMM[map].Type;
367return true;
368}
369}
370
371value->byte = 2; // means Unknown
372return true;
373//value->byte = SMB_MEM_TYPE_DDR2;
374//return true;
375}
376
377bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
378{
379value->word = 0xFFFF;
380return true;
381}
382
383bool getSMBMemoryDeviceMemorySpeed(returnType *value)
384{
385static int idx = -1;
386intmap;
387
388if (!bootInfo->memDetect) {
389return false;
390}
391
392idx++;
393if (idx < MAX_RAM_SLOTS) {
394map = Platform.DMI.DIMM[idx];
395if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {
396DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
397value->dword = Platform.RAM.DIMM[map].Frequency;
398return true;
399}
400}
401
402value->dword = 0; // means Unknown
403return true;
404//value->dword = 800;
405//return true;
406}
407
408bool getSMBMemoryDeviceManufacturer(returnType *value)
409{
410static int idx = -1;
411intmap;
412
413if (!bootInfo->memDetect) {
414return false;
415}
416
417idx++;
418if (idx < MAX_RAM_SLOTS) {
419map = Platform.DMI.DIMM[idx];
420if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) {
421DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
422value->string = Platform.RAM.DIMM[map].Vendor;
423return true;
424}
425}
426
427value->string = NOT_AVAILABLE;
428return true;
429}
430
431bool getSMBMemoryDeviceSerialNumber(returnType *value)
432{
433static int idx = -1;
434intmap;
435
436if (!bootInfo->memDetect) {
437return false;
438}
439
440idx++;
441
442//DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
443
444if (idx < MAX_RAM_SLOTS) {
445map = Platform.DMI.DIMM[idx];
446if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
447DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
448value->string = Platform.RAM.DIMM[map].SerialNo;
449return true;
450}
451}
452
453value->string = NOT_AVAILABLE;
454return true;
455}
456
457bool getSMBMemoryDevicePartNumber(returnType *value)
458{
459static int idx = -1;
460intmap;
461
462if (!bootInfo->memDetect) {
463return false;
464}
465
466idx++;
467if (idx < MAX_RAM_SLOTS) {
468map = Platform.DMI.DIMM[idx];
469if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
470DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
471value->string = Platform.RAM.DIMM[map].PartNo;
472return true;
473}
474}
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: 2470