1223695Sdfr/*-
2223695Sdfr * Copyright (c) 2011 Google, Inc.
3223695Sdfr * All rights reserved.
4223695Sdfr *
5223695Sdfr * Redistribution and use in source and binary forms, with or without
6223695Sdfr * modification, are permitted provided that the following conditions
7223695Sdfr * are met:
8223695Sdfr * 1. Redistributions of source code must retain the above copyright
9223695Sdfr *    notice, this list of conditions and the following disclaimer.
10223695Sdfr * 2. Redistributions in binary form must reproduce the above copyright
11223695Sdfr *    notice, this list of conditions and the following disclaimer in the
12223695Sdfr *    documentation and/or other materials provided with the distribution.
13223695Sdfr *
14223695Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15223695Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16223695Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17223695Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18223695Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19223695Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20223695Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21223695Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22223695Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23223695Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24223695Sdfr * SUCH DAMAGE.
25223695Sdfr */
26223695Sdfr
27223695Sdfr#include <sys/cdefs.h>
28223695Sdfr__FBSDID("$FreeBSD$");
29223695Sdfr
30223695Sdfr#include <stand.h>
31223695Sdfr#include "bootstrap.h"
32223695Sdfr#include "libuserboot.h"
33223695Sdfr
34223695Sdfrint console;
35223695Sdfr
36268953Sjhbstatic struct console *userboot_comconsp;
37268953Sjhb
38223695Sdfrstatic void userboot_cons_probe(struct console *cp);
39223695Sdfrstatic int userboot_cons_init(int);
40268953Sjhbstatic void userboot_comcons_probe(struct console *cp);
41268953Sjhbstatic int userboot_comcons_init(int);
42223695Sdfrstatic void userboot_cons_putchar(int);
43223695Sdfrstatic int userboot_cons_getchar(void);
44223695Sdfrstatic int userboot_cons_poll(void);
45223695Sdfr
46223695Sdfrstruct console userboot_console = {
47223695Sdfr	"userboot",
48223695Sdfr	"userboot",
49223695Sdfr	0,
50223695Sdfr	userboot_cons_probe,
51223695Sdfr	userboot_cons_init,
52223695Sdfr	userboot_cons_putchar,
53223695Sdfr	userboot_cons_getchar,
54223695Sdfr	userboot_cons_poll,
55223695Sdfr};
56223695Sdfr
57268953Sjhb/*
58268953Sjhb * Provide a simple alias to allow loader scripts to set the
59268953Sjhb * console to comconsole without resulting in an error
60268953Sjhb */
61268953Sjhbstruct console userboot_comconsole = {
62268953Sjhb	"comconsole",
63268953Sjhb	"comconsole",
64268953Sjhb	0,
65268953Sjhb	userboot_comcons_probe,
66268953Sjhb	userboot_comcons_init,
67268953Sjhb	userboot_cons_putchar,
68268953Sjhb	userboot_cons_getchar,
69268953Sjhb	userboot_cons_poll,
70268953Sjhb};
71268953Sjhb
72223695Sdfrstatic void
73223695Sdfruserboot_cons_probe(struct console *cp)
74223695Sdfr{
75223695Sdfr
76223695Sdfr	cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
77223695Sdfr}
78223695Sdfr
79223695Sdfrstatic int
80223695Sdfruserboot_cons_init(int arg)
81223695Sdfr{
82223695Sdfr
83223695Sdfr	return (0);
84223695Sdfr}
85223695Sdfr
86223695Sdfrstatic void
87268953Sjhbuserboot_comcons_probe(struct console *cp)
88268953Sjhb{
89268953Sjhb
90268953Sjhb	/*
91268953Sjhb	 * Save the console pointer so the comcons_init routine
92268953Sjhb	 * can set the C_PRESENT* flags. They are not set
93268953Sjhb	 * here to allow the existing userboot console to
94268953Sjhb	 * be elected the default.
95268953Sjhb	 */
96268953Sjhb	userboot_comconsp = cp;
97268953Sjhb}
98268953Sjhb
99268953Sjhbstatic int
100268953Sjhbuserboot_comcons_init(int arg)
101268953Sjhb{
102268953Sjhb
103268953Sjhb	/*
104268953Sjhb	 * Set the C_PRESENT* flags to allow the comconsole
105268953Sjhb	 * to be selected as the active console
106268953Sjhb	 */
107268953Sjhb	userboot_comconsp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
108268953Sjhb	return (0);
109268953Sjhb}
110268953Sjhb
111268953Sjhbstatic void
112223695Sdfruserboot_cons_putchar(int c)
113223695Sdfr{
114223695Sdfr
115223695Sdfr        CALLBACK(putc, c);
116223695Sdfr}
117223695Sdfr
118223695Sdfrstatic int
119223695Sdfruserboot_cons_getchar()
120223695Sdfr{
121223695Sdfr
122223695Sdfr	return (CALLBACK(getc));
123223695Sdfr}
124223695Sdfr
125223695Sdfrstatic int
126223695Sdfruserboot_cons_poll()
127223695Sdfr{
128223695Sdfr
129223695Sdfr	return (CALLBACK(poll));
130223695Sdfr}
131