Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _SPARC_TERMIOS_H |
| 2 | #define _SPARC_TERMIOS_H |
| 3 | |
| 4 | #include <asm/ioctls.h> |
| 5 | #include <asm/termbits.h> |
| 6 | |
| 7 | #if defined(__KERNEL__) || defined(__DEFINE_BSD_TERMIOS) |
| 8 | struct sgttyb { |
| 9 | char sg_ispeed; |
| 10 | char sg_ospeed; |
| 11 | char sg_erase; |
| 12 | char sg_kill; |
| 13 | short sg_flags; |
| 14 | }; |
| 15 | |
| 16 | struct tchars { |
| 17 | char t_intrc; |
| 18 | char t_quitc; |
| 19 | char t_startc; |
| 20 | char t_stopc; |
| 21 | char t_eofc; |
| 22 | char t_brkc; |
| 23 | }; |
| 24 | |
| 25 | struct ltchars { |
| 26 | char t_suspc; |
| 27 | char t_dsuspc; |
| 28 | char t_rprntc; |
| 29 | char t_flushc; |
| 30 | char t_werasc; |
| 31 | char t_lnextc; |
| 32 | }; |
| 33 | #endif /* __KERNEL__ */ |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct winsize { |
| 36 | unsigned short ws_row; |
| 37 | unsigned short ws_col; |
| 38 | unsigned short ws_xpixel; |
| 39 | unsigned short ws_ypixel; |
| 40 | }; |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #ifdef __KERNEL__ |
| 43 | #include <linux/module.h> |
| 44 | |
| 45 | /* |
| 46 | * c_cc characters in the termio structure. Oh, how I love being |
| 47 | * backwardly compatible. Notice that character 4 and 5 are |
| 48 | * interpreted differently depending on whether ICANON is set in |
| 49 | * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise |
| 50 | * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which |
| 51 | * is compatible with sysV)... |
| 52 | */ |
| 53 | #define _VMIN 4 |
| 54 | #define _VTIME 5 |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* intr=^C quit=^\ erase=del kill=^U |
| 57 | eof=^D eol=\0 eol2=\0 sxtc=\0 |
| 58 | start=^Q stop=^S susp=^Z dsusp=^Y |
| 59 | reprint=^R discard=^U werase=^W lnext=^V |
| 60 | vmin=\1 vtime=\0 |
| 61 | */ |
| 62 | #define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001" |
| 63 | |
| 64 | /* |
| 65 | * Translate a "termio" structure into a "termios". Ugh. |
| 66 | */ |
| 67 | #define user_termio_to_kernel_termios(termios, termio) \ |
| 68 | ({ \ |
| 69 | unsigned short tmp; \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 70 | int err; \ |
| 71 | err = get_user(tmp, &(termio)->c_iflag); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 73 | err |= get_user(tmp, &(termio)->c_oflag); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 75 | err |= get_user(tmp, &(termio)->c_cflag); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 77 | err |= get_user(tmp, &(termio)->c_lflag); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 79 | err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \ |
| 80 | err; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }) |
| 82 | |
| 83 | /* |
| 84 | * Translate a "termios" structure into a "termio". Ugh. |
| 85 | * |
| 86 | * Note the "fun" _VMIN overloading. |
| 87 | */ |
| 88 | #define kernel_termios_to_user_termio(termio, termios) \ |
| 89 | ({ \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 90 | int err; \ |
| 91 | err = put_user((termios)->c_iflag, &(termio)->c_iflag); \ |
| 92 | err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \ |
| 93 | err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \ |
| 94 | err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \ |
| 95 | err |= put_user((termios)->c_line, &(termio)->c_line); \ |
| 96 | err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (!((termios)->c_lflag & ICANON)) { \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 98 | err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \ |
| 99 | err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 101 | err; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | }) |
| 103 | |
| 104 | #define user_termios_to_kernel_termios(k, u) \ |
| 105 | ({ \ |
David Miller | 6050afb | 2007-10-17 19:38:10 -0700 | [diff] [blame] | 106 | int err; \ |
| 107 | err = get_user((k)->c_iflag, &(u)->c_iflag); \ |
| 108 | err |= get_user((k)->c_oflag, &(u)->c_oflag); \ |
| 109 | err |= get_user((k)->c_cflag, &(u)->c_cflag); \ |
| 110 | err |= get_user((k)->c_lflag, &(u)->c_lflag); \ |
| 111 | err |= get_user((k)->c_line, &(u)->c_line); \ |
| 112 | err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \ |
| 113 | if ((k)->c_lflag & ICANON) { \ |
| 114 | err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ |
| 115 | err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ |
| 116 | } else { \ |
| 117 | err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ |
| 118 | err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ |
| 119 | } \ |
| 120 | err |= get_user((k)->c_ispeed, &(u)->c_ispeed); \ |
| 121 | err |= get_user((k)->c_ospeed, &(u)->c_ospeed); \ |
| 122 | err; \ |
| 123 | }) |
| 124 | |
| 125 | #define kernel_termios_to_user_termios(u, k) \ |
| 126 | ({ \ |
| 127 | int err; \ |
| 128 | err = put_user((k)->c_iflag, &(u)->c_iflag); \ |
| 129 | err |= put_user((k)->c_oflag, &(u)->c_oflag); \ |
| 130 | err |= put_user((k)->c_cflag, &(u)->c_cflag); \ |
| 131 | err |= put_user((k)->c_lflag, &(u)->c_lflag); \ |
| 132 | err |= put_user((k)->c_line, &(u)->c_line); \ |
| 133 | err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \ |
| 134 | if (!((k)->c_lflag & ICANON)) { \ |
| 135 | err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ |
| 136 | err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ |
| 137 | } else { \ |
| 138 | err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ |
| 139 | err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ |
| 140 | } \ |
| 141 | err |= put_user((k)->c_ispeed, &(u)->c_ispeed); \ |
| 142 | err |= put_user((k)->c_ospeed, &(u)->c_ospeed); \ |
| 143 | err; \ |
| 144 | }) |
| 145 | |
| 146 | #define user_termios_to_kernel_termios_1(k, u) \ |
| 147 | ({ \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 148 | int err; \ |
| 149 | err = get_user((k)->c_iflag, &(u)->c_iflag); \ |
| 150 | err |= get_user((k)->c_oflag, &(u)->c_oflag); \ |
| 151 | err |= get_user((k)->c_cflag, &(u)->c_cflag); \ |
| 152 | err |= get_user((k)->c_lflag, &(u)->c_lflag); \ |
| 153 | err |= get_user((k)->c_line, &(u)->c_line); \ |
| 154 | err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \ |
David Miller | 6050afb | 2007-10-17 19:38:10 -0700 | [diff] [blame] | 155 | if ((k)->c_lflag & ICANON) { \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 156 | err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ |
| 157 | err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } else { \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 159 | err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ |
| 160 | err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 162 | err; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | }) |
| 164 | |
David Miller | 6050afb | 2007-10-17 19:38:10 -0700 | [diff] [blame] | 165 | #define kernel_termios_to_user_termios_1(u, k) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | ({ \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 167 | int err; \ |
| 168 | err = put_user((k)->c_iflag, &(u)->c_iflag); \ |
| 169 | err |= put_user((k)->c_oflag, &(u)->c_oflag); \ |
| 170 | err |= put_user((k)->c_cflag, &(u)->c_cflag); \ |
| 171 | err |= put_user((k)->c_lflag, &(u)->c_lflag); \ |
| 172 | err |= put_user((k)->c_line, &(u)->c_line); \ |
| 173 | err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \ |
David Miller | 6050afb | 2007-10-17 19:38:10 -0700 | [diff] [blame] | 174 | if (!((k)->c_lflag & ICANON)) { \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 175 | err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \ |
| 176 | err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } else { \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 178 | err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \ |
| 179 | err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } \ |
Sam Ravnborg | c6d1b0e | 2008-06-06 21:27:54 +0200 | [diff] [blame] | 181 | err; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | }) |
| 183 | |
| 184 | #endif /* __KERNEL__ */ |
| 185 | |
| 186 | #endif /* _SPARC_TERMIOS_H */ |