TianoCore EDK2 master
Loading...
Searching...
No Matches
PiSmmCore.c
Go to the documentation of this file.
1
9#include "PiSmmCore.h"
10
11//
12// Physical pointer to private structure shared between SMM IPL and the SMM Core
13//
14SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;
15
16//
17// SMM Core global variable for SMM System Table. Only accessed as a physical structure in SMRAM.
18//
19EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst = {
20 {
21 SMM_SMST_SIGNATURE,
22 EFI_SMM_SYSTEM_TABLE2_REVISION,
23 sizeof (gSmmCoreSmst.Hdr)
24 },
25 NULL, // SmmFirmwareVendor
26 0, // SmmFirmwareRevision
28 {
29 {
30 (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5, // SmmMemRead
31 (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5 // SmmMemWrite
32 },
33 {
34 (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5, // SmmIoRead
35 (EFI_SMM_CPU_IO2)SmmEfiNotAvailableYetArg5 // SmmIoWrite
36 }
37 },
42 NULL, // SmmStartupThisAp
43 0, // CurrentlyExecutingCpu
44 0, // NumberOfCpus
45 NULL, // CpuSaveStateSize
46 NULL, // CpuSaveState
47 0, // NumberOfTableEntries
48 NULL, // SmmConfigurationTable
58};
59
60//
61// Flag to determine if the platform has performed a legacy boot.
62// If this flag is TRUE, then the runtime code and runtime data associated with the
63// SMM IPL are converted to free memory, so the SMM Core must guarantee that is
64// does not touch of the code/data associated with the SMM IPL if this flag is TRUE.
65//
66BOOLEAN mInLegacyBoot = FALSE;
67
68//
69// Flag to determine if it is during S3 resume.
70// It will be set in S3 entry callback and cleared at EndOfS3Resume.
71//
72BOOLEAN mDuringS3Resume = FALSE;
73
74//
75// Flag to determine if platform enabled S3.
76// Get the value from PcdAcpiS3Enable.
77//
78BOOLEAN mAcpiS3Enable = FALSE;
79
80//
81// Table of SMI Handlers that are registered by the SMM Core when it is initialized
82//
83SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] = {
84 { SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },
85 { SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, TRUE },
86 { SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },
87 { SmmExitBootServicesHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE },
88 { SmmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE },
89 { SmmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, TRUE },
90 { NULL, NULL, NULL, FALSE }
91};
92
93//
94// Table of SMI Handlers that are registered by the SMM Core when it is initialized
95//
96SMM_CORE_SMI_HANDLERS mSmmCoreS3SmiHandlers[] = {
97 { SmmS3SmmInitDoneHandler, &gEdkiiS3SmmInitDoneGuid, NULL, FALSE },
98 { SmmEndOfS3ResumeHandler, &gEdkiiEndOfS3ResumeGuid, NULL, FALSE },
99 { NULL, NULL, NULL, FALSE }
100};
101
102UINTN mFullSmramRangeCount;
103EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
104
105EFI_SMM_DRIVER_ENTRY *mSmmCoreDriverEntry;
106
107EFI_LOADED_IMAGE_PROTOCOL *mSmmCoreLoadedImage;
108
124EFIAPI
126 UINTN Arg1,
127 UINTN Arg2,
128 UINTN Arg3,
129 UINTN Arg4,
130 UINTN Arg5
131 )
132{
133 //
134 // This function should never be executed. If it does, then the architectural protocols
135 // have not been designed correctly.
136 //
138}
139
158EFIAPI
160 IN EFI_HANDLE DispatchHandle,
161 IN CONST VOID *Context OPTIONAL,
162 IN OUT VOID *CommBuffer OPTIONAL,
163 IN OUT UINTN *CommBufferSize OPTIONAL
164 )
165{
166 EFI_STATUS Status;
167 EFI_HANDLE SmmHandle;
168 UINTN Index;
169
170 //
171 // Install SMM Legacy Boot protocol.
172 //
173 SmmHandle = NULL;
175 &SmmHandle,
176 &gEdkiiSmmLegacyBootProtocolGuid,
178 NULL
179 );
180
181 mInLegacyBoot = TRUE;
182
183 SmiHandlerUnRegister (DispatchHandle);
184
185 //
186 // It is legacy boot, unregister ExitBootService SMI handler.
187 //
188 for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
189 if (CompareGuid (mSmmCoreSmiHandlers[Index].HandlerType, &gEfiEventExitBootServicesGuid)) {
190 SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);
191 break;
192 }
193 }
194
195 return Status;
196}
197
213EFIAPI
215 IN EFI_HANDLE DispatchHandle,
216 IN CONST VOID *Context OPTIONAL,
217 IN OUT VOID *CommBuffer OPTIONAL,
218 IN OUT UINTN *CommBufferSize OPTIONAL
219 )
220{
221 EFI_STATUS Status;
222 EFI_HANDLE SmmHandle;
223 UINTN Index;
224
225 //
226 // Install SMM Exit Boot Services protocol.
227 //
228 SmmHandle = NULL;
230 &SmmHandle,
231 &gEdkiiSmmExitBootServicesProtocolGuid,
233 NULL
234 );
235
236 SmiHandlerUnRegister (DispatchHandle);
237
238 //
239 // It is UEFI boot, unregister LegacyBoot SMI handler.
240 //
241 for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
242 if (CompareGuid (mSmmCoreSmiHandlers[Index].HandlerType, &gEfiEventLegacyBootGuid)) {
243 SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);
244 break;
245 }
246 }
247
248 return Status;
249}
250
270EFIAPI
272 IN EFI_HANDLE DispatchHandle,
273 IN CONST VOID *Context OPTIONAL,
274 IN OUT VOID *CommBuffer OPTIONAL,
275 IN OUT UINTN *CommBufferSize OPTIONAL
276 )
277{
278 mDuringS3Resume = TRUE;
279 return EFI_SUCCESS;
280}
281
297EFIAPI
299 IN EFI_HANDLE DispatchHandle,
300 IN CONST VOID *Context OPTIONAL,
301 IN OUT VOID *CommBuffer OPTIONAL,
302 IN OUT UINTN *CommBufferSize OPTIONAL
303 )
304{
305 EFI_STATUS Status;
306 EFI_HANDLE SmmHandle;
307
308 PERF_CALLBACK_BEGIN (&gEfiEventReadyToBootGuid);
309
310 //
311 // Install SMM Ready To Boot protocol.
312 //
313 SmmHandle = NULL;
315 &SmmHandle,
316 &gEdkiiSmmReadyToBootProtocolGuid,
318 NULL
319 );
320
321 SmiHandlerUnRegister (DispatchHandle);
322
323 PERF_CALLBACK_END (&gEfiEventReadyToBootGuid);
324 return Status;
325}
326
345EFIAPI
347 IN EFI_HANDLE DispatchHandle,
348 IN CONST VOID *Context OPTIONAL,
349 IN OUT VOID *CommBuffer OPTIONAL,
350 IN OUT UINTN *CommBufferSize OPTIONAL
351 )
352{
353 EFI_STATUS Status;
354 UINTN Index;
355 EFI_HANDLE SmmHandle;
356 VOID *Interface;
357
358 PERF_CALLBACK_BEGIN (&gEfiDxeSmmReadyToLockProtocolGuid);
359
360 //
361 // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped
362 //
363 for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
364 if (mSmmCoreSmiHandlers[Index].UnRegister) {
365 SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);
366 }
367 }
368
369 //
370 // Install SMM Ready to lock protocol
371 //
372 SmmHandle = NULL;
374 &SmmHandle,
375 &gEfiSmmReadyToLockProtocolGuid,
377 NULL
378 );
379
380 //
381 // Make sure SMM CPU I/O 2 Protocol has been installed into the handle database
382 //
383 Status = SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid, NULL, &Interface);
384
385 //
386 // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed
387 //
389 if (EFI_ERROR (Status)) {
390 DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));
391 }
392
394
395 //
396 // Assert if the CPU I/O 2 Protocol is not installed
397 //
398 ASSERT_EFI_ERROR (Status);
399
400 //
401 // Display any drivers that were not dispatched because dependency expression
402 // evaluated to false if this is a debug build
403 //
407
408 //
409 // Not allowed to use gST or gBS after lock
410 //
411 gST = NULL;
412 gBS = NULL;
413
415
416 PERF_CALLBACK_END (&gEfiDxeSmmReadyToLockProtocolGuid);
417 return Status;
418}
419
435EFIAPI
437 IN EFI_HANDLE DispatchHandle,
438 IN CONST VOID *Context OPTIONAL,
439 IN OUT VOID *CommBuffer OPTIONAL,
440 IN OUT UINTN *CommBufferSize OPTIONAL
441 )
442{
443 EFI_STATUS Status;
444 EFI_HANDLE SmmHandle;
446 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
447 EFI_HANDLE S3EntryHandle;
448
449 DEBUG ((DEBUG_INFO, "SmmEndOfDxeHandler\n"));
450
451 PERF_CALLBACK_BEGIN (&gEfiEndOfDxeEventGroupGuid);
452
453 //
454 // Install SMM EndOfDxe protocol
455 //
456 SmmHandle = NULL;
458 &SmmHandle,
459 &gEfiSmmEndOfDxeProtocolGuid,
461 NULL
462 );
463
464 if (mAcpiS3Enable) {
465 //
466 // Locate SmmSxDispatch2 protocol.
467 //
468 Status = SmmLocateProtocol (
469 &gEfiSmmSxDispatch2ProtocolGuid,
470 NULL,
471 (VOID **)&SxDispatch
472 );
473 if (!EFI_ERROR (Status) && (SxDispatch != NULL)) {
474 //
475 // Register a S3 entry callback function to
476 // determine if it will be during S3 resume.
477 //
478 EntryRegisterContext.Type = SxS3;
479 EntryRegisterContext.Phase = SxEntry;
480 Status = SxDispatch->Register (
481 SxDispatch,
483 &EntryRegisterContext,
484 &S3EntryHandle
485 );
486 ASSERT_EFI_ERROR (Status);
487 }
488 }
489
490 PERF_CALLBACK_END (&gEfiEndOfDxeEventGroupGuid);
491 return EFI_SUCCESS;
492}
493
509EFIAPI
511 IN EFI_HANDLE DispatchHandle,
512 IN CONST VOID *Context OPTIONAL,
513 IN OUT VOID *CommBuffer OPTIONAL,
514 IN OUT UINTN *CommBufferSize OPTIONAL
515 )
516{
517 EFI_STATUS Status;
518 EFI_HANDLE SmmHandle;
519
520 DEBUG ((DEBUG_INFO, "SmmS3SmmInitDoneHandler\n"));
521
522 if (!mDuringS3Resume) {
523 DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
524 return EFI_SUCCESS;
525 }
526
527 //
528 // Install SMM S3SmmInitDone protocol
529 //
530 SmmHandle = NULL;
532 &SmmHandle,
533 &gEdkiiS3SmmInitDoneGuid,
535 NULL
536 );
537 ASSERT_EFI_ERROR (Status);
538
539 //
540 // Uninstall the protocol here because the comsumer just hook the
541 // installation event.
542 //
544 SmmHandle,
545 &gEdkiiS3SmmInitDoneGuid,
546 NULL
547 );
548 ASSERT_EFI_ERROR (Status);
549
550 return Status;
551}
552
568EFIAPI
570 IN EFI_HANDLE DispatchHandle,
571 IN CONST VOID *Context OPTIONAL,
572 IN OUT VOID *CommBuffer OPTIONAL,
573 IN OUT UINTN *CommBufferSize OPTIONAL
574 )
575{
576 EFI_STATUS Status;
577 EFI_HANDLE SmmHandle;
578
579 DEBUG ((DEBUG_INFO, "SmmEndOfS3ResumeHandler\n"));
580
581 if (!mDuringS3Resume) {
582 DEBUG ((DEBUG_ERROR, "It is not during S3 resume\n"));
583 return EFI_SUCCESS;
584 }
585
586 //
587 // Install SMM EndOfS3Resume protocol
588 //
589 SmmHandle = NULL;
591 &SmmHandle,
592 &gEdkiiEndOfS3ResumeGuid,
594 NULL
595 );
596 ASSERT_EFI_ERROR (Status);
597
598 //
599 // Uninstall the protocol here because the consumer just hook the
600 // installation event.
601 //
603 SmmHandle,
604 &gEdkiiEndOfS3ResumeGuid,
605 NULL
606 );
607 ASSERT_EFI_ERROR (Status);
608
609 mDuringS3Resume = FALSE;
610 return Status;
611}
612
626BOOLEAN
628 IN UINT8 *Buff1,
629 IN UINTN Size1,
630 IN UINT8 *Buff2,
631 IN UINTN Size2
632 )
633{
634 UINTN End1;
635 UINTN End2;
636 BOOLEAN IsOverUnderflow1;
637 BOOLEAN IsOverUnderflow2;
638
639 // Check for over or underflow
640 IsOverUnderflow1 = EFI_ERROR (SafeUintnAdd ((UINTN)Buff1, Size1, &End1));
641 IsOverUnderflow2 = EFI_ERROR (SafeUintnAdd ((UINTN)Buff2, Size2, &End2));
642
643 if (IsOverUnderflow1 || IsOverUnderflow2) {
644 return TRUE;
645 }
646
647 //
648 // If buff1's end is less than the start of buff2, then it's ok.
649 // Also, if buff1's start is beyond buff2's end, then it's ok.
650 //
651 if ((End1 <= (UINTN)Buff2) || ((UINTN)Buff1 >= End2)) {
652 return FALSE;
653 }
654
655 return TRUE;
656}
657
667VOID
668EFIAPI
670 IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext
671 )
672{
673 EFI_STATUS Status;
674 EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;
675 BOOLEAN InLegacyBoot;
676 BOOLEAN IsOverlapped;
677 BOOLEAN IsOverUnderflow;
678 VOID *CommunicationBuffer;
679 UINTN BufferSize;
680
682
683 //
684 // Update SMST with contents of the SmmEntryContext structure
685 //
686 gSmmCoreSmst.SmmStartupThisAp = SmmEntryContext->SmmStartupThisAp;
687 gSmmCoreSmst.CurrentlyExecutingCpu = SmmEntryContext->CurrentlyExecutingCpu;
688 gSmmCoreSmst.NumberOfCpus = SmmEntryContext->NumberOfCpus;
689 gSmmCoreSmst.CpuSaveStateSize = SmmEntryContext->CpuSaveStateSize;
690 gSmmCoreSmst.CpuSaveState = SmmEntryContext->CpuSaveState;
691
692 //
693 // Call platform hook before Smm Dispatch
694 //
695 PERF_START (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
697 PERF_END (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
698
699 //
700 // Call memory management hook function
701 //
703
704 //
705 // If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
706 //
707 InLegacyBoot = mInLegacyBoot;
708 if (!InLegacyBoot) {
709 //
710 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
711 //
712 gSmmCorePrivate->InSmm = TRUE;
713
714 //
715 // Check to see if this is a Synchronous SMI sent through the SMM Communication
716 // Protocol or an Asynchronous SMI
717 //
718 CommunicationBuffer = gSmmCorePrivate->CommunicationBuffer;
719 BufferSize = gSmmCorePrivate->BufferSize;
720 if (CommunicationBuffer != NULL) {
721 //
722 // Synchronous SMI for SMM Core or request from Communicate protocol
723 //
725 (UINT8 *)CommunicationBuffer,
726 BufferSize,
727 (UINT8 *)gSmmCorePrivate,
728 sizeof (*gSmmCorePrivate)
729 );
730 //
731 // Check for over or underflows
732 //
733 IsOverUnderflow = EFI_ERROR (SafeUintnSub (BufferSize, OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data), &BufferSize));
734
735 if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) ||
736 IsOverlapped || IsOverUnderflow)
737 {
738 //
739 // If CommunicationBuffer is not in valid address scope,
740 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
741 // or there is over or underflow,
742 // return EFI_INVALID_PARAMETER
743 //
744 gSmmCorePrivate->CommunicationBuffer = NULL;
745 gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
746 } else {
747 CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
748 // BufferSize was updated by the SafeUintnSub() call above.
749 Status = SmiManage (
750 &CommunicateHeader->HeaderGuid,
751 NULL,
752 CommunicateHeader->Data,
753 &BufferSize
754 );
755 //
756 // Update CommunicationBuffer, BufferSize and ReturnStatus
757 // Communicate service finished, reset the pointer to CommBuffer to NULL
758 //
759 gSmmCorePrivate->BufferSize = BufferSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
760 gSmmCorePrivate->CommunicationBuffer = NULL;
761 gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
762 }
763 }
764 }
765
766 //
767 // Process Asynchronous SMI sources
768 //
770
771 //
772 // Call platform hook after Smm Dispatch
773 //
774 PERF_START (NULL, "PlatformHookAfterSmmDispatch", NULL, 0);
776 PERF_END (NULL, "PlatformHookAfterSmmDispatch", NULL, 0);
777
778 //
779 // If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
780 //
781 if (!InLegacyBoot) {
782 //
783 // Clear the InSmm flag as we are going to leave SMM
784 //
785 gSmmCorePrivate->InSmm = FALSE;
786 }
787
789}
790
794VOID
796 VOID
797 )
798{
799 EFI_STATUS Status;
800 EFI_HANDLE Handle;
801
802 //
803 // Allocate a Loaded Image Protocol in EfiBootServicesData
804 //
805 Status = gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);
806 ASSERT_EFI_ERROR (Status);
807
808 ZeroMem (mSmmCoreLoadedImage, sizeof (EFI_LOADED_IMAGE_PROTOCOL));
809 //
810 // Fill in the remaining fields of the Loaded Image Protocol instance.
811 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
812 //
813 mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
814 mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
815 mSmmCoreLoadedImage->SystemTable = gST;
816
817 mSmmCoreLoadedImage->ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
818 mSmmCoreLoadedImage->ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
819 mSmmCoreLoadedImage->ImageCodeType = EfiRuntimeServicesCode;
820 mSmmCoreLoadedImage->ImageDataType = EfiRuntimeServicesData;
821
822 //
823 // Create a new image handle in the UEFI handle database for the SMM Driver
824 //
825 Handle = NULL;
826 Status = gBS->InstallMultipleProtocolInterfaces (
827 &Handle,
828 &gEfiLoadedImageProtocolGuid,
829 mSmmCoreLoadedImage,
830 NULL
831 );
832 ASSERT_EFI_ERROR (Status);
833
834 //
835 // Allocate a Loaded Image Protocol in SMM
836 //
837 Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof (EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry);
838 ASSERT_EFI_ERROR (Status);
839
840 ZeroMem (mSmmCoreDriverEntry, sizeof (EFI_SMM_DRIVER_ENTRY));
841 //
842 // Fill in the remaining fields of the Loaded Image Protocol instance.
843 //
844 mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
845 mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
846 mSmmCoreDriverEntry->SmmLoadedImage.ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
847 mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST;
848
849 mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
850 mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
851 mSmmCoreDriverEntry->SmmLoadedImage.ImageCodeType = EfiRuntimeServicesCode;
852 mSmmCoreDriverEntry->SmmLoadedImage.ImageDataType = EfiRuntimeServicesData;
853
854 mSmmCoreDriverEntry->ImageEntryPoint = gSmmCorePrivate->PiSmmCoreEntryPoint;
855 mSmmCoreDriverEntry->ImageBuffer = gSmmCorePrivate->PiSmmCoreImageBase;
856 mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)gSmmCorePrivate->PiSmmCoreImageSize);
857
858 //
859 // Create a new image handle in the SMM handle database for the SMM Driver
860 //
861 mSmmCoreDriverEntry->SmmImageHandle = NULL;
863 &mSmmCoreDriverEntry->SmmImageHandle,
864 &gEfiLoadedImageProtocolGuid,
866 &mSmmCoreDriverEntry->SmmLoadedImage
867 );
868 ASSERT_EFI_ERROR (Status);
869
870 return;
871}
872
889EFIAPI
891 IN EFI_HANDLE ImageHandle,
892 IN EFI_SYSTEM_TABLE *SystemTable
893 )
894{
895 EFI_STATUS Status;
896 UINTN Index;
897
898 //
899 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
900 //
901 gSmmCorePrivate = (SMM_CORE_PRIVATE_DATA *)ImageHandle;
902
903 //
904 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
905 //
906 gSmmCorePrivate->Smst = &gSmmCoreSmst;
907 gSmmCorePrivate->SmmEntryPoint = SmmEntryPoint;
908
909 //
910 // No need to initialize memory service.
911 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
912 // so that the library linked with PiSmmCore can use AllocatePool() in constructor.
913 //
914
916
917 //
918 // Copy FullSmramRanges to SMRAM
919 //
920 mFullSmramRangeCount = gSmmCorePrivate->SmramRangeCount;
921 mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
922 ASSERT (mFullSmramRanges != NULL);
923 CopyMem (mFullSmramRanges, gSmmCorePrivate->SmramRanges, mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
924
925 //
926 // Register all SMI Handlers required by the SMM Core
927 //
928 for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
929 Status = SmiHandlerRegister (
930 mSmmCoreSmiHandlers[Index].Handler,
931 mSmmCoreSmiHandlers[Index].HandlerType,
932 &mSmmCoreSmiHandlers[Index].DispatchHandle
933 );
934 ASSERT_EFI_ERROR (Status);
935 }
936
937 mAcpiS3Enable = PcdGetBool (PcdAcpiS3Enable);
938 if (mAcpiS3Enable) {
939 //
940 // Register all S3 related SMI Handlers required by the SMM Core
941 //
942 for (Index = 0; mSmmCoreS3SmiHandlers[Index].HandlerType != NULL; Index++) {
943 Status = SmiHandlerRegister (
944 mSmmCoreS3SmiHandlers[Index].Handler,
945 mSmmCoreS3SmiHandlers[Index].HandlerType,
946 &mSmmCoreS3SmiHandlers[Index].DispatchHandle
947 );
948 ASSERT_EFI_ERROR (Status);
949 }
950 }
951
954
956
958
960
961 return EFI_SUCCESS;
962}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN IsOverlapped(UINT8 *Buff1, UINTN Size1, UINT8 *Buff2, UINTN Size2)
#define EFI_LOADED_IMAGE_PROTOCOL_REVISION
Definition: LoadedImage.h:33
VOID SmmDisplayDiscoveredNotDispatched(VOID)
Definition: Dispatcher.c:1526
EFI_STATUS EFIAPI SmmDriverDispatchHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: Dispatcher.c:1284
EFI_STATUS EFIAPI SmmUninstallProtocolInterface(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, IN VOID *Interface)
Definition: Handle.c:366
EFI_STATUS EFIAPI SmmHandleProtocol(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, OUT VOID **Interface)
Definition: Handle.c:491
EFI_STATUS EFIAPI SmmInstallProtocolInterface(IN OUT EFI_HANDLE *UserHandle, IN EFI_GUID *Protocol, IN EFI_INTERFACE_TYPE InterfaceType, IN VOID *Interface)
Definition: Handle.c:174
EFI_STATUS EFIAPI SmmInstallConfigurationTable(IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable, IN CONST EFI_GUID *Guid, IN VOID *Table, IN UINTN TableSize)
EFI_STATUS EFIAPI SmmLocateProtocol(IN EFI_GUID *Protocol, IN VOID *Registration OPTIONAL, OUT VOID **Interface)
Definition: Locate.c:194
EFI_STATUS EFIAPI SmmLocateHandle(IN EFI_LOCATE_SEARCH_TYPE SearchType, IN EFI_GUID *Protocol OPTIONAL, IN VOID *SearchKey OPTIONAL, IN OUT UINTN *BufferSize, OUT EFI_HANDLE *Buffer)
Definition: Locate.c:271
VOID EFIAPI SmmCoreInitializeMemoryAttributesTable(VOID)
EFI_STATUS EFIAPI SmmRegisterProtocolNotify(IN CONST EFI_GUID *Protocol, IN EFI_SMM_NOTIFY_FN Function, OUT VOID **Registration)
Definition: Notify.c:96
EFI_STATUS EFIAPI SmmFreePages(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
Definition: Page.c:934
EFI_STATUS EFIAPI SmmAllocatePages(IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory)
Definition: Page.c:723
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG_CODE_BEGIN()
Definition: DebugLib.h:564
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define DEBUG_CODE_END()
Definition: DebugLib.h:578
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
#define PERF_FUNCTION_END()
#define PERF_CALLBACK_END(TriggerGuid)
#define PERF_END(Handle, Token, Module, TimeStamp)
#define PERF_FUNCTION_BEGIN()
#define PERF_START(Handle, Token, Module, TimeStamp)
#define PERF_CALLBACK_BEGIN(TriggerGuid)
#define EFI_NOT_AVAILABLE_YET
Definition: PiMultiPhase.h:54
VOID SmmEntryPointMemoryManagementHook(VOID)
Definition: HeapGuard.c:1218
EFI_STATUS EFIAPI SmmS3SmmInitDoneHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:510
VOID EFIAPI SmmEntryPoint(IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext)
Definition: PiSmmCore.c:669
EFI_STATUS EFIAPI SmmS3EntryCallBack(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:271
EFI_STATUS EFIAPI SmmEndOfS3ResumeHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:569
EFI_STATUS EFIAPI SmmReadyToLockHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:346
BOOLEAN InternalIsBufferOverlapped(IN UINT8 *Buff1, IN UINTN Size1, IN UINT8 *Buff2, IN UINTN Size2)
Definition: PiSmmCore.c:627
EFI_STATUS EFIAPI SmmEfiNotAvailableYetArg5(UINTN Arg1, UINTN Arg2, UINTN Arg3, UINTN Arg4, UINTN Arg5)
Definition: PiSmmCore.c:125
VOID SmmCoreInstallLoadedImage(VOID)
Definition: PiSmmCore.c:795
EFI_STATUS EFIAPI SmmMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: PiSmmCore.c:890
EFI_STATUS EFIAPI SmmEndOfDxeHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:436
EFI_STATUS EFIAPI SmmExitBootServicesHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:214
EFI_STATUS EFIAPI SmmReadyToBootHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:298
EFI_STATUS EFIAPI SmmLegacyBootHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: PiSmmCore.c:159
VOID SmramProfileReadyToLock(VOID)
EFI_STATUS EFIAPI SmiManage(IN CONST EFI_GUID *HandlerType, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
Definition: Smi.c:137
VOID SmramProfileInstallProtocol(VOID)
VOID SmmCoreInitializeSmiHandlerProfile(VOID)
EFI_STATUS EFIAPI SmiHandlerUnRegister(IN EFI_HANDLE DispatchHandle)
Definition: Smi.c:394
EFI_STATUS EFIAPI SmmFreePool(IN VOID *Buffer)
Definition: Pool.c:445
EFI_STATUS EFIAPI SmmAllocatePool(IN EFI_MEMORY_TYPE PoolType, IN UINTN Size, OUT VOID **Buffer)
Definition: Pool.c:338
VOID RegisterSmramProfileHandler(VOID)
VOID SmramProfileInit(VOID)
EFI_STATUS EFIAPI SmiHandlerRegister(IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, IN CONST EFI_GUID *HandlerType OPTIONAL, OUT EFI_HANDLE *DispatchHandle)
Definition: Smi.c:334
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFIAPI SafeUintnAdd(IN UINTN Augend, IN UINTN Addend, OUT UINTN *Result)
Definition: SafeIntLib32.c:338
RETURN_STATUS EFIAPI SafeUintnSub(IN UINTN Minuend, IN UINTN Subtrahend, OUT UINTN *Result)
Definition: SafeIntLib32.c:384
EFI_STATUS EFIAPI PlatformHookBeforeSmmDispatch(VOID)
EFI_STATUS EFIAPI PlatformHookAfterSmmDispatch(VOID)
BOOLEAN EFIAPI SmmIsBufferOutsideSmmValid(IN EFI_PHYSICAL_ADDRESS Buffer, IN UINT64 Length)
Definition: SmmMemLib.c:114
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
@ EfiBootServicesData
@ EfiRuntimeServicesCode
@ EfiRuntimeServicesData
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
EFI_SMM_STARTUP_THIS_AP SmmStartupThisAp
Definition: PiSmmCis.h:140
UINTN * CpuSaveStateSize
Definition: PiSmmCis.h:160
EFI_TABLE_HEADER Hdr
Definition: PiSmmCis.h:111
EFI_MEMORY_TYPE ImageDataType
The memory type that the data sections were loaded as.
Definition: LoadedImage.h:70
EFI_MEMORY_TYPE ImageCodeType
The memory type that the code sections were loaded as.
Definition: LoadedImage.h:69
UINT64 ImageSize
The size in bytes of the loaded image.
Definition: LoadedImage.h:68
EFI_SYSTEM_TABLE * SystemTable
the image's EFI system table pointer.
Definition: LoadedImage.h:48
VOID * ImageBase
The base address at which the image was loaded.
Definition: LoadedImage.h:67
EFI_SMM_SYSTEM_TABLE2 * Smst
EFI_SMM_ENTRY_POINT SmmEntryPoint
EFI_SMRAM_DESCRIPTOR * SmramRanges