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