Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2323