1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Portions of this software were developed under sponsorship from Snow 8 * B.V., the Netherlands. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $FreeBSD$ 32 */ 33 34 #ifndef _SYS_TTYDEVSW_H_ 35 #define _SYS_TTYDEVSW_H_ 36 37 #ifndef _SYS_TTY_H_ 38 #error "can only be included through <sys/tty.h>" 39 #endif /* !_SYS_TTY_H_ */ 40 41 /* 42 * Driver routines that are called from the line discipline to adjust 43 * hardware parameters and such. 44 */ 45 typedef int tsw_open_t(struct tty *tp); 46 typedef void tsw_close_t(struct tty *tp); 47 typedef void tsw_outwakeup_t(struct tty *tp); 48 typedef void tsw_inwakeup_t(struct tty *tp); 49 typedef int tsw_ioctl_t(struct tty *tp, u_long cmd, caddr_t data, 50 struct thread *td); 51 typedef int tsw_cioctl_t(struct tty *tp, int unit, u_long cmd, caddr_t data, 52 struct thread *td); 53 typedef int tsw_param_t(struct tty *tp, struct termios *t); 54 typedef int tsw_modem_t(struct tty *tp, int sigon, int sigoff); 55 typedef int tsw_mmap_t(struct tty *tp, vm_ooffset_t offset, 56 vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr); 57 typedef void tsw_pktnotify_t(struct tty *tp, char event); 58 typedef void tsw_free_t(void *softc); 59 typedef bool tsw_busy_t(struct tty *tp); 60 61 struct ttydevsw { 62 unsigned int tsw_flags; /* Default TTY flags. */ 63 64 tsw_open_t *tsw_open; /* Device opening. */ 65 tsw_close_t *tsw_close; /* Device closure. */ 66 67 tsw_outwakeup_t *tsw_outwakeup; /* Output available. */ 68 tsw_inwakeup_t *tsw_inwakeup; /* Input can be stored again. */ 69 70 tsw_ioctl_t *tsw_ioctl; /* ioctl() hooks. */ 71 tsw_cioctl_t *tsw_cioctl; /* ioctl() on control devices. */ 72 tsw_param_t *tsw_param; /* TIOCSETA device parameter setting. */ 73 tsw_modem_t *tsw_modem; /* Modem sigon/sigoff. */ 74 75 tsw_mmap_t *tsw_mmap; /* mmap() hooks. */ 76 tsw_pktnotify_t *tsw_pktnotify; /* TIOCPKT events. */ 77 78 tsw_free_t *tsw_free; /* Destructor. */ 79 80 tsw_busy_t *tsw_busy; /* Draining output. */ 81 82 void *tsw_spare[3]; /* For future use. */ 83 }; 84 85 static __inline int 86 ttydevsw_open(struct tty *tp) 87 { 88 89 tty_lock_assert(tp, MA_OWNED); 90 MPASS(!tty_gone(tp)); 91 92 return (tp->t_devsw->tsw_open(tp)); 93 } 94 95 static __inline void 96 ttydevsw_close(struct tty *tp) 97 { 98 99 tty_lock_assert(tp, MA_OWNED); 100 MPASS(!tty_gone(tp)); 101 102 tp->t_devsw->tsw_close(tp); 103 } 104 105 static __inline void 106 ttydevsw_outwakeup(struct tty *tp) 107 { 108 109 tty_lock_assert(tp, MA_OWNED); 110 MPASS(!tty_gone(tp)); 111 112 /* Prevent spurious wakeups. */ 113 if (ttydisc_getc_poll(tp) == 0) 114 return; 115 116 tp->t_devsw->tsw_outwakeup(tp); 117 } 118 119 static __inline void 120 ttydevsw_inwakeup(struct tty *tp) 121 { 122 123 tty_lock_assert(tp, MA_OWNED); 124 MPASS(!tty_gone(tp)); 125 126 /* Prevent spurious wakeups. */ 127 if (tp->t_flags & TF_HIWAT_IN) 128 return; 129 130 tp->t_devsw->tsw_inwakeup(tp); 131 } 132 133 static __inline int 134 ttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) 135 { 136 137 tty_lock_assert(tp, MA_OWNED); 138 MPASS(!tty_gone(tp)); 139 140 return (tp->t_devsw->tsw_ioctl(tp, cmd, data, td)); 141 } 142 143 static __inline int 144 ttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, caddr_t data, 145 struct thread *td) 146 { 147 148 tty_lock_assert(tp, MA_OWNED); 149 MPASS(!tty_gone(tp)); 150 151 return (tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td)); 152 } 153 154 static __inline int 155 ttydevsw_param(struct tty *tp, struct termios *t) 156 { 157 158 MPASS(!tty_gone(tp)); 159 160 return (tp->t_devsw->tsw_param(tp, t)); 161 } 162 163 static __inline int 164 ttydevsw_modem(struct tty *tp, int sigon, int sigoff) 165 { 166 167 MPASS(!tty_gone(tp)); 168 169 return (tp->t_devsw->tsw_modem(tp, sigon, sigoff)); 170 } 171 172 static __inline int 173 ttydevsw_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr, 174 int nprot, vm_memattr_t *memattr) 175 { 176 177 MPASS(!tty_gone(tp)); 178 179 return (tp->t_devsw->tsw_mmap(tp, offset, paddr, nprot, memattr)); 180 } 181 182 static __inline void 183 ttydevsw_pktnotify(struct tty *tp, char event) 184 { 185 186 tty_lock_assert(tp, MA_OWNED); 187 MPASS(!tty_gone(tp)); 188 189 tp->t_devsw->tsw_pktnotify(tp, event); 190 } 191 192 static __inline void 193 ttydevsw_free(struct tty *tp) 194 { 195 196 MPASS(tty_gone(tp)); 197 198 tp->t_devsw->tsw_free(tty_softc(tp)); 199 } 200 201 static __inline bool 202 ttydevsw_busy(struct tty *tp) 203 { 204 205 tty_lock_assert(tp, MA_OWNED); 206 MPASS(!tty_gone(tp)); 207 208 return (tp->t_devsw->tsw_busy(tp)); 209 } 210 211 #endif /* !_SYS_TTYDEVSW_H_ */ 212