Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2658