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

Method allocate_bars

pci/src/vfio.rs:619–821  ·  view source on GitHub ↗
(
        &mut self,
        allocator: &mut SystemAllocator,
        mmio32_allocator: &mut AddressAllocator,
        mmio64_allocator: &mut AddressAllocator,
        resources: Option<&[Resource]>,

Source from the content-addressed store, hash-verified

617 // The `allocator` argument is unused on `aarch64`
618 #[allow(unused_variables)]
619 pub(crate) fn allocate_bars(
620 &mut self,
621 allocator: &mut SystemAllocator,
622 mmio32_allocator: &mut AddressAllocator,
623 mmio64_allocator: &mut AddressAllocator,
624 resources: Option<&[Resource]>,
625 ) -> Result<Vec<PciBarConfiguration>, PciDeviceError> {
626 let mut bars = Vec::new();
627 let mut bar_id = VFIO_PCI_BAR0_REGION_INDEX;
628
629 // Going through all regular regions to compute the BAR size.
630 // We're not saving the BAR address to restore it, because we
631 // are going to allocate a guest address for each BAR and write
632 // that new address back.
633 while bar_id < VFIO_PCI_CONFIG_REGION_INDEX {
634 let mut region_size: u64 = 0;
635 let mut region_type = PciBarRegionType::Memory32BitRegion;
636 let mut prefetchable = PciBarPrefetchable::NotPrefetchable;
637 let mut flags: u32 = 0;
638
639 let mut restored_bar_addr = None;
640 if let Some(resources) = resources {
641 for resource in resources {
642 if let Resource::PciBar {
643 index,
644 base,
645 size,
646 type_,
647 ..
648 } = resource
649 && *index == bar_id as usize
650 {
651 restored_bar_addr = Some(GuestAddress(*base));
652 region_size = *size;
653 region_type = PciBarRegionType::from(*type_);
654 break;
655 }
656 }
657 if restored_bar_addr.is_none() {
658 bar_id += 1;
659 continue;
660 }
661 } else {
662 let bar_offset = if bar_id == VFIO_PCI_ROM_REGION_INDEX {
663 (PCI_ROM_EXP_BAR_INDEX * 4) as u32
664 } else {
665 PCI_CONFIG_BAR_OFFSET + bar_id * 4
666 };
667
668 // First read flags
669 flags = self.vfio_wrapper.read_config_dword(bar_offset);
670
671 // Is this an IO BAR?
672 let io_bar = if bar_id == VFIO_PCI_ROM_REGION_INDEX {
673 false
674 } else {
675 matches!(flags & PCI_CONFIG_IO_BAR, PCI_CONFIG_IO_BAR)
676 };

Callers

nothing calls this directly

Calls 14

newFunction · 0.85
read_config_dwordMethod · 0.80
write_config_dwordMethod · 0.80
allocate_io_addressesMethod · 0.80
allocateMethod · 0.80
fixup_msix_regionMethod · 0.80
set_prefetchableMethod · 0.80
set_region_typeMethod · 0.80
set_sizeMethod · 0.80
set_addressMethod · 0.80
set_indexMethod · 0.80
add_pci_rom_barMethod · 0.80

Tested by

no test coverage detected