Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2131