]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFsp2WrapperPkg/Library/SecFspWrapperPlatformSecLibSample/SecGetPerformance.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / IntelFsp2WrapperPkg / Library / SecFspWrapperPlatformSecLibSample / SecGetPerformance.c
1 /** @file
2 Sample to provide SecGetPerformance function.
3
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10
11 #include <Ppi/SecPerformance.h>
12 #include <Ppi/TopOfTemporaryRam.h>
13
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/TimerLib.h>
16 #include <Library/DebugLib.h>
17
18 /**
19 This interface conveys performance information out of the Security (SEC) phase into PEI.
20
21 This service is published by the SEC phase. The SEC phase handoff has an optional
22 EFI_PEI_PPI_DESCRIPTOR list as its final argument when control is passed from SEC into the
23 PEI Foundation. As such, if the platform supports collecting performance data in SEC,
24 this information is encapsulated into the data structure abstracted by this service.
25 This information is collected for the boot-strap processor (BSP) on IA-32.
26
27 @param[in] PeiServices The pointer to the PEI Services Table.
28 @param[in] This The pointer to this instance of the PEI_SEC_PERFORMANCE_PPI.
29 @param[out] Performance The pointer to performance data collected in SEC phase.
30
31 @retval EFI_SUCCESS The data was successfully returned.
32
33 **/
34 EFI_STATUS
35 EFIAPI
36 SecGetPerformance (
37 IN CONST EFI_PEI_SERVICES **PeiServices,
38 IN PEI_SEC_PERFORMANCE_PPI *This,
39 OUT FIRMWARE_SEC_PERFORMANCE *Performance
40 )
41 {
42 UINT32 Size;
43 UINT32 Count;
44 UINT32 TopOfTemporaryRam;
45 UINT64 Ticker;
46 VOID *TopOfTemporaryRamPpi;
47 EFI_STATUS Status;
48
49 DEBUG ((DEBUG_INFO, "SecGetPerformance\n"));
50
51 Status = (*PeiServices)->LocatePpi (
52 PeiServices,
53 &gTopOfTemporaryRamPpiGuid,
54 0,
55 NULL,
56 (VOID **) &TopOfTemporaryRamPpi
57 );
58 if (EFI_ERROR (Status)) {
59 return EFI_NOT_FOUND;
60 }
61
62 //
63 // |--------------| <- TopOfTemporaryRam
64 // |Number of BSPs|
65 // |--------------|
66 // | BIST |
67 // |--------------|
68 // | .... |
69 // |--------------|
70 // | TSC[63:32] |
71 // |--------------|
72 // | TSC[31:00] |
73 // |--------------|
74 //
75 TopOfTemporaryRam = (UINT32)(UINTN)TopOfTemporaryRamPpi - sizeof(UINT32);
76 TopOfTemporaryRam -= sizeof(UINT32) * 2;
77 Count = *(UINT32 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32));
78 Size = Count * sizeof (UINT64);
79
80 Ticker = *(UINT64 *) (UINTN) (TopOfTemporaryRam - sizeof (UINT32) - Size - sizeof (UINT32) * 2);
81 Performance->ResetEnd = GetTimeInNanoSecond (Ticker);
82
83 return EFI_SUCCESS;
84 }