Skip to content

patina/serial: add qemu debug console driver - #2018

Open
kraxel wants to merge 8 commits into
OpenDevicePartnership:mainfrom
kraxel:qemudebug
Open

kraxel wants to merge 8 commits into
OpenDevicePartnership:mainfrom
kraxel:qemudebug

Conversation

@kraxel

@kraxel kraxel commented Nov 20, 2026 •

Copy link
Copy Markdown

Description

Add driver for the qemu debug console (-device isa-debugcon).

  • Impacts functionality?

How This Was Tested

kraxel/edk2@4fda393

Call the init function of the serial port used for logging.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Add driver for the qemu debug console (-device isa-debugcon).

The iobase passed to UartQemuDebug::new() must match the iobase
set for the isa-debugcon device.  By convention 0x402 is used
for firmware logging.

Calling init() is mandatory, this will detect whenever the device
is present or not.  Logging happens only in case the device has
been detected.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
@patina-automation

Copy link
Copy Markdown
Contributor

⌛ QEMU Validation Pending

QEMU validation is pending on successful CI completion.

Note: Any previous results are available in this comment's edit history.

This comment was automatically generated by the Patina QEMU PR Validation workflow.

@os-d os-d left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Gerd, thanks for the contribution!

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
sdk/patina/src/peripheral/serial/uart/qemudebug.rs 0.00% 26 Missing ⚠️
sdk/patina/src/debug/log/serial_logger.rs 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

// read value indicating the device is present
const PROBE: u8 = 0xe9;

pub const fn new(io_base: u16) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: (from CI) - public functions need documentation. see: Documenting Quick Reference


use core::arch::asm;

/// qemu debug console

@makubacki makubacki Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll generally want to add a fuller description for public types since the doc comment ends up in published documentation on the type.

For example, these docs for Uart16550 describe some background and safety instructions to supplement the code: https://docs.rs/patina/latest/patina/peripheral/serial/uart/enum.Uart16550.html

This would also be a good place to mention that reading is not supported.

// read value indicating the device is present
const PROBE: u8 = 0xe9;

pub const fn new(io_base: u16) -> Self {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would normally make this unsafe with a SAFETY section like that lists valid I/O port guidance.

Like this from Uart16550::new_io:

    /// # Safety
    ///
    /// The caller must ensure `base` points to a valid Uart16550 I/O port range and that
    /// the caller has the rights to perform the I/O operations on it, for as long as the
    /// returned value is used.


fn outb(&self, value: u8) {
// SAFETY: write output byte to isa-debugcon device
unsafe { asm!("outb %al, %dx", in("al") value, in("dx") self.io_base, options(att_syntax)) }

@cfernald cfernald Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't typically use att_syntax, so considering how minimal this line is, i'd use the default intel syntax.

Additionally, consider adding the nomem, nostack, & preserves_flags to optimize.

// SAFETY: read device detection byte from isa-debugcon device
unsafe {
let ret: u8;
asm!("inb %dx, %al", in("dx") self.io_base, out("al") ret, options(att_syntax));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about att_syntax and other flags

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to advertise that this available in the DXE Core integration example in the mdbook by updating this comment to include UartQemuDebug:

use patina::peripheral::serial::uart::UartNull; // UartPl011 (AARCH64) and Uart16550 (X64) exist

@kraxel

kraxel commented Nov 20, 2026

Copy link
Copy Markdown
Author

Once QE passes I'll go squash all the incremental fixes, probably next week.

@makubacki

makubacki commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

@kraxel, please add unit tests. We can't merge unless code coverage is 80% or higher. You can also disable coverage using #[cfg_attr(coverage, coverage(off))] if there is no value in unit testing it.

@os-d

os-d commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@kraxel, please add unit tests. We can't merge unless code coverage is 80% or higher. You can also disable coverage using #[cfg_attr(coverage, coverage(off))] if there is no value in unit testing it.

Given these are just wrappers around IO port writes, I don't think there is value in testing it and having the module covered with coverage(off) would make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants