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