Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp340162rda; Sat, 21 Oct 2023 09:46:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER+O1NtJVIkA+ZUq6KEWvfRu9zRrnK5/vqyoIm0tO2CIZmF1axyZUpsCpaZQSaiQN5i3pV X-Received: by 2002:a05:6358:63a1:b0:13a:a85b:d024 with SMTP id k33-20020a05635863a100b0013aa85bd024mr6444458rwh.30.1697906794820; Sat, 21 Oct 2023 09:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697906794; cv=none; d=google.com; s=arc-20160816; b=gRSg23ZeJZfvbbwpANQt7vnDCo9PNFtVK6oB4R+8wK64PJ5DlfDEPmMkMCB+Hkq4G4 OP+amhJSWps+jhmY3gTsYAPgFnTY3CmpLFjQDrGLdGPlUmRzJTcatZQ+IO68ZlEA1hIV 1hDOfyd3TYwqNLSbAjW/95eRoq4r1SDGyeC3RLJcj3vC+v05tmnIS12u4cZ3sVaL5zso T0z9b/LP5c2cJjsJMpCx0OzM4+ucCiUPYKN2KkUef1oYg8Bd04e0BeGG/fTLYJOcBmUh 0g1v4asghBGlbo2eeOHuR1yz2cEnbgkDk8ZeJeYSaPGu1l9qjsPmf/1PFJkexdD8zU8x GLCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JpqZ/QuhccWgOBQRQFDJkNiaYqQT0y/crvAPH8ZA3eE=; fh=90bD+2NM68pp+EKVCN45xT00TQqc0qSqSQqkq/mOpp0=; b=wzsAM1cYa++YocndyGl5SNC8RjO+Kso7fsrLk2w/tUmJ6omtMrlMQUFSbZOsBNxf29 wUhWMZ7CiPefi1v5n7OeIbF8WjcvAFWs5u5t+qqWqTc6ZIWS2PNzejAmsyTGe5XeSuVg KFd2Ziz5C3KvKmT0CijZvSSGZIep6uszwXD2/eDU1gueN1OaypsQmi850/RR8YqEUw+4 rg2arHEq7sUWg7L0J/+cCkZkP4xe0CjwdXfCEFQlV48WrBtevgw0vADyqxrx1Dq95s5K jGB608HNdpA5cDCu2jI16p0qcm7lXDSwhA4C8ETIL27krj771mg9/F697Xt12q81pi4I sAZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jWi3ztDg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r36-20020a635d24000000b00563d74b6347si3868660pgb.863.2023.10.21.09.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 09:46:34 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=jWi3ztDg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F2DD780417F3; Sat, 21 Oct 2023 09:46:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231794AbjJUQqa (ORCPT + 99 others); Sat, 21 Oct 2023 12:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbjJUQq3 (ORCPT ); Sat, 21 Oct 2023 12:46:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2A60DD; Sat, 21 Oct 2023 09:46:22 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E9B7C433C7; Sat, 21 Oct 2023 16:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1697906782; bh=QA1JELgGP1CsBBp3+FEwheuuXUtC5NcVTyALFKgjWxs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jWi3ztDgfd2In+Cpk7pjAzhuWb6ZKaeBrI7z2dT43VzEA+KWNpCKeBuH13HC6D1xN v4z+lbijsAF5WzYCOv3kZwvJuv5z3nMT40wExGeDPZT213BSk9cJjnG76st2LiltCA Qo/Lt6pgpi2+9muYtK8s2EAJ4Nfkr01oT948vwqc= Date: Sat, 21 Oct 2023 18:46:19 +0200 From: Greg Kroah-Hartman To: Anup Patel Cc: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Jiri Slaby , Conor Dooley , Andrew Jones , 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, Atish Patra Subject: Re: [PATCH v3 8/9] tty: Add SBI debug console support to HVC SBI driver Message-ID: <2023102153-retread-narrow-54ee@gregkh> References: <20231020072140.900967-1-apatel@ventanamicro.com> <20231020072140.900967-9-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231020072140.900967-9-apatel@ventanamicro.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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]); Sat, 21 Oct 2023 09:46:34 -0700 (PDT) On Fri, Oct 20, 2023 at 12:51:39PM +0530, Anup Patel wrote: > 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 | 82 ++++++++++++++++++++++++++++++--- > 2 files changed, 76 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..56da1a4b5aca 100644 > --- a/drivers/tty/hvc/hvc_riscv_sbi.c > +++ b/drivers/tty/hvc/hvc_riscv_sbi.c > @@ -39,21 +39,89 @@ 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; > + struct sbiret ret; > + > + 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); > + } > + > + if (IS_ENABLED(CONFIG_32BIT)) > + ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, > + count, lower_32_bits(pa), upper_32_bits(pa), > + 0, 0, 0); > + else > + ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, > + count, pa, 0, 0, 0, 0); Again, you need a helper function here to keep you from having to keep this all in sync. > + if (ret.error) > + return 0; > + > + return count; > } > -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; > + struct sbiret ret; > + > + 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); > + } > + > + if (IS_ENABLED(CONFIG_32BIT)) > + ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ, > + count, lower_32_bits(pa), upper_32_bits(pa), > + 0, 0, 0); > + else > + ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ, > + count, pa, 0, 0, 0, 0); And here too. thanks, greg k-h