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{
24value->word = Platform.CPU.FSBFrequency/1000000;
25return true;
26}
27
28bool getProcessorInformationMaximumClock(returnType *value)
29{
30value->word = Platform.CPU.CPUFrequency/1000000;
31return true;
32}
33
34bool getSMBOemProcessorBusSpeed(returnType *value)
35{
36if (Platform.CPU.Vendor == 0x756E6547) // Intel
37{
38switch (Platform.CPU.Family)
39{
40case 0x06:
41{
42switch (Platform.CPU.Model)
43{
44case CPU_MODEL_DOTHAN:// Intel Pentium M
45case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
46case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
47case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
48case CPU_MODEL_ATOM:// Intel Atom (45nm)
49return false;
50
51case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
52case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
53case CPU_MODEL_DALES:
54case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
55case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
56case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
57case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
58{
59// thanks to dgobe for i3/i5/i7 bus speed detection
60int nhm_bus = 0x3F;
61static long possible_nhm_bus[] = {0xFF, 0x7F, 0x3F};
62unsigned long did, vid;
63int i;
64
65// Nehalem supports Scrubbing
66// First, locate the PCI bus where the MCH is located
67for(i = 0; i < sizeof(possible_nhm_bus); i++)
68{
69vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x00);
70did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), 0x02);
71vid &= 0xFFFF;
72did &= 0xFF00;
73
74if(vid == 0x8086 && did >= 0x2C00)
75nhm_bus = possible_nhm_bus[i];
76}
77
78unsigned long qpimult, qpibusspeed;
79qpimult = pci_config_read32(PCIADDR(nhm_bus, 2, 1), 0x50);
80qpimult &= 0x7F;
81DBG("qpimult %d\n", qpimult);
82qpibusspeed = (qpimult * 2 * (Platform.CPU.FSBFrequency/1000000));
83// Rek: rounding decimals to match original mac profile info
84if (qpibusspeed%100 != 0)qpibusspeed = ((qpibusspeed+50)/100)*100;
85DBG("qpibusspeed %d\n", qpibusspeed);
86value->word = qpibusspeed;
87return true;
88}
89case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
90case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
91case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
92{
93int busspeed;
94busspeed = 100;
95value->word = busspeed;
96return true;
97}
98}
99}
100}
101}
102return false;
103}
104
105uint16_t simpleGetSMBOemProcessorType(void)
106{
107if (Platform.CPU.NoCores >= 4)
108{
109return 0x0501;// Quad-Core Xeon
110}
111else if (Platform.CPU.NoCores == 1)
112{
113return 0x0201;// Core Solo
114};
115
116return 0x0301;// Core 2 Duo
117}
118
119bool getSMBOemProcessorType(returnType *value)
120{
121value->word = simpleGetSMBOemProcessorType();
122
123if (Platform.CPU.Vendor == 0x756E6547) // Intel
124{
125switch (Platform.CPU.Family)
126{
127case 0x06:
128{
129switch (Platform.CPU.Model)
130{
131case CPU_MODEL_DOTHAN:// Intel Pentium M
132case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
133case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
134case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
135case CPU_MODEL_ATOM:// Intel Atom (45nm)
136return true;
137
138case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
139case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
140case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
141 case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5-xxxx LGA2011 (32nm)
142if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
143value->word = 0x0501;// Xeon
144else
145value->word = 0x0701;// Core i7
146return true;
147
148case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
149if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
150value->word = 0x0501;// Xeon
151else
152if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
153value->word = 0x0601;// Core i5
154else
155value->word = 0x0701;// Core i7
156return true;
157
158case CPU_MODEL_DALES:
159if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
160value->word = 0x0601;// Core i5
161else
162value->word = 0x0701;// Core i7
163return true;
164
165case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7, Xeon E3-12xx LGA1155 (32nm)
166case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
167case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
168if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
169value->word = 0x0501;// Xeon
170else
171if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
172value->word = 0x0901;// Core i3
173else
174if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
175value->word = 0x0601;// Core i5
176else
177value->word = 0x0701;// Core i7
178return true;
179}
180}
181}
182}
183
184return false;
185}
186
187bool getSMBMemoryDeviceMemoryType(returnType *value)
188{
189static int idx = -1;
190intmap;
191
192idx++;
193if (idx < MAX_RAM_SLOTS)
194{
195map = Platform.DMI.DIMM[idx];
196if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
197{
198DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
199value->byte = Platform.RAM.DIMM[map].Type;
200return true;
201}
202}
203
204return false;
205//value->byte = SMB_MEM_TYPE_DDR2;
206//return true;
207}
208
209bool getSMBMemoryDeviceMemorySpeed(returnType *value)
210{
211static int idx = -1;
212intmap;
213
214idx++;
215if (idx < MAX_RAM_SLOTS)
216{
217map = Platform.DMI.DIMM[idx];
218if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
219{
220DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
221value->dword = Platform.RAM.DIMM[map].Frequency;
222return true;
223}
224}
225
226return false;
227//value->dword = 800;
228//return true;
229}
230
231bool getSMBMemoryDeviceManufacturer(returnType *value)
232{
233static int idx = -1;
234intmap;
235
236idx++;
237if (idx < MAX_RAM_SLOTS)
238{
239map = Platform.DMI.DIMM[idx];
240if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
241{
242DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
243value->string = Platform.RAM.DIMM[map].Vendor;
244return true;
245}
246}
247
248if (!bootInfo->memDetect)
249return false;
250value->string = NOT_AVAILABLE;
251return true;
252}
253
254bool getSMBMemoryDeviceSerialNumber(returnType *value)
255{
256static int idx = -1;
257intmap;
258
259idx++;
260
261 DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
262
263if (idx < MAX_RAM_SLOTS)
264{
265map = Platform.DMI.DIMM[idx];
266if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
267{
268DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
269value->string = Platform.RAM.DIMM[map].SerialNo;
270return true;
271}
272}
273
274if (!bootInfo->memDetect)
275return false;
276value->string = NOT_AVAILABLE;
277return true;
278}
279
280bool getSMBMemoryDevicePartNumber(returnType *value)
281{
282static int idx = -1;
283intmap;
284
285idx++;
286if (idx < MAX_RAM_SLOTS)
287{
288map = Platform.DMI.DIMM[idx];
289if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
290{
291DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
292value->string = Platform.RAM.DIMM[map].PartNo;
293return true;
294}
295}
296
297if (!bootInfo->memDetect)
298return false;
299value->string = NOT_AVAILABLE;
300return true;
301}
302
303
304// getting smbios addr with fast compare ops, late checksum testing ...
305#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
306static const char * const SMTAG = "_SM_";
307static const char* const DMITAG = "_DMI_";
308
309SMBEntryPoint *getAddressOfSmbiosTable(void)
310{
311SMBEntryPoint*smbios;
312/*
313 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
314 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
315 */
316smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
317while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
318if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
319COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
320smbios->dmi.anchor[4] == DMITAG[4] &&
321checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
322 {
323return smbios;
324 }
325smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
326}
327printf("ERROR: Unable to find SMBIOS!\n");
328pause();
329return NULL;
330}
331
332

Archive Download this file

Revision: 1930