From patchwork Sat Jun 4 08:14:24 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: 9154547 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 9951060221 for ; Sat, 4 Jun 2016 08:19:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8408426907 for ; Sat, 4 Jun 2016 08:19:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76DEE2832B; Sat, 4 Jun 2016 08:19:14 +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 0C87A26907 for ; Sat, 4 Jun 2016 08:19:14 +0000 (UTC) Received: from localhost ([::1]:59868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b96nZ-0004uI-3A for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Jun 2016 04:19:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b96jr-0001Ae-FR for qemu-devel@nongnu.org; Sat, 04 Jun 2016 04:15:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b96jf-00024L-3C for qemu-devel@nongnu.org; Sat, 04 Jun 2016 04:15:23 -0400 Received: from m12-18.163.com ([220.181.12.18]:58674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b96jd-0001wy-2i; Sat, 04 Jun 2016 04:15:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=YsZVXlOUZ+ztfSI8B7 joL0tRvaANFUzp2U8+YxTucAY=; b=awNJCpVQ/JzcOUMZdwVCUMur5O2Swa9TaE /staOdArQ5NrQn9SGf2KiJm6qO1iQ6j/hvYVtrfpMPJEliC0G/+F85TCYHj7aG/v UnEYos70jcFGyjCuPURUj94QGNBzjm8j1i3rlVf7QvkkBx9Mq1RzO+zuvZANS1q0 3WGtiA0ss= Received: from debian.lan (unknown [114.111.167.200]) by smtp14 (Coremail) with SMTP id EsCowECpfUbfjVJXKXU9AA--.28040S7; Sat, 04 Jun 2016 16:14:36 +0800 (CST) From: xiaoqiang zhao To: qemu-devel@nongnu.org Date: Sat, 4 Jun 2016 16:14:24 +0800 Message-Id: <1465028065-5855-6-git-send-email-zxq_yx_007@163.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465028065-5855-1-git-send-email-zxq_yx_007@163.com> References: <1465028065-5855-1-git-send-email-zxq_yx_007@163.com> X-CM-TRANSID: EsCowECpfUbfjVJXKXU9AA--.28040S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxZF1rurWfCr4DGw45Ww18AFb_yoWrXF1UpF WkG3Z8Gr9rJFy7JayfAr129Fs8GF97ur1jvryxGr10vw13KrWFy3Z8Ka10yrW3XrWxZ34U ZrZ8WryDGF12vrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bYEfrUUUUU= X-Originating-IP: [114.111.167.200] X-CM-SenderInfo: 520ts5t0bqili6rwjhhfrp/1tbiqAx+xlc64Ky0-QAAs0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 220.181.12.18 Subject: [Qemu-devel] [PATCH v2 5/6] hw/char: QOM'ify xilinx_uartlite model 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: robh@kernel.org, peter.maydell@linaro.org, crosthwaite.peter@gmail.com, armbru@redhat.com, alistair.francis@xilinx.com, qemu-arm@nongnu.org, antonynpavlov@gmail.com, pbonzini@redhat.com, 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 * drop qemu_char_get_next_serial and use chardev prop * create xilinx_uartlite_create wrapper function to create xilinx_uartlite device * change affected board code to use the new way Signed-off-by: xiaoqiang zhao --- hw/char/xilinx_uartlite.c | 10 +++++---- hw/microblaze/petalogix_s3adsp1800_mmu.c | 5 +++-- include/hw/char/xilinx_uartlite.h | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 include/hw/char/xilinx_uartlite.h diff --git a/hw/char/xilinx_uartlite.c b/hw/char/xilinx_uartlite.c index 911af4a..4847efb 100644 --- a/hw/char/xilinx_uartlite.c +++ b/hw/char/xilinx_uartlite.c @@ -172,6 +172,11 @@ static const MemoryRegionOps uart_ops = { } }; +static Property xilinx_uartlite_properties[] = { + DEFINE_PROP_CHR("chardev", XilinxUARTLite, chr), + DEFINE_PROP_END_OF_LIST(), +}; + static void uart_rx(void *opaque, const uint8_t *buf, int size) { XilinxUARTLite *s = opaque; @@ -206,8 +211,6 @@ static void xilinx_uartlite_realize(DeviceState *dev, Error **errp) { XilinxUARTLite *s = XILINX_UARTLITE(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, uart_can_rx, uart_rx, uart_event, s); } @@ -229,8 +232,7 @@ static void xilinx_uartlite_class_init(ObjectClass *klass, void *data) dc->reset = xilinx_uartlite_reset; dc->realize = xilinx_uartlite_realize; - /* Reason: realize() method uses qemu_char_get_next_serial() */ - dc->cannot_instantiate_with_device_add_yet = true; + dc->props = xilinx_uartlite_properties; } static const TypeInfo xilinx_uartlite_info = { diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c index f821e1c..423bcd7 100644 --- a/hw/microblaze/petalogix_s3adsp1800_mmu.c +++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c @@ -36,6 +36,7 @@ #include "hw/boards.h" #include "sysemu/block-backend.h" #include "exec/address-spaces.h" +#include "hw/char/xilinx_uartlite.h" #include "boot.h" @@ -103,8 +104,8 @@ petalogix_s3adsp1800_init(MachineState *machine) irq[i] = qdev_get_gpio_in(dev, i); } - sysbus_create_simple("xlnx.xps-uartlite", UARTLITE_BASEADDR, - irq[UARTLITE_IRQ]); + xilinx_uartlite_create(UARTLITE_BASEADDR, irq[UARTLITE_IRQ], + serial_hds[0]); /* 2 timers at irq 2 @ 62 Mhz. */ dev = qdev_create(NULL, "xlnx.xps-timer"); diff --git a/include/hw/char/xilinx_uartlite.h b/include/hw/char/xilinx_uartlite.h new file mode 100644 index 0000000..8b4fc54 --- /dev/null +++ b/include/hw/char/xilinx_uartlite.h @@ -0,0 +1,35 @@ +/* + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef XILINX_UARTLITE_H +#define XILINX_UARTLITE_H + +static inline DeviceState *xilinx_uartlite_create(hwaddr addr, + qemu_irq irq, + CharDriverState *chr) +{ + DeviceState *dev; + SysBusDevice *s; + + dev = qdev_create(NULL, "xlnx.xps-uartlite"); + s = SYS_BUS_DEVICE(dev); + qdev_prop_set_chr(dev, "chardev", chr); + qdev_init_nofail(dev); + sysbus_mmio_map(s, 0, addr); + sysbus_connect_irq(s, 0, irq); + + return dev; +} + +#endif