From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUi4g-0002gY-IA for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:45:54 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUi4e-0002fU-N9 for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:45:53 -0500 Received: from [199.232.76.173] (port=37293 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUi4e-0002fM-EK for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:45:52 -0500 Received: from mx2.redhat.com ([66.187.237.31]:34115) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LUi4d-0000aI-Mt for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:45:52 -0500 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 n14Djput010503 for ; Wed, 4 Feb 2009 08:45:51 -0500 Message-Id: <20090204133923.175155873@localhost.localdomain> References: <20090204133303.113145633@localhost.localdomain> Date: Wed, 04 Feb 2009 11:33:04 -0200 From: Marcelo Tosatti Content-Disposition: inline; filename=pci-helpers Subject: [Qemu-devel] [patch 01/18] qemu: add pci helper functions 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: Marcelo Tosatti Add pci_find_bus/pci_find_device to be used by PCI hotplug. Signed-off-by: Marcelo Tosatti Index: trunk/hw/pci.c =================================================================== --- trunk.orig/hw/pci.c +++ trunk/hw/pci.c @@ -713,6 +713,33 @@ static void pci_bridge_write_config(PCID 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 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, uint16_t vid, uint16_t did, pci_map_irq_fn map_irq, const char *name) { Index: trunk/hw/pci.h =================================================================== --- trunk.orig/hw/pci.h +++ trunk/hw/pci.h @@ -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 @@ void pci_data_write(void *opaque, uint32 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); void pci_info(void); PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, --