]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Application/VariableInfo/VariableInfo.c
Clean up the private GUID definition in module Level.
[mirror_edk2.git] / SecurityPkg / Application / VariableInfo / VariableInfo.c
CommitLineData
0c18794e 1/** @file\r
2 If the Variable services have PcdVariableCollectStatistics set to TRUE then \r
3 this utility will print out the statistics information. You can use console \r
4 redirection to capture the data.\r
5 \r
6Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
7This program and the accompanying materials \r
8are licensed and made available under the terms and conditions of the BSD License \r
9which accompanies this distribution. The full text of the license may be found at \r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Uefi.h>\r
18#include <Library/UefiLib.h>\r
19#include <Library/UefiApplicationEntryPoint.h>\r
20#include <Library/BaseMemoryLib.h>\r
21\r
22#include <Library/BaseLib.h>\r
23#include <Library/MemoryAllocationLib.h>\r
24#include <Library/DebugLib.h>\r
25#include <Library/UefiBootServicesTableLib.h>\r
26\r
27#include <Guid/AuthenticatedVariableFormat.h>\r
28#include <Guid/SmmVariableCommon.h>\r
29#include <Protocol/SmmCommunication.h>\r
30#include <Protocol/SmmVariable.h>\r
31\r
a0c56a82 32extern EFI_GUID gEfiVariableGuid;\r
0c18794e 33EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r
34\r
35/**\r
36\r
37 This function get the variable statistics data from SMM variable driver. \r
38\r
39 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will\r
40 be passed into an SMM environment. In output, a pointer \r
41 to a collection of data that comes from an SMM environment.\r
42 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.\r
43 \r
44 @retval EFI_SUCCESS Get the statistics data information.\r
45 @retval EFI_NOT_FOUND Not found.\r
46 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r
47\r
48**/\r
49EFI_STATUS\r
50EFIAPI\r
51GetVariableStatisticsData (\r
52 IN OUT EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader,\r
53 IN OUT UINTN *SmmCommunicateSize\r
54 )\r
55{\r
56 EFI_STATUS Status;\r
57 SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;\r
58\r
59 CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);\r
60 SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
61\r
62 SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0];\r
63 SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS;\r
64 \r
65 Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, SmmCommunicateSize);\r
66 ASSERT_EFI_ERROR (Status);\r
67 \r
68 Status = SmmVariableFunctionHeader->ReturnStatus; \r
69 return Status;\r
70}\r
71\r
72\r
73/**\r
74\r
75 This function get and print the variable statistics data from SMM variable driver. \r
76 \r
77 @retval EFI_SUCCESS Print the statistics information successfully.\r
78 @retval EFI_NOT_FOUND Not found the statistics information.\r
79\r
80**/\r
81EFI_STATUS\r
82PrintInfoFromSmm (\r
83 VOID \r
84 )\r
85{\r
86 EFI_STATUS Status;\r
87 VARIABLE_INFO_ENTRY *VariableInfo;\r
88 EFI_SMM_COMMUNICATE_HEADER *CommBuffer;\r
89 UINTN RealCommSize;\r
90 UINTN CommSize;\r
91 SMM_VARIABLE_COMMUNICATE_HEADER *FunctionHeader;\r
92 EFI_SMM_VARIABLE_PROTOCOL *Smmvariable;\r
93 \r
94\r
95 Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable);\r
96 if (EFI_ERROR (Status)) {\r
97 return Status;\r
98 }\r
99\r
100 Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\r
101 if (EFI_ERROR (Status)) {\r
102 return Status;\r
103 } \r
104\r
105 CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
106 RealCommSize = CommSize;\r
107 CommBuffer = AllocateZeroPool (CommSize);\r
108 ASSERT (CommBuffer != NULL);\r
109 \r
110 Print (L"Non-Volatile SMM Variables:\n");\r
111 do {\r
112 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
113 if (Status == EFI_BUFFER_TOO_SMALL) {\r
114 FreePool (CommBuffer);\r
115 CommBuffer = AllocateZeroPool (CommSize);\r
116 ASSERT (CommBuffer != NULL);\r
117 RealCommSize = CommSize;\r
118 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
119 }\r
120\r
121 if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { \r
122 break;\r
123 }\r
124\r
125 if (CommSize < RealCommSize) {\r
126 CommSize = RealCommSize;\r
127 }\r
128\r
129 FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data;\r
130 VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data;\r
131\r
132 if (!VariableInfo->Volatile) {\r
133 Print (\r
134 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
135 &VariableInfo->VendorGuid, \r
136 VariableInfo->ReadCount,\r
137 VariableInfo->CacheCount,\r
138 VariableInfo->WriteCount,\r
139 VariableInfo->DeleteCount,\r
140 (CHAR16 *)(VariableInfo + 1)\r
141 );\r
142 }\r
143 } while (TRUE);\r
144 \r
145 Print (L"Volatile SMM Variables:\n");\r
146 ZeroMem (CommBuffer, CommSize);\r
147 do {\r
148 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
149 if (Status == EFI_BUFFER_TOO_SMALL) {\r
150 FreePool (CommBuffer);\r
151 CommBuffer = AllocateZeroPool (CommSize);\r
152 ASSERT (CommBuffer != NULL);\r
153 RealCommSize = CommSize;\r
154 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
155 }\r
156\r
157 if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { \r
158 break;\r
159 }\r
160\r
161 if (CommSize < RealCommSize) {\r
162 CommSize = RealCommSize;\r
163 }\r
164\r
165 FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data;\r
166 VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data;\r
167\r
168 if (VariableInfo->Volatile) {\r
169 Print (\r
170 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
171 &VariableInfo->VendorGuid, \r
172 VariableInfo->ReadCount,\r
173 VariableInfo->CacheCount,\r
174 VariableInfo->WriteCount,\r
175 VariableInfo->DeleteCount,\r
176 (CHAR16 *)(VariableInfo + 1)\r
177 );\r
178 }\r
179 } while (TRUE);\r
180\r
181 FreePool (CommBuffer); \r
182 return Status;\r
183}\r
184\r
185/**\r
186 The user Entry Point for Application. The user code starts with this function\r
187 as the real entry point for the image goes into a library that calls this \r
188 function.\r
189\r
190 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
191 @param[in] SystemTable A pointer to the EFI System Table.\r
192 \r
193 @retval EFI_SUCCESS The entry point is executed successfully.\r
194 @retval other Some error occurs when executing this entry point.\r
195\r
196**/\r
197EFI_STATUS\r
198EFIAPI\r
199UefiMain (\r
200 IN EFI_HANDLE ImageHandle,\r
201 IN EFI_SYSTEM_TABLE *SystemTable\r
202 )\r
203{\r
204 EFI_STATUS Status;\r
205 VARIABLE_INFO_ENTRY *VariableInfo;\r
206 VARIABLE_INFO_ENTRY *Entry;\r
207\r
a0c56a82 208 Status = EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&Entry);\r
0c18794e 209 if (EFI_ERROR (Status) || (Entry == NULL)) {\r
210 Status = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry);\r
211 }\r
212\r
213 if (EFI_ERROR (Status) || (Entry == NULL)) {\r
214 Status = PrintInfoFromSmm ();\r
215 if (!EFI_ERROR (Status)) {\r
216 return Status;\r
217 }\r
218 } \r
219\r
220 if (!EFI_ERROR (Status) && (Entry != NULL)) {\r
221 Print (L"Non-Volatile EFI Variables:\n");\r
222 VariableInfo = Entry;\r
223 do {\r
224 if (!VariableInfo->Volatile) {\r
225 Print (\r
226 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
227 &VariableInfo->VendorGuid, \r
228 VariableInfo->ReadCount,\r
229 VariableInfo->CacheCount,\r
230 VariableInfo->WriteCount,\r
231 VariableInfo->DeleteCount,\r
232 VariableInfo->Name\r
233 );\r
234 }\r
235\r
236 VariableInfo = VariableInfo->Next;\r
237 } while (VariableInfo != NULL);\r
238\r
239 Print (L"Volatile EFI Variables:\n");\r
240 VariableInfo = Entry;\r
241 do {\r
242 if (VariableInfo->Volatile) {\r
243 Print (\r
244 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
245 &VariableInfo->VendorGuid, \r
246 VariableInfo->ReadCount,\r
247 VariableInfo->CacheCount,\r
248 VariableInfo->WriteCount,\r
249 VariableInfo->DeleteCount,\r
250 VariableInfo->Name\r
251 );\r
252 }\r
253 VariableInfo = VariableInfo->Next;\r
254 } while (VariableInfo != NULL);\r
255\r
256 } else {\r
257 Print (L"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");\r
258 Print (L"If you want to see this info, please:\n");\r
259 Print (L" 1. Set PcdVariableCollectStatistics as TRUE\n");\r
260 Print (L" 2. Rebuild Variable Dxe driver\n");\r
261 Print (L" 3. Run \"VariableInfo\" cmd again\n");\r
262 }\r
263\r
264 return Status;\r
265}\r