30BOOLEAN mSmmConfigurationTableInstalled =
FALSE;
31VOID *mSmmLockBoxRegistrationSmmEndOfDxe =
NULL;
32VOID *mSmmLockBoxRegistrationSmmReadyToLock =
NULL;
33VOID *mSmmLockBoxRegistrationEndOfS3Resume =
NULL;
34BOOLEAN mSmmLockBoxSmmReadyToLock =
FALSE;
35BOOLEAN mSmmLockBoxDuringS3Resume =
FALSE;
85 mSmmLockBoxSmmReadyToLock =
TRUE;
111 IN CONST VOID *Context OPTIONAL,
112 IN OUT VOID *CommBuffer OPTIONAL,
116 mSmmLockBoxDuringS3Resume =
TRUE;
145 Status = gMmst->MmLocateProtocol (
146 &gEfiMmSxDispatchProtocolGuid,
150 if (!EFI_ERROR (Status) && (SxDispatch !=
NULL)) {
155 EntryRegisterContext.Type = SxS3;
156 EntryRegisterContext.Phase = SxEntry;
157 Status = SxDispatch->Register (
160 &EntryRegisterContext,
186 mSmmLockBoxDuringS3Resume =
FALSE;
205 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SmmLockBoxMmConstructor - Enter\n"));
210 Status = gMmst->MmRegisterProtocolNotify (
211 &gEfiMmReadyToLockProtocolGuid,
213 &mSmmLockBoxRegistrationSmmReadyToLock
220 Status = gMmst->MmRegisterProtocolNotify (
221 &gEfiMmEndOfDxeProtocolGuid,
223 &mSmmLockBoxRegistrationSmmEndOfDxe
230 Status = gMmst->MmRegisterProtocolNotify (
231 &gEdkiiEndOfS3ResumeGuid,
233 &mSmmLockBoxRegistrationEndOfS3Resume
241 if (SmmLockBoxContext !=
NULL) {
246 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SmmLockBoxContext - already installed\n"));
247 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
254 if (
sizeof (
UINTN) ==
sizeof (UINT64)) {
262 Status = gMmst->MmInstallConfigurationTable (
264 &gEfiSmmLockBoxCommunicationGuid,
269 mSmmConfigurationTableInstalled =
TRUE;
272 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib LockBoxDataAddress - %x\n", (
UINTN)&mLockBoxQueue));
273 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
293 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SmmLockBoxMmDestructor in %a module\n", gEfiCallerBaseName));
295 if (mSmmConfigurationTableInstalled) {
296 Status = gMmst->MmInstallConfigurationTable (
298 &gEfiSmmLockBoxCommunicationGuid,
303 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib uninstall SmmLockBoxCommunication configuration table\n"));
306 if (mSmmLockBoxRegistrationSmmReadyToLock !=
NULL) {
310 Status = gMmst->MmRegisterProtocolNotify (
311 &gEfiMmReadyToLockProtocolGuid,
313 &mSmmLockBoxRegistrationSmmReadyToLock
318 if (mSmmLockBoxRegistrationSmmEndOfDxe !=
NULL) {
322 Status = gMmst->MmRegisterProtocolNotify (
323 &gEfiMmEndOfDxeProtocolGuid,
325 &mSmmLockBoxRegistrationSmmEndOfDxe
330 if (mSmmLockBoxRegistrationEndOfS3Resume !=
NULL) {
334 Status = gMmst->MmRegisterProtocolNotify (
335 &gEdkiiEndOfS3ResumeGuid,
337 &mSmmLockBoxRegistrationEndOfS3Resume
358 ASSERT (SmmLockBoxContext !=
NULL);
359 if (SmmLockBoxContext ==
NULL) {
383 ASSERT (LockBoxQueue !=
NULL);
385 for (Link = LockBoxQueue->ForwardLink;
386 Link != LockBoxQueue;
387 Link = Link->ForwardLink)
430 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SaveLockBox - Enter\n"));
435 if ((Guid ==
NULL) || (Buffer ==
NULL) || (Length == 0)) {
436 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));
437 return EFI_INVALID_PARAMETER;
444 if (LockBox !=
NULL) {
445 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_ALREADY_STARTED));
446 return EFI_ALREADY_STARTED;
452 Status = gMmst->MmAllocatePages (
459 if (EFI_ERROR (Status)) {
460 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
461 return EFI_OUT_OF_RESOURCES;
473 if (EFI_ERROR (Status)) {
475 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
476 return EFI_OUT_OF_RESOURCES;
487 LockBox->Signature = SMM_LOCK_BOX_DATA_SIGNATURE;
490 LockBox->Length = (UINT64)Length;
491 LockBox->Attributes = 0;
492 LockBox->SmramBuffer = SmramBuffer;
496 "LockBoxGuid - %g, SmramBuffer - 0x%lx, Length - 0x%lx\n",
498 LockBox->SmramBuffer,
503 ASSERT (LockBoxQueue !=
NULL);
509 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n",
EFI_SUCCESS));
535 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SetLockBoxAttributes - Enter\n"));
540 if ((Guid ==
NULL) ||
541 ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE | LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0))
543 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_INVALID_PARAMETER));
544 return EFI_INVALID_PARAMETER;
547 if (((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
548 ((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0))
550 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_INVALID_PARAMETER));
551 DEBUG ((DEBUG_INFO,
" LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE and LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY\n\n"));
552 DEBUG ((DEBUG_INFO,
" can not be set together\n"));
553 return EFI_INVALID_PARAMETER;
560 if (LockBox ==
NULL) {
561 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_NOT_FOUND));
562 return EFI_NOT_FOUND;
565 if ((((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
566 ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0)) ||
567 (((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
568 ((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0)))
570 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SetLockBoxAttributes 0x%lx 0x%lx - Exit (%r)\n", LockBox->Attributes, Attributes, EFI_INVALID_PARAMETER));
571 DEBUG ((DEBUG_INFO,
" LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE and LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY\n\n"));
572 DEBUG ((DEBUG_INFO,
" can not be set together\n"));
573 return EFI_INVALID_PARAMETER;
579 LockBox->Attributes = Attributes;
584 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n",
EFI_SUCCESS));
620 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Enter\n"));
625 if ((Guid ==
NULL) || (Buffer ==
NULL) || (Length == 0) ||
626 (Length > MAX_UINTN - Offset))
628 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));
629 return EFI_INVALID_PARAMETER;
636 if (LockBox ==
NULL) {
637 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_NOT_FOUND));
638 return EFI_NOT_FOUND;
644 if (LockBox->Length < Offset + Length) {
645 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0) {
652 "SmmLockBoxSmmLib UpdateLockBox - Origin LockBox too small, enlarge.\n"
663 "SmmLockBoxSmmLib UpdateLockBox - Allocate new buffer to enlarge.\n"
665 Status = gMmst->MmAllocatePages (
671 if (EFI_ERROR (Status)) {
672 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
673 return EFI_OUT_OF_RESOURCES;
684 LockBox->SmramBuffer = SmramBuffer;
690 if (Offset > LockBox->Length) {
692 (VOID *)((
UINTN)LockBox->SmramBuffer + (
UINTN)LockBox->Length),
693 Offset - (
UINTN)LockBox->Length
697 LockBox->Length = Offset + Length;
703 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_BUFFER_TOO_SMALL));
704 return EFI_BUFFER_TOO_SMALL;
709 CopyMem ((VOID *)((
UINTN)LockBox->SmramBuffer + Offset), Buffer, Length);
714 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n",
EFI_SUCCESS));
740 IN VOID *Buffer OPTIONAL,
747 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreLockBox - Enter\n"));
752 if ((Guid ==
NULL) ||
753 ((Buffer ==
NULL) && (Length !=
NULL)) ||
754 ((Buffer !=
NULL) && (Length ==
NULL)))
756 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));
757 return EFI_INVALID_PARAMETER;
764 if (LockBox ==
NULL) {
768 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_NOT_FOUND));
769 return EFI_NOT_FOUND;
772 if (((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0) &&
773 mSmmLockBoxSmmReadyToLock &&
774 !mSmmLockBoxDuringS3Resume)
780 return EFI_ACCESS_DENIED;
786 if (Buffer !=
NULL) {
790 RestoreBuffer = Buffer;
795 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) == 0) {
796 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_WRITE_PROTECTED));
797 return EFI_WRITE_PROTECTED;
800 RestoreBuffer = (VOID *)(
UINTN)LockBox->Buffer;
806 if (Length !=
NULL) {
807 if (*Length < (
UINTN)LockBox->Length) {
811 *Length = (
UINTN)LockBox->Length;
812 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_BUFFER_TOO_SMALL));
813 return EFI_BUFFER_TOO_SMALL;
816 *Length = (
UINTN)LockBox->Length;
822 CopyMem (RestoreBuffer, (VOID *)(
UINTN)LockBox->SmramBuffer, (
UINTN)LockBox->Length);
827 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n",
EFI_SUCCESS));
848 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Enter\n"));
851 ASSERT (LockBoxQueue !=
NULL);
856 for (Link = LockBoxQueue->ForwardLink;
857 Link != LockBoxQueue;
858 Link = Link->ForwardLink)
865 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) {
876 DEBUG ((DEBUG_INFO,
"SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Exit (%r)\n",
EFI_SUCCESS));
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define BASE_CR(Record, TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_STATUS EFIAPI SmmLockBoxSmmReadyToLockNotify(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
RETURN_STATUS EFIAPI SetLockBoxAttributes(IN GUID *Guid, IN UINT64 Attributes)
RETURN_STATUS EFIAPI RestoreLockBox(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
EFI_STATUS EFIAPI SmmLockBoxS3EntryCallBack(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
SMM_LOCK_BOX_CONTEXT mSmmLockBoxContext
RETURN_STATUS EFIAPI RestoreAllLockBoxInPlace(VOID)
EFI_STATUS SmmLockBoxMmConstructor(VOID)
SMM_LOCK_BOX_DATA * InternalFindLockBoxByGuid(IN EFI_GUID *Guid)
EFI_STATUS SmmLockBoxMmDestructor(VOID)
EFI_STATUS EFIAPI SmmLockBoxEndOfS3ResumeNotify(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
RETURN_STATUS EFIAPI UpdateLockBox(IN GUID *Guid, IN UINTN Offset, IN VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI SmmLockBoxSmmEndOfDxeNotify(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
RETURN_STATUS EFIAPI SaveLockBox(IN GUID *Guid, IN VOID *Buffer, IN UINTN Length)
SMM_LOCK_BOX_CONTEXT * InternalGetSmmLockBoxContext(VOID)
LIST_ENTRY * InternalGetLockBoxQueue(VOID)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_CONFIGURATION_TABLE * MmConfigurationTable
EFI_ALLOCATE_POOL MmAllocatePool
UINTN NumberOfTableEntries