2 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
5 * Portions of this software were developed under sponsorship from Snow
6 * B.V., the Netherlands.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef _SYS_TTYDEVSW_H_
33 #define _SYS_TTYDEVSW_H_
36 #error "can only be included through <sys/tty.h>"
37 #endif /* !_SYS_TTY_H_ */
40 * Driver routines that are called from the line discipline to adjust
41 * hardware parameters and such.
43 typedef int tsw_open_t(struct tty *tp);
44 typedef void tsw_close_t(struct tty *tp);
45 typedef void tsw_outwakeup_t(struct tty *tp);
46 typedef void tsw_inwakeup_t(struct tty *tp);
47 typedef int tsw_ioctl_t(struct tty *tp, u_long cmd, caddr_t data,
49 typedef int tsw_cioctl_t(struct tty *tp, int unit, u_long cmd, caddr_t data,
51 typedef int tsw_param_t(struct tty *tp, struct termios *t);
52 typedef int tsw_modem_t(struct tty *tp, int sigon, int sigoff);
53 typedef int tsw_mmap_t(struct tty *tp, vm_ooffset_t offset,
54 vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr);
55 typedef void tsw_pktnotify_t(struct tty *tp, char event);
56 typedef void tsw_free_t(void *softc);
57 typedef bool tsw_busy_t(struct tty *tp);
60 unsigned int tsw_flags; /* Default TTY flags. */
62 tsw_open_t *tsw_open; /* Device opening. */
63 tsw_close_t *tsw_close; /* Device closure. */
65 tsw_outwakeup_t *tsw_outwakeup; /* Output available. */
66 tsw_inwakeup_t *tsw_inwakeup; /* Input can be stored again. */
68 tsw_ioctl_t *tsw_ioctl; /* ioctl() hooks. */
69 tsw_cioctl_t *tsw_cioctl; /* ioctl() on control devices. */
70 tsw_param_t *tsw_param; /* TIOCSETA device parameter setting. */
71 tsw_modem_t *tsw_modem; /* Modem sigon/sigoff. */
73 tsw_mmap_t *tsw_mmap; /* mmap() hooks. */
74 tsw_pktnotify_t *tsw_pktnotify; /* TIOCPKT events. */
76 tsw_free_t *tsw_free; /* Destructor. */
78 tsw_busy_t *tsw_busy; /* Draining output. */
80 void *tsw_spare[3]; /* For future use. */
84 ttydevsw_open(struct tty *tp)
87 tty_lock_assert(tp, MA_OWNED);
90 return (tp->t_devsw->tsw_open(tp));
94 ttydevsw_close(struct tty *tp)
97 tty_lock_assert(tp, MA_OWNED);
100 tp->t_devsw->tsw_close(tp);
104 ttydevsw_outwakeup(struct tty *tp)
107 tty_lock_assert(tp, MA_OWNED);
108 MPASS(!tty_gone(tp));
110 /* Prevent spurious wakeups. */
111 if (ttydisc_getc_poll(tp) == 0)
114 tp->t_devsw->tsw_outwakeup(tp);
118 ttydevsw_inwakeup(struct tty *tp)
121 tty_lock_assert(tp, MA_OWNED);
122 MPASS(!tty_gone(tp));
124 /* Prevent spurious wakeups. */
125 if (tp->t_flags & TF_HIWAT_IN)
128 tp->t_devsw->tsw_inwakeup(tp);
132 ttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
135 tty_lock_assert(tp, MA_OWNED);
136 MPASS(!tty_gone(tp));
138 return (tp->t_devsw->tsw_ioctl(tp, cmd, data, td));
142 ttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, caddr_t data,
146 tty_lock_assert(tp, MA_OWNED);
147 MPASS(!tty_gone(tp));
149 return (tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td));
153 ttydevsw_param(struct tty *tp, struct termios *t)
156 MPASS(!tty_gone(tp));
158 return (tp->t_devsw->tsw_param(tp, t));
162 ttydevsw_modem(struct tty *tp, int sigon, int sigoff)
165 MPASS(!tty_gone(tp));
167 return (tp->t_devsw->tsw_modem(tp, sigon, sigoff));
171 ttydevsw_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr,
172 int nprot, vm_memattr_t *memattr)
175 MPASS(!tty_gone(tp));
177 return (tp->t_devsw->tsw_mmap(tp, offset, paddr, nprot, memattr));
181 ttydevsw_pktnotify(struct tty *tp, char event)
184 tty_lock_assert(tp, MA_OWNED);
185 MPASS(!tty_gone(tp));
187 tp->t_devsw->tsw_pktnotify(tp, event);
191 ttydevsw_free(struct tty *tp)
196 tp->t_devsw->tsw_free(tty_softc(tp));
200 ttydevsw_busy(struct tty *tp)
203 tty_lock_assert(tp, MA_OWNED);
204 MPASS(!tty_gone(tp));
206 return (tp->t_devsw->tsw_busy(tp));
209 #endif /* !_SYS_TTYDEVSW_H_ */