1276331Snwhitehorn/*- 2276331Snwhitehorn * Copyright (C) 2014 Nathan Whitehorn 3276331Snwhitehorn * All rights reserved. 4276331Snwhitehorn * 5276331Snwhitehorn * Redistribution and use in source and binary forms, with or without 6276331Snwhitehorn * modification, are permitted provided that the following conditions 7276331Snwhitehorn * are met: 8276331Snwhitehorn * 1. Redistributions of source code must retain the above copyright 9276331Snwhitehorn * notice, this list of conditions and the following disclaimer. 10276331Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright 11276331Snwhitehorn * notice, this list of conditions and the following disclaimer in the 12276331Snwhitehorn * documentation and/or other materials provided with the distribution. 13276331Snwhitehorn * 14276331Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15276331Snwhitehorn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16276331Snwhitehorn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17276331Snwhitehorn * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18276331Snwhitehorn * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19276331Snwhitehorn * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20276331Snwhitehorn * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21276331Snwhitehorn * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22276331Snwhitehorn * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23276331Snwhitehorn * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24276331Snwhitehorn */ 25276331Snwhitehorn 26276331Snwhitehorn#include <sys/cdefs.h> 27276331Snwhitehorn__FBSDID("$FreeBSD: stable/11/stand/powerpc/kboot/hostcons.c 276410 2014-12-30 14:50:03Z nwhitehorn $"); 28276331Snwhitehorn 29276331Snwhitehorn#include <sys/types.h> 30276331Snwhitehorn#include "bootstrap.h" 31276331Snwhitehorn#include "host_syscall.h" 32276331Snwhitehorn 33276331Snwhitehornstatic void hostcons_probe(struct console *cp); 34276331Snwhitehornstatic int hostcons_init(int arg); 35276331Snwhitehornstatic void hostcons_putchar(int c); 36276331Snwhitehornstatic int hostcons_getchar(); 37276331Snwhitehornstatic int hostcons_poll(); 38276331Snwhitehorn 39276331Snwhitehornstruct console hostconsole = { 40276331Snwhitehorn "host", 41276331Snwhitehorn "Host Console", 42276331Snwhitehorn 0, 43276331Snwhitehorn hostcons_probe, 44276331Snwhitehorn hostcons_init, 45276331Snwhitehorn hostcons_putchar, 46276331Snwhitehorn hostcons_getchar, 47276331Snwhitehorn hostcons_poll, 48276331Snwhitehorn}; 49276331Snwhitehorn 50276331Snwhitehornstatic void 51276331Snwhitehornhostcons_probe(struct console *cp) 52276331Snwhitehorn{ 53276331Snwhitehorn 54276331Snwhitehorn cp->c_flags |= C_PRESENTIN|C_PRESENTOUT; 55276331Snwhitehorn} 56276331Snwhitehorn 57276331Snwhitehornstatic int 58276331Snwhitehornhostcons_init(int arg) 59276331Snwhitehorn{ 60276331Snwhitehorn 61276331Snwhitehorn /* XXX: set nonblocking */ 62276410Snwhitehorn /* tcsetattr(~(ICANON | ECHO)) */ 63276331Snwhitehorn 64276331Snwhitehorn return (0); 65276331Snwhitehorn} 66276331Snwhitehorn 67276331Snwhitehornstatic void 68276331Snwhitehornhostcons_putchar(int c) 69276331Snwhitehorn{ 70276331Snwhitehorn uint8_t ch = c; 71276331Snwhitehorn 72276331Snwhitehorn host_write(1, &ch, 1); 73276331Snwhitehorn} 74276331Snwhitehorn 75276331Snwhitehornstatic int 76276331Snwhitehornhostcons_getchar() 77276331Snwhitehorn{ 78276331Snwhitehorn uint8_t ch; 79276380Snwhitehorn int rv; 80276331Snwhitehorn 81276380Snwhitehorn rv = host_read(0, &ch, 1); 82276380Snwhitehorn if (rv == 1) 83276380Snwhitehorn return (ch); 84276380Snwhitehorn return (-1); 85276331Snwhitehorn} 86276331Snwhitehorn 87276331Snwhitehornstatic int 88276331Snwhitehornhostcons_poll() 89276331Snwhitehorn{ 90276380Snwhitehorn struct host_timeval tv = {0,0}; 91276380Snwhitehorn long fds = 1 << 0; 92276380Snwhitehorn int ret; 93276380Snwhitehorn 94276380Snwhitehorn ret = host_select(32, &fds, NULL, NULL, &tv); 95276380Snwhitehorn return (ret > 0); 96276331Snwhitehorn} 97276331Snwhitehorn 98