From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiang W Date: Sat, 04 Feb 2023 21:14:45 +0800 Subject: [PATCH v5 6/8] lib: sbi: Add console_puts() callback in the console device In-Reply-To: <20230201090013.ulgfsudxkf3zjhtw@orel> References: <20230113114110.1916226-1-apatel@ventanamicro.com> <20230113114110.1916226-7-apatel@ventanamicro.com> <20230201090013.ulgfsudxkf3zjhtw@orel> Message-ID: List-Id: To: opensbi@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit ? 2023-02-01???? 10:00 +0100?Andrew Jones??? > On Fri, Jan 13, 2023 at 05:11:08PM +0530, Anup Patel wrote: > > We add console_puts() callback in the console device which allows > > console drivers (such as semihosting) to implement a specialized > > way to output character string. > > > > Signed-off-by: Anup Patel > > Reviewed-by: Atish Patra > > Reviewed-by: Xiang W > > Reviewed-by: Bin Meng > > --- > > ?include/sbi/sbi_console.h |? 3 +++ > > ?lib/sbi/sbi_console.c???? | 19 ++++++++++++++----- > > ?2 files changed, 17 insertions(+), 5 deletions(-) > > > > diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h > > index 660c239..8e95b9d 100644 > > --- a/include/sbi/sbi_console.h > > +++ b/include/sbi/sbi_console.h > > @@ -19,6 +19,9 @@ struct sbi_console_device { > > ????????/** Write a character to the console output */ > > ????????void (*console_putc)(char ch); > > ? > > +???????/** Write a character string to the console output */ > > +???????void (*console_puts)(const char *str, unsigned long len); We should add a comment here that \r\n needs to be output when \n is output. Otherwise, the output effect of sbi_nputs will be inconsistent. Regards, Xiang W > > + > > ????????/** Read a character from the console input */ > > ????????int (*console_getc)(void); > > ?}; > > diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c > > index 89d6a49..c1b9f73 100644 > > --- a/lib/sbi/sbi_console.c > > +++ b/lib/sbi/sbi_console.c > > @@ -12,6 +12,7 @@ > > ?#include > > ?#include > > ?#include > > +#include > > ? > > ?static const struct sbi_console_device *console_dev = NULL; > > ?static spinlock_t console_out_lock??????????? = SPIN_LOCK_INITIALIZER; > > @@ -44,9 +45,13 @@ void sbi_putc(char ch) > > ?void sbi_puts(const char *str) > > ?{ > > ????????spin_lock(&console_out_lock); > > -???????while (*str) { > > -???????????????sbi_putc(*str); > > -???????????????str++; > > +???????if (console_dev && console_dev->console_puts) { > > +???????????????console_dev->console_puts(str, sbi_strlen(str)); > > +???????} else { > > +???????????????while (*str) { > > +???????????????????????sbi_putc(*str); > > +???????????????????????str++; > > +???????????????} > > ????????} > > ????????spin_unlock(&console_out_lock); > > ?} > > @@ -56,8 +61,12 @@ void sbi_nputs(const char *str, unsigned long len) > > ????????unsigned long i; > > ? > > ????????spin_lock(&console_out_lock); > > -???????for (i = 0; i < len; i++) > > -???????????????sbi_putc(str[i]); > > +???????if (console_dev && console_dev->console_puts) { > > +???????????????console_dev->console_puts(str, len); > > +???????} else { > > +???????????????for (i = 0; i < len; i++) > > +???????????????????????sbi_putc(str[i]); > > +???????} > > ????????spin_unlock(&console_out_lock); > > ?} > > ? > > -- > > 2.34.1 > > > > Reviewed-by: Andrew Jones