From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LtDFb-0008N2-He for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LtDFW-0008Kg-6J for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:26 -0400 Received: from [199.232.76.173] (port=34769 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LtDFW-0008Kb-40 for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:22 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45112) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LtDFV-0000iG-JF for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:21 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3D3sJoD022910 for ; Sun, 12 Apr 2009 23:54:20 -0400 Message-Id: <20090413035340.221112109@amt.cnet> Date: Mon, 13 Apr 2009 00:53:12 -0300 From: Marcelo Tosatti References: <20090413035311.009617911@amt.cnet> Content-Disposition: inline; filename=pci-assign-dev-addr Subject: [Qemu-devel] [patch 1/2] qemu: move pci devfn "first free" assignment to separate function Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster Move pci device address assignment to a separate function. Index: trunk/hw/pci.c =================================================================== --- trunk.orig/hw/pci.c +++ trunk/hw/pci.c @@ -121,6 +121,16 @@ int pci_bus_num(PCIBus *s) return s->bus_num; } +int pci_bus_assign_dev_addr(PCIBus *bus) +{ + int devfn; + + for(devfn = bus->devfn_min ; devfn < 256; devfn += 8) + if (!bus->devices[devfn]) + return devfn; + return -1; +} + void pci_device_save(PCIDevice *s, QEMUFile *f) { int i; @@ -246,14 +256,6 @@ PCIDevice *pci_register_device(PCIBus *b if (pci_irq_index >= PCI_DEVICES_MAX) return NULL; - if (devfn < 0) { - for(devfn = bus->devfn_min ; devfn < 256; devfn += 8) { - if (!bus->devices[devfn]) - goto found; - } - return NULL; - found: ; - } pci_dev = qemu_mallocz(instance_size); pci_dev->bus = bus; pci_dev->devfn = devfn; Index: trunk/hw/pci.h =================================================================== --- trunk.orig/hw/pci.h +++ trunk/hw/pci.h @@ -184,6 +184,7 @@ PCIDevice *pci_nic_init(PCIBus *bus, NIC void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len); uint32_t pci_data_read(void *opaque, uint32_t addr, int len); int pci_bus_num(PCIBus *s); +int pci_bus_assign_dev_addr(PCIBus *bus); void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d)); PCIBus *pci_find_bus(int bus_num); PCIDevice *pci_find_device(int bus_num, int slot, int function);