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