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_MM_COMMUNICATE_HEADER_V3 *CommunicateHeader;
675 EFI_SMM_COMMUNICATE_HEADER *LegacyCommunicateHeader;
676 BOOLEAN InLegacyBoot;
677 BOOLEAN IsOverlapped;
678 VOID *CommunicationBuffer;
679 UINTN BufferSize;
680 EFI_GUID *CommGuid;
681 VOID *CommData;
682 UINTN CommHeaderSize;
683
685
686 //
687 // Update SMST with contents of the SmmEntryContext structure
688 //
689 gSmmCoreSmst.SmmStartupThisAp = SmmEntryContext->SmmStartupThisAp;
690 gSmmCoreSmst.CurrentlyExecutingCpu = SmmEntryContext->CurrentlyExecutingCpu;
691 gSmmCoreSmst.NumberOfCpus = SmmEntryContext->NumberOfCpus;
692 gSmmCoreSmst.CpuSaveStateSize = SmmEntryContext->CpuSaveStateSize;
693 gSmmCoreSmst.CpuSaveState = SmmEntryContext->CpuSaveState;
694
695 //
696 // Call platform hook before Smm Dispatch
697 //
698 PERF_START (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
700 PERF_END (NULL, "PlatformHookBeforeSmmDispatch", NULL, 0);
701
702 //
703 // Call memory management hook function
704 //
706
707 //
708 // If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
709 //
710 InLegacyBoot = mInLegacyBoot;
711 if (!InLegacyBoot) {
712 //
713 // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol
714 //
715 gSmmCorePrivate->InSmm = TRUE;
716
717 //
718 // Check to see if this is a Synchronous SMI sent through the SMM Communication
719 // Protocol or an Asynchronous SMI
720 //
721 CommunicationBuffer = gSmmCorePrivate->CommunicationBuffer;
722 BufferSize = gSmmCorePrivate->BufferSize;
723 if (CommunicationBuffer != NULL) {
724 //
725 // Synchronous SMI for SMM Core or request from Communicate protocol
726 //
728 (UINT8 *)CommunicationBuffer,
729 BufferSize,
730 (UINT8 *)gSmmCorePrivate,
731 sizeof (*gSmmCorePrivate)
732 );
733 //
734 // Check for over or underflows
735 //
736 if (!SmmIsBufferOutsideSmmValid ((UINTN)CommunicationBuffer, BufferSize) ||
737 IsOverlapped || (BufferSize < OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)))
738 {
739 //
740 // If CommunicationBuffer is not in valid address scope,
741 // or there is overlap between gSmmCorePrivate and CommunicationBuffer,
742 // or there is over or underflow,
743 // return EFI_INVALID_PARAMETER
744 //
745 gSmmCorePrivate->CommunicationBuffer = NULL;
746 gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
747 } else {
748 CommGuid = &((EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer)->HeaderGuid;
749 //
750 // Check if the signature matches EFI_MM_COMMUNICATE_HEADER_V3 definition
751 //
752 if (CompareGuid (CommGuid, &gEfiMmCommunicateHeaderV3Guid)) {
753 //
754 // If so, need to make sure the size is at least the size of the header
755 //
756 if (BufferSize < sizeof (EFI_MM_COMMUNICATE_HEADER_V3)) {
757 gSmmCorePrivate->CommunicationBuffer = NULL;
758 gSmmCorePrivate->ReturnStatus = EFI_ACCESS_DENIED;
759 goto AsyncSmi;
760 }
761
762 CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicationBuffer;
763 CommGuid = &CommunicateHeader->MessageGuid;
764 CommData = CommunicateHeader->MessageData;
765 CommHeaderSize = sizeof (EFI_MM_COMMUNICATE_HEADER_V3);
766 } else {
767 LegacyCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)CommunicationBuffer;
768 CommGuid = &LegacyCommunicateHeader->HeaderGuid;
769 CommData = LegacyCommunicateHeader->Data;
770 CommHeaderSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
771 }
772
773 BufferSize -= CommHeaderSize;
774 Status = SmiManage (
775 CommGuid,
776 NULL,
777 CommData,
778 &BufferSize
779 );
780 //
781 // Update CommunicationBuffer, BufferSize and ReturnStatus
782 // Communicate service finished, reset the pointer to CommBuffer to NULL
783 //
784 gSmmCorePrivate->BufferSize = BufferSize + CommHeaderSize;
785 gSmmCorePrivate->CommunicationBuffer = NULL;
786 gSmmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
787 }
788 }
789 }
790
791AsyncSmi:
792 //
793 // Process Asynchronous SMI sources
794 //
796
797 //
798 // Call platform hook after Smm Dispatch
799 //
800 PERF_START (NULL, "PlatformHookAfterSmmDispatch", NULL, 0);
802 PERF_END (NULL, "PlatformHookAfterSmmDispatch", NULL, 0);
803
804 //
805 // If a legacy boot has occurred, then make sure gSmmCorePrivate is not accessed
806 //
807 if (!InLegacyBoot) {
808 //
809 // Clear the InSmm flag as we are going to leave SMM
810 //
811 gSmmCorePrivate->InSmm = FALSE;
812 }
813
815}
816
820VOID
822 VOID
823 )
824{
825 EFI_STATUS Status;
826 EFI_HANDLE Handle;
827
828 //
829 // Allocate a Loaded Image Protocol in EfiBootServicesData
830 //
831 Status = gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_LOADED_IMAGE_PROTOCOL), (VOID **)&mSmmCoreLoadedImage);
832 ASSERT_EFI_ERROR (Status);
833
834 ZeroMem (mSmmCoreLoadedImage, sizeof (EFI_LOADED_IMAGE_PROTOCOL));
835 //
836 // Fill in the remaining fields of the Loaded Image Protocol instance.
837 // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed.
838 //
839 mSmmCoreLoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
840 mSmmCoreLoadedImage->ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
841 mSmmCoreLoadedImage->SystemTable = gST;
842
843 mSmmCoreLoadedImage->ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
844 mSmmCoreLoadedImage->ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
845 mSmmCoreLoadedImage->ImageCodeType = EfiRuntimeServicesCode;
846 mSmmCoreLoadedImage->ImageDataType = EfiRuntimeServicesData;
847
848 //
849 // Create a new image handle in the UEFI handle database for the SMM Driver
850 //
851 Handle = NULL;
852 Status = gBS->InstallMultipleProtocolInterfaces (
853 &Handle,
854 &gEfiLoadedImageProtocolGuid,
855 mSmmCoreLoadedImage,
856 NULL
857 );
858 ASSERT_EFI_ERROR (Status);
859
860 //
861 // Allocate a Loaded Image Protocol in SMM
862 //
863 Status = SmmAllocatePool (EfiRuntimeServicesData, sizeof (EFI_SMM_DRIVER_ENTRY), (VOID **)&mSmmCoreDriverEntry);
864 ASSERT_EFI_ERROR (Status);
865
866 ZeroMem (mSmmCoreDriverEntry, sizeof (EFI_SMM_DRIVER_ENTRY));
867 //
868 // Fill in the remaining fields of the Loaded Image Protocol instance.
869 //
870 mSmmCoreDriverEntry->Signature = EFI_SMM_DRIVER_ENTRY_SIGNATURE;
871 mSmmCoreDriverEntry->SmmLoadedImage.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
872 mSmmCoreDriverEntry->SmmLoadedImage.ParentHandle = gSmmCorePrivate->SmmIplImageHandle;
873 mSmmCoreDriverEntry->SmmLoadedImage.SystemTable = gST;
874
875 mSmmCoreDriverEntry->SmmLoadedImage.ImageBase = (VOID *)(UINTN)gSmmCorePrivate->PiSmmCoreImageBase;
876 mSmmCoreDriverEntry->SmmLoadedImage.ImageSize = gSmmCorePrivate->PiSmmCoreImageSize;
877 mSmmCoreDriverEntry->SmmLoadedImage.ImageCodeType = EfiRuntimeServicesCode;
878 mSmmCoreDriverEntry->SmmLoadedImage.ImageDataType = EfiRuntimeServicesData;
879
880 mSmmCoreDriverEntry->ImageEntryPoint = gSmmCorePrivate->PiSmmCoreEntryPoint;
881 mSmmCoreDriverEntry->ImageBuffer = gSmmCorePrivate->PiSmmCoreImageBase;
882 mSmmCoreDriverEntry->NumberOfPage = EFI_SIZE_TO_PAGES ((UINTN)gSmmCorePrivate->PiSmmCoreImageSize);
883
884 //
885 // Create a new image handle in the SMM handle database for the SMM Driver
886 //
887 mSmmCoreDriverEntry->SmmImageHandle = NULL;
889 &mSmmCoreDriverEntry->SmmImageHandle,
890 &gEfiLoadedImageProtocolGuid,
892 &mSmmCoreDriverEntry->SmmLoadedImage
893 );
894 ASSERT_EFI_ERROR (Status);
895
896 return;
897}
898
915EFIAPI
917 IN EFI_HANDLE ImageHandle,
918 IN EFI_SYSTEM_TABLE *SystemTable
919 )
920{
921 EFI_STATUS Status;
922 UINTN Index;
923
924 //
925 // Get SMM Core Private context passed in from SMM IPL in ImageHandle.
926 //
927 gSmmCorePrivate = (SMM_CORE_PRIVATE_DATA *)ImageHandle;
928
929 //
930 // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.
931 //
932 gSmmCorePrivate->Smst = &gSmmCoreSmst;
933 gSmmCorePrivate->SmmEntryPoint = SmmEntryPoint;
934
935 //
936 // No need to initialize memory service.
937 // It is done in constructor of PiSmmCoreMemoryAllocationLib(),
938 // so that the library linked with PiSmmCore can use AllocatePool() in constructor.
939 //
940
942
943 //
944 // Copy FullSmramRanges to SMRAM
945 //
946 mFullSmramRangeCount = gSmmCorePrivate->SmramRangeCount;
947 mFullSmramRanges = AllocatePool (mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
948 ASSERT (mFullSmramRanges != NULL);
949 CopyMem (mFullSmramRanges, gSmmCorePrivate->SmramRanges, mFullSmramRangeCount * sizeof (EFI_SMRAM_DESCRIPTOR));
950
951 //
952 // Register all SMI Handlers required by the SMM Core
953 //
954 for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {
955 Status = SmiHandlerRegister (
956 mSmmCoreSmiHandlers[Index].Handler,
957 mSmmCoreSmiHandlers[Index].HandlerType,
958 &mSmmCoreSmiHandlers[Index].DispatchHandle
959 );
960 ASSERT_EFI_ERROR (Status);
961 }
962
963 mAcpiS3Enable = PcdGetBool (PcdAcpiS3Enable);
964 if (mAcpiS3Enable) {
965 //
966 // Register all S3 related SMI Handlers required by the SMM Core
967 //
968 for (Index = 0; mSmmCoreS3SmiHandlers[Index].HandlerType != NULL; Index++) {
969 Status = SmiHandlerRegister (
970 mSmmCoreS3SmiHandlers[Index].Handler,
971 mSmmCoreS3SmiHandlers[Index].HandlerType,
972 &mSmmCoreS3SmiHandlers[Index].DispatchHandle
973 );
974 ASSERT_EFI_ERROR (Status);
975 }
976 }
977
980
982
984
986
987 return EFI_SUCCESS;
988}
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:1521
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:1279
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:938
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:727
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VOID
Definition: Base.h:269
#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:463
#define DEBUG_CODE_BEGIN()
Definition: DebugLib.h:565
#define DEBUG(Expression)
Definition: DebugLib.h:435
#define DEBUG_CODE_END()
Definition: DebugLib.h:579
#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:1221
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:821
EFI_STATUS EFIAPI SmmMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: PiSmmCore.c:916
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:449
EFI_STATUS EFIAPI SmmAllocatePool(IN EFI_MEMORY_TYPE PoolType, IN UINTN Size, OUT VOID **Buffer)
Definition: Pool.c:342
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
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:1203
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
Definition: Base.h:213
EFI_SMM_SYSTEM_TABLE2 * Smst
EFI_SMM_ENTRY_POINT SmmEntryPoint
EFI_SMRAM_DESCRIPTOR * SmramRanges