Skip to content

Commit ccce6de

Browse files
Alan CoxLive-CD User
authored andcommitted
serial: move the flags into the tty_port field
Fortunately the serial layer was designed to use the same flag values but with different names. It has its own SUSPENDED flag which is a free slot in the ASYNC flags so we allocate it in the ASYNC flags instead. Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 91312cd commit ccce6de

File tree

3 files changed

+98
-105
lines changed

3 files changed

+98
-105
lines changed

drivers/serial/serial_core.c

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#include <linux/console.h>
3030
#include <linux/proc_fs.h>
3131
#include <linux/seq_file.h>
32-
#include <linux/serial_core.h>
3332
#include <linux/smp_lock.h>
3433
#include <linux/device.h>
3534
#include <linux/serial.h> /* for serial_state and serial_icounter_struct */
35+
#include <linux/serial_core.h>
3636
#include <linux/delay.h>
3737
#include <linux/mutex.h>
3838

@@ -146,7 +146,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
146146
unsigned long page;
147147
int retval = 0;
148148

149-
if (state->flags & UIF_INITIALIZED)
149+
if (port->flags & ASYNC_INITIALIZED)
150150
return 0;
151151

152152
/*
@@ -189,14 +189,14 @@ static int uart_startup(struct uart_state *state, int init_hw)
189189
uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
190190
}
191191

192-
if (state->flags & UIF_CTS_FLOW) {
192+
if (port->flags & ASYNC_CTS_FLOW) {
193193
spin_lock_irq(&uport->lock);
194194
if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
195195
port->tty->hw_stopped = 1;
196196
spin_unlock_irq(&uport->lock);
197197
}
198198

199-
state->flags |= UIF_INITIALIZED;
199+
set_bit(ASYNCB_INITIALIZED, &port->flags);
200200

201201
clear_bit(TTY_IO_ERROR, &port->tty->flags);
202202
}
@@ -214,7 +214,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
214214
*/
215215
static void uart_shutdown(struct uart_state *state)
216216
{
217-
struct uart_port *port = state->uart_port;
217+
struct uart_port *uport = state->uart_port;
218218
struct tty_struct *tty = state->port.tty;
219219

220220
/*
@@ -223,14 +223,12 @@ static void uart_shutdown(struct uart_state *state)
223223
if (tty)
224224
set_bit(TTY_IO_ERROR, &tty->flags);
225225

226-
if (state->flags & UIF_INITIALIZED) {
227-
state->flags &= ~UIF_INITIALIZED;
228-
226+
if (test_and_clear_bit(ASYNCB_INITIALIZED, &state->port.flags)) {
229227
/*
230228
* Turn off DTR and RTS early.
231229
*/
232230
if (!tty || (tty->termios->c_cflag & HUPCL))
233-
uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
231+
uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
234232

235233
/*
236234
* clear delta_msr_wait queue to avoid mem leaks: we may free
@@ -244,12 +242,12 @@ static void uart_shutdown(struct uart_state *state)
244242
/*
245243
* Free the IRQ and disable the port.
246244
*/
247-
port->ops->shutdown(port);
245+
uport->ops->shutdown(uport);
248246

249247
/*
250248
* Ensure that the IRQ handler isn't running on another CPU.
251249
*/
252-
synchronize_irq(port->irq);
250+
synchronize_irq(uport->irq);
253251
}
254252

255253
/*
@@ -429,15 +427,16 @@ EXPORT_SYMBOL(uart_get_divisor);
429427
static void
430428
uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
431429
{
432-
struct tty_struct *tty = state->port.tty;
433-
struct uart_port *port = state->uart_port;
430+
struct tty_port *port = &state->port;
431+
struct tty_struct *tty = port->tty;
432+
struct uart_port *uport = state->uart_port;
434433
struct ktermios *termios;
435434

436435
/*
437436
* If we have no tty, termios, or the port does not exist,
438437
* then we can't set the parameters for this port.
439438
*/
440-
if (!tty || !tty->termios || port->type == PORT_UNKNOWN)
439+
if (!tty || !tty->termios || uport->type == PORT_UNKNOWN)
441440
return;
442441

