[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 6/9] pci.c: factor out while(bus) bus->next loop log
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH 6/9] pci.c: factor out while(bus) bus->next loop logic into pci_find_bus_from(). |
Date: |
Wed, 15 Jul 2009 20:15:06 +0900 |
factor out while(bus) bus->next loop logic into pci_find_bus_from()
which will be used later.
Signed-off-by: Isaku Yamahata <address@hidden>
---
hw/pci.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index 9639a32..f06e1da 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -574,6 +574,16 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr,
uint32_t val, int l)
pci_update_mappings(d);
}
+static PCIBus *pci_find_bus_from(PCIBus *from, int bus_num)
+{
+ PCIBus *s = from;
+
+ while (s && s->bus_num != bus_num)
+ s = s->next;
+
+ return s;
+}
+
void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
{
PCIBus *s = opaque;
@@ -585,8 +595,7 @@ void pci_data_write(void *opaque, uint32_t addr, uint32_t
val, int len)
addr, val, len);
#endif
bus_num = (addr >> 16) & 0xff;
- while (s && s->bus_num != bus_num)
- s = s->next;
+ s = pci_find_bus_from(s, bus_num);
if (!s)
return;
pci_dev = s->devices[(addr >> 8) & 0xff];
@@ -607,8 +616,7 @@ uint32_t pci_data_read(void *opaque, uint32_t addr, int len)
uint32_t val;
bus_num = (addr >> 16) & 0xff;
- while (s && s->bus_num != bus_num)
- s= s->next;
+ s = pci_find_bus_from(s, bus_num);
if (!s)
goto fail;
pci_dev = s->devices[(addr >> 8) & 0xff];
@@ -792,8 +800,7 @@ void pci_for_each_device(int bus_num, void (*fn)(PCIDevice
*d))
PCIDevice *d;
int devfn;
- while (bus && bus->bus_num != bus_num)
- bus = bus->next;
+ bus = pci_find_bus_from(bus, bus_num);
if (bus) {
for(devfn = 0; devfn < 256; devfn++) {
d = bus->devices[devfn];
@@ -891,12 +898,7 @@ static void pci_bridge_write_config(PCIDevice *d,
PCIBus *pci_find_bus(int bus_num)
{
- PCIBus *bus = first_bus;
-
- while (bus && bus->bus_num != bus_num)
- bus = bus->next;
-
- return bus;
+ return pci_find_bus_from(first_bus, bus_num);
}
PCIDevice *pci_find_device(int bus_num, int slot, int function)
--
1.6.0.2
- [Qemu-devel] [PATCH 0/9] pci: pcie host and mmcfg support, Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 4/9] pci: use uint64_t for bar addr and size instead of uint32_t., Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 1/9] pci: fix PCI_DPRINTF() wrt variadic macro., Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 3/9] pci: define a constant to represent a unmapped bar and use it., Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 6/9] pci.c: factor out while(bus) bus->next loop logic into pci_find_bus_from().,
Isaku Yamahata <=
- [Qemu-devel] [PATCH 2/9] pci.c: use appropriate PRIs in PCI_DPRINTF()., Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 9/9] [RFC] pci: pcie host and mmcfg support., Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 8/9] pci_host.h: split non-inline static function in pci_host.h into pci_host_c.h, Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 5/9] pci: 64bit bar support., Isaku Yamahata, 2009/07/15
- [Qemu-devel] [PATCH 7/9] pci: factor out the logic to get pci device from address., Isaku Yamahata, 2009/07/15