]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFspWrapperPkg/Library/SecPeiFspPlatformSecLibSample/SaveSecContext.c
Add IntelFspWrapper to support boot EDKII on FSP bin.
[mirror_edk2.git] / IntelFspWrapperPkg / Library / SecPeiFspPlatformSecLibSample / SaveSecContext.c
diff --git a/IntelFspWrapperPkg/Library/SecPeiFspPlatformSecLibSample/SaveSecContext.c b/IntelFspWrapperPkg/Library/SecPeiFspPlatformSecLibSample/SaveSecContext.c
new file mode 100644 (file)
index 0000000..3d37441
--- /dev/null
@@ -0,0 +1,111 @@
+/** @file\r
+  Sample to provide SaveSecContext function.\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
+\r
+#include <PiPei.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Ppi/TopOfTemporaryRam.h>\r
+#include <Ppi/SecPlatformInformation.h>\r
+\r
+/**\r
+  Save BIST value before call FspInit.\r
+\r
+  @param[in] Bist   BIST value.\r
+**/\r
+VOID\r
+AsmSaveBistValue (\r
+  IN UINT32  Bist\r
+  );\r
+\r
+/**\r
+  Save Ticker value before call FspInit.\r
+\r
+  @param[in] Ticker   Ticker value.\r
+**/\r
+VOID\r
+AsmSaveTickerValue (\r
+  IN UINT64  Ticker\r
+  );\r
+\r
+/**\r
+  Save SEC context before call FspInit.\r
+\r
+  @param[in] PeiServices  Pointer to PEI Services Table.\r
+**/\r
+VOID\r
+EFIAPI\r
+SaveSecContext (\r
+  IN CONST EFI_PEI_SERVICES                     **PeiServices\r
+  )\r
+{\r
+  UINT32      *Bist;\r
+  UINT64      *Ticker;\r
+  UINT32      Size;\r
+  UINT32      Count;\r
+  UINT32      TopOfTemporaryRam;\r
+  VOID        *TopOfTemporaryRamPpi;\r
+  EFI_STATUS  Status;\r
+\r
+  DEBUG ((DEBUG_INFO, "SaveSecContext - 0x%x\n", PeiServices));\r
+\r
+  Status = (*PeiServices)->LocatePpi (\r
+                             PeiServices,\r
+                             &gTopOfTemporaryRamPpiGuid,\r
+                             0,\r
+                             NULL,\r
+                             (VOID **) &TopOfTemporaryRamPpi\r
+                             );\r
+  if (EFI_ERROR (Status)) {\r
+    return ;\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "TopOfTemporaryRamPpi - 0x%x\n", TopOfTemporaryRamPpi));\r
+\r
+  //\r
+  // The entries of BIST information, together with the number of them,\r
+  // reside in the bottom of stack, left untouched by normal stack operation.\r
+  // This routine copies the BIST information to the buffer pointed by\r
+  // PlatformInformationRecord for output.\r
+  //\r
+  // |--------------| <- TopOfTemporaryRam\r
+  // |Number of BSPs|\r
+  // |--------------|\r
+  // |     BIST     |\r
+  // |--------------|\r
+  // |     ....     |\r
+  // |--------------|\r
+  // |  TSC[63:32]  |\r
+  // |--------------|\r
+  // |  TSC[31:00]  |\r
+  // |--------------|\r
+  //\r
+\r
+  TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof(UINT32);\r
+  TopOfTemporaryRam -= sizeof(UINT32) * 2;\r
+  DEBUG ((DEBUG_INFO, "TopOfTemporaryRam - 0x%x\n", TopOfTemporaryRam));\r
+  Count             = *(UINT32 *)(UINTN)(TopOfTemporaryRam - sizeof(UINT32));\r
+  DEBUG ((DEBUG_INFO, "Count - 0x%x\n", Count));\r
+  Size              = Count * sizeof (IA32_HANDOFF_STATUS);\r
+  DEBUG ((DEBUG_INFO, "Size - 0x%x\n", Size));\r
+\r
+  Bist   = (UINT32 *)(UINTN)(TopOfTemporaryRam - sizeof(UINT32) - Size);\r
+  DEBUG ((DEBUG_INFO, "Bist - 0x%x\n", *Bist));\r
+  Ticker = (UINT64 *)(UINTN)(TopOfTemporaryRam - sizeof(UINT32) - Size - sizeof(UINT64));\r
+  DEBUG ((DEBUG_INFO, "Ticker - 0x%lx\n", *Ticker));\r
+\r
+  // Just need record BSP\r
+  AsmSaveBistValue (*Bist);\r
+  AsmSaveTickerValue (*Ticker);\r
+}\r