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