Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch_Modules/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_E5:
36case CPU_MODEL_IVYBRIDGE:
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_CLARKDALE:// 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)
114{
115qpibusspeed = ((qpibusspeed+50)/100)*100;
116}
117DBG("qpibusspeed %d\n", qpibusspeed);
118value->word = qpibusspeed;
119return true;
120}
121case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
122case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
123case CPU_MODEL_IVYBRIDGE_E5:
124case CPU_MODEL_HASWELL:
125case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
126{
127int busspeed;
128busspeed = 100;
129value->word = busspeed;
130return true;
131}
132}
133}
134}
135}
136return false;
137}
138
139uint16_t simpleGetSMBOemProcessorType(void)
140{
141if (Platform.CPU.NoCores >= 4)
142{
143return 0x0501;// Quad-Core Xeon
144}
145else if (Platform.CPU.NoCores == 1)
146{
147return 0x0201;// Core Solo
148};
149
150return 0x0301;// Core 2 Duo
151}
152
153bool getSMBOemProcessorType(returnType *value)
154{
155static bool done = false;
156
157value->word = simpleGetSMBOemProcessorType();
158
159if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
160{
161if (!done)
162{
163verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, Platform.CPU.Family, Platform.CPU.Model);
164done = true;
165}
166
167switch (Platform.CPU.Family)
168{
169case 0x06:
170{
171switch (Platform.CPU.Model)
172{
173case CPU_MODEL_DOTHAN:// Intel Pentium M
174case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
175case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
176case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
177case CPU_MODEL_ATOM:// Intel Atom (45nm)
178return true;
179
180case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
181case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
182case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
183case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
184if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
185{
186value->word = 0x0501;// Xeon
187}
188else
189{
190value->word = 0x0701;// Core i7
191}
192return true;
193
194case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
195if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
196{
197value->word = 0x0501;// Xeon
198}
199else
200{
201if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
202{
203value->word = 0x0601;// Core i5
204}
205else
206{
207value->word = 0x0701;// Core i7
208}
209}
210return true;
211
212case CPU_MODEL_DALES:
213if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
214{
215value->word = 0x0601;// Core i5
216}
217else
218{
219value->word = 0x0701;// Core i7
220}
221return true;
222
223case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7, Xeon E3-12xx LGA1155 (32nm)
224case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
225case CPU_MODEL_IVYBRIDGE_E5:
226case CPU_MODEL_CLARKDALE:// Intel Core i3, i5 LGA1156 (32nm)
227if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
228{
229value->word = 0x0501;// Xeon
230}
231else if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
232{
233value->word = 0x0901;// Core i3
234}
235else if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
236{
237value->word = 0x0601;// Core i5
238}
239else
240{
241value->word = 0x0701;// Core i7
242}
243return true;
244}
245}
246}
247}
248
249return false;
250}
251
252bool getSMBMemoryDeviceMemoryType(returnType *value)
253{
254static int idx = -1;
255intmap;
256
257idx++;
258if (idx < MAX_RAM_SLOTS)
259{
260map = Platform.DMI.DIMM[idx];
261if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
262{
263DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
264value->byte = Platform.RAM.DIMM[map].Type;
265return true;
266}
267}
268
269return false;
270//value->byte = SMB_MEM_TYPE_DDR2;
271//return true;
272}
273
274bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
275{
276 value->word = 0xFFFF;
277 return true;
278}
279
280bool getSMBMemoryDeviceMemorySpeed(returnType *value)
281{
282static int idx = -1;
283intmap;
284
285idx++;
286if (idx < MAX_RAM_SLOTS)
287{
288map = Platform.DMI.DIMM[idx];
289if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
290{
291DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
292value->dword = Platform.RAM.DIMM[map].Frequency;
293return true;
294}
295}
296
297return false;
298//value->dword = 800;
299//return true;
300}
301
302bool getSMBMemoryDeviceManufacturer(returnType *value)
303{
304static int idx = -1;
305intmap;
306
307idx++;
308if (idx < MAX_RAM_SLOTS)
309{
310map = Platform.DMI.DIMM[idx];
311if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
312{
313DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
314value->string = Platform.RAM.DIMM[map].Vendor;
315return true;
316}
317}
318
319if (!bootInfo->memDetect)
320{
321return false;
322}
323value->string = NOT_AVAILABLE;
324return true;
325}
326
327bool getSMBMemoryDeviceSerialNumber(returnType *value)
328{
329static int idx = -1;
330intmap;
331
332idx++;
333
334 DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
335
336if (idx < MAX_RAM_SLOTS)
337{
338map = Platform.DMI.DIMM[idx];
339if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
340{
341DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
342value->string = Platform.RAM.DIMM[map].SerialNo;
343return true;
344}
345}
346
347if (!bootInfo->memDetect)
348{
349return false;
350}
351value->string = NOT_AVAILABLE;
352return true;
353}
354
355bool getSMBMemoryDevicePartNumber(returnType *value)
356{
357static int idx = -1;
358intmap;
359
360idx++;
361if (idx < MAX_RAM_SLOTS)
362{
363map = Platform.DMI.DIMM[idx];
364if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
365{
366DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
367value->string = Platform.RAM.DIMM[map].PartNo;
368return true;
369}
370}
371
372if (!bootInfo->memDetect)
373{
374return false;
375}
376value->string = NOT_AVAILABLE;
377return true;
378}
379
380
381// getting smbios addr with fast compare ops, late checksum testing ...
382#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
383static const char * const SMTAG = "_SM_";
384static const char* const DMITAG = "_DMI_";
385
386SMBEntryPoint *getAddressOfSmbiosTable(void)
387{
388SMBEntryPoint*smbios;
389/*
390 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
391 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
392 */
393smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
394while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
395if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
396COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
397smbios->dmi.anchor[4] == DMITAG[4] &&
398checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
399 {
400return smbios;
401 }
402smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
403}
404printf("ERROR: Unable to find SMBIOS!\n");
405pause();
406return NULL;
407}
408
409

Archive Download this file

Revision: 2238