From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2Phl-0007QY-3V for qemu-devel@nongnu.org; Tue, 28 Feb 2012 11:15:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S2Pha-00012t-1o for qemu-devel@nongnu.org; Tue, 28 Feb 2012 11:15:08 -0500 Received: from smtp02.citrix.com ([66.165.176.63]:50411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2PhZ-00012Z-Ss for qemu-devel@nongnu.org; Tue, 28 Feb 2012 11:14:57 -0500 From: Anthony PERARD Date: Tue, 28 Feb 2012 16:14:09 +0000 Message-ID: <1330445653-6030-5-git-send-email-anthony.perard@citrix.com> In-Reply-To: <1330445653-6030-1-git-send-email-anthony.perard@citrix.com> References: <1330445653-6030-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH V8 4/8] pci.c: Add pci_check_bar_overlap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU-devel Cc: Anthony PERARD , Yuji Shimada , Xen Devel , Stefano Stabellini From: Yuji Shimada This function helps Xen PCI Passthrough device to check for overlap. Signed-off-by: Yuji Shimada Signed-off-by: Anthony PERARD --- hw/pci.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pci.h | 5 +++++ 2 files changed, 55 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 38e1de5..f950b4e 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1992,6 +1992,56 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev) return dev->bus->address_space_io; } +/* This function checks if an io_region overlap an io_region from another + * device. The io_region to check is provide with (addr, size and type) + * A callback can be provide and will be called for every region that is + * overlapped. + * The return value indicate if the region is overlappsed */ +bool pci_check_bar_overlap(PCIDevice *device, + pcibus_t addr, pcibus_t size, uint8_t type, + void (*c)(void *o, const PCIDevice *d, int index), + void *opaque) +{ + PCIBus *bus = device->bus; + int i, j; + bool rc = false; + + for (i = 0; i < ARRAY_SIZE(bus->devices); i++) { + PCIDevice *d = bus->devices[i]; + if (!d) { + continue; + } + + if (d->devfn == device->devfn) { + continue; + } + + /* xxx: This ignores bridges. */ + for (j = 0; j < PCI_NUM_REGIONS; j++) { + PCIIORegion *r = &d->io_regions[j]; + + if (!r->size) { + continue; + } + if ((type & PCI_BASE_ADDRESS_SPACE_IO) + != (r->type & PCI_BASE_ADDRESS_SPACE_IO)) { + continue; + } + + if (ranges_overlap(addr, size, r->addr, r->size)) { + if (c) { + c(opaque, d, j); + rc = true; + } else { + return true; + } + } + } + } + + return rc; +} + static void pci_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); diff --git a/hw/pci.h b/hw/pci.h index 4f19fdb..cbd04e1 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -628,4 +628,9 @@ extern const VMStateDescription vmstate_pci_device; .offset = vmstate_offset_pointer(_state, _field, PCIDevice), \ } +bool pci_check_bar_overlap(PCIDevice *dev, + pcibus_t addr, pcibus_t size, uint8_t type, + void (*c)(void *o, const PCIDevice *d, int index), + void *opaque); + #endif -- Anthony PERARD