public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/4] MdePkg: Add MipiSysTLib library
@ 2023-01-31  2:48 victorx.hsu
  2023-01-31  2:49 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library victorx.hsu
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: victorx.hsu @ 2023-01-31  2:48 UTC (permalink / raw)
  To: devel
  Cc: VictorX Hsu, Michael D Kinney, Guo Gua, Chan Laura,
	Prakashan Krishnadas Veliyathuparambil, K N Karthik

From: VictorX Hsu <victorx.hsu@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144

Wrap mipi sys-T submodule as a MipiSysTLib. This Library provide
mipi sys-T API to be consumed.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 .gitmodules                                |   5 +-
 .pytool/CISettings.py                      |   2 +
 MdePkg/Include/Library/MipiSysTLib.h       | 242 +++++++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.c   | 110 +++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf |  52 ++
 MdePkg/Library/MipiSysTLib/Platform.c      | 160 ++++++
 MdePkg/Library/MipiSysTLib/Platform.h      | 140 ++++++
 MdePkg/Library/MipiSysTLib/mipi_syst.h     | 539 +++++++++++++++++++++
 MdePkg/Library/MipiSysTLib/mipisyst        |   1 +
 MdePkg/MdePkg.ci.yaml                      |   4 +-
 MdePkg/MdePkg.dec                          |   5 +
 MdePkg/MdePkg.dsc                          |   2 +
 ReadMe.rst                                 |   1 +
 13 files changed, 1261 insertions(+), 2 deletions(-)
 create mode 100644 MdePkg/Include/Library/MipiSysTLib.h
 create mode 100644 MdePkg/Library/MipiSysTLib/MipiSysTLib.c
 create mode 100644 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 create mode 100644 MdePkg/Library/MipiSysTLib/Platform.c
 create mode 100644 MdePkg/Library/MipiSysTLib/Platform.h
 create mode 100644 MdePkg/Library/MipiSysTLib/mipi_syst.h
 create mode 160000 MdePkg/Library/MipiSysTLib/mipisyst

diff --git a/.gitmodules b/.gitmodules
index 8011a88d9d..4a0500eea4 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,10 +16,13 @@
 [submodule "BaseTools/Source/C/BrotliCompress/brotli"]
 	path = BaseTools/Source/C/BrotliCompress/brotli
 	url = https://github.com/google/brotli
-	ignore = untracked
+	ignore = untracked
 [submodule "RedfishPkg/Library/JsonLib/jansson"]
 	path = RedfishPkg/Library/JsonLib/jansson
 	url = https://github.com/akheron/jansson
 [submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
 	path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
 	url = https://github.com/google/googletest.git
+[submodule "MdePkg/Library/MipiSysTLib/mipisyst"]
+	path = MdePkg/Library/MipiSysTLib/mipisyst
+	url = https://github.com/MIPI-Alliance/public-mipi-sys-t.git
diff --git a/.pytool/CISettings.py b/.pytool/CISettings.py
index d87c8e838e..0118820680 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -193,6 +193,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
             "BaseTools/Source/C/BrotliCompress/brotli", False))
         rs.append(RequiredSubmodule(
             "RedfishPkg/Library/JsonLib/jansson", False))
+        rs.append(RequiredSubmodule(
+            "MdePkg/Library/MipiSysTLib/mipisyst", False))
         return rs
 
     def GetName(self):
