[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.
This commit is contained in:
Brandon Bergren 2020-09-23 00:06:48 +00:00
parent 35ef395191
commit 15be37cb7f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=366036
2 changed files with 16 additions and 4 deletions

View File

@ -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, size_t bufsize)
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, size_t bufsize)
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, size_t bufsize)
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, size_t bufsize)
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, size_t bufsize)
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);

View File

@ -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, size_t bufsize)
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, size_t bufsize)
}
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);