Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Apr 2021 20:10:36 GMT
From:      "Alfredo Dal'Ava Junior" <alfredo@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b8bc6b7954e2 - main - opal_console: fix serial console output corruption on powerpc64
Message-ID:  <202104162010.13GKAa3i022290@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by alfredo:

URL: https://cgit.FreeBSD.org/src/commit/?id=b8bc6b7954e27edb449503004ef52b8b97585545

commit b8bc6b7954e27edb449503004ef52b8b97585545
Author:     Alfredo Dal'Ava Junior <alfredo@FreeBSD.org>
AuthorDate: 2021-04-16 22:51:15 +0000
Commit:     Alfredo Dal'Ava Junior <alfredo@FreeBSD.org>
CommitDate: 2021-04-16 23:10:09 +0000

    opal_console: fix serial console output corruption on powerpc64
    
    Adds OPAL_CONSOLE_WRITE error handling and implements a call to
    OPAL_CONSOLE_WRITE_BUFFER_SPACE to verify if there's enough space
    before writing to console.
    
    This fixes serial port output getting corrupted on fast writes, like
    on "dmesg" output.
    
    Tested on Raptor Blackbird running powerpc64 BE kernel
    
    Reviewed by:    luporl
    Sponsored by:   Eldorado Reserach Institute (eldorado.org.br)
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D29063
---
 sys/powerpc/powernv/opal.h         |  1 +
 sys/powerpc/powernv/opal_console.c | 49 ++++++++++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/sys/powerpc/powernv/opal.h b/sys/powerpc/powernv/opal.h
index d7a81e33f809..8e39a39b6c9a 100644
--- a/sys/powerpc/powernv/opal.h
+++ b/sys/powerpc/powernv/opal.h
@@ -56,6 +56,7 @@ int opal_call(uint64_t token, ...);
 #define	OPAL_PCI_CONFIG_WRITE_HALF_WORD	17
 #define	OPAL_PCI_CONFIG_WRITE_WORD	18
 #define	OPAL_PCI_EEH_FREEZE_STATUS	23
+#define OPAL_CONSOLE_WRITE_BUFFER_SPACE 25
 #define	OPAL_PCI_EEH_FREEZE_CLEAR	26
 #define	OPAL_PCI_PHB_MMIO_ENABLE	27
 #define	OPAL_PCI_SET_PHB_MEM_WINDOW	28
diff --git a/sys/powerpc/powernv/opal_console.c b/sys/powerpc/powernv/opal_console.c
index 7b953d2679fb..8f6c88f81f7c 100644
--- a/sys/powerpc/powernv/opal_console.c
+++ b/sys/powerpc/powernv/opal_console.c
@@ -171,6 +171,24 @@ uart_opal_real_unmap_outbuffer(uint64_t *len)
 	mtx_unlock_spin(&opalcons_buffer.mtx);
 }
 
+static int64_t
+uart_opal_console_write_buffer_space(int vtermid)
+{
+	int64_t buffer_space_val = 0;
+	vm_paddr_t buffer_space_ptr;
+
+	if (pmap_bootstrapped)
+		buffer_space_ptr = vtophys(&buffer_space_val);
+	else
+		buffer_space_ptr = (vm_paddr_t)&buffer_space_val;
+
+	if (opal_call(OPAL_CONSOLE_WRITE_BUFFER_SPACE, vtermid,
+	    buffer_space_ptr) != OPAL_SUCCESS)
+		return (-1);
+
+	return (be64toh(buffer_space_val));
+}
+
 static int
 uart_opal_probe_node(struct uart_opal_softc *sc)
 {
@@ -420,12 +438,12 @@ uart_opal_put(struct uart_opal_softc *sc, void *buffer, size_t bufsize)
 		len -= 4;
 	}
 
-#if 0
-	if (err != OPAL_SUCCESS)
-		len = 0;
-#endif
+	if (err == OPAL_SUCCESS)
+		return (len);
+	else if (err == OPAL_BUSY_EVENT)
+		return(0);
 
-	return (len);
+	return (-1);
 }
 
 static int
@@ -481,11 +499,28 @@ uart_opal_ttyoutwakeup(struct tty *tp)
 	struct uart_opal_softc *sc;
 	char buffer[8];
 	int len;
+	int64_t buffer_space;
 
 	sc = tty_softc(tp);
 
-	while ((len = ttydisc_getc(tp, buffer, sizeof(buffer))) != 0)
-		uart_opal_put(sc, buffer, len);
+	while ((len = ttydisc_getc(tp, buffer, sizeof(buffer))) != 0) {
+		int bytes_written = 0;
+		while (bytes_written == 0) {
+			buffer_space = uart_opal_console_write_buffer_space(sc->vtermid);
+			if (buffer_space == -1)
+				/* OPAL failure or invalid terminal */
+				break;
+			else if (buffer_space >= len)
+				bytes_written = uart_opal_put(sc, buffer, len);
+
+			if (bytes_written == 0)
+				/* OPAL must be busy, poll and retry */
+				opal_call(OPAL_POLL_EVENTS, NULL);
+			else if (bytes_written == -1)
+				/* OPAL failure or invalid terminal */
+				break;
+		}
+	}
 }
 
 static void



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104162010.13GKAa3i022290>