1 /* $NetBSD: biconsdev.c,v 1.19 2007/10/18 18:55:00 joerg Exp $ */
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
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
38 * The Regents of the University of California. All rights reserved.
40 * This code is derived from software contributed to Berkeley by
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
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
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>
75 #include <sys/systm.h>
77 #include <sys/ioctl.h>
80 #include <sys/kauth.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
,
105 biconsdevattach(int n
)
107 struct tty
*tp
= &biconsdev_tty
[0];
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
;
134 biconsdev_output(struct tty
*tp
)
140 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
)) {
144 tp
->t_state
|= TS_BUSY
;
146 n
= q_to_b(&tp
->t_outq
, buf
, sizeof(buf
));
150 tp
->t_state
&= ~TS_BUSY
;
151 /* Come back if there's more to do */
153 tp
->t_state
|= TS_TIMEOUT
;
154 callout_schedule(&tp
->t_rstrt_ch
, 1);
161 biconsdevopen(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
163 struct tty
*tp
= &biconsdev_tty
[0];
166 if (kauth_authorize_device_tty(l
->l_cred
, KAUTH_DEVICE_TTY_OPEN
, tp
))
169 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
171 * Leave baud rate alone!
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
);
183 status
= (*tp
->t_linesw
->l_open
)(dev
, tp
);
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
);
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
));
228 biconsdevtty(dev_t dev
)
230 struct tty
*tp
= &biconsdev_tty
[0];
236 biconsdevioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
238 struct tty
*tp
= &biconsdev_tty
[0];
241 if ((error
= tp
->t_linesw
->l_ioctl(tp
, cmd
, data
, flag
, l
)) !=
244 return (ttioctl(tp
, cmd
, data
, flag
, l
));