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