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#include "bootstruct.h"
10
11#ifndef DEBUG_SMBIOS
12#define DEBUG_SMBIOS 0
13#endif
14
15#if DEBUG_SMBIOS
16#define DBG(x...)printf(x)
17#else
18#define DBG(x...)
19#endif
20
21
22bool getProcessorInformationExternalClock(returnType *value)
23{
24if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
25{
26switch (Platform.CPU.Family)
27{
28case 0x06:
29{
30switch (Platform.CPU.Model)
31{
32// set external clock to 0 for SANDY
33// removes FSB info from system profiler as on real mac's.
34case CPU_MODEL_SANDY_XEON:
35case CPU_MODEL_SANDY:
36value->word = 0;
37break;
38default:
39value->word = Platform.CPU.FSBFrequency/1000000;
40}
41}
42break;
43
44default:
45value->word = Platform.CPU.FSBFrequency/1000000;
46}
47}
48return true;
49}
50
51bool getProcessorInformationMaximumClock(returnType *value)
52{
53value->word = Platform.CPU.CPUFrequency/1000000;
54return true;
55}
56
57bool getSMBOemProcessorBusSpeed(returnType *value)
58{
59if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
60{
61switch (Platform.CPU.Family)
62{
63case 0x06:
64{
65switch (Platform.CPU.Model)
66{
67case CPU_MODEL_DOTHAN:// Intel Pentium M
68case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
69case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
70case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
71case CPU_MODEL_ATOM:// Intel Atom (45nm)
72return false;
73
74case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
75case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
76case CPU_MODEL_DALES:
77case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
78case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
79case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
80case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
81{
82// thanks to dgobe for i3/i5/i7 bus speed detection
83int nhm_bus = 0x3F;
84static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
85unsigned long did, vid;
86int i;
87
88// Nehalem supports Scrubbing
89// First, locate the PCI bus where the MCH is located
90for(i = 0; i < sizeof(possible_nhm_bus); i++)
91{
92vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
93did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
94vid &= 0xFFFF;
95did &= 0xFF00;
96
97if(vid == 0x8086 && did >= 0x2C00)
98nhm_bus = possible_nhm_bus[i];
99}
100
101unsigned long qpimult, qpibusspeed;
102qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
103qpimult &= 0x7F;
104DBG("qpimult %d\n", qpimult);
105qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000));
106// Rek: rounding decimals to match original mac profile info
107if (qpibusspeed%100 != 0)qpibusspeed = ((qpibusspeed+50)/100)*100;
108DBG("qpibusspeed %d\n", qpibusspeed);
109value->word = qpibusspeed;
110return true;
111}
112}
113}
114}
115}
116return false;
117}
118
119uint16_t simpleGetSMBOemProcessorType(void)
120{
121if (Platform.CPU.NoCores >= 4)
122{
123return 0x0501;// Quad-Core Xeon
124}
125else if (Platform.CPU.NoCores == 1)
126{
127return 0x0201;// Core Solo
128};
129
130return 0x0301;// Core 2 Duo
131}
132
133bool getSMBOemProcessorType(returnType *value)
134{
135static bool done = false;
136
137value->word = simpleGetSMBOemProcessorType();
138
139if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) // Intel
140{
141if (!done)
142{
143verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, Platform.CPU.Family, Platform.CPU.Model);
144done = true;
145}
146
147switch (Platform.CPU.Family)
148{
149case 0x06:
150{
151switch (Platform.CPU.Model)
152{
153case CPU_MODEL_DOTHAN:// Intel Pentium M
154case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
155case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
156case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
157case CPU_MODEL_ATOM:// Intel Atom (45nm)
158return true;
159
160case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
161if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
162value->word = 0x0501;// Xeon
163else
164value->word = 0x0701;// Core i7
165return true;
166
167case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
168if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
169value->word = 0x0601;// Core i5
170else
171value->word = 0x0701;// Core i7
172return true;
173
174case CPU_MODEL_DALES:
175if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
176value->word = 0x0601;// Core i5
177else
178value->word = 0x0701;// Core i7
179return true;
180
181case CPU_MODEL_SANDY:// Intel Core i3, i5, i7 LGA1155 (32nm)
182 case CPU_MODEL_SANDY_XEON:// Intel Xeon E3
183case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
184if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
185value->word = 0x0901;// Core i3
186else
187if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
188value->word = 0x0601;// Core i5
189else
190value->word = 0x0701;// Core i7
191return true;
192
193case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
194case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
195value->word = 0x0501;// Core i7
196return true;
197}
198}
199}
200}
201
202return false;
203}
204
205bool getSMBMemoryDeviceMemoryType(returnType *value)
206{
207static int idx = -1;
208intmap;
209
210idx++;
211if (idx < MAX_RAM_SLOTS)
212{
213map = Platform.DMI.DIMM[idx];
214if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
215{
216DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
217value->byte = Platform.RAM.DIMM[map].Type;
218return true;
219}
220}
221
222return false;
223//value->byte = SMB_MEM_TYPE_DDR2;
224//return true;
225}
226
227bool getSMBMemoryDeviceMemorySpeed(returnType *value)
228{
229static int idx = -1;
230intmap;
231
232idx++;
233if (idx < MAX_RAM_SLOTS)
234{
235map = Platform.DMI.DIMM[idx];
236if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
237{
238DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
239value->dword = Platform.RAM.DIMM[map].Frequency;
240return true;
241}
242}
243
244return false;
245//value->dword = 800;
246//return true;
247}
248
249bool getSMBMemoryDeviceManufacturer(returnType *value)
250{
251static int idx = -1;
252intmap;
253
254idx++;
255if (idx < MAX_RAM_SLOTS)
256{
257map = Platform.DMI.DIMM[idx];
258if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
259{
260DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
261value->string = Platform.RAM.DIMM[map].Vendor;
262return true;
263}
264}
265
266if (!bootInfo->memDetect)
267return false;
268value->string = NOT_AVAILABLE;
269return true;
270}
271
272bool getSMBMemoryDeviceSerialNumber(returnType *value)
273{
274static int idx = -1;
275intmap;
276
277idx++;
278
279 DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
280
281if (idx < MAX_RAM_SLOTS)
282{
283map = Platform.DMI.DIMM[idx];
284if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
285{
286DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
287value->string = Platform.RAM.DIMM[map].SerialNo;
288return true;
289}
290}
291
292if (!bootInfo->memDetect)
293return false;
294value->string = NOT_AVAILABLE;
295return true;
296}
297
298bool getSMBMemoryDevicePartNumber(returnType *value)
299{
300static int idx = -1;
301intmap;
302
303idx++;
304if (idx < MAX_RAM_SLOTS)
305{
306map = Platform.DMI.DIMM[idx];
307if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
308{
309DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
310value->string = Platform.RAM.DIMM[map].PartNo;
311return true;
312}
313}
314
315if (!bootInfo->memDetect)
316return false;
317value->string = NOT_AVAILABLE;
318return true;
319}
320
321
322// getting smbios addr with fast compare ops, late checksum testing ...
323#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
324static const char * const SMTAG = "_SM_";
325static const char* const DMITAG = "_DMI_";
326
327SMBEntryPoint *getAddressOfSmbiosTable(void)
328{
329SMBEntryPoint*smbios;
330/*
331 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
332 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
333 */
334smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
335while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
336if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
337COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
338smbios->dmi.anchor[4] == DMITAG[4] &&
339checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
340 {
341return smbios;
342 }
343smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
344}
345printf("ERROR: Unable to find SMBIOS!\n");
346pause();
347return NULL;
348}
349
350

Archive Download this file

Revision: 1495