TianoCore EDK2 master
Loading...
Searching...
No Matches
VariableInfo.c
Go to the documentation of this file.
1
11#include <Uefi.h>
12#include <Library/UefiLib.h>
15#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
19
20#include <Guid/VariableFormat.h>
25
26EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL;
27
42EFIAPI
44 IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader,
45 IN OUT UINTN *SmmCommunicateSize
46 )
47{
48 EFI_STATUS Status;
49 SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;
50
51 CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
52 SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
53
54 SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)&SmmCommunicateHeader->Data[0];
55 SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS;
56
57 Status = mMmCommunication2->Communicate (
58 mMmCommunication2,
59 SmmCommunicateHeader,
60 SmmCommunicateHeader,
61 SmmCommunicateSize
62 );
63 ASSERT_EFI_ERROR (Status);
64
65 Status = SmmVariableFunctionHeader->ReturnStatus;
66 return Status;
67}
68
79 VOID
80 )
81{
82 EFI_STATUS Status;
83 VARIABLE_INFO_ENTRY *VariableInfo;
84 EFI_MM_COMMUNICATE_HEADER *CommBuffer;
85 UINTN RealCommSize;
86 UINTN CommSize;
87 SMM_VARIABLE_COMMUNICATE_HEADER *FunctionHeader;
88 EFI_SMM_VARIABLE_PROTOCOL *Smmvariable;
89 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable;
90 UINT32 Index;
92 UINTN Size;
93 UINTN MaxSize;
94
95 Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **)&Smmvariable);
96 if (EFI_ERROR (Status)) {
97 return Status;
98 }
99
100 Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2);
101 if (EFI_ERROR (Status)) {
102 return Status;
103 }
104
105 CommBuffer = NULL;
106 RealCommSize = 0;
108 &gEdkiiPiSmmCommunicationRegionTableGuid,
109 (VOID **)&PiSmmCommunicationRegionTable
110 );
111 if (EFI_ERROR (Status)) {
112 return Status;
113 }
114
115 ASSERT (PiSmmCommunicationRegionTable != NULL);
116 Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1);
117 Size = 0;
118 MaxSize = 0;
119 for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
120 if (Entry->Type == EfiConventionalMemory) {
121 Size = EFI_PAGES_TO_SIZE ((UINTN)Entry->NumberOfPages);
123 if (Size > MaxSize) {
124 MaxSize = Size;
125 RealCommSize = MaxSize;
126 CommBuffer = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)Entry->PhysicalStart;
127 }
128 }
129 }
130
131 Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);
132 }
133
134 ASSERT (CommBuffer != NULL);
135 ZeroMem (CommBuffer, RealCommSize);
136
137 Print (L"SMM Driver Non-Volatile Variables:\n");
138 do {
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");
143 return Status;
144 }
145
146 if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) {
147 break;
148 }
149
150 FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer->Data;
151 VariableInfo = (VARIABLE_INFO_ENTRY *)FunctionHeader->Data;
152
153 if (!VariableInfo->Volatile) {
154 Print (
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)
162 );
163 }
164 } while (TRUE);
165
166 Print (L"SMM Driver Volatile Variables:\n");
167 ZeroMem (CommBuffer, RealCommSize);
168 do {
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");
173 return Status;
174 }
175
176 if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) {
177 break;
178 }
179
180 FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer->Data;
181 VariableInfo = (VARIABLE_INFO_ENTRY *)FunctionHeader->Data;
182
183 if (VariableInfo->Volatile) {
184 Print (
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)
192 );
193 }
194 } while (TRUE);
195
196 return Status;
197}
198
212EFIAPI
214 IN EFI_HANDLE ImageHandle,
215 IN EFI_SYSTEM_TABLE *SystemTable
216 )
217{
218 EFI_STATUS RuntimeDxeStatus;
219 EFI_STATUS SmmStatus;
220 VARIABLE_INFO_ENTRY *VariableInfo;
221 VARIABLE_INFO_ENTRY *Entry;
222
223 RuntimeDxeStatus = EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&Entry);
224 if (EFI_ERROR (RuntimeDxeStatus) || (Entry == NULL)) {
225 RuntimeDxeStatus = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry);
226 }
227
228 if (!EFI_ERROR (RuntimeDxeStatus) && (Entry != NULL)) {
229 Print (L"Runtime DXE Driver Non-Volatile EFI Variables:\n");
230 VariableInfo = Entry;
231 do {
232 if (!VariableInfo->Volatile) {
233 Print (
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,
240 VariableInfo->Name
241 );
242 }
243
244 VariableInfo = VariableInfo->Next;
245 } while (VariableInfo != NULL);
246
247 Print (L"Runtime DXE Driver Volatile EFI Variables:\n");
248 VariableInfo = Entry;
249 do {
250 if (VariableInfo->Volatile) {
251 Print (
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,
258 VariableInfo->Name
259 );
260 }
261
262 VariableInfo = VariableInfo->Next;
263 } while (VariableInfo != NULL);
264 }
265
266 SmmStatus = PrintInfoFromSmm ();
267
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");
274
275 return EFI_NOT_FOUND;
276 }
277
278 return EFI_SUCCESS;
279}
UINT64 UINTN
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define SMM_COMMUNICATE_HEADER_SIZE
#define SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113
@ EfiConventionalMemory
EFI_STATUS PrintInfoFromSmm(VOID)
Definition: VariableInfo.c:78
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: VariableInfo.c:213
EFI_STATUS EFIAPI GetVariableStatisticsData(IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader, IN OUT UINTN *SmmCommunicateSize)
Definition: VariableInfo.c:43
UINT32 DeleteCount
Number of times to delete this variable.
VARIABLE_INFO_ENTRY * Next
Pointer to next entry.
UINT32 CacheCount
Number of times that cache hits this variable.
UINT32 ReadCount
Number of times to read this variable.
CHAR16 * Name
Name of Variable.
BOOLEAN Volatile
TRUE if volatile, FALSE if non-volatile.
EFI_GUID VendorGuid
Guid of Variable.
UINT32 WriteCount
Number of times to write this variable.