Chameleon

Chameleon Svn Source Tree

Root/tags/2.0/i386/libsaio/smbios_getters.c

Source at commit 1808 created 12 years 3 months ago.
By blackosx, Revise layout of package installer 'Welcome' file so it looks cleaner. Change the copyright notice to begin from 2009 as seen in the Chameleon 2.0 r431 installer. Should this date be set earlier?
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}
89}
90}
91}
92}
93return false;
94}
95
96uint16_t simpleGetSMBOemProcessorType(void)
97{
98if (Platform.CPU.NoCores >= 4)
99{
100return 0x0501;// Quad-Core Xeon
101}
102else if (Platform.CPU.NoCores == 1)
103{
104return 0x0201;// Core Solo
105};
106
107return 0x0301;// Core 2 Duo
108}
109
110bool getSMBOemProcessorType(returnType *value)
111{
112static bool done = false;
113
114value->word = simpleGetSMBOemProcessorType();
115
116if (Platform.CPU.Vendor == 0x756E6547) // Intel
117{
118if (!done)
119{
120verbose("CPU is %s, family 0x%x, model 0x%x\n", Platform.CPU.BrandString, Platform.CPU.Family, Platform.CPU.Model);
121done = true;
122}
123
124switch (Platform.CPU.Family)
125{
126case 0x06:
127{
128switch (Platform.CPU.Model)
129{
130case CPU_MODEL_DOTHAN:// Intel Pentium M
131case CPU_MODEL_YONAH:// Intel Mobile Core Solo, Duo
132case CPU_MODEL_MEROM:// Intel Mobile Core 2 Solo, Duo, Xeon 30xx, Xeon 51xx, Xeon X53xx, Xeon E53xx, Xeon X32xx
133case CPU_MODEL_PENRYN:// Intel Core 2 Solo, Duo, Quad, Extreme, Xeon X54xx, Xeon X33xx
134case CPU_MODEL_ATOM:// Intel Atom (45nm)
135return true;
136
137case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
138if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
139value->word = 0x0501;// Xeon
140else
141value->word = 0x0701;// Core i7
142return true;
143
144case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
145if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
146value->word = 0x0601;// Core i5
147else
148value->word = 0x0701;// Core i7
149return true;
150
151case CPU_MODEL_DALES:
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_SANDY:// Intel Core i3, i5, i7 LGA1155 (32nm)
159 case CPU_MODEL_SANDY_XEON:// Intel Xeon E3
160case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
161if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
162value->word = 0x0901;// Core i3
163else
164if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
165value->word = 0x0601;// Core i5
166else
167value->word = 0x0701;// Core i7
168return true;
169
170case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
171case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
172value->word = 0x0501;// Core i7
173return true;
174}
175}
176}
177}
178
179return false;
180}
181
182bool getSMBMemoryDeviceMemoryType(returnType *value)
183{
184static int idx = -1;
185intmap;
186
187idx++;
188if (idx < MAX_RAM_SLOTS)
189{
190map = Platform.DMI.DIMM[idx];
191if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
192{
193DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
194value->byte = Platform.RAM.DIMM[map].Type;
195return true;
196}
197}
198
199return false;
200//value->byte = SMB_MEM_TYPE_DDR2;
201//return true;
202}
203
204bool getSMBMemoryDeviceMemorySpeed(returnType *value)
205{
206static int idx = -1;
207intmap;
208
209idx++;
210if (idx < MAX_RAM_SLOTS)
211{
212map = Platform.DMI.DIMM[idx];
213if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
214{
215DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
216value->dword = Platform.RAM.DIMM[map].Frequency;
217return true;
218}
219}
220
221return false;
222//value->dword = 800;
223//return true;
224}
225
226bool getSMBMemoryDeviceManufacturer(returnType *value)
227{
228static int idx = -1;
229intmap;
230
231idx++;
232if (idx < MAX_RAM_SLOTS)
233{
234map = Platform.DMI.DIMM[idx];
235if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
236{
237DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
238value->string = Platform.RAM.DIMM[map].Vendor;
239return true;
240}
241}
242
243if (!bootInfo->memDetect)
244return false;
245value->string = NOT_AVAILABLE;
246return true;
247}
248
249bool getSMBMemoryDeviceSerialNumber(returnType *value)
250{
251static int idx = -1;
252intmap;
253
254idx++;
255
256 DBG("getSMBMemoryDeviceSerialNumber index: %d, MAX_RAM_SLOTS: %d\n",idx,MAX_RAM_SLOTS);
257
258if (idx < MAX_RAM_SLOTS)
259{
260map = Platform.DMI.DIMM[idx];
261if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
262{
263DBG("map=%d, RAM Detected SerialNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].SerialNo);
264value->string = Platform.RAM.DIMM[map].SerialNo;
265return true;
266}
267}
268
269if (!bootInfo->memDetect)
270return false;
271value->string = NOT_AVAILABLE;
272return true;
273}
274
275bool getSMBMemoryDevicePartNumber(returnType *value)
276{
277static int idx = -1;
278intmap;
279
280idx++;
281if (idx < MAX_RAM_SLOTS)
282{
283map = Platform.DMI.DIMM[idx];
284if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
285{
286DBG("map=%d, RAM Detected PartNo[%d]='%s'\n", map, idx, Platform.RAM.DIMM[map].PartNo);
287value->string = Platform.RAM.DIMM[map].PartNo;
288return true;
289}
290}
291
292if (!bootInfo->memDetect)
293return false;
294value->string = NOT_AVAILABLE;
295return true;
296}
297
298
299// getting smbios addr with fast compare ops, late checksum testing ...
300#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
301static const char * const SMTAG = "_SM_";
302static const char* const DMITAG = "_DMI_";
303
304SMBEntryPoint *getAddressOfSmbiosTable(void)
305{
306SMBEntryPoint*smbios;
307/*
308 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
309 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
310 */
311smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
312while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
313if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
314COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
315smbios->dmi.anchor[4] == DMITAG[4] &&
316checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
317 {
318return smbios;
319 }
320smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
321}
322printf("ERROR: Unable to find SMBIOS!\n");
323pause();
324return NULL;
325}
326
327

Archive Download this file

Revision: 1808