VirtualBox

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

Last change on this file was 105670, checked in by vboxsync, 9 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
1/** @file
2System prints Trace Hub message in SEC/PEI/DXE/SMM based on fixed PCDs.
3Only support single Trace Hub debug instance.
4
5Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
6
7SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include <Base.h>
12#include <Library/BaseLib.h>
13#include <Library/PcdLib.h>
14#include <Library/BaseMemoryLib.h>
15#include <Library/TraceHubDebugSysTLib.h>
16#include <Library/MipiSysTLib.h>
17#include <Library/MipiSysTLib/mipi_syst.h>
18#include <Guid/TraceHubDebugInfoHob.h>
19#include "InternalTraceHubApiCommon.h"
20#include "InternalTraceHubApi.h"
21
22/**
23 Write debug string to specified Trace Hub MMIO address.
24
25 @param[in] SeverityType Severity type of input message.
26 @param[in] Buffer A pointer to the data buffer.
27 @param[in] NumberOfBytes The size of data buffer.
28
29 @retval RETURN_SUCCESS Data was written to Trace Hub.
30 @retval Other Failed to output Trace Hub message.
31**/
32RETURN_STATUS
33EFIAPI
34TraceHubSysTDebugWrite (
35 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
36 IN UINT8 *Buffer,
37 IN UINTN NumberOfBytes
38 )
39{
40 MIPI_SYST_HANDLE MipiSystHandle;
41 MIPI_SYST_HEADER MipiSystHeader;
42 RETURN_STATUS Status;
43 UINT32 DbgInstCount;
44 UINT32 Index;
45
46 if (NumberOfBytes == 0) {
47 //
48 // No data need to be written to Trace Hub
49 //
50 return RETURN_SUCCESS;
51 }
52
53 if (Buffer == NULL) {
54 return RETURN_INVALID_PARAMETER;
55 }
56
57 DbgInstCount = CountThDebugInstance ();
58
59 ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
60 MipiSystHandle.systh_header = &MipiSystHeader;
61
62 Status = InitMipiSystHandle (&MipiSystHandle);
63 if (RETURN_ERROR (Status)) {
64 return Status;
65 }
66
67 for (Index = 0; Index < DbgInstCount; Index++) {
68 Status = CheckWhetherToOutputMsg (
69 &MipiSystHandle,
70 NULL,
71 SeverityType,
72 TraceHubDebugType
73 );
74 if (!RETURN_ERROR (Status)) {
75 Status = MipiSystWriteDebug (
76 &MipiSystHandle,
77 SeverityType,
78 (UINT16)NumberOfBytes,
79 (CHAR8 *)Buffer
80 );
81 if (RETURN_ERROR (Status)) {
82 break;
83 }
84 }
85 }
86
87 return Status;
88}
89
90/**
91 Write catalog status code message to specified Trace Hub MMIO address.
92
93 @param[in] SeverityType Severity type of input message.
94 @param[in] Id Catalog ID.
95 @param[in] Guid Driver Guid.
96
97 @retval RETURN_SUCCESS Data was written to Trace Hub.
98 @retval Other Failed to output Trace Hub message.
99**/
100RETURN_STATUS
101EFIAPI
102TraceHubSysTWriteCataLog64StatusCode (
103 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
104 IN UINT64 Id,
105 IN GUID *Guid
106 )
107{
108 MIPI_SYST_HANDLE MipiSystHandle;
109 MIPI_SYST_HEADER MipiSystHeader;
110 RETURN_STATUS Status;
111 UINT32 DbgInstCount;
112 UINT32 Index;
113
114 if (Guid == NULL) {
115 return RETURN_INVALID_PARAMETER;
116 }
117
118 DbgInstCount = CountThDebugInstance ();
119
120 ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
121 MipiSystHandle.systh_header = &MipiSystHeader;
122
123 Status = InitMipiSystHandle (&MipiSystHandle);
124 if (RETURN_ERROR (Status)) {
125 return Status;
126 }
127
128 SwapBytesGuid (Guid, (GUID *)(VOID *)&MipiSystHandle.systh_guid);
129 MipiSystHandle.systh_tag.et_guid = 1;
130
131 for (Index = 0; Index < DbgInstCount; Index++) {
132 Status = CheckWhetherToOutputMsg (
133 &MipiSystHandle,
134 NULL,
135 SeverityType,
136 TraceHubCatalogType
137 );
138 if (!RETURN_ERROR (Status)) {
139 Status = MipiSystWriteCatalog (
140 &MipiSystHandle,
141 SeverityType,
142 Id
143 );
144 if (RETURN_ERROR (Status)) {
145 break;
146 }
147 }
148 }
149
150 return Status;
151}
152
153/**
154 Write catalog message to specified Trace Hub MMIO address.
155
156 @param[in] SeverityType Severity type of input message.
157 @param[in] Id Catalog ID.
158 @param[in] NumberOfParams Number of entries in argument list.
159 @param[in] ... Catalog message parameters.
160
161 @retval RETURN_SUCCESS Data was written to Trace Hub.
162 @retval Other Failed to output Trace Hub message.
163**/
164RETURN_STATUS
165EFIAPI
166TraceHubSysTWriteCataLog64 (
167 IN TRACE_HUB_SEVERITY_TYPE SeverityType,
168 IN UINT64 Id,
169 IN UINTN NumberOfParams,
170 ...
171 )
172{
173 MIPI_SYST_HANDLE MipiSystHandle;
174 MIPI_SYST_HEADER MipiSystHeader;
175 VA_LIST Args;
176 UINTN Index;
177 RETURN_STATUS Status;
178 UINT32 DbgInstCount;
179
180 DbgInstCount = 0;
181
182 if (NumberOfParams > sizeof (MipiSystHandle.systh_param) / sizeof (UINT32)) {
183 return RETURN_INVALID_PARAMETER;
184 }
185
186 DbgInstCount = CountThDebugInstance ();
187
188 ZeroMem (&MipiSystHandle, sizeof (MIPI_SYST_HANDLE));
189 MipiSystHandle.systh_header = &MipiSystHeader;
190
191 Status = InitMipiSystHandle (&MipiSystHandle);
192 if (RETURN_ERROR (Status)) {
193 return Status;
194 }
195
196 MipiSystHandle.systh_param_count = (UINT32)NumberOfParams;
197 VA_START (Args, NumberOfParams);
198 for (Index = 0; Index < NumberOfParams; Index++) {
199 MipiSystHandle.systh_param[Index] = VA_ARG (Args, UINT32);
200 }
201
202 VA_END (Args);
203
204 for (Index = 0; Index < DbgInstCount; Index++) {
205 Status = CheckWhetherToOutputMsg (
206 &MipiSystHandle,
207 NULL,
208 SeverityType,
209 TraceHubCatalogType
210 );
211 if (!RETURN_ERROR (Status)) {
212 Status = MipiSystWriteCatalog (
213 &MipiSystHandle,
214 SeverityType,
215 Id
216 );
217 if (RETURN_ERROR (Status)) {
218 break;
219 }
220 }
221 }
222
223 return Status;
224}
225
226/**
227 Collect the total number of Trace Hub debug instance in the system.
228
229 @retval UINT32 The total number of Trace Hub debug instance in the system.
230**/
231UINT32
232EFIAPI
233CountThDebugInstance (
234 VOID
235 )
236{
237 UINT32 DbgInstCount;
238
239 //
240 // 1 from PCD.
241 //
242 DbgInstCount = 1;
243
244 return DbgInstCount;
245}
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