]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableSmm / FirmwarePerformanceCommon.c
CommitLineData
0284e90c 1/** @file\r
06201d58 2 This module collects performance data for MM driver boot records and S3 Suspend Performance Record.\r
0284e90c 3\r
1c0cc375 4 This module registers report status code listener to collect performance data\r
06201d58 5 for MM driver boot records and S3 Suspend Performance Record.\r
0284e90c 6\r
ccd2f6b0 7 Caution: This module requires additional review when modified.\r
06201d58 8 This driver will have external input - communicate buffer in MM mode.\r
ccd2f6b0 9 This external input must be validated carefully to avoid security issue like\r
10 buffer overflow, integer overflow.\r
11\r
12 FpdtSmiHandler() will receive untrusted input and do basic validation.\r
13\r
466ebdd2 14 Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>\r
9d510e61 15 SPDX-License-Identifier: BSD-2-Clause-Patent\r
0284e90c
LG
16\r
17**/\r
18\r
06201d58 19#include <PiMm.h>\r
0284e90c 20\r
06201d58 21#include <Protocol/MmReportStatusCodeHandler.h>\r
0284e90c
LG
22\r
23#include <Guid/FirmwarePerformance.h>\r
24\r
06201d58 25#include <Library/MmServicesTableLib.h>\r
0284e90c
LG
26#include <Library/BaseLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/TimerLib.h>\r
29#include <Library/LockBoxLib.h>\r
30#include <Library/PcdLib.h>\r
1c0cc375 31#include <Library/BaseMemoryLib.h>\r
06201d58 32#include "FirmwarePerformanceCommon.h"\r
1c0cc375 33\r
1436aea4
MK
34EFI_MM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;\r
35UINT64 mSuspendStartTime = 0;\r
36BOOLEAN mS3SuspendLockBoxSaved = FALSE;\r
0284e90c
LG
37\r
38/**\r
06201d58 39 Report status code listener for MM. This is used to record the performance\r
0284e90c
LG
40 data for S3 Suspend Start and S3 Suspend End in FPDT.\r
41\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
57EFI_STATUS\r
58EFIAPI\r
06201d58 59FpdtStatusCodeListenerMm (\r
1436aea4
MK
60 IN EFI_STATUS_CODE_TYPE CodeType,\r
61 IN EFI_STATUS_CODE_VALUE Value,\r
62 IN UINT32 Instance,\r
63 IN EFI_GUID *CallerId,\r
64 IN EFI_STATUS_CODE_DATA *Data\r
0284e90c
LG
65 )\r
66{\r
67 EFI_STATUS Status;\r
68 UINT64 CurrentTime;\r
69 EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD S3SuspendRecord;\r
70\r
71 //\r
72 // Check whether status code is what we are interested in.\r
73 //\r
74 if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {\r
75 return EFI_UNSUPPORTED;\r
76 }\r
d1102dba 77\r
1436aea4 78 if ((Data != NULL) && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
06201d58 79 DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableMm\n"));\r
d4ee449d
DB
80 return EFI_UNSUPPORTED;\r
81 }\r
82\r
0284e90c 83 if ((Value != PcdGet32 (PcdProgressCodeS3SuspendStart)) &&\r
1436aea4
MK
84 (Value != PcdGet32 (PcdProgressCodeS3SuspendEnd)))\r
85 {\r
0284e90c
LG
86 return EFI_UNSUPPORTED;\r
87 }\r
88\r
89 //\r
90 // Retrieve current time.\r
91 //\r
92 CurrentTime = GetTimeInNanoSecond (GetPerformanceCounter ());\r
93\r
94 if (Value == PcdGet32 (PcdProgressCodeS3SuspendStart)) {\r
95 //\r
96 // S3 Suspend started, record the performance data and return.\r
97 //\r
98 mSuspendStartTime = CurrentTime;\r
99 return EFI_SUCCESS;\r
100 }\r
101\r
102 //\r
103 // We are going to S3 sleep, record S3 Suspend End performance data.\r
104 //\r
105 S3SuspendRecord.SuspendStart = mSuspendStartTime;\r
106 S3SuspendRecord.SuspendEnd = CurrentTime;\r
107\r
108 //\r
109 // Save S3 suspend performance data to lock box, it will be used by Firmware Performance PEIM.\r
110 //\r
111 if (!mS3SuspendLockBoxSaved) {\r
112 Status = SaveLockBox (\r
113 &gEfiFirmwarePerformanceGuid,\r
114 &S3SuspendRecord,\r
115 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD)\r
116 );\r
117 ASSERT_EFI_ERROR (Status);\r
118\r
119 mS3SuspendLockBoxSaved = TRUE;\r
120 } else {\r
121 Status = UpdateLockBox (\r
122 &gEfiFirmwarePerformanceGuid,\r
123 0,\r
124 &S3SuspendRecord,\r
125 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD)\r
126 );\r
127 ASSERT_EFI_ERROR (Status);\r
128 }\r
129\r
130 return EFI_SUCCESS;\r
131}\r
132\r
133/**\r
06201d58 134 The module Entry Point of the Firmware Performance Data Table MM driver.\r
0284e90c
LG
135\r
136 @retval EFI_SUCCESS The entry point is executed successfully.\r
137 @retval Other Some error occurs when executing this entry point.\r
138\r
139**/\r
140EFI_STATUS\r
06201d58
KQ
141FirmwarePerformanceCommonEntryPoint (\r
142 VOID\r
0284e90c
LG
143 )\r
144{\r
1436aea4 145 EFI_STATUS Status;\r
d1102dba 146\r
1c0cc375 147 //\r
06201d58 148 // Get MM Report Status Code Handler Protocol.\r
1c0cc375 149 //\r
06201d58
KQ
150 Status = gMmst->MmLocateProtocol (\r
151 &gEfiMmRscHandlerProtocolGuid,\r
1c0cc375 152 NULL,\r
1436aea4 153 (VOID **)&mRscHandlerProtocol\r
1c0cc375
LG
154 );\r
155 ASSERT_EFI_ERROR (Status);\r
0284e90c 156\r
1c0cc375
LG
157 //\r
158 // Register report status code listener for BootRecords and S3 Suspend Start and End.\r
159 //\r
06201d58 160 Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm);\r
1c0cc375 161 ASSERT_EFI_ERROR (Status);\r
0284e90c 162\r
1c0cc375 163 return Status;\r
0284e90c 164}\r