Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2329