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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
|
/** @file
Copyright (c) 2004 - 2014, 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 that 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:
SetupInfoRecords.c
Abstract:
This is the filter driver to retrieve data hub entries.
Revision History:
--*/
#include "PlatformSetupDxe.h"
#include <Protocol/LegacyBios.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/DevicePath.h>
#include <Protocol/DiskInfo.h>
#include <Protocol/IdeControllerInit.h>
#include <Protocol/MpService.h>
#include <Protocol/PchPlatformPolicy.h>
#include <Protocol/CpuIo2.h>
#include <Protocol/Smbios.h>
#include <IndustryStandard/SmBios.h>
#include <Library/IoLib.h>
#include <Library/I2CLib.h>
#include <Guid/GlobalVariable.h>
#include "Valleyview.h"
#include "VlvAccess.h"
#include "PchAccess.h"
#include "SetupMode.h"
#include "PchCommonDefinitions.h"
#include <PlatformBaseAddresses.h>
typedef struct {
UINT8 ID;
CHAR8 String[16];
} VLV_REV;
typedef struct {
UINT8 RevId;
CHAR8 String[16];
} SB_REV;
//
// Silicon Steppings
//
SB_REV SBRevisionTable[] = {
{V_PCH_LPC_RID_0, "(A0 Stepping)"},
{V_PCH_LPC_RID_1, "(A0 Stepping)"},
{V_PCH_LPC_RID_2, "(A1 Stepping)"},
{V_PCH_LPC_RID_3, "(A1 Stepping)"},
{V_PCH_LPC_RID_4, "(B0 Stepping)"},
{V_PCH_LPC_RID_5, "(B0 Stepping)"},
{V_PCH_LPC_RID_6, "(B1 Stepping)"},
{V_PCH_LPC_RID_7, "(B1 Stepping)"},
{V_PCH_LPC_RID_8, "(B2 Stepping)"},
{V_PCH_LPC_RID_9, "(B2 Stepping)"},
{V_PCH_LPC_RID_A, "(B3 Stepping)"},
{V_PCH_LPC_RID_B, "(B3 Stepping)"},
{V_PCH_LPC_RID_C, "(C0 Stepping)"},
{V_PCH_LPC_RID_D, "(C0 Stepping)"}
};
#define LEFT_JUSTIFY 0x01
#define PREFIX_SIGN 0x02
#define PREFIX_BLANK 0x04
#define COMMA_TYPE 0x08
#define LONG_TYPE 0x10
#define PREFIX_ZERO 0x20
#define ICH_REG_REV 0x08
#define MSR_IA32_PLATFORM_ID 0x17
BOOLEAN mSetupInfoDone = FALSE;
UINT8 mUseProductKey = 0;
EFI_EXP_BASE10_DATA mProcessorFrequency;
EFI_EXP_BASE10_DATA mProcessorFsbFrequency;
EFI_GUID mProcessorProducerGuid;
EFI_HII_HANDLE mHiiHandle;
EFI_PLATFORM_CPU_INFO mPlatformCpuInfo;
SYSTEM_CONFIGURATION mSystemConfiguration;
EFI_PLATFORM_INFO_HOB *mPlatformInfo;
#define memset SetMem
UINT16 mMemorySpeed = 0xffff;
EFI_PHYSICAL_ADDRESS mMemorySizeChannelASlot0 = 0;
UINT16 mMemorySpeedChannelASlot0 = 0xffff;
EFI_PHYSICAL_ADDRESS mMemorySizeChannelASlot1 = 0;
UINT16 mMemorySpeedChannelASlot1 = 0xffff;
EFI_PHYSICAL_ADDRESS mMemorySizeChannelBSlot0 = 0;
UINT16 mMemorySpeedChannelBSlot0 = 0xffff;
EFI_PHYSICAL_ADDRESS mMemorySizeChannelBSlot1 = 0;
UINT16 mMemorySpeedChannelBSlot1 = 0xffff;
EFI_PHYSICAL_ADDRESS mMemorySizeChannelCSlot0 = 0;
UINT16 mMemorySpeedChannelCSlot0 = 0xffff;
EFI_PHYSICAL_ADDRESS mMemorySizeChannelCSlot1 = 0;
UINT16 mMemorySpeedChannelCSlot1 = 0xffff;
UINTN mMemoryMode = 0xff;
#define CHARACTER_NUMBER_FOR_VALUE 30
typedef struct {
EFI_STRING_TOKEN MemoryDeviceLocator;
EFI_STRING_TOKEN MemoryBankLocator;
EFI_STRING_TOKEN MemoryManufacturer;
EFI_STRING_TOKEN MemorySerialNumber;
EFI_STRING_TOKEN MemoryAssetTag;
EFI_STRING_TOKEN MemoryPartNumber;
EFI_INTER_LINK_DATA MemoryArrayLink;
EFI_INTER_LINK_DATA MemorySubArrayLink;
UINT16 MemoryTotalWidth;
UINT16 MemoryDataWidth;
UINT64 MemoryDeviceSize;
EFI_MEMORY_FORM_FACTOR MemoryFormFactor;
UINT8 MemoryDeviceSet;
EFI_MEMORY_ARRAY_TYPE MemoryType;
EFI_MEMORY_TYPE_DETAIL MemoryTypeDetail;
UINT16 MemorySpeed;
EFI_MEMORY_STATE MemoryState;
} EFI_MEMORY_ARRAY_LINK;
typedef struct {
EFI_PHYSICAL_ADDRESS MemoryArrayStartAddress;
EFI_PHYSICAL_ADDRESS MemoryArrayEndAddress;
EFI_INTER_LINK_DATA PhysicalMemoryArrayLink;
UINT16 MemoryArrayPartitionWidth;
} EFI_MEMORY_ARRAY_START_ADDRESS;
typedef enum {
PCH_SATA_MODE_IDE = 0,
PCH_SATA_MODE_AHCI,
PCH_SATA_MODE_RAID,
PCH_SATA_MODE_MAX
} PCH_SATA_MODE;
/**
Acquire the string associated with the Index from smbios structure and return it.
The caller is responsible for free the string buffer.
@param OptionalStrStart The start position to search the string
@param Index The index of the string to extract
@param String The string that is extracted
@retval EFI_SUCCESS The function returns EFI_SUCCESS always.
**/
EFI_STATUS
GetOptionalStringByIndex (
IN CHAR8 *OptionalStrStart,
IN UINT8 Index,
OUT CHAR16 **String
)
{
UINTN StrSize;
if (Index == 0) {
*String = AllocateZeroPool (sizeof (CHAR16));
return EFI_SUCCESS;
}
StrSize = 0;
do {
Index--;
OptionalStrStart += StrSize;
StrSize = AsciiStrSize (OptionalStrStart);
} while (OptionalStrStart[StrSize] != 0 && Index != 0);
if ((Index != 0) || (StrSize == 1)) {
//
// Meet the end of strings set but Index is non-zero, or
// Find an empty string
//
return EFI_NOT_FOUND;
} else {
*String = AllocatePool (StrSize * sizeof (CHAR16));
AsciiStrToUnicodeStr (OptionalStrStart, *String);
}
return EFI_SUCCESS;
}
/**
VSPrint worker function that prints a Value as a decimal number in Buffer
@param Buffer Location to place ascii decimal number string of Value.
@param Value Decimal value to convert to a string in Buffer.
@param Flags Flags to use in printing decimal string, see file header for details.
@param Width Width of hex value.
Number of characters printed.
**/
UINTN
EfiValueToString (
IN OUT CHAR16 *Buffer,
IN INT64 Value,
IN UINTN Flags,
IN UINTN Width
)
{
CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
CHAR16 *TempStr;
CHAR16 *BufferPtr;
UINTN Count;
UINTN ValueCharNum;
UINTN Remainder;
CHAR16 Prefix;
UINTN Index;
BOOLEAN ValueIsNegative;
UINT64 TempValue;
TempStr = TempBuffer;
BufferPtr = Buffer;
Count = 0;
ValueCharNum = 0;
ValueIsNegative = FALSE;
if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
Width = CHARACTER_NUMBER_FOR_VALUE - 1;
}
if (Value < 0) {
Value = -Value;
ValueIsNegative = TRUE;
}
do {
TempValue = Value;
Value = (INT64)DivU64x32 ((UINT64)Value, 10);
Remainder = (UINTN)((UINT64)TempValue - 10 * Value);
*(TempStr++) = (CHAR16)(Remainder + '0');
ValueCharNum++;
Count++;
if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
if (ValueCharNum % 3 == 0 && Value != 0) {
*(TempStr++) = ',';
Count++;
}
}
} while (Value != 0);
if (ValueIsNegative) {
*(TempStr++) = '-';
Count++;
}
if ((Flags & PREFIX_ZERO) && !ValueIsNegative) {
Prefix = '0';
} else {
Prefix = ' ';
}
Index = Count;
if (!(Flags & LEFT_JUSTIFY)) {
for (; Index < Width; Index++) {
*(TempStr++) = Prefix;
}
}
//
// Reverse temp string into Buffer.
//
if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
TempStr = TempBuffer + Width;
}
Index = 0;
while (TempStr != TempBuffer) {
*(BufferPtr++) = *(--TempStr);
Index++;
}
*BufferPtr = 0;
return Index;
}
static CHAR16 mHexStr[] = { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7',
L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F' };
/**
VSPrint worker function that prints a Value as a hex number in Buffer
@param Buffer Location to place ascii hex string of Value.
@param Value Hex value to convert to a string in Buffer.
@param Flags Flags to use in printing Hex string, see file header for details.
@param Width Width of hex value.
@retval Number of characters printed.
**/
UINTN
EfiValueToHexStr (
IN OUT CHAR16 *Buffer,
IN UINT64 Value,
IN UINTN Flags,
IN UINTN Width
)
{
CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
CHAR16 *TempStr;
CHAR16 Prefix;
CHAR16 *BufferPtr;
UINTN Count;
UINTN Index;
TempStr = TempBuffer;
BufferPtr = Buffer;
//
// Count starts at one since we will null terminate. Each iteration of the
// loop picks off one nibble. Oh yea TempStr ends up backwards
//
Count = 0;
if (Width > CHARACTER_NUMBER_FOR_VALUE - 1) {
Width = CHARACTER_NUMBER_FOR_VALUE - 1;
}
do {
Index = ((UINTN)Value & 0xf);
*(TempStr++) = mHexStr[Index];
Value = RShiftU64 (Value, 4);
Count++;
} while (Value != 0);
if (Flags & PREFIX_ZERO) {
Prefix = '0';
} else {
Prefix = ' ';
}
Index = Count;
if (!(Flags & LEFT_JUSTIFY)) {
for (; Index < Width; Index++) {
*(TempStr++) = Prefix;
}
}
//
// Reverse temp string into Buffer.
//
if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {
TempStr = TempBuffer + Width;
}
Index = 0;
while (TempStr != TempBuffer) {
*(BufferPtr++) = *(--TempStr);
Index++;
}
*BufferPtr = 0;
return Index;
}
/*++
Converts MAC address to Unicode string.
The value is 64-bit and the resulting string will be 12
digit hex number in pairs of digits separated by dashes.
@param String string that will contain the value
@param MacAddr add argument and description to function comment
@param AddrSize add argument and description to function comment
**/
CHAR16 *
StrMacToString (
OUT CHAR16 *String,
IN EFI_MAC_ADDRESS *MacAddr,
IN UINT32 AddrSize
)
{
UINT32 i;
for (i = 0; i < AddrSize; i++) {
EfiValueToHexStr (
&String[2 * i],
MacAddr->Addr[i] & 0xFF,
PREFIX_ZERO,
2
);
}
//
// Terminate the string.
//
String[2 * AddrSize] = L'\0';
return String;
}
VOID UpdateLatestBootTime() {
UINTN VarSize;
EFI_STATUS Status;
UINT64 TimeValue;
CHAR16 Buffer[40];
if (mSystemConfiguration.LogBootTime != 1) {
return;
}
VarSize = sizeof(TimeValue);
Status = gRT->GetVariable(
BOOT_TIME_NAME,
&gEfiNormalSetupGuid,
NULL,
&VarSize,
&TimeValue
);
if (EFI_ERROR(Status)) {
return;
}
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d ms", (UINT32)TimeValue);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_LOG_BOOT_TIME_VALUE), Buffer, NULL);
}
/**
Get Cache Type for the specified Cache. This function is invoked when there is data records
available in the Data Hub.
Get Cache Type function arguments:
@param Instance The instance number of the subclass with the same ProducerName..
@param SubInstance The instance number of the RecordType for the same Instance.
@param CacheType Cache type, see definition of EFI_CACHE_TYPE_DATA.
@retval EFI_STATUS
**/
EFI_STATUS
GetCacheType(
IN UINT16 Instance,
IN UINT16 SubInstance,
IN EFI_CACHE_TYPE_DATA* CacheType)
{
EFI_STATUS Status;
EFI_DATA_HUB_PROTOCOL *DataHub;
EFI_DATA_RECORD_HEADER *Record;
UINT64 MonotonicCount;
EFI_CACHE_VARIABLE_RECORD* CacheVariableRecord;
EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
Status = gBS->LocateProtocol (
&gEfiDataHubProtocolGuid,
NULL,
(void **)&DataHub
);
ASSERT_EFI_ERROR(Status);
//
// Get all available data records from data hub
//
MonotonicCount = 0;
Record = NULL;
do {
Status = DataHub->GetNextRecord (
DataHub,
&MonotonicCount,
NULL,
&Record
);
if (!EFI_ERROR(Status)) {
if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
if(CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
(DataHeader->RecordType == CacheTypeRecordType) &&
(DataHeader->Instance == Instance) &&
(DataHeader->SubInstance == SubInstance)) {
CacheVariableRecord = (EFI_CACHE_VARIABLE_RECORD *)(DataHeader + 1);
if(CacheType){
*CacheType = CacheVariableRecord->CacheType;
return EFI_SUCCESS;
}
}
}
}
} while(!EFI_ERROR(Status) && (MonotonicCount != 0));
return EFI_NOT_FOUND;
}
/**
Setup data filter function. This function is invoked when there is data records
available in the Data Hub.
Standard event notification function arguments:
@param Event The event that is signaled.
@param Context Not used here.
@retval EFI_STATUS
**/
VOID
PrepareSetupInformation (
)
{
EFI_STATUS Status;
EFI_DATA_HUB_PROTOCOL *DataHub;
EFI_DATA_RECORD_HEADER *Record;
UINT8 *SrcData;
EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
CHAR16 *NewString;
CHAR16 *NewString2;
CHAR16 *NewStringToken;
STRING_REF TokenToUpdate;
EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
UINTN Index;
UINTN DataOutput;
EFI_PROCESSOR_MICROCODE_REVISION_DATA *CpuUcodeRevisionData;
EFI_MEMORY_ARRAY_START_ADDRESS *MemoryArray;
EFI_MEMORY_ARRAY_LINK *MemoryArrayLink;
UINT64 MonotonicCount;
CHAR16 Version[100]; //Assuming that strings are < 100 UCHAR
CHAR16 ReleaseDate[100]; //Assuming that strings are < 100 UCHAR
CHAR16 ReleaseTime[100]; //Assuming that strings are < 100 UCHAR
NewString = AllocateZeroPool (0x100);
NewString2 = AllocateZeroPool (0x100);
SetMem(Version, sizeof(Version), 0);
SetMem(ReleaseDate, sizeof(ReleaseDate), 0);
SetMem(ReleaseTime, sizeof(ReleaseTime), 0);
//
// Get the Data Hub Protocol. Assume only one instance
//
Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (void **)&DataHub);
ASSERT_EFI_ERROR(Status);
//
// Get all available data records from data hub
//
MonotonicCount = 0;
Record = NULL;
do {
Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
if (!EFI_ERROR(Status)) {
if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
SrcData = (UINT8 *)(DataHeader + 1);
//
// Processor
//
if (CompareGuid(&Record->DataRecordGuid, &gEfiProcessorSubClassGuid)) {
CopyMem (&mProcessorProducerGuid, &Record->ProducerName, sizeof(EFI_GUID));
switch (DataHeader->RecordType) {
case ProcessorCoreFrequencyRecordType:
CopyMem(&mProcessorFrequency, SrcData, sizeof(EFI_EXP_BASE10_DATA));
Index = EfiValueToString (
NewString,
ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)/1000000000,
PREFIX_ZERO,
0
);
StrCat (NewString, L".");
EfiValueToString (
NewString + Index + 1,
((ConvertBase10ToRaw ((EFI_EXP_BASE10_DATA *)SrcData)%1000000000)/10000000),
PREFIX_ZERO,
0
);
StrCat (NewString, L" GHz");
TokenToUpdate = (STRING_REF)STR_PROCESSOR_SPEED_VALUE;
HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
break;
case ProcessorVersionRecordType:
ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *)SrcData;
NewStringToken = HiiGetPackageString(&mProcessorProducerGuid, *ProcessorVersion, NULL);
TokenToUpdate = (STRING_REF)STR_PROCESSOR_VERSION_VALUE;
HiiSetString(mHiiHandle, TokenToUpdate, NewStringToken, NULL);
break;
case CpuUcodeRevisionDataRecordType:
CpuUcodeRevisionData = (EFI_PROCESSOR_MICROCODE_REVISION_DATA *) SrcData;
if (CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber != 0) {
EfiValueToHexStr (
NewString,
CpuUcodeRevisionData->ProcessorMicrocodeRevisionNumber,
PREFIX_ZERO,
8
);
TokenToUpdate = (STRING_REF)STR_PROCESSOR_MICROCODE_VALUE;
HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
}
break;
default:
break;
}
//
// Cache
//
} else if (CompareGuid(&Record->DataRecordGuid, &gEfiCacheSubClassGuid) &&
(DataHeader->RecordType == CacheSizeRecordType)) {
if (DataHeader->SubInstance == EFI_CACHE_L1) {
EFI_CACHE_TYPE_DATA CacheType;
if (EFI_SUCCESS == GetCacheType(DataHeader->Instance, DataHeader->SubInstance,&CacheType)){
if (CacheType == EfiCacheTypeData) {
TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_DATA_CACHE_VALUE;
} else if (CacheType == EfiCacheTypeInstruction) {
TokenToUpdate = (STRING_REF)STR_PROCESSOR_L1_INSTR_CACHE_VALUE;
} else {
continue;
}
} else {
continue;
}
}
else if (DataHeader->SubInstance == EFI_CACHE_L2) {
TokenToUpdate = (STRING_REF)STR_PROCESSOR_L2_CACHE_VALUE;
} else {
continue;
}
if (ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData)) {
DataOutput = ConvertBase2ToRaw((EFI_EXP_BASE2_DATA *)SrcData) >> 10;
EfiValueToString (NewString, DataOutput, PREFIX_ZERO, 0);
StrCat (NewString, L" KB");
if (DataHeader->SubInstance == EFI_CACHE_L3) {
HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
} else if(DataHeader->SubInstance == EFI_CACHE_L2 && mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage > 1){
//
// Show XxL2 string
//
EfiValueToString (
NewString2,
mPlatformCpuInfo.CpuPackage.CoresPerPhysicalPackage,
PREFIX_ZERO,
0
);
StrCat(NewString2, L"x ");
StrCat(NewString2, NewString);
HiiSetString(mHiiHandle, TokenToUpdate, NewString2, NULL);
} else {
HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
}
}
//
// Memory
//
} else if (CompareGuid(&Record->DataRecordGuid, &gEfiMemorySubClassGuid)) {
switch (DataHeader->RecordType) {
case EFI_MEMORY_ARRAY_LINK_RECORD_NUMBER:
MemoryArrayLink = (EFI_MEMORY_ARRAY_LINK *)SrcData;
if (MemoryArrayLink->MemorySpeed > 0) {
//
// Save the lowest speed memory module
//
if (MemoryArrayLink->MemorySpeed < mMemorySpeed) {
mMemorySpeed = MemoryArrayLink->MemorySpeed;
}
switch (DataHeader->SubInstance) {
case 1:
mMemorySpeedChannelASlot0 = MemoryArrayLink->MemorySpeed;
mMemorySizeChannelASlot0 = MemoryArrayLink->MemoryDeviceSize;
break;
case 2:
mMemorySpeedChannelASlot1 = MemoryArrayLink->MemorySpeed;
mMemorySizeChannelASlot1 = MemoryArrayLink->MemoryDeviceSize;
break;
case 3:
mMemorySpeedChannelBSlot0 = MemoryArrayLink->MemorySpeed;
mMemorySizeChannelBSlot0 = MemoryArrayLink->MemoryDeviceSize;
break;
case 4:
mMemorySpeedChannelBSlot1 = MemoryArrayLink->MemorySpeed;
mMemorySizeChannelBSlot1 = MemoryArrayLink->MemoryDeviceSize;
break;
case 5:
mMemorySpeedChannelCSlot0 = MemoryArrayLink->MemorySpeed;
mMemorySizeChannelCSlot0 = MemoryArrayLink->MemoryDeviceSize;
break;
case 6:
mMemorySpeedChannelCSlot1 = MemoryArrayLink->MemorySpeed;
mMemorySizeChannelCSlot1 = MemoryArrayLink->MemoryDeviceSize;
break;
default:
break;
}
}
break;
case EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER:
MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS *)SrcData;
if (MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress) {
DataOutput = (UINTN)RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20);
EfiValueToString (NewString, DataOutput / 1024, PREFIX_ZERO, 0);
if(DataOutput % 1024) {
StrCat (NewString, L".");
DataOutput = ((DataOutput % 1024) * 1000) / 1024;
while(!(DataOutput % 10))
DataOutput = DataOutput / 10;
EfiValueToString (NewString2, DataOutput, PREFIX_ZERO, 0);
StrCat (NewString, NewString2);
}
StrCat (NewString, L" GB");
TokenToUpdate = (STRING_REF)STR_TOTAL_MEMORY_SIZE_VALUE;
HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
}
break;
default:
break;
}
}
}
}
} while (!EFI_ERROR(Status) && (MonotonicCount != 0));
Status = GetBiosVersionDateTime (
Version,
ReleaseDate,
ReleaseTime
);
DEBUG ((EFI_D_ERROR, "GetBiosVersionDateTime :%s %s %s \n", Version, ReleaseDate, ReleaseTime));
if (!EFI_ERROR (Status)) {
UINTN Length = 0;
CHAR16 *BuildDateTime;
Length = StrLen(ReleaseDate) + StrLen(ReleaseTime);
BuildDateTime = AllocateZeroPool ((Length+2) * sizeof(CHAR16));
StrCpy (BuildDateTime, ReleaseDate);
StrCat (BuildDateTime, L" ");
StrCat (BuildDateTime, ReleaseTime);
TokenToUpdate = (STRING_REF)STR_BIOS_VERSION_VALUE;
DEBUG ((EFI_D_ERROR, "update STR_BIOS_VERSION_VALUE\n"));
HiiSetString(mHiiHandle, TokenToUpdate, Version, NULL);
TokenToUpdate = (STRING_REF)STR_BIOS_BUILD_TIME_VALUE;
DEBUG ((EFI_D_ERROR, "update STR_BIOS_BUILD_TIME_VALUE\n"));
HiiSetString(mHiiHandle, TokenToUpdate, BuildDateTime, NULL);
}
//
// Calculate and update memory speed display in Main Page
//
//
// Update the overall memory speed
//
if (mMemorySpeed != 0xffff) {
EfiValueToString (NewString, mMemorySpeed, PREFIX_ZERO, 0);
StrCat (NewString, L" MHz");
TokenToUpdate = (STRING_REF)STR_SYSTEM_MEMORY_SPEED_VALUE;
HiiSetString(mHiiHandle, TokenToUpdate, NewString, NULL);
}
gBS->FreePool(NewString);
gBS->FreePool(NewString2);
return;
}
/**
Routine Description: update the SETUP info for "Additional Information" which is SMBIOS info.
@retval EFI_STATUS
**/
EFI_STATUS
UpdateAdditionalInformation (
)
{
EFI_STATUS Status;
UINT64 MonotonicCount;
EFI_DATA_HUB_PROTOCOL *DataHub;
EFI_DATA_RECORD_HEADER *Record;
EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
EFI_SMBIOS_PROTOCOL *Smbios;
EFI_SMBIOS_HANDLE SmbiosHandle;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord;
SMBIOS_TABLE_TYPE0 *Type0Record;
UINT8 StrIndex;
CHAR16 *BiosVersion = NULL;
CHAR16 *IfwiVersion = NULL;
UINT16 SearchIndex;
EFI_STRING_ID TokenToUpdate;
#if defined( RVP_SUPPORT ) && RVP_SUPPORT
EFI_MISC_SYSTEM_MANUFACTURER *SystemManufacturer;
#endif
Status = gBS->LocateProtocol (
&gEfiDataHubProtocolGuid,
NULL,
(void **)&DataHub
);
ASSERT_EFI_ERROR(Status);
MonotonicCount = 0;
Record = NULL;
do {
Status = DataHub->GetNextRecord (
DataHub,
&MonotonicCount,
NULL,
&Record
);
if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *)(Record + 1);
if (CompareGuid(&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
(DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)) {
#if defined( RVP_SUPPORT ) && RVP_SUPPORT
//
// System Information
//
SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER *)(DataHeader + 1);
//
// UUID (System Information)
//
SMBIOSString = EfiLibAllocateZeroPool (0x100);
GuidToString ( &SystemManufacturer->SystemUuid, SMBIOSString, 0x00 );
TokenToUpdate = (STRING_REF)STR_SYSTEM_UUID_VALUE;
HiiSetString(mHiiHandle, TokenToUpdate, SMBIOSString, NULL);
gBS->FreePool(SMBIOSString);
#endif
}
}
} while (!EFI_ERROR(Status) && (MonotonicCount != 0));
Status = gBS->LocateProtocol (
&gEfiSmbiosProtocolGuid,
NULL,
(VOID **) &Smbios
);
ASSERT_EFI_ERROR (Status);
SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
do {
Status = Smbios->GetNext (
Smbios,
&SmbiosHandle,
NULL,
&SmbiosRecord,
NULL
);
if (SmbiosRecord->Type == EFI_SMBIOS_TYPE_BIOS_INFORMATION) {
Type0Record = (SMBIOS_TABLE_TYPE0 *) SmbiosRecord;
StrIndex = Type0Record->BiosVersion;
GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type0Record + Type0Record->Hdr.Length), StrIndex, &BiosVersion);
TokenToUpdate = STRING_TOKEN (STR_BIOS_VERSION_VALUE);
for (SearchIndex = 0x0; SearchIndex < SMBIOS_STRING_MAX_LENGTH; SearchIndex++) {
if (BiosVersion[SearchIndex] == 0x0020) {
BiosVersion[SearchIndex] = 0x0000;
IfwiVersion = (CHAR16 *)(&BiosVersion[SearchIndex+1]);
break;
} else if (BiosVersion[SearchIndex] == 0x0000) {
break;
}
}
HiiSetString (mHiiHandle, TokenToUpdate, BiosVersion, NULL);
//
// Check IfwiVersion, to avoid no IFWI version in SMBIOS Type 0 strucntion
//
if(IfwiVersion) {
TokenToUpdate = STRING_TOKEN (STR_IFWI_VERSION_VALUE);
HiiSetString (mHiiHandle, TokenToUpdate, IfwiVersion, NULL);
}
}
} while (!EFI_ERROR(Status));
UpdateLatestBootTime();
return EFI_SUCCESS;
}
VOID
UpdateCPUInformation ()
{
CHAR16 Buffer[40];
UINT16 FamilyId;
UINT8 Model;
UINT8 SteppingId;
UINT8 ProcessorType;
EFI_STATUS Status;
EFI_MP_SERVICES_PROTOCOL *MpService;
UINTN MaximumNumberOfCPUs;
UINTN NumberOfEnabledCPUs;
UINT32 Buffer32 = 0xFFFFFFFF; // Keep buffer with unknown device
EfiCpuVersion (&FamilyId, &Model, &SteppingId, &ProcessorType);
//
//we need raw Model data
//
Model = Model & 0xf;
//
//Family/Model/Step
//
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d/%d/%d", FamilyId, Model, SteppingId);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_ID_VALUE), Buffer, NULL);
Status = gBS->LocateProtocol (
&gEfiMpServiceProtocolGuid,
NULL,
(void **)&MpService
);
if (!EFI_ERROR (Status)) {
//
// Determine the number of processors
//
MpService->GetNumberOfProcessors (
MpService,
&MaximumNumberOfCPUs,
&NumberOfEnabledCPUs
);
UnicodeSPrint (Buffer, sizeof (Buffer), L"%d", MaximumNumberOfCPUs);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_CORE_VALUE), Buffer, NULL);
}
//
// Update Mobile / Desktop / Tablet SKU
//
Buffer32 =(UINT32) RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
switch(Buffer32){
case 0x0:
UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - ISG SKU SOC", Buffer32);
break;
case 0x01:
UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
break;
case 0x02:
UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Desktop SKU SOC", Buffer32);
break;
case 0x03:
UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Mobile SKU SOC", Buffer32);
break;
default:
UnicodeSPrint (Buffer, sizeof (Buffer), L"(%d) - Unknown SKU SOC", Buffer32);
break;
}
HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_SKU_VALUE), Buffer, NULL);
}
EFI_STATUS
SearchChildHandle(
EFI_HANDLE Father,
EFI_HANDLE *Child
)
{
EFI_STATUS Status;
UINTN HandleIndex;
EFI_GUID **ProtocolGuidArray = NULL;
UINTN ArrayCount;
UINTN ProtocolIndex;
UINTN OpenInfoCount;
UINTN OpenInfoIndex;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo = NULL;
UINTN mHandleCount;
EFI_HANDLE *mHandleBuffer= NULL;
//
// Retrieve the list of all handles from the handle database
//
Status = gBS->LocateHandleBuffer (
AllHandles,
NULL,
NULL,
&mHandleCount,
&mHandleBuffer
);
for (HandleIndex = 0; HandleIndex < mHandleCount; HandleIndex++)
{
//
// Retrieve the list of all the protocols on each handle
//
Status = gBS->ProtocolsPerHandle (
mHandleBuffer[HandleIndex],
&ProtocolGuidArray,
&ArrayCount
);
if (!EFI_ERROR (Status))
{
for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++)
{
Status = gBS->OpenProtocolInformation (
mHandleBuffer[HandleIndex],
ProtocolGuidArray[ProtocolIndex],
&OpenInfo,
&OpenInfoCount
);
if (!EFI_ERROR (Status))
{
for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++)
{
if(OpenInfo[OpenInfoIndex].AgentHandle == Father)
{
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER)
{
*Child = mHandleBuffer[HandleIndex];
Status = EFI_SUCCESS;
goto TryReturn;
}
}
}
Status = EFI_NOT_FOUND;
}
}
if(OpenInfo != NULL)
{
FreePool(OpenInfo);
OpenInfo = NULL;
}
}
FreePool (ProtocolGuidArray);
ProtocolGuidArray = NULL;
}
TryReturn:
if(OpenInfo != NULL)
{
FreePool (OpenInfo);
OpenInfo = NULL;
}
if(ProtocolGuidArray != NULL)
{
FreePool(ProtocolGuidArray);
ProtocolGuidArray = NULL;
}
if(mHandleBuffer != NULL)
{
FreePool (mHandleBuffer);
mHandleBuffer = NULL;
}
return Status;
}
EFI_STATUS
JudgeHandleIsPCIDevice(
EFI_HANDLE Handle,
UINT8 Device,
UINT8 Funs
)
{
EFI_STATUS Status;
EFI_DEVICE_PATH *DPath;
Status = gBS->HandleProtocol (
Handle,
&gEfiDevicePathProtocolGuid,
(VOID **) &DPath
);
if(!EFI_ERROR(Status))
{
while(!IsDevicePathEnd(DPath))
{
if((DPath->Type == HARDWARE_DEVICE_PATH) && (DPath->SubType == HW_PCI_DP))
{
PCI_DEVICE_PATH *PCIPath;
PCIPath = (PCI_DEVICE_PATH*) DPath;
DPath = NextDevicePathNode(DPath);
if(IsDevicePathEnd(DPath) && (PCIPath->Device == Device) && (PCIPath->Function == Funs))
{
return EFI_SUCCESS;
}
}
else
{
DPath = NextDevicePathNode(DPath);
}
}
}
return EFI_UNSUPPORTED;
}
EFI_STATUS
GetDriverName(
EFI_HANDLE Handle,
CHAR16 *Name
)
{
EFI_DRIVER_BINDING_PROTOCOL *BindHandle = NULL;
EFI_STATUS Status;
UINT32 Version;
UINT16 *Ptr;
Status = gBS->OpenProtocol(
Handle,
&gEfiDriverBindingProtocolGuid,
(VOID**)&BindHandle,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR(Status))
{
return EFI_NOT_FOUND;
}
Version = BindHandle->Version;
Ptr = (UINT16*)&Version;
UnicodeSPrint(Name, 40, L"%d.%d.%d", Version >> 24 , (Version >>16)& 0x0f ,*(Ptr));
return EFI_SUCCESS;
}
EFI_STATUS
GetGOPDriverName(
CHAR16 *Name
)
{
UINTN HandleCount;
EFI_HANDLE *Handles= NULL;
UINTN Index;
EFI_STATUS Status;
EFI_HANDLE Child = 0;
Status = gBS->LocateHandleBuffer(
ByProtocol,
&gEfiDriverBindingProtocolGuid,
NULL,
&HandleCount,
&Handles
);
for (Index = 0; Index < HandleCount ; Index++)
{
Status = SearchChildHandle(Handles[Index], &Child);
if(!EFI_ERROR(Status))
{
Status = JudgeHandleIsPCIDevice(
Child,
0x02,
0x00
);
if(!EFI_ERROR(Status))
{
return GetDriverName(Handles[Index], Name);
}
}
}
return EFI_UNSUPPORTED;
}
EFI_STATUS
UpdatePlatformInformation (
)
{
UINT32 MicroCodeVersion;
CHAR16 Buffer[40];
UINT8 IgdVBIOSRevH;
UINT8 IgdVBIOSRevL;
UINT16 EDX;
EFI_IA32_REGISTER_SET RegSet;
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios = NULL;
EFI_STATUS Status;
UINT8 CpuFlavor=0;
EFI_PEI_HOB_POINTERS GuidHob;
EFI_PLATFORM_INFO_HOB *mPlatformInfo=NULL;
UINTN NumHandles;
EFI_HANDLE *HandleBuffer;
UINTN Index;
DXE_PCH_PLATFORM_POLICY_PROTOCOL *PchPlatformPolicy;
UINTN PciD31F0RegBase;
UINT8 count;
UINT8 Data8;
UINT8 PIDData8;
CHAR16 Name[40];
UINT32 MrcVersion;
//
// Get the HOB list. If it is not present, then ASSERT.
//
GuidHob.Raw = GetHobList ();
if (GuidHob.Raw != NULL) {
if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
}
}
//
//VBIOS version
//
Status = gBS->LocateProtocol(
&gEfiLegacyBiosProtocolGuid,
NULL,
(void **)&LegacyBios
);
if (!EFI_ERROR (Status)) {
RegSet.X.AX = 0x5f01;
Status = LegacyBios->Int86 (LegacyBios, 0x10, &RegSet);
ASSERT_EFI_ERROR(Status);
//
// simulate AMI int15 (ax=5f01) handler
// check NbInt15.asm in AMI code for asm edition
//
EDX = (UINT16)((RegSet.E.EBX >> 16) & 0xffff);
IgdVBIOSRevH = (UINT8)(((EDX & 0x0F00) >> 4) | (EDX & 0x000F));
IgdVBIOSRevL = (UINT8)(((RegSet.X.BX & 0x0F00) >> 4) | (RegSet.X.BX & 0x000F));
if (IgdVBIOSRevH==0 && IgdVBIOSRevL==0){
HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), L"N/A", NULL);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%02X%02X", IgdVBIOSRevH,IgdVBIOSRevL);
HiiSetString(mHiiHandle, STRING_TOKEN(STR_CHIP_IGD_VBIOS_REV_VALUE), Buffer, NULL);
}
}
Status = GetGOPDriverName(Name);
if (!EFI_ERROR(Status))
{
HiiSetString(mHiiHandle, STRING_TOKEN(STR_GOP_VALUE), Name, NULL);
}
//
// CpuFlavor
// ISG-DC Tablet 000
// VLV-QC Tablet 001
// VLV-QC Desktop 010
// VLV-QC Notebook 011
//
CpuFlavor = RShiftU64 (EfiReadMsr (MSR_IA32_PLATFORM_ID), 50) & 0x07;
switch(CpuFlavor){
case 0x0:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-DC Tablet", CpuFlavor);
break;
case 0x01:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
break;
case 0x02:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Desktop", CpuFlavor);
break;
case 0x03:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"VLV-QC Notebook", CpuFlavor);
break;
default:
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s (%01x)", L"Unknown CPU", CpuFlavor);
break;
}
HiiSetString(mHiiHandle,STRING_TOKEN(STR_CPU_FLAVOR_VALUE), Buffer, NULL);
if ( NULL != mPlatformInfo) {
//
//BoardId
//
switch(mPlatformInfo->BoardId){
case 0x2:
UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE RVP(%02x)", mPlatformInfo->BoardId);
break;
case 0x4:
UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFRD(%02x)", mPlatformInfo->BoardId);
break;
case 0x5:
UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY ROCK RVP DDR3L (%02x)", mPlatformInfo->BoardId);
break;
case 0x20:
UnicodeSPrint (Buffer, sizeof (Buffer), L"BAYLEY BAY (%02x)", mPlatformInfo->BoardId);
break;
case 0x30:
UnicodeSPrint (Buffer, sizeof (Buffer), L"BAKER SPORT (%02x)", mPlatformInfo->BoardId);
break;
case 0x0:
UnicodeSPrint (Buffer, sizeof (Buffer), L"ALPINE VALLEY (%x)", mPlatformInfo->BoardId);
break;
case 0x3:
UnicodeSPrint (Buffer, sizeof (Buffer), L"BAY LAKE FFD8 (%x)", mPlatformInfo->BoardId);
break;
default:
UnicodeSPrint (Buffer, sizeof (Buffer), L"Unknown BOARD (%02x)", mPlatformInfo->BoardId);
break;
}
HiiSetString(mHiiHandle,STRING_TOKEN(STR_BOARD_ID_VALUE), Buffer, NULL);
//
// Get Board FAB ID Info from protocol, update into the NVS area.
// bit0~bit3 are for Fab ID, 0x0F means unknow FAB.
//
if(mPlatformInfo->BoardRev == 0x0F) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", L"Unknown FAB");
HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
} else {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%2x", mPlatformInfo->BoardRev);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_FAB_ID_VALUE), Buffer, NULL);
}
}
//
//Update MRC Version
//
MrcVersion = 0x00000000;
MrcVersion &= 0xffff;
Index = EfiValueToString (Buffer, MrcVersion/100, PREFIX_ZERO, 0);
StrCat (Buffer, L".");
EfiValueToString (Buffer + Index + 1, (MrcVersion%100)/10, PREFIX_ZERO, 0);
EfiValueToString (Buffer + Index + 2, (MrcVersion%100)%10, PREFIX_ZERO, 0);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_MRC_VERSION_VALUE), Buffer, NULL);
//
//Update Soc Version
//
//
// Retrieve all instances of PCH Platform Policy protocol
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gDxePchPlatformPolicyProtocolGuid,
NULL,
&NumHandles,
&HandleBuffer
);
if (!EFI_ERROR (Status)) {
//
// Find the matching PCH Policy protocol
//
for (Index = 0; Index < NumHandles; Index++) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gDxePchPlatformPolicyProtocolGuid,
(void **)&PchPlatformPolicy
);
if (!EFI_ERROR (Status)) {
PciD31F0RegBase = MmPciAddress (
0,
PchPlatformPolicy->BusNumber,
PCI_DEVICE_NUMBER_PCH_LPC,
PCI_FUNCTION_NUMBER_PCH_LPC,
0
);
Data8 = MmioRead8 (PciD31F0RegBase + R_PCH_LPC_RID_CC);
count = sizeof (SBRevisionTable) / sizeof (SBRevisionTable[0]);
for (Index = 0; Index < count; Index++) {
if(Data8 == SBRevisionTable[Index].RevId) {
UnicodeSPrint (Buffer, sizeof (Buffer), L"%02x %a", Data8, SBRevisionTable[Index].String);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_SOC_VALUE), Buffer, NULL);
break;
}
}
break;
}
}
}
//
// Microcode Revision
//
EfiWriteMsr (EFI_MSR_IA32_BIOS_SIGN_ID, 0);
EfiCpuid (EFI_CPUID_VERSION_INFO, NULL);
MicroCodeVersion = (UINT32) RShiftU64 (EfiReadMsr (EFI_MSR_IA32_BIOS_SIGN_ID), 32);
UnicodeSPrint (Buffer, sizeof (Buffer), L"%x", MicroCodeVersion);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_PROCESSOR_MICROCODE_VALUE), Buffer, NULL);
//
// Punit Version
//
Data8 = 0;
UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%x", Data8);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_PUNIT_FW_VALUE), Buffer, NULL);
//
// PMC Version
//
Data8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>16)&0x00FF);
PIDData8 = (UINT8)((MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PRSTS)>>24)&0x00FF);
UnicodeSPrint (Buffer, sizeof (Buffer), L"0x%X_%X",PIDData8, Data8);
HiiSetString(mHiiHandle,STRING_TOKEN(STR_PMC_FW_VALUE), Buffer, NULL);
return EFI_SUCCESS;
}
/**
Update SATA Drivesize Strings for Setup and Boot order
@param NewString - pointer to string.
@param DeviceSpeed - speed of drive.
**/
VOID
GetDeviceSpeedString (
CHAR16 *NewString,
IN UINTN DeviceSpeed
)
{
if (DeviceSpeed == 0x01) {
StrCat (NewString, L"1.5Gb/s");
} else if (DeviceSpeed == 0x02) {
StrCat (NewString, L"3.0Gb/s");
} else if (DeviceSpeed == 0x03) {
StrCat (NewString, L"6.0Gb/s");
} else if (DeviceSpeed == 0x0) {
}
}
UINT8
GetChipsetSataPortSpeed (
UINTN PortNum
)
{
UINT32 DeviceSpeed;
UINT8 DeviceConfigStatus;
UINT32 IdeAhciBar;
EFI_PHYSICAL_ADDRESS MemBaseAddress = 0;
UINT8 FunNum;
DeviceSpeed = 0x01; // generation 1
//
// Allocate the AHCI BAR
//
FunNum = PCI_FUNCTION_NUMBER_PCH_SATA;
MemBaseAddress = 0x0ffffffff;
gDS->AllocateMemorySpace (
EfiGcdAllocateMaxAddressSearchBottomUp,
EfiGcdMemoryTypeMemoryMappedIo,
N_PCH_SATA_ABAR_ALIGNMENT, // 2^11: 2K Alignment
V_PCH_SATA_ABAR_LENGTH, // 2K Length
&MemBaseAddress,
mImageHandle,
NULL
);
IdeAhciBar = MmioRead32 (
MmPciAddress (
0,
0,
PCI_DEVICE_NUMBER_PCH_SATA,
FunNum,
R_PCH_SATA_ABAR
)
);
IdeAhciBar &= 0xFFFFF800;
DeviceConfigStatus = 0;
if (IdeAhciBar == 0) {
DeviceConfigStatus = 1;
IdeAhciBar = (UINT32)MemBaseAddress;
MmioWrite32 (
MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
IdeAhciBar
);
MmioOr16 (
MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_COMMAND),
B_PCH_SATA_COMMAND_MSE
);
}
if (mSystemConfiguration.SataType == PCH_SATA_MODE_IDE){
//
// Program the "Ports Implemented Register"
//
MmioAndThenOr32 (IdeAhciBar + R_PCH_SATA_AHCI_PI, (UINT32)~(B_PCH_SATA_PORT0_IMPLEMENTED + B_PCH_SATA_PORT1_IMPLEMENTED), (UINT32)(B_PCH_SATA_PORT0_IMPLEMENTED + B_PCH_SATA_PORT1_IMPLEMENTED));
}
switch (PortNum)
{
case 0:
DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P0SSTS);
break;
case 1:
DeviceSpeed = *(volatile UINT32 *)(UINTN)(IdeAhciBar + R_PCH_SATA_AHCI_P1SSTS);
break;
}
if (MemBaseAddress) {
gDS->FreeMemorySpace (
MemBaseAddress,
V_PCH_SATA_ABAR_LENGTH
);
}
if (DeviceConfigStatus) {
IdeAhciBar = 0;
MmioWrite32 (
MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, FunNum, R_PCH_SATA_ABAR),
IdeAhciBar
);
}
DeviceSpeed = (UINT8)((DeviceSpeed >> 4) & 0x0F);
return (UINT8)DeviceSpeed;
}
/**
IDE data filter function.
**/
void
IdeDataFilter (void)
{
EFI_STATUS Status;
UINTN HandleCount;
EFI_HANDLE *HandleBuffer;
EFI_DISK_INFO_PROTOCOL *DiskInfo;
EFI_DEVICE_PATH_PROTOCOL *DevicePath, *DevicePathNode;
PCI_DEVICE_PATH *PciDevicePath;
UINTN Index;
UINT8 Index1;
UINT32 BufferSize;
UINT32 DriveSize;
UINT32 IdeChannel;
UINT32 IdeDevice;
EFI_ATA_IDENTIFY_DATA *IdentifyDriveInfo;
CHAR16 *NewString;
CHAR16 SizeString[20];
STRING_REF NameToUpdate;
CHAR8 StringBuffer[0x100];
UINT32 DeviceSpeed;
UINTN PortNumber;
//
// Assume no line strings is longer than 256 bytes.
//
NewString = AllocateZeroPool (0x100);
PciDevicePath = NULL;
//
// Fill IDE Infomation
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiDiskInfoProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
return;
}
for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiDevicePathProtocolGuid,
(VOID*)&DevicePath
);
ASSERT_EFI_ERROR (Status);
DevicePathNode = DevicePath;
while (!IsDevicePathEnd (DevicePathNode) ) {
if ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) &&
( DevicePathSubType (DevicePathNode) == HW_PCI_DP)) {
PciDevicePath = (PCI_DEVICE_PATH *) DevicePathNode;
break;
}
DevicePathNode = NextDevicePathNode (DevicePathNode);
}
if (PciDevicePath == NULL) {
continue;
}
//
// Check for onboard IDE
//
if (PciDevicePath->Device== PCI_DEVICE_NUMBER_PCH_SATA) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiDiskInfoProtocolGuid,
(void **)&DiskInfo
);
ASSERT_EFI_ERROR (Status);
Status = DiskInfo->WhichIde (
DiskInfo,
&IdeChannel,
&IdeDevice
);
ASSERT_EFI_ERROR (Status);
IdentifyDriveInfo = AllocatePool (sizeof(EFI_ATA_IDENTIFY_DATA));
BufferSize = sizeof(EFI_ATA_IDENTIFY_DATA);
Status = DiskInfo->Identify (
DiskInfo,
IdentifyDriveInfo,
&BufferSize
);
ASSERT_EFI_ERROR(Status);
//
// Onboard SATA Devices
//
if (PciDevicePath->Function == PCI_FUNCTION_NUMBER_PCH_SATA) {
if (IdeChannel == 0 && IdeDevice == 0) {
NameToUpdate = (STRING_REF)STR_SATA0_NAME;
} else if (IdeChannel == 1 && IdeDevice == 0) {
NameToUpdate = (STRING_REF)STR_SATA1_NAME;
} else {
continue;
}
} else {
continue;
}
ZeroMem(StringBuffer, sizeof(StringBuffer));
CopyMem(
StringBuffer,
(CHAR8 *)&IdentifyDriveInfo->ModelName,
sizeof(IdentifyDriveInfo->ModelName)
);
SwapEntries(StringBuffer);
AsciiToUnicode(StringBuffer, NewString);
//
// Chap it off after 16 characters
//
NewString[16] = 0;
//
// For HardDisk append the size. Otherwise display atapi
//
if ((IdentifyDriveInfo->config & 0x8000) == 00) {
//
// 48 bit address feature set is supported, get maximum capacity
//
if ((IdentifyDriveInfo->command_set_supported_83 & 0x0400) == 0) {
DriveSize = (((((IdentifyDriveInfo->user_addressable_sectors_hi << 16) +
IdentifyDriveInfo->user_addressable_sectors_lo) / 1000) * 512) / 1000);
} else {
DriveSize = IdentifyDriveInfo->maximum_lba_for_48bit_addressing[0];
for (Index1 = 1; Index1 < 4; Index1++) {
//
// Lower byte goes first: word[100] is the lowest word, word[103] is highest
//
DriveSize |= LShiftU64(IdentifyDriveInfo->maximum_lba_for_48bit_addressing[Index1], 16 * Index1);
}
DriveSize = (UINT32) DivU64x32(MultU64x32(DivU64x32(DriveSize, 1000), 512), 1000);
}
StrCat (NewString, L"(");
EfiValueToString (SizeString, DriveSize/1000, PREFIX_BLANK, 0);
StrCat (NewString, SizeString);
StrCat (NewString, L".");
EfiValueToString (SizeString, (DriveSize%1000)/100, PREFIX_BLANK, 0);
StrCat (NewString, SizeString);
StrCat (NewString, L"GB");
} else {
StrCat (NewString, L"(ATAPI");
}
//
// Update SPEED.
//
PortNumber = (IdeDevice << 1) + IdeChannel;
DeviceSpeed = GetChipsetSataPortSpeed(PortNumber);
if (DeviceSpeed) {
StrCat (NewString, L"-");
GetDeviceSpeedString( NewString, DeviceSpeed);
}
StrCat (NewString, L")");
HiiSetString(mHiiHandle, NameToUpdate, NewString, NULL);
}
}
if (HandleBuffer != NULL) {
gBS->FreePool (HandleBuffer);
}
gBS->FreePool(NewString);
return;
}
VOID
EFIAPI
SetupInfo (void)
{
EFI_STATUS Status;
UINTN VarSize;
EFI_PEI_HOB_POINTERS GuidHob;
if (mSetupInfoDone) {
return;
}
VarSize = sizeof(SYSTEM_CONFIGURATION);
Status = gRT->GetVariable(
NORMAL_SETUP_NAME,
&gEfiNormalSetupGuid,
NULL,
&VarSize,
&mSystemConfiguration
);
if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
//The setup variable is corrupted
VarSize = sizeof(SYSTEM_CONFIGURATION);
Status = gRT->GetVariable(
L"SetupRecovery",
&gEfiNormalSetupGuid,
NULL,
&VarSize,
&mSystemConfiguration
);
ASSERT_EFI_ERROR (Status);
}
//
// Update HOB variable for PCI resource information
// Get the HOB list. If it is not present, then ASSERT.
//
GuidHob.Raw = GetHobList ();
if (GuidHob.Raw != NULL) {
if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformInfoGuid, GuidHob.Raw)) != NULL) {
mPlatformInfo = GET_GUID_HOB_DATA (GuidHob.Guid);
}
}
PrepareSetupInformation();
UpdateAdditionalInformation ();
UpdatePlatformInformation();
UpdateCPUInformation();
IdeDataFilter();
mSetupInfoDone = TRUE;
return;
}
#define EFI_SECURE_BOOT_MODE_NAME L"SecureBoot"
VOID
CheckSystemConfigLoad(SYSTEM_CONFIGURATION *SystemConfigPtr)
{
EFI_STATUS Status;
UINT8 SecureBoot;
UINTN DataSize;
DataSize = sizeof(SecureBoot);
Status = gRT->GetVariable (
EFI_SECURE_BOOT_MODE_NAME,
&gEfiGlobalVariableGuid,
NULL,
&DataSize,
&SecureBoot
);
if (EFI_ERROR(Status)) {
SystemConfigPtr->SecureBoot = 0;
} else {
SystemConfigPtr->SecureBoot = SecureBoot;
}
}
//
// "SecureBootEnable" variable for the Secure boot feature enable/disable.
//
#define EFI_SECURE_BOOT_ENABLE_NAME L"SecureBootEnable"
extern EFI_GUID gEfiSecureBootEnableDisableGuid;
VOID
CheckSystemConfigSave(SYSTEM_CONFIGURATION *SystemConfigPtr)
{
EFI_STATUS Status;
UINT8 SecureBootCfg;
BOOLEAN SecureBootNotFound;
UINTN DataSize;
//
// Secure Boot configuration changes
//
DataSize = sizeof(SecureBootCfg);
SecureBootNotFound = FALSE;
Status = gRT->GetVariable (
EFI_SECURE_BOOT_ENABLE_NAME,
&gEfiSecureBootEnableDisableGuid,
NULL,
&DataSize,
&SecureBootCfg
);
if (EFI_ERROR(Status)) {
SecureBootNotFound = TRUE;
}
if (SecureBootNotFound) {
Status = gRT->GetVariable (
EFI_SECURE_BOOT_ENABLE_NAME,
&gEfiSecureBootEnableDisableGuid,
NULL,
&DataSize,
&SecureBootCfg
);
ASSERT_EFI_ERROR(Status);
}
if ((SecureBootCfg) != SystemConfigPtr->SecureBoot) {
SecureBootCfg = !SecureBootCfg;
Status = gRT->SetVariable (
EFI_SECURE_BOOT_ENABLE_NAME,
&gEfiSecureBootEnableDisableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (UINT8),
&SecureBootCfg
);
}
}
VOID
ConfirmSecureBootTest()
{
}
|