[RFC PATCH v2 111/137] hw/pci, hw/usb, system: Give allocated IRQs an owner and name

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
Convert pci_allocate_irq() and the qtest interceptor to the parented
qemu_allocate_irq() form so the IRQ objects land under the device
that owns their lifetime instead of /machine/unattached.

hw/usb/vt82c686-uhci-pci.c drops the IRQ set up by the base UHCI
class before installing its own; switch that from object_unref() to
qemu_free_irq() so it unparents the now-parented IRQ before freeing
it.

  hw/pci/pci.c pci_allocate_irq()  | OBJECT(pci_dev) | "intx-irq"
  system/qtest.c qtest intercept   | OBJECT(dev)     | "qtest-icpt[*]"
  hw/usb/vt82c686-uhci-pci.c       | OBJECT(s)       | "isa-irq"

AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/pci/pci.c               | 2 +-
 hw/usb/vt82c686-uhci-pci.c | 4 ++--
 system/qtest.c             | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 9ba7bfd977..d92092b233 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1869,7 +1869,7 @@ qemu_irq pci_allocate_irq(PCIDevice *pci_dev)
     int intx = pci_intx(pci_dev);
     assert(0 <= intx && intx < PCI_NUM_PINS);
 
-    return qemu_allocate_irq_orphan(pci_irq_handler, pci_dev, intx);
+    return qemu_allocate_irq(OBJECT(pci_dev), "intx-irq", pci_irq_handler, pci_dev, intx);
 }
 
 void pci_set_irq(PCIDevice *pci_dev, int level)
diff --git a/hw/usb/vt82c686-uhci-pci.c b/hw/usb/vt82c686-uhci-pci.c
index b58b61e609..d8c9e98061 100644
--- a/hw/usb/vt82c686-uhci-pci.c
+++ b/hw/usb/vt82c686-uhci-pci.c
@@ -22,8 +22,8 @@ static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
     pci_set_long(pci_conf + 0xc0, 0x00002000);
 
     usb_uhci_common_realize(dev, errp);
-    object_unref(s->irq);
-    s->irq = qemu_allocate_irq_orphan(uhci_isa_set_irq, s, 0);
+    qemu_free_irq(s->irq);
+    s->irq = qemu_allocate_irq(OBJECT(s), "isa-irq", uhci_isa_set_irq, s, 0);
 }
 
 static UHCIInfo uhci_info[] = {
diff --git a/system/qtest.c b/system/qtest.c
index f38feaac89..5ef99f9f23 100644
--- a/system/qtest.c
+++ b/system/qtest.c
@@ -346,7 +346,7 @@ void qtest_set_command_cb(bool (*pc_cb)(CharFrontend *chr, gchar **words))
 static void qtest_install_gpio_out_intercept(DeviceState *dev, const char *name, int n)
 {
     qemu_irq *disconnected = g_new0(qemu_irq, 1);
-    qemu_irq icpt = qemu_allocate_irq_orphan(qtest_irq_handler,
+    qemu_irq icpt = qemu_allocate_irq(OBJECT(dev), "qtest-icpt[*]", qtest_irq_handler,
                                       disconnected, n);
 
     *disconnected = qdev_intercept_gpio_out(dev, icpt, name, n);
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.