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/MEGA;
31return true;
32}
33
34bool getProcessorInformationMaximumClock(returnType *value)
35{
36value->word = Platform->CPU.CPUFrequency/MEGA;
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 CPU_MODEL_PENTIUM_M:// Dotah
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) Clarkdale
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 CPU_MODEL_PENTIUM_M:// Dothan
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{
209msglog("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{
222//Slice - do not use SPD value for memory speed. DMI has real value.
223//return false;
224static int idx = -1;
225intmap;
226idx++;
227if (idx < MAX_RAM_SLOTS)
228{
229map = Platform->DMI.DIMM[idx];
230if (Platform->RAM.DIMM[map].InUse && Platform->RAM.DIMM[map].Frequency != 0)
231{
232msglog("RAM Detected Freq = %d Mhz\n", Platform->RAM.DIMM[map].Frequency);
233value->dword = Platform->RAM.DIMM[map].Frequency;
234return true;
235}
236}
237
238return false;
239//value->dword = 800;
240//return true;
241}
242
243bool getSMBMemoryDeviceManufacturer(returnType *value)
244{
245static int idx = -1;
246intmap;
247
248idx++;
249if (idx < MAX_RAM_SLOTS)
250{
251map = Platform->DMI.DIMM[idx];
252if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].Vendor) > 0)
253{
254DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform->RAM.DIMM[map].Vendor);
255value->string = Platform->RAM.DIMM[map].Vendor;
256return true;
257}
258}
259
260if (!bootInfo->memDetect)
261return false;
262value->string = NOT_AVAILABLE;
263return true;
264}
265
266bool getSMBMemoryDeviceSerialNumber(returnType *value)
267{
268static int idx = -1;
269intmap;
270
271idx++;
272
273 DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
274
275if (idx < MAX_RAM_SLOTS)
276{
277map = Platform->DMI.DIMM[idx];
278if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].SerialNo) > 0)
279{
280DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform->RAM.DIMM[map].SerialNo);
281value->string = Platform->RAM.DIMM[map].SerialNo;
282return true;
283}
284}
285
286if (!bootInfo->memDetect)
287return false;
288value->string = NOT_AVAILABLE;
289return true;
290}
291
292bool getSMBMemoryDevicePartNumber(returnType *value)
293{
294static int idx = -1;
295intmap;
296
297idx++;
298if (idx < MAX_RAM_SLOTS)
299{
300map = Platform->DMI.DIMM[idx];
301if (Platform->RAM.DIMM[map].InUse && strlen(Platform->RAM.DIMM[map].PartNo) > 0)
302{
303DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform->RAM.DIMM[map].PartNo);
304value->string = Platform->RAM.DIMM[map].PartNo;
305return true;
306}
307}
308
309if (!bootInfo->memDetect)
310return false;
311value->string = NOT_AVAILABLE;
312return true;
313}
314
315
316// getting smbios addr with fast compare ops, late checksum testing ...
317#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
318static const char * const SMTAG = "_SM_";
319static const char* const DMITAG = "_DMI_";
320
321SMBEntryPoint *getAddressOfSmbiosTable(void)
322{
323SMBEntryPoint*smbios;
324/*
325 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
326 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
327 */
328smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
329while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
330if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
331COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
332smbios->dmi.anchor[4] == DMITAG[4] &&
333checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
334 {
335return smbios;
336 }
337smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
338}
339printf("ERROR: Unable to find SMBIOS!\n");
340pause();
341return NULL;
342}
343
344void getSmbiosMacModel(void)
345{
346#define MAX_MODEL_LEN32
347
348//Slice - I want to use MacModel for ACPITables so I need char* representation
349const char*value = getStringForKey("SMproductname", &bootInfo->smbiosConfig);
350int i, n=0, first=0, rev1=0, rev2=0;
351for (i=0; i<8; i++)
352{
353char c = value[i];
354if (isalpha(c))
355{
356MacModel[i]=c;
357n++;
358} else
359if ((c) >= '0' && (c) <= '9')
360{
361if (first)
362{
363rev1 = rev1 * 10 + (int)(c) & 0xf;
364} else
365rev2 = rev2 * 10 + (int)(c) & 0xf;
366} else
367first = 1;
368//printf("char=%c first=%d rev1=%d rev2=%d\n", c, first, rev1, rev2);
369}
370for (i=n; i<8; i++) {
371MacModel[i] = 0x20;
372}
373ModelRev = (rev2 << 16) + rev1;
374//ModelLength = (len + 1) * 2;
375//printf("Model=%s %08x\n", MacModel, ModelRev);
376//getc();
377
378}
379
380//static struct SMBEntryPoint *orig = NULL; // cached
381//static struct SMBEntryPoint *patched = NULL; // cached
382void getSmbiosProductName()
383{
384//struct SMBEntryPoint*smbios;
385SMBSystemInformation*p;
386char*tempString;
387inttmpLen;
388
389//smbios = getSmbios(SMBIOS_ORIGINAL);
390//if (smbios==NULL) return 0;
391
392p = (SMBSystemInformation*) FindFirstDmiTableOfType(1, 0x19); // Type 1: (3.3.2) System Information
393if (p==NULL) return; // NULL;
394
395tempString = (char*)smbiosStringAtIndex((SMBStructHeader*)p, p->productName, &tmpLen);
396tempString[tmpLen] = 0;
397
398gSMBIOSBoardModel = malloc(tmpLen + 1);
399if(gSMBIOSBoardModel)
400{
401strncpy(gSMBIOSBoardModel, tempString, tmpLen);
402Node* node = DT__FindNode("/", false);
403DT__AddProperty(node, "orig-model", tmpLen, gSMBIOSBoardModel);
404}
405verbose("Actual model name is '%s'\n", tempString);
406}
407
408const char * smbiosStringAtIndex(SMBStructHeader* smHeader, int index, int* length )
409{
410 const char * last = 0;
411 const char * next = (const char *) smHeader + smHeader->length;
412
413 if ( length ) *length = 0;
414 while ( index-- )
415 {
416 last = 0;
417const char * cp = 0;
418for ( cp = next; *cp || cp[1]; cp++ )
419 {
420 if ( *cp == '\0' )
421 {
422 last = next;
423 next = cp + 1;
424 break;
425 }
426 }
427 if ( last == 0 ) break;
428 }
429
430 if ( last )
431 {
432 while (*last == ' ') last++;
433 if (length)
434 {
435 UInt8 len;
436 for ( len = next - last - 1; len && last[len - 1] == ' '; len-- )
437 ;
438 *length = len; // number of chars not counting the terminating NULL
439 }
440 }
441
442 return last ? last : "";
443}
444
445//Slice
446//#define MEGA 1000000LL - now in platform.h
447void scan_cpu_DMI(void) //PlatformInfo_t *p)
448{
449// int i=0;
450int maxClock = 0;
451 SMBStructHeader * dmihdr = NULL;
452 SMBProcessorInformation* cpuInfo; // Type 4
453
454for (dmihdr = FindFirstDmiTableOfType(4, 30); dmihdr; dmihdr = FindNextDmiTableOfType(4, 30))
455{
456cpuInfo = (SMBProcessorInformation*)dmihdr;
457if (cpuInfo->processorType != 3) { // CPU
458continue;
459}
460//TODO validate
461#if DEBUG_SMBIOS
462msglog("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);
463
464if ((cpuInfo->externalClock) && (cpuInfo->externalClock < 400)) { //<400MHz
465Platform->CPU.FSBFrequency = (cpuInfo->externalClock) * MEGA;
466}
467maxClock = cpuInfo->maximumClock;
468if (cpuInfo->maximumClock < cpuInfo->currentClock) {
469maxClock = cpuInfo->currentClock;
470}
471if ((maxClock) && (maxClock < 10000)) { //<10GHz
472Platform->CPU.TSCFrequency = maxClock * MEGA;
473}
474if ((cpuInfo->currentClock) && (cpuInfo->currentClock < 10000)) { //<10GHz
475Platform->CPU.CPUFrequency = cpuInfo->currentClock * MEGA;
476}
477#endif
478maxClock = cpuInfo->maximumClock;
479Platform->CPU.CPUFrequency = cpuInfo->currentClock * MEGA;
480msglog("DMI CPU Info:\n FSB=%d\n MaxSpeed=%d\n CurrentSpeed=%d\n", cpuInfo->externalClock, maxClock, cpuInfo->currentClock);
481msglog("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);
482#if 1 //NOTYET
483if ((cpuInfo->coreCount) && (cpuInfo->coreCount<Platform->CPU.NoCores)) {
484if (cpuInfo->coreEnabled < cpuInfo->coreCount) {
485cpuInfo->coreCount = cpuInfo->coreEnabled;
486}
487Platform->CPU.NoCores = cpuInfo->coreCount;
488}
489if ((cpuInfo->Threads) && (cpuInfo->Threads<Platform->CPU.NoThreads)) {
490Platform->CPU.NoThreads = cpuInfo->Threads;
491}
492#endif
493
494return;
495}
496
497return;
498}
499

Archive Download this file

Revision: 1290