]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c
MdeModulePkg/Universal/StatusCodeHandler: Fix a bug about log lost
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / RuntimeDxe / StatusCodeHandlerRuntimeDxe.c
index 497afaa5dc550c4af1c8925cba699fe626a2ddce..d50335af8a19551b7210a516929e2a2ef1f61cd5 100644 (file)
@@ -2,40 +2,28 @@
   Status Code Handler Driver which produces general handlers and hook them\r
   onto the DXE status code router.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation\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
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "StatusCodeHandlerRuntimeDxe.h"\r
 \r
 EFI_EVENT                 mVirtualAddressChangeEvent = NULL;\r
-EFI_EVENT                 mExitBootServicesEvent     = NULL;\r
 EFI_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol       = NULL;\r
 \r
 /**\r
   Unregister status code callback functions only available at boot time from\r
   report status code router when exiting boot services.\r
 \r
-  @param  Event         Event whose notification function is being invoked.\r
-  @param  Context       Pointer to the notification function's context, which is\r
-                        always zero in current implementation.\r
-\r
 **/\r
 VOID\r
 EFIAPI\r
-UnregisterBootTimeHandlers (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
+UnregisterSerialBootTimeHandlers (\r
+  VOID\r
   )\r
 {\r
-  if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
+  if (PcdGetBool (PcdStatusCodeUseSerial)) {\r
     mRscHandlerProtocol->Unregister (SerialStatusCodeReportWorker);\r
   }\r
 }\r
@@ -66,9 +54,9 @@ VirtualAddressChangeCallBack (
 }\r
 \r
 /**\r
-  Dispatch initialization request to sub status code devices based on \r
+  Dispatch initialization request to sub status code devices based on\r
   customized feature flags.\r
\r
+\r
 **/\r
 VOID\r
 InitializationDispatcherWorker (\r
@@ -79,82 +67,67 @@ InitializationDispatcherWorker (
   EFI_STATUS                        Status;\r
   MEMORY_STATUSCODE_PACKET_HEADER   *PacketHeader;\r
   MEMORY_STATUSCODE_RECORD          *Record;\r
-  UINTN                             ExpectedPacketIndex;\r
   UINTN                             Index;\r
-  VOID                              *HobStart;\r
+  UINTN                             MaxRecordNumber;\r
 \r
   //\r
   // If enable UseSerial, then initialize serial port.\r
   // if enable UseRuntimeMemory, then initialize runtime memory status code worker.\r
   //\r
-  if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
+  if (PcdGetBool (PcdStatusCodeUseSerial)) {\r
     //\r
     // Call Serial Port Lib API to initialize serial port.\r
     //\r
     Status = SerialPortInitialize ();\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
-  if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
+  if (PcdGetBool (PcdStatusCodeUseMemory)) {\r
     Status = RtMemoryStatusCodeInitializeWorker ();\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
   //\r
-  // Replay Status code which saved in GUID'ed HOB to all supported devices. \r
+  // Replay Status code which saved in GUID'ed HOB to all supported devices.\r
   //\r
   if (FeaturePcdGet (PcdStatusCodeReplayIn)) {\r
-    // \r
-    // Journal GUID'ed HOBs to find all record entry, if found, \r
+    //\r
+    // Journal GUID'ed HOBs to find all record entry, if found,\r
     // then output record to support replay device.\r
     //\r
-    ExpectedPacketIndex = 0;\r
     Hob.Raw   = GetFirstGuidHob (&gMemoryStatusCodeRecordGuid);\r
-    HobStart  = Hob.Raw;\r
-    while (Hob.Raw != NULL) {\r
+    if (Hob.Raw != NULL) {\r
       PacketHeader = (MEMORY_STATUSCODE_PACKET_HEADER *) GET_GUID_HOB_DATA (Hob.Guid);\r
-      if (PacketHeader->PacketIndex == ExpectedPacketIndex) {\r
-        Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);\r
-        for (Index = 0; Index < PacketHeader->RecordIndex; Index++) {\r
-          //\r
-          // Dispatch records to devices based on feature flag.\r
-          //\r
-          if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
-            SerialStatusCodeReportWorker (\r
-              Record[Index].CodeType,\r
-              Record[Index].Value,\r
-              Record[Index].Instance,\r
-              NULL,\r
-              NULL\r
-              );\r
-          }\r
-          if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
-            RtMemoryStatusCodeReportWorker (\r
-              Record[Index].CodeType,\r
-              Record[Index].Value,\r
-              Record[Index].Instance,\r
-              NULL,\r
-              NULL\r
-              );\r
-          }\r
-        }\r
-        ExpectedPacketIndex++;\r
-  \r
+      Record = (MEMORY_STATUSCODE_RECORD *) (PacketHeader + 1);\r
+      MaxRecordNumber = (UINTN) PacketHeader->RecordIndex;\r
+      if (PacketHeader->PacketIndex > 0) {\r
         //\r
-        // See whether there is gap of packet or not\r
+        // Record has been wrapped around. So, record number has arrived at max number.\r
         //\r
-        if (HobStart != NULL) {\r
-          HobStart  = NULL;\r
-          Hob.Raw   = HobStart;\r
-          continue;\r
-        }\r
-      } else if (HobStart != NULL) {\r
+        MaxRecordNumber = (UINTN) PacketHeader->MaxRecordsNumber;\r
+      }\r
+      for (Index = 0; Index < MaxRecordNumber; Index++) {\r
         //\r
-        // Cache the found packet for improve the performance\r
+        // Dispatch records to devices based on feature flag.\r
         //\r
-        HobStart = Hob.Raw;\r
+        if (PcdGetBool (PcdStatusCodeUseSerial)) {\r
+          SerialStatusCodeReportWorker (\r
+            Record[Index].CodeType,\r
+            Record[Index].Value,\r
+            Record[Index].Instance,\r
+            NULL,\r
+            NULL\r
+            );\r
+        }\r
+        if (PcdGetBool (PcdStatusCodeUseMemory)) {\r
+          RtMemoryStatusCodeReportWorker (\r
+            Record[Index].CodeType,\r
+            Record[Index].Value,\r
+            Record[Index].Instance,\r
+            NULL,\r
+            NULL\r
+            );\r
+        }\r
       }\r
-  \r
-      Hob.Raw = GetNextGuidHob (&gMemoryStatusCodeRecordGuid, Hob.Raw);\r
     }\r
   }\r
 }\r
@@ -167,7 +140,7 @@ InitializationDispatcherWorker (
 \r
   @param  ImageHandle       The firmware allocated handle for the EFI image.\r
   @param  SystemTable       A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
 \r
 **/\r
@@ -192,22 +165,13 @@ StatusCodeHandlerRuntimeDxeEntry (
   //\r
   InitializationDispatcherWorker ();\r
 \r
-  if (FeaturePcdGet (PcdStatusCodeUseSerial)) {\r
+  if (PcdGetBool (PcdStatusCodeUseSerial)) {\r
     mRscHandlerProtocol->Register (SerialStatusCodeReportWorker, TPL_HIGH_LEVEL);\r
   }\r
-  if (FeaturePcdGet (PcdStatusCodeUseMemory)) {\r
+  if (PcdGetBool (PcdStatusCodeUseMemory)) {\r
     mRscHandlerProtocol->Register (RtMemoryStatusCodeReportWorker, TPL_HIGH_LEVEL);\r
   }\r
 \r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  UnregisterBootTimeHandlers,\r
-                  NULL,\r
-                  &gEfiEventExitBootServicesGuid,\r
-                  &mExitBootServicesEvent\r
-                  );\r
-\r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
                   TPL_NOTIFY,\r