]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
Add IntelFspPkg to support create FSP bin based on EDKII.
[mirror_edk2.git] / IntelFspPkg / Library / BaseFspPlatformLib / FspPlatformMemory.c
diff --git a/IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c b/IntelFspPkg/Library/BaseFspPlatformLib/FspPlatformMemory.c
new file mode 100644 (file)
index 0000000..2f1c0b1
--- /dev/null
@@ -0,0 +1,155 @@
+/** @file\r
+\r
+  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/FspCommonLib.h>\r
+#include <Guid/GuidHobFsp.h>\r
+#include <FspGlobalData.h>\r
+#include <FspApi.h>\r
+\r
+/**\r
+  Get system memory from HOB.\r
+\r
+  @param[in,out] LowMemoryLength   less than 4G memory length\r
+  @param[in,out] HighMemoryLength  greater than 4G memory length\r
+**/\r
+VOID\r
+EFIAPI\r
+FspGetSystemMemorySize (\r
+  IN OUT UINT64              *LowMemoryLength,\r
+  IN OUT UINT64              *HighMemoryLength\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS    Hob;\r
+\r
+  *HighMemoryLength = 0;\r
+  *LowMemoryLength  = SIZE_1MB;\r
+  //\r
+  // Get the HOB list for processing\r
+  //\r
+  Hob.Raw = GetHobList ();\r
+\r
+  //\r
+  // Collect memory ranges\r
+  //\r
+  while (!END_OF_HOB_LIST (Hob)) {\r
+    if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r
+      if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
+        //\r
+        // Need memory above 1MB to be collected here\r
+        //\r
+        if (Hob.ResourceDescriptor->PhysicalStart >= BASE_1MB &&\r
+            Hob.ResourceDescriptor->PhysicalStart < (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
+          *LowMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
+        } else if (Hob.ResourceDescriptor->PhysicalStart >= (EFI_PHYSICAL_ADDRESS) BASE_4GB) {\r
+          *HighMemoryLength += (UINT64) (Hob.ResourceDescriptor->ResourceLength);\r
+        }\r
+      }\r
+    }\r
+    Hob.Raw = GET_NEXT_HOB (Hob);\r
+  }\r
+}\r
+\r
+/**\r
+  Migrate bootloader data before destroying CAR.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+FspMigrateTemporaryMemory (\r
+  VOID\r
+ )\r
+{\r
+  FSP_INIT_RT_COMMON_BUFFER  *FspInitRtBuffer;\r
+  UINT32             BootLoaderTempRamStart;\r
+  UINT32             BootLoaderTempRamEnd;\r
+  UINT32             BootLoaderTempRamSize;\r
+  UINT32             OffsetGap;\r
+  UINT32             FspParamPtr;\r
+  FSP_INIT_PARAMS   *FspInitParams;\r
+  UINT32            *NewStackTop;\r
+  VOID              *BootLoaderTempRamHob;\r
+  VOID              *UpdDataRgnPtr;\r
+  VOID              *PlatformDataPtr;\r
+\r
+  //\r
+  // Get the temporary memory range used by the bootloader\r
+  //\r
+  BootLoaderTempRamStart = PcdGet32(PcdTemporaryRamBase);\r
+  BootLoaderTempRamSize  = PcdGet32(PcdTemporaryRamSize) - PcdGet32(PcdFspTemporaryRamSize);\r
+  BootLoaderTempRamEnd   = BootLoaderTempRamStart +  BootLoaderTempRamSize;\r
+\r
+  //\r
+  // Build a Boot Loader Temporary Memory GUID HOB\r
+  //\r
+  BootLoaderTempRamHob = BuildGuidHob (&gFspBootLoaderTemporaryMemoryGuid, BootLoaderTempRamSize);\r
+  CopyMem (BootLoaderTempRamHob, (VOID *)BootLoaderTempRamStart, BootLoaderTempRamSize);\r
+  OffsetGap = (UINT32)BootLoaderTempRamHob - BootLoaderTempRamStart;\r
+\r
+  //\r
+  // Set a new stack frame for the continuation function\r
+  //\r
+  FspInitParams   = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
+  FspInitRtBuffer = (FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr;\r
+  NewStackTop     = (UINT32 *)FspInitRtBuffer->StackTop - 1;\r
+  SetFspCoreStackPointer (NewStackTop);\r
+\r
+  //\r
+  // Fix the FspInit Parameter Pointers to the new location.\r
+  //\r
+  FspParamPtr = GetFspApiParameter ();\r
+  if (FspParamPtr >= BootLoaderTempRamStart && FspParamPtr < BootLoaderTempRamEnd) {\r
+    SetFspApiParameter(FspParamPtr + OffsetGap);\r
+  }\r
+\r
+  FspInitParams = (FSP_INIT_PARAMS *)GetFspApiParameter ();\r
+  if ((UINT32)(FspInitParams->RtBufferPtr) >= BootLoaderTempRamStart &&\r
+      (UINT32)(FspInitParams->RtBufferPtr) <  BootLoaderTempRamEnd) {\r
+    FspInitParams->RtBufferPtr = (VOID *)((UINT32)(FspInitParams->RtBufferPtr) + OffsetGap);\r
+  }\r
+\r
+  if ((UINT32)(FspInitParams->NvsBufferPtr) >= BootLoaderTempRamStart &&\r
+      (UINT32)(FspInitParams->NvsBufferPtr) <  BootLoaderTempRamEnd) {\r
+    FspInitParams->NvsBufferPtr = (VOID *)((UINT32)(FspInitParams->NvsBufferPtr) + OffsetGap);\r
+  }\r
+\r
+  if ((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) >= BootLoaderTempRamStart &&\r
+      (UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) <  BootLoaderTempRamEnd) {\r
+    ((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr = \\r
+           (VOID *)((UINT32)(((FSP_INIT_RT_COMMON_BUFFER *)(FspInitParams->RtBufferPtr))->UpdDataRgnPtr) + OffsetGap);\r
+  }\r
+\r
+  //\r
+  // Update UPD pointer in FSP Global Data\r
+  //\r
+  UpdDataRgnPtr = ((FSP_INIT_RT_COMMON_BUFFER *)FspInitParams->RtBufferPtr)->UpdDataRgnPtr;\r
+  if (UpdDataRgnPtr != NULL) {\r
+    SetFspUpdDataPointer (UpdDataRgnPtr);\r
+  }\r
+\r
+  //\r
+  // Update Platform data pointer in FSP Global Data\r
+  //\r
+  PlatformDataPtr = GetFspPlatformDataPointer ();\r
+  if (((UINT32)PlatformDataPtr >= BootLoaderTempRamStart) &&\r
+      ((UINT32)PlatformDataPtr <  BootLoaderTempRamEnd)) {\r
+    SetFspPlatformDataPointer ((UINT8 *)PlatformDataPtr + OffsetGap);\r
+  }\r
+\r
+}\r