--- /dev/null
+/** @file\r
+ Sample to provide SecGetPerformance 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
+#include <PiPei.h>\r
+\r
+#include <Ppi/SecPerformance.h>\r
+#include <Ppi/TopOfTemporaryRam.h>\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+/**\r
+ This interface conveys performance information out of the Security (SEC) phase into PEI.\r
+\r
+ This service is published by the SEC phase. The SEC phase handoff has an optional\r
+ EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the\r
+ PEI Foundation. As such, if the platform supports collecting performance data in SEC,\r
+ this information is encapsulated into the data structure abstracted by this service.\r
+ This information is collected for the boot-strap processor (BSP) on IA-32.\r
+\r
+ @param[in] PeiServices The pointer to the PEI Services Table.\r
+ @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.\r
+ @param[out] Performance The pointer to performance data collected in SEC phase.\r
+\r
+ @retval EFI_SUCCESS The data was successfully returned.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SecGetPerformance (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN PEI_SEC_PERFORMANCE_PPI *This,\r
+ OUT FIRMWARE_SEC_PERFORMANCE *Performance\r
+ )\r
+{\r
+ UINT32 Size;\r
+ UINT32 Count;\r
+ UINT32 TopOfTemporaryRam;\r
+ UINT64 Ticker;\r
+ VOID *TopOfTemporaryRamPpi;\r
+ EFI_STATUS Status;\r
+\r
+ DEBUG ((DEBUG_INFO, "SecGetPerformance\n"));\r
+\r
+ Status = (*PeiServices)->LocatePpi (\r
+ PeiServices,\r
+ &gTopOfTemporaryRamPpiGuid,\r
+ 0,\r
+ NULL,\r
+ (VOID **) &TopOfTemporaryRamPpi\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\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
+ TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof(UINT32);\r
+ TopOfTemporaryRam -= sizeof(UINT32) * 2;\r
+ Count = *(UINT32 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32));\r
+ Size = Count * sizeof (UINT64);\r
+\r
+ Ticker = *(UINT64 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32) - Size - sizeof (UINT32) * 2);\r
+ Performance->ResetEnd = GetTimeInNanoSecond (Ticker);\r
+\r
+ return EFI_SUCCESS;\r
+}\r