Revision e075e788

b/hw/pci-hotplug.c
124 124
        if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
125 125
            goto err;
126 126
        }
127
        dev = pci_find_device(pci_find_root_bus(0), pci_bus, slot, 0);
127
        dev = pci_find_device(pci_find_root_bus(dom), pci_bus, slot, 0);
128 128
        if (!dev) {
129 129
            monitor_printf(mon, "no pci device with address %s\n", pci_addr);
130 130
            goto err;
......
252 252

  
253 253
    if (dev) {
254 254
        monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
255
                       0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
255
                       pci_find_domain(dev->bus),
256
                       pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
256 257
                       PCI_FUNC(dev->devfn));
257 258
    } else
258 259
        monitor_printf(mon, "failed to add %s\n", opts);
......
269 270
        return -1;
270 271
    }
271 272

  
272
    d = pci_find_device(pci_find_root_bus(0), bus, slot, 0);
273
    d = pci_find_device(pci_find_root_bus(dom), bus, slot, 0);
273 274
    if (!d) {
274 275
        monitor_printf(mon, "slot %d empty\n", slot);
275 276
        return -1;
b/hw/pci.c
200 200
    return NULL;
201 201
}
202 202

  
203
int pci_find_domain(const PCIBus *bus)
204
{
205
    PCIDevice *d;
206
    struct PCIHostBus *host;
207

  
208
    /* obtain root bus */
209
    while ((d = bus->parent_dev) != NULL) {
210
        bus = d->bus;
211
    }
212

  
213
    QLIST_FOREACH(host, &host_buses, next) {
214
        if (host->bus == bus) {
215
            return host->domain;
216
        }
217
    }
218

  
219
    abort();    /* should not be reached */
220
    return -1;
221
}
222

  
203 223
void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
204 224
                         const char *name, int devfn_min)
205 225
{
......
505 525
    }
506 526

  
507 527
    *devfnp = slot << 3;
508
    return pci_find_bus(pci_find_root_bus(0), bus);
528
    return pci_find_bus(pci_find_root_bus(dom), bus);
509 529
}
510 530

  
511 531
static void pci_init_cmask(PCIDevice *dev)
b/hw/pci.h
218 218
int pci_bus_num(PCIBus *s);
219 219
void pci_for_each_device(PCIBus *bus, int bus_num, void (*fn)(PCIBus *bus, PCIDevice *d));
220 220
PCIBus *pci_find_root_bus(int domain);
221
int pci_find_domain(const PCIBus *bus);
221 222
PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
222 223
PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function);
223 224
PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);

Also available in: Unified diff