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

Archive Download this file

Revision: 2049