]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
Update the copyright notice format
[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 - 2010, 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/FirmwareVolume2.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/UefiLib.h>
38 #include <Library/UefiRuntimeLib.h>
39 #include <Library/PcdLib.h>
40
41 #include "PiSmmCorePrivateData.h"
42
43 //
44 // Function prototypes from produced protocols
45 //
46
47 /**
48 Indicate whether the driver is currently executing in the SMM Initialization phase.
49
50 @param This The EFI_SMM_BASE2_PROTOCOL instance.
51 @param InSmram Pointer to a Boolean which, on return, indicates that the driver is currently executing
52 inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
53
54 @retval EFI_INVALID_PARAMETER InSmram was NULL.
55 @retval EFI_SUCCESS The call returned successfully.
56
57 **/
58 EFI_STATUS
59 EFIAPI
60 SmmBase2InSmram (
61 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
62 OUT BOOLEAN *InSmram
63 );
64
65 /**
66 Retrieves the location of the System Management System Table (SMST).
67
68 @param This The EFI_SMM_BASE2_PROTOCOL instance.
69 @param Smst On return, points to a pointer to the System Management Service Table (SMST).
70
71 @retval EFI_INVALID_PARAMETER Smst or This was invalid.
72 @retval EFI_SUCCESS The memory was returned to the system.
73 @retval EFI_UNSUPPORTED Not in SMM.
74
75 **/
76 EFI_STATUS
77 EFIAPI
78 SmmBase2GetSmstLocation (
79 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
80 OUT EFI_SMM_SYSTEM_TABLE2 **Smst
81 );
82
83 /**
84 Communicates with a registered handler.
85
86 This function provides a service to send and receive messages from a registered
87 UEFI service. This function is part of the SMM Communication Protocol that may
88 be called in physical mode prior to SetVirtualAddressMap() and in virtual mode
89 after SetVirtualAddressMap().
90
91 @param[in] This The EFI_SMM_COMMUNICATION_PROTOCOL instance.
92 @param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM.
93 @param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data
94 being returned. Zero if the handler does not wish to reply with any data.
95
96 @retval EFI_SUCCESS The message was successfully posted.
97 @retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
98 **/
99 EFI_STATUS
100 EFIAPI
101 SmmCommunicationCommunicate (
102 IN CONST EFI_SMM_COMMUNICATION_PROTOCOL *This,
103 IN OUT VOID *CommBuffer,
104 IN OUT UINTN *CommSize
105 );
106
107 /**
108 Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
109
110 @param Event The Event that is being processed, not used.
111 @param Context Event Context, not used.
112
113 **/
114 VOID
115 EFIAPI
116 SmmIplSmmConfigurationEventNotify (
117 IN EFI_EVENT Event,
118 IN VOID *Context
119 );
120
121 /**
122 Event notification that is fired every time a DxeSmmReadyToLock protocol is added
123 or if gEfiEventReadyToBootGuid is signalled.
124
125 @param Event The Event that is being processed, not used.
126 @param Context Event Context, not used.
127
128 **/
129 VOID
130 EFIAPI
131 SmmIplReadyToLockEventNotify (
132 IN EFI_EVENT Event,
133 IN VOID *Context
134 );
135
136 /**
137 Event notification that is fired when DxeDispatch Event Group is signaled.
138
139 @param Event The Event that is being processed, not used.
140 @param Context Event Context, not used.
141
142 **/
143 VOID
144 EFIAPI
145 SmmIplGuidedEventNotify (
146 IN EFI_EVENT Event,
147 IN VOID *Context
148 );
149
150 /**
151 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
152
153 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
154 It convers pointer to new virtual address.
155
156 @param Event Event whose notification function is being invoked.
157 @param Context Pointer to the notification function's context.
158
159 **/
160 VOID
161 EFIAPI
162 SmmIplSetVirtualAddressNotify (
163 IN EFI_EVENT Event,
164 IN VOID *Context
165 );
166
167 //
168 // Data structure used to declare a table of protocol notifications and event
169 // notifications required by the SMM IPL
170 //
171 typedef struct {
172 BOOLEAN Protocol;
173 BOOLEAN CloseOnLock;
174 EFI_GUID *Guid;
175 EFI_EVENT_NOTIFY NotifyFunction;
176 VOID *NotifyContext;
177 EFI_EVENT Event;
178 } SMM_IPL_EVENT_NOTIFICATION;
179
180 //
181 // Handle to install the SMM Base2 Protocol and the SMM Communication Protocol
182 //
183 EFI_HANDLE mSmmIplHandle = NULL;
184
185 //
186 // SMM Base 2 Protocol instance
187 //
188 EFI_SMM_BASE2_PROTOCOL mSmmBase2 = {
189 SmmBase2InSmram,
190 SmmBase2GetSmstLocation
191 };
192
193 //
194 // SMM Communication Protocol instance
195 //
196 EFI_SMM_COMMUNICATION_PROTOCOL mSmmCommunication = {
197 SmmCommunicationCommunicate
198 };
199
200 //
201 // SMM Core Private Data structure that contains the data shared between
202 // the SMM IPL and the SMM Core.
203 //
204 SMM_CORE_PRIVATE_DATA mSmmCorePrivateData = {
205 SMM_CORE_PRIVATE_DATA_SIGNATURE, // Signature
206 NULL, // SmmIplImageHandle
207 0, // SmramRangeCount
208 NULL, // SmramRanges
209 NULL, // SmmEntryPoint
210 FALSE, // SmmEntryPointRegistered
211 FALSE, // InSmm
212 NULL, // Smst
213 NULL, // CommunicationBuffer
214 0, // BufferSize
215 EFI_SUCCESS // ReturnStatus
216 };
217
218 //
219 // Global pointer used to access mSmmCorePrivateData from outside and inside SMM
220 //
221 SMM_CORE_PRIVATE_DATA *gSmmCorePrivate = &mSmmCorePrivateData;
222
223 //
224 // SMM IPL global variables
225 //
226 EFI_SMM_CONTROL2_PROTOCOL *mSmmControl2;
227 EFI_SMM_ACCESS2_PROTOCOL *mSmmAccess;
228 EFI_SMRAM_DESCRIPTOR *mCurrentSmramRange;
229 BOOLEAN mSmmLocked = FALSE;
230 EFI_PHYSICAL_ADDRESS mSmramCacheBase;
231 UINT64 mSmramCacheSize;
232
233 //
234 // Table of Protocol notification and GUIDed Event notifications that the SMM IPL requires
235 //
236 SMM_IPL_EVENT_NOTIFICATION mSmmIplEvents[] = {
237 //
238 // Declare protocol notification on the SMM Configuration protocol. When this notification is etablished,
239 // the associated event is immediately signalled, so the notification function will be executed and the
240 // SMM Configuration Protocol will be found if it is already in the handle database.
241 //
242 { TRUE, FALSE, &gEfiSmmConfigurationProtocolGuid, SmmIplSmmConfigurationEventNotify, &gEfiSmmConfigurationProtocolGuid, NULL },
243 //
244 // Declare protocl notification on DxeSmmReadyToLock protocols. When this notification is etablished,
245 // the associated event is immediately signalled, so the notification function will be executed and the
246 // DXE SMM Ready To Lock Protocol will be found if it is already in the handle database.
247 //
248 { TRUE, TRUE, &gEfiDxeSmmReadyToLockProtocolGuid, SmmIplReadyToLockEventNotify, &gEfiDxeSmmReadyToLockProtocolGuid, NULL },
249 //
250 // Declare event notification on the DXE Dispatch Event Group. This event is signaled by the DXE Core
251 // each time the DXE Core dispatcher has completed its work. When this event is signalled, the SMM Core
252 // if notified, so the SMM Core can dispatch SMM drivers.
253 //
254 { FALSE, TRUE, &gEfiEventDxeDispatchGuid, SmmIplGuidedEventNotify, &gEfiEventDxeDispatchGuid, NULL },
255 //
256 // Declare event notification on Ready To Boot Event Group. This is an extra event notification that is
257 // used to make sure SMRAM is locked before any boot options are processed.
258 //
259 { FALSE, TRUE, &gEfiEventReadyToBootGuid, SmmIplReadyToLockEventNotify, &gEfiEventReadyToBootGuid, NULL },
260 //
261 // Declare event notification on Legacy Boot Event Group. This is used to inform the SMM Core that the platform
262 // is performing a legacy boot operation, and that the UEFI environment is no longer available and the SMM Core
263 // must guarantee that it does not access any UEFI related structures outside of SMRAM.
264 //
265 { FALSE, FALSE, &gEfiEventLegacyBootGuid, SmmIplGuidedEventNotify, &gEfiEventLegacyBootGuid, NULL },
266 //
267 // Declare event notification on SetVirtualAddressMap() Event Group. This is used to convert gSmmCorePrivate
268 // and mSmmControl2 from physical addresses to virtual addresses.
269 //
270 { FALSE, FALSE, &gEfiEventVirtualAddressChangeGuid, SmmIplSetVirtualAddressNotify, NULL, NULL },
271 //
272 // Terminate the table of event notifications
273 //
274 { FALSE, FALSE, NULL, NULL, NULL, NULL }
275 };
276
277 /**
278 Find the maximum SMRAM cache range that covers the range specified by SmramRange.
279
280 This function searches and joins all adjacent ranges of SmramRange into a range to be cached.
281
282 @param SmramRange The SMRAM range to search from.
283 @param SmramCacheBase The returned cache range base.
284 @param SmramCacheSize The returned cache range size.
285
286 **/
287 VOID
288 GetSmramCacheRange (
289 IN EFI_SMRAM_DESCRIPTOR *SmramRange,
290 OUT EFI_PHYSICAL_ADDRESS *SmramCacheBase,
291 OUT UINT64 *SmramCacheSize
292 )
293 {
294 UINTN Index;
295 EFI_PHYSICAL_ADDRESS RangeCpuStart;
296 UINT64 RangePhysicalSize;
297 BOOLEAN FoundAjacentRange;
298
299 *SmramCacheBase = SmramRange->CpuStart;
300 *SmramCacheSize = SmramRange->PhysicalSize;
301
302 do {
303 FoundAjacentRange = FALSE;
304 for (Index = 0; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
305 RangeCpuStart = gSmmCorePrivate->SmramRanges[Index].CpuStart;
306 RangePhysicalSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
307 if (RangeCpuStart < *SmramCacheBase && *SmramCacheBase == (RangeCpuStart + RangePhysicalSize)) {
308 *SmramCacheBase = RangeCpuStart;
309 *SmramCacheSize += RangePhysicalSize;
310 FoundAjacentRange = TRUE;
311 } else if ((*SmramCacheBase + *SmramCacheSize) == RangeCpuStart && RangePhysicalSize > 0) {
312 *SmramCacheSize += RangePhysicalSize;
313 FoundAjacentRange = TRUE;
314 }
315 }
316 } while (FoundAjacentRange);
317
318 }
319
320 /**
321 Indicate whether the driver is currently executing in the SMM Initialization phase.
322
323 @param This The EFI_SMM_BASE2_PROTOCOL instance.
324 @param InSmram Pointer to a Boolean which, on return, indicates that the driver is currently executing
325 inside of SMRAM (TRUE) or outside of SMRAM (FALSE).
326
327 @retval EFI_INVALID_PARAMETER InSmram was NULL.
328 @retval EFI_SUCCESS The call returned successfully.
329
330 **/
331 EFI_STATUS
332 EFIAPI
333 SmmBase2InSmram (
334 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
335 OUT BOOLEAN *InSmram
336 )
337 {
338 if (InSmram == NULL) {
339 return EFI_INVALID_PARAMETER;
340 }
341
342 *InSmram = gSmmCorePrivate->InSmm;
343
344 return EFI_SUCCESS;
345 }
346
347 /**
348 Retrieves the location of the System Management System Table (SMST).
349
350 @param This The EFI_SMM_BASE2_PROTOCOL instance.
351 @param Smst On return, points to a pointer to the System Management Service Table (SMST).
352
353 @retval EFI_INVALID_PARAMETER Smst or This was invalid.
354 @retval EFI_SUCCESS The memory was returned to the system.
355 @retval EFI_UNSUPPORTED Not in SMM.
356
357 **/
358 EFI_STATUS
359 EFIAPI
360 SmmBase2GetSmstLocation (
361 IN CONST EFI_SMM_BASE2_PROTOCOL *This,
362 OUT EFI_SMM_SYSTEM_TABLE2 **Smst
363 )
364 {
365 if ((This == NULL) ||(Smst == NULL)) {
366 return EFI_INVALID_PARAMETER;
367 }
368
369 if (!gSmmCorePrivate->InSmm) {
370 return EFI_UNSUPPORTED;
371 }
372
373 *Smst = gSmmCorePrivate->Smst;
374
375 return EFI_SUCCESS;
376 }
377
378 /**
379 Communicates with a registered handler.
380
381 This function provides a service to send and receive messages from a registered
382 UEFI service. This function is part of the SMM Communication Protocol that may
383 be called in physical mode prior to SetVirtualAddressMap() and in virtual mode
384 after SetVirtualAddressMap().
385
386 @param[in] This The EFI_SMM_COMMUNICATION_PROTOCOL instance.
387 @param[in, out] CommBuffer A pointer to the buffer to convey into SMRAM.
388 @param[in, out] CommSize The size of the data buffer being passed in.On exit, the size of data
389 being returned. Zero if the handler does not wish to reply with any data.
390
391 @retval EFI_SUCCESS The message was successfully posted.
392 @retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
393 **/
394 EFI_STATUS
395 EFIAPI
396 SmmCommunicationCommunicate (
397 IN CONST EFI_SMM_COMMUNICATION_PROTOCOL *This,
398 IN OUT VOID *CommBuffer,
399 IN OUT UINTN *CommSize
400 )
401 {
402 EFI_STATUS Status;
403 EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
404 BOOLEAN OldInSmm;
405
406 //
407 // Check parameters
408 //
409 if ((CommBuffer == NULL) || (CommSize == NULL)) {
410 return EFI_INVALID_PARAMETER;
411 }
412
413 //
414 // CommSize must hold HeaderGuid and MessageLength
415 //
416 if (*CommSize < OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)) {
417 return EFI_INVALID_PARAMETER;
418 }
419
420 //
421 // If not already in SMM, then generate a Software SMI
422 //
423 if (!gSmmCorePrivate->InSmm && gSmmCorePrivate->SmmEntryPointRegistered) {
424 //
425 // Put arguments for Software SMI in gSmmCorePrivate
426 //
427 gSmmCorePrivate->CommunicationBuffer = CommBuffer;
428 gSmmCorePrivate->BufferSize = *CommSize;
429
430 //
431 // Generate Software SMI
432 //
433 Status = mSmmControl2->Trigger (mSmmControl2, NULL, NULL, FALSE, 0);
434 if (EFI_ERROR (Status)) {
435 return EFI_UNSUPPORTED;
436 }
437
438 //
439 // Return status from software SMI
440 //
441 *CommSize = gSmmCorePrivate->BufferSize;
442 return gSmmCorePrivate->ReturnStatus;
443 }
444
445 //
446 // If we are in SMM, then the execution mode must be physical, which means that
447 // OS established virtual addresses can not be used. If SetVirtualAddressMap()
448 // has been called, then a direct invocation of the Software SMI is not
449 // not allowed so return EFI_INVALID_PARAMETER.
450 //
451 if (EfiGoneVirtual()) {
452 return EFI_INVALID_PARAMETER;
453 }
454
455 //
456 // Don't allow call SmiManage() directly when SMRAM is closed or locked.
457 //
458 if (!mSmmAccess->OpenState || mSmmAccess->LockState) {
459 return EFI_INVALID_PARAMETER;
460 }
461
462 //
463 // Save current InSmm state and set InSmm state to TRUE
464 //
465 OldInSmm = gSmmCorePrivate->InSmm;
466 gSmmCorePrivate->InSmm = TRUE;
467
468 //
469 // Already in SMM and before SetVirtualAddressMap(), so call SmiManage() directly.
470 //
471 CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommBuffer;
472 *CommSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
473 Status = gSmmCorePrivate->Smst->SmiManage (
474 &CommunicateHeader->HeaderGuid,
475 NULL,
476 CommunicateHeader->Data,
477 CommSize
478 );
479
480 //
481 // Update CommunicationBuffer, BufferSize and ReturnStatus
482 // Communicate service finished, reset the pointer to CommBuffer to NULL
483 //
484 *CommSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
485
486 //
487 // Restore original InSmm state
488 //
489 gSmmCorePrivate->InSmm = OldInSmm;
490
491 return (Status == EFI_WARN_INTERRUPT_SOURCE_QUIESCED) ? EFI_SUCCESS : EFI_NOT_FOUND;
492 }
493
494 /**
495 Event notification that is fired when DxeDispatch Event Group is signaled.
496
497 @param Event The Event that is being processed, not used.
498 @param Context Event Context, not used.
499
500 **/
501 VOID
502 EFIAPI
503 SmmIplGuidedEventNotify (
504 IN EFI_EVENT Event,
505 IN VOID *Context
506 )
507 {
508 EFI_SMM_COMMUNICATE_HEADER CommunicateHeader;
509 UINTN Size;
510
511 //
512 // Use Guid to initialize EFI_SMM_COMMUNICATE_HEADER structure
513 //
514 CopyGuid (&CommunicateHeader.HeaderGuid, (EFI_GUID *)Context);
515 CommunicateHeader.MessageLength = 1;
516 CommunicateHeader.Data[0] = 0;
517
518 //
519 // Generate the Software SMI and return the result
520 //
521 Size = sizeof (CommunicateHeader);
522 SmmCommunicationCommunicate (&mSmmCommunication, &CommunicateHeader, &Size);
523 }
524
525 /**
526 Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
527
528 @param Event The Event that is being processed, not used.
529 @param Context Event Context, not used.
530
531 **/
532 VOID
533 EFIAPI
534 SmmIplSmmConfigurationEventNotify (
535 IN EFI_EVENT Event,
536 IN VOID *Context
537 )
538 {
539 EFI_STATUS Status;
540 EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
541
542 //
543 // Make sure this notification is for this handler
544 //
545 Status = gBS->LocateProtocol (Context, NULL, (VOID **)&SmmConfiguration);
546 if (EFI_ERROR (Status)) {
547 return;
548 }
549
550 //
551 // Register the SMM Entry Point provided by the SMM Core with the SMM COnfiguration protocol
552 //
553 Status = SmmConfiguration->RegisterSmmEntry (SmmConfiguration, gSmmCorePrivate->SmmEntryPoint);
554 ASSERT_EFI_ERROR (Status);
555
556 //
557 // Set flag to indicate that the SM< Entry Point has been registered which
558 // means that SMIs are now fully operational.
559 //
560 gSmmCorePrivate->SmmEntryPointRegistered = TRUE;
561
562 //
563 // Print debug message showing SMM Core entry point address.
564 //
565 DEBUG ((DEBUG_INFO, "SMM IPL registered SMM Entry Point address %p\n", (VOID *)(UINTN)gSmmCorePrivate->SmmEntryPoint));
566
567 //
568 // Attempt to reset SMRAM cacheability to UC
569 //
570 Status = gDS->SetMemorySpaceAttributes(
571 mSmramCacheBase,
572 mSmramCacheSize,
573 EFI_MEMORY_UC
574 );
575 if (EFI_ERROR (Status)) {
576 DEBUG ((DEBUG_WARN, "SMM IPL failed to reset SMRAM window to EFI_MEMORY_UC\n"));
577 }
578
579 //
580 // Close all SMRAM ranges to protect SMRAM
581 //
582 Status = mSmmAccess->Close (mSmmAccess);
583 ASSERT_EFI_ERROR (Status);
584
585 //
586 // Print debug message that the SMRAM window is now closed.
587 //
588 DEBUG ((DEBUG_INFO, "SMM IPL closed SMRAM window\n"));
589 }
590
591 /**
592 Event notification that is fired every time a DxeSmmReadyToLock protocol is added
593 or if gEfiEventReadyToBootGuid is signalled.
594
595 @param Event The Event that is being processed, not used.
596 @param Context Event Context, not used.
597
598 **/
599 VOID
600 EFIAPI
601 SmmIplReadyToLockEventNotify (
602 IN EFI_EVENT Event,
603 IN VOID *Context
604 )
605 {
606 EFI_STATUS Status;
607 VOID *Interface;
608 UINTN Index;
609
610 //
611 // See if we are already locked
612 //
613 if (mSmmLocked) {
614 return;
615 }
616
617 //
618 // Make sure this notification is for this handler
619 //
620 if (CompareGuid ((EFI_GUID *)Context, &gEfiDxeSmmReadyToLockProtocolGuid)) {
621 Status = gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL, &Interface);
622 if (EFI_ERROR (Status)) {
623 return;
624 }
625 } else {
626 //
627 // If SMM is not locked yet and we got here from gEfiEventReadyToBootGuid being
628 // signalled, then gEfiDxeSmmReadyToLockProtocolGuid was not installed as expected.
629 // Print a warning on debug builds.
630 //
631 DEBUG ((DEBUG_WARN, "SMM IPL! DXE SMM Ready To Lock Protocol not installed before Ready To Boot signal\n"));
632 }
633
634 //
635 // Lock the SMRAM (Note: Locking SMRAM may not be supported on all platforms)
636 //
637 mSmmAccess->Lock (mSmmAccess);
638
639 //
640 // Close protocol and event notification events that do not apply after the
641 // DXE SMM Ready To Lock Protocol has been installed or the Ready To Boot
642 // event has been signalled.
643 //
644 for (Index = 0; mSmmIplEvents[Index].NotifyFunction != NULL; Index++) {
645 if (mSmmIplEvents[Index].CloseOnLock) {
646 gBS->CloseEvent (mSmmIplEvents[Index].Event);
647 }
648 }
649
650 //
651 // Inform SMM Core that the DxeSmmReadyToLock protocol was installed
652 //
653 SmmIplGuidedEventNotify (Event, (VOID *)&gEfiDxeSmmReadyToLockProtocolGuid);
654
655 //
656 // Print debug message that the SMRAM window is now locked.
657 //
658 DEBUG ((DEBUG_INFO, "SMM IPL locked SMRAM window\n"));
659
660 //
661 // Set flag so this operation will not be performed again
662 //
663 mSmmLocked = TRUE;
664 }
665
666 /**
667 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
668
669 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
670 It convers pointer to new virtual address.
671
672 @param Event Event whose notification function is being invoked.
673 @param Context Pointer to the notification function's context.
674
675 **/
676 VOID
677 EFIAPI
678 SmmIplSetVirtualAddressNotify (
679 IN EFI_EVENT Event,
680 IN VOID *Context
681 )
682 {
683 EfiConvertPointer (0x0, (VOID **)&mSmmControl2);
684 }
685
686 /**
687 Searches all Firmware Volumes for the first file matching FileType and SectionType and returns the section data.
688
689 @param FileType FileType to search for within any of the firmware volumes in the platform.
690 @param SectionType SectionType to search for within any of the matching FileTypes in the firmware volumes in the platform.
691 @param SourceSize Return the size of the returned section data..
692
693 @retval != NULL Pointer to the allocated buffer containing the section data.
694 @retval NULL Section data was not found.
695
696 **/
697 VOID *
698 GetSectionInAnyFv (
699 IN EFI_FV_FILETYPE FileType,
700 IN EFI_SECTION_TYPE SectionType,
701 OUT UINTN *SourceSize
702 )
703 {
704 EFI_STATUS Status;
705 UINTN HandleCount;
706 EFI_HANDLE *HandleBuffer;
707 UINTN Index;
708 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
709 UINTN Key;
710 EFI_GUID NameGuid;
711 EFI_FV_FILE_ATTRIBUTES Attributes;
712 VOID *SourceBuffer;
713 UINT32 AuthenticationStatus;
714
715 HandleBuffer = NULL;
716 Status = gBS->LocateHandleBuffer (
717 ByProtocol,
718 &gEfiFirmwareVolume2ProtocolGuid,
719 NULL,
720 &HandleCount,
721 &HandleBuffer
722 );
723 if (EFI_ERROR (Status)) {
724 return NULL;
725 }
726
727 for (Index = 0; Index < HandleCount; Index++) {
728 Status = gBS->HandleProtocol (
729 HandleBuffer[Index],
730 &gEfiFirmwareVolume2ProtocolGuid,
731 (VOID **)&Fv
732 );
733 if (EFI_ERROR (Status)) {
734 continue;
735 }
736
737 //
738 // Use Firmware Volume 2 Protocol to search for a file of type FileType
739 //
740 Key = 0;
741 Status = Fv->GetNextFile (Fv, &Key, &FileType, &NameGuid, &Attributes, SourceSize);
742 if (EFI_ERROR (Status)) {
743 continue;
744 }
745
746 //
747 // Use Firmware Volume 2 Protocol to read a section of type SectionType
748 //
749 SourceBuffer = NULL;
750 Status = Fv->ReadSection (Fv, &NameGuid, SectionType, 0, &SourceBuffer, SourceSize, &AuthenticationStatus);
751 if (!EFI_ERROR (Status)) {
752 FreePool (HandleBuffer);
753 return SourceBuffer;
754 }
755 }
756
757 FreePool(HandleBuffer);
758
759 return NULL;
760 }
761 /**
762 Get the fixed loadding address from image header assigned by build tool. This function only be called
763 when Loading module at Fixed address feature enabled.
764
765 @param ImageContext Pointer to the image context structure that describes the PE/COFF
766 image that needs to be examined by this function.
767 @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools .
768 @retval EFI_NOT_FOUND The image has no assigned fixed loadding address.
769 **/
770 EFI_STATUS
771 GetPeCoffImageFixLoadingAssignedAddress(
772 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
773 )
774 {
775 UINTN SectionHeaderOffset;
776 EFI_STATUS Status;
777 EFI_IMAGE_SECTION_HEADER SectionHeader;
778 EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
779 EFI_PHYSICAL_ADDRESS FixLoaddingAddress;
780 UINT16 Index;
781 UINTN Size;
782 UINT16 NumberOfSections;
783 EFI_PHYSICAL_ADDRESS SmramBase;
784 UINT64 SmmCodeSize;
785 UINT64 ValueInSectionHeader;
786 //
787 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
788 //
789 SmmCodeSize = EFI_PAGES_TO_SIZE (PcdGet32(PcdLoadFixAddressSmmCodePageNumber));
790
791 FixLoaddingAddress = 0;
792 Status = EFI_NOT_FOUND;
793 SmramBase = mCurrentSmramRange->CpuStart;
794 //
795 // Get PeHeader pointer
796 //
797 ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
798 SectionHeaderOffset = (UINTN)(
799 ImageContext->PeCoffHeaderOffset +
800 sizeof (UINT32) +
801 sizeof (EFI_IMAGE_FILE_HEADER) +
802 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
803 );
804 NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
805
806 //
807 // Get base address from the first section header that doesn't point to code section.
808 //
809 for (Index = 0; Index < NumberOfSections; Index++) {
810 //
811 // Read section header from file
812 //
813 Size = sizeof (EFI_IMAGE_SECTION_HEADER);
814 Status = ImageContext->ImageRead (
815 ImageContext->Handle,
816 SectionHeaderOffset,
817 &Size,
818 &SectionHeader
819 );
820 if (EFI_ERROR (Status)) {
821 return Status;
822 }
823
824 Status = EFI_NOT_FOUND;
825
826 if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
827 //
828 // Build tool saves the offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields in the
829 // first section header that doesn't point to code section in image header. And there is an assumption that when the
830 // feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers
831 // fields should NOT be Zero, or else, these 2 fileds should be set to Zero
832 //
833 ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
834 if (ValueInSectionHeader != 0) {
835 //
836 // Found first section header that doesn't point to code section in which uild tool saves the
837 // offset to SMRAM base as image base in PointerToRelocations & PointerToLineNumbers fields
838 //
839 FixLoaddingAddress = (EFI_PHYSICAL_ADDRESS)(SmramBase + (INT64)ValueInSectionHeader);
840
841 if (SmramBase + SmmCodeSize > FixLoaddingAddress && SmramBase <= FixLoaddingAddress) {
842 //
843 // The assigned address is valid. Return the specified loadding address
844 //
845 ImageContext->ImageAddress = FixLoaddingAddress;
846 Status = EFI_SUCCESS;
847 }
848 }
849 break;
850 }
851 SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
852 }
853 DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r \n", FixLoaddingAddress, Status));
854 return Status;
855 }
856 /**
857 Load the SMM Core image into SMRAM and executes the SMM Core from SMRAM.
858
859 @param[in] SmramRange Descriptor for the range of SMRAM to reload the
860 currently executing image.
861 @param[in] Context Context to pass into SMM Core
862
863 @return EFI_STATUS
864
865 **/
866 EFI_STATUS
867 ExecuteSmmCoreFromSmram (
868 IN EFI_SMRAM_DESCRIPTOR *SmramRange,
869 IN VOID *Context
870 )
871 {
872 EFI_STATUS Status;
873 VOID *SourceBuffer;
874 UINTN SourceSize;
875 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
876 UINTN PageCount;
877 EFI_PHYSICAL_ADDRESS DestinationBuffer;
878 EFI_IMAGE_ENTRY_POINT EntryPoint;
879
880 //
881 // Search all Firmware Volumes for a PE/COFF image in a file of type SMM_CORE
882 //
883 SourceBuffer = GetSectionInAnyFv (EFI_FV_FILETYPE_SMM_CORE, EFI_SECTION_PE32, &SourceSize);
884 if (SourceBuffer == NULL) {
885 return EFI_NOT_FOUND;
886 }
887
888 //
889 // Initilize ImageContext
890 //
891 ImageContext.Handle = SourceBuffer;
892 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
893
894 //
895 // Get information about the image being loaded
896 //
897 Status = PeCoffLoaderGetImageInfo (&ImageContext);
898 if (EFI_ERROR (Status)) {
899 return Status;
900 }
901 //
902 // if Loading module at Fixed Address feature is enabled, the SMM core driver will be loaded to
903 // the address assigned by build tool.
904 //
905 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
906 //
907 // Get the fixed loading address assigned by Build tool
908 //
909 Status = GetPeCoffImageFixLoadingAssignedAddress (&ImageContext);
910 if (!EFI_ERROR (Status)) {
911 //
912 // Since the memory range to load SMM CORE will be cut out in SMM core, so no need to allocate and free this range
913 //
914 PageCount = 0;
915 } else {
916 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED ERROR: Loading module at fixed address at address failed\n"));
917 //
918 // Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
919 // specified by SmramRange
920 //
921 PageCount = (UINTN)EFI_SIZE_TO_PAGES(ImageContext.ImageSize + ImageContext.SectionAlignment);
922
923 ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
924 ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
925
926 SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
927 DestinationBuffer = SmramRange->CpuStart + SmramRange->PhysicalSize;
928
929 //
930 // Align buffer on section boundry
931 //
932 ImageContext.ImageAddress = DestinationBuffer;
933 }
934 } else {
935 //
936 // Allocate memory for the image being loaded from the EFI_SRAM_DESCRIPTOR
937 // specified by SmramRange
938 //
939 PageCount = (UINTN)EFI_SIZE_TO_PAGES(ImageContext.ImageSize + ImageContext.SectionAlignment);
940
941 ASSERT ((SmramRange->PhysicalSize & EFI_PAGE_MASK) == 0);
942 ASSERT (SmramRange->PhysicalSize > EFI_PAGES_TO_SIZE (PageCount));
943
944 SmramRange->PhysicalSize -= EFI_PAGES_TO_SIZE (PageCount);
945 DestinationBuffer = SmramRange->CpuStart + SmramRange->PhysicalSize;
946
947 //
948 // Align buffer on section boundry
949 //
950 ImageContext.ImageAddress = DestinationBuffer;
951 }
952
953 ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
954 ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);
955
956 //
957 // Print debug message showing SMM Core load address.
958 //
959 DEBUG ((DEBUG_INFO, "SMM IPL loading SMM Core at SMRAM address %p\n", (VOID *)(UINTN)ImageContext.ImageAddress));
960
961 //
962 // Load the image to our new buffer
963 //
964 Status = PeCoffLoaderLoadImage (&ImageContext);
965 if (!EFI_ERROR (Status)) {
966 //
967 // Relocate the image in our new buffer
968 //
969 Status = PeCoffLoaderRelocateImage (&ImageContext);
970 if (!EFI_ERROR (Status)) {
971 //
972 // Flush the instruction cache so the image data are written before we execute it
973 //
974 InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
975
976 //
977 // Print debug message showing SMM Core entry point address.
978 //
979 DEBUG ((DEBUG_INFO, "SMM IPL calling SMM Core at SMRAM address %p\n", (VOID *)(UINTN)ImageContext.EntryPoint));
980
981 //
982 // Execute image
983 //
984 EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)ImageContext.EntryPoint;
985 Status = EntryPoint ((EFI_HANDLE)Context, gST);
986 }
987 }
988
989 //
990 // If the load operation, relocate operation, or the image execution return an
991 // error, then free memory allocated from the EFI_SRAM_DESCRIPTOR specified by
992 // SmramRange
993 //
994 if (EFI_ERROR (Status)) {
995 SmramRange->PhysicalSize += EFI_PAGES_TO_SIZE (PageCount);
996 }
997
998 //
999 // Always free memory allocted by GetFileBufferByFilePath ()
1000 //
1001 FreePool (SourceBuffer);
1002
1003 return Status;
1004 }
1005
1006 /**
1007 The Entry Point for SMM IPL
1008
1009 Load SMM Core into SMRAM, register SMM Core entry point for SMIs, install
1010 SMM Base 2 Protocol and SMM Communication Protocol, and register for the
1011 critical events required to coordinate between DXE and SMM environments.
1012
1013 @param ImageHandle The firmware allocated handle for the EFI image.
1014 @param SystemTable A pointer to the EFI System Table.
1015
1016 @retval EFI_SUCCESS The entry point is executed successfully.
1017 @retval Other Some error occurred when executing this entry point.
1018
1019 **/
1020 EFI_STATUS
1021 EFIAPI
1022 SmmIplEntry (
1023 IN EFI_HANDLE ImageHandle,
1024 IN EFI_SYSTEM_TABLE *SystemTable
1025 )
1026 {
1027 EFI_STATUS Status;
1028 EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration;
1029 UINTN Size;
1030 UINTN Index;
1031 EFI_SMM_RESERVED_SMRAM_REGION *SmramResRegion;
1032 UINT64 MaxSize;
1033 VOID *Registration;
1034 UINT64 SmmCodeSize;
1035 EFI_LOAD_FIXED_ADDRESS_CONFIGURATION_TABLE *LMFAConfigurationTable;
1036
1037 //
1038 // Fill in the image handle of the SMM IPL so the SMM Core can use this as the
1039 // ParentImageHandle field of the Load Image Protocol for all SMM Drivers loaded
1040 // by the SMM Core
1041 //
1042 mSmmCorePrivateData.SmmIplImageHandle = ImageHandle;
1043
1044 //
1045 // Get SMM Access Protocol
1046 //
1047 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&mSmmAccess);
1048 ASSERT_EFI_ERROR (Status);
1049
1050 //
1051 // Get SMM Control2 Protocol
1052 //
1053 Status = gBS->LocateProtocol (&gEfiSmmControl2ProtocolGuid, NULL, (VOID **)&mSmmControl2);
1054 ASSERT_EFI_ERROR (Status);
1055
1056 //
1057 // Get SMM Configuration Protocol if it is present
1058 //
1059 SmmConfiguration = NULL;
1060 Status = gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL, (VOID **) &SmmConfiguration);
1061
1062 //
1063 // Get SMRAM information
1064 //
1065 Size = 0;
1066 Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, NULL);
1067 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
1068
1069 gSmmCorePrivate->SmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size);
1070 ASSERT (gSmmCorePrivate->SmramRanges != NULL);
1071
1072 Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, gSmmCorePrivate->SmramRanges);
1073 ASSERT_EFI_ERROR (Status);
1074
1075 gSmmCorePrivate->SmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);
1076
1077 //
1078 // Open all SMRAM ranges
1079 //
1080 Status = mSmmAccess->Open (mSmmAccess);
1081 ASSERT_EFI_ERROR (Status);
1082
1083 //
1084 // Print debug message that the SMRAM window is now open.
1085 //
1086 DEBUG ((DEBUG_INFO, "SMM IPL opened SMRAM window\n"));
1087
1088 //
1089 // Subtract SMRAM any reserved SMRAM regions.
1090 //
1091 if (SmmConfiguration != NULL) {
1092 SmramResRegion = SmmConfiguration->SmramReservedRegions;
1093 while (SmramResRegion->SmramReservedSize != 0) {
1094 for (Index = 0; Index < gSmmCorePrivate->SmramRangeCount; Index ++) {
1095 if ((SmramResRegion->SmramReservedStart >= gSmmCorePrivate->SmramRanges[Index].CpuStart) && \
1096 ((SmramResRegion->SmramReservedStart + SmramResRegion->SmramReservedSize) <= \
1097 (gSmmCorePrivate->SmramRanges[Index].CpuStart + gSmmCorePrivate->SmramRanges[Index].PhysicalSize))) {
1098 //
1099 // This range has reserved area, calculate the left free size
1100 //
1101 gSmmCorePrivate->SmramRanges[Index].PhysicalSize = SmramResRegion->SmramReservedStart - gSmmCorePrivate->SmramRanges[Index].CpuStart;
1102 }
1103 }
1104 SmramResRegion++;
1105 }
1106 }
1107
1108 //
1109 // Find the largest SMRAM range between 1MB and 4GB that is at least 256KB - 4K in size
1110 //
1111 mCurrentSmramRange = NULL;
1112 for (Index = 0, MaxSize = SIZE_256KB - EFI_PAGE_SIZE; Index < gSmmCorePrivate->SmramRangeCount; Index++) {
1113 if (gSmmCorePrivate->SmramRanges[Index].CpuStart >= BASE_1MB) {
1114 if ((gSmmCorePrivate->SmramRanges[Index].CpuStart + gSmmCorePrivate->SmramRanges[Index].PhysicalSize) <= BASE_4GB) {
1115 if (gSmmCorePrivate->SmramRanges[Index].PhysicalSize >= MaxSize) {
1116 MaxSize = gSmmCorePrivate->SmramRanges[Index].PhysicalSize;
1117 mCurrentSmramRange = &gSmmCorePrivate->SmramRanges[Index];
1118 }
1119 }
1120 }
1121 }
1122
1123 if (mCurrentSmramRange != NULL) {
1124 //
1125 // Print debug message showing SMRAM window that will be used by SMM IPL and SMM Core
1126 //
1127 DEBUG ((DEBUG_INFO, "SMM IPL found SMRAM window %p - %p\n",
1128 (VOID *)(UINTN)mCurrentSmramRange->CpuStart,
1129 (VOID *)(UINTN)(mCurrentSmramRange->CpuStart + mCurrentSmramRange->PhysicalSize - 1)
1130 ));
1131
1132 GetSmramCacheRange (mCurrentSmramRange, &mSmramCacheBase, &mSmramCacheSize);
1133 //
1134 // Attempt to set SMRAM cacheability to WB
1135 //
1136 Status = gDS->SetMemorySpaceAttributes(
1137 mSmramCacheBase,
1138 mSmramCacheSize,
1139 EFI_MEMORY_WB
1140 );
1141 if (EFI_ERROR (Status)) {
1142 DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));
1143 }
1144 //
1145 // if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load
1146 // Modules At Fixed Address Configuration Table.
1147 //
1148 if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {
1149 //
1150 // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressSmmCodePageNumber
1151 //
1152 SmmCodeSize = LShiftU64 (PcdGet32(PcdLoadFixAddressSmmCodePageNumber), EFI_PAGE_SHIFT);
1153 //
1154 // The SMRAM available memory is assumed to be larger than SmmCodeSize
1155 //
1156 ASSERT (mCurrentSmramRange->PhysicalSize > SmmCodeSize);
1157 //
1158 // Retrieve Load modules At fixed address configuration table and save the SMRAM base.
1159 //
1160 Status = EfiGetSystemConfigurationTable (
1161 &gLoadFixedAddressConfigurationTableGuid,
1162 (VOID **) &LMFAConfigurationTable
1163 );
1164 if (!EFI_ERROR (Status) && LMFAConfigurationTable != NULL) {
1165 LMFAConfigurationTable->SmramBase = mCurrentSmramRange->CpuStart;
1166 //
1167 // Print the SMRAM base
1168 //
1169 DEBUG ((EFI_D_INFO, "LOADING MODULE FIXED INFO: TSEG BASE is %x. \n", LMFAConfigurationTable->SmramBase));
1170 }
1171 }
1172 //
1173 // Load SMM Core into SMRAM and execute it from SMRAM
1174 //
1175 Status = ExecuteSmmCoreFromSmram (mCurrentSmramRange, gSmmCorePrivate);
1176 if (EFI_ERROR (Status)) {
1177 //
1178 // Print error message that the SMM Core failed to be loaded and executed.
1179 //
1180 DEBUG ((DEBUG_ERROR, "SMM IPL could not load and execute SMM Core from SMRAM\n"));
1181
1182 //
1183 // Attempt to reset SMRAM cacheability to UC
1184 //
1185 Status = gDS->SetMemorySpaceAttributes(
1186 mSmramCacheBase,
1187 mSmramCacheSize,
1188 EFI_MEMORY_UC
1189 );
1190 if (EFI_ERROR (Status)) {
1191 DEBUG ((DEBUG_WARN, "SMM IPL failed to reset SMRAM window to EFI_MEMORY_UC\n"));
1192 }
1193 }
1194 } else {
1195 //
1196 // Print error message that there are not enough SMRAM resources to load the SMM Core.
1197 //
1198 DEBUG ((DEBUG_ERROR, "SMM IPL could not find a large enough SMRAM region to load SMM Core\n"));
1199 }
1200
1201 //
1202 // If the SMM Core could not be loaded then close SMRAM window, free allocated
1203 // resources, and return an error so SMM IPL will be unloaded.
1204 //
1205 if (mCurrentSmramRange == NULL || EFI_ERROR (Status)) {
1206 //
1207 // Close all SMRAM ranges
1208 //
1209 Status = mSmmAccess->Close (mSmmAccess);
1210 ASSERT_EFI_ERROR (Status);
1211
1212 //
1213 // Print debug message that the SMRAM window is now closed.
1214 //
1215 DEBUG ((DEBUG_INFO, "SMM IPL closed SMRAM window\n"));
1216
1217 //
1218 // Free all allocated resources
1219 //
1220 FreePool (gSmmCorePrivate->SmramRanges);
1221
1222 return EFI_UNSUPPORTED;
1223 }
1224
1225 //
1226 // Install SMM Base2 Protocol and SMM Communication Protocol
1227 //
1228 Status = gBS->InstallMultipleProtocolInterfaces (
1229 &mSmmIplHandle,
1230 &gEfiSmmBase2ProtocolGuid, &mSmmBase2,
1231 &gEfiSmmCommunicationProtocolGuid, &mSmmCommunication,
1232 NULL
1233 );
1234 ASSERT_EFI_ERROR (Status);
1235
1236 //
1237 // Create the set of protocol and event notififcations that the SMM IPL requires
1238 //
1239 for (Index = 0; mSmmIplEvents[Index].NotifyFunction != NULL; Index++) {
1240 if (mSmmIplEvents[Index].Protocol) {
1241 mSmmIplEvents[Index].Event = EfiCreateProtocolNotifyEvent (
1242 mSmmIplEvents[Index].Guid,
1243 TPL_CALLBACK,
1244 mSmmIplEvents[Index].NotifyFunction,
1245 mSmmIplEvents[Index].NotifyContext,
1246 &Registration
1247 );
1248 } else {
1249 Status = gBS->CreateEventEx (
1250 EVT_NOTIFY_SIGNAL,
1251 TPL_CALLBACK,
1252 mSmmIplEvents[Index].NotifyFunction,
1253 mSmmIplEvents[Index].NotifyContext,
1254 mSmmIplEvents[Index].Guid,
1255 &mSmmIplEvents[Index].Event
1256 );
1257 ASSERT_EFI_ERROR (Status);
1258 }
1259 }
1260
1261 return EFI_SUCCESS;
1262 }