2 Report Status Code Library for SMM Phase.
4 Copyright (c) 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.
15 #include <Library/ReportStatusCodeLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/SmmServicesTableLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/PcdLib.h>
22 #include <Guid/StatusCodeDataTypeId.h>
23 #include <Guid/StatusCodeDataTypeDebug.h>
24 #include <Protocol/SmmStatusCode.h>
26 EFI_SMM_REPORT_STATUS_CODE mReportStatusCode
= NULL
;
27 EFI_SMM_STATUS_CODE_PROTOCOL
*mStatusCodeProtocol
= NULL
;
31 Locate the report status code service.
33 @return Function pointer to the report status code service.
34 NULL is returned if no status code service is available.
37 EFI_SMM_REPORT_STATUS_CODE
38 InternalGetReportStatusCode (
44 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid
, NULL
, (VOID
**)&mStatusCodeProtocol
);
45 if (!EFI_ERROR (Status
) && mStatusCodeProtocol
!= NULL
) {
46 return mStatusCodeProtocol
->ReportStatusCode
;
52 Internal worker function that reports a status code through the status code service.
54 If status code service is not cached, then this function checks if status code service is
55 available in system. If status code service is not available, then EFI_UNSUPPORTED is
56 returned. If status code service is present, then it is cached in mReportStatusCode.
57 Finally this function reports status code through the status code service.
59 @param Type Status code type.
60 @param Value Status code value.
61 @param Instance Status code instance number.
62 @param CallerId Pointer to a GUID that identifies the caller of this
63 function. This is an optional parameter that may be
65 @param Data Pointer to the extended data buffer. This is an
66 optional parameter that may be NULL.
68 @retval EFI_SUCCESS The status code was reported.
69 @retval EFI_UNSUPPORTED Status code service is not available.
70 @retval EFI_UNSUPPORTED Status code type is not supported.
74 InternalReportStatusCode (
75 IN EFI_STATUS_CODE_TYPE Type
,
76 IN EFI_STATUS_CODE_VALUE Value
,
78 IN CONST EFI_GUID
*CallerId OPTIONAL
,
79 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
82 if ((ReportProgressCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
83 (ReportErrorCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ||
84 (ReportDebugCodeEnabled() && ((Type
) & EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
)) {
86 // If mReportStatusCode is NULL, then check if status code service is available in system.
88 if (mReportStatusCode
== NULL
) {
89 mReportStatusCode
= InternalGetReportStatusCode ();
90 if (mReportStatusCode
== NULL
) {
91 return EFI_UNSUPPORTED
;
96 // A status code service is present in system, so pass in all the parameters to the service.
98 return (*mReportStatusCode
) (mStatusCodeProtocol
, Type
, Value
, Instance
, (EFI_GUID
*)CallerId
, Data
);
101 return EFI_UNSUPPORTED
;
106 Converts a status code to an 8-bit POST code value.
108 Converts the status code specified by CodeType and Value to an 8-bit POST code
109 and returns the 8-bit POST code in PostCode. If CodeType is an
110 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode
111 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits
112 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.
114 If PostCode is NULL, then ASSERT().
116 @param CodeType The type of status code being converted.
117 @param Value The status code value being converted.
118 @param PostCode A pointer to the 8-bit POST code value to return.
120 @retval TRUE The status code specified by CodeType and Value was converted
121 to an 8-bit POST code and returned in PostCode.
122 @retval FALSE The status code specified by CodeType and Value could not be
123 converted to an 8-bit POST code value.
129 IN EFI_STATUS_CODE_TYPE CodeType
,
130 IN EFI_STATUS_CODE_VALUE Value
,
135 // If PostCode is NULL, then ASSERT()
137 ASSERT (PostCode
!= NULL
);
140 // Convert Value to an 8 bit post code
142 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) ||
143 ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) ) {
144 *PostCode
= (UINT8
) ((((Value
& EFI_STATUS_CODE_CLASS_MASK
) >> 24) << 5) |
145 (((Value
& EFI_STATUS_CODE_SUBCLASS_MASK
) >> 16) & 0x1f));
153 Extracts ASSERT() information from a status code structure.
155 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
156 arguments specified by Filename, Description, and LineNumber. If CodeType is
157 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
158 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
159 Filename, Description, and LineNumber from the optional data area of the
160 status code buffer specified by Data. The optional data area of Data contains
161 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
162 ASCII string for the Description, followed by a 32-bit LineNumber. If the
163 ASSERT() information could be extracted from Data, then return TRUE.
164 Otherwise, FALSE is returned.
166 If Data is NULL, then ASSERT().
167 If Filename is NULL, then ASSERT().
168 If Description is NULL, then ASSERT().
169 If LineNumber is NULL, then ASSERT().
171 @param CodeType The type of status code being converted.
172 @param Value The status code value being converted.
173 @param Data Pointer to status code data buffer.
174 @param Filename Pointer to the source file name that generated the ASSERT().
175 @param Description Pointer to the description of the ASSERT().
176 @param LineNumber Pointer to source line number that generated the ASSERT().
178 @retval TRUE The status code specified by CodeType, Value, and Data was
179 converted ASSERT() arguments specified by Filename, Description,
181 @retval FALSE The status code specified by CodeType, Value, and Data could
182 not be converted to ASSERT() arguments.
187 ReportStatusCodeExtractAssertInfo (
188 IN EFI_STATUS_CODE_TYPE CodeType
,
189 IN EFI_STATUS_CODE_VALUE Value
,
190 IN CONST EFI_STATUS_CODE_DATA
*Data
,
191 OUT CHAR8
**Filename
,
192 OUT CHAR8
**Description
,
193 OUT UINT32
*LineNumber
196 EFI_DEBUG_ASSERT_DATA
*AssertData
;
198 ASSERT (Data
!= NULL
);
199 ASSERT (Filename
!= NULL
);
200 ASSERT (Description
!= NULL
);
201 ASSERT (LineNumber
!= NULL
);
203 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
204 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
) &&
205 ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
)) {
206 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
207 *Filename
= (CHAR8
*)(AssertData
+ 1);
208 *Description
= *Filename
+ AsciiStrLen (*Filename
) + 1;
209 *LineNumber
= AssertData
->LineNumber
;
217 Extracts DEBUG() information from a status code structure.
219 Converts the status code specified by Data to the DEBUG() arguments specified
220 by ErrorLevel, Marker, and Format. If type GUID in Data is
221 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
222 Format from the optional data area of the status code buffer specified by Data.
223 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
224 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
225 the Format. If the DEBUG() information could be extracted from Data, then
226 return TRUE. Otherwise, FALSE is returned.
228 If Data is NULL, then ASSERT().
229 If ErrorLevel is NULL, then ASSERT().
230 If Marker is NULL, then ASSERT().
231 If Format is NULL, then ASSERT().
233 @param Data Pointer to status code data buffer.
234 @param ErrorLevel Pointer to error level mask for a debug message.
235 @param Marker Pointer to the variable argument list associated with Format.
236 @param Format Pointer to a Null-terminated ASCII format string of a
239 @retval TRUE The status code specified by Data was converted DEBUG() arguments
240 specified by ErrorLevel, Marker, and Format.
241 @retval FALSE The status code specified by Data could not be converted to
247 ReportStatusCodeExtractDebugInfo (
248 IN CONST EFI_STATUS_CODE_DATA
*Data
,
249 OUT UINT32
*ErrorLevel
,
250 OUT BASE_LIST
*Marker
,
254 EFI_DEBUG_INFO
*DebugInfo
;
256 ASSERT (Data
!= NULL
);
257 ASSERT (ErrorLevel
!= NULL
);
258 ASSERT (Marker
!= NULL
);
259 ASSERT (Format
!= NULL
);
262 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
264 if (!CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
269 // Retrieve the debug information from the status code record
271 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
273 *ErrorLevel
= DebugInfo
->ErrorLevel
;
276 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
277 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.
278 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is
279 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker
280 // returned is 64-bit aligned.
281 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will
282 // cause unalignment exception.
284 *Marker
= (BASE_LIST
) (DebugInfo
+ 1);
285 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);
292 Reports a status code.
294 Reports the status code specified by the parameters Type and Value. Status
295 code also require an instance, caller ID, and extended data. This function
296 passed in a zero instance, NULL extended data, and a caller ID of
297 gEfiCallerIdGuid, which is the GUID for the module.
299 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
300 is called while processing another any other Report Status Code Library function,
301 then ReportStatusCode() must return immediately.
303 @param Type Status code type.
304 @param Value Status code value.
306 @retval EFI_SUCCESS The status code was reported.
307 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
309 @retval EFI_UNSUPPORTED Report status code is not supported
315 IN EFI_STATUS_CODE_TYPE Type
,
316 IN EFI_STATUS_CODE_VALUE Value
319 return InternalReportStatusCode (Type
, Value
, 0, &gEfiCallerIdGuid
, NULL
);
324 Reports a status code with an extended data buffer.
326 Allocates and fills in the extended data section of a status code with the
327 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
328 is assumed to be one of the data structures specified in Related Definitions.
329 These data structure do not have the standard header, so this function is
330 responsible for allocating a buffer large enough for the standard header and
331 the extended data passed into this function. The standard header is filled
332 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
333 with a zero instance and a caller ID of gEfiCallerIdGuid.
335 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
336 ReportStatusCodeWithExtendedData() is called while processing another any other
337 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
338 must return EFI_DEVICE_ERROR immediately.
340 If ExtendedData is NULL, then ASSERT().
341 If ExtendedDataSize is 0, then ASSERT().
343 @param Type Status code type.
344 @param Value Status code value.
345 @param ExtendedData Pointer to the extended data buffer to be reported.
346 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
349 @retval EFI_SUCCESS The status code was reported with the extended
350 data specified by ExtendedData and ExtendedDataSize.
351 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
352 extended data section.
353 @retval EFI_UNSUPPORTED Report status code is not supported
358 ReportStatusCodeWithExtendedData (
359 IN EFI_STATUS_CODE_TYPE Type
,
360 IN EFI_STATUS_CODE_VALUE Value
,
361 IN CONST VOID
*ExtendedData
,
362 IN UINTN ExtendedDataSize
365 ASSERT (ExtendedData
!= NULL
);
366 ASSERT (ExtendedDataSize
!= 0);
367 return ReportStatusCodeEx (
380 Reports a status code with full parameters.
382 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
383 is 0, then an extended data buffer is not reported. If ExtendedData is not
384 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
385 ExtendedData is assumed not have the standard status code header, so this function
386 is responsible for allocating a buffer large enough for the standard header and
387 the extended data passed into this function. The standard header is filled in
388 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
389 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with
390 an instance specified by Instance and a caller ID specified by CallerId. If
391 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
393 ReportStatusCodeEx()must actively prevent recursion. If
394 ReportStatusCodeEx() is called while processing another any
395 other Report Status Code Library function, then
396 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
398 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
399 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
401 @param Type Status code type.
402 @param Value Status code value.
403 @param Instance Status code instance number.
404 @param CallerId Pointer to a GUID that identifies the caller of this
405 function. If this parameter is NULL, then a caller
406 ID of gEfiCallerIdGuid is used.
407 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
408 If this parameter is NULL, then a the status code
409 standard header is filled in with
410 gEfiStatusCodeSpecificDataGuid.
411 @param ExtendedData Pointer to the extended data buffer. This is an
412 optional parameter that may be NULL.
413 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
415 @retval EFI_SUCCESS The status code was reported.
416 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
417 the extended data section if it was specified.
418 @retval EFI_UNSUPPORTED Report status code is not supported
424 IN EFI_STATUS_CODE_TYPE Type
,
425 IN EFI_STATUS_CODE_VALUE Value
,
427 IN CONST EFI_GUID
*CallerId OPTIONAL
,
428 IN CONST EFI_GUID
*ExtendedDataGuid OPTIONAL
,
429 IN CONST VOID
*ExtendedData OPTIONAL
,
430 IN UINTN ExtendedDataSize
434 EFI_STATUS_CODE_DATA
*StatusCodeData
;
436 ASSERT (!((ExtendedData
== NULL
) && (ExtendedDataSize
!= 0)));
437 ASSERT (!((ExtendedData
!= NULL
) && (ExtendedDataSize
== 0)));
439 if (gSmst
== NULL
|| gSmst
->SmmAllocatePool
== NULL
|| gSmst
->SmmFreePool
== NULL
) {
440 return EFI_UNSUPPORTED
;
444 // Allocate space for the Status Code Header and its buffer
446 StatusCodeData
= NULL
;
447 gSmst
->SmmAllocatePool (EfiRuntimeServicesData
, sizeof (EFI_STATUS_CODE_DATA
) + ExtendedDataSize
, (VOID
**)&StatusCodeData
);
448 if (StatusCodeData
== NULL
) {
449 return EFI_OUT_OF_RESOURCES
;
453 // Fill in the extended data header
455 StatusCodeData
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
456 StatusCodeData
->Size
= (UINT16
)ExtendedDataSize
;
457 if (ExtendedDataGuid
== NULL
) {
458 ExtendedDataGuid
= &gEfiStatusCodeSpecificDataGuid
;
460 CopyGuid (&StatusCodeData
->Type
, ExtendedDataGuid
);
463 // Fill in the extended data buffer
465 if (ExtendedData
!= NULL
) {
466 CopyMem (StatusCodeData
+ 1, ExtendedData
, ExtendedDataSize
);
470 // Report the status code
472 if (CallerId
== NULL
) {
473 CallerId
= &gEfiCallerIdGuid
;
475 Status
= InternalReportStatusCode (Type
, Value
, Instance
, CallerId
, StatusCodeData
);
478 // Free the allocated buffer
480 gSmst
->SmmFreePool (StatusCodeData
);
487 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
489 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
490 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
492 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
493 PcdReportStatusCodeProperyMask is set.
494 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
495 PcdReportStatusCodeProperyMask is clear.
500 ReportProgressCodeEnabled (
504 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
) != 0);
509 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
511 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
512 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
514 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
515 PcdReportStatusCodeProperyMask is set.
516 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
517 PcdReportStatusCodeProperyMask is clear.
522 ReportErrorCodeEnabled (
526 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
) != 0);
531 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
533 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
534 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
536 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
537 PcdReportStatusCodeProperyMask is set.
538 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
539 PcdReportStatusCodeProperyMask is clear.
544 ReportDebugCodeEnabled (
548 return (BOOLEAN
) ((PcdGet8 (PcdReportStatusCodePropertyMask
) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
) != 0);