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_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); 55196452Sedsize_t ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len); 56183274Sedsize_t ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len); 57183274Sedvoid ttydisc_rint_done(struct tty *tp); 58183276Sedsize_t ttydisc_rint_poll(struct tty *tp); 59183274Sedsize_t ttydisc_getc(struct tty *tp, void *buf, size_t len); 60183274Sedint ttydisc_getc_uio(struct tty *tp, struct uio *uio); 61183276Sedsize_t ttydisc_getc_poll(struct tty *tp); 62181905Sed 63181905Sed/* Error codes for ttydisc_rint(). */ 64181905Sed#define TRE_FRAMING 0x01 65181905Sed#define TRE_PARITY 0x02 66181905Sed#define TRE_OVERRUN 0x04 67181905Sed#define TRE_BREAK 0x08 68181905Sed 69181905Sedstatic __inline size_t 70181905Sedttydisc_read_poll(struct tty *tp) 71181905Sed{ 72181905Sed 73181905Sed tty_lock_assert(tp, MA_OWNED); 74181905Sed 75181905Sed return ttyinq_bytescanonicalized(&tp->t_inq); 76181905Sed} 77181905Sed 78181905Sedstatic __inline size_t 79181905Sedttydisc_write_poll(struct tty *tp) 80181905Sed{ 81181905Sed 82181905Sed tty_lock_assert(tp, MA_OWNED); 83181905Sed 84181905Sed return ttyoutq_bytesleft(&tp->t_outq); 85181905Sed} 86181905Sed 87181905Sed#endif /* !_SYS_TTYDISC_H_ */ 88