11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This file is subject to the terms and conditions of the GNU General Public
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * License.  See the file "COPYING" in the main directory of this archive
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * for more details.
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1995, 1996, 2000, 2001 by Ralf Baechle
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2000, 2001 Silicon Graphics, Inc.
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _ASM_TERMIOS_H
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _ASM_TERMIOS_H
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
124ca98d399e66899222f1d457731b7857e85e09f1Paul Gortmaker#include <asm/uaccess.h>
1361730c538f8281efa7ac12596da9f3f9a31b9272David Howells#include <uapi/asm/termios.h>
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *	intr=^C		quit=^\		erase=del	kill=^U
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *	vmin=\1		vtime=\0	eol2=\0		swtc=\0
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *	start=^Q	stop=^S		susp=^Z		vdsusp=
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *	reprint=^R	discard=^U	werase=^W	lnext=^V
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *	eof=^D		eol=\0
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define INIT_C_CC "\003\034\177\025\1\0\0\0\021\023\032\0\022\017\027\026\004\0"
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/string.h>
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Translate a "termio" structure into a "termios". Ugh.
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
29732f0462d59721764843783d790a613613287b33Ralf Baechlestatic inline int user_termio_to_kernel_termios(struct ktermios *termios,
30732f0462d59721764843783d790a613613287b33Ralf Baechle	struct termio __user *termio)
31732f0462d59721764843783d790a613613287b33Ralf Baechle{
32732f0462d59721764843783d790a613613287b33Ralf Baechle	unsigned short iflag, oflag, cflag, lflag;
33732f0462d59721764843783d790a613613287b33Ralf Baechle	unsigned int err;
34732f0462d59721764843783d790a613613287b33Ralf Baechle
35732f0462d59721764843783d790a613613287b33Ralf Baechle	if (!access_ok(VERIFY_READ, termio, sizeof(struct termio)))
36732f0462d59721764843783d790a613613287b33Ralf Baechle		return -EFAULT;
37732f0462d59721764843783d790a613613287b33Ralf Baechle
38732f0462d59721764843783d790a613613287b33Ralf Baechle	err = __get_user(iflag, &termio->c_iflag);
39732f0462d59721764843783d790a613613287b33Ralf Baechle	termios->c_iflag = (termios->c_iflag & 0xffff0000) | iflag;
40732f0462d59721764843783d790a613613287b33Ralf Baechle	err |=__get_user(oflag, &termio->c_oflag);
41732f0462d59721764843783d790a613613287b33Ralf Baechle	termios->c_oflag = (termios->c_oflag & 0xffff0000) | oflag;
42732f0462d59721764843783d790a613613287b33Ralf Baechle	err |=__get_user(cflag, &termio->c_cflag);
43732f0462d59721764843783d790a613613287b33Ralf Baechle	termios->c_cflag = (termios->c_cflag & 0xffff0000) | cflag;
44732f0462d59721764843783d790a613613287b33Ralf Baechle	err |=__get_user(lflag, &termio->c_lflag);
45732f0462d59721764843783d790a613613287b33Ralf Baechle	termios->c_lflag = (termios->c_lflag & 0xffff0000) | lflag;
46732f0462d59721764843783d790a613613287b33Ralf Baechle	err |=__get_user(termios->c_line, &termio->c_line);
47732f0462d59721764843783d790a613613287b33Ralf Baechle	if (err)
48732f0462d59721764843783d790a613613287b33Ralf Baechle		return -EFAULT;
49732f0462d59721764843783d790a613613287b33Ralf Baechle
50732f0462d59721764843783d790a613613287b33Ralf Baechle	if (__copy_from_user(termios->c_cc, termio->c_cc, NCC))
51732f0462d59721764843783d790a613613287b33Ralf Baechle		return -EFAULT;
52732f0462d59721764843783d790a613613287b33Ralf Baechle
53732f0462d59721764843783d790a613613287b33Ralf Baechle	return 0;
54732f0462d59721764843783d790a613613287b33Ralf Baechle}
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Translate a "termios" structure into a "termio". Ugh.
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
59732f0462d59721764843783d790a613613287b33Ralf Baechlestatic inline int kernel_termios_to_user_termio(struct termio __user *termio,
60732f0462d59721764843783d790a613613287b33Ralf Baechle	struct ktermios *termios)
61732f0462d59721764843783d790a613613287b33Ralf Baechle{
62732f0462d59721764843783d790a613613287b33Ralf Baechle	int err;
63732f0462d59721764843783d790a613613287b33Ralf Baechle
64732f0462d59721764843783d790a613613287b33Ralf Baechle	if (!access_ok(VERIFY_WRITE, termio, sizeof(struct termio)))
65732f0462d59721764843783d790a613613287b33Ralf Baechle		return -EFAULT;
66732f0462d59721764843783d790a613613287b33Ralf Baechle
67732f0462d59721764843783d790a613613287b33Ralf Baechle	err = __put_user(termios->c_iflag, &termio->c_iflag);
68732f0462d59721764843783d790a613613287b33Ralf Baechle	err |= __put_user(termios->c_oflag, &termio->c_oflag);
69732f0462d59721764843783d790a613613287b33Ralf Baechle	err |= __put_user(termios->c_cflag, &termio->c_cflag);
70732f0462d59721764843783d790a613613287b33Ralf Baechle	err |= __put_user(termios->c_lflag, &termio->c_lflag);
71732f0462d59721764843783d790a613613287b33Ralf Baechle	err |= __put_user(termios->c_line, &termio->c_line);
72732f0462d59721764843783d790a613613287b33Ralf Baechle	if (err)
73732f0462d59721764843783d790a613613287b33Ralf Baechle		return -EFAULT;
74732f0462d59721764843783d790a613613287b33Ralf Baechle
75732f0462d59721764843783d790a613613287b33Ralf Baechle	if (__copy_to_user(termio->c_cc, termios->c_cc, NCC))
76732f0462d59721764843783d790a613613287b33Ralf Baechle		return -EFAULT;
77732f0462d59721764843783d790a613613287b33Ralf Baechle
78732f0462d59721764843783d790a613613287b33Ralf Baechle	return 0;
79732f0462d59721764843783d790a613613287b33Ralf Baechle}
80732f0462d59721764843783d790a613613287b33Ralf Baechle
81732f0462d59721764843783d790a613613287b33Ralf Baechlestatic inline int user_termios_to_kernel_termios(struct ktermios __user *k,
82732f0462d59721764843783d790a613613287b33Ralf Baechle	struct termios2 *u)
83732f0462d59721764843783d790a613613287b33Ralf Baechle{
84732f0462d59721764843783d790a613613287b33Ralf Baechle	return copy_from_user(k, u, sizeof(struct termios2)) ? -EFAULT : 0;
85732f0462d59721764843783d790a613613287b33Ralf Baechle}
86732f0462d59721764843783d790a613613287b33Ralf Baechle
87732f0462d59721764843783d790a613613287b33Ralf Baechlestatic inline int kernel_termios_to_user_termios(struct termios2 __user *u,
88732f0462d59721764843783d790a613613287b33Ralf Baechle	struct ktermios *k)
89732f0462d59721764843783d790a613613287b33Ralf Baechle{
90732f0462d59721764843783d790a613613287b33Ralf Baechle	return copy_to_user(u, k, sizeof(struct termios2)) ? -EFAULT : 0;
91732f0462d59721764843783d790a613613287b33Ralf Baechle}
92732f0462d59721764843783d790a613613287b33Ralf Baechle
93732f0462d59721764843783d790a613613287b33Ralf Baechlestatic inline int user_termios_to_kernel_termios_1(struct ktermios *k,
94732f0462d59721764843783d790a613613287b33Ralf Baechle	struct termios __user *u)
95732f0462d59721764843783d790a613613287b33Ralf Baechle{
96732f0462d59721764843783d790a613613287b33Ralf Baechle	return copy_from_user(k, u, sizeof(struct termios)) ? -EFAULT : 0;
97732f0462d59721764843783d790a613613287b33Ralf Baechle}
98732f0462d59721764843783d790a613613287b33Ralf Baechle
99732f0462d59721764843783d790a613613287b33Ralf Baechlestatic inline int kernel_termios_to_user_termios_1(struct termios __user *u,
100732f0462d59721764843783d790a613613287b33Ralf Baechle	struct ktermios *k)
101732f0462d59721764843783d790a613613287b33Ralf Baechle{
102732f0462d59721764843783d790a613613287b33Ralf Baechle	return copy_to_user(u, k, sizeof(struct termios)) ? -EFAULT : 0;
103732f0462d59721764843783d790a613613287b33Ralf Baechle}
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* _ASM_TERMIOS_H */
106