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