Skip to content

Commit 290f950

Browse files
committed
Merge tag 'qom-qdev-20250109' of https://github.com/philmd/qemu into staging
QOM & QDev patches - Remove DeviceState::opts (Akihiko) - Replace container_get by machine/object_get_container (Peter) - Remove InterfaceInfo::concrete_class field (Paolo) - Reduce machine_containers[] scope (Philippe) # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAmeABNgACgkQ4+MsLN6t # wN4XtQ/+NyXEK9vjq+yXnk7LRxTDQBrXxNc71gLqNA8rGwXTuELIXOthNW+UM2a9 # CdnVbrIX/FRfQLXTHx0C2ENteafrR1oXDQmEOz1UeYgaCWJsNdVe3r1MYUdHcwVM # 90JcSbYhrvxFE/p/6WhTjjv2DXn4E8witsPwRc8EBi5bHeFz6cNPzhdF59A3ljZF # 0zr1MLHJHhwR6OoBbm9HM8x8i4Zw4LoKEjo8cCgcBfPQIMKf0HQ4XsinIDwn0VXN # S3jIysNyGHlptHOiJuErILZtzrm4F2lGwYan89jxuElfWjC7SVB2z4CQkQtPceIJ # HRBrE7VPwJ566OAThoSwPG3jXT1yCDOYmNCX1kJOMo9rYh3MwG0VrbMr5iwfYk8Z # wO+8IyMAx7m8FibdsoMmxtI1PYTf0JQaCB6MSwdoAMMQVp1FDWBun2g+swLjQgO4 # 15iSB+PMIZe7Ywd0b63VZrUMHKwMxd9RFYEbbsdA8DRI50W3HMQPZAJiGXt7RxJ9 # p9qxqg0WGpVjgTnInt/KH4axiWPD5cru+THVYk6dvOdtTM5wj2jEswWy2vQ6LkEF # MgxaUXfja8E20AXvdr6uXKwcKOIJ9+TaU5AhUmjpvacjJhy5eQdoFt9OnIMQt25U # KTtapCVsong5JzYZWhITNCMf5w2YGCJGJJekxdrqBvFk+FkMR38= # =+TLu # -----END PGP SIGNATURE----- # gpg: Signature made Thu 09 Jan 2025 12:18:16 EST # gpg: using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <[email protected]>" [full] # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * tag 'qom-qdev-20250109' of https://github.com/philmd/qemu: system: Inline machine_containers[] in qemu_create_machine_containers() qom: remove unused InterfaceInfo::concrete_class field qom: Remove container_get() qom: Use object_get_container() qom: Add object_get_container() qdev: Use machine_get_container() qdev: Add machine_get_container() qdev: Make qdev_get_machine() not use container_get() qdev: Implement qdev_create_fake_machine() for user emulation qdev: Remove opts member hw/pci: Use -1 as the default value for rombar Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents bc6afa1 + 5f39693 commit 290f950

File tree

23 files changed

+126
-85
lines changed

23 files changed

+126
-85
lines changed

accel/tcg/tcg-all.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include "qemu/atomic.h"
3636
#include "qapi/qapi-builtin-visit.h"
3737
#include "qemu/units.h"
38-
#if !defined(CONFIG_USER_ONLY)
38+
#if defined(CONFIG_USER_ONLY)
39+
#include "hw/qdev-core.h"
40+
#else
3941
#include "hw/boards.h"
4042
#endif
4143
#include "internal-common.h"
@@ -124,6 +126,10 @@ static int tcg_init_machine(MachineState *ms)
124126
tcg_prologue_init();
125127
#endif
126128

129+
#ifdef CONFIG_USER_ONLY
130+
qdev_create_fake_machine();
131+
#endif
132+
127133
return 0;
128134
}
129135

