]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
Add conditional check before output status code.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / DxeReportStatusCodeLibFramework / ReportStatusCodeLib.c
index 325d9a607d658a8ce38ee04917a75cba199182cc..9e35cdda9083f5e6094099352758d35473437f03 100644 (file)
 \r
 **/\r
 \r
-\r
-#include <FrameworkDxe.h>\r
-\r
-#include <Guid/StatusCodeDataTypeId.h>\r
-#include <Protocol/StatusCode.h>\r
-\r
-#include <Library/ReportStatusCodeLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-\r
-#include <DebugInfo.h>\r
+#include "ReportStatusCodeLibInternal.h"\r
\r
+EFI_REPORT_STATUS_CODE  mReportStatusCode = NULL;\r
 \r
 /**\r
   Internal worker function that reports a status code through the Status Code Protocol\r
@@ -51,7 +39,6 @@
   @retval  EFI_UNSUPPORTED       Status Code Protocol is not available.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 InternalReportStatusCode (\r
   IN EFI_STATUS_CODE_TYPE     Type,\r
@@ -61,33 +48,28 @@ InternalReportStatusCode (
   IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_STATUS_CODE_PROTOCOL      *StatusCode;\r
-  STATIC EFI_REPORT_STATUS_CODE ReportStatusCode = NULL;\r
-\r
-  //\r
-  // If gStatusCode is NULL, then see if a Status Code Protocol instance is present\r
-  // in the handle database.\r
-  //\r
-  if (ReportStatusCode == NULL) {\r
-    if (gBS == NULL) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-    Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCode);\r
-    if (!EFI_ERROR (Status) && StatusCode != NULL) {\r
-      ReportStatusCode = StatusCode->ReportStatusCode;\r
-    } else if (gRT->Hdr.Revision < 0x20000) {\r
-      ReportStatusCode = ((FRAMEWORK_EFI_RUNTIME_SERVICES*)gRT)->ReportStatusCode;\r
-    } else {\r
-      return EFI_UNSUPPORTED;\r
+  if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
+    (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r
+    (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r
+    //\r
+    // If gStatusCode is NULL, then see if a Status Code Protocol instance is present\r
+    // in the handle database.\r
+    //\r
+    if (mReportStatusCode == NULL) {\r
+      mReportStatusCode = InternalGetReportStatusCode ();\r
+      if (mReportStatusCode == NULL) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
     }\r
+  \r
+    //\r
+    // A Status Code Protocol is present in the handle database, so pass in all the\r
+    // parameters to the ReportStatusCode() service of the Status Code Protocol\r
+    //\r
+    return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
   }\r
-\r
-  //\r
-  // A Status Code Protocol is present in the handle database, so pass in all the\r
-  // parameters to the ReportStatusCode() service of the Status Code Protocol\r
-  //\r
-  return (*ReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
+  \r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 \r
@@ -99,7 +81,6 @@ InternalReportStatusCode (
   @return  The size, in bytes, of DevicePath.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 InternalReportStatusCodeDevicePathSize (\r
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
@@ -111,8 +92,8 @@ InternalReportStatusCodeDevicePathSize (
   // Search for the end of the device path structure\r
   //\r
   Start = DevicePath;\r
-  while (!EfiIsDevicePathEnd (DevicePath)) {\r
-    DevicePath = EfiNextDevicePathNode (DevicePath);\r
+  while (!IsDevicePathEnd (DevicePath)) {\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
   }\r
 \r
   //\r
@@ -447,13 +428,14 @@ ReportStatusCodeWithExtendedData (
   is responsible for allocating a buffer large enough for the standard header and\r
   the extended data passed into this function.  The standard header is filled in\r
   with a GUID specified by ExtendedDataGuid.  If ExtendedDataGuid is NULL, then a\r
-  GUID of gEfiStatusCodeSpecificDatauid is used.  The status code is reported with\r
+  GUID of gEfiStatusCodeSpecificDataGuid is used.  The status code is reported with\r
   an instance specified by Instance and a caller ID specified by CallerId.  If\r
   CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
 \r
-  ReportStatusCodeEx()must actively prevent recursion.  If ReportStatusCodeEx()\r
-  is called while processing another any other Report Status Code Library function,\r
-  then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
+  ReportStatusCodeEx()must actively prevent recursion. If\r
+  ReportStatusCodeEx() is called while processing another any\r
+  other Report Status Code Library function, then\r
+  ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
 \r
   If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
   If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
@@ -490,52 +472,17 @@ ReportStatusCodeEx (
   IN UINTN                  ExtendedDataSize\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  EFI_STATUS_CODE_DATA  *StatusCodeData;\r
-\r
-  ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
-  ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
-\r
-  if (gBS == NULL) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Allocate space for the Status Code Header and its buffer\r
-  //\r
-  StatusCodeData = NULL;\r
-  gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
-  if (StatusCodeData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  //\r
-  // Fill in the extended data header\r
-  //\r
-  StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
-  StatusCodeData->Size = (UINT16)ExtendedDataSize;\r
-  if (ExtendedDataGuid == NULL) {\r
-    ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
-  }\r
-  CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r
-\r
-  //\r
-  // Fill in the extended data buffer\r
-  //\r
-  CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
-\r
-  //\r
-  // Report the status code\r
-  //\r
-  if (CallerId == NULL) {\r
-    CallerId = &gEfiCallerIdGuid;\r
-  }\r
-  Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r
-\r
-  //\r
-  // Free the allocated buffer\r
-  //\r
-  gBS->FreePool (StatusCodeData);\r
+  EFI_STATUS  Status;\r
+\r
+  Status = InternalReportStatusCodeEx (\r
+             Type,\r
+             Value,\r
+             Instance,\r
+             CallerId,\r
+             ExtendedDataGuid,\r
+             ExtendedData,\r
+             ExtendedDataSize\r
+             );\r
 \r
   return Status;\r
 }\r