Message ID | 20231020072140.900967-8-apatel@ventanamicro.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp881562vqb; Fri, 20 Oct 2023 00:23:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQaDrD6ddoItY7NYwzcY+++cJxI2Y+E3c2WEYjHiAmuRTXu6mD8mifOkJjgsG3RYYrz+xf X-Received: by 2002:a05:6830:3145:b0:6bd:b879:c313 with SMTP id c5-20020a056830314500b006bdb879c313mr1439900ots.10.1697786588582; Fri, 20 Oct 2023 00:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697786588; cv=none; d=google.com; s=arc-20160816; b=kLqxOFlmiYMscjOwWbYTuf75+00Zcq4JEoGwamqpyKZvGN6dW7kZ2OdMYaILVSn6kK A92rOG4xnkd8QXtpDQfiuZaqZEiNVvKUr+BT0hGbRuagCnFE8AJBP41/2vSLxU0N6JzB 4CGgCm5jaFxGiNTqh0HH+gDtbvOyi2UpPLPk25w351pt7zUbU9ks4vA48aUTm3HAtKqQ hnJbAiXgn9Fj5jFHZhEkM32xuaIq2vkf81RddyjFWGuHDRQo0mys59TndWMuj1x14yJi Fu3TFgiqTBEsGzO7KZ2VZfV9tkLHrwxl1l7ahH6bllHWsFqTThPjC3NVU4xaGknRduiB mNhA== 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=y40VDpa5tFn1F2iuJCGX0eAdf56bF4H2v7CDU5J7JlM=; fh=7GYORjoWw1oF4BCDuq40hd+MOEKRwzNqXwnZ/K2vS9Q=; b=ssVQP/3teGx/TVwrnuDNSjhYyCQFsZYThPyWDZGHg2HMVYPpo1T7uRW0nRJnYIxyJY ooMsqouFN5eVUSkxtCLPijyInHTIZIAp2qtdaBH6p+nQ4I9cs0niE4dHs9HU2vN9ZVkx H4Hq48vwH+S8Z8RCr6gHTxnvZzFgerGTcIuQK2S7LJWTJxz5MvFBpCyRgUoMFG7goLRJ Kml4xK8Qg09IrSs9UG7cgO3mslhztWXGogyBpeE/gfFKZYPm1uJflM8ZINlrS1XbLJ1o ck9KoV0DubRE2U0eYCqQ5pJpkL96KgRtJFmSlM/JvdsjyXlCotNpGjE9f4D5mgvyh5vQ CIzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="Y/dSv7M8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id i10-20020a63bf4a000000b005ab6142f1besi1242840pgo.169.2023.10.20.00.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:23:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="Y/dSv7M8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 21F9281ADB7C; Fri, 20 Oct 2023 00:23:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376510AbjJTHWs (ORCPT <rfc822;lkml4gm@gmail.com> + 25 others); Fri, 20 Oct 2023 03:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376515AbjJTHW3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 20 Oct 2023 03:22:29 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9517171F for <linux-kernel@vger.kernel.org>; Fri, 20 Oct 2023 00:22:22 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b2e4107f47so376703b6e.2 for <linux-kernel@vger.kernel.org>; Fri, 20 Oct 2023 00:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697786542; x=1698391342; 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=y40VDpa5tFn1F2iuJCGX0eAdf56bF4H2v7CDU5J7JlM=; b=Y/dSv7M87ohdmZ4awy0HHKLeA+scxM7mt0K3NdBG6B7PFHtFqgnuE5MD8/oAVDJwbP oYhoDehf1vfzRuNR2JBJatfKHKmrs/7Px/ImZpPIYO7q1/2JZI+tHFbFQ8aLcVT4ShOg HdkKk8JMTSOd/kDrEvdPWrTHf/VS0wkP1s9/qX/Dl2mae+8xJ6w2s91cGLE1pzAY/dMN LVTmx5+PGF3DCSSMvqqnSf3CD4TdcDp+8xoB63mSrSiiI5MepK5YpxBWPGXE+SoAsiaQ 1bvuV3UjZHF3/WoE5reUxLbIwjGDgvhEcEQAQ58K3JRfQJueyvr9zfmpJXJlPo6bJcKC /c/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697786542; x=1698391342; 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=y40VDpa5tFn1F2iuJCGX0eAdf56bF4H2v7CDU5J7JlM=; b=TDnf4vzza5jVrKKYUNrChU4LHV4+ZXiDt0/rBfard5dZU75a+e6NHA0DG3ejEiAk93 TFKbxsv1HuTa1pstDhGFx8MglqpBYeo6HEJqPhZJjWm6DaOD71BgofLNUb/D+cxI4qVO alqQFfp1d5p9MB6/Q6Qs/asSIE8aYNJOoMicbtud8ovb/KkHw3ckOe2ZZwP508fRMArw U6q+aWSLcmhW7KTNTJCaL26AvKMmDBITr/6T8qTmyinaKjiCBnH+xyH6bqCg1KrkEU+u oOSt2+qixJcGEDnj7e2D1E/6617mlZPZfvlOgKfek3y9bXlqlHr2LKejwcP98TLV9zAL 30BA== X-Gm-Message-State: AOJu0Yx0s+E3/J6MQydgnxL/bz3Tea7JyzCDDUUcknP2WAs/ivcbn3tp QOD4KUR1XDWkpoE9CjnGGN9Qxg== X-Received: by 2002:a05:6808:55:b0:3af:d7dc:a47e with SMTP id v21-20020a056808005500b003afd7dca47emr1067018oic.42.1697786541699; Fri, 20 Oct 2023 00:22:21 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([171.76.83.81]) by smtp.gmail.com with ESMTPSA id v12-20020a63f20c000000b005b32d6b4f2fsm828204pgh.81.2023.10.20.00.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:22:21 -0700 (PDT) From: Anup Patel <apatel@ventanamicro.com> To: Paolo Bonzini <pbonzini@redhat.com>, Atish Patra <atishp@atishpatra.org>, Palmer Dabbelt <palmer@dabbelt.com>, Paul Walmsley <paul.walmsley@sifive.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org> Cc: Conor Dooley <conor@kernel.org>, Andrew Jones <ajones@ventanamicro.com>, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Anup Patel <apatel@ventanamicro.com> Subject: [PATCH v3 7/9] tty/serial: Add RISC-V SBI debug console based earlycon Date: Fri, 20 Oct 2023 12:51:38 +0530 Message-Id: <20231020072140.900967-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020072140.900967-1-apatel@ventanamicro.com> References: <20231020072140.900967-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> 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, 20 Oct 2023 00:23:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780258269986351442 X-GMAIL-MSGID: 1780258269986351442 |
Series |
RISC-V SBI debug console extension support
|
|
Commit Message
Anup Patel
Oct. 20, 2023, 7:21 a.m. UTC
We extend the existing RISC-V SBI earlycon support to use the new RISC-V SBI debug console extension. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> --- drivers/tty/serial/Kconfig | 2 +- drivers/tty/serial/earlycon-riscv-sbi.c | 32 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-)
Comments
On Fri, Oct 20, 2023 at 12:51:38PM +0530, Anup Patel wrote: > We extend the existing RISC-V SBI earlycon support to use the new > RISC-V SBI debug console extension. > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > Reviewed-by: Andrew Jones <ajones@ventanamicro.com> > --- > drivers/tty/serial/Kconfig | 2 +- > drivers/tty/serial/earlycon-riscv-sbi.c | 32 +++++++++++++++++++++---- > 2 files changed, 29 insertions(+), 5 deletions(-) > > diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig > index bdc568a4ab66..cec46091a716 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..c21cdef254e7 100644 > --- a/drivers/tty/serial/earlycon-riscv-sbi.c > +++ b/drivers/tty/serial/earlycon-riscv-sbi.c > @@ -15,17 +15,41 @@ 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) > +{ > + phys_addr_t pa = __pa(s); > + > + if (IS_ENABLED(CONFIG_32BIT)) > + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, > + n, lower_32_bits(pa), upper_32_bits(pa), 0, 0, 0); > + else > + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, > + n, pa, 0, 0, 0, 0); This is still a bit hard to follow, and I guarantee it will be a pain to maintain over time, trying to keep both calls in sync, right? Why not fix up sbi_ecall() to get this correct instead? It should be handling phys_addr_t values, not forcing you to do odd bit masking every single time you call it, right? That would make things much easier overall, and this patch simpler, as well as the next one. Oh wait, sbi_ecall() is crazy, and just a pass-through, so that's not going to work, you need a wrapper function for this mess to do that bit twiddeling for you instead of forcing you to do it each time, I guess that's what you are trying to do here, but ick, is it correct? thanks, greg k-h
On Sat, Oct 21, 2023 at 10:16 PM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > On Fri, Oct 20, 2023 at 12:51:38PM +0530, Anup Patel wrote: > > We extend the existing RISC-V SBI earlycon support to use the new > > RISC-V SBI debug console extension. > > > > Signed-off-by: Anup Patel <apatel@ventanamicro.com> > > Reviewed-by: Andrew Jones <ajones@ventanamicro.com> > > --- > > drivers/tty/serial/Kconfig | 2 +- > > drivers/tty/serial/earlycon-riscv-sbi.c | 32 +++++++++++++++++++++---- > > 2 files changed, 29 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig > > index bdc568a4ab66..cec46091a716 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..c21cdef254e7 100644 > > --- a/drivers/tty/serial/earlycon-riscv-sbi.c > > +++ b/drivers/tty/serial/earlycon-riscv-sbi.c > > @@ -15,17 +15,41 @@ 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) > > +{ > > + phys_addr_t pa = __pa(s); > > + > > + if (IS_ENABLED(CONFIG_32BIT)) > > + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, > > + n, lower_32_bits(pa), upper_32_bits(pa), 0, 0, 0); > > + else > > + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, > > + n, pa, 0, 0, 0, 0); > > This is still a bit hard to follow, and I guarantee it will be a pain to > maintain over time, trying to keep both calls in sync, right? > > Why not fix up sbi_ecall() to get this correct instead? It should be > handling phys_addr_t values, not forcing you to do odd bit masking every > single time you call it, right? That would make things much easier > overall, and this patch simpler, as well as the next one. On RV32 systems, the physical address can be 34bits wide hence the on RV32 we have to pass physical address as two parameters whereas on RV64 entier physical address can be passed as single parameter. > > Oh wait, sbi_ecall() is crazy, and just a pass-through, so that's not > going to work, you need a wrapper function for this mess to do that bit > twiddeling for you instead of forcing you to do it each time, I guess > that's what you are trying to do here, but ick, is it correct? Yes, it is better to have a wrapper function to hide the differences of RV32 and RV64 systems. I will update. > > thanks, > > greg k-h > > -- > kvm-riscv mailing list > kvm-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kvm-riscv Regards, Anup
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index bdc568a4ab66..cec46091a716 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..c21cdef254e7 100644 --- a/drivers/tty/serial/earlycon-riscv-sbi.c +++ b/drivers/tty/serial/earlycon-riscv-sbi.c @@ -15,17 +15,41 @@ 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) +{ + phys_addr_t pa = __pa(s); + + if (IS_ENABLED(CONFIG_32BIT)) + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, + n, lower_32_bits(pa), upper_32_bits(pa), 0, 0, 0); + else + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, + n, pa, 0, 0, 0, 0); +} + 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_spec_version >= sbi_mk_version(2, 0)) && + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { + 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);