backends/cryptodev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int qmp_query_cryptodev_foreach(Object *obj, void *data)
9797
QCryptodevInfoList *qmp_query_cryptodev(Error **errp)
9898
{
9999
QCryptodevInfoList *list = NULL;
100-
Object *objs = container_get(object_get_root(), "/objects");
100+
Object *objs = object_get_container("objects");
101101

102102
object_child_foreach(objs, qmp_query_cryptodev_foreach, &list);
103103

@@ -557,7 +557,7 @@ static void cryptodev_backend_stats_cb(StatsResultList **result,
557557
switch (target) {
558558
case STATS_TARGET_CRYPTODEV:
559559
{
560-
Object *objs = container_get(object_get_root(), "/objects");
560+
Object *objs = object_get_container("objects");
561561
StatsArgs stats_args;
562562
stats_args.result.stats = result;
563563
stats_args.names = names;

chardev/char.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
Object *get_chardevs_root(void)
5050
{
51-
return container_get(object_get_root(), "/chardevs");
51+
return object_get_container("chardevs");
5252
}
5353

5454
static void chr_be_event(Chardev *s, QEMUChrEvent event)

hw/core/gpio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
121121
name ? name : "unnamed-gpio-out", n);
122122
if (input_pin && !OBJECT(input_pin)->parent) {
123123
/* We need a name for object_property_set_link to work */
124-
object_property_add_child(container_get(qdev_get_machine(),
125-
"/unattached"),
124+
object_property_add_child(machine_get_container("unattached"),
126125
"non-qdev-gpio[*]", OBJECT(input_pin));
127126
}
128127
object_property_set_link(OBJECT(dev), propname,

hw/core/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ system_ss.add(files(
4646
'vm-change-state-handler.c',
4747
'clock-vmstate.c',
4848
))
49+
user_ss.add(files('qdev-user.c'))

hw/core/qdev-user.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* QDev helpers specific to user emulation.
3+
*
4+
* Copyright 2025 Linaro, Ltd.
5+
*
6+
* SPDX-License-Identifier: GPL-2.0-or-later
7+
*/
8+
#include "qemu/osdep.h"
9+
#include "qom/object.h"
10+
#include "hw/qdev-core.h"
11+
12+
void qdev_create_fake_machine(void)
13+
{
14+
Object *fake_machine_obj;
15+
16+
fake_machine_obj = object_property_add_new_container(object_get_root(),
17+
"machine");
18+
object_property_add_new_container(fake_machine_obj, "unattached");
19+
}

hw/core/qdev.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
476476
if (!obj->parent) {
477477
gchar *name = g_strdup_printf("device[%d]", unattached_count++);
478478

479-
object_property_add_child(container_get(qdev_get_machine(),
480-
"/unattached"),
479+
object_property_add_child(machine_get_container("unattached"),
481480
name, obj);
482481
unattached_parent = true;
483482
g_free(name);
@@ -691,7 +690,6 @@ static void device_finalize(Object *obj)
691690
dev->canonical_path = NULL;
692691
}
693692

694-
qobject_unref(dev->opts);
695693
g_free(dev->id);
696694
}
697695

@@ -818,12 +816,28 @@ Object *qdev_get_machine(void)
818816
static Object *dev;
819817

820818
if (dev == NULL) {
821-
dev = container_get(object_get_root(), "/machine");
819+
dev = object_resolve_path_component(object_get_root(), "machine");
820+
/*
821+
* Any call to this function before machine is created is treated
822+
* as a programming error as of now.
823+
*/
824+
assert(dev);
822825
}
823826

824827
return dev;
825828
}
826829

830+
Object *machine_get_container(const char *name)
831+
{
832+
Object *container, *machine;
833+
834+
machine = qdev_get_machine();
835+
container = object_resolve_path_component(machine, name);
836+
assert(object_dynamic_cast(container, TYPE_CONTAINER));
837+
838+
return container;
839+
}
840+
827841
char *qdev_get_human_name(DeviceState *dev)
828842
{
829843
g_assert(dev != NULL);

hw/core/sysbus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque)
6565
};
6666

6767
/* Loop through all sysbus devices that were spawned outside the machine */
68-
container = container_get(qdev_get_machine(), "/peripheral");
68+
container = machine_get_container("peripheral");
6969
find_sysbus_device(container, &find);
70-
container = container_get(qdev_get_machine(), "/peripheral-anon");
70+
container = machine_get_container("peripheral-anon");
7171
find_sysbus_device(container, &find);
7272
}
7373

hw/i386/pc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int check_fdc(Object *obj, void *opaque)
463463
}
464464

465465
static const char * const fdc_container_path[] = {
466-
"/unattached", "/peripheral", "/peripheral-anon"
466+
"unattached", "peripheral", "peripheral-anon"
467467
};
468468

469469
/*
@@ -477,7 +477,7 @@ static ISADevice *pc_find_fdc0(void)
477477
CheckFdcState state = { 0 };
478478

479479
for (i = 0; i < ARRAY_SIZE(fdc_container_path); i++) {
480-
container = container_get(qdev_get_machine(), fdc_container_path[i]);
480+
container = machine_get_container(fdc_container_path[i]);
481481
object_child_foreach(container, check_fdc, &state);
482482
}
483483

hw/pci/pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static const Property pci_props[] = {
8585
DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
8686
DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
8787
DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX),
88-
DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1),
88+
DEFINE_PROP_INT32("rombar", PCIDevice, rom_bar, -1),
8989
DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
9090
QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
9191
DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present,

0 commit comments

Comments
 (0)