@@ -10,14 +10,11 @@ use std::sync::mpsc;
1010use std:: sync:: { Arc , Mutex } ;
1111
1212use event_manager:: { MutEventSubscriber , SubscriberOps } ;
13- use libc:: EFD_NONBLOCK ;
1413use linux_loader:: cmdline:: Cmdline as LoaderKernelCmdline ;
1514use userfaultfd:: Uffd ;
1615use utils:: time:: TimestampUs ;
1716#[ cfg( target_arch = "aarch64" ) ]
1817use vm_superio:: Rtc ;
19- use vm_superio:: Serial ;
20- use vmm_sys_util:: eventfd:: EventFd ;
2118
2219use crate :: arch:: { ConfigurationError , configure_system_for_boot, load_kernel} ;
2320#[ cfg( target_arch = "aarch64" ) ]
@@ -37,8 +34,8 @@ use crate::devices::BusDevice;
3734use crate :: devices:: acpi:: vmgenid:: { VmGenId , VmGenIdError } ;
3835#[ cfg( target_arch = "aarch64" ) ]
3936use crate :: devices:: legacy:: RTCDevice ;
37+ use crate :: devices:: legacy:: SerialDevice ;
4038use crate :: devices:: legacy:: serial:: SerialOut ;
41- use crate :: devices:: legacy:: { EventFdTrigger , SerialEventsWrapper , SerialWrapper } ;
4239use crate :: devices:: virtio:: balloon:: Balloon ;
4340use crate :: devices:: virtio:: block:: device:: Block ;
4441use crate :: devices:: virtio:: device:: VirtioDevice ;
@@ -158,7 +155,7 @@ fn create_vmm_and_vcpus(
158155 set_stdout_nonblocking ( ) ;
159156
160157 // Serial device setup.
161- let serial_device = setup_serial_device ( event_manager, std :: io :: stdin ( ) , io :: stdout ( ) ) ?;
158+ let serial_device = setup_serial_device ( event_manager) ?;
162159
163160 // x86_64 uses the i8042 reset event as the Vmm exit event.
164161 let reset_evt = vcpus_exit_evt. try_clone ( ) . map_err ( VmmError :: EventFd ) ?;
@@ -532,22 +529,11 @@ pub fn build_microvm_from_snapshot(
532529/// Sets up the serial device.
533530pub fn setup_serial_device (
534531 event_manager : & mut EventManager ,
535- input : std:: io:: Stdin ,
536- out : std:: io:: Stdout ,
537532) -> Result < Arc < Mutex < BusDevice > > , VmmError > {
538- let interrupt_evt = EventFdTrigger :: new ( EventFd :: new ( EFD_NONBLOCK ) . map_err ( VmmError :: EventFd ) ?) ;
539- let kick_stdin_read_evt =
540- EventFdTrigger :: new ( EventFd :: new ( EFD_NONBLOCK ) . map_err ( VmmError :: EventFd ) ?) ;
541- let serial = Arc :: new ( Mutex :: new ( BusDevice :: Serial ( SerialWrapper {
542- serial : Serial :: with_events (
543- interrupt_evt,
544- SerialEventsWrapper {
545- buffer_ready_event_fd : Some ( kick_stdin_read_evt) ,
546- } ,
547- SerialOut :: Stdout ( out) ,
548- ) ,
549- input : Some ( input) ,
550- } ) ) ) ;
533+ let serial = Arc :: new ( Mutex :: new ( BusDevice :: Serial (
534+ SerialDevice :: new ( Some ( std:: io:: stdin ( ) ) , SerialOut :: Stdout ( std:: io:: stdout ( ) ) )
535+ . map_err ( VmmError :: EventFd ) ?,
536+ ) ) ) ;
551537 event_manager. add_subscriber ( serial. clone ( ) ) ;
552538 Ok ( serial)
553539}
@@ -569,7 +555,7 @@ fn attach_legacy_devices_aarch64(
569555 if cmdline_contains_console {
570556 // Make stdout non-blocking.
571557 set_stdout_nonblocking ( ) ;
572- let serial = setup_serial_device ( event_manager, std :: io :: stdin ( ) , std :: io :: stdout ( ) ) ?;
558+ let serial = setup_serial_device ( event_manager) ?;
573559 vmm. mmio_device_manager
574560 . register_mmio_serial ( vmm. vm . fd ( ) , & mut vmm. resource_allocator , serial, None )
575561 . map_err ( VmmError :: RegisterMMIODevice ) ?;
@@ -749,10 +735,12 @@ pub(crate) fn set_stdout_nonblocking() {
749735pub ( crate ) mod tests {
750736
751737 use linux_loader:: cmdline:: Cmdline ;
738+ use vmm_sys_util:: eventfd:: EventFd ;
752739 use vmm_sys_util:: tempfile:: TempFile ;
753740
754741 use super :: * ;
755742 use crate :: device_manager:: resources:: ResourceAllocator ;
743+ use crate :: devices:: legacy:: serial:: SerialOut ;
756744 use crate :: devices:: virtio:: block:: CacheType ;
757745 use crate :: devices:: virtio:: rng:: device:: ENTROPY_DEV_ID ;
758746 use crate :: devices:: virtio:: vsock:: { TYPE_VSOCK , VSOCK_DEV_ID } ;
@@ -829,16 +817,9 @@ pub(crate) mod tests {
829817 let acpi_device_manager = ACPIDeviceManager :: new ( ) ;
830818 #[ cfg( target_arch = "x86_64" ) ]
831819 let pio_device_manager = PortIODeviceManager :: new (
832- Arc :: new ( Mutex :: new ( BusDevice :: Serial ( SerialWrapper {
833- serial : Serial :: with_events (
834- EventFdTrigger :: new ( EventFd :: new ( EFD_NONBLOCK ) . unwrap ( ) ) ,
835- SerialEventsWrapper {
836- buffer_ready_event_fd : None ,
837- } ,
838- SerialOut :: Sink ( std:: io:: sink ( ) ) ,
839- ) ,
840- input : None ,
841- } ) ) ) ,
820+ Arc :: new ( Mutex :: new ( BusDevice :: Serial (
821+ SerialDevice :: new ( None , SerialOut :: Sink ( std:: io:: sink ( ) ) ) . unwrap ( ) ,
822+ ) ) ) ,
842823 EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ,
843824 )
844825 . unwrap ( ) ;
0 commit comments