From: Alistair Francis <alistair23@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm <qemu-arm@nongnu.org>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
"Alistair Francis" <alistair@alistair23.me>
Subject: Re: [PATCH 17/17] Replace uses of FROM_SSI_SLAVE() macro with QOM casts
Date: Thu, 2 Jul 2020 11:23:29 -0700 [thread overview]
Message-ID: <CAKmqyKMSSYZCLT95xur5V3eyz25oX_hMFynifzQrurqTPMUniQ@mail.gmail.com> (raw)
In-Reply-To: <20200628142429.17111-18-peter.maydell@linaro.org>
On Sun, Jun 28, 2020 at 7:37 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> The FROM_SSI_SLAVE() macro predates QOM and is used as a typesafe way
> to cast from an SSISlave* to the instance struct of a subtype of
> TYPE_SSI_SLAVE. Switch to using the QOM cast macros instead, which
> have the same effect (by writing the QOM macros if the types were
> previously missing them.)
>
> (The FROM_SSI_SLAVE() macro allows the SSISlave member of the
> subtype's struct to be anywhere as long as it is named "ssidev",
> whereas a QOM cast macro insists that it is the first thing in the
> subtype's struct. This is true for all the types we convert here.)
>
> This removes all the uses of FROM_SSI_SLAVE() so we can delete the
> definition.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> include/hw/ssi/ssi.h | 2 --
> hw/arm/z2.c | 11 +++++++----
> hw/display/ads7846.c | 9 ++++++---
> hw/display/ssd0323.c | 10 +++++++---
> hw/sd/ssi-sd.c | 4 ++--
> 5 files changed, 22 insertions(+), 14 deletions(-)
>
> diff --git a/include/hw/ssi/ssi.h b/include/hw/ssi/ssi.h
> index 5fd411f2e4e..eac168aa1db 100644
> --- a/include/hw/ssi/ssi.h
> +++ b/include/hw/ssi/ssi.h
> @@ -66,8 +66,6 @@ struct SSISlave {
> bool cs;
> };
>
> -#define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
> -
> extern const VMStateDescription vmstate_ssi_slave;
>
> #define VMSTATE_SSI_SLAVE(_field, _state) { \
> diff --git a/hw/arm/z2.c b/hw/arm/z2.c
> index a0f40959904..e1f22f58681 100644
> --- a/hw/arm/z2.c
> +++ b/hw/arm/z2.c
> @@ -111,9 +111,12 @@ typedef struct {
> int pos;
> } ZipitLCD;
>
> +#define TYPE_ZIPIT_LCD "zipit-lcd"
> +#define ZIPIT_LCD(obj) OBJECT_CHECK(ZipitLCD, (obj), TYPE_ZIPIT_LCD)
> +
> static uint32_t zipit_lcd_transfer(SSISlave *dev, uint32_t value)
> {
> - ZipitLCD *z = FROM_SSI_SLAVE(ZipitLCD, dev);
> + ZipitLCD *z = ZIPIT_LCD(dev);
> uint16_t val;
> if (z->selected) {
> z->buf[z->pos] = value & 0xff;
> @@ -153,7 +156,7 @@ static void z2_lcd_cs(void *opaque, int line, int level)
>
> static void zipit_lcd_realize(SSISlave *dev, Error **errp)
> {
> - ZipitLCD *z = FROM_SSI_SLAVE(ZipitLCD, dev);
> + ZipitLCD *z = ZIPIT_LCD(dev);
> z->selected = 0;
> z->enabled = 0;
> z->pos = 0;
> @@ -185,7 +188,7 @@ static void zipit_lcd_class_init(ObjectClass *klass, void *data)
> }
>
> static const TypeInfo zipit_lcd_info = {
> - .name = "zipit-lcd",
> + .name = TYPE_ZIPIT_LCD,
> .parent = TYPE_SSI_SLAVE,
> .instance_size = sizeof(ZipitLCD),
> .class_init = zipit_lcd_class_init,
> @@ -325,7 +328,7 @@ static void z2_init(MachineState *machine)
>
> type_register_static(&zipit_lcd_info);
> type_register_static(&aer915_info);
> - z2_lcd = ssi_create_slave(mpu->ssp[1], "zipit-lcd");
> + z2_lcd = ssi_create_slave(mpu->ssp[1], TYPE_ZIPIT_LCD);
> bus = pxa2xx_i2c_bus(mpu->i2c[0]);
> i2c_create_slave(bus, TYPE_AER915, 0x55);
> wm = i2c_create_slave(bus, TYPE_WM8750, 0x1b);
> diff --git a/hw/display/ads7846.c b/hw/display/ads7846.c
> index 9228b40b1af..56bf82fe079 100644
> --- a/hw/display/ads7846.c
> +++ b/hw/display/ads7846.c
> @@ -29,6 +29,9 @@ typedef struct {
> int output;
> } ADS7846State;
>
> +#define TYPE_ADS7846 "ads7846"
> +#define ADS7846(obj) OBJECT_CHECK(ADS7846State, (obj), TYPE_ADS7846)
> +
> /* Control-byte bitfields */
> #define CB_PD0 (1 << 0)
> #define CB_PD1 (1 << 1)
> @@ -61,7 +64,7 @@ static void ads7846_int_update(ADS7846State *s)
>
> static uint32_t ads7846_transfer(SSISlave *dev, uint32_t value)
> {
> - ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, dev);
> + ADS7846State *s = ADS7846(dev);
>
> switch (s->cycle ++) {
> case 0:
> @@ -139,7 +142,7 @@ static const VMStateDescription vmstate_ads7846 = {
> static void ads7846_realize(SSISlave *d, Error **errp)
> {
> DeviceState *dev = DEVICE(d);
> - ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, d);
> + ADS7846State *s = ADS7846(d);
>
> qdev_init_gpio_out(dev, &s->interrupt, 1);
>
> @@ -166,7 +169,7 @@ static void ads7846_class_init(ObjectClass *klass, void *data)
> }
>
> static const TypeInfo ads7846_info = {
> - .name = "ads7846",
> + .name = TYPE_ADS7846,
> .parent = TYPE_SSI_SLAVE,
> .instance_size = sizeof(ADS7846State),
> .class_init = ads7846_class_init,
> diff --git a/hw/display/ssd0323.c b/hw/display/ssd0323.c
> index c3bdb18742c..32d27f008ae 100644
> --- a/hw/display/ssd0323.c
> +++ b/hw/display/ssd0323.c
> @@ -66,9 +66,13 @@ typedef struct {
> uint8_t framebuffer[128 * 80 / 2];
> } ssd0323_state;
>
> +#define TYPE_SSD0323 "ssd0323"
> +#define SSD0323(obj) OBJECT_CHECK(ssd0323_state, (obj), TYPE_SSD0323)
> +
> +
> static uint32_t ssd0323_transfer(SSISlave *dev, uint32_t data)
> {
> - ssd0323_state *s = FROM_SSI_SLAVE(ssd0323_state, dev);
> + ssd0323_state *s = SSD0323(dev);
>
> switch (s->mode) {
> case SSD0323_DATA:
> @@ -346,7 +350,7 @@ static const GraphicHwOps ssd0323_ops = {
> static void ssd0323_realize(SSISlave *d, Error **errp)
> {
> DeviceState *dev = DEVICE(d);
> - ssd0323_state *s = FROM_SSI_SLAVE(ssd0323_state, d);
> + ssd0323_state *s = SSD0323(d);
>
> s->col_end = 63;
> s->row_end = 79;
> @@ -368,7 +372,7 @@ static void ssd0323_class_init(ObjectClass *klass, void *data)
> }
>
> static const TypeInfo ssd0323_info = {
> - .name = "ssd0323",
> + .name = TYPE_SSD0323,
> .parent = TYPE_SSI_SLAVE,
> .instance_size = sizeof(ssd0323_state),
> .class_init = ssd0323_class_init,
> diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
> index 25cec2ddeaa..25cdf4c966d 100644
> --- a/hw/sd/ssi-sd.c
> +++ b/hw/sd/ssi-sd.c
> @@ -74,7 +74,7 @@ typedef struct {
>
> static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
> {
> - ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, dev);
> + ssi_sd_state *s = SSI_SD(dev);
>
> /* Special case: allow CMD12 (STOP TRANSMISSION) while reading data. */
> if (s->mode == SSI_SD_DATA_READ && val == 0x4d) {
> @@ -241,7 +241,7 @@ static const VMStateDescription vmstate_ssi_sd = {
>
> static void ssi_sd_realize(SSISlave *d, Error **errp)
> {
> - ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d);
> + ssi_sd_state *s = SSI_SD(d);
> DeviceState *carddev;
> DriveInfo *dinfo;
> Error *err = NULL;
> --
> 2.20.1
>
>
next prev parent reply other threads:[~2020-07-02 18:34 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-28 14:24 [PATCH 00/17] spitz: fix hacks, fix CID 1421913, various cleanups Peter Maydell
2020-06-28 14:24 ` [PATCH 01/17] hw/arm/spitz: Detabify Peter Maydell
2020-06-29 8:49 ` Philippe Mathieu-Daudé
2020-06-29 19:30 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 02/17] hw/arm/spitz: Create SpitzMachineClass abstract base class Peter Maydell
2020-06-29 8:55 ` Philippe Mathieu-Daudé
2020-06-29 14:03 ` Peter Maydell
2020-06-28 14:24 ` [PATCH 03/17] hw/arm/spitz: Keep pointers to MPU and SSI devices in SpitzMachineState Peter Maydell
2020-06-29 19:36 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 04/17] hw/arm/spitz: Keep pointers to scp0, scp1 " Peter Maydell
2020-06-29 19:38 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 05/17] hw/arm/spitz: Implement inbound GPIO lines for bit5 and power signals Peter Maydell
2020-06-30 20:45 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 06/17] hw/misc/max111x: provide QOM properties for setting initial values Peter Maydell
2020-06-29 9:01 ` Philippe Mathieu-Daudé
2020-06-30 20:51 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 07/17] hw/misc/max111x: Don't use vmstate_register() Peter Maydell
2020-06-29 9:01 ` Philippe Mathieu-Daudé
2020-06-30 20:52 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 08/17] ssi: Add ssi_realize_and_unref() Peter Maydell
2020-06-29 9:02 ` Philippe Mathieu-Daudé
2020-06-30 20:55 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 09/17] hw/arm/spitz: Use max111x properties to set initial values Peter Maydell
2020-06-29 9:09 ` Philippe Mathieu-Daudé
2020-06-29 14:05 ` Peter Maydell
2020-06-28 14:24 ` [PATCH 10/17] hw/misc/max111x: Use GPIO lines rather than max111x_set_input() Peter Maydell
2020-07-01 0:37 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 11/17] hw/misc/max111x: Create header file for documentation, TYPE_ macros Peter Maydell
2020-06-29 8:29 ` Philippe Mathieu-Daudé
2020-06-29 12:07 ` Peter Maydell
2020-06-29 14:57 ` Philippe Mathieu-Daudé
2020-06-28 14:24 ` [PATCH 12/17] hw/arm/spitz: Encapsulate misc GPIO handling in a device Peter Maydell
2020-06-29 9:12 ` Philippe Mathieu-Daudé
2020-07-02 17:39 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 13/17] hw/gpio/zaurus.c: Use LOG_GUEST_ERROR for bad guest register accesses Peter Maydell
2020-06-29 9:13 ` Philippe Mathieu-Daudé
2020-07-01 0:38 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 14/17] hw/arm/spitz: " Peter Maydell
2020-06-29 9:14 ` Philippe Mathieu-Daudé
2020-07-01 0:52 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 15/17] hw/arm/pxa2xx_pic: " Peter Maydell
2020-06-29 9:14 ` Philippe Mathieu-Daudé
2020-07-01 0:52 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 16/17] hw/arm/spitz: Provide usual QOM macros for corgi-ssp and spitz-lcdtg Peter Maydell
2020-06-29 9:17 ` Philippe Mathieu-Daudé
2020-07-02 17:51 ` Alistair Francis
2020-06-28 14:24 ` [PATCH 17/17] Replace uses of FROM_SSI_SLAVE() macro with QOM casts Peter Maydell
2020-06-29 9:18 ` Philippe Mathieu-Daudé
2020-07-02 18:23 ` Alistair Francis [this message]
2020-06-28 14:43 ` [PATCH 00/17] spitz: fix hacks, fix CID 1421913, various cleanups no-reply
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=CAKmqyKMSSYZCLT95xur5V3eyz25oX_hMFynifzQrurqTPMUniQ@mail.gmail.com \
--to=alistair23@gmail.com \
--cc=alistair@alistair23.me \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).