From nobody Mon Feb 9 09:33:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104634+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104634+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1683762033; cv=none; d=zohomail.com; s=zohoarc; b=M9hrcZWNDPJdiiMWcM/jGtP+NOtfY2q0YmUd0mRWDwMaSneZ0UYjPq15cHAvEjCY0K4lk9qH0JVlWoiz6Txbq9ai02f8buTbAaUtlV4ROjBbAuHawDZwA1oMVEwQ77/HH801M6vAD6ThWEALTm2PH/DHg1sMD+CPPPD+Z9tt3Gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683762033; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MDzb8ddPzoC9CKC3zACuLP8YKSyWrp1ci7nXHGOKQX8=; b=hXvQ2MrpIsI7o9fjCo8M3DpYhHVJiaAX2nZCNO6yRC1IZsEJCb3dadjMuaoPaGmBfvRhvSQwybqA7w8WNorMxeZ6X5Lvkf97N4c9r09nAWis4YiesnZqCj7Mmrtjd3EjSTdVrL1WwChB0Vh0UYhRndvNJN6vz3VEpVPagh2SE7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104634+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683762033965211.09630093410556; Wed, 10 May 2023 16:40:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id l8ZRYY1788612x4sYSkKQvGf; Wed, 10 May 2023 16:40:33 -0700 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.32930.1683762031295605069 for ; Wed, 10 May 2023 16:40:31 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="436672944" X-IronPort-AV: E=Sophos;i="5.99,265,1677571200"; d="scan'208";a="436672944" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2023 16:40:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="1029405186" X-IronPort-AV: E=Sophos;i="5.99,265,1677571200"; d="scan'208";a="1029405186" X-Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by fmsmga005.fm.intel.com with ESMTP; 10 May 2023 16:40:29 -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 , Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v9 4/5] MdeModulePkg: Add TraceHubDebugSysTLib library Date: Thu, 11 May 2023 07:39:29 +0800 Message-Id: <20230510233930.1419-5-gua.guo@intel.com> In-Reply-To: <20230510233930.1419-1-gua.guo@intel.com> References: <20230510233930.1419-1-gua.guo@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gua.guo@intel.com X-Gm-Message-State: FBi8Y6FKAtBmklZ4HjRLTm1Nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683762033; bh=GwrRAFCmV2+urEFAtF1vlEOqXPZi9grsIx7Qp9ICasM=; h=Cc:Date:From:Reply-To:Subject:To; b=JJeJhNNauS80AoUamvX/+Yantt430bsi6Ly1K2cpHOwKp3t/9Z0YXGIyY3oONcK9dt5 /HackXi7H2rz3+JW1B4KMaav1qmZL7oq5lnG+pHckuf5/+61d09KEjNYmALBuKvYn95DI bgC1HKNCVDF15p+XE8EAp3HdDIGpm4pN/7I= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683762036065100023 Content-Type: text/plain; charset="utf-8" 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 Cc: Jian J Wang Cc: Liming Gao 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 +This header file declares Trace Hub related structure. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef TRACE_HUB_DEBUG_INFO_HOB_H_ +#define TRACE_HUB_DEBUG_INFO_HOB_H_ + +#define TRACEHUB_DEBUG_INFO_HOB_REVISION 1 + +typedef struct { + UINT16 Revision; // Structure revision + BOOLEAN Flag; // Flag to enable or disable Trace Hub d= ebug message. + UINT8 DebugLevel; // Debug level for Trace Hub. + UINT8 Rvsd[4]; // Reserved for future use + UINT64 TraceHubMmioAddress; // MMIO address where Trace Hub debug me= ssage output to. +} TRACEHUB_DEBUG_INFO_HOB; + +extern GUID gTraceHubDebugInfoHobGuid; + +#endif // TRACE_HUB_DEBUG_INFO_HOB_H_ 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 +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs. +Only support single Trace Hub debug instance. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "InternalTraceHubApiCommon.h" +#include "InternalTraceHubApi.h" + +/** + Write debug string to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Buffer A pointer to the data buffer. + @param[in] NumberOfBytes The size of data buffer. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTDebugWrite ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + RETURN_STATUS Status; + UINT32 DbgInstCount; + UINT16 Index; + + if (NumberOfBytes =3D=3D 0) { + // + // No data need to be written to Trace Hub + // + return RETURN_SUCCESS; + } + + if (Buffer =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + DbgInstCount =3D CountThDebugInstance (); + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + NULL, + SeverityType, + TraceHubDebugType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteDebug ( + &MipiSystHandle, + SeverityType, + (UINT16)NumberOfBytes, + (CHAR8 *)Buffer + ); + if (RETURN_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog status code message to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Id Catalog ID. + @param[in] Guid Driver Guid. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTWriteCataLog64StatusCode ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN GUID *Guid + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + RETURN_STATUS Status; + UINT32 DbgInstCount; + UINT16 Index; + + if (Guid =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + DbgInstCount =3D CountThDebugInstance (); + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid); + MipiSystHandle.systh_tag.et_guid =3D 1; + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + NULL, + SeverityType, + TraceHubCatalogType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + SeverityType, + Id + ); + if (RETURN_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog message to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Id Catalog ID. + @param[in] NumberOfParams Number of entries in argument list. + @param[in] ... Catalog message parameters. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTWriteCataLog64 ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN UINTN NumberOfParams, + ... + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + VA_LIST Args; + UINTN Index; + RETURN_STATUS Status; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT3= 2)) { + return RETURN_INVALID_PARAMETER; + } + + DbgInstCount =3D CountThDebugInstance (); + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; + VA_START (Args, NumberOfParams); + for (Index =3D 0; Index < NumberOfParams; Index++) { + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); + } + + VA_END (Args); + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + NULL, + SeverityType, + TraceHubCatalogType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + SeverityType, + Id + ); + if (RETURN_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Collect the total number of Trace Hub debug instance in the system. + + @retval UINT32 The total number of Trace Hub debug instance in the = system. +**/ +UINT32 +EFIAPI +CountThDebugInstance ( + VOID + ) +{ + UINT32 DbgInstCount; + + // + // 1 from PCD. + // + DbgInstCount =3D 1; + + return DbgInstCount; +} 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 +# Debug library to output Trace Hub message. +# Support SEC/PEI/DXE/SMM phase TraceHub debug message based on fixed set= tings. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseTraceHubDebugSysTLib + FILE_GUID =3D 336DA571-AD65-423C-9A43-E0056E5B2D8D + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TraceHubDebugSysTLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[LibraryClasses] + BaseLib + PcdLib + BaseMemoryLib + MipiSysTLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + BaseTraceHubDebugSysTLib.c + InternalTraceHubApiCommon.c + InternalTraceHubApiCommon.h + InternalTraceHubApi.h + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress 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 +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB. +Trace Hub PCDs will be applied if no HOB exist. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "InternalTraceHubApiCommon.h" +#include "InternalTraceHubApi.h" + +GLOBAL_REMOVE_IF_UNREFERENCED TRACEHUB_DEBUG_INFO_HOB *mThDebugInstArray = =3D NULL; +GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mDbgInstCount = =3D 0; + +/** + Write debug string to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Buffer A pointer to the data buffer. + @param[in] NumberOfBytes The size of data buffer. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTDebugWrite ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + RETURN_STATUS Status; + UINT16 Index; + + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { + return RETURN_ABORTED; + } + + if (NumberOfBytes =3D=3D 0) { + // + // No data need to be written to Trace Hub + // + return RETURN_SUCCESS; + } + + if (Buffer =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; Index < mDbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + (UINT8 *)&mThDebugInstArray[Index], + SeverityType, + TraceHubDebugType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteDebug ( + &MipiSystHandle, + SeverityType, + (UINT16)NumberOfBytes, + (CHAR8 *)Buffer + ); + if (RETURN_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog status code message to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Id Catalog ID. + @param[in] Guid Driver Guid. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTWriteCataLog64StatusCode ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN GUID *Guid + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + UINTN Index; + RETURN_STATUS Status; + + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { + return RETURN_ABORTED; + } + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + if (Guid !=3D NULL) { + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid); + MipiSystHandle.systh_tag.et_guid =3D 1; + } else { + MipiSystHandle.systh_tag.et_modunit =3D 2; + MipiSystHandle.systh_tag.et_guid =3D 0; + } + + for (Index =3D 0; Index < mDbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + (UINT8 *)&mThDebugInstArray[Index], + SeverityType, + TraceHubCatalogType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + SeverityType, + Id + ); + if (RETURN_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Write catalog message to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Id Catalog ID. + @param[in] NumberOfParams Number of entries in argument list. + @param[in] ... Catalog message parameters. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTWriteCataLog64 ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN UINTN NumberOfParams, + ... + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + VA_LIST Args; + UINTN Index; + RETURN_STATUS Status; + + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT3= 2)) { + return RETURN_INVALID_PARAMETER; + } + + if ((mDbgInstCount =3D=3D 0) || (mThDebugInstArray =3D=3D NULL)) { + return RETURN_ABORTED; + } + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; + VA_START (Args, NumberOfParams); + for (Index =3D 0; Index < NumberOfParams; Index++) { + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); + } + + VA_END (Args); + + for (Index =3D 0; Index < mDbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + (UINT8 *)&mThDebugInstArray[Index], + SeverityType, + TraceHubCatalogType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + SeverityType, + Id + ); + if (RETURN_ERROR (Status)) { + break; + } + } + } + + return Status; +} + +/** + Constructor to get TraceHob configuration data + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval RETURN_SUCCESS The constructor always returns EFI_SUCC= ESS. + @retval RETURN_OUT_OF_RESOURCES There are not enough resources availabl= e to retrieve the matching FFS section. + +**/ +RETURN_STATUS +EFIAPI +DxeSmmTraceHubDebugSysTLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + if (mDbgInstCount =3D=3D 0) { + mDbgInstCount =3D CountThDebugInstance (); + } + + mThDebugInstArray =3D AllocateZeroPool (mDbgInstCount * sizeof (TRACEHUB= _DEBUG_INFO_HOB)); + + if (mThDebugInstArray !=3D NULL) { + PackThDebugInstance (mThDebugInstArray, mDbgInstCount); + } else { + return RETURN_OUT_OF_RESOURCES; + } + + return RETURN_SUCCESS; +} 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 +# Debug library to output Trace Hub message. +# Support DXE/SMM phase TraceHub debug message based on fixed or dynamic = settings. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeSmmTraceHubDebugSysTLib + FILE_GUID =3D A9B7B825-7902-4616-8556-085DA4DFEC72 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TraceHubDebugSysTLib|DXE_CORE DXE_DRI= VER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION + CONSTRUCTOR =3D DxeSmmTraceHubDebugSysTLibConstructor + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[LibraryClasses] + BaseLib + PcdLib + HobLib + BaseMemoryLib + MemoryAllocationLib + MipiSysTLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + DxeSmmTraceHubDebugSysTLib.c + InternalTraceHubApiCommon.c + InternalTraceHubApiCommon.h + InternalTraceHubApi.h + InternalTraceHubApi.c + +[Guids] + gTraceHubDebugInfoHobGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress 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 +Functions implementation in this file are not common for all type of Trace= HubDebugSysTLib. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "InternalTraceHubApi.h" + +/** + Count the total number of Trace Hub debug instance in the system. + + @retval UINT32 The total number of Trace Hub debug instance in the = system. +**/ +UINT32 +EFIAPI +CountThDebugInstance ( + VOID + ) +{ + UINT8 *DbgContext; + UINT32 DbgInstCount; + + DbgInstCount =3D 0; + + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext !=3D NULL) { + while (DbgContext !=3D NULL) { + DbgInstCount++; + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext)); + } + } else { + DbgInstCount++; + } + + return DbgInstCount; +} + +/** + Pack Trace Hub debug instances in the system. + + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB structur= e. + @param[in] Count Number of Trace Hub HOBs. +**/ +VOID +EFIAPI +PackThDebugInstance ( + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr, + IN UINT32 Count + ) +{ + UINT8 *DbgContext; + UINT16 Index; + + DbgContext =3D GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext !=3D NULL) { + for (Index =3D 0; Index < Count; Index++) { + CopyMem (&ThPtr[Index], GET_GUID_HOB_DATA (DbgContext), sizeof (TRAC= EHUB_DEBUG_INFO_HOB)); + DbgContext =3D GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_= HOB (DbgContext)); + } + } else { + for (Index =3D 0; Index < Count; Index++) { + ThPtr[Index].TraceHubMmioAddress =3D FixedPcdGet64 (PcdTraceHubDebug= MmioAddress); + ThPtr[Index].Flag =3D FixedPcdGetBool (PcdEnableTrace= HubDebugMsg); + ThPtr[Index].DebugLevel =3D FixedPcdGet8 (PcdTraceHubDebugL= evel); + } + } +} 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 +This header file declares functions that are not for common use. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef INTERNAL_TRACE_HUB_API_H_ +#define INTERNAL_TRACE_HUB_API_H_ + +/** + Count the total number of Trace Hub debug instance in the system. + + @retval UINT32 The total number of Trace Hub debug instance in the = system. +**/ +UINT32 +EFIAPI +CountThDebugInstance ( + VOID + ); + +/** + Pack Trace Hub debug instances in the system. + + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB structur= e. + @param[in] Count Number of Trace Hub HOBs. +**/ +VOID +EFIAPI +PackThDebugInstance ( + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr, + IN UINT32 Count + ); + +#endif // INTERNAL_TRACE_HUB_API_H_ 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 +Functions implementation defined in this file are common for all type of T= raceHubDebugSysTLib + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include "InternalTraceHubApiCommon.h" +#include "InternalTraceHubApi.h" + +/** + Conditionally determine whether to enable Trace Hub message. + + @param[in] Flag Flag to enable or disable Trace Hub message. + @param[in] DbgLevel Debug Level of Trace Hub. + @param[in] SeverityType Severity type of input message. + + @retval TRUE Enable trace hub message. + @retval FALSE Disable trace hub message. +**/ +BOOLEAN +EFIAPI +TraceHubDataEnabled ( + IN BOOLEAN Flag, + IN UINT8 DbgLevel, + IN TRACE_HUB_SEVERITY_TYPE SeverityType + ) +{ + if (Flag =3D=3D TraceHubRoutingDisable) { + return FALSE; + } + + if (DbgLevel =3D=3D TraceHubDebugLevelError) { + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError))) { + return TRUE; + } + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarning) { + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError) || (SeverityType =3D=3D SeverityWarning))) { + return TRUE; + } + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfo) { + if (((SeverityType =3D=3D SeverityFatal) || (SeverityType =3D=3D Sever= ityError) || (SeverityType =3D=3D SeverityWarning) || (SeverityType =3D=3D = SeverityNormal))) { + return TRUE; + } + } else if (DbgLevel =3D=3D TraceHubDebugLevelErrorWarningInfoVerbose) { + return TRUE; + } + + return FALSE; +} + +/** + Convert GUID from LE to BE or BE to LE. + + @param[in] Guid GUID that need to be converted. + @param[out] ConvertedGuid GUID that is converted. +**/ +VOID +EFIAPI +SwapBytesGuid ( + IN GUID *Guid, + OUT GUID *ConvertedGuid + ) +{ + CopyGuid (ConvertedGuid, Guid); + ConvertedGuid->Data1 =3D SwapBytes32 (ConvertedGuid->Data1); + ConvertedGuid->Data2 =3D SwapBytes16 (ConvertedGuid->Data2); + ConvertedGuid->Data3 =3D SwapBytes16 (ConvertedGuid->Data3); +} + +/** + Check whether to output Trace Hub message according to some conditions. + Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE + or Trace Hub MMIO address is 0. + + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e. + @param[in] DbgContext A pointer to Trace Hub debug instance. + @param[in] SeverityType Severity type of input message. + @param[in] PrintType Either catalog print or debug print. + + @retval RETURN_SUCCESS Current Trace Hub message need to be output. + @retval Other Current Trace Hub message will be disabled. +**/ +RETURN_STATUS +EFIAPI +CheckWhetherToOutputMsg ( + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, + IN UINT8 *DbgContext, + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN TRACEHUB_PRINTTYPE PrintType + ) +{ + UINT8 DbgLevel; + BOOLEAN Flag; + UINT64 Addr; + RETURN_STATUS Status; + + if (MipiSystHandle =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + if (PrintType =3D=3D TraceHubDebugType) { + Status =3D GetTraceHubMsgVisibility (DbgContext, &Flag, &DbgLevel); + if (RETURN_ERROR (Status)) { + return Status; + } + + if (!TraceHubDataEnabled (Flag, DbgLevel, SeverityType)) { + return RETURN_ABORTED; + } + } + + Status =3D GetTraceHubMmioAddress (DbgContext, &Addr); + if (RETURN_ERROR (Status)) { + return Status; + } + + MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D Addr; + if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr =3D=3D = 0) { + return RETURN_ABORTED; + } + + return RETURN_SUCCESS; +} + +/** + Get Trace Hub MMIO Address. + + @param[in] DbgContext A pointer to Trace Hub debug instance. + @param[in, out] TraceAddress Trace Hub MMIO Address. + + @retval RETURN_SUCCESS Operation is successfully. + @retval Other Operation is failed. +**/ +RETURN_STATUS +EFIAPI +GetTraceHubMmioAddress ( + IN UINT8 *DbgContext, + IN OUT UINT64 *TraceAddress + ) +{ + TRACEHUB_DEBUG_INFO_HOB *ThDbgContext; + + if (TraceAddress =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + if (DbgContext !=3D NULL) { + ThDbgContext =3D (TRACEHUB_DEBUG_INFO_HOB *)DbgContext; + *TraceAddress =3D ThDbgContext->TraceHubMmioAddress; + } else { + *TraceAddress =3D FixedPcdGet64 (PcdTraceHubDebugMmioAddress); + } + + return RETURN_SUCCESS; +} + +/** + Get visibility of Trace Hub Msg. + + @param[in] DbgContext A pointer to Trace Hub debug instance. + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age. + @param[in, out] DbgLevel Debug Level of Trace Hub. + + @retval RETURN_SUCCESS Operation is successfully. + @retval Other Operation is failed. +**/ +RETURN_STATUS +EFIAPI +GetTraceHubMsgVisibility ( + IN UINT8 *DbgContext, + IN OUT BOOLEAN *Flag, + IN OUT UINT8 *DbgLevel + ) +{ + TRACEHUB_DEBUG_INFO_HOB *ThDbgContext; + + if ((Flag =3D=3D NULL) || (DbgLevel =3D=3D NULL)) { + return RETURN_INVALID_PARAMETER; + } + + if (DbgContext !=3D NULL) { + ThDbgContext =3D (TRACEHUB_DEBUG_INFO_HOB *)DbgContext; + *Flag =3D ThDbgContext->Flag; + *DbgLevel =3D ThDbgContext->DebugLevel; + } else { + *DbgLevel =3D FixedPcdGet8 (PcdTraceHubDebugLevel); + *Flag =3D FixedPcdGetBool (PcdEnableTraceHubDebugMsg); + } + + return RETURN_SUCCESS; +} 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 +This header file declares functions and type for common use. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef INTERNAL_TRACE_HUB_API_COMMON_H_ +#define INTERNAL_TRACE_HUB_API_COMMON_H_ + +typedef enum { + TraceHubDebugType =3D 0, + TraceHubCatalogType +} TRACEHUB_PRINTTYPE; + +typedef enum { + TraceHubRoutingDisable =3D 0, + TraceHubRoutingEnable, + TraceHubRoutingMax +} TRACE_HUB_ROUTING; + +typedef enum { + TraceHubDebugLevelError =3D 0, + TraceHubDebugLevelErrorWarning, + TraceHubDebugLevelErrorWarningInfo, + TraceHubDebugLevelErrorWarningInfoVerbose, + TraceHubDebugLevelMax +} TRACE_HUB_DEBUG_LEVEL; + +/** + Conditionally determine whether to enable Trace Hub message. + + @param[in] Flag Flag to enable or disable Trace Hub message. + @param[in] DbgLevel Debug Level of Trace Hub. + @param[in] SeverityType Severity type of input message. + + @retval TRUE Enable trace hub message. + @retval FALSE Disable trace hub message. +**/ +BOOLEAN +EFIAPI +TraceHubDataEnabled ( + IN BOOLEAN Flag, + IN UINT8 DbgLevel, + IN TRACE_HUB_SEVERITY_TYPE SeverityType + ); + +/** + Convert GUID from LE to BE or BE to LE. + + @param[in] Guid GUID that need to be converted. + @param[out] ConvertedGuid GUID that is converted. +**/ +VOID +EFIAPI +SwapBytesGuid ( + IN GUID *Guid, + OUT GUID *ConvertedGuid + ); + +/** + Check whether to output Trace Hub message according to some conditions. + Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE + or Trace Hub MMIO address is 0. + + @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structur= e. + @param[in] DbgContext A pointer to Trace Hub debug instance. + @param[in] SeverityType Severity type of input message. + @param[in] PrintType Either catalog print or debug print. + + @retval RETURN_SUCCESS Current Trace Hub message need to be output. + @retval Other Current Trace Hub message will be disabled. +**/ +RETURN_STATUS +EFIAPI +CheckWhetherToOutputMsg ( + IN OUT MIPI_SYST_HANDLE *MipiSystHandle, + IN UINT8 *DbgContext, + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN TRACEHUB_PRINTTYPE PrintType + ); + +/** + Get Trace Hub MMIO Address. + + @param[in] DbgContext A pointer to Trace Hub debug instance. + @param[in, out] TraceAddress Trace Hub MMIO Address. + + @retval RETURN_SUCCESS Operation is successfully. + @retval Other Operation is failed. +**/ +RETURN_STATUS +EFIAPI +GetTraceHubMmioAddress ( + IN UINT8 *DbgContext, + IN OUT UINT64 *TraceAddress + ); + +/** + Get visibility of Trace Hub Msg. + + @param[in] DbgContext A pointer to Trace Hub debug instance. + @param[in, out] Flag Flag to enable or disable Trace Hub mess= age. + @param[in, out] DbgLevel Debug Level of Trace Hub. + + @retval RETURN_SUCCESS Operation is successfully. + @retval Other Operation is failed. +**/ +RETURN_STATUS +EFIAPI +GetTraceHubMsgVisibility ( + IN UINT8 *DbgContext, + IN OUT BOOLEAN *Flag, + IN OUT UINT8 *DbgLevel + ); + +#endif // INTERNAL_TRACE_HUB_API_COMMON_H_ 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 +System prints Trace Hub message in PEI based on fixed PCDs and HOB. +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid HOB. +Trace Hub PCDs will be applied if no HOB exist. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "InternalTraceHubApiCommon.h" +#include "InternalTraceHubApi.h" + +/** + Write debug string to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Buffer A pointer to the data buffer. + @param[in] NumberOfBytes The size of data buffer. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTDebugWrite ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + RETURN_STATUS Status; + UINT8 *DbgContext; + UINTN Index; + UINT32 DbgInstCount; + UINT8 *ThDebugInfo; + + if (NumberOfBytes =3D=3D 0) { + // + // No data need to be written to Trace Hub + // + return RETURN_SUCCESS; + } + + if (Buffer =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + DbgInstCount =3D CountThDebugInstance (); + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext !=3D NULL) { + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); + } else { + ThDebugInfo =3D NULL; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + ThDebugInfo, + SeverityType, + TraceHubDebugType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteDebug ( + &MipiSystHandle, + SeverityType, + (UINT16)NumberOfBytes, + (CHAR8 *)Buffer + ); + if (RETURN_ERROR (Status)) { + break; + } + } + + if (DbgContext !=3D NULL) { + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext)); + if (DbgContext =3D=3D NULL) { + break; + } + + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); + } + } + + return Status; +} + +/** + Write catalog status code message to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Id Catalog ID. + @param[in] Guid Driver Guid. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTWriteCataLog64StatusCode ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN GUID *Guid + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + UINT32 DbgInstCount; + UINT8 *DbgContext; + RETURN_STATUS Status; + UINTN Index; + UINT8 *ThDebugInfo; + + DbgInstCount =3D CountThDebugInstance (); + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + if (Guid !=3D NULL) { + SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid); + MipiSystHandle.systh_tag.et_guid =3D 1; + } else { + MipiSystHandle.systh_tag.et_modunit =3D 2; + MipiSystHandle.systh_tag.et_guid =3D 0; + } + + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext !=3D NULL) { + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); + } else { + ThDebugInfo =3D NULL; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + ThDebugInfo, + SeverityType, + TraceHubCatalogType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + SeverityType, + Id + ); + if (RETURN_ERROR (Status)) { + break; + } + } + + if (DbgContext !=3D NULL) { + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext)); + if (DbgContext =3D=3D NULL) { + break; + } + + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); + } + } + + return Status; +} + +/** + Write catalog message to specified Trace Hub MMIO address. + + @param[in] SeverityType Severity type of input message. + @param[in] Id Catalog ID. + @param[in] NumberOfParams Number of entries in argument list. + @param[in] ... Catalog message parameters. + + @retval RETURN_SUCCESS Data was written to Trace Hub. + @retval Other Failed to output Trace Hub message. +**/ +RETURN_STATUS +EFIAPI +TraceHubSysTWriteCataLog64 ( + IN TRACE_HUB_SEVERITY_TYPE SeverityType, + IN UINT64 Id, + IN UINTN NumberOfParams, + ... + ) +{ + MIPI_SYST_HANDLE MipiSystHandle; + MIPI_SYST_HEADER MipiSystHeader; + VA_LIST Args; + UINTN Index; + UINT32 DbgInstCount; + UINT8 *DbgContext; + RETURN_STATUS Status; + UINT8 *ThDebugInfo; + + DbgInstCount =3D 0; + + if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT3= 2)) { + return RETURN_INVALID_PARAMETER; + } + + DbgInstCount =3D CountThDebugInstance (); + + ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE)); + MipiSystHandle.systh_header =3D &MipiSystHeader; + + Status =3D InitMipiSystHandle (&MipiSystHandle); + if (RETURN_ERROR (Status)) { + return Status; + } + + MipiSystHandle.systh_param_count =3D (UINT32)NumberOfParams; + VA_START (Args, NumberOfParams); + for (Index =3D 0; Index < NumberOfParams; Index++) { + MipiSystHandle.systh_param[Index] =3D VA_ARG (Args, UINT32); + } + + VA_END (Args); + + DbgContext =3D (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext !=3D NULL) { + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); + } else { + ThDebugInfo =3D NULL; + } + + for (Index =3D 0; Index < DbgInstCount; Index++) { + Status =3D CheckWhetherToOutputMsg ( + &MipiSystHandle, + ThDebugInfo, + SeverityType, + TraceHubCatalogType + ); + if (!RETURN_ERROR (Status)) { + Status =3D MipiSystWriteCatalog ( + &MipiSystHandle, + SeverityType, + Id + ); + if (RETURN_ERROR (Status)) { + break; + } + } + + if (DbgContext !=3D NULL) { + DbgContext =3D (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, = GET_NEXT_HOB (DbgContext)); + if (DbgContext =3D=3D NULL) { + break; + } + + ThDebugInfo =3D GET_GUID_HOB_DATA (DbgContext); + } + } + + return Status; +} 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 +# Debug library to output Trace Hub message. +# Support PEI phase TraceHub debug message based on fixed or dynamic sett= ings. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiTraceHubDebugSysTLib + FILE_GUID =3D C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TraceHubDebugSysTLib|PEI_CORE PEIM + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[LibraryClasses] + BaseLib + PcdLib + HobLib + BaseMemoryLib + MemoryAllocationLib + MipiSysTLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + PeiTraceHubDebugSysTLib.c + InternalTraceHubApiCommon.c + InternalTraceHubApiCommon.h + InternalTraceHubApi.h + InternalTraceHubApi.c + +[Guids] + gTraceHubDebugInfoHobGuid + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress 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 ## +TrcaceHubDebugSysTLib library is a top level library for dumping Trace Hub= messages. +It provides Trace Hub related APIs to dump Trace Hub message via MIPI SYS-= T submodule. +User need to properly configure following Trace Hub related PCDs and HOB. + (See MdeModulePkg.dec to get detailed definition for PCDs below) + - PcdTraceHubDebugLevel + - PcdEnableTraceHubDebugMsg + - PcdTraceHubDebugMmioAddress + (See TraceHubDebugInfoHob.h to get detailed definition for HOB below) + - gTraceHubDebugInfoHobGuid + +## BaseTraceHubDebugSysTLib.inf ## +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs. +Only support single Trace Hub debug instance. + +## PeiTraceHubDebugSysTLib.inf ## +System prints Trace Hub message in PEI based on fixed PCDs and HOB. +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid HOB. +Trace Hub PCDs will be applied if no HOB exist. + +## DxeSmmTraceHubDebugSysTLib.inf ## +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB. +Trace Hub PCDs will be applied if no HOB exist. + +## Note ## +Trace Hub debug library not support DXE_RUNTIME_DRIVER type of module curr= ently. 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 gUniversalPayloadSerialPortInfoGuid =3D { 0xaa7e190d, 0xbe21, 0x4409, { = 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } } =20 + ## Include/Guid/TraceHubDebugInfoHob.h + gTraceHubDebugInfoHobGuid =3D { 0xf88c9c23, 0x646c, 0x4f6c, { 0x8e, 0x3d= , 0x36, 0xa9, 0x43, 0xc1, 0x08, 0x35 } } + ## GUID used for Boot Discovery Policy FormSet guid and related variable= s. gBootDiscoveryPolicyMgrFormsetGuid =3D { 0x5b6f7107, 0xbb3c, 0x4660, { 0= x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } } =20 @@ -1095,6 +1098,24 @@ # @Prompt Enable UEFI Stack Guard. gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055 =20 + ## Indicate debug level of Trace Hub. + # 0x0 - TraceHubDebugLevelError.
+ # 0x1 - TraceHubDebugLevelErrorWarning.
+ # 0x2 - TraceHubDebugLevelErrorWarningInfo.
+ # 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
+ # @Prompt Debug level of Trace Hub. + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel|0|UINT8|0x30001056 + + ## Flag to enable or disable Trace Hub message. + # FALSE - Disable Trace Hub debug message.
+ # TRUE - Enable Trace Hub debug message.
+ # @Prompt Enable or Disable Trace Hub message. + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg|0|BOOLEAN|0x300= 01057 + + ## Indicate MMIO address where Trace Hub message output to. + # @Prompt Output MMIO address of Trace Hub message. + gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress|0|UINT64|0x30= 001058 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## Dynamic type PCD can be registered callback function for Pcd setting = action. # PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of= callback function 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 MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferD= xe.inf MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf + MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf + MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf + MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf =20 [Components.X64] MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf 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" = " FALSE - UEFI Stack Guard will be disabled.
" =20 +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_PROMPT #= language en-US "Debug level of Trace Hub." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugLevel_HELP #= language en-US "Indicate debug level of Trace Hub" + = " 0x0 - TraceHubDebugLevelError.
" + = " 0x1 - TraceHubDebugLevelErrorWarning.
" + = " 0x2 - TraceHubDebugLevelErrorWarningInfo.
" + = " 0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.
" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_PROMP= T #language en-US "Flag to enable or disable Trace Hub message" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_HELP = #language en-US "Enable or Disable Trace Hub message" + = " FALSE - Disable Trace Hub debug message.
" + = " TRUE - Enable Trace Hub debug message.
" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_PRO= MPT #language en-US "Output MMIO address of Trace Hub message" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_HEL= P #language en-US "Indicate MMIO address where Trace Hub message output = to." + #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_PROMPT = #language en-US "NV Storage DefaultId" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_HELP = #language en-US "This dynamic PCD enables the default variable setting.\n" --=20 2.39.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104634): https://edk2.groups.io/g/devel/message/104634 Mute This Topic: https://groups.io/mt/98817583/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-