From nobody Sat Nov 2 16:25:26 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1486571462557497.2807578630677; Wed, 8 Feb 2017 08:31:02 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C94482102; Wed, 8 Feb 2017 08:30:42 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 04386820CD for ; Wed, 8 Feb 2017 08:30:40 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 08 Feb 2017 08:30:39 -0800 Received: from jyao1-mobl.ccr.corp.intel.com ([10.254.185.79]) by fmsmga002.fm.intel.com with ESMTP; 08 Feb 2017 08:30:39 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,348,1477983600"; d="scan'208";a="1123833904" From: Jiewen Yao To: edk2-devel@lists.01.org Date: Wed, 8 Feb 2017 08:30:33 -0800 Message-Id: <1486571434-20000-9-git-send-email-jiewen.yao@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1486571434-20000-1-git-send-email-jiewen.yao@intel.com> References: <1486571434-20000-1-git-send-email-jiewen.yao@intel.com> Subject: [edk2] [PATCH 08/12] MdeModulePkg/App: Add SmiHandlerProfile dump app. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Feng Tian , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This app uses SMM communication to get SMI handler profile from SMM core. Cc: Feng Tian Cc: Star Zeng Cc: Michael D Kinney Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao --- MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c = | 685 ++++++++++++++++++++ MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf = | 65 ++ MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.uni = | 22 + MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoExtra.= uni | 19 + 4 files changed, 791 insertions(+) diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfi= leInfo.c b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfile= Info.c new file mode 100644 index 0000000..00cab0c --- /dev/null +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c @@ -0,0 +1,685 @@ +/** @file + Shell application to dump SMI handler profile information. + +Copyright (c) 2017, 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 IMPLI= ED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define PROFILE_NAME_STRING_LENGTH 64 +CHAR8 mNameString[PROFILE_NAME_STRING_LENGTH + 1]; + +VOID *mSmiHandlerProfileDatabase; +UINTN mSmiHandlerProfileDatabaseSize; + +/** + This function dump raw data. + + @param Data raw data + @param Size raw data size +**/ +VOID +InternalDumpData ( + IN UINT8 *Data, + IN UINTN Size + ) +{ + UINTN Index; + for (Index =3D 0; Index < Size; Index++) { + Print (L"%02x", (UINTN)Data[Index]); + if ((Index + 1) !=3D Size) { + Print (L" "); + } + } +} + +/** + Get SMI handler profile database. +**/ +VOID +GetSmiHandlerProfileDatabase( + VOID + ) +{ + EFI_STATUS Status; + UINTN CommSize; + UINT8 *CommBuffer; + EFI_SMM_COMMUNICATE_HEADER *CommHeader; + SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *CommGetInfo; + SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *CommGetData; + EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; + UINTN MinimalSizeNeeded; + EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationR= egionTable; + UINT32 Index; + EFI_MEMORY_DESCRIPTOR *Entry; + VOID *Buffer; + UINTN Size; + UINTN Offset; + + Status =3D gBS->LocateProtocol(&gEfiSmmCommunicationProtocolGuid, NULL, = (VOID **)&SmmCommunication); + if (EFI_ERROR(Status)) { + Print(L"SmiHandlerProfile: Locate SmmCommunication protocol - %r\n", S= tatus); + return ; + } + + MinimalSizeNeeded =3D EFI_PAGE_SIZE; + + Status =3D EfiGetSystemConfigurationTable( + &gEdkiiPiSmmCommunicationRegionTableGuid, + (VOID **)&PiSmmCommunicationRegionTable + ); + if (EFI_ERROR(Status)) { + Print(L"SmiHandlerProfile: Get PiSmmCommunicationRegionTable - %r\n", = Status); + return ; + } + ASSERT(PiSmmCommunicationRegionTable !=3D NULL); + Entry =3D (EFI_MEMORY_DESCRIPTOR *)(PiSmmCommunicationRegionTable + 1); + Size =3D 0; + for (Index =3D 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries= ; Index++) { + if (Entry->Type =3D=3D EfiConventionalMemory) { + Size =3D EFI_PAGES_TO_SIZE((UINTN)Entry->NumberOfPages); + if (Size >=3D MinimalSizeNeeded) { + break; + } + } + Entry =3D (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicatio= nRegionTable->DescriptorSize); + } + ASSERT(Index < PiSmmCommunicationRegionTable->NumberOfEntries); + CommBuffer =3D (UINT8 *)(UINTN)Entry->PhysicalStart; + + // + // Get Size + // + CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; + CopyMem(&CommHeader->HeaderGuid, &gSmiHandlerProfileGuid, sizeof(gSmiHan= dlerProfileGuid)); + CommHeader->MessageLength =3D sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_I= NFO); + + CommGetInfo =3D (SMI_HANDLER_PROFILE_PARAMETER_GET_INFO *)&CommBuffer[OF= FSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data)]; + CommGetInfo->Header.Command =3D SMI_HANDLER_PROFILE_COMMAND_GET_INFO; + CommGetInfo->Header.DataLength =3D sizeof(*CommGetInfo); + CommGetInfo->Header.ReturnStatus =3D (UINT64)-1; + CommGetInfo->DataSize =3D 0; + + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLengt= h; + Status =3D SmmCommunication->Communicate(SmmCommunication, CommBuffer, &= CommSize); + if (EFI_ERROR(Status)) { + Print(L"SmiHandlerProfile: SmmCommunication - %r\n", Status); + return ; + } + + if (CommGetInfo->Header.ReturnStatus !=3D 0) { + Print(L"SmiHandlerProfile: GetInfo - 0x%0x\n", CommGetInfo->Header.Ret= urnStatus); + return ; + } + + mSmiHandlerProfileDatabaseSize =3D (UINTN)CommGetInfo->DataSize; + + // + // Get Data + // + mSmiHandlerProfileDatabase =3D AllocateZeroPool(mSmiHandlerProfileDataba= seSize); + if (mSmiHandlerProfileDatabase =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + Print(L"SmiHandlerProfile: AllocateZeroPool (0x%x) for dump buffer - %= r\n", mSmiHandlerProfileDatabaseSize, Status); + return ; + } + + CommHeader =3D (EFI_SMM_COMMUNICATE_HEADER *)&CommBuffer[0]; + CopyMem(&CommHeader->HeaderGuid, &gSmiHandlerProfileGuid, sizeof(gSmiHan= dlerProfileGuid)); + CommHeader->MessageLength =3D sizeof(SMI_HANDLER_PROFILE_PARAMETER_GET_D= ATA_BY_OFFSET); + + CommGetData =3D (SMI_HANDLER_PROFILE_PARAMETER_GET_DATA_BY_OFFSET *)&Com= mBuffer[OFFSET_OF(EFI_SMM_COMMUNICATE_HEADER, Data)]; + CommGetData->Header.Command =3D SMI_HANDLER_PROFILE_COMMAND_GET_DATA_BY_= OFFSET; + CommGetData->Header.DataLength =3D sizeof(*CommGetData); + CommGetData->Header.ReturnStatus =3D (UINT64)-1; + + CommSize =3D sizeof(EFI_GUID) + sizeof(UINTN) + CommHeader->MessageLengt= h; + Buffer =3D (UINT8 *)CommHeader + CommSize; + Size -=3D CommSize; + + CommGetData->DataBuffer =3D (PHYSICAL_ADDRESS)(UINTN)Buffer; + CommGetData->DataOffset =3D 0; + while (CommGetData->DataOffset < mSmiHandlerProfileDatabaseSize) { + Offset =3D (UINTN)CommGetData->DataOffset; + if (Size <=3D (mSmiHandlerProfileDatabaseSize - CommGetData->DataOffse= t)) { + CommGetData->DataSize =3D (UINT64)Size; + } else { + CommGetData->DataSize =3D (UINT64)(mSmiHandlerProfileDatabaseSize - = CommGetData->DataOffset); + } + Status =3D SmmCommunication->Communicate(SmmCommunication, CommBuffer,= &CommSize); + ASSERT_EFI_ERROR(Status); + + if (CommGetData->Header.ReturnStatus !=3D 0) { + FreePool(mSmiHandlerProfileDatabase); + mSmiHandlerProfileDatabase =3D NULL; + Print(L"SmiHandlerProfile: GetData - 0x%x\n", CommGetData->Header.Re= turnStatus); + return ; + } + CopyMem((UINT8 *)mSmiHandlerProfileDatabase + Offset, (VOID *)(UINTN)C= ommGetData->DataBuffer, (UINTN)CommGetData->DataSize); + } + + DEBUG ((DEBUG_INFO, "SmiHandlerProfileSize - 0x%x\n", mSmiHandlerProfile= DatabaseSize)); + + return ; +} + +/** + Get the file name portion of the Pdb File Name. + + The portion of the Pdb File Name between the last backslash and + either a following period or the end of the string is copied into + AsciiBuffer. The name is truncated, if necessary, to ensure that + AsciiBuffer is not overrun. + + @param[in] PdbFileName Pdb file name. + @param[out] AsciiBuffer The resultant Ascii File Name. + +**/ +VOID +GetShortPdbFileName ( + IN CHAR8 *PdbFileName, + OUT CHAR8 *AsciiBuffer + ) +{ + UINTN IndexPdb; // Current work location within a Pdb string. + UINTN IndexBuffer; // Current work location within a Buffer string. + UINTN StartIndex; + UINTN EndIndex; + + ZeroMem (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1); + + if (PdbFileName =3D=3D NULL) { + AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1, " ", 1); + } else { + StartIndex =3D 0; + for (EndIndex =3D 0; PdbFileName[EndIndex] !=3D 0; EndIndex++); + for (IndexPdb =3D 0; PdbFileName[IndexPdb] !=3D 0; IndexPdb++) { + if ((PdbFileName[IndexPdb] =3D=3D '\\') || (PdbFileName[IndexPdb] = =3D=3D '/')) { + StartIndex =3D IndexPdb + 1; + } + + if (PdbFileName[IndexPdb] =3D=3D '.') { + EndIndex =3D IndexPdb; + } + } + + IndexBuffer =3D 0; + for (IndexPdb =3D StartIndex; IndexPdb < EndIndex; IndexPdb++) { + AsciiBuffer[IndexBuffer] =3D PdbFileName[IndexPdb]; + IndexBuffer++; + if (IndexBuffer >=3D PROFILE_NAME_STRING_LENGTH) { + AsciiBuffer[PROFILE_NAME_STRING_LENGTH] =3D 0; + break; + } + } + } +} + +/** + Get a human readable name for an image. + The following methods will be tried orderly: + 1. Image PDB + 2. FFS UI section + 3. Image GUID + + @param[in] DriverInfo Pointer to memory profile driver info. + + @return The resulting Ascii name string is stored in the mNameString glo= bal array. + +**/ +CHAR8 * +GetDriverNameString ( + IN SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct + ) +{ + EFI_STATUS Status; + CHAR16 *NameString; + UINTN StringSize; + + if (ImageStruct =3D=3D NULL) { + return "???"; + } + + // + // Method 1: Get the name string from image PDB + // + if (ImageStruct->Header.Length > sizeof (SMM_CORE_IMAGE_DATABASE_STRUCTU= RE)) { + GetShortPdbFileName ((CHAR8 *) (ImageStruct + 1), mNameString); + return mNameString; + } + + if (!IsZeroGuid (&ImageStruct->FileGuid)) { + // + // Try to get the image's FFS UI section by image GUID + // + NameString =3D NULL; + StringSize =3D 0; + Status =3D GetSectionFromAnyFv ( + &ImageStruct->FileGuid, + EFI_SECTION_USER_INTERFACE, + 0, + (VOID **) &NameString, + &StringSize + ); + if (!EFI_ERROR (Status)) { + // + // Method 2: Get the name string from FFS UI section + // + if (StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) { + NameString[PROFILE_NAME_STRING_LENGTH] =3D 0; + } + UnicodeStrToAsciiStrS (NameString, mNameString, sizeof (mNameString)= ); + FreePool (NameString); + return mNameString; + } + } + + // + // Method 3: Get the name string from image GUID + // + AsciiSPrint (mNameString, sizeof (mNameString), "%g", &ImageStruct->File= Guid); + return mNameString; +} + +/** + Get image structure from reference index. + + @param ImageRef the image reference index + + @return image structure +**/ +SMM_CORE_IMAGE_DATABASE_STRUCTURE * +GetImageFromRef ( + IN UINTN ImageRef + ) +{ + SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct; + + ImageStruct =3D (VOID *)mSmiHandlerProfileDatabase; + while ((UINTN)ImageStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHand= lerProfileDatabaseSize) { + if (ImageStruct->Header.Signature =3D=3D SMM_CORE_IMAGE_DATABASE_SIGNA= TURE) { + if (ImageStruct->ImageRef =3D=3D ImageRef) { + return ImageStruct; + } + } + ImageStruct =3D (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Leng= th); + } + + return NULL; +} + +/** + Dump SMM loaded image information. +**/ +VOID +DumpSmmLoadedImage( + VOID + ) +{ + SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct; + CHAR8 *PdbString; + CHAR8 *NameString; + + ImageStruct =3D (VOID *)mSmiHandlerProfileDatabase; + while ((UINTN)ImageStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHand= lerProfileDatabaseSize) { + if (ImageStruct->Header.Signature =3D=3D SMM_CORE_IMAGE_DATABASE_SIGNA= TURE) { + NameString =3D GetDriverNameString (ImageStruct); + Print(L" ImageBase, I= mageStruct->ImageSize); + if (ImageStruct->EntryPoint !=3D 0) { + Print(L" EntryPoint=3D\"0x%x\"", ImageStruct->EntryPoint); + } + Print(L" FvFile=3D\"%g\"", &ImageStruct->FileGuid); + Print(L" RefId=3D\"0x%x\"", ImageStruct->ImageRef); + Print(L">\n"); + PdbString =3D (CHAR8 *)((UINTN)ImageStruct + ImageStruct->PdbStringO= ffset); + Print(L" %a\n", PdbString); + Print(L" \n"); + } + + ImageStruct =3D (VOID *)((UINTN)ImageStruct + ImageStruct->Header.Leng= th); + } + + return; +} + +CHAR8 *mSxTypeString[] =3D { + "SxS0", + "SxS1", + "SxS2", + "SxS3", + "SxS4", + "SxS5", +}; + +/** + Convert SxType to a string. + + @param Type SxType + + @return SxType string +**/ +CHAR8 * +SxTypeToString ( + IN EFI_SLEEP_TYPE Type + ) +{ + if (Type >=3D 0 && Type <=3D ARRAY_SIZE(mSxTypeString)) { + return mSxTypeString[Type]; + } else { + AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Type); + return mNameString; + } +} + +CHAR8 *mSxPhaseString[] =3D { + "SxEntry", + "SxExit", +}; + +/** + Convert SxPhase to a string. + + @param Phase SxPhase + + @return SxPhase string +**/ +CHAR8 * +SxPhaseToString ( + IN EFI_SLEEP_PHASE Phase + ) +{ + if (Phase >=3D 0 && Phase <=3D ARRAY_SIZE(mSxPhaseString)) { + return mSxPhaseString[Phase]; + } else { + AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Phase); + return mNameString; + } +} + +CHAR8 *mPowerButtonPhaseString[] =3D { + "PowerButtonEntry", + "PowerButtonExit", +}; + +/** + Convert PowerButtonPhase to a string. + + @param Phase PowerButtonPhase + + @return PowerButtonPhase string +**/ +CHAR8 * +PowerButtonPhaseToString ( + IN EFI_POWER_BUTTON_PHASE Phase + ) +{ + if (Phase >=3D 0 && Phase <=3D ARRAY_SIZE(mPowerButtonPhaseString)) { + return mPowerButtonPhaseString[Phase]; + } else { + AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Phase); + return mNameString; + } +} + +CHAR8 *mStandbyButtonPhaseString[] =3D { + "StandbyButtonEntry", + "StandbyButtonExit", +}; + +/** + Convert StandbyButtonPhase to a string. + + @param Phase StandbyButtonPhase + + @return StandbyButtonPhase string +**/ +CHAR8 * +StandbyButtonPhaseToString ( + IN EFI_STANDBY_BUTTON_PHASE Phase + ) +{ + if (Phase >=3D 0 && Phase <=3D ARRAY_SIZE(mStandbyButtonPhaseString)) { + return mStandbyButtonPhaseString[Phase]; + } else { + AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Phase); + return mNameString; + } +} + +CHAR8 *mIoTrapTypeString[] =3D { + "WriteTrap", + "ReadTrap", + "ReadWriteTrap", +}; + +/** + Convert IoTrapType to a string. + + @param Type IoTrapType + + @return IoTrapType string +**/ +CHAR8 * +IoTrapTypeToString ( + IN EFI_SMM_IO_TRAP_DISPATCH_TYPE Type + ) +{ + if (Type >=3D 0 && Type <=3D ARRAY_SIZE(mIoTrapTypeString)) { + return mIoTrapTypeString[Type]; + } else { + AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Type); + return mNameString; + } +} + +CHAR8 *mUsbTypeString[] =3D { + "UsbLegacy", + "UsbWake", +}; + +/** + Convert UsbType to a string. + + @param Type UsbType + + @return UsbType string +**/ +CHAR8 * +UsbTypeToString ( + IN EFI_USB_SMI_TYPE Type + ) +{ + if (Type >=3D 0 && Type <=3D ARRAY_SIZE(mUsbTypeString)) { + return mUsbTypeString[Type]; + } else { + AsciiSPrint (mNameString, sizeof(mNameString), "0x%x", Type); + return mNameString; + } +} + +/** + Dump SMI child context. + + @param HandlerType the handler type + @param Context the handler context + @param ContextSize the handler context size +**/ +VOID +DumpSmiChildContext ( + IN EFI_GUID *HandlerType, + IN VOID *Context, + IN UINTN ContextSize + ) +{ + if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) { + Print(L" SwSmi=3D\"0x%x\"", ((EFI_SMM_SW_REGISTER_CONTEXT *)Context)->= SwSmiInputValue); + } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) { + Print(L" SxType=3D\"%a\"", SxTypeToString(((EFI_SMM_SX_REGISTER_CONTEX= T *)Context)->Type)); + Print(L" SxPhase=3D\"%a\"", SxPhaseToString(((EFI_SMM_SX_REGISTER_CONT= EXT *)Context)->Phase)); + } else if (CompareGuid (HandlerType, &gEfiSmmPowerButtonDispatch2Protoco= lGuid)) { + Print(L" PowerButtonPhase=3D\"%a\"", PowerButtonPhaseToString(((EFI_SM= M_POWER_BUTTON_REGISTER_CONTEXT *)Context)->Phase)); + } else if (CompareGuid (HandlerType, &gEfiSmmStandbyButtonDispatch2Proto= colGuid)) { + Print(L" StandbyButtonPhase=3D\"%a\"", StandbyButtonPhaseToString(((EF= I_SMM_STANDBY_BUTTON_REGISTER_CONTEXT *)Context)->Phase)); + } else if (CompareGuid (HandlerType, &gEfiSmmPeriodicTimerDispatch2Proto= colGuid)) { + Print(L" PeriodicTimerPeriod=3D\"%ld\"", ((EFI_SMM_PERIODIC_TIMER_REGI= STER_CONTEXT *)Context)->Period); + Print(L" PeriodicTimerSmiTickInterval=3D\"%ld\"", ((EFI_SMM_PERIODIC_T= IMER_REGISTER_CONTEXT *)Context)->SmiTickInterval); + } else if (CompareGuid (HandlerType, &gEfiSmmGpiDispatch2ProtocolGuid)) { + Print(L" GpiNum=3D\"0x%lx\"", ((EFI_SMM_GPI_REGISTER_CONTEXT *)Context= )->GpiNum); + } else if (CompareGuid (HandlerType, &gEfiSmmIoTrapDispatch2ProtocolGuid= )) { + Print(L" IoTrapAddress=3D\"0x%x\"", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT= *)Context)->Address); + Print(L" IoTrapLength=3D\"0x%x\"", ((EFI_SMM_IO_TRAP_REGISTER_CONTEXT = *)Context)->Length); + Print(L" IoTrapType=3D\"%a\"", IoTrapTypeToString(((EFI_SMM_IO_TRAP_RE= GISTER_CONTEXT *)Context)->Type)); + } else if (CompareGuid (HandlerType, &gEfiSmmUsbDispatch2ProtocolGuid)) { + Print(L" UsbType=3D\"0x%x\"", UsbTypeToString(((SMI_HANDLER_PROFILE_US= B_REGISTER_CONTEXT *)Context)->Type)); + Print(L" UsbDevicePath=3D\"%s\"", ConvertDevicePathToText((EFI_DEVICE_= PATH_PROTOCOL *)(((SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *)Context) + 1)= , TRUE, TRUE)); + } else { + Print(L" Context=3D\""); + InternalDumpData (Context, ContextSize); + Print(L"\""); + } +} + +/** + Dump SMI handler in HandlerCategory. + + @param HandlerCategory SMI handler category +**/ +VOID +DumpSmiHandler( + IN UINT32 HandlerCategory + ) +{ + SMM_CORE_SMI_DATABASE_STRUCTURE *SmiStruct; + SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct; + UINTN Index; + SMM_CORE_IMAGE_DATABASE_STRUCTURE *ImageStruct; + CHAR8 *NameString; + + SmiStruct =3D (VOID *)mSmiHandlerProfileDatabase; + while ((UINTN)SmiStruct < (UINTN)mSmiHandlerProfileDatabase + mSmiHandle= rProfileDatabaseSize) { + if ((SmiStruct->Header.Signature =3D=3D SMM_CORE_SMI_DATABASE_SIGNATUR= E) && (SmiStruct->HandlerCategory =3D=3D HandlerCategory)) { + SmiHandlerStruct =3D (VOID *)(SmiStruct + 1); + Print(L" HandlerType)) { + Print(L" HandlerType=3D\"%g\"", &SmiStruct->HandlerType); + } + Print(L">\n"); + for (Index =3D 0; Index < SmiStruct->HandlerCount; Index++) { + Print(L" ContextBufferSize !=3D 0) { + DumpSmiChildContext (&SmiStruct->HandlerType, (UINT8 *)SmiHandle= rStruct + SmiHandlerStruct->ContextBufferOffset, SmiHandlerStruct->ContextB= ufferSize); + } + Print(L">\n"); + ImageStruct =3D GetImageFromRef((UINTN)SmiHandlerStruct->ImageRef); + NameString =3D GetDriverNameString (ImageStruct); + Print(L" \n", SmiHandl= erStruct->ImageRef, NameString); + if ((ImageStruct !=3D NULL) && (ImageStruct->PdbStringOffset !=3D = 0)) { + Print(L" %a\n", (UINT8 *)ImageStruct + ImageStru= ct->PdbStringOffset); + } + Print(L" \n"); + Print(L" \n", SmiHandlerStruct->H= andler); + if (ImageStruct !=3D NULL) { + Print(L" 0x%x\n", SmiHandlerStruct->Handler -= ImageStruct->ImageBase); + } + Print(L" \n", SmiHandlerStruct->Handler); + Print(L" \n", SmiHandlerStruct->Ca= llerAddr); + if (ImageStruct !=3D NULL) { + Print(L" 0x%x\n", SmiHandlerStruct->CallerAdd= r - ImageStruct->ImageBase); + } + Print(L" \n", SmiHandlerStruct->Handler); + SmiHandlerStruct =3D (VOID *)((UINTN)SmiHandlerStruct + SmiHandler= Struct->Length); + Print(L" \n"); + } + Print(L" \n"); + } + SmiStruct =3D (VOID *)((UINTN)SmiStruct + SmiStruct->Header.Length); + } + + return; +} + +/** + The Entry Point for SMI handler profile info application. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurred when executing this entry poi= nt. +**/ +EFI_STATUS +EFIAPI +SmiHandlerProfileInfoEntrypoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + GetSmiHandlerProfileDatabase(); + + if (mSmiHandlerProfileDatabase =3D=3D NULL) { + return EFI_SUCCESS; + } + + // + // Dump all image + // + Print(L"\n"); + Print(L"\n"); + Print(L"\n"); + Print(L" \n"); + DumpSmmLoadedImage(); + Print(L"\n\n"); + + // + // Dump SMI Handler + // + Print(L"\n"); + Print(L" \n\n"); + Print(L" \n"); + Print(L" \n"); + DumpSmiHandler(SmmCoreSmiHandlerCategoryRootHandler); + Print(L" \n\n"); + + Print(L" \n"); + Print(L" \n"); + DumpSmiHandler(SmmCoreSmiHandlerCategoryGuidHandler); + Print(L" \n\n"); + + Print(L" \n"); + Print(L" \n"); + DumpSmiHandler(SmmCoreSmiHandlerCategoryHardwareHandler); + Print(L" \n\n"); + + Print(L"\n"); + Print(L"\n"); + + if (mSmiHandlerProfileDatabase !=3D NULL) { + FreePool(mSmiHandlerProfileDatabase); + } + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfi= leInfo.inf b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfi= leInfo.inf new file mode 100644 index 0000000..73cc052 --- /dev/null +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.= inf @@ -0,0 +1,65 @@ +## @file +# Shell application to dump SMI handler profile information. +# +# Note that if the feature is not enabled by setting PcdSmiHandlerProfileP= ropertyMask, +# the application will not display SMI handler profile information. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# This program and the accompanying materials are licensed and made availa= ble under +# the terms and conditions of the BSD License that accompanies this distri= bution. +# 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 IMP= LIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmiHandlerProfileInfo + MODULE_UNI_FILE =3D SmiHandlerProfileInfo.uni + FILE_GUID =3D 611EA796-8DF8-4BB6-91FE-6540ED70DC66 + MODULE_TYPE =3D UEFI_APPLICATION + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D SmiHandlerProfileInfoEntrypoint + +[Sources] + SmiHandlerProfileInfo.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + BaseLib + BaseMemoryLib + MemoryAllocationLib + DebugLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + UefiLib + PrintLib + DevicePathLib + PeCoffGetEntryPointLib + DxeServicesLib + +[Protocols] + gEfiSmmCommunicationProtocolGuid ## CONSUMES + gEfiSmmSwDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmSxDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmPowerButtonDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmStandbyButtonDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmPeriodicTimerDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmGpiDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmIoTrapDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + gEfiSmmUsbDispatch2ProtocolGuid ## SOMETIMES_CONSUMES + +[Guids] + gEdkiiPiSmmCommunicationRegionTableGuid ## CONSUMES ## SystemTable + gSmiHandlerProfileGuid ## SOMETIMES_CONSUMES ## GUID= # SmiHandlerRegister + +[UserExtensions.TianoCore."ExtraFiles"] + SmiHandlerProfileInfoExtra.uni + diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfi= leInfo.uni b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfi= leInfo.uni new file mode 100644 index 0000000..d73a1a0 --- /dev/null +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.= uni @@ -0,0 +1,22 @@ +// /** @file +// Shell application to dump SMI handler profile information. +// +// Note that if the feature is not enabled by setting PcdSmiHandlerProfile= PropertyMask, +// the application will not display SMI handler profile information. +// +// Copyright (c) 2017, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD License +// which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Shell application= to dump SMI handler profile information." + +#string STR_MODULE_DESCRIPTION #language en-US "Note that if the = feature is not enabled by setting PcdSmiHandlerProfilePropertyMask, the app= lication will not display SMI handler profile information." + diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfi= leInfoExtra.uni b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandler= ProfileInfoExtra.uni new file mode 100644 index 0000000..b10c71a --- /dev/null +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfoE= xtra.uni @@ -0,0 +1,19 @@ +// /** @file +// SmiHandlerProfileInfo Localized Strings and Content +// +// Copyright (c) 2017, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD License +// which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"SMI Handler Profile Information Application" + + --=20 2.7.4.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel