From owner-dev-commits-src-main@freebsd.org Fri Apr 16 20:10:36 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D20FF5DDFC7; Fri, 16 Apr 2021 20:10:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FMS4r5fB7z4mwm; Fri, 16 Apr 2021 20:10:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B4DAD2AE4; Fri, 16 Apr 2021 20:10:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13GKAaDA022291; Fri, 16 Apr 2021 20:10:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13GKAa3i022290; Fri, 16 Apr 2021 20:10:36 GMT (envelope-from git) Date: Fri, 16 Apr 2021 20:10:36 GMT Message-Id: <202104162010.13GKAa3i022290@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alfredo Dal'Ava Junior" Subject: git: b8bc6b7954e2 - main - opal_console: fix serial console output corruption on powerpc64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: alfredo X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b8bc6b7954e27edb449503004ef52b8b97585545 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2021 20:10:36 -0000 The branch main has been updated by alfredo: URL: https://cgit.FreeBSD.org/src/commit/?id=b8bc6b7954e27edb449503004ef52b8b97585545 commit b8bc6b7954e27edb449503004ef52b8b97585545 Author: Alfredo Dal'Ava Junior AuthorDate: 2021-04-16 22:51:15 +0000 Commit: Alfredo Dal'Ava Junior 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