hw: More QDev cleanups
PATCH 1/21 hw/i386/pc: Do not use C99 mixed-declarations style
In reply to Philippe Mathieu-DaudéQEMU's coding style generally forbids C99 mixed declarations.
--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i386/pc.c +2 -2
@@ -1227,6 +1227,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,*/ if (pcms->hpet_enabled) {qemu_irq rtc_irq; +uint8_t compat; hpet =qdev_try_new (TYPE_HPET );if (!hpet) {
@@ -1238,8 +1239,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,* use IRQ16~23, IRQ8 and IRQ2. If the user has already set * the property, use whatever mask they specified. */ -uint8_t compat =object_property_get_uint (OBJECT (hpet), -HPET_INTCAP ,NULL ); + compat =object_property_get_uint (OBJECT (hpet),HPET_INTCAP ,NULL );if (!compat) {qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); }
Signature · 1 line
2.41.0
PATCH 4/21 hw/tricore/testboard: Use qdev_new() instead of QOM basic API
In reply to Philippe Mathieu-DaudéPrefer QDev API for QDev objects, avoid the underlying QOM layer.
--- include/hw/tricore/tricore_testdevice.h | 3 --- hw/tricore/tricore_testboard.c | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-)
include/hw/tricore/tricore_testdevice.h +0 -3
@@ -25,12 +25,9 @@ OBJECT_CHECK(TriCoreTestDeviceState, (obj), TYPE_TRICORE_TESTDEVICE)typedef struct { -/* <private> */ SysBusDevice parent_obj; -/* <public> */ MemoryRegion iomem; - }TriCoreTestDeviceState ;#endif
hw/tricore/tricore_testboard.c +1 -3
@@ -89,9 +89,7 @@ static void tricore_testboard_init(MachineState *machine, int board_id)memory_region_add_subregion (sysmem,0xf0050000 , pcp_data);memory_region_add_subregion (sysmem,0xf0060000 , pcp_text); - test_dev =g_new (TriCoreTestDeviceState,1 ); -object_initialize (test_dev,sizeof (TriCoreTestDeviceState), -TYPE_TRICORE_TESTDEVICE ); + test_dev =TRICORE_TESTDEVICE (qdev_new (TYPE_TRICORE_TESTDEVICE ));memory_region_add_subregion (sysmem,0xf0000000 , &test_dev->iomem);
Signature · 1 line
2.41.0
PATCH 7/21 target: Replace DEVICE(object_new) -> qdev_new()
In reply to Philippe Mathieu-DaudéPrefer QDev API for QDev objects, avoid the underlying QOM layer.
--- target/mips/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
target/mips/cpu.c +1 -1
@@ -649,7 +649,7 @@ MIPSCPU *mips_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk) {DeviceState *cpu; - cpu =DEVICE (object_new (cpu_type)); + cpu =qdev_new (cpu_type);qdev_connect_clock_in (cpu,"clk-in" , cpu_refclk);qdev_realize (cpu,NULL , &error_abort);
target/xtensa/cpu.c +1 -1
@@ -205,7 +205,7 @@ XtensaCPU *xtensa_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk) {DeviceState *cpu; - cpu =DEVICE (object_new (cpu_type)); + cpu =qdev_new (cpu_type);qdev_connect_clock_in (cpu,"clk-in" , cpu_refclk);qdev_realize (cpu,NULL , &error_abort);
Signature · 1 line
2.41.0
cover hw: More QDev cleanups
Various QDev cleanups extracted to my "enforce QDev API" branch.
- When available, instead of plain QOM, use QDev API equivalent
- Add missing QOM parentship for some obj created with qdev_*new()
- Prefer object_initialize_child() over object_initialize()
Philippe Mathieu-Daudé (21):
hw/i386/pc: Do not use C99 mixed-declarations style hw/i386/pc_sysfw: Use qdev_is_realized() instead of QOM API hw/ppc/spapr_cpu: Use qdev_is_realized() instead of QOM API hw/tricore/testboard: Use qdev_new() instead of QOM basic API hw/ppc/pnv_bmc: Use qdev_new() instead of QOM API
hw: Replace DEVICE(object_new) -> qdev_new()
target: Replace DEVICE(object_new) -> qdev_new()
hw/isa: Inline isa_try_new()
hw/usb: Inline usb_try_new()
hw/usb: Inline usb_new()
hw/usb: Add QOM parentship relation with hub devices hw/pci-host/q35: Update q35_host_props[] comment hw/pci-host/raven: Embedded OrIRQ in PRePPCIState hw/pci-host/raven: Prefer object_initialize_child over
object_initialize
hw/core/register: Prefer object_initialize_child over
object_initialize
hw/net/can/versal: Prefer object_initialize_child over
object_initialize
hw/i386/iommu: Prefer object_initialize_child over object_initialize hw/pci-host/versatile: Replace object_initialize() -> _child() hw/s390x/zpci-bus: Add QOM parentship relation with zPCI devices hw/arm/mps2: Add QOM parentship relation with OR IRQ gates
hw: Add QOM parentship relation with CPUs
include/hw/isa/isa.h | 1 - include/hw/net/ne2000-isa.h | 2 +- include/hw/tricore/tricore_testdevice.h | 3 --- include/hw/usb.h | 1 - hw/arm/mps2.c | 5 +++++ hw/arm/musicpal.c | 2 +- hw/core/qdev.c | 2 +- hw/core/register.c | 2 +- hw/i386/amd_iommu.c | 6 +++--- hw/i386/pc.c | 6 +++--- hw/i386/pc_sysfw.c | 6 ++---- hw/i386/x86.c | 1 + hw/isa/isa-bus.c | 5 ----- hw/microblaze/petalogix_ml605_mmu.c | 1 + hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/mips/cps.c | 1 + hw/net/can/xlnx-versal-canfd.c | 2 +- hw/nios2/10m50_devboard.c | 1 + hw/pci-host/q35.c | 6 +++--- hw/pci-host/raven.c | 18 ++++++++---------- hw/pci-host/versatile.c | 3 ++- hw/ppc/e500.c | 1 + hw/ppc/pnv_bmc.c | 10 +++++----- hw/ppc/spapr.c | 1 + hw/ppc/spapr_cpu_core.c | 3 +-- hw/s390x/s390-pci-bus.c | 1 + hw/sparc/sun4m.c | 4 ++-- hw/tricore/tricore_testboard.c | 4 +--- hw/usb/bus.c | 17 ++++------------- hw/usb/dev-serial.c | 2 +- target/mips/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 32 files changed, 55 insertions(+), 67 deletions(-)
Signature · 1 line
2.41.0
PATCH 2/21 hw/i386/pc_sysfw: Use qdev_is_realized() instead of QOM API
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
--- hw/i386/pc_sysfw.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/i386/pc_sysfw.c +2 -4
@@ -107,17 +107,15 @@ void pc_system_flash_cleanup_unused(PCMachineState *pcms) {char *prop_name;int i; -Object *dev_obj;assert (PC_MACHINE_GET_CLASS (pcms)->pci_enabled);for (i =0 ; i <ARRAY_SIZE (pcms->flash); i++) { - dev_obj =OBJECT (pcms->flash[i]); -if (!object_property_get_bool (dev_obj,"realized" , &error_abort)) { +if (!qdev_is_realized (DEVICE (pcms->flash[i]))) { prop_name =g_strdup_printf ("pflash%d" , i);object_property_del (OBJECT (pcms), prop_name);g_free (prop_name); -object_unparent (dev_obj); +object_unparent (OBJECT (pcms->flash[i])); pcms->flash[i] =NULL ; } }
Signature · 1 line
2.41.0
PATCH 13/21 hw/pci-host/raven: Embedded OrIRQ in PRePPCIState
In reply to Philippe Mathieu-DaudéSince we know the size of the OrIRQ object, we can initialize it directly in place with object_initialize_child(). Doing so we also set the QOM parent <-> child relationship.
--- hw/pci-host/raven.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/pci-host/raven.c +6 -6
@@ -60,7 +60,7 @@ DECLARE_INSTANCE_CHECKER(PREPPCIState, RAVEN_PCI_HOST_BRIDGE,struct PRePPCIState {PCIHostState parent_obj; -OrIRQState *or_irq; +OrIRQState or_irq;qemu_irq pci_irqs[PCI_NUM_PINS ];PCIBus pci_bus;AddressSpace pci_io_as;
@@ -249,14 +249,14 @@ static void raven_pcihost_realizefn(DeviceState *d, Error **errp) }else {/* 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 )); -object_property_set_int (OBJECT (s->or_irq),"num-lines" ,PCI_NUM_PINS , +object_initialize_child (OBJECT (dev),"or-irq" , &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); -sysbus_init_irq (dev, &s->or_irq->out_irq); +qdev_realize (DEVICE (&s->or_irq),NULL , &error_fatal); +sysbus_init_irq (dev, &s->or_irq.out_irq);for (i =0 ; i <PCI_NUM_PINS ; i++) { - s->pci_irqs[i] =qdev_get_gpio_in (DEVICE (s->or_irq), i); + s->pci_irqs[i] =qdev_get_gpio_in (DEVICE (&s->or_irq), i); } }
Signature · 1 line
2.41.0
PATCH 11/21 hw/usb: Add QOM parentship relation with hub devices
In reply to Philippe Mathieu-DaudéQDev objects created with qdev_*new() need to manually add their parent relationship with object_property_add_child().
--- hw/usb/bus.c | 1 + 1 file changed, 1 insertion(+)
hw/usb/bus.c +1 -0
@@ -439,6 +439,7 @@ void usb_claim_port(USBDevice *dev, Error **errp)/* Create a new hub and chain it on */ hub =USB_DEVICE (qdev_try_new ("usb-hub" ));if (hub) { +object_property_add_child (OBJECT (dev),"hub" ,OBJECT (hub));usb_realize_and_unref (hub, bus,NULL ); } }
Signature · 1 line
2.41.0
PATCH 5/21 hw/ppc/pnv_bmc: Use qdev_new() instead of QOM API
In reply to Philippe Mathieu-DaudéPrefer QDev API for QDev objects, avoid the underlying QOM layer.
--- hw/ppc/pnv_bmc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/pnv_bmc.c +5 -5
@@ -269,13 +269,13 @@ void pnv_bmc_set_pnor(IPMIBmc *bmc, PnvPnor *pnor)*/ IPMIBmc *pnv_bmc_create (PnvPnor *pnor) { -Object *obj; +DeviceState *dev; - obj =object_new (TYPE_IPMI_BMC_SIMULATOR ); -qdev_realize (DEVICE (obj),NULL , &error_fatal); -pnv_bmc_set_pnor (IPMI_BMC (obj), pnor); + dev =qdev_new (TYPE_IPMI_BMC_SIMULATOR ); +qdev_realize (dev,NULL , &error_fatal); +pnv_bmc_set_pnor (IPMI_BMC (dev), pnor); -return IPMI_BMC (obj); +return IPMI_BMC (dev); } typedef struct ForeachArgs {
Signature · 1 line
2.41.0
PATCH 17/21 hw/i386/iommu: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéWhen the QOM parent is available, prefer object_initialize_child() over object_initialize(), since it create the parent relationship.
Rename the 'klass' variable as 'obj' since the argument holds a reference to an instance object and not a class one.
--- hw/i386/amd_iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/i386/amd_iommu.c +3 -3
@@ -1616,11 +1616,11 @@ static const VMStateDescription vmstate_amdvi_sysbus = { .unmigratable = 1 }; -static void amdvi_sysbus_instance_init (Object *klass) +static void amdvi_sysbus_instance_init (Object *obj) { -AMDVIState *s =AMD_IOMMU_DEVICE (klass); +AMDVIState *s =AMD_IOMMU_DEVICE (obj); -object_initialize (&s->pci,sizeof (s->pci),TYPE_AMD_IOMMU_PCI ); +object_initialize_child (obj,"iommu" , &s->pci,TYPE_AMD_IOMMU_PCI ); }static void amdvi_sysbus_class_init (ObjectClass *klass,void *data)
Signature · 1 line
2.41.0
PATCH 6/21 hw: Replace DEVICE(object_new) -> qdev_new()
In reply to Philippe Mathieu-DaudéPrefer QDev API for QDev objects, avoid the underlying QOM layer.
--- hw/arm/musicpal.c | 2 +- hw/core/qdev.c | 2 +- hw/sparc/sun4m.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
hw/arm/musicpal.c +1 -1
@@ -1238,7 +1238,7 @@ static void musicpal_init(MachineState *machine) qdev_get_gpio_in(pic, MP_TIMER4_IRQ), NULL);/* Logically OR both UART IRQs together */ - uart_orgate =DEVICE (object_new (TYPE_OR_IRQ )); + uart_orgate =qdev_new (TYPE_OR_IRQ );object_property_set_int (OBJECT (uart_orgate),"num-lines" ,2 , &error_fatal);qdev_realize_and_unref (uart_orgate,NULL , &error_fatal); qdev_connect_gpio_out(uart_orgate, 0,
hw/core/qdev.c +1 -1
@@ -171,7 +171,7 @@ DeviceState *qdev_try_new(const char *name)if (!module_object_class_by_name (name)) {return NULL ; } -return DEVICE (object_new (name)); +return qdev_new (name); } static QTAILQ_HEAD(, DeviceListener) device_listeners
hw/sparc/sun4m.c +2 -2
@@ -979,7 +979,7 @@ static void sun4m_hw_init(MachineState *machine)sysbus_mmio_map (s,0 , hwdef->ms_kb_base);/* Logically OR both its IRQs together */ - ms_kb_orgate =DEVICE (object_new (TYPE_OR_IRQ )); + ms_kb_orgate =qdev_new (TYPE_OR_IRQ );object_property_set_int (OBJECT (ms_kb_orgate),"num-lines" ,2 , &error_fatal);qdev_realize_and_unref (ms_kb_orgate,NULL , &error_fatal);sysbus_connect_irq (s,0 ,qdev_get_gpio_in (ms_kb_orgate,0 ));
@@ -1000,7 +1000,7 @@ static void sun4m_hw_init(MachineState *machine)sysbus_mmio_map (s,0 , hwdef->serial_base);/* Logically OR both its IRQs together */ - serial_orgate =DEVICE (object_new (TYPE_OR_IRQ )); + serial_orgate =qdev_new (TYPE_OR_IRQ );object_property_set_int (OBJECT (serial_orgate),"num-lines" ,2 , &error_fatal);qdev_realize_and_unref (serial_orgate,NULL , &error_fatal);
Signature · 1 line
2.41.0
PATCH 12/21 hw/pci-host/q35: Update q35_host_props[] comment
In reply to Philippe Mathieu-DaudéCommit aff39be0ed ("hw/pci-host: Use object_initialize_child for correct reference counting") replaced object_initialize() by object_initialize_child(), update the comment.
--- hw/pci-host/q35.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/pci-host/q35.c +3 -3
@@ -165,10 +165,10 @@ static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v,/* * NOTE: setting defaults for the mch.* fields in this table * doesn't work, because mch is a separate QOM object that is -* zeroed by the object_initialize(&s->mch, ...) call inside +* zeroed by the object_initialize_child(..., &s->mch, ...) call inside * q35_host_initfn(). The default values for those * properties need to be initialized manually by -* q35_host_initfn() after the object_initialize() call. +* q35_host_initfn() after the object_initialize_child() call. */ static Property q35_host_props[] = { DEFINE_PROP_UINT64(PCIE_HOST_MCFG_BASE, Q35PCIHost, parent_obj.base_addr,
@@ -211,7 +211,7 @@ static void q35_host_initfn(Object *obj)object_initialize_child (OBJECT (s),"mch" , &s->mch,TYPE_MCH_PCI_DEVICE );qdev_prop_set_int32 (DEVICE (&s->mch),"addr" ,PCI_DEVFN (0 ,0 ));qdev_prop_set_bit (DEVICE (&s->mch),"multifunction" , false); -/* mch's object_initialize resets the default value, set it again */ +/* mch's object_initialize_child resets the default value, set it again */ qdev_prop_set_uint64 (DEVICE (s),PCI_HOST_PROP_PCI_HOLE64_SIZE ,Q35_PCI_HOST_HOLE64_SIZE_DEFAULT ); object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "uint32",
Signature · 1 line
2.41.0
PATCH 15/21 hw/core/register: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéWhen the QOM parent is available, prefer object_initialize_child() over object_initialize(), since it create the parent relationship.
--- hw/core/register.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/register.c +1 -1
@@ -259,7 +259,7 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,RegisterInfo *r = &ri[index];/* Init the register, this will zero it. */ -object_initialize ((void *)r,sizeof (*r),TYPE_REGISTER ); +object_initialize_child (OBJECT (owner),"reg[*]" , r,TYPE_REGISTER );/* Set the properties of the register */ r->data = data + data_size * index;
Signature · 1 line
2.41.0
PATCH 19/21 hw/s390x/zpci-bus: Add QOM parentship relation with zPCI devices
In reply to Philippe Mathieu-DaudéQDev objects created with qdev_*new() need to manually add their parent relationship with object_property_add_child().
--- hw/s390x/s390-pci-bus.c | 1 + 1 file changed, 1 insertion(+)
hw/s390x/s390-pci-bus.c +1 -0
@@ -934,6 +934,7 @@ static S390PCIBusDevice *s390_pci_device_new(S390pciState *s, "zPCI device could not be created: ");return NULL ; } +object_property_add_child (OBJECT (s),"zpci[*]" ,OBJECT (dev));if (!qdev_realize_and_unref (dev,BUS (s->bus), &local_err)) {object_unparent (OBJECT (dev)); error_propagate_prepend(errp, local_err,
Signature · 1 line
2.41.0
PATCH 20/21 hw/arm/mps2: Add QOM parentship relation with OR IRQ gates
In reply to Philippe Mathieu-DaudéQDev objects created with object_new() need to manually add their parent relationship with object_property_add_child().
---
Better would be to embedded an call object_initialize_child()...
--- hw/arm/mps2.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/arm/mps2.c +5 -0
@@ -274,6 +274,7 @@ static void mps2_common_init(MachineState *machine) orgate =object_new (TYPE_OR_IRQ );object_property_set_int (orgate,"num-lines" ,6 , &error_fatal); +object_property_add_child (OBJECT (machine),"orgate12" , orgate);qdev_realize (DEVICE (orgate),NULL , &error_fatal); orgate_dev =DEVICE (orgate);qdev_connect_gpio_out (orgate_dev,0 ,qdev_get_gpio_in (armv7m,12 ));
@@ -317,6 +318,7 @@ static void mps2_common_init(MachineState *machine) orgate =object_new (TYPE_OR_IRQ );object_property_set_int (orgate,"num-lines" ,10 , &error_fatal); +object_property_add_child (OBJECT (machine),"orgate-12" , orgate);qdev_realize (DEVICE (orgate),NULL , &error_fatal); orgate_dev =DEVICE (orgate);qdev_connect_gpio_out (orgate_dev,0 ,qdev_get_gpio_in (armv7m,12 ));
@@ -333,6 +335,8 @@ static void mps2_common_init(MachineState *machine) txrx_orgate =object_new (TYPE_OR_IRQ );object_property_set_int (txrx_orgate,"num-lines" ,2 , &error_fatal); +object_property_add_child (OBJECT (machine), +"orgate-uart[*]" , txrx_orgate);qdev_realize (DEVICE (txrx_orgate),NULL , &error_fatal); txrx_orgate_dev =DEVICE (txrx_orgate); qdev_connect_gpio_out(txrx_orgate_dev, 0,
@@ -425,6 +429,7 @@ static void mps2_common_init(MachineState *machine) orgate =object_new (TYPE_OR_IRQ );object_property_set_int (orgate,"num-lines" ,2 , &error_fatal); +object_property_add_child (OBJECT (machine),"orgate-ssi[*]" , orgate); orgate_dev =DEVICE (orgate);qdev_realize (orgate_dev,NULL , &error_fatal); qdev_connect_gpio_out(orgate_dev, 0,
Signature · 1 line
2.41.0
PATCH 9/21 hw/usb: Inline usb_try_new()
In reply to Philippe Mathieu-DaudéInline the single use of usb_try_new().
--- hw/usb/bus.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
hw/usb/bus.c +1 -6
@@ -334,11 +334,6 @@ USBDevice *usb_new(const char *name)return USB_DEVICE (qdev_new (name)); } -static USBDevice *usb_try_new (const char *name) -{ -return USB_DEVICE (qdev_try_new (name)); -} -bool usb_realize_and_unref (USBDevice *dev,USBBus *bus,Error **errp) {return qdev_realize_and_unref (&dev->qdev, &bus->qbus, errp);
@@ -447,7 +442,7 @@ void usb_claim_port(USBDevice *dev, Error **errp) }else {if (bus->nfree ==1 &&strcmp (object_get_typename (OBJECT (dev)),"usb-hub" ) !=0 ) {/* Create a new hub and chain it on */ - hub =usb_try_new ("usb-hub" ); + hub =USB_DEVICE (qdev_try_new ("usb-hub" ));if (hub) {usb_realize_and_unref (hub, bus,NULL ); }
Signature · 1 line
2.41.0
PATCH 14/21 hw/pci-host/raven: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéWhen the QOM parent is available, prefer object_initialize_child() over object_initialize(), since it create the parent relationship.
--- hw/pci-host/raven.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/pci-host/raven.c +2 -4
@@ -290,7 +290,6 @@ static void raven_pcihost_initfn(Object *obj)PCIHostState *h =PCI_HOST_BRIDGE (obj);PREPPCIState *s =RAVEN_PCI_HOST_BRIDGE (obj);MemoryRegion *address_space_mem =get_system_memory (); -DeviceState *pci_dev;memory_region_init (&s->pci_io, obj,"pci-io" ,0x3f800000 ); memory_region_init_io(&s->pci_io_non_contiguous, obj, &raven_io_ops, s,
@@ -328,11 +327,10 @@ static void raven_pcihost_initfn(Object *obj) h->bus = &s->pci_bus; -object_initialize (&s->pci_dev,sizeof (s->pci_dev),TYPE_RAVEN_PCI_DEVICE ); - pci_dev =DEVICE (&s->pci_dev); +object_initialize_child (obj,"bridge" , &s->pci_dev,TYPE_RAVEN_PCI_DEVICE );object_property_set_int (OBJECT (&s->pci_dev),"addr" ,PCI_DEVFN (0 ,0 ),NULL ); -qdev_prop_set_bit (pci_dev,"multifunction" , false); +qdev_prop_set_bit (DEVICE (&s->pci_dev),"multifunction" , false); }static void raven_realize (PCIDevice *d,Error **errp)
Signature · 1 line
2.41.0
PATCH 16/21 hw/net/can/versal: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéWhen the QOM parent is available, prefer object_initialize_child() over object_initialize(), since it create the parent relationship.
--- hw/net/can/xlnx-versal-canfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/can/xlnx-versal-canfd.c +1 -1
@@ -1900,7 +1900,7 @@ static int canfd_populate_regarray(XlnxVersalCANFDState *s,int index = rae[i].addr /4 ;RegisterInfo *r = &s->reg_info[index]; -object_initialize (r,sizeof (*r),TYPE_REGISTER ); +object_initialize_child (OBJECT (s),"reg[*]" , r,TYPE_REGISTER ); *r = (RegisterInfo ) { .data = &s->regs[index],
Signature · 1 line
2.41.0
PATCH 10/21 hw/usb: Inline usb_new()
In reply to Philippe Mathieu-DaudéInline the 2 uses of usb_new().
--- include/hw/usb.h | 1 - hw/usb/bus.c | 9 ++------- hw/usb/dev-serial.c | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-)
include/hw/usb.h +0 -1
@@ -500,7 +500,6 @@ void usb_bus_release(USBBus *bus);USBBus *usb_bus_find (int busnr);void usb_legacy_register (const char *typename,const char *usbdevice_name,USBDevice *(*usbdevice_init)(void )); -USBDevice *usb_new (const char *name);bool usb_realize_and_unref (USBDevice *dev,USBBus *bus,Error **errp);USBDevice *usb_create_simple (USBBus *bus,const char *name);USBDevice *usbdevice_create (const char *cmdline);
hw/usb/bus.c +2 -7
@@ -329,11 +329,6 @@ void usb_legacy_register(const char *typename, const char *usbdevice_name, } } -USBDevice *usb_new (const char *name) -{ -return USB_DEVICE (qdev_new (name)); -} -bool usb_realize_and_unref (USBDevice *dev,USBBus *bus,Error **errp) {return qdev_realize_and_unref (&dev->qdev, &bus->qbus, errp);
@@ -341,7 +336,7 @@ bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)USBDevice *usb_create_simple (USBBus *bus,const char *name) { -USBDevice *dev =usb_new (name); +USBDevice *dev =USB_DEVICE (qdev_new (name));usb_realize_and_unref (dev, bus, &error_abort);return dev;
@@ -693,7 +688,7 @@ USBDevice *usbdevice_create(const char *driver)return NULL ; } - dev = f->usbdevice_init ? f->usbdevice_init () :usb_new (f->name); + dev = f->usbdevice_init ? f->usbdevice_init () :USB_DEVICE (qdev_new (f->name));if (!dev) {error_report ("Failed to create USB device '%s'" , f->name);return NULL ;
hw/usb/dev-serial.c +1 -1
@@ -624,7 +624,7 @@ static USBDevice *usb_braille_init(void)return NULL ; } - dev =usb_new ("usb-braille" ); + dev =USB_DEVICE (qdev_new ("usb-braille" ));qdev_prop_set_chr (&dev->qdev,"chardev" , cdrv);return dev; }
Signature · 1 line
2.41.0
PATCH 21/21 hw: Add QOM parentship relation with CPUs
In reply to Philippe Mathieu-DaudéQDev objects created with object_new() need to manually add their parent relationship with object_property_add_child().
--- hw/i386/x86.c | 1 + hw/microblaze/petalogix_ml605_mmu.c | 1 + hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/mips/cps.c | 1 + hw/nios2/10m50_devboard.c | 1 + hw/ppc/e500.c | 1 + hw/ppc/spapr.c | 1 + 7 files changed, 7 insertions(+)
hw/i386/x86.c +1 -0
@@ -102,6 +102,7 @@ void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)if (!object_property_set_uint (cpu,"apic-id" , apic_id, errp)) { goto out; } +object_property_add_child (OBJECT (x86ms),"cpu[*]" ,OBJECT (cpu));qdev_realize (DEVICE (cpu),NULL , errp); out:
hw/microblaze/petalogix_ml605_mmu.c +1 -0
@@ -83,6 +83,7 @@ petalogix_ml605_init(MachineState *machine)/* init CPUs */ cpu =MICROBLAZE_CPU (object_new (TYPE_MICROBLAZE_CPU )); +object_property_add_child (OBJECT (machine),"cpu" ,OBJECT (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 +1 -0
@@ -70,6 +70,7 @@ petalogix_s3adsp1800_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory (); cpu =MICROBLAZE_CPU (object_new (TYPE_MICROBLAZE_CPU )); +object_property_add_child (OBJECT (machine),"cpu" ,OBJECT (cpu));object_property_set_str (OBJECT (cpu),"version" ,"7.10.d" , &error_abort);qdev_realize (DEVICE (cpu),NULL , &error_abort);
hw/mips/cps.c +1 -0
@@ -84,6 +84,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); +object_property_add_child (OBJECT (dev),"cpu[*]" ,OBJECT (cpu));if (!qdev_realize_and_unref (DEVICE (cpu),NULL , errp)) {return ; }
hw/nios2/10m50_devboard.c +1 -0
@@ -95,6 +95,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine) cpu->exception_addr =0xc8000120 ; cpu->fast_tlb_miss_addr =0xc0000100 ; +object_property_add_child (OBJECT (machine),"cpu" ,OBJECT (cpu));qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal);if (nms->vic) {
hw/ppc/e500.c +1 -0
@@ -956,6 +956,7 @@ void ppce500_init(MachineState *machine)*/ object_property_set_bool (OBJECT (cs),"start-powered-off" , i !=0 , &error_abort); +object_property_add_child (OBJECT (machine),"cpu[*]" ,OBJECT (cpu));qdev_realize_and_unref (DEVICE (cs),NULL , &error_fatal);if (!firstenv) {
hw/ppc/spapr.c +1 -0
@@ -2715,6 +2715,7 @@ static void spapr_init_cpus(SpaprMachineState *spapr) &error_fatal);object_property_set_int (core,CPU_CORE_PROP_CORE_ID , core_id, &error_fatal); +object_property_add_child (OBJECT (spapr),"cpu[*]" ,OBJECT (core));qdev_realize (DEVICE (core),NULL , &error_fatal);object_unref (core);
Signature · 1 line
2.41.0
Re: [PATCH 05/21] hw/ppc/pnv_bmc: Use qdev_new() instead of QOM API
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 27 lines
--- hw/ppc/pnv_bmc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)hw/ppc/pnv_bmc.c +5
-5@@ -269,13 +269,13 @@ void pnv_bmc_set_pnor(IPMIBmc *bmc, PnvPnor *pnor)*/ IPMIBmc *pnv_bmc_create (PnvPnor *pnor) { -Object *obj; +DeviceState *dev; - obj =object_new (TYPE_IPMI_BMC_SIMULATOR ); -qdev_realize (DEVICE (obj),NULL , &error_fatal); -pnv_bmc_set_pnor (IPMI_BMC (obj), pnor); + dev =qdev_new (TYPE_IPMI_BMC_SIMULATOR ); +qdev_realize (dev,NULL , &error_fatal); +pnv_bmc_set_pnor (IPMI_BMC (dev), pnor); -return IPMI_BMC (obj); +return IPMI_BMC (dev); } typedef struct ForeachArgs {
PATCH 8/21 hw/isa: Inline isa_try_new()
In reply to Philippe Mathieu-DaudéInline the 2 single uses of isa_try_new().
--- include/hw/isa/isa.h | 1 - include/hw/net/ne2000-isa.h | 2 +- hw/i386/pc.c | 2 +- hw/isa/isa-bus.c | 5 ----- 4 files changed, 2 insertions(+), 8 deletions(-)
include/hw/isa/isa.h +0 -1
@@ -81,7 +81,6 @@ IsaDma *isa_bus_get_dma(ISABus *bus, int nchan);*/ qemu_irq isa_bus_get_irq (ISABus *bus,unsigned irqnum);ISADevice *isa_new (const char *name); -ISADevice *isa_try_new (const char *name);bool isa_realize_and_unref (ISADevice *dev,ISABus *bus,Error **errp);ISADevice *isa_create_simple (ISABus *bus,const char *name);
include/hw/net/ne2000-isa.h +1 -1
@@ -22,7 +22,7 @@ static inline ISADevice *isa_ne2000_init(ISABus *bus, int base, int irq, {ISADevice *d; - d =isa_try_new (TYPE_ISA_NE2000 ); + d =ISA_DEVICE (qdev_try_new (TYPE_ISA_NE2000 ));if (d) {DeviceState *dev =DEVICE (d);
hw/i386/pc.c +1 -1
@@ -1183,7 +1183,7 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, i8042 =isa_create_simple (isa_bus,TYPE_I8042 );if (!no_vmport) {isa_create_simple (isa_bus,TYPE_VMPORT ); - vmmouse =isa_try_new ("vmmouse" ); + vmmouse =ISA_DEVICE (qdev_try_new ("vmmouse" )); }else { vmmouse =NULL ; }
hw/isa/isa-bus.c +0 -5
@@ -158,11 +158,6 @@ ISADevice *isa_new(const char *name)return ISA_DEVICE (qdev_new (name)); } -ISADevice *isa_try_new (const char *name) -{ -return ISA_DEVICE (qdev_try_new (name)); -} -ISADevice *isa_create_simple (ISABus *bus,const char *name) {ISADevice *dev;
Signature · 1 line
2.41.0
PATCH 3/21 hw/ppc/spapr_cpu: Use qdev_is_realized() instead of QOM API
In reply to Philippe Mathieu-DaudéPrefer QDev API for QDev objects, avoid the underlying QOM layer.
--- hw/ppc/spapr_cpu_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/spapr_cpu_core.c +1 -2
@@ -245,8 +245,7 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)* spapr_cpu_core_realize(), make sure we only unrealize * vCPUs that have already been realized. */ -if (object_property_get_bool (OBJECT (sc->threads[i]),"realized" , - &error_abort)) { +if (qdev_is_realized (DEVICE (sc->threads[i]))) {spapr_unrealize_vcpu (sc->threads[i], sc); }spapr_delete_vcpu (sc->threads[i]);
Signature · 1 line
2.41.0
PATCH 18/21 hw/pci-host/versatile: Replace object_initialize() -> _child()
In reply to Philippe Mathieu-DaudéWhen the QOM parent is available, prefer object_initialize_child() over object_initialize(), since it create the parent relationship.
--- 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 (dev),"pci-func0" , + &s->pci_dev,TYPE_VERSATILE_PCI_HOST );for (i =0 ; i <4 ; i++) {sysbus_init_irq (sbd, &s->irq[i]);
Signature · 1 line
2.41.0
Re: [PATCH 04/21] hw/tricore/testboard: Use qdev_new() instead of QOM basic API
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/tricore/tricore_testdevice.h | 3 --- hw/tricore/tricore_testboard.c | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-)
Cheers,
Bastian
Re: [PATCH 19/21] hw/s390x/zpci-bus: Add QOM parentship relation with zPCI devices
In reply to Philippe Mathieu-DaudéQuoted 13 lines · Philippe Mathieu-Daudé
QDev objects created with qdev_*new() need to manually add their parent relationship with
object_property_add_child().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/s390-pci-bus.c | 1 + 1 file changed, 1 insertion(+)hw/s390x/s390-pci-bus.c +0
-0
hw/s390x/s390-pci-bus.c static S390PCIBusDevice *s390_pci_device_new(S390pciState *s, · line 937
Quoted 4 lines
hw/s390x/s390-pci-bus.c +1
-0@@ -934,6 +934,7 @@ static S390PCIBusDevice *s390_pci_device_new(S390pciState *s, "zPCI device could not be created: ");return NULL ; } +object_property_add_child (OBJECT (s),"zpci[*]" ,OBJECT (dev));
I think there can only be one zpci device per PCI device, so do we need the "[*]" here?
Thomas
Quoted 3 lines
hw/s390x/s390-pci-bus.c +0
-0if (!qdev_realize_and_unref (dev,BUS (s->bus), &local_err)) {object_unparent (OBJECT (dev)); error_propagate_prepend(errp, local_err,
Re: [PATCH 19/21] hw/s390x/zpci-bus: Add QOM parentship relation with zPCI devices
Quoted 9 lines · Thomas Huth
Quoted 8 lines · Philippe Mathieu-Daudé
QDev objects created with qdev_*new() need to manually add their parent relationship with
object_property_add_child().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/s390x/s390-pci-bus.c| 1 +1 file changed, 1 insertion(+)
Quoted 12 lines
hw/s390x/s390-pci-bus.c static S390PCIBusDevice · line 938
Quoted 10 lines
hw/s390x/s390-pci-bus.c +1
-0@@ -934,6 +934,7 @@ static S390PCIBusDevice *s390_pci_device_new (S390pciState *s, "zPCI device could not be created: "); return NULL; } + object_property_add_child(OBJECT(s), "zpci[*]", OBJECT(dev));I think there can only be one zpci device per PCI device, so do we need the "[*]" here?
Oh I missed that, I'll change, thanks.
Re: [PATCH 01/21] hw/i386/pc: Do not use C99 mixed-declarations style
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 25 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:02:52 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 01/21] hw/i386/pc: Do not use C99 mixed-declarations style
X-Mailer: git-send-email 2.41.0QEMU's coding style generally forbids C99 mixed declarations.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/i386/pc.c +1
-0@@ -1227,6 +1227,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,*/ if (pcms->hpet_enabled) {qemu_irq rtc_irq; +uint8_t compat; hpet =qdev_try_new (TYPE_HPET );if (!hpet) {
hw/i386/pc.c void pc_basic_device_init(struct PCMachineState *pcms, · line 1245
Quoted 9 lines
hw/i386/pc.c +1
-2@@ -1238,8 +1239,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,* use IRQ16~23, IRQ8 and IRQ2. If the user has already set * the property, use whatever mask they specified. */ -uint8_t compat =object_property_get_uint (OBJECT (hpet), -HPET_INTCAP ,NULL ); + compat =object_property_get_uint (OBJECT (hpet),HPET_INTCAP ,NULL );if (!compat) {qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); }
"compat" is only used here to check. So, what about getting rid of this variable?
if (!object_property_get_uint(OBJECT(hpet), HPET_INTCAP, NULL)) {
qdev_prop_set_uint32(hpet, HPET_INTCAP, hpet_irqs);
}Re: [PATCH 02/21] hw/i386/pc_sysfw: Use qdev_is_realized() instead of QOM API
In reply to Philippe Mathieu-DaudéQuoted 6 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:02:53 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 02/21] hw/i386/pc_sysfw: Useqdev_is_realized()instead of
QOM API
X-Mailer: git-send-email 2.41.0
Quoted 6 lines
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/pc_sysfw.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Quoted 29 lines
hw/i386/pc_sysfw.c +2
-4@@ -107,17 +107,15 @@ void pc_system_flash_cleanup_unused(PCMachineState *pcms) {char *prop_name;int i; -Object *dev_obj;assert (PC_MACHINE_GET_CLASS (pcms)->pci_enabled);for (i =0 ; i <ARRAY_SIZE (pcms->flash); i++) { - dev_obj =OBJECT (pcms->flash[i]); -if (!object_property_get_bool (dev_obj,"realized" , &error_abort)) { +if (!qdev_is_realized (DEVICE (pcms->flash[i]))) { prop_name =g_strdup_printf ("pflash%d" , i);object_property_del (OBJECT (pcms), prop_name);g_free (prop_name); -object_unparent (dev_obj); +object_unparent (OBJECT (pcms->flash[i])); pcms->flash[i] =NULL ; } }Signature · 1 line
2.41.0
Re: [PATCH 17/21] hw/i386/iommu: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 23 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:03:08 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 17/21] hw/i386/iommu: Preferobject_initialize_childover
object_initialize
X-Mailer: git-send-email 2.41.0When the QOM parent is available, prefer
object_initialize_child()overobject_initialize(), since it create the parent relationship.Rename the 'klass' variable as 'obj' since the argument holds a reference to an instance object and not a class one.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/amd_iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/i386/amd_iommu.c +0
-0@@ -1616,11 +1616,11 @@ static const VMStateDescription vmstate_amdvi_sysbus = { .unmigratable = 1
hw/i386/amd_iommu.c static const VMStateDescription vmstate_amdvi_sysbus = { · line 1623
Quoted 10 lines
hw/i386/amd_iommu.c +3
-3}; -static void amdvi_sysbus_instance_init (Object *klass) +static void amdvi_sysbus_instance_init (Object *obj) { -AMDVIState *s =AMD_IOMMU_DEVICE (klass); +AMDVIState *s =AMD_IOMMU_DEVICE (obj); -object_initialize (&s->pci,sizeof (s->pci),TYPE_AMD_IOMMU_PCI ); +object_initialize_child (obj,"iommu" , &s->pci,TYPE_AMD_IOMMU_PCI );
What about this name "amd-iommu"?
This is more accurate and differentiates it from the other intel-iommu related implementations.
Quoted 7 lines
hw/i386/amd_iommu.c +0
-0}static void amdvi_sysbus_class_init (ObjectClass *klass,void *data)Signature · 1 line
2.41.0
Re: [PATCH 11/21] hw/usb: Add QOM parentship relation with hub devices
In reply to Philippe Mathieu-DaudéHi Philippe,
Quoted 18 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:03:02 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 11/21] hw/usb: Add QOM parentship relation with hub devices
X-Mailer: git-send-email 2.41.0QDev objects created with qdev_*new() need to manually add their parent relationship with
object_property_add_child().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/usb/bus.c | 1 + 1 file changed, 1 insertion(+)hw/usb/bus.c +0
-0
hw/usb/bus.c void usb_claim_port(USBDevice *dev, Error **errp) · line 440
Quoted 2 lines
hw/usb/bus.c +0
-0@@ -439,6 +439,7 @@ void usb_claim_port(USBDevice *dev, Error **errp)/* Create a new hub and chain it on */ hub =USB_DEVICE (qdev_try_new ("usb-hub" ));
One additional question comes to mind, should we use the qdev_new() here?
The difference between qdev_try_new() and qdev_new() is the latter uses assert() to ensure the passed type exists.
So if we know that type parameter is correct, we should just use qdev_new().
Only when the caller is not sure whether the type is valid, qdev_try_new() should be preferred.
Am I understand correctly? ;-)
hw/usb/bus.c void usb_claim_port(USBDevice *dev, Error **errp) · line 442
Quoted 2 lines
hw/usb/bus.c +1
-0if (hub) { +object_property_add_child (OBJECT (dev),"hub" ,OBJECT (hub));
From the comment above the code:
/* Create a new hub and chain it on */
this only creates a new usb-hub, should the new usb-hub become the child object of the original usb-hub?
Quoted 7 lines
hw/usb/bus.c +0
-0usb_realize_and_unref (hub, bus,NULL ); } }Signature · 1 line
2.41.0
Re: [PATCH 06/21] hw: Replace DEVICE(object_new) -> qdev_new()
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:02:57 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 06/21] hw: ReplaceDEVICE(object_new)->qdev_new()
X-Mailer: git-send-email 2.41.0
Quoted 8 lines
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/musicpal.c | 2 +- hw/core/qdev.c | 2 +- hw/sparc/sun4m.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
Quoted 53 lines
hw/arm/musicpal.c +1
-1@@ -1238,7 +1238,7 @@ static void musicpal_init(MachineState *machine) qdev_get_gpio_in(pic, MP_TIMER4_IRQ), NULL);/* Logically OR both UART IRQs together */ - uart_orgate =DEVICE (object_new (TYPE_OR_IRQ )); + uart_orgate =qdev_new (TYPE_OR_IRQ );object_property_set_int (OBJECT (uart_orgate),"num-lines" ,2 , &error_fatal);qdev_realize_and_unref (uart_orgate,NULL , &error_fatal); qdev_connect_gpio_out(uart_orgate, 0,hw/core/qdev.c +1
-1@@ -171,7 +171,7 @@ DeviceState *qdev_try_new(const char *name)if (!module_object_class_by_name (name)) {return NULL ; } -return DEVICE (object_new (name)); +return qdev_new (name); } static QTAILQ_HEAD(, DeviceListener) device_listenershw/sparc/sun4m.c +2
-2@@ -979,7 +979,7 @@ static void sun4m_hw_init(MachineState *machine)sysbus_mmio_map (s,0 , hwdef->ms_kb_base);/* Logically OR both its IRQs together */ - ms_kb_orgate =DEVICE (object_new (TYPE_OR_IRQ )); + ms_kb_orgate =qdev_new (TYPE_OR_IRQ );object_property_set_int (OBJECT (ms_kb_orgate),"num-lines" ,2 , &error_fatal);qdev_realize_and_unref (ms_kb_orgate,NULL , &error_fatal);sysbus_connect_irq (s,0 ,qdev_get_gpio_in (ms_kb_orgate,0 ));@@ -1000,7 +1000,7 @@ static void sun4m_hw_init(MachineState *machine)sysbus_mmio_map (s,0 , hwdef->serial_base);/* Logically OR both its IRQs together */ - serial_orgate =DEVICE (object_new (TYPE_OR_IRQ )); + serial_orgate =qdev_new (TYPE_OR_IRQ );object_property_set_int (OBJECT (serial_orgate),"num-lines" ,2 , &error_fatal);qdev_realize_and_unref (serial_orgate,NULL , &error_fatal);Signature · 1 line
2.41.0
Re: [PATCH 09/21] hw/usb: Inline usb_try_new()
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:03:00 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 09/21] hw/usb: Inlineusb_try_new()
X-Mailer: git-send-email 2.41.0Inline the single use of
usb_try_new().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/usb/bus.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
Quoted 30 lines
hw/usb/bus.c +1
-6@@ -334,11 +334,6 @@ USBDevice *usb_new(const char *name)return USB_DEVICE (qdev_new (name)); } -static USBDevice *usb_try_new (const char *name) -{ -return USB_DEVICE (qdev_try_new (name)); -} -bool usb_realize_and_unref (USBDevice *dev,USBBus *bus,Error **errp) {return qdev_realize_and_unref (&dev->qdev, &bus->qbus, errp);@@ -447,7 +442,7 @@ void usb_claim_port(USBDevice *dev, Error **errp) }else {if (bus->nfree ==1 &&strcmp (object_get_typename (OBJECT (dev)),"usb-hub" ) !=0 ) {/* Create a new hub and chain it on */ - hub =usb_try_new ("usb-hub" ); + hub =USB_DEVICE (qdev_try_new ("usb-hub" ));if (hub) {usb_realize_and_unref (hub, bus,NULL ); }Signature · 1 line
2.41.0
Re: [PATCH 07/21] target: Replace DEVICE(object_new) -> qdev_new()
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:02:58 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 07/21] target: ReplaceDEVICE(object_new)->qdev_new()
X-Mailer: git-send-email 2.41.0
Quoted 7 lines
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 31 lines
target/mips/cpu.c +1
-1@@ -649,7 +649,7 @@ MIPSCPU *mips_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk) {DeviceState *cpu; - cpu =DEVICE (object_new (cpu_type)); + cpu =qdev_new (cpu_type);qdev_connect_clock_in (cpu,"clk-in" , cpu_refclk);qdev_realize (cpu,NULL , &error_abort);target/xtensa/cpu.c +1
-1@@ -205,7 +205,7 @@ XtensaCPU *xtensa_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk) {DeviceState *cpu; - cpu =DEVICE (object_new (cpu_type)); + cpu =qdev_new (cpu_type);qdev_connect_clock_in (cpu,"clk-in" , cpu_refclk);qdev_realize (cpu,NULL , &error_abort);Signature · 1 line
2.41.0
Re: [PATCH 10/21] hw/usb: Inline usb_new()
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:03:01 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 10/21] hw/usb: Inlineusb_new()
X-Mailer: git-send-email 2.41.0
Quoted 8 lines
Inline the 2 uses of
usb_new().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/usb.h | 1 - hw/usb/bus.c | 9 ++------- hw/usb/dev-serial.c | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-)
Quoted 64 lines
include/hw/usb.h +0
-1@@ -500,7 +500,6 @@ void usb_bus_release(USBBus *bus);USBBus *usb_bus_find (int busnr);void usb_legacy_register (const char *typename,const char *usbdevice_name,USBDevice *(*usbdevice_init)(void )); -USBDevice *usb_new (const char *name);bool usb_realize_and_unref (USBDevice *dev,USBBus *bus,Error **errp);USBDevice *usb_create_simple (USBBus *bus,const char *name);USBDevice *usbdevice_create (const char *cmdline);hw/usb/bus.c +2
-7@@ -329,11 +329,6 @@ void usb_legacy_register(const char *typename, const char *usbdevice_name, } } -USBDevice *usb_new (const char *name) -{ -return USB_DEVICE (qdev_new (name)); -} -bool usb_realize_and_unref (USBDevice *dev,USBBus *bus,Error **errp) {return qdev_realize_and_unref (&dev->qdev, &bus->qbus, errp);@@ -341,7 +336,7 @@ bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)USBDevice *usb_create_simple (USBBus *bus,const char *name) { -USBDevice *dev =usb_new (name); +USBDevice *dev =USB_DEVICE (qdev_new (name));usb_realize_and_unref (dev, bus, &error_abort);return dev;@@ -693,7 +688,7 @@ USBDevice *usbdevice_create(const char *driver)return NULL ; } - dev = f->usbdevice_init ? f->usbdevice_init () :usb_new (f->name); + dev = f->usbdevice_init ? f->usbdevice_init () :USB_DEVICE (qdev_new (f->name));if (!dev) {error_report ("Failed to create USB device '%s'" , f->name);return NULL ;hw/usb/dev-serial.c +1
-1@@ -624,7 +624,7 @@ static USBDevice *usb_braille_init(void)return NULL ; } - dev =usb_new ("usb-braille" ); + dev =USB_DEVICE (qdev_new ("usb-braille" ));qdev_prop_set_chr (&dev->qdev,"chardev" , cdrv);return dev; }Signature · 1 line
2.41.0
Re: [PATCH 03/21] hw/ppc/spapr_cpu: Use qdev_is_realized() instead of QOM API
In reply to Philippe Mathieu-DaudéQuoted 6 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:02:54 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 03/21] hw/ppc/spapr_cpu: Useqdev_is_realized()instead of
QOM API
X-Mailer: git-send-email 2.41.0
Quoted 6 lines
Prefer QDev API for QDev objects, avoid the underlying QOM layer.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/ppc/spapr_cpu_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 19 lines
hw/ppc/spapr_cpu_core.c +1
-2@@ -245,8 +245,7 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)* spapr_cpu_core_realize(), make sure we only unrealize * vCPUs that have already been realized. */ -if (object_property_get_bool (OBJECT (sc->threads[i]),"realized" , - &error_abort)) { +if (qdev_is_realized (DEVICE (sc->threads[i]))) {spapr_unrealize_vcpu (sc->threads[i], sc); }spapr_delete_vcpu (sc->threads[i]);Signature · 1 line
2.41.0
Re: [PATCH 21/21] hw: Add QOM parentship relation with CPUs
In reply to Philippe Mathieu-DaudéQuoted 9 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:03:12 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 21/21] hw: Add QOM parentship relation with CPUs
X-Mailer: git-send-email 2.41.0QDev objects created with
object_new()need to manually add their parent relationship withobject_property_add_child().Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 9 lines
--- hw/i386/x86.c | 1 + hw/microblaze/petalogix_ml605_mmu.c | 1 + hw/microblaze/petalogix_s3adsp1800_mmu.c | 1 + hw/mips/cps.c | 1 + hw/nios2/10m50_devboard.c | 1 + hw/ppc/e500.c | 1 + hw/ppc/spapr.c | 1 + 7 files changed, 7 insertions(+)
Quoted 89 lines
hw/i386/x86.c +1
-0@@ -102,6 +102,7 @@ void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)if (!object_property_set_uint (cpu,"apic-id" , apic_id, errp)) { goto out; } +object_property_add_child (OBJECT (x86ms),"cpu[*]" ,OBJECT (cpu));qdev_realize (DEVICE (cpu),NULL , errp); out:hw/microblaze/petalogix_ml605_mmu.c +1
-0@@ -83,6 +83,7 @@ petalogix_ml605_init(MachineState *machine)/* init CPUs */ cpu =MICROBLAZE_CPU (object_new (TYPE_MICROBLAZE_CPU )); +object_property_add_child (OBJECT (machine),"cpu" ,OBJECT (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 +1
-0@@ -70,6 +70,7 @@ petalogix_s3adsp1800_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory (); cpu =MICROBLAZE_CPU (object_new (TYPE_MICROBLAZE_CPU )); +object_property_add_child (OBJECT (machine),"cpu" ,OBJECT (cpu));object_property_set_str (OBJECT (cpu),"version" ,"7.10.d" , &error_abort);qdev_realize (DEVICE (cpu),NULL , &error_abort);hw/mips/cps.c +1
-0@@ -84,6 +84,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); +object_property_add_child (OBJECT (dev),"cpu[*]" ,OBJECT (cpu));if (!qdev_realize_and_unref (DEVICE (cpu),NULL , errp)) {return ; }hw/nios2/10m50_devboard.c +1
-0@@ -95,6 +95,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine) cpu->exception_addr =0xc8000120 ; cpu->fast_tlb_miss_addr =0xc0000100 ; +object_property_add_child (OBJECT (machine),"cpu" ,OBJECT (cpu));qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal);if (nms->vic) {hw/ppc/e500.c +1
-0@@ -956,6 +956,7 @@ void ppce500_init(MachineState *machine)*/ object_property_set_bool (OBJECT (cs),"start-powered-off" , i !=0 , &error_abort); +object_property_add_child (OBJECT (machine),"cpu[*]" ,OBJECT (cpu));qdev_realize_and_unref (DEVICE (cs),NULL , &error_fatal);if (!firstenv) {hw/ppc/spapr.c +1
-0@@ -2715,6 +2715,7 @@ static void spapr_init_cpus(SpaprMachineState *spapr) &error_fatal);object_property_set_int (core,CPU_CORE_PROP_CORE_ID , core_id, &error_fatal); +object_property_add_child (OBJECT (spapr),"cpu[*]" ,OBJECT (core));qdev_realize (DEVICE (core),NULL , &error_fatal);object_unref (core);Signature · 1 line
2.41.0
Re: [PATCH 01/21] hw/i386/pc: Do not use C99 mixed-declarations style
In reply to Zhao LiuQuoted 41 lines · Zhao Liu
Hi Philippe,
Quoted 25 lines · Philippe Mathieu-Daudé
Date: Fri, 16 Feb 2024 12:02:52 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 01/21] hw/i386/pc: Do not use C99 mixed-declarations style
X-Mailer: git-send-email 2.41.0QEMU's coding style generally forbids C99 mixed declarations.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/i386/pc.c +1
-0@@ -1227,6 +1227,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,*/ if (pcms->hpet_enabled) {qemu_irq rtc_irq; +uint8_t compat; hpet =qdev_try_new (TYPE_HPET );if (!hpet) {hw/i386/pc.c void pc_basic_device_init(struct PCMachineState *pcms, · line 1245
Quoted 9 lines
hw/i386/pc.c +1
-2@@ -1238,8 +1239,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,* use IRQ16~23, IRQ8 and IRQ2. If the user has already set * the property, use whatever mask they specified. */ -uint8_t compat =object_property_get_uint (OBJECT (hpet), -HPET_INTCAP ,NULL ); + compat =object_property_get_uint (OBJECT (hpet),HPET_INTCAP ,NULL );if (!compat) {qdev_prop_set_uint32 (hpet,HPET_INTCAP , hpet_irqs); }"compat" is only used here to check. So, what about getting rid of this variable?
Quoted 3 lines
if (!object_property_get_uint(OBJECT(hpet), HPET_INTCAP, NULL)) {
qdev_prop_set_uint32(hpet, HPET_INTCAP, hpet_irqs);
}Ah yeah, I didn't noticed, thanks!
Re: [PATCH 16/21] hw/net/can/versal: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
When the QOM parent is available, prefer
object_initialize_child()overobject_initialize(), since it create the parent relationship.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
--- hw/net/can/xlnx-versal-canfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/net/can/xlnx-versal-canfd.c +1
-1@@ -1900,7 +1900,7 @@ static int canfd_populate_regarray(XlnxVersalCANFDState *s,int index = rae[i].addr /4 ;RegisterInfo *r = &s->reg_info[index]; -object_initialize (r,sizeof (*r),TYPE_REGISTER ); +object_initialize_child (OBJECT (s),"reg[*]" , r,TYPE_REGISTER ); *r = (RegisterInfo ) { .data = &s->regs[index],
Pavel Pisa via
Reviewed-by Pavel PisaRe: [PATCH 16/21] hw/net/can/versal: Prefer object_initialize_child over object_initialize
Quoted 7 lines · On Friday 23 of February 2024 12:06:34 Francisco Iglesias wrote:
Quoted 4 lines · Philippe Mathieu-Daudé
When the QOM parent is available, prefer
object_initialize_child()overobject_initialize(), since it create the parent relationship.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Francisco Iglesias <[email protected]>
Quoted 10 lines · Philippe Mathieu-Daudé
Various QDev cleanups extracted to my "enforce QDev API" branch.
- When available, instead of plain QOM, use QDev API equivalent
- Add missing QOM parentship for some obj created with qdev_*new()
- Preferobject_initialize_child()overobject_initialize()Philippe Mathieu-Daudé (21):
hw: Replace
DEVICE(object_new)->qdev_new()
target: ReplaceDEVICE(object_new)->qdev_new()
Quoted 7 lines
hw/usb: Inline
usb_try_new()
hw/usb: Inlineusb_new()hw/net/can/versal: Prefer
object_initialize_childover
object_initializehw: Add QOM parentship relation with CPUs
Queuing reviewed patches.
Re: [PATCH 16/21] hw/net/can/versal: Prefer object_initialize_child over object_initialize
In reply to Philippe Mathieu-DaudéQuoted 14 lines · Philippe Mathieu-Daudé
When the QOM parent is available, prefer
object_initialize_child()overobject_initialize(), since it create the parent relationship.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/can/xlnx-versal-canfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/net/can/xlnx-versal-canfd.c +0
-0
hw/net/can/xlnx-versal-canfd.c static int canfd_populate_regarray(XlnxVersalCANFDState *s,
Quoted 9 lines
hw/net/can/xlnx-versal-canfd.c +1
-2@@ -1900,7 +1900,7 @@ static int canfd_populate_regarray(XlnxVersalCANFDState *s,int index = rae[i].addr /4 ;RegisterInfo *r = &s->reg_info[index]; -object_initialize (r,sizeof (*r),TYPE_REGISTER ); +object_initialize_child (OBJECT (s),"reg[*]" , r,TYPE_REGISTER ); *r = (RegisterInfo ) { .data = &s->regs[index], --
Hi -- I was just looking at this function since ASAN reports a leak in it. I notice that this patch never got applied -- any reason why?
Also, though, we call object_initialize(r, ...) and then we immediately do "*r = { some struct }" which entirely overwrites the initialization we just did. I guess that should instead be initializing the individual fields...
-- PMM