Chameleon

Chameleon Svn Source Tree

Root/branches/Chimera/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,kSMBString,getFieldOffset(SMBMemoryDevice, partNumber),kSMBMemoryDevicePartNumberKey,
250getSMBMemoryDevicePartNumber,NULL},
251
252
253//-------------------------------------------------------------------------------------------------------------------------
254// Apple Specific
255//-------------------------------------------------------------------------------------------------------------------------
256{kSMBTypeOemProcessorType,kSMBWord,getFieldOffset(SMBOemProcessorType, ProcessorType),kSMBOemProcessorTypeKey,
257getSMBOemProcessorType,NULL},
258
259{kSMBTypeOemProcessorBusSpeed,kSMBWord,getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),kSMBOemProcessorBusSpeedKey,
260getSMBOemProcessorBusSpeed,NULL}
261};
262
263int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);
264
265
266SMBEntryPoint *origeps= 0;
267SMBEntryPoint *neweps= 0;
268
269static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
270static uint8_t stringsSize;// add string size
271
272static SMBWord tableLength= 0;
273static SMBWord handle= 0;
274static SMBWord maxStructSize= 0;
275static SMBWord structureCount= 0;
276
277/* Rewrite this function */
278void setDefaultSMBData(void)
279{
280defaultBIOSInfo.vendor= kDefaultVendorManufacturer;
281defaultBIOSInfo.releaseDate= kDefaultBIOSReleaseDate;
282
283defaultSystemInfo.manufacturer= kDefaultVendorManufacturer;
284defaultSystemInfo.version= kDefaultSystemVersion;
285defaultSystemInfo.serialNumber= kDefaultSerialNumber;
286
287defaultBaseBoard.manufacturer= kDefaultVendorManufacturer;
288defaultBaseBoard.product= kDefaultBoardProduct;
289
290if (platformCPUFeature(CPU_FEATURE_MOBILE))
291{
292if (Platform.CPU.NoCores > 1)
293{
294defaultBIOSInfo.version= kDefaultMacBookProBIOSVersion;
295defaultSystemInfo.productName= kDefaultMacBookPro;
296defaultSystemInfo.family= kDefaultMacBookProFamily;
297}
298else
299{
300defaultBIOSInfo.version= kDefaultMacBookBIOSVersion;
301defaultSystemInfo.productName= kDefaultMacBook;
302defaultSystemInfo.family= kDefaultMacBookFamily;
303}
304}
305else
306{
307switch (Platform.CPU.NoCores)
308{
309case 1:
310defaultBIOSInfo.version= kDefaultMacminiBIOSVersion;
311defaultSystemInfo.productName= kDefaultMacmini;
312defaultSystemInfo.family= kDefaultMacminiFamily;
313break;
314
315case 2:
316defaultBIOSInfo.version= kDefaultiMacBIOSVersion;
317defaultSystemInfo.productName= kDefaultiMac;
318defaultSystemInfo.family= kDefaultiMacFamily;
319break;
320default:
321{
322switch (Platform.CPU.Family)
323{
324case 0x06:
325{
326switch (Platform.CPU.Model)
327{
328case CPU_MODEL_FIELDS: // Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
329case CPU_MODEL_DALES:
330case CPU_MODEL_DALES_32NM: // Intel Core i3, i5 LGA1156 (32nm)
331defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
332defaultSystemInfo.productName= kDefaultiMacNehalem;
333defaultSystemInfo.family= kDefaultiMacFamily;
334break;
335
336case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
337case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
338defaultBIOSInfo.version= kDefaultiMacSandyBIOSVersion;
339defaultSystemInfo.productName= kDefaultiMacSandy;
340defaultSystemInfo.family= kDefaultiMacFamily;
341break;
342case CPU_MODEL_NEHALEM: // Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
343case CPU_MODEL_NEHALEM_EX: // Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
344defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
345defaultSystemInfo.productName= kDefaultMacProNehalem;
346defaultSystemInfo.family= kDefaultMacProFamily;
347break;
348
349case CPU_MODEL_WESTMERE: // Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
350case CPU_MODEL_WESTMERE_EX: // Intel Xeon E7
351 case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
352defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
353defaultBIOSInfo.releaseDate= kDefaulMacProWestmereBIOSReleaseDate;
354defaultSystemInfo.productName= kDefaultMacProWestmere;
355defaultSystemInfo.family= kDefaultMacProFamily;
356break;
357
358default:
359defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
360defaultSystemInfo.productName= kDefaultMacPro;
361defaultSystemInfo.family= kDefaultMacProFamily;
362break;
363}
364break;
365}
366default:
367defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
368defaultSystemInfo.productName= kDefaultMacPro;
369defaultSystemInfo.family= kDefaultMacProFamily;
370break;
371}
372break;
373}
374}
375}
376}
377
378/* Used for SM*n smbios.plist keys */
379bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
380{
381static int idx = -1;
382static int current = -1;
383int len;
384char key[24];
385
386if (current != structHeader->handle)
387{
388idx++;
389current = structHeader->handle;
390}
391
392sprintf(key, "%s%d", keyString, idx);
393
394 if (value)
395 {
396 if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
397 return true;
398 }
399 else
400 {
401 if (getValueForKey(key, string, &len, SMBPlist))
402 return true;
403 }
404
405return false;
406}
407
408char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
409{
410uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
411
412if (!field)
413return NULL;
414
415for (field--; field != 0 && strlen((char *)stringPtr) > 0;
416field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
417
418return (char *)stringPtr;
419}
420
421void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
422{
423int strSize;
424
425if (!field)
426return;
427if (!string)
428{
429*field = 0;
430return;
431}
432
433strSize = strlen(string);
434
435// remove any spaces found at the end
436while ((strSize != 0) && (string[strSize - 1] == ' '))
437strSize--;
438
439if (strSize == 0)
440{
441*field = 0;
442return;
443}
444
445memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
446*field = stringIndex;
447
448stringIndex++;
449stringsSize += strSize + 1;
450}
451
452bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
453{
454const char *string = 0;
455int len;
456bool parsed;
457int val;
458
459if (numOfSetters <= idx)
460return false;
461
462switch (SMBSetters[idx].valueType)
463{
464case kSMBString:
465if (SMBSetters[idx].keyString)
466{
467if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
468break;
469else
470if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
471if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
472break;
473}
474if (SMBSetters[idx].getSMBValue)
475if (SMBSetters[idx].getSMBValue((returnType *)&string))
476break;
477if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))
478{
479string = *(SMBSetters[idx].defaultValue);
480break;
481}
482string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
483break;
484
485case kSMBByte:
486case kSMBWord:
487case kSMBDWord:
488//case kSMBQWord:
489if (SMBSetters[idx].keyString)
490{
491parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
492if (!parsed)
493if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
494parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
495if (parsed)
496{
497switch (SMBSetters[idx].valueType)
498{
499case kSMBByte:
500value->byte = (uint8_t)val;
501break;
502case kSMBWord:
503value->word = (uint16_t)val;
504break;
505case kSMBDWord:
506default:
507value->dword = (uint32_t)val;
508break;
509}
510return true;
511}
512}
513
514if (SMBSetters[idx].getSMBValue)
515if (SMBSetters[idx].getSMBValue(value))
516return true;
517#if 0
518if (*(SMBSetters[idx].defaultValue))
519{
520value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
521return true;
522}
523#endif
524break;
525}
526
527if (SMBSetters[idx].valueType == kSMBString && string)
528setSMBStringForField(structPtr->new, string, &value->byte);
529
530return true;
531}
532
533//-------------------------------------------------------------------------------------------------------------------------
534// Apple Specific
535//-------------------------------------------------------------------------------------------------------------------------
536void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
537{
538return;
539}
540
541void addSMBMemorySPD(SMBStructPtrs *structPtr)
542{
543/* SPD data from Platform.RAM.spd */
544return;
545}
546
547void addSMBOemProcessorType(SMBStructPtrs *structPtr)
548{
549SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
550
551p->header.type= kSMBTypeOemProcessorType;
552p->header.length= sizeof(SMBOemProcessorType);
553p->header.handle= handle++;
554
555setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
556
557structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
558tableLength += sizeof(SMBOemProcessorType) + 2;
559structureCount++;
560}
561
562void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
563{
564SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
565
566switch (Platform.CPU.Family)
567{
568case 0x06:
569{
570switch (Platform.CPU.Model)
571{
572case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
573case CPU_MODEL_DALES:
574case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
575case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
576case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
577case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
578case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
579 case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
580case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
581case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
582 case CPU_MODEL_HASWELL: // Intel Core i3, i5, i7, Xeon E3 LGA1155 (22nm)
583break;
584
585default:
586return;
587}
588}
589}
590
591p->header.type= kSMBTypeOemProcessorBusSpeed;
592p->header.length= sizeof(SMBOemProcessorBusSpeed);
593p->header.handle= handle++;
594
595setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
596
597structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
598tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
599structureCount++;
600}
601
602//-------------------------------------------------------------------------------------------------------------------------
603// EndOfTable
604//-------------------------------------------------------------------------------------------------------------------------
605void addSMBEndOfTable(SMBStructPtrs *structPtr)
606{
607structPtr->new->type= kSMBTypeEndOfTable;
608structPtr->new->length= sizeof(SMBStructHeader);
609structPtr->new->handle= handle++;
610
611structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
612tableLength += sizeof(SMBStructHeader) + 2;
613structureCount++;
614}
615
616void setSMBStruct(SMBStructPtrs *structPtr)
617{
618bool setterFound = false;
619
620uint8_t *ptr;
621SMBWord structSize;
622int i;
623
624stringIndex = 1;
625stringsSize = 0;
626
627if (handle < structPtr->orig->handle)
628handle = structPtr->orig->handle;
629
630memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
631
632for (i = 0; i < numOfSetters; i++)
633if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))
634{
635setterFound = true;
636setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
637}
638
639if (setterFound)
640{
641ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
642for (; ((uint16_t *)ptr)[0] != 0; ptr++);
643
644if (((uint16_t *)ptr)[0] == 0)
645ptr += 2;
646
647structSize = ptr - (uint8_t *)structPtr->new;
648}
649else
650{
651ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
652for (; ((uint16_t *)ptr)[0] != 0; ptr++);
653
654if (((uint16_t *)ptr)[0] == 0)
655ptr += 2;
656
657structSize = ptr - (uint8_t *)structPtr->orig;
658memcpy((void *)structPtr->new, structPtr->orig, structSize);
659}
660
661structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
662
663tableLength += structSize;
664
665if (structSize > maxStructSize)
666maxStructSize = structSize;
667
668structureCount++;
669}
670
671void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
672{
673uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
674structPtr->orig = (SMBStructHeader *)ptr;
675
676for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
677{
678switch (structPtr->orig->type)
679{
680/* Skip all Apple Specific Structures */
681case kSMBTypeFirmwareVolume:
682case kSMBTypeMemorySPD:
683case kSMBTypeOemProcessorType:
684case kSMBTypeOemProcessorBusSpeed:
685/* And this one too, to be added at the end */
686case kSMBTypeEndOfTable:
687break;
688
689default:
690/* Add */
691setSMBStruct(structPtr);
692break;
693}
694
695ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
696for (; ((uint16_t *)ptr)[0] != 0; ptr++);
697
698if (((uint16_t *)ptr)[0] == 0)
699ptr += 2;
700
701structPtr->orig = (SMBStructHeader *)ptr;
702}
703
704addSMBFirmwareVolume(structPtr);
705addSMBMemorySPD(structPtr);
706addSMBOemProcessorType(structPtr);
707addSMBOemProcessorBusSpeed(structPtr);
708
709addSMBEndOfTable(structPtr);
710}
711
712void setupSMBIOSTable(void)
713{
714SMBStructPtrs *structPtr;
715uint8_t *buffer;
716bool setSMB = true;
717
718if (!origeps)
719return;
720
721neweps = origeps;
722
723structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
724if (!structPtr)
725return;
726
727buffer = malloc(SMB_ALLOC_SIZE);
728if (!buffer)
729return;
730
731bzero(buffer, SMB_ALLOC_SIZE);
732structPtr->new = (SMBStructHeader *)buffer;
733
734getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);
735if (setSMB)
736setDefaultSMBData();
737
738setupNewSMBIOSTable(origeps, structPtr);
739
740neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
741if (!neweps)
742return;
743bzero(neweps, sizeof(SMBEntryPoint));
744
745neweps->anchor[0]= '_';
746neweps->anchor[1]= 'S';
747neweps->anchor[2]= 'M';
748neweps->anchor[3]= '_';
749neweps->entryPointLength= sizeof(SMBEntryPoint);
750neweps->majorVersion= 2;
751neweps->minorVersion= 4;
752neweps->maxStructureSize= maxStructSize;
753neweps->entryPointRevision= 0;
754
755neweps->dmi.anchor[0]= '_';
756neweps->dmi.anchor[1]= 'D';
757neweps->dmi.anchor[2]= 'M';
758neweps->dmi.anchor[3]= 'I';
759neweps->dmi.anchor[4]= '_';
760neweps->dmi.tableLength= tableLength;
761neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
762neweps->dmi.structureCount= structureCount;
763neweps->dmi.bcdRevision= 0x24;
764
765if (!neweps->dmi.tableAddress)
766return;
767
768memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
769
770neweps->dmi.checksum= 0;
771neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
772
773neweps->checksum= 0;
774neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
775
776free(buffer);
777decodeSMBIOSTable(neweps);
778}
779
780void *getSmbios(int which)
781{
782switch (which)
783{
784case SMBIOS_ORIGINAL:
785if (!origeps)
786origeps = getAddressOfSmbiosTable();
787return origeps;
788case SMBIOS_PATCHED:
789return neweps;
790}
791
792return 0;
793}
794
795/* Collect any information needed later */
796void readSMBIOSInfo(SMBEntryPoint *eps)
797{
798uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
799SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
800
801int dimmnbr = 0;
802Platform.DMI.MaxMemorySlots= 0;
803Platform.DMI.CntMemorySlots= 0;
804Platform.DMI.MemoryModules= 0;
805
806for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
807{
808switch (structHeader->type)
809{
810case kSMBTypeSystemInformation:
811Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
812break;
813
814case kSMBTypePhysicalMemoryArray:
815Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
816break;
817
818case kSMBTypeMemoryDevice:
819Platform.DMI.CntMemorySlots++;
820if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
821Platform.DMI.MemoryModules++;
822if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
823Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
824dimmnbr++;
825break;
826}
827
828structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
829for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
830
831if (((uint16_t *)structPtr)[0] == 0)
832structPtr += 2;
833
834structHeader = (SMBStructHeader *)structPtr;
835}
836}
837
838

Archive Download this file

Revision: 2249