2 API implementation for instance of Report Status Code Library.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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"
18 Converts a status code to an 8-bit POST code value.
20 Converts the status code specified by CodeType and Value to an 8-bit POST code
21 and returns the 8-bit POST code in PostCode. If CodeType is an
22 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
23 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
24 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
26 If PostCode is NULL, then ASSERT().
28 @param CodeType The type of status code being converted.
29 @param Value The status code value being converted.
30 @param PostCode A pointer to the 8-bit POST code value to return.
32 @retval TRUE The status code specified by CodeType and Value was converted
33 to an 8-bit POST code and returned in PostCode.
34 @retval FALSE The status code specified by CodeType and Value could not be
35 converted to an 8-bit POST code value.
41 IN EFI_STATUS_CODE_TYPE CodeType
,
42 IN EFI_STATUS_CODE_VALUE Value
,
47 // If PostCode is NULL, then ASSERT()
49 ASSERT (PostCode
!= NULL
);
52 // Convert Value to an 8 bit post code
54 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
55 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
56 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
57 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
65 Extracts ASSERT() information from a status code structure.
67 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
68 arguments specified by Filename, Description, and LineNumber. If CodeType is
69 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
70 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
71 Filename, Description, and LineNumber from the optional data area of the
72 status code buffer specified by Data. The optional data area of Data contains
73 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
74 ASCII string for the Description, followed by a 32-bit LineNumber. If the
75 ASSERT() information could be extracted from Data, then return TRUE.
76 Otherwise, FALSE is returned.
78 If Data is NULL, then ASSERT().
79 If Filename is NULL, then ASSERT().
80 If Description is NULL, then ASSERT().
81 If LineNumber is NULL, then ASSERT().
83 @param CodeType The type of status code being converted.
84 @param Value The status code value being converted.
85 @param Data Pointer to status code data buffer.
86 @param Filename Pointer to the source file name that generated the ASSERT().
87 @param Description Pointer to the description of the ASSERT().
88 @param LineNumber Pointer to source line number that generated the ASSERT().
90 @retval TRUE The status code specified by CodeType, Value, and Data was
91 converted ASSERT() arguments specified by Filename, Description,
93 @retval FALSE The status code specified by CodeType, Value, and Data could
94 not be converted to ASSERT() arguments.
99 ReportStatusCodeExtractAssertInfo (
100 IN EFI_STATUS_CODE_TYPE CodeType
,
101 IN EFI_STATUS_CODE_VALUE Value
,
102 IN CONST EFI_STATUS_CODE_DATA
*Data
,
103 OUT CHAR8
**Filename
,
104 OUT CHAR8
**Description
,
105 OUT UINT32
*LineNumber
108 EFI_DEBUG_ASSERT_DATA
*AssertData
;
110 ASSERT (Data
!= NULL
);
111 ASSERT (Filename
!= NULL
);
112 ASSERT (Description
!= NULL
);
113 ASSERT (LineNumber
!= NULL
);
115 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
116 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
117 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
118 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
119 *Filename
= (CHAR8
*)(AssertData
+ 1);
120 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
121 *LineNumber
= AssertData
->LineNumber
;
129 Extracts DEBUG() information from a status code structure.
131 Converts the status code specified by Data to the DEBUG() arguments specified
132 by ErrorLevel, Marker, and Format. If type GUID in Data is
133 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
134 Format from the optional data area of the status code buffer specified by Data.
135 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
136 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
137 the Format. If the DEBUG() information could be extracted from Data, then
138 return TRUE. Otherwise, FALSE is returned.
140 If Data is NULL, then ASSERT().
141 If ErrorLevel is NULL, then ASSERT().
142 If Marker is NULL, then ASSERT().
143 If Format is NULL, then ASSERT().
145 @param Data Pointer to status code data buffer.
146 @param ErrorLevel Pointer to error level mask for a debug message.
147 @param Marker Pointer to the variable argument list associated with Format.
148 @param Format Pointer to a Null-terminated ASCII format string of a
151 @retval TRUE The status code specified by Data was converted DEBUG() arguments
152 specified by ErrorLevel, Marker, and Format.
153 @retval FALSE The status code specified by Data could not be converted to
159 ReportStatusCodeExtractDebugInfo (
160 IN CONST EFI_STATUS_CODE_DATA
*Data
,
161 OUT UINT32
*ErrorLevel
,
162 OUT BASE_LIST
*Marker
,
166 EFI_DEBUG_INFO
*DebugInfo
;
168 ASSERT (Data
!= NULL
);
169 ASSERT (ErrorLevel
!= NULL
);
170 ASSERT (Marker
!= NULL
);
171 ASSERT (Format
!= NULL
);
174 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
176 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
181 // Retrieve the debug information from the status code record
183 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
185 *ErrorLevel
= DebugInfo
->ErrorLevel
;
188 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
189 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.
190 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is
191 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker
192 // returned is 64-bit aligned.
193 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will
194 // cause unalignment exception.
196 *Marker
= (BASE_LIST
) (DebugInfo
+ 1);
197 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
204 Reports a status code.
206 Reports the status code specified by the parameters Type and Value. Status
207 code also require an instance, caller ID, and extended data. This function
208 passed in a zero instance, NULL extended data, and a caller ID of
209 gEfiCallerIdGuid, which is the GUID for the module.
211 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
212 is called while processing another any other Report Status Code Library function,
213 then ReportStatusCode() must return immediately.
215 @param Type Status code type.
216 @param Value Status code value.
218 @retval EFI_SUCCESS The status code was reported.
219 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
221 @retval EFI_UNSUPPORTED Report status code is not supported
227 IN EFI_STATUS_CODE_TYPE Type
,
228 IN EFI_STATUS_CODE_VALUE Value
231 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
236 Reports a status code with a Device Path Protocol as the extended data.
238 Allocates and fills in the extended data section of a status code with the
239 Device Path Protocol specified by DevicePath. This function is responsible
240 for allocating a buffer large enough for the standard header and the device
241 path. The standard header is filled in with a GUID of
242 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
243 instance and a caller ID of gEfiCallerIdGuid.
245 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
246 ReportStatusCodeWithDevicePath() is called while processing another any other
247 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
248 must return EFI_DEVICE_ERROR immediately.
250 If DevicePath is NULL, then ASSERT().
252 @param Type Status code type.
253 @param Value Status code value.
254 @param DevicePath Pointer to the Device Path Protocol to be reported.
256 @retval EFI_SUCCESS The status code was reported with the extended
257 data specified by DevicePath.
258 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
259 extended data section.
260 @retval EFI_UNSUPPORTED Report status code is not supported
265 ReportStatusCodeWithDevicePath (
266 IN EFI_STATUS_CODE_TYPE Type
,
267 IN EFI_STATUS_CODE_VALUE Value
,
268 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
271 ASSERT (DevicePath
!= NULL
);
272 return ReportStatusCodeWithExtendedData (
276 GetDevicePathSize (DevicePath
)
282 Reports a status code with an extended data buffer.
284 Allocates and fills in the extended data section of a status code with the
285 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
286 is assumed to be one of the data structures specified in Related Definitions.
287 These data structure do not have the standard header, so this function is
288 responsible for allocating a buffer large enough for the standard header and
289 the extended data passed into this function. The standard header is filled
290 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
291 with a zero instance and a caller ID of gEfiCallerIdGuid.
293 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
294 ReportStatusCodeWithExtendedData() is called while processing another any other
295 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
296 must return EFI_DEVICE_ERROR immediately.
298 If ExtendedData is NULL, then ASSERT().
299 If ExtendedDataSize is 0, then ASSERT().
301 @param Type Status code type.
302 @param Value Status code value.
303 @param ExtendedData Pointer to the extended data buffer to be reported.
304 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
307 @retval EFI_SUCCESS The status code was reported with the extended
308 data specified by ExtendedData and ExtendedDataSize.
309 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
310 extended data section.
311 @retval EFI_UNSUPPORTED Report status code is not supported
316 ReportStatusCodeWithExtendedData (
317 IN EFI_STATUS_CODE_TYPE Type
,
318 IN EFI_STATUS_CODE_VALUE Value
,
319 IN CONST VOID
*ExtendedData
,
320 IN UINTN ExtendedDataSize
323 ASSERT (ExtendedData
!= NULL
);
324 ASSERT (ExtendedDataSize
!= 0);
325 return ReportStatusCodeEx (
338 Reports a status code with full parameters.
340 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
341 is 0, then an extended data buffer is not reported. If ExtendedData is not
342 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
343 ExtendedData is assumed not have the standard status code header, so this function
344 is responsible for allocating a buffer large enough for the standard header and
345 the extended data passed into this function. The standard header is filled in
346 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
347 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with
348 an instance specified by Instance and a caller ID specified by CallerId. If
349 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
351 ReportStatusCodeEx()must actively prevent recursion. If
352 ReportStatusCodeEx() is called while processing another any
353 other Report Status Code Library function, then
354 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
356 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
357 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
359 @param Type Status code type.
360 @param Value Status code value.
361 @param Instance Status code instance number.
362 @param CallerId Pointer to a GUID that identifies the caller of this
363 function. If this parameter is NULL, then a caller
364 ID of gEfiCallerIdGuid is used.
365 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
366 If this parameter is NULL, then a the status code
367 standard header is filled in with
368 gEfiStatusCodeSpecificDataGuid.
369 @param ExtendedData Pointer to the extended data buffer. This is an
370 optional parameter that may be NULL.
371 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
373 @retval EFI_SUCCESS The status code was reported.
374 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
375 the extended data section if it was specified.
376 @retval EFI_UNSUPPORTED Report status code is not supported
382 IN EFI_STATUS_CODE_TYPE Type
,
383 IN EFI_STATUS_CODE_VALUE Value
,
385 IN CONST EFI_GUID
*CallerId OPTIONAL
,
386 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
387 IN CONST VOID
*ExtendedData OPTIONAL
,
388 IN UINTN ExtendedDataSize
393 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
394 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
396 if (ExtendedDataSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
397 DEBUG ((EFI_D_ERROR
, "Status code extended data is too large to be reported!\n"));
398 return EFI_OUT_OF_RESOURCES
;
402 // Fill in the extended data header
404 mStatusCodeData
->HeaderSize
= (UINT16
) sizeof (EFI_STATUS_CODE_DATA
);
405 mStatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
406 if (ExtendedDataGuid
== NULL
) {
407 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
409 CopyGuid (&mStatusCodeData
->Type
, ExtendedDataGuid
);
412 // Fill in the extended data buffer
414 if (ExtendedData
!= NULL
) {
415 CopyMem (mStatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
419 // Report the status code
421 if (CallerId
== NULL
) {
422 CallerId
= &gEfiCallerIdGuid
;
424 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, mStatusCodeData
);
431 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
433 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
434 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
436 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
437 PcdReportStatusCodeProperyMask is set.
438 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
439 PcdReportStatusCodeProperyMask is clear.
444 ReportProgressCodeEnabled (
448 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
453 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
455 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
456 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
458 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
459 PcdReportStatusCodeProperyMask is set.
460 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
461 PcdReportStatusCodeProperyMask is clear.
466 ReportErrorCodeEnabled (
470 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
475 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
477 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
478 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
480 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
481 PcdReportStatusCodeProperyMask is set.
482 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
483 PcdReportStatusCodeProperyMask is clear.
488 ReportDebugCodeEnabled (
492 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);