qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 1/3] hw/qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro


From: Philippe Mathieu-Daudé
Subject: [RFC PATCH 1/3] hw/qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro
Date: Mon, 13 Feb 2023 11:56:07 +0100

Similarly to QOM OBJECT_DECLARE_TYPE() equivalent, introduce
a QDev macro to declare common helpers for device sitting on
a bus.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/qdev-core.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 93718be156..dc9909a2e7 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -717,6 +717,34 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState 
*container,
 
 BusState *qdev_get_parent_bus(const DeviceState *dev);
 
+/**
+ * QDEV_DECLARE_DEV_BUS_TYPES:
+ * @DeviceInstanceType: device instance struct name
+ * @DeviceClassType: device class struct name
+ * @DEVICE_OBJ_NAME: the device name in uppercase with underscore separators
+ * @BusInstanceType: bus instance struct name
+ * @DeviceClassType: bus class struct name
+ * @BUS_OBJ_NAME: the bus name in uppercase with underscore separators
+ *
+ * This macro is typically used in a header file, and will:
+ *
+ *   - create the typedefs for the object and class structs
+ *   - register the type for use with g_autoptr
+ *   - provide four standard type cast functions
+ *
+ * The device state struct, device class struct, bus state struct need
+ * to be declared manually.
+ */
+#define QDEV_DECLARE_DEV_BUS_TYPES(DeviceInstanceType, DeviceClassType, \
+                                                       DEVICE_OBJ_NAME, \
+                                   BusInstanceType, BUS_OBJ_NAME) \
+    OBJECT_DECLARE_TYPE(DeviceInstanceType, DeviceClassType, DEVICE_OBJ_NAME) \
+    OBJECT_DECLARE_SIMPLE_TYPE(BusInstanceType, BUS_OBJ_NAME) \
+    \
+    static inline G_GNUC_UNUSED BusInstanceType * \
+    DEVICE_OBJ_NAME##_GET_BUS(const DeviceInstanceType *dev) \
+    { return BUS_OBJ_NAME(qdev_get_parent_bus(DEVICE(dev))); }
+
 /*** BUS API. ***/
 
 DeviceState *qdev_find_recursive(BusState *bus, const char *id);
-- 
2.38.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]