From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JZAtm-0007ee-Az for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JZAtl-0007ds-LX for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:33 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JZAtl-0007de-Dx for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:33 -0400 Received: from mx1.redhat.com ([66.187.233.31]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JZAtl-00047N-0R for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:33 -0400 Message-Id: <20080311201418.322848308@localhost.localdomain> References: <20080311201151.959635433@localhost.localdomain> Date: Tue, 11 Mar 2008 17:12:05 -0300 From: Marcelo Tosatti Content-Disposition: inline; filename=pci-find-device Subject: [Qemu-devel] [patch 14/24] QEMU/KVM: add pci_find_device 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, kvm-devel@lists.sourceforge.net Cc: aliguori@us.ibm.com, Marcelo Tosatti Return PCIDevice from bus number and slot. Signed-off-by: Marcelo Tosatti Index: kvm-userspace.hotplug/qemu/hw/pci.c =================================================================== --- kvm-userspace.hotplug.orig/qemu/hw/pci.c +++ kvm-userspace.hotplug/qemu/hw/pci.c @@ -689,6 +689,23 @@ PCIBus *pci_find_bus(int bus_num) return bus; } +PCIDevice *pci_find_device(int bus_num, int slot) +{ + int devfn; + PCIDevice *d; + PCIBus *bus = pci_find_bus(bus_num); + + if (!bus) + return NULL; + + for(devfn = 0; devfn < 256; devfn++) { + d = bus->devices[devfn]; + if (d && PCI_SLOT(devfn) == slot) + return d; + } + return NULL; +} + PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint32_t id, pci_map_irq_fn map_irq, const char *name) { Index: kvm-userspace.hotplug/qemu/hw/pci.h =================================================================== --- kvm-userspace.hotplug.orig/qemu/hw/pci.h +++ kvm-userspace.hotplug/qemu/hw/pci.h @@ -93,6 +93,7 @@ uint32_t pci_data_read(void *opaque, uin int pci_bus_num(PCIBus *s); 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); void pci_info(void); PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint32_t id, --