Chameleon

Chameleon Svn Source Tree

Root/branches/slice/trunkM/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...)verbose(x)
17#else
18#define DBG(x...)
19#endif
20
21//Slice - for ACPI patcher templates
22intModelLength = 0;
23charMacModel[8] = "MacBook";
24unsigned int ModelRev = 0x00010001;
25uint64_t smbios_p;
26char*gSMBIOSBoardModel;
27
28bool getProcessorInformationExternalClock(returnType *value)
29{
30value->word = Platform->CPU.FSBFrequency/1000000;
31return true;
32}
33
34bool getProcessorInformationMaximumClock(returnType *value)
35{
36value->word = Platform->CPU.CPUFrequency/1000000;
37return true;
38}
39
40bool getSMBOemProcessorBusSpeed(returnType *value)
41{
42value->word = 0;
43if (Platform->CPU.Vendor == 0x756E6547) // Intel
44{
45switch (Platform->CPU.Family)
46{
47case 0x06:
48{
49switch (Platform->CPU.Model)
50{
51case 0x0D:// ???
52case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
53case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
54case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
55case CPU_MODEL_ATOM:// Intel Atom (45nm)
56value->word = ((Platform->CPU.FSBFrequency * 4)/1000000); //Slice
57return true;
58
59case 0x19:// ??? Intel Core i5 650 @3.20 GHz
60case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
61case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
62case CPU_MODEL_DALES:
63case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
64case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
65case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
66case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
67case CPU_MODEL_SANDY:
68case CPU_MODEL_SANDY_XEON:
69{
70// thanks to dgobe for i3/i5/i7 bus speed detection
71int nhm_bus = 0x3F;
72static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
73unsigned long did, vid;
74int i;
75
76// Nehalem supports Scrubbing
77// First, locate the PCI bus where the MCH is located
78for(i = 0; i < sizeof(possible_nhm_bus); i++)
79{
80vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
81did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
82vid &= 0xFFFF;
83did &= 0xFF00;
84
85if(vid == 0x8086 && did >= 0x2C00)
86nhm_bus = possible_nhm_bus[i];
87}
88
89unsigned long qpimult, qpibusspeed;
90qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
91qpimult &= 0x7F;
92DBG("qpimult %d\n", qpimult);
93qpibusspeed = (qpimult * 2 * (Platform->CPU.FSBFrequency/1000000));
94// Rek: rounding decimals to match original mac profile info
95if (qpibusspeed%100 != 0)qpibusspeed = ((qpibusspeed+50)/100)*100;
96DBG("qpibusspeed %d\n", qpibusspeed);
97value->word = qpibusspeed;
98return true;
99}
100}
101}
102}
103}
104return false;
105}
106
107uint16_t simpleGetSMBOemProcessorType(void)
108{
109if (Platform->CPU.NoCores >= 4)
110{
111return 0x0501;// Quad-Core Xeon
112}
113else if (Platform->CPU.NoCores == 1)
114{
115return 0x0201;// Core Solo
116};
117
118return 0x0301;// Core 2 Duo
119}
120
121bool getSMBOemProcessorType(returnType *value)
122{
123static bool done = false;
124
125value->word = simpleGetSMBOemProcessorType();
126
127if (Platform->CPU.Vendor == 0x756E6547) // Intel
128{
129if (!done)
130{
131verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform->CPU.BrandString, Platform->CPU.Family, Platform->CPU.Model);
132done = true;
133}
134
135switch (Platform->CPU.Family)
136{
137case 0x06:
138{
139switch (Platform->CPU.Model)
140{
141case 0x0D:// ???
142case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
143case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
144case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
145case CPU_MODEL_ATOM:// Intel Atom (45nm)
146return true;
147
148case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
149if (strstr(Platform->CPU.BrandString, "Xeon(R)"))
150value->word = 0x0501;// Xeon
151else
152value->word = 0x0701;// Core i7
153
154return true;
155
156case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
157if (strstr(Platform->CPU.BrandString, "Core(TM) i5"))
158value->word = 0x0601;// Core i5
159else
160value->word = 0x0701;// Core i7
161return true;
162
163case CPU_MODEL_DALES:
164if (strstr(Platform->CPU.BrandString, "Core(TM) i5"))
165value->word = 0x0601;// Core i5
166else
167value->word = 0x0701;// Core i7
168return true;
169
170case CPU_MODEL_SANDY:// Intel Core i3, i5, i7 LGA1155 (32nm)
171 case CPU_MODEL_SANDY_XEON:// Intel Xeon E3
172case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
173if (strstr(Platform->CPU.BrandString, "Core(TM) i3"))
174value->word = 0x0901;// Core i3
175else
176if (strstr(Platform->CPU.BrandString, "Core(TM) i5"))
177value->word = 0x0601;// Core i5
178else
179value->word = 0x0701;// Core i7
180return true;
181
182case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
183case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
184value->word = 0x0501;// Core i7
185return true;
186
187case 0x19:// ??? Intel Core i5 650 @3.20 GHz
188value->word = 0x0601;// Core i5
189return true;
190}
191}
192}
193}
194
195return false;
196}
197
198bool getSMBMemoryDeviceMemoryType(returnType *value)
199{
200static int idx = -1;
201intmap;
202
203idx++;
204if (idx < MAX_RAM_SLOTS)
205{
206map = Platform->DMI.DIMM[idx];
207if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Type != 0)
208{
209DBG("RAM Detected Type = %d\n", Platform->RAM.DIMM[map].Type);
210value->byte = Platform->RAM.DIMM[map].Type;
211return true;
212}
213}
214
215return false;
216//value->byte = SMB_MEM_TYPE_DDR2;
217//return true;
218}
219
220bool getSMBMemoryDeviceMemorySpeed(returnType *value)
221{
222static int idx = -1;
223intmap;
224
225idx++;
226if (idx < MAX_RAM_SLOTS)
227{
228map = Platform->DMI.DIMM[idx];
229if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Frequency != 0)
230{
231DBG("RAM Detected Freq = %d Mhz\n", Platform->RAM.DIMM[map].Frequency);
232value->dword = Platform->RAM.DIMM[map].Frequency;
233return true;
234}
235}
236
237return false;
238//value->dword = 800;
239//return true;
240}
241
242bool getSMBMemoryDeviceManufacturer(returnType *value)
243{
244static int idx = -1;
245intmap;
246
247idx++;
248if (idx < MAX_RAM_SLOTS)
249{
250map = Platform->DMI.DIMM[idx];
251if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].Vendor) > 0)
252{
253DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform->RAM.DIMM[map].Vendor);
254value->string = Platform->RAM.DIMM[map].Vendor;
255return true;
256}
257}
258
259if (!bootInfo->memDetect)
260return false;
261value->string = NOT_AVAILABLE;
262return true;
263}
264
265bool getSMBMemoryDeviceSerialNumber(returnType *value)
266{
267static int idx = -1;
268intmap;
269
270idx++;
271
272 DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
273
274if (idx < MAX_RAM_SLOTS)
275{
276map = Platform->DMI.DIMM[idx];
277if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].SerialNo) > 0)
278{
279DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform->RAM.DIMM[map].SerialNo);
280value->string = Platform->RAM.DIMM[map].SerialNo;
281return true;
282}
283}
284
285if (!bootInfo->memDetect)
286return false;
287value->string = NOT_AVAILABLE;
288return true;
289}
290
291bool getSMBMemoryDevicePartNumber(returnType *value)
292{
293static int idx = -1;
294intmap;
295
296idx++;
297if (idx < MAX_RAM_SLOTS)
298{
299map = Platform->DMI.DIMM[idx];
300if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].PartNo) > 0)
301{
302DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform->RAM.DIMM[map].PartNo);
303value->string = Platform->RAM.DIMM[map].PartNo;
304return true;
305}
306}
307
308if (!bootInfo->memDetect)
309return false;
310value->string = NOT_AVAILABLE;
311return true;
312}
313
314
315// getting smbios addr with fast compare ops, late checksum testing ...
316#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
317static const char * const SMTAG = "_SM_";
318static const char* const DMITAG = "_DMI_";
319
320SMBEntryPoint *getAddressOfSmbiosTable(void)
321{
322SMBEntryPoint*smbios;
323/*
324 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
325 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
326 */
327smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
328while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
329if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
330COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
331smbios->dmi.anchor[4] == DMITAG[4] &&
332checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
333 {
334return smbios;
335 }
336smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
337}
338printf("ERROR: Unable to find SMBIOS!\n");
339pause();
340return NULL;
341}
342
343void getSmbiosMacModel(void)
344{
345#define MAX_MODEL_LEN32
346
347//Slice - I want to use MacModel for ACPITables so I need char* representation
348const char*value = getStringForKey("SMproductname", &bootInfo->smbiosConfig);
349int i, n=0, first=0, rev1=0, rev2=0;
350for (i=0; i<8; i++)
351{
352char c = value[i];
353if (isalpha(c))
354{
355MacModel[i]=c;
356n++;
357} else
358if ((c) >= '0' && (c) <= '9')
359{
360if (first)
361{
362rev1 = rev1 * 10 + (int)(c) & 0xf;
363} else
364rev2 = rev2 * 10 + (int)(c) & 0xf;
365} else
366first = 1;
367//printf("char=%c first=%d rev1=%d rev2=%d\n", c, first, rev1, rev2);
368}
369for (i=n; i<8; i++) {
370MacModel[i] = 0x20;
371}
372ModelRev = (rev2 << 16) + rev1;
373//ModelLength = (len + 1) * 2;
374//printf("Model=%s %08x\n", MacModel, ModelRev);
375//getc();
376
377}
378
379//static struct SMBEntryPoint *orig = NULL; // cached
380//static struct SMBEntryPoint *patched = NULL; // cached
381void getSmbiosProductName()
382{
383//struct SMBEntryPoint*smbios;
384SMBSystemInformation*p;
385char*tempString;
386inttmpLen;
387
388//smbios = getSmbios(SMBIOS_ORIGINAL);
389//if (smbios==NULL) return 0;
390
391p = (SMBSystemInformation*) FindFirstDmiTableOfType(1, 0x19); // Type 1: (3.3.2) System Information
392if (p==NULL) return; // NULL;
393
394tempString = (char*)smbiosStringAtIndex((SMBStructHeader*)p, p->productName, &tmpLen);
395tempString[tmpLen] = 0;
396
397gSMBIOSBoardModel = malloc(tmpLen + 1);
398if(gSMBIOSBoardModel)
399{
400strncpy(gSMBIOSBoardModel, tempString, tmpLen);
401Node* node = DT__FindNode("/", false);
402DT__AddProperty(node, "orig-model", tmpLen, gSMBIOSBoardModel);
403}
404verbose("Actual model name is '%s'\n", tempString);
405}
406
407const char * smbiosStringAtIndex(SMBStructHeader* smHeader, int index, int* length )
408{
409 const char * last = 0;
410 const char * next = (const char *) smHeader + smHeader->length;
411
412 if ( length ) *length = 0;
413 while ( index-- )
414 {
415 last = 0;
416const char * cp = 0;
417for ( cp = next; *cp || cp[1]; cp++ )
418 {
419 if ( *cp == '\0' )
420 {
421 last = next;
422 next = cp + 1;
423 break;
424 }
425 }
426 if ( last == 0 ) break;
427 }
428
429 if ( last )
430 {
431 while (*last == ' ') last++;
432 if (length)
433 {
434 UInt8 len;
435 for ( len = next - last - 1; len && last[len - 1] == ' '; len-- )
436 ;
437 *length = len; // number of chars not counting the terminating NULL
438 }
439 }
440
441 return last ? last : "";
442}
443
444//Slice
445//#define MEGA 1000000LL - now in platform.h
446void scan_cpu_DMI(void) //PlatformInfo_t *p)
447{
448// int i=0;
449int maxClock = 0;
450 SMBStructHeader * dmihdr = NULL;
451 SMBProcessorInformation* cpuInfo; // Type 4
452
453for (dmihdr = FindFirstDmiTableOfType(4, 30); dmihdr; dmihdr = FindNextDmiTableOfType(4, 30))
454{
455cpuInfo = (SMBProcessorInformation*)dmihdr;
456if (cpuInfo->processorType != 3) { // CPU
457continue;
458}
459//TODO validate
460#if DEBUG_SMBIOS
461msglog("Platform CPU Info:\n FSB=%d\n MaxSpeed=%d\n CurrentSpeed=%d\n", Platform->CPU.FSBFrequency/MEGA, Platform->CPU.TSCFrequency/MEGA, Platform->CPU.CPUFrequency/MEGA);
462
463if ((cpuInfo->externalClock) && (cpuInfo->externalClock < 400)) { //<400MHz
464Platform->CPU.FSBFrequency = (cpuInfo->externalClock) * MEGA;
465}
466maxClock = cpuInfo->maximumClock;
467if (cpuInfo->maximumClock < cpuInfo->currentClock) {
468maxClock = cpuInfo->currentClock;
469}
470if ((maxClock) && (maxClock < 10000)) { //<10GHz
471Platform->CPU.TSCFrequency = maxClock * MEGA;
472}
473if ((cpuInfo->currentClock) && (cpuInfo->currentClock < 10000)) { //<10GHz
474Platform->CPU.CPUFrequency = cpuInfo->currentClock * MEGA;
475}
476#endif
477maxClock = cpuInfo->maximumClock;
478msglog("DMI CPU Info:\n FSB=%d\n MaxSpeed=%d\n CurrentSpeed=%d\n", cpuInfo->externalClock, maxClock, cpuInfo->currentClock);
479msglog("DMI CPU Info 2:\n Family=%x\n Socket=%x\n Cores=%d Enabled=%d Threads=%d\n", cpuInfo->processorFamily, cpuInfo->processorUpgrade, cpuInfo->coreCount, cpuInfo->coreEnabled, cpuInfo->Threads);
480#if 1 //NOTYET
481if ((cpuInfo->coreCount) && (cpuInfo->coreCount<Platform->CPU.NoCores)) {
482if (cpuInfo->coreEnabled < cpuInfo->coreCount) {
483cpuInfo->coreCount = cpuInfo->coreEnabled;
484}
485Platform->CPU.NoCores = cpuInfo->coreCount;
486}
487if ((cpuInfo->Threads) && (cpuInfo->Threads<Platform->CPU.NoThreads)) {
488Platform->CPU.NoThreads = cpuInfo->Threads;
489}
490#endif
491
492return;
493}
494
495return;
496}
497

Archive Download this file

Revision: 1201