From patchwork Mon Feb 22 03:15:26 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: 8371231 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4A12A9F52D for ; Mon, 22 Feb 2016 03:17:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8304420364 for ; Mon, 22 Feb 2016 03:17:37 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id CF34420306 for ; Mon, 22 Feb 2016 03:17:36 +0000 (UTC) Received: from localhost ([::1]:46467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXh0C-0000rE-4U for patchwork-qemu-devel@patchwork.kernel.org; Sun, 21 Feb 2016 22:17:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXgzu-0000mR-Qj for qemu-devel@nongnu.org; Sun, 21 Feb 2016 22:17:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXgzs-0007Vx-NR for qemu-devel@nongnu.org; Sun, 21 Feb 2016 22:17:18 -0500 Received: from m12-16.163.com ([220.181.12.16]:54314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXgzq-0007Rz-0p; Sun, 21 Feb 2016 22:17:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=OFXOh0xWPDR9+RvJd6 u+6FMsc0QnRM6p1sV1Tb4yDSE=; b=D9yK8et+CAl90wRrccseyj7ineueiU241U L+xYTi17ed2w5M1xuTxE1bt/4gwv2KuIoKGCYTmC1UBibLfdRE4pDFaufshyQauY wH9RGPf3C8+PTVOS4ysMXHiKAUOUqm4C1Zn2GYsEn0uKNl0I6Lx1H306dZaYbe1/ 6NL8h14L8= Received: from localhost.localdomain (unknown [118.187.28.42]) by smtp12 (Coremail) with SMTP id EMCowEB5zUeWfcpW0G6hAA--.38100S4; Mon, 22 Feb 2016 11:16:45 +0800 (CST) From: xiaoqiang zhao To: qemu-devel@nongnu.org Date: Mon, 22 Feb 2016 11:15:26 +0800 Message-Id: <1456110933-5457-3-git-send-email-zxq_yx_007@163.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456110933-5457-1-git-send-email-zxq_yx_007@163.com> References: <1456110933-5457-1-git-send-email-zxq_yx_007@163.com> X-CM-TRANSID: EMCowEB5zUeWfcpW0G6hAA--.38100S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw1kJryDKFy5Xw1xWry7trb_yoW5Gr17pw 4fXFnay3W5XF4xXa1xJFnrGFZxAwn7GrW8Grn7JrWI9ws7JryDKa47Ars8tFsFkr4Fva13 JrZ5Kw15CFy7Kr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jl9akUUUUU= X-Originating-IP: [118.187.28.42] X-CM-SenderInfo: 520ts5t0bqili6rwjhhfrp/xtbBEh0XxlZXwMnXMgAAsz X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 220.181.12.16 Cc: peter.maydell@linaro.org, gxt@mprc.pku.edu.cn, i.mitsyanko@gmail.com, mark.cave-ayland@ilande.co.uk, michael@walle.cc, qemu-arm@nongnu.org, edgar.iglesias@gmail.com, m.kozlov@samsung.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v4 2/9] hw/timer: QOM'ify grlib_gptimer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP * split the old SysBus init function into an instance_init and a Device realize function * use DeviceClass::realize instead of SysBusDeviceClass::init Signed-off-by: xiaoqiang zhao --- hw/timer/grlib_gptimer.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c index dd000f5..02a19c9 100644 --- a/hw/timer/grlib_gptimer.c +++ b/hw/timer/grlib_gptimer.c @@ -348,16 +348,29 @@ static void grlib_gptimer_reset(DeviceState *d) } } -static int grlib_gptimer_init(SysBusDevice *dev) +static void grlib_gptimer_init(Object *obj) { - GPTimerUnit *unit = GRLIB_GPTIMER(dev); - unsigned int i; + GPTimerUnit *unit = GRLIB_GPTIMER(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); assert(unit->nr_timers > 0); assert(unit->nr_timers <= GPTIMER_MAX_TIMERS); unit->timers = g_malloc0(sizeof unit->timers[0] * unit->nr_timers); + memory_region_init_io(&unit->iomem, obj, &grlib_gptimer_ops, + unit, "gptimer", + UNIT_REG_SIZE + GPTIMER_REG_SIZE * unit->nr_timers); + + sysbus_init_mmio(dev, &unit->iomem); +} + +static void grlib_gptimer_realize(DeviceState *dev, Error *errp) +{ + GPTimerUnit *unit = GRLIB_GPTIMER(dev); + SysBusDevice *dev = SYS_BUS_DEVICE(dev); + unsigned int i; + for (i = 0; i < unit->nr_timers; i++) { GPTimer *timer = &unit->timers[i]; @@ -371,13 +384,6 @@ static int grlib_gptimer_init(SysBusDevice *dev) ptimer_set_freq(timer->ptimer, unit->freq_hz); } - - memory_region_init_io(&unit->iomem, OBJECT(unit), &grlib_gptimer_ops, - unit, "gptimer", - UNIT_REG_SIZE + GPTIMER_REG_SIZE * unit->nr_timers); - - sysbus_init_mmio(dev, &unit->iomem); - return 0; } static Property grlib_gptimer_properties[] = { @@ -390,9 +396,8 @@ static Property grlib_gptimer_properties[] = { static void grlib_gptimer_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = grlib_gptimer_init; + dc->realize = grlib_gptimer_realize; dc->reset = grlib_gptimer_reset; dc->props = grlib_gptimer_properties; } @@ -401,6 +406,7 @@ static const TypeInfo grlib_gptimer_info = { .name = TYPE_GRLIB_GPTIMER, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(GPTimerUnit), + .instance_init = grlib_gptimer_init, .class_init = grlib_gptimer_class_init, };