Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 436