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 Lib
23 #include "EdkIIGluePeim.h"
26 // Define the maximum extended data size that is supported in the PEI phase
28 #define MAX_EXTENDED_DATA_SIZE 0x200
31 Internal worker function that reports a status code through the Status Code Protocol
33 This function checks to see if a Status Code Protocol is present in the handle
34 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
35 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
36 and the ReportStatusCode() service of the Status Code Protocol is called passing in
37 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
39 @param Type Status code type.
40 @param Value Status code value.
41 @param Instance Status code instance number.
42 @param CallerId Pointer to a GUID that identifies the caller of this
43 function. This is an optional parameter that may be
45 @param Data Pointer to the extended data buffer. This is an
46 optional parameter that may be NULL.
48 @retval EFI_SUCCESS The status code was reported.
49 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
50 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
55 InternalReportStatusCode (
56 IN EFI_STATUS_CODE_TYPE Type
,
57 IN EFI_STATUS_CODE_VALUE Value
,
59 IN CONST EFI_GUID
*CallerId OPTIONAL
,
60 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
63 EFI_PEI_SERVICES
**PeiServices
;
65 PeiServices
= GetPeiServicesTablePointer ();
66 return (*PeiServices
)->PeiReportStatusCode (
78 Converts a status code to an 8-bit POST code value.
80 Converts the status code specified by CodeType and Value to an 8-bit POST code
81 and returns the 8-bit POST code in PostCode. If CodeType is an
82 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
83 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
84 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
86 If PostCode is NULL, then ASSERT().
88 @param CodeType The type of status code being converted.
89 @param Value The status code value being converted.
90 @param PostCode A pointer to the 8-bit POST code value to return.
92 @retval TRUE The status code specified by CodeType and Value was converted
93 to an 8-bit POST code and returned in PostCode.
94 @retval FALSE The status code specified by CodeType and Value could not be
95 converted to an 8-bit POST code value.
100 GlueCodeTypeToPostCode (
101 IN EFI_STATUS_CODE_TYPE CodeType
,
102 IN EFI_STATUS_CODE_VALUE Value
,
107 // If PostCode is NULL, then ASSERT()
109 ASSERT (PostCode
!= NULL
);
112 // Convert Value to an 8 bit post code
114 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
115 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
116 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
117 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
125 Extracts ASSERT() information from a status code structure.
127 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
128 arguments specified by Filename, Description, and LineNumber. If CodeType is
129 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
130 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
131 Filename, Description, and LineNumber from the optional data area of the
132 status code buffer specified by Data. The optional data area of Data contains
133 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
134 ASCII string for the Description, followed by a 32-bit LineNumber. If the
135 ASSERT() information could be extracted from Data, then return TRUE.
136 Otherwise, FALSE is returned.
138 If Data is NULL, then ASSERT().
139 If Filename is NULL, then ASSERT().
140 If Description is NULL, then ASSERT().
141 If LineNumber is NULL, then ASSERT().
143 @param CodeType The type of status code being converted.
144 @param Value The status code value being converted.
145 @param Data Pointer to status code data buffer.
146 @param Filename Pointer to the source file name that generated the ASSERT().
147 @param Description Pointer to the description of the ASSERT().
148 @param LineNumber Pointer to source line number that generated the ASSERT().
150 @retval TRUE The status code specified by CodeType, Value, and Data was
151 converted ASSERT() arguments specified by Filename, Description,
153 @retval FALSE The status code specified by CodeType, Value, and Data could
154 not be converted to ASSERT() arguments.
159 GlueReportStatusCodeExtractAssertInfo (
160 IN EFI_STATUS_CODE_TYPE CodeType
,
161 IN EFI_STATUS_CODE_VALUE Value
,
162 IN CONST EFI_STATUS_CODE_DATA
*Data
,
163 OUT CHAR8
**Filename
,
164 OUT CHAR8
**Description
,
165 OUT UINT32
*LineNumber
168 EFI_DEBUG_ASSERT_DATA
*AssertData
;
170 ASSERT (Data
!= NULL
);
171 ASSERT (Filename
!= NULL
);
172 ASSERT (Description
!= NULL
);
173 ASSERT (LineNumber
!= NULL
);
175 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
176 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
177 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
178 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
179 *Filename
= (CHAR8
*)(AssertData
+ 1);
180 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
181 *LineNumber
= AssertData
->LineNumber
;
189 Extracts DEBUG() information from a status code structure.
191 Converts the status code specified by Data to the DEBUG() arguments specified
192 by ErrorLevel, Marker, and Format. If type GUID in Data is
193 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
194 Format from the optional data area of the status code buffer specified by Data.
195 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
196 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
197 the Format. If the DEBUG() information could be extracted from Data, then
198 return TRUE. Otherwise, FALSE is returned.
200 If Data is NULL, then ASSERT().
201 If ErrorLevel is NULL, then ASSERT().
202 If Marker is NULL, then ASSERT().
203 If Format is NULL, then ASSERT().
205 @param Data Pointer to status code data buffer.
206 @param ErrorLevel Pointer to error level mask for a debug message.
207 @param Marker Pointer to the variable argument list associated with Format.
208 @param Format Pointer to a Null-terminated ASCII format string of a
211 @retval TRUE The status code specified by Data was converted DEBUG() arguments
212 specified by ErrorLevel, Marker, and Format.
213 @retval FALSE The status code specified by Data could not be converted to
219 GlueReportStatusCodeExtractDebugInfo (
220 IN CONST EFI_STATUS_CODE_DATA
*Data
,
221 OUT UINT32
*ErrorLevel
,
226 EFI_DEBUG_INFO
*DebugInfo
;
228 ASSERT (Data
!= NULL
);
229 ASSERT (ErrorLevel
!= NULL
);
230 ASSERT (Marker
!= NULL
);
231 ASSERT (Format
!= NULL
);
234 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
236 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
241 // Retrieve the debug information from the status code record
243 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
245 *ErrorLevel
= DebugInfo
->ErrorLevel
;
248 // The first 12 * UINTN bytes of the string are really an
249 // argument stack to support varargs on the Format string.
251 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
252 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
259 Reports a status code.
261 Reports the status code specified by the parameters Type and Value. Status
262 code also require an instance, caller ID, and extended data. This function
263 passed in a zero instance, NULL extended data, and a caller ID of
264 gEfiCallerIdGuid, which is the GUID for the module.
266 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
267 is called while processing another any other Report Status Code Library function,
268 then ReportStatusCode() must return immediately.
270 @param Type Status code type.
271 @param Value Status code value.
273 @retval EFI_SUCCESS The status code was reported.
274 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
276 @retval EFI_UNSUPPORTED Report status code is not supported
281 GlueReportStatusCode (
282 IN EFI_STATUS_CODE_TYPE Type
,
283 IN EFI_STATUS_CODE_VALUE Value
286 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
291 Reports a status code with a Device Path Protocol as the extended data.
293 Allocates and fills in the extended data section of a status code with the
294 Device Path Protocol specified by DevicePath. This function is responsible
295 for allocating a buffer large enough for the standard header and the device
296 path. The standard header is filled in with a GUID of
297 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
298 instance and a caller ID of gEfiCallerIdGuid.
300 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
301 ReportStatusCodeWithDevicePath() is called while processing another any other
302 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
303 must return EFI_DEVICE_ERROR immediately.
305 If DevicePath is NULL, then ASSERT().
307 @param Type Status code type.
308 @param Value Status code value.
309 @param DevicePath Pointer to the Device Path Protocol to be reported.
311 @retval EFI_SUCCESS The status code was reported with the extended
312 data specified by DevicePath.
313 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
314 extended data section.
315 @retval EFI_UNSUPPORTED Report status code is not supported
320 GlueReportStatusCodeWithDevicePath (
321 IN EFI_STATUS_CODE_TYPE Type
,
322 IN EFI_STATUS_CODE_VALUE Value
,
323 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
326 ASSERT (DevicePath
!= NULL
);
327 return EFI_UNSUPPORTED
;
332 Reports a status code with an extended data buffer.
334 Allocates and fills in the extended data section of a status code with the
335 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
336 is assumed to be one of the data structures specified in Related Definitions.
337 These data structure do not have the standard header, so this function is
338 responsible for allocating a buffer large enough for the standard header and
339 the extended data passed into this function. The standard header is filled
340 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
341 with a zero instance and a caller ID of gEfiCallerIdGuid.
343 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
344 ReportStatusCodeWithExtendedData() is called while processing another any other
345 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
346 must return EFI_DEVICE_ERROR immediately.
348 If ExtendedData is NULL, then ASSERT().
349 If ExtendedDataSize is 0, then ASSERT().
351 @param Type Status code type.
352 @param Value Status code value.
353 @param ExtendedData Pointer to the extended data buffer to be reported.
354 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
357 @retval EFI_SUCCESS The status code was reported with the extended
358 data specified by ExtendedData and ExtendedDataSize.
359 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
360 extended data section.
361 @retval EFI_UNSUPPORTED Report status code is not supported
366 GlueReportStatusCodeWithExtendedData (
367 IN EFI_STATUS_CODE_TYPE Type
,
368 IN EFI_STATUS_CODE_VALUE Value
,
369 IN CONST VOID
*ExtendedData
,
370 IN UINTN ExtendedDataSize
373 ASSERT (ExtendedData
!= NULL
);
374 ASSERT (ExtendedDataSize
!= 0);
375 return ReportStatusCodeEx (
388 Reports a status code with full parameters.
390 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
391 is 0, then an extended data buffer is not reported. If ExtendedData is not
392 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
393 ExtendedData is assumed not have the standard status code header, so this function
394 is responsible for allocating a buffer large enough for the standard header and
395 the extended data passed into this function. The standard header is filled in
396 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
397 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
398 an instance specified by Instance and a caller ID specified by CallerId. If
399 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
401 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
402 is called while processing another any other Report Status Code Library function,
403 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
405 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
406 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
408 @param Type Status code type.
409 @param Value Status code value.
410 @param Instance Status code instance number.
411 @param CallerId Pointer to a GUID that identifies the caller of this
412 function. If this parameter is NULL, then a caller
413 ID of gEfiCallerIdGuid is used.
414 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
415 If this parameter is NULL, then a the status code
416 standard header is filled in with
417 gEfiStatusCodeSpecificDataGuid.
418 @param ExtendedData Pointer to the extended data buffer. This is an
419 optional parameter that may be NULL.
420 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
422 @retval EFI_SUCCESS The status code was reported.
423 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
424 the extended data section if it was specified.
425 @retval EFI_UNSUPPORTED Report status code is not supported
430 GlueReportStatusCodeEx (
431 IN EFI_STATUS_CODE_TYPE Type
,
432 IN EFI_STATUS_CODE_VALUE Value
,
434 IN CONST EFI_GUID
*CallerId OPTIONAL
,
435 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
436 IN CONST VOID
*ExtendedData OPTIONAL
,
437 IN UINTN ExtendedDataSize
440 EFI_STATUS_CODE_DATA
*StatusCodeData
;
441 UINT64 Buffer
[MAX_EXTENDED_DATA_SIZE
/ sizeof (UINT64
)];
443 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
444 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
446 if (ExtendedDataSize
> (MAX_EXTENDED_DATA_SIZE
- sizeof (EFI_STATUS_CODE_DATA
))) {
447 return EFI_OUT_OF_RESOURCES
;
449 StatusCodeData
= (EFI_STATUS_CODE_DATA
*)Buffer
;
450 StatusCodeData
->HeaderSize
= (UINT16
) sizeof (EFI_STATUS_CODE_DATA
);
451 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
452 if (ExtendedDataGuid
== NULL
) {
453 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
455 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
456 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
457 if (CallerId
== NULL
) {
458 CallerId
= &gEfiCallerIdGuid
;
460 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
465 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
467 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
468 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
470 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
471 PcdReportStatusCodeProperyMask is set.
472 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
473 PcdReportStatusCodeProperyMask is clear.
478 GlueReportProgressCodeEnabled (
482 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
487 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
489 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
490 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
492 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
493 PcdReportStatusCodeProperyMask is set.
494 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
495 PcdReportStatusCodeProperyMask is clear.
500 GlueReportErrorCodeEnabled (
504 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
509 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
511 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
512 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
514 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
515 PcdReportStatusCodeProperyMask is set.
516 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
517 PcdReportStatusCodeProperyMask is clear.
522 GlueReportDebugCodeEnabled (
526 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);