/** @file\r
- Detection code for QEMU debug port.\r
+ Detection code for hypervisor 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
- 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 "DebugLibDetect.h"\r
\r
+//\r
+// Set to TRUE if the debug I/O port has been checked\r
+//\r
+STATIC BOOLEAN mDebugIoPortChecked = FALSE;\r
+\r
//\r
// Set to TRUE if the debug I/O port is enabled\r
//\r
-STATIC BOOLEAN mDebugIoPortFound = FALSE;\r
+STATIC BOOLEAN mDebugIoPortFound = FALSE;\r
\r
/**\r
- This constructor function checks if the debug I/O port device is present,\r
- caching the result for later use.\r
+ This constructor function must not do anything.\r
+\r
+ Some modules consuming this library instance, such as the DXE Core, invoke\r
+ the DEBUG() macro before they explicitly call\r
+ ProcessLibraryConstructorList(). Therefore the auto-generated call from\r
+ ProcessLibraryConstructorList() to this constructor function may be preceded\r
+ by some calls to PlatformDebugLibIoPortFound() below. Hence\r
+ PlatformDebugLibIoPortFound() must not rely on anything this constructor\r
+ could set up.\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
+ At the first call, check if the debug I/O port device is present, and cache\r
+ the result for later use. At subsequent calls, return the cached result.\r
\r
@retval TRUE if the debug I/O port device was detected.\r
@retval FALSE otherwise\r
VOID\r
)\r
{\r
+ if (!mDebugIoPortChecked) {\r
+ mDebugIoPortFound = PlatformDebugLibIoPortDetect ();\r
+ mDebugIoPortChecked = TRUE;\r
+ }\r
+\r
return mDebugIoPortFound;\r
}\r