]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EdkCompatibilityPkg: Add AcpiVariableHobOnSmramReserveHobThunk
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 27 Jun 2011 23:32:02 +0000 (23:32 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 27 Jun 2011 23:32:02 +0000 (23:32 +0000)
Signed-off-by: jljusten
Reviewed-by: mdkinney
Reviewed-by: geekboy15a
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11904 6f19259b-4bc3-4df7-8a09-765794883524

EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.c [new file with mode: 0644]
EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.inf [new file with mode: 0644]
EdkCompatibilityPkg/EdkCompatibilityPkg.dsc

diff --git a/EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.c b/EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.c
new file mode 100644 (file)
index 0000000..05dda26
--- /dev/null
@@ -0,0 +1,249 @@
+/** @file\r
+  This is the driver that produce AcpiVariable hob and slit SmramReserve hob\r
+  for ECP platform.\r
+\r
+Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution.  The\r
+full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/SmramMemoryReserve.h>\r
+#include <Guid/AcpiVariable.h>\r
+\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+/**\r
+  Retrieves the data structure associated witht he GUIDed HOB of type gEfiSmmPeiSmramMemoryReserveGuid\r
+  \r
+  @retval NULL   A HOB of type gEfiSmmPeiSmramMemoryReserveGuid could not be found.\r
+  @retval !NULL  A pointer to the GUID data from a HIB of type gEfiSmmPeiSmramMemoryReserveGuid\r
+\r
+**/\r
+EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *\r
+GetSrmamHobData (\r
+  VOID\r
+  )\r
+{\r
+  VOID  *GuidHob;\r
+\r
+  //\r
+  // Search SmramMemoryReserve HOB that describes SMRAM region\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiSmmPeiSmramMemoryReserveGuid);\r
+  if (GuidHob == NULL) {\r
+    return NULL;\r
+  }\r
+  return (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)GET_GUID_HOB_DATA (GuidHob);\r
+}\r
+\r
+/**\r
+  This routine will split SmramReserve hob to reserve 1 page for SMRAM content in S3 phase\r
+  for R9 SMM core.\r
+  \r
+  @retval EFI_SUCCESS           The gEfiSmmPeiSmramMemoryReserveGuid is splited successfully.\r
+  @retval EFI_NOT_FOUND         The gEfiSmmPeiSmramMemoryReserveGuid is not found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SplitSmramReserveHob (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE                *GuidHob;\r
+  EFI_PEI_HOB_POINTERS             Hob;\r
+  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK   *DescriptorBlock;\r
+  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK   *NewDescriptorBlock;\r
+  UINTN                            BufferSize;\r
+  UINTN                            SmramRanges;\r
+  UINTN                            Index;\r
+  UINTN                            SubIndex;\r
+\r
+  //\r
+  // Retrieve the GUID HOB data that contains the set of SMRAM descriptyors\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiSmmPeiSmramMemoryReserveGuid);\r
+  if (GuidHob == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  DescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)GET_GUID_HOB_DATA (GuidHob);\r
+\r
+  //\r
+  // Allocate one extra EFI_SMRAM_DESCRIPTOR to describe a page of SMRAM memory that contains a pointer\r
+  // to the SMM Services Table that is required on the S3 resume path\r
+  //\r
+  SmramRanges = DescriptorBlock->NumberOfSmmReservedRegions;\r
+  BufferSize = sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges * sizeof (EFI_SMRAM_DESCRIPTOR));\r
+\r
+  Hob.Raw = BuildGuidHob (\r
+              &gEfiSmmPeiSmramMemoryReserveGuid,\r
+              BufferSize\r
+              );\r
+  ASSERT (Hob.Raw);\r
+  NewDescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)Hob.Raw;\r
+\r
+  //\r
+  // Copy old EFI_SMRAM_HOB_DESCRIPTOR_BLOCK to new allocated region\r
+  //\r
+  CopyMem ((VOID *)Hob.Raw, DescriptorBlock, BufferSize - sizeof(EFI_SMRAM_DESCRIPTOR));\r
+\r
+  //\r
+  // Increase the number of SMRAM descriptors by 1 to make room for the ALLOCATED descriptor of size EFI_PAGE_SIZE\r
+  //\r
+  NewDescriptorBlock->NumberOfSmmReservedRegions = (UINT32)(SmramRanges + 1);\r
+\r
+  ASSERT (SmramRanges >= 1);\r
+  //\r
+  // Copy last entry to the end - we assume TSEG is last entry, which is same assumption as R8 CPU/SMM driver\r
+  //\r
+  CopyMem (&NewDescriptorBlock->Descriptor[SmramRanges], &NewDescriptorBlock->Descriptor[SmramRanges - 1], sizeof(EFI_SMRAM_DESCRIPTOR));\r
+\r
+  //\r
+  // Update the last but 1 entry in the array with a size of EFI_PAGE_SIZE and put into the ALLOCATED state\r
+  //\r
+  NewDescriptorBlock->Descriptor[SmramRanges - 1].PhysicalSize    = EFI_PAGE_SIZE;\r
+  NewDescriptorBlock->Descriptor[SmramRanges - 1].RegionState    |= EFI_ALLOCATED;\r
+\r
+  //\r
+  // Reduce the size of the last SMRAM descriptor by EFI_PAGE_SIZE \r
+  //\r
+  NewDescriptorBlock->Descriptor[SmramRanges].PhysicalStart += EFI_PAGE_SIZE;\r
+  NewDescriptorBlock->Descriptor[SmramRanges].CpuStart      += EFI_PAGE_SIZE;\r
+  NewDescriptorBlock->Descriptor[SmramRanges].PhysicalSize  -= EFI_PAGE_SIZE;\r
+\r
+  //\r
+  // Now, we have created SmramReserve Hob for SmmAccess drive. But the issue is that, R8 SmmAccess will assume there is 2 SmramReserve region only.\r
+  // Reporting 3 SmramReserve region will cause buffer overflow. Moreover, we would like to filter AB-SEG or H-SEG to avoid SMM cache-poisoning issue.\r
+  // So we uses scan SmmReserve Hob to remove AB-SEG or H-SEG.\r
+  //\r
+  for (Index = 0; Index <= SmramRanges; Index++) {\r
+    if (NewDescriptorBlock->Descriptor[Index].PhysicalSize == 0) {\r
+      //\r
+      // Skip zero entry\r
+      //\r
+      continue;\r
+    }\r
+    if (NewDescriptorBlock->Descriptor[Index].PhysicalStart < BASE_1MB) {\r
+      //\r
+      // Find AB-SEG or H-SEG\r
+      // remove this region\r
+      //\r
+      for (SubIndex = Index; SubIndex < NewDescriptorBlock->NumberOfSmmReservedRegions - 1; SubIndex++) {\r
+        CopyMem (&NewDescriptorBlock->Descriptor[SubIndex], &NewDescriptorBlock->Descriptor[SubIndex + 1], sizeof (EFI_SMRAM_DESCRIPTOR));\r
+      }\r
+      //\r
+      // Zero last one\r
+      //\r
+      ZeroMem (&NewDescriptorBlock->Descriptor[SubIndex], sizeof(EFI_SMRAM_DESCRIPTOR));\r
+      //\r
+      // Decrease Number\r
+      //\r
+      NewDescriptorBlock->NumberOfSmmReservedRegions --;\r
+      //\r
+      // Decrease Index to let it test mew entry\r
+      //\r
+      Index --;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Last step, we can scrub old one\r
+  //\r
+  ZeroMem (&GuidHob->Name, sizeof(GuidHob->Name));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This routine will create AcpiVariable hob to point the reserved smram in S3 phase\r
+  for R9 SMM core.\r
+  \r
+  @retval EFI_SUCCESS           The gEfiAcpiVariableGuid is created successfully.\r
+  @retval EFI_NOT_FOUND         The gEfiSmmPeiSmramMemoryReserveGuid is not found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CreateAcpiVariableHob (\r
+  VOID\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS             Hob;\r
+  EFI_SMRAM_HOB_DESCRIPTOR_BLOCK   *DescriptorBlock;\r
+  UINTN                            SmramRanges;\r
+\r
+  //\r
+  // Retrieve the GUID HOB data that contains the set of SMRAM descriptyors\r
+  //\r
+  DescriptorBlock = GetSrmamHobData ();\r
+  if (DescriptorBlock == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Hob.Raw = BuildGuidHob (\r
+              &gEfiAcpiVariableGuid,\r
+              sizeof (EFI_SMRAM_DESCRIPTOR)\r
+              );\r
+  ASSERT (Hob.Raw);\r
+\r
+  //\r
+  // It should be already patch, so just copy last but 1 region directly.\r
+  //\r
+  SmramRanges = DescriptorBlock->NumberOfSmmReservedRegions;\r
+  ASSERT (SmramRanges >= 2);\r
+  if (SmramRanges >= 2) {\r
+    CopyMem ((VOID *)Hob.Raw, &DescriptorBlock->Descriptor[SmramRanges - 2], sizeof (EFI_SMRAM_DESCRIPTOR));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Driver Entry for AcpiVariableHobOnSmramReservHob PEIM\r
+  \r
+  @param   FileHandle       Handle of the file being invoked.\r
+  @param   PeiServices      Describes the list of possible PEI Services.\r
+  \r
+  @retval EFI_SUCCESS      Success create gEfiAcpiVariableGuid and\r
+                           split gEfiSmmPeiSmramMemoryReserveGuid.\r
+  @retval EFI_NOT_FOUND    Can not get gEfiSmmPeiSmramMemoryReserveGuid hob\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AcpiVariableHobEntry (\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Split SmramReserve hob, which is required for R9 SMM Core for S3.\r
+  //\r
+  Status = SplitSmramReserveHob ();\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Create AcpiVariable hob, which is required for R9 SMM Core for S3.\r
+  //\r
+  Status = CreateAcpiVariableHob ();\r
+\r
+  return Status;\r
+}\r
diff --git a/EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.inf b/EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.inf
new file mode 100644 (file)
index 0000000..447aa77
--- /dev/null
@@ -0,0 +1,52 @@
+## @file\r
+#  Component description file for AcpiVariableHob on SmramReservedHob Thunk driver.\r
+#\r
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions\r
+# of the BSD License which accompanies this distribution.  The\r
+# full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = AcpiVariableHobOnSmramReserveHobThunk\r
+  FILE_GUID                      = 49B7F3E1-6C08-4a5b-911C-E9E397ED4178\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = AcpiVariableHobEntry\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
+\r
+[Sources]\r
+  AcpiVariableHobOnSmramReserveHobThunk.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  PeimEntryPoint\r
+  MemoryAllocationLib\r
+  DebugLib\r
+  HobLib\r
+  PeiServicesLib\r
+  BaseMemoryLib\r
+  \r
+[Guids]\r
+  gEfiSmmPeiSmramMemoryReserveGuid             # ALWAYS_CONSUMED\r
+  gEfiAcpiVariableGuid                         # ALWAYS_CONSUMED\r
+\r
+[Depex]\r
+  gEfiPeiMemoryDiscoveredPpiGuid\r
index ebb26f1c04fa78069df6a76bd2a337b780124338..cf8243d2b841393f2af0268b51ce67c8fa92f805 100644 (file)
@@ -74,6 +74,7 @@ define GCC_MACRO                 = -DEFI_SPECIFICATION_VERSION=0x00020000 -DPI_S
 \r
 [LibraryClasses.common.PEIM]\r
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER,LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
@@ -279,6 +280,7 @@ define GCC_MACRO                 = -DEFI_SPECIFICATION_VERSION=0x00020000 -DPI_S
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiServicesTablePointerLibMm7/PeiServicesTablePointerLibMm7.inf\r
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/DxePerformanceLib/DxePerformanceLib.inf # Use IA32/X64 specific AsmReadTsc (). \r
   EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiPerformanceLib/PeiPerformanceLib.inf # Use IA32/X64 specific AsmReadTsc ().\r
+  EdkCompatibilityPkg/Compatibility/AcpiVariableHobOnSmramReserveHobThunk/AcpiVariableHobOnSmramReserveHobThunk.inf\r
   EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.inf\r
   EdkCompatibilityPkg/Compatibility/SmmBaseOnSmmBase2Thunk/SmmBaseOnSmmBase2Thunk.inf\r
   EdkCompatibilityPkg/Compatibility/SmmBaseHelper/SmmBaseHelper.inf\r