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 (mMmCommunication2
,
61 ASSERT_EFI_ERROR (Status
);
63 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
69 This function get and print the variable statistics data from SMM variable driver.
71 @retval EFI_SUCCESS Print the statistics information successfully.
72 @retval EFI_NOT_FOUND Not found the statistics information.
81 VARIABLE_INFO_ENTRY
*VariableInfo
;
82 EFI_MM_COMMUNICATE_HEADER
*CommBuffer
;
85 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
86 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
87 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*PiSmmCommunicationRegionTable
;
89 EFI_MEMORY_DESCRIPTOR
*Entry
;
93 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**) &Smmvariable
);
94 if (EFI_ERROR (Status
)) {
98 Status
= gBS
->LocateProtocol (&gEfiMmCommunication2ProtocolGuid
, NULL
, (VOID
**) &mMmCommunication2
);
99 if (EFI_ERROR (Status
)) {
105 Status
= EfiGetSystemConfigurationTable (
106 &gEdkiiPiSmmCommunicationRegionTableGuid
,
107 (VOID
**) &PiSmmCommunicationRegionTable
109 if (EFI_ERROR (Status
)) {
112 ASSERT (PiSmmCommunicationRegionTable
!= NULL
);
113 Entry
= (EFI_MEMORY_DESCRIPTOR
*) (PiSmmCommunicationRegionTable
+ 1);
116 for (Index
= 0; Index
< PiSmmCommunicationRegionTable
->NumberOfEntries
; Index
++) {
117 if (Entry
->Type
== EfiConventionalMemory
) {
118 Size
= EFI_PAGES_TO_SIZE ((UINTN
) Entry
->NumberOfPages
);
119 if (Size
> (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
+ sizeof (VARIABLE_INFO_ENTRY
))) {
120 if (Size
> MaxSize
) {
122 RealCommSize
= MaxSize
;
123 CommBuffer
= (EFI_MM_COMMUNICATE_HEADER
*) (UINTN
) Entry
->PhysicalStart
;
127 Entry
= (EFI_MEMORY_DESCRIPTOR
*) ((UINT8
*) Entry
+ PiSmmCommunicationRegionTable
->DescriptorSize
);
129 ASSERT (CommBuffer
!= NULL
);
130 ZeroMem (CommBuffer
, RealCommSize
);
132 Print (L
"SMM Driver Non-Volatile Variables:\n");
134 CommSize
= RealCommSize
;
135 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
136 if (Status
== EFI_BUFFER_TOO_SMALL
) {
137 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
141 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
145 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
146 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
148 if (!VariableInfo
->Volatile
) {
150 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
151 &VariableInfo
->VendorGuid
,
152 VariableInfo
->ReadCount
,
153 VariableInfo
->CacheCount
,
154 VariableInfo
->WriteCount
,
155 VariableInfo
->DeleteCount
,
156 (CHAR16
*)(VariableInfo
+ 1)
161 Print (L
"SMM Driver Volatile Variables:\n");
162 ZeroMem (CommBuffer
, RealCommSize
);
164 CommSize
= RealCommSize
;
165 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
166 if (Status
== EFI_BUFFER_TOO_SMALL
) {
167 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
171 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
175 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
176 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
178 if (VariableInfo
->Volatile
) {
180 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
181 &VariableInfo
->VendorGuid
,
182 VariableInfo
->ReadCount
,
183 VariableInfo
->CacheCount
,
184 VariableInfo
->WriteCount
,
185 VariableInfo
->DeleteCount
,
186 (CHAR16
*)(VariableInfo
+ 1)
195 The user Entry Point for Application. The user code starts with this function
196 as the real entry point for the image goes into a library that calls this
199 @param[in] ImageHandle The firmware allocated handle for the EFI image.
200 @param[in] SystemTable A pointer to the EFI System Table.
202 @retval EFI_SUCCESS The entry point is executed successfully.
203 @retval other Some error occurs when executing this entry point.
209 IN EFI_HANDLE ImageHandle
,
210 IN EFI_SYSTEM_TABLE
*SystemTable
213 EFI_STATUS RuntimeDxeStatus
;
214 EFI_STATUS SmmStatus
;
215 VARIABLE_INFO_ENTRY
*VariableInfo
;
216 VARIABLE_INFO_ENTRY
*Entry
;
218 RuntimeDxeStatus
= EfiGetSystemConfigurationTable (&gEfiVariableGuid
, (VOID
**) &Entry
);
219 if (EFI_ERROR (RuntimeDxeStatus
) || (Entry
== NULL
)) {
220 RuntimeDxeStatus
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**) &Entry
);
223 if (!EFI_ERROR (RuntimeDxeStatus
) && (Entry
!= NULL
)) {
224 Print (L
"Runtime DXE Driver Non-Volatile EFI Variables:\n");
225 VariableInfo
= Entry
;
227 if (!VariableInfo
->Volatile
) {
229 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
230 &VariableInfo
->VendorGuid
,
231 VariableInfo
->ReadCount
,
232 VariableInfo
->CacheCount
,
233 VariableInfo
->WriteCount
,
234 VariableInfo
->DeleteCount
,
239 VariableInfo
= VariableInfo
->Next
;
240 } while (VariableInfo
!= NULL
);
242 Print (L
"Runtime DXE Driver Volatile EFI Variables:\n");
243 VariableInfo
= Entry
;
245 if (VariableInfo
->Volatile
) {
247 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
248 &VariableInfo
->VendorGuid
,
249 VariableInfo
->ReadCount
,
250 VariableInfo
->CacheCount
,
251 VariableInfo
->WriteCount
,
252 VariableInfo
->DeleteCount
,
256 VariableInfo
= VariableInfo
->Next
;
257 } while (VariableInfo
!= NULL
);
260 SmmStatus
= PrintInfoFromSmm ();
262 if (EFI_ERROR (RuntimeDxeStatus
) && EFI_ERROR (SmmStatus
)) {
263 Print (L
"Warning: Variable Dxe/Smm driver doesn't enable the feature of statistical information!\n");
264 Print (L
"If you want to see this info, please:\n");
265 Print (L
" 1. Set PcdVariableCollectStatistics as TRUE\n");
266 Print (L
" 2. Rebuild Variable Dxe/Smm driver\n");
267 Print (L
" 3. Run \"VariableInfo\" cmd again\n");
269 return EFI_NOT_FOUND
;