1181905Sed/*- 2181905Sed * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> 3181905Sed * All rights reserved. 4181905Sed * 5181905Sed * Portions of this software were developed under sponsorship from Snow 6181905Sed * B.V., the Netherlands. 7181905Sed * 8181905Sed * Redistribution and use in source and binary forms, with or without 9181905Sed * modification, are permitted provided that the following conditions 10181905Sed * are met: 11181905Sed * 1. Redistributions of source code must retain the above copyright 12181905Sed * notice, this list of conditions and the following disclaimer. 13181905Sed * 2. Redistributions in binary form must reproduce the above copyright 14181905Sed * notice, this list of conditions and the following disclaimer in the 15181905Sed * documentation and/or other materials provided with the distribution. 16181905Sed * 17181905Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18181905Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19181905Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20181905Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21181905Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22181905Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23181905Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24181905Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25181905Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26181905Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27181905Sed * SUCH DAMAGE. 28181905Sed * 29181905Sed * $FreeBSD$ 30181905Sed */ 31181905Sed 32181905Sed#ifndef _SYS_TTYDEVSW_H_ 33181905Sed#define _SYS_TTYDEVSW_H_ 34181905Sed 35181905Sed#ifndef _SYS_TTY_H_ 36181905Sed#error "can only be included through <sys/tty.h>" 37181905Sed#endif /* !_SYS_TTY_H_ */ 38181905Sed 39181905Sed/* 40181905Sed * Driver routines that are called from the line discipline to adjust 41181905Sed * hardware parameters and such. 42181905Sed */ 43183274Sedtypedef int tsw_open_t(struct tty *tp); 44183274Sedtypedef void tsw_close_t(struct tty *tp); 45183274Sedtypedef void tsw_outwakeup_t(struct tty *tp); 46183274Sedtypedef void tsw_inwakeup_t(struct tty *tp); 47183274Sedtypedef int tsw_ioctl_t(struct tty *tp, u_long cmd, caddr_t data, 48183274Sed struct thread *td); 49223722Sedtypedef int tsw_cioctl_t(struct tty *tp, int unit, u_long cmd, caddr_t data, 50223722Sed struct thread *td); 51183274Sedtypedef int tsw_param_t(struct tty *tp, struct termios *t); 52183274Sedtypedef int tsw_modem_t(struct tty *tp, int sigon, int sigoff); 53201223Srnolandtypedef int tsw_mmap_t(struct tty *tp, vm_ooffset_t offset, 54201223Srnoland vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr); 55183274Sedtypedef void tsw_pktnotify_t(struct tty *tp, char event); 56183274Sedtypedef void tsw_free_t(void *softc); 57181905Sed 58181905Sedstruct ttydevsw { 59181905Sed unsigned int tsw_flags; /* Default TTY flags. */ 60181905Sed 61181905Sed tsw_open_t *tsw_open; /* Device opening. */ 62181905Sed tsw_close_t *tsw_close; /* Device closure. */ 63181905Sed 64181905Sed tsw_outwakeup_t *tsw_outwakeup; /* Output available. */ 65181905Sed tsw_inwakeup_t *tsw_inwakeup; /* Input can be stored again. */ 66181905Sed 67181905Sed tsw_ioctl_t *tsw_ioctl; /* ioctl() hooks. */ 68223722Sed tsw_cioctl_t *tsw_cioctl; /* ioctl() on control devices. */ 69181905Sed tsw_param_t *tsw_param; /* TIOCSETA device parameter setting. */ 70181905Sed tsw_modem_t *tsw_modem; /* Modem sigon/sigoff. */ 71181905Sed 72181905Sed tsw_mmap_t *tsw_mmap; /* mmap() hooks. */ 73182764Sed tsw_pktnotify_t *tsw_pktnotify; /* TIOCPKT events. */ 74181905Sed 75181905Sed tsw_free_t *tsw_free; /* Destructor. */ 76223722Sed 77223722Sed void *tsw_spare[4]; /* For future use. */ 78181905Sed}; 79181905Sed 80181905Sedstatic __inline int 81181905Sedttydevsw_open(struct tty *tp) 82181905Sed{ 83181905Sed tty_lock_assert(tp, MA_OWNED); 84181905Sed MPASS(!tty_gone(tp)); 85181905Sed 86181905Sed return tp->t_devsw->tsw_open(tp); 87181905Sed} 88181905Sed 89181905Sedstatic __inline void 90181905Sedttydevsw_close(struct tty *tp) 91181905Sed{ 92181905Sed tty_lock_assert(tp, MA_OWNED); 93181905Sed MPASS(!tty_gone(tp)); 94181905Sed 95181905Sed tp->t_devsw->tsw_close(tp); 96181905Sed} 97181905Sed 98181905Sedstatic __inline void 99181905Sedttydevsw_outwakeup(struct tty *tp) 100181905Sed{ 101181905Sed tty_lock_assert(tp, MA_OWNED); 102181905Sed MPASS(!tty_gone(tp)); 103181905Sed 104181905Sed /* Prevent spurious wakeups. */ 105183276Sed if (ttydisc_getc_poll(tp) == 0) 106181905Sed return; 107181905Sed 108181905Sed tp->t_devsw->tsw_outwakeup(tp); 109181905Sed} 110181905Sed 111181905Sedstatic __inline void 112181905Sedttydevsw_inwakeup(struct tty *tp) 113181905Sed{ 114181905Sed tty_lock_assert(tp, MA_OWNED); 115181905Sed MPASS(!tty_gone(tp)); 116181905Sed 117181905Sed /* Prevent spurious wakeups. */ 118181905Sed if (tp->t_flags & TF_HIWAT_IN) 119181905Sed return; 120181905Sed 121181905Sed tp->t_devsw->tsw_inwakeup(tp); 122181905Sed} 123181905Sed 124181905Sedstatic __inline int 125181905Sedttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) 126181905Sed{ 127181905Sed tty_lock_assert(tp, MA_OWNED); 128181905Sed MPASS(!tty_gone(tp)); 129181905Sed 130181905Sed return tp->t_devsw->tsw_ioctl(tp, cmd, data, td); 131181905Sed} 132181905Sed 133181905Sedstatic __inline int 134223722Sedttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, caddr_t data, struct thread *td) 135223722Sed{ 136223722Sed tty_lock_assert(tp, MA_OWNED); 137223722Sed MPASS(!tty_gone(tp)); 138223722Sed 139223722Sed return tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td); 140223722Sed} 141223722Sed 142223722Sedstatic __inline int 143181905Sedttydevsw_param(struct tty *tp, struct termios *t) 144181905Sed{ 145181905Sed MPASS(!tty_gone(tp)); 146181905Sed 147181905Sed return tp->t_devsw->tsw_param(tp, t); 148181905Sed} 149181905Sed 150181905Sedstatic __inline int 151181905Sedttydevsw_modem(struct tty *tp, int sigon, int sigoff) 152181905Sed{ 153181905Sed MPASS(!tty_gone(tp)); 154181905Sed 155181905Sed return tp->t_devsw->tsw_modem(tp, sigon, sigoff); 156181905Sed} 157181905Sed 158181905Sedstatic __inline int 159201223Srnolandttydevsw_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr, 160201223Srnoland int nprot, vm_memattr_t *memattr) 161181905Sed{ 162181905Sed MPASS(!tty_gone(tp)); 163181905Sed 164201223Srnoland return tp->t_devsw->tsw_mmap(tp, offset, paddr, nprot, memattr); 165181905Sed} 166181905Sed 167181905Sedstatic __inline void 168182764Sedttydevsw_pktnotify(struct tty *tp, char event) 169182764Sed{ 170182764Sed tty_lock_assert(tp, MA_OWNED); 171182764Sed MPASS(!tty_gone(tp)); 172182764Sed 173182764Sed tp->t_devsw->tsw_pktnotify(tp, event); 174182764Sed} 175182764Sed 176182764Sedstatic __inline void 177181905Sedttydevsw_free(struct tty *tp) 178181905Sed{ 179181905Sed MPASS(tty_gone(tp)); 180181905Sed 181181905Sed tp->t_devsw->tsw_free(tty_softc(tp)); 182181905Sed} 183181905Sed 184181905Sed#endif /* !_SYS_TTYDEVSW_H_ */ 185