From patchwork Tue Mar 30 02:59:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guokai Chen X-Patchwork-Id: 1459863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=YI4Y3rhL; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=maSQeXny; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (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 ozlabs.org (Postfix) with ESMTPS id 4F8Z1G1ZwSz9sRK for ; Tue, 30 Mar 2021 13:59:46 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=BbXXml28HeG9oJHBov31y+SOFoaMwscFH/VBAXkRexI=; b=YI4Y3rhLghg0x+XcbPxHre0/6C XACtGHCRN8BKPOvsfvkU/e/9lu21QynKWGWWXsUbeEORTwFk+63Te1bqrGgcmP6BAJy9VXdm6KeUe Ft8uKy+O6esb8piYv+KtXirKHZy9eWixetaaA94UspJmvQiTyb9PimbPdXQKQseMTsYgKR50wyIiN 9hiYE7eK9kROrILaQ6Cu3rhLrTSB9eEawtLPuwFrQMMXMJLl619BZ/+EKcmZXVqR6Pz86nMJvxh3w j77nkylO15yRxUNkxjgmsXO8R9oYsAt3VbbeNLplSF0c310iZja401tvgreNfnLbDqhIi7XRmgq4Q CiA4VWug==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lR4bT-002WWu-VQ; Tue, 30 Mar 2021 02:59:40 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lR4bN-002WUg-8H for opensbi@lists.infradead.org; Tue, 30 Mar 2021 02:59:35 +0000 Received: by mail-pl1-x636.google.com with SMTP id y2so5391524plg.5 for ; Mon, 29 Mar 2021 19:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fzsu6JB1j82FxXi7OkHR/XxChDH0s7UeavmTqM55dNg=; b=maSQeXny5Ml3Y2fGGJB0V9KQ27J+ADyqe2pFaEBxGwJDyo053iRQRrwiB0Ap5Wti/6 eQkeGFauw4QQRHHbZ5O8vLIMpPZsxMSg1HJTxRn9+DaHAyzXcQ9ZRkTDx4biNVkVuVuM /ay1md6hZ7domm26rjjFZ9N4NlUu+pBd23xsu72gtHQrxFcmOkE4kDJyiIRqyHjKSoOT mbJvf3f9OElZvdBhGAxzoygYDfc0rzJOTWGEISr0t7JHkBCSBnYhkwFslMHfDSQ8eM5U KYJoWz8IbWmIw4pbkhQ3R50QzUHzlYxgQ7O1pb02cMqVSEqks48+b9kIHqmTSny+8vvy pnbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fzsu6JB1j82FxXi7OkHR/XxChDH0s7UeavmTqM55dNg=; b=lRZ2qnvFQLYV+GLBsJwL37KVYRdc3Whesrq+WbbwOOJ1NNjxgdbeLaHWwyA3SJLqet b3XQmaNW3+0xpcVy1GlE3oVQNOtSAhRSg43DWh/uV/G157PXtIa7pRCCjaPmYUueiet8 NCvcJAGoy8WruHxw/tKDEjElaKcAbnf5btxPkfkayk/ODKaLHDiEzPlAGaq5F4jFbyXV TLmSduIRMyBg1KEsSFW296paFd6Io6Uan+Ahlecmcq4qTT2bVg9aEY6ht25LoZbdEMwm rojSDFmZ57nglNG61qHDWD5D4R5LVjhXrionUMsbjCh8NYoEf7iki7OvPGHomyHKDEo+ /Jww== X-Gm-Message-State: AOAM532TPIFRbJiZumOWUYnvKEui8KoY1/mJ2CizULr1lg4oAc5OPjXq xavt6QRjjUthEWFLAoy5WAf+g4uqre542P+S X-Google-Smtp-Source: ABdhPJxNclFAFrMe0DxSRE6gBeLSf6XjMooSj4Gzg04/IlDEL/hpL/dtQY4jafKhKFYnkugnUd6qDQ== X-Received: by 2002:a17:90b:1950:: with SMTP id nk16mr2139169pjb.140.1617073167551; Mon, 29 Mar 2021 19:59:27 -0700 (PDT) Received: from localhost.localdomain (ec2-18-136-91-112.ap-southeast-1.compute.amazonaws.com. [18.136.91.112]) by smtp.gmail.com with ESMTPSA id l17sm3582690pgi.66.2021.03.29.19.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 19:59:27 -0700 (PDT) From: Guokai Chen X-Google-Original-From: Guokai Chen To: opensbi@lists.infradead.org Cc: Guokai Chen Subject: [PATCH] lib: utils: Add Xilinx uartlite implementation Date: Tue, 30 Mar 2021 10:59:21 +0800 Message-Id: <20210330025921.1776900-1-chenguokai17@mails.ucas.ac.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210330_035933_570214_2C4362FA X-CRM114-Status: GOOD ( 17.21 ) X-Spam-Score: 0.1 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: Uartlite is a device commonly used on Xilinx platforms. We add OpenSBI support for uartlite so that OpenSBI boots on SoCs that utilize uartlite for output. Signed-off-by: Guokai Chen --- include/sbi_utils/serial/xilinx-uart.h | 20 ++++++++++++ lib/utils/serial/fdt_serial.c | 2 ++ lib/utils/serial/fdt_serial_xilinx.c | 36 ++++++++++++++++++++++ lib/util [...] Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:636 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [chenguokai123[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [chenguokai123[at]gmail.com] -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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Uartlite is a device commonly used on Xilinx platforms. We add OpenSBI support for uartlite so that OpenSBI boots on SoCs that utilize uartlite for output. Signed-off-by: Guokai Chen Reviewed-by: Xiang W --- include/sbi_utils/serial/xilinx-uart.h | 20 ++++++++++++ lib/utils/serial/fdt_serial.c | 2 ++ lib/utils/serial/fdt_serial_xilinx.c | 36 ++++++++++++++++++++++ lib/utils/serial/objects.mk | 2 ++ lib/utils/serial/xilinx-uart.c | 42 ++++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 include/sbi_utils/serial/xilinx-uart.h create mode 100644 lib/utils/serial/fdt_serial_xilinx.c create mode 100644 lib/utils/serial/xilinx-uart.c diff --git a/include/sbi_utils/serial/xilinx-uart.h b/include/sbi_utils/serial/xilinx-uart.h new file mode 100644 index 0000000..e3d667e --- /dev/null +++ b/include/sbi_utils/serial/xilinx-uart.h @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Guokai Chen + * + * This code is based on include/sbi_utils/serial/shakti-uart.h + */ + +#ifndef __SERIAL_XILINX_UART_H__ +#define __SERIAL_XILINX_UART_H__ + +#include + +void xilinx_uart_putc(char ch); + +int xilinx_uart_getc(void); + +int xilinx_uart_init(unsigned long base, u32 in_freq, u32 baudrate); + +#endif diff --git a/lib/utils/serial/fdt_serial.c b/lib/utils/serial/fdt_serial.c index b9ce67e..8671ee3 100644 --- a/lib/utils/serial/fdt_serial.c +++ b/lib/utils/serial/fdt_serial.c @@ -16,12 +16,14 @@ extern struct fdt_serial fdt_serial_uart8250; extern struct fdt_serial fdt_serial_sifive; extern struct fdt_serial fdt_serial_htif; extern struct fdt_serial fdt_serial_shakti; +extern struct fdt_serial fdt_serial_xilinx; static struct fdt_serial *serial_drivers[] = { &fdt_serial_uart8250, &fdt_serial_sifive, &fdt_serial_htif, &fdt_serial_shakti, + &fdt_serial_xilinx, }; static void dummy_putc(char ch) diff --git a/lib/utils/serial/fdt_serial_xilinx.c b/lib/utils/serial/fdt_serial_xilinx.c new file mode 100644 index 0000000..8b52a7d --- /dev/null +++ b/lib/utils/serial/fdt_serial_xilinx.c @@ -0,0 +1,36 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Guokai Chen + * + * This code is based on lib/utils/serial/fdt_serial_shakti.c + */ + +#include +#include +#include + +static int serial_xilinx_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + + int rc; + struct platform_uart_data uart; + // no need to reinvent a wheel + rc = fdt_parse_shakti_uart_node(fdt, nodeoff, &uart); + if (rc) + return rc; + return xilinx_uart_init(uart.addr, uart.freq, uart.baud); +} + +static const struct fdt_match serial_xilinx_match[] = { + { .compatible = "xilinx,uartlite" }, + { }, +}; + +struct fdt_serial fdt_serial_xilinx = { + .match_table = serial_xilinx_match, + .init = serial_xilinx_init, + .getc = xilinx_uart_getc, + .putc = xilinx_uart_putc +}; diff --git a/lib/utils/serial/objects.mk b/lib/utils/serial/objects.mk index c0746f0..6089944 100644 --- a/lib/utils/serial/objects.mk +++ b/lib/utils/serial/objects.mk @@ -10,8 +10,10 @@ libsbiutils-objs-y += serial/fdt_serial.o libsbiutils-objs-y += serial/fdt_serial_htif.o libsbiutils-objs-y += serial/fdt_serial_shakti.o +libsbiutils-objs-y += serial/fdt_serial_xilinx.o libsbiutils-objs-y += serial/fdt_serial_sifive.o libsbiutils-objs-y += serial/fdt_serial_uart8250.o libsbiutils-objs-y += serial/shakti-uart.o +libsbiutils-objs-y += serial/xilinx-uart.o libsbiutils-objs-y += serial/sifive-uart.o libsbiutils-objs-y += serial/uart8250.o diff --git a/lib/utils/serial/xilinx-uart.c b/lib/utils/serial/xilinx-uart.c new file mode 100644 index 0000000..ea32d47 --- /dev/null +++ b/lib/utils/serial/xilinx-uart.c @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Guokai Chen + * + * This code is based on lib/utils/serial/xilinx-uart.c + */ + +#include +#include +#include + +#define REG_TX 0x04 +#define REG_RX 0x00 +#define REG_STATUS 0x08 +#define REG_CONTROL 0x0C + +#define UART_TX_FULL (1<<0x3) +#define UART_RX_VALID (1<<0x0) + +static volatile void *uart_base; + +void xilinx_uart_putc(char ch) +{ + while((readb(uart_base + REG_STATUS) & UART_TX_FULL)) + ; + writeb(ch, uart_base + REG_TX); +} + +int xilinx_uart_getc(void) +{ + u16 status = readb(uart_base + REG_STATUS); + if (status & UART_RX_VALID) + return readb(uart_base + REG_RX); + return -1; +} + +int xilinx_uart_init(unsigned long base, u32 in_freq, u32 baudrate) +{ + uart_base = (volatile void *)base; + return 0; +}