2 This module updates S3 Resume Performance Record in ACPI Firmware Performance
3 Data Table in S3 resume boot mode.
5 This module register report status code listener to collect performance data
6 for S3 Resume Performance Record on S3 resume boot path.
8 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Ppi/ReportStatusCodeHandler.h>
22 #include <Ppi/ReadOnlyVariable2.h>
24 #include <Guid/FirmwarePerformance.h>
25 #include <Guid/Performance.h>
26 #include <Guid/ExtendedFirmwarePerformance.h>
28 #include <Library/PeiServicesLib.h>
29 #include <Library/BaseLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/TimerLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/LockBoxLib.h>
34 #include <Library/PcdLib.h>
35 #include <Library/HobLib.h>
38 Report status code listener for PEI. This is used to record the performance
39 data for S3 FullResume in FPDT.
41 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
42 @param[in] CodeType Indicates the type of status code being reported.
43 @param[in] Value Describes the current status of a hardware or software entity.
44 This included information about the class and subclass that is used to
45 classify the entity as well as an operation.
46 @param[in] Instance The enumeration of a hardware or software entity within
47 the system. Valid instance numbers start with 1.
48 @param[in] CallerId This optional parameter may be used to identify the caller.
49 This parameter allows the status code driver to apply different rules to
51 @param[in] Data This optional parameter may be used to pass additional data.
53 @retval EFI_SUCCESS Status code is what we expected.
54 @retval EFI_UNSUPPORTED Status code not supported.
59 FpdtStatusCodeListenerPei (
60 IN CONST EFI_PEI_SERVICES
**PeiServices
,
61 IN EFI_STATUS_CODE_TYPE CodeType
,
62 IN EFI_STATUS_CODE_VALUE Value
,
64 IN CONST EFI_GUID
*CallerId
,
65 IN CONST EFI_STATUS_CODE_DATA
*Data
71 EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer
;
72 S3_PERFORMANCE_TABLE
*AcpiS3PerformanceTable
;
73 EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD
*AcpiS3ResumeRecord
;
75 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD S3SuspendRecord
;
76 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD
*AcpiS3SuspendRecord
;
77 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*VariableServices
;
78 UINT8
*BootPerformanceTable
;
79 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
80 EFI_HOB_GUID_TYPE
*GuidHob
;
81 FPDT_PEI_EXT_PERF_HEADER
*PeiPerformanceLogHeader
;
82 UINT8
*FirmwarePerformanceData
;
83 UINT8
*FirmwarePerformanceTablePtr
;
86 // Check whether status code is what we are interested in.
88 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) != EFI_PROGRESS_CODE
) ||
89 (Value
!= (EFI_SOFTWARE_PEI_MODULE
| EFI_SW_PEI_PC_OS_WAKE
))) {
90 return EFI_UNSUPPORTED
;
94 // Retrieve current time as early as possible.
96 CurrentTime
= GetTimeInNanoSecond (GetPerformanceCounter ());
99 // Update S3 Resume Performance Record.
101 S3PerformanceTablePointer
= 0;
102 VarSize
= sizeof (EFI_PHYSICAL_ADDRESS
);
103 Status
= RestoreLockBox (&gFirmwarePerformanceS3PointerGuid
, &S3PerformanceTablePointer
, &VarSize
);
104 ASSERT_EFI_ERROR (Status
);
106 AcpiS3PerformanceTable
= (S3_PERFORMANCE_TABLE
*) (UINTN
) S3PerformanceTablePointer
;
107 ASSERT (AcpiS3PerformanceTable
!= NULL
);
108 if (AcpiS3PerformanceTable
->Header
.Signature
!= EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE
) {
109 DEBUG ((EFI_D_ERROR
, "FPDT S3 performance data in ACPI memory get corrupted\n"));
112 AcpiS3ResumeRecord
= &AcpiS3PerformanceTable
->S3Resume
;
113 AcpiS3ResumeRecord
->FullResume
= CurrentTime
;
115 // Calculate average S3 resume time.
117 S3ResumeTotal
= MultU64x32 (AcpiS3ResumeRecord
->AverageResume
, AcpiS3ResumeRecord
->ResumeCount
);
118 AcpiS3ResumeRecord
->ResumeCount
++;
119 AcpiS3ResumeRecord
->AverageResume
= DivU64x32 (S3ResumeTotal
+ AcpiS3ResumeRecord
->FullResume
, AcpiS3ResumeRecord
->ResumeCount
);
121 DEBUG ((EFI_D_INFO
, "FPDT: S3 Resume Performance - ResumeCount = %d\n", AcpiS3ResumeRecord
->ResumeCount
));
122 DEBUG ((EFI_D_INFO
, "FPDT: S3 Resume Performance - FullResume = %ld\n", AcpiS3ResumeRecord
->FullResume
));
123 DEBUG ((EFI_D_INFO
, "FPDT: S3 Resume Performance - AverageResume = %ld\n", AcpiS3ResumeRecord
->AverageResume
));
126 // Update S3 Suspend Performance Record.
128 AcpiS3SuspendRecord
= &AcpiS3PerformanceTable
->S3Suspend
;
129 VarSize
= sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD
);
130 ZeroMem (&S3SuspendRecord
, sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD
));
131 Status
= RestoreLockBox (
132 &gEfiFirmwarePerformanceGuid
,
136 ASSERT_EFI_ERROR (Status
);
138 AcpiS3SuspendRecord
->SuspendStart
= S3SuspendRecord
.SuspendStart
;
139 AcpiS3SuspendRecord
->SuspendEnd
= S3SuspendRecord
.SuspendEnd
;
141 DEBUG ((EFI_D_INFO
, "FPDT: S3 Suspend Performance - SuspendStart = %ld\n", AcpiS3SuspendRecord
->SuspendStart
));
142 DEBUG ((EFI_D_INFO
, "FPDT: S3 Suspend Performance - SuspendEnd = %ld\n", AcpiS3SuspendRecord
->SuspendEnd
));
144 Status
= PeiServicesLocatePpi (
145 &gEfiPeiReadOnlyVariable2PpiGuid
,
148 (VOID
**) &VariableServices
150 ASSERT_EFI_ERROR (Status
);
153 // Update S3 boot records into the basic boot performance table.
155 VarSize
= sizeof (PerformanceVariable
);
156 Status
= VariableServices
->GetVariable (
158 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
159 &gEfiFirmwarePerformanceGuid
,
164 if (EFI_ERROR (Status
)) {
167 BootPerformanceTable
= (UINT8
*) (UINTN
) PerformanceVariable
.BootPerformanceTablePointer
;
170 // Dump PEI boot records
172 FirmwarePerformanceTablePtr
= (BootPerformanceTable
+ sizeof (BOOT_PERFORMANCE_TABLE
));
173 GuidHob
= GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
);
174 while (GuidHob
!= NULL
) {
175 FirmwarePerformanceData
= GET_GUID_HOB_DATA (GuidHob
);
176 PeiPerformanceLogHeader
= (FPDT_PEI_EXT_PERF_HEADER
*) FirmwarePerformanceData
;
178 CopyMem (FirmwarePerformanceTablePtr
, FirmwarePerformanceData
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
), (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
));
180 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, GET_NEXT_HOB (GuidHob
));
182 FirmwarePerformanceTablePtr
+= (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
);
186 // Update Table length.
188 ((BOOT_PERFORMANCE_TABLE
*) BootPerformanceTable
)->Header
.Length
= (UINT32
)((UINTN
)FirmwarePerformanceTablePtr
- (UINTN
)BootPerformanceTable
);
194 Main entry for Firmware Performance Data Table PEIM.
196 This routine is to register report status code listener for FPDT.
198 @param[in] FileHandle Handle of the file being invoked.
199 @param[in] PeiServices Pointer to PEI Services table.
201 @retval EFI_SUCCESS Report status code listener is registered successfully.
206 FirmwarePerformancePeiEntryPoint (
207 IN EFI_PEI_FILE_HANDLE FileHandle
,
208 IN CONST EFI_PEI_SERVICES
**PeiServices
212 EFI_PEI_RSC_HANDLER_PPI
*RscHandler
;
214 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support
)) {
216 // S3 resume - register status code listener for OS wake vector.
218 Status
= PeiServicesLocatePpi (
219 &gEfiPeiRscHandlerPpiGuid
,
222 (VOID
**) &RscHandler
224 ASSERT_EFI_ERROR (Status
);
226 Status
= RscHandler
->Register (FpdtStatusCodeListenerPei
);
227 ASSERT_EFI_ERROR (Status
);