]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
OvmfPkg/PlatformDebugLibIoPort: list "DebugLibDetect.h" in the INF files
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLib.c
index 585f9fb111d70195c488043d8d18a4fe7ec959c1..36cde54976d8a78816044cc32c9c732ef180bc18 100644 (file)
@@ -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
 /**\r
   Prints a debug message to the debug output device if the specified error level is enabled.\r
 \r
@@ -69,7 +54,7 @@ DebugPrint (
 {\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,9 +62,10 @@ 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
@@ -87,15 +73,13 @@ DebugPrint (
   // Convert the DEBUG() message to an ASCII String\r
   //\r
   VA_START (Marker, Format);\r
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
+  Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
   VA_END (Marker);\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
@@ -129,18 +113,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(%d): %a\n", FileName, 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
@@ -284,3 +269,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