From patchwork Mon May 28 14:45:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 921579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40vfr00vg8z9s0y for ; Tue, 29 May 2018 00:48:48 +1000 (AEST) Received: from localhost ([::1]:56602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJS1-0001SI-Rp for incoming@patchwork.ozlabs.org; Mon, 28 May 2018 10:48:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJOf-0008O8-0x for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNJOa-0005dW-2A for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52352 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNJOZ-0005c2-Qt for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20906BD9E; Mon, 28 May 2018 14:45:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D79C111166F7; Mon, 28 May 2018 14:45:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A6BDC1138658; Mon, 28 May 2018 16:45:09 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 28 May 2018 16:45:06 +0200 Message-Id: <20180528144509.15812-2-armbru@redhat.com> In-Reply-To: <20180528144509.15812-1-armbru@redhat.com> References: <20180528144509.15812-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 28 May 2018 14:45:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 28 May 2018 14:45:11 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 1/4] hw/i2c/smbus: Use DeviceClass::realize instead of SMBusDeviceClass::init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, thuth@redhat.com, pbonzini@redhat.com, f4bug@amsat.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé SMBusDeviceClass::init is no more used, remove it. Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20180419212727.26095-2-f4bug@amsat.org> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- hw/i2c/smbus.c | 9 --------- hw/i2c/smbus_eeprom.c | 5 ++--- include/hw/i2c/smbus.h | 1 - 3 files changed, 2 insertions(+), 13 deletions(-) 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; 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); From patchwork Mon May 28 14:45:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 921581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40vfv45zWSz9s15 for ; Tue, 29 May 2018 00:51:27 +1000 (AEST) Received: from localhost ([::1]:56617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJUa-0002mQ-4b for incoming@patchwork.ozlabs.org; Mon, 28 May 2018 10:51:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJOf-0008P3-6E for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNJOa-0005dg-3E for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50114 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNJOZ-0005cG-RZ for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B9BC4022909; Mon, 28 May 2018 14:45:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D79E7ED17F; Mon, 28 May 2018 14:45:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A99821138665; Mon, 28 May 2018 16:45:09 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 28 May 2018 16:45:07 +0200 Message-Id: <20180528144509.15812-3-armbru@redhat.com> In-Reply-To: <20180528144509.15812-1-armbru@redhat.com> References: <20180528144509.15812-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 28 May 2018 14:45:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 28 May 2018 14:45:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 2/4] hw/i2c: Use DeviceClass::realize instead of I2CSlaveClass::init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, thuth@redhat.com, pbonzini@redhat.com, f4bug@amsat.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé I2CSlaveClass::init is no more used, remove it. Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20180419212727.26095-3-f4bug@amsat.org> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 ++++------- include/hw/i2c/i2c.h | 3 --- 10 files changed, 36 insertions(+), 65 deletions(-) diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c index 416a78e869..f4aa838f62 100644 --- a/hw/audio/wm8750.c +++ b/hw/audio/wm8750.c @@ -617,14 +617,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 @@ -707,7 +705,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 4c203ef5c6..a560e3afd2 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 cfccefca3d..ab72d5bf2b 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -258,18 +258,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; @@ -283,7 +271,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 d39953126b..74da30d9ca 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 9e22d64e36..0918f3a6ea 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 22183f5360..27cd01e615 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -116,31 +116,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 @@ -178,7 +176,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 ef116c636c..3b43b46199 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; diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index d727379b48..5dc166158b 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -28,9 +28,6 @@ typedef struct I2CSlave I2CSlave; 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); From patchwork Mon May 28 14:45:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 921578 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40vfpH0TyZz9s0y for ; Tue, 29 May 2018 00:47:19 +1000 (AEST) Received: from localhost ([::1]:56596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJQa-0000pd-Rf for incoming@patchwork.ozlabs.org; Mon, 28 May 2018 10:47:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJOf-0008O9-1L for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNJOZ-0005d9-V6 for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59660 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNJOZ-0005c1-Ql for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D592401EF04; Mon, 28 May 2018 14:45:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7A191C595; Mon, 28 May 2018 14:45:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id ACEB8113866B; Mon, 28 May 2018 16:45:09 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 28 May 2018 16:45:08 +0200 Message-Id: <20180528144509.15812-4-armbru@redhat.com> In-Reply-To: <20180528144509.15812-1-armbru@redhat.com> References: <20180528144509.15812-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 28 May 2018 14:45:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 28 May 2018 14:45:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 3/4] qdev: Simplify the SysBusDeviceClass::init path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, thuth@redhat.com, pbonzini@redhat.com, f4bug@amsat.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé 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 Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20180419212727.26095-4-f4bug@amsat.org> Reviewed-by: Markus Armbruster [Removal of DeviceClass::init() moved into next patch, sysbus_realize() tweaked for clarity] Signed-off-by: Markus Armbruster --- hw/core/sysbus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 5d0887f499..ecfb0cfc0e 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,18 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size) } } -static int sysbus_device_init(DeviceState *dev) +/* TODO remove once all sysbus devices have been converted to realize */ +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; + return; + } + if (sbc->init(sd) < 0) { + error_setg(errp, "Device initialization failed"); } - return sbc->init(sd); } DeviceState *sysbus_create_varargs(const char *name, @@ -324,7 +328,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, From patchwork Mon May 28 14:45:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 921580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40vfsY0Rlbz9s16 for ; Tue, 29 May 2018 00:50:09 +1000 (AEST) Received: from localhost ([::1]:56605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJTI-00026z-TS for incoming@patchwork.ozlabs.org; Mon, 28 May 2018 10:50:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNJOf-0008OA-1e for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNJOZ-0005dG-Vw for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50106 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNJOZ-0005cC-RP for qemu-devel@nongnu.org; Mon, 28 May 2018 10:45:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A0EC4022905; Mon, 28 May 2018 14:45:11 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D798411166F6; Mon, 28 May 2018 14:45:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B038211386A9; Mon, 28 May 2018 16:45:09 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 28 May 2018 16:45:09 +0200 Message-Id: <20180528144509.15812-5-armbru@redhat.com> In-Reply-To: <20180528144509.15812-1-armbru@redhat.com> References: <20180528144509.15812-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 28 May 2018 14:45:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 28 May 2018 14:45:11 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 4/4] qdev: Remove DeviceClass::init() and ::exit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, thuth@redhat.com, pbonzini@redhat.com, f4bug@amsat.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Since no devices use it, we can safely remove it. Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20180419212727.26095-5-f4bug@amsat.org> Reviewed-by: Markus Armbruster [Removal of DeviceClass::init() moved from previous patch, missing documentation updates supplied] Signed-off-by: Markus Armbruster --- hw/core/qdev.c | 28 ---------------------------- include/hw/qdev-core.h | 20 ++++---------------- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f6f92473b8..ffec461791 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -208,32 +208,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); - - 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) { @@ -1065,8 +1039,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, * so with intent to check it in generic qdev_unplug() / diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9453588160..f1fd0f8736 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -29,8 +29,6 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; -typedef int (*qdev_initfn)(DeviceState *dev); -typedef int (*qdev_event)(DeviceState *dev); typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); typedef void (*DeviceReset)(DeviceState *dev); @@ -43,13 +41,9 @@ struct VMStateDescription; * DeviceClass: * @props: Properties accessing state fields. * @realize: Callback function invoked when the #DeviceState:realized - * property is changed to %true. The default invokes @init if not %NULL. + * property is changed to %true. * @unrealize: Callback function invoked when the #DeviceState:realized * property is changed to %false. - * @init: Callback function invoked when the #DeviceState::realized property - * is changed to %true. Deprecated, new types inheriting directly from - * TYPE_DEVICE should use @realize instead, new leaf types should consult - * their respective parent type. * @hotpluggable: indicates if #DeviceClass is hotpluggable, available * as readonly "hotpluggable" property of #DeviceState instance * @@ -73,19 +67,15 @@ struct VMStateDescription; * object_initialize() in their own #TypeInfo.instance_init and forward the * realization events appropriately. * - * The @init callback is considered private to a particular bus implementation - * (immediate abstract child types of TYPE_DEVICE). Derived leaf types set an - * "init" callback on their parent class instead. - * * Any type may override the @realize and/or @unrealize callbacks but needs * to call the parent type's implementation if keeping their functionality * is desired. Refer to QOM documentation for further discussion and examples. * * * - * If a type derived directly from TYPE_DEVICE implements @realize, it does - * not need to implement @init and therefore does not need to store and call - * #DeviceClass' default @realize callback. + * Since TYPE_DEVICE doesn't implement @realize and @unrealize, types + * derived directly from it need not call their parent's @realize and + * @unrealize. * For other types consult the documentation and implementation of the * respective parent types. * @@ -124,8 +114,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;