Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LXGsP-0003dq-Tm for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:19:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LXGsP-0003dT-Ex for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:19:49 -0500 Received: from [199.232.76.173] (port=52297 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LXGsP-0003dN-7P for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:19:49 -0500 Received: from savannah.gnu.org ([199.232.41.3]:40230 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LXGsO-00024S-Va for qemu-devel@nongnu.org; Wed, 11 Feb 2009 10:19:49 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LXGsN-0004jz-U9 for qemu-devel@nongnu.org; Wed, 11 Feb 2009 15:19:48 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LXGsN-0004jv-8w for qemu-devel@nongnu.org; Wed, 11 Feb 2009 15:19:47 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Wed, 11 Feb 2009 15:19:47 +0000 Subject: [Qemu-devel] [6592] qemu: add pci helper functions (Marcelo Tosatti) 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 Revision: 6592 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6592 Author: aliguori Date: 2009-02-11 15:19:46 +0000 (Wed, 11 Feb 2009) Log Message: ----------- qemu: add pci helper functions (Marcelo Tosatti) Add pci_find_bus/pci_find_device to be used by PCI hotplug. Signed-off-by: Marcelo Tosatti Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/hw/pci.c trunk/hw/pci.h Modified: trunk/hw/pci.c =================================================================== --- trunk/hw/pci.c 2009-02-11 15:19:16 UTC (rev 6591) +++ trunk/hw/pci.c 2009-02-11 15:19:46 UTC (rev 6592) @@ -711,6 +711,26 @@ pci_default_write_config(d, address, val, len); } +PCIBus *pci_find_bus(int bus_num) +{ + PCIBus *bus = first_bus; + + while (bus && bus->bus_num != bus_num) + bus = bus->next; + + return bus; +} + +PCIDevice *pci_find_device(int bus_num, int slot, int function) +{ + PCIBus *bus = pci_find_bus(bus_num); + + if (!bus) + return NULL; + + return bus->devices[PCI_DEVFN(slot, function)]; +} + PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, pci_map_irq_fn map_irq, const char *name) { Modified: trunk/hw/pci.h =================================================================== --- trunk/hw/pci.h 2009-02-11 15:19:16 UTC (rev 6591) +++ trunk/hw/pci.h 2009-02-11 15:19:46 UTC (rev 6592) @@ -8,6 +8,10 @@ extern target_phys_addr_t pci_mem_base; +#define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) +#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) +#define PCI_FUNC(devfn) ((devfn) & 0x07) + /* Device classes and subclasses */ #define PCI_CLASS_STORAGE_SCSI 0x0100 @@ -222,6 +226,8 @@ uint32_t pci_data_read(void *opaque, uint32_t addr, int len); 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, int function); void pci_info(void); PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,