cons.c revision 1.5 1 /* $NetBSD: cons.c,v 1.5 1999/06/28 01:20:44 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 "boot.h"
47 #include "cons.h"
48
49 #ifdef CONS_BE
50 void becnprobe(), becninit(), becnputchar();
51 int becngetchar(), becnscan();
52 #endif
53
54 #ifdef CONS_VGA
55 void vgacnprobe(), vgacninit(), vgacnputchar();
56 int vgacngetchar(), vgacnscan();
57 #endif
58
59 #ifdef CONS_SERIAL
60 void siocnprobe(), siocninit(), siocnputchar();
61 int siocngetchar(), siocnscan();
62 # include "ns16550.h"
63 # ifndef COMPORT
64 # define COMPORT COM1
65 # endif
66 # ifndef COMSPEED
67 # define COMSPEED 9600
68 # endif
69 #endif
70
71 struct consdev constab[] = {
72 #ifdef CONS_BE
73 { "be", 0xd0000000, 0,
74 becnprobe, becninit, becngetchar, becnputchar, becnscan },
75 #endif
76 #ifdef CONS_VGA
77 { "vga", 0xc0000000, 0,
78 vgacnprobe, vgacninit, vgacngetchar, vgacnputchar, vgacnscan },
79 #endif
80 #ifdef CONS_SERIAL
81 { "com", COMPORT, COMSPEED,
82 siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
83 #endif
84 { 0 }
85 };
86
87 struct consdev *cn_tab;
88
89 char *
90 cninit(addr, speed)
91 int *addr;
92 int *speed;
93 {
94 register struct consdev *cp;
95
96 cn_tab = NULL;
97 for (cp = constab; cp->cn_probe; cp++) {
98 (*cp->cn_probe)(cp);
99 if (cp->cn_pri > CN_DEAD &&
100 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
101 cn_tab = cp;
102 }
103 if (cn_tab) {
104 (*cn_tab->cn_init)(cn_tab);
105 *addr = cn_tab->address;
106 *speed = cn_tab->speed;
107 return (cn_tab->cn_name);
108 }
109
110 return (NULL);
111 }
112
113 int
114 cngetc()
115 {
116 if (cn_tab)
117 return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
118 return (0);
119 }
120
121 void
122 cnputc(c)
123 int c;
124 {
125 if (cn_tab)
126 (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
127 }
128
129 int
130 cnscan()
131 {
132 if (cn_tab)
133 return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
134 return (0);
135 }
136
137 #ifdef CONS_BE
138 /*
139 * BeBox default console
140 */
141 void
142 becnprobe(cp)
143 struct consdev *cp;
144 {
145 cp->cn_pri = CN_INTERNAL;
146 }
147
148 void
149 becninit(cp)
150 struct consdev *cp;
151 {
152 video_init((u_char *)cp->address);
153 kbdreset();
154 }
155
156 int
157 becngetchar(dev)
158 void *dev;
159 {
160 return (kbd_getc());
161 }
162
163 void
164 becnputchar(dev, c)
165 void *dev;
166 register int c;
167 {
168 video_putc(c);
169 }
170
171 int
172 becnscan(dev)
173 void *dev;
174 {
175 return (kbd(1));
176 }
177 #endif /* CONS_VGA */
178
179 #ifdef CONS_VGA
180 /*
181 * VGA console
182 */
183 void
184 vgacnprobe(cp)
185 struct consdev *cp;
186 {
187 cp->cn_pri = CN_NORMAL;
188 }
189
190 void
191 vgacninit(cp)
192 struct consdev *cp;
193 {
194 vga_reset((u_char *)cp->address);
195 vga_init((u_char *)cp->address);
196 kbdreset();
197 }
198
199 int
200 vgacngetchar(dev)
201 void *dev;
202 {
203 return (kbd_getc());
204 }
205
206 void
207 vgacnputchar(dev, c)
208 void *dev;
209 register int c;
210 {
211 vga_putc(c);
212 }
213
214 int
215 vgacnscan(dev)
216 void *dev;
217 {
218 return (kbd(1));
219 }
220 #endif /* CONS_VGA */
221
222 #ifdef CONS_SERIAL
223 /*
224 * serial console
225 */
226 void
227 siocnprobe(cp)
228 struct consdev *cp;
229 {
230 cp->cn_pri = CN_REMOTE;
231 }
232
233 void
234 siocninit(cp)
235 struct consdev *cp;
236 {
237 cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
238 }
239
240 int
241 siocngetchar(dev)
242 void *dev;
243 {
244 return (NS16550_getc((struct NS16550 *)dev));
245 }
246
247 void
248 siocnputchar(dev, c)
249 void *dev;
250 register int c;
251 {
252 if (c == '\n')
253 NS16550_putc((struct NS16550 *)dev, '\r');
254 NS16550_putc((struct NS16550 *)dev, c);
255 }
256
257 int
258 siocnscan(dev, cp)
259 void *dev;
260 struct consdev *cp;
261 {
262 return (NS16550_scankbd((struct NS16550 *)dev));
263 }
264 #endif /* CONS_SERIAL */
265