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