diff --git a/MdePkg/Include/Library/MipiSysTLib.h b/MdePkg/Include/Library/MipiSysTLib.h
new file mode 100644
index 0000000000..6282baac8e
--- /dev/null
+++ b/MdePkg/Include/Library/MipiSysTLib.h
@@ -0,0 +1,242 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MIPI_SYST_LIB_H_
+#define MIPI_SYST_LIB_H_
+
+#include <Uefi.h>
+
+#define MIPI_SYST_CONFORMANCE_LEVEL  30
+#define MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA
+#define MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID
+
+struct mipi_syst_header;
+struct mipi_syst_handle;
+struct mipi_syst_scatter_prog;
+
+/**
+ * SyS-T handle state initialization hook definition
+ *
+ * This function gets called in the context of IO handle generation.
+ * Its purpose is to initialize the platform dependent portion of
+*  the handle and other necessary platform specific initialization steps.
+ *
+ * @param systh Pointer to new SyS-T handle
+ * @see syst_handle_t
+ */
+typedef void (*mipi_syst_inithandle_hook_t)(
+  struct mipi_syst_handle  *systh
+  );
+
+/**
+ * SyS-T handle state release hook definition
+ *
+ * This function gets called when a handle is about to be destroyed..
+ * Its purpose is to free any resources allocated during the handle
+ * generation.
+ *
+ * @param systh Pointer to handle that is destroyed
+ * @see syst_handle_t
+ */
+typedef void (*mipi_syst_releasehandle_hook_t)(
+  struct mipi_syst_handle  *systh
+  );
+
+/**
+ * Low level message write routine definition
+ *
+ * This function is called at the end of an instrumentation API to output
+ * the raw message data.
+ *
+ * @param systh pointer to a SyS-T handle structure used in the API call,
+ * @param scatterprog pointer to a list of scatter write instructions that
+ *                    encodes how to convert the descriptor pointer by
+ *                    pdesc into raw binary data. This list doesn't include
+ *                    the mandatory first 32 tag byte value pointed by pdesc.
+ * @param pdesc pointer to a message descriptor, which containing at least
+ *              the 32-bit message tag data
+ */
+typedef void (*mipi_syst_msg_write_t)(
+  struct mipi_syst_handle        *systh,
+  struct mipi_syst_scatter_prog  *scatterprog,
+  const void                     *pdesc
+  );
+
+typedef struct {
+  UINTN    MmioAddr;
+} TRACE_HUB_PLATFORM_SYST_DATA;
+
+struct mipi_syst_platform_handle {
+  TRACE_HUB_PLATFORM_SYST_DATA    TraceHubPlatformData;
+};
+
+/** internal handle state flags
+ */
+typedef struct mipi_syst_handle_flags {
+  UINT32    shf_alloc : 1; /**< set to 1 if heap allocated handle */
+} MIPI_SYST_HANDLE_FLAGS;
+
+/**
+ * Message data header tag definition
+ *
+ * Each SyS-T message starts with a 32-bit message tag. The tag defines the
+ * message originator and decoding information for the data following
+ * the tag.
+ */
+
+typedef struct mipi_syst_msg_tag {
+ #if defined (MIPI_SYST_BIG_ENDIAN)
+  UINT32    et_res31     : 1;  /**< reserved for future use        */
+  UINT32    et_res30     : 1;  /**< reserved for future use        */
+  UINT32    et_subtype   : 6;  /**< type dependent sub category    */
+  UINT32    et_guid      : 1;  /**< 128-bit GUID present           */
+  UINT32    et_modunit   : 11; /**< unit for GUID or module:unit   */
+  UINT32    et_timestamp : 1;  /**< indicate 64-bit timestamp      */
+  UINT32    et_chksum    : 1;  /**< indicate 32-bit CRC            */
+  UINT32    et_length    : 1;  /**< indicate length field          */
+  UINT32    et_location  : 1;  /**< indicate location information  */
+  UINT32    et_res7      : 1;  /**< reserved for future use        */
+  UINT32    et_severity  : 3;  /**< severity level of message      */
+  UINT32    et_type      : 4;  /**< SyS-T message type ID          */
+ #else
+  UINT32    et_type      : 4;  /**< SyS-T message type ID          */
+  UINT32    et_severity  : 3;  /**< severity level of message      */
+  UINT32    et_res7      : 1;  /**< reserved for future use        */
+  UINT32    et_location  : 1;  /**< indicate location information  */
+  UINT32    et_length    : 1;  /**< indicate length field          */
+  UINT32    et_chksum    : 1;  /**< indicate 32-bit CRC            */
+  UINT32    et_timestamp : 1;  /**< indicate 64-bit timestamp      */
+  UINT32    et_modunit   : 11; /**< unit for GUID or module:unit   */
+  UINT32    et_guid      : 1;  /**< 128-bit GUID present           */
+  UINT32    et_subtype   : 6;  /**< type dependent sub category    */
+  UINT32    et_res30     : 1;  /**< reserved for future use        */
+  UINT32    et_res31     : 1;  /**< reserved for future use        */
+ #endif
+} MIPI_SYST_MSG_TAG;
+
+/** 128-bit GUID style message origin ID */
+typedef struct mipi_syst_guid {
+  union {
+    UINT8     b[16];
+    UINT64    ll[2];
+  } u;
+} MIPI_SYST_GUID;
+
+/**
+ * Message severity level enumeration
+ */
+typedef enum mipi_syst_severity {
+  MIPI_SYST_SEVERITY_MAX     = 0,  /**< no assigned severity       */
+  MIPI_SYST_SEVERITY_FATAL   = 1,  /**< critical error level       */
+  MIPI_SYST_SEVERITY_ERROR   = 2,  /**< error message level        */
+  MIPI_SYST_SEVERITY_WARNING = 3,  /**< warning message level      */
+  MIPI_SYST_SEVERITY_INFO    = 4,  /**< information message level  */
+  MIPI_SYST_SEVERITY_USER1   = 5,  /**< user defined level 5       */
+  MIPI_SYST_SEVERITY_USER2   = 6,  /**< user defined level 6       */
+  MIPI_SYST_SEVERITY_DEBUG   = 7   /**< debug information level    */
+} MIPI_SYST_SEVERITY;
+
+/** SyS-T connection handle state structure
+ *
+ * This structure connects the instrumentation API with the underlying SyS-T
+ * infrastructure. It plays a similar role to a FILE * in traditional
+ * C file IO.
+ */
+typedef struct mipi_syst_handle {
+  struct mipi_syst_header             *systh_header;      /**< global state            */
+  struct mipi_syst_handle_flags       systh_flags;        /**< handle state            */
+  struct mipi_syst_msg_tag            systh_tag;          /**< tag flags               */
+
+ #if defined (MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID)
+  struct mipi_syst_guid               systh_guid;         /**< module GUID             */
+ #endif
+
+ #if defined (MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
+  struct mipi_syst_msglocation        systh_location;     /**< location record     */
+ #endif
+
+  UINT32                              systh_param_count;  /**< number of parameters     */
+  UINT32                              systh_param[6];     /**< catalog msg parameters   */
+
+ #if defined (MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)
+  struct mipi_syst_platform_handle    systh_platform;     /**< platform specific state  */
+ #endif
+} MIPI_SYST_HANDLE;
+
+/** SyS-T global state structure.
+ * This structure is holding the global SyS-T library state
+ */
+typedef struct mipi_syst_header {
+  UINT32                             systh_version;  /**< SyS-T version ID         */
+
+ #if defined (MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)
+  mipi_syst_inithandle_hook_t        systh_inith;    /**< handle init hook function*/
+  mipi_syst_releasehandle_hook_t     systh_releaseh; /**< handle release hook      */
+ #endif
+
+ #if MIPI_SYST_CONFORMANCE_LEVEL > 10
+  mipi_syst_msg_write_t              systh_writer;   /**< message output routine   */
+ #endif
+ #if defined (MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)
+  struct mipi_syst_platform_state    systh_platform; /**< platform specific state  */
+ #endif
+} MIPI_SYST_HEADER;
+
+/**
+  Invoke initialization function in Mipi Sys-T module to initialize Mipi Sys-T handle.
+
+  @param[in, out]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+
+  @retval EFI_SUCCESS               MIPI_SYST_HANDLE instance was initialized.
+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+EFI_STATUS
+EFIAPI
+InitMipiSystHandle (
+  IN OUT MIPI_SYST_HANDLE  *MipiSystHandle
+  );
+
+/**
+  Invoke write_debug_string function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.
+  @param[in]  Len             Length of data buffer.
+  @param[in]  Str             A pointer to data buffer.
+
+  @retval EFI_SUCCESS               Data in buffer was processed.
+  @retval EFI_ABORTED               No data need to be written to Trace Hub.
+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+EFI_STATUS
+EFIAPI
+MipiSystWriteDebug (
+  IN        MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN        UINT32            Severity,
+  IN        UINT16            Len,
+  IN CONST  CHAR8             *Str
+  );
+
+/**
+  Invoke catalog_write_message function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.
+  @param[in]  CatId           Catalog Id.
+
+  @retval EFI_SUCCESS      Data in buffer was processed.
+**/
+EFI_STATUS
+EFIAPI
+MipiSystWriteCatalog (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Severity,
+  IN  UINT64            CatId
+  );
+
+#endif // MIPI_SYST_LIB_H_
diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.c b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
new file mode 100644
index 0000000000..0195ad85b0
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
@@ -0,0 +1,110 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include "mipi_syst.h"
+
+/**
+  Invoke initialization function in Mipi Sys-T module to initialize Mipi Sys-T handle.
+
+  @param[in, out]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+
+  @retval EFI_SUCCESS               MIPI_SYST_HANDLE instance was initialized.
+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+EFI_STATUS
+EFIAPI
+InitMipiSystHandle (
+  IN OUT MIPI_SYST_HANDLE  *MipiSystHandle
+  )
+{
+  if (MipiSystHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  mipi_syst_init (MipiSystHandle->systh_header, 0, NULL);
+  mipi_syst_init_handle (MipiSystHandle->systh_header, MipiSystHandle, NULL, 0);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Invoke write_debug_string function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.
+  @param[in]  Len             Length of data buffer.
+  @param[in]  Str             A pointer to data buffer.
+
+  @retval EFI_SUCCESS               Data in buffer was processed.
+  @retval EFI_ABORTED               No data need to be written to Trace Hub.
+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+EFI_STATUS
+EFIAPI
+MipiSystWriteDebug (
+  IN        MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN        UINT32            Severity,
+  IN        UINT16            Len,
+  IN CONST  CHAR8             *Str
+  )
+{
+  if (MipiSystHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if ((Len == 0) || (Str == NULL)) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return EFI_ABORTED;
+  }
+
+  mipi_syst_write_debug_string (
+    MipiSystHandle,
+    MIPI_SYST_NOLOCATION,
+    MIPI_SYST_STRING_GENERIC,
+    Severity,
+    Len,
+    Str
+    );
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Invoke catalog_write_message function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.
+  @param[in]  CatId           Catalog Id.
+
+  @retval EFI_SUCCESS               Data in buffer was processed.
+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+EFI_STATUS
+EFIAPI
+MipiSystWriteCatalog (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Severity,
+  IN  UINT64            CatId
+  )
+{
+  if (MipiSystHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  mipi_syst_write_catalog64_message (
+    MipiSystHandle,
+    MIPI_SYST_NOLOCATION,
+    Severity,
+    CatId
+    );
+
+  return EFI_SUCCESS;
+}
diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
new file mode 100644
index 0000000000..17ede382cc
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
@@ -0,0 +1,52 @@
+## @file
+#  This library provides Mipi Sys-T API.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = MipiSysTLib
+  FILE_GUID                      = A58B0510-9E6D-4747-95D8-E5B8AF4633E6
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = MipiSysTLib
+
+  DEFINE MIPI_HEADER_PATH        = mipisyst/library/include/mipi_syst
+  DEFINE MIPI_SOURCE_PATH        = mipisyst/library/src
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[LibraryClasses]
+  IoLib
+  BaseMemoryLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[Sources]
+  MipiSysTLib.c
+  mipi_syst.h
+  Platform.c
+  Platform.h
+  $(MIPI_HEADER_PATH)/api.h
+  $(MIPI_HEADER_PATH)/crc32.h
+  $(MIPI_HEADER_PATH)/compiler.h
+  $(MIPI_HEADER_PATH)/message.h
+  $(MIPI_HEADER_PATH)/inline.h
+  $(MIPI_SOURCE_PATH)/mipi_syst_init.c
+  $(MIPI_SOURCE_PATH)/mipi_syst_api.c
+  $(MIPI_SOURCE_PATH)/mipi_syst_crc32.c
+  $(MIPI_SOURCE_PATH)/mipi_syst_writer.c
+  $(MIPI_SOURCE_PATH)/mipi_syst_inline.c
+  $(MIPI_SOURCE_PATH)/mipi_syst_compiler.c
+
+[BuildOptions]
+  MSFT:*_*_*_CC_FLAGS = /Od
diff --git a/MdePkg/Library/MipiSysTLib/Platform.c b/MdePkg/Library/MipiSysTLib/Platform.c
new file mode 100644
index 0000000000..4079ccb1b8
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.c
@@ -0,0 +1,160 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/IoLib.h>
+#include <Library/BaseMemoryLib.h>
+#include "mipi_syst.h"
+
+/**
+  Write 4 bytes to Trace Hub MMIO addr + 0x10.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD32Ts (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Data
+  )
+{
+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x10, Data);
+}
+
+/**
+  Write 4 bytes to Trace Hub MMIO addr + 0x18.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD32Mts (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Data
+  )
+{
+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x18, Data);
+}
+
+/**
+  Write 8 bytes to Trace Hub MMIO addr + 0x18.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD64Mts (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT64            Data
+  )
+{
+  MmioWrite64 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x18, Data);
+}
+
+/**
+  Write 1 byte to Trace Hub MMIO addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD8 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT8             Data
+  )
+{
+  MmioWrite8 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);
+}
+
+/**
+  Write 2 bytes to Trace Hub MMIO mmio addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD16 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT16            Data
+  )
+{
+  MmioWrite16 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);
+}
+
+/**
+  Write 4 bytes to Trace Hub MMIO addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD32 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Data
+  )
+{
+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);
+}
+
+/**
+  Write 8 bytes to Trace Hub MMIO addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD64 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT64            Data
+  )
+{
+  MmioWrite64 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);
+}
+
+/**
+  Clear data in Trace Hub MMIO addr + 0x30.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+**/
+VOID
+EFIAPI
+MipiSystWriteFlag (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle
+  )
+{
+  UINT32  Flag;
+
+  Flag = 0;
+
+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x30, Flag);
+}
+
+/**
+  Get Epoch time.
+
+  @retval UINT64    A numeric number for timestamp.
+**/
+UINT64
+EFIAPI
+MipiSystGetEpochUs (
+  VOID
+  )
+{
+  UINT64  Epoch;
+
+  Epoch = 1000;
+
+  return Epoch;
+}
diff --git a/MdePkg/Library/MipiSysTLib/Platform.h b/MdePkg/Library/MipiSysTLib/Platform.h
new file mode 100644
index 0000000000..b36ab6b84b
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.h
@@ -0,0 +1,140 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MIPI_SYST_PLATFORM_H_
+#define MIPI_SYST_PLATFORM_H_
+
+/**
+  Write 4 bytes to Trace Hub MMIO addr + 0x10.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD32Ts (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Data
+  );
+
+/**
+  Write 4 bytes to Trace Hub MMIO addr + 0x18.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD32Mts (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Data
+  );
+
+/**
+  Write 8 bytes to Trace Hub MMIO addr + 0x18.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD64Mts (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT64            Data
+  );
+
+/**
+  Write 1 byte to Trace Hub MMIO addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD8 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT8             Data
+  );
+
+/**
+  Write 2 bytes to Trace Hub MMIO mmio addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD16 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT16            Data
+  );
+
+/**
+  Write 4 bytes to Trace Hub MMIO addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD32 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Data
+  );
+
+/**
+  Write 8 bytes to Trace Hub MMIO addr + 0x0.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Data            Data to be written.
+**/
+VOID
+EFIAPI
+MipiSystWriteD64 (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT64            Data
+  );
+
+/**
+  Clear data in Trace Hub MMIO addr + 0x30.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+**/
+VOID
+EFIAPI
+MipiSystWriteFlag (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle
+  );
+
+/**
+  Get Epoch time.
+
+  @retval UINT64    A numeric number for timestamp.
+**/
+UINT64
+EFIAPI
+MipiSystGetEpochUs (
+  VOID
+  );
+
+#define MIPI_SYST_PLATFORM_CLOCK()  MipiSystGetEpochUs ()
+
+#ifndef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#define MIPI_SYST_OUTPUT_D32TS(MipiSystHandle, Data)   MipiSystWriteD32Ts ((MipiSystHandle), (Data))
+#define MIPI_SYST_OUTPUT_D32MTS(MipiSystHandle, Data)  MipiSystWriteD32Mts ((MipiSystHandle), (Data))
+#define MIPI_SYST_OUTPUT_D64MTS(MipiSystHandle, Data)  MipiSystWriteD64Mts ((MipiSystHandle), (Data))
+#define MIPI_SYST_OUTPUT_D8(MipiSystHandle, Data)      MipiSystWriteD8 ((MipiSystHandle), (Data))
+#define MIPI_SYST_OUTPUT_D16(MipiSystHandle, Data)     MipiSystWriteD16 ((MipiSystHandle), (Data))
+#define MIPI_SYST_OUTPUT_D32(MipiSystHandle, Data)     MipiSystWriteD32 ((MipiSystHandle), (Data))
+  #if defined (MIPI_SYST_PCFG_ENABLE_64BIT_IO)
+#define MIPI_SYST_OUTPUT_D64(MipiSystHandle, Data)  MipiSystWriteD64 ((MipiSystHandle), (Data))
+  #endif
+#define MIPI_SYST_OUTPUT_FLAG(MipiSystHandle)  MipiSystWriteFlag ((MipiSystHandle))
+#endif
+
+#endif // MIPI_SYST_PLATFORM_H_
diff --git a/MdePkg/Library/MipiSysTLib/mipi_syst.h b/MdePkg/Library/MipiSysTLib/mipi_syst.h
new file mode 100644
index 0000000000..29a1aa431b
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipi_syst.h
@@ -0,0 +1,539 @@
+/** @file
+
+This header file is a customized version of mipi_syst.h.in in mipi module.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MIPI_SYST_H_INCLUDED
+#define MIPI_SYST_H_INCLUDED
+
+#include <Library/MipiSysTLib.h>
+
+/* SyS-T API version information
+ */
+#define MIPI_SYST_VERSION_MAJOR  1   /**< Major version, incremented if API changes */
+#define MIPI_SYST_VERSION_MINOR  0   /**< Minor version, incremented on compatible extensions */
+#define MIPI_SYST_VERSION_PATCH  0   /**< Patch for existing major, minor, usually 0 */
+
+/** Define SyS-T API conformance level
+ *
+ * 10 = minimal (only short events)
+ * 20 = low overhead  (exluding varag functions and CRC32)
+ * 30 = full implementation
+ */
+#define MIPI_SYST_CONFORMANCE_LEVEL  30
+
+/** Compute SYS-T version value
+ *
+ * Used to compare SYS-T Major.Minor.patch versions numerically at runtime.
+ *
+ * @param ma major version number
+ * @param mi minor version number
+ * @param p patch version number
+ *
+ * Example:
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
+ *
+ * #if  MIPI_SYST_VERSION_CODE >= MIPI_SYST_MAKE_VERSION_CODE(1,5,0)
+ *     // do what only >= 1.5.x supports
+ * #endif
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#define MIPI_SYST_MAKE_VERSION_CODE(ma, mi, p)  (((ma) << 16) | ((mi)<<8) | (p))
+
+/** Numeric SYS-T version code */
+#define MIPI_SYST_VERSION_CODE  MIPI_SYST_MAKE_VERSION_CODE(\
+  MIPI_SYST_VERSION_MAJOR,\
+  MIPI_SYST_VERSION_MINOR,\
+  MIPI_SYST_VERSION_PATCH)
+
+/* Macros to trick numeric values like __LINE__ into a string
+ */
+#define _MIPI_SYST_STRINGIFY(x)  #x
+#define _MIPI_SYST_CPP_TOSTR(x)  _MIPI_SYST_STRINGIFY(x)
+
+#define _MIPI_SYST_VERSION_STRING(a, b, c) \
+        _MIPI_SYST_CPP_TOSTR(a)"."_MIPI_SYST_CPP_TOSTR(b)"."_MIPI_SYST_CPP_TOSTR(c)
+
+/** Textual version string */
+#define MIPI_SYST_VERSION_STRING \
+        _MIPI_SYST_VERSION_STRING(\
+                MIPI_SYST_VERSION_MAJOR,\
+                MIPI_SYST_VERSION_MINOR,\
+                MIPI_SYST_VERSION_PATCH)
+
+#ifndef MIPI_SYST_COMPILER_INCLUDED
+#define MIPI_SYST_STATIC
+  #include "mipi_syst/compiler.h"
+#endif
+
+/* String hash macros for compile time computation of catalog ID's.
+ * Notes:
+ *    These macros will only be used with optimized builds, otherwise
+ *    a lot of runtime code will be generated.
+ *
+ *    Only the last 64 bytes of the string are considered for hashing
+ */
+#define _MIPI_SYST_HASH1(s, i, x, l)   (x*65599u+(mipi_syst_u8)s[(i)<(l)?((l)-1-(i)):(l)])
+#define _MIPI_SYST_HASH4(s, i, x, l)   _MIPI_SYST_HASH1(s,i,_MIPI_SYST_HASH1(s,i+1,_MIPI_SYST_HASH1(s,i+2,_MIPI_SYST_HASH1(s,i+3,x,l),l),l),l)
+#define _MIPI_SYST_HASH16(s, i, x, l)  _MIPI_SYST_HASH4(s,i,_MIPI_SYST_HASH4(s,i+4,_MIPI_SYST_HASH4(s,i+8,_MIPI_SYST_HASH4(s,i+12,x,l),l),l),l)
+#define _MIPI_SYST_HASH64(s, i, x, l)  _MIPI_SYST_HASH16(s,i,_MIPI_SYST_HASH16(s,i+16,_MIPI_SYST_HASH16(s,i+32,_MIPI_SYST_HASH16(s,i+48,x,l),l),l),l)
+
+#define _MIPI_SYST_HASH_x65599(s, l)  ((mipi_syst_u32)_MIPI_SYST_HASH64(s,0,0,l))
+
+#define _MIPI_SYST_HASH_AT_CPP_TIME(str, offset)  (_MIPI_SYST_HASH_x65599(str, sizeof(str)-1) + (offset))
+#define _MIPI_SYST_HASH_AT_RUN_TIME(str, offset)  (mipi_syst_hash_x65599(str, sizeof(str)-1) + (offset))
+
+#if defined (_MIPI_SYST_OPTIMIZER_ON)
+#define MIPI_SYST_HASH(a, b)  _MIPI_SYST_HASH_AT_CPP_TIME((a), (b))
+#else
+#define MIPI_SYST_HASH(a, b)  _MIPI_SYST_HASH_AT_RUN_TIME((a), (b))
+#endif
+
+/** Major Message Types
+ */
+enum mipi_syst_msgtype {
+  MIPI_SYST_TYPE_BUILD   = 0,        /**< client build id message   */
+  MIPI_SYST_TYPE_SHORT32 = 1,        /**< value only message        */
+  MIPI_SYST_TYPE_STRING  = 2,        /**< text message output       */
+  MIPI_SYST_TYPE_CATALOG = 3,        /**< catalog message output    */
+  MIPI_SYST_TYPE_RAW     = 6,        /**< raw binary data           */
+  MIPI_SYST_TYPE_SHORT64 = 7,        /**<  value only message       */
+  MIPI_SYST_TYPE_CLOCK   = 8,        /**< clock sync message        */
+
+  MIPI_SYST_TYPE_MAX
+};
+
+/** MIPI_SYST_TYPE_DEBUG_STRING Sub-Types
+ */
+enum mipi_syst_subtype_string {
+  MIPI_SYST_STRING_GENERIC       = 1,  /**< string generic debug         */
+  MIPI_SYST_STRING_FUNCTIONENTER = 2,  /**< string is function name      */
+  MIPI_SYST_STRING_FUNCTIONEXIT  = 3,  /**< string is function name      */
+  MIPI_SYST_STRING_INVALIDPARAM  = 5,  /**< invalid SyS-T APIcall        */
+  MIPI_SYST_STRING_ASSERT        = 7,  /**< Software Assert: failure     */
+  MIPI_SYST_STRING_PRINTF_32     = 11, /**< printf with 32-bit packing   */
+  MIPI_SYST_STRING_PRINTF_64     = 12, /**< printf with 64-bit packing   */
+
+  MIPI_SYST_STRING_MAX
+};
+
+/** MIPI_SYST_TYPE_CATALOG Sub-Types
+ */
+enum mipi_syst_subtype_catalog {
+  MIPI_SYST_CATALOG_ID32_P32 = 1,   /**< 32-bit catalog ID, 32-bit packing */
+  MIPI_SYST_CATALOG_ID64_P32 = 2,   /**< 64-bit catalog ID, 32-bit packing */
+  MIPI_SYST_CATALOG_ID32_P64 = 5,   /**< 32-bit catalog ID, 64-bit packing */
+  MIPI_SYST_CATALOG_ID64_P64 = 6,   /**< 64-bit catalog ID, 64-bit packing */
+
+  MIPI_SYST_CATALOG_MAX
+};
+
+/** MIPI_SYST_TYPE_CLOCK Sub-Types
+ */
+enum mipi_syst_subtype_clock {
+  MIPI_SYST_CLOCK_TRANSPORT_SYNC = 1,  /**< SyS-T clock & frequency sync  */
+  MIPI_SYST_CLOCK_MAX
+};
+
+enum mipi_syst_subtype_build {
+  MIPI_SYST_BUILD_ID_COMPACT32 = 0, /**< compact32  build id       */
+  MIPI_SYST_BUILD_ID_COMPACT64 = 1, /**< compact64  build id       */
+  MIPI_SYST_BUILD_ID_LONG      = 2, /**< normal build  message     */
+  MIPI_SYST_BUILD_MAX
+};
+
+/** GUID initializer code
+ *
+ * This macro simplifies converting a GUID from its string representation
+ * into the mipi_syst_guid data structure. The following example shows
+ * how the values from a GUID string are used with the macro. Each numeric
+ * component from the GUID string gets converted into a hex value parameter
+ * when invoking the macro.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
+ *
+ *  // Guid: f614b99d-99a1-4c04-8c30-90999ab5fe05
+ *
+ *   struct mipi_syst_guid guid =
+ *      MIPI_SYST_GEN_GUID(0xf614b99d, 0x99a1, 0x4c04, 0x8c30, 0x90999ab5fe05);
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#define MIPI_SYST_GEN_GUID(l1, w1, w2, w3, l2) \
+  {{\
+          (mipi_syst_u8)((mipi_syst_u32)(l1) >> 24), \
+          (mipi_syst_u8)((mipi_syst_u32)(l1) >> 16), \
+          (mipi_syst_u8)((mipi_syst_u32)(l1) >>  8), \
+          (mipi_syst_u8)((mipi_syst_u32)(l1) >>  0), \
+          (mipi_syst_u8)((mipi_syst_u16)(w1) >>  8), \
+          (mipi_syst_u8)((mipi_syst_u16)(w1) >>  0), \
+          (mipi_syst_u8)((mipi_syst_u16)(w2) >>  8), \
+          (mipi_syst_u8)((mipi_syst_u16)(w2) >>  0), \
+          (mipi_syst_u8)((mipi_syst_u16)(w3) >>  8), \
+          (mipi_syst_u8)((mipi_syst_u16)(w3) >>  0), \
+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 40), \
+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 32), \
+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 24), \
+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 16), \
+          (mipi_syst_u8)((mipi_syst_u64)(l2) >>  8), \
+          (mipi_syst_u8)((mipi_syst_u64)(l2) >>  0)  \
+  }}
+
+/** SyS-T client origin data
+ *
+ * This structure holds the GUID or header origin and unit data
+ * used by SyS-T handles. The structure gets passed into the handle
+ * creation functions to initialize the values that identify clients.
+ * @see MIPI_SYST_SET_HANDLE_GUID_UNIT
+ * @see MIPI_SYST_SET_HANDLE_MODULE_UNIT
+ * @see MIPI_SYST_SET_HANDLE_ORIGIN
+ */
+struct mipi_syst_origin {
+  struct mipi_syst_guid    guid;    /**< origin GUID or module value */
+  mipi_syst_u16            unit;    /**< unit value                  */
+};
+
+/** Origin structure initializer code using GUID
+*
+* This macro simplifies initializing a mipi_syst_origin structure. The
+* first 5 parameters are GUID values as used by the MIPI_SYST_GEN_GUID
+* macro. The last parameter is the unit value (11-Bits).
+* @see MIPI_SYST_GEN_GUID
+*
+*
+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
+*
+*  // Guid: {494E5443-B659-45AF-B786-9DB0786248AE}
+
+*
+*   struct mipi_syst_origin = origin
+*      MIPI_SYST_GEN_ORIGIN_GUID(
+*        0x494E5443, 0xB659, 0x45AF, 0xB786, 0x9DB0786248AE,
+*        0x1);
+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+*/
+#define MIPI_SYST_GEN_ORIGIN_GUID(l1, w1, w2, w3, l2, u) \
+        {\
+                MIPI_SYST_GEN_GUID(l1, w1, w2, w3, l2) ,\
+                u\
+        }
+
+/** Origin structure initializer code using header module value
+*
+* This macro simplifies initializing a mipi_syst_origin structure. The
+* first parameter is the header origin value (7-Bits). The second parameter
+* is the unit value (4-bits)
+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}
+*
+*  // Guid: {494E5443-B659-45AF-B786-9DB0786248AE}
+
+*   #define MODULE_X 0x10
+*   struct mipi_syst_origin =
+*      MIPI_SYST_GEN_ORIGIN_MODULE(MODULE_X, 0x1);
+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+*/
+#define MIPI_SYST_GEN_ORIGIN_MODULE(m, u) \
+        {\
+                MIPI_SYST_GEN_GUID(0,0,0, ((mipi_syst_u16)(m & 0x7F)) << 8, 0 ),\
+                u\
+        }
+
+/**
+ * Global state initialization hook definition
+ *
+ * This function gets called in the context of the mipi_syst_init() API
+ * function after the generic state members of the global state
+ * structure syst_hdr have been setup. It's purpose is to initialize the
+ * platform dependent portion of the state and other necessary
+ * platform specific initialization steps.
+ *
+ * @param systh Pointer to global state structure
+ * @param p user defined value or pointer to data
+ * @see  mipi_syst_header
+ */
+typedef void (MIPI_SYST_CALLCONV *mipi_syst_inithook_t)(
+  struct mipi_syst_header  *systh,
+  const void               *p
+  );
+
+/**
+ * Global state destroy hook definition
+ *
+ * This function gets called in the context of the mipi_syst_destroy() API
+ * function before the generic state members of the global state
+ * structure syst_hdr have been destroyed. Its purpose is to free resources
+ * used by the platform dependent portion of the global state.
+ *
+ * @param systh Pointer to global state structure
+ */
+typedef void (MIPI_SYST_CALLCONV *mipi_syst_destroyhook_t)(
+  struct mipi_syst_header  *systh
+  );
+
+#ifndef MIPI_SYST_PLATFORM_INCLUDED
+
+/**
+ * @defgroup PCFG_Config  Platform Feature Configuration Defines
+ *
+ * Defines to customize the SyS-T feature set to match the platform needs.
+ *
+ * Each optional library feature can be disabled by not defining the related
+ * MIPI_SYST_PCFG_ENABLE define. Removing unused features in this way reduces
+ * both memory footprint and runtime overhead of SyS-T.
+ */
+
+/**
+ * @defgroup PCFG_Global Platform Wide Configuration
+ * @ingroup  PCFG_Config
+ *
+ * These defines enable global features in the SyS-T library.
+ * @{
+ */
+
+/**
+ * Extend SyS-T handle data state
+ *
+ * This define extends the SyS-T handle state data structure
+ * mipi_syst_handle with platform private content. A platform typically
+ * stores data for fast trace hardware access in the handle data, for
+ * example a volatile pointer to an MMIO space.
+ *
+ * The platform example uses #mipi_syst_platform_handle as handle state
+ * extension.
+ */
+#define MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA
+
+/* MSVC and GNU compiler 64-bit mode */
+
+/**
+ * Enable 64-bit instruction addresses
+ *
+ * Set this define if running in 64-bit code address space.
+ */
+  #if defined (_WIN64) || defined (__x86_64__) || defined (__LP64__)
+#define MIPI_SYST_PCFG_ENABLE_64BIT_ADDR
+  #endif
+
+/**
+ * Enable atomic 64-bit write operations
+ *
+ * Set this define if your platform supports an atomic 64-bit data write
+ * operation. This results in fewer MMIO accesses.The SyS-T library
+ * defaults to 2 consecutive 32-Bit writes otherwise.
+ */
+  #if defined (_WIN64) || defined (__x86_64__) || defined (__LP64__)
+#define MIPI_SYST_PCFG_ENABLE_64BIT_IO
+  #endif
+
+/**
+ * Enable helper function code inlining
+ *
+ * Set this define if speed is more important than code size on your platform.
+ * It causes several helper function to get inlined, producing faster, but
+ * also larger, code.
+ */
+#define MIPI_SYST_PCFG_ENABLE_INLINE
+
+/** @} */
+
+/**
+ * @defgroup PCFG_ApiSet Supported API sets
+ * @ingroup  PCFG_Config
+ *
+ * These defines enable API sets in the SyS-T library. They are set by default
+ * depending on the SyS-T API conformance level. The level is specified using
+ * the define #MIPI_SYST_CONFORMANCE_LEVEL.
+ * @{
+ */
+
+  #if MIPI_SYST_CONFORMANCE_LEVEL > 10
+
+/**
+ * Use SyS-T scatter write output function
+ *
+ * The library comes with an output routine that is intended to write data out
+ * to an MMIO space. It simplifies a SyS-T platform integration as
+ * only low-level access macros must be provided for outputting data. These
+ * macros follow MIPI System Trace Protocol (STP) naming convention, also
+ * non STP generators can use this interface.
+ *
+ * These low level output macros are:
+ *
+ * #MIPI_SYST_OUTPUT_D32MTS, #MIPI_SYST_OUTPUT_D64MTS,
+ * #MIPI_SYST_OUTPUT_D32TS, #MIPI_SYST_OUTPUT_D64,
+ * #MIPI_SYST_OUTPUT_D32, #MIPI_SYST_OUTPUT_D16, #MIPI_SYST_OUTPUT_D8 and
+ * #MIPI_SYST_OUTPUT_FLAG
+ *
+ * Note: This version of the write function always starts messages
+ * using a 32-bit timestamped record also other sized timestamped
+ * packets are allowed by the SyS-T specification.
+ */
+#define MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE
+
+/**
+ * Enable the Catalog API for 32-Bit Catalog IDs.
+ */
+#define MIPI_SYST_PCFG_ENABLE_CATID32_API
+
+/**
+ * Enable the Catalog API for 64-Bit Catalog IDs.
+ */
+#define MIPI_SYST_PCFG_ENABLE_CATID64_API
+
+/**
+ * Enable plain UTF-8 string output APIs.
+ */
+#define MIPI_SYST_PCFG_ENABLE_STRING_API
+
+/**
+ * Enable raw data output APIs
+ */
+#define MIPI_SYST_PCFG_ENABLE_WRITE_API
+
+/**
+ * Enable Build API
+ */
+#define MIPI_SYST_PCFG_ENABLE_BUILD_API
+  #endif /* MIPI_SYST_CONFORMANCE_LEVEL > 10 */
+
+  #if  MIPI_SYST_CONFORMANCE_LEVEL > 20
+
+/**
+ * Maximum size of printf payload in bytes.
+ * Adjust this value if larger strings shall be supported by the library.
+ * The buffer space is located in stack memory when calling one of the printf
+ * style APIs.
+ */
+#define MIPI_SYST_PCFG_PRINTF_ARGBUF_SIZE  1024
+
+  #endif /* #if MIPI_SYST_CONFORMANCE_LEVEL > 20 */
+
+/* @} */
+
+/**
+ * @defgroup PCFG_Message Optional Message Attributes
+ * @ingroup  PCFG_Config
+ *
+ * These defines enable optional message components. They are set by default
+ * depending on the SyS-T API conformance level. The level is specified using
+ * the define #MIPI_SYST_CONFORMANCE_LEVEL.
+ * @{
+ */
+
+  #if MIPI_SYST_CONFORMANCE_LEVEL > 10
+
+/**
+ * Enable 128-bit origin GUID support.
+ */
+#define MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID
+
+/**
+ * Enable protocol timestamp.
+ *
+ * This option adds a timestamp into the SyS-T protocol. This
+ * option is used if the SyS-T protocol is not embedded into a hardware
+ * timestamped trace protocol like MIPI STP or if the HW timestamp cannot
+ * be used for other reasons. Setting this option creates the need to define
+ * the macros #MIPI_SYST_PLATFORM_CLOCK and #MIPI_SYST_PLATFORM_FREQ to
+ *  return a 64-bit clock tick value and its frequency.
+ */
+#define MIPI_SYST_PCFG_ENABLE_TIMESTAMP
+
+    #if defined (_DOXYGEN_)  /*  only for doxygen, remove the #if to enable */
+
+/**
+* Enable generation of length field
+*
+* Set this define if the message data shall include the optional length
+* field that indicates how many payload bytes follow.
+*/
+#define MIPI_SYST_PCFG_LENGTH_FIELD
+    #endif
+
+  #endif
+
+  #if MIPI_SYST_CONFORMANCE_LEVEL > 20
+
+/**
+ * Enable message data CRC32 generation.
+ */
+#define MIPI_SYST_PCFG_ENABLE_CHECKSUM
+
+  #endif /* #if MIPI_SYST_CONFORMANCE_LEVEL */
+
+/** @} */
+
+  #include "Platform.h"
+#endif
+
+#if defined (MIPI_SYST_PCFG_ENABLE_INLINE)
+#define MIPI_SYST_INLINE  static MIPI_SYST_CC_INLINE
+#else
+#define MIPI_SYST_INLINE  MIPI_SYST_EXPORT
+#endif
+
+#define _MIPI_SYST_MK_MODUNIT_ORIGIN(m, u)  (((u) & 0xF)|(m<<4))
+
+/**
+ * Location information inside a message (64-bit format)
+ * Location is either the source position of the instrumentation call, or
+ * the call instruction pointer value.
+ */
+union mipi_syst_msglocation32 {
+  struct {
+ #if defined (MIPI_SYST_BIG_ENDIAN)
+    mipi_syst_u16    etls_lineNo; /**< line number in file       */
+    mipi_syst_u16    etls_fileID; /**< ID of instrumented file   */
+ #else
+    mipi_syst_u16    etls_fileID; /**< ID of instrumented file   */
+    mipi_syst_u16    etls_lineNo; /**< line number in file       */
+ #endif
+  } etls_source_location;
+
+  mipi_syst_u32    etls_code_location : 32; /**< instruction pointer value */
+};
+
+/**
+ * Location information inside a message (32-bit format)
+ * Location is either the source position of the instrumentation call, or
+ * the call instruction pointer value.
+ */
+union mipi_syst_msglocation64 {
+  struct {
+ #if defined (MIPI_SYST_BIG_ENDIAN)
+    mipi_syst_u32    etls_lineNo; /**< line number in file       */
+    mipi_syst_u32    etls_fileID; /**< ID of instrumented file   */
+ #else
+    mipi_syst_u32    etls_fileID; /**< ID of instrumented file   */
+    mipi_syst_u32    etls_lineNo; /**< line number in file       */
+ #endif
+  } etls_source_location;
+  mipi_syst_u64    etls_code_location; /**< instruction pointer value */
+};
+
+/**
+ * Location information record descriptor
+ */
+struct mipi_syst_msglocation {
+  /** Message format
+   * 0 = 16-Bit file and 16-Bit line (total: 32-bit)
+   * 1 = 32-Bit file and 32-Bit line (total: 64-bit)
+   * 2 = 32-bit code address
+   * 3 = 64-bit code address
+   */
+  mipi_syst_u8    el_format;
+  union {
+    union mipi_syst_msglocation32    loc32; /**< data for 32-bit variant  */
+    union mipi_syst_msglocation64    loc64; /**< data for 64-bit variant  */
+  } el_u;
+};
+
+#ifndef MIPI_SYST_API_INCLUDED
+  #include "mipi_syst/api.h"
+#endif
+
+#endif
diff --git a/MdePkg/Library/MipiSysTLib/mipisyst b/MdePkg/Library/MipiSysTLib/mipisyst
new file mode 160000
index 0000000000..aae857d0d0
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipisyst
@@ -0,0 +1 @@
+Subproject commit aae857d0d05ac65152ed24992a4acd834a0a107c
diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
index 19bc0138cb..590cb85fd5 100644
--- a/MdePkg/MdePkg.ci.yaml
+++ b/MdePkg/MdePkg.ci.yaml
@@ -64,8 +64,10 @@
             "Include/IndustryStandard/UefiTcgPlatform.h",
             "Include/Library/PcdLib.h",
             "Include/Library/SafeIntLib.h",
+            "Include/Library/MipiSysTLib.h",
             "Include/Protocol/DebugSupport.h",
-            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"
+            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
+            "Library/MipiSysTLib/mipi_syst.h"
         ]
     },
     ## options defined ci/Plugin/CompilerPlugin
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 3d08f20d15..bee7ac538a 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -26,6 +26,7 @@
 [Includes]
   Include
   Test/UnitTest/Include
+  Library/MipiSysTLib/mipisyst/library/include
 
 [Includes.IA32]
   Include/Ia32
@@ -284,6 +285,10 @@
   #
   ArmTrngLib|Include/Library/ArmTrngLib.h
 
