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

Archive Download this file

Revision: 2537