Chameleon

Chameleon Svn Source Tree

Root/trunk/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
52case CPU_MODEL_NEHALEM:// Intel Core i7 LGA1366 (45nm)
53case CPU_MODEL_FIELDS:// Intel Core i5, i7 LGA1156 (45nm)
54case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) ???
55case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm)
56case CPU_MODEL_WESTMERE:// Intel Core i7 LGA1366 (32nm) 6 Core
57case CPU_MODEL_NEHALEM_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
58case CPU_MODEL_WESTMERE_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
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:// Yonah
133case CPU_MODEL_MEROM:// Merom
134case CPU_MODEL_PENRYN:// Penryn
135case CPU_MODEL_ATOM:// Intel Atom (45nm)
136return true;
137
138case CPU_MODEL_NEHALEM:// Intel Core i7 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:// Lynnfield, Clarksfield, Jasper
147if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
148value->word = 0x601;// Core i5
149else
150value->word = 0x0701;// Core i7
151return true;
152
153case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
154if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
155value->word = 0x601;// Core i5
156else
157value->word = 0x0701;// Core i7
158return true;
159
160case CPU_MODEL_SANDY:// Intel Core i3, i5, i7 LGA1155 sandy bridge
161case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)
162if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
163value->word = 0x901;// Core i3
164else
165if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
166value->word = 0x601;// Core i5
167else
168value->word = 0x0701;// Core i7
169return true;
170
171case CPU_MODEL_WESTMERE:// Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS)
172case CPU_MODEL_WESTMERE_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
173value->word = 0x0501;// Core i7
174return true;
175
176case 0x19:// Intel Core i5 650 @3.20 Ghz
177value->word = 0x601;// Core i5
178return true;
179}
180}
181}
182}
183
184return false;
185}
186
187bool getSMBMemoryDeviceMemoryType(returnType *value)
188{
189static int idx = -1;
190intmap;
191
192idx++;
193if (idx < MAX_RAM_SLOTS)
194{
195map = Platform.DMI.DIMM[idx];
196if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
197{
198DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
199value->byte = Platform.RAM.DIMM[map].Type;
200return true;
201}
202}
203
204return false;
205//value->byte = SMB_MEM_TYPE_DDR2;
206//return true;
207}
208
209bool getSMBMemoryDeviceMemorySpeed(returnType *value)
210{
211static int idx = -1;
212intmap;
213
214idx++;
215if (idx < MAX_RAM_SLOTS)
216{
217map = Platform.DMI.DIMM[idx];
218if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
219{
220DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
221value->dword = Platform.RAM.DIMM[map].Frequency;
222return true;
223}
224}
225
226return false;
227//value->dword = 800;
228//return true;
229}
230
231bool getSMBMemoryDeviceManufacturer(returnType *value)
232{
233static int idx = -1;
234intmap;
235
236idx++;
237if (idx < MAX_RAM_SLOTS)
238{
239map = Platform.DMI.DIMM[idx];
240if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
241{
242DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
243value->string = Platform.RAM.DIMM[map].Vendor;
244return true;
245}
246}
247
248return false;
249//value->string = "N/A";
250//return true;
251}
252
253bool getSMBMemoryDeviceSerialNumber(returnType *value)
254{
255static int idx = -1;
256intmap;
257
258idx++;
259if (idx < MAX_RAM_SLOTS)
260{
261map = Platform.DMI.DIMM[idx];
262if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
263{
264DBG("name = %s, map=%d, RAM Detected SerialNo[%d]='%s'\n", name ? name : "",
265map, idx, Platform.RAM.DIMM[map].SerialNo);
266value->string = Platform.RAM.DIMM[map].SerialNo;
267return true;
268}
269}
270
271return false;
272//value->string = "N/A";
273//return true;
274}
275
276bool getSMBMemoryDevicePartNumber(returnType *value)
277{
278static int idx = -1;
279intmap;
280
281idx++;
282if (idx < MAX_RAM_SLOTS)
283{
284map = Platform.DMI.DIMM[idx];
285if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
286{
287DBG("Ram Detected PartNo[%d]='%s'\n", idx, Platform.RAM.DIMM[map].PartNo);
288value->string = Platform.RAM.DIMM[map].PartNo;
289return true;
290}
291}
292
293return false;
294//value->string = "N/A";
295//return 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: 827