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