* [PATCH 02/10] TTY: serial, cleanup atmel_set_ldisc
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-15 9:01 ` Nicolas Ferre
2011-11-09 20:33 ` [PATCH 03/10] TTY: serial, switch closing_wait and close_delay to jiffies Jiri Slaby
` (8 subsequent siblings)
9 siblings, 1 reply; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, linux-serial, jirislaby, Alan Cox, Viktar Palstsiuk,
Nicolas Ferre, Jean-Christophe PLAGNIOL-VILLARD
Current ldisc number is passed as a paramneter -- no need to dig it
out of the tty or ldisc. So switch PPS check to that.
No tty callback can be called with port->line higher than TTY driver
num. So remove the check.
This removes some port.tty users.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
Cc: Viktar Palstsiuk <viktar.palstsiuk@promwad.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/tty/serial/atmel_serial.c | 7 +------
1 files changed, 1 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 4a0f86f..6b844d4 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1256,12 +1256,7 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
static void atmel_set_ldisc(struct uart_port *port, int new)
{
- int line = port->line;
-
- if (line >= port->state->port.tty->driver->num)
- return;
-
- if (port->state->port.tty->ldisc->ops->num == N_PPS) {
+ if (new == N_PPS) {
port->flags |= UPF_HARDPPS_CD;
atmel_enable_ms(port);
} else {
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 02/10] TTY: serial, cleanup atmel_set_ldisc
2011-11-09 20:33 ` [PATCH 02/10] TTY: serial, cleanup atmel_set_ldisc Jiri Slaby
@ 2011-11-15 9:01 ` Nicolas Ferre
0 siblings, 0 replies; 14+ messages in thread
From: Nicolas Ferre @ 2011-11-15 9:01 UTC (permalink / raw)
To: Jiri Slaby
Cc: gregkh, linux-kernel, linux-serial, jirislaby, Alan Cox,
Viktar Palstsiuk, Jean-Christophe PLAGNIOL-VILLARD
On 11/09/2011 09:33 PM, Jiri Slaby :
> Current ldisc number is passed as a paramneter -- no need to dig it
> out of the tty or ldisc. So switch PPS check to that.
>
> No tty callback can be called with port->line higher than TTY driver
> num. So remove the check.
>
> This removes some port.tty users.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Greg Kroah-Hartman <gregkh@suse.de>
> Cc: Alan Cox <alan@linux.intel.com>
> Cc: Viktar Palstsiuk <viktar.palstsiuk@promwad.com>
> Cc: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> drivers/tty/serial/atmel_serial.c | 7 +------
> 1 files changed, 1 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index 4a0f86f..6b844d4 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -1256,12 +1256,7 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
>
> static void atmel_set_ldisc(struct uart_port *port, int new)
> {
> - int line = port->line;
> -
> - if (line >= port->state->port.tty->driver->num)
> - return;
> -
> - if (port->state->port.tty->ldisc->ops->num == N_PPS) {
> + if (new == N_PPS) {
> port->flags |= UPF_HARDPPS_CD;
> atmel_enable_ms(port);
> } else {
--
Nicolas Ferre
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 03/10] TTY: serial, switch closing_wait and close_delay to jiffies
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
2011-11-09 20:33 ` [PATCH 02/10] TTY: serial, cleanup atmel_set_ldisc Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:33 ` [PATCH 04/10] TTY: serial, use tty_port_close_start helper Jiri Slaby
` (7 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
As the tty_port helpers think closing_wait and close_delay are in
jiffies and we want to use the helpers (next patches), we have to
switch the closing_wait and close_delay from ms to jiffies now.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 8d825a3..2b1ee7c 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -659,10 +659,10 @@ static int uart_get_info(struct uart_state *state,
tmp.flags = uport->flags;
tmp.xmit_fifo_size = uport->fifosize;
tmp.baud_base = uport->uartclk / 16;
- tmp.close_delay = port->close_delay / 10;
+ tmp.close_delay = jiffies_to_msecs(port->close_delay) / 10;
tmp.closing_wait = port->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
ASYNC_CLOSING_WAIT_NONE :
- port->closing_wait / 10;
+ jiffies_to_msecs(port->closing_wait) / 10;
tmp.custom_divisor = uport->custom_divisor;
tmp.hub6 = uport->hub6;
tmp.io_type = uport->iotype;
@@ -696,9 +696,10 @@ static int uart_set_info(struct tty_struct *tty, struct uart_state *state,
new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
new_serial.irq = irq_canonicalize(new_serial.irq);
- close_delay = new_serial.close_delay * 10;
+ close_delay = msecs_to_jiffies(new_serial.close_delay * 10);
closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
- ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
+ ASYNC_CLOSING_WAIT_NONE :
+ msecs_to_jiffies(new_serial.closing_wait * 10);
/*
* This semaphore protects port->count. It is also
@@ -1305,8 +1306,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
spin_unlock_irqrestore(&port->lock, flags);
if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
- tty_wait_until_sent_from_close(tty,
- msecs_to_jiffies(port->closing_wait));
+ tty_wait_until_sent_from_close(tty, port->closing_wait);
/*
* At this point, we stop accepting input. To do this, we
@@ -1338,7 +1338,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
if (port->blocked_open) {
spin_unlock_irqrestore(&port->lock, flags);
if (port->close_delay)
- msleep_interruptible(port->close_delay);
+ msleep_interruptible(
+ jiffies_to_msecs(port->close_delay));
spin_lock_irqsave(&port->lock, flags);
} else if (!uart_console(uport)) {
spin_unlock_irqrestore(&port->lock, flags);
@@ -2276,8 +2277,8 @@ int uart_register_driver(struct uart_driver *drv)
tty_port_init(port);
port->ops = &uart_port_ops;
- port->close_delay = 500; /* .5 seconds */
- port->closing_wait = 30000; /* 30 seconds */
+ port->close_delay = HZ / 2; /* .5 seconds */
+ port->closing_wait = 30 * HZ;/* 30 seconds */
}
retval = tty_register_driver(normal);
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 04/10] TTY: serial, use tty_port_close_start helper
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
2011-11-09 20:33 ` [PATCH 02/10] TTY: serial, cleanup atmel_set_ldisc Jiri Slaby
2011-11-09 20:33 ` [PATCH 03/10] TTY: serial, switch closing_wait and close_delay to jiffies Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:33 ` [PATCH 05/10] TTY: serial, document few functions Jiri Slaby
` (6 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
After the previous patches, the code is almost identical. There are
few differences in the helper code:
1) flush_buffer when flow_stopped
* when a user doesn't care about the data, delete it anyways
2) ASYNCB_INITIALIZED test before wait_until_sent_from
* obviously, there is nothing to wait for if the port is dead
3) drain_delay wait
* we don't set drain_delay
So we can use the helper now. It indeed removes a bunch of duplicated
code.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 40 +-------------------------------------
1 files changed, 1 insertions(+), 39 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 2b1ee7c..fcb5342 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1267,46 +1267,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
pr_debug("uart_close(%d) called\n", uport->line);
- spin_lock_irqsave(&port->lock, flags);
-
- if (tty_hung_up_p(filp)) {
- spin_unlock_irqrestore(&port->lock, flags);
+ if (tty_port_close_start(port, tty, filp) == 0)
return;
- }
-
- if ((tty->count == 1) && (port->count != 1)) {
- /*
- * Uh, oh. tty->count is 1, which means that the tty
- * structure will be freed. port->count should always
- * be one in these conditions. If it's greater than
- * one, we've got real problems, since it means the
- * serial port won't be shutdown.
- */
- printk(KERN_ERR "uart_close: bad serial port count; tty->count is 1, "
- "port->count is %d\n", port->count);
- port->count = 1;
- }
- if (--port->count < 0) {
- printk(KERN_ERR "uart_close: bad serial port count for %s: %d\n",
- tty->name, port->count);
- port->count = 0;
- }
- if (port->count) {
- spin_unlock_irqrestore(&port->lock, flags);
- return;
- }
-
- /*
- * Now we wait for the transmit buffer to clear; and we notify
- * the line discipline to only process XON/XOFF characters by
- * setting tty->closing.
- */
- set_bit(ASYNCB_CLOSING, &port->flags);
- tty->closing = 1;
- spin_unlock_irqrestore(&port->lock, flags);
-
- if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
- tty_wait_until_sent_from_close(tty, port->closing_wait);
/*
* At this point, we stop accepting input. To do this, we
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 05/10] TTY: serial, document few functions
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (2 preceding siblings ...)
2011-11-09 20:33 ` [PATCH 04/10] TTY: serial, use tty_port_close_start helper Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:33 ` [PATCH 06/10] TTY: serial, do not touch tty->alt_speed Jiri Slaby
` (5 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
Just put a kernel-doc comment to uart_change_pm and uart_insert_char.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index fcb5342..036e0cc 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1822,6 +1822,14 @@ uart_set_options(struct uart_port *port, struct console *co,
EXPORT_SYMBOL_GPL(uart_set_options);
#endif /* CONFIG_SERIAL_CORE_CONSOLE */
+/**
+ * uart_change_pm - set power state of the port
+ *
+ * @state: port descriptor
+ * @pm_state: new state
+ *
+ * Locking: port->mutex has to be held
+ */
static void uart_change_pm(struct uart_state *state, int pm_state)
{
struct uart_port *port = state->uart_port;
@@ -2495,6 +2503,18 @@ void uart_handle_cts_change(struct uart_port *uport, unsigned int status)
}
EXPORT_SYMBOL_GPL(uart_handle_cts_change);
+/**
+ * uart_insert_char - push a char to the uart layer
+ *
+ * User is responsible to call tty_flip_buffer_push when they are done with
+ * insertion.
+ *
+ * @port: corresponding port
+ * @status: state of the serial port RX buffer (LSR for 8250)
+ * @overrun: mask of overrun bits in @status
+ * @ch: character to push
+ * @flag: flag for the character (see TTY_NORMAL and friends)
+ */
void uart_insert_char(struct uart_port *port, unsigned int status,
unsigned int overrun, unsigned int ch, unsigned int flag)
{
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 06/10] TTY: serial, do not touch tty->alt_speed
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (3 preceding siblings ...)
2011-11-09 20:33 ` [PATCH 05/10] TTY: serial, document few functions Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:33 ` [PATCH 07/10] TTY: serial, inline uart_get Jiri Slaby
` (4 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
It is not used at all, so no need to play any games with that.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 036e0cc..4b1dcd3 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -141,8 +141,7 @@ static int uart_startup(struct tty_struct *tty, struct uart_state *state, int in
/*
* Set the TTY IO error marker - we will only clear this
- * once we have successfully opened the port. Also set
- * up the tty->alt_speed kludge
+ * once we have successfully opened the port.
*/
set_bit(TTY_IO_ERROR, &tty->flags);
@@ -1499,7 +1498,6 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
tty->driver_data = state;
state->uart_port->state = state;
tty->low_latency = (state->uart_port->flags & UPF_LOW_LATENCY) ? 1 : 0;
- tty->alt_speed = 0;
tty_port_tty_set(port, tty);
/*
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 07/10] TTY: serial, inline uart_get
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (4 preceding siblings ...)
2011-11-09 20:33 ` [PATCH 06/10] TTY: serial, do not touch tty->alt_speed Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:33 ` [PATCH 08/10] TTY: serial, define uart_port_activate/shutdown Jiri Slaby
` (3 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
We need to expand uart_get into uart_open. We need it to move on with
conversion to use tty_port_open helper. After we do this, the code
will be much more similar to what tty_port_open does.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 66 ++++++++++++-------------------------
1 files changed, 22 insertions(+), 44 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 4b1dcd3..2ca4df4 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1429,33 +1429,6 @@ static void uart_dtr_rts(struct tty_port *port, int onoff)
uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
}
-static struct uart_state *uart_get(struct uart_driver *drv, int line)
-{
- struct uart_state *state;
- struct tty_port *port;
- int ret = 0;
-
- state = drv->state + line;
- port = &state->port;
- if (mutex_lock_interruptible(&port->mutex)) {
- ret = -ERESTARTSYS;
- goto err;
- }
-
- port->count++;
- if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
- ret = -ENXIO;
- goto err_unlock;
- }
- return state;
-
- err_unlock:
- port->count--;
- mutex_unlock(&port->mutex);
- err:
- return ERR_PTR(ret);
-}
-
/*
* calls to uart_open are serialised by the BKL in
* fs/char_dev.c:chrdev_open()
@@ -1469,26 +1442,29 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line)
static int uart_open(struct tty_struct *tty, struct file *filp)
{
struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state;
- struct uart_state *state;
- struct tty_port *port;
int retval, line = tty->index;
+ struct uart_state *state = drv->state + line;
+ struct tty_port *port = &state->port;
pr_debug("uart_open(%d) called\n", line);
/*
- * We take the semaphore inside uart_get to guarantee that we won't
- * be re-entered while allocating the state structure, or while we
- * request any IRQs that the driver may need. This also has the nice
- * side-effect that it delays the action of uart_hangup, so we can
- * guarantee that state->port.tty will always contain something
- * reasonable.
+ * We take the semaphore here to guarantee that we won't be re-entered
+ * while allocating the state structure, or while we request any IRQs
+ * that the driver may need. This also has the nice side-effect that
+ * it delays the action of uart_hangup, so we can guarantee that
+ * state->port.tty will always contain something reasonable.
*/
- state = uart_get(drv, line);
- if (IS_ERR(state)) {
- retval = PTR_ERR(state);
- goto fail;
+ if (mutex_lock_interruptible(&port->mutex)) {
+ retval = -ERESTARTSYS;
+ goto end;
+ }
+
+ port->count++;
+ if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
+ retval = -ENXIO;
+ goto err_dec_count;
}
- port = &state->port;
/*
* Once we set tty->driver_data here, we are guaranteed that
@@ -1505,9 +1481,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
*/
if (tty_hung_up_p(filp)) {
retval = -EAGAIN;
- port->count--;
- mutex_unlock(&port->mutex);
- goto fail;
+ goto err_dec_count;
}
/*
@@ -1528,8 +1502,12 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
if (retval == 0)
retval = tty_port_block_til_ready(port, tty, filp);
-fail:
+end:
return retval;
+err_dec_count:
+ port->count--;
+ mutex_unlock(&port->mutex);
+ goto end;
}
static const char *uart_type(struct uart_port *port)
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 08/10] TTY: serial, define uart_port_activate/shutdown
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (5 preceding siblings ...)
2011-11-09 20:33 ` [PATCH 07/10] TTY: serial, inline uart_get Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:33 ` [PATCH 09/10] TTY: serial, fill uart_port_shutdown Jiri Slaby
` (2 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
This is a preparation for the next patches which will move the stuff
from uart_open and uart_close/hangup here. Then we will use
tty_port_* helpers.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 2ca4df4..d7e8a5e 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1404,6 +1404,15 @@ static void uart_hangup(struct tty_struct *tty)
mutex_unlock(&port->mutex);
}
+static int uart_port_activate(struct tty_port *port, struct tty_struct *tty)
+{
+ return 0;
+}
+
+static void uart_port_shutdown(struct tty_port *port)
+{
+}
+
static int uart_carrier_raised(struct tty_port *port)
{
struct uart_state *state = container_of(port, struct uart_state, port);
@@ -2162,6 +2171,8 @@ static const struct tty_operations uart_ops = {
};
static const struct tty_port_operations uart_port_ops = {
+ .activate = uart_port_activate,
+ .shutdown = uart_port_shutdown,
.carrier_raised = uart_carrier_raised,
.dtr_rts = uart_dtr_rts,
};
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 09/10] TTY: serial, fill uart_port_shutdown
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (6 preceding siblings ...)
2011-11-09 20:33 ` [PATCH 08/10] TTY: serial, define uart_port_activate/shutdown Jiri Slaby
@ 2011-11-09 20:33 ` Jiri Slaby
2011-11-09 20:34 ` [PATCH 10/10] TTY: serial, extract uart_port_startup Jiri Slaby
2011-11-09 21:59 ` [PATCH 01/10] TTY: serial, cleanup include file Alan Cox
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:33 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
Let's fill the port_ops->shutdown. We will need this for hangup and
close port helpers.
We don't need to touch DTR/RTS registers in uart_port_shutdown. They
are set to off from port_close_start properly already.
Also we don't need to pin the TTY_IO_ERROR bit. This will be done in
close/hangup paths.
We leave uart_shutdown as is, because it is used (and will be) from
several paths now. Like from suspend.
The point is to not touch ASYNC_INITIALIZED bit. It will be set (and
checked) properly by the tty port helpers.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 42 +++++++++++++++++++++----------------
1 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index d7e8a5e..68763c0 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -61,6 +61,8 @@ static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
static void uart_change_pm(struct uart_state *state, int pm_state);
+static void uart_port_shutdown(struct tty_port *port);
+
/*
* This routine is used by the interrupt handler to schedule processing in
* the software interrupt portion of the driver.
@@ -228,24 +230,7 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
if (!tty || (tty->termios->c_cflag & HUPCL))
uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
- /*
- * clear delta_msr_wait queue to avoid mem leaks: we may free
- * the irq here so the queue might never be woken up. Note
- * that we won't end up waiting on delta_msr_wait again since
- * any outstanding file descriptors should be pointing at
- * hung_up_tty_fops now.
- */
- wake_up_interruptible(&port->delta_msr_wait);
-
- /*
- * Free the IRQ and disable the port.
- */
- uport->ops->shutdown(uport);
-
- /*
- * Ensure that the IRQ handler isn't running on another CPU.
- */
- synchronize_irq(uport->irq);
+ uart_port_shutdown(port);
}
/*
@@ -1411,6 +1396,27 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty)
static void uart_port_shutdown(struct tty_port *port)
{
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
+
+ /*
+ * clear delta_msr_wait queue to avoid mem leaks: we may free
+ * the irq here so the queue might never be woken up. Note
+ * that we won't end up waiting on delta_msr_wait again since
+ * any outstanding file descriptors should be pointing at
+ * hung_up_tty_fops now.
+ */
+ wake_up_interruptible(&port->delta_msr_wait);
+
+ /*
+ * Free the IRQ and disable the port.
+ */
+ uport->ops->shutdown(uport);
+
+ /*
+ * Ensure that the IRQ handler isn't running on another CPU.
+ */
+ synchronize_irq(uport->irq);
}
static int uart_carrier_raised(struct tty_port *port)
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 10/10] TTY: serial, extract uart_port_startup
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (7 preceding siblings ...)
2011-11-09 20:33 ` [PATCH 09/10] TTY: serial, fill uart_port_shutdown Jiri Slaby
@ 2011-11-09 20:34 ` Jiri Slaby
2011-11-09 21:59 ` [PATCH 01/10] TTY: serial, cleanup include file Alan Cox
9 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 20:34 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, linux-serial, jirislaby, Alan Cox
Extract ASYNC_INITIALIZED/TTY_IO_ERROR handling from uart_startup.
This will be useful for tty port helpers. These flags are handled
by the helpers instead.
So we create a new function uart_port_startup without touching these
flags there. And we keep uart_startup with the exact behavior as
before. We need that one because we start/stop the device from other
paths than open/close/hangup.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@linux.intel.com>
---
drivers/tty/serial/serial_core.c | 43 ++++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 68763c0..d2990f7 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -131,24 +131,16 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
* Startup the port. This will be called once per open. All calls
* will be serialised by the per-port mutex.
*/
-static int uart_startup(struct tty_struct *tty, struct uart_state *state, int init_hw)
+static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
+ int init_hw)
{
struct uart_port *uport = state->uart_port;
struct tty_port *port = &state->port;
unsigned long page;
int retval = 0;
- if (port->flags & ASYNC_INITIALIZED)
- return 0;
-
- /*
- * Set the TTY IO error marker - we will only clear this
- * once we have successfully opened the port.
- */
- set_bit(TTY_IO_ERROR, &tty->flags);
-
if (uport->type == PORT_UNKNOWN)
- return 0;
+ return 1;
/*
* Initialise and allocate the transmit and temporary
@@ -190,10 +182,6 @@ static int uart_startup(struct tty_struct *tty, struct uart_state *state, int in
tty->hw_stopped = 1;
spin_unlock_irq(&uport->lock);
}
-
- set_bit(ASYNCB_INITIALIZED, &port->flags);
-
- clear_bit(TTY_IO_ERROR, &tty->flags);
}
/*
@@ -202,6 +190,31 @@ static int uart_startup(struct tty_struct *tty, struct uart_state *state, int in
* now.
*/
if (retval && capable(CAP_SYS_ADMIN))
+ return 1;
+
+ return retval;
+}
+
+static int uart_startup(struct tty_struct *tty, struct uart_state *state,
+ int init_hw)
+{
+ struct tty_port *port = &state->port;
+ int retval;
+
+ if (port->flags & ASYNC_INITIALIZED)
+ return 0;
+
+ /*
+ * Set the TTY IO error marker - we will only clear this
+ * once we have successfully opened the port.
+ */
+ set_bit(TTY_IO_ERROR, &tty->flags);
+
+ retval = uart_port_startup(tty, state, init_hw);
+ if (!retval) {
+ set_bit(ASYNCB_INITIALIZED, &port->flags);
+ clear_bit(TTY_IO_ERROR, &tty->flags);
+ } else if (retval > 0)
retval = 0;
return retval;
--
1.7.7
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 01/10] TTY: serial, cleanup include file
2011-11-09 20:33 [PATCH 01/10] TTY: serial, cleanup include file Jiri Slaby
` (8 preceding siblings ...)
2011-11-09 20:34 ` [PATCH 10/10] TTY: serial, extract uart_port_startup Jiri Slaby
@ 2011-11-09 21:59 ` Alan Cox
2011-11-09 22:09 ` Jiri Slaby
9 siblings, 1 reply; 14+ messages in thread
From: Alan Cox @ 2011-11-09 21:59 UTC (permalink / raw)
To: Jiri Slaby; +Cc: gregkh, linux-kernel, linux-serial, jirislaby
> ...instead of taking and dropping a reference in both uart_insert_char
> and uart_push_chars there. But it may be as well an overkill, as this
> stuff is not time critical. So any opinions? (If not I will proceed
> without ticketing having tty_port_tty_get/put in every call. Like I
> have it now.)
The cure for this is different (and a spot more invasive)
We need to move the tty_buffer objects into the tty_port. At that point
the lifetime becomes
create device (and tty_port struct)
request_irq
lifetime of physical port (ttys come and go)
free_irq
free tty_port
done
and the locking goes away. On the flush_to_ldisc side we know the port
physically exists because the work queue for the ldisc is killed and we
wait for it when we kill off the port (we may need a spot more checking
there)
This needs every tty of all kinds to have a tty_port even if isn't used
for anything else. That also cleans a ton of stuff up because then we
can always put the tty_port in tty->private_data which means we can
clean up some of the glue further.
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 01/10] TTY: serial, cleanup include file
2011-11-09 21:59 ` [PATCH 01/10] TTY: serial, cleanup include file Alan Cox
@ 2011-11-09 22:09 ` Jiri Slaby
2011-11-09 23:25 ` Alan Cox
0 siblings, 1 reply; 14+ messages in thread
From: Jiri Slaby @ 2011-11-09 22:09 UTC (permalink / raw)
To: Alan Cox; +Cc: Jiri Slaby, gregkh, linux-kernel, linux-serial
On 11/09/2011 10:59 PM, Alan Cox wrote:
> We need to move the tty_buffer objects into the tty_port.
Thanks a lot for reminding me. (I remember you telling me about this at
KS.) So I suppose you prefer this to be done first... OK, I will look
into that. Leaving the rest of the serial stuff apart for the time being.
> This needs every tty of all kinds to have a tty_port even if isn't used
> for anything else.
Heh, out-of-tree driver maintainers will cry once again. It serves them
right.
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 01/10] TTY: serial, cleanup include file
2011-11-09 22:09 ` Jiri Slaby
@ 2011-11-09 23:25 ` Alan Cox
0 siblings, 0 replies; 14+ messages in thread
From: Alan Cox @ 2011-11-09 23:25 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Jiri Slaby, gregkh, linux-kernel, linux-serial
On Wed, 09 Nov 2011 23:09:07 +0100
Jiri Slaby <jslaby@suse.cz> wrote:
> On 11/09/2011 10:59 PM, Alan Cox wrote:
> > We need to move the tty_buffer objects into the tty_port.
>
> Thanks a lot for reminding me. (I remember you telling me about this
> at KS.) So I suppose you prefer this to be done first... OK, I will
> look into that. Leaving the rest of the serial stuff apart for the
> time being.
I'm not really bothered what is done first - it's not as if I am doing
the work! I just thought it might be easier to do it that way around
rather than adding and removing more complexity on the way ?
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread