From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org, Eduardo Habkost <eduardo@habkost.net>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Thomas Huth" <thuth@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [RFC PATCH 1/3] hw/qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro
Date: Mon, 13 Feb 2023 11:56:07 +0100 [thread overview]
Message-ID: <20230213105609.6173-2-philmd@linaro.org> (raw)
In-Reply-To: <20230213105609.6173-1-philmd@linaro.org>
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
next prev parent reply other threads:[~2023-02-13 10:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 10:56 [RFC PATCH 0/3] qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro Philippe Mathieu-Daudé
2023-02-13 10:56 ` Philippe Mathieu-Daudé [this message]
2023-03-01 14:59 ` [RFC PATCH 1/3] hw/qdev: " Daniel P. Berrangé
2023-02-13 10:56 ` [RFC PATCH 2/3] hw/usb: Declare QOM macros using QDEV_DECLARE_DEV_BUS_TYPES() Philippe Mathieu-Daudé
2023-02-13 10:56 ` [RFC PATCH 3/3] hw/usb: Use USB_DEVICE_GET_BUS() macro Philippe Mathieu-Daudé
2023-03-01 14:42 ` [RFC PATCH 0/3] qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro Igor Mammedov
2023-03-01 15:02 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230213105609.6173-2-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=kraxel@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).