3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Report Status Code Library for SMM Runtime driver.
23 #include "ReportStatusCodeLibInternal.h"
26 EFI_REPORT_STATUS_CODE mReportStatusCode
= NULL
;
29 Internal worker function that reports a status code through the Status Code Protocol
31 This function checks to see if a Status Code Protocol is present in the handle
32 database. If a Status Code Protocol is not present, then EFI_UNSUPPORTED is
33 returned. If a Status Code Protocol is present, then it is cached in gStatusCode,
34 and the ReportStatusCode() service of the Status Code Protocol is called passing in
35 Type, Value, Instance, CallerId, and Data. The result of this call is returned.
37 @param Type Status code type.
38 @param Value Status code value.
39 @param Instance Status code instance number.
40 @param CallerId Pointer to a GUID that identifies the caller of this
41 function. This is an optional parameter that may be
43 @param Data Pointer to the extended data buffer. This is an
44 optional parameter that may be NULL.
46 @retval EFI_SUCCESS The status code was reported.
47 @retval EFI_OUT_OF_RESOURCES There were not enough resources to report the status code.
48 @retval EFI_UNSUPPORTED Status Code Protocol is not available.
52 InternalReportStatusCode (
53 IN EFI_STATUS_CODE_TYPE Type
,
54 IN EFI_STATUS_CODE_VALUE Value
,
56 IN CONST EFI_GUID
*CallerId OPTIONAL
,
57 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
61 // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
62 // in the handle database.
64 if (mReportStatusCode
== NULL
) {
65 mReportStatusCode
= InternalGetReportStatusCode ();
66 if (mReportStatusCode
== NULL
) {
67 return EFI_UNSUPPORTED
;
72 // A Status Code Protocol is present in the handle database, so pass in all the
73 // parameters to the ReportStatusCode() service of the Status Code Protocol
75 return (*mReportStatusCode
) (Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
80 Computes and returns the size, in bytes, of a device path.
82 @param DevicePath A pointer to a device path.
84 @return The size, in bytes, of DevicePath.
88 InternalReportStatusCodeDevicePathSize (
89 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
92 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
95 // Search for the end of the device path structure
98 while (!IsDevicePathEnd (DevicePath
)) {
99 DevicePath
= NextDevicePathNode (DevicePath
);
103 // Subtract the start node from the end node and add in the size of the end node
105 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
110 Converts a status code to an 8-bit POST code value.
112 Converts the status code specified by CodeType and Value to an 8-bit POST code
113 and returns the 8-bit POST code in PostCode. If CodeType is an
114 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
115 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
116 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
118 If PostCode is NULL, then ASSERT().
120 @param CodeType The type of status code being converted.
121 @param Value The status code value being converted.
122 @param PostCode A pointer to the 8-bit POST code value to return.
124 @retval TRUE The status code specified by CodeType and Value was converted
125 to an 8-bit POST code and returned in PostCode.
126 @retval FALSE The status code specified by CodeType and Value could not be
127 converted to an 8-bit POST code value.
132 GlueCodeTypeToPostCode (
133 IN EFI_STATUS_CODE_TYPE CodeType
,
134 IN EFI_STATUS_CODE_VALUE Value
,
139 // If PostCode is NULL, then ASSERT()
141 ASSERT (PostCode
!= NULL
);
144 // Convert Value to an 8 bit post code
146 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
147 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
148 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
149 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
157 Extracts ASSERT() information from a status code structure.
159 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
160 arguments specified by Filename, Description, and LineNumber. If CodeType is
161 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
162 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
163 Filename, Description, and LineNumber from the optional data area of the
164 status code buffer specified by Data. The optional data area of Data contains
165 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
166 ASCII string for the Description, followed by a 32-bit LineNumber. If the
167 ASSERT() information could be extracted from Data, then return TRUE.
168 Otherwise, FALSE is returned.
170 If Data is NULL, then ASSERT().
171 If Filename is NULL, then ASSERT().
172 If Description is NULL, then ASSERT().
173 If LineNumber is NULL, then ASSERT().
175 @param CodeType The type of status code being converted.
176 @param Value The status code value being converted.
177 @param Data Pointer to status code data buffer.
178 @param Filename Pointer to the source file name that generated the ASSERT().
179 @param Description Pointer to the description of the ASSERT().
180 @param LineNumber Pointer to source line number that generated the ASSERT().
182 @retval TRUE The status code specified by CodeType, Value, and Data was
183 converted ASSERT() arguments specified by Filename, Description,
185 @retval FALSE The status code specified by CodeType, Value, and Data could
186 not be converted to ASSERT() arguments.
191 GlueReportStatusCodeExtractAssertInfo (
192 IN EFI_STATUS_CODE_TYPE CodeType
,
193 IN EFI_STATUS_CODE_VALUE Value
,
194 IN CONST EFI_STATUS_CODE_DATA
*Data
,
195 OUT CHAR8
**Filename
,
196 OUT CHAR8
**Description
,
197 OUT UINT32
*LineNumber
200 EFI_DEBUG_ASSERT_DATA
*AssertData
;
202 ASSERT (Data
!= NULL
);
203 ASSERT (Filename
!= NULL
);
204 ASSERT (Description
!= NULL
);
205 ASSERT (LineNumber
!= NULL
);
207 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
208 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
209 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
210 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
211 *Filename
= (CHAR8
*)(AssertData
+ 1);
212 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
213 *LineNumber
= AssertData
->LineNumber
;
221 Extracts DEBUG() information from a status code structure.
223 Converts the status code specified by Data to the DEBUG() arguments specified
224 by ErrorLevel, Marker, and Format. If type GUID in Data is
225 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
226 Format from the optional data area of the status code buffer specified by Data.
227 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
228 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
229 the Format. If the DEBUG() information could be extracted from Data, then
230 return TRUE. Otherwise, FALSE is returned.
232 If Data is NULL, then ASSERT().
233 If ErrorLevel is NULL, then ASSERT().
234 If Marker is NULL, then ASSERT().
235 If Format is NULL, then ASSERT().
237 @param Data Pointer to status code data buffer.
238 @param ErrorLevel Pointer to error level mask for a debug message.
239 @param Marker Pointer to the variable argument list associated with Format.
240 @param Format Pointer to a Null-terminated ASCII format string of a
243 @retval TRUE The status code specified by Data was converted DEBUG() arguments
244 specified by ErrorLevel, Marker, and Format.
245 @retval FALSE The status code specified by Data could not be converted to
251 GlueReportStatusCodeExtractDebugInfo (
252 IN CONST EFI_STATUS_CODE_DATA
*Data
,
253 OUT UINT32
*ErrorLevel
,
258 EFI_DEBUG_INFO
*DebugInfo
;
260 ASSERT (Data
!= NULL
);
261 ASSERT (ErrorLevel
!= NULL
);
262 ASSERT (Marker
!= NULL
);
263 ASSERT (Format
!= NULL
);
266 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
268 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
273 // Retrieve the debug information from the status code record
275 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
277 *ErrorLevel
= DebugInfo
->ErrorLevel
;
280 // The first 12 * UINTN bytes of the string are really an
281 // argument stack to support varargs on the Format string.
283 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
284 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
291 Reports a status code.
293 Reports the status code specified by the parameters Type and Value. Status
294 code also require an instance, caller ID, and extended data. This function
295 passed in a zero instance, NULL extended data, and a caller ID of
296 gEfiCallerIdGuid, which is the GUID for the module.
298 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
299 is called while processing another any other Report Status Code Library function,
300 then ReportStatusCode() must return immediately.
302 @param Type Status code type.
303 @param Value Status code value.
305 @retval EFI_SUCCESS The status code was reported.
306 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
308 @retval EFI_UNSUPPORTED Report status code is not supported
313 GlueReportStatusCode (
314 IN EFI_STATUS_CODE_TYPE Type
,
315 IN EFI_STATUS_CODE_VALUE Value
318 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
323 Reports a status code with a Device Path Protocol as the extended data.
325 Allocates and fills in the extended data section of a status code with the
326 Device Path Protocol specified by DevicePath. This function is responsible
327 for allocating a buffer large enough for the standard header and the device
328 path. The standard header is filled in with a GUID of
329 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero
330 instance and a caller ID of gEfiCallerIdGuid.
332 ReportStatusCodeWithDevicePath()must actively prevent recursion. If
333 ReportStatusCodeWithDevicePath() is called while processing another any other
334 Report Status Code Library function, then ReportStatusCodeWithDevicePath()
335 must return EFI_DEVICE_ERROR immediately.
337 If DevicePath is NULL, then ASSERT().
339 @param Type Status code type.
340 @param Value Status code value.
341 @param DevicePath Pointer to the Device Path Protocol to be reported.
343 @retval EFI_SUCCESS The status code was reported with the extended
344 data specified by DevicePath.
345 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
346 extended data section.
347 @retval EFI_UNSUPPORTED Report status code is not supported
352 GlueReportStatusCodeWithDevicePath (
353 IN EFI_STATUS_CODE_TYPE Type
,
354 IN EFI_STATUS_CODE_VALUE Value
,
355 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
358 ASSERT (DevicePath
!= NULL
);
359 return ReportStatusCodeWithExtendedData (
363 InternalReportStatusCodeDevicePathSize (DevicePath
)
369 Reports a status code with an extended data buffer.
371 Allocates and fills in the extended data section of a status code with the
372 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
373 is assumed to be one of the data structures specified in Related Definitions.
374 These data structure do not have the standard header, so this function is
375 responsible for allocating a buffer large enough for the standard header and
376 the extended data passed into this function. The standard header is filled
377 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
378 with a zero instance and a caller ID of gEfiCallerIdGuid.
380 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
381 ReportStatusCodeWithExtendedData() is called while processing another any other
382 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
383 must return EFI_DEVICE_ERROR immediately.
385 If ExtendedData is NULL, then ASSERT().
386 If ExtendedDataSize is 0, then ASSERT().
388 @param Type Status code type.
389 @param Value Status code value.
390 @param ExtendedData Pointer to the extended data buffer to be reported.
391 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
394 @retval EFI_SUCCESS The status code was reported with the extended
395 data specified by ExtendedData and ExtendedDataSize.
396 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
397 extended data section.
398 @retval EFI_UNSUPPORTED Report status code is not supported
403 GlueReportStatusCodeWithExtendedData (
404 IN EFI_STATUS_CODE_TYPE Type
,
405 IN EFI_STATUS_CODE_VALUE Value
,
406 IN CONST VOID
*ExtendedData
,
407 IN UINTN ExtendedDataSize
410 ASSERT (ExtendedData
!= NULL
);
411 ASSERT (ExtendedDataSize
!= 0);
412 return ReportStatusCodeEx (
425 Reports a status code with full parameters.
427 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
428 is 0, then an extended data buffer is not reported. If ExtendedData is not
429 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
430 ExtendedData is assumed not have the standard status code header, so this function
431 is responsible for allocating a buffer large enough for the standard header and
432 the extended data passed into this function. The standard header is filled in
433 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
434 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
435 an instance specified by Instance and a caller ID specified by CallerId. If
436 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
438 ReportStatusCodeEx()must actively prevent recursion. If
439 ReportStatusCodeEx() is called while processing another any
440 other Report Status Code Library function, then
441 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
443 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
444 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
446 @param Type Status code type.
447 @param Value Status code value.
448 @param Instance Status code instance number.
449 @param CallerId Pointer to a GUID that identifies the caller of this
450 function. If this parameter is NULL, then a caller
451 ID of gEfiCallerIdGuid is used.
452 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
453 If this parameter is NULL, then a the status code
454 standard header is filled in with
455 gEfiStatusCodeSpecificDataGuid.
456 @param ExtendedData Pointer to the extended data buffer. This is an
457 optional parameter that may be NULL.
458 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
460 @retval EFI_SUCCESS The status code was reported.
461 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
462 the extended data section if it was specified.
463 @retval EFI_UNSUPPORTED Report status code is not supported
468 GlueReportStatusCodeEx (
469 IN EFI_STATUS_CODE_TYPE Type
,
470 IN EFI_STATUS_CODE_VALUE Value
,
472 IN CONST EFI_GUID
*CallerId OPTIONAL
,
473 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
474 IN CONST VOID
*ExtendedData OPTIONAL
,
475 IN UINTN ExtendedDataSize
480 Status
= InternalReportStatusCodeEx (
495 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
497 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
498 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
500 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
501 PcdReportStatusCodeProperyMask is set.
502 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
503 PcdReportStatusCodeProperyMask is clear.
508 GlueReportProgressCodeEnabled (
512 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
517 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
519 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
520 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
522 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
523 PcdReportStatusCodeProperyMask is set.
524 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
525 PcdReportStatusCodeProperyMask is clear.
530 GlueReportErrorCodeEnabled (
534 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
539 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
541 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
542 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
544 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
545 PcdReportStatusCodeProperyMask is set.
546 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
547 PcdReportStatusCodeProperyMask is clear.
552 GlueReportDebugCodeEnabled (
556 return (BOOLEAN
) ((PcdGet8(PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);