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

Archive Download this file

Revision: 2849