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