+  ##  @libraryclass  Provides general mipi sys-T services.
+  #
+  MipiSysTLib|Include/Library/MipiSysTLib.h
+
 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
   ##  @libraryclass  Provides services to generate random number.
   #
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 32a852dc46..cbcf4a6047 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -34,6 +34,7 @@
 
 [LibraryClasses]
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
+  MipiSysTLib|MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 
 [Components]
   MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
@@ -135,6 +136,7 @@
   MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf
   MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
   MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
+  MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 
 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
   #
diff --git a/ReadMe.rst b/ReadMe.rst
index 497d963559..283f807ab5 100644
--- a/ReadMe.rst
+++ b/ReadMe.rst
@@ -95,6 +95,7 @@ that are covered by additional licenses.
 -  `UnitTestFrameworkPkg/Library/CmockaLib/cmocka <https://github.com/tianocore/edk2-cmocka/blob/f5e2cd77c88d9f792562888d2b70c5a396bfbf7a/COPYING>`__
 -  `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__
 -  `RedfishPkg/Library/JsonLib/jansson <https://github.com/akheron/jansson/blob/2882ead5bb90cf12a01b07b2c2361e24960fae02/LICENSE>`__
+-  `MdePkg/Library/MipiSysTLib/mipisyst <https://github.com/MIPI-Alliance/public-mipi-sys-t/blob/aae857d0d05ac65152ed24992a4acd834a0a107c/LICENSE>`__
 
 The EDK II Project is composed of packages. The maintainers for each package
 are listed in `Maintainers.txt <Maintainers.txt>`__.
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library
  2023-01-31  2:48 [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
@ 2023-01-31  2:49 ` victorx.hsu
  2023-01-31  3:17   ` Guo, Gua
  2023-01-31  2:49 ` [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT victorx.hsu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: victorx.hsu @ 2023-01-31  2:49 UTC (permalink / raw)
  To: devel
  Cc: VictorX Hsu, Michael D Kinney, Guo Gua, Chan Laura,
	Prakashan Krishnadas Veliyathuparambil, K N Karthik

From: VictorX Hsu <victorx.hsu@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144

This Library provide Trace Hub API which consume MipiSysTLib.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 .../UniversalPayload/TraceHubDebugInfo.h      |  31 ++
 .../BaseTraceHubDebugLibSyst.inf              |  44 ++
 .../BaseTraceHubDebugSystLib.c                | 386 +++++++++++++++
 .../DxeSmmTraceHubDebugLibSyst.inf            |  49 ++
 .../DxeSmmTraceHubDebugSystLib.c              | 462 ++++++++++++++++++
 .../PeiTraceHubDebugLibSyst.inf               |  49 ++
 .../PeiTraceHubDebugSystLib.c                 | 446 +++++++++++++++++
 .../TraceHubDebugLibSysT/TraceHubApiCommon.c  |  81 +++
 .../TraceHubDebugLibSysT/TraceHubApiCommon.h  |  64 +++
 .../TraceHubApiInternal.h                     |  92 ++++
 MdeModulePkg/MdeModulePkg.dec                 |  21 +
 MdeModulePkg/MdeModulePkg.dsc                 |   6 +
 MdeModulePkg/MdeModulePkg.uni                 |  18 +
 13 files changed, 1749 insertions(+)
 create mode 100644 MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h

diff --git a/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h b/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h
new file mode 100644
index 0000000000..6c95a85451
--- /dev/null
+++ b/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h
@@ -0,0 +1,31 @@
+/** @file
+ Define the structure for the Universal Payload TraceHub Debug Info.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+    - Universal Payload Specification 0.9 (https://universalpayload.github.io/documentation/)
+**/
+
+#ifndef UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_
+#define UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_
+
+#include <UniversalPayload/UniversalPayload.h>
+
+typedef struct {
+  BOOLEAN    Flag;         // Flag to enable or disable Trace Hub debug message.
+  UINT8      DebugLevel;   // Debug level for Trace Hub.
+  UINTN      TraceAddress; // MMIO address where Trace Hub debug message output to.
+} TRACEHUB_DEBUG_CONTEXT;
+
+typedef struct {
+  UNIVERSAL_PAYLOAD_GENERIC_HEADER    Header;
+  TRACEHUB_DEBUG_CONTEXT              DebugContext;
+} UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO;
+
+#define UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_REVISION  1
+
+extern EFI_GUID  gUniversalPayloadTraceHubDebugInfoGuid;
+
+#endif // UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf
new file mode 100644
index 0000000000..96ecf9147a
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.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 settings.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseTraceHubDebugLibSyst
+  FILE_GUID                      = 336DA571-AD65-423C-9A43-E0056E5B2D8D
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[LibraryClasses]
+  BaseLib
+  PcdLib
+  BaseMemoryLib
+  MipiSysTLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[Sources]
+  BaseTraceHubDebugSystLib.c
+  TraceHubApiCommon.c
+  TraceHubApiCommon.h
+  TraceHubApiInternal.h
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c
new file mode 100644
index 0000000000..b0e99c69a3
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c
@@ -0,0 +1,386 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/TraceHubDebugLib.h>
+#include <Library/MipiSysTLib.h>
+#include "TraceHubApiCommon.h"
+#include "TraceHubApiInternal.h"
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    Number of bytes to be written.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  EFI_STATUS        Status;
+  UINT32            DbgInstCount;
+  UINT16            Index;
+
+  DbgInstCount = 0;
+
+  if ((NumberOfBytes == 0) || (Buffer == NULL)) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return EFI_ABORTED;
+  }
+
+  Status = MigrateTraceHubHobData ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               NULL,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubDebugType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteDebug (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 (UINT16)NumberOfBytes,
+                 (CHAR8 *)Buffer
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN EFI_GUID                 *Guid
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  EFI_STATUS        Status;
+  UINT32            DbgInstCount;
+  UINT16            Index;
+
+  DbgInstCount = 0;
+
+  if (Guid == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = MigrateTraceHubHobData ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  //
+  // Convert little endian to big endian.
+  //
+  Status = LittleEndianToBigEndian (Guid);
+  CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID));
+  MipiSystHandle.systh_tag.et_guid = 1;
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               NULL,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of parameters in argument list.
+  @param[in]  ...            Argument list that pass to Trace Hub.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64 (
+  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;
+  EFI_STATUS        Status;
+  UINT32            DbgInstCount;
+
+  DbgInstCount = 0;
+
+  if (NumberOfParams > 6) {
+    //
+    // Message with more than 6 parameter is illegal.
+    //
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = MigrateTraceHubHobData ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;
+  VA_START (Args, NumberOfParams);
+  for (Index = 0; Index < NumberOfParams; Index++) {
+    MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);
+  }
+
+  VA_END (Args);
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               NULL,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Get Trace Hub MMIO Address.
+
+  @param[in]      DgbContext        Always NULL.
+  @param[in, out] TraceAddress      Trace Hub MMIO Address.
+
+  @retval EFI_SUCCESS               Get MMIO address successfully.
+  @retval EFI_INVALID_PARAMETER     TraceAddress is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMmioAddress (
+  IN     UINT8  *DgbContext,
+  IN OUT UINTN  *TraceAddress
+  )
+{
+  if (TraceAddress == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugAddress);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get visibility of Trace Hub Msg.
+
+  @param[in]      DgbContext      Always NULL.
+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.
+  @param[in, out] DbgLevel        Debug Level of Trace Hub.
+
+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.
+  @retval EFI_INVALID_PARAMETER   On entry, Flag or DbgLevel is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMsgVisibility (
+  IN     UINT8    *DgbContext,
+  IN OUT BOOLEAN  *Flag,
+  IN OUT UINT8    *DbgLevel
+  )
+{
+  if ((DbgLevel == NULL) || (Flag == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);
+  *Flag     = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Collect the number of available Trace Hub debug instance.
+
+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.
+
+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.
+  @retval Other            Failed to collect the number of available Trace Hub debug instance.
+**/
+STATIC
+EFI_STATUS
+CountDebugInstance (
+  IN OUT UINT32  *DbgInstCount
+  )
+{
+  if (DbgInstCount == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // 1 for fixed PCD.
+  //
+  *DbgInstCount = 1;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Allocate boot time pool memory to store Trace Hub HOB data.
+
+  @retval  EFI_SUCCESS   Migration process is successful.
+  @retval  Other         Migration process is unsuccessful
+**/
+STATIC
+EFI_STATUS
+MigrateTraceHubHobData (
+  VOID
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Check whether to output Tracr Hub message.
+
+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.
+  @param[in, out]  DgbContext       Always NULL.
+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]       PrintType        Either catalog print or debug print.
+
+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.
+  @retval Other            Current Trace Hub message no need to be processed.
+**/
+STATIC
+EFI_STATUS
+CheckWhetherToOutputMsg (
+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
+  IN OUT UINT8                    *DgbContext,
+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN     TRACEHUB_PRINTTYPE       PrintType
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       Addr;
+  UINT8       DbgLevel;
+  BOOLEAN     Flag;
+
+  if (MipiSystHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (PrintType == TraceHubDebugType) {
+    Status = GetTraceHubMsgVisibility (NULL, &Flag, &DbgLevel);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) {
+      return EFI_ABORTED;
+    }
+  }
+
+  Status = GetTraceHubMmioAddress (NULL, &Addr);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;
+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {
+    return EFI_ABORTED;
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
new file mode 100644
index 0000000000..d5bc316083
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
@@ -0,0 +1,49 @@
+## @file
+#  Debug library to output Trace Hub message.
+#  Support DXE/SMM phase TraceHub debug message based on dynamic settings.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeSmmTraceHubDebugLibSyst
+  FILE_GUID                      = A9B7B825-7902-4616-8556-085DA4DFEC72
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugLib|DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[LibraryClasses]
+  BaseLib
+  PcdLib
+  HobLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  MipiSysTLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[Sources]
+  DxeSmmTraceHubDebugSystLib.c
+  TraceHubApiCommon.c
+  TraceHubApiCommon.h
+  TraceHubApiInternal.h
+
+[Guids]
+  gUniversalPayloadTraceHubDebugInfoGuid
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c
new file mode 100644
index 0000000000..d81abd2c97
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c
@@ -0,0 +1,462 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/TraceHubDebugLib.h>
+#include <Library/MipiSysTLib.h>
+#include <UniversalPayload/TraceHubDebugInfo.h>
+#include "TraceHubApiCommon.h"
+#include "TraceHubApiInternal.h"
+
+GLOBAL_REMOVE_IF_UNREFERENCED UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *mThDebugInstArray = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT32                                 mDbgInstCount      = 0;
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    Number of bytes to be written.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  EFI_STATUS        Status;
+  UINT16            Index;
+  UINT32            DbgInstCount;
+
+  DbgInstCount = 0;
+
+  if ((NumberOfBytes == 0) || (Buffer == NULL)) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return EFI_ABORTED;
+  }
+
+  Status = MigrateTraceHubHobData ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               (UINT8 *)&mThDebugInstArray[Index],
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubDebugType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteDebug (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 (UINT16)NumberOfBytes,
+                 (CHAR8 *)Buffer
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN EFI_GUID                 *Guid
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  UINTN             Index;
+  EFI_STATUS        Status;
+  UINT32            DbgInstCount;
+
+  DbgInstCount = 0;
+
+  Status = MigrateTraceHubHobData ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  if (Guid != NULL) {
+    //
+    // Convert little endian to big endian.
+    //
+    Status = LittleEndianToBigEndian (Guid);
+    CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID));
+    MipiSystHandle.systh_tag.et_guid = 1;
+  } else {
+    MipiSystHandle.systh_tag.et_modunit = 2;
+    MipiSystHandle.systh_tag.et_guid    = 0;
+  }
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               (UINT8 *)&mThDebugInstArray[Index],
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of parameters in argument list.
+  @param[in]  ...            Argument list that pass to Trace Hub.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64 (
+  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;
+  EFI_STATUS        Status;
+  UINT32            DbgInstCount;
+
+  DbgInstCount = 0;
+
+  if (NumberOfParams > 6) {
+    //
+    // Message with more than 6 parameter is illegal.
+    //
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = MigrateTraceHubHobData ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;
+  VA_START (Args, NumberOfParams);
+  for (Index = 0; Index < NumberOfParams; Index++) {
+    MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);
+  }
+
+  VA_END (Args);
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               (UINT8 *)&mThDebugInstArray[Index],
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Collect the number of available Trace Hub debug instance.
+
+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.
+
+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.
+  @retval Other            Failed to collect the number of available Trace Hub debug instance.
+**/
+STATIC
+EFI_STATUS
+CountDebugInstance (
+  IN OUT UINT32  *DbgInstCount
+  )
+{
+  UINT8  *DgbContext;
+
+  if (DbgInstCount == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (mThDebugInstArray == NULL) {
+    DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);
+    if (DgbContext != NULL) {
+      while (DgbContext != NULL) {
+        (*DbgInstCount)++;
+        DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));
+      }
+    } else {
+      //
+      // Trace Hub debug instance for PCD
+      //
+      (*DbgInstCount)++;
+    }
+  } else {
+    *DbgInstCount = mDbgInstCount;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Check whether to output Tracr Hub message.
+
+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.
+  @param[in, out]  DgbContext       A pointer to Trace Hub debug instance.
+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]       PrintType        Either catalog print or debug print.
+
+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.
+  @retval Other            Current Trace Hub message no need to be processed.
+**/
+STATIC
+EFI_STATUS
+CheckWhetherToOutputMsg (
+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
+  IN OUT UINT8                    *DgbContext,
+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN     TRACEHUB_PRINTTYPE       PrintType
+  )
+{
+  UINT8       DbgLevel;
+  BOOLEAN     Flag;
+  UINTN       Addr;
+  EFI_STATUS  Status;
+
+  if ((MipiSystHandle == NULL) || (DgbContext == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (PrintType == TraceHubDebugType) {
+    Status = GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) {
+      return EFI_ABORTED;
+    }
+  }
+
+  Status = GetTraceHubMmioAddress (DgbContext, &Addr);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;
+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {
+    return EFI_ABORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get Trace Hub MMIO Address.
+
+  @param[in]      DgbContext        A pointer to Trace Hub debug instance.
+  @param[in, out] TraceAddress      Trace Hub MMIO Address.
+
+  @retval EFI_SUCCESS               Get MMIO address successfully.
+  @retval EFI_INVALID_PARAMETER     TraceAddress or DgbContext is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMmioAddress (
+  IN     UINT8  *DgbContext,
+  IN OUT UINTN  *TraceAddress
+  )
+{
+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDbgContext;
+
+  if ((DgbContext == NULL) || (TraceAddress == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ThDbgContext  = (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *)DgbContext;
+  *TraceAddress = ThDbgContext->DebugContext.TraceAddress;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get visibility of Trace Hub Msg.
+
+  @param[in]      DgbContext      A pointer to Trace Hub debug instance.
+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.
+  @param[in, out] DbgLevel        Debug Level of Trace Hub.
+
+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.
+  @retval EFI_INVALID_PARAMETER   On entry, DgbContext or Flag or DbgLevel is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMsgVisibility (
+  IN     UINT8    *DgbContext,
+  IN OUT BOOLEAN  *Flag,
+  IN OUT UINT8    *DbgLevel
+  )
+{
+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDbgContext;
+
+  if ((DgbContext == NULL) || (Flag == NULL) || (DbgLevel == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ThDbgContext = (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *)DgbContext;
+  *Flag        = ThDbgContext->DebugContext.Flag;
+  *DbgLevel    = ThDbgContext->DebugContext.DebugLevel;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Allocate boot time pool memory to store Trace Hub HOB data.
+
+  @retval  EFI_SUCCESS   Migration process is successful.
+  @retval  Other         Migration process is unsuccessful
+**/
+STATIC
+EFI_STATUS
+MigrateTraceHubHobData (
+  VOID
+  )
+{
+  UINT8       *DgbContext;
+  UINT16      Index;
+  UINT32      DbgInstCount;
+  EFI_STATUS  Status;
+
+  Index        = 0;
+  DgbContext   = NULL;
+  DbgInstCount = 0;
+
+  if (mThDebugInstArray == NULL) {
+    Status = CountDebugInstance (&DbgInstCount);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    mDbgInstCount = DbgInstCount;
+    if (mDbgInstCount != 0) {
+      mThDebugInstArray = AllocateZeroPool (sizeof (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO) * mDbgInstCount);
+      if (mThDebugInstArray == NULL) {
+        return EFI_OUT_OF_RESOURCES;
+      }
+
+      DgbContext = GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);
+      if (DgbContext != NULL) {
+        for (Index = 0; Index < mDbgInstCount; Index++) {
+          CopyMem (&mThDebugInstArray[Index], GET_GUID_HOB_DATA (DgbContext), sizeof (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO));
+          DgbContext = GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));
+        }
+      } else {
+        for (Index = 0; Index < mDbgInstCount; Index++) {
+          mThDebugInstArray[Index].DebugContext.TraceAddress = FixedPcdGet64 (PcdTraceHubDebugAddress);
+          mThDebugInstArray[Index].DebugContext.Flag         = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
+          mThDebugInstArray[Index].DebugContext.DebugLevel   = FixedPcdGet8 (PcdTraceHubDebugLevel);
+        }
+      }
+    } else {
+      return EFI_ABORTED;
+    }
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
new file mode 100644
index 0000000000..4f4bfb695b
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
@@ -0,0 +1,49 @@
+## @file
+#  Debug library to output Trace Hub message.
+#  Support PEI phase TraceHub debug message based on dynamic settings
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PeiTraceHubDebugLibSyst
+  FILE_GUID                      = C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugLib|PEI_CORE PEIM
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[LibraryClasses]
+  BaseLib
+  PcdLib
+  HobLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  MipiSysTLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[Sources]
+  PeiTraceHubDebugSystLib.c
+  TraceHubApiCommon.c
+  TraceHubApiCommon.h
+  TraceHubApiInternal.h
+
+[Guids]
+  gUniversalPayloadTraceHubDebugInfoGuid
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c
new file mode 100644
index 0000000000..10bde71fd3
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c
@@ -0,0 +1,446 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/TraceHubDebugLib.h>
+#include <Library/MipiSysTLib.h>
+#include <UniversalPayload/TraceHubDebugInfo.h>
+#include "TraceHubApiCommon.h"
+#include "TraceHubApiInternal.h"
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    Number of bytes to be written.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  EFI_STATUS        Status;
+  UINT8             *DgbContext;
+  UINTN             Index;
+  UINT32            DbgInstCount;
+
+  DbgInstCount = 0;
+
+  if ((NumberOfBytes == 0) || (Buffer == NULL)) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return EFI_ABORTED;
+  }
+
+  Status = MigrateTraceHubHobData ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               DgbContext,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubDebugType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteDebug (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 (UINT16)NumberOfBytes,
+                 (CHAR8 *)Buffer
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+
+    if (DgbContext != NULL) {
+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));
+      if (DgbContext == NULL) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN EFI_GUID                 *Guid
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  UINT32            DbgInstCount;
+  UINT8             *DgbContext;
+  EFI_STATUS        Status;
+  UINTN             Index;
+
+  DbgInstCount = 0;
+
+  Status = MigrateTraceHubHobData ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  if (Guid != NULL) {
+    //
+    // Convert little endian to big endian.
+    //
+    Status = LittleEndianToBigEndian (Guid);
+    CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID));
+    MipiSystHandle.systh_tag.et_guid = 1;
+  } else {
+    MipiSystHandle.systh_tag.et_modunit = 2;
+    MipiSystHandle.systh_tag.et_guid    = 0;
+  }
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               DgbContext,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+
+    if (DgbContext != NULL) {
+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));
+      if (DgbContext == NULL) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of parameters in argument list.
+  @param[in]  ...            Argument list that pass to Trace Hub.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64 (
+  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             *DgbContext;
+  EFI_STATUS        Status;
+
+  DbgInstCount = 0;
+
+  if (NumberOfParams > 6) {
+    //
+    // Message with more than 6 parameter is illegal.
+    //
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = MigrateTraceHubHobData ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;
+  VA_START (Args, NumberOfParams);
+  for (Index = 0; Index < NumberOfParams; Index++) {
+    MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);
+  }
+
+  VA_END (Args);
+
+  Status = CountDebugInstance (&DbgInstCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               DgbContext,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!EFI_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+
+    if (DgbContext != NULL) {
+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));
+      if (DgbContext == NULL) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Collect the number of available Trace Hub debug instance.
+
+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.
+
+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.
+  @retval Other            Failed to collect the number of available Trace Hub debug instance.
+**/
+STATIC
+EFI_STATUS
+CountDebugInstance (
+  IN OUT UINT32  *DbgInstCount
+  )
+{
+  UINT8  *DgbContext;
+
+  if (DbgInstCount == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);
+  if (DgbContext != NULL) {
+    while (DgbContext != NULL) {
+      (*DbgInstCount)++;
+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));
+    }
+  } else {
+    //
+    // Trace Hub debug instance for PCD
+    //
+    (*DbgInstCount)++;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Check whether to output Tracr Hub message.
+
+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.
+  @param[in, out]  DgbContext       A pointer to Trace Hub debug instance. NULL is acceptable.
+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]       PrintType        Either catalog print or debug print.
+
+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.
+  @retval Other            Current Trace Hub message no need to be processed.
+**/
+STATIC
+EFI_STATUS
+CheckWhetherToOutputMsg (
+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
+  IN OUT UINT8                    *DgbContext,
+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN     TRACEHUB_PRINTTYPE       PrintType
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       Addr;
+  UINT8       DbgLevel;
+  BOOLEAN     Flag;
+
+  if (MipiSystHandle == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (PrintType == TraceHubDebugType) {
+    Status = GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) {
+      return EFI_ABORTED;
+    }
+  }
+
+  Status = GetTraceHubMmioAddress (DgbContext, &Addr);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;
+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {
+    return EFI_ABORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get Trace Hub MMIO Address.
+
+  @param[in]      DgbContext        A pointer to Trace Hub debug instance. NULL is acceptable.
+  @param[in, out] TraceAddress      Trace Hub MMIO Address.
+
+  @retval EFI_SUCCESS               Get MMIO address successfully.
+  @retval EFI_INVALID_PARAMETER     TraceAddress is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMmioAddress (
+  IN     UINT8  *DgbContext,
+  IN OUT UINTN  *TraceAddress
+  )
+{
+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDebugInfo;
+
+  ThDebugInfo = NULL;
+
+  if (TraceAddress == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (DgbContext != NULL) {
+    ThDebugInfo   = GET_GUID_HOB_DATA (DgbContext);
+    *TraceAddress = ThDebugInfo->DebugContext.TraceAddress;
+  } else {
+    *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugAddress);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get visibility of Trace Hub Msg.
+
+  @param[in]      DgbContext      A pointer to Trace Hub debug instance. NULL is acceptable.
+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.
+  @param[in, out] DbgLevel        Debug Level of Trace Hub.
+
+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.
+  @retval EFI_INVALID_PARAMETER   On entry, Flag or DbgLevel is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMsgVisibility (
+  IN     UINT8    *DgbContext,
+  IN OUT BOOLEAN  *Flag,
+  IN OUT UINT8    *DbgLevel
+  )
+{
+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDebugInfo;
+
+  ThDebugInfo = NULL;
+
+  if ((DbgLevel == NULL) || (Flag == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (DgbContext != NULL) {
+    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+    *DbgLevel   = ThDebugInfo->DebugContext.DebugLevel;
+    *Flag       = ThDebugInfo->DebugContext.Flag;
+  } else {
+    *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);
+    *Flag     = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Allocate boot time pool memory to store Trace Hub HOB data.
+
+  @retval  EFI_SUCCESS   Migration process is successful.
+  @retval  Other         Migration process is unsuccessful
+**/
+STATIC
+EFI_STATUS
+MigrateTraceHubHobData (
+  VOID
+  )
+{
+  return EFI_UNSUPPORTED;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c
new file mode 100644
index 0000000000..0e7a09c95e
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c
@@ -0,0 +1,81 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include "TraceHubApiCommon.h"
+
+/**
+  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
+EnableTraceHubData (
+  IN BOOLEAN                  Flag,
+  IN UINT8                    DbgLevel,
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType
+  )
+{
+  if (Flag == TraceHubRoutingDisable) {
+    return FALSE;
+  }
+
+  if (DbgLevel == TraceHubDebugLevelError) {
+    if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError))) {
+      return TRUE;
+    }
+  } else if (DbgLevel == TraceHubDebugLevelErrorWarning) {
+    if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError) || (SeverityType == SeverityWarning))) {
+      return TRUE;
+    }
+  } else if (DbgLevel == TraceHubDebugLevelErrorWarningInfo) {
+    if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError) || (SeverityType == SeverityWarning) || (SeverityType == SeverityNormal))) {
+      return TRUE;
+    }
+  } else if (DbgLevel == TraceHubDebugLevelErrorWarningInfoVerbose) {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/**
+  Convert GUID from little endian to big endian.
+
+  @param[in, out]  Guid   GUID in little endian format on entry. GUID in big endian format on exit.
+
+  @retval EFI_SUCCESS      Convert GUID successfully.
+**/
+EFI_STATUS
+EFIAPI
+LittleEndianToBigEndian (
+  IN OUT EFI_GUID  *Guid
+  )
+{
+  EFI_GUID  TempGuid;
+  UINT64    GuidData4;
+
+  ZeroMem (&TempGuid, sizeof (EFI_GUID));
+  TempGuid.Data1 = SwapBytes32 (Guid->Data1);
+  TempGuid.Data2 = SwapBytes16 (Guid->Data2);
+  TempGuid.Data3 = SwapBytes16 (Guid->Data3);
+  CopyMem (&GuidData4, Guid->Data4, sizeof (Guid->Data4));
+  GuidData4 = SwapBytes64 (GuidData4);
+  CopyMem (TempGuid.Data4, &GuidData4, sizeof (GuidData4));
+  CopyMem (Guid, &TempGuid, sizeof (EFI_GUID));
+
+  return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h
new file mode 100644
index 0000000000..f2f3cda8b7
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h
@@ -0,0 +1,64 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef TRACE_HUB_API_COMMON_H_
+#define TRACE_HUB_API_COMMON_H_
+
+#include <Library/TraceHubDebugLib.h>
+
+typedef enum {
+  TraceHubDebugType = 0,
+  TraceHubCatalogType
+} TRACEHUB_PRINTTYPE;
+
+typedef enum {
+  TraceHubRoutingDisable = 0,
+  TraceHubRoutingEnable,
+  TraceHubRoutingMax
+} TRACE_HUB_ROUTING;
+
+typedef enum {
+  TraceHubDebugLevelError = 0,
+  TraceHubDebugLevelErrorWarning,
+  TraceHubDebugLevelErrorWarningInfo,
+  TraceHubDebugLevelErrorWarningInfoVerbose,
+  TraceHubDebugLevelMax
+} TRACE_HUB_DEBUG_LEVEL;
+
+/**
+  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
+EnableTraceHubData (
+  IN BOOLEAN                  Flag,
+  IN UINT8                    DbgLevel,
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType
+  );
+
+/**
+  Convert GUID from little endian to big endian.
+
+  @param[in, out]  Guid   GUID in little endian format on entry. GUID in big endian format on exit.
+
+  @retval EFI_SUCCESS      Convert GUID successfully.
+**/
+EFI_STATUS
+EFIAPI
+LittleEndianToBigEndian (
+  IN OUT EFI_GUID  *Guid
+  );
+
+#endif // TRACE_HUB_API_COMMON_H_
diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h
new file mode 100644
index 0000000000..23a9879316
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h
@@ -0,0 +1,92 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef TRACE_HUB_API_INTERNAL_H_
+#define TRACE_HUB_API_INTERNAL_H_
+
+/**
+  Collect the number of available Trace Hub debug instance.
+
+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.
+
+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.
+  @retval Other            Failed to collect the number of available Trace Hub debug instance.
+**/
+STATIC
+EFI_STATUS
+CountDebugInstance (
+  IN OUT UINT32  *DbgInstCount
+  );
+
+/**
+  Check whether to output Tracr Hub message.
+
+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.
+  @param[in, out]  DgbContext       A pointer to Trace Hub debug instance.
+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]       PrintType        Either catalog print or debug print.
+
+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.
+  @retval Other            Current Trace Hub message no need to be processed.
+**/
+STATIC
+EFI_STATUS
+CheckWhetherToOutputMsg (
+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
+  IN OUT UINT8                    *DgbContext,
+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN     TRACEHUB_PRINTTYPE       PrintType
+  );
+
+/**
+  Get visibility of Trace Hub Msg.
+
+  @param[in]      DgbContext      A pointer to Trace Hub debug instance.
+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.
+  @param[in, out] DbgLevel        Debug Level of Trace Hub.
+
+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.
+  @retval EFI_INVALID_PARAMETER   On entry, Flag or DbgLevel is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMsgVisibility (
+  IN     UINT8    *DgbContext,
+  IN OUT BOOLEAN  *Flag,
+  IN OUT UINT8    *DbgLevel
+  );
+
+/**
+  Get Trace Hub MMIO Address.
+
+  @param[in]      DgbContext        A pointer to Trace Hub debug instance.
+  @param[in, out] TraceAddress      Trace Hub MMIO Address.
+
+  @retval EFI_SUCCESS               Get MMIO address successfully.
+  @retval EFI_INVALID_PARAMETER     TraceAddress is a NULL pointer.
+**/
+STATIC
+EFI_STATUS
+GetTraceHubMmioAddress (
+  IN     UINT8  *DgbContext,
+  IN OUT UINTN  *TraceAddress
+  );
+
+/**
+  Allocate boot time pool memory to store Trace Hub HOB data.
+
+  @retval  EFI_SUCCESS   Migration process is successful.
+  @retval  Other         Migration process is unsuccessful
+**/
+STATIC
+EFI_STATUS
+MigrateTraceHubHobData (
+  VOID
+  );
+
+#endif // TRACE_HUB_API_INTERNAL_H_
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 9605c617b7..8300c88141 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -438,6 +438,9 @@
   ## Include/UniversalPayload/SerialPortInfo.h
   gUniversalPayloadSerialPortInfoGuid = { 0xaa7e190d, 0xbe21, 0x4409, { 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } }
 
+  ## Include/UniversalPayload/TraceHubDebugInfo.h
+  gUniversalPayloadTraceHubDebugInfoGuid = { 0xf88c9c23, 0x646c, 0x4f6c, { 0x8e, 0x3d, 0x36, 0xa9, 0x43, 0xc1, 0x08, 0x35 } }
+
   ## GUID used for Boot Discovery Policy FormSet guid and related variables.
   gBootDiscoveryPolicyMgrFormsetGuid = { 0x5b6f7107, 0xbb3c, 0x4660, { 0x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } }
 
@@ -1093,6 +1096,24 @@
   # @Prompt Enable UEFI Stack Guard.
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055
 
+  ## Indicate debug level of Trace Hub.
+  #   0x0 - TraceHubDebugLevelError.<BR>
+  #   0x1 - TraceHubDebugLevelErrorWarning.<BR>
+  #   0x2 - TraceHubDebugLevelErrorWarningInfo.<BR>
+  #   0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.<BR>
+  # @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.<BR>
+  #   TRUE  - Enable Trace Hub debug message.<BR>
+  # @Prompt Enable or Disable Trace Hub message.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg|0|BOOLEAN|0x30001057
+
+  ## Indicate MMIO address where Trace Hub message output to.
+  # @Prompt Output MMIO address of Trace Hub message.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress|0|UINT64|0x30001058
+
 [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..a11f26572a 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -106,6 +106,9 @@
   MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
   VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
   IpmiCommandLib|MdeModulePkg/Library/BaseIpmiCommandLibNull/BaseIpmiCommandLibNull.inf
+  TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf
+  TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
+  TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
 
 [LibraryClasses.EBC.PEIM]
   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
@@ -446,6 +449,9 @@
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
   MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
+  MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf
+  MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
+  MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
 
 [Components.IA32, Components.X64, Components.AARCH64]
   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 33ce9f6198..b64f26d255 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -1290,6 +1290,24 @@
                                                                                     "   TRUE  - UEFI Stack Guard will be enabled.<BR>\n"
                                                                                     "   FALSE - UEFI Stack Guard will be disabled.<BR>"
 
+#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.<BR>"
+                                                                                         "  0x1 - TraceHubDebugLevelErrorWarning.<BR>"
+                                                                                         "  0x2 - TraceHubDebugLevelErrorWarningInfo.<BR>"
+                                                                                         "  0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.<BR>"
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_PROMPT  #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.<BR>"
+                                                                                             "  TRUE  - Enable Trace Hub debug message.<BR>"
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugAddress_PROMPT  #language en-US "Output MMIO address of Trace Hub message"
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugAddress_HELP    #language en-US "Indicate MMIO address where Trace Hub message output to."
+
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_PROMPT  #language en-US "NV Storage DefaultId"
 
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_HELP    #language en-US "This dynamic PCD enables the default variable setting.\n"
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT
  2023-01-31  2:48 [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
  2023-01-31  2:49 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library victorx.hsu
@ 2023-01-31  2:49 ` victorx.hsu
  2023-01-31  3:17   ` Guo, Gua
  2023-01-31  2:49 ` [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library victorx.hsu
  2023-01-31  3:17 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library Guo, Gua
  3 siblings, 1 reply; 8+ messages in thread
From: victorx.hsu @ 2023-01-31  2:49 UTC (permalink / raw)
  To: devel
  Cc: VictorX Hsu, Michael D Kinney, Guo Gua, Chan Laura,
	Prakashan Krishnadas Veliyathuparambil, K N Karthik

From: VictorX Hsu <victorx.hsu@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144

This Library is NULL library for TraceHubDebugLibSysT.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 MdePkg/Include/Library/TraceHubDebugLib.h     | 82 +++++++++++++++++++
 .../TraceHubDebugLibNull.c                    | 75 +++++++++++++++++
 .../TraceHubDebugLibNull.inf                  | 29 +++++++
 MdePkg/MdePkg.dec                             |  4 +
 MdePkg/MdePkg.dsc                             |  2 +
 5 files changed, 192 insertions(+)
 create mode 100644 MdePkg/Include/Library/TraceHubDebugLib.h
 create mode 100644 MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c
 create mode 100644 MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf

diff --git a/MdePkg/Include/Library/TraceHubDebugLib.h b/MdePkg/Include/Library/TraceHubDebugLib.h
new file mode 100644
index 0000000000..2e8d70ae97
--- /dev/null
+++ b/MdePkg/Include/Library/TraceHubDebugLib.h
@@ -0,0 +1,82 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef TRACE_HUB_DEBUG_LIB_H_
+#define TRACE_HUB_DEBUG_LIB_H_
+
+#include <Uefi.h>
+
+typedef enum {
+  SeverityNone    = 0,
+  SeverityFatal   = 1,
+  SeverityError   = 2,
+  SeverityWarning = 3,
+  SeverityNormal  = 4,
+  SeverityUser1   = 5,
+  SeverityUser2   = 6,
+  SeverityUser3   = 7,
+  SeverityMax
+} TRACE_HUB_SEVERITY_TYPE;
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    Number of bytes to be written.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  );
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN EFI_GUID                 *Guid
+  );
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of parameters in argument list.
+  @param[in]  ...            Argument list that pass to Trace Hub.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  );
+
+#endif // TRACE_HUB_DEBUG_LIB_H_
diff --git a/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c
new file mode 100644
index 0000000000..8d8f3f69e8
--- /dev/null
+++ b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c
@@ -0,0 +1,75 @@
+/** @file
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/TraceHubDebugLib.h>
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    Number of bytes to be written.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN EFI_GUID                 *Guid
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of parameters in argument list.
+  @param[in]  ...            Argument list that pass to Trace Hub.
+
+  @retval EFI_SUCCESS      Data was written to Trace Hub.
+  @retval Other            Failed to output Trace Hub message.
+**/
+EFI_STATUS
+EFIAPI
+TraceHubWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  )
+{
+  return EFI_UNSUPPORTED;
+}
diff --git a/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf
new file mode 100644
index 0000000000..0629365b6e
--- /dev/null
+++ b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf
@@ -0,0 +1,29 @@
+## @file
+#  Null library of TraceHubDebugLib.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = TraceHubDebugLibNull
+  FILE_GUID                      = 16196A4E-4196-4AF4-9A6B-F4D2ACC430A8
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[Sources]
+  TraceHubDebugLibNull.c
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index bee7ac538a..1ea6a0aae6 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -289,6 +289,10 @@
   #
   MipiSysTLib|Include/Library/MipiSysTLib.h
 
