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