xref: /NextBSD/sys/boot/powerpc/kboot/hostcons.c (revision 287e3b14e9552995def1802ec9c5034f4adf28ec)
1 /*-
2  * Copyright (C) 2014 Nathan Whitehorn
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28 
29 #include <sys/types.h>
30 #include "bootstrap.h"
31 #include "host_syscall.h"
32 
33 static void hostcons_probe(struct console *cp);
34 static int hostcons_init(int arg);
35 static void hostcons_putchar(int c);
36 static int hostcons_getchar();
37 static int hostcons_poll();
38 
39 struct console hostconsole = {
40 	"host",
41 	"Host Console",
42 	0,
43 	hostcons_probe,
44 	hostcons_init,
45 	hostcons_putchar,
46 	hostcons_getchar,
47 	hostcons_poll,
48 };
49 
50 static void
hostcons_probe(struct console * cp)51 hostcons_probe(struct console *cp)
52 {
53 
54 	cp->c_flags |= C_PRESENTIN|C_PRESENTOUT;
55 }
56 
57 static int
hostcons_init(int arg)58 hostcons_init(int arg)
59 {
60 
61 	/* XXX: set nonblocking */
62 	/* tcsetattr(~(ICANON | ECHO)) */
63 
64 	return (0);
65 }
66 
67 static void
hostcons_putchar(int c)68 hostcons_putchar(int c)
69 {
70 	uint8_t ch = c;
71 
72 	host_write(1, &ch, 1);
73 }
74 
75 static int
hostcons_getchar()76 hostcons_getchar()
77 {
78 	uint8_t ch;
79 	int rv;
80 
81 	rv = host_read(0, &ch, 1);
82 	if (rv == 1)
83 		return (ch);
84 	return (-1);
85 }
86 
87 static int
hostcons_poll()88 hostcons_poll()
89 {
90 	struct host_timeval tv = {0,0};
91 	long fds = 1 << 0;
92 	int ret;
93 
94 	ret = host_select(32, &fds, NULL, NULL, &tv);
95 	return (ret > 0);
96 }
97 
98