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  3:17 ` Guo, Gua
  0 siblings, 1 reply; 10+ 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] 10+ messages in thread

* Re: [PATCH 1/4] MdePkg: Add MipiSysTLib library
  2023-01-31  2:48 victorx.hsu
@ 2023-01-31  3:17 ` Guo, Gua
  0 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 1/4] MdePkg: Add MipiSysTLib library
  2023-04-18 11:04 [PATCH 0/4] Trace Hub debug library support victorx.hsu
@ 2023-04-18 11:04 ` victorx.hsu
  0 siblings, 0 replies; 10+ messages in thread
From: victorx.hsu @ 2023-04-18 11:04 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 provides functions consuming MIPI SYS-T submodule.

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       |  66 ++
 MdePkg/Library/MipiSysTLib/GenMipiSystH.py | 132 ++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.c   | 123 ++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf |  55 ++
 MdePkg/Library/MipiSysTLib/Platform.c      | 164 +++++
 MdePkg/Library/MipiSysTLib/Platform.h      | 138 ++++
 MdePkg/Library/MipiSysTLib/Readme.md       |  25 +
 MdePkg/Library/MipiSysTLib/mipi_syst.h     | 789 +++++++++++++++++++++
 MdePkg/Library/MipiSysTLib/mipisyst        |   1 +
 MdePkg/MdePkg.ci.yaml                      |  15 +-
 MdePkg/MdePkg.dec                          |   5 +
 MdePkg/MdePkg.dsc                          |   1 +
 ReadMe.rst                                 |   1 +
 15 files changed, 1519 insertions(+), 3 deletions(-)
 create mode 100644 MdePkg/Include/Library/MipiSysTLib.h
 create mode 100644 MdePkg/Library/MipiSysTLib/GenMipiSystH.py
 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/Readme.md
 create mode 100644 MdePkg/Library/MipiSysTLib/mipi_syst.h
 create mode 160000 MdePkg/Library/MipiSysTLib/mipisyst

diff --git a/.gitmodules b/.gitmodules
index fe8a43be93..19c1bbaf46 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,7 +16,7 @@
 [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
@@ -26,3 +26,6 @@
 [submodule "UnitTestFrameworkPkg/Library/SubhookLib/subhook"]
 	path = UnitTestFrameworkPkg/Library/SubhookLib/subhook
 	url = https://github.com/Zeex/subhook.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 e3f44add58..bfe5fa5be2 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -195,6 +195,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
             "RedfishPkg/Library/JsonLib/jansson", False))
         rs.append(RequiredSubmodule(
             "UnitTestFrameworkPkg/Library/SubhookLib/subhook", 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..4ced1c02cd
--- /dev/null
+++ b/MdePkg/Include/Library/MipiSysTLib.h
@@ -0,0 +1,66 @@
+/** @file
+This header file declares functions consuming MIPI Sys-T submodule.
+
+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_
+
+/**
+  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 RETURN_SUCCESS      MIPI_SYST_HANDLE instance was initialized.
+  @retval Other               MIPI_SYST_HANDLE instance was not initialized.
+**/
+RETURN_STATUS
+EFIAPI
+InitMipiSystHandle (
+  IN OUT VOID  *MipiSystHandle
+  );
+
+/**
+  Invoke write_debug_string function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        Severity type of input message.
+  @param[in]  Len             Length of data buffer.
+  @param[in]  Str             A pointer to data buffer.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_ABORTED               No data need to be written to Trace Hub.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle or Str is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteDebug (
+  IN        VOID    *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        Severity type of input message.
+  @param[in]  CatId           Catalog Id.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteCatalog (
+  IN  VOID    *MipiSystHandle,
+  IN  UINT32  Severity,
+  IN  UINT64  CatId
+  );
+
+#endif // MIPI_SYST_LIB_H_
diff --git a/MdePkg/Library/MipiSysTLib/GenMipiSystH.py b/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
new file mode 100644
index 0000000000..ee48285590
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
@@ -0,0 +1,132 @@
+## @file
+#  This python script update content from mipi_syst.h.in in mipi sys-T submodule
+#  and generate it as mipi_syst.h. mipi_syst.h include necessary data structure and
+#  definition that will be consumed by MipiSysTLib itself, mipi sys-T submodule
+#  and other library.
+#
+#  This script needs to be done once by a developer when adding some
+#  project-relating definition or a new version of mipi_syst.h.in is released.
+#  Normal users do not need to do this, since the resulting file is stored
+#  in the EDK2 git repository.
+#
+#  Customize structures mentioned below to generate updated mipi_syst.h file:
+#  1. ExistingValueToBeReplaced
+#       -> To replace existing value in mipi_syst.h.in to newer one.
+#  2. ExistingDefinitionToBeRemoved
+#       -> To #undef a existing definition in mipi_syst.h.in.
+#  3. NewItemToBeAdded
+#       -> Items in this structure will be placed at the end of mipi_syst.h as a customized section.
+#
+#  Run GenMipiSystH.py without any parameters as normal python script after customizing.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+import os
+import re
+
+#
+# A existing value to be customized should place this structure
+# Definitions in this customizable structure will be processed by ReplaceOldValue()
+# e.g:
+#   Before: @SYST_CFG_VERSION_MAJOR@
+#   After: 1
+#
+ExistingValueToBeReplaced = [
+    ["@SYST_CFG_VERSION_MAJOR@", "1"],      # Major version
+    ["@SYST_CFG_VERSION_MINOR@", "0"],      # Minor version
+    ["@SYST_CFG_VERSION_PATCH@", "0"],      # Patch version
+    ["@SYST_CFG_CONFORMANCE_LEVEL@", "30"], # Feature level of mipi sys-T submodule
+    ["mipi_syst/platform.h", "Platform.h"],
+]
+
+#
+# A existing definition to be removed should place this structure
+# Definitions in this customizable structure will be processed by RemoveDefinition()
+# e.g:
+#   Before:
+#       #define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#   After:
+#       #define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#       #undef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#
+ExistingDefinitionToBeRemoved = [
+    "MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA",
+    "MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY",
+    "MIPI_SYST_PCFG_ENABLE_PRINTF_API",
+    "MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD",
+    "MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS",
+]
+
+#
+# Items in this structure will be placed at the end of mipi_syst.h as a customized section.
+#
+NewItemToBeAdded = [
+    "typedef struct mipi_syst_handle_flags MIPI_SYST_HANDLE_FLAGS;",
+    "typedef struct mipi_syst_msg_tag MIPI_SYST_MSG_TAG;",
+    "typedef struct mipi_syst_guid MIPI_SYST_GUID;",
+    "typedef enum mipi_syst_severity MIPI_SYST_SEVERITY;",
+    "typedef struct mipi_syst_handle MIPI_SYST_HANDLE;",
+    "typedef struct mipi_syst_header MIPI_SYST_HEADER;",
+]
+
+def ProcessSpecialCharacter(Str):
+    Str = Str.rstrip(" \n")
+    Str = Str.replace("\t", "  ")
+    Str += "\n"
+    return Str
+
+def ReplaceOldValue(Str):
+    for i in range(len(ExistingValueToBeReplaced)):
+        Result = re.search(ExistingValueToBeReplaced[i][0], Str)
+        if Result is not None:
+            Str = Str.replace(ExistingValueToBeReplaced[i][0], ExistingValueToBeReplaced[i][1])
+            break
+    return Str
+
+def RemoveDefinition(Str):
+    Result = re.search("\*", Str)
+    if Result is None:
+        for i in range(len(ExistingDefinitionToBeRemoved)):
+            Result = re.search(ExistingDefinitionToBeRemoved[i], Str)
+            if Result is not None:
+                Result = re.search("defined", Str)
+                if Result is None:
+                    Str = Str + "#undef " + ExistingDefinitionToBeRemoved[i]
+                    break
+    return Str
+
+def main():
+    MipiSystHSrcDir = "mipisyst/library/include/mipi_syst.h.in"
+    MipiSystHRealSrcDir = os.path.join(os.getcwd(), os.path.normpath(MipiSystHSrcDir))
+    MipiSystHRealDstDir = os.path.join(os.getcwd(), "mipi_syst.h")
+
+    #
+    # Read content from mipi_syst.h.in and process each line by demand
+    #
+    with open(MipiSystHRealSrcDir, "r") as rfObj:
+        SrcFile = rfObj.readlines()
+        for lineIndex in range(len(SrcFile)):
+            SrcFile[lineIndex] = ProcessSpecialCharacter(SrcFile[lineIndex])
+            SrcFile[lineIndex] = ReplaceOldValue(SrcFile[lineIndex])
+            SrcFile[lineIndex] = RemoveDefinition(SrcFile[lineIndex])
+
+    #
+    # Typedef a structure or enum type
+    #
+    i = -1
+    for struct in NewItemToBeAdded:
+        struct += "\n"
+        SrcFile.insert(i, struct)
+        i -= 1
+
+    #
+    # Save edited content to mipi_syst.h
+    #
+    with open(MipiSystHRealDstDir, "w") as wfObj:
+        wfObj.writelines(SrcFile)
+
+if __name__ == '__main__':
+    main()
diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.c b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
new file mode 100644
index 0000000000..3a15a2af58
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
@@ -0,0 +1,123 @@
+/** @file
+This file provide functions to communicate with mipi sys-T submodule.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.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 RETURN_SUCCESS      MIPI_SYST_HANDLE instance was initialized.
+  @retval Other               MIPI_SYST_HANDLE instance was not initialized.
+**/
+RETURN_STATUS
+EFIAPI
+InitMipiSystHandle (
+  IN OUT VOID  *MipiSystHandle
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  if (MipiSystH == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  mipi_syst_init (MipiSystH->systh_header, 0, NULL);
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Invoke write_debug_string function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        Severity type of input message.
+  @param[in]  Len             Length of data buffer.
+  @param[in]  Str             A pointer to data buffer.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_ABORTED               No data need to be written to Trace Hub.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle or Str is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteDebug (
+  IN        MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN        UINT32            Severity,
+  IN        UINT16            Len,
+  IN CONST  CHAR8             *Str
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  if (MipiSystH == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (Len == 0) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return RETURN_ABORTED;
+  }
+
+  if (Str == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  mipi_syst_write_debug_string (
+    MipiSystH,
+    MIPI_SYST_NOLOCATION,
+    MIPI_SYST_STRING_GENERIC,
+    Severity,
+    Len,
+    Str
+    );
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Invoke catalog_write_message function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        Severity type of input message.
+  @param[in]  CatId           Catalog Id.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteCatalog (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Severity,
+  IN  UINT64            CatId
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  if (MipiSystH == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  mipi_syst_write_catalog64_message (
+    MipiSystH,
+    MIPI_SYST_NOLOCATION,
+    Severity,
+    CatId
+    );
+
+  return RETURN_SUCCESS;
+}
diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
new file mode 100644
index 0000000000..b2aefcc9cc
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
@@ -0,0 +1,55 @@
+## @file
+#  A library providing funcitons to communicate with mipi sys-T submodule.
+#
+#  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:*_*_IA32_CC_FLAGS = /DMIPI_SYST_STATIC
+  MSFT:*_*_X64_CC_FLAGS  = /DMIPI_SYST_STATIC
+  GCC:*_*_IA32_CC_FLAGS  = -DMIPI_SYST_STATIC
+  GCC:*_*_X64_CC_FLAGS   = -DMIPI_SYST_STATIC
diff --git a/MdePkg/Library/MipiSysTLib/Platform.c b/MdePkg/Library/MipiSysTLib/Platform.c
new file mode 100644
index 0000000000..90a524bc1e
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.c
@@ -0,0 +1,164 @@
+/** @file
+This file defines functions that output Trace Hub message.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.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  VOID    *MipiSystHandle,
+  IN  UINT32  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite32 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT32  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite32 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT64  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite64 ((UINTN)(MipiSystH->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  VOID   *MipiSystHandle,
+  IN  UINT8  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite8 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT16  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite16 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT32  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite32 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT64  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite64 ((UINTN)(MipiSystH->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  VOID  *MipiSystHandle
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+
+  MmioWrite32 ((UINTN)(MipiSystH->systh_platform.TraceHubPlatformData.MmioAddr + 0x30), 0x0);
+}
diff --git a/MdePkg/Library/MipiSysTLib/Platform.h b/MdePkg/Library/MipiSysTLib/Platform.h
new file mode 100644
index 0000000000..ac77edf33d
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.h
@@ -0,0 +1,138 @@
+/** @file
+This header file declares functions and structures.
+
+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_
+
+typedef struct {
+  UINT64    MmioAddr;
+} TRACE_HUB_PLATFORM_SYST_DATA;
+
+struct mipi_syst_platform_handle {
+  TRACE_HUB_PLATFORM_SYST_DATA    TraceHubPlatformData;
+};
+
+/**
+  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  VOID    *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  VOID    *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  VOID    *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  VOID   *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  VOID    *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  VOID    *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  VOID    *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  VOID  *MipiSystHandle
+  );
+
+#define MIPI_SYST_PLATFORM_CLOCK()  1000 // (unit: MicroSecond)
+
+#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/Readme.md b/MdePkg/Library/MipiSysTLib/Readme.md
new file mode 100644
index 0000000000..2e5df0194e
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Readme.md
@@ -0,0 +1,25 @@
+## Introduction of MipiSysTLib ##
+MipiSysTLib library is a upper level library consuming MIPI SYS-T submodule.
+It provides MIPI-related APIs in EDK2 format to be consumed.
+
+## MipiSysTLib Version ##
+EDK2 supports building with v1.1+edk2 official version which was fully validated.
+
+## HOW to Install MipiSysTLib for UEFI Building ##
+MIPI SYS-T repository was added as a submodule of EDK2 project. Please
+refer to edk2/Readme.md for how to clone the code.
+
+## About GenMipiSystH.py ##
+"GenMipiSystH.py" is a Python script which is used for customizing the
+mipi_syst.h.in in mipi sys-T repository. The resulting file, mipi_syst.h, will
+be put to same folder level as this script.
+```
+  mipisyst submodule                        MipiSysTLib library
+|---------------------| GenMipiSystH.py   |---------------------|
+|   mipi_syst.h.in    |-----------------> |   mipi_syst.h       |
+|---------------------|                   |---------------------|
+```
+This script needs to be done once by a developer when adding some
+project-related definition or a new version of mipi_syst.h.in was released.
+Normal users do not need to do this, since the resulting file is stored
+in the EDK2 git repository.
diff --git a/MdePkg/Library/MipiSysTLib/mipi_syst.h b/MdePkg/Library/MipiSysTLib/mipi_syst.h
new file mode 100644
index 0000000000..3cf67a1ee5
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipi_syst.h
@@ -0,0 +1,789 @@
+/*
+Copyright (c) 2018, MIPI Alliance, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+* Neither the name of the copyright holder nor the names of its
+  contributors may be used to endorse or promote products derived
+  from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+ * Contributors:
+ * Norbert Schulz (Intel Corporation) - Initial API and implementation
+ */
+
+#ifndef MIPI_SYST_H_INCLUDED
+#define MIPI_SYST_H_INCLUDED
+
+/* 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
+#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
+
+#if defined(__cplusplus)
+extern "C" {
+#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
+};
+
+struct mipi_syst_header;
+struct mipi_syst_handle;
+struct mipi_syst_scatter_prog;
+
+/** 128-bit GUID style message origin ID */
+struct mipi_syst_guid {
+  union {
+    mipi_syst_u8  b[16];
+    mipi_syst_u64 ll[2];
+  } u;
+};
+
+/** 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);
+
+/**
+ * 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);
+
+#ifdef __cplusplus
+} /* extern C */
+#endif
+#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 Platform global SyS-T data state
+ *
+ * This define extends the global SyS-T state data structure
+ * mipi_syst_header with platform private content. A platform typically
+ * stores data for SyS-T handle creation processing in this structure.
+ *
+ * Note: This data is not touched by the library code itself, but typically
+ * is used by platform  hook functions for handle creation and destruction.
+ * **These hook function calls are not lock protected and may happen
+ * concurrently!**  The hook functions need to implement locking if they
+ *  modify the platform state data.
+ *
+ * The platform example uses #mipi_syst_platform_state as data state extension.
+ */
+#define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#undef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+/**
+ * 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
+
+/**
+ * Enable HEAP usage for handle generation
+ *
+ * This macro tells the SyS-T library to enable the heap allocation handle
+ * creation API #MIPI_SYST_ALLOC_HANDLE.
+ * The platform must provide the macros #MIPI_SYST_HEAP_MALLOC and
+ * #MIPI_SYST_HEAP_FREE to point SyS-T to the platform malloc and free
+ * functions.
+ *
+ * Note: In OS kernel space environments, you must use unpaged memory
+ * allocation functions.
+ */
+#define MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY
+#undef MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY
+/* 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
+ /**
+ * Enable printf API support
+ *
+ * Note:
+ * Enabling printf requires compiler var_arg support as defined by the
+ * header files stdarg.h stddef.h.
+ */
+
+#define MIPI_SYST_PCFG_ENABLE_PRINTF_API
+#undef MIPI_SYST_PCFG_ENABLE_PRINTF_API
+/**
+ * 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 the API variants that send file:line ID pair location records.
+ */
+#define MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
+#undef MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
+/**
+ * Enable the API variants that send the address of the instrumentation location.
+ *
+ * This API requires #MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD to be set as well.
+ * It uses its own define as it additionally requires the function
+ * @ref mipi_syst_return_addr() to be implemented for your platform.
+ */
+#define MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
+#undef MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
+/**
+ * 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
+#ifdef __cplusplus
+extern "C" {
+#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
+
+/** SyS-T global state structure.
+ * This structure is holding the global SyS-T library state
+ */
+struct mipi_syst_header {
+  mipi_syst_u32 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
+};
+
+/**
+ * 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.
+ */
+
+struct mipi_syst_msg_tag {
+#if defined(MIPI_SYST_BIG_ENDIAN)
+  mipi_syst_u32 et_res31 : 1;    /**< reserved for future use        */
+  mipi_syst_u32 et_res30 : 1;    /**< reserved for future use        */
+  mipi_syst_u32 et_subtype : 6;  /**< type dependent sub category    */
+  mipi_syst_u32 et_guid : 1;     /**< 128-bit GUID present           */
+  mipi_syst_u32 et_modunit : 11; /**< unit for GUID or module:unit   */
+  mipi_syst_u32 et_timestamp : 1;/**< indicate 64-bit timestamp      */
+  mipi_syst_u32 et_chksum : 1;   /**< indicate 32-bit CRC            */
+  mipi_syst_u32 et_length : 1;   /**< indicate length field          */
+  mipi_syst_u32 et_location : 1; /**< indicate location information  */
+  mipi_syst_u32 et_res7 : 1;     /**< reserved for future use        */
+  mipi_syst_u32 et_severity : 3; /**< severity level of message      */
+  mipi_syst_u32 et_type : 4;     /**< SyS-T message type ID          */
+#else
+  mipi_syst_u32 et_type : 4;     /**< SyS-T message type ID          */
+  mipi_syst_u32 et_severity : 3; /**< severity level of message      */
+  mipi_syst_u32 et_res7 : 1;     /**< reserved for future use        */
+  mipi_syst_u32 et_location : 1; /**< indicate location information  */
+  mipi_syst_u32 et_length : 1;   /**< indicate length field          */
+  mipi_syst_u32 et_chksum : 1;   /**< indicate 32-bit CRC            */
+  mipi_syst_u32 et_timestamp : 1;/**< indicate 64-bit timestamp      */
+  mipi_syst_u32 et_modunit : 11; /**< unit for GUID or module:unit   */
+  mipi_syst_u32 et_guid : 1;     /**< 128-bit GUID present           */
+  mipi_syst_u32 et_subtype : 6;  /**< type dependent sub category    */
+  mipi_syst_u32 et_res30 : 1;    /**< reserved for future use        */
+  mipi_syst_u32 et_res31 : 1;    /**< reserved for future use        */
+#endif
+};
+#define _MIPI_SYST_MK_MODUNIT_ORIGIN(m,u) (((u) & 0xF)|(m<<4))
+
+/**
+ * Message severity level enumeration
+ */
+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    */
+};
+
+/**
+ * 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;
+};
+
+/** internal handle state flags
+ */
+struct mipi_syst_handle_flags {
+  mipi_syst_u32 shf_alloc:1; /**< set to 1 if heap allocated handle */
+};
+
+/** 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.
+ */
+ 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
+
+  mipi_syst_u32 systh_param_count;          /**< number of parameters     */
+  mipi_syst_u32 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
+};
+
+
+#ifdef __cplusplus
+} /* extern C */
+#endif
+#ifndef MIPI_SYST_API_INCLUDED
+#include "mipi_syst/api.h"
+#endif
+
+typedef struct mipi_syst_header MIPI_SYST_HEADER;
+typedef struct mipi_syst_handle MIPI_SYST_HANDLE;
+typedef enum mipi_syst_severity MIPI_SYST_SEVERITY;
+typedef struct mipi_syst_guid MIPI_SYST_GUID;
+typedef struct mipi_syst_msg_tag MIPI_SYST_MSG_TAG;
+typedef struct mipi_syst_handle_flags MIPI_SYST_HANDLE_FLAGS;
+#endif
diff --git a/MdePkg/Library/MipiSysTLib/mipisyst b/MdePkg/Library/MipiSysTLib/mipisyst
new file mode 160000
index 0000000000..370b5944c0
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipisyst
@@ -0,0 +1 @@
+Subproject commit 370b5944c046bab043dd8b133727b2135af7747a
diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
index 6ba85ebe61..31eff06232 100644
--- a/MdePkg/MdePkg.ci.yaml
+++ b/MdePkg/MdePkg.ci.yaml
@@ -10,7 +10,10 @@
 {
     ## options defined .pytool/Plugin/LicenseCheck
     "LicenseCheck": {
-        "IgnoreFiles": []
+        "IgnoreFiles": [
+            # This file is copied from mipi sys-T submodule and generated by python script with customization.
+            "Library/MipiSysTLib/mipi_syst.h"
+        ]
     },
     "EccCheck": {
         ## Exception sample looks like below:
@@ -67,7 +70,8 @@
             "Include/Library/PcdLib.h",
             "Include/Library/SafeIntLib.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
@@ -164,5 +168,12 @@
         "ExtendWords": [],           # words to extend to the dictionary for this package
         "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
         "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
+    },
+
+    # options defined in .pytool/Plugin/UncrustifyCheck
+    "UncrustifyCheck": {
+        "IgnoreFiles": [
+            "mipi_syst.h"
+        ]
     }
 }
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index e70182bf7f..9fcaacbcd8 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -28,6 +28,7 @@
   Include
   Test/UnitTest/Include
   Test/Mock/Include
+  Library/MipiSysTLib/mipisyst/library/include
 
 [Includes.IA32]
   Include/Ia32
@@ -289,6 +290,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 152c02991a..ae9d871c52 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -183,6 +183,7 @@
   MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
   MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
   MdePkg/Library/TdxLib/TdxLib.inf
+  MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 
 [Components.EBC]
   MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
diff --git a/ReadMe.rst b/ReadMe.rst
index 91b9cf3c5e..e90aff710e 100644
--- a/ReadMe.rst
+++ b/ReadMe.rst
@@ -96,6 +96,7 @@ that are covered by additional licenses.
 -  `UnitTestFrameworkPkg/Library/GoogleTestLib/googletest <https://github.com/google/googletest/blob/86add13493e5c881d7e4ba77fb91c1f57752b3a4/LICENSE>`__
 -  `UnitTestFrameworkPkg/Library/SubhookLib/subhook <https://github.com/Zeex/subhook/blob/83d4e1ebef3588fae48b69a7352cc21801cb70bc/LICENSE.txt>`__
 -  `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.40.0.windows.1


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

* [PATCH 0/4] Trace Hub debug library support
@ 2023-05-08  5:31 victorx.hsu
  2023-05-08  5:31 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: victorx.hsu @ 2023-05-08  5:31 UTC (permalink / raw)
  To: devel; +Cc: VictorX Hsu

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

-	TraceHub UniversalPayload Spec: https://github.com/UniversalScalableFirmware/documentation/pull/52  (Industry Standard)
-	MipiSysTLib Wrapper: https://github.com/MIPI-Alliance/public-mipi-sys-t.git (Industry Standard)
-	TraceHubDebugLib: Intel(R) Trace Hub (TH) — The Linux Kernel documentation (Industry Standard)
    Developers Guide: https://cdrdv2-public.intel.com/671536/intel-trace-hub-developers-manual-2-1-2.pdf (Public Document)

VictorX Hsu (4):
  MdePkg: Add MipiSysTLib library
  MdeModulePkg: Add TraceHubDebugSysTLib library
  MdePkg: Add NULL library of TraceHubDebugSysTLib
  Maintainers.txt: Update reviewers and maintainers for Trace Hub dbg
    lib.

 .gitmodules                                   |  11 +-
 .pytool/CISettings.py                         |   2 +
 Maintainers.txt                               |  18 +
 .../Include/Guid/TraceHubDebugInfoHob.h       |  25 +
 .../BaseTraceHubDebugSysTLib.c                | 251 ++++++
 .../BaseTraceHubDebugSysTLib.inf              |  44 +
 .../DxeSmmTraceHubDebugSysTLib.c              | 247 ++++++
 .../DxeSmmTraceHubDebugSysTLib.inf            |  50 ++
 .../InternalTraceHubApi.c                     |  82 ++
 .../InternalTraceHubApi.h                     |  46 +
 .../InternalTraceHubApiCommon.c               | 208 +++++
 .../InternalTraceHubApiCommon.h               | 119 +++
 .../PeiTraceHubDebugSysTLib.c                 | 290 +++++++
 .../PeiTraceHubDebugSysTLib.inf               |  50 ++
 .../Library/TraceHubDebugSysTLib/Readme.md    |  30 +
 MdeModulePkg/MdeModulePkg.dec                 |  21 +
 MdeModulePkg/MdeModulePkg.dsc                 |   3 +
 MdeModulePkg/MdeModulePkg.uni                 |  18 +
 MdePkg/Include/Library/MipiSysTLib.h          |  66 ++
 MdePkg/Include/Library/TraceHubDebugSysTLib.h |  81 ++
 MdePkg/Library/MipiSysTLib/GenMipiSystH.py    | 132 +++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.c      | 123 +++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf    |  55 ++
 MdePkg/Library/MipiSysTLib/Platform.c         | 164 ++++
 MdePkg/Library/MipiSysTLib/Platform.h         | 138 +++
 MdePkg/Library/MipiSysTLib/Readme.md          |  25 +
 MdePkg/Library/MipiSysTLib/mipi_syst.h        | 789 ++++++++++++++++++
 MdePkg/Library/MipiSysTLib/mipisyst           |   1 +
 .../TraceHubDebugSysTLibNull.c                |  76 ++
 .../TraceHubDebugSysTLibNull.inf              |  29 +
 MdePkg/MdePkg.ci.yaml                         |  12 +-
 MdePkg/MdePkg.dec                             |   9 +
 MdePkg/MdePkg.dsc                             |   2 +
 ReadMe.rst                                    |   1 +
 34 files changed, 3211 insertions(+), 7 deletions(-)
 create mode 100644 MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
 create mode 100644 MdePkg/Include/Library/MipiSysTLib.h
 create mode 100644 MdePkg/Include/Library/TraceHubDebugSysTLib.h
 create mode 100644 MdePkg/Library/MipiSysTLib/GenMipiSystH.py
 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/Readme.md
 create mode 100644 MdePkg/Library/MipiSysTLib/mipi_syst.h
 create mode 160000 MdePkg/Library/MipiSysTLib/mipisyst
 create mode 100644 MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.c
 create mode 100644 MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf

--
2.40.0.windows.1


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

* [PATCH 1/4] MdePkg: Add MipiSysTLib library
  2023-05-08  5:31 [PATCH 0/4] Trace Hub debug library support victorx.hsu
@ 2023-05-08  5:31 ` victorx.hsu
  2023-05-08 17:54   ` Michael D Kinney
  2023-05-08  5:31 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugSysTLib library victorx.hsu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: victorx.hsu @ 2023-05-08  5:31 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 provides functions consuming MIPI SYS-T submodule.

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                                |  11 +-
 .pytool/CISettings.py                      |   2 +
 MdePkg/Include/Library/MipiSysTLib.h       |  66 ++
 MdePkg/Library/MipiSysTLib/GenMipiSystH.py | 132 ++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.c   | 123 ++++
 MdePkg/Library/MipiSysTLib/MipiSysTLib.inf |  55 ++
 MdePkg/Library/MipiSysTLib/Platform.c      | 164 +++++
 MdePkg/Library/MipiSysTLib/Platform.h      | 138 ++++
 MdePkg/Library/MipiSysTLib/Readme.md       |  25 +
 MdePkg/Library/MipiSysTLib/mipi_syst.h     | 789 +++++++++++++++++++++
 MdePkg/Library/MipiSysTLib/mipisyst        |   1 +
 MdePkg/MdePkg.ci.yaml                      |  12 +-
 MdePkg/MdePkg.dec                          |   5 +
 MdePkg/MdePkg.dsc                          |   1 +
 ReadMe.rst                                 |   1 +
 15 files changed, 1518 insertions(+), 7 deletions(-)
 create mode 100644 MdePkg/Include/Library/MipiSysTLib.h
 create mode 100644 MdePkg/Library/MipiSysTLib/GenMipiSystH.py
 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/Readme.md
 create mode 100644 MdePkg/Library/MipiSysTLib/mipi_syst.h
 create mode 160000 MdePkg/Library/MipiSysTLib/mipisyst

diff --git a/.gitmodules b/.gitmodules
index 6211c59724..fb79ebfb72 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,7 +16,7 @@
 [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
@@ -26,6 +26,9 @@
 [submodule "UnitTestFrameworkPkg/Library/SubhookLib/subhook"]
 	path = UnitTestFrameworkPkg/Library/SubhookLib/subhook
 	url = https://github.com/Zeex/subhook.git
-[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
-	path = MdePkg/Library/BaseFdtLib/libfdt
-	url = https://github.com/devicetree-org/pylibfdt.git
+[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
+	path = MdePkg/Library/BaseFdtLib/libfdt
+	url = https://github.com/devicetree-org/pylibfdt.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 2fb99f2a17..6fb7342f81 100644
--- a/.pytool/CISettings.py
+++ b/.pytool/CISettings.py
@@ -197,6 +197,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
             "UnitTestFrameworkPkg/Library/SubhookLib/subhook", False))
         rs.append(RequiredSubmodule(
             "MdePkg/Library/BaseFdtLib/libfdt", 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..4ced1c02cd
--- /dev/null
+++ b/MdePkg/Include/Library/MipiSysTLib.h
@@ -0,0 +1,66 @@
+/** @file
+This header file declares functions consuming MIPI Sys-T submodule.
+
+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_
+
+/**
+  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 RETURN_SUCCESS      MIPI_SYST_HANDLE instance was initialized.
+  @retval Other               MIPI_SYST_HANDLE instance was not initialized.
+**/
+RETURN_STATUS
+EFIAPI
+InitMipiSystHandle (
+  IN OUT VOID  *MipiSystHandle
+  );
+
+/**
+  Invoke write_debug_string function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        Severity type of input message.
+  @param[in]  Len             Length of data buffer.
+  @param[in]  Str             A pointer to data buffer.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_ABORTED               No data need to be written to Trace Hub.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle or Str is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteDebug (
+  IN        VOID    *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        Severity type of input message.
+  @param[in]  CatId           Catalog Id.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteCatalog (
+  IN  VOID    *MipiSystHandle,
+  IN  UINT32  Severity,
+  IN  UINT64  CatId
+  );
+
+#endif // MIPI_SYST_LIB_H_
diff --git a/MdePkg/Library/MipiSysTLib/GenMipiSystH.py b/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
new file mode 100644
index 0000000000..ee48285590
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
@@ -0,0 +1,132 @@
+## @file
+#  This python script update content from mipi_syst.h.in in mipi sys-T submodule
+#  and generate it as mipi_syst.h. mipi_syst.h include necessary data structure and
+#  definition that will be consumed by MipiSysTLib itself, mipi sys-T submodule
+#  and other library.
+#
+#  This script needs to be done once by a developer when adding some
+#  project-relating definition or a new version of mipi_syst.h.in is released.
+#  Normal users do not need to do this, since the resulting file is stored
+#  in the EDK2 git repository.
+#
+#  Customize structures mentioned below to generate updated mipi_syst.h file:
+#  1. ExistingValueToBeReplaced
+#       -> To replace existing value in mipi_syst.h.in to newer one.
+#  2. ExistingDefinitionToBeRemoved
+#       -> To #undef a existing definition in mipi_syst.h.in.
+#  3. NewItemToBeAdded
+#       -> Items in this structure will be placed at the end of mipi_syst.h as a customized section.
+#
+#  Run GenMipiSystH.py without any parameters as normal python script after customizing.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+import os
+import re
+
+#
+# A existing value to be customized should place this structure
+# Definitions in this customizable structure will be processed by ReplaceOldValue()
+# e.g:
+#   Before: @SYST_CFG_VERSION_MAJOR@
+#   After: 1
+#
+ExistingValueToBeReplaced = [
+    ["@SYST_CFG_VERSION_MAJOR@", "1"],      # Major version
+    ["@SYST_CFG_VERSION_MINOR@", "0"],      # Minor version
+    ["@SYST_CFG_VERSION_PATCH@", "0"],      # Patch version
+    ["@SYST_CFG_CONFORMANCE_LEVEL@", "30"], # Feature level of mipi sys-T submodule
+    ["mipi_syst/platform.h", "Platform.h"],
+]
+
+#
+# A existing definition to be removed should place this structure
+# Definitions in this customizable structure will be processed by RemoveDefinition()
+# e.g:
+#   Before:
+#       #define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#   After:
+#       #define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#       #undef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#
+ExistingDefinitionToBeRemoved = [
+    "MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA",
+    "MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY",
+    "MIPI_SYST_PCFG_ENABLE_PRINTF_API",
+    "MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD",
+    "MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS",
+]
+
+#
+# Items in this structure will be placed at the end of mipi_syst.h as a customized section.
+#
+NewItemToBeAdded = [
+    "typedef struct mipi_syst_handle_flags MIPI_SYST_HANDLE_FLAGS;",
+    "typedef struct mipi_syst_msg_tag MIPI_SYST_MSG_TAG;",
+    "typedef struct mipi_syst_guid MIPI_SYST_GUID;",
+    "typedef enum mipi_syst_severity MIPI_SYST_SEVERITY;",
+    "typedef struct mipi_syst_handle MIPI_SYST_HANDLE;",
+    "typedef struct mipi_syst_header MIPI_SYST_HEADER;",
+]
+
+def ProcessSpecialCharacter(Str):
+    Str = Str.rstrip(" \n")
+    Str = Str.replace("\t", "  ")
+    Str += "\n"
+    return Str
+
+def ReplaceOldValue(Str):
+    for i in range(len(ExistingValueToBeReplaced)):
+        Result = re.search(ExistingValueToBeReplaced[i][0], Str)
+        if Result is not None:
+            Str = Str.replace(ExistingValueToBeReplaced[i][0], ExistingValueToBeReplaced[i][1])
+            break
+    return Str
+
+def RemoveDefinition(Str):
+    Result = re.search("\*", Str)
+    if Result is None:
+        for i in range(len(ExistingDefinitionToBeRemoved)):
+            Result = re.search(ExistingDefinitionToBeRemoved[i], Str)
+            if Result is not None:
+                Result = re.search("defined", Str)
+                if Result is None:
+                    Str = Str + "#undef " + ExistingDefinitionToBeRemoved[i]
+                    break
+    return Str
+
+def main():
+    MipiSystHSrcDir = "mipisyst/library/include/mipi_syst.h.in"
+    MipiSystHRealSrcDir = os.path.join(os.getcwd(), os.path.normpath(MipiSystHSrcDir))
+    MipiSystHRealDstDir = os.path.join(os.getcwd(), "mipi_syst.h")
+
+    #
+    # Read content from mipi_syst.h.in and process each line by demand
+    #
+    with open(MipiSystHRealSrcDir, "r") as rfObj:
+        SrcFile = rfObj.readlines()
+        for lineIndex in range(len(SrcFile)):
+            SrcFile[lineIndex] = ProcessSpecialCharacter(SrcFile[lineIndex])
+            SrcFile[lineIndex] = ReplaceOldValue(SrcFile[lineIndex])
+            SrcFile[lineIndex] = RemoveDefinition(SrcFile[lineIndex])
+
+    #
+    # Typedef a structure or enum type
+    #
+    i = -1
+    for struct in NewItemToBeAdded:
+        struct += "\n"
+        SrcFile.insert(i, struct)
+        i -= 1
+
+    #
+    # Save edited content to mipi_syst.h
+    #
+    with open(MipiSystHRealDstDir, "w") as wfObj:
+        wfObj.writelines(SrcFile)
+
+if __name__ == '__main__':
+    main()
diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.c b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
new file mode 100644
index 0000000000..3a15a2af58
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
@@ -0,0 +1,123 @@
+/** @file
+This file provide functions to communicate with mipi sys-T submodule.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.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 RETURN_SUCCESS      MIPI_SYST_HANDLE instance was initialized.
+  @retval Other               MIPI_SYST_HANDLE instance was not initialized.
+**/
+RETURN_STATUS
+EFIAPI
+InitMipiSystHandle (
+  IN OUT VOID  *MipiSystHandle
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  if (MipiSystH == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  mipi_syst_init (MipiSystH->systh_header, 0, NULL);
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Invoke write_debug_string function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        Severity type of input message.
+  @param[in]  Len             Length of data buffer.
+  @param[in]  Str             A pointer to data buffer.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_ABORTED               No data need to be written to Trace Hub.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle or Str is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteDebug (
+  IN        MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN        UINT32            Severity,
+  IN        UINT16            Len,
+  IN CONST  CHAR8             *Str
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  if (MipiSystH == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (Len == 0) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return RETURN_ABORTED;
+  }
+
+  if (Str == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  mipi_syst_write_debug_string (
+    MipiSystH,
+    MIPI_SYST_NOLOCATION,
+    MIPI_SYST_STRING_GENERIC,
+    Severity,
+    Len,
+    Str
+    );
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Invoke catalog_write_message function in Mipi Sys-T module.
+
+  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]  Severity        Severity type of input message.
+  @param[in]  CatId           Catalog Id.
+
+  @retval RETURN_SUCCESS               Data in buffer was processed.
+  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle is a NULL pointer.
+**/
+RETURN_STATUS
+EFIAPI
+MipiSystWriteCatalog (
+  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
+  IN  UINT32            Severity,
+  IN  UINT64            CatId
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  if (MipiSystH == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  mipi_syst_write_catalog64_message (
+    MipiSystH,
+    MIPI_SYST_NOLOCATION,
+    Severity,
+    CatId
+    );
+
+  return RETURN_SUCCESS;
+}
diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
new file mode 100644
index 0000000000..b2aefcc9cc
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
@@ -0,0 +1,55 @@
+## @file
+#  A library providing funcitons to communicate with mipi sys-T submodule.
+#
+#  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:*_*_IA32_CC_FLAGS = /DMIPI_SYST_STATIC
+  MSFT:*_*_X64_CC_FLAGS  = /DMIPI_SYST_STATIC
+  GCC:*_*_IA32_CC_FLAGS  = -DMIPI_SYST_STATIC
+  GCC:*_*_X64_CC_FLAGS   = -DMIPI_SYST_STATIC
diff --git a/MdePkg/Library/MipiSysTLib/Platform.c b/MdePkg/Library/MipiSysTLib/Platform.c
new file mode 100644
index 0000000000..90a524bc1e
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.c
@@ -0,0 +1,164 @@
+/** @file
+This file defines functions that output Trace Hub message.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.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  VOID    *MipiSystHandle,
+  IN  UINT32  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite32 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT32  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite32 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT64  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite64 ((UINTN)(MipiSystH->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  VOID   *MipiSystHandle,
+  IN  UINT8  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite8 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT16  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite16 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT32  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite32 ((UINTN)(MipiSystH->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  VOID    *MipiSystHandle,
+  IN  UINT64  Data
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+  MmioWrite64 ((UINTN)(MipiSystH->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  VOID  *MipiSystHandle
+  )
+{
+  MIPI_SYST_HANDLE  *MipiSystH;
+
+  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
+
+  MmioWrite32 ((UINTN)(MipiSystH->systh_platform.TraceHubPlatformData.MmioAddr + 0x30), 0x0);
+}
diff --git a/MdePkg/Library/MipiSysTLib/Platform.h b/MdePkg/Library/MipiSysTLib/Platform.h
new file mode 100644
index 0000000000..ac77edf33d
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Platform.h
@@ -0,0 +1,138 @@
+/** @file
+This header file declares functions and structures.
+
+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_
+
+typedef struct {
+  UINT64    MmioAddr;
+} TRACE_HUB_PLATFORM_SYST_DATA;
+
+struct mipi_syst_platform_handle {
+  TRACE_HUB_PLATFORM_SYST_DATA    TraceHubPlatformData;
+};
+
+/**
+  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  VOID    *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  VOID    *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  VOID    *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  VOID   *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  VOID    *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  VOID    *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  VOID    *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  VOID  *MipiSystHandle
+  );
+
+#define MIPI_SYST_PLATFORM_CLOCK()  1000 // (unit: MicroSecond)
+
+#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/Readme.md b/MdePkg/Library/MipiSysTLib/Readme.md
new file mode 100644
index 0000000000..2e5df0194e
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/Readme.md
@@ -0,0 +1,25 @@
+## Introduction of MipiSysTLib ##
+MipiSysTLib library is a upper level library consuming MIPI SYS-T submodule.
+It provides MIPI-related APIs in EDK2 format to be consumed.
+
+## MipiSysTLib Version ##
+EDK2 supports building with v1.1+edk2 official version which was fully validated.
+
+## HOW to Install MipiSysTLib for UEFI Building ##
+MIPI SYS-T repository was added as a submodule of EDK2 project. Please
+refer to edk2/Readme.md for how to clone the code.
+
+## About GenMipiSystH.py ##
+"GenMipiSystH.py" is a Python script which is used for customizing the
+mipi_syst.h.in in mipi sys-T repository. The resulting file, mipi_syst.h, will
+be put to same folder level as this script.
+```
+  mipisyst submodule                        MipiSysTLib library
+|---------------------| GenMipiSystH.py   |---------------------|
+|   mipi_syst.h.in    |-----------------> |   mipi_syst.h       |
+|---------------------|                   |---------------------|
+```
+This script needs to be done once by a developer when adding some
+project-related definition or a new version of mipi_syst.h.in was released.
+Normal users do not need to do this, since the resulting file is stored
+in the EDK2 git repository.
diff --git a/MdePkg/Library/MipiSysTLib/mipi_syst.h b/MdePkg/Library/MipiSysTLib/mipi_syst.h
new file mode 100644
index 0000000000..3cf67a1ee5
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipi_syst.h
@@ -0,0 +1,789 @@
+/*
+Copyright (c) 2018, MIPI Alliance, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+* Neither the name of the copyright holder nor the names of its
+  contributors may be used to endorse or promote products derived
+  from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+ * Contributors:
+ * Norbert Schulz (Intel Corporation) - Initial API and implementation
+ */
+
+#ifndef MIPI_SYST_H_INCLUDED
+#define MIPI_SYST_H_INCLUDED
+
+/* 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
+#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
+
+#if defined(__cplusplus)
+extern "C" {
+#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
+};
+
+struct mipi_syst_header;
+struct mipi_syst_handle;
+struct mipi_syst_scatter_prog;
+
+/** 128-bit GUID style message origin ID */
+struct mipi_syst_guid {
+  union {
+    mipi_syst_u8  b[16];
+    mipi_syst_u64 ll[2];
+  } u;
+};
+
+/** 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);
+
+/**
+ * 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);
+
+#ifdef __cplusplus
+} /* extern C */
+#endif
+#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 Platform global SyS-T data state
+ *
+ * This define extends the global SyS-T state data structure
+ * mipi_syst_header with platform private content. A platform typically
+ * stores data for SyS-T handle creation processing in this structure.
+ *
+ * Note: This data is not touched by the library code itself, but typically
+ * is used by platform  hook functions for handle creation and destruction.
+ * **These hook function calls are not lock protected and may happen
+ * concurrently!**  The hook functions need to implement locking if they
+ *  modify the platform state data.
+ *
+ * The platform example uses #mipi_syst_platform_state as data state extension.
+ */
+#define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+#undef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
+/**
+ * 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
+
+/**
+ * Enable HEAP usage for handle generation
+ *
+ * This macro tells the SyS-T library to enable the heap allocation handle
+ * creation API #MIPI_SYST_ALLOC_HANDLE.
+ * The platform must provide the macros #MIPI_SYST_HEAP_MALLOC and
+ * #MIPI_SYST_HEAP_FREE to point SyS-T to the platform malloc and free
+ * functions.
+ *
+ * Note: In OS kernel space environments, you must use unpaged memory
+ * allocation functions.
+ */
+#define MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY
+#undef MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY
+/* 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
+ /**
+ * Enable printf API support
+ *
+ * Note:
+ * Enabling printf requires compiler var_arg support as defined by the
+ * header files stdarg.h stddef.h.
+ */
+
+#define MIPI_SYST_PCFG_ENABLE_PRINTF_API
+#undef MIPI_SYST_PCFG_ENABLE_PRINTF_API
+/**
+ * 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 the API variants that send file:line ID pair location records.
+ */
+#define MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
+#undef MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
+/**
+ * Enable the API variants that send the address of the instrumentation location.
+ *
+ * This API requires #MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD to be set as well.
+ * It uses its own define as it additionally requires the function
+ * @ref mipi_syst_return_addr() to be implemented for your platform.
+ */
+#define MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
+#undef MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
+/**
+ * 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
+#ifdef __cplusplus
+extern "C" {
+#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
+
+/** SyS-T global state structure.
+ * This structure is holding the global SyS-T library state
+ */
+struct mipi_syst_header {
+  mipi_syst_u32 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
+};
+
+/**
+ * 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.
+ */
+
+struct mipi_syst_msg_tag {
+#if defined(MIPI_SYST_BIG_ENDIAN)
+  mipi_syst_u32 et_res31 : 1;    /**< reserved for future use        */
+  mipi_syst_u32 et_res30 : 1;    /**< reserved for future use        */
+  mipi_syst_u32 et_subtype : 6;  /**< type dependent sub category    */
+  mipi_syst_u32 et_guid : 1;     /**< 128-bit GUID present           */
+  mipi_syst_u32 et_modunit : 11; /**< unit for GUID or module:unit   */
+  mipi_syst_u32 et_timestamp : 1;/**< indicate 64-bit timestamp      */
+  mipi_syst_u32 et_chksum : 1;   /**< indicate 32-bit CRC            */
+  mipi_syst_u32 et_length : 1;   /**< indicate length field          */
+  mipi_syst_u32 et_location : 1; /**< indicate location information  */
+  mipi_syst_u32 et_res7 : 1;     /**< reserved for future use        */
+  mipi_syst_u32 et_severity : 3; /**< severity level of message      */
+  mipi_syst_u32 et_type : 4;     /**< SyS-T message type ID          */
+#else
+  mipi_syst_u32 et_type : 4;     /**< SyS-T message type ID          */
+  mipi_syst_u32 et_severity : 3; /**< severity level of message      */
+  mipi_syst_u32 et_res7 : 1;     /**< reserved for future use        */
+  mipi_syst_u32 et_location : 1; /**< indicate location information  */
+  mipi_syst_u32 et_length : 1;   /**< indicate length field          */
+  mipi_syst_u32 et_chksum : 1;   /**< indicate 32-bit CRC            */
+  mipi_syst_u32 et_timestamp : 1;/**< indicate 64-bit timestamp      */
+  mipi_syst_u32 et_modunit : 11; /**< unit for GUID or module:unit   */
+  mipi_syst_u32 et_guid : 1;     /**< 128-bit GUID present           */
+  mipi_syst_u32 et_subtype : 6;  /**< type dependent sub category    */
+  mipi_syst_u32 et_res30 : 1;    /**< reserved for future use        */
+  mipi_syst_u32 et_res31 : 1;    /**< reserved for future use        */
+#endif
+};
+#define _MIPI_SYST_MK_MODUNIT_ORIGIN(m,u) (((u) & 0xF)|(m<<4))
+
+/**
+ * Message severity level enumeration
+ */
+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    */
+};
+
+/**
+ * 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;
+};
+
+/** internal handle state flags
+ */
+struct mipi_syst_handle_flags {
+  mipi_syst_u32 shf_alloc:1; /**< set to 1 if heap allocated handle */
+};
+
+/** 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.
+ */
+ 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
+
+  mipi_syst_u32 systh_param_count;          /**< number of parameters     */
+  mipi_syst_u32 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
+};
+
+
+#ifdef __cplusplus
+} /* extern C */
+#endif
+#ifndef MIPI_SYST_API_INCLUDED
+#include "mipi_syst/api.h"
+#endif
+
+typedef struct mipi_syst_header MIPI_SYST_HEADER;
+typedef struct mipi_syst_handle MIPI_SYST_HANDLE;
+typedef enum mipi_syst_severity MIPI_SYST_SEVERITY;
+typedef struct mipi_syst_guid MIPI_SYST_GUID;
+typedef struct mipi_syst_msg_tag MIPI_SYST_MSG_TAG;
+typedef struct mipi_syst_handle_flags MIPI_SYST_HANDLE_FLAGS;
+#endif
diff --git a/MdePkg/Library/MipiSysTLib/mipisyst b/MdePkg/Library/MipiSysTLib/mipisyst
new file mode 160000
index 0000000000..370b5944c0
--- /dev/null
+++ b/MdePkg/Library/MipiSysTLib/mipisyst
@@ -0,0 +1 @@
+Subproject commit 370b5944c046bab043dd8b133727b2135af7747a
diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
index 035c34b3ad..f024b48685 100644
--- a/MdePkg/MdePkg.ci.yaml
+++ b/MdePkg/MdePkg.ci.yaml
@@ -10,7 +10,10 @@
 {
     ## options defined .pytool/Plugin/LicenseCheck
     "LicenseCheck": {
-        "IgnoreFiles": []
+        "IgnoreFiles": [
+            # This file is copied from mipi sys-T submodule and generated by python script with customization.
+            "Library/MipiSysTLib/mipi_syst.h"
+        ]
     },
     "EccCheck": {
         ## Exception sample looks like below:
@@ -68,7 +71,8 @@
             "Include/Library/SafeIntLib.h",
             "Include/Protocol/DebugSupport.h",
             "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
-            "Library/BaseFdtLib"
+            "Library/BaseFdtLib",
+            "Library/MipiSysTLib/mipi_syst.h"
         ]
     },
     ## options defined ci/Plugin/CompilerPlugin
@@ -166,6 +170,7 @@
         "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should be ignore
         "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
     },
+
     # options defined in .pytool/Plugin/UncrustifyCheck
     "UncrustifyCheck": {
         "IgnoreFiles": [
@@ -175,7 +180,8 @@
             "Library/BaseFdtLib/stddef.h",
             "Library/BaseFdtLib/stdint.h",
             "Library/BaseFdtLib/stdlib.h",
-            "Library/BaseFdtLib/string.h"
+            "Library/BaseFdtLib/string.h",
+            "mipi_syst.h"
         ]
     }
 }
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index d6c4179b2a..d68ed988c0 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -28,6 +28,7 @@
   Include
   Test/UnitTest/Include
   Test/Mock/Include
+  Library/MipiSysTLib/mipisyst/library/include
 
 [Includes.IA32]
   Include/Ia32
@@ -293,6 +294,10 @@
   #
   FdtLib|Include/Library/FdtLib.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 b38c863812..902a39cffc 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -184,6 +184,7 @@
   MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
   MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
   MdePkg/Library/TdxLib/TdxLib.inf
+  MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 
 [Components.EBC]
   MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
diff --git a/ReadMe.rst b/ReadMe.rst
index d46c534229..ed1d482245 100644
--- a/ReadMe.rst
+++ b/ReadMe.rst
@@ -97,6 +97,7 @@ that are covered by additional licenses.
 -  `UnitTestFrameworkPkg/Library/SubhookLib/subhook <https://github.com/Zeex/subhook/blob/83d4e1ebef3588fae48b69a7352cc21801cb70bc/LICENSE.txt>`__
 -  `RedfishPkg/Library/JsonLib/jansson <https://github.com/akheron/jansson/blob/2882ead5bb90cf12a01b07b2c2361e24960fae02/LICENSE>`__
 -  `MdePkg/Library/BaseFdtLib/libfdt <https://github.com/devicetree-org/pylibfdt/blob/f39368a217496d32c4091a2dba4045b60649e3a5/BSD-2-Clause>`__
+-  `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.40.0.windows.1


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

* [PATCH 2/4] MdeModulePkg: Add TraceHubDebugSysTLib library
  2023-05-08  5:31 [PATCH 0/4] Trace Hub debug library support victorx.hsu
  2023-05-08  5:31 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
@ 2023-05-08  5:31 ` victorx.hsu
  2023-05-08 17:49   ` Michael D Kinney
  2023-05-08  5:31 ` [PATCH 3/4] MdePkg: Add NULL library of TraceHubDebugSysTLib victorx.hsu
  2023-05-08  5:31 ` [PATCH 4/4] Maintainers.txt: Update reviewers and maintainers for Trace Hub dbg lib victorx.hsu
  3 siblings, 1 reply; 10+ messages in thread
From: victorx.hsu @ 2023-05-08  5:31 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 provides API to dump Trace Hub message.

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>
---
 .../Include/Guid/TraceHubDebugInfoHob.h       |  25 ++
 .../BaseTraceHubDebugSysTLib.c                | 251 +++++++++++++++
 .../BaseTraceHubDebugSysTLib.inf              |  44 +++
 .../DxeSmmTraceHubDebugSysTLib.c              | 247 +++++++++++++++
 .../DxeSmmTraceHubDebugSysTLib.inf            |  50 +++
 .../InternalTraceHubApi.c                     |  82 +++++
 .../InternalTraceHubApi.h                     |  46 +++
 .../InternalTraceHubApiCommon.c               | 208 +++++++++++++
 .../InternalTraceHubApiCommon.h               | 119 +++++++
 .../PeiTraceHubDebugSysTLib.c                 | 290 ++++++++++++++++++
 .../PeiTraceHubDebugSysTLib.inf               |  50 +++
 .../Library/TraceHubDebugSysTLib/Readme.md    |  30 ++
 MdeModulePkg/MdeModulePkg.dec                 |  21 ++
 MdeModulePkg/MdeModulePkg.dsc                 |   3 +
 MdeModulePkg/MdeModulePkg.uni                 |  18 ++
 MdePkg/Include/Library/TraceHubDebugSysTLib.h |  81 +++++
 MdePkg/MdePkg.dec                             |   4 +
 17 files changed, 1569 insertions(+)
 create mode 100644 MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.h
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
 create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
 create mode 100644 MdePkg/Include/Library/TraceHubDebugSysTLib.h

diff --git a/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
new file mode 100644
index 0000000000..3a8fcc3d21
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
@@ -0,0 +1,25 @@
+/** @file
+This header file declares Trace Hub related structure.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef TRACE_HUB_DEBUG_INFO_HOB_H_
+#define TRACE_HUB_DEBUG_INFO_HOB_H_
+
+#define TRACEHUB_DEBUG_INFO_HOB_REVISION  1
+#define MAX_TRACE_HUB_DEBUG_INSTANCE      5
+
+typedef struct {
+  UINT16     Revision;            // Structure revision
+  BOOLEAN    Flag;                // Flag to enable or disable Trace Hub debug message.
+  UINT8      DebugLevel;          // Debug level for Trace Hub.
+  UINT8      Rvsd[4];             // Reserved for future use
+  UINT64     TraceHubMmioAddress; // MMIO address where Trace Hub debug message output to.
+} TRACEHUB_DEBUG_INFO_HOB;
+
+extern GUID  gTraceHubDebugInfoHobGuid;
+
+#endif // TRACE_HUB_DEBUG_INFO_HOB_H_
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
new file mode 100644
index 0000000000..fbf1cc2a9e
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
@@ -0,0 +1,251 @@
+/** @file
+System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.
+Only support single Trace Hub debug instance.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/TraceHubDebugSysTLib.h>
+#include <Library/MipiSysTLib.h>
+#include <Library/MipiSysTLib/mipi_syst.h>
+#include <Guid/TraceHubDebugInfoHob.h>
+#include "InternalTraceHubApiCommon.h"
+#include "InternalTraceHubApi.h"
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    The size of data buffer.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  RETURN_STATUS     Status;
+  UINT32            DbgInstCount;
+  UINT16            Index;
+
+  DbgInstCount = 0;
+
+  if (NumberOfBytes == 0) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return RETURN_ABORTED;
+  }
+
+  if (Buffer == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  DbgInstCount = CountThDebugInstance ();
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               NULL,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubDebugType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteDebug (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 (UINT16)NumberOfBytes,
+                 (CHAR8 *)Buffer
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN GUID                     *Guid
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  RETURN_STATUS     Status;
+  UINT32            DbgInstCount;
+  UINT16            Index;
+  GUID              ConvertedGuid;
+
+  DbgInstCount = 0;
+
+  if (Guid == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  DbgInstCount = CountThDebugInstance ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  ConvertedGuid = SwapBytesGuid (Guid);
+  CopyMem (&MipiSystHandle.systh_guid, &ConvertedGuid, sizeof (GUID));
+  MipiSystHandle.systh_tag.et_guid = 1;
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               NULL,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   Severity type of input message.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of entries in argument list.
+  @param[in]  ...            Catalog message parameters.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  VA_LIST           Args;
+  UINTN             Index;
+  RETURN_STATUS     Status;
+  UINT32            DbgInstCount;
+
+  DbgInstCount = 0;
+
+  if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT32)) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  DbgInstCount = CountThDebugInstance ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_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);
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               NULL,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Collect the total number of Trace Hub debug instance in the system.
+
+  @retval UINT32      The total number of Trace Hub debug instance in the system.
+**/
+UINT32
+EFIAPI
+CountThDebugInstance (
+  VOID
+  )
+{
+  UINT32  DbgInstCount;
+
+  //
+  // 1 from PCD.
+  //
+  DbgInstCount = 1;
+
+  return DbgInstCount;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf
new file mode 100644
index 0000000000..3edc4e8fd8
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf
@@ -0,0 +1,44 @@
+## @file
+#  Debug library to output Trace Hub message.
+#  Support SEC/PEI/DXE/SMM phase TraceHub debug message based on fixed settings.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseTraceHubDebugSysTLib
+  FILE_GUID                      = 336DA571-AD65-423C-9A43-E0056E5B2D8D
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugSysTLib
+
+#
+# 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
+  InternalTraceHubApiCommon.c
+  InternalTraceHubApiCommon.h
+  InternalTraceHubApi.h
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
new file mode 100644
index 0000000000..626e86c880
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.c
@@ -0,0 +1,247 @@
+/** @file
+System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB.
+Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug instances
+in the system.
+Trace Hub PCDs will be applied if no HOB exist.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/TraceHubDebugSysTLib.h>
+#include <Library/MipiSysTLib.h>
+#include <Library/MipiSysTLib/mipi_syst.h>
+#include <Guid/TraceHubDebugInfoHob.h>
+#include "InternalTraceHubApiCommon.h"
+#include "InternalTraceHubApi.h"
+
+GLOBAL_REMOVE_IF_UNREFERENCED TRACEHUB_DEBUG_INFO_HOB  mThDebugInstArray[MAX_TRACE_HUB_DEBUG_INSTANCE];
+GLOBAL_REMOVE_IF_UNREFERENCED UINT32                   mDbgInstCount = 0;
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    The size of data buffer.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  RETURN_STATUS     Status;
+  UINT16            Index;
+
+  if (NumberOfBytes == 0) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return RETURN_ABORTED;
+  }
+
+  if (Buffer == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (mDbgInstCount == 0) {
+    mDbgInstCount = CountThDebugInstance ();
+  }
+
+  if (mThDebugInstArray[0].TraceHubMmioAddress == 0) {
+    PackThDebugInstance (&mThDebugInstArray[0], mDbgInstCount);
+  }
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  for (Index = 0; Index < mDbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               (UINT8 *)&mThDebugInstArray[Index],
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubDebugType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteDebug (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 (UINT16)NumberOfBytes,
+                 (CHAR8 *)Buffer
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN GUID                     *Guid
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  UINTN             Index;
+  RETURN_STATUS     Status;
+  GUID              ConvertedGuid;
+
+  if (mDbgInstCount == 0) {
+    mDbgInstCount = CountThDebugInstance ();
+  }
+
+  if (mThDebugInstArray[0].TraceHubMmioAddress == 0) {
+    PackThDebugInstance (&mThDebugInstArray[0], mDbgInstCount);
+  }
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  if (Guid != NULL) {
+    ConvertedGuid = SwapBytesGuid (Guid);
+    CopyMem (&MipiSystHandle.systh_guid, &ConvertedGuid, sizeof (GUID));
+    MipiSystHandle.systh_tag.et_guid = 1;
+  } else {
+    MipiSystHandle.systh_tag.et_modunit = 2;
+    MipiSystHandle.systh_tag.et_guid    = 0;
+  }
+
+  for (Index = 0; Index < mDbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               (UINT8 *)&mThDebugInstArray[Index],
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   Severity type of input message.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of entries in argument list.
+  @param[in]  ...            Catalog message parameters.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  VA_LIST           Args;
+  UINTN             Index;
+  RETURN_STATUS     Status;
+
+  if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT32)) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (mDbgInstCount == 0) {
+    mDbgInstCount = CountThDebugInstance ();
+  }
+
+  if (mThDebugInstArray[0].TraceHubMmioAddress == 0) {
+    PackThDebugInstance (&mThDebugInstArray[0], mDbgInstCount);
+  }
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_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);
+
+  for (Index = 0; Index < mDbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               (UINT8 *)&mThDebugInstArray[Index],
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf
new file mode 100644
index 0000000000..9ba1b9c42f
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf
@@ -0,0 +1,50 @@
+## @file
+#  Debug library to output Trace Hub message.
+#  Support DXE/SMM phase TraceHub debug message based on fixed or dynamic settings.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeSmmTraceHubDebugSysTLib
+  FILE_GUID                      = A9B7B825-7902-4616-8556-085DA4DFEC72
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugSysTLib|DXE_CORE DXE_DRIVER SMM_CORE DXE_SMM_DRIVER 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
+  InternalTraceHubApiCommon.c
+  InternalTraceHubApiCommon.h
+  InternalTraceHubApi.h
+  InternalTraceHubApi.c
+
+[Guids]
+  gTraceHubDebugInfoHobGuid
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
new file mode 100644
index 0000000000..4f2dd0f2e5
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
@@ -0,0 +1,82 @@
+/** @file
+Functions implementation in this file are not common for all type of TraceHubDebugSysTLib.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Guid/TraceHubDebugInfoHob.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/HobLib.h>
+#include "InternalTraceHubApi.h"
+
+/**
+  Count the total number of Trace Hub debug instance in the system.
+
+  @retval UINT32      The total number of Trace Hub debug instance in the system.
+**/
+UINT32
+EFIAPI
+CountThDebugInstance (
+  VOID
+  )
+{
+  UINT8   *DgbContext;
+  UINT32  DbgInstCount;
+
+  DbgInstCount = 0;
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
+  if (DgbContext != NULL) {
+    while (DgbContext != NULL) {
+      DbgInstCount++;
+      DgbContext = (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
+    }
+  } else {
+    DbgInstCount++;
+  }
+
+  //
+  // Trace Hub HOB larger than MAX_TRACE_HUB_DEBUG_INSTANCE won't be processed.
+  //
+  if (DbgInstCount > MAX_TRACE_HUB_DEBUG_INSTANCE) {
+    DbgInstCount = MAX_TRACE_HUB_DEBUG_INSTANCE;
+  }
+
+  return DbgInstCount;
+}
+
+/**
+  Pack Trace Hub debug instances in the system.
+
+  @param[in, out]  ThPtr     A pointer to TRACEHUB_DEBUG_INFO_HOB structure.
+  @param[in]       Count     Number of Trace Hub HOBs.
+**/
+VOID
+EFIAPI
+PackThDebugInstance (
+  IN OUT TRACEHUB_DEBUG_INFO_HOB  *ThPtr,
+  IN     UINT32                   Count
+  )
+{
+  UINT8   *DgbContext;
+  UINT16  Index;
+
+  ZeroMem (ThPtr, sizeof (TRACEHUB_DEBUG_INFO_HOB) * MAX_TRACE_HUB_DEBUG_INSTANCE);
+  DgbContext = GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
+  if (DgbContext != NULL) {
+    for (Index = 0; Index < Count; Index++) {
+      CopyMem (&ThPtr[Index], GET_GUID_HOB_DATA (DgbContext), sizeof (TRACEHUB_DEBUG_INFO_HOB));
+      DgbContext = GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
+    }
+  } else {
+    for (Index = 0; Index < Count; Index++) {
+      ThPtr[Index].TraceHubMmioAddress = FixedPcdGet64 (PcdTraceHubDebugMmioAddress);
+      ThPtr[Index].Flag                = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
+      ThPtr[Index].DebugLevel          = FixedPcdGet8 (PcdTraceHubDebugLevel);
+    }
+  }
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
new file mode 100644
index 0000000000..a185c17d8c
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
@@ -0,0 +1,46 @@
+/** @file
+This header file declares functions that are not for common use.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef INTERNAL_TRACE_HUB_API_H_
+#define INTERNAL_TRACE_HUB_API_H_
+
+/**
+  Count the total number of Trace Hub debug instance in the system.
+
+  @retval UINT32      The total number of Trace Hub debug instance in the system.
+**/
+UINT32
+EFIAPI
+CountThDebugInstance (
+  VOID
+  );
+
+/**
+  Pack Trace Hub debug instances in the system.
+
+  @param[in, out]  ThPtr     A pointer to TRACEHUB_DEBUG_INFO_HOB structure.
+  @param[in]       Count     Number of Trace Hub HOBs.
+**/
+VOID
+EFIAPI
+PackThDebugInstance (
+  IN OUT TRACEHUB_DEBUG_INFO_HOB  *ThPtr,
+  IN     UINT32                   Count
+  );
+
+/**
+  Convert physical address to virtual address for the pointer to TRACEHUB_DEBUG_INFO_HOB structure.
+**/
+VOID
+EFIAPI
+InternalCreateThExitBootSvcEvent (
+  VOID
+  );
+
+#endif // INTERNAL_TRACE_HUB_API_H_
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c
new file mode 100644
index 0000000000..f32eb43192
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c
@@ -0,0 +1,208 @@
+/** @file
+Functions implementation defined in this file are common for all type of TraceHubDebugSysTLib
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/TraceHubDebugSysTLib.h>
+#include <Library/MipiSysTLib/mipi_syst.h>
+#include <Guid/TraceHubDebugInfoHob.h>
+#include "InternalTraceHubApiCommon.h"
+#include "InternalTraceHubApi.h"
+
+/**
+  Conditionally determine whether to enable Trace Hub message.
+
+  @param[in]  Flag            Flag to enable or disable Trace Hub message.
+  @param[in]  DbgLevel        Debug Level of Trace Hub.
+  @param[in]  SeverityType    Severity type of input message.
+
+  @retval TRUE            Enable trace hub message.
+  @retval FALSE           Disable trace hub message.
+**/
+BOOLEAN
+EFIAPI
+TraceHubDataEnabled (
+  IN BOOLEAN                  Flag,
+  IN UINT8                    DbgLevel,
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType
+  )
+{
+  if (Flag == 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 LE to BE or BE to LE.
+
+  @param[in]  Guid   GUID to be converted.
+
+  @retval RETURN_SUCCESS      Operation is successful.
+**/
+GUID
+EFIAPI
+SwapBytesGuid (
+  IN GUID  *Guid
+  )
+{
+  GUID    ConvertedGuid;
+  UINT64  GuidData4;
+
+  ZeroMem (&ConvertedGuid, sizeof (GUID));
+  ConvertedGuid.Data1 = SwapBytes32 (Guid->Data1);
+  ConvertedGuid.Data2 = SwapBytes16 (Guid->Data2);
+  ConvertedGuid.Data3 = SwapBytes16 (Guid->Data3);
+  CopyMem (&GuidData4, Guid->Data4, sizeof (Guid->Data4));
+  GuidData4 = SwapBytes64 (GuidData4);
+  CopyMem (ConvertedGuid.Data4, &GuidData4, sizeof (GuidData4));
+
+  return ConvertedGuid;
+}
+
+/**
+  Check whether to output Trace Hub message according to some conditions.
+  Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE
+  or Trace Hub MMIO address is 0.
+
+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]       DgbContext       A pointer to Trace Hub debug instance.
+  @param[in]       SeverityType     Severity type of input message.
+  @param[in]       PrintType        Either catalog print or debug print.
+
+  @retval RETURN_SUCCESS      Current Trace Hub message need to be output.
+  @retval Other               Current Trace Hub message will be disabled.
+**/
+RETURN_STATUS
+EFIAPI
+CheckWhetherToOutputMsg (
+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
+  IN     UINT8                    *DgbContext,
+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN     TRACEHUB_PRINTTYPE       PrintType
+  )
+{
+  UINT8          DbgLevel;
+  BOOLEAN        Flag;
+  UINT64         Addr;
+  RETURN_STATUS  Status;
+
+  if (MipiSystHandle == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (PrintType == TraceHubDebugType) {
+    Status = GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel);
+    if (RETURN_ERROR (Status)) {
+      return Status;
+    }
+
+    if (!TraceHubDataEnabled (Flag, DbgLevel, SeverityType)) {
+      return RETURN_ABORTED;
+    }
+  }
+
+  Status = GetTraceHubMmioAddress (DgbContext, &Addr);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;
+  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {
+    return RETURN_ABORTED;
+  }
+
+  return RETURN_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 RETURN_SUCCESS      Operation is successfully.
+  @retval Other               Operation is failed.
+**/
+RETURN_STATUS
+EFIAPI
+GetTraceHubMmioAddress (
+  IN     UINT8   *DgbContext,
+  IN OUT UINT64  *TraceAddress
+  )
+{
+  TRACEHUB_DEBUG_INFO_HOB  *ThDbgContext;
+
+  if (TraceAddress == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (DgbContext != NULL) {
+    ThDbgContext  = (TRACEHUB_DEBUG_INFO_HOB *)DgbContext;
+    *TraceAddress = ThDbgContext->TraceHubMmioAddress;
+  } else {
+    *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugMmioAddress);
+  }
+
+  return RETURN_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 RETURN_SUCCESS      Operation is successfully.
+  @retval Other               Operation is failed.
+**/
+RETURN_STATUS
+EFIAPI
+GetTraceHubMsgVisibility (
+  IN     UINT8    *DgbContext,
+  IN OUT BOOLEAN  *Flag,
+  IN OUT UINT8    *DbgLevel
+  )
+{
+  TRACEHUB_DEBUG_INFO_HOB  *ThDbgContext;
+
+  if ((Flag == NULL) || (DbgLevel == NULL)) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  if (DgbContext != NULL) {
+    ThDbgContext = (TRACEHUB_DEBUG_INFO_HOB *)DgbContext;
+    *Flag        = ThDbgContext->Flag;
+    *DbgLevel    = ThDbgContext->DebugLevel;
+  } else {
+    *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);
+    *Flag     = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
+  }
+
+  return RETURN_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.h b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.h
new file mode 100644
index 0000000000..771c4400af
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.h
@@ -0,0 +1,119 @@
+/** @file
+This header file declares functions and type for common use.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef INTERNAL_TRACE_HUB_API_COMMON_H_
+#define INTERNAL_TRACE_HUB_API_COMMON_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;
+
+/**
+  Conditionally determine whether to enable Trace Hub message.
+
+  @param[in]  Flag            Flag to enable or disable Trace Hub message.
+  @param[in]  DbgLevel        Debug Level of Trace Hub.
+  @param[in]  SeverityType    Severity type of input message.
+
+  @retval TRUE            Enable trace hub message.
+  @retval FALSE           Disable trace hub message.
+**/
+BOOLEAN
+EFIAPI
+TraceHubDataEnabled (
+  IN BOOLEAN                  Flag,
+  IN UINT8                    DbgLevel,
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType
+  );
+
+/**
+  Convert GUID from LE to BE or BE to LE.
+
+  @param[in]  Guid   GUID to be converted.
+
+  @retval RETURN_SUCCESS      Operation is successful.
+**/
+GUID
+EFIAPI
+SwapBytesGuid (
+  IN OUT GUID  *Guid
+  );
+
+/**
+  Check whether to output Trace Hub message according to some conditions.
+  Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE
+  or Trace Hub MMIO address is 0.
+
+  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE structure.
+  @param[in]       DgbContext       A pointer to Trace Hub debug instance.
+  @param[in]       SeverityType     Severity type of input message.
+  @param[in]       PrintType        Either catalog print or debug print.
+
+  @retval RETURN_SUCCESS      Current Trace Hub message need to be output.
+  @retval Other               Current Trace Hub message will be disabled.
+**/
+RETURN_STATUS
+EFIAPI
+CheckWhetherToOutputMsg (
+  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
+  IN     UINT8                    *DgbContext,
+  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN     TRACEHUB_PRINTTYPE       PrintType
+  );
+
+/**
+  Get Trace Hub MMIO Address.
+
+  @param[in]      DgbContext        A pointer to Trace Hub debug instance.
+  @param[in, out] TraceAddress      Trace Hub MMIO Address.
+
+  @retval RETURN_SUCCESS      Operation is successfully.
+  @retval Other               Operation is failed.
+**/
+RETURN_STATUS
+EFIAPI
+GetTraceHubMmioAddress (
+  IN     UINT8   *DgbContext,
+  IN OUT UINT64  *TraceAddress
+  );
+
+/**
+  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 RETURN_SUCCESS      Operation is successfully.
+  @retval Other               Operation is failed.
+**/
+RETURN_STATUS
+EFIAPI
+GetTraceHubMsgVisibility (
+  IN     UINT8    *DgbContext,
+  IN OUT BOOLEAN  *Flag,
+  IN OUT UINT8    *DbgLevel
+  );
+
+#endif // INTERNAL_TRACE_HUB_API_COMMON_H_
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
new file mode 100644
index 0000000000..fafd651499
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
@@ -0,0 +1,290 @@
+/** @file
+System prints Trace Hub message in PEI based on fixed PCDs and HOB.
+System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid HOB.
+Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug instances
+in the system.
+Trace Hub PCDs will be applied if no HOB exist.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/TraceHubDebugSysTLib.h>
+#include <Library/MipiSysTLib.h>
+#include <Library/MipiSysTLib/mipi_syst.h>
+#include <Guid/TraceHubDebugInfoHob.h>
+#include "InternalTraceHubApiCommon.h"
+#include "InternalTraceHubApi.h"
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    The size of data buffer.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  RETURN_STATUS     Status;
+  UINT8             *DgbContext;
+  UINTN             Index;
+  UINT32            DbgInstCount;
+  UINT8             *ThDebugInfo;
+
+  DbgInstCount = 0;
+
+  if (NumberOfBytes == 0) {
+    //
+    // No data need to be written to Trace Hub
+    //
+    return RETURN_ABORTED;
+  }
+
+  if (Buffer == NULL) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  DbgInstCount = CountThDebugInstance ();
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
+  if (DgbContext != NULL) {
+    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+  } else {
+    ThDebugInfo = NULL;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               ThDebugInfo,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubDebugType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteDebug (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 (UINT16)NumberOfBytes,
+                 (CHAR8 *)Buffer
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+
+    if (DgbContext != NULL) {
+      DgbContext = (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
+      if (DgbContext == NULL) {
+        break;
+      }
+
+      ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN GUID                     *Guid
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  UINT32            DbgInstCount;
+  UINT8             *DgbContext;
+  RETURN_STATUS     Status;
+  UINTN             Index;
+  UINT8             *ThDebugInfo;
+  GUID              ConvertedGuid;
+
+  DbgInstCount = 0;
+
+  DbgInstCount = CountThDebugInstance ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_ERROR (Status)) {
+    return Status;
+  }
+
+  if (Guid != NULL) {
+    ConvertedGuid = SwapBytesGuid (Guid);
+    CopyMem (&MipiSystHandle.systh_guid, &ConvertedGuid, sizeof (GUID));
+    MipiSystHandle.systh_tag.et_guid = 1;
+  } else {
+    MipiSystHandle.systh_tag.et_modunit = 2;
+    MipiSystHandle.systh_tag.et_guid    = 0;
+  }
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
+  if (DgbContext != NULL) {
+    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+  } else {
+    ThDebugInfo = NULL;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               ThDebugInfo,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+
+    if (DgbContext != NULL) {
+      DgbContext = (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
+      if (DgbContext == NULL) {
+        break;
+      }
+
+      ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+    }
+  }
+
+  return Status;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   Severity type of input message.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of entries in argument list.
+  @param[in]  ...            Catalog message parameters.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  )
+{
+  MIPI_SYST_HANDLE  MipiSystHandle;
+  MIPI_SYST_HEADER  MipiSystHeader;
+  VA_LIST           Args;
+  UINTN             Index;
+  UINT32            DbgInstCount;
+  UINT8             *DgbContext;
+  RETURN_STATUS     Status;
+  UINT8             *ThDebugInfo;
+
+  DbgInstCount = 0;
+
+  if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT32)) {
+    return RETURN_INVALID_PARAMETER;
+  }
+
+  DbgInstCount = CountThDebugInstance ();
+
+  MipiSystHandle.systh_header = &MipiSystHeader;
+
+  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
+  Status = InitMipiSystHandle (&MipiSystHandle);
+  if (RETURN_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);
+
+  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
+  if (DgbContext != NULL) {
+    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+  } else {
+    ThDebugInfo = NULL;
+  }
+
+  for (Index = 0; Index < DbgInstCount; Index++) {
+    Status = CheckWhetherToOutputMsg (
+               &MipiSystHandle,
+               ThDebugInfo,
+               (MIPI_SYST_SEVERITY)SeverityType,
+               TraceHubCatalogType
+               );
+    if (!RETURN_ERROR (Status)) {
+      Status = MipiSystWriteCatalog (
+                 &MipiSystHandle,
+                 (MIPI_SYST_SEVERITY)SeverityType,
+                 Id
+                 );
+      if (RETURN_ERROR (Status)) {
+        break;
+      }
+    }
+
+    if (DgbContext != NULL) {
+      DgbContext = (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
+      if (DgbContext == NULL) {
+        break;
+      }
+
+      ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
+    }
+  }
+
+  return Status;
+}
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
new file mode 100644
index 0000000000..2a8184d927
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
@@ -0,0 +1,50 @@
+## @file
+#  Debug library to output Trace Hub message.
+#  Support PEI phase TraceHub debug message based on fixed or dynamic settings.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PeiTraceHubDebugSysTLib
+  FILE_GUID                      = C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugSysTLib|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
+  InternalTraceHubApiCommon.c
+  InternalTraceHubApiCommon.h
+  InternalTraceHubApi.h
+  InternalTraceHubApi.c
+
+[Guids]
+  gTraceHubDebugInfoHobGuid
+
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
+  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress
diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
new file mode 100644
index 0000000000..24253eb223
--- /dev/null
+++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
@@ -0,0 +1,30 @@
+## Introduction of TrcaceHubDebugSysTLib ##
+TrcaceHubDebugSysTLib library is a top level library for dumping Trace Hub messages.
+It provides Trace Hub related APIs to dump Trace Hub message via MIPI SYS-T submodule.
+User need to properly configure following Trace Hub related PCDs and HOB.
+  (See MdeModulePkg.dec to get detailed definition for PCDs below)
+  - PcdTraceHubDebugLevel
+  - PcdEnableTraceHubDebugMsg
+  - PcdTraceHubDebugMmioAddress
+  (See TraceHubDebugInfoHob.h to get detailed definition for HOB below)
+  - gTraceHubDebugInfoHobGuid
+
+## BaseTraceHubDebugSysTLib.inf ##
+System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.
+Only support single Trace Hub debug instance.
+
+## PeiTraceHubDebugSysTLib.inf ##
+System prints Trace Hub message in PEI based on fixed PCDs and HOB.
+System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid HOB.
+Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug instances
+in the system.
+Trace Hub PCDs will be applied if no HOB exist.
+
+## DxeSmmTraceHubDebugSysTLib.inf ##
+System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB.
+Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug instances
+in the system.
+Trace Hub PCDs will be applied if no HOB exist.
+
+## Note ##
+Trace Hub debug library not support DXE_RUNTIME_DRIVER type of module currently.
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 3eb4a79bf7..42a1a8e338 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/Guid/TraceHubDebugInfoHob.h
+  gTraceHubDebugInfoHobGuid = { 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 } }
 
@@ -1094,6 +1097,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.PcdTraceHubDebugMmioAddress|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..5b1f50e9c0 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -515,6 +515,9 @@
   MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
   MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicationBufferDxe.inf
   MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
+  MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.inf
+  MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
+  MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTLib.inf
 
 [Components.X64]
   MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 33ce9f6198..a17d34d60b 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -1290,6 +1290,24 @@
                                                                                     "   TRUE  - UEFI Stack Guard will be enabled.<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_PcdTraceHubDebugMmioAddress_PROMPT  #language en-US "Output MMIO address of Trace Hub message"
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_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"
diff --git a/MdePkg/Include/Library/TraceHubDebugSysTLib.h b/MdePkg/Include/Library/TraceHubDebugSysTLib.h
new file mode 100644
index 0000000000..7df20e67d6
--- /dev/null
+++ b/MdePkg/Include/Library/TraceHubDebugSysTLib.h
@@ -0,0 +1,81 @@
+/** @file
+This header file declares Trace Hub related top level APIs.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef TRACE_HUB_DEBUG_SYST_LIB_H_
+#define TRACE_HUB_DEBUG_SYST_LIB_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     Severity type of input message.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    The size of data buffer.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  );
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN GUID                     *Guid
+  );
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   Severity type of input message.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of entries in argument list.
+  @param[in]  ...            Catalog message parameters.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  );
+
+#endif // TRACE_HUB_DEBUG_SYST_LIB_H_
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index d68ed988c0..597f4f7137 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -298,6 +298,10 @@
   #
   MipiSysTLib|Include/Library/MipiSysTLib.h
 
+  ##  @libraryclass  Provides API to output Trace Hub debug message.
+  #
+  TraceHubDebugSysTLib|Include/Library/TraceHubDebugSysTLib.h
+
 [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
   ##  @libraryclass  Provides services to generate random number.
   #
-- 
2.40.0.windows.1


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

* [PATCH 3/4] MdePkg: Add NULL library of TraceHubDebugSysTLib
  2023-05-08  5:31 [PATCH 0/4] Trace Hub debug library support victorx.hsu
  2023-05-08  5:31 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
  2023-05-08  5:31 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugSysTLib library victorx.hsu
@ 2023-05-08  5:31 ` victorx.hsu
  2023-05-08  5:31 ` [PATCH 4/4] Maintainers.txt: Update reviewers and maintainers for Trace Hub dbg lib victorx.hsu
  3 siblings, 0 replies; 10+ messages in thread
From: victorx.hsu @ 2023-05-08  5:31 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 of TraceHubDebugSysTLib.

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>
---
 .../TraceHubDebugSysTLibNull.c                | 76 +++++++++++++++++++
 .../TraceHubDebugSysTLibNull.inf              | 29 +++++++
 MdePkg/MdePkg.dsc                             |  1 +
 3 files changed, 106 insertions(+)
 create mode 100644 MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.c
 create mode 100644 MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf

diff --git a/MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.c b/MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.c
new file mode 100644
index 0000000000..0bd14d4e24
--- /dev/null
+++ b/MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.c
@@ -0,0 +1,76 @@
+/** @file
+Null library of TraceHubDebugSysTLib.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/TraceHubDebugSysTLib.h>
+
+/**
+  Write debug string to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Buffer           A pointer to the data buffer.
+  @param[in]  NumberOfBytes    The size of data buffer.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTDebugWrite (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT8                    *Buffer,
+  IN UINTN                    NumberOfBytes
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Write catalog status code message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType     Severity type of input message.
+  @param[in]  Id               Catalog ID.
+  @param[in]  Guid             Driver Guid.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64StatusCode (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN GUID                     *Guid
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Write catalog message to specified Trace Hub MMIO address.
+
+  @param[in]  SeverityType   Severity type of input message.
+  @param[in]  Id             Catalog ID.
+  @param[in]  NumberOfParams Number of entries in argument list.
+  @param[in]  ...            Catalog message parameters.
+
+  @retval RETURN_SUCCESS      Data was written to Trace Hub.
+  @retval Other               Failed to output Trace Hub message.
+**/
+RETURN_STATUS
+EFIAPI
+TraceHubSysTWriteCataLog64 (
+  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
+  IN UINT64                   Id,
+  IN UINTN                    NumberOfParams,
+  ...
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
diff --git a/MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf b/MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf
new file mode 100644
index 0000000000..ba894fc250
--- /dev/null
+++ b/MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf
@@ -0,0 +1,29 @@
+## @file
+#  Null library of TraceHubDebugSysTLib.
+#
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = TraceHubDebugSysTLibNull
+  FILE_GUID                      = 16196A4E-4196-4AF4-9A6B-F4D2ACC430A8
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TraceHubDebugSysTLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[Sources]
+  TraceHubDebugSysTLibNull.c
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 902a39cffc..536df8e0dc 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -184,6 +184,7 @@
   MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
   MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
   MdePkg/Library/TdxLib/TdxLib.inf
+  MdePkg/Library/TraceHubDebugSysTLibNull/TraceHubDebugSysTLibNull.inf
   MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
 
 [Components.EBC]
-- 
2.40.0.windows.1


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

* [PATCH 4/4] Maintainers.txt: Update reviewers and maintainers for Trace Hub dbg lib.
  2023-05-08  5:31 [PATCH 0/4] Trace Hub debug library support victorx.hsu
                   ` (2 preceding siblings ...)
  2023-05-08  5:31 ` [PATCH 3/4] MdePkg: Add NULL library of TraceHubDebugSysTLib victorx.hsu
@ 2023-05-08  5:31 ` victorx.hsu
  3 siblings, 0 replies; 10+ messages in thread
From: victorx.hsu @ 2023-05-08  5:31 UTC (permalink / raw)
  To: devel; +Cc: VictorX Hsu

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

Update reviewers and maintainers for TraceHubDebugSysTlib.

Signed-off-by: VictorX Hsu <victorx.hsu@intel.com>
---
 Maintainers.txt | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/Maintainers.txt b/Maintainers.txt
index 09d04af27a..30e2d2686d 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -437,6 +437,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 message related library instance
+F: MdeModulePkg/Library/TraceHubDebugSysTLib/
+F: MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
+M: Gua Guo <gua.guo@intel.com> [gguo11837463]
+M: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> [kprakas2]
+R: Chan Laura <laura.chan@intel.com> [lauracha]
+R: K N Karthik <karthik.k.n@intel.com> [karthikkabbigere1]
+
 MdePkg
 F: MdePkg/
 W: https://github.com/tianocore/tianocore.github.io/wiki/MdePkg
@@ -444,6 +452,16 @@ 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 message related library instance
+F: MdePkg/Library/TraceHubDebugSysTLibNull/
+F: MdePkg/Library/MipiSysTLib/
+F: MdePkg/Include/Library/TraceHubDebugSysTLib.h
+F: MdePkg/Include/Library/MipiSysTLib.h
+M: Gua Guo <gua.guo@intel.com> [gguo11837463]
+M: Prakashan Krishnadas Veliyathuparambil <krishnadas.veliyathuparambil.prakashan@intel.com> [kprakas2]
+R: Chan Laura <laura.chan@intel.com> [lauracha]
+R: K N Karthik <karthik.k.n@intel.com> [karthikkabbigere1]
+
 NetworkPkg
 F: NetworkPkg/
 W: https://github.com/tianocore/tianocore.github.io/wiki/NetworkPkg
