ser.c revision 1.41 1 1.41 is /* $NetBSD: ser.c,v 1.41 1997/09/21 17:21:24 is Exp $ */
2 1.23 cgd
3 1.1 mw /*
4 1.1 mw * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
5 1.1 mw * All rights reserved.
6 1.1 mw *
7 1.1 mw * Redistribution and use in source and binary forms, with or without
8 1.1 mw * modification, are permitted provided that the following conditions
9 1.1 mw * are met:
10 1.1 mw * 1. Redistributions of source code must retain the above copyright
11 1.1 mw * notice, this list of conditions and the following disclaimer.
12 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mw * notice, this list of conditions and the following disclaimer in the
14 1.1 mw * documentation and/or other materials provided with the distribution.
15 1.1 mw * 3. All advertising materials mentioning features or use of this software
16 1.1 mw * must display the following acknowledgement:
17 1.1 mw * This product includes software developed by the University of
18 1.1 mw * California, Berkeley and its contributors.
19 1.1 mw * 4. Neither the name of the University nor the names of its contributors
20 1.1 mw * may be used to endorse or promote products derived from this software
21 1.1 mw * without specific prior written permission.
22 1.1 mw *
23 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 mw * SUCH DAMAGE.
34 1.1 mw *
35 1.4 mw * @(#)ser.c 7.12 (Berkeley) 6/27/91
36 1.15 chopps */
37 1.15 chopps /*
38 1.32 is * XXX This file needs major cleanup it will never service more than one
39 1.15 chopps * XXX unit.
40 1.1 mw */
41 1.1 mw
42 1.10 chopps #include <sys/param.h>
43 1.10 chopps #include <sys/systm.h>
44 1.10 chopps #include <sys/ioctl.h>
45 1.15 chopps #include <sys/device.h>
46 1.10 chopps #include <sys/tty.h>
47 1.10 chopps #include <sys/proc.h>
48 1.10 chopps #include <sys/file.h>
49 1.10 chopps #include <sys/malloc.h>
50 1.10 chopps #include <sys/uio.h>
51 1.10 chopps #include <sys/kernel.h>
52 1.10 chopps #include <sys/syslog.h>
53 1.13 chopps #include <sys/queue.h>
54 1.15 chopps #include <machine/cpu.h>
55 1.15 chopps #include <amiga/amiga/device.h>
56 1.10 chopps #include <amiga/dev/serreg.h>
57 1.10 chopps #include <amiga/amiga/custom.h>
58 1.10 chopps #include <amiga/amiga/cia.h>
59 1.10 chopps #include <amiga/amiga/cc.h>
60 1.1 mw
61 1.14 chopps #include <dev/cons.h>
62 1.14 chopps
63 1.31 veego #include <sys/conf.h>
64 1.31 veego #include <machine/conf.h>
65 1.31 veego
66 1.15 chopps #include "ser.h"
67 1.15 chopps #if NSER > 0
68 1.14 chopps
69 1.15 chopps void serattach __P((struct device *, struct device *, void *));
70 1.39 veego int sermatch __P((struct device *, struct cfdata *, void *));
71 1.15 chopps
72 1.28 jtc struct ser_softc {
73 1.28 jtc struct device dev;
74 1.28 jtc struct tty *ser_tty;
75 1.28 jtc };
76 1.28 jtc
77 1.29 thorpej struct cfattach ser_ca = {
78 1.30 mhitch sizeof(struct ser_softc), sermatch, serattach
79 1.29 thorpej };
80 1.29 thorpej
81 1.29 thorpej struct cfdriver ser_cd = {
82 1.29 thorpej NULL, "ser", DV_TTY, NULL, 0
83 1.29 thorpej };
84 1.15 chopps
85 1.26 chopps #ifndef SEROBUF_SIZE
86 1.15 chopps #define SEROBUF_SIZE 32
87 1.26 chopps #endif
88 1.26 chopps #ifndef SERIBUF_SIZE
89 1.15 chopps #define SERIBUF_SIZE 512
90 1.26 chopps #endif
91 1.26 chopps
92 1.26 chopps #define splser() spl5()
93 1.1 mw
94 1.31 veego void serstart __P((struct tty *));
95 1.31 veego int serparam __P((struct tty *, struct termios *));
96 1.31 veego void serintr __P((int));
97 1.31 veego int serhwiflow __P((struct tty *, int));
98 1.31 veego int sermctl __P((dev_t dev, int, int));
99 1.31 veego void ser_fastint __P((void));
100 1.31 veego void sereint __P((int, int));
101 1.31 veego static void ser_putchar __P((struct tty *, u_short));
102 1.31 veego void ser_outintr __P((void));
103 1.31 veego void sercnprobe __P((struct consdev *));
104 1.31 veego void sercninit __P((struct consdev *));
105 1.31 veego void serinit __P((int, int));
106 1.31 veego int sercngetc __P((dev_t dev));
107 1.31 veego void sercnputc __P((dev_t, int));
108 1.31 veego void sercnpollc __P((dev_t, int));
109 1.31 veego
110 1.1 mw int ser_active;
111 1.1 mw int ser_hasfifo;
112 1.1 mw int nser = NSER;
113 1.1 mw #ifdef SERCONSOLE
114 1.1 mw int serconsole = SERCONSOLE;
115 1.1 mw #else
116 1.1 mw int serconsole = -1;
117 1.1 mw #endif
118 1.1 mw int serconsinit;
119 1.1 mw int serdefaultrate = TTYDEF_SPEED;
120 1.1 mw int sermajor;
121 1.14 chopps int serswflags;
122 1.14 chopps #define SWFLAGS(dev) (serswflags | (DIALOUT(dev) ? TIOCFLAG_SOFTCAR : 0))
123 1.14 chopps
124 1.5 mw struct vbl_node ser_vbl_node[NSER];
125 1.1 mw struct tty ser_cons;
126 1.27 chopps struct tty *ser_tty[NSER];
127 1.1 mw
128 1.14 chopps /*
129 1.14 chopps * Since this UART is not particularly bright (to put it nicely), we'll
130 1.14 chopps * have to do parity stuff on our own. This table contains the 8th bit
131 1.14 chopps * in 7bit character mode, for even parity. If you want odd parity,
132 1.14 chopps * flip the bit. (for generation of the table, see genpar.c)
133 1.14 chopps */
134 1.14 chopps
135 1.14 chopps u_char even_parity[] = {
136 1.14 chopps 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
137 1.14 chopps 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
138 1.14 chopps 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
139 1.14 chopps 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
140 1.14 chopps 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
141 1.14 chopps 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
142 1.14 chopps 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
143 1.14 chopps 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
144 1.1 mw };
145 1.1 mw
146 1.14 chopps /*
147 1.14 chopps * Since we don't get interrupts for changes on the modem control line,
148 1.14 chopps * we'll have to fake them by comparing current settings to the settings
149 1.14 chopps * we remembered on last invocation.
150 1.14 chopps */
151 1.14 chopps
152 1.14 chopps u_char last_ciab_pra;
153 1.14 chopps
154 1.14 chopps extern struct tty *constty;
155 1.1 mw
156 1.1 mw #ifdef KGDB
157 1.10 chopps #include <machine/remote-sl.h>
158 1.1 mw
159 1.1 mw extern dev_t kgdb_dev;
160 1.1 mw extern int kgdb_rate;
161 1.1 mw extern int kgdb_debug_init;
162 1.1 mw #endif
163 1.1 mw
164 1.1 mw #ifdef DEBUG
165 1.1 mw long fifoin[17];
166 1.1 mw long fifoout[17];
167 1.1 mw long serintrcount[16];
168 1.1 mw long sermintcount[16];
169 1.1 mw #endif
170 1.1 mw
171 1.14 chopps void sermint __P((register int unit));
172 1.5 mw
173 1.5 mw int
174 1.39 veego sermatch(pdp, cfp, auxp)
175 1.15 chopps struct device *pdp;
176 1.39 veego struct cfdata *cfp;
177 1.39 veego void *auxp;
178 1.15 chopps {
179 1.29 thorpej
180 1.15 chopps if (matchname("ser", (char *)auxp) == 0 || cfp->cf_unit != 0)
181 1.15 chopps return(0);
182 1.15 chopps if (serconsole != 0 && amiga_realconfig == 0)
183 1.15 chopps return(0);
184 1.15 chopps return(1);
185 1.15 chopps }
186 1.15 chopps
187 1.15 chopps
188 1.15 chopps void
189 1.15 chopps serattach(pdp, dp, auxp)
190 1.15 chopps struct device *pdp, *dp;
191 1.15 chopps void *auxp;
192 1.1 mw {
193 1.15 chopps u_short ir;
194 1.14 chopps
195 1.14 chopps ir = custom.intenar;
196 1.15 chopps if (serconsole == 0)
197 1.14 chopps DELAY(100000);
198 1.14 chopps
199 1.15 chopps ser_active |= 1;
200 1.15 chopps ser_vbl_node[0].function = (void (*) (void *)) sermint;
201 1.15 chopps add_vbl_function(&ser_vbl_node[0], SER_VBL_PRIORITY, (void *) 0);
202 1.1 mw #ifdef KGDB
203 1.15 chopps if (kgdb_dev == makedev(sermajor, 0)) {
204 1.15 chopps if (serconsole == 0)
205 1.14 chopps kgdb_dev = NODEV; /* can't debug over console port */
206 1.14 chopps else {
207 1.15 chopps (void) serinit(0, kgdb_rate);
208 1.14 chopps serconsinit = 1; /* don't re-init in serputc */
209 1.14 chopps if (kgdb_debug_init == 0)
210 1.38 christos printf(" kgdb enabled\n");
211 1.14 chopps else {
212 1.14 chopps /*
213 1.14 chopps * Print prefix of device name,
214 1.14 chopps * let kgdb_connect print the rest.
215 1.14 chopps */
216 1.38 christos printf("ser0: ");
217 1.14 chopps kgdb_connect(1);
218 1.14 chopps }
219 1.14 chopps }
220 1.14 chopps }
221 1.5 mw #endif
222 1.14 chopps /*
223 1.14 chopps * Need to reset baud rate, etc. of next print so reset serconsinit.
224 1.14 chopps */
225 1.15 chopps if (0 == serconsole)
226 1.14 chopps serconsinit = 0;
227 1.15 chopps if (dp)
228 1.38 christos printf(": input fifo %d output fifo %d\n", SERIBUF_SIZE,
229 1.15 chopps SEROBUF_SIZE);
230 1.1 mw }
231 1.1 mw
232 1.14 chopps
233 1.1 mw /* ARGSUSED */
234 1.5 mw int
235 1.1 mw seropen(dev, flag, mode, p)
236 1.14 chopps dev_t dev;
237 1.14 chopps int flag, mode;
238 1.14 chopps struct proc *p;
239 1.1 mw {
240 1.14 chopps struct tty *tp;
241 1.14 chopps int unit, error, s;
242 1.14 chopps
243 1.14 chopps error = 0;
244 1.14 chopps unit = SERUNIT(dev);
245 1.14 chopps
246 1.14 chopps if (unit >= NSER || (ser_active & (1 << unit)) == 0)
247 1.14 chopps return (ENXIO);
248 1.14 chopps
249 1.14 chopps s = spltty();
250 1.14 chopps
251 1.14 chopps if (ser_tty[unit])
252 1.14 chopps tp = ser_tty[unit];
253 1.35 mhitch else {
254 1.29 thorpej tp = ((struct ser_softc *)ser_cd.cd_devs[unit])->ser_tty =
255 1.28 jtc ser_tty[unit] = ttymalloc();
256 1.35 mhitch tty_attach(tp);
257 1.35 mhitch }
258 1.14 chopps
259 1.14 chopps tp->t_oproc = (void (*) (struct tty *)) serstart;
260 1.14 chopps tp->t_param = serparam;
261 1.14 chopps tp->t_dev = dev;
262 1.22 chopps tp->t_hwiflow = serhwiflow;
263 1.14 chopps
264 1.14 chopps if ((tp->t_state & TS_ISOPEN) == 0) {
265 1.14 chopps tp->t_state |= TS_WOPEN;
266 1.14 chopps ttychars(tp);
267 1.14 chopps if (tp->t_ispeed == 0) {
268 1.14 chopps /*
269 1.14 chopps * only when cleared do we reset to defaults.
270 1.14 chopps */
271 1.14 chopps tp->t_iflag = TTYDEF_IFLAG;
272 1.14 chopps tp->t_oflag = TTYDEF_OFLAG;
273 1.14 chopps tp->t_cflag = TTYDEF_CFLAG;
274 1.14 chopps tp->t_lflag = TTYDEF_LFLAG;
275 1.14 chopps tp->t_ispeed = tp->t_ospeed = serdefaultrate;
276 1.14 chopps }
277 1.14 chopps /*
278 1.14 chopps * do these all the time
279 1.14 chopps */
280 1.14 chopps if (serswflags & TIOCFLAG_CLOCAL)
281 1.14 chopps tp->t_cflag |= CLOCAL;
282 1.14 chopps if (serswflags & TIOCFLAG_CRTSCTS)
283 1.14 chopps tp->t_cflag |= CRTSCTS;
284 1.14 chopps if (serswflags & TIOCFLAG_MDMBUF)
285 1.14 chopps tp->t_cflag |= MDMBUF;
286 1.14 chopps serparam(tp, &tp->t_termios);
287 1.14 chopps ttsetwater(tp);
288 1.14 chopps
289 1.14 chopps (void)sermctl(dev, TIOCM_DTR | TIOCM_RTS, DMSET);
290 1.14 chopps if ((SWFLAGS(dev) & TIOCFLAG_SOFTCAR) ||
291 1.14 chopps (sermctl(dev, 0, DMGET) & TIOCM_CD))
292 1.14 chopps tp->t_state |= TS_CARR_ON;
293 1.14 chopps else
294 1.14 chopps tp->t_state &= ~TS_CARR_ON;
295 1.14 chopps } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
296 1.14 chopps splx(s);
297 1.14 chopps return(EBUSY);
298 1.14 chopps }
299 1.14 chopps
300 1.14 chopps /*
301 1.14 chopps * if NONBLOCK requested, ignore carrier
302 1.14 chopps */
303 1.14 chopps if (flag & O_NONBLOCK)
304 1.14 chopps goto done;
305 1.14 chopps
306 1.14 chopps /*
307 1.14 chopps * block waiting for carrier
308 1.14 chopps */
309 1.14 chopps while ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0) {
310 1.14 chopps tp->t_state |= TS_WOPEN;
311 1.14 chopps error = ttysleep(tp, (caddr_t)&tp->t_rawq,
312 1.14 chopps TTIPRI | PCATCH, ttopen, 0);
313 1.14 chopps if (error) {
314 1.14 chopps splx(s);
315 1.14 chopps return(error);
316 1.14 chopps }
317 1.1 mw }
318 1.14 chopps done:
319 1.22 chopps /* This is a way to handle lost XON characters */
320 1.22 chopps if ((flag & O_TRUNC) && (tp->t_state & TS_TTSTOP)) {
321 1.22 chopps tp->t_state &= ~TS_TTSTOP;
322 1.22 chopps ttstart (tp);
323 1.22 chopps }
324 1.22 chopps
325 1.14 chopps splx(s);
326 1.14 chopps /*
327 1.14 chopps * Reset the tty pointer, as there could have been a dialout
328 1.14 chopps * use of the tty with a dialin open waiting.
329 1.14 chopps */
330 1.14 chopps tp->t_dev = dev;
331 1.14 chopps return((*linesw[tp->t_line].l_open)(dev, tp));
332 1.1 mw }
333 1.14 chopps
334 1.1 mw /*ARGSUSED*/
335 1.5 mw int
336 1.1 mw serclose(dev, flag, mode, p)
337 1.14 chopps dev_t dev;
338 1.14 chopps int flag, mode;
339 1.14 chopps struct proc *p;
340 1.14 chopps {
341 1.14 chopps struct tty *tp;
342 1.14 chopps int unit;
343 1.41 is int closebits;
344 1.14 chopps
345 1.14 chopps unit = SERUNIT(dev);
346 1.14 chopps
347 1.14 chopps tp = ser_tty[unit];
348 1.14 chopps (*linesw[tp->t_line].l_close)(tp, flag);
349 1.14 chopps custom.adkcon = ADKCONF_UARTBRK; /* clear break */
350 1.1 mw #ifdef KGDB
351 1.14 chopps /*
352 1.14 chopps * do not disable interrupts if debugging
353 1.14 chopps */
354 1.14 chopps if (dev != kgdb_dev)
355 1.1 mw #endif
356 1.14 chopps custom.intena = INTF_RBF | INTF_TBE; /* disable interrups */
357 1.14 chopps custom.intreq = INTF_RBF | INTF_TBE; /* clear intr request */
358 1.14 chopps
359 1.14 chopps /*
360 1.41 is * If HUPCL is not set, leave DTR unchanged.
361 1.14 chopps */
362 1.41 is if (tp->t_cflag & HUPCL)
363 1.41 is closebits = 0;
364 1.41 is else
365 1.41 is closebits = sermctl(dev, 0, DMGET) & TIOCM_DTR;
366 1.41 is
367 1.41 is (void) sermctl(dev, closebits, DMSET);
368 1.41 is
369 1.41 is /*
370 1.41 is * Idea from dev/isa/com.c:
371 1.41 is * sleep a bit so that other side will notice, even if we reopen
372 1.41 is * immediately.
373 1.41 is */
374 1.41 is (void) tsleep(tp, TTIPRI, ttclos, hz);
375 1.14 chopps ttyclose(tp);
376 1.14 chopps #if not_yet
377 1.14 chopps if (tp != &ser_cons) {
378 1.14 chopps remove_vbl_function(&ser_vbl_node[unit]);
379 1.14 chopps ttyfree(tp);
380 1.14 chopps ser_tty[unit] = (struct tty *) NULL;
381 1.14 chopps }
382 1.3 mw #endif
383 1.14 chopps return (0);
384 1.1 mw }
385 1.14 chopps
386 1.5 mw int
387 1.1 mw serread(dev, uio, flag)
388 1.14 chopps dev_t dev;
389 1.14 chopps struct uio *uio;
390 1.14 chopps int flag;
391 1.1 mw {
392 1.14 chopps struct tty *tp;
393 1.14 chopps if ((tp = ser_tty[SERUNIT(dev)]) == NULL)
394 1.14 chopps return(ENXIO);
395 1.14 chopps return((*linesw[tp->t_line].l_read)(tp, uio, flag));
396 1.14 chopps }
397 1.1 mw
398 1.5 mw int
399 1.1 mw serwrite(dev, uio, flag)
400 1.14 chopps dev_t dev;
401 1.14 chopps struct uio *uio;
402 1.14 chopps int flag;
403 1.1 mw {
404 1.14 chopps struct tty *tp;
405 1.14 chopps
406 1.14 chopps if((tp = ser_tty[SERUNIT(dev)]) == NULL)
407 1.14 chopps return(ENXIO);
408 1.14 chopps return((*linesw[tp->t_line].l_write)(tp, uio, flag));
409 1.1 mw }
410 1.3 mw
411 1.27 chopps struct tty *
412 1.27 chopps sertty(dev)
413 1.27 chopps dev_t dev;
414 1.27 chopps {
415 1.27 chopps return (ser_tty[SERUNIT(dev)]);
416 1.27 chopps }
417 1.3 mw
418 1.14 chopps /*
419 1.14 chopps * We don't do any processing of data here, so we store the raw code
420 1.14 chopps * obtained from the uart register. In theory, 110kBaud gives you
421 1.14 chopps * 11kcps, so 16k buffer should be more than enough, interrupt
422 1.14 chopps * latency of 1s should never happen, or something is seriously
423 1.14 chopps * wrong..
424 1.14 chopps */
425 1.14 chopps
426 1.3 mw static u_short serbuf[SERIBUF_SIZE];
427 1.3 mw static u_short *sbrpt = serbuf;
428 1.3 mw static u_short *sbwpt = serbuf;
429 1.22 chopps static u_short sbcnt;
430 1.18 chopps static u_short sbovfl;
431 1.3 mw
432 1.14 chopps /*
433 1.14 chopps * This is a replacement for the lack of a hardware fifo. 32k should be
434 1.14 chopps * enough (there's only one unit anyway, so this is not going to
435 1.14 chopps * accumulate).
436 1.14 chopps */
437 1.3 mw void
438 1.14 chopps ser_fastint()
439 1.3 mw {
440 1.14 chopps /*
441 1.14 chopps * We're at RBE-level, which is higher than VBL-level which is used
442 1.14 chopps * to periodically transmit contents of this buffer up one layer,
443 1.14 chopps * so no spl-raising is necessary.
444 1.14 chopps */
445 1.14 chopps register u_short ints, code;
446 1.14 chopps
447 1.14 chopps ints = custom.intreqr & INTF_RBF;
448 1.14 chopps if (ints == 0)
449 1.14 chopps return;
450 1.14 chopps
451 1.40 mhitch /*
452 1.40 mhitch * this register contains both data and status bits!
453 1.40 mhitch */
454 1.40 mhitch code = custom.serdatr;
455 1.40 mhitch
456 1.14 chopps /*
457 1.14 chopps * clear interrupt
458 1.14 chopps */
459 1.14 chopps custom.intreq = ints;
460 1.14 chopps
461 1.14 chopps /*
462 1.14 chopps * check for buffer overflow.
463 1.14 chopps */
464 1.22 chopps if (sbcnt == SERIBUF_SIZE) {
465 1.18 chopps ++sbovfl;
466 1.14 chopps return;
467 1.14 chopps }
468 1.14 chopps /*
469 1.14 chopps * store in buffer
470 1.14 chopps */
471 1.14 chopps *sbwpt++ = code;
472 1.14 chopps if (sbwpt == serbuf + SERIBUF_SIZE)
473 1.14 chopps sbwpt = serbuf;
474 1.22 chopps ++sbcnt;
475 1.26 chopps if (sbcnt > SERIBUF_SIZE - 20)
476 1.22 chopps CLRRTS(ciab.pra); /* drop RTS if buffer almost full */
477 1.3 mw }
478 1.3 mw
479 1.3 mw
480 1.31 veego void
481 1.14 chopps serintr(unit)
482 1.14 chopps int unit;
483 1.1 mw {
484 1.18 chopps int s1, s2, ovfl;
485 1.22 chopps struct tty *tp = ser_tty[unit];
486 1.1 mw
487 1.14 chopps /*
488 1.14 chopps * Make sure we're not interrupted by another
489 1.14 chopps * vbl, but allow level5 ints
490 1.14 chopps */
491 1.14 chopps s1 = spltty();
492 1.1 mw
493 1.14 chopps /*
494 1.14 chopps * pass along any acumulated information
495 1.14 chopps */
496 1.22 chopps while (sbcnt > 0 && (tp->t_state & TS_TBLOCK) == 0) {
497 1.14 chopps /*
498 1.14 chopps * no collision with ser_fastint()
499 1.14 chopps */
500 1.22 chopps sereint(unit, *sbrpt++);
501 1.14 chopps
502 1.18 chopps ovfl = 0;
503 1.14 chopps /* lock against ser_fastint() */
504 1.26 chopps s2 = splser();
505 1.22 chopps sbcnt--;
506 1.14 chopps if (sbrpt == serbuf + SERIBUF_SIZE)
507 1.14 chopps sbrpt = serbuf;
508 1.18 chopps if (sbovfl != 0) {
509 1.18 chopps ovfl = sbovfl;
510 1.18 chopps sbovfl = 0;
511 1.18 chopps }
512 1.14 chopps splx(s2);
513 1.18 chopps if (ovfl != 0)
514 1.21 chopps log(LOG_WARNING, "ser0: %d ring buffer overflows.\n",
515 1.21 chopps ovfl);
516 1.14 chopps }
517 1.33 is s2 = splser();
518 1.22 chopps if (sbcnt == 0 && (tp->t_state & TS_TBLOCK) == 0)
519 1.22 chopps SETRTS(ciab.pra); /* start accepting data again */
520 1.33 is splx(s2);
521 1.14 chopps splx(s1);
522 1.1 mw }
523 1.1 mw
524 1.31 veego void
525 1.15 chopps sereint(unit, stat)
526 1.14 chopps int unit, stat;
527 1.1 mw {
528 1.14 chopps struct tty *tp;
529 1.14 chopps u_char ch;
530 1.14 chopps int c;
531 1.14 chopps
532 1.14 chopps tp = ser_tty[unit];
533 1.14 chopps ch = stat & 0xff;
534 1.14 chopps c = ch;
535 1.14 chopps
536 1.14 chopps if ((tp->t_state & TS_ISOPEN) == 0) {
537 1.1 mw #ifdef KGDB
538 1.14 chopps /* we don't care about parity errors */
539 1.14 chopps if (kgdb_dev == makedev(sermajor, unit) && c == FRAME_END)
540 1.14 chopps kgdb_connect(0); /* trap into kgdb */
541 1.1 mw #endif
542 1.14 chopps return;
543 1.14 chopps }
544 1.14 chopps
545 1.14 chopps /*
546 1.14 chopps * Check for break and (if enabled) parity error.
547 1.14 chopps */
548 1.14 chopps if ((stat & 0x1ff) == 0)
549 1.14 chopps c |= TTY_FE;
550 1.14 chopps else if ((tp->t_cflag & PARENB) &&
551 1.14 chopps (((ch >> 7) + even_parity[ch & 0x7f]
552 1.14 chopps + !!(tp->t_cflag & PARODD)) & 1))
553 1.14 chopps c |= TTY_PE;
554 1.14 chopps
555 1.14 chopps if (stat & SERDATRF_OVRUN)
556 1.15 chopps log(LOG_WARNING, "ser0: silo overflow\n");
557 1.1 mw
558 1.14 chopps (*linesw[tp->t_line].l_rint)(c, tp);
559 1.14 chopps }
560 1.14 chopps
561 1.14 chopps /*
562 1.14 chopps * This interrupt is periodically invoked in the vertical blank
563 1.14 chopps * interrupt. It's used to keep track of the modem control lines
564 1.14 chopps * and (new with the fast_int code) to move accumulated data
565 1.14 chopps * up into the tty layer.
566 1.14 chopps */
567 1.3 mw void
568 1.14 chopps sermint(unit)
569 1.14 chopps int unit;
570 1.1 mw {
571 1.14 chopps struct tty *tp;
572 1.14 chopps u_char stat, last, istat;
573 1.14 chopps
574 1.14 chopps tp = ser_tty[unit];
575 1.14 chopps if (!tp)
576 1.14 chopps return;
577 1.14 chopps
578 1.14 chopps if ((tp->t_state & (TS_ISOPEN | TS_WOPEN)) == 0) {
579 1.14 chopps sbrpt = sbwpt = serbuf;
580 1.14 chopps return;
581 1.14 chopps }
582 1.14 chopps /*
583 1.14 chopps * empty buffer
584 1.14 chopps */
585 1.14 chopps serintr(unit);
586 1.14 chopps
587 1.14 chopps stat = ciab.pra;
588 1.14 chopps last = last_ciab_pra;
589 1.14 chopps last_ciab_pra = stat;
590 1.14 chopps
591 1.14 chopps /*
592 1.14 chopps * check whether any interesting signal changed state
593 1.14 chopps */
594 1.14 chopps istat = stat ^ last;
595 1.1 mw
596 1.14 chopps if ((istat & CIAB_PRA_CD) &&
597 1.14 chopps (SWFLAGS(tp->t_dev) & TIOCFLAG_SOFTCAR) == 0) {
598 1.14 chopps if (ISDCD(stat))
599 1.14 chopps (*linesw[tp->t_line].l_modem)(tp, 1);
600 1.14 chopps else if ((*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
601 1.14 chopps CLRDTR(stat);
602 1.14 chopps CLRRTS(stat);
603 1.14 chopps ciab.pra = stat;
604 1.14 chopps last_ciab_pra = stat;
605 1.14 chopps }
606 1.14 chopps }
607 1.14 chopps if ((istat & CIAB_PRA_CTS) && (tp->t_state & TS_ISOPEN) &&
608 1.14 chopps (tp->t_cflag & CRTSCTS)) {
609 1.5 mw #if 0
610 1.14 chopps /* the line is up and we want to do rts/cts flow control */
611 1.14 chopps if (ISCTS(stat)) {
612 1.14 chopps tp->t_state &= ~TS_TTSTOP;
613 1.14 chopps ttstart(tp);
614 1.14 chopps /* cause tbe-int if we were stuck there */
615 1.14 chopps custom.intreq = INTF_SETCLR | INTF_TBE;
616 1.14 chopps } else
617 1.14 chopps tp->t_state |= TS_TTSTOP;
618 1.5 mw #else
619 1.14 chopps /* do this on hardware level, not with tty driver */
620 1.14 chopps if (ISCTS(stat)) {
621 1.14 chopps tp->t_state &= ~TS_TTSTOP;
622 1.14 chopps /* cause TBE interrupt */
623 1.14 chopps custom.intreq = INTF_SETCLR | INTF_TBE;
624 1.14 chopps }
625 1.14 chopps #endif
626 1.5 mw }
627 1.1 mw }
628 1.1 mw
629 1.5 mw int
630 1.8 chopps serioctl(dev, cmd, data, flag, p)
631 1.24 chopps dev_t dev;
632 1.24 chopps u_long cmd;
633 1.8 chopps caddr_t data;
634 1.24 chopps int flag;
635 1.8 chopps struct proc *p;
636 1.1 mw {
637 1.14 chopps register struct tty *tp;
638 1.14 chopps register int unit = SERUNIT(dev);
639 1.14 chopps register int error;
640 1.14 chopps
641 1.14 chopps tp = ser_tty[unit];
642 1.14 chopps if (!tp)
643 1.14 chopps return ENXIO;
644 1.14 chopps
645 1.14 chopps error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
646 1.14 chopps if (error >= 0)
647 1.14 chopps return(error);
648 1.14 chopps
649 1.14 chopps error = ttioctl(tp, cmd, data, flag, p);
650 1.14 chopps if (error >= 0)
651 1.14 chopps return(error);
652 1.14 chopps
653 1.14 chopps switch (cmd) {
654 1.14 chopps case TIOCSBRK:
655 1.14 chopps custom.adkcon = ADKCONF_SETCLR | ADKCONF_UARTBRK;
656 1.14 chopps break;
657 1.14 chopps
658 1.14 chopps case TIOCCBRK:
659 1.14 chopps custom.adkcon = ADKCONF_UARTBRK;
660 1.14 chopps break;
661 1.14 chopps
662 1.14 chopps case TIOCSDTR:
663 1.14 chopps (void) sermctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIS);
664 1.14 chopps break;
665 1.14 chopps
666 1.14 chopps case TIOCCDTR:
667 1.14 chopps (void) sermctl(dev, TIOCM_DTR | TIOCM_RTS, DMBIC);
668 1.14 chopps break;
669 1.14 chopps
670 1.14 chopps case TIOCMSET:
671 1.14 chopps (void) sermctl(dev, *(int *) data, DMSET);
672 1.14 chopps break;
673 1.14 chopps
674 1.14 chopps case TIOCMBIS:
675 1.14 chopps (void) sermctl(dev, *(int *) data, DMBIS);
676 1.14 chopps break;
677 1.14 chopps
678 1.14 chopps case TIOCMBIC:
679 1.14 chopps (void) sermctl(dev, *(int *) data, DMBIC);
680 1.14 chopps break;
681 1.14 chopps
682 1.14 chopps case TIOCMGET:
683 1.14 chopps *(int *)data = sermctl(dev, 0, DMGET);
684 1.14 chopps break;
685 1.14 chopps case TIOCGFLAGS:
686 1.14 chopps *(int *)data = SWFLAGS(dev);
687 1.14 chopps break;
688 1.14 chopps case TIOCSFLAGS:
689 1.14 chopps error = suser(p->p_ucred, &p->p_acflag);
690 1.14 chopps if (error != 0)
691 1.14 chopps return(EPERM);
692 1.14 chopps
693 1.14 chopps serswflags = *(int *)data;
694 1.14 chopps serswflags &= /* only allow valid flags */
695 1.14 chopps (TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL | TIOCFLAG_CRTSCTS);
696 1.14 chopps break;
697 1.14 chopps default:
698 1.14 chopps return(ENOTTY);
699 1.14 chopps }
700 1.1 mw
701 1.14 chopps return(0);
702 1.1 mw }
703 1.1 mw
704 1.5 mw int
705 1.1 mw serparam(tp, t)
706 1.14 chopps struct tty *tp;
707 1.14 chopps struct termios *t;
708 1.1 mw {
709 1.34 veego int cflag, unit, ospeed = 0;
710 1.14 chopps
711 1.14 chopps cflag = t->c_cflag;
712 1.14 chopps unit = SERUNIT(tp->t_dev);
713 1.14 chopps
714 1.32 is if (t->c_ospeed > 0) {
715 1.32 is if (t->c_ospeed < 110)
716 1.32 is return(EINVAL);
717 1.32 is ospeed = SERBRD(t->c_ospeed);
718 1.32 is }
719 1.32 is
720 1.32 is if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
721 1.14 chopps return(EINVAL);
722 1.14 chopps
723 1.14 chopps /*
724 1.14 chopps * copy to tty
725 1.14 chopps */
726 1.14 chopps tp->t_ispeed = t->c_ispeed;
727 1.14 chopps tp->t_ospeed = t->c_ospeed;
728 1.14 chopps tp->t_cflag = cflag;
729 1.14 chopps
730 1.14 chopps /*
731 1.14 chopps * enable interrupts
732 1.14 chopps */
733 1.14 chopps custom.intena = INTF_SETCLR | INTF_RBF | INTF_TBE;
734 1.14 chopps last_ciab_pra = ciab.pra;
735 1.14 chopps
736 1.32 is if (t->c_ospeed == 0)
737 1.14 chopps (void)sermctl(tp->t_dev, 0, DMSET); /* hang up line */
738 1.14 chopps else {
739 1.14 chopps /*
740 1.14 chopps * (re)enable DTR
741 1.14 chopps * and set baud rate. (8 bit mode)
742 1.14 chopps */
743 1.14 chopps (void)sermctl(tp->t_dev, TIOCM_DTR | TIOCM_RTS, DMSET);
744 1.14 chopps custom.serper = (0 << 15) | ospeed;
745 1.14 chopps }
746 1.14 chopps return(0);
747 1.1 mw }
748 1.3 mw
749 1.22 chopps int serhwiflow(tp, flag)
750 1.22 chopps struct tty *tp;
751 1.22 chopps int flag;
752 1.22 chopps {
753 1.22 chopps #if 0
754 1.38 christos printf ("serhwiflow %d\n", flag);
755 1.22 chopps #endif
756 1.22 chopps if (flag)
757 1.22 chopps CLRRTS(ciab.pra);
758 1.22 chopps else
759 1.22 chopps SETRTS(ciab.pra);
760 1.22 chopps return 1;
761 1.22 chopps }
762 1.3 mw
763 1.3 mw static void
764 1.14 chopps ser_putchar(tp, c)
765 1.14 chopps struct tty *tp;
766 1.14 chopps u_short c;
767 1.14 chopps {
768 1.14 chopps if ((tp->t_cflag & CSIZE) == CS7 || (tp->t_cflag & PARENB))
769 1.14 chopps c &= 0x7f;
770 1.14 chopps
771 1.14 chopps /*
772 1.14 chopps * handle parity if necessary
773 1.14 chopps */
774 1.14 chopps if (tp->t_cflag & PARENB) {
775 1.14 chopps if (even_parity[c])
776 1.14 chopps c |= 0x80;
777 1.14 chopps if (tp->t_cflag & PARODD)
778 1.14 chopps c ^= 0x80;
779 1.14 chopps }
780 1.14 chopps /*
781 1.14 chopps * add stop bit(s)
782 1.14 chopps */
783 1.14 chopps if (tp->t_cflag & CSTOPB)
784 1.14 chopps c |= 0x300;
785 1.14 chopps else
786 1.14 chopps c |= 0x100;
787 1.14 chopps
788 1.14 chopps custom.serdat = c;
789 1.3 mw }
790 1.3 mw
791 1.3 mw
792 1.3 mw static u_char ser_outbuf[SEROBUF_SIZE];
793 1.14 chopps static u_char *sob_ptr = ser_outbuf, *sob_end = ser_outbuf;
794 1.14 chopps
795 1.3 mw void
796 1.14 chopps ser_outintr()
797 1.3 mw {
798 1.14 chopps struct tty *tp = ser_tty[0];
799 1.14 chopps int s;
800 1.14 chopps
801 1.14 chopps tp = ser_tty[0];
802 1.14 chopps s = spltty();
803 1.14 chopps
804 1.14 chopps if (tp == 0)
805 1.14 chopps goto out;
806 1.14 chopps
807 1.14 chopps if ((custom.intreqr & INTF_TBE) == 0)
808 1.14 chopps goto out;
809 1.14 chopps
810 1.14 chopps /*
811 1.14 chopps * clear interrupt
812 1.14 chopps */
813 1.14 chopps custom.intreq = INTF_TBE;
814 1.14 chopps
815 1.14 chopps if (sob_ptr == sob_end) {
816 1.14 chopps tp->t_state &= ~(TS_BUSY | TS_FLUSH);
817 1.14 chopps if (tp->t_line)
818 1.14 chopps (*linesw[tp->t_line].l_start)(tp);
819 1.14 chopps else
820 1.14 chopps serstart(tp);
821 1.14 chopps goto out;
822 1.14 chopps }
823 1.14 chopps
824 1.14 chopps /*
825 1.14 chopps * Do hardware flow control here. if the CTS line goes down, don't
826 1.14 chopps * transmit anything. That way, we'll be restarted by the periodic
827 1.14 chopps * interrupt when CTS comes back up.
828 1.14 chopps */
829 1.14 chopps if (ISCTS(ciab.pra))
830 1.14 chopps ser_putchar(tp, *sob_ptr++);
831 1.22 chopps else
832 1.22 chopps CLRCTS(last_ciab_pra); /* Remember that CTS is off */
833 1.5 mw out:
834 1.14 chopps splx(s);
835 1.3 mw }
836 1.14 chopps
837 1.31 veego void
838 1.1 mw serstart(tp)
839 1.14 chopps struct tty *tp;
840 1.1 mw {
841 1.14 chopps int cc, s, unit, hiwat;
842 1.14 chopps
843 1.14 chopps hiwat = 0;
844 1.14 chopps
845 1.14 chopps if ((tp->t_state & TS_ISOPEN) == 0)
846 1.14 chopps return;
847 1.14 chopps
848 1.14 chopps unit = SERUNIT(tp->t_dev);
849 1.1 mw
850 1.14 chopps s = spltty();
851 1.14 chopps if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP))
852 1.14 chopps goto out;
853 1.14 chopps
854 1.14 chopps cc = tp->t_outq.c_cc;
855 1.14 chopps if (cc <= tp->t_lowat) {
856 1.14 chopps if (tp->t_state & TS_ASLEEP) {
857 1.14 chopps tp->t_state &= ~TS_ASLEEP;
858 1.14 chopps wakeup((caddr_t) & tp->t_outq);
859 1.14 chopps }
860 1.14 chopps selwakeup(&tp->t_wsel);
861 1.14 chopps }
862 1.14 chopps if (cc == 0 || (tp->t_state & TS_BUSY))
863 1.14 chopps goto out;
864 1.14 chopps
865 1.14 chopps /*
866 1.14 chopps * We only do bulk transfers if using CTSRTS flow control, not for
867 1.14 chopps * (probably sloooow) ixon/ixoff devices.
868 1.14 chopps */
869 1.14 chopps if ((tp->t_cflag & CRTSCTS) == 0)
870 1.14 chopps cc = 1;
871 1.14 chopps
872 1.14 chopps /*
873 1.14 chopps * Limit the amount of output we do in one burst
874 1.14 chopps * to prevent hogging the CPU.
875 1.14 chopps */
876 1.14 chopps if (cc > SEROBUF_SIZE) {
877 1.14 chopps hiwat++;
878 1.14 chopps cc = SEROBUF_SIZE;
879 1.14 chopps }
880 1.14 chopps cc = q_to_b(&tp->t_outq, ser_outbuf, cc);
881 1.14 chopps if (cc > 0) {
882 1.14 chopps tp->t_state |= TS_BUSY;
883 1.14 chopps
884 1.14 chopps sob_ptr = ser_outbuf;
885 1.14 chopps sob_end = ser_outbuf + cc;
886 1.14 chopps
887 1.14 chopps /*
888 1.14 chopps * Get first character out, then have TBE-interrupts blow out
889 1.14 chopps * further characters, until buffer is empty, and TS_BUSY gets
890 1.14 chopps * cleared.
891 1.14 chopps */
892 1.14 chopps ser_putchar(tp, *sob_ptr++);
893 1.14 chopps }
894 1.14 chopps out:
895 1.14 chopps splx(s);
896 1.1 mw }
897 1.14 chopps
898 1.1 mw /*
899 1.1 mw * Stop output on a line.
900 1.1 mw */
901 1.1 mw /*ARGSUSED*/
902 1.36 mycroft void
903 1.1 mw serstop(tp, flag)
904 1.14 chopps struct tty *tp;
905 1.31 veego int flag;
906 1.1 mw {
907 1.14 chopps int s;
908 1.1 mw
909 1.14 chopps s = spltty();
910 1.14 chopps if (tp->t_state & TS_BUSY) {
911 1.14 chopps if ((tp->t_state & TS_TTSTOP) == 0)
912 1.14 chopps tp->t_state |= TS_FLUSH;
913 1.14 chopps }
914 1.14 chopps splx(s);
915 1.1 mw }
916 1.14 chopps
917 1.5 mw int
918 1.1 mw sermctl(dev, bits, how)
919 1.14 chopps dev_t dev;
920 1.14 chopps int bits, how;
921 1.1 mw {
922 1.14 chopps int unit, s;
923 1.31 veego u_char ub = 0;
924 1.14 chopps
925 1.14 chopps unit = SERUNIT(dev);
926 1.14 chopps
927 1.14 chopps /*
928 1.14 chopps * convert TIOCM* mask into CIA mask
929 1.14 chopps * which is active low
930 1.14 chopps */
931 1.14 chopps if (how != DMGET) {
932 1.14 chopps ub = 0;
933 1.14 chopps if (bits & TIOCM_DTR)
934 1.14 chopps ub |= CIAB_PRA_DTR;
935 1.14 chopps if (bits & TIOCM_RTS)
936 1.14 chopps ub |= CIAB_PRA_RTS;
937 1.14 chopps if (bits & TIOCM_CTS)
938 1.14 chopps ub |= CIAB_PRA_CTS;
939 1.14 chopps if (bits & TIOCM_CD)
940 1.14 chopps ub |= CIAB_PRA_CD;
941 1.14 chopps if (bits & TIOCM_RI)
942 1.14 chopps ub |= CIAB_PRA_SEL; /* collision with /dev/par ! */
943 1.14 chopps if (bits & TIOCM_DSR)
944 1.14 chopps ub |= CIAB_PRA_DSR;
945 1.14 chopps }
946 1.14 chopps s = spltty();
947 1.14 chopps switch (how) {
948 1.14 chopps case DMSET:
949 1.14 chopps /* invert and set */
950 1.14 chopps ciab.pra = ~ub;
951 1.14 chopps break;
952 1.14 chopps
953 1.14 chopps case DMBIC:
954 1.14 chopps ciab.pra |= ub;
955 1.14 chopps ub = ~ciab.pra;
956 1.14 chopps break;
957 1.14 chopps
958 1.14 chopps case DMBIS:
959 1.14 chopps ciab.pra &= ~ub;
960 1.14 chopps ub = ~ciab.pra;
961 1.14 chopps break;
962 1.14 chopps
963 1.14 chopps case DMGET:
964 1.14 chopps ub = ~ciab.pra;
965 1.14 chopps break;
966 1.14 chopps }
967 1.14 chopps (void)splx(s);
968 1.14 chopps
969 1.14 chopps bits = 0;
970 1.14 chopps if (ub & CIAB_PRA_DTR)
971 1.14 chopps bits |= TIOCM_DTR;
972 1.14 chopps if (ub & CIAB_PRA_RTS)
973 1.14 chopps bits |= TIOCM_RTS;
974 1.14 chopps if (ub & CIAB_PRA_CTS)
975 1.14 chopps bits |= TIOCM_CTS;
976 1.14 chopps if (ub & CIAB_PRA_CD)
977 1.14 chopps bits |= TIOCM_CD;
978 1.14 chopps if (ub & CIAB_PRA_SEL)
979 1.14 chopps bits |= TIOCM_RI;
980 1.14 chopps if (ub & CIAB_PRA_DSR)
981 1.14 chopps bits |= TIOCM_DSR;
982 1.14 chopps
983 1.14 chopps return(bits);
984 1.1 mw }
985 1.1 mw
986 1.1 mw /*
987 1.1 mw * Following are all routines needed for SER to act as console
988 1.1 mw */
989 1.31 veego void
990 1.1 mw sercnprobe(cp)
991 1.1 mw struct consdev *cp;
992 1.1 mw {
993 1.14 chopps int unit = CONUNIT;
994 1.14 chopps
995 1.14 chopps /* locate the major number */
996 1.14 chopps for (sermajor = 0; sermajor < nchrdev; sermajor++)
997 1.14 chopps if (cdevsw[sermajor].d_open == (void *)seropen)
998 1.14 chopps break;
999 1.14 chopps
1000 1.14 chopps
1001 1.14 chopps unit = CONUNIT; /* XXX: ick */
1002 1.14 chopps
1003 1.14 chopps /*
1004 1.14 chopps * initialize required fields
1005 1.14 chopps */
1006 1.14 chopps cp->cn_dev = makedev(sermajor, unit);
1007 1.14 chopps if (serconsole == unit)
1008 1.14 chopps cp->cn_pri = CN_REMOTE;
1009 1.14 chopps else
1010 1.14 chopps cp->cn_pri = CN_NORMAL;
1011 1.1 mw #ifdef KGDB
1012 1.14 chopps if (major(kgdb_dev) == 1) /* XXX */
1013 1.14 chopps kgdb_dev = makedev(sermajor, minor(kgdb_dev));
1014 1.1 mw #endif
1015 1.1 mw }
1016 1.1 mw
1017 1.31 veego void
1018 1.1 mw sercninit(cp)
1019 1.1 mw struct consdev *cp;
1020 1.1 mw {
1021 1.14 chopps int unit;
1022 1.1 mw
1023 1.14 chopps unit = SERUNIT(cp->cn_dev);
1024 1.14 chopps
1025 1.14 chopps serinit(unit, serdefaultrate);
1026 1.14 chopps serconsole = unit;
1027 1.14 chopps serconsinit = 1;
1028 1.1 mw }
1029 1.1 mw
1030 1.31 veego void
1031 1.1 mw serinit(unit, rate)
1032 1.1 mw int unit, rate;
1033 1.1 mw {
1034 1.14 chopps int s;
1035 1.1 mw
1036 1.26 chopps s = splser();
1037 1.14 chopps /*
1038 1.14 chopps * might want to fiddle with the CIA later ???
1039 1.14 chopps */
1040 1.32 is custom.serper = (rate>=110 ? SERBRD(rate) : 0);
1041 1.14 chopps splx(s);
1042 1.1 mw }
1043 1.1 mw
1044 1.31 veego int
1045 1.1 mw sercngetc(dev)
1046 1.31 veego dev_t dev;
1047 1.1 mw {
1048 1.14 chopps u_short stat;
1049 1.14 chopps int c, s;
1050 1.1 mw
1051 1.26 chopps s = splser();
1052 1.14 chopps /*
1053 1.14 chopps * poll
1054 1.14 chopps */
1055 1.14 chopps while (((stat = custom.serdatr & 0xffff) & SERDATRF_RBF) == 0)
1056 1.14 chopps ;
1057 1.14 chopps c = stat & 0xff;
1058 1.14 chopps /*
1059 1.14 chopps * clear interrupt
1060 1.14 chopps */
1061 1.14 chopps custom.intreq = INTF_RBF;
1062 1.14 chopps splx(s);
1063 1.14 chopps return(c);
1064 1.1 mw }
1065 1.1 mw
1066 1.1 mw /*
1067 1.1 mw * Console kernel output character routine.
1068 1.1 mw */
1069 1.31 veego void
1070 1.1 mw sercnputc(dev, c)
1071 1.14 chopps dev_t dev;
1072 1.14 chopps int c;
1073 1.1 mw {
1074 1.14 chopps register int timo;
1075 1.14 chopps int s;
1076 1.14 chopps
1077 1.14 chopps s = splhigh();
1078 1.1 mw
1079 1.14 chopps if (serconsinit == 0) {
1080 1.14 chopps (void)serinit(SERUNIT(dev), serdefaultrate);
1081 1.14 chopps serconsinit = 1;
1082 1.14 chopps }
1083 1.14 chopps
1084 1.14 chopps /*
1085 1.14 chopps * wait for any pending transmission to finish
1086 1.14 chopps */
1087 1.14 chopps timo = 50000;
1088 1.14 chopps while (!(custom.serdatr & SERDATRF_TBE) && --timo);
1089 1.14 chopps
1090 1.14 chopps /*
1091 1.14 chopps * transmit char.
1092 1.14 chopps */
1093 1.14 chopps custom.serdat = (c & 0xff) | 0x100;
1094 1.14 chopps
1095 1.14 chopps /*
1096 1.14 chopps * wait for this transmission to complete
1097 1.14 chopps */
1098 1.14 chopps timo = 1500000;
1099 1.14 chopps while (!(custom.serdatr & SERDATRF_TBE) && --timo)
1100 1.14 chopps ;
1101 1.14 chopps
1102 1.14 chopps /*
1103 1.14 chopps * Wait for the device (my vt100..) to process the data, since we
1104 1.14 chopps * don't do flow-control with cnputc
1105 1.14 chopps */
1106 1.14 chopps for (timo = 0; timo < 30000; timo++)
1107 1.14 chopps ;
1108 1.14 chopps
1109 1.14 chopps /*
1110 1.14 chopps * clear any interrupts generated by this transmission
1111 1.14 chopps */
1112 1.14 chopps custom.intreq = INTF_TBE;
1113 1.14 chopps splx(s);
1114 1.25 chopps }
1115 1.25 chopps
1116 1.25 chopps void
1117 1.25 chopps sercnpollc(dev, on)
1118 1.25 chopps dev_t dev;
1119 1.25 chopps int on;
1120 1.25 chopps {
1121 1.1 mw }
1122 1.1 mw #endif
1123