2 Report Status Code Library for SMM Runtime driver.
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"
19 EFI_REPORT_STATUS_CODE mReportStatusCode
= NULL
;
22 Internal worker function that reports a status code through the Status Code Protocol
24 This function checks to see if a Status Code Protocol is present in the handle
25 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
26 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
27 and the ReportStatusCode() service of the Status Code Protocol is called passing in
28 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
30 @param Type Status code type.
31 @param Value Status code value.
32 @param Instance Status code instance number.
33 @param CallerId Pointer to a GUID that identifies the caller of this
34 function. This is an optional parameter that may be
36 @param Data Pointer to the extended data buffer. This is an
37 optional parameter that may be NULL.
39 @retval EFI_SUCCESS The status code was reported.
40 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
41 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
45 InternalReportStatusCode (
46 IN EFI_STATUS_CODE_TYPE Type
,
47 IN EFI_STATUS_CODE_VALUE Value
,
49 IN CONST EFI_GUID
*CallerId OPTIONAL
,
50 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
54 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
55 // in the handle database.
57 if (mReportStatusCode
== NULL
) {
58 mReportStatusCode
= InternalGetReportStatusCode ();
59 if (mReportStatusCode
== NULL
) {
60 return EFI_UNSUPPORTED
;
65 // A Status Code Protocol is present in the handle database, so pass in all the
66 // parameters to the ReportStatusCode() service of the Status Code Protocol
68 return (*mReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
73 Computes and returns the size, in bytes, of a device path.
75 @param DevicePath A pointer to a device path.
77 @return The size, in bytes, of DevicePath.
81 InternalReportStatusCodeDevicePathSize (
82 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
85 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
88 // Search for the end of the device path structure
91 while (!IsDevicePathEnd (DevicePath
)) {
92 DevicePath
= NextDevicePathNode (DevicePath
);
96 // Subtract the start node from the end node and add in the size of the end node
98 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
103 Converts a status code to an 8-bit POST code value.
105 Converts the status code specified by CodeType and Value to an 8-bit POST code
106 and returns the 8-bit POST code in PostCode. If CodeType is an
107 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
108 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
109 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
111 If PostCode is NULL, then ASSERT().
113 @param CodeType The type of status code being converted.
114 @param Value The status code value being converted.
115 @param PostCode A pointer to the 8-bit POST code value to return.
117 @retval TRUE The status code specified by CodeType and Value was converted
118 to an 8-bit POST code and returned in PostCode.
119 @retval FALSE The status code specified by CodeType and Value could not be
120 converted to an 8-bit POST code value.
126 IN EFI_STATUS_CODE_TYPE CodeType
,
127 IN EFI_STATUS_CODE_VALUE Value
,
132 // If PostCode is NULL, then ASSERT()
134 ASSERT (PostCode
!= NULL
);
137 // Convert Value to an 8 bit post code
139 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
140 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
141 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
142 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
150 Extracts ASSERT() information from a status code structure.
152 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
153 arguments specified by Filename, Description, and LineNumber. If CodeType is
154 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
155 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
156 Filename, Description, and LineNumber from the optional data area of the
157 status code buffer specified by Data. The optional data area of Data contains
158 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
159 ASCII string for the Description, followed by a 32-bit LineNumber. If the
160 ASSERT() information could be extracted from Data, then return TRUE.
161 Otherwise, FALSE is returned.
163 If Data is NULL, then ASSERT().
164 If Filename is NULL, then ASSERT().
165 If Description is NULL, then ASSERT().
166 If LineNumber is NULL, then ASSERT().
168 @param CodeType The type of status code being converted.
169 @param Value The status code value being converted.
170 @param Data Pointer to status code data buffer.
171 @param Filename Pointer to the source file name that generated the ASSERT().
172 @param Description Pointer to the description of the ASSERT().
173 @param LineNumber Pointer to source line number that generated the ASSERT().
175 @retval TRUE The status code specified by CodeType, Value, and Data was
176 converted ASSERT() arguments specified by Filename, Description,
178 @retval FALSE The status code specified by CodeType, Value, and Data could
179 not be converted to ASSERT() arguments.
184 ReportStatusCodeExtractAssertInfo (
185 IN EFI_STATUS_CODE_TYPE CodeType
,
186 IN EFI_STATUS_CODE_VALUE Value
,
187 IN CONST EFI_STATUS_CODE_DATA
*Data
,
188 OUT CHAR8
**Filename
,
189 OUT CHAR8
**Description
,
190 OUT UINT32
*LineNumber
193 EFI_DEBUG_ASSERT_DATA
*AssertData
;
195 ASSERT (Data
!= NULL
);
196 ASSERT (Filename
!= NULL
);
197 ASSERT (Description
!= NULL
);
198 ASSERT (LineNumber
!= NULL
);
200 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
201 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
202 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
203 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
204 *Filename
= (CHAR8
*)(AssertData
+ 1);
205 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
206 *LineNumber
= AssertData
->LineNumber
;
214 Extracts DEBUG() information from a status code structure.
216 Converts the status code specified by Data to the DEBUG() arguments specified
217 by ErrorLevel, Marker, and Format. If type GUID in Data is
218 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
219 Format from the optional data area of the status code buffer specified by Data.
220 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
221 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
222 the Format. If the DEBUG() information could be extracted from Data, then
223 return TRUE. Otherwise, FALSE is returned.
225 If Data is NULL, then ASSERT().
226 If ErrorLevel is NULL, then ASSERT().
227 If Marker is NULL, then ASSERT().
228 If Format is NULL, then ASSERT().
230 @param Data Pointer to status code data buffer.
231 @param ErrorLevel Pointer to error level mask for a debug message.
232 @param Marker Pointer to the variable argument list associated with Format.
233 @param Format Pointer to a Null-terminated ASCII format string of a
236 @retval TRUE The status code specified by Data was converted DEBUG() arguments
237 specified by ErrorLevel, Marker, and Format.
238 @retval FALSE The status code specified by Data could not be converted to
244 ReportStatusCodeExtractDebugInfo (
245 IN CONST EFI_STATUS_CODE_DATA
*Data
,
246 OUT UINT32
*ErrorLevel
,
251 EFI_DEBUG_INFO
*DebugInfo
;
253 ASSERT (Data
!= NULL
);
254 ASSERT (ErrorLevel
!= NULL
);
255 ASSERT (Marker
!= NULL
);
256 ASSERT (Format
!= NULL
);
259 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
261 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
266 // Retrieve the debug information from the status code record
268 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
270 *ErrorLevel
= DebugInfo
->ErrorLevel
;
273 // The first 12 * UINTN bytes of the string are really an
274 // argument stack to support varargs on the Format string.
276 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
277 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
284 Reports a status code.
286 Reports the status code specified by the parameters Type and Value. Status
287 code also require an instance, caller ID, and extended data. This function
288 passed in a zero instance, NULL extended data, and a caller ID of
289 gEfiCallerIdGuid, which is the GUID for the module.
291 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
292 is called while processing another any other Report Status Code Library function,
293 then ReportStatusCode() must return immediately.
295 @param Type Status code type.
296 @param Value Status code value.
298 @retval EFI_SUCCESS The status code was reported.
299 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
301 @retval EFI_UNSUPPORTED Report status code is not supported
307 IN EFI_STATUS_CODE_TYPE Type
,
308 IN EFI_STATUS_CODE_VALUE Value
311 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
316 Reports a status code with a Device Path Protocol as the extended data.
318 Allocates and fills in the extended data section of a status code with the
319 Device Path Protocol specified by DevicePath. This function is responsible
320 for allocating a buffer large enough for the standard header and the device
321 path. The standard header is filled in with a GUID of
322 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
323 instance and a caller ID of gEfiCallerIdGuid.
325 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
326 ReportStatusCodeWithDevicePath() is called while processing another any other
327 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
328 must return EFI_DEVICE_ERROR immediately.
330 If DevicePath is NULL, then ASSERT().
332 @param Type Status code type.
333 @param Value Status code value.
334 @param DevicePath Pointer to the Device Path Protocol to be reported.
336 @retval EFI_SUCCESS The status code was reported with the extended
337 data specified by DevicePath.
338 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
339 extended data section.
340 @retval EFI_UNSUPPORTED Report status code is not supported
345 ReportStatusCodeWithDevicePath (
346 IN EFI_STATUS_CODE_TYPE Type
,
347 IN EFI_STATUS_CODE_VALUE Value
,
348 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
351 ASSERT (DevicePath
!= NULL
);
352 return ReportStatusCodeWithExtendedData (
356 InternalReportStatusCodeDevicePathSize (DevicePath
)
362 Reports a status code with an extended data buffer.
364 Allocates and fills in the extended data section of a status code with the
365 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
366 is assumed to be one of the data structures specified in Related Definitions.
367 These data structure do not have the standard header, so this function is
368 responsible for allocating a buffer large enough for the standard header and
369 the extended data passed into this function. The standard header is filled
370 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
371 with a zero instance and a caller ID of gEfiCallerIdGuid.
373 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
374 ReportStatusCodeWithExtendedData() is called while processing another any other
375 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
376 must return EFI_DEVICE_ERROR immediately.
378 If ExtendedData is NULL, then ASSERT().
379 If ExtendedDataSize is 0, then ASSERT().
381 @param Type Status code type.
382 @param Value Status code value.
383 @param ExtendedData Pointer to the extended data buffer to be reported.
384 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
387 @retval EFI_SUCCESS The status code was reported with the extended
388 data specified by ExtendedData and ExtendedDataSize.
389 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
390 extended data section.
391 @retval EFI_UNSUPPORTED Report status code is not supported
396 ReportStatusCodeWithExtendedData (
397 IN EFI_STATUS_CODE_TYPE Type
,
398 IN EFI_STATUS_CODE_VALUE Value
,
399 IN CONST VOID
*ExtendedData
,
400 IN UINTN ExtendedDataSize
403 ASSERT (ExtendedData
!= NULL
);
404 ASSERT (ExtendedDataSize
!= 0);
405 return ReportStatusCodeEx (
418 Reports a status code with full parameters.
420 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
421 is 0, then an extended data buffer is not reported. If ExtendedData is not
422 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
423 ExtendedData is assumed not have the standard status code header, so this function
424 is responsible for allocating a buffer large enough for the standard header and
425 the extended data passed into this function. The standard header is filled in
426 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
427 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
428 an instance specified by Instance and a caller ID specified by CallerId. If
429 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
431 ReportStatusCodeEx()must actively prevent recursion. If
432 ReportStatusCodeEx() is called while processing another any
433 other Report Status Code Library function, then
434 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
436 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
437 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
439 @param Type Status code type.
440 @param Value Status code value.
441 @param Instance Status code instance number.
442 @param CallerId Pointer to a GUID that identifies the caller of this
443 function. If this parameter is NULL, then a caller
444 ID of gEfiCallerIdGuid is used.
445 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
446 If this parameter is NULL, then a the status code
447 standard header is filled in with
448 gEfiStatusCodeSpecificDataGuid.
449 @param ExtendedData Pointer to the extended data buffer. This is an
450 optional parameter that may be NULL.
451 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
453 @retval EFI_SUCCESS The status code was reported.
454 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
455 the extended data section if it was specified.
456 @retval EFI_UNSUPPORTED Report status code is not supported
462 IN EFI_STATUS_CODE_TYPE Type
,
463 IN EFI_STATUS_CODE_VALUE Value
,
465 IN CONST EFI_GUID
*CallerId OPTIONAL
,
466 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
467 IN CONST VOID
*ExtendedData OPTIONAL
,
468 IN UINTN ExtendedDataSize
473 Status
= InternalReportStatusCodeEx (
488 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
490 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
491 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
493 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
494 PcdReportStatusCodeProperyMask is set.
495 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
496 PcdReportStatusCodeProperyMask is clear.
501 ReportProgressCodeEnabled (
505 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
510 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
512 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
513 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
515 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
516 PcdReportStatusCodeProperyMask is set.
517 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
518 PcdReportStatusCodeProperyMask is clear.
523 ReportErrorCodeEnabled (
527 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
532 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
534 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
535 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
537 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
538 PcdReportStatusCodeProperyMask is set.
539 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
540 PcdReportStatusCodeProperyMask is clear.
545 ReportDebugCodeEnabled (
549 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);