1 | /*␊ |
2 | * Copyright 2008 mackerintel␊ |
3 | */␊ |
4 | ␊ |
5 | #include "libsaio.h"␊ |
6 | #include "boot.h"␊ |
7 | #include "bootstruct.h"␊ |
8 | #include "acpi.h"␊ |
9 | #include "efi_tables.h"␊ |
10 | #include "fake_efi.h"␊ |
11 | #include "platform.h"␊ |
12 | #include "smbios_patcher.h"␊ |
13 | ␊ |
14 | #ifndef DEBUG_SMBIOS␊ |
15 | #define DEBUG_SMBIOS 0␊ |
16 | #endif␊ |
17 | ␊ |
18 | #if DEBUG_SMBIOS␊ |
19 | #define DBG(x...)␉printf(x)␊ |
20 | #else␊ |
21 | #define DBG(x...)␊ |
22 | #endif␊ |
23 | ␊ |
24 | typedef struct {␊ |
25 | const char* key;␊ |
26 | const char* value;␊ |
27 | } SMStrEntryPair;␊ |
28 | ␊ |
29 | // defaults for a MacBook␊ |
30 | static const SMStrEntryPair const sm_macbook_defaults[]={␊ |
31 | ␉{"SMbiosvendor",␉"Apple Inc."␉␉␉},␊ |
32 | ␉{"SMbiosversion",␉"MB41.88Z.0073.B00.0809221748"␉},␊ |
33 | ␉{"SMbiosdate",␉␉"04/01/2008"␉␉␉},␊ |
34 | ␉{"SMmanufacter",␉"Apple Inc."␉␉␉},␊ |
35 | ␉{"SMproductname",␉"MacBook4,1"␉␉␉},␊ |
36 | ␉{"SMsystemversion",␉"1.0"␉␉␉␉},␊ |
37 | ␉{"SMserial",␉␉"SOMESRLNMBR"␉␉␉},␊ |
38 | ␉{"SMfamily",␉␉"MacBook"␉␉␉},␊ |
39 | ␉{"SMboardmanufacter",␉"Apple Inc."␉␉␉},␊ |
40 | ␉{"SMboardproduct",␉"Mac-F42D89C8"␉␉␉},␊ |
41 | ␉{ "",""␉}␊ |
42 | };␊ |
43 | ␊ |
44 | // defaults for a MacBook Pro␊ |
45 | static const SMStrEntryPair const sm_macbookpro_defaults[]={␊ |
46 | ␉{"SMbiosvendor",␉"Apple Inc."␉␉␉},␊ |
47 | ␉{"SMbiosversion",␉"MBP41.88Z.0073.B00.0809221748"␉},␊ |
48 | ␉{"SMbiosdate",␉␉"04/01/2008"␉␉␉},␊ |
49 | ␉{"SMmanufacter",␉"Apple Inc."␉␉␉},␊ |
50 | ␉{"SMproductname",␉"MacBookPro4,1"␉␉␉},␊ |
51 | ␉{"SMsystemversion",␉"1.0"␉␉␉␉},␊ |
52 | ␉{"SMserial",␉␉"SOMESRLNMBR"␉␉␉},␊ |
53 | ␉{"SMfamily",␉␉"MacBookPro"␉␉␉},␊ |
54 | ␉{"SMboardmanufacter",␉"Apple Inc."␉␉␉},␊ |
55 | ␉{"SMboardproduct",␉"Mac-F42D89C8"␉␉␉},␊ |
56 | ␉{ "",""␉}␊ |
57 | };␊ |
58 | ␊ |
59 | // defaults for a Mac mini ␊ |
60 | static const SMStrEntryPair const sm_macmini_defaults[]={␊ |
61 | ␉{"SMbiosvendor",␉"Apple Inc."␉␉␉},␊ |
62 | ␉{"SMbiosversion",␉"MM21.88Z.009A.B00.0706281359"␉},␊ |
63 | ␉{"SMbiosdate",␉␉"04/01/2008"␉␉␉},␊ |
64 | ␉{"SMmanufacter",␉"Apple Inc."␉␉␉},␊ |
65 | ␉{"SMproductname",␉"Macmini2,1"␉␉␉},␊ |
66 | ␉{"SMsystemversion",␉"1.0"␉␉␉␉},␊ |
67 | ␉{"SMserial",␉␉"SOMESRLNMBR"␉␉␉},␊ |
68 | ␉{"SMfamily",␉␉"Napa Mac"␉␉␉},␊ |
69 | ␉{"SMboardmanufacter",␉"Apple Inc."␉␉␉},␊ |
70 | ␉{"SMboardproduct",␉"Mac-F4208EAA"␉␉␉},␊ |
71 | ␉{ "",""␉}␊ |
72 | };␊ |
73 | ␊ |
74 | // defaults for an iMac␊ |
75 | static const SMStrEntryPair const sm_imac_defaults[]={␊ |
76 | ␉{"SMbiosvendor",␉"Apple Inc."␉␉␉},␊ |
77 | ␉{"SMbiosversion",␉"IM81.88Z.00C1.B00.0802091538"␉},␊ |
78 | ␉{"SMbiosdate",␉␉"04/01/2008"␉␉␉},␊ |
79 | ␉{"SMmanufacter",␉"Apple Inc."␉␉␉},␊ |
80 | ␉{"SMproductname",␉"iMac8,1"␉␉␉},␉␊ |
81 | ␉{"SMsystemversion",␉"1.0"␉␉␉␉},␊ |
82 | ␉{"SMserial",␉␉"SOMESRLNMBR"␉␉␉},␊ |
83 | ␉{"SMfamily",␉␉"Mac"␉␉␉␉},␊ |
84 | ␉{"SMboardmanufacter",␉"Apple Inc."␉␉␉},␊ |
85 | ␉{"SMboardproduct",␉"Mac-F227BEC8"␉␉␉},␊ |
86 | ␉{ "",""␉}␊ |
87 | };␊ |
88 | ␊ |
89 | // defaults for a Mac Pro␊ |
90 | static const SMStrEntryPair const sm_macpro_defaults[]={␊ |
91 | ␉{"SMbiosvendor",␉"Apple Computer, Inc."␉␉},␊ |
92 | ␉{"SMbiosversion",␉"MP31.88Z.006C.B05.0802291410"␉},␊ |
93 | ␉{"SMbiosdate",␉␉"04/01/2008"␉␉␉},␊ |
94 | ␉{"SMmanufacter",␉"Apple Computer, Inc."␉␉},␊ |
95 | ␉{"SMproductname",␉"MacPro3,1"␉␉␉},␊ |
96 | ␉{"SMsystemversion",␉"1.0"␉␉␉␉},␊ |
97 | ␉{"SMserial",␉␉"SOMESRLNMBR"␉␉␉},␊ |
98 | ␉{"SMfamily",␉␉"MacPro"␉␉␉},␊ |
99 | ␉{"SMboardmanufacter",␉"Apple Computer, Inc."␉␉},␊ |
100 | ␉{"SMboardproduct",␉"Mac-F4208DC8"␉␉␉},␊ |
101 | ␉{ "",""␉}␊ |
102 | };␊ |
103 | ␊ |
104 | // defaults for an iMac11,1 core i5/i7␊ |
105 | static const SMStrEntryPair const sm_imacCore_i5_i7_defaults[]={␊ |
106 | ␉{"SMbiosvendor",␉"Apple Inc."␉␉␉},␊ |
107 | ␉{"SMbiosversion",␉"IM111.0034.B00"␉},␊ |
108 | ␉{"SMbiosdate",␉␉"06/01/2009"␉␉␉},␊ |
109 | ␉{"SMmanufacter",␉"Apple Inc."␉␉␉},␊ |
110 | ␉{"SMproductname",␉"iMac11,1"␉␉␉},␉␊ |
111 | ␉{"SMsystemversion",␉"1.0"␉␉␉␉},␊ |
112 | ␉{"SMserial",␉␉"SOMESRLNMBR"␉␉␉},␊ |
113 | ␉{"SMfamily",␉␉"iMac"␉␉␉␉},␊ |
114 | ␉{"SMboardmanufacter","Apple Computer, Inc."␉},␊ |
115 | ␉{"SMboardproduct",␉"Mac-F2268DAE"␉␉␉},␊ |
116 | ␉{ "",""␉}␊ |
117 | };␊ |
118 | ␊ |
119 | static const char* sm_get_defstr(const char * key, int table_num)␊ |
120 | {␊ |
121 | ␉int␉i;␊ |
122 | ␉const SMStrEntryPair*␉sm_defaults;␊ |
123 | ␊ |
124 | ␉if (platformCPUFeature(CPU_FEATURE_MOBILE)) {␊ |
125 | ␉␉if (Platform.CPU.NoCores > 1) {␊ |
126 | ␉␉␉sm_defaults=sm_macbookpro_defaults;␊ |
127 | ␉␉} else {␊ |
128 | ␉␉␉sm_defaults=sm_macbook_defaults;␊ |
129 | ␉␉}␊ |
130 | ␉} else {␊ |
131 | ␉␉switch (Platform.CPU.NoCores) ␊ |
132 | ␉␉{␊ |
133 | ␉␉␉case 1: ␊ |
134 | ␉␉␉␉sm_defaults=sm_macmini_defaults; ␊ |
135 | ␉␉␉␉break;␊ |
136 | ␉␉␉case 2:␊ |
137 | ␉␉␉␉sm_defaults=sm_imac_defaults;␊ |
138 | ␉␉␉␉break;␊ |
139 | ␉␉␉default:␊ |
140 | ␉␉␉{␊ |
141 | ␉␉␉␉switch (Platform.CPU.Family) ␊ |
142 | ␉␉␉␉{␊ |
143 | ␉␉␉␉␉case 0x06:␊ |
144 | ␉␉␉␉␉{␊ |
145 | ␉␉␉␉␉␉switch (Platform.CPU.Model)␊ |
146 | ␉␉␉␉␉␉{␊ |
147 | ␉␉␉␉␉␉␉case 0x19: // Intel Core i5 650␊ |
148 | ␉␉␉␉␉␉␉case 0x1E: // Intel Core i7 LGA1156 (45nm)␊ |
149 | ␉␉␉␉␉␉␉case 0x1F: // Intel Core i5 LGA1156 (45nm)␊ |
150 | ␉␉␉␉␉␉␉␉sm_defaults=sm_imacCore_i5_i7_defaults; ␊ |
151 | ␉␉␉␉␉␉␉␉break;␊ |
152 | ␉␉␉␉␉␉␉default:␊ |
153 | ␉␉␉␉␉␉␉␉sm_defaults=sm_macpro_defaults; ␊ |
154 | ␉␉␉␉␉␉␉␉break;␊ |
155 | ␉␉␉␉␉␉}␊ |
156 | ␉␉␉␉␉␉break;␊ |
157 | ␉␉␉␉␉}␊ |
158 | ␉␉␉␉␉default:␊ |
159 | ␉␉␉␉␉␉sm_defaults=sm_macpro_defaults; ␊ |
160 | ␉␉␉␉␉␉break;␊ |
161 | ␉␉␉␉}␊ |
162 | ␉␉␉␉break;␊ |
163 | ␉␉␉}␊ |
164 | ␉␉}␊ |
165 | ␉}␊ |
166 | ␉␊ |
167 | ␉for (i=0; sm_defaults[i].key[0]; i++) {␊ |
168 | ␉␉if (!strcmp (sm_defaults[i].key, key)) {␊ |
169 | ␉␉␉return sm_defaults[i].value;␊ |
170 | ␉␉}␊ |
171 | ␉}␊ |
172 | ␊ |
173 | ␉// Shouldn't happen␊ |
174 | ␉printf ("Error: no default for '%s' known\n", key);␊ |
175 | ␉sleep (2);␊ |
176 | ␉return "";␊ |
177 | }␊ |
178 | ␊ |
179 | static int sm_get_fsb(const char *name, int table_num)␊ |
180 | {␊ |
181 | ␉return Platform.CPU.FSBFrequency/1000000;␊ |
182 | }␊ |
183 | ␊ |
184 | static int sm_get_cpu (const char *name, int table_num)␊ |
185 | {␊ |
186 | ␉return Platform.CPU.CPUFrequency/1000000;␊ |
187 | }␊ |
188 | ␊ |
189 | static int sm_get_simplecputype()␊ |
190 | {␊ |
191 | ␉if (Platform.CPU.NoCores >= 4) ␊ |
192 | ␉{␊ |
193 | ␉␉return 0x0501; // Quad-Core Xeon␊ |
194 | ␉}␊ |
195 | ␉else if (Platform.CPU.NoCores == 1) ␊ |
196 | ␉{␊ |
197 | ␉␉return 0x0201; // Core Solo␊ |
198 | ␉};␊ |
199 | ␉␊ |
200 | ␉return 0x0301; // Core 2 Duo␊ |
201 | }␊ |
202 | ␊ |
203 | static int sm_get_bus_speed (const char *name, int table_num)␊ |
204 | {␊ |
205 | ␉if (Platform.CPU.Vendor == 0x756E6547) // Intel␊ |
206 | ␉{␉␉␊ |
207 | ␉␉switch (Platform.CPU.Family) ␊ |
208 | ␉␉{␊ |
209 | ␉␉␉case 0x06:␊ |
210 | ␉␉␉{␊ |
211 | ␉␉␉␉switch (Platform.CPU.Model)␊ |
212 | ␉␉␉␉{␊ |
213 | ␉␉␉␉␉case 0x0F: // Intel Core (65nm)␊ |
214 | ␉␉␉␉␉case 0x17: // Intel Core (45nm)␊ |
215 | ␉␉␉␉␉case 0x1C: // Intel Atom (45nm)␊ |
216 | ␉␉␉␉␉␉return 0; // TODO: populate bus speed for these processors␊ |
217 | ␉␉␉␉␉case 0x19: // Intel Core i5 650 @3.20 Ghz␊ |
218 | ␉␉␉␉␉␉return 3600; // GT/s / 1000␊ |
219 | ␉␉␉␉␉case 0x1A: // Intel Core i7 LGA1366 (45nm)␊ |
220 | ␉␉␉␉␉case 0x1E: // Intel Core i5, i7 LGA1156 (45nm)␊ |
221 | ␉␉␉␉␉case 0x1F: // Intel Core i5, i7 LGA1156 (45nm) ???␊ |
222 | ␉␉␉␉␉␉return 4800; // GT/s / 1000␊ |
223 | ␉␉␉␉␉case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
224 | ␉␉␉␉␉␉return 0; // TODO: populate bus speed for these processors␊ |
225 | ␉␉␉␉␉case 0x2C: // Intel Core i7 LGA1366 (32nm) 6 Core␊ |
226 | ␉␉␉␉␉case 0x2E: // Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
227 | ␉␉␉␉␉␉return 0; // TODO: populate bus speed for these processors␊ |
228 | ␉␉␉␉}␊ |
229 | ␉␉␉}␊ |
230 | ␉␉}␊ |
231 | ␉}␊ |
232 | ␉return 0;␊ |
233 | }␊ |
234 | ␊ |
235 | static int sm_get_cputype (const char *name, int table_num)␊ |
236 | {␊ |
237 | ␉static bool done = false;␉␉␊ |
238 | ␉␉␊ |
239 | ␉if (Platform.CPU.Vendor == 0x756E6547) // Intel␊ |
240 | ␉{␊ |
241 | ␉␉if (!done) {␊ |
242 | ␉␉␉verbose("CPU is Intel, family 0x%x, model 0x%x, ext.model 0x%x\n", Platform.CPU.Family, Platform.CPU.Model, Platform.CPU.ExtModel);␊ |
243 | ␉␉␉done = true;␊ |
244 | ␉␉}␊ |
245 | ␉␉␊ |
246 | ␉␉switch (Platform.CPU.Family) ␊ |
247 | ␉␉{␊ |
248 | ␉␉␉case 0x06:␊ |
249 | ␉␉␉{␊ |
250 | ␉␉␉␉switch (Platform.CPU.Model)␊ |
251 | ␉␉␉␉{␊ |
252 | ␉␉␉␉␉case 0x0F: // Intel Core (65nm)␊ |
253 | ␉␉␉␉␉case 0x17: // Intel Core (45nm)␊ |
254 | ␉␉␉␉␉case 0x1C: // Intel Atom (45nm)␊ |
255 | ␉␉␉␉␉␉return sm_get_simplecputype();␊ |
256 | ␉␉␉␉␉case 0x1A: // Intel Core i7 LGA1366 (45nm)␊ |
257 | ␉␉␉␉␉␉return 0x0701;␊ |
258 | ␉␉␉␉␉case 0x1E: // Intel Core i5, i7 LGA1156 (45nm)␊ |
259 | ␉␉␉␉␉␉// get this opportunity to fill the known processor interconnect speed for cor i5/i7 in GT/s␊ |
260 | ␉␉␉␉␉␉return 0x0701;␊ |
261 | ␉␉␉␉␉case 0x19: // Intel Core i5 650 @3.20 Ghz␊ |
262 | ␉␉␉␉␉case 0x1F: // Intel Core i5, i7 LGA1156 (45nm) ???␊ |
263 | ␉␉␉␉␉␉return 0x0601;␊ |
264 | ␉␉␉␉␉case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
265 | ␉␉␉␉␉␉return 0x0301;␊ |
266 | ␉␉␉␉␉case 0x2C: // Intel Core i7 LGA1366 (32nm) 6 Core␊ |
267 | ␉␉␉␉␉case 0x2E: // Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
268 | ␉␉␉␉␉␉return 0x0601;␊ |
269 | ␉␉␉␉}␊ |
270 | ␉␉␉}␊ |
271 | ␉␉}␊ |
272 | ␉}␊ |
273 | ␉␊ |
274 | ␉return sm_get_simplecputype();␊ |
275 | }␊ |
276 | ␊ |
277 | static int sm_get_memtype (const char *name, int table_num)␊ |
278 | {␊ |
279 | ␉int␉map;␊ |
280 | ␊ |
281 | ␉if (table_num < MAX_RAM_SLOTS) {␊ |
282 | ␉␉map = Platform.DMI.DIMM[table_num];␊ |
283 | ␉␉if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Type != 0) {␊ |
284 | DBG("RAM Detected Type = %d\n", Platform.RAM.DIMM[map].Type);␊ |
285 | return Platform.RAM.DIMM[map].Type;␊ |
286 | ␉␉}␊ |
287 | ␉}␊ |
288 | ␉␊ |
289 | ␉return SMB_MEM_TYPE_DDR2;␊ |
290 | }␊ |
291 | ␊ |
292 | static int sm_get_memspeed (const char *name, int table_num)␊ |
293 | {␊ |
294 | ␉int␉map;␊ |
295 | ␊ |
296 | ␉if (table_num < MAX_RAM_SLOTS) {␊ |
297 | ␉␉map = Platform.DMI.DIMM[table_num];␊ |
298 | ␉␉if (Platform.RAM.DIMM[map].InUse && Platform.RAM.DIMM[map].Frequency != 0) {␊ |
299 | DBG("RAM Detected Freq = %d Mhz\n", Platform.RAM.DIMM[map].Frequency);␊ |
300 | return Platform.RAM.DIMM[map].Frequency;␊ |
301 | ␉␉}␊ |
302 | ␉}␊ |
303 | ␊ |
304 | ␉return 800;␊ |
305 | }␊ |
306 | ␊ |
307 | static const char *sm_get_memvendor (const char *name, int table_num)␊ |
308 | {␊ |
309 | ␉int␉map;␊ |
310 | ␊ |
311 | ␉if (table_num < MAX_RAM_SLOTS) {␊ |
312 | ␉␉map = Platform.DMI.DIMM[table_num];␊ |
313 | ␉␉if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].Vendor) > 0) {␊ |
314 | ␉␉␉DBG("RAM Detected Vendor[%d]='%s'\n", table_num, Platform.RAM.DIMM[map].Vendor);␊ |
315 | ␉␉␉return Platform.RAM.DIMM[map].Vendor;␊ |
316 | ␉␉}␊ |
317 | ␉}␊ |
318 | ␉return "N/A";␊ |
319 | }␊ |
320 | ␉␊ |
321 | static const char *sm_get_memserial (const char *name, int table_num)␊ |
322 | {␊ |
323 | ␉int␉map;␊ |
324 | ␊ |
325 | ␉if (table_num < MAX_RAM_SLOTS) {␊ |
326 | ␉␉map = Platform.DMI.DIMM[table_num];␊ |
327 | ␉␉if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].SerialNo) > 0) {␊ |
328 | DBG("name = %s, map=%d, RAM Detected SerialNo[%d]='%s'\n", name ? name : "", ␊ |
329 | map, table_num, Platform.RAM.DIMM[map].SerialNo);␊ |
330 | return Platform.RAM.DIMM[map].SerialNo;␊ |
331 | ␉␉}␊ |
332 | ␉}␊ |
333 | ␉return "N/A";␊ |
334 | }␊ |
335 | ␊ |
336 | static const char *sm_get_mempartno (const char *name, int table_num)␊ |
337 | {␊ |
338 | ␉int␉map;␊ |
339 | ␊ |
340 | ␉if (table_num < MAX_RAM_SLOTS) {␊ |
341 | ␉␉map = Platform.DMI.DIMM[table_num];␊ |
342 | ␉␉if (Platform.RAM.DIMM[map].InUse && strlen(Platform.RAM.DIMM[map].PartNo) > 0) {␊ |
343 | ␉␉␉DBG("Ram Detected PartNo[%d]='%s'\n", table_num, Platform.RAM.DIMM[map].PartNo);␊ |
344 | ␉␉␉return Platform.RAM.DIMM[map].PartNo;␊ |
345 | ␉␉}␊ |
346 | ␉}␊ |
347 | ␉return "N/A";␊ |
348 | }␊ |
349 | ␊ |
350 | static int sm_one (int tablen)␊ |
351 | {␊ |
352 | ␉return 1;␊ |
353 | }␊ |
354 | ␊ |
355 | struct smbios_property smbios_properties[]=␊ |
356 | {␊ |
357 | ␉{.name="SMbiosvendor",␉␉.table_type= 0,␉.value_type=SMSTRING,␉.offset=0x04,␉.auto_str=sm_get_defstr␉},␊ |
358 | ␉{.name="SMbiosversion",␉␉.table_type= 0,␉.value_type=SMSTRING,␉.offset=0x05,␉.auto_str=sm_get_defstr␉},␊ |
359 | ␉{.name="SMbiosdate",␉␉.table_type= 0,␉.value_type=SMSTRING,␉.offset=0x08,␉.auto_str=sm_get_defstr␉},␊ |
360 | ␉{.name="SMmanufacter",␉␉.table_type= 1,␉.value_type=SMSTRING,␉.offset=0x04,␉.auto_str=sm_get_defstr␉},␊ |
361 | ␉{.name="SMproductname",␉␉.table_type= 1,␉.value_type=SMSTRING,␉.offset=0x05,␉.auto_str=sm_get_defstr␉},␊ |
362 | ␉{.name="SMsystemversion",␉.table_type= 1,␉.value_type=SMSTRING,␉.offset=0x06,␉.auto_str=sm_get_defstr␉},␊ |
363 | ␉{.name="SMserial",␉␉.table_type= 1,␉.value_type=SMSTRING,␉.offset=0x07,␉.auto_str=sm_get_defstr␉},␊ |
364 | ␉{.name="SMUUID",␉␉.table_type= 1, .value_type=SMOWORD,␉.offset=0x08,␉.auto_oword=0␉␉},␊ |
365 | ␉{.name="SMfamily",␉␉.table_type= 1,␉.value_type=SMSTRING,␉.offset=0x1a,␉.auto_str=sm_get_defstr␉},␊ |
366 | ␉{.name="SMboardmanufacter",␉.table_type= 2, .value_type=SMSTRING,␉.offset=0x04,␉.auto_str=sm_get_defstr␉},␊ |
367 | ␉{.name="SMboardproduct",␉.table_type= 2, .value_type=SMSTRING,␉.offset=0x05,␉.auto_str=sm_get_defstr␉},␊ |
368 | ␉{.name="SMexternalclock",␉.table_type= 4,␉.value_type=SMWORD,␉.offset=0x12,␉.auto_int=sm_get_fsb␉},␊ |
369 | ␉{.name="SMmaximalclock",␉.table_type= 4,␉.value_type=SMWORD,␉.offset=0x14,␉.auto_int=sm_get_cpu␉},␊ |
370 | ␉{.name="SMmemdevloc",␉␉.table_type=17,␉.value_type=SMSTRING,␉.offset=0x10,␉.auto_str=0␉␉},␊ |
371 | ␉{.name="SMmembankloc",␉␉.table_type=17,␉.value_type=SMSTRING,␉.offset=0x11,␉.auto_str=0␉␉},␊ |
372 | ␉{.name="SMmemtype",␉␉.table_type=17,␉.value_type=SMBYTE,␉.offset=0x12,␉.auto_int=sm_get_memtype},␊ |
373 | ␉{.name="SMmemspeed",␉␉.table_type=17,␉.value_type=SMWORD,␉.offset=0x15,␉.auto_int=sm_get_memspeed},␊ |
374 | ␉{.name="SMmemmanufacter",␉.table_type=17,␉.value_type=SMSTRING,␉.offset=0x17,␉.auto_str=sm_get_memvendor},␊ |
375 | ␉{.name="SMmemserial",␉␉.table_type=17,␉.value_type=SMSTRING,␉.offset=0x18,␉.auto_str=sm_get_memserial},␊ |
376 | ␉{.name="SMmempart",␉␉.table_type=17,␉.value_type=SMSTRING,␉.offset=0x1A,␉.auto_str=sm_get_mempartno},␊ |
377 | ␉{.name="SMcputype",␉␉.table_type=131,.value_type=SMWORD,␉.offset=0x04,␉.auto_int=sm_get_cputype},␊ |
378 | ␉{.name="SMbusspeed",␉␉.table_type=132,.value_type=SMWORD,␉.offset=0x04,␉.auto_int=sm_get_bus_speed}␊ |
379 | };␊ |
380 | ␊ |
381 | struct smbios_table_description smbios_table_descriptions[]=␊ |
382 | {␊ |
383 | ␉{.type=0,␉.len=0x18,␉.numfunc=sm_one},␊ |
384 | ␉{.type=1,␉.len=0x1b,␉.numfunc=sm_one},␊ |
385 | ␉{.type=2,␉.len=0x0f,␉.numfunc=sm_one},␊ |
386 | ␉{.type=4,␉.len=0x2a,␉.numfunc=sm_one},␊ |
387 | ␉{.type=17,␉.len=0x1c,␉.numfunc=0},␊ |
388 | ␉{.type=131,␉.len=0x06,␉.numfunc=sm_one},␊ |
389 | ␉{.type=132,␉.len=0x06,␉.numfunc=sm_one}␊ |
390 | };␊ |
391 | ␊ |
392 | // getting smbios addr with fast compare ops, late checksum testing ...␊ |
393 | #define COMPARE_DWORD(a,b) ( *((u_int32_t *) a) == *((u_int32_t *) b) )␊ |
394 | static const char * const SMTAG = "_SM_";␊ |
395 | static const char* const DMITAG= "_DMI_";␊ |
396 | ␊ |
397 | static struct SMBEntryPoint *getAddressOfSmbiosTable(void)␊ |
398 | {␊ |
399 | ␉struct SMBEntryPoint␉*smbios;␊ |
400 | ␉/* ␊ |
401 | ␉ * The logic is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking␊ |
402 | ␉ * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_").␊ |
403 | ␉ */␊ |
404 | ␉smbios = (struct SMBEntryPoint*) SMBIOS_RANGE_START;␊ |
405 | ␉while (smbios <= (struct SMBEntryPoint *)SMBIOS_RANGE_END) {␊ |
406 | if (COMPARE_DWORD(smbios->anchor, SMTAG) && ␊ |
407 | COMPARE_DWORD(smbios->dmi.anchor, DMITAG) &&␊ |
408 | smbios->dmi.anchor[4]==DMITAG[4] &&␊ |
409 | checksum8(smbios, sizeof(struct SMBEntryPoint)) == 0)␊ |
410 | ␉ {␊ |
411 | return smbios;␊ |
412 | ␉ }␊ |
413 | smbios = (struct SMBEntryPoint*) ( ((char*) smbios) + 16 );␊ |
414 | ␉}␊ |
415 | ␉printf("ERROR: Unable to find SMBIOS!\n");␊ |
416 | ␉pause();␊ |
417 | ␉return NULL;␊ |
418 | }␊ |
419 | ␊ |
420 | /** Compute necessary space requirements for new smbios */␊ |
421 | static struct SMBEntryPoint *smbios_dry_run(struct SMBEntryPoint *origsmbios)␊ |
422 | {␊ |
423 | ␉struct SMBEntryPoint␉*ret;␊ |
424 | ␉char␉␉␉*smbiostables;␊ |
425 | ␉char␉␉␉*tablesptr;␊ |
426 | ␉int␉␉␉origsmbiosnum;␊ |
427 | ␉int␉␉␉i, j;␊ |
428 | ␉int␉␉␉tablespresent[256];␊ |
429 | ␉bool␉␉␉do_auto=true;␊ |
430 | ␊ |
431 | ␉bzero(tablespresent, sizeof(tablespresent));␊ |
432 | ␊ |
433 | ␉getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig);␊ |
434 | ␊ |
435 | ␉ret = (struct SMBEntryPoint *)AllocateKernelMemory(sizeof(struct SMBEntryPoint));␊ |
436 | ␉if (origsmbios) {␊ |
437 | ␉␉smbiostables = (char *)origsmbios->dmi.tableAddress;␊ |
438 | ␉␉origsmbiosnum = origsmbios->dmi.structureCount;␊ |
439 | ␉} else {␊ |
440 | ␉␉smbiostables = NULL;␊ |
441 | ␉␉origsmbiosnum = 0;␊ |
442 | ␉}␊ |
443 | ␊ |
444 | ␉// _SM_␊ |
445 | ␉ret->anchor[0] = 0x5f;␊ |
446 | ␉ret->anchor[1] = 0x53;␊ |
447 | ␉ret->anchor[2] = 0x4d;␊ |
448 | ␉ret->anchor[3] = 0x5f; ␊ |
449 | ␉ret->entryPointLength = sizeof(*ret);␊ |
450 | ␉ret->majorVersion = 2;␊ |
451 | ␉ret->minorVersion = 1;␊ |
452 | ␉ret->maxStructureSize = 0; // will be calculated later in this function␊ |
453 | ␉ret->entryPointRevision = 0;␊ |
454 | ␉for (i=0;i<5;i++) {␊ |
455 | ␉␉ret->formattedArea[i] = 0;␊ |
456 | ␉}␊ |
457 | ␉//_DMI_␊ |
458 | ␉ret->dmi.anchor[0] = 0x5f;␊ |
459 | ␉ret->dmi.anchor[1] = 0x44;␊ |
460 | ␉ret->dmi.anchor[2] = 0x4d;␊ |
461 | ␉ret->dmi.anchor[3] = 0x49;␊ |
462 | ␉ret->dmi.anchor[4] = 0x5f;␊ |
463 | ␉ret->dmi.tableLength = 0; // will be calculated later in this function␊ |
464 | ␉ret->dmi.tableAddress = 0; // will be initialized in smbios_real_run()␊ |
465 | ␉ret->dmi.structureCount = 0; // will be calculated later in this function␊ |
466 | ␉ret->dmi.bcdRevision = 0x21;␊ |
467 | ␉tablesptr = smbiostables;␊ |
468 | ␊ |
469 | // add stringlen of overrides to original stringlen, update maxStructure size adequately, ␊ |
470 | // update structure count and tablepresent[type] with count of type. ␊ |
471 | ␉if (smbiostables) {␊ |
472 | ␉␉for (i=0; i<origsmbiosnum; i++) {␊ |
473 | ␉␉␉struct smbios_table_header␉*cur = (struct smbios_table_header *)tablesptr;␊ |
474 | ␉␉␉char␉␉␉␉*stringsptr;␊ |
475 | ␉␉␉int␉␉␉␉stringlen;␊ |
476 | ␊ |
477 | ␉␉␉tablesptr += cur->length;␊ |
478 | ␉␉␉stringsptr = tablesptr;␊ |
479 | ␉␉␉for (; tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++);␊ |
480 | ␉␉␉tablesptr += 2;␊ |
481 | ␉␉␉stringlen = tablesptr - stringsptr - 1;␊ |
482 | ␉␉␉if (stringlen == 1) {␊ |
483 | ␉␉␉␉stringlen = 0;␊ |
484 | ␉␉␉}␊ |
485 | ␉␉␉for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {␊ |
486 | ␉␉␉␉const char␉*str;␊ |
487 | ␉␉␉␉int␉␉size;␊ |
488 | ␉␉␉␉char␉␉altname[40];␊ |
489 | ␊ |
490 | ␉␉␉␉sprintf(altname, "%s_%d",smbios_properties[j].name, tablespresent[cur->type] + 1);␉␉␉␉␊ |
491 | ␉␉␉␉if (smbios_properties[j].table_type == cur->type &&␊ |
492 | ␉␉␉␉ smbios_properties[j].value_type == SMSTRING &&␊ |
493 | ␉␉␉␉ (getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig) ||␊ |
494 | ␉␉␉␉ getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig)))␊ |
495 | ␉␉␉␉{␊ |
496 | ␉␉␉␉␉stringlen += size + 1;␊ |
497 | ␉␉␉␉} else if (smbios_properties[j].table_type == cur->type &&␊ |
498 | ␉␉␉␉ smbios_properties[j].value_type == SMSTRING &&␊ |
499 | ␉␉␉␉ do_auto && smbios_properties[j].auto_str)␊ |
500 | ␉␉␉␉{␊ |
501 | ␉␉␉␉␉stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[cur->type])) + 1;␊ |
502 | ␉␉␉␉}␊ |
503 | ␉␉␉}␊ |
504 | ␉␉␉if (stringlen == 0) {␊ |
505 | ␉␉␉␉stringlen = 1;␊ |
506 | ␉␉␉}␊ |
507 | ␉␉␉stringlen++;␊ |
508 | ␉␉␉if (ret->maxStructureSize < cur->length+stringlen) {␊ |
509 | ␉␉␉␉ret->maxStructureSize=cur->length+stringlen;␊ |
510 | ␉␉␉}␊ |
511 | ␉␉␉ret->dmi.tableLength += cur->length+stringlen;␊ |
512 | ␉␉␉ret->dmi.structureCount++;␊ |
513 | ␉␉␉tablespresent[cur->type]++;␊ |
514 | ␉␉}␊ |
515 | ␉}␊ |
516 | // Add eventually table types whose detected count would be < required count, and update ret header with:␊ |
517 | // new stringlen addons, structure count, and tablepresent[type] count adequately␊ |
518 | ␉for (i=0; i<sizeof(smbios_table_descriptions)/sizeof(smbios_table_descriptions[0]); i++) {␊ |
519 | ␉␉int␉numnec=-1;␊ |
520 | ␉␉char␉buffer[40];␊ |
521 | ␊ |
522 | ␉␉sprintf(buffer, "SMtable%d", i);␊ |
523 | ␉␉if (!getIntForKey(buffer, &numnec, &bootInfo->smbiosConfig)) {␊ |
524 | ␉␉␉numnec = -1;␊ |
525 | ␉␉}␊ |
526 | ␉␉if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) {␊ |
527 | ␉␉␉numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type);␊ |
528 | ␉␉}␊ |
529 | ␉␉while (tablespresent[smbios_table_descriptions[i].type] < numnec) {␊ |
530 | ␉␉␉int␉stringlen = 0;␊ |
531 | ␉␉␉for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {␊ |
532 | ␉␉␉␉const char␉*str;␊ |
533 | ␉␉␉␉int␉␉size;␊ |
534 | ␉␉␉␉char␉␉altname[40];␊ |
535 | ␊ |
536 | ␉␉␉␉sprintf(altname, "%s_%d",smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type] + 1);␊ |
537 | ␉␉␉␉if (smbios_properties[j].table_type == smbios_table_descriptions[i].type &&␊ |
538 | ␉␉␉␉ smbios_properties[j].value_type == SMSTRING &&␊ |
539 | ␉␉␉␉ (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||␊ |
540 | ␉␉␉␉ getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)))␊ |
541 | ␉␉␉␉{␊ |
542 | ␉␉␉␉␉stringlen += size + 1;␊ |
543 | ␉␉␉␉} else if (smbios_properties[j].table_type == smbios_table_descriptions[i].type &&␊ |
544 | ␉␉␉␉ smbios_properties[j].value_type==SMSTRING &&␊ |
545 | ␉␉␉␉ do_auto && smbios_properties[j].auto_str)␊ |
546 | ␉␉␉␉{␊ |
547 | ␉␉␉␉␉stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type])) + 1;␊ |
548 | ␉␉␉␉}␊ |
549 | ␉␉␉}␊ |
550 | ␉␉␉if (stringlen == 0) {␊ |
551 | ␉␉␉␉stringlen = 1;␊ |
552 | ␉␉␉}␊ |
553 | ␉␉␉stringlen++;␊ |
554 | ␉␉␉if (ret->maxStructureSize < smbios_table_descriptions[i].len+stringlen) {␊ |
555 | ␉␉␉␉ret->maxStructureSize = smbios_table_descriptions[i].len + stringlen;␊ |
556 | ␉␉␉}␊ |
557 | ␉␉␉ret->dmi.tableLength += smbios_table_descriptions[i].len + stringlen;␊ |
558 | ␉␉␉ret->dmi.structureCount++;␊ |
559 | ␉␉␉tablespresent[smbios_table_descriptions[i].type]++;␊ |
560 | ␉␉}␊ |
561 | ␉}␊ |
562 | ␉return ret;␊ |
563 | }␊ |
564 | ␊ |
565 | /** From the origsmbios detected by getAddressOfSmbiosTable() to newsmbios whose entrypoint ␊ |
566 | * struct has been created by smbios_dry_run, update each table struct content of new smbios␊ |
567 | * int the new allocated table address of size newsmbios->tablelength.␊ |
568 | */␊ |
569 | static void smbios_real_run(struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios)␊ |
570 | {␊ |
571 | ␉char *smbiostables;␊ |
572 | ␉char *tablesptr, *newtablesptr;␊ |
573 | ␉int origsmbiosnum;␊ |
574 | ␉// bitmask of used handles␊ |
575 | ␉uint8_t handles[8192]; ␊ |
576 | ␉uint16_t nexthandle=0;␊ |
577 | ␉int i, j;␊ |
578 | ␉int tablespresent[256];␊ |
579 | ␉bool do_auto=true;␊ |
580 | ␉␊ |
581 | static bool done = false; // IMPROVEME: called twice via getSmbios(), but only the second call can get all necessary info !␊ |
582 | ␊ |
583 | ␉extern void dumpPhysAddr(const char * title, void * a, int len);␊ |
584 | ␉␊ |
585 | ␉bzero(tablespresent, sizeof(tablespresent));␊ |
586 | ␉bzero(handles, sizeof(handles));␊ |
587 | ␊ |
588 | ␉getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig);␊ |
589 | ␉␊ |
590 | ␉newsmbios->dmi.tableAddress = (uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength);␊ |
591 | ␉if (origsmbios) {␊ |
592 | ␉␉smbiostables = (char *)origsmbios->dmi.tableAddress;␊ |
593 | ␉␉origsmbiosnum = origsmbios->dmi.structureCount;␊ |
594 | ␉} else {␊ |
595 | ␉␉smbiostables = NULL;␊ |
596 | ␉␉origsmbiosnum = 0;␊ |
597 | ␉}␊ |
598 | ␉tablesptr = smbiostables;␊ |
599 | ␉newtablesptr = (char *)newsmbios->dmi.tableAddress;␊ |
600 | ␊ |
601 | // if old smbios exists then update new smbios with old smbios original content first␊ |
602 | ␉if (smbiostables) {␊ |
603 | ␉␉for (i=0; i<origsmbiosnum; i++) {␊ |
604 | ␉␉␉struct smbios_table_header␉*oldcur = (struct smbios_table_header *) tablesptr;␊ |
605 | ␉␉␉struct smbios_table_header␉*newcur = (struct smbios_table_header *) newtablesptr;␊ |
606 | ␉␉␉char␉␉␉␉*stringsptr;␊ |
607 | ␉␉␉int␉␉␉␉nstrings = 0;␊ |
608 | ␊ |
609 | ␉␉␉handles[(oldcur->handle) / 8] |= 1 << ((oldcur->handle) % 8);␊ |
610 | ␊ |
611 | // copy table length from old table to new table but not the old strings␊ |
612 | ␉␉␉memcpy(newcur,oldcur, oldcur->length);␊ |
613 | ␊ |
614 | ␉␉␉tablesptr += oldcur->length;␊ |
615 | ␉␉␉stringsptr = tablesptr;␊ |
616 | ␉␉␉newtablesptr += oldcur->length;␊ |
617 | ␊ |
618 | // calculate the number of strings in the old content␊ |
619 | ␉␉␉for (;tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++) {␊ |
620 | ␉␉␉␉if (tablesptr[0] == 0) {␊ |
621 | ␉␉␉␉␉nstrings++;␊ |
622 | ␉␉␉␉}␊ |
623 | ␉␉␉}␊ |
624 | ␉␉␉if (tablesptr != stringsptr) {␊ |
625 | ␉␉␉␉nstrings++;␊ |
626 | ␉␉␉}␊ |
627 | ␉␉␉tablesptr += 2;␊ |
628 | ␊ |
629 | // copy the old strings to new table␊ |
630 | ␉␉␉memcpy(newtablesptr, stringsptr, tablesptr-stringsptr);␊ |
631 | ␊ |
632 | ␉␉␉// point to next possible space for a string (deducting the second 0 char at the end)␊ |
633 | ␉␉␉newtablesptr += tablesptr - stringsptr - 1;␊ |
634 | if (nstrings == 0) { // if no string was found rewind to the first 0 char of the 0,0 terminator␊ |
635 | ␉␉␉␉newtablesptr--;␊ |
636 | ␉␉␉}␊ |
637 | ␊ |
638 | // now for each property in the table update the overrides if any (auto or user)␊ |
639 | ␉␉␉for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {␊ |
640 | ␉␉␉␉const char␉*str;␊ |
641 | ␉␉␉␉int␉␉size;␊ |
642 | ␉␉␉␉int␉␉num;␊ |
643 | ␉␉␉␉char␉␉altname[40];␊ |
644 | ␊ |
645 | ␉␉␉␉sprintf(altname, "%s_%d", smbios_properties[j].name, tablespresent[newcur->type] + 1);␊ |
646 | ␉␉␉␉if (smbios_properties[j].table_type == newcur->type) {␊ |
647 | ␉␉␉␉␉switch (smbios_properties[j].value_type) {␊ |
648 | ␉␉␉␉␉case SMSTRING:␊ |
649 | ␉␉␉␉␉␉if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||␊ |
650 | ␉␉␉␉␉␉ getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))␊ |
651 | ␉␉␉␉␉␉{␊ |
652 | ␉␉␉␉␉␉␉memcpy(newtablesptr, str, size);␊ |
653 | ␉␉␉␉␉␉␉newtablesptr[size] = 0;␊ |
654 | ␉␉␉␉␉␉␉newtablesptr += size + 1;␊ |
655 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;␊ |
656 | ␉␉␉␉␉␉} else if (do_auto && smbios_properties[j].auto_str) {␊ |
657 | ␉␉␉␉␉␉␉str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]);␊ |
658 | ␉␉␉␉␉␉␉size = strlen(str);␊ |
659 | ␉␉␉␉␉␉␉memcpy(newtablesptr, str, size);␊ |
660 | ␉␉␉␉␉␉␉newtablesptr[size] = 0;␊ |
661 | ␉␉␉␉␉␉␉newtablesptr += size + 1;␊ |
662 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;␊ |
663 | ␉␉␉␉␉␉}␊ |
664 | ␉␉␉␉␉␉break;␊ |
665 | ␊ |
666 | ␉␉␉␉␉case SMOWORD:␊ |
667 | ␉␉␉␉␉␉if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||␊ |
668 | ␉␉␉␉␉␉ getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))␊ |
669 | ␉␉␉␉␉␉{␊ |
670 | ␉␉␉␉␉␉␉int␉␉k=0, t=0, kk=0;␊ |
671 | ␉␉␉␉␉␉␉const char␉*ptr = str;␊ |
672 | ␉␉␉␉␉␉␉memset(((char*)newcur) + smbios_properties[j].offset, 0, 16);␊ |
673 | ␉␉␉␉␉␉␉while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) {␊ |
674 | ␉␉␉␉␉␉␉␉ptr++;␊ |
675 | ␉␉␉␉␉␉␉}␊ |
676 | ␉␉␉␉␉␉␉if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) {␊ |
677 | ␉␉␉␉␉␉␉␉ptr += 2;␊ |
678 | ␉␉␉␉␉␉␉}␊ |
679 | ␉␉␉␉␉␉␉for (;ptr-str<size && *ptr && k<16;ptr++) {␊ |
680 | ␉␉␉␉␉␉␉␉if (*ptr>='0' && *ptr<='9') {␊ |
681 | ␉␉␉␉␉␉␉␉␉(t=(t<<4)|(*ptr-'0')),kk++;␊ |
682 | ␉␉␉␉␉␉␉␉}␊ |
683 | ␉␉␉␉␉␉␉␉if (*ptr>='a' && *ptr<='f') {␊ |
684 | ␉␉␉␉␉␉␉␉␉(t=(t<<4)|(*ptr-'a'+10)),kk++;␊ |
685 | ␉␉␉␉␉␉␉␉}␊ |
686 | ␉␉␉␉␉␉␉␉if (*ptr>='A' && *ptr<='F') {␊ |
687 | ␉␉␉␉␉␉␉␉␉(t=(t<<4)|(*ptr-'A'+10)),kk++;␊ |
688 | ␉␉␉␉␉␉␉␉}␊ |
689 | ␉␉␉␉␉␉␉␉if (kk == 2) {␊ |
690 | ␉␉␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t;␊ |
691 | ␉␉␉␉␉␉␉␉␉k++;␊ |
692 | ␉␉␉␉␉␉␉␉␉kk = 0;␊ |
693 | ␉␉␉␉␉␉␉␉␉t = 0;␊ |
694 | ␉␉␉␉␉␉␉␉}␊ |
695 | ␉␉␉␉␉␉␉}␊ |
696 | ␉␉␉␉␉␉}␊ |
697 | ␉␉␉␉␉␉break;␊ |
698 | ␊ |
699 | ␉␉␉␉␉case SMBYTE:␊ |
700 | ␉␉␉␉␉␉if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||␊ |
701 | ␉␉␉␉␉␉ getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))␊ |
702 | ␉␉␉␉␉␉{␊ |
703 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;␊ |
704 | ␉␉␉␉␉␉} else if (do_auto && smbios_properties[j].auto_int) {␊ |
705 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);␉␉␉␉␉␉␉␊ |
706 | ␉␉␉␉␉␉}␊ |
707 | ␉␉␉␉␉␉break;␊ |
708 | ␊ |
709 | ␉␉␉␉␉case SMWORD:␊ |
710 | ␉␉␉␉␉␉if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||␊ |
711 | ␉␉␉␉␉␉ getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))␊ |
712 | ␉␉␉␉␉␉{␊ |
713 | ␉␉␉␉␉␉␉*((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;␊ |
714 | ␉␉␉␉␉␉} else if (do_auto && smbios_properties[j].auto_int) {␊ |
715 | ␉␉␉␉␉␉␉*((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);␊ |
716 | ␉␉␉␉␉␉}␊ |
717 | ␉␉␉␉␉␉break;␊ |
718 | ␉␉␉␉␉}␊ |
719 | ␉␉␉␉}␊ |
720 | ␉␉␉}␊ |
721 | ␉␉␉if (nstrings == 0) {␊ |
722 | ␉␉␉␉newtablesptr[0] = 0;␊ |
723 | ␉␉␉␉newtablesptr++;␊ |
724 | ␉␉␉}␊ |
725 | ␉␉␉newtablesptr[0] = 0;␊ |
726 | ␉␉␉newtablesptr++;␊ |
727 | ␉␉␉tablespresent[newcur->type]++;␊ |
728 | ␉␉}␊ |
729 | ␉}␊ |
730 | ␊ |
731 | // for each eventual complementary table not present in the original smbios, do the overrides␊ |
732 | ␉for (i=0; i<sizeof(smbios_table_descriptions)/sizeof(smbios_table_descriptions[0]); i++) {␊ |
733 | ␉␉int␉numnec = -1;␊ |
734 | ␉␉char␉buffer[40];␊ |
735 | ␊ |
736 | ␉␉sprintf(buffer, "SMtable%d", i);␊ |
737 | ␉␉if (!getIntForKey(buffer, &numnec, &bootInfo->smbiosConfig)) {␊ |
738 | ␉␉␉numnec = -1;␊ |
739 | ␉␉}␊ |
740 | ␉␉if (numnec == -1 && do_auto && smbios_table_descriptions[i].numfunc) {␊ |
741 | ␉␉␉numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type);␊ |
742 | ␉␉}␊ |
743 | ␉␉while (tablespresent[smbios_table_descriptions[i].type] < numnec) {␊ |
744 | ␉␉␉struct smbios_table_header␉*newcur = (struct smbios_table_header *) newtablesptr;␊ |
745 | ␉␉␉int␉␉␉␉nstrings = 0;␊ |
746 | ␊ |
747 | ␉␉␉memset(newcur,0, smbios_table_descriptions[i].len);␊ |
748 | ␉␉␉while (handles[(nexthandle)/8] & (1 << ((nexthandle) % 8))) {␊ |
749 | ␉␉␉␉nexthandle++;␊ |
750 | ␉␉␉}␊ |
751 | ␉␉␉newcur->handle = nexthandle;␊ |
752 | ␉␉␉handles[nexthandle / 8] |= 1 << (nexthandle % 8);␊ |
753 | ␉␉␉newcur->type = smbios_table_descriptions[i].type;␊ |
754 | ␉␉␉newcur->length = smbios_table_descriptions[i].len;␊ |
755 | ␉␉␉newtablesptr += smbios_table_descriptions[i].len;␊ |
756 | ␉␉␉for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) {␊ |
757 | ␉␉␉␉const char␉*str;␊ |
758 | ␉␉␉␉int␉␉size;␊ |
759 | ␉␉␉␉int␉␉num;␊ |
760 | ␉␉␉␉char␉␉altname[40];␊ |
761 | ␊ |
762 | ␉␉␉␉sprintf(altname, "%s_%d", smbios_properties[j].name, tablespresent[newcur->type] + 1);␊ |
763 | ␉␉␉␉if (smbios_properties[j].table_type == newcur->type) {␊ |
764 | ␉␉␉␉␉switch (smbios_properties[j].value_type) {␊ |
765 | ␉␉␉␉␉case SMSTRING:␊ |
766 | ␉␉␉␉␉␉if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||␊ |
767 | ␉␉␉␉␉␉ getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))␊ |
768 | ␉␉␉␉␉␉{␊ |
769 | ␉␉␉␉␉␉␉memcpy(newtablesptr, str, size);␊ |
770 | ␉␉␉␉␉␉␉newtablesptr[size] = 0;␊ |
771 | ␉␉␉␉␉␉␉newtablesptr += size + 1;␊ |
772 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;␊ |
773 | ␉␉␉␉␉␉} else if (do_auto && smbios_properties[j].auto_str) {␊ |
774 | ␉␉␉␉␉␉␉str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]);␊ |
775 | ␉␉␉␉␉␉␉size = strlen(str);␊ |
776 | ␉␉␉␉␉␉␉memcpy(newtablesptr, str, size);␊ |
777 | ␉␉␉␉␉␉␉newtablesptr[size] = 0;␊ |
778 | ␉␉␉␉␉␉␉newtablesptr += size + 1;␊ |
779 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings;␊ |
780 | ␉␉␉␉␉␉}␊ |
781 | ␉␉␉␉␉␉break;␊ |
782 | ␊ |
783 | ␉␉␉␉␉case SMOWORD:␊ |
784 | ␉␉␉␉␉␉if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) ||␊ |
785 | ␉␉␉␉␉␉ getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))␊ |
786 | ␉␉␉␉␉␉{␊ |
787 | ␉␉␉␉␉␉␉int␉␉k=0, t=0, kk=0;␊ |
788 | ␉␉␉␉␉␉␉const char␉*ptr = str;␊ |
789 | ␊ |
790 | ␉␉␉␉␉␉␉memset(((char*)newcur) + smbios_properties[j].offset, 0, 16);␊ |
791 | ␉␉␉␉␉␉␉while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) {␊ |
792 | ␉␉␉␉␉␉␉␉ptr++;␊ |
793 | ␉␉␉␉␉␉␉}␊ |
794 | ␉␉␉␉␉␉␉if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) {␊ |
795 | ␉␉␉␉␉␉␉␉ptr += 2;␊ |
796 | ␉␉␉␉␉␉␉}␊ |
797 | ␉␉␉␉␉␉␉for (;ptr-str<size && *ptr && k<16;ptr++) {␊ |
798 | ␉␉␉␉␉␉␉␉if (*ptr>='0' && *ptr<='9') {␊ |
799 | ␉␉␉␉␉␉␉␉␉(t=(t<<4)|(*ptr-'0')),kk++;␊ |
800 | ␉␉␉␉␉␉␉␉}␊ |
801 | ␉␉␉␉␉␉␉␉if (*ptr>='a' && *ptr<='f') {␊ |
802 | ␉␉␉␉␉␉␉␉␉(t=(t<<4)|(*ptr-'a'+10)),kk++;␊ |
803 | ␉␉␉␉␉␉␉␉}␊ |
804 | ␉␉␉␉␉␉␉␉if (*ptr>='A' && *ptr<='F') {␊ |
805 | ␉␉␉␉␉␉␉␉␉(t=(t<<4)|(*ptr-'A'+10)),kk++;␊ |
806 | ␉␉␉␉␉␉␉␉}␊ |
807 | ␉␉␉␉␉␉␉␉if (kk == 2) {␊ |
808 | ␉␉␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t;␊ |
809 | ␉␉␉␉␉␉␉␉␉k++;␊ |
810 | ␉␉␉␉␉␉␉␉␉kk = 0;␊ |
811 | ␉␉␉␉␉␉␉␉␉t = 0;␊ |
812 | ␉␉␉␉␉␉␉␉}␊ |
813 | ␉␉␉␉␉␉␉}␊ |
814 | ␉␉␉␉␉␉}␊ |
815 | ␉␉␉␉␉␉break;␊ |
816 | ␉␉␉␉␉␉␊ |
817 | ␉␉␉␉␉case SMBYTE:␊ |
818 | ␉␉␉␉␉␉if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||␊ |
819 | ␉␉␉␉␉␉ getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))␊ |
820 | ␉␉␉␉␉␉{␊ |
821 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;␊ |
822 | ␉␉␉␉␉␉} else if (do_auto && smbios_properties[j].auto_int) {␊ |
823 | ␉␉␉␉␉␉␉*((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);␊ |
824 | ␉␉␉␉␉␉}␊ |
825 | ␉␉␉␉␉␉break;␊ |
826 | ␉␉␉␉␉␉␊ |
827 | ␉␉␉␉␉case SMWORD:␊ |
828 | ␉␉␉␉␉␉if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) ||␊ |
829 | ␉␉␉␉␉␉ getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig))␊ |
830 | ␉␉␉␉␉␉{␊ |
831 | ␉␉␉␉␉␉␉*((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num;␊ |
832 | ␉␉␉␉␉␉} else if (do_auto && smbios_properties[j].auto_int) {␊ |
833 | ␉␉␉␉␉␉␉*((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]);␊ |
834 | ␉␉␉␉␉␉}␊ |
835 | ␉␉␉␉␉␉break;␊ |
836 | ␉␉␉␉␉}␊ |
837 | ␉␉␉␉}␊ |
838 | ␉␉␉}␊ |
839 | ␉␉␉if (nstrings == 0) {␊ |
840 | ␉␉␉␉newtablesptr[0] = 0;␊ |
841 | ␉␉␉␉newtablesptr++;␊ |
842 | ␉␉␉}␊ |
843 | ␉␉␉newtablesptr[0] = 0;␊ |
844 | ␉␉␉newtablesptr++;␊ |
845 | ␉␉␉tablespresent[smbios_table_descriptions[i].type]++;␊ |
846 | ␉␉}␊ |
847 | ␉}␊ |
848 | ␊ |
849 | // calculate new checksums␊ |
850 | ␉newsmbios->dmi.checksum = 0;␊ |
851 | ␉newsmbios->dmi.checksum = 256 - checksum8(&newsmbios->dmi, sizeof(newsmbios->dmi));␊ |
852 | ␉newsmbios->checksum = 0;␊ |
853 | ␉newsmbios->checksum = 256 - checksum8(newsmbios, sizeof(*newsmbios));␊ |
854 | ␉␊ |
855 | ␉if (!done) {␊ |
856 | ␉␉verbose("Patched DMI Table\n");␊ |
857 | ␉␉done=true;␊ |
858 | ␉}␊ |
859 | }␊ |
860 | ␊ |
861 | #define MAX_DMI_TABLES 96␊ |
862 | typedef struct DmiNumAssocTag {␊ |
863 | struct DMIHeader * dmi;␊ |
864 | uint8_t type;␊ |
865 | } DmiNumAssoc;␊ |
866 | ␊ |
867 | static DmiNumAssoc DmiTablePair[MAX_DMI_TABLES];␊ |
868 | static int DmiTablePairCount = 0;␊ |
869 | static int current_pos=0;␊ |
870 | static bool ftTablePairInit = true;␊ |
871 | ␊ |
872 | /** ␊ |
873 | * Get a table structure entry from a type specification and a smbios address␊ |
874 | * return NULL if table is not found␊ |
875 | */␊ |
876 | static void getSmbiosTableStructure(struct SMBEntryPoint *smbios)␊ |
877 | {␊ |
878 | struct DMIHeader * dmihdr=NULL;␊ |
879 | SMBByte* p;␊ |
880 | int i;␊ |
881 | ␊ |
882 | if (ftTablePairInit && smbios!=NULL) {␊ |
883 | ftTablePairInit = false;␊ |
884 | #if DEBUG_SMBIOS␊ |
885 | printf(">>> SMBIOSAddr=0x%08x\n", smbios);␊ |
886 | printf(">>> DMI: addr=0x%08x, len=%d, count=%d\n", smbios->dmi.tableAddress, ␊ |
887 | smbios->dmi.tableLength, smbios->dmi.structureCount);␊ |
888 | #endif␊ |
889 | p = (SMBByte *) smbios->dmi.tableAddress;␊ |
890 | for (i=0; ␊ |
891 | i < smbios->dmi.structureCount && ␊ |
892 | p + 4 <= (SMBByte *)smbios->dmi.tableAddress + smbios->dmi.tableLength; ␊ |
893 | i++) {␊ |
894 | dmihdr = (struct DMIHeader *) p;␊ |
895 | ␊ |
896 | #if DEBUG_SMBIOS␊ |
897 | // verbose(">>>>>> DMI(%d): type=0x%02x, len=0x%d\n",i,dmihdr->type,dmihdr->length);␊ |
898 | #endif␊ |
899 | if (dmihdr->length < 4 || dmihdr->type == 127 /* EOT */) break;␊ |
900 | if (DmiTablePairCount < MAX_DMI_TABLES) {␊ |
901 | DmiTablePair[DmiTablePairCount].dmi = dmihdr;␊ |
902 | DmiTablePair[DmiTablePairCount].type = dmihdr->type;␊ |
903 | DmiTablePairCount++;␊ |
904 | }␊ |
905 | else {␊ |
906 | printf("DMI table entries list is full! Next entries won't be stored.\n");␊ |
907 | }␊ |
908 | #if DEBUG_SMBIOS␊ |
909 | printf("DMI header found for table type %d, length = %d\n", dmihdr->type, dmihdr->length);␊ |
910 | #endif␊ |
911 | p = p + dmihdr->length;␊ |
912 | while ((p - (SMBByte *)smbios->dmi.tableAddress + 1 < smbios->dmi.tableLength) && (p[0] != 0x00 || p[1] != 0x00)) {␊ |
913 | p++;␊ |
914 | ␉ }␊ |
915 | p += 2;␊ |
916 | ␉}␊ |
917 | ␊ |
918 | }␊ |
919 | }␊ |
920 | ␊ |
921 | /** Get original or new smbios entry point, if sucessful, the adresses are cached for next time */␊ |
922 | struct SMBEntryPoint *getSmbios(int which)␊ |
923 | {␊ |
924 | static struct SMBEntryPoint *orig = NULL; // cached␊ |
925 | static struct SMBEntryPoint *patched = NULL; // cached␊ |
926 | ␊ |
927 | // whatever we are called with orig or new flag, initialize asap both structures␊ |
928 | switch (which) {␊ |
929 | case SMBIOS_ORIGINAL:␊ |
930 | if (orig==NULL) {␊ |
931 | orig = getAddressOfSmbiosTable();␊ |
932 | getSmbiosTableStructure(orig); // generate tables entry list for fast table finding␊ |
933 | }␊ |
934 | return orig;␊ |
935 | case SMBIOS_PATCHED:␊ |
936 | if (orig==NULL && (orig = getAddressOfSmbiosTable())==NULL ) {␊ |
937 | printf("Could not find original SMBIOS !!\n");␊ |
938 | pause();␊ |
939 | } else {␊ |
940 | patched = smbios_dry_run(orig);␊ |
941 | if(patched==NULL) {␊ |
942 | printf("Could not create new SMBIOS !!\n");␊ |
943 | pause();␊ |
944 | }␊ |
945 | else {␊ |
946 | smbios_real_run(orig, patched);␊ |
947 | }␊ |
948 | }␊ |
949 | ␊ |
950 | return patched;␊ |
951 | default:␊ |
952 | printf("ERROR: invalid option for getSmbios() !!\n");␊ |
953 | break;␊ |
954 | }␊ |
955 | ␊ |
956 | return NULL;␊ |
957 | }␊ |
958 | ␊ |
959 | /** Find first original dmi Table with a particular type */␊ |
960 | struct DMIHeader* FindFirstDmiTableOfType(int type, int minlength)␊ |
961 | {␊ |
962 | current_pos = 0;␊ |
963 | ␊ |
964 | return FindNextDmiTableOfType(type, minlength);␊ |
965 | };␊ |
966 | ␊ |
967 | /** Find next original dmi Table with a particular type */␊ |
968 | struct DMIHeader* FindNextDmiTableOfType(int type, int minlength)␊ |
969 | {␊ |
970 | int i;␊ |
971 | ␊ |
972 | if (ftTablePairInit) getSmbios(SMBIOS_ORIGINAL);␊ |
973 | ␊ |
974 | for (i=current_pos; i < DmiTablePairCount; i++) {␊ |
975 | if (type == DmiTablePair[i].type && ␊ |
976 | DmiTablePair[i].dmi &&␊ |
977 | DmiTablePair[i].dmi->length >= minlength ) {␊ |
978 | current_pos = i+1;␊ |
979 | return DmiTablePair[i].dmi;␊ |
980 | }␊ |
981 | }␊ |
982 | return NULL; // not found␊ |
983 | };␊ |
984 | ␊ |
985 | |