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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/UefiLib.h>
19 #include <Library/UefiApplicationEntryPoint.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/BaseLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
26 #include <Guid/VariableFormat.h>
27 #include <Guid/SmmVariableCommon.h>
28 #include <Guid/PiSmmCommunicationRegionTable.h>
29 #include <Protocol/SmmCommunication.h>
30 #include <Protocol/SmmVariable.h>
32 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
35 This function get the variable statistics data from SMM variable driver.
37 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will
38 be passed into an SMM environment. In output, a pointer
39 to a collection of data that comes from an SMM environment.
40 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.
42 @retval EFI_SUCCESS Get the statistics data information.
43 @retval EFI_NOT_FOUND Not found.
44 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
49 GetVariableStatisticsData (
50 IN OUT EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
,
51 IN OUT UINTN
*SmmCommunicateSize
55 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
57 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
58 SmmCommunicateHeader
->MessageLength
= *SmmCommunicateSize
- OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
60 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) &SmmCommunicateHeader
->Data
[0];
61 SmmVariableFunctionHeader
->Function
= SMM_VARIABLE_FUNCTION_GET_STATISTICS
;
63 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, SmmCommunicateHeader
, SmmCommunicateSize
);
64 ASSERT_EFI_ERROR (Status
);
66 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
72 This function get and print the variable statistics data from SMM variable driver.
74 @retval EFI_SUCCESS Print the statistics information successfully.
75 @retval EFI_NOT_FOUND Not found the statistics information.
84 VARIABLE_INFO_ENTRY
*VariableInfo
;
85 EFI_SMM_COMMUNICATE_HEADER
*CommBuffer
;
88 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
89 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
90 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*PiSmmCommunicationRegionTable
;
92 EFI_MEMORY_DESCRIPTOR
*Entry
;
96 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**) &Smmvariable
);
97 if (EFI_ERROR (Status
)) {
101 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
102 if (EFI_ERROR (Status
)) {
108 Status
= EfiGetSystemConfigurationTable (
109 &gEdkiiPiSmmCommunicationRegionTableGuid
,
110 (VOID
**) &PiSmmCommunicationRegionTable
112 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_SMM_COMMUNICATE_HEADER
*) (UINTN
) Entry
->PhysicalStart
;
130 Entry
= (EFI_MEMORY_DESCRIPTOR
*) ((UINT8
*) Entry
+ PiSmmCommunicationRegionTable
->DescriptorSize
);
132 ASSERT (CommBuffer
!= NULL
);
133 ZeroMem (CommBuffer
, RealCommSize
);
135 Print (L
"Non-Volatile SMM Variables:\n");
137 CommSize
= RealCommSize
;
138 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
139 if (Status
== EFI_BUFFER_TOO_SMALL
) {
140 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
144 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
148 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
149 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
151 if (!VariableInfo
->Volatile
) {
153 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
154 &VariableInfo
->VendorGuid
,
155 VariableInfo
->ReadCount
,
156 VariableInfo
->CacheCount
,
157 VariableInfo
->WriteCount
,
158 VariableInfo
->DeleteCount
,
159 (CHAR16
*)(VariableInfo
+ 1)
164 Print (L
"Volatile SMM Variables:\n");
165 ZeroMem (CommBuffer
, RealCommSize
);
167 CommSize
= RealCommSize
;
168 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
169 if (Status
== EFI_BUFFER_TOO_SMALL
) {
170 Print (L
"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");
174 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
178 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
179 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
181 if (VariableInfo
->Volatile
) {
183 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
184 &VariableInfo
->VendorGuid
,
185 VariableInfo
->ReadCount
,
186 VariableInfo
->CacheCount
,
187 VariableInfo
->WriteCount
,
188 VariableInfo
->DeleteCount
,
189 (CHAR16
*)(VariableInfo
+ 1)
198 The user Entry Point for Application. The user code starts with this function
199 as the real entry point for the image goes into a library that calls this
202 @param[in] ImageHandle The firmware allocated handle for the EFI image.
203 @param[in] SystemTable A pointer to the EFI System Table.
205 @retval EFI_SUCCESS The entry point is executed successfully.
206 @retval other Some error occurs when executing this entry point.
212 IN EFI_HANDLE ImageHandle
,
213 IN EFI_SYSTEM_TABLE
*SystemTable
217 VARIABLE_INFO_ENTRY
*VariableInfo
;
218 VARIABLE_INFO_ENTRY
*Entry
;
220 Status
= EfiGetSystemConfigurationTable (&gEfiVariableGuid
, (VOID
**)&Entry
);
221 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
222 Status
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**)&Entry
);
225 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
226 Status
= PrintInfoFromSmm ();
227 if (!EFI_ERROR (Status
)) {
232 if (!EFI_ERROR (Status
) && (Entry
!= NULL
)) {
233 Print (L
"Non-Volatile EFI Variables:\n");
234 VariableInfo
= Entry
;
236 if (!VariableInfo
->Volatile
) {
238 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
239 &VariableInfo
->VendorGuid
,
240 VariableInfo
->ReadCount
,
241 VariableInfo
->CacheCount
,
242 VariableInfo
->WriteCount
,
243 VariableInfo
->DeleteCount
,
248 VariableInfo
= VariableInfo
->Next
;
249 } while (VariableInfo
!= NULL
);
251 Print (L
"Volatile EFI Variables:\n");
252 VariableInfo
= Entry
;
254 if (VariableInfo
->Volatile
) {
256 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
257 &VariableInfo
->VendorGuid
,
258 VariableInfo
->ReadCount
,
259 VariableInfo
->CacheCount
,
260 VariableInfo
->WriteCount
,
261 VariableInfo
->DeleteCount
,
265 VariableInfo
= VariableInfo
->Next
;
266 } while (VariableInfo
!= NULL
);
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");