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

Archive Download this file

Revision: 2456