3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Report Status Code Library for DXE Phase.
23 #include "EdkIIGlueDxe.h"
25 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
27 // Global pointer to the Status Code Protocol
29 static EFI_STATUS_CODE_PROTOCOL
*gStatusCode
= NULL
;
34 Internal worker function that reports a status code through the Status Code Protocol
36 This function checks to see if a Status Code Protocol is present in the handle
37 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
38 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
39 and the ReportStatusCode() service of the Status Code Protocol is called passing in
40 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
42 @param Type Status code type.
43 @param Value Status code value.
44 @param Instance Status code instance number.
45 @param CallerId Pointer to a GUID that identifies the caller of this
46 function. This is an optional parameter that may be
48 @param Data Pointer to the extended data buffer. This is an
49 optional parameter that may be NULL.
51 @retval EFI_SUCCESS The status code was reported.
52 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
53 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
58 InternalReportStatusCode (
59 IN EFI_STATUS_CODE_TYPE Type
,
60 IN EFI_STATUS_CODE_VALUE Value
,
62 IN CONST EFI_GUID
*CallerId OPTIONAL
,
63 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
66 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
71 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
72 // in the handle database.
74 if (gStatusCode
== NULL
) {
75 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&gStatusCode
);
76 if (EFI_ERROR (Status
) || gStatusCode
== NULL
) {
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 (gStatusCode
->ReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
89 return (gRT
->ReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
97 Computes and returns the size, in bytes, of a device path.
99 @param DevicePath A pointer to a device path.
101 @return The size, in bytes, of DevicePath.
106 InternalReportStatusCodeDevicePathSize (
107 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
110 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
113 // Search for the end of the device path structure
116 while (!EfiIsDevicePathEnd (DevicePath
)) {
117 DevicePath
= EfiNextDevicePathNode (DevicePath
);
121 // Subtract the start node from the end node and add in the size of the end node
123 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
128 Converts a status code to an 8-bit POST code value.
130 Converts the status code specified by CodeType and Value to an 8-bit POST code
131 and returns the 8-bit POST code in PostCode. If CodeType is an
132 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
133 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
134 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
136 If PostCode is NULL, then ASSERT().
138 @param CodeType The type of status code being converted.
139 @param Value The status code value being converted.
140 @param PostCode A pointer to the 8-bit POST code value to return.
142 @retval TRUE The status code specified by CodeType and Value was converted
143 to an 8-bit POST code and returned in PostCode.
144 @retval FALSE The status code specified by CodeType and Value could not be
145 converted to an 8-bit POST code value.
150 GlueCodeTypeToPostCode (
151 IN EFI_STATUS_CODE_TYPE CodeType
,
152 IN EFI_STATUS_CODE_VALUE Value
,
157 // If PostCode is NULL, then ASSERT()
159 ASSERT (PostCode
!= NULL
);
162 // Convert Value to an 8 bit post code
164 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
165 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
166 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
167 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
175 Extracts ASSERT() information from a status code structure.
177 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
178 arguments specified by Filename, Description, and LineNumber. If CodeType is
179 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
180 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
181 Filename, Description, and LineNumber from the optional data area of the
182 status code buffer specified by Data. The optional data area of Data contains
183 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
184 ASCII string for the Description, followed by a 32-bit LineNumber. If the
185 ASSERT() information could be extracted from Data, then return TRUE.
186 Otherwise, FALSE is returned.
188 If Data is NULL, then ASSERT().
189 If Filename is NULL, then ASSERT().
190 If Description is NULL, then ASSERT().
191 If LineNumber is NULL, then ASSERT().
193 @param CodeType The type of status code being converted.
194 @param Value The status code value being converted.
195 @param Data Pointer to status code data buffer.
196 @param Filename Pointer to the source file name that generated the ASSERT().
197 @param Description Pointer to the description of the ASSERT().
198 @param LineNumber Pointer to source line number that generated the ASSERT().
200 @retval TRUE The status code specified by CodeType, Value, and Data was
201 converted ASSERT() arguments specified by Filename, Description,
203 @retval FALSE The status code specified by CodeType, Value, and Data could
204 not be converted to ASSERT() arguments.
209 GlueReportStatusCodeExtractAssertInfo (
210 IN EFI_STATUS_CODE_TYPE CodeType
,
211 IN EFI_STATUS_CODE_VALUE Value
,
212 IN CONST EFI_STATUS_CODE_DATA
*Data
,
213 OUT CHAR8
**Filename
,
214 OUT CHAR8
**Description
,
215 OUT UINT32
*LineNumber
218 EFI_DEBUG_ASSERT_DATA
*AssertData
;
220 ASSERT (Data
!= NULL
);
221 ASSERT (Filename
!= NULL
);
222 ASSERT (Description
!= NULL
);
223 ASSERT (LineNumber
!= NULL
);
225 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
226 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
227 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
228 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
229 *Filename
= (CHAR8
*)(AssertData
+ 1);
230 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
231 *LineNumber
= AssertData
->LineNumber
;
239 Extracts DEBUG() information from a status code structure.
241 Converts the status code specified by Data to the DEBUG() arguments specified
242 by ErrorLevel, Marker, and Format. If type GUID in Data is
243 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
244 Format from the optional data area of the status code buffer specified by Data.
245 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
246 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
247 the Format. If the DEBUG() information could be extracted from Data, then
248 return TRUE. Otherwise, FALSE is returned.
250 If Data is NULL, then ASSERT().
251 If ErrorLevel is NULL, then ASSERT().
252 If Marker is NULL, then ASSERT().
253 If Format is NULL, then ASSERT().
255 @param Data Pointer to status code data buffer.
256 @param ErrorLevel Pointer to error level mask for a debug message.
257 @param Marker Pointer to the variable argument list associated with Format.
258 @param Format Pointer to a Null-terminated ASCII format string of a
261 @retval TRUE The status code specified by Data was converted DEBUG() arguments
262 specified by ErrorLevel, Marker, and Format.
263 @retval FALSE The status code specified by Data could not be converted to
269 GlueReportStatusCodeExtractDebugInfo (
270 IN CONST EFI_STATUS_CODE_DATA
*Data
,
271 OUT UINT32
*ErrorLevel
,
276 EFI_DEBUG_INFO
*DebugInfo
;
278 ASSERT (Data
!= NULL
);
279 ASSERT (ErrorLevel
!= NULL
);
280 ASSERT (Marker
!= NULL
);
281 ASSERT (Format
!= NULL
);
284 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
286 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
291 // Retrieve the debug information from the status code record
293 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
295 *ErrorLevel
= DebugInfo
->ErrorLevel
;
298 // The first 12 * UINTN bytes of the string are really an
299 // argument stack to support varargs on the Format string.
301 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
302 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
309 Reports a status code.
311 Reports the status code specified by the parameters Type and Value. Status
312 code also require an instance, caller ID, and extended data. This function
313 passed in a zero instance, NULL extended data, and a caller ID of
314 gEfiCallerIdGuid, which is the GUID for the module.
316 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
317 is called while processing another any other Report Status Code Library function,
318 then ReportStatusCode() must return immediately.
320 @param Type Status code type.
321 @param Value Status code value.
323 @retval EFI_SUCCESS The status code was reported.
324 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
326 @retval EFI_UNSUPPORTED Report status code is not supported
331 GlueReportStatusCode (
332 IN EFI_STATUS_CODE_TYPE Type
,
333 IN EFI_STATUS_CODE_VALUE Value
336 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
341 Reports a status code with a Device Path Protocol as the extended data.
343 Allocates and fills in the extended data section of a status code with the
344 Device Path Protocol specified by DevicePath. This function is responsible
345 for allocating a buffer large enough for the standard header and the device
346 path. The standard header is filled in with a GUID of
347 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
348 instance and a caller ID of gEfiCallerIdGuid.
350 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
351 ReportStatusCodeWithDevicePath() is called while processing another any other
352 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
353 must return EFI_DEVICE_ERROR immediately.
355 If DevicePath is NULL, then ASSERT().
357 @param Type Status code type.
358 @param Value Status code value.
359 @param DevicePath Pointer to the Device Path Protocol to be reported.
361 @retval EFI_SUCCESS The status code was reported with the extended
362 data specified by DevicePath.
363 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
364 extended data section.
365 @retval EFI_UNSUPPORTED Report status code is not supported
370 GlueReportStatusCodeWithDevicePath (
371 IN EFI_STATUS_CODE_TYPE Type
,
372 IN EFI_STATUS_CODE_VALUE Value
,
373 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
376 ASSERT (DevicePath
!= NULL
);
377 return ReportStatusCodeWithExtendedData (
381 InternalReportStatusCodeDevicePathSize (DevicePath
)
387 Reports a status code with an extended data buffer.
389 Allocates and fills in the extended data section of a status code with the
390 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
391 is assumed to be one of the data structures specified in Related Definitions.
392 These data structure do not have the standard header, so this function is
393 responsible for allocating a buffer large enough for the standard header and
394 the extended data passed into this function. The standard header is filled
395 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
396 with a zero instance and a caller ID of gEfiCallerIdGuid.
398 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
399 ReportStatusCodeWithExtendedData() is called while processing another any other
400 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
401 must return EFI_DEVICE_ERROR immediately.
403 If ExtendedData is NULL, then ASSERT().
404 If ExtendedDataSize is 0, then ASSERT().
406 @param Type Status code type.
407 @param Value Status code value.
408 @param ExtendedData Pointer to the extended data buffer to be reported.
409 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
412 @retval EFI_SUCCESS The status code was reported with the extended
413 data specified by ExtendedData and ExtendedDataSize.
414 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
415 extended data section.
416 @retval EFI_UNSUPPORTED Report status code is not supported
421 GlueReportStatusCodeWithExtendedData (
422 IN EFI_STATUS_CODE_TYPE Type
,
423 IN EFI_STATUS_CODE_VALUE Value
,
424 IN CONST VOID
*ExtendedData
,
425 IN UINTN ExtendedDataSize
428 ASSERT (ExtendedData
!= NULL
);
429 ASSERT (ExtendedDataSize
!= 0);
430 return ReportStatusCodeEx (
443 Reports a status code with full parameters.
445 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
446 is 0, then an extended data buffer is not reported. If ExtendedData is not
447 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
448 ExtendedData is assumed not have the standard status code header, so this function
449 is responsible for allocating a buffer large enough for the standard header and
450 the extended data passed into this function. The standard header is filled in
451 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
452 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
453 an instance specified by Instance and a caller ID specified by CallerId. If
454 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
456 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
457 is called while processing another any other Report Status Code Library function,
458 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
460 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
461 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
463 @param Type Status code type.
464 @param Value Status code value.
465 @param Instance Status code instance number.
466 @param CallerId Pointer to a GUID that identifies the caller of this
467 function. If this parameter is NULL, then a caller
468 ID of gEfiCallerIdGuid is used.
469 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
470 If this parameter is NULL, then a the status code
471 standard header is filled in with
472 gEfiStatusCodeSpecificDataGuid.
473 @param ExtendedData Pointer to the extended data buffer. This is an
474 optional parameter that may be NULL.
475 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
477 @retval EFI_SUCCESS The status code was reported.
478 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
479 the extended data section if it was specified.
480 @retval EFI_UNSUPPORTED Report status code is not supported
485 GlueReportStatusCodeEx (
486 IN EFI_STATUS_CODE_TYPE Type
,
487 IN EFI_STATUS_CODE_VALUE Value
,
489 IN CONST EFI_GUID
*CallerId OPTIONAL
,
490 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
491 IN CONST VOID
*ExtendedData OPTIONAL
,
492 IN UINTN ExtendedDataSize
496 EFI_STATUS_CODE_DATA
*StatusCodeData
;
498 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
499 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
502 // Allocate space for the Status Code Header and its buffer
504 StatusCodeData
= NULL
;
505 (gBS
->AllocatePool
) (EfiBootServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + ExtendedDataSize
, (VOID
**)&StatusCodeData
);
506 if (StatusCodeData
== NULL
) {
507 return EFI_OUT_OF_RESOURCES
;
511 // Fill in the extended data header
513 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
514 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
515 if (ExtendedDataGuid
== NULL
) {
516 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
518 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
521 // Fill in the extended data buffer
523 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
526 // Report the status code
528 if (CallerId
== NULL
) {
529 CallerId
= &gEfiCallerIdGuid
;
531 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
534 // Free the allocated buffer
536 (gBS
->FreePool
) (StatusCodeData
);
543 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
545 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
546 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
548 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
549 PcdReportStatusCodeProperyMask is set.
550 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
551 PcdReportStatusCodeProperyMask is clear.
556 GlueReportProgressCodeEnabled (
560 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
565 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
567 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
568 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
570 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
571 PcdReportStatusCodeProperyMask is set.
572 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
573 PcdReportStatusCodeProperyMask is clear.
578 GlueReportErrorCodeEnabled (
582 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
587 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
589 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
590 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
592 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
593 PcdReportStatusCodeProperyMask is set.
594 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
595 PcdReportStatusCodeProperyMask is clear.
600 GlueReportDebugCodeEnabled (
604 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);