]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiDriverLib/ReportStatusCode.c
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / EfiDriverLib / ReportStatusCode.c
index 547c203a832ad9f907deefdfd5f616f860a25bba..e5b84d205a49ca333ad74644fe23ab745079f99c 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -19,12 +19,85 @@ Abstract:
 \r
 #include "Tiano.h"\r
 #include "EfiDriverLib.h"\r
+#include "PeiHob.h"\r
 #include EFI_PROTOCOL_DEFINITION (DevicePath)\r
+#include EFI_GUID_DEFINITION (Hob)\r
 #include EFI_GUID_DEFINITION (StatusCodeDataTypeId)\r
 #include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)\r
 \r
 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-STATIC EFI_STATUS_CODE_PROTOCOL  *gStatusCode = NULL;\r
+\r
+EFI_REPORT_STATUS_CODE gReportStatusCode = NULL;\r
+\r
+VOID\r
+EFIAPI\r
+OnStatusCodeInstall (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_STATUS_CODE_PROTOCOL  *StatusCode;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **) &StatusCode);\r
+  if (!EFI_ERROR (Status)) {\r
+    gReportStatusCode = StatusCode->ReportStatusCode;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+GetPeiProtocol (\r
+  IN EFI_GUID  *ProtocolGuid,\r
+  IN VOID      **Interface\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Searches for a Protocol Interface passed from PEI through a HOB\r
+\r
+Arguments:\r
+\r
+  ProtocolGuid - The Protocol GUID to search for in the HOB List\r
+  Interface    - A pointer to the interface for the Protocol GUID\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - The Protocol GUID was found and its interface is returned in Interface\r
+  EFI_NOT_FOUND - The Protocol GUID was not found in the HOB List\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_PEI_HOB_POINTERS  GuidHob;\r
+\r
+  //\r
+  // Get Hob list\r
+  //\r
+  Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, (VOID **)  &GuidHob.Raw);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {\r
+    if (END_OF_HOB_LIST (GuidHob)) {\r
+      Status = EFI_NOT_FOUND;\r
+      break;\r
+    }\r
+\r
+    if (GET_HOB_TYPE (GuidHob) == EFI_HOB_TYPE_GUID_EXTENSION) {\r
+      if (EfiCompareGuid (ProtocolGuid, &GuidHob.Guid->Name)) {\r
+        Status     = EFI_SUCCESS;\r
+        *Interface = (VOID *) *(UINTN *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID));\r
+      }\r
+    }\r
+\r
+    GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
 #endif\r
 \r
 EFI_STATUS\r
@@ -59,18 +132,28 @@ Returns:
 {\r
   EFI_STATUS  Status;\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000) \r
-  if (gStatusCode == NULL) {\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+  if (gReportStatusCode == NULL) {\r
+    //\r
+    // Because we've installed the protocol notification on EfiStatusCodeRuntimeProtocol,\r
+    //   running here indicates that the StatusCode driver has not started yet.\r
+    //\r
     if (gBS == NULL) {\r
+      //\r
+      // Running here only when StatusCode driver never starts.\r
+      //\r
       return EFI_UNSUPPORTED;\r
     }\r
-    Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
-    if (EFI_ERROR (Status) || gStatusCode == NULL) {\r
+\r
+    //\r
+    // Try to get the PEI version of ReportStatusCode.\r
+    //      \r
+    Status = GetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gReportStatusCode);\r
+    if (EFI_ERROR (Status)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
   }\r
-  Status = gStatusCode->ReportStatusCode (Type, Value, Instance, CallerId, Data);\r
-  return Status;\r
+  Status = gReportStatusCode (Type, Value, Instance, CallerId, Data);\r
 #else\r
   if (gRT == NULL) {\r
     return EFI_UNSUPPORTED;\r
@@ -84,8 +167,8 @@ Returns:
       gRT->ReportStatusCode != NULL) {\r
     Status = gRT->ReportStatusCode (Type, Value, Instance, CallerId, Data);\r
   }\r
-  return Status;\r
 #endif\r
+  return Status;\r
 }\r
 \r
 EFI_STATUS\r