]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/VariableInfo/VariableInfo.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Application / VariableInfo / VariableInfo.c
index 727e1ce105f32d531bb1d72187b3266e60374ba5..3dee41eb4b7b74dab47f40f50c01941bb8051450 100644 (file)
@@ -3,14 +3,8 @@
   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
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -25,10 +19,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Guid/VariableFormat.h>\r
 #include <Guid/SmmVariableCommon.h>\r
-#include <Protocol/SmmCommunication.h>\r
+#include <Guid/PiSmmCommunicationRegionTable.h>\r
+#include <Protocol/MmCommunication2.h>\r
 #include <Protocol/SmmVariable.h>\r
 \r
-EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication = NULL;\r
+EFI_MM_COMMUNICATION2_PROTOCOL  *mMmCommunication2 = NULL;\r
 \r
 /**\r
   This function get the variable statistics data from SMM variable driver.\r
@@ -46,20 +41,25 @@ EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication = NULL;
 EFI_STATUS\r
 EFIAPI\r
 GetVariableStatisticsData (\r
-  IN OUT  EFI_SMM_COMMUNICATE_HEADER  *SmmCommunicateHeader,\r
-  IN OUT  UINTN                       *SmmCommunicateSize\r
+  IN OUT  EFI_MM_COMMUNICATE_HEADER  *SmmCommunicateHeader,\r
+  IN OUT  UINTN                      *SmmCommunicateSize\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  SMM_VARIABLE_COMMUNICATE_HEADER     *SmmVariableFunctionHeader;\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
+  SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);\r
 \r
-  SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0];\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
+  Status = mMmCommunication2->Communicate (\r
+                                mMmCommunication2,\r
+                                SmmCommunicateHeader,\r
+                                SmmCommunicateHeader,\r
+                                SmmCommunicateSize\r
+                                );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   Status = SmmVariableFunctionHeader->ReturnStatus;\r
@@ -79,101 +79,120 @@ PrintInfoFromSmm (
   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
+  EFI_STATUS                               Status;\r
+  VARIABLE_INFO_ENTRY                      *VariableInfo;\r
+  EFI_MM_COMMUNICATE_HEADER                *CommBuffer;\r
+  UINTN                                    RealCommSize;\r
+  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
+    return Status;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\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
 \r
-  CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;\r
-  RealCommSize = CommSize;\r
-  CommBuffer = AllocateZeroPool (CommSize);\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_MM_COMMUNICATE_HEADER *)(UINTN)Entry->PhysicalStart;\r
+        }\r
+      }\r
+    }\r
+\r
+    Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);\r
+  }\r
+\r
   ASSERT (CommBuffer != NULL);\r
+  ZeroMem (CommBuffer, RealCommSize);\r
 \r
-  Print (L"Non-Volatile SMM Variables:\n");\r
+  Print (L"SMM Driver Non-Volatile Variables:\n");\r
   do {\r
-    Status = GetVariableStatisticsData (CommBuffer, &CommSize);\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
+    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
+        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
+  Print (L"SMM Driver Volatile Variables:\n");\r
+  ZeroMem (CommBuffer, RealCommSize);\r
   do {\r
-    Status = GetVariableStatisticsData (CommBuffer, &CommSize);\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
+    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
+        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
@@ -196,24 +215,18 @@ UefiMain (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  VARIABLE_INFO_ENTRY   *VariableInfo;\r
-  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
+  EFI_STATUS           RuntimeDxeStatus;\r
+  EFI_STATUS           SmmStatus;\r
+  VARIABLE_INFO_ENTRY  *VariableInfo;\r
+  VARIABLE_INFO_ENTRY  *Entry;\r
+\r
+  RuntimeDxeStatus = EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&Entry);\r
+  if (EFI_ERROR (RuntimeDxeStatus) || (Entry == NULL)) {\r
+    RuntimeDxeStatus = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry);\r
   }\r
 \r
-  if (!EFI_ERROR (Status) && (Entry != NULL)) {\r
-    Print (L"Non-Volatile EFI Variables:\n");\r
+  if (!EFI_ERROR (RuntimeDxeStatus) && (Entry != NULL)) {\r
+    Print (L"Runtime DXE Driver Non-Volatile EFI Variables:\n");\r
     VariableInfo = Entry;\r
     do {\r
       if (!VariableInfo->Volatile) {\r
@@ -231,7 +244,7 @@ UefiMain (
       VariableInfo = VariableInfo->Next;\r
     } while (VariableInfo != NULL);\r
 \r
-    Print (L"Volatile EFI Variables:\n");\r
+    Print (L"Runtime DXE Driver Volatile EFI Variables:\n");\r
     VariableInfo = Entry;\r
     do {\r
       if (VariableInfo->Volatile) {\r
@@ -245,16 +258,22 @@ UefiMain (
           VariableInfo->Name\r
           );\r
       }\r
+\r
       VariableInfo = VariableInfo->Next;\r
     } while (VariableInfo != NULL);\r
+  }\r
+\r
+  SmmStatus = PrintInfoFromSmm ();\r
 \r
-  } else {\r
-    Print (L"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");\r
+  if (EFI_ERROR (RuntimeDxeStatus) && EFI_ERROR (SmmStatus)) {\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
+    return EFI_NOT_FOUND;\r
   }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r