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

Archive Download this file

Revision: 2483