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