|
| 1 | +diff --git a/OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.c b/OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.c |
| 2 | +new file mode 100644 |
| 3 | +index 0000000000..4e4f20cf2d |
| 4 | +--- /dev/null |
| 5 | ++++ b/OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.c |
| 6 | +@@ -0,0 +1,160 @@ |
| 7 | ++/** @file |
| 8 | ++ Serial Port Library backed by the QEMU debug console (I/O port 0x402). |
| 9 | ++ |
| 10 | ++ Implements SerialPortLib by writing every byte to the I/O port specified |
| 11 | ++ by PcdDebugIoPort (default 0x402). The port is detected at Initialize |
| 12 | ++ time via the Bochs/QEMU magic read-back value 0xE9. |
| 13 | ++ |
| 14 | ++ Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> |
| 15 | ++ SPDX-License-Identifier: BSD-2-Clause-Patent |
| 16 | ++**/ |
| 17 | ++ |
| 18 | ++#include <Base.h> |
| 19 | ++#include <Library/BaseLib.h> |
| 20 | ++#include <Library/IoLib.h> |
| 21 | ++#include <Library/PcdLib.h> |
| 22 | ++#include <Library/SerialPortLib.h> |
| 23 | ++ |
| 24 | ++#define BOCHS_DEBUG_PORT_MAGIC 0xE9 |
| 25 | ++ |
| 26 | ++STATIC BOOLEAN mDebugConDetected = FALSE; |
| 27 | ++ |
| 28 | ++/** |
| 29 | ++ Initialize the serial device hardware. |
| 30 | ++ |
| 31 | ++ Probes the QEMU debug console port. If the magic value 0xE9 is read |
| 32 | ++ back, the port is considered present. |
| 33 | ++ |
| 34 | ++ @retval RETURN_SUCCESS The debug console port was detected. |
| 35 | ++ @retval RETURN_DEVICE_ERROR The debug console port is not available. |
| 36 | ++**/ |
| 37 | ++RETURN_STATUS |
| 38 | ++EFIAPI |
| 39 | ++SerialPortInitialize ( |
| 40 | ++ VOID |
| 41 | ++ ) |
| 42 | ++{ |
| 43 | ++ UINT16 Port; |
| 44 | ++ |
| 45 | ++ Port = PcdGet16 (PcdDebugIoPort); |
| 46 | ++ if (IoRead8 (Port) == BOCHS_DEBUG_PORT_MAGIC) { |
| 47 | ++ mDebugConDetected = TRUE; |
| 48 | ++ return RETURN_SUCCESS; |
| 49 | ++ } |
| 50 | ++ |
| 51 | ++ return RETURN_DEVICE_ERROR; |
| 52 | ++} |
| 53 | ++ |
| 54 | ++/** |
| 55 | ++ Write data to the QEMU debug console port. |
| 56 | ++ |
| 57 | ++ @param Buffer Pointer to the data buffer to be written. |
| 58 | ++ @param NumberOfBytes Number of bytes to write. |
| 59 | ++ |
| 60 | ++ @retval 0 The debug console port is not present. |
| 61 | ++ @retval >0 The number of bytes written. |
| 62 | ++**/ |
| 63 | ++UINTN |
| 64 | ++EFIAPI |
| 65 | ++SerialPortWrite ( |
| 66 | ++ IN UINT8 *Buffer, |
| 67 | ++ IN UINTN NumberOfBytes |
| 68 | ++ ) |
| 69 | ++{ |
| 70 | ++ UINT16 Port; |
| 71 | ++ UINTN Index; |
| 72 | ++ |
| 73 | ++ if (!mDebugConDetected) { |
| 74 | ++ return 0; |
| 75 | ++ } |
| 76 | ++ |
| 77 | ++ Port = PcdGet16 (PcdDebugIoPort); |
| 78 | ++ for (Index = 0; Index < NumberOfBytes; Index++) { |
| 79 | ++ IoWrite8 (Port, Buffer[Index]); |
| 80 | ++ } |
| 81 | ++ |
| 82 | ++ return NumberOfBytes; |
| 83 | ++} |
| 84 | ++ |
| 85 | ++/** |
| 86 | ++ Read is not supported on the debug console port. |
| 87 | ++ |
| 88 | ++ @param Buffer Pointer to the data buffer to store data. |
| 89 | ++ @param NumberOfBytes Number of bytes to read. |
| 90 | ++ |
| 91 | ++ @retval 0 Always returns 0 (not supported). |
| 92 | ++**/ |
| 93 | ++UINTN |
| 94 | ++EFIAPI |
| 95 | ++SerialPortRead ( |
| 96 | ++ OUT UINT8 *Buffer, |
| 97 | ++ IN UINTN NumberOfBytes |
| 98 | ++ ) |
| 99 | ++{ |
| 100 | ++ return 0; |
| 101 | ++} |
| 102 | ++ |
| 103 | ++/** |
| 104 | ++ Polling is not supported on the debug console port. |
| 105 | ++ |
| 106 | ++ @retval FALSE Always returns FALSE. |
| 107 | ++**/ |
| 108 | ++BOOLEAN |
| 109 | ++EFIAPI |
| 110 | ++SerialPortPoll ( |
| 111 | ++ VOID |
| 112 | ++ ) |
| 113 | ++{ |
| 114 | ++ return FALSE; |
| 115 | ++} |
| 116 | ++ |
| 117 | ++/** |
| 118 | ++ Set control bits — not supported. |
| 119 | ++ |
| 120 | ++ @param Control Control bits to set. |
| 121 | ++ |
| 122 | ++ @retval RETURN_UNSUPPORTED Always. |
| 123 | ++**/ |
| 124 | ++RETURN_STATUS |
| 125 | ++EFIAPI |
| 126 | ++SerialPortSetControl ( |
| 127 | ++ IN UINT32 Control |
| 128 | ++ ) |
| 129 | ++{ |
| 130 | ++ return RETURN_UNSUPPORTED; |
| 131 | ++} |
| 132 | ++ |
| 133 | ++/** |
| 134 | ++ Get control bits — not supported. |
| 135 | ++ |
| 136 | ++ @param Control Pointer to receive control signals. |
| 137 | ++ |
| 138 | ++ @retval RETURN_UNSUPPORTED Always. |
| 139 | ++**/ |
| 140 | ++RETURN_STATUS |
| 141 | ++EFIAPI |
| 142 | ++SerialPortGetControl ( |
| 143 | ++ OUT UINT32 *Control |
| 144 | ++ ) |
| 145 | ++{ |
| 146 | ++ return RETURN_UNSUPPORTED; |
| 147 | ++} |
| 148 | ++ |
| 149 | ++/** |
| 150 | ++ Set serial attributes — not supported. |
| 151 | ++ |
| 152 | ++ @retval RETURN_UNSUPPORTED Always. |
| 153 | ++**/ |
| 154 | ++RETURN_STATUS |
| 155 | ++EFIAPI |
| 156 | ++SerialPortSetAttributes ( |
| 157 | ++ IN OUT UINT64 *BaudRate, |
| 158 | ++ IN OUT UINT32 *ReceiveFifoDepth, |
| 159 | ++ IN OUT UINT32 *Timeout, |
| 160 | ++ IN OUT EFI_PARITY_TYPE *Parity, |
| 161 | ++ IN OUT UINT8 *DataBits, |
| 162 | ++ IN OUT EFI_STOP_BITS_TYPE *StopBits |
| 163 | ++ ) |
| 164 | ++{ |
| 165 | ++ return RETURN_UNSUPPORTED; |
| 166 | ++} |
| 167 | +diff --git a/OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.inf b/OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.inf |
| 168 | +new file mode 100644 |
| 169 | +index 0000000000..8b506f9020 |
| 170 | +--- /dev/null |
| 171 | ++++ b/OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.inf |
| 172 | +@@ -0,0 +1,34 @@ |
| 173 | ++## @file |
| 174 | ++# Serial Port Library backed by the QEMU debug console (I/O port 0x402). |
| 175 | ++# |
| 176 | ++# This library instance implements SerialPortLib by writing bytes to the |
| 177 | ++# I/O port configured via PcdDebugIoPort. It can be used together with |
| 178 | ++# BaseDebugLibSerialPort to route DEBUG() output to the QEMU debug console. |
| 179 | ++# |
| 180 | ++# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> |
| 181 | ++# SPDX-License-Identifier: BSD-2-Clause-Patent |
| 182 | ++# |
| 183 | ++## |
| 184 | ++ |
| 185 | ++[Defines] |
| 186 | ++ INF_VERSION = 0x00010005 |
| 187 | ++ BASE_NAME = BaseSerialPortLibDebugCon |
| 188 | ++ FILE_GUID = 53A6F6C9-3297-4A36-95E0-68C5D2A4EA1F |
| 189 | ++ MODULE_TYPE = BASE |
| 190 | ++ VERSION_STRING = 1.0 |
| 191 | ++ LIBRARY_CLASS = SerialPortLib |
| 192 | ++ |
| 193 | ++[Sources] |
| 194 | ++ BaseSerialPortLibDebugCon.c |
| 195 | ++ |
| 196 | ++[Packages] |
| 197 | ++ MdePkg/MdePkg.dec |
| 198 | ++ OvmfPkg/OvmfPkg.dec |
| 199 | ++ |
| 200 | ++[LibraryClasses] |
| 201 | ++ BaseLib |
| 202 | ++ IoLib |
| 203 | ++ PcdLib |
| 204 | ++ |
| 205 | ++[Pcd] |
| 206 | ++ gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES |
| 207 | +diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc |
| 208 | +index 7ab6af3a69..b986ab13b5 100644 |
| 209 | +--- a/OvmfPkg/OvmfPkgIa32.dsc |
| 210 | ++++ b/OvmfPkg/OvmfPkgIa32.dsc |
| 211 | +@@ -165,7 +165,11 @@ |
| 212 | + CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf |
| 213 | + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |
| 214 | + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf |
| 215 | ++!ifdef $(DEBUG_ON_SERIAL_PORT) |
| 216 | + SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf |
| 217 | ++!else |
| 218 | ++ SerialPortLib|OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.inf |
| 219 | ++!endif |
| 220 | + MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf |
| 221 | + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf |
| 222 | + CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf |
| 223 | +diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc |
| 224 | +index e7fff78df9..a2535b548a 100644 |
| 225 | +--- a/OvmfPkg/OvmfPkgIa32X64.dsc |
| 226 | ++++ b/OvmfPkg/OvmfPkgIa32X64.dsc |
| 227 | +@@ -170,7 +170,11 @@ |
| 228 | + CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf |
| 229 | + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |
| 230 | + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf |
| 231 | ++!ifdef $(DEBUG_ON_SERIAL_PORT) |
| 232 | + SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf |
| 233 | ++!else |
| 234 | ++ SerialPortLib|OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.inf |
| 235 | ++!endif |
| 236 | + MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf |
| 237 | + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf |
| 238 | + CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf |
| 239 | +diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc |
| 240 | +index 556984bdaa..51e8fe2789 100644 |
| 241 | +--- a/OvmfPkg/OvmfPkgX64.dsc |
| 242 | ++++ b/OvmfPkg/OvmfPkgX64.dsc |
| 243 | +@@ -182,7 +182,11 @@ |
| 244 | + PciCapPciIoLib|OvmfPkg/Library/UefiPciCapPciIoLib/UefiPciCapPciIoLib.inf |
| 245 | + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf |
| 246 | + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf |
| 247 | ++!ifdef $(DEBUG_ON_SERIAL_PORT) |
| 248 | + SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf |
| 249 | ++!else |
| 250 | ++ SerialPortLib|OvmfPkg/Library/BaseSerialPortLibDebugCon/BaseSerialPortLibDebugCon.inf |
| 251 | ++!endif |
| 252 | + MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf |
| 253 | + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf |
| 254 | + CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf |
0 commit comments