1 /* $NetBSD: biconsdev.c,v 1.1 2001/02/09 19:43:23 uch 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 "biconsdev.h" 74 #if NBICONSDEV > 0 75 76 #include <sys/param.h> 77 #include <sys/proc.h> 78 #include <sys/systm.h> 79 #include <sys/buf.h> 80 #include <sys/ioctl.h> 81 #include <sys/tty.h> 82 #include <sys/conf.h> 83 84 #include <dev/cons.h> 85 #include <dev/hpc/bicons.h> 86 #include <dev/hpc/biconsvar.h> 87 88 struct tty biconsdev_tty[NBICONSDEV]; 89 void biconsdevattach(int); 90 static void biconsdev_output(struct tty *); 91 92 cdev_decl(biconsdev); 93 94 void 95 biconsdevattach(int n) 96 { 97 struct tty *tp = &biconsdev_tty[0]; 98 int maj; 99 100 /* locate the major number */ 101 for (maj = 0; maj < nchrdev; maj++) 102 if (cdevsw[maj].d_open == biconsdevopen) 103 break; 104 105 /* Set up the tty queues now... */ 106 clalloc(&tp->t_rawq, 1024, 1); 107 clalloc(&tp->t_canq, 1024, 1); 108 /* output queue doesn't need quoting */ 109 clalloc(&tp->t_outq, 1024, 0); 110 /* Set default line discipline. */ 111 tp->t_linesw = linesw[0]; 112 113 114 tp->t_dev = makedev(maj, 0); 115 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; 116 tp->t_param = (int (*)(struct tty *, struct termios *))nullop; 117 tp->t_winsize.ws_row = bicons_height; 118 tp->t_winsize.ws_col = bicons_width; 119 tp->t_winsize.ws_xpixel = bicons_xpixel; 120 tp->t_winsize.ws_ypixel = bicons_ypixel; 121 tp->t_oproc = biconsdev_output; 122 } 123 124 125 static void 126 biconsdev_output(struct tty *tp) 127 { 128 int s, n; 129 char buf[OBUFSIZ]; 130 131 s = spltty(); 132 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) { 133 splx(s); 134 return; 135 } 136 tp->t_state |= TS_BUSY; 137 splx(s); 138 n = q_to_b(&tp->t_outq, buf, sizeof(buf)); 139 bicons_putn(buf, n); 140 141 s = spltty(); 142 tp->t_state &= ~TS_BUSY; 143 /* Come back if there's more to do */ 144 if (tp->t_outq.c_cc) { 145 tp->t_state |= TS_TIMEOUT; 146 callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, tp); 147 } 148 if (tp->t_outq.c_cc <= tp->t_lowat) { 149 if (tp->t_state&TS_ASLEEP) { 150 tp->t_state &= ~TS_ASLEEP; 151 wakeup((caddr_t)&tp->t_outq); 152 } 153 selwakeup(&tp->t_wsel); 154 } 155 splx(s); 156 } 157 158 159 int 160 biconsdevopen(dev_t dev, int flag, int mode, struct proc *p) 161 { 162 struct tty *tp = &biconsdev_tty[0]; 163 int status; 164 165 if ((tp->t_state & TS_ISOPEN) == 0) { 166 /* 167 * Leave baud rate alone! 168 */ 169 ttychars(tp); 170 tp->t_iflag = TTYDEF_IFLAG; 171 tp->t_oflag = TTYDEF_OFLAG; 172 tp->t_lflag = TTYDEF_LFLAG; 173 tp->t_cflag = TTYDEF_CFLAG; 174 tp->t_state = TS_ISOPEN | TS_CARR_ON; 175 (void)(*tp->t_param)(tp, &tp->t_termios); 176 ttsetwater(tp); 177 } else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) 178 return (EBUSY); 179 180 status = (*tp->t_linesw->l_open)(dev, tp); 181 return status; 182 } 183 184 185 int 186 biconsdevclose(dev_t dev, int flag, int mode, struct proc *p) 187 { 188 struct tty *tp = &biconsdev_tty[0]; 189 190 (*tp->t_linesw->l_close)(tp, flag); 191 ttyclose(tp); 192 193 return (0); 194 } 195 196 197 int 198 biconsdevread(dev_t dev, struct uio *uio, int flag) 199 { 200 struct tty *tp = &biconsdev_tty[0]; 201 202 return ((*tp->t_linesw->l_read)(tp, uio, flag)); 203 } 204 205 206 int 207 biconsdevwrite(dev_t dev, struct uio *uio, int flag) 208 { 209 struct tty *tp = &biconsdev_tty[0]; 210 211 return ((*tp->t_linesw->l_write)(tp, uio, flag)); 212 } 213 214 215 struct tty * 216 biconsdevtty(dev_t dev) 217 { 218 struct tty *tp = &biconsdev_tty[0]; 219 220 return (tp); 221 } 222 223 int 224 biconsdevioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) 225 { 226 struct tty *tp = &biconsdev_tty[0]; 227 int error; 228 229 if ((error = tp->t_linesw->l_ioctl(tp, cmd, data, flag, p)) >= 0) 230 return (error); 231 if ((error = ttioctl(tp, cmd, data, flag, p)) >= 0) 232 return (error); 233 return (ENOTTY); 234 } 235 236 void 237 biconsdevstop(struct tty *tp, int rw) 238 { 239 240 } 241 242 #endif /* NBICONSDEV > 0 */ 243