]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
acb852b8dd4b6702235b6b58968fd2f53f691d71
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / PiSmmIpl.c
1 /** @file
2 SMM IPL that produces SMM related runtime protocols and load the SMM Core into SMRAM
3
4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16
17 #include <Protocol/SmmBase2.h>
18 #include <Protocol/SmmCommunication.h>
19 #include <Protocol/SmmAccess2.h>
20 #include <Protocol/SmmConfiguration.h>
21 #include <Protocol/SmmControl2.h>
22 #include <Protocol/DxeSmmReadyToLock.h>
23 #include <Protocol/Cpu.h>
24
25 #include <Guid/EventGroup.h>
26 #include <Guid/EventLegacyBios.h>
27 #include <Guid/LoadModuleAtFixedAddress.h>
28
29 #include <Library/BaseLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/PeCoffLib.h>
32 #include <Library/CacheMaintenanceLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/DxeServicesTableLib.h>
37 #include <Library/DxeServicesLib.h>
38 #include <Library/UefiLib.h>
39 #include <Library/UefiRuntimeLib.h>
40 #include <Library/PcdLib.h>
41 #include <Library/ReportStatusCodeLib.h>
42
43 #include "PiSmmCorePrivateData.h"
44
45 //
46 // Function prototypes from produced protocols
47 //
48
49 /**
50 Indicate whether the driver is currently executing in the SMM Initialization phase.
51
52 @param This The EFI_SMM_BASE2_PROTOCOL instance.
53 @param InSmram Pointer to a Boolean which, on return, indicates that the driver is currently executing
54 inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
55
56 @retval EFI_INVALID_PARAMETER InSmram was NULL.
57 @retval EFI_SUCCESS The call returned successfully.
58
59 **/
60 EFI_STATUS
61 EFIAPI
62 SmmBase2InSmram (
63 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
64 OUT BOOLEAN *InSmram
65 );
66
67 /**
68 Retrieves the location of the System Management System Table (SMST).
69
70 @param This The EFI_SMM_BASE2_PROTOCOL instance.
71 @param Smst On return, points to a pointer to the System Management Service Table (SMST).
72
73 @retval EFI_INVALID_PARAMETER Smst or This was invalid.
74 @retval EFI_SUCCESS The memory was returned to the system.
75 @retval EFI_UNSUPPORTED Not in SMM.
76
77 **/
78 EFI_STATUS
79 EFIAPI
80 SmmBase2GetSmstLocation (
81 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
82 OUT EFI_SMM_SYSTEM_TABLE2 **Smst
83 );
84
85 /**
86 Communicates with a registered handler.
87
88 This function provides a service to send and receive messages from a registered
89 UEFI service. This function is part of the SMM Communication Protocol that may
90 be called in physical mode prior to SetVirtualAddressMap() and in virtual mode
91 after SetVirtualAddressMap().
92
93 @param[in] This The EFI_SMM_COMMUNICATION_PROTOCOL instance.
94 @param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM.
95 @param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data
96 being returned. Zero if the handler does not wish to reply with any data.
97
98 @retval EFI_SUCCESS The message was successfully posted.
99 @retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
100 **/
101 EFI_STATUS
102 EFIAPI
103 SmmCommunicationCommunicate (
104 IN CONST EFI_SMM_COMMUNICATION_PROTOCOL *This,
105 IN OUT VOID *CommBuffer,
106 IN OUT UINTN *CommSize
107 );
108
109 /**
110 Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
111
112 @param Event The Event that is being processed, not used.
113 @param Context Event Context, not used.
114
115 **/
116 VOID
117 EFIAPI
118 SmmIplSmmConfigurationEventNotify (
119 IN EFI_EVENT Event,
120 IN VOID *Context
121 );
122
123 /**
124 Event notification that is fired every time a DxeSmmReadyToLock protocol is added
125 or if gEfiEventReadyToBootGuid is signalled.
126
127 @param Event The Event that is being processed, not used.
128 @param Context Event Context, not used.
129
130 **/
131 VOID
132 EFIAPI
133 SmmIplReadyToLockEventNotify (
134 IN EFI_EVENT Event,
135 IN VOID *Context
136 );
137
138 /**
139 Event notification that is fired when DxeDispatch Event Group is signaled.
140
141 @param Event The Event that is being processed, not used.
142 @param Context Event Context, not used.
143
144 **/
145 VOID
146 EFIAPI
147 SmmIplDxeDispatchEventNotify (
148 IN EFI_EVENT Event,
149 IN VOID *Context
150 );
151
152 /**
153 Event notification that is fired when a GUIDed Event Group is signaled.
154
155 @param Event The Event that is being processed, not used.
156 @param Context Event Context, not used.
157
158 **/
159 VOID
160 EFIAPI
161 SmmIplGuidedEventNotify (
162 IN EFI_EVENT Event,
163 IN VOID *Context
164 );
165
166 /**
167 Event notification that is fired when EndOfDxe Event Group is signaled.
168
169 @param Event The Event that is being processed, not used.
170 @param Context Event Context, not used.
171
172 **/
173 VOID
174 EFIAPI
175 SmmIplEndOfDxeEventNotify (
176 IN EFI_EVENT Event,
177 IN VOID *Context
178 );
179
180 /**
181 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
182
183 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
184 It convers pointer to new virtual address.
185
186 @param Event Event whose notification function is being invoked.
187 @param Context Pointer to the notification function's context.
188
189 **/
190 VOID
191 EFIAPI
192 SmmIplSetVirtualAddressNotify (
193 IN EFI_EVENT Event,
194 IN VOID *Context
195 );
196
197 //
198 // Data structure used to declare a table of protocol notifications and event
199 // notifications required by the SMM IPL
200 //
201 typedef struct {
202 BOOLEAN Protocol;
203 BOOLEAN CloseOnLock;
204 EFI_GUID *Guid;
205 EFI_EVENT_NOTIFY NotifyFunction;
206 VOID *NotifyContext;
207 EFI_TPL NotifyTpl;
208 EFI_EVENT Event;
209 } SMM_IPL_EVENT_NOTIFICATION;
210
211 //
212 // Handle to install the SMM Base2 Protocol and the SMM Communication Protocol
213 //
214 EFI_HANDLE mSmmIplHandle = NULL;
215
216 //
217 // SMM Base 2 Protocol instance
218 //
219 EFI_SMM_BASE2_PROTOCOL mSmmBase2 = {
220 SmmBase2InSmram,
221 SmmBase2GetSmstLocation
222 };
223
224 //
225 // SMM Communication Protocol instance
226 //
227 EFI_SMM_COMMUNICATION_PROTOCOL mSmmCommunication = {
228 SmmCommunicationCommunicate
229 };
230
231 //
232 // SMM Core Private Data structure that contains the data shared between
233 // the SMM IPL and the SMM Core.
234 //
235 SMM_CORE_PRIVATE_DATA mSmmCorePrivateData = {
236 SMM_CORE_PRIVATE_DATA_SIGNATURE, // Signature
237 NULL, // SmmIplImageHandle
238 0, // SmramRangeCount
239 NULL, // SmramRanges
240 NULL, // SmmEntryPoint
241 FALSE, // SmmEntryPointRegistered
242 FALSE, // InSmm
243 NULL, // Smst
244 NULL, // CommunicationBuffer
245 0, // BufferSize
246 EFI_SUCCESS // ReturnStatus
247 };
248
249 //
250 // Global pointer used to access mSmmCorePrivateData from outside and inside SMM
251 //
252 SMM_CORE_PRIVATE_DATA *gSmmCorePrivate = &mSmmCorePrivateData;
253
254 //
255 // SMM IPL global variables
256 //
257 EFI_SMM_CONTROL2_PROTOCOL *mSmmControl2;
258 EFI_SMM_ACCESS2_PROTOCOL *mSmmAccess;
259 EFI_SMRAM_DESCRIPTOR *mCurrentSmramRange;
260 BOOLEAN mSmmLocked = FALSE;
261 BOOLEAN mEndOfDxe = FALSE;
262 EFI_PHYSICAL_ADDRESS mSmramCacheBase;
263 UINT64 mSmramCacheSize;
264
265 EFI_SMM_COMMUNICATE_HEADER mCommunicateHeader;
266
267 //
268 // Table of Protocol notification and GUIDed Event notifications that the SMM IPL requires
269 //
270 SMM_IPL_EVENT_NOTIFICATION mSmmIplEvents[] = {
271 //
272 // Declare protocol notification on the SMM Configuration protocol. When this notification is etablished,
273 // the associated event is immediately signalled, so the notification function will be executed and the
274 // SMM Configuration Protocol will be found if it is already in the handle database.
275 //
276 { TRUE, FALSE, &gEfiSmmConfigurationProtocolGuid, SmmIplSmmConfigurationEventNotify, &gEfiSmmConfigurationProtocolGuid, TPL_NOTIFY, NULL },
277 //
278 // Declare protocol notification on DxeSmmReadyToLock protocols. When this notification is established,
279 // the associated event is immediately signalled, so the notification function will be executed and the
280 // DXE SMM Ready To Lock Protocol will be found if it is already in the handle database.
281 //
282 { TRUE, TRUE, &gEfiDxeSmmReadyToLockProtocolGuid, SmmIplReadyToLockEventNotify, &gEfiDxeSmmReadyToLockProtocolGuid, TPL_CALLBACK, NULL },
283 //
284 // Declare event notification on EndOfDxe event. When this notification is etablished,
285 // the associated event is immediately signalled, so the notification function will be executed and the
286 // SMM End Of Dxe Protocol will be found if it is already in the handle database.
287 //
288 { FALSE, TRUE, &gEfiEndOfDxeEventGroupGuid, SmmIplGuidedEventNotify, &gEfiEndOfDxeEventGroupGuid, TPL_CALLBACK, NULL },
289 //
290 // Declare event notification on EndOfDxe event. This is used to set EndOfDxe event signaled flag.
291 //
292 { FALSE, TRUE, &gEfiEndOfDxeEventGroupGuid, SmmIplEndOfDxeEventNotify, &gEfiEndOfDxeEventGroupGuid, TPL_CALLBACK, NULL },
293 //
294 // Declare event notification on the DXE Dispatch Event Group. This event is signaled by the DXE Core
295 // each time the DXE Core dispatcher has completed its work. When this event is signalled, the SMM Core
296 // if notified, so the SMM Core can dispatch SMM drivers.
297 //
298 { FALSE, TRUE, &gEfiEventDxeDispatchGuid, SmmIplDxeDispatchEventNotify, &gEfiEventDxeDispatchGuid, TPL_CALLBACK, NULL },
299 //
300 // Declare event notification on Ready To Boot Event Group. This is an extra event notification that is
301 // used to make sure SMRAM is locked before any boot options are processed.
302 //
303 { FALSE, TRUE, &gEfiEventReadyToBootGuid, SmmIplReadyToLockEventNotify, &gEfiEventReadyToBootGuid, TPL_CALLBACK, NULL },
304 //
305 // Declare event notification on Legacy Boot Event Group. This is used to inform the SMM Core that the platform
306 // is performing a legacy boot operation, and that the UEFI environment is no longer available and the SMM Core
307 // must guarantee that it does not access any UEFI related structures outside of SMRAM.
308 // It is also to inform the SMM Core to notify SMM driver that system enter legacy boot.
309 //
310 { FALSE, FALSE, &gEfiEventLegacyBootGuid, SmmIplGuidedEventNotify, &gEfiEventLegacyBootGuid, TPL_CALLBACK, NULL },
311 //
312 // Declare event notification on Exit Boot Services Event Group. This is used to inform the SMM Core
313 // to notify SMM driver that system enter exit boot services.
314 //
315 { FALSE, FALSE, &gEfiEventExitBootServicesGuid, SmmIplGuidedEventNotify, &gEfiEventExitBootServicesGuid, TPL_CALLBACK, NULL },
316 //
317 // Declare event notification on Ready To Boot Event Group. This is used to inform the SMM Core
318 // to notify SMM driver that system enter ready to boot.
319 //
320 { FALSE, FALSE, &gEfiEventReadyToBootGuid, SmmIplGuidedEventNotify, &gEfiEventReadyToBootGuid, TPL_CALLBACK, NULL },
321 //
322 // Declare event notification on SetVirtualAddressMap() Event Group. This is used to convert gSmmCorePrivate
323 // and mSmmControl2 from physical addresses to virtual addresses.
324 //
325 { FALSE, FALSE, &gEfiEventVirtualAddressChangeGuid, SmmIplSetVirtualAddressNotify, NULL, TPL_CALLBACK, NULL },
326 //
327 // Terminate the table of event notifications
328 //
329 { FALSE, FALSE, NULL, NULL, NULL, TPL_CALLBACK, NULL }
330 };
331
332 /**
333 Find the maximum SMRAM cache range that covers the range specified by SmramRange.
334
335 This function searches and joins all adjacent ranges of SmramRange into a range to be cached.
336
337 @param SmramRange The SMRAM range to search from.
338 @param SmramCacheBase The returned cache range base.
339 @param SmramCacheSize The returned cache range size.
340
341 **/
342 VOID
343 GetSmramCacheRange (
344 IN EFI_SMRAM_DESCRIPTOR *SmramRange,
345 OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
346 OUT UINT64 *SmramCacheSize
347 )
348 {
349 UINTN Index;
350 EFI_PHYSICAL_ADDRESS RangeCpuStart;
351 UINT64 RangePhysicalSize;
352 BOOLEAN FoundAjacentRange;
353
354 *SmramCacheBase = SmramRange->CpuStart;
355 *SmramCacheSize = SmramRange->PhysicalSize;
356
357 do {
358 FoundAjacentRange = FALSE;
359 for (Index = 0; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
360 RangeCpuStart = gSmmCorePrivate->SmramRanges[Index].CpuStart;
361 RangePhysicalSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
362 if (RangeCpuStart < *SmramCacheBase && *SmramCacheBase == (RangeCpuStart + RangePhysicalSize)) {
363 *SmramCacheBase = RangeCpuStart;
364 *SmramCacheSize += RangePhysicalSize;
365 FoundAjacentRange = TRUE;
366 } else if ((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart && RangePhysicalSize > 0) {
367 *SmramCacheSize += RangePhysicalSize;
368 FoundAjacentRange = TRUE;
369 }
370 }
371 } while (FoundAjacentRange);
372
373 }
374
375 /**
376 Indicate whether the driver is currently executing in the SMM Initialization phase.
377
378 @param This The EFI_SMM_BASE2_PROTOCOL instance.
379 @param InSmram Pointer to a Boolean which, on return, indicates that the driver is currently executing
380 inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
381
382 @retval EFI_INVALID_PARAMETER InSmram was NULL.
383 @retval EFI_SUCCESS The call returned successfully.
384
385 **/
386 EFI_STATUS
387 EFIAPI
388 SmmBase2InSmram (
389 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
390 OUT BOOLEAN *InSmram
391 )
392 {
393 if (InSmram == NULL) {
394 return EFI_INVALID_PARAMETER;
395 }
396
397 *InSmram = gSmmCorePrivate->InSmm;
398
399 return EFI_SUCCESS;
400 }
401
402 /**
403 Retrieves the location of the System Management System Table (SMST).
404
405 @param This The EFI_SMM_BASE2_PROTOCOL instance.
406 @param Smst On return, points to a pointer to the System Management Service Table (SMST).
407
408 @retval EFI_INVALID_PARAMETER Smst or This was invalid.
409 @retval EFI_SUCCESS The memory was returned to the system.
410 @retval EFI_UNSUPPORTED Not in SMM.
411
412 **/
413 EFI_STATUS
414 EFIAPI
415 SmmBase2GetSmstLocation (
416 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
417 OUT EFI_SMM_SYSTEM_TABLE2 **Smst
418 )
419 {
420 if ((This == NULL) ||(Smst == NULL)) {
421 return EFI_INVALID_PARAMETER;
422 }
423
424 if (!gSmmCorePrivate->InSmm) {
425 return EFI_UNSUPPORTED;
426 }
427
428 *Smst = gSmmCorePrivate->Smst;
429
430 return EFI_SUCCESS;
431 }
432
433 /**
434 Communicates with a registered handler.
435
436 This function provides a service to send and receive messages from a registered
437 UEFI service. This function is part of the SMM Communication Protocol that may
438 be called in physical mode prior to SetVirtualAddressMap() and in virtual mode
439 after SetVirtualAddressMap().
440
441 @param[in] This The EFI_SMM_COMMUNICATION_PROTOCOL instance.
442 @param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM.
443 @param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data
444 being returned. Zero if the handler does not wish to reply with any data.
445
446 @retval EFI_SUCCESS The message was successfully posted.
447 @retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
448 **/
449 EFI_STATUS
450 EFIAPI
451 SmmCommunicationCommunicate (
452 IN CONST EFI_SMM_COMMUNICATION_PROTOCOL *This,
453 IN OUT VOID *CommBuffer,
454 IN OUT UINTN *CommSize
455 )
456 {
457 EFI_STATUS Status;
458 EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
459 BOOLEAN OldInSmm;
460
461 //
462 // Check parameters
463 //
464 if ((CommBuffer == NULL) || (CommSize == NULL)) {
465 return EFI_INVALID_PARAMETER;
466 }
467
468 //
469 // CommSize must hold HeaderGuid and MessageLength
470 //
471 if (*CommSize < OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)) {
472 return EFI_INVALID_PARAMETER;
473 }
474
475 //
476 // If not already in SMM, then generate a Software SMI
477 //
478 if (!gSmmCorePrivate->InSmm && gSmmCorePrivate->SmmEntryPointRegistered) {
479 //
480 // Put arguments for Software SMI in gSmmCorePrivate
481 //
482 gSmmCorePrivate->CommunicationBuffer = CommBuffer;
483 gSmmCorePrivate->BufferSize = *CommSize;
484
485 //
486 // Generate Software SMI
487 //
488 Status = mSmmControl2->Trigger (mSmmControl2, NULL, NULL, FALSE, 0);
489 if (EFI_ERROR (Status)) {
490 return EFI_UNSUPPORTED;
491 }
492
493 //
494 // Return status from software SMI
495 //
496 *CommSize = gSmmCorePrivate->BufferSize;
497 return gSmmCorePrivate->ReturnStatus;
498 }
499
500 //
501 // If we are in SMM, then the execution mode must be physical, which means that
502 // OS established virtual addresses can not be used. If SetVirtualAddressMap()
503 // has been called, then a direct invocation of the Software SMI is not
504 // not allowed so return EFI_INVALID_PARAMETER.
505 //
506 if (EfiGoneVirtual()) {
507 return EFI_INVALID_PARAMETER;
508 }
509
510 //
511 // If we are not in SMM, don't allow call SmiManage() directly when SMRAM is closed or locked.
512 //
513 if ((!gSmmCorePrivate->InSmm) && (!mSmmAccess->OpenState || mSmmAccess->LockState)) {
514 return EFI_INVALID_PARAMETER;
515 }
516
517 //
518 // Save current InSmm state and set InSmm state to TRUE
519 //
520 OldInSmm = gSmmCorePrivate->InSmm;
521 gSmmCorePrivate->InSmm = TRUE;
522
523 //
524 // Already in SMM and before SetVirtualAddressMap(), so call SmiManage() directly.
525 //
526 CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommBuffer;
527 *CommSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
528 Status = gSmmCorePrivate->Smst->SmiManage (
529 &CommunicateHeader->HeaderGuid,
530 NULL,
531 CommunicateHeader->Data,
532 CommSize
533 );
534
535 //
536 // Update CommunicationBuffer, BufferSize and ReturnStatus
537 // Communicate service finished, reset the pointer to CommBuffer to NULL
538 //
539 *CommSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
540
541 //
542 // Restore original InSmm state
543 //
544 gSmmCorePrivate->InSmm = OldInSmm;
545
546 return (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
547 }
548
549 /**
550 Event notification that is fired when GUIDed Event Group is signaled.
551
552 @param Event The Event that is being processed, not used.
553 @param Context Event Context, not used.
554
555 **/
556 VOID
557 EFIAPI
558 SmmIplGuidedEventNotify (
559 IN EFI_EVENT Event,
560 IN VOID *Context
561 )
562 {
563 UINTN Size;
564
565 //
566 // Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
567 //
568 CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
569 mCommunicateHeader.MessageLength = 1;
570 mCommunicateHeader.Data[0] = 0;
571
572 //
573 // Generate the Software SMI and return the result
574 //
575 Size = sizeof (mCommunicateHeader);
576 SmmCommunicationCommunicate (&mSmmCommunication, &mCommunicateHeader, &Size);
577 }
578
579 /**
580 Event notification that is fired when EndOfDxe Event Group is signaled.
581
582 @param Event The Event that is being processed, not used.
583 @param Context Event Context, not used.
584
585 **/
586 VOID
587 EFIAPI
588 SmmIplEndOfDxeEventNotify (
589 IN EFI_EVENT Event,
590 IN VOID *Context
591 )
592 {
593 mEndOfDxe = TRUE;
594 }
595
596 /**
597 Event notification that is fired when DxeDispatch Event Group is signaled.
598
599 @param Event The Event that is being processed, not used.
600 @param Context Event Context, not used.
601
602 **/
603 VOID
604 EFIAPI
605 SmmIplDxeDispatchEventNotify (
606 IN EFI_EVENT Event,
607 IN VOID *Context
608 )
609 {
610 UINTN Size;
611 EFI_STATUS Status;
612
613 //
614 // Keep calling the SMM Core Dispatcher until there is no request to restart it.
615 //
616 while (TRUE) {
617 //
618 // Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
619 // Clear the buffer passed into the Software SMI. This buffer will return
620 // the status of the SMM Core Dispatcher.
621 //
622 CopyGuid (&mCommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
623 mCommunicateHeader.MessageLength = 1;
624 mCommunicateHeader.Data[0] = 0;
625
626 //
627 // Generate the Software SMI and return the result
628 //
629 Size = sizeof (mCommunicateHeader);
630 SmmCommunicationCommunicate (&mSmmCommunication, &mCommunicateHeader, &Size);
631
632 //
633 // Return if there is no request to restart the SMM Core Dispatcher
634 //
635 if (mCommunicateHeader.Data[0] != COMM_BUFFER_SMM_DISPATCH_RESTART) {
636 return;
637 }
638
639 //
640 // Attempt to reset SMRAM cacheability to UC
641 // Assume CPU AP is available at this time
642 //
643 Status = gDS->SetMemorySpaceAttributes(
644 mSmramCacheBase,
645 mSmramCacheSize,
646 EFI_MEMORY_UC
647 );
648 if (EFI_ERROR (Status)) {
649 DEBUG ((DEBUG_WARN, "SMM IPL failed to reset SMRAM window to EFI_MEMORY_UC\n"));
650 }
651
652 //
653 // Close all SMRAM ranges to protect SMRAM
654 //
655 Status = mSmmAccess->Close (mSmmAccess);
656 ASSERT_EFI_ERROR (Status);
657
658 //
659 // Print debug message that the SMRAM window is now closed.
660 //
661 DEBUG ((DEBUG_INFO, "SMM IPL closed SMRAM window\n"));
662 }
663 }
664
665 /**
666 Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
667
668 @param Event The Event that is being processed, not used.
669 @param Context Event Context, not used.
670
671 **/
672 VOID
673 EFIAPI
674 SmmIplSmmConfigurationEventNotify (
675 IN EFI_EVENT Event,
676 IN VOID *Context
677 )
678 {
679 EFI_STATUS Status;
680 EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
681
682 //
683 // Make sure this notification is for this handler
684 //
685 Status = gBS->LocateProtocol (Context, NULL, (VOID **)&SmmConfiguration);
686 if (EFI_ERROR (Status)) {
687 return;
688 }
689
690 //
691 // Register the SMM Entry Point provided by the SMM Core with the SMM COnfiguration protocol
692 //
693 Status = SmmConfiguration->RegisterSmmEntry (SmmConfiguration, gSmmCorePrivate->SmmEntryPoint);
694 ASSERT_EFI_ERROR (Status);
695
696 //
697 // Set flag to indicate that the SMM Entry Point has been registered which
698 // means that SMIs are now fully operational.
699 //
700 gSmmCorePrivate->SmmEntryPointRegistered = TRUE;
701
702 //
703 // Print debug message showing SMM Core entry point address.
704 //
705 DEBUG ((DEBUG_INFO, "SMM IPL registered SMM Entry Point address %p\n", (VOID *)(UINTN)gSmmCorePrivate->SmmEntryPoint));
706 }
707
708 /**
709 Event notification that is fired every time a DxeSmmReadyToLock protocol is added
710 or if gEfiEventReadyToBootGuid is signaled.
711
712 @param Event The Event that is being processed, not used.
713 @param Context Event Context, not used.
714
715 **/
716 VOID
717 EFIAPI
718 SmmIplReadyToLockEventNotify (
719 IN EFI_EVENT Event,
720 IN VOID *Context
721 )
722 {
723 EFI_STATUS Status;
724 VOID *Interface;
725 UINTN Index;
726
727 //
728 // See if we are already locked
729 //
730 if (mSmmLocked) {
731 return;
732 }
733
734 //
735 // Make sure this notification is for this handler
736 //
737 if (CompareGuid ((EFI_GUID *)Context, &gEfiDxeSmmReadyToLockProtocolGuid)) {
738 Status = gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL, &Interface);
739 if (EFI_ERROR (Status)) {
740 return;
741 }
742 } else {
743 //
744 // If SMM is not locked yet and we got here from gEfiEventReadyToBootGuid being
745 // signaled, then gEfiDxeSmmReadyToLockProtocolGuid was not installed as expected.
746 // Print a warning on debug builds.
747 //
748 DEBUG ((DEBUG_WARN, "SMM IPL! DXE SMM Ready To Lock Protocol not installed before Ready To Boot signal\n"));
749 }
750
751 if (!mEndOfDxe) {
752 DEBUG ((DEBUG_ERROR, "EndOfDxe Event must be signaled before DxeSmmReadyToLock Protocol installation!\n"));
753 REPORT_STATUS_CODE (
754 EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,
755 (EFI_SOFTWARE_SMM_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)
756 );
757 ASSERT (FALSE);
758 }
759
760 //
761 // Lock the SMRAM (Note: Locking SMRAM may not be supported on all platforms)
762 //
763 mSmmAccess->Lock (mSmmAccess);
764
765 //
766 // Close protocol and event notification events that do not apply after the
767 // DXE SMM Ready To Lock Protocol has been installed or the Ready To Boot
768 // event has been signalled.
769 //
770 for (Index = 0; mSmmIplEvents[Index].NotifyFunction != NULL; Index++) {
771 if (mSmmIplEvents[Index].CloseOnLock) {
772 gBS->CloseEvent (mSmmIplEvents[Index].Event);
773 }
774 }
775
776 //
777 // Inform SMM Core that the DxeSmmReadyToLock protocol was installed
778 //
779 SmmIplGuidedEventNotify (Event, (VOID *)&gEfiDxeSmmReadyToLockProtocolGuid);
780
781 //
782 // Print debug message that the SMRAM window is now locked.
783 //
784 DEBUG ((DEBUG_INFO, "SMM IPL locked SMRAM window\n"));
785
786 //
787 // Set flag so this operation will not be performed again
788 //
789 mSmmLocked = TRUE;
790 }
791
792 /**
793 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
794
795 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
796 It convers pointer to new virtual address.
797
798 @param Event Event whose notification function is being invoked.
799 @param Context Pointer to the notification function's context.
800
801 **/
802 VOID
803 EFIAPI
804 SmmIplSetVirtualAddressNotify (
805 IN EFI_EVENT Event,
806 IN VOID *Context
807 )
808 {
809 EfiConvertPointer (0x0, (VOID **)&mSmmControl2);
810 }
811
812 /**
813 Get the fixed loadding address from image header assigned by build tool. This function only be called
814 when Loading module at Fixed address feature enabled.
815
816 @param ImageContext Pointer to the image context structure that describes the PE/COFF
817 image that needs to be examined by this function.
818 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
819 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
820 **/
821 EFI_STATUS
822 GetPeCoffImageFixLoadingAssignedAddress(
823 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
824 )
825 {
826 UINTN SectionHeaderOffset;
827 EFI_STATUS Status;
828 EFI_IMAGE_SECTION_HEADER SectionHeader;
829 EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
830 EFI_PHYSICAL_ADDRESS FixLoaddingAddress;
831 UINT16 Index;
832 UINTN Size;
833 UINT16 NumberOfSections;
834 EFI_PHYSICAL_ADDRESS SmramBase;
835 UINT64 SmmCodeSize;
836 UINT64 ValueInSectionHeader;
837 //
838 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
839 //
840 SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32(PcdLoadFixAddressSmmCodePageNumber));
841
842 FixLoaddingAddress = 0;
843 Status = EFI_NOT_FOUND;
844 SmramBase = mCurrentSmramRange->CpuStart;
845 //
846 // Get PeHeader pointer
847 //
848 ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
849 SectionHeaderOffset = (UINTN)(
850 ImageContext->PeCoffHeaderOffset +
851 sizeof (UINT32) +
852 sizeof (EFI_IMAGE_FILE_HEADER) +
853 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
854 );
855 NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
856
857 //
858 // Get base address from the first section header that doesn't point to code section.
859 //
860 for (Index = 0; Index < NumberOfSections; Index++) {
861 //
862 // Read section header from file
863 //
864 Size = sizeof (EFI_IMAGE_SECTION_HEADER);
865 Status = ImageContext->ImageRead (
866 ImageContext->Handle,
867 SectionHeaderOffset,
868 &Size,
869 &SectionHeader
870 );
871 if (EFI_ERROR (Status)) {
872 return Status;
873 }
874
875 Status = EFI_NOT_FOUND;
876
877 if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
878 //
879 // Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
880 // first section header that doesn't point to code section in image header. And there is an assumption that when the
881 // feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers
882 // fields should NOT be Zero, or else, these 2 fileds should be set to Zero
883 //
884 ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
885 if (ValueInSectionHeader != 0) {
886 //
887 // Found first section header that doesn't point to code section in which uild tool saves the
888 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
889 //
890 FixLoaddingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
891
892 if (SmramBase + SmmCodeSize > FixLoaddingAddress && SmramBase <= FixLoaddingAddress) {
893 //
894 // The assigned address is valid. Return the specified loadding address
895 //
896 ImageContext->ImageAddress = FixLoaddingAddress;
897 Status = EFI_SUCCESS;
898 }
899 }
900 break;
901 }
902 SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
903 }
904 DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoaddingAddress, Status));
905 return Status;
906 }
907 /**
908 Load the SMM Core image into SMRAM and executes the SMM Core from SMRAM.
909
910 @param[in, out] SmramRange Descriptor for the range of SMRAM to reload the
911 currently executing image, the rang of SMRAM to
912 hold SMM Core will be excluded.
913 @param[in, out] SmramRangeSmmCore Descriptor for the range of SMRAM to hold SMM Core.
914
915 @param[in] Context Context to pass into SMM Core
916
917 @return EFI_STATUS
918
919 **/
920 EFI_STATUS
921 ExecuteSmmCoreFromSmram (
922 IN OUT EFI_SMRAM_DESCRIPTOR *SmramRange,
923 IN OUT EFI_SMRAM_DESCRIPTOR *SmramRangeSmmCore,
924 IN VOID *Context
925 )
926 {
927 EFI_STATUS Status;
928 VOID *SourceBuffer;
929 UINTN SourceSize;
930 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
931 UINTN PageCount;
932 EFI_IMAGE_ENTRY_POINT EntryPoint;
933
934 //
935 // Search all Firmware Volumes for a PE/COFF image in a file of type SMM_CORE
936 //
937 Status = GetSectionFromAnyFvByFileType (
938 EFI_FV_FILETYPE_SMM_CORE,
939 0,
940 EFI_SECTION_PE32,
941 0,
942 &SourceBuffer,
943 &SourceSize
944 );
945 if (EFI_ERROR (Status)) {
946 return Status;
947 }
948
949 //
950 // Initilize ImageContext
951 //
952 ImageContext.Handle = SourceBuffer;
953 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
954
955 //
956 // Get information about the image being loaded
957 //
958 Status = PeCoffLoaderGetImageInfo (&ImageContext);
959 if (EFI_ERROR (Status)) {
960 return Status;
961 }
962 //
963 // if Loading module at Fixed Address feature is enabled, the SMM core driver will be loaded to
964 // the address assigned by build tool.
965 //
966 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
967 //
968 // Get the fixed loading address assigned by Build tool
969 //
970 Status = GetPeCoffImageFixLoadingAssignedAddress (&ImageContext);
971 if (!EFI_ERROR (Status)) {
972 //
973 // Since the memory range to load SMM CORE will be cut out in SMM core, so no need to allocate and free this range
974 //
975 PageCount = 0;
976 } else {
977 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR: Loading module at fixed address at address failed\n"));
978 //
979 // Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
980 // specified by SmramRange
981 //
982 PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
983
984 ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
985 ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
986
987 SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
988 SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
989 SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
990 SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
991 SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
992
993 //
994 // Align buffer on section boundary
995 //
996 ImageContext.ImageAddress = SmramRangeSmmCore->CpuStart;
997 }
998 } else {
999 //
1000 // Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
1001 // specified by SmramRange
1002 //
1003 PageCount = (UINTN)EFI_SIZE_TO_PAGES((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
1004
1005 ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
1006 ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
1007
1008 SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
1009 SmramRangeSmmCore->CpuStart = SmramRange->CpuStart + SmramRange->PhysicalSize;
1010 SmramRangeSmmCore->PhysicalStart = SmramRange->PhysicalStart + SmramRange->PhysicalSize;
1011 SmramRangeSmmCore->RegionState = SmramRange->RegionState | EFI_ALLOCATED;
1012 SmramRangeSmmCore->PhysicalSize = EFI_PAGES_TO_SIZE (PageCount);
1013
1014 //
1015 // Align buffer on section boundary
1016 //
1017 ImageContext.ImageAddress = SmramRangeSmmCore->CpuStart;
1018 }
1019
1020 ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
1021 ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
1022
1023 //
1024 // Print debug message showing SMM Core load address.
1025 //
1026 DEBUG ((DEBUG_INFO, "SMM IPL loading SMM Core at SMRAM address %p\n", (VOID *)(UINTN)ImageContext.ImageAddress));
1027
1028 //
1029 // Load the image to our new buffer
1030 //
1031 Status = PeCoffLoaderLoadImage (&ImageContext);
1032 if (!EFI_ERROR (Status)) {
1033 //
1034 // Relocate the image in our new buffer
1035 //
1036 Status = PeCoffLoaderRelocateImage (&ImageContext);
1037 if (!EFI_ERROR (Status)) {
1038 //
1039 // Flush the instruction cache so the image data are written before we execute it
1040 //
1041 InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
1042
1043 //
1044 // Print debug message showing SMM Core entry point address.
1045 //
1046 DEBUG ((DEBUG_INFO, "SMM IPL calling SMM Core at SMRAM address %p\n", (VOID *)(UINTN)ImageContext.EntryPoint));
1047
1048 gSmmCorePrivate->PiSmmCoreImageBase = ImageContext.ImageAddress;
1049 gSmmCorePrivate->PiSmmCoreImageSize = ImageContext.ImageSize;
1050 DEBUG ((DEBUG_INFO, "PiSmmCoreImageBase - 0x%016lx\n", gSmmCorePrivate->PiSmmCoreImageBase));
1051 DEBUG ((DEBUG_INFO, "PiSmmCoreImageSize - 0x%016lx\n", gSmmCorePrivate->PiSmmCoreImageSize));
1052
1053 gSmmCorePrivate->PiSmmCoreEntryPoint = ImageContext.EntryPoint;
1054
1055 //
1056 // Execute image
1057 //
1058 EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)ImageContext.EntryPoint;
1059 Status = EntryPoint ((EFI_HANDLE)Context, gST);
1060 }
1061 }
1062
1063 //
1064 // Always free memory allocted by GetFileBufferByFilePath ()
1065 //
1066 FreePool (SourceBuffer);
1067
1068 return Status;
1069 }
1070
1071 /**
1072 SMM split SMRAM entry.
1073
1074 @param[in, out] RangeToCompare Pointer to EFI_SMRAM_DESCRIPTOR to compare.
1075 @param[in, out] ReservedRangeToCompare Pointer to EFI_SMM_RESERVED_SMRAM_REGION to compare.
1076 @param[out] Ranges Output pointer to hold split EFI_SMRAM_DESCRIPTOR entry.
1077 @param[in, out] RangeCount Pointer to range count.
1078 @param[out] ReservedRanges Output pointer to hold split EFI_SMM_RESERVED_SMRAM_REGION entry.
1079 @param[in, out] ReservedRangeCount Pointer to reserved range count.
1080 @param[out] FinalRanges Output pointer to hold split final EFI_SMRAM_DESCRIPTOR entry
1081 that no need to be split anymore.
1082 @param[in, out] FinalRangeCount Pointer to final range count.
1083
1084 **/
1085 VOID
1086 SmmSplitSmramEntry (
1087 IN OUT EFI_SMRAM_DESCRIPTOR *RangeToCompare,
1088 IN OUT EFI_SMM_RESERVED_SMRAM_REGION *ReservedRangeToCompare,
1089 OUT EFI_SMRAM_DESCRIPTOR *Ranges,
1090 IN OUT UINTN *RangeCount,
1091 OUT EFI_SMM_RESERVED_SMRAM_REGION *ReservedRanges,
1092 IN OUT UINTN *ReservedRangeCount,
1093 OUT EFI_SMRAM_DESCRIPTOR *FinalRanges,
1094 IN OUT UINTN *FinalRangeCount
1095 )
1096 {
1097 UINT64 RangeToCompareEnd;
1098 UINT64 ReservedRangeToCompareEnd;
1099
1100 RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
1101 ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
1102
1103 if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
1104 (RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
1105 if (RangeToCompareEnd < ReservedRangeToCompareEnd) {
1106 //
1107 // RangeToCompare ReservedRangeToCompare
1108 // ---- ---- --------------------------------------
1109 // | | | | -> 1. ReservedRangeToCompare
1110 // ---- | | |--| --------------------------------------
1111 // | | | | | |
1112 // | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
1113 // | | | | | | RangeToCompare->PhysicalSize = 0
1114 // ---- | | |--| --------------------------------------
1115 // | | | | -> 3. ReservedRanges[*ReservedRangeCount] and increment *ReservedRangeCount
1116 // ---- ---- --------------------------------------
1117 //
1118
1119 //
1120 // 1. Update ReservedRangeToCompare.
1121 //
1122 ReservedRangeToCompare->SmramReservedSize = RangeToCompare->CpuStart - ReservedRangeToCompare->SmramReservedStart;
1123 //
1124 // 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
1125 // Zero RangeToCompare->PhysicalSize.
1126 //
1127 FinalRanges[*FinalRangeCount].CpuStart = RangeToCompare->CpuStart;
1128 FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
1129 FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
1130 FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompare->PhysicalSize;
1131 *FinalRangeCount += 1;
1132 RangeToCompare->PhysicalSize = 0;
1133 //
1134 // 3. Update ReservedRanges[*ReservedRangeCount] and increment *ReservedRangeCount.
1135 //
1136 ReservedRanges[*ReservedRangeCount].SmramReservedStart = FinalRanges[*FinalRangeCount - 1].CpuStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1137 ReservedRanges[*ReservedRangeCount].SmramReservedSize = ReservedRangeToCompareEnd - RangeToCompareEnd;
1138 *ReservedRangeCount += 1;
1139 } else {
1140 //
1141 // RangeToCompare ReservedRangeToCompare
1142 // ---- ---- --------------------------------------
1143 // | | | | -> 1. ReservedRangeToCompare
1144 // ---- | | |--| --------------------------------------
1145 // | | | | | |
1146 // | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
1147 // | | | | | |
1148 // | | ---- |--| --------------------------------------
1149 // | | | | -> 3. RangeToCompare
1150 // ---- ---- --------------------------------------
1151 //
1152
1153 //
1154 // 1. Update ReservedRangeToCompare.
1155 //
1156 ReservedRangeToCompare->SmramReservedSize = RangeToCompare->CpuStart - ReservedRangeToCompare->SmramReservedStart;
1157 //
1158 // 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
1159 //
1160 FinalRanges[*FinalRangeCount].CpuStart = RangeToCompare->CpuStart;
1161 FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart;
1162 FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
1163 FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompareEnd - RangeToCompare->CpuStart;
1164 *FinalRangeCount += 1;
1165 //
1166 // 3. Update RangeToCompare.
1167 //
1168 RangeToCompare->CpuStart += FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1169 RangeToCompare->PhysicalStart += FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1170 RangeToCompare->PhysicalSize -= FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1171 }
1172 } else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
1173 (ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
1174 if (ReservedRangeToCompareEnd < RangeToCompareEnd) {
1175 //
1176 // RangeToCompare ReservedRangeToCompare
1177 // ---- ---- --------------------------------------
1178 // | | | | -> 1. RangeToCompare
1179 // | | ---- |--| --------------------------------------
1180 // | | | | | |
1181 // | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
1182 // | | | | | | ReservedRangeToCompare->SmramReservedSize = 0
1183 // | | ---- |--| --------------------------------------
1184 // | | | | -> 3. Ranges[*RangeCount] and increment *RangeCount
1185 // ---- ---- --------------------------------------
1186 //
1187
1188 //
1189 // 1. Update RangeToCompare.
1190 //
1191 RangeToCompare->PhysicalSize = ReservedRangeToCompare->SmramReservedStart - RangeToCompare->CpuStart;
1192 //
1193 // 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
1194 // ReservedRangeToCompare->SmramReservedSize = 0
1195 //
1196 FinalRanges[*FinalRangeCount].CpuStart = ReservedRangeToCompare->SmramReservedStart;
1197 FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
1198 FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
1199 FinalRanges[*FinalRangeCount].PhysicalSize = ReservedRangeToCompare->SmramReservedSize;
1200 *FinalRangeCount += 1;
1201 ReservedRangeToCompare->SmramReservedSize = 0;
1202 //
1203 // 3. Update Ranges[*RangeCount] and increment *RangeCount.
1204 //
1205 Ranges[*RangeCount].CpuStart = FinalRanges[*FinalRangeCount - 1].CpuStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1206 Ranges[*RangeCount].PhysicalStart = FinalRanges[*FinalRangeCount - 1].PhysicalStart + FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1207 Ranges[*RangeCount].RegionState = RangeToCompare->RegionState;
1208 Ranges[*RangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompareEnd;
1209 *RangeCount += 1;
1210 } else {
1211 //
1212 // RangeToCompare ReservedRangeToCompare
1213 // ---- ---- --------------------------------------
1214 // | | | | -> 1. RangeToCompare
1215 // | | ---- |--| --------------------------------------
1216 // | | | | | |
1217 // | | | | | | -> 2. FinalRanges[*FinalRangeCount] and increment *FinalRangeCount
1218 // | | | | | |
1219 // ---- | | |--| --------------------------------------
1220 // | | | | -> 3. ReservedRangeToCompare
1221 // ---- ---- --------------------------------------
1222 //
1223
1224 //
1225 // 1. Update RangeToCompare.
1226 //
1227 RangeToCompare->PhysicalSize = ReservedRangeToCompare->SmramReservedStart - RangeToCompare->CpuStart;
1228 //
1229 // 2. Update FinalRanges[FinalRangeCount] and increment *FinalRangeCount.
1230 // ReservedRangeToCompare->SmramReservedSize = 0
1231 //
1232 FinalRanges[*FinalRangeCount].CpuStart = ReservedRangeToCompare->SmramReservedStart;
1233 FinalRanges[*FinalRangeCount].PhysicalStart = RangeToCompare->PhysicalStart + RangeToCompare->PhysicalSize;
1234 FinalRanges[*FinalRangeCount].RegionState = RangeToCompare->RegionState | EFI_ALLOCATED;
1235 FinalRanges[*FinalRangeCount].PhysicalSize = RangeToCompareEnd - ReservedRangeToCompare->SmramReservedStart;
1236 *FinalRangeCount += 1;
1237 //
1238 // 3. Update ReservedRangeToCompare.
1239 //
1240 ReservedRangeToCompare->SmramReservedStart += FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1241 ReservedRangeToCompare->SmramReservedSize -= FinalRanges[*FinalRangeCount - 1].PhysicalSize;
1242 }
1243 }
1244 }
1245
1246 /**
1247 Returns if SMRAM range and SMRAM reserved range are overlapped.
1248
1249 @param[in] RangeToCompare Pointer to EFI_SMRAM_DESCRIPTOR to compare.
1250 @param[in] ReservedRangeToCompare Pointer to EFI_SMM_RESERVED_SMRAM_REGION to compare.
1251
1252 @retval TRUE There is overlap.
1253 @retval FALSE There is no overlap.
1254
1255 **/
1256 BOOLEAN
1257 SmmIsSmramOverlap (
1258 IN EFI_SMRAM_DESCRIPTOR *RangeToCompare,
1259 IN EFI_SMM_RESERVED_SMRAM_REGION *ReservedRangeToCompare
1260 )
1261 {
1262 UINT64 RangeToCompareEnd;
1263 UINT64 ReservedRangeToCompareEnd;
1264
1265 RangeToCompareEnd = RangeToCompare->CpuStart + RangeToCompare->PhysicalSize;
1266 ReservedRangeToCompareEnd = ReservedRangeToCompare->SmramReservedStart + ReservedRangeToCompare->SmramReservedSize;
1267
1268 if ((RangeToCompare->CpuStart >= ReservedRangeToCompare->SmramReservedStart) &&
1269 (RangeToCompare->CpuStart < ReservedRangeToCompareEnd)) {
1270 return TRUE;
1271 } else if ((ReservedRangeToCompare->SmramReservedStart >= RangeToCompare->CpuStart) &&
1272 (ReservedRangeToCompare->SmramReservedStart < RangeToCompareEnd)) {
1273 return TRUE;
1274 }
1275 return FALSE;
1276 }
1277
1278 /**
1279 Get full SMRAM ranges.
1280
1281 It will get SMRAM ranges from SmmAccess protocol and SMRAM reserved ranges from
1282 SmmConfiguration protocol, split the entries if there is overlap between them.
1283 It will also reserve one entry for SMM core.
1284
1285 @param[out] FullSmramRangeCount Output pointer to full SMRAM range count.
1286
1287 @return Pointer to full SMRAM ranges.
1288
1289 **/
1290 EFI_SMRAM_DESCRIPTOR *
1291 GetFullSmramRanges (
1292 OUT UINTN *FullSmramRangeCount
1293 )
1294 {
1295 EFI_STATUS Status;
1296 EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
1297 UINTN Size;
1298 UINTN Index;
1299 UINTN Index2;
1300 EFI_SMRAM_DESCRIPTOR *FullSmramRanges;
1301 UINTN TempSmramRangeCount;
1302 EFI_SMRAM_DESCRIPTOR *TempSmramRanges;
1303 UINTN SmramRangeCount;
1304 EFI_SMRAM_DESCRIPTOR *SmramRanges;
1305 UINTN SmramReservedCount;
1306 EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges;
1307 UINTN MaxCount;
1308 BOOLEAN Rescan;
1309
1310 //
1311 // Get SMM Configuration Protocol if it is present.
1312 //
1313 SmmConfiguration = NULL;
1314 Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **) &SmmConfiguration);
1315
1316 //
1317 // Get SMRAM information.
1318 //
1319 Size = 0;
1320 Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, NULL);
1321 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
1322
1323 SmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);
1324
1325 //
1326 // Get SMRAM reserved region count.
1327 //
1328 SmramReservedCount = 0;
1329 if (SmmConfiguration != NULL) {
1330 while (SmmConfiguration->SmramReservedRegions[SmramReservedCount].SmramReservedSize != 0) {
1331 SmramReservedCount++;
1332 }
1333 }
1334
1335 if (SmramReservedCount == 0) {
1336 //
1337 // No reserved SMRAM entry from SMM Configuration Protocol.
1338 // Reserve one entry for SMM Core in the full SMRAM ranges.
1339 //
1340 *FullSmramRangeCount = SmramRangeCount + 1;
1341 Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR);
1342 FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocateZeroPool (Size);
1343 ASSERT (FullSmramRanges != NULL);
1344
1345 Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, FullSmramRanges);
1346 ASSERT_EFI_ERROR (Status);
1347
1348 return FullSmramRanges;
1349 }
1350
1351 //
1352 // Why MaxCount = X + 2 * Y?
1353 // Take Y = 1 as example below, Y > 1 case is just the iteration of Y = 1.
1354 //
1355 // X = 1 Y = 1 MaxCount = 3 = 1 + 2 * 1
1356 // ---- ----
1357 // | | ---- |--|
1358 // | | | | -> | |
1359 // | | ---- |--|
1360 // ---- ----
1361 //
1362 // X = 2 Y = 1 MaxCount = 4 = 2 + 2 * 1
1363 // ---- ----
1364 // | | | |
1365 // | | ---- |--|
1366 // | | | | | |
1367 // |--| | | -> |--|
1368 // | | | | | |
1369 // | | ---- |--|
1370 // | | | |
1371 // ---- ----
1372 //
1373 // X = 3 Y = 1 MaxCount = 5 = 3 + 2 * 1
1374 // ---- ----
1375 // | | | |
1376 // | | ---- |--|
1377 // |--| | | |--|
1378 // | | | | -> | |
1379 // |--| | | |--|
1380 // | | ---- |--|
1381 // | | | |
1382 // ---- ----
1383 //
1384 // ......
1385 //
1386 MaxCount = SmramRangeCount + 2 * SmramReservedCount;
1387
1388 Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION);
1389 SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *) AllocatePool (Size);
1390 ASSERT (SmramReservedRanges != NULL);
1391 for (Index = 0; Index < SmramReservedCount; Index++) {
1392 CopyMem (&SmramReservedRanges[Index], &SmmConfiguration->SmramReservedRegions[Index], sizeof (EFI_SMM_RESERVED_SMRAM_REGION));
1393 }
1394
1395 Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR);
1396 TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
1397 ASSERT (TempSmramRanges != NULL);
1398 TempSmramRangeCount = 0;
1399
1400 SmramRanges = (EFI_SMRAM_DESCRIPTOR *) AllocatePool (Size);
1401 ASSERT (SmramRanges != NULL);
1402 Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, SmramRanges);
1403 ASSERT_EFI_ERROR (Status);
1404
1405 do {
1406 Rescan = FALSE;
1407 for (Index = 0; (Index < SmramRangeCount) && !Rescan; Index++) {
1408 //
1409 // Skip zero size entry.
1410 //
1411 if (SmramRanges[Index].PhysicalSize != 0) {
1412 for (Index2 = 0; (Index2 < SmramReservedCount) && !Rescan; Index2++) {
1413 //
1414 // Skip zero size entry.
1415 //
1416 if (SmramReservedRanges[Index2].SmramReservedSize != 0) {
1417 if (SmmIsSmramOverlap (
1418 &SmramRanges[Index],
1419 &SmramReservedRanges[Index2]
1420 )) {
1421 //
1422 // There is overlap, need to split entry and then rescan.
1423 //
1424 SmmSplitSmramEntry (
1425 &SmramRanges[Index],
1426 &SmramReservedRanges[Index2],
1427 SmramRanges,
1428 &SmramRangeCount,
1429 SmramReservedRanges,
1430 &SmramReservedCount,
1431 TempSmramRanges,
1432 &TempSmramRangeCount
1433 );
1434 Rescan = TRUE;
1435 }
1436 }
1437 }
1438 if (!Rescan) {
1439 //
1440 // No any overlap, copy the entry to the temp SMRAM ranges.
1441 // Zero SmramRanges[Index].PhysicalSize = 0;
1442 //
1443 CopyMem (&TempSmramRanges[TempSmramRangeCount++], &SmramRanges[Index], sizeof (EFI_SMRAM_DESCRIPTOR));
1444 SmramRanges[Index].PhysicalSize = 0;
1445 }
1446 }
1447 }
1448 } while (Rescan);
1449 ASSERT (TempSmramRangeCount <= MaxCount);
1450
1451 //
1452 // Sort the entries,
1453 // and reserve one entry for SMM Core in the full SMRAM ranges.
1454 //
1455 FullSmramRanges = AllocateZeroPool ((TempSmramRangeCount + 1) * sizeof (EFI_SMRAM_DESCRIPTOR));
1456 ASSERT (FullSmramRanges != NULL);
1457 *FullSmramRangeCount = 0;
1458 do {
1459 for (Index = 0; Index < TempSmramRangeCount; Index++) {
1460 if (TempSmramRanges[Index].PhysicalSize != 0) {
1461 break;
1462 }
1463 }
1464 ASSERT (Index < TempSmramRangeCount);
1465 for (Index2 = 0; Index2 < TempSmramRangeCount; Index2++) {
1466 if ((Index2 != Index) && (TempSmramRanges[Index2].PhysicalSize != 0) && (TempSmramRanges[Index2].CpuStart < TempSmramRanges[Index].CpuStart)) {
1467 Index = Index2;
1468 }
1469 }
1470 CopyMem (&FullSmramRanges[*FullSmramRangeCount], &TempSmramRanges[Index], sizeof (EFI_SMRAM_DESCRIPTOR));
1471 *FullSmramRangeCount += 1;
1472 TempSmramRanges[Index].PhysicalSize = 0;
1473 } while (*FullSmramRangeCount < TempSmramRangeCount);
1474 ASSERT (*FullSmramRangeCount == TempSmramRangeCount);
1475 *FullSmramRangeCount += 1;
1476
1477 FreePool (SmramRanges);
1478 FreePool (SmramReservedRanges);
1479 FreePool (TempSmramRanges);
1480
1481 return FullSmramRanges;
1482 }
1483
1484 /**
1485 The Entry Point for SMM IPL
1486
1487 Load SMM Core into SMRAM, register SMM Core entry point for SMIs, install
1488 SMM Base 2 Protocol and SMM Communication Protocol, and register for the
1489 critical events required to coordinate between DXE and SMM environments.
1490
1491 @param ImageHandle The firmware allocated handle for the EFI image.
1492 @param SystemTable A pointer to the EFI System Table.
1493
1494 @retval EFI_SUCCESS The entry point is executed successfully.
1495 @retval Other Some error occurred when executing this entry point.
1496
1497 **/
1498 EFI_STATUS
1499 EFIAPI
1500 SmmIplEntry (
1501 IN EFI_HANDLE ImageHandle,
1502 IN EFI_SYSTEM_TABLE *SystemTable
1503 )
1504 {
1505 EFI_STATUS Status;
1506 UINTN Index;
1507 UINT64 MaxSize;
1508 VOID *Registration;
1509 UINT64 SmmCodeSize;
1510 EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
1511 EFI_CPU_ARCH_PROTOCOL *CpuArch;
1512 EFI_STATUS SetAttrStatus;
1513
1514 //
1515 // Fill in the image handle of the SMM IPL so the SMM Core can use this as the
1516 // ParentImageHandle field of the Load Image Protocol for all SMM Drivers loaded
1517 // by the SMM Core
1518 //
1519 mSmmCorePrivateData.SmmIplImageHandle = ImageHandle;
1520
1521 //
1522 // Get SMM Access Protocol
1523 //
1524 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&mSmmAccess);
1525 ASSERT_EFI_ERROR (Status);
1526
1527 //
1528 // Get SMM Control2 Protocol
1529 //
1530 Status = gBS->LocateProtocol (&gEfiSmmControl2ProtocolGuid, NULL, (VOID **)&mSmmControl2);
1531 ASSERT_EFI_ERROR (Status);
1532
1533 gSmmCorePrivate->SmramRanges = GetFullSmramRanges (&gSmmCorePrivate->SmramRangeCount);
1534
1535 //
1536 // Open all SMRAM ranges
1537 //
1538 Status = mSmmAccess->Open (mSmmAccess);
1539 ASSERT_EFI_ERROR (Status);
1540
1541 //
1542 // Print debug message that the SMRAM window is now open.
1543 //
1544 DEBUG ((DEBUG_INFO, "SMM IPL opened SMRAM window\n"));
1545
1546 //
1547 // Find the largest SMRAM range between 1MB and 4GB that is at least 256KB - 4K in size
1548 //
1549 mCurrentSmramRange = NULL;
1550 for (Index = 0, MaxSize = SIZE_256KB - EFI_PAGE_SIZE; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
1551 //
1552 // Skip any SMRAM region that is already allocated, needs testing, or needs ECC initialization
1553 //
1554 if ((gSmmCorePrivate->SmramRanges[Index].RegionState & (EFI_ALLOCATED | EFI_NEEDS_TESTING | EFI_NEEDS_ECC_INITIALIZATION)) != 0) {
1555 continue;
1556 }
1557
1558 if (gSmmCorePrivate->SmramRanges[Index].CpuStart >= BASE_1MB) {
1559 if ((gSmmCorePrivate->SmramRanges[Index].CpuStart + gSmmCorePrivate->SmramRanges[Index].PhysicalSize - 1) <= MAX_ADDRESS) {
1560 if (gSmmCorePrivate->SmramRanges[Index].PhysicalSize >= MaxSize) {
1561 MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
1562 mCurrentSmramRange = &gSmmCorePrivate->SmramRanges[Index];
1563 }
1564 }
1565 }
1566 }
1567
1568 if (mCurrentSmramRange != NULL) {
1569 //
1570 // Print debug message showing SMRAM window that will be used by SMM IPL and SMM Core
1571 //
1572 DEBUG ((DEBUG_INFO, "SMM IPL found SMRAM window %p - %p\n",
1573 (VOID *)(UINTN)mCurrentSmramRange->CpuStart,
1574 (VOID *)(UINTN)(mCurrentSmramRange->CpuStart + mCurrentSmramRange->PhysicalSize - 1)
1575 ));
1576
1577 GetSmramCacheRange (mCurrentSmramRange, &mSmramCacheBase, &mSmramCacheSize);
1578 //
1579 // If CPU AP is present, attempt to set SMRAM cacheability to WB
1580 // Note that it is expected that cacheability of SMRAM has been set to WB if CPU AP
1581 // is not available here.
1582 //
1583 CpuArch = NULL;
1584 Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);
1585 if (!EFI_ERROR (Status)) {
1586 Status = gDS->SetMemorySpaceAttributes(
1587 mSmramCacheBase,
1588 mSmramCacheSize,
1589 EFI_MEMORY_WB
1590 );
1591 if (EFI_ERROR (Status)) {
1592 DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));
1593 }
1594 }
1595 //
1596 // if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load
1597 // Modules At Fixed Address Configuration Table.
1598 //
1599 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
1600 //
1601 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
1602 //
1603 SmmCodeSize = LShiftU64 (PcdGet32(PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
1604 //
1605 // The SMRAM available memory is assumed to be larger than SmmCodeSize
1606 //
1607 ASSERT (mCurrentSmramRange->PhysicalSize > SmmCodeSize);
1608 //
1609 // Retrieve Load modules At fixed address configuration table and save the SMRAM base.
1610 //
1611 Status = EfiGetSystemConfigurationTable (
1612 &gLoadFixedAddressConfigurationTableGuid,
1613 (VOID **) &LMFAConfigurationTable
1614 );
1615 if (!EFI_ERROR (Status) && LMFAConfigurationTable != NULL) {
1616 LMFAConfigurationTable->SmramBase = mCurrentSmramRange->CpuStart;
1617 //
1618 // Print the SMRAM base
1619 //
1620 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: TSEG BASE is %x. \n", LMFAConfigurationTable->SmramBase));
1621 }
1622 }
1623 //
1624 // Load SMM Core into SMRAM and execute it from SMRAM
1625 //
1626 Status = ExecuteSmmCoreFromSmram (
1627 mCurrentSmramRange,
1628 &gSmmCorePrivate->SmramRanges[gSmmCorePrivate->SmramRangeCount - 1],
1629 gSmmCorePrivate
1630 );
1631 if (EFI_ERROR (Status)) {
1632 //
1633 // Print error message that the SMM Core failed to be loaded and executed.
1634 //
1635 DEBUG ((DEBUG_ERROR, "SMM IPL could not load and execute SMM Core from SMRAM\n"));
1636
1637 //
1638 // Attempt to reset SMRAM cacheability to UC
1639 //
1640 if (CpuArch != NULL) {
1641 SetAttrStatus = gDS->SetMemorySpaceAttributes(
1642 mSmramCacheBase,
1643 mSmramCacheSize,
1644 EFI_MEMORY_UC
1645 );
1646 if (EFI_ERROR (SetAttrStatus)) {
1647 DEBUG ((DEBUG_WARN, "SMM IPL failed to reset SMRAM window to EFI_MEMORY_UC\n"));
1648 }
1649 }
1650 }
1651 } else {
1652 //
1653 // Print error message that there are not enough SMRAM resources to load the SMM Core.
1654 //
1655 DEBUG ((DEBUG_ERROR, "SMM IPL could not find a large enough SMRAM region to load SMM Core\n"));
1656 }
1657
1658 //
1659 // If the SMM Core could not be loaded then close SMRAM window, free allocated
1660 // resources, and return an error so SMM IPL will be unloaded.
1661 //
1662 if (mCurrentSmramRange == NULL || EFI_ERROR (Status)) {
1663 //
1664 // Close all SMRAM ranges
1665 //
1666 Status = mSmmAccess->Close (mSmmAccess);
1667 ASSERT_EFI_ERROR (Status);
1668
1669 //
1670 // Print debug message that the SMRAM window is now closed.
1671 //
1672 DEBUG ((DEBUG_INFO, "SMM IPL closed SMRAM window\n"));
1673
1674 //
1675 // Free all allocated resources
1676 //
1677 FreePool (gSmmCorePrivate->SmramRanges);
1678
1679 return EFI_UNSUPPORTED;
1680 }
1681
1682 //
1683 // Install SMM Base2 Protocol and SMM Communication Protocol
1684 //
1685 Status = gBS->InstallMultipleProtocolInterfaces (
1686 &mSmmIplHandle,
1687 &gEfiSmmBase2ProtocolGuid, &mSmmBase2,
1688 &gEfiSmmCommunicationProtocolGuid, &mSmmCommunication,
1689 NULL
1690 );
1691 ASSERT_EFI_ERROR (Status);
1692
1693 //
1694 // Create the set of protocol and event notififcations that the SMM IPL requires
1695 //
1696 for (Index = 0; mSmmIplEvents[Index].NotifyFunction != NULL; Index++) {
1697 if (mSmmIplEvents[Index].Protocol) {
1698 mSmmIplEvents[Index].Event = EfiCreateProtocolNotifyEvent (
1699 mSmmIplEvents[Index].Guid,
1700 mSmmIplEvents[Index].NotifyTpl,
1701 mSmmIplEvents[Index].NotifyFunction,
1702 mSmmIplEvents[Index].NotifyContext,
1703 &Registration
1704 );
1705 } else {
1706 Status = gBS->CreateEventEx (
1707 EVT_NOTIFY_SIGNAL,
1708 mSmmIplEvents[Index].NotifyTpl,
1709 mSmmIplEvents[Index].NotifyFunction,
1710 mSmmIplEvents[Index].NotifyContext,
1711 mSmmIplEvents[Index].Guid,
1712 &mSmmIplEvents[Index].Event
1713 );
1714 ASSERT_EFI_ERROR (Status);
1715 }
1716 }
1717
1718 return EFI_SUCCESS;
1719 }