File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed
Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -35,13 +35,14 @@ impl PlatData {
3535 let gicr = regs. get ( 1 ) . ok_or ( anyhow ! ( "No GICR reg" ) ) ?;
3636 let plat = self . vdev . new_plat ( ) ;
3737
38- let gic = v3:: VGic :: new (
39- ( gicd. address as usize ) . into ( ) ,
40- ( gicr. address as usize ) . into ( ) ,
41- plat. clone ( ) ,
42- ) ;
43-
44- self . vdev . add_device ( & plat, gic) ;
38+ self . vdev . add_device ( |plat| {
39+ let gic = v3:: VGic :: new (
40+ ( gicd. address as usize ) . into ( ) ,
41+ ( gicr. address as usize ) . into ( ) ,
42+ plat. clone ( ) ,
43+ ) ;
44+ Ok ( gic)
45+ } ) ;
4546
4647 Ok ( ( ) )
4748 }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ pub struct VDevice {
1313}
1414
1515impl VDevice {
16- pub fn new ( id : u32 , raw : impl VirtDeviceOp + ' static ) -> Self {
16+ pub fn new ( id : u32 , raw : impl VirtDeviceOp ) -> Self {
1717 Self {
1818 id,
1919 raw : Arc :: new ( Mutex :: new ( Box :: new ( raw) ) ) ,
@@ -67,12 +67,19 @@ impl VDeviceList {
6767 inner. deivces . get ( & id) . cloned ( )
6868 }
6969
70- pub fn add_device ( & self , plat : & VDevPlat , device : impl VirtDeviceOp + ' static ) -> u32 {
70+ pub fn add_device < F , D > ( & self , builder : F ) -> anyhow:: Result < ( ) >
71+ where
72+ D : VirtDeviceOp ,
73+ F : FnOnce ( & VDevPlat ) -> anyhow:: Result < D > ,
74+ {
75+ let plat = self . new_plat ( ) ;
7176 let id = plat. id ;
77+ let device = builder ( & plat) ?;
7278 let mut inner = self . inner . write ( ) ;
7379 let vdev = VDevice :: new ( id, device) ;
7480 inner. deivces . insert ( id, vdev) ;
75- id
81+
82+ Ok ( ( ) )
7683 }
7784
7885 pub fn handle_mmio_read ( & self , addr : GuestPhysAddr , width : AccessWidth ) -> Option < usize > {
You can’t perform that action at this time.
0 commit comments