From: Andrew Jones <ajones@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v5 5/8] lib: sbi: Implement SBI debug console extension
Date: Wed, 1 Feb 2023 09:58:15 +0100 [thread overview]
Message-ID: <20230201085815.77wcmkw76l2in5qc@orel> (raw)
In-Reply-To: <20230113114110.1916226-6-apatel@ventanamicro.com>
On Fri, Jan 13, 2023 at 05:11:07PM +0530, Anup Patel wrote:
> We implement SBI debug console extension as one of the replacement
> SBI extensions. This extension is only available when OpenSBI platform
> provides a console device to generic library.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> Reviewed-by: Atish Patra <atishp@rivosinc.com>
> Reviewed-by: Xiang W <wxjstz@126.com>
> Reviewed-by: Bin Meng <bmeng@tinylab.org>
> ---
> lib/sbi/Kconfig | 4 +++
> lib/sbi/objects.mk | 3 ++
> lib/sbi/sbi_ecall_dbcn.c | 72 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 79 insertions(+)
> create mode 100644 lib/sbi/sbi_ecall_dbcn.c
>
> diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig
> index df74bba..ef6728b 100644
> --- a/lib/sbi/Kconfig
> +++ b/lib/sbi/Kconfig
> @@ -26,6 +26,10 @@ config SBI_ECALL_PMU
> bool "Performance Monitoring Unit extension"
> default y
>
> +config SBI_ECALL_DBCN
> + bool "Debug Console extension"
> + default y
> +
> config SBI_ECALL_LEGACY
> bool "SBI v0.1 legacy extensions"
> default y
> diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
> index c774ebb..319f38d 100644
> --- a/lib/sbi/objects.mk
> +++ b/lib/sbi/objects.mk
> @@ -37,6 +37,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_SRST) += sbi_ecall_srst.o
> carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_PMU) += ecall_pmu
> libsbi-objs-$(CONFIG_SBI_ECALL_PMU) += sbi_ecall_pmu.o
>
> +carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_DBCN) += ecall_dbcn
> +libsbi-objs-$(CONFIG_SBI_ECALL_DBCN) += sbi_ecall_dbcn.o
> +
> carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_LEGACY) += ecall_legacy
> libsbi-objs-$(CONFIG_SBI_ECALL_LEGACY) += sbi_ecall_legacy.o
>
> diff --git a/lib/sbi/sbi_ecall_dbcn.c b/lib/sbi/sbi_ecall_dbcn.c
> new file mode 100644
> index 0000000..bfa40e9
> --- /dev/null
> +++ b/lib/sbi/sbi_ecall_dbcn.c
> @@ -0,0 +1,72 @@
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Copyright (c) 2022 Ventana Micro Systems Inc.
> + *
> + * Authors:
> + * Anup Patel <apatel@ventanamicro.com>
> + */
> +
> +#include <sbi/sbi_console.h>
> +#include <sbi/sbi_domain.h>
> +#include <sbi/sbi_error.h>
> +#include <sbi/sbi_ecall.h>
> +#include <sbi/sbi_ecall_interface.h>
> +#include <sbi/sbi_trap.h>
> +#include <sbi/riscv_asm.h>
> +
> +static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
> + const struct sbi_trap_regs *regs,
> + unsigned long *out_val,
> + struct sbi_trap_info *out_trap)
> +{
> + ulong smode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >>
> + MSTATUS_MPP_SHIFT;
> +
> + switch (funcid) {
> + case SBI_EXT_DBCN_CONSOLE_WRITE:
> + case SBI_EXT_DBCN_CONSOLE_READ:
> + /*
> + * On RV32, the M-mode can only access the first 4GB of
> + * the physical address space because M-mode does not have
> + * MMU to access full 34-bit physical address space.
> + *
> + * Based on above, we simply fail if the upper 32bits of
> + * the physical address (i.e. a2 register) is non-zero on
> + * RV32.
> + */
> +#if __riscv_xlen == 32
> + if (regs->a2)
> + return SBI_ERR_FAILED;
The spec drafts says SBI_ERR_FAILED is only for I/O errors. I think
we should extend the spec draft to point this situation out and return
SBI_ERR_INVALID_ADDRESS.
> +#endif
> + if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
> + regs->a1, regs->a0, smode,
> + SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))
> + return SBI_EINVALID_ADDR;
The spec draft says this should be SBI_ERR_INVALID_PARAM
> + if (funcid == SBI_EXT_DBCN_CONSOLE_WRITE)
> + sbi_nputs((const char *)regs->a1, regs->a0);
> + else
> + *out_val = sbi_ngets((char *)regs->a1, regs->a0);
> + return 0;
> + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
> + sbi_putc(regs->a0);
> + return 0;
> + default:
> + break;
> + }
> +
> + return SBI_ENOTSUPP;
> +}
> +
> +static int sbi_ecall_dbcn_probe(unsigned long extid, unsigned long *out_val)
> +{
> + *out_val = (sbi_console_get_device()) ? 1 : 0;
nit: Unnecessary ()
> + return 0;
> +}
> +
> +struct sbi_ecall_extension ecall_dbcn = {
> + .extid_start = SBI_EXT_DBCN,
> + .extid_end = SBI_EXT_DBCN,
> + .handle = sbi_ecall_dbcn_handler,
> + .probe = sbi_ecall_dbcn_probe,
> +};
> --
> 2.34.1
>
>
Thanks,
drew
next prev parent reply other threads:[~2023-02-01 8:58 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 11:41 [PATCH v5 0/8] OpenSBI debug console support Anup Patel
2023-01-13 11:41 ` [PATCH v5 1/8] include: Add defines for SBI debug console extension Anup Patel
2023-01-31 17:26 ` Andrew Jones
2023-02-09 16:51 ` Anup Patel
2023-01-13 11:41 ` [PATCH v5 2/8] lib: sbi: Add sbi_nputs() function Anup Patel
2023-01-31 17:32 ` Andrew Jones
2023-02-09 16:59 ` Anup Patel
2023-02-09 17:02 ` Jessica Clarke
2023-01-13 11:41 ` [PATCH v5 3/8] lib: sbi: Add sbi_ngets() function Anup Patel
2023-01-31 17:34 ` Andrew Jones
2023-01-13 11:41 ` [PATCH v5 4/8] lib: sbi: Add sbi_domain_check_addr_range() function Anup Patel
2023-02-01 8:48 ` Andrew Jones
2023-01-13 11:41 ` [PATCH v5 5/8] lib: sbi: Implement SBI debug console extension Anup Patel
2023-02-01 8:58 ` Andrew Jones [this message]
2023-02-10 4:23 ` Anup Patel
2023-02-10 5:19 ` Jessica Clarke
2023-02-10 5:29 ` Anup Patel
2023-02-01 9:35 ` Andrew Jones
2023-02-10 4:25 ` Anup Patel
2023-01-13 11:41 ` [PATCH v5 6/8] lib: sbi: Add console_puts() callback in the console device Anup Patel
2023-02-01 9:00 ` Andrew Jones
2023-02-04 13:14 ` Xiang W
2023-02-01 9:30 ` Andrew Jones
2023-02-01 9:37 ` Andrew Jones
2023-01-13 11:41 ` [PATCH v5 7/8] lib: utils/serial: Implement console_puts() for semihosting Anup Patel
2023-02-01 9:03 ` Andrew Jones
2023-01-13 11:41 ` [PATCH v5 8/8] lib: sbi: Speed-up sbi_printf() and friends using nputs() Anup Patel
2023-02-01 9:22 ` Andrew Jones
2023-02-10 5:41 ` Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230201085815.77wcmkw76l2in5qc@orel \
--to=ajones@ventanamicro.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox