Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2249