From 0f0422cedc752d305d8d12a25b11e1dff4d8ff8b Mon Sep 17 00:00:00 2001 From: Gua Guo Date: Wed, 10 May 2023 10:15:35 +0800 Subject: MdeModulePkg: Add TraceHubDebugSysTLib library REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4144 This Library provides API to dump Trace Hub message. Cc: Michael D Kinney Cc: Guo Gua Cc: Chan Laura Cc: Prakashan Krishnadas Veliyathuparambil Cc: K N Karthik Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Guo Gua Reviewed-by: Michael D Kinney Reviewed-by: K N Karthik Reviewed-by: Chan Laura Acked-by: Liming Gao --- .../TraceHubDebugSysTLib/InternalTraceHubApi.c | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c (limited to 'MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c') diff --git a/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c new file mode 100644 index 0000000000..fe946fe60c --- /dev/null +++ b/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApi.c @@ -0,0 +1,74 @@ +/** @file +Functions implementation in this file are not common for all type of TraceHubDebugSysTLib. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include "InternalTraceHubApi.h" + +/** + Count the total number of Trace Hub debug instance in the system. + + @retval UINT32 The total number of Trace Hub debug instance in the system. +**/ +UINT32 +EFIAPI +CountThDebugInstance ( + VOID + ) +{ + UINT8 *DbgContext; + UINT32 DbgInstCount; + + DbgInstCount = 0; + + DbgContext = (UINT8 *)GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext != NULL) { + while (DbgContext != NULL) { + DbgInstCount++; + DbgContext = (UINT8 *)GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DbgContext)); + } + } else { + DbgInstCount++; + } + + return DbgInstCount; +} + +/** + Pack Trace Hub debug instances in the system. + + @param[in, out] ThPtr A pointer to TRACEHUB_DEBUG_INFO_HOB structure. + @param[in] Count Number of Trace Hub HOBs. +**/ +VOID +EFIAPI +PackThDebugInstance ( + IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr, + IN UINT32 Count + ) +{ + UINT8 *DbgContext; + UINT16 Index; + + DbgContext = GetFirstGuidHob (&gTraceHubDebugInfoHobGuid); + if (DbgContext != NULL) { + for (Index = 0; Index < Count; Index++) { + CopyMem (&ThPtr[Index], GET_GUID_HOB_DATA (DbgContext), sizeof (TRACEHUB_DEBUG_INFO_HOB)); + DbgContext = GetNextGuidHob (&gTraceHubDebugInfoHobGuid, GET_NEXT_HOB (DbgContext)); + } + } else { + for (Index = 0; Index < Count; Index++) { + ThPtr[Index].TraceHubMmioAddress = FixedPcdGet64 (PcdTraceHubDebugMmioAddress); + ThPtr[Index].Flag = FixedPcdGetBool (PcdEnableTraceHubDebugMsg); + ThPtr[Index].DebugLevel = FixedPcdGet8 (PcdTraceHubDebugLevel); + } + } +} -- cgit v1.2.3