Patchwork [18/30] ssi: convert to QEMU Object Model

login
register
mail settings
Submitter Anthony Liguori
Date Jan. 3, 2012, 12:52 a.m.
Message ID <1325551939-24749-19-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/133937/
State New
Headers show

Comments

Anthony Liguori - Jan. 3, 2012, 12:52 a.m.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/ads7846.c   |   17 ++++++++++++-----
 hw/max111x.c   |   34 ++++++++++++++++++++++++----------
 hw/spitz.c     |   39 +++++++++++++++++++++++++++------------
 hw/ssd0323.c   |   17 ++++++++++++-----
 hw/ssi-sd.c    |   17 ++++++++++++-----
 hw/ssi.c       |   23 ++++++++++++-----------
 hw/ssi.h       |   18 +++++++++++++-----
 hw/stellaris.c |   17 ++++++++++++-----
 hw/tosa.c      |   19 +++++++++++++------
 hw/z2.c        |   19 +++++++++++++------
 10 files changed, 150 insertions(+), 70 deletions(-)

Patch

diff --git a/hw/ads7846.c b/hw/ads7846.c
index 9c58a5f..9ea7cab 100644
--- a/hw/ads7846.c
+++ b/hw/ads7846.c
@@ -150,11 +150,18 @@  static int ads7846_init(SSISlave *dev)
     return 0;
 }
 
-static SSISlaveInfo ads7846_info = {
-    .qdev.name ="ads7846",
-    .qdev.size = sizeof(ADS7846State),
-    .init = ads7846_init,
-    .transfer = ads7846_transfer
+static void ads7846_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = ads7846_init;
+    k->transfer = ads7846_transfer;
+}
+
+static DeviceInfo ads7846_info = {
+    .name = "ads7846",
+    .size = sizeof(ADS7846State),
+    .class_init = ads7846_class_init,
 };
 
 static void ads7846_register_devices(void)
diff --git a/hw/max111x.c b/hw/max111x.c
index 70cd1af..305392c 100644
--- a/hw/max111x.c
+++ b/hw/max111x.c
@@ -150,18 +150,32 @@  void max111x_set_input(DeviceState *dev, int line, uint8_t value)
     s->input[line] = value;
 }
 
-static SSISlaveInfo max1110_info = {
-    .qdev.name = "max1110",
-    .qdev.size = sizeof(MAX111xState),
-    .init = max1110_init,
-    .transfer = max111x_transfer
+static void max1110_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = max1110_init;
+    k->transfer = max111x_transfer;
+}
+
+static DeviceInfo max1110_info = {
+    .name = "max1110",
+    .size = sizeof(MAX111xState),
+    .class_init = max1110_class_init,
 };
 
-static SSISlaveInfo max1111_info = {
-    .qdev.name = "max1111",
-    .qdev.size = sizeof(MAX111xState),
-    .init = max1111_init,
-    .transfer = max111x_transfer
+static void max1111_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = max1111_init;
+    k->transfer = max111x_transfer;
+}
+
+static DeviceInfo max1111_info = {
+    .name = "max1111",
+    .size = sizeof(MAX111xState),
+    .class_init = max1111_class_init,
 };
 
 static void max111x_register_devices(void)
diff --git a/hw/spitz.c b/hw/spitz.c
index df0e146..8e3aeda 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -1066,12 +1066,20 @@  static const VMStateDescription vmstate_corgi_ssp_regs = {
     }
 };
 
-static SSISlaveInfo corgi_ssp_info = {
-    .qdev.name = "corgi-ssp",
-    .qdev.size = sizeof(CorgiSSPState),
-    .qdev.vmsd = &vmstate_corgi_ssp_regs,
-    .init = corgi_ssp_init,
-    .transfer = corgi_ssp_transfer
+static void corgi_ssp_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = corgi_ssp_init;
+    k->transfer = corgi_ssp_transfer;
+}
+
+
+static DeviceInfo corgi_ssp_info = {
+    .name = "corgi-ssp",
+    .size = sizeof(CorgiSSPState),
+    .vmsd = &vmstate_corgi_ssp_regs,
+    .class_init = corgi_ssp_class_init,
 };
 
 static const VMStateDescription vmstate_spitz_lcdtg_regs = {
@@ -1086,12 +1094,19 @@  static const VMStateDescription vmstate_spitz_lcdtg_regs = {
     }
 };
 
