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