From patchwork Fri Mar 16 16:54:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 147222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BEABBB6EE8 for ; Sat, 17 Mar 2012 03:55:34 +1100 (EST) Received: from localhost ([::1]:50013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8aRA-000426-LV for incoming@patchwork.ozlabs.org; Fri, 16 Mar 2012 12:55:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8aQl-0003mU-TN for qemu-devel@nongnu.org; Fri, 16 Mar 2012 12:55:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S8aQg-0004dP-Gq for qemu-devel@nongnu.org; Fri, 16 Mar 2012 12:55:07 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:54617) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8aQg-0004b2-CZ for qemu-devel@nongnu.org; Fri, 16 Mar 2012 12:55:02 -0400 X-IronPort-AV: E=Sophos;i="4.73,599,1325480400"; d="scan'208";a="186300724" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 16 Mar 2012 12:54:58 -0400 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.213.0; Fri, 16 Mar 2012 12:54:58 -0400 Received: from [10.80.3.61] (helo=perard.uk.xensource.com) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1S8aQb-0008HT-R5; Fri, 16 Mar 2012 16:54:57 +0000 From: Anthony PERARD To: QEMU-devel Date: Fri, 16 Mar 2012 16:54:18 +0000 Message-ID: <1331916862-20504-5-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1331916862-20504-1-git-send-email-anthony.perard@citrix.com> References: <1331916862-20504-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Anthony PERARD , Yuji Shimada , Xen Devel , "Michael S . Tsirkin" , Stefano Stabellini Subject: [Qemu-devel] [PATCH V8 RESEND 4/8] pci.c: Add pci_check_bar_overlap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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