Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 840