Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1985