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