OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <ajones@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v5 7/8] lib: utils/serial: Implement console_puts() for semihosting
Date: Wed, 1 Feb 2023 10:03:53 +0100	[thread overview]
Message-ID: <20230201090353.lg67zpqck4nucl2a@orel> (raw)
In-Reply-To: <20230113114110.1916226-8-apatel@ventanamicro.com>

On Fri, Jan 13, 2023 at 05:11:09PM +0530, Anup Patel wrote:
> We implement console_puts() for semihosting serial driver to speed-up
> semihosting based prints.
> 
> 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/utils/serial/semihosting.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/lib/utils/serial/semihosting.c b/lib/utils/serial/semihosting.c
> index 86fa296..773b75e 100644
> --- a/lib/utils/serial/semihosting.c
> +++ b/lib/utils/serial/semihosting.c
> @@ -15,6 +15,7 @@
>  
>  #define SYSOPEN     0x01
>  #define SYSWRITEC   0x03
> +#define SYSWRITE    0x05
>  #define SYSREAD     0x06
>  #define SYSREADC    0x07
>  #define SYSERRNO	0x13
> @@ -93,6 +94,7 @@ static int semihosting_errno(void)
>  }
>  
>  static int semihosting_infd = SBI_ENODEV;
> +static int semihosting_outfd = SBI_ENODEV;
>  
>  static long semihosting_open(const char *fname, enum semihosting_open_mode mode)
>  {
> @@ -141,6 +143,21 @@ static long semihosting_read(long fd, void *memp, size_t len)
>  	return len - ret;
>  }
>  
> +static long semihosting_write(long fd, const void *memp, size_t len)
> +{
> +	long ret;
> +	struct semihosting_rdwr_s write;
> +
> +	write.fd = fd;
> +	write.memp = (void *)memp;
> +	write.len = len;
> +
> +	ret = semihosting_trap(SYSWRITE, &write);
> +	if (ret < 0)
> +		return semihosting_errno();
> +	return len - ret;
> +}
> +
>  /* clang-format on */
>  
>  static void semihosting_putc(char ch)
> @@ -148,6 +165,20 @@ static void semihosting_putc(char ch)
>  	semihosting_trap(SYSWRITEC, &ch);
>  }
>  
> +static void semihosting_puts(const char *str, unsigned long len)
> +{
> +	char ch;
> +	unsigned long i;
> +
> +	if (semihosting_outfd < 0) {
> +		for (i = 0; i < len; i++) {
> +			ch = str[i];
> +			semihosting_trap(SYSWRITEC, &ch);
> +		}
> +	} else
> +		semihosting_write(semihosting_outfd, str, len);
> +}
> +
>  static int semihosting_getc(void)
>  {
>  	char ch = 0;
> @@ -165,12 +196,14 @@ static int semihosting_getc(void)
>  static struct sbi_console_device semihosting_console = {
>  	.name = "semihosting",
>  	.console_putc = semihosting_putc,
> +	.console_puts = semihosting_puts,
>  	.console_getc = semihosting_getc
>  };
>  
>  int semihosting_init(void)
>  {
>  	semihosting_infd = semihosting_open(":tt", MODE_READ);
> +	semihosting_outfd = semihosting_open(":tt", MODE_WRITE);
>  
>  	sbi_console_set_device(&semihosting_console);
>  
> -- 
> 2.34.1
>

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>

Thanks,
drew


  reply	other threads:[~2023-02-01  9:03 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
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 [this message]
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=20230201090353.lg67zpqck4nucl2a@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