x86 port of Xen lacks vUART facility similar to Arm's vpl011 to support x86
guest OS bring up in the embedded setups.
This patch series introduces initial in-hypervisor emulator for
NS8250/NS16x50-compatible UARTs under CONFIG_VUART_NS16X50.
In parallel domain creation scenario (hyperlaunch), NS16550 emulator helps
early guest firmware and OS bringup debugging, because it eliminates
dependency on the external emulator (qemu) being operational by the time
domains are created.
The emulator also allows to forward the physical console input to the x86
domain which is useful when a system has only one physical UART for early
debugging and this UART is owned by Xen.
By default, CONFIG_VUART_NS16X50 enables emulation of NS16550 at I/O port
0x3f8, IRQ#4 in guest OS (legacy COM1). Legacy COM resources can be selected
at run-time via temporary and undocumented switch 'vuart='.
CONFIG_VUART_NS16X50_DEBUG enables some extra debugging facilities useful
for NS16550 emulator development/debugging (disabled by default).
The NS16550 emulator is disabled in default x86 configuration and goes under
CONFIG_EXPERT in Kconfig.
Note, there's a follow on work for RISC-V which is based on that series:
https://gitlab.com/xen-project/people/olkur/xen/-/tree/riscv-vuart-support-wip?ref_type=heads
Limitations
===========
- Only x86;
- Only legacy COM resources, custom I/O ports/IRQs are not supported;
- Only Xen console as a backend, no inter-domain communication (similar to
vpl011 on Arm);
- Only 8n1 emulation (8-bit data, no parity, 1 stop bit);
- No toolstack integration;
- No baud rate emulation (reports 115200 baud to the guest OS);
- No FIFO-less mode emulation;
- No RX FIFO interrupt moderation (FCR) emulation;
- No integration w/ VM snapshotting (HVM_REGISTER_SAVE_RESTORE() and
friends);
- No MMIO-based UART emulation.
Series
======
Patch 1 introduces the new vUART framework, that is the code originally
posted here:
https://lore.kernel.org/xen-devel/20250624035443.344099-16-dmukhin@ford.com/
Required for emulator.
Patch 2 adds missing NS16550 definitions, required for emulator.
Patches 3-4 introduces the basic emulator skeleton - state machine
initialization stubs, I/O port handler stub, logging, etc.
Patches 5-12 incrementally populate the minimal NS16550 register emulation.
Patch 13 hooks vUART state debugging (disabled by default).
Patch 14-16 adds Kconfig for enabling minimal NS16550 UART (disabled by default).
Patches 17-21 introduce necessary changes to enable NS16550 on dom0 (and PVH).
Patches 22-23 documentation updates. Note, that vuart= setting is not
documented since it will likely change with hyperlanch landing on mainline.
Patches 24-26 tests updates.
Link to CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/3055921295
Link to XTF branch: https://gitlab.com/xen-project/people/dmukhin/xtf/-/commits/emul-16x50
Link to Xen branch: https://gitlab.com/xen-project/people/dmukhin/xen/-/tree/vuart-ns8250-v8?ref_type=heads
Testing
=======
```shell
echo CONFIG_EXPERT=y >> .config
echo CONFIG_VUART_NS16X50=y >> .config
make olddefconfig
```
To test w/ virtual COM2, the guest kernel parameters should contain
something like the following:
earlycon=uart,io,0x2f8,115200n8 console=uart,io,0x2f8,115200n8
Xen command line should have:
vuart=<DOMID>:ns16550,com2
HVM
---
Tested only boot of HVM linux guest with OVMF as the virtual firmware.
SeaBIOS as a virtual firmware is not tested.
Also, HVM is tested via new XTF test:
https://gitlab.com/xen-project/people/dmukhin/xtf/-/commits/emul-16x50
PVH dom0 or domU
----------------
Xen is able to forward physical console input to the domain with virtual
NS16550. To switch the console focus press Ctrl+aaa.
Console switch is limited on x86 to dom0 and Xen.
It is possible to run QEMU-based dom0 + domU test:
- dom0 with emulator:
./automation/scripts/qemu-alpine-x86_64.sh --dom0-type=pvh --dom0-console=ttyS1
- domU with emulator:
./automation/scripts/qemu-alpine-x86_64.sh --dom0-type=pvh --domU-type=pvh --domU-console=ttyS1
Changes since v7:
- Addressed feedback from v7
- Added QEMU tests for PVH guests
- Added XTF tests
- Added initial set of vUART requirements
- Link to v7: https://lore.kernel.org/xen-devel/20250908211149.279143-1-dmukhin@ford.com/
Changes since v6:
- Addressed feedback from v6, mainly DLL, THRE interrupt reason handling and
fixups in vuart.c and ns16x50.c. Also plumbed new temporary swicth 'vuart='
for ease of testing (CI unit test jobs are pending).
- Link to v6: https://lore.kernel.org/xen-devel/20250905232715.440758-1-dmukhin@ford.com/
Changes since v5:
- Split THR/RBR into two separate patches.
- Addressed feedback from v5.
- Link to v5: https://lore.kernel.org/xen-devel/20250828235409.2835815-1-dmukhin@ford.com/
Changes since v4:
- Split the series to make it simpler to review.
- Addressed feedback from v4.
- Dropped xl changes, which I will submit separately.
- Link to v4: https://lore.kernel.org/xen-devel/20250731192130.3948419-1-dmukhin@ford.com/
Changes since v3:
- Reduced the blast radius of the series, thanks to reviews, individual
aspects (like console focus) touched in v3 moved to separate threads.
- Kept the UART emulator framework since I need to redo some of emulator code
and there's more-or-less agreement on it (where to place, naming, scope).
- Applied the feedback from
https://lore.kernel.org/xen-devel/20250624035443.344099-1-dmukhin@ford.com/
- Link to v3: https://lore.kernel.org/xen-devel/20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com/
Changes since v2:
- renamed emulator s/NS8250/NS16550/g
- reduced the patch series after addressing v2 feedback
- introduced driver framework for UART emulators
- unified guest OS printouts across all available UART emulators
- Link to v2: https://lore.kernel.org/xen-devel/20241205-vuart-ns8250-v1-0-e9aa923127eb@ford.com/
Changes since v1:
- dropped kmalloc/kfree aliases
- fixed ECLAIR jobs (thanks Andrew Cooper)
- addressed console forwarding on arm32 and arm64 (thanks to Luca Fancellu)
- moved NS8250 debugging stubs into its own patch
- added fix for https://gitlab.com/xen-project/xen/-/issues/184
- Link to v1: https://lore.kernel.org/r/20241126-vuart-ns8250-v1-v1-0-87b9a8375b7a@ford.com
Ayan Kumar Halder (1):
docs/fusa: add NS16x50 UART requirements for x86
Denis Mukhin (25):
emul/vuart: introduce framework for UART emulators
xen/8250-uart: update definitions
x86: fixup dependencies for asm/x86_emulate.h
emul/ns16x50: implement emulator stub
emul/ns16x50: implement DLL/DLM registers
emul/ns16x50: implement SCR register
emul/ns16x50: implement IER/IIR registers
emul/ns16x50: implement LCR/LSR registers
emul/ns16x50: implement MCR/MSR registers
emul/ns16x50: implement RBR register
emul/ns16x50: implement THR register
emul/ns16x50: implement FCR register (write-only)
emul/ns16550: implement dump_state() hook
emul/vuart: add global UART emulator configuration knob
emul/ns16x50: enable emulator
emul/ns16x50: add Kconfig options
x86/domain: enable per-domain I/O port bitmaps
emul/ns16x50: resolve physical I/O port sharing
xen/domain: allocate d->irq_caps before arch-specific initialization
emul/ns16x50: resolve physical IRQ sharing
emul/ns16x50: implement IRQ emulation via vIOAPIC
MAINTAINERS: add myself as vUART framework maintainer
ci: add initial NS16550-compatible XTF test
ci: add smoke NS16550-compatible PVH Linux test
ci: do not merge: test
MAINTAINERS | 15 +
automation/gitlab-ci/build.yaml | 2 +
automation/gitlab-ci/test.yaml | 37 +-
automation/scripts/include/xtf-runner | 2 +
automation/scripts/include/xtf-x86_64 | 4 +-
automation/scripts/qemu-alpine-x86_64.sh | 325 ++++--
docs/fusa/reqs/design-reqs/x86/ns16x50.rst | 386 +++++++
docs/fusa/reqs/index.rst | 2 +
docs/fusa/reqs/product-reqs/x86/reqs.rst | 24 +
xen/arch/arm/xen.lds.S | 1 +
xen/arch/ppc/xen.lds.S | 1 +
xen/arch/riscv/xen.lds.S | 1 +
xen/arch/x86/Makefile | 1 +
xen/arch/x86/dom0_build.c | 112 +-
xen/arch/x86/hvm/dom0_build.c | 7 +
xen/arch/x86/hvm/hvm.c | 49 +-
xen/arch/x86/hvm/nestedhvm.c | 8 +-
xen/arch/x86/hvm/quirks.c | 3 -
xen/arch/x86/hvm/svm/nestedsvm.c | 2 +-
xen/arch/x86/hvm/vioapic.c | 10 +
xen/arch/x86/hvm/vmx/vvmx.c | 4 +-
xen/arch/x86/include/asm/hvm/nestedhvm.h | 3 +-
xen/arch/x86/include/asm/hvm/support.h | 2 -
xen/arch/x86/include/asm/iocap.h | 3 +
xen/arch/x86/include/asm/irq.h | 8 +
xen/arch/x86/include/asm/x86_emulate.h | 1 +
xen/arch/x86/ioport.c | 168 +++
xen/arch/x86/irq.c | 10 +-
xen/arch/x86/pv/dom0_build.c | 7 +
xen/arch/x86/xen.lds.S | 1 +
xen/common/Kconfig | 2 +
xen/common/Makefile | 1 +
xen/common/domain.c | 8 +-
xen/common/emul/Kconfig | 6 +
xen/common/emul/Makefile | 1 +
xen/common/emul/vuart/Kconfig | 26 +
xen/common/emul/vuart/Makefile | 2 +
xen/common/emul/vuart/ns165x50.c | 0
xen/common/emul/vuart/ns16x50.c | 1135 ++++++++++++++++++++
xen/common/emul/vuart/vuart.c | 266 +++++
xen/common/keyhandler.c | 3 +
xen/drivers/char/console.c | 6 +-
xen/drivers/char/ns16550.c | 16 +-
xen/drivers/passthrough/x86/hvm.c | 11 +-
xen/include/xen/8250-uart.h | 30 +-
xen/include/xen/sched.h | 5 +
xen/include/xen/serial.h | 5 +
xen/include/xen/vuart.h | 121 +++
xen/include/xen/xen.lds.h | 10 +
49 files changed, 2612 insertions(+), 241 deletions(-)
create mode 100644 docs/fusa/reqs/design-reqs/x86/ns16x50.rst
create mode 100644 docs/fusa/reqs/product-reqs/x86/reqs.rst
create mode 100644 xen/arch/x86/ioport.c
create mode 100644 xen/common/emul/Kconfig
create mode 100644 xen/common/emul/Makefile
create mode 100644 xen/common/emul/vuart/Kconfig
create mode 100644 xen/common/emul/vuart/Makefile
create mode 100644 xen/common/emul/vuart/ns165x50.c
create mode 100644 xen/common/emul/vuart/ns16x50.c
create mode 100644 xen/common/emul/vuart/vuart.c
create mode 100644 xen/include/xen/vuart.h
--
2.56.0