443442
termios = tty->termios;
@@ -446,16 +445,16 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
446445
* Set flags based on termios cflag
447446
*/
448447
if (termios->c_cflag & CRTSCTS)
449-
state->flags |= UIF_CTS_FLOW;
448+
set_bit(ASYNCB_CTS_FLOW, &port->flags);
450449
else
451-
state->flags &= ~UIF_CTS_FLOW;
450+
clear_bit(ASYNCB_CTS_FLOW, &port->flags);
452451

453452
if (termios->c_cflag & CLOCAL)
454-
state->flags &= ~UIF_CHECK_CD;
453+
clear_bit(ASYNCB_CHECK_CD, &port->flags);
455454
else
456-
state->flags |= UIF_CHECK_CD;
455+
set_bit(ASYNCB_CHECK_CD, &port->flags);
457456

458-
port->ops->set_termios(port, termios, old_termios);
457+
uport->ops->set_termios(uport, termios, old_termios);
459458
}
460459

461460
static inline int
@@ -848,7 +847,7 @@ static int uart_set_info(struct uart_state *state,
848847
retval = 0;
849848
if (uport->type == PORT_UNKNOWN)
850849
goto exit;
851-
if (state->flags & UIF_INITIALIZED) {
850+
if (port->flags & ASYNC_INITIALIZED) {
852851
if (((old_flags ^ uport->flags) & UPF_SPD_MASK) ||
853852
old_custom_divisor != uport->custom_divisor) {
854853
/*
@@ -1306,7 +1305,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
13061305
* At this point, we stop accepting input. To do this, we
13071306
* disable the receive line status interrupts.
13081307
*/
1309-
if (state->flags & UIF_INITIALIZED) {
1308+
if (port->flags & ASYNC_INITIALIZED) {
13101309
unsigned long flags;
13111310
spin_lock_irqsave(&port->lock, flags);
13121311
uport->ops->stop_rx(uport);
@@ -1337,7 +1336,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
13371336
/*
13381337
* Wake up anyone trying to open this port.
13391338
*/
1340-
state->flags &= ~UIF_NORMAL_ACTIVE;
1339+
clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
13411340
wake_up_interruptible(&port->open_wait);
13421341

13431342
done:
@@ -1418,11 +1417,11 @@ static void uart_hangup(struct tty_struct *tty)
14181417
pr_debug("uart_hangup(%d)\n", state->uart_port->line);
14191418

14201419
mutex_lock(&state->mutex);
1421-
if (state->flags & UIF_NORMAL_ACTIVE) {
1420+
if (port->flags & ASYNC_NORMAL_ACTIVE) {
14221421
uart_flush_buffer(tty);
14231422
uart_shutdown(state);
14241423
port->count = 0;
1425-
state->flags &= ~UIF_NORMAL_ACTIVE;
1424+
clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
14261425
port->tty = NULL;
14271426
wake_up_interruptible(&port->open_wait);
14281427
wake_up_interruptible(&state->delta_msr_wait);
@@ -1493,7 +1492,7 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
14931492
/*
14941493
* If the port has been closed, tell userspace/restart open.
14951494
*/
1496-
if (!(state->flags & UIF_INITIALIZED))
1495+
if (!(port->flags & ASYNC_INITIALIZED))
14971496
break;
14981497

14991498
/*
@@ -1662,8 +1661,8 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
16621661
/*
16631662
* If this is the first open to succeed, adjust things to suit.
16641663
*/
1665-
if (retval == 0 && !(state->flags & UIF_NORMAL_ACTIVE)) {
1666-
state->flags |= UIF_NORMAL_ACTIVE;
1664+
if (retval == 0 && !(port->flags & ASYNC_NORMAL_ACTIVE)) {
1665+
set_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
16671666

16681667
uart_update_termios(state);
16691668
}
@@ -1985,63 +1984,64 @@ static int serial_match_port(struct device *dev, void *data)
19851984
return dev->devt == devt; /* Actually, only one tty per port */
19861985
}
19871986

1988-
int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
1987+
int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
19891988
{
1990-
struct uart_state *state = drv->state + port->line;
1989+
struct uart_state *state = drv->state + uport->line;
1990+
struct tty_port *port = &state->port;
19911991
struct device *tty_dev;
1992-
struct uart_match match = {port, drv};
1992+
struct uart_match match = {uport, drv};
19931993

19941994
mutex_lock(&state->mutex);
19951995

1996-
if (!console_suspend_enabled && uart_console(port)) {
1996+
if (!console_suspend_enabled && uart_console(uport)) {
19971997
/* we're going to avoid suspending serial console */
19981998
mutex_unlock(&state->mutex);
19991999
return 0;
20002000
}
20012001

2002-
tty_dev = device_find_child(port->dev, &match, serial_match_port);
2002+
tty_dev = device_find_child(uport->dev, &match, serial_match_port);
20032003
if (device_may_wakeup(tty_dev)) {
2004-
enable_irq_wake(port->irq);
2004+
enable_irq_wake(uport->irq);
20052005
put_device(tty_dev);
20062006
mutex_unlock(&state->mutex);
20072007
return 0;
20082008
}
2009-
port->suspended = 1;
2009+
uport->suspended = 1;
20102010

2011-
if (state->flags & UIF_INITIALIZED) {
2012-
const struct uart_ops *ops = port->ops;
2011+
if (port->flags & ASYNC_INITIALIZED) {
2012+
const struct uart_ops *ops = uport->ops;
20132013
int tries;
20142014

2015-
state->flags = (state->flags & ~UIF_INITIALIZED)
2016-
| UIF_SUSPENDED;
2015+
set_bit(ASYNCB_SUSPENDED, &port->flags);
2016+
clear_bit(ASYNCB_INITIALIZED, &port->flags);
20172017

2018-
spin_lock_irq(&port->lock);
2019-
ops->stop_tx(port);
2020-
ops->set_mctrl(port, 0);
2021-
ops->stop_rx(port);
2022-
spin_unlock_irq(&port->lock);
2018+
spin_lock_irq(&uport->lock);
2019+
ops->stop_tx(uport);
2020+
ops->set_mctrl(uport, 0);
2021+
ops->stop_rx(uport);
2022+
spin_unlock_irq(&uport->lock);
20232023

20242024
/*
20252025
* Wait for the transmitter to empty.
20262026
*/
2027-
for (tries = 3; !ops->tx_empty(port) && tries; tries--)
2027+
for (tries = 3; !ops->tx_empty(uport) && tries; tries--)
20282028
msleep(10);
20292029
if (!tries)
20302030
printk(KERN_ERR "%s%s%s%d: Unable to drain "
20312031
"transmitter\n",
2032-
port->dev ? dev_name(port->dev) : "",
2033-
port->dev ? ": " : "",
2032+
uport->dev ? dev_name(uport->dev) : "",
2033+
uport->dev ? ": " : "",
20342034
drv->dev_name,
2035-
drv->tty_driver->name_base + port->line);
2035+
drv->tty_driver->name_base + uport->line);
20362036

2037-
ops->shutdown(port);
2037+
ops->shutdown(uport);
20382038
}
20392039

20402040
/*
20412041
* Disable the console device before suspending.
20422042
*/
2043-
if (uart_console(port))
2044-
console_stop(port->cons);
2043+
if (uart_console(uport))
2044+
console_stop(uport->cons);
20452045

20462046
uart_change_pm(state, 3);
20472047

@@ -2050,67 +2050,68 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
20502050
return 0;
20512051
}
20522052

2053-
int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
2053+
int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
20542054
{
2055-
struct uart_state *state = drv->state + port->line;
2055+
struct uart_state *state = drv->state + uport->line;
2056+
struct tty_port *port = &state->port;
20562057
struct device *tty_dev;
2057-
struct uart_match match = {port, drv};
2058+
struct uart_match match = {uport, drv};
20582059

20592060
mutex_lock(&state->mutex);
20602061

2061-
if (!console_suspend_enabled && uart_console(port)) {
2062+
if (!console_suspend_enabled && uart_console(uport)) {
20622063
/* no need to resume serial console, it wasn't suspended */
20632064
mutex_unlock(&state->mutex);
20642065
return 0;
20652066
}
20662067

2067-
tty_dev = device_find_child(port->dev, &match, serial_match_port);
2068-
if (!port->suspended && device_may_wakeup(tty_dev)) {
2069-
disable_irq_wake(port->irq);
2068+
tty_dev = device_find_child(uport->dev, &match, serial_match_port);
2069+
if (!uport->suspended && device_may_wakeup(tty_dev)) {
2070+
disable_irq_wake(uport->irq);
20702071
mutex_unlock(&state->mutex);
20712072
return 0;
20722073
}
2073-
port->suspended = 0;
2074+
uport->suspended = 0;
20742075

20752076
/*
20762077
* Re-enable the console device after suspending.
20772078
*/
2078-
if (uart_console(port)) {
2079+
if (uart_console(uport)) {
20792080
struct ktermios termios;
20802081

20812082
/*
20822083
* First try to use the console cflag setting.
20832084
*/
20842085
memset(&termios, 0, sizeof(struct ktermios));
2085-
termios.c_cflag = port->cons->cflag;
2086+
termios.c_cflag = uport->cons->cflag;
20862087

20872088
/*
20882089
* If that's unset, use the tty termios setting.
20892090
*/
2090-
if (state->port.tty && termios.c_cflag == 0)
2091-
termios = *state->port.tty->termios;
2091+
if (port->tty && termios.c_cflag == 0)
2092+
termios = *port->tty->termios;
20922093

20932094
uart_change_pm(state, 0);
2094-
port->ops->set_termios(port, &termios, NULL);
2095-
console_start(port->cons);
2095+
uport->ops->set_termios(uport, &termios, NULL);
2096+
console_start(uport->cons);
20962097
}
20972098

2098-
if (state->flags & UIF_SUSPENDED) {
2099-
const struct uart_ops *ops = port->ops;
2099+
if (port->flags & ASYNC_SUSPENDED) {
2100+
const struct uart_ops *ops = uport->ops;
21002101
int ret;
21012102

21022103
uart_change_pm(state, 0);
2103-
spin_lock_irq(&port->lock);
2104-
ops->set_mctrl(port, 0);
2105-
spin_unlock_irq(&port->lock);
2106-
ret = ops->startup(port);
2104+
spin_lock_irq(&uport->lock);
2105+
ops->set_mctrl(uport, 0);
2106+
spin_unlock_irq(&uport->lock);
2107+
ret = ops->startup(uport);
21072108
if (ret == 0) {
21082109
uart_change_speed(state, NULL);
2109-
spin_lock_irq(&port->lock);
2110-
ops->set_mctrl(port, port->mctrl);
2111-
ops->start_tx(port);
2112-
spin_unlock_irq(&port->lock);
2113-
state->flags |= UIF_INITIALIZED;
2110+
spin_lock_irq(&uport->lock);
2111+
ops->set_mctrl(uport, uport->mctrl);
2112+
ops->start_tx(uport);
2113+
spin_unlock_irq(&uport->lock);
2114+
set_bit(ASYNCB_INITIALIZED, &port->flags);
21142115
} else {
21152116
/*
21162117
* Failed to resume - maybe hardware went away?
@@ -2120,7 +2121,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
21202121
uart_shutdown(state);
21212122
}
21222123

2123-
state->flags &= ~UIF_SUSPENDED;
2124+
clear_bit(ASYNCB_SUSPENDED, &port->flags);
21242125
}
21252126

21262127
mutex_unlock(&state->mutex);

include/linux/serial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct serial_uart_config {
122122

123123
/* Internal flags used only by kernel */
124124
#define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
125+
#define ASYNCB_SUSPENDED 30 /* Serial port is suspended */
125126
#define ASYNCB_NORMAL_ACTIVE 29 /* Normal device is active */
126127
#define ASYNCB_BOOT_AUTOCONF 28 /* Autoconfigure port on bootup */
127128
#define ASYNCB_CLOSING 27 /* Serial port is closing */
@@ -133,6 +134,7 @@ struct serial_uart_config {
133134
#define ASYNCB_FIRST_KERNEL 22
134135

135136
#define ASYNC_HUP_NOTIFY (1U << ASYNCB_HUP_NOTIFY)
137+
#define ASYNC_SUSPENDED (1U << ASYNCB_SUSPENDED)
136138
#define ASYNC_FOURPORT (1U << ASYNCB_FOURPORT)
137139
#define ASYNC_SAK (1U << ASYNCB_SAK)
138140
#define ASYNC_SPLIT_TERMIOS (1U << ASYNCB_SPLIT_TERMIOS)

0 commit comments

Comments
 (0)