From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.29934.1683754322206264467 for ; Wed, 10 May 2023 14:32:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=kiIW7IhF; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: gua.guo@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683754329; x=1715290329; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uQYF0TmHx2LDlS0su+uMsM2Ljj+dkKnPpjqScEgHl5E=; b=kiIW7IhFO38EYUwRC8nphSQZXgpjqhvG4YQP+x4x7WYbu3gYqTlQk1fZ bTD4czTY/KWmmHhaEfCc6JmnpdrqffvaJ/3Nvqo1G87lwBBVMyzjQbo1B ZIH1VagEh3wqHKhk2lGEQRbfhLE8A0gfSjet5g643/sqbnFswOMGWMVh8 ZlfM3rZdf2pZbXJUPkcYowJN8Jwna8aGjzwXZMNrOpJC08LQPHSULhudg d0OX4W2PHDRbfnNGmOunpn2mGOt2UDXhzbQdt1mXIjqj2wlbEYwEP9Nx4 f4h6PCzBiSYWYWnavmM+uCTMzpL62jFtQYd3iLt5Zgw77DG3mZpXifKqw Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="334798111" X-IronPort-AV: E=Sophos;i="5.99,265,1677571200"; d="scan'208";a="334798111" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 14:32:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="823694005" X-IronPort-AV: E=Sophos;i="5.99,265,1677571200"; d="scan'208";a="823694005" Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by orsmga004.jf.intel.com with ESMTP; 10 May 2023 14:32:06 -0700 From: "Guo, Gua" To: devel@edk2.groups.io Cc: gua.guo@intel.com, Michael D Kinney , Chan Laura , Prakashan Krishnadas Veliyathuparambil , K N Karthik Subject: [PATCH v7 4/5] MdeModulePkg: Add TraceHubDebugSysTLib library Date: Thu, 11 May 2023 05:31:53 +0800 Message-Id: <20230510213154.1994-5-gua.guo@intel.com> X-Mailer: git-send-email 2.39.2.windows.1 In-Reply-To: <20230510213154.1994-1-gua.guo@intel.com> References: <20230510213154.1994-1-gua.guo@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Gua Guo REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4144 This Library provides API to dump Trace Hub message. Cc: Michael D Kinney Cc: Guo Gua Cc: Chan Laura Cc: Prakashan Krishnadas Veliyathuparambil Cc: K N Karthik Signed-off-by: Guo Gua Reviewed-by: Michael D Kinney Reviewed-by: K N Karthik Reviewed-by: Chan Laura --- .../Include/Guid/TraceHubDebugInfoHob.h | 24 ++ .../BaseTraceHubDebugSysTLib.c | 245 +++++++++++++++ .../BaseTraceHubDebugSysTLib.inf | 44 +++ .../DxeSmmTraceHubDebugSysTLib.c | 263 ++++++++++++++++ .../DxeSmmTraceHubDebugSysTLib.inf | 51 ++++ .../InternalTraceHubApi.c | 74 +++++ .../InternalTraceHubApi.h | 37 +++ .../InternalTraceHubApiCommon.c | 200 +++++++++++++ .../InternalTraceHubApiCommon.h | 119 ++++++++ .../PeiTraceHubDebugSysTLib.c | 282 ++++++++++++++++++ .../PeiTraceHubDebugSysTLib.inf | 50 ++++ .../Library/TraceHubDebugSysTLib/Readme.md | 26 ++ MdeModulePkg/MdeModulePkg.dec | 21 ++ MdeModulePkg/MdeModulePkg.dsc | 3 + MdeModulePkg/MdeModulePkg.uni | 18 ++ 15 files changed, 1457 insertions(+) create mode 100644 MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubD= ebugSysTLib.c create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubD= ebugSysTLib.inf create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHu= bDebugSysTLib.c create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHu= bDebugSysTLib.inf create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTrace= HubApi.c create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTrace= HubApi.h create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTrace= HubApiCommon.c create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTrace= HubApiCommon.h create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDe= bugSysTLib.c create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDe= bugSysTLib.inf create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md diff --git a/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h b/MdeModulePk= g/Include/Guid/TraceHubDebugInfoHob.h new file mode 100644 index 0000000000..367f97dc90 --- /dev/null +++ b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h @@ -0,0 +1,24 @@ +/** @file=0D +This header file declares Trace Hub related structure.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef TRACE_HUB_DEBUG_INFO_HOB_H_=0D +#define TRACE_HUB_DEBUG_INFO_HOB_H_=0D +=0D +#define TRACEHUB_DEBUG_INFO_HOB_REVISION 1=0D +=0D +typedef struct {=0D + UINT16 Revision; // Structure revision=0D + BOOLEAN Flag; // Flag to enable or disable Trace Hub d= ebug message.=0D + UINT8 DebugLevel; // Debug level for Trace Hub.=0D + UINT8 Rvsd[4]; // Reserved for future use=0D + UINT64 TraceHubMmioAddress; // MMIO address where Trace Hub debug me= ssage output to.=0D +} TRACEHUB_DEBUG_INFO_HOB;=0D +=0D +extern GUID gTraceHubDebugInfoHobGuid;=0D +=0D +#endif // TRACE_HUB_DEBUG_INFO_HOB_H_=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSys= TLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib= .c new file mode 100644 index 0000000000..45dfd3127a --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c @@ -0,0 +1,245 @@ +/** @file=0D +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.=0D +Only support single Trace Hub debug instance.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "InternalTraceHubApiCommon.h"=0D +#include "InternalTraceHubApi.h"=0D +=0D +/**=0D + Write debug string to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Buffer A pointer to the data buffer.=0D + @param[in] NumberOfBytes The size of data buffer.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTDebugWrite (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT8 *Buffer,=0D + IN UINTN NumberOfBytes=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + RETURN_STATUS Status;=0D + UINT32 DbgInstCount;=0D + UINT16 Index;=0D +=0D + if (NumberOfBytes =3D=3D 0) {=0D + //=0D + // No data need to be written to Trace Hub=0D + //=0D + return RETURN_SUCCESS;=0D + }=0D +=0D + if (Buffer =3D=3D NULL) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + DbgInstCount =3D CountThDebugInstance ();=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + for (Index =3D 0; Index < DbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + NULL,=0D + SeverityType,=0D + TraceHubDebugType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteDebug (=0D + &MipiSystHandle,=0D + SeverityType,=0D + (UINT16)NumberOfBytes,=0D + (CHAR8 *)Buffer=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Write catalog status code message to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Id Catalog ID.=0D + @param[in] Guid Driver Guid.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTWriteCataLog64StatusCode (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT64 Id,=0D + IN GUID *Guid=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + RETURN_STATUS Status;=0D + UINT32 DbgInstCount;=0D + UINT16 Index;=0D +=0D + if (Guid =3D=3D NULL) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + DbgInstCount =3D CountThDebugInstance ();=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid);=0D + MipiSystHandle.systh_tag.et_guid =3D 1;=0D +=0D + for (Index =3D 0; Index < DbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + NULL,=0D + SeverityType,=0D + TraceHubCatalogType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteCatalog (=0D + &MipiSystHandle,=0D + SeverityType,=0D + Id=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Write catalog message to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Id Catalog ID.=0D + @param[in] NumberOfParams Number of entries in argument list.=0D + @param[in] ... Catalog message parameters.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTWriteCataLog64 (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT64 Id,=0D + IN UINTN NumberOfParams,=0D + ...=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + VA_LIST Args;=0D + UINTN Index;=0D + RETURN_STATUS Status;=0D + UINT32 DbgInstCount;=0D +=0D + DbgInstCount =3D 0;=0D +=0D + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT3= 2)) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + DbgInstCount =3D CountThDebugInstance ();=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams;=0D + VA_START (Args, NumberOfParams);=0D + for (Index =3D 0; Index < NumberOfParams; Index++) {=0D + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32);=0D + }=0D +=0D + VA_END (Args);=0D +=0D + for (Index =3D 0; Index < DbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + NULL,=0D + SeverityType,=0D + TraceHubCatalogType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteCatalog (=0D + &MipiSystHandle,=0D + SeverityType,=0D + Id=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Collect the total number of Trace Hub debug instance in the system.=0D +=0D + @retval UINT32 The total number of Trace Hub debug instance in the = system.=0D +**/=0D +UINT32=0D +EFIAPI=0D +CountThDebugInstance (=0D + VOID=0D + )=0D +{=0D + UINT32 DbgInstCount;=0D +=0D + //=0D + // 1 from PCD.=0D + //=0D + DbgInstCount =3D 1;=0D +=0D + return DbgInstCount;=0D +}=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSys= TLib.inf b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTL= ib.inf new file mode 100644 index 0000000000..3edc4e8fd8 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf @@ -0,0 +1,44 @@ +## @file=0D +# Debug library to output Trace Hub message.=0D +# Support SEC/PEI/DXE/SMM phase TraceHub debug message based on fixed set= tings.=0D +#=0D +# Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D BaseTraceHubDebugSysTLib=0D + FILE_GUID =3D 336DA571-AD65-423C-9A43-E0056E5B2D8D= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TraceHubDebugSysTLib=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + PcdLib=0D + BaseMemoryLib=0D + MipiSysTLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D +=0D +[Sources]=0D + BaseTraceHubDebugSysTLib.c=0D + InternalTraceHubApiCommon.c=0D + InternalTraceHubApiCommon.h=0D + InternalTraceHubApi.h=0D +=0D +[Pcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugS= ysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys= TLib.c new file mode 100644 index 0000000000..35c239b5fe --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c @@ -0,0 +1,263 @@ +/** @file=0D +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB.=0D +Trace Hub PCDs will be applied if no HOB exist.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "InternalTraceHubApiCommon.h"=0D +#include "InternalTraceHubApi.h"=0D +=0D +GLOBAL_REMOVE_IF_UNREFERENCED TRACEHUB_DEBUG_INFO_HOB *mThDebugInstArray = =3D NULL;=0D +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mDbgInstCount = =3D 0;=0D +=0D +/**=0D + Write debug string to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Buffer A pointer to the data buffer.=0D + @param[in] NumberOfBytes The size of data buffer.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTDebugWrite (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT8 *Buffer,=0D + IN UINTN NumberOfBytes=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + RETURN_STATUS Status;=0D + UINT16 Index;=0D +=0D + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) {=0D + return RETURN_ABORTED;=0D + }=0D +=0D + if (NumberOfBytes =3D=3D 0) {=0D + //=0D + // No data need to be written to Trace Hub=0D + //=0D + return RETURN_SUCCESS;=0D + }=0D +=0D + if (Buffer =3D=3D NULL) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + for (Index =3D 0; Index < mDbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + (UINT8 *)&mThDebugInstArray[Index],=0D + SeverityType,=0D + TraceHubDebugType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteDebug (=0D + &MipiSystHandle,=0D + SeverityType,=0D + (UINT16)NumberOfBytes,=0D + (CHAR8 *)Buffer=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Write catalog status code message to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Id Catalog ID.=0D + @param[in] Guid Driver Guid.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTWriteCataLog64StatusCode (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT64 Id,=0D + IN GUID *Guid=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + UINTN Index;=0D + RETURN_STATUS Status;=0D +=0D + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) {=0D + return RETURN_ABORTED;=0D + }=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + if (Guid !=3D NULL) {=0D + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid);=0D + MipiSystHandle.systh_tag.et_guid =3D 1;=0D + } else {=0D + MipiSystHandle.systh_tag.et_modunit =3D 2;=0D + MipiSystHandle.systh_tag.et_guid =3D 0;=0D + }=0D +=0D + for (Index =3D 0; Index < mDbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + (UINT8 *)&mThDebugInstArray[Index],=0D + SeverityType,=0D + TraceHubCatalogType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteCatalog (=0D + &MipiSystHandle,=0D + SeverityType,=0D + Id=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Write catalog message to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Id Catalog ID.=0D + @param[in] NumberOfParams Number of entries in argument list.=0D + @param[in] ... Catalog message parameters.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTWriteCataLog64 (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT64 Id,=0D + IN UINTN NumberOfParams,=0D + ...=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + VA_LIST Args;=0D + UINTN Index;=0D + RETURN_STATUS Status;=0D +=0D + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT3= 2)) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) {=0D + return RETURN_ABORTED;=0D + }=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams;=0D + VA_START (Args, NumberOfParams);=0D + for (Index =3D 0; Index < NumberOfParams; Index++) {=0D + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32);=0D + }=0D +=0D + VA_END (Args);=0D +=0D + for (Index =3D 0; Index < mDbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + (UINT8 *)&mThDebugInstArray[Index],=0D + SeverityType,=0D + TraceHubCatalogType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteCatalog (=0D + &MipiSystHandle,=0D + SeverityType,=0D + Id=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Constructor to get TraceHob configuration data=0D +=0D + @param ImageHandle The firmware allocated handle for the EFI image.=0D + @param SystemTable A pointer to the EFI System Table.=0D +=0D + @retval RETURN_SUCCESS The constructor always returns EFI_SUCC= ESS.=0D + @retval RETURN_OUT_OF_RESOURCES There are not enough resources availabl= e to retrieve the matching FFS section.=0D +=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +DxeSmmTraceHubDebugSysTLibConstructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + if (mDbgInstCount =3D=3D 0) {=0D + mDbgInstCount =3D CountThDebugInstance ();=0D + }=0D +=0D + mThDebugInstArray =3D AllocateZeroPool (mDbgInstCount * sizeof (TRACEHUB= _DEBUG_INFO_HOB));=0D +=0D + if (mThDebugInstArray !=3D NULL) {=0D + PackThDebugInstance (mThDebugInstArray, mDbgInstCount);=0D + } else {=0D + return RETURN_OUT_OF_RESOURCES;=0D + }=0D +=0D + return RETURN_SUCCESS;=0D +}=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugS= ysTLib.inf b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugS= ysTLib.inf new file mode 100644 index 0000000000..90213beee1 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.= inf @@ -0,0 +1,51 @@ +## @file=0D +# Debug library to output Trace Hub message.=0D +# Support DXE/SMM phase TraceHub debug message based on fixed or dynamic = settings.=0D +#=0D +# Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D DxeSmmTraceHubDebugSysTLib=0D + FILE_GUID =3D A9B7B825-7902-4616-8556-085DA4DFEC72= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TraceHubDebugSysTLib|DXE_CORE DXE_DRI= VER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION=0D + CONSTRUCTOR =3D DxeSmmTraceHubDebugSysTLibConstructor= =0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + PcdLib=0D + HobLib=0D + BaseMemoryLib=0D + MemoryAllocationLib=0D + MipiSysTLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D +=0D +[Sources]=0D + DxeSmmTraceHubDebugSysTLib.c=0D + InternalTraceHubApiCommon.c=0D + InternalTraceHubApiCommon.h=0D + InternalTraceHubApi.h=0D + InternalTraceHubApi.c=0D +=0D +[Guids]=0D + gTraceHubDebugInfoHobGuid=0D +=0D +[Pcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.= c b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c new file mode 100644 index 0000000000..fe946fe60c --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c @@ -0,0 +1,74 @@ +/** @file=0D +Functions implementation in this file are not common for all type of Trace= HubDebugSysTLib.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "InternalTraceHubApi.h"=0D +=0D +/**=0D + Count the total number of Trace Hub debug instance in the system.=0D +=0D + @retval UINT32 The total number of Trace Hub debug instance in the = system.=0D +**/=0D +UINT32=0D +EFIAPI=0D +CountThDebugInstance (=0D + VOID=0D + )=0D +{=0D + UINT8 *DbgContext;=0D + UINT32 DbgInstCount;=0D +=0D + DbgInstCount =3D 0;=0D +=0D + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);=0D + if (DbgContext !=3D NULL) {=0D + while (DbgContext !=3D NULL) {=0D + DbgInstCount++;=0D + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext));=0D + }=0D + } else {=0D + DbgInstCount++;=0D + }=0D +=0D + return DbgInstCount;=0D +}=0D +=0D +/**=0D + Pack Trace Hub debug instances in the system.=0D +=0D + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB structur= e.=0D + @param[in] Count Number of Trace Hub HOBs.=0D +**/=0D +VOID=0D +EFIAPI=0D +PackThDebugInstance (=0D + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr,=0D + IN UINT32 Count=0D + )=0D +{=0D + UINT8 *DbgContext;=0D + UINT16 Index;=0D +=0D + DbgContext =3D GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);=0D + if (DbgContext !=3D NULL) {=0D + for (Index =3D 0; Index < Count; Index++) {=0D + CopyMem (&ThPtr[Index], GET_GUID_HOB_DATA (DbgContext), sizeof (TRAC= EHUB_DEBUG_INFO_HOB));=0D + DbgContext =3D GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_= HOB (DbgContext));=0D + }=0D + } else {=0D + for (Index =3D 0; Index < Count; Index++) {=0D + ThPtr[Index].TraceHubMmioAddress =3D FixedPcdGet64 (PcdTraceHubDebug= MmioAddress);=0D + ThPtr[Index].Flag =3D FixedPcdGetBool (PcdEnableTrace= HubDebugMsg);=0D + ThPtr[Index].DebugLevel =3D FixedPcdGet8 (PcdTraceHubDebugL= evel);=0D + }=0D + }=0D +}=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.= h b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h new file mode 100644 index 0000000000..f624f73768 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h @@ -0,0 +1,37 @@ +/** @file=0D +This header file declares functions that are not for common use.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef INTERNAL_TRACE_HUB_API_H_=0D +#define INTERNAL_TRACE_HUB_API_H_=0D +=0D +/**=0D + Count the total number of Trace Hub debug instance in the system.=0D +=0D + @retval UINT32 The total number of Trace Hub debug instance in the = system.=0D +**/=0D +UINT32=0D +EFIAPI=0D +CountThDebugInstance (=0D + VOID=0D + );=0D +=0D +/**=0D + Pack Trace Hub debug instances in the system.=0D +=0D + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB structur= e.=0D + @param[in] Count Number of Trace Hub HOBs.=0D +**/=0D +VOID=0D +EFIAPI=0D +PackThDebugInstance (=0D + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr,=0D + IN UINT32 Count=0D + );=0D +=0D +#endif // INTERNAL_TRACE_HUB_API_H_=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiC= ommon.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm= on.c new file mode 100644 index 0000000000..fe77f486f4 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c @@ -0,0 +1,200 @@ +/** @file=0D +Functions implementation defined in this file are common for all type of T= raceHubDebugSysTLib=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "InternalTraceHubApiCommon.h"=0D +#include "InternalTraceHubApi.h"=0D +=0D +/**=0D + Conditionally determine whether to enable Trace Hub message.=0D +=0D + @param[in] Flag Flag to enable or disable Trace Hub message.= =0D + @param[in] DbgLevel Debug Level of Trace Hub.=0D + @param[in] SeverityType Severity type of input message.=0D +=0D + @retval TRUE Enable trace hub message.=0D + @retval FALSE Disable trace hub message.=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +TraceHubDataEnabled (=0D + IN BOOLEAN Flag,=0D + IN UINT8 DbgLevel,=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType=0D + )=0D +{=0D + if (Flag =3D=3D TraceHubRoutingDisable) {=0D + return FALSE;=0D + }=0D +=0D + if (DbgLevel =3D=3D TraceHubDebugLevelError) {=0D + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError))) {=0D + return TRUE;=0D + }=0D + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarning) {=0D + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError) || (SeverityType =3D=3D SeverityWarning))) {=0D + return TRUE;=0D + }=0D + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfo) {=0D + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError) || (SeverityType =3D=3D SeverityWarning) || (SeverityType =3D=3D = SeverityNormal))) {=0D + return TRUE;=0D + }=0D + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfoVerbose) {= =0D + return TRUE;=0D + }=0D +=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Convert GUID from LE to BE or BE to LE.=0D +=0D + @param[in] Guid GUID that need to be converted.=0D + @param[out] ConvertedGuid GUID that is converted.=0D +**/=0D +VOID=0D +EFIAPI=0D +SwapBytesGuid (=0D + IN GUID *Guid,=0D + OUT GUID *ConvertedGuid=0D + )=0D +{=0D + CopyGuid (ConvertedGuid, Guid);=0D + ConvertedGuid->Data1 =3D SwapBytes32 (ConvertedGuid->Data1);=0D + ConvertedGuid->Data2 =3D SwapBytes16 (ConvertedGuid->Data2);=0D + ConvertedGuid->Data3 =3D SwapBytes16 (ConvertedGuid->Data3);=0D +}=0D +=0D +/**=0D + Check whether to output Trace Hub message according to some conditions.= =0D + Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE= =0D + or Trace Hub MMIO address is 0.=0D +=0D + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e.=0D + @param[in] DbgContext A pointer to Trace Hub debug instance.= =0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] PrintType Either catalog print or debug print.=0D +=0D + @retval RETURN_SUCCESS Current Trace Hub message need to be output.= =0D + @retval Other Current Trace Hub message will be disabled.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +CheckWhetherToOutputMsg (=0D + IN OUT MIPI_SYST_HANDLE *MipiSystHandle,=0D + IN UINT8 *DbgContext,=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN TRACEHUB_PRINTTYPE PrintType=0D + )=0D +{=0D + UINT8 DbgLevel;=0D + BOOLEAN Flag;=0D + UINT64 Addr;=0D + RETURN_STATUS Status;=0D +=0D + if (MipiSystHandle =3D=3D NULL) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + if (PrintType =3D=3D TraceHubDebugType) {=0D + Status =3D GetTraceHubMsgVisibility (DbgContext, &Flag, &DbgLevel);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + if (!TraceHubDataEnabled (Flag, DbgLevel, SeverityType)) {=0D + return RETURN_ABORTED;=0D + }=0D + }=0D +=0D + Status =3D GetTraceHubMmioAddress (DbgContext, &Addr);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D Addr;=0D + if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D=3D = 0) {=0D + return RETURN_ABORTED;=0D + }=0D +=0D + return RETURN_SUCCESS;=0D +}=0D +=0D +/**=0D + Get Trace Hub MMIO Address.=0D +=0D + @param[in] DbgContext A pointer to Trace Hub debug instance.= =0D + @param[in, out] TraceAddress Trace Hub MMIO Address.=0D +=0D + @retval RETURN_SUCCESS Operation is successfully.=0D + @retval Other Operation is failed.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +GetTraceHubMmioAddress (=0D + IN UINT8 *DbgContext,=0D + IN OUT UINT64 *TraceAddress=0D + )=0D +{=0D + TRACEHUB_DEBUG_INFO_HOB *ThDbgContext;=0D +=0D + if (TraceAddress =3D=3D NULL) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + if (DbgContext !=3D NULL) {=0D + ThDbgContext =3D (TRACEHUB_DEBUG_INFO_HOB *)DbgContext;=0D + *TraceAddress =3D ThDbgContext->TraceHubMmioAddress;=0D + } else {=0D + *TraceAddress =3D FixedPcdGet64 (PcdTraceHubDebugMmioAddress);=0D + }=0D +=0D + return RETURN_SUCCESS;=0D +}=0D +=0D +/**=0D + Get visibility of Trace Hub Msg.=0D +=0D + @param[in] DbgContext A pointer to Trace Hub debug instance.=0D + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age.=0D + @param[in, out] DbgLevel Debug Level of Trace Hub.=0D +=0D + @retval RETURN_SUCCESS Operation is successfully.=0D + @retval Other Operation is failed.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +GetTraceHubMsgVisibility (=0D + IN UINT8 *DbgContext,=0D + IN OUT BOOLEAN *Flag,=0D + IN OUT UINT8 *DbgLevel=0D + )=0D +{=0D + TRACEHUB_DEBUG_INFO_HOB *ThDbgContext;=0D +=0D + if ((Flag =3D=3D NULL) || (DbgLevel =3D=3D NULL)) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + if (DbgContext !=3D NULL) {=0D + ThDbgContext =3D (TRACEHUB_DEBUG_INFO_HOB *)DbgContext;=0D + *Flag =3D ThDbgContext->Flag;=0D + *DbgLevel =3D ThDbgContext->DebugLevel;=0D + } else {=0D + *DbgLevel =3D FixedPcdGet8 (PcdTraceHubDebugLevel);=0D + *Flag =3D FixedPcdGetBool (PcdEnableTraceHubDebugMsg);=0D + }=0D +=0D + return RETURN_SUCCESS;=0D +}=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiC= ommon.h b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm= on.h new file mode 100644 index 0000000000..b8be48a8bb --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.h @@ -0,0 +1,119 @@ +/** @file=0D +This header file declares functions and type for common use.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef INTERNAL_TRACE_HUB_API_COMMON_H_=0D +#define INTERNAL_TRACE_HUB_API_COMMON_H_=0D +=0D +typedef enum {=0D + TraceHubDebugType =3D 0,=0D + TraceHubCatalogType=0D +} TRACEHUB_PRINTTYPE;=0D +=0D +typedef enum {=0D + TraceHubRoutingDisable =3D 0,=0D + TraceHubRoutingEnable,=0D + TraceHubRoutingMax=0D +} TRACE_HUB_ROUTING;=0D +=0D +typedef enum {=0D + TraceHubDebugLevelError =3D 0,=0D + TraceHubDebugLevelErrorWarning,=0D + TraceHubDebugLevelErrorWarningInfo,=0D + TraceHubDebugLevelErrorWarningInfoVerbose,=0D + TraceHubDebugLevelMax=0D +} TRACE_HUB_DEBUG_LEVEL;=0D +=0D +/**=0D + Conditionally determine whether to enable Trace Hub message.=0D +=0D + @param[in] Flag Flag to enable or disable Trace Hub message.= =0D + @param[in] DbgLevel Debug Level of Trace Hub.=0D + @param[in] SeverityType Severity type of input message.=0D +=0D + @retval TRUE Enable trace hub message.=0D + @retval FALSE Disable trace hub message.=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +TraceHubDataEnabled (=0D + IN BOOLEAN Flag,=0D + IN UINT8 DbgLevel,=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType=0D + );=0D +=0D +/**=0D + Convert GUID from LE to BE or BE to LE.=0D +=0D + @param[in] Guid GUID that need to be converted.=0D + @param[out] ConvertedGuid GUID that is converted.=0D +**/=0D +VOID=0D +EFIAPI=0D +SwapBytesGuid (=0D + IN GUID *Guid,=0D + OUT GUID *ConvertedGuid=0D + );=0D +=0D +/**=0D + Check whether to output Trace Hub message according to some conditions.= =0D + Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE= =0D + or Trace Hub MMIO address is 0.=0D +=0D + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e.=0D + @param[in] DbgContext A pointer to Trace Hub debug instance.= =0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] PrintType Either catalog print or debug print.=0D +=0D + @retval RETURN_SUCCESS Current Trace Hub message need to be output.= =0D + @retval Other Current Trace Hub message will be disabled.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +CheckWhetherToOutputMsg (=0D + IN OUT MIPI_SYST_HANDLE *MipiSystHandle,=0D + IN UINT8 *DbgContext,=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN TRACEHUB_PRINTTYPE PrintType=0D + );=0D +=0D +/**=0D + Get Trace Hub MMIO Address.=0D +=0D + @param[in] DbgContext A pointer to Trace Hub debug instance.= =0D + @param[in, out] TraceAddress Trace Hub MMIO Address.=0D +=0D + @retval RETURN_SUCCESS Operation is successfully.=0D + @retval Other Operation is failed.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +GetTraceHubMmioAddress (=0D + IN UINT8 *DbgContext,=0D + IN OUT UINT64 *TraceAddress=0D + );=0D +=0D +/**=0D + Get visibility of Trace Hub Msg.=0D +=0D + @param[in] DbgContext A pointer to Trace Hub debug instance.=0D + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age.=0D + @param[in, out] DbgLevel Debug Level of Trace Hub.=0D +=0D + @retval RETURN_SUCCESS Operation is successfully.=0D + @retval Other Operation is failed.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +GetTraceHubMsgVisibility (=0D + IN UINT8 *DbgContext,=0D + IN OUT BOOLEAN *Flag,=0D + IN OUT UINT8 *DbgLevel=0D + );=0D +=0D +#endif // INTERNAL_TRACE_HUB_API_COMMON_H_=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysT= Lib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c new file mode 100644 index 0000000000..e68fb8b242 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c @@ -0,0 +1,282 @@ +/** @file=0D +System prints Trace Hub message in PEI based on fixed PCDs and HOB.=0D +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid HOB.= =0D +Trace Hub PCDs will be applied if no HOB exist.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "InternalTraceHubApiCommon.h"=0D +#include "InternalTraceHubApi.h"=0D +=0D +/**=0D + Write debug string to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Buffer A pointer to the data buffer.=0D + @param[in] NumberOfBytes The size of data buffer.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTDebugWrite (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT8 *Buffer,=0D + IN UINTN NumberOfBytes=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + RETURN_STATUS Status;=0D + UINT8 *DbgContext;=0D + UINTN Index;=0D + UINT32 DbgInstCount;=0D + UINT8 *ThDebugInfo;=0D +=0D + if (NumberOfBytes =3D=3D 0) {=0D + //=0D + // No data need to be written to Trace Hub=0D + //=0D + return RETURN_SUCCESS;=0D + }=0D +=0D + if (Buffer =3D=3D NULL) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + DbgInstCount =3D CountThDebugInstance ();=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);=0D + if (DbgContext !=3D NULL) {=0D + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext);=0D + } else {=0D + ThDebugInfo =3D NULL;=0D + }=0D +=0D + for (Index =3D 0; Index < DbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + ThDebugInfo,=0D + SeverityType,=0D + TraceHubDebugType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteDebug (=0D + &MipiSystHandle,=0D + SeverityType,=0D + (UINT16)NumberOfBytes,=0D + (CHAR8 *)Buffer=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D +=0D + if (DbgContext !=3D NULL) {=0D + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext));=0D + if (DbgContext =3D=3D NULL) {=0D + break;=0D + }=0D +=0D + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext);=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Write catalog status code message to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Id Catalog ID.=0D + @param[in] Guid Driver Guid.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTWriteCataLog64StatusCode (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT64 Id,=0D + IN GUID *Guid=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + UINT32 DbgInstCount;=0D + UINT8 *DbgContext;=0D + RETURN_STATUS Status;=0D + UINTN Index;=0D + UINT8 *ThDebugInfo;=0D +=0D + DbgInstCount =3D CountThDebugInstance ();=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + if (Guid !=3D NULL) {=0D + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid);=0D + MipiSystHandle.systh_tag.et_guid =3D 1;=0D + } else {=0D + MipiSystHandle.systh_tag.et_modunit =3D 2;=0D + MipiSystHandle.systh_tag.et_guid =3D 0;=0D + }=0D +=0D + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);=0D + if (DbgContext !=3D NULL) {=0D + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext);=0D + } else {=0D + ThDebugInfo =3D NULL;=0D + }=0D +=0D + for (Index =3D 0; Index < DbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + ThDebugInfo,=0D + SeverityType,=0D + TraceHubCatalogType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteCatalog (=0D + &MipiSystHandle,=0D + SeverityType,=0D + Id=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D +=0D + if (DbgContext !=3D NULL) {=0D + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext));=0D + if (DbgContext =3D=3D NULL) {=0D + break;=0D + }=0D +=0D + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext);=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Write catalog message to specified Trace Hub MMIO address.=0D +=0D + @param[in] SeverityType Severity type of input message.=0D + @param[in] Id Catalog ID.=0D + @param[in] NumberOfParams Number of entries in argument list.=0D + @param[in] ... Catalog message parameters.=0D +=0D + @retval RETURN_SUCCESS Data was written to Trace Hub.=0D + @retval Other Failed to output Trace Hub message.=0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +TraceHubSysTWriteCataLog64 (=0D + IN TRACE_HUB_SEVERITY_TYPE SeverityType,=0D + IN UINT64 Id,=0D + IN UINTN NumberOfParams,=0D + ...=0D + )=0D +{=0D + MIPI_SYST_HANDLE MipiSystHandle;=0D + MIPI_SYST_HEADER MipiSystHeader;=0D + VA_LIST Args;=0D + UINTN Index;=0D + UINT32 DbgInstCount;=0D + UINT8 *DbgContext;=0D + RETURN_STATUS Status;=0D + UINT8 *ThDebugInfo;=0D +=0D + DbgInstCount =3D 0;=0D +=0D + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT3= 2)) {=0D + return RETURN_INVALID_PARAMETER;=0D + }=0D +=0D + DbgInstCount =3D CountThDebugInstance ();=0D +=0D + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));=0D + MipiSystHandle.systh_header =3D &MipiSystHeader;=0D +=0D + Status =3D InitMipiSystHandle (&MipiSystHandle);=0D + if (RETURN_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams;=0D + VA_START (Args, NumberOfParams);=0D + for (Index =3D 0; Index < NumberOfParams; Index++) {=0D + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32);=0D + }=0D +=0D + VA_END (Args);=0D +=0D + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);=0D + if (DbgContext !=3D NULL) {=0D + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext);=0D + } else {=0D + ThDebugInfo =3D NULL;=0D + }=0D +=0D + for (Index =3D 0; Index < DbgInstCount; Index++) {=0D + Status =3D CheckWhetherToOutputMsg (=0D + &MipiSystHandle,=0D + ThDebugInfo,=0D + SeverityType,=0D + TraceHubCatalogType=0D + );=0D + if (!RETURN_ERROR (Status)) {=0D + Status =3D MipiSystWriteCatalog (=0D + &MipiSystHandle,=0D + SeverityType,=0D + Id=0D + );=0D + if (RETURN_ERROR (Status)) {=0D + break;=0D + }=0D + }=0D +=0D + if (DbgContext !=3D NULL) {=0D + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext));=0D + if (DbgContext =3D=3D NULL) {=0D + break;=0D + }=0D +=0D + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext);=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysT= Lib.inf b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib= .inf new file mode 100644 index 0000000000..2a8184d927 --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf @@ -0,0 +1,50 @@ +## @file=0D +# Debug library to output Trace Hub message.=0D +# Support PEI phase TraceHub debug message based on fixed or dynamic sett= ings.=0D +#=0D +# Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D PeiTraceHubDebugSysTLib=0D + FILE_GUID =3D C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TraceHubDebugSysTLib|PEI_CORE PEIM=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + PcdLib=0D + HobLib=0D + BaseMemoryLib=0D + MemoryAllocationLib=0D + MipiSysTLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D +=0D +[Sources]=0D + PeiTraceHubDebugSysTLib.c=0D + InternalTraceHubApiCommon.c=0D + InternalTraceHubApiCommon.h=0D + InternalTraceHubApi.h=0D + InternalTraceHubApi.c=0D +=0D +[Guids]=0D + gTraceHubDebugInfoHobGuid=0D +=0D +[Pcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress=0D diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md b/MdeModul= ePkg/Library/TraceHubDebugSysTLib/Readme.md new file mode 100644 index 0000000000..9e798a41bf --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md @@ -0,0 +1,26 @@ +## Introduction of TrcaceHubDebugSysTLib ##=0D +TrcaceHubDebugSysTLib library is a top level library for dumping Trace Hub= messages.=0D +It provides Trace Hub related APIs to dump Trace Hub message via MIPI SYS-= T submodule.=0D +User need to properly configure following Trace Hub related PCDs and HOB.= =0D + (See MdeModulePkg.dec to get detailed definition for PCDs below)=0D + - PcdTraceHubDebugLevel=0D + - PcdEnableTraceHubDebugMsg=0D + - PcdTraceHubDebugMmioAddress=0D + (See TraceHubDebugInfoHob.h to get detailed definition for HOB below)=0D + - gTraceHubDebugInfoHobGuid=0D +=0D +## BaseTraceHubDebugSysTLib.inf ##=0D +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.=0D +Only support single Trace Hub debug instance.=0D +=0D +## PeiTraceHubDebugSysTLib.inf ##=0D +System prints Trace Hub message in PEI based on fixed PCDs and HOB.=0D +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid HOB.= =0D +Trace Hub PCDs will be applied if no HOB exist.=0D +=0D +## DxeSmmTraceHubDebugSysTLib.inf ##=0D +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB.=0D +Trace Hub PCDs will be applied if no HOB exist.=0D +=0D +## Note ##=0D +Trace Hub debug library not support DXE_RUNTIME_DRIVER type of module curr= ently.=0D diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 9bb0d3ba2d..95dd077e19 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -439,6 +439,9 @@ ## Include/UniversalPayload/SerialPortInfo.h=0D gUniversalPayloadSerialPortInfoGuid =3D { 0xaa7e190d, 0xbe21, 0x4409, { = 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } }=0D =0D + ## Include/Guid/TraceHubDebugInfoHob.h=0D + gTraceHubDebugInfoHobGuid =3D { 0xf88c9c23, 0x646c, 0x4f6c, { 0x8e, 0x3d= , 0x36, 0xa9, 0x43, 0xc1, 0x08, 0x35 } }=0D +=0D ## GUID used for Boot Discovery Policy FormSet guid and related variable= s.=0D gBootDiscoveryPolicyMgrFormsetGuid =3D { 0x5b6f7107, 0xbb3c, 0x4660, { 0= x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } }=0D =0D @@ -1095,6 +1098,24 @@ # @Prompt Enable UEFI Stack Guard.=0D gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055= =0D =0D + ## Indicate debug level of Trace Hub.=0D + # 0x0 - TraceHubDebugLevelError.
=0D + # 0x1 - TraceHubDebugLevelErrorWarning.
=0D + # 0x2 - TraceHubDebugLevelErrorWarningInfo.
=0D + # 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
=0D + # @Prompt Debug level of Trace Hub.=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel|0|UINT8|0x30001056= =0D +=0D + ## Flag to enable or disable Trace Hub message.=0D + # FALSE - Disable Trace Hub debug message.
=0D + # TRUE - Enable Trace Hub debug message.
=0D + # @Prompt Enable or Disable Trace Hub message.=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg|0|BOOLEAN|0x300= 01057=0D +=0D + ## Indicate MMIO address where Trace Hub message output to.=0D + # @Prompt Output MMIO address of Trace Hub message.=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress|0|UINT64|0x30= 001058=0D +=0D [PcdsFixedAtBuild, PcdsPatchableInModule]=0D ## Dynamic type PCD can be registered callback function for Pcd setting = action.=0D # PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of= callback function=0D diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 1014598f31..5b1f50e9c0 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -515,6 +515,9 @@ MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf=0D MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferD= xe.inf=0D MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf=0D + MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf=0D + MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf=0D + MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf= =0D =0D [Components.X64]=0D MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf=0D diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 33ce9f6198..a17d34d60b 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1290,6 +1290,24 @@ = " TRUE - UEFI Stack Guard will be enabled.
\n"=0D = " FALSE - UEFI Stack Guard will be disabled.
"=0D =0D +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_PROMPT #= language en-US "Debug level of Trace Hub."=0D +=0D +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_HELP #= language en-US "Indicate debug level of Trace Hub"=0D + = " 0x0 - TraceHubDebugLevelError.
"=0D + = " 0x1 - TraceHubDebugLevelErrorWarning.
"=0D + = " 0x2 - TraceHubDebugLevelErrorWarningInfo.
"=0D + = " 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
"=0D +=0D +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_PROMP= T #language en-US "Flag to enable or disable Trace Hub message"=0D +=0D +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_HELP = #language en-US "Enable or Disable Trace Hub message"=0D + = " FALSE - Disable Trace Hub debug message.
"=0D + = " TRUE - Enable Trace Hub debug message.
"=0D +=0D +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_PRO= MPT #language en-US "Output MMIO address of Trace Hub message"=0D +=0D +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_HEL= P #language en-US "Indicate MMIO address where Trace Hub message output = to."=0D +=0D #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_PROMPT = #language en-US "NV Storage DefaultId"=0D =0D #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_HELP = #language en-US "This dynamic PCD enables the default variable setting.\n"= =0D --=20 2.39.2.windows.1