TianoCore EDK2 master
Loading...
Searching...
No Matches
FirmwarePerformanceCommon.c
Go to the documentation of this file.
1
19#include <PiMm.h>
20
22
24
26#include <Library/BaseLib.h>
27#include <Library/DebugLib.h>
28#include <Library/TimerLib.h>
29#include <Library/LockBoxLib.h>
30#include <Library/PcdLib.h>
33
34EFI_MM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
35UINT64 mSuspendStartTime = 0;
36BOOLEAN mS3SuspendLockBoxSaved = FALSE;
37
58EFIAPI
60 IN EFI_STATUS_CODE_TYPE CodeType,
62 IN UINT32 Instance,
63 IN EFI_GUID *CallerId,
65 )
66{
67 EFI_STATUS Status;
68 UINT64 CurrentTime;
70
71 //
72 // Check whether status code is what we are interested in.
73 //
74 if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {
75 return EFI_UNSUPPORTED;
76 }
77
78 if ((Data != NULL) && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {
79 DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableMm\n"));
80 return EFI_UNSUPPORTED;
81 }
82
83 if ((Value != PcdGet32 (PcdProgressCodeS3SuspendStart)) &&
84 (Value != PcdGet32 (PcdProgressCodeS3SuspendEnd)))
85 {
86 return EFI_UNSUPPORTED;
87 }
88
89 //
90 // Retrieve current time.
91 //
93
94 if (Value == PcdGet32 (PcdProgressCodeS3SuspendStart)) {
95 //
96 // S3 Suspend started, record the performance data and return.
97 //
98 mSuspendStartTime = CurrentTime;
99 return EFI_SUCCESS;
100 }
101
102 //
103 // We are going to S3 sleep, record S3 Suspend End performance data.
104 //
105 S3SuspendRecord.SuspendStart = mSuspendStartTime;
106 S3SuspendRecord.SuspendEnd = CurrentTime;
107
108 //
109 // Save S3 suspend performance data to lock box, it will be used by Firmware Performance PEIM.
110 //
111 if (!mS3SuspendLockBoxSaved) {
112 Status = SaveLockBox (
113 &gEfiFirmwarePerformanceGuid,
114 &S3SuspendRecord,
116 );
117 ASSERT_EFI_ERROR (Status);
118
119 mS3SuspendLockBoxSaved = TRUE;
120 } else {
121 Status = UpdateLockBox (
122 &gEfiFirmwarePerformanceGuid,
123 0,
124 &S3SuspendRecord,
126 );
127 ASSERT_EFI_ERROR (Status);
128 }
129
130 return EFI_SUCCESS;
131}
132
142 VOID
143 )
144{
145 EFI_STATUS Status;
146
147 //
148 // Get MM Report Status Code Handler Protocol.
149 //
150 Status = gMmst->MmLocateProtocol (
151 &gEfiMmRscHandlerProtocolGuid,
152 NULL,
153 (VOID **)&mRscHandlerProtocol
154 );
155 ASSERT_EFI_ERROR (Status);
156
157 //
158 // Register report status code listener for BootRecords and S3 Suspend Start and End.
159 //
160 Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm);
161 ASSERT_EFI_ERROR (Status);
162
163 return Status;
164}
UINT64 EFIAPI GetTimeInNanoSecond(IN UINT64 Ticks)
UINT64 EFIAPI GetPerformanceCounter(VOID)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS EFIAPI FpdtStatusCodeListenerMm(IN EFI_STATUS_CODE_TYPE CodeType, IN EFI_STATUS_CODE_VALUE Value, IN UINT32 Instance, IN EFI_GUID *CallerId, IN EFI_STATUS_CODE_DATA *Data)
EFI_STATUS FirmwarePerformanceCommonEntryPoint(VOID)
RETURN_STATUS EFIAPI UpdateLockBox(IN GUID *Guid, IN UINTN Offset, IN VOID *Buffer, IN UINTN Length)
RETURN_STATUS EFIAPI SaveLockBox(IN GUID *Guid, IN VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
UINT32 EFI_STATUS_CODE_VALUE
Definition: PiStatusCode.h:67
#define EFI_PROGRESS_CODE
Definition: PiStatusCode.h:43
UINT32 EFI_STATUS_CODE_TYPE
Definition: PiStatusCode.h:24
#define EFI_STATUS_CODE_TYPE_MASK
Definition: PiStatusCode.h:32
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213