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␉␉␉␉␉" MM11.88Z.009A.B00.0903051113"␊ |
79 | ␊ |
80 | // defaults for a MacBook␊ |
81 | #define kDefaultMacBookFamily␉␉␉␉␉␉"MacBook"␊ |
82 | #define kDefaultMacBook␉␉␉␉␉␉␉␉"MacBook4,1"␊ |
83 | #define kDefaultMacBookBIOSVersion␉␉␉␉␉" MB41.88Z.0073.B00.0809221748"␊ |
84 | ␊ |
85 | // defaults for a MacBook Pro␊ |
86 | #define kDefaultMacBookProFamily␉␉␉␉␉"MacBookPro"␊ |
87 | #define kDefaultMacBookPro␉␉␉␉␉␉␉"MacBookPro5,1"␊ |
88 | #define kDefaultMacBookProBIOSVersion␉␉␉␉" MBP51.88Z.007E.B05.0906151647"␊ |
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.0802091538"␊ |
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 (Platform->Type == 2)␉␉//platformCPUFeature(CPU_FEATURE_MOBILE))␊ |
300 | ␉{␊ |
301 | ␉␉if (Platform->CPU.NoCores > 1) //Slice - it is wrong but we have no criteria to choose from␊ |
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 | ␉SMBWord tmp = 0;␊ |
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 | ␉␉␉␉case CPU_MODEL_SANDY:␊ |
585 | ␉␉␉␉case CPU_MODEL_SANDY_XEON:␊ |
586 | ␉␉␉␉␉tmp = p->ProcessorBusSpeed;␊ |
587 | ␉␉␉␉␉break;␊ |
588 | ␊ |
589 | ␉␉␉␉default:␊ |
590 | ␉␉␉␉␉tmp = (Platform->CPU.FSBFrequency * 4) / MEGA;␊ |
591 | ␉␉␉␉␉break;␊ |
592 | ␉␉␉␉␉//return;␊ |
593 | ␉␉␉}␊ |
594 | ␉␉}␊ |
595 | ␉}␊ |
596 | ␊ |
597 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
598 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
599 | ␉p->header.handle␉= handle++;␊ |
600 | ␊ |
601 | ␉if(!setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed)))␊ |
602 | ␉␉p->ProcessorBusSpeed = tmp;␊ |
603 | ␊ |
604 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
605 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
606 | ␉structureCount++;␊ |
607 | }␊ |
608 | ␊ |
609 | //-------------------------------------------------------------------------------------------------------------------------␊ |
610 | // EndOfTable␊ |
611 | //-------------------------------------------------------------------------------------------------------------------------␊ |
612 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
613 | {␊ |
614 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
615 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
616 | ␉structPtr->new->handle␉= handle++;␊ |
617 | ␊ |
618 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
619 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
620 | ␉structureCount++;␊ |
621 | }␊ |
622 | ␊ |
623 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
624 | {␊ |
625 | ␉bool setterFound = false;␊ |
626 | ␊ |
627 | ␉uint8_t *ptr;␊ |
628 | ␉SMBWord structSize;␊ |
629 | ␉int i;␊ |
630 | ␊ |
631 | ␉stringIndex = 1;␊ |
632 | ␉stringsSize = 0;␊ |
633 | ␊ |
634 | ␉if (handle < structPtr->orig->handle)␊ |
635 | ␉␉handle = structPtr->orig->handle;␊ |
636 | ␊ |
637 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
638 | ␊ |
639 | ␉for (i = 0; i < numOfSetters; i++)␊ |
640 | ␉␉if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
641 | ␉␉{␊ |
642 | ␉␉␉setterFound = true;␊ |
643 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
644 | ␉␉}␊ |
645 | ␊ |
646 | ␉if (setterFound)␊ |
647 | ␉{␊ |
648 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
649 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
650 | ␊ |
651 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
652 | ␉␉␉ptr += 2;␊ |
653 | ␊ |
654 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
655 | ␉}␊ |
656 | ␉else␊ |
657 | ␉{␊ |
658 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
659 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
660 | ␊ |
661 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
662 | ␉␉␉ptr += 2;␊ |
663 | ␉␉␊ |
664 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
665 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
666 | ␉}␊ |
667 | ␊ |
668 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
669 | ␊ |
670 | ␉tableLength += structSize;␊ |
671 | ␊ |
672 | ␉if (structSize > maxStructSize)␊ |
673 | ␉␉maxStructSize = structSize;␊ |
674 | ␊ |
675 | ␉structureCount++;␊ |
676 | }␊ |
677 | ␊ |
678 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
679 | {␊ |
680 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
681 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
682 | ␊ |
683 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
684 | ␉{␊ |
685 | ␉␉switch (structPtr->orig->type)␊ |
686 | ␉␉{␊ |
687 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
688 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
689 | ␉␉␉case kSMBTypeMemorySPD:␊ |
690 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
691 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
692 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
693 | ␉␉␉case kSMBTypeEndOfTable:␊ |
694 | ␉␉␉␉break;␊ |
695 | ␊ |
696 | ␉␉␉default:␊ |
697 | ␉␉␉␉/* Add */␊ |
698 | ␉␉␉␉setSMBStruct(structPtr);␊ |
699 | ␉␉␉␉break;␊ |
700 | ␉␉}␊ |
701 | ␊ |
702 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
703 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
704 | ␊ |
705 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
706 | ␉␉␉ptr += 2;␊ |
707 | ␊ |
708 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
709 | ␉}␊ |
710 | ␊ |
711 | ␉addSMBFirmwareVolume(structPtr);␊ |
712 | ␉addSMBMemorySPD(structPtr);␊ |
713 | ␉addSMBOemProcessorType(structPtr);␊ |
714 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
715 | ␊ |
716 | ␉addSMBEndOfTable(structPtr);␊ |
717 | }␊ |
718 | ␊ |
719 | void setupSMBIOSTable(void)␊ |
720 | {␊ |
721 | ␉SMBStructPtrs *structPtr;␊ |
722 | ␉uint8_t *buffer;␊ |
723 | ␉bool setSMB = true;␊ |
724 | ␊ |
725 | ␉if (!origeps)␊ |
726 | ␉␉return;␊ |
727 | ␊ |
728 | ␉neweps = origeps;␊ |
729 | ␊ |
730 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
731 | ␉if (!structPtr)␊ |
732 | ␉␉return;␊ |
733 | ␉␊ |
734 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
735 | ␉if (!buffer)␊ |
736 | ␉␉return;␊ |
737 | ␊ |
738 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
739 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
740 | ␊ |
741 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);␊ |
742 | ␉if (setSMB)␊ |
743 | ␉␉setDefaultSMBData();␊ |
744 | ␊ |
745 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
746 | ␊ |
747 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
748 | ␉if (!neweps)␊ |
749 | ␉␉return;␊ |
750 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
751 | ␊ |
752 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
753 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
754 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
755 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
756 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
757 | ␉neweps->majorVersion␉␉= 2;␊ |
758 | ␉neweps->minorVersion␉␉= 4;␊ |
759 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
760 | ␉neweps->entryPointRevision␉= 0;␊ |
761 | ␊ |
762 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
763 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
764 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
765 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
766 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
767 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
768 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
769 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
770 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
771 | ␊ |
772 | ␉if (!neweps->dmi.tableAddress)␊ |
773 | ␉␉return;␊ |
774 | ␊ |
775 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
776 | ␊ |
777 | ␉neweps->dmi.checksum␉␉= 0;␊ |
778 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
779 | ␊ |
780 | ␉neweps->checksum␉␉␉= 0;␊ |
781 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
782 | ␊ |
783 | ␉free(buffer);␊ |
784 | ␉decodeSMBIOSTable(neweps);␊ |
785 | }␊ |
786 | ␊ |
787 | void *getSmbios(int which)␊ |
788 | {␊ |
789 | ␉switch (which)␊ |
790 | ␉{␊ |
791 | ␉␉case SMBIOS_ORIGINAL:␊ |
792 | ␉␉␉if (!origeps)␊ |
793 | ␉␉␉␉origeps = getAddressOfSmbiosTable();␊ |
794 | ␉␉␉return origeps;␊ |
795 | ␉␉case SMBIOS_PATCHED:␊ |
796 | ␉␉␉return neweps;␊ |
797 | ␉}␊ |
798 | ␊ |
799 | ␉return 0;␊ |
800 | }␊ |
801 | ␊ |
802 | /** Find first original dmi Table with a particular type */␊ |
803 | SMBStructHeader* FindFirstDmiTableOfType(int type, int minlength)␊ |
804 | {␊ |
805 | current_pos = 0; //static variable␊ |
806 | ␊ |
807 | return FindNextDmiTableOfType(type, minlength);␊ |
808 | };␊ |
809 | ␊ |
810 | /** Find next original dmi Table with a particular type */␊ |
811 | SMBStructHeader* FindNextDmiTableOfType(int type, int minlength)␊ |
812 | {␊ |
813 | int i;␊ |
814 | ␉␊ |
815 | if (ftTablePairInit) getSmbios(SMBIOS_ORIGINAL);␊ |
816 | ␉␊ |
817 | for (i=current_pos; i < DmiTablePairCount; i++) {␊ |
818 | if (type == DmiTablePair[i].type && ␊ |
819 | DmiTablePair[i].dmi &&␊ |
820 | DmiTablePair[i].dmi->length >= minlength ) {␊ |
821 | current_pos = i+1;␊ |
822 | return DmiTablePair[i].dmi;␊ |
823 | }␊ |
824 | }␊ |
825 | return NULL; // not found␊ |
826 | };␊ |
827 | ␊ |
828 | ␊ |
829 | /* Collect any information needed later */␊ |
830 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
831 | {␊ |
832 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
833 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
834 | ␉SMBByte tmp = 0;␊ |
835 | ␊ |
836 | ␉int dimmnbr = 0;␊ |
837 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
838 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
839 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
840 | ␊ |
841 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
842 | ␉{␊ |
843 | ␉␉switch (structHeader->type)␊ |
844 | ␉␉{␊ |
845 | ␉␉␉case kSMBTypeSystemInformation:␊ |
846 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
847 | ␉␉␉␉break;␊ |
848 | //Slice - platform mobility should based on Enclosure but not on CPU type␊ |
849 | ␉␉␉case kSMBTypeSystemEnclosure:␊ |
850 | ␉␉␉␉tmp = ((SMBSystemEnclosure *)structHeader)->type;␊ |
851 | ␉␉␉␉Platform->Type = (tmp >=8)?2:1;␊ |
852 | ␉␉␉␉break;␊ |
853 | //Slice - values from DMI/SMBIOS are defined correct if overclocked␉␊ |
854 | // do not need in complex MSR calculation␉␉␉␉␊ |
855 | ␉␉␉case kSMBTypeProcessorInformation:␊ |
856 | ␉␉␉␉tmp = ((SMBProcessorInformation *)structHeader)->externalClock;␊ |
857 | ␉␉␉␉Platform->CPU.FSBFrequency = tmp * MEGA + (tmp & 7) * 110000; //According to Intel␊ |
858 | ␉␉␉␉tmp = ((SMBProcessorInformation *)structHeader)->currentClock;␊ |
859 | ␉␉␉␉Platform->CPU.CPUFrequency = tmp * MEGA + (tmp & 7) * 110000;␊ |
860 | ␉␉␉␉break;␊ |
861 | ␉␊ |
862 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
863 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
864 | ␉␉␉␉break;␊ |
865 | ␊ |
866 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
867 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
868 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
869 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
870 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
871 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
872 | ␉␉␉␉dimmnbr++;␊ |
873 | ␉␉␉␉break;␊ |
874 | ␉␉}␊ |
875 | ␊ |
876 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
877 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
878 | ␊ |
879 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
880 | ␉␉␉structPtr += 2;␊ |
881 | ␊ |
882 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
883 | ␉}␊ |
884 | }␊ |
885 | |