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