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