xref: /freebsd/sys/sys/ttydisc.h (revision 522083ff)
1bc093719SEd Schouten /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c4e20cadSPedro F. Giffuni  *
4bc093719SEd Schouten  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
5bc093719SEd Schouten  * All rights reserved.
6bc093719SEd Schouten  *
7bc093719SEd Schouten  * Portions of this software were developed under sponsorship from Snow
8bc093719SEd Schouten  * B.V., the Netherlands.
9bc093719SEd Schouten  *
10bc093719SEd Schouten  * Redistribution and use in source and binary forms, with or without
11bc093719SEd Schouten  * modification, are permitted provided that the following conditions
12bc093719SEd Schouten  * are met:
13bc093719SEd Schouten  * 1. Redistributions of source code must retain the above copyright
14bc093719SEd Schouten  *    notice, this list of conditions and the following disclaimer.
15bc093719SEd Schouten  * 2. Redistributions in binary form must reproduce the above copyright
16bc093719SEd Schouten  *    notice, this list of conditions and the following disclaimer in the
17bc093719SEd Schouten  *    documentation and/or other materials provided with the distribution.
18bc093719SEd Schouten  *
19bc093719SEd Schouten  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20bc093719SEd Schouten  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21bc093719SEd Schouten  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22bc093719SEd Schouten  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23bc093719SEd Schouten  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24bc093719SEd Schouten  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25bc093719SEd Schouten  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26bc093719SEd Schouten  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27bc093719SEd Schouten  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28bc093719SEd Schouten  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29bc093719SEd Schouten  * SUCH DAMAGE.
30bc093719SEd Schouten  */
31bc093719SEd Schouten 
32bc093719SEd Schouten #ifndef _SYS_TTYDISC_H_
33bc093719SEd Schouten #define	_SYS_TTYDISC_H_
34bc093719SEd Schouten 
35bc093719SEd Schouten #ifndef _SYS_TTY_H_
36bc093719SEd Schouten #error "can only be included through <sys/tty.h>"
37bc093719SEd Schouten #endif /* !_SYS_TTY_H_ */
38bc093719SEd Schouten 
39bc093719SEd Schouten struct cv;
40bc093719SEd Schouten struct thread;
41bc093719SEd Schouten struct tty;
42bc093719SEd Schouten struct uio;
43bc093719SEd Schouten 
44bc093719SEd Schouten /* Top half routines. */
45d344ffe5SEd Schouten void	ttydisc_open(struct tty *tp);
46d344ffe5SEd Schouten void	ttydisc_close(struct tty *tp);
47d51dac5fSKyle Evans size_t	ttydisc_bytesavail(struct tty *tp);
48d344ffe5SEd Schouten int	ttydisc_read(struct tty *tp, struct uio *uio, int ioflag);
49d344ffe5SEd Schouten int	ttydisc_write(struct tty *tp, struct uio *uio, int ioflag);
50*522083ffSKyle Evans void	ttydisc_canonicalize(struct tty *tp);
51d344ffe5SEd Schouten void	ttydisc_optimize(struct tty *tp);
52bc093719SEd Schouten 
53bc093719SEd Schouten /* Bottom half routines. */
54d344ffe5SEd Schouten void	ttydisc_modem(struct tty *tp, int open);
55bc093719SEd Schouten #define ttydisc_can_bypass(tp) ((tp)->t_flags & TF_BYPASS)
56d344ffe5SEd Schouten int	ttydisc_rint(struct tty *tp, char c, int flags);
575c67885aSEd Schouten size_t	ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len);
58d344ffe5SEd Schouten size_t	ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len);
59d344ffe5SEd Schouten void	ttydisc_rint_done(struct tty *tp);
60a1215e37SEd Schouten size_t	ttydisc_rint_poll(struct tty *tp);
61d344ffe5SEd Schouten size_t	ttydisc_getc(struct tty *tp, void *buf, size_t len);
62d344ffe5SEd Schouten int	ttydisc_getc_uio(struct tty *tp, struct uio *uio);
63a1215e37SEd Schouten size_t	ttydisc_getc_poll(struct tty *tp);
64bc093719SEd Schouten 
65bc093719SEd Schouten /* Error codes for ttydisc_rint(). */
66bc093719SEd Schouten #define	TRE_FRAMING	0x01
67bc093719SEd Schouten #define	TRE_PARITY	0x02
68bc093719SEd Schouten #define	TRE_OVERRUN	0x04
69bc093719SEd Schouten #define	TRE_BREAK	0x08
70bc093719SEd Schouten 
71bc093719SEd Schouten static __inline size_t
ttydisc_read_poll(struct tty * tp)72bc093719SEd Schouten ttydisc_read_poll(struct tty *tp)
73bc093719SEd Schouten {
74bc093719SEd Schouten 
7523d53268SKyle Evans 	tty_assert_locked(tp);
76bc093719SEd Schouten 
77bc093719SEd Schouten 	return ttyinq_bytescanonicalized(&tp->t_inq);
78bc093719SEd Schouten }
79bc093719SEd Schouten 
80bc093719SEd Schouten static __inline size_t
ttydisc_write_poll(struct tty * tp)81bc093719SEd Schouten ttydisc_write_poll(struct tty *tp)
82bc093719SEd Schouten {
83bc093719SEd Schouten 
8423d53268SKyle Evans 	tty_assert_locked(tp);
85bc093719SEd Schouten 
86bc093719SEd Schouten 	return ttyoutq_bytesleft(&tp->t_outq);
87bc093719SEd Schouten }
88bc093719SEd Schouten 
89bc093719SEd Schouten #endif /* !_SYS_TTYDISC_H_ */
90