Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/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
10#ifndef DEBUG_SMBIOS
11#define DEBUG_SMBIOS 0
12#endif
13
14#if DEBUG_SMBIOS
15#define DBG(x...)printf(x)
16#else
17#define DBG(x...)
18#endif
19
20
21bool getProcessorInformationExternalClock(returnType *value)
22{
23value->word = Platform.CPU.FSBFrequency/1000000;
24return true;
25}
26
27bool getProcessorInformationMaximumClock(returnType *value)
28{
29value->word = Platform.CPU.CPUFrequency/1000000;
30return true;
31}
32
33bool getSMBOemProcessorBusSpeed(returnType *value)
34{
35if (Platform.CPU.Vendor == 0x756E6547) // Intel
36{
37switch (Platform.CPU.Family)
38{
39case 0x06:
40{
41switch (Platform.CPU.Model)
42{
43case 0x0D:// ?
44case CPU_MODEL_YONAH:// Yonah0x0E
45case CPU_MODEL_MEROM:// Merom0x0F
46case CPU_MODEL_PENRYN:// Penryn0x17
47case CPU_MODEL_ATOM:// Atom 45nm0x1C
48return false;
49
50case 0x19:// Intel Core i5 650 @3.20 Ghz
51case CPU_MODEL_NEHALEM:// Intel Core i7 LGA1366 (45nm)
52case CPU_MODEL_FIELDS:// Intel Core i5, i7 LGA1156 (45nm)
53case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) ???
54case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm)
55case CPU_MODEL_WESTMERE:// Intel Core i7 LGA1366 (32nm) 6 Core
56case CPU_MODEL_NEHALEM_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
57case CPU_MODEL_WESTMERE_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
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 0x0D:// ?
131case CPU_MODEL_YONAH:// Yonah
132case CPU_MODEL_MEROM:// Merom
133case CPU_MODEL_PENRYN:// Penryn
134case CPU_MODEL_ATOM:// Intel Atom (45nm)
135return true;
136
137case CPU_MODEL_NEHALEM:// Intel Core i7 LGA1366 (45nm)
138if (strstr(Platform.CPU.BrandString, "Xeon(R)"))
139value->word = 0x0501;// Xeon
140else
141value->word = 0x0701;// Core i7
142
143return true;
144
145case CPU_MODEL_FIELDS:// Lynnfield, Clarksfield, Jasper
146if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
147value->word = 0x601;// Core i5
148else
149value->word = 0x0701;// Core i7
150return true;
151
152case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) (Havendale, Auburndale)
153if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
154value->word = 0x601;// Core i5
155else
156value->word = 0x0701;// Core i7
157return true;
158
159case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)
160if (strstr(Platform.CPU.BrandString, "Core(TM) i3"))
161value->word = 0x901;// Core i3
162else
163if (strstr(Platform.CPU.BrandString, "Core(TM) i5"))
164value->word = 0x601;// Core i5
165else
166value->word = 0x0701;// Core i7
167return true;
168
169case CPU_MODEL_WESTMERE:// Intel Core i7 LGA1366 (32nm) 6 Core (Gulftown, Westmere-EP, Westmere-WS)
170case CPU_MODEL_WESTMERE_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
171value->word = 0x0701;// Core i7
172return true;
173
174case 0x19:// Intel Core i5 650 @3.20 Ghz
175value->word = 0x601;// Core i5
176return true;
177}
178}
179}
180}
181
182return false;
183}
184
185bool getSMBMemoryDeviceMemoryType(returnType *value)
186{
187static int idx = -1;
188intmap;
189
190idx++;
191if (idx < MAX_RAM_SLOTS)
192{
193map = Platform.DMI.DIMM[idx];
194if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0)
195{
196DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);
197value->byte = Platform.RAM.DIMM[map].Type;
198return true;
199}
200}
201
202return false;
203//value->byte = SMB_MEM_TYPE_DDR2;
204//return true;
205}
206
207bool getSMBMemoryDeviceMemorySpeed(returnType *value)
208{
209static int idx = -1;
210intmap;
211
212idx++;
213if (idx < MAX_RAM_SLOTS)
214{
215map = Platform.DMI.DIMM[idx];
216if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0)
217{
218DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);
219value->dword = Platform.RAM.DIMM[map].Frequency;
220return true;
221}
222}
223
224return false;
225//value->dword = 800;
226//return true;
227}
228
229bool getSMBMemoryDeviceManufacturer(returnType *value)
230{
231static int idx = -1;
232intmap;
233
234idx++;
235if (idx < MAX_RAM_SLOTS)
236{
237map = Platform.DMI.DIMM[idx];
238if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0)
239{
240DBG("RAM Detected Vendor[%d]='%s'\n", idx, Platform.RAM.DIMM[map].Vendor);
241value->string = Platform.RAM.DIMM[map].Vendor;
242return true;
243}
244}
245
246return false;
247//value->string = "N/A";
248//return true;
249}
250
251bool getSMBMemoryDeviceSerialNumber(returnType *value)
252{
253static int idx = -1;
254intmap;
255
256idx++;
257if (idx < MAX_RAM_SLOTS)
258{
259map = Platform.DMI.DIMM[idx];
260if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0)
261{
262DBG("name = %s, map=%d, RAM Detected SerialNo[%d]='%s'\n", name ? name : "",
263map, idx, Platform.RAM.DIMM[map].SerialNo);
264value->string = Platform.RAM.DIMM[map].SerialNo;
265return true;
266}
267}
268
269return false;
270//value->string = "N/A";
271//return true;
272}
273
274bool getSMBMemoryDevicePartNumber(returnType *value)
275{
276static int idx = -1;
277intmap;
278
279idx++;
280if (idx < MAX_RAM_SLOTS)
281{
282map = Platform.DMI.DIMM[idx];
283if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0)
284{
285DBG("Ram Detected PartNo[%d]='%s'\n", idx, Platform.RAM.DIMM[map].PartNo);
286value->string = Platform.RAM.DIMM[map].PartNo;
287return true;
288}
289}
290
291return false;
292//value->string = "N/A";
293//return true;
294}
295
296
297// getting smbios addr with fast compare ops, late checksum testing ...
298#define COMPARE_DWORD(a,b) ( *((uint32_t *) a) == *((uint32_t *) b) )
299static const char * const SMTAG = "_SM_";
300static const char* const DMITAG = "_DMI_";
301
302SMBEntryPoint *getAddressOfSmbiosTable(void)
303{
304SMBEntryPoint*smbios;
305/*
306 * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking
307 * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").
308 */
309smbios = (SMBEntryPoint*)SMBIOS_RANGE_START;
310while (smbios <= (SMBEntryPoint *)SMBIOS_RANGE_END) {
311if (COMPARE_DWORD(smbios->anchor, SMTAG) &&
312COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&
313smbios->dmi.anchor[4] == DMITAG[4] &&
314checksum8(smbios, sizeof(SMBEntryPoint)) == 0)
315 {
316return smbios;
317 }
318smbios = (SMBEntryPoint*)(((char*)smbios) + 16);
319}
320printf("ERROR: Unable to find SMBIOS!\n");
321pause();
322return NULL;
323}
324
325

Archive Download this file

Revision: 809