2 Instance of Report Status Code Library for PEI Phase.
4 Copyright (c) 2006 - 2009, 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 PEI Status Code Service or
37 OEM Hook Status Code Library.
39 This function first tries to report status code via PEI Status Code Service. If the service
40 is not available, it then tries calling OEM Hook Status Code Library.
42 @param Type Status code type.
43 @param Value Status code value.
44 @param Instance Status code instance number.
45 @param CallerId Pointer to a GUID that identifies the caller of this
46 function. This is an optional parameter that may be
48 @param Data Pointer to the extended data buffer. This is an
49 optional parameter that may be NULL.
51 @retval EFI_SUCCESS The status code was reported.
52 @retval EFI_UNSUPPORTED Status code type is not supported.
53 @retval Others Failed to report status code.
57 InternalReportStatusCode (
58 IN EFI_STATUS_CODE_TYPE Type
,
59 IN EFI_STATUS_CODE_VALUE Value
,
61 IN CONST EFI_GUID
*CallerId OPTIONAL
,
62 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
65 CONST EFI_PEI_SERVICES
**PeiServices
;
68 if ((ReportProgressCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
69 (ReportErrorCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ||
70 (ReportDebugCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
)) {
71 PeiServices
= GetPeiServicesTablePointer ();
72 Status
= (*PeiServices
)->ReportStatusCode (
80 if (Status
== EFI_NOT_AVAILABLE_YET
) {
81 Status
= OemHookStatusCodeInitialize ();
82 if (!EFI_ERROR (Status
)) {
83 return OemHookStatusCodeReport (Type
, Value
, Instance
, (EFI_GUID
*) CallerId
, Data
);
89 return EFI_UNSUPPORTED
;
94 Converts a status code to an 8-bit POST code value.
96 Converts the status code specified by CodeType and Value to an 8-bit POST code
97 and returns the 8-bit POST code in PostCode. If CodeType is an
98 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
99 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
100 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
102 If PostCode is NULL, then ASSERT().
104 @param CodeType The type of status code being converted.
105 @param Value The status code value being converted.
106 @param PostCode A pointer to the 8-bit POST code value to return.
108 @retval TRUE The status code specified by CodeType and Value was converted
109 to an 8-bit POST code and returned in PostCode.
110 @retval FALSE The status code specified by CodeType and Value could not be
111 converted to an 8-bit POST code value.
117 IN EFI_STATUS_CODE_TYPE CodeType
,
118 IN EFI_STATUS_CODE_VALUE Value
,
123 // If PostCode is NULL, then ASSERT()
125 ASSERT (PostCode
!= NULL
);
128 // Convert Value to an 8 bit post code
130 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
131 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
)) {
132 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
133 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
141 Extracts ASSERT() information from a status code structure.
143 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
144 arguments specified by Filename, Description, and LineNumber. If CodeType is
145 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
146 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
147 Filename, Description, and LineNumber from the optional data area of the
148 status code buffer specified by Data. The optional data area of Data contains
149 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
150 ASCII string for the Description, followed by a 32-bit LineNumber. If the
151 ASSERT() information could be extracted from Data, then return TRUE.
152 Otherwise, FALSE is returned.
154 If Data is NULL, then ASSERT().
155 If Filename is NULL, then ASSERT().
156 If Description is NULL, then ASSERT().
157 If LineNumber is NULL, then ASSERT().
159 @param CodeType The type of status code being converted.
160 @param Value The status code value being converted.
161 @param Data Pointer to status code data buffer.
162 @param Filename Pointer to the source file name that generated the ASSERT().
163 @param Description Pointer to the description of the ASSERT().
164 @param LineNumber Pointer to source line number that generated the ASSERT().
166 @retval TRUE The status code specified by CodeType, Value, and Data was
167 converted ASSERT() arguments specified by Filename, Description,
169 @retval FALSE The status code specified by CodeType, Value, and Data could
170 not be converted to ASSERT() arguments.
175 ReportStatusCodeExtractAssertInfo (
176 IN EFI_STATUS_CODE_TYPE CodeType
,
177 IN EFI_STATUS_CODE_VALUE Value
,
178 IN CONST EFI_STATUS_CODE_DATA
*Data
,
179 OUT CHAR8
**Filename
,
180 OUT CHAR8
**Description
,
181 OUT UINT32
*LineNumber
184 EFI_DEBUG_ASSERT_DATA
*AssertData
;
186 ASSERT (Data
!= NULL
);
187 ASSERT (Filename
!= NULL
);
188 ASSERT (Description
!= NULL
);
189 ASSERT (LineNumber
!= NULL
);
191 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
192 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
193 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
194 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
195 *Filename
= (CHAR8
*)(AssertData
+ 1);
196 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
197 *LineNumber
= AssertData
->LineNumber
;
205 Extracts DEBUG() information from a status code structure.
207 Converts the status code specified by Data to the DEBUG() arguments specified
208 by ErrorLevel, Marker, and Format. If type GUID in Data is
209 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
210 Format from the optional data area of the status code buffer specified by Data.
211 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
212 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
213 the Format. If the DEBUG() information could be extracted from Data, then
214 return TRUE. Otherwise, FALSE is returned.
216 If Data is NULL, then ASSERT().
217 If ErrorLevel is NULL, then ASSERT().
218 If Marker is NULL, then ASSERT().
219 If Format is NULL, then ASSERT().
221 @param Data Pointer to status code data buffer.
222 @param ErrorLevel Pointer to error level mask for a debug message.
223 @param Marker Pointer to the variable argument list associated with Format.
224 @param Format Pointer to a Null-terminated ASCII format string of a
227 @retval TRUE The status code specified by Data was converted DEBUG() arguments
228 specified by ErrorLevel, Marker, and Format.
229 @retval FALSE The status code specified by Data could not be converted to
235 ReportStatusCodeExtractDebugInfo (
236 IN CONST EFI_STATUS_CODE_DATA
*Data
,
237 OUT UINT32
*ErrorLevel
,
242 EFI_DEBUG_INFO
*DebugInfo
;
244 ASSERT (Data
!= NULL
);
245 ASSERT (ErrorLevel
!= NULL
);
246 ASSERT (Marker
!= NULL
);
247 ASSERT (Format
!= NULL
);
250 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
252 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
257 // Retrieve the debug information from the status code record
259 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
261 *ErrorLevel
= DebugInfo
->ErrorLevel
;
264 // The first 12 * UINTN bytes of the string are really an
265 // argument stack to support varargs on the Format string.
267 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
268 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
275 Reports a status code.
277 Reports the status code specified by the parameters Type and Value. Status
278 code also require an instance, caller ID, and extended data. This function
279 passed in a zero instance, NULL extended data, and a caller ID of
280 gEfiCallerIdGuid, which is the GUID for the module.
282 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
283 is called while processing another any other Report Status Code Library function,
284 then ReportStatusCode() must return immediately.
286 @param Type Status code type.
287 @param Value Status code value.
289 @retval EFI_SUCCESS The status code was reported.
290 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
292 @retval EFI_UNSUPPORTED Report status code is not supported
298 IN EFI_STATUS_CODE_TYPE Type
,
299 IN EFI_STATUS_CODE_VALUE Value
302 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
307 Reports a status code with a Device Path Protocol as the extended data.
309 Allocates and fills in the extended data section of a status code with the
310 Device Path Protocol specified by DevicePath. This function is responsible
311 for allocating a buffer large enough for the standard header and the device
312 path. The standard header is filled in with a GUID of
313 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
314 instance and a caller ID of gEfiCallerIdGuid.
316 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
317 ReportStatusCodeWithDevicePath() is called while processing another any other
318 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
319 must return EFI_DEVICE_ERROR immediately.
321 If DevicePath is NULL, then ASSERT().
323 @param Type Status code type.
324 @param Value Status code value.
325 @param DevicePath Pointer to the Device Path Protocol to be reported.
327 @retval EFI_SUCCESS The status code was reported with the extended
328 data specified by DevicePath.
329 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
330 extended data section.
331 @retval EFI_UNSUPPORTED Report status code is not supported
336 ReportStatusCodeWithDevicePath (
337 IN EFI_STATUS_CODE_TYPE Type
,
338 IN EFI_STATUS_CODE_VALUE Value
,
339 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
342 ASSERT (DevicePath
!= NULL
);
344 // EFI_UNSUPPORTED is returned for device path is not supported in PEI phase.
346 return EFI_UNSUPPORTED
;
351 Reports a status code with an extended data buffer.
353 Allocates and fills in the extended data section of a status code with the
354 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
355 is assumed to be one of the data structures specified in Related Definitions.
356 These data structure do not have the standard header, so this function is
357 responsible for allocating a buffer large enough for the standard header and
358 the extended data passed into this function. The standard header is filled
359 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
360 with a zero instance and a caller ID of gEfiCallerIdGuid.
362 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
363 ReportStatusCodeWithExtendedData() is called while processing another any other
364 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
365 must return EFI_DEVICE_ERROR immediately.
367 If ExtendedData is NULL, then ASSERT().
368 If ExtendedDataSize is 0, then ASSERT().
370 @param Type Status code type.
371 @param Value Status code value.
372 @param ExtendedData Pointer to the extended data buffer to be reported.
373 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
376 @retval EFI_SUCCESS The status code was reported with the extended
377 data specified by ExtendedData and ExtendedDataSize.
378 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
379 extended data section.
380 @retval EFI_UNSUPPORTED Report status code is not supported
385 ReportStatusCodeWithExtendedData (
386 IN EFI_STATUS_CODE_TYPE Type
,
387 IN EFI_STATUS_CODE_VALUE Value
,
388 IN CONST VOID
*ExtendedData
,
389 IN UINTN ExtendedDataSize
392 ASSERT (ExtendedData
!= NULL
);
393 ASSERT (ExtendedDataSize
!= 0);
394 return ReportStatusCodeEx (
407 Reports a status code with full parameters.
409 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
410 is 0, then an extended data buffer is not reported. If ExtendedData is not
411 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
412 ExtendedData is assumed not have the standard status code header, so this function
413 is responsible for allocating a buffer large enough for the standard header and
414 the extended data passed into this function. The standard header is filled in
415 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
416 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
417 an instance specified by Instance and a caller ID specified by CallerId. If
418 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
420 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
421 is called while processing another any other Report Status Code Library function,
422 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
424 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
425 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
427 @param Type Status code type.
428 @param Value Status code value.
429 @param Instance Status code instance number.
430 @param CallerId Pointer to a GUID that identifies the caller of this
431 function. If this parameter is NULL, then a caller
432 ID of gEfiCallerIdGuid is used.
433 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
434 If this parameter is NULL, then a the status code
435 standard header is filled in with
436 gEfiStatusCodeSpecificDataGuid.
437 @param ExtendedData Pointer to the extended data buffer. This is an
438 optional parameter that may be NULL.
439 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
441 @retval EFI_SUCCESS The status code was reported.
442 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
443 the extended data section if it was specified.
444 @retval EFI_UNSUPPORTED Report status code is not supported
450 IN EFI_STATUS_CODE_TYPE Type
,
451 IN EFI_STATUS_CODE_VALUE Value
,
453 IN CONST EFI_GUID
*CallerId OPTIONAL
,
454 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
455 IN CONST VOID
*ExtendedData OPTIONAL
,
456 IN UINTN ExtendedDataSize
459 EFI_STATUS_CODE_DATA
*StatusCodeData
;
460 UINT64 Buffer
[MAX_EXTENDED_DATA_SIZE
/ sizeof (UINT64
)];
463 // If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
465 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
467 // If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
469 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
471 if (ExtendedDataSize
> (MAX_EXTENDED_DATA_SIZE
- sizeof (EFI_STATUS_CODE_DATA
))) {
472 return EFI_OUT_OF_RESOURCES
;
474 StatusCodeData
= (EFI_STATUS_CODE_DATA
*)Buffer
;
475 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
476 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
477 if (ExtendedDataGuid
== NULL
) {
478 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
480 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
481 if (ExtendedData
!= NULL
) {
482 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
484 if (CallerId
== NULL
) {
485 CallerId
= &gEfiCallerIdGuid
;
487 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
492 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
494 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
495 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
497 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
498 PcdReportStatusCodeProperyMask is set.
499 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
500 PcdReportStatusCodeProperyMask is clear.
505 ReportProgressCodeEnabled (
509 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
514 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
516 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
517 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
519 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
520 PcdReportStatusCodeProperyMask is set.
521 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
522 PcdReportStatusCodeProperyMask is clear.
527 ReportErrorCodeEnabled (
531 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
536 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
538 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
539 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
541 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
542 PcdReportStatusCodeProperyMask is set.
543 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
544 PcdReportStatusCodeProperyMask is clear.
549 ReportDebugCodeEnabled (
553 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);