@@ -16,15 +16,14 @@ use libc::EFD_NONBLOCK;
16
16
use vm_superio:: Serial ;
17
17
use vmm_sys_util:: eventfd:: EventFd ;
18
18
19
- use crate :: devices:: bus:: BusDevice ;
20
19
use crate :: devices:: legacy:: serial:: SerialOut ;
21
- use crate :: devices:: legacy:: { EventFdTrigger , SerialDevice , SerialEventsWrapper } ;
20
+ use crate :: devices:: legacy:: { EventFdTrigger , I8042Device , SerialDevice , SerialEventsWrapper } ;
22
21
23
22
/// Errors corresponding to the `PortIODeviceManager`.
24
23
#[ derive( Debug , derive_more:: From , thiserror:: Error , displaydoc:: Display ) ]
25
24
pub enum LegacyDeviceError {
26
25
/// Failed to add legacy device to Bus: {0}
27
- BusError ( crate :: devices :: BusError ) ,
26
+ BusError ( vm_device :: BusError ) ,
28
27
/// Failed to create EventFd: {0}
29
28
EventFd ( std:: io:: Error ) ,
30
29
}
@@ -34,11 +33,11 @@ pub enum LegacyDeviceError {
34
33
/// The `LegacyDeviceManger` should be initialized only by using the constructor.
35
34
#[ derive( Debug ) ]
36
35
pub struct PortIODeviceManager {
37
- pub io_bus : crate :: devices :: Bus ,
36
+ pub io_bus : Arc < vm_device :: Bus > ,
38
37
// BusDevice::Serial
39
- pub stdio_serial : Arc < Mutex < BusDevice > > ,
38
+ pub stdio_serial : Arc < Mutex < SerialDevice > > ,
40
39
// BusDevice::I8042Device
41
- pub i8042 : Arc < Mutex < BusDevice > > ,
40
+ pub i8042 : Arc < Mutex < I8042Device > > ,
42
41
43
42
// Communication event on ports 1 & 3.
44
43
pub com_evt_1_3 : EventFdTrigger ,
@@ -73,29 +72,26 @@ impl PortIODeviceManager {
73
72
74
73
/// Create a new DeviceManager handling legacy devices (uart, i8042).
75
74
pub fn new (
76
- serial : Arc < Mutex < BusDevice > > ,
77
- i8042_reset_evfd : EventFd ,
75
+ stdio_serial : Arc < Mutex < SerialDevice > > ,
76
+ i8042 : Arc < Mutex < I8042Device > > ,
78
77
) -> 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
82
80
. lock ( )
83
81
. expect ( "Poisoned lock" )
84
- . serial_mut ( )
85
- . unwrap ( )
86
82
. serial
87
83
. interrupt_evt ( )
88
84
. try_clone ( ) ?;
89
85
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 ( ) ? ;
95
91
96
92
Ok ( PortIODeviceManager {
97
93
io_bus,
98
- stdio_serial : serial ,
94
+ stdio_serial,
99
95
i8042,
100
96
com_evt_1_3,
101
97
com_evt_2_4,
@@ -105,7 +101,7 @@ impl PortIODeviceManager {
105
101
106
102
/// Register supported legacy devices.
107
103
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 {
109
105
serial : Serial :: with_events (
110
106
self . com_evt_2_4 . try_clone ( ) ?. try_clone ( ) ?,
111
107
SerialEventsWrapper {
@@ -114,8 +110,8 @@ impl PortIODeviceManager {
114
110
SerialOut :: Sink ( std:: io:: sink ( ) ) ,
115
111
) ,
116
112
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 {
119
115
serial : Serial :: with_events (
120
116
self . com_evt_1_3 . try_clone ( ) ?. try_clone ( ) ?,
121
117
SerialEventsWrapper {
@@ -124,7 +120,7 @@ impl PortIODeviceManager {
124
120
SerialOut :: Sink ( std:: io:: sink ( ) ) ,
125
121
) ,
126
122
input : None ,
127
- } ) ) ) ;
123
+ } ) ) ;
128
124
self . io_bus . insert (
129
125
self . stdio_serial . clone ( ) ,
130
126
Self :: SERIAL_PORT_ADDRESSES [ 0 ] ,
@@ -251,7 +247,7 @@ mod tests {
251
247
let ( _, vm) = setup_vm_with_memory ( 0x1000 ) ;
252
248
vm. setup_irqchip ( ) . unwrap ( ) ;
253
249
let mut ldm = PortIODeviceManager :: new (
254
- Arc :: new ( Mutex :: new ( BusDevice :: Serial ( SerialDevice {
250
+ Arc :: new ( Mutex :: new ( SerialDevice {
255
251
serial : Serial :: with_events (
256
252
EventFdTrigger :: new ( EventFd :: new ( EFD_NONBLOCK ) . unwrap ( ) ) ,
257
253
SerialEventsWrapper {
@@ -260,8 +256,11 @@ mod tests {
260
256
SerialOut :: Sink ( std:: io:: sink ( ) ) ,
261
257
) ,
262
258
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
+ ) ) ) ,
265
264
)
266
265
. unwrap ( ) ;
267
266
ldm. register_devices ( vm. fd ( ) ) . unwrap ( ) ;
0 commit comments