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 | ␉// SystemEnclosure␊ |
263 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
264 | ␉{kSMBTypeSystemEnclosure,␉kSMBString,␉getFieldOffset(SMBSystemEnclosure, manufacturer),␊ |
265 | ␉␉kSMBBaseBoardManufacturerKey,␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
266 | ␉␊ |
267 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
268 | ␉// ProcessorInformation␊ |
269 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
270 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
271 | ␊ |
272 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
273 | ␊ |
274 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
275 | ␊ |
276 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
277 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
278 | ␊ |
279 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
280 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
281 | ␊ |
282 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
283 | ␊ |
284 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
285 | ␊ |
286 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
287 | ␊ |
288 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
289 | ␉// Memory Device␊ |
290 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
291 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
292 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
293 | ␊ |
294 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
295 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
296 | ␊ |
297 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
298 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
299 | ␊ |
300 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
301 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
302 | ␊ |
303 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
304 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
305 | ␊ |
306 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
307 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
308 | ␊ |
309 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
310 | ␊ |
311 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
312 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
313 | ␊ |
314 | ␊ |
315 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
316 | ␉// Apple Specific␊ |
317 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
318 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
319 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
320 | ␊ |
321 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
322 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
323 | };␊ |
324 | ␊ |
325 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
326 | ␊ |
327 | ␊ |
328 | SMBEntryPoint *origeps␉= 0;␊ |
329 | SMBEntryPoint *neweps␉= 0;␊ |
330 | ␊ |
331 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
332 | static uint8_t stringsSize;␉// add string size␊ |
333 | ␊ |
334 | static SMBWord tableLength␉␉= 0;␊ |
335 | static SMBWord handle␉␉␉= 0;␊ |
336 | static SMBWord maxStructSize␉= 0;␊ |
337 | static SMBWord structureCount␉= 0;␊ |
338 | ␊ |
339 | /* Rewrite this function */␊ |
340 | void setDefaultSMBData(void)␊ |
341 | {␊ |
342 | ␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
343 | ␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
344 | ␊ |
345 | ␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
346 | ␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
347 | ␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
348 | ␊ |
349 | ␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
350 | ␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
351 | ␊ |
352 | ␉if (Platform->Type == 2)␉␉//platformCPUFeature(CPU_FEATURE_MOBILE))␊ |
353 | ␉{␊ |
354 | ␉␉if (vgaVendor != PCI_VENDOR_ID_INTEL) //Slice␊ |
355 | ␉␉{␊ |
356 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookProBIOSVersion;␊ |
357 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBookPro;␊ |
358 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookProFamily;␊ |
359 | ␉␉}␊ |
360 | ␉␉else␊ |
361 | ␉␉{␊ |
362 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookBIOSVersion;␊ |
363 | ␉␉␉defaultSystemInfo.productName␉= kDefaultMacBook;␊ |
364 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookFamily;␊ |
365 | ␉␉}␊ |
366 | ␉}␊ |
367 | ␉else␊ |
368 | ␉{␊ |
369 | ␉␉switch (Platform->CPU.NoCores) ␊ |
370 | ␉␉{␊ |
371 | ␉␉␉case 1: ␊ |
372 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacminiBIOSVersion;␊ |
373 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacmini;␊ |
374 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacminiFamily;␊ |
375 | ␉␉␉␉break;␊ |
376 | ␊ |
377 | ␉␉␉case 2:␊ |
378 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacBIOSVersion;␊ |
379 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMac;␊ |
380 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
381 | ␉␉␉␉break;␊ |
382 | ␉␉␉default:␊ |
383 | ␉␉␉{␊ |
384 | ␉␉␉␉switch (Platform->CPU.Family) ␊ |
385 | ␉␉␉␉{␊ |
386 | ␉␉␉␉␉case 0x06:␊ |
387 | ␉␉␉␉␉{␊ |
388 | ␉␉␉␉␉␉switch (Platform->CPU.Model)␊ |
389 | ␉␉␉␉␉␉{␊ |
390 | ␉␉␉␉␉␉␉case CPU_MODEL_FIELDS:␉␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
391 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES:␊ |
392 | ␉␉␉␉␉␉␉case CPU_MODEL_DALES_32NM:␉␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
393 | ␉␉␉␉␉␉␉case 0x19:␉␉␉␉␉␉// ??? Intel Core i5 650 @3.20 GHz ␊ |
394 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacNehalemBIOSVersion;␊ |
395 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacNehalem;␊ |
396 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
397 | ␉␉␉␉␉␉␉␉break;␊ |
398 | ␊ |
399 | ␉␉␉␉␉␉␉case CPU_MODEL_SANDY:␉␉␉// Intel Core i3, i5, i7 LGA1155 (32nm)␊ |
400 | ␉␉␉␉␉␉␉case CPU_MODEL_SANDY_XEON:␉␉// Intel Xeon E3␊ |
401 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacSandyBIOSVersion;␊ |
402 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacSandy;␊ |
403 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
404 | ␉␉␉␉␉␉␉␉break;␊ |
405 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM:␉␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
406 | ␉␉␉␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
407 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
408 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
409 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
410 | ␉␉␉␉␉␉␉␉break;␊ |
411 | ␊ |
412 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE:␉␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
413 | ␉␉␉␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉␉// Intel Xeon E7␊ |
414 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProWestmereBIOSVersion;␊ |
415 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulMacProWestmereBIOSReleaseDate;␊ |
416 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProWestmere;␊ |
417 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
418 | ␉␉␉␉␉␉␉␉break;␊ |
419 | ␊ |
420 | ␉␉␉␉␉␉␉default:␊ |
421 | ␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
422 | ␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
423 | ␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
424 | ␉␉␉␉␉␉␉␉break;␊ |
425 | ␉␉␉␉␉␉}␊ |
426 | ␉␉␉␉␉␉break;␊ |
427 | ␉␉␉␉␉}␊ |
428 | ␉␉␉␉␉default:␊ |
429 | ␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
430 | ␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
431 | ␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
432 | ␉␉␉␉␉␉break;␊ |
433 | ␉␉␉␉}␊ |
434 | ␉␉␉␉break;␊ |
435 | ␉␉␉}␊ |
436 | ␉␉}␊ |
437 | ␉}␊ |
438 | }␊ |
439 | ␊ |
440 | /* Used for SM*n smbios.plist keys */␊ |
441 | bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
442 | {␊ |
443 | ␉static int idx = -1;␊ |
444 | ␉static int current = -1;␊ |
445 | ␉int len;␊ |
446 | ␉char key[24];␊ |
447 | ␊ |
448 | ␉if (current != structHeader->handle)␊ |
449 | ␉{␊ |
450 | ␉␉idx++;␊ |
451 | ␉␉current = structHeader->handle;␊ |
452 | ␉}␊ |
453 | ␊ |
454 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
455 | ␊ |
456 | ␉if (value)␊ |
457 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
458 | ␉␉␉return true;␊ |
459 | ␉else␊ |
460 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
461 | ␉␉␉return true;␊ |
462 | ␉return false;␊ |
463 | }␊ |
464 | ␊ |
465 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
466 | {␊ |
467 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
468 | ␊ |
469 | ␉if (!field)␊ |
470 | ␉␉return NULL;␊ |
471 | ␊ |
472 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
473 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
474 | ␊ |
475 | ␉return (char *)stringPtr;␊ |
476 | }␊ |
477 | ␊ |
478 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
479 | {␊ |
480 | ␉int strSize;␊ |
481 | ␊ |
482 | ␉if (!field)␊ |
483 | ␉␉return;␊ |
484 | ␉if (!string)␊ |
485 | ␉{␊ |
486 | ␉␉*field = 0;␊ |
487 | ␉␉return;␊ |
488 | ␉}␊ |
489 | ␊ |
490 | ␉strSize = strlen(string);␊ |
491 | ␊ |
492 | ␉// remove any spaces found at the end␊ |
493 | ␉while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
494 | ␉␉strSize--;␊ |
495 | ␊ |
496 | ␉if (strSize == 0)␊ |
497 | ␉{␊ |
498 | ␉␉*field = 0;␊ |
499 | ␉␉return;␊ |
500 | ␉}␊ |
501 | ␊ |
502 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
503 | ␉*field = stringIndex;␊ |
504 | ␊ |
505 | ␉stringIndex++;␊ |
506 | ␉stringsSize += strSize + 1;␊ |
507 | }␊ |
508 | ␊ |
509 | bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
510 | {␊ |
511 | ␉const char *string = 0;␊ |
512 | ␉int len;␊ |
513 | ␉bool parsed;␊ |
514 | ␉int val;␊ |
515 | ␊ |
516 | ␉if (numOfSetters <= idx)␊ |
517 | ␉␉return false;␊ |
518 | ␊ |
519 | ␉switch (SMBSetters[idx].valueType)␊ |
520 | ␉{␊ |
521 | ␉␉case kSMBString:␊ |
522 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
523 | ␉␉␉{␊ |
524 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
525 | ␉␉␉␉␉break;␊ |
526 | ␉␉␉␉else␊ |
527 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
528 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
529 | ␉␉␉␉␉␉␉break;␊ |
530 | ␉␉␉}␊ |
531 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
532 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
533 | ␉␉␉␉␉break;␊ |
534 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
535 | ␉␉␉{␊ |
536 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
537 | ␉␉␉␉break;␊ |
538 | ␉␉␉}␊ |
539 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
540 | ␉␉␉break;␊ |
541 | ␊ |
542 | ␉␉case kSMBByte:␊ |
543 | ␉␉case kSMBWord:␊ |
544 | ␉␉case kSMBDWord:␊ |
545 | ␉␉//case kSMBQWord:␊ |
546 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
547 | ␉␉␉{␊ |
548 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
549 | ␉␉␉␉if (!parsed)␊ |
550 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
551 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
552 | ␉␉␉␉if (parsed)␊ |
553 | ␉␉␉␉{␊ |
554 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
555 | ␉␉␉␉␉{␊ |
556 | ␉␉␉␉␉␉case kSMBByte:␊ |
557 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
558 | ␉␉␉␉␉␉␉break;␊ |
559 | ␉␉␉␉␉␉case kSMBWord:␊ |
560 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
561 | ␉␉␉␉␉␉␉break;␊ |
562 | ␉␉␉␉␉␉case kSMBDWord:␊ |
563 | ␉␉␉␉␉␉default:␊ |
564 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
565 | ␉␉␉␉␉␉␉break;␊ |
566 | ␉␉␉␉␉}␊ |
567 | ␉␉␉␉␉return true;␊ |
568 | ␉␉␉␉}␊ |
569 | ␉␉␉}␊ |
570 | ␊ |
571 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
572 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
573 | ␉␉␉␉␉return true;␊ |
574 | #if 0␊ |
575 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
576 | ␉␉␉{␊ |
577 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
578 | ␉␉␉␉return true;␊ |
579 | ␉␉␉}␊ |
580 | #endif␊ |
581 | ␉␉␉break;␊ |
582 | ␉}␊ |
583 | ␊ |
584 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
585 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
586 | ␊ |
587 | ␉return true;␊ |
588 | }␊ |
589 | ␊ |
590 | //-------------------------------------------------------------------------------------------------------------------------␊ |
591 | // Apple Specific␊ |
592 | //-------------------------------------------------------------------------------------------------------------------------␊ |
593 | void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
594 | {␊ |
595 | ␉return;␊ |
596 | }␊ |
597 | ␊ |
598 | void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
599 | {␊ |
600 | ␉/* SPD data from Platform->RAM.spd */␊ |
601 | ␉return;␊ |
602 | }␊ |
603 | ␊ |
604 | void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
605 | {␊ |
606 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
607 | ␊ |
608 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
609 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
610 | ␉p->header.handle␉= handle++;␊ |
611 | ␊ |
612 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
613 | ␊ |
614 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
615 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
616 | ␉structureCount++;␊ |
617 | }␊ |
618 | ␊ |
619 | void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
620 | {␊ |
621 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
622 | ␉SMBWord tmp = 0;␊ |
623 | ␉switch (Platform->CPU.Family) ␊ |
624 | ␉{␊ |
625 | ␉␉case 0x06:␊ |
626 | ␉␉{␊ |
627 | ␉␉␉switch (Platform->CPU.Model)␊ |
628 | ␉␉␉{␊ |
629 | ␉␉␉␉case 0x19:␉␉␉␉␉// ??? Intel Core i5 650 @3.20 GHz␊ |
630 | ␉␉␉␉case CPU_MODEL_FIELDS:␉␉// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)␊ |
631 | ␉␉␉␉case CPU_MODEL_DALES:␊ |
632 | ␉␉␉␉case CPU_MODEL_DALES_32NM:␉// Intel Core i3, i5 LGA1156 (32nm)␊ |
633 | ␉␉␉␉case CPU_MODEL_NEHALEM:␉␉// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)␊ |
634 | ␉␉␉␉case CPU_MODEL_NEHALEM_EX:␉// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x␊ |
635 | ␉␉␉␉case CPU_MODEL_WESTMERE:␉// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core␊ |
636 | ␉␉␉␉case CPU_MODEL_WESTMERE_EX:␉// Intel Xeon E7␊ |
637 | ␉␉␉␉case CPU_MODEL_SANDY:␊ |
638 | ␉␉␉␉case CPU_MODEL_SANDY_XEON:␊ |
639 | ␉␉␉␉␉tmp = p->ProcessorBusSpeed;␊ |
640 | ␉␉␉␉␉break;␊ |
641 | ␊ |
642 | ␉␉␉␉default:␊ |
643 | ␉␉␉␉␉tmp = (Platform->CPU.FSBFrequency * 4) / MEGA;␊ |
644 | ␉␉␉␉␉break;␊ |
645 | ␉␉␉␉␉//return;␊ |
646 | ␉␉␉}␊ |
647 | ␉␉}␊ |
648 | ␉}␊ |
649 | ␊ |
650 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
651 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
652 | ␉p->header.handle␉= handle++;␊ |
653 | ␊ |
654 | ␉if(!setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed)))␊ |
655 | ␉␉p->ProcessorBusSpeed = tmp;␊ |
656 | ␊ |
657 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
658 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
659 | ␉structureCount++;␊ |
660 | }␊ |
661 | ␊ |
662 | //-------------------------------------------------------------------------------------------------------------------------␊ |
663 | // EndOfTable␊ |
664 | //-------------------------------------------------------------------------------------------------------------------------␊ |
665 | void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
666 | {␊ |
667 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
668 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
669 | ␉structPtr->new->handle␉= handle++;␊ |
670 | ␊ |
671 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
672 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
673 | ␉structureCount++;␊ |
674 | }␊ |
675 | ␊ |
676 | void setSMBStruct(SMBStructPtrs *structPtr)␊ |
677 | {␊ |
678 | ␉bool setterFound = false;␊ |
679 | ␊ |
680 | ␉uint8_t *ptr;␊ |
681 | ␉SMBWord structSize;␊ |
682 | ␉int i;␊ |
683 | ␊ |
684 | ␉stringIndex = 1;␊ |
685 | ␉stringsSize = 0;␊ |
686 | ␊ |
687 | ␉if (handle < structPtr->orig->handle)␊ |
688 | ␉␉handle = structPtr->orig->handle;␊ |
689 | ␊ |
690 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
691 | ␊ |
692 | ␉for (i = 0; i < numOfSetters; i++)␊ |
693 | ␉␉if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
694 | ␉␉{␊ |
695 | ␉␉␉setterFound = true;␊ |
696 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
697 | ␉␉}␊ |
698 | ␊ |
699 | ␉if (setterFound)␊ |
700 | ␉{␊ |
701 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
702 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
703 | ␊ |
704 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
705 | ␉␉␉ptr += 2;␊ |
706 | ␊ |
707 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
708 | ␉}␊ |
709 | ␉else␊ |
710 | ␉{␊ |
711 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
712 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
713 | ␊ |
714 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
715 | ␉␉␉ptr += 2;␊ |
716 | ␉␉␊ |
717 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
718 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
719 | ␉}␊ |
720 | ␊ |
721 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
722 | ␊ |
723 | ␉tableLength += structSize;␊ |
724 | ␊ |
725 | ␉if (structSize > maxStructSize)␊ |
726 | ␉␉maxStructSize = structSize;␊ |
727 | ␊ |
728 | ␉structureCount++;␊ |
729 | }␊ |
730 | ␊ |
731 | void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
732 | {␊ |
733 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
734 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
735 | ␊ |
736 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
737 | ␉{␊ |
738 | ␉␉switch (structPtr->orig->type)␊ |
739 | ␉␉{␊ |
740 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
741 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
742 | ␉␉␉case kSMBTypeMemorySPD:␊ |
743 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
744 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
745 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
746 | ␉␉␉case kSMBTypeEndOfTable:␊ |
747 | ␉␉␉␉break;␊ |
748 | ␊ |
749 | ␉␉␉default:␊ |
750 | ␉␉␉␉/* Add */␊ |
751 | ␉␉␉␉setSMBStruct(structPtr);␊ |
752 | ␉␉␉␉break;␊ |
753 | ␉␉}␊ |
754 | ␊ |
755 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
756 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
757 | ␊ |
758 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
759 | ␉␉␉ptr += 2;␊ |
760 | ␊ |
761 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
762 | ␉}␊ |
763 | ␊ |
764 | ␉addSMBFirmwareVolume(structPtr);␊ |
765 | ␉addSMBMemorySPD(structPtr);␊ |
766 | ␉addSMBOemProcessorType(structPtr);␊ |
767 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
768 | ␊ |
769 | ␉addSMBEndOfTable(structPtr);␊ |
770 | }␊ |
771 | ␊ |
772 | void setupSMBIOSTable(void)␊ |
773 | {␊ |
774 | ␉SMBStructPtrs *structPtr;␊ |
775 | ␉uint8_t *buffer;␊ |
776 | ␉bool setSMB = true;␊ |
777 | ␊ |
778 | ␉if (!origeps)␊ |
779 | ␉␉return;␊ |
780 | ␊ |
781 | ␉neweps = origeps;␊ |
782 | ␊ |
783 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
784 | ␉if (!structPtr)␊ |
785 | ␉␉return;␊ |
786 | ␉␊ |
787 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
788 | ␉if (!buffer)␊ |
789 | ␉␉return;␊ |
790 | ␊ |
791 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
792 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
793 | ␊ |
794 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);␊ |
795 | ␉if (setSMB)␊ |
796 | ␉␉setDefaultSMBData();␊ |
797 | ␊ |
798 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
799 | ␊ |
800 | ␉neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
801 | ␉if (!neweps)␊ |
802 | ␉␉return;␊ |
803 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
804 | ␊ |
805 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
806 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
807 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
808 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
809 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
810 | ␉neweps->majorVersion␉␉= 2;␊ |
811 | ␉neweps->minorVersion␉␉= 4;␊ |
812 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
813 | ␉neweps->entryPointRevision␉= 0;␊ |
814 | ␊ |
815 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
816 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
817 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
818 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
819 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
820 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
821 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
822 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
823 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
824 | ␊ |
825 | ␉if (!neweps->dmi.tableAddress)␊ |
826 | ␉␉return;␊ |
827 | ␊ |
828 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
829 | ␊ |
830 | ␉neweps->dmi.checksum␉␉= 0;␊ |
831 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
832 | ␊ |
833 | ␉neweps->checksum␉␉␉= 0;␊ |
834 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
835 | ␊ |
836 | ␉free(buffer);␊ |
837 | ␉decodeSMBIOSTable(neweps);␊ |
838 | ␉DBG("SMBIOS orig=%x new=%x\n", origeps, neweps);␊ |
839 | }␊ |
840 | ␊ |
841 | void *getSmbios(int which)␊ |
842 | {␊ |
843 | ␉switch (which)␊ |
844 | ␉{␊ |
845 | ␉␉case SMBIOS_ORIGINAL:␊ |
846 | ␉␉␉if (!origeps)␊ |
847 | ␉␉␉␉origeps = getAddressOfSmbiosTable();␊ |
848 | ␉␉␉return origeps;␊ |
849 | ␉␉case SMBIOS_PATCHED:␊ |
850 | ␉␉␉return neweps;␊ |
851 | ␉}␊ |
852 | ␊ |
853 | ␉return 0;␊ |
854 | }␊ |
855 | ␊ |
856 | /** Find first original dmi Table with a particular type */␊ |
857 | SMBStructHeader* FindFirstDmiTableOfType(int type, int minlength)␊ |
858 | {␊ |
859 | current_pos = 0; //static variable␊ |
860 | ␊ |
861 | return FindNextDmiTableOfType(type, minlength);␊ |
862 | };␊ |
863 | ␊ |
864 | /** Find next original dmi Table with a particular type */␊ |
865 | SMBStructHeader* FindNextDmiTableOfType(int type, int minlength)␊ |
866 | {␊ |
867 | int i;␊ |
868 | ␉␊ |
869 | // if (ftTablePairInit) getSmbios(SMBIOS_ORIGINAL);␊ |
870 | ␉␊ |
871 | for (i=current_pos; i < DmiTablePairCount; i++) {␊ |
872 | if (type == DmiTablePair[i].type && ␊ |
873 | DmiTablePair[i].dmi &&␊ |
874 | DmiTablePair[i].dmi->length >= minlength ) {␊ |
875 | current_pos = i+1;␊ |
876 | #if DEBUG_SMBIOS␊ |
877 | ␉␉␉DBG("SMBIOS table type %d found\n", type);␊ |
878 | ␉␉␉printf("Press a key to continue... (DEBUG)\n");␊ |
879 | ␉␉␉getchar();␊ |
880 | #endif␊ |
881 | ␉␉␉␊ |
882 | return DmiTablePair[i].dmi;␊ |
883 | }␊ |
884 | }␊ |
885 | ␉DBG("SMBIOS table type %d not found\n", type);␊ |
886 | #if DEBUG_ACPI␊ |
887 | ␉printf("Press a key to continue... (DEBUG)\n");␊ |
888 | ␉getchar();␊ |
889 | #endif␊ |
890 | return NULL; // not found␊ |
891 | };␊ |
892 | ␊ |
893 | ␊ |
894 | /* Collect any information needed later */␊ |
895 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
896 | {␊ |
897 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
898 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
899 | ␉SMBByte tmp = 0;␊ |
900 | ␉SMBWord tmpW = 0;␊ |
901 | ␊ |
902 | //␉int dimmnbr = 0;␊ |
903 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
904 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
905 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
906 | ␊ |
907 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
908 | ␉{␊ |
909 | ␉␉switch (structHeader->type)␊ |
910 | ␉␉{␊ |
911 | ␉␉␉case kSMBTypeSystemInformation:␊ |
912 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
913 | ␉␉␉␉break;␊ |
914 | //Slice - platform mobility should based on Enclosure but not on CPU type␊ |
915 | ␉␉␉case kSMBTypeSystemEnclosure:␊ |
916 | ␉␉␉␉tmp = ((SMBSystemEnclosure *)structHeader)->type;␊ |
917 | ␉␉␉␉Platform->Type = (tmp >=8)?2:1;␊ |
918 | ␉␉␉␉break;␊ |
919 | //Slice - values from DMI/SMBIOS are defined correct if overclocked␉␊ |
920 | // do not need in complex MSR calculation␉␉␉␉␊ |
921 | ␉␉␉case kSMBTypeProcessorInformation:␊ |
922 | ␉␉␉␉tmpW = ((SMBProcessorInformation *)structHeader)->externalClock;␊ |
923 | ␉␉␉␉Platform->CPU.FSBFrequency = (uint64_t)tmpW * MEGA + (uint64_t)(tmpW % 10) * 110000; //According to Intel 133->133.33MHz␊ |
924 | ␉␉␉␉tmpW = ((SMBProcessorInformation *)structHeader)->currentClock;␊ |
925 | ␉␉␉␉Platform->CPU.CPUFrequency = (uint64_t)tmpW * MEGA + (uint64_t)(tmpW % 10) * 110000;␊ |
926 | ␉␉␉␉msglog("From SMBIOS: FSB=%d CPU=%d\n", Platform->CPU.FSBFrequency, Platform->CPU.CPUFrequency);␊ |
927 | ␉␉␉␉break;␊ |
928 | ␉␊ |
929 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
930 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
931 | ␉␉␉␉break;␊ |
932 | ␊ |
933 | /*␉␉␉case kSMBTypeMemoryDevice:␊ |
934 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
935 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
936 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
937 | ␉␉␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
938 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
939 | ␉␉␉␉dimmnbr++;␊ |
940 | ␉␉␉␉break;␊ |
941 | */␊ |
942 | ␉␉}␊ |
943 | ␊ |
944 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
945 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
946 | ␊ |
947 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
948 | ␉␉␉structPtr += 2;␊ |
949 | ␊ |
950 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
951 | ␉}␊ |
952 | }␊ |
953 | |