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