2 Report Status Code Library for DXE Phase.
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Common/FrameworkDxeCis.h>
16 #include <Library/DebugLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/UefiRuntimeServicesTableLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/ReportStatusCodeLib.h>
24 #include <Protocol/StatusCode.h>
27 Internal worker function that reports a status code through the Status Code Protocol
29 This function checks to see if a Status Code Protocol is present in the handle
30 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
31 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
32 and the ReportStatusCode() service of the Status Code Protocol is called passing in
33 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
35 @param Type Status code type.
36 @param Value Status code value.
37 @param Instance Status code instance number.
38 @param CallerId Pointer to a GUID that identifies the caller of this
39 function. This is an optional parameter that may be
41 @param Data Pointer to the extended data buffer. This is an
42 optional parameter that may be NULL.
44 @retval EFI_SUCCESS The status code was reported.
45 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
46 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
51 InternalReportStatusCode (
52 IN EFI_STATUS_CODE_TYPE Type
,
53 IN EFI_STATUS_CODE_VALUE Value
,
55 IN CONST EFI_GUID
*CallerId OPTIONAL
,
56 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
60 EFI_STATUS_CODE_PROTOCOL
*StatusCode
;
61 STATIC EFI_REPORT_STATUS_CODE ReportStatusCode
= NULL
;
64 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
65 // in the handle database.
67 if (ReportStatusCode
== NULL
) {
69 return EFI_UNSUPPORTED
;
71 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, &StatusCode
);
72 if (!EFI_ERROR (Status
) && StatusCode
!= NULL
) {
73 ReportStatusCode
= StatusCode
->ReportStatusCode
;
74 } else if (gRT
->Hdr
.Revision
< 0x20000) {
75 ReportStatusCode
= ((FRAMEWORK_EFI_RUNTIME_SERVICES
*)gRT
)->ReportStatusCode
;
77 return EFI_UNSUPPORTED
;
82 // A Status Code Protocol is present in the handle database, so pass in all the
83 // parameters to the ReportStatusCode() service of the Status Code Protocol
85 return (*ReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
90 Computes and returns the size, in bytes, of a device path.
92 @param DevicePath A pointer to a device path.
94 @return The size, in bytes, of DevicePath.
99 InternalReportStatusCodeDevicePathSize (
100 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
103 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
106 // Search for the end of the device path structure
109 while (!EfiIsDevicePathEnd (DevicePath
)) {
110 DevicePath
= EfiNextDevicePathNode (DevicePath
);
114 // Subtract the start node from the end node and add in the size of the end node
116 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
121 Converts a status code to an 8-bit POST code value.
123 Converts the status code specified by CodeType and Value to an 8-bit POST code
124 and returns the 8-bit POST code in PostCode. If CodeType is an
125 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
126 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
127 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
129 If PostCode is NULL, then ASSERT().
131 @param CodeType The type of status code being converted.
132 @param Value The status code value being converted.
133 @param PostCode A pointer to the 8-bit POST code value to return.
135 @retval TRUE The status code specified by CodeType and Value was converted
136 to an 8-bit POST code and returned in PostCode.
137 @retval FALSE The status code specified by CodeType and Value could not be
138 converted to an 8-bit POST code value.
144 IN EFI_STATUS_CODE_TYPE CodeType
,
145 IN EFI_STATUS_CODE_VALUE Value
,
150 // If PostCode is NULL, then ASSERT()
152 ASSERT (PostCode
!= NULL
);
155 // Convert Value to an 8 bit post code
157 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
158 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
159 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
160 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
168 Extracts ASSERT() information from a status code structure.
170 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
171 arguments specified by Filename, Description, and LineNumber. If CodeType is
172 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
173 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
174 Filename, Description, and LineNumber from the optional data area of the
175 status code buffer specified by Data. The optional data area of Data contains
176 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
177 ASCII string for the Description, followed by a 32-bit LineNumber. If the
178 ASSERT() information could be extracted from Data, then return TRUE.
179 Otherwise, FALSE is returned.
181 If Data is NULL, then ASSERT().
182 If Filename is NULL, then ASSERT().
183 If Description is NULL, then ASSERT().
184 If LineNumber is NULL, then ASSERT().
186 @param CodeType The type of status code being converted.
187 @param Value The status code value being converted.
188 @param Data Pointer to status code data buffer.
189 @param Filename Pointer to the source file name that generated the ASSERT().
190 @param Description Pointer to the description of the ASSERT().
191 @param LineNumber Pointer to source line number that generated the ASSERT().
193 @retval TRUE The status code specified by CodeType, Value, and Data was
194 converted ASSERT() arguments specified by Filename, Description,
196 @retval FALSE The status code specified by CodeType, Value, and Data could
197 not be converted to ASSERT() arguments.
202 ReportStatusCodeExtractAssertInfo (
203 IN EFI_STATUS_CODE_TYPE CodeType
,
204 IN EFI_STATUS_CODE_VALUE Value
,
205 IN CONST EFI_STATUS_CODE_DATA
*Data
,
206 OUT CHAR8
**Filename
,
207 OUT CHAR8
**Description
,
208 OUT UINT32
*LineNumber
211 EFI_DEBUG_ASSERT_DATA
*AssertData
;
213 ASSERT (Data
!= NULL
);
214 ASSERT (Filename
!= NULL
);
215 ASSERT (Description
!= NULL
);
216 ASSERT (LineNumber
!= NULL
);
218 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
219 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
220 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
221 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
222 *Filename
= (CHAR8
*)(AssertData
+ 1);
223 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
224 *LineNumber
= AssertData
->LineNumber
;
232 Extracts DEBUG() information from a status code structure.
234 Converts the status code specified by Data to the DEBUG() arguments specified
235 by ErrorLevel, Marker, and Format. If type GUID in Data is
236 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
237 Format from the optional data area of the status code buffer specified by Data.
238 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
239 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
240 the Format. If the DEBUG() information could be extracted from Data, then
241 return TRUE. Otherwise, FALSE is returned.
243 If Data is NULL, then ASSERT().
244 If ErrorLevel is NULL, then ASSERT().
245 If Marker is NULL, then ASSERT().
246 If Format is NULL, then ASSERT().
248 @param Data Pointer to status code data buffer.
249 @param ErrorLevel Pointer to error level mask for a debug message.
250 @param Marker Pointer to the variable argument list associated with Format.
251 @param Format Pointer to a Null-terminated ASCII format string of a
254 @retval TRUE The status code specified by Data was converted DEBUG() arguments
255 specified by ErrorLevel, Marker, and Format.
256 @retval FALSE The status code specified by Data could not be converted to
262 ReportStatusCodeExtractDebugInfo (
263 IN CONST EFI_STATUS_CODE_DATA
*Data
,
264 OUT UINT32
*ErrorLevel
,
269 EFI_DEBUG_INFO
*DebugInfo
;
271 ASSERT (Data
!= NULL
);
272 ASSERT (ErrorLevel
!= NULL
);
273 ASSERT (Marker
!= NULL
);
274 ASSERT (Format
!= NULL
);
277 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
279 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
284 // Retrieve the debug information from the status code record
286 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
288 *ErrorLevel
= DebugInfo
->ErrorLevel
;
291 // The first 12 * UINTN bytes of the string are really an
292 // argument stack to support varargs on the Format string.
294 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
295 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
302 Reports a status code.
304 Reports the status code specified by the parameters Type and Value. Status
305 code also require an instance, caller ID, and extended data. This function
306 passed in a zero instance, NULL extended data, and a caller ID of
307 gEfiCallerIdGuid, which is the GUID for the module.
309 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
310 is called while processing another any other Report Status Code Library function,
311 then ReportStatusCode() must return immediately.
313 @param Type Status code type.
314 @param Value Status code value.
316 @retval EFI_SUCCESS The status code was reported.
317 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
319 @retval EFI_UNSUPPORTED Report status code is not supported
325 IN EFI_STATUS_CODE_TYPE Type
,
326 IN EFI_STATUS_CODE_VALUE Value
329 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
334 Reports a status code with a Device Path Protocol as the extended data.
336 Allocates and fills in the extended data section of a status code with the
337 Device Path Protocol specified by DevicePath. This function is responsible
338 for allocating a buffer large enough for the standard header and the device
339 path. The standard header is filled in with a GUID of
340 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
341 instance and a caller ID of gEfiCallerIdGuid.
343 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
344 ReportStatusCodeWithDevicePath() is called while processing another any other
345 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
346 must return EFI_DEVICE_ERROR immediately.
348 If DevicePath is NULL, then ASSERT().
350 @param Type Status code type.
351 @param Value Status code value.
352 @param DevicePath Pointer to the Device Path Protocol to be reported.
354 @retval EFI_SUCCESS The status code was reported with the extended
355 data specified by DevicePath.
356 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
357 extended data section.
358 @retval EFI_UNSUPPORTED Report status code is not supported
363 ReportStatusCodeWithDevicePath (
364 IN EFI_STATUS_CODE_TYPE Type
,
365 IN EFI_STATUS_CODE_VALUE Value
,
366 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
369 ASSERT (DevicePath
!= NULL
);
370 return ReportStatusCodeWithExtendedData (
374 InternalReportStatusCodeDevicePathSize (DevicePath
)
380 Reports a status code with an extended data buffer.
382 Allocates and fills in the extended data section of a status code with the
383 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
384 is assumed to be one of the data structures specified in Related Definitions.
385 These data structure do not have the standard header, so this function is
386 responsible for allocating a buffer large enough for the standard header and
387 the extended data passed into this function. The standard header is filled
388 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
389 with a zero instance and a caller ID of gEfiCallerIdGuid.
391 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
392 ReportStatusCodeWithExtendedData() is called while processing another any other
393 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
394 must return EFI_DEVICE_ERROR immediately.
396 If ExtendedData is NULL, then ASSERT().
397 If ExtendedDataSize is 0, then ASSERT().
399 @param Type Status code type.
400 @param Value Status code value.
401 @param ExtendedData Pointer to the extended data buffer to be reported.
402 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
405 @retval EFI_SUCCESS The status code was reported with the extended
406 data specified by ExtendedData and ExtendedDataSize.
407 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
408 extended data section.
409 @retval EFI_UNSUPPORTED Report status code is not supported
414 ReportStatusCodeWithExtendedData (
415 IN EFI_STATUS_CODE_TYPE Type
,
416 IN EFI_STATUS_CODE_VALUE Value
,
417 IN CONST VOID
*ExtendedData
,
418 IN UINTN ExtendedDataSize
421 ASSERT (ExtendedData
!= NULL
);
422 ASSERT (ExtendedDataSize
!= 0);
423 return ReportStatusCodeEx (
436 Reports a status code with full parameters.
438 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
439 is 0, then an extended data buffer is not reported. If ExtendedData is not
440 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
441 ExtendedData is assumed not have the standard status code header, so this function
442 is responsible for allocating a buffer large enough for the standard header and
443 the extended data passed into this function. The standard header is filled in
444 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
445 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
446 an instance specified by Instance and a caller ID specified by CallerId. If
447 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
449 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
450 is called while processing another any other Report Status Code Library function,
451 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
453 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
454 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
456 @param Type Status code type.
457 @param Value Status code value.
458 @param Instance Status code instance number.
459 @param CallerId Pointer to a GUID that identifies the caller of this
460 function. If this parameter is NULL, then a caller
461 ID of gEfiCallerIdGuid is used.
462 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
463 If this parameter is NULL, then a the status code
464 standard header is filled in with
465 gEfiStatusCodeSpecificDataGuid.
466 @param ExtendedData Pointer to the extended data buffer. This is an
467 optional parameter that may be NULL.
468 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
470 @retval EFI_SUCCESS The status code was reported.
471 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
472 the extended data section if it was specified.
473 @retval EFI_UNSUPPORTED Report status code is not supported
479 IN EFI_STATUS_CODE_TYPE Type
,
480 IN EFI_STATUS_CODE_VALUE Value
,
482 IN CONST EFI_GUID
*CallerId OPTIONAL
,
483 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
484 IN CONST VOID
*ExtendedData OPTIONAL
,
485 IN UINTN ExtendedDataSize
489 EFI_STATUS_CODE_DATA
*StatusCodeData
;
491 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
492 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
495 return EFI_UNSUPPORTED
;
499 // Allocate space for the Status Code Header and its buffer
501 StatusCodeData
= NULL
;
502 gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + ExtendedDataSize
, (VOID
**)&StatusCodeData
);
503 if (StatusCodeData
== NULL
) {
504 return EFI_OUT_OF_RESOURCES
;
508 // Fill in the extended data header
510 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
511 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
512 if (ExtendedDataGuid
== NULL
) {
513 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
515 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
518 // Fill in the extended data buffer
520 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
523 // Report the status code
525 if (CallerId
== NULL
) {
526 CallerId
= &gEfiCallerIdGuid
;
528 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
531 // Free the allocated buffer
533 gBS
->FreePool (StatusCodeData
);
540 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
542 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
543 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
545 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
546 PcdReportStatusCodeProperyMask is set.
547 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
548 PcdReportStatusCodeProperyMask is clear.
553 ReportProgressCodeEnabled (
557 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
562 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
564 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
565 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
567 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
568 PcdReportStatusCodeProperyMask is set.
569 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
570 PcdReportStatusCodeProperyMask is clear.
575 ReportErrorCodeEnabled (
579 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
584 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
586 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
587 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
589 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
590 PcdReportStatusCodeProperyMask is set.
591 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
592 PcdReportStatusCodeProperyMask is clear.
597 ReportDebugCodeEnabled (
601 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);