Skip to contentSkip to conversation

lib: utils/serial: Optimize semihosting_putc implementation

PATCH New [email protected] 5 participants 9 messages Oct 18, 2023 – Nov 17, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
 lib/utils/serial/semihosting.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/utils/serial/semihosting.c +5 -5
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-	semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
 	char ch;
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
 	return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+	semihosting_puts(&ch, 1);
+}
+
 static int semihosting_getc(void)
 {
 	char ch = 0;
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

Quoted 34 lines · On Wed, Oct 18, 2023 at 10:42?AM <[email protected]> wrote:

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
 lib/utils/serial/semihosting.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/utils/serial/semihosting.c +0 -5
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-       semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
        char ch;

lib/utils/serial/semihosting.c static unsigned long semihosting_puts(const char *str, unsigned long len) · line 185

Quoted 8 lines
lib/utils/serial/semihosting.c +5 -0
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
        return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+       semihosting_puts(&ch, 1);
+}
+

When console_puts() was introduced by commit c43903c4eae41 ("lib: sbi:
Add console_puts() callback in the console device"), sbi_putc() became unnecessary and confusing. See below code:

void sbi_putc(char ch)

{
        if (console_dev && console_dev->console_putc) {
                if (ch == '\n')
                        console_dev->console_putc('\r');
                console_dev->console_putc(ch);
        }
}

static unsigned long nputs(const char *str, unsigned long len)

{
        unsigned long i, ret;

        if (console_dev && console_dev->console_puts) {
                ret = console_dev->console_puts(str, len);
        } else {
                for (i = 0; i < len; i++)
                        sbi_putc(str[i]);
                ret = len;
        }

        return ret;
}

Actually, sbi_putc() is duplicated from inputs(), and it's time to remove sbi_putc to make the opensbi code clearer. Here are the statistics of the work:

lib/utils/serial/uart8250.c-static struct sbi_console_device uart8250_console = {

lib/utils/serial/uart8250.c-    .name = "uart8250",
lib/utils/serial/uart8250.c:    .console_putc = uart8250_putc,
lib/utils/serial/uart8250.c-    .console_getc = uart8250_getc

lib/utils/serial/uart8250.c-};
--
lib/utils/serial/renesas_scif.c-static struct sbi_console_device renesas_scif_console = {

lib/utils/serial/renesas_scif.c-        .name           = "renesas_scif",
lib/utils/serial/renesas_scif.c:        .console_putc   = renesas_scif_putc,

lib/utils/serial/renesas_scif.c-};
--
lib/utils/serial/semihosting.c-static struct sbi_console_device semihosting_console = {
lib/utils/serial/semihosting.c- .name = "semihosting", lib/utils/serial/semihosting.c: .console_putc = semihosting_putc, lib/utils/serial/semihosting.c- .console_puts = semihosting_puts, lib/utils/serial/semihosting.c- .console_getc = semihosting_getc lib/utils/serial/semihosting.c-};
--
lib/utils/serial/shakti-uart.c-static struct sbi_console_device shakti_console = {
lib/utils/serial/shakti-uart.c- .name = "shakti_uart", lib/utils/serial/shakti-uart.c: .console_putc = shakti_uart_putc, lib/utils/serial/shakti-uart.c- .console_getc = shakti_uart_getc lib/utils/serial/shakti-uart.c-};
--
lib/utils/serial/sifive-uart.c-static struct sbi_console_device sifive_console = {
lib/utils/serial/sifive-uart.c- .name = "sifive_uart", lib/utils/serial/sifive-uart.c: .console_putc = sifive_uart_putc, lib/utils/serial/sifive-uart.c- .console_getc = sifive_uart_getc lib/utils/serial/sifive-uart.c-};
--
lib/utils/serial/litex-uart.c-static struct sbi_console_device litex_console = {

lib/utils/serial/litex-uart.c-  .name = "litex_uart",
lib/utils/serial/litex-uart.c:  .console_putc = litex_uart_putc,
lib/utils/serial/litex-uart.c-  .console_getc = litex_uart_getc

lib/utils/serial/litex-uart.c-};
--
lib/utils/serial/gaisler-uart.c-static struct sbi_console_device gaisler_console = {

lib/utils/serial/gaisler-uart.c-        .name         = "gaisler_uart",
lib/utils/serial/gaisler-uart.c:        .console_putc = gaisler_uart_putc,
lib/utils/serial/gaisler-uart.c-        .console_getc = gaisler_uart_getc

lib/utils/serial/gaisler-uart.c-};
--
lib/utils/serial/xlnx-uartlite.c-static struct sbi_console_device xlnx_uartlite_console = {

lib/utils/serial/xlnx-uartlite.c-       .name = "xlnx-uartlite",
lib/utils/serial/xlnx-uartlite.c:       .console_putc = xlnx_uartlite_putc,
lib/utils/serial/xlnx-uartlite.c-       .console_getc = xlnx_uartlite_getc

lib/utils/serial/xlnx-uartlite.c-};
--
lib/utils/serial/cadence-uart.c-static struct sbi_console_device cadence_console = {

lib/utils/serial/cadence-uart.c-        .name = "cadence_uart",
lib/utils/serial/cadence-uart.c:        .console_putc = cadence_uart_putc,
lib/utils/serial/cadence-uart.c-        .console_getc = cadence_uart_getc
lib/utils/serial/cadence-uart.c-};
--
lib/utils/sys/htif.c-static struct sbi_console_device htif_console = {
lib/utils/sys/htif.c-   .name = "htif",
lib/utils/sys/htif.c:   .console_putc = htif_putc,
lib/utils/sys/htif.c-   .console_getc = htif_getc

lib/utils/sys/htif.c-};

Is it worth removing .console_putc by implementing .console_puts.?

Quoted 11 lines
lib/utils/serial/semihosting.c +0 -1
 static int semihosting_getc(void)
 {
        char ch = 0;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 2 lines
Best Regards
 Guo Ren
#2 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

? 2023-10-23???? 14:35 +0800?Guo Ren???

Quoted 143 lines · On Wed, Oct 18, 2023 at 10:42?AM <[email protected]> wrote:
Quoted 34 lines

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
?lib/utils/serial/semihosting.c | 10 +++++-----
?1 file changed, 5 insertions(+), 5 deletions(-)

lib/utils/serial/semihosting.c +0 -0
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 

?/* clang-format on */

lib/utils/serial/semihosting.c +0 -5
-static void semihosting_putc(char ch)
-{
-?????? semihosting_trap(SYSWRITEC, &ch);
-}
-

?static unsigned long semihosting_puts(const char *str, unsigned long len) ?{
??????? char ch;

lib/utils/serial/semihosting.c static unsigned long semihosting_puts(const char *str, unsigned long len) · line 185

Quoted 8 lines
lib/utils/serial/semihosting.c +5 -0
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
 ??????? return (ret < 0) ? 0 : ret;
 ?}
 
+static void semihosting_putc(char ch)
+{
+?????? semihosting_puts(&ch, 1);
+}
+

When console_puts() was introduced by commit c43903c4eae41 ("lib: sbi:
Add console_puts() callback in the console device"), sbi_putc() became unnecessary and confusing. See below code:

void sbi_putc(char ch)
{
??????? if (console_dev && console_dev->console_putc) { ??????????????? if (ch == '\n') ??????????????????????? console_dev->console_putc('\r'); ??????????????? console_dev->console_putc(ch); ??????? }
}

static unsigned long nputs(const char *str, unsigned long len) {
??????? unsigned long i, ret;

??????? if (console_dev && console_dev->console_puts) { ??????????????? ret = console_dev->console_puts(str, len); ??????? } else {
??????????????? for (i = 0; i < len; i++) ??????????????????????? sbi_putc(str[i]); ??????????????? ret = len;
??????? }

??????? return ret;
}

Actually, sbi_putc() is duplicated from inputs(), and it's time to remove sbi_putc to make the opensbi code clearer. Here are the statistics of the work:

lib/utils/serial/uart8250.c-static struct sbi_console_device uart8250_console = {
lib/utils/serial/uart8250.c-??? .name = "uart8250", lib/utils/serial/uart8250.c:??? .console_putc = uart8250_putc, lib/utils/serial/uart8250.c-??? .console_getc = uart8250_getc lib/utils/serial/uart8250.c-};
--
lib/utils/serial/renesas_scif.c-static struct sbi_console_device renesas_scif_console = {
lib/utils/serial/renesas_scif.c-??????? .name?????????? = "renesas_scif", lib/utils/serial/renesas_scif.c:??????? .console_putc?? = renesas_scif_putc, lib/utils/serial/renesas_scif.c-};
--
lib/utils/serial/semihosting.c-static struct sbi_console_device semihosting_console = {
lib/utils/serial/semihosting.c- .name = "semihosting", lib/utils/serial/semihosting.c: .console_putc = semihosting_putc, lib/utils/serial/semihosting.c- .console_puts = semihosting_puts, lib/utils/serial/semihosting.c- .console_getc = semihosting_getc lib/utils/serial/semihosting.c-};
--
lib/utils/serial/shakti-uart.c-static struct sbi_console_device shakti_console = {
lib/utils/serial/shakti-uart.c- .name = "shakti_uart", lib/utils/serial/shakti-uart.c: .console_putc = shakti_uart_putc, lib/utils/serial/shakti-uart.c- .console_getc = shakti_uart_getc lib/utils/serial/shakti-uart.c-};
--
lib/utils/serial/sifive-uart.c-static struct sbi_console_device sifive_console = {
lib/utils/serial/sifive-uart.c- .name = "sifive_uart", lib/utils/serial/sifive-uart.c: .console_putc = sifive_uart_putc, lib/utils/serial/sifive-uart.c- .console_getc = sifive_uart_getc lib/utils/serial/sifive-uart.c-};
--
lib/utils/serial/litex-uart.c-static struct sbi_console_device litex_console = { lib/utils/serial/litex-uart.c-? .name = "litex_uart", lib/utils/serial/litex-uart.c:? .console_putc = litex_uart_putc, lib/utils/serial/litex-uart.c-? .console_getc = litex_uart_getc lib/utils/serial/litex-uart.c-};
--
lib/utils/serial/gaisler-uart.c-static struct sbi_console_device gaisler_console = {
lib/utils/serial/gaisler-uart.c-??????? .name???????? = "gaisler_uart", lib/utils/serial/gaisler-uart.c:??????? .console_putc = gaisler_uart_putc, lib/utils/serial/gaisler-uart.c-??????? .console_getc = gaisler_uart_getc lib/utils/serial/gaisler-uart.c-};
--
lib/utils/serial/xlnx-uartlite.c-static struct sbi_console_device xlnx_uartlite_console = {
lib/utils/serial/xlnx-uartlite.c-?????? .name = "xlnx-uartlite", lib/utils/serial/xlnx-uartlite.c:?????? .console_putc = xlnx_uartlite_putc, lib/utils/serial/xlnx-uartlite.c-?????? .console_getc = xlnx_uartlite_getc lib/utils/serial/xlnx-uartlite.c-};
--
lib/utils/serial/cadence-uart.c-static struct sbi_console_device cadence_console = {
lib/utils/serial/cadence-uart.c-??????? .name = "cadence_uart", lib/utils/serial/cadence-uart.c:??????? .console_putc = cadence_uart_putc, lib/utils/serial/cadence-uart.c-??????? .console_getc = cadence_uart_getc lib/utils/serial/cadence-uart.c-};
--
lib/utils/sys/htif.c-static struct sbi_console_device htif_console = { lib/utils/sys/htif.c-?? .name = "htif",
lib/utils/sys/htif.c:?? .console_putc = htif_putc, lib/utils/sys/htif.c-?? .console_getc = htif_getc lib/utils/sys/htif.c-};

Quoted 1 line

Is it worth removing .console_putc by implementing .console_puts.?

I think sbi_console.c can be modified to make console_putc unnecessary. Just implement one of console_putc/console_puts. This can reduce modifications to sbi_console_device.

Regards,
Xiang W

Quoted 19 lines
Quoted 12 lines
lib/utils/serial/semihosting.c +0 -1
 ?static int semihosting_getc(void)
 ?{
 ??????? char ch = 0;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 2 lines
Best Regards
?Guo Ren
#3 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

In reply to Guo Ren
Quoted 142 lines · On Mon, Oct 23, 2023 at 12:05?PM Guo Ren <[email protected]> wrote:
Quoted 34 lines · On Wed, Oct 18, 2023 at 10:42?AM <[email protected]> wrote:

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
 lib/utils/serial/semihosting.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/utils/serial/semihosting.c +0 -5
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-       semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
        char ch;

lib/utils/serial/semihosting.c static unsigned long semihosting_puts(const char *str, unsigned long len) · line 185

Quoted 8 lines
lib/utils/serial/semihosting.c +5 -0
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
        return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+       semihosting_puts(&ch, 1);
+}
+

When console_puts() was introduced by commit c43903c4eae41 ("lib: sbi:
Add console_puts() callback in the console device"), sbi_putc() became unnecessary and confusing. See below code:

void sbi_putc(char ch)

{
        if (console_dev && console_dev->console_putc) {
                if (ch == '\n')
                        console_dev->console_putc('\r');
                console_dev->console_putc(ch);
        }
}

static unsigned long nputs(const char *str, unsigned long len)

{
        unsigned long i, ret;

        if (console_dev && console_dev->console_puts) {
                ret = console_dev->console_puts(str, len);
        } else {
                for (i = 0; i < len; i++)
                        sbi_putc(str[i]);
                ret = len;
        }

        return ret;
}

Actually, sbi_putc() is duplicated from inputs(), and it's time to remove sbi_putc to make the opensbi code clearer. Here are the statistics of the work:

lib/utils/serial/uart8250.c-static struct sbi_console_device uart8250_console = {

lib/utils/serial/uart8250.c-    .name = "uart8250",
lib/utils/serial/uart8250.c:    .console_putc = uart8250_putc,
lib/utils/serial/uart8250.c-    .console_getc = uart8250_getc

lib/utils/serial/uart8250.c-};
--
lib/utils/serial/renesas_scif.c-static struct sbi_console_device renesas_scif_console = {

lib/utils/serial/renesas_scif.c-        .name           = "renesas_scif",
lib/utils/serial/renesas_scif.c:        .console_putc   = renesas_scif_putc,

lib/utils/serial/renesas_scif.c-};
--
lib/utils/serial/semihosting.c-static struct sbi_console_device semihosting_console = {
lib/utils/serial/semihosting.c- .name = "semihosting", lib/utils/serial/semihosting.c: .console_putc = semihosting_putc, lib/utils/serial/semihosting.c- .console_puts = semihosting_puts, lib/utils/serial/semihosting.c- .console_getc = semihosting_getc lib/utils/serial/semihosting.c-};
--
lib/utils/serial/shakti-uart.c-static struct sbi_console_device shakti_console = {
lib/utils/serial/shakti-uart.c- .name = "shakti_uart", lib/utils/serial/shakti-uart.c: .console_putc = shakti_uart_putc, lib/utils/serial/shakti-uart.c- .console_getc = shakti_uart_getc lib/utils/serial/shakti-uart.c-};
--
lib/utils/serial/sifive-uart.c-static struct sbi_console_device sifive_console = {
lib/utils/serial/sifive-uart.c- .name = "sifive_uart", lib/utils/serial/sifive-uart.c: .console_putc = sifive_uart_putc, lib/utils/serial/sifive-uart.c- .console_getc = sifive_uart_getc lib/utils/serial/sifive-uart.c-};
--
lib/utils/serial/litex-uart.c-static struct sbi_console_device litex_console = {

lib/utils/serial/litex-uart.c-  .name = "litex_uart",
lib/utils/serial/litex-uart.c:  .console_putc = litex_uart_putc,
lib/utils/serial/litex-uart.c-  .console_getc = litex_uart_getc

lib/utils/serial/litex-uart.c-};
--
lib/utils/serial/gaisler-uart.c-static struct sbi_console_device gaisler_console = {

lib/utils/serial/gaisler-uart.c-        .name         = "gaisler_uart",
lib/utils/serial/gaisler-uart.c:        .console_putc = gaisler_uart_putc,
lib/utils/serial/gaisler-uart.c-        .console_getc = gaisler_uart_getc

lib/utils/serial/gaisler-uart.c-};
--
lib/utils/serial/xlnx-uartlite.c-static struct sbi_console_device xlnx_uartlite_console = {

lib/utils/serial/xlnx-uartlite.c-       .name = "xlnx-uartlite",
lib/utils/serial/xlnx-uartlite.c:       .console_putc = xlnx_uartlite_putc,
lib/utils/serial/xlnx-uartlite.c-       .console_getc = xlnx_uartlite_getc

lib/utils/serial/xlnx-uartlite.c-};
--
lib/utils/serial/cadence-uart.c-static struct sbi_console_device cadence_console = {

lib/utils/serial/cadence-uart.c-        .name = "cadence_uart",
lib/utils/serial/cadence-uart.c:        .console_putc = cadence_uart_putc,
lib/utils/serial/cadence-uart.c-        .console_getc = cadence_uart_getc
lib/utils/serial/cadence-uart.c-};
--
lib/utils/sys/htif.c-static struct sbi_console_device htif_console = {
lib/utils/sys/htif.c-   .name = "htif",
lib/utils/sys/htif.c:   .console_putc = htif_putc,
lib/utils/sys/htif.c-   .console_getc = htif_getc
Quoted 3 lines

lib/utils/sys/htif.c-};

Is it worth removing .console_putc by implementing .console_puts.?

NACK, having console_puts in all serial drivers would mean duplicating generic code into all drivers.

Regards,
Anup

Quoted 23 lines
Quoted 8 lines
lib/utils/serial/semihosting.c +0 -1
 static int semihosting_getc(void)
 {
        char ch = 0;
--

2.25.1

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

--
Best Regards
Guo Ren

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#4 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

Quoted 146 lines · On Mon, Oct 23, 2023 at 4:36?PM Anup Patel <[email protected]> wrote:
Quoted 144 lines · On Mon, Oct 23, 2023 at 12:05?PM Guo Ren <[email protected]> wrote:
Quoted 34 lines · On Wed, Oct 18, 2023 at 10:42?AM <[email protected]> wrote:

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
 lib/utils/serial/semihosting.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/utils/serial/semihosting.c +0 -5
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-       semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
        char ch;

lib/utils/serial/semihosting.c static unsigned long semihosting_puts(const char *str, unsigned long len) · line 185

Quoted 8 lines
lib/utils/serial/semihosting.c +5 -0
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
        return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+       semihosting_puts(&ch, 1);
+}
+

When console_puts() was introduced by commit c43903c4eae41 ("lib: sbi:
Add console_puts() callback in the console device"), sbi_putc() became unnecessary and confusing. See below code:

void sbi_putc(char ch)

{
        if (console_dev && console_dev->console_putc) {
                if (ch == '\n')
                        console_dev->console_putc('\r');
                console_dev->console_putc(ch);
        }
}

static unsigned long nputs(const char *str, unsigned long len)

{
        unsigned long i, ret;

        if (console_dev && console_dev->console_puts) {
                ret = console_dev->console_puts(str, len);
        } else {
                for (i = 0; i < len; i++)
                        sbi_putc(str[i]);
                ret = len;
        }

        return ret;
}

Actually, sbi_putc() is duplicated from inputs(), and it's time to remove sbi_putc to make the opensbi code clearer. Here are the statistics of the work:

lib/utils/serial/uart8250.c-static struct sbi_console_device uart8250_console = {

lib/utils/serial/uart8250.c-    .name = "uart8250",
lib/utils/serial/uart8250.c:    .console_putc = uart8250_putc,
lib/utils/serial/uart8250.c-    .console_getc = uart8250_getc

lib/utils/serial/uart8250.c-};
--
lib/utils/serial/renesas_scif.c-static struct sbi_console_device renesas_scif_console = {

lib/utils/serial/renesas_scif.c-        .name           = "renesas_scif",
lib/utils/serial/renesas_scif.c:        .console_putc   = renesas_scif_putc,

lib/utils/serial/renesas_scif.c-};
--
lib/utils/serial/semihosting.c-static struct sbi_console_device semihosting_console = {
lib/utils/serial/semihosting.c- .name = "semihosting", lib/utils/serial/semihosting.c: .console_putc = semihosting_putc, lib/utils/serial/semihosting.c- .console_puts = semihosting_puts, lib/utils/serial/semihosting.c- .console_getc = semihosting_getc lib/utils/serial/semihosting.c-};
--
lib/utils/serial/shakti-uart.c-static struct sbi_console_device shakti_console = {
lib/utils/serial/shakti-uart.c- .name = "shakti_uart", lib/utils/serial/shakti-uart.c: .console_putc = shakti_uart_putc, lib/utils/serial/shakti-uart.c- .console_getc = shakti_uart_getc lib/utils/serial/shakti-uart.c-};
--
lib/utils/serial/sifive-uart.c-static struct sbi_console_device sifive_console = {
lib/utils/serial/sifive-uart.c- .name = "sifive_uart", lib/utils/serial/sifive-uart.c: .console_putc = sifive_uart_putc, lib/utils/serial/sifive-uart.c- .console_getc = sifive_uart_getc lib/utils/serial/sifive-uart.c-};
--
lib/utils/serial/litex-uart.c-static struct sbi_console_device litex_console = {

lib/utils/serial/litex-uart.c-  .name = "litex_uart",
lib/utils/serial/litex-uart.c:  .console_putc = litex_uart_putc,
lib/utils/serial/litex-uart.c-  .console_getc = litex_uart_getc

lib/utils/serial/litex-uart.c-};
--
lib/utils/serial/gaisler-uart.c-static struct sbi_console_device gaisler_console = {

lib/utils/serial/gaisler-uart.c-        .name         = "gaisler_uart",
lib/utils/serial/gaisler-uart.c:        .console_putc = gaisler_uart_putc,
lib/utils/serial/gaisler-uart.c-        .console_getc = gaisler_uart_getc

lib/utils/serial/gaisler-uart.c-};
--
lib/utils/serial/xlnx-uartlite.c-static struct sbi_console_device xlnx_uartlite_console = {

lib/utils/serial/xlnx-uartlite.c-       .name = "xlnx-uartlite",
lib/utils/serial/xlnx-uartlite.c:       .console_putc = xlnx_uartlite_putc,
lib/utils/serial/xlnx-uartlite.c-       .console_getc = xlnx_uartlite_getc

lib/utils/serial/xlnx-uartlite.c-};
--
lib/utils/serial/cadence-uart.c-static struct sbi_console_device cadence_console = {

lib/utils/serial/cadence-uart.c-        .name = "cadence_uart",
lib/utils/serial/cadence-uart.c:        .console_putc = cadence_uart_putc,
lib/utils/serial/cadence-uart.c-        .console_getc = cadence_uart_getc
lib/utils/serial/cadence-uart.c-};
--
lib/utils/sys/htif.c-static struct sbi_console_device htif_console = {
lib/utils/sys/htif.c-   .name = "htif",
lib/utils/sys/htif.c:   .console_putc = htif_putc,
lib/utils/sys/htif.c-   .console_getc = htif_getc

lib/utils/sys/htif.c-};

Quoted 4 lines
Quoted 1 line

Is it worth removing .console_putc by implementing .console_puts.?

NACK, having console_puts in all serial drivers would mean duplicating generic code into all drivers.

Okay, then, I agree with the patch.

+static void semihosting_putc(char ch)
+{
+ semihosting_puts(&ch, 1);
+}

Quoted 27 lines

Regards,
Anup

Quoted 23 lines
Quoted 8 lines
lib/utils/serial/semihosting.c +0 -1
 static int semihosting_getc(void)
 {
        char ch = 0;
--

2.25.1

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

--
Best Regards
Guo Ren

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 2 lines
Best Regards
 Guo Ren
Applied
#5 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

In reply to [email protected]
Quoted 9 lines · On Wed, Oct 18, 2023 at 8:12?AM <[email protected]> wrote:

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 44 lines

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
 lib/utils/serial/semihosting.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/utils/serial/semihosting.c +5 -6
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-       semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
        char ch;
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
        return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+       semihosting_puts(&ch, 1);
+}
+
 static int semihosting_getc(void)
 {
        char ch = 0;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#6 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

? 2023-11-16???? 11:42 +0530?Anup Patel???

Quoted 8 lines · On Wed, Oct 18, 2023 at 8:12?AM <[email protected]> wrote:
Quoted 7 lines

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Quoted 8 lines
Quoted 2 lines

Looks good to me.

Applied this patch to the riscv/opensbi repo.

I submitted a new workaround.

https://patchwork.ozlabs.org/project/opensbi/patch/20231025043104.748104-1-wxjstz at 126.com/
https://patchwork.ozlabs.org/project/opensbi/patch/20231025043104.748104-2-wxjstz at 126.com/

Regards,
Xiang W

Quoted 48 lines

Thanks,
Anup

Quoted 44 lines

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
?lib/utils/serial/semihosting.c | 10 +++++-----
?1 file changed, 5 insertions(+), 5 deletions(-)

lib/utils/serial/semihosting.c +0 -0
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 

?/* clang-format on */

lib/utils/serial/semihosting.c +0 -5
-static void semihosting_putc(char ch)
-{
-?????? semihosting_trap(SYSWRITEC, &ch);
-}
-

?static unsigned long semihosting_puts(const char *str, unsigned long len) ?{
??????? char ch;

lib/utils/serial/semihosting.c +5 -1
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
 ??????? return (ret < 0) ? 0 : ret;
 ?}
 
+static void semihosting_putc(char ch)
+{
+?????? semihosting_puts(&ch, 1);
+}
+
 ?static int semihosting_getc(void)
 ?{
 ??????? char ch = 0;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#7 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

Quoted 15 lines · On Thu, Nov 16, 2023 at 2:16?PM Xiang W <[email protected]> wrote:

? 2023-11-16???? 11:42 +0530?Anup Patel???

Quoted 13 lines · On Wed, Oct 18, 2023 at 8:12?AM <[email protected]> wrote:
Quoted 9 lines

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Looks good to me.

Quoted 7 lines
Quoted 3 lines

Applied this patch to the riscv/opensbi repo.

I submitted a new workaround.

https://patchwork.ozlabs.org/project/opensbi/patch/20231025043104.748104-1-wxjstz at 126.com/
https://patchwork.ozlabs.org/project/opensbi/patch/20231025043104.748104-2-wxjstz at 126.com/

Can you rebase and send a new version for review ?

Regards,
Anup

Quoted 52 lines

Regards,
Xiang W

Quoted 48 lines

Thanks,
Anup

Quoted 44 lines

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
 lib/utils/serial/semihosting.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/utils/serial/semihosting.c +5 -6
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 
 /* clang-format on */
 
-static void semihosting_putc(char ch)
-{
-       semihosting_trap(SYSWRITEC, &ch);
-}
-
 static unsigned long semihosting_puts(const char *str, unsigned long len)
 {
        char ch;
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
        return (ret < 0) ? 0 : ret;
 }
 
+static void semihosting_putc(char ch)
+{
+       semihosting_puts(&ch, 1);
+}
+
 static int semihosting_getc(void)
 {
        char ch = 0;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#8 lore raw

PATCH v2 1/1 lib: utils/serial: Optimize semihosting_putc implementation

? 2023-11-16???? 21:30 +0530?Anup Patel???

Quoted 18 lines · On Thu, Nov 16, 2023 at 2:16?PM Xiang W <[email protected]> wrote:
Quoted 17 lines

? 2023-11-16???? 11:42 +0530?Anup Patel???

Quoted 15 lines · On Wed, Oct 18, 2023 at 8:12?AM <[email protected]> wrote:
Quoted 9 lines

From: Chen Pei <[email protected]>

For some debuggers that do not implement SYSWRITEC and SYSREADC operations, we can use SYSWRITE and SYSREAD instead like the implementation of semihosting_getc().

Looks good to me.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Applied this patch to the riscv/opensbi repo.

I submitted a new workaround.

https://patchwork.ozlabs.org/project/opensbi/patch/20231025043104.748104-1-wxjstz at 126.com/
https://patchwork.ozlabs.org/project/opensbi/patch/20231025043104.748104-2-wxjstz at 126.com/

Can you rebase and send a new version for review ?

New version at:
https://patchwork.ozlabs.org/project/opensbi/patch/20231117010440.105759-1-wxjstz at 126.com/
https://patchwork.ozlabs.org/project/opensbi/patch/20231117010440.105759-2-wxjstz at 126.com/

Regards,
Xiang W

Quoted 57 lines

Regards,
Anup

Quoted 52 lines

Regards,
Xiang W

Quoted 48 lines

Thanks,
Anup

Quoted 44 lines

Changed from v1:
1. simplified by calling semihosting_puts directly.

---
?lib/utils/serial/semihosting.c | 10 +++++-----
?1 file changed, 5 insertions(+), 5 deletions(-)

lib/utils/serial/semihosting.c +0 -0
index ce65887..a27c69e 100644
@@ -160,11 +160,6 @@ static long semihosting_write(long fd, const void *memp, size_t len)
 

?/* clang-format on */

lib/utils/serial/semihosting.c +0 -5
-static void semihosting_putc(char ch)
-{
-?????? semihosting_trap(SYSWRITEC, &ch);
-}
-

?static unsigned long semihosting_puts(const char *str, unsigned long len) ?{
??????? char ch;

lib/utils/serial/semihosting.c +5 -1
@@ -183,6 +178,11 @@ static unsigned long semihosting_puts(const char *str, unsigned long len)
 ??????? return (ret < 0) ? 0 : ret;
 ?}
 
+static void semihosting_putc(char ch)
+{
+?????? semihosting_puts(&ch, 1);
+}
+
 ?static int semihosting_getc(void)
 ?{
 ??????? char ch = 0;
--

2.25.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi