[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [v2][PATCH 1/8] pci: use bitmap to manage registe/runregister pci device



It would be convenient to manage devfn directly in some cases.

Signed-off-by: Tiejun Chen <tiejun.chen@xxxxxxxxx>
---
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


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.