add English.inf, EdkFvbServiceLib.inf and Variable.inf
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Jun 2007 11:29:10 +0000 (11:29 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Jun 2007 11:29:10 +0000 (11:29 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2842 6f19259b-4bc3-4df7-8a09-765794883524

23 files changed:
MdeModulePkg/Include/Common/FlashMap.h [new file with mode: 0644]
MdeModulePkg/Library/EdkFvbServiceLib/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf [new file with mode: 0644]
MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.msa [new file with mode: 0644]
MdeModulePkg/Library/EdkFvbServiceLib/EntryPoint.c [new file with mode: 0644]
MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.inf
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.msa
MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.inf [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.msa [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/UnicodeCollationEng.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/UnicodeCollationEng.h [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/CommonHeader.h [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/InitVariable.c [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/Variable.c [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/Variable.dxs [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/Variable.h [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/Variable.inf [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/Variable.msa [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/reclaim.c [new file with mode: 0644]
MdeModulePkg/Universal/VariableRuntimeDxe/reclaim.h [new file with mode: 0644]

diff --git a/MdeModulePkg/Include/Common/FlashMap.h b/MdeModulePkg/Include/Common/FlashMap.h
new file mode 100644 (file)
index 0000000..0473a69
--- /dev/null
@@ -0,0 +1,112 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  FlashMap.h\r
+\r
+Abstract:\r
+\r
+  FlashMap PPI defined in Tiano\r
+\r
+  This code abstracts FlashMap access\r
+\r
+--*/\r
+\r
+#ifndef __COMMON_FLASHMAP_H__\r
+#define __COMMON_FLASHMAP_H__\r
+\r
+#include <Common/FrameworkHob.h>\r
+//\r
+// Definition for flash map GUIDed HOBs\r
+//\r
+typedef UINT32  EFI_FLASH_AREA_ATTRIBUTES;\r
+\r
+#define EFI_FLASH_AREA_FV           0x0001\r
+#define EFI_FLASH_AREA_SUBFV        0x0002\r
+#define EFI_FLASH_AREA_MEMMAPPED_FV 0x0004\r
+#define EFI_FLASH_AREA_REQUIRED     0x0008\r
+#define EFI_FLASH_AREA_CORRUPT      0x0010\r
+\r
+typedef UINT8   EFI_FLASH_AREA_TYPE;\r
+\r
+#define EFI_FLASH_AREA_RECOVERY_BIOS  0x0   // Recovery code\r
+#define EFI_FLASH_AREA_MAIN_BIOS      0x1   // Regular BIOS code\r
+#define EFI_FLASH_AREA_PAL_B          0x2   // PAL-B\r
+#define EFI_FLASH_AREA_RESERVED_03    0x3   // Reserved for backwards compatibility\r
+#define EFI_FLASH_AREA_RESERVED_04    0x4   // Reserved for backwards compatibility\r
+#define EFI_FLASH_AREA_DMI_FRU        0x5   // DMI FRU information\r
+#define EFI_FLASH_AREA_OEM_BINARY     0x6   // OEM Binary Code/data\r
+#define EFI_FLASH_AREA_RESERVED_07    0x7   // Reserved for backwards compatibility\r
+#define EFI_FLASH_AREA_RESERVED_08    0x8   // Reserved for backwards compatibility\r
+#define EFI_FLASH_AREA_RESERVED_09    0x9   // Reserved for backwards compatibility\r
+#define EFI_FLASH_AREA_RESERVED_0A    0x0a  // Reserved for backwards compatibility\r
+#define EFI_FLASH_AREA_EFI_VARIABLES  0x0b  // EFI variables\r
+#define EFI_FLASH_AREA_MCA_LOG        0x0c  // MCA error log\r
+#define EFI_FLASH_AREA_SMBIOS_LOG     0x0d  // SMBIOS error log\r
+#define EFI_FLASH_AREA_FTW_BACKUP     0x0e  // A backup block during FTW operations\r
+#define EFI_FLASH_AREA_FTW_STATE      0x0f  // State information during FTW operations\r
+#define EFI_FLASH_AREA_UNUSED         0x0fd // Not used\r
+#define EFI_FLASH_AREA_GUID_DEFINED   0x0fe // Usage defined by a GUID\r
+#pragma pack(1)\r
+//\r
+// An individual sub-area Entry.\r
+// A single flash area may consist of  more than one sub-area.\r
+//\r
+typedef struct {\r
+  EFI_FLASH_AREA_ATTRIBUTES Attributes;\r
+  UINT32                    Reserved;\r
+  EFI_PHYSICAL_ADDRESS      Base;\r
+  EFI_PHYSICAL_ADDRESS      Length;\r
+  EFI_GUID                  FileSystem;\r
+} EFI_FLASH_SUBAREA_ENTRY;\r
+\r
+typedef struct {\r
+  UINT8                   Reserved[3];\r
+  EFI_FLASH_AREA_TYPE     AreaType;\r
+  EFI_GUID                AreaTypeGuid;\r
+  UINT32                  NumEntries;\r
+  EFI_FLASH_SUBAREA_ENTRY Entries[1];\r
+} EFI_FLASH_MAP_ENTRY_DATA;\r
+\r
+typedef struct {\r
+  EFI_HOB_GENERIC_HEADER  Header;\r
+  EFI_GUID                Name;\r
+  UINT8                   Reserved[3];\r
+  EFI_FLASH_AREA_TYPE     AreaType;\r
+  EFI_GUID                AreaTypeGuid;\r
+  UINT32                  NumEntries;\r
+  EFI_FLASH_SUBAREA_ENTRY Entries[1];\r
+} EFI_HOB_FLASH_MAP_ENTRY_TYPE;\r
+\r
+//\r
+// Internal definitions\r
+//\r
+typedef struct {\r
+  UINT8                   Reserved[3];\r
+  EFI_FLASH_AREA_TYPE     AreaType;\r
+  EFI_GUID                AreaTypeGuid;\r
+  UINT32                  NumberOfEntries;\r
+  EFI_FLASH_SUBAREA_ENTRY SubAreaData;\r
+} EFI_FLASH_AREA_HOB_DATA;\r
+\r
+typedef struct {\r
+  UINTN                     Base;\r
+  UINTN                     Length;\r
+  EFI_FLASH_AREA_ATTRIBUTES Attributes;\r
+  EFI_FLASH_AREA_TYPE       AreaType;\r
+  UINT8                     Reserved[3];\r
+  EFI_GUID                  AreaTypeGuid;\r
+} EFI_FLASH_AREA_DATA;\r
+\r
+#pragma pack()\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/CommonHeader.h b/MdeModulePkg/Library/EdkFvbServiceLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..01f5eb9
--- /dev/null
@@ -0,0 +1,49 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation\r
+  All rights reserved. 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
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Protocol/FvbExtension.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/FvbServiceLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// Declaration for callback Event.\r
+//\r
+VOID\r
+EFIAPI\r
+FvbVirtualAddressChangeNotifyEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf b/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf
new file mode 100644 (file)
index 0000000..9a89bfb
--- /dev/null
@@ -0,0 +1,123 @@
+#/** @file\r
+# FvbService Library for UEFI drivers\r
+#\r
+# This library instance provide sevice functions to access Firmware Volume Block protocol.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#  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
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EdkFvbServiceLib\r
+  FILE_GUID                      = bd4d540e-04b0-4b10-8fd5-4a7bb533cf67\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = EdkFvbServiceLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = FvbLibInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+#  VIRTUAL_ADDRESS_MAP_CALLBACK  =  FvbVirtualAddressChangeNotifyEvent\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  Fvb.h\r
+\r
+[Sources.Ia32]\r
+  Ia32/Fvb.c\r
+\r
+[Sources.X64]\r
+  x64/Fvb.c\r
+\r
+[Sources.IPF]\r
+  Ipf/Fvb.c\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses.IA32]\r
+  UefiBootServicesTableLib\r
+  UefiRuntimeLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  BaseLib\r
+  UefiLib\r
+\r
+[LibraryClasses.X64]\r
+  UefiBootServicesTableLib\r
+  UefiRuntimeLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  BaseLib\r
+  UefiLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+\r
+[Protocols.IA32]\r
+  gEfiFvbExtensionProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_CONSUMED\r
+\r
+[Protocols.X64]\r
+  gEfiFvbExtensionProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.msa b/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.msa
new file mode 100644 (file)
index 0000000..2aa7abb
--- /dev/null
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>EdkFvbServiceLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>bd4d540e-04b0-4b10-8fd5-4a7bb533cf67</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>FvbService Library for UEFI drivers</Abstract>\r
+    <Description>This library instance provide sevice functions to access Firmware Volume Block protocol.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials
+      are licensed and made available under the terms and conditions of the BSD License
+      which accompanies this distribution.  The full text of the license may be found at
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>EdkFvbServiceLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>EdkFvbServiceLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>UefiRuntimeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IPF">\r
+      <Keyword>EdkDxeSalLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Fvb.h</Filename>\r
+    <Filename SupArchList="IA32">Ia32/Fvb.c</Filename>\r
+    <Filename SupArchList="X64">x64/Fvb.c</Filename>\r
+    <Filename SupArchList="IPF">Ipf/Fvb.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64">\r
+      <ProtocolCName>gEfiFvbExtensionProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <ProtocolNotify Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolNotifyCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolNotifyCName>\r
+    </ProtocolNotify>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>FvbLibInitialize</Constructor>\r
+    </Extern>\r
+    <Extern>\r
+      <SetVirtualAddressMapCallBack>FvbVirtualAddressChangeNotifyEvent</SetVirtualAddressMapCallBack>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/EntryPoint.c b/MdeModulePkg/Library/EdkFvbServiceLib/EntryPoint.c
new file mode 100644 (file)
index 0000000..9cdf594
--- /dev/null
@@ -0,0 +1,54 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation\r
+  All rights reserved. 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
+   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 common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Event for Exit Boot Services Callback\r
+//\r
+STATIC EFI_EVENT mExitBootServicesEvent = NULL;\r
+\r
+/**\r
+  The user Entry Point for module EdkFvbServiceLib. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeEdkFvbServiceLib(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+                  TPL_NOTIFY,\r
+                  FvbVirtualAddressChangeNotifyEvent,\r
+                  NULL,\r
+                  &mExitBootServicesEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h b/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h
new file mode 100644 (file)
index 0000000..0f17932
--- /dev/null
@@ -0,0 +1,44 @@
+/**\r
+  The internal header file for EdkFvbServiceLib.\r
+\r
+Copyright (c) 2006 Intel Corporation. <BR>\r
+All rights reserved. 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
+**/\r
+\r
+#ifndef __FVB_H__\r
+#define __FVB_H__\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Protocol/FvbExtension.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/FvbServiceLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#define MAX_FVB_COUNT 16\r
+\r
+typedef struct {\r
+  EFI_HANDLE                          Handle;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;\r
+  EFI_FVB_EXTENSION_PROTOCOL          *FvbExtension;\r
+  BOOLEAN                             IsRuntimeAccess;\r
+} FVB_ENTRY;\r
+\r
+#endif\r
index 56e39e3..cb5410b 100644 (file)
@@ -96,6 +96,7 @@
   DevicePathLib|${WORKSPACE}/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   DxeServicesTableLib|${WORKSPACE}/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
   DxeServicesTableLib|${WORKSPACE}/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
   DxeServicesTableLib|${WORKSPACE}/MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
 \r
 [LibraryClasses.common.DXE_SAL_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   UefiDriverEntryPoint|${WORKSPACE}/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+\r
 \r
 [LibraryClasses.common.DXE_SMM_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   DevicePathLib|${WORKSPACE}/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+\r
 \r
 [LibraryClasses.common.UEFI_DRIVER]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   UefiDriverEntryPoint|${WORKSPACE}/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+\r
 \r
 [LibraryClasses.common.UEFI_APPLICATION]\r
   HobLib|${WORKSPACE}/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   UefiLib|${WORKSPACE}/MdePkg/Library/UefiLib/UefiLib.inf\r
   UefiRuntimeServicesTableLib|${WORKSPACE}/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
   DebugLib|${WORKSPACE}/MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf\r
+  FvbServiceLib|${WORKSPACE}/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  ReportStatusCodeLib|${WORKSPACE}/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
 \r
 \r
 [LibraryClasses.IA32.BASE]\r
   PcdDriverDiagnostics2Disable|gEfiMdePkgTokenSpaceGuid|TRUE\r
   PcdSupportUpdateCapsuleRest|gEfiEdkModulePkgTokenSpaceGuid|FALSE\r
 \r
+#  PcdStatusCodeUseOEM|gEfiIntelFrameworkModulePkgTokenSpaceGuid|FALSE\r
+\r
 [PcdsFixedAtBuild.common]\r
   PcdMaximumUnicodeStringLength|gEfiMdePkgTokenSpaceGuid|1000000\r
   PcdMaximumAsciiStringLength|gEfiMdePkgTokenSpaceGuid|1000000\r
   PcdFlashNvStorageFtwSpareSize|gEfiGenericPlatformTokenSpaceGuid|0x0\r
   PcdFlashNvStorageFtwWorkingBase|gEfiGenericPlatformTokenSpaceGuid|0x0\r
   PcdFlashNvStorageFtwWorkingSize|gEfiGenericPlatformTokenSpaceGuid|0x0\r
+  PcdFlashNvStorageVariableBase|gEfiGenericPlatformTokenSpaceGuid|0x0\r
+  PcdFlashNvStorageVariableSize|gEfiGenericPlatformTokenSpaceGuid|0x0\r
 \r
 [PcdsPatchableInModule.common]\r
   PcdDebugPrintErrorLevel|gEfiMdePkgTokenSpaceGuid|0x80000000\r
   ${WORKSPACE}/MdeModulePkg/Universal/GenericMemoryTest/Dxe/NullMemoryTest.inf\r
   ${WORKSPACE}/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteLite/Dxe/FtwLite.inf\r
   #${WORKSPACE}/MdeModulePkg/Universal/FirmwareVolume/GuidedSectionExtraction/Crc32SectionExtract/Dxe/Crc32SectionExtract.inf\r
+  ${WORKSPACE}/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.inf\r
   ${WORKSPACE}/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.inf\r
   ${WORKSPACE}/MdeModulePkg/Universal/WatchDogTimerDxe/WatchDogTimer.inf\r
-  ${WORKSPACE}/MdeModulePkg/Universal/VariablePei/Variable.inf
\ No newline at end of file
+  ${WORKSPACE}/MdeModulePkg/Universal/VariablePei/Variable.inf\r
index ad73679..7b4f93d 100644 (file)
@@ -47,7 +47,7 @@
 [Sources.common]\r
   ComponentName.c\r
   DiskIo.h\r
-  diskio.c\r
+  DiskIo.c\r
 \r
 \r
 ################################################################################\r
index f5b93c8..3ee0fee 100644 (file)
@@ -49,7 +49,7 @@
     </LibraryClass>\r
   </LibraryClassDefinitions>\r
   <SourceFiles>\r
-    <Filename>diskio.c</Filename>\r
+    <FilenameDiskIo.c</Filename>\r
     <Filename>DiskIo.h</Filename>\r
     <Filename>ComponentName.c</Filename>\r
   </SourceFiles>\r
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/CommonHeader.h b/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..f1a8cc6
--- /dev/null
@@ -0,0 +1,35 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation\r
+  All rights reserved. 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
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/UnicodeCollation.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.inf b/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.inf
new file mode 100644 (file)
index 0000000..7022ab1
--- /dev/null
@@ -0,0 +1,93 @@
+#/** @file\r
+# Component description file for English module for unicode collation.\r
+#\r
+# This driver installs UEFI EFI_UNICODE_COLLATION_PROTOCOL protocol to provide Unicode strings function.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#  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
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = English\r
+  FILE_GUID                      = CD3BAFB6-50FB-4fe8-8E4E-AB74D2C1A600\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnicodeCollationEng\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UnicodeCollationEng.c\r
+  UnicodeCollationEng.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  $(WORKSPACE)/MdeModulePkg/MdeModulePkg.dec\r
+  $(WORKSPACE)/MdePkg/MdePkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiUnicodeCollationProtocolGuid              # PROTOCOL ALWAYS_PRODUCED\r
+\r
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.msa b/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.msa
new file mode 100644 (file)
index 0000000..3a72998
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>English</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>CD3BAFB6-50FB-4fe8-8E4E-AB74D2C1A600</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for English module for unicode collation.</Abstract>\r
+    <Description>This driver installs UEFI EFI_UNICODE_COLLATION_PROTOCOL protocol to provide Unicode strings function.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. 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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>English</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">\r
+      <Keyword>DebugLib</Keyword>\r
+      <HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnicodeCollationEng.h</Filename>\r
+    <Filename>UnicodeCollationEng.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiUnicodeCollationProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeUnicodeCollationEng</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/UnicodeCollationEng.c b/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/UnicodeCollationEng.c
new file mode 100644 (file)
index 0000000..5b543e9
--- /dev/null
@@ -0,0 +1,479 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  UnicodeCollationEng.c\r
+\r
+Abstract:\r
+\r
+  Unicode Collation Protocol (English)\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+\r
+#include "UnicodeCollationEng.h"\r
+\r
+CHAR8 mEngUpperMap[0x100];\r
+CHAR8 mEngLowerMap[0x100];\r
+CHAR8 mEngInfoMap[0x100];\r
+\r
+CHAR8 mOtherChars[] = {\r
+  '0',\r
+  '1',\r
+  '2',\r
+  '3',\r
+  '4',\r
+  '5',\r
+  '6',\r
+  '7',\r
+  '8',\r
+  '9',\r
+  '\\',\r
+  '.',\r
+  '_',\r
+  '^',\r
+  '$',\r
+  '~',\r
+  '!',\r
+  '#',\r
+  '%',\r
+  '&',\r
+  '-',\r
+  '{',\r
+  '}',\r
+  '(',\r
+  ')',\r
+  '@',\r
+  '`',\r
+  '\'',\r
+  '\0'\r
+};\r
+\r
+EFI_HANDLE  mHandle = NULL;\r
+\r
+EFI_UNICODE_COLLATION_PROTOCOL  UnicodeEng = {\r
+  EngStriColl,\r
+  EngMetaiMatch,\r
+  EngStrLwr,\r
+  EngStrUpr,\r
+  EngFatToStr,\r
+  EngStrToFat,\r
+  "eng"\r
+};\r
+\r
+//\r
+//\r
+//\r
+EFI_STATUS\r
+InitializeUnicodeCollationEng (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initializes the Unicode Collation Driver\r
+\r
+Arguments:\r
+\r
+  ImageHandle -\r
+\r
+  SystemTable -\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_OUT_OF_RESOURCES\r
+\r
+--*/\r
+{\r
+  UINTN       Index;\r
+  UINTN       Index2;\r
+\r
+  //\r
+  // Initialize mapping tables for the supported languages\r
+  //\r
+  for (Index = 0; Index < 0x100; Index++) {\r
+    mEngUpperMap[Index] = (CHAR8) Index;\r
+    mEngLowerMap[Index] = (CHAR8) Index;\r
+    mEngInfoMap[Index]  = 0;\r
+\r
+    if ((Index >= 'a' && Index <= 'z') || (Index >= 0xe0 && Index <= 0xf6) || (Index >= 0xf8 && Index <= 0xfe)) {\r
+\r
+      Index2                = Index - 0x20;\r
+      mEngUpperMap[Index]   = (CHAR8) Index2;\r
+      mEngLowerMap[Index2]  = (CHAR8) Index;\r
+\r
+      mEngInfoMap[Index] |= CHAR_FAT_VALID;\r
+      mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r
+    }\r
+  }\r
+\r
+  for (Index = 0; mOtherChars[Index]; Index++) {\r
+    Index2 = mOtherChars[Index];\r
+    mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r
+  }\r
+  //\r
+  // Create a handle for the device\r
+  //\r
+  return gBS->InstallProtocolInterface (\r
+                &mHandle,\r
+                &gEfiUnicodeCollationProtocolGuid,\r
+                EFI_NATIVE_INTERFACE,\r
+                &UnicodeEng\r
+                );\r
+}\r
+\r
+INTN\r
+EFIAPI\r
+EngStriColl (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN CHAR16                           *s1,\r
+  IN CHAR16                           *s2\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Performs a case-insensitive comparison of two Null-terminated Unicode strings.\r
+\r
+Arguments:\r
+\r
+  This\r
+  s1\r
+  s2\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  while (*s1) {\r
+    if (ToUpper (*s1) != ToUpper (*s2)) {\r
+      break;\r
+    }\r
+\r
+    s1 += 1;\r
+    s2 += 1;\r
+  }\r
+\r
+  return ToUpper (*s1) - ToUpper (*s2);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EngStrLwr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN OUT CHAR16                       *Str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts all the Unicode characters in a Null-terminated Unicode string\r
+  to lower case Unicode characters.\r
+\r
+Arguments:\r
+\r
+  This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.\r
+  Str1  - A pointer to a Null-terminated Unicode string.\r
+  Str2  - A pointer to a Null-terminated Unicode string.\r
+\r
+Returns:\r
+\r
+  0   - s1 is equivalent to s2.\r
+  > 0 - s1 is lexically greater than s2.\r
+  < 0 - s1 is lexically less than s2.\r
+\r
+--*/\r
+{\r
+  while (*Str) {\r
+    *Str = ToLower (*Str);\r
+    Str += 1;\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EngStrUpr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN OUT CHAR16                       *Str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts all the Unicode characters in a Null-terminated\r
+  Unicode string to upper case Unicode characters.\r
+\r
+Arguments:\r
+  This\r
+  Str\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  while (*Str) {\r
+    *Str = ToUpper (*Str);\r
+    Str += 1;\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngMetaiMatch (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN CHAR16                           *String,\r
+  IN CHAR16                           *Pattern\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Performs a case-insensitive comparison between a Null-terminated\r
+  Unicode pattern string and a Null-terminated Unicode string.\r
+\r
+  The pattern string can use the '?' wildcard to match any character,\r
+  and the '*' wildcard to match any sub-string.\r
+\r
+Arguments:\r
+\r
+  This     - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.\r
+  String   - A pointer to a Null-terminated Unicode string.\r
+  Pattern  - A pointer to a Null-terminated Unicode pattern string.\r
+\r
+Returns:\r
+\r
+  TRUE  - Pattern was found in String.\r
+  FALSE - Pattern was not found in String.\r
+\r
+--*/\r
+{\r
+  CHAR16  CharC;\r
+  CHAR16  CharP;\r
+  CHAR16  Index3;\r
+\r
+  for (;;) {\r
+    CharP = *Pattern;\r
+    Pattern += 1;\r
+\r
+    switch (CharP) {\r
+    case 0:\r
+      //\r
+      // End of pattern.  If end of string, TRUE match\r
+      //\r
+      if (*String) {\r
+        return FALSE;\r
+      } else {\r
+        return TRUE;\r
+      }\r
+\r
+    case '*':\r
+      //\r
+      // Match zero or more chars\r
+      //\r
+      while (*String) {\r
+        if (EngMetaiMatch (This, String, Pattern)) {\r
+          return TRUE;\r
+        }\r
+\r
+        String += 1;\r
+      }\r
+\r
+      return EngMetaiMatch (This, String, Pattern);\r
+\r
+    case '?':\r
+      //\r
+      // Match any one char\r
+      //\r
+      if (!*String) {\r
+        return FALSE;\r
+      }\r
+\r
+      String += 1;\r
+      break;\r
+\r
+    case '[':\r
+      //\r
+      // Match char set\r
+      //\r
+      CharC = *String;\r
+      if (!CharC) {\r
+        //\r
+        // syntax problem\r
+        //\r
+        return FALSE;\r
+      }\r
+\r
+      Index3  = 0;\r
+      CharP   = *Pattern++;\r
+      while (CharP) {\r
+        if (CharP == ']') {\r
+          return FALSE;\r
+        }\r
+\r
+        if (CharP == '-') {\r
+          //\r
+          // if range of chars, get high range\r
+          //\r
+          CharP = *Pattern;\r
+          if (CharP == 0 || CharP == ']') {\r
+            //\r
+            // syntax problem\r
+            //\r
+            return FALSE;\r
+          }\r
+\r
+          if (ToUpper (CharC) >= ToUpper (Index3) && ToUpper (CharC) <= ToUpper (CharP)) {\r
+            //\r
+            // if in range, it's a match\r
+            //\r
+            break;\r
+          }\r
+        }\r
+\r
+        Index3 = CharP;\r
+        if (ToUpper (CharC) == ToUpper (CharP)) {\r
+          //\r
+          // if char matches\r
+          //\r
+          break;\r
+        }\r
+\r
+        CharP = *Pattern++;\r
+      }\r
+      //\r
+      // skip to end of match char set\r
+      //\r
+      while (CharP && CharP != ']') {\r
+        CharP = *Pattern;\r
+        Pattern += 1;\r
+      }\r
+\r
+      String += 1;\r
+      break;\r
+\r
+    default:\r
+      CharC = *String;\r
+      if (ToUpper (CharC) != ToUpper (CharP)) {\r
+        return FALSE;\r
+      }\r
+\r
+      String += 1;\r
+      break;\r
+    }\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EngFatToStr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN UINTN                            FatSize,\r
+  IN CHAR8                            *Fat,\r
+  OUT CHAR16                          *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts an 8.3 FAT file name using an OEM character set\r
+  to a Null-terminated Unicode string.\r
+\r
+  BUGBUG: Function has to expand DBCS FAT chars, currently not.\r
+\r
+Arguments:\r
+  This\r
+  FatSize\r
+  Fat\r
+  String\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  //\r
+  // No DBCS issues, just expand and add null terminate to end of string\r
+  //\r
+  while (*Fat && FatSize) {\r
+    *String = *Fat;\r
+    String += 1;\r
+    Fat += 1;\r
+    FatSize -= 1;\r
+  }\r
+\r
+  *String = 0;\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngStrToFat (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN CHAR16                           *String,\r
+  IN UINTN                            FatSize,\r
+  OUT CHAR8                           *Fat\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts a Null-terminated Unicode string to legal characters\r
+  in a FAT filename using an OEM character set.\r
+\r
+  Functions has to crunch string to a fat string. Replacing\r
+  any chars that can't be represented in the fat name.\r
+\r
+Arguments:\r
+  This\r
+  String\r
+  FatSize\r
+  Fat\r
+\r
+Returns:\r
+  TRUE\r
+  FALSE\r
+--*/\r
+{\r
+  BOOLEAN SpecialCharExist;\r
+\r
+  SpecialCharExist = FALSE;\r
+  while (*String && FatSize) {\r
+    //\r
+    // Skip '.' or ' ' when making a fat name\r
+    //\r
+    if (*String != '.' && *String != ' ') {\r
+      //\r
+      // If this is a valid fat char, move it.\r
+      // Otherwise, move a '_' and flag the fact that the name needs an Lfn\r
+      //\r
+      if (*String < 0x100 && (mEngInfoMap[*String] & CHAR_FAT_VALID)) {\r
+        *Fat = mEngUpperMap[*String];\r
+      } else {\r
+        *Fat              = '_';\r
+        SpecialCharExist  = TRUE;\r
+      }\r
+\r
+      Fat += 1;\r
+      FatSize -= 1;\r
+    }\r
+\r
+    String += 1;\r
+  }\r
+  //\r
+  // Do not terminate that fat string\r
+  //\r
+  return SpecialCharExist;\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/UnicodeCollationEng.h b/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/UnicodeCollationEng.h
new file mode 100644 (file)
index 0000000..c8485ac
--- /dev/null
@@ -0,0 +1,117 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  UnicodeCollationEng.h\r
+\r
+Abstract:\r
+\r
+  Head file for Unicode Collation Protocol (English)\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _UNICODE_COLLATION_ENG_H\r
+#define _UNICODE_COLLATION_ENG_H\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/UnicodeCollation.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// Defines\r
+//\r
+#define CHAR_FAT_VALID  0x01\r
+\r
+#define ToUpper(a)      (CHAR16) (a <= 0xFF ? mEngUpperMap[a] : a)\r
+#define ToLower(a)      (CHAR16) (a <= 0xFF ? mEngLowerMap[a] : a)\r
+\r
+//\r
+// Prototypes\r
+//\r
+INTN\r
+EFIAPI\r
+EngStriColl (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL           *This,\r
+  IN CHAR16                                   *s1,\r
+  IN CHAR16                                   *s2\r
+  )\r
+;\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngMetaiMatch (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN CHAR16                                  *String,\r
+  IN CHAR16                                  *Pattern\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+EngStrLwr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN OUT CHAR16                              *Str\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+EngStrUpr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN OUT CHAR16                              *Str\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+EngFatToStr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN UINTN                                   FatSize,\r
+  IN CHAR8                                   *Fat,\r
+  OUT CHAR16                                 *String\r
+  )\r
+;\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngStrToFat (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN CHAR16                                  *String,\r
+  IN UINTN                                   FatSize,\r
+  OUT CHAR8                                  *Fat\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnicodeCollationEng (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/CommonHeader.h b/MdeModulePkg/Universal/VariableRuntimeDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..4f16113
--- /dev/null
@@ -0,0 +1,46 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation\r
+  All rights reserved. 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
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <FrameworkDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/VariableWrite.h>\r
+#include <Protocol/FaultTolerantWriteLite.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Protocol/Variable.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/FvbServiceLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/InitVariable.c b/MdeModulePkg/Universal/VariableRuntimeDxe/InitVariable.c
new file mode 100644 (file)
index 0000000..15e84e8
--- /dev/null
@@ -0,0 +1,234 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  InitVariable.c\r
+\r
+Abstract:\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Variable.h"\r
+\r
+//\r
+// Event for Exit Boot Services Callback\r
+//\r
+STATIC EFI_EVENT mExitBootServicesEvent = NULL;\r
+\r
+\r
+//\r
+// Don't use module globals after the SetVirtualAddress map is signaled\r
+//\r
+extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeServiceGetVariable (\r
+  IN CHAR16        *VariableName,\r
+  IN EFI_GUID      * VendorGuid,\r
+  OUT UINT32       *Attributes OPTIONAL,\r
+  IN OUT UINTN     *DataSize,\r
+  OUT VOID         *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  return GetVariable (\r
+          VariableName,\r
+          VendorGuid,\r
+          Attributes OPTIONAL,\r
+          DataSize,\r
+          Data,\r
+          &mVariableModuleGlobal->VariableGlobal[Physical],\r
+          mVariableModuleGlobal->FvbInstance\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeServiceGetNextVariableName (\r
+  IN OUT UINTN     *VariableNameSize,\r
+  IN OUT CHAR16    *VariableName,\r
+  IN OUT EFI_GUID  *VendorGuid\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  return GetNextVariableName (\r
+          VariableNameSize,\r
+          VariableName,\r
+          VendorGuid,\r
+          &mVariableModuleGlobal->VariableGlobal[Physical],\r
+          mVariableModuleGlobal->FvbInstance\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeServiceSetVariable (\r
+  IN CHAR16        *VariableName,\r
+  IN EFI_GUID      *VendorGuid,\r
+  IN UINT32        Attributes,\r
+  IN UINTN         DataSize,\r
+  IN VOID          *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  return SetVariable (\r
+          VariableName,\r
+          VendorGuid,\r
+          Attributes,\r
+          DataSize,\r
+          Data,\r
+          &mVariableModuleGlobal->VariableGlobal[Physical],\r
+          &mVariableModuleGlobal->VolatileLastVariableOffset,\r
+          &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
+          mVariableModuleGlobal->FvbInstance\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeServiceQueryVariableInfo (\r
+  IN  UINT32                 Attributes,\r
+  OUT UINT64                 *MaximumVariableStorageSize,\r
+  OUT UINT64                 *RemainingVariableStorageSize,\r
+  OUT UINT64                 *MaximumVariableSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  return QueryVariableInfo (\r
+          Attributes,\r
+          MaximumVariableStorageSize,\r
+          RemainingVariableStorageSize,\r
+          MaximumVariableSize,\r
+          &mVariableModuleGlobal->VariableGlobal[Physical],\r
+          mVariableModuleGlobal->FvbInstance\r
+          );\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+VariableClassAddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EfiConvertPointer (\r
+    0x0,\r
+    (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase\r
+    );\r
+  EfiConvertPointer (\r
+    0x0,\r
+    (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase\r
+    );\r
+  EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VariableServiceInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_HANDLE  NewHandle;\r
+  EFI_STATUS  Status;\r
+\r
+  Status = VariableCommonInitialize (ImageHandle, SystemTable);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  SystemTable->RuntimeServices->GetVariable         = RuntimeServiceGetVariable;\r
+  SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r
+  SystemTable->RuntimeServices->SetVariable         = RuntimeServiceSetVariable;\r
+  SystemTable->RuntimeServices->QueryVariableInfo   = RuntimeServiceQueryVariableInfo;\r
+\r
+  //\r
+  // Now install the Variable Runtime Architectural Protocol on a new handle\r
+  //\r
+  NewHandle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &NewHandle,\r
+                  &gEfiVariableArchProtocolGuid,\r
+                  NULL,\r
+                  &gEfiVariableWriteArchProtocolGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+                  TPL_NOTIFY,\r
+                  VariableClassAddressChangeEvent,\r
+                  NULL,\r
+                  &mExitBootServicesEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.c b/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.c
new file mode 100644 (file)
index 0000000..f6aa468
--- /dev/null
@@ -0,0 +1,1479 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  Variable.c\r
+\r
+Abstract:\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+\r
+#include "Variable.h"\r
+#include "reclaim.h"\r
+\r
+#include <Common/FlashMap.h>\r
+\r
+//\r
+// Don't use module globals after the SetVirtualAddress map is signaled\r
+//\r
+ESAL_VARIABLE_GLOBAL  *mVariableModuleGlobal;\r
+\r
+//\r
+// This is a temperary function which will be removed\r
+// when EfiAcquireLock in UefiLib can handle the\r
+// the call in UEFI Runtimer driver in RT phase.\r
+//\r
+STATIC\r
+VOID\r
+AcquireLockOnlyAtBootTime (\r
+  IN EFI_LOCK  *Lock\r
+  )\r
+{\r
+  if (!EfiAtRuntime ()) {\r
+    EfiAcquireLock (Lock);\r
+  }\r
+}\r
+\r
+//\r
+// This is a temperary function which will be removed\r
+// when EfiAcquireLock in UefiLib can handle the\r
+// the call in UEFI Runtimer driver in RT phase.\r
+//\r
+STATIC\r
+VOID\r
+ReleaseLockOnlyAtBootTime (\r
+  IN EFI_LOCK  *Lock\r
+  )\r
+{\r
+  if (!EfiAtRuntime ()) {\r
+    EfiReleaseLock (Lock);\r
+  }\r
+}\r
+\r
+STATIC\r
+BOOLEAN\r
+EFIAPI\r
+IsValidVariableHeader (\r
+  IN  VARIABLE_HEADER   *Variable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code checks if variable header is valid or not.\r
+\r
+Arguments:\r
+  Variable              Pointer to the Variable Header.\r
+\r
+Returns:\r
+  TRUE            Variable header is valid.\r
+  FALSE           Variable header is not valid.\r
+\r
+--*/\r
+{\r
+  if (Variable == NULL ||\r
+      Variable->StartId != VARIABLE_DATA ||\r
+      (sizeof (VARIABLE_HEADER) + Variable->NameSize + Variable->DataSize) > MAX_VARIABLE_SIZE\r
+      ) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UpdateVariableStore (\r
+  IN  VARIABLE_GLOBAL         *Global,\r
+  IN  BOOLEAN                 Volatile,\r
+  IN  BOOLEAN                 SetByIndex,\r
+  IN  UINTN                   Instance,\r
+  IN  UINTN                   DataPtrIndex,\r
+  IN  UINT32                  DataSize,\r
+  IN  UINT8                   *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function writes data to the FWH at the correct LBA even if the LBAs\r
+  are fragmented.\r
+\r
+Arguments:\r
+\r
+  Global            Pointer to VARAIBLE_GLOBAL structure\r
+  Volatile          If the Variable is Volatile or Non-Volatile\r
+  SetByIndex        TRUE: Target pointer is given as index\r
+                    FALSE: Target pointer is absolute\r
+  Instance          Instance of FV Block services\r
+  DataPtrIndex      Pointer to the Data from the end of VARIABLE_STORE_HEADER\r
+                    structure\r
+  DataSize          Size of data to be written.\r
+  Buffer            Pointer to the buffer from which data is written\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+\r
+--*/\r
+{\r
+  EFI_FV_BLOCK_MAP_ENTRY      *PtrBlockMapEntry;\r
+  UINTN                       BlockIndex2;\r
+  UINTN                       LinearOffset;\r
+  UINTN                       CurrWriteSize;\r
+  UINTN                                 CurrWritePtr;\r
+  UINT8                                 *CurrBuffer;\r
+  EFI_LBA                               LbaNumber;\r
+  UINTN                                 Size;\r
+  FRAMEWORK_EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
+  VARIABLE_STORE_HEADER                 *VolatileBase;\r
+  EFI_PHYSICAL_ADDRESS                  FvVolHdr;\r
+  EFI_PHYSICAL_ADDRESS                  DataPtr;\r
+  EFI_STATUS                            Status;\r
+\r
+  FwVolHeader = NULL;\r
+  DataPtr     = DataPtrIndex;\r
+\r
+  //\r
+  // Check if the Data is Volatile\r
+  //\r
+  if (!Volatile) {\r
+    EfiFvbGetPhysicalAddress (Instance, &FvVolHdr);\r
+    FwVolHeader = (FRAMEWORK_EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);\r
+    //\r
+    // Data Pointer should point to the actual Address where data is to be\r
+    // written\r
+    //\r
+    if (SetByIndex) {\r
+      DataPtr += Global->NonVolatileVariableBase;\r
+    }\r
+\r
+    if ((DataPtr + DataSize) >= ((EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) FwVolHeader + FwVolHeader->FvLength))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } else {\r
+    //\r
+    // Data Pointer should point to the actual Address where data is to be\r
+    // written\r
+    //\r
+    VolatileBase = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
+    if (SetByIndex) {\r
+      DataPtr += Global->VolatileVariableBase;\r
+    }\r
+\r
+    if ((DataPtr + DataSize) >= ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // If Volatile Variable just do a simple mem copy.\r
+  //\r
+  if (Volatile) {\r
+    CopyMem ((UINT8 *) ((UINTN) DataPtr), Buffer, DataSize);\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // If we are here we are dealing with Non-Volatile Variables\r
+  //\r
+  LinearOffset  = (UINTN) FwVolHeader;\r
+  CurrWritePtr  = (UINTN) DataPtr;\r
+  CurrWriteSize = DataSize;\r
+  CurrBuffer    = Buffer;\r
+  LbaNumber     = 0;\r
+\r
+  if (CurrWritePtr < LinearOffset) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  for (PtrBlockMapEntry = FwVolHeader->FvBlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
+    for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {\r
+      //\r
+      // Check to see if the Variable Writes are spanning through multiple\r
+      // blocks.\r
+      //\r
+      if ((CurrWritePtr >= LinearOffset) && (CurrWritePtr < LinearOffset + PtrBlockMapEntry->Length)) {\r
+        if ((CurrWritePtr + CurrWriteSize) <= (LinearOffset + PtrBlockMapEntry->Length)) {\r
+          Status = EfiFvbWriteBlock (\r
+                    Instance,\r
+                    LbaNumber,\r
+                    (UINTN) (CurrWritePtr - LinearOffset),\r
+                    &CurrWriteSize,\r
+                    CurrBuffer\r
+                    );\r
+          if (EFI_ERROR (Status)) {\r
+            return Status;\r
+          }\r
+        } else {\r
+          Size = (UINT32) (LinearOffset + PtrBlockMapEntry->Length - CurrWritePtr);\r
+          Status = EfiFvbWriteBlock (\r
+                    Instance,\r
+                    LbaNumber,\r
+                    (UINTN) (CurrWritePtr - LinearOffset),\r
+                    &Size,\r
+                    CurrBuffer\r
+                    );\r
+          if (EFI_ERROR (Status)) {\r
+            return Status;\r
+          }\r
+\r
+          CurrWritePtr  = LinearOffset + PtrBlockMapEntry->Length;\r
+          CurrBuffer    = CurrBuffer + Size;\r
+          CurrWriteSize = CurrWriteSize - Size;\r
+        }\r
+      }\r
+\r
+      LinearOffset += PtrBlockMapEntry->Length;\r
+      LbaNumber++;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+VARIABLE_STORE_STATUS\r
+EFIAPI\r
+GetVariableStoreStatus (\r
+  IN VARIABLE_STORE_HEADER *VarStoreHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code gets the current status of Variable Store.\r
+\r
+Arguments:\r
+\r
+  VarStoreHeader  Pointer to the Variable Store Header.\r
+\r
+Returns:\r
+\r
+  EfiRaw        Variable store status is raw\r
+  EfiValid      Variable store status is valid\r
+  EfiInvalid    Variable store status is invalid\r
+\r
+--*/\r
+{\r
+  if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
+      VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
+      VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
+      ) {\r
+\r
+    return EfiValid;\r
+  } else if (VarStoreHeader->Signature == 0xffffffff &&\r
+           VarStoreHeader->Size == 0xffffffff &&\r
+           VarStoreHeader->Format == 0xff &&\r
+           VarStoreHeader->State == 0xff\r
+          ) {\r
+\r
+    return EfiRaw;\r
+  } else {\r
+    return EfiInvalid;\r
+  }\r
+}\r
+\r
+STATIC\r
+UINT8 *\r
+EFIAPI\r
+GetVariableDataPtr (\r
+  IN  VARIABLE_HEADER   *Variable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code gets the pointer to the variable data.\r
+\r
+Arguments:\r
+\r
+  Variable            Pointer to the Variable Header.\r
+\r
+Returns:\r
+\r
+  UINT8*              Pointer to Variable Data\r
+\r
+--*/\r
+{\r
+  //\r
+  // Be careful about pad size for alignment\r
+  //\r
+  return (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (Variable) + Variable->NameSize + GET_PAD_SIZE (Variable->NameSize));\r
+}\r
+\r
+STATIC\r
+VARIABLE_HEADER *\r
+EFIAPI\r
+GetNextVariablePtr (\r
+  IN  VARIABLE_HEADER   *Variable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code gets the pointer to the next variable header.\r
+\r
+Arguments:\r
+\r
+  Variable              Pointer to the Variable Header.\r
+\r
+Returns:\r
+\r
+  VARIABLE_HEADER*      Pointer to next variable header.\r
+\r
+--*/\r
+{\r
+  if (!IsValidVariableHeader (Variable)) {\r
+    return NULL;\r
+  }\r
+  //\r
+  // Be careful about pad size for alignment\r
+  //\r
+  return (VARIABLE_HEADER *) ((UINTN) GetVariableDataPtr (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));\r
+}\r
+\r
+STATIC\r
+VARIABLE_HEADER *\r
+EFIAPI\r
+GetEndPointer (\r
+  IN VARIABLE_STORE_HEADER       *VarStoreHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code gets the pointer to the last variable memory pointer byte\r
+\r
+Arguments:\r
+\r
+  VarStoreHeader        Pointer to the Variable Store Header.\r
+\r
+Returns:\r
+\r
+  VARIABLE_HEADER*      Pointer to last unavailable Variable Header\r
+\r
+--*/\r
+{\r
+  //\r
+  // The end of variable store\r
+  //\r
+  return (VARIABLE_HEADER *) ((UINTN) VarStoreHeader + VarStoreHeader->Size);\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+Reclaim (\r
+  IN  EFI_PHYSICAL_ADDRESS  VariableBase,\r
+  OUT UINTN                 *LastVariableOffset,\r
+  IN  BOOLEAN               IsVolatile\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Variable store garbage collection and reclaim operation\r
+\r
+Arguments:\r
+\r
+  VariableBase                Base address of variable store\r
+  LastVariableOffset          Offset of last variable\r
+  IsVolatile                  The variable store is volatile or not,\r
+                              if it is non-volatile, need FTW\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+\r
+--*/\r
+{\r
+  VARIABLE_HEADER       *Variable;\r
+  VARIABLE_HEADER       *NextVariable;\r
+  VARIABLE_STORE_HEADER *VariableStoreHeader;\r
+  UINT8                 *ValidBuffer;\r
+  UINTN                 ValidBufferSize;\r
+  UINTN                 VariableSize;\r
+  UINT8                 *CurrPtr;\r
+  EFI_STATUS            Status;\r
+\r
+  VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) VariableBase);\r
+\r
+  //\r
+  // Start Pointers for the variable.\r
+  //\r
+  Variable        = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
+\r
+  ValidBufferSize = sizeof (VARIABLE_STORE_HEADER);\r
+\r
+  while (IsValidVariableHeader (Variable)) {\r
+    NextVariable = GetNextVariablePtr (Variable);\r
+    if (Variable->State == VAR_ADDED) {\r
+      VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
+      ValidBufferSize += VariableSize;\r
+    }\r
+\r
+    Variable = NextVariable;\r
+  }\r
+\r
+  ValidBuffer = AllocatePool (ValidBufferSize);\r
+  if (ValidBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  SetMem (ValidBuffer, ValidBufferSize, 0xff);\r
+\r
+  CurrPtr = ValidBuffer;\r
+\r
+  //\r
+  // Copy variable store header\r
+  //\r
+  CopyMem (CurrPtr, VariableStoreHeader, sizeof (VARIABLE_STORE_HEADER));\r
+  CurrPtr += sizeof (VARIABLE_STORE_HEADER);\r
+\r
+  //\r
+  // Start Pointers for the variable.\r
+  //\r
+  Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
+\r
+  while (IsValidVariableHeader (Variable)) {\r
+    NextVariable = GetNextVariablePtr (Variable);\r
+    if (Variable->State == VAR_ADDED) {\r
+      VariableSize = (UINTN) NextVariable - (UINTN) Variable;\r
+      CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize);\r
+      CurrPtr += VariableSize;\r
+    }\r
+\r
+    Variable = NextVariable;\r
+  }\r
+\r
+  if (IsVolatile) {\r
+    //\r
+    // If volatile variable store, just copy valid buffer\r
+    //\r
+    SetMem ((UINT8 *) (UINTN) VariableBase, VariableStoreHeader->Size, 0xff);\r
+    CopyMem ((UINT8 *) (UINTN) VariableBase, ValidBuffer, ValidBufferSize);\r
+    *LastVariableOffset = ValidBufferSize;\r
+    Status              = EFI_SUCCESS;\r
+  } else {\r
+    //\r
+    // If non-volatile variable store, perform FTW here.\r
+    //\r
+    Status = FtwVariableSpace (\r
+              VariableBase,\r
+              ValidBuffer,\r
+              ValidBufferSize\r
+              );\r
+    if (!EFI_ERROR (Status)) {\r
+      *LastVariableOffset = ValidBufferSize;\r
+    }\r
+  }\r
+\r
+  FreePool (ValidBuffer);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    *LastVariableOffset = 0;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+FindVariable (\r
+  IN  CHAR16                  *VariableName,\r
+  IN  EFI_GUID                *VendorGuid,\r
+  OUT VARIABLE_POINTER_TRACK  *PtrTrack,\r
+  IN  VARIABLE_GLOBAL         *Global\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code finds variable in storage blocks (Volatile or Non-Volatile)\r
+\r
+Arguments:\r
+\r
+  VariableName                Name of the variable to be found\r
+  VendorGuid                  Vendor GUID to be found.\r
+  PtrTrack                    Variable Track Pointer structure that contains\r
+                              Variable Information.\r
+                              Contains the pointer of Variable header.\r
+  Global                      VARIABLE_GLOBAL pointer\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+\r
+--*/\r
+{\r
+  VARIABLE_HEADER       *Variable[2];\r
+  VARIABLE_STORE_HEADER *VariableStoreHeader[2];\r
+  UINTN                 Index;\r
+\r
+  //\r
+  // We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName\r
+  // SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to\r
+  // the correct places if this assumption does not hold TRUE anymore.\r
+  //\r
+  AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\r
+\r
+  //\r
+  // 0: Non-Volatile, 1: Volatile\r
+  //\r
+  VariableStoreHeader[0]  = (VARIABLE_STORE_HEADER *) ((UINTN) Global->NonVolatileVariableBase);\r
+  VariableStoreHeader[1]  = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
+\r
+  //\r
+  // Start Pointers for the variable.\r
+  // Actual Data Pointer where data can be written.\r
+  //\r
+  Variable[0] = (VARIABLE_HEADER *) (VariableStoreHeader[0] + 1);\r
+  Variable[1] = (VARIABLE_HEADER *) (VariableStoreHeader[1] + 1);\r
+\r
+  if (VariableName[0] != 0 && VendorGuid == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Find the variable by walk through non-volatile and volatile variable store\r
+  //\r
+  for (Index = 0; Index < 2; Index++) {\r
+    PtrTrack->StartPtr  = (VARIABLE_HEADER *) (VariableStoreHeader[Index] + 1);\r
+    PtrTrack->EndPtr    = GetEndPointer (VariableStoreHeader[Index]);\r
+\r
+    while (IsValidVariableHeader (Variable[Index]) && (Variable[Index] <= GetEndPointer (VariableStoreHeader[Index]))) {\r
+      if (Variable[Index]->State == VAR_ADDED) {\r
+        if (!(EfiAtRuntime () && !(Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
+          if (VariableName[0] == 0) {\r
+            PtrTrack->CurrPtr   = Variable[Index];\r
+            PtrTrack->Volatile  = (BOOLEAN) Index;\r
+            return EFI_SUCCESS;\r
+          } else {\r
+            if (CompareGuid (VendorGuid, &Variable[Index]->VendorGuid)) {\r
+              if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable[Index]), Variable[Index]->NameSize)) {\r
+                PtrTrack->CurrPtr   = Variable[Index];\r
+                PtrTrack->Volatile  = (BOOLEAN) Index;\r
+                return EFI_SUCCESS;\r
+              }\r
+            }\r
+          }\r
+        }\r
+      }\r
+\r
+      Variable[Index] = GetNextVariablePtr (Variable[Index]);\r
+    }\r
+    //\r
+    // While (...)\r
+    //\r
+  }\r
+  //\r
+  // for (...)\r
+  //\r
+  PtrTrack->CurrPtr = NULL;\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetVariable (\r
+  IN      CHAR16            *VariableName,\r
+  IN      EFI_GUID          * VendorGuid,\r
+  OUT     UINT32            *Attributes OPTIONAL,\r
+  IN OUT  UINTN             *DataSize,\r
+  OUT     VOID              *Data,\r
+  IN      VARIABLE_GLOBAL   * Global,\r
+  IN      UINT32            Instance\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code finds variable in storage blocks (Volatile or Non-Volatile)\r
+\r
+Arguments:\r
+\r
+  VariableName                    Name of Variable to be found\r
+  VendorGuid                      Variable vendor GUID\r
+  Attributes OPTIONAL             Attribute value of the variable found\r
+  DataSize                        Size of Data found. If size is less than the\r
+                                  data, this value contains the required size.\r
+  Data                            Data pointer\r
+  Global                          Pointer to VARIABLE_GLOBAL structure\r
+  Instance                        Instance of the Firmware Volume.\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+\r
+--*/\r
+{\r
+  VARIABLE_POINTER_TRACK  Variable;\r
+  UINTN                   VarDataSize;\r
+  EFI_STATUS              Status;\r
+\r
+  if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Find existing variable\r
+  //\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
+\r
+  if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Get data size\r
+  //\r
+  VarDataSize = Variable.CurrPtr->DataSize;\r
+  if (*DataSize >= VarDataSize) {\r
+    if (Data == NULL) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
+\r
+    CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);\r
+    if (Attributes != NULL) {\r
+      *Attributes = Variable.CurrPtr->Attributes;\r
+    }\r
+\r
+    *DataSize = VarDataSize;\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  } else {\r
+    *DataSize = VarDataSize;\r
+    Status = EFI_BUFFER_TOO_SMALL;\r
+    goto Done;\r
+  }\r
+\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextVariableName (\r
+  IN OUT  UINTN             *VariableNameSize,\r
+  IN OUT  CHAR16            *VariableName,\r
+  IN OUT  EFI_GUID          *VendorGuid,\r
+  IN      VARIABLE_GLOBAL   *Global,\r
+  IN      UINT32            Instance\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code Finds the Next available variable\r
+\r
+Arguments:\r
+\r
+  VariableNameSize            Size of the variable\r
+  VariableName                Pointer to variable name\r
+  VendorGuid                  Variable Vendor Guid\r
+  Global                      VARIABLE_GLOBAL structure pointer.\r
+  Instance                    FV instance\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+\r
+--*/\r
+{\r
+  VARIABLE_POINTER_TRACK  Variable;\r
+  UINTN                   VarNameSize;\r
+  EFI_STATUS              Status;\r
+\r
+  if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
+\r
+  if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  if (VariableName[0] != 0) {\r
+    //\r
+    // If variable name is not NULL, get next variable\r
+    //\r
+    Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
+  }\r
+\r
+  while (TRUE) {\r
+    //\r
+    // If both volatile and non-volatile variable store are parsed,\r
+    // return not found\r
+    //\r
+    if (Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL) {\r
+      Variable.Volatile = (BOOLEAN) (Variable.Volatile ^ ((BOOLEAN) 0x1));\r
+      if (Variable.Volatile) {\r
+        Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER)));\r
+        Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase));\r
+      } else {\r
+        Status = EFI_NOT_FOUND;\r
+        goto Done;\r
+      }\r
+\r
+      Variable.CurrPtr = Variable.StartPtr;\r
+      if (!IsValidVariableHeader (Variable.CurrPtr)) {\r
+        continue;\r
+      }\r
+    }\r
+    //\r
+    // Variable is found\r
+    //\r
+    if (IsValidVariableHeader (Variable.CurrPtr) && Variable.CurrPtr->State == VAR_ADDED) {\r
+      if (!(EfiAtRuntime () && !(Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
+        VarNameSize = Variable.CurrPtr->NameSize;\r
+        if (VarNameSize <= *VariableNameSize) {\r
+          CopyMem (\r
+            VariableName,\r
+            GET_VARIABLE_NAME_PTR (Variable.CurrPtr),\r
+            VarNameSize\r
+            );\r
+          CopyMem (\r
+            VendorGuid,\r
+            &Variable.CurrPtr->VendorGuid,\r
+            sizeof (EFI_GUID)\r
+            );\r
+          Status = EFI_SUCCESS;\r
+        } else {\r
+          Status = EFI_BUFFER_TOO_SMALL;\r
+        }\r
+\r
+        *VariableNameSize = VarNameSize;\r
+        goto Done;\r
+      }\r
+    }\r
+\r
+    Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);\r
+  }\r
+\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SetVariable (\r
+  IN CHAR16                  *VariableName,\r
+  IN EFI_GUID                *VendorGuid,\r
+  IN UINT32                  Attributes,\r
+  IN UINTN                   DataSize,\r
+  IN VOID                    *Data,\r
+  IN VARIABLE_GLOBAL         *Global,\r
+  IN UINTN                   *VolatileOffset,\r
+  IN UINTN                   *NonVolatileOffset,\r
+  IN UINT32                  Instance\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code sets variable in storage blocks (Volatile or Non-Volatile)\r
+\r
+Arguments:\r
+\r
+  VariableName                    Name of Variable to be found\r
+  VendorGuid                      Variable vendor GUID\r
+  Attributes                      Attribute value of the variable found\r
+  DataSize                        Size of Data found. If size is less than the\r
+                                  data, this value contains the required size.\r
+  Data                            Data pointer\r
+  Global                          Pointer to VARIABLE_GLOBAL structure\r
+  VolatileOffset                  The offset of last volatile variable\r
+  NonVolatileOffset               The offset of last non-volatile variable\r
+  Instance                        Instance of the Firmware Volume.\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+  EFI_INVALID_PARAMETER           - Invalid parameter\r
+  EFI_SUCCESS                     - Set successfully\r
+  EFI_OUT_OF_RESOURCES            - Resource not enough to set variable\r
+  EFI_NOT_FOUND                   - Not found\r
+\r
+--*/\r
+{\r
+  VARIABLE_POINTER_TRACK  Variable;\r
+  EFI_STATUS              Status;\r
+  VARIABLE_HEADER         *NextVariable;\r
+  UINTN                   VarNameSize;\r
+  UINTN                   VarNameOffset;\r
+  UINTN                   VarDataOffset;\r
+  UINTN                   VarSize;\r
+  UINT8                   State;\r
+  BOOLEAN                 Reclaimed;\r
+\r
+  Reclaimed = FALSE;\r
+\r
+  if (VariableName == NULL || VariableName[0] == 0 || VendorGuid == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, Global);\r
+\r
+  if (Status == EFI_INVALID_PARAMETER) {\r
+    goto Done;\r
+  } else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) {\r
+    //\r
+    // If EfiAtRuntime and the variable is Volatile and Runtime Access,\r
+    // the volatile is ReadOnly, and SetVariable should be aborted and\r
+    // return EFI_WRITE_PROTECTED.\r
+    //\r
+    Status = EFI_WRITE_PROTECTED;\r
+    goto Done;\r
+  } else if (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > MAX_VARIABLE_SIZE) {\r
+    //\r
+    //  The size of the VariableName, including the Unicode Null in bytes plus\r
+    //  the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  } else if (Attributes == EFI_VARIABLE_NON_VOLATILE) {\r
+    //\r
+    //  Make sure not only EFI_VARIABLE_NON_VOLATILE is set\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) ==\r
+                EFI_VARIABLE_RUNTIME_ACCESS) {\r
+    //\r
+    //  Make sure if runtime bit is set, boot service bit is set also\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+    //\r
+    // Runtime but Attribute is not Runtime\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
+    //\r
+    // Cannot set volatile variable in Runtime\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  } else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
+    //\r
+    // Setting a data variable with no access, or zero DataSize attributes\r
+    // specified causes it to be deleted.\r
+    //\r
+    if (!EFI_ERROR (Status)) {\r
+      State = Variable.CurrPtr->State;\r
+      State &= VAR_DELETED;\r
+\r
+      Status = UpdateVariableStore (\r
+                Global,\r
+                Variable.Volatile,\r
+                FALSE,\r
+                Instance,\r
+                (UINTN) &Variable.CurrPtr->State,\r
+                sizeof (UINT8),\r
+                &State\r
+                );\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+\r
+      Status = EFI_SUCCESS;\r
+      goto Done;\r
+    }\r
+\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
+  } else {\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // If the variable is marked valid and the same data has been passed in\r
+      // then return to the caller immediately.\r
+      //\r
+      if (Variable.CurrPtr->DataSize == DataSize &&\r
+          !CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize)\r
+            ) {\r
+        Status = EFI_SUCCESS;\r
+        goto Done;\r
+      } else if (Variable.CurrPtr->State == VAR_ADDED) {\r
+        //\r
+        // Mark the old variable as in delete transition\r
+        //\r
+        State = Variable.CurrPtr->State;\r
+        State &= VAR_IN_DELETED_TRANSITION;\r
+\r
+        Status = UpdateVariableStore (\r
+                  Global,\r
+                  Variable.Volatile,\r
+                  FALSE,\r
+                  Instance,\r
+                  (UINTN) &Variable.CurrPtr->State,\r
+                  sizeof (UINT8),\r
+                  &State\r
+                  );\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+      }\r
+    }\r
+    //\r
+    // Create a new variable and copy the data.\r
+    //\r
+    // Tricky part: Use scratch data area at the end of volatile variable store\r
+    // as a temporary storage.\r
+    //\r
+    NextVariable = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase));\r
+\r
+    SetMem (NextVariable, SCRATCH_SIZE, 0xff);\r
+\r
+    NextVariable->StartId     = VARIABLE_DATA;\r
+    NextVariable->Attributes  = Attributes;\r
+    //\r
+    // NextVariable->State = VAR_ADDED;\r
+    //\r
+    NextVariable->Reserved  = 0;\r
+    VarNameOffset           = sizeof (VARIABLE_HEADER);\r
+    VarNameSize             = StrSize (VariableName);\r
+    CopyMem (\r
+      (UINT8 *) ((UINTN) NextVariable + VarNameOffset),\r
+      VariableName,\r
+      VarNameSize\r
+      );\r
+    VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);\r
+    CopyMem (\r
+      (UINT8 *) ((UINTN) NextVariable + VarDataOffset),\r
+      Data,\r
+      DataSize\r
+      );\r
+    CopyMem (&NextVariable->VendorGuid, VendorGuid, sizeof (EFI_GUID));\r
+    //\r
+    // There will be pad bytes after Data, the NextVariable->NameSize and\r
+    // NextVariable->DataSize should not include pad size so that variable\r
+    // service can get actual size in GetVariable\r
+    //\r
+    NextVariable->NameSize  = (UINT32)VarNameSize;\r
+    NextVariable->DataSize  = (UINT32)DataSize;\r
+\r
+    //\r
+    // The actual size of the variable that stores in storage should\r
+    // include pad size.\r
+    //\r
+    VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
+    if (Attributes & EFI_VARIABLE_NON_VOLATILE) {\r
+      if ((UINT32) (VarSize +*NonVolatileOffset) >\r
+            ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size\r
+            ) {\r
+        if (EfiAtRuntime ()) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Done;\r
+        }\r
+        //\r
+        // Perform garbage collection & reclaim operation\r
+        //\r
+        Status = Reclaim (Global->NonVolatileVariableBase, NonVolatileOffset, FALSE);\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+        //\r
+        // If still no enough space, return out of resources\r
+        //\r
+        if ((UINT32) (VarSize +*NonVolatileOffset) >\r
+              ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size\r
+              ) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Done;\r
+        }\r
+\r
+        Reclaimed = TRUE;\r
+      }\r
+      //\r
+      // Three steps\r
+      // 1. Write variable header\r
+      // 2. Write variable data\r
+      // 3. Set variable state to valid\r
+      //\r
+      //\r
+      // Step 1:\r
+      //\r
+      Status = UpdateVariableStore (\r
+                Global,\r
+                FALSE,\r
+                TRUE,\r
+                Instance,\r
+                *NonVolatileOffset,\r
+                sizeof (VARIABLE_HEADER),\r
+                (UINT8 *) NextVariable\r
+                );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+      //\r
+      // Step 2:\r
+      //\r
+      Status = UpdateVariableStore (\r
+                Global,\r
+                FALSE,\r
+                TRUE,\r
+                Instance,\r
+                *NonVolatileOffset + sizeof (VARIABLE_HEADER),\r
+                (UINT32) VarSize - sizeof (VARIABLE_HEADER),\r
+                (UINT8 *) NextVariable + sizeof (VARIABLE_HEADER)\r
+                );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+      //\r
+      // Step 3:\r
+      //\r
+      NextVariable->State = VAR_ADDED;\r
+      Status = UpdateVariableStore (\r
+                Global,\r
+                FALSE,\r
+                TRUE,\r
+                Instance,\r
+                *NonVolatileOffset,\r
+                sizeof (VARIABLE_HEADER),\r
+                (UINT8 *) NextVariable\r
+                );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+\r
+      *NonVolatileOffset = *NonVolatileOffset + VarSize;\r
+\r
+    } else {\r
+      if (EfiAtRuntime ()) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+        goto Done;\r
+      }\r
+\r
+      if ((UINT32) (VarSize +*VolatileOffset) >\r
+            ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size\r
+            ) {\r
+        //\r
+        // Perform garbage collection & reclaim operation\r
+        //\r
+        Status = Reclaim (Global->VolatileVariableBase, VolatileOffset, TRUE);\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+        //\r
+        // If still no enough space, return out of resources\r
+        //\r
+        if ((UINT32) (VarSize +*VolatileOffset) >\r
+              ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size\r
+              ) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Done;\r
+        }\r
+\r
+        Reclaimed = TRUE;\r
+      }\r
+\r
+      NextVariable->State = VAR_ADDED;\r
+      Status = UpdateVariableStore (\r
+                Global,\r
+                TRUE,\r
+                TRUE,\r
+                Instance,\r
+                *VolatileOffset,\r
+                (UINT32) VarSize,\r
+                (UINT8 *) NextVariable\r
+                );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+\r
+      *VolatileOffset = *VolatileOffset + VarSize;\r
+    }\r
+    //\r
+    // Mark the old variable as deleted\r
+    //\r
+    if (!Reclaimed && !EFI_ERROR (Status) && Variable.CurrPtr != NULL) {\r
+      State = Variable.CurrPtr->State;\r
+      State &= VAR_DELETED;\r
+\r
+      Status = UpdateVariableStore (\r
+                Global,\r
+                Variable.Volatile,\r
+                FALSE,\r
+                Instance,\r
+                (UINTN) &Variable.CurrPtr->State,\r
+                sizeof (UINT8),\r
+                &State\r
+                );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+    }\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+QueryVariableInfo (\r
+  IN  UINT32                 Attributes,\r
+  OUT UINT64                 *MaximumVariableStorageSize,\r
+  OUT UINT64                 *RemainingVariableStorageSize,\r
+  OUT UINT64                 *MaximumVariableSize,\r
+  IN  VARIABLE_GLOBAL        *Global,\r
+  IN  UINT32                 Instance\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This code returns information about the EFI variables.\r
+\r
+Arguments:\r
+\r
+  Attributes                      Attributes bitmask to specify the type of variables\r
+                                  on which to return information.\r
+  MaximumVariableStorageSize      Pointer to the maximum size of the storage space available\r
+                                  for the EFI variables associated with the attributes specified.\r
+  RemainingVariableStorageSize    Pointer to the remaining size of the storage space available\r
+                                  for the EFI variables associated with the attributes specified.\r
+  MaximumVariableSize             Pointer to the maximum size of the individual EFI variables\r
+                                  associated with the attributes specified.\r
+  Global                          Pointer to VARIABLE_GLOBAL structure.\r
+  Instance                        Instance of the Firmware Volume.\r
+\r
+Returns:\r
+\r
+  EFI STATUS\r
+  EFI_INVALID_PARAMETER           - An invalid combination of attribute bits was supplied.\r
+  EFI_SUCCESS                     - Query successfully.\r
+  EFI_UNSUPPORTED                 - The attribute is not supported on this platform.\r
+\r
+--*/\r
+{\r
+  VARIABLE_HEADER        *Variable;\r
+  VARIABLE_HEADER        *NextVariable;\r
+  UINT64                 VariableSize;\r
+  VARIABLE_STORE_HEADER  *VariableStoreHeader;\r
+\r
+  if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)) == 0) {\r
+    //\r
+    // Make sure the Attributes combination is supported by the platform.\r
+    //\r
+    return EFI_UNSUPPORTED;\r
+  } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
+    //\r
+    // Make sure if runtime bit is set, boot service bit is set also.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  } else if (EfiAtRuntime () && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+    //\r
+    // Make sure RT Attribute is set if we are in Runtime phase.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);\r
+\r
+  if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
+    //\r
+    // Query is Volatile related.\r
+    //\r
+    VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase);\r
+  } else {\r
+    //\r
+    // Query is Non-Volatile related.\r
+    //\r
+    VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) Global->NonVolatileVariableBase);\r
+  }\r
+\r
+  //\r
+  // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize\r
+  // with the storage size (excluding the storage header size).\r
+  //\r
+  *MaximumVariableStorageSize   = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
+  *RemainingVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
+\r
+  //\r
+  // Let *MaximumVariableSize be MAX_VARIABLE_SIZE.\r
+  //\r
+  *MaximumVariableSize = MAX_VARIABLE_SIZE;\r
+\r
+  //\r
+  // Point to the starting address of the variables.\r
+  //\r
+  Variable = (VARIABLE_HEADER *) (VariableStoreHeader + 1);\r
+\r
+  //\r
+  // Now walk through the related variable store.\r
+  //\r
+  while (IsValidVariableHeader (Variable) && (Variable < GetEndPointer (VariableStoreHeader))) {\r
+    NextVariable = GetNextVariablePtr (Variable);\r
+    VariableSize = (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Variable;\r
+\r
+    if (EfiAtRuntime ()) {\r
+      //\r
+      // we don't take the state of the variables in mind\r
+      // when calculating RemainingVariableStorageSize,\r
+      // since the space occupied by variables not marked with\r
+      // VAR_ADDED is not allowed to be reclaimed in Runtime.\r
+      //\r
+      *RemainingVariableStorageSize -= VariableSize;\r
+    } else {\r
+      //\r
+      // Only care about Variables with State VAR_ADDED,because\r
+      // the space not marked as VAR_ADDED is reclaimable now.\r
+      //\r
+      if (Variable->State == VAR_ADDED) {\r
+        *RemainingVariableStorageSize -= VariableSize;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Go to the next one\r
+    //\r
+    Variable = NextVariable;\r
+  }\r
+\r
+  ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VariableCommonInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This function does common initialization for variable services\r
+\r
+Arguments:\r
+\r
+  ImageHandle   - The firmware allocated handle for the EFI image.\r
+  SystemTable   - A pointer to the EFI System Table.\r
+\r
+Returns:\r
+\r
+  Status code.\r
+\r
+  EFI_NOT_FOUND     - Variable store area not found.\r
+  EFI_UNSUPPORTED   - Currently only one non-volatile variable store is supported.\r
+  EFI_SUCCESS       - Variable services successfully initialized.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_FIRMWARE_VOLUME_HEADER      *FwVolHeader;\r
+  CHAR8                           *CurrPtr;\r
+  VARIABLE_STORE_HEADER           *VolatileVariableStore;\r
+  VARIABLE_STORE_HEADER           *VariableStoreHeader;\r
+  VARIABLE_HEADER                 *NextVariable;\r
+  UINT32                          Instance;\r
+  EFI_PHYSICAL_ADDRESS            FvVolHdr;\r
+\r
+  UINT64                          TempVariableStoreHeader;\r
+\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;\r
+  EFI_FLASH_SUBAREA_ENTRY         VariableStoreEntry;\r
+  UINT64                          BaseAddress;\r
+  UINT64                          Length;\r
+  UINTN                           Index;\r
+  UINT8                           Data;\r
+\r
+  mVariableModuleGlobal = AllocateRuntimePool (sizeof (ESAL_VARIABLE_GLOBAL));\r
+  if (mVariableModuleGlobal == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, TPL_NOTIFY);\r
+\r
+  //\r
+  // Allocate memory for volatile variable store\r
+  //\r
+  VolatileVariableStore = AllocateRuntimePool (VARIABLE_STORE_SIZE + SCRATCH_SIZE);\r
+  if (VolatileVariableStore == NULL) {\r
+    FreePool (mVariableModuleGlobal);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  SetMem (VolatileVariableStore, VARIABLE_STORE_SIZE + SCRATCH_SIZE, 0xff);\r
+\r
+  //\r
+  //  Variable Specific Data\r
+  //\r
+  mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;\r
+  mVariableModuleGlobal->VolatileLastVariableOffset = sizeof (VARIABLE_STORE_HEADER);\r
+\r
+  VolatileVariableStore->Signature                  = VARIABLE_STORE_SIGNATURE;\r
+  VolatileVariableStore->Size                       = VARIABLE_STORE_SIZE;\r
+  VolatileVariableStore->Format                     = VARIABLE_STORE_FORMATTED;\r
+  VolatileVariableStore->State                      = VARIABLE_STORE_HEALTHY;\r
+  VolatileVariableStore->Reserved                   = 0;\r
+  VolatileVariableStore->Reserved1                  = 0;\r
+\r
+  //\r
+  // Get non volatile varaible store\r
+  //\r
+\r
+  TempVariableStoreHeader = (UINT64) PcdGet32 (PcdFlashNvStorageVariableBase);\r
+  VariableStoreEntry.Base = TempVariableStoreHeader + \\r
+                              (((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
+  VariableStoreEntry.Length = (UINT64) PcdGet32 (PcdFlashNvStorageVariableSize) - \\r
+                                (((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (TempVariableStoreHeader)) -> HeaderLength);\r
+  //\r
+  // Mark the variable storage region of the FLASH as RUNTIME\r
+  //\r
+  BaseAddress = VariableStoreEntry.Base & (~EFI_PAGE_MASK);\r
+  Length      = VariableStoreEntry.Length + (VariableStoreEntry.Base - BaseAddress);\r
+  Length      = (Length + EFI_PAGE_SIZE - 1) & (~EFI_PAGE_MASK);\r
+\r
+  Status      = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (mVariableModuleGlobal);\r
+    FreePool (VolatileVariableStore);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (\r
+                  BaseAddress,\r
+                  Length,\r
+                  GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (mVariableModuleGlobal);\r
+    FreePool (VolatileVariableStore);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get address of non volatile variable store base\r
+  //\r
+  mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase = VariableStoreEntry.Base;\r
+\r
+  //\r
+  // Check Integrity\r
+  //\r
+  //\r
+  // Find the Correct Instance of the FV Block Service.\r
+  //\r
+  Instance  = 0;\r
+  CurrPtr   = (CHAR8 *) ((UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase);\r
+  while (EfiFvbGetPhysicalAddress (Instance, &FvVolHdr) == EFI_SUCCESS) {\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);\r
+    if (CurrPtr >= (CHAR8 *) FwVolHeader && CurrPtr < (((CHAR8 *) FwVolHeader) + FwVolHeader->FvLength)) {\r
+      mVariableModuleGlobal->FvbInstance = Instance;\r
+      break;\r
+    }\r
+\r
+    Instance++;\r
+  }\r
+\r
+  VariableStoreHeader = (VARIABLE_STORE_HEADER *) CurrPtr;\r
+  if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {\r
+    if (~VariableStoreHeader->Size == 0) {\r
+      Status = UpdateVariableStore (\r
+                &mVariableModuleGlobal->VariableGlobal[Physical],\r
+                FALSE,\r
+                FALSE,\r
+                mVariableModuleGlobal->FvbInstance,\r
+                (UINTN) &VariableStoreHeader->Size,\r
+                sizeof (UINT32),\r
+                (UINT8 *) &VariableStoreEntry.Length\r
+                );\r
+      //\r
+      // As Variables are stored in NV storage, which are slow devices,such as flash.\r
+      // Variable operation may skip checking variable program result to improve performance,\r
+      // We can assume Variable program is OK through some check point.\r
+      // Variable Store Size Setting should be the first Variable write operation,\r
+      // We can assume all Read/Write is OK if we can set Variable store size successfully.\r
+      // If write fail, we will assert here\r
+      //\r
+      ASSERT(VariableStoreHeader->Size == VariableStoreEntry.Length);\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) CurrPtr);\r
+    //\r
+    // Parse non-volatile variable data and get last variable offset\r
+    //\r
+    NextVariable  = (VARIABLE_HEADER *) (CurrPtr + sizeof (VARIABLE_STORE_HEADER));\r
+    Status        = EFI_SUCCESS;\r
+\r
+    while (IsValidVariableHeader (NextVariable)) {\r
+      NextVariable = GetNextVariablePtr (NextVariable);\r
+    }\r
+\r
+    mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;\r
+\r
+    //\r
+    // Check if the free area is blow a threshold\r
+    //\r
+    if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {\r
+      Status = Reclaim (\r
+                mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
+                &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
+                FALSE\r
+                );\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (mVariableModuleGlobal);\r
+      FreePool (VolatileVariableStore);\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Check if the free area is really free.\r
+    //\r
+    for (Index = mVariableModuleGlobal->NonVolatileLastVariableOffset; Index < VariableStoreHeader->Size; Index++) {\r
+      Data = ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase)[Index];\r
+      if (Data != 0xff) {\r
+        //\r
+        // There must be something wrong in variable store, do reclaim operation.\r
+        //\r
+        Status = Reclaim (\r
+                  mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,\r
+                  &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
+                  FALSE\r
+                  );\r
+        break;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (mVariableModuleGlobal);\r
+    FreePool (VolatileVariableStore);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.dxs b/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.dxs
new file mode 100644 (file)
index 0000000..f4aa840
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. 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
+Module Name:\r
+\r
+  Ia32Variable.dxs\r
+\r
+Abstract:\r
+\r
+  Dependency expression source file.\r
+  \r
+--*/  \r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include <DxeDepex.h>\r
+\r
+DEPENDENCY_START\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID AND\r
+  EFI_ALTERNATE_FV_BLOCK_GUID             AND\r
+  EFI_FTW_LITE_PROTOCOL_GUID\r
+DEPENDENCY_END\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.h b/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.h
new file mode 100644 (file)
index 0000000..aff0b82
--- /dev/null
@@ -0,0 +1,158 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  Variable.h\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#ifndef _VARIABLE_H\r
+#define _VARIABLE_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Statements that include other header files\r
+//\r
+\r
+//\r
+// BugBug: We need relcate the head file.\r
+//\r
+#include <Common/Variable.h>\r
+\r
+#define VARIABLE_RECLAIM_THRESHOLD (1024)\r
+\r
+#define VARIABLE_STORE_SIZE (64 * 1024)\r
+#define SCRATCH_SIZE        (4 * 1024)\r
+\r
+//\r
+// Define GET_PAD_SIZE to optimize compiler\r
+//\r
+#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))\r
+#define GET_PAD_SIZE(a) (0)\r
+#else\r
+#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))\r
+#endif\r
+\r
+#define GET_VARIABLE_NAME_PTR(a)  (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))\r
+\r
+typedef enum {\r
+  Physical,\r
+  Virtual\r
+} VARIABLE_POINTER_TYPE;\r
+\r
+typedef struct {\r
+  VARIABLE_HEADER *CurrPtr;\r
+  VARIABLE_HEADER *EndPtr;\r
+  VARIABLE_HEADER *StartPtr;\r
+  BOOLEAN         Volatile;\r
+} VARIABLE_POINTER_TRACK;\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS  VolatileVariableBase;\r
+  EFI_PHYSICAL_ADDRESS  NonVolatileVariableBase;\r
+  EFI_LOCK              VariableServicesLock;\r
+} VARIABLE_GLOBAL;\r
+\r
+typedef struct {\r
+  VARIABLE_GLOBAL VariableGlobal[2];\r
+  UINTN           VolatileLastVariableOffset;\r
+  UINTN           NonVolatileLastVariableOffset;\r
+  UINT32          FvbInstance;\r
+} ESAL_VARIABLE_GLOBAL;\r
+\r
+extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
+\r
+//\r
+// Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+VariableCommonInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VariableServiceInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+VariableClassAddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetVariable (\r
+  IN      CHAR16            *VariableName,\r
+  IN      EFI_GUID          * VendorGuid,\r
+  OUT     UINT32            *Attributes OPTIONAL,\r
+  IN OUT  UINTN             *DataSize,\r
+  OUT     VOID              *Data,\r
+  IN      VARIABLE_GLOBAL   * Global,\r
+  IN      UINT32            Instance\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextVariableName (\r
+  IN OUT  UINTN             *VariableNameSize,\r
+  IN OUT  CHAR16            *VariableName,\r
+  IN OUT  EFI_GUID          *VendorGuid,\r
+  IN      VARIABLE_GLOBAL   *Global,\r
+  IN      UINT32            Instance\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SetVariable (\r
+  IN CHAR16                  *VariableName,\r
+  IN EFI_GUID                *VendorGuid,\r
+  IN UINT32                  Attributes,\r
+  IN UINTN                   DataSize,\r
+  IN VOID                    *Data,\r
+  IN VARIABLE_GLOBAL         *Global,\r
+  IN UINTN                   *VolatileOffset,\r
+  IN UINTN                   *NonVolatileOffset,\r
+  IN UINT32                  Instance\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+QueryVariableInfo (\r
+  IN  UINT32                 Attributes,\r
+  OUT UINT64                 *MaximumVariableStorageSize,\r
+  OUT UINT64                 *RemainingVariableStorageSize,\r
+  OUT UINT64                 *MaximumVariableSize,\r
+  IN  VARIABLE_GLOBAL        *Global,\r
+  IN  UINT32                 Instance\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.inf b/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.inf
new file mode 100644 (file)
index 0000000..c9d9f92
--- /dev/null
@@ -0,0 +1,123 @@
+#/** @file\r
+# Component description file for Variable module.\r
+#\r
+# This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#  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
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Variable\r
+  FILE_GUID                      = CBD2E4D5-7068-4FF5-B462-9822B4AD8D60\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = VariableServiceInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+#  VIRTUAL_ADDRESS_MAP_CALLBACK  =  VariableClassAddressChangeEvent\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  Variable.dxs\r
+  InitVariable.c\r
+  reclaim.c\r
+  reclaim.h\r
+  Variable.c\r
+  Variable.h\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  $(WORKSPACE)/IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  $(WORKSPACE)/MdePkg/MdePkg.dec\r
+  $(WORKSPACE)/MdeModulePkg/MdeModulePkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  MemoryAllocationLib\r
+  BaseLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  FvbServiceLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  UefiRuntimeLib\r
+  DxeServicesTableLib\r
+  UefiDriverEntryPoint\r
+  PcdLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiFaultTolerantWriteLiteProtocolGuid        # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiVariableWriteArchProtocolGuid             # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiVariableArchProtocolGuid                  # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+################################################################################\r
+#\r
+# Pcd DYNAMIC - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamic.common]\r
+  PcdFlashNvStorageVariableSize|gEfiGenericPlatformTokenSpaceGuid\r
+  PcdFlashNvStorageVariableBase|gEfiGenericPlatformTokenSpaceGuid\r
+\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.msa b/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.msa
new file mode 100644 (file)
index 0000000..56f19b0
--- /dev/null
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>Variable</ModuleName>\r
+    <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>\r
+    <GuidValue>CBD2E4D5-7068-4FF5-B462-9822B4AD8D60</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Variable module.</Abstract>\r
+    <Description>This module installs three EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials
+      are licensed and made available under the terms and conditions of the BSD License
+      which accompanies this distribution.  The full text of the license may be found at
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>Variable</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DxeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>EdkFvbServiceLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Variable.h</Filename>\r
+    <Filename>Variable.c</Filename>\r
+    <Filename>reclaim.h</Filename>\r
+    <Filename>reclaim.c</Filename>\r
+    <Filename>InitVariable.c</Filename>\r
+    <Filename>Variable.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiVariableArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiVariableWriteArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiFaultTolerantWriteLiteProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>VariableServiceInitialize</ModuleEntryPoint>\r
+    </Extern>\r
+    <Extern>\r
+      <SetVirtualAddressMapCallBack>VariableClassAddressChangeEvent</SetVirtualAddressMapCallBack>\r
+    </Extern>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdFlashNvStorageVariableBase</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The driver gets the Variable store base address from this PCD.  This base address point to
+        an EFI_FIRMWARE_VOLUMN_HEADER struct.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdFlashNvStorageVariableSize</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The driver gets the NvStorage Variable Size from this PCD.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/reclaim.c b/MdeModulePkg/Universal/VariableRuntimeDxe/reclaim.c
new file mode 100644 (file)
index 0000000..309d285
--- /dev/null
@@ -0,0 +1,242 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  reclaim.c\r
+\r
+Abstract:\r
+\r
+  Handles non-volatile variable store garbage collection, using FTW\r
+  (Fault Tolerant Write) protocol.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+\r
+#include "reclaim.h"\r
+#include "Common/Variable.h"\r
+\r
+EFI_STATUS\r
+GetFvbHandleByAddress (\r
+  IN  EFI_PHYSICAL_ADDRESS   Address,\r
+  OUT EFI_HANDLE             *FvbHandle\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_HANDLE                          *HandleBuffer;\r
+  UINTN                               HandleCount;\r
+  UINTN                               Index;\r
+  EFI_PHYSICAL_ADDRESS                FvbBaseAddress;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *Fvb;\r
+  EFI_FIRMWARE_VOLUME_HEADER          *FwVolHeader;\r
+\r
+  *FvbHandle = NULL;\r
+  //\r
+  // Locate all handles of Fvb protocol\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &HandleBuffer\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Get the FVB to access variable store\r
+  //\r
+  for (Index = 0; Index < HandleCount; Index += 1) {\r
+    Status = gBS->HandleProtocol (\r
+                    HandleBuffer[Index],\r
+                    &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                    (VOID **) &Fvb\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_NOT_FOUND;\r
+      break;\r
+    }\r
+    //\r
+    // Compare the address and select the right one\r
+    //\r
+    Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);\r
+    if ((Address >= FvbBaseAddress) && (Address <= (FvbBaseAddress + FwVolHeader->FvLength))) {\r
+      *FvbHandle  = HandleBuffer[Index];\r
+      Status      = EFI_SUCCESS;\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (HandleBuffer);\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetLbaAndOffsetByAddress (\r
+  IN  EFI_PHYSICAL_ADDRESS   Address,\r
+  OUT EFI_LBA                *Lba,\r
+  OUT UINTN                  *Offset\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  EFI_HANDLE                            FvbHandle;\r
+  EFI_PHYSICAL_ADDRESS                  FvbBaseAddress;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *Fvb;\r
+  FRAMEWORK_EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader;\r
+  EFI_FV_BLOCK_MAP_ENTRY                *FvbMapEntry;\r
+  UINT32                                LbaIndex;\r
+\r
+  *Lba    = (EFI_LBA) (-1);\r
+  *Offset = 0;\r
+\r
+  //\r
+  // Get the proper FVB\r
+  //\r
+  Status = GetFvbHandleByAddress (Address, &FvbHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  FvbHandle,\r
+                  &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                  (VOID **) &Fvb\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Get the Base Address of FV\r
+  //\r
+  Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  FwVolHeader = (FRAMEWORK_EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);\r
+\r
+  //\r
+  // Get the (LBA, Offset) of Address\r
+  //\r
+  if ((Address >= FvbBaseAddress) && (Address <= (FvbBaseAddress + FwVolHeader->FvLength))) {\r
+    if ((FwVolHeader->FvLength) > (FwVolHeader->HeaderLength)) {\r
+      //\r
+      // BUGBUG: Assume one FV has one type of BlockLength\r
+      //\r
+      FvbMapEntry = &FwVolHeader->FvBlockMap[0];\r
+      for (LbaIndex = 1; LbaIndex <= FvbMapEntry->NumBlocks; LbaIndex += 1) {\r
+        if (Address < (FvbBaseAddress + FvbMapEntry->Length * LbaIndex)) {\r
+          //\r
+          // Found the (Lba, Offset)\r
+          //\r
+          *Lba    = LbaIndex - 1;\r
+          *Offset = (UINTN) (Address - (FvbBaseAddress + FvbMapEntry->Length * (LbaIndex - 1)));\r
+          return EFI_SUCCESS;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_ABORTED;\r
+}\r
+\r
+EFI_STATUS\r
+FtwVariableSpace (\r
+  IN EFI_PHYSICAL_ADDRESS   VariableBase,\r
+  IN UINT8                  *Buffer,\r
+  IN UINTN                  BufferSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Write a buffer to Variable space, in the working block.\r
+\r
+Arguments:\r
+    FvbHandle        - Indicates a handle to FVB to access variable store\r
+    Buffer           - Point to the input buffer\r
+    BufferSize       - The number of bytes of the input Buffer\r
+\r
+Returns:\r
+    EFI_SUCCESS            - The function completed successfully\r
+    EFI_ABORTED            - The function could not complete successfully\r
+    EFI_NOT_FOUND          - Locate FVB protocol by handle fails\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_HANDLE            FvbHandle;\r
+  EFI_FTW_LITE_PROTOCOL *FtwLiteProtocol;\r
+  EFI_LBA               VarLba;\r
+  UINTN                 VarOffset;\r
+  UINT8                 *FtwBuffer;\r
+  UINTN                 FtwBufferSize;\r
+\r
+  //\r
+  // Locate fault tolerant write protocol\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiFaultTolerantWriteLiteProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &FtwLiteProtocol\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Locate Fvb handle by address\r
+  //\r
+  Status = GetFvbHandleByAddress (VariableBase, &FvbHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Get LBA and Offset by address\r
+  //\r
+  Status = GetLbaAndOffsetByAddress (VariableBase, &VarLba, &VarOffset);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_ABORTED;\r
+  }\r
+  //\r
+  // Prepare for the variable data\r
+  //\r
+  FtwBufferSize = ((VARIABLE_STORE_HEADER *) ((UINTN) VariableBase))->Size;\r
+  FtwBuffer     = AllocateRuntimePool (FtwBufferSize);\r
+  if (FtwBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  SetMem (FtwBuffer, FtwBufferSize, (UINT8) 0xff);\r
+  CopyMem (FtwBuffer, Buffer, BufferSize);\r
+\r
+  //\r
+  // FTW write record\r
+  //\r
+  Status = FtwLiteProtocol->Write (\r
+                              FtwLiteProtocol,\r
+                              FvbHandle,\r
+                              VarLba,         // LBA\r
+                              VarOffset,      // Offset\r
+                              &FtwBufferSize, // NumBytes,\r
+                              FtwBuffer\r
+                              );\r
+\r
+  FreePool (FtwBuffer);\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/reclaim.h b/MdeModulePkg/Universal/VariableRuntimeDxe/reclaim.h
new file mode 100644 (file)
index 0000000..393b590
--- /dev/null
@@ -0,0 +1,50 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  reclaim.h\r
+\r
+Abstract:\r
+\r
+  Definitions for non-volatile variable store garbage collection\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _VAR_RECLAIM_H\r
+#define _VAR_RECLAIM_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Functions\r
+//\r
+EFI_STATUS\r
+GetFvbHandleByAddress (\r
+  IN  EFI_PHYSICAL_ADDRESS   VariableStoreBase,\r
+  OUT EFI_HANDLE             *FvbHandle\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FtwVariableSpace (\r
+  IN EFI_PHYSICAL_ADDRESS   VariableBaseAddress,\r
+  IN UINT8                  *Buffer,\r
+  IN UINTN                  BufferSize\r
+  )\r
+;\r
+\r
+#endif\r