ttydevsw.h revision 183276
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: head/sys/sys/ttydevsw.h 183276 2008-09-22 19:25:14Z ed $ 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); 49183274Sedtypedef int tsw_param_t(struct tty *tp, struct termios *t); 50183274Sedtypedef int tsw_modem_t(struct tty *tp, int sigon, int sigoff); 51183274Sedtypedef int tsw_mmap_t(struct tty *tp, vm_offset_t offset, 52183274Sed vm_paddr_t * paddr, int nprot); 53183274Sedtypedef void tsw_pktnotify_t(struct tty *tp, char event); 54183274Sedtypedef void tsw_free_t(void *softc); 55181905Sed 56181905Sedstruct ttydevsw { 57181905Sed unsigned int tsw_flags; /* Default TTY flags. */ 58181905Sed 59181905Sed tsw_open_t *tsw_open; /* Device opening. */ 60181905Sed tsw_close_t *tsw_close; /* Device closure. */ 61181905Sed 62181905Sed tsw_outwakeup_t *tsw_outwakeup; /* Output available. */ 63181905Sed tsw_inwakeup_t *tsw_inwakeup; /* Input can be stored again. */ 64181905Sed 65181905Sed tsw_ioctl_t *tsw_ioctl; /* ioctl() hooks. */ 66181905Sed tsw_param_t *tsw_param; /* TIOCSETA device parameter setting. */ 67181905Sed tsw_modem_t *tsw_modem; /* Modem sigon/sigoff. */ 68181905Sed 69181905Sed tsw_mmap_t *tsw_mmap; /* mmap() hooks. */ 70182764Sed tsw_pktnotify_t *tsw_pktnotify; /* TIOCPKT events. */ 71181905Sed 72181905Sed tsw_free_t *tsw_free; /* Destructor. */ 73181905Sed}; 74181905Sed 75181905Sedstatic __inline int 76181905Sedttydevsw_open(struct tty *tp) 77181905Sed{ 78181905Sed tty_lock_assert(tp, MA_OWNED); 79181905Sed MPASS(!tty_gone(tp)); 80181905Sed 81181905Sed return tp->t_devsw->tsw_open(tp); 82181905Sed} 83181905Sed 84181905Sedstatic __inline void 85181905Sedttydevsw_close(struct tty *tp) 86181905Sed{ 87181905Sed tty_lock_assert(tp, MA_OWNED); 88181905Sed MPASS(!tty_gone(tp)); 89181905Sed 90181905Sed tp->t_devsw->tsw_close(tp); 91181905Sed} 92181905Sed 93181905Sedstatic __inline void 94181905Sedttydevsw_outwakeup(struct tty *tp) 95181905Sed{ 96181905Sed tty_lock_assert(tp, MA_OWNED); 97181905Sed MPASS(!tty_gone(tp)); 98181905Sed 99181905Sed /* Prevent spurious wakeups. */ 100183276Sed if (ttydisc_getc_poll(tp) == 0) 101181905Sed return; 102181905Sed 103181905Sed tp->t_devsw->tsw_outwakeup(tp); 104181905Sed} 105181905Sed 106181905Sedstatic __inline void 107181905Sedttydevsw_inwakeup(struct tty *tp) 108181905Sed{ 109181905Sed tty_lock_assert(tp, MA_OWNED); 110181905Sed MPASS(!tty_gone(tp)); 111181905Sed 112181905Sed /* Prevent spurious wakeups. */ 113181905Sed if (tp->t_flags & TF_HIWAT_IN) 114181905Sed return; 115181905Sed 116181905Sed tp->t_devsw->tsw_inwakeup(tp); 117181905Sed} 118181905Sed 119181905Sedstatic __inline int 120181905Sedttydevsw_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) 121181905Sed{ 122181905Sed tty_lock_assert(tp, MA_OWNED); 123181905Sed MPASS(!tty_gone(tp)); 124181905Sed 125181905Sed return tp->t_devsw->tsw_ioctl(tp, cmd, data, td); 126181905Sed} 127181905Sed 128181905Sedstatic __inline int 129181905Sedttydevsw_param(struct tty *tp, struct termios *t) 130181905Sed{ 131181905Sed MPASS(!tty_gone(tp)); 132181905Sed 133181905Sed return tp->t_devsw->tsw_param(tp, t); 134181905Sed} 135181905Sed 136181905Sedstatic __inline int 137181905Sedttydevsw_modem(struct tty *tp, int sigon, int sigoff) 138181905Sed{ 139181905Sed MPASS(!tty_gone(tp)); 140181905Sed 141181905Sed return tp->t_devsw->tsw_modem(tp, sigon, sigoff); 142181905Sed} 143181905Sed 144181905Sedstatic __inline int 145181905Sedttydevsw_mmap(struct tty *tp, vm_offset_t offset, vm_paddr_t *paddr, int nprot) 146181905Sed{ 147181905Sed MPASS(!tty_gone(tp)); 148181905Sed 149181905Sed return tp->t_devsw->tsw_mmap(tp, offset, paddr, nprot); 150181905Sed} 151181905Sed 152181905Sedstatic __inline void 153182764Sedttydevsw_pktnotify(struct tty *tp, char event) 154182764Sed{ 155182764Sed tty_lock_assert(tp, MA_OWNED); 156182764Sed MPASS(!tty_gone(tp)); 157182764Sed 158182764Sed tp->t_devsw->tsw_pktnotify(tp, event); 159182764Sed} 160182764Sed 161182764Sedstatic __inline void 162181905Sedttydevsw_free(struct tty *tp) 163181905Sed{ 164181905Sed MPASS(tty_gone(tp)); 165181905Sed 166181905Sed tp->t_devsw->tsw_free(tty_softc(tp)); 167181905Sed} 168181905Sed 169181905Sed#endif /* !_SYS_TTYDEVSW_H_ */ 170