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