Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp843136rdb; Fri, 20 Oct 2023 00:23:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjl6odhKLNw4VHCIHITpwmkil1Ez2HIjL2qGa7gS+l6BdoMEra5pJ3/gmGu5mwAs5Jj8zE X-Received: by 2002:aa7:8bcf:0:b0:68e:36b1:3d7f with SMTP id s15-20020aa78bcf000000b0068e36b13d7fmr944202pfd.18.1697786618341; Fri, 20 Oct 2023 00:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697786618; cv=none; d=google.com; s=arc-20160816; b=OnHrzbrlEBprD4Jkb+KLT6NP5Yx0RBhR+6VU/0yi81c7kXlHKn3le4n7asTBoQz6OU ke1qPwpJzoXwsheoxZEdSLcRy2RwFFPaISnL8UGQfCYcGBzqiZLmo6gx+X5E2Gz4qq7F 5o0JqrZ41dG+d9EoDOPH/iD3HRjTo194tEPZUDrTnpY6tDlYHPKO5XlcxV9fw2N0CLaB NCaUmnIiEP9/TLqNP20ICslEghQI+CojiJfRkS+GVX2ytckgxYs2OE9gqLod9vbYWAlR XUAFjB5QXaAtN/hZLSDteX7yEYPt7L8P9TWTfxC8pwx/AM4ITcnlMsH5O0O2f38FmCrO T+pA== 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=jRerAerNbb8Gix3xbbzThpKCfwsEd5HQVNj+VzWX/14=; fh=OfNDhWBTBAuUy+hoy8Y3XMW7PkzxeKRBsc+xFswuT9E=; b=novPHN+rxMtpvQQJpwq/Kka4U/NaOwNT4MqiVl3W0f6pI80UnxOYVJJcfxdMBqBGVm 4SU9oSsh0jT1z1NNYkMAJEYDSzQYuBqB4xHpyEobAEP8g9nvW0F35vmZD1XqCEto41Sh UjMrIogZHsPXUt5MHREIogBoTW+gwXlJfocS2nYNhHLR3EtF4pXD2YSH4XxpRlcKUB4u KeEOW2qSmD2EN6kxuW3rdssoM7M7bVNQFvvz6pAE1QhSVhVyo/tScmB/xOGKz3ksYrdz 1gc5jjzNrs3csPCOmZVP5xt0RTO63da6YqXEeG65OFOPMii5mde8JeAYPi45ks5Y/w6F sopA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=KjrGLpp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l18-20020a056a0016d200b006b7884dcd6csi1425437pfc.14.2023.10.20.00.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:23:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=KjrGLpp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 776D183B1EB8; Fri, 20 Oct 2023 00:23:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376568AbjJTHXH (ORCPT + 99 others); Fri, 20 Oct 2023 03:23:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235626AbjJTHWl (ORCPT ); Fri, 20 Oct 2023 03:22:41 -0400 Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C2E1738 for ; Fri, 20 Oct 2023 00:22:28 -0700 (PDT) Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1dcf357deedso368192fac.0 for ; Fri, 20 Oct 2023 00:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697786546; x=1698391346; 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=jRerAerNbb8Gix3xbbzThpKCfwsEd5HQVNj+VzWX/14=; b=KjrGLpp1+Qq+ISGZ+ROuA4avDxaRmJJ9isYoVfubxNd2s7bolIn8sB3stP11bEJa60 sOi3bmbF9mc/MSwqa7WqW57bIy9iYUr3nuUtQcKOxjNatzUNi8i+XCWQbcvvUm2jmmU7 dXK/TA/ZkvNsjDurFfIPb89jCO6/roRHvkXco/uRPbAcbLQy01E9x/TbJLqu4o8jpJtS EjNybfDZCbhhJxnQLnH/q7kx23A1NLxjAR/RaFs2Fs0JOy62oawxhXkyA1EcU6ooZPqf kqSAKIWUIwaoanzV1/wYTVK9N1D6Oq4UjnZS95RjiH88kgMvhIJcCSDoUKSG1V7OGHOD M8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697786546; x=1698391346; 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=jRerAerNbb8Gix3xbbzThpKCfwsEd5HQVNj+VzWX/14=; b=e3ZS9CJva6vGe/cqG5RWg8zHrtc2yqlnH/3hLPfrYg+rz+AL1mQupI0MjRkPKTA50o QYcYtp/ZhgMbsmriQ7LynpQ9Ms+Hoofkg2MpKOBnm4ez/ESUgnf08ZA6SGpARkmlmucn zB6uMpRqS6JxoZY/hZpW4itgAEvsHyopvkvKsrcYk/+Yk6V8Q3VD7N8LYqRSUKUhMecx 9aGwNwnNlos84IrPE1xAb2ECR5VXc5Ju1XhrQ8MghXK/IEwqQiV/ODZMTfRnyYeDsUSY /gQykubIbUqhLTDKc04WczAjflpmmUpzHLFuS1/tZSEEe2enX7Kjdh0ndMLQHflQ+81X 2DUQ== X-Gm-Message-State: AOJu0YxzcJh9oXUMMLzct0IKWcWa/w7rA87dhnDoE4Bh/lCx6OiLsmrU 0xDuxwsQwop3+28v7BgCf8gBYA== X-Received: by 2002:a05:6871:5225:b0:1ea:2ed0:2978 with SMTP id ht37-20020a056871522500b001ea2ed02978mr1202977oac.22.1697786546202; Fri, 20 Oct 2023 00:22:26 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:22:25 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: 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 , Anup Patel Subject: [PATCH v3 8/9] tty: Add SBI debug console support to HVC SBI driver Date: Fri, 20 Oct 2023 12:51:39 +0530 Message-Id: <20231020072140.900967-9-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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 00:23:32 -0700 (PDT) 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); + 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); + if (ret.error) + return 0; + + return ret.value; +} + +static const struct hv_ops hvc_sbi_dbcn_ops = { + .put_chars = hvc_sbi_dbcn_tty_put, + .get_chars = hvc_sbi_dbcn_tty_get, +}; + +static int __init hvc_sbi_init(void) +{ + int err; + + if ((sbi_spec_version >= sbi_mk_version(2, 0)) && + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { + err = PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_dbcn_ops, 16)); + if (err) + return err; + hvc_instantiate(0, 0, &hvc_sbi_dbcn_ops); + } else { + if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) { + err = 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