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