Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/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.0809221748"
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,3"
96#define kDefaultiMacNehalemBIOSVersion" IM112.88Z.0057.B00.1005051455"
97// defaults for an iMac12,1
98#define kDefaultiMacSandy"iMac12,1"
99#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B1F.1223021756"
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.B08.1001221313"
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 kDefaultMacProWestmereBIOSReleaseDate"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// SystemEnclosure
205//-------------------------------------------------------------------------------------------------------------------------
206{kSMBTypeSystemEnclosure,kSMBString,getFieldOffset(SMBSystemEnclosure, manufacturer),
207kSMBBaseBoardManufacturerKey,NULL,&defaultBaseBoard.manufacturer},
208
209//-------------------------------------------------------------------------------------------------------------------------
210// ProcessorInformation
211//-------------------------------------------------------------------------------------------------------------------------
212{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, socketDesignation),NULL,NULL,NULL},
213
214{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, manufacturer),NULL,NULL,NULL},
215
216{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, processorVersion),NULL,NULL,NULL},
217
218{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, externalClock),kSMBProcessorInformationExternalClockKey,
219getProcessorInformationExternalClock,NULL},
220
221{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, maximumClock),kSMBProcessorInformationMaximumClockKey,
222getProcessorInformationMaximumClock,NULL},
223
224{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, serialNumber),NULL,NULL,NULL},
225
226{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, assetTag),NULL,NULL,NULL},
227
228{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, partNumber),NULL,NULL,NULL},
229
230//-------------------------------------------------------------------------------------------------------------------------
231// Memory Device
232//-------------------------------------------------------------------------------------------------------------------------
233{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, deviceLocator),kSMBMemoryDeviceDeviceLocatorKey,
234NULL,NULL},
235
236{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, bankLocator),kSMBMemoryDeviceBankLocatorKey,
237NULL,NULL},
238
239{kSMBTypeMemoryDevice,kSMBByte,getFieldOffset(SMBMemoryDevice, memoryType),kSMBMemoryDeviceMemoryTypeKey,
240getSMBMemoryDeviceMemoryType,NULL},
241
242{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, memorySpeed),kSMBMemoryDeviceMemorySpeedKey,
243getSMBMemoryDeviceMemorySpeed,NULL},
244
245{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, manufacturer),kSMBMemoryDeviceManufacturerKey,
246getSMBMemoryDeviceManufacturer,NULL},
247
248{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, serialNumber),kSMBMemoryDeviceSerialNumberKey,
249getSMBMemoryDeviceSerialNumber,NULL},
250
251{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, assetTag),NULL,NULL,NULL},
252
253{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, errorHandle), NULL, getSMBMemoryDeviceMemoryErrorHandle, NULL},
254
255{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, partNumber),kSMBMemoryDevicePartNumberKey,
256getSMBMemoryDevicePartNumber,NULL},
257
258
259//-------------------------------------------------------------------------------------------------------------------------
260// Apple Specific
261//-------------------------------------------------------------------------------------------------------------------------
262{kSMBTypeOemProcessorType,kSMBWord,getFieldOffset(SMBOemProcessorType, ProcessorType),kSMBOemProcessorTypeKey,
263getSMBOemProcessorType,NULL},
264
265{kSMBTypeOemProcessorBusSpeed,kSMBWord,getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),kSMBOemProcessorBusSpeedKey,
266getSMBOemProcessorBusSpeed,NULL}
267};
268
269int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);
270
271
272SMBEntryPoint *origeps= 0;
273SMBEntryPoint *neweps= 0;
274
275static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
276static uint8_t stringsSize;// add string size
277
278static SMBWord tableLength= 0;
279static SMBWord handle= 0;
280static SMBWord maxStructSize= 0;
281static SMBWord structureCount= 0;
282
283/* Rewrite this function */
284void setDefaultSMBData(void)
285{
286defaultBIOSInfo.vendor= kDefaultVendorManufacturer;
287defaultBIOSInfo.releaseDate= kDefaultBIOSReleaseDate;
288
289defaultSystemInfo.manufacturer= kDefaultVendorManufacturer;
290defaultSystemInfo.version= kDefaultSystemVersion;
291defaultSystemInfo.serialNumber= kDefaultSerialNumber;
292
293defaultBaseBoard.manufacturer= kDefaultVendorManufacturer;
294defaultBaseBoard.product= kDefaultBoardProduct;
295
296if (platformCPUFeature(CPU_FEATURE_MOBILE))
297{
298if (Platform.CPU.NoCores > 1)
299{
300defaultBIOSInfo.version= kDefaultMacBookProBIOSVersion;
301defaultSystemInfo.productName= kDefaultMacBookPro;
302defaultSystemInfo.family= kDefaultMacBookProFamily;
303}
304else
305{
306defaultBIOSInfo.version= kDefaultMacBookBIOSVersion;
307defaultSystemInfo.productName= kDefaultMacBook;
308defaultSystemInfo.family= kDefaultMacBookFamily;
309}
310}
311else
312{
313switch (Platform.CPU.NoCores)
314{
315case 1:
316defaultBIOSInfo.version= kDefaultMacminiBIOSVersion;
317defaultSystemInfo.productName= kDefaultMacmini;
318defaultSystemInfo.family= kDefaultMacminiFamily;
319break;
320
321case 2:
322defaultBIOSInfo.version= kDefaultiMacBIOSVersion;
323defaultSystemInfo.productName= kDefaultiMac;
324defaultSystemInfo.family= kDefaultiMacFamily;
325break;
326default:
327{
328switch (Platform.CPU.Family)
329{
330case 0x06:
331{
332switch (Platform.CPU.Model)
333{
334case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
335case CPU_MODEL_DALES:
336case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
337defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
338defaultSystemInfo.productName= kDefaultiMacNehalem;
339defaultSystemInfo.family= kDefaultiMacFamily;
340break;
341
342case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
343case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
344case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
345defaultBIOSInfo.version= kDefaultiMacSandyBIOSVersion;
346defaultSystemInfo.productName= kDefaultiMacSandy;
347defaultSystemInfo.family= kDefaultiMacFamily;
348break;
349case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
350case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
351defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
352defaultSystemInfo.productName= kDefaultMacProNehalem;
353defaultSystemInfo.family= kDefaultMacProFamily;
354break;
355
356case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
357case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
358defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
359defaultBIOSInfo.releaseDate= kDefaultMacProWestmereBIOSReleaseDate;
360defaultSystemInfo.productName= kDefaultMacProWestmere;
361defaultSystemInfo.family= kDefaultMacProFamily;
362break;
363
364default:
365defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
366defaultSystemInfo.productName= kDefaultMacPro;
367defaultSystemInfo.family= kDefaultMacProFamily;
368break;
369}
370break;
371}
372default:
373defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
374defaultSystemInfo.productName= kDefaultMacPro;
375defaultSystemInfo.family= kDefaultMacProFamily;
376break;
377}
378break;
379}
380}
381}
382}
383
384/* Used for SM*n smbios.plist keys */
385bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
386{
387static int idx = -1;
388static int current = -1;
389int len;
390char key[24];
391
392if (current != structHeader->handle)
393{
394idx++;
395current = structHeader->handle;
396}
397
398sprintf(key, "%s%d", keyString, idx);
399
400if (value)
401if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
402return true;
403else
404if (getValueForKey(key, string, &len, SMBPlist))
405return true;
406return false;
407}
408
409char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
410{
411uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
412
413if (!field)
414return NULL;
415
416for (field--; field != 0 && strlen((char *)stringPtr) > 0;
417field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
418
419return (char *)stringPtr;
420}
421
422void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
423{
424int strSize;
425
426if (!field)
427return;
428if (!string)
429{
430*field = 0;
431return;
432}
433
434strSize = strlen(string);
435
436// remove any spaces found at the end
437while ((strSize != 0) && (string[strSize - 1] == ' '))
438strSize--;
439
440if (strSize == 0)
441{
442*field = 0;
443return;
444}
445
446memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
447*field = stringIndex;
448
449stringIndex++;
450stringsSize += strSize + 1;
451}
452
453bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
454{
455const char *string = 0;
456int len;
457bool parsed;
458int val;
459
460if (numOfSetters <= idx)
461return false;
462
463switch (SMBSetters[idx].valueType)
464{
465case kSMBString:
466if (SMBSetters[idx].keyString)
467{
468if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
469break;
470else
471if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
472if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
473break;
474}
475if (SMBSetters[idx].getSMBValue)
476if (SMBSetters[idx].getSMBValue((returnType *)&string))
477break;
478if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))
479{
480string = *(SMBSetters[idx].defaultValue);
481break;
482}
483string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
484break;
485
486case kSMBByte:
487case kSMBWord:
488case kSMBDWord:
489//case kSMBQWord:
490if (SMBSetters[idx].keyString)
491{
492parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
493if (!parsed)
494if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
495parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
496if (parsed)
497{
498switch (SMBSetters[idx].valueType)
499{
500case kSMBByte:
501value->byte = (uint8_t)val;
502break;
503case kSMBWord:
504value->word = (uint16_t)val;
505break;
506case kSMBDWord:
507default:
508value->dword = (uint32_t)val;
509break;
510}
511return true;
512}
513}
514
515if (SMBSetters[idx].getSMBValue)
516if (SMBSetters[idx].getSMBValue(value))
517return true;
518#if 0
519if (*(SMBSetters[idx].defaultValue))
520{
521value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
522return true;
523}
524#endif
525break;
526}
527
528if (SMBSetters[idx].valueType == kSMBString && string)
529setSMBStringForField(structPtr->new, string, &value->byte);
530
531return true;
532}
533
534//-------------------------------------------------------------------------------------------------------------------------
535// Apple Specific
536//-------------------------------------------------------------------------------------------------------------------------
537void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
538{
539return;
540}
541
542void addSMBMemorySPD(SMBStructPtrs *structPtr)
543{
544/* SPD data from Platform.RAM.spd */
545return;
546}
547
548void addSMBOemProcessorType(SMBStructPtrs *structPtr)
549{
550SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
551
552p->header.type= kSMBTypeOemProcessorType;
553p->header.length= sizeof(SMBOemProcessorType);
554p->header.handle= handle++;
555
556setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
557
558structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
559tableLength += sizeof(SMBOemProcessorType) + 2;
560structureCount++;
561}
562
563void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
564{
565SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
566
567switch (Platform.CPU.Family)
568{
569case 0x06:
570{
571switch (Platform.CPU.Model)
572{
573case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
574case CPU_MODEL_DALES:
575case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
576case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
577case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
578case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
579case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
580case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
581case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
582case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
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

Archive Download this file

Revision: 2004