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

Archive Download this file

Revision: 850