Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1595