aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2013-06-28 02:00:25 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-06-28 02:00:25 -0400
commit31881d74b6dd1a6c530cff61248def4f2da38bee (patch)
treebe62420cf39192074e13b25553d172b9d5e58a33 /drivers/tty
parent8855f30cd2b68012571932c7b01290c20be4508c (diff)
parent257867dc8d893690c175c1f717f91c3b6d44a63d (diff)
Merge branch 'for-next' of git://github.com/rydberg/linux into next
Pull in changes from Henrik: "a trivial MT documentation fix".
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/amiserial.c14
-rw-r--r--drivers/tty/cyclades.c10
-rw-r--r--drivers/tty/ehv_bytechan.c7
-rw-r--r--drivers/tty/hvc/hvsi.c7
-rw-r--r--drivers/tty/ipwireless/hardware.c3
-rw-r--r--drivers/tty/moxa.c19
-rw-r--r--drivers/tty/mxser.c23
-rw-r--r--drivers/tty/n_gsm.c10
-rw-r--r--drivers/tty/n_tty.c180
-rw-r--r--drivers/tty/nozomi.c15
-rw-r--r--drivers/tty/pty.c16
-rw-r--r--drivers/tty/rocket.c312
-rw-r--r--drivers/tty/serial/68328serial.c10
-rw-r--r--drivers/tty/serial/8250/8250.h7
-rw-r--r--drivers/tty/serial/8250/8250_core.c (renamed from drivers/tty/serial/8250/8250.c)10
-rw-r--r--drivers/tty/serial/8250/8250_dma.c52
-rw-r--r--drivers/tty/serial/8250/8250_dw.c197
-rw-r--r--drivers/tty/serial/8250/8250_pci.c13
-rw-r--r--drivers/tty/serial/8250/8250_pnp.c12
-rw-r--r--drivers/tty/serial/8250/Kconfig17
-rw-r--r--drivers/tty/serial/8250/Makefile8
-rw-r--r--drivers/tty/serial/8250/serial_cs.c14
-rw-r--r--drivers/tty/serial/amba-pl011.c245
-rw-r--r--drivers/tty/serial/arc_uart.c2
-rw-r--r--drivers/tty/serial/atmel_serial.c11
-rw-r--r--drivers/tty/serial/bcm63xx_uart.c1
-rw-r--r--drivers/tty/serial/bfin_uart.c23
-rw-r--r--drivers/tty/serial/crisv10.c168
-rw-r--r--drivers/tty/serial/crisv10.h14
-rw-r--r--drivers/tty/serial/icom.c3
-rw-r--r--drivers/tty/serial/ifx6x60.c80
-rw-r--r--drivers/tty/serial/imx.c2
-rw-r--r--drivers/tty/serial/jsm/jsm_tty.c6
-rw-r--r--drivers/tty/serial/max3100.c24
-rw-r--r--drivers/tty/serial/max310x.c24
-rw-r--r--drivers/tty/serial/mcf.c4
-rw-r--r--drivers/tty/serial/mpc52xx_uart.c11
-rw-r--r--drivers/tty/serial/mrst_max3110.c19
-rw-r--r--drivers/tty/serial/msm_serial_hs.c2
-rw-r--r--drivers/tty/serial/msm_smd_tty.c14
-rw-r--r--drivers/tty/serial/mxs-auart.c58
-rw-r--r--drivers/tty/serial/nwpserial.c2
-rw-r--r--drivers/tty/serial/of_serial.c17
-rw-r--r--drivers/tty/serial/omap-serial.c34
-rw-r--r--drivers/tty/serial/pch_uart.c103
-rw-r--r--drivers/tty/serial/samsung.c77
-rw-r--r--drivers/tty/serial/samsung.h4
-rw-r--r--drivers/tty/serial/sccnxp.c23
-rw-r--r--drivers/tty/serial/serial-tegra.c9
-rw-r--r--drivers/tty/serial/serial_core.c6
-rw-r--r--drivers/tty/serial/sh-sci.h2
-rw-r--r--drivers/tty/serial/sirfsoc_uart.c2
-rw-r--r--drivers/tty/serial/sunsab.c2
-rw-r--r--drivers/tty/serial/sunsu.c22
-rw-r--r--drivers/tty/serial/sunzilog.c2
-rw-r--r--drivers/tty/serial/vt8500_serial.c7
-rw-r--r--drivers/tty/serial/xilinx_uartps.c5
-rw-r--r--drivers/tty/synclink.c5
-rw-r--r--drivers/tty/synclink_gt.c2
-rw-r--r--drivers/tty/synclinkmp.c2
-rw-r--r--drivers/tty/sysrq.c38
-rw-r--r--drivers/tty/tty_audit.c104
-rw-r--r--drivers/tty/tty_buffer.c22
-rw-r--r--drivers/tty/tty_io.c188
-rw-r--r--drivers/tty/tty_ioctl.c120
-rw-r--r--drivers/tty/tty_ldisc.c326
-rw-r--r--drivers/tty/tty_port.c111
-rw-r--r--drivers/tty/vt/consolemap.c3
-rw-r--r--drivers/tty/vt/vc_screen.c6
-rw-r--r--drivers/tty/vt/vt.c14
-rw-r--r--drivers/tty/vt/vt_ioctl.c67
71 files changed, 1630 insertions, 1362 deletions
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index fc700342d43f..083710e02367 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1798,19 +1798,7 @@ static struct platform_driver amiga_serial_driver = {
1798 }, 1798 },
1799}; 1799};
1800 1800
1801static int __init amiga_serial_init(void) 1801module_platform_driver_probe(amiga_serial_driver, amiga_serial_probe);
1802{
1803 return platform_driver_probe(&amiga_serial_driver, amiga_serial_probe);
1804}
1805
1806module_init(amiga_serial_init);
1807
1808static void __exit amiga_serial_exit(void)
1809{
1810 platform_driver_unregister(&amiga_serial_driver);
1811}
1812
1813module_exit(amiga_serial_exit);
1814 1802
1815 1803
1816#if defined(CONFIG_SERIAL_CONSOLE) && !defined(MODULE) 1804#if defined(CONFIG_SERIAL_CONSOLE) && !defined(MODULE)
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index 345bd0e0884e..33f83fee9fae 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -1124,14 +1124,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1124 readl(&info->u.cyz.ch_ctrl->rs_status); 1124 readl(&info->u.cyz.ch_ctrl->rs_status);
1125 if (dcd & C_RS_DCD) 1125 if (dcd & C_RS_DCD)
1126 wake_up_interruptible(&info->port.open_wait); 1126 wake_up_interruptible(&info->port.open_wait);
1127 else { 1127 else
1128 struct tty_struct *tty; 1128 tty_port_tty_hangup(&info->port, false);
1129 tty = tty_port_tty_get(&info->port);
1130 if (tty) {
1131 tty_hangup(tty);
1132 tty_kref_put(tty);
1133 }
1134 }
1135 } 1129 }
1136 break; 1130 break;
1137 case C_CM_MCTS: 1131 case C_CM_MCTS:
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
index ed92622b8949..9bffcec5ad82 100644
--- a/drivers/tty/ehv_bytechan.c
+++ b/drivers/tty/ehv_bytechan.c
@@ -472,13 +472,9 @@ static void ehv_bc_tx_dequeue(struct ehv_bc_data *bc)
472static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data) 472static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data)
473{ 473{
474 struct ehv_bc_data *bc = data; 474 struct ehv_bc_data *bc = data;
475 struct tty_struct *ttys = tty_port_tty_get(&bc->port);
476 475
477 ehv_bc_tx_dequeue(bc); 476 ehv_bc_tx_dequeue(bc);
478 if (ttys) { 477 tty_port_tty_wakeup(&bc->port);
479 tty_wakeup(ttys);
480 tty_kref_put(ttys);
481 }
482 478
483 return IRQ_HANDLED; 479 return IRQ_HANDLED;
484} 480}
@@ -863,6 +859,7 @@ error:
863 */ 859 */
864static void __exit ehv_bc_exit(void) 860static void __exit ehv_bc_exit(void)
865{ 861{
862 platform_driver_unregister(&ehv_bc_tty_driver);
866 tty_unregister_driver(ehv_bc_driver); 863 tty_unregister_driver(ehv_bc_driver);
867 put_tty_driver(ehv_bc_driver); 864 put_tty_driver(ehv_bc_driver);
868 kfree(bcs); 865 kfree(bcs);
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index ef95a154854a..41901997c0d6 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -861,7 +861,6 @@ static void hvsi_write_worker(struct work_struct *work)
861{ 861{
862 struct hvsi_struct *hp = 862 struct hvsi_struct *hp =
863 container_of(work, struct hvsi_struct, writer.work); 863 container_of(work, struct hvsi_struct, writer.work);
864 struct tty_struct *tty;
865 unsigned long flags; 864 unsigned long flags;
866#ifdef DEBUG 865#ifdef DEBUG
867 static long start_j = 0; 866 static long start_j = 0;
@@ -895,11 +894,7 @@ static void hvsi_write_worker(struct work_struct *work)
895 start_j = 0; 894 start_j = 0;
896#endif /* DEBUG */ 895#endif /* DEBUG */
897 wake_up_all(&hp->emptyq); 896 wake_up_all(&hp->emptyq);
898 tty = tty_port_tty_get(&hp->port); 897 tty_port_tty_wakeup(&hp->port);
899 if (tty) {
900 tty_wakeup(tty);
901 tty_kref_put(tty);
902 }
903 } 898 }
904 899
905out: 900out:
diff --git a/drivers/tty/ipwireless/hardware.c b/drivers/tty/ipwireless/hardware.c
index 97a511f4185d..2c14842541dd 100644
--- a/drivers/tty/ipwireless/hardware.c
+++ b/drivers/tty/ipwireless/hardware.c
@@ -1732,8 +1732,7 @@ void ipwireless_hardware_free(struct ipw_hardware *hw)
1732 flush_work(&hw->work_rx); 1732 flush_work(&hw->work_rx);
1733 1733
1734 for (i = 0; i < NL_NUM_OF_ADDRESSES; i++) 1734 for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
1735 if (hw->packet_assembler[i] != NULL) 1735 kfree(hw->packet_assembler[i]);
1736 kfree(hw->packet_assembler[i]);
1737 1736
1738 for (i = 0; i < NL_NUM_OF_PRIORITIES; i++) 1737 for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
1739 list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) { 1738 list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index adeac255e526..1deaca4674e4 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -913,16 +913,12 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
913 913
914 /* pci hot-un-plug support */ 914 /* pci hot-un-plug support */
915 for (a = 0; a < brd->numPorts; a++) 915 for (a = 0; a < brd->numPorts; a++)
916 if (brd->ports[a].port.flags & ASYNC_INITIALIZED) { 916 if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
917 struct tty_struct *tty = tty_port_tty_get( 917 tty_port_tty_hangup(&brd->ports[a].port, false);
918 &brd->ports[a].port); 918
919 if (tty) {
920 tty_hangup(tty);
921 tty_kref_put(tty);
922 }
923 }
924 for (a = 0; a < MAX_PORTS_PER_BOARD; a++) 919 for (a = 0; a < MAX_PORTS_PER_BOARD; a++)
925 tty_port_destroy(&brd->ports[a].port); 920 tty_port_destroy(&brd->ports[a].port);
921
926 while (1) { 922 while (1) {
927 opened = 0; 923 opened = 0;
928 for (a = 0; a < brd->numPorts; a++) 924 for (a = 0; a < brd->numPorts; a++)
@@ -1365,7 +1361,6 @@ static void moxa_hangup(struct tty_struct *tty)
1365 1361
1366static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) 1362static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1367{ 1363{
1368 struct tty_struct *tty;
1369 unsigned long flags; 1364 unsigned long flags;
1370 dcd = !!dcd; 1365 dcd = !!dcd;
1371 1366
@@ -1373,10 +1368,8 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1373 if (dcd != p->DCDState) { 1368 if (dcd != p->DCDState) {
1374 p->DCDState = dcd; 1369 p->DCDState = dcd;
1375 spin_unlock_irqrestore(&p->port.lock, flags); 1370 spin_unlock_irqrestore(&p->port.lock, flags);
1376 tty = tty_port_tty_get(&p->port); 1371 if (!dcd)
1377 if (tty && !C_CLOCAL(tty) && !dcd) 1372 tty_port_tty_hangup(&p->port, true);
1378 tty_hangup(tty);
1379 tty_kref_put(tty);
1380 } 1373 }
1381 else 1374 else
1382 spin_unlock_irqrestore(&p->port.lock, flags); 1375 spin_unlock_irqrestore(&p->port.lock, flags);
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 484b6a3c9b03..4c4a23674569 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -1084,6 +1084,10 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1084 mutex_lock(&port->mutex); 1084 mutex_lock(&port->mutex);
1085 mxser_close_port(port); 1085 mxser_close_port(port);
1086 mxser_flush_buffer(tty); 1086 mxser_flush_buffer(tty);
1087 if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
1088 if (C_HUPCL(tty))
1089 tty_port_lower_dtr_rts(port);
1090 }
1087 mxser_shutdown_port(port); 1091 mxser_shutdown_port(port);
1088 clear_bit(ASYNCB_INITIALIZED, &port->flags); 1092 clear_bit(ASYNCB_INITIALIZED, &port->flags);
1089 mutex_unlock(&port->mutex); 1093 mutex_unlock(&port->mutex);
@@ -1614,8 +1618,12 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1614 if (ip->type == PORT_16550A) 1618 if (ip->type == PORT_16550A)
1615 me->fifo[p] = 1; 1619 me->fifo[p] = 1;
1616 1620
1617 opmode = inb(ip->opmode_ioaddr)>>((p % 4) * 2); 1621 if (ip->board->chip_flag == MOXA_MUST_MU860_HWID) {
1618 opmode &= OP_MODE_MASK; 1622 opmode = inb(ip->opmode_ioaddr)>>((p % 4) * 2);
1623 opmode &= OP_MODE_MASK;
1624 } else {
1625 opmode = RS232_MODE;
1626 }
1619 me->iftype[p] = opmode; 1627 me->iftype[p] = opmode;
1620 mutex_unlock(&port->mutex); 1628 mutex_unlock(&port->mutex);
1621 } 1629 }
@@ -1672,6 +1680,9 @@ static int mxser_ioctl(struct tty_struct *tty,
1672 int shiftbit; 1680 int shiftbit;
1673 unsigned char val, mask; 1681 unsigned char val, mask;
1674 1682
1683 if (info->board->chip_flag != MOXA_MUST_MU860_HWID)
1684 return -EFAULT;
1685
1675 p = tty->index % 4; 1686 p = tty->index % 4;
1676 if (cmd == MOXA_SET_OP_MODE) { 1687 if (cmd == MOXA_SET_OP_MODE) {
1677 if (get_user(opmode, (int __user *) argp)) 1688 if (get_user(opmode, (int __user *) argp))
@@ -2643,9 +2654,9 @@ static int mxser_probe(struct pci_dev *pdev,
2643 mxvar_sdriver, brd->idx + i, &pdev->dev); 2654 mxvar_sdriver, brd->idx + i, &pdev->dev);
2644 if (IS_ERR(tty_dev)) { 2655 if (IS_ERR(tty_dev)) {
2645 retval = PTR_ERR(tty_dev); 2656 retval = PTR_ERR(tty_dev);
2646 for (i--; i >= 0; i--) 2657 for (; i > 0; i--)
2647 tty_unregister_device(mxvar_sdriver, 2658 tty_unregister_device(mxvar_sdriver,
2648 brd->idx + i); 2659 brd->idx + i - 1);
2649 goto err_relbrd; 2660 goto err_relbrd;
2650 } 2661 }
2651 } 2662 }
@@ -2751,9 +2762,9 @@ static int __init mxser_module_init(void)
2751 tty_dev = tty_port_register_device(&brd->ports[i].port, 2762 tty_dev = tty_port_register_device(&brd->ports[i].port,
2752 mxvar_sdriver, brd->idx + i, NULL); 2763 mxvar_sdriver, brd->idx + i, NULL);
2753 if (IS_ERR(tty_dev)) { 2764 if (IS_ERR(tty_dev)) {
2754 for (i--; i >= 0; i--) 2765 for (; i > 0; i--)
2755 tty_unregister_device(mxvar_sdriver, 2766 tty_unregister_device(mxvar_sdriver,
2756 brd->idx + i); 2767 brd->idx + i - 1);
2757 for (i = 0; i < brd->info->nports; i++) 2768 for (i = 0; i < brd->info->nports; i++)
2758 tty_port_destroy(&brd->ports[i].port); 2769 tty_port_destroy(&brd->ports[i].port);
2759 free_irq(brd->irq, brd); 2770 free_irq(brd->irq, brd);
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 4a43ef5d7962..642239015b46 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -1418,11 +1418,7 @@ static void gsm_dlci_close(struct gsm_dlci *dlci)
1418 pr_debug("DLCI %d goes closed.\n", dlci->addr); 1418 pr_debug("DLCI %d goes closed.\n", dlci->addr);
1419 dlci->state = DLCI_CLOSED; 1419 dlci->state = DLCI_CLOSED;
1420 if (dlci->addr != 0) { 1420 if (dlci->addr != 0) {
1421 struct tty_struct *tty = tty_port_tty_get(&dlci->port); 1421 tty_port_tty_hangup(&dlci->port, false);
1422 if (tty) {
1423 tty_hangup(tty);
1424 tty_kref_put(tty);
1425 }
1426 kfifo_reset(dlci->fifo); 1422 kfifo_reset(dlci->fifo);
1427 } else 1423 } else
1428 dlci->gsm->dead = 1; 1424 dlci->gsm->dead = 1;
@@ -2968,6 +2964,10 @@ static void gsmtty_close(struct tty_struct *tty, struct file *filp)
2968 if (tty_port_close_start(&dlci->port, tty, filp) == 0) 2964 if (tty_port_close_start(&dlci->port, tty, filp) == 0)
2969 goto out; 2965 goto out;
2970 gsm_dlci_begin_close(dlci); 2966 gsm_dlci_begin_close(dlci);
2967 if (test_bit(ASYNCB_INITIALIZED, &dlci->port.flags)) {
2968 if (C_HUPCL(tty))
2969 tty_port_lower_dtr_rts(&dlci->port);
2970 }
2971 tty_port_close_end(&dlci->port, tty); 2971 tty_port_close_end(&dlci->port, tty);
2972 tty_port_tty_set(&dlci->port, NULL); 2972 tty_port_tty_set(&dlci->port, NULL);
2973out: 2973out:
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 05e72bea9b07..6c7fe90ad72d 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -153,6 +153,12 @@ static void n_tty_set_room(struct tty_struct *tty)
153 if (left && !old_left) { 153 if (left && !old_left) {
154 WARN_RATELIMIT(tty->port->itty == NULL, 154 WARN_RATELIMIT(tty->port->itty == NULL,
155 "scheduling with invalid itty\n"); 155 "scheduling with invalid itty\n");
156 /* see if ldisc has been killed - if so, this means that
157 * even though the ldisc has been halted and ->buf.work
158 * cancelled, ->buf.work is about to be rescheduled
159 */
160 WARN_RATELIMIT(test_bit(TTY_LDISC_HALTED, &tty->flags),
161 "scheduling buffer work for halted ldisc\n");
156 schedule_work(&tty->port->buf.work); 162 schedule_work(&tty->port->buf.work);
157 } 163 }
158} 164}
@@ -189,34 +195,17 @@ static void put_tty_queue(unsigned char c, struct n_tty_data *ldata)
189} 195}
190 196
191/** 197/**
192 * check_unthrottle - allow new receive data
193 * @tty; tty device
194 *
195 * Check whether to call the driver unthrottle functions
196 *
197 * Can sleep, may be called under the atomic_read_lock mutex but
198 * this is not guaranteed.
199 */
200static void check_unthrottle(struct tty_struct *tty)
201{
202 if (tty->count)
203 tty_unthrottle(tty);
204}
205
206/**
207 * reset_buffer_flags - reset buffer state 198 * reset_buffer_flags - reset buffer state
208 * @tty: terminal to reset 199 * @tty: terminal to reset
209 * 200 *
210 * Reset the read buffer counters, clear the flags, 201 * Reset the read buffer counters and clear the flags.
211 * and make sure the driver is unthrottled. Called 202 * Called from n_tty_open() and n_tty_flush_buffer().
212 * from n_tty_open() and n_tty_flush_buffer().
213 * 203 *
214 * Locking: tty_read_lock for read fields. 204 * Locking: tty_read_lock for read fields.
215 */ 205 */
216 206
217static void reset_buffer_flags(struct tty_struct *tty) 207static void reset_buffer_flags(struct n_tty_data *ldata)
218{ 208{
219 struct n_tty_data *ldata = tty->disc_data;
220 unsigned long flags; 209 unsigned long flags;
221 210
222 raw_spin_lock_irqsave(&ldata->read_lock, flags); 211 raw_spin_lock_irqsave(&ldata->read_lock, flags);
@@ -229,36 +218,38 @@ static void reset_buffer_flags(struct tty_struct *tty)
229 218
230 ldata->canon_head = ldata->canon_data = ldata->erasing = 0; 219 ldata->canon_head = ldata->canon_data = ldata->erasing = 0;
231 bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE); 220 bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE);
232 n_tty_set_room(tty); 221}
222
223static void n_tty_packet_mode_flush(struct tty_struct *tty)
224{
225 unsigned long flags;
226
227 spin_lock_irqsave(&tty->ctrl_lock, flags);
228 if (tty->link->packet) {
229 tty->ctrl_status |= TIOCPKT_FLUSHREAD;
230 wake_up_interruptible(&tty->link->read_wait);
231 }
232 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
233} 233}
234 234
235/** 235/**
236 * n_tty_flush_buffer - clean input queue 236 * n_tty_flush_buffer - clean input queue
237 * @tty: terminal device 237 * @tty: terminal device
238 * 238 *
239 * Flush the input buffer. Called when the line discipline is 239 * Flush the input buffer. Called when the tty layer wants the
240 * being closed, when the tty layer wants the buffer flushed (eg 240 * buffer flushed (eg at hangup) or when the N_TTY line discipline
241 * at hangup) or when the N_TTY line discipline internally has to 241 * internally has to clean the pending queue (for example some signals).
242 * clean the pending queue (for example some signals).
243 * 242 *
244 * Locking: ctrl_lock, read_lock. 243 * Locking: ctrl_lock, read_lock.
245 */ 244 */
246 245
247static void n_tty_flush_buffer(struct tty_struct *tty) 246static void n_tty_flush_buffer(struct tty_struct *tty)
248{ 247{
249 unsigned long flags; 248 reset_buffer_flags(tty->disc_data);
250 /* clear everything and unthrottle the driver */ 249 n_tty_set_room(tty);
251 reset_buffer_flags(tty);
252
253 if (!tty->link)
254 return;
255 250
256 spin_lock_irqsave(&tty->ctrl_lock, flags); 251 if (tty->link)
257 if (tty->link->packet) { 252 n_tty_packet_mode_flush(tty);
258 tty->ctrl_status |= TIOCPKT_FLUSHREAD;
259 wake_up_interruptible(&tty->link->read_wait);
260 }
261 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
262} 253}
263 254
264/** 255/**
@@ -1032,23 +1023,19 @@ static void eraser(unsigned char c, struct tty_struct *tty)
1032 * isig - handle the ISIG optio 1023 * isig - handle the ISIG optio
1033 * @sig: signal 1024 * @sig: signal
1034 * @tty: terminal 1025 * @tty: terminal
1035 * @flush: force flush
1036 * 1026 *
1037 * Called when a signal is being sent due to terminal input. This 1027 * Called when a signal is being sent due to terminal input.
1038 * may caus terminal flushing to take place according to the termios 1028 * Called from the driver receive_buf path so serialized.
1039 * settings and character used. Called from the driver receive_buf
1040 * path so serialized.
1041 * 1029 *
1042 * Locking: ctrl_lock, read_lock (both via flush buffer) 1030 * Locking: ctrl_lock
1043 */ 1031 */
1044 1032
1045static inline void isig(int sig, struct tty_struct *tty, int flush) 1033static inline void isig(int sig, struct tty_struct *tty)
1046{ 1034{
1047 if (tty->pgrp) 1035 struct pid *tty_pgrp = tty_get_pgrp(tty);
1048 kill_pgrp(tty->pgrp, sig, 1); 1036 if (tty_pgrp) {
1049 if (flush || !L_NOFLSH(tty)) { 1037 kill_pgrp(tty_pgrp, sig, 1);
1050 n_tty_flush_buffer(tty); 1038 put_pid(tty_pgrp);
1051 tty_driver_flush_buffer(tty);
1052 } 1039 }
1053} 1040}
1054 1041
@@ -1069,7 +1056,11 @@ static inline void n_tty_receive_break(struct tty_struct *tty)
1069 if (I_IGNBRK(tty)) 1056 if (I_IGNBRK(tty))
1070 return; 1057 return;
1071 if (I_BRKINT(tty)) { 1058 if (I_BRKINT(tty)) {
1072 isig(SIGINT, tty, 1); 1059 isig(SIGINT, tty);
1060 if (!L_NOFLSH(tty)) {
1061 n_tty_flush_buffer(tty);
1062 tty_driver_flush_buffer(tty);
1063 }
1073 return; 1064 return;
1074 } 1065 }
1075 if (I_PARMRK(tty)) { 1066 if (I_PARMRK(tty)) {
@@ -1236,11 +1227,6 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1236 signal = SIGTSTP; 1227 signal = SIGTSTP;
1237 if (c == SUSP_CHAR(tty)) { 1228 if (c == SUSP_CHAR(tty)) {
1238send_signal: 1229send_signal:
1239 /*
1240 * Note that we do not use isig() here because we want
1241 * the order to be:
1242 * 1) flush, 2) echo, 3) signal
1243 */
1244 if (!L_NOFLSH(tty)) { 1230 if (!L_NOFLSH(tty)) {
1245 n_tty_flush_buffer(tty); 1231 n_tty_flush_buffer(tty);
1246 tty_driver_flush_buffer(tty); 1232 tty_driver_flush_buffer(tty);
@@ -1251,8 +1237,7 @@ send_signal:
1251 echo_char(c, tty); 1237 echo_char(c, tty);
1252 process_echoes(tty); 1238 process_echoes(tty);
1253 } 1239 }
1254 if (tty->pgrp) 1240 isig(signal, tty);
1255 kill_pgrp(tty->pgrp, signal, 1);
1256 return; 1241 return;
1257 } 1242 }
1258 } 1243 }
@@ -1483,14 +1468,14 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1483 * mode. We don't want to throttle the driver if we're in 1468 * mode. We don't want to throttle the driver if we're in
1484 * canonical mode and don't have a newline yet! 1469 * canonical mode and don't have a newline yet!
1485 */ 1470 */
1486 if (tty->receive_room < TTY_THRESHOLD_THROTTLE) 1471 while (1) {
1487 tty_throttle(tty); 1472 tty_set_flow_change(tty, TTY_THROTTLE_SAFE);
1488 1473 if (tty->receive_room >= TTY_THRESHOLD_THROTTLE)
1489 /* FIXME: there is a tiny race here if the receive room check runs 1474 break;
1490 before the other work executes and empties the buffer (upping 1475 if (!tty_throttle_safe(tty))
1491 the receiving room and unthrottling. We then throttle and get 1476 break;
1492 stuck. This has been observed and traced down by Vincent Pillet/ 1477 }
1493 We need to address this when we sort out out the rx path locking */ 1478 __tty_set_flow_change(tty, 0);
1494} 1479}
1495 1480
1496int is_ignored(int sig) 1481int is_ignored(int sig)
@@ -1588,6 +1573,14 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1588 ldata->real_raw = 0; 1573 ldata->real_raw = 0;
1589 } 1574 }
1590 n_tty_set_room(tty); 1575 n_tty_set_room(tty);
1576 /*
1577 * Fix tty hang when I_IXON(tty) is cleared, but the tty
1578 * been stopped by STOP_CHAR(tty) before it.
1579 */
1580 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow_stopped) {
1581 start_tty(tty);
1582 }
1583
1591 /* The termios change make the tty ready for I/O */ 1584 /* The termios change make the tty ready for I/O */
1592 wake_up_interruptible(&tty->write_wait); 1585 wake_up_interruptible(&tty->write_wait);
1593 wake_up_interruptible(&tty->read_wait); 1586 wake_up_interruptible(&tty->read_wait);
@@ -1607,7 +1600,9 @@ static void n_tty_close(struct tty_struct *tty)
1607{ 1600{
1608 struct n_tty_data *ldata = tty->disc_data; 1601 struct n_tty_data *ldata = tty->disc_data;
1609 1602
1610 n_tty_flush_buffer(tty); 1603 if (tty->link)
1604 n_tty_packet_mode_flush(tty);
1605
1611 kfree(ldata->read_buf); 1606 kfree(ldata->read_buf);
1612 kfree(ldata->echo_buf); 1607 kfree(ldata->echo_buf);
1613 kfree(ldata); 1608 kfree(ldata);
@@ -1645,12 +1640,14 @@ static int n_tty_open(struct tty_struct *tty)
1645 goto err_free_bufs; 1640 goto err_free_bufs;
1646 1641
1647 tty->disc_data = ldata; 1642 tty->disc_data = ldata;
1648 reset_buffer_flags(tty); 1643 reset_buffer_flags(tty->disc_data);
1649 tty_unthrottle(tty);
1650 ldata->column = 0; 1644 ldata->column = 0;
1651 n_tty_set_termios(tty, NULL);
1652 tty->minimum_to_wake = 1; 1645 tty->minimum_to_wake = 1;
1653 tty->closing = 0; 1646 tty->closing = 0;
1647 /* indicate buffer work may resume */
1648 clear_bit(TTY_LDISC_HALTED, &tty->flags);
1649 n_tty_set_termios(tty, NULL);
1650 tty_unthrottle(tty);
1654 1651
1655 return 0; 1652 return 0;
1656err_free_bufs: 1653err_free_bufs:
@@ -1740,10 +1737,9 @@ extern ssize_t redirected_tty_write(struct file *, const char __user *,
1740 * and if appropriate send any needed signals and return a negative 1737 * and if appropriate send any needed signals and return a negative
1741 * error code if action should be taken. 1738 * error code if action should be taken.
1742 * 1739 *
1743 * FIXME: 1740 * Locking: redirected write test is safe
1744 * Locking: None - redirected write test is safe, testing 1741 * current->signal->tty check is safe
1745 * current->signal should possibly lock current->sighand 1742 * ctrl_lock to safely reference tty->pgrp
1746 * pgrp locking ?
1747 */ 1743 */
1748 1744
1749static int job_control(struct tty_struct *tty, struct file *file) 1745static int job_control(struct tty_struct *tty, struct file *file)
@@ -1753,19 +1749,22 @@ static int job_control(struct tty_struct *tty, struct file *file)
1753 /* NOTE: not yet done after every sleep pending a thorough 1749 /* NOTE: not yet done after every sleep pending a thorough
1754 check of the logic of this change. -- jlc */ 1750 check of the logic of this change. -- jlc */
1755 /* don't stop on /dev/console */ 1751 /* don't stop on /dev/console */
1756 if (file->f_op->write != redirected_tty_write && 1752 if (file->f_op->write == redirected_tty_write ||
1757 current->signal->tty == tty) { 1753 current->signal->tty != tty)
1758 if (!tty->pgrp) 1754 return 0;
1759 printk(KERN_ERR "n_tty_read: no tty->pgrp!\n"); 1755
1760 else if (task_pgrp(current) != tty->pgrp) { 1756 spin_lock_irq(&tty->ctrl_lock);
1761 if (is_ignored(SIGTTIN) || 1757 if (!tty->pgrp)
1762 is_current_pgrp_orphaned()) 1758 printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
1763 return -EIO; 1759 else if (task_pgrp(current) != tty->pgrp) {
1764 kill_pgrp(task_pgrp(current), SIGTTIN, 1); 1760 spin_unlock_irq(&tty->ctrl_lock);
1765 set_thread_flag(TIF_SIGPENDING); 1761 if (is_ignored(SIGTTIN) || is_current_pgrp_orphaned())
1766 return -ERESTARTSYS; 1762 return -EIO;
1767 } 1763 kill_pgrp(task_pgrp(current), SIGTTIN, 1);
1764 set_thread_flag(TIF_SIGPENDING);
1765 return -ERESTARTSYS;
1768 } 1766 }
1767 spin_unlock_irq(&tty->ctrl_lock);
1769 return 0; 1768 return 0;
1770} 1769}
1771 1770
@@ -1959,10 +1958,17 @@ do_it_again:
1959 * longer than TTY_THRESHOLD_UNTHROTTLE in canonical mode, 1958 * longer than TTY_THRESHOLD_UNTHROTTLE in canonical mode,
1960 * we won't get any more characters. 1959 * we won't get any more characters.
1961 */ 1960 */
1962 if (n_tty_chars_in_buffer(tty) <= TTY_THRESHOLD_UNTHROTTLE) { 1961 while (1) {
1962 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE);
1963 if (n_tty_chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE)
1964 break;
1965 if (!tty->count)
1966 break;
1963 n_tty_set_room(tty); 1967 n_tty_set_room(tty);
1964 check_unthrottle(tty); 1968 if (!tty_unthrottle_safe(tty))
1969 break;
1965 } 1970 }
1971 __tty_set_flow_change(tty, 0);
1966 1972
1967 if (b - buf >= minimum) 1973 if (b - buf >= minimum)
1968 break; 1974 break;
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index 2dff19796157..d6080c3831ef 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -791,7 +791,6 @@ static int send_data(enum port_type index, struct nozomi *dc)
791 const u8 toggle = port->toggle_ul; 791 const u8 toggle = port->toggle_ul;
792 void __iomem *addr = port->ul_addr[toggle]; 792 void __iomem *addr = port->ul_addr[toggle];
793 const u32 ul_size = port->ul_size[toggle]; 793 const u32 ul_size = port->ul_size[toggle];
794 struct tty_struct *tty = tty_port_tty_get(&port->port);
795 794
796 /* Get data from tty and place in buf for now */ 795 /* Get data from tty and place in buf for now */
797 size = kfifo_out(&port->fifo_ul, dc->send_buf, 796 size = kfifo_out(&port->fifo_ul, dc->send_buf,
@@ -799,7 +798,6 @@ static int send_data(enum port_type index, struct nozomi *dc)
799 798
800 if (size == 0) { 799 if (size == 0) {
801 DBG4("No more data to send, disable link:"); 800 DBG4("No more data to send, disable link:");
802 tty_kref_put(tty);
803 return 0; 801 return 0;
804 } 802 }
805 803
@@ -809,10 +807,8 @@ static int send_data(enum port_type index, struct nozomi *dc)
809 write_mem32(addr, (u32 *) &size, 4); 807 write_mem32(addr, (u32 *) &size, 4);
810 write_mem32(addr + 4, (u32 *) dc->send_buf, size); 808 write_mem32(addr + 4, (u32 *) dc->send_buf, size);
811 809
812 if (tty) 810 tty_port_tty_wakeup(&port->port);
813 tty_wakeup(tty);
814 811
815 tty_kref_put(tty);
816 return 1; 812 return 1;
817} 813}
818 814
@@ -1505,12 +1501,9 @@ static void tty_exit(struct nozomi *dc)
1505 1501
1506 DBG1(" "); 1502 DBG1(" ");
1507 1503
1508 for (i = 0; i < MAX_PORT; ++i) { 1504 for (i = 0; i < MAX_PORT; ++i)
1509 struct tty_struct *tty = tty_port_tty_get(&dc->port[i].port); 1505 tty_port_tty_hangup(&dc->port[i].port, false);
1510 if (tty && list_empty(&tty->hangup_work.entry)) 1506
1511 tty_hangup(tty);
1512 tty_kref_put(tty);
1513 }
1514 /* Racy below - surely should wait for scheduled work to be done or 1507 /* Racy below - surely should wait for scheduled work to be done or
1515 complete off a hangup method ? */ 1508 complete off a hangup method ? */
1516 while (dc->open_ttys) 1509 while (dc->open_ttys)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index c24b4db243b9..59bfaecc4e14 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -405,15 +405,8 @@ err:
405 return retval; 405 return retval;
406} 406}
407 407
408/* this is called once with whichever end is closed last */
409static void pty_unix98_shutdown(struct tty_struct *tty)
410{
411 devpts_kill_index(tty->driver_data, tty->index);
412}
413
414static void pty_cleanup(struct tty_struct *tty) 408static void pty_cleanup(struct tty_struct *tty)
415{ 409{
416 tty->port->itty = NULL;
417 tty_port_put(tty->port); 410 tty_port_put(tty->port);
418} 411}
419 412
@@ -627,6 +620,12 @@ static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
627{ 620{
628} 621}
629 622
623/* this is called once with whichever end is closed last */
624static void pty_unix98_shutdown(struct tty_struct *tty)
625{
626 devpts_kill_index(tty->driver_data, tty->index);
627}
628
630static const struct tty_operations ptm_unix98_ops = { 629static const struct tty_operations ptm_unix98_ops = {
631 .lookup = ptm_unix98_lookup, 630 .lookup = ptm_unix98_lookup,
632 .install = pty_unix98_install, 631 .install = pty_unix98_install,
@@ -682,6 +681,9 @@ static int ptmx_open(struct inode *inode, struct file *filp)
682 681
683 nonseekable_open(inode, filp); 682 nonseekable_open(inode, filp);
684 683
684 /* We refuse fsnotify events on ptmx, since it's a shared resource */
685 filp->f_mode |= FMODE_NONOTIFY;
686
685 retval = tty_alloc_file(filp); 687 retval = tty_alloc_file(filp);
686 if (retval) 688 if (retval)
687 return retval; 689 return retval;
diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
index 1d270034bfc3..354564ea47c5 100644
--- a/drivers/tty/rocket.c
+++ b/drivers/tty/rocket.c
@@ -150,12 +150,14 @@ static Word_t aiop_intr_bits[AIOP_CTL_SIZE] = {
150 AIOP_INTR_BIT_3 150 AIOP_INTR_BIT_3
151}; 151};
152 152
153#ifdef CONFIG_PCI
153static Word_t upci_aiop_intr_bits[AIOP_CTL_SIZE] = { 154static Word_t upci_aiop_intr_bits[AIOP_CTL_SIZE] = {
154 UPCI_AIOP_INTR_BIT_0, 155 UPCI_AIOP_INTR_BIT_0,
155 UPCI_AIOP_INTR_BIT_1, 156 UPCI_AIOP_INTR_BIT_1,
156 UPCI_AIOP_INTR_BIT_2, 157 UPCI_AIOP_INTR_BIT_2,
157 UPCI_AIOP_INTR_BIT_3 158 UPCI_AIOP_INTR_BIT_3
158}; 159};
160#endif
159 161
160static Byte_t RData[RDATASIZE] = { 162static Byte_t RData[RDATASIZE] = {
161 0x00, 0x09, 0xf6, 0x82, 163 0x00, 0x09, 0xf6, 0x82,
@@ -227,7 +229,6 @@ static unsigned long nextLineNumber;
227static int __init init_ISA(int i); 229static int __init init_ISA(int i);
228static void rp_wait_until_sent(struct tty_struct *tty, int timeout); 230static void rp_wait_until_sent(struct tty_struct *tty, int timeout);
229static void rp_flush_buffer(struct tty_struct *tty); 231static void rp_flush_buffer(struct tty_struct *tty);
230static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model);
231static unsigned char GetLineNumber(int ctrl, int aiop, int ch); 232static unsigned char GetLineNumber(int ctrl, int aiop, int ch);
232static unsigned char SetLineNumber(int ctrl, int aiop, int ch); 233static unsigned char SetLineNumber(int ctrl, int aiop, int ch);
233static void rp_start(struct tty_struct *tty); 234static void rp_start(struct tty_struct *tty);
@@ -241,11 +242,6 @@ static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags);
241static void sModemReset(CONTROLLER_T * CtlP, int chan, int on); 242static void sModemReset(CONTROLLER_T * CtlP, int chan, int on);
242static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on); 243static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on);
243static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data); 244static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data);
244static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
245 ByteIO_t * AiopIOList, int AiopIOListSize,
246 WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
247 int PeriodicOnly, int altChanRingIndicator,
248 int UPCIRingInd);
249static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO, 245static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
250 ByteIO_t * AiopIOList, int AiopIOListSize, 246 ByteIO_t * AiopIOList, int AiopIOListSize,
251 int IRQNum, Byte_t Frequency, int PeriodicOnly); 247 int IRQNum, Byte_t Frequency, int PeriodicOnly);
@@ -449,7 +445,7 @@ static void rp_do_transmit(struct r_port *info)
449 445
450 /* Loop sending data to FIFO until done or FIFO full */ 446 /* Loop sending data to FIFO until done or FIFO full */
451 while (1) { 447 while (1) {
452 if (tty->stopped || tty->hw_stopped) 448 if (tty->stopped)
453 break; 449 break;
454 c = min(info->xmit_fifo_room, info->xmit_cnt); 450 c = min(info->xmit_fifo_room, info->xmit_cnt);
455 c = min(c, XMIT_BUF_SIZE - info->xmit_tail); 451 c = min(c, XMIT_BUF_SIZE - info->xmit_tail);
@@ -521,15 +517,10 @@ static void rp_handle_port(struct r_port *info)
521 (ChanStatus & CD_ACT) ? "on" : "off"); 517 (ChanStatus & CD_ACT) ? "on" : "off");
522#endif 518#endif
523 if (!(ChanStatus & CD_ACT) && info->cd_status) { 519 if (!(ChanStatus & CD_ACT) && info->cd_status) {
524 struct tty_struct *tty;
525#ifdef ROCKET_DEBUG_HANGUP 520#ifdef ROCKET_DEBUG_HANGUP
526 printk(KERN_INFO "CD drop, calling hangup.\n"); 521 printk(KERN_INFO "CD drop, calling hangup.\n");
527#endif 522#endif
528 tty = tty_port_tty_get(&info->port); 523 tty_port_tty_hangup(&info->port, false);
529 if (tty) {
530 tty_hangup(tty);
531 tty_kref_put(tty);
532 }
533 } 524 }
534 info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0; 525 info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0;
535 wake_up_interruptible(&info->port.open_wait); 526 wake_up_interruptible(&info->port.open_wait);
@@ -1111,15 +1102,12 @@ static void rp_set_termios(struct tty_struct *tty,
1111 1102
1112 /* Handle transition away from B0 status */ 1103 /* Handle transition away from B0 status */
1113 if (!(old_termios->c_cflag & CBAUD) && (tty->termios.c_cflag & CBAUD)) { 1104 if (!(old_termios->c_cflag & CBAUD) && (tty->termios.c_cflag & CBAUD)) {
1114 if (!tty->hw_stopped || !(tty->termios.c_cflag & CRTSCTS)) 1105 sSetRTS(cp);
1115 sSetRTS(cp);
1116 sSetDTR(cp); 1106 sSetDTR(cp);
1117 } 1107 }
1118 1108
1119 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios.c_cflag & CRTSCTS)) { 1109 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios.c_cflag & CRTSCTS))
1120 tty->hw_stopped = 0;
1121 rp_start(tty); 1110 rp_start(tty);
1122 }
1123} 1111}
1124 1112
1125static int rp_break(struct tty_struct *tty, int break_state) 1113static int rp_break(struct tty_struct *tty, int break_state)
@@ -1575,10 +1563,10 @@ static int rp_put_char(struct tty_struct *tty, unsigned char ch)
1575 spin_lock_irqsave(&info->slock, flags); 1563 spin_lock_irqsave(&info->slock, flags);
1576 cp = &info->channel; 1564 cp = &info->channel;
1577 1565
1578 if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room == 0) 1566 if (!tty->stopped && info->xmit_fifo_room == 0)
1579 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp); 1567 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
1580 1568
1581 if (tty->stopped || tty->hw_stopped || info->xmit_fifo_room == 0 || info->xmit_cnt != 0) { 1569 if (tty->stopped || info->xmit_fifo_room == 0 || info->xmit_cnt != 0) {
1582 info->xmit_buf[info->xmit_head++] = ch; 1570 info->xmit_buf[info->xmit_head++] = ch;
1583 info->xmit_head &= XMIT_BUF_SIZE - 1; 1571 info->xmit_head &= XMIT_BUF_SIZE - 1;
1584 info->xmit_cnt++; 1572 info->xmit_cnt++;
@@ -1619,14 +1607,14 @@ static int rp_write(struct tty_struct *tty,
1619#endif 1607#endif
1620 cp = &info->channel; 1608 cp = &info->channel;
1621 1609
1622 if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room < count) 1610 if (!tty->stopped && info->xmit_fifo_room < count)
1623 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp); 1611 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
1624 1612
1625 /* 1613 /*
1626 * If the write queue for the port is empty, and there is FIFO space, stuff bytes 1614 * If the write queue for the port is empty, and there is FIFO space, stuff bytes
1627 * into FIFO. Use the write queue for temp storage. 1615 * into FIFO. Use the write queue for temp storage.
1628 */ 1616 */
1629 if (!tty->stopped && !tty->hw_stopped && info->xmit_cnt == 0 && info->xmit_fifo_room > 0) { 1617 if (!tty->stopped && info->xmit_cnt == 0 && info->xmit_fifo_room > 0) {
1630 c = min(count, info->xmit_fifo_room); 1618 c = min(count, info->xmit_fifo_room);
1631 b = buf; 1619 b = buf;
1632 1620
@@ -1674,7 +1662,7 @@ static int rp_write(struct tty_struct *tty,
1674 retval += c; 1662 retval += c;
1675 } 1663 }
1676 1664
1677 if ((retval > 0) && !tty->stopped && !tty->hw_stopped) 1665 if ((retval > 0) && !tty->stopped)
1678 set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 1666 set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
1679 1667
1680end: 1668end:
@@ -1783,6 +1771,145 @@ static DEFINE_PCI_DEVICE_TABLE(rocket_pci_ids) = {
1783}; 1771};
1784MODULE_DEVICE_TABLE(pci, rocket_pci_ids); 1772MODULE_DEVICE_TABLE(pci, rocket_pci_ids);
1785 1773
1774/* Resets the speaker controller on RocketModem II and III devices */
1775static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model)
1776{
1777 ByteIO_t addr;
1778
1779 /* RocketModem II speaker control is at the 8th port location of offset 0x40 */
1780 if ((model == MODEL_RP4M) || (model == MODEL_RP6M)) {
1781 addr = CtlP->AiopIO[0] + 0x4F;
1782 sOutB(addr, 0);
1783 }
1784
1785 /* RocketModem III speaker control is at the 1st port location of offset 0x80 */
1786 if ((model == MODEL_UPCI_RM3_8PORT)
1787 || (model == MODEL_UPCI_RM3_4PORT)) {
1788 addr = CtlP->AiopIO[0] + 0x88;
1789 sOutB(addr, 0);
1790 }
1791}
1792
1793/***************************************************************************
1794Function: sPCIInitController
1795Purpose: Initialization of controller global registers and controller
1796 structure.
1797Call: sPCIInitController(CtlP,CtlNum,AiopIOList,AiopIOListSize,
1798 IRQNum,Frequency,PeriodicOnly)
1799 CONTROLLER_T *CtlP; Ptr to controller structure
1800 int CtlNum; Controller number
1801 ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
1802 This list must be in the order the AIOPs will be found on the
1803 controller. Once an AIOP in the list is not found, it is
1804 assumed that there are no more AIOPs on the controller.
1805 int AiopIOListSize; Number of addresses in AiopIOList
1806 int IRQNum; Interrupt Request number. Can be any of the following:
1807 0: Disable global interrupts
1808 3: IRQ 3
1809 4: IRQ 4
1810 5: IRQ 5
1811 9: IRQ 9
1812 10: IRQ 10
1813 11: IRQ 11
1814 12: IRQ 12
1815 15: IRQ 15
1816 Byte_t Frequency: A flag identifying the frequency
1817 of the periodic interrupt, can be any one of the following:
1818 FREQ_DIS - periodic interrupt disabled
1819 FREQ_137HZ - 137 Hertz
1820 FREQ_69HZ - 69 Hertz
1821 FREQ_34HZ - 34 Hertz
1822 FREQ_17HZ - 17 Hertz
1823 FREQ_9HZ - 9 Hertz
1824 FREQ_4HZ - 4 Hertz
1825 If IRQNum is set to 0 the Frequency parameter is
1826 overidden, it is forced to a value of FREQ_DIS.
1827 int PeriodicOnly: 1 if all interrupts except the periodic
1828 interrupt are to be blocked.
1829 0 is both the periodic interrupt and
1830 other channel interrupts are allowed.
1831 If IRQNum is set to 0 the PeriodicOnly parameter is
1832 overidden, it is forced to a value of 0.
1833Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
1834 initialization failed.
1835
1836Comments:
1837 If periodic interrupts are to be disabled but AIOP interrupts
1838 are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
1839
1840 If interrupts are to be completely disabled set IRQNum to 0.
1841
1842 Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
1843 invalid combination.
1844
1845 This function performs initialization of global interrupt modes,
1846 but it does not actually enable global interrupts. To enable
1847 and disable global interrupts use functions sEnGlobalInt() and
1848 sDisGlobalInt(). Enabling of global interrupts is normally not
1849 done until all other initializations are complete.
1850
1851 Even if interrupts are globally enabled, they must also be
1852 individually enabled for each channel that is to generate
1853 interrupts.
1854
1855Warnings: No range checking on any of the parameters is done.
1856
1857 No context switches are allowed while executing this function.
1858
1859 After this function all AIOPs on the controller are disabled,
1860 they can be enabled with sEnAiop().
1861*/
1862static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
1863 ByteIO_t * AiopIOList, int AiopIOListSize,
1864 WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
1865 int PeriodicOnly, int altChanRingIndicator,
1866 int UPCIRingInd)
1867{
1868 int i;
1869 ByteIO_t io;
1870
1871 CtlP->AltChanRingIndicator = altChanRingIndicator;
1872 CtlP->UPCIRingInd = UPCIRingInd;
1873 CtlP->CtlNum = CtlNum;
1874 CtlP->CtlID = CTLID_0001; /* controller release 1 */
1875 CtlP->BusType = isPCI; /* controller release 1 */
1876
1877 if (ConfigIO) {
1878 CtlP->isUPCI = 1;
1879 CtlP->PCIIO = ConfigIO + _PCI_9030_INT_CTRL;
1880 CtlP->PCIIO2 = ConfigIO + _PCI_9030_GPIO_CTRL;
1881 CtlP->AiopIntrBits = upci_aiop_intr_bits;
1882 } else {
1883 CtlP->isUPCI = 0;
1884 CtlP->PCIIO =
1885 (WordIO_t) ((ByteIO_t) AiopIOList[0] + _PCI_INT_FUNC);
1886 CtlP->AiopIntrBits = aiop_intr_bits;
1887 }
1888
1889 sPCIControllerEOI(CtlP); /* clear EOI if warm init */
1890 /* Init AIOPs */
1891 CtlP->NumAiop = 0;
1892 for (i = 0; i < AiopIOListSize; i++) {
1893 io = AiopIOList[i];
1894 CtlP->AiopIO[i] = (WordIO_t) io;
1895 CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
1896
1897 CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
1898 if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
1899 break; /* done looking for AIOPs */
1900
1901 CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
1902 sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
1903 sOutB(io + _INDX_DATA, sClockPrescale);
1904 CtlP->NumAiop++; /* bump count of AIOPs */
1905 }
1906
1907 if (CtlP->NumAiop == 0)
1908 return (-1);
1909 else
1910 return (CtlP->NumAiop);
1911}
1912
1786/* 1913/*
1787 * Called when a PCI card is found. Retrieves and stores model information, 1914 * Called when a PCI card is found. Retrieves and stores model information,
1788 * init's aiopic and serial port hardware. 1915 * init's aiopic and serial port hardware.
@@ -2528,126 +2655,6 @@ static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
2528} 2655}
2529 2656
2530/*************************************************************************** 2657/***************************************************************************
2531Function: sPCIInitController
2532Purpose: Initialization of controller global registers and controller
2533 structure.
2534Call: sPCIInitController(CtlP,CtlNum,AiopIOList,AiopIOListSize,
2535 IRQNum,Frequency,PeriodicOnly)
2536 CONTROLLER_T *CtlP; Ptr to controller structure
2537 int CtlNum; Controller number
2538 ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
2539 This list must be in the order the AIOPs will be found on the
2540 controller. Once an AIOP in the list is not found, it is
2541 assumed that there are no more AIOPs on the controller.
2542 int AiopIOListSize; Number of addresses in AiopIOList
2543 int IRQNum; Interrupt Request number. Can be any of the following:
2544 0: Disable global interrupts
2545 3: IRQ 3
2546 4: IRQ 4
2547 5: IRQ 5
2548 9: IRQ 9
2549 10: IRQ 10
2550 11: IRQ 11
2551 12: IRQ 12
2552 15: IRQ 15
2553 Byte_t Frequency: A flag identifying the frequency
2554 of the periodic interrupt, can be any one of the following:
2555 FREQ_DIS - periodic interrupt disabled
2556 FREQ_137HZ - 137 Hertz
2557 FREQ_69HZ - 69 Hertz
2558 FREQ_34HZ - 34 Hertz
2559 FREQ_17HZ - 17 Hertz
2560 FREQ_9HZ - 9 Hertz
2561 FREQ_4HZ - 4 Hertz
2562 If IRQNum is set to 0 the Frequency parameter is
2563 overidden, it is forced to a value of FREQ_DIS.
2564 int PeriodicOnly: 1 if all interrupts except the periodic
2565 interrupt are to be blocked.
2566 0 is both the periodic interrupt and
2567 other channel interrupts are allowed.
2568 If IRQNum is set to 0 the PeriodicOnly parameter is
2569 overidden, it is forced to a value of 0.
2570Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
2571 initialization failed.
2572
2573Comments:
2574 If periodic interrupts are to be disabled but AIOP interrupts
2575 are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
2576
2577 If interrupts are to be completely disabled set IRQNum to 0.
2578
2579 Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
2580 invalid combination.
2581
2582 This function performs initialization of global interrupt modes,
2583 but it does not actually enable global interrupts. To enable
2584 and disable global interrupts use functions sEnGlobalInt() and
2585 sDisGlobalInt(). Enabling of global interrupts is normally not
2586 done until all other initializations are complete.
2587
2588 Even if interrupts are globally enabled, they must also be
2589 individually enabled for each channel that is to generate
2590 interrupts.
2591
2592Warnings: No range checking on any of the parameters is done.
2593
2594 No context switches are allowed while executing this function.
2595
2596 After this function all AIOPs on the controller are disabled,
2597 they can be enabled with sEnAiop().
2598*/
2599static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
2600 ByteIO_t * AiopIOList, int AiopIOListSize,
2601 WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
2602 int PeriodicOnly, int altChanRingIndicator,
2603 int UPCIRingInd)
2604{
2605 int i;
2606 ByteIO_t io;
2607
2608 CtlP->AltChanRingIndicator = altChanRingIndicator;
2609 CtlP->UPCIRingInd = UPCIRingInd;
2610 CtlP->CtlNum = CtlNum;
2611 CtlP->CtlID = CTLID_0001; /* controller release 1 */
2612 CtlP->BusType = isPCI; /* controller release 1 */
2613
2614 if (ConfigIO) {
2615 CtlP->isUPCI = 1;
2616 CtlP->PCIIO = ConfigIO + _PCI_9030_INT_CTRL;
2617 CtlP->PCIIO2 = ConfigIO + _PCI_9030_GPIO_CTRL;
2618 CtlP->AiopIntrBits = upci_aiop_intr_bits;
2619 } else {
2620 CtlP->isUPCI = 0;
2621 CtlP->PCIIO =
2622 (WordIO_t) ((ByteIO_t) AiopIOList[0] + _PCI_INT_FUNC);
2623 CtlP->AiopIntrBits = aiop_intr_bits;
2624 }
2625
2626 sPCIControllerEOI(CtlP); /* clear EOI if warm init */
2627 /* Init AIOPs */
2628 CtlP->NumAiop = 0;
2629 for (i = 0; i < AiopIOListSize; i++) {
2630 io = AiopIOList[i];
2631 CtlP->AiopIO[i] = (WordIO_t) io;
2632 CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
2633
2634 CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
2635 if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
2636 break; /* done looking for AIOPs */
2637
2638 CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
2639 sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
2640 sOutB(io + _INDX_DATA, sClockPrescale);
2641 CtlP->NumAiop++; /* bump count of AIOPs */
2642 }
2643
2644 if (CtlP->NumAiop == 0)
2645 return (-1);
2646 else
2647 return (CtlP->NumAiop);
2648}
2649
2650/***************************************************************************
2651Function: sReadAiopID 2658Function: sReadAiopID
2652Purpose: Read the AIOP idenfication number directly from an AIOP. 2659Purpose: Read the AIOP idenfication number directly from an AIOP.
2653Call: sReadAiopID(io) 2660Call: sReadAiopID(io)
@@ -3136,25 +3143,6 @@ static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on)
3136 sOutB(addr + chan, 0); /* apply or remove reset */ 3143 sOutB(addr + chan, 0); /* apply or remove reset */
3137} 3144}
3138 3145
3139/* Resets the speaker controller on RocketModem II and III devices */
3140static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model)
3141{
3142 ByteIO_t addr;
3143
3144 /* RocketModem II speaker control is at the 8th port location of offset 0x40 */
3145 if ((model == MODEL_RP4M) || (model == MODEL_RP6M)) {
3146 addr = CtlP->AiopIO[0] + 0x4F;
3147 sOutB(addr, 0);
3148 }
3149
3150 /* RocketModem III speaker control is at the 1st port location of offset 0x80 */
3151 if ((model == MODEL_UPCI_RM3_8PORT)
3152 || (model == MODEL_UPCI_RM3_4PORT)) {
3153 addr = CtlP->AiopIO[0] + 0x88;
3154 sOutB(addr, 0);
3155 }
3156}
3157
3158/* Returns the line number given the controller (board), aiop and channel number */ 3146/* Returns the line number given the controller (board), aiop and channel number */
3159static unsigned char GetLineNumber(int ctrl, int aiop, int ch) 3147static unsigned char GetLineNumber(int ctrl, int aiop, int ch)
3160{ 3148{
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c
index 49399470794d..5dc9c4bfa66e 100644
--- a/drivers/tty/serial/68328serial.c
+++ b/drivers/tty/serial/68328serial.c
@@ -14,7 +14,6 @@
14 * 2.4/2.5 port David McCullough 14 * 2.4/2.5 port David McCullough
15 */ 15 */
16 16
17#include <asm/dbg.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/errno.h> 18#include <linux/errno.h>
20#include <linux/serial.h> 19#include <linux/serial.h>
@@ -630,8 +629,7 @@ static void rs_flush_chars(struct tty_struct *tty)
630 /* Enable transmitter */ 629 /* Enable transmitter */
631 local_irq_save(flags); 630 local_irq_save(flags);
632 631
633 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || 632 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf) {
634 !info->xmit_buf) {
635 local_irq_restore(flags); 633 local_irq_restore(flags);
636 return; 634 return;
637 } 635 }
@@ -697,7 +695,7 @@ static int rs_write(struct tty_struct * tty,
697 total += c; 695 total += c;
698 } 696 }
699 697
700 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) { 698 if (info->xmit_cnt && !tty->stopped) {
701 /* Enable transmitter */ 699 /* Enable transmitter */
702 local_irq_disable(); 700 local_irq_disable();
703#ifndef USE_INTS 701#ifndef USE_INTS
@@ -978,10 +976,8 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
978 change_speed(info, tty); 976 change_speed(info, tty);
979 977
980 if ((old_termios->c_cflag & CRTSCTS) && 978 if ((old_termios->c_cflag & CRTSCTS) &&
981 !(tty->termios.c_cflag & CRTSCTS)) { 979 !(tty->termios.c_cflag & CRTSCTS))
982 tty->hw_stopped = 0;
983 rs_start(tty); 980 rs_start(tty);
984 }
985 981
986} 982}
987 983
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index 34eb676916fe..1ebf8538b4fa 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -117,13 +117,6 @@ static inline void serial_dl_write(struct uart_8250_port *up, int value)
117 * is cleared, the machine locks up with endless interrupts. 117 * is cleared, the machine locks up with endless interrupts.
118 */ 118 */
119#define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1) 119#define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1)
120#elif defined(CONFIG_SBC8560)
121/*
122 * WindRiver did something similarly broken on their SBC8560 board. The
123 * UART tristates its IRQ output while OUT2 is clear, but they pulled
124 * the interrupt line _up_ instead of down, so if we register the IRQ
125 * while the UART is in that state, we die in an IRQ storm. */
126#define ALPHA_KLUDGE_MCR (UART_MCR_OUT2)
127#else 120#else
128#define ALPHA_KLUDGE_MCR 0 121#define ALPHA_KLUDGE_MCR 0
129#endif 122#endif
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250_core.c
index cf6a5383748a..86c00b1c5583 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -3247,6 +3247,10 @@ int serial8250_register_8250_port(struct uart_8250_port *up)
3247 uart->tx_loadsz = up->tx_loadsz; 3247 uart->tx_loadsz = up->tx_loadsz;
3248 uart->capabilities = up->capabilities; 3248 uart->capabilities = up->capabilities;
3249 3249
3250 /* Take tx_loadsz from fifosize if it wasn't set separately */
3251 if (uart->port.fifosize && !uart->tx_loadsz)
3252 uart->tx_loadsz = uart->port.fifosize;
3253
3250 if (up->port.dev) 3254 if (up->port.dev)
3251 uart->port.dev = up->port.dev; 3255 uart->port.dev = up->port.dev;
3252 3256
@@ -3418,6 +3422,7 @@ MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
3418#endif 3422#endif
3419MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); 3423MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
3420 3424
3425#ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
3421#ifndef MODULE 3426#ifndef MODULE
3422/* This module was renamed to 8250_core in 3.7. Keep the old "8250" name 3427/* This module was renamed to 8250_core in 3.7. Keep the old "8250" name
3423 * working as well for the module options so we don't break people. We 3428 * working as well for the module options so we don't break people. We
@@ -3432,7 +3437,7 @@ MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
3432static void __used s8250_options(void) 3437static void __used s8250_options(void)
3433{ 3438{
3434#undef MODULE_PARAM_PREFIX 3439#undef MODULE_PARAM_PREFIX
3435#define MODULE_PARAM_PREFIX "8250." 3440#define MODULE_PARAM_PREFIX "8250_core."
3436 3441
3437 module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644); 3442 module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644);
3438 module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644); 3443 module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644);
@@ -3444,5 +3449,6 @@ static void __used s8250_options(void)
3444#endif 3449#endif
3445} 3450}
3446#else 3451#else
3447MODULE_ALIAS("8250"); 3452MODULE_ALIAS("8250_core");
3453#endif
3448#endif 3454#endif
diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
index b9f7fd28112e..7046769608d4 100644
--- a/drivers/tty/serial/8250/8250_dma.c
+++ b/drivers/tty/serial/8250/8250_dma.c
@@ -33,10 +33,8 @@ static void __dma_tx_complete(void *param)
33 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 33 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
34 uart_write_wakeup(&p->port); 34 uart_write_wakeup(&p->port);
35 35
36 if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port)) { 36 if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port))
37 serial8250_tx_dma(p); 37 serial8250_tx_dma(p);
38 uart_write_wakeup(&p->port);
39 }
40} 38}
41 39
42static void __dma_rx_complete(void *param) 40static void __dma_rx_complete(void *param)
@@ -67,12 +65,11 @@ int serial8250_tx_dma(struct uart_8250_port *p)
67 struct circ_buf *xmit = &p->port.state->xmit; 65 struct circ_buf *xmit = &p->port.state->xmit;
68 struct dma_async_tx_descriptor *desc; 66 struct dma_async_tx_descriptor *desc;
69 67
70 if (dma->tx_running) 68 if (uart_tx_stopped(&p->port) || dma->tx_running ||
71 return -EBUSY; 69 uart_circ_empty(xmit))
70 return 0;
72 71
73 dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); 72 dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
74 if (!dma->tx_size)
75 return -EINVAL;
76 73
77 desc = dmaengine_prep_slave_single(dma->txchan, 74 desc = dmaengine_prep_slave_single(dma->txchan,
78 dma->tx_addr + xmit->tail, 75 dma->tx_addr + xmit->tail,
@@ -104,20 +101,29 @@ int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
104 struct dma_tx_state state; 101 struct dma_tx_state state;
105 int dma_status; 102 int dma_status;
106 103
107 /* 104 dma_status = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
108 * If RCVR FIFO trigger level was not reached, complete the transfer and 105
109 * let 8250.c copy the remaining data. 106 switch (iir & 0x3f) {
110 */ 107 case UART_IIR_RLSI:
111 if ((iir & 0x3f) == UART_IIR_RX_TIMEOUT) { 108 /* 8250_core handles errors and break interrupts */
112 dma_status = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, 109 return -EIO;
113 &state); 110 case UART_IIR_RX_TIMEOUT:
111 /*
112 * If RCVR FIFO trigger level was not reached, complete the
113 * transfer and let 8250_core copy the remaining data.
114 */
114 if (dma_status == DMA_IN_PROGRESS) { 115 if (dma_status == DMA_IN_PROGRESS) {
115 dmaengine_pause(dma->rxchan); 116 dmaengine_pause(dma->rxchan);
116 __dma_rx_complete(p); 117 __dma_rx_complete(p);
117 } 118 }
118 return -ETIMEDOUT; 119 return -ETIMEDOUT;
120 default:
121 break;
119 } 122 }
120 123
124 if (dma_status)
125 return 0;
126
121 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, 127 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
122 dma->rx_size, DMA_DEV_TO_MEM, 128 dma->rx_size, DMA_DEV_TO_MEM,
123 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 129 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
@@ -143,21 +149,31 @@ int serial8250_request_dma(struct uart_8250_port *p)
143 struct uart_8250_dma *dma = p->dma; 149 struct uart_8250_dma *dma = p->dma;
144 dma_cap_mask_t mask; 150 dma_cap_mask_t mask;
145 151
146 dma->rxconf.src_addr = p->port.mapbase + UART_RX; 152 /* Default slave configuration parameters */
147 dma->txconf.dst_addr = p->port.mapbase + UART_TX; 153 dma->rxconf.direction = DMA_DEV_TO_MEM;
154 dma->rxconf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
155 dma->rxconf.src_addr = p->port.mapbase + UART_RX;
156
157 dma->txconf.direction = DMA_MEM_TO_DEV;
158 dma->txconf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
159 dma->txconf.dst_addr = p->port.mapbase + UART_TX;
148 160
149 dma_cap_zero(mask); 161 dma_cap_zero(mask);
150 dma_cap_set(DMA_SLAVE, mask); 162 dma_cap_set(DMA_SLAVE, mask);
151 163
152 /* Get a channel for RX */ 164 /* Get a channel for RX */
153 dma->rxchan = dma_request_channel(mask, dma->fn, dma->rx_param); 165 dma->rxchan = dma_request_slave_channel_compat(mask,
166 dma->fn, dma->rx_param,
167 p->port.dev, "rx");
154 if (!dma->rxchan) 168 if (!dma->rxchan)
155 return -ENODEV; 169 return -ENODEV;
156 170
157 dmaengine_slave_config(dma->rxchan, &dma->rxconf); 171 dmaengine_slave_config(dma->rxchan, &dma->rxconf);
158 172
159 /* Get a channel for TX */ 173 /* Get a channel for TX */
160 dma->txchan = dma_request_channel(mask, dma->fn, dma->tx_param); 174 dma->txchan = dma_request_slave_channel_compat(mask,
175 dma->fn, dma->tx_param,
176 p->port.dev, "tx");
161 if (!dma->txchan) { 177 if (!dma->txchan) {
162 dma_release_channel(dma->rxchan); 178 dma_release_channel(dma->rxchan);
163 return -ENODEV; 179 return -ENODEV;
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index db0e66f6dd0e..d07b6af3a937 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -26,6 +26,8 @@
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/acpi.h> 28#include <linux/acpi.h>
29#include <linux/clk.h>
30#include <linux/pm_runtime.h>
29 31
30#include "8250.h" 32#include "8250.h"
31 33
@@ -34,9 +36,6 @@
34#define DW_UART_CPR 0xf4 /* Component Parameter Register */ 36#define DW_UART_CPR 0xf4 /* Component Parameter Register */
35#define DW_UART_UCV 0xf8 /* UART Component Version */ 37#define DW_UART_UCV 0xf8 /* UART Component Version */
36 38
37/* Intel Low Power Subsystem specific */
38#define LPSS_PRV_CLOCK_PARAMS 0x800
39
40/* Component Parameter Register bits */ 39/* Component Parameter Register bits */
41#define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0) 40#define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0)
42#define DW_UART_CPR_AFCE_MODE (1 << 4) 41#define DW_UART_CPR_AFCE_MODE (1 << 4)
@@ -55,8 +54,9 @@
55 54
56 55
57struct dw8250_data { 56struct dw8250_data {
58 int last_lcr; 57 int last_lcr;
59 int line; 58 int line;
59 struct clk *clk;
60}; 60};
61 61
62static void dw8250_serial_out(struct uart_port *p, int offset, int value) 62static void dw8250_serial_out(struct uart_port *p, int offset, int value)
@@ -113,6 +113,18 @@ static int dw8250_handle_irq(struct uart_port *p)
113 return 0; 113 return 0;
114} 114}
115 115
116static void
117dw8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old)
118{
119 if (!state)
120 pm_runtime_get_sync(port->dev);
121
122 serial8250_do_pm(port, state, old);
123
124 if (state)
125 pm_runtime_put_sync_suspend(port->dev);
126}
127
116static int dw8250_probe_of(struct uart_port *p) 128static int dw8250_probe_of(struct uart_port *p)
117{ 129{
118 struct device_node *np = p->dev->of_node; 130 struct device_node *np = p->dev->of_node;
@@ -136,8 +148,13 @@ static int dw8250_probe_of(struct uart_port *p)
136 if (!of_property_read_u32(np, "reg-shift", &val)) 148 if (!of_property_read_u32(np, "reg-shift", &val))
137 p->regshift = val; 149 p->regshift = val;
138 150
151 /* clock got configured through clk api, all done */
152 if (p->uartclk)
153 return 0;
154
155 /* try to find out clock frequency from DT as fallback */
139 if (of_property_read_u32(np, "clock-frequency", &val)) { 156 if (of_property_read_u32(np, "clock-frequency", &val)) {
140 dev_err(p->dev, "no clock-frequency property set\n"); 157 dev_err(p->dev, "clk or clock-frequency not defined\n");
141 return -EINVAL; 158 return -EINVAL;
142 } 159 }
143 p->uartclk = val; 160 p->uartclk = val;
@@ -146,67 +163,10 @@ static int dw8250_probe_of(struct uart_port *p)
146} 163}
147 164
148#ifdef CONFIG_ACPI 165#ifdef CONFIG_ACPI
149static bool dw8250_acpi_dma_filter(struct dma_chan *chan, void *parm) 166static int dw8250_probe_acpi(struct uart_8250_port *up)
150{
151 return chan->chan_id == *(int *)parm;
152}
153
154static acpi_status
155dw8250_acpi_walk_resource(struct acpi_resource *res, void *data)
156{
157 struct uart_port *p = data;
158 struct uart_8250_port *port;
159 struct uart_8250_dma *dma;
160 struct acpi_resource_fixed_dma *fixed_dma;
161 struct dma_slave_config *slave;
162
163 port = container_of(p, struct uart_8250_port, port);
164
165 switch (res->type) {
166 case ACPI_RESOURCE_TYPE_FIXED_DMA:
167 fixed_dma = &res->data.fixed_dma;
168
169 /* TX comes first */
170 if (!port->dma) {
171 dma = devm_kzalloc(p->dev, sizeof(*dma), GFP_KERNEL);
172 if (!dma)
173 return AE_NO_MEMORY;
174
175 port->dma = dma;
176 slave = &dma->txconf;
177
178 slave->direction = DMA_MEM_TO_DEV;
179 slave->dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
180 slave->slave_id = fixed_dma->request_lines;
181 slave->dst_maxburst = port->tx_loadsz / 4;
182
183 dma->tx_chan_id = fixed_dma->channels;
184 dma->tx_param = &dma->tx_chan_id;
185 dma->fn = dw8250_acpi_dma_filter;
186 } else {
187 dma = port->dma;
188 slave = &dma->rxconf;
189
190 slave->direction = DMA_DEV_TO_MEM;
191 slave->src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
192 slave->slave_id = fixed_dma->request_lines;
193 slave->src_maxburst = p->fifosize / 4;
194
195 dma->rx_chan_id = fixed_dma->channels;
196 dma->rx_param = &dma->rx_chan_id;
197 }
198
199 break;
200 }
201
202 return AE_OK;
203}
204
205static int dw8250_probe_acpi(struct uart_port *p)
206{ 167{
207 const struct acpi_device_id *id; 168 const struct acpi_device_id *id;
208 acpi_status status; 169 struct uart_port *p = &up->port;
209 u32 reg;
210 170
211 id = acpi_match_device(p->dev->driver->acpi_match_table, p->dev); 171 id = acpi_match_device(p->dev->driver->acpi_match_table, p->dev);
212 if (!id) 172 if (!id)
@@ -216,26 +176,21 @@ static int dw8250_probe_acpi(struct uart_port *p)
216 p->serial_in = dw8250_serial_in32; 176 p->serial_in = dw8250_serial_in32;
217 p->serial_out = dw8250_serial_out32; 177 p->serial_out = dw8250_serial_out32;
218 p->regshift = 2; 178 p->regshift = 2;
219 p->uartclk = (unsigned int)id->driver_data;
220 179
221 status = acpi_walk_resources(ACPI_HANDLE(p->dev), METHOD_NAME__CRS, 180 if (!p->uartclk)
222 dw8250_acpi_walk_resource, p); 181 p->uartclk = (unsigned int)id->driver_data;
223 if (ACPI_FAILURE(status)) {
224 dev_err_ratelimited(p->dev, "%s failed \"%s\"\n", __func__,
225 acpi_format_exception(status));
226 return -ENODEV;
227 }
228 182
229 /* Fix Haswell issue where the clocks do not get enabled */ 183 up->dma = devm_kzalloc(p->dev, sizeof(*up->dma), GFP_KERNEL);
230 if (!strcmp(id->id, "INT33C4") || !strcmp(id->id, "INT33C5")) { 184 if (!up->dma)
231 reg = readl(p->membase + LPSS_PRV_CLOCK_PARAMS); 185 return -ENOMEM;
232 writel(reg | 1, p->membase + LPSS_PRV_CLOCK_PARAMS); 186
233 } 187 up->dma->rxconf.src_maxburst = p->fifosize / 4;
188 up->dma->txconf.dst_maxburst = p->fifosize / 4;
234 189
235 return 0; 190 return 0;
236} 191}
237#else 192#else
238static inline int dw8250_probe_acpi(struct uart_port *p) 193static inline int dw8250_probe_acpi(struct uart_8250_port *up)
239{ 194{
240 return -ENODEV; 195 return -ENODEV;
241} 196}
@@ -266,7 +221,11 @@ static void dw8250_setup_port(struct uart_8250_port *up)
266 p->flags |= UPF_FIXED_TYPE; 221 p->flags |= UPF_FIXED_TYPE;
267 p->fifosize = DW_UART_CPR_FIFO_SIZE(reg); 222 p->fifosize = DW_UART_CPR_FIFO_SIZE(reg);
268 up->tx_loadsz = p->fifosize; 223 up->tx_loadsz = p->fifosize;
224 up->capabilities = UART_CAP_FIFO;
269 } 225 }
226
227 if (reg & DW_UART_CPR_AFCE_MODE)
228 up->capabilities |= UART_CAP_AFE;
270} 229}
271 230
272static int dw8250_probe(struct platform_device *pdev) 231static int dw8250_probe(struct platform_device *pdev)
@@ -286,17 +245,30 @@ static int dw8250_probe(struct platform_device *pdev)
286 uart.port.mapbase = regs->start; 245 uart.port.mapbase = regs->start;
287 uart.port.irq = irq->start; 246 uart.port.irq = irq->start;
288 uart.port.handle_irq = dw8250_handle_irq; 247 uart.port.handle_irq = dw8250_handle_irq;
248 uart.port.pm = dw8250_do_pm;
289 uart.port.type = PORT_8250; 249 uart.port.type = PORT_8250;
290 uart.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT; 250 uart.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
291 uart.port.dev = &pdev->dev; 251 uart.port.dev = &pdev->dev;
292 252
293 uart.port.membase = ioremap(regs->start, resource_size(regs)); 253 uart.port.membase = devm_ioremap(&pdev->dev, regs->start,
254 resource_size(regs));
294 if (!uart.port.membase) 255 if (!uart.port.membase)
295 return -ENOMEM; 256 return -ENOMEM;
296 257
258 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
259 if (!data)
260 return -ENOMEM;
261
262 data->clk = devm_clk_get(&pdev->dev, NULL);
263 if (!IS_ERR(data->clk)) {
264 clk_prepare_enable(data->clk);
265 uart.port.uartclk = clk_get_rate(data->clk);
266 }
267
297 uart.port.iotype = UPIO_MEM; 268 uart.port.iotype = UPIO_MEM;
298 uart.port.serial_in = dw8250_serial_in; 269 uart.port.serial_in = dw8250_serial_in;
299 uart.port.serial_out = dw8250_serial_out; 270 uart.port.serial_out = dw8250_serial_out;
271 uart.port.private_data = data;
300 272
301 dw8250_setup_port(&uart); 273 dw8250_setup_port(&uart);
302 274
@@ -305,25 +277,22 @@ static int dw8250_probe(struct platform_device *pdev)
305 if (err) 277 if (err)
306 return err; 278 return err;
307 } else if (ACPI_HANDLE(&pdev->dev)) { 279 } else if (ACPI_HANDLE(&pdev->dev)) {
308 err = dw8250_probe_acpi(&uart.port); 280 err = dw8250_probe_acpi(&uart);
309 if (err) 281 if (err)
310 return err; 282 return err;
311 } else { 283 } else {
312 return -ENODEV; 284 return -ENODEV;
313 } 285 }
314 286
315 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
316 if (!data)
317 return -ENOMEM;
318
319 uart.port.private_data = data;
320
321 data->line = serial8250_register_8250_port(&uart); 287 data->line = serial8250_register_8250_port(&uart);
322 if (data->line < 0) 288 if (data->line < 0)
323 return data->line; 289 return data->line;
324 290
325 platform_set_drvdata(pdev, data); 291 platform_set_drvdata(pdev, data);
326 292
293 pm_runtime_set_active(&pdev->dev);
294 pm_runtime_enable(&pdev->dev);
295
327 return 0; 296 return 0;
328} 297}
329 298
@@ -331,34 +300,66 @@ static int dw8250_remove(struct platform_device *pdev)
331{ 300{
332 struct dw8250_data *data = platform_get_drvdata(pdev); 301 struct dw8250_data *data = platform_get_drvdata(pdev);
333 302
303 pm_runtime_get_sync(&pdev->dev);
304
334 serial8250_unregister_port(data->line); 305 serial8250_unregister_port(data->line);
335 306
307 if (!IS_ERR(data->clk))
308 clk_disable_unprepare(data->clk);
309
310 pm_runtime_disable(&pdev->dev);
311 pm_runtime_put_noidle(&pdev->dev);
312
336 return 0; 313 return 0;
337} 314}
338 315
339#ifdef CONFIG_PM 316#ifdef CONFIG_PM
340static int dw8250_suspend(struct platform_device *pdev, pm_message_t state) 317static int dw8250_suspend(struct device *dev)
341{ 318{
342 struct dw8250_data *data = platform_get_drvdata(pdev); 319 struct dw8250_data *data = dev_get_drvdata(dev);
343 320
344 serial8250_suspend_port(data->line); 321 serial8250_suspend_port(data->line);
345 322
346 return 0; 323 return 0;
347} 324}
348 325
349static int dw8250_resume(struct platform_device *pdev) 326static int dw8250_resume(struct device *dev)
350{ 327{
351 struct dw8250_data *data = platform_get_drvdata(pdev); 328 struct dw8250_data *data = dev_get_drvdata(dev);
352 329
353 serial8250_resume_port(data->line); 330 serial8250_resume_port(data->line);
354 331
355 return 0; 332 return 0;
356} 333}
357#else
358#define dw8250_suspend NULL
359#define dw8250_resume NULL
360#endif /* CONFIG_PM */ 334#endif /* CONFIG_PM */
361 335
336#ifdef CONFIG_PM_RUNTIME
337static int dw8250_runtime_suspend(struct device *dev)
338{
339 struct dw8250_data *data = dev_get_drvdata(dev);
340
341 if (!IS_ERR(data->clk))
342 clk_disable_unprepare(data->clk);
343
344 return 0;
345}
346
347static int dw8250_runtime_resume(struct device *dev)
348{
349 struct dw8250_data *data = dev_get_drvdata(dev);
350
351 if (!IS_ERR(data->clk))
352 clk_prepare_enable(data->clk);
353
354 return 0;
355}
356#endif
357
358static const struct dev_pm_ops dw8250_pm_ops = {
359 SET_SYSTEM_SLEEP_PM_OPS(dw8250_suspend, dw8250_resume)
360 SET_RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL)
361};
362
362static const struct of_device_id dw8250_of_match[] = { 363static const struct of_device_id dw8250_of_match[] = {
363 { .compatible = "snps,dw-apb-uart" }, 364 { .compatible = "snps,dw-apb-uart" },
364 { /* Sentinel */ } 365 { /* Sentinel */ }
@@ -366,8 +367,9 @@ static const struct of_device_id dw8250_of_match[] = {
366MODULE_DEVICE_TABLE(of, dw8250_of_match); 367MODULE_DEVICE_TABLE(of, dw8250_of_match);
367 368
368static const struct acpi_device_id dw8250_acpi_match[] = { 369static const struct acpi_device_id dw8250_acpi_match[] = {
369 { "INT33C4", 100000000 }, 370 { "INT33C4", 0 },
370 { "INT33C5", 100000000 }, 371 { "INT33C5", 0 },
372 { "80860F0A", 0 },
371 { }, 373 { },
372}; 374};
373MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match); 375MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match);
@@ -376,13 +378,12 @@ static struct platform_driver dw8250_platform_driver = {
376 .driver = { 378 .driver = {
377 .name = "dw-apb-uart", 379 .name = "dw-apb-uart",
378 .owner = THIS_MODULE, 380 .owner = THIS_MODULE,
381 .pm = &dw8250_pm_ops,
379 .of_match_table = dw8250_of_match, 382 .of_match_table = dw8250_of_match,
380 .acpi_match_table = ACPI_PTR(dw8250_acpi_match), 383 .acpi_match_table = ACPI_PTR(dw8250_acpi_match),
381 }, 384 },
382 .probe = dw8250_probe, 385 .probe = dw8250_probe,
383 .remove = dw8250_remove, 386 .remove = dw8250_remove,
384 .suspend = dw8250_suspend,
385 .resume = dw8250_resume,
386}; 387};
387 388
388module_platform_driver(dw8250_platform_driver); 389module_platform_driver(dw8250_platform_driver);
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index aa76825229dc..26e3a97ab157 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1554,6 +1554,7 @@ pci_wch_ch353_setup(struct serial_private *priv,
1554#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001 1554#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001
1555#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d 1555#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
1556#define PCI_VENDOR_ID_WCH 0x4348 1556#define PCI_VENDOR_ID_WCH 0x4348
1557#define PCI_DEVICE_ID_WCH_CH352_2S 0x3253
1557#define PCI_DEVICE_ID_WCH_CH353_4S 0x3453 1558#define PCI_DEVICE_ID_WCH_CH353_4S 0x3453
1558#define PCI_DEVICE_ID_WCH_CH353_2S1PF 0x5046 1559#define PCI_DEVICE_ID_WCH_CH353_2S1PF 0x5046
1559#define PCI_DEVICE_ID_WCH_CH353_2S1P 0x7053 1560#define PCI_DEVICE_ID_WCH_CH353_2S1P 0x7053
@@ -2172,6 +2173,14 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
2172 .subdevice = PCI_ANY_ID, 2173 .subdevice = PCI_ANY_ID,
2173 .setup = pci_wch_ch353_setup, 2174 .setup = pci_wch_ch353_setup,
2174 }, 2175 },
2176 /* WCH CH352 2S card (16550 clone) */
2177 {
2178 .vendor = PCI_VENDOR_ID_WCH,
2179 .device = PCI_DEVICE_ID_WCH_CH352_2S,
2180 .subvendor = PCI_ANY_ID,
2181 .subdevice = PCI_ANY_ID,
2182 .setup = pci_wch_ch353_setup,
2183 },
2175 /* 2184 /*
2176 * ASIX devices with FIFO bug 2185 * ASIX devices with FIFO bug
2177 */ 2186 */
@@ -4870,6 +4879,10 @@ static struct pci_device_id serial_pci_tbl[] = {
4870 PCI_ANY_ID, PCI_ANY_ID, 4879 PCI_ANY_ID, PCI_ANY_ID,
4871 0, 0, pbn_b0_bt_2_115200 }, 4880 0, 0, pbn_b0_bt_2_115200 },
4872 4881
4882 { PCI_VENDOR_ID_WCH, PCI_DEVICE_ID_WCH_CH352_2S,
4883 PCI_ANY_ID, PCI_ANY_ID,
4884 0, 0, pbn_b0_bt_2_115200 },
4885
4873 /* 4886 /*
4874 * Commtech, Inc. Fastcom adapters 4887 * Commtech, Inc. Fastcom adapters
4875 */ 4888 */
diff --git a/drivers/tty/serial/8250/8250_pnp.c b/drivers/tty/serial/8250/8250_pnp.c
index b3455a970a1d..35d9ab95c5cb 100644
--- a/drivers/tty/serial/8250/8250_pnp.c
+++ b/drivers/tty/serial/8250/8250_pnp.c
@@ -429,7 +429,6 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
429{ 429{
430 struct uart_8250_port uart; 430 struct uart_8250_port uart;
431 int ret, line, flags = dev_id->driver_data; 431 int ret, line, flags = dev_id->driver_data;
432 struct resource *res = NULL;
433 432
434 if (flags & UNKNOWN_DEV) { 433 if (flags & UNKNOWN_DEV) {
435 ret = serial_pnp_guess_board(dev); 434 ret = serial_pnp_guess_board(dev);
@@ -440,12 +439,11 @@ serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
440 memset(&uart, 0, sizeof(uart)); 439 memset(&uart, 0, sizeof(uart));
441 if (pnp_irq_valid(dev, 0)) 440 if (pnp_irq_valid(dev, 0))
442 uart.port.irq = pnp_irq(dev, 0); 441 uart.port.irq = pnp_irq(dev, 0);
443 if ((flags & CIR_PORT) && pnp_port_valid(dev, 2)) 442 if ((flags & CIR_PORT) && pnp_port_valid(dev, 2)) {
444 res = pnp_get_resource(dev, IORESOURCE_IO, 2); 443 uart.port.iobase = pnp_port_start(dev, 2);
445 else if (pnp_port_valid(dev, 0)) 444 uart.port.iotype = UPIO_PORT;
446 res = pnp_get_resource(dev, IORESOURCE_IO, 0); 445 } else if (pnp_port_valid(dev, 0)) {
447 if (pnp_resource_enabled(res)) { 446 uart.port.iobase = pnp_port_start(dev, 0);
448 uart.port.iobase = res->start;
449 uart.port.iotype = UPIO_PORT; 447 uart.port.iotype = UPIO_PORT;
450 } else if (pnp_mem_valid(dev, 0)) { 448 } else if (pnp_mem_valid(dev, 0)) {
451 uart.port.mapbase = pnp_mem_start(dev, 0); 449 uart.port.mapbase = pnp_mem_start(dev, 0);
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
index 2ef9537bcb2c..80fe91e64a52 100644
--- a/drivers/tty/serial/8250/Kconfig
+++ b/drivers/tty/serial/8250/Kconfig
@@ -33,6 +33,23 @@ config SERIAL_8250
33 Most people will say Y or M here, so that they can use serial mice, 33 Most people will say Y or M here, so that they can use serial mice,
34 modems and similar devices connecting to the standard serial ports. 34 modems and similar devices connecting to the standard serial ports.
35 35
36config SERIAL_8250_DEPRECATED_OPTIONS
37 bool "Support 8250_core.* kernel options (DEPRECATED)"
38 depends on SERIAL_8250
39 default y
40 ---help---
41 In 3.7 we renamed 8250 to 8250_core by mistake, so now we have to
42 accept kernel parameters in both forms like 8250_core.nr_uarts=4 and
43 8250.nr_uarts=4. We now renamed the module back to 8250, but if
44 anybody noticed in 3.7 and changed their userspace we still have to
45 keep the 8350_core.* options around until they revert the changes
46 they already did.
47
48 If 8250 is built as a module, this adds 8250_core alias instead.
49
50 If you did not notice yet and/or you have userspace from pre-3.7, it
51 is safe (and recommended) to say N here.
52
36config SERIAL_8250_PNP 53config SERIAL_8250_PNP
37 bool "8250/16550 PNP device support" if EXPERT 54 bool "8250/16550 PNP device support" if EXPERT
38 depends on SERIAL_8250 && PNP 55 depends on SERIAL_8250 && PNP
diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile
index a23838a4d535..36d68d054307 100644
--- a/drivers/tty/serial/8250/Makefile
+++ b/drivers/tty/serial/8250/Makefile
@@ -2,10 +2,10 @@
2# Makefile for the 8250 serial device drivers. 2# Makefile for the 8250 serial device drivers.
3# 3#
4 4
5obj-$(CONFIG_SERIAL_8250) += 8250_core.o 5obj-$(CONFIG_SERIAL_8250) += 8250.o
68250_core-y := 8250.o 68250-y := 8250_core.o
78250_core-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 78250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
88250_core-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 88250-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o
9obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o 9obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o
10obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o 10obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o
11obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o 11obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o
diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c
index b7d48b346393..1b74b88e1e1e 100644
--- a/drivers/tty/serial/8250/serial_cs.c
+++ b/drivers/tty/serial/8250/serial_cs.c
@@ -852,18 +852,6 @@ static struct pcmcia_driver serial_cs_driver = {
852 .suspend = serial_suspend, 852 .suspend = serial_suspend,
853 .resume = serial_resume, 853 .resume = serial_resume,
854}; 854};
855 855module_pcmcia_driver(serial_cs_driver);
856static int __init init_serial_cs(void)
857{
858 return pcmcia_register_driver(&serial_cs_driver);
859}
860
861static void __exit exit_serial_cs(void)
862{
863 pcmcia_unregister_driver(&serial_cs_driver);
864}
865
866module_init(init_serial_cs);
867module_exit(exit_serial_cs);
868 856
869MODULE_LICENSE("GPL"); 857MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 3ea5408fcbeb..e2774f9ecd59 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -29,6 +29,7 @@
29 * and hooked into this driver. 29 * and hooked into this driver.
30 */ 30 */
31 31
32
32#if defined(CONFIG_SERIAL_AMBA_PL011_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 33#if defined(CONFIG_SERIAL_AMBA_PL011_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
33#define SUPPORT_SYSRQ 34#define SUPPORT_SYSRQ
34#endif 35#endif
@@ -72,32 +73,44 @@
72/* There is by now at least one vendor with differing details, so handle it */ 73/* There is by now at least one vendor with differing details, so handle it */
73struct vendor_data { 74struct vendor_data {
74 unsigned int ifls; 75 unsigned int ifls;
75 unsigned int fifosize;
76 unsigned int lcrh_tx; 76 unsigned int lcrh_tx;
77 unsigned int lcrh_rx; 77 unsigned int lcrh_rx;
78 bool oversampling; 78 bool oversampling;
79 bool dma_threshold; 79 bool dma_threshold;
80 bool cts_event_workaround; 80 bool cts_event_workaround;
81
82 unsigned int (*get_fifosize)(unsigned int periphid);
81}; 83};
82 84
85static unsigned int get_fifosize_arm(unsigned int periphid)
86{
87 unsigned int rev = (periphid >> 20) & 0xf;
88 return rev < 3 ? 16 : 32;
89}
90
83static struct vendor_data vendor_arm = { 91static struct vendor_data vendor_arm = {
84 .ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8, 92 .ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8,
85 .fifosize = 16,
86 .lcrh_tx = UART011_LCRH, 93 .lcrh_tx = UART011_LCRH,
87 .lcrh_rx = UART011_LCRH, 94 .lcrh_rx = UART011_LCRH,
88 .oversampling = false, 95 .oversampling = false,
89 .dma_threshold = false, 96 .dma_threshold = false,
90 .cts_event_workaround = false, 97 .cts_event_workaround = false,
98 .get_fifosize = get_fifosize_arm,
91}; 99};
92 100
101static unsigned int get_fifosize_st(unsigned int periphid)
102{
103 return 64;
104}
105
93static struct vendor_data vendor_st = { 106static struct vendor_data vendor_st = {
94 .ifls = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF, 107 .ifls = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF,
95 .fifosize = 64,
96 .lcrh_tx = ST_UART011_LCRH_TX, 108 .lcrh_tx = ST_UART011_LCRH_TX,
97 .lcrh_rx = ST_UART011_LCRH_RX, 109 .lcrh_rx = ST_UART011_LCRH_RX,
98 .oversampling = true, 110 .oversampling = true,
99 .dma_threshold = true, 111 .dma_threshold = true,
100 .cts_event_workaround = true, 112 .cts_event_workaround = true,
113 .get_fifosize = get_fifosize_st,
101}; 114};
102 115
103static struct uart_amba_port *amba_ports[UART_NR]; 116static struct uart_amba_port *amba_ports[UART_NR];
@@ -117,6 +130,12 @@ struct pl011_dmarx_data {
117 struct pl011_sgbuf sgbuf_b; 130 struct pl011_sgbuf sgbuf_b;
118 dma_cookie_t cookie; 131 dma_cookie_t cookie;
119 bool running; 132 bool running;
133 struct timer_list timer;
134 unsigned int last_residue;
135 unsigned long last_jiffies;
136 bool auto_poll_rate;
137 unsigned int poll_rate;
138 unsigned int poll_timeout;
120}; 139};
121 140
122struct pl011_dmatx_data { 141struct pl011_dmatx_data {
@@ -223,16 +242,18 @@ static int pl011_fifo_to_tty(struct uart_amba_port *uap)
223static int pl011_sgbuf_init(struct dma_chan *chan, struct pl011_sgbuf *sg, 242static int pl011_sgbuf_init(struct dma_chan *chan, struct pl011_sgbuf *sg,
224 enum dma_data_direction dir) 243 enum dma_data_direction dir)
225{ 244{
226 sg->buf = kmalloc(PL011_DMA_BUFFER_SIZE, GFP_KERNEL); 245 dma_addr_t dma_addr;
246
247 sg->buf = dma_alloc_coherent(chan->device->dev,
248 PL011_DMA_BUFFER_SIZE, &dma_addr, GFP_KERNEL);
227 if (!sg->buf) 249 if (!sg->buf)
228 return -ENOMEM; 250 return -ENOMEM;
229 251
230 sg_init_one(&sg->sg, sg->buf, PL011_DMA_BUFFER_SIZE); 252 sg_init_table(&sg->sg, 1);
253 sg_set_page(&sg->sg, phys_to_page(dma_addr),
254 PL011_DMA_BUFFER_SIZE, offset_in_page(dma_addr));
255 sg_dma_address(&sg->sg) = dma_addr;
231 256
232 if (dma_map_sg(chan->device->dev, &sg->sg, 1, dir) != 1) {
233 kfree(sg->buf);
234 return -EINVAL;
235 }
236 return 0; 257 return 0;
237} 258}
238 259
@@ -240,12 +261,13 @@ static void pl011_sgbuf_free(struct dma_chan *chan, struct pl011_sgbuf *sg,
240 enum dma_data_direction dir) 261 enum dma_data_direction dir)
241{ 262{
242 if (sg->buf) { 263 if (sg->buf) {
243 dma_unmap_sg(chan->device->dev, &sg->sg, 1, dir); 264 dma_free_coherent(chan->device->dev,
244 kfree(sg->buf); 265 PL011_DMA_BUFFER_SIZE, sg->buf,
266 sg_dma_address(&sg->sg));
245 } 267 }
246} 268}
247 269
248static void pl011_dma_probe_initcall(struct uart_amba_port *uap) 270static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port *uap)
249{ 271{
250 /* DMA is the sole user of the platform data right now */ 272 /* DMA is the sole user of the platform data right now */
251 struct amba_pl011_data *plat = uap->port.dev->platform_data; 273 struct amba_pl011_data *plat = uap->port.dev->platform_data;
@@ -259,20 +281,25 @@ static void pl011_dma_probe_initcall(struct uart_amba_port *uap)
259 struct dma_chan *chan; 281 struct dma_chan *chan;
260 dma_cap_mask_t mask; 282 dma_cap_mask_t mask;
261 283
262 /* We need platform data */ 284 chan = dma_request_slave_channel(dev, "tx");
263 if (!plat || !plat->dma_filter) {
264 dev_info(uap->port.dev, "no DMA platform data\n");
265 return;
266 }
267
268 /* Try to acquire a generic DMA engine slave TX channel */
269 dma_cap_zero(mask);
270 dma_cap_set(DMA_SLAVE, mask);
271 285
272 chan = dma_request_channel(mask, plat->dma_filter, plat->dma_tx_param);
273 if (!chan) { 286 if (!chan) {
274 dev_err(uap->port.dev, "no TX DMA channel!\n"); 287 /* We need platform data */
275 return; 288 if (!plat || !plat->dma_filter) {
289 dev_info(uap->port.dev, "no DMA platform data\n");
290 return;
291 }
292
293 /* Try to acquire a generic DMA engine slave TX channel */
294 dma_cap_zero(mask);
295 dma_cap_set(DMA_SLAVE, mask);
296
297 chan = dma_request_channel(mask, plat->dma_filter,
298 plat->dma_tx_param);
299 if (!chan) {
300 dev_err(uap->port.dev, "no TX DMA channel!\n");
301 return;
302 }
276 } 303 }
277 304
278 dmaengine_slave_config(chan, &tx_conf); 305 dmaengine_slave_config(chan, &tx_conf);
@@ -282,7 +309,18 @@ static void pl011_dma_probe_initcall(struct uart_amba_port *uap)
282 dma_chan_name(uap->dmatx.chan)); 309 dma_chan_name(uap->dmatx.chan));
283 310
284 /* Optionally make use of an RX channel as well */ 311 /* Optionally make use of an RX channel as well */
285 if (plat->dma_rx_param) { 312 chan = dma_request_slave_channel(dev, "rx");
313
314 if (!chan && plat->dma_rx_param) {
315 chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param);
316
317 if (!chan) {
318 dev_err(uap->port.dev, "no RX DMA channel!\n");
319 return;
320 }
321 }
322
323 if (chan) {
286 struct dma_slave_config rx_conf = { 324 struct dma_slave_config rx_conf = {
287 .src_addr = uap->port.mapbase + UART01x_DR, 325 .src_addr = uap->port.mapbase + UART01x_DR,
288 .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 326 .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE,
@@ -291,15 +329,32 @@ static void pl011_dma_probe_initcall(struct uart_amba_port *uap)
291 .device_fc = false, 329 .device_fc = false,
292 }; 330 };
293 331
294 chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param);
295 if (!chan) {
296 dev_err(uap->port.dev, "no RX DMA channel!\n");
297 return;
298 }
299
300 dmaengine_slave_config(chan, &rx_conf); 332 dmaengine_slave_config(chan, &rx_conf);
301 uap->dmarx.chan = chan; 333 uap->dmarx.chan = chan;
302 334
335 if (plat && plat->dma_rx_poll_enable) {
336 /* Set poll rate if specified. */
337 if (plat->dma_rx_poll_rate) {
338 uap->dmarx.auto_poll_rate = false;
339 uap->dmarx.poll_rate = plat->dma_rx_poll_rate;
340 } else {
341 /*
342 * 100 ms defaults to poll rate if not
343 * specified. This will be adjusted with
344 * the baud rate at set_termios.
345 */
346 uap->dmarx.auto_poll_rate = true;
347 uap->dmarx.poll_rate = 100;
348 }
349 /* 3 secs defaults poll_timeout if not specified. */
350 if (plat->dma_rx_poll_timeout)
351 uap->dmarx.poll_timeout =
352 plat->dma_rx_poll_timeout;
353 else
354 uap->dmarx.poll_timeout = 3000;
355 } else
356 uap->dmarx.auto_poll_rate = false;
357
303 dev_info(uap->port.dev, "DMA channel RX %s\n", 358 dev_info(uap->port.dev, "DMA channel RX %s\n",
304 dma_chan_name(uap->dmarx.chan)); 359 dma_chan_name(uap->dmarx.chan));
305 } 360 }
@@ -315,6 +370,7 @@ static void pl011_dma_probe_initcall(struct uart_amba_port *uap)
315struct dma_uap { 370struct dma_uap {
316 struct list_head node; 371 struct list_head node;
317 struct uart_amba_port *uap; 372 struct uart_amba_port *uap;
373 struct device *dev;
318}; 374};
319 375
320static LIST_HEAD(pl011_dma_uarts); 376static LIST_HEAD(pl011_dma_uarts);
@@ -325,7 +381,7 @@ static int __init pl011_dma_initcall(void)
325 381
326 list_for_each_safe(node, tmp, &pl011_dma_uarts) { 382 list_for_each_safe(node, tmp, &pl011_dma_uarts) {
327 struct dma_uap *dmau = list_entry(node, struct dma_uap, node); 383 struct dma_uap *dmau = list_entry(node, struct dma_uap, node);
328 pl011_dma_probe_initcall(dmau->uap); 384 pl011_dma_probe_initcall(dmau->dev, dmau->uap);
329 list_del(node); 385 list_del(node);
330 kfree(dmau); 386 kfree(dmau);
331 } 387 }
@@ -334,18 +390,19 @@ static int __init pl011_dma_initcall(void)
334 390
335device_initcall(pl011_dma_initcall); 391device_initcall(pl011_dma_initcall);
336 392
337static void pl011_dma_probe(struct uart_amba_port *uap) 393static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap)
338{ 394{
339 struct dma_uap *dmau = kzalloc(sizeof(struct dma_uap), GFP_KERNEL); 395 struct dma_uap *dmau = kzalloc(sizeof(struct dma_uap), GFP_KERNEL);
340 if (dmau) { 396 if (dmau) {
341 dmau->uap = uap; 397 dmau->uap = uap;
398 dmau->dev = dev;
342 list_add_tail(&dmau->node, &pl011_dma_uarts); 399 list_add_tail(&dmau->node, &pl011_dma_uarts);
343 } 400 }
344} 401}
345#else 402#else
346static void pl011_dma_probe(struct uart_amba_port *uap) 403static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap)
347{ 404{
348 pl011_dma_probe_initcall(uap); 405 pl011_dma_probe_initcall(dev, uap);
349} 406}
350#endif 407#endif
351 408
@@ -701,24 +758,30 @@ static void pl011_dma_rx_chars(struct uart_amba_port *uap,
701 struct tty_port *port = &uap->port.state->port; 758 struct tty_port *port = &uap->port.state->port;
702 struct pl011_sgbuf *sgbuf = use_buf_b ? 759 struct pl011_sgbuf *sgbuf = use_buf_b ?
703 &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a; 760 &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a;
704 struct device *dev = uap->dmarx.chan->device->dev;
705 int dma_count = 0; 761 int dma_count = 0;
706 u32 fifotaken = 0; /* only used for vdbg() */ 762 u32 fifotaken = 0; /* only used for vdbg() */
707 763
708 /* Pick everything from the DMA first */ 764 struct pl011_dmarx_data *dmarx = &uap->dmarx;
765 int dmataken = 0;
766
767 if (uap->dmarx.poll_rate) {
768 /* The data can be taken by polling */
769 dmataken = sgbuf->sg.length - dmarx->last_residue;
770 /* Recalculate the pending size */
771 if (pending >= dmataken)
772 pending -= dmataken;
773 }
774
775 /* Pick the remain data from the DMA */
709 if (pending) { 776 if (pending) {
710 /* Sync in buffer */
711 dma_sync_sg_for_cpu(dev, &sgbuf->sg, 1, DMA_FROM_DEVICE);
712 777
713 /* 778 /*
714 * First take all chars in the DMA pipe, then look in the FIFO. 779 * First take all chars in the DMA pipe, then look in the FIFO.
715 * Note that tty_insert_flip_buf() tries to take as many chars 780 * Note that tty_insert_flip_buf() tries to take as many chars
716 * as it can. 781 * as it can.
717 */ 782 */
718 dma_count = tty_insert_flip_string(port, sgbuf->buf, pending); 783 dma_count = tty_insert_flip_string(port, sgbuf->buf + dmataken,
719 784 pending);
720 /* Return buffer to device */
721 dma_sync_sg_for_device(dev, &sgbuf->sg, 1, DMA_FROM_DEVICE);
722 785
723 uap->port.icount.rx += dma_count; 786 uap->port.icount.rx += dma_count;
724 if (dma_count < pending) 787 if (dma_count < pending)
@@ -726,6 +789,10 @@ static void pl011_dma_rx_chars(struct uart_amba_port *uap,
726 "couldn't insert all characters (TTY is full?)\n"); 789 "couldn't insert all characters (TTY is full?)\n");
727 } 790 }
728 791
792 /* Reset the last_residue for Rx DMA poll */
793 if (uap->dmarx.poll_rate)
794 dmarx->last_residue = sgbuf->sg.length;
795
729 /* 796 /*
730 * Only continue with trying to read the FIFO if all DMA chars have 797 * Only continue with trying to read the FIFO if all DMA chars have
731 * been taken first. 798 * been taken first.
@@ -865,6 +932,57 @@ static inline void pl011_dma_rx_stop(struct uart_amba_port *uap)
865 writew(uap->dmacr, uap->port.membase + UART011_DMACR); 932 writew(uap->dmacr, uap->port.membase + UART011_DMACR);
866} 933}
867 934
935/*
936 * Timer handler for Rx DMA polling.
937 * Every polling, It checks the residue in the dma buffer and transfer
938 * data to the tty. Also, last_residue is updated for the next polling.
939 */
940static void pl011_dma_rx_poll(unsigned long args)
941{
942 struct uart_amba_port *uap = (struct uart_amba_port *)args;
943 struct tty_port *port = &uap->port.state->port;
944 struct pl011_dmarx_data *dmarx = &uap->dmarx;
945 struct dma_chan *rxchan = uap->dmarx.chan;
946 unsigned long flags = 0;
947 unsigned int dmataken = 0;
948 unsigned int size = 0;
949 struct pl011_sgbuf *sgbuf;
950 int dma_count;
951 struct dma_tx_state state;
952
953 sgbuf = dmarx->use_buf_b ? &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a;
954 rxchan->device->device_tx_status(rxchan, dmarx->cookie, &state);
955 if (likely(state.residue < dmarx->last_residue)) {
956 dmataken = sgbuf->sg.length - dmarx->last_residue;
957 size = dmarx->last_residue - state.residue;
958 dma_count = tty_insert_flip_string(port, sgbuf->buf + dmataken,
959 size);
960 if (dma_count == size)
961 dmarx->last_residue = state.residue;
962 dmarx->last_jiffies = jiffies;
963 }
964 tty_flip_buffer_push(port);
965
966 /*
967 * If no data is received in poll_timeout, the driver will fall back
968 * to interrupt mode. We will retrigger DMA at the first interrupt.
969 */
970 if (jiffies_to_msecs(jiffies - dmarx->last_jiffies)
971 > uap->dmarx.poll_timeout) {
972
973 spin_lock_irqsave(&uap->port.lock, flags);
974 pl011_dma_rx_stop(uap);
975 spin_unlock_irqrestore(&uap->port.lock, flags);
976
977 uap->dmarx.running = false;
978 dmaengine_terminate_all(rxchan);
979 del_timer(&uap->dmarx.timer);
980 } else {
981 mod_timer(&uap->dmarx.timer,
982 jiffies + msecs_to_jiffies(uap->dmarx.poll_rate));
983 }
984}
985
868static void pl011_dma_startup(struct uart_amba_port *uap) 986static void pl011_dma_startup(struct uart_amba_port *uap)
869{ 987{
870 int ret; 988 int ret;
@@ -927,6 +1045,16 @@ skip_rx:
927 if (pl011_dma_rx_trigger_dma(uap)) 1045 if (pl011_dma_rx_trigger_dma(uap))
928 dev_dbg(uap->port.dev, "could not trigger initial " 1046 dev_dbg(uap->port.dev, "could not trigger initial "
929 "RX DMA job, fall back to interrupt mode\n"); 1047 "RX DMA job, fall back to interrupt mode\n");
1048 if (uap->dmarx.poll_rate) {
1049 init_timer(&(uap->dmarx.timer));
1050 uap->dmarx.timer.function = pl011_dma_rx_poll;
1051 uap->dmarx.timer.data = (unsigned long)uap;
1052 mod_timer(&uap->dmarx.timer,
1053 jiffies +
1054 msecs_to_jiffies(uap->dmarx.poll_rate));
1055 uap->dmarx.last_residue = PL011_DMA_BUFFER_SIZE;
1056 uap->dmarx.last_jiffies = jiffies;
1057 }
930 } 1058 }
931} 1059}
932 1060
@@ -962,6 +1090,8 @@ static void pl011_dma_shutdown(struct uart_amba_port *uap)
962 /* Clean up the RX DMA */ 1090 /* Clean up the RX DMA */
963 pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_a, DMA_FROM_DEVICE); 1091 pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_a, DMA_FROM_DEVICE);
964 pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_b, DMA_FROM_DEVICE); 1092 pl011_sgbuf_free(uap->dmarx.chan, &uap->dmarx.sgbuf_b, DMA_FROM_DEVICE);
1093 if (uap->dmarx.poll_rate)
1094 del_timer_sync(&uap->dmarx.timer);
965 uap->using_rx_dma = false; 1095 uap->using_rx_dma = false;
966 } 1096 }
967} 1097}
@@ -976,10 +1106,9 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap)
976 return uap->using_rx_dma && uap->dmarx.running; 1106 return uap->using_rx_dma && uap->dmarx.running;
977} 1107}
978 1108
979
980#else 1109#else
981/* Blank functions if the DMA engine is not available */ 1110/* Blank functions if the DMA engine is not available */
982static inline void pl011_dma_probe(struct uart_amba_port *uap) 1111static inline void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap)
983{ 1112{
984} 1113}
985 1114
@@ -1088,8 +1217,20 @@ static void pl011_rx_chars(struct uart_amba_port *uap)
1088 dev_dbg(uap->port.dev, "could not trigger RX DMA job " 1217 dev_dbg(uap->port.dev, "could not trigger RX DMA job "
1089 "fall back to interrupt mode again\n"); 1218 "fall back to interrupt mode again\n");
1090 uap->im |= UART011_RXIM; 1219 uap->im |= UART011_RXIM;
1091 } else 1220 } else {
1092 uap->im &= ~UART011_RXIM; 1221 uap->im &= ~UART011_RXIM;
1222#ifdef CONFIG_DMA_ENGINE
1223 /* Start Rx DMA poll */
1224 if (uap->dmarx.poll_rate) {
1225 uap->dmarx.last_jiffies = jiffies;
1226 uap->dmarx.last_residue = PL011_DMA_BUFFER_SIZE;
1227 mod_timer(&uap->dmarx.timer,
1228 jiffies +
1229 msecs_to_jiffies(uap->dmarx.poll_rate));
1230 }
1231#endif
1232 }
1233
1093 writew(uap->im, uap->port.membase + UART011_IMSC); 1234 writew(uap->im, uap->port.membase + UART011_IMSC);
1094 } 1235 }
1095 spin_lock(&uap->port.lock); 1236 spin_lock(&uap->port.lock);
@@ -1164,7 +1305,6 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1164 unsigned int dummy_read; 1305 unsigned int dummy_read;
1165 1306
1166 spin_lock_irqsave(&uap->port.lock, flags); 1307 spin_lock_irqsave(&uap->port.lock, flags);
1167
1168 status = readw(uap->port.membase + UART011_MIS); 1308 status = readw(uap->port.membase + UART011_MIS);
1169 if (status) { 1309 if (status) {
1170 do { 1310 do {
@@ -1551,6 +1691,13 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios,
1551 */ 1691 */
1552 baud = uart_get_baud_rate(port, termios, old, 0, 1692 baud = uart_get_baud_rate(port, termios, old, 0,
1553 port->uartclk / clkdiv); 1693 port->uartclk / clkdiv);
1694#ifdef CONFIG_DMA_ENGINE
1695 /*
1696 * Adjust RX DMA polling rate with baud rate if not specified.
1697 */
1698 if (uap->dmarx.auto_poll_rate)
1699 uap->dmarx.poll_rate = DIV_ROUND_UP(10000000, baud);
1700#endif
1554 1701
1555 if (baud > port->uartclk/16) 1702 if (baud > port->uartclk/16)
1556 quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud); 1703 quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud);
@@ -2010,7 +2157,7 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
2010 uap->lcrh_rx = vendor->lcrh_rx; 2157 uap->lcrh_rx = vendor->lcrh_rx;
2011 uap->lcrh_tx = vendor->lcrh_tx; 2158 uap->lcrh_tx = vendor->lcrh_tx;
2012 uap->old_cr = 0; 2159 uap->old_cr = 0;
2013 uap->fifosize = vendor->fifosize; 2160 uap->fifosize = vendor->get_fifosize(dev->periphid);
2014 uap->port.dev = &dev->dev; 2161 uap->port.dev = &dev->dev;
2015 uap->port.mapbase = dev->res.start; 2162 uap->port.mapbase = dev->res.start;
2016 uap->port.membase = base; 2163 uap->port.membase = base;
@@ -2020,7 +2167,7 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
2020 uap->port.ops = &amba_pl011_pops; 2167 uap->port.ops = &amba_pl011_pops;
2021 uap->port.flags = UPF_BOOT_AUTOCONF; 2168 uap->port.flags = UPF_BOOT_AUTOCONF;
2022 uap->port.line = i; 2169 uap->port.line = i;
2023 pl011_dma_probe(uap); 2170 pl011_dma_probe(&dev->dev, uap);
2024 2171
2025 /* Ensure interrupts from this UART are masked and cleared */ 2172 /* Ensure interrupts from this UART are masked and cleared */
2026 writew(0, uap->port.membase + UART011_IMSC); 2173 writew(0, uap->port.membase + UART011_IMSC);
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c
index d97e194b6bc5..cbf1d155b7b2 100644
--- a/drivers/tty/serial/arc_uart.c
+++ b/drivers/tty/serial/arc_uart.c
@@ -162,7 +162,7 @@ static unsigned int arc_serial_tx_empty(struct uart_port *port)
162/* 162/*
163 * Driver internal routine, used by both tty(serial core) as well as tx-isr 163 * Driver internal routine, used by both tty(serial core) as well as tx-isr
164 * -Called under spinlock in either cases 164 * -Called under spinlock in either cases
165 * -also tty->stopped / tty->hw_stopped has already been checked 165 * -also tty->stopped has already been checked
166 * = by uart_start( ) before calling us 166 * = by uart_start( ) before calling us
167 * = tx_ist checks that too before calling 167 * = tx_ist checks that too before calling
168 */ 168 */
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d4a7c241b751..3467462869ce 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -158,7 +158,7 @@ struct atmel_uart_port {
158}; 158};
159 159
160static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART]; 160static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
161static unsigned long atmel_ports_in_use; 161static DECLARE_BITMAP(atmel_ports_in_use, ATMEL_MAX_UART);
162 162
163#ifdef SUPPORT_SYSRQ 163#ifdef SUPPORT_SYSRQ
164static struct console atmel_console; 164static struct console atmel_console;
@@ -1769,15 +1769,14 @@ static int atmel_serial_probe(struct platform_device *pdev)
1769 if (ret < 0) 1769 if (ret < 0)
1770 /* port id not found in platform data nor device-tree aliases: 1770 /* port id not found in platform data nor device-tree aliases:
1771 * auto-enumerate it */ 1771 * auto-enumerate it */
1772 ret = find_first_zero_bit(&atmel_ports_in_use, 1772 ret = find_first_zero_bit(atmel_ports_in_use, ATMEL_MAX_UART);
1773 sizeof(atmel_ports_in_use));
1774 1773
1775 if (ret > ATMEL_MAX_UART) { 1774 if (ret >= ATMEL_MAX_UART) {
1776 ret = -ENODEV; 1775 ret = -ENODEV;
1777 goto err; 1776 goto err;
1778 } 1777 }
1779 1778
1780 if (test_and_set_bit(ret, &atmel_ports_in_use)) { 1779 if (test_and_set_bit(ret, atmel_ports_in_use)) {
1781 /* port already in use */ 1780 /* port already in use */
1782 ret = -EBUSY; 1781 ret = -EBUSY;
1783 goto err; 1782 goto err;
@@ -1857,7 +1856,7 @@ static int atmel_serial_remove(struct platform_device *pdev)
1857 1856
1858 /* "port" is allocated statically, so we shouldn't free it */ 1857 /* "port" is allocated statically, so we shouldn't free it */
1859 1858
1860 clear_bit(port->line, &atmel_ports_in_use); 1859 clear_bit(port->line, atmel_ports_in_use);
1861 1860
1862 clk_put(atmel_port->clk); 1861 clk_put(atmel_port->clk);
1863 1862
diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c
index 52a3ecd40421..6fa2ae77fffd 100644
--- a/drivers/tty/serial/bcm63xx_uart.c
+++ b/drivers/tty/serial/bcm63xx_uart.c
@@ -30,7 +30,6 @@
30#include <linux/serial.h> 30#include <linux/serial.h>
31#include <linux/serial_core.h> 31#include <linux/serial_core.h>
32 32
33#include <bcm63xx_clk.h>
34#include <bcm63xx_irq.h> 33#include <bcm63xx_irq.h>
35#include <bcm63xx_regs.h> 34#include <bcm63xx_regs.h>
36#include <bcm63xx_io.h> 35#include <bcm63xx_io.h>
diff --git a/drivers/tty/serial/bfin_uart.c b/drivers/tty/serial/bfin_uart.c
index 12dceda9db33..26a3be7ced7d 100644
--- a/drivers/tty/serial/bfin_uart.c
+++ b/drivers/tty/serial/bfin_uart.c
@@ -1011,24 +1011,6 @@ static int bfin_serial_poll_get_char(struct uart_port *port)
1011} 1011}
1012#endif 1012#endif
1013 1013
1014#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
1015 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
1016static void bfin_kgdboc_port_shutdown(struct uart_port *port)
1017{
1018 if (kgdboc_break_enabled) {
1019 kgdboc_break_enabled = 0;
1020 bfin_serial_shutdown(port);
1021 }
1022}
1023
1024static int bfin_kgdboc_port_startup(struct uart_port *port)
1025{
1026 kgdboc_port_line = port->line;
1027 kgdboc_break_enabled = !bfin_serial_startup(port);
1028 return 0;
1029}
1030#endif
1031
1032static struct uart_ops bfin_serial_pops = { 1014static struct uart_ops bfin_serial_pops = {
1033 .tx_empty = bfin_serial_tx_empty, 1015 .tx_empty = bfin_serial_tx_empty,
1034 .set_mctrl = bfin_serial_set_mctrl, 1016 .set_mctrl = bfin_serial_set_mctrl,
@@ -1047,11 +1029,6 @@ static struct uart_ops bfin_serial_pops = {
1047 .request_port = bfin_serial_request_port, 1029 .request_port = bfin_serial_request_port,
1048 .config_port = bfin_serial_config_port, 1030 .config_port = bfin_serial_config_port,
1049 .verify_port = bfin_serial_verify_port, 1031 .verify_port = bfin_serial_verify_port,
1050#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
1051 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
1052 .kgdboc_port_startup = bfin_kgdboc_port_startup,
1053 .kgdboc_port_shutdown = bfin_kgdboc_port_shutdown,
1054#endif
1055#ifdef CONFIG_CONSOLE_POLL 1032#ifdef CONFIG_CONSOLE_POLL
1056 .poll_put_char = bfin_serial_poll_put_char, 1033 .poll_put_char = bfin_serial_poll_put_char,
1057 .poll_get_char = bfin_serial_poll_get_char, 1034 .poll_get_char = bfin_serial_poll_get_char,
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 5f37c31e32bc..477f22f773fc 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -169,7 +169,6 @@ static int get_lsr_info(struct e100_serial *info, unsigned int *value);
169 169
170 170
171#define DEF_BAUD 115200 /* 115.2 kbit/s */ 171#define DEF_BAUD 115200 /* 115.2 kbit/s */
172#define STD_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
173#define DEF_RX 0x20 /* or SERIAL_CTRL_W >> 8 */ 172#define DEF_RX 0x20 /* or SERIAL_CTRL_W >> 8 */
174/* Default value of tx_ctrl register: has txd(bit 7)=1 (idle) as default */ 173/* Default value of tx_ctrl register: has txd(bit 7)=1 (idle) as default */
175#define DEF_TX 0x80 /* or SERIAL_CTRL_B */ 174#define DEF_TX 0x80 /* or SERIAL_CTRL_B */
@@ -246,7 +245,6 @@ static struct e100_serial rs_table[] = {
246 .ifirstadr = R_DMA_CH7_FIRST, 245 .ifirstadr = R_DMA_CH7_FIRST,
247 .icmdadr = R_DMA_CH7_CMD, 246 .icmdadr = R_DMA_CH7_CMD,
248 .idescradr = R_DMA_CH7_DESCR, 247 .idescradr = R_DMA_CH7_DESCR,
249 .flags = STD_FLAGS,
250 .rx_ctrl = DEF_RX, 248 .rx_ctrl = DEF_RX,
251 .tx_ctrl = DEF_TX, 249 .tx_ctrl = DEF_TX,
252 .iseteop = 2, 250 .iseteop = 2,
@@ -300,7 +298,6 @@ static struct e100_serial rs_table[] = {
300 .ifirstadr = R_DMA_CH9_FIRST, 298 .ifirstadr = R_DMA_CH9_FIRST,
301 .icmdadr = R_DMA_CH9_CMD, 299 .icmdadr = R_DMA_CH9_CMD,
302 .idescradr = R_DMA_CH9_DESCR, 300 .idescradr = R_DMA_CH9_DESCR,
303 .flags = STD_FLAGS,
304 .rx_ctrl = DEF_RX, 301 .rx_ctrl = DEF_RX,
305 .tx_ctrl = DEF_TX, 302 .tx_ctrl = DEF_TX,
306 .iseteop = 3, 303 .iseteop = 3,
@@ -356,7 +353,6 @@ static struct e100_serial rs_table[] = {
356 .ifirstadr = R_DMA_CH3_FIRST, 353 .ifirstadr = R_DMA_CH3_FIRST,
357 .icmdadr = R_DMA_CH3_CMD, 354 .icmdadr = R_DMA_CH3_CMD,
358 .idescradr = R_DMA_CH3_DESCR, 355 .idescradr = R_DMA_CH3_DESCR,
359 .flags = STD_FLAGS,
360 .rx_ctrl = DEF_RX, 356 .rx_ctrl = DEF_RX,
361 .tx_ctrl = DEF_TX, 357 .tx_ctrl = DEF_TX,
362 .iseteop = 0, 358 .iseteop = 0,
@@ -410,7 +406,6 @@ static struct e100_serial rs_table[] = {
410 .ifirstadr = R_DMA_CH5_FIRST, 406 .ifirstadr = R_DMA_CH5_FIRST,
411 .icmdadr = R_DMA_CH5_CMD, 407 .icmdadr = R_DMA_CH5_CMD,
412 .idescradr = R_DMA_CH5_DESCR, 408 .idescradr = R_DMA_CH5_DESCR,
413 .flags = STD_FLAGS,
414 .rx_ctrl = DEF_RX, 409 .rx_ctrl = DEF_RX,
415 .tx_ctrl = DEF_TX, 410 .tx_ctrl = DEF_TX,
416 .iseteop = 1, 411 .iseteop = 1,
@@ -2263,8 +2258,7 @@ TODO: The break will be delayed until an F or V character is received.
2263 2258
2264*/ 2259*/
2265 2260
2266static 2261static void handle_ser_rx_interrupt_no_dma(struct e100_serial *info)
2267struct e100_serial * handle_ser_rx_interrupt_no_dma(struct e100_serial *info)
2268{ 2262{
2269 unsigned long data_read; 2263 unsigned long data_read;
2270 2264
@@ -2370,10 +2364,9 @@ more_data:
2370 } 2364 }
2371 2365
2372 tty_flip_buffer_push(&info->port); 2366 tty_flip_buffer_push(&info->port);
2373 return info;
2374} 2367}
2375 2368
2376static struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info) 2369static void handle_ser_rx_interrupt(struct e100_serial *info)
2377{ 2370{
2378 unsigned char rstat; 2371 unsigned char rstat;
2379 2372
@@ -2382,7 +2375,8 @@ static struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info)
2382#endif 2375#endif
2383/* DEBUG_LOG(info->line, "ser_interrupt stat %03X\n", rstat | (i << 8)); */ 2376/* DEBUG_LOG(info->line, "ser_interrupt stat %03X\n", rstat | (i << 8)); */
2384 if (!info->uses_dma_in) { 2377 if (!info->uses_dma_in) {
2385 return handle_ser_rx_interrupt_no_dma(info); 2378 handle_ser_rx_interrupt_no_dma(info);
2379 return;
2386 } 2380 }
2387 /* DMA is used */ 2381 /* DMA is used */
2388 rstat = info->ioport[REG_STATUS]; 2382 rstat = info->ioport[REG_STATUS];
@@ -2489,7 +2483,6 @@ static struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info)
2489 /* Restarting the DMA never hurts */ 2483 /* Restarting the DMA never hurts */
2490 *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart); 2484 *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart);
2491 START_FLUSH_FAST_TIMER(info, "ser_int"); 2485 START_FLUSH_FAST_TIMER(info, "ser_int");
2492 return info;
2493} /* handle_ser_rx_interrupt */ 2486} /* handle_ser_rx_interrupt */
2494 2487
2495static void handle_ser_tx_interrupt(struct e100_serial *info) 2488static void handle_ser_tx_interrupt(struct e100_serial *info)
@@ -2534,8 +2527,7 @@ static void handle_ser_tx_interrupt(struct e100_serial *info)
2534 } 2527 }
2535 /* Normal char-by-char interrupt */ 2528 /* Normal char-by-char interrupt */
2536 if (info->xmit.head == info->xmit.tail 2529 if (info->xmit.head == info->xmit.tail
2537 || info->port.tty->stopped 2530 || info->port.tty->stopped) {
2538 || info->port.tty->hw_stopped) {
2539 DFLOW(DEBUG_LOG(info->line, "tx_int: stopped %i\n", 2531 DFLOW(DEBUG_LOG(info->line, "tx_int: stopped %i\n",
2540 info->port.tty->stopped)); 2532 info->port.tty->stopped));
2541 e100_disable_serial_tx_ready_irq(info); 2533 e100_disable_serial_tx_ready_irq(info);
@@ -2722,7 +2714,7 @@ startup(struct e100_serial * info)
2722 2714
2723 /* if it was already initialized, skip this */ 2715 /* if it was already initialized, skip this */
2724 2716
2725 if (info->flags & ASYNC_INITIALIZED) { 2717 if (info->port.flags & ASYNC_INITIALIZED) {
2726 local_irq_restore(flags); 2718 local_irq_restore(flags);
2727 free_page(xmit_page); 2719 free_page(xmit_page);
2728 return 0; 2720 return 0;
@@ -2847,7 +2839,7 @@ startup(struct e100_serial * info)
2847 2839
2848#endif /* CONFIG_SVINTO_SIM */ 2840#endif /* CONFIG_SVINTO_SIM */
2849 2841
2850 info->flags |= ASYNC_INITIALIZED; 2842 info->port.flags |= ASYNC_INITIALIZED;
2851 2843
2852 local_irq_restore(flags); 2844 local_irq_restore(flags);
2853 return 0; 2845 return 0;
@@ -2892,7 +2884,7 @@ shutdown(struct e100_serial * info)
2892 2884
2893#endif /* CONFIG_SVINTO_SIM */ 2885#endif /* CONFIG_SVINTO_SIM */
2894 2886
2895 if (!(info->flags & ASYNC_INITIALIZED)) 2887 if (!(info->port.flags & ASYNC_INITIALIZED))
2896 return; 2888 return;
2897 2889
2898#ifdef SERIAL_DEBUG_OPEN 2890#ifdef SERIAL_DEBUG_OPEN
@@ -2923,7 +2915,7 @@ shutdown(struct e100_serial * info)
2923 if (info->port.tty) 2915 if (info->port.tty)
2924 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 2916 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
2925 2917
2926 info->flags &= ~ASYNC_INITIALIZED; 2918 info->port.flags &= ~ASYNC_INITIALIZED;
2927 local_irq_restore(flags); 2919 local_irq_restore(flags);
2928} 2920}
2929 2921
@@ -2948,7 +2940,7 @@ change_speed(struct e100_serial *info)
2948 /* possibly, the tx/rx should be disabled first to do this safely */ 2940 /* possibly, the tx/rx should be disabled first to do this safely */
2949 2941
2950 /* change baud-rate and write it to the hardware */ 2942 /* change baud-rate and write it to the hardware */
2951 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) { 2943 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) {
2952 /* Special baudrate */ 2944 /* Special baudrate */
2953 u32 mask = 0xFF << (info->line*8); /* Each port has 8 bits */ 2945 u32 mask = 0xFF << (info->line*8); /* Each port has 8 bits */
2954 unsigned long alt_source = 2946 unsigned long alt_source =
@@ -3098,7 +3090,6 @@ rs_flush_chars(struct tty_struct *tty)
3098 if (info->tr_running || 3090 if (info->tr_running ||
3099 info->xmit.head == info->xmit.tail || 3091 info->xmit.head == info->xmit.tail ||
3100 tty->stopped || 3092 tty->stopped ||
3101 tty->hw_stopped ||
3102 !info->xmit.buf) 3093 !info->xmit.buf)
3103 return; 3094 return;
3104 3095
@@ -3176,7 +3167,6 @@ static int rs_raw_write(struct tty_struct *tty,
3176 3167
3177 if (info->xmit.head != info->xmit.tail && 3168 if (info->xmit.head != info->xmit.tail &&
3178 !tty->stopped && 3169 !tty->stopped &&
3179 !tty->hw_stopped &&
3180 !info->tr_running) { 3170 !info->tr_running) {
3181 start_transmit(info); 3171 start_transmit(info);
3182 } 3172 }
@@ -3400,10 +3390,10 @@ get_serial_info(struct e100_serial * info,
3400 tmp.line = info->line; 3390 tmp.line = info->line;
3401 tmp.port = (int)info->ioport; 3391 tmp.port = (int)info->ioport;
3402 tmp.irq = info->irq; 3392 tmp.irq = info->irq;
3403 tmp.flags = info->flags; 3393 tmp.flags = info->port.flags;
3404 tmp.baud_base = info->baud_base; 3394 tmp.baud_base = info->baud_base;
3405 tmp.close_delay = info->close_delay; 3395 tmp.close_delay = info->port.close_delay;
3406 tmp.closing_wait = info->closing_wait; 3396 tmp.closing_wait = info->port.closing_wait;
3407 tmp.custom_divisor = info->custom_divisor; 3397 tmp.custom_divisor = info->custom_divisor;
3408 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 3398 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
3409 return -EFAULT; 3399 return -EFAULT;
@@ -3425,16 +3415,16 @@ set_serial_info(struct e100_serial *info,
3425 3415
3426 if (!capable(CAP_SYS_ADMIN)) { 3416 if (!capable(CAP_SYS_ADMIN)) {
3427 if ((new_serial.type != info->type) || 3417 if ((new_serial.type != info->type) ||
3428 (new_serial.close_delay != info->close_delay) || 3418 (new_serial.close_delay != info->port.close_delay) ||
3429 ((new_serial.flags & ~ASYNC_USR_MASK) != 3419 ((new_serial.flags & ~ASYNC_USR_MASK) !=
3430 (info->flags & ~ASYNC_USR_MASK))) 3420 (info->port.flags & ~ASYNC_USR_MASK)))
3431 return -EPERM; 3421 return -EPERM;
3432 info->flags = ((info->flags & ~ASYNC_USR_MASK) | 3422 info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
3433 (new_serial.flags & ASYNC_USR_MASK)); 3423 (new_serial.flags & ASYNC_USR_MASK));
3434 goto check_and_exit; 3424 goto check_and_exit;
3435 } 3425 }
3436 3426
3437 if (info->count > 1) 3427 if (info->port.count > 1)
3438 return -EBUSY; 3428 return -EBUSY;
3439 3429
3440 /* 3430 /*
@@ -3443,16 +3433,16 @@ set_serial_info(struct e100_serial *info,
3443 */ 3433 */
3444 3434
3445 info->baud_base = new_serial.baud_base; 3435 info->baud_base = new_serial.baud_base;
3446 info->flags = ((info->flags & ~ASYNC_FLAGS) | 3436 info->port.flags = ((info->port.flags & ~ASYNC_FLAGS) |
3447 (new_serial.flags & ASYNC_FLAGS)); 3437 (new_serial.flags & ASYNC_FLAGS));
3448 info->custom_divisor = new_serial.custom_divisor; 3438 info->custom_divisor = new_serial.custom_divisor;
3449 info->type = new_serial.type; 3439 info->type = new_serial.type;
3450 info->close_delay = new_serial.close_delay; 3440 info->port.close_delay = new_serial.close_delay;
3451 info->closing_wait = new_serial.closing_wait; 3441 info->port.closing_wait = new_serial.closing_wait;
3452 info->port.low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 3442 info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
3453 3443
3454 check_and_exit: 3444 check_and_exit:
3455 if (info->flags & ASYNC_INITIALIZED) { 3445 if (info->port.flags & ASYNC_INITIALIZED) {
3456 change_speed(info); 3446 change_speed(info);
3457 } else 3447 } else
3458 retval = startup(info); 3448 retval = startup(info);
@@ -3733,10 +3723,8 @@ rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3733 3723
3734 /* Handle turning off CRTSCTS */ 3724 /* Handle turning off CRTSCTS */
3735 if ((old_termios->c_cflag & CRTSCTS) && 3725 if ((old_termios->c_cflag & CRTSCTS) &&
3736 !(tty->termios.c_cflag & CRTSCTS)) { 3726 !(tty->termios.c_cflag & CRTSCTS))
3737 tty->hw_stopped = 0;
3738 rs_start(tty); 3727 rs_start(tty);
3739 }
3740 3728
3741} 3729}
3742 3730
@@ -3772,7 +3760,7 @@ rs_close(struct tty_struct *tty, struct file * filp)
3772 printk("[%d] rs_close ttyS%d, count = %d\n", current->pid, 3760 printk("[%d] rs_close ttyS%d, count = %d\n", current->pid,
3773 info->line, info->count); 3761 info->line, info->count);
3774#endif 3762#endif
3775 if ((tty->count == 1) && (info->count != 1)) { 3763 if ((tty->count == 1) && (info->port.count != 1)) {
3776 /* 3764 /*
3777 * Uh, oh. tty->count is 1, which means that the tty 3765 * Uh, oh. tty->count is 1, which means that the tty
3778 * structure will be freed. Info->count should always 3766 * structure will be freed. Info->count should always
@@ -3782,32 +3770,32 @@ rs_close(struct tty_struct *tty, struct file * filp)
3782 */ 3770 */
3783 printk(KERN_ERR 3771 printk(KERN_ERR
3784 "rs_close: bad serial port count; tty->count is 1, " 3772 "rs_close: bad serial port count; tty->count is 1, "
3785 "info->count is %d\n", info->count); 3773 "info->count is %d\n", info->port.count);
3786 info->count = 1; 3774 info->port.count = 1;
3787 } 3775 }
3788 if (--info->count < 0) { 3776 if (--info->port.count < 0) {
3789 printk(KERN_ERR "rs_close: bad serial port count for ttyS%d: %d\n", 3777 printk(KERN_ERR "rs_close: bad serial port count for ttyS%d: %d\n",
3790 info->line, info->count); 3778 info->line, info->port.count);
3791 info->count = 0; 3779 info->port.count = 0;
3792 } 3780 }
3793 if (info->count) { 3781 if (info->port.count) {
3794 local_irq_restore(flags); 3782 local_irq_restore(flags);
3795 return; 3783 return;
3796 } 3784 }
3797 info->flags |= ASYNC_CLOSING; 3785 info->port.flags |= ASYNC_CLOSING;
3798 /* 3786 /*
3799 * Save the termios structure, since this port may have 3787 * Save the termios structure, since this port may have
3800 * separate termios for callout and dialin. 3788 * separate termios for callout and dialin.
3801 */ 3789 */
3802 if (info->flags & ASYNC_NORMAL_ACTIVE) 3790 if (info->port.flags & ASYNC_NORMAL_ACTIVE)
3803 info->normal_termios = tty->termios; 3791 info->normal_termios = tty->termios;
3804 /* 3792 /*
3805 * Now we wait for the transmit buffer to clear; and we notify 3793 * Now we wait for the transmit buffer to clear; and we notify
3806 * the line discipline to only process XON/XOFF characters. 3794 * the line discipline to only process XON/XOFF characters.
3807 */ 3795 */
3808 tty->closing = 1; 3796 tty->closing = 1;
3809 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) 3797 if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
3810 tty_wait_until_sent(tty, info->closing_wait); 3798 tty_wait_until_sent(tty, info->port.closing_wait);
3811 /* 3799 /*
3812 * At this point we stop accepting input. To do this, we 3800 * At this point we stop accepting input. To do this, we
3813 * disable the serial receiver and the DMA receive interrupt. 3801 * disable the serial receiver and the DMA receive interrupt.
@@ -3820,7 +3808,7 @@ rs_close(struct tty_struct *tty, struct file * filp)
3820 e100_disable_rx(info); 3808 e100_disable_rx(info);
3821 e100_disable_rx_irq(info); 3809 e100_disable_rx_irq(info);
3822 3810
3823 if (info->flags & ASYNC_INITIALIZED) { 3811 if (info->port.flags & ASYNC_INITIALIZED) {
3824 /* 3812 /*
3825 * Before we drop DTR, make sure the UART transmitter 3813 * Before we drop DTR, make sure the UART transmitter
3826 * has completely drained; this is especially 3814 * has completely drained; this is especially
@@ -3836,13 +3824,13 @@ rs_close(struct tty_struct *tty, struct file * filp)
3836 tty->closing = 0; 3824 tty->closing = 0;
3837 info->event = 0; 3825 info->event = 0;
3838 info->port.tty = NULL; 3826 info->port.tty = NULL;
3839 if (info->blocked_open) { 3827 if (info->port.blocked_open) {
3840 if (info->close_delay) 3828 if (info->port.close_delay)
3841 schedule_timeout_interruptible(info->close_delay); 3829 schedule_timeout_interruptible(info->port.close_delay);
3842 wake_up_interruptible(&info->open_wait); 3830 wake_up_interruptible(&info->port.open_wait);
3843 } 3831 }
3844 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 3832 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
3845 wake_up_interruptible(&info->close_wait); 3833 wake_up_interruptible(&info->port.close_wait);
3846 local_irq_restore(flags); 3834 local_irq_restore(flags);
3847 3835
3848 /* port closed */ 3836 /* port closed */
@@ -3935,10 +3923,10 @@ rs_hangup(struct tty_struct *tty)
3935 rs_flush_buffer(tty); 3923 rs_flush_buffer(tty);
3936 shutdown(info); 3924 shutdown(info);
3937 info->event = 0; 3925 info->event = 0;
3938 info->count = 0; 3926 info->port.count = 0;
3939 info->flags &= ~ASYNC_NORMAL_ACTIVE; 3927 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
3940 info->port.tty = NULL; 3928 info->port.tty = NULL;
3941 wake_up_interruptible(&info->open_wait); 3929 wake_up_interruptible(&info->port.open_wait);
3942} 3930}
3943 3931
3944/* 3932/*
@@ -3960,11 +3948,11 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3960 * until it's done, and then try again. 3948 * until it's done, and then try again.
3961 */ 3949 */
3962 if (tty_hung_up_p(filp) || 3950 if (tty_hung_up_p(filp) ||
3963 (info->flags & ASYNC_CLOSING)) { 3951 (info->port.flags & ASYNC_CLOSING)) {
3964 wait_event_interruptible_tty(tty, info->close_wait, 3952 wait_event_interruptible_tty(tty, info->port.close_wait,
3965 !(info->flags & ASYNC_CLOSING)); 3953 !(info->port.flags & ASYNC_CLOSING));
3966#ifdef SERIAL_DO_RESTART 3954#ifdef SERIAL_DO_RESTART
3967 if (info->flags & ASYNC_HUP_NOTIFY) 3955 if (info->port.flags & ASYNC_HUP_NOTIFY)
3968 return -EAGAIN; 3956 return -EAGAIN;
3969 else 3957 else
3970 return -ERESTARTSYS; 3958 return -ERESTARTSYS;
@@ -3979,7 +3967,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3979 */ 3967 */
3980 if ((filp->f_flags & O_NONBLOCK) || 3968 if ((filp->f_flags & O_NONBLOCK) ||
3981 (tty->flags & (1 << TTY_IO_ERROR))) { 3969 (tty->flags & (1 << TTY_IO_ERROR))) {
3982 info->flags |= ASYNC_NORMAL_ACTIVE; 3970 info->port.flags |= ASYNC_NORMAL_ACTIVE;
3983 return 0; 3971 return 0;
3984 } 3972 }
3985 3973
@@ -3990,23 +3978,23 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3990 /* 3978 /*
3991 * Block waiting for the carrier detect and the line to become 3979 * Block waiting for the carrier detect and the line to become
3992 * free (i.e., not in use by the callout). While we are in 3980 * free (i.e., not in use by the callout). While we are in
3993 * this loop, info->count is dropped by one, so that 3981 * this loop, info->port.count is dropped by one, so that
3994 * rs_close() knows when to free things. We restore it upon 3982 * rs_close() knows when to free things. We restore it upon
3995 * exit, either normal or abnormal. 3983 * exit, either normal or abnormal.
3996 */ 3984 */
3997 retval = 0; 3985 retval = 0;
3998 add_wait_queue(&info->open_wait, &wait); 3986 add_wait_queue(&info->port.open_wait, &wait);
3999#ifdef SERIAL_DEBUG_OPEN 3987#ifdef SERIAL_DEBUG_OPEN
4000 printk("block_til_ready before block: ttyS%d, count = %d\n", 3988 printk("block_til_ready before block: ttyS%d, count = %d\n",
4001 info->line, info->count); 3989 info->line, info->port.count);
4002#endif 3990#endif
4003 local_irq_save(flags); 3991 local_irq_save(flags);
4004 if (!tty_hung_up_p(filp)) { 3992 if (!tty_hung_up_p(filp)) {
4005 extra_count++; 3993 extra_count++;
4006 info->count--; 3994 info->port.count--;
4007 } 3995 }
4008 local_irq_restore(flags); 3996 local_irq_restore(flags);
4009 info->blocked_open++; 3997 info->port.blocked_open++;
4010 while (1) { 3998 while (1) {
4011 local_irq_save(flags); 3999 local_irq_save(flags);
4012 /* assert RTS and DTR */ 4000 /* assert RTS and DTR */
@@ -4015,9 +4003,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4015 local_irq_restore(flags); 4003 local_irq_restore(flags);
4016 set_current_state(TASK_INTERRUPTIBLE); 4004 set_current_state(TASK_INTERRUPTIBLE);
4017 if (tty_hung_up_p(filp) || 4005 if (tty_hung_up_p(filp) ||
4018 !(info->flags & ASYNC_INITIALIZED)) { 4006 !(info->port.flags & ASYNC_INITIALIZED)) {
4019#ifdef SERIAL_DO_RESTART 4007#ifdef SERIAL_DO_RESTART
4020 if (info->flags & ASYNC_HUP_NOTIFY) 4008 if (info->port.flags & ASYNC_HUP_NOTIFY)
4021 retval = -EAGAIN; 4009 retval = -EAGAIN;
4022 else 4010 else
4023 retval = -ERESTARTSYS; 4011 retval = -ERESTARTSYS;
@@ -4026,7 +4014,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4026#endif 4014#endif
4027 break; 4015 break;
4028 } 4016 }
4029 if (!(info->flags & ASYNC_CLOSING) && do_clocal) 4017 if (!(info->port.flags & ASYNC_CLOSING) && do_clocal)
4030 /* && (do_clocal || DCD_IS_ASSERTED) */ 4018 /* && (do_clocal || DCD_IS_ASSERTED) */
4031 break; 4019 break;
4032 if (signal_pending(current)) { 4020 if (signal_pending(current)) {
@@ -4035,24 +4023,24 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4035 } 4023 }
4036#ifdef SERIAL_DEBUG_OPEN 4024#ifdef SERIAL_DEBUG_OPEN
4037 printk("block_til_ready blocking: ttyS%d, count = %d\n", 4025 printk("block_til_ready blocking: ttyS%d, count = %d\n",
4038 info->line, info->count); 4026 info->line, info->port.count);
4039#endif 4027#endif
4040 tty_unlock(tty); 4028 tty_unlock(tty);
4041 schedule(); 4029 schedule();
4042 tty_lock(tty); 4030 tty_lock(tty);
4043 } 4031 }
4044 set_current_state(TASK_RUNNING); 4032 set_current_state(TASK_RUNNING);
4045 remove_wait_queue(&info->open_wait, &wait); 4033 remove_wait_queue(&info->port.open_wait, &wait);
4046 if (extra_count) 4034 if (extra_count)
4047 info->count++; 4035 info->port.count++;
4048 info->blocked_open--; 4036 info->port.blocked_open--;
4049#ifdef SERIAL_DEBUG_OPEN 4037#ifdef SERIAL_DEBUG_OPEN
4050 printk("block_til_ready after blocking: ttyS%d, count = %d\n", 4038 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
4051 info->line, info->count); 4039 info->line, info->port.count);
4052#endif 4040#endif
4053 if (retval) 4041 if (retval)
4054 return retval; 4042 return retval;
4055 info->flags |= ASYNC_NORMAL_ACTIVE; 4043 info->port.flags |= ASYNC_NORMAL_ACTIVE;
4056 return 0; 4044 return 0;
4057} 4045}
4058 4046
@@ -4086,24 +4074,24 @@ rs_open(struct tty_struct *tty, struct file * filp)
4086 4074
4087#ifdef SERIAL_DEBUG_OPEN 4075#ifdef SERIAL_DEBUG_OPEN
4088 printk("[%d] rs_open %s, count = %d\n", current->pid, tty->name, 4076 printk("[%d] rs_open %s, count = %d\n", current->pid, tty->name,
4089 info->count); 4077 info->port.count);
4090#endif 4078#endif
4091 4079
4092 info->count++; 4080 info->port.count++;
4093 tty->driver_data = info; 4081 tty->driver_data = info;
4094 info->port.tty = tty; 4082 info->port.tty = tty;
4095 4083
4096 info->port.low_latency = !!(info->flags & ASYNC_LOW_LATENCY); 4084 info->port.low_latency = !!(info->port.flags & ASYNC_LOW_LATENCY);
4097 4085
4098 /* 4086 /*
4099 * If the port is in the middle of closing, bail out now 4087 * If the port is in the middle of closing, bail out now
4100 */ 4088 */
4101 if (tty_hung_up_p(filp) || 4089 if (tty_hung_up_p(filp) ||
4102 (info->flags & ASYNC_CLOSING)) { 4090 (info->port.flags & ASYNC_CLOSING)) {
4103 wait_event_interruptible_tty(tty, info->close_wait, 4091 wait_event_interruptible_tty(tty, info->port.close_wait,
4104 !(info->flags & ASYNC_CLOSING)); 4092 !(info->port.flags & ASYNC_CLOSING));
4105#ifdef SERIAL_DO_RESTART 4093#ifdef SERIAL_DO_RESTART
4106 return ((info->flags & ASYNC_HUP_NOTIFY) ? 4094 return ((info->port.flags & ASYNC_HUP_NOTIFY) ?
4107 -EAGAIN : -ERESTARTSYS); 4095 -EAGAIN : -ERESTARTSYS);
4108#else 4096#else
4109 return -EAGAIN; 4097 return -EAGAIN;
@@ -4113,7 +4101,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4113 /* 4101 /*
4114 * If DMA is enabled try to allocate the irq's. 4102 * If DMA is enabled try to allocate the irq's.
4115 */ 4103 */
4116 if (info->count == 1) { 4104 if (info->port.count == 1) {
4117 allocated_resources = 1; 4105 allocated_resources = 1;
4118 if (info->dma_in_enabled) { 4106 if (info->dma_in_enabled) {
4119 if (request_irq(info->dma_in_irq_nbr, 4107 if (request_irq(info->dma_in_irq_nbr,
@@ -4186,7 +4174,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4186 if (allocated_resources) 4174 if (allocated_resources)
4187 deinit_port(info); 4175 deinit_port(info);
4188 4176
4189 /* FIXME Decrease count info->count here too? */ 4177 /* FIXME Decrease count info->port.count here too? */
4190 return retval; 4178 return retval;
4191 } 4179 }
4192 4180
@@ -4203,7 +4191,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4203 return retval; 4191 return retval;
4204 } 4192 }
4205 4193
4206 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) { 4194 if ((info->port.count == 1) && (info->port.flags & ASYNC_SPLIT_TERMIOS)) {
4207 tty->termios = info->normal_termios; 4195 tty->termios = info->normal_termios;
4208 change_speed(info); 4196 change_speed(info);
4209 } 4197 }
@@ -4256,9 +4244,6 @@ static void seq_line_info(struct seq_file *m, struct e100_serial *info)
4256 if (info->port.tty->stopped) 4244 if (info->port.tty->stopped)
4257 seq_printf(m, " stopped:%i", 4245 seq_printf(m, " stopped:%i",
4258 (int)info->port.tty->stopped); 4246 (int)info->port.tty->stopped);
4259 if (info->port.tty->hw_stopped)
4260 seq_printf(m, " hw_stopped:%i",
4261 (int)info->port.tty->hw_stopped);
4262 } 4247 }
4263 4248
4264 { 4249 {
@@ -4455,16 +4440,9 @@ static int __init rs_init(void)
4455 info->forced_eop = 0; 4440 info->forced_eop = 0;
4456 info->baud_base = DEF_BAUD_BASE; 4441 info->baud_base = DEF_BAUD_BASE;
4457 info->custom_divisor = 0; 4442 info->custom_divisor = 0;
4458 info->flags = 0;
4459 info->close_delay = 5*HZ/10;
4460 info->closing_wait = 30*HZ;
4461 info->x_char = 0; 4443 info->x_char = 0;
4462 info->event = 0; 4444 info->event = 0;
4463 info->count = 0;
4464 info->blocked_open = 0;
4465 info->normal_termios = driver->init_termios; 4445 info->normal_termios = driver->init_termios;
4466 init_waitqueue_head(&info->open_wait);
4467 init_waitqueue_head(&info->close_wait);
4468 info->xmit.buf = NULL; 4446 info->xmit.buf = NULL;
4469 info->xmit.tail = info->xmit.head = 0; 4447 info->xmit.tail = info->xmit.head = 0;
4470 info->first_recv_buffer = info->last_recv_buffer = NULL; 4448 info->first_recv_buffer = info->last_recv_buffer = NULL;
diff --git a/drivers/tty/serial/crisv10.h b/drivers/tty/serial/crisv10.h
index ea0beb46a10d..7599014ae03f 100644
--- a/drivers/tty/serial/crisv10.h
+++ b/drivers/tty/serial/crisv10.h
@@ -53,8 +53,6 @@ struct e100_serial {
53 volatile u8 *icmdadr; /* adr to R_DMA_CHx_CMD */ 53 volatile u8 *icmdadr; /* adr to R_DMA_CHx_CMD */
54 volatile u32 *idescradr; /* adr to R_DMA_CHx_DESCR */ 54 volatile u32 *idescradr; /* adr to R_DMA_CHx_DESCR */
55 55
56 int flags; /* defined in tty.h */
57
58 u8 rx_ctrl; /* shadow for R_SERIALx_REC_CTRL */ 56 u8 rx_ctrl; /* shadow for R_SERIALx_REC_CTRL */
59 u8 tx_ctrl; /* shadow for R_SERIALx_TR_CTRL */ 57 u8 tx_ctrl; /* shadow for R_SERIALx_TR_CTRL */
60 u8 iseteop; /* bit number for R_SET_EOP for the input dma */ 58 u8 iseteop; /* bit number for R_SET_EOP for the input dma */
@@ -88,19 +86,10 @@ struct e100_serial {
88 86
89 volatile int tr_running; /* 1 if output is running */ 87 volatile int tr_running; /* 1 if output is running */
90 88
91 struct tty_struct *tty;
92 int read_status_mask;
93 int ignore_status_mask;
94 int x_char; /* xon/xoff character */ 89 int x_char; /* xon/xoff character */
95 int close_delay;
96 unsigned short closing_wait;
97 unsigned short closing_wait2;
98 unsigned long event; 90 unsigned long event;
99 unsigned long last_active;
100 int line; 91 int line;
101 int type; /* PORT_ETRAX */ 92 int type; /* PORT_ETRAX */
102 int count; /* # of fd on device */
103 int blocked_open; /* # of blocked opens */
104 struct circ_buf xmit; 93 struct circ_buf xmit;
105 struct etrax_recv_buffer *first_recv_buffer; 94 struct etrax_recv_buffer *first_recv_buffer;
106 struct etrax_recv_buffer *last_recv_buffer; 95 struct etrax_recv_buffer *last_recv_buffer;
@@ -110,9 +99,6 @@ struct e100_serial {
110 struct work_struct work; 99 struct work_struct work;
111 struct async_icount icount; /* error-statistics etc.*/ 100 struct async_icount icount; /* error-statistics etc.*/
112 struct ktermios normal_termios; 101 struct ktermios normal_termios;
113 struct ktermios callout_termios;
114 wait_queue_head_t open_wait;
115 wait_queue_head_t close_wait;
116 102
117 unsigned long char_time_usec; /* The time for 1 char, in usecs */ 103 unsigned long char_time_usec; /* The time for 1 char, in usecs */
118 unsigned long flush_time_usec; /* How often we should flush */ 104 unsigned long flush_time_usec; /* How often we should flush */
diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c
index bc9e6b017b05..18ed5aebb166 100644
--- a/drivers/tty/serial/icom.c
+++ b/drivers/tty/serial/icom.c
@@ -1415,8 +1415,7 @@ static int icom_alloc_adapter(struct icom_adapter
1415 struct icom_adapter *cur_adapter_entry; 1415 struct icom_adapter *cur_adapter_entry;
1416 struct list_head *tmp; 1416 struct list_head *tmp;
1417 1417
1418 icom_adapter = (struct icom_adapter *) 1418 icom_adapter = kzalloc(sizeof(struct icom_adapter), GFP_KERNEL);
1419 kzalloc(sizeof(struct icom_adapter), GFP_KERNEL);
1420 1419
1421 if (!icom_adapter) { 1420 if (!icom_adapter) {
1422 return -ENOMEM; 1421 return -ENOMEM;
diff --git a/drivers/tty/serial/ifx6x60.c b/drivers/tty/serial/ifx6x60.c
index 68d7ce997ede..8b1534c424af 100644
--- a/drivers/tty/serial/ifx6x60.c
+++ b/drivers/tty/serial/ifx6x60.c
@@ -270,23 +270,6 @@ static void mrdy_assert(struct ifx_spi_device *ifx_dev)
270} 270}
271 271
272/** 272/**
273 * ifx_spi_hangup - hang up an IFX device
274 * @ifx_dev: our SPI device
275 *
276 * Hang up the tty attached to the IFX device if one is currently
277 * open. If not take no action
278 */
279static void ifx_spi_ttyhangup(struct ifx_spi_device *ifx_dev)
280{
281 struct tty_port *pport = &ifx_dev->tty_port;
282 struct tty_struct *tty = tty_port_tty_get(pport);
283 if (tty) {
284 tty_hangup(tty);
285 tty_kref_put(tty);
286 }
287}
288
289/**
290 * ifx_spi_timeout - SPI timeout 273 * ifx_spi_timeout - SPI timeout
291 * @arg: our SPI device 274 * @arg: our SPI device
292 * 275 *
@@ -298,7 +281,7 @@ static void ifx_spi_timeout(unsigned long arg)
298 struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *)arg; 281 struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *)arg;
299 282
300 dev_warn(&ifx_dev->spi_dev->dev, "*** SPI Timeout ***"); 283 dev_warn(&ifx_dev->spi_dev->dev, "*** SPI Timeout ***");
301 ifx_spi_ttyhangup(ifx_dev); 284 tty_port_tty_hangup(&ifx_dev->tty_port, false);
302 mrdy_set_low(ifx_dev); 285 mrdy_set_low(ifx_dev);
303 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); 286 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags);
304} 287}
@@ -443,25 +426,6 @@ static void ifx_spi_setup_spi_header(unsigned char *txbuffer, int tx_count,
443} 426}
444 427
445/** 428/**
446 * ifx_spi_wakeup_serial - SPI space made
447 * @port_data: our SPI device
448 *
449 * We have emptied the FIFO enough that we want to get more data
450 * queued into it. Poke the line discipline via tty_wakeup so that
451 * it will feed us more bits
452 */
453static void ifx_spi_wakeup_serial(struct ifx_spi_device *ifx_dev)
454{
455 struct tty_struct *tty;
456
457 tty = tty_port_tty_get(&ifx_dev->tty_port);
458 if (!tty)
459 return;
460 tty_wakeup(tty);
461 tty_kref_put(tty);
462}
463
464/**
465 * ifx_spi_prepare_tx_buffer - prepare transmit frame 429 * ifx_spi_prepare_tx_buffer - prepare transmit frame
466 * @ifx_dev: our SPI device 430 * @ifx_dev: our SPI device
467 * 431 *
@@ -506,7 +470,7 @@ static int ifx_spi_prepare_tx_buffer(struct ifx_spi_device *ifx_dev)
506 tx_count += temp_count; 470 tx_count += temp_count;
507 if (temp_count == queue_length) 471 if (temp_count == queue_length)
508 /* poke port to get more data */ 472 /* poke port to get more data */
509 ifx_spi_wakeup_serial(ifx_dev); 473 tty_port_tty_wakeup(&ifx_dev->tty_port);
510 else /* more data in port, use next SPI message */ 474 else /* more data in port, use next SPI message */
511 ifx_dev->spi_more = 1; 475 ifx_dev->spi_more = 1;
512 } 476 }
@@ -683,8 +647,6 @@ static void ifx_spi_insert_flip_string(struct ifx_spi_device *ifx_dev,
683static void ifx_spi_complete(void *ctx) 647static void ifx_spi_complete(void *ctx)
684{ 648{
685 struct ifx_spi_device *ifx_dev = ctx; 649 struct ifx_spi_device *ifx_dev = ctx;
686 struct tty_struct *tty;
687 struct tty_ldisc *ldisc = NULL;
688 int length; 650 int length;
689 int actual_length; 651 int actual_length;
690 unsigned char more; 652 unsigned char more;
@@ -762,15 +724,7 @@ complete_exit:
762 */ 724 */
763 ifx_spi_power_state_clear(ifx_dev, 725 ifx_spi_power_state_clear(ifx_dev,
764 IFX_SPI_POWER_DATA_PENDING); 726 IFX_SPI_POWER_DATA_PENDING);
765 tty = tty_port_tty_get(&ifx_dev->tty_port); 727 tty_port_tty_wakeup(&ifx_dev->tty_port);
766 if (tty) {
767 ldisc = tty_ldisc_ref(tty);
768 if (ldisc) {
769 ldisc->ops->write_wakeup(tty);
770 tty_ldisc_deref(ldisc);
771 }
772 tty_kref_put(tty);
773 }
774 } 728 }
775 } 729 }
776} 730}
@@ -962,7 +916,7 @@ static irqreturn_t ifx_spi_reset_interrupt(int irq, void *dev)
962 set_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state); 916 set_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state);
963 if (!solreset) { 917 if (!solreset) {
964 /* unsolicited reset */ 918 /* unsolicited reset */
965 ifx_spi_ttyhangup(ifx_dev); 919 tty_port_tty_hangup(&ifx_dev->tty_port, false);
966 } 920 }
967 } else { 921 } else {
968 /* exited reset */ 922 /* exited reset */
@@ -1325,30 +1279,6 @@ static void ifx_spi_spi_shutdown(struct spi_device *spi)
1325 */ 1279 */
1326 1280
1327/** 1281/**
1328 * ifx_spi_spi_suspend - suspend SPI on system suspend
1329 * @dev: device being suspended
1330 *
1331 * Suspend the SPI side. No action needed on Intel MID platforms, may
1332 * need extending for other systems.
1333 */
1334static int ifx_spi_spi_suspend(struct spi_device *spi, pm_message_t msg)
1335{
1336 return 0;
1337}
1338
1339/**
1340 * ifx_spi_spi_resume - resume SPI side on system resume
1341 * @dev: device being suspended
1342 *
1343 * Suspend the SPI side. No action needed on Intel MID platforms, may
1344 * need extending for other systems.
1345 */
1346static int ifx_spi_spi_resume(struct spi_device *spi)
1347{
1348 return 0;
1349}
1350
1351/**
1352 * ifx_spi_pm_suspend - suspend modem on system suspend 1282 * ifx_spi_pm_suspend - suspend modem on system suspend
1353 * @dev: device being suspended 1283 * @dev: device being suspended
1354 * 1284 *
@@ -1437,8 +1367,6 @@ static struct spi_driver ifx_spi_driver = {
1437 .probe = ifx_spi_spi_probe, 1367 .probe = ifx_spi_spi_probe,
1438 .shutdown = ifx_spi_spi_shutdown, 1368 .shutdown = ifx_spi_spi_shutdown,
1439 .remove = ifx_spi_spi_remove, 1369 .remove = ifx_spi_spi_remove,
1440 .suspend = ifx_spi_spi_suspend,
1441 .resume = ifx_spi_spi_resume,
1442 .id_table = ifx_id_table 1370 .id_table = ifx_id_table
1443}; 1371};
1444 1372
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 147c9e193595..8cdfbd365892 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -761,6 +761,8 @@ static int imx_startup(struct uart_port *port)
761 761
762 temp = readl(sport->port.membase + UCR2); 762 temp = readl(sport->port.membase + UCR2);
763 temp |= (UCR2_RXEN | UCR2_TXEN); 763 temp |= (UCR2_RXEN | UCR2_TXEN);
764 if (!sport->have_rtscts)
765 temp |= UCR2_IRTS;
764 writel(temp, sport->port.membase + UCR2); 766 writel(temp, sport->port.membase + UCR2);
765 767
766 if (USE_IRDA(sport)) { 768 if (USE_IRDA(sport)) {
diff --git a/drivers/tty/serial/jsm/jsm_tty.c b/drivers/tty/serial/jsm/jsm_tty.c
index 00f250ae14c5..27bb75070c96 100644
--- a/drivers/tty/serial/jsm/jsm_tty.c
+++ b/drivers/tty/serial/jsm/jsm_tty.c
@@ -596,12 +596,6 @@ void jsm_input(struct jsm_channel *ch)
596 596
597 jsm_dbg(READ, &ch->ch_bd->pci_dev, "start 2\n"); 597 jsm_dbg(READ, &ch->ch_bd->pci_dev, "start 2\n");
598 598
599 if (data_len <= 0) {
600 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
601 jsm_dbg(READ, &ch->ch_bd->pci_dev, "jsm_input 1\n");
602 return;
603 }
604
605 len = tty_buffer_request_room(port, data_len); 599 len = tty_buffer_request_room(port, data_len);
606 n = len; 600 n = len;
607 601
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 32517d4bceab..35866d5872ad 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -778,7 +778,7 @@ static int max3100_probe(struct spi_device *spi)
778 max3100s[i]->spi = spi; 778 max3100s[i]->spi = spi;
779 max3100s[i]->irq = spi->irq; 779 max3100s[i]->irq = spi->irq;
780 spin_lock_init(&max3100s[i]->conf_lock); 780 spin_lock_init(&max3100s[i]->conf_lock);
781 dev_set_drvdata(&spi->dev, max3100s[i]); 781 spi_set_drvdata(spi, max3100s[i]);
782 pdata = spi->dev.platform_data; 782 pdata = spi->dev.platform_data;
783 max3100s[i]->crystal = pdata->crystal; 783 max3100s[i]->crystal = pdata->crystal;
784 max3100s[i]->loopback = pdata->loopback; 784 max3100s[i]->loopback = pdata->loopback;
@@ -819,7 +819,7 @@ static int max3100_probe(struct spi_device *spi)
819 819
820static int max3100_remove(struct spi_device *spi) 820static int max3100_remove(struct spi_device *spi)
821{ 821{
822 struct max3100_port *s = dev_get_drvdata(&spi->dev); 822 struct max3100_port *s = spi_get_drvdata(spi);
823 int i; 823 int i;
824 824
825 mutex_lock(&max3100s_lock); 825 mutex_lock(&max3100s_lock);
@@ -849,11 +849,11 @@ static int max3100_remove(struct spi_device *spi)
849 return 0; 849 return 0;
850} 850}
851 851
852#ifdef CONFIG_PM 852#ifdef CONFIG_PM_SLEEP
853 853
854static int max3100_suspend(struct spi_device *spi, pm_message_t state) 854static int max3100_suspend(struct device *dev)
855{ 855{
856 struct max3100_port *s = dev_get_drvdata(&spi->dev); 856 struct max3100_port *s = dev_get_drvdata(dev);
857 857
858 dev_dbg(&s->spi->dev, "%s\n", __func__); 858 dev_dbg(&s->spi->dev, "%s\n", __func__);
859 859
@@ -874,9 +874,9 @@ static int max3100_suspend(struct spi_device *spi, pm_message_t state)
874 return 0; 874 return 0;
875} 875}
876 876
877static int max3100_resume(struct spi_device *spi) 877static int max3100_resume(struct device *dev)
878{ 878{
879 struct max3100_port *s = dev_get_drvdata(&spi->dev); 879 struct max3100_port *s = dev_get_drvdata(dev);
880 880
881 dev_dbg(&s->spi->dev, "%s\n", __func__); 881 dev_dbg(&s->spi->dev, "%s\n", __func__);
882 882
@@ -894,21 +894,21 @@ static int max3100_resume(struct spi_device *spi)
894 return 0; 894 return 0;
895} 895}
896 896
897static SIMPLE_DEV_PM_OPS(max3100_pm_ops, max3100_suspend, max3100_resume);
898#define MAX3100_PM_OPS (&max3100_pm_ops)
899
897#else 900#else
898#define max3100_suspend NULL 901#define MAX3100_PM_OPS NULL
899#define max3100_resume NULL
900#endif 902#endif
901 903
902static struct spi_driver max3100_driver = { 904static struct spi_driver max3100_driver = {
903 .driver = { 905 .driver = {
904 .name = "max3100", 906 .name = "max3100",
905 .owner = THIS_MODULE, 907 .owner = THIS_MODULE,
908 .pm = MAX3100_PM_OPS,
906 }, 909 },
907
908 .probe = max3100_probe, 910 .probe = max3100_probe,
909 .remove = max3100_remove, 911 .remove = max3100_remove,
910 .suspend = max3100_suspend,
911 .resume = max3100_resume,
912}; 912};
913 913
914module_spi_driver(max3100_driver); 914module_spi_driver(max3100_driver);
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 0c2422cb04ea..8941e6418942 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -881,12 +881,14 @@ static struct uart_ops max310x_ops = {
881 .verify_port = max310x_verify_port, 881 .verify_port = max310x_verify_port,
882}; 882};
883 883
884static int max310x_suspend(struct spi_device *spi, pm_message_t state) 884#ifdef CONFIG_PM_SLEEP
885
886static int max310x_suspend(struct device *dev)
885{ 887{
886 int ret; 888 int ret;
887 struct max310x_port *s = dev_get_drvdata(&spi->dev); 889 struct max310x_port *s = dev_get_drvdata(dev);
888 890
889 dev_dbg(&spi->dev, "Suspend\n"); 891 dev_dbg(dev, "Suspend\n");
890 892
891 ret = uart_suspend_port(&s->uart, &s->port); 893 ret = uart_suspend_port(&s->uart, &s->port);
892 894
@@ -905,11 +907,11 @@ static int max310x_suspend(struct spi_device *spi, pm_message_t state)
905 return ret; 907 return ret;
906} 908}
907 909
908static int max310x_resume(struct spi_device *spi) 910static int max310x_resume(struct device *dev)
909{ 911{
910 struct max310x_port *s = dev_get_drvdata(&spi->dev); 912 struct max310x_port *s = dev_get_drvdata(dev);
911 913
912 dev_dbg(&spi->dev, "Resume\n"); 914 dev_dbg(dev, "Resume\n");
913 915
914 if (s->pdata->suspend) 916 if (s->pdata->suspend)
915 s->pdata->suspend(0); 917 s->pdata->suspend(0);
@@ -928,6 +930,13 @@ static int max310x_resume(struct spi_device *spi)
928 return uart_resume_port(&s->uart, &s->port); 930 return uart_resume_port(&s->uart, &s->port);
929} 931}
930 932
933static SIMPLE_DEV_PM_OPS(max310x_pm_ops, max310x_suspend, max310x_resume);
934#define MAX310X_PM_OPS (&max310x_pm_ops)
935
936#else
937#define MAX310X_PM_OPS NULL
938#endif
939
931#ifdef CONFIG_GPIOLIB 940#ifdef CONFIG_GPIOLIB
932static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset) 941static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset)
933{ 942{
@@ -1242,11 +1251,10 @@ static struct spi_driver max310x_driver = {
1242 .driver = { 1251 .driver = {
1243 .name = "max310x", 1252 .name = "max310x",
1244 .owner = THIS_MODULE, 1253 .owner = THIS_MODULE,
1254 .pm = MAX310X_PM_OPS,
1245 }, 1255 },
1246 .probe = max310x_probe, 1256 .probe = max310x_probe,
1247 .remove = max310x_remove, 1257 .remove = max310x_remove,
1248 .suspend = max310x_suspend,
1249 .resume = max310x_resume,
1250 .id_table = max310x_id_table, 1258 .id_table = max310x_id_table,
1251}; 1259};
1252module_spi_driver(max310x_driver); 1260module_spi_driver(max310x_driver);
diff --git a/drivers/tty/serial/mcf.c b/drivers/tty/serial/mcf.c
index e956377a38fe..65be0c00c4bf 100644
--- a/drivers/tty/serial/mcf.c
+++ b/drivers/tty/serial/mcf.c
@@ -707,8 +707,10 @@ static int __init mcf_init(void)
707 if (rc) 707 if (rc)
708 return rc; 708 return rc;
709 rc = platform_driver_register(&mcf_platform_driver); 709 rc = platform_driver_register(&mcf_platform_driver);
710 if (rc) 710 if (rc) {
711 uart_unregister_driver(&mcf_driver);
711 return rc; 712 return rc;
713 }
712 return 0; 714 return 0;
713} 715}
714 716
diff --git a/drivers/tty/serial/mpc52xx_uart.c b/drivers/tty/serial/mpc52xx_uart.c
index 018bad922554..f51b280f3bf2 100644
--- a/drivers/tty/serial/mpc52xx_uart.c
+++ b/drivers/tty/serial/mpc52xx_uart.c
@@ -1497,18 +1497,23 @@ mpc52xx_uart_init(void)
1497 if (psc_ops && psc_ops->fifoc_init) { 1497 if (psc_ops && psc_ops->fifoc_init) {
1498 ret = psc_ops->fifoc_init(); 1498 ret = psc_ops->fifoc_init();
1499 if (ret) 1499 if (ret)
1500 return ret; 1500 goto err_init;
1501 } 1501 }
1502 1502
1503 ret = platform_driver_register(&mpc52xx_uart_of_driver); 1503 ret = platform_driver_register(&mpc52xx_uart_of_driver);
1504 if (ret) { 1504 if (ret) {
1505 printk(KERN_ERR "%s: platform_driver_register failed (%i)\n", 1505 printk(KERN_ERR "%s: platform_driver_register failed (%i)\n",
1506 __FILE__, ret); 1506 __FILE__, ret);
1507 uart_unregister_driver(&mpc52xx_uart_driver); 1507 goto err_reg;
1508 return ret;
1509 } 1508 }
1510 1509
1511 return 0; 1510 return 0;
1511err_reg:
1512 if (psc_ops && psc_ops->fifoc_uninit)
1513 psc_ops->fifoc_uninit();
1514err_init:
1515 uart_unregister_driver(&mpc52xx_uart_driver);
1516 return ret;
1512} 1517}
1513 1518
1514static void __exit 1519static void __exit
diff --git a/drivers/tty/serial/mrst_max3110.c b/drivers/tty/serial/mrst_max3110.c
index f641c232beca..9b6ef20420c0 100644
--- a/drivers/tty/serial/mrst_max3110.c
+++ b/drivers/tty/serial/mrst_max3110.c
@@ -743,9 +743,10 @@ static struct uart_driver serial_m3110_reg = {
743 .cons = &serial_m3110_console, 743 .cons = &serial_m3110_console,
744}; 744};
745 745
746#ifdef CONFIG_PM 746#ifdef CONFIG_PM_SLEEP
747static int serial_m3110_suspend(struct spi_device *spi, pm_message_t state) 747static int serial_m3110_suspend(struct device *dev)
748{ 748{
749 struct spi_device *spi = to_spi_device(dev);
749 struct uart_max3110 *max = spi_get_drvdata(spi); 750 struct uart_max3110 *max = spi_get_drvdata(spi);
750 751
751 disable_irq(max->irq); 752 disable_irq(max->irq);
@@ -754,8 +755,9 @@ static int serial_m3110_suspend(struct spi_device *spi, pm_message_t state)
754 return 0; 755 return 0;
755} 756}
756 757
757static int serial_m3110_resume(struct spi_device *spi) 758static int serial_m3110_resume(struct device *dev)
758{ 759{
760 struct spi_device *spi = to_spi_device(dev);
759 struct uart_max3110 *max = spi_get_drvdata(spi); 761 struct uart_max3110 *max = spi_get_drvdata(spi);
760 762
761 max3110_out(max, max->cur_conf); 763 max3110_out(max, max->cur_conf);
@@ -763,9 +765,13 @@ static int serial_m3110_resume(struct spi_device *spi)
763 enable_irq(max->irq); 765 enable_irq(max->irq);
764 return 0; 766 return 0;
765} 767}
768
769static SIMPLE_DEV_PM_OPS(serial_m3110_pm_ops, serial_m3110_suspend,
770 serial_m3110_resume);
771#define SERIAL_M3110_PM_OPS (&serial_m3110_pm_ops)
772
766#else 773#else
767#define serial_m3110_suspend NULL 774#define SERIAL_M3110_PM_OPS NULL
768#define serial_m3110_resume NULL
769#endif 775#endif
770 776
771static int serial_m3110_probe(struct spi_device *spi) 777static int serial_m3110_probe(struct spi_device *spi)
@@ -872,11 +878,10 @@ static struct spi_driver uart_max3110_driver = {
872 .driver = { 878 .driver = {
873 .name = "spi_max3111", 879 .name = "spi_max3111",
874 .owner = THIS_MODULE, 880 .owner = THIS_MODULE,
881 .pm = SERIAL_M3110_PM_OPS,
875 }, 882 },
876 .probe = serial_m3110_probe, 883 .probe = serial_m3110_probe,
877 .remove = serial_m3110_remove, 884 .remove = serial_m3110_remove,
878 .suspend = serial_m3110_suspend,
879 .resume = serial_m3110_resume,
880}; 885};
881 886
882static int __init serial_m3110_init(void) 887static int __init serial_m3110_init(void)
diff --git a/drivers/tty/serial/msm_serial_hs.c b/drivers/tty/serial/msm_serial_hs.c
index 4a942c78347e..4ca2f64861e6 100644
--- a/drivers/tty/serial/msm_serial_hs.c
+++ b/drivers/tty/serial/msm_serial_hs.c
@@ -907,7 +907,6 @@ static void msm_hs_dmov_rx_callback(struct msm_dmov_cmd *cmd_ptr,
907 unsigned int error_f = 0; 907 unsigned int error_f = 0;
908 unsigned long flags; 908 unsigned long flags;
909 unsigned int flush; 909 unsigned int flush;
910 struct tty_struct *tty;
911 struct tty_port *port; 910 struct tty_port *port;
912 struct uart_port *uport; 911 struct uart_port *uport;
913 struct msm_hs_port *msm_uport; 912 struct msm_hs_port *msm_uport;
@@ -919,7 +918,6 @@ static void msm_hs_dmov_rx_callback(struct msm_dmov_cmd *cmd_ptr,
919 clk_enable(msm_uport->clk); 918 clk_enable(msm_uport->clk);
920 919
921 port = &uport->state->port; 920 port = &uport->state->port;
922 tty = port->tty;
923 921
924 msm_hs_write(uport, UARTDM_CR_ADDR, STALE_EVENT_DISABLE); 922 msm_hs_write(uport, UARTDM_CR_ADDR, STALE_EVENT_DISABLE);
925 923
diff --git a/drivers/tty/serial/msm_smd_tty.c b/drivers/tty/serial/msm_smd_tty.c
index e722ff163d91..1238ac370bff 100644
--- a/drivers/tty/serial/msm_smd_tty.c
+++ b/drivers/tty/serial/msm_smd_tty.c
@@ -90,13 +90,13 @@ static void smd_tty_notify(void *priv, unsigned event)
90 90
91static int smd_tty_port_activate(struct tty_port *tport, struct tty_struct *tty) 91static int smd_tty_port_activate(struct tty_port *tport, struct tty_struct *tty)
92{ 92{
93 struct smd_tty_info *info = container_of(tport, struct smd_tty_info,
94 port);
93 int i, res = 0; 95 int i, res = 0;
94 int n = tty->index;
95 const char *name = NULL; 96 const char *name = NULL;
96 struct smd_tty_info *info = smd_tty + n;
97 97
98 for (i = 0; i < smd_tty_channels_len; i++) { 98 for (i = 0; i < smd_tty_channels_len; i++) {
99 if (smd_tty_channels[i].id == n) { 99 if (smd_tty_channels[i].id == tty->index) {
100 name = smd_tty_channels[i].name; 100 name = smd_tty_channels[i].name;
101 break; 101 break;
102 } 102 }
@@ -117,17 +117,13 @@ static int smd_tty_port_activate(struct tty_port *tport, struct tty_struct *tty)
117 117
118static void smd_tty_port_shutdown(struct tty_port *tport) 118static void smd_tty_port_shutdown(struct tty_port *tport)
119{ 119{
120 struct smd_tty_info *info; 120 struct smd_tty_info *info = container_of(tport, struct smd_tty_info,
121 struct tty_struct *tty = tty_port_tty_get(tport); 121 port);
122 122
123 info = tty->driver_data;
124 if (info->ch) { 123 if (info->ch) {
125 smd_close(info->ch); 124 smd_close(info->ch);
126 info->ch = 0; 125 info->ch = 0;
127 } 126 }
128
129 tty->driver_data = 0;
130 tty_kref_put(tty);
131} 127}
132 128
133static int smd_tty_open(struct tty_struct *tty, struct file *f) 129static int smd_tty_open(struct tty_struct *tty, struct file *f)
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index d549fe1fa42a..4f5f161896a1 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -35,7 +35,7 @@
35#include <linux/pinctrl/consumer.h> 35#include <linux/pinctrl/consumer.h>
36#include <linux/of_device.h> 36#include <linux/of_device.h>
37#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/fsl/mxs-dma.h> 38#include <linux/dmaengine.h>
39 39
40#include <asm/cacheflush.h> 40#include <asm/cacheflush.h>
41 41
@@ -148,11 +148,6 @@ struct mxs_auart_port {
148 struct device *dev; 148 struct device *dev;
149 149
150 /* for DMA */ 150 /* for DMA */
151 struct mxs_dma_data dma_data;
152 int dma_channel_rx, dma_channel_tx;
153 int dma_irq_rx, dma_irq_tx;
154 int dma_channel;
155
156 struct scatterlist tx_sgl; 151 struct scatterlist tx_sgl;
157 struct dma_chan *tx_dma_chan; 152 struct dma_chan *tx_dma_chan;
158 void *tx_dma_buf; 153 void *tx_dma_buf;
@@ -440,20 +435,6 @@ static u32 mxs_auart_get_mctrl(struct uart_port *u)
440 return mctrl; 435 return mctrl;
441} 436}
442 437
443static bool mxs_auart_dma_filter(struct dma_chan *chan, void *param)
444{
445 struct mxs_auart_port *s = param;
446
447 if (!mxs_dma_is_apbx(chan))
448 return false;
449
450 if (s->dma_channel == chan->chan_id) {
451 chan->private = &s->dma_data;
452 return true;
453 }
454 return false;
455}
456
457static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s); 438static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s);
458static void dma_rx_callback(void *arg) 439static void dma_rx_callback(void *arg)
459{ 440{
@@ -545,21 +526,11 @@ static void mxs_auart_dma_exit(struct mxs_auart_port *s)
545 526
546static int mxs_auart_dma_init(struct mxs_auart_port *s) 527static int mxs_auart_dma_init(struct mxs_auart_port *s)
547{ 528{
548 dma_cap_mask_t mask;
549
550 if (auart_dma_enabled(s)) 529 if (auart_dma_enabled(s))
551 return 0; 530 return 0;
552 531
553 /* We do not get the right DMA channels. */
554 if (s->dma_channel_rx == -1 || s->dma_channel_tx == -1)
555 return -EINVAL;
556
557 /* init for RX */ 532 /* init for RX */
558 dma_cap_zero(mask); 533 s->rx_dma_chan = dma_request_slave_channel(s->dev, "rx");
559 dma_cap_set(DMA_SLAVE, mask);
560 s->dma_channel = s->dma_channel_rx;
561 s->dma_data.chan_irq = s->dma_irq_rx;
562 s->rx_dma_chan = dma_request_channel(mask, mxs_auart_dma_filter, s);
563 if (!s->rx_dma_chan) 534 if (!s->rx_dma_chan)
564 goto err_out; 535 goto err_out;
565 s->rx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA); 536 s->rx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA);
@@ -567,9 +538,7 @@ static int mxs_auart_dma_init(struct mxs_auart_port *s)
567 goto err_out; 538 goto err_out;
568 539
569 /* init for TX */ 540 /* init for TX */
570 s->dma_channel = s->dma_channel_tx; 541 s->tx_dma_chan = dma_request_slave_channel(s->dev, "tx");
571 s->dma_data.chan_irq = s->dma_irq_tx;
572 s->tx_dma_chan = dma_request_channel(mask, mxs_auart_dma_filter, s);
573 if (!s->tx_dma_chan) 542 if (!s->tx_dma_chan)
574 goto err_out; 543 goto err_out;
575 s->tx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA); 544 s->tx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA);
@@ -883,7 +852,7 @@ auart_console_write(struct console *co, const char *str, unsigned int count)
883 unsigned int old_ctrl0, old_ctrl2; 852 unsigned int old_ctrl0, old_ctrl2;
884 unsigned int to = 1000; 853 unsigned int to = 1000;
885 854
886 if (co->index > MXS_AUART_PORTS || co->index < 0) 855 if (co->index >= MXS_AUART_PORTS || co->index < 0)
887 return; 856 return;
888 857
889 s = auart_port[co->index]; 858 s = auart_port[co->index];
@@ -1020,7 +989,6 @@ static int serial_mxs_probe_dt(struct mxs_auart_port *s,
1020 struct platform_device *pdev) 989 struct platform_device *pdev)
1021{ 990{
1022 struct device_node *np = pdev->dev.of_node; 991 struct device_node *np = pdev->dev.of_node;
1023 u32 dma_channel[2];
1024 int ret; 992 int ret;
1025 993
1026 if (!np) 994 if (!np)
@@ -1034,20 +1002,8 @@ static int serial_mxs_probe_dt(struct mxs_auart_port *s,
1034 } 1002 }
1035 s->port.line = ret; 1003 s->port.line = ret;
1036 1004
1037 s->dma_irq_rx = platform_get_irq(pdev, 1); 1005 s->flags |= MXS_AUART_DMA_CONFIG;
1038 s->dma_irq_tx = platform_get_irq(pdev, 2);
1039 1006
1040 ret = of_property_read_u32_array(np, "fsl,auart-dma-channel",
1041 dma_channel, 2);
1042 if (ret == 0) {
1043 s->dma_channel_rx = dma_channel[0];
1044 s->dma_channel_tx = dma_channel[1];
1045
1046 s->flags |= MXS_AUART_DMA_CONFIG;
1047 } else {
1048 s->dma_channel_rx = -1;
1049 s->dma_channel_tx = -1;
1050 }
1051 return 0; 1007 return 0;
1052} 1008}
1053 1009
@@ -1103,7 +1059,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
1103 s->port.fifosize = 16; 1059 s->port.fifosize = 16;
1104 s->port.uartclk = clk_get_rate(s->clk); 1060 s->port.uartclk = clk_get_rate(s->clk);
1105 s->port.type = PORT_IMX; 1061 s->port.type = PORT_IMX;
1106 s->port.dev = s->dev = get_device(&pdev->dev); 1062 s->port.dev = s->dev = &pdev->dev;
1107 1063
1108 s->ctrl = 0; 1064 s->ctrl = 0;
1109 1065
@@ -1134,7 +1090,6 @@ out_free_irq:
1134 auart_port[pdev->id] = NULL; 1090 auart_port[pdev->id] = NULL;
1135 free_irq(s->irq, s); 1091 free_irq(s->irq, s);
1136out_free_clk: 1092out_free_clk:
1137 put_device(s->dev);
1138 clk_put(s->clk); 1093 clk_put(s->clk);
1139out_free: 1094out_free:
1140 kfree(s); 1095 kfree(s);
@@ -1150,7 +1105,6 @@ static int mxs_auart_remove(struct platform_device *pdev)
1150 1105
1151 auart_port[pdev->id] = NULL; 1106 auart_port[pdev->id] = NULL;
1152 1107
1153 put_device(s->dev);
1154 clk_put(s->clk); 1108 clk_put(s->clk);
1155 free_irq(s->irq, s); 1109 free_irq(s->irq, s);
1156 kfree(s); 1110 kfree(s);
diff --git a/drivers/tty/serial/nwpserial.c b/drivers/tty/serial/nwpserial.c
index 77287c54f331..549c70a2a63e 100644
--- a/drivers/tty/serial/nwpserial.c
+++ b/drivers/tty/serial/nwpserial.c
@@ -199,7 +199,7 @@ static void nwpserial_shutdown(struct uart_port *port)
199 dcr_write(up->dcr_host, UART_IER, up->ier); 199 dcr_write(up->dcr_host, UART_IER, up->ier);
200 200
201 /* free irq */ 201 /* free irq */
202 free_irq(up->port.irq, port); 202 free_irq(up->port.irq, up);
203} 203}
204 204
205static int nwpserial_verify_port(struct uart_port *port, 205static int nwpserial_verify_port(struct uart_port *port,
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index b025d5438275..39c7ea4cb14f 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -14,7 +14,6 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/serial_core.h> 16#include <linux/serial_core.h>
17#include <linux/serial_8250.h>
18#include <linux/serial_reg.h> 17#include <linux/serial_reg.h>
19#include <linux/of_address.h> 18#include <linux/of_address.h>
20#include <linux/of_irq.h> 19#include <linux/of_irq.h>
@@ -22,6 +21,8 @@
22#include <linux/nwpserial.h> 21#include <linux/nwpserial.h>
23#include <linux/clk.h> 22#include <linux/clk.h>
24 23
24#include "8250/8250.h"
25
25struct of_serial_info { 26struct of_serial_info {
26 struct clk *clk; 27 struct clk *clk;
27 int type; 28 int type;
@@ -97,6 +98,10 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
97 if (of_property_read_u32(np, "reg-shift", &prop) == 0) 98 if (of_property_read_u32(np, "reg-shift", &prop) == 0)
98 port->regshift = prop; 99 port->regshift = prop;
99 100
101 /* Check for fifo size */
102 if (of_property_read_u32(np, "fifo-size", &prop) == 0)
103 port->fifosize = prop;
104
100 port->irq = irq_of_parse_and_map(np, 0); 105 port->irq = irq_of_parse_and_map(np, 0);
101 port->iotype = UPIO_MEM; 106 port->iotype = UPIO_MEM;
102 if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { 107 if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
@@ -167,11 +172,17 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
167#ifdef CONFIG_SERIAL_8250 172#ifdef CONFIG_SERIAL_8250
168 case PORT_8250 ... PORT_MAX_8250: 173 case PORT_8250 ... PORT_MAX_8250:
169 { 174 {
170 /* For now the of bindings don't support the extra
171 8250 specific bits */
172 struct uart_8250_port port8250; 175 struct uart_8250_port port8250;
173 memset(&port8250, 0, sizeof(port8250)); 176 memset(&port8250, 0, sizeof(port8250));
174 port8250.port = port; 177 port8250.port = port;
178
179 if (port.fifosize)
180 port8250.capabilities = UART_CAP_FIFO;
181
182 if (of_property_read_bool(ofdev->dev.of_node,
183 "auto-flow-control"))
184 port8250.capabilities |= UART_CAP_AFE;
185
175 ret = serial8250_register_8250_port(&port8250); 186 ret = serial8250_register_8250_port(&port8250);
176 break; 187 break;
177 } 188 }
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 4dc41408ecb7..f0b9f6b52b32 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -202,26 +202,6 @@ static int serial_omap_get_context_loss_count(struct uart_omap_port *up)
202 return pdata->get_context_loss_count(up->dev); 202 return pdata->get_context_loss_count(up->dev);
203} 203}
204 204
205static void serial_omap_set_forceidle(struct uart_omap_port *up)
206{
207 struct omap_uart_port_info *pdata = up->dev->platform_data;
208
209 if (!pdata || !pdata->set_forceidle)
210 return;
211
212 pdata->set_forceidle(up->dev);
213}
214
215static void serial_omap_set_noidle(struct uart_omap_port *up)
216{
217 struct omap_uart_port_info *pdata = up->dev->platform_data;
218
219 if (!pdata || !pdata->set_noidle)
220 return;
221
222 pdata->set_noidle(up->dev);
223}
224
225static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable) 205static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable)
226{ 206{
227 struct omap_uart_port_info *pdata = up->dev->platform_data; 207 struct omap_uart_port_info *pdata = up->dev->platform_data;
@@ -298,8 +278,6 @@ static void serial_omap_stop_tx(struct uart_port *port)
298 serial_out(up, UART_IER, up->ier); 278 serial_out(up, UART_IER, up->ier);
299 } 279 }
300 280
301 serial_omap_set_forceidle(up);
302
303 pm_runtime_mark_last_busy(up->dev); 281 pm_runtime_mark_last_busy(up->dev);
304 pm_runtime_put_autosuspend(up->dev); 282 pm_runtime_put_autosuspend(up->dev);
305} 283}
@@ -364,7 +342,6 @@ static void serial_omap_start_tx(struct uart_port *port)
364 342
365 pm_runtime_get_sync(up->dev); 343 pm_runtime_get_sync(up->dev);
366 serial_omap_enable_ier_thri(up); 344 serial_omap_enable_ier_thri(up);
367 serial_omap_set_noidle(up);
368 pm_runtime_mark_last_busy(up->dev); 345 pm_runtime_mark_last_busy(up->dev);
369 pm_runtime_put_autosuspend(up->dev); 346 pm_runtime_put_autosuspend(up->dev);
370} 347}
@@ -886,6 +863,17 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
886 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); 863 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
887 /* FIFO ENABLE, DMA MODE */ 864 /* FIFO ENABLE, DMA MODE */
888 865
866 up->scr |= OMAP_UART_SCR_RX_TRIG_GRANU1_MASK;
867 /*
868 * NOTE: Setting OMAP_UART_SCR_RX_TRIG_GRANU1_MASK
869 * sets Enables the granularity of 1 for TRIGGER RX
870 * level. Along with setting RX FIFO trigger level
871 * to 1 (as noted below, 16 characters) and TLR[3:0]
872 * to zero this will result RX FIFO threshold level
873 * to 1 character, instead of 16 as noted in comment
874 * below.
875 */
876
889 /* Set receive FIFO threshold to 16 characters and 877 /* Set receive FIFO threshold to 16 characters and
890 * transmit FIFO threshold to 16 spaces 878 * transmit FIFO threshold to 16 spaces
891 */ 879 */
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 7a6c989924b3..21a7e179edf3 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -1493,29 +1493,6 @@ static int pch_uart_verify_port(struct uart_port *port,
1493 return 0; 1493 return 0;
1494} 1494}
1495 1495
1496static struct uart_ops pch_uart_ops = {
1497 .tx_empty = pch_uart_tx_empty,
1498 .set_mctrl = pch_uart_set_mctrl,
1499 .get_mctrl = pch_uart_get_mctrl,
1500 .stop_tx = pch_uart_stop_tx,
1501 .start_tx = pch_uart_start_tx,
1502 .stop_rx = pch_uart_stop_rx,
1503 .enable_ms = pch_uart_enable_ms,
1504 .break_ctl = pch_uart_break_ctl,
1505 .startup = pch_uart_startup,
1506 .shutdown = pch_uart_shutdown,
1507 .set_termios = pch_uart_set_termios,
1508/* .pm = pch_uart_pm, Not supported yet */
1509/* .set_wake = pch_uart_set_wake, Not supported yet */
1510 .type = pch_uart_type,
1511 .release_port = pch_uart_release_port,
1512 .request_port = pch_uart_request_port,
1513 .config_port = pch_uart_config_port,
1514 .verify_port = pch_uart_verify_port
1515};
1516
1517#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1518
1519/* 1496/*
1520 * Wait for transmitter & holding register to empty 1497 * Wait for transmitter & holding register to empty
1521 */ 1498 */
@@ -1547,6 +1524,84 @@ static void wait_for_xmitr(struct eg20t_port *up, int bits)
1547 } 1524 }
1548} 1525}
1549 1526
1527#ifdef CONFIG_CONSOLE_POLL
1528/*
1529 * Console polling routines for communicate via uart while
1530 * in an interrupt or debug context.
1531 */
1532static int pch_uart_get_poll_char(struct uart_port *port)
1533{
1534 struct eg20t_port *priv =
1535 container_of(port, struct eg20t_port, port);
1536 u8 lsr = ioread8(priv->membase + UART_LSR);
1537
1538 if (!(lsr & UART_LSR_DR))
1539 return NO_POLL_CHAR;
1540
1541 return ioread8(priv->membase + PCH_UART_RBR);
1542}
1543
1544
1545static void pch_uart_put_poll_char(struct uart_port *port,
1546 unsigned char c)
1547{
1548 unsigned int ier;
1549 struct eg20t_port *priv =
1550 container_of(port, struct eg20t_port, port);
1551
1552 /*
1553 * First save the IER then disable the interrupts
1554 */
1555 ier = ioread8(priv->membase + UART_IER);
1556 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1557
1558 wait_for_xmitr(priv, UART_LSR_THRE);
1559 /*
1560 * Send the character out.
1561 * If a LF, also do CR...
1562 */
1563 iowrite8(c, priv->membase + PCH_UART_THR);
1564 if (c == 10) {
1565 wait_for_xmitr(priv, UART_LSR_THRE);
1566 iowrite8(13, priv->membase + PCH_UART_THR);
1567 }
1568
1569 /*
1570 * Finally, wait for transmitter to become empty
1571 * and restore the IER
1572 */
1573 wait_for_xmitr(priv, BOTH_EMPTY);
1574 iowrite8(ier, priv->membase + UART_IER);
1575}
1576#endif /* CONFIG_CONSOLE_POLL */
1577
1578static struct uart_ops pch_uart_ops = {
1579 .tx_empty = pch_uart_tx_empty,
1580 .set_mctrl = pch_uart_set_mctrl,
1581 .get_mctrl = pch_uart_get_mctrl,
1582 .stop_tx = pch_uart_stop_tx,
1583 .start_tx = pch_uart_start_tx,
1584 .stop_rx = pch_uart_stop_rx,
1585 .enable_ms = pch_uart_enable_ms,
1586 .break_ctl = pch_uart_break_ctl,
1587 .startup = pch_uart_startup,
1588 .shutdown = pch_uart_shutdown,
1589 .set_termios = pch_uart_set_termios,
1590/* .pm = pch_uart_pm, Not supported yet */
1591/* .set_wake = pch_uart_set_wake, Not supported yet */
1592 .type = pch_uart_type,
1593 .release_port = pch_uart_release_port,
1594 .request_port = pch_uart_request_port,
1595 .config_port = pch_uart_config_port,
1596 .verify_port = pch_uart_verify_port,
1597#ifdef CONFIG_CONSOLE_POLL
1598 .poll_get_char = pch_uart_get_poll_char,
1599 .poll_put_char = pch_uart_put_poll_char,
1600#endif
1601};
1602
1603#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1604
1550static void pch_console_putchar(struct uart_port *port, int ch) 1605static void pch_console_putchar(struct uart_port *port, int ch)
1551{ 1606{
1552 struct eg20t_port *priv = 1607 struct eg20t_port *priv =
@@ -1655,7 +1710,7 @@ static struct console pch_console = {
1655#define PCH_CONSOLE (&pch_console) 1710#define PCH_CONSOLE (&pch_console)
1656#else 1711#else
1657#define PCH_CONSOLE NULL 1712#define PCH_CONSOLE NULL
1658#endif 1713#endif /* CONFIG_SERIAL_PCH_UART_CONSOLE */
1659 1714
1660static struct uart_driver pch_uart_driver = { 1715static struct uart_driver pch_uart_driver = {
1661 .owner = THIS_MODULE, 1716 .owner = THIS_MODULE,
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index 2769a38d15b6..0c8a9fa2be6c 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -39,6 +39,7 @@
39#include <linux/tty_flip.h> 39#include <linux/tty_flip.h>
40#include <linux/serial_core.h> 40#include <linux/serial_core.h>
41#include <linux/serial.h> 41#include <linux/serial.h>
42#include <linux/serial_s3c.h>
42#include <linux/delay.h> 43#include <linux/delay.h>
43#include <linux/clk.h> 44#include <linux/clk.h>
44#include <linux/cpufreq.h> 45#include <linux/cpufreq.h>
@@ -46,10 +47,9 @@
46 47
47#include <asm/irq.h> 48#include <asm/irq.h>
48 49
49#include <mach/hardware.h> 50#ifdef CONFIG_SAMSUNG_CLOCK
50
51#include <plat/regs-serial.h>
52#include <plat/clock.h> 51#include <plat/clock.h>
52#endif
53 53
54#include "samsung.h" 54#include "samsung.h"
55 55
@@ -446,6 +446,8 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
446 446
447 /* Clear pending interrupts and mask all interrupts */ 447 /* Clear pending interrupts and mask all interrupts */
448 if (s3c24xx_serial_has_interrupt_mask(port)) { 448 if (s3c24xx_serial_has_interrupt_mask(port)) {
449 free_irq(port->irq, ourport);
450
449 wr_regl(port, S3C64XX_UINTP, 0xf); 451 wr_regl(port, S3C64XX_UINTP, 0xf);
450 wr_regl(port, S3C64XX_UINTM, 0xf); 452 wr_regl(port, S3C64XX_UINTM, 0xf);
451 } 453 }
@@ -505,6 +507,8 @@ static int s3c64xx_serial_startup(struct uart_port *port)
505 dbg("s3c64xx_serial_startup: port=%p (%08lx,%p)\n", 507 dbg("s3c64xx_serial_startup: port=%p (%08lx,%p)\n",
506 port->mapbase, port->membase); 508 port->mapbase, port->membase);
507 509
510 wr_regl(port, S3C64XX_UINTM, 0xf);
511
508 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED, 512 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED,
509 s3c24xx_serial_portname(port), ourport); 513 s3c24xx_serial_portname(port), ourport);
510 if (ret) { 514 if (ret) {
@@ -894,7 +898,7 @@ console_initcall(s3c24xx_serial_console_init);
894#define S3C24XX_SERIAL_CONSOLE NULL 898#define S3C24XX_SERIAL_CONSOLE NULL
895#endif 899#endif
896 900
897#ifdef CONFIG_CONSOLE_POLL 901#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
898static int s3c24xx_serial_get_poll_char(struct uart_port *port); 902static int s3c24xx_serial_get_poll_char(struct uart_port *port);
899static void s3c24xx_serial_put_poll_char(struct uart_port *port, 903static void s3c24xx_serial_put_poll_char(struct uart_port *port,
900 unsigned char c); 904 unsigned char c);
@@ -918,7 +922,7 @@ static struct uart_ops s3c24xx_serial_ops = {
918 .request_port = s3c24xx_serial_request_port, 922 .request_port = s3c24xx_serial_request_port,
919 .config_port = s3c24xx_serial_config_port, 923 .config_port = s3c24xx_serial_config_port,
920 .verify_port = s3c24xx_serial_verify_port, 924 .verify_port = s3c24xx_serial_verify_port,
921#ifdef CONFIG_CONSOLE_POLL 925#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
922 .poll_get_char = s3c24xx_serial_get_poll_char, 926 .poll_get_char = s3c24xx_serial_get_poll_char,
923 .poll_put_char = s3c24xx_serial_put_poll_char, 927 .poll_put_char = s3c24xx_serial_put_poll_char,
924#endif 928#endif
@@ -1162,6 +1166,18 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1162 ourport->tx_irq = ret; 1166 ourport->tx_irq = ret;
1163 1167
1164 ourport->clk = clk_get(&platdev->dev, "uart"); 1168 ourport->clk = clk_get(&platdev->dev, "uart");
1169 if (IS_ERR(ourport->clk)) {
1170 pr_err("%s: Controller clock not found\n",
1171 dev_name(&platdev->dev));
1172 return PTR_ERR(ourport->clk);
1173 }
1174
1175 ret = clk_prepare_enable(ourport->clk);
1176 if (ret) {
1177 pr_err("uart: clock failed to prepare+enable: %d\n", ret);
1178 clk_put(ourport->clk);
1179 return ret;
1180 }
1165 1181
1166 /* Keep all interrupts masked and cleared */ 1182 /* Keep all interrupts masked and cleared */
1167 if (s3c24xx_serial_has_interrupt_mask(port)) { 1183 if (s3c24xx_serial_has_interrupt_mask(port)) {
@@ -1176,9 +1192,11 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1176 1192
1177 /* reset the fifos (and setup the uart) */ 1193 /* reset the fifos (and setup the uart) */
1178 s3c24xx_serial_resetport(port, cfg); 1194 s3c24xx_serial_resetport(port, cfg);
1195 clk_disable_unprepare(ourport->clk);
1179 return 0; 1196 return 0;
1180} 1197}
1181 1198
1199#ifdef CONFIG_SAMSUNG_CLOCK
1182static ssize_t s3c24xx_serial_show_clksrc(struct device *dev, 1200static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
1183 struct device_attribute *attr, 1201 struct device_attribute *attr,
1184 char *buf) 1202 char *buf)
@@ -1194,7 +1212,7 @@ static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
1194} 1212}
1195 1213
1196static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL); 1214static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
1197 1215#endif
1198 1216
1199/* Device driver serial port probe */ 1217/* Device driver serial port probe */
1200 1218
@@ -1252,9 +1270,11 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
1252 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port); 1270 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
1253 platform_set_drvdata(pdev, &ourport->port); 1271 platform_set_drvdata(pdev, &ourport->port);
1254 1272
1273#ifdef CONFIG_SAMSUNG_CLOCK
1255 ret = device_create_file(&pdev->dev, &dev_attr_clock_source); 1274 ret = device_create_file(&pdev->dev, &dev_attr_clock_source);
1256 if (ret < 0) 1275 if (ret < 0)
1257 dev_err(&pdev->dev, "failed to add clock source attr.\n"); 1276 dev_err(&pdev->dev, "failed to add clock source attr.\n");
1277#endif
1258 1278
1259 ret = s3c24xx_serial_cpufreq_register(ourport); 1279 ret = s3c24xx_serial_cpufreq_register(ourport);
1260 if (ret < 0) 1280 if (ret < 0)
@@ -1272,7 +1292,9 @@ static int s3c24xx_serial_remove(struct platform_device *dev)
1272 1292
1273 if (port) { 1293 if (port) {
1274 s3c24xx_serial_cpufreq_deregister(to_ourport(port)); 1294 s3c24xx_serial_cpufreq_deregister(to_ourport(port));
1295#ifdef CONFIG_SAMSUNG_CLOCK
1275 device_remove_file(&dev->dev, &dev_attr_clock_source); 1296 device_remove_file(&dev->dev, &dev_attr_clock_source);
1297#endif
1276 uart_remove_one_port(&s3c24xx_uart_drv, port); 1298 uart_remove_one_port(&s3c24xx_uart_drv, port);
1277 } 1299 }
1278 1300
@@ -1307,9 +1329,29 @@ static int s3c24xx_serial_resume(struct device *dev)
1307 return 0; 1329 return 0;
1308} 1330}
1309 1331
1332static int s3c24xx_serial_resume_noirq(struct device *dev)
1333{
1334 struct uart_port *port = s3c24xx_dev_to_port(dev);
1335
1336 if (port) {
1337 /* restore IRQ mask */
1338 if (s3c24xx_serial_has_interrupt_mask(port)) {
1339 unsigned int uintm = 0xf;
1340 if (tx_enabled(port))
1341 uintm &= ~S3C64XX_UINTM_TXD_MSK;
1342 if (rx_enabled(port))
1343 uintm &= ~S3C64XX_UINTM_RXD_MSK;
1344 wr_regl(port, S3C64XX_UINTM, uintm);
1345 }
1346 }
1347
1348 return 0;
1349}
1350
1310static const struct dev_pm_ops s3c24xx_serial_pm_ops = { 1351static const struct dev_pm_ops s3c24xx_serial_pm_ops = {
1311 .suspend = s3c24xx_serial_suspend, 1352 .suspend = s3c24xx_serial_suspend,
1312 .resume = s3c24xx_serial_resume, 1353 .resume = s3c24xx_serial_resume,
1354 .resume_noirq = s3c24xx_serial_resume_noirq,
1313}; 1355};
1314#define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops) 1356#define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops)
1315 1357
@@ -1343,6 +1385,13 @@ s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
1343 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0; 1385 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
1344} 1386}
1345 1387
1388static bool
1389s3c24xx_port_configured(unsigned int ucon)
1390{
1391 /* consider the serial port configured if the tx/rx mode set */
1392 return (ucon & 0xf) != 0;
1393}
1394
1346#ifdef CONFIG_CONSOLE_POLL 1395#ifdef CONFIG_CONSOLE_POLL
1347/* 1396/*
1348 * Console polling routines for writing and reading from the uart while 1397 * Console polling routines for writing and reading from the uart while
@@ -1365,6 +1414,11 @@ static void s3c24xx_serial_put_poll_char(struct uart_port *port,
1365 unsigned char c) 1414 unsigned char c)
1366{ 1415{
1367 unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON); 1416 unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
1417 unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
1418
1419 /* not possible to xmit on unconfigured port */
1420 if (!s3c24xx_port_configured(ucon))
1421 return;
1368 1422
1369 while (!s3c24xx_serial_console_txrdy(port, ufcon)) 1423 while (!s3c24xx_serial_console_txrdy(port, ufcon))
1370 cpu_relax(); 1424 cpu_relax();
@@ -1377,6 +1431,12 @@ static void
1377s3c24xx_serial_console_putchar(struct uart_port *port, int ch) 1431s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
1378{ 1432{
1379 unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON); 1433 unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
1434 unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
1435
1436 /* not possible to xmit on unconfigured port */
1437 if (!s3c24xx_port_configured(ucon))
1438 return;
1439
1380 while (!s3c24xx_serial_console_txrdy(port, ufcon)) 1440 while (!s3c24xx_serial_console_txrdy(port, ufcon))
1381 barrier(); 1441 barrier();
1382 wr_regb(cons_uart, S3C2410_UTXH, ch); 1442 wr_regb(cons_uart, S3C2410_UTXH, ch);
@@ -1409,9 +1469,7 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud,
1409 "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n", 1469 "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
1410 port, ulcon, ucon, ubrdiv); 1470 port, ulcon, ucon, ubrdiv);
1411 1471
1412 if ((ucon & 0xf) != 0) { 1472 if (s3c24xx_port_configured(ucon)) {
1413 /* consider the serial port configured if the tx/rx mode set */
1414
1415 switch (ulcon & S3C2410_LCON_CSMASK) { 1473 switch (ulcon & S3C2410_LCON_CSMASK) {
1416 case S3C2410_LCON_CS5: 1474 case S3C2410_LCON_CS5:
1417 *bits = 5; 1475 *bits = 5;
@@ -1758,6 +1816,7 @@ static int __init s3c24xx_serial_modinit(void)
1758 1816
1759static void __exit s3c24xx_serial_modexit(void) 1817static void __exit s3c24xx_serial_modexit(void)
1760{ 1818{
1819 platform_driver_unregister(&samsung_serial_driver);
1761 uart_unregister_driver(&s3c24xx_uart_drv); 1820 uart_unregister_driver(&s3c24xx_uart_drv);
1762} 1821}
1763 1822
diff --git a/drivers/tty/serial/samsung.h b/drivers/tty/serial/samsung.h
index 1a4bca3e4179..00a499ecd385 100644
--- a/drivers/tty/serial/samsung.h
+++ b/drivers/tty/serial/samsung.h
@@ -76,7 +76,9 @@ struct s3c24xx_uart_port {
76#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg)) 76#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg))
77#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg)) 77#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg))
78 78
79#ifdef CONFIG_SERIAL_SAMSUNG_DEBUG 79#if defined(CONFIG_SERIAL_SAMSUNG_DEBUG) && \
80 defined(CONFIG_DEBUG_LL) && \
81 !defined(MODULE)
80 82
81extern void printascii(const char *); 83extern void printascii(const char *);
82 84
diff --git a/drivers/tty/serial/sccnxp.c b/drivers/tty/serial/sccnxp.c
index 08dbfb88d42c..c77304155410 100644
--- a/drivers/tty/serial/sccnxp.c
+++ b/drivers/tty/serial/sccnxp.c
@@ -27,6 +27,7 @@
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/platform_data/serial-sccnxp.h> 29#include <linux/platform_data/serial-sccnxp.h>
30#include <linux/regulator/consumer.h>
30 31
31#define SCCNXP_NAME "uart-sccnxp" 32#define SCCNXP_NAME "uart-sccnxp"
32#define SCCNXP_MAJOR 204 33#define SCCNXP_MAJOR 204
@@ -131,6 +132,8 @@ struct sccnxp_port {
131 struct timer_list timer; 132 struct timer_list timer;
132 133
133 struct sccnxp_pdata pdata; 134 struct sccnxp_pdata pdata;
135
136 struct regulator *regulator;
134}; 137};
135 138
136static inline u8 sccnxp_raw_read(void __iomem *base, u8 reg, u8 shift) 139static inline u8 sccnxp_raw_read(void __iomem *base, u8 reg, u8 shift)
@@ -789,8 +792,6 @@ static int sccnxp_probe(struct platform_device *pdev)
789 return -EADDRNOTAVAIL; 792 return -EADDRNOTAVAIL;
790 } 793 }
791 794
792 dev_set_name(&pdev->dev, SCCNXP_NAME);
793
794 s = devm_kzalloc(&pdev->dev, sizeof(struct sccnxp_port), GFP_KERNEL); 795 s = devm_kzalloc(&pdev->dev, sizeof(struct sccnxp_port), GFP_KERNEL);
795 if (!s) { 796 if (!s) {
796 dev_err(&pdev->dev, "Error allocating port structure\n"); 797 dev_err(&pdev->dev, "Error allocating port structure\n");
@@ -918,6 +919,16 @@ static int sccnxp_probe(struct platform_device *pdev)
918 goto err_out; 919 goto err_out;
919 } 920 }
920 921
922 s->regulator = devm_regulator_get(&pdev->dev, "VCC");
923 if (!IS_ERR(s->regulator)) {
924 ret = regulator_enable(s->regulator);
925 if (ret) {
926 dev_err(&pdev->dev,
927 "Failed to enable regulator: %i\n", ret);
928 return ret;
929 }
930 }
931
921 membase = devm_ioremap_resource(&pdev->dev, res); 932 membase = devm_ioremap_resource(&pdev->dev, res);
922 if (IS_ERR(membase)) { 933 if (IS_ERR(membase)) {
923 ret = PTR_ERR(membase); 934 ret = PTR_ERR(membase);
@@ -967,10 +978,6 @@ static int sccnxp_probe(struct platform_device *pdev)
967 s->imr = 0; 978 s->imr = 0;
968 sccnxp_write(&s->port[0], SCCNXP_IMR_REG, 0); 979 sccnxp_write(&s->port[0], SCCNXP_IMR_REG, 0);
969 980
970 /* Board specific configure */
971 if (s->pdata.init)
972 s->pdata.init();
973
974 if (!s->poll) { 981 if (!s->poll) {
975 ret = devm_request_threaded_irq(&pdev->dev, s->irq, NULL, 982 ret = devm_request_threaded_irq(&pdev->dev, s->irq, NULL,
976 sccnxp_ist, 983 sccnxp_ist,
@@ -1011,8 +1018,8 @@ static int sccnxp_remove(struct platform_device *pdev)
1011 uart_unregister_driver(&s->uart); 1018 uart_unregister_driver(&s->uart);
1012 platform_set_drvdata(pdev, NULL); 1019 platform_set_drvdata(pdev, NULL);
1013 1020
1014 if (s->pdata.exit) 1021 if (!IS_ERR(s->regulator))
1015 s->pdata.exit(); 1022 return regulator_disable(s->regulator);
1016 1023
1017 return 0; 1024 return 0;
1018} 1025}
diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
index 372de8ade76a..9799d043a9bd 100644
--- a/drivers/tty/serial/serial-tegra.c
+++ b/drivers/tty/serial/serial-tegra.c
@@ -26,6 +26,7 @@
26#include <linux/dmaengine.h> 26#include <linux/dmaengine.h>
27#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
28#include <linux/dmapool.h> 28#include <linux/dmapool.h>
29#include <linux/err.h>
29#include <linux/io.h> 30#include <linux/io.h>
30#include <linux/irq.h> 31#include <linux/irq.h>
31#include <linux/module.h> 32#include <linux/module.h>
@@ -1301,11 +1302,9 @@ static int tegra_uart_probe(struct platform_device *pdev)
1301 } 1302 }
1302 1303
1303 u->mapbase = resource->start; 1304 u->mapbase = resource->start;
1304 u->membase = devm_request_and_ioremap(&pdev->dev, resource); 1305 u->membase = devm_ioremap_resource(&pdev->dev, resource);
1305 if (!u->membase) { 1306 if (IS_ERR(u->membase))
1306 dev_err(&pdev->dev, "memregion/iomap address req failed\n"); 1307 return PTR_ERR(u->membase);
1307 return -EADDRNOTAVAIL;
1308 }
1309 1308
1310 tup->uart_clk = devm_clk_get(&pdev->dev, NULL); 1309 tup->uart_clk = devm_clk_get(&pdev->dev, NULL);
1311 if (IS_ERR(tup->uart_clk)) { 1310 if (IS_ERR(tup->uart_clk)) {
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index a400002dfa84..f87dbfd32770 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1711,7 +1711,7 @@ static int uart_proc_show(struct seq_file *m, void *v)
1711 1711
1712static int uart_proc_open(struct inode *inode, struct file *file) 1712static int uart_proc_open(struct inode *inode, struct file *file)
1713{ 1713{
1714 return single_open(file, uart_proc_show, PDE(inode)->data); 1714 return single_open(file, uart_proc_show, PDE_DATA(inode));
1715} 1715}
1716 1716
1717static const struct file_operations uart_proc_fops = { 1717static const struct file_operations uart_proc_fops = {
@@ -1941,6 +1941,8 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
1941 mutex_unlock(&port->mutex); 1941 mutex_unlock(&port->mutex);
1942 return 0; 1942 return 0;
1943 } 1943 }
1944 put_device(tty_dev);
1945
1944 if (console_suspend_enabled || !uart_console(uport)) 1946 if (console_suspend_enabled || !uart_console(uport))
1945 uport->suspended = 1; 1947 uport->suspended = 1;
1946 1948
@@ -2006,9 +2008,11 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2006 disable_irq_wake(uport->irq); 2008 disable_irq_wake(uport->irq);
2007 uport->irq_wake = 0; 2009 uport->irq_wake = 0;
2008 } 2010 }
2011 put_device(tty_dev);
2009 mutex_unlock(&port->mutex); 2012 mutex_unlock(&port->mutex);
2010 return 0; 2013 return 0;
2011 } 2014 }
2015 put_device(tty_dev);
2012 uport->suspended = 0; 2016 uport->suspended = 0;
2013 2017
2014 /* 2018 /*
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
index 4c22a1529aac..5aca7364634c 100644
--- a/drivers/tty/serial/sh-sci.h
+++ b/drivers/tty/serial/sh-sci.h
@@ -15,8 +15,6 @@
15 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 15 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
16 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 16 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
17 defined(CONFIG_ARCH_SH73A0) || \ 17 defined(CONFIG_ARCH_SH73A0) || \
18 defined(CONFIG_ARCH_SH7367) || \
19 defined(CONFIG_ARCH_SH7377) || \
20 defined(CONFIG_ARCH_SH7372) || \ 18 defined(CONFIG_ARCH_SH7372) || \
21 defined(CONFIG_ARCH_R8A7740) 19 defined(CONFIG_ARCH_R8A7740)
22 20
diff --git a/drivers/tty/serial/sirfsoc_uart.c b/drivers/tty/serial/sirfsoc_uart.c
index 6bbfe9934a4d..03465b673945 100644
--- a/drivers/tty/serial/sirfsoc_uart.c
+++ b/drivers/tty/serial/sirfsoc_uart.c
@@ -758,7 +758,7 @@ static struct of_device_id sirfsoc_uart_ids[] = {
758 { .compatible = "sirf,marco-uart", }, 758 { .compatible = "sirf,marco-uart", },
759 {} 759 {}
760}; 760};
761MODULE_DEVICE_TABLE(of, sirfsoc_serial_of_match); 761MODULE_DEVICE_TABLE(of, sirfsoc_uart_ids);
762 762
763static struct platform_driver sirfsoc_uart_driver = { 763static struct platform_driver sirfsoc_uart_driver = {
764 .probe = sirfsoc_uart_probe, 764 .probe = sirfsoc_uart_probe,
diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c
index 8de2213664e0..a422c8b55a47 100644
--- a/drivers/tty/serial/sunsab.c
+++ b/drivers/tty/serial/sunsab.c
@@ -203,7 +203,7 @@ receive_chars(struct uart_sunsab_port *up,
203 flag = TTY_FRAME; 203 flag = TTY_FRAME;
204 } 204 }
205 205
206 if (uart_handle_sysrq_char(&up->port, ch)) 206 if (uart_handle_sysrq_char(&up->port, ch) || !port)
207 continue; 207 continue;
208 208
209 if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 && 209 if ((stat->sreg.isr0 & (up->port.ignore_status_mask & 0xff)) == 0 &&
diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index e343d6670854..0d8465728473 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -968,6 +968,7 @@ static struct uart_ops sunsu_pops = {
968#define UART_NR 4 968#define UART_NR 4
969 969
970static struct uart_sunsu_port sunsu_ports[UART_NR]; 970static struct uart_sunsu_port sunsu_ports[UART_NR];
971static int nr_inst; /* Number of already registered ports */
971 972
972#ifdef CONFIG_SERIO 973#ifdef CONFIG_SERIO
973 974
@@ -1337,13 +1338,8 @@ static int __init sunsu_console_setup(struct console *co, char *options)
1337 printk("Console: ttyS%d (SU)\n", 1338 printk("Console: ttyS%d (SU)\n",
1338 (sunsu_reg.minor - 64) + co->index); 1339 (sunsu_reg.minor - 64) + co->index);
1339 1340
1340 /* 1341 if (co->index > nr_inst)
1341 * Check whether an invalid uart number has been specified, and 1342 return -ENODEV;
1342 * if so, search for the first available port that does have
1343 * console support.
1344 */
1345 if (co->index >= UART_NR)
1346 co->index = 0;
1347 port = &sunsu_ports[co->index].port; 1343 port = &sunsu_ports[co->index].port;
1348 1344
1349 /* 1345 /*
@@ -1408,7 +1404,6 @@ static enum su_type su_get_type(struct device_node *dp)
1408 1404
1409static int su_probe(struct platform_device *op) 1405static int su_probe(struct platform_device *op)
1410{ 1406{
1411 static int inst;
1412 struct device_node *dp = op->dev.of_node; 1407 struct device_node *dp = op->dev.of_node;
1413 struct uart_sunsu_port *up; 1408 struct uart_sunsu_port *up;
1414 struct resource *rp; 1409 struct resource *rp;
@@ -1418,16 +1413,16 @@ static int su_probe(struct platform_device *op)
1418 1413
1419 type = su_get_type(dp); 1414 type = su_get_type(dp);
1420 if (type == SU_PORT_PORT) { 1415 if (type == SU_PORT_PORT) {
1421 if (inst >= UART_NR) 1416 if (nr_inst >= UART_NR)
1422 return -EINVAL; 1417 return -EINVAL;
1423 up = &sunsu_ports[inst]; 1418 up = &sunsu_ports[nr_inst];
1424 } else { 1419 } else {
1425 up = kzalloc(sizeof(*up), GFP_KERNEL); 1420 up = kzalloc(sizeof(*up), GFP_KERNEL);
1426 if (!up) 1421 if (!up)
1427 return -ENOMEM; 1422 return -ENOMEM;
1428 } 1423 }
1429 1424
1430 up->port.line = inst; 1425 up->port.line = nr_inst;
1431 1426
1432 spin_lock_init(&up->port.lock); 1427 spin_lock_init(&up->port.lock);
1433 1428
@@ -1461,6 +1456,8 @@ static int su_probe(struct platform_device *op)
1461 } 1456 }
1462 dev_set_drvdata(&op->dev, up); 1457 dev_set_drvdata(&op->dev, up);
1463 1458
1459 nr_inst++;
1460
1464 return 0; 1461 return 0;
1465 } 1462 }
1466 1463
@@ -1488,7 +1485,7 @@ static int su_probe(struct platform_device *op)
1488 1485
1489 dev_set_drvdata(&op->dev, up); 1486 dev_set_drvdata(&op->dev, up);
1490 1487
1491 inst++; 1488 nr_inst++;
1492 1489
1493 return 0; 1490 return 0;
1494 1491
@@ -1595,6 +1592,7 @@ static int __init sunsu_init(void)
1595 1592
1596static void __exit sunsu_exit(void) 1593static void __exit sunsu_exit(void)
1597{ 1594{
1595 platform_driver_unregister(&su_driver);
1598 if (sunsu_reg.nr) 1596 if (sunsu_reg.nr)
1599 sunserial_unregister_minors(&sunsu_reg, sunsu_reg.nr); 1597 sunserial_unregister_minors(&sunsu_reg, sunsu_reg.nr);
1600} 1598}
diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c
index 27669ff3d446..813ef8eb8eff 100644
--- a/drivers/tty/serial/sunzilog.c
+++ b/drivers/tty/serial/sunzilog.c
@@ -388,7 +388,7 @@ sunzilog_receive_chars(struct uart_sunzilog_port *up,
388 else if (r1 & CRC_ERR) 388 else if (r1 & CRC_ERR)
389 flag = TTY_FRAME; 389 flag = TTY_FRAME;
390 } 390 }
391 if (uart_handle_sysrq_char(&up->port, ch)) 391 if (uart_handle_sysrq_char(&up->port, ch) || !port)
392 continue; 392 continue;
393 393
394 if (up->port.ignore_status_mask == 0xff || 394 if (up->port.ignore_status_mask == 0xff ||
diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
index 705240e6c4ec..1a8bc2275ea4 100644
--- a/drivers/tty/serial/vt8500_serial.c
+++ b/drivers/tty/serial/vt8500_serial.c
@@ -35,6 +35,7 @@
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/of.h> 37#include <linux/of.h>
38#include <linux/err.h>
38 39
39/* 40/*
40 * UART Register offsets 41 * UART Register offsets
@@ -585,9 +586,9 @@ static int vt8500_serial_probe(struct platform_device *pdev)
585 if (!vt8500_port) 586 if (!vt8500_port)
586 return -ENOMEM; 587 return -ENOMEM;
587 588
588 vt8500_port->uart.membase = devm_request_and_ioremap(&pdev->dev, mmres); 589 vt8500_port->uart.membase = devm_ioremap_resource(&pdev->dev, mmres);
589 if (!vt8500_port->uart.membase) 590 if (IS_ERR(vt8500_port->uart.membase))
590 return -EADDRNOTAVAIL; 591 return PTR_ERR(vt8500_port->uart.membase);
591 592
592 vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0); 593 vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0);
593 if (IS_ERR(vt8500_port->clk)) { 594 if (IS_ERR(vt8500_port->clk)) {
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index ba451c7209fc..4e5c77834c50 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -578,14 +578,13 @@ static int xuartps_startup(struct uart_port *port)
578 /* Receive Timeout register is enabled with value of 10 */ 578 /* Receive Timeout register is enabled with value of 10 */
579 xuartps_writel(10, XUARTPS_RXTOUT_OFFSET); 579 xuartps_writel(10, XUARTPS_RXTOUT_OFFSET);
580 580
581 /* Clear out any pending interrupts before enabling them */
582 xuartps_writel(xuartps_readl(XUARTPS_ISR_OFFSET), XUARTPS_ISR_OFFSET);
581 583
582 /* Set the Interrupt Registers with desired interrupts */ 584 /* Set the Interrupt Registers with desired interrupts */
583 xuartps_writel(XUARTPS_IXR_TXEMPTY | XUARTPS_IXR_PARITY | 585 xuartps_writel(XUARTPS_IXR_TXEMPTY | XUARTPS_IXR_PARITY |
584 XUARTPS_IXR_FRAMING | XUARTPS_IXR_OVERRUN | 586 XUARTPS_IXR_FRAMING | XUARTPS_IXR_OVERRUN |
585 XUARTPS_IXR_RXTRIG | XUARTPS_IXR_TOUT, XUARTPS_IER_OFFSET); 587 XUARTPS_IXR_RXTRIG | XUARTPS_IXR_TOUT, XUARTPS_IER_OFFSET);
586 xuartps_writel(~(XUARTPS_IXR_TXEMPTY | XUARTPS_IXR_PARITY |
587 XUARTPS_IXR_FRAMING | XUARTPS_IXR_OVERRUN |
588 XUARTPS_IXR_RXTRIG | XUARTPS_IXR_TOUT), XUARTPS_IDR_OFFSET);
589 588
590 return retval; 589 return retval;
591} 590}
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
index 8983276aa35e..8eaf1ab8addb 100644
--- a/drivers/tty/synclink.c
+++ b/drivers/tty/synclink.c
@@ -1058,9 +1058,6 @@ static void mgsl_bh_handler(struct work_struct *work)
1058 container_of(work, struct mgsl_struct, task); 1058 container_of(work, struct mgsl_struct, task);
1059 int action; 1059 int action;
1060 1060
1061 if (!info)
1062 return;
1063
1064 if ( debug_level >= DEBUG_LEVEL_BH ) 1061 if ( debug_level >= DEBUG_LEVEL_BH )
1065 printk( "%s(%d):mgsl_bh_handler(%s) entry\n", 1062 printk( "%s(%d):mgsl_bh_handler(%s) entry\n",
1066 __FILE__,__LINE__,info->device_name); 1063 __FILE__,__LINE__,info->device_name);
@@ -3311,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3311 port->blocked_open++; 3308 port->blocked_open++;
3312 3309
3313 while (1) { 3310 while (1) {
3314 if (tty->termios.c_cflag & CBAUD) 3311 if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags))
3315 tty_port_raise_dtr_rts(port); 3312 tty_port_raise_dtr_rts(port);
3316 3313
3317 set_current_state(TASK_INTERRUPTIBLE); 3314 set_current_state(TASK_INTERRUPTIBLE);
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index aa9eece35c3b..1abf946463f6 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3308 port->blocked_open++; 3308 port->blocked_open++;
3309 3309
3310 while (1) { 3310 while (1) {
3311 if ((tty->termios.c_cflag & CBAUD)) 3311 if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags))
3312 tty_port_raise_dtr_rts(port); 3312 tty_port_raise_dtr_rts(port);
3313 3313
3314 set_current_state(TASK_INTERRUPTIBLE); 3314 set_current_state(TASK_INTERRUPTIBLE);
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
index 6d5780cf1d57..ff171384ea52 100644
--- a/drivers/tty/synclinkmp.c
+++ b/drivers/tty/synclinkmp.c
@@ -3329,7 +3329,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3329 port->blocked_open++; 3329 port->blocked_open++;
3330 3330
3331 while (1) { 3331 while (1) {
3332 if (tty->termios.c_cflag & CBAUD) 3332 if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags))
3333 tty_port_raise_dtr_rts(port); 3333 tty_port_raise_dtr_rts(port);
3334 3334
3335 set_current_state(TASK_INTERRUPTIBLE); 3335 set_current_state(TASK_INTERRUPTIBLE);
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 80310f7f58d3..55ba46f6207d 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -106,7 +106,7 @@ static void sysrq_handle_SAK(int key)
106} 106}
107static struct sysrq_key_op sysrq_SAK_op = { 107static struct sysrq_key_op sysrq_SAK_op = {
108 .handler = sysrq_handle_SAK, 108 .handler = sysrq_handle_SAK,
109 .help_msg = "saK", 109 .help_msg = "sak(k)",
110 .action_msg = "SAK", 110 .action_msg = "SAK",
111 .enable_mask = SYSRQ_ENABLE_KEYBOARD, 111 .enable_mask = SYSRQ_ENABLE_KEYBOARD,
112}; 112};
@@ -122,7 +122,7 @@ static void sysrq_handle_unraw(int key)
122 122
123static struct sysrq_key_op sysrq_unraw_op = { 123static struct sysrq_key_op sysrq_unraw_op = {
124 .handler = sysrq_handle_unraw, 124 .handler = sysrq_handle_unraw,
125 .help_msg = "unRaw", 125 .help_msg = "unraw(r)",
126 .action_msg = "Keyboard mode set to system default", 126 .action_msg = "Keyboard mode set to system default",
127 .enable_mask = SYSRQ_ENABLE_KEYBOARD, 127 .enable_mask = SYSRQ_ENABLE_KEYBOARD,
128}; 128};
@@ -140,7 +140,7 @@ static void sysrq_handle_crash(int key)
140} 140}
141static struct sysrq_key_op sysrq_crash_op = { 141static struct sysrq_key_op sysrq_crash_op = {
142 .handler = sysrq_handle_crash, 142 .handler = sysrq_handle_crash,
143 .help_msg = "Crash", 143 .help_msg = "crash(c)",
144 .action_msg = "Trigger a crash", 144 .action_msg = "Trigger a crash",
145 .enable_mask = SYSRQ_ENABLE_DUMP, 145 .enable_mask = SYSRQ_ENABLE_DUMP,
146}; 146};
@@ -153,7 +153,7 @@ static void sysrq_handle_reboot(int key)
153} 153}
154static struct sysrq_key_op sysrq_reboot_op = { 154static struct sysrq_key_op sysrq_reboot_op = {
155 .handler = sysrq_handle_reboot, 155 .handler = sysrq_handle_reboot,
156 .help_msg = "reBoot", 156 .help_msg = "reboot(b)",
157 .action_msg = "Resetting", 157 .action_msg = "Resetting",
158 .enable_mask = SYSRQ_ENABLE_BOOT, 158 .enable_mask = SYSRQ_ENABLE_BOOT,
159}; 159};
@@ -164,7 +164,7 @@ static void sysrq_handle_sync(int key)
164} 164}
165static struct sysrq_key_op sysrq_sync_op = { 165static struct sysrq_key_op sysrq_sync_op = {
166 .handler = sysrq_handle_sync, 166 .handler = sysrq_handle_sync,
167 .help_msg = "Sync", 167 .help_msg = "sync(s)",
168 .action_msg = "Emergency Sync", 168 .action_msg = "Emergency Sync",
169 .enable_mask = SYSRQ_ENABLE_SYNC, 169 .enable_mask = SYSRQ_ENABLE_SYNC,
170}; 170};
@@ -176,7 +176,7 @@ static void sysrq_handle_show_timers(int key)
176 176
177static struct sysrq_key_op sysrq_show_timers_op = { 177static struct sysrq_key_op sysrq_show_timers_op = {
178 .handler = sysrq_handle_show_timers, 178 .handler = sysrq_handle_show_timers,
179 .help_msg = "show-all-timers(Q)", 179 .help_msg = "show-all-timers(q)",
180 .action_msg = "Show clockevent devices & pending hrtimers (no others)", 180 .action_msg = "Show clockevent devices & pending hrtimers (no others)",
181}; 181};
182 182
@@ -186,7 +186,7 @@ static void sysrq_handle_mountro(int key)
186} 186}
187static struct sysrq_key_op sysrq_mountro_op = { 187static struct sysrq_key_op sysrq_mountro_op = {
188 .handler = sysrq_handle_mountro, 188 .handler = sysrq_handle_mountro,
189 .help_msg = "Unmount", 189 .help_msg = "unmount(u)",
190 .action_msg = "Emergency Remount R/O", 190 .action_msg = "Emergency Remount R/O",
191 .enable_mask = SYSRQ_ENABLE_REMOUNT, 191 .enable_mask = SYSRQ_ENABLE_REMOUNT,
192}; 192};
@@ -199,7 +199,7 @@ static void sysrq_handle_showlocks(int key)
199 199
200static struct sysrq_key_op sysrq_showlocks_op = { 200static struct sysrq_key_op sysrq_showlocks_op = {
201 .handler = sysrq_handle_showlocks, 201 .handler = sysrq_handle_showlocks,
202 .help_msg = "show-all-locks(D)", 202 .help_msg = "show-all-locks(d)",
203 .action_msg = "Show Locks Held", 203 .action_msg = "Show Locks Held",
204}; 204};
205#else 205#else
@@ -250,7 +250,7 @@ static void sysrq_handle_showallcpus(int key)
250 250
251static struct sysrq_key_op sysrq_showallcpus_op = { 251static struct sysrq_key_op sysrq_showallcpus_op = {
252 .handler = sysrq_handle_showallcpus, 252 .handler = sysrq_handle_showallcpus,
253 .help_msg = "show-backtrace-all-active-cpus(L)", 253 .help_msg = "show-backtrace-all-active-cpus(l)",
254 .action_msg = "Show backtrace of all active CPUs", 254 .action_msg = "Show backtrace of all active CPUs",
255 .enable_mask = SYSRQ_ENABLE_DUMP, 255 .enable_mask = SYSRQ_ENABLE_DUMP,
256}; 256};
@@ -265,7 +265,7 @@ static void sysrq_handle_showregs(int key)
265} 265}
266static struct sysrq_key_op sysrq_showregs_op = { 266static struct sysrq_key_op sysrq_showregs_op = {
267 .handler = sysrq_handle_showregs, 267 .handler = sysrq_handle_showregs,
268 .help_msg = "show-registers(P)", 268 .help_msg = "show-registers(p)",
269 .action_msg = "Show Regs", 269 .action_msg = "Show Regs",
270 .enable_mask = SYSRQ_ENABLE_DUMP, 270 .enable_mask = SYSRQ_ENABLE_DUMP,
271}; 271};
@@ -276,7 +276,7 @@ static void sysrq_handle_showstate(int key)
276} 276}
277static struct sysrq_key_op sysrq_showstate_op = { 277static struct sysrq_key_op sysrq_showstate_op = {
278 .handler = sysrq_handle_showstate, 278 .handler = sysrq_handle_showstate,
279 .help_msg = "show-task-states(T)", 279 .help_msg = "show-task-states(t)",
280 .action_msg = "Show State", 280 .action_msg = "Show State",
281 .enable_mask = SYSRQ_ENABLE_DUMP, 281 .enable_mask = SYSRQ_ENABLE_DUMP,
282}; 282};
@@ -287,7 +287,7 @@ static void sysrq_handle_showstate_blocked(int key)
287} 287}
288static struct sysrq_key_op sysrq_showstate_blocked_op = { 288static struct sysrq_key_op sysrq_showstate_blocked_op = {
289 .handler = sysrq_handle_showstate_blocked, 289 .handler = sysrq_handle_showstate_blocked,
290 .help_msg = "show-blocked-tasks(W)", 290 .help_msg = "show-blocked-tasks(w)",
291 .action_msg = "Show Blocked State", 291 .action_msg = "Show Blocked State",
292 .enable_mask = SYSRQ_ENABLE_DUMP, 292 .enable_mask = SYSRQ_ENABLE_DUMP,
293}; 293};
@@ -301,7 +301,7 @@ static void sysrq_ftrace_dump(int key)
301} 301}
302static struct sysrq_key_op sysrq_ftrace_dump_op = { 302static struct sysrq_key_op sysrq_ftrace_dump_op = {
303 .handler = sysrq_ftrace_dump, 303 .handler = sysrq_ftrace_dump,
304 .help_msg = "dump-ftrace-buffer(Z)", 304 .help_msg = "dump-ftrace-buffer(z)",
305 .action_msg = "Dump ftrace buffer", 305 .action_msg = "Dump ftrace buffer",
306 .enable_mask = SYSRQ_ENABLE_DUMP, 306 .enable_mask = SYSRQ_ENABLE_DUMP,
307}; 307};
@@ -315,7 +315,7 @@ static void sysrq_handle_showmem(int key)
315} 315}
316static struct sysrq_key_op sysrq_showmem_op = { 316static struct sysrq_key_op sysrq_showmem_op = {
317 .handler = sysrq_handle_showmem, 317 .handler = sysrq_handle_showmem,
318 .help_msg = "show-memory-usage(M)", 318 .help_msg = "show-memory-usage(m)",
319 .action_msg = "Show Memory", 319 .action_msg = "Show Memory",
320 .enable_mask = SYSRQ_ENABLE_DUMP, 320 .enable_mask = SYSRQ_ENABLE_DUMP,
321}; 321};
@@ -346,7 +346,7 @@ static void sysrq_handle_term(int key)
346} 346}
347static struct sysrq_key_op sysrq_term_op = { 347static struct sysrq_key_op sysrq_term_op = {
348 .handler = sysrq_handle_term, 348 .handler = sysrq_handle_term,
349 .help_msg = "terminate-all-tasks(E)", 349 .help_msg = "terminate-all-tasks(e)",
350 .action_msg = "Terminate All Tasks", 350 .action_msg = "Terminate All Tasks",
351 .enable_mask = SYSRQ_ENABLE_SIGNAL, 351 .enable_mask = SYSRQ_ENABLE_SIGNAL,
352}; 352};
@@ -365,7 +365,7 @@ static void sysrq_handle_moom(int key)
365} 365}
366static struct sysrq_key_op sysrq_moom_op = { 366static struct sysrq_key_op sysrq_moom_op = {
367 .handler = sysrq_handle_moom, 367 .handler = sysrq_handle_moom,
368 .help_msg = "memory-full-oom-kill(F)", 368 .help_msg = "memory-full-oom-kill(f)",
369 .action_msg = "Manual OOM execution", 369 .action_msg = "Manual OOM execution",
370 .enable_mask = SYSRQ_ENABLE_SIGNAL, 370 .enable_mask = SYSRQ_ENABLE_SIGNAL,
371}; 371};
@@ -377,7 +377,7 @@ static void sysrq_handle_thaw(int key)
377} 377}
378static struct sysrq_key_op sysrq_thaw_op = { 378static struct sysrq_key_op sysrq_thaw_op = {
379 .handler = sysrq_handle_thaw, 379 .handler = sysrq_handle_thaw,
380 .help_msg = "thaw-filesystems(J)", 380 .help_msg = "thaw-filesystems(j)",
381 .action_msg = "Emergency Thaw of all frozen filesystems", 381 .action_msg = "Emergency Thaw of all frozen filesystems",
382 .enable_mask = SYSRQ_ENABLE_SIGNAL, 382 .enable_mask = SYSRQ_ENABLE_SIGNAL,
383}; 383};
@@ -390,7 +390,7 @@ static void sysrq_handle_kill(int key)
390} 390}
391static struct sysrq_key_op sysrq_kill_op = { 391static struct sysrq_key_op sysrq_kill_op = {
392 .handler = sysrq_handle_kill, 392 .handler = sysrq_handle_kill,
393 .help_msg = "kill-all-tasks(I)", 393 .help_msg = "kill-all-tasks(i)",
394 .action_msg = "Kill All Tasks", 394 .action_msg = "Kill All Tasks",
395 .enable_mask = SYSRQ_ENABLE_SIGNAL, 395 .enable_mask = SYSRQ_ENABLE_SIGNAL,
396}; 396};
@@ -401,7 +401,7 @@ static void sysrq_handle_unrt(int key)
401} 401}
402static struct sysrq_key_op sysrq_unrt_op = { 402static struct sysrq_key_op sysrq_unrt_op = {
403 .handler = sysrq_handle_unrt, 403 .handler = sysrq_handle_unrt,
404 .help_msg = "nice-all-RT-tasks(N)", 404 .help_msg = "nice-all-RT-tasks(n)",
405 .action_msg = "Nice All RT Tasks", 405 .action_msg = "Nice All RT Tasks",
406 .enable_mask = SYSRQ_ENABLE_RTNICE, 406 .enable_mask = SYSRQ_ENABLE_RTNICE,
407}; 407};
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 6953dc82850c..a4fdce74f883 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -60,24 +60,22 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf)
60 tty_audit_buf_free(buf); 60 tty_audit_buf_free(buf);
61} 61}
62 62
63static void tty_audit_log(const char *description, struct task_struct *tsk, 63static void tty_audit_log(const char *description, int major, int minor,
64 kuid_t loginuid, unsigned sessionid, int major, 64 unsigned char *data, size_t size)
65 int minor, unsigned char *data, size_t size)
66{ 65{
67 struct audit_buffer *ab; 66 struct audit_buffer *ab;
67 struct task_struct *tsk = current;
68 uid_t uid = from_kuid(&init_user_ns, task_uid(tsk));
69 uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(tsk));
70 u32 sessionid = audit_get_sessionid(tsk);
68 71
69 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); 72 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY);
70 if (ab) { 73 if (ab) {
71 char name[sizeof(tsk->comm)]; 74 char name[sizeof(tsk->comm)];
72 kuid_t uid = task_uid(tsk); 75
73 76 audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
74 audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u " 77 " minor=%d comm=", description, tsk->pid, uid,
75 "major=%d minor=%d comm=", description, 78 loginuid, sessionid, major, minor);
76 tsk->pid,
77 from_kuid(&init_user_ns, uid),
78 from_kuid(&init_user_ns, loginuid),
79 sessionid,
80 major, minor);
81 get_task_comm(name, tsk); 79 get_task_comm(name, tsk);
82 audit_log_untrustedstring(ab, name); 80 audit_log_untrustedstring(ab, name);
83 audit_log_format(ab, " data="); 81 audit_log_format(ab, " data=");
@@ -90,11 +88,9 @@ static void tty_audit_log(const char *description, struct task_struct *tsk,
90 * tty_audit_buf_push - Push buffered data out 88 * tty_audit_buf_push - Push buffered data out
91 * 89 *
92 * Generate an audit message from the contents of @buf, which is owned by 90 * Generate an audit message from the contents of @buf, which is owned by
93 * @tsk with @loginuid. @buf->mutex must be locked. 91 * the current task. @buf->mutex must be locked.
94 */ 92 */
95static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid, 93static void tty_audit_buf_push(struct tty_audit_buf *buf)
96 unsigned int sessionid,
97 struct tty_audit_buf *buf)
98{ 94{
99 if (buf->valid == 0) 95 if (buf->valid == 0)
100 return; 96 return;
@@ -102,25 +98,11 @@ static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid,
102 buf->valid = 0; 98 buf->valid = 0;
103 return; 99 return;
104 } 100 }
105 tty_audit_log("tty", tsk, loginuid, sessionid, buf->major, buf->minor, 101 tty_audit_log("tty", buf->major, buf->minor, buf->data, buf->valid);
106 buf->data, buf->valid);
107 buf->valid = 0; 102 buf->valid = 0;
108} 103}
109 104
110/** 105/**
111 * tty_audit_buf_push_current - Push buffered data out
112 *
113 * Generate an audit message from the contents of @buf, which is owned by
114 * the current task. @buf->mutex must be locked.
115 */
116static void tty_audit_buf_push_current(struct tty_audit_buf *buf)
117{
118 kuid_t auid = audit_get_loginuid(current);
119 unsigned int sessionid = audit_get_sessionid(current);
120 tty_audit_buf_push(current, auid, sessionid, buf);
121}
122
123/**
124 * tty_audit_exit - Handle a task exit 106 * tty_audit_exit - Handle a task exit
125 * 107 *
126 * Make sure all buffered data is written out and deallocate the buffer. 108 * Make sure all buffered data is written out and deallocate the buffer.
@@ -130,15 +112,13 @@ void tty_audit_exit(void)
130{ 112{
131 struct tty_audit_buf *buf; 113 struct tty_audit_buf *buf;
132 114
133 spin_lock_irq(&current->sighand->siglock);
134 buf = current->signal->tty_audit_buf; 115 buf = current->signal->tty_audit_buf;
135 current->signal->tty_audit_buf = NULL; 116 current->signal->tty_audit_buf = NULL;
136 spin_unlock_irq(&current->sighand->siglock);
137 if (!buf) 117 if (!buf)
138 return; 118 return;
139 119
140 mutex_lock(&buf->mutex); 120 mutex_lock(&buf->mutex);
141 tty_audit_buf_push_current(buf); 121 tty_audit_buf_push(buf);
142 mutex_unlock(&buf->mutex); 122 mutex_unlock(&buf->mutex);
143 123
144 tty_audit_buf_put(buf); 124 tty_audit_buf_put(buf);
@@ -151,9 +131,8 @@ void tty_audit_exit(void)
151 */ 131 */
152void tty_audit_fork(struct signal_struct *sig) 132void tty_audit_fork(struct signal_struct *sig)
153{ 133{
154 spin_lock_irq(&current->sighand->siglock);
155 sig->audit_tty = current->signal->audit_tty; 134 sig->audit_tty = current->signal->audit_tty;
156 spin_unlock_irq(&current->sighand->siglock); 135 sig->audit_tty_log_passwd = current->signal->audit_tty_log_passwd;
157} 136}
158 137
159/** 138/**
@@ -163,20 +142,21 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
163{ 142{
164 struct tty_audit_buf *buf; 143 struct tty_audit_buf *buf;
165 int major, minor, should_audit; 144 int major, minor, should_audit;
145 unsigned long flags;
166 146
167 spin_lock_irq(&current->sighand->siglock); 147 spin_lock_irqsave(&current->sighand->siglock, flags);
168 should_audit = current->signal->audit_tty; 148 should_audit = current->signal->audit_tty;
169 buf = current->signal->tty_audit_buf; 149 buf = current->signal->tty_audit_buf;
170 if (buf) 150 if (buf)
171 atomic_inc(&buf->count); 151 atomic_inc(&buf->count);
172 spin_unlock_irq(&current->sighand->siglock); 152 spin_unlock_irqrestore(&current->sighand->siglock, flags);
173 153
174 major = tty->driver->major; 154 major = tty->driver->major;
175 minor = tty->driver->minor_start + tty->index; 155 minor = tty->driver->minor_start + tty->index;
176 if (buf) { 156 if (buf) {
177 mutex_lock(&buf->mutex); 157 mutex_lock(&buf->mutex);
178 if (buf->major == major && buf->minor == minor) 158 if (buf->major == major && buf->minor == minor)
179 tty_audit_buf_push_current(buf); 159 tty_audit_buf_push(buf);
180 mutex_unlock(&buf->mutex); 160 mutex_unlock(&buf->mutex);
181 tty_audit_buf_put(buf); 161 tty_audit_buf_put(buf);
182 } 162 }
@@ -187,24 +167,20 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
187 167
188 auid = audit_get_loginuid(current); 168 auid = audit_get_loginuid(current);
189 sessionid = audit_get_sessionid(current); 169 sessionid = audit_get_sessionid(current);
190 tty_audit_log("ioctl=TIOCSTI", current, auid, sessionid, major, 170 tty_audit_log("ioctl=TIOCSTI", major, minor, &ch, 1);
191 minor, &ch, 1);
192 } 171 }
193} 172}
194 173
195/** 174/**
196 * tty_audit_push_task - Flush task's pending audit data 175 * tty_audit_push_current - Flush current's pending audit data
197 * @tsk: task pointer
198 * @loginuid: sender login uid
199 * @sessionid: sender session id
200 * 176 *
201 * Called with a ref on @tsk held. Try to lock sighand and get a 177 * Try to lock sighand and get a reference to the tty audit buffer if available.
202 * reference to the tty audit buffer if available.
203 * Flush the buffer or return an appropriate error code. 178 * Flush the buffer or return an appropriate error code.
204 */ 179 */
205int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid) 180int tty_audit_push_current(void)
206{ 181{
207 struct tty_audit_buf *buf = ERR_PTR(-EPERM); 182 struct tty_audit_buf *buf = ERR_PTR(-EPERM);
183 struct task_struct *tsk = current;
208 unsigned long flags; 184 unsigned long flags;
209 185
210 if (!lock_task_sighand(tsk, &flags)) 186 if (!lock_task_sighand(tsk, &flags))
@@ -225,7 +201,7 @@ int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid)
225 return PTR_ERR(buf); 201 return PTR_ERR(buf);
226 202
227 mutex_lock(&buf->mutex); 203 mutex_lock(&buf->mutex);
228 tty_audit_buf_push(tsk, loginuid, sessionid, buf); 204 tty_audit_buf_push(buf);
229 mutex_unlock(&buf->mutex); 205 mutex_unlock(&buf->mutex);
230 206
231 tty_audit_buf_put(buf); 207 tty_audit_buf_put(buf);
@@ -243,10 +219,11 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
243 unsigned icanon) 219 unsigned icanon)
244{ 220{
245 struct tty_audit_buf *buf, *buf2; 221 struct tty_audit_buf *buf, *buf2;
222 unsigned long flags;
246 223
247 buf = NULL; 224 buf = NULL;
248 buf2 = NULL; 225 buf2 = NULL;
249 spin_lock_irq(&current->sighand->siglock); 226 spin_lock_irqsave(&current->sighand->siglock, flags);
250 if (likely(!current->signal->audit_tty)) 227 if (likely(!current->signal->audit_tty))
251 goto out; 228 goto out;
252 buf = current->signal->tty_audit_buf; 229 buf = current->signal->tty_audit_buf;
@@ -254,7 +231,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
254 atomic_inc(&buf->count); 231 atomic_inc(&buf->count);
255 goto out; 232 goto out;
256 } 233 }
257 spin_unlock_irq(&current->sighand->siglock); 234 spin_unlock_irqrestore(&current->sighand->siglock, flags);
258 235
259 buf2 = tty_audit_buf_alloc(tty->driver->major, 236 buf2 = tty_audit_buf_alloc(tty->driver->major,
260 tty->driver->minor_start + tty->index, 237 tty->driver->minor_start + tty->index,
@@ -264,7 +241,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
264 return NULL; 241 return NULL;
265 } 242 }
266 243
267 spin_lock_irq(&current->sighand->siglock); 244 spin_lock_irqsave(&current->sighand->siglock, flags);
268 if (!current->signal->audit_tty) 245 if (!current->signal->audit_tty)
269 goto out; 246 goto out;
270 buf = current->signal->tty_audit_buf; 247 buf = current->signal->tty_audit_buf;
@@ -276,7 +253,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
276 atomic_inc(&buf->count); 253 atomic_inc(&buf->count);
277 /* Fall through */ 254 /* Fall through */
278 out: 255 out:
279 spin_unlock_irq(&current->sighand->siglock); 256 spin_unlock_irqrestore(&current->sighand->siglock, flags);
280 if (buf2) 257 if (buf2)
281 tty_audit_buf_free(buf2); 258 tty_audit_buf_free(buf2);
282 return buf; 259 return buf;
@@ -292,10 +269,18 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
292{ 269{
293 struct tty_audit_buf *buf; 270 struct tty_audit_buf *buf;
294 int major, minor; 271 int major, minor;
272 int audit_log_tty_passwd;
273 unsigned long flags;
295 274
296 if (unlikely(size == 0)) 275 if (unlikely(size == 0))
297 return; 276 return;
298 277
278 spin_lock_irqsave(&current->sighand->siglock, flags);
279 audit_log_tty_passwd = current->signal->audit_tty_log_passwd;
280 spin_unlock_irqrestore(&current->sighand->siglock, flags);
281 if (!audit_log_tty_passwd && icanon && !L_ECHO(tty))
282 return;
283
299 if (tty->driver->type == TTY_DRIVER_TYPE_PTY 284 if (tty->driver->type == TTY_DRIVER_TYPE_PTY
300 && tty->driver->subtype == PTY_TYPE_MASTER) 285 && tty->driver->subtype == PTY_TYPE_MASTER)
301 return; 286 return;
@@ -309,7 +294,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
309 minor = tty->driver->minor_start + tty->index; 294 minor = tty->driver->minor_start + tty->index;
310 if (buf->major != major || buf->minor != minor 295 if (buf->major != major || buf->minor != minor
311 || buf->icanon != icanon) { 296 || buf->icanon != icanon) {
312 tty_audit_buf_push_current(buf); 297 tty_audit_buf_push(buf);
313 buf->major = major; 298 buf->major = major;
314 buf->minor = minor; 299 buf->minor = minor;
315 buf->icanon = icanon; 300 buf->icanon = icanon;
@@ -325,7 +310,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
325 data += run; 310 data += run;
326 size -= run; 311 size -= run;
327 if (buf->valid == N_TTY_BUF_SIZE) 312 if (buf->valid == N_TTY_BUF_SIZE)
328 tty_audit_buf_push_current(buf); 313 tty_audit_buf_push(buf);
329 } while (size != 0); 314 } while (size != 0);
330 mutex_unlock(&buf->mutex); 315 mutex_unlock(&buf->mutex);
331 tty_audit_buf_put(buf); 316 tty_audit_buf_put(buf);
@@ -339,16 +324,17 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
339void tty_audit_push(struct tty_struct *tty) 324void tty_audit_push(struct tty_struct *tty)
340{ 325{
341 struct tty_audit_buf *buf; 326 struct tty_audit_buf *buf;
327 unsigned long flags;
342 328
343 spin_lock_irq(&current->sighand->siglock); 329 spin_lock_irqsave(&current->sighand->siglock, flags);
344 if (likely(!current->signal->audit_tty)) { 330 if (likely(!current->signal->audit_tty)) {
345 spin_unlock_irq(&current->sighand->siglock); 331 spin_unlock_irqrestore(&current->sighand->siglock, flags);
346 return; 332 return;
347 } 333 }
348 buf = current->signal->tty_audit_buf; 334 buf = current->signal->tty_audit_buf;
349 if (buf) 335 if (buf)
350 atomic_inc(&buf->count); 336 atomic_inc(&buf->count);
351 spin_unlock_irq(&current->sighand->siglock); 337 spin_unlock_irqrestore(&current->sighand->siglock, flags);
352 338
353 if (buf) { 339 if (buf) {
354 int major, minor; 340 int major, minor;
@@ -357,7 +343,7 @@ void tty_audit_push(struct tty_struct *tty)
357 minor = tty->driver->minor_start + tty->index; 343 minor = tty->driver->minor_start + tty->index;
358 mutex_lock(&buf->mutex); 344 mutex_lock(&buf->mutex);
359 if (buf->major == major && buf->minor == minor) 345 if (buf->major == major && buf->minor == minor)
360 tty_audit_buf_push_current(buf); 346 tty_audit_buf_push(buf);
361 mutex_unlock(&buf->mutex); 347 mutex_unlock(&buf->mutex);
362 tty_audit_buf_put(buf); 348 tty_audit_buf_put(buf);
363 } 349 }
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 578aa7594b11..9121c1f7aeef 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -449,11 +449,6 @@ static void flush_to_ldisc(struct work_struct *work)
449 tty_buffer_free(port, head); 449 tty_buffer_free(port, head);
450 continue; 450 continue;
451 } 451 }
452 /* Ldisc or user is trying to flush the buffers
453 we are feeding to the ldisc, stop feeding the
454 line discipline as we want to empty the queue */
455 if (test_bit(TTYP_FLUSHPENDING, &port->iflags))
456 break;
457 if (!tty->receive_room) 452 if (!tty->receive_room)
458 break; 453 break;
459 if (count > tty->receive_room) 454 if (count > tty->receive_room)
@@ -465,17 +460,20 @@ static void flush_to_ldisc(struct work_struct *work)
465 disc->ops->receive_buf(tty, char_buf, 460 disc->ops->receive_buf(tty, char_buf,
466 flag_buf, count); 461 flag_buf, count);
467 spin_lock_irqsave(&buf->lock, flags); 462 spin_lock_irqsave(&buf->lock, flags);
463 /* Ldisc or user is trying to flush the buffers.
464 We may have a deferred request to flush the
465 input buffer, if so pull the chain under the lock
466 and empty the queue */
467 if (test_bit(TTYP_FLUSHPENDING, &port->iflags)) {
468 __tty_buffer_flush(port);
469 clear_bit(TTYP_FLUSHPENDING, &port->iflags);
470 wake_up(&tty->read_wait);
471 break;
472 }
468 } 473 }
469 clear_bit(TTYP_FLUSHING, &port->iflags); 474 clear_bit(TTYP_FLUSHING, &port->iflags);
470 } 475 }
471 476
472 /* We may have a deferred request to flush the input buffer,
473 if so pull the chain under the lock and empty the queue */
474 if (test_bit(TTYP_FLUSHPENDING, &port->iflags)) {
475 __tty_buffer_flush(port);
476 clear_bit(TTYP_FLUSHPENDING, &port->iflags);
477 wake_up(&tty->read_wait);
478 }
479 spin_unlock_irqrestore(&buf->lock, flags); 477 spin_unlock_irqrestore(&buf->lock, flags);
480 478
481 tty_ldisc_deref(disc); 479 tty_ldisc_deref(disc);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 05400acbc456..6464029e4860 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -533,6 +533,60 @@ void tty_wakeup(struct tty_struct *tty)
533EXPORT_SYMBOL_GPL(tty_wakeup); 533EXPORT_SYMBOL_GPL(tty_wakeup);
534 534
535/** 535/**
536 * tty_signal_session_leader - sends SIGHUP to session leader
537 * @tty controlling tty
538 * @exit_session if non-zero, signal all foreground group processes
539 *
540 * Send SIGHUP and SIGCONT to the session leader and its process group.
541 * Optionally, signal all processes in the foreground process group.
542 *
543 * Returns the number of processes in the session with this tty
544 * as their controlling terminal. This value is used to drop
545 * tty references for those processes.
546 */
547static int tty_signal_session_leader(struct tty_struct *tty, int exit_session)
548{
549 struct task_struct *p;
550 int refs = 0;
551 struct pid *tty_pgrp = NULL;
552
553 read_lock(&tasklist_lock);
554 if (tty->session) {
555 do_each_pid_task(tty->session, PIDTYPE_SID, p) {
556 spin_lock_irq(&p->sighand->siglock);
557 if (p->signal->tty == tty) {
558 p->signal->tty = NULL;
559 /* We defer the dereferences outside fo
560 the tasklist lock */
561 refs++;
562 }
563 if (!p->signal->leader) {
564 spin_unlock_irq(&p->sighand->siglock);
565 continue;
566 }
567 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
568 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
569 put_pid(p->signal->tty_old_pgrp); /* A noop */
570 spin_lock(&tty->ctrl_lock);
571 tty_pgrp = get_pid(tty->pgrp);
572 if (tty->pgrp)
573 p->signal->tty_old_pgrp = get_pid(tty->pgrp);
574 spin_unlock(&tty->ctrl_lock);
575 spin_unlock_irq(&p->sighand->siglock);
576 } while_each_pid_task(tty->session, PIDTYPE_SID, p);
577 }
578 read_unlock(&tasklist_lock);
579
580 if (tty_pgrp) {
581 if (exit_session)
582 kill_pgrp(tty_pgrp, SIGHUP, exit_session);
583 put_pid(tty_pgrp);
584 }
585
586 return refs;
587}
588
589/**
536 * __tty_hangup - actual handler for hangup events 590 * __tty_hangup - actual handler for hangup events
537 * @work: tty device 591 * @work: tty device
538 * 592 *
@@ -554,15 +608,13 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
554 * tasklist_lock to walk task list for hangup event 608 * tasklist_lock to walk task list for hangup event
555 * ->siglock to protect ->signal/->sighand 609 * ->siglock to protect ->signal/->sighand
556 */ 610 */
557static void __tty_hangup(struct tty_struct *tty) 611static void __tty_hangup(struct tty_struct *tty, int exit_session)
558{ 612{
559 struct file *cons_filp = NULL; 613 struct file *cons_filp = NULL;
560 struct file *filp, *f = NULL; 614 struct file *filp, *f = NULL;
561 struct task_struct *p;
562 struct tty_file_private *priv; 615 struct tty_file_private *priv;
563 int closecount = 0, n; 616 int closecount = 0, n;
564 unsigned long flags; 617 int refs;
565 int refs = 0;
566 618
567 if (!tty) 619 if (!tty)
568 return; 620 return;
@@ -599,39 +651,18 @@ static void __tty_hangup(struct tty_struct *tty)
599 } 651 }
600 spin_unlock(&tty_files_lock); 652 spin_unlock(&tty_files_lock);
601 653
654 refs = tty_signal_session_leader(tty, exit_session);
655 /* Account for the p->signal references we killed */
656 while (refs--)
657 tty_kref_put(tty);
658
602 /* 659 /*
603 * it drops BTM and thus races with reopen 660 * it drops BTM and thus races with reopen
604 * we protect the race by TTY_HUPPING 661 * we protect the race by TTY_HUPPING
605 */ 662 */
606 tty_ldisc_hangup(tty); 663 tty_ldisc_hangup(tty);
607 664
608 read_lock(&tasklist_lock); 665 spin_lock_irq(&tty->ctrl_lock);
609 if (tty->session) {
610 do_each_pid_task(tty->session, PIDTYPE_SID, p) {
611 spin_lock_irq(&p->sighand->siglock);
612 if (p->signal->tty == tty) {
613 p->signal->tty = NULL;
614 /* We defer the dereferences outside fo
615 the tasklist lock */
616 refs++;
617 }
618 if (!p->signal->leader) {
619 spin_unlock_irq(&p->sighand->siglock);
620 continue;
621 }
622 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
623 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
624 put_pid(p->signal->tty_old_pgrp); /* A noop */
625 spin_lock_irqsave(&tty->ctrl_lock, flags);
626 if (tty->pgrp)
627 p->signal->tty_old_pgrp = get_pid(tty->pgrp);
628 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
629 spin_unlock_irq(&p->sighand->siglock);
630 } while_each_pid_task(tty->session, PIDTYPE_SID, p);
631 }
632 read_unlock(&tasklist_lock);
633
634 spin_lock_irqsave(&tty->ctrl_lock, flags);
635 clear_bit(TTY_THROTTLED, &tty->flags); 666 clear_bit(TTY_THROTTLED, &tty->flags);
636 clear_bit(TTY_PUSH, &tty->flags); 667 clear_bit(TTY_PUSH, &tty->flags);
637 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 668 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
@@ -640,11 +671,7 @@ static void __tty_hangup(struct tty_struct *tty)
640 tty->session = NULL; 671 tty->session = NULL;
641 tty->pgrp = NULL; 672 tty->pgrp = NULL;
642 tty->ctrl_status = 0; 673 tty->ctrl_status = 0;
643 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 674 spin_unlock_irq(&tty->ctrl_lock);
644
645 /* Account for the p->signal references we killed */
646 while (refs--)
647 tty_kref_put(tty);
648 675
649 /* 676 /*
650 * If one of the devices matches a console pointer, we 677 * If one of the devices matches a console pointer, we
@@ -666,7 +693,6 @@ static void __tty_hangup(struct tty_struct *tty)
666 */ 693 */
667 set_bit(TTY_HUPPED, &tty->flags); 694 set_bit(TTY_HUPPED, &tty->flags);
668 clear_bit(TTY_HUPPING, &tty->flags); 695 clear_bit(TTY_HUPPING, &tty->flags);
669 tty_ldisc_enable(tty);
670 696
671 tty_unlock(tty); 697 tty_unlock(tty);
672 698
@@ -679,7 +705,7 @@ static void do_tty_hangup(struct work_struct *work)
679 struct tty_struct *tty = 705 struct tty_struct *tty =
680 container_of(work, struct tty_struct, hangup_work); 706 container_of(work, struct tty_struct, hangup_work);
681 707
682 __tty_hangup(tty); 708 __tty_hangup(tty, 0);
683} 709}
684 710
685/** 711/**
@@ -717,7 +743,7 @@ void tty_vhangup(struct tty_struct *tty)
717 743
718 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf)); 744 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf));
719#endif 745#endif
720 __tty_hangup(tty); 746 __tty_hangup(tty, 0);
721} 747}
722 748
723EXPORT_SYMBOL(tty_vhangup); 749EXPORT_SYMBOL(tty_vhangup);
@@ -741,6 +767,27 @@ void tty_vhangup_self(void)
741} 767}
742 768
743/** 769/**
770 * tty_vhangup_session - hangup session leader exit
771 * @tty: tty to hangup
772 *
773 * The session leader is exiting and hanging up its controlling terminal.
774 * Every process in the foreground process group is signalled SIGHUP.
775 *
776 * We do this synchronously so that when the syscall returns the process
777 * is complete. That guarantee is necessary for security reasons.
778 */
779
780static void tty_vhangup_session(struct tty_struct *tty)
781{
782#ifdef TTY_DEBUG_HANGUP
783 char buf[64];
784
785 printk(KERN_DEBUG "%s vhangup session...\n", tty_name(tty, buf));
786#endif
787 __tty_hangup(tty, 1);
788}
789
790/**
744 * tty_hung_up_p - was tty hung up 791 * tty_hung_up_p - was tty hung up
745 * @filp: file pointer of tty 792 * @filp: file pointer of tty
746 * 793 *
@@ -797,18 +844,18 @@ void disassociate_ctty(int on_exit)
797 844
798 tty = get_current_tty(); 845 tty = get_current_tty();
799 if (tty) { 846 if (tty) {
800 struct pid *tty_pgrp = get_pid(tty->pgrp); 847 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) {
801 if (on_exit) { 848 tty_vhangup_session(tty);
802 if (tty->driver->type != TTY_DRIVER_TYPE_PTY) 849 } else {
803 tty_vhangup(tty); 850 struct pid *tty_pgrp = tty_get_pgrp(tty);
804 } 851 if (tty_pgrp) {
805 tty_kref_put(tty); 852 kill_pgrp(tty_pgrp, SIGHUP, on_exit);
806 if (tty_pgrp) {
807 kill_pgrp(tty_pgrp, SIGHUP, on_exit);
808 if (!on_exit)
809 kill_pgrp(tty_pgrp, SIGCONT, on_exit); 853 kill_pgrp(tty_pgrp, SIGCONT, on_exit);
810 put_pid(tty_pgrp); 854 put_pid(tty_pgrp);
855 }
811 } 856 }
857 tty_kref_put(tty);
858
812 } else if (on_exit) { 859 } else if (on_exit) {
813 struct pid *old_pgrp; 860 struct pid *old_pgrp;
814 spin_lock_irq(&current->sighand->siglock); 861 spin_lock_irq(&current->sighand->siglock);
@@ -941,6 +988,14 @@ void start_tty(struct tty_struct *tty)
941 988
942EXPORT_SYMBOL(start_tty); 989EXPORT_SYMBOL(start_tty);
943 990
991/* We limit tty time update visibility to every 8 seconds or so. */
992static void tty_update_time(struct timespec *time)
993{
994 unsigned long sec = get_seconds() & ~7;
995 if ((long)(sec - time->tv_sec) > 0)
996 time->tv_sec = sec;
997}
998
944/** 999/**
945 * tty_read - read method for tty device files 1000 * tty_read - read method for tty device files
946 * @file: pointer to tty file 1001 * @file: pointer to tty file
@@ -960,10 +1015,11 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
960 loff_t *ppos) 1015 loff_t *ppos)
961{ 1016{
962 int i; 1017 int i;
1018 struct inode *inode = file_inode(file);
963 struct tty_struct *tty = file_tty(file); 1019 struct tty_struct *tty = file_tty(file);
964 struct tty_ldisc *ld; 1020 struct tty_ldisc *ld;
965 1021
966 if (tty_paranoia_check(tty, file_inode(file), "tty_read")) 1022 if (tty_paranoia_check(tty, inode, "tty_read"))
967 return -EIO; 1023 return -EIO;
968 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) 1024 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags)))
969 return -EIO; 1025 return -EIO;
@@ -977,6 +1033,9 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
977 i = -EIO; 1033 i = -EIO;
978 tty_ldisc_deref(ld); 1034 tty_ldisc_deref(ld);
979 1035
1036 if (i > 0)
1037 tty_update_time(&inode->i_atime);
1038
980 return i; 1039 return i;
981} 1040}
982 1041
@@ -1077,8 +1136,10 @@ static inline ssize_t do_tty_write(
1077 break; 1136 break;
1078 cond_resched(); 1137 cond_resched();
1079 } 1138 }
1080 if (written) 1139 if (written) {
1140 tty_update_time(&file_inode(file)->i_mtime);
1081 ret = written; 1141 ret = written;
1142 }
1082out: 1143out:
1083 tty_write_unlock(tty); 1144 tty_write_unlock(tty);
1084 return ret; 1145 return ret;
@@ -1344,9 +1405,7 @@ static int tty_reopen(struct tty_struct *tty)
1344 } 1405 }
1345 tty->count++; 1406 tty->count++;
1346 1407
1347 mutex_lock(&tty->ldisc_mutex);
1348 WARN_ON(!test_bit(TTY_LDISC, &tty->flags)); 1408 WARN_ON(!test_bit(TTY_LDISC, &tty->flags));
1349 mutex_unlock(&tty->ldisc_mutex);
1350 1409
1351 return 0; 1410 return 0;
1352} 1411}
@@ -1463,6 +1522,17 @@ void tty_free_termios(struct tty_struct *tty)
1463} 1522}
1464EXPORT_SYMBOL(tty_free_termios); 1523EXPORT_SYMBOL(tty_free_termios);
1465 1524
1525/**
1526 * tty_flush_works - flush all works of a tty
1527 * @tty: tty device to flush works for
1528 *
1529 * Sync flush all works belonging to @tty.
1530 */
1531static void tty_flush_works(struct tty_struct *tty)
1532{
1533 flush_work(&tty->SAK_work);
1534 flush_work(&tty->hangup_work);
1535}
1466 1536
1467/** 1537/**
1468 * release_one_tty - release tty structure memory 1538 * release_one_tty - release tty structure memory
@@ -1548,6 +1618,7 @@ static void release_tty(struct tty_struct *tty, int idx)
1548 tty_free_termios(tty); 1618 tty_free_termios(tty);
1549 tty_driver_remove_tty(tty->driver, tty); 1619 tty_driver_remove_tty(tty->driver, tty);
1550 tty->port->itty = NULL; 1620 tty->port->itty = NULL;
1621 cancel_work_sync(&tty->port->buf.work);
1551 1622
1552 if (tty->link) 1623 if (tty->link)
1553 tty_kref_put(tty->link); 1624 tty_kref_put(tty->link);
@@ -1777,12 +1848,21 @@ int tty_release(struct inode *inode, struct file *filp)
1777 return 0; 1848 return 0;
1778 1849
1779#ifdef TTY_DEBUG_HANGUP 1850#ifdef TTY_DEBUG_HANGUP
1780 printk(KERN_DEBUG "%s: freeing tty structure...\n", __func__); 1851 printk(KERN_DEBUG "%s: %s: final close\n", __func__, tty_name(tty, buf));
1781#endif 1852#endif
1782 /* 1853 /*
1783 * Ask the line discipline code to release its structures 1854 * Ask the line discipline code to release its structures
1784 */ 1855 */
1785 tty_ldisc_release(tty, o_tty); 1856 tty_ldisc_release(tty, o_tty);
1857
1858 /* Wait for pending work before tty destruction commmences */
1859 tty_flush_works(tty);
1860 if (o_tty)
1861 tty_flush_works(o_tty);
1862
1863#ifdef TTY_DEBUG_HANGUP
1864 printk(KERN_DEBUG "%s: %s: freeing structure...\n", __func__, tty_name(tty, buf));
1865#endif
1786 /* 1866 /*
1787 * The release_tty function takes care of the details of clearing 1867 * The release_tty function takes care of the details of clearing
1788 * the slots and preserving the termios structure. The tty_unlock_pair 1868 * the slots and preserving the termios structure. The tty_unlock_pair
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index d58b92cc187c..3500d4114147 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -106,6 +106,7 @@ void tty_throttle(struct tty_struct *tty)
106 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && 106 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
107 tty->ops->throttle) 107 tty->ops->throttle)
108 tty->ops->throttle(tty); 108 tty->ops->throttle(tty);
109 tty->flow_change = 0;
109 mutex_unlock(&tty->termios_mutex); 110 mutex_unlock(&tty->termios_mutex);
110} 111}
111EXPORT_SYMBOL(tty_throttle); 112EXPORT_SYMBOL(tty_throttle);
@@ -129,11 +130,74 @@ void tty_unthrottle(struct tty_struct *tty)
129 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 130 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
130 tty->ops->unthrottle) 131 tty->ops->unthrottle)
131 tty->ops->unthrottle(tty); 132 tty->ops->unthrottle(tty);
133 tty->flow_change = 0;
132 mutex_unlock(&tty->termios_mutex); 134 mutex_unlock(&tty->termios_mutex);
133} 135}
134EXPORT_SYMBOL(tty_unthrottle); 136EXPORT_SYMBOL(tty_unthrottle);
135 137
136/** 138/**
139 * tty_throttle_safe - flow control
140 * @tty: terminal
141 *
142 * Similar to tty_throttle() but will only attempt throttle
143 * if tty->flow_change is TTY_THROTTLE_SAFE. Prevents an accidental
144 * throttle due to race conditions when throttling is conditional
145 * on factors evaluated prior to throttling.
146 *
147 * Returns 0 if tty is throttled (or was already throttled)
148 */
149
150int tty_throttle_safe(struct tty_struct *tty)
151{
152 int ret = 0;
153
154 mutex_lock(&tty->termios_mutex);
155 if (!test_bit(TTY_THROTTLED, &tty->flags)) {
156 if (tty->flow_change != TTY_THROTTLE_SAFE)
157 ret = 1;
158 else {
159 set_bit(TTY_THROTTLED, &tty->flags);
160 if (tty->ops->throttle)
161 tty->ops->throttle(tty);
162 }
163 }
164 mutex_unlock(&tty->termios_mutex);
165
166 return ret;
167}
168
169/**
170 * tty_unthrottle_safe - flow control
171 * @tty: terminal
172 *
173 * Similar to tty_unthrottle() but will only attempt unthrottle
174 * if tty->flow_change is TTY_UNTHROTTLE_SAFE. Prevents an accidental
175 * unthrottle due to race conditions when unthrottling is conditional
176 * on factors evaluated prior to unthrottling.
177 *
178 * Returns 0 if tty is unthrottled (or was already unthrottled)
179 */
180
181int tty_unthrottle_safe(struct tty_struct *tty)
182{
183 int ret = 0;
184
185 mutex_lock(&tty->termios_mutex);
186 if (test_bit(TTY_THROTTLED, &tty->flags)) {
187 if (tty->flow_change != TTY_UNTHROTTLE_SAFE)
188 ret = 1;
189 else {
190 clear_bit(TTY_THROTTLED, &tty->flags);
191 if (tty->ops->unthrottle)
192 tty->ops->unthrottle(tty);
193 }
194 }
195 mutex_unlock(&tty->termios_mutex);
196
197 return ret;
198}
199
200/**
137 * tty_wait_until_sent - wait for I/O to finish 201 * tty_wait_until_sent - wait for I/O to finish
138 * @tty: tty we are waiting for 202 * @tty: tty we are waiting for
139 * @timeout: how long we will wait 203 * @timeout: how long we will wait
@@ -415,34 +479,6 @@ void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud)
415EXPORT_SYMBOL_GPL(tty_encode_baud_rate); 479EXPORT_SYMBOL_GPL(tty_encode_baud_rate);
416 480
417/** 481/**
418 * tty_get_baud_rate - get tty bit rates
419 * @tty: tty to query
420 *
421 * Returns the baud rate as an integer for this terminal. The
422 * termios lock must be held by the caller and the terminal bit
423 * flags may be updated.
424 *
425 * Locking: none
426 */
427
428speed_t tty_get_baud_rate(struct tty_struct *tty)
429{
430 speed_t baud = tty_termios_baud_rate(&tty->termios);
431
432 if (baud == 38400 && tty->alt_speed) {
433 if (!tty->warned) {
434 printk(KERN_WARNING "Use of setserial/setrocket to "
435 "set SPD_* flags is deprecated\n");
436 tty->warned = 1;
437 }
438 baud = tty->alt_speed;
439 }
440
441 return baud;
442}
443EXPORT_SYMBOL(tty_get_baud_rate);
444
445/**
446 * tty_termios_copy_hw - copy hardware settings 482 * tty_termios_copy_hw - copy hardware settings
447 * @new: New termios 483 * @new: New termios
448 * @old: Old termios 484 * @old: Old termios
@@ -1086,14 +1122,12 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
1086} 1122}
1087EXPORT_SYMBOL_GPL(tty_mode_ioctl); 1123EXPORT_SYMBOL_GPL(tty_mode_ioctl);
1088 1124
1089int tty_perform_flush(struct tty_struct *tty, unsigned long arg) 1125
1126/* Caller guarantees ldisc reference is held */
1127static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg)
1090{ 1128{
1091 struct tty_ldisc *ld; 1129 struct tty_ldisc *ld = tty->ldisc;
1092 int retval = tty_check_change(tty);
1093 if (retval)
1094 return retval;
1095 1130
1096 ld = tty_ldisc_ref_wait(tty);
1097 switch (arg) { 1131 switch (arg) {
1098 case TCIFLUSH: 1132 case TCIFLUSH:
1099 if (ld && ld->ops->flush_buffer) { 1133 if (ld && ld->ops->flush_buffer) {
@@ -1111,12 +1145,24 @@ int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
1111 tty_driver_flush_buffer(tty); 1145 tty_driver_flush_buffer(tty);
1112 break; 1146 break;
1113 default: 1147 default:
1114 tty_ldisc_deref(ld);
1115 return -EINVAL; 1148 return -EINVAL;
1116 } 1149 }
1117 tty_ldisc_deref(ld);
1118 return 0; 1150 return 0;
1119} 1151}
1152
1153int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
1154{
1155 struct tty_ldisc *ld;
1156 int retval = tty_check_change(tty);
1157 if (retval)
1158 return retval;
1159
1160 ld = tty_ldisc_ref_wait(tty);
1161 retval = __tty_perform_flush(tty, arg);
1162 if (ld)
1163 tty_ldisc_deref(ld);
1164 return retval;
1165}
1120EXPORT_SYMBOL_GPL(tty_perform_flush); 1166EXPORT_SYMBOL_GPL(tty_perform_flush);
1121 1167
1122int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, 1168int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
@@ -1155,7 +1201,7 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
1155 } 1201 }
1156 return 0; 1202 return 0;
1157 case TCFLSH: 1203 case TCFLSH:
1158 return tty_perform_flush(tty, arg); 1204 return __tty_perform_flush(tty, arg);
1159 default: 1205 default:
1160 /* Try the mode commands */ 1206 /* Try the mode commands */
1161 return tty_mode_ioctl(tty, file, cmd, arg); 1207 return tty_mode_ioctl(tty, file, cmd, arg);
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index d794087c327e..1afe192bef6a 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -20,6 +20,17 @@
20#include <linux/uaccess.h> 20#include <linux/uaccess.h>
21#include <linux/ratelimit.h> 21#include <linux/ratelimit.h>
22 22
23#undef LDISC_DEBUG_HANGUP
24
25#ifdef LDISC_DEBUG_HANGUP
26#define tty_ldisc_debug(tty, f, args...) ({ \
27 char __b[64]; \
28 printk(KERN_DEBUG "%s: %s: " f, __func__, tty_name(tty, __b), ##args); \
29})
30#else
31#define tty_ldisc_debug(tty, f, args...)
32#endif
33
23/* 34/*
24 * This guards the refcounted line discipline lists. The lock 35 * This guards the refcounted line discipline lists. The lock
25 * must be taken with irqs off because there are hangup path 36 * must be taken with irqs off because there are hangup path
@@ -31,44 +42,6 @@ static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
31/* Line disc dispatch table */ 42/* Line disc dispatch table */
32static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; 43static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
33 44
34static inline struct tty_ldisc *get_ldisc(struct tty_ldisc *ld)
35{
36 if (ld)
37 atomic_inc(&ld->users);
38 return ld;
39}
40
41static void put_ldisc(struct tty_ldisc *ld)
42{
43 unsigned long flags;
44
45 if (WARN_ON_ONCE(!ld))
46 return;
47
48 /*
49 * If this is the last user, free the ldisc, and
50 * release the ldisc ops.
51 *
52 * We really want an "atomic_dec_and_raw_lock_irqsave()",
53 * but we don't have it, so this does it by hand.
54 */
55 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
56 if (atomic_dec_and_test(&ld->users)) {
57 struct tty_ldisc_ops *ldo = ld->ops;
58
59 ldo->refcount--;
60 module_put(ldo->owner);
61 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
62
63 kfree(ld);
64 return;
65 }
66 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
67
68 if (waitqueue_active(&ld->wq_idle))
69 wake_up(&ld->wq_idle);
70}
71
72/** 45/**
73 * tty_register_ldisc - install a line discipline 46 * tty_register_ldisc - install a line discipline
74 * @disc: ldisc number 47 * @disc: ldisc number
@@ -206,6 +179,29 @@ static struct tty_ldisc *tty_ldisc_get(int disc)
206 return ld; 179 return ld;
207} 180}
208 181
182/**
183 * tty_ldisc_put - release the ldisc
184 *
185 * Complement of tty_ldisc_get().
186 */
187static inline void tty_ldisc_put(struct tty_ldisc *ld)
188{
189 unsigned long flags;
190
191 if (WARN_ON_ONCE(!ld))
192 return;
193
194 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
195
196 /* unreleased reader reference(s) will cause this WARN */
197 WARN_ON(!atomic_dec_and_test(&ld->users));
198
199 ld->ops->refcount--;
200 module_put(ld->ops->owner);
201 kfree(ld);
202 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
203}
204
209static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) 205static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
210{ 206{
211 return (*pos < NR_LDISCS) ? pos : NULL; 207 return (*pos < NR_LDISCS) ? pos : NULL;
@@ -255,24 +251,6 @@ const struct file_operations tty_ldiscs_proc_fops = {
255}; 251};
256 252
257/** 253/**
258 * tty_ldisc_assign - set ldisc on a tty
259 * @tty: tty to assign
260 * @ld: line discipline
261 *
262 * Install an instance of a line discipline into a tty structure. The
263 * ldisc must have a reference count above zero to ensure it remains.
264 * The tty instance refcount starts at zero.
265 *
266 * Locking:
267 * Caller must hold references
268 */
269
270static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
271{
272 tty->ldisc = ld;
273}
274
275/**
276 * tty_ldisc_try - internal helper 254 * tty_ldisc_try - internal helper
277 * @tty: the tty 255 * @tty: the tty
278 * 256 *
@@ -289,10 +267,13 @@ static struct tty_ldisc *tty_ldisc_try(struct tty_struct *tty)
289 unsigned long flags; 267 unsigned long flags;
290 struct tty_ldisc *ld; 268 struct tty_ldisc *ld;
291 269
270 /* FIXME: this allows reference acquire after TTY_LDISC is cleared */
292 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 271 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
293 ld = NULL; 272 ld = NULL;
294 if (test_bit(TTY_LDISC, &tty->flags)) 273 if (test_bit(TTY_LDISC, &tty->flags) && tty->ldisc) {
295 ld = get_ldisc(tty->ldisc); 274 ld = tty->ldisc;
275 atomic_inc(&ld->users);
276 }
296 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 277 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
297 return ld; 278 return ld;
298} 279}
@@ -352,14 +333,23 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref);
352 333
353void tty_ldisc_deref(struct tty_ldisc *ld) 334void tty_ldisc_deref(struct tty_ldisc *ld)
354{ 335{
355 put_ldisc(ld); 336 unsigned long flags;
356}
357EXPORT_SYMBOL_GPL(tty_ldisc_deref);
358 337
359static inline void tty_ldisc_put(struct tty_ldisc *ld) 338 if (WARN_ON_ONCE(!ld))
360{ 339 return;
361 put_ldisc(ld); 340
341 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
342 /*
343 * WARNs if one-too-many reader references were released
344 * - the last reference must be released with tty_ldisc_put
345 */
346 WARN_ON(atomic_dec_and_test(&ld->users));
347 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
348
349 if (waitqueue_active(&ld->wq_idle))
350 wake_up(&ld->wq_idle);
362} 351}
352EXPORT_SYMBOL_GPL(tty_ldisc_deref);
363 353
364/** 354/**
365 * tty_ldisc_enable - allow ldisc use 355 * tty_ldisc_enable - allow ldisc use
@@ -373,8 +363,9 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
373 * Clearing directly is allowed. 363 * Clearing directly is allowed.
374 */ 364 */
375 365
376void tty_ldisc_enable(struct tty_struct *tty) 366static void tty_ldisc_enable(struct tty_struct *tty)
377{ 367{
368 clear_bit(TTY_LDISC_HALTED, &tty->flags);
378 set_bit(TTY_LDISC, &tty->flags); 369 set_bit(TTY_LDISC, &tty->flags);
379 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 370 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
380 wake_up(&tty_ldisc_wait); 371 wake_up(&tty_ldisc_wait);
@@ -479,7 +470,7 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
479 /* There is an outstanding reference here so this is safe */ 470 /* There is an outstanding reference here so this is safe */
480 old = tty_ldisc_get(old->ops->num); 471 old = tty_ldisc_get(old->ops->num);
481 WARN_ON(IS_ERR(old)); 472 WARN_ON(IS_ERR(old));
482 tty_ldisc_assign(tty, old); 473 tty->ldisc = old;
483 tty_set_termios_ldisc(tty, old->ops->num); 474 tty_set_termios_ldisc(tty, old->ops->num);
484 if (tty_ldisc_open(tty, old) < 0) { 475 if (tty_ldisc_open(tty, old) < 0) {
485 tty_ldisc_put(old); 476 tty_ldisc_put(old);
@@ -487,7 +478,7 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
487 new_ldisc = tty_ldisc_get(N_TTY); 478 new_ldisc = tty_ldisc_get(N_TTY);
488 if (IS_ERR(new_ldisc)) 479 if (IS_ERR(new_ldisc))
489 panic("n_tty: get"); 480 panic("n_tty: get");
490 tty_ldisc_assign(tty, new_ldisc); 481 tty->ldisc = new_ldisc;
491 tty_set_termios_ldisc(tty, N_TTY); 482 tty_set_termios_ldisc(tty, N_TTY);
492 r = tty_ldisc_open(tty, new_ldisc); 483 r = tty_ldisc_open(tty, new_ldisc);
493 if (r < 0) 484 if (r < 0)
@@ -498,52 +489,98 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
498} 489}
499 490
500/** 491/**
492 * tty_ldisc_wait_idle - wait for the ldisc to become idle
493 * @tty: tty to wait for
494 * @timeout: for how long to wait at most
495 *
496 * Wait for the line discipline to become idle. The discipline must
497 * have been halted for this to guarantee it remains idle.
498 */
499static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout)
500{
501 long ret;
502 ret = wait_event_timeout(tty->ldisc->wq_idle,
503 atomic_read(&tty->ldisc->users) == 1, timeout);
504 return ret > 0 ? 0 : -EBUSY;
505}
506
507/**
501 * tty_ldisc_halt - shut down the line discipline 508 * tty_ldisc_halt - shut down the line discipline
502 * @tty: tty device 509 * @tty: tty device
510 * @o_tty: paired pty device (can be NULL)
511 * @timeout: # of jiffies to wait for ldisc refs to be released
503 * 512 *
504 * Shut down the line discipline and work queue for this tty device. 513 * Shut down the line discipline and work queue for this tty device and
505 * The TTY_LDISC flag being cleared ensures no further references can 514 * its paired pty (if exists). Clearing the TTY_LDISC flag ensures
506 * be obtained while the delayed work queue halt ensures that no more 515 * no further references can be obtained, while waiting for existing
507 * data is fed to the ldisc. 516 * references to be released ensures no more data is fed to the ldisc.
508 * 517 *
509 * You need to do a 'flush_scheduled_work()' (outside the ldisc_mutex) 518 * You need to do a 'flush_scheduled_work()' (outside the ldisc_mutex)
510 * in order to make sure any currently executing ldisc work is also 519 * in order to make sure any currently executing ldisc work is also
511 * flushed. 520 * flushed.
512 */ 521 */
513 522
514static int tty_ldisc_halt(struct tty_struct *tty) 523static int tty_ldisc_halt(struct tty_struct *tty, struct tty_struct *o_tty,
524 long timeout)
515{ 525{
526 int retval;
527
516 clear_bit(TTY_LDISC, &tty->flags); 528 clear_bit(TTY_LDISC, &tty->flags);
517 return cancel_work_sync(&tty->port->buf.work); 529 if (o_tty)
518} 530 clear_bit(TTY_LDISC, &o_tty->flags);
519 531
520/** 532 retval = tty_ldisc_wait_idle(tty, timeout);
521 * tty_ldisc_flush_works - flush all works of a tty 533 if (!retval && o_tty)
522 * @tty: tty device to flush works for 534 retval = tty_ldisc_wait_idle(o_tty, timeout);
523 * 535 if (retval)
524 * Sync flush all works belonging to @tty. 536 return retval;
525 */ 537
526static void tty_ldisc_flush_works(struct tty_struct *tty) 538 set_bit(TTY_LDISC_HALTED, &tty->flags);
527{ 539 if (o_tty)
528 flush_work(&tty->hangup_work); 540 set_bit(TTY_LDISC_HALTED, &o_tty->flags);
529 flush_work(&tty->SAK_work); 541
530 flush_work(&tty->port->buf.work); 542 return 0;
531} 543}
532 544
533/** 545/**
534 * tty_ldisc_wait_idle - wait for the ldisc to become idle 546 * tty_ldisc_hangup_halt - halt the line discipline for hangup
535 * @tty: tty to wait for 547 * @tty: tty being hung up
536 * @timeout: for how long to wait at most
537 * 548 *
538 * Wait for the line discipline to become idle. The discipline must 549 * Shut down the line discipline and work queue for the tty device
539 * have been halted for this to guarantee it remains idle. 550 * being hungup. Clear the TTY_LDISC flag to ensure no further
551 * references can be obtained and wait for remaining references to be
552 * released to ensure no more data is fed to this ldisc.
553 * Caller must hold legacy and ->ldisc_mutex.
554 *
555 * NB: tty_set_ldisc() is prevented from changing the ldisc concurrently
556 * with this function by checking the TTY_HUPPING flag.
540 */ 557 */
541static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout) 558static bool tty_ldisc_hangup_halt(struct tty_struct *tty)
542{ 559{
543 long ret; 560 char cur_n[TASK_COMM_LEN], tty_n[64];
544 ret = wait_event_timeout(tty->ldisc->wq_idle, 561 long timeout = 3 * HZ;
545 atomic_read(&tty->ldisc->users) == 1, timeout); 562
546 return ret > 0 ? 0 : -EBUSY; 563 clear_bit(TTY_LDISC, &tty->flags);
564
565 if (tty->ldisc) { /* Not yet closed */
566 tty_unlock(tty);
567
568 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
569 timeout = MAX_SCHEDULE_TIMEOUT;
570 printk_ratelimited(KERN_WARNING
571 "%s: waiting (%s) for %s took too long, but we keep waiting...\n",
572 __func__, get_task_comm(cur_n, current),
573 tty_name(tty, tty_n));
574 }
575
576 set_bit(TTY_LDISC_HALTED, &tty->flags);
577
578 /* must reacquire both locks and preserve lock order */
579 mutex_unlock(&tty->ldisc_mutex);
580 tty_lock(tty);
581 mutex_lock(&tty->ldisc_mutex);
582 }
583 return !!tty->ldisc;
547} 584}
548 585
549/** 586/**
@@ -563,7 +600,6 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
563{ 600{
564 int retval; 601 int retval;
565 struct tty_ldisc *o_ldisc, *new_ldisc; 602 struct tty_ldisc *o_ldisc, *new_ldisc;
566 int work, o_work = 0;
567 struct tty_struct *o_tty; 603 struct tty_struct *o_tty;
568 604
569 new_ldisc = tty_ldisc_get(ldisc); 605 new_ldisc = tty_ldisc_get(ldisc);
@@ -589,15 +625,6 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
589 return 0; 625 return 0;
590 } 626 }
591 627
592 tty_unlock(tty);
593 /*
594 * Problem: What do we do if this blocks ?
595 * We could deadlock here
596 */
597
598 tty_wait_until_sent(tty, 0);
599
600 tty_lock(tty);
601 mutex_lock(&tty->ldisc_mutex); 628 mutex_lock(&tty->ldisc_mutex);
602 629
603 /* 630 /*
@@ -637,20 +664,16 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
637 * parallel to the change and re-referencing the tty. 664 * parallel to the change and re-referencing the tty.
638 */ 665 */
639 666
640 work = tty_ldisc_halt(tty); 667 retval = tty_ldisc_halt(tty, o_tty, 5 * HZ);
641 if (o_tty)
642 o_work = tty_ldisc_halt(o_tty);
643 668
644 /* 669 /*
645 * Wait for ->hangup_work and ->buf.work handlers to terminate. 670 * Wait for hangup to complete, if pending.
646 * We must drop the mutex here in case a hangup is also in process. 671 * We must drop the mutex here in case a hangup is also in process.
647 */ 672 */
648 673
649 mutex_unlock(&tty->ldisc_mutex); 674 mutex_unlock(&tty->ldisc_mutex);
650 675
651 tty_ldisc_flush_works(tty); 676 flush_work(&tty->hangup_work);
652
653 retval = tty_ldisc_wait_idle(tty, 5 * HZ);
654 677
655 tty_lock(tty); 678 tty_lock(tty);
656 mutex_lock(&tty->ldisc_mutex); 679 mutex_lock(&tty->ldisc_mutex);
@@ -675,7 +698,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
675 tty_ldisc_close(tty, o_ldisc); 698 tty_ldisc_close(tty, o_ldisc);
676 699
677 /* Now set up the new line discipline. */ 700 /* Now set up the new line discipline. */
678 tty_ldisc_assign(tty, new_ldisc); 701 tty->ldisc = new_ldisc;
679 tty_set_termios_ldisc(tty, ldisc); 702 tty_set_termios_ldisc(tty, ldisc);
680 703
681 retval = tty_ldisc_open(tty, new_ldisc); 704 retval = tty_ldisc_open(tty, new_ldisc);
@@ -705,10 +728,10 @@ enable:
705 728
706 /* Restart the work queue in case no characters kick it off. Safe if 729 /* Restart the work queue in case no characters kick it off. Safe if
707 already running */ 730 already running */
708 if (work) 731 schedule_work(&tty->port->buf.work);
709 schedule_work(&tty->port->buf.work); 732 if (o_tty)
710 if (o_work)
711 schedule_work(&o_tty->port->buf.work); 733 schedule_work(&o_tty->port->buf.work);
734
712 mutex_unlock(&tty->ldisc_mutex); 735 mutex_unlock(&tty->ldisc_mutex);
713 tty_unlock(tty); 736 tty_unlock(tty);
714 return retval; 737 return retval;
@@ -749,11 +772,10 @@ static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
749 772
750 tty_ldisc_close(tty, tty->ldisc); 773 tty_ldisc_close(tty, tty->ldisc);
751 tty_ldisc_put(tty->ldisc); 774 tty_ldisc_put(tty->ldisc);
752 tty->ldisc = NULL;
753 /* 775 /*
754 * Switch the line discipline back 776 * Switch the line discipline back
755 */ 777 */
756 tty_ldisc_assign(tty, ld); 778 tty->ldisc = ld;
757 tty_set_termios_ldisc(tty, ldisc); 779 tty_set_termios_ldisc(tty, ldisc);
758 780
759 return 0; 781 return 0;
@@ -780,6 +802,8 @@ void tty_ldisc_hangup(struct tty_struct *tty)
780 int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS; 802 int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS;
781 int err = 0; 803 int err = 0;
782 804
805 tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc);
806
783 /* 807 /*
784 * FIXME! What are the locking issues here? This may me overdoing 808 * FIXME! What are the locking issues here? This may me overdoing
785 * things... This question is especially important now that we've 809 * things... This question is especially important now that we've
@@ -812,40 +836,12 @@ void tty_ldisc_hangup(struct tty_struct *tty)
812 */ 836 */
813 mutex_lock(&tty->ldisc_mutex); 837 mutex_lock(&tty->ldisc_mutex);
814 838
815 /* 839 if (tty_ldisc_hangup_halt(tty)) {
816 * this is like tty_ldisc_halt, but we need to give up
817 * the BTM before calling cancel_work_sync, which may
818 * need to wait for another function taking the BTM
819 */
820 clear_bit(TTY_LDISC, &tty->flags);
821 tty_unlock(tty);
822 cancel_work_sync(&tty->port->buf.work);
823 mutex_unlock(&tty->ldisc_mutex);
824retry:
825 tty_lock(tty);
826 mutex_lock(&tty->ldisc_mutex);
827
828 /* At this point we have a closed ldisc and we want to
829 reopen it. We could defer this to the next open but
830 it means auditing a lot of other paths so this is
831 a FIXME */
832 if (tty->ldisc) { /* Not yet closed */
833 if (atomic_read(&tty->ldisc->users) != 1) {
834 char cur_n[TASK_COMM_LEN], tty_n[64];
835 long timeout = 3 * HZ;
836 tty_unlock(tty);
837
838 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
839 timeout = MAX_SCHEDULE_TIMEOUT;
840 printk_ratelimited(KERN_WARNING
841 "%s: waiting (%s) for %s took too long, but we keep waiting...\n",
842 __func__, get_task_comm(cur_n, current),
843 tty_name(tty, tty_n));
844 }
845 mutex_unlock(&tty->ldisc_mutex);
846 goto retry;
847 }
848 840
841 /* At this point we have a halted ldisc; we want to close it and
842 reopen a new ldisc. We could defer the reopen to the next
843 open but it means auditing a lot of other paths so this is
844 a FIXME */
849 if (reset == 0) { 845 if (reset == 0) {
850 846
851 if (!tty_ldisc_reinit(tty, tty->termios.c_line)) 847 if (!tty_ldisc_reinit(tty, tty->termios.c_line))
@@ -864,6 +860,8 @@ retry:
864 mutex_unlock(&tty->ldisc_mutex); 860 mutex_unlock(&tty->ldisc_mutex);
865 if (reset) 861 if (reset)
866 tty_reset_termios(tty); 862 tty_reset_termios(tty);
863
864 tty_ldisc_debug(tty, "re-opened ldisc: %p\n", tty->ldisc);
867} 865}
868 866
869/** 867/**
@@ -899,11 +897,6 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
899 897
900static void tty_ldisc_kill(struct tty_struct *tty) 898static void tty_ldisc_kill(struct tty_struct *tty)
901{ 899{
902 /* There cannot be users from userspace now. But there still might be
903 * drivers holding a reference via tty_ldisc_ref. Do not steal them the
904 * ldisc until they are done. */
905 tty_ldisc_wait_idle(tty, MAX_SCHEDULE_TIMEOUT);
906
907 mutex_lock(&tty->ldisc_mutex); 900 mutex_lock(&tty->ldisc_mutex);
908 /* 901 /*
909 * Now kill off the ldisc 902 * Now kill off the ldisc
@@ -931,18 +924,13 @@ static void tty_ldisc_kill(struct tty_struct *tty)
931void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) 924void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
932{ 925{
933 /* 926 /*
934 * Prevent flush_to_ldisc() from rescheduling the work for later. Then 927 * Shutdown this line discipline. As this is the final close,
935 * kill any delayed work. As this is the final close it does not 928 * it does not race with the set_ldisc code path.
936 * race with the set_ldisc code path.
937 */ 929 */
938 930
939 tty_ldisc_halt(tty); 931 tty_ldisc_debug(tty, "closing ldisc: %p\n", tty->ldisc);
940 if (o_tty)
941 tty_ldisc_halt(o_tty);
942 932
943 tty_ldisc_flush_works(tty); 933 tty_ldisc_halt(tty, o_tty, MAX_SCHEDULE_TIMEOUT);
944 if (o_tty)
945 tty_ldisc_flush_works(o_tty);
946 934
947 tty_lock_pair(tty, o_tty); 935 tty_lock_pair(tty, o_tty);
948 /* This will need doing differently if we need to lock */ 936 /* This will need doing differently if we need to lock */
@@ -953,6 +941,8 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
953 tty_unlock_pair(tty, o_tty); 941 tty_unlock_pair(tty, o_tty);
954 /* And the memory resources remaining (buffers, termios) will be 942 /* And the memory resources remaining (buffers, termios) will be
955 disposed of when the kref hits zero */ 943 disposed of when the kref hits zero */
944
945 tty_ldisc_debug(tty, "ldisc closed\n");
956} 946}
957 947
958/** 948/**
@@ -968,7 +958,7 @@ void tty_ldisc_init(struct tty_struct *tty)
968 struct tty_ldisc *ld = tty_ldisc_get(N_TTY); 958 struct tty_ldisc *ld = tty_ldisc_get(N_TTY);
969 if (IS_ERR(ld)) 959 if (IS_ERR(ld))
970 panic("n_tty: init_tty"); 960 panic("n_tty: init_tty");
971 tty_ldisc_assign(tty, ld); 961 tty->ldisc = ld;
972} 962}
973 963
974/** 964/**
@@ -980,8 +970,8 @@ void tty_ldisc_init(struct tty_struct *tty)
980 */ 970 */
981void tty_ldisc_deinit(struct tty_struct *tty) 971void tty_ldisc_deinit(struct tty_struct *tty)
982{ 972{
983 put_ldisc(tty->ldisc); 973 tty_ldisc_put(tty->ldisc);
984 tty_ldisc_assign(tty, NULL); 974 tty->ldisc = NULL;
985} 975}
986 976
987void tty_ldisc_begin(void) 977void tty_ldisc_begin(void)
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index b7ff59d3db88..121aeb9393e1 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -132,6 +132,7 @@ EXPORT_SYMBOL(tty_port_free_xmit_buf);
132 */ 132 */
133void tty_port_destroy(struct tty_port *port) 133void tty_port_destroy(struct tty_port *port)
134{ 134{
135 cancel_work_sync(&port->buf.work);
135 tty_buffer_free_all(port); 136 tty_buffer_free_all(port);
136} 137}
137EXPORT_SYMBOL(tty_port_destroy); 138EXPORT_SYMBOL(tty_port_destroy);
@@ -196,12 +197,24 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
196} 197}
197EXPORT_SYMBOL(tty_port_tty_set); 198EXPORT_SYMBOL(tty_port_tty_set);
198 199
199static void tty_port_shutdown(struct tty_port *port) 200static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
200{ 201{
201 mutex_lock(&port->mutex); 202 mutex_lock(&port->mutex);
202 if (port->ops->shutdown && !port->console && 203 if (port->console)
203 test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) 204 goto out;
205
206 if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) {
207 /*
208 * Drop DTR/RTS if HUPCL is set. This causes any attached
209 * modem to hang up the line.
210 */
211 if (tty && C_HUPCL(tty))
212 tty_port_lower_dtr_rts(port);
213
214 if (port->ops->shutdown)
204 port->ops->shutdown(port); 215 port->ops->shutdown(port);
216 }
217out:
205 mutex_unlock(&port->mutex); 218 mutex_unlock(&port->mutex);
206} 219}
207 220
@@ -215,24 +228,58 @@ static void tty_port_shutdown(struct tty_port *port)
215 228
216void tty_port_hangup(struct tty_port *port) 229void tty_port_hangup(struct tty_port *port)
217{ 230{
231 struct tty_struct *tty;
218 unsigned long flags; 232 unsigned long flags;
219 233
220 spin_lock_irqsave(&port->lock, flags); 234 spin_lock_irqsave(&port->lock, flags);
221 port->count = 0; 235 port->count = 0;
222 port->flags &= ~ASYNC_NORMAL_ACTIVE; 236 port->flags &= ~ASYNC_NORMAL_ACTIVE;
223 if (port->tty) { 237 tty = port->tty;
224 set_bit(TTY_IO_ERROR, &port->tty->flags); 238 if (tty)
225 tty_kref_put(port->tty); 239 set_bit(TTY_IO_ERROR, &tty->flags);
226 }
227 port->tty = NULL; 240 port->tty = NULL;
228 spin_unlock_irqrestore(&port->lock, flags); 241 spin_unlock_irqrestore(&port->lock, flags);
242 tty_port_shutdown(port, tty);
243 tty_kref_put(tty);
229 wake_up_interruptible(&port->open_wait); 244 wake_up_interruptible(&port->open_wait);
230 wake_up_interruptible(&port->delta_msr_wait); 245 wake_up_interruptible(&port->delta_msr_wait);
231 tty_port_shutdown(port);
232} 246}
233EXPORT_SYMBOL(tty_port_hangup); 247EXPORT_SYMBOL(tty_port_hangup);
234 248
235/** 249/**
250 * tty_port_tty_hangup - helper to hang up a tty
251 *
252 * @port: tty port
253 * @check_clocal: hang only ttys with CLOCAL unset?
254 */
255void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
256{
257 struct tty_struct *tty = tty_port_tty_get(port);
258
259 if (tty && (!check_clocal || !C_CLOCAL(tty))) {
260 tty_hangup(tty);
261 tty_kref_put(tty);
262 }
263}
264EXPORT_SYMBOL_GPL(tty_port_tty_hangup);
265
266/**
267 * tty_port_tty_wakeup - helper to wake up a tty
268 *
269 * @port: tty port
270 */
271void tty_port_tty_wakeup(struct tty_port *port)
272{
273 struct tty_struct *tty = tty_port_tty_get(port);
274
275 if (tty) {
276 tty_wakeup(tty);
277 tty_kref_put(tty);
278 }
279}
280EXPORT_SYMBOL_GPL(tty_port_tty_wakeup);
281
282/**
236 * tty_port_carrier_raised - carrier raised check 283 * tty_port_carrier_raised - carrier raised check
237 * @port: tty port 284 * @port: tty port
238 * 285 *
@@ -350,7 +397,7 @@ int tty_port_block_til_ready(struct tty_port *port,
350 397
351 while (1) { 398 while (1) {
352 /* Indicate we are open */ 399 /* Indicate we are open */
353 if (tty->termios.c_cflag & CBAUD) 400 if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags))
354 tty_port_raise_dtr_rts(port); 401 tty_port_raise_dtr_rts(port);
355 402
356 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); 403 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
@@ -395,6 +442,20 @@ int tty_port_block_til_ready(struct tty_port *port,
395} 442}
396EXPORT_SYMBOL(tty_port_block_til_ready); 443EXPORT_SYMBOL(tty_port_block_til_ready);
397 444
445static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty)
446{
447 unsigned int bps = tty_get_baud_rate(tty);
448 long timeout;
449
450 if (bps > 1200) {
451 timeout = (HZ * 10 * port->drain_delay) / bps;
452 timeout = max_t(long, timeout, HZ / 10);
453 } else {
454 timeout = 2 * HZ;
455 }
456 schedule_timeout_interruptible(timeout);
457}
458
398int tty_port_close_start(struct tty_port *port, 459int tty_port_close_start(struct tty_port *port,
399 struct tty_struct *tty, struct file *filp) 460 struct tty_struct *tty, struct file *filp)
400{ 461{
@@ -427,31 +488,19 @@ int tty_port_close_start(struct tty_port *port,
427 set_bit(ASYNCB_CLOSING, &port->flags); 488 set_bit(ASYNCB_CLOSING, &port->flags);
428 tty->closing = 1; 489 tty->closing = 1;
429 spin_unlock_irqrestore(&port->lock, flags); 490 spin_unlock_irqrestore(&port->lock, flags);
430 /* Don't block on a stalled port, just pull the chain */ 491
431 if (tty->flow_stopped) 492 if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
432 tty_driver_flush_buffer(tty); 493 /* Don't block on a stalled port, just pull the chain */
433 if (test_bit(ASYNCB_INITIALIZED, &port->flags) && 494 if (tty->flow_stopped)
434 port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 495 tty_driver_flush_buffer(tty);
435 tty_wait_until_sent_from_close(tty, port->closing_wait); 496 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
436 if (port->drain_delay) { 497 tty_wait_until_sent_from_close(tty, port->closing_wait);
437 unsigned int bps = tty_get_baud_rate(tty); 498 if (port->drain_delay)
438 long timeout; 499 tty_port_drain_delay(port, tty);
439
440 if (bps > 1200)
441 timeout = max_t(long,
442 (HZ * 10 * port->drain_delay) / bps, HZ / 10);
443 else
444 timeout = 2 * HZ;
445 schedule_timeout_interruptible(timeout);
446 } 500 }
447 /* Flush the ldisc buffering */ 501 /* Flush the ldisc buffering */
448 tty_ldisc_flush(tty); 502 tty_ldisc_flush(tty);
449 503
450 /* Drop DTR/RTS if HUPCL is set. This causes any attached modem to
451 hang up the line */
452 if (tty->termios.c_cflag & HUPCL)
453 tty_port_lower_dtr_rts(port);
454
455 /* Don't call port->drop for the last reference. Callers will want 504 /* Don't call port->drop for the last reference. Callers will want
456 to drop the last active reference in ->shutdown() or the tty 505 to drop the last active reference in ->shutdown() or the tty
457 shutdown path */ 506 shutdown path */
@@ -486,7 +535,7 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty,
486{ 535{
487 if (tty_port_close_start(port, tty, filp) == 0) 536 if (tty_port_close_start(port, tty, filp) == 0)
488 return; 537 return;
489 tty_port_shutdown(port); 538 tty_port_shutdown(port, tty);
490 set_bit(TTY_IO_ERROR, &tty->flags); 539 set_bit(TTY_IO_ERROR, &tty->flags);
491 tty_port_close_end(port, tty); 540 tty_port_close_end(port, tty);
492 tty_port_tty_set(port, NULL); 541 tty_port_tty_set(port, NULL);
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 248381b30722..2978ca596a7f 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -194,8 +194,7 @@ static void set_inverse_transl(struct vc_data *conp, struct uni_pagedir *p, int
194 q = p->inverse_translations[i]; 194 q = p->inverse_translations[i];
195 195
196 if (!q) { 196 if (!q) {
197 q = p->inverse_translations[i] = (unsigned char *) 197 q = p->inverse_translations[i] = kmalloc(MAX_GLYPH, GFP_KERNEL);
198 kmalloc(MAX_GLYPH, GFP_KERNEL);
199 if (!q) return; 198 if (!q) return;
200 } 199 }
201 memset(q, 0, MAX_GLYPH); 200 memset(q, 0, MAX_GLYPH);
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index e4ca345873c3..d7799deacb21 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -93,7 +93,7 @@ vcs_poll_data_free(struct vcs_poll_data *poll)
93static struct vcs_poll_data * 93static struct vcs_poll_data *
94vcs_poll_data_get(struct file *file) 94vcs_poll_data_get(struct file *file)
95{ 95{
96 struct vcs_poll_data *poll = file->private_data; 96 struct vcs_poll_data *poll = file->private_data, *kill = NULL;
97 97
98 if (poll) 98 if (poll)
99 return poll; 99 return poll;
@@ -122,10 +122,12 @@ vcs_poll_data_get(struct file *file)
122 file->private_data = poll; 122 file->private_data = poll;
123 } else { 123 } else {
124 /* someone else raced ahead of us */ 124 /* someone else raced ahead of us */
125 vcs_poll_data_free(poll); 125 kill = poll;
126 poll = file->private_data; 126 poll = file->private_data;
127 } 127 }
128 spin_unlock(&file->f_lock); 128 spin_unlock(&file->f_lock);
129 if (kill)
130 vcs_poll_data_free(kill);
129 131
130 return poll; 132 return poll;
131} 133}
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index fbd447b390f7..740202d8a5c4 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -779,7 +779,6 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
779 con_set_default_unimap(vc); 779 con_set_default_unimap(vc);
780 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); 780 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
781 if (!vc->vc_screenbuf) { 781 if (!vc->vc_screenbuf) {
782 tty_port_destroy(&vc->port);
783 kfree(vc); 782 kfree(vc);
784 vc_cons[currcons].d = NULL; 783 vc_cons[currcons].d = NULL;
785 return -ENOMEM; 784 return -ENOMEM;
@@ -986,26 +985,25 @@ static int vt_resize(struct tty_struct *tty, struct winsize *ws)
986 return ret; 985 return ret;
987} 986}
988 987
989void vc_deallocate(unsigned int currcons) 988struct vc_data *vc_deallocate(unsigned int currcons)
990{ 989{
990 struct vc_data *vc = NULL;
991
991 WARN_CONSOLE_UNLOCKED(); 992 WARN_CONSOLE_UNLOCKED();
992 993
993 if (vc_cons_allocated(currcons)) { 994 if (vc_cons_allocated(currcons)) {
994 struct vc_data *vc = vc_cons[currcons].d; 995 struct vt_notifier_param param;
995 struct vt_notifier_param param = { .vc = vc };
996 996
997 param.vc = vc = vc_cons[currcons].d;
997 atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, &param); 998 atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, &param);
998 vcs_remove_sysfs(currcons); 999 vcs_remove_sysfs(currcons);
999 vc->vc_sw->con_deinit(vc); 1000 vc->vc_sw->con_deinit(vc);
1000 put_pid(vc->vt_pid); 1001 put_pid(vc->vt_pid);
1001 module_put(vc->vc_sw->owner); 1002 module_put(vc->vc_sw->owner);
1002 kfree(vc->vc_screenbuf); 1003 kfree(vc->vc_screenbuf);
1003 if (currcons >= MIN_NR_CONSOLES) {
1004 tty_port_destroy(&vc->port);
1005 kfree(vc);
1006 }
1007 vc_cons[currcons].d = NULL; 1004 vc_cons[currcons].d = NULL;
1008 } 1005 }
1006 return vc;
1009} 1007}
1010 1008
1011/* 1009/*
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 98ff1735eafc..fc2c06c66e89 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -283,6 +283,51 @@ do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_
283 return 0; 283 return 0;
284} 284}
285 285
286/* deallocate a single console, if possible (leave 0) */
287static int vt_disallocate(unsigned int vc_num)
288{
289 struct vc_data *vc = NULL;
290 int ret = 0;
291
292 if (!vc_num)
293 return 0;
294
295 console_lock();
296 if (VT_BUSY(vc_num))
297 ret = -EBUSY;
298 else
299 vc = vc_deallocate(vc_num);
300 console_unlock();
301
302 if (vc && vc_num >= MIN_NR_CONSOLES) {
303 tty_port_destroy(&vc->port);
304 kfree(vc);
305 }
306
307 return ret;
308}
309
310/* deallocate all unused consoles, but leave 0 */
311static void vt_disallocate_all(void)
312{
313 struct vc_data *vc[MAX_NR_CONSOLES];
314 int i;
315
316 console_lock();
317 for (i = 1; i < MAX_NR_CONSOLES; i++)
318 if (!VT_BUSY(i))
319 vc[i] = vc_deallocate(i);
320 else
321 vc[i] = NULL;
322 console_unlock();
323
324 for (i = 1; i < MAX_NR_CONSOLES; i++) {
325 if (vc[i] && i >= MIN_NR_CONSOLES) {
326 tty_port_destroy(&vc[i]->port);
327 kfree(vc[i]);
328 }
329 }
330}
286 331
287 332
288/* 333/*
@@ -769,24 +814,10 @@ int vt_ioctl(struct tty_struct *tty,
769 ret = -ENXIO; 814 ret = -ENXIO;
770 break; 815 break;
771 } 816 }
772 if (arg == 0) { 817 if (arg == 0)
773 /* deallocate all unused consoles, but leave 0 */ 818 vt_disallocate_all();
774 console_lock(); 819 else
775 for (i=1; i<MAX_NR_CONSOLES; i++) 820 ret = vt_disallocate(--arg);
776 if (! VT_BUSY(i))
777 vc_deallocate(i);
778 console_unlock();
779 } else {
780 /* deallocate a single console, if possible */
781 arg--;
782 if (VT_BUSY(arg))
783 ret = -EBUSY;
784 else if (arg) { /* leave 0 */
785 console_lock();
786 vc_deallocate(arg);
787 console_unlock();
788 }
789 }
790 break; 821 break;
791 822
792 case VT_RESIZE: 823 case VT_RESIZE: