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// removes FSB info from system profiler as on real mac's.
31 // sets external clock to 0
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
87//case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm) // MacMan removed not valid for this CPU
88//case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm) // MacMan removed not valid for this CPU
89//case CPU_MODEL_IVYBRIDGE_XEON: // MacMan moved
90//case CPU_MODEL_HASWELL: // MacMan removed not valid for this CPU
91//case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)// MacMan moved
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}
125// MacMan the following CPUs have fixed DMI2 speeds
126 case CPU_MODEL_IVYBRIDGE_XEON: // Intel Core i7, Xeon E5 v2 LGA2011 (22nm)
127case CPU_MODEL_JAKETOWN: // Intel Core i7, Xeon E5 LGA2011 (32nm)
128 case CPU_MODEL_HASWELL_SVR: // Intel Core i7, Xeon E5 LGA2011v3
129 {
130 unsigned long dmi2speed;
131 dmi2speed = 5000;
132 DBG("dmi2speed %d\n", dmi2speed);
133value->word = dmi2speed;
134return true;
135 }
136default:
137break; //Unsupported CPU type
138}
139}
140default:
141break;
142}
143}
144return false;
145}
146
147uint16_t simpleGetSMBOemProcessorType(void)
148{
149if (Platform.CPU.NoCores >= 4) {
150return 0x501;// 1281 - Quad-Core Xeon
151} else if (Platform.CPU.NoCores == 1) {
152return 0x201;// 513 - Core Solo
153};
154
155return 0x301;// 769 - Core 2 Duo
156}
157
158bool getSMBOemProcessorType(returnType *value)
159{
160static bool done = false;
161
162value->word = simpleGetSMBOemProcessorType();
163
164if (Platform.CPU.Vendor == CPUID_VENDOR_INTEL) { // Intel
165if (!done) {
166/*verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, (uint32_t)Platform.CPU.Family, (uint32_t)Platform.CPU.Model); */
167done = true;
168}
169// Bungo: fixes Oem Processor Type - better matching IMHO
170 // MacMan changed OEM Processor Type
171switch (Platform.CPU.Family) {
172case 0x06:
173{
174switch (Platform.CPU.Model) {
175
176case CPU_MODEL_DOTHAN:// 0x0D - Intel Pentium M model D
177value->word = 0x101;// 257
178return true;
179
180case CPU_MODEL_YONAH:// 0x0E - Intel Mobile Core Solo, Duo
181case CPU_MODEL_CELERON:
182value->word = 0x201;// 513
183return true;
184
185case CPU_MODEL_XEON_MP:// 0x1D - Six-Core Xeon 7400, "Dunnington", 45nm
186value->word = 0x401;// 1025
187return true;
188
189case CPU_MODEL_MEROM:// 0x0F - Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
190case CPU_MODEL_PENRYN:// 0x17 - Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
191if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
192value->word = 0x402;// 1026 - Xeon
193}
194case CPU_MODEL_PENTIUM_M:// 0x09 - Banias
195case CPU_MODEL_LINCROFT:// 0x27 - Intel Atom, "Lincroft", 45nm
196case CPU_MODEL_ATOM:// 0x1C - Intel Atom (45nm)
197return true;
198
199case CPU_MODEL_FIELDS:// 0x1E - Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
200case CPU_MODEL_DALES:// 0x1F - Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
201 case CPU_MODEL_DALES_32NM:// 0x25 - Intel Core i3, i5 LGA1156 (32nm) (Clarkdale, Arrandale)
202if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
203value->word = 0x501;// 1281 - Lynnfiled Quad-Core Xeon
204return true;
205}
206if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
207value->word = 0x901;// 2305 - Core i3
208return true;
209}
210if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
211value->word = 0x601;// Core i5
212return true;
213}
214if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
215value->word = 0x701;// 1793 - Core i7
216return true;
217}
218if (Platform.CPU.NoCores <= 2) {
219value->word = 0x601;// 1537 - Core i5
220}
221return true;
222
223 case CPU_MODEL_NEHALEM:// 0x1A - Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
224 case CPU_MODEL_NEHALEM_EX:// 0x2E - Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65xx, Xeon L75xx, LGA1567 (45nm)
225 case CPU_MODEL_WESTMERE:// 0x2C - Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
226case CPU_MODEL_WESTMERE_EX:// 0x2F - Intel Xeon E7
227 case CPU_MODEL_JAKETOWN:// 0x2D - Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
228 case CPU_MODEL_HASWELL_SVR:// 0x3F -
229if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
230value->word = 0x501;// 1281 - Xeon
231return true;
232}
233if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
234value->word = 0x702;// 1794 -Core i7
235return true;
236}
237return true;
238
239case CPU_MODEL_SANDYBRIDGE:// 0x2A - Intel Core i3, i5, i7 LGA1155 (32nm)
240 case CPU_MODEL_IVYBRIDGE:// 0x3A - Intel Core i3, i5, i7 LGA1155 (22nm)
241if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
242value->word = 0x501;// 1281 - Xeon
243return true;
244}
245if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
246value->word = 0x902;// 2306 -Core i3
247return true;
248}
249if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
250value->word = 0x603;// 1539 - Core i5
251return true;
252}
253if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
254value->word = 0x703;// 1795 - Core i7
255return true;
256}
257if (Platform.CPU.NoCores <= 2) {
258value->word = 0x603;// 1539 - Core i5
259}
260return true;
261
262case CPU_MODEL_IVYBRIDGE_XEON:// 0x3E - Mac Pro 6,1
263value->word = 0xA01;// 2561
264return true;
265
266case CPU_MODEL_HASWELL:// 0x3C -
267case CPU_MODEL_HASWELL_ULT:// 0x45 -
268case CPU_MODEL_CRYSTALWELL:// 0x46
269if (strstr(Platform.CPU.BrandString, "Xeon(R)")) {
270value->word = 0xA01;// 2561 - Xeon
271return true;
272}
273if (strstr(Platform.CPU.BrandString, "Core(TM) i3")) {
274value->word = 0x904;// 2308 - Core i3 - Apple doesn't use it - but we yes:-)
275return true;
276}
277if (strstr(Platform.CPU.BrandString, "Core(TM) i5")) {
278value->word = 0x605;// 1541 - Core i5
279return true;
280}
281if (strstr(Platform.CPU.BrandString, "Core(TM) i7")) {
282value->word = 0x705;// 1797 - Core i7
283return true;
284}
285if (Platform.CPU.NoCores <= 2) {
286value->word = 0x605;// 1541 - Core i5
287}
288return true;
289
290case 0x15:// EP80579 integrated processor
291value->word = 0x301;// 769
292return true;
293
294case 0x13:// Core i5, Xeon MP, "Havendale", "Auburndale", 45nm
295case 0x19:// Intel Core i5 650 @3.20 Ghz
296value->word = 0x601;// 1537 - Core i5
297return true;
298default:
299break; //Unsupported CPU type
300}
301}
302default:
303break;
304}
305}
306
307return false;
308}
309
310bool getSMBMemoryDeviceMemoryType(returnType *value)
311{
312static int idx = -1;
313intmap;
314
315idx++;
316if (idx < MAX_RAM_SLOTS) {
317map = Platform.DMI.DIMM[idx];
318if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {
319DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
320value->byte = Platform.RAM.DIMM[map].Type;
321return true;
322}
323}
324
325return false;
326//value->byte = SMB_MEM_TYPE_DDR2;
327//return true;
328}
329
330bool getSMBMemoryDeviceMemoryErrorHandle(returnType *value)
331{
332value->word = 0xFFFF;
333return true;
334}
335
336bool getSMBMemoryDeviceMemorySpeed(returnType *value)
337{
338static int idx = -1;
339intmap;
340
341idx++;
342if (idx < MAX_RAM_SLOTS) {
343map = Platform.DMI.DIMM[idx];
344if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {
345DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
346value->dword = Platform.RAM.DIMM[map].Frequency;
347return true;
348}
349}
350
351return false;
352//value->dword = 800;
353//return true;
354}
355
356bool getSMBMemoryDeviceManufacturer(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 && strlen(Platform.RAM.DIMM[map].Vendor) > 0) {
365DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
366value->string = Platform.RAM.DIMM[map].Vendor;
367return true;
368}
369}
370
371if (!bootInfo->memDetect) {
372return false;
373}
374value->string = NOT_AVAILABLE;
375return true;
376}
377
378bool getSMBMemoryDeviceSerialNumber(returnType *value)
379{
380static int idx = -1;
381intmap;
382
383idx++;
384
385DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
386
387if (idx < MAX_RAM_SLOTS) {
388map = Platform.DMI.DIMM[idx];
389if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {
390DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
391value->string = Platform.RAM.DIMM[map].SerialNo;
392return true;
393}
394}
395
396if (!bootInfo->memDetect) {
397return false;
398}
399value->string = NOT_AVAILABLE;
400return true;
401}
402
403bool getSMBMemoryDevicePartNumber(returnType *value)
404{
405static int idx = -1;
406intmap;
407
408idx++;
409if (idx < MAX_RAM_SLOTS) {
410map = Platform.DMI.DIMM[idx];
411if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {
412DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
413value->string = Platform.RAM.DIMM[map].PartNo;
414return true;
415}
416}
417
418if (!bootInfo->memDetect) {
419return false;
420}
421value->string = NOT_AVAILABLE;
422return true;
423}
424
425
426// getting smbios addr with fast compare ops, late checksum testing ...
427#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
428static const char * const SMTAG = "_SM_";
429static const char* const DMITAG = "_DMI_";
430
431SMBEntryPoint *getAddressOfSmbiosTable(void)
432{
433SMBEntryPoint*smbios;
434/*
435 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
436 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
437 */
438smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
439while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
440if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
441COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
442smbios->dmi.anchor[4] == DMITAG[4] &&
443checksum8(smbios, sizeof(SMBEntryPoint)) == 0) {
444return smbios;
445 }
446smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
447}
448printf("ERROR: Unable to find SMBIOS!\n");
449pause();
450return NULL;
451}
452
453

Archive Download this file

Revision: 2403