Home | History | Annotate | Line # | Download | only in hpc
biconsdev.c revision 1.7
      1  1.7  jdolecek /*	$NetBSD: biconsdev.c,v 1.7 2002/10/23 09:13:11 jdolecek Exp $	*/
      2  1.1       uch 
      3  1.1       uch /*-
      4  1.1       uch  * Copyright (c) 1999-2001
      5  1.1       uch  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6  1.1       uch  *
      7  1.1       uch  * Redistribution and use in source and binary forms, with or without
      8  1.1       uch  * modification, are permitted provided that the following conditions
      9  1.1       uch  * are met:
     10  1.1       uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1       uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1       uch  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1       uch  *    notice, this list of conditions and the following disclaimer in the
     14  1.1       uch  *    documentation and/or other materials provided with the distribution.
     15  1.1       uch  * 3. All advertising materials mentioning features or use of this software
     16  1.1       uch  *    must display the following acknowledgement:
     17  1.1       uch  *	This product includes software developed by the PocketBSD project
     18  1.1       uch  *	and its contributors.
     19  1.1       uch  * 4. Neither the name of the project nor the names of its contributors
     20  1.1       uch  *    may be used to endorse or promote products derived from this software
     21  1.1       uch  *    without specific prior written permission.
     22  1.1       uch  *
     23  1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1       uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1       uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1       uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1       uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1       uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1       uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1       uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1       uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1       uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1       uch  * SUCH DAMAGE.
     34  1.1       uch  *
     35  1.1       uch  */
     36  1.1       uch /*
     37  1.1       uch  * Copyright (c) 1995
     38  1.1       uch  *	The Regents of the University of California.  All rights reserved.
     39  1.1       uch  *
     40  1.1       uch  * This code is derived from software contributed to Berkeley by
     41  1.1       uch  * Ted Lemon.
     42  1.1       uch  *
     43  1.1       uch  * Redistribution and use in source and binary forms, with or without
     44  1.1       uch  * modification, are permitted provided that the following conditions
     45  1.1       uch  * are met:
     46  1.1       uch  * 1. Redistributions of source code must retain the above copyright
     47  1.1       uch  *    notice, this list of conditions and the following disclaimer.
     48  1.1       uch  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1       uch  *    notice, this list of conditions and the following disclaimer in the
     50  1.1       uch  *    documentation and/or other materials provided with the distribution.
     51  1.1       uch  * 3. All advertising materials mentioning features or use of this software
     52  1.1       uch  *    must display the following acknowledgement:
     53  1.1       uch  *	This product includes software developed by the University of
     54  1.1       uch  *	California, Berkeley and its contributors.
     55  1.1       uch  * 4. Neither the name of the University nor the names of its contributors
     56  1.1       uch  *    may be used to endorse or promote products derived from this software
     57  1.1       uch  *    without specific prior written permission.
     58  1.1       uch  *
     59  1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.1       uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.1       uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.1       uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.1       uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.1       uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.1       uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.1       uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.1       uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.1       uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.1       uch  * SUCH DAMAGE.
     70  1.1       uch  *
     71  1.1       uch  */
     72  1.3     lukem 
     73  1.3     lukem #include <sys/cdefs.h>
     74  1.7  jdolecek __KERNEL_RCSID(0, "$NetBSD: biconsdev.c,v 1.7 2002/10/23 09:13:11 jdolecek Exp $");
     75  1.1       uch 
     76  1.1       uch #include "biconsdev.h"
     77  1.1       uch #include <sys/param.h>
     78  1.1       uch #include <sys/proc.h>
     79  1.1       uch #include <sys/systm.h>
     80  1.1       uch #include <sys/buf.h>
     81  1.1       uch #include <sys/ioctl.h>
     82  1.1       uch #include <sys/tty.h>
     83  1.1       uch #include <sys/conf.h>
     84  1.1       uch 
     85  1.1       uch #include <dev/cons.h>
     86  1.1       uch #include <dev/hpc/bicons.h>
     87  1.1       uch #include <dev/hpc/biconsvar.h>
     88  1.1       uch 
     89  1.1       uch struct tty biconsdev_tty[NBICONSDEV];
     90  1.1       uch void	biconsdevattach(int);
     91  1.1       uch static	void biconsdev_output(struct tty *);
     92  1.1       uch 
     93  1.6   gehenna dev_type_open(biconsdevopen);
     94  1.6   gehenna dev_type_close(biconsdevclose);
     95  1.6   gehenna dev_type_read(biconsdevread);
     96  1.6   gehenna dev_type_write(biconsdevwrite);
     97  1.6   gehenna dev_type_ioctl(biconsdevioctl);
     98  1.6   gehenna dev_type_tty(biconsdevtty);
     99  1.6   gehenna dev_type_poll(biconsdevpoll);
    100  1.6   gehenna 
    101  1.6   gehenna const struct cdevsw biconsdev_cdevsw = {
    102  1.6   gehenna 	biconsdevopen, biconsdevclose, biconsdevread, biconsdevwrite,
    103  1.7  jdolecek 	biconsdevioctl, nostop, biconsdevtty, biconsdevpoll, nommap,
    104  1.7  jdolecek 	ttykqfilter, D_TTY
    105  1.6   gehenna };
    106  1.1       uch 
    107  1.1       uch void
    108  1.1       uch biconsdevattach(int n)
    109  1.1       uch {
    110  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    111  1.1       uch 	int maj;
    112  1.4       uch 
    113  1.1       uch 	/* locate the major number */
    114  1.6   gehenna 	maj = cdevsw_lookup_major(&biconsdev_cdevsw);
    115  1.1       uch 
    116  1.1       uch 	/* Set up the tty queues now... */
    117  1.1       uch 	clalloc(&tp->t_rawq, 1024, 1);
    118  1.1       uch 	clalloc(&tp->t_canq, 1024, 1);
    119  1.1       uch 	/* output queue doesn't need quoting */
    120  1.1       uch 	clalloc(&tp->t_outq, 1024, 0);
    121  1.1       uch 	/* Set default line discipline. */
    122  1.1       uch 	tp->t_linesw = linesw[0];
    123  1.1       uch 
    124  1.1       uch 
    125  1.1       uch 	tp->t_dev = makedev(maj, 0);
    126  1.1       uch 	tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    127  1.1       uch 	tp->t_param = (int (*)(struct tty *, struct termios *))nullop;
    128  1.1       uch 	tp->t_winsize.ws_row = bicons_height;
    129  1.1       uch 	tp->t_winsize.ws_col = bicons_width;
    130  1.1       uch 	tp->t_winsize.ws_xpixel = bicons_xpixel;
    131  1.1       uch 	tp->t_winsize.ws_ypixel = bicons_ypixel;
    132  1.1       uch 	tp->t_oproc = biconsdev_output;
    133  1.1       uch }
    134  1.1       uch 
    135  1.1       uch 
    136  1.1       uch static void
    137  1.1       uch biconsdev_output(struct tty *tp)
    138  1.1       uch {
    139  1.1       uch 	int s, n;
    140  1.1       uch 	char buf[OBUFSIZ];
    141  1.1       uch 
    142  1.1       uch 	s = spltty();
    143  1.1       uch 	if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
    144  1.1       uch 		splx(s);
    145  1.1       uch 		return;
    146  1.1       uch 	}
    147  1.1       uch 	tp->t_state |= TS_BUSY;
    148  1.1       uch 	splx(s);
    149  1.1       uch 	n = q_to_b(&tp->t_outq, buf, sizeof(buf));
    150  1.1       uch 	bicons_putn(buf, n);
    151  1.1       uch 
    152  1.1       uch 	s = spltty();
    153  1.1       uch 	tp->t_state &= ~TS_BUSY;
    154  1.1       uch 	/* Come back if there's more to do */
    155  1.1       uch 	if (tp->t_outq.c_cc) {
    156  1.1       uch 		tp->t_state |= TS_TIMEOUT;
    157  1.1       uch 		callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp);
    158  1.1       uch 	}
    159  1.1       uch 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    160  1.1       uch 		if (tp->t_state&TS_ASLEEP) {
    161  1.1       uch 			tp->t_state &= ~TS_ASLEEP;
    162  1.1       uch 			wakeup((caddr_t)&tp->t_outq);
    163  1.1       uch 		}
    164  1.1       uch 		selwakeup(&tp->t_wsel);
    165  1.1       uch 	}
    166  1.1       uch 	splx(s);
    167  1.1       uch }
    168  1.1       uch 
    169  1.1       uch 
    170  1.1       uch int
    171  1.1       uch biconsdevopen(dev_t dev, int flag, int mode, struct proc *p)
    172  1.1       uch {
    173  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    174  1.1       uch 	int status;
    175  1.1       uch 
    176  1.1       uch 	if ((tp->t_state & TS_ISOPEN) == 0) {
    177  1.1       uch 		/*
    178  1.1       uch 		 * Leave baud rate alone!
    179  1.1       uch 		 */
    180  1.1       uch 		ttychars(tp);
    181  1.1       uch 		tp->t_iflag = TTYDEF_IFLAG;
    182  1.1       uch 		tp->t_oflag = TTYDEF_OFLAG;
    183  1.1       uch 		tp->t_lflag = TTYDEF_LFLAG;
    184  1.1       uch 		tp->t_cflag = TTYDEF_CFLAG;
    185  1.1       uch 		tp->t_state = TS_ISOPEN | TS_CARR_ON;
    186  1.1       uch 		(void)(*tp->t_param)(tp, &tp->t_termios);
    187  1.1       uch 		ttsetwater(tp);
    188  1.1       uch 	} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0)
    189  1.1       uch 		return (EBUSY);
    190  1.1       uch 
    191  1.1       uch 	status = (*tp->t_linesw->l_open)(dev, tp);
    192  1.1       uch 	return status;
    193  1.1       uch }
    194  1.1       uch 
    195  1.1       uch 
    196  1.1       uch int
    197  1.1       uch biconsdevclose(dev_t dev, int flag, int mode, struct proc *p)
    198  1.1       uch {
    199  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    200  1.1       uch 
    201  1.1       uch 	(*tp->t_linesw->l_close)(tp, flag);
    202  1.1       uch 	ttyclose(tp);
    203  1.1       uch 
    204  1.1       uch 	return (0);
    205  1.1       uch }
    206  1.1       uch 
    207  1.1       uch 
    208  1.1       uch int
    209  1.1       uch biconsdevread(dev_t dev, struct uio *uio, int flag)
    210  1.1       uch {
    211  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    212  1.1       uch 
    213  1.1       uch 	return ((*tp->t_linesw->l_read)(tp, uio, flag));
    214  1.1       uch }
    215  1.1       uch 
    216  1.1       uch 
    217  1.1       uch int
    218  1.1       uch biconsdevwrite(dev_t dev, struct uio *uio, int flag)
    219  1.1       uch {
    220  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    221  1.1       uch 
    222  1.1       uch 	return ((*tp->t_linesw->l_write)(tp, uio, flag));
    223  1.2       scw }
    224  1.2       scw 
    225  1.2       scw 
    226  1.2       scw int
    227  1.2       scw biconsdevpoll(dev_t dev, int events, struct proc *p)
    228  1.2       scw {
    229  1.2       scw 	struct tty *tp = &biconsdev_tty[0];
    230  1.4       uch 
    231  1.2       scw 	return ((*tp->t_linesw->l_poll)(tp, events, p));
    232  1.1       uch }
    233  1.1       uch 
    234  1.1       uch 
    235  1.1       uch struct tty *
    236  1.1       uch biconsdevtty(dev_t dev)
    237  1.1       uch {
    238  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    239  1.1       uch 
    240  1.1       uch         return (tp);
    241  1.1       uch }
    242  1.1       uch 
    243  1.1       uch int
    244  1.1       uch biconsdevioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
    245  1.1       uch {
    246  1.1       uch 	struct tty *tp = &biconsdev_tty[0];
    247  1.1       uch 	int error;
    248  1.1       uch 
    249  1.5    atatat 	if ((error = tp->t_linesw->l_ioctl(tp, cmd, data, flag, p)) !=
    250  1.5    atatat 	    EPASSTHROUGH)
    251  1.1       uch 		return (error);
    252  1.5    atatat 	return (ttioctl(tp, cmd, data, flag, p));
    253  1.1       uch }
    254