qemu-devel
[Top][All Lists]
Advanced

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

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


From: Daniel P . Berrangé
Subject: Re: [RFC PATCH 1/3] hw/qdev: Introduce QDEV_DECLARE_DEV_BUS_TYPES() macro
Date: Wed, 1 Mar 2023 14:59:54 +0000
User-agent: Mutt/2.2.9 (2022-11-12)

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 :|




reply via email to

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