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