From patchwork Thu May 19 03:43:36 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: 9123661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 939F2BF29F for ; Thu, 19 May 2016 03:44:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E4FA22022A for ; Thu, 19 May 2016 03:44:56 +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 34F1C20225 for ; Thu, 19 May 2016 03:44:56 +0000 (UTC) Received: from localhost ([::1]:48022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3EtI-00015s-N4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 May 2016 23:44:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3Esv-00014Y-Ib for qemu-devel@nongnu.org; Wed, 18 May 2016 23:44:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3Esq-0000QX-IG for qemu-devel@nongnu.org; Wed, 18 May 2016 23:44:28 -0400 Received: from m12-11.163.com ([220.181.12.11]:56070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3Esq-0000QD-0i for qemu-devel@nongnu.org; Wed, 18 May 2016 23:44:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=EtS5a1hx4mTOpvI6En dN5dSTBGQqkDK9leq6fHAOaz4=; b=deNubkIUCLM8eROpqOnKmzT47Gq+PgXmpb o6ueOqR7lMzTCFPuHkz6mkygcAk8Z/6WRZYlOayhaCBcIjLsyoZdaZMYijmP5hAQ xzWdmSXx7jzMHUrVX3tzMc+Xl/Tq9LwRt8zp7xiaance5zPS8c7wWLRWLF2q0KMC H58Drq2wI= Received: from localhost.localdomain (unknown [118.187.28.42]) by smtp7 (Coremail) with SMTP id C8CowACHS3lrNj1XtX2nDg--.29618S5; Thu, 19 May 2016 11:43:54 +0800 (CST) From: xiaoqiang zhao To: qemu-devel@nongnu.org Date: Thu, 19 May 2016 11:43:36 +0800 Message-Id: <1463629417-31330-4-git-send-email-zxq_yx_007@163.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463629417-31330-1-git-send-email-zxq_yx_007@163.com> References: <1463629417-31330-1-git-send-email-zxq_yx_007@163.com> X-CM-TRANSID: C8CowACHS3lrNj1XtX2nDg--.29618S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7urW3ZrWUWr4kCw1fKF15Arb_yoW5Jr1DpF ykJFn8Ary5Ka17XFZrGw1xGF1Dtr1rWw17t34xGws29ay7Gr1Fqrn0vayakFWUXFWkZFy3 Za4UJry7tanxJFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDHUDUUUUU= X-Originating-IP: [118.187.28.42] X-CM-SenderInfo: 520ts5t0bqili6rwjhhfrp/xtbBEhxuxlZXx4eHBgAAsm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.11 Subject: [Qemu-devel] [PATCH v4 3/4] hw/char: QOM'ify lm32_juart.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: pbonzini@redhat.com, michael@walle.cc, edgar.iglesias@gmail.com, agraf@suse.de, peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 * Drop the old SysBus init function * Call qemu_chr_add_handlers in the realize callback * Use qdev chardev prop instead of qemu_char_get_next_serial Signed-off-by: xiaoqiang zhao --- hw/char/lm32_juart.c | 17 ++++++++--------- hw/lm32/lm32.h | 4 ++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/char/lm32_juart.c b/hw/char/lm32_juart.c index 5bf8acf..28c2cf7 100644 --- a/hw/char/lm32_juart.c +++ b/hw/char/lm32_juart.c @@ -114,17 +114,13 @@ static void juart_reset(DeviceState *d) s->jrx = 0; } -static int lm32_juart_init(SysBusDevice *dev) +static void lm32_juart_realize(DeviceState *dev, Error **errp) { LM32JuartState *s = LM32_JUART(dev); - /* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial() */ - s->chr = qemu_char_get_next_serial(); if (s->chr) { qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s); } - - return 0; } static const VMStateDescription vmstate_lm32_juart = { @@ -138,16 +134,19 @@ static const VMStateDescription vmstate_lm32_juart = { } }; +static Property lm32_juart_properties[] = { + DEFINE_PROP_CHR("chardev", LM32JuartState, chr), + DEFINE_PROP_END_OF_LIST(), +}; + static void lm32_juart_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = lm32_juart_init; dc->reset = juart_reset; dc->vmsd = &vmstate_lm32_juart; - /* Reason: init() method uses qemu_char_get_next_serial() */ - dc->cannot_instantiate_with_device_add_yet = true; + dc->props = lm32_juart_properties; + dc->realize = lm32_juart_realize; } static const TypeInfo lm32_juart_info = { diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h index 18aa6fd..3b33ed4 100644 --- a/hw/lm32/lm32.h +++ b/hw/lm32/lm32.h @@ -2,6 +2,7 @@ #define HW_LM32_H 1 #include "hw/char/lm32_juart.h" +#include "sysemu/char.h" static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq) { @@ -19,8 +20,11 @@ static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq) static inline DeviceState *lm32_juart_init(void) { DeviceState *dev; + CharDriverState *chr; + chr = qemu_char_get_next_serial(); dev = qdev_create(NULL, TYPE_LM32_JUART); + qdev_prop_set_chr(dev, "chardev", chr); qdev_init_nofail(dev); return dev;