From patchwork Sat Dec 31 01:18:45 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: 9492583 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 3CE0362ABC for ; Sat, 31 Dec 2016 01:27:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28DAE223B2 for ; Sat, 31 Dec 2016 01:27:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A24025F31; Sat, 31 Dec 2016 01:27:51 +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 A8CC8223B2 for ; Sat, 31 Dec 2016 01:27:50 +0000 (UTC) Received: from localhost ([::1]:42151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN8Sb-0000TT-OL for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 20:27:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN8K5-0001QH-JB 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-0000Ku-5D for qemu-devel@nongnu.org; Fri, 30 Dec 2016 20:19:01 -0500 Received: from m12-14.163.com ([220.181.12.14]:45614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN8K2-0000K8-Is 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=lcQmd00q3B/iFT6rJ1 Ky1kLVZ4OERxYJ2+J0sl/b7kE=; b=h7kCtJrZlim5g6b6KaB7AtB0ChH6X9TvzV /AwbnIErZLWE25pMQX1eFTIuDqCCNGoQhWf/JVA6b3ixPRnZhCb2mspvqd+N7YQl /6PrqcZAJBGSj+lnc4eUgo9/U/PUfkcR68/d37akGQuKSUVTliQhvUq9HNytfS5e cPqd1iCSk= Received: from localhost.localdomain (unknown [223.104.3.243]) by smtp10 (Coremail) with SMTP id DsCowAAn4M94B2dY4BCVFw--.1240S5; Sat, 31 Dec 2016 09:18:56 +0800 (CST) From: xiaoqiang zhao To: qemu-devel@nongnu.org Date: Sat, 31 Dec 2016 09:18:45 +0800 Message-Id: <20161231011847.4153-4-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--.1240S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw1kuFWfKrWxtFy5Xr1DJrb_yoW5GFyfpF Z7Zan0kr4DGrsrZrW7Xr1qgF1DAw1ktw18Cr40yrn3CF47Cry5Z3Z2qa4UAF1jqFZYvay3 ZF1rWr1jyFZ8tw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jc6pPUUUUU= X-Originating-IP: [223.104.3.243] X-CM-SenderInfo: 520ts5t0bqili6rwjhhfrp/1tbiTABRxlSISghXTgAAsc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH 3/5] hw/sd: QOM'ify milkymist-memcard.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 function into an instance_init and Device realize function Signed-off-by: xiaoqiang zhao --- hw/sd/milkymist-memcard.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c index 1f2f0ed44a..c5abcfe51f 100644 --- a/hw/sd/milkymist-memcard.c +++ b/hw/sd/milkymist-memcard.c @@ -30,6 +30,7 @@ #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/sd/sd.h" +#include "qapi/error.h" enum { ENABLE_CMD_TX = (1<<0), @@ -250,7 +251,17 @@ static void milkymist_memcard_reset(DeviceState *d) } } -static int milkymist_memcard_init(SysBusDevice *dev) +static void milkymist_memcard_init(Object *obj) +{ + MilkymistMemcardState *s = MILKYMIST_MEMCARD(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); + + memory_region_init_io(&s->regs_region, obj, &memcard_mmio_ops, s, + "milkymist-memcard", R_MAX * 4); + sysbus_init_mmio(dev, &s->regs_region); +} + +static void milkymist_memcard_realize(DeviceState *dev, Error **errp) { MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev); DriveInfo *dinfo; @@ -261,16 +272,10 @@ static int milkymist_memcard_init(SysBusDevice *dev) blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; s->card = sd_init(blk, false); if (s->card == NULL) { - return -1; + error_setg(errp, "sd_init failed"); } s->enabled = blk && blk_is_inserted(blk); - - memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, - "milkymist-memcard", R_MAX * 4); - sysbus_init_mmio(dev, &s->regs_region); - - return 0; } static const VMStateDescription vmstate_milkymist_memcard = { @@ -293,19 +298,19 @@ static const VMStateDescription vmstate_milkymist_memcard = { static void milkymist_memcard_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = milkymist_memcard_init; dc->reset = milkymist_memcard_reset; dc->vmsd = &vmstate_milkymist_memcard; /* Reason: init() method uses drive_get_next() */ dc->cannot_instantiate_with_device_add_yet = true; + dc->realize = milkymist_memcard_realize; } static const TypeInfo milkymist_memcard_info = { .name = TYPE_MILKYMIST_MEMCARD, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(MilkymistMemcardState), + .instance_init = milkymist_memcard_init, .class_init = milkymist_memcard_class_init, };