TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeSmmTraceHubDebugSysTLib.c
Go to the documentation of this file.
1
11#include <Base.h>
12#include <Library/BaseLib.h>
13#include <Library/PcdLib.h>
14#include <Library/HobLib.h>
18#include <Library/MipiSysTLib.h>
19#include <Library/MipiSysTLib/mipi_syst.h>
22#include "InternalTraceHubApi.h"
23
25GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mDbgInstCount = 0;
26
37RETURN_STATUS
38EFIAPI
40 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
41 IN UINT8 *Buffer,
42 IN UINTN NumberOfBytes
43 )
44{
45 MIPI_SYST_HANDLE MipiSystHandle;
46 MIPI_SYST_HEADER MipiSystHeader;
47 RETURN_STATUS Status;
48 UINT32 Index;
49
50 if ((mDbgInstCount == 0) || (mThDebugInstArray == NULL)) {
51 return RETURN_ABORTED;
52 }
53
54 if (NumberOfBytes == 0) {
55 //
56 // No data need to be written to Trace Hub
57 //
58 return RETURN_SUCCESS;
59 }
60
61 if (Buffer == NULL) {
63 }
64
65 ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
66 MipiSystHandle.systh_header = &MipiSystHeader;
67
68 Status = InitMipiSystHandle (&MipiSystHandle);
69 if (RETURN_ERROR (Status)) {
70 return Status;
71 }
72
73 for (Index = 0; Index < mDbgInstCount; Index++) {
75 &MipiSystHandle,
76 (UINT8 *)&mThDebugInstArray[Index],
77 SeverityType,
78 TraceHubDebugType
79 );
80 if (!RETURN_ERROR (Status)) {
81 Status = MipiSystWriteDebug (
82 &MipiSystHandle,
83 SeverityType,
84 (UINT16)NumberOfBytes,
85 (CHAR8 *)Buffer
86 );
87 if (RETURN_ERROR (Status)) {
88 break;
89 }
90 }
91 }
92
93 return Status;
94}
95
106RETURN_STATUS
107EFIAPI
109 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
110 IN UINT64 Id,
111 IN GUID *Guid
112 )
113{
114 MIPI_SYST_HANDLE MipiSystHandle;
115 MIPI_SYST_HEADER MipiSystHeader;
116 UINTN Index;
117 RETURN_STATUS Status;
118
119 if ((mDbgInstCount == 0) || (mThDebugInstArray == NULL)) {
120 return RETURN_ABORTED;
121 }
122
123 ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
124 MipiSystHandle.systh_header = &MipiSystHeader;
125
126 Status = InitMipiSystHandle (&MipiSystHandle);
127 if (RETURN_ERROR (Status)) {
128 return Status;
129 }
130
131 if (Guid != NULL) {
132 SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid);
133 MipiSystHandle.systh_tag.et_guid = 1;
134 } else {
135 MipiSystHandle.systh_tag.et_modunit = 2;
136 MipiSystHandle.systh_tag.et_guid = 0;
137 }
138
139 for (Index = 0; Index < mDbgInstCount; Index++) {
140 Status = CheckWhetherToOutputMsg (
141 &MipiSystHandle,
142 (UINT8 *)&mThDebugInstArray[Index],
143 SeverityType,
144 TraceHubCatalogType
145 );
146 if (!RETURN_ERROR (Status)) {
147 Status = MipiSystWriteCatalog (
148 &MipiSystHandle,
149 SeverityType,
150 Id
151 );
152 if (RETURN_ERROR (Status)) {
153 break;
154 }
155 }
156 }
157
158 return Status;
159}
160
172RETURN_STATUS
173EFIAPI
175 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
176 IN UINT64 Id,
177 IN UINTN NumberOfParams,
178 ...
179 )
180{
181 MIPI_SYST_HANDLE MipiSystHandle;
182 MIPI_SYST_HEADER MipiSystHeader;
183 VA_LIST Args;
184 UINTN Index;
185 RETURN_STATUS Status;
186
187 if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT32)) {
189 }
190
191 if ((mDbgInstCount == 0) || (mThDebugInstArray == NULL)) {
192 return RETURN_ABORTED;
193 }
194
195 ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
196 MipiSystHandle.systh_header = &MipiSystHeader;
197
198 Status = InitMipiSystHandle (&MipiSystHandle);
199 if (RETURN_ERROR (Status)) {
200 return Status;
201 }
202
203 MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;
204 VA_START (Args, NumberOfParams);
205 for (Index = 0; Index < NumberOfParams; Index++) {
206 MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);
207 }
208
209 VA_END (Args);
210
211 for (Index = 0; Index < mDbgInstCount; Index++) {
212 Status = CheckWhetherToOutputMsg (
213 &MipiSystHandle,
214 (UINT8 *)&mThDebugInstArray[Index],
215 SeverityType,
216 TraceHubCatalogType
217 );
218 if (!RETURN_ERROR (Status)) {
219 Status = MipiSystWriteCatalog (
220 &MipiSystHandle,
221 SeverityType,
222 Id
223 );
224 if (RETURN_ERROR (Status)) {
225 break;
226 }
227 }
228 }
229
230 return Status;
231}
232
243RETURN_STATUS
244EFIAPI
246 IN EFI_HANDLE ImageHandle,
247 IN EFI_SYSTEM_TABLE *SystemTable
248 )
249{
250 if (mDbgInstCount == 0) {
251 mDbgInstCount = CountThDebugInstance ();
252 }
253
254 mThDebugInstArray = AllocateZeroPool (mDbgInstCount * sizeof (TRACEHUB_DEBUG_INFO_HOB));
255
256 if (mThDebugInstArray != NULL) {
257 PackThDebugInstance (mThDebugInstArray, mDbgInstCount);
258 } else {
260 }
261
262 return RETURN_SUCCESS;
263}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT32 EFIAPI CountThDebugInstance(VOID)
RETURN_STATUS EFIAPI TraceHubSysTWriteCataLog64StatusCode(IN TRACE_HUB_SEVERITY_TYPE SeverityType, IN UINT64 Id, IN GUID *Guid)
RETURN_STATUS EFIAPI TraceHubSysTWriteCataLog64(IN TRACE_HUB_SEVERITY_TYPE SeverityType, IN UINT64 Id, IN UINTN NumberOfParams,...)
RETURN_STATUS EFIAPI DxeSmmTraceHubDebugSysTLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
RETURN_STATUS EFIAPI TraceHubSysTDebugWrite(IN TRACE_HUB_SEVERITY_TYPE SeverityType, IN UINT8 *Buffer, IN UINTN NumberOfBytes)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI PackThDebugInstance(IN OUT TRACEHUB_DEBUG_INFO_HOB *ThPtr, IN UINT32 Count)
RETURN_STATUS EFIAPI CheckWhetherToOutputMsg(IN OUT MIPI_SYST_HANDLE *MipiSystHandle, IN UINT8 *DbgContext, IN TRACE_HUB_SEVERITY_TYPE SeverityType, IN TRACEHUB_PRINTTYPE PrintType)
VOID EFIAPI SwapBytesGuid(IN GUID *Guid, OUT GUID *ConvertedGuid)
#define NULL
Definition: Base.h:319
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define RETURN_ABORTED
Definition: Base.h:1177
#define RETURN_OUT_OF_RESOURCES
Definition: Base.h:1114
#define VA_ARG(Marker, TYPE)
Definition: Base.h:679
#define VA_START(Marker, Parameter)
Definition: Base.h:661
#define RETURN_SUCCESS
Definition: Base.h:1066
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define VA_END(Marker)
Definition: Base.h:691
RETURN_STATUS EFIAPI InitMipiSystHandle(IN OUT VOID *MipiSystHandle)
Definition: MipiSysTLib.c:23
RETURN_STATUS EFIAPI MipiSystWriteCatalog(IN VOID *MipiSystHandle, IN UINT32 Severity, IN UINT64 CatId)
RETURN_STATUS EFIAPI MipiSystWriteDebug(IN VOID *MipiSystHandle, IN UINT32 Severity, IN UINT16 Len, IN CONST CHAR8 *Str)
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
struct mipi_syst_msg_tag systh_tag
Definition: mipi_syst.h:756
mipi_syst_u32 et_modunit
Definition: mipi_syst.h:664
mipi_syst_u32 et_guid
Definition: mipi_syst.h:665
struct mipi_syst_guid systh_guid
Definition: mipi_syst.h:759
mipi_syst_u32 systh_param_count
Definition: mipi_syst.h:766
mipi_syst_u32 systh_param[6]
Definition: mipi_syst.h:767
struct mipi_syst_header * systh_header
Definition: mipi_syst.h:754
Definition: Base.h:213