@@ -32,6 +32,8 @@ use devices::legacy::Serial;
32
32
use devices:: legacy:: VcpuList ;
33
33
#[ cfg( target_os = "macos" ) ]
34
34
use devices:: legacy:: { GicV3 , HvfGicV3 } ;
35
+ #[ cfg( target_arch = "x86_64" ) ]
36
+ use devices:: legacy:: { IoApic , IrqChipT } ;
35
37
use devices:: legacy:: { IrqChip , IrqChipDevice } ;
36
38
#[ cfg( feature = "net" ) ]
37
39
use devices:: virtio:: Net ;
@@ -664,10 +666,20 @@ pub fn build_microvm(
664
666
// while on aarch64 we need to do it the other way around.
665
667
#[ cfg( target_arch = "x86_64" ) ]
666
668
{
667
- let kvmioapic = KvmIoapic :: new ( vm. fd ( ) ) . map_err ( StartMicrovmError :: CreateKvmIrqChip ) ?;
668
- intc = Arc :: new ( Mutex :: new ( IrqChipDevice :: new ( Box :: new ( kvmioapic) ) ) ) ;
669
+ let ioapic: Box < dyn IrqChipT > = if vm_resources. split_irqchip {
670
+ Box :: new ( IoApic :: new ( vm. fd ( ) , irq_sender) . map_err ( StartMicrovmError :: CreateKvmIrqChip ) ?)
671
+ } else {
672
+ Box :: new ( KvmIoapic :: new ( vm. fd ( ) ) . map_err ( StartMicrovmError :: CreateKvmIrqChip ) ?)
673
+ } ;
674
+ intc = Arc :: new ( Mutex :: new ( IrqChipDevice :: new ( ioapic) ) ) ;
669
675
670
- attach_legacy_devices ( & vm, & mut pio_device_manager) ?;
676
+ attach_legacy_devices (
677
+ & vm,
678
+ vm_resources. split_irqchip ,
679
+ & mut pio_device_manager,
680
+ & mut mmio_device_manager,
681
+ Some ( intc. clone ( ) ) ,
682
+ ) ?;
671
683
672
684
vcpus = create_vcpus_x86_64 (
673
685
& vm,
@@ -1333,13 +1345,23 @@ pub fn setup_serial_device(
1333
1345
#[ cfg( target_arch = "x86_64" ) ]
1334
1346
fn attach_legacy_devices (
1335
1347
vm : & Vm ,
1348
+ split_irqchip : bool ,
1336
1349
pio_device_manager : & mut PortIODeviceManager ,
1350
+ mmio_device_manager : & mut MMIODeviceManager ,
1351
+ intc : Option < Arc < Mutex < IrqChipDevice > > > ,
1337
1352
) -> std:: result:: Result < ( ) , StartMicrovmError > {
1338
1353
pio_device_manager
1339
1354
. register_devices ( )
1340
1355
. map_err ( Error :: LegacyIOBus )
1341
1356
. map_err ( StartMicrovmError :: Internal ) ?;
1342
1357
1358
+ if split_irqchip {
1359
+ mmio_device_manager
1360
+ . register_mmio_ioapic ( intc)
1361
+ . map_err ( Error :: RegisterMMIODevice )
1362
+ . map_err ( StartMicrovmError :: Internal ) ?;
1363
+ }
1364
+
1343
1365
macro_rules! register_irqfd_evt {
1344
1366
( $evt: ident, $index: expr) => { {
1345
1367
vm. fd( )
0 commit comments