1 | /*␊ |
2 | * SMBIOS Table Patcher, part of the Chameleon Boot Loader Project␊ |
3 | *␊ |
4 | * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.␊ |
5 | *␊ |
6 | */␊ |
7 | ␊ |
8 | ␊ |
9 | #include "boot.h"␊ |
10 | #include "bootstruct.h"␊ |
11 | #include "smbios_getters.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_SMBIOS␊ |
14 | #define DEBUG_SMBIOS 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_SMBIOS==2␊ |
18 | #define DBG(x...)␉printf(x)␊ |
19 | #elif DEBUG_SMBIOS==1␊ |
20 | #define DBG(x...) msglog(x)␊ |
21 | #else␊ |
22 | #define DBG(x...)␉␊ |
23 | #endif␊ |
24 | ␊ |
25 | #define SMBPlist␉␉␉&bootInfo->smbiosConfig␊ |
26 | /* ASSUMPTION: 16KB should be enough for the whole thing */␊ |
27 | #define SMB_ALLOC_SIZE␉16384␊ |
28 | ␊ |
29 | ␊ |
30 | //-------------------------------------------------------------------------------------------------------------------------␊ |
31 | // SMBIOS Plist Keys␊ |
32 | //-------------------------------------------------------------------------------------------------------------------------␊ |
33 | /* BIOS Information */␊ |
34 | #define kSMBBIOSInformationVendorKey␉␉␉␉"SMbiosvendor"␊ |
35 | #define kSMBBIOSInformationVersionKey␉␉␉␉"SMbiosversion"␊ |
36 | #define kSMBBIOSInformationReleaseDateKey␉␉␉"SMbiosdate"␊ |
37 | ␊ |
38 | /* System Information */␊ |
39 | #define kSMBSystemInformationManufacturerKey␉␉"SMmanufacturer"␊ |
40 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
41 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
42 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
43 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
44 | ␊ |
45 | /* Base Board */␊ |
46 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacturer"␊ |
47 | #define kSMBBaseBoardProductKey␉␉␉␉␉␉"SMboardproduct"␊ |
48 | ␊ |
49 | /* Processor Information */␊ |
50 | #define kSMBProcessorInformationExternalClockKey␉"SMexternalclock"␊ |
51 | #define kSMBProcessorInformationMaximumClockKey␉␉"SMmaximalclock"␊ |
52 | ␊ |
53 | /* Memory Device */␊ |
54 | #define kSMBMemoryDeviceDeviceLocatorKey␉␉␉"SMmemdevloc"␊ |
55 | #define kSMBMemoryDeviceBankLocatorKey␉␉␉␉"SMmembankloc"␊ |
56 | #define kSMBMemoryDeviceMemoryTypeKey␉␉␉␉"SMmemtype"␊ |
57 | #define kSMBMemoryDeviceMemorySpeedKey␉␉␉␉"SMmemspeed"␊ |
58 | #define kSMBMemoryDeviceManufacturerKey␉␉␉␉"SMmemmanufacturer"␊ |
59 | #define kSMBMemoryDeviceSerialNumberKey␉␉␉␉"SMmemserial"␊ |
60 | #define kSMBMemoryDevicePartNumberKey␉␉␉␉"SMmempart"␊ |
61 | ␊ |
62 | /* Apple Specific */␊ |
63 | #define kSMBOemProcessorTypeKey␉␉␉␉␉␉"SMcputype"␊ |
64 | #define kSMBOemProcessorBusSpeedKey␉␉␉␉␉"SMbusspeed"␊ |
65 | ␊ |
66 | //-------------------------------------------------------------------------------------------------------------------------␊ |
67 | // Default SMBIOS Data␊ |
68 | //-------------------------------------------------------------------------------------------------------------------------␊ |
69 | /* Rewrite: use a struct */␊ |
70 | ␊ |
71 | #define kDefaultVendorManufacturer␉␉␉␉␉"Apple Inc."␊ |
72 | #define kDefaultBIOSReleaseDate␉␉␉␉␉␉"11/06/2009"␊ |
73 | #define kDefaultSerialNumber␉␉␉␉␉␉"SOMESRLNMBR"␊ |
74 | #define kDefaultBoardProduct␉␉␉␉␉␉"Mac-F4208DC8"␊ |
75 | #define kDefaultSystemVersion␉␉␉␉␉␉"1.0"␊ |
76 | ␊ |
77 | // defaults for a Mac mini ␊ |
78 | #define kDefaultMacminiFamily␉␉␉␉␉␉"Macmini"␊ |
79 | #define kDefaultMacmini␉␉␉␉␉␉␉␉"Macmini2,1"␊ |
80 | #define kDefaultMacminiBIOSVersion␉␉␉␉␉" MM21.88Z.009A.B00.0903051113"␊ |
81 | ␊ |
82 | // defaults for a MacBook␊ |
83 | #define kDefaultMacBookFamily␉␉␉␉␉␉"MacBook"␊ |
84 | #define kDefaultMacBook␉␉␉␉␉␉␉␉"MacBook4,1"␊ |
85 | #define kDefaultMacBookBIOSVersion␉␉␉␉␉" MB41.88Z.0073.B00.0903051113"␊ |
86 | ␊ |
87 | // defaults for a MacBook Pro␊ |
88 | #define kDefaultMacBookProFamily␉␉␉␉␉"MacBookPro"␊ |
89 | #define kDefaultMacBookPro␉␉␉␉␉␉␉"MacBookPro4,1"␊ |
90 | #define kDefaultMacBookProBIOSVersion␉␉␉␉" MBP41.88Z.0073.B00.0903051113"␊ |
91 | ␊ |
92 | // defaults for an iMac␊ |
93 | #define kDefaultiMacFamily␉␉␉␉␉␉␉"iMac"␊ |
94 | #define kDefaultiMac␉␉␉␉␉␉␉␉"iMac8,1"␊ |
95 | #define kDefaultiMacBIOSVersion␉␉␉␉␉␉" IM81.88Z.00C1.B00.0903051113"␊ |
96 | // defaults for an iMac11,1 core i3/i5/i7␊ |
97 | #define kDefaultiMacNehalem␉␉␉␉␉␉␉"iMac11,1"␊ |
98 | #define kDefaultiMacNehalemBIOSVersion␉␉␉␉" IM111.88Z.0034.B00.0903051113"␊ |
99 | ␊ |
100 | // defaults for a Mac Pro␊ |
101 | #define kDefaultMacProFamily␉␉␉␉␉␉"MacPro"␊ |
102 | #define kDefaultMacPro␉␉␉␉␉␉␉␉"MacPro3,1"␊ |
103 | #define kDefaultMacProBIOSVersion␉␉␉␉␉" MP31.88Z.006C.B05.0903051113"␊ |
104 | // defaults for a Mac Pro 4,1 core i7/Xeon␊ |
105 | #define kDefaultMacProNehalem␉␉␉␉␉␉"MacPro4,1"␊ |
106 | #define kDefaultMacProNehalemBIOSVersion␉␉␉" MP41.88Z.0081.B04.0903051113"␊ |
107 | // defaults for a Mac Pro 5,1 core i7/Xeon␊ |
108 | #define kDefaultMacProWestmere␉␉␉␉␉␉"MacPro5,1"␊ |
109 | #define kDefaultMacProWestmereBIOSVersion␉␉␉" MP51.88Z.007F.B00.1008031144"␊ |
110 | #define kDefaulMacProWestmereBIOSReleaseDate␉␉"08/03/10"␊ |
111 | //-------------------------------------------------------------------------------------------------------------------------␊ |
112 | ␊ |
113 | ␊ |
114 | #define getFieldOffset(struct, field)␉((uint8_t)(uint32_t)&(((struct *)0)->field))␊ |
115 | ␊ |
116 | typedef struct {␊ |
117 | ␉SMBStructHeader *orig;␊ |
118 | ␉SMBStructHeader *new;␊ |
119 | } SMBStructPtrs;␊ |
120 | ␊ |
121 | struct {␊ |
122 | ␉char *vendor;␊ |
123 | ␉char *version;␊ |
124 | ␉char *releaseDate;␊ |
125 | } defaultBIOSInfo;␊ |
126 | ␊ |
127 | struct {␊ |
128 | ␉char *manufacturer;␊ |
129 | ␉char *productName;␊ |
130 | ␉char *version;␊ |
131 | ␉char *serialNumber;␊ |
132 | ␉char *family;␊ |
133 | } defaultSystemInfo;␊ |
134 | ␊ |
135 | struct {␊ |
136 | ␉char *manufacturer;␊ |
137 | ␉char *product;␊ |
138 | } defaultBaseBoard;␊ |
139 | ␊ |
140 | ␊ |
141 | typedef struct {␊ |
142 | ␉uint8_t␉␉␉type;␊ |
143 | ␉SMBValueType␉valueType;␊ |
144 | ␉uint8_t␉␉␉fieldOffset;␊ |
145 | ␉char␉␉␉*keyString;␊ |
146 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
147 | ␉char␉␉␉**defaultValue;␊ |
148 | } SMBValueSetter;␊ |
149 | ␊ |
150 | SMBValueSetter SMBSetters[] = ␊ |
151 | { ␊ |
152 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
153 | ␉// BIOSInformation␊ |
154 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
155 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
156 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
157 | ␊ |
158 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
159 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
160 | ␊ |
161 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
162 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
163 | ␊ |
164 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
165 | ␉// SystemInformation␊ |
166 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
167 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
168 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
169 | ␊ |
170 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
171 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
172 | ␊ |
173 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
174 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
175 | ␊ |
176 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
177 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
178 | ␊ |
179 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
180 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
181 | ␊ |
182 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
183 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
184 | ␊ |
185 | ␊ |
186 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
187 | ␉// BaseBoard␊ |
188 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
189 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
190 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
191 | ␊ |
192 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
193 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
194 | ␊ |
195 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
196 | ␊ |
197 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
198 | ␊ |
199 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
200 | ␊ |
201 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
202 | ␊ |
203 | ␊ |
204 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
205 | ␉// ProcessorInformation␊ |
206 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
207 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
208 | ␊ |
209 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
210 | ␊ |
211 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
212 | ␊ |
213 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
214 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
215 | ␊ |
216 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
217 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
218 | ␊ |
219 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
220 | ␊ |
221 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
222 | ␊ |
223 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
224 | ␊ |
225 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
226 | ␉// Memory Device␊ |
227 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
228 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
229 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
230 | ␊ |
231 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
232 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
233 | ␊ |
234 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
235 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
236 | ␊ |
237 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
238 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
239 | ␊ |
240 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
241 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
242 | ␊ |
243 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
244 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
245 | ␊ |
246 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
247 | ␊ |
248 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
249 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
250 | ␊ |
251 | ␊ |
252 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
253 | ␉// Apple Specific␊ |
254 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
255 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
256 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
257 | ␊ |
258 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
259 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
260 | };␊ |
261 | ␊ |
262 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
263 | ␊ |
264 | ␊ |
265 | SMBEntryPoint *origeps␉= 0;␊ |
266 | SMBEntryPoint *neweps␉= 0;␊ |
267 | ␊ |
268 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
269 | static uint8_t stringsSize;␉// add string size␊ |
270 | ␊ |
271 | static SMBWord tableLength␉␉= 0;␊ |
272 | static SMBWord handle␉␉␉= 0;␊ |
273 | static SMBWord maxStructSize␉= 0;␊ |
274 | static SMBWord structureCount␉= 0;␊ |
275 | ␊ |
276 | /* Rewrite this function */␊ |
277 | char *setDefaultSMBData(void)␊ |
278 | {␊ |
279 | ␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
280 | ␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
281 | ␊ |
282 | ␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
283 | ␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
284 | ␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
285 | ␊ |
286 | ␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
287 | ␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
288 | ␊ |
289 | ␉if (platformCPUFeature(CPU_FEATURE_MOBILE))␊ |
290 | ␉{␊ |
291 | ␉␉if (Platform->CPU.NoCores > 1)␊ |
292 | ␉␉{␊ |
293 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookProBIOSVersion;␊ |
294 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBookPro;␊ |
295 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookProFamily;␊ |
296 | ␉␉}␊ |
297 | ␉␉else␊ |
298 | ␉␉{␊ |
299 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookBIOSVersion;␊ |
300 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBook;␊ |
301 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookFamily;␊ |
302 | ␉␉}␊ |
303 | ␉}␊ |
304 | ␉else␊ |
305 | ␉{␊ |
306 | ␉␉switch (Platform->CPU.NoCores) ␊ |
307 | ␉␉{␊ |
308 | ␉␉␉case 1: ␊ |
309 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacminiBIOSVersion;␊ |
310 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacmini;␊ |
311 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacminiFamily;␊ |
312 | ␉␉␉␉break;␊ |
313 | ␊ |
314 | ␉␉␉case 2:␊ |
315 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacBIOSVersion;␊ |
316 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMac;␊ |
317 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
318 | ␉␉␉␉break;␊ |
319 | ␉␉␉default:␊ |
320 | ␉␉␉{␊ |
321 | ␉␉␉␉switch (Platform->CPU.Family) ␊ |
322 | ␉␉␉␉{␊ |
323 | ␉␉␉␉␉case 0x06:␊ |
324 | ␉␉␉␉␉{␊ |
325 | ␉␉␉␉␉␉switch (Platform->CPU.Model)␊ |
326 | ␉␉␉␉␉␉{␊ |
327 | ␉␉␉␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
328 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
329 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)␊ |
330 | ␉␉␉␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz ␊ |
331 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacNehalemBIOSVersion;␊ |
332 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacNehalem;␊ |
333 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
334 | ␉␉␉␉␉␉␉␉break;␊ |
335 | ␊ |
336 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM: ␊ |
337 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␊ |
338 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
339 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
340 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
341 | ␉␉␉␉␉␉␉␉break;␊ |
342 | ␊ |
343 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE: ␊ |
344 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␊ |
345 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProWestmereBIOSVersion;␊ |
346 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulMacProWestmereBIOSReleaseDate;␊ |
347 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProWestmere;␊ |
348 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
349 | ␉␉␉␉␉␉␉␉break;␊ |
350 | ␊ |
351 | ␉␉␉␉␉␉␉default:␊ |
352 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
353 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
354 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
355 | ␉␉␉␉␉␉␉␉break;␊ |
356 | ␉␉␉␉␉␉}␊ |
357 | ␉␉␉␉␉␉break;␊ |
358 | ␉␉␉␉␉}␊ |
359 | ␉␉␉␉␉default:␊ |
360 | ␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
361 | ␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
362 | ␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
363 | ␉␉␉␉␉␉break;␊ |
364 | ␉␉␉␉}␊ |
365 | ␉␉␉␉break;␊ |
366 | ␉␉␉}␊ |
367 | ␉␉}␊ |
368 | ␉}␊ |
369 | ␉return defaultSystemInfo.productName;␊ |
370 | }␊ |
371 | ␊ |
372 | /* Used for SM*_N smbios.plist keys */␊ |
373 | bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
374 | {␊ |
375 | ␉static int idx = -1;␊ |
376 | ␉static int current = -1;␊ |
377 | ␉int len;␊ |
378 | ␉char key[24];␊ |
379 | ␊ |
380 | ␉if (current != structHeader->handle)␊ |
381 | ␉{␊ |
382 | ␉␉idx++;␊ |
383 | ␉␉current = structHeader->handle;␊ |
384 | ␉}␊ |
385 | ␊ |
386 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
387 | ␊ |
388 | ␉if (value)␊ |
389 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
390 | ␉␉␉return true;␊ |
391 | ␉else␊ |
392 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
393 | ␉␉␉return true;␊ |
394 | ␉return false;␊ |
395 | }␊ |
396 | ␊ |
397 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
398 | {␊ |
399 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
400 | ␊ |
401 | ␉if (!field)␊ |
402 | ␉␉return (char *)0;␊ |
403 | ␊ |
404 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
405 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
406 | ␊ |
407 | ␉return (char *)stringPtr;␊ |
408 | }␊ |
409 | ␊ |
410 | #ifndef BETA␊ |
411 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
412 | {␊ |
413 | ␉if (!field)␊ |
414 | ␉␉return;␊ |
415 | ␉if (!string)␊ |
416 | ␉{␊ |
417 | ␉␉*field = 0;␊ |
418 | ␉␉return;␊ |
419 | ␉}␊ |
420 | ␊ |
421 | ␉int strSize = strlen(string) + 1;␊ |
422 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
423 | ␉*field = stringIndex;␊ |
424 | ␊ |
425 | ␉stringIndex++;␊ |
426 | ␉stringsSize += strSize;␊ |
427 | }␊ |
428 | ␊ |
429 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
430 | {␊ |
431 | ␉const char *string = 0;␊ |
432 | ␉int len;␊ |
433 | ␊ |
434 | ␉if (numOfSetters <= idx)␊ |
435 | ␉␉return false;␊ |
436 | ␊ |
437 | ␉switch (SMBSetters[idx].valueType)␊ |
438 | ␉{␊ |
439 | ␉␉case kSMBString:␊ |
440 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
441 | ␉␉␉{␊ |
442 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
443 | ␉␉␉␉␉break;␊ |
444 | ␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
445 | ␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
446 | ␉␉␉␉␉␉break;␊ |
447 | ␉␉␉}␊ |
448 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
449 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
450 | ␉␉␉␉␉break;␊ |
451 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
452 | ␉␉␉{␊ |
453 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
454 | ␉␉␉␉break;␊ |
455 | ␉␉␉}␊ |
456 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
457 | ␉␉␉break;␊ |
458 | ␊ |
459 | ␉␉case kSMBByte:␊ |
460 | ␉␉case kSMBWord:␊ |
461 | ␉␉case kSMBDWord:␊ |
462 | ␉␉//case kSMBQWord:␊ |
463 | ␉␉␉if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))␊ |
464 | ␉␉␉␉return true;␊ |
465 | ␉␉␉else␊ |
466 | ␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
467 | ␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
468 | ␉␉␉␉␉␉return true;␊ |
469 | ␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
470 | ␉␉␉␉return true;␊ |
471 | #if 0␊ |
472 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
473 | ␉␉␉{␊ |
474 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
475 | ␉␉␉␉return true;␊ |
476 | ␉␉␉}␊ |
477 | #endif␊ |
478 | ␉␉␉break;␊ |
479 | ␉}␊ |
480 | ␊ |
481 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
482 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
483 | ␊ |
484 | ␉return true;␊ |
485 | }␊ |
486 | #else␊ |
487 | ␊ |
488 | #if FIXME␊ |
489 | // this function don't work, it give me a corrupted dimm-part-number value (all other values seems to be correct), and so, ␊ |
490 | // an error in the memory tab of sysprofiler, i haven't checked yet what's wrong inside this function,␊ |
491 | // it should be :␊ |
492 | // dimm-part-number data <"2G-UDIMM", "99U5429-005.A00LF", "2G-UDIMM", "KLCD48F-A8KB5">␊ |
493 | // but it give:␊ |
494 | // dimm-part-number data <11 1b 1e 00 11 1b 1f 00 11 1b 20 13 0f 21 00> // automatic is set in property options, ???␊ |
495 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
496 | {␊ |
497 | ␉int strSize;␊ |
498 | ␉␊ |
499 | ␉if (!field)␊ |
500 | ␉␉return;␊ |
501 | ␉if (!string)␊ |
502 | ␉{␊ |
503 | ␉␉*field = 0;␊ |
504 | ␉␉return;␊ |
505 | ␉}␊ |
506 | ␉␊ |
507 | ␉strSize = strlen(string);␊ |
508 | ␉␊ |
509 | ␉// remove any spaces found at the end␊ |
510 | ␉while (string[strSize - 1] == ' ')␊ |
511 | ␉␉strSize--;␊ |
512 | ␉␊ |
513 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
514 | ␉*field = stringIndex;␊ |
515 | ␉␊ |
516 | ␉stringIndex++;␊ |
517 | ␉stringsSize += strSize + 1;␊ |
518 | }␊ |
519 | #else␊ |
520 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
521 | {␊ |
522 | ␉if (!field)␊ |
523 | ␉␉return;␊ |
524 | ␉if (!string)␊ |
525 | ␉{␊ |
526 | ␉␉*field = 0;␊ |
527 | ␉␉return;␊ |
528 | ␉}␊ |
529 | ␉␊ |
530 | ␉int strSize = strlen(string) + 1;␊ |
531 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
532 | ␉*field = stringIndex;␊ |
533 | ␉␊ |
534 | ␉stringIndex++;␊ |
535 | ␉stringsSize += strSize;␊ |
536 | }␊ |
537 | #endif␊ |
538 | ␊ |
539 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
540 | {␊ |
541 | ␉const char *string = 0;␊ |
542 | ␉int len;␊ |
543 | ␉␊ |
544 | ␉if (numOfSetters <= idx)␊ |
545 | ␉␉return false;␊ |
546 | ␉␊ |
547 | ␉switch (SMBSetters[idx].valueType)␊ |
548 | ␉{␊ |
549 | ␉␉case kSMBString:␊ |
550 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
551 | ␉␉␉{␊ |
552 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
553 | ␉␉␉␉␉break;␊ |
554 | ␉␉␉␉else␊ |
555 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
556 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
557 | ␉␉␉␉␉␉␉break;␊ |
558 | ␉␉␉}␊ |
559 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
560 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
561 | ␉␉␉␉␉break;␊ |
562 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
563 | ␉␉␉{␊ |
564 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
565 | ␉␉␉␉break;␊ |
566 | ␉␉␉}␊ |
567 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
568 | ␉␉␉break;␊ |
569 | ␉␉␉␊ |
570 | ␉␉case kSMBByte:␊ |
571 | ␉␉case kSMBWord:␊ |
572 | ␉␉case kSMBDWord:␊ |
573 | ␉␉␉//case kSMBQWord:␊ |
574 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
575 | ␉␉␉{␊ |
576 | ␉␉␉␉if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))␊ |
577 | ␉␉␉␉␉return true;␊ |
578 | ␉␉␉␉else␊ |
579 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
580 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
581 | ␉␉␉␉␉␉␉return true;␊ |
582 | ␉␉␉}␊ |
583 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
584 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
585 | ␉␉␉␉␉return true;␊ |
586 | #if 0␊ |
587 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
588 | ␉␉␉{␊ |
589 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
590 | ␉␉␉␉return true;␊ |
591 | ␉␉␉}␊ |
592 | #endif␊ |
593 | ␉␉␉break;␊ |
594 | ␉}␊ |
595 | ␉␊ |
596 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
597 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
598 | ␉␊ |
599 | ␉return true;␊ |
600 | }␊ |
601 | #endif␊ |
602 | //-------------------------------------------------------------------------------------------------------------------------␊ |
603 | // Apple Specific␊ |
604 | //-------------------------------------------------------------------------------------------------------------------------␊ |
605 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
606 | {␊ |
607 | ␉return;␊ |
608 | }␊ |
609 | ␊ |
610 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
611 | {␊ |
612 | ␉/* SPD data from Platform->RAM.spd */␊ |
613 | ␉return;␊ |
614 | }␊ |
615 | ␊ |
616 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
617 | {␊ |
618 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
619 | ␊ |
620 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
621 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
622 | ␉p->header.handle␉= handle++;␊ |
623 | ␊ |
624 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
625 | ␊ |
626 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
627 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
628 | ␉structureCount++;␊ |
629 | }␊ |
630 | ␊ |
631 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
632 | {␊ |
633 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
634 | ␊ |
635 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
636 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
637 | ␉p->header.handle␉= handle++;␊ |
638 | ␊ |
639 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
640 | ␊ |
641 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
642 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
643 | ␉structureCount++;␊ |
644 | }␊ |
645 | ␊ |
646 | //-------------------------------------------------------------------------------------------------------------------------␊ |
647 | // EndOfTable␊ |
648 | //-------------------------------------------------------------------------------------------------------------------------␊ |
649 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
650 | {␊ |
651 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
652 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
653 | ␉structPtr->new->handle␉= handle++;␊ |
654 | ␊ |
655 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
656 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
657 | ␉structureCount++;␊ |
658 | }␊ |
659 | ␊ |
660 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
661 | {␊ |
662 | ␉bool setterFound = false;␊ |
663 | ␊ |
664 | ␉uint8_t *ptr;␊ |
665 | ␉SMBWord structSize;␊ |
666 | ␉int i;␊ |
667 | ␊ |
668 | ␉stringIndex = 1;␊ |
669 | ␉stringsSize = 0;␊ |
670 | ␊ |
671 | ␉if (handle < structPtr->orig->handle)␊ |
672 | ␉␉handle = structPtr->orig->handle;␊ |
673 | ␊ |
674 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
675 | ␊ |
676 | ␉for (i = 0; i < numOfSetters; i++)␊ |
677 | ␉␉if (structPtr->orig->type == SMBSetters[i].type)␊ |
678 | ␉␉{␊ |
679 | ␉␉␉setterFound = true;␊ |
680 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
681 | ␉␉}␊ |
682 | ␊ |
683 | ␉if (setterFound)␊ |
684 | ␉{␊ |
685 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
686 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
687 | ␊ |
688 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
689 | ␉␉␉ptr += 2;␊ |
690 | ␊ |
691 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
692 | ␉}␊ |
693 | ␉else␊ |
694 | ␉{␊ |
695 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
696 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
697 | ␊ |
698 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
699 | ␉␉␉ptr += 2;␊ |
700 | ␉␉␊ |
701 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
702 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
703 | ␉}␊ |
704 | ␊ |
705 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
706 | ␊ |
707 | ␉tableLength += structSize;␊ |
708 | ␊ |
709 | ␉if (structSize > maxStructSize)␊ |
710 | ␉␉maxStructSize = structSize;␊ |
711 | ␊ |
712 | ␉structureCount++;␊ |
713 | }␊ |
714 | ␊ |
715 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
716 | {␊ |
717 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
718 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
719 | ␊ |
720 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
721 | ␉{␊ |
722 | ␉␉switch (structPtr->orig->type)␊ |
723 | ␉␉{␊ |
724 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
725 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
726 | ␉␉␉case kSMBTypeMemorySPD:␊ |
727 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
728 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
729 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
730 | ␉␉␉case kSMBTypeEndOfTable:␊ |
731 | ␉␉␉␉break;␊ |
732 | ␊ |
733 | ␉␉␉default:␊ |
734 | ␉␉␉␉/* Add */␊ |
735 | ␉␉␉␉setSMBStruct(structPtr);␊ |
736 | ␉␉␉␉break;␊ |
737 | ␉␉}␊ |
738 | ␊ |
739 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
740 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
741 | ␊ |
742 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
743 | ␉␉␉ptr += 2;␊ |
744 | ␊ |
745 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
746 | ␉}␊ |
747 | ␊ |
748 | ␉addSMBFirmwareVolume(structPtr);␊ |
749 | ␉addSMBMemorySPD(structPtr);␊ |
750 | ␉addSMBOemProcessorType(structPtr);␊ |
751 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
752 | ␊ |
753 | ␉addSMBEndOfTable(structPtr);␊ |
754 | }␊ |
755 | ␊ |
756 | void setupSMBIOSTable(void)␊ |
757 | {␊ |
758 | ␉SMBStructPtrs *structPtr;␊ |
759 | ␉uint8_t *buffer;␊ |
760 | ␉bool setSMB = true;␊ |
761 | ␊ |
762 | ␉if (!origeps)␊ |
763 | ␉␉return;␊ |
764 | ␊ |
765 | ␉neweps = origeps;␊ |
766 | ␊ |
767 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
768 | ␉if (!structPtr)␊ |
769 | ␉␉return;␊ |
770 | ␉␊ |
771 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
772 | ␉if (!buffer)␊ |
773 | ␉␉return;␊ |
774 | ␊ |
775 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
776 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
777 | ␊ |
778 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->bootConfig);␊ |
779 | ␉if (setSMB)␊ |
780 | ␉␉setDefaultSMBData();␊ |
781 | ␊ |
782 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
783 | ␊ |
784 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
785 | ␉if (!neweps)␊ |
786 | ␉␉return;␊ |
787 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
788 | ␊ |
789 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
790 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
791 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
792 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
793 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
794 | ␉neweps->majorVersion␉␉= 2;␊ |
795 | ␉neweps->minorVersion␉␉= 4;␊ |
796 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
797 | ␉neweps->entryPointRevision␉= 0;␊ |
798 | ␊ |
799 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
800 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
801 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
802 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
803 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
804 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
805 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
806 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
807 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
808 | ␊ |
809 | ␉if (!neweps->dmi.tableAddress)␊ |
810 | ␉␉return;␊ |
811 | ␊ |
812 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
813 | ␊ |
814 | ␉neweps->dmi.checksum␉␉= 0;␊ |
815 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
816 | ␊ |
817 | ␉neweps->checksum␉␉␉= 0;␊ |
818 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
819 | ␊ |
820 | ␉free(buffer);␊ |
821 | ␉decodeSMBIOSTable(neweps);␊ |
822 | }␊ |
823 | ␊ |
824 | void *getSmbiosPatched()␊ |
825 | {␊ |
826 | ␉return neweps;␉␊ |
827 | }␊ |
828 | ␊ |
829 | /* Collect any information needed later */␊ |
830 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
831 | {␊ |
832 | ␉origeps = eps;␊ |
833 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
834 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
835 | ␊ |
836 | ␉int dimmnbr = 0;␊ |
837 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
838 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
839 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
840 | ␊ |
841 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
842 | ␉{␊ |
843 | ␉␉switch (structHeader->type)␊ |
844 | ␉␉{␊ |
845 | ␉␉␉/*case kSMBTypeSystemInformation:␊ |
846 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
847 | ␉␉␉␉break;*/␊ |
848 | ␊ |
849 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
850 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
851 | ␉␉␉␉break;␊ |
852 | ␊ |
853 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
854 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
855 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
856 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
857 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
858 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
859 | ␉␉␉␉dimmnbr++;␊ |
860 | ␉␉␉␉break;␊ |
861 | ␉␉}␊ |
862 | ␊ |
863 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
864 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
865 | ␊ |
866 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
867 | ␉␉␉structPtr += 2;␊ |
868 | ␊ |
869 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
870 | ␉}␊ |
871 | }␊ |
872 | ␊ |
873 | |