Deleted Added
full compact
phyp_console.c (256281) phyp_console.c (259230)
1/*-
2 * Copyright (C) 2011 by Nathan Whitehorn. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
21 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 2011 by Nathan Whitehorn. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
21 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include <sys/cdefs.h>
26__FBSDID("$FreeBSD: stable/10/sys/powerpc/pseries/phyp_console.c 255895 2013-09-26 18:01:32Z nwhitehorn $");
26__FBSDID("$FreeBSD: stable/10/sys/powerpc/pseries/phyp_console.c 259230 2013-12-11 21:37:32Z andreast $");
27
28#include <sys/param.h>
29#include <sys/kdb.h>
30#include <sys/kernel.h>
31#include <sys/priv.h>
32#include <sys/systm.h>
33#include <sys/module.h>
34#include <sys/types.h>

--- 246 unchanged lines hidden (view full) ---

281uart_phyp_cnterm(struct consdev *cp)
282{
283}
284
285static int
286uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
287{
288 int err;
27
28#include <sys/param.h>
29#include <sys/kdb.h>
30#include <sys/kernel.h>
31#include <sys/priv.h>
32#include <sys/systm.h>
33#include <sys/module.h>
34#include <sys/types.h>

--- 246 unchanged lines hidden (view full) ---

281uart_phyp_cnterm(struct consdev *cp)
282{
283}
284
285static int
286uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
287{
288 int err;
289 int hdr = 0;
289
290 uart_lock(&sc->sc_mtx);
291 if (sc->inbuflen == 0) {
292 err = phyp_pft_hcall(H_GET_TERM_CHAR, sc->vtermid,
293 0, 0, 0, &sc->inbuflen, &sc->phyp_inbuf.u64[0],
294 &sc->phyp_inbuf.u64[1]);
295 if (err != H_SUCCESS) {
296 uart_unlock(&sc->sc_mtx);
297 return (-1);
298 }
290
291 uart_lock(&sc->sc_mtx);
292 if (sc->inbuflen == 0) {
293 err = phyp_pft_hcall(H_GET_TERM_CHAR, sc->vtermid,
294 0, 0, 0, &sc->inbuflen, &sc->phyp_inbuf.u64[0],
295 &sc->phyp_inbuf.u64[1]);
296 if (err != H_SUCCESS) {
297 uart_unlock(&sc->sc_mtx);
298 return (-1);
299 }
300 hdr = 1;
299 }
300
301 if (sc->inbuflen == 0) {
302 uart_unlock(&sc->sc_mtx);
303 return (0);
304 }
305
306 if (bufsize > sc->inbuflen)
307 bufsize = sc->inbuflen;
301 }
302
303 if (sc->inbuflen == 0) {
304 uart_unlock(&sc->sc_mtx);
305 return (0);
306 }
307
308 if (bufsize > sc->inbuflen)
309 bufsize = sc->inbuflen;
310
311 if ((sc->protocol == HVTERMPROT) && (hdr == 1)) {
312 sc->inbuflen = sc->inbuflen - 4;
313 /* The VTERM protocol has a 4 byte header, skip it here. */
314 memmove(&sc->phyp_inbuf.str[0], &sc->phyp_inbuf.str[4],
315 sc->inbuflen);
316 }
317
308 memcpy(buffer, sc->phyp_inbuf.str, bufsize);
309 sc->inbuflen -= bufsize;
310 if (sc->inbuflen > 0)
311 memmove(&sc->phyp_inbuf.str[0], &sc->phyp_inbuf.str[bufsize],
312 sc->inbuflen);
313
314 uart_unlock(&sc->sc_mtx);
315 return (bufsize);
316}
317
318static int
319uart_phyp_put(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
320{
321 uint16_t seqno;
322 uint64_t len = 0;
318 memcpy(buffer, sc->phyp_inbuf.str, bufsize);
319 sc->inbuflen -= bufsize;
320 if (sc->inbuflen > 0)
321 memmove(&sc->phyp_inbuf.str[0], &sc->phyp_inbuf.str[bufsize],
322 sc->inbuflen);
323
324 uart_unlock(&sc->sc_mtx);
325 return (bufsize);
326}
327
328static int
329uart_phyp_put(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
330{
331 uint16_t seqno;
332 uint64_t len = 0;
333 int err;
334
323 union {
335 union {
324 uint64_t u64;
325 char bytes[8];
336 uint64_t u64[2];
337 char bytes[16];
326 } cbuf;
327
328 uart_lock(&sc->sc_mtx);
329 switch (sc->protocol) {
330 case HVTERM1:
338 } cbuf;
339
340 uart_lock(&sc->sc_mtx);
341 switch (sc->protocol) {
342 case HVTERM1:
331 if (bufsize > 8)
332 bufsize = 8;
343 if (bufsize > 16)
344 bufsize = 16;
333 memcpy(&cbuf, buffer, bufsize);
334 len = bufsize;
335 break;
336 case HVTERMPROT:
345 memcpy(&cbuf, buffer, bufsize);
346 len = bufsize;
347 break;
348 case HVTERMPROT:
337 if (bufsize > 4)
338 bufsize = 4;
349 if (bufsize > 12)
350 bufsize = 12;
339 seqno = sc->outseqno++;
340 cbuf.bytes[0] = VS_DATA_PACKET_HEADER;
351 seqno = sc->outseqno++;
352 cbuf.bytes[0] = VS_DATA_PACKET_HEADER;
341 cbuf.bytes[1] = 4 + bufsize; /* total length */
353 cbuf.bytes[1] = 4 + bufsize; /* total length, max 16 bytes */
342 cbuf.bytes[2] = (seqno >> 8) & 0xff;
343 cbuf.bytes[3] = seqno & 0xff;
344 memcpy(&cbuf.bytes[4], buffer, bufsize);
345 len = 4 + bufsize;
346 break;
347 }
354 cbuf.bytes[2] = (seqno >> 8) & 0xff;
355 cbuf.bytes[3] = seqno & 0xff;
356 memcpy(&cbuf.bytes[4], buffer, bufsize);
357 len = 4 + bufsize;
358 break;
359 }
348 phyp_hcall(H_PUT_TERM_CHAR, sc->vtermid, len, cbuf.u64, 0);
360
361 do {
362 err = phyp_hcall(H_PUT_TERM_CHAR, sc->vtermid, len, cbuf.u64[0],
363 cbuf.u64[1]);
364 DELAY(100);
365 } while (err == H_BUSY);
366
349 uart_unlock(&sc->sc_mtx);
350
351 return (bufsize);
352}
353
354static int
355uart_phyp_cngetc(struct consdev *cp)
356{

--- 61 unchanged lines hidden ---
367 uart_unlock(&sc->sc_mtx);
368
369 return (bufsize);
370}
371
372static int
373uart_phyp_cngetc(struct consdev *cp)
374{

--- 61 unchanged lines hidden ---