Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 851