-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathsmbios.cpp
2191 lines (2000 loc) · 81.3 KB
/
smbios.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
smbios.c
original idea of SMBIOS patching by mackerintel
implementation for UEFI smbios table patching
Slice 2011.
portion copyright Intel
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SmbiosGen.c
**/
#include "Platform.h"
#include "smbios.h"
#include "cpu.h"
#include "platformdata.h"
#include "AcpiPatcher.h"
#ifdef __cplusplus
extern "C" {
#include <Library/PrintLib.h>
}
#endif
#ifndef DEBUG_ALL
#define DEBUG_SMBIOS 1
#else
#define DEBUG_SMBIOS DEBUG_ALL
#endif
#if DEBUG_SMBIOS == 0
#define DBG(...)
#else
#define DBG(...) DebugLog(DEBUG_SMBIOS, __VA_ARGS__)
#endif
#define REMAP_SMBIOS_TABLE_GUID { 0xeb9d2d35, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
#define MAX_OEM_STRING 256
#define ROUND_PAGE(x) ((((unsigned)(x)) + EFI_PAGE_SIZE - 1) & ~(EFI_PAGE_SIZE - 1))
EFI_GUID *gTableGuidArray[] = {&gEfiSmbiosTableGuid, &gEfiSmbios3TableGuid};
const CHAR8 unknown[] = "unknown";
//
// syscl: implement Dell truncate fix
// remap EFI_SMBIOS_TABLE_1 to new guid to fix Dell
// SMBIOS Table 1 truncate issue credit David Passmore
//
EFI_GUID gRemapEfiSmbiosTableGuid = REMAP_SMBIOS_TABLE_GUID;
//EFI_PHYSICAL_ADDRESS *smbiosTable;
VOID *Smbios; //pointer to SMBIOS data
SMBIOS_TABLE_ENTRY_POINT *EntryPoint; //SmbiosEps original
SMBIOS_TABLE_ENTRY_POINT *SmbiosEpsNew; //new SmbiosEps
//for patching
APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTable;
APPLE_SMBIOS_STRUCTURE_POINTER newSmbiosTable;
UINT16 NumberOfRecords;
UINT16 MaxStructureSize;
UINT8* Current; //pointer to the current end of tables
EFI_SMBIOS_TABLE_HEADER *Record;
EFI_SMBIOS_HANDLE Handle;
EFI_SMBIOS_TYPE Type;
UINTN stringNumber;
UINTN TableSize;
UINTN Index, Size, NewSize, MaxSize;
UINT16 CoreCache = 0;
UINT16 TotalCount = 0;
UINT16 L1, L2, L3;
UINT32 MaxMemory = 0;
UINT32 mTotalSystemMemory;
UINT64 gTotalMemory;
UINT16 mHandle3;
UINT16 mHandle16 = 0x1000;
UINT16 mHandle17[MAX_RAM_SLOTS];
UINT16 mHandle19;
UINT16 mMemory17[MAX_RAM_SLOTS];
UINT64 mInstalled[MAX_RAM_SLOTS];
UINT64 mEnabled[MAX_RAM_SLOTS];
BOOLEAN gMobile;
UINT8 gBootStatus;
BOOLEAN Once;
MEM_STRUCTURE gRAM;
//DMI* gDMI;
UINT8 gRAMCount = 0;
#define MAX_HANDLE 0xFEFF
#define SMBIOS_PTR SIGNATURE_32('_','S','M','_')
#define MAX_TABLE_SIZE 512
#define smbios_offsetof(s,m) ( (SMBIOS_TABLE_STRING) ((UINT8*)&((s*)0)->m - (UINT8*)0))
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE0_STR_IDX[] = {
smbios_offsetof(SMBIOS_TABLE_TYPE0, Vendor),
smbios_offsetof(SMBIOS_TABLE_TYPE0, BiosVersion),
smbios_offsetof(SMBIOS_TABLE_TYPE0, BiosReleaseDate),
0x00
}; // offsets of structures that values are strings for type 0 Bios
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE1_STR_IDX[] = {
smbios_offsetof(SMBIOS_TABLE_TYPE1, Manufacturer),
smbios_offsetof(SMBIOS_TABLE_TYPE1, ProductName),
smbios_offsetof(SMBIOS_TABLE_TYPE1, Version),
smbios_offsetof(SMBIOS_TABLE_TYPE1, SerialNumber),
smbios_offsetof(SMBIOS_TABLE_TYPE1, SKUNumber),
smbios_offsetof(SMBIOS_TABLE_TYPE1, Family),
0x00
}; // offsets of structures that values are strings for type 1 System
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE2_STR_IDX[] = {
smbios_offsetof(SMBIOS_TABLE_TYPE2, Manufacturer),
smbios_offsetof(SMBIOS_TABLE_TYPE2, ProductName),
smbios_offsetof(SMBIOS_TABLE_TYPE2, Version),
smbios_offsetof(SMBIOS_TABLE_TYPE2, SerialNumber),
smbios_offsetof(SMBIOS_TABLE_TYPE2, AssetTag),
smbios_offsetof(SMBIOS_TABLE_TYPE2, LocationInChassis),
0x00
}; // offsets of structures that values are strings for type 2 BaseBoard
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE3_STR_IDX[] = {
smbios_offsetof(SMBIOS_TABLE_TYPE3, Manufacturer),
smbios_offsetof(SMBIOS_TABLE_TYPE3, Version),
smbios_offsetof(SMBIOS_TABLE_TYPE3, SerialNumber),
smbios_offsetof(SMBIOS_TABLE_TYPE3, AssetTag),
0x00
}; // offsets of structures that values are strings for type 3 Chassis
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE4_STR_IDX[] = {
smbios_offsetof(SMBIOS_TABLE_TYPE4, Socket),
smbios_offsetof(SMBIOS_TABLE_TYPE4, ProcessorManufacture),
smbios_offsetof(SMBIOS_TABLE_TYPE4, ProcessorVersion),
smbios_offsetof(SMBIOS_TABLE_TYPE4, SerialNumber),
smbios_offsetof(SMBIOS_TABLE_TYPE4, AssetTag),
smbios_offsetof(SMBIOS_TABLE_TYPE4, PartNumber),
0x00
}; // offsets of structures that values are strings for type 3 Chassis
/* Functions */
// validate the SMBIOS entry point structure
BOOLEAN IsEntryPointStructureValid (IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure)
{
UINTN I;
UINT8 Length;
UINT8 Checksum = 0;
UINT8 *BytePtr;
if (!EntryPointStructure)
return FALSE;
BytePtr = (UINT8*) EntryPointStructure;
Length = EntryPointStructure->EntryPointLength;
for (I = 0; I < Length; I++) {
Checksum = Checksum + (UINT8) BytePtr[I];
}
// a valid SMBIOS EPS must have checksum of 0
return (Checksum == 0);
}
VOID* FindOemSMBIOSPtr (VOID)
{
UINTN Address;
// Search 0x0f0000 - 0x0fffff for SMBIOS Ptr
for (Address = 0xf0000; Address < 0xfffff; Address += 0x10) {
if (*(UINT32 *)(Address) == SMBIOS_PTR && IsEntryPointStructureValid((SMBIOS_TABLE_ENTRY_POINT*)Address)) {
return (VOID *)Address;
}
}
return NULL;
}
VOID* GetSmbiosTablesFromHob (VOID)
{
EFI_PHYSICAL_ADDRESS *Table;
EFI_PEI_HOB_POINTERS GuidHob;
GuidHob.Raw = (__typeof_am__(GuidHob.Raw))GetFirstGuidHob (&gEfiSmbiosTableGuid);
if (GuidHob.Raw != NULL) {
Table = (__typeof__(Table))GET_GUID_HOB_DATA (GuidHob.Guid);
if (Table != NULL) {
return (VOID *)(UINTN)*Table;
}
}
GuidHob.Raw = (__typeof_am__(GuidHob.Raw))GetFirstGuidHob (&gEfiSmbios3TableGuid);
if (GuidHob.Raw != NULL) {
Table = (__typeof_am__(Table))GET_GUID_HOB_DATA (GuidHob.Guid);
if (Table != NULL) {
return (VOID *)(UINTN)*Table;
}
}
return NULL;
}
VOID* GetSmbiosTablesFromConfigTables (VOID)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS *Table;
Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **)&Table);
if (EFI_ERROR(Status) || Table == NULL) {
Table = NULL;
Status = EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **)&Table);
if (EFI_ERROR(Status)) {
Table = NULL;
}
}
return Table;
}
// This function determines ascii string length ending by space.
// search restricted to MaxLen, for example
// iStrLen("ABC ", 20) == 3
// if MaxLen=0 then as usual strlen but bugless
UINTN iStrLen(CONST CHAR8* String, UINTN MaxLen)
{
UINTN Len = 0;
CONST CHAR8* BA;
if(MaxLen > 0) {
for (Len=0; Len<MaxLen; Len++) {
if (String[Len] == 0) {
break;
}
}
BA = &String[Len - 1];
while ((Len != 0) && ((*BA == ' ') || (*BA == 0))) {
BA--; Len--;
}
} else {
BA = String;
while(*BA){BA++; Len++;}
}
return Len;
}
// Internal functions for flat SMBIOS
UINT16 SmbiosTableLength (APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN)
{
CHAR8 *AChar;
UINT16 Length;
AChar = (CHAR8 *)(SmbiosTableN.Raw + SmbiosTableN.Hdr->Length);
while ((*AChar != 0) || (*(AChar + 1) != 0)) {
AChar ++; //stop at 00 - first 0
}
Length = (UINT16)((UINTN)AChar - (UINTN)SmbiosTableN.Raw + 2); //length includes 00
return Length;
}
EFI_SMBIOS_HANDLE LogSmbiosTable (APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN)
{
UINT16 Length = SmbiosTableLength(SmbiosTableN);
if (Length > MaxStructureSize) {
MaxStructureSize = Length;
}
CopyMem(Current, SmbiosTableN.Raw, Length);
Current += Length;
NumberOfRecords++;
return SmbiosTableN.Hdr->Handle;
}
// the procedure insert Buffer into SmbiosTable by copy and update Field
// the Buffer restricted by zero or by space
EFI_STATUS UpdateSmbiosString (OUT APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN,
SMBIOS_TABLE_STRING* Field, IN CONST CHAR8* Buffer)
{
CHAR8* AString;
CHAR8* C1; //pointers for copy
CHAR8* C2;
UINTN Length = SmbiosTableLength(SmbiosTableN);
UINTN ALength, BLength;
UINT8 IndexStr = 1;
if ((SmbiosTableN.Raw == NULL) || !Buffer || !Field) {
return EFI_NOT_FOUND;
}
AString = (CHAR8*)(SmbiosTableN.Raw + SmbiosTableN.Hdr->Length); //first string
while (IndexStr != *Field) {
if (*AString) {
IndexStr++;
}
while (*AString != 0) AString++; //skip string at index
AString++; //next string
if (*AString == 0) {
//this is end of the table
if (*Field == 0) {
AString[1] = 0; //one more zero
}
*Field = IndexStr; //index of the next string that is empty
if (IndexStr == 1) {
AString--; //first string has no leading zero
}
break;
}
}
// AString is at place to copy
ALength = iStrLen(AString, 0);
BLength = iStrLen(Buffer, MAX_OEM_STRING);
// DBG("Table type %d field %d\n", SmbiosTable.Hdr->Type, *Field);
// DBG("Old string length=%d new length=%d\n", ALength, BLength);
if (BLength > ALength) {
//Shift right
C1 = (CHAR8*)SmbiosTableN.Raw + Length; //old end
C2 = C1 + BLength - ALength; //new end
*C2 = 0;
while (C1 != AString) *(--C2) = *(--C1);
} else if (BLength < ALength) {
//Shift left
C1 = AString + ALength; //old start
C2 = AString + BLength; //new start
while (C1 != ((CHAR8*)SmbiosTableN.Raw + Length)) {
*C2++ = *C1++;
}
*C2 = 0;
*(--C2) = 0; //end of table
}
CopyMem(AString, Buffer, BLength);
*(AString + BLength) = 0; // not sure there is 0
return EFI_SUCCESS;
}
APPLE_SMBIOS_STRUCTURE_POINTER GetSmbiosTableFromType (SMBIOS_TABLE_ENTRY_POINT *SmbiosPoint,
UINT8 SmbiosType, UINTN IndexTable)
{
APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN;
UINTN SmbiosTypeIndex;
SmbiosTypeIndex = 0;
SmbiosTableN.Raw = (UINT8 *)((UINTN)SmbiosPoint->TableAddress);
if (SmbiosTableN.Raw == NULL) {
return SmbiosTableN;
}
while ((SmbiosTypeIndex != IndexTable) || (SmbiosTableN.Hdr->Type != SmbiosType)) {
if (SmbiosTableN.Hdr->Type == SMBIOS_TYPE_END_OF_TABLE) {
SmbiosTableN.Raw = NULL;
return SmbiosTableN;
}
if (SmbiosTableN.Hdr->Type == SmbiosType) {
SmbiosTypeIndex++;
}
SmbiosTableN.Raw = (UINT8 *)(SmbiosTableN.Raw + SmbiosTableLength (SmbiosTableN));
}
return SmbiosTableN;
}
CHAR8* GetSmbiosString (APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN, SMBIOS_TABLE_STRING StringN)
{
CHAR8 *AString;
UINT8 Ind;
Ind = 1;
AString = (CHAR8 *)(SmbiosTableN.Raw + SmbiosTableN.Hdr->Length); //first string
while (Ind != StringN) {
while (*AString != 0) {
AString ++;
}
AString ++; //skip zero ending
if (*AString == 0) {
return AString; //this is end of the table
}
Ind++;
}
return AString; //return pointer to Ascii string
}
VOID AddSmbiosEndOfTable()
{
SMBIOS_STRUCTURE* StructurePtr = (SMBIOS_STRUCTURE*)Current;
StructurePtr->Type = SMBIOS_TYPE_END_OF_TABLE;
StructurePtr->Length = sizeof(SMBIOS_STRUCTURE);
StructurePtr->Handle = SMBIOS_TYPE_INACTIVE; //spec 2.7 p.120
Current += sizeof(SMBIOS_STRUCTURE);
*Current++ = 0;
*Current++ = 0; //double 0 at the end
NumberOfRecords++;
}
VOID UniquifySmbiosTableStr (APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN, SMBIOS_TABLE_STRING* str_idx)
{
INTN i, j;
SMBIOS_TABLE_STRING cmp_idx;
SMBIOS_TABLE_STRING cmp_str;
SMBIOS_TABLE_STRING ref_str;
if (0 == str_idx[0]) return; // SMBIOS doesn't have string structures, just return;
for (i = 1; ;i++) {
cmp_idx = str_idx[i];
if (0 == cmp_idx) break;
cmp_str = SmbiosTableN.Raw[cmp_idx];
if (0 == cmp_str) continue; // if string is undefine, continue
for (j = 0; j < i; j++) {
ref_str = SmbiosTableN.Raw[str_idx[j]];
if (cmp_str == ref_str) {
SmbiosTableN.Raw[cmp_idx] = 0; // pretend the string doesn't exist
// UpdateSmbiosString(SmbiosTableN, &SmbiosTableN.Raw[cmp_idx], GetSmbiosString(SmbiosTableN, ref_str));
break;
}
}
}
}
/* Patching Functions */
VOID PatchTableType0()
{
// BIOS information
//
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_BIOS_INFORMATION, 0);
if (SmbiosTable.Raw == NULL) {
// DBG("SmbiosTable: Type 0 (Bios Information) not found!\n");
return;
}
TableSize = SmbiosTableLength(SmbiosTable);
ZeroMem((VOID*)newSmbiosTable.Type0, MAX_TABLE_SIZE);
CopyMem((VOID*)newSmbiosTable.Type0, (VOID*)SmbiosTable.Type0, TableSize); //can't point to union
/* Real Mac
BIOS Information (Type 0)
Raw Data:
Header and Data:
00 18 2E 00 01 02 00 00 03 7F 80 98 01 00 00 00
00 00 C1 02 00 01 FF FF
Strings:
Apple Inc.
MBP81.88Z.0047.B22.1109281426
09/28/11
*/
newSmbiosTable.Type0->BiosSegment = 0; //like in Mac
newSmbiosTable.Type0->SystemBiosMajorRelease = 0;
newSmbiosTable.Type0->SystemBiosMinorRelease = 1;
// newSmbiosTable.Type0->BiosCharacteristics.BiosCharacteristicsNotSupported = 0;
// newSmbiosTable.Type0->BIOSCharacteristicsExtensionBytes[1] |= 8; //UefiSpecificationSupported;
//Slice: ----------------------
//there is a bug in AppleSMBIOS-42 v1.7
//to eliminate this I have to zero first byte in the field
*(UINT8*)&newSmbiosTable.Type0->BiosCharacteristics = 0;
//dunno about latest version but there is a way to set good characteristics
//if use patched AppleSMBIOS
//----------------
Once = TRUE;
UniquifySmbiosTableStr(newSmbiosTable, SMBIOS_TABLE_TYPE0_STR_IDX);
if(iStrLen(gSettings.VendorName, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->Vendor, gSettings.VendorName);
}
if(iStrLen(gSettings.RomVersion, 64)>0){
if(iStrLen(gSettings.EfiVersion, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->BiosVersion, gSettings.EfiVersion);
} else {
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->BiosVersion, gSettings.RomVersion);
}
}
if(iStrLen(gSettings.ReleaseDate, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->BiosReleaseDate, gSettings.ReleaseDate);
}
Handle = LogSmbiosTable(newSmbiosTable);
}
VOID GetTableType1()
{
CHAR8* s;
// System Information
//
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_SYSTEM_INFORMATION, 0);
if (SmbiosTable.Raw == NULL) {
DBG("SmbiosTable: Type 1 (System Information) not found!\n");
return;
}
CopyMem((VOID*)&gSettings.SmUUID, (VOID*)&SmbiosTable.Type1->Uuid, 16);
s = GetSmbiosString(SmbiosTable, SmbiosTable.Type1->ProductName);
CopyMem(gSettings.OEMProduct, s, iStrLen(s, 64) + 1); //take ending zero
return;
}
VOID PatchTableType1()
{
// System Information
//
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_SYSTEM_INFORMATION, 0);
if (SmbiosTable.Raw == NULL) {
return;
}
//Increase table size
Size = SmbiosTable.Type1->Hdr.Length; //old size
TableSize = SmbiosTableLength(SmbiosTable); //including strings
NewSize = 27; //sizeof(SMBIOS_TABLE_TYPE1);
ZeroMem((VOID*)newSmbiosTable.Type1, MAX_TABLE_SIZE);
CopyMem((VOID*)newSmbiosTable.Type1, (VOID*)SmbiosTable.Type1, Size); //copy main table
CopyMem((CHAR8*)newSmbiosTable.Type1+NewSize, (CHAR8*)SmbiosTable.Type1+Size, TableSize - Size); //copy strings
newSmbiosTable.Type1->Hdr.Length = (UINT8)NewSize;
UniquifySmbiosTableStr(newSmbiosTable, SMBIOS_TABLE_TYPE1_STR_IDX);
newSmbiosTable.Type1->WakeUpType = SystemWakeupTypePowerSwitch;
Once = TRUE;
if((gSettings.SmUUID.Data3 & 0xF000) != 0) {
CopyMem((VOID*)&newSmbiosTable.Type1->Uuid, (VOID*)&gSettings.SmUUID, 16);
}
if(iStrLen(gSettings.ManufactureName, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type1->Manufacturer, gSettings.ManufactureName);
}
if(iStrLen(gSettings.ProductName, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type1->ProductName, gSettings.ProductName);
}
if(iStrLen( gSettings.VersionNr, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type1->Version, gSettings.VersionNr);
}
if(iStrLen(gSettings.SerialNr, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type1->SerialNumber, gSettings.SerialNr);
}
if(iStrLen(gSettings.BoardNumber, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type1->SKUNumber, gSettings.BoardNumber); //iMac17,1 - there is nothing
}
if(iStrLen(gSettings.FamilyName, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type1->Family, gSettings.FamilyName);
}
Handle = LogSmbiosTable(newSmbiosTable);
return;
}
VOID GetTableType2()
{
CHAR8* s;
// System Information
//
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION, 0);
if (SmbiosTable.Raw == NULL) {
return;
}
s = GetSmbiosString(SmbiosTable, SmbiosTable.Type2->ProductName);
CopyMem(gSettings.OEMBoard, s, iStrLen(s, 64) + 1);
s = GetSmbiosString(SmbiosTable, SmbiosTable.Type2->Manufacturer);
CopyMem(gSettings.OEMVendor, s, iStrLen(s, 64) + 1);
}
VOID PatchTableType2()
{
// BaseBoard Information
//
NewSize = 0x10; //sizeof(SMBIOS_TABLE_TYPE2);
ZeroMem((VOID*)newSmbiosTable.Type2, MAX_TABLE_SIZE);
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION, 0);
if (SmbiosTable.Raw == NULL) {
MsgLog("SmbiosTable: Type 2 (BaseBoard Information) not found, create new\n");
//Create new one
newSmbiosTable.Type2->Hdr.Type = 2;
newSmbiosTable.Type2->Hdr.Handle = 0x0200; //common rule
} else {
Size = SmbiosTable.Type2->Hdr.Length; //old size
TableSize = SmbiosTableLength(SmbiosTable); //including strings
if (NewSize > Size) {
CopyMem((VOID*)newSmbiosTable.Type2, (VOID*)SmbiosTable.Type2, Size); //copy main table
CopyMem((CHAR8*)newSmbiosTable.Type2 + NewSize, (CHAR8*)SmbiosTable.Type2 + Size, TableSize - Size); //copy strings
} else {
CopyMem((VOID*)newSmbiosTable.Type2, (VOID*)SmbiosTable.Type2, TableSize); //copy full table
}
}
newSmbiosTable.Type2->Hdr.Length = (UINT8)NewSize;
newSmbiosTable.Type2->ChassisHandle = mHandle3; //from GetTableType3
newSmbiosTable.Type2->BoardType = gSettings.BoardType;
ZeroMem((VOID*)&newSmbiosTable.Type2->FeatureFlag, sizeof(BASE_BOARD_FEATURE_FLAGS));
newSmbiosTable.Type2->FeatureFlag.Motherboard = 1;
newSmbiosTable.Type2->FeatureFlag.Replaceable = 1;
if (gSettings.BoardType == 11) {
newSmbiosTable.Type2->FeatureFlag.Removable = 1;
}
Once = TRUE;
UniquifySmbiosTableStr(newSmbiosTable, SMBIOS_TABLE_TYPE2_STR_IDX);
if(iStrLen(gSettings.BoardManufactureName, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type2->Manufacturer, gSettings.BoardManufactureName);
}
if(iStrLen(gSettings.BoardNumber, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type2->ProductName, gSettings.BoardNumber);
}
if(iStrLen( gSettings.BoardVersion, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type2->Version, gSettings.BoardVersion); //iMac17,1 - there is ProductName
}
if(iStrLen(gSettings.BoardSerialNumber, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type2->SerialNumber, gSettings.BoardSerialNumber);
}
if(iStrLen(gSettings.LocationInChassis, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type2->LocationInChassis, gSettings.LocationInChassis);
}
//what about Asset Tag??? Not used in real mac. till now.
//Slice - for the table2 one patch more needed
/* spec
Field 0x0E - Identifies the number (0 to 255) of Contained Object Handles that follow
Field 0x0F - A list of handles of other structures (for example, Baseboard, Processor, Port, System Slots, Memory Device) that are contained by this baseboard
It may be good before our patching but changed after. We should at least check if all tables mentioned here are present in final structure
I just set 0 as in iMac11
*/
newSmbiosTable.Type2->NumberOfContainedObjectHandles = 0;
Handle = LogSmbiosTable(newSmbiosTable);
return;
}
VOID GetTableType3()
{
// System Chassis Information
//
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE, 0);
if (SmbiosTable.Raw == NULL) {
DBG("SmbiosTable: Type 3 (System Chassis Information) not found!\n");
gMobile = FALSE; //default value
return;
}
mHandle3 = SmbiosTable.Type3->Hdr.Handle;
gMobile = ((SmbiosTable.Type3->Type) >= 8) && (SmbiosTable.Type3->Type != 0x0D); //iMac is desktop!
return;
}
VOID PatchTableType3()
{
// System Chassis Information
//
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE, 0);
if (SmbiosTable.Raw == NULL) {
// DBG("SmbiosTable: Type 3 (System Chassis Information) not found!\n");
return;
}
Size = SmbiosTable.Type3->Hdr.Length; //old size
TableSize = SmbiosTableLength(SmbiosTable); //including strings
NewSize = 0x15; //sizeof(SMBIOS_TABLE_TYPE3);
ZeroMem((VOID*)newSmbiosTable.Type3, MAX_TABLE_SIZE);
if (NewSize > Size) {
CopyMem((VOID*)newSmbiosTable.Type3, (VOID*)SmbiosTable.Type3, Size); //copy main table
CopyMem((CHAR8*)newSmbiosTable.Type3 + NewSize, (CHAR8*)SmbiosTable.Type3 + Size, TableSize - Size); //copy strings
newSmbiosTable.Type3->Hdr.Length = (UINT8)NewSize;
} else {
CopyMem((VOID*)newSmbiosTable.Type3, (VOID*)SmbiosTable.Type3, TableSize); //copy full table
}
newSmbiosTable.Type3->BootupState = ChassisStateSafe;
newSmbiosTable.Type3->PowerSupplyState = ChassisStateSafe;
newSmbiosTable.Type3->ThermalState = ChassisStateOther;
newSmbiosTable.Type3->SecurityStatus = ChassisSecurityStatusOther; //ChassisSecurityStatusNone;
newSmbiosTable.Type3->NumberofPowerCords = 1;
newSmbiosTable.Type3->ContainedElementCount = 0;
newSmbiosTable.Type3->ContainedElementRecordLength = 0;
Once = TRUE;
UniquifySmbiosTableStr(newSmbiosTable, SMBIOS_TABLE_TYPE3_STR_IDX);
if (gSettings.ChassisType != 0) {
newSmbiosTable.Type3->Type = gSettings.ChassisType;
}
if(iStrLen(gSettings.ChassisManufacturer, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type3->Manufacturer, gSettings.ChassisManufacturer);
}
//SIC! According to iMac there must be the BoardNumber
if(iStrLen(gSettings.BoardNumber, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type3->Version, gSettings.BoardNumber);
}
if(iStrLen(gSettings.SerialNr, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type3->SerialNumber, gSettings.SerialNr);
}
if(iStrLen(gSettings.ChassisAssetTag, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type3->AssetTag, gSettings.ChassisAssetTag);
}
Handle = LogSmbiosTable(newSmbiosTable);
return;
}
VOID GetTableType4()
{
// Processor Information
//
INTN res = 0;
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, 0);
if (SmbiosTable.Raw == NULL) {
DBG("SmbiosTable: Type 4 (Processor Information) not found!\n");
return;
}
res = (SmbiosTable.Type4->ExternalClock * 3 + 2) % 100;
if (res > 2) {
res = 0;
} else {
res = SmbiosTable.Type4->ExternalClock % 10;
}
gCPUStructure.ExternalClock = (UINT32)((SmbiosTable.Type4->ExternalClock * 1000) + (res * 110));//MHz->kHz
//snwprintf(gSettings.BusSpeed, 10, "%d", gCPUStructure.ExternalClock);
//gSettings.BusSpeed = gCPUStructure.ExternalClock; //why duplicate??
gCPUStructure.CurrentSpeed = SmbiosTable.Type4->CurrentSpeed;
gCPUStructure.MaxSpeed = SmbiosTable.Type4->MaxSpeed;
if (Size > 0x23) { //Smbios <=2.3
gSettings.EnabledCores = SmbiosTable.Type4->EnabledCoreCount;
} else {
gSettings.EnabledCores = 0; //to change later
}
//snwprintf(gSettings.CpuFreqMHz, 10, "%d", gCPUStructure.CurrentSpeed);
//gSettings.CpuFreqMHz = gCPUStructure.CurrentSpeed;
return;
}
VOID PatchTableType4()
{
// Processor Information
//
UINTN AddBrand = 0;
CHAR8 BrandStr[48];
UINT16 ProcChar = 0;
//Note. iMac11,2 has four tables for CPU i3
UINTN CpuNumber;
CopyMem(BrandStr, gCPUStructure.BrandString, 48);
BrandStr[47] = '\0';
// DBG("BrandString=%s\n", BrandStr);
for (CpuNumber = 0; CpuNumber < gCPUStructure.Cores; CpuNumber++) {
// Get Table Type4
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, CpuNumber);
if (SmbiosTable.Raw == NULL) {
break;
}
// we make SMBios v2.4 while it may be older so we have to increase size
Size = SmbiosTable.Type4->Hdr.Length; //old size
TableSize = SmbiosTableLength(SmbiosTable); //including strings
AddBrand = 0;
if (SmbiosTable.Type4->ProcessorVersion == 0) { //if no BrandString we can add
AddBrand = 48;
}
NewSize = sizeof(SMBIOS_TABLE_TYPE4);
ZeroMem((VOID*)newSmbiosTable.Type4, MAX_TABLE_SIZE);
CopyMem((VOID*)newSmbiosTable.Type4, (VOID*)SmbiosTable.Type4, Size); //copy main table
CopyMem((CHAR8*)newSmbiosTable.Type4+NewSize, (CHAR8*)SmbiosTable.Type4+Size, TableSize - Size); //copy strings
newSmbiosTable.Type4->Hdr.Length = (UINT8)NewSize;
newSmbiosTable.Type4->MaxSpeed = (UINT16)gCPUStructure.MaxSpeed;
//old version has no such fields. Fill now
if (Size <= 0x20){
//sanity check and clear
newSmbiosTable.Type4->SerialNumber = 0;
newSmbiosTable.Type4->AssetTag = 0;
newSmbiosTable.Type4->PartNumber = 0;
}
if (Size <= 0x23) { //Smbios <=2.3
newSmbiosTable.Type4->CoreCount = gCPUStructure.Cores;
newSmbiosTable.Type4->ThreadCount = gCPUStructure.Threads;
newSmbiosTable.Type4->ProcessorCharacteristics = (UINT16)gCPUStructure.Features;
} //else we propose DMI data is better then cpuid().
// if (newSmbiosTable.Type4->CoreCount < newSmbiosTable.Type4->EnabledCoreCount) {
// newSmbiosTable.Type4->EnabledCoreCount = gCPUStructure.Cores;
// }
//DBG("insert ExternalClock: %d MHz\n", (INT32)(DivU64x32(gCPUStructure.ExternalClock, kilo)));
newSmbiosTable.Type4->ExternalClock = (UINT16)DivU64x32 (gCPUStructure.ExternalClock, kilo);
newSmbiosTable.Type4->EnabledCoreCount = gSettings.EnabledCores;
//some verifications
if ((newSmbiosTable.Type4->ThreadCount < newSmbiosTable.Type4->CoreCount) ||
newSmbiosTable.Type4->ThreadCount > newSmbiosTable.Type4->CoreCount * 2) {
newSmbiosTable.Type4->ThreadCount = gCPUStructure.Threads;
}
UniquifySmbiosTableStr(newSmbiosTable, SMBIOS_TABLE_TYPE4_STR_IDX);
// TODO: Set SmbiosTable.Type4->ProcessorFamily for all implemented CPU models
Once = TRUE;
if (gCPUStructure.Model == CPU_MODEL_ATOM) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelAtom;
}
if ((gCPUStructure.Model == CPU_MODEL_DOTHAN) ||
(gCPUStructure.Model == CPU_MODEL_YONAH)) {
if (gCPUStructure.Mobile) {
newSmbiosTable.Type4->ProcessorUpgrade = ProcessorUpgradeSocket478;
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreSoloMobile;
if (gCPUStructure.Cores == 2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreDuoMobile;
}
} else {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreSolo;
if (gCPUStructure.Cores == 2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreDuo;
}
}
}
if (gCPUStructure.Model == CPU_MODEL_MEROM) {
if (gCPUStructure.Mobile) {
if (gCPUStructure.Cores==2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2DuoMobile;
}
if (gCPUStructure.Cores==1) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2SoloMobile;
}
} else { // Conroe
newSmbiosTable.Type4->ProcessorUpgrade = ProcessorUpgradeSocketLGA775;
if (gCPUStructure.Cores>2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2Quad;
} else
if (gCPUStructure.Cores==2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2Extreme;
}
if (gCPUStructure.Cores==1) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2Solo;
}
}
}
if (gCPUStructure.Model == CPU_MODEL_PENRYN) {
if (gCPUStructure.Mobile) {
if (gCPUStructure.Cores>2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2ExtremeMobile;
}
if (gCPUStructure.Cores==2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2DuoMobile;
}
} else {
newSmbiosTable.Type4->ProcessorUpgrade = ProcessorUpgradeSocketLGA775;
if (gCPUStructure.Cores>2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2Quad;
} else if (gCPUStructure.Cores==2) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2;
} else {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2Solo;
}
if (AsciiStrStr(gCPUStructure.BrandString, "Celeron")) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyDualCoreIntelCeleron;
} else if (AsciiStrStr(gCPUStructure.BrandString, "Extreme")) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2Extreme;
}
}
}
if (gCPUStructure.Model >= CPU_MODEL_NEHALEM) {
if (AsciiStrStr(gCPUStructure.BrandString, "i3"))
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreI3;
if (AsciiStrStr(gCPUStructure.BrandString, "i5"))
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreI5;
if (AsciiStrStr(gCPUStructure.BrandString, "i7"))
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCoreI7;
}
//spec 2.7 page 48 note 3
if ((newSmbiosTable.Type4->ProcessorFamily == ProcessorFamilyIntelCore2)
&& gCPUStructure.Mobile) {
newSmbiosTable.Type4->ProcessorFamily = ProcessorFamilyIntelCore2DuoMobile;
}
// Set CPU Attributes
newSmbiosTable.Type4->L1CacheHandle = L1;
newSmbiosTable.Type4->L2CacheHandle = L2;
newSmbiosTable.Type4->L3CacheHandle = L3;
newSmbiosTable.Type4->ProcessorType = CentralProcessor;
newSmbiosTable.Type4->ProcessorId.Signature.ProcessorSteppingId = gCPUStructure.Stepping;
newSmbiosTable.Type4->ProcessorId.Signature.ProcessorModel = (gCPUStructure.Model & 0xF);
newSmbiosTable.Type4->ProcessorId.Signature.ProcessorFamily = gCPUStructure.Family;
newSmbiosTable.Type4->ProcessorId.Signature.ProcessorType = gCPUStructure.Type;
newSmbiosTable.Type4->ProcessorId.Signature.ProcessorXModel = gCPUStructure.Extmodel;
newSmbiosTable.Type4->ProcessorId.Signature.ProcessorXFamily = gCPUStructure.Extfamily;
// CopyMem((VOID*)&newSmbiosTable.Type4->ProcessorId.FeatureFlags, (VOID*)&gCPUStructure.Features, 4);
// newSmbiosTable.Type4->ProcessorId.FeatureFlags = (PROCESSOR_FEATURE_FLAGS)(UINT32)gCPUStructure.Features;
if (Size <= 0x26) {
newSmbiosTable.Type4->ProcessorFamily2 = newSmbiosTable.Type4->ProcessorFamily;
ProcChar |= (gCPUStructure.ExtFeatures & CPUID_EXTFEATURE_EM64T)?0x04:0;
ProcChar |= (gCPUStructure.Cores > 1)?0x08:0;
ProcChar |= (gCPUStructure.Cores < gCPUStructure.Threads)?0x10:0;
ProcChar |= (gCPUStructure.ExtFeatures & CPUID_EXTFEATURE_XD)?0x20:0;
ProcChar |= (gCPUStructure.Features & CPUID_FEATURE_VMX)?0x40:0;
ProcChar |= (gCPUStructure.Features & CPUID_FEATURE_EST)?0x80:0;
newSmbiosTable.Type4->ProcessorCharacteristics = ProcChar;
}
// TODO Jief : looks that the next line modify SocketDesignationMac, which is not used
CHAR8 SocketDesignationMac[] = "U2E1";
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type4->Socket, SocketDesignationMac);
if (AddBrand) {
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type4->ProcessorVersion, BrandStr);
}
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type4->AssetTag, BrandStr); //like mac
// looks to be MicroCode revision
if(gCPUStructure.MicroCode > 0){
snprintf(BrandStr, 20, "%llX", gCPUStructure.MicroCode); // MicroCode > 0 so %X and %llX do the same
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type4->SerialNumber, BrandStr);
}
Handle = LogSmbiosTable(newSmbiosTable);
}
return;
}
VOID PatchTableType6()
{
UINT8 SizeField = 0;
//
// MemoryModule (TYPE 6)
// This table is obsolete accoding to Spec but Apple still using it so
// copy existing table if found, no patches will be here
// we can have more then 1 module.
for (Index = 0; Index < MAX_RAM_SLOTS; Index++) {
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_MEMORY_MODULE_INFORMATON,Index);
if (SmbiosTable.Raw == NULL) {
// MsgLog("SMBIOS Table 6 index %d not found\n", Index);
continue;
}
SizeField = SmbiosTable.Type6->InstalledSize.InstalledOrEnabledSize & 0x7F;
if (SizeField < 0x7D) {
mInstalled[Index] = LShiftU64(1ULL, 20 + SizeField);
} else if (SizeField == 0x7F) {
mInstalled[Index] = 0;
} else
mInstalled[Index] = 4096ULL * (1024ULL * 1024ULL);
MsgLog("Table 6 MEMORY_MODULE %llu Installed %llX ", Index, mInstalled[Index]);
if (SizeField >= 0x7D) {
mEnabled[Index] = 0;
} else
mEnabled[Index] = LShiftU64(1ULL, 20 + ((UINT8)SmbiosTable.Type6->EnabledSize.InstalledOrEnabledSize & 0x7F));
MsgLog("... enabled %llX \n", mEnabled[Index]);
LogSmbiosTable(SmbiosTable);
}
return;
}
VOID PatchTableType7()
{
// Cache Information
//
//TODO - should be separate table for each CPU core
//new handle for each core and attach Type4 tables for individual Type7
// Handle = 0x0700 + CoreN<<2 + CacheN (4-level cache is supported
// L1[CoreN] = Handle
CHAR8 SSocketD[9];
BOOLEAN correctSD = FALSE;
//according to spec for Smbios v2.0 max handle is 0xFFFE, for v>2.0 (we made 2.6) max handle=0xFEFF.
// Value 0xFFFF means no cache
L1 = 0xFFFF; // L1 Cache
L2 = 0xFFFF; // L2 Cache
L3 = 0xFFFF; // L3 Cache
// Get Table Type7 and set CPU Caches
for (Index = 0; Index < MAX_CACHE_COUNT; Index++) {
SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_CACHE_INFORMATION, Index);
if (SmbiosTable.Raw == NULL) {
break;
}
TableSize = SmbiosTableLength(SmbiosTable);
ZeroMem((VOID*)newSmbiosTable.Type7, MAX_TABLE_SIZE);
CopyMem((VOID*)newSmbiosTable.Type7, (VOID*)SmbiosTable.Type7, TableSize);
correctSD = (newSmbiosTable.Type7->SocketDesignation == 0);
CoreCache = newSmbiosTable.Type7->CacheConfiguration & 3;
Once = TRUE;
//SSocketD = "L1-Cache";
CopyMem(SSocketD, "L1-Cache", 9);
if(correctSD) {
SSocketD[1] = (CHAR8)(0x31 + CoreCache);