Commit ecbbfd44 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

TTY: move tty buffers to tty_port

So this is it. The big step why we did all the work over the past
kernel releases. Now everything is prepared, so nothing protects us
from doing that big step.

           |  |            \  \ nnnn/^l      |  |
           |  |             \  /     /       |  |
           |  '-,.__   =>    \/   ,-`    =>  |  '-,.__
           | O __.´´)        (  .`           | O __.´´)
            ~~~   ~~          ``              ~~~   ~~
The buffers are now in the tty_port structure and we can start
teaching the buffer helpers (insert char/string, flip etc.) to use
tty_port instead of tty_struct all around.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Acked-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 967fab69
...@@ -149,8 +149,11 @@ static void n_tty_set_room(struct tty_struct *tty) ...@@ -149,8 +149,11 @@ static void n_tty_set_room(struct tty_struct *tty)
tty->receive_room = left; tty->receive_room = left;
/* Did this open up the receive buffer? We may need to flip */ /* Did this open up the receive buffer? We may need to flip */
if (left && !old_left) if (left && !old_left) {
schedule_work(&tty->buf.work); WARN_RATELIMIT(tty->port->itty == NULL,
"scheduling with invalid itty");
schedule_work(&tty->port->buf.work);
}
} }
static void put_tty_queue_nolock(unsigned char c, struct n_tty_data *ldata) static void put_tty_queue_nolock(unsigned char c, struct n_tty_data *ldata)
......
...@@ -93,7 +93,7 @@ static void pty_unthrottle(struct tty_struct *tty) ...@@ -93,7 +93,7 @@ static void pty_unthrottle(struct tty_struct *tty)
static int pty_space(struct tty_struct *to) static int pty_space(struct tty_struct *to)
{ {
int n = 8192 - to->buf.memory_used; int n = 8192 - to->port->buf.memory_used;
if (n < 0) if (n < 0)
return 0; return 0;
return n; return n;
......
This diff is collapsed.
...@@ -186,7 +186,6 @@ void free_tty_struct(struct tty_struct *tty) ...@@ -186,7 +186,6 @@ void free_tty_struct(struct tty_struct *tty)
if (tty->dev) if (tty->dev)
put_device(tty->dev); put_device(tty->dev);
kfree(tty->write_buf); kfree(tty->write_buf);
tty_buffer_free_all(tty);
tty->magic = 0xDEADDEAD; tty->magic = 0xDEADDEAD;
kfree(tty); kfree(tty);
} }
...@@ -2935,7 +2934,6 @@ void initialize_tty_struct(struct tty_struct *tty, ...@@ -2935,7 +2934,6 @@ void initialize_tty_struct(struct tty_struct *tty,
tty_ldisc_init(tty); tty_ldisc_init(tty);
tty->session = NULL; tty->session = NULL;
tty->pgrp = NULL; tty->pgrp = NULL;
tty_buffer_init(tty);
mutex_init(&tty->legacy_mutex); mutex_init(&tty->legacy_mutex);
mutex_init(&tty->termios_mutex); mutex_init(&tty->termios_mutex);
mutex_init(&tty->ldisc_mutex); mutex_init(&tty->ldisc_mutex);
......
...@@ -512,7 +512,7 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) ...@@ -512,7 +512,7 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
static int tty_ldisc_halt(struct tty_struct *tty) static int tty_ldisc_halt(struct tty_struct *tty)
{ {
clear_bit(TTY_LDISC, &tty->flags); clear_bit(TTY_LDISC, &tty->flags);
return cancel_work_sync(&tty->buf.work); return cancel_work_sync(&tty->port->buf.work);
} }
/** /**
...@@ -525,7 +525,7 @@ static void tty_ldisc_flush_works(struct tty_struct *tty) ...@@ -525,7 +525,7 @@ static void tty_ldisc_flush_works(struct tty_struct *tty)
{ {
flush_work(&tty->hangup_work); flush_work(&tty->hangup_work);
flush_work(&tty->SAK_work); flush_work(&tty->SAK_work);
flush_work(&tty->buf.work); flush_work(&tty->port->buf.work);
} }
/** /**
...@@ -704,9 +704,9 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) ...@@ -704,9 +704,9 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
/* Restart the work queue in case no characters kick it off. Safe if /* Restart the work queue in case no characters kick it off. Safe if
already running */ already running */
if (work) if (work)
schedule_work(&tty->buf.work); schedule_work(&tty->port->buf.work);
if (o_work) if (o_work)
schedule_work(&o_tty->buf.work); schedule_work(&o_tty->port->buf.work);
mutex_unlock(&tty->ldisc_mutex); mutex_unlock(&tty->ldisc_mutex);
tty_unlock(tty); tty_unlock(tty);
return retval; return retval;
...@@ -817,7 +817,7 @@ void tty_ldisc_hangup(struct tty_struct *tty) ...@@ -817,7 +817,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
*/ */
clear_bit(TTY_LDISC, &tty->flags); clear_bit(TTY_LDISC, &tty->flags);
tty_unlock(tty); tty_unlock(tty);
cancel_work_sync(&tty->buf.work); cancel_work_sync(&tty->port->buf.work);
mutex_unlock(&tty->ldisc_mutex); mutex_unlock(&tty->ldisc_mutex);
retry: retry:
tty_lock(tty); tty_lock(tty);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
void tty_port_init(struct tty_port *port) void tty_port_init(struct tty_port *port)
{ {
memset(port, 0, sizeof(*port)); memset(port, 0, sizeof(*port));
tty_buffer_init(port);
init_waitqueue_head(&port->open_wait); init_waitqueue_head(&port->open_wait);
init_waitqueue_head(&port->close_wait); init_waitqueue_head(&port->close_wait);
init_waitqueue_head(&port->delta_msr_wait); init_waitqueue_head(&port->delta_msr_wait);
...@@ -126,6 +127,7 @@ static void tty_port_destructor(struct kref *kref) ...@@ -126,6 +127,7 @@ static void tty_port_destructor(struct kref *kref)
struct tty_port *port = container_of(kref, struct tty_port, kref); struct tty_port *port = container_of(kref, struct tty_port, kref);
if (port->xmit_buf) if (port->xmit_buf)
free_page((unsigned long)port->xmit_buf); free_page((unsigned long)port->xmit_buf);
tty_buffer_free_all(port);
if (port->ops->destruct) if (port->ops->destruct)
port->ops->destruct(port); port->ops->destruct(port);
else else
......
...@@ -188,6 +188,7 @@ struct tty_port_operations { ...@@ -188,6 +188,7 @@ struct tty_port_operations {
}; };
struct tty_port { struct tty_port {
struct tty_bufhead buf; /* Locked internally */
struct tty_struct *tty; /* Back pointer */ struct tty_struct *tty; /* Back pointer */
struct tty_struct *itty; /* internal back ptr */ struct tty_struct *itty; /* internal back ptr */
const struct tty_port_operations *ops; /* Port operations */ const struct tty_port_operations *ops; /* Port operations */
...@@ -259,7 +260,6 @@ struct tty_struct { ...@@ -259,7 +260,6 @@ struct tty_struct {
struct tty_struct *link; struct tty_struct *link;
struct fasync_struct *fasync; struct fasync_struct *fasync;
struct tty_bufhead buf; /* Locked internally */
int alt_speed; /* For magic substitution of 38400 bps */ int alt_speed; /* For magic substitution of 38400 bps */
wait_queue_head_t write_wait; wait_queue_head_t write_wait;
wait_queue_head_t read_wait; wait_queue_head_t read_wait;
...@@ -388,9 +388,9 @@ extern void disassociate_ctty(int priv); ...@@ -388,9 +388,9 @@ extern void disassociate_ctty(int priv);
extern void no_tty(void); extern void no_tty(void);
extern void tty_flip_buffer_push(struct tty_struct *tty); extern void tty_flip_buffer_push(struct tty_struct *tty);
extern void tty_flush_to_ldisc(struct tty_struct *tty); extern void tty_flush_to_ldisc(struct tty_struct *tty);
extern void tty_buffer_free_all(struct tty_struct *tty); extern void tty_buffer_free_all(struct tty_port *port);
extern void tty_buffer_flush(struct tty_struct *tty); extern void tty_buffer_flush(struct tty_struct *tty);
extern void tty_buffer_init(struct tty_struct *tty); extern void tty_buffer_init(struct tty_port *port);
extern speed_t tty_get_baud_rate(struct tty_struct *tty); extern speed_t tty_get_baud_rate(struct tty_struct *tty);
extern speed_t tty_termios_baud_rate(struct ktermios *termios); extern speed_t tty_termios_baud_rate(struct ktermios *termios);
extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); extern speed_t tty_termios_input_baud_rate(struct ktermios *termios);
......
...@@ -11,7 +11,7 @@ void tty_schedule_flip(struct tty_struct *tty); ...@@ -11,7 +11,7 @@ void tty_schedule_flip(struct tty_struct *tty);
static inline int tty_insert_flip_char(struct tty_struct *tty, static inline int tty_insert_flip_char(struct tty_struct *tty,
unsigned char ch, char flag) unsigned char ch, char flag)
{ {
struct tty_buffer *tb = tty->buf.tail; struct tty_buffer *tb = tty->port->buf.tail;
if (tb && tb->used < tb->size) { if (tb && tb->used < tb->size) {
tb->flag_buf_ptr[tb->used] = flag; tb->flag_buf_ptr[tb->used] = flag;
tb->char_buf_ptr[tb->used++] = ch; tb->char_buf_ptr[tb->used++] = ch;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment