MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / add_pci_device

Method add_pci_device

vmm/src/device_manager.rs:4006–4063  ·  view source on GitHub ↗
(
        &mut self,
        bus_device: Arc<dyn BusDeviceSync>,
        pci_device: Arc<Mutex<dyn PciDevice>>,
        segment_id: u16,
        bdf: PciBdf,
        resources: Option<Vec<Resource>>,

Source from the content-addressed store, hash-verified

4004 }
4005
4006 fn add_pci_device(
4007 &mut self,
4008 bus_device: Arc<dyn BusDeviceSync>,
4009 pci_device: Arc<Mutex<dyn PciDevice>>,
4010 segment_id: u16,
4011 bdf: PciBdf,
4012 resources: Option<Vec<Resource>>,
4013 ) -> DeviceManagerResult<Vec<Resource>> {
4014 let bars = pci_device
4015 .lock()
4016 .unwrap()
4017 .allocate_bars(
4018 &mut self.address_manager.allocator.lock().unwrap(),
4019 &mut self.pci_segments[segment_id as usize]
4020 .mem32_allocator
4021 .lock()
4022 .unwrap(),
4023 &mut self.pci_segments[segment_id as usize]
4024 .mem64_allocator
4025 .lock()
4026 .unwrap(),
4027 resources,
4028 )
4029 .map_err(DeviceManagerError::AllocateBars)?;
4030
4031 let mut pci_bus = self.pci_segments[segment_id as usize]
4032 .pci_bus
4033 .lock()
4034 .unwrap();
4035
4036 pci_bus
4037 .add_device(bdf.device(), pci_device)
4038 .map_err(DeviceManagerError::AddPciDevice)?;
4039
4040 self.bus_devices.push(Arc::clone(&bus_device));
4041
4042 pci_bus
4043 .register_mapping(
4044 bus_device,
4045 self.address_manager.io_bus.as_ref(),
4046 self.address_manager.mmio_bus.as_ref(),
4047 bars.clone(),
4048 )
4049 .map_err(DeviceManagerError::AddPciDevice)?;
4050
4051 let mut new_resources = Vec::new();
4052 for bar in bars {
4053 new_resources.push(Resource::PciBar {
4054 index: bar.idx(),
4055 base: bar.addr(),
4056 size: bar.size(),
4057 type_: bar.region_type().into(),
4058 prefetchable: bar.prefetchable().into(),
4059 });
4060 }
4061
4062 Ok(new_resources)
4063 }

Callers 6

add_vfio_deviceMethod · 0.80
add_vfio_user_deviceMethod · 0.80
add_virtio_pci_deviceMethod · 0.80
add_pvpanic_deviceMethod · 0.80
add_ivshmem_deviceMethod · 0.80

Calls 12

newFunction · 0.85
deviceMethod · 0.80
register_mappingMethod · 0.80
idxMethod · 0.80
region_typeMethod · 0.80
prefetchableMethod · 0.80
allocate_barsMethod · 0.45
add_deviceMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
addrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected