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

Archive Download this file

Revision: 2871