]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/VariableInfo/VariableInfo.c
Merge branch 'master' of https://github.com/tianocore/edk2
[mirror_edk2.git] / MdeModulePkg / Application / VariableInfo / VariableInfo.c
index 727e1ce105f32d531bb1d72187b3266e60374ba5..a88b7f1ec42ce8f4878c5654e4f012eec9568b3e 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,48 @@ 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
+  RealCommSize = 0;\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 +162,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 +191,6 @@ PrintInfoFromSmm (
     }\r
   } while (TRUE);\r
 \r
-  FreePool (CommBuffer);\r
   return Status;\r
 }\r
 \r
@@ -249,10 +266,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