* [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit()
@ 2018-01-22 12:03 Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 1/7] hw/i2c/smbus: use DeviceClass::realize instead of SMBusDeviceClass::init Philippe Mathieu-Daudé
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth
since v1:
- fix format string on 32-bit host (patchew)
- do not add smbus_eeprom_reset() (Eduardo)
- directly use DeviceClass::realize (Eduardo)
- squashed 2 patches (Eduardo)
Hi,
This series finalize the qdev QOMification.
We first convert the I2CSlave/SMBusDevice,
then the usb-ccid and virtio-ccw,
and finally the SysBusDevice.
At the end we get one less TODO :)
/* TODO remove, once users are converted to unrealize */
There is still one standing in SysBusDeviceClass::init().
Regards,
Phil.
Philippe Mathieu-Daudé (7):
hw/i2c/smbus: use DeviceClass::realize instead of SMBusDeviceClass::init
hw/i2c: use DeviceClass::realize instead of I2CSlaveClass::init
usb-ccid: convert CCIDCardClass::init -> realize
virtio-ccw: convert VirtIOCCWDeviceClass::exit -> unrealize
qdev: simplify the SysBusDeviceClass::init path
qdev: remove DeviceClass::exit
qdev: rename typedef qdev_resetfn() -> DeviceReset()
include/hw/i2c/i2c.h | 3 ---
include/hw/i2c/smbus.h | 1 -
include/hw/qdev-core.h | 8 ++----
hw/s390x/virtio-ccw.h | 2 +-
hw/usb/ccid.h | 9 +++++--
hw/audio/wm8750.c | 8 +++---
hw/core/qdev.c | 28 ---------------------
hw/core/sysbus.c | 15 ++++++++----
hw/display/ssd0303.c | 9 +++----
hw/gpio/max7310.c | 9 +++----
hw/i2c/core.c | 13 ----------
hw/i2c/smbus.c | 9 -------
hw/i2c/smbus_eeprom.c | 5 ++--
hw/input/lm832x.c | 9 +++----
hw/misc/tmp105.c | 7 +++---
hw/misc/tmp421.c | 8 +++---
hw/nvram/eeprom_at24c.c | 24 +++++++++---------
hw/s390x/virtio-ccw.c | 35 +++++++++++++-------------
hw/timer/twl92230.c | 11 +++------
hw/usb/ccid-card-emulated.c | 45 ++++++++++++++++++----------------
hw/usb/ccid-card-passthru.c | 10 ++++----
hw/usb/dev-smartcard-reader.c | 57 +++++++++++++++----------------------------
22 files changed, 124 insertions(+), 201 deletions(-)
--
2.15.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 1/7] hw/i2c/smbus: use DeviceClass::realize instead of SMBusDeviceClass::init
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 2/7] hw/i2c: use DeviceClass::realize instead of I2CSlaveClass::init Philippe Mathieu-Daudé
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth
and remove SMBusDeviceClass::init, there are no more users.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/i2c/smbus.h | 1 -
hw/i2c/smbus.c | 9 ---------
hw/i2c/smbus_eeprom.c | 5 ++---
3 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h
index 544bbc1957..cfe3fa69f3 100644
--- a/include/hw/i2c/smbus.h
+++ b/include/hw/i2c/smbus.h
@@ -38,7 +38,6 @@
typedef struct SMBusDeviceClass
{
I2CSlaveClass parent_class;
- int (*init)(SMBusDevice *dev);
void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
void (*send_byte)(SMBusDevice *dev, uint8_t val);
uint8_t (*receive_byte)(SMBusDevice *dev);
diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 2d1b79a689..587ce1ab7f 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -202,14 +202,6 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data)
return 0;
}
-static int smbus_device_init(I2CSlave *i2c)
-{
- SMBusDevice *dev = SMBUS_DEVICE(i2c);
- SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
-
- return sc->init(dev);
-}
-
/* Master device commands. */
int smbus_quick_command(I2CBus *bus, uint8_t addr, int read)
{
@@ -350,7 +342,6 @@ static void smbus_device_class_init(ObjectClass *klass, void *data)
{
I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
- sc->init = smbus_device_init;
sc->event = smbus_i2c_event;
sc->recv = smbus_i2c_recv;
sc->send = smbus_i2c_send;
diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c
index b13ec0fe7a..125c887d1f 100644
--- a/hw/i2c/smbus_eeprom.c
+++ b/hw/i2c/smbus_eeprom.c
@@ -97,12 +97,11 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n)
return eeprom_receive_byte(dev);
}
-static int smbus_eeprom_initfn(SMBusDevice *dev)
+static void smbus_eeprom_realize(DeviceState *dev, Error **errp)
{
SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
eeprom->offset = 0;
- return 0;
}
static Property smbus_eeprom_properties[] = {
@@ -115,7 +114,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass);
- sc->init = smbus_eeprom_initfn;
+ dc->realize = smbus_eeprom_realize;
sc->quick_cmd = eeprom_quick_cmd;
sc->send_byte = eeprom_send_byte;
sc->receive_byte = eeprom_receive_byte;
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 2/7] hw/i2c: use DeviceClass::realize instead of I2CSlaveClass::init
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 1/7] hw/i2c/smbus: use DeviceClass::realize instead of SMBusDeviceClass::init Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize Philippe Mathieu-Daudé
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth,
Gerd Hoffmann
and remove I2CSlaveClass::init, there are no more users.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/i2c/i2c.h | 3 ---
hw/audio/wm8750.c | 8 +++-----
hw/display/ssd0303.c | 9 ++++-----
hw/gpio/max7310.c | 9 ++++-----
hw/i2c/core.c | 13 -------------
hw/input/lm832x.c | 9 ++++-----
hw/misc/tmp105.c | 7 +++----
hw/misc/tmp421.c | 8 +++-----
hw/nvram/eeprom_at24c.c | 24 +++++++++++-------------
hw/timer/twl92230.c | 11 ++++-------
10 files changed, 36 insertions(+), 65 deletions(-)
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index 2ce611d4c8..605cf84e96 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -29,9 +29,6 @@ typedef struct I2CSlaveClass
{
DeviceClass parent_class;
- /* Callbacks provided by the device. */
- int (*init)(I2CSlave *dev);
-
/* Master to slave. Returns non-zero for a NAK, 0 for success. */
int (*send)(I2CSlave *s, uint8_t data);
diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c
index 8bb44a7cc1..1bbae592cb 100644
--- a/hw/audio/wm8750.c
+++ b/hw/audio/wm8750.c
@@ -618,14 +618,12 @@ static const VMStateDescription vmstate_wm8750 = {
}
};
-static int wm8750_init(I2CSlave *i2c)
+static void wm8750_realize(DeviceState *dev, Error **errp)
{
- WM8750State *s = WM8750(i2c);
+ WM8750State *s = WM8750(dev);
AUD_register_card(CODEC, &s->card);
wm8750_reset(I2C_SLAVE(s));
-
- return 0;
}
#if 0
@@ -709,7 +707,7 @@ static void wm8750_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
- sc->init = wm8750_init;
+ dc->realize = wm8750_realize;
sc->event = wm8750_event;
sc->recv = wm8750_rx;
sc->send = wm8750_tx;
diff --git a/hw/display/ssd0303.c b/hw/display/ssd0303.c
index 68a80b9d64..eb90ba26be 100644
--- a/hw/display/ssd0303.c
+++ b/hw/display/ssd0303.c
@@ -297,13 +297,12 @@ static const GraphicHwOps ssd0303_ops = {
.gfx_update = ssd0303_update_display,
};
-static int ssd0303_init(I2CSlave *i2c)
+static void ssd0303_realize(DeviceState *dev, Error **errp)
{
- ssd0303_state *s = SSD0303(i2c);
+ ssd0303_state *s = SSD0303(dev);
- s->con = graphic_console_init(DEVICE(i2c), 0, &ssd0303_ops, s);
+ s->con = graphic_console_init(dev, 0, &ssd0303_ops, s);
qemu_console_resize(s->con, 96 * MAGNIFY, 16 * MAGNIFY);
- return 0;
}
static void ssd0303_class_init(ObjectClass *klass, void *data)
@@ -311,7 +310,7 @@ static void ssd0303_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
- k->init = ssd0303_init;
+ dc->realize = ssd0303_realize;
k->event = ssd0303_event;
k->recv = ssd0303_recv;
k->send = ssd0303_send;
diff --git a/hw/gpio/max7310.c b/hw/gpio/max7310.c
index f82e3e6555..8ace416c8f 100644
--- a/hw/gpio/max7310.c
+++ b/hw/gpio/max7310.c
@@ -182,14 +182,13 @@ static void max7310_gpio_set(void *opaque, int line, int level)
/* MAX7310 is SMBus-compatible (can be used with only SMBus protocols),
* but also accepts sequences that are not SMBus so return an I2C device. */
-static int max7310_init(I2CSlave *i2c)
+static void max7310_realize(DeviceState *dev, Error **errp)
{
- MAX7310State *s = MAX7310(i2c);
+ I2CSlave *i2c = I2C_SLAVE(dev);
+ MAX7310State *s = MAX7310(dev);
qdev_init_gpio_in(&i2c->qdev, max7310_gpio_set, 8);
qdev_init_gpio_out(&i2c->qdev, s->handler, 8);
-
- return 0;
}
static void max7310_class_init(ObjectClass *klass, void *data)
@@ -197,7 +196,7 @@ static void max7310_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
- k->init = max7310_init;
+ dc->realize = max7310_realize;
k->event = max7310_event;
k->recv = max7310_rx;
k->send = max7310_tx;
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 59068f157e..a9802cb5a8 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -276,18 +276,6 @@ const VMStateDescription vmstate_i2c_slave = {
}
};
-static int i2c_slave_qdev_init(DeviceState *dev)
-{
- I2CSlave *s = I2C_SLAVE(dev);
- I2CSlaveClass *sc = I2C_SLAVE_GET_CLASS(s);
-
- if (sc->init) {
- return sc->init(s);
- }
-
- return 0;
-}
-
DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr)
{
DeviceState *dev;
@@ -301,7 +289,6 @@ DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr)
static void i2c_slave_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->init = i2c_slave_qdev_init;
set_bit(DEVICE_CATEGORY_MISC, k->categories);
k->bus_type = TYPE_I2C_BUS;
k->props = i2c_props;
diff --git a/hw/input/lm832x.c b/hw/input/lm832x.c
index 2340523da0..b3e4099872 100644
--- a/hw/input/lm832x.c
+++ b/hw/input/lm832x.c
@@ -464,20 +464,19 @@ static const VMStateDescription vmstate_lm_kbd = {
};
-static int lm8323_init(I2CSlave *i2c)
+static void lm8323_realize(DeviceState *dev, Error **errp)
{
- LM823KbdState *s = LM8323(i2c);
+ LM823KbdState *s = LM8323(dev);
s->model = 0x8323;
s->pwm.tm[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, lm_kbd_pwm0_tick, s);
s->pwm.tm[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, lm_kbd_pwm1_tick, s);
s->pwm.tm[2] = timer_new_ns(QEMU_CLOCK_VIRTUAL, lm_kbd_pwm2_tick, s);
- qdev_init_gpio_out(DEVICE(i2c), &s->nirq, 1);
+ qdev_init_gpio_out(dev, &s->nirq, 1);
lm_kbd_reset(s);
qemu_register_reset((void *) lm_kbd_reset, s);
- return 0;
}
void lm832x_key_event(DeviceState *dev, int key, int state)
@@ -505,7 +504,7 @@ static void lm8323_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
- k->init = lm8323_init;
+ dc->realize = lm8323_realize;
k->event = lm_i2c_event;
k->recv = lm_i2c_rx;
k->send = lm_i2c_tx;
diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c
index 04e83787d4..3f5e3ca5d0 100644
--- a/hw/misc/tmp105.c
+++ b/hw/misc/tmp105.c
@@ -229,15 +229,14 @@ static void tmp105_reset(I2CSlave *i2c)
tmp105_interrupt_update(s);
}
-static int tmp105_init(I2CSlave *i2c)
+static void tmp105_realize(DeviceState *dev, Error **errp)
{
+ I2CSlave *i2c = I2C_SLAVE(dev);
TMP105State *s = TMP105(i2c);
qdev_init_gpio_out(&i2c->qdev, &s->pin, 1);
tmp105_reset(&s->i2c);
-
- return 0;
}
static void tmp105_initfn(Object *obj)
@@ -252,7 +251,7 @@ static void tmp105_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
- k->init = tmp105_init;
+ dc->realize = tmp105_realize;
k->event = tmp105_event;
k->recv = tmp105_rx;
k->send = tmp105_tx;
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 4a505abbce..c234044305 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -335,13 +335,11 @@ static void tmp421_reset(I2CSlave *i2c)
s->status = 0;
}
-static int tmp421_init(I2CSlave *i2c)
+static void tmp421_realize(DeviceState *dev, Error **errp)
{
- TMP421State *s = TMP421(i2c);
+ TMP421State *s = TMP421(dev);
tmp421_reset(&s->i2c);
-
- return 0;
}
static void tmp421_initfn(Object *obj)
@@ -366,7 +364,7 @@ static void tmp421_class_init(ObjectClass *klass, void *data)
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
TMP421Class *sc = TMP421_CLASS(klass);
- k->init = tmp421_init;
+ dc->realize = tmp421_realize;
k->event = tmp421_event;
k->recv = tmp421_rx;
k->send = tmp421_tx;
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index efa3621ac6..dece04a503 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -117,31 +117,29 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data)
return 0;
}
-static
-int at24c_eeprom_init(I2CSlave *i2c)
+static void at24c_eeprom_realize(DeviceState *dev, Error **errp)
{
- EEPROMState *ee = AT24C_EE(i2c);
-
- ee->mem = g_malloc0(ee->rsize);
+ EEPROMState *ee = AT24C_EE(dev);
if (ee->blk) {
int64_t len = blk_getlength(ee->blk);
if (len != ee->rsize) {
- ERR(TYPE_AT24C_EE " : Backing file size %lu != %u\n",
- (unsigned long)len, (unsigned)ee->rsize);
- exit(1);
+ error_setg(errp, "%s: Backing file size %" PRId64 " != %u",
+ TYPE_AT24C_EE, len, ee->rsize);
+ return;
}
if (blk_set_perm(ee->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
BLK_PERM_ALL, &error_fatal) < 0)
{
- ERR(TYPE_AT24C_EE
- " : Backing file incorrect permission\n");
- exit(1);
+ error_setg(errp, "%s: Backing file incorrect permission",
+ TYPE_AT24C_EE);
+ return;
}
}
- return 0;
+
+ ee->mem = g_malloc0(ee->rsize);
}
static
@@ -179,7 +177,7 @@ void at24c_eeprom_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
- k->init = &at24c_eeprom_init;
+ dc->realize = &at24c_eeprom_realize;
k->event = &at24c_eeprom_event;
k->recv = &at24c_eeprom_recv;
k->send = &at24c_eeprom_send;
diff --git a/hw/timer/twl92230.c b/hw/timer/twl92230.c
index eb58c378e0..9cbf0adba8 100644
--- a/hw/timer/twl92230.c
+++ b/hw/timer/twl92230.c
@@ -853,10 +853,9 @@ static const VMStateDescription vmstate_menelaus = {
}
};
-static int twl92230_init(I2CSlave *i2c)
+static void twl92230_realize(DeviceState *dev, Error **errp)
{
- DeviceState *dev = DEVICE(i2c);
- MenelausState *s = TWL92230(i2c);
+ MenelausState *s = TWL92230(dev);
s->rtc.hz_tm = timer_new_ms(rtc_clock, menelaus_rtc_hz, s);
/* Three output pins plus one interrupt pin. */
@@ -865,9 +864,7 @@ static int twl92230_init(I2CSlave *i2c)
/* Three input pins plus one power-button pin. */
qdev_init_gpio_in(dev, menelaus_gpio_set, 4);
- menelaus_reset(i2c);
-
- return 0;
+ menelaus_reset(I2C_SLAVE(dev));
}
static void twl92230_class_init(ObjectClass *klass, void *data)
@@ -875,7 +872,7 @@ static void twl92230_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
- sc->init = twl92230_init;
+ dc->realize = twl92230_realize;
sc->event = menelaus_event;
sc->recv = menelaus_rx;
sc->send = menelaus_tx;
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 1/7] hw/i2c/smbus: use DeviceClass::realize instead of SMBusDeviceClass::init Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 2/7] hw/i2c: use DeviceClass::realize instead of I2CSlaveClass::init Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-25 15:25 ` Gerd Hoffmann
2018-01-31 13:43 ` Markus Armbruster
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 4/7] virtio-ccw: convert VirtIOCCWDeviceClass::exit -> unrealize Philippe Mathieu-Daudé
` (4 subsequent siblings)
7 siblings, 2 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth,
Gerd Hoffmann
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/usb/ccid.h | 9 +++++--
hw/usb/ccid-card-emulated.c | 45 ++++++++++++++++++----------------
hw/usb/ccid-card-passthru.c | 10 ++++----
hw/usb/dev-smartcard-reader.c | 57 +++++++++++++++----------------------------
4 files changed, 56 insertions(+), 65 deletions(-)
diff --git a/hw/usb/ccid.h b/hw/usb/ccid.h
index 1f070116d6..11056b91ee 100644
--- a/hw/usb/ccid.h
+++ b/hw/usb/ccid.h
@@ -28,20 +28,25 @@ typedef struct CCIDCardInfo CCIDCardInfo;
* into the smartcard device (hw/ccid-card-*.c)
*/
typedef struct CCIDCardClass {
+ /*< private >*/
DeviceClass parent_class;
+ /*< public >*/
+
+ void (*realize)(CCIDCardState *card, Error **errp);
+ void (*unrealize)(CCIDCardState *card, Error **errp);
const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
void (*apdu_from_guest)(CCIDCardState *card,
const uint8_t *apdu,
uint32_t len);
- void (*exitfn)(CCIDCardState *card);
- int (*initfn)(CCIDCardState *card);
} CCIDCardClass;
/*
* state of the CCID Card device (i.e. hw/ccid-card-*.c)
*/
struct CCIDCardState {
+ /*< private >*/
DeviceState qdev;
+ /*< public >*/
uint32_t slot; /* For future use with multiple slot reader. */
};
diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index e646eb243b..a2b608a953 100644
--- a/hw/usb/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -27,6 +27,7 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include <eventt.h>
#include <vevent.h>
#include <vreader.h>
@@ -480,7 +481,7 @@ static uint32_t parse_enumeration(char *str,
return ret;
}
-static int emulated_initfn(CCIDCardState *base)
+static void emulated_realize(CCIDCardState *base, Error **errp)
{
EmulatedState *card = EMULATED_CCID_CARD(base);
VCardEmulError ret;
@@ -495,7 +496,8 @@ static int emulated_initfn(CCIDCardState *base)
card->reader = NULL;
card->quit_apdu_thread = 0;
if (init_event_notifier(card) < 0) {
- return -1;
+ error_setg(errp, TYPE_EMULATED_CCID ": event notifier creation failed");
+ return;
}
card->backend = 0;
@@ -505,11 +507,12 @@ static int emulated_initfn(CCIDCardState *base)
}
if (card->backend == 0) {
- printf("backend must be one of:\n");
+ error_setg(errp, TYPE_EMULATED_CCID ": no backend specified.");
+ error_append_hint(errp, "backend must be one of:\n");
for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) {
- printf("%s\n", ptable->name);
+ error_append_hint(errp, "%s\n", ptable->name);
}
- return -1;
+ return;
}
/* TODO: a passthru backened that works on local machine. third card type?*/
@@ -517,37 +520,37 @@ static int emulated_initfn(CCIDCardState *base)
if (card->cert1 != NULL && card->cert2 != NULL && card->cert3 != NULL) {
ret = emulated_initialize_vcard_from_certificates(card);
} else {
- printf("%s: you must provide all three certs for"
- " certificates backend\n", TYPE_EMULATED_CCID);
- return -1;
+ error_setg(errp, TYPE_EMULATED_CCID ": you must provide all three "
+ "certs for certificates backend");
+ return;
}
} else {
if (card->backend != BACKEND_NSS_EMULATED) {
- printf("%s: bad backend specified. The options are:\n%s (default),"
- " %s.\n", TYPE_EMULATED_CCID, BACKEND_NSS_EMULATED_NAME,
- BACKEND_CERTIFICATES_NAME);
- return -1;
+ error_setg(errp, TYPE_EMULATED_CCID ": no backend specified.");
+ error_append_hint(errp, "The options are: %s (default), %s.",
+ BACKEND_NSS_EMULATED_NAME,
+ BACKEND_CERTIFICATES_NAME);
+ return;
}
if (card->cert1 != NULL || card->cert2 != NULL || card->cert3 != NULL) {
- printf("%s: unexpected cert parameters to nss emulated backend\n",
- TYPE_EMULATED_CCID);
- return -1;
+ error_setg(errp, TYPE_EMULATED_CCID ": unexpected cert parameters "
+ "to nss emulated backend");
+ return;
}
/* default to mirroring the local hardware readers */
ret = wrap_vcard_emul_init(NULL);
}
if (ret != VCARD_EMUL_OK) {
- printf("%s: failed to initialize vcard\n", TYPE_EMULATED_CCID);
- return -1;
+ error_setg(errp, TYPE_EMULATED_CCID ": failed to initialize vcard");
+ return;
}
qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread,
card, QEMU_THREAD_JOINABLE);
qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thread,
card, QEMU_THREAD_JOINABLE);
- return 0;
}
-static void emulated_exitfn(CCIDCardState *base)
+static void emulated_unrealize(CCIDCardState *base, Error **errp)
{
EmulatedState *card = EMULATED_CCID_CARD(base);
VEvent *vevent = vevent_new(VEVENT_LAST, NULL, NULL);
@@ -581,8 +584,8 @@ static void emulated_class_initfn(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
CCIDCardClass *cc = CCID_CARD_CLASS(klass);
- cc->initfn = emulated_initfn;
- cc->exitfn = emulated_exitfn;
+ cc->realize = emulated_realize;
+ cc->unrealize = emulated_unrealize;
cc->get_atr = emulated_get_atr;
cc->apdu_from_guest = emulated_apdu_from_guest;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index 117711862e..844ad2f878 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -9,6 +9,7 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include <cacard/vscard_common.h>
#include "chardev/char-fe.h"
#include "qemu/error-report.h"
@@ -337,7 +338,7 @@ static const uint8_t *passthru_get_atr(CCIDCardState *base, uint32_t *len)
return card->atr;
}
-static int passthru_initfn(CCIDCardState *base)
+static void passthru_realize(CCIDCardState *base, Error **errp)
{
PassthruState *card = PASSTHRU_CCID_CARD(base);
@@ -351,15 +352,14 @@ static int passthru_initfn(CCIDCardState *base)
ccid_card_vscard_event, NULL, card, NULL, true);
ccid_card_vscard_send_init(card);
} else {
- error_report("missing chardev");
- return -1;
+ error_setg(errp, "missing chardev");
+ return;
}
card->debug = parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE,
card->debug);
assert(sizeof(DEFAULT_ATR) <= MAX_ATR_SIZE);
memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR));
card->atr_length = sizeof(DEFAULT_ATR);
- return 0;
}
static VMStateDescription passthru_vmstate = {
@@ -387,7 +387,7 @@ static void passthru_class_initfn(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
CCIDCardClass *cc = CCID_CARD_CLASS(klass);
- cc->initfn = passthru_initfn;
+ cc->realize = passthru_realize;
cc->get_atr = passthru_get_atr;
cc->apdu_from_guest = passthru_apdu_from_guest;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index e334d3be11..e36b190118 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -37,7 +37,6 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
-#include "qemu/error-report.h"
#include "hw/usb.h"
#include "hw/usb/desc.h"
@@ -500,26 +499,6 @@ static void ccid_card_apdu_from_guest(CCIDCardState *card,
}
}
-static void ccid_card_exitfn(CCIDCardState *card)
-{
- CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
-
- if (cc->exitfn) {
- cc->exitfn(card);
- }
-
-}
-
-static int ccid_card_initfn(CCIDCardState *card)
-{
- CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
-
- if (cc->initfn) {
- return cc->initfn(card);
- }
- return 0;
-}
-
static bool ccid_has_pending_answers(USBCCIDState *s)
{
return s->pending_answers_num > 0;
@@ -1281,41 +1260,45 @@ void ccid_card_card_inserted(CCIDCardState *card)
ccid_on_slot_change(s, true);
}
-static int ccid_card_exit(DeviceState *qdev)
+static void ccid_card_unrealize(DeviceState *qdev, Error **errp)
{
CCIDCardState *card = CCID_CARD(qdev);
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
USBDevice *dev = USB_DEVICE(qdev->parent_bus->parent);
USBCCIDState *s = USB_CCID_DEV(dev);
if (ccid_card_inserted(s)) {
ccid_card_card_removed(card);
}
- ccid_card_exitfn(card);
+ if (cc->unrealize) {
+ cc->unrealize(card, errp);
+ }
s->card = NULL;
- return 0;
}
-static int ccid_card_init(DeviceState *qdev)
+static void ccid_card_realize(DeviceState *qdev, Error **errp)
{
CCIDCardState *card = CCID_CARD(qdev);
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
USBDevice *dev = USB_DEVICE(qdev->parent_bus->parent);
USBCCIDState *s = USB_CCID_DEV(dev);
- int ret = 0;
if (card->slot != 0) {
- warn_report("usb-ccid supports one slot, can't add %d",
- card->slot);
- return -1;
+ error_setg(errp, "usb-ccid supports one slot, can't add %d",
+ card->slot);
+ return;
}
if (s->card != NULL) {
- warn_report("usb-ccid card already full, not adding");
- return -1;
+ error_setg(errp, "usb-ccid card already full, not adding");
+ return;
}
- ret = ccid_card_initfn(card);
- if (ret == 0) {
- s->card = card;
+ if (cc->realize) {
+ cc->realize(card, errp);
+ if (errp && *errp) {
+ return;
+ }
}
- return ret;
+ s->card = card;
}
static void ccid_realize(USBDevice *dev, Error **errp)
@@ -1477,8 +1460,8 @@ static void ccid_card_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
k->bus_type = TYPE_CCID_BUS;
- k->init = ccid_card_init;
- k->exit = ccid_card_exit;
+ k->realize = ccid_card_realize;
+ k->unrealize = ccid_card_unrealize;
k->props = ccid_props;
}
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 4/7] virtio-ccw: convert VirtIOCCWDeviceClass::exit -> unrealize
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 5/7] qdev: simplify the SysBusDeviceClass::init path Philippe Mathieu-Daudé
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth,
Michael S. Tsirkin, Cornelia Huck, Christian Borntraeger,
Alexander Graf, Richard Henderson, open list:virtio-ccw
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Farhan Ali <alifm@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
hw/s390x/virtio-ccw.h | 2 +-
hw/s390x/virtio-ccw.c | 35 +++++++++++++++++------------------
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 3905f3a3d6..2fc513001e 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -76,7 +76,7 @@ typedef struct VirtioCcwDevice VirtioCcwDevice;
typedef struct VirtIOCCWDeviceClass {
CCWDeviceClass parent_class;
void (*realize)(VirtioCcwDevice *dev, Error **errp);
- int (*exit)(VirtioCcwDevice *dev);
+ void (*unrealize)(VirtioCcwDevice *dev, Error **errp);
} VirtIOCCWDeviceClass;
/* Performance improves when virtqueue kick processing is decoupled from the
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 38f6a8afc9..a71c3feeb5 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -751,7 +751,7 @@ out_err:
g_free(sch);
}
-static int virtio_ccw_exit(VirtioCcwDevice *dev)
+static void virtio_ccw_unrealize(VirtioCcwDevice *dev, Error **errp)
{
CcwDevice *ccw_dev = CCW_DEVICE(dev);
SubchDev *sch = ccw_dev->sch;
@@ -764,7 +764,6 @@ static int virtio_ccw_exit(VirtioCcwDevice *dev)
release_indicator(&dev->routes.adapter, dev->indicators);
dev->indicators = NULL;
}
- return 0;
}
static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
@@ -1343,7 +1342,7 @@ static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_net_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_net_properties;
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
@@ -1371,7 +1370,7 @@ static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_blk_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_blk_properties;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
@@ -1399,7 +1398,7 @@ static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_serial_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_serial_properties;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
@@ -1427,7 +1426,7 @@ static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_balloon_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_balloon_properties;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -1455,7 +1454,7 @@ static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_scsi_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_scsi_properties;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
@@ -1482,7 +1481,7 @@ static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = vhost_ccw_scsi_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = vhost_ccw_scsi_properties;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
@@ -1519,7 +1518,7 @@ static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_rng_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_rng_properties;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -1557,7 +1556,7 @@ static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_crypto_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_crypto_properties;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -1595,7 +1594,7 @@ static void virtio_ccw_gpu_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_gpu_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_gpu_properties;
dc->hotpluggable = false;
@@ -1624,7 +1623,7 @@ static void virtio_ccw_input_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = virtio_ccw_input_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_input_properties;
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
@@ -1704,12 +1703,12 @@ static void virtio_ccw_busdev_realize(DeviceState *dev, Error **errp)
virtio_ccw_device_realize(_dev, errp);
}
-static int virtio_ccw_busdev_exit(DeviceState *dev)
+static void virtio_ccw_busdev_unrealize(DeviceState *dev, Error **errp)
{
VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
- VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
+ VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
- return _info->exit(_dev);
+ k->unrealize(_dev, errp);
}
static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev,
@@ -1727,7 +1726,7 @@ static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
k->unplug = virtio_ccw_busdev_unplug;
dc->realize = virtio_ccw_busdev_realize;
- dc->exit = virtio_ccw_busdev_exit;
+ dc->unrealize = virtio_ccw_busdev_unrealize;
dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
}
@@ -1803,7 +1802,7 @@ static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
k->realize = virtio_ccw_9p_realize;
dc->reset = virtio_ccw_reset;
dc->props = virtio_ccw_9p_properties;
@@ -1852,7 +1851,7 @@ static void vhost_vsock_ccw_class_init(ObjectClass *klass, void *data)
VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
k->realize = vhost_vsock_ccw_realize;
- k->exit = virtio_ccw_exit;
+ k->unrealize = virtio_ccw_unrealize;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
dc->props = vhost_vsock_ccw_properties;
dc->reset = virtio_ccw_reset;
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 5/7] qdev: simplify the SysBusDeviceClass::init path
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 4/7] virtio-ccw: convert VirtIOCCWDeviceClass::exit -> unrealize Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 6/7] qdev: remove DeviceClass::exit Philippe Mathieu-Daudé
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth
The SysBusDevice is the last DeviceClass::init user.
Instead of using
SysBusDeviceClass::realize
-> DeviceClass::realize
-> DeviceClass::init
-> sysbus_device_init
-> SysBusDeviceClass::init
Simplify the path by directly calling SysBusDeviceClass::init
in SysBusDeviceClass::realize:
SysBusDeviceClass::realize
-> SysBusDeviceClass::init
Finally, remove the DeviceClass::init, there are no more users.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/qdev-core.h | 2 --
hw/core/qdev.c | 14 --------------
hw/core/sysbus.c | 15 ++++++++++-----
3 files changed, 10 insertions(+), 21 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 51473eee7b..fd386b5d49 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -30,7 +30,6 @@ typedef enum DeviceCategory {
DEVICE_CATEGORY_MAX
} DeviceCategory;
-typedef int (*qdev_initfn)(DeviceState *dev);
typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
@@ -125,7 +124,6 @@ typedef struct DeviceClass {
const struct VMStateDescription *vmsd;
/* Private to qdev / bus. */
- qdev_initfn init; /* TODO remove, once users are converted to realize */
qdev_event exit; /* TODO remove, once users are converted to unrealize */
const char *bus_type;
} DeviceClass;
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index f739753e3a..1a985a511e 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -219,19 +219,6 @@ void device_listener_unregister(DeviceListener *listener)
QTAILQ_REMOVE(&device_listeners, listener, link);
}
-static void device_realize(DeviceState *dev, Error **errp)
-{
- DeviceClass *dc = DEVICE_GET_CLASS(dev);
-
- if (dc->init) {
- int rc = dc->init(dev);
- if (rc < 0) {
- error_setg(errp, "Device initialization failed.");
- return;
- }
- }
-}
-
static void device_unrealize(DeviceState *dev, Error **errp)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -1139,7 +1126,6 @@ static void device_class_init(ObjectClass *class, void *data)
DeviceClass *dc = DEVICE_CLASS(class);
class->unparent = device_unparent;
- dc->realize = device_realize;
dc->unrealize = device_unrealize;
/* by default all devices were considered as hotpluggable,
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 5d0887f499..11f6d14b84 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -18,6 +18,7 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "hw/sysbus.h"
#include "monitor/monitor.h"
#include "exec/address-spaces.h"
@@ -200,15 +201,19 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
}
}
-static int sysbus_device_init(DeviceState *dev)
+static void sysbus_realize(DeviceState *dev, Error **errp)
{
SysBusDevice *sd = SYS_BUS_DEVICE(dev);
SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
- if (!sbc->init) {
- return 0;
+ /* TODO remove, once users are converted to realize */
+ if (sbc->init) {
+ int rc = sbc->init(sd);
+ if (rc < 0) {
+ error_setg(errp, "Device initialization failed.");
+ return;
+ }
}
- return sbc->init(sd);
}
DeviceState *sysbus_create_varargs(const char *name,
@@ -324,7 +329,7 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)
static void sysbus_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->init = sysbus_device_init;
+ k->realize = sysbus_realize;
k->bus_type = TYPE_SYSTEM_BUS;
/*
* device_add plugs devices into a suitable bus. For "real" buses,
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 6/7] qdev: remove DeviceClass::exit
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 5/7] qdev: simplify the SysBusDeviceClass::init path Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 7/7] qdev: rename typedef qdev_resetfn() -> DeviceReset() Philippe Mathieu-Daudé
2018-01-31 13:42 ` [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Markus Armbruster
7 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth
it has no users.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/qdev-core.h | 2 --
hw/core/qdev.c | 14 --------------
2 files changed, 16 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index fd386b5d49..0bcba3b785 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -30,7 +30,6 @@ typedef enum DeviceCategory {
DEVICE_CATEGORY_MAX
} DeviceCategory;
-typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
@@ -124,7 +123,6 @@ typedef struct DeviceClass {
const struct VMStateDescription *vmsd;
/* Private to qdev / bus. */
- qdev_event exit; /* TODO remove, once users are converted to unrealize */
const char *bus_type;
} DeviceClass;
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 1a985a511e..0ee86d2db8 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -219,19 +219,6 @@ void device_listener_unregister(DeviceListener *listener)
QTAILQ_REMOVE(&device_listeners, listener, link);
}
-static void device_unrealize(DeviceState *dev, Error **errp)
-{
- DeviceClass *dc = DEVICE_GET_CLASS(dev);
-
- if (dc->exit) {
- int rc = dc->exit(dev);
- if (rc < 0) {
- error_setg(errp, "Device exit failed.");
- return;
- }
- }
-}
-
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version)
{
@@ -1126,7 +1113,6 @@ static void device_class_init(ObjectClass *class, void *data)
DeviceClass *dc = DEVICE_CLASS(class);
class->unparent = device_unparent;
- dc->unrealize = device_unrealize;
/* by default all devices were considered as hotpluggable,
* so with intent to check it in generic qdev_unplug() /
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [Qemu-devel] [PATCH v2 7/7] qdev: rename typedef qdev_resetfn() -> DeviceReset()
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 6/7] qdev: remove DeviceClass::exit Philippe Mathieu-Daudé
@ 2018-01-22 12:03 ` Philippe Mathieu-Daudé
2018-01-31 13:42 ` [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Markus Armbruster
7 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-01-22 12:03 UTC (permalink / raw)
To: Eduardo Habkost, Paolo Bonzini
Cc: Philippe Mathieu-Daudé,
qemu-devel, Markus Armbruster, Peter Maydell, Thomas Huth
following the DeviceRealize and DeviceUnrealize typedefs,
this unify a bit the QOM API.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/qdev-core.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 0bcba3b785..ae86cdd9ed 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -30,9 +30,9 @@ typedef enum DeviceCategory {
DEVICE_CATEGORY_MAX
} DeviceCategory;
-typedef void (*qdev_resetfn)(DeviceState *dev);
typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
+typedef void (*DeviceReset)(DeviceState *dev);
typedef void (*BusRealize)(BusState *bus, Error **errp);
typedef void (*BusUnrealize)(BusState *bus, Error **errp);
@@ -115,7 +115,7 @@ typedef struct DeviceClass {
bool hotpluggable;
/* callbacks */
- void (*reset)(DeviceState *dev);
+ DeviceReset reset;
DeviceRealize realize;
DeviceUnrealize unrealize;
--
2.15.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize Philippe Mathieu-Daudé
@ 2018-01-25 15:25 ` Gerd Hoffmann
2018-01-31 13:43 ` Markus Armbruster
1 sibling, 0 replies; 11+ messages in thread
From: Gerd Hoffmann @ 2018-01-25 15:25 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Eduardo Habkost, Paolo Bonzini, qemu-devel, Markus Armbruster,
Peter Maydell, Thomas Huth
On Mon, Jan 22, 2018 at 09:03:47AM -0300, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/usb/ccid.h | 9 +++++--
> hw/usb/ccid-card-emulated.c | 45 ++++++++++++++++++----------------
> hw/usb/ccid-card-passthru.c | 10 ++++----
> hw/usb/dev-smartcard-reader.c | 57 +++++++++++++++----------------------------
> 4 files changed, 56 insertions(+), 65 deletions(-)
Conflicts with another patch doing simliar things (switch to realize,
use error_report(), ...).
usb pull request is in flight. Can you have a look once it is merged?
thanks,
Gerd
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit()
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 7/7] qdev: rename typedef qdev_resetfn() -> DeviceReset() Philippe Mathieu-Daudé
@ 2018-01-31 13:42 ` Markus Armbruster
7 siblings, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2018-01-31 13:42 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Eduardo Habkost, Paolo Bonzini, Peter Maydell, Thomas Huth, qemu-devel
Philippe Mathieu-Daudé <f4bug@amsat.org> writes:
> since v1:
> - fix format string on 32-bit host (patchew)
> - do not add smbus_eeprom_reset() (Eduardo)
> - directly use DeviceClass::realize (Eduardo)
> - squashed 2 patches (Eduardo)
>
> Hi,
>
> This series finalize the qdev QOMification.
Awesome!
It's been almost nine years since qdev, and more than 7 since QOM.
Sadly, I don't have the time to review this closely right now.
> We first convert the I2CSlave/SMBusDevice,
> then the usb-ccid and virtio-ccw,
> and finally the SysBusDevice.
>
> At the end we get one less TODO :)
>
> /* TODO remove, once users are converted to unrealize */
>
> There is still one standing in SysBusDeviceClass::init().
Another one in ssi_sd_realize(), I think. I didn't really look for
more.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize Philippe Mathieu-Daudé
2018-01-25 15:25 ` Gerd Hoffmann
@ 2018-01-31 13:43 ` Markus Armbruster
1 sibling, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2018-01-31 13:43 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Eduardo Habkost, Paolo Bonzini, Peter Maydell, Thomas Huth,
qemu-devel, Gerd Hoffmann
Philippe Mathieu-Daudé <f4bug@amsat.org> writes:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/usb/ccid.h | 9 +++++--
> hw/usb/ccid-card-emulated.c | 45 ++++++++++++++++++----------------
> hw/usb/ccid-card-passthru.c | 10 ++++----
> hw/usb/dev-smartcard-reader.c | 57 +++++++++++++++----------------------------
> 4 files changed, 56 insertions(+), 65 deletions(-)
>
[...]
> diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
> index e646eb243b..a2b608a953 100644
> --- a/hw/usb/ccid-card-emulated.c
> +++ b/hw/usb/ccid-card-emulated.c
> @@ -27,6 +27,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qapi/error.h"
> #include <eventt.h>
> #include <vevent.h>
> #include <vreader.h>
> @@ -480,7 +481,7 @@ static uint32_t parse_enumeration(char *str,
> return ret;
> }
>
> -static int emulated_initfn(CCIDCardState *base)
> +static void emulated_realize(CCIDCardState *base, Error **errp)
> {
> EmulatedState *card = EMULATED_CCID_CARD(base);
> VCardEmulError ret;
> @@ -495,7 +496,8 @@ static int emulated_initfn(CCIDCardState *base)
> card->reader = NULL;
> card->quit_apdu_thread = 0;
> if (init_event_notifier(card) < 0) {
> - return -1;
> + error_setg(errp, TYPE_EMULATED_CCID ": event notifier creation failed");
> + return;
> }
>
> card->backend = 0;
> @@ -505,11 +507,12 @@ static int emulated_initfn(CCIDCardState *base)
> }
>
> if (card->backend == 0) {
> - printf("backend must be one of:\n");
> + error_setg(errp, TYPE_EMULATED_CCID ": no backend specified.");
No period at end of error_setg() messages, please. More of the same below.
> + error_append_hint(errp, "backend must be one of:\n");
> for (ptable = backend_enum_table; ptable->name != NULL; ++ptable) {
> - printf("%s\n", ptable->name);
> + error_append_hint(errp, "%s\n", ptable->name);
> }
> - return -1;
> + return;
> }
>
> /* TODO: a passthru backened that works on local machine. third card type?*/
[...]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-01-31 13:43 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-22 12:03 [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 1/7] hw/i2c/smbus: use DeviceClass::realize instead of SMBusDeviceClass::init Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 2/7] hw/i2c: use DeviceClass::realize instead of I2CSlaveClass::init Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 3/7] usb-ccid: convert CCIDCardClass::init -> realize Philippe Mathieu-Daudé
2018-01-25 15:25 ` Gerd Hoffmann
2018-01-31 13:43 ` Markus Armbruster
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 4/7] virtio-ccw: convert VirtIOCCWDeviceClass::exit -> unrealize Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 5/7] qdev: simplify the SysBusDeviceClass::init path Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 6/7] qdev: remove DeviceClass::exit Philippe Mathieu-Daudé
2018-01-22 12:03 ` [Qemu-devel] [PATCH v2 7/7] qdev: rename typedef qdev_resetfn() -> DeviceReset() Philippe Mathieu-Daudé
2018-01-31 13:42 ` [Qemu-devel] [PATCH v2 0/7] qdev: remove DeviceClass::init/exit() Markus Armbruster
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.