From patchwork Thu Feb 24 05:01:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1596997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4dXR1rUg; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=CGQPyFQq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=fVf988xB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K414X4bysz9sGL for ; Thu, 24 Feb 2022 16:02:52 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=rwwFwIUldHmhu4cHg1hq4qGqEtErOgkQXSaOI3KVx04=; b=4dXR1rUgPPQvQS SDmajLEtR/CGBhy8rm96YtDiv1gAjY4z9oXhfBe7aY9QnM5oN57Z/vJgOHKSKDw6gZUa/ZixV8TZH W/tea4T10oAiGL09Qa/Cz/pMhlN8aFUXu0SpbVHWmYZqjes/2GP9gmPmg5JHBY8SsDyNKR4lt2PiZ zjiE4c4xs85ckQ5oXVLe+4pJ3xaiep7k4zaPWyspAO1yTMnIlQ2V1sjSEzr0+AUzWNaJ6LVBX8C4v BvrfLzW36A3x0nH7R2wcCCIgn9eLCjX+TdfI0LvMq9VNwGhxn5zH7SWv8lRPPv55iP3qnAjHtp9BY g8KWeHEwaJgvVvjrFRgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nN6Gr-00Gp5K-9R; Thu, 24 Feb 2022 05:02:29 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nN6Gn-00Gp4v-8Q for opensbi@lists.infradead.org; Thu, 24 Feb 2022 05:02:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1645678945; x=1677214945; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=sg/SXKv1B4j1uib1MFq0M9WGswKSV8CgFQFZm+zgqn0=; b=CGQPyFQqbml+ow+YKu/DbZCWVwIVTLxmTZzr+VeU8Lddd31Mg5KCKSRd 0+UFTAkkKtlCWHYi7TYE/cdAMqM/5fEWMEeNeGYZitRFh8Es0Wvz1u93z 0QtYQYKPhYi+WuglqTnrRAR6pTSdIt5KIq9npEmBNW4EPSd8jY7Kc+mru lJs18vEPPJ+5tpfKiZvLxXScLofeVPBE5Uk37gD3QkdiZ2u0B5oZqY81S avFT5qpZ2sffUcPl16MdgEmqAnIwl/Dvq/m5UWulHzQl3O6+jh9hfsUJo cj3niWymnRyEdhFs1ULhKOwHaDS7y/57AA1+4x5pQ2cSTu6Xcy8gt6Z4l w==; X-IronPort-AV: E=Sophos;i="5.88,393,1635177600"; d="scan'208";a="192751298" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Feb 2022 13:02:01 +0800 IronPort-SDR: 62cWNEVxUZBGsyOPjFhL42J3HwR5s6lMEUjE0OU2TVpr+5E1yM+TwMTqYKRoJzh6vHhnpHWI76 8ondxEIlnTyy7Yl+Q2Xbf11F1gNNPlpuHYwmV2tt4d46MV3CNzQIQzPisi1vNIMm35btG7/rrp ZdSt/22mnPpGdSEfSfnyhSpRmGiBV7XawrNEmufVBYWGJaTzeWBEP9/dw0mAFP44f/BGw1M3hQ RCPYe6dRyX9TDwE2AxK8p4VZ+q3LjzdMCfF/VyXy8V9IjgHiY3O8aJB0c9F3lGC6WCTT7jZBDh BOzs9hohAEqM2WmY3ZxdxA/E Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 20:33:31 -0800 IronPort-SDR: o0djwNjytKCU72Dqu1fm70fdwp3/w1EbHi4Q79p2Z9S1fN3znuLuBCUEAQm6SKRNzptckxUDiD esE8qJznTqw+TiU4vVbcAJh6h+umsG+q+YRixDLFbmQ8PO8fw3dfjOVajQneZQ3YBGUggsR9dZ iyzOcpYOeU/mp5mzcp/CdFy3ws6K+GgxWchrx9xqLipYovnldqiM99NlYyBeaA0nrz4xDlFMm0 grWnOsJTwDrtSO4yuJnuB9Hm4ExV57SfUMf9YFuFxaMPIxoQV+GZCOniZ4aBuTYObWIblwYKFn /Ys= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 21:02:00 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4K413X2vZBz1SVnx for ; Wed, 23 Feb 2022 21:02:00 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :x-mailer:message-id:date:subject:to:from; s=dkim; t=1645678919; x=1648270920; bh=sg/SXKv1B4j1uib1MFq0M9WGswKSV8CgFQFZm+zgqn0=; b= fVf988xB4a3m3orGH09iGrgu9OLgYg4Shojh4eyRYIkKz+uutfE2SmrSBhIx3fS+ VrLif3wde7B8ygd2D6Fm0EX92FoqKszhftuo20CcTe+eOFYd0dIkOf/OpSX9JVVp 3FrokiC4R3V3ROdCaStvv+WSFnbnLZRTMtKVyIobTJugP6jP1Ek66aL9grPDLzSO eiaWsM6Ok9nBsiVzN6gvRRoQEarLAMUV7NWxyuYd4vv/1+tgVizshWuu0JyEWPcD qnArL2XRgYt9HDAO29A7uDHNvqfF9DOE0uBlMctYRHrEVG1VVv6NEpaoZVWYlL4w ZLKijaQLeYY4keyyWFAcNA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id GgkyAChEaV_Q for ; Wed, 23 Feb 2022 21:01:59 -0800 (PST) Received: from toolbox.alistair23.me (unknown [10.225.165.99]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4K413S6xYXz1Rvlx; Wed, 23 Feb 2022 21:01:56 -0800 (PST) From: Alistair Francis To: opensbi@lists.infradead.org Cc: alistair23@gmail.com, Alistair Francis , Xiang W Subject: [PATCH v2] lib: utils: serial: Initial commit of xlnx-uartlite Date: Thu, 24 Feb 2022 15:01:46 +1000 Message-Id: <20220224050146.179139-1-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220223_210225_466062_0AE066CC X-CRM114-Status: GOOD ( 21.48 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Alistair Francis Initial commit of the xlnx-uartlite device and FDT support. This was tested by running OpenSBI on a modified QEMU virt machine using the xlnx-uartlite for serial. Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Alistair Francis Initial commit of the xlnx-uartlite device and FDT support. This was tested by running OpenSBI on a modified QEMU virt machine using the xlnx-uartlite for serial. Signed-off-by: Alistair Francis Reviewed-by: Xiang W Reviewed-by: Anup Patel --- include/sbi_utils/fdt/fdt_helper.h | 3 + include/sbi_utils/serial/xlnx_uartlite.h | 16 +++++ lib/utils/fdt/fdt_helper.c | 18 ++++++ lib/utils/serial/fdt_serial.c | 4 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 35 +++++++++++ lib/utils/serial/objects.mk | 2 + lib/utils/serial/xlnx-uartlite.c | 67 +++++++++++++++++++++ 7 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 include/sbi_utils/serial/xlnx_uartlite.h create mode 100644 lib/utils/serial/fdt_serial_xlnx_uartlite.c create mode 100644 lib/utils/serial/xlnx-uartlite.c diff --git a/include/sbi_utils/fdt/fdt_helper.h b/include/sbi_utils/fdt/fdt_helper.h index 1232b26..41ee826 100644 --- a/include/sbi_utils/fdt/fdt_helper.h +++ b/include/sbi_utils/fdt/fdt_helper.h @@ -68,6 +68,9 @@ int fdt_parse_uart8250_node(void *fdt, int nodeoffset, int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, const char *compatible); +int fdt_parse_xlnx_uartlite_node(void *fdt, int nodeoffset, + struct platform_uart_data *uart); + struct aplic_data; int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic); diff --git a/include/sbi_utils/serial/xlnx_uartlite.h b/include/sbi_utils/serial/xlnx_uartlite.h new file mode 100644 index 0000000..45927b7 --- /dev/null +++ b/include/sbi_utils/serial/xlnx_uartlite.h @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 Western Digital Corporation or its affiliates. + * + * Authors: + * Alistair Francis + */ +#ifndef __SERIAL_XLNX_UARTLITE_H__ +#define __SERIAL_XLNX_UARTLITE_H__ + +#include + +int xlnx_uartlite_init(unsigned long base); + +#endif diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index 3a306cb..4dd0602 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -467,6 +467,24 @@ int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, return fdt_parse_uart8250_node(fdt, nodeoffset, uart); } +int fdt_parse_xlnx_uartlite_node(void *fdt, int nodeoffset, + struct platform_uart_data *uart) +{ + int rc; + uint64_t reg_addr, reg_size; + + if (nodeoffset < 0 || !uart || !fdt) + return SBI_ENODEV; + + rc = fdt_get_node_addr_size(fdt, nodeoffset, 0, + ®_addr, ®_size); + if (rc < 0 || !reg_addr || !reg_size) + return SBI_ENODEV; + uart->addr = reg_addr; + + return 0; +} + int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic) { bool child_found; diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index f73d26a..45aea4a 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -19,6 +19,7 @@ extern struct fdt_serial fdt_serial_litex; extern struct fdt_serial fdt_serial_htif; extern struct fdt_serial fdt_serial_shakti; extern struct fdt_serial fdt_serial_gaisler; +extern struct fdt_serial fdt_serial_xlnx_uartlite; static struct fdt_serial *serial_drivers[] = { &fdt_serial_uart8250, @@ -26,7 +27,8 @@ static struct fdt_serial *serial_drivers[] = { &fdt_serial_litex, &fdt_serial_htif, &fdt_serial_shakti, - &fdt_serial_gaisler + &fdt_serial_gaisler, + &fdt_serial_xlnx_uartlite, }; static struct fdt_serial dummy = { diff --git a/lib/utils/serial/fdt_serial_xlnx_uartlite.c b/lib/utils/serial/fdt_serial_xlnx_uartlite.c new file mode 100644 index 0000000..466e16e --- /dev/null +++ b/lib/utils/serial/fdt_serial_xlnx_uartlite.c @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 Western Digital Corporation or its affiliates. + * + * Authors: + * Alistair Francis + */ + +#include +#include +#include + +static int serial_xlnx_uartlite_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc; + struct platform_uart_data uart; + + rc = fdt_parse_xlnx_uartlite_node(fdt, nodeoff, &uart); + if (rc) + return rc; + + return xlnx_uartlite_init(uart.addr); +} + +static const struct fdt_match serial_xlnx_uartlite_match[] = { + { .compatible = "xlnx,xps-uartlite-1.00.a" }, + { }, +}; + +struct fdt_serial fdt_serial_xlnx_uartlite = { + .match_table = serial_xlnx_uartlite_match, + .init = serial_xlnx_uartlite_init, +}; diff --git a/lib/utils/serial/objects.mk b/lib/utils/serial/objects.mk index 4f751ba..4fb9627 100644 --- a/lib/utils/serial/objects.mk +++ b/lib/utils/serial/objects.mk @@ -14,8 +14,10 @@ libsbiutils-objs-y += serial/fdt_serial_shakti.o libsbiutils-objs-y += serial/fdt_serial_sifive.o libsbiutils-objs-y += serial/fdt_serial_litex.o libsbiutils-objs-y += serial/fdt_serial_uart8250.o +libsbiutils-objs-y += serial/fdt_serial_xlnx_uartlite.o libsbiutils-objs-y += serial/gaisler-uart.o libsbiutils-objs-y += serial/shakti-uart.o libsbiutils-objs-y += serial/sifive-uart.o libsbiutils-objs-y += serial/litex-uart.o libsbiutils-objs-y += serial/uart8250.o +libsbiutils-objs-y += serial/xlnx-uartlite.o diff --git a/lib/utils/serial/xlnx-uartlite.c b/lib/utils/serial/xlnx-uartlite.c new file mode 100644 index 0000000..1d8d440 --- /dev/null +++ b/lib/utils/serial/xlnx-uartlite.c @@ -0,0 +1,67 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 Western Digital Corporation or its affiliates. + * + * Authors: + * Alistair Francis + */ + +#include +#include +#include + +/* clang-format off */ + +#define UART_RX_OFFSET 0x00 +#define UART_TX_OFFSET 0x04 +#define UART_STATUS_OFFSET 0x08 +# define UART_STATUS_RXVALID 0x01 +# define UART_STATUS_RXFULL 0x02 +# define UART_STATUS_TXEMPTY 0x04 +# define UART_STATUS_TXFULL 0x08 +# define UART_STATUS_IE 0x10 +# define UART_STATUS_OVERRUN 0x20 +# define UART_STATUS_FRAME 0x40 +# define UART_STATUS_PARITY 0x80 +#define UART_CTRL_OFFSET 0x0C +# define UART_CTRL_RST_TX 0x01 +# define UART_CTRL_RST_RX 0x02 +# define UART_CTRL_IE 0x10 + +/* clang-format on */ + +static volatile char *xlnx_uartlite_base; + +static void xlnx_uartlite_putc(char ch) +{ + while((readb(xlnx_uartlite_base + UART_STATUS_OFFSET) & UART_STATUS_TXFULL)) + ; + + writeb(ch, xlnx_uartlite_base + UART_TX_OFFSET); +} + +static int xlnx_uartlite_getc(void) +{ + u16 status = readb(xlnx_uartlite_base + UART_STATUS_OFFSET); + + if (status & UART_STATUS_RXVALID) + return readb(xlnx_uartlite_base + UART_RX_OFFSET); + + return -1; +} + +static struct sbi_console_device xlnx_uartlite_console = { + .name = "xlnx-uartlite", + .console_putc = xlnx_uartlite_putc, + .console_getc = xlnx_uartlite_getc +}; + +int xlnx_uartlite_init(unsigned long base) +{ + xlnx_uartlite_base = (volatile char *)base; + + sbi_console_set_device(&xlnx_uartlite_console); + + return 0; +}