VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/TraceHubDebugSysTLib/InternalTraceHubApiCommon.c

Last change on this file was 101291, checked in by vboxsync, 19 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1/** @file
2Functions implementation defined in this file are common for all type of TraceHubDebugSysTLib
3
4Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
5
6SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <Base.h>
11#include <Library/BaseLib.h>
12#include <Library/BaseMemoryLib.h>
13#include <Library/TraceHubDebugSysTLib.h>
14#include <Library/MipiSysTLib/mipi_syst.h>
15#include <Guid/TraceHubDebugInfoHob.h>
16#include "InternalTraceHubApiCommon.h"
17#include "InternalTraceHubApi.h"
18
19/**
20 Conditionally determine whether to enable Trace Hub message.
21
22 @param[in] Flag Flag to enable or disable Trace Hub message.
23 @param[in] DbgLevel Debug Level of Trace Hub.
24 @param[in] SeverityType Severity type of input message.
25
26 @retval TRUE Enable trace hub message.
27 @retval FALSE Disable trace hub message.
28**/
29BOOLEAN
30EFIAPI
31TraceHubDataEnabled (
32 IN BOOLEAN Flag,
33 IN UINT8 DbgLevel,
34 IN TRACE_HUB_SEVERITY_TYPE SeverityType
35 )
36{
37 if (Flag == TraceHubRoutingDisable) {
38 return FALSE;
39 }
40
41 if (DbgLevel == TraceHubDebugLevelError) {
42 if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError))) {
43 return TRUE;
44 }
45 } else if (DbgLevel == TraceHubDebugLevelErrorWarning) {
46 if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError) || (SeverityType == SeverityWarning))) {
47 return TRUE;
48 }
49 } else if (DbgLevel == TraceHubDebugLevelErrorWarningInfo) {
50 if (((SeverityType == SeverityFatal) || (SeverityType == SeverityError) || (SeverityType == SeverityWarning) || (SeverityType == SeverityNormal))) {
51 return TRUE;
52 }
53 } else if (DbgLevel == TraceHubDebugLevelErrorWarningInfoVerbose) {
54 return TRUE;
55 }
56
57 return FALSE;
58}
59
60/**
61 Convert GUID from LE to BE or BE to LE.
62
63 @param[in] Guid GUID that need to be converted.
64 @param[out] ConvertedGuid GUID that is converted.
65**/
66VOID
67EFIAPI
68SwapBytesGuid (
69 IN GUID *Guid,
70 OUT GUID *ConvertedGuid
71 )
72{
73 CopyGuid (ConvertedGuid, Guid);
74 ConvertedGuid->Data1 = SwapBytes32 (ConvertedGuid->Data1);
75 ConvertedGuid->Data2 = SwapBytes16 (ConvertedGuid->Data2);
76 ConvertedGuid->Data3 = SwapBytes16 (ConvertedGuid->Data3);
77}
78
79/**
80 Check whether to output Trace Hub message according to some conditions.
81 Trace Hub message will be disabled if TraceHubDataEnabled() return FALSE
82 or Trace Hub MMIO address is 0.
83
84 @param[in, out] MipiSystHandle A pointer to MIPI_SYST_HANDLE structure.
85 @param[in] DbgContext A pointer to Trace Hub debug instance.
86 @param[in] SeverityType Severity type of input message.
87 @param[in] PrintType Either catalog print or debug print.
88
89 @retval RETURN_SUCCESS Current Trace Hub message need to be output.
90 @retval Other Current Trace Hub message will be disabled.
91**/
92RETURN_STATUS
93EFIAPI
94CheckWhetherToOutputMsg (
95 IN OUT MIPI_SYST_HANDLE *MipiSystHandle,
96 IN UINT8 *DbgContext,
97 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
98 IN TRACEHUB_PRINTTYPE PrintType
99 )
100{
101 UINT8 DbgLevel;
102 BOOLEAN Flag;
103 UINT64 Addr;
104 RETURN_STATUS Status;
105
106 if (MipiSystHandle == NULL) {
107 return RETURN_INVALID_PARAMETER;
108 }
109
110 if (PrintType == TraceHubDebugType) {
111 Status = GetTraceHubMsgVisibility (DbgContext, &Flag, &DbgLevel);
112 if (RETURN_ERROR (Status)) {
113 return Status;
114 }
115
116 if (!TraceHubDataEnabled (Flag, DbgLevel, SeverityType)) {
117 return RETURN_ABORTED;
118 }
119 }
120
121 Status = GetTraceHubMmioAddress (DbgContext, &Addr);
122 if (RETURN_ERROR (Status)) {
123 return Status;
124 }
125
126 MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr = Addr;
127 if (MipiSystHandle->systh_platform.TraceHubPlatformData.MmioAddr == 0) {
128 return RETURN_ABORTED;
129 }
130
131 return RETURN_SUCCESS;
132}
133
134/**
135 Get Trace Hub MMIO Address.
136
137 @param[in] DbgContext A pointer to Trace Hub debug instance.
138 @param[in, out] TraceAddress Trace Hub MMIO Address.
139
140 @retval RETURN_SUCCESS Operation is successfully.
141 @retval Other Operation is failed.
142**/
143RETURN_STATUS
144EFIAPI
145GetTraceHubMmioAddress (
146 IN UINT8 *DbgContext,
147 IN OUT UINT64 *TraceAddress
148 )
149{
150 TRACEHUB_DEBUG_INFO_HOB *ThDbgContext;
151
152 if (TraceAddress == NULL) {
153 return RETURN_INVALID_PARAMETER;
154 }
155
156 if (DbgContext != NULL) {
157 ThDbgContext = (TRACEHUB_DEBUG_INFO_HOB *)DbgContext;
158 *TraceAddress = ThDbgContext->TraceHubMmioAddress;
159 } else {
160 *TraceAddress = FixedPcdGet64 (PcdTraceHubDebugMmioAddress);
161 }
162
163 return RETURN_SUCCESS;
164}
165
166/**
167 Get visibility of Trace Hub Msg.
168
169 @param[in] DbgContext A pointer to Trace Hub debug instance.
170 @param[in, out] Flag Flag to enable or disable Trace Hub message.
171 @param[in, out] DbgLevel Debug Level of Trace Hub.
172
173 @retval RETURN_SUCCESS Operation is successfully.
174 @retval Other Operation is failed.
175**/
176RETURN_STATUS
177EFIAPI
178GetTraceHubMsgVisibility (
179 IN UINT8 *DbgContext,
180 IN OUT BOOLEAN *Flag,
181 IN OUT UINT8 *DbgLevel
182 )
183{
184 TRACEHUB_DEBUG_INFO_HOB *ThDbgContext;
185
186 if ((Flag == NULL) || (DbgLevel == NULL)) {
187 return RETURN_INVALID_PARAMETER;
188 }
189
190 if (DbgContext != NULL) {
191 ThDbgContext = (TRACEHUB_DEBUG_INFO_HOB *)DbgContext;
192 *Flag = ThDbgContext->Flag;
193 *DbgLevel = ThDbgContext->DebugLevel;
194 } else {
195 *DbgLevel = FixedPcdGet8 (PcdTraceHubDebugLevel);
196 *Flag = FixedPcdGetBool (PcdEnableTraceHubDebugMsg);
197 }
198
199 return RETURN_SUCCESS;
200}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette