From nobody Thu May 2 14:33:09 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1622372090; cv=none; d=zohomail.com; s=zohoarc; b=Sxv4CKi4xcrAh0eCsRTeUvIzimF8RuNAN4uBv2XJ1evN+CLw5bwMTCwU+r3sAvGq79iOwMoDFlc1rG0nJMwViGIJ79QSy01ucFKkM4AcqcRXeXlxX1YKQYIc0TRL76FHc+SzyBM44g+aJRAPw9enoV/mIBPqjpOZ3LStGKB3dOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622372090; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CpmDxxxQw54UxyXP00z4yoCWjDmkpwmExjscuG+5mrs=; b=LzKqfsmWpUZdil5TPeBY+cKBhIeqydZuRSOhGLpt6hjFe2v6NErdrb8d5zqAVwWYsPIgx1arn+sB64s9VSexJmUEMh8FhkccvdeO/Ae/SdpbUlbY0VP9RfPXhbKaPo7jRg6M/8pRzrk3u+TrmPTq1dHzhdj+pjHKzQyxCQzP+3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622372090559852.3659279790156; Sun, 30 May 2021 03:54:50 -0700 (PDT) Received: from localhost ([::1]:37268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnJ5l-0004Ui-Ex for importer2@patchew.org; Sun, 30 May 2021 06:54:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnJ0p-0002IP-0T; Sun, 30 May 2021 06:49:43 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:35090) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnJ0m-0001LE-NM; Sun, 30 May 2021 06:49:42 -0400 Received: from fornax.fritz.box (b2b-109-90-5-113.unitymedia.biz [109.90.5.113]) by beetle.greensocs.com (Postfix) with ESMTPSA id D9C7C2078C; Sun, 30 May 2021 10:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1622371774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CpmDxxxQw54UxyXP00z4yoCWjDmkpwmExjscuG+5mrs=; b=MPmzk2ksuOHEgzKtmZoaAAIGm7kDg3riUQUGQYeeY4UUdWcKT9l95eN+XJtDMeDIprR4zo DHA+/WdLj42bKcOv4Mp+IGj/iucOdIspx4O1XeaVzdkzbXbRxgM5p6ajBew5+P3MWh82bS nAWitSmMA2WlGlWnUyCSlBc5NF46e6I= From: =?UTF-8?q?Lukas=20J=C3=BCnger?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] hw/char: sifive_uart Date: Sun, 30 May 2021 12:49:21 +0200 Message-Id: <20210530104922.466175-2-lukas.juenger@greensocs.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210530104922.466175-1-lukas.juenger@greensocs.com> References: <20210530104922.466175-1-lukas.juenger@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=lukas.juenger@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, bin.meng@windriver.com, mark.burton@greensocs.com, marcandre.lureau@redhat.com, palmer@dabbelt.com, pbonzini@redhat.com, alistair.francis@wdc.com, =?UTF-8?q?Lukas=20J=C3=BCnger?= , luc.michel@greensocs.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Make function names consistent Signed-off-by: Lukas J=C3=BCnger Reviewed-by: Bin Meng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/char/sifive_uart.c | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c index fe12666789..101d68d8cf 100644 --- a/hw/char/sifive_uart.c +++ b/hw/char/sifive_uart.c @@ -31,7 +31,7 @@ */ =20 /* Returns the state of the IP (interrupt pending) register */ -static uint64_t uart_ip(SiFiveUARTState *s) +static uint64_t sifive_uart_ip(SiFiveUARTState *s) { uint64_t ret =3D 0; =20 @@ -48,7 +48,7 @@ static uint64_t uart_ip(SiFiveUARTState *s) return ret; } =20 -static void update_irq(SiFiveUARTState *s) +static void sifive_uart_update_irq(SiFiveUARTState *s) { int cond =3D 0; if ((s->ie & SIFIVE_UART_IE_TXWM) || @@ -63,7 +63,7 @@ static void update_irq(SiFiveUARTState *s) } =20 static uint64_t -uart_read(void *opaque, hwaddr addr, unsigned int size) +sifive_uart_read(void *opaque, hwaddr addr, unsigned int size) { SiFiveUARTState *s =3D opaque; unsigned char r; @@ -74,7 +74,7 @@ uart_read(void *opaque, hwaddr addr, unsigned int size) memmove(s->rx_fifo, s->rx_fifo + 1, s->rx_fifo_len - 1); s->rx_fifo_len--; qemu_chr_fe_accept_input(&s->chr); - update_irq(s); + sifive_uart_update_irq(s); return r; } return 0x80000000; @@ -84,7 +84,7 @@ uart_read(void *opaque, hwaddr addr, unsigned int size) case SIFIVE_UART_IE: return s->ie; case SIFIVE_UART_IP: - return uart_ip(s); + return sifive_uart_ip(s); case SIFIVE_UART_TXCTRL: return s->txctrl; case SIFIVE_UART_RXCTRL: @@ -99,8 +99,8 @@ uart_read(void *opaque, hwaddr addr, unsigned int size) } =20 static void -uart_write(void *opaque, hwaddr addr, - uint64_t val64, unsigned int size) +sifive_uart_write(void *opaque, hwaddr addr, + uint64_t val64, unsigned int size) { SiFiveUARTState *s =3D opaque; uint32_t value =3D val64; @@ -109,11 +109,11 @@ uart_write(void *opaque, hwaddr addr, switch (addr) { case SIFIVE_UART_TXFIFO: qemu_chr_fe_write(&s->chr, &ch, 1); - update_irq(s); + sifive_uart_update_irq(s); return; case SIFIVE_UART_IE: s->ie =3D val64; - update_irq(s); + sifive_uart_update_irq(s); return; case SIFIVE_UART_TXCTRL: s->txctrl =3D val64; @@ -129,9 +129,9 @@ uart_write(void *opaque, hwaddr addr, __func__, (int)addr, (int)value); } =20 -static const MemoryRegionOps uart_ops =3D { - .read =3D uart_read, - .write =3D uart_write, +static const MemoryRegionOps sifive_uart_ops =3D { + .read =3D sifive_uart_read, + .write =3D sifive_uart_write, .endianness =3D DEVICE_NATIVE_ENDIAN, .valid =3D { .min_access_size =3D 4, @@ -139,7 +139,7 @@ static const MemoryRegionOps uart_ops =3D { } }; =20 -static void uart_rx(void *opaque, const uint8_t *buf, int size) +static void sifive_uart_rx(void *opaque, const uint8_t *buf, int size) { SiFiveUARTState *s =3D opaque; =20 @@ -150,26 +150,26 @@ static void uart_rx(void *opaque, const uint8_t *buf,= int size) } s->rx_fifo[s->rx_fifo_len++] =3D *buf; =20 - update_irq(s); + sifive_uart_update_irq(s); } =20 -static int uart_can_rx(void *opaque) +static int sifive_uart_can_rx(void *opaque) { SiFiveUARTState *s =3D opaque; =20 return s->rx_fifo_len < sizeof(s->rx_fifo); } =20 -static void uart_event(void *opaque, QEMUChrEvent event) +static void sifive_uart_event(void *opaque, QEMUChrEvent event) { } =20 -static int uart_be_change(void *opaque) +static int sifive_uart_be_change(void *opaque) { SiFiveUARTState *s =3D opaque; =20 - qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx, uart_event, - uart_be_change, s, NULL, true); + qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx, + sifive_uart_event, sifive_uart_be_change, s, NULL, true); =20 return 0; } @@ -183,9 +183,9 @@ SiFiveUARTState *sifive_uart_create(MemoryRegion *addre= ss_space, hwaddr base, SiFiveUARTState *s =3D g_malloc0(sizeof(SiFiveUARTState)); s->irq =3D irq; qemu_chr_fe_init(&s->chr, chr, &error_abort); - qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx, uart_event, - uart_be_change, s, NULL, true); - memory_region_init_io(&s->mmio, NULL, &uart_ops, s, + qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx, + sifive_uart_event, sifive_uart_be_change, s, NULL, true); + memory_region_init_io(&s->mmio, NULL, &sifive_uart_ops, s, TYPE_SIFIVE_UART, SIFIVE_UART_MAX); memory_region_add_subregion(address_space, base, &s->mmio); return s; --=20 2.31.1 From nobody Thu May 2 14:33:09 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1622372093; cv=none; d=zohomail.com; s=zohoarc; b=lJ+qpeAoX5YyLcVNq1RpDB0oEh8ey1FBguYvWI3WAwzCldUbVWQZf6EhcBwAkvLEfLUorxyOFCi88yPb3mdRI8gFR5pza+PKhdIJJ5SCqpgDDnoLXVQtv5ZOcao9WUiLyjW3R9BuyhvKIJgsURR2ZLk91tGwN3HW6eA7Zz+Q2ZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622372093; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kdEHYRbQuDE0es/AbLBFsfZ7HIPr78oILEQpaVGqivw=; b=XEZyDFaOvj3McCNMmLU+sIPmBO+yAtM1aKqoZFwtdIwMu0tvmgXu/jlAlg0tmZuE10rqgy5mlqxSG527Z58vOFjQfdKw9Cdf9Ndl9nwMjeTWrQY7boWN6/dcuIxnCLUg34UzMNBnJpkjF3DZ2AvI0sxEYEHdrIdyZLv5CrP46+A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622372093170555.7000920457799; Sun, 30 May 2021 03:54:53 -0700 (PDT) Received: from localhost ([::1]:37304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnJ5o-0004WE-1l for importer2@patchew.org; Sun, 30 May 2021 06:54:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnJ0q-0002It-9n; Sun, 30 May 2021 06:49:44 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:35112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnJ0m-0001MU-Uh; Sun, 30 May 2021 06:49:43 -0400 Received: from fornax.fritz.box (b2b-109-90-5-113.unitymedia.biz [109.90.5.113]) by beetle.greensocs.com (Postfix) with ESMTPSA id 299F42089E; Sun, 30 May 2021 10:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1622371775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kdEHYRbQuDE0es/AbLBFsfZ7HIPr78oILEQpaVGqivw=; b=KAFd5/QP3AzPGOJjtxR2Q0xo0r6E4v1s/2gAgcEsUq8OmueyUvAC79qLhwFIjzHrBKWGxb 5dpS+u8dYsireJ13Y9H5pYGQK5vHiq94XgqDVwYM+RzaPF3BWWxOpcbVKXT9Paoqmoev88 fUqIBpiRiBI7haEz/UjG5rOfEnt6WZ4= From: =?UTF-8?q?Lukas=20J=C3=BCnger?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] hw/char: sifive_uart Date: Sun, 30 May 2021 12:49:22 +0200 Message-Id: <20210530104922.466175-3-lukas.juenger@greensocs.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210530104922.466175-1-lukas.juenger@greensocs.com> References: <20210530104922.466175-1-lukas.juenger@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.135.226.135; envelope-from=lukas.juenger@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, bin.meng@windriver.com, mark.burton@greensocs.com, marcandre.lureau@redhat.com, palmer@dabbelt.com, pbonzini@redhat.com, alistair.francis@wdc.com, =?UTF-8?q?Lukas=20J=C3=BCnger?= , luc.michel@greensocs.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) QOMify sifive_uart model Signed-off-by: Lukas J=C3=BCnger Reviewed-by: Bin Meng --- include/hw/char/sifive_uart.h | 6 +-- hw/char/sifive_uart.c | 72 ++++++++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/include/hw/char/sifive_uart.h b/include/hw/char/sifive_uart.h index 3e962be659..45d66b1db5 100644 --- a/include/hw/char/sifive_uart.h +++ b/include/hw/char/sifive_uart.h @@ -21,6 +21,7 @@ #define HW_SIFIVE_UART_H =20 #include "chardev/char-fe.h" +#include "hw/qdev-properties.h" #include "hw/sysbus.h" #include "qom/object.h" =20 @@ -51,10 +52,7 @@ enum { #define SIFIVE_UART_GET_RXCNT(rxctrl) ((rxctrl >> 16) & 0x7) =20 #define TYPE_SIFIVE_UART "riscv.sifive.uart" - -typedef struct SiFiveUARTState SiFiveUARTState; -DECLARE_INSTANCE_CHECKER(SiFiveUARTState, SIFIVE_UART, - TYPE_SIFIVE_UART) +OBJECT_DECLARE_SIMPLE_TYPE(SiFiveUARTState, SIFIVE_UART) =20 struct SiFiveUARTState { /*< private >*/ diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c index 101d68d8cf..7f0ee8d77d 100644 --- a/hw/char/sifive_uart.c +++ b/hw/char/sifive_uart.c @@ -23,6 +23,7 @@ #include "chardev/char-fe.h" #include "hw/irq.h" #include "hw/char/sifive_uart.h" +#include "hw/qdev-properties-system.h" =20 /* * Not yet implemented: @@ -174,19 +175,72 @@ static int sifive_uart_be_change(void *opaque) return 0; } =20 +static Property sifive_uart_properties[] =3D { + DEFINE_PROP_CHR("chardev", SiFiveUARTState, chr), + DEFINE_PROP_END_OF_LIST(), +}; + +static void sifive_uart_init(Object *obj) +{ + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + SiFiveUARTState *s =3D SIFIVE_UART(obj); + + memory_region_init_io(&s->mmio, OBJECT(s), &sifive_uart_ops, s, + TYPE_SIFIVE_UART, SIFIVE_UART_MAX); + sysbus_init_mmio(sbd, &s->mmio); + sysbus_init_irq(sbd, &s->irq); +} + +static void sifive_uart_realize(DeviceState *dev, Error **errp) +{ + SiFiveUARTState *s =3D SIFIVE_UART(dev); + + qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx, + sifive_uart_event, sifive_uart_be_change, s, NULL, true); + +} + +static void sifive_uart_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D sifive_uart_realize; + device_class_set_props(dc, sifive_uart_properties); +} + +static const TypeInfo sifive_uart_info =3D { + .name =3D TYPE_SIFIVE_UART, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(SiFiveUARTState), + .instance_init =3D sifive_uart_init, + .class_init =3D sifive_uart_class_init, +}; + +static void sifive_uart_register_types(void) +{ + type_register_static(&sifive_uart_info); +} + +type_init(sifive_uart_register_types) + /* * Create UART device. */ SiFiveUARTState *sifive_uart_create(MemoryRegion *address_space, hwaddr ba= se, Chardev *chr, qemu_irq irq) { - SiFiveUARTState *s =3D g_malloc0(sizeof(SiFiveUARTState)); - s->irq =3D irq; - qemu_chr_fe_init(&s->chr, chr, &error_abort); - qemu_chr_fe_set_handlers(&s->chr, sifive_uart_can_rx, sifive_uart_rx, - sifive_uart_event, sifive_uart_be_change, s, NULL, true); - memory_region_init_io(&s->mmio, NULL, &sifive_uart_ops, s, - TYPE_SIFIVE_UART, SIFIVE_UART_MAX); - memory_region_add_subregion(address_space, base, &s->mmio); - return s; + DeviceState *dev; + SysBusDevice *s; + SiFiveUARTState *r; + + dev =3D qdev_new("riscv.sifive.uart"); + s =3D SYS_BUS_DEVICE(dev); + qdev_prop_set_chr(dev, "chardev", chr); + sysbus_realize_and_unref(s, &error_fatal); + memory_region_add_subregion(address_space, base, + sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, irq); + + r =3D SIFIVE_UART(dev); + return r; } --=20 2.31.1