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