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

Archive Download this file

Revision: 2253