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

Archive Download this file

Revision: 2269