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
|
/** @file
SMM IPL that produces SMM related runtime protocols and load the SMM Core into SMRAM
Copyright (c) 2009 - 2016, 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.
**/
#include <PiDxe.h>
#include <Protocol/SmmBase2.h>
#include <Protocol/SmmCommunication.h>
#include <Protocol/SmmAccess2.h>
#include <Protocol/SmmConfiguration.h>
#include <Protocol/SmmControl2.h>
#include <Protocol/DxeSmmReadyToLock.h>
#include <Protocol/Cpu.h>
#include <Guid/EventGroup.h>
#include <Guid/EventLegacyBios.h>
#include <Guid/LoadModuleAtFixedAddress.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PeCoffLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/DxeServicesLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/PcdLib.h>
#include <Library/ReportStatusCodeLib.h>
#include "PiSmmCorePrivateData.h"
//
// Function prototypes from produced protocols
//
/**
Indicate whether the driver is currently executing in the SMM Initialization phase.
@param This The EFI_SMM_BASE2_PROTOCOL instance.
@param InSmram Pointer to a Boolean which, on return, indicates that the driver is currently executing
inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
@retval EFI_INVALID_PARAMETER InSmram was NULL.
@retval EFI_SUCCESS The call returned successfully.
**/
EFI_STATUS
EFIAPI
SmmBase2InSmram (
IN CONST EFI_SMM_BASE2_PROTOCOL *This,
OUT BOOLEAN *InSmram
);
/**
Retrieves the location of the System Management System Table (SMST).
@param This The EFI_SMM_BASE2_PROTOCOL instance.
@param Smst On return, points to a pointer to the System Management Service Table (SMST).
@retval EFI_INVALID_PARAMETER Smst or This was invalid.
@retval EFI_SUCCESS The memory was returned to the system.
@retval EFI_UNSUPPORTED Not in SMM.
**/
EFI_STATUS
EFIAPI
SmmBase2GetSmstLocation (
IN CONST EFI_SMM_BASE2_PROTOCOL *This,
OUT EFI_SMM_SYSTEM_TABLE2 **Smst
);
/**
Communicates with a registered handler.
This function provides a service to send and receive messages from a registered
UEFI service. This function is part of the SMM Communication Protocol that may
be called in physical mode prior to SetVirtualAddressMap() and in virtual mode
after SetVirtualAddressMap().
@param[in] This The EFI_SMM_COMMUNICATION_PROTOCOL instance.
@param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM.
@param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data
being returned. Zero if the handler does not wish to reply with any data.
@retval EFI_SUCCESS The message was successfully posted.
@retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
**/
EFI_STATUS
EFIAPI
SmmCommunicationCommunicate (
IN CONST EFI_SMM_COMMUNICATION_PROTOCOL *This,
IN OUT VOID *CommBuffer,
IN OUT UINTN *CommSize
);
/**
Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplSmmConfigurationEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Event notification that is fired every time a DxeSmmReadyToLock protocol is added
or if gEfiEventReadyToBootGuid is signalled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplReadyToLockEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Event notification that is fired when DxeDispatch Event Group is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplDxeDispatchEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Event notification that is fired when a GUIDed Event Group is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplGuidedEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Event notification that is fired when EndOfDxe Event Group is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplEndOfDxeEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
/**
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
It convers pointer to new virtual address.
@param Event Event whose notification function is being invoked.
@param Context Pointer to the notification function's context.
**/
VOID
EFIAPI
SmmIplSetVirtualAddressNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
//
// Data structure used to declare a table of protocol notifications and event
// notifications required by the SMM IPL
//
typedef struct {
BOOLEAN Protocol;
BOOLEAN CloseOnLock;
EFI_GUID *Guid;
EFI_EVENT_NOTIFY NotifyFunction;
VOID *NotifyContext;
EFI_TPL NotifyTpl;
EFI_EVENT Event;
} SMM_IPL_EVENT_NOTIFICATION;
//
// Handle to install the SMM Base2 Protocol and the SMM Communication Protocol
//
EFI_HANDLE mSmmIplHandle = NULL;
//
// SMM Base 2 Protocol instance
//
EFI_SMM_BASE2_PROTOCOL mSmmBase2 = {
SmmBase2InSmram,
SmmBase2GetSmstLocation
};
//
// SMM Communication Protocol instance
//
EFI_SMM_COMMUNICATION_PROTOCOL mSmmCommunication = {
SmmCommunicationCommunicate
};
//
// SMM Core Private Data structure that contains the data shared between
// the SMM IPL and the SMM Core.
//
SMM_CORE_PRIVATE_DATA mSmmCorePrivateData = {
SMM_CORE_PRIVATE_DATA_SIGNATURE, // Signature
NULL, // SmmIplImageHandle
0, // SmramRangeCount
NULL, // SmramRanges
NULL, // SmmEntryPoint
FALSE, // SmmEntryPointRegistered
FALSE, // InSmm
NULL, // Smst
NULL, // CommunicationBuffer
0, // BufferSize
EFI_SUCCESS // ReturnStatus
};
//
// Global pointer used to access mSmmCorePrivateData from outside and inside SMM
//
SMM_CORE_PRIVATE_DATA *gSmmCorePrivate = &mSmmCorePrivateData;
//
// SMM IPL global variables
//
EFI_SMM_CONTROL2_PROTOCOL *mSmmControl2;
EFI_SMM_ACCESS2_PROTOCOL *mSmmAccess;
EFI_SMRAM_DESCRIPTOR *mCurrentSmramRange;
BOOLEAN mSmmLocked = FALSE;
BOOLEAN mEndOfDxe = FALSE;
EFI_PHYSICAL_ADDRESS mSmramCacheBase;
UINT64 mSmramCacheSize;
EFI_SMM_COMMUNICATE_HEADER mCommunicateHeader;
//
// Table of Protocol notification and GUIDed Event notifications that the SMM IPL requires
//
SMM_IPL_EVENT_NOTIFICATION mSmmIplEvents[] = {
//
// Declare protocol notification on the SMM Configuration protocol. When this notification is etablished,
// the associated event is immediately signalled, so the notification function will be executed and the
// SMM Configuration Protocol will be found if it is already in the handle database.
//
{ TRUE, FALSE, &gEfiSmmConfigurationProtocolGuid, SmmIplSmmConfigurationEventNotify, &gEfiSmmConfigurationProtocolGuid, TPL_NOTIFY, NULL },
//
// Declare protocol notification on DxeSmmReadyToLock protocols. When this notification is established,
// the associated event is immediately signalled, so the notification function will be executed and the
// DXE SMM Ready To Lock Protocol will be found if it is already in the handle database.
//
{ TRUE, TRUE, &gEfiDxeSmmReadyToLockProtocolGuid, SmmIplReadyToLockEventNotify, &gEfiDxeSmmReadyToLockProtocolGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on EndOfDxe event. When this notification is etablished,
// the associated event is immediately signalled, so the notification function will be executed and the
// SMM End Of Dxe Protocol will be found if it is already in the handle database.
//
{ FALSE, TRUE, &gEfiEndOfDxeEventGroupGuid, SmmIplGuidedEventNotify, &gEfiEndOfDxeEventGroupGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on EndOfDxe event. This is used to set EndOfDxe event signaled flag.
//
{ FALSE, TRUE, &gEfiEndOfDxeEventGroupGuid, SmmIplEndOfDxeEventNotify, &gEfiEndOfDxeEventGroupGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on the DXE Dispatch Event Group. This event is signaled by the DXE Core
// each time the DXE Core dispatcher has completed its work. When this event is signalled, the SMM Core
// if notified, so the SMM Core can dispatch SMM drivers.
//
{ FALSE, TRUE, &gEfiEventDxeDispatchGuid, SmmIplDxeDispatchEventNotify, &gEfiEventDxeDispatchGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on Ready To Boot Event Group. This is an extra event notification that is
// used to make sure SMRAM is locked before any boot options are processed.
//
{ FALSE, TRUE, &gEfiEventReadyToBootGuid, SmmIplReadyToLockEventNotify, &gEfiEventReadyToBootGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on Legacy Boot Event Group. This is used to inform the SMM Core that the platform
// is performing a legacy boot operation, and that the UEFI environment is no longer available and the SMM Core
// must guarantee that it does not access any UEFI related structures outside of SMRAM.
// It is also to inform the SMM Core to notify SMM driver that system enter legacy boot.
//
{ FALSE, FALSE, &gEfiEventLegacyBootGuid, SmmIplGuidedEventNotify, &gEfiEventLegacyBootGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on Exit Boot Services Event Group. This is used to inform the SMM Core
// to notify SMM driver that system enter exit boot services.
//
{ FALSE, FALSE, &gEfiEventExitBootServicesGuid, SmmIplGuidedEventNotify, &gEfiEventExitBootServicesGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on Ready To Boot Event Group. This is used to inform the SMM Core
// to notify SMM driver that system enter ready to boot.
//
{ FALSE, FALSE, &gEfiEventReadyToBootGuid, SmmIplGuidedEventNotify, &gEfiEventReadyToBootGuid, TPL_CALLBACK, NULL },
//
// Declare event notification on SetVirtualAddressMap() Event Group. This is used to convert gSmmCorePrivate
// and mSmmControl2 from physical addresses to virtual addresses.
//
{ FALSE, FALSE, &gEfiEventVirtualAddressChangeGuid, SmmIplSetVirtualAddressNotify, NULL, TPL_CALLBACK, NULL },
//
// Terminate the table of event notifications
//
{ FALSE, FALSE, NULL, NULL, NULL, TPL_CALLBACK, NULL }
};
/**
Find the maximum SMRAM cache range that covers the range specified by SmramRange.
This function searches and joins all adjacent ranges of SmramRange into a range to be cached.
@param SmramRange The SMRAM range to search from.
@param SmramCacheBase The returned cache range base.
@param SmramCacheSize The returned cache range size.
**/
VOID
GetSmramCacheRange (
IN EFI_SMRAM_DESCRIPTOR *SmramRange,
OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
OUT UINT64 *SmramCacheSize
)
{
UINTN Index;
EFI_PHYSICAL_ADDRESS RangeCpuStart;
UINT64 RangePhysicalSize;
BOOLEAN FoundAjacentRange;
*SmramCacheBase = SmramRange->CpuStart;
*SmramCacheSize = SmramRange->PhysicalSize;
do {
FoundAjacentRange = FALSE;
for (Index = 0; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
RangeCpuStart = gSmmCorePrivate->SmramRanges[Index].CpuStart;
RangePhysicalSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
if (RangeCpuStart < *SmramCacheBase && *SmramCacheBase == (RangeCpuStart + RangePhysicalSize)) {
*SmramCacheBase = RangeCpuStart;
*SmramCacheSize += RangePhysicalSize;
FoundAjacentRange = TRUE;
} else if ((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart && RangePhysicalSize > 0) {
*SmramCacheSize += RangePhysicalSize;
FoundAjacentRange = TRUE;
}
}
} while (FoundAjacentRange);
}
/**
Indicate whether the driver is currently executing in the SMM Initialization phase.
@param This The EFI_SMM_BASE2_PROTOCOL instance.
@param InSmram Pointer to a Boolean which, on return, indicates that the driver is currently executing
inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
@retval EFI_INVALID_PARAMETER InSmram was NULL.
@retval EFI_SUCCESS The call returned successfully.
**/
EFI_STATUS
EFIAPI
SmmBase2InSmram (
IN CONST EFI_SMM_BASE2_PROTOCOL *This,
OUT BOOLEAN *InSmram
)
{
if (InSmram == NULL) {
return EFI_INVALID_PARAMETER;
}
*InSmram = gSmmCorePrivate->InSmm;
return EFI_SUCCESS;
}
/**
Retrieves the location of the System Management System Table (SMST).
@param This The EFI_SMM_BASE2_PROTOCOL instance.
@param Smst On return, points to a pointer to the System Management Service Table (SMST).
@retval EFI_INVALID_PARAMETER Smst or This was invalid.
@retval EFI_SUCCESS The memory was returned to the system.
@retval EFI_UNSUPPORTED Not in SMM.
**/
EFI_STATUS
EFIAPI
SmmBase2GetSmstLocation (
IN CONST EFI_SMM_BASE2_PROTOCOL *This,
OUT EFI_SMM_SYSTEM_TABLE2 **Smst
)
{
if ((This == NULL) ||(Smst == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (!gSmmCorePrivate->InSmm) {
return EFI_UNSUPPORTED;
}
*Smst = gSmmCorePrivate->Smst;
return EFI_SUCCESS;
}
/**
Communicates with a registered handler.
This function provides a service to send and receive messages from a registered
UEFI service. This function is part of the SMM Communication Protocol that may
be called in physical mode prior to SetVirtualAddressMap() and in virtual mode
after SetVirtualAddressMap().
@param[in] This The EFI_SMM_COMMUNICATION_PROTOCOL instance.
@param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM.
@param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data
being returned. Zero if the handler does not wish to reply with any data.
@retval EFI_SUCCESS The message was successfully posted.
@retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
**/
EFI_STATUS
EFIAPI
SmmCommunicationCommunicate (
IN CONST EFI_SMM_COMMUNICATION_PROTOCOL *This,
IN OUT VOID *CommBuffer,
IN OUT UINTN *CommSize
)
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
BOOLEAN OldInSmm;
//
// Check parameters
//
if ((CommBuffer == NULL) || (CommSize == NULL)) {
return EFI_INVALID_PARAMETER;
}
//
// CommSize must hold HeaderGuid and MessageLength
//
if (*CommSize < OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)) {
return EFI_INVALID_PARAMETER;
}
//
// If not already in SMM, then generate a Software SMI
//
if (!gSmmCorePrivate->InSmm && gSmmCorePrivate->SmmEntryPointRegistered) {
//
// Put arguments for Software SMI in gSmmCorePrivate
//
gSmmCorePrivate->CommunicationBuffer = CommBuffer;
gSmmCorePrivate->BufferSize = *CommSize;
//
// Generate Software SMI
//
Status = mSmmControl2->Trigger (mSmmControl2, NULL, NULL, FALSE, 0);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Return status from software SMI
//
*CommSize = gSmmCorePrivate->BufferSize;
return gSmmCorePrivate->ReturnStatus;
}
//
// If we are in SMM, then the execution mode must be physical, which means that
// OS established virtual addresses can not be used. If SetVirtualAddressMap()
// has been called, then a direct invocation of the Software SMI is not
// not allowed so return EFI_INVALID_PARAMETER.
//
if (EfiGoneVirtual()) {
return EFI_INVALID_PARAMETER;
}
//
// If we are not in SMM, don't allow call SmiManage() directly when SMRAM is closed or locked.
//
if ((!gSmmCorePrivate->InSmm) && (!mSmmAccess->OpenState || mSmmAccess->LockState)) {
return EFI_INVALID_PARAMETER;
}
//
// Save current InSmm state and set InSmm state to TRUE
//
OldInSmm = gSmmCorePrivate->InSmm;
gSmmCorePrivate->InSmm = TRUE;
//
// Already in SMM and before SetVirtualAddressMap(), so call SmiManage() directly.
//
CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommBuffer;
*CommSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
Status = gSmmCorePrivate->Smst->SmiManage (
&CommunicateHeader->HeaderGuid,
NULL,
CommunicateHeader->Data,
CommSize
);
//
// Update CommunicationBuffer, BufferSize and ReturnStatus
// Communicate service finished, reset the pointer to CommBuffer to NULL
//
*CommSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
//
// Restore original InSmm state
//
gSmmCorePrivate->InSmm = OldInSmm;
return (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
}
/**
Event notification that is fired when GUIDed Event Group is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplGuidedEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
UINTN Size;
//
// Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
//
CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
mCommunicateHeader.MessageLength = 1;
mCommunicateHeader.Data[0] = 0;
//
// Generate the Software SMI and return the result
//
Size = sizeof (mCommunicateHeader);
SmmCommunicationCommunicate (&mSmmCommunication, &mCommunicateHeader, &Size);
}
/**
Event notification that is fired when EndOfDxe Event Group is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplEndOfDxeEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
mEndOfDxe = TRUE;
}
/**
Event notification that is fired when DxeDispatch Event Group is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplDxeDispatchEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
UINTN Size;
EFI_STATUS Status;
//
// Keep calling the SMM Core Dispatcher until there is no request to restart it.
//
while (TRUE) {
//
// Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
// Clear the buffer passed into the Software SMI. This buffer will return
// the status of the SMM Core Dispatcher.
//
CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
mCommunicateHeader.MessageLength = 1;
mCommunicateHeader.Data[0] = 0;
//
// Generate the Software SMI and return the result
//
Size = sizeof (mCommunicateHeader);
SmmCommunicationCommunicate (&mSmmCommunication, &mCommunicateHeader, &Size);
//
// Return if there is no request to restart the SMM Core Dispatcher
//
if (mCommunicateHeader.Data[0] != COMM_BUFFER_SMM_DISPATCH_RESTART) {
return;
}
//
// Attempt to reset SMRAM cacheability to UC
// Assume CPU AP is available at this time
//
Status = gDS->SetMemorySpaceAttributes(
mSmramCacheBase,
mSmramCacheSize,
EFI_MEMORY_UC
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "SMM IPL failed to reset SMRAM window to EFI_MEMORY_UC\n"));
}
//
// Close all SMRAM ranges to protect SMRAM
//
Status = mSmmAccess->Close (mSmmAccess);
ASSERT_EFI_ERROR (Status);
//
// Print debug message that the SMRAM window is now closed.
//
DEBUG ((DEBUG_INFO, "SMM IPL closed SMRAM window\n"));
}
}
/**
Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplSmmConfigurationEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
//
// Make sure this notification is for this handler
//
Status = gBS->LocateProtocol (Context, NULL, (VOID **)&SmmConfiguration);
if (EFI_ERROR (Status)) {
return;
}
//
// Register the SMM Entry Point provided by the SMM Core with the SMM COnfiguration protocol
//
Status = SmmConfiguration->RegisterSmmEntry (SmmConfiguration, gSmmCorePrivate->SmmEntryPoint);
ASSERT_EFI_ERROR (Status);
//
// Set flag to indicate that the SMM Entry Point has been registered which
// means that SMIs are now fully operational.
//
gSmmCorePrivate->SmmEntryPointRegistered = TRUE;
//
// Print debug message showing SMM Core entry point address.
//
DEBUG ((DEBUG_INFO, "SMM IPL registered SMM Entry Point address %p\n", (VOID *)(UINTN)gSmmCorePrivate->SmmEntryPoint));
}
/**
Event notification that is fired every time a DxeSmmReadyToLock protocol is added
or if gEfiEventReadyToBootGuid is signaled.
@param Event The Event that is being processed, not used.
@param Context Event Context, not used.
**/
VOID
EFIAPI
SmmIplReadyToLockEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
VOID *Interface;
UINTN Index;
//
// See if we are already locked
//
if (mSmmLocked) {
return;
}
//
// Make sure this notification is for this handler
//
if (CompareGuid ((EFI_GUID *)Context, &gEfiDxeSmmReadyToLockProtocolGuid)) {
Status = gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL, &Interface);
if (EFI_ERROR (Status)) {
return;
}
} else {
//
// If SMM is not locked yet and we got here from gEfiEventReadyToBootGuid being
// signaled, then gEfiDxeSmmReadyToLockProtocolGuid was not installed as expected.
// Print a warning on debug builds.
//
DEBUG ((DEBUG_WARN, "SMM IPL! DXE SMM Ready To Lock Protocol not installed before Ready To Boot signal\n"));
}
if (!mEndOfDxe) {
DEBUG ((DEBUG_ERROR, "EndOfDxe Event must be signaled before DxeSmmReadyToLock Protocol installation!\n"));
REPORT_STATUS_CODE (
EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,
(EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)
);
ASSERT (FALSE);
}
//
// Lock the SMRAM (Note: Locking SMRAM may not be supported on all platforms)
//
mSmmAccess->Lock (mSmmAccess);
//
// Close protocol and event notification events that do not apply after the
// DXE SMM Ready To Lock Protocol has been installed or the Ready To Boot
// event has been signalled.
//
for (Index = 0; mSmmIplEvents[Index].NotifyFunction != NULL; Index++) {
if (mSmmIplEvents[Index].CloseOnLock) {
gBS->CloseEvent (mSmmIplEvents[Index].Event);
}
}
//
// Inform SMM Core that the DxeSmmReadyToLock protocol was installed
//
SmmIplGuidedEventNotify (Event, (VOID *)&gEfiDxeSmmReadyToLockProtocolGuid);
//
// Print debug message that the SMRAM window is now locked.
//
DEBUG ((DEBUG_INFO, "SMM IPL locked SMRAM window\n"));
//
// Set flag so this operation will not be performed again
//
mSmmLocked = TRUE;
}
/**
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
It convers pointer to new virtual address.
@param Event Event whose notification function is being invoked.
@param Context Pointer to the notification function's context.
**/
VOID
EFIAPI
SmmIplSetVirtualAddressNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EfiConvertPointer (0x0, (VOID **)&mSmmControl2);
}
/**
Get the fixed loadding address from image header assigned by build tool. This function only be called
when Loading module at Fixed address feature enabled.
@param ImageContext Pointer to the image context structure that describes the PE/COFF
image that needs to be examined by this function.
@retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
@retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
**/
EFI_STATUS
GetPeCoffImageFixLoadingAssignedAddress(
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
UINTN SectionHeaderOffset;
EFI_STATUS Status;
EFI_IMAGE_SECTION_HEADER SectionHeader;
EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
EFI_PHYSICAL_ADDRESS FixLoaddingAddress;
UINT16 Index;
UINTN Size;
UINT16 NumberOfSections;
EFI_PHYSICAL_ADDRESS SmramBase;
UINT64 SmmCodeSize;
UINT64 ValueInSectionHeader;
//
// Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
//
SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32(PcdLoadFixAddressSmmCodePageNumber));
FixLoaddingAddress = 0;
Status = EFI_NOT_FOUND;
SmramBase = mCurrentSmramRange->CpuStart;
//
// Get PeHeader pointer
//
ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
SectionHeaderOffset = (UINTN)(
ImageContext->PeCoffHeaderOffset +
sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER) +
ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
);
NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
//
// Get base address from the first section header that doesn't point to code section.
//
for (Index = 0; Index < NumberOfSections; Index++) {
//
// Read section header from file
//
Size = sizeof (EFI_IMAGE_SECTION_HEADER);
Status = ImageContext->ImageRead (
ImageContext->Handle,
SectionHeaderOffset,
&Size,
&SectionHeader
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = EFI_NOT_FOUND;
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
//
// Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
// first section header that doesn't point to code section in image header. And there is an assumption that when the
// feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers
// fields should NOT be Zero, or else, these 2 fileds should be set to Zero
//
ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
if (ValueInSectionHeader != 0) {
//
// Found first section header that doesn't point to code section in which uild tool saves the
// offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
//
FixLoaddingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
if (SmramBase + SmmCodeSize > FixLoaddingAddress && SmramBase <= FixLoaddingAddress) {
//
// The assigned address is valid. Return the specified loadding address
//
ImageContext->ImageAddress = FixLoaddingAddress;
Status = EFI_SUCCESS;
}
}
break;
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoaddingAddress, Status));
return Status;
}
/**
Load the SMM Core image into SMRAM and executes the SMM Core from SMRAM.
@param[in, out] SmramRange Descriptor for the range of SMRAM to reload the
currently executing image, the rang of SMRAM to
hold SMM Core will be excluded.
@param[in, out] SmramRangeSmmCore Descriptor for the range of SMRAM to hold SMM Core.
@param[in] Context Context to pass into SMM Core
@return EFI_STATUS
**/
EFI_STATUS
ExecuteSmmCoreFromSmram (
IN OUT EFI_SMRAM_DESCRIPTOR *SmramRange,
IN OUT EFI_SMRAM_DESCRIPTOR *SmramRangeSmmCore,
IN VOID *Context
)
{
EFI_STATUS Status;
VOID *SourceBuffer;
UINTN SourceSize;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
UINTN PageCount;
EFI_IMAGE_ENTRY_POINT EntryPoint;
//
// Search all Firmware Volumes for a PE/COFF image in a file of type SMM_CORE
//
Status = GetSectionFromAnyFvByFileType (
EFI_FV_FILETYPE_SMM_CORE,
0,
EFI_SECTION_PE32,
0,
&SourceBuffer,
&SourceSize
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Initilize ImageContext
//
ImageContext.Handle = SourceBuffer;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
//
// Get information about the image being loaded
//
Status = PeCoffLoaderGetImageInfo (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
//
// if Loading module at Fixed Address feature is enabled, the SMM core driver will be loaded to
// the address assigned by build tool.
//
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Get the fixed loading address assigned by Build tool
//
Status = GetPeCoffImageFixLoadingAssignedAddress (&ImageContext);
if (!EFI_ERROR (Status)) {
//
// Since the memory range to load SMM CORE will be cut out in SMM core, so no need to allocate and free this range
//
PageCount = 0;
} else {
DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR: Loading module at fixed address at address failed\n"));
//
// Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
// specified by SmramRange
//
PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
//
// Align buffer on section boundary
//
ImageContext.ImageAddress = SmramRangeSmmCore->CpuStart;
}
} else {
//
// Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
// specified by SmramRange
//
PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
//
// Align buffer on section boundary
//
ImageContext.ImageAddress = SmramRangeSmmCore->CpuStart;
}
ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
//
// Print debug message showing SMM Core load address.
//
DEBUG ((DEBUG_INFO, "SMM IPL loading SMM Core at SMRAM address %p\n", (VOID *)(UINTN)ImageContext.ImageAddress));
//
// Load the image to our new buffer
//
Status = PeCoffLoaderLoadImage (&ImageContext);
if (!EFI_ERROR (Status)) {
//
// Relocate the image in our new buffer
//
Status = PeCoffLoaderRelocateImage (&ImageContext);
if (!EFI_ERROR (Status)) {
//
// Flush the instruction cache so the image data are written before we execute it
//
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
//
// Print debug message showing SMM Core entry point address.
//
DEBUG ((DEBUG_INFO, "SMM IPL calling SMM Core at SMRAM address %p\n", (VOID *)(UINTN)ImageContext.EntryPoint));
gSmmCorePrivate->PiSmmCoreImageBase = ImageContext.ImageAddress;
gSmmCorePrivate->PiSmmCoreImageSize = ImageContext.ImageSize;
DEBUG ((DEBUG_INFO, "PiSmmCoreImageBase - 0x%016lx\n", gSmmCorePrivate->PiSmmCoreImageBase));
DEBUG ((DEBUG_INFO, "PiSmmCoreImageSize - 0x%016lx\n", gSmmCorePrivate->PiSmmCoreImageSize));
gSmmCorePrivate->PiSmmCoreEntryPoint = ImageContext.EntryPoint;
//
// Execute image
//
EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)ImageContext.EntryPoint;
Status = EntryPoint ((EFI_HANDLE)Context, gST);
}
}
//
// Always free memory allocted by GetFileBufferByFilePath ()
//
FreePool (SourceBuffer);
return Status;
}
/**
SMM split SMRAM entry.
@param[in, out] RangeToCompare Pointer to EFI_SMRAM_DESCRIPTOR to compare.
@param[in, out] ReservedRangeToCompare Pointer to EFI_SMM_RESERVED_SMRAM_REGION to compare.
@param[out] Ranges Output pointer to hold split EFI_SMRAM_DESCRIPTOR entry.
@param[in, out] RangeCount Pointer to range count.
@param[out] ReservedRanges Output pointer to hold split EFI_SMM_RESERVED_SMRAM_REGION entry.
@param[in, out] ReservedRangeCount Pointer to reserved range count.
@param[out] FinalRanges Output pointer to hold split final EFI_SMRAM_DESCRIPTOR entry
that no need to be split anymore.
@param[in, out] FinalRangeCount Pointer to final range count.
**/
VOID
SmmSplitSmramEntry (
IN OUT EFI_SMRAM_DESCRIPTOR *RangeToCompare,
IN OUT EFI_SMM_RESERVED_SMRAM_REGION *ReservedRangeToCompare,
OUT EFI_SMRAM_DESCRIPTOR *Ranges,
IN OUT UINTN *RangeCount,
OUT EFI_SMM_RESERVED_SMRAM_REGION *ReservedRanges,
IN OUT UINTN *ReservedRangeCount,
OUT EFI_SMRAM_DESCRIPTOR *FinalRanges,
IN OUT UINTN *FinalRangeCount
)
{
UINT64 RangeToCompareEnd;
UINT64 ReservedRangeToCompareEnd;
RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
(RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
if (RangeToCompareEnd < ReservedRangeToCompareEnd) {
//
// RangeToCompare ReservedRangeToCompare
// ---- ---- --------------------------------------
// | | | | -> 1. ReservedRangeToCompare
// ---- | | |--| --------------------------------------
// | | | | | |
// | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
// | | | | | | RangeToCompare->PhysicalSize = 0
// ---- | | |--| --------------------------------------
// | | | | -> 3. ReservedRanges[*ReservedRangeCount] and increment *ReservedRangeCount
// ---- ---- --------------------------------------
//
//
// 1. Update ReservedRangeToCompare.
//
ReservedRangeToCompare->SmramReservedSize = RangeToCompare->CpuStart - ReservedRangeToCompare->SmramReservedStart;
//
// 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
// Zero RangeToCompare->PhysicalSize.
//
FinalRanges[*FinalRangeCount].CpuStart = RangeToCompare->CpuStart;
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompare->PhysicalSize;
*FinalRangeCount += 1;
RangeToCompare->PhysicalSize = 0;
//
// 3. Update ReservedRanges[*ReservedRangeCount] and increment *ReservedRangeCount.
//
ReservedRanges[*ReservedRangeCount].SmramReservedStart = FinalRanges[*FinalRangeCount - 1].CpuStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
ReservedRanges[*ReservedRangeCount].SmramReservedSize = ReservedRangeToCompareEnd - RangeToCompareEnd;
*ReservedRangeCount += 1;
} else {
//
// RangeToCompare ReservedRangeToCompare
// ---- ---- --------------------------------------
// | | | | -> 1. ReservedRangeToCompare
// ---- | | |--| --------------------------------------
// | | | | | |
// | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
// | | | | | |
// | | ---- |--| --------------------------------------
// | | | | -> 3. RangeToCompare
// ---- ---- --------------------------------------
//
//
// 1. Update ReservedRangeToCompare.
//
ReservedRangeToCompare->SmramReservedSize = RangeToCompare->CpuStart - ReservedRangeToCompare->SmramReservedStart;
//
// 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
//
FinalRanges[*FinalRangeCount].CpuStart = RangeToCompare->CpuStart;
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompareEnd - RangeToCompare->CpuStart;
*FinalRangeCount += 1;
//
// 3. Update RangeToCompare.
//
RangeToCompare->CpuStart += FinalRanges[*FinalRangeCount - 1].PhysicalSize;
RangeToCompare->PhysicalStart += FinalRanges[*FinalRangeCount - 1].PhysicalSize;
RangeToCompare->PhysicalSize -= FinalRanges[*FinalRangeCount - 1].PhysicalSize;
}
} else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
(ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
if (ReservedRangeToCompareEnd < RangeToCompareEnd) {
//
// RangeToCompare ReservedRangeToCompare
// ---- ---- --------------------------------------
// | | | | -> 1. RangeToCompare
// | | ---- |--| --------------------------------------
// | | | | | |
// | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
// | | | | | | ReservedRangeToCompare->SmramReservedSize = 0
// | | ---- |--| --------------------------------------
// | | | | -> 3. Ranges[*RangeCount] and increment *RangeCount
// ---- ---- --------------------------------------
//
//
// 1. Update RangeToCompare.
//
RangeToCompare->PhysicalSize = ReservedRangeToCompare->SmramReservedStart - RangeToCompare->CpuStart;
//
// 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
// ReservedRangeToCompare->SmramReservedSize = 0
//
FinalRanges[*FinalRangeCount].CpuStart = ReservedRangeToCompare->SmramReservedStart;
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompare->SmramReservedSize;
*FinalRangeCount += 1;
ReservedRangeToCompare->SmramReservedSize = 0;
//
// 3. Update Ranges[*RangeCount] and increment *RangeCount.
//
Ranges[*RangeCount].CpuStart = FinalRanges[*FinalRangeCount - 1].CpuStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
Ranges[*RangeCount].PhysicalStart = FinalRanges[*FinalRangeCount - 1].PhysicalStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
Ranges[*RangeCount].RegionState = RangeToCompare->RegionState;
Ranges[*RangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompareEnd;
*RangeCount += 1;
} else {
//
// RangeToCompare ReservedRangeToCompare
// ---- ---- --------------------------------------
// | | | | -> 1. RangeToCompare
// | | ---- |--| --------------------------------------
// | | | | | |
// | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
// | | | | | |
// ---- | | |--| --------------------------------------
// | | | | -> 3. ReservedRangeToCompare
// ---- ---- --------------------------------------
//
//
// 1. Update RangeToCompare.
//
RangeToCompare->PhysicalSize = ReservedRangeToCompare->SmramReservedStart - RangeToCompare->CpuStart;
//
// 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
// ReservedRangeToCompare->SmramReservedSize = 0
//
FinalRanges[*FinalRangeCount].CpuStart = ReservedRangeToCompare->SmramReservedStart;
FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompare->SmramReservedStart;
*FinalRangeCount += 1;
//
// 3. Update ReservedRangeToCompare.
//
ReservedRangeToCompare->SmramReservedStart += FinalRanges[*FinalRangeCount - 1].PhysicalSize;
ReservedRangeToCompare->SmramReservedSize -= FinalRanges[*FinalRangeCount - 1].PhysicalSize;
}
}
}
/**
Returns if SMRAM range and SMRAM reserved range are overlapped.
@param[in] RangeToCompare Pointer to EFI_SMRAM_DESCRIPTOR to compare.
@param[in] ReservedRangeToCompare Pointer to EFI_SMM_RESERVED_SMRAM_REGION to compare.
@retval TRUE There is overlap.
@retval FALSE There is no overlap.
**/
BOOLEAN
SmmIsSmramOverlap (
IN EFI_SMRAM_DESCRIPTOR *RangeToCompare,
IN EFI_SMM_RESERVED_SMRAM_REGION *ReservedRangeToCompare
)
{
UINT64 RangeToCompareEnd;
UINT64 ReservedRangeToCompareEnd;
RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
(RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
return TRUE;
} else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
(ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
return TRUE;
}
return FALSE;
}
/**
Get full SMRAM ranges.
It will get SMRAM ranges from SmmAccess protocol and SMRAM reserved ranges from
SmmConfiguration protocol, split the entries if there is overlap between them.
It will also reserve one entry for SMM core.
@param[out] FullSmramRangeCount Output pointer to full SMRAM range count.
@return Pointer to full SMRAM ranges.
**/
EFI_SMRAM_DESCRIPTOR *
GetFullSmramRanges (
OUT UINTN *FullSmramRangeCount
)
{
EFI_STATUS Status;
EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
UINTN Size;
UINTN Index;
UINTN Index2;
EFI_SMRAM_DESCRIPTOR *FullSmramRanges;
UINTN TempSmramRangeCount;
EFI_SMRAM_DESCRIPTOR *TempSmramRanges;
UINTN SmramRangeCount;
EFI_SMRAM_DESCRIPTOR *SmramRanges;
UINTN SmramReservedCount;
EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
UINTN MaxCount;
BOOLEAN Rescan;
//
// Get SMM Configuration Protocol if it is present.
//
SmmConfiguration = NULL;
Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **) &SmmConfiguration);
//
// Get SMRAM information.
//
Size = 0;
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, NULL);
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
SmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);
//
// Get SMRAM reserved region count.
//
SmramReservedCount = 0;
if (SmmConfiguration != NULL) {
while (SmmConfiguration->SmramReservedRegions[SmramReservedCount].SmramReservedSize != 0) {
SmramReservedCount++;
}
}
if (SmramReservedCount == 0) {
//
// No reserved SMRAM entry from SMM Configuration Protocol.
// Reserve one entry for SMM Core in the full SMRAM ranges.
//
*FullSmramRangeCount = SmramRangeCount + 1;
Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocateZeroPool (Size);
ASSERT (FullSmramRanges != NULL);
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, FullSmramRanges);
ASSERT_EFI_ERROR (Status);
return FullSmramRanges;
}
//
// Why MaxCount = X + 2 * Y?
// Take Y = 1 as example below, Y > 1 case is just the iteration of Y = 1.
//
// X = 1 Y = 1 MaxCount = 3 = 1 + 2 * 1
// ---- ----
// | | ---- |--|
// | | | | -> | |
// | | ---- |--|
// ---- ----
//
// X = 2 Y = 1 MaxCount = 4 = 2 + 2 * 1
// ---- ----
// | | | |
// | | ---- |--|
// | | | | | |
// |--| | | -> |--|
// | | | | | |
// | | ---- |--|
// | | | |
// ---- ----
//
// X = 3 Y = 1 MaxCount = 5 = 3 + 2 * 1
// ---- ----
// | | | |
// | | ---- |--|
// |--| | | |--|
// | | | | -> | |
// |--| | | |--|
// | | ---- |--|
// | | | |
// ---- ----
//
// ......
//
MaxCount = SmramRangeCount + 2 * SmramReservedCount;
Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *) AllocatePool (Size);
ASSERT (SmramReservedRanges != NULL);
for (Index = 0; Index < SmramReservedCount; Index++) {
CopyMem (&SmramReservedRanges[Index], &SmmConfiguration->SmramReservedRegions[Index], sizeof (EFI_SMM_RESERVED_SMRAM_REGION));
}
Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
ASSERT (TempSmramRanges != NULL);
TempSmramRangeCount = 0;
SmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
ASSERT (SmramRanges != NULL);
Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, SmramRanges);
ASSERT_EFI_ERROR (Status);
do {
Rescan = FALSE;
for (Index = 0; (Index < SmramRangeCount) && !Rescan; Index++) {
//
// Skip zero size entry.
//
if (SmramRanges[Index].PhysicalSize != 0) {
for (Index2 = 0; (Index2 < SmramReservedCount) && !Rescan; Index2++) {
//
// Skip zero size entry.
//
if (SmramReservedRanges[Index2].SmramReservedSize != 0) {
if (SmmIsSmramOverlap (
&SmramRanges[Index],
&SmramReservedRanges[Index2]
)) {
//
// There is overlap, need to split entry and then rescan.
//
SmmSplitSmramEntry (
&SmramRanges[Index],
&SmramReservedRanges[Index2],
SmramRanges,
&SmramRangeCount,
SmramReservedRanges,
&SmramReservedCount,
TempSmramRanges,
&TempSmramRangeCount
);
Rescan = TRUE;
}
}
}
if (!Rescan) {
//
// No any overlap, copy the entry to the temp SMRAM ranges.
// Zero SmramRanges[Index].PhysicalSize = 0;
//
CopyMem (&TempSmramRanges[TempSmramRangeCount++], &SmramRanges[Index], sizeof (EFI_SMRAM_DESCRIPTOR));
SmramRanges[Index].PhysicalSize = 0;
}
}
}
} while (Rescan);
ASSERT (TempSmramRangeCount <= MaxCount);
//
// Sort the entries,
// and reserve one entry for SMM Core in the full SMRAM ranges.
//
FullSmramRanges = AllocateZeroPool ((TempSmramRangeCount + 1) * sizeof (EFI_SMRAM_DESCRIPTOR));
ASSERT (FullSmramRanges != NULL);
*FullSmramRangeCount = 0;
do {
for (Index = 0; Index < TempSmramRangeCount; Index++) {
if (TempSmramRanges[Index].PhysicalSize != 0) {
break;
}
}
ASSERT (Index < TempSmramRangeCount);
for (Index2 = 0; Index2 < TempSmramRangeCount; Index2++) {
if ((Index2 != Index) && (TempSmramRanges[Index2].PhysicalSize != 0) && (TempSmramRanges[Index2].CpuStart < TempSmramRanges[Index].CpuStart)) {
Index = Index2;
}
}
CopyMem (&FullSmramRanges[*FullSmramRangeCount], &TempSmramRanges[Index], sizeof (EFI_SMRAM_DESCRIPTOR));
*FullSmramRangeCount += 1;
TempSmramRanges[Index].PhysicalSize = 0;
} while (*FullSmramRangeCount < TempSmramRangeCount);
ASSERT (*FullSmramRangeCount == TempSmramRangeCount);
*FullSmramRangeCount += 1;
FreePool (SmramRanges);
FreePool (SmramReservedRanges);
FreePool (TempSmramRanges);
return FullSmramRanges;
}
/**
The Entry Point for SMM IPL
Load SMM Core into SMRAM, register SMM Core entry point for SMIs, install
SMM Base 2 Protocol and SMM Communication Protocol, and register for the
critical events required to coordinate between DXE and SMM environments.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval Other Some error occurred when executing this entry point.
**/
EFI_STATUS
EFIAPI
SmmIplEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINTN Index;
UINT64 MaxSize;
VOID *Registration;
UINT64 SmmCodeSize;
EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
EFI_CPU_ARCH_PROTOCOL *CpuArch;
EFI_STATUS SetAttrStatus;
//
// Fill in the image handle of the SMM IPL so the SMM Core can use this as the
// ParentImageHandle field of the Load Image Protocol for all SMM Drivers loaded
// by the SMM Core
//
mSmmCorePrivateData.SmmIplImageHandle = ImageHandle;
//
// Get SMM Access Protocol
//
Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&mSmmAccess);
ASSERT_EFI_ERROR (Status);
//
// Get SMM Control2 Protocol
//
Status = gBS->LocateProtocol (&gEfiSmmControl2ProtocolGuid, NULL, (VOID **)&mSmmControl2);
ASSERT_EFI_ERROR (Status);
gSmmCorePrivate->SmramRanges = GetFullSmramRanges (&gSmmCorePrivate->SmramRangeCount);
//
// Open all SMRAM ranges
//
Status = mSmmAccess->Open (mSmmAccess);
ASSERT_EFI_ERROR (Status);
//
// Print debug message that the SMRAM window is now open.
//
DEBUG ((DEBUG_INFO, "SMM IPL opened SMRAM window\n"));
//
// Find the largest SMRAM range between 1MB and 4GB that is at least 256KB - 4K in size
//
mCurrentSmramRange = NULL;
for (Index = 0, MaxSize = SIZE_256KB - EFI_PAGE_SIZE; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
//
// Skip any SMRAM region that is already allocated, needs testing, or needs ECC initialization
//
if ((gSmmCorePrivate->SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
continue;
}
if (gSmmCorePrivate->SmramRanges[Index].CpuStart >= BASE_1MB) {
if ((gSmmCorePrivate->SmramRanges[Index].CpuStart + gSmmCorePrivate->SmramRanges[Index].PhysicalSize - 1) <= MAX_ADDRESS) {
if (gSmmCorePrivate->SmramRanges[Index].PhysicalSize >= MaxSize) {
MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
mCurrentSmramRange = &gSmmCorePrivate->SmramRanges[Index];
}
}
}
}
if (mCurrentSmramRange != NULL) {
//
// Print debug message showing SMRAM window that will be used by SMM IPL and SMM Core
//
DEBUG ((DEBUG_INFO, "SMM IPL found SMRAM window %p - %p\n",
(VOID *)(UINTN)mCurrentSmramRange->CpuStart,
(VOID *)(UINTN)(mCurrentSmramRange->CpuStart + mCurrentSmramRange->PhysicalSize - 1)
));
GetSmramCacheRange (mCurrentSmramRange, &mSmramCacheBase, &mSmramCacheSize);
//
// If CPU AP is present, attempt to set SMRAM cacheability to WB
// Note that it is expected that cacheability of SMRAM has been set to WB if CPU AP
// is not available here.
//
CpuArch = NULL;
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);
if (!EFI_ERROR (Status)) {
Status = gDS->SetMemorySpaceAttributes(
mSmramCacheBase,
mSmramCacheSize,
EFI_MEMORY_WB
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));
}
}
//
// if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load
// Modules At Fixed Address Configuration Table.
//
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
//
// Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
//
SmmCodeSize = LShiftU64 (PcdGet32(PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
//
// The SMRAM available memory is assumed to be larger than SmmCodeSize
//
ASSERT (mCurrentSmramRange->PhysicalSize > SmmCodeSize);
//
// Retrieve Load modules At fixed address configuration table and save the SMRAM base.
//
Status = EfiGetSystemConfigurationTable (
&gLoadFixedAddressConfigurationTableGuid,
(VOID **) &LMFAConfigurationTable
);
if (!EFI_ERROR (Status) && LMFAConfigurationTable != NULL) {
LMFAConfigurationTable->SmramBase = mCurrentSmramRange->CpuStart;
//
// Print the SMRAM base
//
DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: TSEG BASE is %x. \n", LMFAConfigurationTable->SmramBase));
}
}
//
// Load SMM Core into SMRAM and execute it from SMRAM
//
Status = ExecuteSmmCoreFromSmram (
mCurrentSmramRange,
&gSmmCorePrivate->SmramRanges[gSmmCorePrivate->SmramRangeCount - 1],
gSmmCorePrivate
);
if (EFI_ERROR (Status)) {
//
// Print error message that the SMM Core failed to be loaded and executed.
//
DEBUG ((DEBUG_ERROR, "SMM IPL could not load and execute SMM Core from SMRAM\n"));
//
// Attempt to reset SMRAM cacheability to UC
//
if (CpuArch != NULL) {
SetAttrStatus = gDS->SetMemorySpaceAttributes(
mSmramCacheBase,
mSmramCacheSize,
EFI_MEMORY_UC
);
if (EFI_ERROR (SetAttrStatus)) {
DEBUG ((DEBUG_WARN, "SMM IPL failed to reset SMRAM window to EFI_MEMORY_UC\n"));
}
}
}
} else {
//
// Print error message that there are not enough SMRAM resources to load the SMM Core.
//
DEBUG ((DEBUG_ERROR, "SMM IPL could not find a large enough SMRAM region to load SMM Core\n"));
}
//
// If the SMM Core could not be loaded then close SMRAM window, free allocated
// resources, and return an error so SMM IPL will be unloaded.
//
if (mCurrentSmramRange == NULL || EFI_ERROR (Status)) {
//
// Close all SMRAM ranges
//
Status = mSmmAccess->Close (mSmmAccess);
ASSERT_EFI_ERROR (Status);
//
// Print debug message that the SMRAM window is now closed.
//
DEBUG ((DEBUG_INFO, "SMM IPL closed SMRAM window\n"));
//
// Free all allocated resources
//
FreePool (gSmmCorePrivate->SmramRanges);
return EFI_UNSUPPORTED;
}
//
// Install SMM Base2 Protocol and SMM Communication Protocol
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mSmmIplHandle,
&gEfiSmmBase2ProtocolGuid, &mSmmBase2,
&gEfiSmmCommunicationProtocolGuid, &mSmmCommunication,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Create the set of protocol and event notififcations that the SMM IPL requires
//
for (Index = 0; mSmmIplEvents[Index].NotifyFunction != NULL; Index++) {
if (mSmmIplEvents[Index].Protocol) {
mSmmIplEvents[Index].Event = EfiCreateProtocolNotifyEvent (
mSmmIplEvents[Index].Guid,
mSmmIplEvents[Index].NotifyTpl,
mSmmIplEvents[Index].NotifyFunction,
mSmmIplEvents[Index].NotifyContext,
&Registration
);
} else {
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
mSmmIplEvents[Index].NotifyTpl,
mSmmIplEvents[Index].NotifyFunction,
mSmmIplEvents[Index].NotifyContext,
mSmmIplEvents[Index].Guid,
&mSmmIplEvents[Index].Event
);
ASSERT_EFI_ERROR (Status);
}
}
return EFI_SUCCESS;
}
|