Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2842