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// 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 LGA1156 (45nm)
344case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) ???
345case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)
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:
354case CPU_MODEL_SANDY_XEON:
355defaultBIOSInfo.version= kDefaultiMacSandyBIOSVersion;
356defaultSystemInfo.productName= kDefaultiMacSandy;
357defaultSystemInfo.family= kDefaultiMacFamily;
358defaultBaseBoard.product= kDefaultiMacSandyBoardProduct; // ??
359break;
360case CPU_MODEL_NEHALEM:
361case CPU_MODEL_NEHALEM_EX:
362defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
363defaultSystemInfo.productName= kDefaultMacProNehalem;
364defaultSystemInfo.family= kDefaultMacProFamily;
365defaultBaseBoard.product= kDefaultMacProNehalemBoardProduct;
366break;
367
368case CPU_MODEL_WESTMERE:
369case CPU_MODEL_WESTMERE_EX:
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 (char *)0;
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 (string[strSize - 1] == ' ')
453strSize--;
454
455memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
456*field = stringIndex;
457
458stringIndex++;
459stringsSize += strSize + 1;
460}
461
462bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
463{
464const char *string = 0;
465int len;
466
467if (numOfSetters <= idx)
468return false;
469
470switch (SMBSetters[idx].valueType)
471{
472case kSMBString:
473if (SMBSetters[idx].keyString)
474{
475if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
476break;
477else
478if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
479if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
480break;
481}
482if (SMBSetters[idx].getSMBValue)
483if (SMBSetters[idx].getSMBValue((returnType *)&string))
484break;
485if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))
486{
487string = *(SMBSetters[idx].defaultValue);
488break;
489}
490string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
491break;
492
493case kSMBByte:
494case kSMBWord:
495case kSMBDWord:
496//case kSMBQWord:
497if (SMBSetters[idx].keyString)
498{
499if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))
500return true;
501else
502if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
503if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))
504return true;
505}
506if (SMBSetters[idx].getSMBValue)
507if (SMBSetters[idx].getSMBValue(value))
508return true;
509#if 0
510if (*(SMBSetters[idx].defaultValue))
511{
512value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
513return true;
514}
515#endif
516break;
517}
518
519if (SMBSetters[idx].valueType == kSMBString && string)
520setSMBStringForField(structPtr->new, string, &value->byte);
521
522return true;
523}
524
525//-------------------------------------------------------------------------------------------------------------------------
526// Apple Specific
527//-------------------------------------------------------------------------------------------------------------------------
528void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
529{
530return;
531}
532
533void addSMBMemorySPD(SMBStructPtrs *structPtr)
534{
535/* SPD data from Platform.RAM.spd */
536return;
537}
538
539void addSMBOemProcessorType(SMBStructPtrs *structPtr)
540{
541SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
542
543p->header.type= kSMBTypeOemProcessorType;
544p->header.length= sizeof(SMBOemProcessorType);
545p->header.handle= handle++;
546
547setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
548
549structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
550tableLength += sizeof(SMBOemProcessorType) + 2;
551structureCount++;
552}
553
554void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
555{
556SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
557
558switch (Platform.CPU.Family)
559{
560case 0x06:
561{
562switch (Platform.CPU.Model)
563{
564case 0x19:// Intel Core i5 650 @3.20 Ghz
565case CPU_MODEL_FIELDS:// Intel Core i5, i7 LGA1156 (45nm)
566case CPU_MODEL_DALES:// Intel Core i5, i7 LGA1156 (45nm) ???
567case CPU_MODEL_DALES_32NM:// Intel Core i3, i5, i7 LGA1156 (32nm)
568case CPU_MODEL_NEHALEM:// Intel Core i7 LGA1366 (45nm)
569case CPU_MODEL_NEHALEM_EX:// Intel Core i7 LGA1366 (45nm) 6 Core ???
570case CPU_MODEL_WESTMERE:// Intel Core i7 LGA1366 (32nm) 6 Core
571case CPU_MODEL_WESTMERE_EX: // Intel Core i7 LGA1366 (45nm) 6 Core ???
572break;
573default:
574return;
575}
576}
577}
578
579p->header.type= kSMBTypeOemProcessorBusSpeed;
580p->header.length= sizeof(SMBOemProcessorBusSpeed);
581p->header.handle= handle++;
582
583setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
584
585structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
586tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
587structureCount++;
588}
589
590//-------------------------------------------------------------------------------------------------------------------------
591// EndOfTable
592//-------------------------------------------------------------------------------------------------------------------------
593void addSMBEndOfTable(SMBStructPtrs *structPtr)
594{
595structPtr->new->type= kSMBTypeEndOfTable;
596structPtr->new->length= sizeof(SMBStructHeader);
597structPtr->new->handle= handle++;
598
599structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
600tableLength += sizeof(SMBStructHeader) + 2;
601structureCount++;
602}
603
604void setSMBStruct(SMBStructPtrs *structPtr)
605{
606bool setterFound = false;
607
608uint8_t *ptr;
609SMBWord structSize;
610int i;
611
612stringIndex = 1;
613stringsSize = 0;
614
615if (handle < structPtr->orig->handle)
616handle = structPtr->orig->handle;
617
618memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
619
620for (i = 0; i < numOfSetters; i++)
621if (structPtr->orig->type == SMBSetters[i].type)
622{
623if (SMBSetters[i].fieldOffset > structPtr->orig->length)
624continue;
625setterFound = true;
626setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
627}
628
629if (setterFound)
630{
631ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
632for (; ((uint16_t *)ptr)[0] != 0; ptr++);
633
634if (((uint16_t *)ptr)[0] == 0)
635ptr += 2;
636
637structSize = ptr - (uint8_t *)structPtr->new;
638}
639else
640{
641ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
642for (; ((uint16_t *)ptr)[0] != 0; ptr++);
643
644if (((uint16_t *)ptr)[0] == 0)
645ptr += 2;
646
647structSize = ptr - (uint8_t *)structPtr->orig;
648memcpy((void *)structPtr->new, structPtr->orig, structSize);
649}
650
651structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
652
653tableLength += structSize;
654
655if (structSize > maxStructSize)
656maxStructSize = structSize;
657
658structureCount++;
659}
660
661void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
662{
663uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
664structPtr->orig = (SMBStructHeader *)ptr;
665
666for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
667{
668switch (structPtr->orig->type)
669{
670/* Skip all Apple Specific Structures */
671case kSMBTypeFirmwareVolume:
672case kSMBTypeMemorySPD:
673case kSMBTypeOemProcessorType:
674case kSMBTypeOemProcessorBusSpeed:
675/* And this one too, to be added at the end */
676case kSMBTypeEndOfTable:
677break;
678
679default:
680/* Add */
681setSMBStruct(structPtr);
682break;
683}
684
685ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
686for (; ((uint16_t *)ptr)[0] != 0; ptr++);
687
688if (((uint16_t *)ptr)[0] == 0)
689ptr += 2;
690
691structPtr->orig = (SMBStructHeader *)ptr;
692}
693
694addSMBFirmwareVolume(structPtr);
695addSMBMemorySPD(structPtr);
696addSMBOemProcessorType(structPtr);
697addSMBOemProcessorBusSpeed(structPtr);
698
699addSMBEndOfTable(structPtr);
700}
701
702void setupSMBIOSTable(void)
703{
704SMBStructPtrs *structPtr;
705uint8_t *buffer;
706bool setSMB = true;
707
708if (!origeps)
709return;
710
711neweps = origeps;
712
713structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
714if (!structPtr)
715return;
716
717buffer = malloc(SMB_ALLOC_SIZE);
718if (!buffer)
719return;
720
721bzero(buffer, SMB_ALLOC_SIZE);
722structPtr->new = (SMBStructHeader *)buffer;
723
724getBoolForKey(kSMBIOSdefaultsKey, &setSMB, &bootInfo->bootConfig);
725if (setSMB)
726setDefaultSMBData();
727
728setupNewSMBIOSTable(origeps, structPtr);
729
730neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
731if (!neweps)
732return;
733bzero(neweps, sizeof(SMBEntryPoint));
734
735neweps->anchor[0]= '_';
736neweps->anchor[1]= 'S';
737neweps->anchor[2]= 'M';
738neweps->anchor[3]= '_';
739neweps->entryPointLength= sizeof(SMBEntryPoint);
740neweps->majorVersion= 2;
741neweps->minorVersion= 4;
742neweps->maxStructureSize= maxStructSize;
743neweps->entryPointRevision= 0;
744
745neweps->dmi.anchor[0]= '_';
746neweps->dmi.anchor[1]= 'D';
747neweps->dmi.anchor[2]= 'M';
748neweps->dmi.anchor[3]= 'I';
749neweps->dmi.anchor[4]= '_';
750neweps->dmi.tableLength= tableLength;
751neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
752neweps->dmi.structureCount= structureCount;
753neweps->dmi.bcdRevision= 0x24;
754
755if (!neweps->dmi.tableAddress)
756return;
757
758memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
759
760neweps->dmi.checksum= 0;
761neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
762
763neweps->checksum= 0;
764neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
765
766free(buffer);
767decodeSMBIOSTable(neweps);
768}
769
770void *getSmbios(int which)
771{
772switch (which)
773{
774case SMBIOS_ORIGINAL:
775if (!origeps)
776origeps = getAddressOfSmbiosTable();
777return origeps;
778case SMBIOS_PATCHED:
779return neweps;
780}
781
782return 0;
783}
784
785/* Collect any information needed later */
786void readSMBIOSInfo(SMBEntryPoint *eps)
787{
788uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
789SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
790
791int dimmnbr = 0;
792Platform.DMI.MaxMemorySlots= 0;
793Platform.DMI.CntMemorySlots= 0;
794Platform.DMI.MemoryModules= 0;
795
796for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
797{
798switch (structHeader->type)
799{
800case kSMBTypeSystemInformation:
801Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
802break;
803
804case kSMBTypePhysicalMemoryArray:
805Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
806break;
807
808case kSMBTypeMemoryDevice:
809Platform.DMI.CntMemorySlots++;
810if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
811Platform.DMI.MemoryModules++;
812if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
813Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
814dimmnbr++;
815break;
816}
817
818structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
819for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
820
821if (((uint16_t *)structPtr)[0] == 0)
822structPtr += 2;
823
824structHeader = (SMBStructHeader *)structPtr;
825}
826}
827
828

Archive Download this file

Revision: 870