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,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.B0A.1104221555"␊ |
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 | ␊ |
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␉␉= kDefaultMacProWestmereBIOSReleaseDate;␊ |
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 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
398 | ␉␉␉return true;␊ |
399 | ␉else␊ |
400 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
401 | ␉␉␉return true;␊ |
402 | ␉return false;␊ |
403 | }␊ |
404 | ␊ |
405 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
406 | {␊ |
407 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
408 | ␊ |
409 | ␉if (!field)␊ |
410 | ␉␉return NULL;␊ |
411 | ␊ |
412 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
413 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
414 | ␊ |
415 | ␉return (char *)stringPtr;␊ |
416 | }␊ |
417 | ␊ |
418 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
419 | {␊ |
420 | ␉int strSize;␊ |
421 | ␊ |
422 | ␉if (!field)␊ |
423 | ␉␉return;␊ |
424 | ␉if (!string)␊ |
425 | ␉{␊ |
426 | ␉␉*field = 0;␊ |
427 | ␉␉return;␊ |
428 | ␉}␊ |
429 | ␊ |
430 | ␉strSize = strlen(string);␊ |
431 | ␊ |
432 | ␉// remove any spaces found at the end␊ |
433 | ␉while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
434 | ␉␉strSize--;␊ |
435 | ␊ |
436 | ␉if (strSize == 0)␊ |
437 | ␉{␊ |
438 | ␉␉*field = 0;␊ |
439 | ␉␉return;␊ |
440 | ␉}␊ |
441 | ␊ |
442 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
443 | ␉*field = stringIndex;␊ |
444 | ␊ |
445 | ␉stringIndex++;␊ |
446 | ␉stringsSize += strSize + 1;␊ |
447 | }␊ |
448 | ␊ |
449 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
450 | {␊ |
451 | ␉const char *string = 0;␊ |
452 | ␉int len;␊ |
453 | ␉bool parsed;␊ |
454 | ␉int val;␊ |
455 | ␊ |
456 | ␉if (numOfSetters <= idx)␊ |
457 | ␉␉return false;␊ |
458 | ␊ |
459 | ␉switch (SMBSetters[idx].valueType)␊ |
460 | ␉{␊ |
461 | ␉␉case kSMBString:␊ |
462 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
463 | ␉␉␉{␊ |
464 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
465 | ␉␉␉␉␉break;␊ |
466 | ␉␉␉␉else␊ |
467 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
468 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
469 | ␉␉␉␉␉␉␉break;␊ |
470 | ␉␉␉}␊ |
471 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
472 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
473 | ␉␉␉␉␉break;␊ |
474 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
475 | ␉␉␉{␊ |
476 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
477 | ␉␉␉␉break;␊ |
478 | ␉␉␉}␊ |
479 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
480 | ␉␉␉break;␊ |
481 | ␊ |
482 | ␉␉case kSMBByte:␊ |
483 | ␉␉case kSMBWord:␊ |
484 | ␉␉case kSMBDWord:␊ |
485 | ␉␉//case kSMBQWord:␊ |
486 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
487 | ␉␉␉{␊ |
488 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
489 | ␉␉␉␉if (!parsed)␊ |
490 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
491 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
492 | ␉␉␉␉if (parsed)␊ |
493 | ␉␉␉␉{␊ |
494 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
495 | ␉␉␉␉␉{␊ |
496 | ␉␉␉␉␉␉case kSMBByte:␊ |
497 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
498 | ␉␉␉␉␉␉␉break;␊ |
499 | ␉␉␉␉␉␉case kSMBWord:␊ |
500 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
501 | ␉␉␉␉␉␉␉break;␊ |
502 | ␉␉␉␉␉␉case kSMBDWord:␊ |
503 | ␉␉␉␉␉␉default:␊ |
504 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
505 | ␉␉␉␉␉␉␉break;␊ |
506 | ␉␉␉␉␉}␊ |
507 | ␉␉␉␉␉return true;␊ |
508 | ␉␉␉␉}␊ |
509 | ␉␉␉}␊ |
510 | ␊ |
511 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
512 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
513 | ␉␉␉␉␉return true;␊ |
514 | #if 0␊ |
515 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
516 | ␉␉␉{␊ |
517 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
518 | ␉␉␉␉return true;␊ |
519 | ␉␉␉}␊ |
520 | #endif␊ |
521 | ␉␉␉break;␊ |
522 | ␉}␊ |
523 | ␊ |
524 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
525 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
526 | ␊ |
527 | ␉return true;␊ |
528 | }␊ |
529 | ␊ |
530 | //-------------------------------------------------------------------------------------------------------------------------␊ |
531 | // Apple Specific␊ |
532 | //-------------------------------------------------------------------------------------------------------------------------␊ |
533 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
534 | {␊ |
535 | ␉return;␊ |
536 | }␊ |
537 | ␊ |
538 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
539 | {␊ |
540 | ␉/* SPD data from Platform.RAM.spd */␊ |
541 | ␉return;␊ |
542 | }␊ |
543 | ␊ |
544 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
545 | {␊ |
546 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
547 | ␊ |
548 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
549 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
550 | ␉p->header.handle␉= handle++;␊ |
551 | ␊ |
552 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
553 | ␊ |
554 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
555 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
556 | ␉structureCount++;␊ |
557 | }␊ |
558 | ␊ |
559 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
560 | {␊ |
561 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
562 | ␊ |
563 | ␉switch (Platform.CPU.Family) ␊ |
564 | ␉{␊ |
565 | ␉␉case 0x06:␊ |
566 | ␉␉{␊ |
567 | ␉␉␉switch (Platform.CPU.Model)␊ |
568 | ␉␉␉{␊ |
569 | ␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
570 | ␉␉␉␉case CPU_MODEL_DALES:␊ |
571 | ␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
572 | ␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
573 | ␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
574 | ␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
575 | ␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉// Intel Xeon E7␊ |
576 | ␉␉␉␉␉break;␊ |
577 | ␊ |
578 | ␉␉␉␉default:␊ |
579 | ␉␉␉␉␉return;␊ |
580 | ␉␉␉}␊ |
581 | ␉␉}␊ |
582 | ␉}␊ |
583 | ␊ |
584 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
585 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
586 | ␉p->header.handle␉= handle++;␊ |
587 | ␊ |
588 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
589 | ␊ |
590 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
591 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
592 | ␉structureCount++;␊ |
593 | }␊ |
594 | ␊ |
595 | //-------------------------------------------------------------------------------------------------------------------------␊ |
596 | // EndOfTable␊ |
597 | //-------------------------------------------------------------------------------------------------------------------------␊ |
598 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
599 | {␊ |
600 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
601 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
602 | ␉structPtr->new->handle␉= handle++;␊ |
603 | ␊ |
604 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
605 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
606 | ␉structureCount++;␊ |
607 | }␊ |
608 | ␊ |
609 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
610 | {␊ |
611 | ␉bool setterFound = false;␊ |
612 | ␊ |
613 | ␉uint8_t *ptr;␊ |
614 | ␉SMBWord structSize;␊ |
615 | ␉int i;␊ |
616 | ␊ |
617 | ␉stringIndex = 1;␊ |
618 | ␉stringsSize = 0;␊ |
619 | ␊ |
620 | ␉if (handle < structPtr->orig->handle)␊ |
621 | ␉␉handle = structPtr->orig->handle;␊ |
622 | ␊ |
623 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
624 | ␊ |
625 | ␉for (i = 0; i < numOfSetters; i++)␊ |
626 | ␉␉if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
627 | ␉␉{␊ |
628 | ␉␉␉setterFound = true;␊ |
629 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
630 | ␉␉}␊ |
631 | ␊ |
632 | ␉if (setterFound)␊ |
633 | ␉{␊ |
634 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
635 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
636 | ␊ |
637 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
638 | ␉␉␉ptr += 2;␊ |
639 | ␊ |
640 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
641 | ␉}␊ |
642 | ␉else␊ |
643 | ␉{␊ |
644 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
645 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
646 | ␊ |
647 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
648 | ␉␉␉ptr += 2;␊ |
649 | ␉␉␊ |
650 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
651 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
652 | ␉}␊ |
653 | ␊ |
654 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
655 | ␊ |
656 | ␉tableLength += structSize;␊ |
657 | ␊ |
658 | ␉if (structSize > maxStructSize)␊ |
659 | ␉␉maxStructSize = structSize;␊ |
660 | ␊ |
661 | ␉structureCount++;␊ |
662 | }␊ |
663 | ␊ |
664 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
665 | {␊ |
666 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
667 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
668 | ␊ |
669 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
670 | ␉{␊ |
671 | ␉␉switch (structPtr->orig->type)␊ |
672 | ␉␉{␊ |
673 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
674 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
675 | ␉␉␉case kSMBTypeMemorySPD:␊ |
676 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
677 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
678 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
679 | ␉␉␉case kSMBTypeEndOfTable:␊ |
680 | ␉␉␉␉break;␊ |
681 | ␊ |
682 | ␉␉␉default:␊ |
683 | ␉␉␉␉/* Add */␊ |
684 | ␉␉␉␉setSMBStruct(structPtr);␊ |
685 | ␉␉␉␉break;␊ |
686 | ␉␉}␊ |
687 | ␊ |
688 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
689 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
690 | ␊ |
691 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
692 | ␉␉␉ptr += 2;␊ |
693 | ␊ |
694 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
695 | ␉}␊ |
696 | ␊ |
697 | ␉addSMBFirmwareVolume(structPtr);␊ |
698 | ␉addSMBMemorySPD(structPtr);␊ |
699 | ␉addSMBOemProcessorType(structPtr);␊ |
700 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
701 | ␊ |
702 | ␉addSMBEndOfTable(structPtr);␊ |
703 | }␊ |
704 | ␊ |
705 | void setupSMBIOSTable(void)␊ |
706 | {␊ |
707 | ␉SMBStructPtrs *structPtr;␊ |
708 | ␉uint8_t *buffer;␊ |
709 | ␉bool setSMB = true;␊ |
710 | ␊ |
711 | ␉if (!origeps)␊ |
712 | ␉␉return;␊ |
713 | ␊ |
714 | ␉neweps = origeps;␊ |
715 | ␊ |
716 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
717 | ␉if (!structPtr)␊ |
718 | ␉␉return;␊ |
719 | ␉␊ |
720 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
721 | ␉if (!buffer)␊ |
722 | ␉␉return;␊ |
723 | ␊ |
724 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
725 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
726 | ␊ |
727 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);␊ |
728 | ␉if (setSMB)␊ |
729 | ␉␉setDefaultSMBData();␊ |
730 | ␊ |
731 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
732 | ␊ |
733 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
734 | ␉if (!neweps)␊ |
735 | ␉␉return;␊ |
736 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
737 | ␊ |
738 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
739 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
740 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
741 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
742 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
743 | ␉neweps->majorVersion␉␉= 2;␊ |
744 | ␉neweps->minorVersion␉␉= 4;␊ |
745 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
746 | ␉neweps->entryPointRevision␉= 0;␊ |
747 | ␊ |
748 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
749 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
750 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
751 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
752 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
753 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
754 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
755 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
756 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
757 | ␊ |
758 | ␉if (!neweps->dmi.tableAddress)␊ |
759 | ␉␉return;␊ |
760 | ␊ |
761 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
762 | ␊ |
763 | ␉neweps->dmi.checksum␉␉= 0;␊ |
764 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
765 | ␊ |
766 | ␉neweps->checksum␉␉␉= 0;␊ |
767 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
768 | ␊ |
769 | ␉free(buffer);␊ |
770 | ␉decodeSMBIOSTable(neweps);␊ |
771 | }␊ |
772 | ␊ |
773 | void *getSmbios(int which)␊ |
774 | {␊ |
775 | ␉switch (which)␊ |
776 | ␉{␊ |
777 | ␉␉case SMBIOS_ORIGINAL:␊ |
778 | ␉␉␉if (!origeps)␊ |
779 | ␉␉␉␉origeps = getAddressOfSmbiosTable();␊ |
780 | ␉␉␉return origeps;␊ |
781 | ␉␉case SMBIOS_PATCHED:␊ |
782 | ␉␉␉return neweps;␊ |
783 | ␉}␊ |
784 | ␊ |
785 | ␉return 0;␊ |
786 | }␊ |
787 | ␊ |
788 | /* Collect any information needed later */␊ |
789 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
790 | {␊ |
791 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
792 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
793 | ␊ |
794 | ␉int dimmnbr = 0;␊ |
795 | ␉Platform.DMI.MaxMemorySlots␉= 0;␊ |
796 | ␉Platform.DMI.CntMemorySlots␉= 0;␊ |
797 | ␉Platform.DMI.MemoryModules␉= 0;␊ |
798 | ␊ |
799 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
800 | ␉{␊ |
801 | ␉␉switch (structHeader->type)␊ |
802 | ␉␉{␊ |
803 | ␉␉␉case kSMBTypeSystemInformation:␊ |
804 | ␉␉␉␉Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
805 | ␉␉␉␉break;␊ |
806 | ␊ |
807 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
808 | ␉␉␉␉Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
809 | ␉␉␉␉break;␊ |
810 | ␊ |
811 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
812 | ␉␉␉␉Platform.DMI.CntMemorySlots++;␊ |
813 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
814 | ␉␉␉␉␉Platform.DMI.MemoryModules++;␊ |
815 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
816 | ␉␉␉␉␉Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
817 | ␉␉␉␉dimmnbr++;␊ |
818 | ␉␉␉␉break;␊ |
819 | ␉␉}␊ |
820 | ␊ |
821 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
822 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
823 | ␊ |
824 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
825 | ␉␉␉structPtr += 2;␊ |
826 | ␊ |
827 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
828 | ␉}␊ |
829 | }␊ |
830 | ␊ |
831 | |