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

Archive Download this file

Revision: 1031