]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.c
Clean up include of ACPI header file so that only IndustryStandard/Acpi.h is needed...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTablePei / FirmwarePerformancePei.c
1 /** @file
2 This module updates S3 Resume Performance Record in ACPI Firmware Performance
3 Data Table in S3 resume boot mode. In normal boot mode, this module consumes
4 SecPerformance PPI produced by SEC phase and build Hob to convey the SEC
5 performance data to DXE phase.
6
7 This module register report status code listener to collect performance data
8 for S3 Resume Performance Record on S3 resume boot path.
9
10 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
15
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18
19 **/
20
21 #include <PiPei.h>
22
23 #include <Ppi/ReadOnlyVariable2.h>
24 #include <Ppi/ReportStatusCodeHandler.h>
25 #include <Ppi/SecPerformance.h>
26
27 #include <Guid/FirmwarePerformance.h>
28
29 #include <Library/PeiServicesLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/TimerLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/LockBoxLib.h>
35 #include <Library/HobLib.h>
36 #include <Library/PcdLib.h>
37
38 /**
39 Report status code listener for PEI. This is used to record the performance
40 data for S3 FullResume in FPDT.
41
42 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
43 @param[in] CodeType Indicates the type of status code being reported.
44 @param[in] Value Describes the current status of a hardware or software entity.
45 This included information about the class and subclass that is used to
46 classify the entity as well as an operation.
47 @param[in] Instance The enumeration of a hardware or software entity within
48 the system. Valid instance numbers start with 1.
49 @param[in] CallerId This optional parameter may be used to identify the caller.
50 This parameter allows the status code driver to apply different rules to
51 different callers.
52 @param[in] Data This optional parameter may be used to pass additional data.
53
54 @retval EFI_SUCCESS Status code is what we expected.
55 @retval EFI_UNSUPPORTED Status code not supported.
56
57 **/
58 EFI_STATUS
59 EFIAPI
60 FpdtStatusCodeListenerPei (
61 IN CONST EFI_PEI_SERVICES **PeiServices,
62 IN EFI_STATUS_CODE_TYPE CodeType,
63 IN EFI_STATUS_CODE_VALUE Value,
64 IN UINT32 Instance,
65 IN CONST EFI_GUID *CallerId,
66 IN CONST EFI_STATUS_CODE_DATA *Data
67 )
68 {
69 EFI_STATUS Status;
70 UINT64 CurrentTime;
71 EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariableServices;
72 UINTN VarSize;
73 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
74 S3_PERFORMANCE_TABLE *AcpiS3PerformanceTable;
75 EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD *AcpiS3ResumeRecord;
76 UINT64 S3ResumeTotal;
77 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD S3SuspendRecord;
78 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD *AcpiS3SuspendRecord;
79
80 //
81 // Check whether status code is what we are interested in.
82 //
83 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) ||
84 (Value != (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_OS_WAKE))) {
85 return EFI_UNSUPPORTED;
86 }
87
88 //
89 // Retrieve current time as early as possible.
90 //
91 CurrentTime = GetTimeInNanoSecond (GetPerformanceCounter ());
92
93 Status = PeiServicesLocatePpi (
94 &gEfiPeiReadOnlyVariable2PpiGuid,
95 0,
96 NULL,
97 (VOID **) &VariableServices
98 );
99 ASSERT_EFI_ERROR (Status);
100
101 //
102 // Update S3 Resume Performance Record.
103 //
104 VarSize = sizeof (FIRMWARE_PERFORMANCE_VARIABLE);
105 Status = VariableServices->GetVariable (
106 VariableServices,
107 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
108 &gEfiFirmwarePerformanceGuid,
109 NULL,
110 &VarSize,
111 &PerformanceVariable
112 );
113 if (EFI_ERROR (Status)) {
114 return Status;
115 }
116
117 AcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.S3PerformanceTablePointer;
118 ASSERT (AcpiS3PerformanceTable != NULL);
119 ASSERT (AcpiS3PerformanceTable->Header.Signature == EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE);
120 AcpiS3ResumeRecord = &AcpiS3PerformanceTable->S3Resume;
121 AcpiS3ResumeRecord->FullResume = CurrentTime;
122 //
123 // Calculate average S3 resume time.
124 //
125 S3ResumeTotal = MultU64x32 (AcpiS3ResumeRecord->AverageResume, AcpiS3ResumeRecord->ResumeCount);
126 AcpiS3ResumeRecord->ResumeCount++;
127 AcpiS3ResumeRecord->AverageResume = DivU64x32 (S3ResumeTotal + AcpiS3ResumeRecord->FullResume, AcpiS3ResumeRecord->ResumeCount);
128
129 DEBUG ((EFI_D_INFO, "FPDT: S3 Resume Performance - ResumeCount = %d\n", AcpiS3ResumeRecord->ResumeCount));
130 DEBUG ((EFI_D_INFO, "FPDT: S3 Resume Performance - FullResume = %ld\n", AcpiS3ResumeRecord->FullResume));
131 DEBUG ((EFI_D_INFO, "FPDT: S3 Resume Performance - AverageResume = %ld\n", AcpiS3ResumeRecord->AverageResume));
132
133 //
134 // Update S3 Suspend Performance Record.
135 //
136 AcpiS3SuspendRecord = &AcpiS3PerformanceTable->S3Suspend;
137 VarSize = sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD);
138 ZeroMem (&S3SuspendRecord, sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD));
139 Status = RestoreLockBox (
140 &gEfiFirmwarePerformanceGuid,
141 &S3SuspendRecord,
142 &VarSize
143 );
144 ASSERT_EFI_ERROR (Status);
145
146 AcpiS3SuspendRecord->SuspendStart = S3SuspendRecord.SuspendStart;
147 AcpiS3SuspendRecord->SuspendEnd = S3SuspendRecord.SuspendEnd;
148
149 DEBUG ((EFI_D_INFO, "FPDT: S3 Suspend Performance - SuspendStart = %ld\n", AcpiS3SuspendRecord->SuspendStart));
150 DEBUG ((EFI_D_INFO, "FPDT: S3 Suspend Performance - SuspendEnd = %ld\n", AcpiS3SuspendRecord->SuspendEnd));
151
152 return EFI_SUCCESS;
153 }
154
155 /**
156 Main entry for Firmware Performance Data Table PEIM.
157
158 This routine is to register report status code listener for FPDT.
159
160 @param[in] FileHandle Handle of the file being invoked.
161 @param[in] PeiServices Pointer to PEI Services table.
162
163 @retval EFI_SUCCESS Report status code listener is registered successfully.
164
165 **/
166 EFI_STATUS
167 EFIAPI
168 FirmwarePerformancePeiEntryPoint (
169 IN EFI_PEI_FILE_HANDLE FileHandle,
170 IN CONST EFI_PEI_SERVICES **PeiServices
171 )
172 {
173 EFI_STATUS Status;
174 EFI_BOOT_MODE BootMode;
175 EFI_PEI_RSC_HANDLER_PPI *RscHandler;
176 PEI_SEC_PERFORMANCE_PPI *SecPerf;
177 FIRMWARE_SEC_PERFORMANCE Performance;
178
179 Status = PeiServicesGetBootMode(&BootMode);
180 ASSERT_EFI_ERROR (Status);
181
182 if (BootMode == BOOT_ON_S3_RESUME) {
183 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
184 //
185 // S3 resume - register status code listener for OS wake vector.
186 //
187 Status = PeiServicesLocatePpi (
188 &gEfiPeiRscHandlerPpiGuid,
189 0,
190 NULL,
191 (VOID **) &RscHandler
192 );
193 ASSERT_EFI_ERROR (Status);
194
195 Status = RscHandler->Register (FpdtStatusCodeListenerPei);
196 ASSERT_EFI_ERROR (Status);
197 }
198 } else {
199 //
200 // Normal boot - build Hob for SEC performance data.
201 //
202 Status = PeiServicesLocatePpi (
203 &gPeiSecPerformancePpiGuid,
204 0,
205 NULL,
206 (VOID **) &SecPerf
207 );
208 if (!EFI_ERROR (Status)) {
209 Status = SecPerf->GetPerformance (PeiServices, SecPerf, &Performance);
210 }
211 if (!EFI_ERROR (Status)) {
212 BuildGuidDataHob (
213 &gEfiFirmwarePerformanceGuid,
214 &Performance,
215 sizeof (FIRMWARE_SEC_PERFORMANCE)
216 );
217 DEBUG ((EFI_D_INFO, "FPDT: SEC Performance Hob ResetEnd = %ld\n", Performance.ResetEnd));
218 } else {
219 //
220 // SEC performance PPI is not installed or fail to get performance data
221 // from SEC Performance PPI.
222 //
223 DEBUG ((EFI_D_ERROR, "FPDT: WARNING: SEC Performance PPI not installed or failed!\n"));
224 }
225 }
226
227 return EFI_SUCCESS;
228 }