Skip to content

Commit 213f63d

Browse files
committed
Replace uses of FROM_SSI_SLAVE() macro with QOM casts
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 <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Message-id: [email protected]
1 parent 62a4d34 commit 213f63d

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

hw/arm/z2.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ typedef struct {
111111
int pos;
112112
} ZipitLCD;
113113

114+
#define TYPE_ZIPIT_LCD "zipit-lcd"
115+
#define ZIPIT_LCD(obj) OBJECT_CHECK(ZipitLCD, (obj), TYPE_ZIPIT_LCD)
116+
114117
static uint32_t zipit_lcd_transfer(SSISlave *dev, uint32_t value)
115118
{
116-
ZipitLCD *z = FROM_SSI_SLAVE(ZipitLCD, dev);
119+
ZipitLCD *z = ZIPIT_LCD(dev);
117120
uint16_t val;
118121
if (z->selected) {
119122
z->buf[z->pos] = value & 0xff;
@@ -153,7 +156,7 @@ static void z2_lcd_cs(void *opaque, int line, int level)
153156

154157
static void zipit_lcd_realize(SSISlave *dev, Error **errp)
155158
{
156-
ZipitLCD *z = FROM_SSI_SLAVE(ZipitLCD, dev);
159+
ZipitLCD *z = ZIPIT_LCD(dev);
157160
z->selected = 0;
158161
z->enabled = 0;
159162
z->pos = 0;
@@ -185,7 +188,7 @@ static void zipit_lcd_class_init(ObjectClass *klass, void *data)
185188
}
186189

187190
static const TypeInfo zipit_lcd_info = {
188-
.name = "zipit-lcd",
191+
.name = TYPE_ZIPIT_LCD,
189192
.parent = TYPE_SSI_SLAVE,
190193
.instance_size = sizeof(ZipitLCD),
191194
.class_init = zipit_lcd_class_init,
@@ -325,7 +328,7 @@ static void z2_init(MachineState *machine)
325328

326329
type_register_static(&zipit_lcd_info);
327330
type_register_static(&aer915_info);
328-
z2_lcd = ssi_create_slave(mpu->ssp[1], "zipit-lcd");
331+
z2_lcd = ssi_create_slave(mpu->ssp[1], TYPE_ZIPIT_LCD);
329332
bus = pxa2xx_i2c_bus(mpu->i2c[0]);
330333
i2c_create_slave(bus, TYPE_AER915, 0x55);
331334
wm = i2c_create_slave(bus, TYPE_WM8750, 0x1b);

hw/display/ads7846.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ typedef struct {
2929
int output;
3030
} ADS7846State;
3131

32+
#define TYPE_ADS7846 "ads7846"
33+
#define ADS7846(obj) OBJECT_CHECK(ADS7846State, (obj), TYPE_ADS7846)
34+
3235
/* Control-byte bitfields */
3336
#define CB_PD0 (1 << 0)
3437
#define CB_PD1 (1 << 1)
@@ -61,7 +64,7 @@ static void ads7846_int_update(ADS7846State *s)
6164

6265
static uint32_t ads7846_transfer(SSISlave *dev, uint32_t value)
6366
{
64-
ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, dev);
67+
ADS7846State *s = ADS7846(dev);
6568

6669
switch (s->cycle ++) {
6770
case 0:
@@ -139,7 +142,7 @@ static const VMStateDescription vmstate_ads7846 = {
139142
static void ads7846_realize(SSISlave *d, Error **errp)
140143
{
141144
DeviceState *dev = DEVICE(d);
142-
ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, d);
145+
ADS7846State *s = ADS7846(d);
143146

144147
qdev_init_gpio_out(dev, &s->interrupt, 1);
145148

@@ -166,7 +169,7 @@ static void ads7846_class_init(ObjectClass *klass, void *data)
166169
}
167170

168171
static const TypeInfo ads7846_info = {
169-
.name = "ads7846",
172+
.name = TYPE_ADS7846,
170173
.parent = TYPE_SSI_SLAVE,
171174
.instance_size = sizeof(ADS7846State),
172175
.class_init = ads7846_class_init,

hw/display/ssd0323.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ typedef struct {
6666
uint8_t framebuffer[128 * 80 / 2];
6767
} ssd0323_state;
6868

69+
#define TYPE_SSD0323 "ssd0323"
70+
#define SSD0323(obj) OBJECT_CHECK(ssd0323_state, (obj), TYPE_SSD0323)
71+
72+
6973
static uint32_t ssd0323_transfer(SSISlave *dev, uint32_t data)
7074
{
71-
ssd0323_state *s = FROM_SSI_SLAVE(ssd0323_state, dev);
75+
ssd0323_state *s = SSD0323(dev);
7276

7377
switch (s->mode) {
7478
case SSD0323_DATA:
@@ -346,7 +350,7 @@ static const GraphicHwOps ssd0323_ops = {
346350
static void ssd0323_realize(SSISlave *d, Error **errp)
347351
{
348352
DeviceState *dev = DEVICE(d);
349-
ssd0323_state *s = FROM_SSI_SLAVE(ssd0323_state, d);
353+
ssd0323_state *s = SSD0323(d);
350354

351355
s->col_end = 63;
352356
s->row_end = 79;
@@ -368,7 +372,7 @@ static void ssd0323_class_init(ObjectClass *klass, void *data)
368372
}
369373

370374
static const TypeInfo ssd0323_info = {
371-
.name = "ssd0323",
375+
.name = TYPE_SSD0323,
372376
.parent = TYPE_SSI_SLAVE,
373377
.instance_size = sizeof(ssd0323_state),
374378
.class_init = ssd0323_class_init,

hw/sd/ssi-sd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct {
7474

7575
static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val)
7676
{
77-
ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, dev);
77+
ssi_sd_state *s = SSI_SD(dev);
7878

7979
/* Special case: allow CMD12 (STOP TRANSMISSION) while reading data. */
8080
if (s->mode == SSI_SD_DATA_READ && val == 0x4d) {
@@ -241,7 +241,7 @@ static const VMStateDescription vmstate_ssi_sd = {
241241

242242
static void ssi_sd_realize(SSISlave *d, Error **errp)
243243
{
244-
ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d);
244+
ssi_sd_state *s = SSI_SD(d);
245245
DeviceState *carddev;
246246
DriveInfo *dinfo;
247247
Error *err = NULL;

include/hw/ssi/ssi.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ struct SSISlave {
6666
bool cs;
6767
};
6868

69-
#define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
70-
7169
extern const VMStateDescription vmstate_ssi_slave;
7270

7371
#define VMSTATE_SSI_SLAVE(_field, _state) { \

0 commit comments

Comments
 (0)