Repository navigation
patina/serial: add qemu debug console driver #2018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kraxel
wants to merge
8
commits into
OpenDevicePartnership:main
Choose a base branch
from
kraxel:qemudebug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
693f27e
SerialLogger: add init function
kraxel b64bf72
patina/serial: add qemu debug console driver
kraxel 377e4cf
fixup! patina/serial: add qemu debug console driver
kraxel 4dd2507
fixup! patina/serial: add qemu debug console driver
kraxel 2420378
fixup! SerialLogger: add init function
kraxel f4976be
fixup! patina/serial: add qemu debug console driver
kraxel cf8d9a9
fixup! patina/serial: add qemu debug console driver
kraxel 43eba1d
add UartQemuDebug to integration docs
kraxel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //! [`UartQemuDebug`] - [`SerialIO`](crate::peripheral::serial::SerialIO) implementation. | ||
| //! | ||
| //! ## License | ||
| //! | ||
| //! SPDX-License-Identifier: Apache-2.0 | ||
| //! | ||
|
|
||
| use core::arch::asm; | ||
|
|
||
| /// interface for the qemu debug console | ||
| /// | ||
| /// The `isa-debugcon` device logs any data written to the port | ||
| /// specified via `iobase` property. On reads it returns 0xe9. The | ||
| /// latter allows presense detection, it is not possible to actually | ||
| /// read input data, this is a output-only device. | ||
| /// | ||
| /// By convention `iobase=0x402` is used for firmware logging. | ||
| /// | ||
| /// typical usage: | ||
| /// ``` | ||
| /// qemu-system-x86_64 \ | ||
| /// -chardev file,path=/path/to/firmware.log,id=fw \ | ||
| /// -device isa-debugcon,iobase=0x402,chardev=fw \ | ||
|
Check warning on line 23 in sdk/patina/src/peripheral/serial/uart/qemudebug.rs
|
||
| /// $moreargs | ||
| /// ``` | ||
| #[derive(Debug)] | ||
| pub struct UartQemuDebug { | ||
| io_base: u16, | ||
| present: bool, | ||
| } | ||
|
|
||
| impl UartQemuDebug { | ||
| // read value indicating the device is present | ||
| const PROBE: u8 = 0xe9; | ||
|
|
||
| /// create `UartQemuDebug` with io base specified | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must ensure `io_base` points to a valid isa-debugcon io port. | ||
| pub const unsafe fn new(io_base: u16) -> Self { | ||
| Self { io_base, present: false } | ||
| } | ||
|
|
||
| fn outb(&self, value: u8) { | ||
| // SAFETY: write output byte to isa-debugcon device | ||
| unsafe { | ||
| asm!("outb dx, al", in("al") value, in("dx") self.io_base, | ||
| options(nomem,nostack,preserves_flags) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| fn inb(&self) -> u8 { | ||
| // SAFETY: read device detection byte from isa-debugcon device | ||
| unsafe { | ||
| let ret: u8; | ||
| asm!("inb al, dx", in("dx") self.io_base, out("al") ret); | ||
| ret | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl crate::peripheral::serial::SerialIO for UartQemuDebug { | ||
| fn init(&mut self) { | ||
| let value = self.inb(); | ||
| self.present = value == Self::PROBE; | ||
| } | ||
|
|
||
| fn write(&mut self, buffer: &[u8]) { | ||
| if self.present { | ||
| for c in buffer { | ||
| self.outb(*c); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn read(&mut self) -> u8 { | ||
| // PANIC: Would loop forever, better to panic. | ||
| panic!(); | ||
| } | ||
|
|
||
| fn try_read(&mut self) -> Option<u8> { | ||
| None | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:patina/docs/src/integrate/dxe_core.md
Line 370 in 1f69e13