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