From 0066ddefe1ea174af5895cb4b59e577c9c3718ca Mon Sep 17 00:00:00 2001 From: William Douglas Date: Fri, 24 Sep 2021 05:17:51 +0000 Subject: [PATCH] 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 --- devices/src/legacy/serial.rs | 11 +++++++++++ devices/src/legacy/uart_pl011.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/devices/src/legacy/serial.rs b/devices/src/legacy/serial.rs index c6554c770..ff4074a27 100644 --- a/devices/src/legacy/serial.rs +++ b/devices/src/legacy/serial.rs @@ -124,6 +124,10 @@ impl Serial { Self::new(id, interrupt, None) } + pub fn set_out(&mut self, out: Box) { + 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 } diff --git a/devices/src/legacy/uart_pl011.rs b/devices/src/legacy/uart_pl011.rs index e4e2379c7..39e7a1cee 100644 --- a/devices/src/legacy/uart_pl011.rs +++ b/devices/src/legacy/uart_pl011.rs @@ -138,6 +138,10 @@ impl Pl011 { } } + pub fn set_out(&mut self, out: Box) { + 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;