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...)␉verbose(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␊ |
21 | #endif␊ |
22 | ␊ |
23 | #define SMBPlist␉␉␉&bootInfo->smbiosConfig␊ |
24 | /* ASSUMPTION: 16KB should be enough for the whole thing */␊ |
25 | #define SMB_ALLOC_SIZE␉16384␊ |
26 | ␊ |
27 | ␊ |
28 | //-------------------------------------------------------------------------------------------------------------------------␊ |
29 | // SMBIOS Plist Keys␊ |
30 | //-------------------------------------------------------------------------------------------------------------------------␊ |
31 | /* BIOS Information */␊ |
32 | #define kSMBBIOSInformationVendorKey␉␉␉␉"SMbiosvendor"␊ |
33 | #define kSMBBIOSInformationVersionKey␉␉␉␉"SMbiosversion"␊ |
34 | #define kSMBBIOSInformationReleaseDateKey␉␉␉"SMbiosdate"␊ |
35 | ␊ |
36 | /* System Information */␊ |
37 | #define kSMBSystemInformationManufacturerKey␉␉"SMmanufacturer"␊ |
38 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
39 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
40 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
41 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
42 | ␊ |
43 | /* Base Board */␊ |
44 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacturer"␊ |
45 | #define kSMBBaseBoardProductKey␉␉␉␉␉␉"SMboardproduct"␊ |
46 | ␊ |
47 | /* Processor Information */␊ |
48 | #define kSMBProcessorInformationExternalClockKey␉"SMexternalclock"␊ |
49 | #define kSMBProcessorInformationMaximumClockKey␉␉"SMmaximalclock"␊ |
50 | ␊ |
51 | /* Memory Device */␊ |
52 | #define kSMBMemoryDeviceDeviceLocatorKey␉␉␉"SMmemdevloc"␊ |
53 | #define kSMBMemoryDeviceBankLocatorKey␉␉␉␉"SMmembankloc"␊ |
54 | #define kSMBMemoryDeviceMemoryTypeKey␉␉␉␉"SMmemtype"␊ |
55 | #define kSMBMemoryDeviceMemorySpeedKey␉␉␉␉"SMmemspeed"␊ |
56 | #define kSMBMemoryDeviceManufacturerKey␉␉␉␉"SMmemmanufacturer"␊ |
57 | #define kSMBMemoryDeviceSerialNumberKey␉␉␉␉"SMmemserial"␊ |
58 | #define kSMBMemoryDevicePartNumberKey␉␉␉␉"SMmempart"␊ |
59 | ␊ |
60 | /* Apple Specific */␊ |
61 | #define kSMBOemProcessorTypeKey␉␉␉␉␉␉"SMcputype"␊ |
62 | #define kSMBOemProcessorBusSpeedKey␉␉␉␉␉"SMbusspeed"␊ |
63 | ␊ |
64 | //-------------------------------------------------------------------------------------------------------------------------␊ |
65 | // Default SMBIOS Data␊ |
66 | //-------------------------------------------------------------------------------------------------------------------------␊ |
67 | /* Rewrite: use a struct */␊ |
68 | ␊ |
69 | #define kDefaultVendorManufacturer␉␉␉␉␉"Apple Inc."␊ |
70 | #define kDefaultBIOSReleaseDate␉␉␉␉␉␉"11/06/2009"␊ |
71 | #define kDefaultSerialNumber␉␉␉␉␉␉"SOMESRLNMBR"␊ |
72 | #define kDefaultBoardProduct␉␉␉␉␉␉"Mac-F4208DC8"␊ |
73 | #define kDefaultSystemVersion␉␉␉␉␉␉"1.0"␊ |
74 | ␊ |
75 | // defaults for a Mac mini ␊ |
76 | #define kDefaultMacminiFamily␉␉␉␉␉␉"Macmini"␊ |
77 | #define kDefaultMacmini␉␉␉␉␉␉␉␉"Macmini1,1"␊ |
78 | #define kDefaultMacminiBIOSVersion␉␉␉␉␉" MM11.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.0809221748"␊ |
84 | ␊ |
85 | // defaults for a MacBook Pro␊ |
86 | #define kDefaultMacBookProFamily␉␉␉␉␉"MacBookPro"␊ |
87 | #define kDefaultMacBookPro␉␉␉␉␉␉␉"MacBookPro5,1"␊ |
88 | #define kDefaultMacBookProBIOSVersion␉␉␉␉" MBP51.88Z.007E.B05.0906151647"␊ |
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.0802091538"␊ |
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 | #define MAX_DMI_TABLES 255␊ |
114 | typedef struct DmiNumAssocTag {␊ |
115 | SMBStructHeader* dmi;␊ |
116 | uint8_t type;␊ |
117 | } DmiNumAssoc;␊ |
118 | ␊ |
119 | static DmiNumAssoc DmiTablePair[MAX_DMI_TABLES];␊ |
120 | static int DmiTablePairCount = 0;␊ |
121 | static int current_pos=0;␊ |
122 | static bool ftTablePairInit = true; //use twice first run and after␊ |
123 | ␊ |
124 | #define getFieldOffset(struct, field)␉((uint8_t)(uint32_t)&(((struct *)0)->field))␊ |
125 | ␊ |
126 | /** ␊ |
127 | * Get a table structure entry from a type specification and a smbios address␊ |
128 | * return NULL if table is not found␊ |
129 | */␊ |
130 | void getSmbiosTableStructure(struct SMBEntryPoint *smbios)␊ |
131 | {␊ |
132 | SMBStructHeader* dmihdr=NULL;␊ |
133 | SMBByte* p;␊ |
134 | int i;␊ |
135 | ␉␊ |
136 | if (ftTablePairInit && smbios!=NULL) {␊ |
137 | ftTablePairInit = false;␊ |
138 | #if DEBUG_SMBIOS␊ |
139 | verbose(">>> SMBIOSAddr=0x%08x\n", smbios);␊ |
140 | verbose(">>> DMI: addr=0x%08x, len=%d, count=%d\n", smbios->dmi.tableAddress, ␊ |
141 | ␉␉␉␉smbios->dmi.tableLength, smbios->dmi.structureCount);␊ |
142 | #endif␊ |
143 | p = (SMBByte *) smbios->dmi.tableAddress;␊ |
144 | for (i=0; ␊ |
145 | i < smbios->dmi.structureCount && ␊ |
146 | p + 4 <= (SMBByte *)smbios->dmi.tableAddress + smbios->dmi.tableLength; ␊ |
147 | i++) {␊ |
148 | dmihdr = (SMBStructHeader *) p;␊ |
149 | ␉␉␉␊ |
150 | #if DEBUG_SMBIOS␊ |
151 | // verbose(">>>>>> DMI(%d): type=0x%02x, len=0x%d\n",i,dmihdr->type,dmihdr->length);␊ |
152 | #endif␊ |
153 | if (dmihdr->length < 4 || dmihdr->type == 127 /* EOT */) break;␊ |
154 | if (DmiTablePairCount < MAX_DMI_TABLES) {␊ |
155 | DmiTablePair[DmiTablePairCount].dmi = dmihdr;␊ |
156 | DmiTablePair[DmiTablePairCount].type = dmihdr->type;␊ |
157 | DmiTablePairCount++;␊ |
158 | }␊ |
159 | else {␊ |
160 | verbose("DMI table entries list is full! Next entries won't be stored.\n");␊ |
161 | }␊ |
162 | #if DEBUG_SMBIOS␊ |
163 | verbose("DMI header found for table type %d, length = %d\n", dmihdr->type, dmihdr->length);␊ |
164 | #endif␊ |
165 | p = p + dmihdr->length;␊ |
166 | while ((p - (SMBByte *)smbios->dmi.tableAddress + 1 < smbios->dmi.tableLength) && (p[0] != 0x00 || p[1] != 0x00)) {␊ |
167 | p++;␊ |
168 | ␉␉␉}␊ |
169 | p += 2;␊ |
170 | ␉␉}␊ |
171 | ␊ |
172 | }␊ |
173 | }␊ |
174 | ␊ |
175 | typedef struct {␊ |
176 | ␉SMBStructHeader *orig;␊ |
177 | ␉SMBStructHeader *new;␊ |
178 | } SMBStructPtrs;␊ |
179 | ␊ |
180 | struct {␊ |
181 | ␉char *vendor;␊ |
182 | ␉char *version;␊ |
183 | ␉char *releaseDate;␊ |
184 | } defaultBIOSInfo;␊ |
185 | ␊ |
186 | struct {␊ |
187 | ␉char *manufacturer;␊ |
188 | ␉char *productName;␊ |
189 | ␉char *version;␊ |
190 | ␉char *serialNumber;␊ |
191 | ␉char *family;␊ |
192 | } defaultSystemInfo;␊ |
193 | ␊ |
194 | struct {␊ |
195 | ␉char *manufacturer;␊ |
196 | ␉char *product;␊ |
197 | } defaultBaseBoard;␊ |
198 | ␊ |
199 | ␊ |
200 | typedef struct {␊ |
201 | ␉uint8_t␉␉␉type;␊ |
202 | ␉SMBValueType␉valueType;␊ |
203 | ␉uint8_t␉␉␉fieldOffset;␊ |
204 | ␉char␉␉␉*keyString;␊ |
205 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
206 | ␉char␉␉␉**defaultValue;␊ |
207 | } SMBValueSetter;␊ |
208 | ␊ |
209 | SMBValueSetter SMBSetters[] = ␊ |
210 | {␊ |
211 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
212 | ␉// BIOSInformation␊ |
213 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
214 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
215 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
216 | ␊ |
217 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
218 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
219 | ␊ |
220 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
221 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
222 | ␊ |
223 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
224 | ␉// SystemInformation␊ |
225 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
226 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
227 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
228 | ␊ |
229 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
230 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
231 | ␊ |
232 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
233 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
234 | ␊ |
235 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
236 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
237 | ␊ |
238 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
239 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
240 | ␊ |
241 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
242 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
243 | ␊ |
244 | ␊ |
245 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
246 | ␉// BaseBoard␊ |
247 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
248 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
249 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
250 | ␊ |
251 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
252 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
253 | ␊ |
254 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
255 | ␊ |
256 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
257 | ␊ |
258 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
259 | ␊ |
260 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
261 | ␊ |
262 | ␊ |
263 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
264 | ␉// ProcessorInformation␊ |
265 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
266 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
267 | ␊ |
268 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
269 | ␊ |
270 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
271 | ␊ |
272 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
273 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
274 | ␊ |
275 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
276 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
277 | ␊ |
278 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
279 | ␊ |
280 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
281 | ␊ |
282 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
283 | ␊ |
284 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
285 | ␉// Memory Device␊ |
286 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
287 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
288 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
289 | ␊ |
290 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
291 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
292 | ␊ |
293 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
294 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
295 | ␊ |
296 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
297 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
298 | ␊ |
299 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
300 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
301 | ␊ |
302 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
303 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
304 | ␊ |
305 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
306 | ␊ |
307 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
308 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
309 | ␊ |
310 | ␊ |
311 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
312 | ␉// Apple Specific␊ |
313 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
314 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
315 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
316 | ␊ |
317 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
318 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
319 | };␊ |
320 | ␊ |
321 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
322 | ␊ |
323 | ␊ |
324 | SMBEntryPoint *origeps␉= 0;␊ |
325 | SMBEntryPoint *neweps␉= 0;␊ |
326 | ␊ |
327 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
328 | static uint8_t stringsSize;␉// add string size␊ |
329 | ␊ |
330 | static SMBWord tableLength␉␉= 0;␊ |
331 | static SMBWord handle␉␉␉= 0;␊ |
332 | static SMBWord maxStructSize␉= 0;␊ |
333 | static SMBWord structureCount␉= 0;␊ |
334 | ␊ |
335 | /* Rewrite this function */␊ |
336 | void setDefaultSMBData(void)␊ |
337 | {␊ |
338 | ␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
339 | ␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
340 | ␊ |
341 | ␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
342 | ␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
343 | ␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
344 | ␊ |
345 | ␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
346 | ␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
347 | ␊ |
348 | ␉if (Platform->Type == 2)␉␉//platformCPUFeature(CPU_FEATURE_MOBILE))␊ |
349 | ␉{␊ |
350 | ␉␉if (vgaVendor != PCI_VENDOR_ID_INTEL) //Slice␊ |
351 | ␉␉{␊ |
352 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookProBIOSVersion;␊ |
353 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBookPro;␊ |
354 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookProFamily;␊ |
355 | ␉␉}␊ |
356 | ␉␉else␊ |
357 | ␉␉{␊ |
358 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookBIOSVersion;␊ |
359 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBook;␊ |
360 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookFamily;␊ |
361 | ␉␉}␊ |
362 | ␉}␊ |
363 | ␉else␊ |
364 | ␉{␊ |
365 | ␉␉switch (Platform->CPU.NoCores) ␊ |
366 | ␉␉{␊ |
367 | ␉␉␉case 1: ␊ |
368 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacminiBIOSVersion;␊ |
369 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacmini;␊ |
370 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacminiFamily;␊ |
371 | ␉␉␉␉break;␊ |
372 | ␊ |
373 | ␉␉␉case 2:␊ |
374 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacBIOSVersion;␊ |
375 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMac;␊ |
376 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
377 | ␉␉␉␉break;␊ |
378 | ␉␉␉default:␊ |
379 | ␉␉␉{␊ |
380 | ␉␉␉␉switch (Platform->CPU.Family) ␊ |
381 | ␉␉␉␉{␊ |
382 | ␉␉␉␉␉case 0x06:␊ |
383 | ␉␉␉␉␉{␊ |
384 | ␉␉␉␉␉␉switch (Platform->CPU.Model)␊ |
385 | ␉␉␉␉␉␉{␊ |
386 | ␉␉␉␉␉␉␉case CPU_MODEL_FIELDS:␉␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
387 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES:␊ |
388 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
389 | ␉␉␉␉␉␉␉case 0x19:␉␉␉␉␉␉// ??? Intel Core i5 650 @3.20 GHz ␊ |
390 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacNehalemBIOSVersion;␊ |
391 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacNehalem;␊ |
392 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
393 | ␉␉␉␉␉␉␉␉break;␊ |
394 | ␊ |
395 | ␉␉␉␉␉␉␉case CPU_MODEL_SANDY:␉␉␉// Intel Core i3, i5, i7 LGA1155 (32nm)␊ |
396 | ␉␉␉␉␉␉␉case CPU_MODEL_SANDY_XEON:␉␉// Intel Xeon E3␊ |
397 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacSandyBIOSVersion;␊ |
398 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacSandy;␊ |
399 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
400 | ␉␉␉␉␉␉␉␉break;␊ |
401 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM:␉␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
402 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
403 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
404 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
405 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
406 | ␉␉␉␉␉␉␉␉break;␊ |
407 | ␊ |
408 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE:␉␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
409 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉␉// Intel Xeon E7␊ |
410 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProWestmereBIOSVersion;␊ |
411 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulMacProWestmereBIOSReleaseDate;␊ |
412 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProWestmere;␊ |
413 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
414 | ␉␉␉␉␉␉␉␉break;␊ |
415 | ␊ |
416 | ␉␉␉␉␉␉␉default:␊ |
417 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
418 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
419 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
420 | ␉␉␉␉␉␉␉␉break;␊ |
421 | ␉␉␉␉␉␉}␊ |
422 | ␉␉␉␉␉␉break;␊ |
423 | ␉␉␉␉␉}␊ |
424 | ␉␉␉␉␉default:␊ |
425 | ␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
426 | ␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
427 | ␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
428 | ␉␉␉␉␉␉break;␊ |
429 | ␉␉␉␉}␊ |
430 | ␉␉␉␉break;␊ |
431 | ␉␉␉}␊ |
432 | ␉␉}␊ |
433 | ␉}␊ |
434 | }␊ |
435 | ␊ |
436 | /* Used for SM*n smbios.plist keys */␊ |
437 | bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
438 | {␊ |
439 | ␉static int idx = -1;␊ |
440 | ␉static int current = -1;␊ |
441 | ␉int len;␊ |
442 | ␉char key[24];␊ |
443 | ␊ |
444 | ␉if (current != structHeader->handle)␊ |
445 | ␉{␊ |
446 | ␉␉idx++;␊ |
447 | ␉␉current = structHeader->handle;␊ |
448 | ␉}␊ |
449 | ␊ |
450 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
451 | ␊ |
452 | ␉if (value)␊ |
453 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
454 | ␉␉␉return true;␊ |
455 | ␉else␊ |
456 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
457 | ␉␉␉return true;␊ |
458 | ␉return false;␊ |
459 | }␊ |
460 | ␊ |
461 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
462 | {␊ |
463 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
464 | ␊ |
465 | ␉if (!field)␊ |
466 | ␉␉return NULL;␊ |
467 | ␊ |
468 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
469 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
470 | ␊ |
471 | ␉return (char *)stringPtr;␊ |
472 | }␊ |
473 | ␊ |
474 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
475 | {␊ |
476 | ␉int strSize;␊ |
477 | ␊ |
478 | ␉if (!field)␊ |
479 | ␉␉return;␊ |
480 | ␉if (!string)␊ |
481 | ␉{␊ |
482 | ␉␉*field = 0;␊ |
483 | ␉␉return;␊ |
484 | ␉}␊ |
485 | ␊ |
486 | ␉strSize = strlen(string);␊ |
487 | ␊ |
488 | ␉// remove any spaces found at the end␊ |
489 | ␉while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
490 | ␉␉strSize--;␊ |
491 | ␊ |
492 | ␉if (strSize == 0)␊ |
493 | ␉{␊ |
494 | ␉␉*field = 0;␊ |
495 | ␉␉return;␊ |
496 | ␉}␊ |
497 | ␊ |
498 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
499 | ␉*field = stringIndex;␊ |
500 | ␊ |
501 | ␉stringIndex++;␊ |
502 | ␉stringsSize += strSize + 1;␊ |
503 | }␊ |
504 | ␊ |
505 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
506 | {␊ |
507 | ␉const char *string = 0;␊ |
508 | ␉int len;␊ |
509 | ␉bool parsed;␊ |
510 | ␉int val;␊ |
511 | ␊ |
512 | ␉if (numOfSetters <= idx)␊ |
513 | ␉␉return false;␊ |
514 | ␊ |
515 | ␉switch (SMBSetters[idx].valueType)␊ |
516 | ␉{␊ |
517 | ␉␉case kSMBString:␊ |
518 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
519 | ␉␉␉{␊ |
520 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
521 | ␉␉␉␉␉break;␊ |
522 | ␉␉␉␉else␊ |
523 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
524 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
525 | ␉␉␉␉␉␉␉break;␊ |
526 | ␉␉␉}␊ |
527 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
528 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
529 | ␉␉␉␉␉break;␊ |
530 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
531 | ␉␉␉{␊ |
532 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
533 | ␉␉␉␉break;␊ |
534 | ␉␉␉}␊ |
535 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
536 | ␉␉␉break;␊ |
537 | ␊ |
538 | ␉␉case kSMBByte:␊ |
539 | ␉␉case kSMBWord:␊ |
540 | ␉␉case kSMBDWord:␊ |
541 | ␉␉//case kSMBQWord:␊ |
542 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
543 | ␉␉␉{␊ |
544 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
545 | ␉␉␉␉if (!parsed)␊ |
546 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
547 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
548 | ␉␉␉␉if (parsed)␊ |
549 | ␉␉␉␉{␊ |
550 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
551 | ␉␉␉␉␉{␊ |
552 | ␉␉␉␉␉␉case kSMBByte:␊ |
553 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
554 | ␉␉␉␉␉␉␉break;␊ |
555 | ␉␉␉␉␉␉case kSMBWord:␊ |
556 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
557 | ␉␉␉␉␉␉␉break;␊ |
558 | ␉␉␉␉␉␉case kSMBDWord:␊ |
559 | ␉␉␉␉␉␉default:␊ |
560 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
561 | ␉␉␉␉␉␉␉break;␊ |
562 | ␉␉␉␉␉}␊ |
563 | ␉␉␉␉␉return true;␊ |
564 | ␉␉␉␉}␊ |
565 | ␉␉␉}␊ |
566 | ␊ |
567 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
568 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
569 | ␉␉␉␉␉return true;␊ |
570 | #if 0␊ |
571 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
572 | ␉␉␉{␊ |
573 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
574 | ␉␉␉␉return true;␊ |
575 | ␉␉␉}␊ |
576 | #endif␊ |
577 | ␉␉␉break;␊ |
578 | ␉}␊ |
579 | ␊ |
580 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
581 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
582 | ␊ |
583 | ␉return true;␊ |
584 | }␊ |
585 | ␊ |
586 | //-------------------------------------------------------------------------------------------------------------------------␊ |
587 | // Apple Specific␊ |
588 | //-------------------------------------------------------------------------------------------------------------------------␊ |
589 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
590 | {␊ |
591 | ␉return;␊ |
592 | }␊ |
593 | ␊ |
594 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
595 | {␊ |
596 | ␉/* SPD data from Platform->RAM.spd */␊ |
597 | ␉return;␊ |
598 | }␊ |
599 | ␊ |
600 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
601 | {␊ |
602 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
603 | ␊ |
604 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
605 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
606 | ␉p->header.handle␉= handle++;␊ |
607 | ␊ |
608 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
609 | ␊ |
610 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
611 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
612 | ␉structureCount++;␊ |
613 | }␊ |
614 | ␊ |
615 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
616 | {␊ |
617 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
618 | ␉SMBWord tmp = 0;␊ |
619 | ␉switch (Platform->CPU.Family) ␊ |
620 | ␉{␊ |
621 | ␉␉case 0x06:␊ |
622 | ␉␉{␊ |
623 | ␉␉␉switch (Platform->CPU.Model)␊ |
624 | ␉␉␉{␊ |
625 | ␉␉␉␉case 0x19:␉␉␉␉␉// ??? Intel Core i5 650 @3.20 GHz␊ |
626 | ␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
627 | ␉␉␉␉case CPU_MODEL_DALES:␊ |
628 | ␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
629 | ␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
630 | ␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
631 | ␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
632 | ␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉// Intel Xeon E7␊ |
633 | ␉␉␉␉case CPU_MODEL_SANDY:␊ |
634 | ␉␉␉␉case CPU_MODEL_SANDY_XEON:␊ |
635 | ␉␉␉␉␉tmp = p->ProcessorBusSpeed;␊ |
636 | ␉␉␉␉␉break;␊ |
637 | ␊ |
638 | ␉␉␉␉default:␊ |
639 | ␉␉␉␉␉tmp = (Platform->CPU.FSBFrequency * 4) / MEGA;␊ |
640 | ␉␉␉␉␉break;␊ |
641 | ␉␉␉␉␉//return;␊ |
642 | ␉␉␉}␊ |
643 | ␉␉}␊ |
644 | ␉}␊ |
645 | ␊ |
646 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
647 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
648 | ␉p->header.handle␉= handle++;␊ |
649 | ␊ |
650 | ␉if(!setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed)))␊ |
651 | ␉␉p->ProcessorBusSpeed = tmp;␊ |
652 | ␊ |
653 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
654 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
655 | ␉structureCount++;␊ |
656 | }␊ |
657 | ␊ |
658 | //-------------------------------------------------------------------------------------------------------------------------␊ |
659 | // EndOfTable␊ |
660 | //-------------------------------------------------------------------------------------------------------------------------␊ |
661 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
662 | {␊ |
663 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
664 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
665 | ␉structPtr->new->handle␉= handle++;␊ |
666 | ␊ |
667 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
668 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
669 | ␉structureCount++;␊ |
670 | }␊ |
671 | ␊ |
672 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
673 | {␊ |
674 | ␉bool setterFound = false;␊ |
675 | ␊ |
676 | ␉uint8_t *ptr;␊ |
677 | ␉SMBWord structSize;␊ |
678 | ␉int i;␊ |
679 | ␊ |
680 | ␉stringIndex = 1;␊ |
681 | ␉stringsSize = 0;␊ |
682 | ␊ |
683 | ␉if (handle < structPtr->orig->handle)␊ |
684 | ␉␉handle = structPtr->orig->handle;␊ |
685 | ␊ |
686 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
687 | ␊ |
688 | ␉for (i = 0; i < numOfSetters; i++)␊ |
689 | ␉␉if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
690 | ␉␉{␊ |
691 | ␉␉␉setterFound = true;␊ |
692 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
693 | ␉␉}␊ |
694 | ␊ |
695 | ␉if (setterFound)␊ |
696 | ␉{␊ |
697 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
698 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
699 | ␊ |
700 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
701 | ␉␉␉ptr += 2;␊ |
702 | ␊ |
703 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
704 | ␉}␊ |
705 | ␉else␊ |
706 | ␉{␊ |
707 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
708 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
709 | ␊ |
710 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
711 | ␉␉␉ptr += 2;␊ |
712 | ␉␉␊ |
713 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
714 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
715 | ␉}␊ |
716 | ␊ |
717 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
718 | ␊ |
719 | ␉tableLength += structSize;␊ |
720 | ␊ |
721 | ␉if (structSize > maxStructSize)␊ |
722 | ␉␉maxStructSize = structSize;␊ |
723 | ␊ |
724 | ␉structureCount++;␊ |
725 | }␊ |
726 | ␊ |
727 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
728 | {␊ |
729 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
730 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
731 | ␊ |
732 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
733 | ␉{␊ |
734 | ␉␉switch (structPtr->orig->type)␊ |
735 | ␉␉{␊ |
736 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
737 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
738 | ␉␉␉case kSMBTypeMemorySPD:␊ |
739 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
740 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
741 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
742 | ␉␉␉case kSMBTypeEndOfTable:␊ |
743 | ␉␉␉␉break;␊ |
744 | ␊ |
745 | ␉␉␉default:␊ |
746 | ␉␉␉␉/* Add */␊ |
747 | ␉␉␉␉setSMBStruct(structPtr);␊ |
748 | ␉␉␉␉break;␊ |
749 | ␉␉}␊ |
750 | ␊ |
751 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
752 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
753 | ␊ |
754 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
755 | ␉␉␉ptr += 2;␊ |
756 | ␊ |
757 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
758 | ␉}␊ |
759 | ␊ |
760 | ␉addSMBFirmwareVolume(structPtr);␊ |
761 | ␉addSMBMemorySPD(structPtr);␊ |
762 | ␉addSMBOemProcessorType(structPtr);␊ |
763 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
764 | ␊ |
765 | ␉addSMBEndOfTable(structPtr);␊ |
766 | }␊ |
767 | ␊ |
768 | void setupSMBIOSTable(void)␊ |
769 | {␊ |
770 | ␉SMBStructPtrs *structPtr;␊ |
771 | ␉uint8_t *buffer;␊ |
772 | ␉bool setSMB = true;␊ |
773 | ␊ |
774 | ␉if (!origeps)␊ |
775 | ␉␉return;␊ |
776 | ␊ |
777 | ␉neweps = origeps;␊ |
778 | ␊ |
779 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
780 | ␉if (!structPtr)␊ |
781 | ␉␉return;␊ |
782 | ␉␊ |
783 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
784 | ␉if (!buffer)␊ |
785 | ␉␉return;␊ |
786 | ␊ |
787 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
788 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
789 | ␊ |
790 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);␊ |
791 | ␉if (setSMB)␊ |
792 | ␉␉setDefaultSMBData();␊ |
793 | ␊ |
794 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
795 | ␊ |
796 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
797 | ␉if (!neweps)␊ |
798 | ␉␉return;␊ |
799 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
800 | ␊ |
801 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
802 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
803 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
804 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
805 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
806 | ␉neweps->majorVersion␉␉= 2;␊ |
807 | ␉neweps->minorVersion␉␉= 4;␊ |
808 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
809 | ␉neweps->entryPointRevision␉= 0;␊ |
810 | ␊ |
811 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
812 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
813 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
814 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
815 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
816 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
817 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
818 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
819 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
820 | ␊ |
821 | ␉if (!neweps->dmi.tableAddress)␊ |
822 | ␉␉return;␊ |
823 | ␊ |
824 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
825 | ␊ |
826 | ␉neweps->dmi.checksum␉␉= 0;␊ |
827 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
828 | ␊ |
829 | ␉neweps->checksum␉␉␉= 0;␊ |
830 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
831 | ␊ |
832 | ␉free(buffer);␊ |
833 | ␉decodeSMBIOSTable(neweps);␊ |
834 | ␉DBG("SMBIOS orig=%x new=%x\n", origeps, neweps);␊ |
835 | }␊ |
836 | ␊ |
837 | void *getSmbios(int which)␊ |
838 | {␊ |
839 | ␉switch (which)␊ |
840 | ␉{␊ |
841 | ␉␉case SMBIOS_ORIGINAL:␊ |
842 | ␉␉␉if (!origeps)␊ |
843 | ␉␉␉␉origeps = getAddressOfSmbiosTable();␊ |
844 | ␉␉␉return origeps;␊ |
845 | ␉␉case SMBIOS_PATCHED:␊ |
846 | ␉␉␉return neweps;␊ |
847 | ␉}␊ |
848 | ␊ |
849 | ␉return 0;␊ |
850 | }␊ |
851 | ␊ |
852 | /** Find first original dmi Table with a particular type */␊ |
853 | SMBStructHeader* FindFirstDmiTableOfType(int type, int minlength)␊ |
854 | {␊ |
855 | current_pos = 0; //static variable␊ |
856 | ␊ |
857 | return FindNextDmiTableOfType(type, minlength);␊ |
858 | };␊ |
859 | ␊ |
860 | /** Find next original dmi Table with a particular type */␊ |
861 | SMBStructHeader* FindNextDmiTableOfType(int type, int minlength)␊ |
862 | {␊ |
863 | int i;␊ |
864 | ␉␊ |
865 | // if (ftTablePairInit) getSmbios(SMBIOS_ORIGINAL);␊ |
866 | ␉␊ |
867 | for (i=current_pos; i < DmiTablePairCount; i++) {␊ |
868 | if (type == DmiTablePair[i].type && ␊ |
869 | DmiTablePair[i].dmi &&␊ |
870 | DmiTablePair[i].dmi->length >= minlength ) {␊ |
871 | current_pos = i+1;␊ |
872 | #if DEBUG_SMBIOS␊ |
873 | ␉␉␉DBG("SMBIOS table type %d found\n", type);␊ |
874 | ␉␉␉printf("Press a key to continue... (DEBUG)\n");␊ |
875 | ␉␉␉getchar();␊ |
876 | #endif␊ |
877 | ␉␉␉␊ |
878 | return DmiTablePair[i].dmi;␊ |
879 | }␊ |
880 | }␊ |
881 | ␉DBG("SMBIOS table type %d not found\n", type);␊ |
882 | #if DEBUG_ACPI␊ |
883 | ␉printf("Press a key to continue... (DEBUG)\n");␊ |
884 | ␉getchar();␊ |
885 | #endif␊ |
886 | return NULL; // not found␊ |
887 | };␊ |
888 | ␊ |
889 | ␊ |
890 | /* Collect any information needed later */␊ |
891 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
892 | {␊ |
893 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
894 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
895 | ␉SMBByte tmp = 0;␊ |
896 | ␉SMBWord tmpW = 0;␊ |
897 | ␊ |
898 | ␉int dimmnbr = 0;␊ |
899 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
900 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
901 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
902 | ␊ |
903 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
904 | ␉{␊ |
905 | ␉␉switch (structHeader->type)␊ |
906 | ␉␉{␊ |
907 | ␉␉␉case kSMBTypeSystemInformation:␊ |
908 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
909 | ␉␉␉␉break;␊ |
910 | //Slice - platform mobility should based on Enclosure but not on CPU type␊ |
911 | ␉␉␉case kSMBTypeSystemEnclosure:␊ |
912 | ␉␉␉␉tmp = ((SMBSystemEnclosure *)structHeader)->type;␊ |
913 | ␉␉␉␉Platform->Type = (tmp >=8)?2:1;␊ |
914 | ␉␉␉␉break;␊ |
915 | //Slice - values from DMI/SMBIOS are defined correct if overclocked␉␊ |
916 | // do not need in complex MSR calculation␉␉␉␉␊ |
917 | ␉␉␉case kSMBTypeProcessorInformation:␊ |
918 | ␉␉␉␉tmpW = ((SMBProcessorInformation *)structHeader)->externalClock;␊ |
919 | ␉␉␉␉Platform->CPU.FSBFrequency = tmpW * MEGA + (tmpW & 7) * 110000; //According to Intel 133->133.33MHz␊ |
920 | ␉␉␉␉tmpW = ((SMBProcessorInformation *)structHeader)->currentClock;␊ |
921 | ␉␉␉␉Platform->CPU.CPUFrequency = tmpW * MEGA + (tmpW & 7) * 110000;␊ |
922 | ␉␉␉␉msglog("From SMBIOS: FSB=%d CPU=%d\n", Platform->CPU.FSBFrequency, Platform->CPU.CPUFrequency);␊ |
923 | ␉␉␉␉break;␊ |
924 | ␉␊ |
925 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
926 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
927 | ␉␉␉␉break;␊ |
928 | ␊ |
929 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
930 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
931 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
932 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
933 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
934 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
935 | ␉␉␉␉dimmnbr++;␊ |
936 | ␉␉␉␉break;␊ |
937 | ␉␉}␊ |
938 | ␊ |
939 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
940 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
941 | ␊ |
942 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
943 | ␉␉␉structPtr += 2;␊ |
944 | ␊ |
945 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
946 | ␉}␊ |
947 | }␊ |
948 | |