From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Eduardo Habkost <eduardo@habkost.net>,
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>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
Thomas Huth <thuth@redhat.com>
Subject: Re: [RFC PATCH 1/3] hw/qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro
Date: Wed, 1 Mar 2023 14:59:54 +0000 [thread overview]
Message-ID: <Y/9oap1KoVAmY8Wr@redhat.com> (raw)
In-Reply-To: <20230213105609.6173-2-philmd@linaro.org>
On Mon, Feb 13, 2023 at 11:56:07AM +0100, Philippe Mathieu-Daudé wrote:
> 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) \
I'm not especially a fan of putting the declaration of two distinct
types behind one macro. This also makes it mismatch with the need
to use distinct OBJECT_DEFINE macros for each of the types.
> + \
> + 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
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2023-03-01 15:00 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 ` [RFC PATCH 1/3] hw/qdev: " Philippe Mathieu-Daudé
2023-03-01 14:59 ` Daniel P. Berrangé [this message]
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=Y/9oap1KoVAmY8Wr@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@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=philmd@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).