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

Archive Download this file

Revision: 2049