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

Archive Download this file

Revision: 2687