[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [patch 01/18] qemu: add pci helper functions
From: |
Marcelo Tosatti |
Subject: |
Re: [Qemu-devel] [patch 01/18] qemu: add pci helper functions |
Date: |
Fri, 6 Feb 2009 15:35:24 -0200 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Wed, Feb 04, 2009 at 01:15:19PM -0600, Anthony Liguori wrote:
>> This loop is bogus. You already know the devfn from the slot.
>> It's also completely busted if you have multifunction devices.
>>
> It should probably try a bit harder to handle the multifunction case.
> You know your device is bus->devices[slot * 8] but you should also check
> slot * 8 + 1..slot * 8 + 7 to see if there are any sub functions and
> return NULL or something.
qemu: add pci helper functions
Add pci_find_bus/pci_find_device to be used by PCI hotplug.
Signed-off-by: Marcelo Tosatti <address@hidden>
Index: trunk/hw/pci.c
===================================================================
--- trunk.orig/hw/pci.c
+++ trunk/hw/pci.c
@@ -713,6 +713,26 @@ 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 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)
{
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, int function);
void pci_info(void);
PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
- [Qemu-devel] [patch 00/18] acpi pci hotplug support, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 02/18] qemu: return PCIDevice on net device init and record devfn, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 03/18] qemu: dynamic drive/drive_opt index allocation, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 04/18] qemu: dynamic nic info index allocation, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 05/18] qemu: drive removal support, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 06/18] qemu: record devfn on block driver instance, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 07/18] qemu: move drives_opt for external use, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 09/18] qemu: add net_client_uninit / qemu_find_vlan_client, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 08/18] qemu: net/drive add/remove tweaks, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 10/18] qemu: add cpu_unregister_io_memory and make io mem table index dynamic, Marcelo Tosatti, 2009/02/04
- [Qemu-devel] [patch 11/18] qemu: add qemu_free_irqs, Marcelo Tosatti, 2009/02/04