2 Provides services to log status code records.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef __REPORT_STATUS_CODE_LIB_H__
10 #define __REPORT_STATUS_CODE_LIB_H__
12 #include <Uefi/UefiBaseType.h>
13 #include <Pi/PiStatusCode.h>
14 #include <Protocol/DevicePath.h>
17 // Declare bits for PcdReportStatusCodePropertyMask
19 #define REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED 0x00000001
20 #define REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED 0x00000002
21 #define REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED 0x00000004
24 Converts a status code to an 8-bit POST code value.
26 Converts the status code specified by CodeType and Value to an 8-bit POST code
27 and returns the 8-bit POST code in PostCode. If CodeType is an
28 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
29 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
30 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
32 If PostCode is NULL, then ASSERT().
34 @param CodeType The type of status code being converted.
35 @param Value The status code value being converted.
36 @param PostCode A pointer to the 8-bit POST code value to return.
38 @retval TRUE The status code specified by CodeType and Value was converted
39 to an 8-bit POST code and returned in PostCode.
40 @retval FALSE The status code specified by CodeType and Value could not be
41 converted to an 8-bit POST code value.
47 IN EFI_STATUS_CODE_TYPE CodeType
,
48 IN EFI_STATUS_CODE_VALUE Value
,
53 Extracts ASSERT() information from a status code structure.
55 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
56 arguments specified by Filename, Description, and LineNumber. If CodeType is
57 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
58 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
59 Filename, Description, and LineNumber from the optional data area of the
60 status code buffer specified by Data. The optional data area of Data contains
61 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
62 ASCII string for the Description, followed by a 32-bit LineNumber. If the
63 ASSERT() information could be extracted from Data, then return TRUE.
64 Otherwise, FALSE is returned.
66 If Data is NULL, then ASSERT().
67 If Filename is NULL, then ASSERT().
68 If Description is NULL, then ASSERT().
69 If LineNumber is NULL, then ASSERT().
71 @param CodeType The type of status code being converted.
72 @param Value The status code value being converted.
73 @param Data The pointer to status code data buffer.
74 @param Filename The pointer to the source file name that generated the ASSERT().
75 @param Description The pointer to the description of the ASSERT().
76 @param LineNumber The pointer to source line number that generated the ASSERT().
78 @retval TRUE The status code specified by CodeType, Value, and Data was
79 converted ASSERT() arguments specified by Filename, Description,
81 @retval FALSE The status code specified by CodeType, Value, and Data could
82 not be converted to ASSERT() arguments.
87 ReportStatusCodeExtractAssertInfo (
88 IN EFI_STATUS_CODE_TYPE CodeType
,
89 IN EFI_STATUS_CODE_VALUE Value
,
90 IN CONST EFI_STATUS_CODE_DATA
*Data
,
92 OUT CHAR8
**Description
,
93 OUT UINT32
*LineNumber
97 Extracts DEBUG() information from a status code structure.
99 Converts the status code specified by Data to the DEBUG() arguments specified
100 by ErrorLevel, Marker, and Format. If type GUID in Data is
101 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
102 Format from the optional data area of the status code buffer specified by Data.
103 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
104 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
105 the Format. If the DEBUG() information could be extracted from Data, then
106 return TRUE. Otherwise, FALSE is returned.
108 If Data is NULL, then ASSERT().
109 If ErrorLevel is NULL, then ASSERT().
110 If Marker is NULL, then ASSERT().
111 If Format is NULL, then ASSERT().
113 @param Data The pointer to status code data buffer.
114 @param ErrorLevel The pointer to error level mask for a debug message.
115 @param Marker The pointer to the variable argument list associated with Format.
116 @param Format The pointer to a Null-terminated ASCII format string of a
119 @retval TRUE The status code specified by Data was converted DEBUG() arguments
120 specified by ErrorLevel, Marker, and Format.
121 @retval FALSE The status code specified by Data could not be converted to
127 ReportStatusCodeExtractDebugInfo (
128 IN CONST EFI_STATUS_CODE_DATA
*Data
,
129 OUT UINT32
*ErrorLevel
,
130 OUT BASE_LIST
*Marker
,
135 Reports a status code.
137 Reports the status code specified by the parameters Type and Value. Status
138 code also require an instance, caller ID, and extended data. This function
139 passed in a zero instance, NULL extended data, and a caller ID of
140 gEfiCallerIdGuid, which is the GUID for the module.
142 ReportStatusCode()must actively prevent recursion. If ReportStatusCode()
143 is called while processing another any other Report Status Code Library function,
144 then ReportStatusCode() must return immediately.
146 @param Type Status code type.
147 @param Value Status code value.
149 @retval EFI_SUCCESS The status code was reported.
150 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
152 @retval EFI_UNSUPPORTED The report status code is not supported.
158 IN EFI_STATUS_CODE_TYPE Type
,
159 IN EFI_STATUS_CODE_VALUE Value
163 Reports a status code with a Device Path Protocol as the extended data.
165 Allocates and fills in the extended data section of a status code with the
166 Device Path Protocol specified by DevicePath. This function is responsible
167 for allocating a buffer large enough for the standard header and the device
168 path. The standard header is filled in with an implementation dependent GUID.
169 The status code is reported with a zero instance and a caller ID of gEfiCallerIdGuid.
171 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
172 ReportStatusCodeWithDevicePath() is called while processing another any other
173 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
174 must return EFI_DEVICE_ERROR immediately.
176 If DevicePath is NULL, then ASSERT().
178 @param Type The status code type.
179 @param Value The status code value.
180 @param DevicePath The pointer to the Device Path Protocol to be reported.
182 @retval EFI_SUCCESS The status code was reported with the extended
183 data specified by DevicePath.
184 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
185 extended data section.
186 @retval EFI_UNSUPPORTED The report status code is not supported.
187 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function
188 is already in progress.
193 ReportStatusCodeWithDevicePath (
194 IN EFI_STATUS_CODE_TYPE Type
,
195 IN EFI_STATUS_CODE_VALUE Value
,
196 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
200 Reports a status code with an extended data buffer.
202 Allocates and fills in the extended data section of a status code with the
203 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
204 is assumed to be one of the data structures specified in Related Definitions.
205 These data structure do not have the standard header, so this function is
206 responsible for allocating a buffer large enough for the standard header and
207 the extended data passed into this function. The standard header is filled
208 in with an implementation dependent GUID. The status code is reported
209 with a zero instance and a caller ID of gEfiCallerIdGuid.
211 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
212 ReportStatusCodeWithExtendedData() is called while processing another any other
213 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
214 must return EFI_DEVICE_ERROR immediately.
216 If ExtendedData is NULL, then ASSERT().
217 If ExtendedDataSize is 0, then ASSERT().
219 @param Type The status code type.
220 @param Value The status code value.
221 @param ExtendedData The pointer to the extended data buffer to be reported.
222 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
225 @retval EFI_SUCCESS The status code was reported with the extended
226 data specified by ExtendedData and ExtendedDataSize.
227 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
228 extended data section.
229 @retval EFI_UNSUPPORTED The report status code is not supported.
230 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function
231 is already in progress.
236 ReportStatusCodeWithExtendedData (
237 IN EFI_STATUS_CODE_TYPE Type
,
238 IN EFI_STATUS_CODE_VALUE Value
,
239 IN CONST VOID
*ExtendedData
,
240 IN UINTN ExtendedDataSize
244 Reports a status code with full parameters.
246 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
247 is 0, then an extended data buffer is not reported. If ExtendedData is not
248 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
249 ExtendedData is assumed not have the standard status code header, so this function
250 is responsible for allocating a buffer large enough for the standard header and
251 the extended data passed into this function. The standard header is filled in
252 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
253 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with
254 an instance specified by Instance and a caller ID specified by CallerId. If
255 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
257 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
258 is called while processing another any other Report Status Code Library function,
259 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
261 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
262 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
264 @param Type The status code type.
265 @param Value The status code value.
266 @param Instance The status code instance number.
267 @param CallerId The pointer to a GUID that identifies the caller of this
268 function. If this parameter is NULL, then a caller
269 ID of gEfiCallerIdGuid is used.
270 @param ExtendedDataGuid The pointer to the GUID for the extended data buffer.
271 If this parameter is NULL, then a the status code
272 standard header is filled in with an implementation dependent GUID.
273 @param ExtendedData The pointer to the extended data buffer. This is an
274 optional parameter that may be NULL.
275 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
277 @retval EFI_SUCCESS The status code was reported.
278 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
279 the extended data section if it was specified.
280 @retval EFI_UNSUPPORTED The report status code is not supported.
281 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function
282 is already in progress.
288 IN EFI_STATUS_CODE_TYPE Type
,
289 IN EFI_STATUS_CODE_VALUE Value
,
291 IN CONST EFI_GUID
*CallerId OPTIONAL
,
292 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
293 IN CONST VOID
*ExtendedData OPTIONAL
,
294 IN UINTN ExtendedDataSize
298 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
300 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
301 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
303 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
304 PcdReportStatusCodeProperyMask is set.
305 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
306 PcdReportStatusCodeProperyMask is clear.
311 ReportProgressCodeEnabled (
316 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
318 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
319 bit of PcdReportStatusCodeProperyMask is set. Otherwise, FALSE is returned.
321 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
322 PcdReportStatusCodeProperyMask is set.
323 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
324 PcdReportStatusCodeProperyMask is clear.
329 ReportErrorCodeEnabled (
334 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
336 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
337 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
339 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
340 PcdReportStatusCodeProperyMask is set.
341 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
342 PcdReportStatusCodeProperyMask is clear.
347 ReportDebugCodeEnabled (
352 Reports a status code with minimal parameters if the status code type is enabled.
354 If the status code type specified by Type is enabled in
355 PcdReportStatusCodeProperyMask, then call ReportStatusCode() passing in Type
358 @param Type The status code type.
359 @param Value The status code value.
361 @retval EFI_SUCCESS The status code was reported.
362 @retval EFI_DEVICE_ERROR There status code could not be reported due to a device error.
363 @retval EFI_UNSUPPORTED Report status code is not supported.
366 #define REPORT_STATUS_CODE(Type, Value) \
367 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \
368 ReportStatusCode(Type,Value) : \
369 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \
370 ReportStatusCode(Type,Value) : \
371 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \
372 ReportStatusCode(Type,Value) : \
376 Reports a status code with a Device Path Protocol as the extended data if the
377 status code type is enabled.
379 If the status code type specified by Type is enabled in
380 PcdReportStatusCodeProperyMask, then call ReportStatusCodeWithDevicePath()
381 passing in Type, Value, and DevicePath.
383 @param Type The status code type.
384 @param Value The status code value.
385 @param DevicePath Pointer to the Device Path Protocol to be reported.
387 @retval EFI_SUCCESS The status code was reported with the extended
388 data specified by DevicePath.
389 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
390 extended data section.
391 @retval EFI_UNSUPPORTED The report status code is not supported.
392 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function
393 is already in progress.
396 #define REPORT_STATUS_CODE_WITH_DEVICE_PATH(Type, Value, DevicePathParameter) \
397 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \
398 ReportStatusCodeWithDevicePath(Type,Value,DevicePathParameter) : \
399 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \
400 ReportStatusCodeWithDevicePath(Type,Value,DevicePathParameter) : \
401 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \
402 ReportStatusCodeWithDevicePath(Type,Value,DevicePathParameter) : \
406 Reports a status code with an extended data buffer if the status code type
409 If the status code type specified by Type is enabled in
410 PcdReportStatusCodeProperyMask, then call ReportStatusCodeWithExtendedData()
411 passing in Type, Value, ExtendedData, and ExtendedDataSize.
413 @param Type The status code type.
414 @param Value The status code value.
415 @param ExtendedData The pointer to the extended data buffer to be reported.
416 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
419 @retval EFI_SUCCESS The status code was reported with the extended
420 data specified by ExtendedData and ExtendedDataSize.
421 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
422 extended data section.
423 @retval EFI_UNSUPPORTED The report status code is not supported.
424 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function
425 is already in progress.
428 #define REPORT_STATUS_CODE_WITH_EXTENDED_DATA(Type, Value, ExtendedData, ExtendedDataSize) \
429 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \
430 ReportStatusCodeWithExtendedData(Type,Value,ExtendedData,ExtendedDataSize) : \
431 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \
432 ReportStatusCodeWithExtendedData(Type,Value,ExtendedData,ExtendedDataSize) : \
433 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \
434 ReportStatusCodeWithExtendedData(Type,Value,ExtendedData,ExtendedDataSize) : \
438 Reports a status code specifying all parameters if the status code type is enabled.
440 If the status code type specified by Type is enabled in
441 PcdReportStatusCodeProperyMask, then call ReportStatusCodeEx() passing in Type,
442 Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, and ExtendedDataSize.
444 @param Type The status code type.
445 @param Value The status code value.
446 @param Instance The status code instance number.
447 @param CallerId The pointer to a GUID that identifies the caller of this
448 function. If this parameter is NULL, then a caller
449 ID of gEfiCallerIdGuid is used.
450 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
451 If this parameter is NULL, then a the status code
452 standard header is filled in with an implementation dependent GUID.
453 @param ExtendedData Pointer to the extended data buffer. This is an
454 optional parameter that may be NULL.
455 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
457 @retval EFI_SUCCESS The status code was reported.
458 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
459 extended data section if it was specified.
460 @retval EFI_UNSUPPORTED The report status code is not supported.
461 @retval EFI_DEVICE_ERROR A call to a Report Status Code Library function
462 is already in progress.
465 #define REPORT_STATUS_CODE_EX(Type, Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, ExtendedDataSize) \
466 (ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ? \
467 ReportStatusCodeEx(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) : \
468 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ? \
469 ReportStatusCodeEx(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) : \
470 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) ? \
471 ReportStatusCodeEx(Type,Value,Instance,CallerId,ExtendedDataGuid,ExtendedData,ExtendedDataSize) : \