[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/9] qdev: Add qdev_create_simple() helper
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 2/9] qdev: Add qdev_create_simple() helper |
Date: |
Mon, 9 Jan 2023 10:26:10 +0100 |
Add a helper to easily create a qdev with no (or default) property.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/core/qdev.c | 9 +++++++++
include/hw/qdev-core.h | 11 +++++++++++
2 files changed, 20 insertions(+)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index d759c4602c..4afed2a24c 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -174,6 +174,15 @@ DeviceState *qdev_try_new(const char *name)
return DEVICE(object_new(name));
}
+DeviceState *qdev_create_simple(const char *name, Error **errp)
+{
+ DeviceState *dev = qdev_new(name);
+
+ qdev_realize_and_unref(dev, NULL, errp);
+
+ return dev;
+}
+
static QTAILQ_HEAD(, DeviceListener) device_listeners
= QTAILQ_HEAD_INITIALIZER(device_listeners);
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 35fddb19a6..ca6b2b8458 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -397,6 +397,17 @@ bool qdev_realize_and_unref(DeviceState *dev, BusState
*bus, Error **errp);
* the life of the simulation and should not be unrealized and freed.
*/
void qdev_unrealize(DeviceState *dev);
+
+/**
+ * Create and realize a device on the heap.
+ * @name: device type to create (we assert() that this type exists)
+ * @errp: pointer to error object
+ *
+ * Create the device state structure, initialize it, and drop the
+ * reference to it (the device is realized).
+ */
+DeviceState *qdev_create_simple(const char *name, Error **errp);
+
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version);
HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev);
--
2.38.1
- [PATCH 0/9] hw: Convert simple devices from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 1/9] hw/arm/musicpal: Remove unused dummy MemoryRegion, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 2/9] qdev: Add qdev_create_simple() helper,
Philippe Mathieu-Daudé <=
- [PATCH 3/9] hw/i2c/bitbang_i2c: Convert TYPE_GPIO_I2C from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 5/9] hw/arm/palm: Convert TYPE_PALM_MISC_GPIO from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 4/9] hw/arm/tosa: Convert TYPE_TOSA_MISC_GPIO from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 6/9] hw/arm/musicpal: Convert TYPE_MUSICPAL_KEY from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 7/9] hw/arm/spitz: Convert TYPE_SPITZ_KEYBOARD from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 8/9] hw/arm/tosa: Convert TYPE_SPITZ_MISC_GPIO from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- [PATCH 9/9] hw/i386/kvm: Convert TYPE_KVM_CLOCK from SysBus to QDev, Philippe Mathieu-Daudé, 2023/01/09
- Re: [PATCH 0/9] hw: Convert simple devices from SysBus to QDev, Peter Maydell, 2023/01/09