2 Report Status Code Library for PEI Phase.
4 Copyright (c) 2006 - 2008, 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 #include <FrameworkPei.h>
18 #include <Guid/StatusCodeDataTypeId.h>
20 #include <Library/ReportStatusCodeLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/PeiServicesTablePointerLib.h>
25 #include <Library/OemHookStatusCodeLib.h>
26 #include <Library/PcdLib.h>
28 #include <DebugInfo.h>
31 // Define the maximum extended data size that is supported in the PEI phase
33 #define MAX_EXTENDED_DATA_SIZE 0x200
36 Internal worker function that reports a status code through the Status Code Protocol
38 This function checks to see if a Status Code Protocol is present in the handle
39 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
40 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
41 and the ReportStatusCode() service of the Status Code Protocol is called passing in
42 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
44 @param Type Status code type.
45 @param Value Status code value.
46 @param Instance Status code instance number.
47 @param CallerId Pointer to a GUID that identifies the caller of this
48 function. This is an optional parameter that may be
50 @param Data Pointer to the extended data buffer. This is an
51 optional parameter that may be NULL.
53 @retval EFI_SUCCESS The status code was reported.
54 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
55 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
59 InternalReportStatusCode (
60 IN EFI_STATUS_CODE_TYPE Type
,
61 IN EFI_STATUS_CODE_VALUE Value
,
63 IN CONST EFI_GUID
*CallerId OPTIONAL
,
64 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
67 CONST EFI_PEI_SERVICES
**PeiServices
;
70 PeiServices
= GetPeiServicesTablePointer ();
71 Status
= (*PeiServices
)->ReportStatusCode (
79 if (Status
== EFI_NOT_AVAILABLE_YET
) {
80 Status
= OemHookStatusCodeInitialize ();
81 if (!EFI_ERROR (Status
)) {
82 return OemHookStatusCodeReport (Type
, Value
, Instance
, (EFI_GUID
*) CallerId
, Data
);
90 Converts a status code to an 8-bit POST code value.
92 Converts the status code specified by CodeType and Value to an 8-bit POST code
93 and returns the 8-bit POST code in PostCode. If CodeType is an
94 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
95 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
96 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
98 If PostCode is NULL, then ASSERT().
100 @param CodeType The type of status code being converted.
101 @param Value The status code value being converted.
102 @param PostCode A pointer to the 8-bit POST code value to return.
104 @retval TRUE The status code specified by CodeType and Value was converted
105 to an 8-bit POST code and returned in PostCode.
106 @retval FALSE The status code specified by CodeType and Value could not be
107 converted to an 8-bit POST code value.
113 IN EFI_STATUS_CODE_TYPE CodeType
,
114 IN EFI_STATUS_CODE_VALUE Value
,
119 // If PostCode is NULL, then ASSERT()
121 ASSERT (PostCode
!= NULL
);
124 // Convert Value to an 8 bit post code
126 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
127 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
128 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
129 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
137 Extracts ASSERT() information from a status code structure.
139 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
140 arguments specified by Filename, Description, and LineNumber. If CodeType is
141 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
142 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
143 Filename, Description, and LineNumber from the optional data area of the
144 status code buffer specified by Data. The optional data area of Data contains
145 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
146 ASCII string for the Description, followed by a 32-bit LineNumber. If the
147 ASSERT() information could be extracted from Data, then return TRUE.
148 Otherwise, FALSE is returned.
150 If Data is NULL, then ASSERT().
151 If Filename is NULL, then ASSERT().
152 If Description is NULL, then ASSERT().
153 If LineNumber is NULL, then ASSERT().
155 @param CodeType The type of status code being converted.
156 @param Value The status code value being converted.
157 @param Data Pointer to status code data buffer.
158 @param Filename Pointer to the source file name that generated the ASSERT().
159 @param Description Pointer to the description of the ASSERT().
160 @param LineNumber Pointer to source line number that generated the ASSERT().
162 @retval TRUE The status code specified by CodeType, Value, and Data was
163 converted ASSERT() arguments specified by Filename, Description,
165 @retval FALSE The status code specified by CodeType, Value, and Data could
166 not be converted to ASSERT() arguments.
171 ReportStatusCodeExtractAssertInfo (
172 IN EFI_STATUS_CODE_TYPE CodeType
,
173 IN EFI_STATUS_CODE_VALUE Value
,
174 IN CONST EFI_STATUS_CODE_DATA
*Data
,
175 OUT CHAR8
**Filename
,
176 OUT CHAR8
**Description
,
177 OUT UINT32
*LineNumber
180 EFI_DEBUG_ASSERT_DATA
*AssertData
;
182 ASSERT (Data
!= NULL
);
183 ASSERT (Filename
!= NULL
);
184 ASSERT (Description
!= NULL
);
185 ASSERT (LineNumber
!= NULL
);
187 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
188 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
189 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
190 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
191 *Filename
= (CHAR8
*)(AssertData
+ 1);
192 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
193 *LineNumber
= AssertData
->LineNumber
;
201 Extracts DEBUG() information from a status code structure.
203 Converts the status code specified by Data to the DEBUG() arguments specified
204 by ErrorLevel, Marker, and Format. If type GUID in Data is
205 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
206 Format from the optional data area of the status code buffer specified by Data.
207 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
208 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
209 the Format. If the DEBUG() information could be extracted from Data, then
210 return TRUE. Otherwise, FALSE is returned.
212 If Data is NULL, then ASSERT().
213 If ErrorLevel is NULL, then ASSERT().
214 If Marker is NULL, then ASSERT().
215 If Format is NULL, then ASSERT().
217 @param Data Pointer to status code data buffer.
218 @param ErrorLevel Pointer to error level mask for a debug message.
219 @param Marker Pointer to the variable argument list associated with Format.
220 @param Format Pointer to a Null-terminated ASCII format string of a
223 @retval TRUE The status code specified by Data was converted DEBUG() arguments
224 specified by ErrorLevel, Marker, and Format.
225 @retval FALSE The status code specified by Data could not be converted to
231 ReportStatusCodeExtractDebugInfo (
232 IN CONST EFI_STATUS_CODE_DATA
*Data
,
233 OUT UINT32
*ErrorLevel
,
238 EFI_DEBUG_INFO
*DebugInfo
;
240 ASSERT (Data
!= NULL
);
241 ASSERT (ErrorLevel
!= NULL
);
242 ASSERT (Marker
!= NULL
);
243 ASSERT (Format
!= NULL
);
246 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
248 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
253 // Retrieve the debug information from the status code record
255 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
257 *ErrorLevel
= DebugInfo
->ErrorLevel
;
260 // The first 12 * UINTN bytes of the string are really an
261 // argument stack to support varargs on the Format string.
263 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
264 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
271 Reports a status code.
273 Reports the status code specified by the parameters Type and Value. Status
274 code also require an instance, caller ID, and extended data. This function
275 passed in a zero instance, NULL extended data, and a caller ID of
276 gEfiCallerIdGuid, which is the GUID for the module.
278 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
279 is called while processing another any other Report Status Code Library function,
280 then ReportStatusCode() must return immediately.
282 @param Type Status code type.
283 @param Value Status code value.
285 @retval EFI_SUCCESS The status code was reported.
286 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
288 @retval EFI_UNSUPPORTED Report status code is not supported
294 IN EFI_STATUS_CODE_TYPE Type
,
295 IN EFI_STATUS_CODE_VALUE Value
298 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
303 Reports a status code with a Device Path Protocol as the extended data.
305 Allocates and fills in the extended data section of a status code with the
306 Device Path Protocol specified by DevicePath. This function is responsible
307 for allocating a buffer large enough for the standard header and the device
308 path. The standard header is filled in with a GUID of
309 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
310 instance and a caller ID of gEfiCallerIdGuid.
312 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
313 ReportStatusCodeWithDevicePath() is called while processing another any other
314 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
315 must return EFI_DEVICE_ERROR immediately.
317 If DevicePath is NULL, then ASSERT().
319 @param Type Status code type.
320 @param Value Status code value.
321 @param DevicePath Pointer to the Device Path Protocol to be reported.
323 @retval EFI_SUCCESS The status code was reported with the extended
324 data specified by DevicePath.
325 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
326 extended data section.
327 @retval EFI_UNSUPPORTED Report status code is not supported
332 ReportStatusCodeWithDevicePath (
333 IN EFI_STATUS_CODE_TYPE Type
,
334 IN EFI_STATUS_CODE_VALUE Value
,
335 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
338 ASSERT (DevicePath
!= NULL
);
339 return EFI_UNSUPPORTED
;
344 Reports a status code with an extended data buffer.
346 Allocates and fills in the extended data section of a status code with the
347 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
348 is assumed to be one of the data structures specified in Related Definitions.
349 These data structure do not have the standard header, so this function is
350 responsible for allocating a buffer large enough for the standard header and
351 the extended data passed into this function. The standard header is filled
352 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
353 with a zero instance and a caller ID of gEfiCallerIdGuid.
355 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
356 ReportStatusCodeWithExtendedData() is called while processing another any other
357 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
358 must return EFI_DEVICE_ERROR immediately.
360 If ExtendedData is NULL, then ASSERT().
361 If ExtendedDataSize is 0, then ASSERT().
363 @param Type Status code type.
364 @param Value Status code value.
365 @param ExtendedData Pointer to the extended data buffer to be reported.
366 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
369 @retval EFI_SUCCESS The status code was reported with the extended
370 data specified by ExtendedData and ExtendedDataSize.
371 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
372 extended data section.
373 @retval EFI_UNSUPPORTED Report status code is not supported
378 ReportStatusCodeWithExtendedData (
379 IN EFI_STATUS_CODE_TYPE Type
,
380 IN EFI_STATUS_CODE_VALUE Value
,
381 IN CONST VOID
*ExtendedData
,
382 IN UINTN ExtendedDataSize
385 ASSERT (ExtendedData
!= NULL
);
386 ASSERT (ExtendedDataSize
!= 0);
387 return ReportStatusCodeEx (
400 Reports a status code with full parameters.
402 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
403 is 0, then an extended data buffer is not reported. If ExtendedData is not
404 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
405 ExtendedData is assumed not have the standard status code header, so this function
406 is responsible for allocating a buffer large enough for the standard header and
407 the extended data passed into this function. The standard header is filled in
408 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
409 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
410 an instance specified by Instance and a caller ID specified by CallerId. If
411 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
413 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
414 is called while processing another any other Report Status Code Library function,
415 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
417 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
418 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
420 @param Type Status code type.
421 @param Value Status code value.
422 @param Instance Status code instance number.
423 @param CallerId Pointer to a GUID that identifies the caller of this
424 function. If this parameter is NULL, then a caller
425 ID of gEfiCallerIdGuid is used.
426 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
427 If this parameter is NULL, then a the status code
428 standard header is filled in with
429 gEfiStatusCodeSpecificDataGuid.
430 @param ExtendedData Pointer to the extended data buffer. This is an
431 optional parameter that may be NULL.
432 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
434 @retval EFI_SUCCESS The status code was reported.
435 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
436 the extended data section if it was specified.
437 @retval EFI_UNSUPPORTED Report status code is not supported
443 IN EFI_STATUS_CODE_TYPE Type
,
444 IN EFI_STATUS_CODE_VALUE Value
,
446 IN CONST EFI_GUID
*CallerId OPTIONAL
,
447 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
448 IN CONST VOID
*ExtendedData OPTIONAL
,
449 IN UINTN ExtendedDataSize
452 EFI_STATUS_CODE_DATA
*StatusCodeData
;
453 UINT64 Buffer
[MAX_EXTENDED_DATA_SIZE
/ sizeof (UINT64
)];
455 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
456 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
458 if (ExtendedDataSize
> (MAX_EXTENDED_DATA_SIZE
- sizeof (EFI_STATUS_CODE_DATA
))) {
459 return EFI_OUT_OF_RESOURCES
;
461 StatusCodeData
= (EFI_STATUS_CODE_DATA
*)Buffer
;
462 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
463 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
464 if (ExtendedDataGuid
== NULL
) {
465 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
467 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
468 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
469 if (CallerId
== NULL
) {
470 CallerId
= &gEfiCallerIdGuid
;
472 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
477 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
479 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
480 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
482 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
483 PcdReportStatusCodeProperyMask is set.
484 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
485 PcdReportStatusCodeProperyMask is clear.
490 ReportProgressCodeEnabled (
494 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
499 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
501 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
502 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
504 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
505 PcdReportStatusCodeProperyMask is set.
506 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
507 PcdReportStatusCodeProperyMask is clear.
512 ReportErrorCodeEnabled (
516 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
521 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
523 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
524 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
526 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
527 PcdReportStatusCodeProperyMask is set.
528 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
529 PcdReportStatusCodeProperyMask is clear.
534 ReportDebugCodeEnabled (
538 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);