mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
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:
parent
f9dd0aaf8a
commit
0066ddefe1
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user