From patchwork Sat Nov 18 03:38:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 166436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp970228vqn; Fri, 17 Nov 2023 19:39:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7UKHN6z0hyhudZgpK6hcweGf08NbCEX0VlGTmKW0mDnRK/HalsXq3Nq9CwU+L6FujNXRR X-Received: by 2002:a05:6a00:390c:b0:6b4:231b:a45c with SMTP id fh12-20020a056a00390c00b006b4231ba45cmr1661443pfb.26.1700278786666; Fri, 17 Nov 2023 19:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700278786; cv=none; d=google.com; s=arc-20160816; b=Br63ZCoA+y/L5C+2wm76fHRgtqR50aTeeXhj+UoGkYshkWs93zg6045BDYM+akHZFm F2isD0X9VKv4Q5ljwrDCAbClnq7uZWxE/6bxGqQI9SJfWfs3p7sAxy3ynYpkupdVOgLF 1a7EgziI1o8c/aEGfz7NOthTjLeJRC6IYxvThJojcDSirWioZzJlEKgr5/PTHcNo0Hmw 13wWzebBLYW0V0fg9w5Mzi4zZ+AY8pqTFY6D9urW7V1HB7cM8OzPqx1J/xBfEjdNNAEa 8wzV+L0oQlEj9LkXOlJavFE3GIRNmCYTqG3XokmRgmfuO9sw1RkbqGL659IFaLMXq/5C rB7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rUH3sN/jANNMbAvxiLE+FR6QScUT3piYF3Fp6n0y2EI=; fh=sCaLDPmI3z3WfJgoG5Ri8nSrNxiyuF4F9Uj24RFqprM=; b=rNNPTUJqQp8OnncyILxjgFu4GgoM9OvELaySUj5PQQk1PzLRL0n5+HoZAMWNfiX9cQ jLztt5rtGeohcj6UNK+NKtZ2Q/gzs81bWx1k58iHXaLsoINZl01pr8dDD/cGsOe/jAQk xelh8J+r3rXaGVNzXG/NjdZIppPBZ+Ys9G+H78uNGuUjzTzuqz90QrHGmSFIn9WUAzAI 0JQ0yk3HK3S1Pc+5+ei5fLVrCvad9U0PwVeoPqDYWGMTCHTI9iOaw6YgngQDomCPuSL3 dSQv4rSWoWvljvZY44o5SMKQr7+rpw7Rb6qeS5QnosotkYM/ufREoeTCEjA3+8lqfujL 7iBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JB96zYtX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t32-20020a635360000000b005c207717411si2520532pgl.864.2023.11.17.19.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=JB96zYtX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CA4F980B1D2E; Fri, 17 Nov 2023 19:39:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346430AbjKRDjl (ORCPT + 29 others); 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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 19:39:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782871529398347824 X-GMAIL-MSGID: 1782871529398347824 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 long arg0, unsigned long arg3, unsigned long arg4, unsigned long arg5); +#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); From patchwork Sat Nov 18 03:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 166437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp970234vqn; Fri, 17 Nov 2023 19:39:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJeIuMMmXby506SEpVvJpAN4OEyGs7niIZ7tjLLbDN7a4JxBM/KPKL2XoPniUORmxtu5tv X-Received: by 2002:a17:90b:3618:b0:280:5b98:5450 with SMTP id ml24-20020a17090b361800b002805b985450mr1753942pjb.15.1700278789572; Fri, 17 Nov 2023 19:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700278789; cv=none; d=google.com; s=arc-20160816; b=jCgOpPFIk5L+O5dcjvH9iKutjS2qITFjjwRCZY34BmVhDHOQtMFDWtZJyMogqyjhv0 8wOa4UVnRp/M4vH/jrTRNmZsJHLrh7QLJPFvBMntVSfYN2X+D2pxpt57ywBDKKedlwXx 4FmO1jGOK++z9ddnCkleJG4CXSBc2mTXbqKD16BQ1tESbYeelwp2Lo/bClRQdCNG3Ley SIqmfSJBR7qdcee38+z5ze7lyPykXjqygmdb/v0GuupnssTz9/o+kTqW0wn/pOABcqIS 53Dh+1/djv6AWem8vtYt6AnkOw8FW9343qFME5sUABtzfb/i5D/RqKCQCOsgQscuZukk 5qZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lUknxwWYXkt9C2M9pb/Z3CUGPfJIBZQMgmHAhH/xaf8=; fh=sCaLDPmI3z3WfJgoG5Ri8nSrNxiyuF4F9Uj24RFqprM=; b=jZ/iwZVLc4MBqd43CSC31vdbBYHn2+6CoJovG0S1HZDvvU71scg9d878n2koFNkwlT oF4XA8W+Zkef+/Q/XVakrCu4TY9HoBRQ7EIcgNGYTYaqxff4QkIQwMy4BemjUM2tsNsU TaQfS2N0EPI2w/KQJ7Ih7Kno0KeXSOXi3BS1DJdSqgMkFbssux09S1at5FqAGCOOeqIw 0dJOCWed1nLBviaMUOMaXtQDj9ZkYYwn8eyfHWow4E86ZVVyv6w0QMgbE7Ska3KwxNxs PvW7ZMLRfZe3yK5lgdP9UaOdTKmqDftJoilf1mvrS6vE/XPqSkWKh0/eSkWuhq0iEAjS gl+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=IHinz0gC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id lx8-20020a17090b4b0800b00283942c01e5si4074974pjb.183.2023.11.17.19.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:39:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=IHinz0gC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 50A9880B2324; Fri, 17 Nov 2023 19:39:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346438AbjKRDjr (ORCPT + 29 others); Fri, 17 Nov 2023 22:39:47 -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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 19:39:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782871531673662127 X-GMAIL-MSGID: 1782871531673662127 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 long major, } 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) { return -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); +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 = 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 = 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 = 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 = 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 = 192; register_restart_handler(&sbi_srst_reboot_nb); } + if ((sbi_spec_version >= sbi_mk_version(2, 0)) && + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { + pr_info("SBI DBCN extension detected\n"); + sbi_debug_console_available = true; + } } else { __sbi_set_timer = __sbi_set_timer_v01; __sbi_send_ipi = __sbi_send_ipi_v01; From patchwork Sat Nov 18 03:38:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 166438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp970352vqn; Fri, 17 Nov 2023 19:40:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtskwzyO3kC+QaXfpu8nUmkELhtcmqIoQT0VnfV37t/ozDap6tTwb/EEKBE/DwtYq9TFKb X-Received: by 2002:a05:6870:d28d:b0:1f4:dd99:b07 with SMTP id d13-20020a056870d28d00b001f4dd990b07mr1363093oae.49.1700278821970; Fri, 17 Nov 2023 19:40:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700278821; cv=none; d=google.com; s=arc-20160816; b=poHHsLys+aGvwSWxei43z4RXm4wn5vHoL3E6pEsk81XREi1I3jKgCaZgJlPMo/EdDo Hhf3Ud4Qjnt1Bzed6DyAgLJNEhCc5s+fq85i9sOtafqX92dcwLmU+KjQKptakRDpT5L6 k7RCTN5KpGrJWjp6ne1cR3t47cw1q4UZ6DK1P+2D4fSkF3o5pEWsqX4hnDFjmAkUxmEu L8AhE+taZgW2cak0vYvy7Tun4hNd3kdtTyp2zhegWzI66eaDhLV3gE/WpF2lSbYPiTbv ZHsLN1ezEMvNpJovJQH1//XywgFdnq2ACuS2bdNxLuUnNMICYxQhocrMP5sRmMXJ36T4 eVRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ii/r8hzimL/XtavRWrcGkJgKEnLeFuQkfTAUm70Wb2A=; fh=sCaLDPmI3z3WfJgoG5Ri8nSrNxiyuF4F9Uj24RFqprM=; b=D0DQsQftXUgywm3uvTCh1d1gB3j1nuBLNCWBKpkz+HlNZzBuhcpJ/QTNO2S3NuwMRt ELERkSjebj+cVIajdQM4cddgxSdgkFMhq/esrOcIGSeVn15OfPkXKFmkCnCgFa/bj8or hgXD2cafKCWjIZxqBMMTsq5HDnmK5+nXi3ipPReGerQBySfy+5WPnUHI7Uflpc6l31y3 RhQfmOsAce8FpuvGsgj6Ol8jhzNmvJJlabm2SrJZG9SME4bpTp7Sn4t0ao586SQG30DX Q/sy+sZkhZgkNxL2N0cBdUyigdTpzzVBWPIFrpaTvAAlDHTWSro1BExNdLtDi7LaKLtz fkHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=L7tk3XsP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b187-20020a6334c4000000b005b96fdd43cdsi3227407pga.759.2023.11.17.19.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:40:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=L7tk3XsP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 182DE805AA09; Fri, 17 Nov 2023 19:40:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346451AbjKRDjz (ORCPT + 29 others); 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-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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 19:40:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782871566273574816 X-GMAIL-MSGID: 1782871566273574816 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 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/earlycon-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 char c) sbi_console_putchar(c); } -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 = con->data; uart_console_write(&dev->port, s, n, sbi_putc); } +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 = sbi_console_write; - return 0; + int ret = 0; + + if (sbi_debug_console_available) { + device->con->write = sbi_dbcn_console_write; + } else { + if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) + device->con->write = sbi_0_1_console_write; + else + ret = -ENODEV; + } + + return ret; } EARLYCON_DECLARE(sbi, early_sbi_setup); From patchwork Sat Nov 18 03:38:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 166440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp970380vqn; Fri, 17 Nov 2023 19:40:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlD3oMZIKnCvq/DmCCMRIKJztCCD70+Gb0UtuYlGkYGjg0Pop0pU6SW+WckwaD41kOcpNk X-Received: by 2002:a05:6a20:2d13:b0:16c:b5ce:50f with SMTP id g19-20020a056a202d1300b0016cb5ce050fmr1235744pzl.32.1700278825181; Fri, 17 Nov 2023 19:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700278825; cv=none; d=google.com; s=arc-20160816; b=Is+b/NL2RpiLeQmSKsFK9fIJcEnh4ynHn5sR8Sv5fRCuZ91XSYVQW/RDFz625Sc32O Ra18x37m7FMvC/u0SRg+EHdURshYKQf3CG65B2AX+E1Yl0mkItURndjcUQyUUAWBFzsC cy9L0tfrl21ebvQxB7x9eLWFhPjWtyyUykTu66Lq0hD86lwTyHx0mVbsCWVaeRRP9csY nBIgpDMCGRN7Kzfojozm1ENlMQEEw523g92vpQJk3hDeuKPhidqfNWRWpZPSSsJiZ3PW udn79/zv+VQXHIJZDSU8e61+8alLa8S0cvTA5sQFgg8sVN1fjSstPw6neGZkr95aZKm3 5BiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E5CqYtZjogFbVXt6oNqdtFyBl6EwNFmDaHiSS35XtX0=; fh=AB671bsq6wR7DceXjf9pC9mFDEFzybXlmQ7x1GwQJjg=; b=kp+3XLCTNImhqtE6dOn/hVO18ERQ5hfGNoa+l8QzN5VhDF20Ez4AOcS2prsTD/ChOl hACDzJpYydEEA4BDEt/hG9nNZRS8UaLcI1Ocby2SYlaj6LjpNbrw+vxHDUbta+oHOSJc uFgkGogRE3AXB7qr+ytJ8ovEZLSKGSLNKPB1XxHi4yqYpRiaHGQgHsz029QNij3AEq+H VuP1Kj/nRPdC0Zmt7AjSI6Z7W924FDFqri68GFM9LKaHH9VISMKIoWJ1CTtXlWkvU+Wl eeMwX8uFQS/G5gYFSZMkUf0xp9EoVAroMJlAKGovUMDwMZd5LL5BtAMq/y+yN99lQ1lt xSCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="Ca/6T14O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id c10-20020a170902d48a00b001cf531cf5d5si122491plg.482.2023.11.17.19.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:40:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="Ca/6T14O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DC3FC8304EE3; Fri, 17 Nov 2023 19:40:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346477AbjKRDj5 (ORCPT + 29 others); Fri, 17 Nov 2023 22:39:57 -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-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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 17 Nov 2023 19:40:22 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782871569390408306 X-GMAIL-MSGID: 1782871569390408306 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 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_sbi.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; } -static const struct hv_ops hvc_sbi_ops = { +static const struct hv_ops hvc_sbi_v01_ops = { .get_chars = hvc_sbi_tty_get, .put_chars = hvc_sbi_tty_put, }; -static int __init hvc_sbi_init(void) +static int hvc_sbi_dbcn_tty_put(uint32_t vtermno, const char *buf, int count) { - return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16)); + phys_addr_t pa; + + if (is_vmalloc_addr(buf)) { + pa = page_to_phys(vmalloc_to_page(buf)) + offset_in_page(buf); + if (PAGE_SIZE < (offset_in_page(buf) + count)) + count = PAGE_SIZE - offset_in_page(buf); + } else { + pa = __pa(buf); + } + + return sbi_debug_console_write(count, pa); } -device_initcall(hvc_sbi_init); -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 = page_to_phys(vmalloc_to_page(buf)) + offset_in_page(buf); + if (PAGE_SIZE < (offset_in_page(buf) + count)) + count = PAGE_SIZE - offset_in_page(buf); + } else { + pa = __pa(buf); + } + + return sbi_debug_console_read(count, pa); +} + +static const struct hv_ops hvc_sbi_dbcn_ops = { + .put_chars = hvc_sbi_dbcn_tty_put, + .get_chars = hvc_sbi_dbcn_tty_get, +}; + +static int __init hvc_sbi_init(void) +{ + int err; + + if (sbi_debug_console_available) { + err = 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 = 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; + } + } return 0; } -console_initcall(hvc_sbi_console_init); +device_initcall(hvc_sbi_init); From patchwork Sat Nov 18 03:38:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 166439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp970367vqn; Fri, 17 Nov 2023 19:40:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEk1ARx9t2Uzphld0+es+iqf8CtScui+v34TVmSqiJInOWyjLibzyaMXzasg+LFzcLXSTS X-Received: by 2002:a0d:eb83:0:b0:5a7:c8a9:79e8 with SMTP id u125-20020a0deb83000000b005a7c8a979e8mr1671844ywe.4.1700278823834; Fri, 17 Nov 2023 19:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700278823; cv=none; d=google.com; s=arc-20160816; b=xpsMYQMFQ57IVX2f+2FzYaFWWwvjERwLixL3nhTuOMbmu/JsGkdIFHUOBO/8W5rUO0 qAtQMogig22W9T3GelPNMNQSRmdsnT1oi5q0YAcJkJbBTFStgrbushZBpk2+uLHVno1o BJuj5ll4iehN7z6vGUOKUV59INjFTx9Lbhvhg+0EeAE7hOGz7MlcErApOr7JaMQJoiyJ FJy7mfCf04htc+ox3t3vs/O26s52vnL25HNmovdqI7J7h95cuiYTrrRjqVcztrpHT632 w5bKaP6Z3LiBtWwsR4EbzX/4ZuwvtL8Inc+5e0QqOyE4TGAncp5DoUP1v1XbgEQS0u/+ ekxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UwuJDohRQ3aqDyqXIkqqX8SciM39GRJg3jYARQ14u9s=; fh=sCaLDPmI3z3WfJgoG5Ri8nSrNxiyuF4F9Uj24RFqprM=; b=jzkRetaPfFeQeRmWfiDq9oxutWfMwzKsT8oozQxBDWj+8WNeTs39B/9OuiyRzXhFBQ ywlXgPfMBoLW/ApiQLg8RZUk/c9PrMQnMbhBIP3hEWgghpLEaYmQrDOFCbd/EQktgIXm JQk/Ve2Rt/UA9pGEAM3LsLXndV5MESysvUzMy+QlBAeSYlYPk1dWNRe7vu6eWa6Bu5tl tMAbR+JXSPzn4/kQR7GLMYFuBdiLxCO5R3tXFxaakZ/1lJZM+dsx27KzCkgTlLhKTyJR 8qIM5DkQ5x5wVBU/lW+KMqHog5fHA4w0mCBFLHr3Js9s0q/lpkU4eSJJzQcL8uHqk4Pb 2ieQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=aRonvU5o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u14-20020a056a00098e00b006cb4b976a22si890252pfg.227.2023.11.17.19.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 19:40:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=aRonvU5o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 95F5A8059355; Fri, 17 Nov 2023 19:40:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346429AbjKRDkJ (ORCPT + 29 others); Fri, 17 Nov 2023 22:40:09 -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-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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 19:40:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782871567586935806 X-GMAIL-MSGID: 1782871567586935806 Let us enable SBI based earlycon support in defconfigs for both RV32 and RV64 so that "earlycon=sbi" 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=y CONFIG_SERIAL_8250_DW=y CONFIG_SERIAL_OF_PLATFORM=y CONFIG_SERIAL_SH_SCI=y +CONFIG_SERIAL_EARLYCON_RISCV_SBI=y CONFIG_VIRTIO_CONSOLE=y CONFIG_HW_RANDOM=y CONFIG_HW_RANDOM_VIRTIO=y diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig index 89b601e253a6..5721af39afd1 100644 --- a/arch/riscv/configs/rv32_defconfig +++ b/arch/riscv/configs/rv32_defconfig @@ -66,6 +66,7 @@ CONFIG_INPUT_MOUSEDEV=y CONFIG_SERIAL_8250=y CONFIG_SERIAL_8250_CONSOLE=y CONFIG_SERIAL_OF_PLATFORM=y +CONFIG_SERIAL_EARLYCON_RISCV_SBI=y CONFIG_VIRTIO_CONSOLE=y CONFIG_HW_RANDOM=y CONFIG_HW_RANDOM_VIRTIO=y