TianoCore EDK2 master
Loading...
Searching...
No Matches
SmmLockBoxMmLib.c
Go to the documentation of this file.
1
9#include <PiMm.h>
11#include <Library/BaseLib.h>
13#include <Library/LockBoxLib.h>
14#include <Library/DebugLib.h>
15#include <Guid/SmmLockBox.h>
16#include <Guid/EndOfS3Resume.h>
18#include <Protocol/MmEndOfDxe.h>
20
22
28LIST_ENTRY mLockBoxQueue = INITIALIZE_LIST_HEAD_VARIABLE (mLockBoxQueue);
29
30BOOLEAN mSmmConfigurationTableInstalled = FALSE;
31VOID *mSmmLockBoxRegistrationSmmEndOfDxe = NULL;
32VOID *mSmmLockBoxRegistrationSmmReadyToLock = NULL;
33VOID *mSmmLockBoxRegistrationEndOfS3Resume = NULL;
34BOOLEAN mSmmLockBoxSmmReadyToLock = FALSE;
35BOOLEAN mSmmLockBoxDuringS3Resume = FALSE;
36
44 VOID
45 )
46{
47 UINTN Index;
48
49 //
50 // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone
51 //
52 for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
53 if (CompareGuid (&gMmst->MmConfigurationTable[Index].VendorGuid, &gEfiSmmLockBoxCommunicationGuid)) {
54 //
55 // Found. That means some other library instance is already run.
56 // No need to install again, just return.
57 //
59 }
60 }
61
62 //
63 // Not found.
64 //
65 return NULL;
66}
67
78EFIAPI
80 IN CONST EFI_GUID *Protocol,
81 IN VOID *Interface,
82 IN EFI_HANDLE Handle
83 )
84{
85 mSmmLockBoxSmmReadyToLock = TRUE;
86 return EFI_SUCCESS;
87}
88
108EFIAPI
110 IN EFI_HANDLE DispatchHandle,
111 IN CONST VOID *Context OPTIONAL,
112 IN OUT VOID *CommBuffer OPTIONAL,
113 IN OUT UINTN *CommBufferSize OPTIONAL
114 )
115{
116 mSmmLockBoxDuringS3Resume = TRUE;
117 return EFI_SUCCESS;
118}
119
130EFIAPI
132 IN CONST EFI_GUID *Protocol,
133 IN VOID *Interface,
134 IN EFI_HANDLE Handle
135 )
136{
137 EFI_STATUS Status;
139 EFI_SMM_SX_REGISTER_CONTEXT EntryRegisterContext;
140 EFI_HANDLE S3EntryHandle;
141
142 //
143 // Locate SmmSxDispatch2 protocol.
144 //
145 Status = gMmst->MmLocateProtocol (
146 &gEfiMmSxDispatchProtocolGuid,
147 NULL,
148 (VOID **)&SxDispatch
149 );
150 if (!EFI_ERROR (Status) && (SxDispatch != NULL)) {
151 //
152 // Register a S3 entry callback function to
153 // determine if it will be during S3 resume.
154 //
155 EntryRegisterContext.Type = SxS3;
156 EntryRegisterContext.Phase = SxEntry;
157 Status = SxDispatch->Register (
158 SxDispatch,
160 &EntryRegisterContext,
161 &S3EntryHandle
162 );
163 ASSERT_EFI_ERROR (Status);
164 }
165
166 return EFI_SUCCESS;
167}
168
179EFIAPI
181 IN CONST EFI_GUID *Protocol,
182 IN VOID *Interface,
183 IN EFI_HANDLE Handle
184 )
185{
186 mSmmLockBoxDuringS3Resume = FALSE;
187 return EFI_SUCCESS;
188}
189
199 VOID
200 )
201{
202 EFI_STATUS Status;
203 SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;
204
205 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Enter\n"));
206
207 //
208 // Register SmmReadyToLock notification.
209 //
210 Status = gMmst->MmRegisterProtocolNotify (
211 &gEfiMmReadyToLockProtocolGuid,
213 &mSmmLockBoxRegistrationSmmReadyToLock
214 );
215 ASSERT_EFI_ERROR (Status);
216
217 //
218 // Register SmmEndOfDxe notification.
219 //
220 Status = gMmst->MmRegisterProtocolNotify (
221 &gEfiMmEndOfDxeProtocolGuid,
223 &mSmmLockBoxRegistrationSmmEndOfDxe
224 );
225 ASSERT_EFI_ERROR (Status);
226
227 //
228 // Register EndOfS3Resume notification.
229 //
230 Status = gMmst->MmRegisterProtocolNotify (
231 &gEdkiiEndOfS3ResumeGuid,
233 &mSmmLockBoxRegistrationEndOfS3Resume
234 );
235 ASSERT_EFI_ERROR (Status);
236
237 //
238 // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone
239 //
240 SmmLockBoxContext = InternalGetSmmLockBoxContext ();
241 if (SmmLockBoxContext != NULL) {
242 //
243 // Find it. That means some other library instance is already run.
244 // No need to install again, just return.
245 //
246 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - already installed\n"));
247 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
248 return EFI_SUCCESS;
249 }
250
251 //
252 // If no one install this, it means this is first instance. Install it.
253 //
254 if (sizeof (UINTN) == sizeof (UINT64)) {
255 mSmmLockBoxContext.Signature = SMM_LOCK_BOX_SIGNATURE_64;
256 } else {
257 mSmmLockBoxContext.Signature = SMM_LOCK_BOX_SIGNATURE_32;
258 }
259
260 mSmmLockBoxContext.LockBoxDataAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)&mLockBoxQueue;
261
262 Status = gMmst->MmInstallConfigurationTable (
263 gMmst,
264 &gEfiSmmLockBoxCommunicationGuid,
266 sizeof (mSmmLockBoxContext)
267 );
268 ASSERT_EFI_ERROR (Status);
269 mSmmConfigurationTableInstalled = TRUE;
270
271 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - %x\n", (UINTN)&mSmmLockBoxContext));
272 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib LockBoxDataAddress - %x\n", (UINTN)&mLockBoxQueue));
273 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
274
275 return Status;
276}
277
288 VOID
289 )
290{
291 EFI_STATUS Status;
292
293 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmDestructor in %a module\n", gEfiCallerBaseName));
294
295 if (mSmmConfigurationTableInstalled) {
296 Status = gMmst->MmInstallConfigurationTable (
297 gMmst,
298 &gEfiSmmLockBoxCommunicationGuid,
299 NULL,
300 0
301 );
302 ASSERT_EFI_ERROR (Status);
303 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib uninstall SmmLockBoxCommunication configuration table\n"));
304 }
305
306 if (mSmmLockBoxRegistrationSmmReadyToLock != NULL) {
307 //
308 // Unregister SmmReadyToLock notification.
309 //
310 Status = gMmst->MmRegisterProtocolNotify (
311 &gEfiMmReadyToLockProtocolGuid,
312 NULL,
313 &mSmmLockBoxRegistrationSmmReadyToLock
314 );
315 ASSERT_EFI_ERROR (Status);
316 }
317
318 if (mSmmLockBoxRegistrationSmmEndOfDxe != NULL) {
319 //
320 // Unregister SmmEndOfDxe notification.
321 //
322 Status = gMmst->MmRegisterProtocolNotify (
323 &gEfiMmEndOfDxeProtocolGuid,
324 NULL,
325 &mSmmLockBoxRegistrationSmmEndOfDxe
326 );
327 ASSERT_EFI_ERROR (Status);
328 }
329
330 if (mSmmLockBoxRegistrationEndOfS3Resume != NULL) {
331 //
332 // Unregister EndOfS3Resume notification.
333 //
334 Status = gMmst->MmRegisterProtocolNotify (
335 &gEdkiiEndOfS3ResumeGuid,
336 NULL,
337 &mSmmLockBoxRegistrationEndOfS3Resume
338 );
339 ASSERT_EFI_ERROR (Status);
340 }
341
342 return EFI_SUCCESS;
343}
344
352 VOID
353 )
354{
355 SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;
356
357 SmmLockBoxContext = InternalGetSmmLockBoxContext ();
358 ASSERT (SmmLockBoxContext != NULL);
359 if (SmmLockBoxContext == NULL) {
360 return NULL;
361 }
362
363 return (LIST_ENTRY *)(UINTN)SmmLockBoxContext->LockBoxDataAddress;
364}
365
375 IN EFI_GUID *Guid
376 )
377{
378 LIST_ENTRY *Link;
379 SMM_LOCK_BOX_DATA *LockBox;
380 LIST_ENTRY *LockBoxQueue;
381
382 LockBoxQueue = InternalGetLockBoxQueue ();
383 ASSERT (LockBoxQueue != NULL);
384
385 for (Link = LockBoxQueue->ForwardLink;
386 Link != LockBoxQueue;
387 Link = Link->ForwardLink)
388 {
389 LockBox = BASE_CR (
390 Link,
392 Link
393 );
394 if (CompareGuid (&LockBox->Guid, Guid)) {
395 return LockBox;
396 }
397 }
398
399 return NULL;
400}
401
417RETURN_STATUS
418EFIAPI
420 IN GUID *Guid,
421 IN VOID *Buffer,
422 IN UINTN Length
423 )
424{
425 SMM_LOCK_BOX_DATA *LockBox;
426 EFI_PHYSICAL_ADDRESS SmramBuffer;
427 EFI_STATUS Status;
428 LIST_ENTRY *LockBoxQueue;
429
430 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Enter\n"));
431
432 //
433 // Basic check
434 //
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;
438 }
439
440 //
441 // Find LockBox
442 //
443 LockBox = InternalFindLockBoxByGuid (Guid);
444 if (LockBox != NULL) {
445 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_ALREADY_STARTED));
446 return EFI_ALREADY_STARTED;
447 }
448
449 //
450 // Allocate SMRAM buffer
451 //
452 Status = gMmst->MmAllocatePages (
455 EFI_SIZE_TO_PAGES (Length),
456 &SmramBuffer
457 );
458 ASSERT_EFI_ERROR (Status);
459 if (EFI_ERROR (Status)) {
460 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
461 return EFI_OUT_OF_RESOURCES;
462 }
463
464 //
465 // Allocate LockBox
466 //
467 Status = gMmst->MmAllocatePool (
469 sizeof (*LockBox),
470 (VOID **)&LockBox
471 );
472 ASSERT_EFI_ERROR (Status);
473 if (EFI_ERROR (Status)) {
474 gMmst->MmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
475 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
476 return EFI_OUT_OF_RESOURCES;
477 }
478
479 //
480 // Save data
481 //
482 CopyMem ((VOID *)(UINTN)SmramBuffer, (VOID *)(UINTN)Buffer, Length);
483
484 //
485 // Insert LockBox to queue
486 //
487 LockBox->Signature = SMM_LOCK_BOX_DATA_SIGNATURE;
488 CopyMem (&LockBox->Guid, Guid, sizeof (EFI_GUID));
489 LockBox->Buffer = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
490 LockBox->Length = (UINT64)Length;
491 LockBox->Attributes = 0;
492 LockBox->SmramBuffer = SmramBuffer;
493
494 DEBUG ((
495 DEBUG_INFO,
496 "LockBoxGuid - %g, SmramBuffer - 0x%lx, Length - 0x%lx\n",
497 &LockBox->Guid,
498 LockBox->SmramBuffer,
499 LockBox->Length
500 ));
501
502 LockBoxQueue = InternalGetLockBoxQueue ();
503 ASSERT (LockBoxQueue != NULL);
504 InsertTailList (LockBoxQueue, &LockBox->Link);
505
506 //
507 // Done
508 //
509 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_SUCCESS));
510 return EFI_SUCCESS;
511}
512
526RETURN_STATUS
527EFIAPI
529 IN GUID *Guid,
530 IN UINT64 Attributes
531 )
532{
533 SMM_LOCK_BOX_DATA *LockBox;
534
535 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Enter\n"));
536
537 //
538 // Basic check
539 //
540 if ((Guid == NULL) ||
541 ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE | LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0))
542 {
543 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_INVALID_PARAMETER));
544 return EFI_INVALID_PARAMETER;
545 }
546
547 if (((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
548 ((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0))
549 {
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;
554 }
555
556 //
557 // Find LockBox
558 //
559 LockBox = InternalFindLockBoxByGuid (Guid);
560 if (LockBox == NULL) {
561 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_NOT_FOUND));
562 return EFI_NOT_FOUND;
563 }
564
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)))
569 {
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;
574 }
575
576 //
577 // Update data
578 //
579 LockBox->Attributes = Attributes;
580
581 //
582 // Done
583 //
584 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit (%r)\n", EFI_SUCCESS));
585 return EFI_SUCCESS;
586}
587
607RETURN_STATUS
608EFIAPI
610 IN GUID *Guid,
611 IN UINTN Offset,
612 IN VOID *Buffer,
613 IN UINTN Length
614 )
615{
616 SMM_LOCK_BOX_DATA *LockBox;
617 EFI_PHYSICAL_ADDRESS SmramBuffer;
618 EFI_STATUS Status;
619
620 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib UpdateLockBox - Enter\n"));
621
622 //
623 // Basic check
624 //
625 if ((Guid == NULL) || (Buffer == NULL) || (Length == 0) ||
626 (Length > MAX_UINTN - Offset))
627 {
628 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));
629 return EFI_INVALID_PARAMETER;
630 }
631
632 //
633 // Find LockBox
634 //
635 LockBox = InternalFindLockBoxByGuid (Guid);
636 if (LockBox == NULL) {
637 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_NOT_FOUND));
638 return EFI_NOT_FOUND;
639 }
640
641 //
642 // Update data
643 //
644 if (LockBox->Length < Offset + Length) {
645 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0) {
646 //
647 // If 'LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY' attribute is set, enlarge the
648 // LockBox.
649 //
650 DEBUG ((
651 DEBUG_INFO,
652 "SmmLockBoxSmmLib UpdateLockBox - Origin LockBox too small, enlarge.\n"
653 ));
654
655 if (EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES ((UINTN)LockBox->Length)) < Offset + Length) {
656 //
657 // In SaveLockBox(), the SMRAM buffer allocated for LockBox is of page
658 // granularity. Here, if the required size is larger than the origin size
659 // of the pages, allocate new buffer from SMRAM to enlarge the LockBox.
660 //
661 DEBUG ((
662 DEBUG_INFO,
663 "SmmLockBoxSmmLib UpdateLockBox - Allocate new buffer to enlarge.\n"
664 ));
665 Status = gMmst->MmAllocatePages (
668 EFI_SIZE_TO_PAGES (Offset + Length),
669 &SmramBuffer
670 );
671 if (EFI_ERROR (Status)) {
672 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
673 return EFI_OUT_OF_RESOURCES;
674 }
675
676 //
677 // Copy origin data to the new SMRAM buffer and wipe the content in the
678 // origin SMRAM buffer.
679 //
680 CopyMem ((VOID *)(UINTN)SmramBuffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
681 ZeroMem ((VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
682 gMmst->MmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES ((UINTN)LockBox->Length));
683
684 LockBox->SmramBuffer = SmramBuffer;
685 }
686
687 //
688 // Handle uninitialized content in the LockBox.
689 //
690 if (Offset > LockBox->Length) {
691 ZeroMem (
692 (VOID *)((UINTN)LockBox->SmramBuffer + (UINTN)LockBox->Length),
693 Offset - (UINTN)LockBox->Length
694 );
695 }
696
697 LockBox->Length = Offset + Length;
698 } else {
699 //
700 // If 'LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY' attribute is NOT set, return
701 // EFI_BUFFER_TOO_SMALL directly.
702 //
703 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_BUFFER_TOO_SMALL));
704 return EFI_BUFFER_TOO_SMALL;
705 }
706 }
707
708 ASSERT ((UINTN)LockBox->SmramBuffer <= (MAX_ADDRESS - Offset));
709 CopyMem ((VOID *)((UINTN)LockBox->SmramBuffer + Offset), Buffer, Length);
710
711 //
712 // Done
713 //
714 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib UpdateLockBox - Exit (%r)\n", EFI_SUCCESS));
715 return EFI_SUCCESS;
716}
717
736RETURN_STATUS
737EFIAPI
739 IN GUID *Guid,
740 IN VOID *Buffer OPTIONAL,
741 IN OUT UINTN *Length OPTIONAL
742 )
743{
744 SMM_LOCK_BOX_DATA *LockBox;
745 VOID *RestoreBuffer;
746
747 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreLockBox - Enter\n"));
748
749 //
750 // Restore this, Buffer and Length MUST be both NULL or both non-NULL
751 //
752 if ((Guid == NULL) ||
753 ((Buffer == NULL) && (Length != NULL)) ||
754 ((Buffer != NULL) && (Length == NULL)))
755 {
756 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_INVALID_PARAMETER));
757 return EFI_INVALID_PARAMETER;
758 }
759
760 //
761 // Find LockBox
762 //
763 LockBox = InternalFindLockBoxByGuid (Guid);
764 if (LockBox == NULL) {
765 //
766 // Not found
767 //
768 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_NOT_FOUND));
769 return EFI_NOT_FOUND;
770 }
771
772 if (((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0) &&
773 mSmmLockBoxSmmReadyToLock &&
774 !mSmmLockBoxDuringS3Resume)
775 {
776 //
777 // With LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY,
778 // this LockBox can be restored in S3 resume only.
779 //
780 return EFI_ACCESS_DENIED;
781 }
782
783 //
784 // Set RestoreBuffer
785 //
786 if (Buffer != NULL) {
787 //
788 // restore to new buffer
789 //
790 RestoreBuffer = Buffer;
791 } else {
792 //
793 // restore to original buffer
794 //
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;
798 }
799
800 RestoreBuffer = (VOID *)(UINTN)LockBox->Buffer;
801 }
802
803 //
804 // Set RestoreLength
805 //
806 if (Length != NULL) {
807 if (*Length < (UINTN)LockBox->Length) {
808 //
809 // Input buffer is too small to hold all data.
810 //
811 *Length = (UINTN)LockBox->Length;
812 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_BUFFER_TOO_SMALL));
813 return EFI_BUFFER_TOO_SMALL;
814 }
815
816 *Length = (UINTN)LockBox->Length;
817 }
818
819 //
820 // Restore data
821 //
822 CopyMem (RestoreBuffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
823
824 //
825 // Done
826 //
827 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreLockBox - Exit (%r)\n", EFI_SUCCESS));
828 return EFI_SUCCESS;
829}
830
838RETURN_STATUS
839EFIAPI
841 VOID
842 )
843{
844 SMM_LOCK_BOX_DATA *LockBox;
845 LIST_ENTRY *Link;
846 LIST_ENTRY *LockBoxQueue;
847
848 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Enter\n"));
849
850 LockBoxQueue = InternalGetLockBoxQueue ();
851 ASSERT (LockBoxQueue != NULL);
852
853 //
854 // Restore all, Buffer and Length MUST be NULL
855 //
856 for (Link = LockBoxQueue->ForwardLink;
857 Link != LockBoxQueue;
858 Link = Link->ForwardLink)
859 {
860 LockBox = BASE_CR (
861 Link,
863 Link
864 );
865 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) {
866 //
867 // Restore data
868 //
869 CopyMem ((VOID *)(UINTN)LockBox->Buffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
870 }
871 }
872
873 //
874 // Done
875 //
876 DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Exit (%r)\n", EFI_SUCCESS));
877 return EFI_SUCCESS;
878}
UINT64 UINTN
#define MAX_ADDRESS
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
Definition: BaseLib.h:2904
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
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)
#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 OUT
Definition: Base.h:284
#define BASE_CR(Record, TYPE, Field)
Definition: Base.h:891
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
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
Definition: UefiBaseType.h:50
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
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
@ EfiRuntimeServicesData
@ AllocateAnyPages
Definition: UefiSpec.h:33
EFI_CONFIGURATION_TABLE * MmConfigurationTable
Definition: PiMmCis.h:322
EFI_ALLOCATE_POOL MmAllocatePool
Definition: PiMmCis.h:274
UINTN NumberOfTableEntries
Definition: PiMmCis.h:317
Definition: Base.h:213