qom: Make composition-tree parenting mandatory
Subsystems (11)
RFC PATCH v2 109/137 irq: Rename qemu_allocate_irq*() and friends to *_orphan()
In reply to Alexander GrafMechanical rename of the IRQ allocation helpers that create an IRQState via object_new() with no QOM parent:
qemu_allocate_irq -> qemu_allocate_irq_orphan qemu_allocate_irqs -> qemu_allocate_irqs_orphan qemu_extend_irqs -> qemu_extend_irqs_orphan qemu_irq_invert -> qemu_irq_invert_orphan
The next commit reintroduces the well-known names with a mandatory (owner, name, ...) prefix, and later commits convert every caller per subdirectory before deleting the *_orphan() variants.
Coccinelle: scripts/coccinelle/qom-parent/irq-rename.cocci
git ls-files '*.c' '*.h' | grep -v '^subprojects/' |
xargs sed -i -e 's/\bqemu_allocate_irqs\b/qemu_allocate_irqs_orphan/g' \
-e 's/\bqemu_allocate_irq\b/qemu_allocate_irq_orphan/g' \
-e 's/\bqemu_extend_irqs\b/qemu_extend_irqs_orphan/g' \
-e 's/\bqemu_irq_invert\b/qemu_irq_invert_orphan/g'AI-used-for: code (refactoring)
--- hw/alpha/typhoon.c | 4 ++-- hw/arm/armsse.c | 4 ++-- hw/arm/exynos4_boards.c | 2 +- hw/arm/mps2-tz.c | 2 +- hw/arm/omap1.c | 14 +++++++------- hw/arm/realview.c | 2 +- hw/arm/stellaris.c | 10 +++++----- hw/char/diva-gsp.c | 2 +- hw/core/gpio.c | 2 +- hw/core/irq.c | 14 +++++++------- hw/display/macfb.c | 2 +- hw/dma/omap_dma.c | 4 ++-- hw/i386/kvm/i8259.c | 2 +- hw/i386/microvm.c | 2 +- hw/i386/pc.c | 4 ++-- hw/i386/pc_piix.c | 2 +- hw/i386/x86-cpu.c | 2 +- hw/i386/xen/xen-hvm.c | 2 +- hw/ide/ahci.c | 2 +- hw/ide/pci.c | 2 +- hw/intc/sh_intc.c | 2 +- hw/isa/i82378.c | 2 +- hw/isa/lpc_ich9.c | 2 +- hw/m68k/mcf5206.c | 2 +- hw/m68k/q800.c | 4 ++-- hw/mips/mips_int.c | 2 +- hw/net/can/can_kvaser_pci.c | 2 +- hw/pci-host/pnv_phb3.c | 2 +- hw/pci-host/pnv_phb3_msi.c | 2 +- hw/pci-host/pnv_phb4.c | 2 +- hw/pci/pci.c | 2 +- hw/ppc/e500.c | 2 +- hw/ppc/pnv_lpc.c | 2 +- hw/ppc/pnv_psi.c | 4 ++-- hw/ppc/spapr_irq.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/scsi/esp-pci.c | 2 +- hw/sh4/sh7750.c | 2 +- hw/sparc/sun4m.c | 4 ++-- hw/sparc64/sun4u.c | 2 +- hw/timer/arm_timer.c | 4 ++-- hw/usb/vt82c686-uhci-pci.c | 2 +- hw/xen/xen-pvh-common.c | 4 ++-- hw/xtensa/mx_pic.c | 2 +- hw/xtensa/pic_cpu.c | 4 ++-- include/hw/core/irq.h | 8 ++++---- scripts/coccinelle/qom-parent/irq-rename.cocci | 15 +++++++++++++++ system/qtest.c | 2 +- 48 files changed, 91 insertions(+), 76 deletions(-) create mode 100644 scripts/coccinelle/qom-parent/irq-rename.cocci
hw/alpha/typhoon.c +2 -2
@@ -849,8 +849,8 @@ PCIBus *typhoon_init(Object *parent, MemoryRegion *ram, qemu_irq *p_isa_irq, } } - *p_isa_irq =qemu_allocate_irq (typhoon_set_isa_irq, s,0 ); - *p_rtc_irq =qemu_allocate_irq (typhoon_set_timer_irq, s,0 ); + *p_isa_irq =qemu_allocate_irq_orphan (typhoon_set_isa_irq, s,0 ); + *p_rtc_irq =qemu_allocate_irq_orphan (typhoon_set_timer_irq, s,0 );/* Main memory region, 0x00.0000.0000. Real hardware supports 32GB, but the address space hole reserved at this point is 8TB. */
hw/arm/armsse.c +2 -2
@@ -693,7 +693,7 @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s)DeviceState *dev_splitter =DEVICE (&s->sec_resp_splitter);qdev_init_gpio_out_named (dev, &s->sec_resp_cfg,"sec_resp_cfg" ,1 ); - s->sec_resp_cfg_in =qemu_allocate_irq (irq_status_forwarder, + s->sec_resp_cfg_in =qemu_allocate_irq_orphan (irq_status_forwarder, s->sec_resp_cfg,1 );qdev_connect_gpio_out (dev_splitter,2 , s->sec_resp_cfg_in); }
@@ -1137,7 +1137,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (sbd_secctl,0 ,0x50080000 );sysbus_mmio_map (sbd_secctl,1 ,0x40080000 ); - s->nsc_cfg_in =qemu_allocate_irq (nsccfg_handler, s,1 ); + s->nsc_cfg_in =qemu_allocate_irq_orphan (nsccfg_handler, s,1 );qdev_connect_gpio_out_named (dev_secctl,"nsc_cfg" ,0 , s->nsc_cfg_in);/* The sec_resp_cfg output from the security controller must be split into
hw/arm/exynos4_boards.c +1 -1
@@ -146,7 +146,7 @@ static void smdkc210_init(MachineState *machine) EXYNOS4_BOARD_SMDKC210);lan9215_init (SMDK_LAN9118_BASE_ADDR , -qemu_irq_invert (s->soc.irq_table[exynos4210_get_irq (37 ,1 )])); +qemu_irq_invert_orphan (s->soc.irq_table[exynos4210_get_irq (37 ,1 )]));arm_load_kernel (s->soc.cpu[0 ], machine, &exynos4_board_binfo); }
hw/arm/mps2-tz.c +1 -1
@@ -1209,7 +1209,7 @@ static void mps2tz_common_init(MachineState *machine)* Connect the line from the SCC so that we can remap when the * guest updates that register. */ - mms->remap_irq =qemu_allocate_irq (remap_irq_fn, mms,0 ); + mms->remap_irq =qemu_allocate_irq_orphan (remap_irq_fn, mms,0 );qdev_connect_gpio_out_named (DEVICE (&mms->scc),"remap" ,0 , mms->remap_irq); }
hw/arm/omap1.c +7 -7
@@ -139,7 +139,7 @@ static void omap_timer_clk_update(void *opaque, int line, int on)static void omap_timer_clk_setup (struct omap_mpu_timer_s *timer) {omap_clk_adduser (timer->clk, -qemu_allocate_irq (omap_timer_clk_update, timer,0 )); +qemu_allocate_irq_orphan (omap_timer_clk_update, timer,0 )); timer->rate =omap_clk_getrate (timer->clk); }
@@ -2083,14 +2083,14 @@ static struct omap_mpuio_s *omap_mpuio_init(Object *owner, s->irq = gpio_int; s->kbd_irq = kbd_int; - s->in =qemu_allocate_irqs (omap_mpuio_set, s,16 ); + s->in =qemu_allocate_irqs_orphan (omap_mpuio_set, s,16 );omap_mpuio_reset (s);memory_region_init_io (&s->iomem, owner, &omap_mpuio_ops, s,"omap-mpuio" ,0x800 );memory_region_add_subregion (memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irq (omap_mpuio_onoff, s,0 )); +omap_clk_adduser (clk,qemu_allocate_irq_orphan (omap_mpuio_onoff, s,0 ));return s; }
@@ -2363,7 +2363,7 @@ static struct omap_pwl_s *omap_pwl_init(Object *owner, "omap-pwl", 0x800);memory_region_add_subregion (system_memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irq (omap_pwl_clk_update, s,0 )); +omap_clk_adduser (clk,qemu_allocate_irq_orphan (omap_pwl_clk_update, s,0 ));return s; }
@@ -3426,8 +3426,8 @@ static void omap_mcbsp_i2s_start(void *opaque, int line, int level)void omap_mcbsp_i2s_attach (struct omap_mcbsp_s *s,I2SCodec *slave) { s->codec = slave; - slave->rx_swallow =qemu_allocate_irq (omap_mcbsp_i2s_swallow, s,0 ); - slave->tx_start =qemu_allocate_irq (omap_mcbsp_i2s_start, s,0 ); + slave->rx_swallow =qemu_allocate_irq_orphan (omap_mcbsp_i2s_swallow, s,0 ); + slave->tx_start =qemu_allocate_irq_orphan (omap_mcbsp_i2s_start, s,0 ); }/* LED Pulse Generators */
@@ -3579,7 +3579,7 @@ static struct omap_lpg_s *omap_lpg_init(Object *owner, "omap-lpg", 0x800);memory_region_add_subregion (system_memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irq (omap_lpg_clk_update, s,0 )); +omap_clk_adduser (clk,qemu_allocate_irq_orphan (omap_lpg_clk_update, s,0 ));return s; }
hw/arm/realview.c +1 -1
@@ -276,7 +276,7 @@ static void realview_init(MachineState *machine,split_irq_from_named (OBJECT (machine), dev,"card-inserted" ,qdev_get_gpio_in (sysctl,ARM_SYSCTL_GPIO_MMC_CARDIN ), -qemu_irq_invert (qdev_get_gpio_in (gpio2,0 ))); +qemu_irq_invert_orphan (qdev_get_gpio_in (gpio2,0 ))); dinfo =drive_get (IF_SD ,0 ,0 );if (dinfo) {
hw/arm/stellaris.c +5 -5
@@ -1358,15 +1358,15 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)sysbus_realize (SYS_BUS_DEVICE (gpad), &error_fatal);qdev_connect_gpio_out (gpad,0 , -qemu_irq_invert (gpio_in[GPIO_E ][0 ]));/* up */ +qemu_irq_invert_orphan (gpio_in[GPIO_E ][0 ]));/* up */ qdev_connect_gpio_out (gpad,1 , -qemu_irq_invert (gpio_in[GPIO_E ][1 ]));/* down */ +qemu_irq_invert_orphan (gpio_in[GPIO_E ][1 ]));/* down */ qdev_connect_gpio_out (gpad,2 , -qemu_irq_invert (gpio_in[GPIO_E ][2 ]));/* left */ +qemu_irq_invert_orphan (gpio_in[GPIO_E ][2 ]));/* left */ qdev_connect_gpio_out (gpad,3 , -qemu_irq_invert (gpio_in[GPIO_E ][3 ]));/* right */ +qemu_irq_invert_orphan (gpio_in[GPIO_E ][3 ]));/* right */ qdev_connect_gpio_out (gpad,4 , -qemu_irq_invert (gpio_in[GPIO_F ][1 ]));/* select */ +qemu_irq_invert_orphan (gpio_in[GPIO_F ][1 ]));/* select */ }for (i =0 ; i <7 ; i++) {if (board->dc4 & (1 << i)) {
hw/char/diva-gsp.c +1 -1
@@ -126,7 +126,7 @@ static void diva_pci_realize(PCIDevice *dev, Error **errp) pci->dev.config[PCI_INTERRUPT_PIN ] =1 ;memory_region_init (&pci->membar,OBJECT (pci),"serial_ports" ,4096 );pci_register_bar (&pci->dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &pci->membar); - pci->irqs =qemu_allocate_irqs (multi_serial_irq_mux, pci, di.nports); + pci->irqs =qemu_allocate_irqs_orphan (multi_serial_irq_mux, pci, di.nports);for (i =0 ; i < di.nports; i++) { s = pci->state + i;
hw/core/gpio.c +1 -1
@@ -49,7 +49,7 @@ void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,NamedGPIOList *gpio_list =qdev_get_named_gpio_list (dev, name);assert (gpio_list->num_out ==0 || !name); - gpio_list->in =qemu_extend_irqs (gpio_list->in, gpio_list->num_in, handler, + gpio_list->in =qemu_extend_irqs_orphan (gpio_list->in, gpio_list->num_in, handler, opaque, n);if (!name) {
hw/core/irq.c +7 -7
@@ -68,7 +68,7 @@ void qemu_init_irqs(IRQState irq[], size_t count, } } -qemu_irq *qemu_extend_irqs (qemu_irq *old,int n_old,qemu_irq_handler handler, +qemu_irq *qemu_extend_irqs_orphan (qemu_irq *old,int n_old,qemu_irq_handler handler,void *opaque,int n) {qemu_irq *s;
@@ -79,17 +79,17 @@ qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler, } s = old ?g_renew (qemu_irq, old, n + n_old) :g_new (qemu_irq, n);for (i = n_old; i < n + n_old; i++) { - s[i] =qemu_allocate_irq (handler, opaque, i); + s[i] =qemu_allocate_irq_orphan (handler, opaque, i); }return s; } -qemu_irq *qemu_allocate_irqs (qemu_irq_handler handler,void *opaque,int n) +qemu_irq *qemu_allocate_irqs_orphan (qemu_irq_handler handler,void *opaque,int n) { -return qemu_extend_irqs (NULL ,0 , handler, opaque, n); +return qemu_extend_irqs_orphan (NULL ,0 , handler, opaque, n); } -qemu_irq qemu_allocate_irq (qemu_irq_handler handler,void *opaque,int n) +qemu_irq qemu_allocate_irq_orphan (qemu_irq_handler handler,void *opaque,int n) {IRQState *irq =IRQ (object_new (TYPE_IRQ ));init_irq_fields (irq, handler, opaque, n);
@@ -117,11 +117,11 @@ static void qemu_notirq(void *opaque, int line, int level)qemu_set_irq (irq, !level); } -qemu_irq qemu_irq_invert (qemu_irq irq) +qemu_irq qemu_irq_invert_orphan (qemu_irq irq) {/* The default state for IRQs is low, so raise the output now. */ qemu_irq_raise (irq); -return qemu_allocate_irq (qemu_notirq, irq,0 ); +return qemu_allocate_irq_orphan (qemu_notirq, irq,0 ); }void qemu_irq_set_observer (qemu_irq *gpio_in,qemu_irq_handler handler,int n)
hw/display/macfb.c +1 -1
@@ -737,7 +737,7 @@ static void macfb_nubus_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&nd->slot_mem,DAFB_BASE , &ms->mem_ctrl);memory_region_add_subregion (&nd->slot_mem,VIDEO_BASE , &ms->mem_vram); - ms->irq =qemu_allocate_irq (macfb_nubus_set_irq, s,0 ); + ms->irq =qemu_allocate_irq_orphan (macfb_nubus_set_irq, s,0 ); }static void macfb_nubus_unrealize (DeviceState *dev)
hw/dma/omap_dma.c +2 -2
@@ -1109,7 +1109,7 @@ struct soc_dma_s *omap_dma_init(Object *owner, hwaddr base, qemu_irq *irqs, s->dma->freq =omap_clk_getrate (clk); s->dma->transfer_fn = omap_dma_transfer_generic; s->dma->setup_fn = omap_dma_transfer_setup; - s->dma->drq =qemu_allocate_irqs (omap_dma_request, s,32 ); + s->dma->drq =qemu_allocate_irqs_orphan (omap_dma_request, s,32 ); s->dma->opaque = s;while (num_irqs --)
@@ -1123,7 +1123,7 @@ struct soc_dma_s *omap_dma_init(Object *owner, hwaddr base, qemu_irq *irqs, s->dma->ch[i].opaque = &s->ch[i]; } -omap_clk_adduser (s->clk,qemu_allocate_irq (omap_dma_clk_update, s,0 )); +omap_clk_adduser (s->clk,qemu_allocate_irq_orphan (omap_dma_clk_update, s,0 ));omap_dma_reset (s->dma);omap_dma_clk_update (s,0 ,1 );
hw/i386/kvm/i8259.c +1 -1
@@ -136,7 +136,7 @@ qemu_irq *kvm_i8259_init(Object *parent, ISABus *bus)i8259_init_chip (parent,TYPE_KVM_I8259 , bus, true);i8259_init_chip (parent,TYPE_KVM_I8259 , bus, false); -return qemu_allocate_irqs (kvm_pic_set_irq,NULL ,ISA_NUM_IRQS ); +return qemu_allocate_irqs_orphan (kvm_pic_set_irq,NULL ,ISA_NUM_IRQS ); }static void kvm_i8259_class_init (ObjectClass *klass,const void *data)
hw/i386/microvm.c +1 -1
@@ -168,7 +168,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)/* Core components */ ioapics =microvm_ioapics (mms); gsi_state =g_malloc0 (sizeof (*gsi_state)); - x86ms->gsi =qemu_allocate_irqs (gsi_handler, gsi_state, + x86ms->gsi =qemu_allocate_irqs_orphan (gsi_handler, gsi_state,IOAPIC_NUM_PINS * ioapics); isa_bus = isa_bus_new_bridge(OBJECT(mms), get_system_memory(), get_system_io(),
hw/i386/pc.c +2 -2
@@ -200,7 +200,7 @@ GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled)if (kvm_ioapic_in_kernel ()) {kvm_pc_setup_irq_routing (pci_enabled); } - *irqs =qemu_allocate_irqs (gsi_handler, s,IOAPIC_NUM_PINS ); + *irqs =qemu_allocate_irqs_orphan (gsi_handler, s,IOAPIC_NUM_PINS );return s; }
@@ -1028,7 +1028,7 @@ static void pc_superio_init(Object *parent, ISABus *isa_bus, bool create_fdctrl, } port92 =isa_create_simple (parent,"port92" , isa_bus,TYPE_PORT92 ); - a20_line =qemu_allocate_irqs (handle_a20_line_change, first_cpu,2 ); + a20_line =qemu_allocate_irqs_orphan (handle_a20_line_change, first_cpu,2 );qdev_connect_gpio_out_named (DEVICE (i8042),I8042_A20_LINE ,0 , a20_line[0 ]); qdev_connect_gpio_out_named(DEVICE(port92),
hw/i386/pc_piix.c +1 -1
@@ -299,7 +299,7 @@ static void pc_init1(MachineState *machine, const char *pci_type)pc_nic_init (pcmc, isa_bus, pcms->pcibus);if (piix4_pm) { - smi_irq =qemu_allocate_irq (pc_acpi_smi_interrupt, first_cpu,0 ); + smi_irq =qemu_allocate_irq_orphan (pc_acpi_smi_interrupt, first_cpu,0 );qdev_connect_gpio_out_named (DEVICE (piix4_pm),"smi-irq" ,0 , smi_irq); pcms->smbus =I2C_BUS (qdev_get_child_bus (DEVICE (piix4_pm),"i2c" ));
hw/i386/x86-cpu.c +1 -1
@@ -63,7 +63,7 @@ static void pic_irq_request(void *opaque, int irq, int level)qemu_irq x86_allocate_cpu_irq (void ) { -return qemu_allocate_irq (pic_irq_request,NULL ,0 ); +return qemu_allocate_irq_orphan (pic_irq_request,NULL ,0 ); }int cpu_get_pic_interrupt (CPUX86State *env)
hw/i386/xen/xen-hvm.c +1 -1
@@ -114,7 +114,7 @@ static void xen_set_irq(void *opaque, int irq, int level)qemu_irq *xen_interrupt_controller_init (void ) { -return qemu_allocate_irqs (xen_set_irq,NULL ,16 ); +return qemu_allocate_irqs_orphan (xen_set_irq,NULL ,16 ); }/* Memory Ops */
hw/ide/ahci.c +1 -1
@@ -1594,7 +1594,7 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as)assert (s->ports >0 ); s->dev =g_new0 (AHCIDevice, s->ports);ahci_reg_init (s); - irqs =qemu_allocate_irqs (ahci_irq_set, s, s->ports); + irqs =qemu_allocate_irqs_orphan (ahci_irq_set, s, s->ports);for (i =0 ; i < s->ports; i++) {AHCIDevice *ad = &s->dev[i];
hw/ide/pci.c +1 -1
@@ -606,7 +606,7 @@ void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d) bm->dma.ops = &bmdma_ops; bus->dma = &bm->dma; bm->irq = bus->irq; - bus->irq =qemu_allocate_irq (bmdma_irq, bm,0 ); + bus->irq =qemu_allocate_irq_orphan (bmdma_irq, bm,0 ); bm->bus = bus; bm->pci_dev = d; }
hw/intc/sh_intc.c +1 -1
@@ -403,7 +403,7 @@ int sh_intc_init(Object *owner, MemoryRegion *sysmem,for (i =0 ; i < nr_sources; i++) { desc->sources[i].parent = desc; } - desc->irqs =qemu_allocate_irqs (sh_intc_set_irq, desc, nr_sources); + desc->irqs =qemu_allocate_irqs_orphan (sh_intc_set_irq, desc, nr_sources);memory_region_init_io (&desc->iomem, owner, &sh_intc_ops, desc,"intc" ,0x100000000ULL ); j =0 ;
hw/isa/i82378.c +1 -1
@@ -95,7 +95,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)/* 2 82C59 (irq) */ s->isa_irqs_in =i8259_init (OBJECT (pci), isabus, -qemu_allocate_irq (i82378_request_out0_irq, +qemu_allocate_irq_orphan (i82378_request_out0_irq, s,0 ));isa_bus_register_input_irqs (isabus, s->isa_irqs_in);
hw/isa/lpc_ich9.c +1 -1
@@ -429,7 +429,7 @@ static void ich9_lpc_pm_init(ICH9LPCState *lpc)qemu_irq sci_irq;FWCfgState *fw_cfg =fw_cfg_find (); - sci_irq =qemu_allocate_irq (ich9_set_sci, lpc,0 ); + sci_irq =qemu_allocate_irq_orphan (ich9_set_sci, lpc,0 );ich9_pm_init (PCI_DEVICE (lpc), &lpc->pm, sci_irq);if (lpc->smi_host_features && fw_cfg) {
hw/m68k/mcf5206.c +1 -1
@@ -593,7 +593,7 @@ static void mcf5206_mbar_realize(DeviceState *dev, Error **errp) "mbar", 0x00001000);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem); - s->pic =qemu_allocate_irqs (m5206_mbar_set_irq, s,14 ); + s->pic =qemu_allocate_irqs_orphan (m5206_mbar_set_irq, s,14 );m5206_timer_init (&s->timer[0 ], s->pic[9 ]);m5206_timer_init (&s->timer[1 ], s->pic[10 ]); s->uart[0 ] =mcf_uart_create (OBJECT (s), s->pic[12 ],serial_hd (0 ));
hw/m68k/q800.c +2 -2
@@ -474,11 +474,11 @@ static void q800_machine_init(MachineState *machine)sysbus_realize (sysbus, &error_fatal);/* SCSI and SCSI data IRQs are negative edge triggered */ sysbus_connect_irq (sysbus,0 , -qemu_irq_invert ( +qemu_irq_invert_orphan (qdev_get_gpio_in (DEVICE (&m->via2),VIA2_IRQ_SCSI_BIT )));sysbus_connect_irq (sysbus,1 , -qemu_irq_invert ( +qemu_irq_invert_orphan (qdev_get_gpio_in (DEVICE (&m->via2),VIA2_IRQ_SCSI_DATA_BIT ))); memory_region_add_subregion(&m->macio, ESP_BASE - IO_BASE,
hw/mips/mips_int.c +1 -1
@@ -56,7 +56,7 @@ void cpu_mips_irq_init_cpu(MIPSCPU *cpu)qemu_irq *qi;int i; - qi =qemu_allocate_irqs (cpu_mips_irq_request, cpu,8 ); + qi =qemu_allocate_irqs_orphan (cpu_mips_irq_request, cpu,8 );for (i =0 ; i <8 ; i++) { env->irq[i] = qi[i]; }
hw/net/can/can_kvaser_pci.c +1 -1
@@ -224,7 +224,7 @@ static void kvaser_pci_realize(PCIDevice *pci_dev, Error **errp) pci_conf = pci_dev->config; pci_conf[PCI_INTERRUPT_PIN ] =0x01 ;/* interrupt pin A */ - d->irq =qemu_allocate_irq (kvaser_pci_irq_handler, d,0 ); + d->irq =qemu_allocate_irq_orphan (kvaser_pci_irq_handler, d,0 );can_sja_init (s, d->irq);
hw/pci-host/pnv_phb3.c +1 -1
@@ -1054,7 +1054,7 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)ics_set_irq_type (&phb->lsis, i, true); } - phb->qirqs =qemu_allocate_irqs (ics_set_irq, &phb->lsis, phb->lsis.nr_irqs); + phb->qirqs =qemu_allocate_irqs_orphan (ics_set_irq, &phb->lsis, phb->lsis.nr_irqs);/* MSI sources */ object_property_set_link(OBJECT(&phb->msis), "phb", OBJECT(phb),
hw/pci-host/pnv_phb3_msi.c +1 -1
@@ -267,7 +267,7 @@ static void phb3_msi_realize(DeviceState *dev, Error **errp)return ; } - msi->qirqs =qemu_allocate_irqs (phb3_msi_set_irq, msi, ics->nr_irqs); + msi->qirqs =qemu_allocate_irqs_orphan (phb3_msi_set_irq, msi, ics->nr_irqs); }static void phb3_msi_instance_init (Object *obj)
hw/pci-host/pnv_phb4.c +1 -1
@@ -1605,7 +1605,7 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)pnv_phb4_update_xsrc (phb); - phb->qirqs =qemu_allocate_irqs (xive_source_set_irq, xsrc, xsrc->nr_irqs); + phb->qirqs =qemu_allocate_irqs_orphan (xive_source_set_irq, xsrc, xsrc->nr_irqs);pnv_phb4_xscom_realize (phb); }
hw/pci/pci.c +1 -1
@@ -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 (pci_irq_handler, pci_dev, intx); +return qemu_allocate_irq_orphan (pci_irq_handler, pci_dev, intx); }void pci_set_irq (PCIDevice *pci_dev,int level)
hw/ppc/e500.c +1 -1
@@ -1089,7 +1089,7 @@ void ppce500_init(MachineState *machine) sysbus_mmio_get_region(s, 0));/* Power Off GPIO at Pin 0 */ - poweroff_irq =qemu_allocate_irq (ppce500_power_off,NULL ,0 ); + poweroff_irq =qemu_allocate_irq_orphan (ppce500_power_off,NULL ,0 );qdev_connect_gpio_out (dev,0 , poweroff_irq); }
hw/ppc/pnv_lpc.c +1 -1
@@ -993,7 +993,7 @@ ISABus *pnv_lpc_isa_create(PnvLpcController *lpc, bool use_cpld, Error **errp) }/* POWER has a 17th irq, QEMU only implements the 16 regular device irqs */ - irqs =qemu_allocate_irqs (handler, lpc,ISA_NUM_IRQS ); + irqs =qemu_allocate_irqs_orphan (handler, lpc,ISA_NUM_IRQS );isa_bus_register_input_irqs (isa_bus, irqs);
hw/ppc/pnv_psi.c +2 -2
@@ -509,7 +509,7 @@ static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)qdev_init_gpio_in (dev, pnv_psi_power8_set_irq, ics->nr_irqs); - psi->qirqs =qemu_allocate_irqs (ics_set_irq, ics, ics->nr_irqs); + psi->qirqs =qemu_allocate_irqs_orphan (ics_set_irq, ics, ics->nr_irqs);/* XSCOM region for PSI registers */ pnv_xscom_region_init(&psi->xscom_regs, OBJECT(dev), &pnv_psi_xscom_ops,
@@ -872,7 +872,7 @@ static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)xive_source_irq_set_lsi (xsrc, i); } - psi->qirqs =qemu_allocate_irqs (xive_source_set_irq, xsrc, xsrc->nr_irqs); + psi->qirqs =qemu_allocate_irqs_orphan (xive_source_set_irq, xsrc, xsrc->nr_irqs);qdev_init_gpio_in (dev, pnv_psi_power9_set_irq, xsrc->nr_irqs);
hw/ppc/spapr_irq.c +1 -1
@@ -339,7 +339,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)spapr_xive_hcall_init (spapr); } - spapr->qirqs =qemu_allocate_irqs (spapr_set_irq, spapr, + spapr->qirqs =qemu_allocate_irqs_orphan (spapr_set_irq, spapr,SPAPR_NR_XIRQS +SPAPR_IRQ_NR_IPIS );/*
hw/riscv/sifive_u.c +1 -1
@@ -484,7 +484,7 @@ static void sifive_u_machine_init(MachineState *machine)/* register gpio-restart */ qdev_connect_gpio_out (DEVICE (&(s->soc.gpio)),10 , -qemu_allocate_irq (sifive_u_machine_reset,NULL ,0 )); +qemu_allocate_irq_orphan (sifive_u_machine_reset,NULL ,0 ));/* load/create device tree */ if (machine->dtb) {
hw/scsi/esp-pci.c +1 -1
@@ -407,7 +407,7 @@ static void esp_pci_scsi_realize(PCIDevice *dev, Error **errp) "esp-io", 0x80);pci_register_bar (dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , &pci->io); - s->irq =qemu_allocate_irq (esp_irq_handler, pci,0 ); + s->irq =qemu_allocate_irq_orphan (esp_irq_handler, pci,0 );scsi_bus_init (&s->bus,sizeof (s->bus), d, &esp_pci_scsi_info); }
hw/sh4/sh7750.c +1 -1
@@ -848,5 +848,5 @@ SH7750State *sh7750_init(Object *parent, SuperHCPU *cpu,qemu_irq sh7750_irl (SH7750State *s) {sh_intc_toggle_source (&s->intc.sources[IRL ],1 ,0 );/* enable */ -return qemu_allocate_irq (sh_intc_set_irl, &s->intc.sources[IRL ],0 ); +return qemu_allocate_irq_orphan (sh_intc_set_irl, &s->intc.sources[IRL ],0 ); }
hw/sparc/sun4m.c +2 -2
@@ -1008,7 +1008,7 @@ static void sun4m_hw_init(MachineState *machine)if (hwdef->apc_base) {apc_init (OBJECT (machine), hwdef->apc_base, -qemu_allocate_irq (cpu_halt_signal,NULL ,0 )); +qemu_allocate_irq_orphan (cpu_halt_signal,NULL ,0 )); }if (hwdef->fd_base) {
@@ -1018,7 +1018,7 @@ static void sun4m_hw_init(MachineState *machine)sun4m_fdctrl_init (OBJECT (machine), slavio_irq[22 ], hwdef->fd_base, fd, &fdc_tc); }else { - fdc_tc =qemu_allocate_irq (dummy_fdc_tc,NULL ,0 ); + fdc_tc =qemu_allocate_irq_orphan (dummy_fdc_tc,NULL ,0 ); } slavio_misc_init(OBJECT(machine), hwdef->slavio_base, hwdef->aux1_base,
hw/sparc64/sun4u.c +1 -1
@@ -311,7 +311,7 @@ static void ebus_realize(PCIDevice *pci_dev, Error **errp) }/* ISA bus */ - s->isa_irqs_in =qemu_allocate_irqs (ebus_isa_irq_handler, s,ISA_NUM_IRQS ); + s->isa_irqs_in =qemu_allocate_irqs_orphan (ebus_isa_irq_handler, s,ISA_NUM_IRQS );isa_bus_register_input_irqs (s->isa_bus, s->isa_irqs_in);qdev_init_gpio_out_named (DEVICE (s), s->isa_irqs_out,"isa-irq" ,ISA_NUM_IRQS );
hw/timer/arm_timer.c +2 -2
@@ -305,8 +305,8 @@ static void sp804_realize(DeviceState *dev, Error **errp) s->timer[0 ] =arm_timer_init (s->freq0); s->timer[1 ] =arm_timer_init (s->freq1); - s->timer[0 ]->irq =qemu_allocate_irq (sp804_set_irq, s,0 ); - s->timer[1 ]->irq =qemu_allocate_irq (sp804_set_irq, s,1 ); + s->timer[0 ]->irq =qemu_allocate_irq_orphan (sp804_set_irq, s,0 ); + s->timer[1 ]->irq =qemu_allocate_irq_orphan (sp804_set_irq, s,1 ); }/* Integrator/CP timer module. */
hw/usb/vt82c686-uhci-pci.c +1 -1
@@ -23,7 +23,7 @@ static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)usb_uhci_common_realize (dev, errp);object_unref (s->irq); - s->irq =qemu_allocate_irq (uhci_isa_set_irq, s,0 ); + s->irq =qemu_allocate_irq_orphan (uhci_isa_set_irq, s,0 ); }static UHCIInfo uhci_info[] = {
hw/xen/xen-pvh-common.c +2 -2
@@ -170,7 +170,7 @@ static void xen_create_virtio_mmio_devices(XenPVHMachineState *s)*/ for (i = s->cfg.virtio_mmio_num -1 ; i >=0 ; i--) {hwaddr base = s->cfg.virtio_mmio.base + i * s->cfg.virtio_mmio.size; -qemu_irq irq =qemu_allocate_irq (xen_set_irq,NULL , +qemu_irq irq =qemu_allocate_irq_orphan (xen_set_irq,NULL , s->cfg.virtio_mmio_irq_base + i); sysbus_create_simple(OBJECT(s), "virtio-mmio[*]", "virtio-mmio",
@@ -260,7 +260,7 @@ static inline void xenpvh_gpex_init(XenPVHMachineState *s,assert (xpc->set_pci_intx_irq);for (i =0 ; i <PCI_NUM_PINS ; i++) { -qemu_irq irq =qemu_allocate_irq (xpc->set_pci_intx_irq, s, i); +qemu_irq irq =qemu_allocate_irq_orphan (xpc->set_pci_intx_irq, s, i);sysbus_connect_irq (SYS_BUS_DEVICE (dev), i, irq);gpex_set_irq_num (GPEX_HOST (dev), i, s->cfg.pci_intx_irq_base + i);
hw/xtensa/mx_pic.c +1 -1
@@ -346,7 +346,7 @@ XtensaMxPic *xtensa_mx_pic_init(unsigned n_irq)XtensaMxPic *mx =g_new0 (XtensaMxPic,1 ); mx->n_irq = n_irq +1 ; - mx->irq_inputs =qemu_allocate_irqs (xtensa_mx_pic_set_irq, mx, + mx->irq_inputs =qemu_allocate_irqs_orphan (xtensa_mx_pic_set_irq, mx, mx->n_irq);return mx; }
hw/xtensa/pic_cpu.c +2 -2
@@ -102,7 +102,7 @@ void xtensa_irq_init(CPUXtensaState *env) {unsigned i; - env->irq_inputs =qemu_allocate_irqs (xtensa_set_irq, env, + env->irq_inputs =qemu_allocate_irqs_orphan (xtensa_set_irq, env, env->config->ninterrupt);if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { env->time_base =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );
@@ -118,7 +118,7 @@ void xtensa_irq_init(CPUXtensaState *env) env->ext_irq_inputs[i] = env->irq_inputs[irq]; } - env->runstall_irq =qemu_allocate_irq (xtensa_set_runstall, env,0 ); + env->runstall_irq =qemu_allocate_irq_orphan (xtensa_set_runstall, env,0 ); }qemu_irq *xtensa_get_extints (CPUXtensaState *env)
include/hw/core/irq.h +4 -4
@@ -77,25 +77,25 @@ void qemu_init_irqs(IRQState irq[], size_t count,/* Returns an array of N IRQs. Each IRQ is assigned the argument handler and * opaque data. */ -qemu_irq *qemu_allocate_irqs (qemu_irq_handler handler,void *opaque,int n); +qemu_irq *qemu_allocate_irqs_orphan (qemu_irq_handler handler,void *opaque,int n);/* * Allocates a single IRQ. The irq is assigned with a handler, an opaque * data and the interrupt number. */ -qemu_irq qemu_allocate_irq (qemu_irq_handler handler,void *opaque,int n); +qemu_irq qemu_allocate_irq_orphan (qemu_irq_handler handler,void *opaque,int n);/* Extends an Array of IRQs. Old IRQs have their handlers and opaque data * preserved. New IRQs are assigned the argument handler and opaque data. */ -qemu_irq *qemu_extend_irqs (qemu_irq *old,int n_old,qemu_irq_handler handler, +qemu_irq *qemu_extend_irqs_orphan (qemu_irq *old,int n_old,qemu_irq_handler handler,void *opaque,int n);void qemu_free_irqs (qemu_irq *s,int n);void qemu_free_irq (qemu_irq irq);/* Returns a new IRQ with opposite polarity. */ -qemu_irq qemu_irq_invert (qemu_irq irq); +qemu_irq qemu_irq_invert_orphan (qemu_irq irq);/* For internal use in qtest. */ void qemu_irq_set_observer (qemu_irq *gpio_in,qemu_irq_handler handler,int n);
scripts/coccinelle/qom-parent/irq-rename.cocci new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Rename the IRQ allocation helpers to *_orphan() so the parented +// variants can take the well-known names. +@@ @@ +- qemu_allocate_irqs ++ qemu_allocate_irqs_orphan +@@ @@ +- qemu_allocate_irq ++ qemu_allocate_irq_orphan +@@ @@ +- qemu_extend_irqs ++ qemu_extend_irqs_orphan +@@ @@ +- qemu_irq_invert ++ qemu_irq_invert_orphan
system/qtest.c +1 -1
@@ -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 (qtest_irq_handler, +qemu_irq icpt =qemu_allocate_irq_orphan (qtest_irq_handler, disconnected, n); *disconnected =qdev_intercept_gpio_out (dev, icpt, name, n);
Signature · 1 line
2.47.1
RFC PATCH v2 110/137 irq: Reintroduce qemu_allocate_irq*() with a mandatory owner and name
In reply to Alexander GrafAdd parented variants of the IRQ allocation helpers under the well-known names, taking (Object *owner, const char *name, ...) as their first two arguments:
qemu_allocate_irq(owner, name, handler, opaque, n) qemu_allocate_irqs(owner, name, handler, opaque, n) qemu_extend_irqs(owner, name, old, n_old, handler, opaque, n) qemu_irq_invert(owner, name, irq)
The new IRQ object is created via object_new_child() so it lands under @owner with a stable path. The array/extend variants suffix "[*]" so callers pass a bare name and get name[0], name[1], ...
qemu_free_irq() is taught to unparent when the IRQ has a QOM parent, so it works for both the *_orphan() and the parented allocation paths during the transition.
The *_orphan() variants stay for now; later commits convert every caller and delete them, at which point the /machine/unattached fallback in qdev_connect_gpio_out_named() also goes away.
AI-used-for: code (refactoring)
--- hw/core/irq.c | 45 ++++++++++++++++++++++++++++++++++++++++++- include/hw/core/irq.h | 15 +++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-)
hw/core/irq.c +44 -1
@@ -96,6 +96,38 @@ qemu_irq qemu_allocate_irq_orphan(qemu_irq_handler handler, void *opaque, int n)return irq; } +qemu_irq qemu_allocate_irq (Object *owner,const char *name, +qemu_irq_handler handler,void *opaque,int n) +{ +IRQState *irq =IRQ (object_new_child (owner, name,TYPE_IRQ )); +init_irq_fields (irq, handler, opaque, n); +return irq; +} + +qemu_irq *qemu_extend_irqs (Object *owner,const char *name, +qemu_irq *old,int n_old, +qemu_irq_handler handler,void *opaque,int n) +{ +qemu_irq *s; +int i; + +if (!old) { + n_old =0 ; + } + s = old ?g_renew (qemu_irq, old, n + n_old) :g_new (qemu_irq, n); +for (i = n_old; i < n + n_old; i++) { + g_autofree char *propname = g_strdup_printf("%s[%d]", name, i); + s[i] =qemu_allocate_irq (owner, propname, handler, opaque, i); + } +return s; +} + +qemu_irq *qemu_allocate_irqs (Object *owner,const char *name, +qemu_irq_handler handler,void *opaque,int n) +{ +return qemu_extend_irqs (owner, name,NULL ,0 , handler, opaque, n); +} +void qemu_free_irqs (qemu_irq *s,int n) {int i;
@@ -107,7 +139,11 @@ void qemu_free_irqs(qemu_irq *s, int n)void qemu_free_irq (qemu_irq irq) { -object_unref (OBJECT (irq)); +if (irq &&OBJECT (irq)->parent) { +object_unparent (OBJECT (irq)); + }else { +object_unref (OBJECT (irq)); + } }static void qemu_notirq (void *opaque,int line,int level)
@@ -124,6 +160,13 @@ qemu_irq qemu_irq_invert_orphan(qemu_irq irq)return qemu_allocate_irq_orphan (qemu_notirq, irq,0 ); } +qemu_irq qemu_irq_invert (Object *owner,const char *name,qemu_irq irq) +{ +/* The default state for IRQs is low, so raise the output now. */ +qemu_irq_raise (irq); +return qemu_allocate_irq (owner, name, qemu_notirq, irq,0 ); +} +void qemu_irq_set_observer (qemu_irq *gpio_in,qemu_irq_handler handler,int n) {int i;
include/hw/core/irq.h +15 -0
@@ -85,6 +85,20 @@ qemu_irq *qemu_allocate_irqs_orphan(qemu_irq_handler handler, void *opaque, int*/ qemu_irq qemu_allocate_irq_orphan (qemu_irq_handler handler,void *opaque,int n); +/* +* Same as the *_orphan() variants above, but the new IRQ objects are +* parented under @owner with property name @name (or @name[*] for the +* array/extend variants). The reference is held by @owner; call +* qemu_free_irq() to unparent and free. +*/ +qemu_irq qemu_allocate_irq (Object *owner,const char *name, +qemu_irq_handler handler,void *opaque,int n); +qemu_irq *qemu_allocate_irqs (Object *owner,const char *name, +qemu_irq_handler handler,void *opaque,int n); +qemu_irq *qemu_extend_irqs (Object *owner,const char *name, +qemu_irq *old,int n_old, +qemu_irq_handler handler,void *opaque,int n); +/* Extends an Array of IRQs. Old IRQs have their handlers and opaque data * preserved. New IRQs are assigned the argument handler and opaque data. */
@@ -96,6 +110,7 @@ void qemu_free_irq(qemu_irq irq);/* Returns a new IRQ with opposite polarity. */ qemu_irq qemu_irq_invert_orphan (qemu_irq irq); +qemu_irq qemu_irq_invert (Object *owner,const char *name,qemu_irq irq);/* For internal use in qtest. */ void qemu_irq_set_observer (qemu_irq *gpio_in,qemu_irq_handler handler,int n);
Signature · 1 line
2.47.1
RFC PATCH v2 111/137 hw/pci, hw/usb, system: Give allocated IRQs an owner and name
In reply to Alexander GrafConvert 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)
--- hw/pci/pci.c | 2 +- hw/usb/vt82c686-uhci-pci.c | 4 ++-- system/qtest.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
hw/pci/pci.c +1 -1
@@ -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)
hw/usb/vt82c686-uhci-pci.c +2 -2
@@ -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[] = {
system/qtest.c +1 -1
@@ -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);
Signature · 1 line
2.47.1
RFC PATCH v2 112/137 hw/i386, hw/xen: Give allocated IRQs an owner and name
In reply to Alexander GrafConvert the IRQ allocation calls in hw/i386 and the Xen accelerator to the parented form. Thread an Object *parent through the small helpers that had none:
pc_gsi_create() -> +Object *parent
x86_allocate_cpu_irq() -> +Object *parent
xen_interrupt_controller_init() -> +Object *parent
Per-site owner/name:
pc.c pc_gsi_create() | parent | "gsi" pc.c a20 line | parent | "a20" pc_piix.c smi | OBJECT(machine) | "smi" x86-cpu.c CPU IRQ | parent | "pic-cpu-irq" microvm.c gsi | OBJECT(mms) | "gsi" kvm/i8259.c | parent | "kvm-pic-irq" xen-hvm.c | parent | "xen-irq"
AI-used-for: code (refactoring)
--- hw/i386/isapc.c | 2 +- hw/i386/kvm/i8259.c | 2 +- hw/i386/microvm.c | 4 ++-- hw/i386/pc.c | 10 +++++----- hw/i386/pc_piix.c | 5 +++-- hw/i386/pc_q35.c | 2 +- hw/i386/x86-cpu.c | 4 ++-- hw/i386/xen/xen-hvm.c | 4 ++-- include/hw/i386/pc.h | 2 +- include/hw/i386/x86.h | 2 +- include/hw/xen/xen.h | 2 +- stubs/xen-hw-stub.c | 2 +- 12 files changed, 21 insertions(+), 20 deletions(-)
hw/i386/isapc.c +1 -1
@@ -106,7 +106,7 @@ static void pc_init_isa(MachineState *machine) } } - gsi_state =pc_gsi_create (&x86ms->gsi, false); + gsi_state =pc_gsi_create (OBJECT (machine), &x86ms->gsi, false); isa_bus =isa_bus_new_bridge (OBJECT (machine), system_memory, system_io, &error_abort);
hw/i386/kvm/i8259.c +1 -1
@@ -136,7 +136,7 @@ qemu_irq *kvm_i8259_init(Object *parent, ISABus *bus)i8259_init_chip (parent,TYPE_KVM_I8259 , bus, true);i8259_init_chip (parent,TYPE_KVM_I8259 , bus, false); -return qemu_allocate_irqs_orphan (kvm_pic_set_irq,NULL ,ISA_NUM_IRQS ); +return qemu_allocate_irqs (parent,"kvm-pic-irq" , kvm_pic_set_irq,NULL ,ISA_NUM_IRQS ); }static void kvm_i8259_class_init (ObjectClass *klass,const void *data)
hw/i386/microvm.c +2 -2
@@ -168,7 +168,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)/* Core components */ ioapics =microvm_ioapics (mms); gsi_state =g_malloc0 (sizeof (*gsi_state)); - x86ms->gsi =qemu_allocate_irqs_orphan (gsi_handler, gsi_state, + x86ms->gsi =qemu_allocate_irqs (OBJECT (mms),"gsi" , gsi_handler, gsi_state,IOAPIC_NUM_PINS * ioapics); isa_bus = isa_bus_new_bridge(OBJECT(mms), get_system_memory(), get_system_io(),
@@ -252,7 +252,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)if (x86ms->pic ==ON_OFF_AUTO_ON || x86ms->pic ==ON_OFF_AUTO_AUTO ) {qemu_irq *i8259; - i8259 =i8259_init (OBJECT (mms), isa_bus,x86_allocate_cpu_irq ()); + i8259 =i8259_init (OBJECT (mms), isa_bus,x86_allocate_cpu_irq (OBJECT (mms)));for (i =0 ; i <ISA_NUM_IRQS ; i++) { gsi_state->i8259_irq[i] = i8259[i]; }
hw/i386/pc.c +5 -5
@@ -192,7 +192,7 @@ const size_t pc_compat_4_1_len = G_N_ELEMENTS(pc_compat_4_1);*/ #define PC_FW_DATA (0x20000 + 0x8000) -GSIState *pc_gsi_create (qemu_irq **irqs,bool pci_enabled) +GSIState *pc_gsi_create (Object *parent,qemu_irq **irqs,bool pci_enabled) {GSIState *s;
@@ -200,7 +200,7 @@ GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled)if (kvm_ioapic_in_kernel ()) {kvm_pc_setup_irq_routing (pci_enabled); } - *irqs =qemu_allocate_irqs_orphan (gsi_handler, s,IOAPIC_NUM_PINS ); + *irqs =qemu_allocate_irqs (parent,"gsi" , gsi_handler, s,IOAPIC_NUM_PINS );return s; }
@@ -1028,7 +1028,7 @@ static void pc_superio_init(Object *parent, ISABus *isa_bus, bool create_fdctrl, } port92 =isa_create_simple (parent,"port92" , isa_bus,TYPE_PORT92 ); - a20_line =qemu_allocate_irqs_orphan (handle_a20_line_change, first_cpu,2 ); + a20_line =qemu_allocate_irqs (parent,"a20" , handle_a20_line_change, first_cpu,2 );qdev_connect_gpio_out_named (DEVICE (i8042),I8042_A20_LINE ,0 , a20_line[0 ]); qdev_connect_gpio_out_named(DEVICE(port92),
@@ -1167,9 +1167,9 @@ void pc_i8259_create(Object *parent, ISABus *isa_bus, qemu_irq *i8259_irqs)if (kvm_pic_in_kernel ()) { i8259 =kvm_i8259_init (parent, isa_bus); }else if (xen_enabled ()) { - i8259 =xen_interrupt_controller_init (); + i8259 =xen_interrupt_controller_init (parent); }else { - i8259 =i8259_init (parent, isa_bus,x86_allocate_cpu_irq ()); + i8259 =i8259_init (parent, isa_bus,x86_allocate_cpu_irq (parent)); }for (size_t i =0 ; i <ISA_NUM_IRQS ; i++) {
hw/i386/pc_piix.c +3 -2
@@ -233,7 +233,7 @@ static void pc_init1(MachineState *machine, const char *pci_type) } } - gsi_state =pc_gsi_create (&x86ms->gsi, true); + gsi_state =pc_gsi_create (OBJECT (machine), &x86ms->gsi, true); pci_dev =pci_new_multifunction (OBJECT (machine),"south-bridge" ,-1 , pcms->south_bridge);
@@ -299,7 +299,8 @@ static void pc_init1(MachineState *machine, const char *pci_type)pc_nic_init (pcmc, isa_bus, pcms->pcibus);if (piix4_pm) { - smi_irq =qemu_allocate_irq_orphan (pc_acpi_smi_interrupt, first_cpu,0 ); + smi_irq =qemu_allocate_irq (OBJECT (machine),"smi" , + pc_acpi_smi_interrupt, first_cpu,0 );qdev_connect_gpio_out_named (DEVICE (piix4_pm),"smi-irq" ,0 , smi_irq); pcms->smbus =I2C_BUS (qdev_get_child_bus (DEVICE (piix4_pm),"i2c" ));
hw/i386/pc_q35.c +1 -1
@@ -233,7 +233,7 @@ static void pc_q35_init(MachineState *machine) pcms->pcibus =PCI_BUS (qdev_get_child_bus (DEVICE (phb),"pcie.0" ));/* irq lines */ - gsi_state =pc_gsi_create (&x86ms->gsi, true); + gsi_state =pc_gsi_create (OBJECT (machine), &x86ms->gsi, true);/* create ISA bus */ lpc = pci_new_multifunction(OBJECT(machine), "lpc",
hw/i386/x86-cpu.c +2 -2
@@ -61,9 +61,9 @@ static void pic_irq_request(void *opaque, int irq, int level) } } -qemu_irq x86_allocate_cpu_irq (void ) +qemu_irq x86_allocate_cpu_irq (Object *parent) { -return qemu_allocate_irq_orphan (pic_irq_request,NULL ,0 ); +return qemu_allocate_irq (parent,"pic-cpu-irq" , pic_irq_request,NULL ,0 ); }int cpu_get_pic_interrupt (CPUX86State *env)
hw/i386/xen/xen-hvm.c +2 -2
@@ -112,9 +112,9 @@ static void xen_set_irq(void *opaque, int irq, int level)xen_set_isa_irq_level (xen_domid, irq, level); } -qemu_irq *xen_interrupt_controller_init (void ) +qemu_irq *xen_interrupt_controller_init (Object *parent) { -return qemu_allocate_irqs_orphan (xen_set_irq,NULL ,16 ); +return qemu_allocate_irqs (parent,"xen-irq" , xen_set_irq,NULL ,16 ); }/* Memory Ops */
include/hw/i386/pc.h +1 -1
@@ -126,7 +126,7 @@ OBJECT_DECLARE_TYPE(PCMachineState, PCMachineClass, PC_MACHINE)/* ioapic.c */ -GSIState *pc_gsi_create (qemu_irq **irqs,bool pci_enabled); +GSIState *pc_gsi_create (Object *parent,qemu_irq **irqs,bool pci_enabled);/* pc.c */
include/hw/i386/x86.h +1 -1
@@ -145,7 +145,7 @@ typedef struct GSIState {qemu_irq ioapic2_irq[IOAPIC_NUM_PINS ]; } GSIState; -qemu_irq x86_allocate_cpu_irq (void ); +qemu_irq x86_allocate_cpu_irq (Object *parent);void gsi_handler (void *opaque,int n,int level);void ioapic_init_gsi (GSIState *gsi_state,Object *parent);DeviceState *ioapic_init_secondary (Object *parent,GSIState *gsi_state);
include/hw/xen/xen.h +1 -1
@@ -42,7 +42,7 @@ void xen_intx_set_irq(void *opaque, int irq_num, int level);void xen_hvm_inject_msi (uint64_t addr,uint32_t data);int xen_is_pirq_msi (uint32_t msi_data); -qemu_irq *xen_interrupt_controller_init (void ); +qemu_irq *xen_interrupt_controller_init (Object *parent);void xen_register_framebuffer (struct MemoryRegion *mr);
stubs/xen-hw-stub.c +1 -1
@@ -29,7 +29,7 @@ int xen_is_pirq_msi(uint32_t msi_data)return 0 ; } -qemu_irq *xen_interrupt_controller_init (void ) +qemu_irq *xen_interrupt_controller_init (Object *parent) {return NULL ; }
Signature · 1 line
2.47.1
RFC PATCH v2 113/137 hw/arm: Give allocated IRQs an owner and name
In reply to Alexander GrafConvert the IRQ allocation calls in hw/arm boards and the OMAP peripheral models to the parented form. Thread an Object *owner through the small helpers that had none:
omap_timer_clk_setup() -> +Object *owner omap_mcbsp_i2s_attach() -> +Object *owner (no callers, kept for API)
The OMAP init helpers are called multiple times from omap310_mpu_init() so their IRQ names use the auto-index [*] form.
AI-used-for: code (refactoring)
--- hw/arm/armsse.c | 5 +++-- hw/arm/exynos4_boards.c | 3 ++- hw/arm/mps2-tz.c | 3 ++- hw/arm/omap1.c | 29 +++++++++++++++++------------ hw/arm/realview.c | 3 ++- hw/arm/stellaris.c | 15 ++++++++++----- hw/dma/omap_dma.c | 5 +++-- hw/timer/arm_timer.c | 6 ++++-- include/hw/arm/omap.h | 2 +- 9 files changed, 44 insertions(+), 27 deletions(-)
hw/arm/armsse.c +3 -2
@@ -693,7 +693,8 @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s)DeviceState *dev_splitter =DEVICE (&s->sec_resp_splitter);qdev_init_gpio_out_named (dev, &s->sec_resp_cfg,"sec_resp_cfg" ,1 ); - s->sec_resp_cfg_in =qemu_allocate_irq_orphan (irq_status_forwarder, + s->sec_resp_cfg_in =qemu_allocate_irq (OBJECT (s),"sec-resp-cfg-in" , + irq_status_forwarder, s->sec_resp_cfg,1 );qdev_connect_gpio_out (dev_splitter,2 , s->sec_resp_cfg_in); }
@@ -1137,7 +1138,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (sbd_secctl,0 ,0x50080000 );sysbus_mmio_map (sbd_secctl,1 ,0x40080000 ); - s->nsc_cfg_in =qemu_allocate_irq_orphan (nsccfg_handler, s,1 ); + s->nsc_cfg_in =qemu_allocate_irq (OBJECT (dev),"nsc-cfg-in" , nsccfg_handler, s,1 );qdev_connect_gpio_out_named (dev_secctl,"nsc_cfg" ,0 , s->nsc_cfg_in);/* The sec_resp_cfg output from the security controller must be split into
hw/arm/exynos4_boards.c +2 -1
@@ -146,7 +146,8 @@ static void smdkc210_init(MachineState *machine) EXYNOS4_BOARD_SMDKC210);lan9215_init (SMDK_LAN9118_BASE_ADDR , -qemu_irq_invert_orphan (s->soc.irq_table[exynos4210_get_irq (37 ,1 )])); +qemu_irq_invert (OBJECT (machine),"lan9118-irq-inv" , + s->soc.irq_table[exynos4210_get_irq (37 ,1 )]));arm_load_kernel (s->soc.cpu[0 ], machine, &exynos4_board_binfo); }
hw/arm/mps2-tz.c +2 -1
@@ -1209,7 +1209,8 @@ static void mps2tz_common_init(MachineState *machine)* Connect the line from the SCC so that we can remap when the * guest updates that register. */ - mms->remap_irq =qemu_allocate_irq_orphan (remap_irq_fn, mms,0 ); + mms->remap_irq =qemu_allocate_irq (OBJECT (machine),"remap-irq" , + remap_irq_fn, mms,0 );qdev_connect_gpio_out_named (DEVICE (&mms->scc),"remap" ,0 , mms->remap_irq); }
hw/arm/omap1.c +17 -12
@@ -136,10 +136,11 @@ static void omap_timer_clk_update(void *opaque, int line, int on)omap_timer_update (timer); } -static void omap_timer_clk_setup (struct omap_mpu_timer_s *timer) +static void omap_timer_clk_setup (Object *owner,struct omap_mpu_timer_s *timer) {omap_clk_adduser (timer->clk, -qemu_allocate_irq_orphan (omap_timer_clk_update, timer,0 )); +qemu_allocate_irq (owner,"rate-irq[*]" , + omap_timer_clk_update, timer,0 )); timer->rate =omap_clk_getrate (timer->clk); }
@@ -232,7 +233,7 @@ static struct omap_mpu_timer_s *omap_mpu_timer_init(Object *owner, s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , omap_timer_tick, s); s->tick =qemu_bh_new (omap_timer_fire, s);omap_mpu_timer_reset (s); -omap_timer_clk_setup (s); +omap_timer_clk_setup (owner, s);memory_region_init_io (&s->iomem, owner, &omap_mpu_timer_ops, s,"omap-mpu-timer" ,0x100 );
@@ -363,7 +364,7 @@ static struct omap_watchdog_timer_s *omap_wd_timer_init(Object *owner, s->timer.clk = clk; s->timer.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , omap_timer_tick, &s->timer);omap_wd_timer_reset (s); -omap_timer_clk_setup (&s->timer); +omap_timer_clk_setup (owner, &s->timer);memory_region_init_io (&s->iomem, owner, &omap_wd_timer_ops, s,"omap-wd-timer" ,0x100 );
@@ -472,7 +473,7 @@ static struct omap_32khz_timer_s *omap_os_timer_init(Object *owner, s->timer.clk = clk; s->timer.timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , omap_timer_tick, &s->timer);omap_os_timer_reset (s); -omap_timer_clk_setup (&s->timer); +omap_timer_clk_setup (owner, &s->timer);memory_region_init_io (&s->iomem, owner, &omap_os_timer_ops, s,"omap-os-timer" ,0x800 );
@@ -2083,14 +2084,15 @@ static struct omap_mpuio_s *omap_mpuio_init(Object *owner, s->irq = gpio_int; s->kbd_irq = kbd_int; - s->in =qemu_allocate_irqs_orphan (omap_mpuio_set, s,16 ); + s->in =qemu_allocate_irqs (owner,"mpuio-in" , omap_mpuio_set, s,16 );omap_mpuio_reset (s);memory_region_init_io (&s->iomem, owner, &omap_mpuio_ops, s,"omap-mpuio" ,0x800 );memory_region_add_subregion (memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irq_orphan (omap_mpuio_onoff, s,0 )); +omap_clk_adduser (clk,qemu_allocate_irq (owner,"mpuio-clk-onoff[*]" , + omap_mpuio_onoff, s,0 ));return s; }
@@ -2363,7 +2365,8 @@ static struct omap_pwl_s *omap_pwl_init(Object *owner, "omap-pwl", 0x800);memory_region_add_subregion (system_memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irq_orphan (omap_pwl_clk_update, s,0 )); +omap_clk_adduser (clk,qemu_allocate_irq (owner,"pwl-clk-irq[*]" , + omap_pwl_clk_update, s,0 ));return s; }
@@ -3423,11 +3426,12 @@ static void omap_mcbsp_i2s_start(void *opaque, int line, int level) } } -void omap_mcbsp_i2s_attach (struct omap_mcbsp_s *s,I2SCodec *slave) +void omap_mcbsp_i2s_attach (Object *owner,struct omap_mcbsp_s *s,I2SCodec *slave) { s->codec = slave; - slave->rx_swallow =qemu_allocate_irq_orphan (omap_mcbsp_i2s_swallow, s,0 ); - slave->tx_start =qemu_allocate_irq_orphan (omap_mcbsp_i2s_start, s,0 ); + slave->rx_swallow =qemu_allocate_irq (owner,"rx-swallow[*]" , + omap_mcbsp_i2s_swallow, s,0 ); + slave->tx_start =qemu_allocate_irq (owner,"tx-start[*]" , omap_mcbsp_i2s_start, s,0 ); }/* LED Pulse Generators */
@@ -3579,7 +3583,8 @@ static struct omap_lpg_s *omap_lpg_init(Object *owner, "omap-lpg", 0x800);memory_region_add_subregion (system_memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irq_orphan (omap_lpg_clk_update, s,0 )); +omap_clk_adduser (clk,qemu_allocate_irq (owner,"lpg-clk-irq[*]" , + omap_lpg_clk_update, s,0 ));return s; }
hw/arm/realview.c +2 -1
@@ -276,7 +276,8 @@ static void realview_init(MachineState *machine,split_irq_from_named (OBJECT (machine), dev,"card-inserted" ,qdev_get_gpio_in (sysctl,ARM_SYSCTL_GPIO_MMC_CARDIN ), -qemu_irq_invert_orphan (qdev_get_gpio_in (gpio2,0 ))); +qemu_irq_invert (OBJECT (machine),"mmc-cd-inv" , +qdev_get_gpio_in (gpio2,0 ))); dinfo =drive_get (IF_SD ,0 ,0 );if (dinfo) {
hw/arm/stellaris.c +10 -5
@@ -1358,15 +1358,20 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)sysbus_realize (SYS_BUS_DEVICE (gpad), &error_fatal);qdev_connect_gpio_out (gpad,0 , -qemu_irq_invert_orphan (gpio_in[GPIO_E ][0 ]));/* up */ +qemu_irq_invert (OBJECT (ms),"gpio-in-irq[*]" , + gpio_in[GPIO_E ][0 ]));/* up */ qdev_connect_gpio_out (gpad,1 , -qemu_irq_invert_orphan (gpio_in[GPIO_E ][1 ]));/* down */ +qemu_irq_invert (OBJECT (ms),"gpio-in-irq[*]" , + gpio_in[GPIO_E ][1 ]));/* down */ qdev_connect_gpio_out (gpad,2 , -qemu_irq_invert_orphan (gpio_in[GPIO_E ][2 ]));/* left */ +qemu_irq_invert (OBJECT (ms),"gpio-in-irq[*]" , + gpio_in[GPIO_E ][2 ]));/* left */ qdev_connect_gpio_out (gpad,3 , -qemu_irq_invert_orphan (gpio_in[GPIO_E ][3 ]));/* right */ +qemu_irq_invert (OBJECT (ms),"gpio-in-irq[*]" , + gpio_in[GPIO_E ][3 ]));/* right */ qdev_connect_gpio_out (gpad,4 , -qemu_irq_invert_orphan (gpio_in[GPIO_F ][1 ]));/* select */ +qemu_irq_invert (OBJECT (ms),"gpio-in-irq[*]" , + gpio_in[GPIO_F ][1 ]));/* select */ }for (i =0 ; i <7 ; i++) {if (board->dc4 & (1 << i)) {
hw/dma/omap_dma.c +3 -2
@@ -1109,7 +1109,7 @@ struct soc_dma_s *omap_dma_init(Object *owner, hwaddr base, qemu_irq *irqs, s->dma->freq =omap_clk_getrate (clk); s->dma->transfer_fn = omap_dma_transfer_generic; s->dma->setup_fn = omap_dma_transfer_setup; - s->dma->drq =qemu_allocate_irqs_orphan (omap_dma_request, s,32 ); + s->dma->drq =qemu_allocate_irqs (owner,"drq" , omap_dma_request, s,32 ); s->dma->opaque = s;while (num_irqs --)
@@ -1123,7 +1123,8 @@ struct soc_dma_s *omap_dma_init(Object *owner, hwaddr base, qemu_irq *irqs, s->dma->ch[i].opaque = &s->ch[i]; } -omap_clk_adduser (s->clk,qemu_allocate_irq_orphan (omap_dma_clk_update, s,0 )); +omap_clk_adduser (s->clk,qemu_allocate_irq (owner,"clk-irq" , + omap_dma_clk_update, s,0 ));omap_dma_reset (s->dma);omap_dma_clk_update (s,0 ,1 );
hw/timer/arm_timer.c +4 -2
@@ -305,8 +305,10 @@ static void sp804_realize(DeviceState *dev, Error **errp) s->timer[0 ] =arm_timer_init (s->freq0); s->timer[1 ] =arm_timer_init (s->freq1); - s->timer[0 ]->irq =qemu_allocate_irq_orphan (sp804_set_irq, s,0 ); - s->timer[1 ]->irq =qemu_allocate_irq_orphan (sp804_set_irq, s,1 ); + s->timer[0 ]->irq =qemu_allocate_irq (OBJECT (dev),"timer-irq[*]" , + sp804_set_irq, s,0 ); + s->timer[1 ]->irq =qemu_allocate_irq (OBJECT (dev),"timer-irq[*]" , + sp804_set_irq, s,1 ); }/* Integrator/CP timer module. */
include/hw/arm/omap.h +1 -1
@@ -291,7 +291,7 @@ struct I2SCodec { } in, out; };struct omap_mcbsp_s ; -void omap_mcbsp_i2s_attach (struct omap_mcbsp_s *s,I2SCodec *slave); +void omap_mcbsp_i2s_attach (Object *owner,struct omap_mcbsp_s *s,I2SCodec *slave);/* omap_lcdc.c */ struct omap_lcd_panel_s ;
Signature · 1 line
2.47.1
RFC PATCH v2 114/137 hw/xtensa: Give allocated IRQs an owner and name
In reply to Alexander GrafThread an Object *owner through xtensa_mx_pic_init() and use the CPU object as owner for the per-CPU IRQ input arrays.
AI-used-for: code (refactoring)
--- hw/xtensa/mx_pic.c | 4 ++-- hw/xtensa/pic_cpu.c | 5 +++-- hw/xtensa/xtfpga.c | 2 +- include/hw/xtensa/mx_pic.h | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-)
hw/xtensa/mx_pic.c +2 -2
@@ -341,12 +341,12 @@ static void xtensa_mx_pic_set_irq(void *opaque, int irq, int active) } } -XtensaMxPic *xtensa_mx_pic_init (unsigned n_irq) +XtensaMxPic *xtensa_mx_pic_init (Object *owner,unsigned n_irq) {XtensaMxPic *mx =g_new0 (XtensaMxPic,1 ); mx->n_irq = n_irq +1 ; - mx->irq_inputs =qemu_allocate_irqs_orphan (xtensa_mx_pic_set_irq, mx, + mx->irq_inputs =qemu_allocate_irqs (owner,"irq" , xtensa_mx_pic_set_irq, mx, mx->n_irq);return mx; }
hw/xtensa/pic_cpu.c +3 -2
@@ -100,9 +100,10 @@ static void xtensa_set_runstall(void *opaque, int irq, int active)void xtensa_irq_init (CPUXtensaState *env) { +Object *cpu =OBJECT (env_cpu (env));unsigned i; - env->irq_inputs =qemu_allocate_irqs_orphan (xtensa_set_irq, env, + env->irq_inputs =qemu_allocate_irqs (cpu,"irq-in" , xtensa_set_irq, env, env->config->ninterrupt);if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { env->time_base =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );
@@ -118,7 +119,7 @@ void xtensa_irq_init(CPUXtensaState *env) env->ext_irq_inputs[i] = env->irq_inputs[irq]; } - env->runstall_irq =qemu_allocate_irq_orphan (xtensa_set_runstall, env,0 ); + env->runstall_irq =qemu_allocate_irq (cpu,"runstall" , xtensa_set_runstall, env,0 ); }qemu_irq *xtensa_get_extints (CPUXtensaState *env)
hw/xtensa/xtfpga.c +1 -1
@@ -247,7 +247,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)Object *mo =OBJECT (machine);if (smp_cpus >1 ) { - mx_pic =xtensa_mx_pic_init (31 ); + mx_pic =xtensa_mx_pic_init (mo,31 );qemu_register_reset (xtensa_mx_pic_reset, mx_pic); }for (n =0 ; n < smp_cpus; n++) {
include/hw/xtensa/mx_pic.h +1 -1
@@ -33,7 +33,7 @@struct XtensaMxPic ;typedef struct XtensaMxPic XtensaMxPic ; -XtensaMxPic *xtensa_mx_pic_init (unsigned n_extint); +XtensaMxPic *xtensa_mx_pic_init (Object *owner,unsigned n_extint);void xtensa_mx_pic_reset (void *opaque); MemoryRegion *xtensa_mx_pic_register_cpu(Object *owner, XtensaMxPic *mx, qemu_irq *irq,
Signature · 1 line
2.47.1
RFC PATCH v2 115/137 hw: Give allocated IRQs an owner and name
In reply to Alexander GrafConvert the remaining IRQ allocation calls across hw/ to the parented form. Owner is the enclosing device for realize()-time allocations and the machine for board-init allocations. Names describe the pin's purpose; the auto-indexed [*] form is used where the same allocation runs in a loop.
AI-used-for: code (refactoring)
--- hw/alpha/typhoon.c | 4 ++-- hw/char/diva-gsp.c | 3 ++- hw/display/macfb.c | 2 +- hw/ide/ahci.c | 2 +- hw/ide/pci.c | 2 +- hw/intc/sh_intc.c | 2 +- hw/isa/i82378.c | 3 ++- hw/isa/lpc_ich9.c | 2 +- hw/m68k/mcf5206.c | 2 +- hw/m68k/q800.c | 4 ++-- hw/mips/mips_int.c | 2 +- hw/net/can/can_kvaser_pci.c | 2 +- hw/pci-host/pnv_phb3.c | 3 ++- hw/pci-host/pnv_phb3_msi.c | 3 ++- hw/pci-host/pnv_phb4.c | 3 ++- hw/ppc/e500.c | 3 ++- hw/ppc/pnv_lpc.c | 2 +- hw/ppc/pnv_psi.c | 6 ++++-- hw/ppc/spapr_irq.c | 2 +- hw/riscv/sifive_u.c | 3 ++- hw/scsi/esp-pci.c | 2 +- hw/sh4/sh7750.c | 2 +- hw/sparc/sun4m.c | 5 +++-- hw/sparc64/sun4u.c | 3 ++- hw/xen/xen-pvh-common.c | 5 +++-- 25 files changed, 42 insertions(+), 30 deletions(-)
hw/alpha/typhoon.c +2 -2
@@ -849,8 +849,8 @@ PCIBus *typhoon_init(Object *parent, MemoryRegion *ram, qemu_irq *p_isa_irq, } } - *p_isa_irq =qemu_allocate_irq_orphan (typhoon_set_isa_irq, s,0 ); - *p_rtc_irq =qemu_allocate_irq_orphan (typhoon_set_timer_irq, s,0 ); + *p_isa_irq =qemu_allocate_irq (parent,"isa-irq" , typhoon_set_isa_irq, s,0 ); + *p_rtc_irq =qemu_allocate_irq (parent,"rtc-irq" , typhoon_set_timer_irq, s,0 );/* Main memory region, 0x00.0000.0000. Real hardware supports 32GB, but the address space hole reserved at this point is 8TB. */
hw/char/diva-gsp.c +2 -1
@@ -126,7 +126,8 @@ static void diva_pci_realize(PCIDevice *dev, Error **errp) pci->dev.config[PCI_INTERRUPT_PIN ] =1 ;memory_region_init (&pci->membar,OBJECT (pci),"serial_ports" ,4096 );pci_register_bar (&pci->dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &pci->membar); - pci->irqs =qemu_allocate_irqs_orphan (multi_serial_irq_mux, pci, di.nports); + pci->irqs =qemu_allocate_irqs (OBJECT (dev),"serial-irq" , + multi_serial_irq_mux, pci, di.nports);for (i =0 ; i < di.nports; i++) { s = pci->state + i;
hw/display/macfb.c +1 -1
@@ -737,7 +737,7 @@ static void macfb_nubus_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&nd->slot_mem,DAFB_BASE , &ms->mem_ctrl);memory_region_add_subregion (&nd->slot_mem,VIDEO_BASE , &ms->mem_vram); - ms->irq =qemu_allocate_irq_orphan (macfb_nubus_set_irq, s,0 ); + ms->irq =qemu_allocate_irq (OBJECT (dev),"nubus-irq" , macfb_nubus_set_irq, s,0 ); }static void macfb_nubus_unrealize (DeviceState *dev)
hw/ide/ahci.c +1 -1
@@ -1594,7 +1594,7 @@ void ahci_realize(AHCIState *s, DeviceState *qdev, AddressSpace *as)assert (s->ports >0 ); s->dev =g_new0 (AHCIDevice, s->ports);ahci_reg_init (s); - irqs =qemu_allocate_irqs_orphan (ahci_irq_set, s, s->ports); + irqs =qemu_allocate_irqs (OBJECT (qdev),"port-irq" , ahci_irq_set, s, s->ports);for (i =0 ; i < s->ports; i++) {AHCIDevice *ad = &s->dev[i];
hw/ide/pci.c +1 -1
@@ -606,7 +606,7 @@ void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d) bm->dma.ops = &bmdma_ops; bus->dma = &bm->dma; bm->irq = bus->irq; - bus->irq =qemu_allocate_irq_orphan (bmdma_irq, bm,0 ); + bus->irq =qemu_allocate_irq (OBJECT (d),"bmdma-irq[*]" , bmdma_irq, bm,0 ); bm->bus = bus; bm->pci_dev = d; }
hw/intc/sh_intc.c +1 -1
@@ -403,7 +403,7 @@ int sh_intc_init(Object *owner, MemoryRegion *sysmem,for (i =0 ; i < nr_sources; i++) { desc->sources[i].parent = desc; } - desc->irqs =qemu_allocate_irqs_orphan (sh_intc_set_irq, desc, nr_sources); + desc->irqs =qemu_allocate_irqs (owner,"src-irq" , sh_intc_set_irq, desc, nr_sources);memory_region_init_io (&desc->iomem, owner, &sh_intc_ops, desc,"intc" ,0x100000000ULL ); j =0 ;
hw/isa/i82378.c +2 -1
@@ -95,7 +95,8 @@ static void i82378_realize(PCIDevice *pci, Error **errp)/* 2 82C59 (irq) */ s->isa_irqs_in =i8259_init (OBJECT (pci), isabus, -qemu_allocate_irq_orphan (i82378_request_out0_irq, +qemu_allocate_irq (OBJECT (dev),"out0-irq" , + i82378_request_out0_irq, s,0 ));isa_bus_register_input_irqs (isabus, s->isa_irqs_in);
hw/isa/lpc_ich9.c +1 -1
@@ -429,7 +429,7 @@ static void ich9_lpc_pm_init(ICH9LPCState *lpc)qemu_irq sci_irq;FWCfgState *fw_cfg =fw_cfg_find (); - sci_irq =qemu_allocate_irq_orphan (ich9_set_sci, lpc,0 ); + sci_irq =qemu_allocate_irq (OBJECT (lpc),"sci-irq" , ich9_set_sci, lpc,0 );ich9_pm_init (PCI_DEVICE (lpc), &lpc->pm, sci_irq);if (lpc->smi_host_features && fw_cfg) {
hw/m68k/mcf5206.c +1 -1
@@ -593,7 +593,7 @@ static void mcf5206_mbar_realize(DeviceState *dev, Error **errp) "mbar", 0x00001000);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem); - s->pic =qemu_allocate_irqs_orphan (m5206_mbar_set_irq, s,14 ); + s->pic =qemu_allocate_irqs (OBJECT (dev),"pic-irq" , m5206_mbar_set_irq, s,14 );m5206_timer_init (&s->timer[0 ], s->pic[9 ]);m5206_timer_init (&s->timer[1 ], s->pic[10 ]); s->uart[0 ] =mcf_uart_create (OBJECT (s), s->pic[12 ],serial_hd (0 ));
hw/m68k/q800.c +2 -2
@@ -474,11 +474,11 @@ static void q800_machine_init(MachineState *machine)sysbus_realize (sysbus, &error_fatal);/* SCSI and SCSI data IRQs are negative edge triggered */ sysbus_connect_irq (sysbus,0 , -qemu_irq_invert_orphan ( +qemu_irq_invert (OBJECT (machine),"scsi-irq-inv" ,qdev_get_gpio_in (DEVICE (&m->via2),VIA2_IRQ_SCSI_BIT )));sysbus_connect_irq (sysbus,1 , -qemu_irq_invert_orphan ( +qemu_irq_invert (OBJECT (machine),"scsi-drq-inv" ,qdev_get_gpio_in (DEVICE (&m->via2),VIA2_IRQ_SCSI_DATA_BIT ))); memory_region_add_subregion(&m->macio, ESP_BASE - IO_BASE,
hw/mips/mips_int.c +1 -1
@@ -56,7 +56,7 @@ void cpu_mips_irq_init_cpu(MIPSCPU *cpu)qemu_irq *qi;int i; - qi =qemu_allocate_irqs_orphan (cpu_mips_irq_request, cpu,8 ); + qi =qemu_allocate_irqs (OBJECT (cpu),"cpu-irq" , cpu_mips_irq_request, cpu,8 );for (i =0 ; i <8 ; i++) { env->irq[i] = qi[i]; }
hw/net/can/can_kvaser_pci.c +1 -1
@@ -224,7 +224,7 @@ static void kvaser_pci_realize(PCIDevice *pci_dev, Error **errp) pci_conf = pci_dev->config; pci_conf[PCI_INTERRUPT_PIN ] =0x01 ;/* interrupt pin A */ - d->irq =qemu_allocate_irq_orphan (kvaser_pci_irq_handler, d,0 ); + d->irq =qemu_allocate_irq (OBJECT (s),"kvaser-irq" , kvaser_pci_irq_handler, d,0 );can_sja_init (s, d->irq);
hw/pci-host/pnv_phb3.c +2 -1
@@ -1054,7 +1054,8 @@ static void pnv_phb3_realize(DeviceState *dev, Error **errp)ics_set_irq_type (&phb->lsis, i, true); } - phb->qirqs =qemu_allocate_irqs_orphan (ics_set_irq, &phb->lsis, phb->lsis.nr_irqs); + phb->qirqs =qemu_allocate_irqs (OBJECT (dev),"lsi-irq" , + ics_set_irq, &phb->lsis, phb->lsis.nr_irqs);/* MSI sources */ object_property_set_link(OBJECT(&phb->msis), "phb", OBJECT(phb),
hw/pci-host/pnv_phb3_msi.c +2 -1
@@ -267,7 +267,8 @@ static void phb3_msi_realize(DeviceState *dev, Error **errp)return ; } - msi->qirqs =qemu_allocate_irqs_orphan (phb3_msi_set_irq, msi, ics->nr_irqs); + msi->qirqs =qemu_allocate_irqs (OBJECT (dev),"msi-irq" , + phb3_msi_set_irq, msi, ics->nr_irqs); }static void phb3_msi_instance_init (Object *obj)
hw/pci-host/pnv_phb4.c +2 -1
@@ -1605,7 +1605,8 @@ static void pnv_phb4_realize(DeviceState *dev, Error **errp)pnv_phb4_update_xsrc (phb); - phb->qirqs =qemu_allocate_irqs_orphan (xive_source_set_irq, xsrc, xsrc->nr_irqs); + phb->qirqs =qemu_allocate_irqs (OBJECT (dev),"lsi-irq" , + xive_source_set_irq, xsrc, xsrc->nr_irqs);pnv_phb4_xscom_realize (phb); }
hw/ppc/e500.c +2 -1
@@ -1089,7 +1089,8 @@ void ppce500_init(MachineState *machine) sysbus_mmio_get_region(s, 0));/* Power Off GPIO at Pin 0 */ - poweroff_irq =qemu_allocate_irq_orphan (ppce500_power_off,NULL ,0 ); + poweroff_irq =qemu_allocate_irq (OBJECT (machine),"poweroff" , + ppce500_power_off,NULL ,0 );qdev_connect_gpio_out (dev,0 , poweroff_irq); }
hw/ppc/pnv_lpc.c +1 -1
@@ -993,7 +993,7 @@ ISABus *pnv_lpc_isa_create(PnvLpcController *lpc, bool use_cpld, Error **errp) }/* POWER has a 17th irq, QEMU only implements the 16 regular device irqs */ - irqs =qemu_allocate_irqs_orphan (handler, lpc,ISA_NUM_IRQS ); + irqs =qemu_allocate_irqs (OBJECT (lpc),"isa-irq" , handler, lpc,ISA_NUM_IRQS );isa_bus_register_input_irqs (isa_bus, irqs);
hw/ppc/pnv_psi.c +4 -2
@@ -509,7 +509,8 @@ static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)qdev_init_gpio_in (dev, pnv_psi_power8_set_irq, ics->nr_irqs); - psi->qirqs =qemu_allocate_irqs_orphan (ics_set_irq, ics, ics->nr_irqs); + psi->qirqs =qemu_allocate_irqs (OBJECT (dev),"psi-irq" , + ics_set_irq, ics, ics->nr_irqs);/* XSCOM region for PSI registers */ pnv_xscom_region_init(&psi->xscom_regs, OBJECT(dev), &pnv_psi_xscom_ops,
@@ -872,7 +873,8 @@ static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)xive_source_irq_set_lsi (xsrc, i); } - psi->qirqs =qemu_allocate_irqs_orphan (xive_source_set_irq, xsrc, xsrc->nr_irqs); + psi->qirqs =qemu_allocate_irqs (OBJECT (dev),"psi-irq" , + xive_source_set_irq, xsrc, xsrc->nr_irqs);qdev_init_gpio_in (dev, pnv_psi_power9_set_irq, xsrc->nr_irqs);
hw/ppc/spapr_irq.c +1 -1
@@ -339,7 +339,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)spapr_xive_hcall_init (spapr); } - spapr->qirqs =qemu_allocate_irqs_orphan (spapr_set_irq, spapr, + spapr->qirqs =qemu_allocate_irqs (OBJECT (spapr),"irq" , spapr_set_irq, spapr,SPAPR_NR_XIRQS +SPAPR_IRQ_NR_IPIS );/*
hw/riscv/sifive_u.c +2 -1
@@ -484,7 +484,8 @@ static void sifive_u_machine_init(MachineState *machine)/* register gpio-restart */ qdev_connect_gpio_out (DEVICE (&(s->soc.gpio)),10 , -qemu_allocate_irq_orphan (sifive_u_machine_reset,NULL ,0 )); +qemu_allocate_irq (OBJECT (machine),"reset-irq" , + sifive_u_machine_reset,NULL ,0 ));/* load/create device tree */ if (machine->dtb) {
hw/scsi/esp-pci.c +1 -1
@@ -407,7 +407,7 @@ static void esp_pci_scsi_realize(PCIDevice *dev, Error **errp) "esp-io", 0x80);pci_register_bar (dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , &pci->io); - s->irq =qemu_allocate_irq_orphan (esp_irq_handler, pci,0 ); + s->irq =qemu_allocate_irq (OBJECT (s),"esp-irq" , esp_irq_handler, pci,0 );scsi_bus_init (&s->bus,sizeof (s->bus), d, &esp_pci_scsi_info); }
hw/sh4/sh7750.c +1 -1
@@ -848,5 +848,5 @@ SH7750State *sh7750_init(Object *parent, SuperHCPU *cpu,qemu_irq sh7750_irl (SH7750State *s) {sh_intc_toggle_source (&s->intc.sources[IRL ],1 ,0 );/* enable */ -return qemu_allocate_irq_orphan (sh_intc_set_irl, &s->intc.sources[IRL ],0 ); +return qemu_allocate_irq (OBJECT (s),"irl" , sh_intc_set_irl, &s->intc.sources[IRL ],0 ); }
hw/sparc/sun4m.c +3 -2
@@ -1008,7 +1008,8 @@ static void sun4m_hw_init(MachineState *machine)if (hwdef->apc_base) {apc_init (OBJECT (machine), hwdef->apc_base, -qemu_allocate_irq_orphan (cpu_halt_signal,NULL ,0 )); +qemu_allocate_irq (OBJECT (machine),"cpu-halt" , + cpu_halt_signal,NULL ,0 )); }if (hwdef->fd_base) {
@@ -1018,7 +1019,7 @@ static void sun4m_hw_init(MachineState *machine)sun4m_fdctrl_init (OBJECT (machine), slavio_irq[22 ], hwdef->fd_base, fd, &fdc_tc); }else { - fdc_tc =qemu_allocate_irq_orphan (dummy_fdc_tc,NULL ,0 ); + fdc_tc =qemu_allocate_irq (OBJECT (machine),"fdc-tc" , dummy_fdc_tc,NULL ,0 ); } slavio_misc_init(OBJECT(machine), hwdef->slavio_base, hwdef->aux1_base,
hw/sparc64/sun4u.c +2 -1
@@ -311,7 +311,8 @@ static void ebus_realize(PCIDevice *pci_dev, Error **errp) }/* ISA bus */ - s->isa_irqs_in =qemu_allocate_irqs_orphan (ebus_isa_irq_handler, s,ISA_NUM_IRQS ); + s->isa_irqs_in =qemu_allocate_irqs (OBJECT (s),"isa-irq-in" , + ebus_isa_irq_handler, s,ISA_NUM_IRQS );isa_bus_register_input_irqs (s->isa_bus, s->isa_irqs_in);qdev_init_gpio_out_named (DEVICE (s), s->isa_irqs_out,"isa-irq" ,ISA_NUM_IRQS );
hw/xen/xen-pvh-common.c +3 -2
@@ -170,7 +170,7 @@ static void xen_create_virtio_mmio_devices(XenPVHMachineState *s)*/ for (i = s->cfg.virtio_mmio_num -1 ; i >=0 ; i--) {hwaddr base = s->cfg.virtio_mmio.base + i * s->cfg.virtio_mmio.size; -qemu_irq irq =qemu_allocate_irq_orphan (xen_set_irq,NULL , +qemu_irq irq =qemu_allocate_irq (OBJECT (s),"virtio-irq[*]" , xen_set_irq,NULL , s->cfg.virtio_mmio_irq_base + i); sysbus_create_simple(OBJECT(s), "virtio-mmio[*]", "virtio-mmio",
@@ -260,7 +260,8 @@ static inline void xenpvh_gpex_init(XenPVHMachineState *s,assert (xpc->set_pci_intx_irq);for (i =0 ; i <PCI_NUM_PINS ; i++) { -qemu_irq irq =qemu_allocate_irq_orphan (xpc->set_pci_intx_irq, s, i); +qemu_irq irq =qemu_allocate_irq (OBJECT (s),"pci-intx-irq[*]" , + xpc->set_pci_intx_irq, s, i);sysbus_connect_irq (SYS_BUS_DEVICE (dev), i, irq);gpex_set_irq_num (GPEX_HOST (dev), i, s->cfg.pci_intx_irq_base + i);
Signature · 1 line
2.47.1
RFC PATCH v2 116/137 hw/core: Parent GPIO input IRQs and embedded IRQState via QOM
In reply to Alexander Grafqdev_init_gpio_in_named_with_opaque() now uses qemu_extend_irqs() directly, so the input IRQ objects are parented under the device via object_new_child() and the manual object_property_add_child() loop goes away. device_finalize() no longer needs to free the IRQ objects explicitly since child<> property destruction does that; only the qemu_irq* array itself needs g_free().
Convert the six users of qemu_init_irq()/qemu_init_irqs() (which initialize an IRQState embedded in a device struct) to qemu_init_irq_child() so those IRQs also get a QOM parent.
qdev_connect_gpio_out_named() now asserts that its input pin has a parent instead of falling back to /machine/unattached; every qemu_irq that reaches it is parented after this and the preceding commits.
AI-used-for: code (refactoring)
--- hw/core/gpio.c | 24 ++++-------------------- hw/core/qdev.c | 3 ++- hw/ipack/ipack.c | 11 +++++++++-- hw/isa/vt82c686.c | 3 ++- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 2 +- hw/ppc/pegasos.c | 3 ++- hw/sh4/r2d.c | 5 ++++- 8 files changed, 25 insertions(+), 28 deletions(-)
hw/core/gpio.c +4 -20
@@ -45,24 +45,12 @@ void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,void *opaque, const char *name, int n) { - int i; NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);assert (gpio_list->num_out ==0 || !name); - gpio_list->in =qemu_extend_irqs_orphan (gpio_list->in, gpio_list->num_in, handler, - opaque, n); - -if (!name) { - name ="unnamed-gpio-in" ; - } -for (i = gpio_list->num_in; i < gpio_list->num_in + n; i++) { -gchar *propname =g_strdup_printf ("%s[%u]" , name, i); - -object_property_add_child (OBJECT (dev), propname, -OBJECT (gpio_list->in[i])); -g_free (propname); - } - + gpio_list->in =qemu_extend_irqs (OBJECT (dev), name ?:"unnamed-gpio-in" , + gpio_list->in, gpio_list->num_in, + handler, opaque, n); gpio_list->num_in += n; }
@@ -119,11 +107,7 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, {char *propname =g_strdup_printf ("%s[%d]" , name ? name :"unnamed-gpio-out" , n); -if (input_pin && !OBJECT (input_pin)->parent) { -/* We need a name for object_property_set_link to work */ -object_property_add_child (machine_get_container ("unattached" ), -"non-qdev-gpio[*]" ,OBJECT (input_pin)); - } +g_assert (!input_pin ||OBJECT (input_pin)->parent);object_property_set_link (OBJECT (dev), propname,OBJECT (input_pin), &error_abort);g_free (propname);
hw/core/qdev.c +2 -1
@@ -698,7 +698,8 @@ static void device_finalize(Object *obj) QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {QLIST_REMOVE (ngl, node); -qemu_free_irqs (ngl->in, ngl->num_in); +/* IRQs are child<> properties of dev; freed via child destruction */ +g_free (ngl->in);g_free (ngl->name);g_free (ngl);/* ngl->out irqs are owned by the other end and should not be freed
hw/ipack/ipack.c +9 -2
@@ -55,18 +55,25 @@ static void ipack_device_realize(DeviceState *dev, Error **errp) } bus->free_slot = idev->slot +1 ; -qemu_init_irqs (idev->irq,ARRAY_SIZE (idev->irq), bus->set_irq, idev); +for (int i =0 ; i <ARRAY_SIZE (idev->irq); i++) { +qemu_init_irq_child (OBJECT (idev),"irq[*]" , &idev->irq[i], + bus->set_irq, idev, i); + } k->realize (dev, errp); }static void ipack_device_unrealize (DeviceState *dev) { +IPackDevice *idev =IPACK_DEVICE (dev);IPackDeviceClass *k =IPACK_DEVICE_GET_CLASS (dev);if (k->unrealize) { k->unrealize (dev); -return ; + } + +for (int i =0 ; i <ARRAY_SIZE (idev->irq); i++) { +object_unparent (OBJECT (&idev->irq[i])); } }
hw/isa/vt82c686.c +2 -1
@@ -722,7 +722,8 @@ static void via_isa_realize(PCIDevice *d, Error **errp)qdev_init_gpio_out_named (dev, &s->cpu_intr,"intr" ,1 );qdev_init_gpio_in_named (dev, via_isa_pirq,"pirq" ,PCI_NUM_PINS ); -qemu_init_irq (&s->i8259_irq, via_isa_request_i8259_irq, s,0 ); +qemu_init_irq_child (OBJECT (s),"i8259-irq" , &s->i8259_irq, + via_isa_request_i8259_irq, s,0 ); isa_bus =isa_bus_new (dev,pci_address_space (d),pci_address_space_io (d), errp);
hw/net/imx_fec.c +1 -1
@@ -1205,7 +1205,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)sysbus_init_irq (sbd, &s->irq[0 ]);sysbus_init_irq (sbd, &s->irq[1 ]); -qemu_init_irq (&s->mii_irq, imx_phy_update_irq, s,0 ); +qemu_init_irq_child (OBJECT (s),"mii-irq" , &s->mii_irq, imx_phy_update_irq, s,0 );object_initialize_child (OBJECT (s),"mii" , &s->mii,TYPE_LAN9118_PHY );if (!sysbus_realize_and_unref (SYS_BUS_DEVICE (&s->mii), errp)) {return ;
hw/net/lan9118.c +1 -1
@@ -1274,7 +1274,7 @@ static void lan9118_realize(DeviceState *dev, Error **errp)const MemoryRegionOps *mem_ops = s->mode_16bit ? &lan9118_16bit_mem_ops : &lan9118_mem_ops; -qemu_init_irq (&s->mii_irq, lan9118_update_irq, s,0 ); +qemu_init_irq_child (OBJECT (s),"mii-irq" , &s->mii_irq, lan9118_update_irq, s,0 );object_initialize_child (OBJECT (s),"mii" , &s->mii,TYPE_LAN9118_PHY );if (!sysbus_realize_and_unref (SYS_BUS_DEVICE (&s->mii), errp)) {return ;
hw/ppc/pegasos.c +2 -1
@@ -134,7 +134,8 @@ static void pegasos2_setup_pci_irq(PegasosMachineState *pm)TYPE_OR_IRQ , &error_fatal, "num-lines", "2", NULL);qdev_realize (DEVICE (ori),NULL , &error_fatal); -qemu_init_irq (&pm->pci_irqs[i], pegasos2_pci_irq, pm, i); +qemu_init_irq_child (OBJECT (pm),"pci-irq[*]" , &pm->pci_irqs[i], + pegasos2_pci_irq, pm, i);qdev_connect_gpio_out (DEVICE (ori),0 , &pm->pci_irqs[i]); pm->mv_pirq[i] =qdev_get_gpio_in_named (pm->nb,"gpp" ,12 + i); pm->via_pirq[i] =qdev_get_gpio_in_named (pm->sb,"pirq" , i);
hw/sh4/r2d.c +4 -1
@@ -200,7 +200,10 @@ static r2d_fpga_t *r2d_fpga_init(Object *owner,memory_region_init_io (&s->iomem, owner, &r2d_fpga_ops, s,"r2d-fpga" ,0x40 );memory_region_add_subregion (sysmem, base, &s->iomem); -qemu_init_irqs (s->irq,NR_IRQS , r2d_fpga_irq_set, s); +for (int i =0 ; i <NR_IRQS ; i++) { +qemu_init_irq_child (owner,"fpga-irq[*]" , &s->irq[i], + r2d_fpga_irq_set, s, i); + }return s; }
Signature · 1 line
2.47.1
RFC PATCH v2 117/137 irq: Delete the *_orphan() IRQ allocation variants
In reply to Alexander GrafEvery caller has been converted to the parented form; drop the transitional *_orphan() helpers.
AI-used-for: code (refactoring)
--- hw/core/irq.c | 35 ----------------------------------- include/hw/core/irq.h | 20 +------------------- 2 files changed, 1 insertion(+), 54 deletions(-)
hw/core/irq.c +0 -35
@@ -68,34 +68,6 @@ void qemu_init_irqs(IRQState irq[], size_t count, } } -qemu_irq *qemu_extend_irqs_orphan (qemu_irq *old,int n_old,qemu_irq_handler handler, -void *opaque,int n) -{ -qemu_irq *s; -int i; - -if (!old) { - n_old =0 ; - } - s = old ?g_renew (qemu_irq, old, n + n_old) :g_new (qemu_irq, n); -for (i = n_old; i < n + n_old; i++) { - s[i] =qemu_allocate_irq_orphan (handler, opaque, i); - } -return s; -} - -qemu_irq *qemu_allocate_irqs_orphan (qemu_irq_handler handler,void *opaque,int n) -{ -return qemu_extend_irqs_orphan (NULL ,0 , handler, opaque, n); -} - -qemu_irq qemu_allocate_irq_orphan (qemu_irq_handler handler,void *opaque,int n) -{ -IRQState *irq =IRQ (object_new (TYPE_IRQ )); -init_irq_fields (irq, handler, opaque, n); -return irq; -} -qemu_irq qemu_allocate_irq (Object *owner,const char *name,qemu_irq_handler handler,void *opaque,int n) {
@@ -153,13 +125,6 @@ static void qemu_notirq(void *opaque, int line, int level)qemu_set_irq (irq, !level); } -qemu_irq qemu_irq_invert_orphan (qemu_irq irq) -{ -/* The default state for IRQs is low, so raise the output now. */ -qemu_irq_raise (irq); -return qemu_allocate_irq_orphan (qemu_notirq, irq,0 ); -} -qemu_irq qemu_irq_invert (Object *owner,const char *name,qemu_irq irq) {/* The default state for IRQs is low, so raise the output now. */
include/hw/core/irq.h +1 -19
@@ -74,19 +74,8 @@ void qemu_init_irq_child(Object *parent, const char *propname,void qemu_init_irqs (IRQState irq[],size_t count,qemu_irq_handler handler,void *opaque); -/* Returns an array of N IRQs. Each IRQ is assigned the argument handler and -* opaque data. -*/ -qemu_irq *qemu_allocate_irqs_orphan (qemu_irq_handler handler,void *opaque,int n); -/* -* Allocates a single IRQ. The irq is assigned with a handler, an opaque -* data and the interrupt number. -*/ -qemu_irq qemu_allocate_irq_orphan (qemu_irq_handler handler,void *opaque,int n); - -/* -* Same as the *_orphan() variants above, but the new IRQ objects are +* Allocate IRQ objects with an explicit QOM parent. The new objects are * parented under @owner with property name @name (or @name[*] for the * array/extend variants). The reference is held by @owner; call * qemu_free_irq() to unparent and free.
@@ -99,17 +88,10 @@ qemu_irq *qemu_extend_irqs(Object *owner, const char *name, qemu_irq *old, int n_old, qemu_irq_handler handler, void *opaque, int n); -/* Extends an Array of IRQs. Old IRQs have their handlers and opaque data -* preserved. New IRQs are assigned the argument handler and opaque data. -*/ -qemu_irq *qemu_extend_irqs_orphan (qemu_irq *old,int n_old,qemu_irq_handler handler, -void *opaque,int n); -void qemu_free_irqs (qemu_irq *s,int n);void qemu_free_irq (qemu_irq irq);/* Returns a new IRQ with opposite polarity. */ -qemu_irq qemu_irq_invert_orphan (qemu_irq irq);qemu_irq qemu_irq_invert (Object *owner,const char *name,qemu_irq irq);/* For internal use in qtest. */
Signature · 1 line
2.47.1
RFC PATCH v2 118/137 sysbus: Parent main-system-bus directly under /machine
In reply to Alexander GrafThe main system bus is the only object deliberately placed under /machine/unattached; every other resident is an accidental orphan. Promoting it to /machine/sysbus makes /machine/unattached a pure bug indicator that later commits can turn into a hard error.
The canonical path changes from /machine/unattached/sysbus to /machine/sysbus. qom-list users that hard-code the old path need to be updated; the hmp/qmp qom-tree output naturally follows.
AI-used-for: code (refactoring)
--- system/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
system/vl.c +1 -1
@@ -2211,7 +2211,7 @@ static void qemu_create_machine(QDict *qdict)object_property_add_child (object_get_root (),"machine" ,OBJECT (current_machine));qemu_create_machine_containers (OBJECT (current_machine)); -object_property_add_child (machine_get_container ("unattached" ), +object_property_add_child (OBJECT (current_machine),"sysbus" ,OBJECT (sysbus_get_default ()));if (machine_class->minimum_page_bits) {
Signature · 1 line
2.47.1
RFC PATCH v2 119/137 accel: Parent the accelerator singleton under /machine
In reply to Alexander Grafdo_configure_accelerator() runs after qemu_create_machine(), so current_machine is available. Give the AccelState singleton a canonical path at /machine/accel and drop the floating caller reference; on init failure, unparent instead of unref.
AI-used-for: code (refactoring)
--- accel/accel-system.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
accel/accel-system.c +3 -1
@@ -41,12 +41,14 @@ int accel_init_machine(AccelState *accel, MachineState *ms)AccelClass *acc =ACCEL_GET_CLASS (accel);int ret; ms->accelerator = accel; +object_property_add_child (OBJECT (ms),"accel" ,OBJECT (accel)); +object_unref (OBJECT (accel)); *(acc->allowed) = true; ret = acc->init_machine (accel, ms);if (ret <0 ) { ms->accelerator =NULL ; *(acc->allowed) = false; -object_unref (OBJECT (accel)); +object_unparent (OBJECT (accel)); }else {object_set_accelerator_compat_props (acc->compat_props); }
Signature · 1 line
2.47.1
RFC PATCH v2 120/137 hw/intc/mips_gic: Register reset handler at realize, not instance_init
In reply to Alexander Grafmips_gic_init() calls qemu_register_reset(gic_reset, s), but there is no matching qemu_unregister_reset() in an instance_finalize. This leaks a reset handler every time the type is introspected via device-list-properties (object_new + object_unref). The following patch makes each legacy reset handler visible in the composition tree under /machine/reset-container/legacy-reset[*], which turns this pre-existing leak into a device-introspect-test failure.
Move the registration to mips_gic_realize(), matching every other in-tree interrupt controller.
AI-used-for: code (refactoring)
--- hw/intc/mips_gic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/mips_gic.c +1 -1
@@ -394,7 +394,6 @@ static void mips_gic_init(Object *obj)memory_region_init_io (&s->mr,OBJECT (s), &gic_ops, s,"mips-gic" ,GIC_ADDRSPACE_SZ );sysbus_init_mmio (sbd, &s->mr); -qemu_register_reset (gic_reset, s); }static void mips_gic_realize (DeviceState *dev,Error **errp)
@@ -430,6 +429,7 @@ static void mips_gic_realize(DeviceState *dev, Error **errp)for (i =0 ; i < s->num_irq; i++) { s->irq_state[i].irq =qdev_get_gpio_in (dev, i); } +qemu_register_reset (gic_reset, s); }static const Property mips_gic_properties[] = {
Signature · 1 line
2.47.1
RFC PATCH v2 121/137 hw/core/reset: Give the root reset container and legacy shims a QOM path
In reply to Alexander GrafThe root ResettableContainer and the LegacyReset shim objects are long-lived singletons held only by static pointers and refcounts. Give them a canonical path in the composition tree so qom-tree/qom-list can enumerate them and so device_set_realized() can require a QOM parent for every object.
/machine/reset-container (ResettableContainer)
/machine/reset-container/legacy-reset[N] (LegacyReset shims)
get_root_reset_container() is first reached from configure_accelerators() or machine_run_board_init(), both of which run after qemu_create_machine(), so qdev_get_machine() is available. qemu_unregister_reset() switches from object_unref() to object_unparent() to release the child<> ref.
AI-used-for: code (refactoring)
--- hw/core/reset.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/core/reset.c +9 -4
@@ -27,6 +27,7 @@#include "system/reset.h" #include "hw/core/resettable.h" #include "hw/core/resetcontainer.h" +#include "hw/core/qdev.h" /* * Return a pointer to the singleton container that holds all the Resettable
@@ -38,7 +39,9 @@ static ResettableContainer *get_root_reset_container(void)if (!root_reset_container) { root_reset_container = -RESETTABLE_CONTAINER (object_new (TYPE_RESETTABLE_CONTAINER )); +RESETTABLE_CONTAINER (object_new_child (qdev_get_machine (), +"reset-container" , +TYPE_RESETTABLE_CONTAINER )); }return root_reset_container; }
@@ -94,7 +97,8 @@ static void legacy_reset_class_init(ObjectClass *klass, const void *data)void qemu_register_reset (QEMUResetHandler *func,void *opaque) { -Object *obj =object_new (TYPE_LEGACY_RESET ); +Object *obj =object_new_child (OBJECT (get_root_reset_container ()), +"legacy-reset[*]" ,TYPE_LEGACY_RESET );LegacyReset *lr =LEGACY_RESET (obj); lr->func = func;
@@ -104,7 +108,8 @@ void qemu_register_reset(QEMUResetHandler *func, void *opaque)void qemu_register_reset_nosnapshotload (QEMUResetHandler *func,void *opaque) { -Object *obj =object_new (TYPE_LEGACY_RESET ); +Object *obj =object_new_child (OBJECT (get_root_reset_container ()), +"legacy-reset[*]" ,TYPE_LEGACY_RESET );LegacyReset *lr =LEGACY_RESET (obj); lr->func = func;
@@ -156,7 +161,7 @@ void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)if (obj) {qemu_unregister_resettable (obj); -object_unref (obj); +object_unparent (obj); } }
Signature · 1 line
2.47.1
RFC PATCH v2 122/137 system: Parent per-MR helper objects under their owner
In reply to Alexander GrafRamBlockAttributes and MemoryRegionPortioList objects are long-lived helpers whose lifetime is already tied to a MemoryRegion or its owner. Give each a canonical path under that owner instead of leaving them as floating refcounted objects:
<mr-path>/attributes (RamBlockAttributes)
<owner-path>/portio-list[N] (MemoryRegionPortioList)
The destroy paths switch from object_unref() to object_unparent() now that the parent holds the reference.
RamDiscardManager is deliberately left as-is: it is unref'd from memory_region_finalize() itself, so making it a child<> of the MR would introduce a use-after-free during MR teardown. It can move under a different owner in a follow-up once the RDM lifecycle is untangled from MR finalize.
AI-used-for: code (refactoring)
--- system/ioport.c | 5 +++-- system/ram-block-attributes.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-)
system/ioport.c +3 -2
@@ -145,7 +145,7 @@ void portio_list_destroy(PortioList *piolist)for (i =0 ; i < piolist->nr; ++i) { mrpio =container_of (piolist->regions[i], MemoryRegionPortioList, mr);object_unparent (OBJECT (&mrpio->mr)); -object_unref (mrpio); +object_unparent (OBJECT (mrpio)); }g_free (piolist->regions); }
@@ -228,7 +228,8 @@ static void portio_list_add_1(PortioList *piolist,/* Copy the sub-list and null-terminate it. */ mrpio =MEMORY_REGION_PORTIO_LIST ( -object_new (TYPE_MEMORY_REGION_PORTIO_LIST )); +object_new_child (piolist->owner,"portio-list[*]" , +TYPE_MEMORY_REGION_PORTIO_LIST )); mrpio->portio_opaque = piolist->opaque; mrpio->ports =g_new0 (MemoryRegionPortio, count +1 );memcpy (mrpio->ports, pio_init,sizeof (MemoryRegionPortio) * count);
system/ram-block-attributes.c +4 -3
@@ -182,12 +182,13 @@ RamBlockAttributes *ram_block_attributes_create(RAMBlock *ram_block)RamBlockAttributes *attr;MemoryRegion *mr = ram_block->mr; - attr =RAM_BLOCK_ATTRIBUTES (object_new (TYPE_RAM_BLOCK_ATTRIBUTES )); + attr =RAM_BLOCK_ATTRIBUTES (object_new_child (OBJECT (mr),"attributes" , +TYPE_RAM_BLOCK_ATTRIBUTES )); attr->ram_block = ram_block;if (memory_region_add_ram_discard_source (mr,RAM_DISCARD_SOURCE (attr))) { -object_unref (OBJECT (attr)); +object_unparent (OBJECT (attr));return NULL ; } attr->bitmap_size =DIV_ROUND_UP (int128_get64 (mr->size), block_size);
@@ -202,7 +203,7 @@ void ram_block_attributes_destroy(RamBlockAttributes *attr)g_free (attr->bitmap);memory_region_del_ram_discard_source (attr->ram_block->mr,RAM_DISCARD_SOURCE (attr)); -object_unref (OBJECT (attr)); +object_unparent (OBJECT (attr)); }static void ram_block_attributes_init (Object *obj)
Signature · 1 line
2.47.1
RFC PATCH v2 123/137 hw/virtio, hw/display: Parent per-device helper objects
In reply to Alexander GrafThe virtio-mem system-reset shim, the vhost-user-gpu backend, and its socket chardev live exactly as long as their enclosing virtio device. Parent them under it so they show up in the composition tree instead of floating with only a refcount.
The unrealize/finalize/error paths switch from object_unref() to object_unparent(), and vhost_user_gpu_instance_finalize() drops its now-redundant unref: the vhost-backend is a child<> of the GPU and is released automatically when the GPU is finalized.
AI-used-for: code (refactoring)
--- hw/display/vhost-user-gpu.c | 12 ++++++------ hw/virtio/virtio-mem.c | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-)
hw/display/vhost-user-gpu.c +6 -6
@@ -439,7 +439,8 @@ vhost_user_gpu_do_set_socket(VhostUserGPU *g, Error **errp)return false; } - chr =CHARDEV (object_new (TYPE_CHARDEV_SOCKET )); + chr =CHARDEV (object_new_child (OBJECT (g),"vhost-chardev" , +TYPE_CHARDEV_SOCKET ));if (!chr ||qemu_chr_add_client (chr, sv[0 ]) ==-1 ) {error_setg (errp,"Failed to make socket chardev" ); goto err;
@@ -462,7 +463,7 @@ err:close (sv[0 ]);close (sv[1 ]);if (chr) { -object_unref (OBJECT (chr)); +object_unparent (OBJECT (chr)); }return false; }
@@ -584,7 +585,8 @@ vhost_user_gpu_instance_init(Object *obj) {VhostUserGPU *g =VHOST_USER_GPU (obj); - g->vhost =VHOST_USER_BACKEND (object_new (TYPE_VHOST_USER_BACKEND )); + g->vhost =VHOST_USER_BACKEND (object_new_child (obj,"vhost-backend" , +TYPE_VHOST_USER_BACKEND ));object_property_add_alias (obj,"chardev" ,OBJECT (g->vhost),"chardev" ); }
@@ -592,9 +594,7 @@ vhost_user_gpu_instance_init(Object *obj)static void vhost_user_gpu_instance_finalize (Object *obj) { -VhostUserGPU *g =VHOST_USER_GPU (obj); - -object_unref (OBJECT (g->vhost)); +/* g->vhost is a child<> of obj and released with it */ } static void
hw/virtio/virtio-mem.c +3 -2
@@ -1011,7 +1011,8 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)* we need a dedicated reset object that only gets called during * qemu_devices_reset(). */ - obj =object_new (TYPE_VIRTIO_MEM_SYSTEM_RESET ); + obj =object_new_child (OBJECT (vmem),"system-reset" , +TYPE_VIRTIO_MEM_SYSTEM_RESET ); vmem->system_reset =VIRTIO_MEM_SYSTEM_RESET (obj); vmem->system_reset->vmem = vmem;qemu_register_resettable (obj);
@@ -1023,7 +1024,7 @@ static void virtio_mem_device_unrealize(DeviceState *dev)VirtIOMEM *vmem =VIRTIO_MEM (dev);qemu_unregister_resettable (OBJECT (vmem->system_reset)); -object_unref (OBJECT (vmem->system_reset)); +object_unparent (OBJECT (vmem->system_reset));if (vmem->early_migration) { vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_early,
Signature · 1 line
2.47.1
RFC PATCH v2 124/137 hw/i386/amd_iommu: Parent internally-created AMDVI-PCI under the IOMMU
In reply to Alexander GrafWhen the AMD IOMMU creates its own PCI companion device (no pci-id supplied by the user), parent it under the sysbus IOMMU so it has a canonical path at <iommu>/pci. The user-supplied path already parents via -device.
AI-used-for: code (refactoring)
--- hw/i386/amd_iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/amd_iommu.c +2 -1
@@ -2698,7 +2698,8 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) s->pci =AMD_IOMMU_PCI (pdev); dc->vmsd = &vmstate_amdvi_sysbus_migratable; }else { - s->pci =AMD_IOMMU_PCI (object_new (TYPE_AMD_IOMMU_PCI )); + s->pci =AMD_IOMMU_PCI (object_new_child (OBJECT (s),"pci" , +TYPE_AMD_IOMMU_PCI ));/* This device should take care of IOMMU PCI properties */ if (!qdev_realize (DEVICE (s->pci), &bus->qbus, errp)) {return ;
Signature · 1 line
2.47.1
RFC PATCH v2 125/137 hw/s390x, hw/remote: Parent per-devfn IOMMU objects
In reply to Alexander GrafGive the per-devfn S390 PCI IOMMU object a canonical path under the S390 PCI host state. s390_pci_iommu_free() already calls object_unparent(), which was previously a no-op; it now performs the actual release.
For the multi-process remote IOMMU, replace the raw object_new(TYPE_MEMORY_REGION) with a proper memory_region_init() under the RemoteIommu object so the MR gets an owner like every other MR in the tree.
AI-used-for: code (refactoring)
--- hw/remote/iommu.c | 7 ++++--- hw/s390x/s390-pci-bus.c | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-)
hw/remote/iommu.c +4 -3
@@ -52,8 +52,9 @@ static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, }if (!elem->mr) { - elem->mr =MEMORY_REGION (object_new (TYPE_MEMORY_REGION )); -memory_region_set_size (elem->mr,UINT64_MAX ); + g_autofree char *name = g_strdup_printf("mr-devfn-%02x", devfn); + elem->mr =g_new0 (MemoryRegion,1 ); +memory_region_init (elem->mr,OBJECT (iommu), name,UINT64_MAX );address_space_init (&elem->as, elem->mr,NULL ); }
@@ -75,7 +76,7 @@ void remote_iommu_unplug_dev(PCIDevice *pci_dev)address_space_destroy (&elem->as); -object_unref (elem->mr); +object_unparent (OBJECT (elem->mr)); elem->mr =NULL ; }
hw/s390x/s390-pci-bus.c +7 -2
@@ -618,7 +618,13 @@ static S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, PCIBus *bus, iommu = table->iommu[PCI_SLOT (devfn)];if (!iommu) { - iommu =S390_PCI_IOMMU (object_new (TYPE_S390_PCI_IOMMU )); +char *ch_name =g_strdup_printf ("iommu[%02x:%02x.%01x]" , +pci_bus_num (bus), +PCI_SLOT (devfn), +PCI_FUNC (devfn)); + iommu =S390_PCI_IOMMU (object_new_child (OBJECT (s), ch_name, +TYPE_S390_PCI_IOMMU )); +g_free (ch_name); char *mr_name = g_strdup_printf("iommu-root-%02x:%02x.%01x", pci_bus_num(bus),
@@ -798,7 +804,6 @@ static void s390_pci_iommu_free(S390pciState *s, PCIBus *bus, int32_t devfn)address_space_destroy (&iommu->as);object_unparent (OBJECT (&iommu->mr));object_unparent (OBJECT (iommu)); -object_unref (OBJECT (iommu)); }S390PCIGroup *s390_group_create (int id,int host_id)
Signature · 1 line
2.47.1
RFC PATCH v2 126/137 hw/pci-host/raven: Parent the OR-IRQ under the host bridge
In reply to Alexander GrafThe PReP raven host bridge creates an or-irq gate to fan PCI interrupts into IRQ 15. Parent it under the host bridge so it gets a canonical path.
AI-used-for: code (refactoring)
--- hw/pci-host/raven.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci-host/raven.c +2 -1
@@ -249,7 +249,8 @@ static void raven_pcihost_realizefn(DeviceState *d, Error **errp)* According to PReP specification section 6.1.6 "System Interrupt * Assignments", all PCI interrupts are routed via IRQ 15 */ - s->or_irq =OR_IRQ (object_new (TYPE_OR_IRQ )); + s->or_irq =OR_IRQ (object_new_child (OBJECT (s),"or-irq" , +TYPE_OR_IRQ ));object_property_set_int (OBJECT (s->or_irq),"num-lines" ,PCI_NUM_PINS , &error_fatal);qdev_realize (DEVICE (s->or_irq),NULL , &error_fatal);
Signature · 1 line
2.47.1
RFC PATCH v2 127/137 hw/arm/mps2: Parent the OR-IRQ gates under the machine
In reply to Alexander GrafThe mps2 board creates several TYPE_OR_IRQ gates for UART overflow, per-UART tx/rx, and SPI interrupts. Parent them under the machine so they get canonical paths. The 282/325 pair sit on mutually-exclusive switch arms, so a single "uart-orgate" name is sufficient; the loop-created gates use "[*]" auto-indexing.
AI-used-for: code (refactoring)
--- hw/arm/mps2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/arm/mps2.c +5 -4
@@ -279,7 +279,7 @@ static void mps2_common_init(MachineState *machine)Object *orgate;DeviceState *orgate_dev; - orgate =object_new (TYPE_OR_IRQ ); + orgate =object_new_child (OBJECT (mms),"uart-orgate" ,TYPE_OR_IRQ );object_property_set_int (orgate,"num-lines" ,6 , &error_fatal);qdev_realize (DEVICE (orgate),NULL , &error_fatal); orgate_dev =DEVICE (orgate);
@@ -322,7 +322,7 @@ static void mps2_common_init(MachineState *machine)Object *orgate;DeviceState *orgate_dev; - orgate =object_new (TYPE_OR_IRQ ); + orgate =object_new_child (OBJECT (mms),"uart-orgate" ,TYPE_OR_IRQ );object_property_set_int (orgate,"num-lines" ,10 , &error_fatal);qdev_realize (DEVICE (orgate),NULL , &error_fatal); orgate_dev =DEVICE (orgate);
@@ -338,7 +338,8 @@ static void mps2_common_init(MachineState *machine)DeviceState *txrx_orgate_dev, *dev;SysBusDevice *s; - txrx_orgate =object_new (TYPE_OR_IRQ ); + txrx_orgate =object_new_child (OBJECT (mms),"uart-txrx-orgate[*]" , +TYPE_OR_IRQ );object_property_set_int (txrx_orgate,"num-lines" ,2 , &error_fatal);qdev_realize (DEVICE (txrx_orgate),NULL , &error_fatal); txrx_orgate_dev =DEVICE (txrx_orgate);
@@ -430,7 +431,7 @@ static void mps2_common_init(MachineState *machine)Object *orgate;int j; - orgate =object_new (TYPE_OR_IRQ ); + orgate =object_new_child (OBJECT (mms),"spi-orgate[*]" ,TYPE_OR_IRQ );object_property_set_int (orgate,"num-lines" ,2 , &error_fatal); orgate_dev =DEVICE (orgate);qdev_realize (orgate_dev,NULL , &error_fatal);
Signature · 1 line
2.47.1
RFC PATCH v2 128/137 hw/arm/digic: Parent the DIGIC SoC under the machine
In reply to Alexander GrafBring digic in line with cubieboard/orangepi/bpim2u/imx6ul/imx7, which all parent their SoC as /machine/soc.
AI-used-for: code (refactoring)
--- hw/arm/digic_boards.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/arm/digic_boards.c +2 -1
@@ -50,7 +50,8 @@ typedef struct DigicBoard {static void digic4_board_init (MachineState *machine,DigicBoard *board) {Error *err =NULL ; -DigicState *s =DIGIC (object_new (TYPE_DIGIC )); +DigicState *s =DIGIC (object_new_child (OBJECT (machine),"soc" , +TYPE_DIGIC ));MachineClass *mc =MACHINE_GET_CLASS (machine);if (machine->ram_size != mc->default_ram_size) {
Signature · 1 line
2.47.1
RFC PATCH v2 129/137 hw/microblaze: Parent the CPU under the machine
In reply to Alexander GrafBoth petalogix boards create exactly one MicroBlaze CPU via object_new(); parent it as /machine/cpu[0] like every other single-CPU board.
AI-used-for: code (refactoring)
--- hw/microblaze/petalogix_ml605_mmu.c | 3 ++- hw/microblaze/petalogix_s3adsp1800_mmu.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
hw/microblaze/petalogix_ml605_mmu.c +2 -1
@@ -82,7 +82,8 @@ petalogix_ml605_init(MachineState *machine)qemu_irq irq[32 ];/* init CPUs */ - cpu =MICROBLAZE_CPU (object_new (TYPE_MICROBLAZE_CPU )); + cpu =MICROBLAZE_CPU (object_new_child (OBJECT (machine),"cpu[0]" , +TYPE_MICROBLAZE_CPU ));object_property_set_str (OBJECT (cpu),"version" ,"8.10.a" , &error_abort);/* Use FPU but don't use floating point conversion and square * root instructions
hw/microblaze/petalogix_s3adsp1800_mmu.c +2 -1
@@ -85,7 +85,8 @@ petalogix_s3adsp1800_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory ();EndianMode endianness = psms->endianness; - cpu =MICROBLAZE_CPU (object_new (TYPE_MICROBLAZE_CPU )); + cpu =MICROBLAZE_CPU (object_new_child (OBJECT (machine),"cpu[0]" , +TYPE_MICROBLAZE_CPU ));object_property_set_str (OBJECT (cpu),"version" ,"7.10.d" , &error_abort);object_property_set_bool (OBJECT (cpu),"little-endian" , endianness ==ENDIAN_MODE_LITTLE , &error_abort);
Signature · 1 line
2.47.1
RFC PATCH v2 130/137 hw: Pair object_initialize_child() with plain realize()
In reply to Alexander GrafA number of composite devices and boards create embedded children via object_initialize_child() (or object_new_with_props()) and then realize them via *_realize_and_unref(). The child<> property already holds the sole reference; the extra unref drops it and the object survives only because bus_add_child() takes a reference of its own. Use plain sysbus_realize()/qdev_realize() so the parent's child<> keeps the reference it is documented to hold.
AI-used-for: code (refactoring)
--- hw/arm/imx8mm-evk.c | 2 +- hw/arm/imx8mp-evk.c | 2 +- hw/arm/mps2.c | 2 +- hw/display/sm501.c | 2 +- hw/m68k/q800.c | 6 +++--- hw/misc/macio/macio.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 2 +- hw/nubus/nubus-virtio-mmio.c | 2 +- hw/pci-host/mv64361.c | 2 +- hw/xen/xen-pvh-common.c | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-)
hw/arm/imx8mm-evk.c +1 -1
@@ -80,7 +80,7 @@ static void imx8mm_evk_init(MachineState *machine) s =FSL_IMX8MM (object_new_with_props (TYPE_FSL_IMX8MM ,OBJECT (machine),"soc" , &error_fatal,NULL ));object_property_set_uint (OBJECT (s),"fec1-phy-num" ,1 , &error_fatal); -sysbus_realize_and_unref (SYS_BUS_DEVICE (s), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (s), &error_fatal);memory_region_add_subregion (get_system_memory (),FSL_IMX8MM_RAM_START , machine->ram);
hw/arm/imx8mp-evk.c +1 -1
@@ -93,7 +93,7 @@ static void imx8mp_evk_init(MachineState *machine)object_property_set_link (OBJECT (&s->soc), bus_name,OBJECT (s->canbus[i]), &error_fatal); } -sysbus_realize_and_unref (SYS_BUS_DEVICE (&s->soc), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (&s->soc), &error_fatal);memory_region_add_subregion (get_system_memory (),FSL_IMX8MP_RAM_START , machine->ram);
hw/arm/mps2.c +1 -1
@@ -379,7 +379,7 @@ static void mps2_common_init(MachineState *machine) TYPE_CMSDK_APB_TIMER); sbd =SYS_BUS_DEVICE (&mms->timer[i]);qdev_connect_clock_in (DEVICE (&mms->timer[i]),"pclk" , mms->sysclk); -sysbus_realize_and_unref (sbd, &error_fatal); +sysbus_realize (sbd, &error_fatal);sysbus_mmio_map (sbd,0 , base);sysbus_connect_irq (sbd,0 ,qdev_get_gpio_in (armv7m, irqno)); }
hw/display/sm501.c +1 -1
@@ -2091,7 +2091,7 @@ static void sm501_realize_sysbus(DeviceState *dev, Error **errp)sysbus_init_mmio (sbd, &s->state.mmio_region);/* bridge to usb host emulation module */ -sysbus_realize_and_unref (SYS_BUS_DEVICE (&s->ohci), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (&s->ohci), &error_fatal);memory_region_add_subregion (&s->state.mmio_region,SM501_USB_HOST ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->ohci),0 ));sysbus_pass_irq (sbd,SYS_BUS_DEVICE (&s->ohci));
hw/m68k/q800.c +3 -3
@@ -324,14 +324,14 @@ static void q800_machine_init(MachineState *machine)object_initialize_child (OBJECT (machine),"djmemc" , &m->djmemc,TYPE_DJMEMC ); sysbus =SYS_BUS_DEVICE (&m->djmemc); -sysbus_realize_and_unref (sysbus, &error_fatal); +sysbus_realize (sysbus, &error_fatal);memory_region_add_subregion (&m->macio,DJMEMC_BASE -IO_BASE ,sysbus_mmio_get_region (sysbus,0 ));/* IOSB subsystem */ object_initialize_child (OBJECT (machine),"iosb" , &m->iosb,TYPE_IOSB ); sysbus =SYS_BUS_DEVICE (&m->iosb); -sysbus_realize_and_unref (sysbus, &error_fatal); +sysbus_realize (sysbus, &error_fatal);memory_region_add_subregion (&m->macio,IOSB_BASE -IO_BASE ,sysbus_mmio_get_region (sysbus,0 ));
@@ -497,7 +497,7 @@ static void q800_machine_init(MachineState *machine)qdev_prop_set_string (DEVICE (&m->asc),"audiodev" , machine->audiodev); } sysbus =SYS_BUS_DEVICE (&m->asc); -sysbus_realize_and_unref (sysbus, &error_fatal); +sysbus_realize (sysbus, &error_fatal);memory_region_add_subregion (&m->macio,ASC_BASE -IO_BASE ,sysbus_mmio_get_region (sysbus,0 )); sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(DEVICE(&m->glue),
hw/misc/macio/macio.c +1 -1
@@ -274,7 +274,7 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)/* OpenPIC */ qdev_prop_set_uint32 (pic_dev,"model" ,OPENPIC_MODEL_KEYLARGO ); sbd =SYS_BUS_DEVICE (&ns->pic); -sysbus_realize_and_unref (sbd, &error_fatal); +sysbus_realize (sbd, &error_fatal);memory_region_add_subregion (&s->bar,0x40000 ,sysbus_mmio_get_region (sbd,0 ));
hw/net/imx_fec.c +1 -1
@@ -1207,7 +1207,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)qemu_init_irq_child (OBJECT (s),"mii-irq" , &s->mii_irq, imx_phy_update_irq, s,0 );object_initialize_child (OBJECT (s),"mii" , &s->mii,TYPE_LAN9118_PHY ); -if (!sysbus_realize_and_unref (SYS_BUS_DEVICE (&s->mii), errp)) { +if (!sysbus_realize (SYS_BUS_DEVICE (&s->mii), errp)) {return ; }qdev_connect_gpio_out (DEVICE (&s->mii),0 , &s->mii_irq);
hw/net/lan9118.c +1 -1
@@ -1276,7 +1276,7 @@ static void lan9118_realize(DeviceState *dev, Error **errp)qemu_init_irq_child (OBJECT (s),"mii-irq" , &s->mii_irq, lan9118_update_irq, s,0 );object_initialize_child (OBJECT (s),"mii" , &s->mii,TYPE_LAN9118_PHY ); -if (!sysbus_realize_and_unref (SYS_BUS_DEVICE (&s->mii), errp)) { +if (!sysbus_realize (SYS_BUS_DEVICE (&s->mii), errp)) {return ; }qdev_connect_gpio_out (DEVICE (&s->mii),0 , &s->mii_irq);
hw/nubus/nubus-virtio-mmio.c +1 -1
@@ -51,7 +51,7 @@ static void nubus_virtio_mmio_realize(DeviceState *dev, Error **errp)for (i =0 ; i <NUBUS_VIRTIO_MMIO_NUM_DEVICES ; i++) { sbd =SYS_BUS_DEVICE (&s->virtio_mmio[i]);qdev_prop_set_bit (DEVICE (sbd),"force-legacy" , false); -if (!sysbus_realize_and_unref (sbd, errp)) { +if (!sysbus_realize (sbd, errp)) {return ; }
hw/pci-host/mv64361.c +1 -1
@@ -874,7 +874,7 @@ static void mv64361_realize(DeviceState *dev, Error **errp) TYPE_MV64361_PCI);DeviceState *pci =DEVICE (&s->pci[i]);qdev_prop_set_uint8 (pci,"index" , i); -sysbus_realize_and_unref (SYS_BUS_DEVICE (pci), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (pci), &error_fatal); }sysbus_init_irq (SYS_BUS_DEVICE (dev), &s->cpu_irq);qdev_init_gpio_in_named (dev, mv64361_gpp_irq,"gpp" ,32 );
hw/xen/xen-pvh-common.c +1 -1
@@ -230,7 +230,7 @@ static inline void xenpvh_gpex_init(XenPVHMachineState *s,object_initialize_child (OBJECT (s),"gpex" , &s->pci.gpex,TYPE_GPEX_HOST ); dev =DEVICE (&s->pci.gpex); -sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_realize (SYS_BUS_DEVICE (dev), &error_fatal); ecam_reg =sysbus_mmio_get_region (SYS_BUS_DEVICE (dev),0 );memory_region_add_subregion (sysmem, s->cfg.pci_ecam.base, ecam_reg);
Signature · 1 line
2.47.1
RFC PATCH v2 131/137 hw: Parent board-created CPUs under the machine
In reply to Alexander GrafA number of boards create CPUs via object_new(cpu_type) followed by property setting and qdev_realize(NULL), rather than through cpu_create(). These CPUs currently fall into /machine/unattached via the device_set_realized() fallback. Parent them explicitly under the machine (or the CPS/SoC container that owns them) as "cpu[*]", matching the naming convention used by cpu_create().
The subsequent object_unref() and qdev_realize_and_unref() calls are converted to plain qdev_realize() (or dropped) since the parent's child<> property now holds the reference. Error paths switch to object_unparent().
The transient introspection object_new() in hw/arm/virt.c machvirt_init() (probing pa_bits) is deliberately left as-is; it is unref'd immediately without being realized.
hw/arm: integratorcp mps3r realview sbsa-ref versatilepb
vexpress virt xilinx-zynq
hw/hexagon: hexagon_dsp virt
hw/i386: x86-common xen-pvh
hw/loongarch: virt
hw/mips: cps hw/ppc: e500 spapr (cpu-core) hw/riscv: cps microblaze-v-generic hw/s390x: s390-virtio-ccw hw/sparc: leon3 sun4m hw/sparc64: sparc64
Hot-plugged CPUs (via -device / device_add) continue to be parented under /machine/peripheral by the user's id=; only cold-boot board-created CPUs move under /machine/cpu[*].
AI-used-for: code (refactoring)
--- hw/arm/integratorcp.c | 3 ++- hw/arm/mps3r.c | 4 ++-- hw/arm/realview.c | 3 ++- hw/arm/sbsa-ref.c | 5 +++-- hw/arm/versatilepb.c | 3 ++- hw/arm/vexpress.c | 3 ++- hw/arm/virt.c | 5 +++-- hw/arm/xilinx_zynq.c | 3 ++- hw/hexagon/hexagon_dsp.c | 5 +++-- hw/hexagon/virt.c | 5 +++-- hw/i386/x86-common.c | 9 ++++----- hw/i386/xen/xen-pvh.c | 5 ++--- hw/loongarch/virt.c | 6 ++++-- hw/mips/cps.c | 5 +++-- hw/ppc/e500.c | 5 +++-- hw/ppc/spapr.c | 5 +++-- hw/riscv/cps.c | 5 +++-- hw/riscv/microblaze-v-generic.c | 3 ++- hw/s390x/s390-virtio-ccw.c | 16 +++++++--------- hw/sparc/leon3.c | 3 ++- hw/sparc/sun4m.c | 5 +++-- hw/sparc64/sparc64.c | 3 ++- 22 files changed, 62 insertions(+), 47 deletions(-)
hw/arm/integratorcp.c +2 -1
@@ -598,7 +598,8 @@ static void integratorcp_init(MachineState *machine)DriveInfo *dinfo;int i; - cpuobj =object_new (machine->cpu_type); + cpuobj =object_new_child (OBJECT (machine),"cpu[0]" , + machine->cpu_type);/* By default ARM1176 CPUs have EL3 enabled. This board does not * currently support EL3 so the CPU EL3 property is disabled before
hw/arm/mps3r.c +2 -2
@@ -388,13 +388,13 @@ static void mps3r_common_init(MachineState *machine)memory_region_add_subregion_overlap (&mms->cpu_sysmem[i],0 , &mms->sysmem_alias[i],-1 ); - mms->cpu[i] =object_new (machine->cpu_type); + mms->cpu[i] =object_new_child (OBJECT (mms),"cpu[*]" , + machine->cpu_type);object_property_set_link (mms->cpu[i],"memory" ,OBJECT (&mms->cpu_sysmem[i]), &error_abort);object_property_set_int (mms->cpu[i],"reset-cbar" ,PERIPHBASE , &error_abort);qdev_realize (DEVICE (mms->cpu[i]),NULL , &error_fatal); -object_unref (mms->cpu[i]);/* Per-CPU RAM */ memory_region_init_ram(&mms->cpu_ram[i], OBJECT(mms), ramname,
hw/arm/realview.c +2 -1
@@ -119,7 +119,8 @@ static void realview_init(MachineState *machine, }for (n =0 ; n < smp_cpus; n++) { -Object *cpuobj =object_new (machine->cpu_type); +Object *cpuobj =object_new_child (OBJECT (machine),"cpu[*]" , + machine->cpu_type);/* By default A9,A15 and ARM1176 CPUs have EL3 enabled. This board * does not currently support EL3 so the CPU EL3 property is disabled
hw/arm/sbsa-ref.c +3 -2
@@ -783,7 +783,9 @@ static void sbsa_ref_init(MachineState *machine)break ; } - cpuobj =object_new (possible_cpus->cpus[n].type); + g_autofree char *cpu_name = g_strdup_printf("cpu[%d]", n); + cpuobj =object_new_child (OBJECT (sms), cpu_name, + possible_cpus->cpus[n].type);object_property_set_int (cpuobj,"mp-affinity" , possible_cpus->cpus[n].arch_id,NULL );
@@ -808,7 +810,6 @@ static void sbsa_ref_init(MachineState *machine) OBJECT(secure_sysmem), &error_abort);qdev_realize (DEVICE (cpuobj),NULL , &error_fatal); -object_unref (cpuobj); } memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_MEM].base,
hw/arm/versatilepb.c +2 -1
@@ -208,7 +208,8 @@ static void versatile_init(MachineState *machine, int board_id)exit (1 ); } - cpuobj =object_new (machine->cpu_type); + cpuobj =object_new_child (OBJECT (machine),"cpu[0]" , + machine->cpu_type);/* By default ARM1176 CPUs have EL3 enabled. This board does not * currently support EL3 so the CPU EL3 property is disabled before
hw/arm/vexpress.c +2 -1
@@ -219,7 +219,8 @@ static void init_cpus(MachineState *ms, const char *cpu_type,/* Create the actual CPUs */ for (n =0 ; n < smp_cpus; n++) { -Object *cpuobj =object_new (cpu_type); +Object *cpuobj =object_new_child (qdev_get_machine (),"cpu[*]" , + cpu_type);if (!secure) {object_property_set_bool (cpuobj,"has_el3" , false,NULL );
hw/arm/virt.c +3 -2
@@ -3039,7 +3039,9 @@ static void machvirt_init(MachineState *machine)break ; } - cpuobj =object_new (possible_cpus->cpus[n].type); + g_autofree char *cpu_name = g_strdup_printf("cpu[%d]", n); + cpuobj =object_new_child (OBJECT (vms), cpu_name, + possible_cpus->cpus[n].type);object_property_set_int (cpuobj,"mp-affinity" , possible_cpus->cpus[n].arch_id,NULL );
@@ -3139,7 +3141,6 @@ static void machvirt_init(MachineState *machine) }qdev_realize (DEVICE (cpuobj),NULL , &error_fatal); -object_unref (cpuobj); }/* Now we've created the CPUs we can see if they have the hypvirt timer */
hw/arm/xilinx_zynq.c +2 -1
@@ -222,7 +222,8 @@ static void zynq_init(MachineState *machine) }for (n =0 ; n < smp_cpus; n++) { -Object *cpuobj =object_new (machine->cpu_type); +Object *cpuobj =object_new_child (OBJECT (machine),"cpu[*]" , + machine->cpu_type);object_property_set_int (cpuobj,"midr" ,ZYNQ_BOARD_MIDR , &error_fatal);
hw/hexagon/hexagon_dsp.c +3 -2
@@ -143,7 +143,8 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,sysbus_realize (SYS_BUS_DEVICE (tlb_dev), &error_fatal);for (int i =0 ; i < machine->smp.cpus; i++) { -HexagonCPU *cpu =HEXAGON_CPU (object_new (machine->cpu_type)); +HexagonCPU *cpu =HEXAGON_CPU (object_new_child (OBJECT (machine),"cpu[*]" , + machine->cpu_type));qemu_register_reset (do_cpu_reset, cpu);/*
@@ -158,7 +159,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev, OBJECT(glob_regs_dev), &error_fatal);object_property_set_link (OBJECT (cpu),"tlb" ,OBJECT (tlb_dev), &error_fatal); -qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal); +qdev_realize (DEVICE (cpu),NULL , &error_fatal); } rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
hw/hexagon/virt.c +3 -2
@@ -280,7 +280,8 @@ static void virt_init(MachineState *ms) cpu0 =NULL ;for (int i =0 ; i < ms->smp.cpus; i++) { -HexagonCPU *cpu =HEXAGON_CPU (object_new (ms->cpu_type)); +HexagonCPU *cpu =HEXAGON_CPU (object_new_child (OBJECT (ms),"cpu[*]" , + ms->cpu_type));qemu_register_reset (do_cpu_reset, cpu);if (i ==0 ) {
@@ -300,7 +301,7 @@ static void virt_init(MachineState *ms)object_property_set_link (OBJECT (cpu),"tlb" ,OBJECT (tlb_dev), &error_fatal); -qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal); +qdev_realize (DEVICE (cpu),NULL , &error_fatal); }fdt_add_cpu_nodes (vms); clk_phandle =fdt_add_clocks (vms);
hw/i386/x86-common.c +4 -5
@@ -55,15 +55,14 @@ static size_t pvh_start_addr;static void x86_cpu_new (X86MachineState *x86ms,int64_t apic_id,Error **errp) { -Object *cpu =object_new (MACHINE (x86ms)->cpu_type); +Object *cpu =object_new_child (OBJECT (x86ms),"cpu[*]" , +MACHINE (x86ms)->cpu_type);if (!object_property_set_uint (cpu,"apic-id" , apic_id, errp)) { - goto out; +object_unparent (cpu); +return ; }qdev_realize (DEVICE (cpu),NULL , errp); - -out: -object_unref (cpu); }void x86_cpus_init (X86MachineState *x86ms,int default_cpu_version)
hw/i386/xen/xen-pvh.c +2 -3
@@ -29,12 +29,11 @@ struct XenPVHx86State {static DeviceState *xen_pvh_cpu_new (MachineState *ms,int64_t apic_id) { -Object *cpu =object_new (ms->cpu_type); +Object *cpu =object_new_child (OBJECT (ms),"cpu[*]" , + ms->cpu_type); -object_property_add_child (OBJECT (ms),"cpu[*]" , cpu);object_property_set_uint (cpu,"apic-id" , apic_id, &error_fatal);qdev_realize (DEVICE (cpu),NULL , &error_fatal); -object_unref (cpu);return DEVICE (cpu); }
hw/loongarch/virt.c +4 -2
@@ -948,13 +948,15 @@ static void virt_init(MachineState *machine)/* Init CPUs */ mc->possible_cpu_arch_ids (machine);for (i =0 ; i < machine->smp.cpus; i++) { - cpuobj =object_new (machine->cpu_type); + g_autofree char *cpu_name = g_strdup_printf("cpu[%d]", i); + cpuobj =object_new_child (OBJECT (machine), cpu_name, + machine->cpu_type);if (cpuobj ==NULL ) {error_report ("Fail to create object with type %s " , machine->cpu_type);exit (EXIT_FAILURE ); } -qdev_realize_and_unref (DEVICE (cpuobj),NULL , &error_fatal); +qdev_realize (DEVICE (cpuobj),NULL , &error_fatal); }virt_check_dmsi (machine);fw_cfg_add_memory (machine);
hw/mips/cps.c +3 -2
@@ -74,7 +74,8 @@ static void mips_cps_realize(DeviceState *dev, Error **errp) }for (int i =0 ; i < s->num_vp; i++) { -MIPSCPU *cpu =MIPS_CPU (object_new (s->cpu_type)); +MIPSCPU *cpu =MIPS_CPU (object_new_child (OBJECT (s),"cpu[*]" , + s->cpu_type));CPUMIPSState *env = &cpu->env; object_property_set_bool(OBJECT(cpu), "big-endian", s->cpu_is_bigendian,
@@ -87,7 +88,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)/* All cores use the same clock tree */ qdev_connect_clock_in (DEVICE (cpu),"clk-in" , s->clock); -if (!qdev_realize_and_unref (DEVICE (cpu),NULL , errp)) { +if (!qdev_realize (DEVICE (cpu),NULL , errp)) {return ; }
hw/ppc/e500.c +3 -2
@@ -941,7 +941,8 @@ void ppce500_init(MachineState *machine)PowerPCCPU *cpu;CPUState *cs; - cpu =POWERPC_CPU (object_new (machine->cpu_type)); + cpu =POWERPC_CPU (object_new_child (OBJECT (machine),"cpu[*]" , + machine->cpu_type)); env = &cpu->env; cs =CPU (cpu);
@@ -956,7 +957,7 @@ void ppce500_init(MachineState *machine)*/ object_property_set_bool (OBJECT (cs),"start-powered-off" , i !=0 , &error_abort); -qdev_realize_and_unref (DEVICE (cs),NULL , &error_fatal); +qdev_realize (DEVICE (cs),NULL , &error_fatal);if (!firstenv) { firstenv = env;
hw/ppc/spapr.c +3 -2
@@ -2776,7 +2776,9 @@ static void spapr_init_cpus(SpaprMachineState *spapr) }if (i < boot_cores_nr) { -Object *core =object_new (type); + g_autofree char *core_name = g_strdup_printf("cpu-core[%d]", i); +Object *core =object_new_child (OBJECT (spapr), core_name, + type);int nr_threads = smp_threads;/* Handle the partially filled core for older machine types */
@@ -2790,7 +2792,6 @@ static void spapr_init_cpus(SpaprMachineState *spapr) &error_fatal);qdev_realize (DEVICE (core),NULL , &error_fatal); -object_unref (core); } } }
hw/riscv/cps.c +3 -2
@@ -63,13 +63,14 @@ static void riscv_cps_realize(DeviceState *dev, Error **errp)int harts_in_cluster = s->num_hart * s->num_core;int num_of_clusters = s->num_vp / harts_in_cluster;for (i =0 ; i < s->num_vp; i++) { - cpu =RISCV_CPU (object_new (s->cpu_type)); + cpu =RISCV_CPU (object_new_child (OBJECT (s),"cpu[*]" , + s->cpu_type));/* All VPs are halted on reset. Leave powering up to CPC. */ object_property_set_bool (OBJECT (cpu),"start-powered-off" , true, &error_abort); -if (!qdev_realize_and_unref (DEVICE (cpu),NULL , errp)) { +if (!qdev_realize (DEVICE (cpu),NULL , errp)) {return ; }
hw/riscv/microblaze-v-generic.c +2 -1
@@ -65,7 +65,8 @@ static void mb_v_generic_init(MachineState *machine)qemu_irq irq[32 ];MemoryRegion *sysmem =get_system_memory (); - cpu =RISCV_CPU (object_new (machine->cpu_type)); + cpu =RISCV_CPU (object_new_child (OBJECT (machine),"cpu[0]" , + machine->cpu_type));object_property_set_bool (OBJECT (cpu),"h" , false,NULL );object_property_set_bool (OBJECT (cpu),"d" , false,NULL );qdev_realize (DEVICE (cpu),NULL , &error_abort);
hw/s390x/s390-virtio-ccw.c +7 -9
@@ -56,20 +56,18 @@ static Error *pv_mig_blocker;static S390CPU *s390x_new_cpu (const char *typename,uint32_t core_id,Error **errp) { -S390CPU *cpu =S390_CPU (object_new (typename)); -S390CPU *ret =NULL ; +S390CPU *cpu =S390_CPU (object_new_child (qdev_get_machine (),"cpu[*]" , + typename));if (!object_property_set_int (OBJECT (cpu),"core-id" , core_id, errp)) { - goto out; +object_unparent (OBJECT (cpu)); +return NULL ; }if (!qdev_realize (DEVICE (cpu),NULL , errp)) { - goto out; +object_unparent (OBJECT (cpu)); +return NULL ; } - ret = cpu; - -out: -object_unref (OBJECT (cpu)); -return ret; +return cpu; }static void s390_init_cpus (MachineState *machine)
hw/sparc/leon3.c +2 -1
@@ -278,7 +278,8 @@ static void leon3_generic_hw_init(MachineState *machine)for (i =0 ; i < machine->smp.cpus; i++) {/* Init CPU */ - cpu =SPARC_CPU (object_new (machine->cpu_type)); + cpu =SPARC_CPU (object_new_child (OBJECT (machine),"cpu[*]" , + machine->cpu_type));qdev_init_gpio_in_named (DEVICE (cpu), leon3_start_cpu,"start_cpu" ,1 );qdev_init_gpio_in_named (DEVICE (cpu), leon3_set_pil_in,"pil" ,1 );qdev_realize (DEVICE (cpu),NULL , &error_fatal);
hw/sparc/sun4m.c +3 -2
@@ -787,7 +787,8 @@ static DeviceState *cpu_devinit(const char *cpu_type, unsigned int id,CPUSPARCState *env;DeviceState *cpudev; - cpu =SPARC_CPU (object_new (cpu_type)); + cpu =SPARC_CPU (object_new_child (qdev_get_machine (),"cpu[*]" , + cpu_type)); env = &cpu->env; cpudev =DEVICE (cpu);
@@ -795,7 +796,7 @@ static DeviceState *cpu_devinit(const char *cpu_type, unsigned int id,object_property_set_bool (OBJECT (cpu),"start-powered-off" , id !=0 , &error_abort);qdev_init_gpio_in_named (cpudev, cpu_set_irq,"pil" ,MAX_PILS ); -qdev_realize_and_unref (cpudev,NULL , &error_fatal); +qdev_realize (cpudev,NULL , &error_fatal);cpu_sparc_set_id (env, id); env->prom_addr = prom_addr;return cpudev;
hw/sparc64/sparc64.c +2 -1
@@ -272,7 +272,8 @@ SPARCCPU *sparc64_cpu_devinit(const char *cpu_type, uint64_t prom_addr)uint32_t stick_frequency =100 *1000000 ;uint32_t hstick_frequency =100 *1000000 ; - cpu =SPARC_CPU (object_new (cpu_type)); + cpu =SPARC_CPU (object_new_child (qdev_get_machine (),"cpu[0]" , + cpu_type));qdev_init_gpio_in_named (DEVICE (cpu), sparc64_cpu_set_ivec_irq,"ivec-irq" ,IVEC_MAX );qdev_realize (DEVICE (cpu),NULL , &error_fatal);
Signature · 1 line
2.47.1
RFC PATCH v2 132/137 hw/pci-host/versatile: Use object_initialize_child() for pci_dev
In reply to Alexander GrafThe embedded versatile_pci_host device was initialized via object_initialize() without ever being parented, so it landed in /machine/unattached at realize time. Switch to object_initialize_child() so it becomes a proper child<> of the host bridge.
AI-used-for: code (refactoring)
--- hw/pci-host/versatile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci-host/versatile.c +2 -1
@@ -410,7 +410,8 @@ static void pci_vpb_realize(DeviceState *dev, Error **errp) PCI_DEVFN(11, 0), TYPE_PCI_BUS); h->bus = &s->pci_bus; -object_initialize (&s->pci_dev,sizeof (s->pci_dev),TYPE_VERSATILE_PCI_HOST ); +object_initialize_child (OBJECT (s),"pci-host" , &s->pci_dev, +TYPE_VERSATILE_PCI_HOST );for (i =0 ; i <4 ; i++) {sysbus_init_irq (sbd, &s->irq[i]);
Signature · 1 line
2.47.1
RFC PATCH v2 133/137 docs, qapi, scripts, iotests: Update /machine/unattached path references
In reply to Alexander GrafBoard-created devices no longer land in /machine/unattached and the next commit removes the container entirely. Update the in-tree consumers of the old paths:
scripts/arm_processor_error.py, scripts/qmp_helper.py
Search for CPUs directly under /machine.
docs/devel/s390-cpu-topology.rst, docs/system/cpu-hotplug.rst qapi/{block-core,block,machine,qom}.json
Refresh example qom-path strings.
tests/qemu-iotests/common.filter
_filter_qom_path() now normalizes any /machine/... device path so the reference outputs are stable across board naming changes.
tests/qemu-iotests/{172,186}.out
Regenerated against the new filter.
AI-used-for: code (refactoring)
--- docs/devel/s390-cpu-topology.rst | 2 +- docs/system/cpu-hotplug.rst | 4 +- qapi/block-core.json | 12 +++--- qapi/block.json | 2 +- qapi/machine.json | 12 +++--- qapi/qom.json | 4 +- scripts/arm_processor_error.py | 3 +- scripts/qmp_helper.py | 2 +- tests/qemu-iotests/172.out | 72 ++++++++++++++++---------------- tests/qemu-iotests/186.out | 10 ++--- tests/qemu-iotests/common.filter | 2 +- 11 files changed, 62 insertions(+), 63 deletions(-)
docs/devel/s390-cpu-topology.rst +1 -1
@@ -40,7 +40,7 @@ modifiers for all configured vCPUs. }, "cpu-state": "operating", "entitlement": "medium", - "qom-path": "/machine/unattached/device[0]", + "qom-path": "/machine/cpu[0]", "cpu-index": 0, "target": "s390x" },
docs/system/cpu-hotplug.rst +2 -2
@@ -47,7 +47,7 @@ vCPU hotplug "socket-id": 0, "thread-id": 0 }, - "qom-path": "/machine/unattached/device[0]", + "qom-path": "/machine/cpu[0]", "type": "IvyBridge-IBRS-x86_64-cpu", "vcpus-count": 1 }
@@ -95,7 +95,7 @@ vCPU hotplug "socket-id": 0, "thread-id": 0 }, - "qom-path": "/machine/unattached/device[0]", + "qom-path": "/machine/cpu[0]", "target": "x86_64", "thread-id": 28957 },
qapi/block-core.json +6 -6
@@ -928,7 +928,7 @@ # "device":"ide1-cd0", # "locked":false, # "removable":true, -# "qdev": "/machine/unattached/device[23]", +# "qdev": "/machine/ide[1]/ide.1/cd0", # "tray_open": false, # "type":"unknown" # },
@@ -936,7 +936,7 @@ # "device":"floppy0", # "locked":false, # "removable":true, -# "qdev": "/machine/unattached/device[20]", +# "qdev": "/machine/fdc/floppy[0]", # "type":"unknown" # }, # {
@@ -1310,7 +1310,7 @@ # "account_invalid":true, # "account_failed":false # }, -# "qdev": "/machine/unattached/device[23]" +# "qdev": "/machine/ide[0]/ide.0/hd0" # }, # { # "device":"ide1-cd0",
@@ -1329,7 +1329,7 @@ # "account_invalid":false, # "account_failed":false # }, -# "qdev": "/machine/unattached/device[24]" +# "qdev": "/machine/ide[1]/ide.1/cd0" # }, # { # "device":"floppy0",
@@ -1348,7 +1348,7 @@ # "account_invalid":false, # "account_failed":false # }, -# "qdev": "/machine/unattached/device[16]" +# "qdev": "/machine/fdc/floppy[0]" # }, # { # "device":"sd0",
@@ -5750,7 +5750,7 @@ # .. qmp-example:: # # <- { "event": "BLOCK_IO_ERROR", -# "data": { "qom-path": "/machine/unattached/device[0]", +# "data": { "qom-path": "/machine/ide[0]/ide.0/hd1", # "device": "ide0-hd1", # "node-name": "#block212", # "operation": "write",
qapi/block.json +1 -1
@@ -404,7 +404,7 @@ # # <- { "event": "DEVICE_TRAY_MOVED", # "data": { "device": "ide1-cd0", -# "id": "/machine/unattached/device[22]", +# "id": "/machine/ide[1]/ide.1/cd0", # "tray-open": true # }, # "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
qapi/machine.json +6 -6
@@ -121,7 +121,7 @@ # "thread-id": 0, # "socket-id": 0 # }, -# "qom-path": "/machine/unattached/device[0]", +# "qom-path": "/machine/cpu[0]", # "target":"x86_64", # "cpu-index": 0 # },
@@ -132,7 +132,7 @@ # "thread-id": 0, # "socket-id": 1 # }, -# "qom-path": "/machine/unattached/device[2]", +# "qom-path": "/machine/cpu[1]", # "target":"x86_64", # "cpu-index": 1 # }
@@ -1028,7 +1028,7 @@ # { "props": { "core-id": 8 }, "type": "POWER8-spapr-cpu-core", # "vcpus-count": 1 }, # { "props": { "core-id": 0 }, "type": "POWER8-spapr-cpu-core", -# "vcpus-count": 1, "qom-path": "/machine/unattached/device[0]"} +# "vcpus-count": 1, "qom-path": "/machine/cpu[0]"} # ]} # # .. qmp-example::
@@ -1043,7 +1043,7 @@ # "props": {"core-id": 0, "socket-id": 1, "thread-id": 0} # }, # { -# "qom-path": "/machine/unattached/device[0]", +# "qom-path": "/machine/cpu[0]", # "type": "qemu64-x86_64-cpu", "vcpus-count": 1, # "props": {"core-id": 0, "socket-id": 0, "thread-id": 0} # }
@@ -1062,7 +1062,7 @@ # "props": { "core-id": 1 } # }, # { -# "qom-path": "/machine/unattached/device[0]", +# "qom-path": "/machine/cpu[0]", # "type": "qemu-s390x-cpu", "vcpus-count": 1, # "props": { "core-id": 0 } # }
@@ -1617,7 +1617,7 @@ # # <- { "event": "MEMORY_DEVICE_SIZE_CHANGE", # "data": { "id": "vm0", "size": 1073741824, -# "qom-path": "/machine/unattached/device[2]" }, +# "qom-path": "/machine/peripheral/vm0" }, # "timestamp": { "seconds": 1588168529, "microseconds": 201316 } } ## { 'event': 'MEMORY_DEVICE_SIZE_CHANGE',
qapi/qom.json +2 -2
@@ -135,7 +135,7 @@ # :title: Use absolute path # # -> { "execute": "qom-get", -# "arguments": { "path": "/machine/unattached/device[0]", +# "arguments": { "path": "/machine/cpu[0]", # "property": "hotplugged" } } # <- { "return": false } #
@@ -143,7 +143,7 @@ # :title: Use partial path # # -> { "execute": "qom-get", -# "arguments": { "path": "unattached/sysbus", +# "arguments": { "path": "machine/sysbus", # "property": "type" } } # <- { "return": "System" } ##
scripts/arm_processor_error.py +1 -2
@@ -244,8 +244,7 @@ def send_cper(self, args): qmp_cmd.set_args(args) is_cpu_type = re.compile(r"^([\w+]+\-)?arm\-cpu$") - cpus = qmp_cmd.search_qom("/machine/unattached/device", - "type", is_cpu_type) + cpus = qmp_cmd.search_qom("/machine/cpu", "type", is_cpu_type) cper = {} pei = {}
scripts/qmp_helper.py +1 -1
@@ -601,7 +601,7 @@ def search_qom(self, path, prop, regex): """ Return a list of devices that match path array like: - /machine/unattached/device + /machine/cpu /machine/peripheral-anon/device ... """
tests/qemu-iotests/172.out +36 -36
266 lines not on this page · raw message
tests/qemu-iotests/186.out +5 -5
@@ -404,7 +404,7 @@ Testing: -drive if=floppy QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block floppy0: [not inserted] - Attached to: /machine/unattached/device[N] + Attached to: PATH Removable device: not locked, tray closed (qemu) quit
@@ -412,7 +412,7 @@ Testing: -drive if=floppy,driver=null-co,read-zeroes=on QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block floppy0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: /machine/unattached/device[N] + Attached to: PATH Removable device: not locked, tray closed Cache mode: writeback (qemu) quit
@@ -421,7 +421,7 @@ Testing: -drive if=ide,driver=null-co,read-zeroes=on QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block ide0-hd0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co) - Attached to: /machine/unattached/device[N] + Attached to: PATH Cache mode: writeback (qemu) quit
@@ -429,7 +429,7 @@ Testing: -drive if=ide,media=cdrom QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block ide0-cd0: [not inserted] - Attached to: /machine/unattached/device[N] + Attached to: PATH Removable device: not locked, tray closed (qemu) quit
@@ -437,7 +437,7 @@ Testing: -drive if=ide,driver=null-co,read-zeroes=on,media=cdrom QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block ide0-cd0 (NODE_NAME): json:{"read-zeroes": "on", "driver": "null-co"} (null-co, read-only) - Attached to: /machine/unattached/device[N] + Attached to: PATH Removable device: not locked, tray closed Cache mode: writeback (qemu) quit
tests/qemu-iotests/common.filter +1 -1
@@ -37,7 +37,7 @@ _filter_generated_node_ids() _filter_qom_path() { - gsed -e '/Attached to:/s/\device[[0-9]\+\]/device[N]/g' + gsed -e '/Attached to:/s#/machine/.*#PATH#' } # replace occurrences of the actual TEST_DIR value with TEST_DIR
Signature · 1 line
2.47.1
RFC PATCH v2 134/137 qom: Delete /machine/unattached and error on unparented realize
In reply to Alexander GrafWith every board-created device, memory region, IRQ, and singleton now given an explicit QOM parent, the /machine/unattached container serves no legitimate purpose. Remove it and turn the device_set_realized() fallback into a hard error, so that any future orphan is caught at realize time rather than silently adopted into an anonymous bucket.
hw/core/qdev.c error out on !obj->parent instead of adopting
hw/core/qdev-user.c drop the fake unattached container
system/vl.c drop "unattached" from machine container list
hw/i386/pc.c search /machine recursively for the FDC instead
of the (unattached, peripheral, peripheral-anon) container triple
tests/unit/ parent test devices explicitly under /machine
After this commit, info qom-tree no longer shows /machine/unattached on any target/machine combination, and git grep '"unattached"' returns zero hits.
AI-used-for: code (refactoring)
--- hw/core/qdev-user.c | 6 +----- hw/core/qdev.c | 20 ++++---------------- hw/i386/pc.c | 11 +---------- include/hw/core/qdev.h | 2 +- system/vl.c | 1 - tests/unit/test-qdev-global-props.c | 17 +++++++---------- tests/unit/test-qdev.c | 12 ++++-------- 7 files changed, 18 insertions(+), 51 deletions(-)
hw/core/qdev-user.c +1 -5
@@ -11,9 +11,5 @@void qdev_create_fake_machine (void ) { -Object *fake_machine_obj; - - fake_machine_obj =object_property_add_new_container (object_get_root (), -"machine" ); -object_property_add_new_container (fake_machine_obj,"unattached" ); +object_property_add_new_container (object_get_root (),"machine" ); }
hw/core/qdev.c +4 -16
@@ -486,8 +486,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)BusState *bus;NamedClockList *ncl;Error *local_err =NULL ; -bool unattached_parent = false; -static int unattached_count;if (dev->hotplugged && !dc->hotpluggable) { error_setg(errp, "Device '%s' does not support hotplugging",
@@ -501,12 +499,10 @@ static void device_set_realized(Object *obj, bool value, Error **errp) }if (!obj->parent) { -gchar *name =g_strdup_printf ("device[%d]" , unattached_count++); - -object_property_add_child (machine_get_container ("unattached" ), - name, obj); - unattached_parent = true; -g_free (name); +error_setg (errp,"device type '%s' has no QOM parent; " +"use qdev_new() with a parent" , +object_get_typename (obj)); +return ; } hotplug_ctrl =qdev_get_hotplug_handler (dev);
@@ -634,14 +630,6 @@ post_realize_fail: fail:error_propagate (errp, local_err); -if (unattached_parent) { -/* -* Beware, this doesn't just revert -* object_property_add_child(), it also runs bus_remove()! -*/ -object_unparent (OBJECT (dev)); - unattached_count--; - } }static bool device_get_hotpluggable (Object *obj,Error **errp)
hw/i386/pc.c +1 -10
@@ -368,24 +368,15 @@ static int check_fdc(Object *obj, void *opaque)return 0 ; } -static const char *const fdc_container_path[] = { -"unattached" ,"peripheral" ,"peripheral-anon" -}; -/* * Locate the FDC at IO address 0x3f0, in order to configure the CMOS registers * and ACPI objects. */ static ISADevice *pc_find_fdc0 (void ) { -int i; -Object *container;CheckFdcState state = {0 }; -for (i =0 ; i <ARRAY_SIZE (fdc_container_path); i++) { - container =machine_get_container (fdc_container_path[i]); -object_child_foreach (container, check_fdc, &state); - } +object_child_foreach_recursive (qdev_get_machine (), check_fdc, &state);if (state.multiple) { warn_report("multiple floppy disk controllers with "
include/hw/core/qdev.h +1 -1
@@ -462,7 +462,7 @@ static inline bool qdev_is_realized(DeviceState *dev)* initialization. * @dev must not be plugged into a bus already. * If @bus, plug @dev into @bus. This takes a reference to @dev. -* If @dev has no QOM parent, make one up, taking another reference. +* @dev must already have a QOM parent (see qdev_new()). * * If you created @dev via object_new() directly (holding a floating * reference), you probably want to use qdev_realize_and_unref() instead.
system/vl.c +0 -1
@@ -2192,7 +2192,6 @@ static void parse_memory_options(void)static void qemu_create_machine_containers (Object *machine) {static const char *const containers[] = { -"unattached" ,"peripheral" ,"peripheral-anon" , };
tests/unit/test-qdev-global-props.c +7 -10
@@ -78,25 +78,22 @@ static const TypeInfo subclass_type = {* inherit the global states of the parent process) will try to create qdev * and realize the device. * -* Realization of such anonymous qdev (with no parent object) requires both -* the machine object and its "unattached" container to be at least present. +* Realization requires that the device already has a QOM parent. */ static void test_init_machine (void ) {/* This is a fake machine - it doesn't need to be a machine object */ -Object *machine =object_property_add_new_container ( +object_property_add_new_container (object_get_root (),"machine" ); -/* This container must exist for anonymous qdevs to realize() */ -object_property_add_new_container (machine,"unattached" ); -} + }/* Test simple static property setting to default value */ static void test_static_prop_subprocess (void ) {MyType *mt; - mt =STATIC_TYPE (object_new (TYPE_STATIC_PROPS )); + mt =STATIC_TYPE (object_new_child (qdev_get_machine (),"dev[*]" ,TYPE_STATIC_PROPS ));qdev_realize (DEVICE (mt),NULL , &error_fatal); g_assert_cmpuint(mt->prop1, ==, PROP_DEFAULT);
@@ -131,7 +128,7 @@ static void test_static_globalprop_subprocess(void)register_global_properties (props); - mt =STATIC_TYPE (object_new (TYPE_STATIC_PROPS )); + mt =STATIC_TYPE (object_new_child (qdev_get_machine (),"dev[*]" ,TYPE_STATIC_PROPS ));qdev_realize (DEVICE (mt),NULL , &error_fatal); g_assert_cmpuint(mt->prop1, ==, 200);
@@ -249,7 +246,7 @@ static void test_dynamic_globalprop_subprocess(void)register_global_properties (props); - mt =DYNAMIC_TYPE (object_new (TYPE_DYNAMIC_PROPS )); + mt =DYNAMIC_TYPE (object_new_child (qdev_get_machine (),"dev[*]" ,TYPE_DYNAMIC_PROPS ));qdev_realize (DEVICE (mt),NULL , &error_fatal); g_assert_cmpuint(mt->prop1, ==, 101);
@@ -295,7 +292,7 @@ static void test_subclass_global_props(void)register_global_properties (props); - mt =STATIC_TYPE (object_new (TYPE_SUBCLASS )); + mt =STATIC_TYPE (object_new_child (qdev_get_machine (),"dev[*]" ,TYPE_SUBCLASS ));qdev_realize (DEVICE (mt),NULL , &error_fatal); g_assert_cmpuint(mt->prop1, ==, 102);
tests/unit/test-qdev.c +4 -8
@@ -44,24 +44,21 @@ static const TypeInfo my_dev_type_info = {/* * Initialize a fake machine, being prepared for future tests. * -* Realization of anonymous qdev (with no parent object) requires both -* the machine object and its "unattached" container to be at least present. +* Realization requires that the device already has a QOM parent. */ static void test_init_machine (void ) {/* This is a fake machine - it doesn't need to be a machine object */ -Object *machine =object_property_add_new_container ( +object_property_add_new_container (object_get_root (),"machine" ); -/* This container must exist for anonymous qdevs to realize() */ -object_property_add_new_container (machine,"unattached" ); -} + }static void test_qdev_free_properties (void ) {MyDev *mt; - mt =STATIC_TYPE (object_new (TYPE_MY_DEV )); + mt =STATIC_TYPE (object_new_child (qdev_get_machine (),"dev[*]" ,TYPE_MY_DEV )); object_set_props(OBJECT(mt), &error_fatal, "string", "something", "array-u32", "12,13",
@@ -75,7 +72,6 @@ static void test_qdev_free_properties(void) g_assert_cmpuint(mt->prop_array_u32[1], ==, 13);object_unparent (OBJECT (mt)); -object_unref (mt); }
Signature · 1 line
2.47.1
RFC PATCH v2 135/137 tests/qtest/qom-test: Add smp-max init-time ceiling test
In reply to Alexander GrafAdd a slow-mode subtest that boots aarch64/virt and ppc64/pseries at their maximum -smp count and asserts that qtest_init() returns within 15 seconds. This guards against quadratic-time init regressions when many child objects are created under a single parent, such as the "[*]" auto-index property scan that made pseries take ~10 s to launch before qemu_extend_irqs() switched to explicit indices.
AI-used-for: code (refactoring)
--- tests/qtest/qom-test.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
tests/qtest/qom-test.c +35 -0
@@ -238,8 +238,32 @@ static void test_qom_qtests(void)qtest_quit (qts); } +/* +* Guard against O(n^2) init-time regressions when many child objects are +* created under one parent (e.g. board-created CPUs). Launch the machine +* at its maximum SMP count and assert an upper bound on time-to-monitor. +* The bound is generous (15 s) so this only fires when init cost blows up +* quadratically, not on ordinary CI jitter. +*/ +static void test_smp_max (gconstpointer data) +{ +const char *args = data; +gint64 t0, dt; +QTestState *qts; + + t0 =g_get_monotonic_time (); + qts =qtest_initf ("%s" , args); + dt =g_get_monotonic_time () - t0; + +g_test_message ("smp-max init time: %" G_GINT64_FORMAT " ms" , dt /1000 ); + g_assert_cmpint(dt, <, 15 * G_USEC_PER_SEC); + +qtest_quit (qts); +} +int main (int argc,char **argv) { +const char *arch =qtest_get_arch ();char *v_env =getenv ("V" );if (v_env) {
@@ -251,5 +275,16 @@ int main(int argc, char **argv)qtest_cb_for_every_machine (add_machine_test_case,g_test_quick ());qtest_add_func ("qom/qom-qtests" , test_qom_qtests); +if (g_test_slow ()) { +if (g_str_equal (arch,"aarch64" )) { +qtest_add_data_func ("qom/smp-max/virt" , +"-M virt,gic-version=max -smp 512" , + test_smp_max); + }else if (g_str_equal (arch,"ppc64" )) { +qtest_add_data_func ("qom/smp-max/pseries" , +"-M pseries -smp 512" , test_smp_max); + } + } +return g_test_run (); }
Signature · 1 line
2.47.1
RFC PATCH v2 136/137 docs/devel/qom: Document the composition-tree parenting contract
In reply to Alexander GrafAdd a section to the QOM developer documentation explaining that every object must have a composition-tree parent before use, how to pick the parent (creator owns lifetime), how to name children, the reference-count contract for parented creators, and where the contract is enforced (device_set_realized, memory_region_do_init, qdev_connect_gpio_out_named).
AI-used-for: code (refactoring)
--- docs/devel/qom.rst | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+)
docs/devel/qom.rst +96 -0
@@ -27,6 +27,102 @@ that make up a QEMU "machine". You can view this tree by running objects created by the machine itself as well those created due to user configuration. +Composition-tree parenting contract +==================================== + +Every QOM object that participates in the running system must have a +composition-tree parent before it is used. The parent gives the object +a stable, canonical path such as ``/machine/soc/uart[0]`` that is +visible in ``info qom-tree`` and addressable via ``qom-get`` and +``qom-set``. Objects that reach ``realize`` (for devices), that are +wired to another object (for IRQ lines), or that are given a name (for +memory regions) without a parent are programming errors. + +Creating parented objects +------------------------- + +The standard creation helpers all take the composition-tree parent and +the child name as their first two arguments: + +.. code-block:: c + + Object *object_new_child(Object *parent, const char *id, + const char *typename); + DeviceState *qdev_new(Object *parent, const char *id, + const char *typename); + DeviceState *sysbus_create_simple(Object *parent, const char *id, + const char *type, hwaddr, qemu_irq); + PCIDevice *pci_new(Object *parent, const char *id, ...); + ISADevice *isa_new(Object *parent, const char *id, ...); + /* i2c_slave_new(), ssi_create_peripheral(), usb_new(), + cpu_create() etc. follow the same pattern. */ + +``object_new()`` remains available as the primitive allocator for +transient introspection objects and for ``qdev_device_add()``, which +parents the device via ``qdev_set_id()``. All other callers should use +one of the parented helpers above, or ``object_initialize_child()`` for +objects that are embedded by value in the parent's instance struct. + +Choosing the parent +------------------- + +The QOM parent is the object that owns the child's lifetime. In +practice this is the object whose code is creating the child: + +* Board code (``MachineClass.init``) parents onboard devices to the + machine: ``OBJECT(machine)``. +* A composite device's ``DeviceClass.realize`` parents the sub-devices + it creates to itself: ``OBJECT(dev)``. +* An SoC container likewise parents the devices it creates to the SoC + object. + +The bus a device is plugged into is *not* its composition-tree parent. +A device may sit on a bus owned by ``B`` without being a child of +``B``; the bus relationship is expressed through the ``parent_bus`` +link, not the ``child<>`` property. + +Choosing the child name +----------------------- + +* A single instance takes a bare noun: ``"uart"``, ``"gic"``, ``"rtc"``. +* A fixed number of identical instances take an explicit index: + ``"uart[0]"``, ``"uart[1]"``. +* When the caller does not care about the index, ``"uart[*]"`` lets + QOM allocate the next free slot in the ``uart[]`` array. +* Address-based names such as ``"eth@0x30000000"`` should only be used + when the address is genuinely the identity of the device. + +Child names share the parent's property namespace, so avoid names that +collide with class-defined properties of the parent (in particular, +machine class properties visible on ``/machine``). + +Reference-count contract +------------------------ + +``object_new_child()``, ``qdev_new()`` and the per-bus creators return +with the object's single reference held by the parent's ``child<>`` +property. The caller does *not* hold a reference of its own and must +therefore pair creation with plain ``qdev_realize()`` rather than +``qdev_realize_and_unref()``. The object is finalized when the parent +drops its ``child<>`` property, typically via ``object_unparent()``. + +Enforcement +----------- + +The parenting contract is enforced at the points where an unparented +object would first become visible or entangled with another object: + +* ``device_set_realized()`` fails with an ``Error`` if the device has + no composition-tree parent. +* ``memory_region_do_init()`` asserts that a memory region given a + non-empty name also has an owner. +* ``qdev_connect_gpio_out_named()`` asserts that the outbound IRQ + line being connected already has a composition-tree parent. + +There is no ``/machine/unattached`` fallback container; an object that +would previously have landed there now triggers one of the errors +above instead. + Creating a QOM class ====================
Signature · 1 line
2.47.1
RFC PATCH v2 137/137 MAINTAINERS: Add scripts/coccinelle/qom-parent/ under QOM
In reply to Alexander GrafThe Coccinelle scripts used to perform the tree-wide *_orphan() renames are stored under scripts/coccinelle/qom-parent/. Add the directory to the QOM MAINTAINERS entry.
AI-used-for: code (refactoring)
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -3639,6 +3639,7 @@ S: Supported F: docs/devel/qom.rst F: include/qom/ F: qapi/qom.json +F: scripts/coccinelle/qom-parent/ F: scripts/coccinelle/qom-parent-type.cocci F: scripts/qom-cast-macro-clean-cocci-gen.py F: qom/
Signature · 1 line
2.47.1