cons.c revision 1.1 1 /* $NetBSD: cons.c,v 1.1 1998/01/16 04:17:40 sakamoto Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: Utah Hdr: cons.c 1.7 92/02/28
41 *
42 * @(#)cons.c 8.1 (Berkeley) 6/10/93
43 */
44
45 #include <sys/param.h>
46 #include "cons.h"
47
48 void becnprobe(), becninit(), becnputchar();
49 int becngetchar(), becnscan();
50 void siocnprobe(), siocninit(), siocnputchar();
51 int siocngetchar(), siocnscan();
52
53 struct consdev constab[] = {
54 #ifdef CONS_VGA
55 { becnprobe, becninit, becngetchar, becnputchar, becnscan },
56 #endif
57 #ifdef CONS_SERIAL
58 { siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
59 #endif
60 { 0 }
61 };
62
63 struct consdev *cn_tab;
64 int noconsole;
65
66 cninit()
67 {
68 register struct consdev *cp;
69
70 cn_tab = NULL;
71 noconsole = 1;
72 for (cp = constab; cp->cn_probe; cp++) {
73 (*cp->cn_probe)(cp);
74 if (cp->cn_pri > CN_DEAD &&
75 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
76 cn_tab = cp;
77 }
78 if (cn_tab) {
79 (*cn_tab->cn_init)(cn_tab);
80 noconsole = 0;
81 }
82 }
83
84 cngetc()
85 {
86 if (cn_tab)
87 return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
88 return (0);
89 }
90
91 cnputc(c)
92 int c;
93 {
94 if (cn_tab)
95 (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
96 }
97
98 cnscan()
99 {
100 if (cn_tab)
101 return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
102 return (0);
103 }
104
105 #ifdef CONS_VGA
106 /*
107 * BeBox default console
108 */
109 void
110 becnprobe(cp)
111 struct consdev *cp;
112 {
113 cp->cn_pri = CN_NORMAL;
114 }
115
116 void
117 becninit(cp)
118 struct consdev *cp;
119 {
120 #define PCI_BASE 0xC0000000
121 unsigned char *display_memory = (unsigned char *)PCI_BASE;
122
123 vga_init(display_memory);
124 CRT_init(display_memory);
125 kbdreset();
126 }
127
128 becngetchar(cp)
129 struct consdev *cp;
130 {
131 return (CRT_getc());
132 }
133
134 void
135 becnputchar(cp, c)
136 struct consdev *cp;
137 register int c;
138 {
139 CRT_putc(c);
140 }
141
142 becnscan(cp)
143 struct consdev *cp;
144 {
145 return (kbd(1));
146 }
147 #endif /* CONS_VGA */
148
149 #ifdef CONS_SERIAL
150 /*
151 * BeBox serial console
152 */
153 void
154 siocnprobe(cp)
155 struct consdev *cp;
156 {
157 cp->cn_pri = CN_REMOTE;
158 }
159
160 #include "ns16550.h"
161 struct NS16550 *sio;
162
163 void
164 siocninit(cp)
165 struct consdev *cp;
166 {
167 sio = (struct NS16550 *)NS16550_init();
168 }
169
170 siocngetchar(cp)
171 struct consdev *cp;
172 {
173 return (NS16550_getc(sio));
174 }
175
176 void
177 siocnputchar(cp, c)
178 struct consdev *cp;
179 register int c;
180 {
181 if (c == '\n')
182 NS16550_putc(sio, '\r');
183 NS16550_putc(sio, c);
184 }
185
186 siocnscan(cp)
187 struct consdev *cp;
188 {
189 return (NS16550_scankbd(sio));
190 }
191 #endif /* CONS_SERIAL */
192