devices: Add utility functions for the serial output buffer

In preparation for reorganizing how the serial output is constructed
add methods to the serial devices for setting the out buffer after the
device is created.

Also add a method to enable flushing the output buffer to be used to
write the buffer to the PTY fd once the PTY is writable.

Signed-off-by: William Douglas <william.douglas@intel.com>
This commit is contained in:
William Douglas 2021-09-24 05:17:51 +00:00 committed by Rob Bradford
parent f9dd0aaf8a
commit 0066ddefe1
2 changed files with 22 additions and 0 deletions

View File

@ -124,6 +124,10 @@ impl Serial {
Self::new(id, interrupt, None)
}
pub fn set_out(&mut self, out: Box<dyn io::Write + Send>) {
self.out = Some(out);
}
/// Queues raw bytes for the guest to read and signals the interrupt if the line status would
/// change.
pub fn queue_input_bytes(&mut self, c: &[u8]) -> Result<()> {
@ -134,6 +138,13 @@ impl Serial {
Ok(())
}
pub fn flush_output(&mut self) -> result::Result<(), io::Error> {
if let Some(out) = self.out.as_mut() {
out.flush()?;
}
Ok(())
}
fn is_dlab_set(&self) -> bool {
(self.line_control & LCR_DLAB_BIT) != 0
}

View File

@ -138,6 +138,10 @@ impl Pl011 {
}
}
pub fn set_out(&mut self, out: Box<dyn io::Write + Send>) {
self.out = Some(out);
}
fn state(&self) -> Pl011State {
Pl011State {
flags: self.flags,
@ -192,6 +196,13 @@ impl Pl011 {
Ok(())
}
pub fn flush_output(&mut self) -> result::Result<(), io::Error> {
if let Some(out) = self.out.as_mut() {
out.flush()?;
}
Ok(())
}
fn pl011_get_baudrate(&self) -> u32 {
if self.fbrd == 0 {
return 0;