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