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 | // defaults for an iMac12,1␊ |
100 | #define kDefaultiMacSandy␉␉␉␉␉␉␉"iMac12,1"␊ |
101 | #define kDefaultiMacSandyBIOSVersion␉␉␉␉" IM121.88Z.0047.B00.1102091756"␊ |
102 | // defaults for a Mac Pro␊ |
103 | #define kDefaultMacProFamily␉␉␉␉␉␉"MacPro"␊ |
104 | #define kDefaultMacPro␉␉␉␉␉␉␉␉"MacPro3,1"␊ |
105 | #define kDefaultMacProBIOSVersion␉␉␉␉␉" MP31.88Z.006C.B05.0903051113"␊ |
106 | // defaults for a Mac Pro 4,1 core i7/Xeon␊ |
107 | #define kDefaultMacProNehalem␉␉␉␉␉␉"MacPro4,1"␊ |
108 | #define kDefaultMacProNehalemBIOSVersion␉␉␉" MP41.88Z.0081.B04.0903051113"␊ |
109 | // defaults for a Mac Pro 5,1 core i7/Xeon␊ |
110 | #define kDefaultMacProWestmere␉␉␉␉␉␉"MacPro5,1"␊ |
111 | #define kDefaultMacProWestmereBIOSVersion␉␉␉" MP51.88Z.007F.B00.1008031144"␊ |
112 | #define kDefaulMacProWestmereBIOSReleaseDate␉␉"08/03/10"␊ |
113 | // defaults for a Xserve␊ |
114 | #define kDefaultXserve␉␉␉␉␉␉␉␉"Xserve2,1"␊ |
115 | #define kDefaultXserveBIOSVersion␉␉␉␉␉" XS21.88Z.006C.B06.0804011317"␊ |
116 | #define kDefaulXserveBIOSReleaseDate␉␉␉␉"04/01/2008"␊ |
117 | #define kDefaultXserveFamily␉␉␉␉␉␉"Xserve"␊ |
118 | //-------------------------------------------------------------------------------------------------------------------------␊ |
119 | ␊ |
120 | ␊ |
121 | #define getFieldOffset(struct, field)␉((uint8_t)(uint32_t)&(((struct *)0)->field))␊ |
122 | ␊ |
123 | typedef struct {␊ |
124 | ␉SMBStructHeader *orig;␊ |
125 | ␉SMBStructHeader *new;␊ |
126 | } SMBStructPtrs;␊ |
127 | ␊ |
128 | struct {␊ |
129 | ␉char *vendor;␊ |
130 | ␉char *version;␊ |
131 | ␉char *releaseDate;␊ |
132 | } defaultBIOSInfo;␊ |
133 | ␊ |
134 | struct {␊ |
135 | ␉char *manufacturer;␊ |
136 | ␉char *productName;␊ |
137 | ␉char *version;␊ |
138 | ␉char *serialNumber;␊ |
139 | ␉char *family;␊ |
140 | } defaultSystemInfo;␊ |
141 | ␊ |
142 | struct {␊ |
143 | ␉char *manufacturer;␊ |
144 | ␉char *product;␊ |
145 | } defaultBaseBoard;␊ |
146 | ␊ |
147 | ␊ |
148 | typedef struct {␊ |
149 | ␉uint8_t␉␉␉type;␊ |
150 | ␉SMBValueType␉valueType;␊ |
151 | ␉uint8_t␉␉␉fieldOffset;␊ |
152 | ␉char␉␉␉*keyString;␊ |
153 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
154 | ␉char␉␉␉**defaultValue;␊ |
155 | } SMBValueSetter;␊ |
156 | ␊ |
157 | SMBValueSetter SMBSetters[] = ␊ |
158 | { ␊ |
159 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
160 | ␉// BIOSInformation␊ |
161 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
162 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
163 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
164 | ␊ |
165 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
166 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
167 | ␊ |
168 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
169 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
170 | ␊ |
171 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
172 | ␉// SystemInformation␊ |
173 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
174 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
175 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
176 | ␊ |
177 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
178 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
179 | ␊ |
180 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
181 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
182 | ␊ |
183 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
184 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
185 | ␊ |
186 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
187 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
188 | ␊ |
189 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
190 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
191 | ␊ |
192 | ␊ |
193 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
194 | ␉// BaseBoard␊ |
195 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
196 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
197 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
198 | ␊ |
199 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
200 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
201 | ␊ |
202 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
203 | ␊ |
204 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
205 | ␊ |
206 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
207 | ␊ |
208 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
209 | ␊ |
210 | ␊ |
211 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
212 | ␉// ProcessorInformation␊ |
213 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
214 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
215 | ␊ |
216 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
217 | ␊ |
218 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
219 | ␊ |
220 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
221 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
222 | ␊ |
223 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
224 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
225 | ␊ |
226 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
227 | ␊ |
228 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
229 | ␊ |
230 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
231 | ␊ |
232 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
233 | ␉// Memory Device␊ |
234 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
235 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
236 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
237 | ␊ |
238 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
239 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
240 | ␊ |
241 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
242 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
243 | ␊ |
244 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
245 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
246 | ␊ |
247 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
248 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
249 | ␊ |
250 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
251 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
252 | ␊ |
253 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
254 | ␊ |
255 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
256 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
257 | ␊ |
258 | ␊ |
259 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
260 | ␉// Apple Specific␊ |
261 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
262 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
263 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
264 | ␊ |
265 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
266 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
267 | };␊ |
268 | ␊ |
269 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
270 | ␊ |
271 | SMBEntryPoint *neweps␉= 0;␊ |
272 | ␊ |
273 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
274 | static uint8_t stringsSize;␉// add string size␊ |
275 | ␊ |
276 | static SMBWord tableLength␉␉= 0;␊ |
277 | static SMBWord handle␉␉␉= 0;␊ |
278 | static SMBWord maxStructSize␉= 0;␊ |
279 | static SMBWord structureCount␉= 0;␊ |
280 | ␊ |
281 | void setDefaultSMBData(void);␊ |
282 | ␊ |
283 | ␊ |
284 | char *getDefaultSMBproductName(void)␊ |
285 | {␊ |
286 | ␉setDefaultSMBData();␊ |
287 | ␉return defaultSystemInfo.productName;␊ |
288 | }␊ |
289 | ␊ |
290 | char *getDefaultSMBBoardProduct(void)␊ |
291 | {␊ |
292 | ␉setDefaultSMBData();␊ |
293 | ␉return defaultBaseBoard.product;␊ |
294 | }␊ |
295 | ␊ |
296 | /* Rewrite this function */␊ |
297 | void setDefaultSMBData(void)␊ |
298 | {␊ |
299 | ␉static bool setDefSMB = true;␊ |
300 | ␉␊ |
301 | ␉if (setDefSMB) {␉␉␊ |
302 | ␉␉␊ |
303 | ␉␉if (Platform->CPU.isServer == true) {␊ |
304 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultXserveBIOSVersion;␊ |
305 | ␉␉␉defaultSystemInfo.productName␉= kDefaultXserve;␉␉␉␊ |
306 | ␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulXserveBIOSReleaseDate;␊ |
307 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultXserveFamily;␊ |
308 | ␉␉}␊ |
309 | ␉␉else if (Platform->CPU.isMobile == true)␊ |
310 | ␉␉{␊ |
311 | ␉␉␉if (Platform->CPU.NoCores > 1)␊ |
312 | ␉␉␉{␊ |
313 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookProBIOSVersion;␊ |
314 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacBookPro;␊ |
315 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookProFamily;␊ |
316 | ␉␉␉}␊ |
317 | ␉␉␉else␊ |
318 | ␉␉␉{␊ |
319 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookBIOSVersion;␊ |
320 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacBook;␊ |
321 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookFamily;␊ |
322 | ␉␉␉}␊ |
323 | ␉␉}␊ |
324 | ␉␉else␊ |
325 | ␉␉{␊ |
326 | ␉␉␉switch (Platform->CPU.NoCores) ␊ |
327 | ␉␉␉{␊ |
328 | ␉␉␉␉case 1: ␊ |
329 | ␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacminiBIOSVersion;␊ |
330 | ␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacmini;␊ |
331 | ␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacminiFamily;␊ |
332 | ␉␉␉␉␉break;␊ |
333 | ␉␉␉␉␉␊ |
334 | ␉␉␉␉case 2:␊ |
335 | ␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacBIOSVersion;␊ |
336 | ␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMac;␊ |
337 | ␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
338 | ␉␉␉␉␉break;␊ |
339 | ␉␉␉␉default:␊ |
340 | ␉␉␉␉{␊ |
341 | ␉␉␉␉␉switch (Platform->CPU.Family) ␊ |
342 | ␉␉␉␉␉{␊ |
343 | ␉␉␉␉␉␉case 0x06:␊ |
344 | ␉␉␉␉␉␉{␊ |
345 | ␉␉␉␉␉␉␉switch (Platform->CPU.Model)␊ |
346 | ␉␉␉␉␉␉␉{␊ |
347 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
348 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
349 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)␊ |
350 | ␉␉␉␉␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz ␊ |
351 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacNehalemBIOSVersion;␊ |
352 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacNehalem;␊ |
353 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
354 | ␉␉␉␉␉␉␉␉␉break;␊ |
355 | ␉␉␉␉␉␉␉␉␉␊ |
356 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
357 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_JAKETOWN: // Until Apple release a MacPro6,1 ??␊ |
358 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacSandyBIOSVersion;␊ |
359 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacSandy;␊ |
360 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
361 | ␉␉␉␉␉␉␉␉␉break;␊ |
362 | ␉␉␉␉␉␉␉␉␉␊ |
363 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_NEHALEM: ␊ |
364 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␊ |
365 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
366 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
367 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
368 | ␉␉␉␉␉␉␉␉␉break;␊ |
369 | ␉␉␉␉␉␉␉␉␉␊ |
370 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_WESTMERE: ␊ |
371 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␊ |
372 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProWestmereBIOSVersion;␊ |
373 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulMacProWestmereBIOSReleaseDate;␊ |
374 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProWestmere;␊ |
375 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
376 | ␉␉␉␉␉␉␉␉␉break;␊ |
377 | ␉␉␉␉␉␉␉␉␉␊ |
378 | ␉␉␉␉␉␉␉␉default:␊ |
379 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
380 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
381 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
382 | ␉␉␉␉␉␉␉␉␉break;␊ |
383 | ␉␉␉␉␉␉␉}␊ |
384 | ␉␉␉␉␉␉␉break;␊ |
385 | ␉␉␉␉␉␉}␊ |
386 | ␉␉␉␉␉␉default:␊ |
387 | ␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
388 | ␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
389 | ␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
390 | ␉␉␉␉␉␉␉break;␊ |
391 | ␉␉␉␉␉}␊ |
392 | ␉␉␉␉␉break;␊ |
393 | ␉␉␉␉}␊ |
394 | ␉␉␉}␊ |
395 | ␉␉}␊ |
396 | ␉␉␊ |
397 | ␉␉if (!defaultBIOSInfo.vendor) ␊ |
398 | ␉␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
399 | ␉␉if (!defaultBIOSInfo.releaseDate) ␊ |
400 | ␉␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
401 | ␉␉␊ |
402 | ␉␉if (!defaultSystemInfo.manufacturer) ␊ |
403 | ␉␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
404 | ␉␉if (!defaultSystemInfo.version) ␊ |
405 | ␉␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
406 | ␉␉if (!defaultSystemInfo.serialNumber) ␊ |
407 | ␉␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
408 | ␉␉␊ |
409 | ␉␉if (!defaultBaseBoard.manufacturer) ␊ |
410 | ␉␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
411 | ␉␉if (!defaultBaseBoard.product) ␊ |
412 | ␉␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
413 | ␉␉␊ |
414 | ␉␉setDefSMB = false;␊ |
415 | ␉}␉␊ |
416 | }␊ |
417 | ␊ |
418 | /* Used for SM*_N smbios.plist keys */␊ |
419 | bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
420 | {␊ |
421 | ␉static int idx = -1;␊ |
422 | ␉static int current = -1;␊ |
423 | ␉int len;␊ |
424 | ␉char key[24];␊ |
425 | ␊ |
426 | ␉if (current != structHeader->handle)␊ |
427 | ␉{␊ |
428 | ␉␉idx++;␊ |
429 | ␉␉current = structHeader->handle;␊ |
430 | ␉}␊ |
431 | ␊ |
432 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
433 | ␊ |
434 | ␉if (value)␊ |
435 | ␉{␊ |
436 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
437 | ␉␉␉return true;␊ |
438 | ␉}␊ |
439 | ␉else␊ |
440 | ␉{␊ |
441 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
442 | ␉␉␉return true;␊ |
443 | ␉}␊ |
444 | ␉␊ |
445 | ␉return false;␊ |
446 | }␊ |
447 | ␊ |
448 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
449 | {␊ |
450 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
451 | ␊ |
452 | ␉if (!field)␊ |
453 | {␊ |
454 | ␉␉//return (char *)0;␊ |
455 | return NULL;␊ |
456 | }␊ |
457 | ␊ |
458 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
459 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
460 | ␊ |
461 | ␉return (char *)stringPtr;␊ |
462 | }␊ |
463 | ␊ |
464 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
465 | {␊ |
466 | ␉int strSize;␊ |
467 | ␊ |
468 | ␉if (!field)␊ |
469 | {␊ |
470 | ␊ |
471 | ␉␉return;␊ |
472 | }␊ |
473 | ␉if (!string)␊ |
474 | ␉{␊ |
475 | ␉␉*field = 0;␊ |
476 | ␉␉return;␊ |
477 | ␉}␊ |
478 | ␉␊ |
479 | ␉strSize = strlen(string);␊ |
480 | ␉␊ |
481 | ␉// remove any spaces found at the end␊ |
482 | while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
483 | ␉␉strSize--;␊ |
484 | ␉␊ |
485 | ␊ |
486 | ␉if (strSize == 0)␊ |
487 | ␉{␊ |
488 | ␉␉*field = 0;␊ |
489 | ␉␉return;␊ |
490 | ␉}␊ |
491 | ␉␊ |
492 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
493 | ␊ |
494 | ␉*field = stringIndex;␊ |
495 | ␉␊ |
496 | ␉stringIndex++;␊ |
497 | ␉stringsSize += strSize + 1;␊ |
498 | }␊ |
499 | ␊ |
500 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
501 | {␊ |
502 | ␉const char *string = 0;␊ |
503 | ␉int len;␊ |
504 | ␉bool parsed;␊ |
505 | ␉int val;␊ |
506 | ␊ |
507 | ␉if (numOfSetters <= idx)␊ |
508 | ␉␉return false;␊ |
509 | ␉␊ |
510 | ␉switch (SMBSetters[idx].valueType)␊ |
511 | ␉{␊ |
512 | ␉␉case kSMBString:␊ |
513 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
514 | ␉␉␉{␊ |
515 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
516 | ␉␉␉␉␉break;␊ |
517 | ␉␉␉␉else␊ |
518 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
519 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
520 | ␉␉␉␉␉␉␉break;␊ |
521 | ␉␉␉}␊ |
522 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
523 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
524 | ␉␉␉␉␉break;␊ |
525 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
526 | ␉␉␉{␊ |
527 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
528 | ␉␉␉␉break;␊ |
529 | ␉␉␉}␊ |
530 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
531 | ␉␉␉break;␊ |
532 | ␉␉␉␊ |
533 | ␉␉case kSMBByte:␊ |
534 | ␉␉case kSMBWord:␊ |
535 | ␉␉case kSMBDWord:␊ |
536 | ␉␉␉//case kSMBQWord:␊ |
537 | ␉␉␉/*if (SMBSetters[idx].keyString)␊ |
538 | {␊ |
539 | if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))␊ |
540 | return true;␊ |
541 | else␊ |
542 | if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
543 | if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
544 | return true;␊ |
545 | }*/␊ |
546 | if (SMBSetters[idx].keyString)␊ |
547 | ␉␉␉{␊ |
548 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
549 | ␉␉␉␉if (!parsed)␊ |
550 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
551 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
552 | ␉␉␉␉if (parsed)␊ |
553 | ␉␉␉␉{␊ |
554 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
555 | ␉␉␉␉␉{␊ |
556 | ␉␉␉␉␉␉case kSMBByte:␊ |
557 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
558 | ␉␉␉␉␉␉␉break;␊ |
559 | ␉␉␉␉␉␉case kSMBWord:␊ |
560 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
561 | ␉␉␉␉␉␉␉break;␊ |
562 | ␉␉␉␉␉␉case kSMBDWord:␊ |
563 | ␉␉␉␉␉␉default:␊ |
564 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
565 | ␉␉␉␉␉␉␉break;␊ |
566 | ␉␉␉␉␉}␊ |
567 | ␉␉␉␉␉return true;␊ |
568 | ␉␉␉␉}␊ |
569 | }␊ |
570 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
571 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
572 | ␉␉␉␉␉return true;␊ |
573 | #if 0␊ |
574 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
575 | ␉␉␉{␊ |
576 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
577 | ␉␉␉␉return true;␊ |
578 | ␉␉␉}␊ |
579 | #endif␊ |
580 | ␉␉␉break;␊ |
581 | ␉}␊ |
582 | ␉␊ |
583 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
584 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
585 | ␊ |
586 | ␉return true;␊ |
587 | }␊ |
588 | //-------------------------------------------------------------------------------------------------------------------------␊ |
589 | // Apple Specific␊ |
590 | //-------------------------------------------------------------------------------------------------------------------------␊ |
591 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
592 | {␊ |
593 | ␉return;␊ |
594 | }␊ |
595 | ␊ |
596 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
597 | {␊ |
598 | ␉/* SPD data from Platform->RAM.spd */␊ |
599 | ␉return;␊ |
600 | }␊ |
601 | ␊ |
602 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
603 | {␊ |
604 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
605 | ␉␊ |
606 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
607 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
608 | ␉p->header.handle␉= handle++;␊ |
609 | ␊ |
610 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
611 | ␊ |
612 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
613 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
614 | ␉structureCount++;␊ |
615 | }␊ |
616 | ␊ |
617 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
618 | {␊ |
619 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
620 | ␊ |
621 | ␉switch (Platform->CPU.Family) ␊ |
622 | ␉{␊ |
623 | ␉␉case 0x06:␊ |
624 | ␉␉{␊ |
625 | ␉␉␉switch (Platform->CPU.Model)␊ |
626 | ␉␉␉{␊ |
627 | ␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz␊ |
628 | ␉␉␉␉case CPUID_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
629 | ␉␉␉␉case CPUID_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
630 | ␉␉␉␉case CPUID_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
631 | ␉␉␉␉case CPUID_MODEL_NEHALEM:␉␉// Intel Core i7 LGA1366 (45nm)␊ |
632 | ␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
633 | ␉␉␉␉case CPUID_MODEL_WESTMERE:␉// Intel Core i7 LGA1366 (32nm) 6 Core␊ |
634 | ␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
635 | ␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
636 | ␉␉␉␉case CPUID_MODEL_JAKETOWN: ␊ |
637 | ␉␉␉␉␉break;␊ |
638 | ␉␉␉␉␉␊ |
639 | ␉␉␉␉default:␊ |
640 | ␉␉␉␉␉return;␊ |
641 | ␉␉␉}␊ |
642 | ␉␉}␊ |
643 | ␉}␊ |
644 | ␉␊ |
645 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
646 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
647 | ␉p->header.handle␉= handle++;␊ |
648 | ␊ |
649 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
650 | ␊ |
651 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
652 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
653 | ␉structureCount++;␊ |
654 | }␊ |
655 | ␊ |
656 | //-------------------------------------------------------------------------------------------------------------------------␊ |
657 | // EndOfTable␊ |
658 | //-------------------------------------------------------------------------------------------------------------------------␊ |
659 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
660 | {␊ |
661 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
662 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
663 | ␉structPtr->new->handle␉= handle++;␊ |
664 | ␊ |
665 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
666 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
667 | ␉structureCount++;␊ |
668 | }␊ |
669 | ␊ |
670 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
671 | {␊ |
672 | ␉bool setterFound = false;␊ |
673 | ␊ |
674 | ␉uint8_t *ptr;␊ |
675 | ␉SMBWord structSize;␊ |
676 | ␉int i;␊ |
677 | ␉␉␊ |
678 | ␉stringIndex = 1;␊ |
679 | ␉stringsSize = 0;␊ |
680 | ␊ |
681 | ␉if (handle < structPtr->orig->handle)␊ |
682 | ␉␉handle = structPtr->orig->handle;␊ |
683 | ␊ |
684 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
685 | ␊ |
686 | ␉for (i = 0; i < numOfSetters; i++)␊ |
687 | ␉␉/*if (structPtr->orig->type == SMBSetters[i].type)␊ |
688 | ␉␉{␊ |
689 | ␉␉␉if (SMBSetters[i].fieldOffset > structPtr->orig->length)␊ |
690 | ␉␉␉␉continue;*/␊ |
691 | if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
692 | {␊ |
693 | ␉␉␉setterFound = true;␊ |
694 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
695 | ␉␉}␊ |
696 | ␊ |
697 | ␉if (setterFound)␊ |
698 | ␉{␊ |
699 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
700 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
701 | ␊ |
702 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
703 | ␉␉␉ptr += 2;␊ |
704 | ␊ |
705 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
706 | ␉}␊ |
707 | ␉else␊ |
708 | ␉{␊ |
709 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
710 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
711 | ␊ |
712 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
713 | ␉␉␉ptr += 2;␊ |
714 | ␉␉␊ |
715 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
716 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
717 | ␉}␊ |
718 | ␊ |
719 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
720 | ␊ |
721 | ␉tableLength += structSize;␊ |
722 | ␊ |
723 | ␉if (structSize > maxStructSize)␊ |
724 | ␉␉maxStructSize = structSize;␊ |
725 | ␊ |
726 | ␉structureCount++;␊ |
727 | ␊ |
728 | }␊ |
729 | ␊ |
730 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
731 | {␊ |
732 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
733 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
734 | ␊ |
735 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
736 | ␉{␊ |
737 | ␉␉switch (structPtr->orig->type)␊ |
738 | ␉␉{␊ |
739 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
740 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
741 | ␉␉␉case kSMBTypeMemorySPD:␊ |
742 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
743 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
744 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
745 | ␉␉␉case kSMBTypeEndOfTable:␊ |
746 | ␉␉␉␉break;␊ |
747 | ␊ |
748 | ␉␉␉default:␊ |
749 | {␊ |
750 | ␉␉␉␉/* Add */␊ |
751 | ␉␉␉␉setSMBStruct(structPtr);␊ |
752 | ␉␉␉␉break;␊ |
753 | }␊ |
754 | ␉␉}␊ |
755 | ␊ |
756 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
757 | ␊ |
758 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
759 | ␊ |
760 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
761 | ␉␉␉ptr += 2;␊ |
762 | ␊ |
763 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
764 | ␉}␊ |
765 | ␊ |
766 | ␊ |
767 | ␉addSMBFirmwareVolume(structPtr);␊ |
768 | ␊ |
769 | ␉addSMBMemorySPD(structPtr);␊ |
770 | ␊ |
771 | ␉addSMBOemProcessorType(structPtr);␊ |
772 | ␊ |
773 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
774 | ␊ |
775 | ␉addSMBEndOfTable(structPtr);␊ |
776 | ␊ |
777 | ␊ |
778 | }␊ |
779 | ␊ |
780 | SMBEntryPoint * setupSMBIOSTable(SMBEntryPoint *origeps)␊ |
781 | {␊ |
782 | ␉SMBStructPtrs *structPtr;␊ |
783 | ␉uint8_t *buffer;␊ |
784 | ␉bool setSMB = true;␊ |
785 | ␊ |
786 | ␉if (!origeps)␊ |
787 | ␉␉return NULL;␊ |
788 | ␊ |
789 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
790 | ␉if (!structPtr)␊ |
791 | ␉␉return NULL;␊ |
792 | ␉␊ |
793 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
794 | ␉if (!buffer)␊ |
795 | ␉␉return NULL;␊ |
796 | ␊ |
797 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
798 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
799 | ␊ |
800 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->bootConfig);␊ |
801 | ␉if (setSMB)␊ |
802 | ␉␉setDefaultSMBData();␊ |
803 | ␊ |
804 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
805 | ␉␊ |
806 | ␉SMBEntryPoint *neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
807 | ␉if (!neweps)␊ |
808 | ␉␉return NULL;␊ |
809 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
810 | ␊ |
811 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
812 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
813 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
814 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
815 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
816 | ␉neweps->majorVersion␉␉= 2;␊ |
817 | ␉neweps->minorVersion␉␉= 4;␊ |
818 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
819 | ␉neweps->entryPointRevision␉= 0;␊ |
820 | ␊ |
821 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
822 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
823 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
824 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
825 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
826 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
827 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
828 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
829 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
830 | ␊ |
831 | ␉if (!neweps->dmi.tableAddress)␊ |
832 | ␉␉return NULL;␊ |
833 | ␊ |
834 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
835 | ␊ |
836 | ␉neweps->dmi.checksum␉␉= 0;␊ |
837 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
838 | ␊ |
839 | ␉neweps->checksum␉␉␉= 0;␊ |
840 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
841 | ␊ |
842 | ␉free(buffer);␊ |
843 | ␉decodeSMBIOSTable(neweps);␊ |
844 | ␊ |
845 | return neweps;␊ |
846 | }␊ |
847 | ␊ |
848 | /* Collect any information needed later */␊ |
849 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
850 | {␊ |
851 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
852 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
853 | ␊ |
854 | ␉int dimmnbr = 0;␊ |
855 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
856 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
857 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
858 | ␊ |
859 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
860 | ␉{␊ |
861 | ␉␉switch (structHeader->type)␊ |
862 | ␉␉{␊ |
863 | ␉␉␉case kSMBTypeSystemInformation:␊ |
864 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
865 | ␉␉␉␉break;␊ |
866 | ␊ |
867 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
868 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
869 | ␉␉␉␉break;␊ |
870 | ␊ |
871 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
872 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
873 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
874 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
875 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
876 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
877 | ␉␉␉␉dimmnbr++;␊ |
878 | ␉␉␉␉break;␊ |
879 | ␉␉␉default:␊ |
880 | ␉␉␉␉break;␊ |
881 | ␉␉}␊ |
882 | ␊ |
883 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
884 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
885 | ␊ |
886 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
887 | ␉␉␉structPtr += 2;␊ |
888 | ␊ |
889 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
890 | ␉}␊ |
891 | }␊ |
892 | ␊ |
893 | |