+  ##  @libraryclass  Provides API to output Trace Hub debug message.
+  #
+  TraceHubDebugLib|Include/Library/TraceHubDebugLib.h
+
 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
   ##  @libraryclass  Provides services to generate random number.
   #
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index cbcf4a6047..a2b4164d84 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -35,6 +35,7 @@
 [LibraryClasses]
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
   MipiSysTLib|MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
+  TraceHubDebugLib|MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf
 
 [Components]
   MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
@@ -137,6 +138,7 @@
   MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf
   MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
   MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
+  MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf
 
 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]
   #
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library.
  2023-01-31  2:48 [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
  2023-01-31  2:49 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library victorx.hsu
  2023-01-31  2:49 ` [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT victorx.hsu
@ 2023-01-31  2:49 ` victorx.hsu
  2023-01-31  3:16   ` Guo, Gua
  2023-01-31  3:17 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library Guo, Gua
  3 siblings, 1 reply; 8+ messages in thread
From: victorx.hsu @ 2023-01-31  2:49 UTC (permalink / raw)
  To: devel
  Cc: VictorX Hsu, Michael D Kinney, Guo Gua, Chan Laura,
	Prakashan Krishnadas Veliyathuparambil, K N Karthik

From: VictorX Hsu <victorx.hsu@intel.com>

Update reviewers for Trace Hub library.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 Maintainers.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Maintainers.txt b/Maintainers.txt
index 68f603b483..2fdb417541 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -421,6 +421,14 @@ R: Zhiguang Liu <zhiguang.liu@intel.com> [LiuZhiguang001]
 R: Ray Ni <ray.ni@intel.com> [niruiyu]
 R: Gua Guo <gua.guo@intel.com> [gguo11837463]
 
+MdeModulePkg: Trace Hub Debug instance
+F: MdeModulePkg/*/*TraceHub*
+R: Michael D Kinney <michael.d.kinney@intel.com> [mdkinney]
+R: Chan Laura <laura.chan@intel.com> [lauracha]
+R: K N Karthik <karthik.k.n@intel.com> [karthikkabbigere1]
+M: Gua Guo <gua.guo@intel.com> [gguo11837463]
+M: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> [kprakas2]
+
 MdePkg
 F: MdePkg/
 W: https://github.com/tianocore/tianocore.github.io/wiki/MdePkg
@@ -428,6 +436,15 @@ M: Michael D Kinney <michael.d.kinney@intel.com> [mdkinney]
 M: Liming Gao <gaoliming@byosoft.com.cn> [lgao4]
 R: Zhiguang Liu <zhiguang.liu@intel.com> [LiuZhiguang001]
 
+MdePkg: Trace Hub Debug instance
+F: MdePkg/*/*MipiSysT*
+F: MdePkg/*/*TraceHub*
+R: Michael D Kinney <michael.d.kinney@intel.com> [mdkinney]
+R: Chan Laura <laura.chan@intel.com> [lauracha]
+R: K N Karthik <karthik.k.n@intel.com> [karthikkabbigere1]
+M: Gua Guo <gua.guo@intel.com> [gguo11837463]
+M: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> [kprakas2]
+
 NetworkPkg
 F: NetworkPkg/
 W: https://github.com/tianocore/tianocore.github.io/wiki/NetworkPkg
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library.
  2023-01-31  2:49 ` [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library victorx.hsu
@ 2023-01-31  3:16   ` Guo, Gua
  0 siblings, 0 replies; 8+ messages in thread
From: Guo, Gua @ 2023-01-31  3:16 UTC (permalink / raw)
  To: Hsu, VictorX, devel@edk2.groups.io
  Cc: Kinney, Michael D, Chan, Laura,
	Prakashan, Krishnadas Veliyathuparambil, K N, Karthik

Reviewed-by: Gua Guo <gua.guo@intel.com> 

-----Original Message-----
From: Hsu, VictorX <victorx.hsu@intel.com> 
Sent: Tuesday, January 31, 2023 10:49 AM
To: devel@edk2.groups.io
Cc: Hsu, VictorX <victorx.hsu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Guo, Gua <gua.guo@intel.com>; Chan, Laura <laura.chan@intel.com>; Prakashan, Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>; K N, Karthik <karthik.k.n@intel.com>
Subject: [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library.

From: VictorX Hsu <victorx.hsu@intel.com>

Update reviewers for Trace Hub library.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 Maintainers.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Maintainers.txt b/Maintainers.txt index 68f603b483..2fdb417541 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -421,6 +421,14 @@ R: Zhiguang Liu <zhiguang.liu@intel.com> [LiuZhiguang001]
 R: Ray Ni <ray.ni@intel.com> [niruiyu] R: Gua Guo <gua.guo@intel.com> [gguo11837463] +MdeModulePkg: Trace Hub Debug instance+F: MdeModulePkg/*/*TraceHub*+R: Michael D Kinney <michael.d.kinney@intel.com> [mdkinney]+R: Chan Laura <laura.chan@intel.com> [lauracha]+R: K N Karthik <karthik.k.n@intel.com> [karthikkabbigere1]+M: Gua Guo <gua.guo@intel.com> [gguo11837463]+M: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> [kprakas2]+ MdePkg F: MdePkg/ W: https://github.com/tianocore/tianocore.github.io/wiki/MdePkg@@ -428,6 +436,15 @@ M: Michael D Kinney <michael.d.kinney@intel.com> [mdkinney]
 M: Liming Gao <gaoliming@byosoft.com.cn> [lgao4] R: Zhiguang Liu <zhiguang.liu@intel.com> [LiuZhiguang001] +MdePkg: Trace Hub Debug instance+F: MdePkg/*/*MipiSysT*+F: MdePkg/*/*TraceHub*+R: Michael D Kinney <michael.d.kinney@intel.com> [mdkinney]+R: Chan Laura <laura.chan@intel.com> [lauracha]+R: K N Karthik <karthik.k.n@intel.com> [karthikkabbigere1]+M: Gua Guo <gua.guo@intel.com> [gguo11837463]+M: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> [kprakas2]+ NetworkPkg F: NetworkPkg/ W: https://github.com/tianocore/tianocore.github.io/wiki/NetworkPkg--
2.28.0.windows.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] MdePkg: Add MipiSysTLib library
  2023-01-31  2:48 [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
                   ` (2 preceding siblings ...)
  2023-01-31  2:49 ` [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library victorx.hsu
@ 2023-01-31  3:17 ` Guo, Gua
  3 siblings, 0 replies; 8+ messages in thread
From: Guo, Gua @ 2023-01-31  3:17 UTC (permalink / raw)
  To: Hsu, VictorX, devel@edk2.groups.io
  Cc: Kinney, Michael D, Chan, Laura,
	Prakashan, Krishnadas Veliyathuparambil, K N, Karthik

Reviewed-by: Gua Guo <gua.guo@intel.com>

-----Original Message-----
From: Hsu, VictorX <victorx.hsu@intel.com> 
Sent: Tuesday, January 31, 2023 10:49 AM
To: devel@edk2.groups.io
Cc: Hsu, VictorX <victorx.hsu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Guo, Gua <gua.guo@intel.com>; Chan, Laura <laura.chan@intel.com>; Prakashan, Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>; K N, Karthik <karthik.k.n@intel.com>
Subject: [PATCH 1/4] MdePkg: Add MipiSysTLib library

From: VictorX Hsu <victorx.hsu@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144

Wrap mipi sys-T submodule as a MipiSysTLib. This Library provide mipi sys-T API to be consumed.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 .gitmodules                                |   5 +-
 .pytool/CISettings.py                      |   2 +
 MdePkg/Include/Library/MipiSysTLib.h       | 242 +++++++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.c   | 110 +++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf |  52 ++
 MdePkg/Library/MipiSysTLib/Platform.c      | 160 ++++++
 MdePkg/Library/MipiSysTLib/Platform.h      | 140 ++++++
 MdePkg/Library/MipiSysTLib/mipi_syst.h     | 539 +++++++++++++++++++++
 MdePkg/Library/MipiSysTLib/mipisyst        |   1 +
 MdePkg/MdePkg.ci.yaml                      |   4 +-
 MdePkg/MdePkg.dec                          |   5 +
 MdePkg/MdePkg.dsc                          |   2 +
 ReadMe.rst                                 |   1 +
 13 files changed, 1261 insertions(+), 2 deletions(-)  create mode 100644 MdePkg/Include/Library/MipiSysTLib.h
 create mode 100644 MdePkg/Library/MipiSysTLib/MipiSysTLib.c
 create mode 100644 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 create mode 100644 MdePkg/Library/MipiSysTLib/Platform.c
 create mode 100644 MdePkg/Library/MipiSysTLib/Platform.h
 create mode 100644 MdePkg/Library/MipiSysTLib/mipi_syst.h
 create mode 160000 MdePkg/Library/MipiSysTLib/mipisyst

diff --git a/.gitmodules b/.gitmodules
index 8011a88d9d..4a0500eea4 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,10 +16,13 @@
 [submodule "BaseTools/Source/C/BrotliCompress/brotli"]
 	path = BaseTools/Source/C/BrotliCompress/brotli
 	url = https://github.com/google/brotli
-	ignore = untracked+	ignore = untracked
 [submodule "RedfishPkg/Library/JsonLib/jansson"]
 	path = RedfishPkg/Library/JsonLib/jansson
 	url = https://github.com/akheron/jansson
 [submodule "UnitTestFrameworkPkg/Library/GoogleTestLib/googletest"]
 	path = UnitTestFrameworkPkg/Library/GoogleTestLib/googletest
 	url = https://github.com/google/googletest.git
+[submodule "MdePkg/Library/MipiSysTLib/mipisyst"]
+	path = MdePkg/Library/MipiSysTLib/mipisyst
+	url = https://github.com/MIPI-Alliance/public-mipi-sys-t.git
diff --git a/.pytool/CISettings.py b/.pytool/CISettings.py index d87c8e838e..0118820680 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -193,6 +193,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
             "BaseTools/Source/C/BrotliCompress/brotli", False))         rs.append(RequiredSubmodule(             "RedfishPkg/Library/JsonLib/jansson", False))+        rs.append(RequiredSubmodule(+            "MdePkg/Library/MipiSysTLib/mipisyst", False))         return rs      def GetName(self):diff --git a/MdePkg/Include/Library/MipiSysTLib.h b/MdePkg/Include/Library/MipiSysTLib.h
