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