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 - 2016, 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/SmmCommunication.h>
24 #include <Protocol/SmmVariable.h>
26 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= 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_SMM_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_SMM_COMMUNICATE_HEADER
, Data
);
54 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) &SmmCommunicateHeader
->Data
[0];
55 SmmVariableFunctionHeader
->Function
= SMM_VARIABLE_FUNCTION_GET_STATISTICS
;
57 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, SmmCommunicateHeader
, SmmCommunicateSize
);
58 ASSERT_EFI_ERROR (Status
);
60 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
66 This function get and print the variable statistics data from SMM variable driver.
68 @retval EFI_SUCCESS Print the statistics information successfully.
69 @retval EFI_NOT_FOUND Not found the statistics information.
78 VARIABLE_INFO_ENTRY
*VariableInfo
;
79 EFI_SMM_COMMUNICATE_HEADER
*CommBuffer
;
82 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
83 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
84 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*PiSmmCommunicationRegionTable
;
86 EFI_MEMORY_DESCRIPTOR
*Entry
;
90 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**) &Smmvariable
);
91 if (EFI_ERROR (Status
)) {
95 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
96 if (EFI_ERROR (Status
)) {
102 Status
= EfiGetSystemConfigurationTable (
103 &gEdkiiPiSmmCommunicationRegionTableGuid
,
104 (VOID
**) &PiSmmCommunicationRegionTable
106 if (EFI_ERROR (Status
)) {
109 ASSERT (PiSmmCommunicationRegionTable
!= NULL
);
110 Entry
= (EFI_MEMORY_DESCRIPTOR
*) (PiSmmCommunicationRegionTable
+ 1);
113 for (Index
= 0; Index
< PiSmmCommunicationRegionTable
->NumberOfEntries
; Index
++) {
114 if (Entry
->Type
== EfiConventionalMemory
) {
115 Size
= EFI_PAGES_TO_SIZE ((UINTN
) Entry
->NumberOfPages
);
116 if (Size
> (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
+ sizeof (VARIABLE_INFO_ENTRY
))) {
117 if (Size
> MaxSize
) {
119 RealCommSize
= MaxSize
;
120 CommBuffer
= (EFI_SMM_COMMUNICATE_HEADER
*) (UINTN
) Entry
->PhysicalStart
;
124 Entry
= (EFI_MEMORY_DESCRIPTOR
*) ((UINT8
*) Entry
+ PiSmmCommunicationRegionTable
->DescriptorSize
);
126 ASSERT (CommBuffer
!= NULL
);
127 ZeroMem (CommBuffer
, RealCommSize
);
129 Print (L
"Non-Volatile SMM Variables:\n");
131 CommSize
= RealCommSize
;
132 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
133 if (Status
== EFI_BUFFER_TOO_SMALL
) {
134 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
138 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
142 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
143 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
145 if (!VariableInfo
->Volatile
) {
147 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
148 &VariableInfo
->VendorGuid
,
149 VariableInfo
->ReadCount
,
150 VariableInfo
->CacheCount
,
151 VariableInfo
->WriteCount
,
152 VariableInfo
->DeleteCount
,
153 (CHAR16
*)(VariableInfo
+ 1)
158 Print (L
"Volatile SMM Variables:\n");
159 ZeroMem (CommBuffer
, RealCommSize
);
161 CommSize
= RealCommSize
;
162 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
163 if (Status
== EFI_BUFFER_TOO_SMALL
) {
164 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
168 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
172 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
173 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
175 if (VariableInfo
->Volatile
) {
177 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
178 &VariableInfo
->VendorGuid
,
179 VariableInfo
->ReadCount
,
180 VariableInfo
->CacheCount
,
181 VariableInfo
->WriteCount
,
182 VariableInfo
->DeleteCount
,
183 (CHAR16
*)(VariableInfo
+ 1)
192 The user Entry Point for Application. The user code starts with this function
193 as the real entry point for the image goes into a library that calls this
196 @param[in] ImageHandle The firmware allocated handle for the EFI image.
197 @param[in] SystemTable A pointer to the EFI System Table.
199 @retval EFI_SUCCESS The entry point is executed successfully.
200 @retval other Some error occurs when executing this entry point.
206 IN EFI_HANDLE ImageHandle
,
207 IN EFI_SYSTEM_TABLE
*SystemTable
211 VARIABLE_INFO_ENTRY
*VariableInfo
;
212 VARIABLE_INFO_ENTRY
*Entry
;
214 Status
= EfiGetSystemConfigurationTable (&gEfiVariableGuid
, (VOID
**)&Entry
);
215 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
216 Status
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**)&Entry
);
219 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
220 Status
= PrintInfoFromSmm ();
221 if (!EFI_ERROR (Status
)) {
226 if (!EFI_ERROR (Status
) && (Entry
!= NULL
)) {
227 Print (L
"Non-Volatile EFI Variables:\n");
228 VariableInfo
= Entry
;
230 if (!VariableInfo
->Volatile
) {
232 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
233 &VariableInfo
->VendorGuid
,
234 VariableInfo
->ReadCount
,
235 VariableInfo
->CacheCount
,
236 VariableInfo
->WriteCount
,
237 VariableInfo
->DeleteCount
,
242 VariableInfo
= VariableInfo
->Next
;
243 } while (VariableInfo
!= NULL
);
245 Print (L
"Volatile EFI Variables:\n");
246 VariableInfo
= Entry
;
248 if (VariableInfo
->Volatile
) {
250 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
251 &VariableInfo
->VendorGuid
,
252 VariableInfo
->ReadCount
,
253 VariableInfo
->CacheCount
,
254 VariableInfo
->WriteCount
,
255 VariableInfo
->DeleteCount
,
259 VariableInfo
= VariableInfo
->Next
;
260 } while (VariableInfo
!= NULL
);
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");