-- 
2.40.0.windows.1


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

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

Hi Victor,

Comment on SwapBytesGuid() API below.  I believe there is a significant logic issues and an opportunity to simplify.  Please let me know if you found a different algorithm to perform GUID LE <-> BE conversions.

A second comment on the limit on max instances being 5.  Why is 5 selected?  The HOB list can support any number of instances and the consumers that need to cache the HOB state can do dynamical allocation using AllocatePool() to allocate space for the number of HOBs detected.

Mike

> -----Original Message-----
> From: Hsu, VictorX <victorx.hsu@intel.com>
> Sent: Sunday, May 7, 2023 10:32 PM
> 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 TraceHubDebugSysTLib library
> 
> From: VictorX Hsu <victorx.hsu@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144
> 
> This Library provides API to dump Trace Hub message.
> 
> 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>
> ---
>  .../Include/Guid/TraceHubDebugInfoHob.h       |  25 ++
>  .../BaseTraceHubDebugSysTLib.c                | 251 +++++++++++++++
>  .../BaseTraceHubDebugSysTLib.inf              |  44 +++
>  .../DxeSmmTraceHubDebugSysTLib.c              | 247 +++++++++++++++
>  .../DxeSmmTraceHubDebugSysTLib.inf            |  50 +++
>  .../InternalTraceHubApi.c                     |  82 +++++
>  .../InternalTraceHubApi.h                     |  46 +++
>  .../InternalTraceHubApiCommon.c               | 208 +++++++++++++
>  .../InternalTraceHubApiCommon.h               | 119 +++++++
>  .../PeiTraceHubDebugSysTLib.c                 | 290 ++++++++++++++++++
>  .../PeiTraceHubDebugSysTLib.inf               |  50 +++
>  .../Library/TraceHubDebugSysTLib/Readme.md    |  30 ++
>  MdeModulePkg/MdeModulePkg.dec                 |  21 ++
>  MdeModulePkg/MdeModulePkg.dsc                 |   3 +
>  MdeModulePkg/MdeModulePkg.uni                 |  18 ++
>  MdePkg/Include/Library/TraceHubDebugSysTLib.h |  81 +++++
>  MdePkg/MdePkg.dec                             |   4 +
>  17 files changed, 1569 insertions(+)
>  create mode 100644 MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.c
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.i
> nf
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTL
> ib.c
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTL
> ib.inf
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon
> .c
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon
> .h
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
>  create mode 100644
> MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
>  create mode 100644 MdePkg/Include/Library/TraceHubDebugSysTLib.h
> 
> diff --git a/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
> b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
> new file mode 100644
> index 0000000000..3a8fcc3d21
> --- /dev/null
> +++ b/MdeModulePkg/Include/Guid/TraceHubDebugInfoHob.h
> @@ -0,0 +1,25 @@
> +/** @file
> 
> +This header file declares Trace Hub related structure.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +**/
> 
> +
> 
> +#ifndef TRACE_HUB_DEBUG_INFO_HOB_H_
> 
> +#define TRACE_HUB_DEBUG_INFO_HOB_H_
> 
> +
> 
> +#define TRACEHUB_DEBUG_INFO_HOB_REVISION  1
> 
> +#define MAX_TRACE_HUB_DEBUG_INSTANCE      5

