]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg VariableInfo: Merge from VariableInfo in SecurityPkg
authorStar Zeng <star.zeng@intel.com>
Wed, 1 Jul 2015 03:02:45 +0000 (03:02 +0000)
committerlzeng14 <lzeng14@Edk2>
Wed, 1 Jul 2015 03:02:45 +0000 (03:02 +0000)
What to do:
1. Merge VariableInfo in SecurityPkg to VariableInfo in MdeModulePkg.

Why to do:
1. Remove code duplication and reduce maintenance effort.
The functionality of VariableInfo in SecurityPkg has covered VariableInfo
in MdeModulePkg.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17755 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Application/VariableInfo/VariableInfo.c
MdeModulePkg/Application/VariableInfo/VariableInfo.inf
MdeModulePkg/Application/VariableInfo/VariableInfo.uni

index 50b67d097480605c013e132d927d60124a8ce30b..727e1ce105f32d531bb1d72187b3266e60374ba5 100644 (file)
 /** @file\r
-  If the Variable services have PcdVariableCollectStatistics set to TRUE then \r
-  the EFI system table will contain statistical information about variable usage\r
-  an this utility will print out the information. You can use console redirection\r
-  to capture the data.\r
-  \r
-  Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+  If the Variable services have PcdVariableCollectStatistics set to TRUE then\r
+  this utility will print out the statistics information. You can use console\r
+  redirection to capture the data.\r
+\r
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
 #include <Uefi.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/UefiApplicationEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
 #include <Guid/VariableFormat.h>\r
+#include <Guid/SmmVariableCommon.h>\r
+#include <Protocol/SmmCommunication.h>\r
+#include <Protocol/SmmVariable.h>\r
+\r
+EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication = NULL;\r
+\r
+/**\r
+  This function get the variable statistics data from SMM variable driver.\r
+\r
+  @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will\r
+                                       be passed into an SMM environment. In output, a pointer\r
+                                       to a collection of data that comes from an SMM environment.\r
+  @param[in, out] SmmCommunicateSize   The size of the SmmCommunicateHeader.\r
+\r
+  @retval EFI_SUCCESS               Get the statistics data information.\r
+  @retval EFI_NOT_FOUND             Not found.\r
+  @retval EFI_BUFFER_TO_SMALL       DataSize is too small for the result.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetVariableStatisticsData (\r
+  IN OUT  EFI_SMM_COMMUNICATE_HEADER  *SmmCommunicateHeader,\r
+  IN OUT  UINTN                       *SmmCommunicateSize\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  SMM_VARIABLE_COMMUNICATE_HEADER     *SmmVariableFunctionHeader;\r
+\r
+  CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);\r
+  SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r
+\r
+  SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0];\r
+  SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS;\r
 \r
+  Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, SmmCommunicateSize);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = SmmVariableFunctionHeader->ReturnStatus;\r
+  return Status;\r
+}\r
+\r
+/**\r
+\r
+  This function get and print the variable statistics data from SMM variable driver.\r
+\r
+  @retval EFI_SUCCESS               Print the statistics information successfully.\r
+  @retval EFI_NOT_FOUND             Not found the statistics information.\r
+\r
+**/\r
+EFI_STATUS\r
+PrintInfoFromSmm (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                                     Status;\r
+  VARIABLE_INFO_ENTRY                            *VariableInfo;\r
+  EFI_SMM_COMMUNICATE_HEADER                     *CommBuffer;\r
+  UINTN                                          RealCommSize;\r
+  UINTN                                          CommSize;\r
+  SMM_VARIABLE_COMMUNICATE_HEADER                *FunctionHeader;\r
+  EFI_SMM_VARIABLE_PROTOCOL                      *Smmvariable;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
+  RealCommSize = CommSize;\r
+  CommBuffer = AllocateZeroPool (CommSize);\r
+  ASSERT (CommBuffer != NULL);\r
+\r
+  Print (L"Non-Volatile SMM Variables:\n");\r
+  do {\r
+    Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      FreePool (CommBuffer);\r
+      CommBuffer = AllocateZeroPool (CommSize);\r
+      ASSERT (CommBuffer != NULL);\r
+      RealCommSize = CommSize;\r
+      Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
+    }\r
+\r
+    if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) {\r
+      break;\r
+    }\r
+\r
+    if (CommSize < RealCommSize) {\r
+      CommSize = RealCommSize;\r
+    }\r
+\r
+    FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data;\r
+    VariableInfo   = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data;\r
+\r
+    if (!VariableInfo->Volatile) {\r
+      Print (\r
+          L"%g R%03d(%03d) W%03d D%03d:%s\n",\r
+          &VariableInfo->VendorGuid,\r
+          VariableInfo->ReadCount,\r
+          VariableInfo->CacheCount,\r
+          VariableInfo->WriteCount,\r
+          VariableInfo->DeleteCount,\r
+          (CHAR16 *)(VariableInfo + 1)\r
+          );\r
+    }\r
+  } while (TRUE);\r
+\r
+  Print (L"Volatile SMM Variables:\n");\r
+  ZeroMem (CommBuffer, CommSize);\r
+  do {\r
+    Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      FreePool (CommBuffer);\r
+      CommBuffer = AllocateZeroPool (CommSize);\r
+      ASSERT (CommBuffer != NULL);\r
+      RealCommSize = CommSize;\r
+      Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
+    }\r
+\r
+    if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) {\r
+      break;\r
+    }\r
+\r
+    if (CommSize < RealCommSize) {\r
+      CommSize = RealCommSize;\r
+    }\r
+\r
+    FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data;\r
+    VariableInfo   = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data;\r
+\r
+    if (VariableInfo->Volatile) {\r
+      Print (\r
+          L"%g R%03d(%03d) W%03d D%03d:%s\n",\r
+          &VariableInfo->VendorGuid,\r
+          VariableInfo->ReadCount,\r
+          VariableInfo->CacheCount,\r
+          VariableInfo->WriteCount,\r
+          VariableInfo->DeleteCount,\r
+          (CHAR16 *)(VariableInfo + 1)\r
+          );\r
+    }\r
+  } while (TRUE);\r
+\r
+  FreePool (CommBuffer);\r
+  return Status;\r
+}\r
 \r
 /**\r
   The user Entry Point for Application. The user code starts with this function\r
-  as the real entry point for the image goes into a library that calls this \r
+  as the real entry point for the image goes into a library that calls this\r
   function.\r
 \r
-\r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
   @retval other             Some error occurs when executing this entry point.\r
 \r
@@ -46,14 +201,25 @@ UefiMain (
   VARIABLE_INFO_ENTRY   *Entry;\r
 \r
   Status = EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&Entry);\r
+  if (EFI_ERROR (Status) || (Entry == NULL)) {\r
+    Status = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry);\r
+  }\r
+\r
+  if (EFI_ERROR (Status) || (Entry == NULL)) {\r
+    Status = PrintInfoFromSmm ();\r
+    if (!EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   if (!EFI_ERROR (Status) && (Entry != NULL)) {\r
     Print (L"Non-Volatile EFI Variables:\n");\r
     VariableInfo = Entry;\r
     do {\r
       if (!VariableInfo->Volatile) {\r
         Print (\r
-          L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
-          &VariableInfo->VendorGuid,  \r
+          L"%g R%03d(%03d) W%03d D%03d:%s\n",\r
+          &VariableInfo->VendorGuid,\r
           VariableInfo->ReadCount,\r
           VariableInfo->CacheCount,\r
           VariableInfo->WriteCount,\r
@@ -70,8 +236,8 @@ UefiMain (
     do {\r
       if (VariableInfo->Volatile) {\r
         Print (\r
-          L"%g R%03d(%03d) W%03d D%03d:%s\n", \r
-          &VariableInfo->VendorGuid,  \r
+          L"%g R%03d(%03d) W%03d D%03d:%s\n",\r
+          &VariableInfo->VendorGuid,\r
           VariableInfo->ReadCount,\r
           VariableInfo->CacheCount,\r
           VariableInfo->WriteCount,\r
@@ -88,7 +254,6 @@ UefiMain (
     Print (L"  1. Set PcdVariableCollectStatistics as TRUE\n");\r
     Print (L"  2. Rebuild Variable Dxe driver\n");\r
     Print (L"  3. Run \"VariableInfo\" cmd again\n");\r
-\r
   }\r
 \r
   return Status;\r
index 4d9dc71565a2473f5455981bd6237653141364b0..f76637a2f5fbd2421950248c77c306526c7710a9 100644 (file)
@@ -1,9 +1,12 @@
 ## @file\r
-#  This is a shell application that will display statistical information about variable usage.\r
+#  A shell application that displays statistical information about variable usage.\r
+#\r
+#  This application can display statistical information about variable usage for SMM variable\r
+#  driver and non-SMM variable driver.\r
 #  Note that if Variable Dxe driver doesn't enable the feature by setting PcdVariableCollectStatistics\r
-#  as TRUE, The application will not display variable statistical information.\r
+#  as TRUE, the application will not display variable statistical information.\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution. The full text of the license may be found at\r
@@ -20,7 +23,6 @@
   FILE_GUID                      = 202A2922-8C27-4943-9855-26180BF9F113\r
   MODULE_TYPE                    = UEFI_APPLICATION\r
   VERSION_STRING                 = 1.0\r
-\r
   ENTRY_POINT                    = UefiMain\r
 \r
 #\r
 [Sources]\r
   VariableInfo.c\r
 \r
-\r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
 \r
-\r
 [LibraryClasses]\r
   UefiApplicationEntryPoint\r
   UefiLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+\r
+[Protocols]\r
+  gEfiSmmCommunicationProtocolGuid   ## SOMETIMES_CONSUMES\r
+\r
+  ## UNDEFINED            # Used to do smm communication\r
+  ## SOMETIMES_CONSUMES\r
+  gEfiSmmVariableProtocolGuid\r
 \r
 [Guids]\r
-  gEfiVariableGuid          ## CONSUMES ## SystemTable\r
+  gEfiAuthenticatedVariableGuid      ## SOMETIMES_CONSUMES   ## SystemTable\r
+  gEfiVariableGuid                   ## CONSUMES             ## SystemTable\r
 \r
 [UserExtensions.TianoCore."ExtraFiles"]\r
   VariableInfoExtra.uni\r
index ea839d5c0bb7161d3d2f6495f575e97139e934e8..b8e6fd406f0263b6633ade51be96d4065dc58f68 100644 (file)
Binary files a/MdeModulePkg/Application/VariableInfo/VariableInfo.uni and b/MdeModulePkg/Application/VariableInfo/VariableInfo.uni differ