Lines Matching refs:tty
30 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args) argument
32 # define tty_debug_hangup(tty, f, args...) do {} while (0) argument
41 static void pty_close(struct tty_struct *tty, struct file *filp) in pty_close() argument
43 BUG_ON(!tty); in pty_close()
44 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_close()
45 WARN_ON(tty->count > 1); in pty_close()
47 if (test_bit(TTY_IO_ERROR, &tty->flags)) in pty_close()
49 if (tty->count > 2) in pty_close()
52 set_bit(TTY_IO_ERROR, &tty->flags); in pty_close()
53 wake_up_interruptible(&tty->read_wait); in pty_close()
54 wake_up_interruptible(&tty->write_wait); in pty_close()
55 spin_lock_irq(&tty->ctrl_lock); in pty_close()
56 tty->packet = 0; in pty_close()
57 spin_unlock_irq(&tty->ctrl_lock); in pty_close()
59 if (!tty->link) in pty_close()
61 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_close()
62 wake_up_interruptible(&tty->link->read_wait); in pty_close()
63 wake_up_interruptible(&tty->link->write_wait); in pty_close()
64 if (tty->driver->subtype == PTY_TYPE_MASTER) { in pty_close()
65 set_bit(TTY_OTHER_CLOSED, &tty->flags); in pty_close()
67 if (tty->driver == ptm_driver) { in pty_close()
69 if (tty->link->driver_data) in pty_close()
70 devpts_pty_kill(tty->link->driver_data); in pty_close()
74 tty_vhangup(tty->link); in pty_close()
88 static void pty_unthrottle(struct tty_struct *tty) in pty_unthrottle() argument
90 tty_wakeup(tty->link); in pty_unthrottle()
91 set_bit(TTY_THROTTLED, &tty->flags); in pty_unthrottle()
106 static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c) in pty_write() argument
108 struct tty_struct *to = tty->link; in pty_write()
110 if (tty->stopped) in pty_write()
131 static int pty_write_room(struct tty_struct *tty) in pty_write_room() argument
133 if (tty->stopped) in pty_write_room()
135 return tty_buffer_space_avail(tty->link->port); in pty_write_room()
146 static int pty_chars_in_buffer(struct tty_struct *tty) in pty_chars_in_buffer() argument
152 static int pty_set_lock(struct tty_struct *tty, int __user *arg) in pty_set_lock() argument
158 set_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
160 clear_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
164 static int pty_get_lock(struct tty_struct *tty, int __user *arg) in pty_get_lock() argument
166 int locked = test_bit(TTY_PTY_LOCK, &tty->flags); in pty_get_lock()
171 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg) in pty_set_pktmode() argument
178 spin_lock_irq(&tty->ctrl_lock); in pty_set_pktmode()
180 if (!tty->packet) { in pty_set_pktmode()
181 tty->link->ctrl_status = 0; in pty_set_pktmode()
183 tty->packet = 1; in pty_set_pktmode()
186 tty->packet = 0; in pty_set_pktmode()
187 spin_unlock_irq(&tty->ctrl_lock); in pty_set_pktmode()
193 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg) in pty_get_pktmode() argument
195 int pktmode = tty->packet; in pty_get_pktmode()
200 static int pty_signal(struct tty_struct *tty, int sig) in pty_signal() argument
207 if (tty->link) { in pty_signal()
208 pgrp = tty_get_pgrp(tty->link); in pty_signal()
216 static void pty_flush_buffer(struct tty_struct *tty) in pty_flush_buffer() argument
218 struct tty_struct *to = tty->link; in pty_flush_buffer()
230 spin_lock_irq(&tty->ctrl_lock); in pty_flush_buffer()
231 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; in pty_flush_buffer()
233 spin_unlock_irq(&tty->ctrl_lock); in pty_flush_buffer()
237 static int pty_open(struct tty_struct *tty, struct file *filp) in pty_open() argument
239 if (!tty || !tty->link) in pty_open()
242 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in pty_open()
244 if (test_bit(TTY_PTY_LOCK, &tty->link->flags)) in pty_open()
246 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1) in pty_open()
249 clear_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
250 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_open()
251 set_bit(TTY_THROTTLED, &tty->flags); in pty_open()
255 set_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
259 static void pty_set_termios(struct tty_struct *tty, in pty_set_termios() argument
263 if (tty->link && tty->link->packet) { in pty_set_termios()
265 (tty->termios.c_lflag & EXTPROC); in pty_set_termios()
269 int new_flow = (I_IXON(tty) && in pty_set_termios()
270 STOP_CHAR(tty) == '\023' && in pty_set_termios()
271 START_CHAR(tty) == '\021'); in pty_set_termios()
273 spin_lock_irq(&tty->ctrl_lock); in pty_set_termios()
275 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); in pty_set_termios()
277 tty->ctrl_status |= TIOCPKT_DOSTOP; in pty_set_termios()
279 tty->ctrl_status |= TIOCPKT_NOSTOP; in pty_set_termios()
282 tty->ctrl_status |= TIOCPKT_IOCTL; in pty_set_termios()
283 spin_unlock_irq(&tty->ctrl_lock); in pty_set_termios()
284 wake_up_interruptible(&tty->link->read_wait); in pty_set_termios()
288 tty->termios.c_cflag &= ~(CSIZE | PARENB); in pty_set_termios()
289 tty->termios.c_cflag |= (CS8 | CREAD); in pty_set_termios()
301 static int pty_resize(struct tty_struct *tty, struct winsize *ws) in pty_resize() argument
304 struct tty_struct *pty = tty->link; in pty_resize()
307 mutex_lock(&tty->winsize_mutex); in pty_resize()
308 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in pty_resize()
312 pgrp = tty_get_pgrp(tty); in pty_resize()
323 tty->winsize = *ws; in pty_resize()
326 mutex_unlock(&tty->winsize_mutex); in pty_resize()
340 static void pty_start(struct tty_struct *tty) in pty_start() argument
344 if (tty->link && tty->link->packet) { in pty_start()
345 spin_lock_irqsave(&tty->ctrl_lock, flags); in pty_start()
346 tty->ctrl_status &= ~TIOCPKT_STOP; in pty_start()
347 tty->ctrl_status |= TIOCPKT_START; in pty_start()
348 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in pty_start()
349 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN); in pty_start()
353 static void pty_stop(struct tty_struct *tty) in pty_stop() argument
357 if (tty->link && tty->link->packet) { in pty_stop()
358 spin_lock_irqsave(&tty->ctrl_lock, flags); in pty_stop()
359 tty->ctrl_status &= ~TIOCPKT_START; in pty_stop()
360 tty->ctrl_status |= TIOCPKT_STOP; in pty_stop()
361 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in pty_stop()
362 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN); in pty_stop()
377 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, in pty_common_install() argument
382 int idx = tty->index; in pty_common_install()
407 retval = tty_init_termios(tty); in pty_common_install()
416 driver->ttys[idx] = tty; in pty_common_install()
418 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
419 tty->termios = driver->init_termios; in pty_common_install()
420 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
429 tty->link = o_tty; in pty_common_install()
430 o_tty->link = tty; in pty_common_install()
436 tty->port = ports[1]; in pty_common_install()
442 tty->count++; in pty_common_install()
447 tty_free_termios(tty); in pty_common_install()
459 static void pty_cleanup(struct tty_struct *tty) in pty_cleanup() argument
461 tty_port_put(tty->port); in pty_cleanup()
467 static int pty_install(struct tty_driver *driver, struct tty_struct *tty) in pty_install() argument
469 return pty_common_install(driver, tty, true); in pty_install()
472 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_remove() argument
474 struct tty_struct *pair = tty->link; in pty_remove()
475 driver->ttys[tty->index] = NULL; in pty_remove()
480 static int pty_bsd_ioctl(struct tty_struct *tty, in pty_bsd_ioctl() argument
485 return pty_set_lock(tty, (int __user *) arg); in pty_bsd_ioctl()
487 return pty_get_lock(tty, (int __user *)arg); in pty_bsd_ioctl()
489 return pty_set_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
491 return pty_get_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
493 return pty_signal(tty, (int) arg); in pty_bsd_ioctl()
607 static int pty_unix98_ioctl(struct tty_struct *tty, in pty_unix98_ioctl() argument
612 return pty_set_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
614 return pty_get_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
616 return pty_set_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
618 return pty_get_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
620 return put_user(tty->index, (unsigned int __user *)arg); in pty_unix98_ioctl()
622 return pty_signal(tty, (int) arg); in pty_unix98_ioctl()
656 struct tty_struct *tty; in pts_unix98_lookup() local
659 tty = devpts_get_priv(pts_inode); in pts_unix98_lookup()
662 if (!tty) in pts_unix98_lookup()
664 return tty; in pts_unix98_lookup()
670 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_install() argument
672 return pty_common_install(driver, tty, false); in pty_unix98_install()
675 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_remove() argument
680 static void pty_unix98_shutdown(struct tty_struct *tty) in pty_unix98_shutdown() argument
684 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_unix98_shutdown()
685 ptmx_inode = tty->driver_data; in pty_unix98_shutdown()
687 ptmx_inode = tty->link->driver_data; in pty_unix98_shutdown()
688 devpts_kill_index(ptmx_inode, tty->index); in pty_unix98_shutdown()
741 struct tty_struct *tty; in ptmx_open() local
767 tty = tty_init_dev(ptm_driver, index); in ptmx_open()
769 if (IS_ERR(tty)) { in ptmx_open()
770 retval = PTR_ERR(tty); in ptmx_open()
778 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ in ptmx_open()
779 tty->driver_data = inode; in ptmx_open()
793 tty_add_file(tty, filp); in ptmx_open()
797 tty->link); in ptmx_open()
802 tty->link->driver_data = slave_inode; in ptmx_open()
804 retval = ptm_driver->ops->open(tty, filp); in ptmx_open()
808 tty_debug_hangup(tty, "(tty count=%d)\n", tty->count); in ptmx_open()
810 tty_unlock(tty); in ptmx_open()
813 tty_unlock(tty); in ptmx_open()