]> 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 a88b7f1ec42ce8f4878c5654e4f012eec9568b3e..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
   this utility will print out the statistics information. You can use console\r
   redirection to capture the data.\r
 \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
-  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
 \r
 **/\r
 \r
@@ -26,10 +20,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/VariableFormat.h>\r
 #include <Guid/SmmVariableCommon.h>\r
 #include <Guid/PiSmmCommunicationRegionTable.h>\r
 #include <Guid/VariableFormat.h>\r
 #include <Guid/SmmVariableCommon.h>\r
 #include <Guid/PiSmmCommunicationRegionTable.h>\r
-#include <Protocol/SmmCommunication.h>\r
+#include <Protocol/MmCommunication2.h>\r
 #include <Protocol/SmmVariable.h>\r
 \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
 \r
 /**\r
   This function get the variable statistics data from SMM variable driver.\r
@@ -47,20 +41,25 @@ EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication = NULL;
 EFI_STATUS\r
 EFIAPI\r
 GetVariableStatisticsData (\r
 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
   )\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
 \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
 \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
   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
   ASSERT_EFI_ERROR (Status);\r
 \r
   Status = SmmVariableFunctionHeader->ReturnStatus;\r
@@ -80,62 +79,65 @@ PrintInfoFromSmm (
   VOID\r
   )\r
 {\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
-  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
+  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
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);\r
+  Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  CommBuffer = NULL;\r
+  CommBuffer   = NULL;\r
   RealCommSize = 0;\r
   RealCommSize = 0;\r
-  Status = EfiGetSystemConfigurationTable (\r
-             &gEdkiiPiSmmCommunicationRegionTableGuid,\r
-             (VOID **) &PiSmmCommunicationRegionTable\r
-             );\r
+  Status       = EfiGetSystemConfigurationTable (\r
+                   &gEdkiiPiSmmCommunicationRegionTableGuid,\r
+                   (VOID **)&PiSmmCommunicationRegionTable\r
+                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
   ASSERT (PiSmmCommunicationRegionTable != NULL);\r
   ASSERT (PiSmmCommunicationRegionTable != NULL);\r
-  Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1);\r
-  Size = 0;\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
   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
+      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
       if (Size > (SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (VARIABLE_INFO_ENTRY))) {\r
         if (Size > MaxSize) {\r
-          MaxSize = Size;\r
+          MaxSize      = Size;\r
           RealCommSize = MaxSize;\r
           RealCommSize = MaxSize;\r
-          CommBuffer = (EFI_SMM_COMMUNICATE_HEADER *) (UINTN) Entry->PhysicalStart;\r
+          CommBuffer   = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)Entry->PhysicalStart;\r
         }\r
       }\r
     }\r
         }\r
       }\r
     }\r
-    Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize);\r
+\r
+    Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);\r
   }\r
   }\r
+\r
   ASSERT (CommBuffer != NULL);\r
   ZeroMem (CommBuffer, RealCommSize);\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
     CommSize = RealCommSize;\r
   do {\r
     CommSize = RealCommSize;\r
-    Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
+    Status   = GetVariableStatisticsData (CommBuffer, &CommSize);\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");\r
       return Status;\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");\r
       return Status;\r
@@ -145,27 +147,27 @@ PrintInfoFromSmm (
       break;\r
     }\r
 \r
       break;\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
 \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
     }\r
   } while (TRUE);\r
 \r
-  Print (L"Volatile SMM Variables:\n");\r
+  Print (L"SMM Driver Volatile Variables:\n");\r
   ZeroMem (CommBuffer, RealCommSize);\r
   do {\r
     CommSize = RealCommSize;\r
   ZeroMem (CommBuffer, RealCommSize);\r
   do {\r
     CommSize = RealCommSize;\r
-    Status = GetVariableStatisticsData (CommBuffer, &CommSize);\r
+    Status   = GetVariableStatisticsData (CommBuffer, &CommSize);\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");\r
       return Status;\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n");\r
       return Status;\r
@@ -175,19 +177,19 @@ PrintInfoFromSmm (
       break;\r
     }\r
 \r
       break;\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
 \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
     }\r
   } while (TRUE);\r
 \r
@@ -213,24 +215,18 @@ UefiMain (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   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
   }\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
     VariableInfo = Entry;\r
     do {\r
       if (!VariableInfo->Volatile) {\r
@@ -248,7 +244,7 @@ UefiMain (
       VariableInfo = VariableInfo->Next;\r
     } while (VariableInfo != NULL);\r
 \r
       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
     VariableInfo = Entry;\r
     do {\r
       if (VariableInfo->Volatile) {\r
@@ -262,16 +258,22 @@ UefiMain (
           VariableInfo->Name\r
           );\r
       }\r
           VariableInfo->Name\r
           );\r
       }\r
+\r
       VariableInfo = VariableInfo->Next;\r
     } while (VariableInfo != NULL);\r
       VariableInfo = VariableInfo->Next;\r
     } while (VariableInfo != NULL);\r
+  }\r
 \r
 \r
-  } else {\r
+  SmmStatus = PrintInfoFromSmm ();\r
+\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/Smm driver\n");\r
     Print (L"  3. Run \"VariableInfo\" cmd again\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/Smm driver\n");\r
     Print (L"  3. Run \"VariableInfo\" cmd again\n");\r
+\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 }\r