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