svn commit: r366036 - in head/sys/powerpc: powernv pseries

Brandon Bergren bdragon at FreeBSD.org
Wed Sep 23 00:06:49 UTC 2020


Author: bdragon
Date: Wed Sep 23 00:06:48 2020
New Revision: 366036
URL: https://svnweb.freebsd.org/changeset/base/366036

Log:
  [PowerPC64LE] Fix endianness issues in phyp and opal consoles.
  
  This applies to both pseries and powernv, which were tested at different
  points during the patchset development.
  
  Sponsored by:	Tag1 Consulting, Inc.

Modified:
  head/sys/powerpc/powernv/opal_console.c
  head/sys/powerpc/pseries/phyp_console.c

Modified: head/sys/powerpc/powernv/opal_console.c
==============================================================================
--- head/sys/powerpc/powernv/opal_console.c	Wed Sep 23 00:03:35 2020	(r366035)
+++ head/sys/powerpc/powernv/opal_console.c	Wed Sep 23 00:06:48 2020	(r366036)
@@ -25,6 +25,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/endian.h>
 #include <sys/param.h>
 #include <sys/conf.h>
 #include <sys/cons.h>
@@ -323,7 +324,7 @@ uart_opal_get(struct uart_opal_softc *sc, void *buffer
 	int hdr = 0;
 
 	if (sc->protocol == OPAL_RAW) {
-		uint64_t len = bufsize;
+		uint64_t len = htobe64(bufsize);
 		uint64_t olen = (uint64_t)&len;
 		uint64_t obuf = (uint64_t)buffer;
 
@@ -336,7 +337,7 @@ uart_opal_get(struct uart_opal_softc *sc, void *buffer
 		if (err != OPAL_SUCCESS)
 			return (-1);
 
-		bufsize = len;
+		bufsize = be64toh(len);
 	} else {
 		uart_lock(&sc->sc_mtx);
 		if (sc->inbuflen == 0) {
@@ -347,6 +348,7 @@ uart_opal_get(struct uart_opal_softc *sc, void *buffer
 				return (-1);
 			}
 			hdr = 1; 
+			sc->inbuflen = be64toh(sc->inbuflen);
 		}
 
 		if (sc->inbuflen == 0) {
@@ -391,7 +393,9 @@ uart_opal_put(struct uart_opal_softc *sc, void *buffer
 		len = bufsize;
 
 		uart_opal_real_map_outbuffer(&obuf, &olen);
+		*(uint64_t*)olen = htobe64(*(uint64_t*)olen);
 		err = opal_call(OPAL_CONSOLE_WRITE, sc->vtermid, olen, obuf);
+		*(uint64_t*)olen = be64toh(*(uint64_t*)olen);
 		uart_opal_real_unmap_outbuffer(&len);
 	} else {
 		uart_lock(&sc->sc_mtx);
@@ -406,7 +410,9 @@ uart_opal_put(struct uart_opal_softc *sc, void *buffer
 		len = 4 + bufsize;
 
 		uart_opal_real_map_outbuffer(&obuf, &olen);
+		*(uint64_t*)olen = htobe64(*(uint64_t*)olen);
 		err = opal_call(OPAL_CONSOLE_WRITE, sc->vtermid, olen, obuf);
+		*(uint64_t*)olen = be64toh(*(uint64_t*)olen);
 		uart_opal_real_unmap_outbuffer(&len);
 
 		uart_unlock(&sc->sc_mtx);

Modified: head/sys/powerpc/pseries/phyp_console.c
==============================================================================
--- head/sys/powerpc/pseries/phyp_console.c	Wed Sep 23 00:03:35 2020	(r366035)
+++ head/sys/powerpc/pseries/phyp_console.c	Wed Sep 23 00:06:48 2020	(r366036)
@@ -27,6 +27,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/endian.h>
 #include <sys/param.h>
 #include <sys/kdb.h>
 #include <sys/kernel.h>
@@ -306,6 +307,11 @@ uart_phyp_get(struct uart_phyp_softc *sc, void *buffer
 		return (0);
 	}
 
+#if BYTE_ORDER == LITTLE_ENDIAN
+	sc->phyp_inbuf.u64[0] = be64toh(sc->phyp_inbuf.u64[0]);
+	sc->phyp_inbuf.u64[1] = be64toh(sc->phyp_inbuf.u64[1]);
+#endif
+
 	if ((sc->protocol == HVTERMPROT) && (hdr == 1)) {
 		sc->inbuflen = sc->inbuflen - 4;
 		/* The VTERM protocol has a 4 byte header, skip it here. */
@@ -380,8 +386,8 @@ uart_phyp_put(struct uart_phyp_softc *sc, void *buffer
 	}
 
 	do {
-	    err = phyp_hcall(H_PUT_TERM_CHAR, sc->vtermid, len, cbuf.u64[0],
-			    cbuf.u64[1]);
+	    err = phyp_hcall(H_PUT_TERM_CHAR, sc->vtermid, len, htobe64(cbuf.u64[0]),
+			    htobe64(cbuf.u64[1]));
 		DELAY(100);
 	} while (err == H_BUSY);
 


More information about the svn-src-head mailing list