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