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#define XEON "Xeon"
22#define CORE_I3 "Core(TM) i3"
23#define CORE_I5 "Core(TM) i5"
24#define CORE_I7 "Core(TM) i7"
25
26bool getProcessorInformationExternalClock(returnType *value)
27{
28if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
29{
30switch (Platform.CPU.Family)
31{
32case 0x06:
33switch (Platform.CPU.Model)
34{
35// set external clock to 0 for SANDY
36// removes FSB info from system profiler as on real mac's.
37case CPUID_MODEL_SANDYBRIDGE:
38case CPUID_MODEL_JAKETOWN:
39case CPUID_MODEL_IVYBRIDGE_EP:
40case CPUID_MODEL_IVYBRIDGE:
41case CPUID_MODEL_HASWELL:
42case CPUID_MODEL_HASWELL_SVR:
43case CPUID_MODEL_HASWELL_ULT:
44case CPUID_MODEL_CRYSTALWELL:
45
46value->word = 0;
47break;
48default:
49value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
50break;
51}
52break;
53
54default:
55value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
56break;
57}
58}
59else
60{
61value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
62}
63
64return true;
65}
66
67bool getProcessorInformationMaximumClock(returnType *value)
68{
69value->word = (uint16_t)(Platform.CPU.CPUFrequency/1000000LL);
70return true;
71}
72
73bool getSMBOemProcessorBusSpeed(returnType *value)
74{
75if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
76{
77switch (Platform.CPU.Family)
78{
79case 0x06:
80switch (Platform.CPU.Model)
81{
82 /*
83case CPUID_MODEL_PENTIUM_M:
84case CPUID_MODEL_DOTHAN:// Intel Pentium M
85case CPUID_MODEL_YONAH:// Intel Mobile Core Solo, Duo
86case CPUID_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
87case CPUID_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
88case CPUID_MODEL_ATOM:// Intel Atom (45nm)
89return false;
90 */
91case 0x19:
92case CPUID_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
93case CPUID_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
94case CPUID_MODEL_DALES:
95case CPUID_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
96case CPUID_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
97case CPUID_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
98case CPUID_MODEL_WESTMERE_EX:// Intel Xeon E7
99case CPUID_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
100case CPUID_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
101case CPUID_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
102case CPUID_MODEL_IVYBRIDGE_EP:
103case CPUID_MODEL_HASWELL:
104{
105// thanks to dgobe for i3/i5/i7 bus speed detection
106int nhm_bus = 0x3F;
107static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
108unsigned long did, vid;
109unsigned int i;
110
111// Nehalem supports Scrubbing
112// First, locate the PCI bus where the MCH is located
113for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++)
114{
115vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
116did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
117vid &= 0xFFFF;
118did &= 0xFF00;
119
120if(vid == 0x8086 && did >= 0x2C00)
121{
122nhm_bus = possible_nhm_bus[i];
123}
124}
125
126unsigned long qpimult, qpibusspeed;
127qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
128qpimult &= 0x7F;
129verbose("qpimult %d\n", qpimult);
130qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000LL));
131// Rek: rounding decimals to match original mac profile info
132if (qpibusspeed%100 != 0)
133{
134qpibusspeed = ((qpibusspeed+50)/100)*100;
135}
136verbose("qpibusspeed %d\n", qpibusspeed);
137value->word = qpibusspeed;
138return true;
139}
140break;
141
142default:
143break;
144}
145break;
146
147default:
148break;
149}
150}
151
152return false; //Unsupported CPU type
153}
154
155uint16_t simpleGetSMBOemProcessorType(void)
156{
157if (Platform.CPU.NoCores >= 4)
158{
159return 0x402;// 1026 - Quad-Core Xeon
160}
161else if (Platform.CPU.NoCores == 2)
162{
163return 0x301;// 513 - Core 2 Duo
164}
165
166return 0x201;// 769 - Core Duo
167}
168
169bool getSMBOemProcessorType(returnType *value)
170{
171static bool done = false;
172
173value->word = simpleGetSMBOemProcessorType();
174
175if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
176{
177if (!done)
178{
179//DBG("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model);
180done = true;
181}
182// Bungo: fixes Oem Processor Type - better matching IMHO, needs testing
183switch (Platform.CPU.Family)
184{
185case 0x06:
186case 0x0F:
187switch (Platform.CPU.Model)
188{
189case CPUID_MODEL_PENTIUM_M:
190case CPUID_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
191case CPUID_MODEL_NOCONA:
192case CPUID_MODEL_IRWINDALE:
193if (strstr(Platform.CPU.BrandString, "Xeon"))
194{
195value->word = 0x402;// 1026 - Xeon
196}
197return true;
198
199case CPUID_MODEL_PRESLER:
200case CPUID_MODEL_CELERON:
201case CPUID_MODEL_YONAH:// 0x0E - Intel Mobile Core Solo, Duo
202value->word = 0x201;// 513
203return true;
204
205case CPUID_MODEL_MEROM:// 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
206case CPUID_MODEL_XEON_MP:// 0x1D - Six-Core Xeon 7400, "Dunnington", 45nm
207case CPUID_MODEL_PENRYN:// 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
208if (strstr(Platform.CPU.BrandString, XEON))
209{
210value->word = 0x402;// 1026 - Xeon
211return true;
212}
213if (Platform.CPU.NoCores <= 2)
214{
215value->word = 0x301;// 769 - Core 2 Duo , Pentium Dual Core etc.
216}
217else
218{
219value->word = 0x402;// 1026 - Core 2 Quad as Xeon
220}
221return true;
222
223case CPUID_MODEL_LINCROFT:// 0x27 - Intel Atom, "Lincroft", 45nm
224case CPUID_MODEL_ATOM:// 0x1C - Intel Atom (45nm)
225return true;
226
227case CPUID_MODEL_NEHALEM_EX:// 0x2E - Nehalem-ex, "Beckton", 45nm
228case CPUID_MODEL_NEHALEM:// 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
229case CPUID_MODEL_FIELDS:// 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
230case CPUID_MODEL_DALES:// 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
231if (strstr(Platform.CPU.BrandString, XEON))
232{
233value->word = 0x501;// 1281 - Lynnfiled Quad-Core Xeon
234return true;
235}
236if (strstr(Platform.CPU.BrandString, CORE_I3))
237{
238value->word = 0x901;// 2305 - Core i3
239return true;
240}
241if (strstr(Platform.CPU.BrandString, CORE_I5))
242{
243value->word = 0x601;// Core i5
244return true;
245}
246if (strstr(Platform.CPU.BrandString, CORE_I7))
247{
248value->word = 0x701;// 1793 - Core i7
249return true;
250}
251if (Platform.CPU.NoCores <= 2)
252{
253value->word = 0x901;// - Pentium Dual Core as Core i3
254}
255return true;
256
257case CPUID_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
258case CPUID_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
259case CPUID_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
260if (strstr(Platform.CPU.BrandString, XEON))
261{
262value->word = 0x501;// 1281 - Xeon
263return true;
264}
265if (strstr(Platform.CPU.BrandString, CORE_I3))
266{
267value->word = 0x901;// 2305 - Core i3
268return true;
269}
270if (strstr(Platform.CPU.BrandString, CORE_I5))
271{
272value->word = 0x602;// 1538 - Core i5
273return true;
274}
275if (strstr(Platform.CPU.BrandString, CORE_I7))
276{
277value->word = 0x702;// 1794 -Core i7
278return true;
279}
280if (Platform.CPU.NoCores <= 2)
281{
282value->word = 0x901;// - Pentium Dual Core as Core i3
283}
284return true;
285
286case CPUID_MODEL_JAKETOWN:// 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
287case CPUID_MODEL_SANDYBRIDGE:// 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm)
288if (strstr(Platform.CPU.BrandString, XEON))
289{
290value->word = 0x501;// 1281 - Xeon
291return true;
292}
293if (strstr(Platform.CPU.BrandString, CORE_I3))
294{
295value->word = 0x902;// 2306 -Core i3
296return true;
297}
298if (strstr(Platform.CPU.BrandString, CORE_I5))
299{
300value->word = 0x603;// 1539 - Core i5
301return true;
302}
303if (strstr(Platform.CPU.BrandString, CORE_I7))
304{
305value->word = 0x703;// 1795 - Core i7
306return true;
307}
308if (Platform.CPU.NoCores <= 2)
309{
310value->word = 0x902;// - Pentium Dual Core as Core i3
311}
312return true;
313
314case CPUID_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
315if (strstr(Platform.CPU.BrandString, XEON))
316{
317value->word = 0xA01;// 2561 - Xeon
318return true;
319}
320if (strstr(Platform.CPU.BrandString, CORE_I3))
321{
322value->word = 0x903;// 2307 - Core i3 - Apple doesn't use it
323return true;
324}
325if (strstr(Platform.CPU.BrandString, CORE_I5))
326{
327value->word = 0x604;// 1540 - Core i5
328return true;
329}
330if (strstr(Platform.CPU.BrandString, CORE_I7))
331{
332value->word = 0x704;// 1796 - Core i7
333return true;
334}
335if (Platform.CPU.NoCores <= 2)
336{
337value->word = 0x903;// - Pentium Dual Core as Core i3
338}
339return true;
340
341case CPUID_MODEL_IVYBRIDGE_EP:// 0x3E - Mac Pro 6,1
342value->word = 0xA01;// 2561 - Xeon
343return true;
344
345case CPUID_MODEL_HASWELL:// 0x3C -
346case CPUID_MODEL_HASWELL_SVR:// 0x3F -
347case CPUID_MODEL_HASWELL_ULT:// 0x45 -
348case CPUID_MODEL_CRYSTALWELL:// 0x46
349if (strstr(Platform.CPU.BrandString, XEON))
350{
351value->word = 0xA01;// 2561 - Xeon
352return true;
353}
354if (strstr(Platform.CPU.BrandString, CORE_I3))
355{
356value->word = 0x904;// 2308 - Core i3 - Apple doesn't use it - but we yes:-)
357return true;
358}
359if (strstr(Platform.CPU.BrandString, CORE_I5))
360{
361value->word = 0x605;// 1541 - Core i5
362return true;
363}
364if (strstr(Platform.CPU.BrandString, CORE_I7))
365{
366value->word = 0x705;// 1797 - Core i7
367return true;
368}
369if (Platform.CPU.NoCores <= 2)
370{
371value->word = 0x904;// - Pentium Dual Core as Core i3
372}
373return true;
374
375case 0x15:// EP80579 integrated processor
376value->word = 0x301;// 769
377return true;
378
379case 0x13:// Core i5, Xeon MP, "Havendale", "Auburndale", 45nm
380case 0x19:// Intel Core i5 650 @3.20 Ghz
381value->word = 0x601;// 1537 - Core i5
382return true;
383default:
384break; // Unsupported CPU type
385}
386break;
387
388default:
389break;
390}
391}
392
393return false;
394}
395
396bool getSMBMemoryDeviceMemoryType(returnType *value)
397{
398static int idx = -1;
399intmap;
400
401if (!bootInfo->memDetect)
402{
403return false;
404}
405
406idx++;
407if (idx < MAX_RAM_SLOTS)
408{
409map = Platform.DMI.DIMM[idx];
410if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
411{
412verbose("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
413value->byte = Platform.RAM.DIMM[map].Type;
414return true;
415}
416}
417
418value->byte = 2; // means Unknown
419return true;
420//value->byte = SMB_MEM_TYPE_DDR2;
421//return true;
422}
423
424bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
425{
426value->word = 0xFFFF;
427return true;
428}
429
430bool getSMBMemoryDeviceMemorySpeed(returnType *value)
431{
432static int idx = -1;
433intmap;
434
435if (!bootInfo->memDetect)
436{
437return false;
438}
439
440idx++;
441if (idx < MAX_RAM_SLOTS)
442{
443map = Platform.DMI.DIMM[idx];
444if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
445{
446verbose("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
447value->dword = Platform.RAM.DIMM[map].Frequency;
448return true;
449}
450}
451
452value->dword = 0; // means Unknown
453return true;
454//value->dword = 800;
455//return true;
456}
457
458bool getSMBMemoryDeviceManufacturer(returnType *value)
459{
460static int idx = -1;
461intmap;
462
463if (!bootInfo->memDetect)
464{
465return false;
466}
467
468idx++;
469if (idx < MAX_RAM_SLOTS)
470{
471map = Platform.DMI.DIMM[idx];
472if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
473{
474verbose("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
475value->string = Platform.RAM.DIMM[map].Vendor;
476return true;
477}
478}
479
480value->string = NOT_AVAILABLE;
481return true;
482}
483
484bool getSMBMemoryDeviceSerialNumber(returnType *value)
485{
486static int idx = -1;
487intmap;
488
489if (!bootInfo->memDetect)
490{
491return false;
492}
493
494idx++;
495
496//DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
497
498if (idx < MAX_RAM_SLOTS)
499{
500map = Platform.DMI.DIMM[idx];
501if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
502{
503verbose("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
504value->string = Platform.RAM.DIMM[map].SerialNo;
505return true;
506}
507}
508
509value->string = NOT_AVAILABLE;
510return true;
511}
512
513bool getSMBMemoryDevicePartNumber(returnType *value)
514{
515static int idx = -1;
516intmap;
517
518if (!bootInfo->memDetect)
519{
520return false;
521}
522
523idx++;
524if (idx < MAX_RAM_SLOTS)
525{
526map = Platform.DMI.DIMM[idx];
527if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
528{
529verbose("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
530value->string = Platform.RAM.DIMM[map].PartNo;
531return true;
532}
533}
534
535value->string = NOT_AVAILABLE;
536return true;
537}
538
539
540// getting smbios addr with fast compare ops, late checksum testing ...
541#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
542static const char * const SMTAG = "_SM_";
543static const char* const DMITAG = "_DMI_";
544
545SMBEntryPoint *getAddressOfSmbiosTable(void)
546{
547SMBEntryPoint*smbios;
548/*
549 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
550 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
551 */
552smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
553while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END)
554{
555if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
556COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
557smbios->dmi.anchor[4] == DMITAG[4] &&
558checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
559{
560return smbios;
561 }
562smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
563}
564error("ERROR: Unable to find SMBIOS!\n");
565pause("");
566return NULL;
567}
568
569

Archive Download this file

Revision: 2839