]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg VariableInfo: Use fixed buffer for smm comm buffer
authorStar Zeng <star.zeng@intel.com>
Tue, 28 Jun 2016 05:37:06 +0000 (13:37 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 29 Jun 2016 04:57:49 +0000 (12:57 +0800)
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Application/VariableInfo/VariableInfo.c
MdeModulePkg/Application/VariableInfo/VariableInfo.inf
MdeModulePkg/Application/VariableInfo/VariableInfo.uni

index 727e1ce105f32d531bb1d72187b3266e60374ba5..df91c1451c194304d83f810dd7c6c6f3a7ed8b4d 100644 (file)
@@ -3,7 +3,7 @@
   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
+  Copyright (c) 2006 - 2016, 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
@@ -25,6 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Guid/VariableFormat.h>\r
 #include <Guid/SmmVariableCommon.h>\r
+#include <Guid/PiSmmCommunicationRegionTable.h>\r
 #include <Protocol/SmmCommunication.h>\r
 #include <Protocol/SmmVariable.h>\r
 \r
@@ -86,6 +87,11 @@ PrintInfoFromSmm (
   UINTN                                          CommSize;\r
   SMM_VARIABLE_COMMUNICATE_HEADER                *FunctionHeader;\r
   EFI_SMM_VARIABLE_PROTOCOL                      *Smmvariable;\r
+  EDKII_PI_SMM_COMMUNICATION_REGION_TABLE        *PiSmmCommunicationRegionTable;\r
+  UINT32                                         Index;\r
+  EFI_MEMORY_DESCRIPTOR                          *Entry;\r
+  UINTN                                          Size;\r
+  UINTN                                          MaxSize;\r
 \r
   Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable);\r
   if (EFI_ERROR (Status)) {\r
@@ -97,30 +103,47 @@ PrintInfoFromSmm (
     return Status;\r
   }\r
 \r
-  CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
-  RealCommSize = CommSize;\r
-  CommBuffer = AllocateZeroPool (CommSize);\r
+  CommBuffer = NULL;\r
+  Status = EfiGetSystemConfigurationTable (\r
+             &gEdkiiPiSmmCommunicationRegionTableGuid,\r
+             (VOID **) &PiSmmCommunicationRegionTable\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  ASSERT (PiSmmCommunicationRegionTable != NULL);\r
+  Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1);\r
+  Size = 0;\r
+  MaxSize = 0;\r
+  for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {\r
+    if (Entry->Type == EfiConventionalMemory) {\r
+      Size = EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages);\r
+      if (Size > (SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (VARIABLE_INFO_ENTRY))) {\r
+        if (Size > MaxSize) {\r
+          MaxSize = Size;\r
+          RealCommSize = MaxSize;\r
+          CommBuffer = (EFI_SMM_COMMUNICATE_HEADER *) (UINTN) Entry->PhysicalStart;\r
+        }\r
+      }\r
+    }\r
+    Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize);\r
+  }\r
   ASSERT (CommBuffer != NULL);\r
+  ZeroMem (CommBuffer, RealCommSize);\r
 \r
   Print (L"Non-Volatile SMM Variables:\n");\r
   do {\r
+    CommSize = RealCommSize;\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
+      Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");\r
+      return Status;\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
@@ -138,25 +161,19 @@ PrintInfoFromSmm (
   } while (TRUE);\r
 \r
   Print (L"Volatile SMM Variables:\n");\r
-  ZeroMem (CommBuffer, CommSize);\r
+  ZeroMem (CommBuffer, RealCommSize);\r
   do {\r
+    CommSize = RealCommSize;\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
+      Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");\r
+      return Status;\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
@@ -173,7 +190,6 @@ PrintInfoFromSmm (
     }\r
   } while (TRUE);\r
 \r
-  FreePool (CommBuffer);\r
   return Status;\r
 }\r
 \r
@@ -249,10 +265,10 @@ UefiMain (
     } while (VariableInfo != NULL);\r
 \r
   } else {\r
-    Print (L"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");\r
+    Print (L"Warning: Variable Dxe/Smm driver doesn't enable the feature of statistical information!\n");\r
     Print (L"If you want to see this info, please:\n");\r
     Print (L"  1. Set PcdVariableCollectStatistics as TRUE\n");\r
-    Print (L"  2. Rebuild Variable Dxe driver\n");\r
+    Print (L"  2. Rebuild Variable Dxe/Smm driver\n");\r
     Print (L"  3. Run \"VariableInfo\" cmd again\n");\r
   }\r
 \r
index f76637a2f5fbd2421950248c77c306526c7710a9..484ad32a4ea6128e5d39bfbf350e2dbc94da1e6c 100644 (file)
@@ -3,10 +3,10 @@
 #\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
+#  Note that if Variable Dxe/Smm driver doesn't enable the feature by setting PcdVariableCollectStatistics\r
 #  as TRUE, the application will not display variable statistical information.\r
 #\r
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, 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
@@ -53,8 +53,9 @@
   gEfiSmmVariableProtocolGuid\r
 \r
 [Guids]\r
-  gEfiAuthenticatedVariableGuid      ## SOMETIMES_CONSUMES   ## SystemTable\r
-  gEfiVariableGuid                   ## CONSUMES             ## SystemTable\r
+  gEfiAuthenticatedVariableGuid              ## SOMETIMES_CONSUMES ## SystemTable\r
+  gEfiVariableGuid                           ## SOMETIMES_CONSUMES ## SystemTable\r
+  gEdkiiPiSmmCommunicationRegionTableGuid    ## SOMETIMES_CONSUMES ## SystemTable\r
 \r
 [UserExtensions.TianoCore."ExtraFiles"]\r
   VariableInfoExtra.uni\r
index 19d440736bba7ed48178c8fe375a66943f42faf1..fec4593c4af363252560e3d4c9b53e378c6b18d4 100644 (file)
@@ -3,10 +3,10 @@
 //\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
+// Note that if Variable Dxe/Smm driver doesn't enable the feature by setting PcdVariableCollectStatistics\r
 // as TRUE, the application will not display variable statistical information.\r
 //\r
-// Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+// Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 //\r
 // This program and the accompanying materials\r
 // are licensed and made available under the terms and conditions of the BSD License\r
@@ -20,5 +20,5 @@
 \r
 #string STR_MODULE_ABSTRACT             #language en-US "A shell application that displays statistical information about variable usage"\r
 \r
-#string STR_MODULE_DESCRIPTION          #language en-US "This application can display statistical information about variable usage for SMM variable driver and non-SMM variable driver. Note that if Variable DXE driver doesn't enable the feature by setting PcdVariableCollectStatistics as TRUE, the application will not display variable statistical information."\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This application can display statistical information about variable usage for SMM variable driver and non-SMM variable driver. Note that if Variable DXE/SMM driver doesn't enable the feature by setting PcdVariableCollectStatistics as TRUE, the application will not display variable statistical information."\r
 \r