]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.c
MdeModulePkg/DxeCorePerformanceLib:Variable Initial
[mirror_edk2.git] / MdeModulePkg / Library / SmmLockBoxLib / SmmLockBoxPeiLib.c
index bd3204b195343cdf6c89262a64a0d871e8f6ad52..fe1059d8fe5566c9dfc75c34eeee80dd16173a18 100644 (file)
@@ -1,15 +1,8 @@
 /** @file\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>\r
 \r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions\r
-of the BSD License which accompanies this distribution.  The\r
-full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -237,7 +230,7 @@ InternalGetSmmLockBoxContext (
   @param Length the length of the restored confidential information\r
 \r
   @retval RETURN_SUCCESS            the information is restored successfully.\r
-  @retval RETURN_WRITE_PROTECTED    Buffer and Length are NULL, but the LockBox has no \r
+  @retval RETURN_WRITE_PROTECTED    Buffer and Length are NULL, but the LockBox has no\r
                                     LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE attribute.\r
   @retval RETURN_BUFFER_TOO_SMALL   the Length is too small to hold the confidential information.\r
   @retval RETURN_NOT_FOUND          the requested GUID not found.\r
@@ -477,7 +470,10 @@ SetLockBoxAttributes (
   @retval RETURN_SUCCESS            the information is saved successfully.\r
   @retval RETURN_INVALID_PARAMETER  the Guid is NULL, or Buffer is NULL, or Length is 0.\r
   @retval RETURN_NOT_FOUND          the requested GUID not found.\r
-  @retval RETURN_BUFFER_TOO_SMALL   the original buffer to too small to hold new information.\r
+  @retval RETURN_BUFFER_TOO_SMALL   for lockbox without attribute LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY,\r
+                                    the original buffer to too small to hold new information.\r
+  @retval RETURN_OUT_OF_RESOURCES   for lockbox with attribute LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY,\r
+                                    no enough resource to save the information.\r
   @retval RETURN_ACCESS_DENIED      it is too late to invoke this interface\r
   @retval RETURN_NOT_STARTED        it is too early to invoke this interface\r
   @retval RETURN_UNSUPPORTED        the service is not supported by implementaion.\r
@@ -509,7 +505,7 @@ UpdateLockBox (
 \r
   @retval RETURN_SUCCESS            the information is restored successfully.\r
   @retval RETURN_INVALID_PARAMETER  the Guid is NULL, or one of Buffer and Length is NULL.\r
-  @retval RETURN_WRITE_PROTECTED    Buffer and Length are NULL, but the LockBox has no \r
+  @retval RETURN_WRITE_PROTECTED    Buffer and Length are NULL, but the LockBox has no\r
                                     LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE attribute.\r
   @retval RETURN_BUFFER_TOO_SMALL   the Length is too small to hold the confidential information.\r
   @retval RETURN_NOT_FOUND          the requested GUID not found.\r
@@ -542,7 +538,7 @@ RestoreLockBox (
   // } EFI_SMM_COMMUNICATE_HEADER;\r
   //\r
 \r
-  DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib RestoreLockBox - Enter\n"));\r
+  DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib RestoreLockBox - Enter\n"));\r
 \r
   //\r
   // Basic check\r
@@ -563,7 +559,10 @@ RestoreLockBox (
              (VOID **)&SmmCommunicationPpi\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_NOT_STARTED;\r
+    DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib LocatePpi - (%r)\n", Status));\r
+    Status = InternalRestoreLockBoxFromSmram (Guid, Buffer, Length);\r
+    DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib RestoreLockBox - Exit (%r)\n", Status));\r
+    return Status;\r
   }\r
 \r
   //\r
@@ -578,13 +577,13 @@ RestoreLockBox (
     CommHeader->MessageLength = sizeof(*LockBoxParameterRestore);\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib CommBuffer - %x\n", &CommBuffer[0]));\r
+  DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib CommBuffer - %x\n", &CommBuffer[0]));\r
   if ((sizeof(UINTN) == sizeof(UINT32)) && (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) ) {\r
     LockBoxParameterRestore = (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, MessageLength) + sizeof(UINT64)];\r
   } else {\r
     LockBoxParameterRestore = (EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *)&CommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, MessageLength) + sizeof(UINTN)];\r
   }\r
-  DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib LockBoxParameterRestore - %x\n", LockBoxParameterRestore));\r
+  DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib LockBoxParameterRestore - %x\n", LockBoxParameterRestore));\r
   LockBoxParameterRestore->Header.Command    = EFI_SMM_LOCK_BOX_COMMAND_RESTORE;\r
   LockBoxParameterRestore->Header.DataLength = sizeof(*LockBoxParameterRestore);\r
   LockBoxParameterRestore->Header.ReturnStatus = (UINT64)-1;\r
@@ -613,14 +612,13 @@ RestoreLockBox (
     //\r
     // Pei SMM communication not ready yet, so we access SMRAM directly\r
     //\r
-    DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib Communicate - (%r)\n", Status));\r
+    DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib Communicate - (%r)\n", Status));\r
     Status = InternalRestoreLockBoxFromSmram (Guid, Buffer, Length);\r
     LockBoxParameterRestore->Header.ReturnStatus = (UINT64)Status;\r
     if (Length != NULL) {\r
       LockBoxParameterRestore->Length = (UINT64)*Length;\r
     }\r
   }\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   if (Length != NULL) {\r
     *Length = (UINTN)LockBoxParameterRestore->Length;\r
@@ -632,7 +630,7 @@ RestoreLockBox (
     Status |= MAX_BIT;\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib RestoreLockBox - Exit (%r)\n", Status));\r
+  DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib RestoreLockBox - Exit (%r)\n", Status));\r
 \r
   //\r
   // Done\r
@@ -670,7 +668,7 @@ RestoreAllLockBoxInPlace (
   // } EFI_SMM_COMMUNICATE_HEADER;\r
   //\r
 \r
-  DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Enter\n"));\r
+  DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Enter\n"));\r
 \r
   //\r
   // Get needed resource\r
@@ -682,7 +680,10 @@ RestoreAllLockBoxInPlace (
              (VOID **)&SmmCommunicationPpi\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_NOT_STARTED;\r
+    DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib LocatePpi - (%r)\n", Status));\r
+    Status = InternalRestoreAllLockBoxInPlaceFromSmram ();\r
+    DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));\r
+    return Status;\r
   }\r
 \r
   //\r
@@ -719,7 +720,7 @@ RestoreAllLockBoxInPlace (
     //\r
     // Pei SMM communication not ready yet, so we access SMRAM directly\r
     //\r
-    DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib Communicate - (%r)\n", Status));\r
+    DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib Communicate - (%r)\n", Status));\r
     Status = InternalRestoreAllLockBoxInPlaceFromSmram ();\r
     LockBoxParameterRestoreAllInPlace->Header.ReturnStatus = (UINT64)Status;\r
   }\r
@@ -731,7 +732,7 @@ RestoreAllLockBoxInPlace (
     Status |= MAX_BIT;\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));\r
+  DEBUG ((DEBUG_INFO, "SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));\r
 \r
   //\r
   // Done\r