Chameleon

Chameleon Svn Source Tree

Root/branches/Kabyl/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"Macmini2,1"
78#define kDefaultMacminiBIOSVersion" MM21.88Z.009A.B00.0903051113"
79
80// defaults for a MacBook
81#define kDefaultMacBookFamily"MacBook"
82#define kDefaultMacBook"MacBook4,1"
83#define kDefaultMacBookBIOSVersion" MB41.88Z.0073.B00.0903051113"
84
85// defaults for a MacBook Pro
86#define kDefaultMacBookProFamily"MacBookPro"
87#define kDefaultMacBookPro"MacBookPro4,1"
88#define kDefaultMacBookProBIOSVersion" MBP41.88Z.0073.B00.0903051113"
89
90// defaults for an iMac
91#define kDefaultiMacFamily"iMac"
92#define kDefaultiMac"iMac8,1"
93#define kDefaultiMacBIOSVersion" IM81.88Z.00C1.B00.0903051113"
94// defaults for an iMac11,1 core i3/i5/i7
95#define kDefaultiMacNehalem"iMac11,1"
96#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B00.0903051113"
97
98// defaults for a Mac Pro
99#define kDefaultMacProFamily"MacPro"
100#define kDefaultMacPro"MacPro3,1"
101#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
102// defaults for a Mac Pro 4,1 core i7/Xeon
103#define kDefaultMacProNehalem"MacPro4,1"
104#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B04.0903051113"
105// defaults for a Mac Pro 5,1 core i7/Xeon
106#define kDefaultMacProWestmere"MacPro5,1"
107#define kDefaultMacProWestmereBIOSVersion" MP51.88Z.007F.B00.1008031144"
108#define kDefaulMacProWestmereBIOSReleaseDate"08/03/10"
109//-------------------------------------------------------------------------------------------------------------------------
110
111
112#define getFieldOffset(struct, field)((uint8_t)(uint32_t)&(((struct *)0)->field))
113
114typedef struct {
115SMBStructHeader *orig;
116SMBStructHeader *new;
117} SMBStructPtrs;
118
119struct {
120char *vendor;
121char *version;
122char *releaseDate;
123} defaultBIOSInfo;
124
125struct {
126char *manufacturer;
127char *productName;
128char *version;
129char *serialNumber;
130char *family;
131} defaultSystemInfo;
132
133struct {
134char *manufacturer;
135char *product;
136} defaultBaseBoard;
137
138
139typedef struct {
140uint8_ttype;
141SMBValueTypevalueType;
142uint8_tfieldOffset;
143char*keyString;
144bool(*getSMBValue)(returnType *);
145char**defaultValue;
146} SMBValueSetter;
147
148SMBValueSetter SMBSetters[] =
149{
150//-------------------------------------------------------------------------------------------------------------------------
151// BIOSInformation
152//-------------------------------------------------------------------------------------------------------------------------
153{kSMBTypeBIOSInformation,kSMBString,getFieldOffset(SMBBIOSInformation, vendor),kSMBBIOSInformationVendorKey,
154NULL,&defaultBIOSInfo.vendor},
155
156{kSMBTypeBIOSInformation,kSMBString,getFieldOffset(SMBBIOSInformation, version),kSMBBIOSInformationVersionKey,
157NULL,&defaultBIOSInfo.version},
158
159{kSMBTypeBIOSInformation,kSMBString,getFieldOffset(SMBBIOSInformation, releaseDate),kSMBBIOSInformationReleaseDateKey,
160NULL,&defaultBIOSInfo.releaseDate},
161
162//-------------------------------------------------------------------------------------------------------------------------
163// SystemInformation
164//-------------------------------------------------------------------------------------------------------------------------
165{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, manufacturer),kSMBSystemInformationManufacturerKey,
166NULL,&defaultSystemInfo.manufacturer},
167
168{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, productName),kSMBSystemInformationProductNameKey,
169NULL,&defaultSystemInfo.productName},
170
171{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, version),kSMBSystemInformationVersionKey,
172NULL,&defaultSystemInfo.version},
173
174{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, serialNumber),kSMBSystemInformationSerialNumberKey,
175NULL,&defaultSystemInfo.serialNumber},
176
177{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, skuNumber),NULL,
178NULL,NULL},
179
180{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, family),kSMBSystemInformationFamilyKey,
181NULL,&defaultSystemInfo.family},
182
183
184//-------------------------------------------------------------------------------------------------------------------------
185// BaseBoard
186//-------------------------------------------------------------------------------------------------------------------------
187{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, manufacturer),kSMBBaseBoardManufacturerKey,
188NULL,&defaultBaseBoard.manufacturer},
189
190{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, product),kSMBBaseBoardProductKey,
191NULL,&defaultBaseBoard.product},
192
193 {kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, version),NULL,NULL,NULL},
194
195 {kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, serialNumber),NULL,NULL,NULL},
196
197 {kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, assetTagNumber),NULL,NULL,NULL},
198
199 {kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, locationInChassis),NULL,NULL,NULL},
200
201
202//-------------------------------------------------------------------------------------------------------------------------
203// ProcessorInformation
204//-------------------------------------------------------------------------------------------------------------------------
205{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, socketDesignation),NULL,NULL,NULL},
206
207{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, manufacturer),NULL,NULL,NULL},
208
209{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, processorVersion),NULL,NULL,NULL},
210
211{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, externalClock),kSMBProcessorInformationExternalClockKey,
212getProcessorInformationExternalClock,NULL},
213
214{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, maximumClock),kSMBProcessorInformationMaximumClockKey,
215getProcessorInformationMaximumClock,NULL},
216
217{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, serialNumber),NULL,NULL,NULL},
218
219{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, assetTag),NULL,NULL,NULL},
220
221{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, partNumber),NULL,NULL,NULL},
222
223//-------------------------------------------------------------------------------------------------------------------------
224// Memory Device
225//-------------------------------------------------------------------------------------------------------------------------
226{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, deviceLocator),kSMBMemoryDeviceDeviceLocatorKey,
227NULL,NULL},
228
229{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, bankLocator),kSMBMemoryDeviceBankLocatorKey,
230NULL,NULL},
231
232{kSMBTypeMemoryDevice,kSMBByte,getFieldOffset(SMBMemoryDevice, memoryType),kSMBMemoryDeviceMemoryTypeKey,
233getSMBMemoryDeviceMemoryType,NULL},
234
235{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, memorySpeed),kSMBMemoryDeviceMemorySpeedKey,
236getSMBMemoryDeviceMemorySpeed,NULL},
237
238{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, manufacturer),kSMBMemoryDeviceManufacturerKey,
239getSMBMemoryDeviceManufacturer,NULL},
240
241{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, serialNumber),kSMBMemoryDeviceSerialNumberKey,
242getSMBMemoryDeviceSerialNumber,NULL},
243
244{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, assetTag),NULL,NULL,NULL},
245
246{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, partNumber),kSMBMemoryDevicePartNumberKey,
247getSMBMemoryDevicePartNumber,NULL},
248
249
250//-------------------------------------------------------------------------------------------------------------------------
251// Apple Specific
252//-------------------------------------------------------------------------------------------------------------------------
253{kSMBTypeOemProcessorType,kSMBWord,getFieldOffset(SMBOemProcessorType, ProcessorType),kSMBOemProcessorTypeKey,
254getSMBOemProcessorType,NULL},
255
256{kSMBTypeOemProcessorBusSpeed,kSMBWord,getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),kSMBOemProcessorBusSpeedKey,
257getSMBOemProcessorBusSpeed,NULL}
258};
259
260int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);
261
262
263SMBEntryPoint *origeps= 0;
264SMBEntryPoint *neweps= 0;
265
266static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
267static uint8_t stringsSize;// add string size
268
269static SMBWord tableLength= 0;
270static SMBWord handle= 0;
271static SMBWord maxStructSize= 0;
272static SMBWord structureCount= 0;
273
274/* Rewrite this function */
275void setDefaultSMBData(void)
276{
277defaultBIOSInfo.vendor= kDefaultVendorManufacturer;
278defaultBIOSInfo.releaseDate= kDefaultBIOSReleaseDate;
279
280defaultSystemInfo.manufacturer= kDefaultVendorManufacturer;
281defaultSystemInfo.version= kDefaultSystemVersion;
282defaultSystemInfo.serialNumber= kDefaultSerialNumber;
283
284defaultBaseBoard.manufacturer= kDefaultVendorManufacturer;
285defaultBaseBoard.product= kDefaultBoardProduct;
286
287if (platformCPUFeature(CPU_FEATURE_MOBILE))
288{
289if (Platform.CPU.NoCores > 1)
290{
291defaultBIOSInfo.version= kDefaultMacBookProBIOSVersion;
292defaultSystemInfo.productName= kDefaultMacBookPro;
293defaultSystemInfo.family= kDefaultMacBookProFamily;
294}
295else
296{
297defaultBIOSInfo.version= kDefaultMacBookBIOSVersion;
298defaultSystemInfo.productName= kDefaultMacBook;
299defaultSystemInfo.family= kDefaultMacBookFamily;
300}
301}
302else
303{
304switch (Platform.CPU.NoCores)
305{
306case 1:
307defaultBIOSInfo.version= kDefaultMacminiBIOSVersion;
308defaultSystemInfo.productName= kDefaultMacmini;
309defaultSystemInfo.family= kDefaultMacminiFamily;
310break;
311
312case 2:
313defaultBIOSInfo.version= kDefaultiMacBIOSVersion;
314defaultSystemInfo.productName= kDefaultiMac;
315defaultSystemInfo.family= kDefaultiMacFamily;
316break;
317default:
318{
319switch (Platform.CPU.Family)
320{
321case 0x06:
322{
323switch (Platform.CPU.Model)
324{
325case CPU_MODEL_FIELDS:// Intel Core i5, i7 LGA1156 (45nm)
326case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) ???
327case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)
328case 0x19:// Intel Core i5 650 @3.20 Ghz
329defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
330defaultSystemInfo.productName= kDefaultiMacNehalem;
331defaultSystemInfo.family= kDefaultiMacFamily;
332break;
333
334case CPU_MODEL_NEHALEM:
335case CPU_MODEL_NEHALEM_EX:
336defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
337defaultSystemInfo.productName= kDefaultMacProNehalem;
338defaultSystemInfo.family= kDefaultMacProFamily;
339break;
340
341case CPU_MODEL_WESTMERE:
342case CPU_MODEL_WESTMERE_EX:
343defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
344defaultBIOSInfo.releaseDate= kDefaulMacProWestmereBIOSReleaseDate;
345defaultSystemInfo.productName= kDefaultMacProWestmere;
346defaultSystemInfo.family= kDefaultMacProFamily;
347break;
348
349default:
350defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
351defaultSystemInfo.productName= kDefaultMacPro;
352defaultSystemInfo.family= kDefaultMacProFamily;
353break;
354}
355break;
356}
357default:
358defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
359defaultSystemInfo.productName= kDefaultMacPro;
360defaultSystemInfo.family= kDefaultMacProFamily;
361break;
362}
363break;
364}
365}
366}
367}
368
369/* Used for SM*_N smbios.plist keys */
370bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
371{
372static int idx = -1;
373static int current = -1;
374int len;
375char key[24];
376
377if (current != structHeader->handle)
378{
379idx++;
380current = structHeader->handle;
381}
382
383sprintf(key, "%s%d", keyString, idx);
384
385if (value)
386if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
387return true;
388else
389if (getValueForKey(key, string, &len, SMBPlist))
390return true;
391return false;
392}
393
394char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
395{
396uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
397
398if (!field)
399return (char *)0;
400
401for (field--; field != 0 && strlen((char *)stringPtr) > 0;
402field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
403
404return (char *)stringPtr;
405}
406
407void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
408{
409if (!field)
410return;
411if (!string)
412{
413*field = 0;
414return;
415}
416
417int strSize = strlen(string) + 1;
418memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
419*field = stringIndex;
420
421stringIndex++;
422stringsSize += strSize;
423}
424
425bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
426{
427const char *string = 0;
428int len;
429
430if (numOfSetters <= idx)
431return false;
432
433switch (SMBSetters[idx].valueType)
434{
435case kSMBString:
436if (SMBSetters[idx].keyString)
437{
438if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
439break;
440if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
441if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
442break;
443}
444if (SMBSetters[idx].getSMBValue)
445if (SMBSetters[idx].getSMBValue((returnType *)&string))
446break;
447if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))
448{
449string = *(SMBSetters[idx].defaultValue);
450break;
451}
452string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
453break;
454
455case kSMBByte:
456case kSMBWord:
457case kSMBDWord:
458//case kSMBQWord:
459if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))
460return true;
461else
462if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
463if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))
464return true;
465if (SMBSetters[idx].getSMBValue(value))
466return true;
467#if 0
468if (*(SMBSetters[idx].defaultValue))
469{
470value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
471return true;
472}
473#endif
474break;
475}
476
477if (SMBSetters[idx].valueType == kSMBString && string)
478setSMBStringForField(structPtr->new, string, &value->byte);
479
480return true;
481}
482
483//-------------------------------------------------------------------------------------------------------------------------
484// Apple Specific
485//-------------------------------------------------------------------------------------------------------------------------
486void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
487{
488return;
489}
490
491void addSMBMemorySPD(SMBStructPtrs *structPtr)
492{
493/* SPD data from Platform.RAM.spd */
494return;
495}
496
497void addSMBOemProcessorType(SMBStructPtrs *structPtr)
498{
499SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
500
501p->header.type= kSMBTypeOemProcessorType;
502p->header.length= sizeof(SMBOemProcessorType);
503p->header.handle= handle++;
504
505setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
506
507structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
508tableLength += sizeof(SMBOemProcessorType) + 2;
509structureCount++;
510}
511
512void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
513{
514SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
515
516p->header.type= kSMBTypeOemProcessorBusSpeed;
517p->header.length= sizeof(SMBOemProcessorBusSpeed);
518p->header.handle= handle++;
519
520setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
521
522structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
523tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
524structureCount++;
525}
526
527//-------------------------------------------------------------------------------------------------------------------------
528// EndOfTable
529//-------------------------------------------------------------------------------------------------------------------------
530void addSMBEndOfTable(SMBStructPtrs *structPtr)
531{
532structPtr->new->type= kSMBTypeEndOfTable;
533structPtr->new->length= sizeof(SMBStructHeader);
534structPtr->new->handle= handle++;
535
536structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
537tableLength += sizeof(SMBStructHeader) + 2;
538structureCount++;
539}
540
541void setSMBStruct(SMBStructPtrs *structPtr)
542{
543bool setterFound = false;
544
545uint8_t *ptr;
546SMBWord structSize;
547int i;
548
549stringIndex = 1;
550stringsSize = 0;
551
552if (handle < structPtr->orig->handle)
553handle = structPtr->orig->handle;
554
555memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
556
557for (i = 0; i < numOfSetters; i++)
558if (structPtr->orig->type == SMBSetters[i].type)
559{
560setterFound = true;
561setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
562}
563
564if (setterFound)
565{
566ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
567for (; ((uint16_t *)ptr)[0] != 0; ptr++);
568
569if (((uint16_t *)ptr)[0] == 0)
570ptr += 2;
571
572structSize = ptr - (uint8_t *)structPtr->new;
573}
574else
575{
576ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
577for (; ((uint16_t *)ptr)[0] != 0; ptr++);
578
579if (((uint16_t *)ptr)[0] == 0)
580ptr += 2;
581
582structSize = ptr - (uint8_t *)structPtr->orig;
583memcpy((void *)structPtr->new, structPtr->orig, structSize);
584}
585
586structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
587
588tableLength += structSize;
589
590if (structSize > maxStructSize)
591maxStructSize = structSize;
592
593structureCount++;
594}
595
596void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
597{
598uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
599structPtr->orig = (SMBStructHeader *)ptr;
600
601for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
602{
603switch (structPtr->orig->type)
604{
605/* Skip all Apple Specific Structures */
606case kSMBTypeFirmwareVolume:
607case kSMBTypeMemorySPD:
608case kSMBTypeOemProcessorType:
609case kSMBTypeOemProcessorBusSpeed:
610/* And this one too, to be added at the end */
611case kSMBTypeEndOfTable:
612break;
613
614default:
615/* Add */
616setSMBStruct(structPtr);
617break;
618}
619
620ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
621for (; ((uint16_t *)ptr)[0] != 0; ptr++);
622
623if (((uint16_t *)ptr)[0] == 0)
624ptr += 2;
625
626structPtr->orig = (SMBStructHeader *)ptr;
627}
628
629addSMBFirmwareVolume(structPtr);
630addSMBMemorySPD(structPtr);
631addSMBOemProcessorType(structPtr);
632addSMBOemProcessorBusSpeed(structPtr);
633
634addSMBEndOfTable(structPtr);
635}
636
637void setupSMBIOSTable(void)
638{
639SMBStructPtrs *structPtr;
640uint8_t *buffer;
641bool setSMB = true;
642
643if (!origeps)
644return;
645
646neweps = origeps;
647
648structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
649if (!structPtr)
650return;
651
652buffer = malloc(SMB_ALLOC_SIZE);
653if (!buffer)
654return;
655
656bzero(buffer, SMB_ALLOC_SIZE);
657structPtr->new = (SMBStructHeader *)buffer;
658
659getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->bootConfig);
660if (setSMB)
661setDefaultSMBData();
662
663setupNewSMBIOSTable(origeps, structPtr);
664
665neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
666if (!neweps)
667return;
668bzero(neweps, sizeof(SMBEntryPoint));
669
670neweps->anchor[0]= '_';
671neweps->anchor[1]= 'S';
672neweps->anchor[2]= 'M';
673neweps->anchor[3]= '_';
674neweps->entryPointLength= sizeof(SMBEntryPoint);
675neweps->majorVersion= 2;
676neweps->minorVersion= 4;
677neweps->maxStructureSize= maxStructSize;
678neweps->entryPointRevision= 0;
679
680neweps->dmi.anchor[0]= '_';
681neweps->dmi.anchor[1]= 'D';
682neweps->dmi.anchor[2]= 'M';
683neweps->dmi.anchor[3]= 'I';
684neweps->dmi.anchor[4]= '_';
685neweps->dmi.tableLength= tableLength;
686neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
687neweps->dmi.structureCount= structureCount;
688neweps->dmi.bcdRevision= 0x24;
689
690if (!neweps->dmi.tableAddress)
691return;
692
693memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
694
695neweps->dmi.checksum= 0;
696neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
697
698neweps->checksum= 0;
699neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
700
701free(buffer);
702decodeSMBIOSTable(neweps);
703}
704
705void *getSmbios(int which)
706{
707switch (which)
708{
709case SMBIOS_ORIGINAL:
710if (!origeps)
711origeps = getAddressOfSmbiosTable();
712return origeps;
713case SMBIOS_PATCHED:
714return neweps;
715}
716
717return 0;
718}
719
720/* Collect any information needed later */
721void readSMBIOSInfo(SMBEntryPoint *eps)
722{
723uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
724SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
725
726int dimmnbr = 0;
727Platform.DMI.MaxMemorySlots= 0;
728Platform.DMI.CntMemorySlots= 0;
729Platform.DMI.MemoryModules= 0;
730
731for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
732{
733switch (structHeader->type)
734{
735case kSMBTypeSystemInformation:
736Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
737break;
738
739case kSMBTypePhysicalMemoryArray:
740Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
741break;
742
743case kSMBTypeMemoryDevice:
744Platform.DMI.CntMemorySlots++;
745 if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
746Platform.DMI.MemoryModules++;
747 if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
748Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
749dimmnbr++;
750break;
751}
752
753structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
754for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
755
756if (((uint16_t *)structPtr)[0] == 0)
757structPtr += 2;
758
759structHeader = (SMBStructHeader *)structPtr;
760}
761}
762
763

Archive Download this file

Revision: 585