Introduce XenDebugLibIoPort which is enabled with
DEBUG_ON_HYPERVISOR_CONSOLE which send the debug output to Xen's
console.

It's a copy PlatformDebugLibIoPort which always write to the IO port.
It works with both Xen HVM guest and Xen PVH guest whereas the default
PlatformDebugLibIoPort works only in HVM when QEMU is present.

Signed-off-by: Anthony PERARD <anthony.per...@citrix.com>
---

Notes:
    Do you think it would be better to introduce a PCD to
    PlatformDebugLibIoPort where we can disable the check
    for the debug port and simply always write to it?

 OvmfPkg/OvmfXen.dsc                           | 13 ++++++++++++
 .../PlatformDebugLibIoPort.inf                |  6 +++---
 .../DebugLibDetect.h                          | 20 -------------------
 .../DebugLib.c                                | 16 ---------------
 .../DebugLibDetect.c                          | 20 ++-----------------
 5 files changed, 18 insertions(+), 57 deletions(-)
 copy OvmfPkg/Library/{PlatformDebugLibIoPort => 
XenDebugLibIoPort}/PlatformDebugLibIoPort.inf (76%)
 copy OvmfPkg/Library/{PlatformDebugLibIoPort => 
XenDebugLibIoPort}/DebugLibDetect.h (57%)
 copy OvmfPkg/Library/{PlatformDebugLibIoPort => XenDebugLibIoPort}/DebugLib.c 
(94%)
 copy OvmfPkg/Library/{PlatformDebugLibIoPort => 
XenDebugLibIoPort}/DebugLibDetect.c (61%)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 4859faf1bff7..8e4d70f21fc8 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -205,14 +205,22 @@ [LibraryClasses]
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
   RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
+!ifdef $(DEBUG_ON_HYPERVISOR_CONSOLE)
+  DebugLib|OvmfPkg/Library/XenDebugLibIoPort/PlatformDebugLibIoPort.inf
+!else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+!endif
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
 
 [LibraryClasses.common.SEC]
   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
+!ifdef $(DEBUG_ON_HYPERVISOR_CONSOLE)
+  DebugLib|OvmfPkg/Library/XenDebugLibIoPort/PlatformDebugLibIoPort.inf
+!else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
+!endif
   
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   
ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -405,6 +413,11 @@ [PcdsFixedAtBuild]
   #
 !include NetworkPkg/NetworkPcds.dsc.inc
 
+!ifdef $(DEBUG_ON_HYPERVISOR_CONSOLE)
+  ## This flag is used to control the destination port for 
PlatformDebugLibIoPort
+  gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort|0xe9
+!endif
+
   # IRQs 5, 9, 10, 11 are level-triggered
   gUefiOvmfPkgTokenSpaceGuid.Pcd8259LegacyModeEdgeLevel|0x0E20
 
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf 
b/OvmfPkg/Library/XenDebugLibIoPort/PlatformDebugLibIoPort.inf
similarity index 76%
copy from OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
copy to OvmfPkg/Library/XenDebugLibIoPort/PlatformDebugLibIoPort.inf
index c09f312ffb1d..141fe7498335 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+++ b/OvmfPkg/Library/XenDebugLibIoPort/PlatformDebugLibIoPort.inf
@@ -12,11 +12,11 @@
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = PlatformDebugLibIoPort
-  FILE_GUID                      = DF934DA3-CD31-49FE-AF50-B3C87C79325F
+  BASE_NAME                      = XenDebugLibIoPort
+  FILE_GUID                      = 201EE63F-79DC-4B8E-953C-FA794C0883A3
   MODULE_TYPE                    = BASE
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = DebugLib|PEI_CORE PEIM DXE_CORE DXE_DRIVER 
DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION
+  LIBRARY_CLASS                  = DebugLib|SEC PEI_CORE PEIM DXE_CORE 
DXE_DRIVER DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER 
UEFI_APPLICATION
   CONSTRUCTOR                    = PlatformDebugLibIoPortConstructor
 
 #
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.h 
b/OvmfPkg/Library/XenDebugLibIoPort/DebugLibDetect.h
similarity index 57%
copy from OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.h
copy to OvmfPkg/Library/XenDebugLibIoPort/DebugLibDetect.h
index 71a7f33aaf17..d5ec4063c5be 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.h
+++ b/OvmfPkg/Library/XenDebugLibIoPort/DebugLibDetect.h
@@ -12,26 +12,6 @@
 
 #include <Base.h>
 
