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

Archive Download this file

Revision: 2473