--- /dev/null
+/** @file\r
+\r
+ Copyright (c) 2006 - 2014, 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 of the BSD License\r
+ which accompanies this distribution. The 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
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <LockBoxLib.h>\r
+\r
+/**\r
+ Allocates a buffer of type EfiACPIMemoryNVS.\r
+\r
+ Allocates the number bytes specified by AllocationSize of type\r
+ EfiACPIMemoryNVS and returns a pointer to the allocated buffer.\r
+ If AllocationSize is 0, then a valid buffer of 0 size is\r
+ returned. If there is not enough memory remaining to satisfy\r
+ the request, then NULL is returned.\r
+\r
+ @param AllocationSize The number of bytes to allocate.\r
+\r
+ @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAcpiNvsPool (\r
+ IN UINTN AllocationSize\r
+ )\r
+{\r
+ ASSERT_EFI_ERROR (RETURN_UNSUPPORTED);\r
+ return NULL;\r
+}\r
--- /dev/null
+## @file\r
+#\r
+# Library implementing the LockBox interface for OVMF\r
+#\r
+# Copyright (C) 2013, Red Hat, Inc.\r
+# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution. The 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\r
+# IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = LockBoxBaseLib\r
+ FILE_GUID = 17CA9B37-5BAB-492C-A09C-7121FBE34CE6\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = LockBoxLib\r
+\r
+ CONSTRUCTOR = LockBoxLibInitialize\r
+\r
+[Sources]\r
+ LockBoxBase.c\r
+ LockBoxLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseMemoryLib\r
+ DebugLib\r
+\r
+[Pcd]\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
--- /dev/null
+/** @file\r
+\r
+ Copyright (c) 2006 - 2014, 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 of the BSD License\r
+ which accompanies this distribution. The 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
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <LockBoxLib.h>\r
+\r
+/**\r
+ Allocate memory below 4G memory address.\r
+\r
+ This function allocates memory below 4G memory address.\r
+\r
+ @param MemoryType Memory type of memory to allocate.\r
+ @param Size Size of memory to allocate.\r
+ \r
+ @return Allocated address for output.\r
+\r
+**/\r
+STATIC\r
+VOID *\r
+AllocateMemoryBelow4G (\r
+ IN EFI_MEMORY_TYPE MemoryType,\r
+ IN UINTN Size\r
+ )\r
+{\r
+ UINTN Pages;\r
+ EFI_PHYSICAL_ADDRESS Address;\r
+ EFI_STATUS Status;\r
+ VOID* Buffer;\r
+ UINTN AllocRemaining;\r
+\r
+ Pages = EFI_SIZE_TO_PAGES (Size);\r
+ Address = 0xffffffff;\r
+\r
+ //\r
+ // Since we need to use gBS->AllocatePages to get a buffer below\r
+ // 4GB, there is a good chance that space will be wasted for very\r
+ // small allocation. We keep track of unused portions of the page\r
+ // allocations, and use these to allocate memory for small buffers.\r
+ //\r
+ ASSERT (mLockBoxGlobal->Signature == LOCK_BOX_GLOBAL_SIGNATURE);\r
+ if ((UINTN) mLockBoxGlobal->SubPageRemaining >= Size) {\r
+ Buffer = (VOID*)(UINTN) mLockBoxGlobal->SubPageBuffer;\r
+ mLockBoxGlobal->SubPageBuffer += (UINT32) Size;\r
+ mLockBoxGlobal->SubPageRemaining -= (UINT32) Size;\r
+ return Buffer;\r
+ }\r
+\r
+ Status = gBS->AllocatePages (\r
+ AllocateMaxAddress,\r
+ MemoryType,\r
+ Pages,\r
+ &Address\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return NULL;\r
+ }\r
+\r
+ Buffer = (VOID *) (UINTN) Address;\r
+ ZeroMem (Buffer, EFI_PAGES_TO_SIZE (Pages));\r
+\r
+ AllocRemaining = EFI_PAGES_TO_SIZE (Pages) - Size;\r
+ if (AllocRemaining > (UINTN) mLockBoxGlobal->SubPageRemaining) {\r
+ mLockBoxGlobal->SubPageBuffer = (UINT32) (Address + Size);\r
+ mLockBoxGlobal->SubPageRemaining = (UINT32) AllocRemaining;\r
+ }\r
+\r
+ return Buffer;\r
+}\r
+\r
+\r
+/**\r
+ Allocates a buffer of type EfiACPIMemoryNVS.\r
+\r
+ Allocates the number bytes specified by AllocationSize of type\r
+ EfiACPIMemoryNVS and returns a pointer to the allocated buffer.\r
+ If AllocationSize is 0, then a valid buffer of 0 size is\r
+ returned. If there is not enough memory remaining to satisfy\r
+ the request, then NULL is returned.\r
+\r
+ @param AllocationSize The number of bytes to allocate.\r
+\r
+ @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAcpiNvsPool (\r
+ IN UINTN AllocationSize\r
+ )\r
+{\r
+ return AllocateMemoryBelow4G (EfiACPIMemoryNVS, AllocationSize);\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+LockBoxDxeLibInitialize (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return LockBoxLibInitialize ();\r
+}\r
--- /dev/null
+## @file\r
+#\r
+# Library implementing the LockBox interface for OVMF\r
+#\r
+# Copyright (C) 2013, Red Hat, Inc.\r
+# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution. The 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\r
+# IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = LockBoxDxeLib\r
+ FILE_GUID = f61c9a34-2e18-44ce-af2f-21a998e64fda\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = LockBoxLib\r
+\r
+ CONSTRUCTOR = LockBoxDxeLibInitialize\r
+\r
+[Sources]\r
+ LockBoxDxe.c\r
+ LockBoxLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseMemoryLib\r
+ DebugLib\r
+ UefiBootServicesTableLib\r
+\r
+[Pcd]\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
--- /dev/null
+/** @file\r
+\r
+ Library implementing the LockBox interface for OVMF\r
+\r
+ Copyright (C) 2013, Red Hat, Inc.\r
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The 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, WITHOUT\r
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/LockBoxLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <LockBoxLib.h>\r
+\r
+#pragma pack(1)\r
+typedef struct {\r
+ EFI_GUID Guid;\r
+ EFI_PHYSICAL_ADDRESS OrigAddress;\r
+ EFI_PHYSICAL_ADDRESS CopyAddress;\r
+ UINT32 Size;\r
+ UINT64 Attributes;\r
+} LOCK_BOX_ENTRY;\r
+#pragma pack()\r
+\r
+LOCK_BOX_GLOBAL *mLockBoxGlobal = NULL;\r
+STATIC LOCK_BOX_ENTRY *StartOfEntries = NULL;\r
+STATIC LOCK_BOX_ENTRY *EndOfEntries = NULL;\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+LockBoxLibInitialize (\r
+ VOID\r
+ )\r
+{\r
+ UINTN NumEntries;\r
+\r
+ if (PcdGet32 (PcdOvmfLockBoxStorageSize) < sizeof (LOCK_BOX_GLOBAL)) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+\r
+ mLockBoxGlobal = (LOCK_BOX_GLOBAL *)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase);\r
+ StartOfEntries = ((LOCK_BOX_ENTRY *) (mLockBoxGlobal + 1));\r
+ NumEntries = ((PcdGet32 (PcdOvmfLockBoxStorageSize) - sizeof (LOCK_BOX_GLOBAL)) /\r
+ sizeof (LOCK_BOX_ENTRY));\r
+ EndOfEntries = StartOfEntries + NumEntries; \r
+ if (mLockBoxGlobal->Signature != LOCK_BOX_GLOBAL_SIGNATURE) {\r
+ //\r
+ // Note: This code depends on the lock box being cleared in early\r
+ // PEI before usage, so the SubPageBuffer and SubPageRemaining\r
+ // fields don't need to be set to 0.\r
+ //\r
+ mLockBoxGlobal->Signature = LOCK_BOX_GLOBAL_SIGNATURE;\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ Find LockBox entry based on GUID.\r
+\r
+ @param[in] Guid The GUID to search for.\r
+\r
+ @return Address of the LOCK_BOX_ENTRY found.\r
+\r
+ If NULL, then the item was not found, and there is no space\r
+ left to store a new item.\r
+\r
+ If non-NULL and LOCK_BOX_ENTRY.Size == 0, then the item was not\r
+ found, but a new item can be inserted at the returned location.\r
+\r
+ If non-NULL and LOCK_BOX_ENTRY.Size > 0, then the item was found.\r
+**/\r
+STATIC\r
+LOCK_BOX_ENTRY *\r
+EFIAPI\r
+FindHeaderByGuid (\r
+ IN CONST EFI_GUID *Guid\r
+ )\r
+{\r
+ LOCK_BOX_ENTRY *Header;\r
+\r
+ for (Header = StartOfEntries; Header < EndOfEntries; Header++) {\r
+ if (Header->Size == 0 || CompareGuid (Guid, &Header->Guid)) {\r
+ return Header;\r
+ }\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+\r
+/**\r
+ This function will save confidential information to lockbox.\r
+\r
+ @param Guid the guid to identify the confidential information\r
+ @param Buffer the address of the confidential information\r
+ @param Length the length of the confidential information\r
+\r
+ @retval RETURN_SUCCESS the information is saved successfully.\r
+ @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or\r
+ Length is 0\r
+ @retval RETURN_ALREADY_STARTED the requested GUID already exist.\r
+ @retval RETURN_OUT_OF_RESOURCES 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\r
+ implementaion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SaveLockBox (\r
+ IN GUID *Guid,\r
+ IN VOID *Buffer,\r
+ IN UINTN Length\r
+ )\r
+{\r
+ LOCK_BOX_ENTRY *Header;\r
+ VOID *CopyBuffer;\r
+\r
+ DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Buffer=%p Length=0x%x\n", __FUNCTION__,\r
+ Guid, Buffer, (UINT32) Length));\r
+\r
+ if (Guid == NULL || Buffer == NULL || Length == 0) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (Length > 0xFFFFFFFF) {\r
+ return RETURN_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ Header = FindHeaderByGuid (Guid);\r
+ if (Header == NULL) {\r
+ return RETURN_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ if (Header->Size > 0) {\r
+ return RETURN_ALREADY_STARTED;\r
+ }\r
+\r
+ CopyBuffer = AllocateAcpiNvsPool (Length);\r
+ if (CopyBuffer == NULL) {\r
+ return RETURN_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // overwrite the current terminator header with new metadata\r
+ //\r
+ CopyGuid (&Header->Guid, Guid);\r
+ Header->OrigAddress = (UINTN) Buffer;\r
+ Header->CopyAddress = (UINTN) CopyBuffer;\r
+ Header->Size = (UINT32) Length;\r
+ Header->Attributes = 0;\r
+\r
+ //\r
+ // copy contents\r
+ //\r
+ CopyMem (CopyBuffer, Buffer, Length);\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This function will set lockbox attributes.\r
+\r
+ @param Guid the guid to identify the confidential information\r
+ @param Attributes the attributes of the lockbox\r
+\r
+ @retval RETURN_SUCCESS the information is saved successfully.\r
+ @retval RETURN_INVALID_PARAMETER attributes is invalid.\r
+ @retval RETURN_NOT_FOUND the requested GUID not found.\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\r
+ implementaion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+SetLockBoxAttributes (\r
+ IN GUID *Guid,\r
+ IN UINT64 Attributes\r
+ )\r
+{\r
+ LOCK_BOX_ENTRY *Header;\r
+\r
+ DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Attributes=0x%Lx\n", __FUNCTION__, Guid,\r
+ Attributes));\r
+\r
+ if (Guid == NULL) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ Header = FindHeaderByGuid (Guid);\r
+ if (!Header || Header->Size == 0) {\r
+ return RETURN_NOT_FOUND;\r
+ }\r
+ Header->Attributes = Attributes;\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This function will update confidential information to lockbox.\r
+\r
+ @param Guid the guid to identify the original confidential information\r
+ @param Offset the offset of the original confidential information\r
+ @param Buffer the address of the updated confidential information\r
+ @param Length the length of the updated confidential information\r
+\r
+ @retval RETURN_SUCCESS the information is saved successfully.\r
+ @retval RETURN_INVALID_PARAMETER the Guid is NULL, or Buffer is NULL, or\r
+ 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\r
+ new 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\r
+ implementaion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+UpdateLockBox (\r
+ IN GUID *Guid,\r
+ IN UINTN Offset,\r
+ IN VOID *Buffer,\r
+ IN UINTN Length\r
+ )\r
+{\r
+ LOCK_BOX_ENTRY *Header;\r
+\r
+ DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Offset=0x%x Length=0x%x\n", __FUNCTION__,\r
+ Guid, (UINT32) Offset, (UINT32) Length));\r
+\r
+ if (Guid == NULL || Buffer == NULL || Length == 0) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
+\r
+ Header = FindHeaderByGuid (Guid);\r
+ if (!Header || Header->Size == 0) {\r
+ return RETURN_NOT_FOUND;\r
+ }\r
+\r
+ if (Header->Size < Offset ||\r
+ Length > Header->Size - Offset) {\r
+ return RETURN_BUFFER_TOO_SMALL;\r
+ }\r
+\r
+ CopyMem ((UINT8 *)(UINTN) (Header->CopyAddress) + Offset, Buffer, Length);\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This function will restore confidential information from lockbox.\r
+\r
+ @param Guid the guid to identify the confidential information\r
+ @param Buffer the address of the restored confidential information\r
+ NULL means restored to original address, Length MUST be NULL at\r
+ same time.\r
+ @param Length the length of the restored confidential information\r
+\r
+ @retval RETURN_SUCCESS the information is restored successfully.\r
+ @retval RETURN_INVALID_PARAMETER the Guid is NULL, or one of Buffer and\r
+ Length is NULL.\r
+ @retval RETURN_WRITE_PROTECTED Buffer and Length are NULL, but the LockBox\r
+ has no LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE\r
+ attribute.\r
+ @retval RETURN_BUFFER_TOO_SMALL the Length is too small to hold the\r
+ confidential information.\r
+ @retval RETURN_NOT_FOUND the requested GUID not found.\r
+ @retval RETURN_NOT_STARTED it is too early to invoke this interface\r
+ @retval RETURN_ACCESS_DENIED not allow to restore to the address\r
+ @retval RETURN_UNSUPPORTED the service is not supported by\r
+ implementaion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+RestoreLockBox (\r
+ IN GUID *Guid,\r
+ IN VOID *Buffer, OPTIONAL\r
+ IN OUT UINTN *Length OPTIONAL\r
+ )\r
+{\r
+ LOCK_BOX_ENTRY *Header;\r
+\r
+ DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Buffer=%p\n", __FUNCTION__, Guid,\r
+ Buffer));\r
+\r
+ if ((Guid == NULL) ||\r
+ ((Buffer == NULL) && (Length != NULL)) ||\r
+ ((Buffer != NULL) && (Length == NULL))) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Header = FindHeaderByGuid (Guid);\r
+ if (!Header || Header->Size == 0) {\r
+ return RETURN_NOT_FOUND;\r
+ }\r
+\r
+ if (Buffer == NULL) {\r
+ if (!(Header->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE)) {\r
+ return RETURN_WRITE_PROTECTED;\r
+ }\r
+ if (Header->OrigAddress + (Header->Size - 1) > MAX_ADDRESS) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+ Buffer = (VOID *)(UINTN) Header->OrigAddress;\r
+ }\r
+\r
+ //\r
+ // Set RestoreLength\r
+ //\r
+ if (Length != NULL) {\r
+ if (Header->Size > *Length) {\r
+ //\r
+ // Input buffer is too small to hold all data.\r
+ //\r
+ *Length = Header->Size;\r
+ return EFI_BUFFER_TOO_SMALL;\r
+ }\r
+ *Length = Header->Size;\r
+ }\r
+\r
+ CopyMem (Buffer, (VOID*)(UINTN) Header->CopyAddress, Header->Size);\r
+\r
+ return RETURN_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This function will restore confidential information from all lockbox which\r
+ have RestoreInPlace attribute.\r
+\r
+ @retval RETURN_SUCCESS the information is restored successfully.\r
+ @retval RETURN_NOT_STARTED it is too early to invoke this interface\r
+ @retval RETURN_UNSUPPORTED the service is not supported by\r
+ implementaion.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+RestoreAllLockBoxInPlace (\r
+ VOID\r
+ )\r
+{\r
+ LOCK_BOX_ENTRY *Header;\r
+\r
+ for (Header = StartOfEntries;\r
+ Header < EndOfEntries && Header->Size > 0;\r
+ Header++) {\r
+ if (Header->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) {\r
+ VOID *Buffer;\r
+\r
+ if (Header->OrigAddress + (Header->Size - 1) > MAX_ADDRESS) {\r
+ return RETURN_UNSUPPORTED;\r
+ }\r
+ Buffer = (VOID *)(UINTN) Header->OrigAddress;\r
+ CopyMem (Buffer, (VOID*)(UINTN)Header->CopyAddress, Header->Size);\r
+ DEBUG ((DEBUG_VERBOSE, "%a: Guid=%g Buffer=%p\n", __FUNCTION__,\r
+ Header->Guid, Buffer));\r
+ }\r
+ }\r
+ return RETURN_SUCCESS;\r
+}\r
--- /dev/null
+/** @file\r
+ \r
+ Copyright (c) 2006 - 2014, 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 of the BSD License\r
+ which accompanies this distribution. The 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
+\r
+**/\r
+\r
+#ifndef __LOCK_BOX_LIB_IMPL_H__\r
+#define __LOCK_BOX_LIB_IMPL_H__\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+ UINT32 Signature;\r
+ UINT32 SubPageBuffer;\r
+ UINT32 SubPageRemaining;\r
+} LOCK_BOX_GLOBAL;\r
+\r
+#define LOCK_BOX_GLOBAL_SIGNATURE SIGNATURE_32('L', 'B', 'G', 'S')\r
+\r
+extern LOCK_BOX_GLOBAL *mLockBoxGlobal;\r
+\r
+#pragma pack()\r
+\r
+/**\r
+ Allocates a buffer of type EfiACPIMemoryNVS.\r
+\r
+ Allocates the number bytes specified by AllocationSize of type\r
+ EfiACPIMemoryNVS and returns a pointer to the allocated buffer.\r
+ If AllocationSize is 0, then a valid buffer of 0 size is\r
+ returned. If there is not enough memory remaining to satisfy\r
+ the request, then NULL is returned.\r
+\r
+ @param AllocationSize The number of bytes to allocate.\r
+\r
+ @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocateAcpiNvsPool (\r
+ IN UINTN AllocationSize\r
+ );\r
+\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+LockBoxLibInitialize (\r
+ VOID\r
+ );\r
+\r
+\r
+#endif\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|0x0|UINT32|0x13\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize|0x0|UINT32|0x14\r
gUefiOvmfPkgTokenSpaceGuid.PcdS3AcpiReservedMemoryBase|0x0|UINT32|0x17\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase|0x0|UINT32|0x18\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize|0x0|UINT32|0x19\r
\r
[PcdsDynamic, PcdsDynamicEx]\r
gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2\r
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf\r
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
- LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf\r
+ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf\r
\r
!ifdef $(SOURCE_DEBUG_ENABLE)\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
PlatformBdsLib|OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf\r
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
+ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf\r
\r
[LibraryClasses.common.UEFI_APPLICATION]\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
0x000000|0x006000\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize\r
\r
+0x006000|0x001000\r
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
+\r
0x010000|0x008000\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize\r
\r
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf\r
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
- LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf\r
+ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf\r
\r
!ifdef $(SOURCE_DEBUG_ENABLE)\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
PlatformBdsLib|OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf\r
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
+ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf\r
\r
[LibraryClasses.common.UEFI_APPLICATION]\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
0x000000|0x006000\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize\r
\r
+0x006000|0x001000\r
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
+\r
0x010000|0x008000\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize\r
\r
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf\r
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf\r
LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf\r
- LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf\r
+ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf\r
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf\r
\r
!ifdef $(SOURCE_DEBUG_ENABLE)\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
PlatformBdsLib|OvmfPkg/Library/PlatformBdsLib/PlatformBdsLib.inf\r
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
+ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf\r
\r
[LibraryClasses.common.UEFI_APPLICATION]\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
0x000000|0x006000\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize\r
\r
+0x006000|0x001000\r
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
+\r
0x010000|0x008000\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize\r
\r
//\r
// The Library classes this module consumes\r
//\r
+#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/HobLib.h>\r
#include <Library/IoLib.h>\r
EfiACPIMemoryNVS\r
);\r
#endif\r
+\r
+ //\r
+ // Reserve the lock box storage area\r
+ //\r
+ // Since this memory range will be used on S3 resume, it must be\r
+ // reserved as ACPI NVS.\r
+ //\r
+ ZeroMem (\r
+ (VOID*)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase),\r
+ (UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize)\r
+ );\r
+ BuildMemoryAllocationHob (\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase),\r
+ (UINT64)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize),\r
+ EfiACPIMemoryNVS\r
+ );\r
}\r
}\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase\r
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdS3AcpiReservedMemorySize\r
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r