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

Archive Download this file

Revision: 594