2 Report Status Code Library for DXE Phase.
4 Copyright (c) 2006, 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.
16 // Global pointer to the Status Code Protocol
18 static EFI_STATUS_CODE_PROTOCOL
*gStatusCode
= NULL
;
21 Internal worker function that reports a status code through the Status Code Protocol
23 This function checks to see if a Status Code Protocol is present in the handle
24 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
25 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
26 and the ReportStatusCode() service of the Status Code Protocol is called passing in
27 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
29 @param Type Status code type.
30 @param Value Status code value.
31 @param Instance Status code instance number.
32 @param CallerId Pointer to a GUID that identifies the caller of this
33 function. This is an optional parameter that may be
35 @param Data Pointer to the extended data buffer. This is an
36 optional parameter that may be NULL.
38 @retval EFI_SUCCESS The status code was reported.
39 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
40 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
44 InternalReportStatusCode (
45 IN EFI_STATUS_CODE_TYPE Type
,
46 IN EFI_STATUS_CODE_VALUE Value
,
48 IN EFI_GUID
*CallerId OPTIONAL
,
49 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
55 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
56 // in the handle database.
58 if (gStatusCode
== NULL
) {
59 Status
= gBS
->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid
, NULL
, (VOID
**)&gStatusCode
);
60 if (EFI_ERROR (Status
) || gStatusCode
== 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 gStatusCode
->ReportStatusCode (Type
, Value
, Instance
, CallerId
, Data
);
74 Computes and returns the size, in bytes, of a device path.
76 @param DevicePath A pointer to a device path.
78 @return The size, in bytes, of DevicePath.
82 InternalReportStatusCodeDevicePathSize (
83 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
86 EFI_DEVICE_PATH_PROTOCOL
*Start
;
88 if (DevicePath
== NULL
) {
93 // Search for the end of the device path structure
96 while (!EfiIsDevicePathEnd (DevicePath
)) {
97 DevicePath
= EfiNextDevicePathNode (DevicePath
);
101 // Subtract the start node from the end node and add in the size of the end node
103 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
108 Converts a status code to an 8-bit POST code value.
110 Converts the status code specified by CodeType and Value to an 8-bit POST code
111 and returns the 8-bit POST code in PostCode. If CodeType is an
112 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
113 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
114 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
116 If PostCode is NULL, then ASSERT().
118 @param CodeType The type of status code being converted.
119 @param Value The status code value being converted.
120 @param PostCode A pointer to the 8-bit POST code value to return.
122 @retval TRUE The status code specified by CodeType and Value was converted
123 to an 8-bit POST code and returned in PostCode.
124 @retval FALSE The status code specified by CodeType and Value could not be
125 converted to an 8-bit POST code value.
131 IN EFI_STATUS_CODE_TYPE CodeType
,
132 IN EFI_STATUS_CODE_VALUE Value
,
137 // If PostCode is NULL, then ASSERT()
139 ASSERT (PostCode
!= NULL
);
142 // Convert Value to an 8 bit post code
144 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
145 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
146 *PostCode
= (UINT8
) (((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5);
147 *PostCode
|= (UINT8
) (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f);
155 Extracts ASSERT() information from a status code structure.
157 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
158 arguments specified by Filename, Description, and LineNumber. If CodeType is
159 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
160 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
161 Filename, Description, and LineNumber from the optional data area of the
162 status code buffer specified by Data. The optional data area of Data contains
163 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
164 ASCII string for the Description, followed by a 32-bit LineNumber. If the
165 ASSERT() information could be extracted from Data, then return TRUE.
166 Otherwise, FALSE is returned.
168 If Data is NULL, then ASSERT().
169 If Filename is NULL, then ASSERT().
170 If Description is NULL, then ASSERT().
171 If LineNumber is NULL, then ASSERT().
173 @param CodeType The type of status code being converted.
174 @param Value The status code value being converted.
175 @param Data Pointer to status code data buffer.
176 @param Filename Pointer to the source file name that generated the ASSERT().
177 @param Description Pointer to the description of the ASSERT().
178 @param LineNumber Pointer to source line number that generated the ASSERT().
180 @retval TRUE The status code specified by CodeType, Value, and Data was
181 converted ASSERT() arguments specified by Filename, Description,
183 @retval FALSE The status code specified by CodeType, Value, and Data could
184 not be converted to ASSERT() arguments.
189 ReportStatusCodeExtractAssertInfo (
190 IN EFI_STATUS_CODE_TYPE CodeType
,
191 IN EFI_STATUS_CODE_VALUE Value
,
192 IN EFI_STATUS_CODE_DATA
*Data
,
193 OUT CHAR8
**Filename
,
194 OUT CHAR8
**Description
,
195 OUT UINT32
*LineNumber
198 EFI_DEBUG_ASSERT_DATA
*AssertData
;
200 ASSERT (Data
!= NULL
);
201 ASSERT (Filename
!= NULL
);
202 ASSERT (Description
!= NULL
);
203 ASSERT (LineNumber
!= NULL
);
205 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
206 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
207 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
208 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
209 *Filename
= (CHAR8
*)(AssertData
+ 1);
210 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
211 *LineNumber
= AssertData
->LineNumber
;
219 Extracts DEBUG() information from a status code structure.
221 Converts the status code specified by Data to the DEBUG() arguments specified
222 by ErrorLevel, Marker, and Format. If type GUID in Data is
223 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
224 Format from the optional data area of the status code buffer specified by Data.
225 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
226 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
227 the Format. If the DEBUG() information could be extracted from Data, then
228 return TRUE. Otherwise, FALSE is returned.
230 If Data is NULL, then ASSERT().
231 If ErrorLevel is NULL, then ASSERT().
232 If Marker is NULL, then ASSERT().
233 If Format is NULL, then ASSERT().
235 @param Data Pointer to status code data buffer.
236 @param ErrorLevel Pointer to error level mask for a debug message.
237 @param Marker Pointer to the variable argument list associated with Format.
238 @param Format Pointer to a Null-terminated ASCII format string of a
241 @retval TRUE The status code specified by Data was converted DEBUG() arguments
242 specified by ErrorLevel, Marker, and Format.
243 @retval FALSE The status code specified by Data could not be converted to
249 ReportStatusCodeExtractDebugInfo (
250 IN EFI_STATUS_CODE_DATA
*Data
,
251 OUT UINT32
*ErrorLevel
,
256 EFI_DEBUG_INFO
*DebugInfo
;
258 ASSERT (Data
!= NULL
);
259 ASSERT (ErrorLevel
!= NULL
);
260 ASSERT (Marker
!= NULL
);
261 ASSERT (Format
!= NULL
);
264 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
266 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
271 // Retrieve the debug information from the status code record
273 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
275 *ErrorLevel
= DebugInfo
->ErrorLevel
;
278 // The first 12 * UINTN bytes of the string are really an
279 // argument stack to support varargs on the Format string.
281 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
282 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
289 Reports a status code.
291 Reports the status code specified by the parameters Type and Value. Status
292 code also require an instance, caller ID, and extended data. This function
293 passed in a zero instance, NULL extended data, and a caller ID of
294 gEfiCallerIdGuid, which is the GUID for the module.
296 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
297 is called while processing another any other Report Status Code Library function,
298 then ReportStatusCode() must return immediately.
300 @param Type Status code type.
301 @param Value Status code value.
303 @retval EFI_SUCCESS The status code was reported.
304 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
306 @retval EFI_UNSUPPORTED Report status code is not supported
312 IN EFI_STATUS_CODE_TYPE Type
,
313 IN EFI_STATUS_CODE_VALUE Value
316 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
321 Reports a status code with a Device Path Protocol as the extended data.
323 Allocates and fills in the extended data section of a status code with the
324 Device Path Protocol specified by DevicePath. This function is responsible
325 for allocating a buffer large enough for the standard header and the device
326 path. The standard header is filled in with a GUID of
327 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
328 instance and a caller ID of gEfiCallerIdGuid.
330 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
331 ReportStatusCodeWithDevicePath() is called while processing another any other
332 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
333 must return EFI_DEVICE_ERROR immediately.
335 If DevicePath is NULL, then ASSERT().
337 @param Type Status code type.
338 @param Value Status code value.
339 @param DevicePath Pointer to the Device Path Protocol to be reported.
341 @retval EFI_SUCCESS The status code was reported with the extended
342 data specified by DevicePath.
343 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
344 extended data section.
345 @retval EFI_UNSUPPORTED Report status code is not supported
350 ReportStatusCodeWithDevicePath (
351 IN EFI_STATUS_CODE_TYPE Type
,
352 IN EFI_STATUS_CODE_VALUE Value
,
353 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
356 ASSERT (DevicePath
!= NULL
);
357 return ReportStatusCodeWithExtendedData (
361 InternalReportStatusCodeDevicePathSize (DevicePath
)
367 Reports a status code with an extended data buffer.
369 Allocates and fills in the extended data section of a status code with the
370 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
371 is assumed to be one of the data structures specified in Related Definitions.
372 These data structure do not have the standard header, so this function is
373 responsible for allocating a buffer large enough for the standard header and
374 the extended data passed into this function. The standard header is filled
375 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
376 with a zero instance and a caller ID of gEfiCallerIdGuid.
378 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
379 ReportStatusCodeWithExtendedData() is called while processing another any other
380 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
381 must return EFI_DEVICE_ERROR immediately.
383 If ExtendedData is NULL, then ASSERT().
384 If ExtendedDataSize is 0, then ASSERT().
386 @param Type Status code type.
387 @param Value Status code value.
388 @param ExtendedData Pointer to the extended data buffer to be reported.
389 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
392 @retval EFI_SUCCESS The status code was reported with the extended
393 data specified by ExtendedData and ExtendedDataSize.
394 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
395 extended data section.
396 @retval EFI_UNSUPPORTED Report status code is not supported
401 ReportStatusCodeWithExtendedData (
402 IN EFI_STATUS_CODE_TYPE Type
,
403 IN EFI_STATUS_CODE_VALUE Value
,
404 IN VOID
*ExtendedData
,
405 IN UINTN ExtendedDataSize
408 ASSERT (ExtendedData
!= NULL
);
409 ASSERT (ExtendedDataSize
!= 0);
410 return ReportStatusCodeEx (
423 Reports a status code with full parameters.
425 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
426 is 0, then an extended data buffer is not reported. If ExtendedData is not
427 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
428 ExtendedData is assumed not have the standard status code header, so this function
429 is responsible for allocating a buffer large enough for the standard header and
430 the extended data passed into this function. The standard header is filled in
431 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
432 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
433 an instance specified by Instance and a caller ID specified by CallerId. If
434 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
436 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
437 is called while processing another any other Report Status Code Library function,
438 then 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 EFI_GUID
*CallerId OPTIONAL
,
470 IN EFI_GUID
*ExtendedDataGuid OPTIONAL
,
471 IN VOID
*ExtendedData OPTIONAL
,
472 IN UINTN ExtendedDataSize
476 EFI_STATUS_CODE_DATA
*StatusCodeData
;
478 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
479 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
482 // Allocate space for the Status Code Header and its buffer
484 StatusCodeData
= NULL
;
485 gBS
->AllocatePool (EfiBootServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + ExtendedDataSize
, (VOID
**)&StatusCodeData
);
486 if (StatusCodeData
== NULL
) {
487 return EFI_OUT_OF_RESOURCES
;
491 // Fill in the extended data header
493 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
494 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
495 if (ExtendedDataGuid
== NULL
) {
496 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
498 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
501 // Fill in the extended data buffer
503 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
506 // Report the status code
508 if (CallerId
== NULL
) {
509 CallerId
= &gEfiCallerIdGuid
;
511 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
514 // Free the allocated buffer
516 gBS
->FreePool (StatusCodeData
);
523 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
525 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
526 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
528 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
529 PcdReportStatusCodeProperyMask is set.
530 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
531 PcdReportStatusCodeProperyMask is clear.
536 ReportProgressCodeEnabled (
540 return ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
545 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
547 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
548 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
550 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
551 PcdReportStatusCodeProperyMask is set.
552 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
553 PcdReportStatusCodeProperyMask is clear.
558 ReportErrorCodeEnabled (
562 return ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
567 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
569 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
570 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
572 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
573 PcdReportStatusCodeProperyMask is set.
574 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
575 PcdReportStatusCodeProperyMask is clear.
580 ReportDebugCodeEnabled (
584 return ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);