ttydisc.h revision 183274
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/ttydisc.h 183274 2008-09-22 18:44:09Z ed $ 30181905Sed */ 31181905Sed 32181905Sed#ifndef _SYS_TTYDISC_H_ 33181905Sed#define _SYS_TTYDISC_H_ 34181905Sed 35181905Sed#ifndef _SYS_TTY_H_ 36181905Sed#error "can only be included through <sys/tty.h>" 37181905Sed#endif /* !_SYS_TTY_H_ */ 38181905Sed 39181905Sedstruct cv; 40181905Sedstruct thread; 41181905Sedstruct tty; 42181905Sedstruct uio; 43181905Sed 44181905Sed/* Top half routines. */ 45183274Sedvoid ttydisc_open(struct tty *tp); 46183274Sedvoid ttydisc_close(struct tty *tp); 47183274Sedint ttydisc_read(struct tty *tp, struct uio *uio, int ioflag); 48183274Sedint ttydisc_write(struct tty *tp, struct uio *uio, int ioflag); 49183274Sedvoid ttydisc_optimize(struct tty *tp); 50181905Sed 51181905Sed/* Bottom half routines. */ 52183274Sedvoid ttydisc_modem(struct tty *tp, int open); 53181905Sed#define ttydisc_can_bypass(tp) ((tp)->t_flags & TF_BYPASS) 54183274Sedint ttydisc_rint(struct tty *tp, char c, int flags); 55183274Sedsize_t ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len); 56183274Sedvoid ttydisc_rint_done(struct tty *tp); 57183274Sedsize_t ttydisc_getc(struct tty *tp, void *buf, size_t len); 58183274Sedint ttydisc_getc_uio(struct tty *tp, struct uio *uio); 59181905Sed 60181905Sed/* Error codes for ttydisc_rint(). */ 61181905Sed#define TRE_FRAMING 0x01 62181905Sed#define TRE_PARITY 0x02 63181905Sed#define TRE_OVERRUN 0x04 64181905Sed#define TRE_BREAK 0x08 65181905Sed 66181905Sedstatic __inline size_t 67181905Sedttydisc_read_poll(struct tty *tp) 68181905Sed{ 69181905Sed 70181905Sed tty_lock_assert(tp, MA_OWNED); 71181905Sed 72181905Sed return ttyinq_bytescanonicalized(&tp->t_inq); 73181905Sed} 74181905Sed 75181905Sedstatic __inline size_t 76181905Sedttydisc_write_poll(struct tty *tp) 77181905Sed{ 78181905Sed 79181905Sed tty_lock_assert(tp, MA_OWNED); 80181905Sed 81181905Sed return ttyoutq_bytesleft(&tp->t_outq); 82181905Sed} 83181905Sed 84181905Sedstatic __inline size_t 85181905Sedttydisc_rint_poll(struct tty *tp) 86181905Sed{ 87182444Sed size_t l; 88181905Sed 89182445Sed tty_lock_assert(tp, MA_OWNED); 90182445Sed 91182444Sed /* 92182444Sed * XXX: Still allow character input when there's no space in the 93182444Sed * buffers, but we haven't entered the high watermark. This is 94182444Sed * to allow backspace characters to be inserted when in 95182444Sed * canonical mode. 96182444Sed */ 97182444Sed l = ttyinq_bytesleft(&tp->t_inq); 98182444Sed if (l == 0 && (tp->t_flags & TF_HIWAT_IN) == 0) 99182444Sed return (1); 100182444Sed 101182444Sed return (l); 102181905Sed} 103181905Sed 104181905Sedstatic __inline size_t 105181905Sedttydisc_getc_poll(struct tty *tp) 106181905Sed{ 107181905Sed 108181905Sed tty_lock_assert(tp, MA_OWNED); 109181905Sed 110181905Sed if (tp->t_flags & TF_STOPPED) 111181905Sed return (0); 112181905Sed 113181905Sed return ttyoutq_bytesused(&tp->t_outq); 114181905Sed} 115181905Sed 116181905Sed#endif /* !_SYS_TTYDISC_H_ */ 117