Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1040