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 "ReportStatusCodeLibInternal.h"
17 EFI_REPORT_STATUS_CODE mReportStatusCode
= NULL
;
20 Internal worker function that reports a status code through the Status Code Protocol
22 This function checks to see if a Status Code Protocol is present in the handle
23 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
24 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
25 and the ReportStatusCode() service of the Status Code Protocol is called passing in
26 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
28 @param Type Status code type.
29 @param Value Status code value.
30 @param Instance Status code instance number.
31 @param CallerId Pointer to a GUID that identifies the caller of this
32 function. This is an optional parameter that may be
34 @param Data Pointer to the extended data buffer. This is an
35 optional parameter that may be NULL.
37 @retval EFI_SUCCESS The status code was reported.
38 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
39 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
43 InternalReportStatusCode (
44 IN EFI_STATUS_CODE_TYPE Type
,
45 IN EFI_STATUS_CODE_VALUE Value
,
47 IN CONST EFI_GUID
*CallerId OPTIONAL
,
48 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
51 if ((ReportProgressCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
52 (ReportErrorCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ||
53 (ReportDebugCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
)) {
55 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
56 // in the handle database.
58 if (mReportStatusCode
== NULL
) {
59 mReportStatusCode
= InternalGetReportStatusCode ();
60 if (mReportStatusCode
== NULL
) {
61 return EFI_UNSUPPORTED
;
66 // A Status Code Protocol is present in the handle database, so pass in all the
67 // parameters to the ReportStatusCode() service of the Status Code Protocol
69 return (*mReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
72 return EFI_UNSUPPORTED
;
77 Computes and returns the size, in bytes, of a device path.
79 @param DevicePath A pointer to a device path.
81 @return The size, in bytes, of DevicePath.
85 InternalReportStatusCodeDevicePathSize (
86 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
89 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
92 // Search for the end of the device path structure
95 while (!IsDevicePathEnd (DevicePath
)) {
96 DevicePath
= NextDevicePathNode (DevicePath
);
100 // Subtract the start node from the end node and add in the size of the end node
102 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
107 Converts a status code to an 8-bit POST code value.
109 Converts the status code specified by CodeType and Value to an 8-bit POST code
110 and returns the 8-bit POST code in PostCode. If CodeType is an
111 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
112 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
113 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
115 If PostCode is NULL, then ASSERT().
117 @param CodeType The type of status code being converted.
118 @param Value The status code value being converted.
119 @param PostCode A pointer to the 8-bit POST code value to return.
121 @retval TRUE The status code specified by CodeType and Value was converted
122 to an 8-bit POST code and returned in PostCode.
123 @retval FALSE The status code specified by CodeType and Value could not be
124 converted to an 8-bit POST code value.
130 IN EFI_STATUS_CODE_TYPE CodeType
,
131 IN EFI_STATUS_CODE_VALUE Value
,
136 // If PostCode is NULL, then ASSERT()
138 ASSERT (PostCode
!= NULL
);
141 // Convert Value to an 8 bit post code
143 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
144 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
145 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
146 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
154 Extracts ASSERT() information from a status code structure.
156 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
157 arguments specified by Filename, Description, and LineNumber. If CodeType is
158 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
159 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
160 Filename, Description, and LineNumber from the optional data area of the
161 status code buffer specified by Data. The optional data area of Data contains
162 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
163 ASCII string for the Description, followed by a 32-bit LineNumber. If the
164 ASSERT() information could be extracted from Data, then return TRUE.
165 Otherwise, FALSE is returned.
167 If Data is NULL, then ASSERT().
168 If Filename is NULL, then ASSERT().
169 If Description is NULL, then ASSERT().
170 If LineNumber is NULL, then ASSERT().
172 @param CodeType The type of status code being converted.
173 @param Value The status code value being converted.
174 @param Data Pointer to status code data buffer.
175 @param Filename Pointer to the source file name that generated the ASSERT().
176 @param Description Pointer to the description of the ASSERT().
177 @param LineNumber Pointer to source line number that generated the ASSERT().
179 @retval TRUE The status code specified by CodeType, Value, and Data was
180 converted ASSERT() arguments specified by Filename, Description,
182 @retval FALSE The status code specified by CodeType, Value, and Data could
183 not be converted to ASSERT() arguments.
188 ReportStatusCodeExtractAssertInfo (
189 IN EFI_STATUS_CODE_TYPE CodeType
,
190 IN EFI_STATUS_CODE_VALUE Value
,
191 IN CONST EFI_STATUS_CODE_DATA
*Data
,
192 OUT CHAR8
**Filename
,
193 OUT CHAR8
**Description
,
194 OUT UINT32
*LineNumber
197 EFI_DEBUG_ASSERT_DATA
*AssertData
;
199 ASSERT (Data
!= NULL
);
200 ASSERT (Filename
!= NULL
);
201 ASSERT (Description
!= NULL
);
202 ASSERT (LineNumber
!= NULL
);
204 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
205 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
206 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
207 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
208 *Filename
= (CHAR8
*)(AssertData
+ 1);
209 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
210 *LineNumber
= AssertData
->LineNumber
;
218 Extracts DEBUG() information from a status code structure.
220 Converts the status code specified by Data to the DEBUG() arguments specified
221 by ErrorLevel, Marker, and Format. If type GUID in Data is
222 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
223 Format from the optional data area of the status code buffer specified by Data.
224 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
225 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
226 the Format. If the DEBUG() information could be extracted from Data, then
227 return TRUE. Otherwise, FALSE is returned.
229 If Data is NULL, then ASSERT().
230 If ErrorLevel is NULL, then ASSERT().
231 If Marker is NULL, then ASSERT().
232 If Format is NULL, then ASSERT().
234 @param Data Pointer to status code data buffer.
235 @param ErrorLevel Pointer to error level mask for a debug message.
236 @param Marker Pointer to the variable argument list associated with Format.
237 @param Format Pointer to a Null-terminated ASCII format string of a
240 @retval TRUE The status code specified by Data was converted DEBUG() arguments
241 specified by ErrorLevel, Marker, and Format.
242 @retval FALSE The status code specified by Data could not be converted to
248 ReportStatusCodeExtractDebugInfo (
249 IN CONST EFI_STATUS_CODE_DATA
*Data
,
250 OUT UINT32
*ErrorLevel
,
251 OUT BASE_LIST
*Marker
,
255 EFI_DEBUG_INFO
*DebugInfo
;
257 ASSERT (Data
!= NULL
);
258 ASSERT (ErrorLevel
!= NULL
);
259 ASSERT (Marker
!= NULL
);
260 ASSERT (Format
!= NULL
);
263 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
265 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
270 // Retrieve the debug information from the status code record
272 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
274 *ErrorLevel
= DebugInfo
->ErrorLevel
;
277 // The first 12 * UINTN bytes of the string are really an
278 // argument stack to support varargs on the Format string.
280 *Marker
= (BASE_LIST
) (DebugInfo
+ 1);
281 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
288 Reports a status code.
290 Reports the status code specified by the parameters Type and Value. Status
291 code also require an instance, caller ID, and extended data. This function
292 passed in a zero instance, NULL extended data, and a caller ID of
293 gEfiCallerIdGuid, which is the GUID for the module.
295 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
296 is called while processing another any other Report Status Code Library function,
297 then ReportStatusCode() must return immediately.
299 @param Type Status code type.
300 @param Value Status code value.
302 @retval EFI_SUCCESS The status code was reported.
303 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
305 @retval EFI_UNSUPPORTED Report status code is not supported
311 IN EFI_STATUS_CODE_TYPE Type
,
312 IN EFI_STATUS_CODE_VALUE Value
315 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
320 Reports a status code with a Device Path Protocol as the extended data.
322 Allocates and fills in the extended data section of a status code with the
323 Device Path Protocol specified by DevicePath. This function is responsible
324 for allocating a buffer large enough for the standard header and the device
325 path. The standard header is filled in with a GUID of
326 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
327 instance and a caller ID of gEfiCallerIdGuid.
329 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
330 ReportStatusCodeWithDevicePath() is called while processing another any other
331 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
332 must return EFI_DEVICE_ERROR immediately.
334 If DevicePath is NULL, then ASSERT().
336 @param Type Status code type.
337 @param Value Status code value.
338 @param DevicePath Pointer to the Device Path Protocol to be reported.
340 @retval EFI_SUCCESS The status code was reported with the extended
341 data specified by DevicePath.
342 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
343 extended data section.
344 @retval EFI_UNSUPPORTED Report status code is not supported
349 ReportStatusCodeWithDevicePath (
350 IN EFI_STATUS_CODE_TYPE Type
,
351 IN EFI_STATUS_CODE_VALUE Value
,
352 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
355 ASSERT (DevicePath
!= NULL
);
356 return ReportStatusCodeWithExtendedData (
360 InternalReportStatusCodeDevicePathSize (DevicePath
)
366 Reports a status code with an extended data buffer.
368 Allocates and fills in the extended data section of a status code with the
369 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
370 is assumed to be one of the data structures specified in Related Definitions.
371 These data structure do not have the standard header, so this function is
372 responsible for allocating a buffer large enough for the standard header and
373 the extended data passed into this function. The standard header is filled
374 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
375 with a zero instance and a caller ID of gEfiCallerIdGuid.
377 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
378 ReportStatusCodeWithExtendedData() is called while processing another any other
379 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
380 must return EFI_DEVICE_ERROR immediately.
382 If ExtendedData is NULL, then ASSERT().
383 If ExtendedDataSize is 0, then ASSERT().
385 @param Type Status code type.
386 @param Value Status code value.
387 @param ExtendedData Pointer to the extended data buffer to be reported.
388 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
391 @retval EFI_SUCCESS The status code was reported with the extended
392 data specified by ExtendedData and ExtendedDataSize.
393 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
394 extended data section.
395 @retval EFI_UNSUPPORTED Report status code is not supported
400 ReportStatusCodeWithExtendedData (
401 IN EFI_STATUS_CODE_TYPE Type
,
402 IN EFI_STATUS_CODE_VALUE Value
,
403 IN CONST VOID
*ExtendedData
,
404 IN UINTN ExtendedDataSize
407 ASSERT (ExtendedData
!= NULL
);
408 ASSERT (ExtendedDataSize
!= 0);
409 return ReportStatusCodeEx (
422 Reports a status code with full parameters.
424 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
425 is 0, then an extended data buffer is not reported. If ExtendedData is not
426 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
427 ExtendedData is assumed not have the standard status code header, so this function
428 is responsible for allocating a buffer large enough for the standard header and
429 the extended data passed into this function. The standard header is filled in
430 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
431 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with
432 an instance specified by Instance and a caller ID specified by CallerId. If
433 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
435 ReportStatusCodeEx()must actively prevent recursion. If
436 ReportStatusCodeEx() is called while processing another any
437 other Report Status Code Library function, then
438 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
440 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
441 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
443 @param Type Status code type.
444 @param Value Status code value.
445 @param Instance Status code instance number.
446 @param CallerId Pointer to a GUID that identifies the caller of this
447 function. If this parameter is NULL, then a caller
448 ID of gEfiCallerIdGuid is used.
449 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
450 If this parameter is NULL, then a the status code
451 standard header is filled in with
452 gEfiStatusCodeSpecificDataGuid.
453 @param ExtendedData Pointer to the extended data buffer. This is an
454 optional parameter that may be NULL.
455 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
457 @retval EFI_SUCCESS The status code was reported.
458 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
459 the extended data section if it was specified.
460 @retval EFI_UNSUPPORTED Report status code is not supported
466 IN EFI_STATUS_CODE_TYPE Type
,
467 IN EFI_STATUS_CODE_VALUE Value
,
469 IN CONST EFI_GUID
*CallerId OPTIONAL
,
470 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
471 IN CONST VOID
*ExtendedData OPTIONAL
,
472 IN UINTN ExtendedDataSize
477 Status
= InternalReportStatusCodeEx (
492 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
494 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
495 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
497 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
498 PcdReportStatusCodeProperyMask is set.
499 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
500 PcdReportStatusCodeProperyMask is clear.
505 ReportProgressCodeEnabled (
509 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
514 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
516 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
517 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
519 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
520 PcdReportStatusCodeProperyMask is set.
521 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
522 PcdReportStatusCodeProperyMask is clear.
527 ReportErrorCodeEnabled (
531 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
536 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
538 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
539 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
541 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
542 PcdReportStatusCodeProperyMask is set.
543 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
544 PcdReportStatusCodeProperyMask is clear.
549 ReportDebugCodeEnabled (
553 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);