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