#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
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
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
{\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
/** @file\r
- Constructor code for QEMU debug port library.\r
- Non-SEC instance.\r
+ Detection code for QEMU debug port.\r
+ Non-SEC instance, caches the result of detection.\r
\r
Copyright (c) 2017, Red Hat, Inc.<BR>\r
This program and the accompanying materials\r
**/\r
\r
#include <Base.h>\r
+#include "DebugLibDetect.h"\r
+\r
+//\r
+// Set to TRUE if the debug I/O port is enabled\r
+//\r
+STATIC BOOLEAN mDebugIoPortFound = FALSE;\r
\r
/**\r
- This constructor function does not have anything to do.\r
+ This constructor function checks if the debug I/O port device is present,\r
+ caching the result for later use.\r
\r
@retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS.\r
\r
VOID\r
)\r
{\r
+ mDebugIoPortFound = PlatformDebugLibIoPortDetect();\r
return RETURN_SUCCESS;\r
}\r
+\r
+/**\r
+ Return the cached 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
+PlatformDebugLibIoPortFound (\r
+ VOID\r
+ )\r
+{\r
+ return mDebugIoPortFound;\r
+}\r
--- /dev/null
+/** @file\r
+ 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) 2017, 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
+\r
+**/\r
+\r
+#ifndef __DEBUG_IO_PORT_DETECT_H__\r
+#define __DEBUG_IO_PORT_DETECT_H__\r
+\r
+#include <Base.h>\r
+\r
+//\r
+// The constant value that is read from the debug I/O port\r
+//\r
+#define BOCHS_DEBUG_PORT_MAGIC 0xE9\r
+\r
+\r
+/**\r
+ Helper function to return whether the virtual machine has a debug I/O port.\r
+ PlatformDebugLibIoPortFound can call this function directly or cache the\r
+ result.\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
+/**\r
+ Return whether the virtual machine has a debug I/O port. DebugLib.c\r
+ calls this function instead of PlatformDebugLibIoPortDetect, to allow\r
+ caching if possible.\r
+\r
+ @retval TRUE if the debug I/O port device was detected.\r
+ @retval FALSE otherwise\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PlatformDebugLibIoPortFound (\r
+ VOID\r
+ );\r
+\r
+#endif\r
/** @file\r
- Constructor code for QEMU debug port library.\r
- SEC instance.\r
+ Detection code for QEMU debug port.\r
+ SEC instance, cannot cache the result of detection.\r
\r
Copyright (c) 2017, Red Hat, Inc.<BR>\r
This program and the accompanying materials\r
**/\r
\r
#include <Base.h>\r
+#include "DebugLibDetect.h"\r
\r
/**\r
This constructor function does not have anything to do.\r
{\r
return RETURN_SUCCESS;\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
+PlatformDebugLibIoPortFound (\r
+ VOID\r
+ )\r
+{\r
+ return PlatformDebugLibIoPortDetect ();\r
+}\r