3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 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"
26 // Global pointer to the Status Code Protocol
28 static EFI_STATUS_CODE_PROTOCOL
*gStatusCode
= NULL
;
32 Internal worker function that reports a status code through the Status Code Protocol
34 This function checks to see if a Status Code Protocol is present in the handle
35 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
36 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
37 and the ReportStatusCode() service of the Status Code Protocol is called passing in
38 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
40 @param Type Status code type.
41 @param Value Status code value.
42 @param Instance Status code instance number.
43 @param CallerId Pointer to a GUID that identifies the caller of this
44 function. This is an optional parameter that may be
46 @param Data Pointer to the extended data buffer. This is an
47 optional parameter that may be NULL.
49 @retval EFI_SUCCESS The status code was reported.
50 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
51 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
56 InternalReportStatusCode (
57 IN EFI_STATUS_CODE_TYPE Type
,
58 IN EFI_STATUS_CODE_VALUE Value
,
60 IN CONST EFI_GUID
*CallerId OPTIONAL
,
61 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
67 return EFI_UNSUPPORTED
;
70 if (gRT
->Hdr
.Revision
>= 0x00020000) {
72 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
73 // in the handle database.
75 if (gStatusCode
== NULL
) {
76 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&gStatusCode
);
77 if (EFI_ERROR (Status
) || gStatusCode
== NULL
) {
78 return EFI_UNSUPPORTED
;
83 // A Status Code Protocol is present in the handle database, so pass in all the
84 // parameters to the ReportStatusCode() service of the Status Code Protocol
86 return (gStatusCode
->ReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
88 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
89 return (gRT
->ReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
91 return EFI_UNSUPPORTED
;
99 Computes and returns the size, in bytes, of a device path.
101 @param DevicePath A pointer to a device path.
103 @return The size, in bytes, of DevicePath.
108 InternalReportStatusCodeDevicePathSize (
109 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
112 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
115 // Search for the end of the device path structure
118 while (!EfiIsDevicePathEnd (DevicePath
)) {
119 DevicePath
= EfiNextDevicePathNode (DevicePath
);
123 // Subtract the start node from the end node and add in the size of the end node
125 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
130 Converts a status code to an 8-bit POST code value.
132 Converts the status code specified by CodeType and Value to an 8-bit POST code
133 and returns the 8-bit POST code in PostCode. If CodeType is an
134 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
135 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
136 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
138 If PostCode is NULL, then ASSERT().
140 @param CodeType The type of status code being converted.
141 @param Value The status code value being converted.
142 @param PostCode A pointer to the 8-bit POST code value to return.
144 @retval TRUE The status code specified by CodeType and Value was converted
145 to an 8-bit POST code and returned in PostCode.
146 @retval FALSE The status code specified by CodeType and Value could not be
147 converted to an 8-bit POST code value.
152 GlueCodeTypeToPostCode (
153 IN EFI_STATUS_CODE_TYPE CodeType
,
154 IN EFI_STATUS_CODE_VALUE Value
,
159 // If PostCode is NULL, then ASSERT()
161 ASSERT (PostCode
!= NULL
);
164 // Convert Value to an 8 bit post code
166 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
167 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
168 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
169 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
177 Extracts ASSERT() information from a status code structure.
179 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
180 arguments specified by Filename, Description, and LineNumber. If CodeType is
181 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
182 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
183 Filename, Description, and LineNumber from the optional data area of the
184 status code buffer specified by Data. The optional data area of Data contains
185 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
186 ASCII string for the Description, followed by a 32-bit LineNumber. If the
187 ASSERT() information could be extracted from Data, then return TRUE.
188 Otherwise, FALSE is returned.
190 If Data is NULL, then ASSERT().
191 If Filename is NULL, then ASSERT().
192 If Description is NULL, then ASSERT().
193 If LineNumber is NULL, then ASSERT().
195 @param CodeType The type of status code being converted.
196 @param Value The status code value being converted.
197 @param Data Pointer to status code data buffer.
198 @param Filename Pointer to the source file name that generated the ASSERT().
199 @param Description Pointer to the description of the ASSERT().
200 @param LineNumber Pointer to source line number that generated the ASSERT().
202 @retval TRUE The status code specified by CodeType, Value, and Data was
203 converted ASSERT() arguments specified by Filename, Description,
205 @retval FALSE The status code specified by CodeType, Value, and Data could
206 not be converted to ASSERT() arguments.
211 GlueReportStatusCodeExtractAssertInfo (
212 IN EFI_STATUS_CODE_TYPE CodeType
,
213 IN EFI_STATUS_CODE_VALUE Value
,
214 IN CONST EFI_STATUS_CODE_DATA
*Data
,
215 OUT CHAR8
**Filename
,
216 OUT CHAR8
**Description
,
217 OUT UINT32
*LineNumber
220 EFI_DEBUG_ASSERT_DATA
*AssertData
;
222 ASSERT (Data
!= NULL
);
223 ASSERT (Filename
!= NULL
);
224 ASSERT (Description
!= NULL
);
225 ASSERT (LineNumber
!= NULL
);
227 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
228 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
229 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
230 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
231 *Filename
= (CHAR8
*)(AssertData
+ 1);
232 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
233 *LineNumber
= AssertData
->LineNumber
;
241 Extracts DEBUG() information from a status code structure.
243 Converts the status code specified by Data to the DEBUG() arguments specified
244 by ErrorLevel, Marker, and Format. If type GUID in Data is
245 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
246 Format from the optional data area of the status code buffer specified by Data.
247 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
248 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
249 the Format. If the DEBUG() information could be extracted from Data, then
250 return TRUE. Otherwise, FALSE is returned.
252 If Data is NULL, then ASSERT().
253 If ErrorLevel is NULL, then ASSERT().
254 If Marker is NULL, then ASSERT().
255 If Format is NULL, then ASSERT().
257 @param Data Pointer to status code data buffer.
258 @param ErrorLevel Pointer to error level mask for a debug message.
259 @param Marker Pointer to the variable argument list associated with Format.
260 @param Format Pointer to a Null-terminated ASCII format string of a
263 @retval TRUE The status code specified by Data was converted DEBUG() arguments
264 specified by ErrorLevel, Marker, and Format.
265 @retval FALSE The status code specified by Data could not be converted to
271 GlueReportStatusCodeExtractDebugInfo (
272 IN CONST EFI_STATUS_CODE_DATA
*Data
,
273 OUT UINT32
*ErrorLevel
,
278 EFI_DEBUG_INFO
*DebugInfo
;
280 ASSERT (Data
!= NULL
);
281 ASSERT (ErrorLevel
!= NULL
);
282 ASSERT (Marker
!= NULL
);
283 ASSERT (Format
!= NULL
);
286 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
288 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
293 // Retrieve the debug information from the status code record
295 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
297 *ErrorLevel
= DebugInfo
->ErrorLevel
;
300 // This is non portable C code you can't assume VA_LIST is pointer
304 // The first 12 * UINTN bytes of the string are really an
305 // argument stack to support varargs on the Format string.
307 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
309 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
316 Reports a status code.
318 Reports the status code specified by the parameters Type and Value. Status
319 code also require an instance, caller ID, and extended data. This function
320 passed in a zero instance, NULL extended data, and a caller ID of
321 gEfiCallerIdGuid, which is the GUID for the module.
323 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
324 is called while processing another any other Report Status Code Library function,
325 then ReportStatusCode() must return immediately.
327 @param Type Status code type.
328 @param Value Status code value.
330 @retval EFI_SUCCESS The status code was reported.
331 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
333 @retval EFI_UNSUPPORTED Report status code is not supported
338 GlueReportStatusCode (
339 IN EFI_STATUS_CODE_TYPE Type
,
340 IN EFI_STATUS_CODE_VALUE Value
343 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
348 Reports a status code with a Device Path Protocol as the extended data.
350 Allocates and fills in the extended data section of a status code with the
351 Device Path Protocol specified by DevicePath. This function is responsible
352 for allocating a buffer large enough for the standard header and the device
353 path. The standard header is filled in with a GUID of
354 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
355 instance and a caller ID of gEfiCallerIdGuid.
357 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
358 ReportStatusCodeWithDevicePath() is called while processing another any other
359 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
360 must return EFI_DEVICE_ERROR immediately.
362 If DevicePath is NULL, then ASSERT().
364 @param Type Status code type.
365 @param Value Status code value.
366 @param DevicePath Pointer to the Device Path Protocol to be reported.
368 @retval EFI_SUCCESS The status code was reported with the extended
369 data specified by DevicePath.
370 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
371 extended data section.
372 @retval EFI_UNSUPPORTED Report status code is not supported
377 GlueReportStatusCodeWithDevicePath (
378 IN EFI_STATUS_CODE_TYPE Type
,
379 IN EFI_STATUS_CODE_VALUE Value
,
380 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
383 ASSERT (DevicePath
!= NULL
);
384 return ReportStatusCodeWithExtendedData (
388 InternalReportStatusCodeDevicePathSize (DevicePath
)
394 Reports a status code with an extended data buffer.
396 Allocates and fills in the extended data section of a status code with the
397 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
398 is assumed to be one of the data structures specified in Related Definitions.
399 These data structure do not have the standard header, so this function is
400 responsible for allocating a buffer large enough for the standard header and
401 the extended data passed into this function. The standard header is filled
402 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
403 with a zero instance and a caller ID of gEfiCallerIdGuid.
405 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
406 ReportStatusCodeWithExtendedData() is called while processing another any other
407 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
408 must return EFI_DEVICE_ERROR immediately.
410 If ExtendedData is NULL, then ASSERT().
411 If ExtendedDataSize is 0, then ASSERT().
413 @param Type Status code type.
414 @param Value Status code value.
415 @param ExtendedData Pointer to the extended data buffer to be reported.
416 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
419 @retval EFI_SUCCESS The status code was reported with the extended
420 data specified by ExtendedData and ExtendedDataSize.
421 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
422 extended data section.
423 @retval EFI_UNSUPPORTED Report status code is not supported
428 GlueReportStatusCodeWithExtendedData (
429 IN EFI_STATUS_CODE_TYPE Type
,
430 IN EFI_STATUS_CODE_VALUE Value
,
431 IN CONST VOID
*ExtendedData
,
432 IN UINTN ExtendedDataSize
435 ASSERT (ExtendedData
!= NULL
);
436 ASSERT (ExtendedDataSize
!= 0);
437 return ReportStatusCodeEx (
450 Reports a status code with full parameters.
452 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
453 is 0, then an extended data buffer is not reported. If ExtendedData is not
454 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
455 ExtendedData is assumed not have the standard status code header, so this function
456 is responsible for allocating a buffer large enough for the standard header and
457 the extended data passed into this function. The standard header is filled in
458 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
459 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
460 an instance specified by Instance and a caller ID specified by CallerId. If
461 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
463 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
464 is called while processing another any other Report Status Code Library function,
465 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
467 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
468 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
470 @param Type Status code type.
471 @param Value Status code value.
472 @param Instance Status code instance number.
473 @param CallerId Pointer to a GUID that identifies the caller of this
474 function. If this parameter is NULL, then a caller
475 ID of gEfiCallerIdGuid is used.
476 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
477 If this parameter is NULL, then a the status code
478 standard header is filled in with
479 gEfiStatusCodeSpecificDataGuid.
480 @param ExtendedData Pointer to the extended data buffer. This is an
481 optional parameter that may be NULL.
482 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
484 @retval EFI_SUCCESS The status code was reported.
485 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
486 the extended data section if it was specified.
487 @retval EFI_UNSUPPORTED Report status code is not supported
492 GlueReportStatusCodeEx (
493 IN EFI_STATUS_CODE_TYPE Type
,
494 IN EFI_STATUS_CODE_VALUE Value
,
496 IN CONST EFI_GUID
*CallerId OPTIONAL
,
497 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
498 IN CONST VOID
*ExtendedData OPTIONAL
,
499 IN UINTN ExtendedDataSize
503 EFI_STATUS_CODE_DATA
*StatusCodeData
;
505 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
506 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
509 // Allocate space for the Status Code Header and its buffer
511 StatusCodeData
= NULL
;
512 (gBS
->AllocatePool
) (EfiBootServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + ExtendedDataSize
, (VOID
**)&StatusCodeData
);
513 if (StatusCodeData
== NULL
) {
514 return EFI_OUT_OF_RESOURCES
;
518 // Fill in the extended data header
520 StatusCodeData
->HeaderSize
= (UINT16
) sizeof (EFI_STATUS_CODE_DATA
);
521 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
522 if (ExtendedDataGuid
== NULL
) {
523 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
525 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
528 // Fill in the extended data buffer
530 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
533 // Report the status code
535 if (CallerId
== NULL
) {
536 CallerId
= &gEfiCallerIdGuid
;
538 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
541 // Free the allocated buffer
543 (gBS
->FreePool
) (StatusCodeData
);
550 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
552 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
553 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
555 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
556 PcdReportStatusCodeProperyMask is set.
557 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
558 PcdReportStatusCodeProperyMask is clear.
563 GlueReportProgressCodeEnabled (
567 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
572 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
574 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
575 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
577 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
578 PcdReportStatusCodeProperyMask is set.
579 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
580 PcdReportStatusCodeProperyMask is clear.
585 GlueReportErrorCodeEnabled (
589 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
594 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
596 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
597 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
599 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
600 PcdReportStatusCodeProperyMask is set.
601 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
602 PcdReportStatusCodeProperyMask is clear.
607 GlueReportDebugCodeEnabled (
611 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);