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