[PowerPC64LE] pseries: Fix input buffering logic.

In uart_phyp_get(), when the internal buffer is empty, we make a
hypercall to retrieve up to 16 bytes of input data from the
hypervisor. As this is specified to be returned in BE format, we need
to do a 64-bit byte swap on the first and second half of the data.

If the buffer being passed in was insufficient to return the fetched
data, we store the remainder in the internal buffer and use it to
satisfy the following calls to uart_phyp_get() until it is drained.

However, in this case, we were accidentally byteswapping the internal
buffer again.

Move the byteswapping code to just after the hypercall so it only gets
swapped when we're filling the buffer.

Fixes arrow keys in qemu on pseries, among other console oddities.

Sponsored by:	Tag1 Consulting, Inc.
MFC after:	3 days
This commit is contained in:
Brandon Bergren 2021-02-25 12:55:58 -06:00
parent d7671ad8d6
commit 5001c579ba

View File

@ -295,6 +295,10 @@ uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
err = phyp_pft_hcall(H_GET_TERM_CHAR, sc->vtermid,
0, 0, 0, &sc->inbuflen, &sc->phyp_inbuf.u64[0],
&sc->phyp_inbuf.u64[1]);
#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 (err != H_SUCCESS) {
uart_unlock(&sc->sc_mtx);
return (-1);
@ -307,11 +311,6 @@ 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. */