epcom.c revision 1.1 1 1.1 joff /* $NetBSD: epcom.c,v 1.1 2004/12/22 19:10:25 joff Exp $ */
2 1.1 joff /*
3 1.1 joff * Copyright (c) 1998, 1999, 2001, 2002, 2004 The NetBSD Foundation, Inc.
4 1.1 joff * All rights reserved.
5 1.1 joff *
6 1.1 joff * This code is derived from software contributed to The NetBSD Foundation
7 1.1 joff * by Jesse Off
8 1.1 joff *
9 1.1 joff * This code is derived from software contributed to The NetBSD Foundation
10 1.1 joff * by Ichiro FUKUHARA and Naoto Shimazaki.
11 1.1 joff *
12 1.1 joff * This code is derived from software contributed to The NetBSD Foundation
13 1.1 joff * by IWAMOTO Toshihiro.
14 1.1 joff *
15 1.1 joff * This code is derived from software contributed to The NetBSD Foundation
16 1.1 joff * by Charles M. Hannum.
17 1.1 joff *
18 1.1 joff * Redistribution and use in source and binary forms, with or without
19 1.1 joff * modification, are permitted provided that the following conditions
20 1.1 joff * are met:
21 1.1 joff * 1. Redistributions of source code must retain the above copyright
22 1.1 joff * notice, this list of conditions and the following disclaimer.
23 1.1 joff * 2. Redistributions in binary form must reproduce the above copyright
24 1.1 joff * notice, this list of conditions and the following disclaimer in the
25 1.1 joff * documentation and/or other materials provided with the distribution.
26 1.1 joff * 3. All advertising materials mentioning features or use of this software
27 1.1 joff * must display the following acknowledgement:
28 1.1 joff * This product includes software developed by the NetBSD
29 1.1 joff * Foundation, Inc. and its contributors.
30 1.1 joff * 4. Neither the name of The NetBSD Foundation nor the names of its
31 1.1 joff * contributors may be used to endorse or promote products derived
32 1.1 joff * from this software without specific prior written permission.
33 1.1 joff *
34 1.1 joff * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
35 1.1 joff * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36 1.1 joff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37 1.1 joff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
38 1.1 joff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39 1.1 joff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40 1.1 joff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41 1.1 joff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42 1.1 joff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 1.1 joff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 1.1 joff * POSSIBILITY OF SUCH DAMAGE.
45 1.1 joff */
46 1.1 joff
47 1.1 joff /*
48 1.1 joff * Copyright (c) 1991 The Regents of the University of California.
49 1.1 joff * All rights reserved.
50 1.1 joff *
51 1.1 joff * Redistribution and use in source and binary forms, with or without
52 1.1 joff * modification, are permitted provided that the following conditions
53 1.1 joff * are met:
54 1.1 joff * 1. Redistributions of source code must retain the above copyright
55 1.1 joff * notice, this list of conditions and the following disclaimer.
56 1.1 joff * 2. Redistributions in binary form must reproduce the above copyright
57 1.1 joff * notice, this list of conditions and the following disclaimer in the
58 1.1 joff * documentation and/or other materials provided with the distribution.
59 1.1 joff * 3. Neither the name of the University nor the names of its contributors
60 1.1 joff * may be used to endorse or promote products derived from this software
61 1.1 joff * without specific prior written permission.
62 1.1 joff *
63 1.1 joff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 1.1 joff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 1.1 joff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 1.1 joff * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67 1.1 joff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 1.1 joff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 1.1 joff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 1.1 joff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 1.1 joff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 1.1 joff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 1.1 joff * SUCH DAMAGE.
74 1.1 joff *
75 1.1 joff * @(#)com.c 7.5 (Berkeley) 5/16/91
76 1.1 joff */
77 1.1 joff
78 1.1 joff /*
79 1.1 joff * TODO: hardware flow control
80 1.1 joff */
81 1.1 joff
82 1.1 joff #include <sys/cdefs.h>
83 1.1 joff __KERNEL_RCSID(0, "$NetBSD: epcom.c,v 1.1 2004/12/22 19:10:25 joff Exp $");
84 1.1 joff
85 1.1 joff #include "opt_ddb.h"
86 1.1 joff #include "opt_kgdb.h"
87 1.1 joff #include "epcom.h"
88 1.1 joff
89 1.1 joff #include "rnd.h"
90 1.1 joff #if NRND > 0 && defined(RND_COM)
91 1.1 joff #include <sys/rnd.h>
92 1.1 joff #endif
93 1.1 joff
94 1.1 joff /*
95 1.1 joff * Override cnmagic(9) macro before including <sys/systm.h>.
96 1.1 joff * We need to know if cn_check_magic triggered debugger, so set a flag.
97 1.1 joff * Callers of cn_check_magic must declare int cn_trapped = 0;
98 1.1 joff * XXX: this is *ugly*!
99 1.1 joff */
100 1.1 joff #define cn_trap() \
101 1.1 joff do { \
102 1.1 joff console_debugger(); \
103 1.1 joff cn_trapped = 1; \
104 1.1 joff } while (/* CONSTCOND */ 0)
105 1.1 joff
106 1.1 joff
107 1.1 joff #include <sys/param.h>
108 1.1 joff #include <sys/systm.h>
109 1.1 joff #include <sys/types.h>
110 1.1 joff #include <sys/conf.h>
111 1.1 joff #include <sys/file.h>
112 1.1 joff #include <sys/device.h>
113 1.1 joff #include <sys/kernel.h>
114 1.1 joff #include <sys/malloc.h>
115 1.1 joff #include <sys/tty.h>
116 1.1 joff #include <sys/uio.h>
117 1.1 joff #include <sys/vnode.h>
118 1.1 joff
119 1.1 joff #include <machine/intr.h>
120 1.1 joff #include <machine/bus.h>
121 1.1 joff
122 1.1 joff #include <arm/ep93xx/epcomreg.h>
123 1.1 joff #include <arm/ep93xx/epcomvar.h>
124 1.1 joff #include <arm/ep93xx/ep93xxreg.h>
125 1.1 joff #include <arm/ep93xx/ep93xxvar.h>
126 1.1 joff
127 1.1 joff #include <dev/cons.h>
128 1.1 joff
129 1.1 joff static int epcomparam(struct tty *, struct termios *);
130 1.1 joff static void epcomstart(struct tty *);
131 1.1 joff static int epcomhwiflow(struct tty *, int);
132 1.1 joff
133 1.1 joff static u_int cflag2lcrhi(tcflag_t);
134 1.1 joff static void epcom_iflush(struct epcom_softc *);
135 1.1 joff static void epcom_set(struct epcom_softc *);
136 1.1 joff
137 1.1 joff int epcomcngetc(dev_t);
138 1.1 joff void epcomcnputc(dev_t, int);
139 1.1 joff void epcomcnpollc(dev_t, int);
140 1.1 joff
141 1.1 joff static void epcomsoft(void* arg);
142 1.1 joff inline static void epcom_txsoft(struct epcom_softc *, struct tty *);
143 1.1 joff inline static void epcom_rxsoft(struct epcom_softc *, struct tty *);
144 1.1 joff
145 1.1 joff void epcomcnprobe(struct consdev *);
146 1.1 joff void epcomcninit(struct consdev *);
147 1.1 joff
148 1.1 joff static struct epcom_cons_softc {
149 1.1 joff bus_space_tag_t sc_iot;
150 1.1 joff bus_space_handle_t sc_ioh;
151 1.1 joff bus_addr_t sc_hwbase;
152 1.1 joff int sc_ospeed;
153 1.1 joff tcflag_t sc_cflag;
154 1.1 joff int sc_attached;
155 1.1 joff } epcomcn_sc;
156 1.1 joff
157 1.1 joff static struct cnm_state epcom_cnm_state;
158 1.1 joff
159 1.1 joff extern struct cfdriver epcom_cd;
160 1.1 joff
161 1.1 joff dev_type_open(epcomopen);
162 1.1 joff dev_type_close(epcomclose);
163 1.1 joff dev_type_read(epcomread);
164 1.1 joff dev_type_write(epcomwrite);
165 1.1 joff dev_type_ioctl(epcomioctl);
166 1.1 joff dev_type_stop(epcomstop);
167 1.1 joff dev_type_tty(epcomtty);
168 1.1 joff dev_type_poll(epcompoll);
169 1.1 joff
170 1.1 joff const struct cdevsw epcom_cdevsw = {
171 1.1 joff epcomopen, epcomclose, epcomread, epcomwrite, epcomioctl,
172 1.1 joff epcomstop, epcomtty, epcompoll, nommap, ttykqfilter, D_TTY
173 1.1 joff };
174 1.1 joff
175 1.1 joff struct consdev epcomcons = {
176 1.1 joff NULL, NULL, epcomcngetc, epcomcnputc, epcomcnpollc, NULL,
177 1.1 joff NULL, NULL, NODEV, CN_NORMAL
178 1.1 joff };
179 1.1 joff
180 1.1 joff #ifndef DEFAULT_COMSPEED
181 1.1 joff #define DEFAULT_COMSPEED 115200
182 1.1 joff #endif
183 1.1 joff
184 1.1 joff #define COMUNIT_MASK 0x7ffff
185 1.1 joff #define COMDIALOUT_MASK 0x80000
186 1.1 joff
187 1.1 joff #define COMUNIT(x) (minor(x) & COMUNIT_MASK)
188 1.1 joff #define COMDIALOUT(x) (minor(x) & COMDIALOUT_MASK)
189 1.1 joff
190 1.1 joff #define COM_ISALIVE(sc) ((sc)->enabled != 0 && \
191 1.1 joff ISSET((sc)->sc_dev.dv_flags, DVF_ACTIVE))
192 1.1 joff
193 1.1 joff #define SET(t, f) (t) |= (f)
194 1.1 joff #define CLR(t, f) (t) &= ~(f)
195 1.1 joff #define ISSET(t, f) ((t) & (f))
196 1.1 joff
197 1.1 joff void
198 1.1 joff epcom_attach_subr(sc)
199 1.1 joff struct epcom_softc *sc;
200 1.1 joff {
201 1.1 joff struct tty *tp;
202 1.1 joff
203 1.1 joff if (sc->sc_iot == epcomcn_sc.sc_iot
204 1.1 joff && sc->sc_hwbase == epcomcn_sc.sc_hwbase) {
205 1.1 joff epcomcn_sc.sc_attached = 1;
206 1.1 joff sc->sc_lcrlo = EPCOMSPEED2BRD(epcomcn_sc.sc_ospeed) & 0xff;
207 1.1 joff sc->sc_lcrmid = EPCOMSPEED2BRD(epcomcn_sc.sc_ospeed) >> 8;
208 1.1 joff
209 1.1 joff /* Make sure the console is always "hardwired". */
210 1.1 joff delay(10000); /* wait for output to finish */
211 1.1 joff SET(sc->sc_hwflags, COM_HW_CONSOLE);
212 1.1 joff SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
213 1.1 joff }
214 1.1 joff
215 1.1 joff tp = ttymalloc();
216 1.1 joff tp->t_oproc = epcomstart;
217 1.1 joff tp->t_param = epcomparam;
218 1.1 joff tp->t_hwiflow = epcomhwiflow;
219 1.1 joff
220 1.1 joff sc->sc_tty = tp;
221 1.1 joff sc->sc_rbuf = malloc(EPCOM_RING_SIZE << 1, M_DEVBUF, M_NOWAIT);
222 1.1 joff sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
223 1.1 joff sc->sc_rbavail = EPCOM_RING_SIZE;
224 1.1 joff if (sc->sc_rbuf == NULL) {
225 1.1 joff printf("%s: unable to allocate ring buffer\n",
226 1.1 joff sc->sc_dev.dv_xname);
227 1.1 joff return;
228 1.1 joff }
229 1.1 joff sc->sc_ebuf = sc->sc_rbuf + (EPCOM_RING_SIZE << 1);
230 1.1 joff sc->sc_tbc = 0;
231 1.1 joff
232 1.1 joff sc->sc_lcrlo = EPCOMSPEED2BRD(DEFAULT_COMSPEED) & 0xff;
233 1.1 joff sc->sc_lcrmid = EPCOMSPEED2BRD(DEFAULT_COMSPEED) >> 8;
234 1.1 joff sc->sc_lcrhi = cflag2lcrhi(CS8); /* 8N1 */
235 1.1 joff
236 1.1 joff tty_attach(tp);
237 1.1 joff
238 1.1 joff if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
239 1.1 joff int maj;
240 1.1 joff
241 1.1 joff /* locate the major number */
242 1.1 joff maj = cdevsw_lookup_major(&epcom_cdevsw);
243 1.1 joff
244 1.1 joff cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
245 1.1 joff
246 1.1 joff aprint_normal("%s: console\n", sc->sc_dev.dv_xname);
247 1.1 joff }
248 1.1 joff
249 1.1 joff sc->sc_si = softintr_establish(IPL_SOFTSERIAL, epcomsoft, sc);
250 1.1 joff
251 1.1 joff #if NRND > 0 && defined(RND_COM)
252 1.1 joff rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
253 1.1 joff RND_TYPE_TTY, 0);
254 1.1 joff #endif
255 1.1 joff
256 1.1 joff /* if there are no enable/disable functions, assume the device
257 1.1 joff is always enabled */
258 1.1 joff if (!sc->enable)
259 1.1 joff sc->enabled = 1;
260 1.1 joff
261 1.1 joff /* XXX configure register */
262 1.1 joff /* xxx_config(sc) */
263 1.1 joff
264 1.1 joff SET(sc->sc_hwflags, COM_HW_DEV_OK);
265 1.1 joff }
266 1.1 joff
267 1.1 joff static int
268 1.1 joff epcomparam(tp, t)
269 1.1 joff struct tty *tp;
270 1.1 joff struct termios *t;
271 1.1 joff {
272 1.1 joff struct epcom_softc *sc
273 1.1 joff = device_lookup(&epcom_cd, COMUNIT(tp->t_dev));
274 1.1 joff int s;
275 1.1 joff
276 1.1 joff if (COM_ISALIVE(sc) == 0)
277 1.1 joff return (EIO);
278 1.1 joff
279 1.1 joff if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
280 1.1 joff return (EINVAL);
281 1.1 joff
282 1.1 joff /*
283 1.1 joff * For the console, always force CLOCAL and !HUPCL, so that the port
284 1.1 joff * is always active.
285 1.1 joff */
286 1.1 joff if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
287 1.1 joff ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
288 1.1 joff SET(t->c_cflag, CLOCAL);
289 1.1 joff CLR(t->c_cflag, HUPCL);
290 1.1 joff }
291 1.1 joff
292 1.1 joff /*
293 1.1 joff * If there were no changes, don't do anything. This avoids dropping
294 1.1 joff * input and improves performance when all we did was frob things like
295 1.1 joff * VMIN and VTIME.
296 1.1 joff */
297 1.1 joff if (tp->t_ospeed == t->c_ospeed &&
298 1.1 joff tp->t_cflag == t->c_cflag)
299 1.1 joff return (0);
300 1.1 joff
301 1.1 joff s = splserial();
302 1.1 joff
303 1.1 joff sc->sc_lcrhi = cflag2lcrhi(t->c_cflag);
304 1.1 joff sc->sc_lcrlo = EPCOMSPEED2BRD(t->c_ospeed) & 0xff;
305 1.1 joff sc->sc_lcrmid = EPCOMSPEED2BRD(t->c_ospeed) >> 8;
306 1.1 joff
307 1.1 joff /* And copy to tty. */
308 1.1 joff tp->t_ispeed = 0;
309 1.1 joff tp->t_ospeed = t->c_ospeed;
310 1.1 joff tp->t_cflag = t->c_cflag;
311 1.1 joff
312 1.1 joff if (!sc->sc_heldchange) {
313 1.1 joff if (sc->sc_tx_busy) {
314 1.1 joff sc->sc_heldtbc = sc->sc_tbc;
315 1.1 joff sc->sc_tbc = 0;
316 1.1 joff sc->sc_heldchange = 1;
317 1.1 joff } else
318 1.1 joff epcom_set(sc);
319 1.1 joff }
320 1.1 joff
321 1.1 joff splx(s);
322 1.1 joff
323 1.1 joff /*
324 1.1 joff * Update the tty layer's idea of the carrier bit.
325 1.1 joff * We tell tty the carrier is always on.
326 1.1 joff */
327 1.1 joff (void) (*tp->t_linesw->l_modem)(tp, 1);
328 1.1 joff
329 1.1 joff #ifdef COM_DEBUG
330 1.1 joff if (com_debug)
331 1.1 joff comstatus(sc, "comparam ");
332 1.1 joff #endif
333 1.1 joff
334 1.1 joff if (!ISSET(t->c_cflag, CHWFLOW)) {
335 1.1 joff if (sc->sc_tx_stopped) {
336 1.1 joff sc->sc_tx_stopped = 0;
337 1.1 joff epcomstart(tp);
338 1.1 joff }
339 1.1 joff }
340 1.1 joff
341 1.1 joff return (0);
342 1.1 joff }
343 1.1 joff
344 1.1 joff static int
345 1.1 joff epcomhwiflow(tp, block)
346 1.1 joff struct tty *tp;
347 1.1 joff int block;
348 1.1 joff {
349 1.1 joff return (0);
350 1.1 joff }
351 1.1 joff
352 1.1 joff static void
353 1.1 joff epcom_filltx(struct epcom_softc *sc)
354 1.1 joff {
355 1.1 joff bus_space_tag_t iot = sc->sc_iot;
356 1.1 joff bus_space_handle_t ioh = sc->sc_ioh;
357 1.1 joff int n;
358 1.1 joff
359 1.1 joff n = 0;
360 1.1 joff while ((bus_space_read_4(iot, ioh, EPCOM_Flag) & Flag_TXFF) == 0) {
361 1.1 joff if (n >= sc->sc_tbc)
362 1.1 joff break;
363 1.1 joff bus_space_write_4(iot, ioh, EPCOM_Data,
364 1.1 joff 0xff & *(sc->sc_tba + n));
365 1.1 joff n++;
366 1.1 joff }
367 1.1 joff sc->sc_tbc -= n;
368 1.1 joff sc->sc_tba += n;
369 1.1 joff }
370 1.1 joff
371 1.1 joff static void
372 1.1 joff epcomstart(tp)
373 1.1 joff struct tty *tp;
374 1.1 joff {
375 1.1 joff struct epcom_softc *sc
376 1.1 joff = device_lookup(&epcom_cd, COMUNIT(tp->t_dev));
377 1.1 joff int s;
378 1.1 joff
379 1.1 joff if (COM_ISALIVE(sc) == 0)
380 1.1 joff return;
381 1.1 joff
382 1.1 joff s = spltty();
383 1.1 joff if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
384 1.1 joff goto out;
385 1.1 joff if (sc->sc_tx_stopped)
386 1.1 joff goto out;
387 1.1 joff
388 1.1 joff if (tp->t_outq.c_cc <= tp->t_lowat) {
389 1.1 joff if (ISSET(tp->t_state, TS_ASLEEP)) {
390 1.1 joff CLR(tp->t_state, TS_ASLEEP);
391 1.1 joff wakeup(&tp->t_outq);
392 1.1 joff }
393 1.1 joff selwakeup(&tp->t_wsel);
394 1.1 joff if (tp->t_outq.c_cc == 0)
395 1.1 joff goto out;
396 1.1 joff }
397 1.1 joff
398 1.1 joff /* Grab the first contiguous region of buffer space. */
399 1.1 joff {
400 1.1 joff u_char *tba;
401 1.1 joff int tbc;
402 1.1 joff
403 1.1 joff tba = tp->t_outq.c_cf;
404 1.1 joff tbc = ndqb(&tp->t_outq, 0);
405 1.1 joff
406 1.1 joff (void)splserial();
407 1.1 joff
408 1.1 joff sc->sc_tba = tba;
409 1.1 joff sc->sc_tbc = tbc;
410 1.1 joff }
411 1.1 joff
412 1.1 joff SET(tp->t_state, TS_BUSY);
413 1.1 joff sc->sc_tx_busy = 1;
414 1.1 joff
415 1.1 joff if (!ISSET(sc->sc_ctrl, Ctrl_TIE)) {
416 1.1 joff SET(sc->sc_ctrl, Ctrl_TIE);
417 1.1 joff epcom_set(sc);
418 1.1 joff }
419 1.1 joff
420 1.1 joff /* Output the first chunk of the contiguous buffer. */
421 1.1 joff epcom_filltx(sc);
422 1.1 joff
423 1.1 joff out:
424 1.1 joff splx(s);
425 1.1 joff return;
426 1.1 joff }
427 1.1 joff
428 1.1 joff static void
429 1.1 joff epcom_break(struct epcom_softc *sc, int onoff)
430 1.1 joff {
431 1.1 joff if (onoff)
432 1.1 joff SET(sc->sc_lcrhi, LinCtrlHigh_BRK);
433 1.1 joff else
434 1.1 joff CLR(sc->sc_lcrhi, LinCtrlHigh_BRK);
435 1.1 joff if (!sc->sc_heldchange) {
436 1.1 joff if (sc->sc_tx_busy) {
437 1.1 joff sc->sc_heldtbc = sc->sc_tbc;
438 1.1 joff sc->sc_tbc = 0;
439 1.1 joff sc->sc_heldchange = 1;
440 1.1 joff } else
441 1.1 joff epcom_set(sc);
442 1.1 joff }
443 1.1 joff }
444 1.1 joff
445 1.1 joff static void
446 1.1 joff epcom_shutdown(struct epcom_softc *sc)
447 1.1 joff {
448 1.1 joff int s;
449 1.1 joff
450 1.1 joff s = splserial();
451 1.1 joff
452 1.1 joff /* Turn off interrupts. */
453 1.1 joff CLR(sc->sc_ctrl, (Ctrl_TIE|Ctrl_RTIE|Ctrl_RIE));
454 1.1 joff
455 1.1 joff /* Clear any break condition set with TIOCSBRK. */
456 1.1 joff epcom_break(sc, 0);
457 1.1 joff epcom_set(sc);
458 1.1 joff
459 1.1 joff if (sc->disable) {
460 1.1 joff #ifdef DIAGNOSTIC
461 1.1 joff if (!sc->enabled)
462 1.1 joff panic("epcom_shutdown: not enabled?");
463 1.1 joff #endif
464 1.1 joff (*sc->disable)(sc);
465 1.1 joff sc->enabled = 0;
466 1.1 joff }
467 1.1 joff splx(s);
468 1.1 joff }
469 1.1 joff
470 1.1 joff int
471 1.1 joff epcomopen(dev, flag, mode, p)
472 1.1 joff dev_t dev;
473 1.1 joff int flag, mode;
474 1.1 joff struct proc *p;
475 1.1 joff {
476 1.1 joff struct epcom_softc *sc;
477 1.1 joff struct tty *tp;
478 1.1 joff int s, s2;
479 1.1 joff int error;
480 1.1 joff
481 1.1 joff sc = device_lookup(&epcom_cd, COMUNIT(dev));
482 1.1 joff if (sc == NULL || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK) ||
483 1.1 joff sc->sc_rbuf == NULL)
484 1.1 joff return (ENXIO);
485 1.1 joff
486 1.1 joff if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
487 1.1 joff return (ENXIO);
488 1.1 joff
489 1.1 joff #ifdef KGDB
490 1.1 joff /*
491 1.1 joff * If this is the kgdb port, no other use is permitted.
492 1.1 joff */
493 1.1 joff if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
494 1.1 joff return (EBUSY);
495 1.1 joff #endif
496 1.1 joff
497 1.1 joff tp = sc->sc_tty;
498 1.1 joff
499 1.1 joff if (ISSET(tp->t_state, TS_ISOPEN) &&
500 1.1 joff ISSET(tp->t_state, TS_XCLUDE) &&
501 1.1 joff p->p_ucred->cr_uid != 0)
502 1.1 joff return (EBUSY);
503 1.1 joff
504 1.1 joff s = spltty();
505 1.1 joff
506 1.1 joff /*
507 1.1 joff * Do the following iff this is a first open.
508 1.1 joff */
509 1.1 joff if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
510 1.1 joff struct termios t;
511 1.1 joff
512 1.1 joff tp->t_dev = dev;
513 1.1 joff
514 1.1 joff s2 = splserial();
515 1.1 joff
516 1.1 joff if (sc->enable) {
517 1.1 joff if ((*sc->enable)(sc)) {
518 1.1 joff splx(s2);
519 1.1 joff splx(s);
520 1.1 joff printf("%s: device enable failed\n",
521 1.1 joff sc->sc_dev.dv_xname);
522 1.1 joff return (EIO);
523 1.1 joff }
524 1.1 joff sc->enabled = 1;
525 1.1 joff #if 0
526 1.1 joff /* XXXXXXXXXXXXXXX */
527 1.1 joff com_config(sc);
528 1.1 joff #endif
529 1.1 joff }
530 1.1 joff
531 1.1 joff /* Turn on interrupts. */
532 1.1 joff SET(sc->sc_ctrl, (Ctrl_UARTE|Ctrl_RIE|Ctrl_RTIE));
533 1.1 joff epcom_set(sc);
534 1.1 joff
535 1.1 joff #if 0
536 1.1 joff /* Fetch the current modem control status, needed later. */
537 1.1 joff sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
538 1.1 joff
539 1.1 joff /* Clear PPS capture state on first open. */
540 1.1 joff sc->sc_ppsmask = 0;
541 1.1 joff sc->ppsparam.mode = 0;
542 1.1 joff #endif
543 1.1 joff
544 1.1 joff splx(s2);
545 1.1 joff
546 1.1 joff /*
547 1.1 joff * Initialize the termios status to the defaults. Add in the
548 1.1 joff * sticky bits from TIOCSFLAGS.
549 1.1 joff */
550 1.1 joff t.c_ispeed = 0;
551 1.1 joff if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
552 1.1 joff t.c_ospeed = epcomcn_sc.sc_ospeed;
553 1.1 joff t.c_cflag = epcomcn_sc.sc_cflag;
554 1.1 joff } else {
555 1.1 joff t.c_ospeed = TTYDEF_SPEED;
556 1.1 joff t.c_cflag = TTYDEF_CFLAG;
557 1.1 joff }
558 1.1 joff if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
559 1.1 joff SET(t.c_cflag, CLOCAL);
560 1.1 joff if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
561 1.1 joff SET(t.c_cflag, CRTSCTS);
562 1.1 joff if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
563 1.1 joff SET(t.c_cflag, MDMBUF);
564 1.1 joff /* Make sure epcomparam() will do something. */
565 1.1 joff tp->t_ospeed = 0;
566 1.1 joff (void) epcomparam(tp, &t);
567 1.1 joff tp->t_iflag = TTYDEF_IFLAG;
568 1.1 joff tp->t_oflag = TTYDEF_OFLAG;
569 1.1 joff tp->t_lflag = TTYDEF_LFLAG;
570 1.1 joff ttychars(tp);
571 1.1 joff ttsetwater(tp);
572 1.1 joff
573 1.1 joff s2 = splserial();
574 1.1 joff
575 1.1 joff /* Clear the input ring, and unblock. */
576 1.1 joff sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
577 1.1 joff sc->sc_rbavail = EPCOM_RING_SIZE;
578 1.1 joff epcom_iflush(sc);
579 1.1 joff CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
580 1.1 joff
581 1.1 joff #ifdef COM_DEBUG
582 1.1 joff if (epcom_debug)
583 1.1 joff comstatus(sc, "epcomopen ");
584 1.1 joff #endif
585 1.1 joff
586 1.1 joff splx(s2);
587 1.1 joff }
588 1.1 joff
589 1.1 joff splx(s);
590 1.1 joff
591 1.1 joff error = ttyopen(tp, COMDIALOUT(dev), ISSET(flag, O_NONBLOCK));
592 1.1 joff if (error)
593 1.1 joff goto bad;
594 1.1 joff
595 1.1 joff error = (*tp->t_linesw->l_open)(dev, tp);
596 1.1 joff if (error)
597 1.1 joff goto bad;
598 1.1 joff
599 1.1 joff return (0);
600 1.1 joff
601 1.1 joff bad:
602 1.1 joff if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
603 1.1 joff /*
604 1.1 joff * We failed to open the device, and nobody else had it opened.
605 1.1 joff * Clean up the state as appropriate.
606 1.1 joff */
607 1.1 joff epcom_shutdown(sc);
608 1.1 joff }
609 1.1 joff
610 1.1 joff return (error);
611 1.1 joff }
612 1.1 joff
613 1.1 joff int
614 1.1 joff epcomclose(dev, flag, mode, p)
615 1.1 joff dev_t dev;
616 1.1 joff int flag, mode;
617 1.1 joff struct proc *p;
618 1.1 joff {
619 1.1 joff struct epcom_softc *sc = device_lookup(&epcom_cd, COMUNIT(dev));
620 1.1 joff struct tty *tp = sc->sc_tty;
621 1.1 joff
622 1.1 joff /* XXX This is for cons.c. */
623 1.1 joff if (!ISSET(tp->t_state, TS_ISOPEN))
624 1.1 joff return (0);
625 1.1 joff
626 1.1 joff (*tp->t_linesw->l_close)(tp, flag);
627 1.1 joff ttyclose(tp);
628 1.1 joff
629 1.1 joff if (COM_ISALIVE(sc) == 0)
630 1.1 joff return (0);
631 1.1 joff
632 1.1 joff if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
633 1.1 joff /*
634 1.1 joff * Although we got a last close, the device may still be in
635 1.1 joff * use; e.g. if this was the dialout node, and there are still
636 1.1 joff * processes waiting for carrier on the non-dialout node.
637 1.1 joff */
638 1.1 joff epcom_shutdown(sc);
639 1.1 joff }
640 1.1 joff
641 1.1 joff return (0);
642 1.1 joff }
643 1.1 joff
644 1.1 joff int
645 1.1 joff epcomread(dev, uio, flag)
646 1.1 joff dev_t dev;
647 1.1 joff struct uio *uio;
648 1.1 joff int flag;
649 1.1 joff {
650 1.1 joff struct epcom_softc *sc = device_lookup(&epcom_cd, COMUNIT(dev));
651 1.1 joff struct tty *tp = sc->sc_tty;
652 1.1 joff
653 1.1 joff if (COM_ISALIVE(sc) == 0)
654 1.1 joff return (EIO);
655 1.1 joff
656 1.1 joff return ((*tp->t_linesw->l_read)(tp, uio, flag));
657 1.1 joff }
658 1.1 joff
659 1.1 joff int
660 1.1 joff epcomwrite(dev, uio, flag)
661 1.1 joff dev_t dev;
662 1.1 joff struct uio *uio;
663 1.1 joff int flag;
664 1.1 joff {
665 1.1 joff struct epcom_softc *sc = device_lookup(&epcom_cd, COMUNIT(dev));
666 1.1 joff struct tty *tp = sc->sc_tty;
667 1.1 joff
668 1.1 joff if (COM_ISALIVE(sc) == 0)
669 1.1 joff return (EIO);
670 1.1 joff
671 1.1 joff return ((*tp->t_linesw->l_write)(tp, uio, flag));
672 1.1 joff }
673 1.1 joff
674 1.1 joff int
675 1.1 joff epcompoll(dev, events, p)
676 1.1 joff dev_t dev;
677 1.1 joff int events;
678 1.1 joff struct proc *p;
679 1.1 joff {
680 1.1 joff struct epcom_softc *sc = device_lookup(&epcom_cd, COMUNIT(dev));
681 1.1 joff struct tty *tp = sc->sc_tty;
682 1.1 joff
683 1.1 joff if (COM_ISALIVE(sc) == 0)
684 1.1 joff return (EIO);
685 1.1 joff
686 1.1 joff return ((*tp->t_linesw->l_poll)(tp, events, p));
687 1.1 joff }
688 1.1 joff
689 1.1 joff struct tty *
690 1.1 joff epcomtty(dev)
691 1.1 joff dev_t dev;
692 1.1 joff {
693 1.1 joff struct epcom_softc *sc = device_lookup(&epcom_cd, COMUNIT(dev));
694 1.1 joff struct tty *tp = sc->sc_tty;
695 1.1 joff
696 1.1 joff return (tp);
697 1.1 joff }
698 1.1 joff
699 1.1 joff int
700 1.1 joff epcomioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
701 1.1 joff {
702 1.1 joff struct epcom_softc *sc = device_lookup(&epcom_cd, COMUNIT(dev));
703 1.1 joff struct tty *tp = sc->sc_tty;
704 1.1 joff int error;
705 1.1 joff int s;
706 1.1 joff
707 1.1 joff if (COM_ISALIVE(sc) == 0)
708 1.1 joff return (EIO);
709 1.1 joff
710 1.1 joff error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
711 1.1 joff if (error != EPASSTHROUGH)
712 1.1 joff return (error);
713 1.1 joff
714 1.1 joff error = ttioctl(tp, cmd, data, flag, p);
715 1.1 joff if (error != EPASSTHROUGH)
716 1.1 joff return (error);
717 1.1 joff
718 1.1 joff error = 0;
719 1.1 joff
720 1.1 joff s = splserial();
721 1.1 joff
722 1.1 joff switch (cmd) {
723 1.1 joff case TIOCSBRK:
724 1.1 joff epcom_break(sc, 1);
725 1.1 joff break;
726 1.1 joff
727 1.1 joff case TIOCCBRK:
728 1.1 joff epcom_break(sc, 0);
729 1.1 joff break;
730 1.1 joff
731 1.1 joff case TIOCGFLAGS:
732 1.1 joff *(int *)data = sc->sc_swflags;
733 1.1 joff break;
734 1.1 joff
735 1.1 joff case TIOCSFLAGS:
736 1.1 joff error = suser(p->p_ucred, &p->p_acflag);
737 1.1 joff if (error)
738 1.1 joff break;
739 1.1 joff sc->sc_swflags = *(int *)data;
740 1.1 joff break;
741 1.1 joff
742 1.1 joff default:
743 1.1 joff error = EPASSTHROUGH;
744 1.1 joff break;
745 1.1 joff }
746 1.1 joff
747 1.1 joff splx(s);
748 1.1 joff
749 1.1 joff return (error);
750 1.1 joff }
751 1.1 joff
752 1.1 joff /*
753 1.1 joff * Stop output on a line.
754 1.1 joff */
755 1.1 joff void
756 1.1 joff epcomstop(tp, flag)
757 1.1 joff struct tty *tp;
758 1.1 joff int flag;
759 1.1 joff {
760 1.1 joff struct epcom_softc *sc
761 1.1 joff = device_lookup(&epcom_cd, COMUNIT(tp->t_dev));
762 1.1 joff int s;
763 1.1 joff
764 1.1 joff s = splserial();
765 1.1 joff if (ISSET(tp->t_state, TS_BUSY)) {
766 1.1 joff /* Stop transmitting at the next chunk. */
767 1.1 joff sc->sc_tbc = 0;
768 1.1 joff sc->sc_heldtbc = 0;
769 1.1 joff if (!ISSET(tp->t_state, TS_TTSTOP))
770 1.1 joff SET(tp->t_state, TS_FLUSH);
771 1.1 joff }
772 1.1 joff splx(s);
773 1.1 joff }
774 1.1 joff
775 1.1 joff static u_int
776 1.1 joff cflag2lcrhi(cflag)
777 1.1 joff tcflag_t cflag;
778 1.1 joff {
779 1.1 joff u_int lcrhi;
780 1.1 joff
781 1.1 joff switch (cflag & CSIZE) {
782 1.1 joff case CS7:
783 1.1 joff lcrhi = 0x40;
784 1.1 joff break;
785 1.1 joff case CS6:
786 1.1 joff lcrhi = 0x20;
787 1.1 joff break;
788 1.1 joff case CS8:
789 1.1 joff default:
790 1.1 joff lcrhi = 0x60;
791 1.1 joff break;
792 1.1 joff }
793 1.1 joff lcrhi |= (cflag & PARENB) ? LinCtrlHigh_PEN : 0;
794 1.1 joff lcrhi |= (cflag & PARODD) ? 0 : LinCtrlHigh_EPS;
795 1.1 joff lcrhi |= (cflag & CSTOPB) ? LinCtrlHigh_STP2 : 0;
796 1.1 joff lcrhi |= LinCtrlHigh_FEN; /* FIFO always enabled */
797 1.1 joff
798 1.1 joff return (lcrhi);
799 1.1 joff }
800 1.1 joff
801 1.1 joff static void
802 1.1 joff epcom_iflush(sc)
803 1.1 joff struct epcom_softc *sc;
804 1.1 joff {
805 1.1 joff bus_space_tag_t iot = sc->sc_iot;
806 1.1 joff bus_space_handle_t ioh = sc->sc_ioh;
807 1.1 joff #ifdef DIAGNOSTIC
808 1.1 joff int reg;
809 1.1 joff #endif
810 1.1 joff int timo;
811 1.1 joff
812 1.1 joff #ifdef DIAGNOSTIC
813 1.1 joff reg = 0xffff;
814 1.1 joff #endif
815 1.1 joff timo = 50000;
816 1.1 joff /* flush any pending I/O */
817 1.1 joff while ((bus_space_read_4(iot, ioh, EPCOM_Flag) & Flag_RXFE) == 0
818 1.1 joff && --timo)
819 1.1 joff #ifdef DIAGNOSTIC
820 1.1 joff reg =
821 1.1 joff #else
822 1.1 joff (void)
823 1.1 joff #endif
824 1.1 joff bus_space_read_4(iot, ioh, EPCOM_Data);
825 1.1 joff #ifdef DIAGNOSTIC
826 1.1 joff if (!timo)
827 1.1 joff printf("%s: com_iflush timeout %02x\n", sc->sc_dev.dv_xname,
828 1.1 joff reg);
829 1.1 joff #endif
830 1.1 joff }
831 1.1 joff
832 1.1 joff static void
833 1.1 joff epcom_set(struct epcom_softc *sc)
834 1.1 joff {
835 1.1 joff bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPCOM_LinCtrlLow,
836 1.1 joff sc->sc_lcrlo);
837 1.1 joff bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPCOM_LinCtrlMid,
838 1.1 joff sc->sc_lcrmid);
839 1.1 joff bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPCOM_LinCtrlHigh,
840 1.1 joff sc->sc_lcrhi);
841 1.1 joff bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPCOM_Ctrl,
842 1.1 joff sc->sc_ctrl);
843 1.1 joff }
844 1.1 joff
845 1.1 joff int
846 1.1 joff epcomcnattach(iot, iobase, ioh, ospeed, cflag)
847 1.1 joff bus_space_tag_t iot;
848 1.1 joff bus_addr_t iobase;
849 1.1 joff bus_space_handle_t ioh;
850 1.1 joff int ospeed;
851 1.1 joff tcflag_t cflag;
852 1.1 joff {
853 1.1 joff u_int lcrlo, lcrmid, lcrhi, ctrl, pwrcnt;
854 1.1 joff bus_space_handle_t syscon_ioh;
855 1.1 joff
856 1.1 joff cn_tab = &epcomcons;
857 1.1 joff cn_init_magic(&epcom_cnm_state);
858 1.1 joff cn_set_magic("\047\001");
859 1.1 joff
860 1.1 joff epcomcn_sc.sc_iot = iot;
861 1.1 joff epcomcn_sc.sc_ioh = ioh;
862 1.1 joff epcomcn_sc.sc_hwbase = iobase;
863 1.1 joff epcomcn_sc.sc_ospeed = ospeed;
864 1.1 joff epcomcn_sc.sc_cflag = cflag;
865 1.1 joff
866 1.1 joff lcrhi = cflag2lcrhi(cflag);
867 1.1 joff lcrlo = EPCOMSPEED2BRD(ospeed) & 0xff;
868 1.1 joff lcrmid = EPCOMSPEED2BRD(ospeed) >> 8;
869 1.1 joff ctrl = Ctrl_UARTE;
870 1.1 joff
871 1.1 joff bus_space_map(iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
872 1.1 joff EP93XX_APB_SYSCON_SIZE, 0, &syscon_ioh);
873 1.1 joff pwrcnt = bus_space_read_4(iot, syscon_ioh, EP93XX_SYSCON_PwrCnt);
874 1.1 joff pwrcnt &= ~(PwrCnt_UARTBAUD);
875 1.1 joff bus_space_write_4(iot, syscon_ioh, EP93XX_SYSCON_PwrCnt, pwrcnt);
876 1.1 joff bus_space_unmap(iot, syscon_ioh, EP93XX_APB_SYSCON_SIZE);
877 1.1 joff
878 1.1 joff bus_space_write_4(iot, ioh, EPCOM_LinCtrlLow, lcrlo);
879 1.1 joff bus_space_write_4(iot, ioh, EPCOM_LinCtrlMid, lcrmid);
880 1.1 joff bus_space_write_4(iot, ioh, EPCOM_LinCtrlHigh, lcrhi);
881 1.1 joff bus_space_write_4(iot, ioh, EPCOM_Ctrl, ctrl);
882 1.1 joff
883 1.1 joff return (0);
884 1.1 joff }
885 1.1 joff
886 1.1 joff void
887 1.1 joff epcomcnprobe(cp)
888 1.1 joff struct consdev *cp;
889 1.1 joff {
890 1.1 joff cp->cn_pri = CN_REMOTE;
891 1.1 joff }
892 1.1 joff
893 1.1 joff void
894 1.1 joff epcomcnpollc(dev, on)
895 1.1 joff dev_t dev;
896 1.1 joff int on;
897 1.1 joff {
898 1.1 joff }
899 1.1 joff
900 1.1 joff void
901 1.1 joff epcomcnputc(dev, c)
902 1.1 joff dev_t dev;
903 1.1 joff int c;
904 1.1 joff {
905 1.1 joff int s;
906 1.1 joff bus_space_tag_t iot = epcomcn_sc.sc_iot;
907 1.1 joff bus_space_handle_t ioh = epcomcn_sc.sc_ioh;
908 1.1 joff
909 1.1 joff s = splserial();
910 1.1 joff
911 1.1 joff while((bus_space_read_4(iot, ioh, EPCOM_Flag) & Flag_TXFF) != 0)
912 1.1 joff ;
913 1.1 joff
914 1.1 joff bus_space_write_4(iot, ioh, EPCOM_Data, c);
915 1.1 joff
916 1.1 joff #ifdef DEBUG
917 1.1 joff if (c == '\r') {
918 1.1 joff while((bus_space_read_4(iot, ioh, EPCOM_Flag) & Flag_TXFE) == 0)
919 1.1 joff ;
920 1.1 joff }
921 1.1 joff #endif
922 1.1 joff
923 1.1 joff splx(s);
924 1.1 joff }
925 1.1 joff
926 1.1 joff int
927 1.1 joff epcomcngetc(dev)
928 1.1 joff dev_t dev;
929 1.1 joff {
930 1.1 joff int c, sts;
931 1.1 joff int s;
932 1.1 joff bus_space_tag_t iot = epcomcn_sc.sc_iot;
933 1.1 joff bus_space_handle_t ioh = epcomcn_sc.sc_ioh;
934 1.1 joff
935 1.1 joff s = splserial();
936 1.1 joff
937 1.1 joff while((bus_space_read_4(iot, ioh, EPCOM_Flag) & Flag_RXFE) != 0)
938 1.1 joff ;
939 1.1 joff
940 1.1 joff c = bus_space_read_4(iot, ioh, EPCOM_Data);
941 1.1 joff sts = bus_space_read_4(iot, ioh, EPCOM_RXSts);
942 1.1 joff if (ISSET(sts, RXSts_BE)) c = CNC_BREAK;
943 1.1 joff #ifdef DDB
944 1.1 joff extern int db_active;
945 1.1 joff if (!db_active)
946 1.1 joff #endif
947 1.1 joff {
948 1.1 joff int cn_trapped = 0; /* unused */
949 1.1 joff
950 1.1 joff cn_check_magic(dev, c, epcom_cnm_state);
951 1.1 joff }
952 1.1 joff c &= 0xff;
953 1.1 joff splx(s);
954 1.1 joff
955 1.1 joff return (c);
956 1.1 joff }
957 1.1 joff
958 1.1 joff inline static void
959 1.1 joff epcom_txsoft(sc, tp)
960 1.1 joff struct epcom_softc *sc;
961 1.1 joff struct tty *tp;
962 1.1 joff {
963 1.1 joff CLR(tp->t_state, TS_BUSY);
964 1.1 joff if (ISSET(tp->t_state, TS_FLUSH))
965 1.1 joff CLR(tp->t_state, TS_FLUSH);
966 1.1 joff else
967 1.1 joff ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
968 1.1 joff (*tp->t_linesw->l_start)(tp);
969 1.1 joff }
970 1.1 joff
971 1.1 joff inline static void
972 1.1 joff epcom_rxsoft(sc, tp)
973 1.1 joff struct epcom_softc *sc;
974 1.1 joff struct tty *tp;
975 1.1 joff {
976 1.1 joff int (*rint) __P((int c, struct tty *tp)) = tp->t_linesw->l_rint;
977 1.1 joff u_char *get, *end;
978 1.1 joff u_int cc, scc;
979 1.1 joff u_char sts;
980 1.1 joff int code;
981 1.1 joff int s;
982 1.1 joff
983 1.1 joff end = sc->sc_ebuf;
984 1.1 joff get = sc->sc_rbget;
985 1.1 joff scc = cc = EPCOM_RING_SIZE - sc->sc_rbavail;
986 1.1 joff #if 0
987 1.1 joff if (cc == EPCOM_RING_SIZE) {
988 1.1 joff sc->sc_floods++;
989 1.1 joff if (sc->sc_errors++ == 0)
990 1.1 joff callout_reset(&sc->sc_diag_callout, 60 * hz,
991 1.1 joff comdiag, sc);
992 1.1 joff }
993 1.1 joff #endif
994 1.1 joff while (cc) {
995 1.1 joff code = get[0];
996 1.1 joff sts = get[1];
997 1.1 joff if (ISSET(sts, RXSts_OE | RXSts_FE | RXSts_PE | RXSts_BE)) {
998 1.1 joff #if 0
999 1.1 joff if (ISSET(lsr, DR_ROR)) {
1000 1.1 joff sc->sc_overflows++;
1001 1.1 joff if (sc->sc_errors++ == 0)
1002 1.1 joff callout_reset(&sc->sc_diag_callout,
1003 1.1 joff 60 * hz, comdiag, sc);
1004 1.1 joff }
1005 1.1 joff #endif
1006 1.1 joff if (ISSET(sts, (RXSts_FE|RXSts_BE)))
1007 1.1 joff SET(code, TTY_FE);
1008 1.1 joff if (ISSET(sts, RXSts_PE))
1009 1.1 joff SET(code, TTY_PE);
1010 1.1 joff }
1011 1.1 joff if ((*rint)(code, tp) == -1) {
1012 1.1 joff /*
1013 1.1 joff * The line discipline's buffer is out of space.
1014 1.1 joff */
1015 1.1 joff if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
1016 1.1 joff /*
1017 1.1 joff * We're either not using flow control, or the
1018 1.1 joff * line discipline didn't tell us to block for
1019 1.1 joff * some reason. Either way, we have no way to
1020 1.1 joff * know when there's more space available, so
1021 1.1 joff * just drop the rest of the data.
1022 1.1 joff */
1023 1.1 joff get += cc << 1;
1024 1.1 joff if (get >= end)
1025 1.1 joff get -= EPCOM_RING_SIZE << 1;
1026 1.1 joff cc = 0;
1027 1.1 joff } else {
1028 1.1 joff /*
1029 1.1 joff * Don't schedule any more receive processing
1030 1.1 joff * until the line discipline tells us there's
1031 1.1 joff * space available (through comhwiflow()).
1032 1.1 joff * Leave the rest of the data in the input
1033 1.1 joff * buffer.
1034 1.1 joff */
1035 1.1 joff SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
1036 1.1 joff }
1037 1.1 joff break;
1038 1.1 joff }
1039 1.1 joff get += 2;
1040 1.1 joff if (get >= end)
1041 1.1 joff get = sc->sc_rbuf;
1042 1.1 joff cc--;
1043 1.1 joff }
1044 1.1 joff
1045 1.1 joff if (cc != scc) {
1046 1.1 joff sc->sc_rbget = get;
1047 1.1 joff s = splserial();
1048 1.1 joff
1049 1.1 joff cc = sc->sc_rbavail += scc - cc;
1050 1.1 joff /* Buffers should be ok again, release possible block. */
1051 1.1 joff if (cc >= 1) {
1052 1.1 joff if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1053 1.1 joff CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1054 1.1 joff SET(sc->sc_ctrl, (Ctrl_RIE|Ctrl_RTIE));
1055 1.1 joff epcom_set(sc);
1056 1.1 joff }
1057 1.1 joff if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
1058 1.1 joff CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
1059 1.1 joff #if 0
1060 1.1 joff com_hwiflow(sc);
1061 1.1 joff #endif
1062 1.1 joff }
1063 1.1 joff }
1064 1.1 joff splx(s);
1065 1.1 joff }
1066 1.1 joff }
1067 1.1 joff
1068 1.1 joff static void
1069 1.1 joff epcomsoft(void* arg)
1070 1.1 joff {
1071 1.1 joff struct epcom_softc *sc = arg;
1072 1.1 joff
1073 1.1 joff if (COM_ISALIVE(sc) == 0)
1074 1.1 joff return;
1075 1.1 joff
1076 1.1 joff if (sc->sc_rx_ready) {
1077 1.1 joff sc->sc_rx_ready = 0;
1078 1.1 joff epcom_rxsoft(sc, sc->sc_tty);
1079 1.1 joff }
1080 1.1 joff if (sc->sc_tx_done) {
1081 1.1 joff sc->sc_tx_done = 0;
1082 1.1 joff epcom_txsoft(sc, sc->sc_tty);
1083 1.1 joff }
1084 1.1 joff }
1085 1.1 joff
1086 1.1 joff int
1087 1.1 joff epcomintr(void* arg)
1088 1.1 joff {
1089 1.1 joff struct epcom_softc *sc = arg;
1090 1.1 joff bus_space_tag_t iot = sc->sc_iot;
1091 1.1 joff bus_space_handle_t ioh = sc->sc_ioh;
1092 1.1 joff u_char *put, *end;
1093 1.1 joff u_int cc;
1094 1.1 joff u_int flagr;
1095 1.1 joff u_int intr;
1096 1.1 joff u_int32_t c, csts;
1097 1.1 joff
1098 1.1 joff intr = bus_space_read_4(iot, ioh, EPCOM_IntIDIntClr);
1099 1.1 joff
1100 1.1 joff if (COM_ISALIVE(sc) == 0)
1101 1.1 joff panic("intr on disabled epcom");
1102 1.1 joff
1103 1.1 joff flagr = bus_space_read_4(iot, ioh, EPCOM_Flag);
1104 1.1 joff
1105 1.1 joff end = sc->sc_ebuf;
1106 1.1 joff put = sc->sc_rbput;
1107 1.1 joff cc = sc->sc_rbavail;
1108 1.1 joff
1109 1.1 joff if (!(ISSET(flagr, Flag_RXFE))) {
1110 1.1 joff if (!ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
1111 1.1 joff while (cc > 0) {
1112 1.1 joff if (ISSET(flagr, Flag_RXFE))
1113 1.1 joff break;
1114 1.1 joff c = bus_space_read_4(iot, ioh, EPCOM_Data);
1115 1.1 joff csts = bus_space_read_4(iot, ioh, EPCOM_RXSts);
1116 1.1 joff if (ISSET(csts, RXSts_BE)) {
1117 1.1 joff int cn_trapped = 0;
1118 1.1 joff
1119 1.1 joff cn_check_magic(sc->sc_tty->t_dev,
1120 1.1 joff CNC_BREAK, epcom_cnm_state);
1121 1.1 joff if (cn_trapped)
1122 1.1 joff goto next;
1123 1.1 joff #if defined(KGDB) && !defined(DDB)
1124 1.1 joff if (ISSET(sc->sc_hwflags, COM_HW_KGDB)){
1125 1.1 joff kgdb_connect(1);
1126 1.1 joff goto next;
1127 1.1 joff }
1128 1.1 joff #endif
1129 1.1 joff } else {
1130 1.1 joff int cn_trapped = 0;
1131 1.1 joff
1132 1.1 joff cn_check_magic(sc->sc_tty->t_dev,
1133 1.1 joff (c & 0xff), epcom_cnm_state);
1134 1.1 joff if (cn_trapped)
1135 1.1 joff goto next;
1136 1.1 joff }
1137 1.1 joff
1138 1.1 joff
1139 1.1 joff put[0] = c & 0xff;
1140 1.1 joff put[1] = csts & 0xf;
1141 1.1 joff put += 2;
1142 1.1 joff if (put >= end)
1143 1.1 joff put = sc->sc_rbuf;
1144 1.1 joff cc--;
1145 1.1 joff next:
1146 1.1 joff flagr = bus_space_read_4(iot, ioh, EPCOM_Flag);
1147 1.1 joff }
1148 1.1 joff
1149 1.1 joff /*
1150 1.1 joff * Current string of incoming characters ended because
1151 1.1 joff * no more data was available or we ran out of space.
1152 1.1 joff * Schedule a receive event if any data was received.
1153 1.1 joff * If we're out of space, turn off receive interrupts.
1154 1.1 joff */
1155 1.1 joff sc->sc_rbput = put;
1156 1.1 joff sc->sc_rbavail = cc;
1157 1.1 joff if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
1158 1.1 joff sc->sc_rx_ready = 1;
1159 1.1 joff
1160 1.1 joff /*
1161 1.1 joff * See if we are in danger of overflowing a buffer. If
1162 1.1 joff * so, use hardware flow control to ease the pressure.
1163 1.1 joff */
1164 1.1 joff
1165 1.1 joff /* but epcom cannot. X-( */
1166 1.1 joff
1167 1.1 joff /*
1168 1.1 joff * If we're out of space, disable receive interrupts
1169 1.1 joff * until the queue has drained a bit.
1170 1.1 joff */
1171 1.1 joff if (!cc) {
1172 1.1 joff SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
1173 1.1 joff CLR(sc->sc_ctrl, (Ctrl_RIE|Ctrl_RTIE));
1174 1.1 joff epcom_set(sc);
1175 1.1 joff }
1176 1.1 joff } else {
1177 1.1 joff #ifdef DIAGNOSTIC
1178 1.1 joff panic("epcomintr: we shouldn't reach here");
1179 1.1 joff #endif
1180 1.1 joff CLR(sc->sc_ctrl, (Ctrl_RIE|Ctrl_RTIE));
1181 1.1 joff epcom_set(sc);
1182 1.1 joff }
1183 1.1 joff }
1184 1.1 joff
1185 1.1 joff /*
1186 1.1 joff * Done handling any receive interrupts. See if data can be
1187 1.1 joff * transmitted as well. Schedule tx done event if no data left
1188 1.1 joff * and tty was marked busy.
1189 1.1 joff */
1190 1.1 joff if (ISSET(flagr, Flag_TXFE)) {
1191 1.1 joff /*
1192 1.1 joff * If we've delayed a parameter change, do it now, and restart
1193 1.1 joff * output.
1194 1.1 joff */
1195 1.1 joff if (sc->sc_heldchange) {
1196 1.1 joff epcom_set(sc);
1197 1.1 joff sc->sc_heldchange = 0;
1198 1.1 joff sc->sc_tbc = sc->sc_heldtbc;
1199 1.1 joff sc->sc_heldtbc = 0;
1200 1.1 joff }
1201 1.1 joff
1202 1.1 joff /* Output the next chunk of the contiguous buffer, if any. */
1203 1.1 joff if (sc->sc_tbc > 0) {
1204 1.1 joff epcom_filltx(sc);
1205 1.1 joff } else {
1206 1.1 joff /* Disable transmit completion interrupts if necessary. */
1207 1.1 joff if (ISSET(sc->sc_ctrl, Ctrl_TIE)) {
1208 1.1 joff CLR(sc->sc_ctrl, Ctrl_TIE);
1209 1.1 joff epcom_set(sc);
1210 1.1 joff }
1211 1.1 joff if (sc->sc_tx_busy) {
1212 1.1 joff sc->sc_tx_busy = 0;
1213 1.1 joff sc->sc_tx_done = 1;
1214 1.1 joff }
1215 1.1 joff }
1216 1.1 joff }
1217 1.1 joff
1218 1.1 joff /* Wake up the poller. */
1219 1.1 joff softintr_schedule(sc->sc_si);
1220 1.1 joff
1221 1.1 joff #if 0 /* XXX: broken */
1222 1.1 joff #if NRND > 0 && defined(RND_COM)
1223 1.1 joff rnd_add_uint32(&sc->rnd_source, intr ^ flagr);
1224 1.1 joff #endif
1225 1.1 joff #endif
1226 1.1 joff return (1);
1227 1.1 joff }
1228