Why is this hard coded to 5 instances?  Can't all consumers use the number of instances of this GUIDed HOB that are present in the HOB list?

> 
> +
> 
> +typedef struct {
> 
> +  UINT16     Revision;            // Structure revision
> 
> +  BOOLEAN    Flag;                // Flag to enable or disable Trace Hub debug
> message.
> 
> +  UINT8      DebugLevel;          // Debug level for Trace Hub.
> 
> +  UINT8      Rvsd[4];             // Reserved for future use
> 
> +  UINT64     TraceHubMmioAddress; // MMIO address where Trace Hub
> debug message output to.
> 
> +} TRACEHUB_DEBUG_INFO_HOB;
> 
> +
> 
> +extern GUID  gTraceHubDebugInfoHobGuid;
> 
> +
> 
> +#endif // TRACE_HUB_DEBUG_INFO_HOB_H_
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib
> .c
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib
> .c
> new file mode 100644
> index 0000000000..fbf1cc2a9e
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib
> .c
> @@ -0,0 +1,251 @@
> +/** @file
> 
> +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.
> 
> +Only support single Trace Hub debug instance.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.h>
> 
> +#include <Library/BaseLib.h>
> 
> +#include <Library/PcdLib.h>
> 
> +#include <Library/BaseMemoryLib.h>
> 
> +#include <Library/TraceHubDebugSysTLib.h>
> 
> +#include <Library/MipiSysTLib.h>
> 
> +#include <Library/MipiSysTLib/mipi_syst.h>
> 
> +#include <Guid/TraceHubDebugInfoHob.h>
> 
> +#include "InternalTraceHubApiCommon.h"
> 
> +#include "InternalTraceHubApi.h"
> 
> +
> 
> +/**
> 
> +  Write debug string to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Buffer           A pointer to the data buffer.
> 
> +  @param[in]  NumberOfBytes    The size of data buffer.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTDebugWrite (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT8                    *Buffer,
> 
> +  IN UINTN                    NumberOfBytes
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINT32            DbgInstCount;
> 
> +  UINT16            Index;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  if (NumberOfBytes == 0) {
> 
> +    //
> 
> +    // No data need to be written to Trace Hub
> 
> +    //
> 
> +    return RETURN_ABORTED;
> 
> +  }
> 
> +
> 
> +  if (Buffer == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  DbgInstCount = CountThDebugInstance ();
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  for (Index = 0; Index < DbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               NULL,
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubDebugType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteDebug (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 (UINT16)NumberOfBytes,
> 
> +                 (CHAR8 *)Buffer
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Write catalog status code message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Id               Catalog ID.
> 
> +  @param[in]  Guid             Driver Guid.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64StatusCode (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN GUID                     *Guid
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINT32            DbgInstCount;
> 
> +  UINT16            Index;
> 
> +  GUID              ConvertedGuid;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  if (Guid == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  DbgInstCount = CountThDebugInstance ();
> 
> +
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  ConvertedGuid = SwapBytesGuid (Guid);
> 
> +  CopyMem (&MipiSystHandle.systh_guid, &ConvertedGuid, sizeof (GUID));
> 
> +  MipiSystHandle.systh_tag.et_guid = 1;
> 
> +
> 
> +  for (Index = 0; Index < DbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               NULL,
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubCatalogType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteCatalog (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 Id
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Write catalog message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType   Severity type of input message.
> 
> +  @param[in]  Id             Catalog ID.
> 
> +  @param[in]  NumberOfParams Number of entries in argument list.
> 
> +  @param[in]  ...            Catalog message parameters.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64 (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN UINTN                    NumberOfParams,
> 
> +  ...
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  VA_LIST           Args;
> 
> +  UINTN             Index;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINT32            DbgInstCount;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof
> (UINT32)) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  DbgInstCount = CountThDebugInstance ();
> 
> +
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_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);
> 
> +
> 
> +  for (Index = 0; Index < DbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               NULL,
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubCatalogType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteCatalog (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 Id
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Collect the total number of Trace Hub debug instance in the system.
> 
> +
> 
> +  @retval UINT32      The total number of Trace Hub debug instance in the
> system.
> 
> +**/
> 
> +UINT32
> 
> +EFIAPI
> 
> +CountThDebugInstance (
> 
> +  VOID
> 
> +  )
> 
> +{
> 
> +  UINT32  DbgInstCount;
> 
> +
> 
> +  //
> 
> +  // 1 from PCD.
> 
> +  //
> 
> +  DbgInstCount = 1;
> 
> +
> 
> +  return DbgInstCount;
> 
> +}
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib
> .inf
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib
> .inf
> new file mode 100644
> index 0000000000..3edc4e8fd8
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib
> .inf
> @@ -0,0 +1,44 @@
> +## @file
> 
> +#  Debug library to output Trace Hub message.
> 
> +#  Support SEC/PEI/DXE/SMM phase TraceHub debug message based on
> fixed settings.
> 
> +#
> 
> +#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +#
> 
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +#
> 
> +##
> 
> +
> 
> +[Defines]
> 
> +  INF_VERSION                    = 0x00010005
> 
> +  BASE_NAME                      = BaseTraceHubDebugSysTLib
> 
> +  FILE_GUID                      = 336DA571-AD65-423C-9A43-E0056E5B2D8D
> 
> +  MODULE_TYPE                    = BASE
> 
> +  VERSION_STRING                 = 1.0
> 
> +  LIBRARY_CLASS                  = TraceHubDebugSysTLib
> 
> +
> 
> +#
> 
> +# 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
> 
> +  InternalTraceHubApiCommon.c
> 
> +  InternalTraceHubApiCommon.h
> 
> +  InternalTraceHubApi.h
> 
> +
> 
> +[Pcd]
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys
> TLib.c
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys
> TLib.c
> new file mode 100644
> index 0000000000..626e86c880
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys
> TLib.c
> @@ -0,0 +1,247 @@
> +/** @file
> 
> +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB.
> 
> +Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug
> instances
> 
> +in the system.
> 
> +Trace Hub PCDs will be applied if no HOB exist.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.h>
> 
> +#include <Library/BaseLib.h>
> 
> +#include <Library/PcdLib.h>
> 
> +#include <Library/HobLib.h>
> 
> +#include <Library/BaseMemoryLib.h>
> 
> +#include <Library/MemoryAllocationLib.h>
> 
> +#include <Library/TraceHubDebugSysTLib.h>
> 
> +#include <Library/MipiSysTLib.h>
> 
> +#include <Library/MipiSysTLib/mipi_syst.h>
> 
> +#include <Guid/TraceHubDebugInfoHob.h>
> 
> +#include "InternalTraceHubApiCommon.h"
> 
> +#include "InternalTraceHubApi.h"
> 
> +
> 
> +GLOBAL_REMOVE_IF_UNREFERENCED TRACEHUB_DEBUG_INFO_HOB
> mThDebugInstArray[MAX_TRACE_HUB_DEBUG_INSTANCE];
> 
> +GLOBAL_REMOVE_IF_UNREFERENCED UINT32                   mDbgInstCount = 0;
> 
> +
> 
> +/**
> 
> +  Write debug string to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Buffer           A pointer to the data buffer.
> 
> +  @param[in]  NumberOfBytes    The size of data buffer.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTDebugWrite (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT8                    *Buffer,
> 
> +  IN UINTN                    NumberOfBytes
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINT16            Index;
> 
> +
> 
> +  if (NumberOfBytes == 0) {
> 
> +    //
> 
> +    // No data need to be written to Trace Hub
> 
> +    //
> 
> +    return RETURN_ABORTED;
> 
> +  }
> 
> +
> 
> +  if (Buffer == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  if (mDbgInstCount == 0) {
> 
> +    mDbgInstCount = CountThDebugInstance ();
> 
> +  }
> 
> +
> 
> +  if (mThDebugInstArray[0].TraceHubMmioAddress == 0) {
> 
> +    PackThDebugInstance (&mThDebugInstArray[0], mDbgInstCount);
> 
> +  }
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  for (Index = 0; Index < mDbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               (UINT8 *)&mThDebugInstArray[Index],
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubDebugType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteDebug (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 (UINT16)NumberOfBytes,
> 
> +                 (CHAR8 *)Buffer
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Write catalog status code message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Id               Catalog ID.
> 
> +  @param[in]  Guid             Driver Guid.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64StatusCode (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN GUID                     *Guid
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  UINTN             Index;
> 
> +  RETURN_STATUS     Status;
> 
> +  GUID              ConvertedGuid;
> 
> +
> 
> +  if (mDbgInstCount == 0) {
> 
> +    mDbgInstCount = CountThDebugInstance ();
> 
> +  }
> 
> +
> 
> +  if (mThDebugInstArray[0].TraceHubMmioAddress == 0) {
> 
> +    PackThDebugInstance (&mThDebugInstArray[0], mDbgInstCount);
> 
> +  }
> 
> +
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  if (Guid != NULL) {
> 
> +    ConvertedGuid = SwapBytesGuid (Guid);
> 
> +    CopyMem (&MipiSystHandle.systh_guid, &ConvertedGuid, sizeof (GUID));
> 
> +    MipiSystHandle.systh_tag.et_guid = 1;
> 
> +  } else {
> 
> +    MipiSystHandle.systh_tag.et_modunit = 2;
> 
> +    MipiSystHandle.systh_tag.et_guid    = 0;
> 
> +  }
> 
> +
> 
> +  for (Index = 0; Index < mDbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               (UINT8 *)&mThDebugInstArray[Index],
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubCatalogType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteCatalog (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 Id
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Write catalog message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType   Severity type of input message.
> 
> +  @param[in]  Id             Catalog ID.
> 
> +  @param[in]  NumberOfParams Number of entries in argument list.
> 
> +  @param[in]  ...            Catalog message parameters.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64 (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN UINTN                    NumberOfParams,
> 
> +  ...
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  VA_LIST           Args;
> 
> +  UINTN             Index;
> 
> +  RETURN_STATUS     Status;
> 
> +
> 
> +  if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof
> (UINT32)) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  if (mDbgInstCount == 0) {
> 
> +    mDbgInstCount = CountThDebugInstance ();
> 
> +  }
> 
> +
> 
> +  if (mThDebugInstArray[0].TraceHubMmioAddress == 0) {
> 
> +    PackThDebugInstance (&mThDebugInstArray[0], mDbgInstCount);
> 
> +  }
> 
> +
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_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);
> 
> +
> 
> +  for (Index = 0; Index < mDbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               (UINT8 *)&mThDebugInstArray[Index],
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubCatalogType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteCatalog (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 Id
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys
> TLib.inf
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys
> TLib.inf
> new file mode 100644
> index 0000000000..9ba1b9c42f
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSys
> TLib.inf
> @@ -0,0 +1,50 @@
> +## @file
> 
> +#  Debug library to output Trace Hub message.
> 
> +#  Support DXE/SMM phase TraceHub debug message based on fixed or
> dynamic settings.
> 
> +#
> 
> +#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +#
> 
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +#
> 
> +##
> 
> +
> 
> +[Defines]
> 
> +  INF_VERSION                    = 0x00010005
> 
> +  BASE_NAME                      = DxeSmmTraceHubDebugSysTLib
> 
> +  FILE_GUID                      = A9B7B825-7902-4616-8556-085DA4DFEC72
> 
> +  MODULE_TYPE                    = DXE_DRIVER
> 
> +  VERSION_STRING                 = 1.0
> 
> +  LIBRARY_CLASS                  = TraceHubDebugSysTLib|DXE_CORE DXE_DRIVER
> SMM_CORE DXE_SMM_DRIVER 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
> 
> +  InternalTraceHubApiCommon.c
> 
> +  InternalTraceHubApiCommon.h
> 
> +  InternalTraceHubApi.h
> 
> +  InternalTraceHubApi.c
> 
> +
> 
> +[Guids]
> 
> +  gTraceHubDebugInfoHobGuid
> 
> +
> 
> +[Pcd]
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
> new file mode 100644
> index 0000000000..4f2dd0f2e5
> --- /dev/null
> +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c
> @@ -0,0 +1,82 @@
> +/** @file
> 
> +Functions implementation in this file are not common for all type of
> TraceHubDebugSysTLib.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.h>
> 
> +#include <Guid/TraceHubDebugInfoHob.h>
> 
> +#include <Library/BaseMemoryLib.h>
> 
> +#include <Library/HobLib.h>
> 
> +#include "InternalTraceHubApi.h"
> 
> +
> 
> +/**
> 
> +  Count the total number of Trace Hub debug instance in the system.
> 
> +
> 
> +  @retval UINT32      The total number of Trace Hub debug instance in the
> system.
> 
> +**/
> 
> +UINT32
> 
> +EFIAPI
> 
> +CountThDebugInstance (
> 
> +  VOID
> 
> +  )
> 
> +{
> 
> +  UINT8   *DgbContext;
> 
> +  UINT32  DbgInstCount;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
> 
> +  if (DgbContext != NULL) {
> 
> +    while (DgbContext != NULL) {
> 
> +      DbgInstCount++;
> 
> +      DgbContext = (UINT8 *)GetNextGuidHob
> (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
> 
> +    }
> 
> +  } else {
> 
> +    DbgInstCount++;
> 
> +  }
> 
> +
> 
> +  //
> 
> +  // Trace Hub HOB larger than MAX_TRACE_HUB_DEBUG_INSTANCE won't
> be processed.
> 
> +  //
> 
> +  if (DbgInstCount > MAX_TRACE_HUB_DEBUG_INSTANCE) {
> 
> +    DbgInstCount = MAX_TRACE_HUB_DEBUG_INSTANCE;
> 
> +  }
> 
> +
> 
> +  return DbgInstCount;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Pack Trace Hub debug instances in the system.
> 
> +
> 
> +  @param[in, out]  ThPtr     A pointer to TRACEHUB_DEBUG_INFO_HOB
> structure.
> 
> +  @param[in]       Count     Number of Trace Hub HOBs.
> 
> +**/
> 
> +VOID
> 
> +EFIAPI
> 
> +PackThDebugInstance (
> 
> +  IN OUT TRACEHUB_DEBUG_INFO_HOB  *ThPtr,
> 
> +  IN     UINT32                   Count
> 
> +  )
> 
> +{
> 
> +  UINT8   *DgbContext;
> 
> +  UINT16  Index;
> 
> +
> 
> +  ZeroMem (ThPtr, sizeof (TRACEHUB_DEBUG_INFO_HOB) *
> MAX_TRACE_HUB_DEBUG_INSTANCE);
> 
> +  DgbContext = GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
> 
> +  if (DgbContext != NULL) {
> 
> +    for (Index = 0; Index < Count; Index++) {
> 
> +      CopyMem (&ThPtr[Index], GET_GUID_HOB_DATA (DgbContext), sizeof
> (TRACEHUB_DEBUG_INFO_HOB));
> 
> +      DgbContext = GetNextGuidHob (&gTraceHubDebugInfoHobGuid,
> GET_NEXT_HOB (DgbContext));
> 
> +    }
> 
> +  } else {
> 
> +    for (Index = 0; Index < Count; Index++) {
> 
> +      ThPtr[Index].TraceHubMmioAddress = FixedPcdGet64
> (PcdTraceHubDebugMmioAddress);
> 
> +      ThPtr[Index].Flag                = FixedPcdGetBool
> (PcdEnableTraceHubDebugMsg);
> 
> +      ThPtr[Index].DebugLevel          = FixedPcdGet8 (PcdTraceHubDebugLevel);
> 
> +    }
> 
> +  }
> 
> +}
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
> new file mode 100644
> index 0000000000..a185c17d8c
> --- /dev/null
> +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.h
> @@ -0,0 +1,46 @@
> +/** @file
> 
> +This header file declares functions that are not for common use.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef INTERNAL_TRACE_HUB_API_H_
> 
> +#define INTERNAL_TRACE_HUB_API_H_
> 
> +
> 
> +/**
> 
> +  Count the total number of Trace Hub debug instance in the system.
> 
> +
> 
> +  @retval UINT32      The total number of Trace Hub debug instance in the
> system.
> 
> +**/
> 
> +UINT32
> 
> +EFIAPI
> 
> +CountThDebugInstance (
> 
> +  VOID
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Pack Trace Hub debug instances in the system.
> 
> +
> 
> +  @param[in, out]  ThPtr     A pointer to TRACEHUB_DEBUG_INFO_HOB
> structure.
> 
> +  @param[in]       Count     Number of Trace Hub HOBs.
> 
> +**/
> 
> +VOID
> 
> +EFIAPI
> 
> +PackThDebugInstance (
> 
> +  IN OUT TRACEHUB_DEBUG_INFO_HOB  *ThPtr,
> 
> +  IN     UINT32                   Count
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Convert physical address to virtual address for the pointer to
> TRACEHUB_DEBUG_INFO_HOB structure.
> 
> +**/
> 
> +VOID
> 
> +EFIAPI
> 
> +InternalCreateThExitBootSvcEvent (
> 
> +  VOID
> 
> +  );
> 
> +
> 
> +#endif // INTERNAL_TRACE_HUB_API_H_
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm
> on.c
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm
> on.c
> new file mode 100644
> index 0000000000..f32eb43192
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm
> on.c
> @@ -0,0 +1,208 @@
> +/** @file
> 
> +Functions implementation defined in this file are common for all type of
> TraceHubDebugSysTLib
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.h>
> 
> +#include <Library/BaseLib.h>
> 
> +#include <Library/BaseMemoryLib.h>
> 
> +#include <Library/TraceHubDebugSysTLib.h>
> 
> +#include <Library/MipiSysTLib/mipi_syst.h>
> 
> +#include <Guid/TraceHubDebugInfoHob.h>
> 
> +#include "InternalTraceHubApiCommon.h"
> 
> +#include "InternalTraceHubApi.h"
> 
> +
> 
> +/**
> 
> +  Conditionally determine whether to enable Trace Hub message.
> 
> +
> 
> +  @param[in]  Flag            Flag to enable or disable Trace Hub message.
> 
> +  @param[in]  DbgLevel        Debug Level of Trace Hub.
> 
> +  @param[in]  SeverityType    Severity type of input message.
> 
> +
> 
> +  @retval TRUE            Enable trace hub message.
> 
> +  @retval FALSE           Disable trace hub message.
> 
> +**/
> 
> +BOOLEAN
> 
> +EFIAPI
> 
> +TraceHubDataEnabled (
> 
> +  IN BOOLEAN                  Flag,
> 
> +  IN UINT8                    DbgLevel,
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType
> 
> +  )
> 
> +{
> 
> +  if (Flag == 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 LE to BE or BE to LE.
> 
> +
> 
> +  @param[in]  Guid   GUID to be converted.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Operation is successful.
> 
> +**/
> 
> +GUID
> 
> +EFIAPI
> 
> +SwapBytesGuid (
> 
> +  IN GUID  *Guid
> 
> +  )
> 
> +{
> 
> +  GUID    ConvertedGuid;
> 
> +  UINT64  GuidData4;
> 
> +
> 
> +  ZeroMem (&ConvertedGuid, sizeof (GUID));
> 
> +  ConvertedGuid.Data1 = SwapBytes32 (Guid->Data1);
> 
> +  ConvertedGuid.Data2 = SwapBytes16 (Guid->Data2);
> 
> +  ConvertedGuid.Data3 = SwapBytes16 (Guid->Data3);
> 
> +  CopyMem (&GuidData4, Guid->Data4, sizeof (Guid->Data4));
> 
> +  GuidData4 = SwapBytes64 (GuidData4);
> 
> +  CopyMem (ConvertedGuid.Data4, &GuidData4, sizeof (GuidData4));
> 
> +
> 
> +  return ConvertedGuid;
> 
> +}

I do not think the algorithm in this API is correct.  I used python uuid module to generate a GUID and dump it as little endian and big endian.  The UINT32 and UINT16 fields are swapped, but the 8 byte array GuideData4 is left alone.

>>> [int(x) for x in a.bytes]
[157, 128, 47, 218, 201, 182, 17, 237, 164, 194, 84, 225, 173, 59, 241, 52]
>>> [int(x) for x in a.bytes_le]
[218, 47, 128, 157, 182, 201, 237, 17, 164, 194, 84, 225, 173, 59, 241, 52]

I think the following should be the simplified and correct version of this API.

RETURN_STATUS
EFIAPI
SwapBytesGuid (
  IN OUT GUID  *Guid
  )
{
  Guid->Data1 = SwapBytes32 (Guid->Data1);
  Guid->Data2 = SwapBytes16 (Guid->Data2);
  Guid->Data3 = SwapBytes16 (Guid->Data3);
  return RETURN_SUCCESS;
}


> 
> +
> 
> +/**
> 
> +  Check whether to output Trace Hub message according to some conditions.
> 
> +  Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE
> 
> +  or Trace Hub MMIO address is 0.
> 
> +
> 
> +  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE
> structure.
> 
> +  @param[in]       DgbContext       A pointer to Trace Hub debug instance.
> 
> +  @param[in]       SeverityType     Severity type of input message.
> 
> +  @param[in]       PrintType        Either catalog print or debug print.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Current Trace Hub message need to be
> output.
> 
> +  @retval Other               Current Trace Hub message will be disabled.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +CheckWhetherToOutputMsg (
> 
> +  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
> 
> +  IN     UINT8                    *DgbContext,
> 
> +  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN     TRACEHUB_PRINTTYPE       PrintType
> 
> +  )
> 
> +{
> 
> +  UINT8          DbgLevel;
> 
> +  BOOLEAN        Flag;
> 
> +  UINT64         Addr;
> 
> +  RETURN_STATUS  Status;
> 
> +
> 
> +  if (MipiSystHandle == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  if (PrintType == TraceHubDebugType) {
> 
> +    Status = GetTraceHubMsgVisibility (DgbContext, &Flag, &DbgLevel);
> 
> +    if (RETURN_ERROR (Status)) {
> 
> +      return Status;
> 
> +    }
> 
> +
> 
> +    if (!TraceHubDataEnabled (Flag, DbgLevel, SeverityType)) {
> 
> +      return RETURN_ABORTED;
> 
> +    }
> 
> +  }
> 
> +
> 
> +  Status = GetTraceHubMmioAddress (DgbContext, &Addr);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;
> 
> +  if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0)
> {
> 
> +    return RETURN_ABORTED;
> 
> +  }
> 
> +
> 
> +  return RETURN_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 RETURN_SUCCESS      Operation is successfully.
> 
> +  @retval Other               Operation is failed.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +GetTraceHubMmioAddress (
> 
> +  IN     UINT8   *DgbContext,
> 
> +  IN OUT UINT64  *TraceAddress
> 
> +  )
> 
> +{
> 
> +  TRACEHUB_DEBUG_INFO_HOB  *ThDbgContext;
> 
> +
> 
> +  if (TraceAddress == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  if (DgbContext != NULL) {
> 
> +    ThDbgContext  = (TRACEHUB_DEBUG_INFO_HOB *)DgbContext;
> 
> +    *TraceAddress = ThDbgContext->TraceHubMmioAddress;
> 
> +  } else {
> 
> +    *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugMmioAddress);
> 
> +  }
> 
> +
> 
> +  return RETURN_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 RETURN_SUCCESS      Operation is successfully.
> 
> +  @retval Other               Operation is failed.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +GetTraceHubMsgVisibility (
> 
> +  IN     UINT8    *DgbContext,
> 
> +  IN OUT BOOLEAN  *Flag,
> 
> +  IN OUT UINT8    *DbgLevel
> 
> +  )
> 
> +{
> 
> +  TRACEHUB_DEBUG_INFO_HOB  *ThDbgContext;
> 
> +
> 
> +  if ((Flag == NULL) || (DbgLevel == NULL)) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  if (DgbContext != NULL) {
> 
> +    ThDbgContext = (TRACEHUB_DEBUG_INFO_HOB *)DgbContext;
> 
> +    *Flag        = ThDbgContext->Flag;
> 
> +    *DbgLevel    = ThDbgContext->DebugLevel;
> 
> +  } else {
> 
> +    *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);
> 
> +    *Flag     = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
> 
> +  }
> 
> +
> 
> +  return RETURN_SUCCESS;
> 
> +}
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm
> on.h
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm
> on.h
> new file mode 100644
> index 0000000000..771c4400af
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiComm
> on.h
> @@ -0,0 +1,119 @@
> +/** @file
> 
> +This header file declares functions and type for common use.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef INTERNAL_TRACE_HUB_API_COMMON_H_
> 
> +#define INTERNAL_TRACE_HUB_API_COMMON_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;
> 
> +
> 
> +/**
> 
> +  Conditionally determine whether to enable Trace Hub message.
> 
> +
> 
> +  @param[in]  Flag            Flag to enable or disable Trace Hub message.
> 
> +  @param[in]  DbgLevel        Debug Level of Trace Hub.
> 
> +  @param[in]  SeverityType    Severity type of input message.
> 
> +
> 
> +  @retval TRUE            Enable trace hub message.
> 
> +  @retval FALSE           Disable trace hub message.
> 
> +**/
> 
> +BOOLEAN
> 
> +EFIAPI
> 
> +TraceHubDataEnabled (
> 
> +  IN BOOLEAN                  Flag,
> 
> +  IN UINT8                    DbgLevel,
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Convert GUID from LE to BE or BE to LE.
> 
> +
> 
> +  @param[in]  Guid   GUID to be converted.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Operation is successful.
> 
> +**/
> 
> +GUID
> 
> +EFIAPI
> 
> +SwapBytesGuid (
> 
> +  IN OUT GUID  *Guid
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Check whether to output Trace Hub message according to some conditions.
> 
> +  Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE
> 
> +  or Trace Hub MMIO address is 0.
> 
> +
> 
> +  @param[in, out]  MipiSystHandle   A pointer to MIPI_SYST_HANDLE
> structure.
> 
> +  @param[in]       DgbContext       A pointer to Trace Hub debug instance.
> 
> +  @param[in]       SeverityType     Severity type of input message.
> 
> +  @param[in]       PrintType        Either catalog print or debug print.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Current Trace Hub message need to be
> output.
> 
> +  @retval Other               Current Trace Hub message will be disabled.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +CheckWhetherToOutputMsg (
> 
> +  IN OUT MIPI_SYST_HANDLE         *MipiSystHandle,
> 
> +  IN     UINT8                    *DgbContext,
> 
> +  IN     TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN     TRACEHUB_PRINTTYPE       PrintType
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Get Trace Hub MMIO Address.
> 
> +
> 
> +  @param[in]      DgbContext        A pointer to Trace Hub debug instance.
> 
> +  @param[in, out] TraceAddress      Trace Hub MMIO Address.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Operation is successfully.
> 
> +  @retval Other               Operation is failed.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +GetTraceHubMmioAddress (
> 
> +  IN     UINT8   *DgbContext,
> 
> +  IN OUT UINT64  *TraceAddress
> 
> +  );
> 
> +
> 
> +/**
> 
> +  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 RETURN_SUCCESS      Operation is successfully.
> 
> +  @retval Other               Operation is failed.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +GetTraceHubMsgVisibility (
> 
> +  IN     UINT8    *DgbContext,
> 
> +  IN OUT BOOLEAN  *Flag,
> 
> +  IN OUT UINT8    *DbgLevel
> 
> +  );
> 
> +
> 
> +#endif // INTERNAL_TRACE_HUB_API_COMMON_H_
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
> new file mode 100644
> index 0000000000..fafd651499
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.c
> @@ -0,0 +1,290 @@
> +/** @file
> 
> +System prints Trace Hub message in PEI based on fixed PCDs and HOB.
> 
> +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid
> HOB.
> 
> +Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug
> instances
> 
> +in the system.
> 
> +Trace Hub PCDs will be applied if no HOB exist.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.h>
> 
> +#include <Library/BaseLib.h>
> 
> +#include <Library/PcdLib.h>
> 
> +#include <Library/HobLib.h>
> 
> +#include <Library/BaseMemoryLib.h>
> 
> +#include <Library/MemoryAllocationLib.h>
> 
> +#include <Library/TraceHubDebugSysTLib.h>
> 
> +#include <Library/MipiSysTLib.h>
> 
> +#include <Library/MipiSysTLib/mipi_syst.h>
> 
> +#include <Guid/TraceHubDebugInfoHob.h>
> 
> +#include "InternalTraceHubApiCommon.h"
> 
> +#include "InternalTraceHubApi.h"
> 
> +
> 
> +/**
> 
> +  Write debug string to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Buffer           A pointer to the data buffer.
> 
> +  @param[in]  NumberOfBytes    The size of data buffer.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTDebugWrite (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT8                    *Buffer,
> 
> +  IN UINTN                    NumberOfBytes
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINT8             *DgbContext;
> 
> +  UINTN             Index;
> 
> +  UINT32            DbgInstCount;
> 
> +  UINT8             *ThDebugInfo;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  if (NumberOfBytes == 0) {
> 
> +    //
> 
> +    // No data need to be written to Trace Hub
> 
> +    //
> 
> +    return RETURN_ABORTED;
> 
> +  }
> 
> +
> 
> +  if (Buffer == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  DbgInstCount = CountThDebugInstance ();
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
> 
> +  if (DgbContext != NULL) {
> 
> +    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
> 
> +  } else {
> 
> +    ThDebugInfo = NULL;
> 
> +  }
> 
> +
> 
> +  for (Index = 0; Index < DbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               ThDebugInfo,
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubDebugType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteDebug (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 (UINT16)NumberOfBytes,
> 
> +                 (CHAR8 *)Buffer
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +
> 
> +    if (DgbContext != NULL) {
> 
> +      DgbContext = (UINT8 *)GetNextGuidHob
> (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
> 
> +      if (DgbContext == NULL) {
> 
> +        break;
> 
> +      }
> 
> +
> 
> +      ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Write catalog status code message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Id               Catalog ID.
> 
> +  @param[in]  Guid             Driver Guid.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64StatusCode (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN GUID                     *Guid
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  UINT32            DbgInstCount;
> 
> +  UINT8             *DgbContext;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINTN             Index;
> 
> +  UINT8             *ThDebugInfo;
> 
> +  GUID              ConvertedGuid;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  DbgInstCount = CountThDebugInstance ();
> 
> +
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_ERROR (Status)) {
> 
> +    return Status;
> 
> +  }
> 
> +
> 
> +  if (Guid != NULL) {
> 
> +    ConvertedGuid = SwapBytesGuid (Guid);
> 
> +    CopyMem (&MipiSystHandle.systh_guid, &ConvertedGuid, sizeof (GUID));
> 
> +    MipiSystHandle.systh_tag.et_guid = 1;
> 
> +  } else {
> 
> +    MipiSystHandle.systh_tag.et_modunit = 2;
> 
> +    MipiSystHandle.systh_tag.et_guid    = 0;
> 
> +  }
> 
> +
> 
> +  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
> 
> +  if (DgbContext != NULL) {
> 
> +    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
> 
> +  } else {
> 
> +    ThDebugInfo = NULL;
> 
> +  }
> 
> +
> 
> +  for (Index = 0; Index < DbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               ThDebugInfo,
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubCatalogType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteCatalog (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 Id
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +
> 
> +    if (DgbContext != NULL) {
> 
> +      DgbContext = (UINT8 *)GetNextGuidHob
> (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
> 
> +      if (DgbContext == NULL) {
> 
> +        break;
> 
> +      }
> 
> +
> 
> +      ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Write catalog message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType   Severity type of input message.
> 
> +  @param[in]  Id             Catalog ID.
> 
> +  @param[in]  NumberOfParams Number of entries in argument list.
> 
> +  @param[in]  ...            Catalog message parameters.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64 (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN UINTN                    NumberOfParams,
> 
> +  ...
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  MipiSystHandle;
> 
> +  MIPI_SYST_HEADER  MipiSystHeader;
> 
> +  VA_LIST           Args;
> 
> +  UINTN             Index;
> 
> +  UINT32            DbgInstCount;
> 
> +  UINT8             *DgbContext;
> 
> +  RETURN_STATUS     Status;
> 
> +  UINT8             *ThDebugInfo;
> 
> +
> 
> +  DbgInstCount = 0;
> 
> +
> 
> +  if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof
> (UINT32)) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  DbgInstCount = CountThDebugInstance ();
> 
> +
> 
> +  MipiSystHandle.systh_header = &MipiSystHeader;
> 
> +
> 
> +  ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
> 
> +  Status = InitMipiSystHandle (&MipiSystHandle);
> 
> +  if (RETURN_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);
> 
> +
> 
> +  DgbContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid);
> 
> +  if (DgbContext != NULL) {
> 
> +    ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
> 
> +  } else {
> 
> +    ThDebugInfo = NULL;
> 
> +  }
> 
> +
> 
> +  for (Index = 0; Index < DbgInstCount; Index++) {
> 
> +    Status = CheckWhetherToOutputMsg (
> 
> +               &MipiSystHandle,
> 
> +               ThDebugInfo,
> 
> +               (MIPI_SYST_SEVERITY)SeverityType,
> 
> +               TraceHubCatalogType
> 
> +               );
> 
> +    if (!RETURN_ERROR (Status)) {
> 
> +      Status = MipiSystWriteCatalog (
> 
> +                 &MipiSystHandle,
> 
> +                 (MIPI_SYST_SEVERITY)SeverityType,
> 
> +                 Id
> 
> +                 );
> 
> +      if (RETURN_ERROR (Status)) {
> 
> +        break;
> 
> +      }
> 
> +    }
> 
> +
> 
> +    if (DgbContext != NULL) {
> 
> +      DgbContext = (UINT8 *)GetNextGuidHob
> (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DgbContext));
> 
> +      if (DgbContext == NULL) {
> 
> +        break;
> 
> +      }
> 
> +
> 
> +      ThDebugInfo = GET_GUID_HOB_DATA (DgbContext);
> 
> +    }
> 
> +  }
> 
> +
> 
> +  return Status;
> 
> +}
> 
> diff --git
> a/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.i
> nf
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.i
> nf
> new file mode 100644
> index 0000000000..2a8184d927
> --- /dev/null
> +++
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.i
> nf
> @@ -0,0 +1,50 @@
> +## @file
> 
> +#  Debug library to output Trace Hub message.
> 
> +#  Support PEI phase TraceHub debug message based on fixed or dynamic
> settings.
> 
> +#
> 
> +#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +#
> 
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +#
> 
> +##
> 
> +
> 
> +[Defines]
> 
> +  INF_VERSION                    = 0x00010005
> 
> +  BASE_NAME                      = PeiTraceHubDebugSysTLib
> 
> +  FILE_GUID                      = C61E8C2E-0935-4E3D-BCBB-5ED84AFD9FD1
> 
> +  MODULE_TYPE                    = PEIM
> 
> +  VERSION_STRING                 = 1.0
> 
> +  LIBRARY_CLASS                  = TraceHubDebugSysTLib|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
> 
> +  InternalTraceHubApiCommon.c
> 
> +  InternalTraceHubApiCommon.h
> 
> +  InternalTraceHubApi.h
> 
> +  InternalTraceHubApi.c
> 
> +
> 
> +[Guids]
> 
> +  gTraceHubDebugInfoHobGuid
> 
> +
> 
> +[Pcd]
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugLevel
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdEnableTraceHubDebugMsg
> 
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress
> 
> diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
> b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
> new file mode 100644
> index 0000000000..24253eb223
> --- /dev/null
> +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/Readme.md
> @@ -0,0 +1,30 @@
> +## Introduction of TrcaceHubDebugSysTLib ##
> 
> +TrcaceHubDebugSysTLib library is a top level library for dumping Trace Hub
> messages.
> 
> +It provides Trace Hub related APIs to dump Trace Hub message via MIPI SYS-
> T submodule.
> 
> +User need to properly configure following Trace Hub related PCDs and HOB.
> 
> +  (See MdeModulePkg.dec to get detailed definition for PCDs below)
> 
> +  - PcdTraceHubDebugLevel
> 
> +  - PcdEnableTraceHubDebugMsg
> 
> +  - PcdTraceHubDebugMmioAddress
> 
> +  (See TraceHubDebugInfoHob.h to get detailed definition for HOB below)
> 
> +  - gTraceHubDebugInfoHobGuid
> 
> +
> 
> +## BaseTraceHubDebugSysTLib.inf ##
> 
> +System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.
> 
> +Only support single Trace Hub debug instance.
> 
> +
> 
> +## PeiTraceHubDebugSysTLib.inf ##
> 
> +System prints Trace Hub message in PEI based on fixed PCDs and HOB.
> 
> +System applies Trace Hub HOB once it detect gTraceHubDebugInfoHobGuid
> HOB.
> 
> +Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug
> instances
> 
> +in the system.
> 
> +Trace Hub PCDs will be applied if no HOB exist.
> 
> +
> 
> +## DxeSmmTraceHubDebugSysTLib.inf ##
> 
> +System prints Trace Hub message in DXE/SMM based on fixed PCDs and HOB.
> 
> +Support at most MAX_TRACE_HUB_DEBUG_INSTANCE of Trace Hub debug
> instances
> 
> +in the system.
> 
> +Trace Hub PCDs will be applied if no HOB exist.
> 
> +
> 
> +## Note ##
> 
> +Trace Hub debug library not support DXE_RUNTIME_DRIVER type of module
> currently.
> 
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec
> index 3eb4a79bf7..42a1a8e338 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/Guid/TraceHubDebugInfoHob.h
> 
> +  gTraceHubDebugInfoHobGuid = { 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 } }
> 
> 
> 
> @@ -1094,6 +1097,24 @@
>    # @Prompt Enable UEFI Stack Guard.
> 
> 
> gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30
> 001055
> 
> 
> 
> +  ## 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|0x3000
> 1056
> 
> +
> 
> +  ## 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|BOOLEA
> N|0x30001057
> 
> +
> 
> +  ## Indicate MMIO address where Trace Hub message output to.
> 
> +  # @Prompt Output MMIO address of Trace Hub message.
> 
> +
> gEfiMdeModulePkgTokenSpaceGuid.PcdTraceHubDebugMmioAddress|0|UINT
> 64|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..5b1f50e9c0 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -515,6 +515,9 @@
>    MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
> 
> 
> MdeModulePkg/Universal/SmmCommunicationBufferDxe/SmmCommunicatio
> nBufferDxe.inf
> 
>    MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
> 
> +
> MdeModulePkg/Library/TraceHubDebugSysTLib/BaseTraceHubDebugSysTLib.i
> nf
> 
> +
> MdeModulePkg/Library/TraceHubDebugSysTLib/PeiTraceHubDebugSysTLib.inf
> 
> +
> MdeModulePkg/Library/TraceHubDebugSysTLib/DxeSmmTraceHubDebugSysTL
> ib.inf
> 
> 
> 
>  [Components.X64]
> 
>    MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
> 
> diff --git a/MdeModulePkg/MdeModulePkg.uni
> b/MdeModulePkg/MdeModulePkg.uni
> index 33ce9f6198..a17d34d60b 100644
> --- a/MdeModulePkg/MdeModulePkg.uni
> +++ b/MdeModulePkg/MdeModulePkg.uni
> @@ -1290,6 +1290,24 @@
>                                                                                      "   TRUE  - UEFI Stack Guard
> will be enabled.<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_PRO
> MPT  #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_PcdTraceHubDebugMmioAddress_P
> ROMPT  #language en-US "Output MMIO address of Trace Hub message"
> 
> +
> 
> +#string
> STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTraceHubDebugMmioAddress_H
> ELP    #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"
> 
> diff --git a/MdePkg/Include/Library/TraceHubDebugSysTLib.h
> b/MdePkg/Include/Library/TraceHubDebugSysTLib.h
> new file mode 100644
> index 0000000000..7df20e67d6
> --- /dev/null
> +++ b/MdePkg/Include/Library/TraceHubDebugSysTLib.h
> @@ -0,0 +1,81 @@
> +/** @file
> 
> +This header file declares Trace Hub related top level APIs.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef TRACE_HUB_DEBUG_SYST_LIB_H_
> 
> +#define TRACE_HUB_DEBUG_SYST_LIB_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     Severity type of input message.
> 
> +  @param[in]  Buffer           A pointer to the data buffer.
> 
> +  @param[in]  NumberOfBytes    The size of data buffer.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTDebugWrite (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT8                    *Buffer,
> 
> +  IN UINTN                    NumberOfBytes
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Write catalog status code message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType     Severity type of input message.
> 
> +  @param[in]  Id               Catalog ID.
> 
> +  @param[in]  Guid             Driver Guid.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64StatusCode (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN GUID                     *Guid
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Write catalog message to specified Trace Hub MMIO address.
> 
> +
> 
> +  @param[in]  SeverityType   Severity type of input message.
> 
> +  @param[in]  Id             Catalog ID.
> 
> +  @param[in]  NumberOfParams Number of entries in argument list.
> 
> +  @param[in]  ...            Catalog message parameters.
> 
> +
> 
> +  @retval RETURN_SUCCESS      Data was written to Trace Hub.
> 
> +  @retval Other               Failed to output Trace Hub message.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +TraceHubSysTWriteCataLog64 (
> 
> +  IN TRACE_HUB_SEVERITY_TYPE  SeverityType,
> 
> +  IN UINT64                   Id,
> 
> +  IN UINTN                    NumberOfParams,
> 
> +  ...
> 
> +  );
> 
> +
> 
> +#endif // TRACE_HUB_DEBUG_SYST_LIB_H_
> 
> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
> index d68ed988c0..597f4f7137 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -298,6 +298,10 @@
>    #
> 
>    MipiSysTLib|Include/Library/MipiSysTLib.h
> 
> 
> 
> +  ##  @libraryclass  Provides API to output Trace Hub debug message.
> 
> +  #
> 
> +  TraceHubDebugSysTLib|Include/Library/TraceHubDebugSysTLib.h
> 
> +
> 
>  [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64]
> 
>    ##  @libraryclass  Provides services to generate random number.
> 
>    #
> 
> --
> 2.40.0.windows.1


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

* Re: [PATCH 1/4] MdePkg: Add MipiSysTLib library
  2023-05-08  5:31 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
@ 2023-05-08 17:54   ` Michael D Kinney
  0 siblings, 0 replies; 10+ messages in thread
From: Michael D Kinney @ 2023-05-08 17:54 UTC (permalink / raw)
  To: Hsu, VictorX, devel@edk2.groups.io
  Cc: Guo, Gua, Chan, Laura, Prakashan, Krishnadas Veliyathuparambil,
	K N, Karthik, Kinney, Michael D

Update to INF to simplify [BuildOptions] section below.

Mike

> -----Original Message-----
> From: Hsu, VictorX <victorx.hsu@intel.com>
> Sent: Sunday, May 7, 2023 10:32 PM
> 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
> 
> This Library provides functions consuming MIPI SYS-T submodule.
> 
> 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                                |  11 +-
>  .pytool/CISettings.py                      |   2 +
>  MdePkg/Include/Library/MipiSysTLib.h       |  66 ++
>  MdePkg/Library/MipiSysTLib/GenMipiSystH.py | 132 ++++
>  MdePkg/Library/MipiSysTLib/MipiSysTLib.c   | 123 ++++
>  MdePkg/Library/MipiSysTLib/MipiSysTLib.inf |  55 ++
>  MdePkg/Library/MipiSysTLib/Platform.c      | 164 +++++
>  MdePkg/Library/MipiSysTLib/Platform.h      | 138 ++++
>  MdePkg/Library/MipiSysTLib/Readme.md       |  25 +
>  MdePkg/Library/MipiSysTLib/mipi_syst.h     | 789 +++++++++++++++++++++
>  MdePkg/Library/MipiSysTLib/mipisyst        |   1 +
>  MdePkg/MdePkg.ci.yaml                      |  12 +-
>  MdePkg/MdePkg.dec                          |   5 +
>  MdePkg/MdePkg.dsc                          |   1 +
>  ReadMe.rst                                 |   1 +
>  15 files changed, 1518 insertions(+), 7 deletions(-)
>  create mode 100644 MdePkg/Include/Library/MipiSysTLib.h
>  create mode 100644 MdePkg/Library/MipiSysTLib/GenMipiSystH.py
>  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/Readme.md
>  create mode 100644 MdePkg/Library/MipiSysTLib/mipi_syst.h
>  create mode 160000 MdePkg/Library/MipiSysTLib/mipisyst
> 
> diff --git a/.gitmodules b/.gitmodules
> index 6211c59724..fb79ebfb72 100644
> --- a/.gitmodules
> +++ b/.gitmodules
> @@ -16,7 +16,7 @@
>  [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
> @@ -26,6 +26,9 @@
>  [submodule "UnitTestFrameworkPkg/Library/SubhookLib/subhook"]
>  	path = UnitTestFrameworkPkg/Library/SubhookLib/subhook
>  	url = https://github.com/Zeex/subhook.git
> -[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
> 
> -	path = MdePkg/Library/BaseFdtLib/libfdt
> 
> -	url = https://github.com/devicetree-org/pylibfdt.git
> 
> +[submodule "MdePkg/Library/BaseFdtLib/libfdt"]
> +	path = MdePkg/Library/BaseFdtLib/libfdt
> +	url = https://github.com/devicetree-org/pylibfdt.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 2fb99f2a17..6fb7342f81 100644
> --- a/.pytool/CISettings.py
> +++ b/.pytool/CISettings.py
> @@ -197,6 +197,8 @@ class Settings(CiBuildSettingsManager,
> UpdateSettingsManager, SetupSettingsManag
>              "UnitTestFrameworkPkg/Library/SubhookLib/subhook", False))
> 
>          rs.append(RequiredSubmodule(
> 
>              "MdePkg/Library/BaseFdtLib/libfdt", 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..4ced1c02cd
> --- /dev/null
> +++ b/MdePkg/Include/Library/MipiSysTLib.h
> @@ -0,0 +1,66 @@
> +/** @file
> 
> +This header file declares functions consuming MIPI Sys-T submodule.
> 
> +
> 
> +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_
> 
> +
> 
> +/**
> 
> +  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 RETURN_SUCCESS      MIPI_SYST_HANDLE instance was initialized.
> 
> +  @retval Other               MIPI_SYST_HANDLE instance was not initialized.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +InitMipiSystHandle (
> 
> +  IN OUT VOID  *MipiSystHandle
> 
> +  );
> 
> +
> 
> +/**
> 
> +  Invoke write_debug_string function in Mipi Sys-T module.
> 
> +
> 
> +  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
> 
> +  @param[in]  Severity        Severity type of input message.
> 
> +  @param[in]  Len             Length of data buffer.
> 
> +  @param[in]  Str             A pointer to data buffer.
> 
> +
> 
> +  @retval RETURN_SUCCESS               Data in buffer was processed.
> 
> +  @retval RETURN_ABORTED               No data need to be written to Trace
> Hub.
> 
> +  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle or Str is
> a NULL pointer.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +MipiSystWriteDebug (
> 
> +  IN        VOID    *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        Severity type of input message.
> 
> +  @param[in]  CatId           Catalog Id.
> 
> +
> 
> +  @retval RETURN_SUCCESS               Data in buffer was processed.
> 
> +  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle is a
> NULL pointer.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +MipiSystWriteCatalog (
> 
> +  IN  VOID    *MipiSystHandle,
> 
> +  IN  UINT32  Severity,
> 
> +  IN  UINT64  CatId
> 
> +  );
> 
> +
> 
> +#endif // MIPI_SYST_LIB_H_
> 
> diff --git a/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
> b/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
> new file mode 100644
> index 0000000000..ee48285590
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/GenMipiSystH.py
> @@ -0,0 +1,132 @@
> +## @file
> 
> +#  This python script update content from mipi_syst.h.in in mipi sys-T
> submodule
> 
> +#  and generate it as mipi_syst.h. mipi_syst.h include necessary data
> structure and
> 
> +#  definition that will be consumed by MipiSysTLib itself, mipi sys-T
> submodule
> 
> +#  and other library.
> 
> +#
> 
> +#  This script needs to be done once by a developer when adding some
> 
> +#  project-relating definition or a new version of mipi_syst.h.in is released.
> 
> +#  Normal users do not need to do this, since the resulting file is stored
> 
> +#  in the EDK2 git repository.
> 
> +#
> 
> +#  Customize structures mentioned below to generate updated mipi_syst.h
> file:
> 
> +#  1. ExistingValueToBeReplaced
> 
> +#       -> To replace existing value in mipi_syst.h.in to newer one.
> 
> +#  2. ExistingDefinitionToBeRemoved
> 
> +#       -> To #undef a existing definition in mipi_syst.h.in.
> 
> +#  3. NewItemToBeAdded
> 
> +#       -> Items in this structure will be placed at the end of mipi_syst.h as a
> customized section.
> 
> +#
> 
> +#  Run GenMipiSystH.py without any parameters as normal python script
> after customizing.
> 
> +#
> 
> +#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +#
> 
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +#
> 
> +##
> 
> +import os
> 
> +import re
> 
> +
> 
> +#
> 
> +# A existing value to be customized should place this structure
> 
> +# Definitions in this customizable structure will be processed by
> ReplaceOldValue()
> 
> +# e.g:
> 
> +#   Before: @SYST_CFG_VERSION_MAJOR@
> 
> +#   After: 1
> 
> +#
> 
> +ExistingValueToBeReplaced = [
> 
> +    ["@SYST_CFG_VERSION_MAJOR@", "1"],      # Major version
> 
> +    ["@SYST_CFG_VERSION_MINOR@", "0"],      # Minor version
> 
> +    ["@SYST_CFG_VERSION_PATCH@", "0"],      # Patch version
> 
> +    ["@SYST_CFG_CONFORMANCE_LEVEL@", "30"], # Feature level of mipi sys-
> T submodule
> 
> +    ["mipi_syst/platform.h", "Platform.h"],
> 
> +]
> 
> +
> 
> +#
> 
> +# A existing definition to be removed should place this structure
> 
> +# Definitions in this customizable structure will be processed by
> RemoveDefinition()
> 
> +# e.g:
> 
> +#   Before:
> 
> +#       #define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
> 
> +#   After:
> 
> +#       #define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
> 
> +#       #undef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
> 
> +#
> 
> +ExistingDefinitionToBeRemoved = [
> 
> +    "MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA",
> 
> +    "MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY",
> 
> +    "MIPI_SYST_PCFG_ENABLE_PRINTF_API",
> 
> +    "MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD",
> 
> +    "MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS",
> 
> +]
> 
> +
> 
> +#
> 
> +# Items in this structure will be placed at the end of mipi_syst.h as a
> customized section.
> 
> +#
> 
> +NewItemToBeAdded = [
> 
> +    "typedef struct mipi_syst_handle_flags MIPI_SYST_HANDLE_FLAGS;",
> 
> +    "typedef struct mipi_syst_msg_tag MIPI_SYST_MSG_TAG;",
> 
> +    "typedef struct mipi_syst_guid MIPI_SYST_GUID;",
> 
> +    "typedef enum mipi_syst_severity MIPI_SYST_SEVERITY;",
> 
> +    "typedef struct mipi_syst_handle MIPI_SYST_HANDLE;",
> 
> +    "typedef struct mipi_syst_header MIPI_SYST_HEADER;",
> 
> +]
> 
> +
> 
> +def ProcessSpecialCharacter(Str):
> 
> +    Str = Str.rstrip(" \n")
> 
> +    Str = Str.replace("\t", "  ")
> 
> +    Str += "\n"
> 
> +    return Str
> 
> +
> 
> +def ReplaceOldValue(Str):
> 
> +    for i in range(len(ExistingValueToBeReplaced)):
> 
> +        Result = re.search(ExistingValueToBeReplaced[i][0], Str)
> 
> +        if Result is not None:
> 
> +            Str = Str.replace(ExistingValueToBeReplaced[i][0],
> ExistingValueToBeReplaced[i][1])
> 
> +            break
> 
> +    return Str
> 
> +
> 
> +def RemoveDefinition(Str):
> 
> +    Result = re.search("\*", Str)
> 
> +    if Result is None:
> 
> +        for i in range(len(ExistingDefinitionToBeRemoved)):
> 
> +            Result = re.search(ExistingDefinitionToBeRemoved[i], Str)
> 
> +            if Result is not None:
> 
> +                Result = re.search("defined", Str)
> 
> +                if Result is None:
> 
> +                    Str = Str + "#undef " + ExistingDefinitionToBeRemoved[i]
> 
> +                    break
> 
> +    return Str
> 
> +
> 
> +def main():
> 
> +    MipiSystHSrcDir = "mipisyst/library/include/mipi_syst.h.in"
> 
> +    MipiSystHRealSrcDir = os.path.join(os.getcwd(),
> os.path.normpath(MipiSystHSrcDir))
> 
> +    MipiSystHRealDstDir = os.path.join(os.getcwd(), "mipi_syst.h")
> 
> +
> 
> +    #
> 
> +    # Read content from mipi_syst.h.in and process each line by demand
> 
> +    #
> 
> +    with open(MipiSystHRealSrcDir, "r") as rfObj:
> 
> +        SrcFile = rfObj.readlines()
> 
> +        for lineIndex in range(len(SrcFile)):
> 
> +            SrcFile[lineIndex] = ProcessSpecialCharacter(SrcFile[lineIndex])
> 
> +            SrcFile[lineIndex] = ReplaceOldValue(SrcFile[lineIndex])
> 
> +            SrcFile[lineIndex] = RemoveDefinition(SrcFile[lineIndex])
> 
> +
> 
> +    #
> 
> +    # Typedef a structure or enum type
> 
> +    #
> 
> +    i = -1
> 
> +    for struct in NewItemToBeAdded:
> 
> +        struct += "\n"
> 
> +        SrcFile.insert(i, struct)
> 
> +        i -= 1
> 
> +
> 
> +    #
> 
> +    # Save edited content to mipi_syst.h
> 
> +    #
> 
> +    with open(MipiSystHRealDstDir, "w") as wfObj:
> 
> +        wfObj.writelines(SrcFile)
> 
> +
> 
> +if __name__ == '__main__':
> 
> +    main()
> 
> diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
> b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
> new file mode 100644
> index 0000000000..3a15a2af58
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.c
> @@ -0,0 +1,123 @@
> +/** @file
> 
> +This file provide functions to communicate with mipi sys-T submodule.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.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 RETURN_SUCCESS      MIPI_SYST_HANDLE instance was initialized.
> 
> +  @retval Other               MIPI_SYST_HANDLE instance was not initialized.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +InitMipiSystHandle (
> 
> +  IN OUT VOID  *MipiSystHandle
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  if (MipiSystH == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  mipi_syst_init (MipiSystH->systh_header, 0, NULL);
> 
> +
> 
> +  return RETURN_SUCCESS;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Invoke write_debug_string function in Mipi Sys-T module.
> 
> +
> 
> +  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
> 
> +  @param[in]  Severity        Severity type of input message.
> 
> +  @param[in]  Len             Length of data buffer.
> 
> +  @param[in]  Str             A pointer to data buffer.
> 
> +
> 
> +  @retval RETURN_SUCCESS               Data in buffer was processed.
> 
> +  @retval RETURN_ABORTED               No data need to be written to Trace
> Hub.
> 
> +  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle or Str is
> a NULL pointer.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +MipiSystWriteDebug (
> 
> +  IN        MIPI_SYST_HANDLE  *MipiSystHandle,
> 
> +  IN        UINT32            Severity,
> 
> +  IN        UINT16            Len,
> 
> +  IN CONST  CHAR8             *Str
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  if (MipiSystH == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  if (Len == 0) {
> 
> +    //
> 
> +    // No data need to be written to Trace Hub
> 
> +    //
> 
> +    return RETURN_ABORTED;
> 
> +  }
> 
> +
> 
> +  if (Str == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  mipi_syst_write_debug_string (
> 
> +    MipiSystH,
> 
> +    MIPI_SYST_NOLOCATION,
> 
> +    MIPI_SYST_STRING_GENERIC,
> 
> +    Severity,
> 
> +    Len,
> 
> +    Str
> 
> +    );
> 
> +
> 
> +  return RETURN_SUCCESS;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Invoke catalog_write_message function in Mipi Sys-T module.
> 
> +
> 
> +  @param[in]  MipiSystHandle  A pointer to MIPI_SYST_HANDLE structure.
> 
> +  @param[in]  Severity        Severity type of input message.
> 
> +  @param[in]  CatId           Catalog Id.
> 
> +
> 
> +  @retval RETURN_SUCCESS               Data in buffer was processed.
> 
> +  @retval RETURN_INVALID_PARAMETER     On entry, MipiSystHandle is a
> NULL pointer.
> 
> +**/
> 
> +RETURN_STATUS
> 
> +EFIAPI
> 
> +MipiSystWriteCatalog (
> 
> +  IN  MIPI_SYST_HANDLE  *MipiSystHandle,
> 
> +  IN  UINT32            Severity,
> 
> +  IN  UINT64            CatId
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  if (MipiSystH == NULL) {
> 
> +    return RETURN_INVALID_PARAMETER;
> 
> +  }
> 
> +
> 
> +  mipi_syst_write_catalog64_message (
> 
> +    MipiSystH,
> 
> +    MIPI_SYST_NOLOCATION,
> 
> +    Severity,
> 
> +    CatId
> 
> +    );
> 
> +
> 
> +  return RETURN_SUCCESS;
> 
> +}
> 
> diff --git a/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
> b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
> new file mode 100644
> index 0000000000..b2aefcc9cc
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
> @@ -0,0 +1,55 @@
> +## @file
> 
> +#  A library providing funcitons to communicate with mipi sys-T submodule.
> 
> +#
> 
> +#  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:*_*_IA32_CC_FLAGS = /DMIPI_SYST_STATIC
> 
> +  MSFT:*_*_X64_CC_FLAGS  = /DMIPI_SYST_STATIC
> 
> +  GCC:*_*_IA32_CC_FLAGS  = -DMIPI_SYST_STATIC
> 
> +  GCC:*_*_X64_CC_FLAGS   = -DMIPI_SYST_STATIC

MSFT and GCC both support -D, and this can be further simplified to a single line by removing arch specific statements

*_*_*_CC_FLAGS = -DMIPI_SYST_STATIC

> 
> diff --git a/MdePkg/Library/MipiSysTLib/Platform.c
> b/MdePkg/Library/MipiSysTLib/Platform.c
> new file mode 100644
> index 0000000000..90a524bc1e
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/Platform.c
> @@ -0,0 +1,164 @@
> +/** @file
> 
> +This file defines functions that output Trace Hub message.
> 
> +
> 
> +Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
> 
> +
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include <Base.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  VOID    *MipiSystHandle,
> 
> +  IN  UINT32  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite32 ((UINTN)(MipiSystH-
> >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  VOID    *MipiSystHandle,
> 
> +  IN  UINT32  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite32 ((UINTN)(MipiSystH-
> >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  VOID    *MipiSystHandle,
> 
> +  IN  UINT64  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite64 ((UINTN)(MipiSystH-
> >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  VOID   *MipiSystHandle,
> 
> +  IN  UINT8  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite8 ((UINTN)(MipiSystH-
> >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  VOID    *MipiSystHandle,
> 
> +  IN  UINT16  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite16 ((UINTN)(MipiSystH-
> >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  VOID    *MipiSystHandle,
> 
> +  IN  UINT32  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite32 ((UINTN)(MipiSystH-
> >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  VOID    *MipiSystHandle,
> 
> +  IN  UINT64  Data
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +  MmioWrite64 ((UINTN)(MipiSystH-
> >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  VOID  *MipiSystHandle
> 
> +  )
> 
> +{
> 
> +  MIPI_SYST_HANDLE  *MipiSystH;
> 
> +
> 
> +  MipiSystH = (MIPI_SYST_HANDLE *)MipiSystHandle;
> 
> +
> 
> +  MmioWrite32 ((UINTN)(MipiSystH-
> >systh_platform.TraceHubPlatformData.MmioAddr + 0x30), 0x0);
> 
> +}
> 
> diff --git a/MdePkg/Library/MipiSysTLib/Platform.h
> b/MdePkg/Library/MipiSysTLib/Platform.h
> new file mode 100644
> index 0000000000..ac77edf33d
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/Platform.h
> @@ -0,0 +1,138 @@
> +/** @file
> 
> +This header file declares functions and structures.
> 
> +
> 
> +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_
> 
> +
> 
> +typedef struct {
> 
> +  UINT64    MmioAddr;
> 
> +} TRACE_HUB_PLATFORM_SYST_DATA;
> 
> +
> 
> +struct mipi_syst_platform_handle {
> 
> +  TRACE_HUB_PLATFORM_SYST_DATA    TraceHubPlatformData;
> 
> +};
> 
> +
> 
> +/**
> 
> +  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  VOID    *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  VOID    *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  VOID    *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  VOID   *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  VOID    *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  VOID    *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  VOID    *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  VOID  *MipiSystHandle
> 
> +  );
> 
> +
> 
> +#define MIPI_SYST_PLATFORM_CLOCK()  1000 // (unit: MicroSecond)
> 
> +
> 
> +#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/Readme.md
> b/MdePkg/Library/MipiSysTLib/Readme.md
> new file mode 100644
> index 0000000000..2e5df0194e
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/Readme.md
> @@ -0,0 +1,25 @@
> +## Introduction of MipiSysTLib ##
> 
> +MipiSysTLib library is a upper level library consuming MIPI SYS-T submodule.
> 
> +It provides MIPI-related APIs in EDK2 format to be consumed.
> 
> +
> 
> +## MipiSysTLib Version ##
> 
> +EDK2 supports building with v1.1+edk2 official version which was fully
> validated.
> 
> +
> 
> +## HOW to Install MipiSysTLib for UEFI Building ##
> 
> +MIPI SYS-T repository was added as a submodule of EDK2 project. Please
> 
> +refer to edk2/Readme.md for how to clone the code.
> 
> +
> 
> +## About GenMipiSystH.py ##
> 
> +"GenMipiSystH.py" is a Python script which is used for customizing the
> 
> +mipi_syst.h.in in mipi sys-T repository. The resulting file, mipi_syst.h, will
> 
> +be put to same folder level as this script.
> 
> +```
> 
> +  mipisyst submodule                        MipiSysTLib library
> 
> +|---------------------| GenMipiSystH.py   |---------------------|
> 
> +|   mipi_syst.h.in    |-----------------> |   mipi_syst.h       |
> 
> +|---------------------|                   |---------------------|
> 
> +```
> 
> +This script needs to be done once by a developer when adding some
> 
> +project-related definition or a new version of mipi_syst.h.in was released.
> 
> +Normal users do not need to do this, since the resulting file is stored
> 
> +in the EDK2 git repository.
> 
> diff --git a/MdePkg/Library/MipiSysTLib/mipi_syst.h
> b/MdePkg/Library/MipiSysTLib/mipi_syst.h
> new file mode 100644
> index 0000000000..3cf67a1ee5
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/mipi_syst.h
> @@ -0,0 +1,789 @@
> +/*
> 
> +Copyright (c) 2018, MIPI Alliance, Inc.
> 
> +All rights reserved.
> 
> +
> 
> +Redistribution and use in source and binary forms, with or without
> 
> +modification, are permitted provided that the following conditions
> 
> +are met:
> 
> +
> 
> +* Redistributions of source code must retain the above copyright
> 
> +  notice, this list of conditions and the following disclaimer.
> 
> +
> 
> +* Redistributions in binary form must reproduce the above copyright
> 
> +  notice, this list of conditions and the following disclaimer in
> 
> +  the documentation and/or other materials provided with the
> 
> +  distribution.
> 
> +
> 
> +* Neither the name of the copyright holder nor the names of its
> 
> +  contributors may be used to endorse or promote products derived
> 
> +  from this software without specific prior written permission.
> 
> +
> 
> +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> CONTRIBUTORS
> 
> +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> 
> +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
> FOR
> 
> +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
> COPYRIGHT
> 
> +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> 
> +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> 
> +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> USE,
> 
> +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> ANY
> 
> +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> 
> +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
> USE
> 
> +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> 
> +*/
> 
> +
> 
> +/*
> 
> + * Contributors:
> 
> + * Norbert Schulz (Intel Corporation) - Initial API and implementation
> 
> + */
> 
> +
> 
> +#ifndef MIPI_SYST_H_INCLUDED
> 
> +#define MIPI_SYST_H_INCLUDED
> 
> +
> 
> +/* 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_TO
> STR(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
> 
> +#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,_MIP
> I_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,_MIP
> I_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+3
> 2,_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
> 
> +
> 
> +#if defined(__cplusplus)
> 
> +extern "C" {
> 
> +#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
> 
> +};
> 
> +
> 
> +struct mipi_syst_header;
> 
> +struct mipi_syst_handle;
> 
> +struct mipi_syst_scatter_prog;
> 
> +
> 
> +/** 128-bit GUID style message origin ID */
> 
> +struct mipi_syst_guid {
> 
> +  union {
> 
> +    mipi_syst_u8  b[16];
> 
> +    mipi_syst_u64 ll[2];
> 
> +  } u;
> 
> +};
> 
> +
> 
> +/** 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);
> 
> +
> 
> +/**
> 
> + * 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);
> 
> +
> 
> +#ifdef __cplusplus
> 
> +} /* extern C */
> 
> +#endif
> 
> +#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 Platform global SyS-T data state
> 
> + *
> 
> + * This define extends the global SyS-T state data structure
> 
> + * mipi_syst_header with platform private content. A platform typically
> 
> + * stores data for SyS-T handle creation processing in this structure.
> 
> + *
> 
> + * Note: This data is not touched by the library code itself, but typically
> 
> + * is used by platform  hook functions for handle creation and destruction.
> 
> + * **These hook function calls are not lock protected and may happen
> 
> + * concurrently!**  The hook functions need to implement locking if they
> 
> + *  modify the platform state data.
> 
> + *
> 
> + * The platform example uses #mipi_syst_platform_state as data state
> extension.
> 
> + */
> 
> +#define MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
> 
> +#undef MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA
> 
> +/**
> 
> + * 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
> 
> +
> 
> +/**
> 
> + * Enable HEAP usage for handle generation
> 
> + *
> 
> + * This macro tells the SyS-T library to enable the heap allocation handle
> 
> + * creation API #MIPI_SYST_ALLOC_HANDLE.
> 
> + * The platform must provide the macros #MIPI_SYST_HEAP_MALLOC and
> 
> + * #MIPI_SYST_HEAP_FREE to point SyS-T to the platform malloc and free
> 
> + * functions.
> 
> + *
> 
> + * Note: In OS kernel space environments, you must use unpaged memory
> 
> + * allocation functions.
> 
> + */
> 
> +#define MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY
> 
> +#undef MIPI_SYST_PCFG_ENABLE_HEAP_MEMORY
> 
> +/* 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
> 
> + /**
> 
> + * Enable printf API support
> 
> + *
> 
> + * Note:
> 
> + * Enabling printf requires compiler var_arg support as defined by the
> 
> + * header files stdarg.h stddef.h.
> 
> + */
> 
> +
> 
> +#define MIPI_SYST_PCFG_ENABLE_PRINTF_API
> 
> +#undef MIPI_SYST_PCFG_ENABLE_PRINTF_API
> 
> +/**
> 
> + * 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 the API variants that send file:line ID pair location records.
> 
> + */
> 
> +#define MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
> 
> +#undef MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
> 
> +/**
> 
> + * Enable the API variants that send the address of the instrumentation
> location.
> 
> + *
> 
> + * This API requires #MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD to be set
> as well.
> 
> + * It uses its own define as it additionally requires the function
> 
> + * @ref mipi_syst_return_addr() to be implemented for your platform.
> 
> + */
> 
> +#define MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
> 
> +#undef MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
> 
> +/**
> 
> + * 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
> 
> +#ifdef __cplusplus
> 
> +extern "C" {
> 
> +#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
> 
> +
> 
> +/** SyS-T global state structure.
> 
> + * This structure is holding the global SyS-T library state
> 
> + */
> 
> +struct mipi_syst_header {
> 
> +  mipi_syst_u32 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
> 
> +};
> 
> +
> 
> +/**
> 
> + * 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.
> 
> + */
> 
> +
> 
> +struct mipi_syst_msg_tag {
> 
> +#if defined(MIPI_SYST_BIG_ENDIAN)
> 
> +  mipi_syst_u32 et_res31 : 1;    /**< reserved for future use        */
> 
> +  mipi_syst_u32 et_res30 : 1;    /**< reserved for future use        */
> 
> +  mipi_syst_u32 et_subtype : 6;  /**< type dependent sub category    */
> 
> +  mipi_syst_u32 et_guid : 1;     /**< 128-bit GUID present           */
> 
> +  mipi_syst_u32 et_modunit : 11; /**< unit for GUID or module:unit   */
> 
> +  mipi_syst_u32 et_timestamp : 1;/**< indicate 64-bit timestamp      */
> 
> +  mipi_syst_u32 et_chksum : 1;   /**< indicate 32-bit CRC            */
> 
> +  mipi_syst_u32 et_length : 1;   /**< indicate length field          */
> 
> +  mipi_syst_u32 et_location : 1; /**< indicate location information  */
> 
> +  mipi_syst_u32 et_res7 : 1;     /**< reserved for future use        */
> 
> +  mipi_syst_u32 et_severity : 3; /**< severity level of message      */
> 
> +  mipi_syst_u32 et_type : 4;     /**< SyS-T message type ID          */
> 
> +#else
> 
> +  mipi_syst_u32 et_type : 4;     /**< SyS-T message type ID          */
> 
> +  mipi_syst_u32 et_severity : 3; /**< severity level of message      */
> 
> +  mipi_syst_u32 et_res7 : 1;     /**< reserved for future use        */
> 
> +  mipi_syst_u32 et_location : 1; /**< indicate location information  */
> 
> +  mipi_syst_u32 et_length : 1;   /**< indicate length field          */
> 
> +  mipi_syst_u32 et_chksum : 1;   /**< indicate 32-bit CRC            */
> 
> +  mipi_syst_u32 et_timestamp : 1;/**< indicate 64-bit timestamp      */
> 
> +  mipi_syst_u32 et_modunit : 11; /**< unit for GUID or module:unit   */
> 
> +  mipi_syst_u32 et_guid : 1;     /**< 128-bit GUID present           */
> 
> +  mipi_syst_u32 et_subtype : 6;  /**< type dependent sub category    */
> 
> +  mipi_syst_u32 et_res30 : 1;    /**< reserved for future use        */
> 
> +  mipi_syst_u32 et_res31 : 1;    /**< reserved for future use        */
> 
> +#endif
> 
> +};
> 
> +#define _MIPI_SYST_MK_MODUNIT_ORIGIN(m,u) (((u) & 0xF)|(m<<4))
> 
> +
> 
> +/**
> 
> + * Message severity level enumeration
> 
> + */
> 
> +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    */
> 
> +};
> 
> +
> 
> +/**
> 
> + * 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;
> 
> +};
> 
> +
> 
> +/** internal handle state flags
> 
> + */
> 
> +struct mipi_syst_handle_flags {
> 
> +  mipi_syst_u32 shf_alloc:1; /**< set to 1 if heap allocated handle */
> 
> +};
> 
> +
> 
> +/** 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.
> 
> + */
> 
> + 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
> 
> +
> 
> +  mipi_syst_u32 systh_param_count;          /**< number of parameters     */
> 
> +  mipi_syst_u32 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
> 
> +};
> 
> +
> 
> +
> 
> +#ifdef __cplusplus
> 
> +} /* extern C */
> 
> +#endif
> 
> +#ifndef MIPI_SYST_API_INCLUDED
> 
> +#include "mipi_syst/api.h"
> 
> +#endif
> 
> +
> 
> +typedef struct mipi_syst_header MIPI_SYST_HEADER;
> 
> +typedef struct mipi_syst_handle MIPI_SYST_HANDLE;
> 
> +typedef enum mipi_syst_severity MIPI_SYST_SEVERITY;
> 
> +typedef struct mipi_syst_guid MIPI_SYST_GUID;
> 
> +typedef struct mipi_syst_msg_tag MIPI_SYST_MSG_TAG;
> 
> +typedef struct mipi_syst_handle_flags MIPI_SYST_HANDLE_FLAGS;
> 
> +#endif
> 
> diff --git a/MdePkg/Library/MipiSysTLib/mipisyst
> b/MdePkg/Library/MipiSysTLib/mipisyst
> new file mode 160000
> index 0000000000..370b5944c0
> --- /dev/null
> +++ b/MdePkg/Library/MipiSysTLib/mipisyst
> @@ -0,0 +1 @@
> +Subproject commit 370b5944c046bab043dd8b133727b2135af7747a
> diff --git a/MdePkg/MdePkg.ci.yaml b/MdePkg/MdePkg.ci.yaml
> index 035c34b3ad..f024b48685 100644
> --- a/MdePkg/MdePkg.ci.yaml
> +++ b/MdePkg/MdePkg.ci.yaml
> @@ -10,7 +10,10 @@
>  {
> 
>      ## options defined .pytool/Plugin/LicenseCheck
> 
>      "LicenseCheck": {
> 
> -        "IgnoreFiles": []
> 
> +        "IgnoreFiles": [
> 
> +            # This file is copied from mipi sys-T submodule and generated by
> python script with customization.
> 
> +            "Library/MipiSysTLib/mipi_syst.h"
> 
> +        ]
> 
>      },
> 
>      "EccCheck": {
> 
>          ## Exception sample looks like below:
> 
> @@ -68,7 +71,8 @@
>              "Include/Library/SafeIntLib.h",
> 
>              "Include/Protocol/DebugSupport.h",
> 
>              "Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c",
> 
> -            "Library/BaseFdtLib"
> 
> +            "Library/BaseFdtLib",
> 
> +            "Library/MipiSysTLib/mipi_syst.h"
> 
>          ]
> 
>      },
> 
>      ## options defined ci/Plugin/CompilerPlugin
> 
> @@ -166,6 +170,7 @@
>          "IgnoreStandardPaths": [],   # Standard Plugin defined paths that should
> be ignore
> 
>          "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards
> supported)
> 
>      },
> 
> +
> 
>      # options defined in .pytool/Plugin/UncrustifyCheck
> 
>      "UncrustifyCheck": {
> 
>          "IgnoreFiles": [
> 
> @@ -175,7 +180,8 @@
>              "Library/BaseFdtLib/stddef.h",
> 
>              "Library/BaseFdtLib/stdint.h",
> 
>              "Library/BaseFdtLib/stdlib.h",
> 
> -            "Library/BaseFdtLib/string.h"
> 
> +            "Library/BaseFdtLib/string.h",
> 
> +            "mipi_syst.h"
> 
>          ]
> 
>      }
> 
>  }
> 
> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
> index d6c4179b2a..d68ed988c0 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -28,6 +28,7 @@
>    Include
> 
>    Test/UnitTest/Include
> 
>    Test/Mock/Include
> 
> +  Library/MipiSysTLib/mipisyst/library/include
> 
> 
> 
>  [Includes.IA32]
> 
>    Include/Ia32
> 
> @@ -293,6 +294,10 @@
>    #
> 
>    FdtLib|Include/Library/FdtLib.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 b38c863812..902a39cffc 100644
> --- a/MdePkg/MdePkg.dsc
> +++ b/MdePkg/MdePkg.dsc
> @@ -184,6 +184,7 @@
>    MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
> 
>    MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf
> 
>    MdePkg/Library/TdxLib/TdxLib.inf
> 
> +  MdePkg/Library/MipiSysTLib/MipiSysTLib.inf
> 
> 
> 
>  [Components.EBC]
> 
>    MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
> 
> diff --git a/ReadMe.rst b/ReadMe.rst
> index d46c534229..ed1d482245 100644
> --- a/ReadMe.rst
> +++ b/ReadMe.rst
> @@ -97,6 +97,7 @@ that are covered by additional licenses.
>  -  `UnitTestFrameworkPkg/Library/SubhookLib/subhook
> <https://github.com/Zeex/subhook/blob/83d4e1ebef3588fae48b69a7352cc21
> 801cb70bc/LICENSE.txt>`__
> 
>  -  `RedfishPkg/Library/JsonLib/jansson
> <https://github.com/akheron/jansson/blob/2882ead5bb90cf12a01b07b2c236
> 1e24960fae02/LICENSE>`__
> 
>  -  `MdePkg/Library/BaseFdtLib/libfdt <https://github.com/devicetree-
> org/pylibfdt/blob/f39368a217496d32c4091a2dba4045b60649e3a5/BSD-2-
> Clause>`__
> 
> +-  `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.40.0.windows.1


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

end of thread, other threads:[~2023-05-08 17:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-08  5:31 [PATCH 0/4] Trace Hub debug library support victorx.hsu
2023-05-08  5:31 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
2023-05-08 17:54   ` Michael D Kinney
2023-05-08  5:31 ` [PATCH 2/4] MdeModulePkg: Add TraceHubDebugSysTLib library victorx.hsu
2023-05-08 17:49   ` Michael D Kinney
2023-05-08  5:31 ` [PATCH 3/4] MdePkg: Add NULL library of TraceHubDebugSysTLib victorx.hsu
2023-05-08  5:31 ` [PATCH 4/4] Maintainers.txt: Update reviewers and maintainers for Trace Hub dbg lib victorx.hsu
  -- strict thread matches above, loose matches on Subject: below --
2023-04-18 11:04 [PATCH 0/4] Trace Hub debug library support victorx.hsu
2023-04-18 11:04 ` [PATCH 1/4] MdePkg: Add MipiSysTLib library victorx.hsu
2023-01-31  2:48 victorx.hsu
2023-01-31  3:17 ` Guo, Gua

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