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 // Define the maximum extended data size that is supported in the PEI phase
18 #define MAX_EXTENDED_DATA_SIZE 0x200
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
52 EFI_PEI_SERVICES
**PeiServices
;
54 PeiServices
= GetPeiServicesTablePointer ();
55 return (*PeiServices
)->PeiReportStatusCode (PeiServices
, Type
, Value
, Instance
, CallerId
, Data
);
60 Computes and returns the size, in bytes, of a device path.
62 @param DevicePath A pointer to a device path.
64 @return The size, in bytes, of DevicePath.
68 InternalReportStatusCodeDevicePathSize (
69 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
72 EFI_DEVICE_PATH_PROTOCOL
*Start
;
74 if (DevicePath
== NULL
) {
79 // Search for the end of the device path structure
82 while (!EfiIsDevicePathEnd (DevicePath
)) {
83 DevicePath
= EfiNextDevicePathNode (DevicePath
);
87 // Subtract the start node from the end node and add in the size of the end node
89 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
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 *PostCode
|= (UINT8
) (((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 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 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 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
342 ASSERT (DevicePath
!= NULL
);
343 return ReportStatusCodeWithExtendedData (
347 InternalReportStatusCodeDevicePathSize (DevicePath
)
353 Reports a status code with an extended data buffer.
355 Allocates and fills in the extended data section of a status code with the
356 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
357 is assumed to be one of the data structures specified in Related Definitions.
358 These data structure do not have the standard header, so this function is
359 responsible for allocating a buffer large enough for the standard header and
360 the extended data passed into this function. The standard header is filled
361 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
362 with a zero instance and a caller ID of gEfiCallerIdGuid.
364 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
365 ReportStatusCodeWithExtendedData() is called while processing another any other
366 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
367 must return EFI_DEVICE_ERROR immediately.
369 If ExtendedData is NULL, then ASSERT().
370 If ExtendedDataSize is 0, then ASSERT().
372 @param Type Status code type.
373 @param Value Status code value.
374 @param ExtendedData Pointer to the extended data buffer to be reported.
375 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
378 @retval EFI_SUCCESS The status code was reported with the extended
379 data specified by ExtendedData and ExtendedDataSize.
380 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
381 extended data section.
382 @retval EFI_UNSUPPORTED Report status code is not supported
387 ReportStatusCodeWithExtendedData (
388 IN EFI_STATUS_CODE_TYPE Type
,
389 IN EFI_STATUS_CODE_VALUE Value
,
390 IN VOID
*ExtendedData
,
391 IN UINTN ExtendedDataSize
394 ASSERT (ExtendedData
!= NULL
);
395 ASSERT (ExtendedDataSize
!= 0);
396 return ReportStatusCodeEx (
409 Reports a status code with full parameters.
411 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
412 is 0, then an extended data buffer is not reported. If ExtendedData is not
413 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
414 ExtendedData is assumed not have the standard status code header, so this function
415 is responsible for allocating a buffer large enough for the standard header and
416 the extended data passed into this function. The standard header is filled in
417 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
418 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
419 an instance specified by Instance and a caller ID specified by CallerId. If
420 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
422 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
423 is called while processing another any other Report Status Code Library function,
424 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
426 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
427 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
429 @param Type Status code type.
430 @param Value Status code value.
431 @param Instance Status code instance number.
432 @param CallerId Pointer to a GUID that identifies the caller of this
433 function. If this parameter is NULL, then a caller
434 ID of gEfiCallerIdGuid is used.
435 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
436 If this parameter is NULL, then a the status code
437 standard header is filled in with
438 gEfiStatusCodeSpecificDataGuid.
439 @param ExtendedData Pointer to the extended data buffer. This is an
440 optional parameter that may be NULL.
441 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
443 @retval EFI_SUCCESS The status code was reported.
444 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
445 the extended data section if it was specified.
446 @retval EFI_UNSUPPORTED Report status code is not supported
452 IN EFI_STATUS_CODE_TYPE Type
,
453 IN EFI_STATUS_CODE_VALUE Value
,
455 IN EFI_GUID
*CallerId OPTIONAL
,
456 IN EFI_GUID
*ExtendedDataGuid OPTIONAL
,
457 IN VOID
*ExtendedData OPTIONAL
,
458 IN UINTN ExtendedDataSize
461 EFI_STATUS_CODE_DATA
*StatusCodeData
;
462 UINT64 Buffer
[MAX_EXTENDED_DATA_SIZE
/ sizeof (UINT64
)];
464 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
465 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
467 if (ExtendedDataSize
> (MAX_EXTENDED_DATA_SIZE
- sizeof (EFI_STATUS_CODE_DATA
))) {
468 return EFI_OUT_OF_RESOURCES
;
470 StatusCodeData
= (EFI_STATUS_CODE_DATA
*)Buffer
;
471 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
472 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
473 if (ExtendedDataGuid
== NULL
) {
474 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
476 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
477 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
478 if (CallerId
== NULL
) {
479 CallerId
= &gEfiCallerIdGuid
;
481 return InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
486 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
488 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
489 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
491 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
492 PcdReportStatusCodeProperyMask is set.
493 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
494 PcdReportStatusCodeProperyMask is clear.
499 ReportProgressCodeEnabled (
503 return ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
508 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
510 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
511 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
513 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
514 PcdReportStatusCodeProperyMask is set.
515 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
516 PcdReportStatusCodeProperyMask is clear.
521 ReportErrorCodeEnabled (
525 return ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
530 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
532 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
533 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
535 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
536 PcdReportStatusCodeProperyMask is set.
537 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
538 PcdReportStatusCodeProperyMask is clear.
543 ReportDebugCodeEnabled (
547 return ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);