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