EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/SmmRuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c

Go to the documentation of this file.
00001 /*++
00002 
00003 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
00004 This program and the accompanying materials                          
00005 are licensed and made available under the terms and conditions of the BSD License         
00006 which accompanies this distribution.  The full text of the license may be found at        
00007 http://opensource.org/licenses/bsd-license.php                                            
00008                                                                                           
00009 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
00010 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.              
00011 
00012 
00013 Module Name:
00014 
00015   ReportStatusCodeLib.c
00016   
00017 Abstract: 
00018 
00019   Report Status Code Library for SMM Runtime driver.
00020 
00021 --*/
00022 
00023 #include "ReportStatusCodeLibInternal.h"
00024 
00025  
00026 EFI_REPORT_STATUS_CODE  mReportStatusCode = NULL;
00027 
00051 EFI_STATUS
00052 InternalReportStatusCode (
00053   IN EFI_STATUS_CODE_TYPE     Type,
00054   IN EFI_STATUS_CODE_VALUE    Value,
00055   IN UINT32                   Instance,
00056   IN CONST EFI_GUID           *CallerId OPTIONAL,
00057   IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL
00058   )
00059 {
00060   //
00061   // If gStatusCode is NULL, then see if a Status Code Protocol instance is present
00062   // in the handle database.
00063   //
00064   if (mReportStatusCode == NULL) {
00065     mReportStatusCode = InternalGetReportStatusCode ();
00066     if (mReportStatusCode == NULL) {
00067       return EFI_UNSUPPORTED;
00068     }
00069   }
00070 
00071   //
00072   // A Status Code Protocol is present in the handle database, so pass in all the
00073   // parameters to the ReportStatusCode() service of the Status Code Protocol
00074   //
00075   return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
00076 }
00077 
00078 
00087 UINTN
00088 InternalReportStatusCodeDevicePathSize (
00089   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
00090   )
00091 {
00092   CONST EFI_DEVICE_PATH_PROTOCOL  *Start;
00093 
00094   //
00095   // Search for the end of the device path structure
00096   //
00097   Start = DevicePath;
00098   while (!IsDevicePathEnd (DevicePath)) {
00099     DevicePath = NextDevicePathNode (DevicePath);
00100   }
00101 
00102   //
00103   // Subtract the start node from the end node and add in the size of the end node
00104   //
00105   return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);
00106 }
00107 
00108 
00130 BOOLEAN
00131 EFIAPI
00132 GlueCodeTypeToPostCode (
00133   IN  EFI_STATUS_CODE_TYPE   CodeType,
00134   IN  EFI_STATUS_CODE_VALUE  Value,
00135   OUT UINT8                  *PostCode
00136   )
00137 {
00138   //
00139   // If PostCode is NULL, then ASSERT()
00140   //
00141   ASSERT (PostCode != NULL);
00142 
00143   //
00144   // Convert Value to an 8 bit post code
00145   //
00146   if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||
00147       ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE)       ) {
00148     *PostCode  = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |
00149                           (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));
00150     return TRUE;
00151   }
00152   return FALSE;
00153 }
00154 
00155 
00189 BOOLEAN
00190 EFIAPI
00191 GlueReportStatusCodeExtractAssertInfo (
00192   IN EFI_STATUS_CODE_TYPE        CodeType,
00193   IN EFI_STATUS_CODE_VALUE       Value,
00194   IN CONST EFI_STATUS_CODE_DATA  *Data,
00195   OUT CHAR8                      **Filename,
00196   OUT CHAR8                      **Description,
00197   OUT UINT32                     *LineNumber
00198   )
00199 {
00200   EFI_DEBUG_ASSERT_DATA  *AssertData;
00201 
00202   ASSERT (Data        != NULL);
00203   ASSERT (Filename    != NULL);
00204   ASSERT (Description != NULL);
00205   ASSERT (LineNumber  != NULL);
00206 
00207   if (((CodeType & EFI_STATUS_CODE_TYPE_MASK)      == EFI_ERROR_CODE) &&
00208       ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK)  == EFI_ERROR_UNRECOVERED) &&
00209       ((Value    & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {
00210     AssertData   = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);
00211     *Filename    = (CHAR8 *)(AssertData + 1);
00212     *Description = *Filename + AsciiStrLen (*Filename) + 1;
00213     *LineNumber  = AssertData->LineNumber;
00214     return TRUE;
00215   }
00216   return FALSE;
00217 }
00218 
00219 
00249 BOOLEAN
00250 EFIAPI
00251 GlueReportStatusCodeExtractDebugInfo (
00252   IN CONST EFI_STATUS_CODE_DATA  *Data,
00253   OUT UINT32                     *ErrorLevel,
00254   OUT VA_LIST                    *Marker,
00255   OUT CHAR8                      **Format
00256   )
00257 {
00258   EFI_DEBUG_INFO  *DebugInfo;
00259 
00260   ASSERT (Data       != NULL);
00261   ASSERT (ErrorLevel != NULL);
00262   ASSERT (Marker     != NULL);
00263   ASSERT (Format     != NULL);
00264 
00265   //
00266   // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
00267   //
00268   if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {
00269     return FALSE;
00270   }
00271 
00272   //
00273   // Retrieve the debug information from the status code record
00274   //
00275   DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);
00276 
00277   *ErrorLevel = DebugInfo->ErrorLevel;
00278 
00279   //
00280   // The first 12 * UINTN bytes of the string are really an
00281   // argument stack to support varargs on the Format string.
00282   //
00283 #ifdef __APPLE__
00284   // This is non portable C code you can't assume VA_LIST is pointer
00285   return FALSE;
00286 #else
00287   *Marker = (VA_LIST) (DebugInfo + 1);
00288 #endif
00289   *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);
00290 
00291   return TRUE;
00292 }
00293 
00294 
00316 EFI_STATUS
00317 EFIAPI
00318 GlueReportStatusCode (
00319   IN EFI_STATUS_CODE_TYPE   Type,
00320   IN EFI_STATUS_CODE_VALUE  Value
00321   )
00322 {
00323   return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);
00324 }
00325 
00326 
00355 EFI_STATUS
00356 EFIAPI
00357 GlueReportStatusCodeWithDevicePath (
00358   IN EFI_STATUS_CODE_TYPE            Type,
00359   IN EFI_STATUS_CODE_VALUE           Value,
00360   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
00361   )
00362 {
00363   ASSERT (DevicePath != NULL);
00364   return ReportStatusCodeWithExtendedData (
00365            Type,
00366            Value,
00367            (VOID *)DevicePath,
00368            InternalReportStatusCodeDevicePathSize (DevicePath)
00369            );
00370 }
00371 
00372 
00406 EFI_STATUS
00407 EFIAPI
00408 GlueReportStatusCodeWithExtendedData (
00409   IN EFI_STATUS_CODE_TYPE   Type,
00410   IN EFI_STATUS_CODE_VALUE  Value,
00411   IN CONST VOID             *ExtendedData,
00412   IN UINTN                  ExtendedDataSize
00413   )
00414 {
00415   ASSERT (ExtendedData     != NULL);
00416   ASSERT (ExtendedDataSize != 0);
00417   return ReportStatusCodeEx (
00418            Type,
00419            Value,
00420            0,
00421            NULL,
00422            NULL,
00423            ExtendedData,
00424            ExtendedDataSize
00425            );
00426 }
00427 
00428 
00471 EFI_STATUS
00472 EFIAPI
00473 GlueReportStatusCodeEx (
00474   IN EFI_STATUS_CODE_TYPE   Type,
00475   IN EFI_STATUS_CODE_VALUE  Value,
00476   IN UINT32                 Instance,
00477   IN CONST EFI_GUID         *CallerId          OPTIONAL,
00478   IN CONST EFI_GUID         *ExtendedDataGuid  OPTIONAL,
00479   IN CONST VOID             *ExtendedData      OPTIONAL,
00480   IN UINTN                  ExtendedDataSize
00481   )
00482 {
00483   EFI_STATUS  Status;
00484 
00485   Status = InternalReportStatusCodeEx (
00486              Type,
00487              Value,
00488              Instance,
00489              CallerId,
00490              ExtendedDataGuid,
00491              ExtendedData,
00492              ExtendedDataSize
00493              );
00494 
00495   return Status;
00496 }
00497 
00498 
00511 BOOLEAN
00512 EFIAPI
00513 GlueReportProgressCodeEnabled (
00514   VOID
00515   )
00516 {
00517   return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);
00518 }
00519 
00520 
00533 BOOLEAN
00534 EFIAPI
00535 GlueReportErrorCodeEnabled (
00536   VOID
00537   )
00538 {
00539   return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);
00540 }
00541 
00542 
00555 BOOLEAN
00556 EFIAPI
00557 GlueReportDebugCodeEnabled (
00558   VOID
00559   )
00560 {
00561   return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);
00562 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines