Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1032692rdb; Fri, 20 Oct 2023 06:47:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdYLn5uhq3JRLYQG25E1I5Mukxx0dVvKmydR6n/BCBpeHaP771bEJC3Ncyq0YcfwYDNEdM X-Received: by 2002:a05:6830:3145:b0:6ce:29cd:b699 with SMTP id c5-20020a056830314500b006ce29cdb699mr2341342ots.10.1697809645745; Fri, 20 Oct 2023 06:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697809645; cv=none; d=google.com; s=arc-20160816; b=lMdMkrvyFhW5h3XAY927wPWsIrqy6tQU8bpkIMA2jFbY5YWEWumHSMqReNBrhHmyR+ DycfVvS9a9bUXAY5G6PnPEitf1aGM/LqPtv89UtH9hns11ibRb3piaEwOnqERnwXPluH IoMoS7LEHzsJa35mbK16C5G6HtJc+rgvzpZTe2NRv1TmpaVmVf/JaeYbnTFkjkSUK6rp 6L0WvOLCxrMsDfu1BYssq/TF4PwuQLqwmquQyJ/rtqXSHiylo7U3hiui6E8kiQO6fVSr vr8AGNdtcSutf7XPBLgtiq5NBQ5ZRSmKS6YFIWihd5btQek3q/SlIUJwUaNuoTkHJVmb zM0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ujFKaHWQlVUmMQlPTcdZIic60Ioy7TSqQ3nDhHoDDn0=; fh=A9pKLZk2XxrPNa0Pnlm/MYmPI6NZjVnMK+TlQgbpYLE=; b=AhVTbC5ruVeJaJG4K811pAQO2VvTyPdzTWn7NisKVX18lhyFdYgD1HeMwIsT1OLcq9 pl44OyZ4cE2BNE92jRMNFBqkw7q1hIQPavXDbMVr9FIovCt9hwesl9EagsW5IaJ/yetn dF8Ig12cYHF0Qbr6wad2xWxjobWjsANhoyRVjmFTipOh1gYKYUAZWkMAvtwiSn8k7RTf TxQ/Ah6Lc/E+eq78gdUUeQY6jGup2g9at53x5o9ZIHmMn1/0T1uIqeJAW4tYPavbHN5K WtluYANISOPE7uiViyb6M/qnBf3aDYUb8kUoy55gG0VT8MpGYXTXM6h0MHv+nV+h26cG 0aRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=P6hJA9XH; 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q7-20020aa79607000000b00665c24182bcsi1930528pfg.219.2023.10.20.06.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:47:25 -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=@ventanamicro.com header.s=google header.b=P6hJA9XH; 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 7EDE481BEEBF; Fri, 20 Oct 2023 06:47:24 -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 S1377469AbjJTNrV (ORCPT + 99 others); Fri, 20 Oct 2023 09:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377438AbjJTNrU (ORCPT ); Fri, 20 Oct 2023 09:47:20 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAFD3CA for ; Fri, 20 Oct 2023 06:47:16 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5a9bc2ec556so583234a12.0 for ; Fri, 20 Oct 2023 06:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697809636; x=1698414436; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ujFKaHWQlVUmMQlPTcdZIic60Ioy7TSqQ3nDhHoDDn0=; b=P6hJA9XHLrlREANM92ye5l+V/OvcbTs9+UCzklsxfA+8AWC2JFc3ImCtV4ectOGTkh ABMJoNI3/T1b90RNFNBMNHvPEyZ5mcPXcGCP+OjLVezORt1WOZeJhjXp4D7Fdu+BmDt2 736ngLQ/QdC6O0hRN+h8OzjY2f4Ba+vmCBJjrLMBOoRu49V/QyPAZX33coy7A7VaCjCF 4zyAGQA91ak6Q6I3bYsdbGrFTZ9NFWiIdUE07XMVb8M0+KTF+785ac3Czh1ic/9ArUtD 4TjOavBfPz7YIGHs3zm1hwp/hI1OGwboG22n3JL0bkksqaCoTjCfvQvzqKDjyFQli1Sh c5JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697809636; x=1698414436; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ujFKaHWQlVUmMQlPTcdZIic60Ioy7TSqQ3nDhHoDDn0=; b=FdkxRause94nZHZgRWoXk/reI8+1FfF3lOUmbwQPLcNTxAgRxuRflml+JO3eumCS1b mAnnnbEZbsYQ3CIFdO/6kXWO6wUAj3RRyt0fJHap0nv6nBmordFLopjGsbf/oiPqEwRf /i2HS8l2gRiMSNYuGGV0nGeUZt8a9gdi2vRcj121eLA1oz7+Cse4Uf173jRoH9YRoiUJ s3B7b8kRzzV+IMyX6xkNQWkLm16AoKtAMRlx3nXJI3PX3HyO1Yc9BP6emjG5DmpGwG/b oe4ZOzvb0CMuZPiWlb0fLDgnQYNmhz2HaTs1HC2q2S+whh8tDEN8fSnrdx3PH7JkcyUY HMBQ== X-Gm-Message-State: AOJu0YznV4VJwlQYbfKbflkvEOZsIDjZQBoxeES5Y5k/uRAJUzoLAv66 q/UqcoM0GodIseTfwmyYuwGUVR+JkhMGHpxtYjC+IA== X-Received: by 2002:a05:6a21:66cb:b0:172:f4e:5104 with SMTP id ze11-20020a056a2166cb00b001720f4e5104mr1738132pzb.20.1697809636011; Fri, 20 Oct 2023 06:47:16 -0700 (PDT) MIME-Version: 1.0 References: <20231020072140.900967-1-apatel@ventanamicro.com> <20231020072140.900967-9-apatel@ventanamicro.com> <20231020-f1ec2b7e384a4cfeae39966f@orel> In-Reply-To: <20231020-f1ec2b7e384a4cfeae39966f@orel> From: Anup Patel Date: Fri, 20 Oct 2023 19:17:03 +0530 Message-ID: Subject: Re: [PATCH v3 8/9] tty: Add SBI debug console support to HVC SBI driver To: Andrew Jones Cc: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby , Conor Dooley , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_BLOCKED, 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 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, 20 Oct 2023 06:47:24 -0700 (PDT) On Fri, Oct 20, 2023 at 4:16=E2=80=AFPM Andrew Jones wrote: > > 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, w= hich > > diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_risc= v_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 =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, > > }; > > > > -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 =3D page_to_phys(vmalloc_to_page(buf)) + offset_in_pag= e(buf); > > + if (PAGE_SIZE < (offset_in_page(buf) + count)) > > I thought checkpatch complained about uppercase constants being on the > left in comparisons. Nope checkpatch does not complain about this. > > > + count =3D PAGE_SIZE - offset_in_page(buf); > > + } else { > > + pa =3D __pa(buf); > > + } > > + > > + if (IS_ENABLED(CONFIG_32BIT)) > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRIT= E, > > + count, lower_32_bits(pa), upper_32_bits(p= a), > > + 0, 0, 0); > > + else > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRIT= E, > > + count, pa, 0, 0, 0, 0); > > + if (ret.error) > > + return 0; > > + > > + return count; > > Shouldn't we return ret.value here in case it's less than count? I see we > already do that below in get(). Ahh, yes. Good catch, I will update. > > > } > > -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 =3D page_to_phys(vmalloc_to_page(buf)) + offset_in_pag= e(buf); > > + if (PAGE_SIZE < (offset_in_page(buf) + count)) > > + count =3D PAGE_SIZE - offset_in_page(buf); > > + } else { > > + pa =3D __pa(buf); > > + } > > + > > + if (IS_ENABLED(CONFIG_32BIT)) > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ= , > > + count, lower_32_bits(pa), upper_32_bits(p= a), > > + 0, 0, 0); > > + else > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ= , > > + count, pa, 0, 0, 0, 0); > > + if (ret.error) > > + return 0; > > + > > + return ret.value; > > +} > > + > > +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_spec_version >=3D sbi_mk_version(2, 0)) && > > + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { > > + err =3D PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_dbcn_ops= , 16)); > > Why an outbuf size of only 16? The output buffer size of 16 is a very common choice across HVC drivers. The next best choice is 256. I guess 256 is better so I will go with that. > > > + 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, 16)); > > + 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); > > -- > > 2.34.1 > > > > Thanks, > drew Regards, Anup