]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLib.c
index 585f9fb111d70195c488043d8d18a4fe7ec959c1..6895458cf09f6003da437ecec9e562e462238b91 100644 (file)
@@ -1,21 +1,14 @@
 /** @file\r
-  Base Debug library instance for QEMU debug port.\r
+  Base Debug library instance for hypervisor 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
-  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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\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
+#define MAX_DEBUG_MESSAGE_LENGTH  0x200\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
@@ -67,9 +52,40 @@ DebugPrint (
   ...\r
   )\r
 {\r
-  CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
   VA_LIST  Marker;\r
-  UINT8    *Ptr;\r
+\r
+  VA_START (Marker, Format);\r
+  DebugVPrint (ErrorLevel, Format, Marker);\r
+  VA_END (Marker);\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
+  UINTN  Length;\r
 \r
   //\r
   // If Format is NULL, then ASSERT().\r
@@ -77,27 +93,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
+  {\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
+  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
+  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
   Prints an assert message containing a filename, line number, and description.\r
@@ -129,31 +200,37 @@ 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(%d): %a\n", FileName, LineNumber, Description);\r
+  Length = AsciiSPrint (\r
+             Buffer,\r
+             sizeof Buffer,\r
+             "ASSERT %a(%Lu): %a\n",\r
+             FileName,\r
+             (UINT64)LineNumber,\r
+             Description\r
+             );\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
   // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
   //\r
-  if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
+  if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
     CpuBreakpoint ();\r
-  } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
+  } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
     CpuDeadLoop ();\r
   }\r
 }\r
 \r
-\r
 /**\r
   Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
 \r
@@ -182,12 +259,11 @@ DebugClearMemory (
   ASSERT (Buffer != NULL);\r
 \r
   //\r
-  // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
+  // SetMem() checks for the ASSERT() condition on Length and returns Buffer\r
   //\r
-  return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
+  return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if ASSERT() macros are enabled.\r
 \r
@@ -204,10 +280,9 @@ DebugAssertEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG() macros are enabled.\r
 \r
@@ -224,10 +299,9 @@ DebugPrintEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG_CODE() macros are enabled.\r
 \r
@@ -244,10 +318,9 @@ DebugCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
 }\r
 \r
-\r
 /**\r
   Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
 \r
@@ -264,7 +337,7 @@ DebugClearMemoryEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
 }\r
 \r
 /**\r
@@ -279,8 +352,8 @@ DebugClearMemoryEnabled (
 BOOLEAN\r
 EFIAPI\r
 DebugPrintLevelEnabled (\r
-  IN  CONST UINTN        ErrorLevel\r
+  IN  CONST UINTN  ErrorLevel\r
   )\r
 {\r
-  return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r
+  return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);\r
 }\r