Root/
Source at commit 2381 created 10 years 21 days ago. By ifabio, Apply patch: (Credits to Thomas Jansen aka tja) - Reading options from all devices during boot. The options for the boot menu are only read from the devices rd(0,0) or bt(0,0). Consequently, boot menu options (e.g. "Quiet Boot", "Timeout", etc.) in plists on other devices (like most users have) are ignored. This patch extends the list of paths to search for the options plist on all devices that can be found. | |
---|---|
1 | /*␊ |
2 | * SMBIOS Table Patcher, part of the Chameleon Boot Loader Project␊ |
3 | *␊ |
4 | * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.␊ |
5 | *␊ |
6 | */␊ |
7 | ␊ |
8 | ␊ |
9 | #include "boot.h"␊ |
10 | #include "bootstruct.h"␊ |
11 | #include "smbios_getters.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_SMBIOS␊ |
14 | #define DEBUG_SMBIOS 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_SMBIOS␊ |
18 | #define DBG(x...)␉printf(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␉msglog(x)␊ |
21 | #endif␊ |
22 | ␊ |
23 | #define SMBPlist␉␉␉&bootInfo->smbiosConfig␊ |
24 | /* ASSUMPTION: 16KB should be enough for the whole thing */␊ |
25 | #define SMB_ALLOC_SIZE␉16384␊ |
26 | ␊ |
27 | ␊ |
28 | //-------------------------------------------------------------------------------------------------------------------------␊ |
29 | // SMBIOS Plist Keys␊ |
30 | //-------------------------------------------------------------------------------------------------------------------------␊ |
31 | /* BIOS Information */␊ |
32 | #define kSMBBIOSInformationVendorKey␉␉␉␉"SMbiosvendor"␊ |
33 | #define kSMBBIOSInformationVersionKey␉␉␉␉"SMbiosversion"␊ |
34 | #define kSMBBIOSInformationReleaseDateKey␉␉␉"SMbiosdate"␊ |
35 | ␊ |
36 | /* System Information */␊ |
37 | #define kSMBSystemInformationManufacturerKey␉␉"SMmanufacturer"␊ |
38 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
39 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
40 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
41 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
42 | ␊ |
43 | /* Base Board */␊ |
44 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacturer"␊ |
45 | #define kSMBBaseBoardProductKey␉␉␉␉␉␉"SMboardproduct"␊ |
46 | ␊ |
47 | /* Processor Information */␊ |
48 | #define kSMBProcessorInformationExternalClockKey␉"SMexternalclock"␊ |
49 | #define kSMBProcessorInformationMaximumClockKey␉␉"SMmaximalclock"␊ |
50 | ␊ |
51 | /* Memory Device */␊ |
52 | #define kSMBMemoryDeviceDeviceLocatorKey␉␉␉"SMmemdevloc"␊ |
53 | #define kSMBMemoryDeviceBankLocatorKey␉␉␉␉"SMmembankloc"␊ |
54 | #define kSMBMemoryDeviceMemoryTypeKey␉␉␉␉"SMmemtype"␊ |
55 | #define kSMBMemoryDeviceMemorySpeedKey␉␉␉␉"SMmemspeed"␊ |
56 | #define kSMBMemoryDeviceManufacturerKey␉␉␉␉"SMmemmanufacturer"␊ |
57 | #define kSMBMemoryDeviceSerialNumberKey␉␉␉␉"SMmemserial"␊ |
58 | #define kSMBMemoryDevicePartNumberKey␉␉␉␉"SMmempart"␊ |
59 | ␊ |
60 | /* Apple Specific */␊ |
61 | #define kSMBOemProcessorTypeKey␉␉␉␉␉␉"SMcputype"␊ |
62 | #define kSMBOemProcessorBusSpeedKey␉␉␉␉␉"SMbusspeed"␊ |
63 | ␊ |
64 | //-------------------------------------------------------------------------------------------------------------------------␊ |
65 | // Default SMBIOS Data␊ |
66 | //-------------------------------------------------------------------------------------------------------------------------␊ |
67 | /* Rewrite: use a struct */␊ |
68 | ␊ |
69 | #define kDefaultVendorManufacturer␉␉␉␉␉"Apple Inc."␊ |
70 | #define kDefaultBIOSReleaseDate␉␉␉␉␉␉"11/06/2009"␊ |
71 | #define kDefaultSerialNumber␉␉␉␉␉␉"SOMESRLNMBR"␊ |
72 | #define kDefaultBoardProduct␉␉␉␉␉␉"Mac-F4208DC8"␊ |
73 | #define kDefaultSystemVersion␉␉␉␉␉␉"1.0"␊ |
74 | ␊ |
75 | // defaults for a Mac mini ␊ |
76 | #define kDefaultMacminiFamily␉␉␉␉␉␉"Macmini"␊ |
77 | #define kDefaultMacmini␉␉␉␉␉␉␉␉"Macmini1,1"␊ |
78 | #define kDefaultMacminiBIOSVersion␉␉␉␉␉" MM21.88Z.009A.B00.0903051113"␊ |
79 | ␊ |
80 | // defaults for a MacBook␊ |
81 | #define kDefaultMacBookFamily␉␉␉␉␉␉"MacBook"␊ |
82 | #define kDefaultMacBook␉␉␉␉␉␉␉␉"MacBook4,1"␊ |
83 | #define kDefaultMacBookBIOSVersion␉␉␉␉␉" MB41.88Z.0073.B00.0903051113"␊ |
84 | ␊ |
85 | // defaults for a MacBook Pro␊ |
86 | #define kDefaultMacBookProFamily␉␉␉␉␉"MacBookPro"␊ |
87 | #define kDefaultMacBookPro␉␉␉␉␉␉␉"MacBookPro4,1"␊ |
88 | #define kDefaultMacBookProBIOSVersion␉␉␉␉" MBP41.88Z.0073.B00.0903051113"␊ |
89 | ␊ |
90 | // defaults for an iMac␊ |
91 | #define kDefaultiMacFamily␉␉␉␉␉␉␉"iMac"␊ |
92 | #define kDefaultiMac␉␉␉␉␉␉␉␉"iMac8,1"␊ |
93 | #define kDefaultiMacBIOSVersion␉␉␉␉␉␉" IM81.88Z.00C1.B00.0903051113"␊ |
94 | // defaults for an iMac11,1 core i3/i5/i7␊ |
95 | #define kDefaultiMacNehalem␉␉␉␉␉␉␉"iMac11,1"␊ |
96 | #define kDefaultiMacNehalemBIOSVersion␉␉␉␉" IM111.88Z.0034.B00.0903051113"␊ |
97 | // defaults for an iMac12,1␊ |
98 | #define kDefaultiMacSandy␉␉␉␉␉␉␉"iMac12,1"␊ |
99 | #define kDefaultiMacSandyBIOSVersion␉␉␉␉" IM121.88Z.0047.B00.1102091756"␊ |
100 | ␊ |
101 | // defaults for a Mac Pro␊ |
102 | #define kDefaultMacProFamily␉␉␉␉␉␉"MacPro"␊ |
103 | #define kDefaultMacPro␉␉␉␉␉␉␉␉"MacPro3,1"␊ |
104 | #define kDefaultMacProBIOSVersion␉␉␉␉␉" MP31.88Z.006C.B05.0903051113"␊ |
105 | // defaults for a Mac Pro 4,1 core i7/Xeon␊ |
106 | #define kDefaultMacProNehalem␉␉␉␉␉␉"MacPro4,1"␊ |
107 | #define kDefaultMacProNehalemBIOSVersion␉␉␉" MP41.88Z.0081.B04.0903051113"␊ |
108 | // defaults for a Mac Pro 5,1 core i7/Xeon␊ |
109 | #define kDefaultMacProWestmere␉␉␉␉␉␉"MacPro5,1"␊ |
110 | #define kDefaultMacProWestmereBIOSVersion␉␉␉" MP51.88Z.007F.B00.1008031144"␊ |
111 | #define kDefaulMacProWestmereBIOSReleaseDate␉␉"08/03/10"␊ |
112 | //-------------------------------------------------------------------------------------------------------------------------␊ |
113 | ␊ |
114 | ␊ |
115 | #define getFieldOffset(struct, field)␉((uint8_t)(uint32_t)&(((struct *)0)->field))␊ |
116 | ␊ |
117 | typedef struct {␊ |
118 | ␉SMBStructHeader *orig;␊ |
119 | ␉SMBStructHeader *new;␊ |
120 | } SMBStructPtrs;␊ |
121 | ␊ |
122 | struct {␊ |
123 | ␉char *vendor;␊ |
124 | ␉char *version;␊ |
125 | ␉char *releaseDate;␊ |
126 | } defaultBIOSInfo;␊ |
127 | ␊ |
128 | struct {␊ |
129 | ␉char *manufacturer;␊ |
130 | ␉char *productName;␊ |
131 | ␉char *version;␊ |
132 | ␉char *serialNumber;␊ |
133 | ␉char *family;␊ |
134 | } defaultSystemInfo;␊ |
135 | ␊ |
136 | struct {␊ |
137 | ␉char *manufacturer;␊ |
138 | ␉char *product;␊ |
139 | } defaultBaseBoard;␊ |
140 | ␊ |
141 | ␊ |
142 | typedef struct {␊ |
143 | ␉uint8_t␉␉␉type;␊ |
144 | ␉SMBValueType␉valueType;␊ |
145 | ␉uint8_t␉␉␉fieldOffset;␊ |
146 | ␉char␉␉␉*keyString;␊ |
147 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
148 | ␉char␉␉␉**defaultValue;␊ |
149 | } SMBValueSetter;␊ |
150 | ␊ |
151 | SMBValueSetter SMBSetters[] = ␊ |
152 | {␊ |
153 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
154 | ␉// BIOSInformation␊ |
155 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
156 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
157 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
158 | ␊ |
159 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
160 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
161 | ␊ |
162 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
163 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
164 | ␊ |
165 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
166 | ␉// SystemInformation␊ |
167 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
168 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
169 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
170 | ␊ |
171 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
172 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
173 | ␊ |
174 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
175 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
176 | ␊ |
177 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
178 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
179 | ␊ |
180 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
181 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
182 | ␊ |
183 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
184 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
185 | ␊ |
186 | ␊ |
187 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
188 | ␉// BaseBoard␊ |
189 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
190 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
191 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
192 | ␊ |
193 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
194 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
195 | ␊ |
196 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
197 | ␊ |
198 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
199 | ␊ |
200 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
201 | ␊ |
202 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
203 | ␊ |
204 | ␊ |
205 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
206 | ␉// ProcessorInformation␊ |
207 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
208 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
209 | ␊ |
210 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
211 | ␊ |
212 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
213 | ␊ |
214 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
215 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
216 | ␊ |
217 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
218 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
219 | ␊ |
220 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
221 | ␊ |
222 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
223 | ␊ |
224 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
225 | ␊ |
226 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
227 | ␉// Memory Device␊ |
228 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
229 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
230 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
231 | ␊ |
232 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
233 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
234 | ␊ |
235 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
236 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
237 | ␊ |
238 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
239 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
240 | ␊ |
241 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
242 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
243 | ␊ |
244 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
245 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
246 | ␊ |
247 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
248 | ␊ |
249 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
250 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
251 | ␊ |
252 | ␊ |
253 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
254 | ␉// Apple Specific␊ |
255 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
256 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
257 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
258 | ␊ |
259 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
260 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
261 | };␊ |
262 | ␊ |
263 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
264 | ␊ |
265 | ␊ |
266 | SMBEntryPoint *origeps␉= 0;␊ |
267 | SMBEntryPoint *neweps␉= 0;␊ |
268 | ␊ |
269 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
270 | static uint8_t stringsSize;␉// add string size␊ |
271 | ␊ |
272 | static SMBWord tableLength␉␉= 0;␊ |
273 | static SMBWord handle␉␉␉= 0;␊ |
274 | static SMBWord maxStructSize␉= 0;␊ |
275 | static SMBWord structureCount␉= 0;␊ |
276 | ␊ |
277 | /* Rewrite this function */␊ |
278 | void setDefaultSMBData(void)␊ |
279 | {␊ |
280 | ␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
281 | ␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
282 | ␊ |
283 | ␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
284 | ␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
285 | ␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
286 | ␊ |
287 | ␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
288 | ␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
289 | ␊ |
290 | ␉if (platformCPUFeature(CPU_FEATURE_MOBILE))␊ |
291 | ␉{␊ |
292 | ␉␉if (Platform.CPU.NoCores > 1)␊ |
293 | ␉␉{␊ |
294 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookProBIOSVersion;␊ |
295 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBookPro;␊ |
296 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookProFamily;␊ |
297 | ␉␉}␊ |
298 | ␉␉else␊ |
299 | ␉␉{␊ |
300 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookBIOSVersion;␊ |
301 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBook;␊ |
302 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookFamily;␊ |
303 | ␉␉}␊ |
304 | ␉}␊ |
305 | ␉else␊ |
306 | ␉{␊ |
307 | ␉␉switch (Platform.CPU.NoCores) ␊ |
308 | ␉␉{␊ |
309 | ␉␉␉case 1: ␊ |
310 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacminiBIOSVersion;␊ |
311 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacmini;␊ |
312 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacminiFamily;␊ |
313 | ␉␉␉␉break;␊ |
314 | ␊ |
315 | ␉␉␉case 2:␊ |
316 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacBIOSVersion;␊ |
317 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMac;␊ |
318 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
319 | ␉␉␉␉break;␊ |
320 | ␉␉␉default:␊ |
321 | ␉␉␉{␊ |
322 | ␉␉␉␉switch (Platform.CPU.Family) ␊ |
323 | ␉␉␉␉{␊ |
324 | ␉␉␉␉␉case 0x06:␊ |
325 | ␉␉␉␉␉{␊ |
326 | ␉␉␉␉␉␉switch (Platform.CPU.Model)␊ |
327 | ␉␉␉␉␉␉{␊ |
328 | ␉␉␉␉␉␉␉case CPU_MODEL_FIELDS:␉␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
329 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES:␊ |
330 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
331 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacNehalemBIOSVersion;␊ |
332 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacNehalem;␊ |
333 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
334 | ␉␉␉␉␉␉␉␉break;␊ |
335 | ␊ |
336 | ␉␉␉␉␉␉␉case CPU_MODEL_SANDYBRIDGE:␉␉␉// Intel Core i3, i5, i7 LGA1155 (32nm)␊ |
337 | ␉␉␉␉␉␉␉case CPU_MODEL_JAKETOWN:␉␉␉// Intel Core i7, Xeon E5 LGA2011 (32nm)␊ |
338 | ␉␉␉␉␉␉␉case CPU_MODEL_IVYBRIDGE:␉␉␉// Intel Core i3, i5, i7 LGA1155 (22nm)␊ |
339 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacSandyBIOSVersion;␊ |
340 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacSandy;␊ |
341 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
342 | ␉␉␉␉␉␉␉␉break;␊ |
343 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM:␉␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
344 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
345 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
346 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
347 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
348 | ␉␉␉␉␉␉␉␉break;␊ |
349 | ␊ |
350 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE:␉␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
351 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉␉// Intel Xeon E7␊ |
352 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProWestmereBIOSVersion;␊ |
353 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulMacProWestmereBIOSReleaseDate;␊ |
354 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProWestmere;␊ |
355 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
356 | ␉␉␉␉␉␉␉␉break;␊ |
357 | ␊ |
358 | ␉␉␉␉␉␉␉default:␊ |
359 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
360 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
361 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
362 | ␉␉␉␉␉␉␉␉break;␊ |
363 | ␉␉␉␉␉␉}␊ |
364 | ␉␉␉␉␉␉break;␊ |
365 | ␉␉␉␉␉}␊ |
366 | ␉␉␉␉␉default:␊ |
367 | ␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
368 | ␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
369 | ␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
370 | ␉␉␉␉␉␉break;␊ |
371 | ␉␉␉␉}␊ |
372 | ␉␉␉␉break;␊ |
373 | ␉␉␉}␊ |
374 | ␉␉}␊ |
375 | ␉}␊ |
376 | }␊ |
377 | ␊ |
378 | /* Used for SM*n smbios.plist keys */␊ |
379 | bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
380 | {␊ |
381 | ␉static int idx = -1;␊ |
382 | ␉static int current = -1;␊ |
383 | ␉int len;␊ |
384 | ␉char key[24];␊ |
385 | ␊ |
386 | ␉if (current != structHeader->handle)␊ |
387 | ␉{␊ |
388 | ␉␉idx++;␊ |
389 | ␉␉current = structHeader->handle;␊ |
390 | ␉}␊ |
391 | ␊ |
392 | ␉sprintf(key, "%s%d", keyString, idx);␉␊ |
393 | ␊ |
394 | if (value) ␊ |
395 | {␊ |
396 | if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
397 | return true;␊ |
398 | }␊ |
399 | else ␊ |
400 | {␊ |
401 | if (getValueForKey(key, string, &len, SMBPlist))␊ |
402 | return true;␊ |
403 | }␊ |
404 | ␊ |
405 | ␉return false;␊ |
406 | }␊ |
407 | ␊ |
408 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
409 | {␊ |
410 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
411 | ␊ |
412 | ␉if (!field)␊ |
413 | ␉␉return NULL;␊ |
414 | ␊ |
415 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
416 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
417 | ␊ |
418 | ␉return (char *)stringPtr;␊ |
419 | }␊ |
420 | ␊ |
421 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
422 | {␊ |
423 | ␉int strSize;␊ |
424 | ␊ |
425 | ␉if (!field)␊ |
426 | ␉␉return;␊ |
427 | ␉if (!string)␊ |
428 | ␉{␊ |
429 | ␉␉*field = 0;␊ |
430 | ␉␉return;␊ |
431 | ␉}␊ |
432 | ␊ |
433 | ␉strSize = strlen(string);␊ |
434 | ␊ |
435 | ␉// remove any spaces found at the end␊ |
436 | ␉while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
437 | ␉␉strSize--;␊ |
438 | ␊ |
439 | ␉if (strSize == 0)␊ |
440 | ␉{␊ |
441 | ␉␉*field = 0;␊ |
442 | ␉␉return;␊ |
443 | ␉}␊ |
444 | ␊ |
445 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
446 | ␉*field = stringIndex;␊ |
447 | ␊ |
448 | ␉stringIndex++;␊ |
449 | ␉stringsSize += strSize + 1;␊ |
450 | }␊ |
451 | ␊ |
452 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
453 | {␊ |
454 | ␉const char *string = 0;␊ |
455 | ␉int len;␊ |
456 | ␉bool parsed;␊ |
457 | ␉int val;␊ |
458 | ␊ |
459 | ␉if (numOfSetters <= idx)␊ |
460 | ␉␉return false;␊ |
461 | ␊ |
462 | ␉switch (SMBSetters[idx].valueType)␊ |
463 | ␉{␊ |
464 | ␉␉case kSMBString:␊ |
465 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
466 | ␉␉␉{␊ |
467 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
468 | ␉␉␉␉␉break;␊ |
469 | ␉␉␉␉else␊ |
470 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
471 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
472 | ␉␉␉␉␉␉␉break;␊ |
473 | ␉␉␉}␊ |
474 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
475 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
476 | ␉␉␉␉␉break;␊ |
477 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
478 | ␉␉␉{␊ |
479 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
480 | ␉␉␉␉break;␊ |
481 | ␉␉␉}␊ |
482 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
483 | ␉␉␉break;␊ |
484 | ␊ |
485 | ␉␉case kSMBByte:␊ |
486 | ␉␉case kSMBWord:␊ |
487 | ␉␉case kSMBDWord:␊ |
488 | ␉␉//case kSMBQWord:␊ |
489 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
490 | ␉␉␉{␊ |
491 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
492 | ␉␉␉␉if (!parsed)␊ |
493 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
494 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
495 | ␉␉␉␉if (parsed)␊ |
496 | ␉␉␉␉{␊ |
497 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
498 | ␉␉␉␉␉{␊ |
499 | ␉␉␉␉␉␉case kSMBByte:␊ |
500 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
501 | ␉␉␉␉␉␉␉break;␊ |
502 | ␉␉␉␉␉␉case kSMBWord:␊ |
503 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
504 | ␉␉␉␉␉␉␉break;␊ |
505 | ␉␉␉␉␉␉case kSMBDWord:␊ |
506 | ␉␉␉␉␉␉default:␊ |
507 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
508 | ␉␉␉␉␉␉␉break;␊ |
509 | ␉␉␉␉␉}␊ |
510 | ␉␉␉␉␉return true;␊ |
511 | ␉␉␉␉}␊ |
512 | ␉␉␉}␊ |
513 | ␊ |
514 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
515 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
516 | ␉␉␉␉␉return true;␊ |
517 | #if 0␊ |
518 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
519 | ␉␉␉{␊ |
520 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
521 | ␉␉␉␉return true;␊ |
522 | ␉␉␉}␊ |
523 | #endif␊ |
524 | ␉␉␉break;␊ |
525 | ␉}␊ |
526 | ␊ |
527 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
528 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
529 | ␊ |
530 | ␉return true;␊ |
531 | }␊ |
532 | ␊ |
533 | //-------------------------------------------------------------------------------------------------------------------------␊ |
534 | // Apple Specific␊ |
535 | //-------------------------------------------------------------------------------------------------------------------------␊ |
536 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
537 | {␊ |
538 | ␉return;␊ |
539 | }␊ |
540 | ␊ |
541 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
542 | {␊ |
543 | ␉/* SPD data from Platform.RAM.spd */␊ |
544 | ␉return;␊ |
545 | }␊ |
546 | ␊ |
547 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
548 | {␊ |
549 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
550 | ␊ |
551 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
552 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
553 | ␉p->header.handle␉= handle++;␊ |
554 | ␊ |
555 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
556 | ␊ |
557 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
558 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
559 | ␉structureCount++;␊ |
560 | }␊ |
561 | ␊ |
562 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
563 | {␊ |
564 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
565 | ␊ |
566 | ␉switch (Platform.CPU.Family) ␊ |
567 | ␉{␊ |
568 | ␉␉case 0x06:␊ |
569 | ␉␉{␊ |
570 | ␉␉␉switch (Platform.CPU.Model)␊ |
571 | ␉␉␉{␊ |
572 | ␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
573 | ␉␉␉␉case CPU_MODEL_DALES:␊ |
574 | ␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
575 | ␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
576 | ␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
577 | ␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
578 | ␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉// Intel Xeon E7␊ |
579 | ␉␉␉␉␉break;␊ |
580 | ␊ |
581 | ␉␉␉␉default:␊ |
582 | ␉␉␉␉␉return;␊ |
583 | ␉␉␉}␊ |
584 | ␉␉}␊ |
585 | ␉}␊ |
586 | ␊ |
587 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
588 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
589 | ␉p->header.handle␉= handle++;␊ |
590 | ␊ |
591 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
592 | ␊ |
593 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
594 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
595 | ␉structureCount++;␊ |
596 | }␊ |
597 | ␊ |
598 | //-------------------------------------------------------------------------------------------------------------------------␊ |
599 | // EndOfTable␊ |
600 | //-------------------------------------------------------------------------------------------------------------------------␊ |
601 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
602 | {␊ |
603 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
604 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
605 | ␉structPtr->new->handle␉= handle++;␊ |
606 | ␊ |
607 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
608 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
609 | ␉structureCount++;␊ |
610 | }␊ |
611 | ␊ |
612 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
613 | {␊ |
614 | ␉bool setterFound = false;␊ |
615 | ␊ |
616 | ␉uint8_t *ptr;␊ |
617 | ␉SMBWord structSize;␊ |
618 | ␉int i;␊ |
619 | ␊ |
620 | ␉stringIndex = 1;␊ |
621 | ␉stringsSize = 0;␊ |
622 | ␊ |
623 | ␉if (handle < structPtr->orig->handle)␊ |
624 | ␉␉handle = structPtr->orig->handle;␊ |
625 | ␊ |
626 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
627 | ␊ |
628 | ␉for (i = 0; i < numOfSetters; i++)␊ |
629 | ␉␉if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
630 | ␉␉{␊ |
631 | ␉␉␉setterFound = true;␊ |
632 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
633 | ␉␉}␊ |
634 | ␊ |
635 | ␉if (setterFound)␊ |
636 | ␉{␊ |
637 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
638 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
639 | ␊ |
640 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
641 | ␉␉␉ptr += 2;␊ |
642 | ␊ |
643 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
644 | ␉}␊ |
645 | ␉else␊ |
646 | ␉{␊ |
647 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
648 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
649 | ␊ |
650 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
651 | ␉␉␉ptr += 2;␊ |
652 | ␉␉␊ |
653 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
654 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
655 | ␉}␊ |
656 | ␊ |
657 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
658 | ␊ |
659 | ␉tableLength += structSize;␊ |
660 | ␊ |
661 | ␉if (structSize > maxStructSize)␊ |
662 | ␉␉maxStructSize = structSize;␊ |
663 | ␊ |
664 | ␉structureCount++;␊ |
665 | }␊ |
666 | ␊ |
667 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
668 | {␊ |
669 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
670 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
671 | ␊ |
672 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
673 | ␉{␊ |
674 | ␉␉switch (structPtr->orig->type)␊ |
675 | ␉␉{␊ |
676 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
677 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
678 | ␉␉␉case kSMBTypeMemorySPD:␊ |
679 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
680 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
681 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
682 | ␉␉␉case kSMBTypeEndOfTable:␊ |
683 | ␉␉␉␉break;␊ |
684 | ␊ |
685 | ␉␉␉default:␊ |
686 | ␉␉␉␉/* Add */␊ |
687 | ␉␉␉␉setSMBStruct(structPtr);␊ |
688 | ␉␉␉␉break;␊ |
689 | ␉␉}␊ |
690 | ␊ |
691 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
692 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
693 | ␊ |
694 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
695 | ␉␉␉ptr += 2;␊ |
696 | ␊ |
697 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
698 | ␉}␊ |
699 | ␊ |
700 | ␉addSMBFirmwareVolume(structPtr);␊ |
701 | ␉addSMBMemorySPD(structPtr);␊ |
702 | ␉addSMBOemProcessorType(structPtr);␊ |
703 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
704 | ␊ |
705 | ␉addSMBEndOfTable(structPtr);␊ |
706 | }␊ |
707 | ␊ |
708 | void setupSMBIOSTable(void)␊ |
709 | {␊ |
710 | ␉SMBStructPtrs *structPtr;␊ |
711 | ␉uint8_t *buffer;␊ |
712 | ␉bool setSMB = true;␊ |
713 | ␊ |
714 | ␉if (!origeps)␊ |
715 | ␉␉return;␊ |
716 | ␊ |
717 | ␉neweps = origeps;␊ |
718 | ␊ |
719 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
720 | ␉if (!structPtr)␊ |
721 | ␉␉return;␊ |
722 | ␉␊ |
723 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
724 | ␉if (!buffer)␊ |
725 | ␉␉return;␊ |
726 | ␊ |
727 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
728 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
729 | ␊ |
730 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);␊ |
731 | ␉if (setSMB)␊ |
732 | ␉␉setDefaultSMBData();␊ |
733 | ␊ |
734 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
735 | ␊ |
736 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
737 | ␉if (!neweps)␊ |
738 | ␉␉return;␊ |
739 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
740 | ␊ |
741 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
742 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
743 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
744 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
745 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
746 | ␉neweps->majorVersion␉␉= 2;␊ |
747 | ␉neweps->minorVersion␉␉= 4;␊ |
748 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
749 | ␉neweps->entryPointRevision␉= 0;␊ |
750 | ␊ |
751 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
752 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
753 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
754 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
755 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
756 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
757 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
758 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
759 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
760 | ␊ |
761 | ␉if (!neweps->dmi.tableAddress)␊ |
762 | ␉␉return;␊ |
763 | ␊ |
764 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
765 | ␊ |
766 | ␉neweps->dmi.checksum␉␉= 0;␊ |
767 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
768 | ␊ |
769 | ␉neweps->checksum␉␉␉= 0;␊ |
770 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
771 | ␊ |
772 | ␉free(buffer);␊ |
773 | ␉decodeSMBIOSTable(neweps);␊ |
774 | }␊ |
775 | ␊ |
776 | void *getSmbios(int which)␊ |
777 | {␊ |
778 | ␉switch (which)␊ |
779 | ␉{␊ |
780 | ␉␉case SMBIOS_ORIGINAL:␊ |
781 | ␉␉␉if (!origeps)␊ |
782 | ␉␉␉␉origeps = getAddressOfSmbiosTable();␊ |
783 | ␉␉␉return origeps;␊ |
784 | ␉␉case SMBIOS_PATCHED:␊ |
785 | ␉␉␉return neweps;␊ |
786 | ␉}␊ |
787 | ␊ |
788 | ␉return 0;␊ |
789 | }␊ |
790 | ␊ |
791 | /* Collect any information needed later */␊ |
792 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
793 | {␊ |
794 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
795 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
796 | ␊ |
797 | ␉int dimmnbr = 0;␊ |
798 | ␉Platform.DMI.MaxMemorySlots␉= 0;␊ |
799 | ␉Platform.DMI.CntMemorySlots␉= 0;␊ |
800 | ␉Platform.DMI.MemoryModules␉= 0;␊ |
801 | ␊ |
802 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
803 | ␉{␊ |
804 | ␉␉switch (structHeader->type)␊ |
805 | ␉␉{␊ |
806 | ␉␉␉case kSMBTypeSystemInformation:␊ |
807 | ␉␉␉␉Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
808 | ␉␉␉␉break;␊ |
809 | ␊ |
810 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
811 | ␉␉␉␉Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
812 | ␉␉␉␉break;␊ |
813 | ␊ |
814 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
815 | ␉␉␉␉Platform.DMI.CntMemorySlots++;␊ |
816 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
817 | ␉␉␉␉␉Platform.DMI.MemoryModules++;␊ |
818 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
819 | ␉␉␉␉␉Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
820 | ␉␉␉␉dimmnbr++;␊ |
821 | ␉␉␉␉break;␊ |
822 | ␉␉}␊ |
823 | ␊ |
824 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
825 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
826 | ␊ |
827 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
828 | ␉␉␉structPtr += 2;␊ |
829 | ␊ |
830 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
831 | ␉}␊ |
832 | }␊ |
833 | ␊ |
834 |