cons.c revision 1.12 1 /* $NetBSD: cons.c,v 1.12 2011/02/08 20:20:10 rmind 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. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: Utah Hdr: cons.c 1.7 92/02/28
37 *
38 * @(#)cons.c 8.1 (Berkeley) 6/10/93
39 */
40
41 #include <lib/libsa/stand.h>
42 #include <sys/param.h>
43 #include "boot.h"
44 #include "cons.h"
45
46 #ifdef CONS_BE
47 void becnprobe(struct consdev *);
48 void becninit(struct consdev *);
49 void becnputchar(void *, register int);
50 int becngetchar(void *);
51 int becnscan(void *);
52 #endif
53
54 #ifdef CONS_VGA
55 void vgacnprobe(struct consdev *);
56 void vgacninit(struct consdev *);
57 void vgacnputchar(void *, register int);
58 int vgacngetchar(void *);
59 int vgacnscan(void *);
60 #endif
61
62 #ifdef CONS_SERIAL
63 void siocnprobe(struct consdev *);
64 void siocninit(struct consdev *);
65 void siocnputchar(void *, register int);
66 int siocngetchar(void *);
67 int siocnscan(void *);
68 # include "ns16550.h"
69 # ifndef COMPORT
70 # define COMPORT COM1
71 # endif
72 # ifndef COMSPEED
73 # define COMSPEED 9600
74 # endif
75 #endif
76
77 struct consdev constab[] = {
78 #ifdef CONS_BE
79 { "be", 0xd0000000, 0,
80 becnprobe, becninit, becngetchar, becnputchar, becnscan },
81 #endif
82 #ifdef CONS_VGA
83 { "vga", 0xc0000000, 0,
84 vgacnprobe, vgacninit, vgacngetchar, vgacnputchar, vgacnscan },
85 #endif
86 #ifdef CONS_SERIAL
87 { "com", COMPORT, COMSPEED,
88 siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
89 #endif
90 { 0 }
91 };
92
93 struct consdev *cn_tab;
94
95 char *
96 cninit(int *addr, int *speed)
97 {
98 register struct consdev *cp;
99
100 cn_tab = NULL;
101 for (cp = constab; cp->cn_probe; cp++) {
102 (*cp->cn_probe)(cp);
103 if (cp->cn_pri > CN_DEAD &&
104 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
105 cn_tab = cp;
106 }
107 if (cn_tab) {
108 (*cn_tab->cn_init)(cn_tab);
109 *addr = cn_tab->address;
110 *speed = cn_tab->speed;
111 return (cn_tab->cn_name);
112 }
113
114 return (NULL);
115 }
116
117 int
118 cngetc(void)
119 {
120
121 if (cn_tab)
122 return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
123 return (0);
124 }
125
126 void
127 cnputc(int c)
128 {
129
130 if (cn_tab)
131 (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
132 }
133
134 int
135 cnscan(void)
136 {
137
138 if (cn_tab)
139 return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
140 return -1;
141 }
142
143 #ifdef CONS_BE
144 /*
145 * BeBox default console
146 */
147 void
148 becnprobe(struct consdev *cp)
149 {
150
151 cp->cn_pri = CN_INTERNAL;
152 }
153
154 void
155 becninit(struct consdev *cp)
156 {
157
158 video_init((u_char *)cp->address);
159 kbdreset();
160 kbd(1); /* read out ugly data */
161 }
162
163 int
164 becngetchar(void *dev)
165 {
166
167 return (kbd_getc());
168 }
169
170 void
171 becnputchar(void *dev, register int c)
172 {
173
174 video_putc(c);
175 }
176
177 int
178 becnscan(void *dev)
179 {
180
181 return (kbd(1));
182 }
183 #endif /* CONS_BE */
184
185 #ifdef CONS_VGA
186 /*
187 * VGA console
188 */
189 void
190 vgacnprobe(struct consdev *cp)
191 {
192
193 cp->cn_pri = CN_NORMAL;
194 }
195
196 void
197 vgacninit(struct consdev *cp)
198 {
199
200 vga_reset((u_char *)cp->address);
201 vga_init((u_char *)cp->address);
202 kbdreset();
203 }
204
205 int
206 vgacngetchar(void *dev)
207 {
208
209 return (kbd_getc());
210 }
211
212 void
213 vgacnputchar(void *dev, register int c)
214 {
215
216 vga_putc(c);
217 }
218
219 int
220 vgacnscan(void *dev)
221 {
222
223 return (kbd(1));
224 }
225 #endif /* CONS_VGA */
226
227 #ifdef CONS_SERIAL
228 /*
229 * serial console
230 */
231 void
232 siocnprobe(struct consdev *cp)
233 {
234
235 cp->cn_pri = CN_REMOTE;
236 }
237
238 void
239 siocninit(struct consdev *cp)
240 {
241
242 cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
243 }
244
245 int
246 siocngetchar(void *dev)
247 {
248
249 return (NS16550_getc((struct NS16550 *)dev));
250 }
251
252 void
253 siocnputchar(void *dev, register int c)
254 {
255
256 if (c == '\n')
257 NS16550_putc((struct NS16550 *)dev, '\r');
258 NS16550_putc((struct NS16550 *)dev, c);
259 }
260
261 int
262 siocnscan(void *dev)
263 {
264
265 return (NS16550_scankbd((struct NS16550 *)dev));
266 }
267 #endif /* CONS_SERIAL */
268