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