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