@@ -16,15 +16,14 @@ use libc::EFD_NONBLOCK;
1616use vm_superio:: Serial ;
1717use vmm_sys_util:: eventfd:: EventFd ;
1818
19- use crate :: devices:: bus:: BusDevice ;
2019use crate :: devices:: legacy:: serial:: SerialOut ;
21- use crate :: devices:: legacy:: { EventFdTrigger , SerialDevice , SerialEventsWrapper } ;
20+ use crate :: devices:: legacy:: { EventFdTrigger , I8042Device , SerialDevice , SerialEventsWrapper } ;
2221
2322/// Errors corresponding to the `PortIODeviceManager`.
2423#[ derive( Debug , derive_more:: From , thiserror:: Error , displaydoc:: Display ) ]
2524pub enum LegacyDeviceError {
2625 /// Failed to add legacy device to Bus: {0}
27- BusError ( crate :: devices :: BusError ) ,
26+ BusError ( vm_device :: BusError ) ,
2827 /// Failed to create EventFd: {0}
2928 EventFd ( std:: io:: Error ) ,
3029}
@@ -34,11 +33,11 @@ pub enum LegacyDeviceError {
3433/// The `LegacyDeviceManger` should be initialized only by using the constructor.
3534#[ derive( Debug ) ]
3635pub struct PortIODeviceManager {
37- pub io_bus : crate :: devices :: Bus ,
36+ pub io_bus : Arc < vm_device :: Bus > ,
3837 // BusDevice::Serial
39- pub stdio_serial : Arc < Mutex < BusDevice > > ,
38+ pub stdio_serial : Arc < Mutex < SerialDevice > > ,
4039 // BusDevice::I8042Device
41- pub i8042 : Arc < Mutex < BusDevice > > ,
40+ pub i8042 : Arc < Mutex < I8042Device > > ,
4241
4342 // Communication event on ports 1 & 3.
4443 pub com_evt_1_3 : EventFdTrigger ,
@@ -73,29 +72,26 @@ impl PortIODeviceManager {
7372
7473 /// Create a new DeviceManager handling legacy devices (uart, i8042).
7574 pub fn new (
76- serial : Arc < Mutex < BusDevice > > ,
77- i8042_reset_evfd : EventFd ,
75+ stdio_serial : Arc < Mutex < SerialDevice > > ,
76+ i8042 : Arc < Mutex < I8042Device > > ,
7877 ) -> Result < Self , LegacyDeviceError > {
79- debug_assert ! ( matches!( * serial. lock( ) . unwrap( ) , BusDevice :: Serial ( _) ) ) ;
80- let io_bus = crate :: devices:: Bus :: new ( ) ;
81- let com_evt_1_3 = serial
78+ let io_bus = Arc :: new ( vm_device:: Bus :: new ( ) ) ;
79+ let com_evt_1_3 = stdio_serial
8280 . lock ( )
8381 . expect ( "Poisoned lock" )
84- . serial_mut ( )
85- . unwrap ( )
8682 . serial
8783 . interrupt_evt ( )
8884 . try_clone ( ) ?;
8985 let com_evt_2_4 = EventFdTrigger :: new ( EventFd :: new ( EFD_NONBLOCK ) ?) ;
90- let kbd_evt = EventFd :: new ( libc :: EFD_NONBLOCK ) ? ;
91-
92- let i8042 = Arc :: new ( Mutex :: new ( BusDevice :: I8042Device (
93- crate :: devices :: legacy :: I8042Device :: new ( i8042_reset_evfd , kbd_evt . try_clone ( ) ? ) ,
94- ) ) ) ;
86+ let kbd_evt = i8042
87+ . lock ( )
88+ . expect ( "Poisoned lock" )
89+ . kbd_interrupt_evt
90+ . try_clone ( ) ? ;
9591
9692 Ok ( PortIODeviceManager {
9793 io_bus,
98- stdio_serial : serial ,
94+ stdio_serial,
9995 i8042,
10096 com_evt_1_3,
10197 com_evt_2_4,
@@ -105,7 +101,7 @@ impl PortIODeviceManager {
105101
106102 /// Register supported legacy devices.
107103 pub fn register_devices ( & mut self , vm_fd : & VmFd ) -> Result < ( ) , LegacyDeviceError > {
108- let serial_2_4 = Arc :: new ( Mutex :: new ( BusDevice :: Serial ( SerialDevice {
104+ let serial_2_4 = Arc :: new ( Mutex :: new ( SerialDevice {
109105 serial : Serial :: with_events (
110106 self . com_evt_2_4 . try_clone ( ) ?. try_clone ( ) ?,
111107 SerialEventsWrapper {
@@ -114,8 +110,8 @@ impl PortIODeviceManager {
114110 SerialOut :: Sink ( std:: io:: sink ( ) ) ,
115111 ) ,
116112 input : None ,
117- } ) ) ) ;
118- let serial_1_3 = Arc :: new ( Mutex :: new ( BusDevice :: Serial ( SerialDevice {
113+ } ) ) ;
114+ let serial_1_3 = Arc :: new ( Mutex :: new ( SerialDevice {
119115 serial : Serial :: with_events (
120116 self . com_evt_1_3 . try_clone ( ) ?. try_clone ( ) ?,
121117 SerialEventsWrapper {
@@ -124,7 +120,7 @@ impl PortIODeviceManager {
124120 SerialOut :: Sink ( std:: io:: sink ( ) ) ,
125121 ) ,
126122 input : None ,
127- } ) ) ) ;
123+ } ) ) ;
128124 self . io_bus . insert (
129125 self . stdio_serial . clone ( ) ,
130126 Self :: SERIAL_PORT_ADDRESSES [ 0 ] ,
@@ -251,7 +247,7 @@ mod tests {
251247 let ( _, vm) = setup_vm_with_memory ( 0x1000 ) ;
252248 vm. setup_irqchip ( ) . unwrap ( ) ;
253249 let mut ldm = PortIODeviceManager :: new (
254- Arc :: new ( Mutex :: new ( BusDevice :: Serial ( SerialDevice {
250+ Arc :: new ( Mutex :: new ( SerialDevice {
255251 serial : Serial :: with_events (
256252 EventFdTrigger :: new ( EventFd :: new ( EFD_NONBLOCK ) . unwrap ( ) ) ,
257253 SerialEventsWrapper {
@@ -260,8 +256,11 @@ mod tests {
260256 SerialOut :: Sink ( std:: io:: sink ( ) ) ,
261257 ) ,
262258 input : None ,
263- } ) ) ) ,
264- EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ,
259+ } ) ) ,
260+ Arc :: new ( Mutex :: new ( I8042Device :: new (
261+ EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ,
262+ EventFd :: new ( libc:: EFD_NONBLOCK ) . unwrap ( ) ,
263+ ) ) ) ,
265264 )
266265 . unwrap ( ) ;
267266 ldm. register_devices ( vm. fd ( ) ) . unwrap ( ) ;
0 commit comments