new file mode 100644
index 0000000000..6282baac8e
--- /dev/null
+++ b/MdePkg/Include/Library/MipiSysTLib.h
@@ -0,0 +1,242 @@
+/** @file++Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>++SPDX-License-Identifier: BSD-2-Clause-Patent++**/++#ifndef MIPI_SYST_LIB_H_+#define MIPI_SYST_LIB_H_++#include <Uefi.h>++#define MIPI_SYST_CONFORMANCE_LEVEL  30+#define MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA+#define MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID++struct mipi_syst_header;+struct mipi_syst_handle;+struct mipi_syst_scatter_prog;++/**+ * SyS-T handle state initialization hook definition+ *+ * This function gets called in the context of IO handle generation.+ * Its purpose is to initialize the platform dependent portion of+*  the handle and other necessary platform specific initialization steps.+ *+ * @param systh Pointer to new SyS-T handle+ * @see syst_handle_t+ */+typedef void (*mipi_syst_inithandle_hook_t)(+  struct mipi_syst_handle  *systh+  );++/**+ * SyS-T handle state release hook definition+ *+ * This function gets called when a handle is about to be destroyed..+ * Its purpose is to free any resources allocated during the handle+ * generation.+ *+ * @param systh Pointer to handle that is destroyed+ * @see syst_handle_t+ */+typedef void (*mipi_syst_releasehandle_hook_t)(+  struct mipi_syst_handle  *systh+  );++/**+ * Low level message write routine definition+ *+ * This function is called at the end of an instrumentation API to output+ * the raw message data.+ *+ * @param systh pointer to a SyS-T handle structure used in the API call,+ * @param scatterprog pointer to a list of scatter write instructions that+ *                    encodes how to convert the descriptor pointer by+ *                    pdesc into raw binary data. This list doesn't include+ *                    the mandatory first 32 tag byte value pointed by pdesc.+ * @param pdesc pointer to a message descriptor, which containing at least+ *              the 32-bit message tag data+ */+typedef void (*mipi_syst_msg_write_t)(+  struct mipi_syst_handle        *systh,+  struct mipi_syst_scatter_prog  *scatterprog,+  const void                     *pdesc+  );++typedef struct {+  UINTN    MmioAddr;+} TRACE_HUB_PLATFORM_SYST_DATA;++struct mipi_syst_platform_handle {+  TRACE_HUB_PLATFORM_SYST_DATA    TraceHubPlatformData;+};++/** internal handle state flags+ */+typedef struct mipi_syst_handle_flags {+  UINT32    shf_alloc : 1; /**< set to 1 if heap allocated handle */+} MIPI_SYST_HANDLE_FLAGS;++/**+ * Message data header tag definition+ *+ * Each SyS-T message starts with a 32-bit message tag. The tag defines the+ * message originator and decoding information for the data following+ * the tag.+ */++typedef struct mipi_syst_msg_tag {+ #if defined (MIPI_SYST_BIG_ENDIAN)+  UINT32    et_res31     : 1;  /**< reserved for future use        */+  UINT32    et_res30     : 1;  /**< reserved for future use        */+  UINT32    et_subtype   : 6;  /**< type dependent sub category    */+  UINT32    et_guid      : 1;  /**< 128-bit GUID present           */+  UINT32    et_modunit   : 11; /**< unit for GUID or module:unit   */+  UINT32    et_timestamp : 1;  /**< indicate 64-bit timestamp      */+  UINT32    et_chksum    : 1;  /**< indicate 32-bit CRC            */+  UINT32    et_length    : 1;  /**< indicate length field          */+  UINT32    et_location  : 1;  /**< indicate location information  */+  UINT32    et_res7      : 1;  /**< reserved for future use        */+  UINT32    et_severity  : 3;  /**< severity level of message      */+  UINT32    et_type      : 4;  /**< SyS-T message type ID          */+ #else+  UINT32    et_type      : 4;  /**< SyS-T message type ID          */+  UINT32    et_severity  : 3;  /**< severity level of message      */+  UINT32    et_res7      : 1;  /**< reserved for future use        */+  UINT32    et_location  : 1;  /**< indicate location information  */+  UINT32    et_length    : 1;  /**< indicate length field          */+  UINT32    et_chksum    : 1;  /**< indicate 32-bit CRC            */+  UINT32    et_timestamp : 1;  /**< indicate 64-bit timestamp      */+  UINT32    et_modunit   : 11; /**< unit for GUID or module:unit   */+  UINT32    et_guid      : 1;  /**< 128-bit GUID present           */+  UINT32    et_subtype   : 6;  /**< type dependent sub category    */+  UINT32    et_res30     : 1;  /**< reserved for future use        */+  UINT32    et_res31     : 1;  /**< reserved for future use        */+ #endif+} MIPI_SYST_MSG_TAG;++/** 128-bit GUID style message origin ID */+typedef struct mipi_syst_guid {+  union {+    UINT8     b[16];+    UINT64    ll[2];+  } u;+} MIPI_SYST_GUID;++/**+ * Message severity level enumeration+ */+typedef enum mipi_syst_severity {+  MIPI_SYST_SEVERITY_MAX     = 0,  /**< no assigned severity       */+  MIPI_SYST_SEVERITY_FATAL   = 1,  /**< critical error level       */+  MIPI_SYST_SEVERITY_ERROR   = 2,  /**< error message level        */+  MIPI_SYST_SEVERITY_WARNING = 3,  /**< warning message level      */+  MIPI_SYST_SEVERITY_INFO    = 4,  /**< information message level  */+  MIPI_SYST_SEVERITY_USER1   = 5,  /**< user defined level 5       */+  MIPI_SYST_SEVERITY_USER2   = 6,  /**< user defined level 6       */+  MIPI_SYST_SEVERITY_DEBUG   = 7   /**< debug information level    */+} MIPI_SYST_SEVERITY;++/** SyS-T connection handle state structure+ *+ * This structure connects the instrumentation API with the underlying SyS-T+ * infrastructure. It plays a similar role to a FILE * in traditional+ * C file IO.+ */+typedef struct mipi_syst_handle {+  struct mipi_syst_header             *systh_header;      /**< global state            */+  struct mipi_syst_handle_flags       systh_flags;        /**< handle state            */+  struct mipi_syst_msg_tag            systh_tag;          /**< tag flags               */++ #if defined (MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID)+  struct mipi_syst_guid               systh_guid;         /**< module GUID             */+ #endif++ #if defined (MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)+  struct mipi_syst_msglocation        systh_location;     /**< location record     */+ #endif++  UINT32                              systh_param_count;  /**< number of parameters     */+  UINT32                              systh_param[6];     /**< catalog msg parameters   */++ #if defined (MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)+  struct mipi_syst_platform_handle    systh_platform;     /**< platform specific state  */+ #endif+} MIPI_SYST_HANDLE;++/** SyS-T global state structure.+ * This structure is holding the global SyS-T library state+ */+typedef struct mipi_syst_header {+  UINT32                             systh_version;  /**< SyS-T version ID         */++ #if defined (MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)+  mipi_syst_inithandle_hook_t        systh_inith;    /**< handle init hook function*/+  mipi_syst_releasehandle_hook_t     systh_releaseh; /**< handle release hook      */+ #endif++ #if MIPI_SYST_CONFORMANCE_LEVEL > 10+  mipi_syst_msg_write_t              systh_writer;   /**< message output routine   */+ #endif+ #if defined (MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)+  struct mipi_syst_platform_state    systh_platform; /**< platform specific state  */+ #endif+} MIPI_SYST_HEADER;++/**+  Invoke initialization function in Mipi Sys-T module to initialize Mipi Sys-T handle.++  @param[in, out]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.++  @retval EFI_SUCCESS               MIPI_SYST_HANDLE instance was initialized.+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.+**/+EFI_STATUS+EFIAPI+InitMipiSystHandle (+  IN OUT MIPI_SYST_HANDLE  *MipiSystHandle+  );++/**+  Invoke write_debug_string function in Mipi Sys-T module.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.+  @param[in]  Len             Length of data buffer.+  @param[in]  Str             A pointer to data buffer.++  @retval EFI_SUCCESS               Data in buffer was processed.+  @retval EFI_ABORTED               No data need to be written to Trace Hub.+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.+**/+EFI_STATUS+EFIAPI+MipiSystWriteDebug (+  IN        MIPI_SYST_HANDLE  *MipiSystHandle,+  IN        UINT32            Severity,+  IN        UINT16            Len,+  IN CONST  CHAR8             *Str+  );++/**+  Invoke catalog_write_message function in Mipi Sys-T module.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.+  @param[in]  CatId           Catalog Id.++  @retval EFI_SUCCESS      Data in buffer was processed.+**/+EFI_STATUS+EFIAPI+MipiSystWriteCatalog (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Severity,+  IN  UINT64            CatId+  );++#endif // MIPI_SYST_LIB_H_diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.c b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
new file mode 100644
index 0000000000..0195ad85b0
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
@@ -0,0 +1,110 @@
+/** @file++Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>++SPDX-License-Identifier: BSD-2-Clause-Patent++**/++#include <Uefi.h>+#include "mipi_syst.h"++/**+  Invoke initialization function in Mipi Sys-T module to initialize Mipi Sys-T handle.++  @param[in, out]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.++  @retval EFI_SUCCESS               MIPI_SYST_HANDLE instance was initialized.+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.+**/+EFI_STATUS+EFIAPI+InitMipiSystHandle (+  IN OUT MIPI_SYST_HANDLE  *MipiSystHandle+  )+{+  if (MipiSystHandle == NULL) {+    return EFI_INVALID_PARAMETER;+  }++  mipi_syst_init (MipiSystHandle->systh_header, 0, NULL);+  mipi_syst_init_handle (MipiSystHandle->systh_header, MipiSystHandle, NULL, 0);++  return EFI_SUCCESS;+}++/**+  Invoke write_debug_string function in Mipi Sys-T module.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.+  @param[in]  Len             Length of data buffer.+  @param[in]  Str             A pointer to data buffer.++  @retval EFI_SUCCESS               Data in buffer was processed.+  @retval EFI_ABORTED               No data need to be written to Trace Hub.+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.+**/+EFI_STATUS+EFIAPI+MipiSystWriteDebug (+  IN        MIPI_SYST_HANDLE  *MipiSystHandle,+  IN        UINT32            Severity,+  IN        UINT16            Len,+  IN CONST  CHAR8             *Str+  )+{+  if (MipiSystHandle == NULL) {+    return EFI_INVALID_PARAMETER;+  }++  if ((Len == 0) || (Str == NULL)) {+    //+    // No data need to be written to Trace Hub+    //+    return EFI_ABORTED;+  }++  mipi_syst_write_debug_string (+    MipiSystHandle,+    MIPI_SYST_NOLOCATION,+    MIPI_SYST_STRING_GENERIC,+    Severity,+    Len,+    Str+    );++  return EFI_SUCCESS;+}++/**+  Invoke catalog_write_message function in Mipi Sys-T module.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Severity        An error level to decide whether to enable Trace Hub data.+  @param[in]  CatId           Catalog Id.++  @retval EFI_SUCCESS               Data in buffer was processed.+  @retval EFI_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.+**/+EFI_STATUS+EFIAPI+MipiSystWriteCatalog (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Severity,+  IN  UINT64            CatId+  )+{+  if (MipiSystHandle == NULL) {+    return EFI_INVALID_PARAMETER;+  }++  mipi_syst_write_catalog64_message (+    MipiSystHandle,+    MIPI_SYST_NOLOCATION,+    Severity,+    CatId+    );++  return EFI_SUCCESS;+}diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
new file mode 100644
index 0000000000..17ede382cc
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
@@ -0,0 +1,52 @@
+## @file+#  This library provides Mipi Sys-T API.+#+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>+#+#  SPDX-License-Identifier: BSD-2-Clause-Patent+#+##++[Defines]+  INF_VERSION                    = 0x00010005+  BASE_NAME                      = MipiSysTLib+  FILE_GUID                      = A58B0510-9E6D-4747-95D8-E5B8AF4633E6+  MODULE_TYPE                    = BASE+  VERSION_STRING                 = 1.0+  LIBRARY_CLASS                  = MipiSysTLib++  DEFINE MIPI_HEADER_PATH        = mipisyst/library/include/mipi_syst+  DEFINE MIPI_SOURCE_PATH        = mipisyst/library/src++#+# The following information is for reference only and not required by the build tools.+#+# VALID_ARCHITECTURES = IA32 X64+#++[LibraryClasses]+  IoLib+  BaseMemoryLib++[Packages]+  MdePkg/MdePkg.dec++[Sources]+  MipiSysTLib.c+  mipi_syst.h+  Platform.c+  Platform.h+  $(MIPI_HEADER_PATH)/api.h+  $(MIPI_HEADER_PATH)/crc32.h+  $(MIPI_HEADER_PATH)/compiler.h+  $(MIPI_HEADER_PATH)/message.h+  $(MIPI_HEADER_PATH)/inline.h+  $(MIPI_SOURCE_PATH)/mipi_syst_init.c+  $(MIPI_SOURCE_PATH)/mipi_syst_api.c+  $(MIPI_SOURCE_PATH)/mipi_syst_crc32.c+  $(MIPI_SOURCE_PATH)/mipi_syst_writer.c+  $(MIPI_SOURCE_PATH)/mipi_syst_inline.c+  $(MIPI_SOURCE_PATH)/mipi_syst_compiler.c++[BuildOptions]+  MSFT:*_*_*_CC_FLAGS = /Oddiff --git a/MdePkg/Library/MipiSysTLib/Platform.c b/MdePkg/Library/MipiSysTLib/Platform.c
new file mode 100644
index 0000000000..4079ccb1b8
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.c
@@ -0,0 +1,160 @@
+/** @file++Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>++SPDX-License-Identifier: BSD-2-Clause-Patent++**/++#include <Uefi.h>+#include <Library/IoLib.h>+#include <Library/BaseMemoryLib.h>+#include "mipi_syst.h"++/**+  Write 4 bytes to Trace Hub MMIO addr + 0x10.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD32Ts (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Data+  )+{+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x10, Data);+}++/**+  Write 4 bytes to Trace Hub MMIO addr + 0x18.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD32Mts (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Data+  )+{+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x18, Data);+}++/**+  Write 8 bytes to Trace Hub MMIO addr + 0x18.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD64Mts (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT64            Data+  )+{+  MmioWrite64 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x18, Data);+}++/**+  Write 1 byte to Trace Hub MMIO addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD8 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT8             Data+  )+{+  MmioWrite8 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);+}++/**+  Write 2 bytes to Trace Hub MMIO mmio addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD16 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT16            Data+  )+{+  MmioWrite16 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);+}++/**+  Write 4 bytes to Trace Hub MMIO addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD32 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Data+  )+{+  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);+}++/**+  Write 8 bytes to Trace Hub MMIO addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD64 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT64            Data+  )+{+  MmioWrite64 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x0, Data);+}++/**+  Clear data in Trace Hub MMIO addr + 0x30.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+**/+VOID+EFIAPI+MipiSystWriteFlag (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle+  )+{+  UINT32  Flag;++  Flag = 0;++  MmioWrite32 (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr + 0x30, Flag);+}++/**+  Get Epoch time.++  @retval UINT64    A numeric number for timestamp.+**/+UINT64+EFIAPI+MipiSystGetEpochUs (+  VOID+  )+{+  UINT64  Epoch;++  Epoch = 1000;++  return Epoch;+}diff --git a/MdePkg/Library/MipiSysTLib/Platform.h b/MdePkg/Library/MipiSysTLib/Platform.h
new file mode 100644
index 0000000000..b36ab6b84b
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.h
@@ -0,0 +1,140 @@
+/** @file++Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>++SPDX-License-Identifier: BSD-2-Clause-Patent++**/++#ifndef MIPI_SYST_PLATFORM_H_+#define MIPI_SYST_PLATFORM_H_++/**+  Write 4 bytes to Trace Hub MMIO addr + 0x10.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD32Ts (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Data+  );++/**+  Write 4 bytes to Trace Hub MMIO addr + 0x18.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD32Mts (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Data+  );++/**+  Write 8 bytes to Trace Hub MMIO addr + 0x18.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD64Mts (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT64            Data+  );++/**+  Write 1 byte to Trace Hub MMIO addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD8 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT8             Data+  );++/**+  Write 2 bytes to Trace Hub MMIO mmio addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD16 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT16            Data+  );++/**+  Write 4 bytes to Trace Hub MMIO addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD32 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT32            Data+  );++/**+  Write 8 bytes to Trace Hub MMIO addr + 0x0.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+  @param[in]  Data            Data to be written.+**/+VOID+EFIAPI+MipiSystWriteD64 (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,+  IN  UINT64            Data+  );++/**+  Clear data in Trace Hub MMIO addr + 0x30.++  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.+**/+VOID+EFIAPI+MipiSystWriteFlag (+  IN  MIPI_SYST_HANDLE  *MipiSystHandle+  );++/**+  Get Epoch time.++  @retval UINT64    A numeric number for timestamp.+**/+UINT64+EFIAPI+MipiSystGetEpochUs (+  VOID+  );++#define MIPI_SYST_PLATFORM_CLOCK()  MipiSystGetEpochUs ()++#ifndef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA+#define MIPI_SYST_OUTPUT_D32TS(MipiSystHandle, Data)   MipiSystWriteD32Ts ((MipiSystHandle), (Data))+#define MIPI_SYST_OUTPUT_D32MTS(MipiSystHandle, Data)  MipiSystWriteD32Mts ((MipiSystHandle), (Data))+#define MIPI_SYST_OUTPUT_D64MTS(MipiSystHandle, Data)  MipiSystWriteD64Mts ((MipiSystHandle), (Data))+#define MIPI_SYST_OUTPUT_D8(MipiSystHandle, Data)      MipiSystWriteD8 ((MipiSystHandle), (Data))+#define MIPI_SYST_OUTPUT_D16(MipiSystHandle, Data)     MipiSystWriteD16 ((MipiSystHandle), (Data))+#define MIPI_SYST_OUTPUT_D32(MipiSystHandle, Data)     MipiSystWriteD32 ((MipiSystHandle), (Data))+  #if defined (MIPI_SYST_PCFG_ENABLE_64BIT_IO)+#define MIPI_SYST_OUTPUT_D64(MipiSystHandle, Data)  MipiSystWriteD64 ((MipiSystHandle), (Data))+  #endif+#define MIPI_SYST_OUTPUT_FLAG(MipiSystHandle)  MipiSystWriteFlag ((MipiSystHandle))+#endif++#endif // MIPI_SYST_PLATFORM_H_diff --git a/MdePkg/Library/MipiSysTLib/mipi_syst.h b/MdePkg/Library/MipiSysTLib/mipi_syst.h
new file mode 100644
index 0000000000..29a1aa431b
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipi_syst.h
@@ -0,0 +1,539 @@
+/** @file++This header file is a customized version of mipi_syst.h.in in mipi module.++Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>++SPDX-License-Identifier: BSD-2-Clause-Patent++**/++#ifndef MIPI_SYST_H_INCLUDED+#define MIPI_SYST_H_INCLUDED++#include <Library/MipiSysTLib.h>++/* SyS-T API version information+ */+#define MIPI_SYST_VERSION_MAJOR  1   /**< Major version, incremented if API changes */+#define MIPI_SYST_VERSION_MINOR  0   /**< Minor version, incremented on compatible extensions */+#define MIPI_SYST_VERSION_PATCH  0   /**< Patch for existing major, minor, usually 0 */++/** Define SyS-T API conformance level+ *+ * 10 = minimal (only short events)+ * 20 = low overhead  (exluding varag functions and CRC32)+ * 30 = full implementation+ */+#define MIPI_SYST_CONFORMANCE_LEVEL  30++/** Compute SYS-T version value+ *+ * Used to compare SYS-T Major.Minor.patch versions numerically at runtime.+ *+ * @param ma major version number+ * @param mi minor version number+ * @param p patch version number+ *+ * Example:+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}+ *+ * #if  MIPI_SYST_VERSION_CODE >= MIPI_SYST_MAKE_VERSION_CODE(1,5,0)+ *     // do what only >= 1.5.x supports+ * #endif+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */+#define MIPI_SYST_MAKE_VERSION_CODE(ma, mi, p)  (((ma) << 16) | ((mi)<<8) | (p))++/** Numeric SYS-T version code */+#define MIPI_SYST_VERSION_CODE  MIPI_SYST_MAKE_VERSION_CODE(\+  MIPI_SYST_VERSION_MAJOR,\+  MIPI_SYST_VERSION_MINOR,\+  MIPI_SYST_VERSION_PATCH)++/* Macros to trick numeric values like __LINE__ into a string+ */+#define _MIPI_SYST_STRINGIFY(x)  #x+#define _MIPI_SYST_CPP_TOSTR(x)  _MIPI_SYST_STRINGIFY(x)++#define _MIPI_SYST_VERSION_STRING(a, b, c) \+        _MIPI_SYST_CPP_TOSTR(a)"."_MIPI_SYST_CPP_TOSTR(b)"."_MIPI_SYST_CPP_TOSTR(c)++/** Textual version string */+#define MIPI_SYST_VERSION_STRING \+        _MIPI_SYST_VERSION_STRING(\+                MIPI_SYST_VERSION_MAJOR,\+                MIPI_SYST_VERSION_MINOR,\+                MIPI_SYST_VERSION_PATCH)++#ifndef MIPI_SYST_COMPILER_INCLUDED+#define MIPI_SYST_STATIC+  #include "mipi_syst/compiler.h"+#endif++/* String hash macros for compile time computation of catalog ID's.+ * Notes:+ *    These macros will only be used with optimized builds, otherwise+ *    a lot of runtime code will be generated.+ *+ *    Only the last 64 bytes of the string are considered for hashing+ */+#define _MIPI_SYST_HASH1(s, i, x, l)   (x*65599u+(mipi_syst_u8)s[(i)<(l)?((l)-1-(i)):(l)])+#define _MIPI_SYST_HASH4(s, i, x, l)   _MIPI_SYST_HASH1(s,i,_MIPI_SYST_HASH1(s,i+1,_MIPI_SYST_HASH1(s,i+2,_MIPI_SYST_HASH1(s,i+3,x,l),l),l),l)+#define _MIPI_SYST_HASH16(s, i, x, l)  _MIPI_SYST_HASH4(s,i,_MIPI_SYST_HASH4(s,i+4,_MIPI_SYST_HASH4(s,i+8,_MIPI_SYST_HASH4(s,i+12,x,l),l),l),l)+#define _MIPI_SYST_HASH64(s, i, x, l)  _MIPI_SYST_HASH16(s,i,_MIPI_SYST_HASH16(s,i+16,_MIPI_SYST_HASH16(s,i+32,_MIPI_SYST_HASH16(s,i+48,x,l),l),l),l)++#define _MIPI_SYST_HASH_x65599(s, l)  ((mipi_syst_u32)_MIPI_SYST_HASH64(s,0,0,l))++#define _MIPI_SYST_HASH_AT_CPP_TIME(str, offset)  (_MIPI_SYST_HASH_x65599(str, sizeof(str)-1) + (offset))+#define _MIPI_SYST_HASH_AT_RUN_TIME(str, offset)  (mipi_syst_hash_x65599(str, sizeof(str)-1) + (offset))++#if defined (_MIPI_SYST_OPTIMIZER_ON)+#define MIPI_SYST_HASH(a, b)  _MIPI_SYST_HASH_AT_CPP_TIME((a), (b))+#else+#define MIPI_SYST_HASH(a, b)  _MIPI_SYST_HASH_AT_RUN_TIME((a), (b))+#endif++/** Major Message Types+ */+enum mipi_syst_msgtype {+  MIPI_SYST_TYPE_BUILD   = 0,        /**< client build id message   */+  MIPI_SYST_TYPE_SHORT32 = 1,        /**< value only message        */+  MIPI_SYST_TYPE_STRING  = 2,        /**< text message output       */+  MIPI_SYST_TYPE_CATALOG = 3,        /**< catalog message output    */+  MIPI_SYST_TYPE_RAW     = 6,        /**< raw binary data           */+  MIPI_SYST_TYPE_SHORT64 = 7,        /**<  value only message       */+  MIPI_SYST_TYPE_CLOCK   = 8,        /**< clock sync message        */++  MIPI_SYST_TYPE_MAX+};++/** MIPI_SYST_TYPE_DEBUG_STRING Sub-Types+ */+enum mipi_syst_subtype_string {+  MIPI_SYST_STRING_GENERIC       = 1,  /**< string generic debug         */+  MIPI_SYST_STRING_FUNCTIONENTER = 2,  /**< string is function name      */+  MIPI_SYST_STRING_FUNCTIONEXIT  = 3,  /**< string is function name      */+  MIPI_SYST_STRING_INVALIDPARAM  = 5,  /**< invalid SyS-T APIcall        */+  MIPI_SYST_STRING_ASSERT        = 7,  /**< Software Assert: failure     */+  MIPI_SYST_STRING_PRINTF_32     = 11, /**< printf with 32-bit packing   */+  MIPI_SYST_STRING_PRINTF_64     = 12, /**< printf with 64-bit packing   */++  MIPI_SYST_STRING_MAX+};++/** MIPI_SYST_TYPE_CATALOG Sub-Types+ */+enum mipi_syst_subtype_catalog {+  MIPI_SYST_CATALOG_ID32_P32 = 1,   /**< 32-bit catalog ID, 32-bit packing */+  MIPI_SYST_CATALOG_ID64_P32 = 2,   /**< 64-bit catalog ID, 32-bit packing */+  MIPI_SYST_CATALOG_ID32_P64 = 5,   /**< 32-bit catalog ID, 64-bit packing */+  MIPI_SYST_CATALOG_ID64_P64 = 6,   /**< 64-bit catalog ID, 64-bit packing */++  MIPI_SYST_CATALOG_MAX+};++/** MIPI_SYST_TYPE_CLOCK Sub-Types+ */+enum mipi_syst_subtype_clock {+  MIPI_SYST_CLOCK_TRANSPORT_SYNC = 1,  /**< SyS-T clock & frequency sync  */+  MIPI_SYST_CLOCK_MAX+};++enum mipi_syst_subtype_build {+  MIPI_SYST_BUILD_ID_COMPACT32 = 0, /**< compact32  build id       */+  MIPI_SYST_BUILD_ID_COMPACT64 = 1, /**< compact64  build id       */+  MIPI_SYST_BUILD_ID_LONG      = 2, /**< normal build  message     */+  MIPI_SYST_BUILD_MAX+};++/** GUID initializer code+ *+ * This macro simplifies converting a GUID from its string representation+ * into the mipi_syst_guid data structure. The following example shows+ * how the values from a GUID string are used with the macro. Each numeric+ * component from the GUID string gets converted into a hex value parameter+ * when invoking the macro.+ *+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}+ *+ *  // Guid: f614b99d-99a1-4c04-8c30-90999ab5fe05+ *+ *   struct mipi_syst_guid guid =+ *      MIPI_SYST_GEN_GUID(0xf614b99d, 0x99a1, 0x4c04, 0x8c30, 0x90999ab5fe05);+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ */+#define MIPI_SYST_GEN_GUID(l1, w1, w2, w3, l2) \+  {{\+          (mipi_syst_u8)((mipi_syst_u32)(l1) >> 24), \+          (mipi_syst_u8)((mipi_syst_u32)(l1) >> 16), \+          (mipi_syst_u8)((mipi_syst_u32)(l1) >>  8), \+          (mipi_syst_u8)((mipi_syst_u32)(l1) >>  0), \+          (mipi_syst_u8)((mipi_syst_u16)(w1) >>  8), \+          (mipi_syst_u8)((mipi_syst_u16)(w1) >>  0), \+          (mipi_syst_u8)((mipi_syst_u16)(w2) >>  8), \+          (mipi_syst_u8)((mipi_syst_u16)(w2) >>  0), \+          (mipi_syst_u8)((mipi_syst_u16)(w3) >>  8), \+          (mipi_syst_u8)((mipi_syst_u16)(w3) >>  0), \+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 40), \+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 32), \+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 24), \+          (mipi_syst_u8)((mipi_syst_u64)(l2) >> 16), \+          (mipi_syst_u8)((mipi_syst_u64)(l2) >>  8), \+          (mipi_syst_u8)((mipi_syst_u64)(l2) >>  0)  \+  }}++/** SyS-T client origin data+ *+ * This structure holds the GUID or header origin and unit data+ * used by SyS-T handles. The structure gets passed into the handle+ * creation functions to initialize the values that identify clients.+ * @see MIPI_SYST_SET_HANDLE_GUID_UNIT+ * @see MIPI_SYST_SET_HANDLE_MODULE_UNIT+ * @see MIPI_SYST_SET_HANDLE_ORIGIN+ */+struct mipi_syst_origin {+  struct mipi_syst_guid    guid;    /**< origin GUID or module value */+  mipi_syst_u16            unit;    /**< unit value                  */+};++/** Origin structure initializer code using GUID+*+* This macro simplifies initializing a mipi_syst_origin structure. The+* first 5 parameters are GUID values as used by the MIPI_SYST_GEN_GUID+* macro. The last parameter is the unit value (11-Bits).+* @see MIPI_SYST_GEN_GUID+*+*+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}+*+*  // Guid: {494E5443-B659-45AF-B786-9DB0786248AE}++*+*   struct mipi_syst_origin = origin+*      MIPI_SYST_GEN_ORIGIN_GUID(+*        0x494E5443, 0xB659, 0x45AF, 0xB786, 0x9DB0786248AE,+*        0x1);+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+*/+#define MIPI_SYST_GEN_ORIGIN_GUID(l1, w1, w2, w3, l2, u) \+        {\+                MIPI_SYST_GEN_GUID(l1, w1, w2, w3, l2) ,\+                u\+        }++/** Origin structure initializer code using header module value+*+* This macro simplifies initializing a mipi_syst_origin structure. The+* first parameter is the header origin value (7-Bits). The second parameter+* is the unit value (4-bits)+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}+*+*  // Guid: {494E5443-B659-45AF-B786-9DB0786248AE}++*   #define MODULE_X 0x10+*   struct mipi_syst_origin =+*      MIPI_SYST_GEN_ORIGIN_MODULE(MODULE_X, 0x1);+* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+*/+#define MIPI_SYST_GEN_ORIGIN_MODULE(m, u) \+        {\+                MIPI_SYST_GEN_GUID(0,0,0, ((mipi_syst_u16)(m & 0x7F)) << 8, 0 ),\+                u\+        }++/**+ * Global state initialization hook definition+ *+ * This function gets called in the context of the mipi_syst_init() API+ * function after the generic state members of the global state+ * structure syst_hdr have been setup. It's purpose is to initialize the+ * platform dependent portion of the state and other necessary+ * platform specific initialization steps.+ *+ * @param systh Pointer to global state structure+ * @param p user defined value or pointer to data+ * @see  mipi_syst_header+ */+typedef void (MIPI_SYST_CALLCONV *mipi_syst_inithook_t)(+  struct mipi_syst_header  *systh,+  const void               *p+  );++/**+ * Global state destroy hook definition+ *+ * This function gets called in the context of the mipi_syst_destroy() API+ * function before the generic state members of the global state+ * structure syst_hdr have been destroyed. Its purpose is to free resources+ * used by the platform dependent portion of the global state.+ *+ * @param systh Pointer to global state structure+ */+typedef void (MIPI_SYST_CALLCONV *mipi_syst_destroyhook_t)(+  struct mipi_syst_header  *systh+  );++#ifndef MIPI_SYST_PLATFORM_INCLUDED++/**+ * @defgroup PCFG_Config  Platform Feature Configuration Defines+ *+ * Defines to customize the SyS-T feature set to match the platform needs.+ *+ * Each optional library feature can be disabled by not defining the related+ * MIPI_SYST_PCFG_ENABLE define. Removing unused features in this way reduces+ * both memory footprint and runtime overhead of SyS-T.+ */++/**+ * @defgroup PCFG_Global Platform Wide Configuration+ * @ingroup  PCFG_Config+ *+ * These defines enable global features in the SyS-T library.+ * @{+ */++/**+ * Extend SyS-T handle data state+ *+ * This define extends the SyS-T handle state data structure+ * mipi_syst_handle with platform private content. A platform typically+ * stores data for fast trace hardware access in the handle data, for+ * example a volatile pointer to an MMIO space.+ *+ * The platform example uses #mipi_syst_platform_handle as handle state+ * extension.+ */+#define MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA++/* MSVC and GNU compiler 64-bit mode */++/**+ * Enable 64-bit instruction addresses+ *+ * Set this define if running in 64-bit code address space.+ */+  #if defined (_WIN64) || defined (__x86_64__) || defined (__LP64__)+#define MIPI_SYST_PCFG_ENABLE_64BIT_ADDR+  #endif++/**+ * Enable atomic 64-bit write operations+ *+ * Set this define if your platform supports an atomic 64-bit data write+ * operation. This results in fewer MMIO accesses.The SyS-T library+ * defaults to 2 consecutive 32-Bit writes otherwise.+ */+  #if defined (_WIN64) || defined (__x86_64__) || defined (__LP64__)+#define MIPI_SYST_PCFG_ENABLE_64BIT_IO+  #endif++/**+ * Enable helper function code inlining+ *+ * Set this define if speed is more important than code size on your platform.+ * It causes several helper function to get inlined, producing faster, but+ * also larger, code.+ */+#define MIPI_SYST_PCFG_ENABLE_INLINE++/** @} */++/**+ * @defgroup PCFG_ApiSet Supported API sets+ * @ingroup  PCFG_Config+ *+ * These defines enable API sets in the SyS-T library. They are set by default+ * depending on the SyS-T API conformance level. The level is specified using+ * the define #MIPI_SYST_CONFORMANCE_LEVEL.+ * @{+ */++  #if MIPI_SYST_CONFORMANCE_LEVEL > 10++/**+ * Use SyS-T scatter write output function+ *+ * The library comes with an output routine that is intended to write data out+ * to an MMIO space. It simplifies a SyS-T platform integration as+ * only low-level access macros must be provided for outputting data. These+ * macros follow MIPI System Trace Protocol (STP) naming convention, also+ * non STP generators can use this interface.+ *+ * These low level output macros are:+ *+ * #MIPI_SYST_OUTPUT_D32MTS, #MIPI_SYST_OUTPUT_D64MTS,+ * #MIPI_SYST_OUTPUT_D32TS, #MIPI_SYST_OUTPUT_D64,+ * #MIPI_SYST_OUTPUT_D32, #MIPI_SYST_OUTPUT_D16, #MIPI_SYST_OUTPUT_D8 and+ * #MIPI_SYST_OUTPUT_FLAG+ *+ * Note: This version of the write function always starts messages+ * using a 32-bit timestamped record also other sized timestamped+ * packets are allowed by the SyS-T specification.+ */+#define MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE++/**+ * Enable the Catalog API for 32-Bit Catalog IDs.+ */+#define MIPI_SYST_PCFG_ENABLE_CATID32_API++/**+ * Enable the Catalog API for 64-Bit Catalog IDs.+ */+#define MIPI_SYST_PCFG_ENABLE_CATID64_API++/**+ * Enable plain UTF-8 string output APIs.+ */+#define MIPI_SYST_PCFG_ENABLE_STRING_API++/**+ * Enable raw data output APIs+ */+#define MIPI_SYST_PCFG_ENABLE_WRITE_API++/**+ * Enable Build API+ */+#define MIPI_SYST_PCFG_ENABLE_BUILD_API+  #endif /* MIPI_SYST_CONFORMANCE_LEVEL > 10 */++  #if  MIPI_SYST_CONFORMANCE_LEVEL > 20++/**+ * Maximum size of printf payload in bytes.+ * Adjust this value if larger strings shall be supported by the library.+ * The buffer space is located in stack memory when calling one of the printf+ * style APIs.+ */+#define MIPI_SYST_PCFG_PRINTF_ARGBUF_SIZE  1024++  #endif /* #if MIPI_SYST_CONFORMANCE_LEVEL > 20 */++/* @} */++/**+ * @defgroup PCFG_Message Optional Message Attributes+ * @ingroup  PCFG_Config+ *+ * These defines enable optional message components. They are set by default+ * depending on the SyS-T API conformance level. The level is specified using+ * the define #MIPI_SYST_CONFORMANCE_LEVEL.+ * @{+ */++  #if MIPI_SYST_CONFORMANCE_LEVEL > 10++/**+ * Enable 128-bit origin GUID support.+ */+#define MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID++/**+ * Enable protocol timestamp.+ *+ * This option adds a timestamp into the SyS-T protocol. This+ * option is used if the SyS-T protocol is not embedded into a hardware+ * timestamped trace protocol like MIPI STP or if the HW timestamp cannot+ * be used for other reasons. Setting this option creates the need to define+ * the macros #MIPI_SYST_PLATFORM_CLOCK and #MIPI_SYST_PLATFORM_FREQ to+ *  return a 64-bit clock tick value and its frequency.+ */+#define MIPI_SYST_PCFG_ENABLE_TIMESTAMP++    #if defined (_DOXYGEN_)  /*  only for doxygen, remove the #if to enable */++/**+* Enable generation of length field+*+* Set this define if the message data shall include the optional length+* field that indicates how many payload bytes follow.+*/+#define MIPI_SYST_PCFG_LENGTH_FIELD+    #endif++  #endif++  #if MIPI_SYST_CONFORMANCE_LEVEL > 20++/**+ * Enable message data CRC32 generation.+ */+#define MIPI_SYST_PCFG_ENABLE_CHECKSUM++  #endif /* #if MIPI_SYST_CONFORMANCE_LEVEL */++/** @} */++  #include "Platform.h"+#endif++#if defined (MIPI_SYST_PCFG_ENABLE_INLINE)+#define MIPI_SYST_INLINE  static MIPI_SYST_CC_INLINE+#else+#define MIPI_SYST_INLINE  MIPI_SYST_EXPORT+#endif++#define _MIPI_SYST_MK_MODUNIT_ORIGIN(m, u)  (((u) & 0xF)|(m<<4))++/**+ * Location information inside a message (64-bit format)+ * Location is either the source position of the instrumentation call, or+ * the call instruction pointer value.+ */+union mipi_syst_msglocation32 {+  struct {+ #if defined (MIPI_SYST_BIG_ENDIAN)+    mipi_syst_u16    etls_lineNo; /**< line number in file       */+    mipi_syst_u16    etls_fileID; /**< ID of instrumented file   */+ #else+    mipi_syst_u16    etls_fileID; /**< ID of instrumented file   */+    mipi_syst_u16    etls_lineNo; /**< line number in file       */+ #endif+  } etls_source_location;++  mipi_syst_u32    etls_code_location : 32; /**< instruction pointer value */+};++/**+ * Location information inside a message (32-bit format)+ * Location is either the source position of the instrumentation call, or+ * the call instruction pointer value.+ */+union mipi_syst_msglocation64 {+  struct {+ #if defined (MIPI_SYST_BIG_ENDIAN)+    mipi_syst_u32    etls_lineNo; /**< line number in file       */+    mipi_syst_u32    etls_fileID; /**< ID of instrumented file   */+ #else+    mipi_syst_u32    etls_fileID; /**< ID of instrumented file   */+    mipi_syst_u32    etls_lineNo; /**< line number in file       */+ #endif+  } etls_source_location;+  mipi_syst_u64    etls_code_location; /**< instruction pointer value */+};++/**+ * Location information record descriptor+ */+struct mipi_syst_msglocation {+  /** Message format+   * 0 = 16-Bit file and 16-Bit line (total: 32-bit)+   * 1 = 32-Bit file and 32-Bit line (total: 64-bit)+   * 2 = 32-bit code address+   * 3 = 64-bit code address+   */+  mipi_syst_u8    el_format;+  union {+    union mipi_syst_msglocation32    loc32; /**< data for 32-bit variant  */+    union mipi_syst_msglocation64    loc64; /**< data for 64-bit variant  */+  } el_u;+};++#ifndef MIPI_SYST_API_INCLUDED+  #include "mipi_syst/api.h"+#endif++#endifdiff --git a/MdePkg/Library/MipiSysTLib/mipisyst b/MdePkg/Library/MipiSysTLib/mipisyst
new file mode 160000
index 0000000000..aae857d0d0
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipisyst
@@ -0,0 +1 @@
+Subproject commit aae857d0d05ac65152ed24992a4acd834a0a107c
diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml index 19bc0138cb..590cb85fd5 100644
--- a/MdePkg/MdePkg.ci.yaml
+++ b/MdePkg/MdePkg.ci.yaml
@@ -64,8 +64,10 @@
             "Include/IndustryStandard/UefiTcgPlatform.h",             "Include/Library/PcdLib.h",             "Include/Library/SafeIntLib.h",+            "Include/Library/MipiSysTLib.h",             "Include/Protocol/DebugSupport.h",-            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c"+            "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",+            "Library/MipiSysTLib/mipi_syst.h"         ]     },     ## options defined ci/Plugin/CompilerPlugindiff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 3d08f20d15..bee7ac538a 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -26,6 +26,7 @@
 [Includes]   Include   Test/UnitTest/Include+  Library/MipiSysTLib/mipisyst/library/include  [Includes.IA32]   Include/Ia32@@ -284,6 +285,10 @@
   #   ArmTrngLib|Include/Library/ArmTrngLib.h +  ##  @libraryclass  Provides general mipi sys-T services.+  #+  MipiSysTLib|Include/Library/MipiSysTLib.h+ [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]   ##  @libraryclass  Provides services to generate random number.   #diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 32a852dc46..cbcf4a6047 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -34,6 +34,7 @@
  [LibraryClasses]   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf+  MipiSysTLib|MdePkg/Library/MipiSysTLib/MipiSysTLib.inf  [Components]   MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf@@ -135,6 +136,7 @@
   MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf   MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf   MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf+  MdePkg/Library/MipiSysTLib/MipiSysTLib.inf  [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]   #diff --git a/ReadMe.rst b/ReadMe.rst
