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.
17 #include <Framework/StatusCodeDataTypeId.h>
18 #include <Framework/StatusCode.h>
20 #include <Guid/StatusCodeDataTypeId.h>
21 #include <Library/ReportStatusCodeLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/BaseLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/PcdLib.h>
30 Internal worker function that reports a status code through the Status Code Protocol
32 This function checks to see if a Status Code Protocol is present in the handle
33 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
34 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
35 and the ReportStatusCode() service of the Status Code Protocol is called passing in
36 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
38 @param Type Status code type.
39 @param Value Status code value.
40 @param Instance Status code instance number.
41 @param CallerId Pointer to a GUID that identifies the caller of this
42 function. This is an optional parameter that may be
44 @param Data Pointer to the extended data buffer. This is an
45 optional parameter that may be NULL.
47 @retval EFI_SUCCESS The status code was reported.
48 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
49 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
54 InternalReportStatusCode (
55 IN EFI_STATUS_CODE_TYPE Type
,
56 IN EFI_STATUS_CODE_VALUE Value
,
58 IN CONST EFI_GUID
*CallerId OPTIONAL
,
59 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
67 Computes and returns the size, in bytes, of a device path.
69 @param DevicePath A pointer to a device path.
71 @return The size, in bytes, of DevicePath.
76 InternalReportStatusCodeDevicePathSize (
77 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
80 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
83 // Search for the end of the device path structure
86 while (!EfiIsDevicePathEnd (DevicePath
)) {
87 DevicePath
= EfiNextDevicePathNode (DevicePath
);
91 // Subtract the start node from the end node and add in the size of the end node
93 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
98 Converts a status code to an 8-bit POST code value.
100 Converts the status code specified by CodeType and Value to an 8-bit POST code
101 and returns the 8-bit POST code in PostCode. If CodeType is an
102 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
103 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
104 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
106 If PostCode is NULL, then ASSERT().
108 @param CodeType The type of status code being converted.
109 @param Value The status code value being converted.
110 @param PostCode A pointer to the 8-bit POST code value to return.
112 @retval TRUE The status code specified by CodeType and Value was converted
113 to an 8-bit POST code and returned in PostCode.
114 @retval FALSE The status code specified by CodeType and Value could not be
115 converted to an 8-bit POST code value.
121 IN EFI_STATUS_CODE_TYPE CodeType
,
122 IN EFI_STATUS_CODE_VALUE Value
,
127 // If PostCode is NULL, then ASSERT()
129 ASSERT (PostCode
!= NULL
);
132 // Convert Value to an 8 bit post code
134 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
135 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
136 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
137 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
145 Extracts ASSERT() information from a status code structure.
147 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
148 arguments specified by Filename, Description, and LineNumber. If CodeType is
149 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
150 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
151 Filename, Description, and LineNumber from the optional data area of the
152 status code buffer specified by Data. The optional data area of Data contains
153 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
154 ASCII string for the Description, followed by a 32-bit LineNumber. If the
155 ASSERT() information could be extracted from Data, then return TRUE.
156 Otherwise, FALSE is returned.
158 If Data is NULL, then ASSERT().
159 If Filename is NULL, then ASSERT().
160 If Description is NULL, then ASSERT().
161 If LineNumber is NULL, then ASSERT().
163 @param CodeType The type of status code being converted.
164 @param Value The status code value being converted.
165 @param Data Pointer to status code data buffer.
166 @param Filename Pointer to the source file name that generated the ASSERT().
167 @param Description Pointer to the description of the ASSERT().
168 @param LineNumber Pointer to source line number that generated the ASSERT().
170 @retval TRUE The status code specified by CodeType, Value, and Data was
171 converted ASSERT() arguments specified by Filename, Description,
173 @retval FALSE The status code specified by CodeType, Value, and Data could
174 not be converted to ASSERT() arguments.
179 ReportStatusCodeExtractAssertInfo (
180 IN EFI_STATUS_CODE_TYPE CodeType
,
181 IN EFI_STATUS_CODE_VALUE Value
,
182 IN CONST EFI_STATUS_CODE_DATA
*Data
,
183 OUT CHAR8
**Filename
,
184 OUT CHAR8
**Description
,
185 OUT UINT32
*LineNumber
188 EFI_DEBUG_ASSERT_DATA
*AssertData
;
190 ASSERT (Data
!= NULL
);
191 ASSERT (Filename
!= NULL
);
192 ASSERT (Description
!= NULL
);
193 ASSERT (LineNumber
!= NULL
);
195 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
196 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
197 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
198 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
199 *Filename
= (CHAR8
*)(AssertData
+ 1);
200 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
201 *LineNumber
= AssertData
->LineNumber
;
209 Extracts DEBUG() information from a status code structure.
211 Converts the status code specified by Data to the DEBUG() arguments specified
212 by ErrorLevel, Marker, and Format. If type GUID in Data is
213 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
214 Format from the optional data area of the status code buffer specified by Data.
215 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
216 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
217 the Format. If the DEBUG() information could be extracted from Data, then
218 return TRUE. Otherwise, FALSE is returned.
220 If Data is NULL, then ASSERT().
221 If ErrorLevel is NULL, then ASSERT().
222 If Marker is NULL, then ASSERT().
223 If Format is NULL, then ASSERT().
225 @param Data Pointer to status code data buffer.
226 @param ErrorLevel Pointer to error level mask for a debug message.
227 @param Marker Pointer to the variable argument list associated with Format.
228 @param Format Pointer to a Null-terminated ASCII format string of a
231 @retval TRUE The status code specified by Data was converted DEBUG() arguments
232 specified by ErrorLevel, Marker, and Format.
233 @retval FALSE The status code specified by Data could not be converted to
239 ReportStatusCodeExtractDebugInfo (
240 IN CONST EFI_STATUS_CODE_DATA
*Data
,
241 OUT UINT32
*ErrorLevel
,
246 EFI_DEBUG_INFO
*DebugInfo
;
248 ASSERT (Data
!= NULL
);
249 ASSERT (ErrorLevel
!= NULL
);
250 ASSERT (Marker
!= NULL
);
251 ASSERT (Format
!= NULL
);
254 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
256 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
261 // Retrieve the debug information from the status code record
263 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
265 *ErrorLevel
= DebugInfo
->ErrorLevel
;
268 // The first 12 * UINTN bytes of the string are really an
269 // argument stack to support varargs on the Format string.
271 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
272 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
279 Reports a status code.
281 Reports the status code specified by the parameters Type and Value. Status
282 code also require an instance, caller ID, and extended data. This function
283 passed in a zero instance, NULL extended data, and a caller ID of
284 gEfiCallerIdGuid, which is the GUID for the module.
286 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
287 is called while processing another any other Report Status Code Library function,
288 then ReportStatusCode() must return immediately.
290 @param Type Status code type.
291 @param Value Status code value.
293 @retval EFI_SUCCESS The status code was reported.
294 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
296 @retval EFI_UNSUPPORTED Report status code is not supported
302 IN EFI_STATUS_CODE_TYPE Type
,
303 IN EFI_STATUS_CODE_VALUE Value
306 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
311 Reports a status code with a Device Path Protocol as the extended data.
313 Allocates and fills in the extended data section of a status code with the
314 Device Path Protocol specified by DevicePath. This function is responsible
315 for allocating a buffer large enough for the standard header and the device
316 path. The standard header is filled in with a GUID of
317 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
318 instance and a caller ID of gEfiCallerIdGuid.
320 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
321 ReportStatusCodeWithDevicePath() is called while processing another any other
322 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
323 must return EFI_DEVICE_ERROR immediately.
325 If DevicePath is NULL, then ASSERT().
327 @param Type Status code type.
328 @param Value Status code value.
329 @param DevicePath Pointer to the Device Path Protocol to be reported.
331 @retval EFI_SUCCESS The status code was reported with the extended
332 data specified by DevicePath.
333 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
334 extended data section.
335 @retval EFI_UNSUPPORTED Report status code is not supported
340 ReportStatusCodeWithDevicePath (
341 IN EFI_STATUS_CODE_TYPE Type
,
342 IN EFI_STATUS_CODE_VALUE Value
,
343 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
346 ASSERT (DevicePath
!= NULL
);
347 return ReportStatusCodeWithExtendedData (
351 InternalReportStatusCodeDevicePathSize (DevicePath
)
357 Reports a status code with an extended data buffer.
359 Allocates and fills in the extended data section of a status code with the
360 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
361 is assumed to be one of the data structures specified in Related Definitions.
362 These data structure do not have the standard header, so this function is
363 responsible for allocating a buffer large enough for the standard header and
364 the extended data passed into this function. The standard header is filled
365 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
366 with a zero instance and a caller ID of gEfiCallerIdGuid.
368 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
369 ReportStatusCodeWithExtendedData() is called while processing another any other
370 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
371 must return EFI_DEVICE_ERROR immediately.
373 If ExtendedData is NULL, then ASSERT().
374 If ExtendedDataSize is 0, then ASSERT().
376 @param Type Status code type.
377 @param Value Status code value.
378 @param ExtendedData Pointer to the extended data buffer to be reported.
379 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
382 @retval EFI_SUCCESS The status code was reported with the extended
383 data specified by ExtendedData and ExtendedDataSize.
384 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
385 extended data section.
386 @retval EFI_UNSUPPORTED Report status code is not supported
391 ReportStatusCodeWithExtendedData (
392 IN EFI_STATUS_CODE_TYPE Type
,
393 IN EFI_STATUS_CODE_VALUE Value
,
394 IN CONST VOID
*ExtendedData
,
395 IN UINTN ExtendedDataSize
398 ASSERT (ExtendedData
!= NULL
);
399 ASSERT (ExtendedDataSize
!= 0);
400 return ReportStatusCodeEx (
413 Reports a status code with full parameters.
415 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
416 is 0, then an extended data buffer is not reported. If ExtendedData is not
417 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
418 ExtendedData is assumed not have the standard status code header, so this function
419 is responsible for allocating a buffer large enough for the standard header and
420 the extended data passed into this function. The standard header is filled in
421 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
422 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
423 an instance specified by Instance and a caller ID specified by CallerId. If
424 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
426 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
427 is called while processing another any other Report Status Code Library function,
428 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
430 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
431 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
433 @param Type Status code type.
434 @param Value Status code value.
435 @param Instance Status code instance number.
436 @param CallerId Pointer to a GUID that identifies the caller of this
437 function. If this parameter is NULL, then a caller
438 ID of gEfiCallerIdGuid is used.
439 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
440 If this parameter is NULL, then a the status code
441 standard header is filled in with
442 gEfiStatusCodeSpecificDataGuid.
443 @param ExtendedData Pointer to the extended data buffer. This is an
444 optional parameter that may be NULL.
445 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
447 @retval EFI_SUCCESS The status code was reported.
448 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
449 the extended data section if it was specified.
450 @retval EFI_UNSUPPORTED Report status code is not supported
456 IN EFI_STATUS_CODE_TYPE Type
,
457 IN EFI_STATUS_CODE_VALUE Value
,
459 IN CONST EFI_GUID
*CallerId OPTIONAL
,
460 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
461 IN CONST VOID
*ExtendedData OPTIONAL
,
462 IN UINTN ExtendedDataSize
470 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
472 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
473 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
475 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
476 PcdReportStatusCodeProperyMask is set.
477 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
478 PcdReportStatusCodeProperyMask is clear.
483 ReportProgressCodeEnabled (
487 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
492 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
494 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
495 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
497 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
498 PcdReportStatusCodeProperyMask is set.
499 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
500 PcdReportStatusCodeProperyMask is clear.
505 ReportErrorCodeEnabled (
509 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
514 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
516 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
517 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
519 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
520 PcdReportStatusCodeProperyMask is set.
521 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
522 PcdReportStatusCodeProperyMask is clear.
527 ReportDebugCodeEnabled (
531 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);