]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
OvmfPkg/PlatformDebugLibIoPort: Add new APIs
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLib.c
index 44850a9dbad06117840a703666930f949fdb847a..cda35faf661147180f3269b4dd84ecc2da084141 100644 (file)
@@ -2,7 +2,7 @@
   Base Debug library instance for QEMU debug port.\r
   It uses PrintLib to send debug messages to a fixed I/O port.\r
 \r
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2012, Red Hat, Inc.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -15,7 +15,6 @@
 **/\r
 \r
 #include <Base.h>\r
-#include <Uefi.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugPrintErrorLevelLib.h>\r
+#include "DebugLibDetect.h"\r
 \r
 //\r
 // Define the maximum debug and assert message length that this library supports\r
 //\r
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100\r
 \r
-/**\r
-  This constructor function does not have to do anything.\r
-\r
-  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.\r
-\r
-**/\r
-RETURN_STATUS\r
-EFIAPI\r
-PlatformDebugLibIoPortConstructor (\r
-  VOID\r
-  )\r
-{\r
-  return EFI_SUCCESS;\r
-}\r
+//\r
+// VA_LIST can not initialize to NULL for all compiler, so we use this to\r
+// indicate a null VA_LIST\r
+//\r
+VA_LIST     mVaListNull;\r
 \r
 /**\r
   Prints a debug message to the debug output device if the specified error level is enabled.\r
@@ -66,10 +57,42 @@ DebugPrint (
   IN  CONST CHAR8  *Format,\r
   ...\r
   )\r
+{\r
+  VA_LIST         Marker;\r
+\r
+  VA_START (Marker, Format);\r
+  DebugVPrint (ErrorLevel, Format, Marker);\r
+  VA_END (Marker);\r
+}\r
+\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled base on Null-terminated format string and a\r
+  VA_LIST argument list or a BASE_LIST argument list.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel      The error level of the debug message.\r
+  @param  Format          Format string for the debug message to print.\r
+  @param  VaListMarker    VA_LIST marker for the variable argument list.\r
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+DebugPrintMarker (\r
+  IN  UINTN         ErrorLevel,\r
+  IN  CONST CHAR8   *Format,\r
+  IN  VA_LIST       VaListMarker,\r
+  IN  BASE_LIST     BaseListMarker\r
+  )\r
 {\r
   CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
-  VA_LIST  Marker;\r
-  UINT8    *Ptr;\r
+  UINTN    Length;\r
 \r
   //\r
   // If Format is NULL, then ASSERT().\r
@@ -77,25 +100,82 @@ DebugPrint (
   ASSERT (Format != NULL);\r
 \r
   //\r
-  // Check driver debug mask value and global mask\r
+  // Check if the global mask disables this message or the device is inactive\r
   //\r
-  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r
+  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0 ||\r
+      !PlatformDebugLibIoPortFound ()) {\r
     return;\r
   }\r
 \r
   //\r
   // Convert the DEBUG() message to an ASCII String\r
   //\r
-  VA_START (Marker, Format);\r
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
-  VA_END (Marker);\r
+  if (BaseListMarker == NULL) {\r
+    Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);\r
+  } else {\r
+    Length = AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);\r
+  }\r
 \r
   //\r
   // Send the print string to the debug I/O port\r
   //\r
-  for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r
-    IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r
-  }\r
+  IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
+}\r
+\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel    The error level of the debug message.\r
+  @param  Format        Format string for the debug message to print.\r
+  @param  VaListMarker  VA_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugVPrint (\r
+  IN  UINTN         ErrorLevel,\r
+  IN  CONST CHAR8   *Format,\r
+  IN  VA_LIST       VaListMarker\r
+  )\r
+{\r
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r
+}\r
+\r
+\r
+/**\r
+  Prints a debug message to the debug output device if the specified\r
+  error level is enabled.\r
+  This function use BASE_LIST which would provide a more compatible\r
+  service than VA_LIST.\r
+\r
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r
+  GetDebugPrintErrorLevel (), then print the message specified by Format and\r
+  the associated variable argument list to the debug output device.\r
+\r
+  If Format is NULL, then ASSERT().\r
+\r
+  @param  ErrorLevel      The error level of the debug message.\r
+  @param  Format          Format string for the debug message to print.\r
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DebugBPrint (\r
+  IN  UINTN         ErrorLevel,\r
+  IN  CONST CHAR8   *Format,\r
+  IN  BASE_LIST     BaseListMarker\r
+  )\r
+{\r
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r
 }\r
 \r
 \r
@@ -129,19 +209,19 @@ DebugAssert (
   )\r
 {\r
   CHAR8  Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
-  UINT8 *Ptr;\r
+  UINTN  Length;\r
 \r
   //\r
   // Generate the ASSERT() message in Ascii format\r
   //\r
-  AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n", FileName,\r
-    (UINT64)LineNumber, Description);\r
+  Length = AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n",\r
+             FileName, (UINT64)LineNumber, Description);\r
 \r
   //\r
-  // Send the print string to the Console Output device\r
+  // Send the print string to the debug I/O port, if present\r
   //\r
-  for (Ptr = (UINT8 *) Buffer; *Ptr; Ptr++) {\r
-    IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr);\r
+  if (PlatformDebugLibIoPortFound ()) {\r
+    IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
   }\r
 \r
   //\r
@@ -285,3 +365,19 @@ DebugPrintLevelEnabled (
 {\r
   return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r
 }\r
+\r
+/**\r
+  Return the result of detecting the debug I/O port device.\r
+\r
+  @retval TRUE   if the debug I/O port device was detected.\r
+  @retval FALSE  otherwise\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PlatformDebugLibIoPortDetect (\r
+  VOID\r
+  )\r
+{\r
+  return IoRead8 (PcdGet16 (PcdDebugIoPort)) == BOCHS_DEBUG_PORT_MAGIC;\r
+}\r