index 497d963559..283f807ab5 100644
--- a/ReadMe.rst
+++ b/ReadMe.rst
@@ -95,6 +95,7 @@ that are covered by additional licenses.
 -  `UnitTestFrameworkPkg/Library/CmockaLib/cmocka <https://github.com/tianocore/edk2-cmocka/blob/f5e2cd77c88d9f792562888d2b70c5a396bfbf7a/COPYING>`__ -  `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__ -  `RedfishPkg/Library/JsonLib/jansson <https://github.com/akheron/jansson/blob/2882ead5bb90cf12a01b07b2c2361e24960fae02/LICENSE>`__+-  `MdePkg/Library/MipiSysTLib/mipisyst <https://github.com/MIPI-Alliance/public-mipi-sys-t/blob/aae857d0d05ac65152ed24992a4acd834a0a107c/LICENSE>`__  The EDK II Project is composed of packages. The maintainers for each package are listed in `Maintainers.txt <Maintainers.txt>`__.--
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library
  2023-01-31  2:49 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library victorx.hsu
@ 2023-01-31  3:17   ` Guo, Gua
  0 siblings, 0 replies; 8+ messages in thread
From: Guo, Gua @ 2023-01-31  3:17 UTC (permalink / raw)
  To: Hsu, VictorX, devel@edk2.groups.io
  Cc: Kinney, Michael D, Chan, Laura,
	Prakashan, Krishnadas Veliyathuparambil, K N, Karthik

Reviewed-by: Gua Guo <gua.guo@intel.com>

-----Original Message-----
From: Hsu, VictorX <victorx.hsu@intel.com> 
Sent: Tuesday, January 31, 2023 10:49 AM
To: devel@edk2.groups.io
Cc: Hsu, VictorX <victorx.hsu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Guo, Gua <gua.guo@intel.com>; Chan, Laura <laura.chan@intel.com>; Prakashan, Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>; K N, Karthik <karthik.k.n@intel.com>
Subject: [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library

From: VictorX Hsu <victorx.hsu@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144

This Library provide Trace Hub API which consume MipiSysTLib.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 .../UniversalPayload/TraceHubDebugInfo.h      |  31 ++
 .../BaseTraceHubDebugLibSyst.inf              |  44 ++
 .../BaseTraceHubDebugSystLib.c                | 386 +++++++++++++++
 .../DxeSmmTraceHubDebugLibSyst.inf            |  49 ++
 .../DxeSmmTraceHubDebugSystLib.c              | 462 ++++++++++++++++++
 .../PeiTraceHubDebugLibSyst.inf               |  49 ++
 .../PeiTraceHubDebugSystLib.c                 | 446 +++++++++++++++++
 .../TraceHubDebugLibSysT/TraceHubApiCommon.c  |  81 +++
 .../TraceHubDebugLibSysT/TraceHubApiCommon.h  |  64 +++
 .../TraceHubApiInternal.h                     |  92 ++++
 MdeModulePkg/MdeModulePkg.dec                 |  21 +
 MdeModulePkg/MdeModulePkg.dsc                 |   6 +
 MdeModulePkg/MdeModulePkg.uni                 |  18 +
 13 files changed, 1749 insertions(+)
 create mode 100644 MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h

diff --git a/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h b/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h
new file mode 100644
index 0000000000..6c95a85451
--- /dev/null
+++ b/MdeModulePkg/Include/UniversalPayload/TraceHubDebugInfo.h
@@ -0,0 +1,31 @@
+/** @file

+ Define the structure for the Universal Payload TraceHub Debug Info.

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+  @par Revision Reference:

+    - Universal Payload Specification 0.9 (https://universalpayload.github.io/documentation/)

+**/

+

+#ifndef UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_

+#define UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_

+

+#include <UniversalPayload/UniversalPayload.h>

+

+typedef struct {

+  BOOLEAN    Flag;         // Flag to enable or disable Trace Hub debug message.

+  UINT8      DebugLevel;   // Debug level for Trace Hub.

+  UINTN      TraceAddress; // MMIO address where Trace Hub debug message output to.

+} TRACEHUB_DEBUG_CONTEXT;

+

+typedef struct {

+  UNIVERSAL_PAYLOAD_GENERIC_HEADER    Header;

+  TRACEHUB_DEBUG_CONTEXT              DebugContext;

+} UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO;

+

+#define UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_REVISION  1

+

+extern EFI_GUID  gUniversalPayloadTraceHubDebugInfoGuid;

+

+#endif // UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO_H_

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf
new file mode 100644
index 0000000000..96ecf9147a
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.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 settings.

+#

+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = BaseTraceHubDebugLibSyst

+  FILE_GUID                      = 336DA571-AD65-423C-9A43-E0056E5B2D8D

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = TraceHubDebugLib

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+# VALID_ARCHITECTURES = IA32 X64

+#

+

+[LibraryClasses]

+  BaseLib

+  PcdLib

+  BaseMemoryLib

+  MipiSysTLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+

+[Sources]

+  BaseTraceHubDebugSystLib.c

+  TraceHubApiCommon.c

+  TraceHubApiCommon.h

+  TraceHubApiInternal.h

+

+[Pcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel

+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c
new file mode 100644
index 0000000000..b0e99c69a3
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugSystLib.c
@@ -0,0 +1,386 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Uefi.h>

+#include <Library/BaseLib.h>

+#include <Library/PcdLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/TraceHubDebugLib.h>

+#include <Library/MipiSysTLib.h>

+#include "TraceHubApiCommon.h"

+#include "TraceHubApiInternal.h"

+

+/**

+  Write debug string to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Buffer           A pointer to the data buffer.

+  @param[in]  NumberOfBytes    Number of bytes to be written.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubDebugWrite (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT8                    *Buffer,

+  IN UINTN                    NumberOfBytes

+  )

+{

+  MIPI_SYST_HANDLE  MipiSystHandle;

+  MIPI_SYST_HEADER  MipiSystHeader;

+  EFI_STATUS        Status;

+  UINT32            DbgInstCount;

+  UINT16            Index;

+

+  DbgInstCount = 0;

+

+  if ((NumberOfBytes == 0) || (Buffer == NULL)) {

+    //

+    // No data need to be written to Trace Hub

+    //

+    return EFI_ABORTED;

+  }

+

+  Status = MigrateTraceHubHobData ();

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               NULL,

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubDebugType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteDebug (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 (UINT16)NumberOfBytes,

+                 (CHAR8 *)Buffer

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Write catalog status code message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id               Catalog ID.

+  @param[in]  Guid             Driver Guid.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64StatusCode (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN EFI_GUID                 *Guid

+  )

+{

+  MIPI_SYST_HANDLE  MipiSystHandle;

+  MIPI_SYST_HEADER  MipiSystHeader;

+  EFI_STATUS        Status;

+  UINT32            DbgInstCount;

+  UINT16            Index;

+

+  DbgInstCount = 0;

+

+  if (Guid == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = MigrateTraceHubHobData ();

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  //

+  // Convert little endian to big endian.

+  //

+  Status = LittleEndianToBigEndian (Guid);

+  CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID));

+  MipiSystHandle.systh_tag.et_guid = 1;

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               NULL,

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubCatalogType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteCatalog (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 Id

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Write catalog message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id             Catalog ID.

+  @param[in]  NumberOfParams Number of parameters in argument list.

+  @param[in]  ...            Argument list that pass to Trace Hub.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64 (

+  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;

+  EFI_STATUS        Status;

+  UINT32            DbgInstCount;

+

+  DbgInstCount = 0;

+

+  if (NumberOfParams > 6) {

+    //

+    // Message with more than 6 parameter is illegal.

+    //

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = MigrateTraceHubHobData ();

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;

+  VA_START (Args, NumberOfParams);

+  for (Index = 0; Index < NumberOfParams; Index++) {

+    MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);

+  }

+

+  VA_END (Args);

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               NULL,

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubCatalogType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteCatalog (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 Id

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Get Trace Hub MMIO Address.

+

+  @param[in]      DgbContext        Always NULL.

+  @param[in, out] TraceAddress      Trace Hub MMIO Address.

+

+  @retval EFI_SUCCESS               Get MMIO address successfully.

+  @retval EFI_INVALID_PARAMETER     TraceAddress is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMmioAddress (

+  IN     UINT8  *DgbContext,

+  IN OUT UINTN  *TraceAddress

+  )

+{

+  if (TraceAddress == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugAddress);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Get visibility of Trace Hub Msg.

+

+  @param[in]      DgbContext      Always NULL.

+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.

+  @param[in, out] DbgLevel        Debug Level of Trace Hub.

+

+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.

+  @retval EFI_INVALID_PARAMETER   On entry, Flag or DbgLevel is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMsgVisibility (

+  IN     UINT8    *DgbContext,

+  IN OUT BOOLEAN  *Flag,

+  IN OUT UINT8    *DbgLevel

+  )

+{

+  if ((DbgLevel == NULL) || (Flag == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);

+  *Flag     = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Collect the number of available Trace Hub debug instance.

+

+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.

+

+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.

+  @retval Other            Failed to collect the number of available Trace Hub debug instance.

+**/

+STATIC

+EFI_STATUS

+CountDebugInstance (

+  IN OUT UINT32  *DbgInstCount

+  )

+{

+  if (DbgInstCount == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  //

+  // 1 for fixed PCD.

+  //

+  *DbgInstCount = 1;

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Allocate boot time pool memory to store Trace Hub HOB data.

+

+  @retval  EFI_SUCCESS   Migration process is successful.

+  @retval  Other         Migration process is unsuccessful

+**/

+STATIC

+EFI_STATUS

+MigrateTraceHubHobData (

+  VOID

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Check whether to output Tracr Hub message.

+

+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.

+  @param[in, out]  DgbContext       Always NULL.

+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]       PrintType        Either catalog print or debug print.

+

+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.

+  @retval Other            Current Trace Hub message no need to be processed.

+**/

+STATIC

+EFI_STATUS

+CheckWhetherToOutputMsg (

+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,

+  IN OUT UINT8                    *DgbContext,

+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN     TRACEHUB_PRINTTYPE       PrintType

+  )

+{

+  EFI_STATUS  Status;

+  UINTN       Addr;

+  UINT8       DbgLevel;

+  BOOLEAN     Flag;

+

+  if (MipiSystHandle == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (PrintType == TraceHubDebugType) {

+    Status = GetTraceHubMsgVisibility (NULL, &Flag, &DbgLevel);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) {

+      return EFI_ABORTED;

+    }

+  }

+

+  Status = GetTraceHubMmioAddress (NULL, &Addr);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;

+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {

+    return EFI_ABORTED;

+  }

+

+  return EFI_SUCCESS;

+}

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
new file mode 100644
index 0000000000..d5bc316083
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf
@@ -0,0 +1,49 @@
+## @file

+#  Debug library to output Trace Hub message.

+#  Support DXE/SMM phase TraceHub debug message based on dynamic settings.

+#

+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = DxeSmmTraceHubDebugLibSyst

+  FILE_GUID                      = A9B7B825-7902-4616-8556-085DA4DFEC72

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = TraceHubDebugLib|DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER DXE_DRIVER DXE_CORE UEFI_DRIVER UEFI_APPLICATION

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+# VALID_ARCHITECTURES = IA32 X64

+#

+

+[LibraryClasses]

+  BaseLib

+  PcdLib

+  HobLib

+  BaseMemoryLib

+  MemoryAllocationLib

+  MipiSysTLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+

+[Sources]

+  DxeSmmTraceHubDebugSystLib.c

+  TraceHubApiCommon.c

+  TraceHubApiCommon.h

+  TraceHubApiInternal.h

+

+[Guids]

+  gUniversalPayloadTraceHubDebugInfoGuid

+

+[Pcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel

+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c
new file mode 100644
index 0000000000..d81abd2c97
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugSystLib.c
@@ -0,0 +1,462 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Uefi.h>

+#include <Library/BaseLib.h>

+#include <Library/PcdLib.h>

+#include <Library/HobLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/TraceHubDebugLib.h>

+#include <Library/MipiSysTLib.h>

+#include <UniversalPayload/TraceHubDebugInfo.h>

+#include "TraceHubApiCommon.h"

+#include "TraceHubApiInternal.h"

+

+GLOBAL_REMOVE_IF_UNREFERENCED UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *mThDebugInstArray = NULL;

+GLOBAL_REMOVE_IF_UNREFERENCED UINT32                                 mDbgInstCount      = 0;

+

+/**

+  Write debug string to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Buffer           A pointer to the data buffer.

+  @param[in]  NumberOfBytes    Number of bytes to be written.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubDebugWrite (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT8                    *Buffer,

+  IN UINTN                    NumberOfBytes

+  )

+{

+  MIPI_SYST_HANDLE  MipiSystHandle;

+  MIPI_SYST_HEADER  MipiSystHeader;

+  EFI_STATUS        Status;

+  UINT16            Index;

+  UINT32            DbgInstCount;

+

+  DbgInstCount = 0;

+

+  if ((NumberOfBytes == 0) || (Buffer == NULL)) {

+    //

+    // No data need to be written to Trace Hub

+    //

+    return EFI_ABORTED;

+  }

+

+  Status = MigrateTraceHubHobData ();

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               (UINT8 *)&mThDebugInstArray[Index],

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubDebugType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteDebug (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 (UINT16)NumberOfBytes,

+                 (CHAR8 *)Buffer

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Write catalog status code message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id               Catalog ID.

+  @param[in]  Guid             Driver Guid.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64StatusCode (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN EFI_GUID                 *Guid

+  )

+{

+  MIPI_SYST_HANDLE  MipiSystHandle;

+  MIPI_SYST_HEADER  MipiSystHeader;

+  UINTN             Index;

+  EFI_STATUS        Status;

+  UINT32            DbgInstCount;

+

+  DbgInstCount = 0;

+

+  Status = MigrateTraceHubHobData ();

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  if (Guid != NULL) {

+    //

+    // Convert little endian to big endian.

+    //

+    Status = LittleEndianToBigEndian (Guid);

+    CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID));

+    MipiSystHandle.systh_tag.et_guid = 1;

+  } else {

+    MipiSystHandle.systh_tag.et_modunit = 2;

+    MipiSystHandle.systh_tag.et_guid    = 0;

+  }

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               (UINT8 *)&mThDebugInstArray[Index],

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubCatalogType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteCatalog (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 Id

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Write catalog message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id             Catalog ID.

+  @param[in]  NumberOfParams Number of parameters in argument list.

+  @param[in]  ...            Argument list that pass to Trace Hub.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64 (

+  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;

+  EFI_STATUS        Status;

+  UINT32            DbgInstCount;

+

+  DbgInstCount = 0;

+

+  if (NumberOfParams > 6) {

+    //

+    // Message with more than 6 parameter is illegal.

+    //

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = MigrateTraceHubHobData ();

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;

+  VA_START (Args, NumberOfParams);

+  for (Index = 0; Index < NumberOfParams; Index++) {

+    MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);

+  }

+

+  VA_END (Args);

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               (UINT8 *)&mThDebugInstArray[Index],

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubCatalogType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteCatalog (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 Id

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Collect the number of available Trace Hub debug instance.

+

+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.

+

+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.

+  @retval Other            Failed to collect the number of available Trace Hub debug instance.

+**/

+STATIC

+EFI_STATUS

+CountDebugInstance (

+  IN OUT UINT32  *DbgInstCount

+  )

+{

+  UINT8  *DgbContext;

+

+  if (DbgInstCount == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (mThDebugInstArray == NULL) {

+    DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);

+    if (DgbContext != NULL) {

+      while (DgbContext != NULL) {

+        (*DbgInstCount)++;

+        DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));

+      }

+    } else {

+      //

+      // Trace Hub debug instance for PCD

+      //

+      (*DbgInstCount)++;

+    }

+  } else {

+    *DbgInstCount = mDbgInstCount;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Check whether to output Tracr Hub message.

+

+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.

+  @param[in, out]  DgbContext       A pointer to Trace Hub debug instance.

+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]       PrintType        Either catalog print or debug print.

+

+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.

+  @retval Other            Current Trace Hub message no need to be processed.

+**/

+STATIC

+EFI_STATUS

+CheckWhetherToOutputMsg (

+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,

+  IN OUT UINT8                    *DgbContext,

+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN     TRACEHUB_PRINTTYPE       PrintType

+  )

+{

+  UINT8       DbgLevel;

+  BOOLEAN     Flag;

+  UINTN       Addr;

+  EFI_STATUS  Status;

+

+  if ((MipiSystHandle == NULL) || (DgbContext == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (PrintType == TraceHubDebugType) {

+    Status = GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) {

+      return EFI_ABORTED;

+    }

+  }

+

+  Status = GetTraceHubMmioAddress (DgbContext, &Addr);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;

+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {

+    return EFI_ABORTED;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Get Trace Hub MMIO Address.

+

+  @param[in]      DgbContext        A pointer to Trace Hub debug instance.

+  @param[in, out] TraceAddress      Trace Hub MMIO Address.

+

+  @retval EFI_SUCCESS               Get MMIO address successfully.

+  @retval EFI_INVALID_PARAMETER     TraceAddress or DgbContext is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMmioAddress (

+  IN     UINT8  *DgbContext,

+  IN OUT UINTN  *TraceAddress

+  )

+{

+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDbgContext;

+

+  if ((DgbContext == NULL) || (TraceAddress == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  ThDbgContext  = (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *)DgbContext;

+  *TraceAddress = ThDbgContext->DebugContext.TraceAddress;

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Get visibility of Trace Hub Msg.

+

+  @param[in]      DgbContext      A pointer to Trace Hub debug instance.

+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.

+  @param[in, out] DbgLevel        Debug Level of Trace Hub.

+

+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.

+  @retval EFI_INVALID_PARAMETER   On entry, DgbContext or Flag or DbgLevel is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMsgVisibility (

+  IN     UINT8    *DgbContext,

+  IN OUT BOOLEAN  *Flag,

+  IN OUT UINT8    *DbgLevel

+  )

+{

+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDbgContext;

+

+  if ((DgbContext == NULL) || (Flag == NULL) || (DbgLevel == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  ThDbgContext = (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO *)DgbContext;

+  *Flag        = ThDbgContext->DebugContext.Flag;

+  *DbgLevel    = ThDbgContext->DebugContext.DebugLevel;

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Allocate boot time pool memory to store Trace Hub HOB data.

+

+  @retval  EFI_SUCCESS   Migration process is successful.

+  @retval  Other         Migration process is unsuccessful

+**/

+STATIC

+EFI_STATUS

+MigrateTraceHubHobData (

+  VOID

+  )

+{

+  UINT8       *DgbContext;

+  UINT16      Index;

+  UINT32      DbgInstCount;

+  EFI_STATUS  Status;

+

+  Index        = 0;

+  DgbContext   = NULL;

+  DbgInstCount = 0;

+

+  if (mThDebugInstArray == NULL) {

+    Status = CountDebugInstance (&DbgInstCount);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    mDbgInstCount = DbgInstCount;

+    if (mDbgInstCount != 0) {

+      mThDebugInstArray = AllocateZeroPool (sizeof (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO) * mDbgInstCount);

+      if (mThDebugInstArray == NULL) {

+        return EFI_OUT_OF_RESOURCES;

+      }

+

+      DgbContext = GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);

+      if (DgbContext != NULL) {

+        for (Index = 0; Index < mDbgInstCount; Index++) {

+          CopyMem (&mThDebugInstArray[Index], GET_GUID_HOB_DATA (DgbContext), sizeof (UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO));

+          DgbContext = GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));

+        }

+      } else {

+        for (Index = 0; Index < mDbgInstCount; Index++) {

+          mThDebugInstArray[Index].DebugContext.TraceAddress = FixedPcdGet64 (PcdTraceHubDebugAddress);

+          mThDebugInstArray[Index].DebugContext.Flag         = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);

+          mThDebugInstArray[Index].DebugContext.DebugLevel   = FixedPcdGet8 (PcdTraceHubDebugLevel);

+        }

+      }

+    } else {

+      return EFI_ABORTED;

+    }

+  }

+

+  return EFI_SUCCESS;

+}

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
new file mode 100644
index 0000000000..4f4bfb695b
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf
@@ -0,0 +1,49 @@
+## @file

+#  Debug library to output Trace Hub message.

+#  Support PEI phase TraceHub debug message based on dynamic settings

+#

+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = PeiTraceHubDebugLibSyst

+  FILE_GUID                      = C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1

+  MODULE_TYPE                    = PEIM

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = TraceHubDebugLib|PEI_CORE PEIM

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+# VALID_ARCHITECTURES = IA32 X64

+#

+

+[LibraryClasses]

+  BaseLib

+  PcdLib

+  HobLib

+  BaseMemoryLib

+  MemoryAllocationLib

+  MipiSysTLib

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+

+[Sources]

+  PeiTraceHubDebugSystLib.c

+  TraceHubApiCommon.c

+  TraceHubApiCommon.h

+  TraceHubApiInternal.h

+

+[Guids]

+  gUniversalPayloadTraceHubDebugInfoGuid

+

+[Pcd]

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel

+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c
new file mode 100644
index 0000000000..10bde71fd3
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugSystLib.c
@@ -0,0 +1,446 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Uefi.h>

+#include <Library/BaseLib.h>

+#include <Library/PcdLib.h>

+#include <Library/HobLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+#include <Library/TraceHubDebugLib.h>

+#include <Library/MipiSysTLib.h>

+#include <UniversalPayload/TraceHubDebugInfo.h>

+#include "TraceHubApiCommon.h"

+#include "TraceHubApiInternal.h"

+

+/**

+  Write debug string to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Buffer           A pointer to the data buffer.

+  @param[in]  NumberOfBytes    Number of bytes to be written.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubDebugWrite (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT8                    *Buffer,

+  IN UINTN                    NumberOfBytes

+  )

+{

+  MIPI_SYST_HANDLE  MipiSystHandle;

+  MIPI_SYST_HEADER  MipiSystHeader;

+  EFI_STATUS        Status;

+  UINT8             *DgbContext;

+  UINTN             Index;

+  UINT32            DbgInstCount;

+

+  DbgInstCount = 0;

+

+  if ((NumberOfBytes == 0) || (Buffer == NULL)) {

+    //

+    // No data need to be written to Trace Hub

+    //

+    return EFI_ABORTED;

+  }

+

+  Status = MigrateTraceHubHobData ();

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               DgbContext,

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubDebugType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteDebug (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 (UINT16)NumberOfBytes,

+                 (CHAR8 *)Buffer

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+

+    if (DgbContext != NULL) {

+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));

+      if (DgbContext == NULL) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Write catalog status code message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id               Catalog ID.

+  @param[in]  Guid             Driver Guid.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64StatusCode (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN EFI_GUID                 *Guid

+  )

+{

+  MIPI_SYST_HANDLE  MipiSystHandle;

+  MIPI_SYST_HEADER  MipiSystHeader;

+  UINT32            DbgInstCount;

+  UINT8             *DgbContext;

+  EFI_STATUS        Status;

+  UINTN             Index;

+

+  DbgInstCount = 0;

+

+  Status = MigrateTraceHubHobData ();

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  if (Guid != NULL) {

+    //

+    // Convert little endian to big endian.

+    //

+    Status = LittleEndianToBigEndian (Guid);

+    CopyMem (&MipiSystHandle.systh_guid, Guid, sizeof (EFI_GUID));

+    MipiSystHandle.systh_tag.et_guid = 1;

+  } else {

+    MipiSystHandle.systh_tag.et_modunit = 2;

+    MipiSystHandle.systh_tag.et_guid    = 0;

+  }

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               DgbContext,

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubCatalogType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteCatalog (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 Id

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+

+    if (DgbContext != NULL) {

+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));

+      if (DgbContext == NULL) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Write catalog message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id             Catalog ID.

+  @param[in]  NumberOfParams Number of parameters in argument list.

+  @param[in]  ...            Argument list that pass to Trace Hub.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64 (

+  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             *DgbContext;

+  EFI_STATUS        Status;

+

+  DbgInstCount = 0;

+

+  if (NumberOfParams > 6) {

+    //

+    // Message with more than 6 parameter is illegal.

+    //

+    return EFI_INVALID_PARAMETER;

+  }

+

+  Status = MigrateTraceHubHobData ();

+

+  MipiSystHandle.systh_header = &MipiSystHeader;

+

+  Status = InitMipiSystHandle (&MipiSystHandle);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;

+  VA_START (Args, NumberOfParams);

+  for (Index = 0; Index < NumberOfParams; Index++) {

+    MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);

+  }

+

+  VA_END (Args);

+

+  Status = CountDebugInstance (&DbgInstCount);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);

+  for (Index = 0; Index < DbgInstCount; Index++) {

+    Status = CheckWhetherToOutputMsg (

+               &MipiSystHandle,

+               DgbContext,

+               (MIPI_SYST_SEVERITY)SeverityType,

+               TraceHubCatalogType

+               );

+    if (!EFI_ERROR (Status)) {

+      Status = MipiSystWriteCatalog (

+                 &MipiSystHandle,

+                 (MIPI_SYST_SEVERITY)SeverityType,

+                 Id

+                 );

+      if (EFI_ERROR (Status)) {

+        break;

+      }

+    }

+

+    if (DgbContext != NULL) {

+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));

+      if (DgbContext == NULL) {

+        break;

+      }

+    }

+  }

+

+  return Status;

+}

+

+/**

+  Collect the number of available Trace Hub debug instance.

+

+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.

+

+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.

+  @retval Other            Failed to collect the number of available Trace Hub debug instance.

+**/

+STATIC

+EFI_STATUS

+CountDebugInstance (

+  IN OUT UINT32  *DbgInstCount

+  )

+{

+  UINT8  *DgbContext;

+

+  if (DbgInstCount == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  DgbContext = (UINT8 *)GetFirstGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid);

+  if (DgbContext != NULL) {

+    while (DgbContext != NULL) {

+      (*DbgInstCount)++;

+      DgbContext = (UINT8 *)GetNextGuidHob (&gUniversalPayloadTraceHubDebugInfoGuid, GET_NEXT_HOB (DgbContext));

+    }

+  } else {

+    //

+    // Trace Hub debug instance for PCD

+    //

+    (*DbgInstCount)++;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Check whether to output Tracr Hub message.

+

+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.

+  @param[in, out]  DgbContext       A pointer to Trace Hub debug instance. NULL is acceptable.

+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]       PrintType        Either catalog print or debug print.

+

+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.

+  @retval Other            Current Trace Hub message no need to be processed.

+**/

+STATIC

+EFI_STATUS

+CheckWhetherToOutputMsg (

+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,

+  IN OUT UINT8                    *DgbContext,

+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN     TRACEHUB_PRINTTYPE       PrintType

+  )

+{

+  EFI_STATUS  Status;

+  UINTN       Addr;

+  UINT8       DbgLevel;

+  BOOLEAN     Flag;

+

+  if (MipiSystHandle == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (PrintType == TraceHubDebugType) {

+    Status = GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel);

+    if (EFI_ERROR (Status)) {

+      return Status;

+    }

+

+    if (!EnableTraceHubData (Flag, DbgLevel, SeverityType)) {

+      return EFI_ABORTED;

+    }

+  }

+

+  Status = GetTraceHubMmioAddress (DgbContext, &Addr);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;

+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {

+    return EFI_ABORTED;

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Get Trace Hub MMIO Address.

+

+  @param[in]      DgbContext        A pointer to Trace Hub debug instance. NULL is acceptable.

+  @param[in, out] TraceAddress      Trace Hub MMIO Address.

+

+  @retval EFI_SUCCESS               Get MMIO address successfully.

+  @retval EFI_INVALID_PARAMETER     TraceAddress is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMmioAddress (

+  IN     UINT8  *DgbContext,

+  IN OUT UINTN  *TraceAddress

+  )

+{

+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDebugInfo;

+

+  ThDebugInfo = NULL;

+

+  if (TraceAddress == NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (DgbContext != NULL) {

+    ThDebugInfo   = GET_GUID_HOB_DATA (DgbContext);

+    *TraceAddress = ThDebugInfo->DebugContext.TraceAddress;

+  } else {

+    *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugAddress);

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Get visibility of Trace Hub Msg.

+

+  @param[in]      DgbContext      A pointer to Trace Hub debug instance. NULL is acceptable.

+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.

+  @param[in, out] DbgLevel        Debug Level of Trace Hub.

+

+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.

+  @retval EFI_INVALID_PARAMETER   On entry, Flag or DbgLevel is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMsgVisibility (

+  IN     UINT8    *DgbContext,

+  IN OUT BOOLEAN  *Flag,

+  IN OUT UINT8    *DbgLevel

+  )

+{

+  UNIVERSAL_PAYLOAD_TRACEHUB_DEBUG_INFO  *ThDebugInfo;

+

+  ThDebugInfo = NULL;

+

+  if ((DbgLevel == NULL) || (Flag == NULL)) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  if (DgbContext != NULL) {

+    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);

+    *DbgLevel   = ThDebugInfo->DebugContext.DebugLevel;

+    *Flag       = ThDebugInfo->DebugContext.Flag;

+  } else {

+    *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);

+    *Flag     = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);

+  }

+

+  return EFI_SUCCESS;

+}

+

+/**

+  Allocate boot time pool memory to store Trace Hub HOB data.

+

+  @retval  EFI_SUCCESS   Migration process is successful.

+  @retval  Other         Migration process is unsuccessful

+**/

+STATIC

+EFI_STATUS

+MigrateTraceHubHobData (

+  VOID

+  )

+{

+  return EFI_UNSUPPORTED;

+}

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c
new file mode 100644
index 0000000000..0e7a09c95e
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.c
@@ -0,0 +1,81 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Uefi.h>

+#include <Library/BaseLib.h>

+#include <Library/BaseMemoryLib.h>

+#include "TraceHubApiCommon.h"

+

+/**

+  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

+EnableTraceHubData (

+  IN BOOLEAN                  Flag,

+  IN UINT8                    DbgLevel,

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType

+  )

+{

+  if (Flag == TraceHubRoutingDisable) {

+    return FALSE;

+  }

+

+  if (DbgLevel == TraceHubDebugLevelError) {

+    if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError))) {

+      return TRUE;

+    }

+  } else if (DbgLevel == TraceHubDebugLevelErrorWarning) {

+    if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError) || (SeverityType == SeverityWarning))) {

+      return TRUE;

+    }

+  } else if (DbgLevel == TraceHubDebugLevelErrorWarningInfo) {

+    if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError) || (SeverityType == SeverityWarning) || (SeverityType == SeverityNormal))) {

+      return TRUE;

+    }

+  } else if (DbgLevel == TraceHubDebugLevelErrorWarningInfoVerbose) {

+    return TRUE;

+  }

+

+  return FALSE;

+}

+

+/**

+  Convert GUID from little endian to big endian.

+

+  @param[in, out]  Guid   GUID in little endian format on entry. GUID in big endian format on exit.

+

+  @retval EFI_SUCCESS      Convert GUID successfully.

+**/

+EFI_STATUS

+EFIAPI

+LittleEndianToBigEndian (

+  IN OUT EFI_GUID  *Guid

+  )

+{

+  EFI_GUID  TempGuid;

+  UINT64    GuidData4;

+

+  ZeroMem (&TempGuid, sizeof (EFI_GUID));

+  TempGuid.Data1 = SwapBytes32 (Guid->Data1);

+  TempGuid.Data2 = SwapBytes16 (Guid->Data2);

+  TempGuid.Data3 = SwapBytes16 (Guid->Data3);

+  CopyMem (&GuidData4, Guid->Data4, sizeof (Guid->Data4));

+  GuidData4 = SwapBytes64 (GuidData4);

+  CopyMem (TempGuid.Data4, &GuidData4, sizeof (GuidData4));

+  CopyMem (Guid, &TempGuid, sizeof (EFI_GUID));

+

+  return EFI_SUCCESS;

+}

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h
new file mode 100644
index 0000000000..f2f3cda8b7
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiCommon.h
@@ -0,0 +1,64 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef TRACE_HUB_API_COMMON_H_

+#define TRACE_HUB_API_COMMON_H_

+

+#include <Library/TraceHubDebugLib.h>

+

+typedef enum {

+  TraceHubDebugType = 0,

+  TraceHubCatalogType

+} TRACEHUB_PRINTTYPE;

+

+typedef enum {

+  TraceHubRoutingDisable = 0,

+  TraceHubRoutingEnable,

+  TraceHubRoutingMax

+} TRACE_HUB_ROUTING;

+

+typedef enum {

+  TraceHubDebugLevelError = 0,

+  TraceHubDebugLevelErrorWarning,

+  TraceHubDebugLevelErrorWarningInfo,

+  TraceHubDebugLevelErrorWarningInfoVerbose,

+  TraceHubDebugLevelMax

+} TRACE_HUB_DEBUG_LEVEL;

+

+/**

+  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

+EnableTraceHubData (

+  IN BOOLEAN                  Flag,

+  IN UINT8                    DbgLevel,

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType

+  );

+

+/**

+  Convert GUID from little endian to big endian.

+

+  @param[in, out]  Guid   GUID in little endian format on entry. GUID in big endian format on exit.

+

+  @retval EFI_SUCCESS      Convert GUID successfully.

+**/

+EFI_STATUS

+EFIAPI

+LittleEndianToBigEndian (

+  IN OUT EFI_GUID  *Guid

+  );

+

+#endif // TRACE_HUB_API_COMMON_H_

diff --git a/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h
new file mode 100644
index 0000000000..23a9879316
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugLibSysT/TraceHubApiInternal.h
@@ -0,0 +1,92 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef TRACE_HUB_API_INTERNAL_H_

+#define TRACE_HUB_API_INTERNAL_H_

+

+/**

+  Collect the number of available Trace Hub debug instance.

+

+  @param[in, out]  DbgInstCount   The number of available Trace Hub debug instance.

+

+  @retval EFI_SUCCESS      Collect the number of available Trace Hub debug instance successfully.

+  @retval Other            Failed to collect the number of available Trace Hub debug instance.

+**/

+STATIC

+EFI_STATUS

+CountDebugInstance (

+  IN OUT UINT32  *DbgInstCount

+  );

+

+/**

+  Check whether to output Tracr Hub message.

+

+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.

+  @param[in, out]  DgbContext       A pointer to Trace Hub debug instance.

+  @param[in]       SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]       PrintType        Either catalog print or debug print.

+

+  @retval EFI_SUCCESS      Current Trace Hub message need to be processed.

+  @retval Other            Current Trace Hub message no need to be processed.

+**/

+STATIC

+EFI_STATUS

+CheckWhetherToOutputMsg (

+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,

+  IN OUT UINT8                    *DgbContext,

+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN     TRACEHUB_PRINTTYPE       PrintType

+  );

+

+/**

+  Get visibility of Trace Hub Msg.

+

+  @param[in]      DgbContext      A pointer to Trace Hub debug instance.

+  @param[in, out] Flag            Flag to enable or disable Trace Hub message.

+  @param[in, out] DbgLevel        Debug Level of Trace Hub.

+

+  @retval EFI_SUCCESS             Get visibility of Trace Hub Msg successfully.

+  @retval EFI_INVALID_PARAMETER   On entry, Flag or DbgLevel is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMsgVisibility (

+  IN     UINT8    *DgbContext,

+  IN OUT BOOLEAN  *Flag,

+  IN OUT UINT8    *DbgLevel

+  );

+

+/**

+  Get Trace Hub MMIO Address.

+

+  @param[in]      DgbContext        A pointer to Trace Hub debug instance.

+  @param[in, out] TraceAddress      Trace Hub MMIO Address.

+

+  @retval EFI_SUCCESS               Get MMIO address successfully.

+  @retval EFI_INVALID_PARAMETER     TraceAddress is a NULL pointer.

+**/

+STATIC

+EFI_STATUS

+GetTraceHubMmioAddress (

+  IN     UINT8  *DgbContext,

+  IN OUT UINTN  *TraceAddress

+  );

+

+/**

+  Allocate boot time pool memory to store Trace Hub HOB data.

+

+  @retval  EFI_SUCCESS   Migration process is successful.

+  @retval  Other         Migration process is unsuccessful

+**/

+STATIC

+EFI_STATUS

+MigrateTraceHubHobData (

+  VOID

+  );

+

+#endif // TRACE_HUB_API_INTERNAL_H_

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 9605c617b7..8300c88141 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -438,6 +438,9 @@
   ## Include/UniversalPayload/SerialPortInfo.h

   gUniversalPayloadSerialPortInfoGuid = { 0xaa7e190d, 0xbe21, 0x4409, { 0x8e, 0x67, 0xa2, 0xcd, 0xf, 0x61, 0xe1, 0x70 } }

 

+  ## Include/UniversalPayload/TraceHubDebugInfo.h

+  gUniversalPayloadTraceHubDebugInfoGuid = { 0xf88c9c23, 0x646c, 0x4f6c, { 0x8e, 0x3d, 0x36, 0xa9, 0x43, 0xc1, 0x08, 0x35 } }

+

   ## GUID used for Boot Discovery Policy FormSet guid and related variables.

   gBootDiscoveryPolicyMgrFormsetGuid = { 0x5b6f7107, 0xbb3c, 0x4660, { 0x92, 0xcd, 0x54, 0x26, 0x90, 0x28, 0x0b, 0xbd } }

 

@@ -1093,6 +1096,24 @@
   # @Prompt Enable UEFI Stack Guard.

   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055

 

+  ## Indicate debug level of Trace Hub.

+  #   0x0 - TraceHubDebugLevelError.<BR>

+  #   0x1 - TraceHubDebugLevelErrorWarning.<BR>

+  #   0x2 - TraceHubDebugLevelErrorWarningInfo.<BR>

+  #   0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.<BR>

+  # @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.<BR>

+  #   TRUE  - Enable Trace Hub debug message.<BR>

+  # @Prompt Enable or Disable Trace Hub message.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg|0|BOOLEAN|0x30001057

+

+  ## Indicate MMIO address where Trace Hub message output to.

+  # @Prompt Output MMIO address of Trace Hub message.

+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugAddress|0|UINT64|0x30001058

+

 [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..a11f26572a 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -106,6 +106,9 @@
   MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf

   VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf

   IpmiCommandLib|MdeModulePkg/Library/BaseIpmiCommandLibNull/BaseIpmiCommandLibNull.inf

+  TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf

+  TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf

+  TraceHubDebugLib|MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf

 

 [LibraryClasses.EBC.PEIM]

   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf

@@ -446,6 +449,9 @@
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf

   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf

   MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf

+  MdeModulePkg/Library/TraceHubDebugLibSysT/BaseTraceHubDebugLibSyst.inf

+  MdeModulePkg/Library/TraceHubDebugLibSysT/PeiTraceHubDebugLibSyst.inf

+  MdeModulePkg/Library/TraceHubDebugLibSysT/DxeSmmTraceHubDebugLibSyst.inf

 

 [Components.IA32, Components.X64, Components.AARCH64]

   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 33ce9f6198..b64f26d255 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -1290,6 +1290,24 @@
                                                                                     "   TRUE  - UEFI Stack Guard will be enabled.<BR>\n"

                                                                                     "   FALSE - UEFI Stack Guard will be disabled.<BR>"

 

+#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.<BR>"

+                                                                                         "  0x1 - TraceHubDebugLevelErrorWarning.<BR>"

+                                                                                         "  0x2 - TraceHubDebugLevelErrorWarningInfo.<BR>"

+                                                                                         "  0x3 - TraceHubDebugLevelErrorWarningInfoVerbose.<BR>"

+

+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdEnableTraceHubDebugMsg_PROMPT  #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.<BR>"

+                                                                                             "  TRUE  - Enable Trace Hub debug message.<BR>"

+

+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugAddress_PROMPT  #language en-US "Output MMIO address of Trace Hub message"

+

+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugAddress_HELP    #language en-US "Indicate MMIO address where Trace Hub message output to."

+

 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_PROMPT  #language en-US "NV Storage DefaultId"

 

 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdSetNvStoreDefaultId_HELP    #language en-US "This dynamic PCD enables the default variable setting.\n"

-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT
  2023-01-31  2:49 ` [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT victorx.hsu
@ 2023-01-31  3:17   ` Guo, Gua
  0 siblings, 0 replies; 8+ messages in thread
From: Guo, Gua @ 2023-01-31  3:17 UTC (permalink / raw)
  To: Hsu, VictorX, devel@edk2.groups.io
  Cc: Kinney, Michael D, Chan, Laura,
	Prakashan, Krishnadas Veliyathuparambil, K N, Karthik

Reviewed-by: Gua Guo <gua.guo@intel.com>

-----Original Message-----
From: Hsu, VictorX <victorx.hsu@intel.com> 
Sent: Tuesday, January 31, 2023 10:49 AM
To: devel@edk2.groups.io
Cc: Hsu, VictorX <victorx.hsu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Guo, Gua <gua.guo@intel.com>; Chan, Laura <laura.chan@intel.com>; Prakashan, Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>; K N, Karthik <karthik.k.n@intel.com>
Subject: [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT

From: VictorX Hsu <victorx.hsu@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144

This Library is NULL library for TraceHubDebugLibSysT.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guo Gua <gua.guo@intel.com>
Cc: Chan Laura <laura.chan@intel.com>
Cc: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com>
Cc: K N Karthik <karthik.k.n@intel.com>
Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 MdePkg/Include/Library/TraceHubDebugLib.h     | 82 +++++++++++++++++++
 .../TraceHubDebugLibNull.c                    | 75 +++++++++++++++++
 .../TraceHubDebugLibNull.inf                  | 29 +++++++
 MdePkg/MdePkg.dec                             |  4 +
 MdePkg/MdePkg.dsc                             |  2 +
 5 files changed, 192 insertions(+)
 create mode 100644 MdePkg/Include/Library/TraceHubDebugLib.h
 create mode 100644 MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c
 create mode 100644 MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf

diff --git a/MdePkg/Include/Library/TraceHubDebugLib.h b/MdePkg/Include/Library/TraceHubDebugLib.h
new file mode 100644
index 0000000000..2e8d70ae97
--- /dev/null
+++ b/MdePkg/Include/Library/TraceHubDebugLib.h
@@ -0,0 +1,82 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef TRACE_HUB_DEBUG_LIB_H_

+#define TRACE_HUB_DEBUG_LIB_H_

+

+#include <Uefi.h>

+

+typedef enum {

+  SeverityNone    = 0,

+  SeverityFatal   = 1,

+  SeverityError   = 2,

+  SeverityWarning = 3,

+  SeverityNormal  = 4,

+  SeverityUser1   = 5,

+  SeverityUser2   = 6,

+  SeverityUser3   = 7,

+  SeverityMax

+} TRACE_HUB_SEVERITY_TYPE;

+

+/**

+  Write debug string to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Buffer           A pointer to the data buffer.

+  @param[in]  NumberOfBytes    Number of bytes to be written.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubDebugWrite (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT8                    *Buffer,

+  IN UINTN                    NumberOfBytes

+  );

+

+/**

+  Write catalog status code message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id               Catalog ID.

+  @param[in]  Guid             Driver Guid.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64StatusCode (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN EFI_GUID                 *Guid

+  );

+

+/**

+  Write catalog message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id             Catalog ID.

+  @param[in]  NumberOfParams Number of parameters in argument list.

+  @param[in]  ...            Argument list that pass to Trace Hub.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64 (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN UINTN                    NumberOfParams,

+  ...

+  );

+

+#endif // TRACE_HUB_DEBUG_LIB_H_

diff --git a/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c
new file mode 100644
index 0000000000..8d8f3f69e8
--- /dev/null
+++ b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.c
@@ -0,0 +1,75 @@
+/** @file

+

+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Uefi.h>

+#include <Library/TraceHubDebugLib.h>

+

+/**

+  Write debug string to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Buffer           A pointer to the data buffer.

+  @param[in]  NumberOfBytes    Number of bytes to be written.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubDebugWrite (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT8                    *Buffer,

+  IN UINTN                    NumberOfBytes

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Write catalog status code message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType     An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id               Catalog ID.

+  @param[in]  Guid             Driver Guid.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64StatusCode (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN EFI_GUID                 *Guid

+  )

+{

+  return EFI_UNSUPPORTED;

+}

+

+/**

+  Write catalog message to specified Trace Hub MMIO address.

+

+  @param[in]  SeverityType   An error level to decide whether to enable Trace Hub data.

+  @param[in]  Id             Catalog ID.

+  @param[in]  NumberOfParams Number of parameters in argument list.

+  @param[in]  ...            Argument list that pass to Trace Hub.

+

+  @retval EFI_SUCCESS      Data was written to Trace Hub.

+  @retval Other            Failed to output Trace Hub message.

+**/

+EFI_STATUS

+EFIAPI

+TraceHubWriteCataLog64 (

+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,

+  IN UINT64                   Id,

+  IN UINTN                    NumberOfParams,

+  ...

+  )

+{

+  return EFI_UNSUPPORTED;

+}

diff --git a/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf
new file mode 100644
index 0000000000..0629365b6e
--- /dev/null
+++ b/MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf
@@ -0,0 +1,29 @@
+## @file

+#  Null library of TraceHubDebugLib.

+#

+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+

+[Defines]

+  INF_VERSION                    = 0x00010005

+  BASE_NAME                      = TraceHubDebugLibNull

+  FILE_GUID                      = 16196A4E-4196-4AF4-9A6B-F4D2ACC430A8

+  MODULE_TYPE                    = BASE

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = TraceHubDebugLib

+

+#

+# The following information is for reference only and not required by the build tools.

+#

+# VALID_ARCHITECTURES = IA32 X64

+#

+

+[Packages]

+  MdePkg/MdePkg.dec

+

+[Sources]

+  TraceHubDebugLibNull.c

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index bee7ac538a..1ea6a0aae6 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -289,6 +289,10 @@
   #

   MipiSysTLib|Include/Library/MipiSysTLib.h

 

+  ##  @libraryclass  Provides API to output Trace Hub debug message.

+  #

+  TraceHubDebugLib|Include/Library/TraceHubDebugLib.h

+

 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]

   ##  @libraryclass  Provides services to generate random number.

   #

diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index cbcf4a6047..a2b4164d84 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -35,6 +35,7 @@
 [LibraryClasses]

   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf

   MipiSysTLib|MdePkg/Library/MipiSysTLib/MipiSysTLib.inf

+  TraceHubDebugLib|MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf

 

 [Components]

   MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf

@@ -137,6 +138,7 @@
   MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf

   MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf

   MdePkg/Library/MipiSysTLib/MipiSysTLib.inf

+  MdePkg/Library/TraceHubDebugLibNull/TraceHubDebugLibNull.inf

 

 [Components.IA32, Components.X64, Components.ARM, Components.AARCH64]

   #

-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-31  3:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-31  2:48 [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
2023-01-31  2:49 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugLibSysT library victorx.hsu
2023-01-31  3:17   ` Guo, Gua
2023-01-31  2:49 ` [PATCH 3/4] MdePkg: Add NULL library for TraceHubDebugLibSysT victorx.hsu
2023-01-31  3:17   ` Guo, Gua
2023-01-31  2:49 ` [PATCH 4/4] Maintainers.txt: Update reviewers for Trace Hub library victorx.hsu
2023-01-31  3:16   ` Guo, Gua
2023-01-31  3:17 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library Guo, Gua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox