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