What to do: 1. Merge VariableInfo in SecurityPkg to VariableInfo in MdeModulePkg.
Why to do: 1. Remove code duplication and reduce maintenance effort. The functionality of VariableInfo in SecurityPkg has covered VariableInfo in MdeModulePkg. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.z...@intel.com> Reviewed-by: Jiewen Yao <jiewen....@intel.com> Reviewed-by: Liming Gao <liming....@intel.com> --- .../Application/VariableInfo/VariableInfo.c | 209 ++++++++++++++++++--- .../Application/VariableInfo/VariableInfo.inf | 25 ++- .../Application/VariableInfo/VariableInfo.uni | Bin 2430 -> 2904 bytes 3 files changed, 205 insertions(+), 29 deletions(-) diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.c b/MdeModulePkg/Application/VariableInfo/VariableInfo.c index 50b67d0..727e1ce 100644 --- a/MdeModulePkg/Application/VariableInfo/VariableInfo.c +++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.c @@ -1,35 +1,190 @@ /** @file - If the Variable services have PcdVariableCollectStatistics set to TRUE then - the EFI system table will contain statistical information about variable usage - an this utility will print out the information. You can use console redirection - to capture the data. - - Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR> - 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. + If the Variable services have PcdVariableCollectStatistics set to TRUE then + this utility will print out the statistics information. You can use console + redirection to capture the data. + + Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> + 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. **/ #include <Uefi.h> #include <Library/UefiLib.h> #include <Library/UefiApplicationEntryPoint.h> +#include <Library/BaseMemoryLib.h> +#include <Library/BaseLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h> + #include <Guid/VariableFormat.h> +#include <Guid/SmmVariableCommon.h> +#include <Protocol/SmmCommunication.h> +#include <Protocol/SmmVariable.h> + +EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL; + +/** + This function get the variable statistics data from SMM variable driver. + + @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will + be passed into an SMM environment. In output, a pointer + to a collection of data that comes from an SMM environment. + @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader. + + @retval EFI_SUCCESS Get the statistics data information. + @retval EFI_NOT_FOUND Not found. + @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result. + +**/ +EFI_STATUS +EFIAPI +GetVariableStatisticsData ( + IN OUT EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader, + IN OUT UINTN *SmmCommunicateSize + ) +{ + EFI_STATUS Status; + SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; + + CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid); + SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data); + + SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0]; + SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS; + Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, SmmCommunicateSize); + ASSERT_EFI_ERROR (Status); + + Status = SmmVariableFunctionHeader->ReturnStatus; + return Status; +} + +/** + + This function get and print the variable statistics data from SMM variable driver. + + @retval EFI_SUCCESS Print the statistics information successfully. + @retval EFI_NOT_FOUND Not found the statistics information. + +**/ +EFI_STATUS +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; + + Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication); + if (EFI_ERROR (Status)) { + return Status; + } + + CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE; + RealCommSize = CommSize; + CommBuffer = AllocateZeroPool (CommSize); + ASSERT (CommBuffer != NULL); + + Print (L"Non-Volatile SMM Variables:\n"); + do { + Status = GetVariableStatisticsData (CommBuffer, &CommSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (CommBuffer); + CommBuffer = AllocateZeroPool (CommSize); + ASSERT (CommBuffer != NULL); + RealCommSize = CommSize; + Status = GetVariableStatisticsData (CommBuffer, &CommSize); + } + + if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { + break; + } + + if (CommSize < RealCommSize) { + CommSize = RealCommSize; + } + + 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) + ); + } + } while (TRUE); + + Print (L"Volatile SMM Variables:\n"); + ZeroMem (CommBuffer, CommSize); + do { + Status = GetVariableStatisticsData (CommBuffer, &CommSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (CommBuffer); + CommBuffer = AllocateZeroPool (CommSize); + ASSERT (CommBuffer != NULL); + RealCommSize = CommSize; + Status = GetVariableStatisticsData (CommBuffer, &CommSize); + } + + if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { + break; + } + + if (CommSize < RealCommSize) { + CommSize = RealCommSize; + } + + 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) + ); + } + } while (TRUE); + + FreePool (CommBuffer); + return Status; +} /** The user Entry Point for Application. The user code starts with this function - as the real entry point for the image goes into a library that calls this + as the real entry point for the image goes into a library that calls this function. - - @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. - + @retval EFI_SUCCESS The entry point is executed successfully. @retval other Some error occurs when executing this entry point. @@ -46,14 +201,25 @@ UefiMain ( 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; + } + } + if (!EFI_ERROR (Status) && (Entry != NULL)) { Print (L"Non-Volatile EFI Variables:\n"); VariableInfo = Entry; do { if (!VariableInfo->Volatile) { Print ( - L"%g R%03d(%03d) W%03d D%03d:%s\n", - &VariableInfo->VendorGuid, + L"%g R%03d(%03d) W%03d D%03d:%s\n", + &VariableInfo->VendorGuid, VariableInfo->ReadCount, VariableInfo->CacheCount, VariableInfo->WriteCount, @@ -70,8 +236,8 @@ UefiMain ( do { if (VariableInfo->Volatile) { Print ( - L"%g R%03d(%03d) W%03d D%03d:%s\n", - &VariableInfo->VendorGuid, + L"%g R%03d(%03d) W%03d D%03d:%s\n", + &VariableInfo->VendorGuid, VariableInfo->ReadCount, VariableInfo->CacheCount, VariableInfo->WriteCount, @@ -88,7 +254,6 @@ UefiMain ( Print (L" 1. Set PcdVariableCollectStatistics as TRUE\n"); Print (L" 2. Rebuild Variable Dxe driver\n"); Print (L" 3. Run \"VariableInfo\" cmd again\n"); - } return Status; diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.inf b/MdeModulePkg/Application/VariableInfo/VariableInfo.inf index 4d9dc71..9074b52 100644 --- a/MdeModulePkg/Application/VariableInfo/VariableInfo.inf +++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.inf @@ -1,9 +1,12 @@ ## @file -# This is a shell application that will display statistical information about variable usage. +# A shell application that displays statistical information about variable usage. +# +# 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. +# as TRUE, the application will not display variable statistical information. # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR> # 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 @@ -20,7 +23,6 @@ [Defines] FILE_GUID = 202A2922-8C27-4943-9855-26180BF9F113 MODULE_TYPE = UEFI_APPLICATION VERSION_STRING = 1.0 - ENTRY_POINT = UefiMain # @@ -32,18 +34,27 @@ [Defines] [Sources] VariableInfo.c - [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec - [LibraryClasses] UefiApplicationEntryPoint UefiLib + UefiBootServicesTableLib + BaseMemoryLib + MemoryAllocationLib + +[Protocols] + gEfiSmmCommunicationProtocolGuid ## SOMETIMES_CONSUMES + ## UNDEFINED # Used to do smm communication + ## SOMETIMES_CONSUMES + gEfiSmmVariableProtocolGuid + [Guids] - gEfiVariableGuid ## CONSUMES ## SystemTable + gEfiAuthenticatedVariableGuid ## SOMETIMES_CONSUMES ## SystemTable + gEfiVariableGuid ## CONSUMES ## SystemTable [UserExtensions.TianoCore."ExtraFiles"] VariableInfoExtra.uni diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.uni b/MdeModulePkg/Application/VariableInfo/VariableInfo.uni index ea839d5c0bb7161d3d2f6495f575e97139e934e8..b8e6fd406f0263b6633ade51be96d4065dc58f68 100644 GIT binary patch delta 311 zcmew-bVF={3ZvshQ$zj~hD?THh608hhD3%+hT_SNoQ4zE*|CQ(WPl_lI!d!917-3i z=4SgVFr+c$GZZl>Fa$IB0-*v!8BnSSs4kHq31~nn11|#?gFX-{Fr<LR%Yb4a^*{rF zA__n<ABc4!`X}piit-|>)0_D4En~^#j~vaDgP5EcO*c<v@@K*0O0CJW*lV!4lpoEd WAe)qtZ6e-9FAXQVaI68lsuuwLHc1=+ delta 136 zcmca1_D^VnieLys216!8F@pk>Oq_h1-H^Q;$jf2KnfN<<;sKG#j~E}Zg4Cr>G?bqF riYsNZ2eT8S$>wfme-?uJne`ZyCdaeuPhQ6112jl)vK-eMWW(|RyA3E- -- 1.9.5.msysgit.0 ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel