Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp241884rdh; Thu, 23 Nov 2023 02:47:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdKPm8B2XaE4iJAFPdniOj76UgOqdhvfbGSOfz5CBzK1qCLSbGsBHOozGUpildAZcGprwJ X-Received: by 2002:a17:90b:38c8:b0:280:14ac:a6db with SMTP id nn8-20020a17090b38c800b0028014aca6dbmr5028000pjb.18.1700736460468; Thu, 23 Nov 2023 02:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700736460; cv=none; d=google.com; s=arc-20160816; b=pG/21x6AAFST6Ly0vDewxu4Tn7J+tugphwtTuUlYE0t+3q5KDHBGSMQ5kZw0udCiVi V/fFZWz0Poj+/hUOtzcNb0wZfntIG1WDpjLuf+FAkT6VAnMzVcAqp/jtQ6Irp/GVbKDi t8s4F2SHMcZmYUHHf5ECKD/VavI7lQTFD6sjM1oJ6JqZvrNdoLuTOsYAeN6Su+fCg01G jJ70Qyh9uOfepOPyZ8NSb4TdggKbff67HE8MnKWdMpZ28Qm8E4wTEzzM+xoJbZ3UtDeo zgKc7BrhDtcWmIOT+dqZtGUrdzD8acb/msizgNDT1aBpREKZ2dHXxp6F6277qVJeht/u ubNw== 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=7pMzVl5pf9UJJ+Fo0I8VraoGZ78XJdMnoApdVbnPwyI=; fh=MumW4bYHu2wWsl5Tk6NoVfWRcZ+272UFRrVgGuM3fB8=; b=Djo5fyzOI0i/YvH0T9O5pbqwRQrhKrZxLPmIGRBMBw22ViyLFiNKeETW5QtQKekwIB Ts/qwJk+aqchODHTdd1jEa7n4Xng8Pbxs+9ee7CGMwhhE1JRFpXAj7/ypwMC3TU+Rjs9 5yxHqv7ursG8chMWxNtzZ3e+mvTR06FEKn44WWD36CKjCBfQQi/yKZpWpswsiRwRRX7I kDEwN+g09y0wjpDvoRM88TlgQ0ZwPSoB5q2aKli5CUnB7s7a4Cm3p9OG+l3a72xPkatX 4+Nib1aqRkkvnuwnaE2BzODCmzg9WtfU4TEVR9ijOxeT/iGV7T4UYUfPUfFSFpDRJQGT NqZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="l+1P/55K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id cz11-20020a17090ad44b00b00280216d7e36si1053996pjb.171.2023.11.23.02.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 02:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="l+1P/55K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 7C7BB808726D; Thu, 23 Nov 2023 02:47:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235213AbjKWKrT (ORCPT + 99 others); Thu, 23 Nov 2023 05:47:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjKWKrI (ORCPT ); Thu, 23 Nov 2023 05:47:08 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B48D4E for ; Thu, 23 Nov 2023 02:47:15 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2856437b584so376569a91.3 for ; Thu, 23 Nov 2023 02:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1700736434; x=1701341234; 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=7pMzVl5pf9UJJ+Fo0I8VraoGZ78XJdMnoApdVbnPwyI=; b=l+1P/55KqdusmhKA4Wd3D1cDY9EIErGd3ChMlBmTF/mKHGJ2k5XQrncqTlxqHiGbrt P0pC1NtXC+eZTz7hZWevNr+pbdQR92Izb/pbThDI6qMVgiNfjXQa8OqhVuv2hDI4ccBz ftPIXvjmvmLYWrNxGoOmnuiiSVNuVC074jLpa/3+uSasquVfm65nyGsssmqBibt+9rZl LLUZuDfxG4dNXq7kcEW0+hU452FhCJBvZm9EH6uByoQkg5M78w7xCXUqJw9B1WAmuJV2 AkFETBkuLsHdWvr2DNPIy6GLpErH06q210OkSoA+2ZldkBia9igl9gy3XX4DDk/cPO9V k9vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700736434; x=1701341234; 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=7pMzVl5pf9UJJ+Fo0I8VraoGZ78XJdMnoApdVbnPwyI=; b=kZdtFAZ/9hkdaEh9Q/XXY/J/J642sog5E8vWBHplhrPaZ05FtJ+q5+0OGaPWIqq+AJ 7NwAlA6GYmKZ5s42gfjXdtACuFj6awm1WUnrt1n5HYpW1NF68lSJPJ1u5Z99YP8VwiI4 vVGLz8Bgti8ctlP/DkdhEa2PO3MmALu9+ZOlXSFWzlc/4t6V9LN/AJpSsl7dg0Q5zwsQ /uhvbXdSivoaNqLduj8/m6bPKP0GSEyzGQCrD17JmZeK91pQA3T6x4SWg09+6hNk12Hd dtBTFby1v+Xb/0Jnx14zx75Ftz2G1s2f2FE8n+r0ezzpWMONtfSP6tMm8DnDAiAeIi1m MlbA== X-Gm-Message-State: AOJu0YyeT6imdbwOnpREe7VANT28hsYmn+AMyAiSR5zui5J5I6+v+b3w 2taaJ7EA9zV7H6hMOj5y8kOy2myxj5CLKCbE50juYw== X-Received: by 2002:a17:90a:187:b0:27d:3fa4:9d9a with SMTP id 7-20020a17090a018700b0027d3fa49d9amr5082578pjc.29.1700736434399; Thu, 23 Nov 2023 02:47:14 -0800 (PST) MIME-Version: 1.0 References: <20231118033859.726692-1-apatel@ventanamicro.com> <20231118033859.726692-3-apatel@ventanamicro.com> <20231120-639982716fbfd33a6fc144d6@orel> In-Reply-To: <20231120-639982716fbfd33a6fc144d6@orel> From: Anup Patel Date: Thu, 23 Nov 2023 16:17:02 +0530 Message-ID: Subject: Re: [PATCH v4 2/5] RISC-V: Add SBI debug console helper routines To: Andrew Jones Cc: Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby , Conor Dooley , linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Thu, 23 Nov 2023 02:47:37 -0800 (PST) On Mon, Nov 20, 2023 at 1:35=E2=80=AFPM Andrew Jones wrote: > > On Sat, Nov 18, 2023 at 09:08:56AM +0530, Anup Patel wrote: > > Let us provide SBI debug console helper routines which can be > > shared by serial/earlycon-riscv-sbi.c and hvc/hvc_riscv_sbi.c. > > > > Signed-off-by: Anup Patel > > --- > > arch/riscv/include/asm/sbi.h | 5 +++++ > > arch/riscv/kernel/sbi.c | 43 ++++++++++++++++++++++++++++++++++++ > > 2 files changed, 48 insertions(+) > > > > diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.= h > > index 66f3933c14f6..ee7aef5f6233 100644 > > --- a/arch/riscv/include/asm/sbi.h > > +++ b/arch/riscv/include/asm/sbi.h > > @@ -334,6 +334,11 @@ static inline unsigned long sbi_mk_version(unsigne= d long major, > > } > > > > int sbi_err_map_linux_errno(int err); > > + > > +extern bool sbi_debug_console_available; > > +int sbi_debug_console_write(unsigned int num_bytes, phys_addr_t base_a= ddr); > > +int sbi_debug_console_read(unsigned int num_bytes, phys_addr_t base_ad= dr); > > + > > #else /* CONFIG_RISCV_SBI */ > > static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) {= return -1; } > > static inline void sbi_init(void) {} > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c > > index 5a62ed1da453..73a9c22c3945 100644 > > --- a/arch/riscv/kernel/sbi.c > > +++ b/arch/riscv/kernel/sbi.c > > @@ -571,6 +571,44 @@ long sbi_get_mimpid(void) > > } > > EXPORT_SYMBOL_GPL(sbi_get_mimpid); > > > > +bool sbi_debug_console_available; > > + > > +int sbi_debug_console_write(unsigned int num_bytes, phys_addr_t base_a= ddr) > > +{ > > + struct sbiret ret; > > + > > + if (!sbi_debug_console_available) > > + return -EOPNOTSUPP; > > + > > + if (IS_ENABLED(CONFIG_32BIT)) > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRIT= E, > > + num_bytes, lower_32_bits(base_addr), > > + upper_32_bits(base_addr), 0, 0, 0); > > + else > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRIT= E, > > + num_bytes, base_addr, 0, 0, 0, 0); > > + > > + return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value= ; > > We can't get perfect mappings, but I wonder if we can do better than > returning ENOTSUPP for "Failed to write the byte due to I/O errors." > > How about > > if (ret.error =3D=3D SBI_ERR_FAILURE) > return -EIO; > > return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value; Seems overkill but I will update anyway. > > > > +} > > + > > +int sbi_debug_console_read(unsigned int num_bytes, phys_addr_t base_ad= dr) > > +{ > > + struct sbiret ret; > > + > > + if (!sbi_debug_console_available) > > + return -EOPNOTSUPP; > > + > > + if (IS_ENABLED(CONFIG_32BIT)) > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ= , > > + num_bytes, lower_32_bits(base_addr), > > + upper_32_bits(base_addr), 0, 0, 0); > > + else > > + ret =3D sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ= , > > + num_bytes, base_addr, 0, 0, 0, 0); > > + > > + return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value= ; > > Same comment as above. Okay. > > > +} > > + > > void __init sbi_init(void) > > { > > int ret; > > @@ -612,6 +650,11 @@ void __init sbi_init(void) > > sbi_srst_reboot_nb.priority =3D 192; > > register_restart_handler(&sbi_srst_reboot_nb); > > } > > + if ((sbi_spec_version >=3D sbi_mk_version(2, 0)) && > > + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { > > + pr_info("SBI DBCN extension detected\n"); > > + sbi_debug_console_available =3D true; > > + } > > } else { > > __sbi_set_timer =3D __sbi_set_timer_v01; > > __sbi_send_ipi =3D __sbi_send_ipi_v01; > > -- > > 2.34.1 > > > > Otherwise, > > Reviewed-by: Andrew Jones > > Thanks, > drew Regards, Anup