From patchwork Sat Dec 31 01:18:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhao xiao qiang X-Patchwork-Id: 9492573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15ED262AB9 for ; Sat, 31 Dec 2016 01:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0090D252D5 for ; Sat, 31 Dec 2016 01:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E62D925F31; Sat, 31 Dec 2016 01:20:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 82256252D5 for ; Sat, 31 Dec 2016 01:20:25 +0000 (UTC) Received: from localhost ([::1]:42110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN8LQ-00025u-EV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 20:20:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN8K5-0001QF-Ik for qemu-devel@nongnu.org; Fri, 30 Dec 2016 20:19:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cN8K3-0000L0-7z for qemu-devel@nongnu.org; Fri, 30 Dec 2016 20:19:01 -0500 Received: from m12-14.163.com ([220.181.12.14]:45625) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN8K2-0000KA-LV for qemu-devel@nongnu.org; Fri, 30 Dec 2016 20:18:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=Ad8iqPb6qRpHbljkpF Otcj14E95h9OE8VTfAWg+08RE=; b=kSwcVPEHxmsvTkK1RSok2KslyoIfsX5IlL 4pys00wRBxDJpT6g/vqW0NvNt2SxBB0hxsm3S9NHLqt2gTDlABExTgk8jepMEFjb OCMSilgwxH/XsJ5J6JmcFqLmBbHImAOPf4gb1fhRSTrqsZg9W8jQtDyQgJ26UQ+w 2QU/Hcn9Q= Received: from localhost.localdomain (unknown [223.104.3.243]) by smtp10 (Coremail) with SMTP id DsCowAAn4M94B2dY4BCVFw--.1240S6; Sat, 31 Dec 2016 09:18:57 +0800 (CST) From: xiaoqiang zhao To: qemu-devel@nongnu.org Date: Sat, 31 Dec 2016 09:18:46 +0800 Message-Id: <20161231011847.4153-5-zxq_yx_007@163.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161231011847.4153-1-zxq_yx_007@163.com> References: <20161231011847.4153-1-zxq_yx_007@163.com> X-CM-TRANSID: DsCowAAn4M94B2dY4BCVFw--.1240S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw1ktw43Kr1xZr4ftF1DWrg_yoW5Cw1kpF Z3ZFZ0kr48JFZ7ZrZrA3yqgF1Fkwn7Kw17CFyIkwn2qF17Jry7XFs7WFyjyFW7KrZFqa1f tFW8Jr129anYq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j40PhUUUUU= X-Originating-IP: [223.104.3.243] X-CM-SenderInfo: 520ts5t0bqili6rwjhhfrp/1tbiFgFRxlWBUOwlXAAAsR X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH 4/5] hw/net: QOM'ify milkymist-minimac2.c 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: michael@walle.cc Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP * Split the old SysBus init into an instance_init and a DeviceClass::realize function * Drop the old SysBus init function and use instance_init Signed-off-by: xiaoqiang zhao --- hw/net/milkymist-minimac2.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/net/milkymist-minimac2.c b/hw/net/milkymist-minimac2.c index c3a12e1197..81d10d64bb 100644 --- a/hw/net/milkymist-minimac2.c +++ b/hw/net/milkymist-minimac2.c @@ -452,21 +452,21 @@ static NetClientInfo net_milkymist_minimac2_info = { .receive = minimac2_rx, }; -static int milkymist_minimac2_init(SysBusDevice *sbd) +static void milkymist_minimac2_init(Object *obj) { - DeviceState *dev = DEVICE(sbd); - MilkymistMinimac2State *s = MILKYMIST_MINIMAC2(dev); + MilkymistMinimac2State *s = MILKYMIST_MINIMAC2(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); size_t buffers_size = TARGET_PAGE_ALIGN(3 * MINIMAC2_BUFFER_SIZE); sysbus_init_irq(sbd, &s->rx_irq); sysbus_init_irq(sbd, &s->tx_irq); - memory_region_init_io(&s->regs_region, OBJECT(dev), &minimac2_ops, s, + memory_region_init_io(&s->regs_region, obj, &minimac2_ops, s, "milkymist-minimac2", R_MAX * 4); sysbus_init_mmio(sbd, &s->regs_region); /* register buffers memory */ - memory_region_init_ram(&s->buffers, OBJECT(dev), "milkymist-minimac2.buffers", + memory_region_init_ram(&s->buffers, obj, "milkymist-minimac2.buffers", buffers_size, &error_fatal); vmstate_register_ram_global(&s->buffers); s->rx0_buf = memory_region_get_ram_ptr(&s->buffers); @@ -474,13 +474,16 @@ static int milkymist_minimac2_init(SysBusDevice *sbd) s->tx_buf = s->rx1_buf + MINIMAC2_BUFFER_SIZE; sysbus_init_mmio(sbd, &s->buffers); +} + +static void milkymist_minimac2_realize(DeviceState *dev, Error **errp) +{ + MilkymistMinimac2State *s = MILKYMIST_MINIMAC2(dev); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_milkymist_minimac2_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); - - return 0; } static const VMStateDescription vmstate_milkymist_minimac2_mdio = { @@ -521,18 +524,18 @@ static Property milkymist_minimac2_properties[] = { static void milkymist_minimac2_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = milkymist_minimac2_init; dc->reset = milkymist_minimac2_reset; dc->vmsd = &vmstate_milkymist_minimac2; dc->props = milkymist_minimac2_properties; + dc->realize = milkymist_minimac2_realize; } static const TypeInfo milkymist_minimac2_info = { .name = TYPE_MILKYMIST_MINIMAC2, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(MilkymistMinimac2State), + .instance_init = milkymist_minimac2_init, .class_init = milkymist_minimac2_class_init, };