From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlFmz-0004EP-40 for qemu-devel@nongnu.org; Fri, 16 May 2014 06:55:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WlFmu-0001aT-0C for qemu-devel@nongnu.org; Fri, 16 May 2014 06:54:57 -0400 Received: from mga01.intel.com ([192.55.52.88]:37873) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlFmt-0001a9-RA for qemu-devel@nongnu.org; Fri, 16 May 2014 06:54:51 -0400 From: Tiejun Chen Date: Fri, 16 May 2014 18:53:37 +0800 Message-Id: <1400237624-8505-2-git-send-email-tiejun.chen@intel.com> In-Reply-To: <1400237624-8505-1-git-send-email-tiejun.chen@intel.com> References: <1400237624-8505-1-git-send-email-tiejun.chen@intel.com> Subject: [Qemu-devel] [v2][PATCH 1/8] pci: use bitmap to manage registe/runregister pci device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, mst@redhat.com, Kelly.Zytaruk@amd.com Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com, weidong.han@intel.com, allen.m.kay@intel.com, qemu-devel@nongnu.org, jean.guyader@eu.citrix.com, anthony@codemonkey.ws, yang.z.zhang@Intel.com It would be convenient to manage devfn directly in some cases. Signed-off-by: Tiejun Chen --- v2: * New patch hw/pci/pci.c | 12 +++++++++++- include/hw/pci/pci_bus.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 22fe5ee..ef944cf 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -36,6 +36,7 @@ #include "hw/pci/msix.h" #include "exec/address-spaces.h" #include "hw/hotplug.h" +#include "qemu/bitmap.h" //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -316,6 +317,12 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent, QLIST_INIT(&bus->child); pci_host_bus_register(bus, parent); + + if (bus->pci_bdf_bitmap) { + g_free(bus->pci_bdf_bitmap); + } + bus->pci_bdf_bitmap = bitmap_new(PCI_SLOT_MAX * PCI_FUNC_MAX); + bitmap_clear(bus->pci_bdf_bitmap, 0, PCI_SLOT_MAX * PCI_FUNC_MAX); } bool pci_bus_is_express(PCIBus *bus) @@ -798,6 +805,7 @@ static void pci_config_free(PCIDevice *pci_dev) static void do_pci_unregister_device(PCIDevice *pci_dev) { + clear_bit(pci_dev->devfn, pci_dev->bus->pci_bdf_bitmap); pci_dev->bus->devices[pci_dev->devfn] = NULL; pci_config_free(pci_dev); @@ -817,8 +825,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, if (devfn < 0) { for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices); devfn += PCI_FUNC_MAX) { - if (!bus->devices[devfn]) + if (!test_bit(devfn, bus->pci_bdf_bitmap)) { goto found; + } } error_report("PCI: no slot/function available for %s, all in use", name); return NULL; @@ -840,6 +849,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, name); pci_dev->devfn = devfn; + set_bit(pci_dev->devfn, pci_dev->bus->pci_bdf_bitmap); pstrcpy(pci_dev->name, sizeof(pci_dev->name), name); pci_dev->irq_state = 0; pci_config_alloc(pci_dev); diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h index fabaeee..f2d8d53 100644 --- a/include/hw/pci/pci_bus.h +++ b/include/hw/pci/pci_bus.h @@ -19,6 +19,7 @@ struct PCIBus { void *irq_opaque; PCIDevice *devices[PCI_SLOT_MAX * PCI_FUNC_MAX]; PCIDevice *parent_dev; + unsigned long *pci_bdf_bitmap; MemoryRegion *address_space_mem; MemoryRegion *address_space_io; -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tiejun Chen Subject: [v2][PATCH 1/8] pci: use bitmap to manage registe/runregister pci device Date: Fri, 16 May 2014 18:53:37 +0800 Message-ID: <1400237624-8505-2-git-send-email-tiejun.chen@intel.com> References: <1400237624-8505-1-git-send-email-tiejun.chen@intel.com> Return-path: In-Reply-To: <1400237624-8505-1-git-send-email-tiejun.chen@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org To: anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, mst@redhat.com, Kelly.Zytaruk@amd.com Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com, weidong.han@intel.com, allen.m.kay@intel.com, qemu-devel@nongnu.org, jean.guyader@eu.citrix.com, anthony@codemonkey.ws, yang.z.zhang@Intel.com List-Id: xen-devel@lists.xenproject.org It would be convenient to manage devfn directly in some cases. Signed-off-by: Tiejun Chen --- v2: * New patch hw/pci/pci.c | 12 +++++++++++- include/hw/pci/pci_bus.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 22fe5ee..ef944cf 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -36,6 +36,7 @@ #include "hw/pci/msix.h" #include "exec/address-spaces.h" #include "hw/hotplug.h" +#include "qemu/bitmap.h" //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -316,6 +317,12 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent, QLIST_INIT(&bus->child); pci_host_bus_register(bus, parent); + + if (bus->pci_bdf_bitmap) { + g_free(bus->pci_bdf_bitmap); + } + bus->pci_bdf_bitmap = bitmap_new(PCI_SLOT_MAX * PCI_FUNC_MAX); + bitmap_clear(bus->pci_bdf_bitmap, 0, PCI_SLOT_MAX * PCI_FUNC_MAX); } bool pci_bus_is_express(PCIBus *bus) @@ -798,6 +805,7 @@ static void pci_config_free(PCIDevice *pci_dev) static void do_pci_unregister_device(PCIDevice *pci_dev) { + clear_bit(pci_dev->devfn, pci_dev->bus->pci_bdf_bitmap); pci_dev->bus->devices[pci_dev->devfn] = NULL; pci_config_free(pci_dev); @@ -817,8 +825,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, if (devfn < 0) { for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices); devfn += PCI_FUNC_MAX) { - if (!bus->devices[devfn]) + if (!test_bit(devfn, bus->pci_bdf_bitmap)) { goto found; + } } error_report("PCI: no slot/function available for %s, all in use", name); return NULL; @@ -840,6 +849,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, name); pci_dev->devfn = devfn; + set_bit(pci_dev->devfn, pci_dev->bus->pci_bdf_bitmap); pstrcpy(pci_dev->name, sizeof(pci_dev->name), name); pci_dev->irq_state = 0; pci_config_alloc(pci_dev); diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h index fabaeee..f2d8d53 100644 --- a/include/hw/pci/pci_bus.h +++ b/include/hw/pci/pci_bus.h @@ -19,6 +19,7 @@ struct PCIBus { void *irq_opaque; PCIDevice *devices[PCI_SLOT_MAX * PCI_FUNC_MAX]; PCIDevice *parent_dev; + unsigned long *pci_bdf_bitmap; MemoryRegion *address_space_mem; MemoryRegion *address_space_io; -- 1.9.1