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

Archive Download this file

Revision: 1468