-static SSISlaveInfo spitz_lcdtg_info = {
-    .qdev.name = "spitz-lcdtg",
-    .qdev.size = sizeof(SpitzLCDTG),
-    .qdev.vmsd = &vmstate_spitz_lcdtg_regs,
-    .init = spitz_lcdtg_init,
-    .transfer = spitz_lcdtg_transfer
+static void spitz_lcdtg_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = spitz_lcdtg_init;
+    k->transfer = spitz_lcdtg_transfer;
+}
+
+static DeviceInfo spitz_lcdtg_info = {
+    .name = "spitz-lcdtg",
+    .size = sizeof(SpitzLCDTG),
+    .vmsd = &vmstate_spitz_lcdtg_regs,
+    .class_init = spitz_lcdtg_class_init,
 };
 
 static void spitz_register_devices(void)
diff --git a/hw/ssd0323.c b/hw/ssd0323.c
index 1eb3823..8e2fac8 100644
--- a/hw/ssd0323.c
+++ b/hw/ssd0323.c
@@ -340,11 +340,18 @@  static int ssd0323_init(SSISlave *dev)
     return 0;
 }
 
-static SSISlaveInfo ssd0323_info = {
-    .qdev.name = "ssd0323",
-    .qdev.size = sizeof(ssd0323_state),
-    .init = ssd0323_init,
-    .transfer = ssd0323_transfer
+static void ssd0323_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = ssd0323_init;
+    k->transfer = ssd0323_transfer;
+}
+
+static DeviceInfo ssd0323_info = {
+    .name = "ssd0323",
+    .size = sizeof(ssd0323_state),
+    .class_init = ssd0323_class_init,
 };
 
 static void ssd03232_register_devices(void)
diff --git a/hw/ssi-sd.c b/hw/ssi-sd.c
index 18dabd6..e559264 100644
--- a/hw/ssi-sd.c
+++ b/hw/ssi-sd.c
@@ -241,11 +241,18 @@  static int ssi_sd_init(SSISlave *dev)
     return 0;
 }
 
-static SSISlaveInfo ssi_sd_info = {
-    .qdev.name = "ssi-sd",
-    .qdev.size = sizeof(ssi_sd_state),
-    .init = ssi_sd_init,
-    .transfer = ssi_sd_transfer
+static void ssi_sd_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = ssi_sd_init;
+    k->transfer = ssi_sd_transfer;
+}
+
+static DeviceInfo ssi_sd_info = {
+    .name = "ssi-sd",
+    .size = sizeof(ssi_sd_state),
+    .class_init = ssi_sd_class_init,
 };
 
 static void ssi_sd_register_devices(void)
diff --git a/hw/ssi.c b/hw/ssi.c
index 9842fe7..3c7867d 100644
--- a/hw/ssi.c
+++ b/hw/ssi.c
@@ -20,8 +20,8 @@  static struct BusInfo ssi_bus_info = {
 
 static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
 {
-    SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
-    SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
+    SSISlave *s = SSI_SLAVE(dev);
+    SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s);
     SSIBus *bus;
 
     bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
@@ -30,16 +30,15 @@  static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
         hw_error("Too many devices on SSI bus");
     }
 
-    s->info = info;
-    return info->init(s);
+    return ssc->init(s);
 }
 
