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

Archive Download this file

Revision: 2542