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