]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.c
MdeModulePkg FirmwarePerfPei: Remove SEC performance data getting code
[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.
4
5 This module register report status code listener to collect performance data
6 for S3 Resume Performance Record on S3 resume boot path.
7
8 Copyright (c) 2011 - 2017, 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
13
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.
16
17 **/
18
19 #include <PiPei.h>
20
21 #include <Ppi/ReportStatusCodeHandler.h>
22
23 #include <Guid/FirmwarePerformance.h>
24
25 #include <Library/PeiServicesLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/TimerLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/LockBoxLib.h>
31 #include <Library/PcdLib.h>
32
33 /**
34 Report status code listener for PEI. This is used to record the performance
35 data for S3 FullResume in FPDT.
36
37 @param[in] PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
38 @param[in] CodeType Indicates the type of status code being reported.
39 @param[in] Value Describes the current status of a hardware or software entity.
40 This included information about the class and subclass that is used to
41 classify the entity as well as an operation.
42 @param[in] Instance The enumeration of a hardware or software entity within
43 the system. Valid instance numbers start with 1.
44 @param[in] CallerId This optional parameter may be used to identify the caller.
45 This parameter allows the status code driver to apply different rules to
46 different callers.
47 @param[in] Data This optional parameter may be used to pass additional data.
48
49 @retval EFI_SUCCESS Status code is what we expected.
50 @retval EFI_UNSUPPORTED Status code not supported.
51
52 **/
53 EFI_STATUS
54 EFIAPI
55 FpdtStatusCodeListenerPei (
56 IN CONST EFI_PEI_SERVICES **PeiServices,
57 IN EFI_STATUS_CODE_TYPE CodeType,
58 IN EFI_STATUS_CODE_VALUE Value,
59 IN UINT32 Instance,
60 IN CONST EFI_GUID *CallerId,
61 IN CONST EFI_STATUS_CODE_DATA *Data
62 )
63 {
64 EFI_STATUS Status;
65 UINT64 CurrentTime;
66 UINTN VarSize;
67 EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer;
68 S3_PERFORMANCE_TABLE *AcpiS3PerformanceTable;
69 EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD *AcpiS3ResumeRecord;
70 UINT64 S3ResumeTotal;
71 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD S3SuspendRecord;
72 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD *AcpiS3SuspendRecord;
73
74 //
75 // Check whether status code is what we are interested in.
76 //
77 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) ||
78 (Value != (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_OS_WAKE))) {
79 return EFI_UNSUPPORTED;
80 }
81
82 //
83 // Retrieve current time as early as possible.
84 //
85 CurrentTime = GetTimeInNanoSecond (GetPerformanceCounter ());
86
87 //
88 // Update S3 Resume Performance Record.
89 //
90 S3PerformanceTablePointer = 0;
91 VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
92 Status = RestoreLockBox (&gFirmwarePerformanceS3PointerGuid, &S3PerformanceTablePointer, &VarSize);
93 ASSERT_EFI_ERROR (Status);
94
95 AcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) S3PerformanceTablePointer;
96 ASSERT (AcpiS3PerformanceTable != NULL);
97 if (AcpiS3PerformanceTable->Header.Signature != EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE) {
98 DEBUG ((EFI_D_ERROR, "FPDT S3 performance data in ACPI memory get corrupted\n"));
99 return EFI_ABORTED;
100 }
101 AcpiS3ResumeRecord = &AcpiS3PerformanceTable->S3Resume;
102 AcpiS3ResumeRecord->FullResume = CurrentTime;
103 //
104 // Calculate average S3 resume time.
105 //
106 S3ResumeTotal = MultU64x32 (AcpiS3ResumeRecord->AverageResume, AcpiS3ResumeRecord->ResumeCount);
107 AcpiS3ResumeRecord->ResumeCount++;
108 AcpiS3ResumeRecord->AverageResume = DivU64x32 (S3ResumeTotal + AcpiS3ResumeRecord->FullResume, AcpiS3ResumeRecord->ResumeCount);
109
110 DEBUG ((EFI_D_INFO, "FPDT: S3 Resume Performance - ResumeCount = %d\n", AcpiS3ResumeRecord->ResumeCount));
111 DEBUG ((EFI_D_INFO, "FPDT: S3 Resume Performance - FullResume = %ld\n", AcpiS3ResumeRecord->FullResume));
112 DEBUG ((EFI_D_INFO, "FPDT: S3 Resume Performance - AverageResume = %ld\n", AcpiS3ResumeRecord->AverageResume));
113
114 //
115 // Update S3 Suspend Performance Record.
116 //
117 AcpiS3SuspendRecord = &AcpiS3PerformanceTable->S3Suspend;
118 VarSize = sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD);
119 ZeroMem (&S3SuspendRecord, sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD));
120 Status = RestoreLockBox (
121 &gEfiFirmwarePerformanceGuid,
122 &S3SuspendRecord,
123 &VarSize
124 );
125 ASSERT_EFI_ERROR (Status);
126
127 AcpiS3SuspendRecord->SuspendStart = S3SuspendRecord.SuspendStart;
128 AcpiS3SuspendRecord->SuspendEnd = S3SuspendRecord.SuspendEnd;
129
130 DEBUG ((EFI_D_INFO, "FPDT: S3 Suspend Performance - SuspendStart = %ld\n", AcpiS3SuspendRecord->SuspendStart));
131 DEBUG ((EFI_D_INFO, "FPDT: S3 Suspend Performance - SuspendEnd = %ld\n", AcpiS3SuspendRecord->SuspendEnd));
132
133 return EFI_SUCCESS;
134 }
135
136 /**
137 Main entry for Firmware Performance Data Table PEIM.
138
139 This routine is to register report status code listener for FPDT.
140
141 @param[in] FileHandle Handle of the file being invoked.
142 @param[in] PeiServices Pointer to PEI Services table.
143
144 @retval EFI_SUCCESS Report status code listener is registered successfully.
145
146 **/
147 EFI_STATUS
148 EFIAPI
149 FirmwarePerformancePeiEntryPoint (
150 IN EFI_PEI_FILE_HANDLE FileHandle,
151 IN CONST EFI_PEI_SERVICES **PeiServices
152 )
153 {
154 EFI_STATUS Status;
155 EFI_PEI_RSC_HANDLER_PPI *RscHandler;
156
157 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
158 //
159 // S3 resume - register status code listener for OS wake vector.
160 //
161 Status = PeiServicesLocatePpi (
162 &gEfiPeiRscHandlerPpiGuid,
163 0,
164 NULL,
165 (VOID **) &RscHandler
166 );
167 ASSERT_EFI_ERROR (Status);
168
169 Status = RscHandler->Register (FpdtStatusCodeListenerPei);
170 ASSERT_EFI_ERROR (Status);
171 }
172
173 return EFI_SUCCESS;
174 }