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