]> 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 5a1c86f2c3fda554ff66ba5f3ad847787d511745..36cde54976d8a78816044cc32c9c732ef180bc18 100644 (file)
@@ -22,6 +22,7 @@
 #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
@@ -61,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
@@ -120,9 +122,11 @@ DebugAssert (
              FileName, (UINT64)LineNumber, Description);\r
 \r
   //\r
-  // Send the print string to the debug I/O port\r
+  // Send the print string to the debug I/O port, if present\r
   //\r
-  IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
+  if (PlatformDebugLibIoPortFound ()) {\r
+    IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r
+  }\r
 \r
   //\r
   // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
@@ -265,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