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