Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / hpc / biconsdev.c
blobab989f2f90f39e54fd12c000207b1fd8176bdf3f
1 /* $NetBSD: biconsdev.c,v 1.19 2007/10/18 18:55:00 joerg Exp $ */
3 /*-
4 * Copyright (c) 1999-2001
5 * Shin Takemura and PocketBSD Project. All rights reserved.
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.
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.
37 * Copyright (c) 1995
38 * The Regents of the University of California. All rights reserved.
40 * This code is derived from software contributed to Berkeley by
41 * Ted Lemon.
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. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: biconsdev.c,v 1.19 2007/10/18 18:55:00 joerg Exp $");
72 #include "biconsdev.h"
73 #include <sys/param.h>
74 #include <sys/proc.h>
75 #include <sys/systm.h>
76 #include <sys/buf.h>
77 #include <sys/ioctl.h>
78 #include <sys/tty.h>
79 #include <sys/conf.h>
80 #include <sys/kauth.h>
82 #include <dev/cons.h>
83 #include <dev/hpc/bicons.h>
84 #include <dev/hpc/biconsvar.h>
86 struct tty biconsdev_tty[NBICONSDEV];
87 void biconsdevattach(int);
88 static void biconsdev_output(struct tty *);
90 dev_type_open(biconsdevopen);
91 dev_type_close(biconsdevclose);
92 dev_type_read(biconsdevread);
93 dev_type_write(biconsdevwrite);
94 dev_type_ioctl(biconsdevioctl);
95 dev_type_tty(biconsdevtty);
96 dev_type_poll(biconsdevpoll);
98 const struct cdevsw biconsdev_cdevsw = {
99 biconsdevopen, biconsdevclose, biconsdevread, biconsdevwrite,
100 biconsdevioctl, nostop, biconsdevtty, biconsdevpoll, nommap,
101 ttykqfilter, D_TTY
104 void
105 biconsdevattach(int n)
107 struct tty *tp = &biconsdev_tty[0];
108 int maj;
110 /* locate the major number */
111 maj = cdevsw_lookup_major(&biconsdev_cdevsw);
113 /* Set up the tty queues now... */
114 clalloc(&tp->t_rawq, 1024, 1);
115 clalloc(&tp->t_canq, 1024, 1);
116 /* output queue doesn't need quoting */
117 clalloc(&tp->t_outq, 1024, 0);
118 /* Set default line discipline. */
119 tp->t_linesw = ttyldisc_default();
122 tp->t_dev = makedev(maj, 0);
123 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
124 tp->t_param = (int (*)(struct tty *, struct termios *))nullop;
125 tp->t_winsize.ws_row = bicons_height;
126 tp->t_winsize.ws_col = bicons_width;
127 tp->t_winsize.ws_xpixel = bicons_xpixel;
128 tp->t_winsize.ws_ypixel = bicons_ypixel;
129 tp->t_oproc = biconsdev_output;
133 static void
134 biconsdev_output(struct tty *tp)
136 int s, n;
137 char buf[OBUFSIZ];
139 s = spltty();
140 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
141 splx(s);
142 return;
144 tp->t_state |= TS_BUSY;
145 splx(s);
146 n = q_to_b(&tp->t_outq, buf, sizeof(buf));
147 bicons_putn(buf, n);
149 s = spltty();
150 tp->t_state &= ~TS_BUSY;
151 /* Come back if there's more to do */
152 if (ttypull(tp)) {
153 tp->t_state |= TS_TIMEOUT;
154 callout_schedule(&tp->t_rstrt_ch, 1);
156 splx(s);
161 biconsdevopen(dev_t dev, int flag, int mode, struct lwp *l)
163 struct tty *tp = &biconsdev_tty[0];
164 int status;
166 if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
167 return (EBUSY);
169 if ((tp->t_state & TS_ISOPEN) == 0) {
171 * Leave baud rate alone!
173 ttychars(tp);
174 tp->t_iflag = TTYDEF_IFLAG;
175 tp->t_oflag = TTYDEF_OFLAG;
176 tp->t_lflag = TTYDEF_LFLAG;
177 tp->t_cflag = TTYDEF_CFLAG;
178 tp->t_state = TS_ISOPEN | TS_CARR_ON;
179 (void)(*tp->t_param)(tp, &tp->t_termios);
180 ttsetwater(tp);
183 status = (*tp->t_linesw->l_open)(dev, tp);
184 return status;
189 biconsdevclose(dev_t dev, int flag, int mode, struct lwp *l)
191 struct tty *tp = &biconsdev_tty[0];
193 (*tp->t_linesw->l_close)(tp, flag);
194 ttyclose(tp);
196 return (0);
201 biconsdevread(dev_t dev, struct uio *uio, int flag)
203 struct tty *tp = &biconsdev_tty[0];
205 return ((*tp->t_linesw->l_read)(tp, uio, flag));
210 biconsdevwrite(dev_t dev, struct uio *uio, int flag)
212 struct tty *tp = &biconsdev_tty[0];
214 return ((*tp->t_linesw->l_write)(tp, uio, flag));
219 biconsdevpoll(dev_t dev, int events, struct lwp *l)
221 struct tty *tp = &biconsdev_tty[0];
223 return ((*tp->t_linesw->l_poll)(tp, events, l));
227 struct tty *
228 biconsdevtty(dev_t dev)
230 struct tty *tp = &biconsdev_tty[0];
232 return (tp);
236 biconsdevioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
238 struct tty *tp = &biconsdev_tty[0];
239 int error;
241 if ((error = tp->t_linesw->l_ioctl(tp, cmd, data, flag, l)) !=
242 EPASSTHROUGH)
243 return (error);
244 return (ttioctl(tp, cmd, data, flag, l));