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