cons.c revision 1.8 1 1.8 tsutsui /* $NetBSD: cons.c,v 1.8 2008/03/23 17:19:57 tsutsui Exp $ */
2 1.1 cdi
3 1.1 cdi /*
4 1.1 cdi * Copyright (c) 1990, 1993
5 1.1 cdi * The Regents of the University of California. All rights reserved.
6 1.2 agc *
7 1.2 agc * This code is derived from software contributed to Berkeley by
8 1.2 agc * the Systems Programming Group of the University of Utah Computer
9 1.2 agc * Science Department.
10 1.2 agc *
11 1.2 agc * Redistribution and use in source and binary forms, with or without
12 1.2 agc * modification, are permitted provided that the following conditions
13 1.2 agc * are met:
14 1.2 agc * 1. Redistributions of source code must retain the above copyright
15 1.2 agc * notice, this list of conditions and the following disclaimer.
16 1.2 agc * 2. Redistributions in binary form must reproduce the above copyright
17 1.2 agc * notice, this list of conditions and the following disclaimer in the
18 1.2 agc * documentation and/or other materials provided with the distribution.
19 1.2 agc * 3. Neither the name of the University nor the names of its contributors
20 1.2 agc * may be used to endorse or promote products derived from this software
21 1.2 agc * without specific prior written permission.
22 1.2 agc *
23 1.2 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.2 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.2 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.2 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.2 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.2 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.2 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.2 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.2 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.2 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.2 agc * SUCH DAMAGE.
34 1.2 agc *
35 1.2 agc * from: Utah Hdr: cons.c 1.7 92/02/28
36 1.2 agc *
37 1.2 agc * @(#)cons.c 8.1 (Berkeley) 6/10/93
38 1.2 agc */
39 1.2 agc /*
40 1.2 agc * Copyright (c) 1988 University of Utah.
41 1.1 cdi *
42 1.1 cdi * This code is derived from software contributed to Berkeley by
43 1.1 cdi * the Systems Programming Group of the University of Utah Computer
44 1.1 cdi * Science Department.
45 1.1 cdi *
46 1.1 cdi * Redistribution and use in source and binary forms, with or without
47 1.1 cdi * modification, are permitted provided that the following conditions
48 1.1 cdi * are met:
49 1.1 cdi * 1. Redistributions of source code must retain the above copyright
50 1.1 cdi * notice, this list of conditions and the following disclaimer.
51 1.1 cdi * 2. Redistributions in binary form must reproduce the above copyright
52 1.1 cdi * notice, this list of conditions and the following disclaimer in the
53 1.1 cdi * documentation and/or other materials provided with the distribution.
54 1.1 cdi * 3. All advertising materials mentioning features or use of this software
55 1.1 cdi * must display the following acknowledgement:
56 1.1 cdi * This product includes software developed by the University of
57 1.1 cdi * California, Berkeley and its contributors.
58 1.1 cdi * 4. Neither the name of the University nor the names of its contributors
59 1.1 cdi * may be used to endorse or promote products derived from this software
60 1.1 cdi * without specific prior written permission.
61 1.1 cdi *
62 1.1 cdi * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.1 cdi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.1 cdi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.1 cdi * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.1 cdi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.1 cdi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.1 cdi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.1 cdi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.1 cdi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.1 cdi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.1 cdi * SUCH DAMAGE.
73 1.1 cdi *
74 1.1 cdi * from: Utah Hdr: cons.c 1.7 92/02/28
75 1.1 cdi *
76 1.1 cdi * @(#)cons.c 8.1 (Berkeley) 6/10/93
77 1.1 cdi */
78 1.1 cdi
79 1.1 cdi #include <lib/libsa/stand.h>
80 1.1 cdi
81 1.8 tsutsui #include <machine/cpu.h>
82 1.8 tsutsui
83 1.1 cdi #include "boot.h"
84 1.1 cdi #include "cons.h"
85 1.1 cdi
86 1.1 cdi #ifdef CONS_SERIAL
87 1.4 tsutsui void siocnprobe(struct consdev *);
88 1.4 tsutsui void siocninit(struct consdev *);
89 1.4 tsutsui void siocnputchar(void *, int);
90 1.4 tsutsui int siocngetchar(void *);
91 1.4 tsutsui int siocnscan(void *);
92 1.1 cdi # include "ns16550.h"
93 1.1 cdi # ifndef COMPORT
94 1.1 cdi # define COMPORT COM1
95 1.1 cdi # endif
96 1.1 cdi # ifndef COMSPEED
97 1.1 cdi # define COMSPEED 9600
98 1.1 cdi # endif
99 1.1 cdi #endif
100 1.1 cdi
101 1.7 tsutsui #ifdef CONS_ZS
102 1.7 tsutsui void zscnprobe(struct consdev *);
103 1.7 tsutsui void zscninit(struct consdev *);
104 1.7 tsutsui void zscnputchar(void *, int);
105 1.7 tsutsui int zscngetchar(void *);
106 1.7 tsutsui int zscnscan(void *);
107 1.7 tsutsui #include "zs.h"
108 1.7 tsutsui #ifndef ZSCHAN
109 1.7 tsutsui #define ZSCHAN ZS_CHAN_A
110 1.7 tsutsui #endif
111 1.7 tsutsui #ifndef ZSSPEED
112 1.7 tsutsui #define ZSSPEED 115200
113 1.7 tsutsui #endif
114 1.7 tsutsui #endif
115 1.7 tsutsui
116 1.1 cdi struct consdev constab[] = {
117 1.1 cdi #ifdef CONS_SERIAL
118 1.1 cdi { "com", COMPORT, COMSPEED,
119 1.1 cdi siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
120 1.1 cdi #endif
121 1.7 tsutsui #ifdef CONS_ZS
122 1.7 tsutsui { "zs", ZSCHAN, ZSSPEED,
123 1.7 tsutsui zscnprobe, zscninit, zscngetchar, zscnputchar, zscnscan },
124 1.7 tsutsui #endif
125 1.1 cdi { 0 }
126 1.1 cdi };
127 1.1 cdi
128 1.1 cdi struct consdev *cn_tab;
129 1.1 cdi
130 1.1 cdi char *
131 1.4 tsutsui cninit(int *addr, int *speed)
132 1.1 cdi {
133 1.1 cdi register struct consdev *cp;
134 1.1 cdi
135 1.1 cdi cn_tab = NULL;
136 1.1 cdi for (cp = constab; cp->cn_probe; cp++) {
137 1.1 cdi (*cp->cn_probe)(cp);
138 1.1 cdi if (cp->cn_pri > CN_DEAD &&
139 1.1 cdi (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
140 1.1 cdi cn_tab = cp;
141 1.1 cdi }
142 1.1 cdi if (cn_tab) {
143 1.1 cdi (*cn_tab->cn_init)(cn_tab);
144 1.1 cdi *addr = cn_tab->address;
145 1.1 cdi *speed = cn_tab->speed;
146 1.4 tsutsui return cn_tab->cn_name;
147 1.1 cdi }
148 1.1 cdi
149 1.4 tsutsui return NULL;
150 1.1 cdi }
151 1.1 cdi
152 1.1 cdi int
153 1.4 tsutsui cngetc(void)
154 1.1 cdi {
155 1.1 cdi
156 1.1 cdi if (cn_tab)
157 1.4 tsutsui return (*cn_tab->cn_getc)(cn_tab->cn_dev);
158 1.4 tsutsui return 0;
159 1.1 cdi }
160 1.1 cdi
161 1.1 cdi void
162 1.4 tsutsui cnputc(int c)
163 1.1 cdi {
164 1.1 cdi
165 1.1 cdi if (cn_tab)
166 1.1 cdi (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
167 1.1 cdi }
168 1.1 cdi
169 1.1 cdi int
170 1.4 tsutsui cnscan(void)
171 1.1 cdi {
172 1.1 cdi
173 1.1 cdi if (cn_tab)
174 1.4 tsutsui return (*cn_tab->cn_scan)(cn_tab->cn_dev);
175 1.6 tsutsui return -1;
176 1.1 cdi }
177 1.1 cdi
178 1.1 cdi #ifdef CONS_FB
179 1.1 cdi /*
180 1.1 cdi * frame buffer console
181 1.1 cdi */
182 1.1 cdi void
183 1.4 tsutsui fbcnprobe(struct consdev *cp)
184 1.1 cdi {
185 1.1 cdi
186 1.1 cdi cp->cn_pri = CN_INTERNAL;
187 1.1 cdi }
188 1.1 cdi
189 1.1 cdi void
190 1.4 tsutsui fbcninit(struct consdev *cp)
191 1.1 cdi {
192 1.1 cdi
193 1.4 tsutsui video_init((uint8_t *)cp->address);
194 1.1 cdi kbdreset();
195 1.1 cdi }
196 1.1 cdi
197 1.1 cdi int
198 1.4 tsutsui fbcngetchar(void *dev)
199 1.1 cdi {
200 1.1 cdi
201 1.4 tsutsui return kbd_getc();
202 1.1 cdi }
203 1.1 cdi
204 1.1 cdi void
205 1.4 tsutsui fbcnputchar(void *dev, int c)
206 1.1 cdi {
207 1.1 cdi
208 1.1 cdi video_putc(c);
209 1.1 cdi }
210 1.1 cdi
211 1.1 cdi int
212 1.4 tsutsui fbcnscan(void *dev)
213 1.1 cdi {
214 1.1 cdi
215 1.4 tsutsui return kbd(1);
216 1.1 cdi }
217 1.1 cdi #endif /* CONS_FB */
218 1.1 cdi
219 1.1 cdi #ifdef CONS_VGA
220 1.1 cdi /*
221 1.1 cdi * VGA console
222 1.1 cdi */
223 1.1 cdi void
224 1.4 tsutsui vgacnprobe(struct consdev *cp)
225 1.1 cdi {
226 1.4 tsutsui
227 1.1 cdi cp->cn_pri = CN_NORMAL;
228 1.1 cdi }
229 1.1 cdi
230 1.1 cdi void
231 1.4 tsutsui vgacninit(struct consdev *cp)
232 1.1 cdi {
233 1.1 cdi
234 1.4 tsutsui vga_reset((uint8_t *)cp->address);
235 1.4 tsutsui vga_init((uint8_t *)cp->address);
236 1.1 cdi kbdreset();
237 1.1 cdi }
238 1.1 cdi
239 1.1 cdi int
240 1.4 tsutsui vgacngetchar(void *dev)
241 1.1 cdi {
242 1.1 cdi
243 1.4 tsutsui return kbd_getc();
244 1.1 cdi }
245 1.1 cdi
246 1.1 cdi void
247 1.4 tsutsui vgacnputchar(void *dev, int c)
248 1.1 cdi {
249 1.1 cdi
250 1.1 cdi vga_putc(c);
251 1.1 cdi }
252 1.1 cdi
253 1.1 cdi int
254 1.4 tsutsui vgacnscan(void *dev)
255 1.1 cdi {
256 1.1 cdi
257 1.4 tsutsui return kbd(1);
258 1.1 cdi }
259 1.1 cdi #endif /* CONS_VGA */
260 1.1 cdi
261 1.1 cdi #ifdef CONS_SERIAL
262 1.1 cdi /*
263 1.1 cdi * serial console
264 1.1 cdi */
265 1.1 cdi void
266 1.4 tsutsui siocnprobe(struct consdev *cp)
267 1.1 cdi {
268 1.4 tsutsui
269 1.7 tsutsui if (*((uint32_t *)COMPROBE) != 0 &&
270 1.7 tsutsui cobalt_id != COBALT_ID_QUBE2700)
271 1.1 cdi cp->cn_pri = CN_REMOTE;
272 1.1 cdi }
273 1.1 cdi
274 1.1 cdi void
275 1.4 tsutsui siocninit(struct consdev *cp)
276 1.1 cdi {
277 1.1 cdi
278 1.1 cdi cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
279 1.1 cdi }
280 1.1 cdi
281 1.1 cdi int
282 1.4 tsutsui siocngetchar(void *dev)
283 1.1 cdi {
284 1.1 cdi
285 1.4 tsutsui return NS16550_getc((struct NS16550 *)dev);
286 1.1 cdi }
287 1.1 cdi
288 1.1 cdi void
289 1.4 tsutsui siocnputchar(void *dev, int c)
290 1.1 cdi {
291 1.1 cdi
292 1.1 cdi if (c == '\n')
293 1.1 cdi NS16550_putc((struct NS16550 *)dev, '\r');
294 1.1 cdi NS16550_putc((struct NS16550 *)dev, c);
295 1.1 cdi }
296 1.1 cdi
297 1.1 cdi int
298 1.4 tsutsui siocnscan(void *dev)
299 1.1 cdi {
300 1.1 cdi
301 1.4 tsutsui return NS16550_scankbd((struct NS16550 *)dev);
302 1.1 cdi }
303 1.1 cdi #endif /* CONS_SERIAL */
304 1.7 tsutsui
305 1.7 tsutsui #ifdef CONS_ZS
306 1.7 tsutsui /*
307 1.7 tsutsui * optional z85c30 serial console on Qube2700
308 1.7 tsutsui */
309 1.7 tsutsui void
310 1.7 tsutsui zscnprobe(struct consdev *cp)
311 1.7 tsutsui {
312 1.7 tsutsui
313 1.7 tsutsui if (*((uint32_t *)ZSPROBE) != 0 &&
314 1.7 tsutsui cobalt_id == COBALT_ID_QUBE2700)
315 1.7 tsutsui cp->cn_pri = CN_REMOTE;
316 1.7 tsutsui }
317 1.7 tsutsui
318 1.7 tsutsui void
319 1.7 tsutsui zscninit(struct consdev *cp)
320 1.7 tsutsui {
321 1.7 tsutsui
322 1.7 tsutsui cp->cn_dev = zs_init(cp->address, cp->speed);
323 1.7 tsutsui }
324 1.7 tsutsui
325 1.7 tsutsui int
326 1.7 tsutsui zscngetchar(void *dev)
327 1.7 tsutsui {
328 1.7 tsutsui
329 1.7 tsutsui return zs_getc(dev);
330 1.7 tsutsui }
331 1.7 tsutsui
332 1.7 tsutsui void
333 1.7 tsutsui zscnputchar(void *dev, int c)
334 1.7 tsutsui {
335 1.7 tsutsui
336 1.7 tsutsui if (c == '\n')
337 1.7 tsutsui zs_putc(dev, '\r');
338 1.7 tsutsui zs_putc(dev, c);
339 1.7 tsutsui }
340 1.7 tsutsui
341 1.7 tsutsui int
342 1.7 tsutsui zscnscan(void *dev)
343 1.7 tsutsui {
344 1.7 tsutsui
345 1.7 tsutsui return zs_scan(dev);
346 1.7 tsutsui }
347 1.7 tsutsui #endif /* CONS_ZS */
348