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
129value->word = simpleGetSMBOemProcessorType();
130
131if (Platform.CPU.Vendor == 0x756E6547) // Intel
132{
133if (!done)
134{
135verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, Platform.CPU.Family, Platform.CPU.Model);
136done = true;
137}
138
139switch (Platform.CPU.Family)
140{
141case 0x06:
142{
143switch (Platform.CPU.Model)
144{
145case 0x0D:// ?
146case CPU_MODEL_YONAH:// Yonah
147case CPU_MODEL_MEROM:// Merom
148case CPU_MODEL_PENRYN:// Penryn
149case CPU_MODEL_ATOM:// Intel Atom (45nm)
150return true;
151
152case CPU_MODEL_NEHALEM:// Intel Core i7 LGA1366 (45nm)
153value->word = 0x0701;// Core i7
154return true;
155
156case CPU_MODEL_FIELDS:// Lynnfield, Clarksfield, Jasper
157if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
158value->word = 0x601;// Core i5
159else
160value->word = 0x701;// Core i7
161return true;
162
163case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
164if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
165value->word = 0x601;// Core i5
166else
167value->word = 0x0701;// Core i7
168return true;
169
170case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)
171if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
172value->word = 0x901;// Core i3
173else
174if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
175value->word = 0x601;// Core i5
176else
177value->word = 0x0701;// Core i7
178return true;
179
180case CPU_MODEL_WESTMERE:// Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS)
181case CPU_MODEL_WESTMERE_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
182value->word = 0x0701;// Core i7
183return true;
184
185case 0x19:// Intel Core i5 650 @3.20 Ghz
186value->word = 0x601;// Core i5
187return true;
188}
189}
190}
191}
192
193return false;
194}
195
196bool getSMBMemoryDeviceMemoryType(returnType *value)
197{
198static int idx = -1;
199intmap;
200
201idx++;
202if (idx < MAX_RAM_SLOTS)
203{
204map = Platform.DMI.DIMM[idx];
205if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
206{
207DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
208value->byte = Platform.RAM.DIMM[map].Type;
209return true;
210}
211}
212
213return false;
214//value->byte = SMB_MEM_TYPE_DDR2;
215//return true;
216}
217
218bool getSMBMemoryDeviceMemorySpeed(returnType *value)
219{
220static int idx = -1;
221intmap;
222
223idx++;
224if (idx < MAX_RAM_SLOTS)
225{
226map = Platform.DMI.DIMM[idx];
227if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
228{
229DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
230value->dword = Platform.RAM.DIMM[map].Frequency;
231return true;
232}
233}
234
235return false;
236//value->dword = 800;
237//return true;
238}
239
240bool getSMBMemoryDeviceManufacturer(returnType *value)
241{
242static int idx = -1;
243intmap;
244
245idx++;
246if (idx < MAX_RAM_SLOTS)
247{
248map = Platform.DMI.DIMM[idx];
249if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
250{
251DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
252value->string = Platform.RAM.DIMM[map].Vendor;
253return true;
254}
255}
256
257return false;
258//value->string = "N/A";
259//return true;
260}
261
262bool getSMBMemoryDeviceSerialNumber(returnType *value)
263{
264static int idx = -1;
265intmap;
266
267idx++;
268if (idx < MAX_RAM_SLOTS)
269{
270map = Platform.DMI.DIMM[idx];
271if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
272{
273DBG("name = %s, map=%d, RAM Detected SerialNo[%d]='%s'\n", name ? name : "",
274map, idx, Platform.RAM.DIMM[map].SerialNo);
275value->string = Platform.RAM.DIMM[map].SerialNo;
276return true;
277}
278}
279
280return false;
281//value->string = "N/A";
282//return true;
283}
284
285bool getSMBMemoryDevicePartNumber(returnType *value)
286{
287static int idx = -1;
288intmap;
289
290idx++;
291if (idx < MAX_RAM_SLOTS)
292{
293map = Platform.DMI.DIMM[idx];
294if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
295{
296DBG("Ram Detected PartNo[%d]='%s'\n", idx, Platform.RAM.DIMM[map].PartNo);
297value->string = Platform.RAM.DIMM[map].PartNo;
298return true;
299}
300}
301
302return false;
303//value->string = "N/A";
304//return true;
305}
306
307
308// getting smbios addr with fast compare ops, late checksum testing ...
309#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
310static const char * const SMTAG = "_SM_";
311static const char* const DMITAG = "_DMI_";
312
313SMBEntryPoint *getAddressOfSmbiosTable(void)
314{
315SMBEntryPoint*smbios;
316/*
317 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
318 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
319 */
320smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
321while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
322if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
323COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
324smbios->dmi.anchor[4] == DMITAG[4] &&
325checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
326 {
327return smbios;
328 }
329smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
330}
331printf("ERROR: Unable to find SMBIOS!\n");
332pause();
333return NULL;
334}
335
336

Archive Download this file

Revision: 585