diff options
author | Alan Cox <alan@linux.intel.com> | 2009-09-19 16:13:31 -0400 |
---|---|---|
committer | Live-CD User <linux@linux.site> | 2009-09-19 16:13:31 -0400 |
commit | a2bceae065ed8c4f552b35c4dde4cc2db05ce9e3 (patch) | |
tree | 90c50ada1362bbb65c1b6f8c8c4fbc9227a21455 /drivers | |
parent | a03006860d272eac5a8ebf23f04f54c7e1e783a5 (diff) |
serial: replace the state mutex with the tty port mutex
They cover essentially the same stuff and we can therefore fold it into the
tty_port one.
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/serial/pmac_zilog.c | 8 | ||||
-rw-r--r-- | drivers/serial/serial_core.c | 227 |
2 files changed, 123 insertions, 112 deletions
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c index ab4c85ba3549..0dc786835dca 100644 --- a/drivers/serial/pmac_zilog.c +++ b/drivers/serial/pmac_zilog.c | |||
@@ -1645,7 +1645,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state) | |||
1645 | state = pmz_uart_reg.state + uap->port.line; | 1645 | state = pmz_uart_reg.state + uap->port.line; |
1646 | 1646 | ||
1647 | mutex_lock(&pmz_irq_mutex); | 1647 | mutex_lock(&pmz_irq_mutex); |
1648 | mutex_lock(&state->mutex); | 1648 | mutex_lock(&state->port.mutex); |
1649 | 1649 | ||
1650 | spin_lock_irqsave(&uap->port.lock, flags); | 1650 | spin_lock_irqsave(&uap->port.lock, flags); |
1651 | 1651 | ||
@@ -1676,7 +1676,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state) | |||
1676 | /* Shut the chip down */ | 1676 | /* Shut the chip down */ |
1677 | pmz_set_scc_power(uap, 0); | 1677 | pmz_set_scc_power(uap, 0); |
1678 | 1678 | ||
1679 | mutex_unlock(&state->mutex); | 1679 | mutex_unlock(&state->port.mutex); |
1680 | mutex_unlock(&pmz_irq_mutex); | 1680 | mutex_unlock(&pmz_irq_mutex); |
1681 | 1681 | ||
1682 | pmz_debug("suspend, switching complete\n"); | 1682 | pmz_debug("suspend, switching complete\n"); |
@@ -1705,7 +1705,7 @@ static int pmz_resume(struct macio_dev *mdev) | |||
1705 | state = pmz_uart_reg.state + uap->port.line; | 1705 | state = pmz_uart_reg.state + uap->port.line; |
1706 | 1706 | ||
1707 | mutex_lock(&pmz_irq_mutex); | 1707 | mutex_lock(&pmz_irq_mutex); |
1708 | mutex_lock(&state->mutex); | 1708 | mutex_lock(&state->port.mutex); |
1709 | 1709 | ||
1710 | spin_lock_irqsave(&uap->port.lock, flags); | 1710 | spin_lock_irqsave(&uap->port.lock, flags); |
1711 | if (!ZS_IS_OPEN(uap) && !ZS_IS_CONS(uap)) { | 1711 | if (!ZS_IS_OPEN(uap) && !ZS_IS_CONS(uap)) { |
@@ -1737,7 +1737,7 @@ static int pmz_resume(struct macio_dev *mdev) | |||
1737 | } | 1737 | } |
1738 | 1738 | ||
1739 | bail: | 1739 | bail: |
1740 | mutex_unlock(&state->mutex); | 1740 | mutex_unlock(&state->port.mutex); |
1741 | mutex_unlock(&pmz_irq_mutex); | 1741 | mutex_unlock(&pmz_irq_mutex); |
1742 | 1742 | ||
1743 | /* Right now, we deal with delay by blocking here, I'll be | 1743 | /* Right now, we deal with delay by blocking here, I'll be |
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c index 744dec9301fb..9d42e57e1971 100644 --- a/drivers/serial/serial_core.c +++ b/drivers/serial/serial_core.c | |||
@@ -633,35 +633,36 @@ static void uart_unthrottle(struct tty_struct *tty) | |||
633 | static int uart_get_info(struct uart_state *state, | 633 | static int uart_get_info(struct uart_state *state, |
634 | struct serial_struct __user *retinfo) | 634 | struct serial_struct __user *retinfo) |
635 | { | 635 | { |
636 | struct uart_port *port = state->uart_port; | 636 | struct uart_port *uport = state->uart_port; |
637 | struct tty_port *port = &state->port; | ||
637 | struct serial_struct tmp; | 638 | struct serial_struct tmp; |
638 | 639 | ||
639 | memset(&tmp, 0, sizeof(tmp)); | 640 | memset(&tmp, 0, sizeof(tmp)); |
640 | 641 | ||
641 | /* Ensure the state we copy is consistent and no hardware changes | 642 | /* Ensure the state we copy is consistent and no hardware changes |
642 | occur as we go */ | 643 | occur as we go */ |
643 | mutex_lock(&state->mutex); | 644 | mutex_lock(&port->mutex); |
644 | 645 | ||
645 | tmp.type = port->type; | 646 | tmp.type = uport->type; |
646 | tmp.line = port->line; | 647 | tmp.line = uport->line; |
647 | tmp.port = port->iobase; | 648 | tmp.port = uport->iobase; |
648 | if (HIGH_BITS_OFFSET) | 649 | if (HIGH_BITS_OFFSET) |
649 | tmp.port_high = (long) port->iobase >> HIGH_BITS_OFFSET; | 650 | tmp.port_high = (long) uport->iobase >> HIGH_BITS_OFFSET; |
650 | tmp.irq = port->irq; | 651 | tmp.irq = uport->irq; |
651 | tmp.flags = port->flags; | 652 | tmp.flags = uport->flags; |
652 | tmp.xmit_fifo_size = port->fifosize; | 653 | tmp.xmit_fifo_size = uport->fifosize; |
653 | tmp.baud_base = port->uartclk / 16; | 654 | tmp.baud_base = uport->uartclk / 16; |
654 | tmp.close_delay = state->port.close_delay / 10; | 655 | tmp.close_delay = port->close_delay / 10; |
655 | tmp.closing_wait = state->port.closing_wait == USF_CLOSING_WAIT_NONE ? | 656 | tmp.closing_wait = port->closing_wait == USF_CLOSING_WAIT_NONE ? |
656 | ASYNC_CLOSING_WAIT_NONE : | 657 | ASYNC_CLOSING_WAIT_NONE : |
657 | state->port.closing_wait / 10; | 658 | port->closing_wait / 10; |
658 | tmp.custom_divisor = port->custom_divisor; | 659 | tmp.custom_divisor = uport->custom_divisor; |
659 | tmp.hub6 = port->hub6; | 660 | tmp.hub6 = uport->hub6; |
660 | tmp.io_type = port->iotype; | 661 | tmp.io_type = uport->iotype; |
661 | tmp.iomem_reg_shift = port->regshift; | 662 | tmp.iomem_reg_shift = uport->regshift; |
662 | tmp.iomem_base = (void *)(unsigned long)port->mapbase; | 663 | tmp.iomem_base = (void *)(unsigned long)uport->mapbase; |
663 | 664 | ||
664 | mutex_unlock(&state->mutex); | 665 | mutex_unlock(&port->mutex); |
665 | 666 | ||
666 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | 667 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
667 | return -EFAULT; | 668 | return -EFAULT; |
@@ -699,7 +700,7 @@ static int uart_set_info(struct uart_state *state, | |||
699 | * module insertion/removal doesn't change anything | 700 | * module insertion/removal doesn't change anything |
700 | * under us. | 701 | * under us. |
701 | */ | 702 | */ |
702 | mutex_lock(&state->mutex); | 703 | mutex_lock(&port->mutex); |
703 | 704 | ||
704 | change_irq = !(uport->flags & UPF_FIXED_PORT) | 705 | change_irq = !(uport->flags & UPF_FIXED_PORT) |
705 | && new_serial.irq != uport->irq; | 706 | && new_serial.irq != uport->irq; |
@@ -867,7 +868,7 @@ static int uart_set_info(struct uart_state *state, | |||
867 | } else | 868 | } else |
868 | retval = uart_startup(state, 1); | 869 | retval = uart_startup(state, 1); |
869 | exit: | 870 | exit: |
870 | mutex_unlock(&state->mutex); | 871 | mutex_unlock(&port->mutex); |
871 | return retval; | 872 | return retval; |
872 | } | 873 | } |
873 | 874 | ||
@@ -902,10 +903,11 @@ static int uart_get_lsr_info(struct uart_state *state, | |||
902 | static int uart_tiocmget(struct tty_struct *tty, struct file *file) | 903 | static int uart_tiocmget(struct tty_struct *tty, struct file *file) |
903 | { | 904 | { |
904 | struct uart_state *state = tty->driver_data; | 905 | struct uart_state *state = tty->driver_data; |
906 | struct tty_port *port = &state->port; | ||
905 | struct uart_port *uport = state->uart_port; | 907 | struct uart_port *uport = state->uart_port; |
906 | int result = -EIO; | 908 | int result = -EIO; |
907 | 909 | ||
908 | mutex_lock(&state->mutex); | 910 | mutex_lock(&port->mutex); |
909 | if ((!file || !tty_hung_up_p(file)) && | 911 | if ((!file || !tty_hung_up_p(file)) && |
910 | !(tty->flags & (1 << TTY_IO_ERROR))) { | 912 | !(tty->flags & (1 << TTY_IO_ERROR))) { |
911 | result = uport->mctrl; | 913 | result = uport->mctrl; |
@@ -914,7 +916,7 @@ static int uart_tiocmget(struct tty_struct *tty, struct file *file) | |||
914 | result |= uport->ops->get_mctrl(uport); | 916 | result |= uport->ops->get_mctrl(uport); |
915 | spin_unlock_irq(&uport->lock); | 917 | spin_unlock_irq(&uport->lock); |
916 | } | 918 | } |
917 | mutex_unlock(&state->mutex); | 919 | mutex_unlock(&port->mutex); |
918 | 920 | ||
919 | return result; | 921 | return result; |
920 | } | 922 | } |
@@ -925,35 +927,38 @@ uart_tiocmset(struct tty_struct *tty, struct file *file, | |||
925 | { | 927 | { |
926 | struct uart_state *state = tty->driver_data; | 928 | struct uart_state *state = tty->driver_data; |
927 | struct uart_port *uport = state->uart_port; | 929 | struct uart_port *uport = state->uart_port; |
930 | struct tty_port *port = &state->port; | ||
928 | int ret = -EIO; | 931 | int ret = -EIO; |
929 | 932 | ||
930 | mutex_lock(&state->mutex); | 933 | mutex_lock(&port->mutex); |
931 | if ((!file || !tty_hung_up_p(file)) && | 934 | if ((!file || !tty_hung_up_p(file)) && |
932 | !(tty->flags & (1 << TTY_IO_ERROR))) { | 935 | !(tty->flags & (1 << TTY_IO_ERROR))) { |
933 | uart_update_mctrl(uport, set, clear); | 936 | uart_update_mctrl(uport, set, clear); |
934 | ret = 0; | 937 | ret = 0; |
935 | } | 938 | } |
936 | mutex_unlock(&state->mutex); | 939 | mutex_unlock(&port->mutex); |
937 | return ret; | 940 | return ret; |
938 | } | 941 | } |
939 | 942 | ||
940 | static int uart_break_ctl(struct tty_struct *tty, int break_state) | 943 | static int uart_break_ctl(struct tty_struct *tty, int break_state) |
941 | { | 944 | { |
942 | struct uart_state *state = tty->driver_data; | 945 | struct uart_state *state = tty->driver_data; |
946 | struct tty_port *port = &state->port; | ||
943 | struct uart_port *uport = state->uart_port; | 947 | struct uart_port *uport = state->uart_port; |
944 | 948 | ||
945 | mutex_lock(&state->mutex); | 949 | mutex_lock(&port->mutex); |
946 | 950 | ||
947 | if (uport->type != PORT_UNKNOWN) | 951 | if (uport->type != PORT_UNKNOWN) |
948 | uport->ops->break_ctl(uport, break_state); | 952 | uport->ops->break_ctl(uport, break_state); |
949 | 953 | ||
950 | mutex_unlock(&state->mutex); | 954 | mutex_unlock(&port->mutex); |
951 | return 0; | 955 | return 0; |
952 | } | 956 | } |
953 | 957 | ||
954 | static int uart_do_autoconfig(struct uart_state *state) | 958 | static int uart_do_autoconfig(struct uart_state *state) |
955 | { | 959 | { |
956 | struct uart_port *uport = state->uart_port; | 960 | struct uart_port *uport = state->uart_port; |
961 | struct tty_port *port = &state->port; | ||
957 | int flags, ret; | 962 | int flags, ret; |
958 | 963 | ||
959 | if (!capable(CAP_SYS_ADMIN)) | 964 | if (!capable(CAP_SYS_ADMIN)) |
@@ -964,7 +969,7 @@ static int uart_do_autoconfig(struct uart_state *state) | |||
964 | * changing, and hence any extra opens of the port while | 969 | * changing, and hence any extra opens of the port while |
965 | * we're auto-configuring. | 970 | * we're auto-configuring. |
966 | */ | 971 | */ |
967 | if (mutex_lock_interruptible(&state->mutex)) | 972 | if (mutex_lock_interruptible(&port->mutex)) |
968 | return -ERESTARTSYS; | 973 | return -ERESTARTSYS; |
969 | 974 | ||
970 | ret = -EBUSY; | 975 | ret = -EBUSY; |
@@ -990,7 +995,7 @@ static int uart_do_autoconfig(struct uart_state *state) | |||
990 | 995 | ||
991 | ret = uart_startup(state, 1); | 996 | ret = uart_startup(state, 1); |
992 | } | 997 | } |
993 | mutex_unlock(&state->mutex); | 998 | mutex_unlock(&port->mutex); |
994 | return ret; | 999 | return ret; |
995 | } | 1000 | } |
996 | 1001 | ||
@@ -1093,6 +1098,7 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, | |||
1093 | unsigned long arg) | 1098 | unsigned long arg) |
1094 | { | 1099 | { |
1095 | struct uart_state *state = tty->driver_data; | 1100 | struct uart_state *state = tty->driver_data; |
1101 | struct tty_port *port = &state->port; | ||
1096 | void __user *uarg = (void __user *)arg; | 1102 | void __user *uarg = (void __user *)arg; |
1097 | int ret = -ENOIOCTLCMD; | 1103 | int ret = -ENOIOCTLCMD; |
1098 | 1104 | ||
@@ -1143,7 +1149,7 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, | |||
1143 | if (ret != -ENOIOCTLCMD) | 1149 | if (ret != -ENOIOCTLCMD) |
1144 | goto out; | 1150 | goto out; |
1145 | 1151 | ||
1146 | mutex_lock(&state->mutex); | 1152 | mutex_lock(&port->mutex); |
1147 | 1153 | ||
1148 | if (tty_hung_up_p(filp)) { | 1154 | if (tty_hung_up_p(filp)) { |
1149 | ret = -EIO; | 1155 | ret = -EIO; |
@@ -1167,7 +1173,7 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, | |||
1167 | } | 1173 | } |
1168 | } | 1174 | } |
1169 | out_up: | 1175 | out_up: |
1170 | mutex_unlock(&state->mutex); | 1176 | mutex_unlock(&port->mutex); |
1171 | out: | 1177 | out: |
1172 | return ret; | 1178 | return ret; |
1173 | } | 1179 | } |
@@ -1266,7 +1272,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp) | |||
1266 | 1272 | ||
1267 | pr_debug("uart_close(%d) called\n", uport->line); | 1273 | pr_debug("uart_close(%d) called\n", uport->line); |
1268 | 1274 | ||
1269 | mutex_lock(&state->mutex); | 1275 | mutex_lock(&port->mutex); |
1270 | 1276 | ||
1271 | if (tty_hung_up_p(filp)) | 1277 | if (tty_hung_up_p(filp)) |
1272 | goto done; | 1278 | goto done; |
@@ -1340,7 +1346,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp) | |||
1340 | wake_up_interruptible(&port->open_wait); | 1346 | wake_up_interruptible(&port->open_wait); |
1341 | 1347 | ||
1342 | done: | 1348 | done: |
1343 | mutex_unlock(&state->mutex); | 1349 | mutex_unlock(&port->mutex); |
1344 | } | 1350 | } |
1345 | 1351 | ||
1346 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout) | 1352 | static void uart_wait_until_sent(struct tty_struct *tty, int timeout) |
@@ -1416,7 +1422,7 @@ static void uart_hangup(struct tty_struct *tty) | |||
1416 | BUG_ON(!kernel_locked()); | 1422 | BUG_ON(!kernel_locked()); |
1417 | pr_debug("uart_hangup(%d)\n", state->uart_port->line); | 1423 | pr_debug("uart_hangup(%d)\n", state->uart_port->line); |
1418 | 1424 | ||
1419 | mutex_lock(&state->mutex); | 1425 | mutex_lock(&port->mutex); |
1420 | if (port->flags & ASYNC_NORMAL_ACTIVE) { | 1426 | if (port->flags & ASYNC_NORMAL_ACTIVE) { |
1421 | uart_flush_buffer(tty); | 1427 | uart_flush_buffer(tty); |
1422 | uart_shutdown(state); | 1428 | uart_shutdown(state); |
@@ -1426,7 +1432,7 @@ static void uart_hangup(struct tty_struct *tty) | |||
1426 | wake_up_interruptible(&port->open_wait); | 1432 | wake_up_interruptible(&port->open_wait); |
1427 | wake_up_interruptible(&state->delta_msr_wait); | 1433 | wake_up_interruptible(&state->delta_msr_wait); |
1428 | } | 1434 | } |
1429 | mutex_unlock(&state->mutex); | 1435 | mutex_unlock(&port->mutex); |
1430 | } | 1436 | } |
1431 | 1437 | ||
1432 | /* | 1438 | /* |
@@ -1528,9 +1534,9 @@ uart_block_til_ready(struct file *filp, struct uart_state *state) | |||
1528 | if (mctrl & TIOCM_CAR) | 1534 | if (mctrl & TIOCM_CAR) |
1529 | break; | 1535 | break; |
1530 | 1536 | ||
1531 | mutex_unlock(&state->mutex); | 1537 | mutex_unlock(&port->mutex); |
1532 | schedule(); | 1538 | schedule(); |
1533 | mutex_lock(&state->mutex); | 1539 | mutex_lock(&port->mutex); |
1534 | 1540 | ||
1535 | if (signal_pending(current)) | 1541 | if (signal_pending(current)) |
1536 | break; | 1542 | break; |
@@ -1553,15 +1559,17 @@ uart_block_til_ready(struct file *filp, struct uart_state *state) | |||
1553 | static struct uart_state *uart_get(struct uart_driver *drv, int line) | 1559 | static struct uart_state *uart_get(struct uart_driver *drv, int line) |
1554 | { | 1560 | { |
1555 | struct uart_state *state; | 1561 | struct uart_state *state; |
1562 | struct tty_port *port; | ||
1556 | int ret = 0; | 1563 | int ret = 0; |
1557 | 1564 | ||
1558 | state = drv->state + line; | 1565 | state = drv->state + line; |
1559 | if (mutex_lock_interruptible(&state->mutex)) { | 1566 | port = &state->port; |
1567 | if (mutex_lock_interruptible(&port->mutex)) { | ||
1560 | ret = -ERESTARTSYS; | 1568 | ret = -ERESTARTSYS; |
1561 | goto err; | 1569 | goto err; |
1562 | } | 1570 | } |
1563 | 1571 | ||
1564 | state->port.count++; | 1572 | port->count++; |
1565 | if (!state->uart_port || state->uart_port->flags & UPF_DEAD) { | 1573 | if (!state->uart_port || state->uart_port->flags & UPF_DEAD) { |
1566 | ret = -ENXIO; | 1574 | ret = -ENXIO; |
1567 | goto err_unlock; | 1575 | goto err_unlock; |
@@ -1569,8 +1577,8 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line) | |||
1569 | return state; | 1577 | return state; |
1570 | 1578 | ||
1571 | err_unlock: | 1579 | err_unlock: |
1572 | state->port.count--; | 1580 | port->count--; |
1573 | mutex_unlock(&state->mutex); | 1581 | mutex_unlock(&port->mutex); |
1574 | err: | 1582 | err: |
1575 | return ERR_PTR(ret); | 1583 | return ERR_PTR(ret); |
1576 | } | 1584 | } |
@@ -1636,7 +1644,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp) | |||
1636 | if (tty_hung_up_p(filp)) { | 1644 | if (tty_hung_up_p(filp)) { |
1637 | retval = -EAGAIN; | 1645 | retval = -EAGAIN; |
1638 | port->count--; | 1646 | port->count--; |
1639 | mutex_unlock(&state->mutex); | 1647 | mutex_unlock(&port->mutex); |
1640 | goto fail; | 1648 | goto fail; |
1641 | } | 1649 | } |
1642 | 1650 | ||
@@ -1656,7 +1664,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp) | |||
1656 | */ | 1664 | */ |
1657 | if (retval == 0) | 1665 | if (retval == 0) |
1658 | retval = uart_block_til_ready(filp, state); | 1666 | retval = uart_block_til_ready(filp, state); |
1659 | mutex_unlock(&state->mutex); | 1667 | mutex_unlock(&port->mutex); |
1660 | 1668 | ||
1661 | /* | 1669 | /* |
1662 | * If this is the first open to succeed, adjust things to suit. | 1670 | * If this is the first open to succeed, adjust things to suit. |
@@ -1667,7 +1675,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp) | |||
1667 | uart_update_termios(state); | 1675 | uart_update_termios(state); |
1668 | } | 1676 | } |
1669 | 1677 | ||
1670 | fail: | 1678 | fail: |
1671 | return retval; | 1679 | return retval; |
1672 | } | 1680 | } |
1673 | 1681 | ||
@@ -1689,57 +1697,58 @@ static const char *uart_type(struct uart_port *port) | |||
1689 | static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i) | 1697 | static void uart_line_info(struct seq_file *m, struct uart_driver *drv, int i) |
1690 | { | 1698 | { |
1691 | struct uart_state *state = drv->state + i; | 1699 | struct uart_state *state = drv->state + i; |
1700 | struct tty_port *port = &state->port; | ||
1692 | int pm_state; | 1701 | int pm_state; |
1693 | struct uart_port *port = state->uart_port; | 1702 | struct uart_port *uport = state->uart_port; |
1694 | char stat_buf[32]; | 1703 | char stat_buf[32]; |
1695 | unsigned int status; | 1704 | unsigned int status; |
1696 | int mmio; | 1705 | int mmio; |
1697 | 1706 | ||
1698 | if (!port) | 1707 | if (!uport) |
1699 | return; | 1708 | return; |
1700 | 1709 | ||
1701 | mmio = port->iotype >= UPIO_MEM; | 1710 | mmio = uport->iotype >= UPIO_MEM; |
1702 | seq_printf(m, "%d: uart:%s %s%08llX irq:%d", | 1711 | seq_printf(m, "%d: uart:%s %s%08llX irq:%d", |
1703 | port->line, uart_type(port), | 1712 | uport->line, uart_type(uport), |
1704 | mmio ? "mmio:0x" : "port:", | 1713 | mmio ? "mmio:0x" : "port:", |
1705 | mmio ? (unsigned long long)port->mapbase | 1714 | mmio ? (unsigned long long)uport->mapbase |
1706 | : (unsigned long long) port->iobase, | 1715 | : (unsigned long long)uport->iobase, |
1707 | port->irq); | 1716 | uport->irq); |
1708 | 1717 | ||
1709 | if (port->type == PORT_UNKNOWN) { | 1718 | if (uport->type == PORT_UNKNOWN) { |
1710 | seq_putc(m, '\n'); | 1719 | seq_putc(m, '\n'); |
1711 | return; | 1720 | return; |
1712 | } | 1721 | } |
1713 | 1722 | ||
1714 | if (capable(CAP_SYS_ADMIN)) { | 1723 | if (capable(CAP_SYS_ADMIN)) { |
1715 | mutex_lock(&state->mutex); | 1724 | mutex_lock(&port->mutex); |
1716 | pm_state = state->pm_state; | 1725 | pm_state = state->pm_state; |
1717 | if (pm_state) | 1726 | if (pm_state) |
1718 | uart_change_pm(state, 0); | 1727 | uart_change_pm(state, 0); |
1719 | spin_lock_irq(&port->lock); | 1728 | spin_lock_irq(&uport->lock); |
1720 | status = port->ops->get_mctrl(port); | 1729 | status = uport->ops->get_mctrl(uport); |
1721 | spin_unlock_irq(&port->lock); | 1730 | spin_unlock_irq(&uport->lock); |
1722 | if (pm_state) | 1731 | if (pm_state) |
1723 | uart_change_pm(state, pm_state); | 1732 | uart_change_pm(state, pm_state); |
1724 | mutex_unlock(&state->mutex); | 1733 | mutex_unlock(&port->mutex); |
1725 | 1734 | ||
1726 | seq_printf(m, " tx:%d rx:%d", | 1735 | seq_printf(m, " tx:%d rx:%d", |
1727 | port->icount.tx, port->icount.rx); | 1736 | uport->icount.tx, uport->icount.rx); |
1728 | if (port->icount.frame) | 1737 | if (uport->icount.frame) |
1729 | seq_printf(m, " fe:%d", | 1738 | seq_printf(m, " fe:%d", |
1730 | port->icount.frame); | 1739 | uport->icount.frame); |
1731 | if (port->icount.parity) | 1740 | if (uport->icount.parity) |
1732 | seq_printf(m, " pe:%d", | 1741 | seq_printf(m, " pe:%d", |
1733 | port->icount.parity); | 1742 | uport->icount.parity); |
1734 | if (port->icount.brk) | 1743 | if (uport->icount.brk) |
1735 | seq_printf(m, " brk:%d", | 1744 | seq_printf(m, " brk:%d", |
1736 | port->icount.brk); | 1745 | uport->icount.brk); |
1737 | if (port->icount.overrun) | 1746 | if (uport->icount.overrun) |
1738 | seq_printf(m, " oe:%d", | 1747 | seq_printf(m, " oe:%d", |
1739 | port->icount.overrun); | 1748 | uport->icount.overrun); |
1740 | 1749 | ||
1741 | #define INFOBIT(bit, str) \ | 1750 | #define INFOBIT(bit, str) \ |
1742 | if (port->mctrl & (bit)) \ | 1751 | if (uport->mctrl & (bit)) \ |
1743 | strncat(stat_buf, (str), sizeof(stat_buf) - \ | 1752 | strncat(stat_buf, (str), sizeof(stat_buf) - \ |
1744 | strlen(stat_buf) - 2) | 1753 | strlen(stat_buf) - 2) |
1745 | #define STATBIT(bit, str) \ | 1754 | #define STATBIT(bit, str) \ |
@@ -1991,11 +2000,11 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport) | |||
1991 | struct device *tty_dev; | 2000 | struct device *tty_dev; |
1992 | struct uart_match match = {uport, drv}; | 2001 | struct uart_match match = {uport, drv}; |
1993 | 2002 | ||
1994 | mutex_lock(&state->mutex); | 2003 | mutex_lock(&port->mutex); |
1995 | 2004 | ||
1996 | if (!console_suspend_enabled && uart_console(uport)) { | 2005 | if (!console_suspend_enabled && uart_console(uport)) { |
1997 | /* we're going to avoid suspending serial console */ | 2006 | /* we're going to avoid suspending serial console */ |
1998 | mutex_unlock(&state->mutex); | 2007 | mutex_unlock(&port->mutex); |
1999 | return 0; | 2008 | return 0; |
2000 | } | 2009 | } |
2001 | 2010 | ||
@@ -2003,7 +2012,7 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport) | |||
2003 | if (device_may_wakeup(tty_dev)) { | 2012 | if (device_may_wakeup(tty_dev)) { |
2004 | enable_irq_wake(uport->irq); | 2013 | enable_irq_wake(uport->irq); |
2005 | put_device(tty_dev); | 2014 | put_device(tty_dev); |
2006 | mutex_unlock(&state->mutex); | 2015 | mutex_unlock(&port->mutex); |
2007 | return 0; | 2016 | return 0; |
2008 | } | 2017 | } |
2009 | uport->suspended = 1; | 2018 | uport->suspended = 1; |
@@ -2045,7 +2054,7 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport) | |||
2045 | 2054 | ||
2046 | uart_change_pm(state, 3); | 2055 | uart_change_pm(state, 3); |
2047 | 2056 | ||
2048 | mutex_unlock(&state->mutex); | 2057 | mutex_unlock(&port->mutex); |
2049 | 2058 | ||
2050 | return 0; | 2059 | return 0; |
2051 | } | 2060 | } |
@@ -2057,18 +2066,18 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport) | |||
2057 | struct device *tty_dev; | 2066 | struct device *tty_dev; |
2058 | struct uart_match match = {uport, drv}; | 2067 | struct uart_match match = {uport, drv}; |
2059 | 2068 | ||
2060 | mutex_lock(&state->mutex); | 2069 | mutex_lock(&port->mutex); |
2061 | 2070 | ||
2062 | if (!console_suspend_enabled && uart_console(uport)) { | 2071 | if (!console_suspend_enabled && uart_console(uport)) { |
2063 | /* no need to resume serial console, it wasn't suspended */ | 2072 | /* no need to resume serial console, it wasn't suspended */ |
2064 | mutex_unlock(&state->mutex); | 2073 | mutex_unlock(&port->mutex); |
2065 | return 0; | 2074 | return 0; |
2066 | } | 2075 | } |
2067 | 2076 | ||
2068 | tty_dev = device_find_child(uport->dev, &match, serial_match_port); | 2077 | tty_dev = device_find_child(uport->dev, &match, serial_match_port); |
2069 | if (!uport->suspended && device_may_wakeup(tty_dev)) { | 2078 | if (!uport->suspended && device_may_wakeup(tty_dev)) { |
2070 | disable_irq_wake(uport->irq); | 2079 | disable_irq_wake(uport->irq); |
2071 | mutex_unlock(&state->mutex); | 2080 | mutex_unlock(&port->mutex); |
2072 | return 0; | 2081 | return 0; |
2073 | } | 2082 | } |
2074 | uport->suspended = 0; | 2083 | uport->suspended = 0; |
@@ -2124,7 +2133,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport) | |||
2124 | clear_bit(ASYNCB_SUSPENDED, &port->flags); | 2133 | clear_bit(ASYNCB_SUSPENDED, &port->flags); |
2125 | } | 2134 | } |
2126 | 2135 | ||
2127 | mutex_unlock(&state->mutex); | 2136 | mutex_unlock(&port->mutex); |
2128 | 2137 | ||
2129 | return 0; | 2138 | return 0; |
2130 | } | 2139 | } |
@@ -2364,12 +2373,11 @@ int uart_register_driver(struct uart_driver *drv) | |||
2364 | */ | 2373 | */ |
2365 | for (i = 0; i < drv->nr; i++) { | 2374 | for (i = 0; i < drv->nr; i++) { |
2366 | struct uart_state *state = drv->state + i; | 2375 | struct uart_state *state = drv->state + i; |
2376 | struct tty_port *port = &state->port; | ||
2367 | 2377 | ||
2368 | mutex_init(&state->mutex); | 2378 | tty_port_init(port); |
2369 | 2379 | port->close_delay = 500; /* .5 seconds */ | |
2370 | tty_port_init(&state->port); | 2380 | port->closing_wait = 30000; /* 30 seconds */ |
2371 | state->port.close_delay = 500; /* .5 seconds */ | ||
2372 | state->port.closing_wait = 30000; /* 30 seconds */ | ||
2373 | init_waitqueue_head(&state->delta_msr_wait); | 2381 | init_waitqueue_head(&state->delta_msr_wait); |
2374 | tasklet_init(&state->tlet, uart_tasklet_action, | 2382 | tasklet_init(&state->tlet, uart_tasklet_action, |
2375 | (unsigned long)state); | 2383 | (unsigned long)state); |
@@ -2419,62 +2427,64 @@ struct tty_driver *uart_console_device(struct console *co, int *index) | |||
2419 | * level uart drivers to expand uart_port, rather than having yet | 2427 | * level uart drivers to expand uart_port, rather than having yet |
2420 | * more levels of structures. | 2428 | * more levels of structures. |
2421 | */ | 2429 | */ |
2422 | int uart_add_one_port(struct uart_driver *drv, struct uart_port *port) | 2430 | int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) |
2423 | { | 2431 | { |
2424 | struct uart_state *state; | 2432 | struct uart_state *state; |
2433 | struct tty_port *port; | ||
2425 | int ret = 0; | 2434 | int ret = 0; |
2426 | struct device *tty_dev; | 2435 | struct device *tty_dev; |
2427 | 2436 | ||
2428 | BUG_ON(in_interrupt()); | 2437 | BUG_ON(in_interrupt()); |
2429 | 2438 | ||
2430 | if (port->line >= drv->nr) | 2439 | if (uport->line >= drv->nr) |
2431 | return -EINVAL; | 2440 | return -EINVAL; |
2432 | 2441 | ||
2433 | state = drv->state + port->line; | 2442 | state = drv->state + uport->line; |
2443 | port = &state->port; | ||
2434 | 2444 | ||
2435 | mutex_lock(&port_mutex); | 2445 | mutex_lock(&port_mutex); |
2436 | mutex_lock(&state->mutex); | 2446 | mutex_lock(&port->mutex); |
2437 | if (state->uart_port) { | 2447 | if (state->uart_port) { |
2438 | ret = -EINVAL; | 2448 | ret = -EINVAL; |
2439 | goto out; | 2449 | goto out; |
2440 | } | 2450 | } |
2441 | 2451 | ||
2442 | state->uart_port = port; | 2452 | state->uart_port = uport; |
2443 | state->pm_state = -1; | 2453 | state->pm_state = -1; |
2444 | 2454 | ||
2445 | port->cons = drv->cons; | 2455 | uport->cons = drv->cons; |
2446 | port->state = state; | 2456 | uport->state = state; |
2447 | 2457 | ||
2448 | /* | 2458 | /* |
2449 | * If this port is a console, then the spinlock is already | 2459 | * If this port is a console, then the spinlock is already |
2450 | * initialised. | 2460 | * initialised. |
2451 | */ | 2461 | */ |
2452 | if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) { | 2462 | if (!(uart_console(uport) && (uport->cons->flags & CON_ENABLED))) { |
2453 | spin_lock_init(&port->lock); | 2463 | spin_lock_init(&uport->lock); |
2454 | lockdep_set_class(&port->lock, &port_lock_key); | 2464 | lockdep_set_class(&uport->lock, &port_lock_key); |
2455 | } | 2465 | } |
2456 | 2466 | ||
2457 | uart_configure_port(drv, state, port); | 2467 | uart_configure_port(drv, state, uport); |
2458 | 2468 | ||
2459 | /* | 2469 | /* |
2460 | * Register the port whether it's detected or not. This allows | 2470 | * Register the port whether it's detected or not. This allows |
2461 | * setserial to be used to alter this ports parameters. | 2471 | * setserial to be used to alter this ports parameters. |
2462 | */ | 2472 | */ |
2463 | tty_dev = tty_register_device(drv->tty_driver, port->line, port->dev); | 2473 | tty_dev = tty_register_device(drv->tty_driver, uport->line, uport->dev); |
2464 | if (likely(!IS_ERR(tty_dev))) { | 2474 | if (likely(!IS_ERR(tty_dev))) { |
2465 | device_init_wakeup(tty_dev, 1); | 2475 | device_init_wakeup(tty_dev, 1); |
2466 | device_set_wakeup_enable(tty_dev, 0); | 2476 | device_set_wakeup_enable(tty_dev, 0); |
2467 | } else | 2477 | } else |
2468 | printk(KERN_ERR "Cannot register tty device on line %d\n", | 2478 | printk(KERN_ERR "Cannot register tty device on line %d\n", |
2469 | port->line); | 2479 | uport->line); |
2470 | 2480 | ||
2471 | /* | 2481 | /* |
2472 | * Ensure UPF_DEAD is not set. | 2482 | * Ensure UPF_DEAD is not set. |
2473 | */ | 2483 | */ |
2474 | port->flags &= ~UPF_DEAD; | 2484 | uport->flags &= ~UPF_DEAD; |
2475 | 2485 | ||
2476 | out: | 2486 | out: |
2477 | mutex_unlock(&state->mutex); | 2487 | mutex_unlock(&port->mutex); |
2478 | mutex_unlock(&port_mutex); | 2488 | mutex_unlock(&port_mutex); |
2479 | 2489 | ||
2480 | return ret; | 2490 | return ret; |
@@ -2489,15 +2499,16 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port) | |||
2489 | * core driver. No further calls will be made to the low-level code | 2499 | * core driver. No further calls will be made to the low-level code |
2490 | * for this port. | 2500 | * for this port. |
2491 | */ | 2501 | */ |
2492 | int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port) | 2502 | int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport) |
2493 | { | 2503 | { |
2494 | struct uart_state *state = drv->state + port->line; | 2504 | struct uart_state *state = drv->state + uport->line; |
2505 | struct tty_port *port = &state->port; | ||
2495 | 2506 | ||
2496 | BUG_ON(in_interrupt()); | 2507 | BUG_ON(in_interrupt()); |
2497 | 2508 | ||
2498 | if (state->uart_port != port) | 2509 | if (state->uart_port != uport) |
2499 | printk(KERN_ALERT "Removing wrong port: %p != %p\n", | 2510 | printk(KERN_ALERT "Removing wrong port: %p != %p\n", |
2500 | state->uart_port, port); | 2511 | state->uart_port, uport); |
2501 | 2512 | ||
2502 | mutex_lock(&port_mutex); | 2513 | mutex_lock(&port_mutex); |
2503 | 2514 | ||
@@ -2505,28 +2516,28 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port) | |||
2505 | * Mark the port "dead" - this prevents any opens from | 2516 | * Mark the port "dead" - this prevents any opens from |
2506 | * succeeding while we shut down the port. | 2517 | * succeeding while we shut down the port. |
2507 | */ | 2518 | */ |
2508 | mutex_lock(&state->mutex); | 2519 | mutex_lock(&port->mutex); |
2509 | port->flags |= UPF_DEAD; | 2520 | uport->flags |= UPF_DEAD; |
2510 | mutex_unlock(&state->mutex); | 2521 | mutex_unlock(&port->mutex); |
2511 | 2522 | ||
2512 | /* | 2523 | /* |
2513 | * Remove the devices from the tty layer | 2524 | * Remove the devices from the tty layer |
2514 | */ | 2525 | */ |
2515 | tty_unregister_device(drv->tty_driver, port->line); | 2526 | tty_unregister_device(drv->tty_driver, uport->line); |
2516 | 2527 | ||
2517 | if (state->port.tty) | 2528 | if (port->tty) |
2518 | tty_vhangup(state->port.tty); | 2529 | tty_vhangup(port->tty); |
2519 | 2530 | ||
2520 | /* | 2531 | /* |
2521 | * Free the port IO and memory resources, if any. | 2532 | * Free the port IO and memory resources, if any. |
2522 | */ | 2533 | */ |
2523 | if (port->type != PORT_UNKNOWN) | 2534 | if (uport->type != PORT_UNKNOWN) |
2524 | port->ops->release_port(port); | 2535 | uport->ops->release_port(uport); |
2525 | 2536 | ||
2526 | /* | 2537 | /* |
2527 | * Indicate that there isn't a port here anymore. | 2538 | * Indicate that there isn't a port here anymore. |
2528 | */ | 2539 | */ |
2529 | port->type = PORT_UNKNOWN; | 2540 | uport->type = PORT_UNKNOWN; |
2530 | 2541 | ||
2531 | /* | 2542 | /* |
2532 | * Kill the tasklet, and free resources. | 2543 | * Kill the tasklet, and free resources. |