-void ssi_register_slave(SSISlaveInfo *info)
+void ssi_register_slave(DeviceInfo *info)
 {
-    assert(info->qdev.size >= sizeof(SSISlave));
-    info->qdev.init = ssi_slave_init;
-    info->qdev.bus_info = &ssi_bus_info;
-    qdev_register(&info->qdev);
+    assert(info->size >= sizeof(SSISlave));
+    info->init = ssi_slave_init;
+    info->bus_info = &ssi_bus_info;
+    qdev_register(info);
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
@@ -61,10 +60,12 @@  uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
 {
     DeviceState *dev;
     SSISlave *slave;
+    SSISlaveClass *ssc;
     dev = QTAILQ_FIRST(&bus->qbus.children);
     if (!dev) {
         return 0;
     }
-    slave = SSI_SLAVE_FROM_QDEV(dev);
-    return slave->info->transfer(slave, val);
+    slave = SSI_SLAVE(dev);
+    ssc = SSI_SLAVE_GET_CLASS(slave);
+    return ssc->transfer(slave, val);
 }
diff --git a/hw/ssi.h b/hw/ssi.h
index 24610a8..97aefa7 100644
--- a/hw/ssi.h
+++ b/hw/ssi.h
@@ -15,22 +15,30 @@ 
 
 typedef struct SSISlave SSISlave;
 
+#define TYPE_SSI_SLAVE "ssi-slave"
+#define SSI_SLAVE(obj) \
+     OBJECT_CHECK(SSISlave, (obj), TYPE_SSI_SLAVE)
+#define SSI_SLAVE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(SSISlaveClass, (klass), TYPE_SSI_SLAVE)
+#define SSI_SLAVE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(SSISlaveClass, (obj), TYPE_SSI_SLAVE)
+
 /* Slave devices.  */
-typedef struct {
-    DeviceInfo qdev;
+typedef struct SSISlaveClass {
+    DeviceClass parent_class;
+
     int (*init)(SSISlave *dev);
     uint32_t (*transfer)(SSISlave *dev, uint32_t val);
-} SSISlaveInfo;
+} SSISlaveClass;
 
 struct SSISlave {
     DeviceState qdev;
-    SSISlaveInfo *info;
 };
 
 #define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
-void ssi_register_slave(SSISlaveInfo *info);
+void ssi_register_slave(DeviceInfo *info);
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name);
 
diff --git a/hw/stellaris.c b/hw/stellaris.c
index 7a73074..a1620cb 100644
--- a/hw/stellaris.c
+++ b/hw/stellaris.c
@@ -1394,11 +1394,18 @@  static void stellaris_machine_init(void)
 
 machine_init(stellaris_machine_init);
 
-static SSISlaveInfo stellaris_ssi_bus_info = {
-    .qdev.name = "evb6965-ssi",
-    .qdev.size = sizeof(stellaris_ssi_bus_state),
-    .init = stellaris_ssi_bus_init,
-    .transfer = stellaris_ssi_bus_transfer
+static void stellaris_ssi_bus_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = stellaris_ssi_bus_init;
+    k->transfer = stellaris_ssi_bus_transfer;
+}
+
+static DeviceInfo stellaris_ssi_bus_info = {
+    .name = "evb6965-ssi",
+    .size = sizeof(stellaris_ssi_bus_state),
+    .class_init = stellaris_ssi_bus_class_init,
 };
 
 static void stellaris_register_devices(void)
diff --git a/hw/tosa.c b/hw/tosa.c
index 67a71fe..0977cc9 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -262,13 +262,20 @@  static I2CSlaveInfo tosa_dac_info = {
     .event = tosa_dac_event,
     .recv = tosa_dac_recv,
     .send = tosa_dac_send
-};
+ };
+
+static void tosa_ssp_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = tosa_ssp_init;
+    k->transfer = tosa_ssp_tansfer;
+}
 
-static SSISlaveInfo tosa_ssp_info = {
-    .qdev.name = "tosa-ssp",
-    .qdev.size = sizeof(SSISlave),
-    .init = tosa_ssp_init,
-    .transfer = tosa_ssp_tansfer
+static DeviceInfo tosa_ssp_info = {
+    .name = "tosa-ssp",
+    .size = sizeof(SSISlave),
+    .class_init = tosa_ssp_class_init,
 };
 
 static void tosa_register_devices(void)
diff --git a/hw/z2.c b/hw/z2.c
index a03bb33..96a8587 100644
--- a/hw/z2.c
+++ b/hw/z2.c
@@ -171,12 +171,19 @@  static VMStateDescription vmstate_zipit_lcd_state = {
     }
 };
 
-static SSISlaveInfo zipit_lcd_info = {
-    .qdev.name = "zipit-lcd",
-    .qdev.size = sizeof(ZipitLCD),
-    .qdev.vmsd = &vmstate_zipit_lcd_state,
-    .init = zipit_lcd_init,
-    .transfer = zipit_lcd_transfer
+static void zipit_lcd_class_init(ObjectClass *klass, void *data)
+{
+    SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+    k->init = zipit_lcd_init;
+    k->transfer = zipit_lcd_transfer;
+}
+
+static DeviceInfo zipit_lcd_info = {
+    .name = "zipit-lcd",
+    .size = sizeof(ZipitLCD),
+    .vmsd = &vmstate_zipit_lcd_state,
+    .class_init = zipit_lcd_class_init,
 };
 
 typedef struct {