]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
Removes redundant code and adds data size check for certificate data in DxeImageVerif...
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableSmm / FirmwarePerformanceSmm.c
CommitLineData
0284e90c
LG
1/** @file\r
2 This module update S3 Suspend Performance Record in ACPI Firmware Performance Data Table.\r
3\r
4 This module register report status code listener to collect performance data\r
5 for S3 Suspend Performance Record.\r
6\r
7 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
8 This program and the accompanying materials\r
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include <PiSmm.h>\r
19\r
20#include <IndustryStandard/Acpi50.h>\r
21\r
22#include <Protocol/SmmReportStatusCodeHandler.h>\r
23\r
24#include <Guid/FirmwarePerformance.h>\r
25\r
26#include <Library/SmmServicesTableLib.h>\r
27#include <Library/BaseLib.h>\r
28#include <Library/DebugLib.h>\r
29#include <Library/TimerLib.h>\r
30#include <Library/LockBoxLib.h>\r
31#include <Library/PcdLib.h>\r
32\r
33EFI_SMM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;\r
34UINT64 mSuspendStartTime = 0;\r
35BOOLEAN mS3SuspendLockBoxSaved = FALSE;\r
36\r
37/**\r
38 Report status code listener for SMM. This is used to record the performance\r
39 data for S3 Suspend Start and S3 Suspend End in FPDT.\r
40\r
41 @param[in] CodeType Indicates the type of status code being reported.\r
42 @param[in] Value Describes the current status of a hardware or software entity.\r
43 This included information about the class and subclass that is used to\r
44 classify the entity as well as an operation.\r
45 @param[in] Instance The enumeration of a hardware or software entity within\r
46 the system. Valid instance numbers start with 1.\r
47 @param[in] CallerId This optional parameter may be used to identify the caller.\r
48 This parameter allows the status code driver to apply different rules to\r
49 different callers.\r
50 @param[in] Data This optional parameter may be used to pass additional data.\r
51\r
52 @retval EFI_SUCCESS Status code is what we expected.\r
53 @retval EFI_UNSUPPORTED Status code not supported.\r
54\r
55**/\r
56EFI_STATUS\r
57EFIAPI\r
58FpdtStatusCodeListenerSmm (\r
59 IN EFI_STATUS_CODE_TYPE CodeType,\r
60 IN EFI_STATUS_CODE_VALUE Value,\r
61 IN UINT32 Instance,\r
62 IN EFI_GUID *CallerId,\r
63 IN EFI_STATUS_CODE_DATA *Data\r
64 )\r
65{\r
66 EFI_STATUS Status;\r
67 UINT64 CurrentTime;\r
68 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD S3SuspendRecord;\r
69\r
70 //\r
71 // Check whether status code is what we are interested in.\r
72 //\r
73 if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {\r
74 return EFI_UNSUPPORTED;\r
75 }\r
76 if ((Value != PcdGet32 (PcdProgressCodeS3SuspendStart)) &&\r
77 (Value != PcdGet32 (PcdProgressCodeS3SuspendEnd))) {\r
78 return EFI_UNSUPPORTED;\r
79 }\r
80\r
81 //\r
82 // Retrieve current time.\r
83 //\r
84 CurrentTime = GetTimeInNanoSecond (GetPerformanceCounter ());\r
85\r
86 if (Value == PcdGet32 (PcdProgressCodeS3SuspendStart)) {\r
87 //\r
88 // S3 Suspend started, record the performance data and return.\r
89 //\r
90 mSuspendStartTime = CurrentTime;\r
91 return EFI_SUCCESS;\r
92 }\r
93\r
94 //\r
95 // We are going to S3 sleep, record S3 Suspend End performance data.\r
96 //\r
97 S3SuspendRecord.SuspendStart = mSuspendStartTime;\r
98 S3SuspendRecord.SuspendEnd = CurrentTime;\r
99\r
100 //\r
101 // Save S3 suspend performance data to lock box, it will be used by Firmware Performance PEIM.\r
102 //\r
103 if (!mS3SuspendLockBoxSaved) {\r
104 Status = SaveLockBox (\r
105 &gEfiFirmwarePerformanceGuid,\r
106 &S3SuspendRecord,\r
107 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD)\r
108 );\r
109 ASSERT_EFI_ERROR (Status);\r
110\r
111 mS3SuspendLockBoxSaved = TRUE;\r
112 } else {\r
113 Status = UpdateLockBox (\r
114 &gEfiFirmwarePerformanceGuid,\r
115 0,\r
116 &S3SuspendRecord,\r
117 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD)\r
118 );\r
119 ASSERT_EFI_ERROR (Status);\r
120 }\r
121\r
122 return EFI_SUCCESS;\r
123}\r
124\r
125/**\r
126 The module Entry Point of the Firmware Performance Data Table SMM driver.\r
127\r
128 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
129 @param[in] SystemTable A pointer to the EFI System Table.\r
130\r
131 @retval EFI_SUCCESS The entry point is executed successfully.\r
132 @retval Other Some error occurs when executing this entry point.\r
133\r
134**/\r
135EFI_STATUS\r
136EFIAPI\r
137FirmwarePerformanceSmmEntryPoint (\r
138 IN EFI_HANDLE ImageHandle,\r
139 IN EFI_SYSTEM_TABLE *SystemTable\r
140 )\r
141{\r
142 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {\r
143 EFI_STATUS Status;\r
144\r
145 //\r
146 // Get SMM Report Status Code Handler Protocol.\r
147 //\r
148 Status = gSmst->SmmLocateProtocol (\r
149 &gEfiSmmRscHandlerProtocolGuid,\r
150 NULL,\r
151 (VOID **) &mRscHandlerProtocol\r
152 );\r
153 ASSERT_EFI_ERROR (Status);\r
154\r
155 //\r
156 // Register report status code listener for S3 Suspend Start and End.\r
157 //\r
158 Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);\r
159 ASSERT_EFI_ERROR (Status);\r
160\r
161 return Status;\r
162 } else {\r
163 return EFI_UNSUPPORTED;\r
164 }\r
165}\r