Set the ISA Bus link property on the PIIX IDE object from the two unique users, the PC machine and the PIIX4 function.
Add a check in pci_piix_ide_realize() to be sure this property is set. Signed-off-by: Philippe Mathieu-Daudé <phi...@redhat.com> --- hw/i386/pc_piix.c | 2 ++ hw/ide/piix.c | 5 +++++ hw/isa/piix4.c | 10 +++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index fb606c14768..d799c8004df 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -246,6 +246,8 @@ static void pc_init1(MachineState *machine, dev = pci_new(piix3_devfn + 1, xen_enabled() ? "piix3-ide-xen" : "piix3-ide"); + object_property_set_link(OBJECT(dev), "isa-bus", + OBJECT(isa_bus), &error_abort); pci_realize_and_unref(dev, pci_bus, &error_abort); pci_ide_create_devs(dev); idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0"); diff --git a/hw/ide/piix.c b/hw/ide/piix.c index 48da68da37f..3aef9b1e21c 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -152,6 +152,11 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp) PCIIDEState *d = PCI_IDE(dev); uint8_t *pci_conf = dev->config; + if (!d->isa_bus) { + error_setg(errp, "piix-ide: 'isa-bus' link not set"); + return; + } + pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode bmdma_setup_bar(d); diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c index d60f161ecf4..ef11c2d1f8d 100644 --- a/hw/isa/piix4.c +++ b/hw/isa/piix4.c @@ -248,20 +248,24 @@ static void piix4_register_types(void) type_init(piix4_register_types) -DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_bus, I2CBus **smbus) +DeviceState *piix4_create(PCIBus *pci_bus, ISABus **isa_busp, I2CBus **smbus) { PCIDevice *pci; DeviceState *dev; + ISABus *isa_bus; int devfn = PCI_DEVFN(10, 0); pci = pci_create_simple_multifunction(pci_bus, devfn, true, TYPE_PIIX4_PCI_DEVICE); dev = DEVICE(pci); - if (isa_bus) { - *isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0")); + isa_bus = ISA_BUS(qdev_get_child_bus(dev, "isa.0")); + if (isa_busp) { + *isa_busp = isa_bus; } pci = pci_new(devfn + 1, "piix4-ide"); + object_property_set_link(OBJECT(pci), "isa-bus", + OBJECT(isa_bus), &error_abort); pci_realize_and_unref(pci, pci_bus, &error_abort); pci_ide_create_devs(pci); -- 2.26.3