From nobody Tue Dec 30 07:38:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 611EBC47071 for ; Sat, 18 Nov 2023 03:39:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346432AbjKRDjl (ORCPT ); Fri, 17 Nov 2023 22:39:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbjKRDji (ORCPT ); Fri, 17 Nov 2023 22:39:38 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B36CD72 for ; Fri, 17 Nov 2023 19:39:35 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2802d218242so2299001a91.1 for ; Fri, 17 Nov 2023 19:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1700278775; x=1700883575; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rUH3sN/jANNMbAvxiLE+FR6QScUT3piYF3Fp6n0y2EI=; b=JB96zYtXcwC6xFXzykj3V+MKnG4qCBTaBH+IWV8wFYK+dc1sfUyf2W5SSK3oVVny9F VWQlOetAR8ENiS/FdhGNOib5JBWu5MUNpcYAQbDDPJyRDc3oi67JIFGmZQUIw55qWTvj diYd3f6YOpdms8avA8DNQqtu33VHTLeJmXVqLkJTJjRFT5SoDrrGkC1BjqEgOzU7edWy WeRGJopCYaraDpmSs/HI2mBoeOWGD3YS0ZNCbaFueMu8TLlPBwFRtpaYlP7ksJV6zhs2 SmzO1hLRBChDXvwQIzmuo9+USt/t3ZXVXZxEK3FelS2NBUaefga+W9NyG+Fk49A541IZ Bvkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700278775; x=1700883575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rUH3sN/jANNMbAvxiLE+FR6QScUT3piYF3Fp6n0y2EI=; b=U6EnOQEj/MnKVxOpMsELjmlbRWHTehQVodYR7g1uguQCOicDJ0klnhcNFZqgFHuRM4 h3GvpW84ez/YFjnKgcu3qaaZLHefK8BUj+8dtnRX7TGUuBIqlsmzhli4DNuBpy/zf72i i8B4uqzadP71qnuSUhNvUGdx2WzBnMYkQrh6L1GC9ggFKET4wB0IdqDBsGFeC44/gnHC KBveKJDyRJssIN3FeSoNuP7MprflVz773EVfc1dDrR2REo41vdsmOOJZqyk2n+I4lSca 2C8TCHQS2r2ZlbgQ5PZ8S7ipO0vxh3TMPxQkW4PTza4FVlp4y1kvr6CRtBMm+OfF8+Ft BwJQ== X-Gm-Message-State: AOJu0YzOANuAPy8bT5syvm3EQMDuq9KYOEbIkwNvNGUzRGMyc2tVEVdd bTE7KaGxo4p1b3E7L2c0pR6erg== X-Google-Smtp-Source: AGHT+IFL/vhOEv9SFr5vahVonbYDfe/rMF/KgPJfyv64wzi2WyOjQ+a4xtQ3OlsfO5O9XMpJ2UxSgA== X-Received: by 2002:a17:90b:3b45:b0:280:29cd:4802 with SMTP id ot5-20020a17090b3b4500b0028029cd4802mr1636773pjb.3.1700278774537; Fri, 17 Nov 2023 19:39:34 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.108]) by smtp.gmail.com with ESMTPSA id cz8-20020a17090ad44800b00280fcbbe774sm2053823pjb.10.2023.11.17.19.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:33 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v4 1/5] RISC-V: Add stubs for sbi_console_putchar/getchar() Date: Sat, 18 Nov 2023 09:08:55 +0530 Message-Id: <20231118033859.726692-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118033859.726692-1-apatel@ventanamicro.com> References: <20231118033859.726692-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The functions sbi_console_putchar() and sbi_console_getchar() are not defined when CONFIG_RISCV_SBI_V01 is disabled so let us add stub of these functions to avoid "#ifdef" on user side. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- arch/riscv/include/asm/sbi.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 0892f4421bc4..66f3933c14f6 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -271,8 +271,13 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned lon= g arg0, unsigned long arg3, unsigned long arg4, unsigned long arg5); =20 +#ifdef CONFIG_RISCV_SBI_V01 void sbi_console_putchar(int ch); int sbi_console_getchar(void); +#else +static inline void sbi_console_putchar(int ch) { } +static inline int sbi_console_getchar(void) { return -ENOENT; } +#endif long sbi_get_mvendorid(void); long sbi_get_marchid(void); long sbi_get_mimpid(void); --=20 2.34.1 From nobody Tue Dec 30 07:38:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD79FC47071 for ; Sat, 18 Nov 2023 03:39:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346441AbjKRDjs (ORCPT ); Fri, 17 Nov 2023 22:39:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346435AbjKRDjl (ORCPT ); Fri, 17 Nov 2023 22:39:41 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0CA8D7E for ; Fri, 17 Nov 2023 19:39:38 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-28398d6c9f3so1206963a91.0 for ; Fri, 17 Nov 2023 19:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1700278778; x=1700883578; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lUknxwWYXkt9C2M9pb/Z3CUGPfJIBZQMgmHAhH/xaf8=; b=IHinz0gC9R+tzPymiH/JYDJhkA1wbhQAUTXtmV8pyHSzPlZAcwIeDTK5Fi0FYCDuFY BPf7XkCaBf4DpJeDsDjEEyjA6mxsD7olqrLUy63PqC8wKgBRbjQhJ+U3dC0EXS5Dj/6n OHsJFVQFL1HfPjTBhISf7TH4K/0T1eJX1ZuZn/VUggTkINKUWUuljbxT9/E39owHOTJl 6wcinfSZw9yz+cAX28qCKoGn54+4TpNa0HwpYgtOpgNnKwRWJPRiJA5lF8du9u/jpLeN id4pvq9Ju4CZfzrqJZQ1tBRXiELsF4fxDCVm/h798hhGQo6dFnUJx2fbUclpc/0jQjxv e69w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700278778; x=1700883578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUknxwWYXkt9C2M9pb/Z3CUGPfJIBZQMgmHAhH/xaf8=; b=ZuHqPJdCvH0HHEtQ7u7Ieaa4HkxhyyegpOpuyTlszZ5g0OsBBqjSxcSNKEe6ywTh1X pktni5Aq4QFMvW1Y5DFlQeH6BTjkJ23GnwUC51FbC5Y+bypmDivLLdvLqNCHw9gPLEAW 0FHOYCZdbkrJCvNClZc+OtbhSPCp6HYWPwARdjAs2h0M9RHAWuSJkhed/KQQoQ+3mQMs SJCs8p0KhQFCHzaju1wNyG76tiWqMXk6LcRG7KSXEPz072dxrNx8HafDc/ngWTyX/bOG Leq0AqGRbWY/Na6QpSexnJTNVXxw/+3JjBGCZ3I3vWFQPX6k9XdXZNVjjdQMBxRtmYrf L/dA== X-Gm-Message-State: AOJu0YxLlZDfZ63SxzT/ww9zDChs5OSu03K3aG/Aw90/lbrovWpysuvf UzMh+d5Gb8jjIm9M1URlIgpjPQ== X-Google-Smtp-Source: AGHT+IGETYioNALUjNhz6JIS+eO7DP/jwO69X1kH6NZN6oXPpq2gEGKYxgt01iCN0WIJkFYPAiCO9A== X-Received: by 2002:a17:90b:1e02:b0:27d:7887:ddc5 with SMTP id pg2-20020a17090b1e0200b0027d7887ddc5mr1729418pjb.32.1700278778017; Fri, 17 Nov 2023 19:39:38 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.108]) by smtp.gmail.com with ESMTPSA id cz8-20020a17090ad44800b00280fcbbe774sm2053823pjb.10.2023.11.17.19.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:37 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v4 2/5] RISC-V: Add SBI debug console helper routines Date: Sat, 18 Nov 2023 09:08:56 +0530 Message-Id: <20231118033859.726692-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118033859.726692-1-apatel@ventanamicro.com> References: <20231118033859.726692-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let us provide SBI debug console helper routines which can be shared by serial/earlycon-riscv-sbi.c and hvc/hvc_riscv_sbi.c. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- arch/riscv/include/asm/sbi.h | 5 +++++ arch/riscv/kernel/sbi.c | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 66f3933c14f6..ee7aef5f6233 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -334,6 +334,11 @@ static inline unsigned long sbi_mk_version(unsigned lo= ng major, } =20 int sbi_err_map_linux_errno(int err); + +extern bool sbi_debug_console_available; +int sbi_debug_console_write(unsigned int num_bytes, phys_addr_t base_addr); +int sbi_debug_console_read(unsigned int num_bytes, phys_addr_t base_addr); + #else /* CONFIG_RISCV_SBI */ static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { ret= urn -1; } static inline void sbi_init(void) {} diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 5a62ed1da453..73a9c22c3945 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -571,6 +571,44 @@ long sbi_get_mimpid(void) } EXPORT_SYMBOL_GPL(sbi_get_mimpid); =20 +bool sbi_debug_console_available; + +int sbi_debug_console_write(unsigned int num_bytes, phys_addr_t base_addr) +{ + struct sbiret ret; + + if (!sbi_debug_console_available) + return -EOPNOTSUPP; + + if (IS_ENABLED(CONFIG_32BIT)) + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, + num_bytes, lower_32_bits(base_addr), + upper_32_bits(base_addr), 0, 0, 0); + else + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, + num_bytes, base_addr, 0, 0, 0, 0); + + return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value; +} + +int sbi_debug_console_read(unsigned int num_bytes, phys_addr_t base_addr) +{ + struct sbiret ret; + + if (!sbi_debug_console_available) + return -EOPNOTSUPP; + + if (IS_ENABLED(CONFIG_32BIT)) + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ, + num_bytes, lower_32_bits(base_addr), + upper_32_bits(base_addr), 0, 0, 0); + else + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ, + num_bytes, base_addr, 0, 0, 0, 0); + + return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value; +} + void __init sbi_init(void) { int ret; @@ -612,6 +650,11 @@ void __init sbi_init(void) sbi_srst_reboot_nb.priority =3D 192; register_restart_handler(&sbi_srst_reboot_nb); } + if ((sbi_spec_version >=3D sbi_mk_version(2, 0)) && + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { + pr_info("SBI DBCN extension detected\n"); + sbi_debug_console_available =3D true; + } } else { __sbi_set_timer =3D __sbi_set_timer_v01; __sbi_send_ipi =3D __sbi_send_ipi_v01; --=20 2.34.1 From nobody Tue Dec 30 07:38:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E417DC5AE4A for ; Sat, 18 Nov 2023 03:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346456AbjKRDjz (ORCPT ); Fri, 17 Nov 2023 22:39:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346461AbjKRDjt (ORCPT ); Fri, 17 Nov 2023 22:39:49 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79D51739 for ; Fri, 17 Nov 2023 19:39:42 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-28003daaaa6so2214176a91.0 for ; Fri, 17 Nov 2023 19:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1700278782; x=1700883582; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ii/r8hzimL/XtavRWrcGkJgKEnLeFuQkfTAUm70Wb2A=; b=L7tk3XsPAJfBJui+7mljsx5jHduoziR5VxXsq4WSWgLyVhrKSG2R6kpLmbGgZLDnNB wqftKeb/NTcH74tLHPrV09IVx1PWAzvf8VDD4/9eQxKPe5DTpT4gqczLHCpkIUIFsxhw dQIKqTmDJK5dWM+uzcmcdnD7gB2FBY3Qu5mYbVoniYAqV0/DYD6syD+9naE1EE7gzz+I ZnYSZy7HvptS1saW9ulyRYdjhZiw58NDKM/oDZxJ3U5/JQqgFWGJOwOuelcuS18t5qoT E92fLTMkKAwAc7mCF8/bsREFCPb0kYIWAzR3b6pkAChA4yr5Msvd9uzTuKf7R9qFPLAt DNcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700278782; x=1700883582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ii/r8hzimL/XtavRWrcGkJgKEnLeFuQkfTAUm70Wb2A=; b=gROLCU5wwnb/xsfPLOrFgln94KK9rwphHUWqVi+NP+doYHC4galIvO0XQUkZVOio5G qcMA4ssAtRGO4B4t5yNhiaFd7jnmZLGKfuGw4Sv08x5SGbn4Hv372bB5Pdoqp4NuolwF iFVBoVx0uhQtYxEQ7hAfplHyglp917YiJLKd1u13m7zHw3rIyJz5uY0UieCGyfjxAC4t dk9k1BK6duBmciEob4DgKQcjLS3hcOAQXrGtlw9oJGIFQ/ULoxvZgW6JAcPp3Q4Cc0n1 0GQwWKnzrXdhpkB9Ht3G41gAcAi/dqTkZtgJgEIEKlyXw+v0LIKgc/m955E6jkI1+jW+ PHvw== X-Gm-Message-State: AOJu0YyjUv+t8AiEdXZeEOoJjOxG9z6w6s7P4WwnFazULP8zbDinTrsu PNaxw0PHphUCyF4iki3sqDIbC+mE3PYq7J78ryg= X-Google-Smtp-Source: AGHT+IEnlmvKg48AWLtRJlHz9Rg/Q27+8No7s5ojWvtL/WdnvFdbsfi5N3eU9MggG7ZhT0nUoF/4cA== X-Received: by 2002:a17:90b:38cb:b0:27d:1376:3ae1 with SMTP id nn11-20020a17090b38cb00b0027d13763ae1mr1378816pjb.0.1700278781572; Fri, 17 Nov 2023 19:39:41 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.108]) by smtp.gmail.com with ESMTPSA id cz8-20020a17090ad44800b00280fcbbe774sm2053823pjb.10.2023.11.17.19.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:41 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v4 3/5] tty/serial: Add RISC-V SBI debug console based earlycon Date: Sat, 18 Nov 2023 09:08:57 +0530 Message-Id: <20231118033859.726692-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118033859.726692-1-apatel@ventanamicro.com> References: <20231118033859.726692-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We extend the existing RISC-V SBI earlycon support to use the new RISC-V SBI debug console extension. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/earlycon-riscv-sbi.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 732c893c8d16..1f2594b8ab9d 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -87,7 +87,7 @@ config SERIAL_EARLYCON_SEMIHOST =20 config SERIAL_EARLYCON_RISCV_SBI bool "Early console using RISC-V SBI" - depends on RISCV_SBI_V01 + depends on RISCV_SBI select SERIAL_CORE select SERIAL_CORE_CONSOLE select SERIAL_EARLYCON diff --git a/drivers/tty/serial/earlycon-riscv-sbi.c b/drivers/tty/serial/e= arlycon-riscv-sbi.c index 27afb0b74ea7..5351e1e31f45 100644 --- a/drivers/tty/serial/earlycon-riscv-sbi.c +++ b/drivers/tty/serial/earlycon-riscv-sbi.c @@ -15,17 +15,33 @@ static void sbi_putc(struct uart_port *port, unsigned c= har c) sbi_console_putchar(c); } =20 -static void sbi_console_write(struct console *con, - const char *s, unsigned n) +static void sbi_0_1_console_write(struct console *con, + const char *s, unsigned int n) { struct earlycon_device *dev =3D con->data; uart_console_write(&dev->port, s, n, sbi_putc); } =20 +static void sbi_dbcn_console_write(struct console *con, + const char *s, unsigned int n) +{ + sbi_debug_console_write(n, __pa(s)); +} + static int __init early_sbi_setup(struct earlycon_device *device, const char *opt) { - device->con->write =3D sbi_console_write; - return 0; + int ret =3D 0; + + if (sbi_debug_console_available) { + device->con->write =3D sbi_dbcn_console_write; + } else { + if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) + device->con->write =3D sbi_0_1_console_write; + else + ret =3D -ENODEV; + } + + return ret; } EARLYCON_DECLARE(sbi, early_sbi_setup); --=20 2.34.1 From nobody Tue Dec 30 07:38:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11403C5AE5B for ; Sat, 18 Nov 2023 03:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346483AbjKRDj6 (ORCPT ); Fri, 17 Nov 2023 22:39:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234760AbjKRDjw (ORCPT ); Fri, 17 Nov 2023 22:39:52 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26944170F for ; Fri, 17 Nov 2023 19:39:46 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6d33298f8fdso1509471a34.1 for ; Fri, 17 Nov 2023 19:39:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1700278785; x=1700883585; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E5CqYtZjogFbVXt6oNqdtFyBl6EwNFmDaHiSS35XtX0=; b=Ca/6T14OGl0TQlPtX1CWXh9y09HtCzxopj0NiLKPPkhsihrGCY6VuW3iJTJirP8qW2 WYowKEzYHH+xDo9lbhcTZukRg0MA2B4QAvnKxX3d1BetuwE/kd7uE3tBI6bqwTrtyiMy HItjpedjgxgviQ0mWkpKC7w7Ub6qkKWRQk6Itd1jXrXPTNZqmmeSadMUs8kUU795up4/ jfG5ttKVYh4iDO1GujAKdNyri49RSza8Cdr5Y4k8W95RyvpViFEN3Y6OPqW5UVJJdkNP ICfD3x02XGTD5eYRMPkCvwoRhTnJwqRI0iFgEZkS6SA9H0ZolD5HRjH1df7Tg/j6QWMi XIYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700278785; x=1700883585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E5CqYtZjogFbVXt6oNqdtFyBl6EwNFmDaHiSS35XtX0=; b=Hw25985mpPf0AWdF8TeX68ThODKWXWAjYS7qcMOJUlNZeAIHCbsXfu2mBHttFKFtQj 16OdpTXRwCTJpWn1J131tV8ke2mQEu2N4gBzLCjE23Gblrunb4ExZpbyML/iWwAc3rxN rtJuQZUGqwZ5PXIdjoKhaWBWXEDDXVU25zV60vO09vxNdCwmPZVg2JInHLhX6RFiyDS4 gXfk4jMQyvNDwn380qxXdmVUSzvC6kreGSVENtQjFEW6DJMyq0fDgZJ9tgC6YCAWj+/Z Yp8g/CUGgGs5hrKuVDuVwB2IcR2YFBEJv/jpZH4bwkixXB1daIIajkW0BTZ7ZzoCmx+F PPBg== X-Gm-Message-State: AOJu0YzCwsPsONj4x9Kkc5MX/B9FMbCJ9a8Jz/BvY0qWJJuTh04K0F+H 9CnNxyreD3Yj909DC54paeAfFw== X-Google-Smtp-Source: AGHT+IFb5EggA2BEK2LPl8TELrC4wgaMj8P7ee9t/caB/1Et1jdB4N8VOhdF9KYDfMnGJFJ+eqIzWA== X-Received: by 2002:a05:6871:728a:b0:1e9:9867:247 with SMTP id mm10-20020a056871728a00b001e998670247mr1437835oac.47.1700278785270; Fri, 17 Nov 2023 19:39:45 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.108]) by smtp.gmail.com with ESMTPSA id cz8-20020a17090ad44800b00280fcbbe774sm2053823pjb.10.2023.11.17.19.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:44 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Atish Patra , Anup Patel Subject: [PATCH v4 4/5] tty: Add SBI debug console support to HVC SBI driver Date: Sat, 18 Nov 2023 09:08:58 +0530 Message-Id: <20231118033859.726692-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118033859.726692-1-apatel@ventanamicro.com> References: <20231118033859.726692-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Atish Patra RISC-V SBI specification supports advanced debug console support via SBI DBCN extension. Extend the HVC SBI driver to support it. Signed-off-by: Atish Patra Signed-off-by: Anup Patel --- drivers/tty/hvc/Kconfig | 2 +- drivers/tty/hvc/hvc_riscv_sbi.c | 59 +++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig index 4f9264d005c0..6e05c5c7bca1 100644 --- a/drivers/tty/hvc/Kconfig +++ b/drivers/tty/hvc/Kconfig @@ -108,7 +108,7 @@ config HVC_DCC_SERIALIZE_SMP =20 config HVC_RISCV_SBI bool "RISC-V SBI console support" - depends on RISCV_SBI_V01 + depends on RISCV_SBI select HVC_DRIVER help This enables support for console output via RISC-V SBI calls, which diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sb= i.c index 31f53fa77e4a..697c981221b5 100644 --- a/drivers/tty/hvc/hvc_riscv_sbi.c +++ b/drivers/tty/hvc/hvc_riscv_sbi.c @@ -39,21 +39,66 @@ static int hvc_sbi_tty_get(uint32_t vtermno, char *buf,= int count) return i; } =20 -static const struct hv_ops hvc_sbi_ops =3D { +static const struct hv_ops hvc_sbi_v01_ops =3D { .get_chars =3D hvc_sbi_tty_get, .put_chars =3D hvc_sbi_tty_put, }; =20 -static int __init hvc_sbi_init(void) +static int hvc_sbi_dbcn_tty_put(uint32_t vtermno, const char *buf, int cou= nt) { - return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16)); + phys_addr_t pa; + + if (is_vmalloc_addr(buf)) { + pa =3D page_to_phys(vmalloc_to_page(buf)) + offset_in_page(buf); + if (PAGE_SIZE < (offset_in_page(buf) + count)) + count =3D PAGE_SIZE - offset_in_page(buf); + } else { + pa =3D __pa(buf); + } + + return sbi_debug_console_write(count, pa); } -device_initcall(hvc_sbi_init); =20 -static int __init hvc_sbi_console_init(void) +static int hvc_sbi_dbcn_tty_get(uint32_t vtermno, char *buf, int count) { - hvc_instantiate(0, 0, &hvc_sbi_ops); + phys_addr_t pa; + + if (is_vmalloc_addr(buf)) { + pa =3D page_to_phys(vmalloc_to_page(buf)) + offset_in_page(buf); + if (PAGE_SIZE < (offset_in_page(buf) + count)) + count =3D PAGE_SIZE - offset_in_page(buf); + } else { + pa =3D __pa(buf); + } + + return sbi_debug_console_read(count, pa); +} + +static const struct hv_ops hvc_sbi_dbcn_ops =3D { + .put_chars =3D hvc_sbi_dbcn_tty_put, + .get_chars =3D hvc_sbi_dbcn_tty_get, +}; + +static int __init hvc_sbi_init(void) +{ + int err; + + if (sbi_debug_console_available) { + err =3D PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_dbcn_ops, 256)); + if (err) + return err; + hvc_instantiate(0, 0, &hvc_sbi_dbcn_ops); + } else { + if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) { + err =3D PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_v01_ops, 256)); + if (err) + return err; + hvc_instantiate(0, 0, &hvc_sbi_v01_ops); + } else { + return -ENODEV; + } + } =20 return 0; } -console_initcall(hvc_sbi_console_init); +device_initcall(hvc_sbi_init); --=20 2.34.1 From nobody Tue Dec 30 07:38:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE178C2BB3F for ; Sat, 18 Nov 2023 03:40:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346453AbjKRDkK (ORCPT ); Fri, 17 Nov 2023 22:40:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346474AbjKRDj5 (ORCPT ); Fri, 17 Nov 2023 22:39:57 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48AC8172C for ; Fri, 17 Nov 2023 19:39:49 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-35742cbb670so9326785ab.2 for ; Fri, 17 Nov 2023 19:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1700278789; x=1700883589; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UwuJDohRQ3aqDyqXIkqqX8SciM39GRJg3jYARQ14u9s=; b=aRonvU5ownT5UnSsSA8+v5t8/CtqHPWQKm3q796XR4S5793C2R62EUvHSVvEJYBWzZ UHXUnoObMEmMbkeCTEurnSG3mgcaUHS95oOJTicP6z8hJIqXl/HdIAFGFjhlw1CVWgn7 5wxi0JZjD2sPQ0feNKIWt9laCyCWeq+7d2HIklu23vpSWZ7dUhDJSc1f/VF7jFqRaZnj jRt1iB4zDecwtkqk1PFoiz1Kp8LHNGqdfQo525vW62gvENA94YogwLgLZ54QrI+a3kgH /3etdgH5a1552oTQq2/SLkXXMsBrFglJVNAaf608u5LnB4JD/IFJZSmIdfdDLbQ3MyPp rFVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700278789; x=1700883589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UwuJDohRQ3aqDyqXIkqqX8SciM39GRJg3jYARQ14u9s=; b=LWYIqiFKfKwKZyEVft60AzPzSAclt1VWB7Pe3Yxi7WOhhdBZrAZPvAyb6oJ1+26Q5j ZDjffrG1A56WasXHD9Nv8kJngs/tR7Bem3a+9xWOwXOhpHiI/McGxAu7y4TBEtoGBN1z O3Er1QaFMXcO2N/Jslnnpdt0gbQLDb06KgjjGITsekXP0/ijupyH/5//R2Sf3/veXW52 ZVqozy93+XefU18fqthuX9wqW746cOlmjmcHuTqUG6cxhkVxcN3XZQSIz5G/rry2Kzdb ZE2vc6O9xdJtXQR4QIWfb4JkyvZymdigJfaZ9xvvF9wiPSxw2fgraMzIl1Yz7xuEzl4k ONiw== X-Gm-Message-State: AOJu0YwGq2hXSjQq//VoPUxitzaykgJR5go4JFsM0y8OK0qGv9FPoBTl 19ks/Vr9nWeEe6DxXhFi8zaQRA== X-Google-Smtp-Source: AGHT+IHOlKnIVZ4ksof0LCT4ATUyA4aQHrNLe3GwQ2oPH5iU/GU5vmFy/egl6dy1iF7ul/LCCaVvEg== X-Received: by 2002:a05:6e02:58f:b0:357:4a63:2ad2 with SMTP id c15-20020a056e02058f00b003574a632ad2mr1554139ils.21.1700278788781; Fri, 17 Nov 2023 19:39:48 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([171.76.80.108]) by smtp.gmail.com with ESMTPSA id cz8-20020a17090ad44800b00280fcbbe774sm2053823pjb.10.2023.11.17.19.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:48 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v4 5/5] RISC-V: Enable SBI based earlycon support Date: Sat, 18 Nov 2023 09:08:59 +0530 Message-Id: <20231118033859.726692-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118033859.726692-1-apatel@ventanamicro.com> References: <20231118033859.726692-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let us enable SBI based earlycon support in defconfigs for both RV32 and RV64 so that "earlycon=3Dsbi" can be used again. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- arch/riscv/configs/defconfig | 1 + arch/riscv/configs/rv32_defconfig | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index 905881282a7c..eaf34e871e30 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -149,6 +149,7 @@ CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_8250_DW=3Dy CONFIG_SERIAL_OF_PLATFORM=3Dy CONFIG_SERIAL_SH_SCI=3Dy +CONFIG_SERIAL_EARLYCON_RISCV_SBI=3Dy CONFIG_VIRTIO_CONSOLE=3Dy CONFIG_HW_RANDOM=3Dy CONFIG_HW_RANDOM_VIRTIO=3Dy diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_de= fconfig index 89b601e253a6..5721af39afd1 100644 --- a/arch/riscv/configs/rv32_defconfig +++ b/arch/riscv/configs/rv32_defconfig @@ -66,6 +66,7 @@ CONFIG_INPUT_MOUSEDEV=3Dy CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_OF_PLATFORM=3Dy +CONFIG_SERIAL_EARLYCON_RISCV_SBI=3Dy CONFIG_VIRTIO_CONSOLE=3Dy CONFIG_HW_RANDOM=3Dy CONFIG_HW_RANDOM_VIRTIO=3Dy --=20 2.34.1