Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/libsaio/smbios.c

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

Archive Download this file

Revision: 2281