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␉␉"SMmanufacter" //*** was SMmanufacturer ␊ |
38 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
39 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
40 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
41 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
42 | ␊ |
43 | /* Base Board */␊ |
44 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacter" //***␊ |
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␉␉␉␉"SMmemmanufacter" //***␊ |
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␉␉␉␉␉␉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 LGA1156 (45nm)␊ |
344 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
345 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)␊ |
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:␊ |
354 | ␉␉␉␉␉␉␉case CPU_MODEL_SANDY_XEON:␊ |
355 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacSandyBIOSVersion;␊ |
356 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacSandy;␊ |
357 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
358 | ␉␉␉␉␉␉␉␉defaultBaseBoard.product␉␉= kDefaultiMacSandyBoardProduct; // ??␊ |
359 | ␉␉␉␉␉␉␉␉break;␊ |
360 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM: ␊ |
361 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␊ |
362 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
363 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
364 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
365 | ␉␉␉␉␉␉␉␉defaultBaseBoard.product␉␉= kDefaultMacProNehalemBoardProduct;␊ |
366 | ␉␉␉␉␉␉␉␉break;␊ |
367 | ␊ |
368 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE: ␊ |
369 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␊ |
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 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
456 | ␉*field = stringIndex;␊ |
457 | ␊ |
458 | ␉stringIndex++;␊ |
459 | ␉stringsSize += strSize + 1;␊ |
460 | }␊ |
461 | ␊ |
462 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
463 | {␊ |
464 | ␉const char *string = 0;␊ |
465 | ␉int len;␊ |
466 | ␊ |
467 | ␉if (numOfSetters <= idx)␊ |
468 | ␉␉return false;␊ |
469 | ␊ |
470 | ␉switch (SMBSetters[idx].valueType)␊ |
471 | ␉{␊ |
472 | ␉␉case kSMBString:␊ |
473 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
474 | ␉␉␉{␊ |
475 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
476 | ␉␉␉␉␉break;␊ |
477 | ␉␉␉␉else␊ |
478 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
479 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
480 | ␉␉␉␉␉␉␉break;␊ |
481 | ␉␉␉}␊ |
482 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
483 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
484 | ␉␉␉␉␉break;␊ |
485 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
486 | ␉␉␉{␊ |
487 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
488 | ␉␉␉␉break;␊ |
489 | ␉␉␉}␊ |
490 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
491 | ␉␉␉break;␊ |
492 | ␊ |
493 | ␉␉case kSMBByte:␊ |
494 | ␉␉case kSMBWord:␊ |
495 | ␉␉case kSMBDWord:␊ |
496 | ␉␉//case kSMBQWord:␊ |
497 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
498 | ␉␉␉{␊ |
499 | ␉␉␉␉if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))␊ |
500 | ␉␉␉␉␉return true;␊ |
501 | ␉␉␉␉else␊ |
502 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
503 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
504 | ␉␉␉␉␉␉␉return true;␊ |
505 | ␉␉␉}␊ |
506 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
507 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
508 | ␉␉␉␉␉return true;␊ |
509 | #if 0␊ |
510 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
511 | ␉␉␉{␊ |
512 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
513 | ␉␉␉␉return true;␊ |
514 | ␉␉␉}␊ |
515 | #endif␊ |
516 | ␉␉␉break;␊ |
517 | ␉}␊ |
518 | ␊ |
519 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
520 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
521 | ␊ |
522 | ␉return true;␊ |
523 | }␊ |
524 | ␊ |
525 | //-------------------------------------------------------------------------------------------------------------------------␊ |
526 | // Apple Specific␊ |
527 | //-------------------------------------------------------------------------------------------------------------------------␊ |
528 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
529 | {␊ |
530 | ␉return;␊ |
531 | }␊ |
532 | ␊ |
533 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
534 | {␊ |
535 | ␉/* SPD data from Platform.RAM.spd */␊ |
536 | ␉return;␊ |
537 | }␊ |
538 | ␊ |
539 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
540 | {␊ |
541 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
542 | ␊ |
543 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
544 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
545 | ␉p->header.handle␉= handle++;␊ |
546 | ␊ |
547 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
548 | ␊ |
549 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
550 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
551 | ␉structureCount++;␊ |
552 | }␊ |
553 | ␊ |
554 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
555 | {␊ |
556 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
557 | ␊ |
558 | ␉switch (Platform.CPU.Family) ␊ |
559 | ␉{␊ |
560 | ␉␉case 0x06:␊ |
561 | ␉␉{␊ |
562 | ␉␉␉switch (Platform.CPU.Model)␊ |
563 | ␉␉␉{␊ |
564 | ␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz␊ |
565 | ␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
566 | ␉␉␉␉case CPU_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
567 | ␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
568 | ␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7 LGA1366 (45nm)␊ |
569 | ␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
570 | ␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7 LGA1366 (32nm) 6 Core␊ |
571 | ␉␉␉␉case CPU_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
572 | ␉␉␉␉␉break;␊ |
573 | ␉␉␉␉␉default:␊ |
574 | ␉␉␉␉␉return;␊ |
575 | ␉␉␉}␊ |
576 | ␉␉}␊ |
577 | ␉}␊ |
578 | ␊ |
579 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
580 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
581 | ␉p->header.handle␉= handle++;␊ |
582 | ␊ |
583 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
584 | ␊ |
585 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
586 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
587 | ␉structureCount++;␊ |
588 | }␊ |
589 | ␊ |
590 | //-------------------------------------------------------------------------------------------------------------------------␊ |
591 | // EndOfTable␊ |
592 | //-------------------------------------------------------------------------------------------------------------------------␊ |
593 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
594 | {␊ |
595 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
596 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
597 | ␉structPtr->new->handle␉= handle++;␊ |
598 | ␊ |
599 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
600 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
601 | ␉structureCount++;␊ |
602 | }␊ |
603 | ␊ |
604 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
605 | {␊ |
606 | ␉bool setterFound = false;␊ |
607 | ␊ |
608 | ␉uint8_t *ptr;␊ |
609 | ␉SMBWord structSize;␊ |
610 | ␉int i;␊ |
611 | ␊ |
612 | ␉stringIndex = 1;␊ |
613 | ␉stringsSize = 0;␊ |
614 | ␊ |
615 | ␉if (handle < structPtr->orig->handle)␊ |
616 | ␉␉handle = structPtr->orig->handle;␊ |
617 | ␊ |
618 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
619 | ␊ |
620 | ␉for (i = 0; i < numOfSetters; i++)␊ |
621 | ␉␉if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
622 | ␉␉{␊ |
623 | ␉␉␉setterFound = true;␊ |
624 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
625 | ␉␉}␊ |
626 | ␊ |
627 | ␉if (setterFound)␊ |
628 | ␉{␊ |
629 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
630 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
631 | ␊ |
632 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
633 | ␉␉␉ptr += 2;␊ |
634 | ␊ |
635 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
636 | ␉}␊ |
637 | ␉else␊ |
638 | ␉{␊ |
639 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
640 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
641 | ␊ |
642 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
643 | ␉␉␉ptr += 2;␊ |
644 | ␉␉␊ |
645 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
646 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
647 | ␉}␊ |
648 | ␊ |
649 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
650 | ␊ |
651 | ␉tableLength += structSize;␊ |
652 | ␊ |
653 | ␉if (structSize > maxStructSize)␊ |
654 | ␉␉maxStructSize = structSize;␊ |
655 | ␊ |
656 | ␉structureCount++;␊ |
657 | }␊ |
658 | ␊ |
659 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
660 | {␊ |
661 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
662 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
663 | ␊ |
664 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
665 | ␉{␊ |
666 | ␉␉switch (structPtr->orig->type)␊ |
667 | ␉␉{␊ |
668 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
669 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
670 | ␉␉␉case kSMBTypeMemorySPD:␊ |
671 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
672 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
673 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
674 | ␉␉␉case kSMBTypeEndOfTable:␊ |
675 | ␉␉␉␉break;␊ |
676 | ␊ |
677 | ␉␉␉default:␊ |
678 | ␉␉␉␉/* Add */␊ |
679 | ␉␉␉␉setSMBStruct(structPtr);␊ |
680 | ␉␉␉␉break;␊ |
681 | ␉␉}␊ |
682 | ␊ |
683 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
684 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
685 | ␊ |
686 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
687 | ␉␉␉ptr += 2;␊ |
688 | ␊ |
689 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
690 | ␉}␊ |
691 | ␊ |
692 | ␉addSMBFirmwareVolume(structPtr);␊ |
693 | ␉addSMBMemorySPD(structPtr);␊ |
694 | ␉addSMBOemProcessorType(structPtr);␊ |
695 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
696 | ␊ |
697 | ␉addSMBEndOfTable(structPtr);␊ |
698 | }␊ |
699 | ␊ |
700 | void setupSMBIOSTable(void)␊ |
701 | {␊ |
702 | ␉SMBStructPtrs *structPtr;␊ |
703 | ␉uint8_t *buffer;␊ |
704 | ␉bool setSMB = true;␊ |
705 | ␊ |
706 | ␉if (!origeps)␊ |
707 | ␉␉return;␊ |
708 | ␊ |
709 | ␉neweps = origeps;␊ |
710 | ␊ |
711 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
712 | ␉if (!structPtr)␊ |
713 | ␉␉return;␊ |
714 | ␉␊ |
715 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
716 | ␉if (!buffer)␊ |
717 | ␉␉return;␊ |
718 | ␊ |
719 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
720 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
721 | ␊ |
722 | ␉getBoolForKey(kSMBIOSdefaultsKey, &setSMB, &bootInfo->bootConfig);␊ |
723 | ␉if (setSMB)␊ |
724 | ␉␉setDefaultSMBData();␊ |
725 | ␊ |
726 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
727 | ␊ |
728 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
729 | ␉if (!neweps)␊ |
730 | ␉␉return;␊ |
731 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
732 | ␊ |
733 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
734 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
735 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
736 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
737 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
738 | ␉neweps->majorVersion␉␉= 2;␊ |
739 | ␉neweps->minorVersion␉␉= 4;␊ |
740 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
741 | ␉neweps->entryPointRevision␉= 0;␊ |
742 | ␊ |
743 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
744 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
745 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
746 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
747 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
748 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
749 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
750 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
751 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
752 | ␊ |
753 | ␉if (!neweps->dmi.tableAddress)␊ |
754 | ␉␉return;␊ |
755 | ␊ |
756 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
757 | ␊ |
758 | ␉neweps->dmi.checksum␉␉= 0;␊ |
759 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
760 | ␊ |
761 | ␉neweps->checksum␉␉␉= 0;␊ |
762 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
763 | ␊ |
764 | ␉free(buffer);␊ |
765 | ␉decodeSMBIOSTable(neweps);␊ |
766 | }␊ |
767 | ␊ |
768 | void *getSmbios(int which)␊ |
769 | {␊ |
770 | ␉switch (which)␊ |
771 | ␉{␊ |
772 | ␉␉case SMBIOS_ORIGINAL:␊ |
773 | ␉␉␉if (!origeps)␊ |
774 | ␉␉␉␉origeps = getAddressOfSmbiosTable();␊ |
775 | ␉␉␉return origeps;␊ |
776 | ␉␉case SMBIOS_PATCHED:␊ |
777 | ␉␉␉return neweps;␊ |
778 | ␉}␊ |
779 | ␊ |
780 | ␉return 0;␊ |
781 | }␊ |
782 | ␊ |
783 | /* Collect any information needed later */␊ |
784 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
785 | {␊ |
786 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
787 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
788 | ␊ |
789 | ␉int dimmnbr = 0;␊ |
790 | ␉Platform.DMI.MaxMemorySlots␉= 0;␊ |
791 | ␉Platform.DMI.CntMemorySlots␉= 0;␊ |
792 | ␉Platform.DMI.MemoryModules␉= 0;␊ |
793 | ␊ |
794 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
795 | ␉{␊ |
796 | ␉␉switch (structHeader->type)␊ |
797 | ␉␉{␊ |
798 | ␉␉␉case kSMBTypeSystemInformation:␊ |
799 | ␉␉␉␉Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
800 | ␉␉␉␉break;␊ |
801 | ␊ |
802 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
803 | ␉␉␉␉Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
804 | ␉␉␉␉break;␊ |
805 | ␊ |
806 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
807 | ␉␉␉␉Platform.DMI.CntMemorySlots++;␊ |
808 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
809 | ␉␉␉␉␉Platform.DMI.MemoryModules++;␊ |
810 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
811 | ␉␉␉␉␉Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
812 | ␉␉␉␉dimmnbr++;␊ |
813 | ␉␉␉␉break;␊ |
814 | ␉␉}␊ |
815 | ␊ |
816 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
817 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
818 | ␊ |
819 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
820 | ␉␉␉structPtr += 2;␊ |
821 | ␊ |
822 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
823 | ␉}␊ |
824 | }␊ |
825 | ␊ |
826 | |