]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/StatusCode/Dxe/SerialStatusCodeWorker.c
Fix EDKT497. In the patch:
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / SerialStatusCodeWorker.c
index e65294f370f9f58e053f5877c491e473cdd72617..0b16dfeadb5d8b562a962a3f5cf4606ca641a8dd 100644 (file)
@@ -2,20 +2,21 @@
 /** @file\r
   Serial I/O status code reporting worker.\r
 \r
-Copyright (c) 2006, Intel Corporation. All rights reserved. \r
-This software and associated documentation (if any) is furnished\r
-under a license and may only be used or copied in accordance\r
-with the terms of the license. Except as permitted by such\r
-license, no part of this software or documentation may be\r
-reproduced, stored in a retrieval system, or transmitted in any\r
-form or by any means without the express written consent of\r
-Intel Corporation.\r
+  Copyright (c) 2006, 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
 \r
   Module Name:  SerialStatusCodeWorker.c\r
 \r
 **/\r
 \r
-EFI_SERIAL_IO_PROTOCOL *SerialIoProtocol;\r
+STATIC\r
+EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;\r
 \r
 /**\r
   Initialize serial status code worker.\r
@@ -31,10 +32,10 @@ EfiSerialStatusCodeInitializeWorker (
   EFI_STATUS Status;\r
 \r
   Status = gBS->LocateProtocol (\r
-            &gEfiSerialIoProtocolGuid,\r
-            NULL,\r
-            (VOID **) &SerialIoProtocol\r
-            );\r
+             &gEfiSerialIoProtocolGuid,\r
+             NULL,\r
+             (VOID **) &mSerialIoProtocol\r
+             );\r
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -45,13 +46,13 @@ EfiSerialStatusCodeInitializeWorker (
 /**\r
   Convert status code value and extended data to readable ASCII string, send string to serial I/O device.\r
  \r
-  @param  CodeType      Indicates the type of status code being reported.  Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.\r
+  @param  CodeType      Indicates the type of status code being reported.  Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
  \r
   @param  Value         Describes the current status of a hardware or software entity.  \r
                         This included information about the class and subclass that is used to classify the entity \r
                         as well as an operation.  For progress codes, the operation is the current activity. \r
                         For error codes, it is the exception.  For debug codes, it is not defined at this time. \r
-                        Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.  \r
+                        Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.  \r
                         Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
  \r
   @param  Instance      The enumeration of a hardware or software entity within the system.  \r
@@ -67,7 +68,8 @@ EfiSerialStatusCodeInitializeWorker (
 \r
   @param  Data          This optional parameter may be used to pass additional data\r
  \r
-  @return               The function always return EFI_SUCCESS.\r
+  @retval EFI_SUCCESS         Success to report status code to serial I/O.\r
+  @retval EFI_DEVICE_ERROR    EFI serial device can not work after ExitBootService() is called .\r
 \r
 **/\r
 EFI_STATUS\r
@@ -88,6 +90,20 @@ SerialStatusCodeReportWorker (
   UINTN           CharCount;\r
   VA_LIST         Marker;\r
   EFI_DEBUG_INFO  *DebugInfo;\r
+  EFI_TPL         CurrentTpl;\r
+\r
+\r
+  if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
+    if (EfiAtRuntime ()) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+    CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);\r
+    gBS->RestoreTPL (CurrentTpl);\r
+\r
+    if (CurrentTpl > EFI_TPL_CALLBACK ) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
 \r
   Buffer[0] = '\0';\r
 \r
@@ -130,10 +146,18 @@ SerialStatusCodeReportWorker (
     //\r
     // Print ERROR information into output buffer.\r
     //\r
-    CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "ERROR: C%x:V%x I%x", CodeType, Value, Instance);\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "ERROR: C%x:V%x I%x", \r
+                  CodeType, \r
+                  Value, \r
+                  Instance\r
+                  );\r
 \r
     //\r
-    // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
+    // Make sure we don't try to print values that weren't \r
+    // intended to be printed, especially NULL GUID pointers.\r
     //\r
     \r
     if (CallerId != NULL) {\r
@@ -145,7 +169,7 @@ SerialStatusCodeReportWorker (
                      );\r
     }\r
 \r
-    if (Data) {\r
+    if (Data != NULL) {\r
       CharCount += AsciiSPrint (\r
                      &Buffer[CharCount - 1],\r
                      (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
@@ -160,9 +184,22 @@ SerialStatusCodeReportWorker (
                    "\n\r"\r
                    );\r
   } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
-    CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "PROGRESS CODE: V%x I%x\n\r", Value, Instance);\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "PROGRESS CODE: V%x I%x\n\r", \r
+                  Value, \r
+                  Instance\r
+                  );\r
   } else {\r
-    CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "Undefined: C%x:V%x I%x\n\r", CodeType, Value, Instance);\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "Undefined: C%x:V%x I%x\n\r", \r
+                  CodeType, \r
+                  Value, \r
+                  Instance\r
+                  );\r
   }\r
 \r
 \r
@@ -173,8 +210,8 @@ SerialStatusCodeReportWorker (
     SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
   }\r
   if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
-    SerialIoProtocol->Write (\r
-      SerialIoProtocol,\r
+    mSerialIoProtocol->Write (\r
+      mSerialIoProtocol,\r
       &CharCount,\r
       Buffer\r
       );\r