]> 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
32#define EFI_VARIABLE_GUID \\r
33 { 0xddcf3616, 0x3275, 0x4164, { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d } }\r
34\r
35EFI_GUID mEfiVariableGuid = EFI_VARIABLE_GUID;\r
36EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r
37\r
38/**\r
39\r
40 This function get the variable statistics data from SMM variable driver. \r
41\r
42 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will\r
43 be passed into an SMM environment. In output, a pointer \r
44 to a collection of data that comes from an SMM environment.\r
45 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.\r
46 \r
47 @retval EFI_SUCCESS Get the statistics data information.\r
48 @retval EFI_NOT_FOUND Not found.\r
49 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r
50\r
51**/\r
52EFI_STATUS\r
53EFIAPI\r
54GetVariableStatisticsData (\r
55 IN OUT EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader,\r
56 IN OUT UINTN *SmmCommunicateSize\r
57 )\r
58{\r
59 EFI_STATUS Status;\r
60 SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;\r
61\r
62 CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);\r
63 SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
64\r
65 SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0];\r
66 SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS;\r
67 \r
68 Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, SmmCommunicateSize);\r
69 ASSERT_EFI_ERROR (Status);\r
70 \r
71 Status = SmmVariableFunctionHeader->ReturnStatus; \r
72 return Status;\r
73}\r
74\r
75\r
76/**\r
77\r
78 This function get and print the variable statistics data from SMM variable driver. \r
79 \r
80 @retval EFI_SUCCESS Print the statistics information successfully.\r
81 @retval EFI_NOT_FOUND Not found the statistics information.\r
82\r
83**/\r
84EFI_STATUS\r
85PrintInfoFromSmm (\r
86 VOID \r
87 )\r
88{\r
89 EFI_STATUS Status;\r
90 VARIABLE_INFO_ENTRY *VariableInfo;\r
91 EFI_SMM_COMMUNICATE_HEADER *CommBuffer;\r
92 UINTN RealCommSize;\r
93 UINTN CommSize;\r
94 SMM_VARIABLE_COMMUNICATE_HEADER *FunctionHeader;\r
95 EFI_SMM_VARIABLE_PROTOCOL *Smmvariable;\r
96 \r
97\r
98 Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable);\r
99 if (EFI_ERROR (Status)) {\r
100 return Status;\r
101 }\r
102\r
103 Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\r
104 if (EFI_ERROR (Status)) {\r
105 return Status;\r
106 } \r
107\r
108 CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
109 RealCommSize = CommSize;\r
110 CommBuffer = AllocateZeroPool (CommSize);\r
111 ASSERT (CommBuffer != NULL);\r
112 \r
113 Print (L"Non-Volatile SMM Variables:\n");\r
114 do {\r
115 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
116 if (Status == EFI_BUFFER_TOO_SMALL) {\r
117 FreePool (CommBuffer);\r
118 CommBuffer = AllocateZeroPool (CommSize);\r
119 ASSERT (CommBuffer != NULL);\r
120 RealCommSize = CommSize;\r
121 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
122 }\r
123\r
124 if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { \r
125 break;\r
126 }\r
127\r
128 if (CommSize < RealCommSize) {\r
129 CommSize = RealCommSize;\r
130 }\r
131\r
132 FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data;\r
133 VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data;\r
134\r
135 if (!VariableInfo->Volatile) {\r
136 Print (\r
137 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
138 &VariableInfo->VendorGuid, \r
139 VariableInfo->ReadCount,\r
140 VariableInfo->CacheCount,\r
141 VariableInfo->WriteCount,\r
142 VariableInfo->DeleteCount,\r
143 (CHAR16 *)(VariableInfo + 1)\r
144 );\r
145 }\r
146 } while (TRUE);\r
147 \r
148 Print (L"Volatile SMM Variables:\n");\r
149 ZeroMem (CommBuffer, CommSize);\r
150 do {\r
151 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
152 if (Status == EFI_BUFFER_TOO_SMALL) {\r
153 FreePool (CommBuffer);\r
154 CommBuffer = AllocateZeroPool (CommSize);\r
155 ASSERT (CommBuffer != NULL);\r
156 RealCommSize = CommSize;\r
157 Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
158 }\r
159\r
160 if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { \r
161 break;\r
162 }\r
163\r
164 if (CommSize < RealCommSize) {\r
165 CommSize = RealCommSize;\r
166 }\r
167\r
168 FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data;\r
169 VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data;\r
170\r
171 if (VariableInfo->Volatile) {\r
172 Print (\r
173 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
174 &VariableInfo->VendorGuid, \r
175 VariableInfo->ReadCount,\r
176 VariableInfo->CacheCount,\r
177 VariableInfo->WriteCount,\r
178 VariableInfo->DeleteCount,\r
179 (CHAR16 *)(VariableInfo + 1)\r
180 );\r
181 }\r
182 } while (TRUE);\r
183\r
184 FreePool (CommBuffer); \r
185 return Status;\r
186}\r
187\r
188/**\r
189 The user Entry Point for Application. The user code starts with this function\r
190 as the real entry point for the image goes into a library that calls this \r
191 function.\r
192\r
193 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
194 @param[in] SystemTable A pointer to the EFI System Table.\r
195 \r
196 @retval EFI_SUCCESS The entry point is executed successfully.\r
197 @retval other Some error occurs when executing this entry point.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202UefiMain (\r
203 IN EFI_HANDLE ImageHandle,\r
204 IN EFI_SYSTEM_TABLE *SystemTable\r
205 )\r
206{\r
207 EFI_STATUS Status;\r
208 VARIABLE_INFO_ENTRY *VariableInfo;\r
209 VARIABLE_INFO_ENTRY *Entry;\r
210\r
211 Status = EfiGetSystemConfigurationTable (&mEfiVariableGuid, (VOID **)&Entry);\r
212 if (EFI_ERROR (Status) || (Entry == NULL)) {\r
213 Status = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry);\r
214 }\r
215\r
216 if (EFI_ERROR (Status) || (Entry == NULL)) {\r
217 Status = PrintInfoFromSmm ();\r
218 if (!EFI_ERROR (Status)) {\r
219 return Status;\r
220 }\r
221 } \r
222\r
223 if (!EFI_ERROR (Status) && (Entry != NULL)) {\r
224 Print (L"Non-Volatile EFI Variables:\n");\r
225 VariableInfo = Entry;\r
226 do {\r
227 if (!VariableInfo->Volatile) {\r
228 Print (\r
229 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
230 &VariableInfo->VendorGuid, \r
231 VariableInfo->ReadCount,\r
232 VariableInfo->CacheCount,\r
233 VariableInfo->WriteCount,\r
234 VariableInfo->DeleteCount,\r
235 VariableInfo->Name\r
236 );\r
237 }\r
238\r
239 VariableInfo = VariableInfo->Next;\r
240 } while (VariableInfo != NULL);\r
241\r
242 Print (L"Volatile EFI Variables:\n");\r
243 VariableInfo = Entry;\r
244 do {\r
245 if (VariableInfo->Volatile) {\r
246 Print (\r
247 L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
248 &VariableInfo->VendorGuid, \r
249 VariableInfo->ReadCount,\r
250 VariableInfo->CacheCount,\r
251 VariableInfo->WriteCount,\r
252 VariableInfo->DeleteCount,\r
253 VariableInfo->Name\r
254 );\r
255 }\r
256 VariableInfo = VariableInfo->Next;\r
257 } while (VariableInfo != NULL);\r
258\r
259 } else {\r
260 Print (L"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");\r
261 Print (L"If you want to see this info, please:\n");\r
262 Print (L" 1. Set PcdVariableCollectStatistics as TRUE\n");\r
263 Print (L" 2. Rebuild Variable Dxe driver\n");\r
264 Print (L" 3. Run \"VariableInfo\" cmd again\n");\r
265 }\r
266\r
267 return Status;\r
268}\r