X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FApplication%2FVariableInfo%2FVariableInfo.c;h=a7df365b58958dc2e7726d0b7f3573e52ece797b;hp=df91c1451c194304d83f810dd7c6c6f3a7ed8b4d;hb=HEAD;hpb=faf3de9bd036cd2a387c1e44d403d24386fadb49 diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.c b/MdeModulePkg/Application/VariableInfo/VariableInfo.c index df91c1451c..3dee41eb4b 100644 --- a/MdeModulePkg/Application/VariableInfo/VariableInfo.c +++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.c @@ -3,14 +3,8 @@ this utility will print out the statistics information. You can use console redirection to capture the data. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
- This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -26,10 +20,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include +#include #include -EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL; +EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL; /** This function get the variable statistics data from SMM variable driver. @@ -47,20 +41,25 @@ EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL; EFI_STATUS EFIAPI GetVariableStatisticsData ( - IN OUT EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader, - IN OUT UINTN *SmmCommunicateSize + IN OUT EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader, + IN OUT UINTN *SmmCommunicateSize ) { - EFI_STATUS Status; - SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; + EFI_STATUS Status; + SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid); - SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data); - SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0]; + SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)&SmmCommunicateHeader->Data[0]; SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS; - Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, SmmCommunicateSize); + Status = mMmCommunication2->Communicate ( + mMmCommunication2, + SmmCommunicateHeader, + SmmCommunicateHeader, + SmmCommunicateSize + ); ASSERT_EFI_ERROR (Status); Status = SmmVariableFunctionHeader->ReturnStatus; @@ -80,61 +79,65 @@ PrintInfoFromSmm ( VOID ) { - EFI_STATUS Status; - VARIABLE_INFO_ENTRY *VariableInfo; - EFI_SMM_COMMUNICATE_HEADER *CommBuffer; - UINTN RealCommSize; - UINTN CommSize; - SMM_VARIABLE_COMMUNICATE_HEADER *FunctionHeader; - EFI_SMM_VARIABLE_PROTOCOL *Smmvariable; - EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable; - UINT32 Index; - EFI_MEMORY_DESCRIPTOR *Entry; - UINTN Size; - UINTN MaxSize; - - Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable); + EFI_STATUS Status; + VARIABLE_INFO_ENTRY *VariableInfo; + EFI_MM_COMMUNICATE_HEADER *CommBuffer; + UINTN RealCommSize; + UINTN CommSize; + SMM_VARIABLE_COMMUNICATE_HEADER *FunctionHeader; + EFI_SMM_VARIABLE_PROTOCOL *Smmvariable; + EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable; + UINT32 Index; + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN Size; + UINTN MaxSize; + + Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **)&Smmvariable); if (EFI_ERROR (Status)) { return Status; } - Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication); + Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **)&mMmCommunication2); if (EFI_ERROR (Status)) { return Status; } - CommBuffer = NULL; - Status = EfiGetSystemConfigurationTable ( - &gEdkiiPiSmmCommunicationRegionTableGuid, - (VOID **) &PiSmmCommunicationRegionTable - ); + CommBuffer = NULL; + RealCommSize = 0; + Status = EfiGetSystemConfigurationTable ( + &gEdkiiPiSmmCommunicationRegionTableGuid, + (VOID **)&PiSmmCommunicationRegionTable + ); if (EFI_ERROR (Status)) { return Status; } + ASSERT (PiSmmCommunicationRegionTable != NULL); - Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1); - Size = 0; + Entry = (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1); + Size = 0; MaxSize = 0; for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) { if (Entry->Type == EfiConventionalMemory) { - Size = EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages); + Size = EFI_PAGES_TO_SIZE ((UINTN)Entry->NumberOfPages); if (Size > (SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (VARIABLE_INFO_ENTRY))) { if (Size > MaxSize) { - MaxSize = Size; + MaxSize = Size; RealCommSize = MaxSize; - CommBuffer = (EFI_SMM_COMMUNICATE_HEADER *) (UINTN) Entry->PhysicalStart; + CommBuffer = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)Entry->PhysicalStart; } } } - Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize); + + Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize); } + ASSERT (CommBuffer != NULL); ZeroMem (CommBuffer, RealCommSize); - Print (L"Non-Volatile SMM Variables:\n"); + Print (L"SMM Driver Non-Volatile Variables:\n"); do { CommSize = RealCommSize; - Status = GetVariableStatisticsData (CommBuffer, &CommSize); + Status = GetVariableStatisticsData (CommBuffer, &CommSize); if (Status == EFI_BUFFER_TOO_SMALL) { Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n"); return Status; @@ -144,27 +147,27 @@ PrintInfoFromSmm ( break; } - FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data; - VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data; + FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer->Data; + VariableInfo = (VARIABLE_INFO_ENTRY *)FunctionHeader->Data; if (!VariableInfo->Volatile) { Print ( - L"%g R%03d(%03d) W%03d D%03d:%s\n", - &VariableInfo->VendorGuid, - VariableInfo->ReadCount, - VariableInfo->CacheCount, - VariableInfo->WriteCount, - VariableInfo->DeleteCount, - (CHAR16 *)(VariableInfo + 1) - ); + L"%g R%03d(%03d) W%03d D%03d:%s\n", + &VariableInfo->VendorGuid, + VariableInfo->ReadCount, + VariableInfo->CacheCount, + VariableInfo->WriteCount, + VariableInfo->DeleteCount, + (CHAR16 *)(VariableInfo + 1) + ); } } while (TRUE); - Print (L"Volatile SMM Variables:\n"); + Print (L"SMM Driver Volatile Variables:\n"); ZeroMem (CommBuffer, RealCommSize); do { CommSize = RealCommSize; - Status = GetVariableStatisticsData (CommBuffer, &CommSize); + Status = GetVariableStatisticsData (CommBuffer, &CommSize); if (Status == EFI_BUFFER_TOO_SMALL) { Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n"); return Status; @@ -174,19 +177,19 @@ PrintInfoFromSmm ( break; } - FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data; - VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data; + FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer->Data; + VariableInfo = (VARIABLE_INFO_ENTRY *)FunctionHeader->Data; if (VariableInfo->Volatile) { Print ( - L"%g R%03d(%03d) W%03d D%03d:%s\n", - &VariableInfo->VendorGuid, - VariableInfo->ReadCount, - VariableInfo->CacheCount, - VariableInfo->WriteCount, - VariableInfo->DeleteCount, - (CHAR16 *)(VariableInfo + 1) - ); + L"%g R%03d(%03d) W%03d D%03d:%s\n", + &VariableInfo->VendorGuid, + VariableInfo->ReadCount, + VariableInfo->CacheCount, + VariableInfo->WriteCount, + VariableInfo->DeleteCount, + (CHAR16 *)(VariableInfo + 1) + ); } } while (TRUE); @@ -212,24 +215,18 @@ UefiMain ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - VARIABLE_INFO_ENTRY *VariableInfo; - VARIABLE_INFO_ENTRY *Entry; - - Status = EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&Entry); - if (EFI_ERROR (Status) || (Entry == NULL)) { - Status = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry); - } - - if (EFI_ERROR (Status) || (Entry == NULL)) { - Status = PrintInfoFromSmm (); - if (!EFI_ERROR (Status)) { - return Status; - } + EFI_STATUS RuntimeDxeStatus; + EFI_STATUS SmmStatus; + VARIABLE_INFO_ENTRY *VariableInfo; + VARIABLE_INFO_ENTRY *Entry; + + RuntimeDxeStatus = EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&Entry); + if (EFI_ERROR (RuntimeDxeStatus) || (Entry == NULL)) { + RuntimeDxeStatus = EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid, (VOID **)&Entry); } - if (!EFI_ERROR (Status) && (Entry != NULL)) { - Print (L"Non-Volatile EFI Variables:\n"); + if (!EFI_ERROR (RuntimeDxeStatus) && (Entry != NULL)) { + Print (L"Runtime DXE Driver Non-Volatile EFI Variables:\n"); VariableInfo = Entry; do { if (!VariableInfo->Volatile) { @@ -247,7 +244,7 @@ UefiMain ( VariableInfo = VariableInfo->Next; } while (VariableInfo != NULL); - Print (L"Volatile EFI Variables:\n"); + Print (L"Runtime DXE Driver Volatile EFI Variables:\n"); VariableInfo = Entry; do { if (VariableInfo->Volatile) { @@ -261,16 +258,22 @@ UefiMain ( VariableInfo->Name ); } + VariableInfo = VariableInfo->Next; } while (VariableInfo != NULL); + } - } else { + SmmStatus = PrintInfoFromSmm (); + + if (EFI_ERROR (RuntimeDxeStatus) && EFI_ERROR (SmmStatus)) { Print (L"Warning: Variable Dxe/Smm driver doesn't enable the feature of statistical information!\n"); Print (L"If you want to see this info, please:\n"); Print (L" 1. Set PcdVariableCollectStatistics as TRUE\n"); Print (L" 2. Rebuild Variable Dxe/Smm driver\n"); Print (L" 3. Run \"VariableInfo\" cmd again\n"); + + return EFI_NOT_FOUND; } - return Status; + return EFI_SUCCESS; }