VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c

Last change on this file was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 20.4 KB
Line 
1/** @file
2 Instance of Report Status Code Library for PEI Phase.
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <Guid/StatusCodeDataTypeId.h>
10#include <Guid/StatusCodeDataTypeDebug.h>
11
12#include <Library/ReportStatusCodeLib.h>
13#include <Library/DebugLib.h>
14#include <Library/BaseLib.h>
15#include <Library/BaseMemoryLib.h>
16#include <Library/PeiServicesTablePointerLib.h>
17#include <Library/OemHookStatusCodeLib.h>
18#include <Library/PcdLib.h>
19
20/**
21 Internal worker function that reports a status code through the PEI Status Code Service or
22 OEM Hook Status Code Library.
23
24 This function first tries to report status code via PEI Status Code Service. If the service
25 is not available, it then tries calling OEM Hook Status Code Library.
26
27 @param Type Status code type.
28 @param Value Status code value.
29 @param Instance Status code instance number.
30 @param CallerId Pointer to a GUID that identifies the caller of this
31 function. This is an optional parameter that may be
32 NULL.
33 @param Data Pointer to the extended data buffer. This is an
34 optional parameter that may be NULL.
35
36 @retval EFI_SUCCESS The status code was reported.
37 @retval EFI_UNSUPPORTED Status code type is not supported.
38 @retval Others Failed to report status code.
39
40**/
41EFI_STATUS
42InternalReportStatusCode (
43 IN EFI_STATUS_CODE_TYPE Type,
44 IN EFI_STATUS_CODE_VALUE Value,
45 IN UINT32 Instance,
46 IN CONST EFI_GUID *CallerId OPTIONAL,
47 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
48 )
49{
50 CONST EFI_PEI_SERVICES **PeiServices;
51 EFI_STATUS Status;
52
53 if ((ReportProgressCodeEnabled () && (((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE)) ||
54 (ReportErrorCodeEnabled () && (((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE)) ||
55 (ReportDebugCodeEnabled () && (((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)))
56 {
57 PeiServices = GetPeiServicesTablePointer ();
58 Status = (*PeiServices)->ReportStatusCode (
59 PeiServices,
60 Type,
61 Value,
62 Instance,
63 (EFI_GUID *)CallerId,
64 Data
65 );
66 if (Status == EFI_NOT_AVAILABLE_YET) {
67 Status = OemHookStatusCodeInitialize ();
68 if (!EFI_ERROR (Status)) {
69 return OemHookStatusCodeReport (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
70 }
71 }
72
73 return Status;
74 }
75
76 return EFI_UNSUPPORTED;
77}
78
79/**
80 Converts a status code to an 8-bit POST code value.
81
82 Converts the status code specified by CodeType and Value to an 8-bit POST code
83 and returns the 8-bit POST code in PostCode. If CodeType is an
84 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
85 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
86 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
87
88 If PostCode is NULL, then ASSERT().
89
90 @param CodeType The type of status code being converted.
91 @param Value The status code value being converted.
92 @param PostCode A pointer to the 8-bit POST code value to return.
93
94 @retval TRUE The status code specified by CodeType and Value was converted
95 to an 8-bit POST code and returned in PostCode.
96 @retval FALSE The status code specified by CodeType and Value could not be
97 converted to an 8-bit POST code value.
98
99**/
100BOOLEAN
101EFIAPI
102CodeTypeToPostCode (
103 IN EFI_STATUS_CODE_TYPE CodeType,
104 IN EFI_STATUS_CODE_VALUE Value,
105 OUT UINT8 *PostCode
106 )
107{
108 //
109 // If PostCode is NULL, then ASSERT()
110 //
111 ASSERT (PostCode != NULL);
112
113 //
114 // Convert Value to an 8 bit post code
115 //
116 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||
117 ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE))
118 {
119 *PostCode = (UINT8)((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |
120 (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));
121 return TRUE;
122 }
123
124 return FALSE;
125}
126
127/**
128 Extracts ASSERT() information from a status code structure.
129
130 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
131 arguments specified by Filename, Description, and LineNumber. If CodeType is
132 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
133 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
134 Filename, Description, and LineNumber from the optional data area of the
135 status code buffer specified by Data. The optional data area of Data contains
136 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
137 ASCII string for the Description, followed by a 32-bit LineNumber. If the
138 ASSERT() information could be extracted from Data, then return TRUE.
139 Otherwise, FALSE is returned.
140
141 If Data is NULL, then ASSERT().
142 If Filename is NULL, then ASSERT().
143 If Description is NULL, then ASSERT().
144 If LineNumber is NULL, then ASSERT().
145
146 @param CodeType The type of status code being converted.
147 @param Value The status code value being converted.
148 @param Data Pointer to status code data buffer.
149 @param Filename Pointer to the source file name that generated the ASSERT().
150 @param Description Pointer to the description of the ASSERT().
151 @param LineNumber Pointer to source line number that generated the ASSERT().
152
153 @retval TRUE The status code specified by CodeType, Value, and Data was
154 converted ASSERT() arguments specified by Filename, Description,
155 and LineNumber.
156 @retval FALSE The status code specified by CodeType, Value, and Data could
157 not be converted to ASSERT() arguments.
158
159**/
160BOOLEAN
161EFIAPI
162ReportStatusCodeExtractAssertInfo (
163 IN EFI_STATUS_CODE_TYPE CodeType,
164 IN EFI_STATUS_CODE_VALUE Value,
165 IN CONST EFI_STATUS_CODE_DATA *Data,
166 OUT CHAR8 **Filename,
167 OUT CHAR8 **Description,
168 OUT UINT32 *LineNumber
169 )
170{
171 EFI_DEBUG_ASSERT_DATA *AssertData;
172
173 ASSERT (Data != NULL);
174 ASSERT (Filename != NULL);
175 ASSERT (Description != NULL);
176 ASSERT (LineNumber != NULL);
177
178 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&
179 ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&
180 ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE))
181 {
182 AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);
183 *Filename = (CHAR8 *)(AssertData + 1);
184 *Description = *Filename + AsciiStrLen (*Filename) + 1;
185 *LineNumber = AssertData->LineNumber;
186 return TRUE;
187 }
188
189 return FALSE;
190}
191
192/**
193 Extracts DEBUG() information from a status code structure.
194
195 Converts the status code specified by Data to the DEBUG() arguments specified
196 by ErrorLevel, Marker, and Format. If type GUID in Data is
197 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
198 Format from the optional data area of the status code buffer specified by Data.
199 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
200 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
201 the Format. If the DEBUG() information could be extracted from Data, then
202 return TRUE. Otherwise, FALSE is returned.
203
204 If Data is NULL, then ASSERT().
205 If ErrorLevel is NULL, then ASSERT().
206 If Marker is NULL, then ASSERT().
207 If Format is NULL, then ASSERT().
208
209 @param Data Pointer to status code data buffer.
210 @param ErrorLevel Pointer to error level mask for a debug message.
211 @param Marker Pointer to the variable argument list associated with Format.
212 @param Format Pointer to a Null-terminated ASCII format string of a
213 debug message.
214
215 @retval TRUE The status code specified by Data was converted DEBUG() arguments
216 specified by ErrorLevel, Marker, and Format.
217 @retval FALSE The status code specified by Data could not be converted to
218 DEBUG() arguments.
219
220**/
221BOOLEAN
222EFIAPI
223ReportStatusCodeExtractDebugInfo (
224 IN CONST EFI_STATUS_CODE_DATA *Data,
225 OUT UINT32 *ErrorLevel,
226 OUT BASE_LIST *Marker,
227 OUT CHAR8 **Format
228 )
229{
230 EFI_DEBUG_INFO *DebugInfo;
231
232 ASSERT (Data != NULL);
233 ASSERT (ErrorLevel != NULL);
234 ASSERT (Marker != NULL);
235 ASSERT (Format != NULL);
236
237 //
238 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
239 //
240 if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {
241 return FALSE;
242 }
243
244 //
245 // Retrieve the debug information from the status code record
246 //
247 DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);
248
249 *ErrorLevel = DebugInfo->ErrorLevel;
250
251 //
252 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
253 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.
254 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is
255 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker
256 // returned is 64-bit aligned.
257 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will
258 // cause unalignment exception.
259 //
260 *Marker = (BASE_LIST)(DebugInfo + 1);
261 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);
262
263 return TRUE;
264}
265
266/**
267 Reports a status code.
268
269 Reports the status code specified by the parameters Type and Value. Status
270 code also require an instance, caller ID, and extended data. This function
271 passed in a zero instance, NULL extended data, and a caller ID of
272 gEfiCallerIdGuid, which is the GUID for the module.
273
274 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
275 is called while processing another any other Report Status Code Library function,
276 then ReportStatusCode() must return immediately.
277
278 @param Type Status code type.
279 @param Value Status code value.
280
281 @retval EFI_SUCCESS The status code was reported.
282 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
283 device error.
284 @retval EFI_UNSUPPORTED Report status code is not supported
285
286**/
287EFI_STATUS
288EFIAPI
289ReportStatusCode (
290 IN EFI_STATUS_CODE_TYPE Type,
291 IN EFI_STATUS_CODE_VALUE Value
292 )
293{
294 return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);
295}
296
297/**
298 Reports a status code with a Device Path Protocol as the extended data.
299
300 Allocates and fills in the extended data section of a status code with the
301 Device Path Protocol specified by DevicePath. This function is responsible
302 for allocating a buffer large enough for the standard header and the device
303 path. The standard header is filled in with a GUID of
304 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
305 instance and a caller ID of gEfiCallerIdGuid.
306
307 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
308 ReportStatusCodeWithDevicePath() is called while processing another any other
309 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
310 must return EFI_DEVICE_ERROR immediately.
311
312 If DevicePath is NULL, then ASSERT().
313
314 @param Type Status code type.
315 @param Value Status code value.
316 @param DevicePath Pointer to the Device Path Protocol to be reported.
317
318 @retval EFI_SUCCESS The status code was reported with the extended
319 data specified by DevicePath.
320 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
321 extended data section.
322 @retval EFI_UNSUPPORTED Report status code is not supported
323
324**/
325EFI_STATUS
326EFIAPI
327ReportStatusCodeWithDevicePath (
328 IN EFI_STATUS_CODE_TYPE Type,
329 IN EFI_STATUS_CODE_VALUE Value,
330 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
331 )
332{
333 ASSERT (DevicePath != NULL);
334 //
335 // EFI_UNSUPPORTED is returned for device path is not supported in PEI phase.
336 //
337 return EFI_UNSUPPORTED;
338}
339
340/**
341 Reports a status code with an extended data buffer.
342
343 Allocates and fills in the extended data section of a status code with the
344 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
345 is assumed to be one of the data structures specified in Related Definitions.
346 These data structure do not have the standard header, so this function is
347 responsible for allocating a buffer large enough for the standard header and
348 the extended data passed into this function. The standard header is filled
349 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
350 with a zero instance and a caller ID of gEfiCallerIdGuid.
351
352 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
353 ReportStatusCodeWithExtendedData() is called while processing another any other
354 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
355 must return EFI_DEVICE_ERROR immediately.
356
357 If ExtendedData is NULL, then ASSERT().
358 If ExtendedDataSize is 0, then ASSERT().
359
360 @param Type Status code type.
361 @param Value Status code value.
362 @param ExtendedData Pointer to the extended data buffer to be reported.
363 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
364 be reported.
365
366 @retval EFI_SUCCESS The status code was reported with the extended
367 data specified by ExtendedData and ExtendedDataSize.
368 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
369 extended data section.
370 @retval EFI_UNSUPPORTED Report status code is not supported
371
372**/
373EFI_STATUS
374EFIAPI
375ReportStatusCodeWithExtendedData (
376 IN EFI_STATUS_CODE_TYPE Type,
377 IN EFI_STATUS_CODE_VALUE Value,
378 IN CONST VOID *ExtendedData,
379 IN UINTN ExtendedDataSize
380 )
381{
382 ASSERT (ExtendedData != NULL);
383 ASSERT (ExtendedDataSize != 0);
384 return ReportStatusCodeEx (
385 Type,
386 Value,
387 0,
388 NULL,
389 NULL,
390 ExtendedData,
391 ExtendedDataSize
392 );
393}
394
395/**
396 Reports a status code with full parameters.
397
398 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
399 is 0, then an extended data buffer is not reported. If ExtendedData is not
400 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
401 ExtendedData is assumed not have the standard status code header, so this function
402 is responsible for allocating a buffer large enough for the standard header and
403 the extended data passed into this function. The standard header is filled in
404 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
405 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
406 an instance specified by Instance and a caller ID specified by CallerId. If
407 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
408
409 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
410 is called while processing another any other Report Status Code Library function,
411 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
412
413 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
414 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
415
416 @param Type Status code type.
417 @param Value Status code value.
418 @param Instance Status code instance number.
419 @param CallerId Pointer to a GUID that identifies the caller of this
420 function. If this parameter is NULL, then a caller
421 ID of gEfiCallerIdGuid is used.
422 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
423 If this parameter is NULL, then a the status code
424 standard header is filled in with
425 gEfiStatusCodeSpecificDataGuid.
426 @param ExtendedData Pointer to the extended data buffer. This is an
427 optional parameter that may be NULL.
428 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
429
430 @retval EFI_SUCCESS The status code was reported.
431 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
432 the extended data section if it was specified.
433 @retval EFI_UNSUPPORTED Report status code is not supported
434
435**/
436EFI_STATUS
437EFIAPI
438ReportStatusCodeEx (
439 IN EFI_STATUS_CODE_TYPE Type,
440 IN EFI_STATUS_CODE_VALUE Value,
441 IN UINT32 Instance,
442 IN CONST EFI_GUID *CallerId OPTIONAL,
443 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,
444 IN CONST VOID *ExtendedData OPTIONAL,
445 IN UINTN ExtendedDataSize
446 )
447{
448 EFI_STATUS_CODE_DATA *StatusCodeData;
449 UINT64 Buffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1];
450
451 //
452 // If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
453 //
454 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
455 //
456 // If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
457 //
458 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
459
460 if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
461 //
462 // The local variable Buffer not large enough to hold the extended data associated
463 // with the status code being reported.
464 //
465 DEBUG ((DEBUG_ERROR, "Status code extended data is too large to be reported!\n"));
466 return EFI_OUT_OF_RESOURCES;
467 }
468
469 StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;
470 StatusCodeData->HeaderSize = (UINT16)sizeof (EFI_STATUS_CODE_DATA);
471 StatusCodeData->Size = (UINT16)ExtendedDataSize;
472 if (ExtendedDataGuid == NULL) {
473 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
474 }
475
476 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
477 if (ExtendedData != NULL) {
478 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
479 }
480
481 if (CallerId == NULL) {
482 CallerId = &gEfiCallerIdGuid;
483 }
484
485 return InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
486}
487
488/**
489 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
490
491 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
492 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
493
494 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
495 PcdReportStatusCodeProperyMask is set.
496 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
497 PcdReportStatusCodeProperyMask is clear.
498
499**/
500BOOLEAN
501EFIAPI
502ReportProgressCodeEnabled (
503 VOID
504 )
505{
506 return (BOOLEAN)((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);
507}
508
509/**
510 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
511
512 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
513 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
514
515 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
516 PcdReportStatusCodeProperyMask is set.
517 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
518 PcdReportStatusCodeProperyMask is clear.
519
520**/
521BOOLEAN
522EFIAPI
523ReportErrorCodeEnabled (
524 VOID
525 )
526{
527 return (BOOLEAN)((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);
528}
529
530/**
531 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
532
533 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
534 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
535
536 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
537 PcdReportStatusCodeProperyMask is set.
538 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
539 PcdReportStatusCodeProperyMask is clear.
540
541**/
542BOOLEAN
543EFIAPI
544ReportDebugCodeEnabled (
545 VOID
546 )
547{
548 return (BOOLEAN)((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);
549}
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