]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
1) Move gEfiStatusCodeDataTypeDebugGuid from the IntelFrameworkPkg to the IntelFramew...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PeiReportStatusCodeLib / ReportStatusCodeLib.c
index cb77d5fe0d566702e7e13eca6664e084394d25bd..de1ee1093670b12393e48f68ab7c6006f7fae73c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Report Status Code Library for DXE Phase.\r
+  Instance of Report Status Code Library for PEI Phase.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include <FrameworkPei.h>\r
 \r
 #include <Guid/StatusCodeDataTypeId.h>\r
+#include <Guid/StatusCodeDataTypeDebug.h>\r
 \r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/OemHookStatusCodeLib.h>\r
 #include <Library/PcdLib.h>\r
 \r
-#include <DebugInfo.h>\r
-\r
 //\r
 // Define the maximum extended data size that is supported in the PEI phase\r
 //\r
 #define MAX_EXTENDED_DATA_SIZE  0x200\r
 \r
 /**\r
-  Internal worker function that reports a status code through the Status Code Protocol\r
+  Internal worker function that reports a status code through the PEI Status Code Service or\r
+  OEM Hook Status Code Library.\r
 \r
-  This function checks to see if a Status Code Protocol is present in the handle\r
-  database.  If a Status Code Protocol is not present, then EFI_UNSUPPORTED is\r
-  returned.  If a Status Code Protocol is present, then it is cached in gStatusCode,\r
-  and the ReportStatusCode() service of the Status Code Protocol is called passing in\r
-  Type, Value, Instance, CallerId, and Data.  The result of this call is returned.\r
+  This function first tries to report status code via PEI Status Code Service. If the service\r
+  is not available, it then tries calling OEM Hook Status Code Library.\r
 \r
   @param  Type              Status code type.\r
   @param  Value             Status code value.\r
   @param  Data              Pointer to the extended data buffer.  This is an\r
                             optional parameter that may be NULL.\r
 \r
-  @retval  EFI_SUCCESS           The status code was reported.\r
-  @retval  EFI_OUT_OF_RESOURCES  There were not enough resources to report the status code.\r
-  @retval  EFI_UNSUPPORTED       Status Code Protocol is not available.\r
+  @retval EFI_SUCCESS       The status code was reported.\r
+  @retval EFI_UNSUPPORTED   Status code type is not supported.\r
+  @retval Others            Failed to report status code.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 InternalReportStatusCode (\r
   IN EFI_STATUS_CODE_TYPE     Type,\r
@@ -64,17 +61,31 @@ InternalReportStatusCode (
   IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL\r
   )\r
 {\r
-  EFI_PEI_SERVICES  **PeiServices;\r
-\r
-  PeiServices = GetPeiServicesTablePointer ();\r
-  return (*PeiServices)->ReportStatusCode (\r
-                           PeiServices,\r
-                           Type,\r
-                           Value,\r
-                           Instance,\r
-                           (EFI_GUID *)CallerId,\r
-                           Data\r
-                           );\r
+  CONST EFI_PEI_SERVICES  **PeiServices;\r
+  EFI_STATUS              Status;\r
+\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
+    PeiServices = GetPeiServicesTablePointer ();\r
+    Status = (*PeiServices)->ReportStatusCode (\r
+                               PeiServices,\r
+                               Type,\r
+                               Value,\r
+                               Instance,\r
+                               (EFI_GUID *)CallerId,\r
+                               Data\r
+                               );\r
+    if (Status == EFI_NOT_AVAILABLE_YET) {\r
+      Status = OemHookStatusCodeInitialize ();\r
+      if (!EFI_ERROR (Status)) {\r
+        return OemHookStatusCodeReport (Type, Value, Instance, (EFI_GUID *) CallerId, Data);\r
+      }\r
+    }\r
+    return Status;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 \r
@@ -116,7 +127,7 @@ CodeTypeToPostCode (
   // Convert Value to an 8 bit post code\r
   //\r
   if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
-      ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE)       ) {\r
+      ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE)) {\r
     *PostCode  = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |\r
                           (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));\r
     return TRUE;\r
@@ -223,7 +234,7 @@ EFIAPI
 ReportStatusCodeExtractDebugInfo (\r
   IN CONST EFI_STATUS_CODE_DATA  *Data,\r
   OUT UINT32                     *ErrorLevel,\r
-  OUT VA_LIST                    *Marker,\r
+  OUT BASE_LIST                  *Marker,\r
   OUT CHAR8                      **Format\r
   )\r
 {\r
@@ -252,7 +263,7 @@ ReportStatusCodeExtractDebugInfo (
   // The first 12 * UINTN bytes of the string are really an\r
   // argument stack to support varargs on the Format string.\r
   //\r
-  *Marker = (VA_LIST) (DebugInfo + 1);\r
+  *Marker = (BASE_LIST) (DebugInfo + 1);\r
   *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
 \r
   return TRUE;\r
@@ -328,6 +339,9 @@ ReportStatusCodeWithDevicePath (
   )\r
 {\r
   ASSERT (DevicePath != NULL);\r
+  //\r
+  // EFI_UNSUPPORTED is returned for device path is not supported in PEI phase.\r
+  //\r
   return EFI_UNSUPPORTED;\r
 }\r
 \r
@@ -444,7 +458,13 @@ ReportStatusCodeEx (
   EFI_STATUS_CODE_DATA  *StatusCodeData;\r
   UINT64                Buffer[MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)];\r
 \r
+  //\r
+  // If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
+  //\r
   ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
+  //\r
+  // If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
+  //\r
   ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
 \r
   if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
@@ -457,7 +477,9 @@ ReportStatusCodeEx (
     ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
   }\r
   CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r
-  CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
+  if (ExtendedData != NULL) {\r
+    CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
+  }\r
   if (CallerId == NULL) {\r
     CallerId = &gEfiCallerIdGuid;\r
   }\r
@@ -483,7 +505,7 @@ ReportProgressCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
 }\r
 \r
 \r
@@ -505,7 +527,7 @@ ReportErrorCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
 }\r
 \r
 \r
@@ -527,5 +549,5 @@ ReportDebugCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
 }\r