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 = 0;
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)
445{
446SMBSetters[idx].getSMBValue((returnType *)&string);
447break;
448}
449if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))
450{
451string = *(SMBSetters[idx].defaultValue);
452break;
453}
454string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
455break;
456
457case kSMBByte:
458case kSMBWord:
459case kSMBDWord:
460//case kSMBQWord:
461if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))
462return true;
463else
464if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
465if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))
466return true;
467if (SMBSetters[idx].getSMBValue(value))
468return true;
469#if 0
470if (*(SMBSetters[idx].defaultValue))
471{
472value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
473return true;
474}
475#endif
476break;
477}
478
479if (SMBSetters[idx].valueType == kSMBString && string)
480setSMBStringForField(structPtr->new, string, &value->byte);
481
482return true;
483}
484
485//-------------------------------------------------------------------------------------------------------------------------
486// Apple Specific
487//-------------------------------------------------------------------------------------------------------------------------
488void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
489{
490return;
491}
492
493void addSMBMemorySPD(SMBStructPtrs *structPtr)
494{
495/* SPD data from Platform.RAM.spd */
496return;
497}
498
499void addSMBOemProcessorType(SMBStructPtrs *structPtr)
500{
501SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
502
503p->header.type= kSMBTypeOemProcessorType;
504p->header.length= sizeof(SMBOemProcessorType);
505p->header.handle= handle++;
506
507setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
508
509structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
510tableLength += sizeof(SMBOemProcessorType) + 2;
511structureCount++;
512}
513
514void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
515{
516SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
517
518p->header.type= kSMBTypeOemProcessorBusSpeed;
519p->header.length= sizeof(SMBOemProcessorBusSpeed);
520p->header.handle= handle++;
521
522setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
523
524structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
525tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
526structureCount++;
527}
528
529//-------------------------------------------------------------------------------------------------------------------------
530// EndOfTable
531//-------------------------------------------------------------------------------------------------------------------------
532void addSMBEndOfTable(SMBStructPtrs *structPtr)
533{
534structPtr->new->type= kSMBTypeEndOfTable;
535structPtr->new->length= sizeof(SMBStructHeader);
536structPtr->new->handle= handle++;
537
538structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
539tableLength += sizeof(SMBStructHeader) + 2;
540structureCount++;
541}
542
543void setSMBStruct(SMBStructPtrs *structPtr)
544{
545bool setterFound = false;
546
547uint8_t *ptr;
548SMBWord structSize;
549int i;
550
551stringIndex = 1;
552stringsSize = 0;
553
554if (handle < structPtr->orig->handle)
555handle = structPtr->orig->handle;
556
557memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
558
559for (i = 0; i < numOfSetters; i++)
560if (structPtr->orig->type == SMBSetters[i].type)
561{
562setterFound = true;
563setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
564}
565
566if (setterFound)
567{
568ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
569for (; ((uint16_t *)ptr)[0] != 0; ptr++);
570
571if (((uint16_t *)ptr)[0] == 0)
572ptr += 2;
573
574structSize = ptr - (uint8_t *)structPtr->new;
575}
576else
577{
578ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
579for (; ((uint16_t *)ptr)[0] != 0; ptr++);
580
581if (((uint16_t *)ptr)[0] == 0)
582ptr += 2;
583
584structSize = ptr - (uint8_t *)structPtr->orig;
585memcpy((void *)structPtr->new, structPtr->orig, structSize);
586}
587
588structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
589
590tableLength += structSize;
591
592if (structSize > maxStructSize)
593maxStructSize = structSize;
594
595structureCount++;
596}
597
598void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
599{
600uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
601structPtr->orig = (SMBStructHeader *)ptr;
602
603for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
604{
605switch (structPtr->orig->type)
606{
607/* Skip all Apple Specific Structures */
608case kSMBTypeFirmwareVolume:
609case kSMBTypeMemorySPD:
610case kSMBTypeOemProcessorType:
611case kSMBTypeOemProcessorBusSpeed:
612/* And this one too, to be added at the end */
613case kSMBTypeEndOfTable:
614break;
615
616default:
617/* Add */
618setSMBStruct(structPtr);
619break;
620}
621
622ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
623for (; ((uint16_t *)ptr)[0] != 0; ptr++);
624
625if (((uint16_t *)ptr)[0] == 0)
626ptr += 2;
627
628structPtr->orig = (SMBStructHeader *)ptr;
629}
630
631addSMBFirmwareVolume(structPtr);
632addSMBMemorySPD(structPtr);
633addSMBOemProcessorType(structPtr);
634addSMBOemProcessorBusSpeed(structPtr);
635
636addSMBEndOfTable(structPtr);
637}
638
639void setupSMBIOSTable(void)
640{
641SMBStructPtrs *structPtr;
642uint8_t *buffer;
643bool setSMB = true;
644
645if (!origeps)
646return;
647
648neweps = origeps;
649
650structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
651if (!structPtr)
652return;
653
654buffer = malloc(SMB_ALLOC_SIZE);
655if (!buffer)
656return;
657
658bzero(buffer, SMB_ALLOC_SIZE);
659structPtr->new = (SMBStructHeader *)buffer;
660
661getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->bootConfig);
662if (setSMB)
663setDefaultSMBData();
664
665setupNewSMBIOSTable(origeps, structPtr);
666
667neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
668if (!neweps)
669return;
670bzero(neweps, sizeof(SMBEntryPoint));
671
672neweps->anchor[0]= '_';
673neweps->anchor[1]= 'S';
674neweps->anchor[2]= 'M';
675neweps->anchor[3]= '_';
676neweps->entryPointLength= sizeof(SMBEntryPoint);
677neweps->majorVersion= 2;
678neweps->minorVersion= 4;
679neweps->maxStructureSize= maxStructSize;
680neweps->entryPointRevision= 0;
681
682neweps->dmi.anchor[0]= '_';
683neweps->dmi.anchor[1]= 'D';
684neweps->dmi.anchor[2]= 'M';
685neweps->dmi.anchor[3]= 'I';
686neweps->dmi.anchor[4]= '_';
687neweps->dmi.tableLength= tableLength;
688neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
689neweps->dmi.structureCount= structureCount;
690neweps->dmi.bcdRevision= 0x24;
691
692if (!neweps->dmi.tableAddress)
693return;
694
695memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
696
697neweps->dmi.checksum= 0;
698neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
699
700neweps->checksum= 0;
701neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
702
703free(buffer);
704decodeSMBIOSTable(neweps);
705}
706
707void *getSmbios(int which)
708{
709switch (which)
710{
711case SMBIOS_ORIGINAL:
712if (!origeps)
713origeps = getAddressOfSmbiosTable();
714return origeps;
715case SMBIOS_PATCHED:
716return neweps;
717}
718
719return 0;
720}
721
722/* Collect any information needed later */
723void readSMBIOSInfo(SMBEntryPoint *eps)
724{
725uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
726SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
727
728int dimmnbr = 0;
729Platform.DMI.MaxMemorySlots= 0;
730Platform.DMI.CntMemorySlots= 0;
731Platform.DMI.MemoryModules= 0;
732
733for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
734{
735switch (structHeader->type)
736{
737case kSMBTypeSystemInformation:
738Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
739break;
740
741case kSMBTypePhysicalMemoryArray:
742Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
743break;
744
745case kSMBTypeMemoryDevice:
746Platform.DMI.CntMemorySlots++;
747 if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
748Platform.DMI.MemoryModules++;
749 if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
750Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
751dimmnbr++;
752break;
753}
754
755structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
756for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
757
758if (((uint16_t *)structPtr)[0] == 0)
759structPtr += 2;
760
761structHeader = (SMBStructHeader *)structPtr;
762}
763}
764
765

Archive Download this file

Revision: 443