Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef _ASM_GENERIC_TERMIOS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _ASM_GENERIC_TERMIOS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <uapi/asm-generic/termios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) /*	intr=^C		quit=^\		erase=del	kill=^U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 	eof=^D		vtime=\0	vmin=\1		sxtc=\0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 	start=^Q	stop=^S		susp=^Z		eol=\0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	reprint=^R	discard=^U	werase=^W	lnext=^V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	eol2=\0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Translate a "termio" structure into a "termios". Ugh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static inline int user_termio_to_kernel_termios(struct ktermios *termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 						const struct termio __user *termio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	unsigned short tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	if (get_user(tmp, &termio->c_iflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (get_user(tmp, &termio->c_oflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (get_user(tmp, &termio->c_cflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (get_user(tmp, &termio->c_lflag) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (get_user(termios->c_line, &termio->c_line) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * Translate a "termios" structure into a "termio". Ugh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static inline int kernel_termios_to_user_termio(struct termio __user *termio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 						struct ktermios *termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	    put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	    put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	    put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	    put_user(termios->c_line,  &termio->c_line) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	    copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #ifdef TCGETS2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static inline int user_termios_to_kernel_termios(struct ktermios *k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 						 struct termios2 __user *u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return copy_from_user(k, u, sizeof(struct termios2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 						 struct ktermios *k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return copy_to_user(u, k, sizeof(struct termios2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 						   struct termios __user *u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return copy_from_user(k, u, sizeof(struct termios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 						   struct ktermios *k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return copy_to_user(u, k, sizeof(struct termios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #else /* TCGETS2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static inline int user_termios_to_kernel_termios(struct ktermios *k,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 						 struct termios __user *u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return copy_from_user(k, u, sizeof(struct termios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static inline int kernel_termios_to_user_termios(struct termios __user *u,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 						 struct ktermios *k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return copy_to_user(u, k, sizeof(struct termios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #endif /* TCGETS2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #endif /* _ASM_GENERIC_TERMIOS_H */