Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp234603lqe; Tue, 9 Apr 2024 23:36:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqd5uATVItK94pIuruQFpYWbhlJ1gZsP56nRn8UfkpKHjvy6iH0iKmvC0hHlbvelC8AaEpOdC7KiT49STRIO6lCrMR6AzwWxjs3xzPQw== X-Google-Smtp-Source: AGHT+IGpAhdNg0wIdjjx5Mkv/1oNRvOrDdXH27wavy1rdkrfZrKlj3XiGYL0xvxNr5oq4LjQ/WlS X-Received: by 2002:a17:907:2d12:b0:a52:3d1:6768 with SMTP id gs18-20020a1709072d1200b00a5203d16768mr1088133ejc.1.1712730996723; Tue, 09 Apr 2024 23:36:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712730996; cv=pass; d=google.com; s=arc-20160816; b=nMrxYH8nG39VBt+1VCeHLG2MIYSnLPzW5kCZVxg3sqb3hJL0SAocsMd++oJgSL598o 1SSKSvhJr6uylWJIANOabazPIUQo55W0xxYsXMZ6nhNNknkhvwlhHvWlwfvZ00Uj6tb7 N7MkrVWaWMhyNFIXxKqB9xQPWPvDk79BETb1WzcFPAIj+NO8ZhqfyNdGWOHX/h6Du9EL pIcwldcyCI+2uWVkbysV8FjLibm+4KdVu3BCDcJ943gMDRHSgfGpv+FvsUG2vU3rrrGd fgKQcg7XYzH/TxVLSZI9+RizxKdFRE9wk20thWVintdLzZd+e2NIz5K6YYWMNfgbWLQ2 rIYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=K7st77X+PSbizH6dzC2MWrXxZ3jWmTycyWs/o4rJ2T8=; fh=5FOMqvpTdDbC4nTMe1TviMZp/mItQrJU1sIzVJ0NYUE=; b=bg2ixdRNfGSsyYP/XRf21CxFojQgDzziDn+j/n4R6REjK5Ef2RHK1iWyJakKbTxNXL Yzu9UMu1NS2aLc3tcAsQFs9TX1RySolg7GCdgsvYmv0ZGzrKJpEYGRwdwDe04ID+psTk R2jTJBYfW9UGboQKt5MarYwvAFWNNsaOneYsagjXBSihZQzVP12SC/1NOsKUV+VvZ/T3 b4xNfbst6PJBPni1QMPslX6eGVRbElWThwGBrn8M3wppJ5OreND+myQN77JLeiLOsXRB nyS2ima1GlqCvu3/5HGHwJDTfSAH8JBAYQXExpaME5E4GR73JARkCT1tTdlw755pETGz PgrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-137998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137998-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o11-20020a17090611cb00b00a4744935a60si5312876eja.864.2024.04.09.23.36.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 23:36:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=shingroup.cn dmarc=pass fromdomain=shingroup.cn); spf=pass (google.com: domain of linux-kernel+bounces-137998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137998-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=shingroup.cn Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 74F071F21A63 for ; Wed, 10 Apr 2024 06:36:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7FCC36B08; Wed, 10 Apr 2024 06:36:11 +0000 (UTC) Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30AD01427B for ; Wed, 10 Apr 2024 06:36:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.206.34.216 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712730971; cv=none; b=UUeDOtSmPBJ0Pgj3o0HEQj/R3GWONMOvSD3yFZAn6Zvkj9f/Dgia13yFVJHnrUW2hXmDiZjxpWX44/9Jzl3PHLiL69J310SFFgZHGk+e7NkG1757vhNlVpVn3DVw7yErEZB8aDhoUn747bjaupjgBrY3q2upQk65uBePLwb9cSY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712730971; c=relaxed/simple; bh=Bswf8GGz9nhrCHVYWM9I5EX2nibhIgOoLY2Rrl6ouss=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kVNbCuixeuTfKmGoADG++OUif4UbrJWNYAUHb1qeG1lOi9Qx9gOxuuFgu470qyZ00s1EQkfs/SkepVDS1NRSBEl53wmuh1NXkwVoaxz7QxyuCpDt5qk/XBCBnbFa40e8BvgpaPqk0U1Qkr8IaA5r8HTvsOmmZznBeFAUHMHKbZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn; spf=pass smtp.mailfrom=shingroup.cn; arc=none smtp.client-ip=54.206.34.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shingroup.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shingroup.cn X-QQ-mid: bizesmtp86t1712730896tvu5ywkv X-QQ-Originating-IP: r0h3XHYT18sT2yt8k08GzNHSk4HTIBc66vnGcRK0aQI= Received: from HX01040082.powercore.com.cn ( [14.19.197.107]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 10 Apr 2024 14:34:49 +0800 (CST) X-QQ-SSF: 01400000000000B09000000A0000000 X-QQ-FEAT: 3M0okmaRx3i4lw8jCv5pRZ7eo/gTlSNfqfJCPj1K7jvvSLIS40Dayz+ynQ2CK 68XPUeRpihraguLeHHDc5Ady/t6uyuXAWz9D0gg08WMVpbdPkCpxYKWJ46mJRHekC77N4gq 7eHNphwxlOOSmvR2iEiuWYHe1bWWaBuubSPXEHA6DPiBfdt3120CrKvB/FuppwIth/AlOjS oFwQiLyd9wlMT9+VRqYsS3NnEVUFosFvo0XnHfuqQgp0Zb4hqrYhdgWwiRTMtD7xAbfEE5m bGVsfo39affMyu2danRjhIP67B8TMJhHRq6ayu2OELnse0uQUCL+Lwhn7xyMu/iCKGMk6Wn 3QQEsF2X2a7p3pGnrxGxJnV+PYquzqxiGgxiyrleUUh0ZOEu3nBrpuo4Hqz5nmix/+o/0ex zlZ6ECdTLx9zkkKO+eIghg== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 10304416365381800906 From: Jinglin Wen To: palmer@dabbelt.com Cc: paul.walmsley@sifive.com, aou@eecs.berkeley.edu, gregkh@linuxfoundation.org, atishp@rivosinc.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Jinglin Wen Subject: [PATCH 2/3] riscv: SBI as the interface for the early console Date: Wed, 10 Apr 2024 14:34:31 +0800 Message-Id: <20240410063432.23058-3-jinglin.wen@shingroup.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240410063432.23058-1-jinglin.wen@shingroup.cn> References: <20240410063432.23058-1-jinglin.wen@shingroup.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:shingroup.cn:qybglogicsvrgz:qybglogicsvrgz5a-2 Use the SBI interface as the early console output interface for the RISC-V platform. Signed-off-by: Jinglin Wen --- drivers/tty/hvc/Kconfig | 12 ++++++++++++ drivers/tty/hvc/hvc_riscv_sbi.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig index c2a4e88b328f..48658d2b700c 100644 --- a/drivers/tty/hvc/Kconfig +++ b/drivers/tty/hvc/Kconfig @@ -118,6 +118,18 @@ config HVC_RISCV_SBI If you don't know what do to here, say N. +config RISCV_EARLY_CONSOLE_SBI + bool "Use SBI as the interface for RISC-V early console" + depends on RISCV + help + Choose 'Y' to use the SBI interface as the early console + output interface for the RISC-V platform. + + This configuration is a temporary setup for debugging + purposes during the boot process to address issues as + early as possible. It should not be enabled in production + kernel. + config HVCS tristate "IBM Hypervisor Virtual Console Server support" depends on PPC_PSERIES && HVC_CONSOLE diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c index cede8a572594..6686dcf62853 100644 --- a/drivers/tty/hvc/hvc_riscv_sbi.c +++ b/drivers/tty/hvc/hvc_riscv_sbi.c @@ -12,6 +12,7 @@ #include #include +#include #include "hvc_console.h" @@ -81,3 +82,31 @@ static int __init hvc_sbi_init(void) return 0; } device_initcall(hvc_sbi_init); + +#ifdef CONFIG_RISCV_EARLY_CONSOLE_SBI +static ssize_t (*sbi_early_putc_common)(uint32_t vtermno, const u8 *buf, size_t count); + +static void sbi_early_putc(char c) +{ + unsigned int termno = 0; + int count = -1; + + if (c == '\n') + sbi_early_putc('\r'); + + do { + count = sbi_early_putc_common(termno, &c, 1); + } while (count == 0 || count == -EAGAIN); +} + +void __init hvc_sbi_early_init(void (**putc)(char c)) +{ + if (sbi_debug_console_available) + sbi_early_putc_common = hvc_sbi_dbcn_tty_put; + else if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) + sbi_early_putc_common = hvc_sbi_tty_put; + + if (sbi_early_putc_common) + *putc = sbi_early_putc; +} +#endif -- 2.25.1