-//
-// The constant value that is read from the debug I/O port
-//
-#define BOCHS_DEBUG_PORT_MAGIC    0xE9
-
-
-/**
-  Helper function to return whether the virtual machine has a debug I/O port.
-  PlatformDebugLibIoPortFound can call this function directly or cache the
-  result.
-
-  @retval TRUE   if the debug I/O port device was detected.
-  @retval FALSE  otherwise
-
-**/
-BOOLEAN
-EFIAPI
-PlatformDebugLibIoPortDetect (
-  VOID
-  );
 
 /**
   Return whether the virtual machine has a debug I/O port.  DebugLib.c
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c 
b/OvmfPkg/Library/XenDebugLibIoPort/DebugLib.c
similarity index 94%
copy from OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
copy to OvmfPkg/Library/XenDebugLibIoPort/DebugLib.c
index 3dfa3126c3d0..b3952c9936da 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
+++ b/OvmfPkg/Library/XenDebugLibIoPort/DebugLib.c
@@ -359,19 +359,3 @@ DebugPrintLevelEnabled (
 {
   return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 
0);
 }
-
-/**
-  Return the result of detecting the debug I/O port device.
-
-  @retval TRUE   if the debug I/O port device was detected.
-  @retval FALSE  otherwise
-
-**/
-BOOLEAN
-EFIAPI
-PlatformDebugLibIoPortDetect (
-  VOID
-  )
-{
-  return IoRead8 (PcdGet16 (PcdDebugIoPort)) == BOCHS_DEBUG_PORT_MAGIC;
-}
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c 
b/OvmfPkg/Library/XenDebugLibIoPort/DebugLibDetect.c
similarity index 61%
copy from OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c
copy to OvmfPkg/Library/XenDebugLibIoPort/DebugLibDetect.c
index 2c659e7aea0a..04de924f3fa2 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c
+++ b/OvmfPkg/Library/XenDebugLibIoPort/DebugLibDetect.c
@@ -1,6 +1,5 @@
 /** @file
   Detection code for QEMU debug port.
-  Non-SEC instance, caches the result of detection.
 
   Copyright (c) 2017, Red Hat, Inc.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -10,16 +9,6 @@
 #include <Base.h>
 #include "DebugLibDetect.h"
 
-//
-// Set to TRUE if the debug I/O port has been checked
-//
-STATIC BOOLEAN mDebugIoPortChecked = FALSE;
-
-//
-// Set to TRUE if the debug I/O port is enabled
-//
-STATIC BOOLEAN mDebugIoPortFound = FALSE;
-
 /**
   This constructor function must not do anything.
 
@@ -44,8 +33,7 @@ PlatformDebugLibIoPortConstructor (
 }
 
 /**
-  At the first call, check if the debug I/O port device is present, and cache
-  the result for later use. At subsequent calls, return the cached result.
+  Return the result of detecting the debug I/O port device.
 
   @retval TRUE   if the debug I/O port device was detected.
   @retval FALSE  otherwise
@@ -57,9 +45,5 @@ PlatformDebugLibIoPortFound (
   VOID
   )
 {
-  if (!mDebugIoPortChecked) {
-    mDebugIoPortFound = PlatformDebugLibIoPortDetect ();
-    mDebugIoPortChecked = TRUE;
-  }
-  return mDebugIoPortFound;
+  return TRUE;
 }
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57643): https://edk2.groups.io/g/devel/message/57643
Mute This Topic: https://groups.io/mt/73153294/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to