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
25switch (Platform.CPU.Family) {
26case 0x06:
27{
28switch (Platform.CPU.Model)
29{
30// set external clock to 0 for SANDY
31// removes FSB info from system profiler as on real mac's.
32case CPU_MODEL_SANDYBRIDGE:
33case CPU_MODEL_IVYBRIDGE_XEON:
34case CPU_MODEL_IVYBRIDGE:
35case CPU_MODEL_HASWELL:
36case CPU_MODEL_HASWELL_SVR:
37case CPU_MODEL_HASWELL_ULT:
38case CPU_MODEL_CRYSTALWELL:
39
40value->word = 0;
41break;
42default:
43value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
44}
45}
46break;
47
48default:
49value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
50}
51} else {
52value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
53}
54
55return true;
56}
57
58bool getProcessorInformationMaximumClock(returnType *value)
59{
60value->word = (uint16_t)(Platform.CPU.CPUFrequency/1000000LL);
61return true;
62}
63
64bool getSMBOemProcessorBusSpeed(returnType *value)
65{
66if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
67switch (Platform.CPU.Family) {
68case 0x06:
69{
70switch (Platform.CPU.Model) {
71case CPU_MODEL_PENTIUM_M:
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 0x19:
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_DALES_32NM:// 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
87case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
88case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
89case CPU_MODEL_IVYBRIDGE_XEON:
90case CPU_MODEL_HASWELL:
91case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
92{
93// thanks to dgobe for i3/i5/i7 bus speed detection
94int nhm_bus = 0x3F;
95static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
96unsigned long did, vid;
97unsigned int i;
98
99// Nehalem supports Scrubbing
100// First, locate the PCI bus where the MCH is located
101for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) {
102vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
103did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
104vid &= 0xFFFF;
105did &= 0xFF00;
106
107if(vid == 0x8086 && did >= 0x2C00) {
108nhm_bus = possible_nhm_bus[i];
109}
110}
111
112unsigned long qpimult, qpibusspeed;
113qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
114qpimult &= 0x7F;
115DBG("qpimult %d\n", qpimult);
116qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000LL));
117// Rek: rounding decimals to match original mac profile info
118if (qpibusspeed%100 != 0) {
119qpibusspeed = ((qpibusspeed+50)/100)*100;
120}
121DBG("qpibusspeed %d\n", qpibusspeed);
122value->word = qpibusspeed;
123return true;
124}
125default:
126break; //Unsupported CPU type
127}
128}
129default:
130break;
131}
132}
133return false;
134}
135
136uint16_t simpleGetSMBOemProcessorType(void)
137{
138if (Platform.CPU.NoCores >= 4) {
139return 0x501;// 1281 - Quad-Core Xeon
140} else if (Platform.CPU.NoCores == 1) {
141return 0x201;// 513 - Core Solo
142};
143
144return 0x301;// 769 - Core 2 Duo
145}
146
147bool getSMBOemProcessorType(returnType *value)
148{
149static bool done = false;
150
151value->word = simpleGetSMBOemProcessorType();
152
153if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
154if (!done) {
155verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model);
156done = true;
157}
158// Bungo: fixes Oem Processor Type - better matching IMHO
159switch (Platform.CPU.Family) {
160case 0x06:
161{
162switch (Platform.CPU.Model) {
163
164case CPU_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
165value->word = 0x101;// 257
166return true;
167
168case CPU_MODEL_YONAH:// 0x0E - Intel Mobile Core Solo, Duo
169case CPU_MODEL_CELERON:
170value->word = 0x201;// 513
171return true;
172
173case CPU_MODEL_XEON_MP:// 0x1D - Six-Core Xeon 7400, "Dunnington", 45nm
174value->word = 0x401;// 1025
175return true;
176
177case CPU_MODEL_MEROM:// 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
178case CPU_MODEL_PENRYN:// 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
179if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
180value->word = 0x402;// 1026 - Xeon
181}
182case CPU_MODEL_PENTIUM_M:// 0x09 - Banias
183case CPU_MODEL_LINCROFT:// 0x27 - Intel Atom, "Lincroft", 45nm
184case CPU_MODEL_ATOM:// 0x1C - Intel Atom (45nm)
185return true;
186
187case CPU_MODEL_NEHALEM_EX:// 0x2E - Nehalem-ex, "Beckton", 45nm
188case CPU_MODEL_NEHALEM:// 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
189case CPU_MODEL_FIELDS:// 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
190case CPU_MODEL_DALES:// 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
191if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
192value->word = 0x501;// 1281 - Lynnfiled Quad-Core Xeon
193return true;
194}
195if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
196value->word = 0x901;// 2305 - Core i3
197return true;
198}
199if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
200value->word = 0x601;// Core i5
201return true;
202}
203if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
204value->word = 0x701;// 1793 - Core i7
205return true;
206}
207if (Platform.CPU.NoCores <= 2) {
208value->word = 0x601;// 1537 - Core i5
209}
210return true;
211
212case CPU_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
213case CPU_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
214case CPU_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
215if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
216value->word = 0x501;// 1281 - Xeon
217return true;
218}
219if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
220value->word = 0x901;// 2305 - Core i3
221return true;
222}
223if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
224value->word = 0x602;// 1538 - Core i5
225return true;
226}
227if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
228value->word = 0x702;// 1794 -Core i7
229return true;
230}
231if (Platform.CPU.NoCores <= 2) {
232value->word = 0x602;// 1538 - Core i5
233}
234return true;
235
236case CPU_MODEL_JAKETOWN:// 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
237case CPU_MODEL_SANDYBRIDGE:// 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm)
238if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
239value->word = 0x501;// 1281 - Xeon
240return true;
241}
242if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
243value->word = 0x902;// 2306 -Core i3
244return true;
245}
246if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
247value->word = 0x603;// 1539 - Core i5
248return true;
249}
250if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
251value->word = 0x703;// 1795 - Core i7
252return true;
253}
254if (Platform.CPU.NoCores <= 2) {
255value->word = 0x603;// 1539 - Core i5
256}
257return true;
258
259case CPU_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
260if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
261value->word = 0xA01;// 2561 - Xeon
262return true;
263}
264if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
265value->word = 0x903;// 2307 - Core i3 - Apple doesn't use it
266return true;
267}
268if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
269value->word = 0x604;// 1540 - Core i5
270return true;
271}
272if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
273value->word = 0x704;// 1796 - Core i7
274return true;
275}
276if (Platform.CPU.NoCores <= 2) {
277value->word = 0x604;// 1540 - Core i5
278}
279return true;
280
281case CPU_MODEL_IVYBRIDGE_XEON:// 0x3E - Mac Pro 6,1
282value->word = 0xA01;// 2561
283return true;
284
285case CPU_MODEL_HASWELL:// 0x3C -
286case CPU_MODEL_HASWELL_SVR:// 0x3F -
287case CPU_MODEL_HASWELL_ULT:// 0x45 -
288case CPU_MODEL_CRYSTALWELL:// 0x46
289if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
290value->word = 0xA01;// 2561 - Xeon
291return true;
292}
293if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
294value->word = 0x904;// 2308 - Core i3 - Apple doesn't use it - but we yes:-)
295return true;
296}
297if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
298value->word = 0x605;// 1541 - Core i5
299return true;
300}
301if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
302value->word = 0x705;// 1797 - Core i7
303return true;
304}
305if (Platform.CPU.NoCores <= 2) {
306value->word = 0x605;// 1541 - Core i5
307}
308return true;
309
310case 0x15:// EP80579 integrated processor
311value->word = 0x301;// 769
312return true;
313
314case 0x13:// Core i5, Xeon MP, "Havendale", "Auburndale", 45nm
315case 0x19:// Intel Core i5 650 @3.20 Ghz
316value->word = 0x601;// 1537 - Core i5
317return true;
318default:
319break; //Unsupported CPU type
320}
321}
322default:
323break;
324}
325}
326
327return false;
328}
329
330bool getSMBMemoryDeviceMemoryType(returnType *value)
331{
332static int idx = -1;
333intmap;
334
335idx++;
336if (idx < MAX_RAM_SLOTS) {
337map = Platform.DMI.DIMM[idx];
338if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {
339DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
340value->byte = Platform.RAM.DIMM[map].Type;
341return true;
342}
343}
344
345return false;
346//value->byte = SMB_MEM_TYPE_DDR2;
347//return true;
348}
349
350bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
351{
352value->word = 0xFFFF;
353return true;
354}
355
356bool getSMBMemoryDeviceMemorySpeed(returnType *value)
357{
358static int idx = -1;
359intmap;
360
361idx++;
362if (idx < MAX_RAM_SLOTS) {
363map = Platform.DMI.DIMM[idx];
364if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {
365DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
366value->dword = Platform.RAM.DIMM[map].Frequency;
367return true;
368}
369}
370
371return false;
372//value->dword = 800;
373//return true;
374}
375
376bool getSMBMemoryDeviceManufacturer(returnType *value)
377{
378static int idx = -1;
379intmap;
380
381idx++;
382if (idx < MAX_RAM_SLOTS) {
383map = Platform.DMI.DIMM[idx];
384if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) {
385DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
386value->string = Platform.RAM.DIMM[map].Vendor;
387return true;
388}
389}
390
391if (!bootInfo->memDetect) {
392return false;
393}
394value->string = NOT_AVAILABLE;
395return true;
396}
397
398bool getSMBMemoryDeviceSerialNumber(returnType *value)
399{
400static int idx = -1;
401intmap;
402
403idx++;
404
405DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
406
407if (idx < MAX_RAM_SLOTS) {
408map = Platform.DMI.DIMM[idx];
409if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
410DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
411value->string = Platform.RAM.DIMM[map].SerialNo;
412return true;
413}
414}
415
416if (!bootInfo->memDetect) {
417return false;
418}
419value->string = NOT_AVAILABLE;
420return true;
421}
422
423bool getSMBMemoryDevicePartNumber(returnType *value)
424{
425static int idx = -1;
426intmap;
427
428idx++;
429if (idx < MAX_RAM_SLOTS) {
430map = Platform.DMI.DIMM[idx];
431if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
432DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
433value->string = Platform.RAM.DIMM[map].PartNo;
434return true;
435}
436}
437
438if (!bootInfo->memDetect) {
439return false;
440}
441value->string = NOT_AVAILABLE;
442return true;
443}
444
445
446// getting smbios addr with fast compare ops, late checksum testing ...
447#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
448static const char * const SMTAG = "_SM_";
449static const char* const DMITAG = "_DMI_";
450
451SMBEntryPoint *getAddressOfSmbiosTable(void)
452{
453SMBEntryPoint*smbios;
454/*
455 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
456 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
457 */
458smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
459while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
460if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
461COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
462smbios->dmi.anchor[4] == DMITAG[4] &&
463checksum8(smbios, sizeof(SMBEntryPoint)) == 0) {
464return smbios;
465 }
466smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
467}
468printf("ERROR: Unable to find SMBIOS!\n");
469pause();
470return NULL;
471}
472
473

Archive Download this file

Revision: 2361