diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-22 19:12:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-22 19:12:24 -0400 |
commit | 94b5aff4c6f72fee6b0f49d49e4fa8b204e8ded9 (patch) | |
tree | 39197121b6ef8cddaa0f4057fe24b4ced58e8982 /drivers | |
parent | 5d4e2d08e7fdf7339f84a1c670d296a77e02f881 (diff) | |
parent | 59bd234b72fc29887839d792b7d6c7e8d2a577a6 (diff) |
Merge tag 'tty-3.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull TTY updates from Greg Kroah-Hartman:
"Here's the big TTY/serial driver pull request for the 3.5-rc1 merge
window.
Nothing major in here, just lots of incremental changes from Alan and
Jiri reworking some tty core things to behave better and to get a more
solid grasp on some of the nasty tty locking issues.
There are a few tty and serial driver updates in here as well.
All of this has been in the linux-next releases for a while with no
problems.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>"
* tag 'tty-3.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (115 commits)
serial: bfin_uart: Make MMR access compatible with 32 bits bf609 style controller.
serial: bfin_uart: RTS and CTS MMRs can be either 16-bit width or 32-bit width.
serial: bfin_uart: narrow the reboot condition in DMA tx interrupt
serial: bfin_uart: Adapt bf5xx serial driver to bf60x serial4 controller.
Revert "serial_core: Update buffer overrun statistics."
tty: hvc_xen: NULL dereference on allocation failure
tty: Fix LED error return
tty: Allow uart_register/unregister/register
tty: move global ldisc idle waitqueue to the individual ldisc
serial8250-em: Add DT support
serial8250-em: clk_get() IS_ERR() error handling fix
serial_core: Update buffer overrun statistics.
tty: drop the pty lock during hangup
cris: fix missing tty arg in wait_event_interruptible_tty call
tty/amiserial: Add missing argument for tty_unlock()
tty_lock: Localise the lock
pty: Lock the devpts bits privately
tty_lock: undo the old tty_lock use on the ctty
serial8250-em: Emma Mobile UART driver V2
Add missing call to uart_update_timeout()
...
Diffstat (limited to 'drivers')
52 files changed, 1759 insertions, 1778 deletions
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c index d9f5524593fb..8c610fa6782b 100644 --- a/drivers/isdn/i4l/isdn_common.c +++ b/drivers/isdn/i4l/isdn_common.c | |||
@@ -46,7 +46,6 @@ static DEFINE_MUTEX(isdn_mutex); | |||
46 | static char *isdn_revision = "$Revision: 1.1.2.3 $"; | 46 | static char *isdn_revision = "$Revision: 1.1.2.3 $"; |
47 | 47 | ||
48 | extern char *isdn_net_revision; | 48 | extern char *isdn_net_revision; |
49 | extern char *isdn_tty_revision; | ||
50 | #ifdef CONFIG_ISDN_PPP | 49 | #ifdef CONFIG_ISDN_PPP |
51 | extern char *isdn_ppp_revision; | 50 | extern char *isdn_ppp_revision; |
52 | #else | 51 | #else |
@@ -2327,8 +2326,6 @@ static int __init isdn_init(void) | |||
2327 | dev->chanmap[i] = -1; | 2326 | dev->chanmap[i] = -1; |
2328 | dev->m_idx[i] = -1; | 2327 | dev->m_idx[i] = -1; |
2329 | strcpy(dev->num[i], "???"); | 2328 | strcpy(dev->num[i], "???"); |
2330 | init_waitqueue_head(&dev->mdm.info[i].open_wait); | ||
2331 | init_waitqueue_head(&dev->mdm.info[i].close_wait); | ||
2332 | } | 2329 | } |
2333 | if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) { | 2330 | if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) { |
2334 | printk(KERN_WARNING "isdn: Could not register control devices\n"); | 2331 | printk(KERN_WARNING "isdn: Could not register control devices\n"); |
@@ -2353,8 +2350,6 @@ static int __init isdn_init(void) | |||
2353 | 2350 | ||
2354 | strcpy(tmprev, isdn_revision); | 2351 | strcpy(tmprev, isdn_revision); |
2355 | printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev)); | 2352 | printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev)); |
2356 | strcpy(tmprev, isdn_tty_revision); | ||
2357 | printk("%s/", isdn_getrev(tmprev)); | ||
2358 | strcpy(tmprev, isdn_net_revision); | 2353 | strcpy(tmprev, isdn_net_revision); |
2359 | printk("%s/", isdn_getrev(tmprev)); | 2354 | printk("%s/", isdn_getrev(tmprev)); |
2360 | strcpy(tmprev, isdn_ppp_revision); | 2355 | strcpy(tmprev, isdn_ppp_revision); |
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c index 3831abdbc66f..7bc50670d7d9 100644 --- a/drivers/isdn/i4l/isdn_tty.c +++ b/drivers/isdn/i4l/isdn_tty.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* $Id: isdn_tty.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $ | 1 | /* |
2 | * | ||
3 | * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). | 2 | * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). |
4 | * | 3 | * |
5 | * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) | 4 | * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) |
@@ -12,6 +11,7 @@ | |||
12 | #undef ISDN_TTY_STAT_DEBUG | 11 | #undef ISDN_TTY_STAT_DEBUG |
13 | 12 | ||
14 | #include <linux/isdn.h> | 13 | #include <linux/isdn.h> |
14 | #include <linux/serial.h> /* ASYNC_* flags */ | ||
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/mutex.h> | 17 | #include <linux/mutex.h> |
@@ -48,9 +48,6 @@ static int bit2si[8] = | |||
48 | static int si2bit[8] = | 48 | static int si2bit[8] = |
49 | {4, 1, 4, 4, 4, 4, 4, 4}; | 49 | {4, 1, 4, 4, 4, 4, 4, 4}; |
50 | 50 | ||
51 | char *isdn_tty_revision = "$Revision: 1.1.2.3 $"; | ||
52 | |||
53 | |||
54 | /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() | 51 | /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() |
55 | * to stuff incoming data directly into a tty's flip-buffer. This | 52 | * to stuff incoming data directly into a tty's flip-buffer. This |
56 | * is done to speed up tty-receiving if the receive-queue is empty. | 53 | * is done to speed up tty-receiving if the receive-queue is empty. |
@@ -68,49 +65,54 @@ isdn_tty_try_read(modem_info *info, struct sk_buff *skb) | |||
68 | struct tty_struct *tty; | 65 | struct tty_struct *tty; |
69 | char last; | 66 | char last; |
70 | 67 | ||
71 | if (info->online) { | 68 | if (!info->online) |
72 | if ((tty = info->tty)) { | 69 | return 0; |
73 | if (info->mcr & UART_MCR_RTS) { | 70 | |
74 | len = skb->len | 71 | tty = info->port.tty; |
72 | if (!tty) | ||
73 | return 0; | ||
74 | |||
75 | if (!(info->mcr & UART_MCR_RTS)) | ||
76 | return 0; | ||
77 | |||
78 | len = skb->len | ||
75 | #ifdef CONFIG_ISDN_AUDIO | 79 | #ifdef CONFIG_ISDN_AUDIO |
76 | + ISDN_AUDIO_SKB_DLECOUNT(skb) | 80 | + ISDN_AUDIO_SKB_DLECOUNT(skb) |
77 | #endif | 81 | #endif |
78 | ; | 82 | ; |
83 | |||
84 | c = tty_buffer_request_room(tty, len); | ||
85 | if (c < len) | ||
86 | return 0; | ||
79 | 87 | ||
80 | c = tty_buffer_request_room(tty, len); | ||
81 | if (c >= len) { | ||
82 | #ifdef CONFIG_ISDN_AUDIO | ||
83 | if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { | ||
84 | int l = skb->len; | ||
85 | unsigned char *dp = skb->data; | ||
86 | while (--l) { | ||
87 | if (*dp == DLE) | ||
88 | tty_insert_flip_char(tty, DLE, 0); | ||
89 | tty_insert_flip_char(tty, *dp++, 0); | ||
90 | } | ||
91 | if (*dp == DLE) | ||
92 | tty_insert_flip_char(tty, DLE, 0); | ||
93 | last = *dp; | ||
94 | } else { | ||
95 | #endif | ||
96 | if (len > 1) | ||
97 | tty_insert_flip_string(tty, skb->data, len - 1); | ||
98 | last = skb->data[len - 1]; | ||
99 | #ifdef CONFIG_ISDN_AUDIO | 88 | #ifdef CONFIG_ISDN_AUDIO |
100 | } | 89 | if (ISDN_AUDIO_SKB_DLECOUNT(skb)) { |
90 | int l = skb->len; | ||
91 | unsigned char *dp = skb->data; | ||
92 | while (--l) { | ||
93 | if (*dp == DLE) | ||
94 | tty_insert_flip_char(tty, DLE, 0); | ||
95 | tty_insert_flip_char(tty, *dp++, 0); | ||
96 | } | ||
97 | if (*dp == DLE) | ||
98 | tty_insert_flip_char(tty, DLE, 0); | ||
99 | last = *dp; | ||
100 | } else { | ||
101 | #endif | 101 | #endif |
102 | if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) | 102 | if (len > 1) |
103 | tty_insert_flip_char(tty, last, 0xFF); | 103 | tty_insert_flip_string(tty, skb->data, len - 1); |
104 | else | 104 | last = skb->data[len - 1]; |
105 | tty_insert_flip_char(tty, last, TTY_NORMAL); | 105 | #ifdef CONFIG_ISDN_AUDIO |
106 | tty_flip_buffer_push(tty); | ||
107 | kfree_skb(skb); | ||
108 | return 1; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | 106 | } |
113 | return 0; | 107 | #endif |
108 | if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) | ||
109 | tty_insert_flip_char(tty, last, 0xFF); | ||
110 | else | ||
111 | tty_insert_flip_char(tty, last, TTY_NORMAL); | ||
112 | tty_flip_buffer_push(tty); | ||
113 | kfree_skb(skb); | ||
114 | |||
115 | return 1; | ||
114 | } | 116 | } |
115 | 117 | ||
116 | /* isdn_tty_readmodem() is called periodically from within timer-interrupt. | 118 | /* isdn_tty_readmodem() is called periodically from within timer-interrupt. |
@@ -128,35 +130,39 @@ isdn_tty_readmodem(void) | |||
128 | modem_info *info; | 130 | modem_info *info; |
129 | 131 | ||
130 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | 132 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
131 | if ((midx = dev->m_idx[i]) >= 0) { | 133 | midx = dev->m_idx[i]; |
132 | info = &dev->mdm.info[midx]; | 134 | if (midx < 0) |
133 | if (info->online) { | 135 | continue; |
134 | r = 0; | 136 | |
137 | info = &dev->mdm.info[midx]; | ||
138 | if (!info->online) | ||
139 | continue; | ||
140 | |||
141 | r = 0; | ||
135 | #ifdef CONFIG_ISDN_AUDIO | 142 | #ifdef CONFIG_ISDN_AUDIO |
136 | isdn_audio_eval_dtmf(info); | 143 | isdn_audio_eval_dtmf(info); |
137 | if ((info->vonline & 1) && (info->emu.vpar[1])) | 144 | if ((info->vonline & 1) && (info->emu.vpar[1])) |
138 | isdn_audio_eval_silence(info); | 145 | isdn_audio_eval_silence(info); |
139 | #endif | 146 | #endif |
140 | if ((tty = info->tty)) { | 147 | tty = info->port.tty; |
141 | if (info->mcr & UART_MCR_RTS) { | 148 | if (tty) { |
142 | /* CISCO AsyncPPP Hack */ | 149 | if (info->mcr & UART_MCR_RTS) { |
143 | if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) | 150 | /* CISCO AsyncPPP Hack */ |
144 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); | 151 | if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) |
145 | else | 152 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); |
146 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); | 153 | else |
147 | if (r) | 154 | r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); |
148 | tty_flip_buffer_push(tty); | 155 | if (r) |
149 | } else | 156 | tty_flip_buffer_push(tty); |
150 | r = 1; | 157 | } else |
151 | } else | 158 | r = 1; |
152 | r = 1; | 159 | } else |
153 | if (r) { | 160 | r = 1; |
154 | info->rcvsched = 0; | 161 | if (r) { |
155 | resched = 1; | 162 | info->rcvsched = 0; |
156 | } else | 163 | resched = 1; |
157 | info->rcvsched = 1; | 164 | } else |
158 | } | 165 | info->rcvsched = 1; |
159 | } | ||
160 | } | 166 | } |
161 | if (!resched) | 167 | if (!resched) |
162 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); | 168 | isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); |
@@ -294,7 +300,7 @@ isdn_tty_tint(modem_info *info) | |||
294 | len = skb->len; | 300 | len = skb->len; |
295 | if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, | 301 | if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, |
296 | info->isdn_channel, 1, skb)) == len) { | 302 | info->isdn_channel, 1, skb)) == len) { |
297 | struct tty_struct *tty = info->tty; | 303 | struct tty_struct *tty = info->port.tty; |
298 | info->send_outstanding++; | 304 | info->send_outstanding++; |
299 | info->msr &= ~UART_MSR_CTS; | 305 | info->msr &= ~UART_MSR_CTS; |
300 | info->lsr &= ~UART_LSR_TEMT; | 306 | info->lsr &= ~UART_LSR_TEMT; |
@@ -327,7 +333,7 @@ isdn_tty_countDLE(unsigned char *buf, int len) | |||
327 | static int | 333 | static int |
328 | isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) | 334 | isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) |
329 | { | 335 | { |
330 | unsigned char *p = &info->xmit_buf[info->xmit_count]; | 336 | unsigned char *p = &info->port.xmit_buf[info->xmit_count]; |
331 | int count = 0; | 337 | int count = 0; |
332 | 338 | ||
333 | while (len > 0) { | 339 | while (len > 0) { |
@@ -471,7 +477,7 @@ isdn_tty_senddown(modem_info *info) | |||
471 | return; | 477 | return; |
472 | } | 478 | } |
473 | skb_reserve(skb, skb_res); | 479 | skb_reserve(skb, skb_res); |
474 | memcpy(skb_put(skb, buflen), info->xmit_buf, buflen); | 480 | memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen); |
475 | info->xmit_count = 0; | 481 | info->xmit_count = 0; |
476 | #ifdef CONFIG_ISDN_AUDIO | 482 | #ifdef CONFIG_ISDN_AUDIO |
477 | if (info->vonline & 2) { | 483 | if (info->vonline & 2) { |
@@ -699,7 +705,7 @@ isdn_tty_modem_hup(modem_info *info, int local) | |||
699 | printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); | 705 | printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); |
700 | #endif | 706 | #endif |
701 | info->rcvsched = 0; | 707 | info->rcvsched = 0; |
702 | isdn_tty_flush_buffer(info->tty); | 708 | isdn_tty_flush_buffer(info->port.tty); |
703 | if (info->online) { | 709 | if (info->online) { |
704 | info->last_lhup = local; | 710 | info->last_lhup = local; |
705 | info->online = 0; | 711 | info->online = 0; |
@@ -997,20 +1003,21 @@ isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine) | |||
997 | static void | 1003 | static void |
998 | isdn_tty_change_speed(modem_info *info) | 1004 | isdn_tty_change_speed(modem_info *info) |
999 | { | 1005 | { |
1006 | struct tty_port *port = &info->port; | ||
1000 | uint cflag, | 1007 | uint cflag, |
1001 | cval, | 1008 | cval, |
1002 | quot; | 1009 | quot; |
1003 | int i; | 1010 | int i; |
1004 | 1011 | ||
1005 | if (!info->tty || !info->tty->termios) | 1012 | if (!port->tty || !port->tty->termios) |
1006 | return; | 1013 | return; |
1007 | cflag = info->tty->termios->c_cflag; | 1014 | cflag = port->tty->termios->c_cflag; |
1008 | 1015 | ||
1009 | quot = i = cflag & CBAUD; | 1016 | quot = i = cflag & CBAUD; |
1010 | if (i & CBAUDEX) { | 1017 | if (i & CBAUDEX) { |
1011 | i &= ~CBAUDEX; | 1018 | i &= ~CBAUDEX; |
1012 | if (i < 1 || i > 2) | 1019 | if (i < 1 || i > 2) |
1013 | info->tty->termios->c_cflag &= ~CBAUDEX; | 1020 | port->tty->termios->c_cflag &= ~CBAUDEX; |
1014 | else | 1021 | else |
1015 | i += 15; | 1022 | i += 15; |
1016 | } | 1023 | } |
@@ -1040,20 +1047,20 @@ isdn_tty_change_speed(modem_info *info) | |||
1040 | 1047 | ||
1041 | /* CTS flow control flag and modem status interrupts */ | 1048 | /* CTS flow control flag and modem status interrupts */ |
1042 | if (cflag & CRTSCTS) { | 1049 | if (cflag & CRTSCTS) { |
1043 | info->flags |= ISDN_ASYNC_CTS_FLOW; | 1050 | port->flags |= ASYNC_CTS_FLOW; |
1044 | } else | 1051 | } else |
1045 | info->flags &= ~ISDN_ASYNC_CTS_FLOW; | 1052 | port->flags &= ~ASYNC_CTS_FLOW; |
1046 | if (cflag & CLOCAL) | 1053 | if (cflag & CLOCAL) |
1047 | info->flags &= ~ISDN_ASYNC_CHECK_CD; | 1054 | port->flags &= ~ASYNC_CHECK_CD; |
1048 | else { | 1055 | else { |
1049 | info->flags |= ISDN_ASYNC_CHECK_CD; | 1056 | port->flags |= ASYNC_CHECK_CD; |
1050 | } | 1057 | } |
1051 | } | 1058 | } |
1052 | 1059 | ||
1053 | static int | 1060 | static int |
1054 | isdn_tty_startup(modem_info *info) | 1061 | isdn_tty_startup(modem_info *info) |
1055 | { | 1062 | { |
1056 | if (info->flags & ISDN_ASYNC_INITIALIZED) | 1063 | if (info->port.flags & ASYNC_INITIALIZED) |
1057 | return 0; | 1064 | return 0; |
1058 | isdn_lock_drivers(); | 1065 | isdn_lock_drivers(); |
1059 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1066 | #ifdef ISDN_DEBUG_MODEM_OPEN |
@@ -1063,14 +1070,14 @@ isdn_tty_startup(modem_info *info) | |||
1063 | * Now, initialize the UART | 1070 | * Now, initialize the UART |
1064 | */ | 1071 | */ |
1065 | info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; | 1072 | info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; |
1066 | if (info->tty) | 1073 | if (info->port.tty) |
1067 | clear_bit(TTY_IO_ERROR, &info->tty->flags); | 1074 | clear_bit(TTY_IO_ERROR, &info->port.tty->flags); |
1068 | /* | 1075 | /* |
1069 | * and set the speed of the serial port | 1076 | * and set the speed of the serial port |
1070 | */ | 1077 | */ |
1071 | isdn_tty_change_speed(info); | 1078 | isdn_tty_change_speed(info); |
1072 | 1079 | ||
1073 | info->flags |= ISDN_ASYNC_INITIALIZED; | 1080 | info->port.flags |= ASYNC_INITIALIZED; |
1074 | info->msr |= (UART_MSR_DSR | UART_MSR_CTS); | 1081 | info->msr |= (UART_MSR_DSR | UART_MSR_CTS); |
1075 | info->send_outstanding = 0; | 1082 | info->send_outstanding = 0; |
1076 | return 0; | 1083 | return 0; |
@@ -1083,14 +1090,14 @@ isdn_tty_startup(modem_info *info) | |||
1083 | static void | 1090 | static void |
1084 | isdn_tty_shutdown(modem_info *info) | 1091 | isdn_tty_shutdown(modem_info *info) |
1085 | { | 1092 | { |
1086 | if (!(info->flags & ISDN_ASYNC_INITIALIZED)) | 1093 | if (!(info->port.flags & ASYNC_INITIALIZED)) |
1087 | return; | 1094 | return; |
1088 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1095 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1089 | printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); | 1096 | printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); |
1090 | #endif | 1097 | #endif |
1091 | isdn_unlock_drivers(); | 1098 | isdn_unlock_drivers(); |
1092 | info->msr &= ~UART_MSR_RI; | 1099 | info->msr &= ~UART_MSR_RI; |
1093 | if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { | 1100 | if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) { |
1094 | info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); | 1101 | info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); |
1095 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { | 1102 | if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { |
1096 | isdn_tty_modem_reset_regs(info, 0); | 1103 | isdn_tty_modem_reset_regs(info, 0); |
@@ -1100,10 +1107,10 @@ isdn_tty_shutdown(modem_info *info) | |||
1100 | isdn_tty_modem_hup(info, 1); | 1107 | isdn_tty_modem_hup(info, 1); |
1101 | } | 1108 | } |
1102 | } | 1109 | } |
1103 | if (info->tty) | 1110 | if (info->port.tty) |
1104 | set_bit(TTY_IO_ERROR, &info->tty->flags); | 1111 | set_bit(TTY_IO_ERROR, &info->port.tty->flags); |
1105 | 1112 | ||
1106 | info->flags &= ~ISDN_ASYNC_INITIALIZED; | 1113 | info->port.flags &= ~ASYNC_INITIALIZED; |
1107 | } | 1114 | } |
1108 | 1115 | ||
1109 | /* isdn_tty_write() is the main send-routine. It is called from the upper | 1116 | /* isdn_tty_write() is the main send-routine. It is called from the upper |
@@ -1146,7 +1153,7 @@ isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count) | |||
1146 | isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, | 1153 | isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, |
1147 | &(m->pluscount), | 1154 | &(m->pluscount), |
1148 | &(m->lastplus)); | 1155 | &(m->lastplus)); |
1149 | memcpy(&(info->xmit_buf[info->xmit_count]), buf, c); | 1156 | memcpy(&info->port.xmit_buf[info->xmit_count], buf, c); |
1150 | #ifdef CONFIG_ISDN_AUDIO | 1157 | #ifdef CONFIG_ISDN_AUDIO |
1151 | if (info->vonline) { | 1158 | if (info->vonline) { |
1152 | int cc = isdn_tty_handleDLEdown(info, m, c); | 1159 | int cc = isdn_tty_handleDLEdown(info, m, c); |
@@ -1478,107 +1485,6 @@ isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) | |||
1478 | * isdn_tty_open() and friends | 1485 | * isdn_tty_open() and friends |
1479 | * ------------------------------------------------------------ | 1486 | * ------------------------------------------------------------ |
1480 | */ | 1487 | */ |
1481 | static int | ||
1482 | isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info *info) | ||
1483 | { | ||
1484 | DECLARE_WAITQUEUE(wait, NULL); | ||
1485 | int do_clocal = 0; | ||
1486 | int retval; | ||
1487 | |||
1488 | /* | ||
1489 | * If the device is in the middle of being closed, then block | ||
1490 | * until it's done, and then try again. | ||
1491 | */ | ||
1492 | if (tty_hung_up_p(filp) || | ||
1493 | (info->flags & ISDN_ASYNC_CLOSING)) { | ||
1494 | if (info->flags & ISDN_ASYNC_CLOSING) | ||
1495 | interruptible_sleep_on(&info->close_wait); | ||
1496 | #ifdef MODEM_DO_RESTART | ||
1497 | if (info->flags & ISDN_ASYNC_HUP_NOTIFY) | ||
1498 | return -EAGAIN; | ||
1499 | else | ||
1500 | return -ERESTARTSYS; | ||
1501 | #else | ||
1502 | return -EAGAIN; | ||
1503 | #endif | ||
1504 | } | ||
1505 | /* | ||
1506 | * If non-blocking mode is set, then make the check up front | ||
1507 | * and then exit. | ||
1508 | */ | ||
1509 | if ((filp->f_flags & O_NONBLOCK) || | ||
1510 | (tty->flags & (1 << TTY_IO_ERROR))) { | ||
1511 | if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) | ||
1512 | return -EBUSY; | ||
1513 | info->flags |= ISDN_ASYNC_NORMAL_ACTIVE; | ||
1514 | return 0; | ||
1515 | } | ||
1516 | if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) { | ||
1517 | if (info->normal_termios.c_cflag & CLOCAL) | ||
1518 | do_clocal = 1; | ||
1519 | } else { | ||
1520 | if (tty->termios->c_cflag & CLOCAL) | ||
1521 | do_clocal = 1; | ||
1522 | } | ||
1523 | /* | ||
1524 | * Block waiting for the carrier detect and the line to become | ||
1525 | * free (i.e., not in use by the callout). While we are in | ||
1526 | * this loop, info->count is dropped by one, so that | ||
1527 | * isdn_tty_close() knows when to free things. We restore it upon | ||
1528 | * exit, either normal or abnormal. | ||
1529 | */ | ||
1530 | retval = 0; | ||
1531 | add_wait_queue(&info->open_wait, &wait); | ||
1532 | #ifdef ISDN_DEBUG_MODEM_OPEN | ||
1533 | printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n", | ||
1534 | info->line, info->count); | ||
1535 | #endif | ||
1536 | if (!(tty_hung_up_p(filp))) | ||
1537 | info->count--; | ||
1538 | info->blocked_open++; | ||
1539 | while (1) { | ||
1540 | set_current_state(TASK_INTERRUPTIBLE); | ||
1541 | if (tty_hung_up_p(filp) || | ||
1542 | !(info->flags & ISDN_ASYNC_INITIALIZED)) { | ||
1543 | #ifdef MODEM_DO_RESTART | ||
1544 | if (info->flags & ISDN_ASYNC_HUP_NOTIFY) | ||
1545 | retval = -EAGAIN; | ||
1546 | else | ||
1547 | retval = -ERESTARTSYS; | ||
1548 | #else | ||
1549 | retval = -EAGAIN; | ||
1550 | #endif | ||
1551 | break; | ||
1552 | } | ||
1553 | if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) && | ||
1554 | !(info->flags & ISDN_ASYNC_CLOSING) && | ||
1555 | (do_clocal || (info->msr & UART_MSR_DCD))) { | ||
1556 | break; | ||
1557 | } | ||
1558 | if (signal_pending(current)) { | ||
1559 | retval = -ERESTARTSYS; | ||
1560 | break; | ||
1561 | } | ||
1562 | #ifdef ISDN_DEBUG_MODEM_OPEN | ||
1563 | printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n", | ||
1564 | info->line, info->count); | ||
1565 | #endif | ||
1566 | schedule(); | ||
1567 | } | ||
1568 | current->state = TASK_RUNNING; | ||
1569 | remove_wait_queue(&info->open_wait, &wait); | ||
1570 | if (!tty_hung_up_p(filp)) | ||
1571 | info->count++; | ||
1572 | info->blocked_open--; | ||
1573 | #ifdef ISDN_DEBUG_MODEM_OPEN | ||
1574 | printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n", | ||
1575 | info->line, info->count); | ||
1576 | #endif | ||
1577 | if (retval) | ||
1578 | return retval; | ||
1579 | info->flags |= ISDN_ASYNC_NORMAL_ACTIVE; | ||
1580 | return 0; | ||
1581 | } | ||
1582 | 1488 | ||
1583 | /* | 1489 | /* |
1584 | * This routine is called whenever a serial port is opened. It | 1490 | * This routine is called whenever a serial port is opened. It |
@@ -1589,23 +1495,22 @@ isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info * | |||
1589 | static int | 1495 | static int |
1590 | isdn_tty_open(struct tty_struct *tty, struct file *filp) | 1496 | isdn_tty_open(struct tty_struct *tty, struct file *filp) |
1591 | { | 1497 | { |
1498 | struct tty_port *port; | ||
1592 | modem_info *info; | 1499 | modem_info *info; |
1593 | int retval; | 1500 | int retval; |
1594 | 1501 | ||
1595 | info = &dev->mdm.info[tty->index]; | 1502 | info = &dev->mdm.info[tty->index]; |
1596 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) | 1503 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) |
1597 | return -ENODEV; | 1504 | return -ENODEV; |
1598 | if (!try_module_get(info->owner)) { | 1505 | port = &info->port; |
1599 | printk(KERN_WARNING "%s: cannot reserve module\n", __func__); | ||
1600 | return -ENODEV; | ||
1601 | } | ||
1602 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1506 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1603 | printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, | 1507 | printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, |
1604 | info->count); | 1508 | port->count); |
1605 | #endif | 1509 | #endif |
1606 | info->count++; | 1510 | port->count++; |
1607 | tty->driver_data = info; | 1511 | tty->driver_data = info; |
1608 | info->tty = tty; | 1512 | port->tty = tty; |
1513 | tty->port = port; | ||
1609 | /* | 1514 | /* |
1610 | * Start up serial port | 1515 | * Start up serial port |
1611 | */ | 1516 | */ |
@@ -1614,15 +1519,13 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp) | |||
1614 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1519 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1615 | printk(KERN_DEBUG "isdn_tty_open return after startup\n"); | 1520 | printk(KERN_DEBUG "isdn_tty_open return after startup\n"); |
1616 | #endif | 1521 | #endif |
1617 | module_put(info->owner); | ||
1618 | return retval; | 1522 | return retval; |
1619 | } | 1523 | } |
1620 | retval = isdn_tty_block_til_ready(tty, filp, info); | 1524 | retval = tty_port_block_til_ready(port, tty, filp); |
1621 | if (retval) { | 1525 | if (retval) { |
1622 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1526 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1623 | printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); | 1527 | printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); |
1624 | #endif | 1528 | #endif |
1625 | module_put(info->owner); | ||
1626 | return retval; | 1529 | return retval; |
1627 | } | 1530 | } |
1628 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1531 | #ifdef ISDN_DEBUG_MODEM_OPEN |
@@ -1639,6 +1542,7 @@ static void | |||
1639 | isdn_tty_close(struct tty_struct *tty, struct file *filp) | 1542 | isdn_tty_close(struct tty_struct *tty, struct file *filp) |
1640 | { | 1543 | { |
1641 | modem_info *info = (modem_info *) tty->driver_data; | 1544 | modem_info *info = (modem_info *) tty->driver_data; |
1545 | struct tty_port *port = &info->port; | ||
1642 | ulong timeout; | 1546 | ulong timeout; |
1643 | 1547 | ||
1644 | if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) | 1548 | if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) |
@@ -1649,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp) | |||
1649 | #endif | 1553 | #endif |
1650 | return; | 1554 | return; |
1651 | } | 1555 | } |
1652 | if ((tty->count == 1) && (info->count != 1)) { | 1556 | if ((tty->count == 1) && (port->count != 1)) { |
1653 | /* | 1557 | /* |
1654 | * Uh, oh. tty->count is 1, which means that the tty | 1558 | * Uh, oh. tty->count is 1, which means that the tty |
1655 | * structure will be freed. Info->count should always | 1559 | * structure will be freed. Info->count should always |
@@ -1658,30 +1562,21 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp) | |||
1658 | * serial port won't be shutdown. | 1562 | * serial port won't be shutdown. |
1659 | */ | 1563 | */ |
1660 | printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " | 1564 | printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " |
1661 | "info->count is %d\n", info->count); | 1565 | "info->count is %d\n", port->count); |
1662 | info->count = 1; | 1566 | port->count = 1; |
1663 | } | 1567 | } |
1664 | if (--info->count < 0) { | 1568 | if (--port->count < 0) { |
1665 | printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", | 1569 | printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", |
1666 | info->line, info->count); | 1570 | info->line, port->count); |
1667 | info->count = 0; | 1571 | port->count = 0; |
1668 | } | 1572 | } |
1669 | if (info->count) { | 1573 | if (port->count) { |
1670 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1574 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1671 | printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); | 1575 | printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); |
1672 | #endif | 1576 | #endif |
1673 | module_put(info->owner); | ||
1674 | return; | 1577 | return; |
1675 | } | 1578 | } |
1676 | info->flags |= ISDN_ASYNC_CLOSING; | 1579 | port->flags |= ASYNC_CLOSING; |
1677 | /* | ||
1678 | * Save the termios structure, since this port may have | ||
1679 | * separate termios for callout and dialin. | ||
1680 | */ | ||
1681 | if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) | ||
1682 | info->normal_termios = *tty->termios; | ||
1683 | if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) | ||
1684 | info->callout_termios = *tty->termios; | ||
1685 | 1580 | ||
1686 | tty->closing = 1; | 1581 | tty->closing = 1; |
1687 | /* | 1582 | /* |
@@ -1690,7 +1585,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp) | |||
1690 | * interrupt driver to stop checking the data ready bit in the | 1585 | * interrupt driver to stop checking the data ready bit in the |
1691 | * line status register. | 1586 | * line status register. |
1692 | */ | 1587 | */ |
1693 | if (info->flags & ISDN_ASYNC_INITIALIZED) { | 1588 | if (port->flags & ASYNC_INITIALIZED) { |
1694 | tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ | 1589 | tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ |
1695 | /* | 1590 | /* |
1696 | * Before we drop DTR, make sure the UART transmitter | 1591 | * Before we drop DTR, make sure the UART transmitter |
@@ -1708,16 +1603,10 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp) | |||
1708 | isdn_tty_shutdown(info); | 1603 | isdn_tty_shutdown(info); |
1709 | isdn_tty_flush_buffer(tty); | 1604 | isdn_tty_flush_buffer(tty); |
1710 | tty_ldisc_flush(tty); | 1605 | tty_ldisc_flush(tty); |
1711 | info->tty = NULL; | 1606 | port->tty = NULL; |
1712 | info->ncarrier = 0; | 1607 | info->ncarrier = 0; |
1713 | tty->closing = 0; | 1608 | |
1714 | module_put(info->owner); | 1609 | tty_port_close_end(port, tty); |
1715 | if (info->blocked_open) { | ||
1716 | msleep_interruptible(500); | ||
1717 | wake_up_interruptible(&info->open_wait); | ||
1718 | } | ||
1719 | info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CLOSING); | ||
1720 | wake_up_interruptible(&info->close_wait); | ||
1721 | #ifdef ISDN_DEBUG_MODEM_OPEN | 1610 | #ifdef ISDN_DEBUG_MODEM_OPEN |
1722 | printk(KERN_DEBUG "isdn_tty_close normal exit\n"); | 1611 | printk(KERN_DEBUG "isdn_tty_close normal exit\n"); |
1723 | #endif | 1612 | #endif |
@@ -1730,14 +1619,15 @@ static void | |||
1730 | isdn_tty_hangup(struct tty_struct *tty) | 1619 | isdn_tty_hangup(struct tty_struct *tty) |
1731 | { | 1620 | { |
1732 | modem_info *info = (modem_info *) tty->driver_data; | 1621 | modem_info *info = (modem_info *) tty->driver_data; |
1622 | struct tty_port *port = &info->port; | ||
1733 | 1623 | ||
1734 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) | 1624 | if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) |
1735 | return; | 1625 | return; |
1736 | isdn_tty_shutdown(info); | 1626 | isdn_tty_shutdown(info); |
1737 | info->count = 0; | 1627 | port->count = 0; |
1738 | info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE); | 1628 | port->flags &= ~ASYNC_NORMAL_ACTIVE; |
1739 | info->tty = NULL; | 1629 | port->tty = NULL; |
1740 | wake_up_interruptible(&info->open_wait); | 1630 | wake_up_interruptible(&port->open_wait); |
1741 | } | 1631 | } |
1742 | 1632 | ||
1743 | /* This routine initializes all emulator-data. | 1633 | /* This routine initializes all emulator-data. |
@@ -1864,6 +1754,16 @@ static const struct tty_operations modem_ops = { | |||
1864 | .tiocmset = isdn_tty_tiocmset, | 1754 | .tiocmset = isdn_tty_tiocmset, |
1865 | }; | 1755 | }; |
1866 | 1756 | ||
1757 | static int isdn_tty_carrier_raised(struct tty_port *port) | ||
1758 | { | ||
1759 | modem_info *info = container_of(port, modem_info, port); | ||
1760 | return info->msr & UART_MSR_DCD; | ||
1761 | } | ||
1762 | |||
1763 | static const struct tty_port_operations isdn_tty_port_ops = { | ||
1764 | .carrier_raised = isdn_tty_carrier_raised, | ||
1765 | }; | ||
1766 | |||
1867 | int | 1767 | int |
1868 | isdn_tty_modem_init(void) | 1768 | isdn_tty_modem_init(void) |
1869 | { | 1769 | { |
@@ -1899,9 +1799,8 @@ isdn_tty_modem_init(void) | |||
1899 | goto err_unregister; | 1799 | goto err_unregister; |
1900 | } | 1800 | } |
1901 | #endif | 1801 | #endif |
1902 | #ifdef MODULE | 1802 | tty_port_init(&info->port); |
1903 | info->owner = THIS_MODULE; | 1803 | info->port.ops = &isdn_tty_port_ops; |
1904 | #endif | ||
1905 | spin_lock_init(&info->readlock); | 1804 | spin_lock_init(&info->readlock); |
1906 | sprintf(info->last_cause, "0000"); | 1805 | sprintf(info->last_cause, "0000"); |
1907 | sprintf(info->last_num, "none"); | 1806 | sprintf(info->last_num, "none"); |
@@ -1913,12 +1812,7 @@ isdn_tty_modem_init(void) | |||
1913 | isdn_tty_modem_reset_regs(info, 1); | 1812 | isdn_tty_modem_reset_regs(info, 1); |
1914 | info->magic = ISDN_ASYNC_MAGIC; | 1813 | info->magic = ISDN_ASYNC_MAGIC; |
1915 | info->line = i; | 1814 | info->line = i; |
1916 | info->tty = NULL; | ||
1917 | info->x_char = 0; | 1815 | info->x_char = 0; |
1918 | info->count = 0; | ||
1919 | info->blocked_open = 0; | ||
1920 | init_waitqueue_head(&info->open_wait); | ||
1921 | init_waitqueue_head(&info->close_wait); | ||
1922 | info->isdn_driver = -1; | 1816 | info->isdn_driver = -1; |
1923 | info->isdn_channel = -1; | 1817 | info->isdn_channel = -1; |
1924 | info->drv_index = -1; | 1818 | info->drv_index = -1; |
@@ -1930,13 +1824,15 @@ isdn_tty_modem_init(void) | |||
1930 | #ifdef CONFIG_ISDN_AUDIO | 1824 | #ifdef CONFIG_ISDN_AUDIO |
1931 | skb_queue_head_init(&info->dtmf_queue); | 1825 | skb_queue_head_init(&info->dtmf_queue); |
1932 | #endif | 1826 | #endif |
1933 | if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) { | 1827 | info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, |
1828 | GFP_KERNEL); | ||
1829 | if (!info->port.xmit_buf) { | ||
1934 | printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); | 1830 | printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); |
1935 | retval = -ENOMEM; | 1831 | retval = -ENOMEM; |
1936 | goto err_unregister; | 1832 | goto err_unregister; |
1937 | } | 1833 | } |
1938 | /* Make room for T.70 header */ | 1834 | /* Make room for T.70 header */ |
1939 | info->xmit_buf += 4; | 1835 | info->port.xmit_buf += 4; |
1940 | } | 1836 | } |
1941 | return 0; | 1837 | return 0; |
1942 | err_unregister: | 1838 | err_unregister: |
@@ -1945,7 +1841,7 @@ err_unregister: | |||
1945 | #ifdef CONFIG_ISDN_TTY_FAX | 1841 | #ifdef CONFIG_ISDN_TTY_FAX |
1946 | kfree(info->fax); | 1842 | kfree(info->fax); |
1947 | #endif | 1843 | #endif |
1948 | kfree(info->xmit_buf - 4); | 1844 | kfree(info->port.xmit_buf - 4); |
1949 | } | 1845 | } |
1950 | tty_unregister_driver(m->tty_modem); | 1846 | tty_unregister_driver(m->tty_modem); |
1951 | err: | 1847 | err: |
@@ -1966,7 +1862,7 @@ isdn_tty_exit(void) | |||
1966 | #ifdef CONFIG_ISDN_TTY_FAX | 1862 | #ifdef CONFIG_ISDN_TTY_FAX |
1967 | kfree(info->fax); | 1863 | kfree(info->fax); |
1968 | #endif | 1864 | #endif |
1969 | kfree(info->xmit_buf - 4); | 1865 | kfree(info->port.xmit_buf - 4); |
1970 | } | 1866 | } |
1971 | tty_unregister_driver(dev->mdm.tty_modem); | 1867 | tty_unregister_driver(dev->mdm.tty_modem); |
1972 | put_tty_driver(dev->mdm.tty_modem); | 1868 | put_tty_driver(dev->mdm.tty_modem); |
@@ -2068,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup) | |||
2068 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | 1964 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
2069 | modem_info *info = &dev->mdm.info[i]; | 1965 | modem_info *info = &dev->mdm.info[i]; |
2070 | 1966 | ||
2071 | if (info->count == 0) | 1967 | if (info->port.count == 0) |
2072 | continue; | 1968 | continue; |
2073 | if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ | 1969 | if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ |
2074 | (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ | 1970 | (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ |
@@ -2076,12 +1972,12 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup) | |||
2076 | #ifdef ISDN_DEBUG_MODEM_ICALL | 1972 | #ifdef ISDN_DEBUG_MODEM_ICALL |
2077 | printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); | 1973 | printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); |
2078 | printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, | 1974 | printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, |
2079 | info->flags, info->isdn_driver, info->isdn_channel, | 1975 | info->port.flags, info->isdn_driver, |
2080 | dev->usage[idx]); | 1976 | info->isdn_channel, dev->usage[idx]); |
2081 | #endif | 1977 | #endif |
2082 | if ( | 1978 | if ( |
2083 | #ifndef FIX_FILE_TRANSFER | 1979 | #ifndef FIX_FILE_TRANSFER |
2084 | (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) && | 1980 | (info->port.flags & ASYNC_NORMAL_ACTIVE) && |
2085 | #endif | 1981 | #endif |
2086 | (info->isdn_driver == -1) && | 1982 | (info->isdn_driver == -1) && |
2087 | (info->isdn_channel == -1) && | 1983 | (info->isdn_channel == -1) && |
@@ -2120,8 +2016,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup) | |||
2120 | return (wret == 2) ? 3 : 0; | 2016 | return (wret == 2) ? 3 : 0; |
2121 | } | 2017 | } |
2122 | 2018 | ||
2123 | #define TTY_IS_ACTIVE(info) \ | 2019 | #define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE) |
2124 | (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE)) | ||
2125 | 2020 | ||
2126 | int | 2021 | int |
2127 | isdn_tty_stat_callback(int i, isdn_ctrl *c) | 2022 | isdn_tty_stat_callback(int i, isdn_ctrl *c) |
@@ -2212,9 +2107,9 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c) | |||
2212 | * for incoming call of this device when | 2107 | * for incoming call of this device when |
2213 | * DCD follow the state of incoming carrier | 2108 | * DCD follow the state of incoming carrier |
2214 | */ | 2109 | */ |
2215 | if (info->blocked_open && | 2110 | if (info->port.blocked_open && |
2216 | (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { | 2111 | (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { |
2217 | wake_up_interruptible(&info->open_wait); | 2112 | wake_up_interruptible(&info->port.open_wait); |
2218 | } | 2113 | } |
2219 | 2114 | ||
2220 | /* Schedule CONNECT-Message to any tty | 2115 | /* Schedule CONNECT-Message to any tty |
@@ -2222,7 +2117,8 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c) | |||
2222 | * set DCD-bit of its modem-status. | 2117 | * set DCD-bit of its modem-status. |
2223 | */ | 2118 | */ |
2224 | if (TTY_IS_ACTIVE(info) || | 2119 | if (TTY_IS_ACTIVE(info) || |
2225 | (info->blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { | 2120 | (info->port.blocked_open && |
2121 | (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { | ||
2226 | info->msr |= UART_MSR_DCD; | 2122 | info->msr |= UART_MSR_DCD; |
2227 | info->emu.charge = 0; | 2123 | info->emu.charge = 0; |
2228 | if (info->dialing & 0xf) | 2124 | if (info->dialing & 0xf) |
@@ -2339,8 +2235,8 @@ isdn_tty_at_cout(char *msg, modem_info *info) | |||
2339 | l = strlen(msg); | 2235 | l = strlen(msg); |
2340 | 2236 | ||
2341 | spin_lock_irqsave(&info->readlock, flags); | 2237 | spin_lock_irqsave(&info->readlock, flags); |
2342 | tty = info->tty; | 2238 | tty = info->port.tty; |
2343 | if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) { | 2239 | if ((info->port.flags & ASYNC_CLOSING) || (!tty)) { |
2344 | spin_unlock_irqrestore(&info->readlock, flags); | 2240 | spin_unlock_irqrestore(&info->readlock, flags); |
2345 | return; | 2241 | return; |
2346 | } | 2242 | } |
@@ -2490,15 +2386,15 @@ isdn_tty_modem_result(int code, modem_info *info) | |||
2490 | case RESULT_NO_CARRIER: | 2386 | case RESULT_NO_CARRIER: |
2491 | #ifdef ISDN_DEBUG_MODEM_HUP | 2387 | #ifdef ISDN_DEBUG_MODEM_HUP |
2492 | printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", | 2388 | printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", |
2493 | (info->flags & ISDN_ASYNC_CLOSING), | 2389 | (info->port.flags & ASYNC_CLOSING), |
2494 | (!info->tty)); | 2390 | (!info->port.tty)); |
2495 | #endif | 2391 | #endif |
2496 | m->mdmreg[REG_RINGCNT] = 0; | 2392 | m->mdmreg[REG_RINGCNT] = 0; |
2497 | del_timer(&info->nc_timer); | 2393 | del_timer(&info->nc_timer); |
2498 | info->ncarrier = 0; | 2394 | info->ncarrier = 0; |
2499 | if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) { | 2395 | if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) |
2500 | return; | 2396 | return; |
2501 | } | 2397 | |
2502 | #ifdef CONFIG_ISDN_AUDIO | 2398 | #ifdef CONFIG_ISDN_AUDIO |
2503 | if (info->vonline & 1) { | 2399 | if (info->vonline & 1) { |
2504 | #ifdef ISDN_DEBUG_MODEM_VOICE | 2400 | #ifdef ISDN_DEBUG_MODEM_VOICE |
@@ -2629,14 +2525,11 @@ isdn_tty_modem_result(int code, modem_info *info) | |||
2629 | } | 2525 | } |
2630 | } | 2526 | } |
2631 | if (code == RESULT_NO_CARRIER) { | 2527 | if (code == RESULT_NO_CARRIER) { |
2632 | if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) { | 2528 | if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty)) |
2633 | return; | 2529 | return; |
2634 | } | 2530 | |
2635 | if ((info->flags & ISDN_ASYNC_CHECK_CD) && | 2531 | if (info->port.flags & ASYNC_CHECK_CD) |
2636 | (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) && | 2532 | tty_hangup(info->port.tty); |
2637 | (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) { | ||
2638 | tty_hangup(info->tty); | ||
2639 | } | ||
2640 | } | 2533 | } |
2641 | } | 2534 | } |
2642 | 2535 | ||
@@ -3803,19 +3696,19 @@ isdn_tty_modem_escape(void) | |||
3803 | int midx; | 3696 | int midx; |
3804 | 3697 | ||
3805 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) | 3698 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) |
3806 | if (USG_MODEM(dev->usage[i])) | 3699 | if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) { |
3807 | if ((midx = dev->m_idx[i]) >= 0) { | 3700 | modem_info *info = &dev->mdm.info[midx]; |
3808 | modem_info *info = &dev->mdm.info[midx]; | 3701 | if (info->online) { |
3809 | if (info->online) { | 3702 | ton = 1; |
3810 | ton = 1; | 3703 | if ((info->emu.pluscount == 3) && |
3811 | if ((info->emu.pluscount == 3) && | 3704 | time_after(jiffies, |
3812 | time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) { | 3705 | info->emu.lastplus + PLUSWAIT2)) { |
3813 | info->emu.pluscount = 0; | 3706 | info->emu.pluscount = 0; |
3814 | info->online = 0; | 3707 | info->online = 0; |
3815 | isdn_tty_modem_result(RESULT_OK, info); | 3708 | isdn_tty_modem_result(RESULT_OK, info); |
3816 | } | ||
3817 | } | 3709 | } |
3818 | } | 3710 | } |
3711 | } | ||
3819 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); | 3712 | isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); |
3820 | } | 3713 | } |
3821 | 3714 | ||
@@ -3873,15 +3766,14 @@ isdn_tty_carrier_timeout(void) | |||
3873 | 3766 | ||
3874 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { | 3767 | for (i = 0; i < ISDN_MAX_CHANNELS; i++) { |
3875 | modem_info *info = &dev->mdm.info[i]; | 3768 | modem_info *info = &dev->mdm.info[i]; |
3876 | if (info->dialing) { | 3769 | if (!info->dialing) |
3877 | if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { | 3770 | continue; |
3878 | info->dialing = 0; | 3771 | if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { |
3879 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); | 3772 | info->dialing = 0; |
3880 | isdn_tty_modem_hup(info, 1); | 3773 | isdn_tty_modem_result(RESULT_NO_CARRIER, info); |
3881 | } | 3774 | isdn_tty_modem_hup(info, 1); |
3882 | else | 3775 | } else |
3883 | ton = 1; | 3776 | ton = 1; |
3884 | } | ||
3885 | } | 3777 | } |
3886 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); | 3778 | isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); |
3887 | } | 3779 | } |
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index 042c1a99520f..62f30b46fa42 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c | |||
@@ -106,13 +106,6 @@ | |||
106 | 106 | ||
107 | #define MAX_RX_URBS 2 | 107 | #define MAX_RX_URBS 2 |
108 | 108 | ||
109 | static inline struct hso_serial *get_serial_by_tty(struct tty_struct *tty) | ||
110 | { | ||
111 | if (tty) | ||
112 | return tty->driver_data; | ||
113 | return NULL; | ||
114 | } | ||
115 | |||
116 | /*****************************************************************************/ | 109 | /*****************************************************************************/ |
117 | /* Debugging functions */ | 110 | /* Debugging functions */ |
118 | /*****************************************************************************/ | 111 | /*****************************************************************************/ |
@@ -255,9 +248,8 @@ struct hso_serial { | |||
255 | u8 dtr_state; | 248 | u8 dtr_state; |
256 | unsigned tx_urb_used:1; | 249 | unsigned tx_urb_used:1; |
257 | 250 | ||
251 | struct tty_port port; | ||
258 | /* from usb_serial_port */ | 252 | /* from usb_serial_port */ |
259 | struct tty_struct *tty; | ||
260 | int open_count; | ||
261 | spinlock_t serial_lock; | 253 | spinlock_t serial_lock; |
262 | 254 | ||
263 | int (*write_data) (struct hso_serial *serial); | 255 | int (*write_data) (struct hso_serial *serial); |
@@ -1114,7 +1106,7 @@ static void hso_init_termios(struct ktermios *termios) | |||
1114 | static void _hso_serial_set_termios(struct tty_struct *tty, | 1106 | static void _hso_serial_set_termios(struct tty_struct *tty, |
1115 | struct ktermios *old) | 1107 | struct ktermios *old) |
1116 | { | 1108 | { |
1117 | struct hso_serial *serial = get_serial_by_tty(tty); | 1109 | struct hso_serial *serial = tty->driver_data; |
1118 | struct ktermios *termios; | 1110 | struct ktermios *termios; |
1119 | 1111 | ||
1120 | if (!serial) { | 1112 | if (!serial) { |
@@ -1190,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial) | |||
1190 | struct urb *urb; | 1182 | struct urb *urb; |
1191 | 1183 | ||
1192 | urb = serial->rx_urb[0]; | 1184 | urb = serial->rx_urb[0]; |
1193 | if (serial->open_count > 0) { | 1185 | if (serial->port.count > 0) { |
1194 | count = put_rxbuf_data(urb, serial); | 1186 | count = put_rxbuf_data(urb, serial); |
1195 | if (count == -1) | 1187 | if (count == -1) |
1196 | return; | 1188 | return; |
@@ -1226,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb) | |||
1226 | DUMP1(urb->transfer_buffer, urb->actual_length); | 1218 | DUMP1(urb->transfer_buffer, urb->actual_length); |
1227 | 1219 | ||
1228 | /* Anyone listening? */ | 1220 | /* Anyone listening? */ |
1229 | if (serial->open_count == 0) | 1221 | if (serial->port.count == 0) |
1230 | return; | 1222 | return; |
1231 | 1223 | ||
1232 | if (status == 0) { | 1224 | if (status == 0) { |
@@ -1268,7 +1260,7 @@ static void hso_unthrottle_tasklet(struct hso_serial *serial) | |||
1268 | 1260 | ||
1269 | static void hso_unthrottle(struct tty_struct *tty) | 1261 | static void hso_unthrottle(struct tty_struct *tty) |
1270 | { | 1262 | { |
1271 | struct hso_serial *serial = get_serial_by_tty(tty); | 1263 | struct hso_serial *serial = tty->driver_data; |
1272 | 1264 | ||
1273 | tasklet_hi_schedule(&serial->unthrottle_tasklet); | 1265 | tasklet_hi_schedule(&serial->unthrottle_tasklet); |
1274 | } | 1266 | } |
@@ -1304,15 +1296,12 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp) | |||
1304 | kref_get(&serial->parent->ref); | 1296 | kref_get(&serial->parent->ref); |
1305 | 1297 | ||
1306 | /* setup */ | 1298 | /* setup */ |
1307 | spin_lock_irq(&serial->serial_lock); | ||
1308 | tty->driver_data = serial; | 1299 | tty->driver_data = serial; |
1309 | tty_kref_put(serial->tty); | 1300 | tty_port_tty_set(&serial->port, tty); |
1310 | serial->tty = tty_kref_get(tty); | ||
1311 | spin_unlock_irq(&serial->serial_lock); | ||
1312 | 1301 | ||
1313 | /* check for port already opened, if not set the termios */ | 1302 | /* check for port already opened, if not set the termios */ |
1314 | serial->open_count++; | 1303 | serial->port.count++; |
1315 | if (serial->open_count == 1) { | 1304 | if (serial->port.count == 1) { |
1316 | serial->rx_state = RX_IDLE; | 1305 | serial->rx_state = RX_IDLE; |
1317 | /* Force default termio settings */ | 1306 | /* Force default termio settings */ |
1318 | _hso_serial_set_termios(tty, NULL); | 1307 | _hso_serial_set_termios(tty, NULL); |
@@ -1324,7 +1313,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp) | |||
1324 | result = hso_start_serial_device(serial->parent, GFP_KERNEL); | 1313 | result = hso_start_serial_device(serial->parent, GFP_KERNEL); |
1325 | if (result) { | 1314 | if (result) { |
1326 | hso_stop_serial_device(serial->parent); | 1315 | hso_stop_serial_device(serial->parent); |
1327 | serial->open_count--; | 1316 | serial->port.count--; |
1328 | kref_put(&serial->parent->ref, hso_serial_ref_free); | 1317 | kref_put(&serial->parent->ref, hso_serial_ref_free); |
1329 | } | 1318 | } |
1330 | } else { | 1319 | } else { |
@@ -1361,17 +1350,11 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp) | |||
1361 | 1350 | ||
1362 | /* reset the rts and dtr */ | 1351 | /* reset the rts and dtr */ |
1363 | /* do the actual close */ | 1352 | /* do the actual close */ |
1364 | serial->open_count--; | 1353 | serial->port.count--; |
1365 | 1354 | ||
1366 | if (serial->open_count <= 0) { | 1355 | if (serial->port.count <= 0) { |
1367 | serial->open_count = 0; | 1356 | serial->port.count = 0; |
1368 | spin_lock_irq(&serial->serial_lock); | 1357 | tty_port_tty_set(&serial->port, NULL); |
1369 | if (serial->tty == tty) { | ||
1370 | serial->tty->driver_data = NULL; | ||
1371 | serial->tty = NULL; | ||
1372 | tty_kref_put(tty); | ||
1373 | } | ||
1374 | spin_unlock_irq(&serial->serial_lock); | ||
1375 | if (!usb_gone) | 1358 | if (!usb_gone) |
1376 | hso_stop_serial_device(serial->parent); | 1359 | hso_stop_serial_device(serial->parent); |
1377 | tasklet_kill(&serial->unthrottle_tasklet); | 1360 | tasklet_kill(&serial->unthrottle_tasklet); |
@@ -1390,7 +1373,7 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp) | |||
1390 | static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf, | 1373 | static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf, |
1391 | int count) | 1374 | int count) |
1392 | { | 1375 | { |
1393 | struct hso_serial *serial = get_serial_by_tty(tty); | 1376 | struct hso_serial *serial = tty->driver_data; |
1394 | int space, tx_bytes; | 1377 | int space, tx_bytes; |
1395 | unsigned long flags; | 1378 | unsigned long flags; |
1396 | 1379 | ||
@@ -1422,7 +1405,7 @@ out: | |||
1422 | /* how much room is there for writing */ | 1405 | /* how much room is there for writing */ |
1423 | static int hso_serial_write_room(struct tty_struct *tty) | 1406 | static int hso_serial_write_room(struct tty_struct *tty) |
1424 | { | 1407 | { |
1425 | struct hso_serial *serial = get_serial_by_tty(tty); | 1408 | struct hso_serial *serial = tty->driver_data; |
1426 | int room; | 1409 | int room; |
1427 | unsigned long flags; | 1410 | unsigned long flags; |
1428 | 1411 | ||
@@ -1437,7 +1420,7 @@ static int hso_serial_write_room(struct tty_struct *tty) | |||
1437 | /* setup the term */ | 1420 | /* setup the term */ |
1438 | static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) | 1421 | static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) |
1439 | { | 1422 | { |
1440 | struct hso_serial *serial = get_serial_by_tty(tty); | 1423 | struct hso_serial *serial = tty->driver_data; |
1441 | unsigned long flags; | 1424 | unsigned long flags; |
1442 | 1425 | ||
1443 | if (old) | 1426 | if (old) |
@@ -1446,7 +1429,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) | |||
1446 | 1429 | ||
1447 | /* the actual setup */ | 1430 | /* the actual setup */ |
1448 | spin_lock_irqsave(&serial->serial_lock, flags); | 1431 | spin_lock_irqsave(&serial->serial_lock, flags); |
1449 | if (serial->open_count) | 1432 | if (serial->port.count) |
1450 | _hso_serial_set_termios(tty, old); | 1433 | _hso_serial_set_termios(tty, old); |
1451 | else | 1434 | else |
1452 | tty->termios = old; | 1435 | tty->termios = old; |
@@ -1458,7 +1441,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) | |||
1458 | /* how many characters in the buffer */ | 1441 | /* how many characters in the buffer */ |
1459 | static int hso_serial_chars_in_buffer(struct tty_struct *tty) | 1442 | static int hso_serial_chars_in_buffer(struct tty_struct *tty) |
1460 | { | 1443 | { |
1461 | struct hso_serial *serial = get_serial_by_tty(tty); | 1444 | struct hso_serial *serial = tty->driver_data; |
1462 | int chars; | 1445 | int chars; |
1463 | unsigned long flags; | 1446 | unsigned long flags; |
1464 | 1447 | ||
@@ -1629,7 +1612,7 @@ static int hso_get_count(struct tty_struct *tty, | |||
1629 | struct serial_icounter_struct *icount) | 1612 | struct serial_icounter_struct *icount) |
1630 | { | 1613 | { |
1631 | struct uart_icount cnow; | 1614 | struct uart_icount cnow; |
1632 | struct hso_serial *serial = get_serial_by_tty(tty); | 1615 | struct hso_serial *serial = tty->driver_data; |
1633 | struct hso_tiocmget *tiocmget = serial->tiocmget; | 1616 | struct hso_tiocmget *tiocmget = serial->tiocmget; |
1634 | 1617 | ||
1635 | memset(icount, 0, sizeof(struct serial_icounter_struct)); | 1618 | memset(icount, 0, sizeof(struct serial_icounter_struct)); |
@@ -1659,7 +1642,7 @@ static int hso_get_count(struct tty_struct *tty, | |||
1659 | static int hso_serial_tiocmget(struct tty_struct *tty) | 1642 | static int hso_serial_tiocmget(struct tty_struct *tty) |
1660 | { | 1643 | { |
1661 | int retval; | 1644 | int retval; |
1662 | struct hso_serial *serial = get_serial_by_tty(tty); | 1645 | struct hso_serial *serial = tty->driver_data; |
1663 | struct hso_tiocmget *tiocmget; | 1646 | struct hso_tiocmget *tiocmget; |
1664 | u16 UART_state_bitmap; | 1647 | u16 UART_state_bitmap; |
1665 | 1648 | ||
@@ -1693,7 +1676,7 @@ static int hso_serial_tiocmset(struct tty_struct *tty, | |||
1693 | int val = 0; | 1676 | int val = 0; |
1694 | unsigned long flags; | 1677 | unsigned long flags; |
1695 | int if_num; | 1678 | int if_num; |
1696 | struct hso_serial *serial = get_serial_by_tty(tty); | 1679 | struct hso_serial *serial = tty->driver_data; |
1697 | 1680 | ||
1698 | /* sanity check */ | 1681 | /* sanity check */ |
1699 | if (!serial) { | 1682 | if (!serial) { |
@@ -1733,7 +1716,7 @@ static int hso_serial_tiocmset(struct tty_struct *tty, | |||
1733 | static int hso_serial_ioctl(struct tty_struct *tty, | 1716 | static int hso_serial_ioctl(struct tty_struct *tty, |
1734 | unsigned int cmd, unsigned long arg) | 1717 | unsigned int cmd, unsigned long arg) |
1735 | { | 1718 | { |
1736 | struct hso_serial *serial = get_serial_by_tty(tty); | 1719 | struct hso_serial *serial = tty->driver_data; |
1737 | int ret = 0; | 1720 | int ret = 0; |
1738 | D4("IOCTL cmd: %d, arg: %ld", cmd, arg); | 1721 | D4("IOCTL cmd: %d, arg: %ld", cmd, arg); |
1739 | 1722 | ||
@@ -1905,7 +1888,7 @@ static void intr_callback(struct urb *urb) | |||
1905 | D1("Pending read interrupt on port %d\n", i); | 1888 | D1("Pending read interrupt on port %d\n", i); |
1906 | spin_lock(&serial->serial_lock); | 1889 | spin_lock(&serial->serial_lock); |
1907 | if (serial->rx_state == RX_IDLE && | 1890 | if (serial->rx_state == RX_IDLE && |
1908 | serial->open_count > 0) { | 1891 | serial->port.count > 0) { |
1909 | /* Setup and send a ctrl req read on | 1892 | /* Setup and send a ctrl req read on |
1910 | * port i */ | 1893 | * port i */ |
1911 | if (!serial->rx_urb_filled[0]) { | 1894 | if (!serial->rx_urb_filled[0]) { |
@@ -1954,14 +1937,13 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb) | |||
1954 | 1937 | ||
1955 | spin_lock(&serial->serial_lock); | 1938 | spin_lock(&serial->serial_lock); |
1956 | serial->tx_urb_used = 0; | 1939 | serial->tx_urb_used = 0; |
1957 | tty = tty_kref_get(serial->tty); | ||
1958 | spin_unlock(&serial->serial_lock); | 1940 | spin_unlock(&serial->serial_lock); |
1959 | if (status) { | 1941 | if (status) { |
1960 | handle_usb_error(status, __func__, serial->parent); | 1942 | handle_usb_error(status, __func__, serial->parent); |
1961 | tty_kref_put(tty); | ||
1962 | return; | 1943 | return; |
1963 | } | 1944 | } |
1964 | hso_put_activity(serial->parent); | 1945 | hso_put_activity(serial->parent); |
1946 | tty = tty_port_tty_get(&serial->port); | ||
1965 | if (tty) { | 1947 | if (tty) { |
1966 | tty_wakeup(tty); | 1948 | tty_wakeup(tty); |
1967 | tty_kref_put(tty); | 1949 | tty_kref_put(tty); |
@@ -2001,7 +1983,6 @@ static void ctrl_callback(struct urb *urb) | |||
2001 | struct hso_serial *serial = urb->context; | 1983 | struct hso_serial *serial = urb->context; |
2002 | struct usb_ctrlrequest *req; | 1984 | struct usb_ctrlrequest *req; |
2003 | int status = urb->status; | 1985 | int status = urb->status; |
2004 | struct tty_struct *tty; | ||
2005 | 1986 | ||
2006 | /* sanity check */ | 1987 | /* sanity check */ |
2007 | if (!serial) | 1988 | if (!serial) |
@@ -2009,11 +1990,9 @@ static void ctrl_callback(struct urb *urb) | |||
2009 | 1990 | ||
2010 | spin_lock(&serial->serial_lock); | 1991 | spin_lock(&serial->serial_lock); |
2011 | serial->tx_urb_used = 0; | 1992 | serial->tx_urb_used = 0; |
2012 | tty = tty_kref_get(serial->tty); | ||
2013 | spin_unlock(&serial->serial_lock); | 1993 | spin_unlock(&serial->serial_lock); |
2014 | if (status) { | 1994 | if (status) { |
2015 | handle_usb_error(status, __func__, serial->parent); | 1995 | handle_usb_error(status, __func__, serial->parent); |
2016 | tty_kref_put(tty); | ||
2017 | return; | 1996 | return; |
2018 | } | 1997 | } |
2019 | 1998 | ||
@@ -2031,13 +2010,15 @@ static void ctrl_callback(struct urb *urb) | |||
2031 | put_rxbuf_data_and_resubmit_ctrl_urb(serial); | 2010 | put_rxbuf_data_and_resubmit_ctrl_urb(serial); |
2032 | spin_unlock(&serial->serial_lock); | 2011 | spin_unlock(&serial->serial_lock); |
2033 | } else { | 2012 | } else { |
2013 | struct tty_struct *tty = tty_port_tty_get(&serial->port); | ||
2034 | hso_put_activity(serial->parent); | 2014 | hso_put_activity(serial->parent); |
2035 | if (tty) | 2015 | if (tty) { |
2036 | tty_wakeup(tty); | 2016 | tty_wakeup(tty); |
2017 | tty_kref_put(tty); | ||
2018 | } | ||
2037 | /* response to a write command */ | 2019 | /* response to a write command */ |
2038 | hso_kick_transmit(serial); | 2020 | hso_kick_transmit(serial); |
2039 | } | 2021 | } |
2040 | tty_kref_put(tty); | ||
2041 | } | 2022 | } |
2042 | 2023 | ||
2043 | /* handle RX data for serial port */ | 2024 | /* handle RX data for serial port */ |
@@ -2053,8 +2034,7 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) | |||
2053 | return -2; | 2034 | return -2; |
2054 | } | 2035 | } |
2055 | 2036 | ||
2056 | /* All callers to put_rxbuf_data hold serial_lock */ | 2037 | tty = tty_port_tty_get(&serial->port); |
2057 | tty = tty_kref_get(serial->tty); | ||
2058 | 2038 | ||
2059 | /* Push data to tty */ | 2039 | /* Push data to tty */ |
2060 | if (tty) { | 2040 | if (tty) { |
@@ -2074,12 +2054,12 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) | |||
2074 | write_length_remaining -= curr_write_len; | 2054 | write_length_remaining -= curr_write_len; |
2075 | tty_flip_buffer_push(tty); | 2055 | tty_flip_buffer_push(tty); |
2076 | } | 2056 | } |
2057 | tty_kref_put(tty); | ||
2077 | } | 2058 | } |
2078 | if (write_length_remaining == 0) { | 2059 | if (write_length_remaining == 0) { |
2079 | serial->curr_rx_urb_offset = 0; | 2060 | serial->curr_rx_urb_offset = 0; |
2080 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; | 2061 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; |
2081 | } | 2062 | } |
2082 | tty_kref_put(tty); | ||
2083 | return write_length_remaining; | 2063 | return write_length_remaining; |
2084 | } | 2064 | } |
2085 | 2065 | ||
@@ -2320,6 +2300,7 @@ static int hso_serial_common_create(struct hso_serial *serial, int num_urbs, | |||
2320 | serial->minor = minor; | 2300 | serial->minor = minor; |
2321 | serial->magic = HSO_SERIAL_MAGIC; | 2301 | serial->magic = HSO_SERIAL_MAGIC; |
2322 | spin_lock_init(&serial->serial_lock); | 2302 | spin_lock_init(&serial->serial_lock); |
2303 | tty_port_init(&serial->port); | ||
2323 | serial->num_rx_urbs = num_urbs; | 2304 | serial->num_rx_urbs = num_urbs; |
2324 | 2305 | ||
2325 | /* RX, allocate urb and initialize */ | 2306 | /* RX, allocate urb and initialize */ |
@@ -3098,7 +3079,7 @@ static int hso_resume(struct usb_interface *iface) | |||
3098 | /* Start all serial ports */ | 3079 | /* Start all serial ports */ |
3099 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { | 3080 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { |
3100 | if (serial_table[i] && (serial_table[i]->interface == iface)) { | 3081 | if (serial_table[i] && (serial_table[i]->interface == iface)) { |
3101 | if (dev2ser(serial_table[i])->open_count) { | 3082 | if (dev2ser(serial_table[i])->port.count) { |
3102 | result = | 3083 | result = |
3103 | hso_start_serial_device(serial_table[i], GFP_NOIO); | 3084 | hso_start_serial_device(serial_table[i], GFP_NOIO); |
3104 | hso_kick_transmit(dev2ser(serial_table[i])); | 3085 | hso_kick_transmit(dev2ser(serial_table[i])); |
@@ -3172,13 +3153,12 @@ static void hso_free_interface(struct usb_interface *interface) | |||
3172 | if (serial_table[i] && | 3153 | if (serial_table[i] && |
3173 | (serial_table[i]->interface == interface)) { | 3154 | (serial_table[i]->interface == interface)) { |
3174 | hso_dev = dev2ser(serial_table[i]); | 3155 | hso_dev = dev2ser(serial_table[i]); |
3175 | spin_lock_irq(&hso_dev->serial_lock); | 3156 | tty = tty_port_tty_get(&hso_dev->port); |
3176 | tty = tty_kref_get(hso_dev->tty); | 3157 | if (tty) { |
3177 | spin_unlock_irq(&hso_dev->serial_lock); | ||
3178 | if (tty) | ||
3179 | tty_hangup(tty); | 3158 | tty_hangup(tty); |
3159 | tty_kref_put(tty); | ||
3160 | } | ||
3180 | mutex_lock(&hso_dev->parent->mutex); | 3161 | mutex_lock(&hso_dev->parent->mutex); |
3181 | tty_kref_put(tty); | ||
3182 | hso_dev->parent->usb_gone = 1; | 3162 | hso_dev->parent->usb_gone = 1; |
3183 | mutex_unlock(&hso_dev->parent->mutex); | 3163 | mutex_unlock(&hso_dev->parent->mutex); |
3184 | kref_put(&serial_table[i]->ref, hso_serial_ref_free); | 3164 | kref_put(&serial_table[i]->ref, hso_serial_ref_free); |
@@ -3313,7 +3293,6 @@ static int __init hso_init(void) | |||
3313 | return -ENOMEM; | 3293 | return -ENOMEM; |
3314 | 3294 | ||
3315 | /* fill in all needed values */ | 3295 | /* fill in all needed values */ |
3316 | tty_drv->magic = TTY_DRIVER_MAGIC; | ||
3317 | tty_drv->driver_name = driver_name; | 3296 | tty_drv->driver_name = driver_name; |
3318 | tty_drv->name = tty_filename; | 3297 | tty_drv->name = tty_filename; |
3319 | 3298 | ||
@@ -3334,7 +3313,7 @@ static int __init hso_init(void) | |||
3334 | if (result) { | 3313 | if (result) { |
3335 | printk(KERN_ERR "%s - tty_register_driver failed(%d)\n", | 3314 | printk(KERN_ERR "%s - tty_register_driver failed(%d)\n", |
3336 | __func__, result); | 3315 | __func__, result); |
3337 | return result; | 3316 | goto err_free_tty; |
3338 | } | 3317 | } |
3339 | 3318 | ||
3340 | /* register this module as an usb driver */ | 3319 | /* register this module as an usb driver */ |
@@ -3342,13 +3321,16 @@ static int __init hso_init(void) | |||
3342 | if (result) { | 3321 | if (result) { |
3343 | printk(KERN_ERR "Could not register hso driver? error: %d\n", | 3322 | printk(KERN_ERR "Could not register hso driver? error: %d\n", |
3344 | result); | 3323 | result); |
3345 | /* cleanup serial interface */ | 3324 | goto err_unreg_tty; |
3346 | tty_unregister_driver(tty_drv); | ||
3347 | return result; | ||
3348 | } | 3325 | } |
3349 | 3326 | ||
3350 | /* done */ | 3327 | /* done */ |
3351 | return 0; | 3328 | return 0; |
3329 | err_unreg_tty: | ||
3330 | tty_unregister_driver(tty_drv); | ||
3331 | err_free_tty: | ||
3332 | put_tty_driver(tty_drv); | ||
3333 | return result; | ||
3352 | } | 3334 | } |
3353 | 3335 | ||
3354 | static void __exit hso_exit(void) | 3336 | static void __exit hso_exit(void) |
@@ -3356,6 +3338,7 @@ static void __exit hso_exit(void) | |||
3356 | printk(KERN_INFO "hso: unloaded\n"); | 3338 | printk(KERN_INFO "hso: unloaded\n"); |
3357 | 3339 | ||
3358 | tty_unregister_driver(tty_drv); | 3340 | tty_unregister_driver(tty_drv); |
3341 | put_tty_driver(tty_drv); | ||
3359 | /* deregister the usb driver */ | 3342 | /* deregister the usb driver */ |
3360 | usb_deregister(&hso_driver); | 3343 | usb_deregister(&hso_driver); |
3361 | } | 3344 | } |
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c index 4f9f1dcc1551..6c0116d48c74 100644 --- a/drivers/s390/char/con3215.c +++ b/drivers/s390/char/con3215.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/interrupt.h> | 20 | #include <linux/interrupt.h> |
21 | #include <linux/err.h> | 21 | #include <linux/err.h> |
22 | #include <linux/reboot.h> | 22 | #include <linux/reboot.h> |
23 | #include <linux/serial.h> /* ASYNC_* flags */ | ||
23 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
24 | #include <asm/ccwdev.h> | 25 | #include <asm/ccwdev.h> |
25 | #include <asm/cio.h> | 26 | #include <asm/cio.h> |
@@ -44,14 +45,11 @@ | |||
44 | #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */ | 45 | #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */ |
45 | 46 | ||
46 | #define RAW3215_FIXED 1 /* 3215 console device is not be freed */ | 47 | #define RAW3215_FIXED 1 /* 3215 console device is not be freed */ |
47 | #define RAW3215_ACTIVE 2 /* set if the device is in use */ | ||
48 | #define RAW3215_WORKING 4 /* set if a request is being worked on */ | 48 | #define RAW3215_WORKING 4 /* set if a request is being worked on */ |
49 | #define RAW3215_THROTTLED 8 /* set if reading is disabled */ | 49 | #define RAW3215_THROTTLED 8 /* set if reading is disabled */ |
50 | #define RAW3215_STOPPED 16 /* set if writing is disabled */ | 50 | #define RAW3215_STOPPED 16 /* set if writing is disabled */ |
51 | #define RAW3215_CLOSING 32 /* set while in close process */ | ||
52 | #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */ | 51 | #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */ |
53 | #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */ | 52 | #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */ |
54 | #define RAW3215_FROZEN 256 /* set if 3215 is frozen for suspend */ | ||
55 | 53 | ||
56 | #define TAB_STOP_SIZE 8 /* tab stop size */ | 54 | #define TAB_STOP_SIZE 8 /* tab stop size */ |
57 | 55 | ||
@@ -76,6 +74,7 @@ struct raw3215_req { | |||
76 | } __attribute__ ((aligned(8))); | 74 | } __attribute__ ((aligned(8))); |
77 | 75 | ||
78 | struct raw3215_info { | 76 | struct raw3215_info { |
77 | struct tty_port port; | ||
79 | struct ccw_device *cdev; /* device for tty driver */ | 78 | struct ccw_device *cdev; /* device for tty driver */ |
80 | spinlock_t *lock; /* pointer to irq lock */ | 79 | spinlock_t *lock; /* pointer to irq lock */ |
81 | int flags; /* state flags */ | 80 | int flags; /* state flags */ |
@@ -84,7 +83,6 @@ struct raw3215_info { | |||
84 | int head; /* first free byte in output buffer */ | 83 | int head; /* first free byte in output buffer */ |
85 | int count; /* number of bytes in output buffer */ | 84 | int count; /* number of bytes in output buffer */ |
86 | int written; /* number of bytes in write requests */ | 85 | int written; /* number of bytes in write requests */ |
87 | struct tty_struct *tty; /* pointer to tty structure if present */ | ||
88 | struct raw3215_req *queued_read; /* pointer to queued read requests */ | 86 | struct raw3215_req *queued_read; /* pointer to queued read requests */ |
89 | struct raw3215_req *queued_write;/* pointer to queued write requests */ | 87 | struct raw3215_req *queued_write;/* pointer to queued write requests */ |
90 | struct tasklet_struct tlet; /* tasklet to invoke tty_wakeup */ | 88 | struct tasklet_struct tlet; /* tasklet to invoke tty_wakeup */ |
@@ -293,7 +291,7 @@ static void raw3215_timeout(unsigned long __data) | |||
293 | if (raw->flags & RAW3215_TIMER_RUNS) { | 291 | if (raw->flags & RAW3215_TIMER_RUNS) { |
294 | del_timer(&raw->timer); | 292 | del_timer(&raw->timer); |
295 | raw->flags &= ~RAW3215_TIMER_RUNS; | 293 | raw->flags &= ~RAW3215_TIMER_RUNS; |
296 | if (!(raw->flags & RAW3215_FROZEN)) { | 294 | if (!(raw->port.flags & ASYNC_SUSPENDED)) { |
297 | raw3215_mk_write_req(raw); | 295 | raw3215_mk_write_req(raw); |
298 | raw3215_start_io(raw); | 296 | raw3215_start_io(raw); |
299 | } | 297 | } |
@@ -309,7 +307,8 @@ static void raw3215_timeout(unsigned long __data) | |||
309 | */ | 307 | */ |
310 | static inline void raw3215_try_io(struct raw3215_info *raw) | 308 | static inline void raw3215_try_io(struct raw3215_info *raw) |
311 | { | 309 | { |
312 | if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FROZEN)) | 310 | if (!(raw->port.flags & ASYNC_INITIALIZED) || |
311 | (raw->port.flags & ASYNC_SUSPENDED)) | ||
313 | return; | 312 | return; |
314 | if (raw->queued_read != NULL) | 313 | if (raw->queued_read != NULL) |
315 | raw3215_start_io(raw); | 314 | raw3215_start_io(raw); |
@@ -324,10 +323,7 @@ static inline void raw3215_try_io(struct raw3215_info *raw) | |||
324 | } | 323 | } |
325 | } else if (!(raw->flags & RAW3215_TIMER_RUNS)) { | 324 | } else if (!(raw->flags & RAW3215_TIMER_RUNS)) { |
326 | /* delay small writes */ | 325 | /* delay small writes */ |
327 | init_timer(&raw->timer); | ||
328 | raw->timer.expires = RAW3215_TIMEOUT + jiffies; | 326 | raw->timer.expires = RAW3215_TIMEOUT + jiffies; |
329 | raw->timer.data = (unsigned long) raw; | ||
330 | raw->timer.function = raw3215_timeout; | ||
331 | add_timer(&raw->timer); | 327 | add_timer(&raw->timer); |
332 | raw->flags |= RAW3215_TIMER_RUNS; | 328 | raw->flags |= RAW3215_TIMER_RUNS; |
333 | } | 329 | } |
@@ -340,17 +336,21 @@ static inline void raw3215_try_io(struct raw3215_info *raw) | |||
340 | static void raw3215_wakeup(unsigned long data) | 336 | static void raw3215_wakeup(unsigned long data) |
341 | { | 337 | { |
342 | struct raw3215_info *raw = (struct raw3215_info *) data; | 338 | struct raw3215_info *raw = (struct raw3215_info *) data; |
343 | tty_wakeup(raw->tty); | 339 | struct tty_struct *tty; |
340 | |||
341 | tty = tty_port_tty_get(&raw->port); | ||
342 | tty_wakeup(tty); | ||
343 | tty_kref_put(tty); | ||
344 | } | 344 | } |
345 | 345 | ||
346 | /* | 346 | /* |
347 | * Try to start the next IO and wake up processes waiting on the tty. | 347 | * Try to start the next IO and wake up processes waiting on the tty. |
348 | */ | 348 | */ |
349 | static void raw3215_next_io(struct raw3215_info *raw) | 349 | static void raw3215_next_io(struct raw3215_info *raw, struct tty_struct *tty) |
350 | { | 350 | { |
351 | raw3215_mk_write_req(raw); | 351 | raw3215_mk_write_req(raw); |
352 | raw3215_try_io(raw); | 352 | raw3215_try_io(raw); |
353 | if (raw->tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) | 353 | if (tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) |
354 | tasklet_schedule(&raw->tlet); | 354 | tasklet_schedule(&raw->tlet); |
355 | } | 355 | } |
356 | 356 | ||
@@ -368,10 +368,11 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
368 | 368 | ||
369 | raw = dev_get_drvdata(&cdev->dev); | 369 | raw = dev_get_drvdata(&cdev->dev); |
370 | req = (struct raw3215_req *) intparm; | 370 | req = (struct raw3215_req *) intparm; |
371 | tty = tty_port_tty_get(&raw->port); | ||
371 | cstat = irb->scsw.cmd.cstat; | 372 | cstat = irb->scsw.cmd.cstat; |
372 | dstat = irb->scsw.cmd.dstat; | 373 | dstat = irb->scsw.cmd.dstat; |
373 | if (cstat != 0) | 374 | if (cstat != 0) |
374 | raw3215_next_io(raw); | 375 | raw3215_next_io(raw, tty); |
375 | if (dstat & 0x01) { /* we got a unit exception */ | 376 | if (dstat & 0x01) { /* we got a unit exception */ |
376 | dstat &= ~0x01; /* we can ignore it */ | 377 | dstat &= ~0x01; /* we can ignore it */ |
377 | } | 378 | } |
@@ -381,13 +382,13 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
381 | break; | 382 | break; |
382 | /* Attention interrupt, someone hit the enter key */ | 383 | /* Attention interrupt, someone hit the enter key */ |
383 | raw3215_mk_read_req(raw); | 384 | raw3215_mk_read_req(raw); |
384 | raw3215_next_io(raw); | 385 | raw3215_next_io(raw, tty); |
385 | break; | 386 | break; |
386 | case 0x08: | 387 | case 0x08: |
387 | case 0x0C: | 388 | case 0x0C: |
388 | /* Channel end interrupt. */ | 389 | /* Channel end interrupt. */ |
389 | if ((raw = req->info) == NULL) | 390 | if ((raw = req->info) == NULL) |
390 | return; /* That shouldn't happen ... */ | 391 | goto put_tty; /* That shouldn't happen ... */ |
391 | if (req->type == RAW3215_READ) { | 392 | if (req->type == RAW3215_READ) { |
392 | /* store residual count, then wait for device end */ | 393 | /* store residual count, then wait for device end */ |
393 | req->residual = irb->scsw.cmd.count; | 394 | req->residual = irb->scsw.cmd.count; |
@@ -397,11 +398,10 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
397 | case 0x04: | 398 | case 0x04: |
398 | /* Device end interrupt. */ | 399 | /* Device end interrupt. */ |
399 | if ((raw = req->info) == NULL) | 400 | if ((raw = req->info) == NULL) |
400 | return; /* That shouldn't happen ... */ | 401 | goto put_tty; /* That shouldn't happen ... */ |
401 | if (req->type == RAW3215_READ && raw->tty != NULL) { | 402 | if (req->type == RAW3215_READ && tty != NULL) { |
402 | unsigned int cchar; | 403 | unsigned int cchar; |
403 | 404 | ||
404 | tty = raw->tty; | ||
405 | count = 160 - req->residual; | 405 | count = 160 - req->residual; |
406 | EBCASC(raw->inbuf, count); | 406 | EBCASC(raw->inbuf, count); |
407 | cchar = ctrlchar_handle(raw->inbuf, count, tty); | 407 | cchar = ctrlchar_handle(raw->inbuf, count, tty); |
@@ -411,7 +411,7 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
411 | 411 | ||
412 | case CTRLCHAR_CTRL: | 412 | case CTRLCHAR_CTRL: |
413 | tty_insert_flip_char(tty, cchar, TTY_NORMAL); | 413 | tty_insert_flip_char(tty, cchar, TTY_NORMAL); |
414 | tty_flip_buffer_push(raw->tty); | 414 | tty_flip_buffer_push(tty); |
415 | break; | 415 | break; |
416 | 416 | ||
417 | case CTRLCHAR_NONE: | 417 | case CTRLCHAR_NONE: |
@@ -424,7 +424,7 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
424 | } else | 424 | } else |
425 | count -= 2; | 425 | count -= 2; |
426 | tty_insert_flip_string(tty, raw->inbuf, count); | 426 | tty_insert_flip_string(tty, raw->inbuf, count); |
427 | tty_flip_buffer_push(raw->tty); | 427 | tty_flip_buffer_push(tty); |
428 | break; | 428 | break; |
429 | } | 429 | } |
430 | } else if (req->type == RAW3215_WRITE) { | 430 | } else if (req->type == RAW3215_WRITE) { |
@@ -439,7 +439,7 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
439 | raw->queued_read == NULL) { | 439 | raw->queued_read == NULL) { |
440 | wake_up_interruptible(&raw->empty_wait); | 440 | wake_up_interruptible(&raw->empty_wait); |
441 | } | 441 | } |
442 | raw3215_next_io(raw); | 442 | raw3215_next_io(raw, tty); |
443 | break; | 443 | break; |
444 | default: | 444 | default: |
445 | /* Strange interrupt, I'll do my best to clean up */ | 445 | /* Strange interrupt, I'll do my best to clean up */ |
@@ -451,9 +451,10 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm, | |||
451 | raw->flags &= ~RAW3215_WORKING; | 451 | raw->flags &= ~RAW3215_WORKING; |
452 | raw3215_free_req(req); | 452 | raw3215_free_req(req); |
453 | } | 453 | } |
454 | raw3215_next_io(raw); | 454 | raw3215_next_io(raw, tty); |
455 | } | 455 | } |
456 | return; | 456 | put_tty: |
457 | tty_kref_put(tty); | ||
457 | } | 458 | } |
458 | 459 | ||
459 | /* | 460 | /* |
@@ -487,7 +488,7 @@ static void raw3215_make_room(struct raw3215_info *raw, unsigned int length) | |||
487 | /* While console is frozen for suspend we have no other | 488 | /* While console is frozen for suspend we have no other |
488 | * choice but to drop message from the buffer to make | 489 | * choice but to drop message from the buffer to make |
489 | * room for even more messages. */ | 490 | * room for even more messages. */ |
490 | if (raw->flags & RAW3215_FROZEN) { | 491 | if (raw->port.flags & ASYNC_SUSPENDED) { |
491 | raw3215_drop_line(raw); | 492 | raw3215_drop_line(raw); |
492 | continue; | 493 | continue; |
493 | } | 494 | } |
@@ -609,10 +610,10 @@ static int raw3215_startup(struct raw3215_info *raw) | |||
609 | { | 610 | { |
610 | unsigned long flags; | 611 | unsigned long flags; |
611 | 612 | ||
612 | if (raw->flags & RAW3215_ACTIVE) | 613 | if (raw->port.flags & ASYNC_INITIALIZED) |
613 | return 0; | 614 | return 0; |
614 | raw->line_pos = 0; | 615 | raw->line_pos = 0; |
615 | raw->flags |= RAW3215_ACTIVE; | 616 | raw->port.flags |= ASYNC_INITIALIZED; |
616 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); | 617 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); |
617 | raw3215_try_io(raw); | 618 | raw3215_try_io(raw); |
618 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); | 619 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); |
@@ -628,14 +629,15 @@ static void raw3215_shutdown(struct raw3215_info *raw) | |||
628 | DECLARE_WAITQUEUE(wait, current); | 629 | DECLARE_WAITQUEUE(wait, current); |
629 | unsigned long flags; | 630 | unsigned long flags; |
630 | 631 | ||
631 | if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED)) | 632 | if (!(raw->port.flags & ASYNC_INITIALIZED) || |
633 | (raw->flags & RAW3215_FIXED)) | ||
632 | return; | 634 | return; |
633 | /* Wait for outstanding requests, then free irq */ | 635 | /* Wait for outstanding requests, then free irq */ |
634 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); | 636 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); |
635 | if ((raw->flags & RAW3215_WORKING) || | 637 | if ((raw->flags & RAW3215_WORKING) || |
636 | raw->queued_write != NULL || | 638 | raw->queued_write != NULL || |
637 | raw->queued_read != NULL) { | 639 | raw->queued_read != NULL) { |
638 | raw->flags |= RAW3215_CLOSING; | 640 | raw->port.flags |= ASYNC_CLOSING; |
639 | add_wait_queue(&raw->empty_wait, &wait); | 641 | add_wait_queue(&raw->empty_wait, &wait); |
640 | set_current_state(TASK_INTERRUPTIBLE); | 642 | set_current_state(TASK_INTERRUPTIBLE); |
641 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); | 643 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); |
@@ -643,11 +645,41 @@ static void raw3215_shutdown(struct raw3215_info *raw) | |||
643 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); | 645 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); |
644 | remove_wait_queue(&raw->empty_wait, &wait); | 646 | remove_wait_queue(&raw->empty_wait, &wait); |
645 | set_current_state(TASK_RUNNING); | 647 | set_current_state(TASK_RUNNING); |
646 | raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING); | 648 | raw->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING); |
647 | } | 649 | } |
648 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); | 650 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); |
649 | } | 651 | } |
650 | 652 | ||
653 | static struct raw3215_info *raw3215_alloc_info(void) | ||
654 | { | ||
655 | struct raw3215_info *info; | ||
656 | |||
657 | info = kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA); | ||
658 | if (!info) | ||
659 | return NULL; | ||
660 | |||
661 | info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); | ||
662 | info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA); | ||
663 | if (!info->buffer || !info->inbuf) { | ||
664 | kfree(info); | ||
665 | return NULL; | ||
666 | } | ||
667 | |||
668 | setup_timer(&info->timer, raw3215_timeout, (unsigned long)info); | ||
669 | init_waitqueue_head(&info->empty_wait); | ||
670 | tasklet_init(&info->tlet, raw3215_wakeup, (unsigned long)info); | ||
671 | tty_port_init(&info->port); | ||
672 | |||
673 | return info; | ||
674 | } | ||
675 | |||
676 | static void raw3215_free_info(struct raw3215_info *raw) | ||
677 | { | ||
678 | kfree(raw->inbuf); | ||
679 | kfree(raw->buffer); | ||
680 | kfree(raw); | ||
681 | } | ||
682 | |||
651 | static int raw3215_probe (struct ccw_device *cdev) | 683 | static int raw3215_probe (struct ccw_device *cdev) |
652 | { | 684 | { |
653 | struct raw3215_info *raw; | 685 | struct raw3215_info *raw; |
@@ -656,11 +688,15 @@ static int raw3215_probe (struct ccw_device *cdev) | |||
656 | /* Console is special. */ | 688 | /* Console is special. */ |
657 | if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev))) | 689 | if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev))) |
658 | return 0; | 690 | return 0; |
659 | raw = kmalloc(sizeof(struct raw3215_info) + | 691 | |
660 | RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA); | 692 | raw = raw3215_alloc_info(); |
661 | if (raw == NULL) | 693 | if (raw == NULL) |
662 | return -ENOMEM; | 694 | return -ENOMEM; |
663 | 695 | ||
696 | raw->cdev = cdev; | ||
697 | dev_set_drvdata(&cdev->dev, raw); | ||
698 | cdev->handler = raw3215_irq; | ||
699 | |||
664 | spin_lock(&raw3215_device_lock); | 700 | spin_lock(&raw3215_device_lock); |
665 | for (line = 0; line < NR_3215; line++) { | 701 | for (line = 0; line < NR_3215; line++) { |
666 | if (!raw3215[line]) { | 702 | if (!raw3215[line]) { |
@@ -670,28 +706,10 @@ static int raw3215_probe (struct ccw_device *cdev) | |||
670 | } | 706 | } |
671 | spin_unlock(&raw3215_device_lock); | 707 | spin_unlock(&raw3215_device_lock); |
672 | if (line == NR_3215) { | 708 | if (line == NR_3215) { |
673 | kfree(raw); | 709 | raw3215_free_info(raw); |
674 | return -ENODEV; | 710 | return -ENODEV; |
675 | } | 711 | } |
676 | 712 | ||
677 | raw->cdev = cdev; | ||
678 | raw->inbuf = (char *) raw + sizeof(struct raw3215_info); | ||
679 | memset(raw, 0, sizeof(struct raw3215_info)); | ||
680 | raw->buffer = kmalloc(RAW3215_BUFFER_SIZE, | ||
681 | GFP_KERNEL|GFP_DMA); | ||
682 | if (raw->buffer == NULL) { | ||
683 | spin_lock(&raw3215_device_lock); | ||
684 | raw3215[line] = NULL; | ||
685 | spin_unlock(&raw3215_device_lock); | ||
686 | kfree(raw); | ||
687 | return -ENOMEM; | ||
688 | } | ||
689 | init_waitqueue_head(&raw->empty_wait); | ||
690 | tasklet_init(&raw->tlet, raw3215_wakeup, (unsigned long) raw); | ||
691 | |||
692 | dev_set_drvdata(&cdev->dev, raw); | ||
693 | cdev->handler = raw3215_irq; | ||
694 | |||
695 | return 0; | 713 | return 0; |
696 | } | 714 | } |
697 | 715 | ||
@@ -703,8 +721,7 @@ static void raw3215_remove (struct ccw_device *cdev) | |||
703 | raw = dev_get_drvdata(&cdev->dev); | 721 | raw = dev_get_drvdata(&cdev->dev); |
704 | if (raw) { | 722 | if (raw) { |
705 | dev_set_drvdata(&cdev->dev, NULL); | 723 | dev_set_drvdata(&cdev->dev, NULL); |
706 | kfree(raw->buffer); | 724 | raw3215_free_info(raw); |
707 | kfree(raw); | ||
708 | } | 725 | } |
709 | } | 726 | } |
710 | 727 | ||
@@ -741,7 +758,7 @@ static int raw3215_pm_stop(struct ccw_device *cdev) | |||
741 | raw = dev_get_drvdata(&cdev->dev); | 758 | raw = dev_get_drvdata(&cdev->dev); |
742 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); | 759 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); |
743 | raw3215_make_room(raw, RAW3215_BUFFER_SIZE); | 760 | raw3215_make_room(raw, RAW3215_BUFFER_SIZE); |
744 | raw->flags |= RAW3215_FROZEN; | 761 | raw->port.flags |= ASYNC_SUSPENDED; |
745 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); | 762 | spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); |
746 | return 0; | 763 | return 0; |
747 | } | 764 | } |
@@ -754,7 +771,7 @@ static int raw3215_pm_start(struct ccw_device *cdev) | |||
754 | /* Allow I/O again and flush output buffer. */ | 771 | /* Allow I/O again and flush output buffer. */ |
755 | raw = dev_get_drvdata(&cdev->dev); | 772 | raw = dev_get_drvdata(&cdev->dev); |
756 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); | 773 | spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); |
757 | raw->flags &= ~RAW3215_FROZEN; | 774 | raw->port.flags &= ~ASYNC_SUSPENDED; |
758 | raw->flags |= RAW3215_FLUSHING; | 775 | raw->flags |= RAW3215_FLUSHING; |
759 | raw3215_try_io(raw); | 776 | raw3215_try_io(raw); |
760 | raw->flags &= ~RAW3215_FLUSHING; | 777 | raw->flags &= ~RAW3215_FLUSHING; |
@@ -827,7 +844,7 @@ static void con3215_flush(void) | |||
827 | unsigned long flags; | 844 | unsigned long flags; |
828 | 845 | ||
829 | raw = raw3215[0]; /* console 3215 is the first one */ | 846 | raw = raw3215[0]; /* console 3215 is the first one */ |
830 | if (raw->flags & RAW3215_FROZEN) | 847 | if (raw->port.flags & ASYNC_SUSPENDED) |
831 | /* The console is still frozen for suspend. */ | 848 | /* The console is still frozen for suspend. */ |
832 | if (ccw_device_force_console()) | 849 | if (ccw_device_force_console()) |
833 | /* Forcing didn't work, no panic message .. */ | 850 | /* Forcing didn't work, no panic message .. */ |
@@ -897,23 +914,16 @@ static int __init con3215_init(void) | |||
897 | if (IS_ERR(cdev)) | 914 | if (IS_ERR(cdev)) |
898 | return -ENODEV; | 915 | return -ENODEV; |
899 | 916 | ||
900 | raw3215[0] = raw = (struct raw3215_info *) | 917 | raw3215[0] = raw = raw3215_alloc_info(); |
901 | kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA); | ||
902 | raw->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); | ||
903 | raw->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA); | ||
904 | raw->cdev = cdev; | 918 | raw->cdev = cdev; |
905 | dev_set_drvdata(&cdev->dev, raw); | 919 | dev_set_drvdata(&cdev->dev, raw); |
906 | cdev->handler = raw3215_irq; | 920 | cdev->handler = raw3215_irq; |
907 | 921 | ||
908 | raw->flags |= RAW3215_FIXED; | 922 | raw->flags |= RAW3215_FIXED; |
909 | init_waitqueue_head(&raw->empty_wait); | ||
910 | tasklet_init(&raw->tlet, raw3215_wakeup, (unsigned long) raw); | ||
911 | 923 | ||
912 | /* Request the console irq */ | 924 | /* Request the console irq */ |
913 | if (raw3215_startup(raw) != 0) { | 925 | if (raw3215_startup(raw) != 0) { |
914 | kfree(raw->inbuf); | 926 | raw3215_free_info(raw); |
915 | kfree(raw->buffer); | ||
916 | kfree(raw); | ||
917 | raw3215[0] = NULL; | 927 | raw3215[0] = NULL; |
918 | return -ENODEV; | 928 | return -ENODEV; |
919 | } | 929 | } |
@@ -940,7 +950,7 @@ static int tty3215_open(struct tty_struct *tty, struct file * filp) | |||
940 | return -ENODEV; | 950 | return -ENODEV; |
941 | 951 | ||
942 | tty->driver_data = raw; | 952 | tty->driver_data = raw; |
943 | raw->tty = tty; | 953 | tty_port_tty_set(&raw->port, tty); |
944 | 954 | ||
945 | tty->low_latency = 0; /* don't use bottom half for pushing chars */ | 955 | tty->low_latency = 0; /* don't use bottom half for pushing chars */ |
946 | /* | 956 | /* |
@@ -971,7 +981,7 @@ static void tty3215_close(struct tty_struct *tty, struct file * filp) | |||
971 | raw3215_shutdown(raw); | 981 | raw3215_shutdown(raw); |
972 | tasklet_kill(&raw->tlet); | 982 | tasklet_kill(&raw->tlet); |
973 | tty->closing = 0; | 983 | tty->closing = 0; |
974 | raw->tty = NULL; | 984 | tty_port_tty_set(&raw->port, NULL); |
975 | } | 985 | } |
976 | 986 | ||
977 | /* | 987 | /* |
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c index 806588192483..7ef9cfdc17d8 100644 --- a/drivers/s390/char/keyboard.c +++ b/drivers/s390/char/keyboard.c | |||
@@ -199,7 +199,7 @@ handle_diacr(struct kbd_data *kbd, unsigned int ch) | |||
199 | if (ch == ' ' || ch == d) | 199 | if (ch == ' ' || ch == d) |
200 | return d; | 200 | return d; |
201 | 201 | ||
202 | kbd_put_queue(kbd->tty, d); | 202 | kbd_put_queue(kbd->port, d); |
203 | return ch; | 203 | return ch; |
204 | } | 204 | } |
205 | 205 | ||
@@ -221,7 +221,7 @@ k_self(struct kbd_data *kbd, unsigned char value) | |||
221 | { | 221 | { |
222 | if (kbd->diacr) | 222 | if (kbd->diacr) |
223 | value = handle_diacr(kbd, value); | 223 | value = handle_diacr(kbd, value); |
224 | kbd_put_queue(kbd->tty, value); | 224 | kbd_put_queue(kbd->port, value); |
225 | } | 225 | } |
226 | 226 | ||
227 | /* | 227 | /* |
@@ -239,7 +239,7 @@ static void | |||
239 | k_fn(struct kbd_data *kbd, unsigned char value) | 239 | k_fn(struct kbd_data *kbd, unsigned char value) |
240 | { | 240 | { |
241 | if (kbd->func_table[value]) | 241 | if (kbd->func_table[value]) |
242 | kbd_puts_queue(kbd->tty, kbd->func_table[value]); | 242 | kbd_puts_queue(kbd->port, kbd->func_table[value]); |
243 | } | 243 | } |
244 | 244 | ||
245 | static void | 245 | static void |
@@ -257,20 +257,20 @@ k_spec(struct kbd_data *kbd, unsigned char value) | |||
257 | * but we need only 16 bits here | 257 | * but we need only 16 bits here |
258 | */ | 258 | */ |
259 | static void | 259 | static void |
260 | to_utf8(struct tty_struct *tty, ushort c) | 260 | to_utf8(struct tty_port *port, ushort c) |
261 | { | 261 | { |
262 | if (c < 0x80) | 262 | if (c < 0x80) |
263 | /* 0******* */ | 263 | /* 0******* */ |
264 | kbd_put_queue(tty, c); | 264 | kbd_put_queue(port, c); |
265 | else if (c < 0x800) { | 265 | else if (c < 0x800) { |
266 | /* 110***** 10****** */ | 266 | /* 110***** 10****** */ |
267 | kbd_put_queue(tty, 0xc0 | (c >> 6)); | 267 | kbd_put_queue(port, 0xc0 | (c >> 6)); |
268 | kbd_put_queue(tty, 0x80 | (c & 0x3f)); | 268 | kbd_put_queue(port, 0x80 | (c & 0x3f)); |
269 | } else { | 269 | } else { |
270 | /* 1110**** 10****** 10****** */ | 270 | /* 1110**** 10****** 10****** */ |
271 | kbd_put_queue(tty, 0xe0 | (c >> 12)); | 271 | kbd_put_queue(port, 0xe0 | (c >> 12)); |
272 | kbd_put_queue(tty, 0x80 | ((c >> 6) & 0x3f)); | 272 | kbd_put_queue(port, 0x80 | ((c >> 6) & 0x3f)); |
273 | kbd_put_queue(tty, 0x80 | (c & 0x3f)); | 273 | kbd_put_queue(port, 0x80 | (c & 0x3f)); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | 276 | ||
@@ -283,7 +283,7 @@ kbd_keycode(struct kbd_data *kbd, unsigned int keycode) | |||
283 | unsigned short keysym; | 283 | unsigned short keysym; |
284 | unsigned char type, value; | 284 | unsigned char type, value; |
285 | 285 | ||
286 | if (!kbd || !kbd->tty) | 286 | if (!kbd) |
287 | return; | 287 | return; |
288 | 288 | ||
289 | if (keycode >= 384) | 289 | if (keycode >= 384) |
@@ -323,7 +323,7 @@ kbd_keycode(struct kbd_data *kbd, unsigned int keycode) | |||
323 | #endif | 323 | #endif |
324 | (*k_handler[type])(kbd, value); | 324 | (*k_handler[type])(kbd, value); |
325 | } else | 325 | } else |
326 | to_utf8(kbd->tty, keysym); | 326 | to_utf8(kbd->port, keysym); |
327 | } | 327 | } |
328 | 328 | ||
329 | /* | 329 | /* |
@@ -457,6 +457,7 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs, | |||
457 | 457 | ||
458 | int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) | 458 | int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) |
459 | { | 459 | { |
460 | struct tty_struct *tty; | ||
460 | void __user *argp; | 461 | void __user *argp; |
461 | unsigned int ct; | 462 | unsigned int ct; |
462 | int perm; | 463 | int perm; |
@@ -467,7 +468,10 @@ int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) | |||
467 | * To have permissions to do most of the vt ioctls, we either have | 468 | * To have permissions to do most of the vt ioctls, we either have |
468 | * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. | 469 | * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. |
469 | */ | 470 | */ |
470 | perm = current->signal->tty == kbd->tty || capable(CAP_SYS_TTY_CONFIG); | 471 | tty = tty_port_tty_get(kbd->port); |
472 | /* FIXME this test is pretty racy */ | ||
473 | perm = current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG); | ||
474 | tty_kref_put(tty); | ||
471 | switch (cmd) { | 475 | switch (cmd) { |
472 | case KDGKBTYPE: | 476 | case KDGKBTYPE: |
473 | return put_user(KB_101, (char __user *)argp); | 477 | return put_user(KB_101, (char __user *)argp); |
diff --git a/drivers/s390/char/keyboard.h b/drivers/s390/char/keyboard.h index 7e736aaeae6e..f682f4e49680 100644 --- a/drivers/s390/char/keyboard.h +++ b/drivers/s390/char/keyboard.h | |||
@@ -21,7 +21,7 @@ typedef void (fn_handler_fn)(struct kbd_data *); | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | struct kbd_data { | 23 | struct kbd_data { |
24 | struct tty_struct *tty; | 24 | struct tty_port *port; |
25 | unsigned short **key_maps; | 25 | unsigned short **key_maps; |
26 | char **func_table; | 26 | char **func_table; |
27 | fn_handler_fn **fn_handler; | 27 | fn_handler_fn **fn_handler; |
@@ -42,16 +42,24 @@ int kbd_ioctl(struct kbd_data *, unsigned int, unsigned long); | |||
42 | * Helper Functions. | 42 | * Helper Functions. |
43 | */ | 43 | */ |
44 | static inline void | 44 | static inline void |
45 | kbd_put_queue(struct tty_struct *tty, int ch) | 45 | kbd_put_queue(struct tty_port *port, int ch) |
46 | { | 46 | { |
47 | struct tty_struct *tty = tty_port_tty_get(port); | ||
48 | if (!tty) | ||
49 | return; | ||
47 | tty_insert_flip_char(tty, ch, 0); | 50 | tty_insert_flip_char(tty, ch, 0); |
48 | tty_schedule_flip(tty); | 51 | tty_schedule_flip(tty); |
52 | tty_kref_put(tty); | ||
49 | } | 53 | } |
50 | 54 | ||
51 | static inline void | 55 | static inline void |
52 | kbd_puts_queue(struct tty_struct *tty, char *cp) | 56 | kbd_puts_queue(struct tty_port *port, char *cp) |
53 | { | 57 | { |
58 | struct tty_struct *tty = tty_port_tty_get(port); | ||
59 | if (!tty) | ||
60 | return; | ||
54 | while (*cp) | 61 | while (*cp) |
55 | tty_insert_flip_char(tty, *cp++, 0); | 62 | tty_insert_flip_char(tty, *cp++, 0); |
56 | tty_schedule_flip(tty); | 63 | tty_schedule_flip(tty); |
64 | tty_kref_put(tty); | ||
57 | } | 65 | } |
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c index 40a9d69c898e..e66a75b3822c 100644 --- a/drivers/s390/char/sclp_tty.c +++ b/drivers/s390/char/sclp_tty.c | |||
@@ -48,7 +48,7 @@ static struct sclp_buffer *sclp_ttybuf; | |||
48 | /* Timer for delayed output of console messages. */ | 48 | /* Timer for delayed output of console messages. */ |
49 | static struct timer_list sclp_tty_timer; | 49 | static struct timer_list sclp_tty_timer; |
50 | 50 | ||
51 | static struct tty_struct *sclp_tty; | 51 | static struct tty_port sclp_port; |
52 | static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE]; | 52 | static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE]; |
53 | static unsigned short int sclp_tty_chars_count; | 53 | static unsigned short int sclp_tty_chars_count; |
54 | 54 | ||
@@ -64,7 +64,7 @@ static int sclp_tty_columns = 80; | |||
64 | static int | 64 | static int |
65 | sclp_tty_open(struct tty_struct *tty, struct file *filp) | 65 | sclp_tty_open(struct tty_struct *tty, struct file *filp) |
66 | { | 66 | { |
67 | sclp_tty = tty; | 67 | tty_port_tty_set(&sclp_port, tty); |
68 | tty->driver_data = NULL; | 68 | tty->driver_data = NULL; |
69 | tty->low_latency = 0; | 69 | tty->low_latency = 0; |
70 | return 0; | 70 | return 0; |
@@ -76,7 +76,7 @@ sclp_tty_close(struct tty_struct *tty, struct file *filp) | |||
76 | { | 76 | { |
77 | if (tty->count > 1) | 77 | if (tty->count > 1) |
78 | return; | 78 | return; |
79 | sclp_tty = NULL; | 79 | tty_port_tty_set(&sclp_port, NULL); |
80 | } | 80 | } |
81 | 81 | ||
82 | /* | 82 | /* |
@@ -108,6 +108,7 @@ sclp_tty_write_room (struct tty_struct *tty) | |||
108 | static void | 108 | static void |
109 | sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc) | 109 | sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc) |
110 | { | 110 | { |
111 | struct tty_struct *tty; | ||
111 | unsigned long flags; | 112 | unsigned long flags; |
112 | void *page; | 113 | void *page; |
113 | 114 | ||
@@ -126,8 +127,10 @@ sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc) | |||
126 | spin_unlock_irqrestore(&sclp_tty_lock, flags); | 127 | spin_unlock_irqrestore(&sclp_tty_lock, flags); |
127 | } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback)); | 128 | } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback)); |
128 | /* check if the tty needs a wake up call */ | 129 | /* check if the tty needs a wake up call */ |
129 | if (sclp_tty != NULL) { | 130 | tty = tty_port_tty_get(&sclp_port); |
130 | tty_wakeup(sclp_tty); | 131 | if (tty != NULL) { |
132 | tty_wakeup(tty); | ||
133 | tty_kref_put(tty); | ||
131 | } | 134 | } |
132 | } | 135 | } |
133 | 136 | ||
@@ -326,21 +329,22 @@ sclp_tty_flush_buffer(struct tty_struct *tty) | |||
326 | static void | 329 | static void |
327 | sclp_tty_input(unsigned char* buf, unsigned int count) | 330 | sclp_tty_input(unsigned char* buf, unsigned int count) |
328 | { | 331 | { |
332 | struct tty_struct *tty = tty_port_tty_get(&sclp_port); | ||
329 | unsigned int cchar; | 333 | unsigned int cchar; |
330 | 334 | ||
331 | /* | 335 | /* |
332 | * If this tty driver is currently closed | 336 | * If this tty driver is currently closed |
333 | * then throw the received input away. | 337 | * then throw the received input away. |
334 | */ | 338 | */ |
335 | if (sclp_tty == NULL) | 339 | if (tty == NULL) |
336 | return; | 340 | return; |
337 | cchar = ctrlchar_handle(buf, count, sclp_tty); | 341 | cchar = ctrlchar_handle(buf, count, tty); |
338 | switch (cchar & CTRLCHAR_MASK) { | 342 | switch (cchar & CTRLCHAR_MASK) { |
339 | case CTRLCHAR_SYSRQ: | 343 | case CTRLCHAR_SYSRQ: |
340 | break; | 344 | break; |
341 | case CTRLCHAR_CTRL: | 345 | case CTRLCHAR_CTRL: |
342 | tty_insert_flip_char(sclp_tty, cchar, TTY_NORMAL); | 346 | tty_insert_flip_char(tty, cchar, TTY_NORMAL); |
343 | tty_flip_buffer_push(sclp_tty); | 347 | tty_flip_buffer_push(tty); |
344 | break; | 348 | break; |
345 | case CTRLCHAR_NONE: | 349 | case CTRLCHAR_NONE: |
346 | /* send (normal) input to line discipline */ | 350 | /* send (normal) input to line discipline */ |
@@ -348,13 +352,14 @@ sclp_tty_input(unsigned char* buf, unsigned int count) | |||
348 | (strncmp((const char *) buf + count - 2, "^n", 2) && | 352 | (strncmp((const char *) buf + count - 2, "^n", 2) && |
349 | strncmp((const char *) buf + count - 2, "\252n", 2))) { | 353 | strncmp((const char *) buf + count - 2, "\252n", 2))) { |
350 | /* add the auto \n */ | 354 | /* add the auto \n */ |
351 | tty_insert_flip_string(sclp_tty, buf, count); | 355 | tty_insert_flip_string(tty, buf, count); |
352 | tty_insert_flip_char(sclp_tty, '\n', TTY_NORMAL); | 356 | tty_insert_flip_char(tty, '\n', TTY_NORMAL); |
353 | } else | 357 | } else |
354 | tty_insert_flip_string(sclp_tty, buf, count - 2); | 358 | tty_insert_flip_string(tty, buf, count - 2); |
355 | tty_flip_buffer_push(sclp_tty); | 359 | tty_flip_buffer_push(tty); |
356 | break; | 360 | break; |
357 | } | 361 | } |
362 | tty_kref_put(tty); | ||
358 | } | 363 | } |
359 | 364 | ||
360 | /* | 365 | /* |
@@ -543,7 +548,7 @@ sclp_tty_init(void) | |||
543 | sclp_tty_tolower = 1; | 548 | sclp_tty_tolower = 1; |
544 | } | 549 | } |
545 | sclp_tty_chars_count = 0; | 550 | sclp_tty_chars_count = 0; |
546 | sclp_tty = NULL; | 551 | tty_port_init(&sclp_port); |
547 | 552 | ||
548 | rc = sclp_register(&sclp_input_event); | 553 | rc = sclp_register(&sclp_input_event); |
549 | if (rc) { | 554 | if (rc) { |
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c index b635472ae660..edfc0fd73dc6 100644 --- a/drivers/s390/char/sclp_vt220.c +++ b/drivers/s390/char/sclp_vt220.c | |||
@@ -34,7 +34,6 @@ | |||
34 | #define SCLP_VT220_DEVICE_NAME "ttysclp" | 34 | #define SCLP_VT220_DEVICE_NAME "ttysclp" |
35 | #define SCLP_VT220_CONSOLE_NAME "ttyS" | 35 | #define SCLP_VT220_CONSOLE_NAME "ttyS" |
36 | #define SCLP_VT220_CONSOLE_INDEX 1 /* console=ttyS1 */ | 36 | #define SCLP_VT220_CONSOLE_INDEX 1 /* console=ttyS1 */ |
37 | #define SCLP_VT220_BUF_SIZE 80 | ||
38 | 37 | ||
39 | /* Representation of a single write request */ | 38 | /* Representation of a single write request */ |
40 | struct sclp_vt220_request { | 39 | struct sclp_vt220_request { |
@@ -56,8 +55,7 @@ struct sclp_vt220_sccb { | |||
56 | /* Structures and data needed to register tty driver */ | 55 | /* Structures and data needed to register tty driver */ |
57 | static struct tty_driver *sclp_vt220_driver; | 56 | static struct tty_driver *sclp_vt220_driver; |
58 | 57 | ||
59 | /* The tty_struct that the kernel associated with us */ | 58 | static struct tty_port sclp_vt220_port; |
60 | static struct tty_struct *sclp_vt220_tty; | ||
61 | 59 | ||
62 | /* Lock to protect internal data from concurrent access */ | 60 | /* Lock to protect internal data from concurrent access */ |
63 | static spinlock_t sclp_vt220_lock; | 61 | static spinlock_t sclp_vt220_lock; |
@@ -116,6 +114,7 @@ static struct sclp_register sclp_vt220_register = { | |||
116 | static void | 114 | static void |
117 | sclp_vt220_process_queue(struct sclp_vt220_request *request) | 115 | sclp_vt220_process_queue(struct sclp_vt220_request *request) |
118 | { | 116 | { |
117 | struct tty_struct *tty; | ||
119 | unsigned long flags; | 118 | unsigned long flags; |
120 | void *page; | 119 | void *page; |
121 | 120 | ||
@@ -141,8 +140,10 @@ sclp_vt220_process_queue(struct sclp_vt220_request *request) | |||
141 | if (request == NULL && sclp_vt220_flush_later) | 140 | if (request == NULL && sclp_vt220_flush_later) |
142 | sclp_vt220_emit_current(); | 141 | sclp_vt220_emit_current(); |
143 | /* Check if the tty needs a wake up call */ | 142 | /* Check if the tty needs a wake up call */ |
144 | if (sclp_vt220_tty != NULL) { | 143 | tty = tty_port_tty_get(&sclp_vt220_port); |
145 | tty_wakeup(sclp_vt220_tty); | 144 | if (tty) { |
145 | tty_wakeup(tty); | ||
146 | tty_kref_put(tty); | ||
146 | } | 147 | } |
147 | } | 148 | } |
148 | 149 | ||
@@ -460,11 +461,12 @@ sclp_vt220_write(struct tty_struct *tty, const unsigned char *buf, int count) | |||
460 | static void | 461 | static void |
461 | sclp_vt220_receiver_fn(struct evbuf_header *evbuf) | 462 | sclp_vt220_receiver_fn(struct evbuf_header *evbuf) |
462 | { | 463 | { |
464 | struct tty_struct *tty = tty_port_tty_get(&sclp_vt220_port); | ||
463 | char *buffer; | 465 | char *buffer; |
464 | unsigned int count; | 466 | unsigned int count; |
465 | 467 | ||
466 | /* Ignore input if device is not open */ | 468 | /* Ignore input if device is not open */ |
467 | if (sclp_vt220_tty == NULL) | 469 | if (tty == NULL) |
468 | return; | 470 | return; |
469 | 471 | ||
470 | buffer = (char *) ((addr_t) evbuf + sizeof(struct evbuf_header)); | 472 | buffer = (char *) ((addr_t) evbuf + sizeof(struct evbuf_header)); |
@@ -478,10 +480,11 @@ sclp_vt220_receiver_fn(struct evbuf_header *evbuf) | |||
478 | /* Send input to line discipline */ | 480 | /* Send input to line discipline */ |
479 | buffer++; | 481 | buffer++; |
480 | count--; | 482 | count--; |
481 | tty_insert_flip_string(sclp_vt220_tty, buffer, count); | 483 | tty_insert_flip_string(tty, buffer, count); |
482 | tty_flip_buffer_push(sclp_vt220_tty); | 484 | tty_flip_buffer_push(tty); |
483 | break; | 485 | break; |
484 | } | 486 | } |
487 | tty_kref_put(tty); | ||
485 | } | 488 | } |
486 | 489 | ||
487 | /* | 490 | /* |
@@ -491,10 +494,7 @@ static int | |||
491 | sclp_vt220_open(struct tty_struct *tty, struct file *filp) | 494 | sclp_vt220_open(struct tty_struct *tty, struct file *filp) |
492 | { | 495 | { |
493 | if (tty->count == 1) { | 496 | if (tty->count == 1) { |
494 | sclp_vt220_tty = tty; | 497 | tty_port_tty_set(&sclp_vt220_port, tty); |
495 | tty->driver_data = kmalloc(SCLP_VT220_BUF_SIZE, GFP_KERNEL); | ||
496 | if (tty->driver_data == NULL) | ||
497 | return -ENOMEM; | ||
498 | tty->low_latency = 0; | 498 | tty->low_latency = 0; |
499 | if (!tty->winsize.ws_row && !tty->winsize.ws_col) { | 499 | if (!tty->winsize.ws_row && !tty->winsize.ws_col) { |
500 | tty->winsize.ws_row = 24; | 500 | tty->winsize.ws_row = 24; |
@@ -510,11 +510,8 @@ sclp_vt220_open(struct tty_struct *tty, struct file *filp) | |||
510 | static void | 510 | static void |
511 | sclp_vt220_close(struct tty_struct *tty, struct file *filp) | 511 | sclp_vt220_close(struct tty_struct *tty, struct file *filp) |
512 | { | 512 | { |
513 | if (tty->count == 1) { | 513 | if (tty->count == 1) |
514 | sclp_vt220_tty = NULL; | 514 | tty_port_tty_set(&sclp_vt220_port, NULL); |
515 | kfree(tty->driver_data); | ||
516 | tty->driver_data = NULL; | ||
517 | } | ||
518 | } | 515 | } |
519 | 516 | ||
520 | /* | 517 | /* |
@@ -635,9 +632,9 @@ static int __init __sclp_vt220_init(int num_pages) | |||
635 | INIT_LIST_HEAD(&sclp_vt220_empty); | 632 | INIT_LIST_HEAD(&sclp_vt220_empty); |
636 | INIT_LIST_HEAD(&sclp_vt220_outqueue); | 633 | INIT_LIST_HEAD(&sclp_vt220_outqueue); |
637 | init_timer(&sclp_vt220_timer); | 634 | init_timer(&sclp_vt220_timer); |
635 | tty_port_init(&sclp_vt220_port); | ||
638 | sclp_vt220_current_request = NULL; | 636 | sclp_vt220_current_request = NULL; |
639 | sclp_vt220_buffered_chars = 0; | 637 | sclp_vt220_buffered_chars = 0; |
640 | sclp_vt220_tty = NULL; | ||
641 | sclp_vt220_flush_later = 0; | 638 | sclp_vt220_flush_later = 0; |
642 | 639 | ||
643 | /* Allocate pages for output buffering */ | 640 | /* Allocate pages for output buffering */ |
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c index b43445a55cb6..10ec690197cb 100644 --- a/drivers/s390/char/tty3270.c +++ b/drivers/s390/char/tty3270.c | |||
@@ -61,7 +61,7 @@ struct tty3270_line { | |||
61 | */ | 61 | */ |
62 | struct tty3270 { | 62 | struct tty3270 { |
63 | struct raw3270_view view; | 63 | struct raw3270_view view; |
64 | struct tty_struct *tty; /* Pointer to tty structure */ | 64 | struct tty_port port; |
65 | void **freemem_pages; /* Array of pages used for freemem. */ | 65 | void **freemem_pages; /* Array of pages used for freemem. */ |
66 | struct list_head freemem; /* List of free memory for strings. */ | 66 | struct list_head freemem; /* List of free memory for strings. */ |
67 | 67 | ||
@@ -324,9 +324,8 @@ tty3270_blank_line(struct tty3270 *tp) | |||
324 | static void | 324 | static void |
325 | tty3270_write_callback(struct raw3270_request *rq, void *data) | 325 | tty3270_write_callback(struct raw3270_request *rq, void *data) |
326 | { | 326 | { |
327 | struct tty3270 *tp; | 327 | struct tty3270 *tp = container_of(rq->view, struct tty3270, view); |
328 | 328 | ||
329 | tp = (struct tty3270 *) rq->view; | ||
330 | if (rq->rc != 0) { | 329 | if (rq->rc != 0) { |
331 | /* Write wasn't successful. Refresh all. */ | 330 | /* Write wasn't successful. Refresh all. */ |
332 | tp->update_flags = TTY_UPDATE_ALL; | 331 | tp->update_flags = TTY_UPDATE_ALL; |
@@ -450,10 +449,9 @@ tty3270_rcl_add(struct tty3270 *tp, char *input, int len) | |||
450 | static void | 449 | static void |
451 | tty3270_rcl_backward(struct kbd_data *kbd) | 450 | tty3270_rcl_backward(struct kbd_data *kbd) |
452 | { | 451 | { |
453 | struct tty3270 *tp; | 452 | struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); |
454 | struct string *s; | 453 | struct string *s; |
455 | 454 | ||
456 | tp = kbd->tty->driver_data; | ||
457 | spin_lock_bh(&tp->view.lock); | 455 | spin_lock_bh(&tp->view.lock); |
458 | if (tp->inattr == TF_INPUT) { | 456 | if (tp->inattr == TF_INPUT) { |
459 | if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines) | 457 | if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines) |
@@ -478,9 +476,8 @@ tty3270_rcl_backward(struct kbd_data *kbd) | |||
478 | static void | 476 | static void |
479 | tty3270_exit_tty(struct kbd_data *kbd) | 477 | tty3270_exit_tty(struct kbd_data *kbd) |
480 | { | 478 | { |
481 | struct tty3270 *tp; | 479 | struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); |
482 | 480 | ||
483 | tp = kbd->tty->driver_data; | ||
484 | raw3270_deactivate_view(&tp->view); | 481 | raw3270_deactivate_view(&tp->view); |
485 | } | 482 | } |
486 | 483 | ||
@@ -490,10 +487,9 @@ tty3270_exit_tty(struct kbd_data *kbd) | |||
490 | static void | 487 | static void |
491 | tty3270_scroll_forward(struct kbd_data *kbd) | 488 | tty3270_scroll_forward(struct kbd_data *kbd) |
492 | { | 489 | { |
493 | struct tty3270 *tp; | 490 | struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); |
494 | int nr_up; | 491 | int nr_up; |
495 | 492 | ||
496 | tp = kbd->tty->driver_data; | ||
497 | spin_lock_bh(&tp->view.lock); | 493 | spin_lock_bh(&tp->view.lock); |
498 | nr_up = tp->nr_up - tp->view.rows + 2; | 494 | nr_up = tp->nr_up - tp->view.rows + 2; |
499 | if (nr_up < 0) | 495 | if (nr_up < 0) |
@@ -513,10 +509,9 @@ tty3270_scroll_forward(struct kbd_data *kbd) | |||
513 | static void | 509 | static void |
514 | tty3270_scroll_backward(struct kbd_data *kbd) | 510 | tty3270_scroll_backward(struct kbd_data *kbd) |
515 | { | 511 | { |
516 | struct tty3270 *tp; | 512 | struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); |
517 | int nr_up; | 513 | int nr_up; |
518 | 514 | ||
519 | tp = kbd->tty->driver_data; | ||
520 | spin_lock_bh(&tp->view.lock); | 515 | spin_lock_bh(&tp->view.lock); |
521 | nr_up = tp->nr_up + tp->view.rows - 2; | 516 | nr_up = tp->nr_up + tp->view.rows - 2; |
522 | if (nr_up + tp->view.rows - 2 > tp->nr_lines) | 517 | if (nr_up + tp->view.rows - 2 > tp->nr_lines) |
@@ -537,11 +532,10 @@ static void | |||
537 | tty3270_read_tasklet(struct raw3270_request *rrq) | 532 | tty3270_read_tasklet(struct raw3270_request *rrq) |
538 | { | 533 | { |
539 | static char kreset_data = TW_KR; | 534 | static char kreset_data = TW_KR; |
540 | struct tty3270 *tp; | 535 | struct tty3270 *tp = container_of(rrq->view, struct tty3270, view); |
541 | char *input; | 536 | char *input; |
542 | int len; | 537 | int len; |
543 | 538 | ||
544 | tp = (struct tty3270 *) rrq->view; | ||
545 | spin_lock_bh(&tp->view.lock); | 539 | spin_lock_bh(&tp->view.lock); |
546 | /* | 540 | /* |
547 | * Two AID keys are special: For 0x7d (enter) the input line | 541 | * Two AID keys are special: For 0x7d (enter) the input line |
@@ -577,13 +571,10 @@ tty3270_read_tasklet(struct raw3270_request *rrq) | |||
577 | raw3270_request_add_data(tp->kreset, &kreset_data, 1); | 571 | raw3270_request_add_data(tp->kreset, &kreset_data, 1); |
578 | raw3270_start(&tp->view, tp->kreset); | 572 | raw3270_start(&tp->view, tp->kreset); |
579 | 573 | ||
580 | /* Emit input string. */ | 574 | while (len-- > 0) |
581 | if (tp->tty) { | 575 | kbd_keycode(tp->kbd, *input++); |
582 | while (len-- > 0) | 576 | /* Emit keycode for AID byte. */ |
583 | kbd_keycode(tp->kbd, *input++); | 577 | kbd_keycode(tp->kbd, 256 + tp->input->string[0]); |
584 | /* Emit keycode for AID byte. */ | ||
585 | kbd_keycode(tp->kbd, 256 + tp->input->string[0]); | ||
586 | } | ||
587 | 578 | ||
588 | raw3270_request_reset(rrq); | 579 | raw3270_request_reset(rrq); |
589 | xchg(&tp->read, rrq); | 580 | xchg(&tp->read, rrq); |
@@ -596,9 +587,10 @@ tty3270_read_tasklet(struct raw3270_request *rrq) | |||
596 | static void | 587 | static void |
597 | tty3270_read_callback(struct raw3270_request *rq, void *data) | 588 | tty3270_read_callback(struct raw3270_request *rq, void *data) |
598 | { | 589 | { |
590 | struct tty3270 *tp = container_of(rq->view, struct tty3270, view); | ||
599 | raw3270_get_view(rq->view); | 591 | raw3270_get_view(rq->view); |
600 | /* Schedule tasklet to pass input to tty. */ | 592 | /* Schedule tasklet to pass input to tty. */ |
601 | tasklet_schedule(&((struct tty3270 *) rq->view)->readlet); | 593 | tasklet_schedule(&tp->readlet); |
602 | } | 594 | } |
603 | 595 | ||
604 | /* | 596 | /* |
@@ -635,9 +627,8 @@ tty3270_issue_read(struct tty3270 *tp, int lock) | |||
635 | static int | 627 | static int |
636 | tty3270_activate(struct raw3270_view *view) | 628 | tty3270_activate(struct raw3270_view *view) |
637 | { | 629 | { |
638 | struct tty3270 *tp; | 630 | struct tty3270 *tp = container_of(view, struct tty3270, view); |
639 | 631 | ||
640 | tp = (struct tty3270 *) view; | ||
641 | tp->update_flags = TTY_UPDATE_ALL; | 632 | tp->update_flags = TTY_UPDATE_ALL; |
642 | tty3270_set_timer(tp, 1); | 633 | tty3270_set_timer(tp, 1); |
643 | return 0; | 634 | return 0; |
@@ -646,9 +637,8 @@ tty3270_activate(struct raw3270_view *view) | |||
646 | static void | 637 | static void |
647 | tty3270_deactivate(struct raw3270_view *view) | 638 | tty3270_deactivate(struct raw3270_view *view) |
648 | { | 639 | { |
649 | struct tty3270 *tp; | 640 | struct tty3270 *tp = container_of(view, struct tty3270, view); |
650 | 641 | ||
651 | tp = (struct tty3270 *) view; | ||
652 | del_timer(&tp->timer); | 642 | del_timer(&tp->timer); |
653 | } | 643 | } |
654 | 644 | ||
@@ -690,6 +680,17 @@ tty3270_alloc_view(void) | |||
690 | if (!tp->freemem_pages) | 680 | if (!tp->freemem_pages) |
691 | goto out_tp; | 681 | goto out_tp; |
692 | INIT_LIST_HEAD(&tp->freemem); | 682 | INIT_LIST_HEAD(&tp->freemem); |
683 | INIT_LIST_HEAD(&tp->lines); | ||
684 | INIT_LIST_HEAD(&tp->update); | ||
685 | INIT_LIST_HEAD(&tp->rcl_lines); | ||
686 | tp->rcl_max = 20; | ||
687 | tty_port_init(&tp->port); | ||
688 | setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update, | ||
689 | (unsigned long) tp); | ||
690 | tasklet_init(&tp->readlet, | ||
691 | (void (*)(unsigned long)) tty3270_read_tasklet, | ||
692 | (unsigned long) tp->read); | ||
693 | |||
693 | for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) { | 694 | for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) { |
694 | tp->freemem_pages[pages] = (void *) | 695 | tp->freemem_pages[pages] = (void *) |
695 | __get_free_pages(GFP_KERNEL|GFP_DMA, 0); | 696 | __get_free_pages(GFP_KERNEL|GFP_DMA, 0); |
@@ -794,16 +795,15 @@ tty3270_free_screen(struct tty3270 *tp) | |||
794 | static void | 795 | static void |
795 | tty3270_release(struct raw3270_view *view) | 796 | tty3270_release(struct raw3270_view *view) |
796 | { | 797 | { |
797 | struct tty3270 *tp; | 798 | struct tty3270 *tp = container_of(view, struct tty3270, view); |
798 | struct tty_struct *tty; | 799 | struct tty_struct *tty = tty_port_tty_get(&tp->port); |
799 | 800 | ||
800 | tp = (struct tty3270 *) view; | ||
801 | tty = tp->tty; | ||
802 | if (tty) { | 801 | if (tty) { |
803 | tty->driver_data = NULL; | 802 | tty->driver_data = NULL; |
804 | tp->tty = tp->kbd->tty = NULL; | 803 | tty_port_tty_set(&tp->port, NULL); |
805 | tty_hangup(tty); | 804 | tty_hangup(tty); |
806 | raw3270_put_view(&tp->view); | 805 | raw3270_put_view(&tp->view); |
806 | tty_kref_put(tty); | ||
807 | } | 807 | } |
808 | } | 808 | } |
809 | 809 | ||
@@ -813,8 +813,9 @@ tty3270_release(struct raw3270_view *view) | |||
813 | static void | 813 | static void |
814 | tty3270_free(struct raw3270_view *view) | 814 | tty3270_free(struct raw3270_view *view) |
815 | { | 815 | { |
816 | tty3270_free_screen((struct tty3270 *) view); | 816 | struct tty3270 *tp = container_of(view, struct tty3270, view); |
817 | tty3270_free_view((struct tty3270 *) view); | 817 | tty3270_free_screen(tp); |
818 | tty3270_free_view(tp); | ||
818 | } | 819 | } |
819 | 820 | ||
820 | /* | 821 | /* |
@@ -823,14 +824,13 @@ tty3270_free(struct raw3270_view *view) | |||
823 | static void | 824 | static void |
824 | tty3270_del_views(void) | 825 | tty3270_del_views(void) |
825 | { | 826 | { |
826 | struct tty3270 *tp; | ||
827 | int i; | 827 | int i; |
828 | 828 | ||
829 | for (i = 0; i < tty3270_max_index; i++) { | 829 | for (i = 0; i < tty3270_max_index; i++) { |
830 | tp = (struct tty3270 *) | 830 | struct raw3270_view *view = |
831 | raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR); | 831 | raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR); |
832 | if (!IS_ERR(tp)) | 832 | if (!IS_ERR(view)) |
833 | raw3270_del_view(&tp->view); | 833 | raw3270_del_view(view); |
834 | } | 834 | } |
835 | } | 835 | } |
836 | 836 | ||
@@ -848,22 +848,23 @@ static struct raw3270_fn tty3270_fn = { | |||
848 | static int | 848 | static int |
849 | tty3270_open(struct tty_struct *tty, struct file * filp) | 849 | tty3270_open(struct tty_struct *tty, struct file * filp) |
850 | { | 850 | { |
851 | struct raw3270_view *view; | ||
851 | struct tty3270 *tp; | 852 | struct tty3270 *tp; |
852 | int i, rc; | 853 | int i, rc; |
853 | 854 | ||
854 | if (tty->count > 1) | 855 | if (tty->count > 1) |
855 | return 0; | 856 | return 0; |
856 | /* Check if the tty3270 is already there. */ | 857 | /* Check if the tty3270 is already there. */ |
857 | tp = (struct tty3270 *) | 858 | view = raw3270_find_view(&tty3270_fn, |
858 | raw3270_find_view(&tty3270_fn, | ||
859 | tty->index + RAW3270_FIRSTMINOR); | 859 | tty->index + RAW3270_FIRSTMINOR); |
860 | if (!IS_ERR(tp)) { | 860 | if (!IS_ERR(view)) { |
861 | tp = container_of(view, struct tty3270, view); | ||
861 | tty->driver_data = tp; | 862 | tty->driver_data = tp; |
862 | tty->winsize.ws_row = tp->view.rows - 2; | 863 | tty->winsize.ws_row = tp->view.rows - 2; |
863 | tty->winsize.ws_col = tp->view.cols; | 864 | tty->winsize.ws_col = tp->view.cols; |
864 | tty->low_latency = 0; | 865 | tty->low_latency = 0; |
865 | tp->tty = tty; | 866 | /* why to reassign? */ |
866 | tp->kbd->tty = tty; | 867 | tty_port_tty_set(&tp->port, tty); |
867 | tp->inattr = TF_INPUT; | 868 | tp->inattr = TF_INPUT; |
868 | return 0; | 869 | return 0; |
869 | } | 870 | } |
@@ -871,7 +872,7 @@ tty3270_open(struct tty_struct *tty, struct file * filp) | |||
871 | tty3270_max_index = tty->index + 1; | 872 | tty3270_max_index = tty->index + 1; |
872 | 873 | ||
873 | /* Quick exit if there is no device for tty->index. */ | 874 | /* Quick exit if there is no device for tty->index. */ |
874 | if (PTR_ERR(tp) == -ENODEV) | 875 | if (PTR_ERR(view) == -ENODEV) |
875 | return -ENODEV; | 876 | return -ENODEV; |
876 | 877 | ||
877 | /* Allocate tty3270 structure on first open. */ | 878 | /* Allocate tty3270 structure on first open. */ |
@@ -879,16 +880,6 @@ tty3270_open(struct tty_struct *tty, struct file * filp) | |||
879 | if (IS_ERR(tp)) | 880 | if (IS_ERR(tp)) |
880 | return PTR_ERR(tp); | 881 | return PTR_ERR(tp); |
881 | 882 | ||
882 | INIT_LIST_HEAD(&tp->lines); | ||
883 | INIT_LIST_HEAD(&tp->update); | ||
884 | INIT_LIST_HEAD(&tp->rcl_lines); | ||
885 | tp->rcl_max = 20; | ||
886 | setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update, | ||
887 | (unsigned long) tp); | ||
888 | tasklet_init(&tp->readlet, | ||
889 | (void (*)(unsigned long)) tty3270_read_tasklet, | ||
890 | (unsigned long) tp->read); | ||
891 | |||
892 | rc = raw3270_add_view(&tp->view, &tty3270_fn, | 883 | rc = raw3270_add_view(&tp->view, &tty3270_fn, |
893 | tty->index + RAW3270_FIRSTMINOR); | 884 | tty->index + RAW3270_FIRSTMINOR); |
894 | if (rc) { | 885 | if (rc) { |
@@ -903,7 +894,7 @@ tty3270_open(struct tty_struct *tty, struct file * filp) | |||
903 | return rc; | 894 | return rc; |
904 | } | 895 | } |
905 | 896 | ||
906 | tp->tty = tty; | 897 | tty_port_tty_set(&tp->port, tty); |
907 | tty->low_latency = 0; | 898 | tty->low_latency = 0; |
908 | tty->driver_data = tp; | 899 | tty->driver_data = tp; |
909 | tty->winsize.ws_row = tp->view.rows - 2; | 900 | tty->winsize.ws_row = tp->view.rows - 2; |
@@ -917,7 +908,7 @@ tty3270_open(struct tty_struct *tty, struct file * filp) | |||
917 | for (i = 0; i < tp->view.rows - 2; i++) | 908 | for (i = 0; i < tp->view.rows - 2; i++) |
918 | tty3270_blank_line(tp); | 909 | tty3270_blank_line(tp); |
919 | 910 | ||
920 | tp->kbd->tty = tty; | 911 | tp->kbd->port = &tp->port; |
921 | tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty; | 912 | tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty; |
922 | tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward; | 913 | tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward; |
923 | tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward; | 914 | tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward; |
@@ -935,14 +926,13 @@ tty3270_open(struct tty_struct *tty, struct file * filp) | |||
935 | static void | 926 | static void |
936 | tty3270_close(struct tty_struct *tty, struct file * filp) | 927 | tty3270_close(struct tty_struct *tty, struct file * filp) |
937 | { | 928 | { |
938 | struct tty3270 *tp; | 929 | struct tty3270 *tp = tty->driver_data; |
939 | 930 | ||
940 | if (tty->count > 1) | 931 | if (tty->count > 1) |
941 | return; | 932 | return; |
942 | tp = (struct tty3270 *) tty->driver_data; | ||
943 | if (tp) { | 933 | if (tp) { |
944 | tty->driver_data = NULL; | 934 | tty->driver_data = NULL; |
945 | tp->tty = tp->kbd->tty = NULL; | 935 | tty_port_tty_set(&tp->port, NULL); |
946 | raw3270_put_view(&tp->view); | 936 | raw3270_put_view(&tp->view); |
947 | } | 937 | } |
948 | } | 938 | } |
@@ -1391,7 +1381,7 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch) | |||
1391 | tty3270_lf(tp); | 1381 | tty3270_lf(tp); |
1392 | break; | 1382 | break; |
1393 | case 'Z': /* Respond ID. */ | 1383 | case 'Z': /* Respond ID. */ |
1394 | kbd_puts_queue(tp->tty, "\033[?6c"); | 1384 | kbd_puts_queue(&tp->port, "\033[?6c"); |
1395 | break; | 1385 | break; |
1396 | case '7': /* Save cursor position. */ | 1386 | case '7': /* Save cursor position. */ |
1397 | tp->saved_cx = tp->cx; | 1387 | tp->saved_cx = tp->cx; |
@@ -1437,11 +1427,11 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch) | |||
1437 | tp->esc_state = ESnormal; | 1427 | tp->esc_state = ESnormal; |
1438 | if (ch == 'n' && !tp->esc_ques) { | 1428 | if (ch == 'n' && !tp->esc_ques) { |
1439 | if (tp->esc_par[0] == 5) /* Status report. */ | 1429 | if (tp->esc_par[0] == 5) /* Status report. */ |
1440 | kbd_puts_queue(tp->tty, "\033[0n"); | 1430 | kbd_puts_queue(&tp->port, "\033[0n"); |
1441 | else if (tp->esc_par[0] == 6) { /* Cursor report. */ | 1431 | else if (tp->esc_par[0] == 6) { /* Cursor report. */ |
1442 | char buf[40]; | 1432 | char buf[40]; |
1443 | sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1); | 1433 | sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1); |
1444 | kbd_puts_queue(tp->tty, buf); | 1434 | kbd_puts_queue(&tp->port, buf); |
1445 | } | 1435 | } |
1446 | return; | 1436 | return; |
1447 | } | 1437 | } |
@@ -1513,12 +1503,13 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch) | |||
1513 | * String write routine for 3270 ttys | 1503 | * String write routine for 3270 ttys |
1514 | */ | 1504 | */ |
1515 | static void | 1505 | static void |
1516 | tty3270_do_write(struct tty3270 *tp, const unsigned char *buf, int count) | 1506 | tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty, |
1507 | const unsigned char *buf, int count) | ||
1517 | { | 1508 | { |
1518 | int i_msg, i; | 1509 | int i_msg, i; |
1519 | 1510 | ||
1520 | spin_lock_bh(&tp->view.lock); | 1511 | spin_lock_bh(&tp->view.lock); |
1521 | for (i_msg = 0; !tp->tty->stopped && i_msg < count; i_msg++) { | 1512 | for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) { |
1522 | if (tp->esc_state != 0) { | 1513 | if (tp->esc_state != 0) { |
1523 | /* Continue escape sequence. */ | 1514 | /* Continue escape sequence. */ |
1524 | tty3270_escape_sequence(tp, buf[i_msg]); | 1515 | tty3270_escape_sequence(tp, buf[i_msg]); |
@@ -1595,10 +1586,10 @@ tty3270_write(struct tty_struct * tty, | |||
1595 | if (!tp) | 1586 | if (!tp) |
1596 | return 0; | 1587 | return 0; |
1597 | if (tp->char_count > 0) { | 1588 | if (tp->char_count > 0) { |
1598 | tty3270_do_write(tp, tp->char_buf, tp->char_count); | 1589 | tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); |
1599 | tp->char_count = 0; | 1590 | tp->char_count = 0; |
1600 | } | 1591 | } |
1601 | tty3270_do_write(tp, buf, count); | 1592 | tty3270_do_write(tp, tty, buf, count); |
1602 | return count; | 1593 | return count; |
1603 | } | 1594 | } |
1604 | 1595 | ||
@@ -1629,7 +1620,7 @@ tty3270_flush_chars(struct tty_struct *tty) | |||
1629 | if (!tp) | 1620 | if (!tp) |
1630 | return; | 1621 | return; |
1631 | if (tp->char_count > 0) { | 1622 | if (tp->char_count > 0) { |
1632 | tty3270_do_write(tp, tp->char_buf, tp->char_count); | 1623 | tty3270_do_write(tp, tty, tp->char_buf, tp->char_count); |
1633 | tp->char_count = 0; | 1624 | tp->char_count = 0; |
1634 | } | 1625 | } |
1635 | } | 1626 | } |
diff --git a/drivers/staging/serial/68360serial.c b/drivers/staging/serial/68360serial.c index daf0b1d0dc28..23ee50e25e44 100644 --- a/drivers/staging/serial/68360serial.c +++ b/drivers/staging/serial/68360serial.c | |||
@@ -1859,9 +1859,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, | |||
1859 | printk("block_til_ready blocking: ttys%d, count = %d\n", | 1859 | printk("block_til_ready blocking: ttys%d, count = %d\n", |
1860 | info->line, state->count); | 1860 | info->line, state->count); |
1861 | #endif | 1861 | #endif |
1862 | tty_unlock(); | 1862 | tty_unlock(tty); |
1863 | schedule(); | 1863 | schedule(); |
1864 | tty_lock(); | 1864 | tty_lock(tty); |
1865 | } | 1865 | } |
1866 | current->state = TASK_RUNNING; | 1866 | current->state = TASK_RUNNING; |
1867 | remove_wait_queue(&info->open_wait, &wait); | 1867 | remove_wait_queue(&info->open_wait, &wait); |
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c index 6cc4358f68c1..35819e312624 100644 --- a/drivers/tty/amiserial.c +++ b/drivers/tty/amiserial.c | |||
@@ -1033,7 +1033,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1033 | if (!retinfo) | 1033 | if (!retinfo) |
1034 | return -EFAULT; | 1034 | return -EFAULT; |
1035 | memset(&tmp, 0, sizeof(tmp)); | 1035 | memset(&tmp, 0, sizeof(tmp)); |
1036 | tty_lock(); | 1036 | tty_lock(tty); |
1037 | tmp.line = tty->index; | 1037 | tmp.line = tty->index; |
1038 | tmp.port = state->port; | 1038 | tmp.port = state->port; |
1039 | tmp.flags = state->tport.flags; | 1039 | tmp.flags = state->tport.flags; |
@@ -1042,7 +1042,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1042 | tmp.close_delay = state->tport.close_delay; | 1042 | tmp.close_delay = state->tport.close_delay; |
1043 | tmp.closing_wait = state->tport.closing_wait; | 1043 | tmp.closing_wait = state->tport.closing_wait; |
1044 | tmp.custom_divisor = state->custom_divisor; | 1044 | tmp.custom_divisor = state->custom_divisor; |
1045 | tty_unlock(); | 1045 | tty_unlock(tty); |
1046 | if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) | 1046 | if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) |
1047 | return -EFAULT; | 1047 | return -EFAULT; |
1048 | return 0; | 1048 | return 0; |
@@ -1059,12 +1059,12 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1059 | if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) | 1059 | if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) |
1060 | return -EFAULT; | 1060 | return -EFAULT; |
1061 | 1061 | ||
1062 | tty_lock(); | 1062 | tty_lock(tty); |
1063 | change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || | 1063 | change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || |
1064 | new_serial.custom_divisor != state->custom_divisor; | 1064 | new_serial.custom_divisor != state->custom_divisor; |
1065 | if (new_serial.irq || new_serial.port != state->port || | 1065 | if (new_serial.irq || new_serial.port != state->port || |
1066 | new_serial.xmit_fifo_size != state->xmit_fifo_size) { | 1066 | new_serial.xmit_fifo_size != state->xmit_fifo_size) { |
1067 | tty_unlock(); | 1067 | tty_unlock(tty); |
1068 | return -EINVAL; | 1068 | return -EINVAL; |
1069 | } | 1069 | } |
1070 | 1070 | ||
@@ -1074,7 +1074,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1074 | (new_serial.xmit_fifo_size != state->xmit_fifo_size) || | 1074 | (new_serial.xmit_fifo_size != state->xmit_fifo_size) || |
1075 | ((new_serial.flags & ~ASYNC_USR_MASK) != | 1075 | ((new_serial.flags & ~ASYNC_USR_MASK) != |
1076 | (port->flags & ~ASYNC_USR_MASK))) { | 1076 | (port->flags & ~ASYNC_USR_MASK))) { |
1077 | tty_unlock(); | 1077 | tty_unlock(tty); |
1078 | return -EPERM; | 1078 | return -EPERM; |
1079 | } | 1079 | } |
1080 | port->flags = ((port->flags & ~ASYNC_USR_MASK) | | 1080 | port->flags = ((port->flags & ~ASYNC_USR_MASK) | |
@@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, | |||
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | if (new_serial.baud_base < 9600) { | 1086 | if (new_serial.baud_base < 9600) { |
1087 | tty_unlock(); | 1087 | tty_unlock(tty); |
1088 | return -EINVAL; | 1088 | return -EINVAL; |
1089 | } | 1089 | } |
1090 | 1090 | ||
@@ -1116,7 +1116,7 @@ check_and_exit: | |||
1116 | } | 1116 | } |
1117 | } else | 1117 | } else |
1118 | retval = startup(tty, state); | 1118 | retval = startup(tty, state); |
1119 | tty_unlock(); | 1119 | tty_unlock(tty); |
1120 | return retval; | 1120 | return retval; |
1121 | } | 1121 | } |
1122 | 1122 | ||
diff --git a/drivers/tty/bfin_jtag_comm.c b/drivers/tty/bfin_jtag_comm.c index 946f799861f5..61fc74fe1747 100644 --- a/drivers/tty/bfin_jtag_comm.c +++ b/drivers/tty/bfin_jtag_comm.c | |||
@@ -62,9 +62,7 @@ static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d) | |||
62 | 62 | ||
63 | static struct tty_driver *bfin_jc_driver; | 63 | static struct tty_driver *bfin_jc_driver; |
64 | static struct task_struct *bfin_jc_kthread; | 64 | static struct task_struct *bfin_jc_kthread; |
65 | static struct tty_struct * volatile bfin_jc_tty; | 65 | static struct tty_port port; |
66 | static unsigned long bfin_jc_count; | ||
67 | static DEFINE_MUTEX(bfin_jc_tty_mutex); | ||
68 | static volatile struct circ_buf bfin_jc_write_buf; | 66 | static volatile struct circ_buf bfin_jc_write_buf; |
69 | 67 | ||
70 | static int | 68 | static int |
@@ -73,18 +71,21 @@ bfin_jc_emudat_manager(void *arg) | |||
73 | uint32_t inbound_len = 0, outbound_len = 0; | 71 | uint32_t inbound_len = 0, outbound_len = 0; |
74 | 72 | ||
75 | while (!kthread_should_stop()) { | 73 | while (!kthread_should_stop()) { |
74 | struct tty_struct *tty = tty_port_tty_get(&port); | ||
76 | /* no one left to give data to, so sleep */ | 75 | /* no one left to give data to, so sleep */ |
77 | if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { | 76 | if (tty == NULL && circ_empty(&bfin_jc_write_buf)) { |
78 | pr_debug("waiting for readers\n"); | 77 | pr_debug("waiting for readers\n"); |
79 | __set_current_state(TASK_UNINTERRUPTIBLE); | 78 | __set_current_state(TASK_UNINTERRUPTIBLE); |
80 | schedule(); | 79 | schedule(); |
81 | __set_current_state(TASK_RUNNING); | 80 | __set_current_state(TASK_RUNNING); |
81 | continue; | ||
82 | } | 82 | } |
83 | 83 | ||
84 | /* no data available, so just chill */ | 84 | /* no data available, so just chill */ |
85 | if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { | 85 | if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { |
86 | pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n", | 86 | pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n", |
87 | inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); | 87 | inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); |
88 | tty_kref_put(tty); | ||
88 | if (inbound_len) | 89 | if (inbound_len) |
89 | schedule(); | 90 | schedule(); |
90 | else | 91 | else |
@@ -94,9 +95,6 @@ bfin_jc_emudat_manager(void *arg) | |||
94 | 95 | ||
95 | /* if incoming data is ready, eat it */ | 96 | /* if incoming data is ready, eat it */ |
96 | if (bfin_read_DBGSTAT() & EMUDIF) { | 97 | if (bfin_read_DBGSTAT() & EMUDIF) { |
97 | struct tty_struct *tty; | ||
98 | mutex_lock(&bfin_jc_tty_mutex); | ||
99 | tty = (struct tty_struct *)bfin_jc_tty; | ||
100 | if (tty != NULL) { | 98 | if (tty != NULL) { |
101 | uint32_t emudat = bfin_read_emudat(); | 99 | uint32_t emudat = bfin_read_emudat(); |
102 | if (inbound_len == 0) { | 100 | if (inbound_len == 0) { |
@@ -110,7 +108,6 @@ bfin_jc_emudat_manager(void *arg) | |||
110 | tty_flip_buffer_push(tty); | 108 | tty_flip_buffer_push(tty); |
111 | } | 109 | } |
112 | } | 110 | } |
113 | mutex_unlock(&bfin_jc_tty_mutex); | ||
114 | } | 111 | } |
115 | 112 | ||
116 | /* if outgoing data is ready, post it */ | 113 | /* if outgoing data is ready, post it */ |
@@ -120,7 +117,6 @@ bfin_jc_emudat_manager(void *arg) | |||
120 | bfin_write_emudat(outbound_len); | 117 | bfin_write_emudat(outbound_len); |
121 | pr_debug("outgoing length: 0x%08x\n", outbound_len); | 118 | pr_debug("outgoing length: 0x%08x\n", outbound_len); |
122 | } else { | 119 | } else { |
123 | struct tty_struct *tty; | ||
124 | int tail = bfin_jc_write_buf.tail; | 120 | int tail = bfin_jc_write_buf.tail; |
125 | size_t ate = (4 <= outbound_len ? 4 : outbound_len); | 121 | size_t ate = (4 <= outbound_len ? 4 : outbound_len); |
126 | uint32_t emudat = | 122 | uint32_t emudat = |
@@ -132,14 +128,12 @@ bfin_jc_emudat_manager(void *arg) | |||
132 | ); | 128 | ); |
133 | bfin_jc_write_buf.tail += ate; | 129 | bfin_jc_write_buf.tail += ate; |
134 | outbound_len -= ate; | 130 | outbound_len -= ate; |
135 | mutex_lock(&bfin_jc_tty_mutex); | ||
136 | tty = (struct tty_struct *)bfin_jc_tty; | ||
137 | if (tty) | 131 | if (tty) |
138 | tty_wakeup(tty); | 132 | tty_wakeup(tty); |
139 | mutex_unlock(&bfin_jc_tty_mutex); | ||
140 | pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); | 133 | pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); |
141 | } | 134 | } |
142 | } | 135 | } |
136 | tty_kref_put(tty); | ||
143 | } | 137 | } |
144 | 138 | ||
145 | __set_current_state(TASK_RUNNING); | 139 | __set_current_state(TASK_RUNNING); |
@@ -149,24 +143,28 @@ bfin_jc_emudat_manager(void *arg) | |||
149 | static int | 143 | static int |
150 | bfin_jc_open(struct tty_struct *tty, struct file *filp) | 144 | bfin_jc_open(struct tty_struct *tty, struct file *filp) |
151 | { | 145 | { |
152 | mutex_lock(&bfin_jc_tty_mutex); | 146 | unsigned long flags; |
153 | pr_debug("open %lu\n", bfin_jc_count); | 147 | |
154 | ++bfin_jc_count; | 148 | spin_lock_irqsave(&port.lock, flags); |
155 | bfin_jc_tty = tty; | 149 | port.count++; |
150 | spin_unlock_irqrestore(&port.lock, flags); | ||
151 | tty_port_tty_set(&port, tty); | ||
156 | wake_up_process(bfin_jc_kthread); | 152 | wake_up_process(bfin_jc_kthread); |
157 | mutex_unlock(&bfin_jc_tty_mutex); | ||
158 | return 0; | 153 | return 0; |
159 | } | 154 | } |
160 | 155 | ||
161 | static void | 156 | static void |
162 | bfin_jc_close(struct tty_struct *tty, struct file *filp) | 157 | bfin_jc_close(struct tty_struct *tty, struct file *filp) |
163 | { | 158 | { |
164 | mutex_lock(&bfin_jc_tty_mutex); | 159 | unsigned long flags; |
165 | pr_debug("close %lu\n", bfin_jc_count); | 160 | bool last; |
166 | if (--bfin_jc_count == 0) | 161 | |
167 | bfin_jc_tty = NULL; | 162 | spin_lock_irqsave(&port.lock, flags); |
163 | last = --port.count == 0; | ||
164 | spin_unlock_irqrestore(&port.lock, flags); | ||
165 | if (last) | ||
166 | tty_port_tty_set(&port, NULL); | ||
168 | wake_up_process(bfin_jc_kthread); | 167 | wake_up_process(bfin_jc_kthread); |
169 | mutex_unlock(&bfin_jc_tty_mutex); | ||
170 | } | 168 | } |
171 | 169 | ||
172 | /* XXX: we dont handle the put_char() case where we must handle count = 1 */ | 170 | /* XXX: we dont handle the put_char() case where we must handle count = 1 */ |
@@ -242,6 +240,8 @@ static int __init bfin_jc_init(void) | |||
242 | { | 240 | { |
243 | int ret; | 241 | int ret; |
244 | 242 | ||
243 | tty_port_init(&port); | ||
244 | |||
245 | bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); | 245 | bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); |
246 | if (IS_ERR(bfin_jc_kthread)) | 246 | if (IS_ERR(bfin_jc_kthread)) |
247 | return PTR_ERR(bfin_jc_kthread); | 247 | return PTR_ERR(bfin_jc_kthread); |
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c index e61cabdd69df..6984e1a2686a 100644 --- a/drivers/tty/cyclades.c +++ b/drivers/tty/cyclades.c | |||
@@ -1599,7 +1599,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp) | |||
1599 | * If the port is the middle of closing, bail out now | 1599 | * If the port is the middle of closing, bail out now |
1600 | */ | 1600 | */ |
1601 | if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { | 1601 | if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { |
1602 | wait_event_interruptible_tty(info->port.close_wait, | 1602 | wait_event_interruptible_tty(tty, info->port.close_wait, |
1603 | !(info->port.flags & ASYNC_CLOSING)); | 1603 | !(info->port.flags & ASYNC_CLOSING)); |
1604 | return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; | 1604 | return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; |
1605 | } | 1605 | } |
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 8880adf5fc6f..2d691eb7c40a 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c | |||
@@ -107,7 +107,7 @@ static struct hvc_struct *hvc_get_by_index(int index) | |||
107 | list_for_each_entry(hp, &hvc_structs, next) { | 107 | list_for_each_entry(hp, &hvc_structs, next) { |
108 | spin_lock_irqsave(&hp->lock, flags); | 108 | spin_lock_irqsave(&hp->lock, flags); |
109 | if (hp->index == index) { | 109 | if (hp->index == index) { |
110 | kref_get(&hp->kref); | 110 | tty_port_get(&hp->port); |
111 | spin_unlock_irqrestore(&hp->lock, flags); | 111 | spin_unlock_irqrestore(&hp->lock, flags); |
112 | spin_unlock(&hvc_structs_lock); | 112 | spin_unlock(&hvc_structs_lock); |
113 | return hp; | 113 | return hp; |
@@ -229,9 +229,9 @@ static int __init hvc_console_init(void) | |||
229 | console_initcall(hvc_console_init); | 229 | console_initcall(hvc_console_init); |
230 | 230 | ||
231 | /* callback when the kboject ref count reaches zero. */ | 231 | /* callback when the kboject ref count reaches zero. */ |
232 | static void destroy_hvc_struct(struct kref *kref) | 232 | static void hvc_port_destruct(struct tty_port *port) |
233 | { | 233 | { |
234 | struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref); | 234 | struct hvc_struct *hp = container_of(port, struct hvc_struct, port); |
235 | unsigned long flags; | 235 | unsigned long flags; |
236 | 236 | ||
237 | spin_lock(&hvc_structs_lock); | 237 | spin_lock(&hvc_structs_lock); |
@@ -264,7 +264,7 @@ int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops) | |||
264 | /* make sure no no tty has been registered in this index */ | 264 | /* make sure no no tty has been registered in this index */ |
265 | hp = hvc_get_by_index(index); | 265 | hp = hvc_get_by_index(index); |
266 | if (hp) { | 266 | if (hp) { |
267 | kref_put(&hp->kref, destroy_hvc_struct); | 267 | tty_port_put(&hp->port); |
268 | return -1; | 268 | return -1; |
269 | } | 269 | } |
270 | 270 | ||
@@ -313,20 +313,17 @@ static int hvc_open(struct tty_struct *tty, struct file * filp) | |||
313 | if (!(hp = hvc_get_by_index(tty->index))) | 313 | if (!(hp = hvc_get_by_index(tty->index))) |
314 | return -ENODEV; | 314 | return -ENODEV; |
315 | 315 | ||
316 | spin_lock_irqsave(&hp->lock, flags); | 316 | spin_lock_irqsave(&hp->port.lock, flags); |
317 | /* Check and then increment for fast path open. */ | 317 | /* Check and then increment for fast path open. */ |
318 | if (hp->count++ > 0) { | 318 | if (hp->port.count++ > 0) { |
319 | tty_kref_get(tty); | 319 | spin_unlock_irqrestore(&hp->port.lock, flags); |
320 | spin_unlock_irqrestore(&hp->lock, flags); | ||
321 | hvc_kick(); | 320 | hvc_kick(); |
322 | return 0; | 321 | return 0; |
323 | } /* else count == 0 */ | 322 | } /* else count == 0 */ |
323 | spin_unlock_irqrestore(&hp->port.lock, flags); | ||
324 | 324 | ||
325 | tty->driver_data = hp; | 325 | tty->driver_data = hp; |
326 | 326 | tty_port_tty_set(&hp->port, tty); | |
327 | hp->tty = tty_kref_get(tty); | ||
328 | |||
329 | spin_unlock_irqrestore(&hp->lock, flags); | ||
330 | 327 | ||
331 | if (hp->ops->notifier_add) | 328 | if (hp->ops->notifier_add) |
332 | rc = hp->ops->notifier_add(hp, hp->data); | 329 | rc = hp->ops->notifier_add(hp, hp->data); |
@@ -338,12 +335,9 @@ static int hvc_open(struct tty_struct *tty, struct file * filp) | |||
338 | * tty fields and return the kref reference. | 335 | * tty fields and return the kref reference. |
339 | */ | 336 | */ |
340 | if (rc) { | 337 | if (rc) { |
341 | spin_lock_irqsave(&hp->lock, flags); | 338 | tty_port_tty_set(&hp->port, NULL); |
342 | hp->tty = NULL; | ||
343 | spin_unlock_irqrestore(&hp->lock, flags); | ||
344 | tty_kref_put(tty); | ||
345 | tty->driver_data = NULL; | 339 | tty->driver_data = NULL; |
346 | kref_put(&hp->kref, destroy_hvc_struct); | 340 | tty_port_put(&hp->port); |
347 | printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); | 341 | printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); |
348 | } | 342 | } |
349 | /* Force wakeup of the polling thread */ | 343 | /* Force wakeup of the polling thread */ |
@@ -370,12 +364,12 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) | |||
370 | 364 | ||
371 | hp = tty->driver_data; | 365 | hp = tty->driver_data; |
372 | 366 | ||
373 | spin_lock_irqsave(&hp->lock, flags); | 367 | spin_lock_irqsave(&hp->port.lock, flags); |
374 | 368 | ||
375 | if (--hp->count == 0) { | 369 | if (--hp->port.count == 0) { |
370 | spin_unlock_irqrestore(&hp->port.lock, flags); | ||
376 | /* We are done with the tty pointer now. */ | 371 | /* We are done with the tty pointer now. */ |
377 | hp->tty = NULL; | 372 | tty_port_tty_set(&hp->port, NULL); |
378 | spin_unlock_irqrestore(&hp->lock, flags); | ||
379 | 373 | ||
380 | if (hp->ops->notifier_del) | 374 | if (hp->ops->notifier_del) |
381 | hp->ops->notifier_del(hp, hp->data); | 375 | hp->ops->notifier_del(hp, hp->data); |
@@ -390,14 +384,13 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) | |||
390 | */ | 384 | */ |
391 | tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); | 385 | tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); |
392 | } else { | 386 | } else { |
393 | if (hp->count < 0) | 387 | if (hp->port.count < 0) |
394 | printk(KERN_ERR "hvc_close %X: oops, count is %d\n", | 388 | printk(KERN_ERR "hvc_close %X: oops, count is %d\n", |
395 | hp->vtermno, hp->count); | 389 | hp->vtermno, hp->port.count); |
396 | spin_unlock_irqrestore(&hp->lock, flags); | 390 | spin_unlock_irqrestore(&hp->port.lock, flags); |
397 | } | 391 | } |
398 | 392 | ||
399 | tty_kref_put(tty); | 393 | tty_port_put(&hp->port); |
400 | kref_put(&hp->kref, destroy_hvc_struct); | ||
401 | } | 394 | } |
402 | 395 | ||
403 | static void hvc_hangup(struct tty_struct *tty) | 396 | static void hvc_hangup(struct tty_struct *tty) |
@@ -412,32 +405,31 @@ static void hvc_hangup(struct tty_struct *tty) | |||
412 | /* cancel pending tty resize work */ | 405 | /* cancel pending tty resize work */ |
413 | cancel_work_sync(&hp->tty_resize); | 406 | cancel_work_sync(&hp->tty_resize); |
414 | 407 | ||
415 | spin_lock_irqsave(&hp->lock, flags); | 408 | spin_lock_irqsave(&hp->port.lock, flags); |
416 | 409 | ||
417 | /* | 410 | /* |
418 | * The N_TTY line discipline has problems such that in a close vs | 411 | * The N_TTY line discipline has problems such that in a close vs |
419 | * open->hangup case this can be called after the final close so prevent | 412 | * open->hangup case this can be called after the final close so prevent |
420 | * that from happening for now. | 413 | * that from happening for now. |
421 | */ | 414 | */ |
422 | if (hp->count <= 0) { | 415 | if (hp->port.count <= 0) { |
423 | spin_unlock_irqrestore(&hp->lock, flags); | 416 | spin_unlock_irqrestore(&hp->port.lock, flags); |
424 | return; | 417 | return; |
425 | } | 418 | } |
426 | 419 | ||
427 | temp_open_count = hp->count; | 420 | temp_open_count = hp->port.count; |
428 | hp->count = 0; | 421 | hp->port.count = 0; |
429 | hp->n_outbuf = 0; | 422 | spin_unlock_irqrestore(&hp->port.lock, flags); |
430 | hp->tty = NULL; | 423 | tty_port_tty_set(&hp->port, NULL); |
431 | 424 | ||
432 | spin_unlock_irqrestore(&hp->lock, flags); | 425 | hp->n_outbuf = 0; |
433 | 426 | ||
434 | if (hp->ops->notifier_hangup) | 427 | if (hp->ops->notifier_hangup) |
435 | hp->ops->notifier_hangup(hp, hp->data); | 428 | hp->ops->notifier_hangup(hp, hp->data); |
436 | 429 | ||
437 | while(temp_open_count) { | 430 | while(temp_open_count) { |
438 | --temp_open_count; | 431 | --temp_open_count; |
439 | tty_kref_put(tty); | 432 | tty_port_put(&hp->port); |
440 | kref_put(&hp->kref, destroy_hvc_struct); | ||
441 | } | 433 | } |
442 | } | 434 | } |
443 | 435 | ||
@@ -478,7 +470,8 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count | |||
478 | if (!hp) | 470 | if (!hp) |
479 | return -EPIPE; | 471 | return -EPIPE; |
480 | 472 | ||
481 | if (hp->count <= 0) | 473 | /* FIXME what's this (unprotected) check for? */ |
474 | if (hp->port.count <= 0) | ||
482 | return -EIO; | 475 | return -EIO; |
483 | 476 | ||
484 | spin_lock_irqsave(&hp->lock, flags); | 477 | spin_lock_irqsave(&hp->lock, flags); |
@@ -526,13 +519,12 @@ static void hvc_set_winsz(struct work_struct *work) | |||
526 | 519 | ||
527 | hp = container_of(work, struct hvc_struct, tty_resize); | 520 | hp = container_of(work, struct hvc_struct, tty_resize); |
528 | 521 | ||
529 | spin_lock_irqsave(&hp->lock, hvc_flags); | 522 | tty = tty_port_tty_get(&hp->port); |
530 | if (!hp->tty) { | 523 | if (!tty) |
531 | spin_unlock_irqrestore(&hp->lock, hvc_flags); | ||
532 | return; | 524 | return; |
533 | } | 525 | |
534 | ws = hp->ws; | 526 | spin_lock_irqsave(&hp->lock, hvc_flags); |
535 | tty = tty_kref_get(hp->tty); | 527 | ws = hp->ws; |
536 | spin_unlock_irqrestore(&hp->lock, hvc_flags); | 528 | spin_unlock_irqrestore(&hp->lock, hvc_flags); |
537 | 529 | ||
538 | tty_do_resize(tty, &ws); | 530 | tty_do_resize(tty, &ws); |
@@ -601,7 +593,7 @@ int hvc_poll(struct hvc_struct *hp) | |||
601 | } | 593 | } |
602 | 594 | ||
603 | /* No tty attached, just skip */ | 595 | /* No tty attached, just skip */ |
604 | tty = tty_kref_get(hp->tty); | 596 | tty = tty_port_tty_get(&hp->port); |
605 | if (tty == NULL) | 597 | if (tty == NULL) |
606 | goto bail; | 598 | goto bail; |
607 | 599 | ||
@@ -681,8 +673,7 @@ int hvc_poll(struct hvc_struct *hp) | |||
681 | 673 | ||
682 | tty_flip_buffer_push(tty); | 674 | tty_flip_buffer_push(tty); |
683 | } | 675 | } |
684 | if (tty) | 676 | tty_kref_put(tty); |
685 | tty_kref_put(tty); | ||
686 | 677 | ||
687 | return poll_mask; | 678 | return poll_mask; |
688 | } | 679 | } |
@@ -817,6 +808,10 @@ static const struct tty_operations hvc_ops = { | |||
817 | #endif | 808 | #endif |
818 | }; | 809 | }; |
819 | 810 | ||
811 | static const struct tty_port_operations hvc_port_ops = { | ||
812 | .destruct = hvc_port_destruct, | ||
813 | }; | ||
814 | |||
820 | struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, | 815 | struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, |
821 | const struct hv_ops *ops, | 816 | const struct hv_ops *ops, |
822 | int outbuf_size) | 817 | int outbuf_size) |
@@ -842,7 +837,8 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, | |||
842 | hp->outbuf_size = outbuf_size; | 837 | hp->outbuf_size = outbuf_size; |
843 | hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; | 838 | hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; |
844 | 839 | ||
845 | kref_init(&hp->kref); | 840 | tty_port_init(&hp->port); |
841 | hp->port.ops = &hvc_port_ops; | ||
846 | 842 | ||
847 | INIT_WORK(&hp->tty_resize, hvc_set_winsz); | 843 | INIT_WORK(&hp->tty_resize, hvc_set_winsz); |
848 | spin_lock_init(&hp->lock); | 844 | spin_lock_init(&hp->lock); |
@@ -875,9 +871,9 @@ int hvc_remove(struct hvc_struct *hp) | |||
875 | unsigned long flags; | 871 | unsigned long flags; |
876 | struct tty_struct *tty; | 872 | struct tty_struct *tty; |
877 | 873 | ||
878 | spin_lock_irqsave(&hp->lock, flags); | 874 | tty = tty_port_tty_get(&hp->port); |
879 | tty = tty_kref_get(hp->tty); | ||
880 | 875 | ||
876 | spin_lock_irqsave(&hp->lock, flags); | ||
881 | if (hp->index < MAX_NR_HVC_CONSOLES) | 877 | if (hp->index < MAX_NR_HVC_CONSOLES) |
882 | vtermnos[hp->index] = -1; | 878 | vtermnos[hp->index] = -1; |
883 | 879 | ||
@@ -891,7 +887,7 @@ int hvc_remove(struct hvc_struct *hp) | |||
891 | * kref cause it to be removed, which will probably be the tty_vhangup | 887 | * kref cause it to be removed, which will probably be the tty_vhangup |
892 | * below. | 888 | * below. |
893 | */ | 889 | */ |
894 | kref_put(&hp->kref, destroy_hvc_struct); | 890 | tty_port_put(&hp->port); |
895 | 891 | ||
896 | /* | 892 | /* |
897 | * This function call will auto chain call hvc_hangup. | 893 | * This function call will auto chain call hvc_hangup. |
diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h index c335a1492a54..674d23cb919a 100644 --- a/drivers/tty/hvc/hvc_console.h +++ b/drivers/tty/hvc/hvc_console.h | |||
@@ -46,10 +46,9 @@ | |||
46 | #define HVC_ALLOC_TTY_ADAPTERS 8 | 46 | #define HVC_ALLOC_TTY_ADAPTERS 8 |
47 | 47 | ||
48 | struct hvc_struct { | 48 | struct hvc_struct { |
49 | struct tty_port port; | ||
49 | spinlock_t lock; | 50 | spinlock_t lock; |
50 | int index; | 51 | int index; |
51 | struct tty_struct *tty; | ||
52 | int count; | ||
53 | int do_wakeup; | 52 | int do_wakeup; |
54 | char *outbuf; | 53 | char *outbuf; |
55 | int outbuf_size; | 54 | int outbuf_size; |
@@ -61,7 +60,6 @@ struct hvc_struct { | |||
61 | struct winsize ws; | 60 | struct winsize ws; |
62 | struct work_struct tty_resize; | 61 | struct work_struct tty_resize; |
63 | struct list_head next; | 62 | struct list_head next; |
64 | struct kref kref; /* ref count & hvc_struct lifetime */ | ||
65 | }; | 63 | }; |
66 | 64 | ||
67 | /* implemented by a low level driver */ | 65 | /* implemented by a low level driver */ |
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c index 83d5c88e7165..d3d91dae065c 100644 --- a/drivers/tty/hvc/hvc_xen.c +++ b/drivers/tty/hvc/hvc_xen.c | |||
@@ -430,9 +430,9 @@ static int __devinit xencons_probe(struct xenbus_device *dev, | |||
430 | if (devid == 0) | 430 | if (devid == 0) |
431 | return -ENODEV; | 431 | return -ENODEV; |
432 | 432 | ||
433 | info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL | __GFP_ZERO); | 433 | info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL); |
434 | if (!info) | 434 | if (!info) |
435 | goto error_nomem; | 435 | return -ENOMEM; |
436 | dev_set_drvdata(&dev->dev, info); | 436 | dev_set_drvdata(&dev->dev, info); |
437 | info->xbdev = dev; | 437 | info->xbdev = dev; |
438 | info->vtermno = xenbus_devid_to_vtermno(devid); | 438 | info->vtermno = xenbus_devid_to_vtermno(devid); |
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index 3436436fe2d7..d56788c83974 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c | |||
@@ -261,6 +261,7 @@ static DEFINE_SPINLOCK(hvcs_pi_lock); | |||
261 | 261 | ||
262 | /* One vty-server per hvcs_struct */ | 262 | /* One vty-server per hvcs_struct */ |
263 | struct hvcs_struct { | 263 | struct hvcs_struct { |
264 | struct tty_port port; | ||
264 | spinlock_t lock; | 265 | spinlock_t lock; |
265 | 266 | ||
266 | /* | 267 | /* |
@@ -269,9 +270,6 @@ struct hvcs_struct { | |||
269 | */ | 270 | */ |
270 | unsigned int index; | 271 | unsigned int index; |
271 | 272 | ||
272 | struct tty_struct *tty; | ||
273 | int open_count; | ||
274 | |||
275 | /* | 273 | /* |
276 | * Used to tell the driver kernel_thread what operations need to take | 274 | * Used to tell the driver kernel_thread what operations need to take |
277 | * place upon this hvcs_struct instance. | 275 | * place upon this hvcs_struct instance. |
@@ -290,12 +288,11 @@ struct hvcs_struct { | |||
290 | int chars_in_buffer; | 288 | int chars_in_buffer; |
291 | 289 | ||
292 | /* | 290 | /* |
293 | * Any variable below the kref is valid before a tty is connected and | 291 | * Any variable below is valid before a tty is connected and |
294 | * stays valid after the tty is disconnected. These shouldn't be | 292 | * stays valid after the tty is disconnected. These shouldn't be |
295 | * whacked until the kobject refcount reaches zero though some entries | 293 | * whacked until the kobject refcount reaches zero though some entries |
296 | * may be changed via sysfs initiatives. | 294 | * may be changed via sysfs initiatives. |
297 | */ | 295 | */ |
298 | struct kref kref; /* ref count & hvcs_struct lifetime */ | ||
299 | int connected; /* is the vty-server currently connected to a vty? */ | 296 | int connected; /* is the vty-server currently connected to a vty? */ |
300 | uint32_t p_unit_address; /* partner unit address */ | 297 | uint32_t p_unit_address; /* partner unit address */ |
301 | uint32_t p_partition_ID; /* partner partition ID */ | 298 | uint32_t p_partition_ID; /* partner partition ID */ |
@@ -304,9 +301,6 @@ struct hvcs_struct { | |||
304 | struct vio_dev *vdev; | 301 | struct vio_dev *vdev; |
305 | }; | 302 | }; |
306 | 303 | ||
307 | /* Required to back map a kref to its containing object */ | ||
308 | #define from_kref(k) container_of(k, struct hvcs_struct, kref) | ||
309 | |||
310 | static LIST_HEAD(hvcs_structs); | 304 | static LIST_HEAD(hvcs_structs); |
311 | static DEFINE_SPINLOCK(hvcs_structs_lock); | 305 | static DEFINE_SPINLOCK(hvcs_structs_lock); |
312 | static DEFINE_MUTEX(hvcs_init_mutex); | 306 | static DEFINE_MUTEX(hvcs_init_mutex); |
@@ -422,7 +416,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut | |||
422 | 416 | ||
423 | spin_lock_irqsave(&hvcsd->lock, flags); | 417 | spin_lock_irqsave(&hvcsd->lock, flags); |
424 | 418 | ||
425 | if (hvcsd->open_count > 0) { | 419 | if (hvcsd->port.count > 0) { |
426 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 420 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
427 | printk(KERN_INFO "HVCS: vterm state unchanged. " | 421 | printk(KERN_INFO "HVCS: vterm state unchanged. " |
428 | "The hvcs device node is still in use.\n"); | 422 | "The hvcs device node is still in use.\n"); |
@@ -564,7 +558,7 @@ static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance) | |||
564 | static void hvcs_try_write(struct hvcs_struct *hvcsd) | 558 | static void hvcs_try_write(struct hvcs_struct *hvcsd) |
565 | { | 559 | { |
566 | uint32_t unit_address = hvcsd->vdev->unit_address; | 560 | uint32_t unit_address = hvcsd->vdev->unit_address; |
567 | struct tty_struct *tty = hvcsd->tty; | 561 | struct tty_struct *tty = hvcsd->port.tty; |
568 | int sent; | 562 | int sent; |
569 | 563 | ||
570 | if (hvcsd->todo_mask & HVCS_TRY_WRITE) { | 564 | if (hvcsd->todo_mask & HVCS_TRY_WRITE) { |
@@ -602,7 +596,7 @@ static int hvcs_io(struct hvcs_struct *hvcsd) | |||
602 | spin_lock_irqsave(&hvcsd->lock, flags); | 596 | spin_lock_irqsave(&hvcsd->lock, flags); |
603 | 597 | ||
604 | unit_address = hvcsd->vdev->unit_address; | 598 | unit_address = hvcsd->vdev->unit_address; |
605 | tty = hvcsd->tty; | 599 | tty = hvcsd->port.tty; |
606 | 600 | ||
607 | hvcs_try_write(hvcsd); | 601 | hvcs_try_write(hvcsd); |
608 | 602 | ||
@@ -701,10 +695,9 @@ static void hvcs_return_index(int index) | |||
701 | hvcs_index_list[index] = -1; | 695 | hvcs_index_list[index] = -1; |
702 | } | 696 | } |
703 | 697 | ||
704 | /* callback when the kref ref count reaches zero */ | 698 | static void hvcs_destruct_port(struct tty_port *p) |
705 | static void destroy_hvcs_struct(struct kref *kref) | ||
706 | { | 699 | { |
707 | struct hvcs_struct *hvcsd = from_kref(kref); | 700 | struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port); |
708 | struct vio_dev *vdev; | 701 | struct vio_dev *vdev; |
709 | unsigned long flags; | 702 | unsigned long flags; |
710 | 703 | ||
@@ -741,6 +734,10 @@ static void destroy_hvcs_struct(struct kref *kref) | |||
741 | kfree(hvcsd); | 734 | kfree(hvcsd); |
742 | } | 735 | } |
743 | 736 | ||
737 | static const struct tty_port_operations hvcs_port_ops = { | ||
738 | .destruct = hvcs_destruct_port, | ||
739 | }; | ||
740 | |||
744 | static int hvcs_get_index(void) | 741 | static int hvcs_get_index(void) |
745 | { | 742 | { |
746 | int i; | 743 | int i; |
@@ -789,10 +786,9 @@ static int __devinit hvcs_probe( | |||
789 | if (!hvcsd) | 786 | if (!hvcsd) |
790 | return -ENODEV; | 787 | return -ENODEV; |
791 | 788 | ||
792 | 789 | tty_port_init(&hvcsd->port); | |
790 | hvcsd->port.ops = &hvcs_port_ops; | ||
793 | spin_lock_init(&hvcsd->lock); | 791 | spin_lock_init(&hvcsd->lock); |
794 | /* Automatically incs the refcount the first time */ | ||
795 | kref_init(&hvcsd->kref); | ||
796 | 792 | ||
797 | hvcsd->vdev = dev; | 793 | hvcsd->vdev = dev; |
798 | dev_set_drvdata(&dev->dev, hvcsd); | 794 | dev_set_drvdata(&dev->dev, hvcsd); |
@@ -852,7 +848,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev) | |||
852 | 848 | ||
853 | spin_lock_irqsave(&hvcsd->lock, flags); | 849 | spin_lock_irqsave(&hvcsd->lock, flags); |
854 | 850 | ||
855 | tty = hvcsd->tty; | 851 | tty = hvcsd->port.tty; |
856 | 852 | ||
857 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 853 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
858 | 854 | ||
@@ -860,7 +856,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev) | |||
860 | * Let the last holder of this object cause it to be removed, which | 856 | * Let the last holder of this object cause it to be removed, which |
861 | * would probably be tty_hangup below. | 857 | * would probably be tty_hangup below. |
862 | */ | 858 | */ |
863 | kref_put(&hvcsd->kref, destroy_hvcs_struct); | 859 | tty_port_put(&hvcsd->port); |
864 | 860 | ||
865 | /* | 861 | /* |
866 | * The hangup is a scheduled function which will auto chain call | 862 | * The hangup is a scheduled function which will auto chain call |
@@ -1094,7 +1090,7 @@ static struct hvcs_struct *hvcs_get_by_index(int index) | |||
1094 | list_for_each_entry(hvcsd, &hvcs_structs, next) { | 1090 | list_for_each_entry(hvcsd, &hvcs_structs, next) { |
1095 | spin_lock_irqsave(&hvcsd->lock, flags); | 1091 | spin_lock_irqsave(&hvcsd->lock, flags); |
1096 | if (hvcsd->index == index) { | 1092 | if (hvcsd->index == index) { |
1097 | kref_get(&hvcsd->kref); | 1093 | tty_port_get(&hvcsd->port); |
1098 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 1094 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
1099 | spin_unlock(&hvcs_structs_lock); | 1095 | spin_unlock(&hvcs_structs_lock); |
1100 | return hvcsd; | 1096 | return hvcsd; |
@@ -1138,8 +1134,8 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp) | |||
1138 | if ((retval = hvcs_partner_connect(hvcsd))) | 1134 | if ((retval = hvcs_partner_connect(hvcsd))) |
1139 | goto error_release; | 1135 | goto error_release; |
1140 | 1136 | ||
1141 | hvcsd->open_count = 1; | 1137 | hvcsd->port.count = 1; |
1142 | hvcsd->tty = tty; | 1138 | hvcsd->port.tty = tty; |
1143 | tty->driver_data = hvcsd; | 1139 | tty->driver_data = hvcsd; |
1144 | 1140 | ||
1145 | memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN); | 1141 | memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN); |
@@ -1160,7 +1156,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp) | |||
1160 | * and will grab the spinlock and free the connection if it fails. | 1156 | * and will grab the spinlock and free the connection if it fails. |
1161 | */ | 1157 | */ |
1162 | if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) { | 1158 | if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) { |
1163 | kref_put(&hvcsd->kref, destroy_hvcs_struct); | 1159 | tty_port_put(&hvcsd->port); |
1164 | printk(KERN_WARNING "HVCS: enable device failed.\n"); | 1160 | printk(KERN_WARNING "HVCS: enable device failed.\n"); |
1165 | return rc; | 1161 | return rc; |
1166 | } | 1162 | } |
@@ -1171,8 +1167,8 @@ fast_open: | |||
1171 | hvcsd = tty->driver_data; | 1167 | hvcsd = tty->driver_data; |
1172 | 1168 | ||
1173 | spin_lock_irqsave(&hvcsd->lock, flags); | 1169 | spin_lock_irqsave(&hvcsd->lock, flags); |
1174 | kref_get(&hvcsd->kref); | 1170 | tty_port_get(&hvcsd->port); |
1175 | hvcsd->open_count++; | 1171 | hvcsd->port.count++; |
1176 | hvcsd->todo_mask |= HVCS_SCHED_READ; | 1172 | hvcsd->todo_mask |= HVCS_SCHED_READ; |
1177 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 1173 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
1178 | 1174 | ||
@@ -1186,7 +1182,7 @@ open_success: | |||
1186 | 1182 | ||
1187 | error_release: | 1183 | error_release: |
1188 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 1184 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
1189 | kref_put(&hvcsd->kref, destroy_hvcs_struct); | 1185 | tty_port_put(&hvcsd->port); |
1190 | 1186 | ||
1191 | printk(KERN_WARNING "HVCS: partner connect failed.\n"); | 1187 | printk(KERN_WARNING "HVCS: partner connect failed.\n"); |
1192 | return retval; | 1188 | return retval; |
@@ -1216,7 +1212,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp) | |||
1216 | hvcsd = tty->driver_data; | 1212 | hvcsd = tty->driver_data; |
1217 | 1213 | ||
1218 | spin_lock_irqsave(&hvcsd->lock, flags); | 1214 | spin_lock_irqsave(&hvcsd->lock, flags); |
1219 | if (--hvcsd->open_count == 0) { | 1215 | if (--hvcsd->port.count == 0) { |
1220 | 1216 | ||
1221 | vio_disable_interrupts(hvcsd->vdev); | 1217 | vio_disable_interrupts(hvcsd->vdev); |
1222 | 1218 | ||
@@ -1225,7 +1221,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp) | |||
1225 | * execute any operations on the TTY even though it is obligated | 1221 | * execute any operations on the TTY even though it is obligated |
1226 | * to deliver any pending I/O to the hypervisor. | 1222 | * to deliver any pending I/O to the hypervisor. |
1227 | */ | 1223 | */ |
1228 | hvcsd->tty = NULL; | 1224 | hvcsd->port.tty = NULL; |
1229 | 1225 | ||
1230 | irq = hvcsd->vdev->irq; | 1226 | irq = hvcsd->vdev->irq; |
1231 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 1227 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
@@ -1240,16 +1236,16 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp) | |||
1240 | tty->driver_data = NULL; | 1236 | tty->driver_data = NULL; |
1241 | 1237 | ||
1242 | free_irq(irq, hvcsd); | 1238 | free_irq(irq, hvcsd); |
1243 | kref_put(&hvcsd->kref, destroy_hvcs_struct); | 1239 | tty_port_put(&hvcsd->port); |
1244 | return; | 1240 | return; |
1245 | } else if (hvcsd->open_count < 0) { | 1241 | } else if (hvcsd->port.count < 0) { |
1246 | printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" | 1242 | printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" |
1247 | " is missmanaged.\n", | 1243 | " is missmanaged.\n", |
1248 | hvcsd->vdev->unit_address, hvcsd->open_count); | 1244 | hvcsd->vdev->unit_address, hvcsd->port.count); |
1249 | } | 1245 | } |
1250 | 1246 | ||
1251 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 1247 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
1252 | kref_put(&hvcsd->kref, destroy_hvcs_struct); | 1248 | tty_port_put(&hvcsd->port); |
1253 | } | 1249 | } |
1254 | 1250 | ||
1255 | static void hvcs_hangup(struct tty_struct * tty) | 1251 | static void hvcs_hangup(struct tty_struct * tty) |
@@ -1261,7 +1257,7 @@ static void hvcs_hangup(struct tty_struct * tty) | |||
1261 | 1257 | ||
1262 | spin_lock_irqsave(&hvcsd->lock, flags); | 1258 | spin_lock_irqsave(&hvcsd->lock, flags); |
1263 | /* Preserve this so that we know how many kref refs to put */ | 1259 | /* Preserve this so that we know how many kref refs to put */ |
1264 | temp_open_count = hvcsd->open_count; | 1260 | temp_open_count = hvcsd->port.count; |
1265 | 1261 | ||
1266 | /* | 1262 | /* |
1267 | * Don't kref put inside the spinlock because the destruction | 1263 | * Don't kref put inside the spinlock because the destruction |
@@ -1273,10 +1269,10 @@ static void hvcs_hangup(struct tty_struct * tty) | |||
1273 | hvcsd->todo_mask = 0; | 1269 | hvcsd->todo_mask = 0; |
1274 | 1270 | ||
1275 | /* I don't think the tty needs the hvcs_struct pointer after a hangup */ | 1271 | /* I don't think the tty needs the hvcs_struct pointer after a hangup */ |
1276 | hvcsd->tty->driver_data = NULL; | 1272 | tty->driver_data = NULL; |
1277 | hvcsd->tty = NULL; | 1273 | hvcsd->port.tty = NULL; |
1278 | 1274 | ||
1279 | hvcsd->open_count = 0; | 1275 | hvcsd->port.count = 0; |
1280 | 1276 | ||
1281 | /* This will drop any buffered data on the floor which is OK in a hangup | 1277 | /* This will drop any buffered data on the floor which is OK in a hangup |
1282 | * scenario. */ | 1278 | * scenario. */ |
@@ -1301,7 +1297,7 @@ static void hvcs_hangup(struct tty_struct * tty) | |||
1301 | * NOTE: If this hangup was signaled from user space then the | 1297 | * NOTE: If this hangup was signaled from user space then the |
1302 | * final put will never happen. | 1298 | * final put will never happen. |
1303 | */ | 1299 | */ |
1304 | kref_put(&hvcsd->kref, destroy_hvcs_struct); | 1300 | tty_port_put(&hvcsd->port); |
1305 | } | 1301 | } |
1306 | } | 1302 | } |
1307 | 1303 | ||
@@ -1347,7 +1343,7 @@ static int hvcs_write(struct tty_struct *tty, | |||
1347 | * the middle of a write operation? This is a crummy place to do this | 1343 | * the middle of a write operation? This is a crummy place to do this |
1348 | * but we want to keep it all in the spinlock. | 1344 | * but we want to keep it all in the spinlock. |
1349 | */ | 1345 | */ |
1350 | if (hvcsd->open_count <= 0) { | 1346 | if (hvcsd->port.count <= 0) { |
1351 | spin_unlock_irqrestore(&hvcsd->lock, flags); | 1347 | spin_unlock_irqrestore(&hvcsd->lock, flags); |
1352 | return -ENODEV; | 1348 | return -ENODEV; |
1353 | } | 1349 | } |
@@ -1421,7 +1417,7 @@ static int hvcs_write_room(struct tty_struct *tty) | |||
1421 | { | 1417 | { |
1422 | struct hvcs_struct *hvcsd = tty->driver_data; | 1418 | struct hvcs_struct *hvcsd = tty->driver_data; |
1423 | 1419 | ||
1424 | if (!hvcsd || hvcsd->open_count <= 0) | 1420 | if (!hvcsd || hvcsd->port.count <= 0) |
1425 | return 0; | 1421 | return 0; |
1426 | 1422 | ||
1427 | return HVCS_BUFF_LEN - hvcsd->chars_in_buffer; | 1423 | return HVCS_BUFF_LEN - hvcsd->chars_in_buffer; |
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c index a7488b748647..6f5bc49c441f 100644 --- a/drivers/tty/hvc/hvsi.c +++ b/drivers/tty/hvc/hvsi.c | |||
@@ -69,14 +69,13 @@ | |||
69 | #define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) | 69 | #define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) |
70 | 70 | ||
71 | struct hvsi_struct { | 71 | struct hvsi_struct { |
72 | struct tty_port port; | ||
72 | struct delayed_work writer; | 73 | struct delayed_work writer; |
73 | struct work_struct handshaker; | 74 | struct work_struct handshaker; |
74 | wait_queue_head_t emptyq; /* woken when outbuf is emptied */ | 75 | wait_queue_head_t emptyq; /* woken when outbuf is emptied */ |
75 | wait_queue_head_t stateq; /* woken when HVSI state changes */ | 76 | wait_queue_head_t stateq; /* woken when HVSI state changes */ |
76 | spinlock_t lock; | 77 | spinlock_t lock; |
77 | int index; | 78 | int index; |
78 | struct tty_struct *tty; | ||
79 | int count; | ||
80 | uint8_t throttle_buf[128]; | 79 | uint8_t throttle_buf[128]; |
81 | uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ | 80 | uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ |
82 | /* inbuf is for packet reassembly. leave a little room for leftovers. */ | 81 | /* inbuf is for packet reassembly. leave a little room for leftovers. */ |
@@ -237,7 +236,7 @@ static int hvsi_read(struct hvsi_struct *hp, char *buf, int count) | |||
237 | } | 236 | } |
238 | 237 | ||
239 | static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, | 238 | static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, |
240 | struct tty_struct **to_hangup, struct hvsi_struct **to_handshake) | 239 | struct tty_struct *tty, struct hvsi_struct **to_handshake) |
241 | { | 240 | { |
242 | struct hvsi_control *header = (struct hvsi_control *)packet; | 241 | struct hvsi_control *header = (struct hvsi_control *)packet; |
243 | 242 | ||
@@ -247,9 +246,8 @@ static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, | |||
247 | /* CD went away; no more connection */ | 246 | /* CD went away; no more connection */ |
248 | pr_debug("hvsi%i: CD dropped\n", hp->index); | 247 | pr_debug("hvsi%i: CD dropped\n", hp->index); |
249 | hp->mctrl &= TIOCM_CD; | 248 | hp->mctrl &= TIOCM_CD; |
250 | /* If userland hasn't done an open(2) yet, hp->tty is NULL. */ | 249 | if (tty && !C_CLOCAL(tty)) |
251 | if (hp->tty && !(hp->tty->flags & CLOCAL)) | 250 | tty_hangup(tty); |
252 | *to_hangup = hp->tty; | ||
253 | } | 251 | } |
254 | break; | 252 | break; |
255 | case VSV_CLOSE_PROTOCOL: | 253 | case VSV_CLOSE_PROTOCOL: |
@@ -331,7 +329,8 @@ static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet) | |||
331 | } | 329 | } |
332 | } | 330 | } |
333 | 331 | ||
334 | static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len) | 332 | static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty, |
333 | const char *buf, int len) | ||
335 | { | 334 | { |
336 | int i; | 335 | int i; |
337 | 336 | ||
@@ -347,7 +346,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len) | |||
347 | continue; | 346 | continue; |
348 | } | 347 | } |
349 | #endif /* CONFIG_MAGIC_SYSRQ */ | 348 | #endif /* CONFIG_MAGIC_SYSRQ */ |
350 | tty_insert_flip_char(hp->tty, c, 0); | 349 | tty_insert_flip_char(tty, c, 0); |
351 | } | 350 | } |
352 | } | 351 | } |
353 | 352 | ||
@@ -360,7 +359,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len) | |||
360 | * revisited. | 359 | * revisited. |
361 | */ | 360 | */ |
362 | #define TTY_THRESHOLD_THROTTLE 128 | 361 | #define TTY_THRESHOLD_THROTTLE 128 |
363 | static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp, | 362 | static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty, |
364 | const uint8_t *packet) | 363 | const uint8_t *packet) |
365 | { | 364 | { |
366 | const struct hvsi_header *header = (const struct hvsi_header *)packet; | 365 | const struct hvsi_header *header = (const struct hvsi_header *)packet; |
@@ -371,14 +370,14 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp, | |||
371 | pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data); | 370 | pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data); |
372 | 371 | ||
373 | if (datalen == 0) | 372 | if (datalen == 0) |
374 | return NULL; | 373 | return false; |
375 | 374 | ||
376 | if (overflow > 0) { | 375 | if (overflow > 0) { |
377 | pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__); | 376 | pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__); |
378 | datalen = TTY_THRESHOLD_THROTTLE; | 377 | datalen = TTY_THRESHOLD_THROTTLE; |
379 | } | 378 | } |
380 | 379 | ||
381 | hvsi_insert_chars(hp, data, datalen); | 380 | hvsi_insert_chars(hp, tty, data, datalen); |
382 | 381 | ||
383 | if (overflow > 0) { | 382 | if (overflow > 0) { |
384 | /* | 383 | /* |
@@ -390,7 +389,7 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp, | |||
390 | hp->n_throttle = overflow; | 389 | hp->n_throttle = overflow; |
391 | } | 390 | } |
392 | 391 | ||
393 | return hp->tty; | 392 | return true; |
394 | } | 393 | } |
395 | 394 | ||
396 | /* | 395 | /* |
@@ -399,14 +398,13 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp, | |||
399 | * machine during console handshaking (in which case tty = NULL and we ignore | 398 | * machine during console handshaking (in which case tty = NULL and we ignore |
400 | * incoming data). | 399 | * incoming data). |
401 | */ | 400 | */ |
402 | static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip, | 401 | static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty, |
403 | struct tty_struct **hangup, struct hvsi_struct **handshake) | 402 | struct hvsi_struct **handshake) |
404 | { | 403 | { |
405 | uint8_t *packet = hp->inbuf; | 404 | uint8_t *packet = hp->inbuf; |
406 | int chunklen; | 405 | int chunklen; |
406 | bool flip = false; | ||
407 | 407 | ||
408 | *flip = NULL; | ||
409 | *hangup = NULL; | ||
410 | *handshake = NULL; | 408 | *handshake = NULL; |
411 | 409 | ||
412 | chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ); | 410 | chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ); |
@@ -440,12 +438,12 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip, | |||
440 | case VS_DATA_PACKET_HEADER: | 438 | case VS_DATA_PACKET_HEADER: |
441 | if (!is_open(hp)) | 439 | if (!is_open(hp)) |
442 | break; | 440 | break; |
443 | if (hp->tty == NULL) | 441 | if (tty == NULL) |
444 | break; /* no tty buffer to put data in */ | 442 | break; /* no tty buffer to put data in */ |
445 | *flip = hvsi_recv_data(hp, packet); | 443 | flip = hvsi_recv_data(hp, tty, packet); |
446 | break; | 444 | break; |
447 | case VS_CONTROL_PACKET_HEADER: | 445 | case VS_CONTROL_PACKET_HEADER: |
448 | hvsi_recv_control(hp, packet, hangup, handshake); | 446 | hvsi_recv_control(hp, packet, tty, handshake); |
449 | break; | 447 | break; |
450 | case VS_QUERY_RESPONSE_PACKET_HEADER: | 448 | case VS_QUERY_RESPONSE_PACKET_HEADER: |
451 | hvsi_recv_response(hp, packet); | 449 | hvsi_recv_response(hp, packet); |
@@ -462,28 +460,26 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip, | |||
462 | 460 | ||
463 | packet += len_packet(packet); | 461 | packet += len_packet(packet); |
464 | 462 | ||
465 | if (*hangup || *handshake) { | 463 | if (*handshake) { |
466 | pr_debug("%s: hangup or handshake\n", __func__); | 464 | pr_debug("%s: handshake\n", __func__); |
467 | /* | ||
468 | * we need to send the hangup now before receiving any more data. | ||
469 | * If we get "data, hangup, data", we can't deliver the second | ||
470 | * data before the hangup. | ||
471 | */ | ||
472 | break; | 465 | break; |
473 | } | 466 | } |
474 | } | 467 | } |
475 | 468 | ||
476 | compact_inbuf(hp, packet); | 469 | compact_inbuf(hp, packet); |
477 | 470 | ||
471 | if (flip) | ||
472 | tty_flip_buffer_push(tty); | ||
473 | |||
478 | return 1; | 474 | return 1; |
479 | } | 475 | } |
480 | 476 | ||
481 | static void hvsi_send_overflow(struct hvsi_struct *hp) | 477 | static void hvsi_send_overflow(struct hvsi_struct *hp, struct tty_struct *tty) |
482 | { | 478 | { |
483 | pr_debug("%s: delivering %i bytes overflow\n", __func__, | 479 | pr_debug("%s: delivering %i bytes overflow\n", __func__, |
484 | hp->n_throttle); | 480 | hp->n_throttle); |
485 | 481 | ||
486 | hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle); | 482 | hvsi_insert_chars(hp, tty, hp->throttle_buf, hp->n_throttle); |
487 | hp->n_throttle = 0; | 483 | hp->n_throttle = 0; |
488 | } | 484 | } |
489 | 485 | ||
@@ -494,35 +490,20 @@ static void hvsi_send_overflow(struct hvsi_struct *hp) | |||
494 | static irqreturn_t hvsi_interrupt(int irq, void *arg) | 490 | static irqreturn_t hvsi_interrupt(int irq, void *arg) |
495 | { | 491 | { |
496 | struct hvsi_struct *hp = (struct hvsi_struct *)arg; | 492 | struct hvsi_struct *hp = (struct hvsi_struct *)arg; |
497 | struct tty_struct *flip; | ||
498 | struct tty_struct *hangup; | ||
499 | struct hvsi_struct *handshake; | 493 | struct hvsi_struct *handshake; |
494 | struct tty_struct *tty; | ||
500 | unsigned long flags; | 495 | unsigned long flags; |
501 | int again = 1; | 496 | int again = 1; |
502 | 497 | ||
503 | pr_debug("%s\n", __func__); | 498 | pr_debug("%s\n", __func__); |
504 | 499 | ||
500 | tty = tty_port_tty_get(&hp->port); | ||
501 | |||
505 | while (again) { | 502 | while (again) { |
506 | spin_lock_irqsave(&hp->lock, flags); | 503 | spin_lock_irqsave(&hp->lock, flags); |
507 | again = hvsi_load_chunk(hp, &flip, &hangup, &handshake); | 504 | again = hvsi_load_chunk(hp, tty, &handshake); |
508 | spin_unlock_irqrestore(&hp->lock, flags); | 505 | spin_unlock_irqrestore(&hp->lock, flags); |
509 | 506 | ||
510 | /* | ||
511 | * we have to call tty_flip_buffer_push() and tty_hangup() outside our | ||
512 | * spinlock. But we also have to keep going until we've read all the | ||
513 | * available data. | ||
514 | */ | ||
515 | |||
516 | if (flip) { | ||
517 | /* there was data put in the tty flip buffer */ | ||
518 | tty_flip_buffer_push(flip); | ||
519 | flip = NULL; | ||
520 | } | ||
521 | |||
522 | if (hangup) { | ||
523 | tty_hangup(hangup); | ||
524 | } | ||
525 | |||
526 | if (handshake) { | 507 | if (handshake) { |
527 | pr_debug("hvsi%i: attempting re-handshake\n", handshake->index); | 508 | pr_debug("hvsi%i: attempting re-handshake\n", handshake->index); |
528 | schedule_work(&handshake->handshaker); | 509 | schedule_work(&handshake->handshaker); |
@@ -530,18 +511,15 @@ static irqreturn_t hvsi_interrupt(int irq, void *arg) | |||
530 | } | 511 | } |
531 | 512 | ||
532 | spin_lock_irqsave(&hp->lock, flags); | 513 | spin_lock_irqsave(&hp->lock, flags); |
533 | if (hp->tty && hp->n_throttle | 514 | if (tty && hp->n_throttle && !test_bit(TTY_THROTTLED, &tty->flags)) { |
534 | && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) { | 515 | /* we weren't hung up and we weren't throttled, so we can |
535 | /* we weren't hung up and we weren't throttled, so we can deliver the | 516 | * deliver the rest now */ |
536 | * rest now */ | 517 | hvsi_send_overflow(hp, tty); |
537 | flip = hp->tty; | 518 | tty_flip_buffer_push(tty); |
538 | hvsi_send_overflow(hp); | ||
539 | } | 519 | } |
540 | spin_unlock_irqrestore(&hp->lock, flags); | 520 | spin_unlock_irqrestore(&hp->lock, flags); |
541 | 521 | ||
542 | if (flip) { | 522 | tty_kref_put(tty); |
543 | tty_flip_buffer_push(flip); | ||
544 | } | ||
545 | 523 | ||
546 | return IRQ_HANDLED; | 524 | return IRQ_HANDLED; |
547 | } | 525 | } |
@@ -749,9 +727,9 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp) | |||
749 | if (hp->state == HVSI_FSP_DIED) | 727 | if (hp->state == HVSI_FSP_DIED) |
750 | return -EIO; | 728 | return -EIO; |
751 | 729 | ||
730 | tty_port_tty_set(&hp->port, tty); | ||
752 | spin_lock_irqsave(&hp->lock, flags); | 731 | spin_lock_irqsave(&hp->lock, flags); |
753 | hp->tty = tty; | 732 | hp->port.count++; |
754 | hp->count++; | ||
755 | atomic_set(&hp->seqno, 0); | 733 | atomic_set(&hp->seqno, 0); |
756 | h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); | 734 | h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); |
757 | spin_unlock_irqrestore(&hp->lock, flags); | 735 | spin_unlock_irqrestore(&hp->lock, flags); |
@@ -808,8 +786,8 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp) | |||
808 | 786 | ||
809 | spin_lock_irqsave(&hp->lock, flags); | 787 | spin_lock_irqsave(&hp->lock, flags); |
810 | 788 | ||
811 | if (--hp->count == 0) { | 789 | if (--hp->port.count == 0) { |
812 | hp->tty = NULL; | 790 | tty_port_tty_set(&hp->port, NULL); |
813 | hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */ | 791 | hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */ |
814 | 792 | ||
815 | /* only close down connection if it is not the console */ | 793 | /* only close down connection if it is not the console */ |
@@ -841,9 +819,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp) | |||
841 | 819 | ||
842 | spin_lock_irqsave(&hp->lock, flags); | 820 | spin_lock_irqsave(&hp->lock, flags); |
843 | } | 821 | } |
844 | } else if (hp->count < 0) | 822 | } else if (hp->port.count < 0) |
845 | printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n", | 823 | printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n", |
846 | hp - hvsi_ports, hp->count); | 824 | hp - hvsi_ports, hp->port.count); |
847 | 825 | ||
848 | spin_unlock_irqrestore(&hp->lock, flags); | 826 | spin_unlock_irqrestore(&hp->lock, flags); |
849 | } | 827 | } |
@@ -855,12 +833,11 @@ static void hvsi_hangup(struct tty_struct *tty) | |||
855 | 833 | ||
856 | pr_debug("%s\n", __func__); | 834 | pr_debug("%s\n", __func__); |
857 | 835 | ||
858 | spin_lock_irqsave(&hp->lock, flags); | 836 | tty_port_tty_set(&hp->port, NULL); |
859 | 837 | ||
860 | hp->count = 0; | 838 | spin_lock_irqsave(&hp->lock, flags); |
839 | hp->port.count = 0; | ||
861 | hp->n_outbuf = 0; | 840 | hp->n_outbuf = 0; |
862 | hp->tty = NULL; | ||
863 | |||
864 | spin_unlock_irqrestore(&hp->lock, flags); | 841 | spin_unlock_irqrestore(&hp->lock, flags); |
865 | } | 842 | } |
866 | 843 | ||
@@ -888,6 +865,7 @@ static void hvsi_write_worker(struct work_struct *work) | |||
888 | { | 865 | { |
889 | struct hvsi_struct *hp = | 866 | struct hvsi_struct *hp = |
890 | container_of(work, struct hvsi_struct, writer.work); | 867 | container_of(work, struct hvsi_struct, writer.work); |
868 | struct tty_struct *tty; | ||
891 | unsigned long flags; | 869 | unsigned long flags; |
892 | #ifdef DEBUG | 870 | #ifdef DEBUG |
893 | static long start_j = 0; | 871 | static long start_j = 0; |
@@ -921,7 +899,11 @@ static void hvsi_write_worker(struct work_struct *work) | |||
921 | start_j = 0; | 899 | start_j = 0; |
922 | #endif /* DEBUG */ | 900 | #endif /* DEBUG */ |
923 | wake_up_all(&hp->emptyq); | 901 | wake_up_all(&hp->emptyq); |
924 | tty_wakeup(hp->tty); | 902 | tty = tty_port_tty_get(&hp->port); |
903 | if (tty) { | ||
904 | tty_wakeup(tty); | ||
905 | tty_kref_put(tty); | ||
906 | } | ||
925 | } | 907 | } |
926 | 908 | ||
927 | out: | 909 | out: |
@@ -966,8 +948,8 @@ static int hvsi_write(struct tty_struct *tty, | |||
966 | * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls | 948 | * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls |
967 | * will see there is no room in outbuf and return. | 949 | * will see there is no room in outbuf and return. |
968 | */ | 950 | */ |
969 | while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) { | 951 | while ((count > 0) && (hvsi_write_room(tty) > 0)) { |
970 | int chunksize = min(count, hvsi_write_room(hp->tty)); | 952 | int chunksize = min(count, hvsi_write_room(tty)); |
971 | 953 | ||
972 | BUG_ON(hp->n_outbuf < 0); | 954 | BUG_ON(hp->n_outbuf < 0); |
973 | memcpy(hp->outbuf + hp->n_outbuf, source, chunksize); | 955 | memcpy(hp->outbuf + hp->n_outbuf, source, chunksize); |
@@ -1014,19 +996,16 @@ static void hvsi_unthrottle(struct tty_struct *tty) | |||
1014 | { | 996 | { |
1015 | struct hvsi_struct *hp = tty->driver_data; | 997 | struct hvsi_struct *hp = tty->driver_data; |
1016 | unsigned long flags; | 998 | unsigned long flags; |
1017 | int shouldflip = 0; | ||
1018 | 999 | ||
1019 | pr_debug("%s\n", __func__); | 1000 | pr_debug("%s\n", __func__); |
1020 | 1001 | ||
1021 | spin_lock_irqsave(&hp->lock, flags); | 1002 | spin_lock_irqsave(&hp->lock, flags); |
1022 | if (hp->n_throttle) { | 1003 | if (hp->n_throttle) { |
1023 | hvsi_send_overflow(hp); | 1004 | hvsi_send_overflow(hp, tty); |
1024 | shouldflip = 1; | 1005 | tty_flip_buffer_push(tty); |
1025 | } | 1006 | } |
1026 | spin_unlock_irqrestore(&hp->lock, flags); | 1007 | spin_unlock_irqrestore(&hp->lock, flags); |
1027 | 1008 | ||
1028 | if (shouldflip) | ||
1029 | tty_flip_buffer_push(hp->tty); | ||
1030 | 1009 | ||
1031 | h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); | 1010 | h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); |
1032 | } | 1011 | } |
@@ -1228,6 +1207,7 @@ static int __init hvsi_console_init(void) | |||
1228 | init_waitqueue_head(&hp->emptyq); | 1207 | init_waitqueue_head(&hp->emptyq); |
1229 | init_waitqueue_head(&hp->stateq); | 1208 | init_waitqueue_head(&hp->stateq); |
1230 | spin_lock_init(&hp->lock); | 1209 | spin_lock_init(&hp->lock); |
1210 | tty_port_init(&hp->port); | ||
1231 | hp->index = hvsi_count; | 1211 | hp->index = hvsi_count; |
1232 | hp->inbuf_end = hp->inbuf; | 1212 | hp->inbuf_end = hp->inbuf; |
1233 | hp->state = HVSI_CLOSED; | 1213 | hp->state = HVSI_CLOSED; |
diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c index 6f4dd83d8695..59c135dd5d20 100644 --- a/drivers/tty/hvc/hvsi_lib.c +++ b/drivers/tty/hvc/hvsi_lib.c | |||
@@ -377,7 +377,7 @@ int hvsilib_open(struct hvsi_priv *pv, struct hvc_struct *hp) | |||
377 | pr_devel("HVSI@%x: open !\n", pv->termno); | 377 | pr_devel("HVSI@%x: open !\n", pv->termno); |
378 | 378 | ||
379 | /* Keep track of the tty data structure */ | 379 | /* Keep track of the tty data structure */ |
380 | pv->tty = tty_kref_get(hp->tty); | 380 | pv->tty = tty_port_tty_get(&hp->port); |
381 | 381 | ||
382 | hvsilib_establish(pv); | 382 | hvsilib_establish(pv); |
383 | 383 | ||
diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c index 4daf962f7055..f8b5fa0093a3 100644 --- a/drivers/tty/ipwireless/tty.c +++ b/drivers/tty/ipwireless/tty.c | |||
@@ -44,14 +44,13 @@ | |||
44 | #define TTYTYPE_RAS_RAW (2) | 44 | #define TTYTYPE_RAS_RAW (2) |
45 | 45 | ||
46 | struct ipw_tty { | 46 | struct ipw_tty { |
47 | struct tty_port port; | ||
47 | int index; | 48 | int index; |
48 | struct ipw_hardware *hardware; | 49 | struct ipw_hardware *hardware; |
49 | unsigned int channel_idx; | 50 | unsigned int channel_idx; |
50 | unsigned int secondary_channel_idx; | 51 | unsigned int secondary_channel_idx; |
51 | int tty_type; | 52 | int tty_type; |
52 | struct ipw_network *network; | 53 | struct ipw_network *network; |
53 | struct tty_struct *linux_tty; | ||
54 | int open_count; | ||
55 | unsigned int control_lines; | 54 | unsigned int control_lines; |
56 | struct mutex ipw_tty_mutex; | 55 | struct mutex ipw_tty_mutex; |
57 | int tx_bytes_queued; | 56 | int tx_bytes_queued; |
@@ -73,23 +72,6 @@ static char *tty_type_name(int tty_type) | |||
73 | return channel_names[tty_type]; | 72 | return channel_names[tty_type]; |
74 | } | 73 | } |
75 | 74 | ||
76 | static void report_registering(struct ipw_tty *tty) | ||
77 | { | ||
78 | char *iftype = tty_type_name(tty->tty_type); | ||
79 | |||
80 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME | ||
81 | ": registering %s device ttyIPWp%d\n", iftype, tty->index); | ||
82 | } | ||
83 | |||
84 | static void report_deregistering(struct ipw_tty *tty) | ||
85 | { | ||
86 | char *iftype = tty_type_name(tty->tty_type); | ||
87 | |||
88 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME | ||
89 | ": deregistering %s device ttyIPWp%d\n", iftype, | ||
90 | tty->index); | ||
91 | } | ||
92 | |||
93 | static struct ipw_tty *get_tty(int index) | 75 | static struct ipw_tty *get_tty(int index) |
94 | { | 76 | { |
95 | /* | 77 | /* |
@@ -117,12 +99,12 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp) | |||
117 | mutex_unlock(&tty->ipw_tty_mutex); | 99 | mutex_unlock(&tty->ipw_tty_mutex); |
118 | return -ENODEV; | 100 | return -ENODEV; |
119 | } | 101 | } |
120 | if (tty->open_count == 0) | 102 | if (tty->port.count == 0) |
121 | tty->tx_bytes_queued = 0; | 103 | tty->tx_bytes_queued = 0; |
122 | 104 | ||
123 | tty->open_count++; | 105 | tty->port.count++; |
124 | 106 | ||
125 | tty->linux_tty = linux_tty; | 107 | tty->port.tty = linux_tty; |
126 | linux_tty->driver_data = tty; | 108 | linux_tty->driver_data = tty; |
127 | linux_tty->low_latency = 1; | 109 | linux_tty->low_latency = 1; |
128 | 110 | ||
@@ -136,13 +118,13 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp) | |||
136 | 118 | ||
137 | static void do_ipw_close(struct ipw_tty *tty) | 119 | static void do_ipw_close(struct ipw_tty *tty) |
138 | { | 120 | { |
139 | tty->open_count--; | 121 | tty->port.count--; |
140 | 122 | ||
141 | if (tty->open_count == 0) { | 123 | if (tty->port.count == 0) { |
142 | struct tty_struct *linux_tty = tty->linux_tty; | 124 | struct tty_struct *linux_tty = tty->port.tty; |
143 | 125 | ||
144 | if (linux_tty != NULL) { | 126 | if (linux_tty != NULL) { |
145 | tty->linux_tty = NULL; | 127 | tty->port.tty = NULL; |
146 | linux_tty->driver_data = NULL; | 128 | linux_tty->driver_data = NULL; |
147 | 129 | ||
148 | if (tty->tty_type == TTYTYPE_MODEM) | 130 | if (tty->tty_type == TTYTYPE_MODEM) |
@@ -159,7 +141,7 @@ static void ipw_hangup(struct tty_struct *linux_tty) | |||
159 | return; | 141 | return; |
160 | 142 | ||
161 | mutex_lock(&tty->ipw_tty_mutex); | 143 | mutex_lock(&tty->ipw_tty_mutex); |
162 | if (tty->open_count == 0) { | 144 | if (tty->port.count == 0) { |
163 | mutex_unlock(&tty->ipw_tty_mutex); | 145 | mutex_unlock(&tty->ipw_tty_mutex); |
164 | return; | 146 | return; |
165 | } | 147 | } |
@@ -182,13 +164,13 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data, | |||
182 | int work = 0; | 164 | int work = 0; |
183 | 165 | ||
184 | mutex_lock(&tty->ipw_tty_mutex); | 166 | mutex_lock(&tty->ipw_tty_mutex); |
185 | linux_tty = tty->linux_tty; | 167 | linux_tty = tty->port.tty; |
186 | if (linux_tty == NULL) { | 168 | if (linux_tty == NULL) { |
187 | mutex_unlock(&tty->ipw_tty_mutex); | 169 | mutex_unlock(&tty->ipw_tty_mutex); |
188 | return; | 170 | return; |
189 | } | 171 | } |
190 | 172 | ||
191 | if (!tty->open_count) { | 173 | if (!tty->port.count) { |
192 | mutex_unlock(&tty->ipw_tty_mutex); | 174 | mutex_unlock(&tty->ipw_tty_mutex); |
193 | return; | 175 | return; |
194 | } | 176 | } |
@@ -230,7 +212,7 @@ static int ipw_write(struct tty_struct *linux_tty, | |||
230 | return -ENODEV; | 212 | return -ENODEV; |
231 | 213 | ||
232 | mutex_lock(&tty->ipw_tty_mutex); | 214 | mutex_lock(&tty->ipw_tty_mutex); |
233 | if (!tty->open_count) { | 215 | if (!tty->port.count) { |
234 | mutex_unlock(&tty->ipw_tty_mutex); | 216 | mutex_unlock(&tty->ipw_tty_mutex); |
235 | return -EINVAL; | 217 | return -EINVAL; |
236 | } | 218 | } |
@@ -270,7 +252,7 @@ static int ipw_write_room(struct tty_struct *linux_tty) | |||
270 | if (!tty) | 252 | if (!tty) |
271 | return -ENODEV; | 253 | return -ENODEV; |
272 | 254 | ||
273 | if (!tty->open_count) | 255 | if (!tty->port.count) |
274 | return -EINVAL; | 256 | return -EINVAL; |
275 | 257 | ||
276 | room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued; | 258 | room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued; |
@@ -312,7 +294,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty) | |||
312 | if (!tty) | 294 | if (!tty) |
313 | return 0; | 295 | return 0; |
314 | 296 | ||
315 | if (!tty->open_count) | 297 | if (!tty->port.count) |
316 | return 0; | 298 | return 0; |
317 | 299 | ||
318 | return tty->tx_bytes_queued; | 300 | return tty->tx_bytes_queued; |
@@ -393,7 +375,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty) | |||
393 | if (!tty) | 375 | if (!tty) |
394 | return -ENODEV; | 376 | return -ENODEV; |
395 | 377 | ||
396 | if (!tty->open_count) | 378 | if (!tty->port.count) |
397 | return -EINVAL; | 379 | return -EINVAL; |
398 | 380 | ||
399 | return get_control_lines(tty); | 381 | return get_control_lines(tty); |
@@ -409,7 +391,7 @@ ipw_tiocmset(struct tty_struct *linux_tty, | |||
409 | if (!tty) | 391 | if (!tty) |
410 | return -ENODEV; | 392 | return -ENODEV; |
411 | 393 | ||
412 | if (!tty->open_count) | 394 | if (!tty->port.count) |
413 | return -EINVAL; | 395 | return -EINVAL; |
414 | 396 | ||
415 | return set_control_lines(tty, set, clear); | 397 | return set_control_lines(tty, set, clear); |
@@ -423,7 +405,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, | |||
423 | if (!tty) | 405 | if (!tty) |
424 | return -ENODEV; | 406 | return -ENODEV; |
425 | 407 | ||
426 | if (!tty->open_count) | 408 | if (!tty->port.count) |
427 | return -EINVAL; | 409 | return -EINVAL; |
428 | 410 | ||
429 | /* FIXME: Exactly how is the tty object locked here .. */ | 411 | /* FIXME: Exactly how is the tty object locked here .. */ |
@@ -492,6 +474,7 @@ static int add_tty(int j, | |||
492 | ttys[j]->network = network; | 474 | ttys[j]->network = network; |
493 | ttys[j]->tty_type = tty_type; | 475 | ttys[j]->tty_type = tty_type; |
494 | mutex_init(&ttys[j]->ipw_tty_mutex); | 476 | mutex_init(&ttys[j]->ipw_tty_mutex); |
477 | tty_port_init(&ttys[j]->port); | ||
495 | 478 | ||
496 | tty_register_device(ipw_tty_driver, j, NULL); | 479 | tty_register_device(ipw_tty_driver, j, NULL); |
497 | ipwireless_associate_network_tty(network, channel_idx, ttys[j]); | 480 | ipwireless_associate_network_tty(network, channel_idx, ttys[j]); |
@@ -500,8 +483,12 @@ static int add_tty(int j, | |||
500 | ipwireless_associate_network_tty(network, | 483 | ipwireless_associate_network_tty(network, |
501 | secondary_channel_idx, | 484 | secondary_channel_idx, |
502 | ttys[j]); | 485 | ttys[j]); |
503 | if (get_tty(j) == ttys[j]) | 486 | /* check if we provide raw device (if loopback is enabled) */ |
504 | report_registering(ttys[j]); | 487 | if (get_tty(j)) |
488 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME | ||
489 | ": registering %s device ttyIPWp%d\n", | ||
490 | tty_type_name(tty_type), j); | ||
491 | |||
505 | return 0; | 492 | return 0; |
506 | } | 493 | } |
507 | 494 | ||
@@ -560,19 +547,21 @@ void ipwireless_tty_free(struct ipw_tty *tty) | |||
560 | 547 | ||
561 | if (ttyj) { | 548 | if (ttyj) { |
562 | mutex_lock(&ttyj->ipw_tty_mutex); | 549 | mutex_lock(&ttyj->ipw_tty_mutex); |
563 | if (get_tty(j) == ttyj) | 550 | if (get_tty(j)) |
564 | report_deregistering(ttyj); | 551 | printk(KERN_INFO IPWIRELESS_PCCARD_NAME |
552 | ": deregistering %s device ttyIPWp%d\n", | ||
553 | tty_type_name(ttyj->tty_type), j); | ||
565 | ttyj->closing = 1; | 554 | ttyj->closing = 1; |
566 | if (ttyj->linux_tty != NULL) { | 555 | if (ttyj->port.tty != NULL) { |
567 | mutex_unlock(&ttyj->ipw_tty_mutex); | 556 | mutex_unlock(&ttyj->ipw_tty_mutex); |
568 | tty_hangup(ttyj->linux_tty); | 557 | tty_vhangup(ttyj->port.tty); |
569 | /* Wait till the tty_hangup has completed */ | ||
570 | flush_work_sync(&ttyj->linux_tty->hangup_work); | ||
571 | /* FIXME: Exactly how is the tty object locked here | 558 | /* FIXME: Exactly how is the tty object locked here |
572 | against a parallel ioctl etc */ | 559 | against a parallel ioctl etc */ |
560 | /* FIXME2: hangup does not mean all processes | ||
561 | * are gone */ | ||
573 | mutex_lock(&ttyj->ipw_tty_mutex); | 562 | mutex_lock(&ttyj->ipw_tty_mutex); |
574 | } | 563 | } |
575 | while (ttyj->open_count) | 564 | while (ttyj->port.count) |
576 | do_ipw_close(ttyj); | 565 | do_ipw_close(ttyj); |
577 | ipwireless_disassociate_network_ttys(network, | 566 | ipwireless_disassociate_network_ttys(network, |
578 | ttyj->channel_idx); | 567 | ttyj->channel_idx); |
@@ -661,8 +650,8 @@ ipwireless_tty_notify_control_line_change(struct ipw_tty *tty, | |||
661 | */ | 650 | */ |
662 | if ((old_control_lines & IPW_CONTROL_LINE_DCD) | 651 | if ((old_control_lines & IPW_CONTROL_LINE_DCD) |
663 | && !(tty->control_lines & IPW_CONTROL_LINE_DCD) | 652 | && !(tty->control_lines & IPW_CONTROL_LINE_DCD) |
664 | && tty->linux_tty) { | 653 | && tty->port.tty) { |
665 | tty_hangup(tty->linux_tty); | 654 | tty_hangup(tty->port.tty); |
666 | } | 655 | } |
667 | } | 656 | } |
668 | 657 | ||
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index c6f372dd5623..90cc680c4f0e 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c | |||
@@ -2326,7 +2326,7 @@ static const struct tty_operations mxser_ops = { | |||
2326 | .get_icount = mxser_get_icount, | 2326 | .get_icount = mxser_get_icount, |
2327 | }; | 2327 | }; |
2328 | 2328 | ||
2329 | struct tty_port_operations mxser_port_ops = { | 2329 | static struct tty_port_operations mxser_port_ops = { |
2330 | .carrier_raised = mxser_carrier_raised, | 2330 | .carrier_raised = mxser_carrier_raised, |
2331 | .dtr_rts = mxser_dtr_rts, | 2331 | .dtr_rts = mxser_dtr_rts, |
2332 | .activate = mxser_activate, | 2332 | .activate = mxser_activate, |
diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c index 5c6c31459a2f..656ad93bbc96 100644 --- a/drivers/tty/n_r3964.c +++ b/drivers/tty/n_r3964.c | |||
@@ -1065,7 +1065,8 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, | |||
1065 | 1065 | ||
1066 | TRACE_L("read()"); | 1066 | TRACE_L("read()"); |
1067 | 1067 | ||
1068 | tty_lock(); | 1068 | /* FIXME: should use a private lock */ |
1069 | tty_lock(tty); | ||
1069 | 1070 | ||
1070 | pClient = findClient(pInfo, task_pid(current)); | 1071 | pClient = findClient(pInfo, task_pid(current)); |
1071 | if (pClient) { | 1072 | if (pClient) { |
@@ -1077,7 +1078,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, | |||
1077 | goto unlock; | 1078 | goto unlock; |
1078 | } | 1079 | } |
1079 | /* block until there is a message: */ | 1080 | /* block until there is a message: */ |
1080 | wait_event_interruptible_tty(pInfo->read_wait, | 1081 | wait_event_interruptible_tty(tty, pInfo->read_wait, |
1081 | (pMsg = remove_msg(pInfo, pClient))); | 1082 | (pMsg = remove_msg(pInfo, pClient))); |
1082 | } | 1083 | } |
1083 | 1084 | ||
@@ -1107,7 +1108,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, | |||
1107 | } | 1108 | } |
1108 | ret = -EPERM; | 1109 | ret = -EPERM; |
1109 | unlock: | 1110 | unlock: |
1110 | tty_unlock(); | 1111 | tty_unlock(tty); |
1111 | return ret; | 1112 | return ret; |
1112 | } | 1113 | } |
1113 | 1114 | ||
@@ -1156,7 +1157,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, | |||
1156 | pHeader->locks = 0; | 1157 | pHeader->locks = 0; |
1157 | pHeader->owner = NULL; | 1158 | pHeader->owner = NULL; |
1158 | 1159 | ||
1159 | tty_lock(); | 1160 | tty_lock(tty); |
1160 | 1161 | ||
1161 | pClient = findClient(pInfo, task_pid(current)); | 1162 | pClient = findClient(pInfo, task_pid(current)); |
1162 | if (pClient) { | 1163 | if (pClient) { |
@@ -1175,7 +1176,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, | |||
1175 | add_tx_queue(pInfo, pHeader); | 1176 | add_tx_queue(pInfo, pHeader); |
1176 | trigger_transmit(pInfo); | 1177 | trigger_transmit(pInfo); |
1177 | 1178 | ||
1178 | tty_unlock(); | 1179 | tty_unlock(tty); |
1179 | 1180 | ||
1180 | return 0; | 1181 | return 0; |
1181 | } | 1182 | } |
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 94b6eda87afd..ee1c268f5f9d 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c | |||
@@ -1630,6 +1630,7 @@ static int copy_from_read_buf(struct tty_struct *tty, | |||
1630 | int retval; | 1630 | int retval; |
1631 | size_t n; | 1631 | size_t n; |
1632 | unsigned long flags; | 1632 | unsigned long flags; |
1633 | bool is_eof; | ||
1633 | 1634 | ||
1634 | retval = 0; | 1635 | retval = 0; |
1635 | spin_lock_irqsave(&tty->read_lock, flags); | 1636 | spin_lock_irqsave(&tty->read_lock, flags); |
@@ -1639,15 +1640,15 @@ static int copy_from_read_buf(struct tty_struct *tty, | |||
1639 | if (n) { | 1640 | if (n) { |
1640 | retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n); | 1641 | retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n); |
1641 | n -= retval; | 1642 | n -= retval; |
1643 | is_eof = n == 1 && | ||
1644 | tty->read_buf[tty->read_tail] == EOF_CHAR(tty); | ||
1642 | tty_audit_add_data(tty, &tty->read_buf[tty->read_tail], n); | 1645 | tty_audit_add_data(tty, &tty->read_buf[tty->read_tail], n); |
1643 | spin_lock_irqsave(&tty->read_lock, flags); | 1646 | spin_lock_irqsave(&tty->read_lock, flags); |
1644 | tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1); | 1647 | tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1); |
1645 | tty->read_cnt -= n; | 1648 | tty->read_cnt -= n; |
1646 | /* Turn single EOF into zero-length read */ | 1649 | /* Turn single EOF into zero-length read */ |
1647 | if (L_EXTPROC(tty) && tty->icanon && n == 1) { | 1650 | if (L_EXTPROC(tty) && tty->icanon && is_eof && !tty->read_cnt) |
1648 | if (!tty->read_cnt && (*b)[n-1] == EOF_CHAR(tty)) | 1651 | n = 0; |
1649 | n--; | ||
1650 | } | ||
1651 | spin_unlock_irqrestore(&tty->read_lock, flags); | 1652 | spin_unlock_irqrestore(&tty->read_lock, flags); |
1652 | *b += n; | 1653 | *b += n; |
1653 | *nr -= n; | 1654 | *nr -= n; |
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index eeae7fafe9a7..59af3945ea85 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -26,11 +26,13 @@ | |||
26 | #include <linux/bitops.h> | 26 | #include <linux/bitops.h> |
27 | #include <linux/devpts_fs.h> | 27 | #include <linux/devpts_fs.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/mutex.h> | ||
29 | 30 | ||
30 | 31 | ||
31 | #ifdef CONFIG_UNIX98_PTYS | 32 | #ifdef CONFIG_UNIX98_PTYS |
32 | static struct tty_driver *ptm_driver; | 33 | static struct tty_driver *ptm_driver; |
33 | static struct tty_driver *pts_driver; | 34 | static struct tty_driver *pts_driver; |
35 | static DEFINE_MUTEX(devpts_mutex); | ||
34 | #endif | 36 | #endif |
35 | 37 | ||
36 | static void pty_close(struct tty_struct *tty, struct file *filp) | 38 | static void pty_close(struct tty_struct *tty, struct file *filp) |
@@ -45,6 +47,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp) | |||
45 | wake_up_interruptible(&tty->read_wait); | 47 | wake_up_interruptible(&tty->read_wait); |
46 | wake_up_interruptible(&tty->write_wait); | 48 | wake_up_interruptible(&tty->write_wait); |
47 | tty->packet = 0; | 49 | tty->packet = 0; |
50 | /* Review - krefs on tty_link ?? */ | ||
48 | if (!tty->link) | 51 | if (!tty->link) |
49 | return; | 52 | return; |
50 | tty->link->packet = 0; | 53 | tty->link->packet = 0; |
@@ -54,12 +57,15 @@ static void pty_close(struct tty_struct *tty, struct file *filp) | |||
54 | if (tty->driver->subtype == PTY_TYPE_MASTER) { | 57 | if (tty->driver->subtype == PTY_TYPE_MASTER) { |
55 | set_bit(TTY_OTHER_CLOSED, &tty->flags); | 58 | set_bit(TTY_OTHER_CLOSED, &tty->flags); |
56 | #ifdef CONFIG_UNIX98_PTYS | 59 | #ifdef CONFIG_UNIX98_PTYS |
57 | if (tty->driver == ptm_driver) | 60 | if (tty->driver == ptm_driver) { |
61 | mutex_lock(&devpts_mutex); | ||
58 | devpts_pty_kill(tty->link); | 62 | devpts_pty_kill(tty->link); |
63 | mutex_unlock(&devpts_mutex); | ||
64 | } | ||
59 | #endif | 65 | #endif |
60 | tty_unlock(); | 66 | tty_unlock(tty); |
61 | tty_vhangup(tty->link); | 67 | tty_vhangup(tty->link); |
62 | tty_lock(); | 68 | tty_lock(tty); |
63 | } | 69 | } |
64 | } | 70 | } |
65 | 71 | ||
@@ -475,13 +481,17 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, | |||
475 | * @idx: tty index | 481 | * @idx: tty index |
476 | * | 482 | * |
477 | * Look up a pty master device. Called under the tty_mutex for now. | 483 | * Look up a pty master device. Called under the tty_mutex for now. |
478 | * This provides our locking. | 484 | * This provides our locking for the tty pointer. |
479 | */ | 485 | */ |
480 | 486 | ||
481 | static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, | 487 | static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, |
482 | struct inode *pts_inode, int idx) | 488 | struct inode *pts_inode, int idx) |
483 | { | 489 | { |
484 | struct tty_struct *tty = devpts_get_tty(pts_inode, idx); | 490 | struct tty_struct *tty; |
491 | |||
492 | mutex_lock(&devpts_mutex); | ||
493 | tty = devpts_get_tty(pts_inode, idx); | ||
494 | mutex_unlock(&devpts_mutex); | ||
485 | /* Master must be open before slave */ | 495 | /* Master must be open before slave */ |
486 | if (!tty) | 496 | if (!tty) |
487 | return ERR_PTR(-EIO); | 497 | return ERR_PTR(-EIO); |
@@ -613,24 +623,29 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
613 | return retval; | 623 | return retval; |
614 | 624 | ||
615 | /* find a device that is not in use. */ | 625 | /* find a device that is not in use. */ |
616 | tty_lock(); | 626 | mutex_lock(&devpts_mutex); |
617 | index = devpts_new_index(inode); | 627 | index = devpts_new_index(inode); |
618 | tty_unlock(); | ||
619 | if (index < 0) { | 628 | if (index < 0) { |
620 | retval = index; | 629 | retval = index; |
621 | goto err_file; | 630 | goto err_file; |
622 | } | 631 | } |
623 | 632 | ||
633 | mutex_unlock(&devpts_mutex); | ||
634 | |||
624 | mutex_lock(&tty_mutex); | 635 | mutex_lock(&tty_mutex); |
625 | tty_lock(); | 636 | mutex_lock(&devpts_mutex); |
626 | tty = tty_init_dev(ptm_driver, index); | 637 | tty = tty_init_dev(ptm_driver, index); |
627 | mutex_unlock(&tty_mutex); | ||
628 | 638 | ||
629 | if (IS_ERR(tty)) { | 639 | if (IS_ERR(tty)) { |
630 | retval = PTR_ERR(tty); | 640 | retval = PTR_ERR(tty); |
631 | goto out; | 641 | goto out; |
632 | } | 642 | } |
633 | 643 | ||
644 | /* The tty returned here is locked so we can safely | ||
645 | drop the mutex */ | ||
646 | mutex_unlock(&devpts_mutex); | ||
647 | mutex_unlock(&tty_mutex); | ||
648 | |||
634 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ | 649 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ |
635 | 650 | ||
636 | tty_add_file(tty, filp); | 651 | tty_add_file(tty, filp); |
@@ -643,16 +658,17 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
643 | if (retval) | 658 | if (retval) |
644 | goto err_release; | 659 | goto err_release; |
645 | 660 | ||
646 | tty_unlock(); | 661 | tty_unlock(tty); |
647 | return 0; | 662 | return 0; |
648 | err_release: | 663 | err_release: |
649 | tty_unlock(); | 664 | tty_unlock(tty); |
650 | tty_release(inode, filp); | 665 | tty_release(inode, filp); |
651 | return retval; | 666 | return retval; |
652 | out: | 667 | out: |
668 | mutex_unlock(&tty_mutex); | ||
653 | devpts_kill_index(inode, index); | 669 | devpts_kill_index(inode, index); |
654 | tty_unlock(); | ||
655 | err_file: | 670 | err_file: |
671 | mutex_unlock(&devpts_mutex); | ||
656 | tty_free_file(filp); | 672 | tty_free_file(filp); |
657 | return retval; | 673 | return retval; |
658 | } | 674 | } |
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c index 5ce782529d65..3ed20e435e59 100644 --- a/drivers/tty/serial/68328serial.c +++ b/drivers/tty/serial/68328serial.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <asm/dbg.h> | 17 | #include <asm/dbg.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/serial.h> | ||
20 | #include <linux/signal.h> | 21 | #include <linux/signal.h> |
21 | #include <linux/sched.h> | 22 | #include <linux/sched.h> |
22 | #include <linux/timer.h> | 23 | #include <linux/timer.h> |
@@ -56,8 +57,6 @@ | |||
56 | #endif /* CONFIG_M68VZ328 */ | 57 | #endif /* CONFIG_M68VZ328 */ |
57 | #endif /* CONFIG_M68EZ328 */ | 58 | #endif /* CONFIG_M68EZ328 */ |
58 | 59 | ||
59 | #include "68328serial.h" | ||
60 | |||
61 | /* Turn off usage of real serial interrupt code, to "support" Copilot */ | 60 | /* Turn off usage of real serial interrupt code, to "support" Copilot */ |
62 | #ifdef CONFIG_XCOPILOT_BUGS | 61 | #ifdef CONFIG_XCOPILOT_BUGS |
63 | #undef USE_INTS | 62 | #undef USE_INTS |
@@ -65,33 +64,82 @@ | |||
65 | #define USE_INTS | 64 | #define USE_INTS |
66 | #endif | 65 | #endif |
67 | 66 | ||
68 | static struct m68k_serial m68k_soft[NR_PORTS]; | 67 | /* |
68 | * I believe this is the optimal setting that reduces the number of interrupts. | ||
69 | * At high speeds the output might become a little "bursted" (use USTCNT_TXHE | ||
70 | * if that bothers you), but in most cases it will not, since we try to | ||
71 | * transmit characters every time rs_interrupt is called. Thus, quite often | ||
72 | * you'll see that a receive interrupt occures before the transmit one. | ||
73 | * -- Vladimir Gurevich | ||
74 | */ | ||
75 | #define USTCNT_TX_INTR_MASK (USTCNT_TXEE) | ||
69 | 76 | ||
70 | static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS; | 77 | /* |
78 | * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special | ||
79 | * "Old data interrupt" which occures whenever the data stay in the FIFO | ||
80 | * longer than 30 bits time. This allows us to use FIFO without compromising | ||
81 | * latency. '328 does not have this feature and without the real 328-based | ||
82 | * board I would assume that RXRE is the safest setting. | ||
83 | * | ||
84 | * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of | ||
85 | * interrupts. RXFE (receive queue full) causes the system to lose data | ||
86 | * at least at 115200 baud | ||
87 | * | ||
88 | * If your board is busy doing other stuff, you might consider to use | ||
89 | * RXRE (data ready intrrupt) instead. | ||
90 | * | ||
91 | * The other option is to make these INTR masks run-time configurable, so | ||
92 | * that people can dynamically adapt them according to the current usage. | ||
93 | * -- Vladimir Gurevich | ||
94 | */ | ||
71 | 95 | ||
72 | /* multiple ports are contiguous in memory */ | 96 | /* (es) */ |
73 | m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; | 97 | #if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328) |
98 | #define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN) | ||
99 | #elif defined(CONFIG_M68328) | ||
100 | #define USTCNT_RX_INTR_MASK (USTCNT_RXRE) | ||
101 | #else | ||
102 | #error Please, define the Rx interrupt events for your CPU | ||
103 | #endif | ||
104 | /* (/es) */ | ||
74 | 105 | ||
75 | struct tty_struct m68k_ttys; | 106 | /* |
76 | struct m68k_serial *m68k_consinfo = 0; | 107 | * This is our internal structure for each serial port's state. |
108 | */ | ||
109 | struct m68k_serial { | ||
110 | struct tty_port tport; | ||
111 | char is_cons; /* Is this our console. */ | ||
112 | int magic; | ||
113 | int baud_base; | ||
114 | int port; | ||
115 | int irq; | ||
116 | int type; /* UART type */ | ||
117 | int custom_divisor; | ||
118 | int x_char; /* xon/xoff character */ | ||
119 | int line; | ||
120 | unsigned char *xmit_buf; | ||
121 | int xmit_head; | ||
122 | int xmit_tail; | ||
123 | int xmit_cnt; | ||
124 | }; | ||
77 | 125 | ||
78 | #define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */ | 126 | #define SERIAL_MAGIC 0x5301 |
79 | 127 | ||
80 | struct tty_driver *serial_driver; | 128 | /* |
129 | * Define the number of ports supported and their irqs. | ||
130 | */ | ||
131 | #define NR_PORTS 1 | ||
81 | 132 | ||
82 | /* number of characters left in xmit buffer before we ask for more */ | 133 | static struct m68k_serial m68k_soft[NR_PORTS]; |
83 | #define WAKEUP_CHARS 256 | ||
84 | 134 | ||
85 | /* Debugging... DEBUG_INTR is bad to use when one of the zs | 135 | static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM }; |
86 | * lines is your console ;( | ||
87 | */ | ||
88 | #undef SERIAL_DEBUG_INTR | ||
89 | #undef SERIAL_DEBUG_OPEN | ||
90 | #undef SERIAL_DEBUG_FLOW | ||
91 | 136 | ||
92 | #define RS_ISR_PASS_LIMIT 256 | 137 | /* multiple ports are contiguous in memory */ |
138 | m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; | ||
139 | |||
140 | struct tty_driver *serial_driver; | ||
93 | 141 | ||
94 | static void change_speed(struct m68k_serial *info); | 142 | static void change_speed(struct m68k_serial *info, struct tty_struct *tty); |
95 | 143 | ||
96 | /* | 144 | /* |
97 | * Setup for console. Argument comes from the boot command line. | 145 | * Setup for console. Argument comes from the boot command line. |
@@ -143,17 +191,6 @@ static int baud_table[] = { | |||
143 | 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, | 191 | 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, |
144 | 9600, 19200, 38400, 57600, 115200, 0 }; | 192 | 9600, 19200, 38400, 57600, 115200, 0 }; |
145 | 193 | ||
146 | /* Sets or clears DTR/RTS on the requested line */ | ||
147 | static inline void m68k_rtsdtr(struct m68k_serial *ss, int set) | ||
148 | { | ||
149 | if (set) { | ||
150 | /* set the RTS/CTS line */ | ||
151 | } else { | ||
152 | /* clear it */ | ||
153 | } | ||
154 | return; | ||
155 | } | ||
156 | |||
157 | /* Utility routines */ | 194 | /* Utility routines */ |
158 | static inline int get_baud(struct m68k_serial *ss) | 195 | static inline int get_baud(struct m68k_serial *ss) |
159 | { | 196 | { |
@@ -189,7 +226,8 @@ static void rs_stop(struct tty_struct *tty) | |||
189 | 226 | ||
190 | static int rs_put_char(char ch) | 227 | static int rs_put_char(char ch) |
191 | { | 228 | { |
192 | int flags, loops = 0; | 229 | unsigned long flags; |
230 | int loops = 0; | ||
193 | 231 | ||
194 | local_irq_save(flags); | 232 | local_irq_save(flags); |
195 | 233 | ||
@@ -224,28 +262,9 @@ static void rs_start(struct tty_struct *tty) | |||
224 | local_irq_restore(flags); | 262 | local_irq_restore(flags); |
225 | } | 263 | } |
226 | 264 | ||
227 | /* Drop into either the boot monitor or kadb upon receiving a break | 265 | static void receive_chars(struct m68k_serial *info, struct tty_struct *tty, |
228 | * from keyboard/console input. | 266 | unsigned short rx) |
229 | */ | ||
230 | static void batten_down_hatches(void) | ||
231 | { | ||
232 | /* Drop into the debugger */ | ||
233 | } | ||
234 | |||
235 | static void status_handle(struct m68k_serial *info, unsigned short status) | ||
236 | { | 267 | { |
237 | /* If this is console input and this is a | ||
238 | * 'break asserted' status change interrupt | ||
239 | * see if we can drop into the debugger | ||
240 | */ | ||
241 | if((status & URX_BREAK) && info->break_abort) | ||
242 | batten_down_hatches(); | ||
243 | return; | ||
244 | } | ||
245 | |||
246 | static void receive_chars(struct m68k_serial *info, unsigned short rx) | ||
247 | { | ||
248 | struct tty_struct *tty = info->tty; | ||
249 | m68328_uart *uart = &uart_addr[info->line]; | 268 | m68328_uart *uart = &uart_addr[info->line]; |
250 | unsigned char ch, flag; | 269 | unsigned char ch, flag; |
251 | 270 | ||
@@ -259,7 +278,6 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx) | |||
259 | 278 | ||
260 | if(info->is_cons) { | 279 | if(info->is_cons) { |
261 | if(URX_BREAK & rx) { /* whee, break received */ | 280 | if(URX_BREAK & rx) { /* whee, break received */ |
262 | status_handle(info, rx); | ||
263 | return; | 281 | return; |
264 | #ifdef CONFIG_MAGIC_SYSRQ | 282 | #ifdef CONFIG_MAGIC_SYSRQ |
265 | } else if (ch == 0x10) { /* ^P */ | 283 | } else if (ch == 0x10) { /* ^P */ |
@@ -280,16 +298,13 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx) | |||
280 | 298 | ||
281 | flag = TTY_NORMAL; | 299 | flag = TTY_NORMAL; |
282 | 300 | ||
283 | if(rx & URX_PARITY_ERROR) { | 301 | if (rx & URX_PARITY_ERROR) |
284 | flag = TTY_PARITY; | 302 | flag = TTY_PARITY; |
285 | status_handle(info, rx); | 303 | else if (rx & URX_OVRUN) |
286 | } else if(rx & URX_OVRUN) { | ||
287 | flag = TTY_OVERRUN; | 304 | flag = TTY_OVERRUN; |
288 | status_handle(info, rx); | 305 | else if (rx & URX_FRAME_ERROR) |
289 | } else if(rx & URX_FRAME_ERROR) { | ||
290 | flag = TTY_FRAME; | 306 | flag = TTY_FRAME; |
291 | status_handle(info, rx); | 307 | |
292 | } | ||
293 | tty_insert_flip_char(tty, ch, flag); | 308 | tty_insert_flip_char(tty, ch, flag); |
294 | #ifndef CONFIG_XCOPILOT_BUGS | 309 | #ifndef CONFIG_XCOPILOT_BUGS |
295 | } while((rx = uart->urx.w) & URX_DATA_READY); | 310 | } while((rx = uart->urx.w) & URX_DATA_READY); |
@@ -301,7 +316,7 @@ clear_and_exit: | |||
301 | return; | 316 | return; |
302 | } | 317 | } |
303 | 318 | ||
304 | static void transmit_chars(struct m68k_serial *info) | 319 | static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty) |
305 | { | 320 | { |
306 | m68328_uart *uart = &uart_addr[info->line]; | 321 | m68328_uart *uart = &uart_addr[info->line]; |
307 | 322 | ||
@@ -312,7 +327,7 @@ static void transmit_chars(struct m68k_serial *info) | |||
312 | goto clear_and_return; | 327 | goto clear_and_return; |
313 | } | 328 | } |
314 | 329 | ||
315 | if((info->xmit_cnt <= 0) || info->tty->stopped) { | 330 | if ((info->xmit_cnt <= 0) || !tty || tty->stopped) { |
316 | /* That's peculiar... TX ints off */ | 331 | /* That's peculiar... TX ints off */ |
317 | uart->ustcnt &= ~USTCNT_TX_INTR_MASK; | 332 | uart->ustcnt &= ~USTCNT_TX_INTR_MASK; |
318 | goto clear_and_return; | 333 | goto clear_and_return; |
@@ -340,6 +355,7 @@ clear_and_return: | |||
340 | irqreturn_t rs_interrupt(int irq, void *dev_id) | 355 | irqreturn_t rs_interrupt(int irq, void *dev_id) |
341 | { | 356 | { |
342 | struct m68k_serial *info = dev_id; | 357 | struct m68k_serial *info = dev_id; |
358 | struct tty_struct *tty = tty_port_tty_get(&info->tport); | ||
343 | m68328_uart *uart; | 359 | m68328_uart *uart; |
344 | unsigned short rx; | 360 | unsigned short rx; |
345 | unsigned short tx; | 361 | unsigned short tx; |
@@ -350,20 +366,24 @@ irqreturn_t rs_interrupt(int irq, void *dev_id) | |||
350 | #ifdef USE_INTS | 366 | #ifdef USE_INTS |
351 | tx = uart->utx.w; | 367 | tx = uart->utx.w; |
352 | 368 | ||
353 | if (rx & URX_DATA_READY) receive_chars(info, rx); | 369 | if (rx & URX_DATA_READY) |
354 | if (tx & UTX_TX_AVAIL) transmit_chars(info); | 370 | receive_chars(info, tty, rx); |
371 | if (tx & UTX_TX_AVAIL) | ||
372 | transmit_chars(info, tty); | ||
355 | #else | 373 | #else |
356 | receive_chars(info, rx); | 374 | receive_chars(info, tty, rx); |
357 | #endif | 375 | #endif |
376 | tty_kref_put(tty); | ||
377 | |||
358 | return IRQ_HANDLED; | 378 | return IRQ_HANDLED; |
359 | } | 379 | } |
360 | 380 | ||
361 | static int startup(struct m68k_serial * info) | 381 | static int startup(struct m68k_serial *info, struct tty_struct *tty) |
362 | { | 382 | { |
363 | m68328_uart *uart = &uart_addr[info->line]; | 383 | m68328_uart *uart = &uart_addr[info->line]; |
364 | unsigned long flags; | 384 | unsigned long flags; |
365 | 385 | ||
366 | if (info->flags & S_INITIALIZED) | 386 | if (info->tport.flags & ASYNC_INITIALIZED) |
367 | return 0; | 387 | return 0; |
368 | 388 | ||
369 | if (!info->xmit_buf) { | 389 | if (!info->xmit_buf) { |
@@ -380,7 +400,6 @@ static int startup(struct m68k_serial * info) | |||
380 | */ | 400 | */ |
381 | 401 | ||
382 | uart->ustcnt = USTCNT_UEN; | 402 | uart->ustcnt = USTCNT_UEN; |
383 | info->xmit_fifo_size = 1; | ||
384 | uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; | 403 | uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; |
385 | (void)uart->urx.w; | 404 | (void)uart->urx.w; |
386 | 405 | ||
@@ -394,17 +413,17 @@ static int startup(struct m68k_serial * info) | |||
394 | uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; | 413 | uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; |
395 | #endif | 414 | #endif |
396 | 415 | ||
397 | if (info->tty) | 416 | if (tty) |
398 | clear_bit(TTY_IO_ERROR, &info->tty->flags); | 417 | clear_bit(TTY_IO_ERROR, &tty->flags); |
399 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; | 418 | info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; |
400 | 419 | ||
401 | /* | 420 | /* |
402 | * and set the speed of the serial port | 421 | * and set the speed of the serial port |
403 | */ | 422 | */ |
404 | 423 | ||
405 | change_speed(info); | 424 | change_speed(info, tty); |
406 | 425 | ||
407 | info->flags |= S_INITIALIZED; | 426 | info->tport.flags |= ASYNC_INITIALIZED; |
408 | local_irq_restore(flags); | 427 | local_irq_restore(flags); |
409 | return 0; | 428 | return 0; |
410 | } | 429 | } |
@@ -413,13 +432,13 @@ static int startup(struct m68k_serial * info) | |||
413 | * This routine will shutdown a serial port; interrupts are disabled, and | 432 | * This routine will shutdown a serial port; interrupts are disabled, and |
414 | * DTR is dropped if the hangup on close termio flag is on. | 433 | * DTR is dropped if the hangup on close termio flag is on. |
415 | */ | 434 | */ |
416 | static void shutdown(struct m68k_serial * info) | 435 | static void shutdown(struct m68k_serial *info, struct tty_struct *tty) |
417 | { | 436 | { |
418 | m68328_uart *uart = &uart_addr[info->line]; | 437 | m68328_uart *uart = &uart_addr[info->line]; |
419 | unsigned long flags; | 438 | unsigned long flags; |
420 | 439 | ||
421 | uart->ustcnt = 0; /* All off! */ | 440 | uart->ustcnt = 0; /* All off! */ |
422 | if (!(info->flags & S_INITIALIZED)) | 441 | if (!(info->tport.flags & ASYNC_INITIALIZED)) |
423 | return; | 442 | return; |
424 | 443 | ||
425 | local_irq_save(flags); | 444 | local_irq_save(flags); |
@@ -429,10 +448,10 @@ static void shutdown(struct m68k_serial * info) | |||
429 | info->xmit_buf = 0; | 448 | info->xmit_buf = 0; |
430 | } | 449 | } |
431 | 450 | ||
432 | if (info->tty) | 451 | if (tty) |
433 | set_bit(TTY_IO_ERROR, &info->tty->flags); | 452 | set_bit(TTY_IO_ERROR, &tty->flags); |
434 | 453 | ||
435 | info->flags &= ~S_INITIALIZED; | 454 | info->tport.flags &= ~ASYNC_INITIALIZED; |
436 | local_irq_restore(flags); | 455 | local_irq_restore(flags); |
437 | } | 456 | } |
438 | 457 | ||
@@ -488,7 +507,7 @@ struct { | |||
488 | * This routine is called to set the UART divisor registers to match | 507 | * This routine is called to set the UART divisor registers to match |
489 | * the specified baud rate for a serial port. | 508 | * the specified baud rate for a serial port. |
490 | */ | 509 | */ |
491 | static void change_speed(struct m68k_serial *info) | 510 | static void change_speed(struct m68k_serial *info, struct tty_struct *tty) |
492 | { | 511 | { |
493 | m68328_uart *uart = &uart_addr[info->line]; | 512 | m68328_uart *uart = &uart_addr[info->line]; |
494 | unsigned short port; | 513 | unsigned short port; |
@@ -496,9 +515,7 @@ static void change_speed(struct m68k_serial *info) | |||
496 | unsigned cflag; | 515 | unsigned cflag; |
497 | int i; | 516 | int i; |
498 | 517 | ||
499 | if (!info->tty || !info->tty->termios) | 518 | cflag = tty->termios->c_cflag; |
500 | return; | ||
501 | cflag = info->tty->termios->c_cflag; | ||
502 | if (!(port = info->port)) | 519 | if (!(port = info->port)) |
503 | return; | 520 | return; |
504 | 521 | ||
@@ -510,7 +527,6 @@ static void change_speed(struct m68k_serial *info) | |||
510 | i = (i & ~CBAUDEX) + B38400; | 527 | i = (i & ~CBAUDEX) + B38400; |
511 | } | 528 | } |
512 | 529 | ||
513 | info->baud = baud_table[i]; | ||
514 | uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | | 530 | uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | |
515 | PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); | 531 | PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); |
516 | 532 | ||
@@ -807,10 +823,10 @@ static int get_serial_info(struct m68k_serial * info, | |||
807 | tmp.line = info->line; | 823 | tmp.line = info->line; |
808 | tmp.port = info->port; | 824 | tmp.port = info->port; |
809 | tmp.irq = info->irq; | 825 | tmp.irq = info->irq; |
810 | tmp.flags = info->flags; | 826 | tmp.flags = info->tport.flags; |
811 | tmp.baud_base = info->baud_base; | 827 | tmp.baud_base = info->baud_base; |
812 | tmp.close_delay = info->close_delay; | 828 | tmp.close_delay = info->tport.close_delay; |
813 | tmp.closing_wait = info->closing_wait; | 829 | tmp.closing_wait = info->tport.closing_wait; |
814 | tmp.custom_divisor = info->custom_divisor; | 830 | tmp.custom_divisor = info->custom_divisor; |
815 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | 831 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
816 | return -EFAULT; | 832 | return -EFAULT; |
@@ -818,9 +834,10 @@ static int get_serial_info(struct m68k_serial * info, | |||
818 | return 0; | 834 | return 0; |
819 | } | 835 | } |
820 | 836 | ||
821 | static int set_serial_info(struct m68k_serial * info, | 837 | static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty, |
822 | struct serial_struct * new_info) | 838 | struct serial_struct * new_info) |
823 | { | 839 | { |
840 | struct tty_port *port = &info->tport; | ||
824 | struct serial_struct new_serial; | 841 | struct serial_struct new_serial; |
825 | struct m68k_serial old_info; | 842 | struct m68k_serial old_info; |
826 | int retval = 0; | 843 | int retval = 0; |
@@ -834,17 +851,17 @@ static int set_serial_info(struct m68k_serial * info, | |||
834 | if (!capable(CAP_SYS_ADMIN)) { | 851 | if (!capable(CAP_SYS_ADMIN)) { |
835 | if ((new_serial.baud_base != info->baud_base) || | 852 | if ((new_serial.baud_base != info->baud_base) || |
836 | (new_serial.type != info->type) || | 853 | (new_serial.type != info->type) || |
837 | (new_serial.close_delay != info->close_delay) || | 854 | (new_serial.close_delay != port->close_delay) || |
838 | ((new_serial.flags & ~S_USR_MASK) != | 855 | ((new_serial.flags & ~ASYNC_USR_MASK) != |
839 | (info->flags & ~S_USR_MASK))) | 856 | (port->flags & ~ASYNC_USR_MASK))) |
840 | return -EPERM; | 857 | return -EPERM; |
841 | info->flags = ((info->flags & ~S_USR_MASK) | | 858 | port->flags = ((port->flags & ~ASYNC_USR_MASK) | |
842 | (new_serial.flags & S_USR_MASK)); | 859 | (new_serial.flags & ASYNC_USR_MASK)); |
843 | info->custom_divisor = new_serial.custom_divisor; | 860 | info->custom_divisor = new_serial.custom_divisor; |
844 | goto check_and_exit; | 861 | goto check_and_exit; |
845 | } | 862 | } |
846 | 863 | ||
847 | if (info->count > 1) | 864 | if (port->count > 1) |
848 | return -EBUSY; | 865 | return -EBUSY; |
849 | 866 | ||
850 | /* | 867 | /* |
@@ -853,14 +870,14 @@ static int set_serial_info(struct m68k_serial * info, | |||
853 | */ | 870 | */ |
854 | 871 | ||
855 | info->baud_base = new_serial.baud_base; | 872 | info->baud_base = new_serial.baud_base; |
856 | info->flags = ((info->flags & ~S_FLAGS) | | 873 | port->flags = ((port->flags & ~ASYNC_FLAGS) | |
857 | (new_serial.flags & S_FLAGS)); | 874 | (new_serial.flags & ASYNC_FLAGS)); |
858 | info->type = new_serial.type; | 875 | info->type = new_serial.type; |
859 | info->close_delay = new_serial.close_delay; | 876 | port->close_delay = new_serial.close_delay; |
860 | info->closing_wait = new_serial.closing_wait; | 877 | port->closing_wait = new_serial.closing_wait; |
861 | 878 | ||
862 | check_and_exit: | 879 | check_and_exit: |
863 | retval = startup(info); | 880 | retval = startup(info, tty); |
864 | return retval; | 881 | return retval; |
865 | } | 882 | } |
866 | 883 | ||
@@ -946,7 +963,7 @@ static int rs_ioctl(struct tty_struct *tty, | |||
946 | return get_serial_info(info, | 963 | return get_serial_info(info, |
947 | (struct serial_struct *) arg); | 964 | (struct serial_struct *) arg); |
948 | case TIOCSSERIAL: | 965 | case TIOCSSERIAL: |
949 | return set_serial_info(info, | 966 | return set_serial_info(info, tty, |
950 | (struct serial_struct *) arg); | 967 | (struct serial_struct *) arg); |
951 | case TIOCSERGETLSR: /* Get line status register */ | 968 | case TIOCSERGETLSR: /* Get line status register */ |
952 | return get_lsr_info(info, (unsigned int *) arg); | 969 | return get_lsr_info(info, (unsigned int *) arg); |
@@ -965,7 +982,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) | |||
965 | { | 982 | { |
966 | struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; | 983 | struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; |
967 | 984 | ||
968 | change_speed(info); | 985 | change_speed(info, tty); |
969 | 986 | ||
970 | if ((old_termios->c_cflag & CRTSCTS) && | 987 | if ((old_termios->c_cflag & CRTSCTS) && |
971 | !(tty->termios->c_cflag & CRTSCTS)) { | 988 | !(tty->termios->c_cflag & CRTSCTS)) { |
@@ -988,6 +1005,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) | |||
988 | static void rs_close(struct tty_struct *tty, struct file * filp) | 1005 | static void rs_close(struct tty_struct *tty, struct file * filp) |
989 | { | 1006 | { |
990 | struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; | 1007 | struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; |
1008 | struct tty_port *port = &info->tport; | ||
991 | m68328_uart *uart = &uart_addr[info->line]; | 1009 | m68328_uart *uart = &uart_addr[info->line]; |
992 | unsigned long flags; | 1010 | unsigned long flags; |
993 | 1011 | ||
@@ -1001,7 +1019,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp) | |||
1001 | return; | 1019 | return; |
1002 | } | 1020 | } |
1003 | 1021 | ||
1004 | if ((tty->count == 1) && (info->count != 1)) { | 1022 | if ((tty->count == 1) && (port->count != 1)) { |
1005 | /* | 1023 | /* |
1006 | * Uh, oh. tty->count is 1, which means that the tty | 1024 | * Uh, oh. tty->count is 1, which means that the tty |
1007 | * structure will be freed. Info->count should always | 1025 | * structure will be freed. Info->count should always |
@@ -1010,26 +1028,26 @@ static void rs_close(struct tty_struct *tty, struct file * filp) | |||
1010 | * serial port won't be shutdown. | 1028 | * serial port won't be shutdown. |
1011 | */ | 1029 | */ |
1012 | printk("rs_close: bad serial port count; tty->count is 1, " | 1030 | printk("rs_close: bad serial port count; tty->count is 1, " |
1013 | "info->count is %d\n", info->count); | 1031 | "port->count is %d\n", port->count); |
1014 | info->count = 1; | 1032 | port->count = 1; |
1015 | } | 1033 | } |
1016 | if (--info->count < 0) { | 1034 | if (--port->count < 0) { |
1017 | printk("rs_close: bad serial port count for ttyS%d: %d\n", | 1035 | printk("rs_close: bad serial port count for ttyS%d: %d\n", |
1018 | info->line, info->count); | 1036 | info->line, port->count); |
1019 | info->count = 0; | 1037 | port->count = 0; |
1020 | } | 1038 | } |
1021 | if (info->count) { | 1039 | if (port->count) { |
1022 | local_irq_restore(flags); | 1040 | local_irq_restore(flags); |
1023 | return; | 1041 | return; |
1024 | } | 1042 | } |
1025 | info->flags |= S_CLOSING; | 1043 | port->flags |= ASYNC_CLOSING; |
1026 | /* | 1044 | /* |
1027 | * Now we wait for the transmit buffer to clear; and we notify | 1045 | * Now we wait for the transmit buffer to clear; and we notify |
1028 | * the line discipline to only process XON/XOFF characters. | 1046 | * the line discipline to only process XON/XOFF characters. |
1029 | */ | 1047 | */ |
1030 | tty->closing = 1; | 1048 | tty->closing = 1; |
1031 | if (info->closing_wait != S_CLOSING_WAIT_NONE) | 1049 | if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
1032 | tty_wait_until_sent(tty, info->closing_wait); | 1050 | tty_wait_until_sent(tty, port->closing_wait); |
1033 | /* | 1051 | /* |
1034 | * At this point we stop accepting input. To do this, we | 1052 | * At this point we stop accepting input. To do this, we |
1035 | * disable the receive line status interrupts, and tell the | 1053 | * disable the receive line status interrupts, and tell the |
@@ -1040,13 +1058,12 @@ static void rs_close(struct tty_struct *tty, struct file * filp) | |||
1040 | uart->ustcnt &= ~USTCNT_RXEN; | 1058 | uart->ustcnt &= ~USTCNT_RXEN; |
1041 | uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); | 1059 | uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); |
1042 | 1060 | ||
1043 | shutdown(info); | 1061 | shutdown(info, tty); |
1044 | rs_flush_buffer(tty); | 1062 | rs_flush_buffer(tty); |
1045 | 1063 | ||
1046 | tty_ldisc_flush(tty); | 1064 | tty_ldisc_flush(tty); |
1047 | tty->closing = 0; | 1065 | tty->closing = 0; |
1048 | info->event = 0; | 1066 | tty_port_tty_set(&info->tport, NULL); |
1049 | info->tty = NULL; | ||
1050 | #warning "This is not and has never been valid so fix it" | 1067 | #warning "This is not and has never been valid so fix it" |
1051 | #if 0 | 1068 | #if 0 |
1052 | if (tty->ldisc.num != ldiscs[N_TTY].num) { | 1069 | if (tty->ldisc.num != ldiscs[N_TTY].num) { |
@@ -1058,14 +1075,13 @@ static void rs_close(struct tty_struct *tty, struct file * filp) | |||
1058 | (tty->ldisc.open)(tty); | 1075 | (tty->ldisc.open)(tty); |
1059 | } | 1076 | } |
1060 | #endif | 1077 | #endif |
1061 | if (info->blocked_open) { | 1078 | if (port->blocked_open) { |
1062 | if (info->close_delay) { | 1079 | if (port->close_delay) |
1063 | msleep_interruptible(jiffies_to_msecs(info->close_delay)); | 1080 | msleep_interruptible(jiffies_to_msecs(port->close_delay)); |
1064 | } | 1081 | wake_up_interruptible(&port->open_wait); |
1065 | wake_up_interruptible(&info->open_wait); | ||
1066 | } | 1082 | } |
1067 | info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING); | 1083 | port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); |
1068 | wake_up_interruptible(&info->close_wait); | 1084 | wake_up_interruptible(&port->close_wait); |
1069 | local_irq_restore(flags); | 1085 | local_irq_restore(flags); |
1070 | } | 1086 | } |
1071 | 1087 | ||
@@ -1080,107 +1096,14 @@ void rs_hangup(struct tty_struct *tty) | |||
1080 | return; | 1096 | return; |
1081 | 1097 | ||
1082 | rs_flush_buffer(tty); | 1098 | rs_flush_buffer(tty); |
1083 | shutdown(info); | 1099 | shutdown(info, tty); |
1084 | info->event = 0; | 1100 | info->tport.count = 0; |
1085 | info->count = 0; | 1101 | info->tport.flags &= ~ASYNC_NORMAL_ACTIVE; |
1086 | info->flags &= ~S_NORMAL_ACTIVE; | 1102 | tty_port_tty_set(&info->tport, NULL); |
1087 | info->tty = NULL; | 1103 | wake_up_interruptible(&info->tport.open_wait); |
1088 | wake_up_interruptible(&info->open_wait); | ||
1089 | } | 1104 | } |
1090 | 1105 | ||
1091 | /* | 1106 | /* |
1092 | * ------------------------------------------------------------ | ||
1093 | * rs_open() and friends | ||
1094 | * ------------------------------------------------------------ | ||
1095 | */ | ||
1096 | static int block_til_ready(struct tty_struct *tty, struct file * filp, | ||
1097 | struct m68k_serial *info) | ||
1098 | { | ||
1099 | DECLARE_WAITQUEUE(wait, current); | ||
1100 | int retval; | ||
1101 | int do_clocal = 0; | ||
1102 | |||
1103 | /* | ||
1104 | * If the device is in the middle of being closed, then block | ||
1105 | * until it's done, and then try again. | ||
1106 | */ | ||
1107 | if (info->flags & S_CLOSING) { | ||
1108 | interruptible_sleep_on(&info->close_wait); | ||
1109 | #ifdef SERIAL_DO_RESTART | ||
1110 | if (info->flags & S_HUP_NOTIFY) | ||
1111 | return -EAGAIN; | ||
1112 | else | ||
1113 | return -ERESTARTSYS; | ||
1114 | #else | ||
1115 | return -EAGAIN; | ||
1116 | #endif | ||
1117 | } | ||
1118 | |||
1119 | /* | ||
1120 | * If non-blocking mode is set, or the port is not enabled, | ||
1121 | * then make the check up front and then exit. | ||
1122 | */ | ||
1123 | if ((filp->f_flags & O_NONBLOCK) || | ||
1124 | (tty->flags & (1 << TTY_IO_ERROR))) { | ||
1125 | info->flags |= S_NORMAL_ACTIVE; | ||
1126 | return 0; | ||
1127 | } | ||
1128 | |||
1129 | if (tty->termios->c_cflag & CLOCAL) | ||
1130 | do_clocal = 1; | ||
1131 | |||
1132 | /* | ||
1133 | * Block waiting for the carrier detect and the line to become | ||
1134 | * free (i.e., not in use by the callout). While we are in | ||
1135 | * this loop, info->count is dropped by one, so that | ||
1136 | * rs_close() knows when to free things. We restore it upon | ||
1137 | * exit, either normal or abnormal. | ||
1138 | */ | ||
1139 | retval = 0; | ||
1140 | add_wait_queue(&info->open_wait, &wait); | ||
1141 | |||
1142 | info->count--; | ||
1143 | info->blocked_open++; | ||
1144 | while (1) { | ||
1145 | local_irq_disable(); | ||
1146 | m68k_rtsdtr(info, 1); | ||
1147 | local_irq_enable(); | ||
1148 | current->state = TASK_INTERRUPTIBLE; | ||
1149 | if (tty_hung_up_p(filp) || | ||
1150 | !(info->flags & S_INITIALIZED)) { | ||
1151 | #ifdef SERIAL_DO_RESTART | ||
1152 | if (info->flags & S_HUP_NOTIFY) | ||
1153 | retval = -EAGAIN; | ||
1154 | else | ||
1155 | retval = -ERESTARTSYS; | ||
1156 | #else | ||
1157 | retval = -EAGAIN; | ||
1158 | #endif | ||
1159 | break; | ||
1160 | } | ||
1161 | if (!(info->flags & S_CLOSING) && do_clocal) | ||
1162 | break; | ||
1163 | if (signal_pending(current)) { | ||
1164 | retval = -ERESTARTSYS; | ||
1165 | break; | ||
1166 | } | ||
1167 | tty_unlock(); | ||
1168 | schedule(); | ||
1169 | tty_lock(); | ||
1170 | } | ||
1171 | current->state = TASK_RUNNING; | ||
1172 | remove_wait_queue(&info->open_wait, &wait); | ||
1173 | if (!tty_hung_up_p(filp)) | ||
1174 | info->count++; | ||
1175 | info->blocked_open--; | ||
1176 | |||
1177 | if (retval) | ||
1178 | return retval; | ||
1179 | info->flags |= S_NORMAL_ACTIVE; | ||
1180 | return 0; | ||
1181 | } | ||
1182 | |||
1183 | /* | ||
1184 | * This routine is called whenever a serial port is opened. It | 1107 | * This routine is called whenever a serial port is opened. It |
1185 | * enables interrupts for a serial port, linking in its S structure into | 1108 | * enables interrupts for a serial port, linking in its S structure into |
1186 | * the IRQ chain. It also performs the serial-specific | 1109 | * the IRQ chain. It also performs the serial-specific |
@@ -1196,18 +1119,18 @@ int rs_open(struct tty_struct *tty, struct file * filp) | |||
1196 | if (serial_paranoia_check(info, tty->name, "rs_open")) | 1119 | if (serial_paranoia_check(info, tty->name, "rs_open")) |
1197 | return -ENODEV; | 1120 | return -ENODEV; |
1198 | 1121 | ||
1199 | info->count++; | 1122 | info->tport.count++; |
1200 | tty->driver_data = info; | 1123 | tty->driver_data = info; |
1201 | info->tty = tty; | 1124 | tty_port_tty_set(&info->tport, tty); |
1202 | 1125 | ||
1203 | /* | 1126 | /* |
1204 | * Start up serial port | 1127 | * Start up serial port |
1205 | */ | 1128 | */ |
1206 | retval = startup(info); | 1129 | retval = startup(info, tty); |
1207 | if (retval) | 1130 | if (retval) |
1208 | return retval; | 1131 | return retval; |
1209 | 1132 | ||
1210 | return block_til_ready(tty, filp, info); | 1133 | return tty_port_block_til_ready(&info->tport, tty, filp); |
1211 | } | 1134 | } |
1212 | 1135 | ||
1213 | /* Finally, routines used to initialize the serial driver. */ | 1136 | /* Finally, routines used to initialize the serial driver. */ |
@@ -1235,11 +1158,15 @@ static const struct tty_operations rs_ops = { | |||
1235 | .set_ldisc = rs_set_ldisc, | 1158 | .set_ldisc = rs_set_ldisc, |
1236 | }; | 1159 | }; |
1237 | 1160 | ||
1161 | static const struct tty_port_operations rs_port_ops = { | ||
1162 | }; | ||
1163 | |||
1238 | /* rs_init inits the driver */ | 1164 | /* rs_init inits the driver */ |
1239 | static int __init | 1165 | static int __init |
1240 | rs68328_init(void) | 1166 | rs68328_init(void) |
1241 | { | 1167 | { |
1242 | int flags, i; | 1168 | unsigned long flags; |
1169 | int i; | ||
1243 | struct m68k_serial *info; | 1170 | struct m68k_serial *info; |
1244 | 1171 | ||
1245 | serial_driver = alloc_tty_driver(NR_PORTS); | 1172 | serial_driver = alloc_tty_driver(NR_PORTS); |
@@ -1273,19 +1200,13 @@ rs68328_init(void) | |||
1273 | for(i=0;i<NR_PORTS;i++) { | 1200 | for(i=0;i<NR_PORTS;i++) { |
1274 | 1201 | ||
1275 | info = &m68k_soft[i]; | 1202 | info = &m68k_soft[i]; |
1203 | tty_port_init(&info->tport); | ||
1204 | info->tport.ops = &rs_port_ops; | ||
1276 | info->magic = SERIAL_MAGIC; | 1205 | info->magic = SERIAL_MAGIC; |
1277 | info->port = (int) &uart_addr[i]; | 1206 | info->port = (int) &uart_addr[i]; |
1278 | info->tty = NULL; | ||
1279 | info->irq = uart_irqs[i]; | 1207 | info->irq = uart_irqs[i]; |
1280 | info->custom_divisor = 16; | 1208 | info->custom_divisor = 16; |
1281 | info->close_delay = 50; | ||
1282 | info->closing_wait = 3000; | ||
1283 | info->x_char = 0; | 1209 | info->x_char = 0; |
1284 | info->event = 0; | ||
1285 | info->count = 0; | ||
1286 | info->blocked_open = 0; | ||
1287 | init_waitqueue_head(&info->open_wait); | ||
1288 | init_waitqueue_head(&info->close_wait); | ||
1289 | info->line = i; | 1210 | info->line = i; |
1290 | info->is_cons = 1; /* Means shortcuts work */ | 1211 | info->is_cons = 1; /* Means shortcuts work */ |
1291 | 1212 | ||
diff --git a/drivers/tty/serial/68328serial.h b/drivers/tty/serial/68328serial.h deleted file mode 100644 index 3d2faabd766f..000000000000 --- a/drivers/tty/serial/68328serial.h +++ /dev/null | |||
@@ -1,186 +0,0 @@ | |||
1 | /* 68328serial.h: Definitions for the mc68328 serial driver. | ||
2 | * | ||
3 | * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu> | ||
4 | * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com> | ||
5 | * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org> | ||
6 | * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com> | ||
7 | * | ||
8 | * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca> | ||
9 | */ | ||
10 | |||
11 | #ifndef _MC683XX_SERIAL_H | ||
12 | #define _MC683XX_SERIAL_H | ||
13 | |||
14 | |||
15 | struct serial_struct { | ||
16 | int type; | ||
17 | int line; | ||
18 | int port; | ||
19 | int irq; | ||
20 | int flags; | ||
21 | int xmit_fifo_size; | ||
22 | int custom_divisor; | ||
23 | int baud_base; | ||
24 | unsigned short close_delay; | ||
25 | char reserved_char[2]; | ||
26 | int hub6; /* FIXME: We don't have AT&T Hub6 boards! */ | ||
27 | unsigned short closing_wait; /* time to wait before closing */ | ||
28 | unsigned short closing_wait2; /* no longer used... */ | ||
29 | int reserved[4]; | ||
30 | }; | ||
31 | |||
32 | /* | ||
33 | * For the close wait times, 0 means wait forever for serial port to | ||
34 | * flush its output. 65535 means don't wait at all. | ||
35 | */ | ||
36 | #define S_CLOSING_WAIT_INF 0 | ||
37 | #define S_CLOSING_WAIT_NONE 65535 | ||
38 | |||
39 | /* | ||
40 | * Definitions for S_struct (and serial_struct) flags field | ||
41 | */ | ||
42 | #define S_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes | ||
43 | on the callout port */ | ||
44 | #define S_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */ | ||
45 | #define S_SAK 0x0004 /* Secure Attention Key (Orange book) */ | ||
46 | #define S_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */ | ||
47 | |||
48 | #define S_SPD_MASK 0x0030 | ||
49 | #define S_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */ | ||
50 | |||
51 | #define S_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */ | ||
52 | #define S_SPD_CUST 0x0030 /* Use user-specified divisor */ | ||
53 | |||
54 | #define S_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */ | ||
55 | #define S_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */ | ||
56 | #define S_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */ | ||
57 | #define S_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */ | ||
58 | #define S_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */ | ||
59 | |||
60 | #define S_FLAGS 0x0FFF /* Possible legal S flags */ | ||
61 | #define S_USR_MASK 0x0430 /* Legal flags that non-privileged | ||
62 | * users can set or reset */ | ||
63 | |||
64 | /* Internal flags used only by kernel/chr_drv/serial.c */ | ||
65 | #define S_INITIALIZED 0x80000000 /* Serial port was initialized */ | ||
66 | #define S_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */ | ||
67 | #define S_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ | ||
68 | #define S_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ | ||
69 | #define S_CLOSING 0x08000000 /* Serial port is closing */ | ||
70 | #define S_CTS_FLOW 0x04000000 /* Do CTS flow control */ | ||
71 | #define S_CHECK_CD 0x02000000 /* i.e., CLOCAL */ | ||
72 | |||
73 | /* Software state per channel */ | ||
74 | |||
75 | #ifdef __KERNEL__ | ||
76 | |||
77 | /* | ||
78 | * I believe this is the optimal setting that reduces the number of interrupts. | ||
79 | * At high speeds the output might become a little "bursted" (use USTCNT_TXHE | ||
80 | * if that bothers you), but in most cases it will not, since we try to | ||
81 | * transmit characters every time rs_interrupt is called. Thus, quite often | ||
82 | * you'll see that a receive interrupt occures before the transmit one. | ||
83 | * -- Vladimir Gurevich | ||
84 | */ | ||
85 | #define USTCNT_TX_INTR_MASK (USTCNT_TXEE) | ||
86 | |||
87 | /* | ||
88 | * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special | ||
89 | * "Old data interrupt" which occures whenever the data stay in the FIFO | ||
90 | * longer than 30 bits time. This allows us to use FIFO without compromising | ||
91 | * latency. '328 does not have this feature and without the real 328-based | ||
92 | * board I would assume that RXRE is the safest setting. | ||
93 | * | ||
94 | * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of | ||
95 | * interrupts. RXFE (receive queue full) causes the system to lose data | ||
96 | * at least at 115200 baud | ||
97 | * | ||
98 | * If your board is busy doing other stuff, you might consider to use | ||
99 | * RXRE (data ready intrrupt) instead. | ||
100 | * | ||
101 | * The other option is to make these INTR masks run-time configurable, so | ||
102 | * that people can dynamically adapt them according to the current usage. | ||
103 | * -- Vladimir Gurevich | ||
104 | */ | ||
105 | |||
106 | /* (es) */ | ||
107 | #if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328) | ||
108 | #define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN) | ||
109 | #elif defined(CONFIG_M68328) | ||
110 | #define USTCNT_RX_INTR_MASK (USTCNT_RXRE) | ||
111 | #else | ||
112 | #error Please, define the Rx interrupt events for your CPU | ||
113 | #endif | ||
114 | /* (/es) */ | ||
115 | |||
116 | /* | ||
117 | * This is our internal structure for each serial port's state. | ||
118 | * | ||
119 | * Many fields are paralleled by the structure used by the serial_struct | ||
120 | * structure. | ||
121 | * | ||
122 | * For definitions of the flags field, see tty.h | ||
123 | */ | ||
124 | |||
125 | struct m68k_serial { | ||
126 | char soft_carrier; /* Use soft carrier on this channel */ | ||
127 | char break_abort; /* Is serial console in, so process brk/abrt */ | ||
128 | char is_cons; /* Is this our console. */ | ||
129 | |||
130 | /* We need to know the current clock divisor | ||
131 | * to read the bps rate the chip has currently | ||
132 | * loaded. | ||
133 | */ | ||
134 | unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */ | ||
135 | int baud; | ||
136 | int magic; | ||
137 | int baud_base; | ||
138 | int port; | ||
139 | int irq; | ||
140 | int flags; /* defined in tty.h */ | ||
141 | int type; /* UART type */ | ||
142 | struct tty_struct *tty; | ||
143 | int read_status_mask; | ||
144 | int ignore_status_mask; | ||
145 | int timeout; | ||
146 | int xmit_fifo_size; | ||
147 | int custom_divisor; | ||
148 | int x_char; /* xon/xoff character */ | ||
149 | int close_delay; | ||
150 | unsigned short closing_wait; | ||
151 | unsigned short closing_wait2; | ||
152 | unsigned long event; | ||
153 | unsigned long last_active; | ||
154 | int line; | ||
155 | int count; /* # of fd on device */ | ||
156 | int blocked_open; /* # of blocked opens */ | ||
157 | unsigned char *xmit_buf; | ||
158 | int xmit_head; | ||
159 | int xmit_tail; | ||
160 | int xmit_cnt; | ||
161 | wait_queue_head_t open_wait; | ||
162 | wait_queue_head_t close_wait; | ||
163 | }; | ||
164 | |||
165 | |||
166 | #define SERIAL_MAGIC 0x5301 | ||
167 | |||
168 | /* | ||
169 | * The size of the serial xmit buffer is 1 page, or 4096 bytes | ||
170 | */ | ||
171 | #define SERIAL_XMIT_SIZE 4096 | ||
172 | |||
173 | /* | ||
174 | * Events are used to schedule things to happen at timer-interrupt | ||
175 | * time, instead of at rs interrupt time. | ||
176 | */ | ||
177 | #define RS_EVENT_WRITE_WAKEUP 0 | ||
178 | |||
179 | /* | ||
180 | * Define the number of ports supported and their irqs. | ||
181 | */ | ||
182 | #define NR_PORTS 1 | ||
183 | #define UART_IRQ_DEFNS {UART_IRQ_NUM} | ||
184 | |||
185 | #endif /* __KERNEL__ */ | ||
186 | #endif /* !(_MC683XX_SERIAL_H) */ | ||
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c index 5c27f7e6c9f1..47d061b9ad4d 100644 --- a/drivers/tty/serial/8250/8250.c +++ b/drivers/tty/serial/8250/8250.c | |||
@@ -284,7 +284,20 @@ static const struct serial8250_config uart_config[] = { | |||
284 | }, | 284 | }, |
285 | }; | 285 | }; |
286 | 286 | ||
287 | #if defined(CONFIG_MIPS_ALCHEMY) | 287 | /* Uart divisor latch read */ |
288 | static int default_serial_dl_read(struct uart_8250_port *up) | ||
289 | { | ||
290 | return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8; | ||
291 | } | ||
292 | |||
293 | /* Uart divisor latch write */ | ||
294 | static void default_serial_dl_write(struct uart_8250_port *up, int value) | ||
295 | { | ||
296 | serial_out(up, UART_DLL, value & 0xff); | ||
297 | serial_out(up, UART_DLM, value >> 8 & 0xff); | ||
298 | } | ||
299 | |||
300 | #ifdef CONFIG_MIPS_ALCHEMY | ||
288 | 301 | ||
289 | /* Au1x00 UART hardware has a weird register layout */ | 302 | /* Au1x00 UART hardware has a weird register layout */ |
290 | static const u8 au_io_in_map[] = { | 303 | static const u8 au_io_in_map[] = { |
@@ -305,22 +318,32 @@ static const u8 au_io_out_map[] = { | |||
305 | [UART_MCR] = 6, | 318 | [UART_MCR] = 6, |
306 | }; | 319 | }; |
307 | 320 | ||
308 | /* sane hardware needs no mapping */ | 321 | static unsigned int au_serial_in(struct uart_port *p, int offset) |
309 | static inline int map_8250_in_reg(struct uart_port *p, int offset) | 322 | { |
323 | offset = au_io_in_map[offset] << p->regshift; | ||
324 | return __raw_readl(p->membase + offset); | ||
325 | } | ||
326 | |||
327 | static void au_serial_out(struct uart_port *p, int offset, int value) | ||
328 | { | ||
329 | offset = au_io_out_map[offset] << p->regshift; | ||
330 | __raw_writel(value, p->membase + offset); | ||
331 | } | ||
332 | |||
333 | /* Au1x00 haven't got a standard divisor latch */ | ||
334 | static int au_serial_dl_read(struct uart_8250_port *up) | ||
310 | { | 335 | { |
311 | if (p->iotype != UPIO_AU) | 336 | return __raw_readl(up->port.membase + 0x28); |
312 | return offset; | ||
313 | return au_io_in_map[offset]; | ||
314 | } | 337 | } |
315 | 338 | ||
316 | static inline int map_8250_out_reg(struct uart_port *p, int offset) | 339 | static void au_serial_dl_write(struct uart_8250_port *up, int value) |
317 | { | 340 | { |
318 | if (p->iotype != UPIO_AU) | 341 | __raw_writel(value, up->port.membase + 0x28); |
319 | return offset; | ||
320 | return au_io_out_map[offset]; | ||
321 | } | 342 | } |
322 | 343 | ||
323 | #elif defined(CONFIG_SERIAL_8250_RM9K) | 344 | #endif |
345 | |||
346 | #ifdef CONFIG_SERIAL_8250_RM9K | ||
324 | 347 | ||
325 | static const u8 | 348 | static const u8 |
326 | regmap_in[8] = { | 349 | regmap_in[8] = { |
@@ -344,87 +367,79 @@ static const u8 | |||
344 | [UART_SCR] = 0x2c | 367 | [UART_SCR] = 0x2c |
345 | }; | 368 | }; |
346 | 369 | ||
347 | static inline int map_8250_in_reg(struct uart_port *p, int offset) | 370 | static unsigned int rm9k_serial_in(struct uart_port *p, int offset) |
348 | { | 371 | { |
349 | if (p->iotype != UPIO_RM9000) | 372 | offset = regmap_in[offset] << p->regshift; |
350 | return offset; | 373 | return readl(p->membase + offset); |
351 | return regmap_in[offset]; | ||
352 | } | 374 | } |
353 | 375 | ||
354 | static inline int map_8250_out_reg(struct uart_port *p, int offset) | 376 | static void rm9k_serial_out(struct uart_port *p, int offset, int value) |
355 | { | 377 | { |
356 | if (p->iotype != UPIO_RM9000) | 378 | offset = regmap_out[offset] << p->regshift; |
357 | return offset; | 379 | writel(value, p->membase + offset); |
358 | return regmap_out[offset]; | ||
359 | } | 380 | } |
360 | 381 | ||
361 | #else | 382 | static int rm9k_serial_dl_read(struct uart_8250_port *up) |
383 | { | ||
384 | return ((__raw_readl(up->port.membase + 0x10) << 8) | | ||
385 | (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff; | ||
386 | } | ||
362 | 387 | ||
363 | /* sane hardware needs no mapping */ | 388 | static void rm9k_serial_dl_write(struct uart_8250_port *up, int value) |
364 | #define map_8250_in_reg(up, offset) (offset) | 389 | { |
365 | #define map_8250_out_reg(up, offset) (offset) | 390 | __raw_writel(value, up->port.membase + 0x08); |
391 | __raw_writel(value >> 8, up->port.membase + 0x10); | ||
392 | } | ||
366 | 393 | ||
367 | #endif | 394 | #endif |
368 | 395 | ||
369 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) | 396 | static unsigned int hub6_serial_in(struct uart_port *p, int offset) |
370 | { | 397 | { |
371 | offset = map_8250_in_reg(p, offset) << p->regshift; | 398 | offset = offset << p->regshift; |
372 | outb(p->hub6 - 1 + offset, p->iobase); | 399 | outb(p->hub6 - 1 + offset, p->iobase); |
373 | return inb(p->iobase + 1); | 400 | return inb(p->iobase + 1); |
374 | } | 401 | } |
375 | 402 | ||
376 | static void hub6_serial_out(struct uart_port *p, int offset, int value) | 403 | static void hub6_serial_out(struct uart_port *p, int offset, int value) |
377 | { | 404 | { |
378 | offset = map_8250_out_reg(p, offset) << p->regshift; | 405 | offset = offset << p->regshift; |
379 | outb(p->hub6 - 1 + offset, p->iobase); | 406 | outb(p->hub6 - 1 + offset, p->iobase); |
380 | outb(value, p->iobase + 1); | 407 | outb(value, p->iobase + 1); |
381 | } | 408 | } |
382 | 409 | ||
383 | static unsigned int mem_serial_in(struct uart_port *p, int offset) | 410 | static unsigned int mem_serial_in(struct uart_port *p, int offset) |
384 | { | 411 | { |
385 | offset = map_8250_in_reg(p, offset) << p->regshift; | 412 | offset = offset << p->regshift; |
386 | return readb(p->membase + offset); | 413 | return readb(p->membase + offset); |
387 | } | 414 | } |
388 | 415 | ||
389 | static void mem_serial_out(struct uart_port *p, int offset, int value) | 416 | static void mem_serial_out(struct uart_port *p, int offset, int value) |
390 | { | 417 | { |
391 | offset = map_8250_out_reg(p, offset) << p->regshift; | 418 | offset = offset << p->regshift; |
392 | writeb(value, p->membase + offset); | 419 | writeb(value, p->membase + offset); |
393 | } | 420 | } |
394 | 421 | ||
395 | static void mem32_serial_out(struct uart_port *p, int offset, int value) | 422 | static void mem32_serial_out(struct uart_port *p, int offset, int value) |
396 | { | 423 | { |
397 | offset = map_8250_out_reg(p, offset) << p->regshift; | 424 | offset = offset << p->regshift; |
398 | writel(value, p->membase + offset); | 425 | writel(value, p->membase + offset); |
399 | } | 426 | } |
400 | 427 | ||
401 | static unsigned int mem32_serial_in(struct uart_port *p, int offset) | 428 | static unsigned int mem32_serial_in(struct uart_port *p, int offset) |
402 | { | 429 | { |
403 | offset = map_8250_in_reg(p, offset) << p->regshift; | 430 | offset = offset << p->regshift; |
404 | return readl(p->membase + offset); | 431 | return readl(p->membase + offset); |
405 | } | 432 | } |
406 | 433 | ||
407 | static unsigned int au_serial_in(struct uart_port *p, int offset) | ||
408 | { | ||
409 | offset = map_8250_in_reg(p, offset) << p->regshift; | ||
410 | return __raw_readl(p->membase + offset); | ||
411 | } | ||
412 | |||
413 | static void au_serial_out(struct uart_port *p, int offset, int value) | ||
414 | { | ||
415 | offset = map_8250_out_reg(p, offset) << p->regshift; | ||
416 | __raw_writel(value, p->membase + offset); | ||
417 | } | ||
418 | |||
419 | static unsigned int io_serial_in(struct uart_port *p, int offset) | 434 | static unsigned int io_serial_in(struct uart_port *p, int offset) |
420 | { | 435 | { |
421 | offset = map_8250_in_reg(p, offset) << p->regshift; | 436 | offset = offset << p->regshift; |
422 | return inb(p->iobase + offset); | 437 | return inb(p->iobase + offset); |
423 | } | 438 | } |
424 | 439 | ||
425 | static void io_serial_out(struct uart_port *p, int offset, int value) | 440 | static void io_serial_out(struct uart_port *p, int offset, int value) |
426 | { | 441 | { |
427 | offset = map_8250_out_reg(p, offset) << p->regshift; | 442 | offset = offset << p->regshift; |
428 | outb(value, p->iobase + offset); | 443 | outb(value, p->iobase + offset); |
429 | } | 444 | } |
430 | 445 | ||
@@ -434,6 +449,10 @@ static void set_io_from_upio(struct uart_port *p) | |||
434 | { | 449 | { |
435 | struct uart_8250_port *up = | 450 | struct uart_8250_port *up = |
436 | container_of(p, struct uart_8250_port, port); | 451 | container_of(p, struct uart_8250_port, port); |
452 | |||
453 | up->dl_read = default_serial_dl_read; | ||
454 | up->dl_write = default_serial_dl_write; | ||
455 | |||
437 | switch (p->iotype) { | 456 | switch (p->iotype) { |
438 | case UPIO_HUB6: | 457 | case UPIO_HUB6: |
439 | p->serial_in = hub6_serial_in; | 458 | p->serial_in = hub6_serial_in; |
@@ -445,16 +464,28 @@ static void set_io_from_upio(struct uart_port *p) | |||
445 | p->serial_out = mem_serial_out; | 464 | p->serial_out = mem_serial_out; |
446 | break; | 465 | break; |
447 | 466 | ||
448 | case UPIO_RM9000: | ||
449 | case UPIO_MEM32: | 467 | case UPIO_MEM32: |
450 | p->serial_in = mem32_serial_in; | 468 | p->serial_in = mem32_serial_in; |
451 | p->serial_out = mem32_serial_out; | 469 | p->serial_out = mem32_serial_out; |
452 | break; | 470 | break; |
453 | 471 | ||
472 | #ifdef CONFIG_SERIAL_8250_RM9K | ||
473 | case UPIO_RM9000: | ||
474 | p->serial_in = rm9k_serial_in; | ||
475 | p->serial_out = rm9k_serial_out; | ||
476 | up->dl_read = rm9k_serial_dl_read; | ||
477 | up->dl_write = rm9k_serial_dl_write; | ||
478 | break; | ||
479 | #endif | ||
480 | |||
481 | #ifdef CONFIG_MIPS_ALCHEMY | ||
454 | case UPIO_AU: | 482 | case UPIO_AU: |
455 | p->serial_in = au_serial_in; | 483 | p->serial_in = au_serial_in; |
456 | p->serial_out = au_serial_out; | 484 | p->serial_out = au_serial_out; |
485 | up->dl_read = au_serial_dl_read; | ||
486 | up->dl_write = au_serial_dl_write; | ||
457 | break; | 487 | break; |
488 | #endif | ||
458 | 489 | ||
459 | default: | 490 | default: |
460 | p->serial_in = io_serial_in; | 491 | p->serial_in = io_serial_in; |
@@ -481,59 +512,6 @@ serial_port_out_sync(struct uart_port *p, int offset, int value) | |||
481 | } | 512 | } |
482 | } | 513 | } |
483 | 514 | ||
484 | /* Uart divisor latch read */ | ||
485 | static inline int _serial_dl_read(struct uart_8250_port *up) | ||
486 | { | ||
487 | return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8; | ||
488 | } | ||
489 | |||
490 | /* Uart divisor latch write */ | ||
491 | static inline void _serial_dl_write(struct uart_8250_port *up, int value) | ||
492 | { | ||
493 | serial_out(up, UART_DLL, value & 0xff); | ||
494 | serial_out(up, UART_DLM, value >> 8 & 0xff); | ||
495 | } | ||
496 | |||
497 | #if defined(CONFIG_MIPS_ALCHEMY) | ||
498 | /* Au1x00 haven't got a standard divisor latch */ | ||
499 | static int serial_dl_read(struct uart_8250_port *up) | ||
500 | { | ||
501 | if (up->port.iotype == UPIO_AU) | ||
502 | return __raw_readl(up->port.membase + 0x28); | ||
503 | else | ||
504 | return _serial_dl_read(up); | ||
505 | } | ||
506 | |||
507 | static void serial_dl_write(struct uart_8250_port *up, int value) | ||
508 | { | ||
509 | if (up->port.iotype == UPIO_AU) | ||
510 | __raw_writel(value, up->port.membase + 0x28); | ||
511 | else | ||
512 | _serial_dl_write(up, value); | ||
513 | } | ||
514 | #elif defined(CONFIG_SERIAL_8250_RM9K) | ||
515 | static int serial_dl_read(struct uart_8250_port *up) | ||
516 | { | ||
517 | return (up->port.iotype == UPIO_RM9000) ? | ||
518 | (((__raw_readl(up->port.membase + 0x10) << 8) | | ||
519 | (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) : | ||
520 | _serial_dl_read(up); | ||
521 | } | ||
522 | |||
523 | static void serial_dl_write(struct uart_8250_port *up, int value) | ||
524 | { | ||
525 | if (up->port.iotype == UPIO_RM9000) { | ||
526 | __raw_writel(value, up->port.membase + 0x08); | ||
527 | __raw_writel(value >> 8, up->port.membase + 0x10); | ||
528 | } else { | ||
529 | _serial_dl_write(up, value); | ||
530 | } | ||
531 | } | ||
532 | #else | ||
533 | #define serial_dl_read(up) _serial_dl_read(up) | ||
534 | #define serial_dl_write(up, value) _serial_dl_write(up, value) | ||
535 | #endif | ||
536 | |||
537 | /* | 515 | /* |
538 | * For the 16C950 | 516 | * For the 16C950 |
539 | */ | 517 | */ |
@@ -568,6 +546,16 @@ static void serial8250_clear_fifos(struct uart_8250_port *p) | |||
568 | } | 546 | } |
569 | } | 547 | } |
570 | 548 | ||
549 | void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p) | ||
550 | { | ||
551 | unsigned char fcr; | ||
552 | |||
553 | serial8250_clear_fifos(p); | ||
554 | fcr = uart_config[p->port.type].fcr; | ||
555 | serial_out(p, UART_FCR, fcr); | ||
556 | } | ||
557 | EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos); | ||
558 | |||
571 | /* | 559 | /* |
572 | * IER sleep support. UARTs which have EFRs need the "extended | 560 | * IER sleep support. UARTs which have EFRs need the "extended |
573 | * capability" bit enabled. Note that on XR16C850s, we need to | 561 | * capability" bit enabled. Note that on XR16C850s, we need to |
@@ -1332,27 +1320,6 @@ static void serial8250_enable_ms(struct uart_port *port) | |||
1332 | } | 1320 | } |
1333 | 1321 | ||
1334 | /* | 1322 | /* |
1335 | * Clear the Tegra rx fifo after a break | ||
1336 | * | ||
1337 | * FIXME: This needs to become a port specific callback once we have a | ||
1338 | * framework for this | ||
1339 | */ | ||
1340 | static void clear_rx_fifo(struct uart_8250_port *up) | ||
1341 | { | ||
1342 | unsigned int status, tmout = 10000; | ||
1343 | do { | ||
1344 | status = serial_in(up, UART_LSR); | ||
1345 | if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) | ||
1346 | status = serial_in(up, UART_RX); | ||
1347 | else | ||
1348 | break; | ||
1349 | if (--tmout == 0) | ||
1350 | break; | ||
1351 | udelay(1); | ||
1352 | } while (1); | ||
1353 | } | ||
1354 | |||
1355 | /* | ||
1356 | * serial8250_rx_chars: processes according to the passed in LSR | 1323 | * serial8250_rx_chars: processes according to the passed in LSR |
1357 | * value, and returns the remaining LSR bits not handled | 1324 | * value, and returns the remaining LSR bits not handled |
1358 | * by this Rx routine. | 1325 | * by this Rx routine. |
@@ -1386,20 +1353,10 @@ serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr) | |||
1386 | up->lsr_saved_flags = 0; | 1353 | up->lsr_saved_flags = 0; |
1387 | 1354 | ||
1388 | if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { | 1355 | if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { |
1389 | /* | ||
1390 | * For statistics only | ||
1391 | */ | ||
1392 | if (lsr & UART_LSR_BI) { | 1356 | if (lsr & UART_LSR_BI) { |
1393 | lsr &= ~(UART_LSR_FE | UART_LSR_PE); | 1357 | lsr &= ~(UART_LSR_FE | UART_LSR_PE); |
1394 | port->icount.brk++; | 1358 | port->icount.brk++; |
1395 | /* | 1359 | /* |
1396 | * If tegra port then clear the rx fifo to | ||
1397 | * accept another break/character. | ||
1398 | */ | ||
1399 | if (port->type == PORT_TEGRA) | ||
1400 | clear_rx_fifo(up); | ||
1401 | |||
1402 | /* | ||
1403 | * We do the SysRQ and SAK checking | 1360 | * We do the SysRQ and SAK checking |
1404 | * here because otherwise the break | 1361 | * here because otherwise the break |
1405 | * may get masked by ignore_status_mask | 1362 | * may get masked by ignore_status_mask |
@@ -2280,10 +2237,11 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, | |||
2280 | quot++; | 2237 | quot++; |
2281 | 2238 | ||
2282 | if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { | 2239 | if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { |
2283 | if (baud < 2400) | 2240 | fcr = uart_config[port->type].fcr; |
2284 | fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; | 2241 | if (baud < 2400) { |
2285 | else | 2242 | fcr &= ~UART_FCR_TRIGGER_MASK; |
2286 | fcr = uart_config[port->type].fcr; | 2243 | fcr |= UART_FCR_TRIGGER_1; |
2244 | } | ||
2287 | } | 2245 | } |
2288 | 2246 | ||
2289 | /* | 2247 | /* |
@@ -3037,6 +2995,7 @@ static int __devinit serial8250_probe(struct platform_device *dev) | |||
3037 | port.serial_in = p->serial_in; | 2995 | port.serial_in = p->serial_in; |
3038 | port.serial_out = p->serial_out; | 2996 | port.serial_out = p->serial_out; |
3039 | port.handle_irq = p->handle_irq; | 2997 | port.handle_irq = p->handle_irq; |
2998 | port.handle_break = p->handle_break; | ||
3040 | port.set_termios = p->set_termios; | 2999 | port.set_termios = p->set_termios; |
3041 | port.pm = p->pm; | 3000 | port.pm = p->pm; |
3042 | port.dev = &dev->dev; | 3001 | port.dev = &dev->dev; |
@@ -3153,7 +3112,7 @@ static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port * | |||
3153 | } | 3112 | } |
3154 | 3113 | ||
3155 | /** | 3114 | /** |
3156 | * serial8250_register_port - register a serial port | 3115 | * serial8250_register_8250_port - register a serial port |
3157 | * @port: serial port template | 3116 | * @port: serial port template |
3158 | * | 3117 | * |
3159 | * Configure the serial port specified by the request. If the | 3118 | * Configure the serial port specified by the request. If the |
@@ -3165,50 +3124,56 @@ static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port * | |||
3165 | * | 3124 | * |
3166 | * On success the port is ready to use and the line number is returned. | 3125 | * On success the port is ready to use and the line number is returned. |
3167 | */ | 3126 | */ |
3168 | int serial8250_register_port(struct uart_port *port) | 3127 | int serial8250_register_8250_port(struct uart_8250_port *up) |
3169 | { | 3128 | { |
3170 | struct uart_8250_port *uart; | 3129 | struct uart_8250_port *uart; |
3171 | int ret = -ENOSPC; | 3130 | int ret = -ENOSPC; |
3172 | 3131 | ||
3173 | if (port->uartclk == 0) | 3132 | if (up->port.uartclk == 0) |
3174 | return -EINVAL; | 3133 | return -EINVAL; |
3175 | 3134 | ||
3176 | mutex_lock(&serial_mutex); | 3135 | mutex_lock(&serial_mutex); |
3177 | 3136 | ||
3178 | uart = serial8250_find_match_or_unused(port); | 3137 | uart = serial8250_find_match_or_unused(&up->port); |
3179 | if (uart) { | 3138 | if (uart) { |
3180 | uart_remove_one_port(&serial8250_reg, &uart->port); | 3139 | uart_remove_one_port(&serial8250_reg, &uart->port); |
3181 | 3140 | ||
3182 | uart->port.iobase = port->iobase; | 3141 | uart->port.iobase = up->port.iobase; |
3183 | uart->port.membase = port->membase; | 3142 | uart->port.membase = up->port.membase; |
3184 | uart->port.irq = port->irq; | 3143 | uart->port.irq = up->port.irq; |
3185 | uart->port.irqflags = port->irqflags; | 3144 | uart->port.irqflags = up->port.irqflags; |
3186 | uart->port.uartclk = port->uartclk; | 3145 | uart->port.uartclk = up->port.uartclk; |
3187 | uart->port.fifosize = port->fifosize; | 3146 | uart->port.fifosize = up->port.fifosize; |
3188 | uart->port.regshift = port->regshift; | 3147 | uart->port.regshift = up->port.regshift; |
3189 | uart->port.iotype = port->iotype; | 3148 | uart->port.iotype = up->port.iotype; |
3190 | uart->port.flags = port->flags | UPF_BOOT_AUTOCONF; | 3149 | uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF; |
3191 | uart->port.mapbase = port->mapbase; | 3150 | uart->port.mapbase = up->port.mapbase; |
3192 | uart->port.private_data = port->private_data; | 3151 | uart->port.private_data = up->port.private_data; |
3193 | if (port->dev) | 3152 | if (up->port.dev) |
3194 | uart->port.dev = port->dev; | 3153 | uart->port.dev = up->port.dev; |
3195 | 3154 | ||
3196 | if (port->flags & UPF_FIXED_TYPE) | 3155 | if (up->port.flags & UPF_FIXED_TYPE) |
3197 | serial8250_init_fixed_type_port(uart, port->type); | 3156 | serial8250_init_fixed_type_port(uart, up->port.type); |
3198 | 3157 | ||
3199 | set_io_from_upio(&uart->port); | 3158 | set_io_from_upio(&uart->port); |
3200 | /* Possibly override default I/O functions. */ | 3159 | /* Possibly override default I/O functions. */ |
3201 | if (port->serial_in) | 3160 | if (up->port.serial_in) |
3202 | uart->port.serial_in = port->serial_in; | 3161 | uart->port.serial_in = up->port.serial_in; |
3203 | if (port->serial_out) | 3162 | if (up->port.serial_out) |
3204 | uart->port.serial_out = port->serial_out; | 3163 | uart->port.serial_out = up->port.serial_out; |
3205 | if (port->handle_irq) | 3164 | if (up->port.handle_irq) |
3206 | uart->port.handle_irq = port->handle_irq; | 3165 | uart->port.handle_irq = up->port.handle_irq; |
3207 | /* Possibly override set_termios call */ | 3166 | /* Possibly override set_termios call */ |
3208 | if (port->set_termios) | 3167 | if (up->port.set_termios) |
3209 | uart->port.set_termios = port->set_termios; | 3168 | uart->port.set_termios = up->port.set_termios; |
3210 | if (port->pm) | 3169 | if (up->port.pm) |
3211 | uart->port.pm = port->pm; | 3170 | uart->port.pm = up->port.pm; |
3171 | if (up->port.handle_break) | ||
3172 | uart->port.handle_break = up->port.handle_break; | ||
3173 | if (up->dl_read) | ||
3174 | uart->dl_read = up->dl_read; | ||
3175 | if (up->dl_write) | ||
3176 | uart->dl_write = up->dl_write; | ||
3212 | 3177 | ||
3213 | if (serial8250_isa_config != NULL) | 3178 | if (serial8250_isa_config != NULL) |
3214 | serial8250_isa_config(0, &uart->port, | 3179 | serial8250_isa_config(0, &uart->port, |
@@ -3222,6 +3187,29 @@ int serial8250_register_port(struct uart_port *port) | |||
3222 | 3187 | ||
3223 | return ret; | 3188 | return ret; |
3224 | } | 3189 | } |
3190 | EXPORT_SYMBOL(serial8250_register_8250_port); | ||
3191 | |||
3192 | /** | ||
3193 | * serial8250_register_port - register a serial port | ||
3194 | * @port: serial port template | ||
3195 | * | ||
3196 | * Configure the serial port specified by the request. If the | ||
3197 | * port exists and is in use, it is hung up and unregistered | ||
3198 | * first. | ||
3199 | * | ||
3200 | * The port is then probed and if necessary the IRQ is autodetected | ||
3201 | * If this fails an error is returned. | ||
3202 | * | ||
3203 | * On success the port is ready to use and the line number is returned. | ||
3204 | */ | ||
3205 | int serial8250_register_port(struct uart_port *port) | ||
3206 | { | ||
3207 | struct uart_8250_port up; | ||
3208 | |||
3209 | memset(&up, 0, sizeof(up)); | ||
3210 | memcpy(&up.port, port, sizeof(*port)); | ||
3211 | return serial8250_register_8250_port(&up); | ||
3212 | } | ||
3225 | EXPORT_SYMBOL(serial8250_register_port); | 3213 | EXPORT_SYMBOL(serial8250_register_port); |
3226 | 3214 | ||
3227 | /** | 3215 | /** |
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h index 2868a1da254d..f9719d167c8d 100644 --- a/drivers/tty/serial/8250/8250.h +++ b/drivers/tty/serial/8250/8250.h | |||
@@ -37,6 +37,10 @@ struct uart_8250_port { | |||
37 | unsigned char lsr_saved_flags; | 37 | unsigned char lsr_saved_flags; |
38 | #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA | 38 | #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA |
39 | unsigned char msr_saved_flags; | 39 | unsigned char msr_saved_flags; |
40 | |||
41 | /* 8250 specific callbacks */ | ||
42 | int (*dl_read)(struct uart_8250_port *); | ||
43 | void (*dl_write)(struct uart_8250_port *, int); | ||
40 | }; | 44 | }; |
41 | 45 | ||
42 | struct old_serial_port { | 46 | struct old_serial_port { |
@@ -96,6 +100,18 @@ static inline void serial_out(struct uart_8250_port *up, int offset, int value) | |||
96 | up->port.serial_out(&up->port, offset, value); | 100 | up->port.serial_out(&up->port, offset, value); |
97 | } | 101 | } |
98 | 102 | ||
103 | void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p); | ||
104 | |||
105 | static inline int serial_dl_read(struct uart_8250_port *up) | ||
106 | { | ||
107 | return up->dl_read(up); | ||
108 | } | ||
109 | |||
110 | static inline void serial_dl_write(struct uart_8250_port *up, int value) | ||
111 | { | ||
112 | up->dl_write(up, value); | ||
113 | } | ||
114 | |||
99 | #if defined(__alpha__) && !defined(CONFIG_PCI) | 115 | #if defined(__alpha__) && !defined(CONFIG_PCI) |
100 | /* | 116 | /* |
101 | * Digital did something really horribly wrong with the OUT1 and OUT2 | 117 | * Digital did something really horribly wrong with the OUT1 and OUT2 |
diff --git a/drivers/tty/serial/8250/8250_em.c b/drivers/tty/serial/8250/8250_em.c new file mode 100644 index 000000000000..3a0363e7f3a7 --- /dev/null +++ b/drivers/tty/serial/8250/8250_em.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /* | ||
2 | * Renesas Emma Mobile 8250 driver | ||
3 | * | ||
4 | * Copyright (C) 2012 Magnus Damm | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/device.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/io.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/serial_8250.h> | ||
25 | #include <linux/serial_core.h> | ||
26 | #include <linux/serial_reg.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/clk.h> | ||
29 | #include <linux/slab.h> | ||
30 | |||
31 | #include "8250.h" | ||
32 | |||
33 | #define UART_DLL_EM 9 | ||
34 | #define UART_DLM_EM 10 | ||
35 | |||
36 | struct serial8250_em_priv { | ||
37 | struct clk *sclk; | ||
38 | int line; | ||
39 | }; | ||
40 | |||
41 | static void serial8250_em_serial_out(struct uart_port *p, int offset, int value) | ||
42 | { | ||
43 | switch (offset) { | ||
44 | case UART_TX: /* TX @ 0x00 */ | ||
45 | writeb(value, p->membase); | ||
46 | break; | ||
47 | case UART_FCR: /* FCR @ 0x0c (+1) */ | ||
48 | case UART_LCR: /* LCR @ 0x10 (+1) */ | ||
49 | case UART_MCR: /* MCR @ 0x14 (+1) */ | ||
50 | case UART_SCR: /* SCR @ 0x20 (+1) */ | ||
51 | writel(value, p->membase + ((offset + 1) << 2)); | ||
52 | break; | ||
53 | case UART_IER: /* IER @ 0x04 */ | ||
54 | value &= 0x0f; /* only 4 valid bits - not Xscale */ | ||
55 | /* fall-through */ | ||
56 | case UART_DLL_EM: /* DLL @ 0x24 (+9) */ | ||
57 | case UART_DLM_EM: /* DLM @ 0x28 (+9) */ | ||
58 | writel(value, p->membase + (offset << 2)); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | static unsigned int serial8250_em_serial_in(struct uart_port *p, int offset) | ||
63 | { | ||
64 | switch (offset) { | ||
65 | case UART_RX: /* RX @ 0x00 */ | ||
66 | return readb(p->membase); | ||
67 | case UART_MCR: /* MCR @ 0x14 (+1) */ | ||
68 | case UART_LSR: /* LSR @ 0x18 (+1) */ | ||
69 | case UART_MSR: /* MSR @ 0x1c (+1) */ | ||
70 | case UART_SCR: /* SCR @ 0x20 (+1) */ | ||
71 | return readl(p->membase + ((offset + 1) << 2)); | ||
72 | case UART_IER: /* IER @ 0x04 */ | ||
73 | case UART_IIR: /* IIR @ 0x08 */ | ||
74 | case UART_DLL_EM: /* DLL @ 0x24 (+9) */ | ||
75 | case UART_DLM_EM: /* DLM @ 0x28 (+9) */ | ||
76 | return readl(p->membase + (offset << 2)); | ||
77 | } | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | static int serial8250_em_serial_dl_read(struct uart_8250_port *up) | ||
82 | { | ||
83 | return serial_in(up, UART_DLL_EM) | serial_in(up, UART_DLM_EM) << 8; | ||
84 | } | ||
85 | |||
86 | static void serial8250_em_serial_dl_write(struct uart_8250_port *up, int value) | ||
87 | { | ||
88 | serial_out(up, UART_DLL_EM, value & 0xff); | ||
89 | serial_out(up, UART_DLM_EM, value >> 8 & 0xff); | ||
90 | } | ||
91 | |||
92 | static int __devinit serial8250_em_probe(struct platform_device *pdev) | ||
93 | { | ||
94 | struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
95 | struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
96 | struct serial8250_em_priv *priv; | ||
97 | struct uart_8250_port up; | ||
98 | int ret = -EINVAL; | ||
99 | |||
100 | if (!regs || !irq) { | ||
101 | dev_err(&pdev->dev, "missing registers or irq\n"); | ||
102 | goto err0; | ||
103 | } | ||
104 | |||
105 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
106 | if (!priv) { | ||
107 | dev_err(&pdev->dev, "unable to allocate private data\n"); | ||
108 | ret = -ENOMEM; | ||
109 | goto err0; | ||
110 | } | ||
111 | |||
112 | priv->sclk = clk_get(&pdev->dev, "sclk"); | ||
113 | if (IS_ERR(priv->sclk)) { | ||
114 | dev_err(&pdev->dev, "unable to get clock\n"); | ||
115 | ret = PTR_ERR(priv->sclk); | ||
116 | goto err1; | ||
117 | } | ||
118 | |||
119 | memset(&up, 0, sizeof(up)); | ||
120 | up.port.mapbase = regs->start; | ||
121 | up.port.irq = irq->start; | ||
122 | up.port.type = PORT_UNKNOWN; | ||
123 | up.port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_IOREMAP; | ||
124 | up.port.dev = &pdev->dev; | ||
125 | up.port.private_data = priv; | ||
126 | |||
127 | clk_enable(priv->sclk); | ||
128 | up.port.uartclk = clk_get_rate(priv->sclk); | ||
129 | |||
130 | up.port.iotype = UPIO_MEM32; | ||
131 | up.port.serial_in = serial8250_em_serial_in; | ||
132 | up.port.serial_out = serial8250_em_serial_out; | ||
133 | up.dl_read = serial8250_em_serial_dl_read; | ||
134 | up.dl_write = serial8250_em_serial_dl_write; | ||
135 | |||
136 | ret = serial8250_register_8250_port(&up); | ||
137 | if (ret < 0) { | ||
138 | dev_err(&pdev->dev, "unable to register 8250 port\n"); | ||
139 | goto err2; | ||
140 | } | ||
141 | |||
142 | priv->line = ret; | ||
143 | platform_set_drvdata(pdev, priv); | ||
144 | return 0; | ||
145 | |||
146 | err2: | ||
147 | clk_disable(priv->sclk); | ||
148 | clk_put(priv->sclk); | ||
149 | err1: | ||
150 | kfree(priv); | ||
151 | err0: | ||
152 | return ret; | ||
153 | } | ||
154 | |||
155 | static int __devexit serial8250_em_remove(struct platform_device *pdev) | ||
156 | { | ||
157 | struct serial8250_em_priv *priv = platform_get_drvdata(pdev); | ||
158 | |||
159 | serial8250_unregister_port(priv->line); | ||
160 | clk_disable(priv->sclk); | ||
161 | clk_put(priv->sclk); | ||
162 | kfree(priv); | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static const struct of_device_id serial8250_em_dt_ids[] __devinitconst = { | ||
167 | { .compatible = "renesas,em-uart", }, | ||
168 | {}, | ||
169 | }; | ||
170 | MODULE_DEVICE_TABLE(of, serial8250_em_dt_ids); | ||
171 | |||
172 | static struct platform_driver serial8250_em_platform_driver = { | ||
173 | .driver = { | ||
174 | .name = "serial8250-em", | ||
175 | .of_match_table = serial8250_em_dt_ids, | ||
176 | .owner = THIS_MODULE, | ||
177 | }, | ||
178 | .probe = serial8250_em_probe, | ||
179 | .remove = __devexit_p(serial8250_em_remove), | ||
180 | }; | ||
181 | |||
182 | module_platform_driver(serial8250_em_platform_driver); | ||
183 | |||
184 | MODULE_AUTHOR("Magnus Damm"); | ||
185 | MODULE_DESCRIPTION("Renesas Emma Mobile 8250 Driver"); | ||
186 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c index 858dca865d6a..28e7c7cce893 100644 --- a/drivers/tty/serial/8250/8250_pci.c +++ b/drivers/tty/serial/8250/8250_pci.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/tty.h> | 19 | #include <linux/tty.h> |
20 | #include <linux/serial_reg.h> | ||
20 | #include <linux/serial_core.h> | 21 | #include <linux/serial_core.h> |
21 | #include <linux/8250_pci.h> | 22 | #include <linux/8250_pci.h> |
22 | #include <linux/bitops.h> | 23 | #include <linux/bitops.h> |
@@ -1092,11 +1093,49 @@ static int skip_tx_en_setup(struct serial_private *priv, | |||
1092 | return pci_default_setup(priv, board, port, idx); | 1093 | return pci_default_setup(priv, board, port, idx); |
1093 | } | 1094 | } |
1094 | 1095 | ||
1096 | static void kt_handle_break(struct uart_port *p) | ||
1097 | { | ||
1098 | struct uart_8250_port *up = | ||
1099 | container_of(p, struct uart_8250_port, port); | ||
1100 | /* | ||
1101 | * On receipt of a BI, serial device in Intel ME (Intel | ||
1102 | * management engine) needs to have its fifos cleared for sane | ||
1103 | * SOL (Serial Over Lan) output. | ||
1104 | */ | ||
1105 | serial8250_clear_and_reinit_fifos(up); | ||
1106 | } | ||
1107 | |||
1108 | static unsigned int kt_serial_in(struct uart_port *p, int offset) | ||
1109 | { | ||
1110 | struct uart_8250_port *up = | ||
1111 | container_of(p, struct uart_8250_port, port); | ||
1112 | unsigned int val; | ||
1113 | |||
1114 | /* | ||
1115 | * When the Intel ME (management engine) gets reset its serial | ||
1116 | * port registers could return 0 momentarily. Functions like | ||
1117 | * serial8250_console_write, read and save the IER, perform | ||
1118 | * some operation and then restore it. In order to avoid | ||
1119 | * setting IER register inadvertently to 0, if the value read | ||
1120 | * is 0, double check with ier value in uart_8250_port and use | ||
1121 | * that instead. up->ier should be the same value as what is | ||
1122 | * currently configured. | ||
1123 | */ | ||
1124 | val = inb(p->iobase + offset); | ||
1125 | if (offset == UART_IER) { | ||
1126 | if (val == 0) | ||
1127 | val = up->ier; | ||
1128 | } | ||
1129 | return val; | ||
1130 | } | ||
1131 | |||
1095 | static int kt_serial_setup(struct serial_private *priv, | 1132 | static int kt_serial_setup(struct serial_private *priv, |
1096 | const struct pciserial_board *board, | 1133 | const struct pciserial_board *board, |
1097 | struct uart_port *port, int idx) | 1134 | struct uart_port *port, int idx) |
1098 | { | 1135 | { |
1099 | port->flags |= UPF_BUG_THRE; | 1136 | port->flags |= UPF_BUG_THRE; |
1137 | port->serial_in = kt_serial_in; | ||
1138 | port->handle_break = kt_handle_break; | ||
1100 | return skip_tx_en_setup(priv, board, port, idx); | 1139 | return skip_tx_en_setup(priv, board, port, idx); |
1101 | } | 1140 | } |
1102 | 1141 | ||
@@ -1609,54 +1648,72 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = { | |||
1609 | { | 1648 | { |
1610 | .vendor = PCI_VENDOR_ID_INTEL, | 1649 | .vendor = PCI_VENDOR_ID_INTEL, |
1611 | .device = 0x8811, | 1650 | .device = 0x8811, |
1651 | .subvendor = PCI_ANY_ID, | ||
1652 | .subdevice = PCI_ANY_ID, | ||
1612 | .init = pci_eg20t_init, | 1653 | .init = pci_eg20t_init, |
1613 | .setup = pci_default_setup, | 1654 | .setup = pci_default_setup, |
1614 | }, | 1655 | }, |
1615 | { | 1656 | { |
1616 | .vendor = PCI_VENDOR_ID_INTEL, | 1657 | .vendor = PCI_VENDOR_ID_INTEL, |
1617 | .device = 0x8812, | 1658 | .device = 0x8812, |
1659 | .subvendor = PCI_ANY_ID, | ||
1660 | .subdevice = PCI_ANY_ID, | ||
1618 | .init = pci_eg20t_init, | 1661 | .init = pci_eg20t_init, |
1619 | .setup = pci_default_setup, | 1662 | .setup = pci_default_setup, |
1620 | }, | 1663 | }, |
1621 | { | 1664 | { |
1622 | .vendor = PCI_VENDOR_ID_INTEL, | 1665 | .vendor = PCI_VENDOR_ID_INTEL, |
1623 | .device = 0x8813, | 1666 | .device = 0x8813, |
1667 | .subvendor = PCI_ANY_ID, | ||
1668 | .subdevice = PCI_ANY_ID, | ||
1624 | .init = pci_eg20t_init, | 1669 | .init = pci_eg20t_init, |
1625 | .setup = pci_default_setup, | 1670 | .setup = pci_default_setup, |
1626 | }, | 1671 | }, |
1627 | { | 1672 | { |
1628 | .vendor = PCI_VENDOR_ID_INTEL, | 1673 | .vendor = PCI_VENDOR_ID_INTEL, |
1629 | .device = 0x8814, | 1674 | .device = 0x8814, |
1675 | .subvendor = PCI_ANY_ID, | ||
1676 | .subdevice = PCI_ANY_ID, | ||
1630 | .init = pci_eg20t_init, | 1677 | .init = pci_eg20t_init, |
1631 | .setup = pci_default_setup, | 1678 | .setup = pci_default_setup, |
1632 | }, | 1679 | }, |
1633 | { | 1680 | { |
1634 | .vendor = 0x10DB, | 1681 | .vendor = 0x10DB, |
1635 | .device = 0x8027, | 1682 | .device = 0x8027, |
1683 | .subvendor = PCI_ANY_ID, | ||
1684 | .subdevice = PCI_ANY_ID, | ||
1636 | .init = pci_eg20t_init, | 1685 | .init = pci_eg20t_init, |
1637 | .setup = pci_default_setup, | 1686 | .setup = pci_default_setup, |
1638 | }, | 1687 | }, |
1639 | { | 1688 | { |
1640 | .vendor = 0x10DB, | 1689 | .vendor = 0x10DB, |
1641 | .device = 0x8028, | 1690 | .device = 0x8028, |
1691 | .subvendor = PCI_ANY_ID, | ||
1692 | .subdevice = PCI_ANY_ID, | ||
1642 | .init = pci_eg20t_init, | 1693 | .init = pci_eg20t_init, |
1643 | .setup = pci_default_setup, | 1694 | .setup = pci_default_setup, |
1644 | }, | 1695 | }, |
1645 | { | 1696 | { |
1646 | .vendor = 0x10DB, | 1697 | .vendor = 0x10DB, |
1647 | .device = 0x8029, | 1698 | .device = 0x8029, |
1699 | .subvendor = PCI_ANY_ID, | ||
1700 | .subdevice = PCI_ANY_ID, | ||
1648 | .init = pci_eg20t_init, | 1701 | .init = pci_eg20t_init, |
1649 | .setup = pci_default_setup, | 1702 | .setup = pci_default_setup, |
1650 | }, | 1703 | }, |
1651 | { | 1704 | { |
1652 | .vendor = 0x10DB, | 1705 | .vendor = 0x10DB, |
1653 | .device = 0x800C, | 1706 | .device = 0x800C, |
1707 | .subvendor = PCI_ANY_ID, | ||
1708 | .subdevice = PCI_ANY_ID, | ||
1654 | .init = pci_eg20t_init, | 1709 | .init = pci_eg20t_init, |
1655 | .setup = pci_default_setup, | 1710 | .setup = pci_default_setup, |
1656 | }, | 1711 | }, |
1657 | { | 1712 | { |
1658 | .vendor = 0x10DB, | 1713 | .vendor = 0x10DB, |
1659 | .device = 0x800D, | 1714 | .device = 0x800D, |
1715 | .subvendor = PCI_ANY_ID, | ||
1716 | .subdevice = PCI_ANY_ID, | ||
1660 | .init = pci_eg20t_init, | 1717 | .init = pci_eg20t_init, |
1661 | .setup = pci_default_setup, | 1718 | .setup = pci_default_setup, |
1662 | }, | 1719 | }, |
@@ -2775,6 +2832,12 @@ void pciserial_suspend_ports(struct serial_private *priv) | |||
2775 | for (i = 0; i < priv->nr; i++) | 2832 | for (i = 0; i < priv->nr; i++) |
2776 | if (priv->line[i] >= 0) | 2833 | if (priv->line[i] >= 0) |
2777 | serial8250_suspend_port(priv->line[i]); | 2834 | serial8250_suspend_port(priv->line[i]); |
2835 | |||
2836 | /* | ||
2837 | * Ensure that every init quirk is properly torn down | ||
2838 | */ | ||
2839 | if (priv->quirk->exit) | ||
2840 | priv->quirk->exit(priv->dev); | ||
2778 | } | 2841 | } |
2779 | EXPORT_SYMBOL_GPL(pciserial_suspend_ports); | 2842 | EXPORT_SYMBOL_GPL(pciserial_suspend_ports); |
2780 | 2843 | ||
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig index 591f8018e7dd..8bc7ecbf6bea 100644 --- a/drivers/tty/serial/8250/Kconfig +++ b/drivers/tty/serial/8250/Kconfig | |||
@@ -278,3 +278,11 @@ config SERIAL_8250_DW | |||
278 | help | 278 | help |
279 | Selecting this option will enable handling of the extra features | 279 | Selecting this option will enable handling of the extra features |
280 | present in the Synopsys DesignWare APB UART. | 280 | present in the Synopsys DesignWare APB UART. |
281 | |||
282 | config SERIAL_8250_EM | ||
283 | tristate "Support for Emma Mobile intergrated serial port" | ||
284 | depends on SERIAL_8250 && ARM && HAVE_CLK | ||
285 | help | ||
286 | Selecting this option will add support for the integrated serial | ||
287 | port hardware found on the Emma Mobile line of processors. | ||
288 | If unsure, say N. | ||
diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile index 867bba738908..3f35eacdf673 100644 --- a/drivers/tty/serial/8250/Makefile +++ b/drivers/tty/serial/8250/Makefile | |||
@@ -18,3 +18,4 @@ obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o | |||
18 | obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o | 18 | obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o |
19 | obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o | 19 | obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o |
20 | obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o | 20 | obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o |
21 | obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o | ||
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 062ef8c2b3cb..4ad721fb8405 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c | |||
@@ -68,30 +68,6 @@ | |||
68 | #define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) | 68 | #define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) |
69 | #define UART_DUMMY_DR_RX (1 << 16) | 69 | #define UART_DUMMY_DR_RX (1 << 16) |
70 | 70 | ||
71 | |||
72 | #define UART_WA_SAVE_NR 14 | ||
73 | |||
74 | static void pl011_lockup_wa(unsigned long data); | ||
75 | static const u32 uart_wa_reg[UART_WA_SAVE_NR] = { | ||
76 | ST_UART011_DMAWM, | ||
77 | ST_UART011_TIMEOUT, | ||
78 | ST_UART011_LCRH_RX, | ||
79 | UART011_IBRD, | ||
80 | UART011_FBRD, | ||
81 | ST_UART011_LCRH_TX, | ||
82 | UART011_IFLS, | ||
83 | ST_UART011_XFCR, | ||
84 | ST_UART011_XON1, | ||
85 | ST_UART011_XON2, | ||
86 | ST_UART011_XOFF1, | ||
87 | ST_UART011_XOFF2, | ||
88 | UART011_CR, | ||
89 | UART011_IMSC | ||
90 | }; | ||
91 | |||
92 | static u32 uart_wa_regdata[UART_WA_SAVE_NR]; | ||
93 | static DECLARE_TASKLET(pl011_lockup_tlet, pl011_lockup_wa, 0); | ||
94 | |||
95 | /* There is by now at least one vendor with differing details, so handle it */ | 71 | /* There is by now at least one vendor with differing details, so handle it */ |
96 | struct vendor_data { | 72 | struct vendor_data { |
97 | unsigned int ifls; | 73 | unsigned int ifls; |
@@ -101,6 +77,7 @@ struct vendor_data { | |||
101 | bool oversampling; | 77 | bool oversampling; |
102 | bool interrupt_may_hang; /* vendor-specific */ | 78 | bool interrupt_may_hang; /* vendor-specific */ |
103 | bool dma_threshold; | 79 | bool dma_threshold; |
80 | bool cts_event_workaround; | ||
104 | }; | 81 | }; |
105 | 82 | ||
106 | static struct vendor_data vendor_arm = { | 83 | static struct vendor_data vendor_arm = { |
@@ -110,6 +87,7 @@ static struct vendor_data vendor_arm = { | |||
110 | .lcrh_rx = UART011_LCRH, | 87 | .lcrh_rx = UART011_LCRH, |
111 | .oversampling = false, | 88 | .oversampling = false, |
112 | .dma_threshold = false, | 89 | .dma_threshold = false, |
90 | .cts_event_workaround = false, | ||
113 | }; | 91 | }; |
114 | 92 | ||
115 | static struct vendor_data vendor_st = { | 93 | static struct vendor_data vendor_st = { |
@@ -120,6 +98,7 @@ static struct vendor_data vendor_st = { | |||
120 | .oversampling = true, | 98 | .oversampling = true, |
121 | .interrupt_may_hang = true, | 99 | .interrupt_may_hang = true, |
122 | .dma_threshold = true, | 100 | .dma_threshold = true, |
101 | .cts_event_workaround = true, | ||
123 | }; | 102 | }; |
124 | 103 | ||
125 | static struct uart_amba_port *amba_ports[UART_NR]; | 104 | static struct uart_amba_port *amba_ports[UART_NR]; |
@@ -1055,69 +1034,6 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap) | |||
1055 | #define pl011_dma_flush_buffer NULL | 1034 | #define pl011_dma_flush_buffer NULL |
1056 | #endif | 1035 | #endif |
1057 | 1036 | ||
1058 | |||
1059 | /* | ||
1060 | * pl011_lockup_wa | ||
1061 | * This workaround aims to break the deadlock situation | ||
1062 | * when after long transfer over uart in hardware flow | ||
1063 | * control, uart interrupt registers cannot be cleared. | ||
1064 | * Hence uart transfer gets blocked. | ||
1065 | * | ||
1066 | * It is seen that during such deadlock condition ICR | ||
1067 | * don't get cleared even on multiple write. This leads | ||
1068 | * pass_counter to decrease and finally reach zero. This | ||
1069 | * can be taken as trigger point to run this UART_BT_WA. | ||
1070 | * | ||
1071 | */ | ||
1072 | static void pl011_lockup_wa(unsigned long data) | ||
1073 | { | ||
1074 | struct uart_amba_port *uap = amba_ports[0]; | ||
1075 | void __iomem *base = uap->port.membase; | ||
1076 | struct circ_buf *xmit = &uap->port.state->xmit; | ||
1077 | struct tty_struct *tty = uap->port.state->port.tty; | ||
1078 | int buf_empty_retries = 200; | ||
1079 | int loop; | ||
1080 | |||
1081 | /* Stop HCI layer from submitting data for tx */ | ||
1082 | tty->hw_stopped = 1; | ||
1083 | while (!uart_circ_empty(xmit)) { | ||
1084 | if (buf_empty_retries-- == 0) | ||
1085 | break; | ||
1086 | udelay(100); | ||
1087 | } | ||
1088 | |||
1089 | /* Backup registers */ | ||
1090 | for (loop = 0; loop < UART_WA_SAVE_NR; loop++) | ||
1091 | uart_wa_regdata[loop] = readl(base + uart_wa_reg[loop]); | ||
1092 | |||
1093 | /* Disable UART so that FIFO data is flushed out */ | ||
1094 | writew(0x00, uap->port.membase + UART011_CR); | ||
1095 | |||
1096 | /* Soft reset UART module */ | ||
1097 | if (uap->port.dev->platform_data) { | ||
1098 | struct amba_pl011_data *plat; | ||
1099 | |||
1100 | plat = uap->port.dev->platform_data; | ||
1101 | if (plat->reset) | ||
1102 | plat->reset(); | ||
1103 | } | ||
1104 | |||
1105 | /* Restore registers */ | ||
1106 | for (loop = 0; loop < UART_WA_SAVE_NR; loop++) | ||
1107 | writew(uart_wa_regdata[loop] , | ||
1108 | uap->port.membase + uart_wa_reg[loop]); | ||
1109 | |||
1110 | /* Initialise the old status of the modem signals */ | ||
1111 | uap->old_status = readw(uap->port.membase + UART01x_FR) & | ||
1112 | UART01x_FR_MODEM_ANY; | ||
1113 | |||
1114 | if (readl(base + UART011_MIS) & 0x2) | ||
1115 | printk(KERN_EMERG "UART_BT_WA: ***FAILED***\n"); | ||
1116 | |||
1117 | /* Start Tx/Rx */ | ||
1118 | tty->hw_stopped = 0; | ||
1119 | } | ||
1120 | |||
1121 | static void pl011_stop_tx(struct uart_port *port) | 1037 | static void pl011_stop_tx(struct uart_port *port) |
1122 | { | 1038 | { |
1123 | struct uart_amba_port *uap = (struct uart_amba_port *)port; | 1039 | struct uart_amba_port *uap = (struct uart_amba_port *)port; |
@@ -1246,12 +1162,26 @@ static irqreturn_t pl011_int(int irq, void *dev_id) | |||
1246 | unsigned long flags; | 1162 | unsigned long flags; |
1247 | unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; | 1163 | unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; |
1248 | int handled = 0; | 1164 | int handled = 0; |
1165 | unsigned int dummy_read; | ||
1249 | 1166 | ||
1250 | spin_lock_irqsave(&uap->port.lock, flags); | 1167 | spin_lock_irqsave(&uap->port.lock, flags); |
1251 | 1168 | ||
1252 | status = readw(uap->port.membase + UART011_MIS); | 1169 | status = readw(uap->port.membase + UART011_MIS); |
1253 | if (status) { | 1170 | if (status) { |
1254 | do { | 1171 | do { |
1172 | if (uap->vendor->cts_event_workaround) { | ||
1173 | /* workaround to make sure that all bits are unlocked.. */ | ||
1174 | writew(0x00, uap->port.membase + UART011_ICR); | ||
1175 | |||
1176 | /* | ||
1177 | * WA: introduce 26ns(1 uart clk) delay before W1C; | ||
1178 | * single apb access will incur 2 pclk(133.12Mhz) delay, | ||
1179 | * so add 2 dummy reads | ||
1180 | */ | ||
1181 | dummy_read = readw(uap->port.membase + UART011_ICR); | ||
1182 | dummy_read = readw(uap->port.membase + UART011_ICR); | ||
1183 | } | ||
1184 | |||
1255 | writew(status & ~(UART011_TXIS|UART011_RTIS| | 1185 | writew(status & ~(UART011_TXIS|UART011_RTIS| |
1256 | UART011_RXIS), | 1186 | UART011_RXIS), |
1257 | uap->port.membase + UART011_ICR); | 1187 | uap->port.membase + UART011_ICR); |
@@ -1268,11 +1198,8 @@ static irqreturn_t pl011_int(int irq, void *dev_id) | |||
1268 | if (status & UART011_TXIS) | 1198 | if (status & UART011_TXIS) |
1269 | pl011_tx_chars(uap); | 1199 | pl011_tx_chars(uap); |
1270 | 1200 | ||
1271 | if (pass_counter-- == 0) { | 1201 | if (pass_counter-- == 0) |
1272 | if (uap->interrupt_may_hang) | ||
1273 | tasklet_schedule(&pl011_lockup_tlet); | ||
1274 | break; | 1202 | break; |
1275 | } | ||
1276 | 1203 | ||
1277 | status = readw(uap->port.membase + UART011_MIS); | 1204 | status = readw(uap->port.membase + UART011_MIS); |
1278 | } while (status != 0); | 1205 | } while (status != 0); |
diff --git a/drivers/tty/serial/bfin_uart.c b/drivers/tty/serial/bfin_uart.c index 5832fdef11e9..bd97db23985b 100644 --- a/drivers/tty/serial/bfin_uart.c +++ b/drivers/tty/serial/bfin_uart.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Blackfin On-Chip Serial Driver | 2 | * Blackfin On-Chip Serial Driver |
3 | * | 3 | * |
4 | * Copyright 2006-2010 Analog Devices Inc. | 4 | * Copyright 2006-2011 Analog Devices Inc. |
5 | * | 5 | * |
6 | * Enter bugs at http://blackfin.uclinux.org/ | 6 | * Enter bugs at http://blackfin.uclinux.org/ |
7 | * | 7 | * |
@@ -35,10 +35,6 @@ | |||
35 | #include <asm/portmux.h> | 35 | #include <asm/portmux.h> |
36 | #include <asm/cacheflush.h> | 36 | #include <asm/cacheflush.h> |
37 | #include <asm/dma.h> | 37 | #include <asm/dma.h> |
38 | |||
39 | #define port_membase(uart) (((struct bfin_serial_port *)(uart))->port.membase) | ||
40 | #define get_lsr_cache(uart) (((struct bfin_serial_port *)(uart))->lsr) | ||
41 | #define put_lsr_cache(uart, v) (((struct bfin_serial_port *)(uart))->lsr = (v)) | ||
42 | #include <asm/bfin_serial.h> | 38 | #include <asm/bfin_serial.h> |
43 | 39 | ||
44 | #ifdef CONFIG_SERIAL_BFIN_MODULE | 40 | #ifdef CONFIG_SERIAL_BFIN_MODULE |
@@ -166,7 +162,7 @@ static void bfin_serial_stop_tx(struct uart_port *port) | |||
166 | uart->tx_count = 0; | 162 | uart->tx_count = 0; |
167 | uart->tx_done = 1; | 163 | uart->tx_done = 1; |
168 | #else | 164 | #else |
169 | #ifdef CONFIG_BF54x | 165 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x) |
170 | /* Clear TFI bit */ | 166 | /* Clear TFI bit */ |
171 | UART_PUT_LSR(uart, TFI); | 167 | UART_PUT_LSR(uart, TFI); |
172 | #endif | 168 | #endif |
@@ -337,7 +333,7 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart) | |||
337 | struct circ_buf *xmit = &uart->port.state->xmit; | 333 | struct circ_buf *xmit = &uart->port.state->xmit; |
338 | 334 | ||
339 | if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) { | 335 | if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) { |
340 | #ifdef CONFIG_BF54x | 336 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x) |
341 | /* Clear TFI bit */ | 337 | /* Clear TFI bit */ |
342 | UART_PUT_LSR(uart, TFI); | 338 | UART_PUT_LSR(uart, TFI); |
343 | #endif | 339 | #endif |
@@ -536,7 +532,7 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id) | |||
536 | */ | 532 | */ |
537 | UART_CLEAR_IER(uart, ETBEI); | 533 | UART_CLEAR_IER(uart, ETBEI); |
538 | uart->port.icount.tx += uart->tx_count; | 534 | uart->port.icount.tx += uart->tx_count; |
539 | if (!uart_circ_empty(xmit)) { | 535 | if (!(xmit->tail == 0 && xmit->head == 0)) { |
540 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); | 536 | xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); |
541 | 537 | ||
542 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | 538 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
@@ -553,7 +549,7 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id) | |||
553 | static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id) | 549 | static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id) |
554 | { | 550 | { |
555 | struct bfin_serial_port *uart = dev_id; | 551 | struct bfin_serial_port *uart = dev_id; |
556 | unsigned short irqstat; | 552 | unsigned int irqstat; |
557 | int x_pos, pos; | 553 | int x_pos, pos; |
558 | 554 | ||
559 | spin_lock(&uart->rx_lock); | 555 | spin_lock(&uart->rx_lock); |
@@ -586,7 +582,7 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id) | |||
586 | static unsigned int bfin_serial_tx_empty(struct uart_port *port) | 582 | static unsigned int bfin_serial_tx_empty(struct uart_port *port) |
587 | { | 583 | { |
588 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 584 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
589 | unsigned short lsr; | 585 | unsigned int lsr; |
590 | 586 | ||
591 | lsr = UART_GET_LSR(uart); | 587 | lsr = UART_GET_LSR(uart); |
592 | if (lsr & TEMT) | 588 | if (lsr & TEMT) |
@@ -598,7 +594,7 @@ static unsigned int bfin_serial_tx_empty(struct uart_port *port) | |||
598 | static void bfin_serial_break_ctl(struct uart_port *port, int break_state) | 594 | static void bfin_serial_break_ctl(struct uart_port *port, int break_state) |
599 | { | 595 | { |
600 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 596 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
601 | u16 lcr = UART_GET_LCR(uart); | 597 | u32 lcr = UART_GET_LCR(uart); |
602 | if (break_state) | 598 | if (break_state) |
603 | lcr |= SB; | 599 | lcr |= SB; |
604 | else | 600 | else |
@@ -745,7 +741,7 @@ static int bfin_serial_startup(struct uart_port *port) | |||
745 | } | 741 | } |
746 | 742 | ||
747 | /* CTS RTS PINs are negative assertive. */ | 743 | /* CTS RTS PINs are negative assertive. */ |
748 | UART_PUT_MCR(uart, ACTS); | 744 | UART_PUT_MCR(uart, UART_GET_MCR(uart) | ACTS); |
749 | UART_SET_IER(uart, EDSSI); | 745 | UART_SET_IER(uart, EDSSI); |
750 | } | 746 | } |
751 | #endif | 747 | #endif |
@@ -803,7 +799,7 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios, | |||
803 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 799 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
804 | unsigned long flags; | 800 | unsigned long flags; |
805 | unsigned int baud, quot; | 801 | unsigned int baud, quot; |
806 | unsigned short val, ier, lcr = 0; | 802 | unsigned int ier, lcr = 0; |
807 | 803 | ||
808 | switch (termios->c_cflag & CSIZE) { | 804 | switch (termios->c_cflag & CSIZE) { |
809 | case CS8: | 805 | case CS8: |
@@ -875,26 +871,23 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios, | |||
875 | 871 | ||
876 | /* Disable UART */ | 872 | /* Disable UART */ |
877 | ier = UART_GET_IER(uart); | 873 | ier = UART_GET_IER(uart); |
874 | UART_PUT_GCTL(uart, UART_GET_GCTL(uart) & ~UCEN); | ||
878 | UART_DISABLE_INTS(uart); | 875 | UART_DISABLE_INTS(uart); |
879 | 876 | ||
880 | /* Set DLAB in LCR to Access DLL and DLH */ | 877 | /* Set DLAB in LCR to Access CLK */ |
881 | UART_SET_DLAB(uart); | 878 | UART_SET_DLAB(uart); |
882 | 879 | ||
883 | UART_PUT_DLL(uart, quot & 0xFF); | 880 | UART_PUT_CLK(uart, quot); |
884 | UART_PUT_DLH(uart, (quot >> 8) & 0xFF); | ||
885 | SSYNC(); | 881 | SSYNC(); |
886 | 882 | ||
887 | /* Clear DLAB in LCR to Access THR RBR IER */ | 883 | /* Clear DLAB in LCR to Access THR RBR IER */ |
888 | UART_CLEAR_DLAB(uart); | 884 | UART_CLEAR_DLAB(uart); |
889 | 885 | ||
890 | UART_PUT_LCR(uart, lcr); | 886 | UART_PUT_LCR(uart, (UART_GET_LCR(uart) & ~LCR_MASK) | lcr); |
891 | 887 | ||
892 | /* Enable UART */ | 888 | /* Enable UART */ |
893 | UART_ENABLE_INTS(uart, ier); | 889 | UART_ENABLE_INTS(uart, ier); |
894 | 890 | UART_PUT_GCTL(uart, UART_GET_GCTL(uart) | UCEN); | |
895 | val = UART_GET_GCTL(uart); | ||
896 | val |= UCEN; | ||
897 | UART_PUT_GCTL(uart, val); | ||
898 | 891 | ||
899 | /* Port speed changed, update the per-port timeout. */ | 892 | /* Port speed changed, update the per-port timeout. */ |
900 | uart_update_timeout(port, termios->c_cflag, baud); | 893 | uart_update_timeout(port, termios->c_cflag, baud); |
@@ -954,17 +947,17 @@ bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser) | |||
954 | static void bfin_serial_set_ldisc(struct uart_port *port, int ld) | 947 | static void bfin_serial_set_ldisc(struct uart_port *port, int ld) |
955 | { | 948 | { |
956 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 949 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
957 | unsigned short val; | 950 | unsigned int val; |
958 | 951 | ||
959 | switch (ld) { | 952 | switch (ld) { |
960 | case N_IRDA: | 953 | case N_IRDA: |
961 | val = UART_GET_GCTL(uart); | 954 | val = UART_GET_GCTL(uart); |
962 | val |= (IREN | RPOLC); | 955 | val |= (UMOD_IRDA | RPOLC); |
963 | UART_PUT_GCTL(uart, val); | 956 | UART_PUT_GCTL(uart, val); |
964 | break; | 957 | break; |
965 | default: | 958 | default: |
966 | val = UART_GET_GCTL(uart); | 959 | val = UART_GET_GCTL(uart); |
967 | val &= ~(IREN | RPOLC); | 960 | val &= ~(UMOD_MASK | RPOLC); |
968 | UART_PUT_GCTL(uart, val); | 961 | UART_PUT_GCTL(uart, val); |
969 | } | 962 | } |
970 | } | 963 | } |
@@ -972,13 +965,13 @@ static void bfin_serial_set_ldisc(struct uart_port *port, int ld) | |||
972 | static void bfin_serial_reset_irda(struct uart_port *port) | 965 | static void bfin_serial_reset_irda(struct uart_port *port) |
973 | { | 966 | { |
974 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; | 967 | struct bfin_serial_port *uart = (struct bfin_serial_port *)port; |
975 | unsigned short val; | 968 | unsigned int val; |
976 | 969 | ||
977 | val = UART_GET_GCTL(uart); | 970 | val = UART_GET_GCTL(uart); |
978 | val &= ~(IREN | RPOLC); | 971 | val &= ~(UMOD_MASK | RPOLC); |
979 | UART_PUT_GCTL(uart, val); | 972 | UART_PUT_GCTL(uart, val); |
980 | SSYNC(); | 973 | SSYNC(); |
981 | val |= (IREN | RPOLC); | 974 | val |= (UMOD_IRDA | RPOLC); |
982 | UART_PUT_GCTL(uart, val); | 975 | UART_PUT_GCTL(uart, val); |
983 | SSYNC(); | 976 | SSYNC(); |
984 | } | 977 | } |
@@ -1070,12 +1063,12 @@ static void __init | |||
1070 | bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud, | 1063 | bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud, |
1071 | int *parity, int *bits) | 1064 | int *parity, int *bits) |
1072 | { | 1065 | { |
1073 | unsigned short status; | 1066 | unsigned int status; |
1074 | 1067 | ||
1075 | status = UART_GET_IER(uart) & (ERBFI | ETBEI); | 1068 | status = UART_GET_IER(uart) & (ERBFI | ETBEI); |
1076 | if (status == (ERBFI | ETBEI)) { | 1069 | if (status == (ERBFI | ETBEI)) { |
1077 | /* ok, the port was enabled */ | 1070 | /* ok, the port was enabled */ |
1078 | u16 lcr, dlh, dll; | 1071 | u32 lcr, clk; |
1079 | 1072 | ||
1080 | lcr = UART_GET_LCR(uart); | 1073 | lcr = UART_GET_LCR(uart); |
1081 | 1074 | ||
@@ -1086,30 +1079,17 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud, | |||
1086 | else | 1079 | else |
1087 | *parity = 'o'; | 1080 | *parity = 'o'; |
1088 | } | 1081 | } |
1089 | switch (lcr & 0x03) { | 1082 | *bits = ((lcr & WLS_MASK) >> WLS_OFFSET) + 5; |
1090 | case 0: | 1083 | |
1091 | *bits = 5; | 1084 | /* Set DLAB in LCR to Access CLK */ |
1092 | break; | ||
1093 | case 1: | ||
1094 | *bits = 6; | ||
1095 | break; | ||
1096 | case 2: | ||
1097 | *bits = 7; | ||
1098 | break; | ||
1099 | case 3: | ||
1100 | *bits = 8; | ||
1101 | break; | ||
1102 | } | ||
1103 | /* Set DLAB in LCR to Access DLL and DLH */ | ||
1104 | UART_SET_DLAB(uart); | 1085 | UART_SET_DLAB(uart); |
1105 | 1086 | ||
1106 | dll = UART_GET_DLL(uart); | 1087 | clk = UART_GET_CLK(uart); |
1107 | dlh = UART_GET_DLH(uart); | ||
1108 | 1088 | ||
1109 | /* Clear DLAB in LCR to Access THR RBR IER */ | 1089 | /* Clear DLAB in LCR to Access THR RBR IER */ |
1110 | UART_CLEAR_DLAB(uart); | 1090 | UART_CLEAR_DLAB(uart); |
1111 | 1091 | ||
1112 | *baud = get_sclk() / (16*(dll | dlh << 8)); | 1092 | *baud = get_sclk() / (16*clk); |
1113 | } | 1093 | } |
1114 | pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits); | 1094 | pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits); |
1115 | } | 1095 | } |
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c index 5b07c0c3a10c..7264d4d26717 100644 --- a/drivers/tty/serial/crisv10.c +++ b/drivers/tty/serial/crisv10.c | |||
@@ -952,19 +952,6 @@ static const struct control_pins e100_modem_pins[NR_PORTS] = | |||
952 | /* Input */ | 952 | /* Input */ |
953 | #define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask) | 953 | #define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask) |
954 | 954 | ||
955 | |||
956 | /* | ||
957 | * tmp_buf is used as a temporary buffer by serial_write. We need to | ||
958 | * lock it in case the memcpy_fromfs blocks while swapping in a page, | ||
959 | * and some other program tries to do a serial write at the same time. | ||
960 | * Since the lock will only come under contention when the system is | ||
961 | * swapping and available memory is low, it makes sense to share one | ||
962 | * buffer across all the serial ports, since it significantly saves | ||
963 | * memory if large numbers of serial ports are open. | ||
964 | */ | ||
965 | static unsigned char *tmp_buf; | ||
966 | static DEFINE_MUTEX(tmp_buf_mutex); | ||
967 | |||
968 | /* Calculate the chartime depending on baudrate, numbor of bits etc. */ | 955 | /* Calculate the chartime depending on baudrate, numbor of bits etc. */ |
969 | static void update_char_time(struct e100_serial * info) | 956 | static void update_char_time(struct e100_serial * info) |
970 | { | 957 | { |
@@ -3150,7 +3137,7 @@ static int rs_raw_write(struct tty_struct *tty, | |||
3150 | 3137 | ||
3151 | /* first some sanity checks */ | 3138 | /* first some sanity checks */ |
3152 | 3139 | ||
3153 | if (!tty || !info->xmit.buf || !tmp_buf) | 3140 | if (!tty || !info->xmit.buf) |
3154 | return 0; | 3141 | return 0; |
3155 | 3142 | ||
3156 | #ifdef SERIAL_DEBUG_DATA | 3143 | #ifdef SERIAL_DEBUG_DATA |
@@ -3989,7 +3976,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp, | |||
3989 | */ | 3976 | */ |
3990 | if (tty_hung_up_p(filp) || | 3977 | if (tty_hung_up_p(filp) || |
3991 | (info->flags & ASYNC_CLOSING)) { | 3978 | (info->flags & ASYNC_CLOSING)) { |
3992 | wait_event_interruptible_tty(info->close_wait, | 3979 | wait_event_interruptible_tty(tty, info->close_wait, |
3993 | !(info->flags & ASYNC_CLOSING)); | 3980 | !(info->flags & ASYNC_CLOSING)); |
3994 | #ifdef SERIAL_DO_RESTART | 3981 | #ifdef SERIAL_DO_RESTART |
3995 | if (info->flags & ASYNC_HUP_NOTIFY) | 3982 | if (info->flags & ASYNC_HUP_NOTIFY) |
@@ -4065,9 +4052,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp, | |||
4065 | printk("block_til_ready blocking: ttyS%d, count = %d\n", | 4052 | printk("block_til_ready blocking: ttyS%d, count = %d\n", |
4066 | info->line, info->count); | 4053 | info->line, info->count); |
4067 | #endif | 4054 | #endif |
4068 | tty_unlock(); | 4055 | tty_unlock(tty); |
4069 | schedule(); | 4056 | schedule(); |
4070 | tty_lock(); | 4057 | tty_lock(tty); |
4071 | } | 4058 | } |
4072 | set_current_state(TASK_RUNNING); | 4059 | set_current_state(TASK_RUNNING); |
4073 | remove_wait_queue(&info->open_wait, &wait); | 4060 | remove_wait_queue(&info->open_wait, &wait); |
@@ -4106,7 +4093,6 @@ rs_open(struct tty_struct *tty, struct file * filp) | |||
4106 | { | 4093 | { |
4107 | struct e100_serial *info; | 4094 | struct e100_serial *info; |
4108 | int retval; | 4095 | int retval; |
4109 | unsigned long page; | ||
4110 | int allocated_resources = 0; | 4096 | int allocated_resources = 0; |
4111 | 4097 | ||
4112 | info = rs_table + tty->index; | 4098 | info = rs_table + tty->index; |
@@ -4124,23 +4110,12 @@ rs_open(struct tty_struct *tty, struct file * filp) | |||
4124 | 4110 | ||
4125 | tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY); | 4111 | tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY); |
4126 | 4112 | ||
4127 | if (!tmp_buf) { | ||
4128 | page = get_zeroed_page(GFP_KERNEL); | ||
4129 | if (!page) { | ||
4130 | return -ENOMEM; | ||
4131 | } | ||
4132 | if (tmp_buf) | ||
4133 | free_page(page); | ||
4134 | else | ||
4135 | tmp_buf = (unsigned char *) page; | ||
4136 | } | ||
4137 | |||
4138 | /* | 4113 | /* |
4139 | * If the port is in the middle of closing, bail out now | 4114 | * If the port is in the middle of closing, bail out now |
4140 | */ | 4115 | */ |
4141 | if (tty_hung_up_p(filp) || | 4116 | if (tty_hung_up_p(filp) || |
4142 | (info->flags & ASYNC_CLOSING)) { | 4117 | (info->flags & ASYNC_CLOSING)) { |
4143 | wait_event_interruptible_tty(info->close_wait, | 4118 | wait_event_interruptible_tty(tty, info->close_wait, |
4144 | !(info->flags & ASYNC_CLOSING)); | 4119 | !(info->flags & ASYNC_CLOSING)); |
4145 | #ifdef SERIAL_DO_RESTART | 4120 | #ifdef SERIAL_DO_RESTART |
4146 | return ((info->flags & ASYNC_HUP_NOTIFY) ? | 4121 | return ((info->flags & ASYNC_HUP_NOTIFY) ? |
@@ -4487,6 +4462,7 @@ static int __init rs_init(void) | |||
4487 | info->enabled = 0; | 4462 | info->enabled = 0; |
4488 | } | 4463 | } |
4489 | } | 4464 | } |
4465 | tty_port_init(&info->port); | ||
4490 | info->uses_dma_in = 0; | 4466 | info->uses_dma_in = 0; |
4491 | info->uses_dma_out = 0; | 4467 | info->uses_dma_out = 0; |
4492 | info->line = i; | 4468 | info->line = i; |
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 7081600bede4..ec56d8397aae 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c | |||
@@ -370,6 +370,8 @@ static void mxs_auart_settermios(struct uart_port *u, | |||
370 | 370 | ||
371 | writel(ctrl, u->membase + AUART_LINECTRL); | 371 | writel(ctrl, u->membase + AUART_LINECTRL); |
372 | writel(ctrl2, u->membase + AUART_CTRL2); | 372 | writel(ctrl2, u->membase + AUART_CTRL2); |
373 | |||
374 | uart_update_timeout(u, termios->c_cflag, baud); | ||
373 | } | 375 | } |
374 | 376 | ||
375 | static irqreturn_t mxs_auart_irq_handle(int irq, void *context) | 377 | static irqreturn_t mxs_auart_irq_handle(int irq, void *context) |
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c index e8c9cee07d00..5410c0637266 100644 --- a/drivers/tty/serial/of_serial.c +++ b/drivers/tty/serial/of_serial.c | |||
@@ -12,10 +12,13 @@ | |||
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/delay.h> | ||
15 | #include <linux/serial_core.h> | 16 | #include <linux/serial_core.h> |
16 | #include <linux/serial_8250.h> | 17 | #include <linux/serial_8250.h> |
18 | #include <linux/serial_reg.h> | ||
17 | #include <linux/of_address.h> | 19 | #include <linux/of_address.h> |
18 | #include <linux/of_irq.h> | 20 | #include <linux/of_irq.h> |
21 | #include <linux/of_serial.h> | ||
19 | #include <linux/of_platform.h> | 22 | #include <linux/of_platform.h> |
20 | #include <linux/nwpserial.h> | 23 | #include <linux/nwpserial.h> |
21 | 24 | ||
@@ -24,6 +27,26 @@ struct of_serial_info { | |||
24 | int line; | 27 | int line; |
25 | }; | 28 | }; |
26 | 29 | ||
30 | #ifdef CONFIG_ARCH_TEGRA | ||
31 | void tegra_serial_handle_break(struct uart_port *p) | ||
32 | { | ||
33 | unsigned int status, tmout = 10000; | ||
34 | |||
35 | do { | ||
36 | status = p->serial_in(p, UART_LSR); | ||
37 | if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) | ||
38 | status = p->serial_in(p, UART_RX); | ||
39 | else | ||
40 | break; | ||
41 | if (--tmout == 0) | ||
42 | break; | ||
43 | udelay(1); | ||
44 | } while (1); | ||
45 | } | ||
46 | /* FIXME remove this export when tegra finishes conversion to open firmware */ | ||
47 | EXPORT_SYMBOL_GPL(tegra_serial_handle_break); | ||
48 | #endif | ||
49 | |||
27 | /* | 50 | /* |
28 | * Fill a struct uart_port for a given device node | 51 | * Fill a struct uart_port for a given device node |
29 | */ | 52 | */ |
@@ -84,6 +107,9 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev, | |||
84 | | UPF_FIXED_PORT | UPF_FIXED_TYPE; | 107 | | UPF_FIXED_PORT | UPF_FIXED_TYPE; |
85 | port->dev = &ofdev->dev; | 108 | port->dev = &ofdev->dev; |
86 | 109 | ||
110 | if (type == PORT_TEGRA) | ||
111 | port->handle_break = tegra_serial_handle_break; | ||
112 | |||
87 | return 0; | 113 | return 0; |
88 | } | 114 | } |
89 | 115 | ||
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index d00b38eb268e..d3cda0cb2df0 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c | |||
@@ -44,6 +44,13 @@ | |||
44 | #include <plat/dmtimer.h> | 44 | #include <plat/dmtimer.h> |
45 | #include <plat/omap-serial.h> | 45 | #include <plat/omap-serial.h> |
46 | 46 | ||
47 | #define UART_BUILD_REVISION(x, y) (((x) << 8) | (y)) | ||
48 | |||
49 | #define OMAP_UART_REV_42 0x0402 | ||
50 | #define OMAP_UART_REV_46 0x0406 | ||
51 | #define OMAP_UART_REV_52 0x0502 | ||
52 | #define OMAP_UART_REV_63 0x0603 | ||
53 | |||
47 | #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/ | 54 | #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/ |
48 | 55 | ||
49 | /* SCR register bitmasks */ | 56 | /* SCR register bitmasks */ |
@@ -53,6 +60,17 @@ | |||
53 | #define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6 | 60 | #define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6 |
54 | #define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6) | 61 | #define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6) |
55 | 62 | ||
63 | /* MVR register bitmasks */ | ||
64 | #define OMAP_UART_MVR_SCHEME_SHIFT 30 | ||
65 | |||
66 | #define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0 | ||
67 | #define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4 | ||
68 | #define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f | ||
69 | |||
70 | #define OMAP_UART_MVR_MAJ_MASK 0x700 | ||
71 | #define OMAP_UART_MVR_MAJ_SHIFT 8 | ||
72 | #define OMAP_UART_MVR_MIN_MASK 0x3f | ||
73 | |||
56 | static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS]; | 74 | static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS]; |
57 | 75 | ||
58 | /* Forward declaration of functions */ | 76 | /* Forward declaration of functions */ |
@@ -1346,6 +1364,59 @@ static void uart_tx_dma_callback(int lch, u16 ch_status, void *data) | |||
1346 | return; | 1364 | return; |
1347 | } | 1365 | } |
1348 | 1366 | ||
1367 | static void omap_serial_fill_features_erratas(struct uart_omap_port *up) | ||
1368 | { | ||
1369 | u32 mvr, scheme; | ||
1370 | u16 revision, major, minor; | ||
1371 | |||
1372 | mvr = serial_in(up, UART_OMAP_MVER); | ||
1373 | |||
1374 | /* Check revision register scheme */ | ||
1375 | scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT; | ||
1376 | |||
1377 | switch (scheme) { | ||
1378 | case 0: /* Legacy Scheme: OMAP2/3 */ | ||
1379 | /* MINOR_REV[0:4], MAJOR_REV[4:7] */ | ||
1380 | major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >> | ||
1381 | OMAP_UART_LEGACY_MVR_MAJ_SHIFT; | ||
1382 | minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK); | ||
1383 | break; | ||
1384 | case 1: | ||
1385 | /* New Scheme: OMAP4+ */ | ||
1386 | /* MINOR_REV[0:5], MAJOR_REV[8:10] */ | ||
1387 | major = (mvr & OMAP_UART_MVR_MAJ_MASK) >> | ||
1388 | OMAP_UART_MVR_MAJ_SHIFT; | ||
1389 | minor = (mvr & OMAP_UART_MVR_MIN_MASK); | ||
1390 | break; | ||
1391 | default: | ||
1392 | dev_warn(&up->pdev->dev, | ||
1393 | "Unknown %s revision, defaulting to highest\n", | ||
1394 | up->name); | ||
1395 | /* highest possible revision */ | ||
1396 | major = 0xff; | ||
1397 | minor = 0xff; | ||
1398 | } | ||
1399 | |||
1400 | /* normalize revision for the driver */ | ||
1401 | revision = UART_BUILD_REVISION(major, minor); | ||
1402 | |||
1403 | switch (revision) { | ||
1404 | case OMAP_UART_REV_46: | ||
1405 | up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | | ||
1406 | UART_ERRATA_i291_DMA_FORCEIDLE); | ||
1407 | break; | ||
1408 | case OMAP_UART_REV_52: | ||
1409 | up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | | ||
1410 | UART_ERRATA_i291_DMA_FORCEIDLE); | ||
1411 | break; | ||
1412 | case OMAP_UART_REV_63: | ||
1413 | up->errata |= UART_ERRATA_i202_MDR1_ACCESS; | ||
1414 | break; | ||
1415 | default: | ||
1416 | break; | ||
1417 | } | ||
1418 | } | ||
1419 | |||
1349 | static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) | 1420 | static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) |
1350 | { | 1421 | { |
1351 | struct omap_uart_port_info *omap_up_info; | 1422 | struct omap_uart_port_info *omap_up_info; |
@@ -1439,7 +1510,6 @@ static int serial_omap_probe(struct platform_device *pdev) | |||
1439 | "%d\n", DEFAULT_CLK_SPEED); | 1510 | "%d\n", DEFAULT_CLK_SPEED); |
1440 | } | 1511 | } |
1441 | up->uart_dma.uart_base = mem->start; | 1512 | up->uart_dma.uart_base = mem->start; |
1442 | up->errata = omap_up_info->errata; | ||
1443 | 1513 | ||
1444 | if (omap_up_info->dma_enabled) { | 1514 | if (omap_up_info->dma_enabled) { |
1445 | up->uart_dma.uart_dma_tx = dma_tx->start; | 1515 | up->uart_dma.uart_dma_tx = dma_tx->start; |
@@ -1469,6 +1539,8 @@ static int serial_omap_probe(struct platform_device *pdev) | |||
1469 | pm_runtime_enable(&pdev->dev); | 1539 | pm_runtime_enable(&pdev->dev); |
1470 | pm_runtime_get_sync(&pdev->dev); | 1540 | pm_runtime_get_sync(&pdev->dev); |
1471 | 1541 | ||
1542 | omap_serial_fill_features_erratas(up); | ||
1543 | |||
1472 | ui[up->port.line] = up; | 1544 | ui[up->port.line] = up; |
1473 | serial_omap_add_console_port(up); | 1545 | serial_omap_add_console_port(up); |
1474 | 1546 | ||
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index c2816f494807..4fdec6a6b758 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c | |||
@@ -39,6 +39,7 @@ enum { | |||
39 | PCH_UART_HANDLED_RX_ERR_INT_SHIFT, | 39 | PCH_UART_HANDLED_RX_ERR_INT_SHIFT, |
40 | PCH_UART_HANDLED_RX_TRG_INT_SHIFT, | 40 | PCH_UART_HANDLED_RX_TRG_INT_SHIFT, |
41 | PCH_UART_HANDLED_MS_INT_SHIFT, | 41 | PCH_UART_HANDLED_MS_INT_SHIFT, |
42 | PCH_UART_HANDLED_LS_INT_SHIFT, | ||
42 | }; | 43 | }; |
43 | 44 | ||
44 | enum { | 45 | enum { |
@@ -63,6 +64,8 @@ enum { | |||
63 | PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1)) | 64 | PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1)) |
64 | #define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1)) | 65 | #define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1)) |
65 | 66 | ||
67 | #define PCH_UART_HANDLED_LS_INT (1<<((PCH_UART_HANDLED_LS_INT_SHIFT)<<1)) | ||
68 | |||
66 | #define PCH_UART_RBR 0x00 | 69 | #define PCH_UART_RBR 0x00 |
67 | #define PCH_UART_THR 0x00 | 70 | #define PCH_UART_THR 0x00 |
68 | 71 | ||
@@ -229,7 +232,6 @@ struct eg20t_port { | |||
229 | int start_tx; | 232 | int start_tx; |
230 | int start_rx; | 233 | int start_rx; |
231 | int tx_empty; | 234 | int tx_empty; |
232 | int int_dis_flag; | ||
233 | int trigger; | 235 | int trigger; |
234 | int trigger_level; | 236 | int trigger_level; |
235 | struct pch_uart_buffer rxbuf; | 237 | struct pch_uart_buffer rxbuf; |
@@ -237,7 +239,6 @@ struct eg20t_port { | |||
237 | unsigned int fcr; | 239 | unsigned int fcr; |
238 | unsigned int mcr; | 240 | unsigned int mcr; |
239 | unsigned int use_dma; | 241 | unsigned int use_dma; |
240 | unsigned int use_dma_flag; | ||
241 | struct dma_async_tx_descriptor *desc_tx; | 242 | struct dma_async_tx_descriptor *desc_tx; |
242 | struct dma_async_tx_descriptor *desc_rx; | 243 | struct dma_async_tx_descriptor *desc_rx; |
243 | struct pch_dma_slave param_tx; | 244 | struct pch_dma_slave param_tx; |
@@ -560,14 +561,10 @@ static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf, | |||
560 | return i; | 561 | return i; |
561 | } | 562 | } |
562 | 563 | ||
563 | static unsigned int pch_uart_hal_get_iid(struct eg20t_port *priv) | 564 | static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv) |
564 | { | 565 | { |
565 | unsigned int iir; | 566 | return ioread8(priv->membase + UART_IIR) &\ |
566 | int ret; | 567 | (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP); |
567 | |||
568 | iir = ioread8(priv->membase + UART_IIR); | ||
569 | ret = (iir & (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP)); | ||
570 | return ret; | ||
571 | } | 568 | } |
572 | 569 | ||
573 | static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv) | 570 | static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv) |
@@ -666,10 +663,13 @@ static void pch_free_dma(struct uart_port *port) | |||
666 | dma_release_channel(priv->chan_rx); | 663 | dma_release_channel(priv->chan_rx); |
667 | priv->chan_rx = NULL; | 664 | priv->chan_rx = NULL; |
668 | } | 665 | } |
669 | if (sg_dma_address(&priv->sg_rx)) | 666 | |
670 | dma_free_coherent(port->dev, port->fifosize, | 667 | if (priv->rx_buf_dma) { |
671 | sg_virt(&priv->sg_rx), | 668 | dma_free_coherent(port->dev, port->fifosize, priv->rx_buf_virt, |
672 | sg_dma_address(&priv->sg_rx)); | 669 | priv->rx_buf_dma); |
670 | priv->rx_buf_virt = NULL; | ||
671 | priv->rx_buf_dma = 0; | ||
672 | } | ||
673 | 673 | ||
674 | return; | 674 | return; |
675 | } | 675 | } |
@@ -1053,12 +1053,17 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) | |||
1053 | unsigned int handled; | 1053 | unsigned int handled; |
1054 | u8 lsr; | 1054 | u8 lsr; |
1055 | int ret = 0; | 1055 | int ret = 0; |
1056 | unsigned int iid; | 1056 | unsigned char iid; |
1057 | unsigned long flags; | 1057 | unsigned long flags; |
1058 | int next = 1; | ||
1059 | u8 msr; | ||
1058 | 1060 | ||
1059 | spin_lock_irqsave(&priv->port.lock, flags); | 1061 | spin_lock_irqsave(&priv->port.lock, flags); |
1060 | handled = 0; | 1062 | handled = 0; |
1061 | while ((iid = pch_uart_hal_get_iid(priv)) > 1) { | 1063 | while (next) { |
1064 | iid = pch_uart_hal_get_iid(priv); | ||
1065 | if (iid & PCH_UART_IIR_IP) /* No Interrupt */ | ||
1066 | break; | ||
1062 | switch (iid) { | 1067 | switch (iid) { |
1063 | case PCH_UART_IID_RLS: /* Receiver Line Status */ | 1068 | case PCH_UART_IID_RLS: /* Receiver Line Status */ |
1064 | lsr = pch_uart_hal_get_line_status(priv); | 1069 | lsr = pch_uart_hal_get_line_status(priv); |
@@ -1066,6 +1071,8 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) | |||
1066 | UART_LSR_PE | UART_LSR_OE)) { | 1071 | UART_LSR_PE | UART_LSR_OE)) { |
1067 | pch_uart_err_ir(priv, lsr); | 1072 | pch_uart_err_ir(priv, lsr); |
1068 | ret = PCH_UART_HANDLED_RX_ERR_INT; | 1073 | ret = PCH_UART_HANDLED_RX_ERR_INT; |
1074 | } else { | ||
1075 | ret = PCH_UART_HANDLED_LS_INT; | ||
1069 | } | 1076 | } |
1070 | break; | 1077 | break; |
1071 | case PCH_UART_IID_RDR: /* Received Data Ready */ | 1078 | case PCH_UART_IID_RDR: /* Received Data Ready */ |
@@ -1092,20 +1099,22 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) | |||
1092 | ret = handle_tx(priv); | 1099 | ret = handle_tx(priv); |
1093 | break; | 1100 | break; |
1094 | case PCH_UART_IID_MS: /* Modem Status */ | 1101 | case PCH_UART_IID_MS: /* Modem Status */ |
1095 | ret = PCH_UART_HANDLED_MS_INT; | 1102 | msr = pch_uart_hal_get_modem(priv); |
1103 | next = 0; /* MS ir prioirty is the lowest. So, MS ir | ||
1104 | means final interrupt */ | ||
1105 | if ((msr & UART_MSR_ANY_DELTA) == 0) | ||
1106 | break; | ||
1107 | ret |= PCH_UART_HANDLED_MS_INT; | ||
1096 | break; | 1108 | break; |
1097 | default: /* Never junp to this label */ | 1109 | default: /* Never junp to this label */ |
1098 | dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__, | 1110 | dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__, |
1099 | iid, jiffies); | 1111 | iid, jiffies); |
1100 | ret = -1; | 1112 | ret = -1; |
1113 | next = 0; | ||
1101 | break; | 1114 | break; |
1102 | } | 1115 | } |
1103 | handled |= (unsigned int)ret; | 1116 | handled |= (unsigned int)ret; |
1104 | } | 1117 | } |
1105 | if (handled == 0 && iid <= 1) { | ||
1106 | if (priv->int_dis_flag) | ||
1107 | priv->int_dis_flag = 0; | ||
1108 | } | ||
1109 | 1118 | ||
1110 | spin_unlock_irqrestore(&priv->port.lock, flags); | 1119 | spin_unlock_irqrestore(&priv->port.lock, flags); |
1111 | return IRQ_RETVAL(handled); | 1120 | return IRQ_RETVAL(handled); |
@@ -1200,7 +1209,6 @@ static void pch_uart_stop_rx(struct uart_port *port) | |||
1200 | priv = container_of(port, struct eg20t_port, port); | 1209 | priv = container_of(port, struct eg20t_port, port); |
1201 | priv->start_rx = 0; | 1210 | priv->start_rx = 0; |
1202 | pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT); | 1211 | pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT); |
1203 | priv->int_dis_flag = 1; | ||
1204 | } | 1212 | } |
1205 | 1213 | ||
1206 | /* Enable the modem status interrupts. */ | 1214 | /* Enable the modem status interrupts. */ |
@@ -1447,7 +1455,6 @@ static int pch_uart_verify_port(struct uart_port *port, | |||
1447 | __func__); | 1455 | __func__); |
1448 | return -EOPNOTSUPP; | 1456 | return -EOPNOTSUPP; |
1449 | #endif | 1457 | #endif |
1450 | priv->use_dma_flag = 1; | ||
1451 | dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n"); | 1458 | dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n"); |
1452 | if (!priv->use_dma) | 1459 | if (!priv->use_dma) |
1453 | pch_request_dma(port); | 1460 | pch_request_dma(port); |
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 9c4c05b2825b..246b823c1b27 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c | |||
@@ -2282,6 +2282,7 @@ void uart_unregister_driver(struct uart_driver *drv) | |||
2282 | tty_unregister_driver(p); | 2282 | tty_unregister_driver(p); |
2283 | put_tty_driver(p); | 2283 | put_tty_driver(p); |
2284 | kfree(drv->state); | 2284 | kfree(drv->state); |
2285 | drv->state = NULL; | ||
2285 | drv->tty_driver = NULL; | 2286 | drv->tty_driver = NULL; |
2286 | } | 2287 | } |
2287 | 2288 | ||
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c index 593d40ad0a6b..5ed0daae6564 100644 --- a/drivers/tty/synclink.c +++ b/drivers/tty/synclink.c | |||
@@ -3338,9 +3338,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, | |||
3338 | printk("%s(%d):block_til_ready blocking on %s count=%d\n", | 3338 | printk("%s(%d):block_til_ready blocking on %s count=%d\n", |
3339 | __FILE__,__LINE__, tty->driver->name, port->count ); | 3339 | __FILE__,__LINE__, tty->driver->name, port->count ); |
3340 | 3340 | ||
3341 | tty_unlock(); | 3341 | tty_unlock(tty); |
3342 | schedule(); | 3342 | schedule(); |
3343 | tty_lock(); | 3343 | tty_lock(tty); |
3344 | } | 3344 | } |
3345 | 3345 | ||
3346 | set_current_state(TASK_RUNNING); | 3346 | set_current_state(TASK_RUNNING); |
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c index aa1debf97cc7..45b43f11ca39 100644 --- a/drivers/tty/synclink_gt.c +++ b/drivers/tty/synclink_gt.c | |||
@@ -3336,9 +3336,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, | |||
3336 | } | 3336 | } |
3337 | 3337 | ||
3338 | DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); | 3338 | DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); |
3339 | tty_unlock(); | 3339 | tty_unlock(tty); |
3340 | schedule(); | 3340 | schedule(); |
3341 | tty_lock(); | 3341 | tty_lock(tty); |
3342 | } | 3342 | } |
3343 | 3343 | ||
3344 | set_current_state(TASK_RUNNING); | 3344 | set_current_state(TASK_RUNNING); |
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c index a3dddc12d2fe..4a1e4f07765b 100644 --- a/drivers/tty/synclinkmp.c +++ b/drivers/tty/synclinkmp.c | |||
@@ -3357,9 +3357,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, | |||
3357 | printk("%s(%d):%s block_til_ready() count=%d\n", | 3357 | printk("%s(%d):%s block_til_ready() count=%d\n", |
3358 | __FILE__,__LINE__, tty->driver->name, port->count ); | 3358 | __FILE__,__LINE__, tty->driver->name, port->count ); |
3359 | 3359 | ||
3360 | tty_unlock(); | 3360 | tty_unlock(tty); |
3361 | schedule(); | 3361 | schedule(); |
3362 | tty_lock(); | 3362 | tty_lock(tty); |
3363 | } | 3363 | } |
3364 | 3364 | ||
3365 | set_current_state(TASK_RUNNING); | 3365 | set_current_state(TASK_RUNNING); |
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index 6c9b7cd6778a..91e326ffe7db 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c | |||
@@ -185,25 +185,19 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size) | |||
185 | /* Should possibly check if this fails for the largest buffer we | 185 | /* Should possibly check if this fails for the largest buffer we |
186 | have queued and recycle that ? */ | 186 | have queued and recycle that ? */ |
187 | } | 187 | } |
188 | |||
189 | /** | 188 | /** |
190 | * tty_buffer_request_room - grow tty buffer if needed | 189 | * __tty_buffer_request_room - grow tty buffer if needed |
191 | * @tty: tty structure | 190 | * @tty: tty structure |
192 | * @size: size desired | 191 | * @size: size desired |
193 | * | 192 | * |
194 | * Make at least size bytes of linear space available for the tty | 193 | * Make at least size bytes of linear space available for the tty |
195 | * buffer. If we fail return the size we managed to find. | 194 | * buffer. If we fail return the size we managed to find. |
196 | * | 195 | * Locking: Caller must hold tty->buf.lock |
197 | * Locking: Takes tty->buf.lock | ||
198 | */ | 196 | */ |
199 | int tty_buffer_request_room(struct tty_struct *tty, size_t size) | 197 | static int __tty_buffer_request_room(struct tty_struct *tty, size_t size) |
200 | { | 198 | { |
201 | struct tty_buffer *b, *n; | 199 | struct tty_buffer *b, *n; |
202 | int left; | 200 | int left; |
203 | unsigned long flags; | ||
204 | |||
205 | spin_lock_irqsave(&tty->buf.lock, flags); | ||
206 | |||
207 | /* OPTIMISATION: We could keep a per tty "zero" sized buffer to | 201 | /* OPTIMISATION: We could keep a per tty "zero" sized buffer to |
208 | remove this conditional if its worth it. This would be invisible | 202 | remove this conditional if its worth it. This would be invisible |
209 | to the callers */ | 203 | to the callers */ |
@@ -225,9 +219,30 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size) | |||
225 | size = left; | 219 | size = left; |
226 | } | 220 | } |
227 | 221 | ||
228 | spin_unlock_irqrestore(&tty->buf.lock, flags); | ||
229 | return size; | 222 | return size; |
230 | } | 223 | } |
224 | |||
225 | |||
226 | /** | ||
227 | * tty_buffer_request_room - grow tty buffer if needed | ||
228 | * @tty: tty structure | ||
229 | * @size: size desired | ||
230 | * | ||
231 | * Make at least size bytes of linear space available for the tty | ||
232 | * buffer. If we fail return the size we managed to find. | ||
233 | * | ||
234 | * Locking: Takes tty->buf.lock | ||
235 | */ | ||
236 | int tty_buffer_request_room(struct tty_struct *tty, size_t size) | ||
237 | { | ||
238 | unsigned long flags; | ||
239 | int length; | ||
240 | |||
241 | spin_lock_irqsave(&tty->buf.lock, flags); | ||
242 | length = __tty_buffer_request_room(tty, size); | ||
243 | spin_unlock_irqrestore(&tty->buf.lock, flags); | ||
244 | return length; | ||
245 | } | ||
231 | EXPORT_SYMBOL_GPL(tty_buffer_request_room); | 246 | EXPORT_SYMBOL_GPL(tty_buffer_request_room); |
232 | 247 | ||
233 | /** | 248 | /** |
@@ -249,14 +264,22 @@ int tty_insert_flip_string_fixed_flag(struct tty_struct *tty, | |||
249 | int copied = 0; | 264 | int copied = 0; |
250 | do { | 265 | do { |
251 | int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); | 266 | int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); |
252 | int space = tty_buffer_request_room(tty, goal); | 267 | int space; |
253 | struct tty_buffer *tb = tty->buf.tail; | 268 | unsigned long flags; |
269 | struct tty_buffer *tb; | ||
270 | |||
271 | spin_lock_irqsave(&tty->buf.lock, flags); | ||
272 | space = __tty_buffer_request_room(tty, goal); | ||
273 | tb = tty->buf.tail; | ||
254 | /* If there is no space then tb may be NULL */ | 274 | /* If there is no space then tb may be NULL */ |
255 | if (unlikely(space == 0)) | 275 | if (unlikely(space == 0)) { |
276 | spin_unlock_irqrestore(&tty->buf.lock, flags); | ||
256 | break; | 277 | break; |
278 | } | ||
257 | memcpy(tb->char_buf_ptr + tb->used, chars, space); | 279 | memcpy(tb->char_buf_ptr + tb->used, chars, space); |
258 | memset(tb->flag_buf_ptr + tb->used, flag, space); | 280 | memset(tb->flag_buf_ptr + tb->used, flag, space); |
259 | tb->used += space; | 281 | tb->used += space; |
282 | spin_unlock_irqrestore(&tty->buf.lock, flags); | ||
260 | copied += space; | 283 | copied += space; |
261 | chars += space; | 284 | chars += space; |
262 | /* There is a small chance that we need to split the data over | 285 | /* There is a small chance that we need to split the data over |
@@ -286,14 +309,22 @@ int tty_insert_flip_string_flags(struct tty_struct *tty, | |||
286 | int copied = 0; | 309 | int copied = 0; |
287 | do { | 310 | do { |
288 | int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); | 311 | int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); |
289 | int space = tty_buffer_request_room(tty, goal); | 312 | int space; |
290 | struct tty_buffer *tb = tty->buf.tail; | 313 | unsigned long __flags; |
314 | struct tty_buffer *tb; | ||
315 | |||
316 | spin_lock_irqsave(&tty->buf.lock, __flags); | ||
317 | space = __tty_buffer_request_room(tty, goal); | ||
318 | tb = tty->buf.tail; | ||
291 | /* If there is no space then tb may be NULL */ | 319 | /* If there is no space then tb may be NULL */ |
292 | if (unlikely(space == 0)) | 320 | if (unlikely(space == 0)) { |
321 | spin_unlock_irqrestore(&tty->buf.lock, __flags); | ||
293 | break; | 322 | break; |
323 | } | ||
294 | memcpy(tb->char_buf_ptr + tb->used, chars, space); | 324 | memcpy(tb->char_buf_ptr + tb->used, chars, space); |
295 | memcpy(tb->flag_buf_ptr + tb->used, flags, space); | 325 | memcpy(tb->flag_buf_ptr + tb->used, flags, space); |
296 | tb->used += space; | 326 | tb->used += space; |
327 | spin_unlock_irqrestore(&tty->buf.lock, __flags); | ||
297 | copied += space; | 328 | copied += space; |
298 | chars += space; | 329 | chars += space; |
299 | flags += space; | 330 | flags += space; |
@@ -344,13 +375,20 @@ EXPORT_SYMBOL(tty_schedule_flip); | |||
344 | int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, | 375 | int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, |
345 | size_t size) | 376 | size_t size) |
346 | { | 377 | { |
347 | int space = tty_buffer_request_room(tty, size); | 378 | int space; |
379 | unsigned long flags; | ||
380 | struct tty_buffer *tb; | ||
381 | |||
382 | spin_lock_irqsave(&tty->buf.lock, flags); | ||
383 | space = __tty_buffer_request_room(tty, size); | ||
384 | |||
385 | tb = tty->buf.tail; | ||
348 | if (likely(space)) { | 386 | if (likely(space)) { |
349 | struct tty_buffer *tb = tty->buf.tail; | ||
350 | *chars = tb->char_buf_ptr + tb->used; | 387 | *chars = tb->char_buf_ptr + tb->used; |
351 | memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); | 388 | memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); |
352 | tb->used += space; | 389 | tb->used += space; |
353 | } | 390 | } |
391 | spin_unlock_irqrestore(&tty->buf.lock, flags); | ||
354 | return space; | 392 | return space; |
355 | } | 393 | } |
356 | EXPORT_SYMBOL_GPL(tty_prepare_flip_string); | 394 | EXPORT_SYMBOL_GPL(tty_prepare_flip_string); |
@@ -374,13 +412,20 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string); | |||
374 | int tty_prepare_flip_string_flags(struct tty_struct *tty, | 412 | int tty_prepare_flip_string_flags(struct tty_struct *tty, |
375 | unsigned char **chars, char **flags, size_t size) | 413 | unsigned char **chars, char **flags, size_t size) |
376 | { | 414 | { |
377 | int space = tty_buffer_request_room(tty, size); | 415 | int space; |
416 | unsigned long __flags; | ||
417 | struct tty_buffer *tb; | ||
418 | |||
419 | spin_lock_irqsave(&tty->buf.lock, __flags); | ||
420 | space = __tty_buffer_request_room(tty, size); | ||
421 | |||
422 | tb = tty->buf.tail; | ||
378 | if (likely(space)) { | 423 | if (likely(space)) { |
379 | struct tty_buffer *tb = tty->buf.tail; | ||
380 | *chars = tb->char_buf_ptr + tb->used; | 424 | *chars = tb->char_buf_ptr + tb->used; |
381 | *flags = tb->flag_buf_ptr + tb->used; | 425 | *flags = tb->flag_buf_ptr + tb->used; |
382 | tb->used += space; | 426 | tb->used += space; |
383 | } | 427 | } |
428 | spin_unlock_irqrestore(&tty->buf.lock, __flags); | ||
384 | return space; | 429 | return space; |
385 | } | 430 | } |
386 | EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); | 431 | EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); |
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index d939bd705c71..9e930c009bf2 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c | |||
@@ -185,6 +185,7 @@ void free_tty_struct(struct tty_struct *tty) | |||
185 | put_device(tty->dev); | 185 | put_device(tty->dev); |
186 | kfree(tty->write_buf); | 186 | kfree(tty->write_buf); |
187 | tty_buffer_free_all(tty); | 187 | tty_buffer_free_all(tty); |
188 | tty->magic = 0xDEADDEAD; | ||
188 | kfree(tty); | 189 | kfree(tty); |
189 | } | 190 | } |
190 | 191 | ||
@@ -573,7 +574,7 @@ void __tty_hangup(struct tty_struct *tty) | |||
573 | } | 574 | } |
574 | spin_unlock(&redirect_lock); | 575 | spin_unlock(&redirect_lock); |
575 | 576 | ||
576 | tty_lock(); | 577 | tty_lock(tty); |
577 | 578 | ||
578 | /* some functions below drop BTM, so we need this bit */ | 579 | /* some functions below drop BTM, so we need this bit */ |
579 | set_bit(TTY_HUPPING, &tty->flags); | 580 | set_bit(TTY_HUPPING, &tty->flags); |
@@ -666,7 +667,7 @@ void __tty_hangup(struct tty_struct *tty) | |||
666 | clear_bit(TTY_HUPPING, &tty->flags); | 667 | clear_bit(TTY_HUPPING, &tty->flags); |
667 | tty_ldisc_enable(tty); | 668 | tty_ldisc_enable(tty); |
668 | 669 | ||
669 | tty_unlock(); | 670 | tty_unlock(tty); |
670 | 671 | ||
671 | if (f) | 672 | if (f) |
672 | fput(f); | 673 | fput(f); |
@@ -855,10 +856,11 @@ void disassociate_ctty(int on_exit) | |||
855 | */ | 856 | */ |
856 | void no_tty(void) | 857 | void no_tty(void) |
857 | { | 858 | { |
859 | /* FIXME: Review locking here. The tty_lock never covered any race | ||
860 | between a new association and proc_clear_tty but possible we need | ||
861 | to protect against this anyway */ | ||
858 | struct task_struct *tsk = current; | 862 | struct task_struct *tsk = current; |
859 | tty_lock(); | ||
860 | disassociate_ctty(0); | 863 | disassociate_ctty(0); |
861 | tty_unlock(); | ||
862 | proc_clear_tty(tsk); | 864 | proc_clear_tty(tsk); |
863 | } | 865 | } |
864 | 866 | ||
@@ -1102,12 +1104,12 @@ void tty_write_message(struct tty_struct *tty, char *msg) | |||
1102 | { | 1104 | { |
1103 | if (tty) { | 1105 | if (tty) { |
1104 | mutex_lock(&tty->atomic_write_lock); | 1106 | mutex_lock(&tty->atomic_write_lock); |
1105 | tty_lock(); | 1107 | tty_lock(tty); |
1106 | if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { | 1108 | if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { |
1107 | tty_unlock(); | 1109 | tty_unlock(tty); |
1108 | tty->ops->write(tty, msg, strlen(msg)); | 1110 | tty->ops->write(tty, msg, strlen(msg)); |
1109 | } else | 1111 | } else |
1110 | tty_unlock(); | 1112 | tty_unlock(tty); |
1111 | tty_write_unlock(tty); | 1113 | tty_write_unlock(tty); |
1112 | } | 1114 | } |
1113 | return; | 1115 | return; |
@@ -1402,6 +1404,7 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) | |||
1402 | } | 1404 | } |
1403 | initialize_tty_struct(tty, driver, idx); | 1405 | initialize_tty_struct(tty, driver, idx); |
1404 | 1406 | ||
1407 | tty_lock(tty); | ||
1405 | retval = tty_driver_install_tty(driver, tty); | 1408 | retval = tty_driver_install_tty(driver, tty); |
1406 | if (retval < 0) | 1409 | if (retval < 0) |
1407 | goto err_deinit_tty; | 1410 | goto err_deinit_tty; |
@@ -1414,9 +1417,11 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) | |||
1414 | retval = tty_ldisc_setup(tty, tty->link); | 1417 | retval = tty_ldisc_setup(tty, tty->link); |
1415 | if (retval) | 1418 | if (retval) |
1416 | goto err_release_tty; | 1419 | goto err_release_tty; |
1420 | /* Return the tty locked so that it cannot vanish under the caller */ | ||
1417 | return tty; | 1421 | return tty; |
1418 | 1422 | ||
1419 | err_deinit_tty: | 1423 | err_deinit_tty: |
1424 | tty_unlock(tty); | ||
1420 | deinitialize_tty_struct(tty); | 1425 | deinitialize_tty_struct(tty); |
1421 | free_tty_struct(tty); | 1426 | free_tty_struct(tty); |
1422 | err_module_put: | 1427 | err_module_put: |
@@ -1425,6 +1430,7 @@ err_module_put: | |||
1425 | 1430 | ||
1426 | /* call the tty release_tty routine to clean out this slot */ | 1431 | /* call the tty release_tty routine to clean out this slot */ |
1427 | err_release_tty: | 1432 | err_release_tty: |
1433 | tty_unlock(tty); | ||
1428 | printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " | 1434 | printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " |
1429 | "clearing slot %d\n", idx); | 1435 | "clearing slot %d\n", idx); |
1430 | release_tty(tty, idx); | 1436 | release_tty(tty, idx); |
@@ -1627,7 +1633,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1627 | if (tty_paranoia_check(tty, inode, __func__)) | 1633 | if (tty_paranoia_check(tty, inode, __func__)) |
1628 | return 0; | 1634 | return 0; |
1629 | 1635 | ||
1630 | tty_lock(); | 1636 | tty_lock(tty); |
1631 | check_tty_count(tty, __func__); | 1637 | check_tty_count(tty, __func__); |
1632 | 1638 | ||
1633 | __tty_fasync(-1, filp, 0); | 1639 | __tty_fasync(-1, filp, 0); |
@@ -1636,10 +1642,11 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1636 | pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && | 1642 | pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && |
1637 | tty->driver->subtype == PTY_TYPE_MASTER); | 1643 | tty->driver->subtype == PTY_TYPE_MASTER); |
1638 | devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; | 1644 | devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; |
1645 | /* Review: parallel close */ | ||
1639 | o_tty = tty->link; | 1646 | o_tty = tty->link; |
1640 | 1647 | ||
1641 | if (tty_release_checks(tty, o_tty, idx)) { | 1648 | if (tty_release_checks(tty, o_tty, idx)) { |
1642 | tty_unlock(); | 1649 | tty_unlock(tty); |
1643 | return 0; | 1650 | return 0; |
1644 | } | 1651 | } |
1645 | 1652 | ||
@@ -1651,7 +1658,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1651 | if (tty->ops->close) | 1658 | if (tty->ops->close) |
1652 | tty->ops->close(tty, filp); | 1659 | tty->ops->close(tty, filp); |
1653 | 1660 | ||
1654 | tty_unlock(); | 1661 | tty_unlock(tty); |
1655 | /* | 1662 | /* |
1656 | * Sanity check: if tty->count is going to zero, there shouldn't be | 1663 | * Sanity check: if tty->count is going to zero, there shouldn't be |
1657 | * any waiters on tty->read_wait or tty->write_wait. We test the | 1664 | * any waiters on tty->read_wait or tty->write_wait. We test the |
@@ -1674,7 +1681,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1674 | opens on /dev/tty */ | 1681 | opens on /dev/tty */ |
1675 | 1682 | ||
1676 | mutex_lock(&tty_mutex); | 1683 | mutex_lock(&tty_mutex); |
1677 | tty_lock(); | 1684 | tty_lock_pair(tty, o_tty); |
1678 | tty_closing = tty->count <= 1; | 1685 | tty_closing = tty->count <= 1; |
1679 | o_tty_closing = o_tty && | 1686 | o_tty_closing = o_tty && |
1680 | (o_tty->count <= (pty_master ? 1 : 0)); | 1687 | (o_tty->count <= (pty_master ? 1 : 0)); |
@@ -1705,7 +1712,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1705 | 1712 | ||
1706 | printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", | 1713 | printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", |
1707 | __func__, tty_name(tty, buf)); | 1714 | __func__, tty_name(tty, buf)); |
1708 | tty_unlock(); | 1715 | tty_unlock_pair(tty, o_tty); |
1709 | mutex_unlock(&tty_mutex); | 1716 | mutex_unlock(&tty_mutex); |
1710 | schedule(); | 1717 | schedule(); |
1711 | } | 1718 | } |
@@ -1768,7 +1775,7 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1768 | 1775 | ||
1769 | /* check whether both sides are closing ... */ | 1776 | /* check whether both sides are closing ... */ |
1770 | if (!tty_closing || (o_tty && !o_tty_closing)) { | 1777 | if (!tty_closing || (o_tty && !o_tty_closing)) { |
1771 | tty_unlock(); | 1778 | tty_unlock_pair(tty, o_tty); |
1772 | return 0; | 1779 | return 0; |
1773 | } | 1780 | } |
1774 | 1781 | ||
@@ -1781,14 +1788,16 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1781 | tty_ldisc_release(tty, o_tty); | 1788 | tty_ldisc_release(tty, o_tty); |
1782 | /* | 1789 | /* |
1783 | * The release_tty function takes care of the details of clearing | 1790 | * The release_tty function takes care of the details of clearing |
1784 | * the slots and preserving the termios structure. | 1791 | * the slots and preserving the termios structure. The tty_unlock_pair |
1792 | * should be safe as we keep a kref while the tty is locked (so the | ||
1793 | * unlock never unlocks a freed tty). | ||
1785 | */ | 1794 | */ |
1786 | release_tty(tty, idx); | 1795 | release_tty(tty, idx); |
1796 | tty_unlock_pair(tty, o_tty); | ||
1787 | 1797 | ||
1788 | /* Make this pty number available for reallocation */ | 1798 | /* Make this pty number available for reallocation */ |
1789 | if (devpts) | 1799 | if (devpts) |
1790 | devpts_kill_index(inode, idx); | 1800 | devpts_kill_index(inode, idx); |
1791 | tty_unlock(); | ||
1792 | return 0; | 1801 | return 0; |
1793 | } | 1802 | } |
1794 | 1803 | ||
@@ -1800,6 +1809,9 @@ int tty_release(struct inode *inode, struct file *filp) | |||
1800 | * | 1809 | * |
1801 | * We cannot return driver and index like for the other nodes because | 1810 | * We cannot return driver and index like for the other nodes because |
1802 | * devpts will not work then. It expects inodes to be from devpts FS. | 1811 | * devpts will not work then. It expects inodes to be from devpts FS. |
1812 | * | ||
1813 | * We need to move to returning a refcounted object from all the lookup | ||
1814 | * paths including this one. | ||
1803 | */ | 1815 | */ |
1804 | static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp) | 1816 | static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp) |
1805 | { | 1817 | { |
@@ -1816,6 +1828,7 @@ static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp) | |||
1816 | /* noctty = 1; */ | 1828 | /* noctty = 1; */ |
1817 | tty_kref_put(tty); | 1829 | tty_kref_put(tty); |
1818 | /* FIXME: we put a reference and return a TTY! */ | 1830 | /* FIXME: we put a reference and return a TTY! */ |
1831 | /* This is only safe because the caller holds tty_mutex */ | ||
1819 | return tty; | 1832 | return tty; |
1820 | } | 1833 | } |
1821 | 1834 | ||
@@ -1888,6 +1901,9 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, | |||
1888 | * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. | 1901 | * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. |
1889 | * tty->count should protect the rest. | 1902 | * tty->count should protect the rest. |
1890 | * ->siglock protects ->signal/->sighand | 1903 | * ->siglock protects ->signal/->sighand |
1904 | * | ||
1905 | * Note: the tty_unlock/lock cases without a ref are only safe due to | ||
1906 | * tty_mutex | ||
1891 | */ | 1907 | */ |
1892 | 1908 | ||
1893 | static int tty_open(struct inode *inode, struct file *filp) | 1909 | static int tty_open(struct inode *inode, struct file *filp) |
@@ -1911,8 +1927,7 @@ retry_open: | |||
1911 | retval = 0; | 1927 | retval = 0; |
1912 | 1928 | ||
1913 | mutex_lock(&tty_mutex); | 1929 | mutex_lock(&tty_mutex); |
1914 | tty_lock(); | 1930 | /* This is protected by the tty_mutex */ |
1915 | |||
1916 | tty = tty_open_current_tty(device, filp); | 1931 | tty = tty_open_current_tty(device, filp); |
1917 | if (IS_ERR(tty)) { | 1932 | if (IS_ERR(tty)) { |
1918 | retval = PTR_ERR(tty); | 1933 | retval = PTR_ERR(tty); |
@@ -1933,17 +1948,19 @@ retry_open: | |||
1933 | } | 1948 | } |
1934 | 1949 | ||
1935 | if (tty) { | 1950 | if (tty) { |
1951 | tty_lock(tty); | ||
1936 | retval = tty_reopen(tty); | 1952 | retval = tty_reopen(tty); |
1937 | if (retval) | 1953 | if (retval < 0) { |
1954 | tty_unlock(tty); | ||
1938 | tty = ERR_PTR(retval); | 1955 | tty = ERR_PTR(retval); |
1939 | } else | 1956 | } |
1957 | } else /* Returns with the tty_lock held for now */ | ||
1940 | tty = tty_init_dev(driver, index); | 1958 | tty = tty_init_dev(driver, index); |
1941 | 1959 | ||
1942 | mutex_unlock(&tty_mutex); | 1960 | mutex_unlock(&tty_mutex); |
1943 | if (driver) | 1961 | if (driver) |
1944 | tty_driver_kref_put(driver); | 1962 | tty_driver_kref_put(driver); |
1945 | if (IS_ERR(tty)) { | 1963 | if (IS_ERR(tty)) { |
1946 | tty_unlock(); | ||
1947 | retval = PTR_ERR(tty); | 1964 | retval = PTR_ERR(tty); |
1948 | goto err_file; | 1965 | goto err_file; |
1949 | } | 1966 | } |
@@ -1972,7 +1989,7 @@ retry_open: | |||
1972 | printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, | 1989 | printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, |
1973 | retval, tty->name); | 1990 | retval, tty->name); |
1974 | #endif | 1991 | #endif |
1975 | tty_unlock(); /* need to call tty_release without BTM */ | 1992 | tty_unlock(tty); /* need to call tty_release without BTM */ |
1976 | tty_release(inode, filp); | 1993 | tty_release(inode, filp); |
1977 | if (retval != -ERESTARTSYS) | 1994 | if (retval != -ERESTARTSYS) |
1978 | return retval; | 1995 | return retval; |
@@ -1984,17 +2001,15 @@ retry_open: | |||
1984 | /* | 2001 | /* |
1985 | * Need to reset f_op in case a hangup happened. | 2002 | * Need to reset f_op in case a hangup happened. |
1986 | */ | 2003 | */ |
1987 | tty_lock(); | ||
1988 | if (filp->f_op == &hung_up_tty_fops) | 2004 | if (filp->f_op == &hung_up_tty_fops) |
1989 | filp->f_op = &tty_fops; | 2005 | filp->f_op = &tty_fops; |
1990 | tty_unlock(); | ||
1991 | goto retry_open; | 2006 | goto retry_open; |
1992 | } | 2007 | } |
1993 | tty_unlock(); | 2008 | tty_unlock(tty); |
1994 | 2009 | ||
1995 | 2010 | ||
1996 | mutex_lock(&tty_mutex); | 2011 | mutex_lock(&tty_mutex); |
1997 | tty_lock(); | 2012 | tty_lock(tty); |
1998 | spin_lock_irq(¤t->sighand->siglock); | 2013 | spin_lock_irq(¤t->sighand->siglock); |
1999 | if (!noctty && | 2014 | if (!noctty && |
2000 | current->signal->leader && | 2015 | current->signal->leader && |
@@ -2002,11 +2017,10 @@ retry_open: | |||
2002 | tty->session == NULL) | 2017 | tty->session == NULL) |
2003 | __proc_set_tty(current, tty); | 2018 | __proc_set_tty(current, tty); |
2004 | spin_unlock_irq(¤t->sighand->siglock); | 2019 | spin_unlock_irq(¤t->sighand->siglock); |
2005 | tty_unlock(); | 2020 | tty_unlock(tty); |
2006 | mutex_unlock(&tty_mutex); | 2021 | mutex_unlock(&tty_mutex); |
2007 | return 0; | 2022 | return 0; |
2008 | err_unlock: | 2023 | err_unlock: |
2009 | tty_unlock(); | ||
2010 | mutex_unlock(&tty_mutex); | 2024 | mutex_unlock(&tty_mutex); |
2011 | /* after locks to avoid deadlock */ | 2025 | /* after locks to avoid deadlock */ |
2012 | if (!IS_ERR_OR_NULL(driver)) | 2026 | if (!IS_ERR_OR_NULL(driver)) |
@@ -2089,10 +2103,13 @@ out: | |||
2089 | 2103 | ||
2090 | static int tty_fasync(int fd, struct file *filp, int on) | 2104 | static int tty_fasync(int fd, struct file *filp, int on) |
2091 | { | 2105 | { |
2106 | struct tty_struct *tty = file_tty(filp); | ||
2092 | int retval; | 2107 | int retval; |
2093 | tty_lock(); | 2108 | |
2109 | tty_lock(tty); | ||
2094 | retval = __tty_fasync(fd, filp, on); | 2110 | retval = __tty_fasync(fd, filp, on); |
2095 | tty_unlock(); | 2111 | tty_unlock(tty); |
2112 | |||
2096 | return retval; | 2113 | return retval; |
2097 | } | 2114 | } |
2098 | 2115 | ||
@@ -2929,6 +2946,7 @@ void initialize_tty_struct(struct tty_struct *tty, | |||
2929 | tty->pgrp = NULL; | 2946 | tty->pgrp = NULL; |
2930 | tty->overrun_time = jiffies; | 2947 | tty->overrun_time = jiffies; |
2931 | tty_buffer_init(tty); | 2948 | tty_buffer_init(tty); |
2949 | mutex_init(&tty->legacy_mutex); | ||
2932 | mutex_init(&tty->termios_mutex); | 2950 | mutex_init(&tty->termios_mutex); |
2933 | mutex_init(&tty->ldisc_mutex); | 2951 | mutex_init(&tty->ldisc_mutex); |
2934 | init_waitqueue_head(&tty->write_wait); | 2952 | init_waitqueue_head(&tty->write_wait); |
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index 24b95db75d84..173a9000a6cb 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c | |||
@@ -28,7 +28,6 @@ | |||
28 | 28 | ||
29 | static DEFINE_SPINLOCK(tty_ldisc_lock); | 29 | static DEFINE_SPINLOCK(tty_ldisc_lock); |
30 | static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); | 30 | static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); |
31 | static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_idle); | ||
32 | /* Line disc dispatch table */ | 31 | /* Line disc dispatch table */ |
33 | static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; | 32 | static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; |
34 | 33 | ||
@@ -65,7 +64,7 @@ static void put_ldisc(struct tty_ldisc *ld) | |||
65 | return; | 64 | return; |
66 | } | 65 | } |
67 | local_irq_restore(flags); | 66 | local_irq_restore(flags); |
68 | wake_up(&tty_ldisc_idle); | 67 | wake_up(&ld->wq_idle); |
69 | } | 68 | } |
70 | 69 | ||
71 | /** | 70 | /** |
@@ -200,6 +199,8 @@ static struct tty_ldisc *tty_ldisc_get(int disc) | |||
200 | 199 | ||
201 | ld->ops = ldops; | 200 | ld->ops = ldops; |
202 | atomic_set(&ld->users, 1); | 201 | atomic_set(&ld->users, 1); |
202 | init_waitqueue_head(&ld->wq_idle); | ||
203 | |||
203 | return ld; | 204 | return ld; |
204 | } | 205 | } |
205 | 206 | ||
@@ -538,7 +539,7 @@ static void tty_ldisc_flush_works(struct tty_struct *tty) | |||
538 | static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout) | 539 | static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout) |
539 | { | 540 | { |
540 | long ret; | 541 | long ret; |
541 | ret = wait_event_timeout(tty_ldisc_idle, | 542 | ret = wait_event_timeout(tty->ldisc->wq_idle, |
542 | atomic_read(&tty->ldisc->users) == 1, timeout); | 543 | atomic_read(&tty->ldisc->users) == 1, timeout); |
543 | return ret > 0 ? 0 : -EBUSY; | 544 | return ret > 0 ? 0 : -EBUSY; |
544 | } | 545 | } |
@@ -567,7 +568,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
567 | if (IS_ERR(new_ldisc)) | 568 | if (IS_ERR(new_ldisc)) |
568 | return PTR_ERR(new_ldisc); | 569 | return PTR_ERR(new_ldisc); |
569 | 570 | ||
570 | tty_lock(); | 571 | tty_lock(tty); |
571 | /* | 572 | /* |
572 | * We need to look at the tty locking here for pty/tty pairs | 573 | * We need to look at the tty locking here for pty/tty pairs |
573 | * when both sides try to change in parallel. | 574 | * when both sides try to change in parallel. |
@@ -581,12 +582,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
581 | */ | 582 | */ |
582 | 583 | ||
583 | if (tty->ldisc->ops->num == ldisc) { | 584 | if (tty->ldisc->ops->num == ldisc) { |
584 | tty_unlock(); | 585 | tty_unlock(tty); |
585 | tty_ldisc_put(new_ldisc); | 586 | tty_ldisc_put(new_ldisc); |
586 | return 0; | 587 | return 0; |
587 | } | 588 | } |
588 | 589 | ||
589 | tty_unlock(); | 590 | tty_unlock(tty); |
590 | /* | 591 | /* |
591 | * Problem: What do we do if this blocks ? | 592 | * Problem: What do we do if this blocks ? |
592 | * We could deadlock here | 593 | * We could deadlock here |
@@ -594,7 +595,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
594 | 595 | ||
595 | tty_wait_until_sent(tty, 0); | 596 | tty_wait_until_sent(tty, 0); |
596 | 597 | ||
597 | tty_lock(); | 598 | tty_lock(tty); |
598 | mutex_lock(&tty->ldisc_mutex); | 599 | mutex_lock(&tty->ldisc_mutex); |
599 | 600 | ||
600 | /* | 601 | /* |
@@ -604,10 +605,10 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
604 | 605 | ||
605 | while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { | 606 | while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { |
606 | mutex_unlock(&tty->ldisc_mutex); | 607 | mutex_unlock(&tty->ldisc_mutex); |
607 | tty_unlock(); | 608 | tty_unlock(tty); |
608 | wait_event(tty_ldisc_wait, | 609 | wait_event(tty_ldisc_wait, |
609 | test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); | 610 | test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); |
610 | tty_lock(); | 611 | tty_lock(tty); |
611 | mutex_lock(&tty->ldisc_mutex); | 612 | mutex_lock(&tty->ldisc_mutex); |
612 | } | 613 | } |
613 | 614 | ||
@@ -622,7 +623,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
622 | 623 | ||
623 | o_ldisc = tty->ldisc; | 624 | o_ldisc = tty->ldisc; |
624 | 625 | ||
625 | tty_unlock(); | 626 | tty_unlock(tty); |
626 | /* | 627 | /* |
627 | * Make sure we don't change while someone holds a | 628 | * Make sure we don't change while someone holds a |
628 | * reference to the line discipline. The TTY_LDISC bit | 629 | * reference to the line discipline. The TTY_LDISC bit |
@@ -649,7 +650,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
649 | 650 | ||
650 | retval = tty_ldisc_wait_idle(tty, 5 * HZ); | 651 | retval = tty_ldisc_wait_idle(tty, 5 * HZ); |
651 | 652 | ||
652 | tty_lock(); | 653 | tty_lock(tty); |
653 | mutex_lock(&tty->ldisc_mutex); | 654 | mutex_lock(&tty->ldisc_mutex); |
654 | 655 | ||
655 | /* handle wait idle failure locked */ | 656 | /* handle wait idle failure locked */ |
@@ -664,7 +665,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) | |||
664 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); | 665 | clear_bit(TTY_LDISC_CHANGING, &tty->flags); |
665 | mutex_unlock(&tty->ldisc_mutex); | 666 | mutex_unlock(&tty->ldisc_mutex); |
666 | tty_ldisc_put(new_ldisc); | 667 | tty_ldisc_put(new_ldisc); |
667 | tty_unlock(); | 668 | tty_unlock(tty); |
668 | return -EIO; | 669 | return -EIO; |
669 | } | 670 | } |
670 | 671 | ||
@@ -707,7 +708,7 @@ enable: | |||
707 | if (o_work) | 708 | if (o_work) |
708 | schedule_work(&o_tty->buf.work); | 709 | schedule_work(&o_tty->buf.work); |
709 | mutex_unlock(&tty->ldisc_mutex); | 710 | mutex_unlock(&tty->ldisc_mutex); |
710 | tty_unlock(); | 711 | tty_unlock(tty); |
711 | return retval; | 712 | return retval; |
712 | } | 713 | } |
713 | 714 | ||
@@ -815,11 +816,11 @@ void tty_ldisc_hangup(struct tty_struct *tty) | |||
815 | * need to wait for another function taking the BTM | 816 | * need to wait for another function taking the BTM |
816 | */ | 817 | */ |
817 | clear_bit(TTY_LDISC, &tty->flags); | 818 | clear_bit(TTY_LDISC, &tty->flags); |
818 | tty_unlock(); | 819 | tty_unlock(tty); |
819 | cancel_work_sync(&tty->buf.work); | 820 | cancel_work_sync(&tty->buf.work); |
820 | mutex_unlock(&tty->ldisc_mutex); | 821 | mutex_unlock(&tty->ldisc_mutex); |
821 | retry: | 822 | retry: |
822 | tty_lock(); | 823 | tty_lock(tty); |
823 | mutex_lock(&tty->ldisc_mutex); | 824 | mutex_lock(&tty->ldisc_mutex); |
824 | 825 | ||
825 | /* At this point we have a closed ldisc and we want to | 826 | /* At this point we have a closed ldisc and we want to |
@@ -830,7 +831,7 @@ retry: | |||
830 | if (atomic_read(&tty->ldisc->users) != 1) { | 831 | if (atomic_read(&tty->ldisc->users) != 1) { |
831 | char cur_n[TASK_COMM_LEN], tty_n[64]; | 832 | char cur_n[TASK_COMM_LEN], tty_n[64]; |
832 | long timeout = 3 * HZ; | 833 | long timeout = 3 * HZ; |
833 | tty_unlock(); | 834 | tty_unlock(tty); |
834 | 835 | ||
835 | while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { | 836 | while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { |
836 | timeout = MAX_SCHEDULE_TIMEOUT; | 837 | timeout = MAX_SCHEDULE_TIMEOUT; |
@@ -911,10 +912,10 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) | |||
911 | * race with the set_ldisc code path. | 912 | * race with the set_ldisc code path. |
912 | */ | 913 | */ |
913 | 914 | ||
914 | tty_unlock(); | 915 | tty_unlock(tty); |
915 | tty_ldisc_halt(tty); | 916 | tty_ldisc_halt(tty); |
916 | tty_ldisc_flush_works(tty); | 917 | tty_ldisc_flush_works(tty); |
917 | tty_lock(); | 918 | tty_lock(tty); |
918 | 919 | ||
919 | mutex_lock(&tty->ldisc_mutex); | 920 | mutex_lock(&tty->ldisc_mutex); |
920 | /* | 921 | /* |
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c index 9ff986c32a21..69adc80c98cd 100644 --- a/drivers/tty/tty_mutex.c +++ b/drivers/tty/tty_mutex.c | |||
@@ -4,29 +4,59 @@ | |||
4 | #include <linux/semaphore.h> | 4 | #include <linux/semaphore.h> |
5 | #include <linux/sched.h> | 5 | #include <linux/sched.h> |
6 | 6 | ||
7 | /* | 7 | /* Legacy tty mutex glue */ |
8 | * The 'big tty mutex' | ||
9 | * | ||
10 | * This mutex is taken and released by tty_lock() and tty_unlock(), | ||
11 | * replacing the older big kernel lock. | ||
12 | * It can no longer be taken recursively, and does not get | ||
13 | * released implicitly while sleeping. | ||
14 | * | ||
15 | * Don't use in new code. | ||
16 | */ | ||
17 | static DEFINE_MUTEX(big_tty_mutex); | ||
18 | 8 | ||
19 | /* | 9 | /* |
20 | * Getting the big tty mutex. | 10 | * Getting the big tty mutex. |
21 | */ | 11 | */ |
22 | void __lockfunc tty_lock(void) | 12 | |
13 | void __lockfunc tty_lock(struct tty_struct *tty) | ||
23 | { | 14 | { |
24 | mutex_lock(&big_tty_mutex); | 15 | if (tty->magic != TTY_MAGIC) { |
16 | printk(KERN_ERR "L Bad %p\n", tty); | ||
17 | WARN_ON(1); | ||
18 | return; | ||
19 | } | ||
20 | tty_kref_get(tty); | ||
21 | mutex_lock(&tty->legacy_mutex); | ||
25 | } | 22 | } |
26 | EXPORT_SYMBOL(tty_lock); | 23 | EXPORT_SYMBOL(tty_lock); |
27 | 24 | ||
28 | void __lockfunc tty_unlock(void) | 25 | void __lockfunc tty_unlock(struct tty_struct *tty) |
29 | { | 26 | { |
30 | mutex_unlock(&big_tty_mutex); | 27 | if (tty->magic != TTY_MAGIC) { |
28 | printk(KERN_ERR "U Bad %p\n", tty); | ||
29 | WARN_ON(1); | ||
30 | return; | ||
31 | } | ||
32 | mutex_unlock(&tty->legacy_mutex); | ||
33 | tty_kref_put(tty); | ||
31 | } | 34 | } |
32 | EXPORT_SYMBOL(tty_unlock); | 35 | EXPORT_SYMBOL(tty_unlock); |
36 | |||
37 | /* | ||
38 | * Getting the big tty mutex for a pair of ttys with lock ordering | ||
39 | * On a non pty/tty pair tty2 can be NULL which is just fine. | ||
40 | */ | ||
41 | void __lockfunc tty_lock_pair(struct tty_struct *tty, | ||
42 | struct tty_struct *tty2) | ||
43 | { | ||
44 | if (tty < tty2) { | ||
45 | tty_lock(tty); | ||
46 | tty_lock(tty2); | ||
47 | } else { | ||
48 | if (tty2 && tty2 != tty) | ||
49 | tty_lock(tty2); | ||
50 | tty_lock(tty); | ||
51 | } | ||
52 | } | ||
53 | EXPORT_SYMBOL(tty_lock_pair); | ||
54 | |||
55 | void __lockfunc tty_unlock_pair(struct tty_struct *tty, | ||
56 | struct tty_struct *tty2) | ||
57 | { | ||
58 | tty_unlock(tty); | ||
59 | if (tty2 && tty2 != tty) | ||
60 | tty_unlock(tty2); | ||
61 | } | ||
62 | EXPORT_SYMBOL(tty_unlock_pair); | ||
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index bf6e238146ae..d9cca95a5452 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c | |||
@@ -230,7 +230,7 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
230 | 230 | ||
231 | /* block if port is in the process of being closed */ | 231 | /* block if port is in the process of being closed */ |
232 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { | 232 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { |
233 | wait_event_interruptible_tty(port->close_wait, | 233 | wait_event_interruptible_tty(tty, port->close_wait, |
234 | !(port->flags & ASYNC_CLOSING)); | 234 | !(port->flags & ASYNC_CLOSING)); |
235 | if (port->flags & ASYNC_HUP_NOTIFY) | 235 | if (port->flags & ASYNC_HUP_NOTIFY) |
236 | return -EAGAIN; | 236 | return -EAGAIN; |
@@ -296,9 +296,9 @@ int tty_port_block_til_ready(struct tty_port *port, | |||
296 | retval = -ERESTARTSYS; | 296 | retval = -ERESTARTSYS; |
297 | break; | 297 | break; |
298 | } | 298 | } |
299 | tty_unlock(); | 299 | tty_unlock(tty); |
300 | schedule(); | 300 | schedule(); |
301 | tty_lock(); | 301 | tty_lock(tty); |
302 | } | 302 | } |
303 | finish_wait(&port->open_wait, &wait); | 303 | finish_wait(&port->open_wait, &wait); |
304 | 304 | ||
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c index 8308fc7cdc26..2aaa0c228409 100644 --- a/drivers/tty/vt/consolemap.c +++ b/drivers/tty/vt/consolemap.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/tty.h> | 20 | #include <linux/tty.h> |
21 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
22 | #include <linux/console.h> | ||
22 | #include <linux/consolemap.h> | 23 | #include <linux/consolemap.h> |
23 | #include <linux/vt_kern.h> | 24 | #include <linux/vt_kern.h> |
24 | 25 | ||
@@ -312,6 +313,7 @@ int con_set_trans_old(unsigned char __user * arg) | |||
312 | if (!access_ok(VERIFY_READ, arg, E_TABSZ)) | 313 | if (!access_ok(VERIFY_READ, arg, E_TABSZ)) |
313 | return -EFAULT; | 314 | return -EFAULT; |
314 | 315 | ||
316 | console_lock(); | ||
315 | for (i=0; i<E_TABSZ ; i++) { | 317 | for (i=0; i<E_TABSZ ; i++) { |
316 | unsigned char uc; | 318 | unsigned char uc; |
317 | __get_user(uc, arg+i); | 319 | __get_user(uc, arg+i); |
@@ -319,6 +321,7 @@ int con_set_trans_old(unsigned char __user * arg) | |||
319 | } | 321 | } |
320 | 322 | ||
321 | update_user_maps(); | 323 | update_user_maps(); |
324 | console_unlock(); | ||
322 | return 0; | 325 | return 0; |
323 | } | 326 | } |
324 | 327 | ||
@@ -330,11 +333,13 @@ int con_get_trans_old(unsigned char __user * arg) | |||
330 | if (!access_ok(VERIFY_WRITE, arg, E_TABSZ)) | 333 | if (!access_ok(VERIFY_WRITE, arg, E_TABSZ)) |
331 | return -EFAULT; | 334 | return -EFAULT; |
332 | 335 | ||
336 | console_lock(); | ||
333 | for (i=0; i<E_TABSZ ; i++) | 337 | for (i=0; i<E_TABSZ ; i++) |
334 | { | 338 | { |
335 | ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]); | 339 | ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]); |
336 | __put_user((ch & ~0xff) ? 0 : ch, arg+i); | 340 | __put_user((ch & ~0xff) ? 0 : ch, arg+i); |
337 | } | 341 | } |
342 | console_unlock(); | ||
338 | return 0; | 343 | return 0; |
339 | } | 344 | } |
340 | 345 | ||
@@ -346,6 +351,7 @@ int con_set_trans_new(ushort __user * arg) | |||
346 | if (!access_ok(VERIFY_READ, arg, E_TABSZ*sizeof(unsigned short))) | 351 | if (!access_ok(VERIFY_READ, arg, E_TABSZ*sizeof(unsigned short))) |
347 | return -EFAULT; | 352 | return -EFAULT; |
348 | 353 | ||
354 | console_lock(); | ||
349 | for (i=0; i<E_TABSZ ; i++) { | 355 | for (i=0; i<E_TABSZ ; i++) { |
350 | unsigned short us; | 356 | unsigned short us; |
351 | __get_user(us, arg+i); | 357 | __get_user(us, arg+i); |
@@ -353,6 +359,7 @@ int con_set_trans_new(ushort __user * arg) | |||
353 | } | 359 | } |
354 | 360 | ||
355 | update_user_maps(); | 361 | update_user_maps(); |
362 | console_unlock(); | ||
356 | return 0; | 363 | return 0; |
357 | } | 364 | } |
358 | 365 | ||
@@ -364,8 +371,10 @@ int con_get_trans_new(ushort __user * arg) | |||
364 | if (!access_ok(VERIFY_WRITE, arg, E_TABSZ*sizeof(unsigned short))) | 371 | if (!access_ok(VERIFY_WRITE, arg, E_TABSZ*sizeof(unsigned short))) |
365 | return -EFAULT; | 372 | return -EFAULT; |
366 | 373 | ||
374 | console_lock(); | ||
367 | for (i=0; i<E_TABSZ ; i++) | 375 | for (i=0; i<E_TABSZ ; i++) |
368 | __put_user(p[i], arg+i); | 376 | __put_user(p[i], arg+i); |
377 | console_unlock(); | ||
369 | 378 | ||
370 | return 0; | 379 | return 0; |
371 | } | 380 | } |
@@ -407,6 +416,7 @@ static void con_release_unimap(struct uni_pagedir *p) | |||
407 | } | 416 | } |
408 | } | 417 | } |
409 | 418 | ||
419 | /* Caller must hold the console lock */ | ||
410 | void con_free_unimap(struct vc_data *vc) | 420 | void con_free_unimap(struct vc_data *vc) |
411 | { | 421 | { |
412 | struct uni_pagedir *p; | 422 | struct uni_pagedir *p; |
@@ -487,17 +497,21 @@ con_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos) | |||
487 | return 0; | 497 | return 0; |
488 | } | 498 | } |
489 | 499 | ||
490 | /* ui is a leftover from using a hashtable, but might be used again */ | 500 | /* ui is a leftover from using a hashtable, but might be used again |
491 | int con_clear_unimap(struct vc_data *vc, struct unimapinit *ui) | 501 | Caller must hold the lock */ |
502 | static int con_do_clear_unimap(struct vc_data *vc, struct unimapinit *ui) | ||
492 | { | 503 | { |
493 | struct uni_pagedir *p, *q; | 504 | struct uni_pagedir *p, *q; |
494 | 505 | ||
495 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; | 506 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; |
496 | if (p && p->readonly) return -EIO; | 507 | if (p && p->readonly) |
508 | return -EIO; | ||
509 | |||
497 | if (!p || --p->refcount) { | 510 | if (!p || --p->refcount) { |
498 | q = kzalloc(sizeof(*p), GFP_KERNEL); | 511 | q = kzalloc(sizeof(*p), GFP_KERNEL); |
499 | if (!q) { | 512 | if (!q) { |
500 | if (p) p->refcount++; | 513 | if (p) |
514 | p->refcount++; | ||
501 | return -ENOMEM; | 515 | return -ENOMEM; |
502 | } | 516 | } |
503 | q->refcount=1; | 517 | q->refcount=1; |
@@ -511,23 +525,43 @@ int con_clear_unimap(struct vc_data *vc, struct unimapinit *ui) | |||
511 | return 0; | 525 | return 0; |
512 | } | 526 | } |
513 | 527 | ||
528 | int con_clear_unimap(struct vc_data *vc, struct unimapinit *ui) | ||
529 | { | ||
530 | int ret; | ||
531 | console_lock(); | ||
532 | ret = con_do_clear_unimap(vc, ui); | ||
533 | console_unlock(); | ||
534 | return ret; | ||
535 | } | ||
536 | |||
514 | int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) | 537 | int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) |
515 | { | 538 | { |
516 | int err = 0, err1, i; | 539 | int err = 0, err1, i; |
517 | struct uni_pagedir *p, *q; | 540 | struct uni_pagedir *p, *q; |
518 | 541 | ||
542 | console_lock(); | ||
543 | |||
519 | /* Save original vc_unipagdir_loc in case we allocate a new one */ | 544 | /* Save original vc_unipagdir_loc in case we allocate a new one */ |
520 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; | 545 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; |
521 | if (p->readonly) return -EIO; | 546 | if (p->readonly) { |
547 | console_unlock(); | ||
548 | return -EIO; | ||
549 | } | ||
522 | 550 | ||
523 | if (!ct) return 0; | 551 | if (!ct) { |
552 | console_unlock(); | ||
553 | return 0; | ||
554 | } | ||
524 | 555 | ||
525 | if (p->refcount > 1) { | 556 | if (p->refcount > 1) { |
526 | int j, k; | 557 | int j, k; |
527 | u16 **p1, *p2, l; | 558 | u16 **p1, *p2, l; |
528 | 559 | ||
529 | err1 = con_clear_unimap(vc, NULL); | 560 | err1 = con_do_clear_unimap(vc, NULL); |
530 | if (err1) return err1; | 561 | if (err1) { |
562 | console_unlock(); | ||
563 | return err1; | ||
564 | } | ||
531 | 565 | ||
532 | /* | 566 | /* |
533 | * Since refcount was > 1, con_clear_unimap() allocated a | 567 | * Since refcount was > 1, con_clear_unimap() allocated a |
@@ -558,7 +592,8 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) | |||
558 | *vc->vc_uni_pagedir_loc = (unsigned long)p; | 592 | *vc->vc_uni_pagedir_loc = (unsigned long)p; |
559 | con_release_unimap(q); | 593 | con_release_unimap(q); |
560 | kfree(q); | 594 | kfree(q); |
561 | return err1; | 595 | console_unlock(); |
596 | return err1; | ||
562 | } | 597 | } |
563 | } | 598 | } |
564 | } else { | 599 | } else { |
@@ -592,21 +627,30 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) | |||
592 | /* | 627 | /* |
593 | * Merge with fontmaps of any other virtual consoles. | 628 | * Merge with fontmaps of any other virtual consoles. |
594 | */ | 629 | */ |
595 | if (con_unify_unimap(vc, p)) | 630 | if (con_unify_unimap(vc, p)) { |
631 | console_unlock(); | ||
596 | return err; | 632 | return err; |
633 | } | ||
597 | 634 | ||
598 | for (i = 0; i <= 3; i++) | 635 | for (i = 0; i <= 3; i++) |
599 | set_inverse_transl(vc, p, i); /* Update inverse translations */ | 636 | set_inverse_transl(vc, p, i); /* Update inverse translations */ |
600 | set_inverse_trans_unicode(vc, p); | 637 | set_inverse_trans_unicode(vc, p); |
601 | 638 | ||
639 | console_unlock(); | ||
602 | return err; | 640 | return err; |
603 | } | 641 | } |
604 | 642 | ||
605 | /* Loads the unimap for the hardware font, as defined in uni_hash.tbl. | 643 | /** |
606 | The representation used was the most compact I could come up | 644 | * con_set_default_unimap - set default unicode map |
607 | with. This routine is executed at sys_setup time, and when the | 645 | * @vc: the console we are updating |
608 | PIO_FONTRESET ioctl is called. */ | 646 | * |
609 | 647 | * Loads the unimap for the hardware font, as defined in uni_hash.tbl. | |
648 | * The representation used was the most compact I could come up | ||
649 | * with. This routine is executed at video setup, and when the | ||
650 | * PIO_FONTRESET ioctl is called. | ||
651 | * | ||
652 | * The caller must hold the console lock | ||
653 | */ | ||
610 | int con_set_default_unimap(struct vc_data *vc) | 654 | int con_set_default_unimap(struct vc_data *vc) |
611 | { | 655 | { |
612 | int i, j, err = 0, err1; | 656 | int i, j, err = 0, err1; |
@@ -617,6 +661,7 @@ int con_set_default_unimap(struct vc_data *vc) | |||
617 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; | 661 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; |
618 | if (p == dflt) | 662 | if (p == dflt) |
619 | return 0; | 663 | return 0; |
664 | |||
620 | dflt->refcount++; | 665 | dflt->refcount++; |
621 | *vc->vc_uni_pagedir_loc = (unsigned long)dflt; | 666 | *vc->vc_uni_pagedir_loc = (unsigned long)dflt; |
622 | if (p && !--p->refcount) { | 667 | if (p && !--p->refcount) { |
@@ -628,8 +673,9 @@ int con_set_default_unimap(struct vc_data *vc) | |||
628 | 673 | ||
629 | /* The default font is always 256 characters */ | 674 | /* The default font is always 256 characters */ |
630 | 675 | ||
631 | err = con_clear_unimap(vc, NULL); | 676 | err = con_do_clear_unimap(vc, NULL); |
632 | if (err) return err; | 677 | if (err) |
678 | return err; | ||
633 | 679 | ||
634 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; | 680 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; |
635 | q = dfont_unitable; | 681 | q = dfont_unitable; |
@@ -654,6 +700,13 @@ int con_set_default_unimap(struct vc_data *vc) | |||
654 | } | 700 | } |
655 | EXPORT_SYMBOL(con_set_default_unimap); | 701 | EXPORT_SYMBOL(con_set_default_unimap); |
656 | 702 | ||
703 | /** | ||
704 | * con_copy_unimap - copy unimap between two vts | ||
705 | * @dst_vc: target | ||
706 | * @src_vt: source | ||
707 | * | ||
708 | * The caller must hold the console lock when invoking this method | ||
709 | */ | ||
657 | int con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc) | 710 | int con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc) |
658 | { | 711 | { |
659 | struct uni_pagedir *q; | 712 | struct uni_pagedir *q; |
@@ -668,13 +721,23 @@ int con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc) | |||
668 | *dst_vc->vc_uni_pagedir_loc = (long)q; | 721 | *dst_vc->vc_uni_pagedir_loc = (long)q; |
669 | return 0; | 722 | return 0; |
670 | } | 723 | } |
724 | EXPORT_SYMBOL(con_copy_unimap); | ||
671 | 725 | ||
726 | /** | ||
727 | * con_get_unimap - get the unicode map | ||
728 | * @vc: the console to read from | ||
729 | * | ||
730 | * Read the console unicode data for this console. Called from the ioctl | ||
731 | * handlers. | ||
732 | */ | ||
672 | int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list) | 733 | int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list) |
673 | { | 734 | { |
674 | int i, j, k, ect; | 735 | int i, j, k, ect; |
675 | u16 **p1, *p2; | 736 | u16 **p1, *p2; |
676 | struct uni_pagedir *p; | 737 | struct uni_pagedir *p; |
677 | 738 | ||
739 | console_lock(); | ||
740 | |||
678 | ect = 0; | 741 | ect = 0; |
679 | if (*vc->vc_uni_pagedir_loc) { | 742 | if (*vc->vc_uni_pagedir_loc) { |
680 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; | 743 | p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; |
@@ -694,22 +757,19 @@ int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct uni | |||
694 | } | 757 | } |
695 | } | 758 | } |
696 | __put_user(ect, uct); | 759 | __put_user(ect, uct); |
760 | console_unlock(); | ||
697 | return ((ect <= ct) ? 0 : -ENOMEM); | 761 | return ((ect <= ct) ? 0 : -ENOMEM); |
698 | } | 762 | } |
699 | 763 | ||
700 | void con_protect_unimap(struct vc_data *vc, int rdonly) | ||
701 | { | ||
702 | struct uni_pagedir *p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; | ||
703 | |||
704 | if (p) | ||
705 | p->readonly = rdonly; | ||
706 | } | ||
707 | |||
708 | /* | 764 | /* |
709 | * Always use USER_MAP. These functions are used by the keyboard, | 765 | * Always use USER_MAP. These functions are used by the keyboard, |
710 | * which shouldn't be affected by G0/G1 switching, etc. | 766 | * which shouldn't be affected by G0/G1 switching, etc. |
711 | * If the user map still contains default values, i.e. the | 767 | * If the user map still contains default values, i.e. the |
712 | * direct-to-font mapping, then assume user is using Latin1. | 768 | * direct-to-font mapping, then assume user is using Latin1. |
769 | * | ||
770 | * FIXME: at some point we need to decide if we want to lock the table | ||
771 | * update element itself via the keyboard_event_lock for consistency with the | ||
772 | * keyboard driver as well as the consoles | ||
713 | */ | 773 | */ |
714 | /* may be called during an interrupt */ | 774 | /* may be called during an interrupt */ |
715 | u32 conv_8bit_to_uni(unsigned char c) | 775 | u32 conv_8bit_to_uni(unsigned char c) |
@@ -777,4 +837,3 @@ console_map_init(void) | |||
777 | con_set_default_unimap(vc_cons[i].d); | 837 | con_set_default_unimap(vc_cons[i].d); |
778 | } | 838 | } |
779 | 839 | ||
780 | EXPORT_SYMBOL(con_copy_unimap); | ||
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 2156188db4a6..84cbf298c094 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c | |||
@@ -3892,36 +3892,6 @@ static void set_palette(struct vc_data *vc) | |||
3892 | vc->vc_sw->con_set_palette(vc, color_table); | 3892 | vc->vc_sw->con_set_palette(vc, color_table); |
3893 | } | 3893 | } |
3894 | 3894 | ||
3895 | static int set_get_cmap(unsigned char __user *arg, int set) | ||
3896 | { | ||
3897 | int i, j, k; | ||
3898 | |||
3899 | WARN_CONSOLE_UNLOCKED(); | ||
3900 | |||
3901 | for (i = 0; i < 16; i++) | ||
3902 | if (set) { | ||
3903 | get_user(default_red[i], arg++); | ||
3904 | get_user(default_grn[i], arg++); | ||
3905 | get_user(default_blu[i], arg++); | ||
3906 | } else { | ||
3907 | put_user(default_red[i], arg++); | ||
3908 | put_user(default_grn[i], arg++); | ||
3909 | put_user(default_blu[i], arg++); | ||
3910 | } | ||
3911 | if (set) { | ||
3912 | for (i = 0; i < MAX_NR_CONSOLES; i++) | ||
3913 | if (vc_cons_allocated(i)) { | ||
3914 | for (j = k = 0; j < 16; j++) { | ||
3915 | vc_cons[i].d->vc_palette[k++] = default_red[j]; | ||
3916 | vc_cons[i].d->vc_palette[k++] = default_grn[j]; | ||
3917 | vc_cons[i].d->vc_palette[k++] = default_blu[j]; | ||
3918 | } | ||
3919 | set_palette(vc_cons[i].d); | ||
3920 | } | ||
3921 | } | ||
3922 | return 0; | ||
3923 | } | ||
3924 | |||
3925 | /* | 3895 | /* |
3926 | * Load palette into the DAC registers. arg points to a colour | 3896 | * Load palette into the DAC registers. arg points to a colour |
3927 | * map, 3 bytes per colour, 16 colours, range from 0 to 255. | 3897 | * map, 3 bytes per colour, 16 colours, range from 0 to 255. |
@@ -3929,24 +3899,50 @@ static int set_get_cmap(unsigned char __user *arg, int set) | |||
3929 | 3899 | ||
3930 | int con_set_cmap(unsigned char __user *arg) | 3900 | int con_set_cmap(unsigned char __user *arg) |
3931 | { | 3901 | { |
3932 | int rc; | 3902 | int i, j, k; |
3903 | unsigned char colormap[3*16]; | ||
3904 | |||
3905 | if (copy_from_user(colormap, arg, sizeof(colormap))) | ||
3906 | return -EFAULT; | ||
3933 | 3907 | ||
3934 | console_lock(); | 3908 | console_lock(); |
3935 | rc = set_get_cmap (arg,1); | 3909 | for (i = k = 0; i < 16; i++) { |
3910 | default_red[i] = colormap[k++]; | ||
3911 | default_grn[i] = colormap[k++]; | ||
3912 | default_blu[i] = colormap[k++]; | ||
3913 | } | ||
3914 | for (i = 0; i < MAX_NR_CONSOLES; i++) { | ||
3915 | if (!vc_cons_allocated(i)) | ||
3916 | continue; | ||
3917 | for (j = k = 0; j < 16; j++) { | ||
3918 | vc_cons[i].d->vc_palette[k++] = default_red[j]; | ||
3919 | vc_cons[i].d->vc_palette[k++] = default_grn[j]; | ||
3920 | vc_cons[i].d->vc_palette[k++] = default_blu[j]; | ||
3921 | } | ||
3922 | set_palette(vc_cons[i].d); | ||
3923 | } | ||
3936 | console_unlock(); | 3924 | console_unlock(); |
3937 | 3925 | ||
3938 | return rc; | 3926 | return 0; |
3939 | } | 3927 | } |
3940 | 3928 | ||
3941 | int con_get_cmap(unsigned char __user *arg) | 3929 | int con_get_cmap(unsigned char __user *arg) |
3942 | { | 3930 | { |
3943 | int rc; | 3931 | int i, k; |
3932 | unsigned char colormap[3*16]; | ||
3944 | 3933 | ||
3945 | console_lock(); | 3934 | console_lock(); |
3946 | rc = set_get_cmap (arg,0); | 3935 | for (i = k = 0; i < 16; i++) { |
3936 | colormap[k++] = default_red[i]; | ||
3937 | colormap[k++] = default_grn[i]; | ||
3938 | colormap[k++] = default_blu[i]; | ||
3939 | } | ||
3947 | console_unlock(); | 3940 | console_unlock(); |
3948 | 3941 | ||
3949 | return rc; | 3942 | if (copy_to_user(arg, colormap, sizeof(colormap))) |
3943 | return -EFAULT; | ||
3944 | |||
3945 | return 0; | ||
3950 | } | 3946 | } |
3951 | 3947 | ||
3952 | void reset_palette(struct vc_data *vc) | 3948 | void reset_palette(struct vc_data *vc) |
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c index ede2ef18d2fb..64618547be11 100644 --- a/drivers/tty/vt/vt_ioctl.c +++ b/drivers/tty/vt/vt_ioctl.c | |||
@@ -910,7 +910,9 @@ int vt_ioctl(struct tty_struct *tty, | |||
910 | ret = con_font_op(vc_cons[fg_console].d, &op); | 910 | ret = con_font_op(vc_cons[fg_console].d, &op); |
911 | if (ret) | 911 | if (ret) |
912 | break; | 912 | break; |
913 | console_lock(); | ||
913 | con_set_default_unimap(vc_cons[fg_console].d); | 914 | con_set_default_unimap(vc_cons[fg_console].d); |
915 | console_unlock(); | ||
914 | break; | 916 | break; |
915 | } | 917 | } |
916 | #endif | 918 | #endif |
@@ -934,33 +936,23 @@ int vt_ioctl(struct tty_struct *tty, | |||
934 | case PIO_SCRNMAP: | 936 | case PIO_SCRNMAP: |
935 | if (!perm) | 937 | if (!perm) |
936 | ret = -EPERM; | 938 | ret = -EPERM; |
937 | else { | 939 | else |
938 | tty_lock(); | ||
939 | ret = con_set_trans_old(up); | 940 | ret = con_set_trans_old(up); |
940 | tty_unlock(); | ||
941 | } | ||
942 | break; | 941 | break; |
943 | 942 | ||
944 | case GIO_SCRNMAP: | 943 | case GIO_SCRNMAP: |
945 | tty_lock(); | ||
946 | ret = con_get_trans_old(up); | 944 | ret = con_get_trans_old(up); |
947 | tty_unlock(); | ||
948 | break; | 945 | break; |
949 | 946 | ||
950 | case PIO_UNISCRNMAP: | 947 | case PIO_UNISCRNMAP: |
951 | if (!perm) | 948 | if (!perm) |
952 | ret = -EPERM; | 949 | ret = -EPERM; |
953 | else { | 950 | else |
954 | tty_lock(); | ||
955 | ret = con_set_trans_new(up); | 951 | ret = con_set_trans_new(up); |
956 | tty_unlock(); | ||
957 | } | ||
958 | break; | 952 | break; |
959 | 953 | ||
960 | case GIO_UNISCRNMAP: | 954 | case GIO_UNISCRNMAP: |
961 | tty_lock(); | ||
962 | ret = con_get_trans_new(up); | 955 | ret = con_get_trans_new(up); |
963 | tty_unlock(); | ||
964 | break; | 956 | break; |
965 | 957 | ||
966 | case PIO_UNIMAPCLR: | 958 | case PIO_UNIMAPCLR: |
@@ -970,19 +962,14 @@ int vt_ioctl(struct tty_struct *tty, | |||
970 | ret = copy_from_user(&ui, up, sizeof(struct unimapinit)); | 962 | ret = copy_from_user(&ui, up, sizeof(struct unimapinit)); |
971 | if (ret) | 963 | if (ret) |
972 | ret = -EFAULT; | 964 | ret = -EFAULT; |
973 | else { | 965 | else |
974 | tty_lock(); | ||
975 | con_clear_unimap(vc, &ui); | 966 | con_clear_unimap(vc, &ui); |
976 | tty_unlock(); | ||
977 | } | ||
978 | break; | 967 | break; |
979 | } | 968 | } |
980 | 969 | ||
981 | case PIO_UNIMAP: | 970 | case PIO_UNIMAP: |
982 | case GIO_UNIMAP: | 971 | case GIO_UNIMAP: |
983 | tty_lock(); | ||
984 | ret = do_unimap_ioctl(cmd, up, perm, vc); | 972 | ret = do_unimap_ioctl(cmd, up, perm, vc); |
985 | tty_unlock(); | ||
986 | break; | 973 | break; |
987 | 974 | ||
988 | case VT_LOCKSWITCH: | 975 | case VT_LOCKSWITCH: |
@@ -1196,9 +1183,7 @@ long vt_compat_ioctl(struct tty_struct *tty, | |||
1196 | 1183 | ||
1197 | case PIO_UNIMAP: | 1184 | case PIO_UNIMAP: |
1198 | case GIO_UNIMAP: | 1185 | case GIO_UNIMAP: |
1199 | tty_lock(); | ||
1200 | ret = compat_unimap_ioctl(cmd, up, perm, vc); | 1186 | ret = compat_unimap_ioctl(cmd, up, perm, vc); |
1201 | tty_unlock(); | ||
1202 | break; | 1187 | break; |
1203 | 1188 | ||
1204 | /* | 1189 | /* |
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 380a87f6e56c..15a42c8c1943 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -94,17 +94,14 @@ struct gs_buf { | |||
94 | * (and thus for each /dev/ node). | 94 | * (and thus for each /dev/ node). |
95 | */ | 95 | */ |
96 | struct gs_port { | 96 | struct gs_port { |
97 | struct tty_port port; | ||
97 | spinlock_t port_lock; /* guard port_* access */ | 98 | spinlock_t port_lock; /* guard port_* access */ |
98 | 99 | ||
99 | struct gserial *port_usb; | 100 | struct gserial *port_usb; |
100 | struct tty_struct *port_tty; | ||
101 | 101 | ||
102 | unsigned open_count; | ||
103 | bool openclose; /* open/close in progress */ | 102 | bool openclose; /* open/close in progress */ |
104 | u8 port_num; | 103 | u8 port_num; |
105 | 104 | ||
106 | wait_queue_head_t close_wait; /* wait for last close */ | ||
107 | |||
108 | struct list_head read_pool; | 105 | struct list_head read_pool; |
109 | int read_started; | 106 | int read_started; |
110 | int read_allocated; | 107 | int read_allocated; |
@@ -412,8 +409,8 @@ __acquires(&port->port_lock) | |||
412 | break; | 409 | break; |
413 | } | 410 | } |
414 | 411 | ||
415 | if (do_tty_wake && port->port_tty) | 412 | if (do_tty_wake && port->port.tty) |
416 | tty_wakeup(port->port_tty); | 413 | tty_wakeup(port->port.tty); |
417 | return status; | 414 | return status; |
418 | } | 415 | } |
419 | 416 | ||
@@ -435,7 +432,7 @@ __acquires(&port->port_lock) | |||
435 | struct tty_struct *tty; | 432 | struct tty_struct *tty; |
436 | 433 | ||
437 | /* no more rx if closed */ | 434 | /* no more rx if closed */ |
438 | tty = port->port_tty; | 435 | tty = port->port.tty; |
439 | if (!tty) | 436 | if (!tty) |
440 | break; | 437 | break; |
441 | 438 | ||
@@ -488,7 +485,7 @@ static void gs_rx_push(unsigned long _port) | |||
488 | 485 | ||
489 | /* hand any queued data to the tty */ | 486 | /* hand any queued data to the tty */ |
490 | spin_lock_irq(&port->port_lock); | 487 | spin_lock_irq(&port->port_lock); |
491 | tty = port->port_tty; | 488 | tty = port->port.tty; |
492 | while (!list_empty(queue)) { | 489 | while (!list_empty(queue)) { |
493 | struct usb_request *req; | 490 | struct usb_request *req; |
494 | 491 | ||
@@ -699,7 +696,7 @@ static int gs_start_io(struct gs_port *port) | |||
699 | 696 | ||
700 | /* unblock any pending writes into our circular buffer */ | 697 | /* unblock any pending writes into our circular buffer */ |
701 | if (started) { | 698 | if (started) { |
702 | tty_wakeup(port->port_tty); | 699 | tty_wakeup(port->port.tty); |
703 | } else { | 700 | } else { |
704 | gs_free_requests(ep, head, &port->read_allocated); | 701 | gs_free_requests(ep, head, &port->read_allocated); |
705 | gs_free_requests(port->port_usb->in, &port->write_pool, | 702 | gs_free_requests(port->port_usb->in, &port->write_pool, |
@@ -734,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
734 | spin_lock_irq(&port->port_lock); | 731 | spin_lock_irq(&port->port_lock); |
735 | 732 | ||
736 | /* already open? Great. */ | 733 | /* already open? Great. */ |
737 | if (port->open_count) { | 734 | if (port->port.count) { |
738 | status = 0; | 735 | status = 0; |
739 | port->open_count++; | 736 | port->port.count++; |
740 | 737 | ||
741 | /* currently opening/closing? wait ... */ | 738 | /* currently opening/closing? wait ... */ |
742 | } else if (port->openclose) { | 739 | } else if (port->openclose) { |
@@ -793,9 +790,9 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
793 | /* REVISIT maybe wait for "carrier detect" */ | 790 | /* REVISIT maybe wait for "carrier detect" */ |
794 | 791 | ||
795 | tty->driver_data = port; | 792 | tty->driver_data = port; |
796 | port->port_tty = tty; | 793 | port->port.tty = tty; |
797 | 794 | ||
798 | port->open_count = 1; | 795 | port->port.count = 1; |
799 | port->openclose = false; | 796 | port->openclose = false; |
800 | 797 | ||
801 | /* if connected, start the I/O stream */ | 798 | /* if connected, start the I/O stream */ |
@@ -837,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
837 | 834 | ||
838 | spin_lock_irq(&port->port_lock); | 835 | spin_lock_irq(&port->port_lock); |
839 | 836 | ||
840 | if (port->open_count != 1) { | 837 | if (port->port.count != 1) { |
841 | if (port->open_count == 0) | 838 | if (port->port.count == 0) |
842 | WARN_ON(1); | 839 | WARN_ON(1); |
843 | else | 840 | else |
844 | --port->open_count; | 841 | --port->port.count; |
845 | goto exit; | 842 | goto exit; |
846 | } | 843 | } |
847 | 844 | ||
@@ -851,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
851 | * and sleep if necessary | 848 | * and sleep if necessary |
852 | */ | 849 | */ |
853 | port->openclose = true; | 850 | port->openclose = true; |
854 | port->open_count = 0; | 851 | port->port.count = 0; |
855 | 852 | ||
856 | gser = port->port_usb; | 853 | gser = port->port_usb; |
857 | if (gser && gser->disconnect) | 854 | if (gser && gser->disconnect) |
@@ -879,14 +876,14 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
879 | gs_buf_clear(&port->port_write_buf); | 876 | gs_buf_clear(&port->port_write_buf); |
880 | 877 | ||
881 | tty->driver_data = NULL; | 878 | tty->driver_data = NULL; |
882 | port->port_tty = NULL; | 879 | port->port.tty = NULL; |
883 | 880 | ||
884 | port->openclose = false; | 881 | port->openclose = false; |
885 | 882 | ||
886 | pr_debug("gs_close: ttyGS%d (%p,%p) done!\n", | 883 | pr_debug("gs_close: ttyGS%d (%p,%p) done!\n", |
887 | port->port_num, tty, file); | 884 | port->port_num, tty, file); |
888 | 885 | ||
889 | wake_up_interruptible(&port->close_wait); | 886 | wake_up_interruptible(&port->port.close_wait); |
890 | exit: | 887 | exit: |
891 | spin_unlock_irq(&port->port_lock); | 888 | spin_unlock_irq(&port->port_lock); |
892 | } | 889 | } |
@@ -1034,8 +1031,8 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) | |||
1034 | if (port == NULL) | 1031 | if (port == NULL) |
1035 | return -ENOMEM; | 1032 | return -ENOMEM; |
1036 | 1033 | ||
1034 | tty_port_init(&port->port); | ||
1037 | spin_lock_init(&port->port_lock); | 1035 | spin_lock_init(&port->port_lock); |
1038 | init_waitqueue_head(&port->close_wait); | ||
1039 | init_waitqueue_head(&port->drain_wait); | 1036 | init_waitqueue_head(&port->drain_wait); |
1040 | 1037 | ||
1041 | tasklet_init(&port->push, gs_rx_push, (unsigned long) port); | 1038 | tasklet_init(&port->push, gs_rx_push, (unsigned long) port); |
@@ -1155,7 +1152,7 @@ static int gs_closed(struct gs_port *port) | |||
1155 | int cond; | 1152 | int cond; |
1156 | 1153 | ||
1157 | spin_lock_irq(&port->port_lock); | 1154 | spin_lock_irq(&port->port_lock); |
1158 | cond = (port->open_count == 0) && !port->openclose; | 1155 | cond = (port->port.count == 0) && !port->openclose; |
1159 | spin_unlock_irq(&port->port_lock); | 1156 | spin_unlock_irq(&port->port_lock); |
1160 | return cond; | 1157 | return cond; |
1161 | } | 1158 | } |
@@ -1194,7 +1191,7 @@ void gserial_cleanup(void) | |||
1194 | tasklet_kill(&port->push); | 1191 | tasklet_kill(&port->push); |
1195 | 1192 | ||
1196 | /* wait for old opens to finish */ | 1193 | /* wait for old opens to finish */ |
1197 | wait_event(port->close_wait, gs_closed(port)); | 1194 | wait_event(port->port.close_wait, gs_closed(port)); |
1198 | 1195 | ||
1199 | WARN_ON(port->port_usb != NULL); | 1196 | WARN_ON(port->port_usb != NULL); |
1200 | 1197 | ||
@@ -1268,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num) | |||
1268 | /* if it's already open, start I/O ... and notify the serial | 1265 | /* if it's already open, start I/O ... and notify the serial |
1269 | * protocol about open/close status (connect/disconnect). | 1266 | * protocol about open/close status (connect/disconnect). |
1270 | */ | 1267 | */ |
1271 | if (port->open_count) { | 1268 | if (port->port.count) { |
1272 | pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); | 1269 | pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); |
1273 | gs_start_io(port); | 1270 | gs_start_io(port); |
1274 | if (gser->connect) | 1271 | if (gser->connect) |
@@ -1315,10 +1312,10 @@ void gserial_disconnect(struct gserial *gser) | |||
1315 | 1312 | ||
1316 | port->port_usb = NULL; | 1313 | port->port_usb = NULL; |
1317 | gser->ioport = NULL; | 1314 | gser->ioport = NULL; |
1318 | if (port->open_count > 0 || port->openclose) { | 1315 | if (port->port.count > 0 || port->openclose) { |
1319 | wake_up_interruptible(&port->drain_wait); | 1316 | wake_up_interruptible(&port->drain_wait); |
1320 | if (port->port_tty) | 1317 | if (port->port.tty) |
1321 | tty_hangup(port->port_tty); | 1318 | tty_hangup(port->port.tty); |
1322 | } | 1319 | } |
1323 | spin_unlock_irqrestore(&port->port_lock, flags); | 1320 | spin_unlock_irqrestore(&port->port_lock, flags); |
1324 | 1321 | ||
@@ -1331,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser) | |||
1331 | 1328 | ||
1332 | /* finally, free any unused/unusable I/O buffers */ | 1329 | /* finally, free any unused/unusable I/O buffers */ |
1333 | spin_lock_irqsave(&port->port_lock, flags); | 1330 | spin_lock_irqsave(&port->port_lock, flags); |
1334 | if (port->open_count == 0 && !port->openclose) | 1331 | if (port->port.count == 0 && !port->openclose) |
1335 | gs_buf_free(&port->port_write_buf); | 1332 | gs_buf_free(&port->port_write_buf); |
1336 | gs_free_requests(gser->out, &port->read_pool, NULL); | 1333 | gs_free_requests(gser->out, &port->read_pool, NULL); |
1337 | gs_free_requests(gser->out, &port->read_queue, NULL); | 1334 | gs_free_requests(gser->out, &port->read_queue, NULL); |