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 CPU_MODEL_SANDYBRIDGE:
35case CPU_MODEL_IVYBRIDGE_XEON:
36case CPU_MODEL_IVYBRIDGE:
37case CPU_MODEL_HASWELL:
38case CPU_MODEL_HASWELL_MB:
39case CPU_MODEL_HASWELL_ULT:
40case CPU_MODEL_CRYSTALWELL:
41
42value->word = 0;
43break;
44default:
45value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
46}
47}
48break;
49
50default:
51value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
52}
53}
54else
55{
56value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000);
57}
58
59return true;
60}
61
62bool getProcessorInformationMaximumClock(returnType *value)
63{
64value->word = (uint16_t)(Platform.CPU.CPUFrequency/1000000);
65return true;
66}
67
68bool getSMBOemProcessorBusSpeed(returnType *value)
69{
70if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
71{
72switch (Platform.CPU.Family)
73{
74case 0x06:
75{
76switch (Platform.CPU.Model)
77{
78case CPU_MODEL_PENTIUM_M:
79case CPU_MODEL_DOTHAN:// Intel Pentium M
80case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
81case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
82case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
83case CPU_MODEL_ATOM:// Intel Atom (45nm)
84return false;
85
86case 0x19:
87case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
88case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
89case CPU_MODEL_DALES:
90case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
91case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
92case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
93case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
94case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
95case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
96case CPU_MODEL_IVYBRIDGE_XEON:
97case CPU_MODEL_HASWELL:
98case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
99{
100// thanks to dgobe for i3/i5/i7 bus speed detection
101int nhm_bus = 0x3F;
102static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
103unsigned long did, vid;
104unsigned int i;
105
106// Nehalem supports Scrubbing
107// First, locate the PCI bus where the MCH is located
108for(i = 0; i < sizeof(possible_nhm_bus); i++)
109{
110vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
111did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
112vid &= 0xFFFF;
113did &= 0xFF00;
114
115if(vid == 0x8086 && did >= 0x2C00)
116nhm_bus = possible_nhm_bus[i];
117}
118
119unsigned long qpimult, qpibusspeed;
120qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
121qpimult &= 0x7F;
122DBG("qpimult %d\n", qpimult);
123qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000));
124// Rek: rounding decimals to match original mac profile info
125if (qpibusspeed%100 != 0)
126{
127qpibusspeed = ((qpibusspeed+50)/100)*100;
128}
129DBG("qpibusspeed %d\n", qpibusspeed);
130value->word = qpibusspeed;
131return true;
132}
133default:
134break; //Unsupported CPU type
135}
136}
137default:
138break;
139}
140}
141return false;
142}
143
144uint16_t simpleGetSMBOemProcessorType(void)
145{
146if (Platform.CPU.NoCores >= 4)
147{
148return 0x0501;// Quad-Core Xeon
149}
150else if (Platform.CPU.NoCores == 1)
151{
152return 0x0201;// Core Solo
153};
154
155return 0x0301;// Core 2 Duo
156}
157
158bool getSMBOemProcessorType(returnType *value)
159{
160static bool done = false;
161
162value->word = simpleGetSMBOemProcessorType();
163
164if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
165{
166if (!done)
167{
168verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model);
169done = true;
170}
171
172switch (Platform.CPU.Family)
173{
174case 0x06:
175{
176switch (Platform.CPU.Model)
177{
178case CPU_MODEL_PENTIUM_M:
179case CPU_MODEL_DOTHAN:// Intel Pentium M
180case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
181case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
182case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
183case CPU_MODEL_ATOM:// Intel Atom (45nm)
184return true;
185
186case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
187case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
188case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
189case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
190if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
191{
192value->word = 0x0501;// Xeon
193}
194if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
195{
196value->word = 0x0701;// Core i7
197}
198return true;
199
200case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
201if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
202{
203value->word = 0x501;// Xeon
204}
205if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
206{
207value->word = 0x601;// Core i5
208}
209if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
210{
211value->word = 0x701;// Core i7
212}
213
214return true;
215
216case CPU_MODEL_DALES:
217if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
218{
219value->word = 0x601;// Core i5
220}
221else
222{
223value->word = 0x0701;// Core i7
224}
225return true;
226
227case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
228case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
229case CPU_MODEL_IVYBRIDGE_XEON:
230case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
231case CPU_MODEL_HASWELL:
232case CPU_MODEL_HASWELL_MB:
233case CPU_MODEL_HASWELL_ULT:
234case CPU_MODEL_CRYSTALWELL:
235if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
236{
237value->word = 0x0501;// Xeon
238}
239if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
240{
241value->word = 0x901;// Core i3
242}
243if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
244{
245value->word = 0x601;// Core i5
246}
247if (strstr(Platform.CPU.BrandString, "Core(TM) i7"))
248{
249value->word = 0x0701;// Core i7
250}
251return true;
252
253
254case 0x19:// Intel Core i5 650 @3.20 Ghz
255value->word = 0x601;// Core i5
256return true;
257default:
258break; //Unsupported CPU type
259}
260}
261default:
262break;
263}
264}
265
266return false;
267}
268
269bool getSMBMemoryDeviceMemoryType(returnType *value)
270{
271static int idx = -1;
272intmap;
273
274idx++;
275if (idx < MAX_RAM_SLOTS)
276{
277map = Platform.DMI.DIMM[idx];
278if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
279{
280DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
281value->byte = Platform.RAM.DIMM[map].Type;
282return true;
283}
284}
285
286return false;
287//value->byte = SMB_MEM_TYPE_DDR2;
288//return true;
289}
290
291bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
292{
293value->word = 0xFFFF;
294return true;
295}
296
297bool getSMBMemoryDeviceMemorySpeed(returnType *value)
298{
299static int idx = -1;
300intmap;
301
302idx++;
303if (idx < MAX_RAM_SLOTS)
304{
305map = Platform.DMI.DIMM[idx];
306if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
307{
308DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
309value->dword = Platform.RAM.DIMM[map].Frequency;
310return true;
311}
312}
313
314return false;
315//value->dword = 800;
316//return true;
317}
318
319bool getSMBMemoryDeviceManufacturer(returnType *value)
320{
321static int idx = -1;
322intmap;
323
324idx++;
325if (idx < MAX_RAM_SLOTS)
326{
327map = Platform.DMI.DIMM[idx];
328if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
329{
330DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
331value->string = Platform.RAM.DIMM[map].Vendor;
332return true;
333}
334}
335
336if (!bootInfo->memDetect)
337{
338return false;
339}
340value->string = NOT_AVAILABLE;
341return true;
342}
343
344bool getSMBMemoryDeviceSerialNumber(returnType *value)
345{
346static int idx = -1;
347intmap;
348
349idx++;
350
351DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
352
353if (idx < MAX_RAM_SLOTS)
354{
355map = Platform.DMI.DIMM[idx];
356if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
357{
358DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
359value->string = Platform.RAM.DIMM[map].SerialNo;
360return true;
361}
362}
363
364if (!bootInfo->memDetect)
365{
366return false;
367}
368value->string = NOT_AVAILABLE;
369return true;
370}
371
372bool getSMBMemoryDevicePartNumber(returnType *value)
373{
374static int idx = -1;
375intmap;
376
377idx++;
378if (idx < MAX_RAM_SLOTS)
379{
380map = Platform.DMI.DIMM[idx];
381if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
382{
383DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
384value->string = Platform.RAM.DIMM[map].PartNo;
385return true;
386}
387}
388
389if (!bootInfo->memDetect)
390{
391return false;
392}
393value->string = NOT_AVAILABLE;
394return true;
395}
396
397
398// getting smbios addr with fast compare ops, late checksum testing ...
399#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
400static const char * const SMTAG = "_SM_";
401static const char* const DMITAG = "_DMI_";
402
403SMBEntryPoint *getAddressOfSmbiosTable(void)
404{
405SMBEntryPoint*smbios;
406/*
407 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
408 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
409 */
410smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
411while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
412if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
413COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
414smbios->dmi.anchor[4] == DMITAG[4] &&
415checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
416 {
417return smbios;
418 }
419smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
420}
421printf("ERROR: Unable to find SMBIOS!\n");
422pause();
423return NULL;
424}
425
426

Archive Download this file

Revision: 2285