Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp500574rdb; Fri, 17 Nov 2023 05:11:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+fGofL4u3dD4vo7qdQVOCrwE5gOZc9E/bpsisHF1Fux/8RmOMVwk80mijRye70UHBOHQk X-Received: by 2002:a17:90b:1d8e:b0:27d:3be:8e13 with SMTP id pf14-20020a17090b1d8e00b0027d03be8e13mr17001907pjb.12.1700226710721; Fri, 17 Nov 2023 05:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700226710; cv=none; d=google.com; s=arc-20160816; b=hHAMLnlro89Vq0OW/Y1BBkj0XywV3dWDAw2zVnYVV6kBqyPs3RjbeF1hO1Xq81AmtK Tyo3Bq4fajEZB0EPS/gXyHghC08SW2CTQQqNCuhp1QSrG2b16dZGDKDnwF7SjKxLEgx7 CaSovPxVSyL0e6Lfi3sKEYj8lCshF0Iv8AxSkpLf+gzOKoR/BYcPswM+nB6tWGDpUd2U ew7kktZwmYR6Nl4WYw6u4L3Ip6fxXRtH3hPNS+1ii+N2S1HUqawvP/P3NINKJpi68FVL g206oAaYnmUCTQ/jULswXh0AJ3WzuZHP64J5Gp9Zocvde3f4YfjdT1oWGmVDPinK5/OM Axxw== 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=6E9rdo8qzUdOfFpLyb8P/NwaQhOJy8xXp5m1DZcVMbs=; fh=KBd3BISmMWmKrDalsSejRbQA/TkysZqZnkUBLqj39kM=; b=tHG74mRWk5R7TmXj5bQCMsgUF9K7sbmHBNgWTerWlfUVt71xnoSO/sVw2GS8rrXFK8 +otfLjSJ081YcSn9MMkEI3Cc2Z7AseTSBbxeNGjlnr5n7kpeK1TqhVjQ+DX1FbZDgn8U QxZ1/LuAV8oMqbd0ucZ8Pq3atQlq5414P6aFn9vK4T6nHvVbzzbLHQHiHIhAwy5F+loz Md3JZEsbeyS9AZkQ/TI+Pvc830PTvI2o7nx12WA6SrRLmrvR0e+cIjwVairjp7HNhWhG m/Xf+cYZzw500rCrChXVtOVyVwwWkobH7Oh23UyzYCxZ4V+kl+HME2Y2I/rm0c5IiDLP kq2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=0Jh9IEnc; 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 nw10-20020a17090b254a00b0027d30e575ccsi2046438pjb.115.2023.11.17.05.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 05:11:50 -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=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=0Jh9IEnc; 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 370A182A0BF8; Fri, 17 Nov 2023 05:11:40 -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 S1345923AbjKQNLj (ORCPT + 99 others); Fri, 17 Nov 2023 08:11:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbjKQNLi (ORCPT ); Fri, 17 Nov 2023 08:11:38 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A390D56 for ; Fri, 17 Nov 2023 05:11:35 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5c19a328797so1459671a12.3 for ; Fri, 17 Nov 2023 05:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1700226694; x=1700831494; 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=6E9rdo8qzUdOfFpLyb8P/NwaQhOJy8xXp5m1DZcVMbs=; b=0Jh9IEncApe3dbjC0pYFA6uGR96saTAaIoi1TMkeMwBv+5Oswt9hbuRJ9gjctTfZVv iMeoPeCv+tjez7DDFpZGYLpF/ix0UIse7qdmeKx/YKD6UZaOaF7s2Bl3/WoIOM9npcJd k4/VCKT43U6Ra9sPQiQL9xyaRHnRTWiEf4CJTybfC2jSvKB1gUsMrvLdklhzT079E9Qx 5BnVRW2uSlZ6PyUutWCMgFdYUrAQzM88i0AJaWuN/lB0lsAmhPJ8HMEuP5gsxlx+c+XF GIFUUTcqdZL38LIARq68Z1xfFsG4inBCIhfeqGKvd1EODnp9bSBmRUGQlvHWoiGIvVqs sjiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700226694; x=1700831494; 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=6E9rdo8qzUdOfFpLyb8P/NwaQhOJy8xXp5m1DZcVMbs=; b=DFaTCrnjzT0YpncQOS0cJglfhSfnKuFi9Way1k6DdqFt8Af9fC8nV9mJyhVnp9z+aG AO7MZotg6xWrqXLDWWHoGLKX/TKUTr4Zhy3hjRe0c8gBfxnys1UJE3OQ/U/cQutN35ka BdCdXkBKoa5xR+PoAOolfO7CV/6LAQHoRSOUK3/5oE45K5uIKPJvZoKrKy5XnFBp6H4A FLi1H6PGBk05Aqbgn/w1sBQLpIeykcVgWMUS3rOZakicLjHN3vMjj+wBPSmI9jSga8nn XaoBFSt9JSDv+ELV2szpFJKbr8ruW7XU6w3rCIsa/te07s3IxvZj2fvkD80uNP2jdU6B 7lqA== X-Gm-Message-State: AOJu0Yy7KPdcdKW+R5N1AL3ZOROLOo04TU6z+DxC3/tQ6Fmp1XcWoun8 MPZkR1XmNEIVRRHSo3LppYBUgwGkYOdYVwlJqFMXFQ== X-Received: by 2002:a17:90a:974a:b0:281:3a4a:2e61 with SMTP id i10-20020a17090a974a00b002813a4a2e61mr14672875pjw.14.1700226694377; Fri, 17 Nov 2023 05:11:34 -0800 (PST) MIME-Version: 1.0 References: <20231020072140.900967-1-apatel@ventanamicro.com> <20231020072140.900967-9-apatel@ventanamicro.com> <2023102153-retread-narrow-54ee@gregkh> In-Reply-To: <2023102153-retread-narrow-54ee@gregkh> From: Anup Patel Date: Fri, 17 Nov 2023 18:41:23 +0530 Message-ID: Subject: Re: [PATCH v3 8/9] tty: Add SBI debug console support to HVC SBI driver To: Greg Kroah-Hartman Cc: Anup Patel , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, 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 05:11:40 -0800 (PST) On Sat, Oct 21, 2023 at 10:16=E2=80=AFPM Greg Kroah-Hartman 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)) > > + 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); > > Again, you need a helper function here to keep you from having to keep > this all in sync. Sure, I will update. > > > + 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 =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); > > And here too. Okay. > > thanks, > > greg k-h Regards, Anup