[RFC PATCH 3/7] hw/ide/cmd646: Configure IDE bus IRQs after realization

Philippe Mathieu-Daudé posted 7 patches 8 months, 1 week ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, John Snow <jsnow@redhat.com>, BALATON Zoltan <balaton@eik.bme.hu>, "Michael S. Tsirkin" <mst@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Laurent Vivier <laurent@vivier.eu>
[RFC PATCH 3/7] hw/ide/cmd646: Configure IDE bus IRQs after realization
Posted by Philippe Mathieu-Daudé 8 months, 1 week ago
We shouldn't call qdev_get_gpio_in() on unrealized devices.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
Ideally we should rework the current IDE bus model to really
use QOM and not globals. Left for later.
---
 hw/ide/cmd646.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index c0bcfa4414..92e1e7a4fc 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -291,9 +291,18 @@ static void pci_cmd646_ide_realize(PCIDevice *dev, Error **errp)
     /* TODO: RST# value should be 0 */
     pci_conf[PCI_INTERRUPT_PIN] = 0x01; // interrupt on pin 1
 
-    qdev_init_gpio_in(ds, cmd646_set_irq, 2);
     for (i = 0; i < 2; i++) {
         ide_bus_init(&d->bus[i], sizeof(d->bus[i]), ds, i, 2);
+    }
+}
+
+static void pci_cmd646_ide_wire(DeviceState *dev)
+{
+    PCIIDEState *d = PCI_IDE(dev);
+    DeviceState *ds = DEVICE(dev);
+
+    qdev_init_gpio_in(ds, cmd646_set_irq, 2);
+    for (unsigned i = 0; i < 2; i++) {
         ide_bus_init_output_irq(&d->bus[i], qdev_get_gpio_in(ds, i));
 
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
@@ -324,6 +333,7 @@ static void cmd646_ide_class_init(ObjectClass *klass, void *data)
 
     dc->reset = cmd646_reset;
     dc->vmsd = &vmstate_ide_pci;
+    dc->wire = pci_cmd646_ide_wire;
     k->realize = pci_cmd646_ide_realize;
     k->exit = pci_cmd646_ide_exitfn;
     k->vendor_id = PCI_VENDOR_ID_CMD;
-- 
2.41.0