2 If the Variable services have PcdVariableCollectStatistics set to TRUE then
3 this utility will print out the statistics information. You can use console
4 redirection to capture the data.
6 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/UefiLib.h>
13 #include <Library/UefiApplicationEntryPoint.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/MemoryAllocationLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
20 #include <Guid/VariableFormat.h>
21 #include <Guid/SmmVariableCommon.h>
22 #include <Guid/PiSmmCommunicationRegionTable.h>
23 #include <Protocol/MmCommunication2.h>
24 #include <Protocol/SmmVariable.h>
26 EFI_MM_COMMUNICATION2_PROTOCOL
*mMmCommunication2
= NULL
;
29 This function get the variable statistics data from SMM variable driver.
31 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will
32 be passed into an SMM environment. In output, a pointer
33 to a collection of data that comes from an SMM environment.
34 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.
36 @retval EFI_SUCCESS Get the statistics data information.
37 @retval EFI_NOT_FOUND Not found.
38 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
43 GetVariableStatisticsData (
44 IN OUT EFI_MM_COMMUNICATE_HEADER
*SmmCommunicateHeader
,
45 IN OUT UINTN
*SmmCommunicateSize
49 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
51 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
52 SmmCommunicateHeader
->MessageLength
= *SmmCommunicateSize
- OFFSET_OF (EFI_MM_COMMUNICATE_HEADER
, Data
);
54 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*)&SmmCommunicateHeader
->Data
[0];
55 SmmVariableFunctionHeader
->Function
= SMM_VARIABLE_FUNCTION_GET_STATISTICS
;
57 Status
= mMmCommunication2
->Communicate (
63 ASSERT_EFI_ERROR (Status
);
65 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
71 This function get and print the variable statistics data from SMM variable driver.
73 @retval EFI_SUCCESS Print the statistics information successfully.
74 @retval EFI_NOT_FOUND Not found the statistics information.
83 VARIABLE_INFO_ENTRY
*VariableInfo
;
84 EFI_MM_COMMUNICATE_HEADER
*CommBuffer
;
87 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
88 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
89 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*PiSmmCommunicationRegionTable
;
91 EFI_MEMORY_DESCRIPTOR
*Entry
;
95 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**)&Smmvariable
);
96 if (EFI_ERROR (Status
)) {
100 Status
= gBS
->LocateProtocol (&gEfiMmCommunication2ProtocolGuid
, NULL
, (VOID
**)&mMmCommunication2
);
101 if (EFI_ERROR (Status
)) {
107 Status
= EfiGetSystemConfigurationTable (
108 &gEdkiiPiSmmCommunicationRegionTableGuid
,
109 (VOID
**)&PiSmmCommunicationRegionTable
111 if (EFI_ERROR (Status
)) {
115 ASSERT (PiSmmCommunicationRegionTable
!= NULL
);
116 Entry
= (EFI_MEMORY_DESCRIPTOR
*)(PiSmmCommunicationRegionTable
+ 1);
119 for (Index
= 0; Index
< PiSmmCommunicationRegionTable
->NumberOfEntries
; Index
++) {
120 if (Entry
->Type
== EfiConventionalMemory
) {
121 Size
= EFI_PAGES_TO_SIZE ((UINTN
)Entry
->NumberOfPages
);
122 if (Size
> (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
+ sizeof (VARIABLE_INFO_ENTRY
))) {
123 if (Size
> MaxSize
) {
125 RealCommSize
= MaxSize
;
126 CommBuffer
= (EFI_MM_COMMUNICATE_HEADER
*)(UINTN
)Entry
->PhysicalStart
;
131 Entry
= (EFI_MEMORY_DESCRIPTOR
*)((UINT8
*)Entry
+ PiSmmCommunicationRegionTable
->DescriptorSize
);
134 ASSERT (CommBuffer
!= NULL
);
135 ZeroMem (CommBuffer
, RealCommSize
);
137 Print (L
"SMM Driver Non-Volatile Variables:\n");
139 CommSize
= RealCommSize
;
140 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
141 if (Status
== EFI_BUFFER_TOO_SMALL
) {
142 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
146 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
150 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*)CommBuffer
->Data
;
151 VariableInfo
= (VARIABLE_INFO_ENTRY
*)FunctionHeader
->Data
;
153 if (!VariableInfo
->Volatile
) {
155 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
156 &VariableInfo
->VendorGuid
,
157 VariableInfo
->ReadCount
,
158 VariableInfo
->CacheCount
,
159 VariableInfo
->WriteCount
,
160 VariableInfo
->DeleteCount
,
161 (CHAR16
*)(VariableInfo
+ 1)
166 Print (L
"SMM Driver Volatile Variables:\n");
167 ZeroMem (CommBuffer
, RealCommSize
);
169 CommSize
= RealCommSize
;
170 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
171 if (Status
== EFI_BUFFER_TOO_SMALL
) {
172 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
176 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
180 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*)CommBuffer
->Data
;
181 VariableInfo
= (VARIABLE_INFO_ENTRY
*)FunctionHeader
->Data
;
183 if (VariableInfo
->Volatile
) {
185 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
186 &VariableInfo
->VendorGuid
,
187 VariableInfo
->ReadCount
,
188 VariableInfo
->CacheCount
,
189 VariableInfo
->WriteCount
,
190 VariableInfo
->DeleteCount
,
191 (CHAR16
*)(VariableInfo
+ 1)
200 The user Entry Point for Application. The user code starts with this function
201 as the real entry point for the image goes into a library that calls this
204 @param[in] ImageHandle The firmware allocated handle for the EFI image.
205 @param[in] SystemTable A pointer to the EFI System Table.
207 @retval EFI_SUCCESS The entry point is executed successfully.
208 @retval other Some error occurs when executing this entry point.
214 IN EFI_HANDLE ImageHandle
,
215 IN EFI_SYSTEM_TABLE
*SystemTable
218 EFI_STATUS RuntimeDxeStatus
;
219 EFI_STATUS SmmStatus
;
220 VARIABLE_INFO_ENTRY
*VariableInfo
;
221 VARIABLE_INFO_ENTRY
*Entry
;
223 RuntimeDxeStatus
= EfiGetSystemConfigurationTable (&gEfiVariableGuid
, (VOID
**)&Entry
);
224 if (EFI_ERROR (RuntimeDxeStatus
) || (Entry
== NULL
)) {
225 RuntimeDxeStatus
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**)&Entry
);
228 if (!EFI_ERROR (RuntimeDxeStatus
) && (Entry
!= NULL
)) {
229 Print (L
"Runtime DXE Driver Non-Volatile EFI Variables:\n");
230 VariableInfo
= Entry
;
232 if (!VariableInfo
->Volatile
) {
234 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
235 &VariableInfo
->VendorGuid
,
236 VariableInfo
->ReadCount
,
237 VariableInfo
->CacheCount
,
238 VariableInfo
->WriteCount
,
239 VariableInfo
->DeleteCount
,
244 VariableInfo
= VariableInfo
->Next
;
245 } while (VariableInfo
!= NULL
);
247 Print (L
"Runtime DXE Driver Volatile EFI Variables:\n");
248 VariableInfo
= Entry
;
250 if (VariableInfo
->Volatile
) {
252 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
253 &VariableInfo
->VendorGuid
,
254 VariableInfo
->ReadCount
,
255 VariableInfo
->CacheCount
,
256 VariableInfo
->WriteCount
,
257 VariableInfo
->DeleteCount
,
262 VariableInfo
= VariableInfo
->Next
;
263 } while (VariableInfo
!= NULL
);
266 SmmStatus
= PrintInfoFromSmm ();
268 if (EFI_ERROR (RuntimeDxeStatus
) && EFI_ERROR (SmmStatus
)) {
269 Print (L
"Warning: Variable Dxe/Smm driver doesn't enable the feature of statistical information!\n");
270 Print (L
"If you want to see this info, please:\n");
271 Print (L
" 1. Set PcdVariableCollectStatistics as TRUE\n");
272 Print (L
" 2. Rebuild Variable Dxe/Smm driver\n");
273 Print (L
" 3. Run \"VariableInfo\" cmd again\n");
275 return EFI_NOT_FOUND
;