From patchwork Sun Oct 23 07:06:53 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: 9391035 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 EB6C2607FF for ; Sun, 23 Oct 2016 07:23:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE82528E1C for ; Sun, 23 Oct 2016 07:23:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B32DC28E36; Sun, 23 Oct 2016 07:23:06 +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 0183B28E1C for ; Sun, 23 Oct 2016 07:23:05 +0000 (UTC) Received: from localhost ([::1]:39991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byD7Y-0001PB-Dp for patchwork-qemu-devel@patchwork.kernel.org; Sun, 23 Oct 2016 03:23:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byD7B-0001P3-63 for qemu-devel@nongnu.org; Sun, 23 Oct 2016 03:22:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byD78-0006Oa-16 for qemu-devel@nongnu.org; Sun, 23 Oct 2016 03:22:41 -0400 Received: from mproxyhzb2.163.com ([123.58.178.202]:51930) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byD77-0006OF-4R for qemu-devel@nongnu.org; Sun, 23 Oct 2016 03:22:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=XcLkDFTDzx/Eaxk08j /3TrNjiMXe0J8NPLpj4NbVCbI=; b=AqFe6vPDkaHE/DPSos6RV18zL4qaOPdN+z T4oYLVqWVzxFtfl/299LNo/lSUIh/eMZHQZ/So1I9HtqN9D+4V/DnN546DGEEYrh STpiTlE8317UwJsdhGTPftTss8HW+02+QDgtKJ9MxSrDcJsweZtnT/dyoFTFqjSm mQzD3SMqg= Received: from debian.lan (unknown [114.111.167.207]) by smtp13 (Coremail) with SMTP id EcCowABHWQyHYQxYnpqrBA--.5335S4; Sun, 23 Oct 2016 15:06:55 +0800 (CST) From: xiaoqiang zhao To: qemu-devel@nongnu.org Date: Sun, 23 Oct 2016 15:06:53 +0800 Message-Id: <20161023070653.1665-3-zxq_yx_007@163.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161023070653.1665-1-zxq_yx_007@163.com> References: <20161023070653.1665-1-zxq_yx_007@163.com> X-CM-TRANSID: EcCowABHWQyHYQxYnpqrBA--.5335S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw4UZFWDXw4rWrW3GFy3Arb_yoW5WF4DpF Z3Wan8CF4vgFsxJwsFkFZrCFn5Jan7WryfKry3GrnakayUWF1DXryvkryFkrW8GrWkAF15 ZrW8Xr97G3WUKr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b1sqXUUUUU= X-Originating-IP: [114.111.167.207] X-CM-SenderInfo: 520ts5t0bqili6rwjhhfrp/xtbBEg8MxlZX0PAyTQAAsJ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 123.58.178.202 Subject: [Qemu-devel] [PATCH 2/2] hw/net: QOM'ify etraxfs_eth.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: edgar.iglesias@gmail.com 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 Reviewed-by: Edgar E. Iglesias --- hw/net/etraxfs_eth.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index efaa49f..9bb814f 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -27,6 +27,7 @@ #include "net/net.h" #include "hw/cris/etraxfs.h" #include "qemu/error-report.h" +#include "qapi/error.h" #define D(x) @@ -584,14 +585,25 @@ static NetClientInfo net_etraxfs_info = { .link_status_changed = eth_set_link, }; -static int fs_eth_init(SysBusDevice *sbd) +static void fs_eth_init(Object *obj) +{ + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + ETRAXFSEthState *s = ETRAX_FS_ETH(obj); + + memory_region_init_io(&s->mmio, obj, ð_ops, s, + "etraxfs-eth", 0x5c); + sysbus_init_mmio(sbd, &s->mmio); + + tdk_init(&s->phy); +} + +static void fs_eth_realize(DeviceState *dev, Error **errp) { - DeviceState *dev = DEVICE(sbd); ETRAXFSEthState *s = ETRAX_FS_ETH(dev); if (!s->dma_out || !s->dma_in) { - error_report("Unconnected ETRAX-FS Ethernet MAC"); - return -1; + error_setg(errp, "Unconnected ETRAX-FS Ethernet MAC"); + return; } s->dma_out->client.push = eth_tx_push; @@ -599,19 +611,11 @@ static int fs_eth_init(SysBusDevice *sbd) s->dma_in->client.opaque = s; s->dma_in->client.pull = NULL; - memory_region_init_io(&s->mmio, OBJECT(dev), ð_ops, s, - "etraxfs-eth", 0x5c); - sysbus_init_mmio(sbd, &s->mmio); - qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf, - object_get_typename(OBJECT(s)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); - - - tdk_init(&s->phy); mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr); - return 0; } static Property etraxfs_eth_properties[] = { @@ -625,18 +629,18 @@ static Property etraxfs_eth_properties[] = { static void etraxfs_eth_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = fs_eth_init; dc->props = etraxfs_eth_properties; /* Reason: pointer properties "dma_out", "dma_in" */ dc->cannot_instantiate_with_device_add_yet = true; + dc->realize = fs_eth_realize; } static const TypeInfo etraxfs_eth_info = { .name = TYPE_ETRAX_FS_ETH, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(ETRAXFSEthState), + .instance_init = fs_eth_init, .class_init = etraxfs_eth_class_init, };