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

Archive Download this file

Revision: 1918