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