Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'tty-3.3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty

Pull TTY/serial patches from Greg KH:
"tty and serial merge for 3.4-rc1

Here's the big serial and tty merge for the 3.4-rc1 tree.

There's loads of fixes and reworks in here from Jiri for the tty
layer, and a number of patches from Alan to help try to wrestle the vt
layer into a sane model.

Other than that, lots of driver updates and fixes, and other minor
stuff, all detailed in the shortlog."

* tag 'tty-3.3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (132 commits)
serial: pxa: add clk_prepare/clk_unprepare calls
TTY: Wrong unicode value copied in con_set_unimap()
serial: PL011: clear pending interrupts
serial: bfin-uart: Don't access tty circular buffer in TX DMA interrupt after it is reset.
vt: NULL dereference in vt_do_kdsk_ioctl()
tty: serial: vt8500: fix annotations for probe/remove
serial: remove back and forth conversions in serial_out_sync
serial: use serial_port_in/out vs serial_in/out in 8250
serial: introduce generic port in/out helpers
serial: reduce number of indirections in 8250 code
serial: delete useless void casts in 8250.c
serial: make 8250's serial_in shareable to other drivers.
serial: delete last unused traces of pausing I/O in 8250
pch_uart: Add module parameter descriptions
pch_uart: Use existing default_baud in setup_console
pch_uart: Add user_uartclk parameter
pch_uart: Add Fish River Island II uart clock quirks
pch_uart: Use uartclk instead of base_baud
mpc5200b/uart: select more tolerant uart prescaler on low baudrates
tty: moxa: fix bit test in moxa_start()
...

+3206 -3138
+14
Documentation/devicetree/bindings/tty/serial/efm32-uart.txt
··· 1 + * Energymicro efm32 UART 2 + 3 + Required properties: 4 + - compatible : Should be "efm32,uart" 5 + - reg : Address and length of the register set 6 + - interrupts : Should contain uart interrupt 7 + 8 + Example: 9 + 10 + uart@0x4000c400 { 11 + compatible = "efm32,uart"; 12 + reg = <0x4000c400 0x400>; 13 + interrupts = <15>; 14 + };
+1 -1
MAINTAINERS
··· 6212 6212 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6.git 6213 6213 T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-next-2.6.git 6214 6214 S: Maintained 6215 + F: include/linux/sunserialcore.h 6215 6216 F: drivers/tty/serial/suncore.c 6216 - F: drivers/tty/serial/suncore.h 6217 6217 F: drivers/tty/serial/sunhv.c 6218 6218 F: drivers/tty/serial/sunsab.c 6219 6219 F: drivers/tty/serial/sunsab.h
+23 -55
arch/alpha/kernel/srmcons.c
··· 30 30 #define MAX_SRM_CONSOLE_DEVICES 1 /* only support 1 console device */ 31 31 32 32 struct srmcons_private { 33 - struct tty_struct *tty; 33 + struct tty_port port; 34 34 struct timer_list timer; 35 - spinlock_t lock; 36 - }; 35 + } srmcons_singleton; 37 36 38 37 typedef union _srmcons_result { 39 38 struct { ··· 67 68 srmcons_receive_chars(unsigned long data) 68 69 { 69 70 struct srmcons_private *srmconsp = (struct srmcons_private *)data; 71 + struct tty_port *port = &srmconsp->port; 70 72 unsigned long flags; 71 73 int incr = 10; 72 74 73 75 local_irq_save(flags); 74 76 if (spin_trylock(&srmcons_callback_lock)) { 75 - if (!srmcons_do_receive_chars(srmconsp->tty)) 77 + if (!srmcons_do_receive_chars(port->tty)) 76 78 incr = 100; 77 79 spin_unlock(&srmcons_callback_lock); 78 80 } 79 81 80 - spin_lock(&srmconsp->lock); 81 - if (srmconsp->tty) { 82 - srmconsp->timer.expires = jiffies + incr; 83 - add_timer(&srmconsp->timer); 84 - } 85 - spin_unlock(&srmconsp->lock); 82 + spin_lock(&port->lock); 83 + if (port->tty) 84 + mod_timer(&srmconsp->timer, jiffies + incr); 85 + spin_unlock(&port->lock); 86 86 87 87 local_irq_restore(flags); 88 88 } ··· 154 156 } 155 157 156 158 static int 157 - srmcons_get_private_struct(struct srmcons_private **ps) 158 - { 159 - static struct srmcons_private *srmconsp = NULL; 160 - static DEFINE_SPINLOCK(srmconsp_lock); 161 - unsigned long flags; 162 - int retval = 0; 163 - 164 - if (srmconsp == NULL) { 165 - srmconsp = kmalloc(sizeof(*srmconsp), GFP_KERNEL); 166 - spin_lock_irqsave(&srmconsp_lock, flags); 167 - 168 - if (srmconsp == NULL) 169 - retval = -ENOMEM; 170 - else { 171 - srmconsp->tty = NULL; 172 - spin_lock_init(&srmconsp->lock); 173 - init_timer(&srmconsp->timer); 174 - } 175 - 176 - spin_unlock_irqrestore(&srmconsp_lock, flags); 177 - } 178 - 179 - *ps = srmconsp; 180 - return retval; 181 - } 182 - 183 - static int 184 159 srmcons_open(struct tty_struct *tty, struct file *filp) 185 160 { 186 - struct srmcons_private *srmconsp; 161 + struct srmcons_private *srmconsp = &srmcons_singleton; 162 + struct tty_port *port = &srmconsp->port; 187 163 unsigned long flags; 188 - int retval; 189 164 190 - retval = srmcons_get_private_struct(&srmconsp); 191 - if (retval) 192 - return retval; 165 + spin_lock_irqsave(&port->lock, flags); 193 166 194 - spin_lock_irqsave(&srmconsp->lock, flags); 195 - 196 - if (!srmconsp->tty) { 167 + if (!port->tty) { 197 168 tty->driver_data = srmconsp; 198 - 199 - srmconsp->tty = tty; 200 - srmconsp->timer.function = srmcons_receive_chars; 201 - srmconsp->timer.data = (unsigned long)srmconsp; 202 - srmconsp->timer.expires = jiffies + 10; 203 - add_timer(&srmconsp->timer); 169 + tty->port = port; 170 + port->tty = tty; /* XXX proper refcounting */ 171 + mod_timer(&srmconsp->timer, jiffies + 10); 204 172 } 205 173 206 - spin_unlock_irqrestore(&srmconsp->lock, flags); 174 + spin_unlock_irqrestore(&port->lock, flags); 207 175 208 176 return 0; 209 177 } ··· 178 214 srmcons_close(struct tty_struct *tty, struct file *filp) 179 215 { 180 216 struct srmcons_private *srmconsp = tty->driver_data; 217 + struct tty_port *port = &srmconsp->port; 181 218 unsigned long flags; 182 219 183 - spin_lock_irqsave(&srmconsp->lock, flags); 220 + spin_lock_irqsave(&port->lock, flags); 184 221 185 222 if (tty->count == 1) { 186 - srmconsp->tty = NULL; 223 + port->tty = NULL; 187 224 del_timer(&srmconsp->timer); 188 225 } 189 226 190 - spin_unlock_irqrestore(&srmconsp->lock, flags); 227 + spin_unlock_irqrestore(&port->lock, flags); 191 228 } 192 229 193 230 ··· 205 240 static int __init 206 241 srmcons_init(void) 207 242 { 243 + tty_port_init(&srmcons_singleton.port); 244 + setup_timer(&srmcons_singleton.timer, srmcons_receive_chars, 245 + (unsigned long)&srmcons_singleton); 208 246 if (srm_is_registered_console) { 209 247 struct tty_driver *driver; 210 248 int err;
+4 -13
arch/ia64/hp/sim/boot/fw-emu.c
··· 160 160 */ 161 161 status = 0; 162 162 if (index == SAL_FREQ_BASE) { 163 - switch (in1) { 164 - case SAL_FREQ_BASE_PLATFORM: 163 + if (in1 == SAL_FREQ_BASE_PLATFORM) 165 164 r9 = 200000000; 166 - break; 167 - 168 - case SAL_FREQ_BASE_INTERVAL_TIMER: 165 + else if (in1 == SAL_FREQ_BASE_INTERVAL_TIMER) { 169 166 /* 170 167 * Is this supposed to be the cr.itc frequency 171 168 * or something platform specific? The SAL 172 169 * doc ain't exactly clear on this... 173 170 */ 174 171 r9 = 700000000; 175 - break; 176 - 177 - case SAL_FREQ_BASE_REALTIME_CLOCK: 172 + } else if (in1 == SAL_FREQ_BASE_REALTIME_CLOCK) 178 173 r9 = 1; 179 - break; 180 - 181 - default: 174 + else 182 175 status = -1; 183 - break; 184 - } 185 176 } else if (index == SAL_SET_VECTORS) { 186 177 ; 187 178 } else if (index == SAL_GET_STATE_INFO) {
+30 -6
arch/ia64/hp/sim/hpsim_irq.c
··· 10 10 #include <linux/sched.h> 11 11 #include <linux/irq.h> 12 12 13 + #include "hpsim_ssc.h" 14 + 13 15 static unsigned int 14 16 hpsim_irq_startup(struct irq_data *data) 15 17 { ··· 39 37 .irq_set_affinity = hpsim_set_affinity_noop, 40 38 }; 41 39 40 + static void hpsim_irq_set_chip(int irq) 41 + { 42 + struct irq_chip *chip = irq_get_chip(irq); 43 + 44 + if (chip == &no_irq_chip) 45 + irq_set_chip(irq, &irq_type_hp_sim); 46 + } 47 + 48 + static void hpsim_connect_irq(int intr, int irq) 49 + { 50 + ia64_ssc(intr, irq, 0, 0, SSC_CONNECT_INTERRUPT); 51 + } 52 + 53 + int hpsim_get_irq(int intr) 54 + { 55 + int irq = assign_irq_vector(AUTO_ASSIGN); 56 + 57 + if (irq >= 0) { 58 + hpsim_irq_set_chip(irq); 59 + irq_set_handler(irq, handle_simple_irq); 60 + hpsim_connect_irq(intr, irq); 61 + } 62 + 63 + return irq; 64 + } 65 + 42 66 void __init 43 67 hpsim_irq_init (void) 44 68 { 45 69 int i; 46 70 47 - for_each_active_irq(i) { 48 - struct irq_chip *chip = irq_get_chip(i); 49 - 50 - if (chip == &no_irq_chip) 51 - irq_set_chip(i, &irq_type_hp_sim); 52 - } 71 + for_each_active_irq(i) 72 + hpsim_irq_set_chip(i); 53 73 }
-6
arch/ia64/hp/sim/hpsim_setup.c
··· 26 26 #include "hpsim_ssc.h" 27 27 28 28 void 29 - ia64_ssc_connect_irq (long intr, long irq) 30 - { 31 - ia64_ssc(intr, irq, 0, 0, SSC_CONNECT_INTERRUPT); 32 - } 33 - 34 - void 35 29 ia64_ctl_trace (long on) 36 30 { 37 31 ia64_ssc(on, 0, 0, 0, SSC_CTL_TRACE);
+3 -16
arch/ia64/hp/sim/simeth.c
··· 129 129 130 130 131 131 static inline int 132 - netdev_connect(int irq) 133 - { 134 - /* XXX Fix me 135 - * this does not support multiple cards 136 - * also no return value 137 - */ 138 - ia64_ssc_connect_irq(NETWORK_INTR, irq); 139 - return 0; 140 - } 141 - 142 - static inline int 143 132 netdev_attach(int fd, int irq, unsigned int ipaddr) 144 133 { 145 134 /* this puts the host interface in the right mode (start interrupting) */ ··· 215 226 return err; 216 227 } 217 228 218 - if ((rc = assign_irq_vector(AUTO_ASSIGN)) < 0) 219 - panic("%s: out of interrupt vectors!\n", __func__); 220 - dev->irq = rc; 221 - 222 229 /* 223 230 * attach the interrupt in the simulator, this does enable interrupts 224 231 * until a netdev_attach() is called 225 232 */ 226 - netdev_connect(dev->irq); 233 + if ((rc = hpsim_get_irq(NETWORK_INTR)) < 0) 234 + panic("%s: out of interrupt vectors!\n", __func__); 235 + dev->irq = rc; 227 236 228 237 printk(KERN_INFO "%s: hosteth=%s simfd=%d, HwAddr", 229 238 dev->name, simeth_device, local->simfd);
+148 -559
arch/ia64/hp/sim/simserial.c
··· 4 4 * This driver is mostly used for bringup purposes and will go away. 5 5 * It has a strong dependency on the system console. All outputs 6 6 * are rerouted to the same facility as the one used by printk which, in our 7 - * case means sys_sim.c console (goes via the simulator). The code hereafter 8 - * is completely leveraged from the serial.c driver. 7 + * case means sys_sim.c console (goes via the simulator). 9 8 * 10 9 * Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co 11 10 * Stephane Eranian <eranian@hpl.hp.com> 12 11 * David Mosberger-Tang <davidm@hpl.hp.com> 13 - * 14 - * 02/04/00 D. Mosberger Merged in serial.c bug fixes in rs_close(). 15 - * 02/25/00 D. Mosberger Synced up with 2.3.99pre-5 version of serial.c. 16 - * 07/30/02 D. Mosberger Replace sti()/cli() with explicit spinlocks & local irq masking 17 12 */ 18 13 19 14 #include <linux/init.h> ··· 22 27 #include <linux/seq_file.h> 23 28 #include <linux/slab.h> 24 29 #include <linux/capability.h> 30 + #include <linux/circ_buf.h> 25 31 #include <linux/console.h> 32 + #include <linux/irq.h> 26 33 #include <linux/module.h> 27 34 #include <linux/serial.h> 28 - #include <linux/serialP.h> 29 35 #include <linux/sysrq.h> 36 + #include <linux/uaccess.h> 30 37 31 - #include <asm/irq.h> 32 - #include <asm/hw_irq.h> 33 - #include <asm/uaccess.h> 38 + #include <asm/hpsim.h> 39 + 40 + #include "hpsim_ssc.h" 34 41 35 42 #undef SIMSERIAL_DEBUG /* define this to get some debug information */ 36 43 ··· 40 43 41 44 #define NR_PORTS 1 /* only one port for now */ 42 45 43 - #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : IRQF_DISABLED) 44 - 45 - #define SSC_GETCHAR 21 46 - 47 - extern long ia64_ssc (long, long, long, long, int); 48 - extern void ia64_ssc_connect_irq (long intr, long irq); 49 - 50 - static char *serial_name = "SimSerial driver"; 51 - static char *serial_version = "0.6"; 52 - 53 - /* 54 - * This has been extracted from asm/serial.h. We need one eventually but 55 - * I don't know exactly what we're going to put in it so just fake one 56 - * for now. 57 - */ 58 - #define BASE_BAUD ( 1843200 / 16 ) 59 - 60 - #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST) 61 - 62 - /* 63 - * Most of the values here are meaningless to this particular driver. 64 - * However some values must be preserved for the code (leveraged from serial.c 65 - * to work correctly). 66 - * port must not be 0 67 - * type must not be UNKNOWN 68 - * So I picked arbitrary (guess from where?) values instead 69 - */ 70 - static struct serial_state rs_table[NR_PORTS]={ 71 - /* UART CLK PORT IRQ FLAGS */ 72 - { 0, BASE_BAUD, 0x3F8, 0, STD_COM_FLAGS,0,PORT_16550 } /* ttyS0 */ 46 + struct serial_state { 47 + struct tty_port port; 48 + struct circ_buf xmit; 49 + int irq; 50 + int x_char; 73 51 }; 74 52 75 - /* 76 - * Just for the fun of it ! 77 - */ 78 - static struct serial_uart_config uart_config[] = { 79 - { "unknown", 1, 0 }, 80 - { "8250", 1, 0 }, 81 - { "16450", 1, 0 }, 82 - { "16550", 1, 0 }, 83 - { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO }, 84 - { "cirrus", 1, 0 }, 85 - { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH }, 86 - { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO | 87 - UART_STARTECH }, 88 - { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO}, 89 - { NULL, 0} 90 - }; 53 + static struct serial_state rs_table[NR_PORTS]; 91 54 92 55 struct tty_driver *hp_simserial_driver; 93 56 94 - static struct async_struct *IRQ_ports[NR_IRQS]; 95 - 96 57 static struct console *console; 97 58 98 - static unsigned char *tmp_buf; 99 - 100 - extern struct console *console_drivers; /* from kernel/printk.c */ 101 - 102 - /* 103 - * ------------------------------------------------------------ 104 - * rs_stop() and rs_start() 105 - * 106 - * This routines are called before setting or resetting tty->stopped. 107 - * They enable or disable transmitter interrupts, as necessary. 108 - * ------------------------------------------------------------ 109 - */ 110 - static void rs_stop(struct tty_struct *tty) 111 - { 112 - #ifdef SIMSERIAL_DEBUG 113 - printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n", 114 - tty->stopped, tty->hw_stopped, tty->flow_stopped); 115 - #endif 116 - 117 - } 118 - 119 - static void rs_start(struct tty_struct *tty) 120 - { 121 - #ifdef SIMSERIAL_DEBUG 122 - printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n", 123 - tty->stopped, tty->hw_stopped, tty->flow_stopped); 124 - #endif 125 - } 126 - 127 - static void receive_chars(struct tty_struct *tty) 59 + static void receive_chars(struct tty_struct *tty) 128 60 { 129 61 unsigned char ch; 130 62 static unsigned char seen_esc = 0; 131 63 132 64 while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) { 133 - if ( ch == 27 && seen_esc == 0 ) { 65 + if (ch == 27 && seen_esc == 0) { 134 66 seen_esc = 1; 135 67 continue; 136 - } else { 137 - if ( seen_esc==1 && ch == 'O' ) { 138 - seen_esc = 2; 139 - continue; 140 - } else if ( seen_esc == 2 ) { 141 - if ( ch == 'P' ) /* F1 */ 142 - show_state(); 68 + } else if (seen_esc == 1 && ch == 'O') { 69 + seen_esc = 2; 70 + continue; 71 + } else if (seen_esc == 2) { 72 + if (ch == 'P') /* F1 */ 73 + show_state(); 143 74 #ifdef CONFIG_MAGIC_SYSRQ 144 - if ( ch == 'S' ) { /* F4 */ 145 - do 146 - ch = ia64_ssc(0, 0, 0, 0, 147 - SSC_GETCHAR); 148 - while (!ch); 149 - handle_sysrq(ch); 150 - } 151 - #endif 152 - seen_esc = 0; 153 - continue; 75 + if (ch == 'S') { /* F4 */ 76 + do { 77 + ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR); 78 + } while (!ch); 79 + handle_sysrq(ch); 154 80 } 81 + #endif 82 + seen_esc = 0; 83 + continue; 155 84 } 156 85 seen_esc = 0; 157 86 ··· 92 169 */ 93 170 static irqreturn_t rs_interrupt_single(int irq, void *dev_id) 94 171 { 95 - struct async_struct * info; 172 + struct serial_state *info = dev_id; 173 + struct tty_struct *tty = tty_port_tty_get(&info->port); 96 174 97 - /* 98 - * I don't know exactly why they don't use the dev_id opaque data 99 - * pointer instead of this extra lookup table 100 - */ 101 - info = IRQ_ports[irq]; 102 - if (!info || !info->tty) { 103 - printk(KERN_INFO "simrs_interrupt_single: info|tty=0 info=%p problem\n", info); 175 + if (!tty) { 176 + printk(KERN_INFO "%s: tty=0 problem\n", __func__); 104 177 return IRQ_NONE; 105 178 } 106 179 /* 107 180 * pretty simple in our case, because we only get interrupts 108 181 * on inbound traffic 109 182 */ 110 - receive_chars(info->tty); 183 + receive_chars(tty); 184 + tty_kref_put(tty); 111 185 return IRQ_HANDLED; 112 186 } 113 187 ··· 114 194 * ------------------------------------------------------------------- 115 195 */ 116 196 117 - static void do_softint(struct work_struct *private_) 118 - { 119 - printk(KERN_ERR "simserial: do_softint called\n"); 120 - } 121 - 122 197 static int rs_put_char(struct tty_struct *tty, unsigned char ch) 123 198 { 124 - struct async_struct *info = (struct async_struct *)tty->driver_data; 199 + struct serial_state *info = tty->driver_data; 125 200 unsigned long flags; 126 201 127 - if (!tty || !info->xmit.buf) 202 + if (!info->xmit.buf) 128 203 return 0; 129 204 130 205 local_irq_save(flags); ··· 133 218 return 1; 134 219 } 135 220 136 - static void transmit_chars(struct async_struct *info, int *intr_done) 221 + static void transmit_chars(struct tty_struct *tty, struct serial_state *info, 222 + int *intr_done) 137 223 { 138 224 int count; 139 225 unsigned long flags; 140 - 141 226 142 227 local_irq_save(flags); 143 228 ··· 146 231 147 232 console->write(console, &c, 1); 148 233 149 - info->state->icount.tx++; 150 234 info->x_char = 0; 151 235 152 236 goto out; 153 237 } 154 238 155 - if (info->xmit.head == info->xmit.tail || info->tty->stopped || info->tty->hw_stopped) { 239 + if (info->xmit.head == info->xmit.tail || tty->stopped || 240 + tty->hw_stopped) { 156 241 #ifdef SIMSERIAL_DEBUG 157 242 printk("transmit_chars: head=%d, tail=%d, stopped=%d\n", 158 - info->xmit.head, info->xmit.tail, info->tty->stopped); 243 + info->xmit.head, info->xmit.tail, tty->stopped); 159 244 #endif 160 245 goto out; 161 246 } ··· 187 272 188 273 static void rs_flush_chars(struct tty_struct *tty) 189 274 { 190 - struct async_struct *info = (struct async_struct *)tty->driver_data; 275 + struct serial_state *info = tty->driver_data; 191 276 192 - if (info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped || 193 - !info->xmit.buf) 277 + if (info->xmit.head == info->xmit.tail || tty->stopped || 278 + tty->hw_stopped || !info->xmit.buf) 194 279 return; 195 280 196 - transmit_chars(info, NULL); 281 + transmit_chars(tty, info, NULL); 197 282 } 198 - 199 283 200 284 static int rs_write(struct tty_struct * tty, 201 285 const unsigned char *buf, int count) 202 286 { 287 + struct serial_state *info = tty->driver_data; 203 288 int c, ret = 0; 204 - struct async_struct *info = (struct async_struct *)tty->driver_data; 205 289 unsigned long flags; 206 290 207 - if (!tty || !info->xmit.buf || !tmp_buf) return 0; 291 + if (!info->xmit.buf) 292 + return 0; 208 293 209 294 local_irq_save(flags); 210 295 while (1) { ··· 225 310 /* 226 311 * Hey, we transmit directly from here in our case 227 312 */ 228 - if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) 229 - && !tty->stopped && !tty->hw_stopped) { 230 - transmit_chars(info, NULL); 231 - } 313 + if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) && 314 + !tty->stopped && !tty->hw_stopped) 315 + transmit_chars(tty, info, NULL); 316 + 232 317 return ret; 233 318 } 234 319 235 320 static int rs_write_room(struct tty_struct *tty) 236 321 { 237 - struct async_struct *info = (struct async_struct *)tty->driver_data; 322 + struct serial_state *info = tty->driver_data; 238 323 239 324 return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); 240 325 } 241 326 242 327 static int rs_chars_in_buffer(struct tty_struct *tty) 243 328 { 244 - struct async_struct *info = (struct async_struct *)tty->driver_data; 329 + struct serial_state *info = tty->driver_data; 245 330 246 331 return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE); 247 332 } 248 333 249 334 static void rs_flush_buffer(struct tty_struct *tty) 250 335 { 251 - struct async_struct *info = (struct async_struct *)tty->driver_data; 336 + struct serial_state *info = tty->driver_data; 252 337 unsigned long flags; 253 338 254 339 local_irq_save(flags); ··· 264 349 */ 265 350 static void rs_send_xchar(struct tty_struct *tty, char ch) 266 351 { 267 - struct async_struct *info = (struct async_struct *)tty->driver_data; 352 + struct serial_state *info = tty->driver_data; 268 353 269 354 info->x_char = ch; 270 355 if (ch) { ··· 272 357 * I guess we could call console->write() directly but 273 358 * let's do that for now. 274 359 */ 275 - transmit_chars(info, NULL); 360 + transmit_chars(tty, info, NULL); 276 361 } 277 362 } 278 363 ··· 286 371 */ 287 372 static void rs_throttle(struct tty_struct * tty) 288 373 { 289 - if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty)); 374 + if (I_IXOFF(tty)) 375 + rs_send_xchar(tty, STOP_CHAR(tty)); 290 376 291 377 printk(KERN_INFO "simrs_throttle called\n"); 292 378 } 293 379 294 380 static void rs_unthrottle(struct tty_struct * tty) 295 381 { 296 - struct async_struct *info = (struct async_struct *)tty->driver_data; 382 + struct serial_state *info = tty->driver_data; 297 383 298 384 if (I_IXOFF(tty)) { 299 385 if (info->x_char) ··· 304 388 } 305 389 printk(KERN_INFO "simrs_unthrottle called\n"); 306 390 } 307 - 308 391 309 392 static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) 310 393 { ··· 315 400 } 316 401 317 402 switch (cmd) { 318 - case TIOCGSERIAL: 319 - printk(KERN_INFO "simrs_ioctl TIOCGSERIAL called\n"); 320 - return 0; 321 - case TIOCSSERIAL: 322 - printk(KERN_INFO "simrs_ioctl TIOCSSERIAL called\n"); 323 - return 0; 324 - case TIOCSERCONFIG: 325 - printk(KERN_INFO "rs_ioctl: TIOCSERCONFIG called\n"); 326 - return -EINVAL; 327 - 328 - case TIOCSERGETLSR: /* Get line status register */ 329 - printk(KERN_INFO "rs_ioctl: TIOCSERGETLSR called\n"); 330 - return -EINVAL; 331 - 332 - case TIOCSERGSTRUCT: 333 - printk(KERN_INFO "rs_ioctl: TIOCSERGSTRUCT called\n"); 334 - #if 0 335 - if (copy_to_user((struct async_struct *) arg, 336 - info, sizeof(struct async_struct))) 337 - return -EFAULT; 338 - #endif 339 - return 0; 340 - 341 - /* 342 - * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 343 - * - mask passed in arg for lines of interest 344 - * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 345 - * Caller should use TIOCGICOUNT to see which one it was 346 - */ 347 - case TIOCMIWAIT: 348 - printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n"); 349 - return 0; 350 - case TIOCSERGWILD: 351 - case TIOCSERSWILD: 352 - /* "setserial -W" is called in Debian boot */ 353 - printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n"); 354 - return 0; 355 - 356 - default: 357 - return -ENOIOCTLCMD; 358 - } 359 - return 0; 403 + case TIOCGSERIAL: 404 + case TIOCSSERIAL: 405 + case TIOCSERGSTRUCT: 406 + case TIOCMIWAIT: 407 + return 0; 408 + case TIOCSERCONFIG: 409 + case TIOCSERGETLSR: /* Get line status register */ 410 + return -EINVAL; 411 + case TIOCSERGWILD: 412 + case TIOCSERSWILD: 413 + /* "setserial -W" is called in Debian boot */ 414 + printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n"); 415 + return 0; 416 + } 417 + return -ENOIOCTLCMD; 360 418 } 361 419 362 420 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) ··· 340 452 if ((old_termios->c_cflag & CRTSCTS) && 341 453 !(tty->termios->c_cflag & CRTSCTS)) { 342 454 tty->hw_stopped = 0; 343 - rs_start(tty); 344 455 } 345 456 } 346 457 /* 347 458 * This routine will shutdown a serial port; interrupts are disabled, and 348 459 * DTR is dropped if the hangup on close termio flag is on. 349 460 */ 350 - static void shutdown(struct async_struct * info) 461 + static void shutdown(struct tty_port *port) 351 462 { 352 - unsigned long flags; 353 - struct serial_state *state; 354 - int retval; 355 - 356 - if (!(info->flags & ASYNC_INITIALIZED)) return; 357 - 358 - state = info->state; 359 - 360 - #ifdef SIMSERIAL_DEBUG 361 - printk("Shutting down serial port %d (irq %d)....", info->line, 362 - state->irq); 363 - #endif 463 + struct serial_state *info = container_of(port, struct serial_state, 464 + port); 465 + unsigned long flags; 364 466 365 467 local_irq_save(flags); 366 - { 367 - /* 368 - * First unlink the serial port from the IRQ chain... 369 - */ 370 - if (info->next_port) 371 - info->next_port->prev_port = info->prev_port; 372 - if (info->prev_port) 373 - info->prev_port->next_port = info->next_port; 374 - else 375 - IRQ_ports[state->irq] = info->next_port; 468 + if (info->irq) 469 + free_irq(info->irq, info); 376 470 377 - /* 378 - * Free the IRQ, if necessary 379 - */ 380 - if (state->irq && (!IRQ_ports[state->irq] || 381 - !IRQ_ports[state->irq]->next_port)) { 382 - if (IRQ_ports[state->irq]) { 383 - free_irq(state->irq, NULL); 384 - retval = request_irq(state->irq, rs_interrupt_single, 385 - IRQ_T(info), "serial", NULL); 386 - 387 - if (retval) 388 - printk(KERN_ERR "serial shutdown: request_irq: error %d" 389 - " Couldn't reacquire IRQ.\n", retval); 390 - } else 391 - free_irq(state->irq, NULL); 392 - } 393 - 394 - if (info->xmit.buf) { 395 - free_page((unsigned long) info->xmit.buf); 396 - info->xmit.buf = NULL; 397 - } 398 - 399 - if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags); 400 - 401 - info->flags &= ~ASYNC_INITIALIZED; 471 + if (info->xmit.buf) { 472 + free_page((unsigned long) info->xmit.buf); 473 + info->xmit.buf = NULL; 402 474 } 403 475 local_irq_restore(flags); 404 476 } 405 477 406 - /* 407 - * ------------------------------------------------------------ 408 - * rs_close() 409 - * 410 - * This routine is called when the serial port gets closed. First, we 411 - * wait for the last remaining data to be sent. Then, we unlink its 412 - * async structure from the interrupt chain if necessary, and we free 413 - * that IRQ if nothing is left in the chain. 414 - * ------------------------------------------------------------ 415 - */ 416 478 static void rs_close(struct tty_struct *tty, struct file * filp) 417 479 { 418 - struct async_struct * info = (struct async_struct *)tty->driver_data; 419 - struct serial_state *state; 420 - unsigned long flags; 480 + struct serial_state *info = tty->driver_data; 421 481 422 - if (!info ) return; 423 - 424 - state = info->state; 425 - 426 - local_irq_save(flags); 427 - if (tty_hung_up_p(filp)) { 428 - #ifdef SIMSERIAL_DEBUG 429 - printk("rs_close: hung_up\n"); 430 - #endif 431 - local_irq_restore(flags); 432 - return; 433 - } 434 - #ifdef SIMSERIAL_DEBUG 435 - printk("rs_close ttys%d, count = %d\n", info->line, state->count); 436 - #endif 437 - if ((tty->count == 1) && (state->count != 1)) { 438 - /* 439 - * Uh, oh. tty->count is 1, which means that the tty 440 - * structure will be freed. state->count should always 441 - * be one in these conditions. If it's greater than 442 - * one, we've got real problems, since it means the 443 - * serial port won't be shutdown. 444 - */ 445 - printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, " 446 - "state->count is %d\n", state->count); 447 - state->count = 1; 448 - } 449 - if (--state->count < 0) { 450 - printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n", 451 - info->line, state->count); 452 - state->count = 0; 453 - } 454 - if (state->count) { 455 - local_irq_restore(flags); 456 - return; 457 - } 458 - info->flags |= ASYNC_CLOSING; 459 - local_irq_restore(flags); 460 - 461 - /* 462 - * Now we wait for the transmit buffer to clear; and we notify 463 - * the line discipline to only process XON/XOFF characters. 464 - */ 465 - shutdown(info); 466 - rs_flush_buffer(tty); 467 - tty_ldisc_flush(tty); 468 - info->event = 0; 469 - info->tty = NULL; 470 - if (info->blocked_open) { 471 - if (info->close_delay) 472 - schedule_timeout_interruptible(info->close_delay); 473 - wake_up_interruptible(&info->open_wait); 474 - } 475 - info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 476 - wake_up_interruptible(&info->close_wait); 482 + tty_port_close(&info->port, tty, filp); 477 483 } 478 484 479 - /* 480 - * rs_wait_until_sent() --- wait until the transmitter is empty 481 - */ 482 - static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 483 - { 484 - } 485 - 486 - 487 - /* 488 - * rs_hangup() --- called by tty_hangup() when a hangup is signaled. 489 - */ 490 485 static void rs_hangup(struct tty_struct *tty) 491 486 { 492 - struct async_struct * info = (struct async_struct *)tty->driver_data; 493 - struct serial_state *state = info->state; 494 - 495 - #ifdef SIMSERIAL_DEBUG 496 - printk("rs_hangup: called\n"); 497 - #endif 498 - 499 - state = info->state; 487 + struct serial_state *info = tty->driver_data; 500 488 501 489 rs_flush_buffer(tty); 502 - if (info->flags & ASYNC_CLOSING) 503 - return; 504 - shutdown(info); 505 - 506 - info->event = 0; 507 - state->count = 0; 508 - info->flags &= ~ASYNC_NORMAL_ACTIVE; 509 - info->tty = NULL; 510 - wake_up_interruptible(&info->open_wait); 490 + tty_port_hangup(&info->port); 511 491 } 512 492 513 - 514 - static int get_async_struct(int line, struct async_struct **ret_info) 493 + static int activate(struct tty_port *port, struct tty_struct *tty) 515 494 { 516 - struct async_struct *info; 517 - struct serial_state *sstate; 518 - 519 - sstate = rs_table + line; 520 - sstate->count++; 521 - if (sstate->info) { 522 - *ret_info = sstate->info; 523 - return 0; 524 - } 525 - info = kzalloc(sizeof(struct async_struct), GFP_KERNEL); 526 - if (!info) { 527 - sstate->count--; 528 - return -ENOMEM; 529 - } 530 - init_waitqueue_head(&info->open_wait); 531 - init_waitqueue_head(&info->close_wait); 532 - init_waitqueue_head(&info->delta_msr_wait); 533 - info->magic = SERIAL_MAGIC; 534 - info->port = sstate->port; 535 - info->flags = sstate->flags; 536 - info->xmit_fifo_size = sstate->xmit_fifo_size; 537 - info->line = line; 538 - INIT_WORK(&info->work, do_softint); 539 - info->state = sstate; 540 - if (sstate->info) { 541 - kfree(info); 542 - *ret_info = sstate->info; 543 - return 0; 544 - } 545 - *ret_info = sstate->info = info; 546 - return 0; 547 - } 548 - 549 - static int 550 - startup(struct async_struct *info) 551 - { 552 - unsigned long flags; 553 - int retval=0; 554 - irq_handler_t handler; 555 - struct serial_state *state= info->state; 556 - unsigned long page; 495 + struct serial_state *state = container_of(port, struct serial_state, 496 + port); 497 + unsigned long flags, page; 498 + int retval = 0; 557 499 558 500 page = get_zeroed_page(GFP_KERNEL); 559 501 if (!page) ··· 391 673 392 674 local_irq_save(flags); 393 675 394 - if (info->flags & ASYNC_INITIALIZED) { 395 - free_page(page); 396 - goto errout; 397 - } 398 - 399 - if (!state->port || !state->type) { 400 - if (info->tty) set_bit(TTY_IO_ERROR, &info->tty->flags); 401 - free_page(page); 402 - goto errout; 403 - } 404 - if (info->xmit.buf) 676 + if (state->xmit.buf) 405 677 free_page(page); 406 678 else 407 - info->xmit.buf = (unsigned char *) page; 679 + state->xmit.buf = (unsigned char *) page; 408 680 409 - #ifdef SIMSERIAL_DEBUG 410 - printk("startup: ttys%d (irq %d)...", info->line, state->irq); 411 - #endif 412 - 413 - /* 414 - * Allocate the IRQ if necessary 415 - */ 416 - if (state->irq && (!IRQ_ports[state->irq] || 417 - !IRQ_ports[state->irq]->next_port)) { 418 - if (IRQ_ports[state->irq]) { 419 - retval = -EBUSY; 681 + if (state->irq) { 682 + retval = request_irq(state->irq, rs_interrupt_single, 0, 683 + "simserial", state); 684 + if (retval) 420 685 goto errout; 421 - } else 422 - handler = rs_interrupt_single; 423 - 424 - retval = request_irq(state->irq, handler, IRQ_T(info), "simserial", NULL); 425 - if (retval) { 426 - if (capable(CAP_SYS_ADMIN)) { 427 - if (info->tty) 428 - set_bit(TTY_IO_ERROR, 429 - &info->tty->flags); 430 - retval = 0; 431 - } 432 - goto errout; 433 - } 434 686 } 435 687 436 - /* 437 - * Insert serial port into IRQ chain. 438 - */ 439 - info->prev_port = NULL; 440 - info->next_port = IRQ_ports[state->irq]; 441 - if (info->next_port) 442 - info->next_port->prev_port = info; 443 - IRQ_ports[state->irq] = info; 444 - 445 - if (info->tty) clear_bit(TTY_IO_ERROR, &info->tty->flags); 446 - 447 - info->xmit.head = info->xmit.tail = 0; 448 - 449 - #if 0 450 - /* 451 - * Set up serial timers... 452 - */ 453 - timer_table[RS_TIMER].expires = jiffies + 2*HZ/100; 454 - timer_active |= 1 << RS_TIMER; 455 - #endif 688 + state->xmit.head = state->xmit.tail = 0; 456 689 457 690 /* 458 691 * Set up the tty->alt_speed kludge 459 692 */ 460 - if (info->tty) { 461 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 462 - info->tty->alt_speed = 57600; 463 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 464 - info->tty->alt_speed = 115200; 465 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 466 - info->tty->alt_speed = 230400; 467 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 468 - info->tty->alt_speed = 460800; 469 - } 470 - 471 - info->flags |= ASYNC_INITIALIZED; 472 - local_irq_restore(flags); 473 - return 0; 693 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 694 + tty->alt_speed = 57600; 695 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 696 + tty->alt_speed = 115200; 697 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 698 + tty->alt_speed = 230400; 699 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 700 + tty->alt_speed = 460800; 474 701 475 702 errout: 476 703 local_irq_restore(flags); ··· 431 768 */ 432 769 static int rs_open(struct tty_struct *tty, struct file * filp) 433 770 { 434 - struct async_struct *info; 435 - int retval, line; 436 - unsigned long page; 771 + struct serial_state *info = rs_table + tty->index; 772 + struct tty_port *port = &info->port; 437 773 438 - line = tty->index; 439 - if ((line < 0) || (line >= NR_PORTS)) 440 - return -ENODEV; 441 - retval = get_async_struct(line, &info); 442 - if (retval) 443 - return retval; 444 774 tty->driver_data = info; 445 - info->tty = tty; 446 - 447 - #ifdef SIMSERIAL_DEBUG 448 - printk("rs_open %s, count = %d\n", tty->name, info->state->count); 449 - #endif 450 - info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 451 - 452 - if (!tmp_buf) { 453 - page = get_zeroed_page(GFP_KERNEL); 454 - if (!page) 455 - return -ENOMEM; 456 - if (tmp_buf) 457 - free_page(page); 458 - else 459 - tmp_buf = (unsigned char *) page; 460 - } 461 - 462 - /* 463 - * If the port is the middle of closing, bail out now 464 - */ 465 - if (tty_hung_up_p(filp) || 466 - (info->flags & ASYNC_CLOSING)) { 467 - if (info->flags & ASYNC_CLOSING) 468 - interruptible_sleep_on(&info->close_wait); 469 - #ifdef SERIAL_DO_RESTART 470 - return ((info->flags & ASYNC_HUP_NOTIFY) ? 471 - -EAGAIN : -ERESTARTSYS); 472 - #else 473 - return -EAGAIN; 474 - #endif 475 - } 476 - 477 - /* 478 - * Start up serial port 479 - */ 480 - retval = startup(info); 481 - if (retval) { 482 - return retval; 483 - } 775 + tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 484 776 485 777 /* 486 778 * figure out which console to use (should be one already) ··· 446 828 console = console->next; 447 829 } 448 830 449 - #ifdef SIMSERIAL_DEBUG 450 - printk("rs_open ttys%d successful\n", info->line); 451 - #endif 452 - return 0; 831 + return tty_port_open(port, tty, filp); 453 832 } 454 833 455 834 /* 456 835 * /proc fs routines.... 457 836 */ 458 837 459 - static inline void line_info(struct seq_file *m, struct serial_state *state) 460 - { 461 - seq_printf(m, "%d: uart:%s port:%lX irq:%d\n", 462 - state->line, uart_config[state->type].name, 463 - state->port, state->irq); 464 - } 465 - 466 838 static int rs_proc_show(struct seq_file *m, void *v) 467 839 { 468 840 int i; 469 841 470 - seq_printf(m, "simserinfo:1.0 driver:%s\n", serial_version); 842 + seq_printf(m, "simserinfo:1.0\n"); 471 843 for (i = 0; i < NR_PORTS; i++) 472 - line_info(m, &rs_table[i]); 844 + seq_printf(m, "%d: uart:16550 port:3F8 irq:%d\n", 845 + i, rs_table[i].irq); 473 846 return 0; 474 847 } 475 848 ··· 477 868 .release = single_release, 478 869 }; 479 870 480 - /* 481 - * --------------------------------------------------------------------- 482 - * rs_init() and friends 483 - * 484 - * rs_init() is called at boot-time to initialize the serial driver. 485 - * --------------------------------------------------------------------- 486 - */ 487 - 488 - /* 489 - * This routine prints out the appropriate serial driver version 490 - * number, and identifies which options were configured into this 491 - * driver. 492 - */ 493 - static inline void show_serial_version(void) 494 - { 495 - printk(KERN_INFO "%s version %s with", serial_name, serial_version); 496 - printk(KERN_INFO " no serial options enabled\n"); 497 - } 498 - 499 871 static const struct tty_operations hp_ops = { 500 872 .open = rs_open, 501 873 .close = rs_close, ··· 491 901 .unthrottle = rs_unthrottle, 492 902 .send_xchar = rs_send_xchar, 493 903 .set_termios = rs_set_termios, 494 - .stop = rs_stop, 495 - .start = rs_start, 496 904 .hangup = rs_hangup, 497 - .wait_until_sent = rs_wait_until_sent, 498 905 .proc_fops = &rs_proc_fops, 499 906 }; 500 907 501 - /* 502 - * The serial driver boot-time initialization code! 503 - */ 504 - static int __init 505 - simrs_init (void) 908 + static const struct tty_port_operations hp_port_ops = { 909 + .activate = activate, 910 + .shutdown = shutdown, 911 + }; 912 + 913 + static int __init simrs_init(void) 506 914 { 507 - int i, rc; 508 - struct serial_state *state; 915 + struct serial_state *state; 916 + int retval; 509 917 510 918 if (!ia64_platform_is("hpsim")) 511 919 return -ENODEV; 512 920 513 - hp_simserial_driver = alloc_tty_driver(1); 921 + hp_simserial_driver = alloc_tty_driver(NR_PORTS); 514 922 if (!hp_simserial_driver) 515 923 return -ENOMEM; 516 924 517 - show_serial_version(); 925 + printk(KERN_INFO "SimSerial driver with no serial options enabled\n"); 518 926 519 927 /* Initialize the tty_driver structure */ 520 928 521 - hp_simserial_driver->owner = THIS_MODULE; 522 929 hp_simserial_driver->driver_name = "simserial"; 523 930 hp_simserial_driver->name = "ttyS"; 524 931 hp_simserial_driver->major = TTY_MAJOR; ··· 528 941 hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW; 529 942 tty_set_operations(hp_simserial_driver, &hp_ops); 530 943 531 - /* 532 - * Let's have a little bit of fun ! 533 - */ 534 - for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) { 944 + state = rs_table; 945 + tty_port_init(&state->port); 946 + state->port.ops = &hp_port_ops; 947 + state->port.close_delay = 0; /* XXX really 0? */ 535 948 536 - if (state->type == PORT_UNKNOWN) continue; 537 - 538 - if (!state->irq) { 539 - if ((rc = assign_irq_vector(AUTO_ASSIGN)) < 0) 540 - panic("%s: out of interrupt vectors!\n", 541 - __func__); 542 - state->irq = rc; 543 - ia64_ssc_connect_irq(KEYBOARD_INTR, state->irq); 544 - } 545 - 546 - printk(KERN_INFO "ttyS%d at 0x%04lx (irq = %d) is a %s\n", 547 - state->line, 548 - state->port, state->irq, 549 - uart_config[state->type].name); 949 + retval = hpsim_get_irq(KEYBOARD_INTR); 950 + if (retval < 0) { 951 + printk(KERN_ERR "%s: out of interrupt vectors!\n", 952 + __func__); 953 + goto err_free_tty; 550 954 } 551 955 552 - if (tty_register_driver(hp_simserial_driver)) 553 - panic("Couldn't register simserial driver\n"); 956 + state->irq = retval; 957 + 958 + /* the port is imaginary */ 959 + printk(KERN_INFO "ttyS0 at 0x03f8 (irq = %d) is a 16550\n", state->irq); 960 + 961 + retval = tty_register_driver(hp_simserial_driver); 962 + if (retval) { 963 + printk(KERN_ERR "Couldn't register simserial driver\n"); 964 + goto err_free_tty; 965 + } 554 966 555 967 return 0; 968 + err_free_tty: 969 + put_tty_driver(hp_simserial_driver); 970 + return retval; 556 971 } 557 972 558 973 #ifndef MODULE
+1 -1
arch/ia64/include/asm/hpsim.h
··· 10 10 struct tty_driver; 11 11 extern struct tty_driver *hp_simserial_driver; 12 12 13 - void ia64_ssc_connect_irq(long intr, long irq); 13 + extern int hpsim_get_irq(int intr); 14 14 void ia64_ctl_trace(long on); 15 15 16 16 #endif
-1
arch/m68k/emu/nfcon.c
··· 127 127 if (!nfcon_tty_driver) 128 128 return -ENOMEM; 129 129 130 - nfcon_tty_driver->owner = THIS_MODULE; 131 130 nfcon_tty_driver->driver_name = "nfcon"; 132 131 nfcon_tty_driver->name = "nfcon"; 133 132 nfcon_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
+28 -29
arch/parisc/kernel/pdc_cons.c
··· 90 90 91 91 #define PDC_CONS_POLL_DELAY (30 * HZ / 1000) 92 92 93 - static struct timer_list pdc_console_timer; 93 + static void pdc_console_poll(unsigned long unused); 94 + static DEFINE_TIMER(pdc_console_timer, pdc_console_poll, 0, 0); 95 + static struct tty_port tty_port; 94 96 95 97 static int pdc_console_tty_open(struct tty_struct *tty, struct file *filp) 96 98 { 97 - 99 + tty_port_tty_set(&tty_port, tty); 98 100 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY); 99 101 100 102 return 0; ··· 104 102 105 103 static void pdc_console_tty_close(struct tty_struct *tty, struct file *filp) 106 104 { 107 - if (!tty->count) 108 - del_timer(&pdc_console_timer); 105 + if (!tty->count) { 106 + del_timer_sync(&pdc_console_timer); 107 + tty_port_tty_set(&tty_port, NULL); 108 + } 109 109 } 110 110 111 111 static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) ··· 126 122 return 0; /* no buffer */ 127 123 } 128 124 129 - static struct tty_driver *pdc_console_tty_driver; 130 - 131 125 static const struct tty_operations pdc_console_tty_ops = { 132 126 .open = pdc_console_tty_open, 133 127 .close = pdc_console_tty_close, ··· 136 134 137 135 static void pdc_console_poll(unsigned long unused) 138 136 { 139 - 140 137 int data, count = 0; 141 - 142 - struct tty_struct *tty = pdc_console_tty_driver->ttys[0]; 138 + struct tty_struct *tty = tty_port_tty_get(&tty_port); 143 139 144 140 if (!tty) 145 141 return; ··· 153 153 if (count) 154 154 tty_flip_buffer_push(tty); 155 155 156 - if (tty->count && (pdc_cons.flags & CON_ENABLED)) 156 + tty_kref_put(tty); 157 + 158 + if (pdc_cons.flags & CON_ENABLED) 157 159 mod_timer(&pdc_console_timer, jiffies + PDC_CONS_POLL_DELAY); 158 160 } 159 161 162 + static struct tty_driver *pdc_console_tty_driver; 163 + 160 164 static int __init pdc_console_tty_driver_init(void) 161 165 { 162 - 163 166 int err; 164 - struct tty_driver *drv; 165 167 166 168 /* Check if the console driver is still registered. 167 169 * It is unregistered if the pdc console was not selected as the ··· 185 183 printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n"); 186 184 pdc_cons.flags &= ~CON_BOOT; 187 185 188 - drv = alloc_tty_driver(1); 186 + tty_port_init(&tty_port); 189 187 190 - if (!drv) 188 + pdc_console_tty_driver = alloc_tty_driver(1); 189 + 190 + if (!pdc_console_tty_driver) 191 191 return -ENOMEM; 192 192 193 - drv->driver_name = "pdc_cons"; 194 - drv->name = "ttyB"; 195 - drv->major = MUX_MAJOR; 196 - drv->minor_start = 0; 197 - drv->type = TTY_DRIVER_TYPE_SYSTEM; 198 - drv->init_termios = tty_std_termios; 199 - drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS; 200 - tty_set_operations(drv, &pdc_console_tty_ops); 193 + pdc_console_tty_driver->driver_name = "pdc_cons"; 194 + pdc_console_tty_driver->name = "ttyB"; 195 + pdc_console_tty_driver->major = MUX_MAJOR; 196 + pdc_console_tty_driver->minor_start = 0; 197 + pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM; 198 + pdc_console_tty_driver->init_termios = tty_std_termios; 199 + pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW | 200 + TTY_DRIVER_RESET_TERMIOS; 201 + tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops); 201 202 202 - err = tty_register_driver(drv); 203 + err = tty_register_driver(pdc_console_tty_driver); 203 204 if (err) { 204 205 printk(KERN_ERR "Unable to register the PDC console TTY driver\n"); 205 206 return err; 206 207 } 207 - 208 - pdc_console_tty_driver = drv; 209 - 210 - /* No need to initialize the pdc_console_timer if tty isn't allocated */ 211 - init_timer(&pdc_console_timer); 212 - pdc_console_timer.function = pdc_console_poll; 213 208 214 209 return 0; 215 210 }
+8 -14
arch/xtensa/platforms/iss/console.c
··· 19 19 #include <linux/param.h> 20 20 #include <linux/seq_file.h> 21 21 #include <linux/serial.h> 22 - #include <linux/serialP.h> 23 22 24 23 #include <asm/uaccess.h> 25 24 #include <asm/irq.h> ··· 36 37 #define SERIAL_TIMER_VALUE (20 * HZ) 37 38 38 39 static struct tty_driver *serial_driver; 40 + static struct tty_port serial_port; 39 41 static struct timer_list serial_timer; 40 42 41 43 static DEFINE_SPINLOCK(timer_lock); ··· 68 68 69 69 static int rs_open(struct tty_struct *tty, struct file * filp) 70 70 { 71 - int line = tty->index; 72 - 73 - if ((line < 0) || (line >= SERIAL_MAX_NUM_LINES)) 74 - return -ENODEV; 75 - 71 + tty->port = &serial_port; 76 72 spin_lock(&timer_lock); 77 - 78 73 if (tty->count == 1) { 79 - init_timer(&serial_timer); 80 - serial_timer.data = (unsigned long) tty; 81 - serial_timer.function = rs_poll; 74 + setup_timer(&serial_timer, rs_poll, (unsigned long)tty); 82 75 mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE); 83 76 } 84 77 spin_unlock(&timer_lock); ··· 92 99 */ 93 100 static void rs_close(struct tty_struct *tty, struct file * filp) 94 101 { 95 - spin_lock(&timer_lock); 102 + spin_lock_bh(&timer_lock); 96 103 if (tty->count == 1) 97 104 del_timer_sync(&serial_timer); 98 - spin_unlock(&timer_lock); 105 + spin_unlock_bh(&timer_lock); 99 106 } 100 107 101 108 ··· 203 210 204 211 int __init rs_init(void) 205 212 { 206 - serial_driver = alloc_tty_driver(1); 213 + tty_port_init(&serial_port); 214 + 215 + serial_driver = alloc_tty_driver(SERIAL_MAX_NUM_LINES); 207 216 208 217 printk ("%s %s\n", serial_name, serial_version); 209 218 210 219 /* Initialize the tty_driver structure */ 211 220 212 - serial_driver->owner = THIS_MODULE; 213 221 serial_driver->driver_name = "iss_serial"; 214 222 serial_driver->name = "ttyS"; 215 223 serial_driver->major = TTY_MAJOR;
+3 -6
drivers/accessibility/braille/braille_console.c
··· 244 244 245 245 switch (val) { 246 246 case KVAL(K_CAPS): 247 - on_off = vc_kbd_led(kbd_table + fg_console, 248 - VC_CAPSLOCK); 247 + on_off = vt_get_leds(fg_console, VC_CAPSLOCK); 249 248 break; 250 249 case KVAL(K_NUM): 251 - on_off = vc_kbd_led(kbd_table + fg_console, 252 - VC_NUMLOCK); 250 + on_off = vt_get_leds(fg_console, VC_NUMLOCK); 253 251 break; 254 252 case KVAL(K_HOLD): 255 - on_off = vc_kbd_led(kbd_table + fg_console, 256 - VC_SCROLLOCK); 253 + on_off = vt_get_leds(fg_console, VC_SCROLLOCK); 257 254 break; 258 255 } 259 256 if (on_off == 1)
-15
drivers/char/Kconfig
··· 66 66 67 67 If unsure, say N. 68 68 69 - config BRIQ_PANEL 70 - tristate 'Total Impact briQ front panel driver' 71 - depends on PPC_CHRP 72 - ---help--- 73 - The briQ is a small footprint CHRP computer with a frontpanel VFD, a 74 - tristate led and two switches. It is the size of a CDROM drive. 75 - 76 - If you have such one and want anything showing on the VFD then you 77 - must answer Y here. 78 - 79 - To compile this driver as a module, choose M here: the 80 - module will be called briq_panel. 81 - 82 - It's safe to say N here. 83 - 84 69 config BFIN_OTP 85 70 tristate "Blackfin On-Chip OTP Memory Support" 86 71 depends on BLACKFIN && (BF51x || BF52x || BF54x)
-1
drivers/char/Makefile
··· 16 16 obj-$(CONFIG_VIOTAPE) += viotape.o 17 17 obj-$(CONFIG_IBM_BSR) += bsr.o 18 18 obj-$(CONFIG_SGI_MBCS) += mbcs.o 19 - obj-$(CONFIG_BRIQ_PANEL) += briq_panel.o 20 19 obj-$(CONFIG_BFIN_OTP) += bfin-otp.o 21 20 22 21 obj-$(CONFIG_PRINTER) += lp.o
-266
drivers/char/briq_panel.c
··· 1 - /* 2 - * Drivers for the Total Impact PPC based computer "BRIQ" 3 - * by Dr. Karsten Jeppesen 4 - * 5 - */ 6 - 7 - #include <linux/module.h> 8 - 9 - #include <linux/types.h> 10 - #include <linux/errno.h> 11 - #include <linux/tty.h> 12 - #include <linux/timer.h> 13 - #include <linux/kernel.h> 14 - #include <linux/wait.h> 15 - #include <linux/string.h> 16 - #include <linux/ioport.h> 17 - #include <linux/delay.h> 18 - #include <linux/miscdevice.h> 19 - #include <linux/fs.h> 20 - #include <linux/mm.h> 21 - #include <linux/init.h> 22 - 23 - #include <asm/uaccess.h> 24 - #include <asm/io.h> 25 - #include <asm/prom.h> 26 - 27 - #define BRIQ_PANEL_MINOR 156 28 - #define BRIQ_PANEL_VFD_IOPORT 0x0390 29 - #define BRIQ_PANEL_LED_IOPORT 0x0398 30 - #define BRIQ_PANEL_VER "1.1 (04/20/2002)" 31 - #define BRIQ_PANEL_MSG0 "Loading Linux" 32 - 33 - static int vfd_is_open; 34 - static unsigned char vfd[40]; 35 - static int vfd_cursor; 36 - static unsigned char ledpb, led; 37 - 38 - static void update_vfd(void) 39 - { 40 - int i; 41 - 42 - /* cursor home */ 43 - outb(0x02, BRIQ_PANEL_VFD_IOPORT); 44 - for (i=0; i<20; i++) 45 - outb(vfd[i], BRIQ_PANEL_VFD_IOPORT + 1); 46 - 47 - /* cursor to next line */ 48 - outb(0xc0, BRIQ_PANEL_VFD_IOPORT); 49 - for (i=20; i<40; i++) 50 - outb(vfd[i], BRIQ_PANEL_VFD_IOPORT + 1); 51 - 52 - } 53 - 54 - static void set_led(char state) 55 - { 56 - if (state == 'R') 57 - led = 0x01; 58 - else if (state == 'G') 59 - led = 0x02; 60 - else if (state == 'Y') 61 - led = 0x03; 62 - else if (state == 'X') 63 - led = 0x00; 64 - outb(led, BRIQ_PANEL_LED_IOPORT); 65 - } 66 - 67 - static int briq_panel_open(struct inode *ino, struct file *filep) 68 - { 69 - tty_lock(); 70 - /* enforce single access, vfd_is_open is protected by BKL */ 71 - if (vfd_is_open) { 72 - tty_unlock(); 73 - return -EBUSY; 74 - } 75 - vfd_is_open = 1; 76 - 77 - tty_unlock(); 78 - return 0; 79 - } 80 - 81 - static int briq_panel_release(struct inode *ino, struct file *filep) 82 - { 83 - if (!vfd_is_open) 84 - return -ENODEV; 85 - 86 - vfd_is_open = 0; 87 - 88 - return 0; 89 - } 90 - 91 - static ssize_t briq_panel_read(struct file *file, char __user *buf, size_t count, 92 - loff_t *ppos) 93 - { 94 - unsigned short c; 95 - unsigned char cp; 96 - 97 - if (!vfd_is_open) 98 - return -ENODEV; 99 - 100 - c = (inb(BRIQ_PANEL_LED_IOPORT) & 0x000c) | (ledpb & 0x0003); 101 - set_led(' '); 102 - /* upper button released */ 103 - if ((!(ledpb & 0x0004)) && (c & 0x0004)) { 104 - cp = ' '; 105 - ledpb = c; 106 - if (copy_to_user(buf, &cp, 1)) 107 - return -EFAULT; 108 - return 1; 109 - } 110 - /* lower button released */ 111 - else if ((!(ledpb & 0x0008)) && (c & 0x0008)) { 112 - cp = '\r'; 113 - ledpb = c; 114 - if (copy_to_user(buf, &cp, 1)) 115 - return -EFAULT; 116 - return 1; 117 - } else { 118 - ledpb = c; 119 - return 0; 120 - } 121 - } 122 - 123 - static void scroll_vfd( void ) 124 - { 125 - int i; 126 - 127 - for (i=0; i<20; i++) { 128 - vfd[i] = vfd[i+20]; 129 - vfd[i+20] = ' '; 130 - } 131 - vfd_cursor = 20; 132 - } 133 - 134 - static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_t len, 135 - loff_t *ppos) 136 - { 137 - size_t indx = len; 138 - int i, esc = 0; 139 - 140 - if (!vfd_is_open) 141 - return -EBUSY; 142 - 143 - for (;;) { 144 - char c; 145 - if (!indx) 146 - break; 147 - if (get_user(c, buf)) 148 - return -EFAULT; 149 - if (esc) { 150 - set_led(c); 151 - esc = 0; 152 - } else if (c == 27) { 153 - esc = 1; 154 - } else if (c == 12) { 155 - /* do a form feed */ 156 - for (i=0; i<40; i++) 157 - vfd[i] = ' '; 158 - vfd_cursor = 0; 159 - } else if (c == 10) { 160 - if (vfd_cursor < 20) 161 - vfd_cursor = 20; 162 - else if (vfd_cursor < 40) 163 - vfd_cursor = 40; 164 - else if (vfd_cursor < 60) 165 - vfd_cursor = 60; 166 - if (vfd_cursor > 59) 167 - scroll_vfd(); 168 - } else { 169 - /* just a character */ 170 - if (vfd_cursor > 39) 171 - scroll_vfd(); 172 - vfd[vfd_cursor++] = c; 173 - } 174 - indx--; 175 - buf++; 176 - } 177 - update_vfd(); 178 - 179 - return len; 180 - } 181 - 182 - static const struct file_operations briq_panel_fops = { 183 - .owner = THIS_MODULE, 184 - .read = briq_panel_read, 185 - .write = briq_panel_write, 186 - .open = briq_panel_open, 187 - .release = briq_panel_release, 188 - .llseek = noop_llseek, 189 - }; 190 - 191 - static struct miscdevice briq_panel_miscdev = { 192 - BRIQ_PANEL_MINOR, 193 - "briq_panel", 194 - &briq_panel_fops 195 - }; 196 - 197 - static int __init briq_panel_init(void) 198 - { 199 - struct device_node *root = of_find_node_by_path("/"); 200 - const char *machine; 201 - int i; 202 - 203 - machine = of_get_property(root, "model", NULL); 204 - if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0) { 205 - of_node_put(root); 206 - return -ENODEV; 207 - } 208 - of_node_put(root); 209 - 210 - printk(KERN_INFO 211 - "briq_panel: v%s Dr. Karsten Jeppesen (kj@totalimpact.com)\n", 212 - BRIQ_PANEL_VER); 213 - 214 - if (!request_region(BRIQ_PANEL_VFD_IOPORT, 4, "BRIQ Front Panel")) 215 - return -EBUSY; 216 - 217 - if (!request_region(BRIQ_PANEL_LED_IOPORT, 2, "BRIQ Front Panel")) { 218 - release_region(BRIQ_PANEL_VFD_IOPORT, 4); 219 - return -EBUSY; 220 - } 221 - ledpb = inb(BRIQ_PANEL_LED_IOPORT) & 0x000c; 222 - 223 - if (misc_register(&briq_panel_miscdev) < 0) { 224 - release_region(BRIQ_PANEL_VFD_IOPORT, 4); 225 - release_region(BRIQ_PANEL_LED_IOPORT, 2); 226 - return -EBUSY; 227 - } 228 - 229 - outb(0x38, BRIQ_PANEL_VFD_IOPORT); /* Function set */ 230 - outb(0x01, BRIQ_PANEL_VFD_IOPORT); /* Clear display */ 231 - outb(0x0c, BRIQ_PANEL_VFD_IOPORT); /* Display on */ 232 - outb(0x06, BRIQ_PANEL_VFD_IOPORT); /* Entry normal */ 233 - for (i=0; i<40; i++) 234 - vfd[i]=' '; 235 - #ifndef MODULE 236 - vfd[0] = 'L'; 237 - vfd[1] = 'o'; 238 - vfd[2] = 'a'; 239 - vfd[3] = 'd'; 240 - vfd[4] = 'i'; 241 - vfd[5] = 'n'; 242 - vfd[6] = 'g'; 243 - vfd[7] = ' '; 244 - vfd[8] = '.'; 245 - vfd[9] = '.'; 246 - vfd[10] = '.'; 247 - #endif /* !MODULE */ 248 - 249 - update_vfd(); 250 - 251 - return 0; 252 - } 253 - 254 - static void __exit briq_panel_exit(void) 255 - { 256 - misc_deregister(&briq_panel_miscdev); 257 - release_region(BRIQ_PANEL_VFD_IOPORT, 4); 258 - release_region(BRIQ_PANEL_LED_IOPORT, 2); 259 - } 260 - 261 - module_init(briq_panel_init); 262 - module_exit(briq_panel_exit); 263 - 264 - MODULE_LICENSE("GPL"); 265 - MODULE_AUTHOR("Karsten Jeppesen <karsten@jeppesens.com>"); 266 - MODULE_DESCRIPTION("Driver for the Total Impact briQ front panel");
-2
drivers/char/ttyprintk.c
··· 184 184 if (!ttyprintk_driver) 185 185 return ret; 186 186 187 - ttyprintk_driver->owner = THIS_MODULE; 188 187 ttyprintk_driver->driver_name = "ttyprintk"; 189 188 ttyprintk_driver->name = "ttyprintk"; 190 189 ttyprintk_driver->major = TTYAUX_MAJOR; 191 190 ttyprintk_driver->minor_start = 3; 192 - ttyprintk_driver->num = 1; 193 191 ttyprintk_driver->type = TTY_DRIVER_TYPE_CONSOLE; 194 192 ttyprintk_driver->init_termios = tty_std_termios; 195 193 ttyprintk_driver->init_termios.c_oflag = OPOST | OCRNL | ONOCR | ONLRET;
+4 -9
drivers/isdn/capi/capi.c
··· 1013 1013 static int 1014 1014 capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty) 1015 1015 { 1016 - int idx = tty->index; 1017 - struct capiminor *mp = capiminor_get(idx); 1018 - int ret = tty_init_termios(tty); 1016 + struct capiminor *mp = capiminor_get(tty->index); 1017 + int ret = tty_standard_install(driver, tty); 1019 1018 1020 - if (ret == 0) { 1021 - tty_driver_kref_get(driver); 1022 - tty->count++; 1019 + if (ret == 0) 1023 1020 tty->driver_data = mp; 1024 - driver->ttys[idx] = tty; 1025 - } else 1021 + else 1026 1022 capiminor_put(mp); 1027 1023 return ret; 1028 1024 } ··· 1286 1290 kfree(capiminors); 1287 1291 return -ENOMEM; 1288 1292 } 1289 - drv->owner = THIS_MODULE; 1290 1293 drv->driver_name = "capi_nc"; 1291 1294 drv->name = "capi"; 1292 1295 drv->major = 0;
+1 -4
drivers/isdn/gigaset/common.c
··· 720 720 721 721 tasklet_init(&cs->event_tasklet, gigaset_handle_event, 722 722 (unsigned long) cs); 723 + tty_port_init(&cs->port); 723 724 cs->commands_pending = 0; 724 725 cs->cur_at_seq = 0; 725 726 cs->gotfwver = -1; 726 - cs->open_count = 0; 727 727 cs->dev = NULL; 728 - cs->tty = NULL; 729 728 cs->tty_dev = NULL; 730 729 cs->cidmode = cidmode != 0; 731 730 cs->tabnocid = gigaset_tab_nocid; ··· 1050 1051 1051 1052 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty) 1052 1053 { 1053 - if (tty->index < 0 || tty->index >= tty->driver->num) 1054 - return NULL; 1055 1054 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start); 1056 1055 } 1057 1056
+1 -2
drivers/isdn/gigaset/gigaset.h
··· 433 433 spinlock_t cmdlock; 434 434 unsigned curlen, cmdbytes; 435 435 436 - unsigned open_count; 437 - struct tty_struct *tty; 436 + struct tty_port port; 438 437 struct tasklet_struct if_wake_tasklet; 439 438 unsigned control_state; 440 439
+34 -124
drivers/isdn/gigaset/interface.c
··· 146 146 static int if_open(struct tty_struct *tty, struct file *filp) 147 147 { 148 148 struct cardstate *cs; 149 - unsigned long flags; 150 149 151 150 gig_dbg(DEBUG_IF, "%d+%d: %s()", 152 151 tty->driver->minor_start, tty->index, __func__); 153 - 154 - tty->driver_data = NULL; 155 152 156 153 cs = gigaset_get_cs_by_tty(tty); 157 154 if (!cs || !try_module_get(cs->driver->owner)) ··· 160 163 } 161 164 tty->driver_data = cs; 162 165 163 - ++cs->open_count; 166 + ++cs->port.count; 164 167 165 - if (cs->open_count == 1) { 166 - spin_lock_irqsave(&cs->lock, flags); 167 - cs->tty = tty; 168 - spin_unlock_irqrestore(&cs->lock, flags); 168 + if (cs->port.count == 1) { 169 + tty_port_tty_set(&cs->port, tty); 169 170 tty->low_latency = 1; 170 171 } 171 172 ··· 173 178 174 179 static void if_close(struct tty_struct *tty, struct file *filp) 175 180 { 176 - struct cardstate *cs; 177 - unsigned long flags; 181 + struct cardstate *cs = tty->driver_data; 178 182 179 - cs = (struct cardstate *) tty->driver_data; 180 - if (!cs) { 181 - pr_err("%s: no cardstate\n", __func__); 183 + if (!cs) { /* happens if we didn't find cs in open */ 184 + printk(KERN_DEBUG "%s: no cardstate\n", __func__); 182 185 return; 183 186 } 184 187 ··· 186 193 187 194 if (!cs->connected) 188 195 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ 189 - else if (!cs->open_count) 196 + else if (!cs->port.count) 190 197 dev_warn(cs->dev, "%s: device not opened\n", __func__); 191 - else { 192 - if (!--cs->open_count) { 193 - spin_lock_irqsave(&cs->lock, flags); 194 - cs->tty = NULL; 195 - spin_unlock_irqrestore(&cs->lock, flags); 196 - } 197 - } 198 + else if (!--cs->port.count) 199 + tty_port_tty_set(&cs->port, NULL); 198 200 199 201 mutex_unlock(&cs->mutex); 200 202 ··· 199 211 static int if_ioctl(struct tty_struct *tty, 200 212 unsigned int cmd, unsigned long arg) 201 213 { 202 - struct cardstate *cs; 214 + struct cardstate *cs = tty->driver_data; 203 215 int retval = -ENODEV; 204 216 int int_arg; 205 217 unsigned char buf[6]; 206 218 unsigned version[4]; 207 - 208 - cs = (struct cardstate *) tty->driver_data; 209 - if (!cs) { 210 - pr_err("%s: no cardstate\n", __func__); 211 - return -ENODEV; 212 - } 213 219 214 220 gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd); 215 221 ··· 213 231 if (!cs->connected) { 214 232 gig_dbg(DEBUG_IF, "not connected"); 215 233 retval = -ENODEV; 216 - } else if (!cs->open_count) 217 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 218 - else { 234 + } else { 219 235 retval = 0; 220 236 switch (cmd) { 221 237 case GIGASET_REDIR: ··· 265 285 266 286 static int if_tiocmget(struct tty_struct *tty) 267 287 { 268 - struct cardstate *cs; 288 + struct cardstate *cs = tty->driver_data; 269 289 int retval; 270 - 271 - cs = (struct cardstate *) tty->driver_data; 272 - if (!cs) { 273 - pr_err("%s: no cardstate\n", __func__); 274 - return -ENODEV; 275 - } 276 290 277 291 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 278 292 ··· 283 309 static int if_tiocmset(struct tty_struct *tty, 284 310 unsigned int set, unsigned int clear) 285 311 { 286 - struct cardstate *cs; 312 + struct cardstate *cs = tty->driver_data; 287 313 int retval; 288 314 unsigned mc; 289 - 290 - cs = (struct cardstate *) tty->driver_data; 291 - if (!cs) { 292 - pr_err("%s: no cardstate\n", __func__); 293 - return -ENODEV; 294 - } 295 315 296 316 gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)", 297 317 cs->minor_index, __func__, set, clear); ··· 309 341 310 342 static int if_write(struct tty_struct *tty, const unsigned char *buf, int count) 311 343 { 312 - struct cardstate *cs; 344 + struct cardstate *cs = tty->driver_data; 313 345 struct cmdbuf_t *cb; 314 346 int retval; 315 - 316 - cs = (struct cardstate *) tty->driver_data; 317 - if (!cs) { 318 - pr_err("%s: no cardstate\n", __func__); 319 - return -ENODEV; 320 - } 321 347 322 348 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 323 349 ··· 320 358 321 359 if (!cs->connected) { 322 360 gig_dbg(DEBUG_IF, "not connected"); 323 - retval = -ENODEV; 324 - goto done; 325 - } 326 - if (!cs->open_count) { 327 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 328 361 retval = -ENODEV; 329 362 goto done; 330 363 } ··· 354 397 355 398 static int if_write_room(struct tty_struct *tty) 356 399 { 357 - struct cardstate *cs; 400 + struct cardstate *cs = tty->driver_data; 358 401 int retval = -ENODEV; 359 - 360 - cs = (struct cardstate *) tty->driver_data; 361 - if (!cs) { 362 - pr_err("%s: no cardstate\n", __func__); 363 - return -ENODEV; 364 - } 365 402 366 403 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 367 404 ··· 365 414 if (!cs->connected) { 366 415 gig_dbg(DEBUG_IF, "not connected"); 367 416 retval = -ENODEV; 368 - } else if (!cs->open_count) 369 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 370 - else if (cs->mstate != MS_LOCKED) { 417 + } else if (cs->mstate != MS_LOCKED) { 371 418 dev_warn(cs->dev, "can't write to unlocked device\n"); 372 419 retval = -EBUSY; 373 420 } else ··· 378 429 379 430 static int if_chars_in_buffer(struct tty_struct *tty) 380 431 { 381 - struct cardstate *cs; 432 + struct cardstate *cs = tty->driver_data; 382 433 int retval = 0; 383 - 384 - cs = (struct cardstate *) tty->driver_data; 385 - if (!cs) { 386 - pr_err("%s: no cardstate\n", __func__); 387 - return 0; 388 - } 389 434 390 435 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 391 436 ··· 387 444 388 445 if (!cs->connected) 389 446 gig_dbg(DEBUG_IF, "not connected"); 390 - else if (!cs->open_count) 391 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 392 447 else if (cs->mstate != MS_LOCKED) 393 448 dev_warn(cs->dev, "can't write to unlocked device\n"); 394 449 else ··· 399 458 400 459 static void if_throttle(struct tty_struct *tty) 401 460 { 402 - struct cardstate *cs; 403 - 404 - cs = (struct cardstate *) tty->driver_data; 405 - if (!cs) { 406 - pr_err("%s: no cardstate\n", __func__); 407 - return; 408 - } 461 + struct cardstate *cs = tty->driver_data; 409 462 410 463 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 411 464 ··· 407 472 408 473 if (!cs->connected) 409 474 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ 410 - else if (!cs->open_count) 411 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 412 475 else 413 476 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); 414 477 ··· 415 482 416 483 static void if_unthrottle(struct tty_struct *tty) 417 484 { 418 - struct cardstate *cs; 419 - 420 - cs = (struct cardstate *) tty->driver_data; 421 - if (!cs) { 422 - pr_err("%s: no cardstate\n", __func__); 423 - return; 424 - } 485 + struct cardstate *cs = tty->driver_data; 425 486 426 487 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 427 488 ··· 423 496 424 497 if (!cs->connected) 425 498 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */ 426 - else if (!cs->open_count) 427 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 428 499 else 429 500 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); 430 501 ··· 431 506 432 507 static void if_set_termios(struct tty_struct *tty, struct ktermios *old) 433 508 { 434 - struct cardstate *cs; 509 + struct cardstate *cs = tty->driver_data; 435 510 unsigned int iflag; 436 511 unsigned int cflag; 437 512 unsigned int old_cflag; 438 513 unsigned int control_state, new_state; 439 - 440 - cs = (struct cardstate *) tty->driver_data; 441 - if (!cs) { 442 - pr_err("%s: no cardstate\n", __func__); 443 - return; 444 - } 445 514 446 515 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__); 447 516 ··· 443 524 444 525 if (!cs->connected) { 445 526 gig_dbg(DEBUG_IF, "not connected"); 446 - goto out; 447 - } 448 - 449 - if (!cs->open_count) { 450 - dev_warn(cs->dev, "%s: device not opened\n", __func__); 451 527 goto out; 452 528 } 453 529 ··· 502 588 /* wakeup tasklet for the write operation */ 503 589 static void if_wake(unsigned long data) 504 590 { 505 - struct cardstate *cs = (struct cardstate *) data; 591 + struct cardstate *cs = (struct cardstate *)data; 592 + struct tty_struct *tty = tty_port_tty_get(&cs->port); 506 593 507 - if (cs->tty) 508 - tty_wakeup(cs->tty); 594 + if (tty) { 595 + tty_wakeup(tty); 596 + tty_kref_put(tty); 597 + } 509 598 } 510 599 511 600 /*** interface to common ***/ ··· 561 644 void gigaset_if_receive(struct cardstate *cs, 562 645 unsigned char *buffer, size_t len) 563 646 { 564 - unsigned long flags; 565 - struct tty_struct *tty; 647 + struct tty_struct *tty = tty_port_tty_get(&cs->port); 566 648 567 - spin_lock_irqsave(&cs->lock, flags); 568 - tty = cs->tty; 569 - if (tty == NULL) 649 + if (tty == NULL) { 570 650 gig_dbg(DEBUG_IF, "receive on closed device"); 571 - else { 572 - tty_insert_flip_string(tty, buffer, len); 573 - tty_flip_buffer_push(tty); 651 + return; 574 652 } 575 - spin_unlock_irqrestore(&cs->lock, flags); 653 + 654 + tty_insert_flip_string(tty, buffer, len); 655 + tty_flip_buffer_push(tty); 656 + tty_kref_put(tty); 576 657 } 577 658 EXPORT_SYMBOL_GPL(gigaset_if_receive); 578 659 ··· 584 669 void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 585 670 const char *devname) 586 671 { 587 - unsigned minors = drv->minors; 588 672 int ret; 589 673 struct tty_driver *tty; 590 674 591 675 drv->have_tty = 0; 592 676 593 - drv->tty = tty = alloc_tty_driver(minors); 677 + drv->tty = tty = alloc_tty_driver(drv->minors); 594 678 if (tty == NULL) 595 679 goto enomem; 596 680 597 - tty->magic = TTY_DRIVER_MAGIC, 598 681 tty->type = TTY_DRIVER_TYPE_SERIAL, 599 682 tty->subtype = SERIAL_TYPE_NORMAL, 600 683 tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; ··· 600 687 tty->driver_name = procname; 601 688 tty->name = devname; 602 689 tty->minor_start = drv->minor; 603 - tty->num = drv->minors; 604 - 605 - tty->owner = THIS_MODULE; 606 690 607 691 tty->init_termios = tty_std_termios; 608 692 tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+2 -5
drivers/isdn/i4l/isdn_tty.c
··· 1590 1590 isdn_tty_open(struct tty_struct *tty, struct file *filp) 1591 1591 { 1592 1592 modem_info *info; 1593 - int retval, line; 1593 + int retval; 1594 1594 1595 - line = tty->index; 1596 - if (line < 0 || line >= ISDN_MAX_CHANNELS) 1597 - return -ENODEV; 1598 - info = &dev->mdm.info[line]; 1595 + info = &dev->mdm.info[tty->index]; 1599 1596 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) 1600 1597 return -ENODEV; 1601 1598 if (!try_module_get(info->owner)) {
+2 -10
drivers/misc/pti.c
··· 481 481 { 482 482 int idx = tty->index; 483 483 struct pti_tty *pti_tty_data; 484 - int ret = tty_init_termios(tty); 484 + int ret = tty_standard_install(driver, tty); 485 485 486 486 if (ret == 0) { 487 - tty_driver_kref_get(driver); 488 - tty->count++; 489 - driver->ttys[idx] = tty; 490 - 491 487 pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL); 492 488 if (pti_tty_data == NULL) 493 489 return -ENOMEM; ··· 907 911 908 912 /* First register module as tty device */ 909 913 910 - pti_tty_driver = alloc_tty_driver(1); 914 + pti_tty_driver = alloc_tty_driver(PTITTY_MINOR_NUM); 911 915 if (pti_tty_driver == NULL) { 912 916 pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n", 913 917 __func__, __LINE__); 914 918 return -ENOMEM; 915 919 } 916 920 917 - pti_tty_driver->owner = THIS_MODULE; 918 - pti_tty_driver->magic = TTY_DRIVER_MAGIC; 919 921 pti_tty_driver->driver_name = DRIVERNAME; 920 922 pti_tty_driver->name = TTYNAME; 921 923 pti_tty_driver->major = 0; 922 924 pti_tty_driver->minor_start = PTITTY_MINOR_START; 923 - pti_tty_driver->minor_num = PTITTY_MINOR_NUM; 924 - pti_tty_driver->num = PTITTY_MINOR_NUM; 925 925 pti_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM; 926 926 pti_tty_driver->subtype = SYSTEM_TYPE_SYSCONS; 927 927 pti_tty_driver->flags = TTY_DRIVER_REAL_RAW |
+3 -7
drivers/mmc/card/sdio_uart.c
··· 750 750 { 751 751 int idx = tty->index; 752 752 struct sdio_uart_port *port = sdio_uart_port_get(idx); 753 - int ret = tty_init_termios(tty); 753 + int ret = tty_standard_install(driver, tty); 754 754 755 - if (ret == 0) { 756 - tty_driver_kref_get(driver); 757 - tty->count++; 755 + if (ret == 0) 758 756 /* This is the ref sdio_uart_port get provided */ 759 757 tty->driver_data = port; 760 - driver->ttys[idx] = tty; 761 - } else 758 + else 762 759 sdio_uart_port_put(port); 763 760 return ret; 764 761 } ··· 1175 1178 if (!tty_drv) 1176 1179 return -ENOMEM; 1177 1180 1178 - tty_drv->owner = THIS_MODULE; 1179 1181 tty_drv->driver_name = "sdio_uart"; 1180 1182 tty_drv->name = "ttySDIO"; 1181 1183 tty_drv->major = 0; /* dynamically allocated */
-2
drivers/net/usb/hso.c
··· 3313 3313 3314 3314 /* fill in all needed values */ 3315 3315 tty_drv->magic = TTY_DRIVER_MAGIC; 3316 - tty_drv->owner = THIS_MODULE; 3317 3316 tty_drv->driver_name = driver_name; 3318 3317 tty_drv->name = tty_filename; 3319 3318 ··· 3321 3322 tty_drv->major = tty_major; 3322 3323 3323 3324 tty_drv->minor_start = 0; 3324 - tty_drv->num = HSO_SERIAL_TTY_MINORS; 3325 3325 tty_drv->type = TTY_DRIVER_TYPE_SERIAL; 3326 3326 tty_drv->subtype = SERIAL_TYPE_NORMAL; 3327 3327 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+2 -11
drivers/net/wan/pc300_drv.c
··· 299 299 void cpc_tty_unregister_service(pc300dev_t * pc300dev); 300 300 void cpc_tty_receive(pc300dev_t * pc300dev); 301 301 void cpc_tty_trigger_poll(pc300dev_t * pc300dev); 302 - void cpc_tty_reset_var(void); 303 302 #endif 304 303 305 304 /************************/ ··· 3231 3232 3232 3233 } 3233 3234 3234 - static inline void show_version(void) 3235 + static void show_version(void) 3235 3236 { 3236 3237 char *rcsvers, *rcsdate, *tmp; 3237 3238 ··· 3412 3413 static int __devinit 3413 3414 cpc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 3414 3415 { 3415 - static int first_time = 1; 3416 3416 int err, eeprom_outdated = 0; 3417 3417 u16 device_id; 3418 3418 pc300_t *card; 3419 - 3420 - if (first_time) { 3421 - first_time = 0; 3422 - show_version(); 3423 - #ifdef CONFIG_PC300_MLPPP 3424 - cpc_tty_reset_var(); 3425 - #endif 3426 - } 3427 3419 3428 3420 if ((err = pci_enable_device(pdev)) < 0) 3429 3421 return err; ··· 3651 3661 3652 3662 static int __init cpc_init(void) 3653 3663 { 3664 + show_version(); 3654 3665 return pci_register_driver(&cpc_driver); 3655 3666 } 3656 3667
-18
drivers/net/wan/pc300_tty.c
··· 139 139 void cpc_tty_unregister_service(pc300dev_t *pc300dev); 140 140 void cpc_tty_receive(pc300dev_t *pc300dev); 141 141 void cpc_tty_trigger_poll(pc300dev_t *pc300dev); 142 - void cpc_tty_reset_var(void); 143 142 144 143 /* 145 144 * PC300 TTY clear "signal" ··· 1077 1078 } 1078 1079 schedule_work(&(cpc_tty->tty_tx_work)); 1079 1080 } 1080 - 1081 - /* 1082 - * PC300 TTY reset var routine 1083 - * This routine is called by pc300driver to init the TTY area. 1084 - */ 1085 - 1086 - void cpc_tty_reset_var(void) 1087 - { 1088 - int i ; 1089 - 1090 - CPC_TTY_DBG("hdlcX-tty: reset variables\n"); 1091 - /* reset the tty_driver structure - serial_drv */ 1092 - memset(&serial_drv, 0, sizeof(struct tty_driver)); 1093 - for (i=0; i < CPC_TTY_NPORTS; i++){ 1094 - memset(&cpc_tty_area[i],0, sizeof(st_cpc_tty_area)); 1095 - } 1096 - }
+2 -7
drivers/s390/char/con3215.c
··· 933 933 static int tty3215_open(struct tty_struct *tty, struct file * filp) 934 934 { 935 935 struct raw3215_info *raw; 936 - int retval, line; 936 + int retval; 937 937 938 - line = tty->index; 939 - if ((line < 0) || (line >= NR_3215)) 940 - return -ENODEV; 941 - 942 - raw = raw3215[line]; 938 + raw = raw3215[tty->index]; 943 939 if (raw == NULL) 944 940 return -ENODEV; 945 941 ··· 1141 1145 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc 1142 1146 */ 1143 1147 1144 - driver->owner = THIS_MODULE; 1145 1148 driver->driver_name = "tty3215"; 1146 1149 driver->name = "ttyS"; 1147 1150 driver->major = TTY_MAJOR;
-1
drivers/s390/char/sclp_tty.c
··· 551 551 return rc; 552 552 } 553 553 554 - driver->owner = THIS_MODULE; 555 554 driver->driver_name = "sclp_line"; 556 555 driver->name = "sclp_line"; 557 556 driver->major = TTY_MAJOR;
-1
drivers/s390/char/sclp_vt220.c
··· 685 685 if (rc) 686 686 goto out_driver; 687 687 688 - driver->owner = THIS_MODULE; 689 688 driver->driver_name = SCLP_VT220_DRIVER_NAME; 690 689 driver->name = SCLP_VT220_DEVICE_NAME; 691 690 driver->major = SCLP_VT220_MAJOR;
-1
drivers/s390/char/tty3270.c
··· 1784 1784 * Entries in tty3270_driver that are NOT initialized: 1785 1785 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc 1786 1786 */ 1787 - driver->owner = THIS_MODULE; 1788 1787 driver->driver_name = "ttyTUB"; 1789 1788 driver->name = "ttyTUB"; 1790 1789 driver->major = IBM_TTY3270_MAJOR;
+4 -4
drivers/staging/speakup/main.c
··· 1731 1731 switch (value) { 1732 1732 case KVAL(K_CAPS): 1733 1733 label = msg_get(MSG_KEYNAME_CAPSLOCK); 1734 - on_off = (vc_kbd_led(kbd_table + vc->vc_num, VC_CAPSLOCK)); 1734 + on_off = vt_get_leds(fg_console, VC_CAPSLOCK); 1735 1735 break; 1736 1736 case KVAL(K_NUM): 1737 1737 label = msg_get(MSG_KEYNAME_NUMLOCK); 1738 - on_off = (vc_kbd_led(kbd_table + vc->vc_num, VC_NUMLOCK)); 1738 + on_off = vt_get_leds(fg_console, VC_NUMLOCK); 1739 1739 break; 1740 1740 case KVAL(K_HOLD): 1741 1741 label = msg_get(MSG_KEYNAME_SCROLLLOCK); 1742 - on_off = (vc_kbd_led(kbd_table + vc->vc_num, VC_SCROLLOCK)); 1742 + on_off = vt_get_leds(fg_console, VC_SCROLLOCK); 1743 1743 if (speakup_console[vc->vc_num]) 1744 1744 speakup_console[vc->vc_num]->tty_stopped = on_off; 1745 1745 break; ··· 2020 2020 if (type >= 0xf0) 2021 2021 type -= 0xf0; 2022 2022 if (type == KT_PAD 2023 - && (vc_kbd_led(kbd_table + fg_console, VC_NUMLOCK))) { 2023 + && (vt_get_leds(fg_console, VC_NUMLOCK))) { 2024 2024 if (up_flag) { 2025 2025 spk_keydown = 0; 2026 2026 goto out;
+5 -6
drivers/staging/speakup/serialio.c
··· 8 8 9 9 static void start_serial_interrupt(int irq); 10 10 11 - static struct serial_state rs_table[] = { 11 + static const struct old_serial_port rs_table[] = { 12 12 SERIAL_PORT_DFNS 13 13 }; 14 - static struct serial_state *serstate; 14 + static const struct old_serial_port *serstate; 15 15 static int timeouts; 16 16 17 - struct serial_state *spk_serial_init(int index) 17 + const struct old_serial_port *spk_serial_init(int index) 18 18 { 19 19 int baud = 9600, quot = 0; 20 20 unsigned int cval = 0; 21 21 int cflag = CREAD | HUPCL | CLOCAL | B9600 | CS8; 22 - struct serial_state *ser = NULL; 22 + const struct old_serial_port *ser = rs_table + index; 23 23 int err; 24 24 25 - ser = rs_table + index; 26 25 /* Divisor, bytesize and parity */ 27 26 quot = ser->baud_base / baud; 28 27 cval = cflag & (CSIZE | CSTOPB); ··· 40 41 __release_region(&ioport_resource, ser->port, 8); 41 42 err = synth_request_region(ser->port, 8); 42 43 if (err) { 43 - pr_warn("Unable to allocate port at %lx, errno %i", 44 + pr_warn("Unable to allocate port at %x, errno %i", 44 45 ser->port, err); 45 46 return NULL; 46 47 }
+12 -1
drivers/staging/speakup/serialio.h
··· 4 4 #include <linux/serial.h> /* for rs_table, serial constants & 5 5 serial_uart_config */ 6 6 #include <linux/serial_reg.h> /* for more serial constants */ 7 - #include <linux/serialP.h> /* for struct serial_state */ 8 7 #ifndef __sparc__ 9 8 #include <asm/serial.h> 10 9 #endif 10 + 11 + /* 12 + * this is cut&paste from 8250.h. Get rid of the structure, the definitions 13 + * and this whole broken driver. 14 + */ 15 + struct old_serial_port { 16 + unsigned int uart; /* unused */ 17 + unsigned int baud_base; 18 + unsigned int port; 19 + unsigned int irq; 20 + unsigned int flags; /* unused */ 21 + }; 11 22 12 23 /* countdown values for serial timeouts in us */ 13 24 #define SPK_SERIAL_TIMEOUT 100000
+1 -1
drivers/staging/speakup/spk_priv.h
··· 44 44 45 45 #define KT_SPKUP 15 46 46 47 - extern struct serial_state *spk_serial_init(int index); 47 + extern const struct old_serial_port *spk_serial_init(int index); 48 48 extern void stop_serial_interrupt(void); 49 49 extern int wait_for_xmitr(void); 50 50 extern unsigned char spk_serial_in(void);
+1 -1
drivers/staging/speakup/synth.c
··· 34 34 35 35 int serial_synth_probe(struct spk_synth *synth) 36 36 { 37 - struct serial_state *ser; 37 + const struct old_serial_port *ser; 38 38 int failed = 0; 39 39 40 40 if ((synth->ser >= SPK_LO_TTY) && (synth->ser <= SPK_HI_TTY)) {
+222 -508
drivers/tty/amiserial.c
··· 45 45 46 46 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT) 47 47 #define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \ 48 - tty->name, (info->flags), serial_driver->refcount,info->count,tty->count,s) 48 + tty->name, (info->tport.flags), serial_driver->refcount,info->count,tty->count,s) 49 49 #else 50 50 #define DBG_CNT(s) 51 51 #endif ··· 58 58 59 59 #include <linux/types.h> 60 60 #include <linux/serial.h> 61 - #include <linux/serialP.h> 62 61 #include <linux/serial_reg.h> 63 62 static char *serial_version = "4.30"; 64 63 ··· 69 70 #include <linux/interrupt.h> 70 71 #include <linux/tty.h> 71 72 #include <linux/tty_flip.h> 73 + #include <linux/circ_buf.h> 72 74 #include <linux/console.h> 73 75 #include <linux/major.h> 74 76 #include <linux/string.h> ··· 92 92 #include <asm/amigahw.h> 93 93 #include <asm/amigaints.h> 94 94 95 + struct serial_state { 96 + struct tty_port tport; 97 + struct circ_buf xmit; 98 + struct async_icount icount; 99 + 100 + unsigned long port; 101 + int baud_base; 102 + int xmit_fifo_size; 103 + int custom_divisor; 104 + int read_status_mask; 105 + int ignore_status_mask; 106 + int timeout; 107 + int quot; 108 + int IER; /* Interrupt Enable Register */ 109 + int MCR; /* Modem control register */ 110 + int x_char; /* xon/xoff character */ 111 + }; 112 + 95 113 #define custom amiga_custom 96 114 static char *serial_name = "Amiga-builtin serial driver"; 97 115 ··· 118 100 /* number of characters left in xmit buffer before we ask for more */ 119 101 #define WAKEUP_CHARS 256 120 102 121 - static struct async_struct *IRQ_ports; 122 - 123 103 static unsigned char current_ctl_bits; 124 104 125 - static void change_speed(struct async_struct *info, struct ktermios *old); 105 + static void change_speed(struct tty_struct *tty, struct serial_state *info, 106 + struct ktermios *old); 126 107 static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 127 108 128 109 ··· 134 117 #define serial_isroot() (capable(CAP_SYS_ADMIN)) 135 118 136 119 137 - static inline int serial_paranoia_check(struct async_struct *info, 120 + static inline int serial_paranoia_check(struct serial_state *info, 138 121 char *name, const char *routine) 139 122 { 140 123 #ifdef SERIAL_PARANOIA_CHECK ··· 187 170 */ 188 171 static void rs_stop(struct tty_struct *tty) 189 172 { 190 - struct async_struct *info = tty->driver_data; 173 + struct serial_state *info = tty->driver_data; 191 174 unsigned long flags; 192 175 193 176 if (serial_paranoia_check(info, tty->name, "rs_stop")) ··· 207 190 208 191 static void rs_start(struct tty_struct *tty) 209 192 { 210 - struct async_struct *info = tty->driver_data; 193 + struct serial_state *info = tty->driver_data; 211 194 unsigned long flags; 212 195 213 196 if (serial_paranoia_check(info, tty->name, "rs_start")) ··· 248 231 * ----------------------------------------------------------------------- 249 232 */ 250 233 251 - /* 252 - * This routine is used by the interrupt handler to schedule 253 - * processing in the software interrupt portion of the driver. 254 - */ 255 - static void rs_sched_event(struct async_struct *info, 256 - int event) 257 - { 258 - info->event |= 1 << event; 259 - tasklet_schedule(&info->tlet); 260 - } 261 - 262 - static void receive_chars(struct async_struct *info) 234 + static void receive_chars(struct serial_state *info) 263 235 { 264 236 int status; 265 237 int serdatr; 266 - struct tty_struct *tty = info->tty; 238 + struct tty_struct *tty = info->tport.tty; 267 239 unsigned char ch, flag; 268 240 struct async_icount *icount; 269 241 int oe = 0; 270 242 271 - icount = &info->state->icount; 243 + icount = &info->icount; 272 244 273 245 status = UART_LSR_DR; /* We obviously have a character! */ 274 246 serdatr = custom.serdatr; ··· 314 308 printk("handling break...."); 315 309 #endif 316 310 flag = TTY_BREAK; 317 - if (info->flags & ASYNC_SAK) 311 + if (info->tport.flags & ASYNC_SAK) 318 312 do_SAK(tty); 319 313 } else if (status & UART_LSR_PE) 320 314 flag = TTY_PARITY; ··· 337 331 return; 338 332 } 339 333 340 - static void transmit_chars(struct async_struct *info) 334 + static void transmit_chars(struct serial_state *info) 341 335 { 342 336 custom.intreq = IF_TBE; 343 337 mb(); 344 338 if (info->x_char) { 345 339 custom.serdat = info->x_char | 0x100; 346 340 mb(); 347 - info->state->icount.tx++; 341 + info->icount.tx++; 348 342 info->x_char = 0; 349 343 return; 350 344 } 351 345 if (info->xmit.head == info->xmit.tail 352 - || info->tty->stopped 353 - || info->tty->hw_stopped) { 346 + || info->tport.tty->stopped 347 + || info->tport.tty->hw_stopped) { 354 348 info->IER &= ~UART_IER_THRI; 355 349 custom.intena = IF_TBE; 356 350 mb(); ··· 360 354 custom.serdat = info->xmit.buf[info->xmit.tail++] | 0x100; 361 355 mb(); 362 356 info->xmit.tail = info->xmit.tail & (SERIAL_XMIT_SIZE-1); 363 - info->state->icount.tx++; 357 + info->icount.tx++; 364 358 365 359 if (CIRC_CNT(info->xmit.head, 366 360 info->xmit.tail, 367 361 SERIAL_XMIT_SIZE) < WAKEUP_CHARS) 368 - rs_sched_event(info, RS_EVENT_WRITE_WAKEUP); 362 + tty_wakeup(info->tport.tty); 369 363 370 364 #ifdef SERIAL_DEBUG_INTR 371 365 printk("THRE..."); ··· 377 371 } 378 372 } 379 373 380 - static void check_modem_status(struct async_struct *info) 374 + static void check_modem_status(struct serial_state *info) 381 375 { 376 + struct tty_port *port = &info->tport; 382 377 unsigned char status = ciab.pra & (SER_DCD | SER_CTS | SER_DSR); 383 378 unsigned char dstatus; 384 379 struct async_icount *icount; ··· 389 382 current_ctl_bits = status; 390 383 391 384 if (dstatus) { 392 - icount = &info->state->icount; 385 + icount = &info->icount; 393 386 /* update input line counters */ 394 387 if (dstatus & SER_DSR) 395 388 icount->dsr++; 396 389 if (dstatus & SER_DCD) { 397 390 icount->dcd++; 398 391 #ifdef CONFIG_HARD_PPS 399 - if ((info->flags & ASYNC_HARDPPS_CD) && 392 + if ((port->flags & ASYNC_HARDPPS_CD) && 400 393 !(status & SER_DCD)) 401 394 hardpps(); 402 395 #endif 403 396 } 404 397 if (dstatus & SER_CTS) 405 398 icount->cts++; 406 - wake_up_interruptible(&info->delta_msr_wait); 399 + wake_up_interruptible(&port->delta_msr_wait); 407 400 } 408 401 409 - if ((info->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) { 402 + if ((port->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) { 410 403 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR)) 411 404 printk("ttyS%d CD now %s...", info->line, 412 405 (!(status & SER_DCD)) ? "on" : "off"); 413 406 #endif 414 407 if (!(status & SER_DCD)) 415 - wake_up_interruptible(&info->open_wait); 408 + wake_up_interruptible(&port->open_wait); 416 409 else { 417 410 #ifdef SERIAL_DEBUG_OPEN 418 411 printk("doing serial hangup..."); 419 412 #endif 420 - if (info->tty) 421 - tty_hangup(info->tty); 413 + if (port->tty) 414 + tty_hangup(port->tty); 422 415 } 423 416 } 424 - if (info->flags & ASYNC_CTS_FLOW) { 425 - if (info->tty->hw_stopped) { 417 + if (port->flags & ASYNC_CTS_FLOW) { 418 + if (port->tty->hw_stopped) { 426 419 if (!(status & SER_CTS)) { 427 420 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW)) 428 421 printk("CTS tx start..."); 429 422 #endif 430 - info->tty->hw_stopped = 0; 423 + port->tty->hw_stopped = 0; 431 424 info->IER |= UART_IER_THRI; 432 425 custom.intena = IF_SETCLR | IF_TBE; 433 426 mb(); 434 427 /* set a pending Tx Interrupt, transmitter should restart now */ 435 428 custom.intreq = IF_SETCLR | IF_TBE; 436 429 mb(); 437 - rs_sched_event(info, RS_EVENT_WRITE_WAKEUP); 430 + tty_wakeup(port->tty); 438 431 return; 439 432 } 440 433 } else { ··· 442 435 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW)) 443 436 printk("CTS tx stop..."); 444 437 #endif 445 - info->tty->hw_stopped = 1; 438 + port->tty->hw_stopped = 1; 446 439 info->IER &= ~UART_IER_THRI; 447 440 /* disable Tx interrupt and remove any pending interrupts */ 448 441 custom.intena = IF_TBE; ··· 457 450 static irqreturn_t ser_vbl_int( int irq, void *data) 458 451 { 459 452 /* vbl is just a periodic interrupt we tie into to update modem status */ 460 - struct async_struct * info = IRQ_ports; 453 + struct serial_state *info = data; 461 454 /* 462 455 * TBD - is it better to unregister from this interrupt or to 463 456 * ignore it if MSI is clear ? ··· 469 462 470 463 static irqreturn_t ser_rx_int(int irq, void *dev_id) 471 464 { 472 - struct async_struct * info; 465 + struct serial_state *info = dev_id; 473 466 474 467 #ifdef SERIAL_DEBUG_INTR 475 468 printk("ser_rx_int..."); 476 469 #endif 477 470 478 - info = IRQ_ports; 479 - if (!info || !info->tty) 471 + if (!info->tport.tty) 480 472 return IRQ_NONE; 481 473 482 474 receive_chars(info); 483 - info->last_active = jiffies; 484 475 #ifdef SERIAL_DEBUG_INTR 485 476 printk("end.\n"); 486 477 #endif ··· 487 482 488 483 static irqreturn_t ser_tx_int(int irq, void *dev_id) 489 484 { 490 - struct async_struct * info; 485 + struct serial_state *info = dev_id; 491 486 492 487 if (custom.serdatr & SDR_TBE) { 493 488 #ifdef SERIAL_DEBUG_INTR 494 489 printk("ser_tx_int..."); 495 490 #endif 496 491 497 - info = IRQ_ports; 498 - if (!info || !info->tty) 492 + if (!info->tport.tty) 499 493 return IRQ_NONE; 500 494 501 495 transmit_chars(info); 502 - info->last_active = jiffies; 503 496 #ifdef SERIAL_DEBUG_INTR 504 497 printk("end.\n"); 505 498 #endif ··· 512 509 */ 513 510 514 511 /* 515 - * This routine is used to handle the "bottom half" processing for the 516 - * serial driver, known also the "software interrupt" processing. 517 - * This processing is done at the kernel interrupt level, after the 518 - * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This 519 - * is where time-consuming activities which can not be done in the 520 - * interrupt driver proper are done; the interrupt driver schedules 521 - * them using rs_sched_event(), and they get done here. 522 - */ 523 - 524 - static void do_softint(unsigned long private_) 525 - { 526 - struct async_struct *info = (struct async_struct *) private_; 527 - struct tty_struct *tty; 528 - 529 - tty = info->tty; 530 - if (!tty) 531 - return; 532 - 533 - if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) 534 - tty_wakeup(tty); 535 - } 536 - 537 - /* 538 512 * --------------------------------------------------------------- 539 513 * Low level utility subroutines for the serial driver: routines to 540 514 * figure out the appropriate timeout for an interrupt chain, routines ··· 520 540 * --------------------------------------------------------------- 521 541 */ 522 542 523 - static int startup(struct async_struct * info) 543 + static int startup(struct tty_struct *tty, struct serial_state *info) 524 544 { 545 + struct tty_port *port = &info->tport; 525 546 unsigned long flags; 526 547 int retval=0; 527 548 unsigned long page; ··· 533 552 534 553 local_irq_save(flags); 535 554 536 - if (info->flags & ASYNC_INITIALIZED) { 555 + if (port->flags & ASYNC_INITIALIZED) { 537 556 free_page(page); 538 557 goto errout; 539 558 } ··· 555 574 retval = request_irq(IRQ_AMIGA_VERTB, ser_vbl_int, 0, "serial status", info); 556 575 if (retval) { 557 576 if (serial_isroot()) { 558 - if (info->tty) 559 - set_bit(TTY_IO_ERROR, 560 - &info->tty->flags); 577 + set_bit(TTY_IO_ERROR, &tty->flags); 561 578 retval = 0; 562 579 } 563 580 goto errout; ··· 569 590 /* remember current state of the DCD and CTS bits */ 570 591 current_ctl_bits = ciab.pra & (SER_DCD | SER_CTS | SER_DSR); 571 592 572 - IRQ_ports = info; 573 - 574 593 info->MCR = 0; 575 - if (info->tty->termios->c_cflag & CBAUD) 594 + if (C_BAUD(tty)) 576 595 info->MCR = SER_DTR | SER_RTS; 577 596 rtsdtr_ctrl(info->MCR); 578 597 579 - if (info->tty) 580 - clear_bit(TTY_IO_ERROR, &info->tty->flags); 598 + clear_bit(TTY_IO_ERROR, &tty->flags); 581 599 info->xmit.head = info->xmit.tail = 0; 582 600 583 601 /* 584 602 * Set up the tty->alt_speed kludge 585 603 */ 586 - if (info->tty) { 587 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 588 - info->tty->alt_speed = 57600; 589 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 590 - info->tty->alt_speed = 115200; 591 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 592 - info->tty->alt_speed = 230400; 593 - if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 594 - info->tty->alt_speed = 460800; 595 - } 604 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 605 + tty->alt_speed = 57600; 606 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 607 + tty->alt_speed = 115200; 608 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 609 + tty->alt_speed = 230400; 610 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 611 + tty->alt_speed = 460800; 596 612 597 613 /* 598 614 * and set the speed of the serial port 599 615 */ 600 - change_speed(info, NULL); 616 + change_speed(tty, info, NULL); 601 617 602 - info->flags |= ASYNC_INITIALIZED; 618 + port->flags |= ASYNC_INITIALIZED; 603 619 local_irq_restore(flags); 604 620 return 0; 605 621 ··· 607 633 * This routine will shutdown a serial port; interrupts are disabled, and 608 634 * DTR is dropped if the hangup on close termio flag is on. 609 635 */ 610 - static void shutdown(struct async_struct * info) 636 + static void shutdown(struct tty_struct *tty, struct serial_state *info) 611 637 { 612 638 unsigned long flags; 613 639 struct serial_state *state; 614 640 615 - if (!(info->flags & ASYNC_INITIALIZED)) 641 + if (!(info->tport.flags & ASYNC_INITIALIZED)) 616 642 return; 617 643 618 - state = info->state; 644 + state = info; 619 645 620 646 #ifdef SERIAL_DEBUG_OPEN 621 647 printk("Shutting down serial port %d ....\n", info->line); ··· 627 653 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq 628 654 * here so the queue might never be waken up 629 655 */ 630 - wake_up_interruptible(&info->delta_msr_wait); 631 - 632 - IRQ_ports = NULL; 656 + wake_up_interruptible(&info->tport.delta_msr_wait); 633 657 634 658 /* 635 659 * Free the IRQ, if necessary ··· 647 675 custom.adkcon = AC_UARTBRK; 648 676 mb(); 649 677 650 - if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) 678 + if (tty->termios->c_cflag & HUPCL) 651 679 info->MCR &= ~(SER_DTR|SER_RTS); 652 680 rtsdtr_ctrl(info->MCR); 653 681 654 - if (info->tty) 655 - set_bit(TTY_IO_ERROR, &info->tty->flags); 682 + set_bit(TTY_IO_ERROR, &tty->flags); 656 683 657 - info->flags &= ~ASYNC_INITIALIZED; 684 + info->tport.flags &= ~ASYNC_INITIALIZED; 658 685 local_irq_restore(flags); 659 686 } 660 687 ··· 662 691 * This routine is called to set the UART divisor registers to match 663 692 * the specified baud rate for a serial port. 664 693 */ 665 - static void change_speed(struct async_struct *info, 694 + static void change_speed(struct tty_struct *tty, struct serial_state *info, 666 695 struct ktermios *old_termios) 667 696 { 697 + struct tty_port *port = &info->tport; 668 698 int quot = 0, baud_base, baud; 669 699 unsigned cflag, cval = 0; 670 700 int bits; 671 701 unsigned long flags; 672 702 673 - if (!info->tty || !info->tty->termios) 674 - return; 675 - cflag = info->tty->termios->c_cflag; 703 + cflag = tty->termios->c_cflag; 676 704 677 705 /* Byte size is always 8 bits plus parity bit if requested */ 678 706 ··· 692 722 #endif 693 723 694 724 /* Determine divisor based on baud rate */ 695 - baud = tty_get_baud_rate(info->tty); 725 + baud = tty_get_baud_rate(tty); 696 726 if (!baud) 697 727 baud = 9600; /* B0 transition handled in rs_set_termios */ 698 - baud_base = info->state->baud_base; 699 - if (baud == 38400 && 700 - ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) 701 - quot = info->state->custom_divisor; 728 + baud_base = info->baud_base; 729 + if (baud == 38400 && (port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) 730 + quot = info->custom_divisor; 702 731 else { 703 732 if (baud == 134) 704 733 /* Special case since 134 is really 134.5 */ ··· 708 739 /* If the quotient is zero refuse the change */ 709 740 if (!quot && old_termios) { 710 741 /* FIXME: Will need updating for new tty in the end */ 711 - info->tty->termios->c_cflag &= ~CBAUD; 712 - info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD); 713 - baud = tty_get_baud_rate(info->tty); 742 + tty->termios->c_cflag &= ~CBAUD; 743 + tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD); 744 + baud = tty_get_baud_rate(tty); 714 745 if (!baud) 715 746 baud = 9600; 716 747 if (baud == 38400 && 717 - ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) 718 - quot = info->state->custom_divisor; 748 + (port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) 749 + quot = info->custom_divisor; 719 750 else { 720 751 if (baud == 134) 721 752 /* Special case since 134 is really 134.5 */ ··· 733 764 734 765 /* CTS flow control flag and modem status interrupts */ 735 766 info->IER &= ~UART_IER_MSI; 736 - if (info->flags & ASYNC_HARDPPS_CD) 767 + if (port->flags & ASYNC_HARDPPS_CD) 737 768 info->IER |= UART_IER_MSI; 738 769 if (cflag & CRTSCTS) { 739 - info->flags |= ASYNC_CTS_FLOW; 770 + port->flags |= ASYNC_CTS_FLOW; 740 771 info->IER |= UART_IER_MSI; 741 772 } else 742 - info->flags &= ~ASYNC_CTS_FLOW; 773 + port->flags &= ~ASYNC_CTS_FLOW; 743 774 if (cflag & CLOCAL) 744 - info->flags &= ~ASYNC_CHECK_CD; 775 + port->flags &= ~ASYNC_CHECK_CD; 745 776 else { 746 - info->flags |= ASYNC_CHECK_CD; 777 + port->flags |= ASYNC_CHECK_CD; 747 778 info->IER |= UART_IER_MSI; 748 779 } 749 780 /* TBD: ··· 755 786 */ 756 787 757 788 info->read_status_mask = UART_LSR_OE | UART_LSR_DR; 758 - if (I_INPCK(info->tty)) 789 + if (I_INPCK(tty)) 759 790 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 760 - if (I_BRKINT(info->tty) || I_PARMRK(info->tty)) 791 + if (I_BRKINT(tty) || I_PARMRK(tty)) 761 792 info->read_status_mask |= UART_LSR_BI; 762 793 763 794 /* 764 795 * Characters to ignore 765 796 */ 766 797 info->ignore_status_mask = 0; 767 - if (I_IGNPAR(info->tty)) 798 + if (I_IGNPAR(tty)) 768 799 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 769 - if (I_IGNBRK(info->tty)) { 800 + if (I_IGNBRK(tty)) { 770 801 info->ignore_status_mask |= UART_LSR_BI; 771 802 /* 772 803 * If we're ignore parity and break indicators, ignore 773 804 * overruns too. (For real raw support). 774 805 */ 775 - if (I_IGNPAR(info->tty)) 806 + if (I_IGNPAR(tty)) 776 807 info->ignore_status_mask |= UART_LSR_OE; 777 808 } 778 809 /* ··· 797 828 mb(); 798 829 } 799 830 800 - info->LCR = cval; /* Save LCR */ 801 831 local_irq_restore(flags); 802 832 } 803 833 804 834 static int rs_put_char(struct tty_struct *tty, unsigned char ch) 805 835 { 806 - struct async_struct *info; 836 + struct serial_state *info; 807 837 unsigned long flags; 808 838 809 839 info = tty->driver_data; ··· 829 861 830 862 static void rs_flush_chars(struct tty_struct *tty) 831 863 { 832 - struct async_struct *info = tty->driver_data; 864 + struct serial_state *info = tty->driver_data; 833 865 unsigned long flags; 834 866 835 867 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) ··· 854 886 static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count) 855 887 { 856 888 int c, ret = 0; 857 - struct async_struct *info; 889 + struct serial_state *info = tty->driver_data; 858 890 unsigned long flags; 859 - 860 - info = tty->driver_data; 861 891 862 892 if (serial_paranoia_check(info, tty->name, "rs_write")) 863 893 return 0; ··· 900 934 901 935 static int rs_write_room(struct tty_struct *tty) 902 936 { 903 - struct async_struct *info = tty->driver_data; 937 + struct serial_state *info = tty->driver_data; 904 938 905 939 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 906 940 return 0; ··· 909 943 910 944 static int rs_chars_in_buffer(struct tty_struct *tty) 911 945 { 912 - struct async_struct *info = tty->driver_data; 946 + struct serial_state *info = tty->driver_data; 913 947 914 948 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 915 949 return 0; ··· 918 952 919 953 static void rs_flush_buffer(struct tty_struct *tty) 920 954 { 921 - struct async_struct *info = tty->driver_data; 955 + struct serial_state *info = tty->driver_data; 922 956 unsigned long flags; 923 957 924 958 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) ··· 935 969 */ 936 970 static void rs_send_xchar(struct tty_struct *tty, char ch) 937 971 { 938 - struct async_struct *info = tty->driver_data; 972 + struct serial_state *info = tty->driver_data; 939 973 unsigned long flags; 940 974 941 975 if (serial_paranoia_check(info, tty->name, "rs_send_char")) ··· 970 1004 */ 971 1005 static void rs_throttle(struct tty_struct * tty) 972 1006 { 973 - struct async_struct *info = tty->driver_data; 1007 + struct serial_state *info = tty->driver_data; 974 1008 unsigned long flags; 975 1009 #ifdef SERIAL_DEBUG_THROTTLE 976 1010 char buf[64]; ··· 995 1029 996 1030 static void rs_unthrottle(struct tty_struct * tty) 997 1031 { 998 - struct async_struct *info = tty->driver_data; 1032 + struct serial_state *info = tty->driver_data; 999 1033 unsigned long flags; 1000 1034 #ifdef SERIAL_DEBUG_THROTTLE 1001 1035 char buf[64]; ··· 1026 1060 * ------------------------------------------------------------ 1027 1061 */ 1028 1062 1029 - static int get_serial_info(struct async_struct * info, 1063 + static int get_serial_info(struct tty_struct *tty, struct serial_state *state, 1030 1064 struct serial_struct __user * retinfo) 1031 1065 { 1032 1066 struct serial_struct tmp; 1033 - struct serial_state *state = info->state; 1034 1067 1035 1068 if (!retinfo) 1036 1069 return -EFAULT; 1037 1070 memset(&tmp, 0, sizeof(tmp)); 1038 1071 tty_lock(); 1039 - tmp.type = state->type; 1040 - tmp.line = state->line; 1072 + tmp.line = tty->index; 1041 1073 tmp.port = state->port; 1042 - tmp.irq = state->irq; 1043 - tmp.flags = state->flags; 1074 + tmp.flags = state->tport.flags; 1044 1075 tmp.xmit_fifo_size = state->xmit_fifo_size; 1045 1076 tmp.baud_base = state->baud_base; 1046 - tmp.close_delay = state->close_delay; 1047 - tmp.closing_wait = state->closing_wait; 1077 + tmp.close_delay = state->tport.close_delay; 1078 + tmp.closing_wait = state->tport.closing_wait; 1048 1079 tmp.custom_divisor = state->custom_divisor; 1049 1080 tty_unlock(); 1050 1081 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) ··· 1049 1086 return 0; 1050 1087 } 1051 1088 1052 - static int set_serial_info(struct async_struct * info, 1089 + static int set_serial_info(struct tty_struct *tty, struct serial_state *state, 1053 1090 struct serial_struct __user * new_info) 1054 1091 { 1092 + struct tty_port *port = &state->tport; 1055 1093 struct serial_struct new_serial; 1056 - struct serial_state old_state, *state; 1057 - unsigned int change_irq,change_port; 1094 + bool change_spd; 1058 1095 int retval = 0; 1059 1096 1060 1097 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1061 1098 return -EFAULT; 1062 1099 1063 1100 tty_lock(); 1064 - state = info->state; 1065 - old_state = *state; 1066 - 1067 - change_irq = new_serial.irq != state->irq; 1068 - change_port = (new_serial.port != state->port); 1069 - if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) { 1070 - tty_unlock(); 1071 - return -EINVAL; 1101 + change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || 1102 + new_serial.custom_divisor != state->custom_divisor; 1103 + if (new_serial.irq || new_serial.port != state->port || 1104 + new_serial.xmit_fifo_size != state->xmit_fifo_size) { 1105 + tty_unlock(); 1106 + return -EINVAL; 1072 1107 } 1073 1108 1074 1109 if (!serial_isroot()) { 1075 1110 if ((new_serial.baud_base != state->baud_base) || 1076 - (new_serial.close_delay != state->close_delay) || 1111 + (new_serial.close_delay != port->close_delay) || 1077 1112 (new_serial.xmit_fifo_size != state->xmit_fifo_size) || 1078 1113 ((new_serial.flags & ~ASYNC_USR_MASK) != 1079 - (state->flags & ~ASYNC_USR_MASK))) 1114 + (port->flags & ~ASYNC_USR_MASK))) 1080 1115 return -EPERM; 1081 - state->flags = ((state->flags & ~ASYNC_USR_MASK) | 1082 - (new_serial.flags & ASYNC_USR_MASK)); 1083 - info->flags = ((info->flags & ~ASYNC_USR_MASK) | 1116 + port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1084 1117 (new_serial.flags & ASYNC_USR_MASK)); 1085 1118 state->custom_divisor = new_serial.custom_divisor; 1086 1119 goto check_and_exit; ··· 1093 1134 */ 1094 1135 1095 1136 state->baud_base = new_serial.baud_base; 1096 - state->flags = ((state->flags & ~ASYNC_FLAGS) | 1137 + port->flags = ((port->flags & ~ASYNC_FLAGS) | 1097 1138 (new_serial.flags & ASYNC_FLAGS)); 1098 - info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) | 1099 - (info->flags & ASYNC_INTERNAL_FLAGS)); 1100 1139 state->custom_divisor = new_serial.custom_divisor; 1101 - state->close_delay = new_serial.close_delay * HZ/100; 1102 - state->closing_wait = new_serial.closing_wait * HZ/100; 1103 - info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1140 + port->close_delay = new_serial.close_delay * HZ/100; 1141 + port->closing_wait = new_serial.closing_wait * HZ/100; 1142 + tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1104 1143 1105 1144 check_and_exit: 1106 - if (info->flags & ASYNC_INITIALIZED) { 1107 - if (((old_state.flags & ASYNC_SPD_MASK) != 1108 - (state->flags & ASYNC_SPD_MASK)) || 1109 - (old_state.custom_divisor != state->custom_divisor)) { 1110 - if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1111 - info->tty->alt_speed = 57600; 1112 - if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1113 - info->tty->alt_speed = 115200; 1114 - if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 1115 - info->tty->alt_speed = 230400; 1116 - if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 1117 - info->tty->alt_speed = 460800; 1118 - change_speed(info, NULL); 1145 + if (port->flags & ASYNC_INITIALIZED) { 1146 + if (change_spd) { 1147 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1148 + tty->alt_speed = 57600; 1149 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1150 + tty->alt_speed = 115200; 1151 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 1152 + tty->alt_speed = 230400; 1153 + if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 1154 + tty->alt_speed = 460800; 1155 + change_speed(tty, state, NULL); 1119 1156 } 1120 1157 } else 1121 - retval = startup(info); 1158 + retval = startup(tty, state); 1122 1159 tty_unlock(); 1123 1160 return retval; 1124 1161 } ··· 1130 1175 * transmit holding register is empty. This functionality 1131 1176 * allows an RS485 driver to be written in user space. 1132 1177 */ 1133 - static int get_lsr_info(struct async_struct * info, unsigned int __user *value) 1178 + static int get_lsr_info(struct serial_state *info, unsigned int __user *value) 1134 1179 { 1135 1180 unsigned char status; 1136 1181 unsigned int result; ··· 1149 1194 1150 1195 static int rs_tiocmget(struct tty_struct *tty) 1151 1196 { 1152 - struct async_struct * info = tty->driver_data; 1197 + struct serial_state *info = tty->driver_data; 1153 1198 unsigned char control, status; 1154 1199 unsigned long flags; 1155 1200 ··· 1172 1217 static int rs_tiocmset(struct tty_struct *tty, unsigned int set, 1173 1218 unsigned int clear) 1174 1219 { 1175 - struct async_struct * info = tty->driver_data; 1220 + struct serial_state *info = tty->driver_data; 1176 1221 unsigned long flags; 1177 1222 1178 1223 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) ··· 1199 1244 */ 1200 1245 static int rs_break(struct tty_struct *tty, int break_state) 1201 1246 { 1202 - struct async_struct * info = tty->driver_data; 1247 + struct serial_state *info = tty->driver_data; 1203 1248 unsigned long flags; 1204 1249 1205 1250 if (serial_paranoia_check(info, tty->name, "rs_break")) ··· 1224 1269 static int rs_get_icount(struct tty_struct *tty, 1225 1270 struct serial_icounter_struct *icount) 1226 1271 { 1227 - struct async_struct *info = tty->driver_data; 1272 + struct serial_state *info = tty->driver_data; 1228 1273 struct async_icount cnow; 1229 1274 unsigned long flags; 1230 1275 1231 1276 local_irq_save(flags); 1232 - cnow = info->state->icount; 1277 + cnow = info->icount; 1233 1278 local_irq_restore(flags); 1234 1279 icount->cts = cnow.cts; 1235 1280 icount->dsr = cnow.dsr; ··· 1249 1294 static int rs_ioctl(struct tty_struct *tty, 1250 1295 unsigned int cmd, unsigned long arg) 1251 1296 { 1252 - struct async_struct * info = tty->driver_data; 1297 + struct serial_state *info = tty->driver_data; 1253 1298 struct async_icount cprev, cnow; /* kernel counter temps */ 1254 1299 void __user *argp = (void __user *)arg; 1255 1300 unsigned long flags; ··· 1266 1311 1267 1312 switch (cmd) { 1268 1313 case TIOCGSERIAL: 1269 - return get_serial_info(info, argp); 1314 + return get_serial_info(tty, info, argp); 1270 1315 case TIOCSSERIAL: 1271 - return set_serial_info(info, argp); 1316 + return set_serial_info(tty, info, argp); 1272 1317 case TIOCSERCONFIG: 1273 1318 return 0; 1274 1319 ··· 1277 1322 1278 1323 case TIOCSERGSTRUCT: 1279 1324 if (copy_to_user(argp, 1280 - info, sizeof(struct async_struct))) 1325 + info, sizeof(struct serial_state))) 1281 1326 return -EFAULT; 1282 1327 return 0; 1283 1328 ··· 1290 1335 case TIOCMIWAIT: 1291 1336 local_irq_save(flags); 1292 1337 /* note the counters on entry */ 1293 - cprev = info->state->icount; 1338 + cprev = info->icount; 1294 1339 local_irq_restore(flags); 1295 1340 while (1) { 1296 - interruptible_sleep_on(&info->delta_msr_wait); 1341 + interruptible_sleep_on(&info->tport.delta_msr_wait); 1297 1342 /* see if a signal did it */ 1298 1343 if (signal_pending(current)) 1299 1344 return -ERESTARTSYS; 1300 1345 local_irq_save(flags); 1301 - cnow = info->state->icount; /* atomic copy */ 1346 + cnow = info->icount; /* atomic copy */ 1302 1347 local_irq_restore(flags); 1303 1348 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 1304 1349 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) ··· 1327 1372 1328 1373 static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1329 1374 { 1330 - struct async_struct *info = tty->driver_data; 1375 + struct serial_state *info = tty->driver_data; 1331 1376 unsigned long flags; 1332 1377 unsigned int cflag = tty->termios->c_cflag; 1333 1378 1334 - change_speed(info, old_termios); 1379 + change_speed(tty, info, old_termios); 1335 1380 1336 1381 /* Handle transition to B0 status */ 1337 1382 if ((old_termios->c_cflag & CBAUD) && ··· 1387 1432 */ 1388 1433 static void rs_close(struct tty_struct *tty, struct file * filp) 1389 1434 { 1390 - struct async_struct * info = tty->driver_data; 1391 - struct serial_state *state; 1392 - unsigned long flags; 1435 + struct serial_state *state = tty->driver_data; 1436 + struct tty_port *port = &state->tport; 1393 1437 1394 - if (!info || serial_paranoia_check(info, tty->name, "rs_close")) 1438 + if (serial_paranoia_check(state, tty->name, "rs_close")) 1395 1439 return; 1396 1440 1397 - state = info->state; 1398 - 1399 - local_irq_save(flags); 1400 - 1401 - if (tty_hung_up_p(filp)) { 1402 - DBG_CNT("before DEC-hung"); 1403 - local_irq_restore(flags); 1441 + if (tty_port_close_start(port, tty, filp) == 0) 1404 1442 return; 1405 - } 1406 1443 1407 - #ifdef SERIAL_DEBUG_OPEN 1408 - printk("rs_close ttys%d, count = %d\n", info->line, state->count); 1409 - #endif 1410 - if ((tty->count == 1) && (state->count != 1)) { 1411 - /* 1412 - * Uh, oh. tty->count is 1, which means that the tty 1413 - * structure will be freed. state->count should always 1414 - * be one in these conditions. If it's greater than 1415 - * one, we've got real problems, since it means the 1416 - * serial port won't be shutdown. 1417 - */ 1418 - printk("rs_close: bad serial port count; tty->count is 1, " 1419 - "state->count is %d\n", state->count); 1420 - state->count = 1; 1421 - } 1422 - if (--state->count < 0) { 1423 - printk("rs_close: bad serial port count for ttys%d: %d\n", 1424 - info->line, state->count); 1425 - state->count = 0; 1426 - } 1427 - if (state->count) { 1428 - DBG_CNT("before DEC-2"); 1429 - local_irq_restore(flags); 1430 - return; 1431 - } 1432 - info->flags |= ASYNC_CLOSING; 1433 - /* 1434 - * Now we wait for the transmit buffer to clear; and we notify 1435 - * the line discipline to only process XON/XOFF characters. 1436 - */ 1437 - tty->closing = 1; 1438 - if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1439 - tty_wait_until_sent(tty, info->closing_wait); 1440 1444 /* 1441 1445 * At this point we stop accepting input. To do this, we 1442 1446 * disable the receive line status interrupts, and tell the 1443 1447 * interrupt driver to stop checking the data ready bit in the 1444 1448 * line status register. 1445 1449 */ 1446 - info->read_status_mask &= ~UART_LSR_DR; 1447 - if (info->flags & ASYNC_INITIALIZED) { 1450 + state->read_status_mask &= ~UART_LSR_DR; 1451 + if (port->flags & ASYNC_INITIALIZED) { 1448 1452 /* disable receive interrupts */ 1449 1453 custom.intena = IF_RBF; 1450 1454 mb(); ··· 1416 1502 * has completely drained; this is especially 1417 1503 * important if there is a transmit FIFO! 1418 1504 */ 1419 - rs_wait_until_sent(tty, info->timeout); 1505 + rs_wait_until_sent(tty, state->timeout); 1420 1506 } 1421 - shutdown(info); 1507 + shutdown(tty, state); 1422 1508 rs_flush_buffer(tty); 1423 1509 1424 1510 tty_ldisc_flush(tty); 1425 - tty->closing = 0; 1426 - info->event = 0; 1427 - info->tty = NULL; 1428 - if (info->blocked_open) { 1429 - if (info->close_delay) { 1430 - msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1431 - } 1432 - wake_up_interruptible(&info->open_wait); 1433 - } 1434 - info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1435 - wake_up_interruptible(&info->close_wait); 1436 - local_irq_restore(flags); 1511 + port->tty = NULL; 1512 + 1513 + tty_port_close_end(port, tty); 1437 1514 } 1438 1515 1439 1516 /* ··· 1432 1527 */ 1433 1528 static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 1434 1529 { 1435 - struct async_struct * info = tty->driver_data; 1530 + struct serial_state *info = tty->driver_data; 1436 1531 unsigned long orig_jiffies, char_time; 1437 1532 int lsr; 1438 1533 ··· 1495 1590 */ 1496 1591 static void rs_hangup(struct tty_struct *tty) 1497 1592 { 1498 - struct async_struct * info = tty->driver_data; 1499 - struct serial_state *state = info->state; 1593 + struct serial_state *info = tty->driver_data; 1500 1594 1501 1595 if (serial_paranoia_check(info, tty->name, "rs_hangup")) 1502 1596 return; 1503 1597 1504 - state = info->state; 1505 - 1506 1598 rs_flush_buffer(tty); 1507 - shutdown(info); 1508 - info->event = 0; 1509 - state->count = 0; 1510 - info->flags &= ~ASYNC_NORMAL_ACTIVE; 1511 - info->tty = NULL; 1512 - wake_up_interruptible(&info->open_wait); 1513 - } 1514 - 1515 - /* 1516 - * ------------------------------------------------------------ 1517 - * rs_open() and friends 1518 - * ------------------------------------------------------------ 1519 - */ 1520 - static int block_til_ready(struct tty_struct *tty, struct file * filp, 1521 - struct async_struct *info) 1522 - { 1523 - #ifdef DECLARE_WAITQUEUE 1524 - DECLARE_WAITQUEUE(wait, current); 1525 - #else 1526 - struct wait_queue wait = { current, NULL }; 1527 - #endif 1528 - struct serial_state *state = info->state; 1529 - int retval; 1530 - int do_clocal = 0, extra_count = 0; 1531 - unsigned long flags; 1532 - 1533 - /* 1534 - * If the device is in the middle of being closed, then block 1535 - * until it's done, and then try again. 1536 - */ 1537 - if (tty_hung_up_p(filp) || 1538 - (info->flags & ASYNC_CLOSING)) { 1539 - if (info->flags & ASYNC_CLOSING) 1540 - interruptible_sleep_on(&info->close_wait); 1541 - #ifdef SERIAL_DO_RESTART 1542 - return ((info->flags & ASYNC_HUP_NOTIFY) ? 1543 - -EAGAIN : -ERESTARTSYS); 1544 - #else 1545 - return -EAGAIN; 1546 - #endif 1547 - } 1548 - 1549 - /* 1550 - * If non-blocking mode is set, or the port is not enabled, 1551 - * then make the check up front and then exit. 1552 - */ 1553 - if ((filp->f_flags & O_NONBLOCK) || 1554 - (tty->flags & (1 << TTY_IO_ERROR))) { 1555 - info->flags |= ASYNC_NORMAL_ACTIVE; 1556 - return 0; 1557 - } 1558 - 1559 - if (tty->termios->c_cflag & CLOCAL) 1560 - do_clocal = 1; 1561 - 1562 - /* 1563 - * Block waiting for the carrier detect and the line to become 1564 - * free (i.e., not in use by the callout). While we are in 1565 - * this loop, state->count is dropped by one, so that 1566 - * rs_close() knows when to free things. We restore it upon 1567 - * exit, either normal or abnormal. 1568 - */ 1569 - retval = 0; 1570 - add_wait_queue(&info->open_wait, &wait); 1571 - #ifdef SERIAL_DEBUG_OPEN 1572 - printk("block_til_ready before block: ttys%d, count = %d\n", 1573 - state->line, state->count); 1574 - #endif 1575 - local_irq_save(flags); 1576 - if (!tty_hung_up_p(filp)) { 1577 - extra_count = 1; 1578 - state->count--; 1579 - } 1580 - local_irq_restore(flags); 1581 - info->blocked_open++; 1582 - while (1) { 1583 - local_irq_save(flags); 1584 - if (tty->termios->c_cflag & CBAUD) 1585 - rtsdtr_ctrl(SER_DTR|SER_RTS); 1586 - local_irq_restore(flags); 1587 - set_current_state(TASK_INTERRUPTIBLE); 1588 - if (tty_hung_up_p(filp) || 1589 - !(info->flags & ASYNC_INITIALIZED)) { 1590 - #ifdef SERIAL_DO_RESTART 1591 - if (info->flags & ASYNC_HUP_NOTIFY) 1592 - retval = -EAGAIN; 1593 - else 1594 - retval = -ERESTARTSYS; 1595 - #else 1596 - retval = -EAGAIN; 1597 - #endif 1598 - break; 1599 - } 1600 - if (!(info->flags & ASYNC_CLOSING) && 1601 - (do_clocal || (!(ciab.pra & SER_DCD)) )) 1602 - break; 1603 - if (signal_pending(current)) { 1604 - retval = -ERESTARTSYS; 1605 - break; 1606 - } 1607 - #ifdef SERIAL_DEBUG_OPEN 1608 - printk("block_til_ready blocking: ttys%d, count = %d\n", 1609 - info->line, state->count); 1610 - #endif 1611 - tty_unlock(); 1612 - schedule(); 1613 - tty_lock(); 1614 - } 1615 - __set_current_state(TASK_RUNNING); 1616 - remove_wait_queue(&info->open_wait, &wait); 1617 - if (extra_count) 1618 - state->count++; 1619 - info->blocked_open--; 1620 - #ifdef SERIAL_DEBUG_OPEN 1621 - printk("block_til_ready after blocking: ttys%d, count = %d\n", 1622 - info->line, state->count); 1623 - #endif 1624 - if (retval) 1625 - return retval; 1626 - info->flags |= ASYNC_NORMAL_ACTIVE; 1627 - return 0; 1628 - } 1629 - 1630 - static int get_async_struct(int line, struct async_struct **ret_info) 1631 - { 1632 - struct async_struct *info; 1633 - struct serial_state *sstate; 1634 - 1635 - sstate = rs_table + line; 1636 - sstate->count++; 1637 - if (sstate->info) { 1638 - *ret_info = sstate->info; 1639 - return 0; 1640 - } 1641 - info = kzalloc(sizeof(struct async_struct), GFP_KERNEL); 1642 - if (!info) { 1643 - sstate->count--; 1644 - return -ENOMEM; 1645 - } 1646 - #ifdef DECLARE_WAITQUEUE 1647 - init_waitqueue_head(&info->open_wait); 1648 - init_waitqueue_head(&info->close_wait); 1649 - init_waitqueue_head(&info->delta_msr_wait); 1650 - #endif 1651 - info->magic = SERIAL_MAGIC; 1652 - info->port = sstate->port; 1653 - info->flags = sstate->flags; 1654 - info->xmit_fifo_size = sstate->xmit_fifo_size; 1655 - info->line = line; 1656 - tasklet_init(&info->tlet, do_softint, (unsigned long)info); 1657 - info->state = sstate; 1658 - if (sstate->info) { 1659 - kfree(info); 1660 - *ret_info = sstate->info; 1661 - return 0; 1662 - } 1663 - *ret_info = sstate->info = info; 1664 - return 0; 1599 + shutdown(tty, info); 1600 + info->tport.count = 0; 1601 + info->tport.flags &= ~ASYNC_NORMAL_ACTIVE; 1602 + info->tport.tty = NULL; 1603 + wake_up_interruptible(&info->tport.open_wait); 1665 1604 } 1666 1605 1667 1606 /* ··· 1516 1767 */ 1517 1768 static int rs_open(struct tty_struct *tty, struct file * filp) 1518 1769 { 1519 - struct async_struct *info; 1520 - int retval, line; 1770 + struct serial_state *info = rs_table + tty->index; 1771 + struct tty_port *port = &info->tport; 1772 + int retval; 1521 1773 1522 - line = tty->index; 1523 - if ((line < 0) || (line >= NR_PORTS)) { 1524 - return -ENODEV; 1525 - } 1526 - retval = get_async_struct(line, &info); 1527 - if (retval) { 1528 - return retval; 1529 - } 1774 + port->count++; 1775 + port->tty = tty; 1530 1776 tty->driver_data = info; 1531 - info->tty = tty; 1777 + tty->port = port; 1532 1778 if (serial_paranoia_check(info, tty->name, "rs_open")) 1533 1779 return -ENODEV; 1534 1780 1535 - #ifdef SERIAL_DEBUG_OPEN 1536 - printk("rs_open %s, count = %d\n", tty->name, info->state->count); 1537 - #endif 1538 - info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1781 + tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1539 1782 1540 - /* 1541 - * If the port is the middle of closing, bail out now 1542 - */ 1543 - if (tty_hung_up_p(filp) || 1544 - (info->flags & ASYNC_CLOSING)) { 1545 - if (info->flags & ASYNC_CLOSING) 1546 - interruptible_sleep_on(&info->close_wait); 1547 - #ifdef SERIAL_DO_RESTART 1548 - return ((info->flags & ASYNC_HUP_NOTIFY) ? 1549 - -EAGAIN : -ERESTARTSYS); 1550 - #else 1551 - return -EAGAIN; 1552 - #endif 1553 - } 1554 - 1555 - /* 1556 - * Start up serial port 1557 - */ 1558 - retval = startup(info); 1783 + retval = startup(tty, info); 1559 1784 if (retval) { 1560 1785 return retval; 1561 1786 } 1562 1787 1563 - retval = block_til_ready(tty, filp, info); 1564 - if (retval) { 1565 - #ifdef SERIAL_DEBUG_OPEN 1566 - printk("rs_open returning after block_til_ready with %d\n", 1567 - retval); 1568 - #endif 1569 - return retval; 1570 - } 1571 - 1572 - #ifdef SERIAL_DEBUG_OPEN 1573 - printk("rs_open %s successful...", tty->name); 1574 - #endif 1575 - return 0; 1788 + return tty_port_block_til_ready(port, tty, filp); 1576 1789 } 1577 1790 1578 1791 /* 1579 1792 * /proc fs routines.... 1580 1793 */ 1581 1794 1582 - static inline void line_info(struct seq_file *m, struct serial_state *state) 1795 + static inline void line_info(struct seq_file *m, int line, 1796 + struct serial_state *state) 1583 1797 { 1584 - struct async_struct *info = state->info, scr_info; 1585 1798 char stat_buf[30], control, status; 1586 1799 unsigned long flags; 1587 1800 1588 - seq_printf(m, "%d: uart:amiga_builtin",state->line); 1801 + seq_printf(m, "%d: uart:amiga_builtin", line); 1589 1802 1590 - /* 1591 - * Figure out the current RS-232 lines 1592 - */ 1593 - if (!info) { 1594 - info = &scr_info; /* This is just for serial_{in,out} */ 1595 - 1596 - info->magic = SERIAL_MAGIC; 1597 - info->flags = state->flags; 1598 - info->quot = 0; 1599 - info->tty = NULL; 1600 - } 1601 1803 local_irq_save(flags); 1602 1804 status = ciab.pra; 1603 - control = info ? info->MCR : status; 1805 + control = (state->tport.flags & ASYNC_INITIALIZED) ? state->MCR : status; 1604 1806 local_irq_restore(flags); 1605 1807 1606 1808 stat_buf[0] = 0; ··· 1567 1867 if(!(status & SER_DCD)) 1568 1868 strcat(stat_buf, "|CD"); 1569 1869 1570 - if (info->quot) { 1571 - seq_printf(m, " baud:%d", state->baud_base / info->quot); 1572 - } 1870 + if (state->quot) 1871 + seq_printf(m, " baud:%d", state->baud_base / state->quot); 1573 1872 1574 1873 seq_printf(m, " tx:%d rx:%d", state->icount.tx, state->icount.rx); 1575 1874 ··· 1593 1894 static int rs_proc_show(struct seq_file *m, void *v) 1594 1895 { 1595 1896 seq_printf(m, "serinfo:1.0 driver:%s\n", serial_version); 1596 - line_info(m, &rs_table[0]); 1897 + line_info(m, 0, &rs_table[0]); 1597 1898 return 0; 1598 1899 } 1599 1900 ··· 1654 1955 .proc_fops = &rs_proc_fops, 1655 1956 }; 1656 1957 1958 + static int amiga_carrier_raised(struct tty_port *port) 1959 + { 1960 + return !(ciab.pra & SER_DCD); 1961 + } 1962 + 1963 + static void amiga_dtr_rts(struct tty_port *port, int raise) 1964 + { 1965 + struct serial_state *info = container_of(port, struct serial_state, 1966 + tport); 1967 + unsigned long flags; 1968 + 1969 + if (raise) 1970 + info->MCR |= SER_DTR|SER_RTS; 1971 + else 1972 + info->MCR &= ~(SER_DTR|SER_RTS); 1973 + 1974 + local_irq_save(flags); 1975 + rtsdtr_ctrl(info->MCR); 1976 + local_irq_restore(flags); 1977 + } 1978 + 1979 + static const struct tty_port_operations amiga_port_ops = { 1980 + .carrier_raised = amiga_carrier_raised, 1981 + .dtr_rts = amiga_dtr_rts, 1982 + }; 1983 + 1657 1984 /* 1658 1985 * The serial driver boot-time initialization code! 1659 1986 */ ··· 1689 1964 struct serial_state * state; 1690 1965 int error; 1691 1966 1692 - serial_driver = alloc_tty_driver(1); 1967 + serial_driver = alloc_tty_driver(NR_PORTS); 1693 1968 if (!serial_driver) 1694 1969 return -ENOMEM; 1695 - 1696 - IRQ_ports = NULL; 1697 1970 1698 1971 show_serial_version(); 1699 1972 1700 1973 /* Initialize the tty_driver structure */ 1701 1974 1702 - serial_driver->owner = THIS_MODULE; 1703 1975 serial_driver->driver_name = "amiserial"; 1704 1976 serial_driver->name = "ttyS"; 1705 1977 serial_driver->major = TTY_MAJOR; ··· 1714 1992 goto fail_put_tty_driver; 1715 1993 1716 1994 state = rs_table; 1717 - state->magic = SSTATE_MAGIC; 1718 1995 state->port = (int)&custom.serdatr; /* Just to give it a value */ 1719 - state->line = 0; 1720 1996 state->custom_divisor = 0; 1721 - state->close_delay = 5*HZ/10; 1722 - state->closing_wait = 30*HZ; 1723 1997 state->icount.cts = state->icount.dsr = 1724 1998 state->icount.rng = state->icount.dcd = 0; 1725 1999 state->icount.rx = state->icount.tx = 0; 1726 2000 state->icount.frame = state->icount.parity = 0; 1727 2001 state->icount.overrun = state->icount.brk = 0; 2002 + tty_port_init(&state->tport); 2003 + state->tport.ops = &amiga_port_ops; 1728 2004 1729 - printk(KERN_INFO "ttyS%d is the amiga builtin serial port\n", 1730 - state->line); 2005 + printk(KERN_INFO "ttyS0 is the amiga builtin serial port\n"); 1731 2006 1732 2007 /* Hardware set up */ 1733 2008 ··· 1777 2058 { 1778 2059 int error; 1779 2060 struct serial_state *state = platform_get_drvdata(pdev); 1780 - struct async_struct *info = state->info; 1781 2061 1782 2062 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */ 1783 - tasklet_kill(&info->tlet); 1784 2063 if ((error = tty_unregister_driver(serial_driver))) 1785 2064 printk("SERIAL: failed to unregister serial driver (%d)\n", 1786 2065 error); 1787 2066 put_tty_driver(serial_driver); 1788 2067 1789 - rs_table[0].info = NULL; 1790 - kfree(info); 1791 - 1792 - free_irq(IRQ_AMIGA_TBE, rs_table); 1793 - free_irq(IRQ_AMIGA_RBF, rs_table); 2068 + free_irq(IRQ_AMIGA_TBE, state); 2069 + free_irq(IRQ_AMIGA_RBF, state); 1794 2070 1795 2071 platform_set_drvdata(pdev, NULL); 1796 2072
-1
drivers/tty/bfin_jtag_comm.c
··· 257 257 if (!bfin_jc_driver) 258 258 goto err_driver; 259 259 260 - bfin_jc_driver->owner = THIS_MODULE; 261 260 bfin_jc_driver->driver_name = DRV_NAME; 262 261 bfin_jc_driver->name = DEV_NAME; 263 262 bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL;
+2 -7
drivers/tty/cyclades.c
··· 1515 1515 static int cy_open(struct tty_struct *tty, struct file *filp) 1516 1516 { 1517 1517 struct cyclades_port *info; 1518 - unsigned int i, line; 1518 + unsigned int i, line = tty->index; 1519 1519 int retval; 1520 - 1521 - line = tty->index; 1522 - if (tty->index < 0 || NR_PORTS <= line) 1523 - return -ENODEV; 1524 1520 1525 1521 for (i = 0; i < NR_CARDS; i++) 1526 1522 if (line < cy_card[i].first_line + cy_card[i].nports && ··· 2409 2413 /* Not supported yet */ 2410 2414 return -EINVAL; 2411 2415 } 2412 - return put_user(result, (unsigned long __user *)value); 2416 + return put_user(result, value); 2413 2417 } 2414 2418 2415 2419 static int cy_tiocmget(struct tty_struct *tty) ··· 4086 4090 4087 4091 /* Initialize the tty_driver structure */ 4088 4092 4089 - cy_serial_driver->owner = THIS_MODULE; 4090 4093 cy_serial_driver->driver_name = "cyclades"; 4091 4094 cy_serial_driver->name = "ttyC"; 4092 4095 cy_serial_driver->major = CYCLADES_MAJOR;
-1
drivers/tty/ehv_bytechan.c
··· 825 825 goto error; 826 826 } 827 827 828 - ehv_bc_driver->owner = THIS_MODULE; 829 828 ehv_bc_driver->driver_name = "ehv-bc"; 830 829 ehv_bc_driver->name = ehv_bc_console.name; 831 830 ehv_bc_driver->type = TTY_DRIVER_TYPE_CONSOLE;
+1 -1
drivers/tty/hvc/hvc_beat.c
··· 113 113 if (!firmware_has_feature(FW_FEATURE_BEAT)) 114 114 return -ENODEV; 115 115 116 - hp = hvc_alloc(0, NO_IRQ, &hvc_beat_get_put_ops, 16); 116 + hp = hvc_alloc(0, 0, &hvc_beat_get_put_ops, 16); 117 117 if (IS_ERR(hp)) 118 118 return PTR_ERR(hp); 119 119 hvc_beat_dev = hp;
-1
drivers/tty/hvc/hvc_console.c
··· 917 917 goto out; 918 918 } 919 919 920 - drv->owner = THIS_MODULE; 921 920 drv->driver_name = "hvc"; 922 921 drv->name = "hvc"; 923 922 drv->major = HVC_MAJOR;
+1 -1
drivers/tty/hvc/hvc_rtas.c
··· 94 94 95 95 /* Allocate an hvc_struct for the console device we instantiated 96 96 * earlier. Save off hp so that we can return it on exit */ 97 - hp = hvc_alloc(hvc_rtas_cookie, NO_IRQ, &hvc_rtas_get_put_ops, 16); 97 + hp = hvc_alloc(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops, 16); 98 98 if (IS_ERR(hp)) 99 99 return PTR_ERR(hp); 100 100
+1 -1
drivers/tty/hvc/hvc_udbg.c
··· 69 69 70 70 BUG_ON(hvc_udbg_dev); 71 71 72 - hp = hvc_alloc(0, NO_IRQ, &hvc_udbg_ops, 16); 72 + hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16); 73 73 if (IS_ERR(hp)) 74 74 return PTR_ERR(hp); 75 75
+1 -1
drivers/tty/hvc/hvc_xen.c
··· 176 176 xencons_irq = bind_evtchn_to_irq(xen_start_info->console.domU.evtchn); 177 177 } 178 178 if (xencons_irq < 0) 179 - xencons_irq = 0; /* NO_IRQ */ 179 + xencons_irq = 0; 180 180 else 181 181 irq_set_noprobe(xencons_irq); 182 182
+12 -18
drivers/tty/hvc/hvcs.c
··· 1090 1090 */ 1091 1091 static struct hvcs_struct *hvcs_get_by_index(int index) 1092 1092 { 1093 - struct hvcs_struct *hvcsd = NULL; 1093 + struct hvcs_struct *hvcsd; 1094 1094 unsigned long flags; 1095 1095 1096 1096 spin_lock(&hvcs_structs_lock); 1097 - /* We can immediately discard OOB requests */ 1098 - if (index >= 0 && index < HVCS_MAX_SERVER_ADAPTERS) { 1099 - list_for_each_entry(hvcsd, &hvcs_structs, next) { 1100 - spin_lock_irqsave(&hvcsd->lock, flags); 1101 - if (hvcsd->index == index) { 1102 - kref_get(&hvcsd->kref); 1103 - spin_unlock_irqrestore(&hvcsd->lock, flags); 1104 - spin_unlock(&hvcs_structs_lock); 1105 - return hvcsd; 1106 - } 1097 + list_for_each_entry(hvcsd, &hvcs_structs, next) { 1098 + spin_lock_irqsave(&hvcsd->lock, flags); 1099 + if (hvcsd->index == index) { 1100 + kref_get(&hvcsd->kref); 1107 1101 spin_unlock_irqrestore(&hvcsd->lock, flags); 1102 + spin_unlock(&hvcs_structs_lock); 1103 + return hvcsd; 1108 1104 } 1109 - hvcsd = NULL; 1105 + spin_unlock_irqrestore(&hvcsd->lock, flags); 1110 1106 } 1111 - 1112 1107 spin_unlock(&hvcs_structs_lock); 1113 - return hvcsd; 1108 + 1109 + return NULL; 1114 1110 } 1115 1111 1116 1112 /* ··· 1199 1203 { 1200 1204 struct hvcs_struct *hvcsd; 1201 1205 unsigned long flags; 1202 - int irq = NO_IRQ; 1206 + int irq; 1203 1207 1204 1208 /* 1205 1209 * Is someone trying to close the file associated with this device after ··· 1260 1264 struct hvcs_struct *hvcsd = tty->driver_data; 1261 1265 unsigned long flags; 1262 1266 int temp_open_count; 1263 - int irq = NO_IRQ; 1267 + int irq; 1264 1268 1265 1269 spin_lock_irqsave(&hvcsd->lock, flags); 1266 1270 /* Preserve this so that we know how many kref refs to put */ ··· 1494 1498 rc = -ENOMEM; 1495 1499 goto index_fail; 1496 1500 } 1497 - 1498 - hvcs_tty_driver->owner = THIS_MODULE; 1499 1501 1500 1502 hvcs_tty_driver->driver_name = hvcs_driver_name; 1501 1503 hvcs_tty_driver->name = hvcs_device_node;
+2 -6
drivers/tty/hvc/hvsi.c
··· 737 737 { 738 738 struct hvsi_struct *hp; 739 739 unsigned long flags; 740 - int line = tty->index; 741 740 int ret; 742 741 743 742 pr_debug("%s\n", __func__); 744 743 745 - if (line < 0 || line >= hvsi_count) 746 - return -ENODEV; 747 - hp = &hvsi_ports[line]; 744 + hp = &hvsi_ports[tty->index]; 748 745 749 746 tty->driver_data = hp; 750 747 ··· 1085 1088 if (!hvsi_driver) 1086 1089 return -ENOMEM; 1087 1090 1088 - hvsi_driver->owner = THIS_MODULE; 1089 1091 hvsi_driver->driver_name = "hvsi"; 1090 1092 hvsi_driver->name = "hvsi"; 1091 1093 hvsi_driver->major = HVSI_MAJOR; ··· 1233 1237 hp->state = HVSI_CLOSED; 1234 1238 hp->vtermno = *vtermno; 1235 1239 hp->virq = irq_create_mapping(NULL, irq[0]); 1236 - if (hp->virq == NO_IRQ) { 1240 + if (hp->virq == 0) { 1237 1241 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n", 1238 1242 __func__, irq[0]); 1239 1243 continue;
+12 -23
drivers/tty/ipwireless/tty.c
··· 90 90 tty->index); 91 91 } 92 92 93 - static struct ipw_tty *get_tty(int minor) 93 + static struct ipw_tty *get_tty(int index) 94 94 { 95 - if (minor < ipw_tty_driver->minor_start 96 - || minor >= ipw_tty_driver->minor_start + 97 - IPWIRELESS_PCMCIA_MINORS) 95 + /* 96 + * The 'ras_raw' channel is only available when 'loopback' mode 97 + * is enabled. 98 + * Number of minor starts with 16 (_RANGE * _RAS_RAW). 99 + */ 100 + if (!ipwireless_loopback && index >= 101 + IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW) 98 102 return NULL; 99 - else { 100 - int minor_offset = minor - ipw_tty_driver->minor_start; 101 103 102 - /* 103 - * The 'ras_raw' channel is only available when 'loopback' mode 104 - * is enabled. 105 - * Number of minor starts with 16 (_RANGE * _RAS_RAW). 106 - */ 107 - if (!ipwireless_loopback && 108 - minor_offset >= 109 - IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW) 110 - return NULL; 111 - 112 - return ttys[minor_offset]; 113 - } 104 + return ttys[index]; 114 105 } 115 106 116 107 static int ipw_open(struct tty_struct *linux_tty, struct file *filp) 117 108 { 118 - int minor = linux_tty->index; 119 - struct ipw_tty *tty = get_tty(minor); 109 + struct ipw_tty *tty = get_tty(linux_tty->index); 120 110 121 111 if (!tty) 122 112 return -ENODEV; ··· 500 510 ipwireless_associate_network_tty(network, 501 511 secondary_channel_idx, 502 512 ttys[j]); 503 - if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j]) 513 + if (get_tty(j) == ttys[j]) 504 514 report_registering(ttys[j]); 505 515 return 0; 506 516 } ··· 560 570 561 571 if (ttyj) { 562 572 mutex_lock(&ttyj->ipw_tty_mutex); 563 - if (get_tty(j + ipw_tty_driver->minor_start) == ttyj) 573 + if (get_tty(j) == ttyj) 564 574 report_deregistering(ttyj); 565 575 ttyj->closing = 1; 566 576 if (ttyj->linux_tty != NULL) { ··· 604 614 if (!ipw_tty_driver) 605 615 return -ENOMEM; 606 616 607 - ipw_tty_driver->owner = THIS_MODULE; 608 617 ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME; 609 618 ipw_tty_driver->name = "ttyIPWp"; 610 619 ipw_tty_driver->major = 0;
-3
drivers/tty/isicom.c
··· 849 849 unsigned int board; 850 850 int line = tty->index; 851 851 852 - if (line < 0 || line > PORT_COUNT-1) 853 - return NULL; 854 852 board = BOARD(line); 855 853 card = &isi_card[board]; 856 854 ··· 1676 1678 goto error; 1677 1679 } 1678 1680 1679 - isicom_normal->owner = THIS_MODULE; 1680 1681 isicom_normal->name = "ttyM"; 1681 1682 isicom_normal->major = ISICOM_NMAJOR; 1682 1683 isicom_normal->minor_start = 0;
+1 -2
drivers/tty/moxa.c
··· 1036 1036 if (!moxaDriver) 1037 1037 return -ENOMEM; 1038 1038 1039 - moxaDriver->owner = THIS_MODULE; 1040 1039 moxaDriver->name = "ttyMX"; 1041 1040 moxaDriver->major = ttymajor; 1042 1041 moxaDriver->minor_start = 0; ··· 1330 1331 if (ch == NULL) 1331 1332 return; 1332 1333 1333 - if (!(ch->statusflags & TXSTOPPED)) 1334 + if (!test_bit(TXSTOPPED, &ch->statusflags)) 1334 1335 return; 1335 1336 1336 1337 MoxaPortTxEnable(ch);
-5
drivers/tty/mxser.c
··· 1010 1010 line = tty->index; 1011 1011 if (line == MXSER_PORTS) 1012 1012 return 0; 1013 - if (line < 0 || line > MXSER_PORTS) 1014 - return -ENODEV; 1015 1013 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD]; 1016 1014 if (!info->ioaddr) 1017 1015 return -ENODEV; ··· 2656 2658 MXSER_VERSION); 2657 2659 2658 2660 /* Initialize the tty_driver structure */ 2659 - mxvar_sdriver->owner = THIS_MODULE; 2660 - mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 2661 2661 mxvar_sdriver->name = "ttyMI"; 2662 2662 mxvar_sdriver->major = ttymajor; 2663 2663 mxvar_sdriver->minor_start = 0; 2664 - mxvar_sdriver->num = MXSER_PORTS + 1; 2665 2664 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL; 2666 2665 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; 2667 2666 mxvar_sdriver->init_termios = tty_std_termios;
-1
drivers/tty/n_gsm.c
··· 3120 3120 pr_err("gsm_init: tty allocation failed.\n"); 3121 3121 return -EINVAL; 3122 3122 } 3123 - gsm_tty_driver->owner = THIS_MODULE; 3124 3123 gsm_tty_driver->driver_name = "gsmtty"; 3125 3124 gsm_tty_driver->name = "gsmtty"; 3126 3125 gsm_tty_driver->major = 0; /* Dynamic */
+2 -7
drivers/tty/nozomi.c
··· 1602 1602 int ret; 1603 1603 if (!port || !dc || dc->state != NOZOMI_STATE_READY) 1604 1604 return -ENODEV; 1605 - ret = tty_init_termios(tty); 1606 - if (ret == 0) { 1607 - tty_driver_kref_get(driver); 1608 - tty->count++; 1605 + ret = tty_standard_install(driver, tty); 1606 + if (ret == 0) 1609 1607 tty->driver_data = port; 1610 - driver->ttys[tty->index] = tty; 1611 - } 1612 1608 return ret; 1613 1609 } 1614 1610 ··· 1916 1920 if (!ntty_driver) 1917 1921 return -ENOMEM; 1918 1922 1919 - ntty_driver->owner = THIS_MODULE; 1920 1923 ntty_driver->driver_name = NOZOMI_NAME_TTY; 1921 1924 ntty_driver->name = "noz"; 1922 1925 ntty_driver->major = 0;
+3 -60
drivers/tty/pty.c
··· 21 21 #include <linux/major.h> 22 22 #include <linux/mm.h> 23 23 #include <linux/init.h> 24 - #include <linux/sysctl.h> 25 24 #include <linux/device.h> 26 25 #include <linux/uaccess.h> 27 26 #include <linux/bitops.h> ··· 393 394 if (!pty_slave_driver) 394 395 panic("Couldn't allocate pty slave driver"); 395 396 396 - pty_driver->owner = THIS_MODULE; 397 397 pty_driver->driver_name = "pty_master"; 398 398 pty_driver->name = "pty"; 399 399 pty_driver->major = PTY_MASTER_MAJOR; ··· 410 412 pty_driver->other = pty_slave_driver; 411 413 tty_set_operations(pty_driver, &master_pty_ops_bsd); 412 414 413 - pty_slave_driver->owner = THIS_MODULE; 414 415 pty_slave_driver->driver_name = "pty_slave"; 415 416 pty_slave_driver->name = "ttyp"; 416 417 pty_slave_driver->major = PTY_SLAVE_MAJOR; ··· 436 439 437 440 /* Unix98 devices */ 438 441 #ifdef CONFIG_UNIX98_PTYS 439 - /* 440 - * sysctl support for setting limits on the number of Unix98 ptys allocated. 441 - * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly. 442 - */ 443 - int pty_limit = NR_UNIX98_PTY_DEFAULT; 444 - static int pty_limit_min; 445 - static int pty_limit_max = NR_UNIX98_PTY_MAX; 446 - static int pty_count; 447 442 448 443 static struct cdev ptmx_cdev; 449 - 450 - static struct ctl_table pty_table[] = { 451 - { 452 - .procname = "max", 453 - .maxlen = sizeof(int), 454 - .mode = 0644, 455 - .data = &pty_limit, 456 - .proc_handler = proc_dointvec_minmax, 457 - .extra1 = &pty_limit_min, 458 - .extra2 = &pty_limit_max, 459 - }, { 460 - .procname = "nr", 461 - .maxlen = sizeof(int), 462 - .mode = 0444, 463 - .data = &pty_count, 464 - .proc_handler = proc_dointvec, 465 - }, 466 - {} 467 - }; 468 - 469 - static struct ctl_table pty_kern_table[] = { 470 - { 471 - .procname = "pty", 472 - .mode = 0555, 473 - .child = pty_table, 474 - }, 475 - {} 476 - }; 477 - 478 - static struct ctl_table pty_root_table[] = { 479 - { 480 - .procname = "kernel", 481 - .mode = 0555, 482 - .child = pty_kern_table, 483 - }, 484 - {} 485 - }; 486 - 487 444 488 445 static int pty_unix98_ioctl(struct tty_struct *tty, 489 446 unsigned int cmd, unsigned long arg) ··· 466 515 static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, 467 516 struct inode *ptm_inode, int idx) 468 517 { 469 - struct tty_struct *tty = devpts_get_tty(ptm_inode, idx); 470 - if (tty) 471 - tty = tty->link; 472 - return tty; 518 + /* Master must be open via /dev/ptmx */ 519 + return ERR_PTR(-EIO); 473 520 } 474 521 475 522 /** ··· 538 589 */ 539 590 tty_driver_kref_get(driver); 540 591 tty->count++; 541 - pty_count++; 542 592 return 0; 543 593 err_free_mem: 544 594 deinitialize_tty_struct(o_tty); ··· 551 603 552 604 static void ptm_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) 553 605 { 554 - pty_count--; 555 606 } 556 607 557 608 static void pts_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) ··· 624 677 625 678 mutex_lock(&tty_mutex); 626 679 tty_lock(); 627 - tty = tty_init_dev(ptm_driver, index, 1); 680 + tty = tty_init_dev(ptm_driver, index); 628 681 mutex_unlock(&tty_mutex); 629 682 630 683 if (IS_ERR(tty)) { ··· 669 722 if (!pts_driver) 670 723 panic("Couldn't allocate Unix98 pts driver"); 671 724 672 - ptm_driver->owner = THIS_MODULE; 673 725 ptm_driver->driver_name = "pty_master"; 674 726 ptm_driver->name = "ptm"; 675 727 ptm_driver->major = UNIX98_PTY_MASTER_MAJOR; ··· 687 741 ptm_driver->other = pts_driver; 688 742 tty_set_operations(ptm_driver, &ptm_unix98_ops); 689 743 690 - pts_driver->owner = THIS_MODULE; 691 744 pts_driver->driver_name = "pty_slave"; 692 745 pts_driver->name = "pts"; 693 746 pts_driver->major = UNIX98_PTY_SLAVE_MAJOR; ··· 706 761 panic("Couldn't register Unix98 ptm driver"); 707 762 if (tty_register_driver(pts_driver)) 708 763 panic("Couldn't register Unix98 pts driver"); 709 - 710 - register_sysctl_table(pty_root_table); 711 764 712 765 /* Now create the /dev/ptmx special device */ 713 766 tty_default_fops(&ptmx_fops);
+3 -4
drivers/tty/rocket.c
··· 892 892 { 893 893 struct r_port *info; 894 894 struct tty_port *port; 895 - int line = 0, retval; 895 + int retval; 896 896 CHANNEL_t *cp; 897 897 unsigned long page; 898 898 899 - line = tty->index; 900 - if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL)) 899 + info = rp_table[tty->index]; 900 + if (info == NULL) 901 901 return -ENXIO; 902 902 port = &info->port; 903 903 ··· 2277 2277 * driver with the tty layer. 2278 2278 */ 2279 2279 2280 - rocket_driver->owner = THIS_MODULE; 2281 2280 rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV; 2282 2281 rocket_driver->name = "ttyR"; 2283 2282 rocket_driver->driver_name = "Comtrol RocketPort";
+2 -2
drivers/tty/serial/21285.c
··· 331 331 int ret = 0; 332 332 if (ser->type != PORT_UNKNOWN && ser->type != PORT_21285) 333 333 ret = -EINVAL; 334 - if (ser->irq != NO_IRQ) 334 + if (ser->irq <= 0) 335 335 ret = -EINVAL; 336 336 if (ser->baud_base != port->uartclk / 16) 337 337 ret = -EINVAL; ··· 360 360 static struct uart_port serial21285_port = { 361 361 .mapbase = 0x42000160, 362 362 .iotype = UPIO_MEM, 363 - .irq = NO_IRQ, 363 + .irq = 0, 364 364 .fifosize = 16, 365 365 .ops = &serial21285_ops, 366 366 .flags = UPF_BOOT_AUTOCONF,
+2 -7
drivers/tty/serial/68328serial.c
··· 1190 1190 int rs_open(struct tty_struct *tty, struct file * filp) 1191 1191 { 1192 1192 struct m68k_serial *info; 1193 - int retval, line; 1193 + int retval; 1194 1194 1195 - line = tty->index; 1196 - 1197 - if (line >= NR_PORTS || line < 0) /* we have exactly one */ 1198 - return -ENODEV; 1199 - 1200 - info = &m68k_soft[line]; 1195 + info = &m68k_soft[tty->index]; 1201 1196 1202 1197 if (serial_paranoia_check(info, tty->name, "rs_open")) 1203 1198 return -ENODEV;
+366 -376
drivers/tty/serial/8250/8250.c
··· 38 38 #include <linux/nmi.h> 39 39 #include <linux/mutex.h> 40 40 #include <linux/slab.h> 41 + #ifdef CONFIG_SPARC 42 + #include <linux/sunserialcore.h> 43 + #endif 41 44 42 45 #include <asm/io.h> 43 46 #include <asm/irq.h> 44 47 45 48 #include "8250.h" 46 - 47 - #ifdef CONFIG_SPARC 48 - #include "../suncore.h" 49 - #endif 50 49 51 50 /* 52 51 * Configuration: ··· 84 85 85 86 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 86 87 87 - 88 - /* 89 - * We default to IRQ0 for the "no irq" hack. Some 90 - * machine types want others as well - they're free 91 - * to redefine this in their header file. 92 - */ 93 - #define is_real_interrupt(irq) ((irq) != 0) 94 88 95 89 #ifdef CONFIG_SERIAL_8250_DETECT_IRQ 96 90 #define CONFIG_SERIAL_DETECT_IRQ 1 ··· 467 475 } 468 476 469 477 static void 470 - serial_out_sync(struct uart_8250_port *up, int offset, int value) 478 + serial_port_out_sync(struct uart_port *p, int offset, int value) 471 479 { 472 - struct uart_port *p = &up->port; 473 480 switch (p->iotype) { 474 481 case UPIO_MEM: 475 482 case UPIO_MEM32: ··· 481 490 } 482 491 } 483 492 484 - #define serial_in(up, offset) \ 485 - (up->port.serial_in(&(up)->port, (offset))) 486 - #define serial_out(up, offset, value) \ 487 - (up->port.serial_out(&(up)->port, (offset), (value))) 488 - /* 489 - * We used to support using pause I/O for certain machines. We 490 - * haven't supported this for a while, but just in case it's badly 491 - * needed for certain old 386 machines, I've left these #define's 492 - * in.... 493 - */ 494 - #define serial_inp(up, offset) serial_in(up, offset) 495 - #define serial_outp(up, offset, value) serial_out(up, offset, value) 496 - 497 493 /* Uart divisor latch read */ 498 494 static inline int _serial_dl_read(struct uart_8250_port *up) 499 495 { 500 - return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8; 496 + return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8; 501 497 } 502 498 503 499 /* Uart divisor latch write */ 504 500 static inline void _serial_dl_write(struct uart_8250_port *up, int value) 505 501 { 506 - serial_outp(up, UART_DLL, value & 0xff); 507 - serial_outp(up, UART_DLM, value >> 8 & 0xff); 502 + serial_out(up, UART_DLL, value & 0xff); 503 + serial_out(up, UART_DLM, value >> 8 & 0xff); 508 504 } 509 505 510 506 #if defined(CONFIG_MIPS_ALCHEMY) ··· 561 583 static void serial8250_clear_fifos(struct uart_8250_port *p) 562 584 { 563 585 if (p->capabilities & UART_CAP_FIFO) { 564 - serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO); 565 - serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO | 586 + serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO); 587 + serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO | 566 588 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 567 - serial_outp(p, UART_FCR, 0); 589 + serial_out(p, UART_FCR, 0); 568 590 } 569 591 } 570 592 ··· 577 599 { 578 600 if (p->capabilities & UART_CAP_SLEEP) { 579 601 if (p->capabilities & UART_CAP_EFR) { 580 - serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_B); 581 - serial_outp(p, UART_EFR, UART_EFR_ECB); 582 - serial_outp(p, UART_LCR, 0); 602 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 603 + serial_out(p, UART_EFR, UART_EFR_ECB); 604 + serial_out(p, UART_LCR, 0); 583 605 } 584 - serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 606 + serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 585 607 if (p->capabilities & UART_CAP_EFR) { 586 - serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_B); 587 - serial_outp(p, UART_EFR, 0); 588 - serial_outp(p, UART_LCR, 0); 608 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 609 + serial_out(p, UART_EFR, 0); 610 + serial_out(p, UART_LCR, 0); 589 611 } 590 612 } 591 613 } ··· 600 622 unsigned char mode; 601 623 int result; 602 624 603 - mode = serial_inp(up, UART_RSA_MSR); 625 + mode = serial_in(up, UART_RSA_MSR); 604 626 result = mode & UART_RSA_MSR_FIFO; 605 627 606 628 if (!result) { 607 - serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 608 - mode = serial_inp(up, UART_RSA_MSR); 629 + serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 630 + mode = serial_in(up, UART_RSA_MSR); 609 631 result = mode & UART_RSA_MSR_FIFO; 610 632 } 611 633 ··· 624 646 spin_unlock_irq(&up->port.lock); 625 647 } 626 648 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) 627 - serial_outp(up, UART_RSA_FRR, 0); 649 + serial_out(up, UART_RSA_FRR, 0); 628 650 } 629 651 } 630 652 ··· 643 665 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { 644 666 spin_lock_irq(&up->port.lock); 645 667 646 - mode = serial_inp(up, UART_RSA_MSR); 668 + mode = serial_in(up, UART_RSA_MSR); 647 669 result = !(mode & UART_RSA_MSR_FIFO); 648 670 649 671 if (!result) { 650 - serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 651 - mode = serial_inp(up, UART_RSA_MSR); 672 + serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 673 + mode = serial_in(up, UART_RSA_MSR); 652 674 result = !(mode & UART_RSA_MSR_FIFO); 653 675 } 654 676 ··· 669 691 unsigned short old_dl; 670 692 int count; 671 693 672 - old_lcr = serial_inp(up, UART_LCR); 673 - serial_outp(up, UART_LCR, 0); 674 - old_fcr = serial_inp(up, UART_FCR); 675 - old_mcr = serial_inp(up, UART_MCR); 676 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | 694 + old_lcr = serial_in(up, UART_LCR); 695 + serial_out(up, UART_LCR, 0); 696 + old_fcr = serial_in(up, UART_FCR); 697 + old_mcr = serial_in(up, UART_MCR); 698 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | 677 699 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 678 - serial_outp(up, UART_MCR, UART_MCR_LOOP); 679 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); 700 + serial_out(up, UART_MCR, UART_MCR_LOOP); 701 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 680 702 old_dl = serial_dl_read(up); 681 703 serial_dl_write(up, 0x0001); 682 - serial_outp(up, UART_LCR, 0x03); 704 + serial_out(up, UART_LCR, 0x03); 683 705 for (count = 0; count < 256; count++) 684 - serial_outp(up, UART_TX, count); 706 + serial_out(up, UART_TX, count); 685 707 mdelay(20);/* FIXME - schedule_timeout */ 686 - for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) && 708 + for (count = 0; (serial_in(up, UART_LSR) & UART_LSR_DR) && 687 709 (count < 256); count++) 688 - serial_inp(up, UART_RX); 689 - serial_outp(up, UART_FCR, old_fcr); 690 - serial_outp(up, UART_MCR, old_mcr); 691 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); 710 + serial_in(up, UART_RX); 711 + serial_out(up, UART_FCR, old_fcr); 712 + serial_out(up, UART_MCR, old_mcr); 713 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 692 714 serial_dl_write(up, old_dl); 693 - serial_outp(up, UART_LCR, old_lcr); 715 + serial_out(up, UART_LCR, old_lcr); 694 716 695 717 return count; 696 718 } ··· 705 727 unsigned char old_dll, old_dlm, old_lcr; 706 728 unsigned int id; 707 729 708 - old_lcr = serial_inp(p, UART_LCR); 709 - serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_A); 730 + old_lcr = serial_in(p, UART_LCR); 731 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_A); 710 732 711 - old_dll = serial_inp(p, UART_DLL); 712 - old_dlm = serial_inp(p, UART_DLM); 733 + old_dll = serial_in(p, UART_DLL); 734 + old_dlm = serial_in(p, UART_DLM); 713 735 714 - serial_outp(p, UART_DLL, 0); 715 - serial_outp(p, UART_DLM, 0); 736 + serial_out(p, UART_DLL, 0); 737 + serial_out(p, UART_DLM, 0); 716 738 717 - id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8; 739 + id = serial_in(p, UART_DLL) | serial_in(p, UART_DLM) << 8; 718 740 719 - serial_outp(p, UART_DLL, old_dll); 720 - serial_outp(p, UART_DLM, old_dlm); 721 - serial_outp(p, UART_LCR, old_lcr); 741 + serial_out(p, UART_DLL, old_dll); 742 + serial_out(p, UART_DLM, old_dlm); 743 + serial_out(p, UART_LCR, old_lcr); 722 744 723 745 return id; 724 746 } ··· 828 850 up->port.type = PORT_8250; 829 851 830 852 scratch = serial_in(up, UART_SCR); 831 - serial_outp(up, UART_SCR, 0xa5); 853 + serial_out(up, UART_SCR, 0xa5); 832 854 status1 = serial_in(up, UART_SCR); 833 - serial_outp(up, UART_SCR, 0x5a); 855 + serial_out(up, UART_SCR, 0x5a); 834 856 status2 = serial_in(up, UART_SCR); 835 - serial_outp(up, UART_SCR, scratch); 857 + serial_out(up, UART_SCR, scratch); 836 858 837 859 if (status1 == 0xa5 && status2 == 0x5a) 838 860 up->port.type = PORT_16450; ··· 863 885 } else { 864 886 status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ 865 887 status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ 866 - serial_outp(up, 0x04, status); 888 + serial_out(up, 0x04, status); 867 889 } 868 890 return 1; 869 891 } ··· 886 908 * Check for presence of the EFR when DLAB is set. 887 909 * Only ST16C650V1 UARTs pass this test. 888 910 */ 889 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); 911 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 890 912 if (serial_in(up, UART_EFR) == 0) { 891 - serial_outp(up, UART_EFR, 0xA8); 913 + serial_out(up, UART_EFR, 0xA8); 892 914 if (serial_in(up, UART_EFR) != 0) { 893 915 DEBUG_AUTOCONF("EFRv1 "); 894 916 up->port.type = PORT_16650; ··· 896 918 } else { 897 919 DEBUG_AUTOCONF("Motorola 8xxx DUART "); 898 920 } 899 - serial_outp(up, UART_EFR, 0); 921 + serial_out(up, UART_EFR, 0); 900 922 return; 901 923 } 902 924 ··· 904 926 * Maybe it requires 0xbf to be written to the LCR. 905 927 * (other ST16C650V2 UARTs, TI16C752A, etc) 906 928 */ 907 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 929 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 908 930 if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) { 909 931 DEBUG_AUTOCONF("EFRv2 "); 910 932 autoconfig_has_efr(up); ··· 918 940 * switch back to bank 2, read it from EXCR1 again and check 919 941 * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 920 942 */ 921 - serial_outp(up, UART_LCR, 0); 943 + serial_out(up, UART_LCR, 0); 922 944 status1 = serial_in(up, UART_MCR); 923 - serial_outp(up, UART_LCR, 0xE0); 945 + serial_out(up, UART_LCR, 0xE0); 924 946 status2 = serial_in(up, 0x02); /* EXCR1 */ 925 947 926 948 if (!((status2 ^ status1) & UART_MCR_LOOP)) { 927 - serial_outp(up, UART_LCR, 0); 928 - serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP); 929 - serial_outp(up, UART_LCR, 0xE0); 949 + serial_out(up, UART_LCR, 0); 950 + serial_out(up, UART_MCR, status1 ^ UART_MCR_LOOP); 951 + serial_out(up, UART_LCR, 0xE0); 930 952 status2 = serial_in(up, 0x02); /* EXCR1 */ 931 - serial_outp(up, UART_LCR, 0); 932 - serial_outp(up, UART_MCR, status1); 953 + serial_out(up, UART_LCR, 0); 954 + serial_out(up, UART_MCR, status1); 933 955 934 956 if ((status2 ^ status1) & UART_MCR_LOOP) { 935 957 unsigned short quot; 936 958 937 - serial_outp(up, UART_LCR, 0xE0); 959 + serial_out(up, UART_LCR, 0xE0); 938 960 939 961 quot = serial_dl_read(up); 940 962 quot <<= 3; ··· 942 964 if (ns16550a_goto_highspeed(up)) 943 965 serial_dl_write(up, quot); 944 966 945 - serial_outp(up, UART_LCR, 0); 967 + serial_out(up, UART_LCR, 0); 946 968 947 969 up->port.uartclk = 921600*16; 948 970 up->port.type = PORT_NS16550A; ··· 957 979 * Try setting it with and without DLAB set. Cheap clones 958 980 * set bit 5 without DLAB set. 959 981 */ 960 - serial_outp(up, UART_LCR, 0); 961 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 982 + serial_out(up, UART_LCR, 0); 983 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 962 984 status1 = serial_in(up, UART_IIR) >> 5; 963 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 964 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A); 965 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 985 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 986 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 987 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 966 988 status2 = serial_in(up, UART_IIR) >> 5; 967 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 968 - serial_outp(up, UART_LCR, 0); 989 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 990 + serial_out(up, UART_LCR, 0); 969 991 970 992 DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2); 971 993 ··· 984 1006 * already a 1 and maybe locked there before we even start start. 985 1007 */ 986 1008 iersave = serial_in(up, UART_IER); 987 - serial_outp(up, UART_IER, iersave & ~UART_IER_UUE); 1009 + serial_out(up, UART_IER, iersave & ~UART_IER_UUE); 988 1010 if (!(serial_in(up, UART_IER) & UART_IER_UUE)) { 989 1011 /* 990 1012 * OK it's in a known zero state, try writing and reading 991 1013 * without disturbing the current state of the other bits. 992 1014 */ 993 - serial_outp(up, UART_IER, iersave | UART_IER_UUE); 1015 + serial_out(up, UART_IER, iersave | UART_IER_UUE); 994 1016 if (serial_in(up, UART_IER) & UART_IER_UUE) { 995 1017 /* 996 1018 * It's an Xscale. ··· 1008 1030 */ 1009 1031 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); 1010 1032 } 1011 - serial_outp(up, UART_IER, iersave); 1033 + serial_out(up, UART_IER, iersave); 1012 1034 1013 1035 /* 1014 1036 * Exar uarts have EFR in a weird location ··· 1039 1061 { 1040 1062 unsigned char status1, scratch, scratch2, scratch3; 1041 1063 unsigned char save_lcr, save_mcr; 1064 + struct uart_port *port = &up->port; 1042 1065 unsigned long flags; 1043 1066 1044 - if (!up->port.iobase && !up->port.mapbase && !up->port.membase) 1067 + if (!port->iobase && !port->mapbase && !port->membase) 1045 1068 return; 1046 1069 1047 1070 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ", 1048 - serial_index(&up->port), up->port.iobase, up->port.membase); 1071 + serial_index(port), port->iobase, port->membase); 1049 1072 1050 1073 /* 1051 1074 * We really do need global IRQs disabled here - we're going to 1052 1075 * be frobbing the chips IRQ enable register to see if it exists. 1053 1076 */ 1054 - spin_lock_irqsave(&up->port.lock, flags); 1077 + spin_lock_irqsave(&port->lock, flags); 1055 1078 1056 1079 up->capabilities = 0; 1057 1080 up->bugs = 0; 1058 1081 1059 - if (!(up->port.flags & UPF_BUGGY_UART)) { 1082 + if (!(port->flags & UPF_BUGGY_UART)) { 1060 1083 /* 1061 1084 * Do a simple existence test first; if we fail this, 1062 1085 * there's no point trying anything else. ··· 1071 1092 * Note: this is safe as long as MCR bit 4 is clear 1072 1093 * and the device is in "PC" mode. 1073 1094 */ 1074 - scratch = serial_inp(up, UART_IER); 1075 - serial_outp(up, UART_IER, 0); 1095 + scratch = serial_in(up, UART_IER); 1096 + serial_out(up, UART_IER, 0); 1076 1097 #ifdef __i386__ 1077 1098 outb(0xff, 0x080); 1078 1099 #endif ··· 1080 1101 * Mask out IER[7:4] bits for test as some UARTs (e.g. TL 1081 1102 * 16C754B) allow only to modify them if an EFR bit is set. 1082 1103 */ 1083 - scratch2 = serial_inp(up, UART_IER) & 0x0f; 1084 - serial_outp(up, UART_IER, 0x0F); 1104 + scratch2 = serial_in(up, UART_IER) & 0x0f; 1105 + serial_out(up, UART_IER, 0x0F); 1085 1106 #ifdef __i386__ 1086 1107 outb(0, 0x080); 1087 1108 #endif 1088 - scratch3 = serial_inp(up, UART_IER) & 0x0f; 1089 - serial_outp(up, UART_IER, scratch); 1109 + scratch3 = serial_in(up, UART_IER) & 0x0f; 1110 + serial_out(up, UART_IER, scratch); 1090 1111 if (scratch2 != 0 || scratch3 != 0x0F) { 1091 1112 /* 1092 1113 * We failed; there's nothing here ··· 1109 1130 * manufacturer would be stupid enough to design a board 1110 1131 * that conflicts with COM 1-4 --- we hope! 1111 1132 */ 1112 - if (!(up->port.flags & UPF_SKIP_TEST)) { 1113 - serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1114 - status1 = serial_inp(up, UART_MSR) & 0xF0; 1115 - serial_outp(up, UART_MCR, save_mcr); 1133 + if (!(port->flags & UPF_SKIP_TEST)) { 1134 + serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1135 + status1 = serial_in(up, UART_MSR) & 0xF0; 1136 + serial_out(up, UART_MCR, save_mcr); 1116 1137 if (status1 != 0x90) { 1117 1138 DEBUG_AUTOCONF("LOOP test failed (%02x) ", 1118 1139 status1); ··· 1129 1150 * We also initialise the EFR (if any) to zero for later. The 1130 1151 * EFR occupies the same register location as the FCR and IIR. 1131 1152 */ 1132 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 1133 - serial_outp(up, UART_EFR, 0); 1134 - serial_outp(up, UART_LCR, 0); 1153 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 1154 + serial_out(up, UART_EFR, 0); 1155 + serial_out(up, UART_LCR, 0); 1135 1156 1136 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1157 + serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1137 1158 scratch = serial_in(up, UART_IIR) >> 6; 1138 1159 1139 1160 DEBUG_AUTOCONF("iir=%d ", scratch); ··· 1143 1164 autoconfig_8250(up); 1144 1165 break; 1145 1166 case 1: 1146 - up->port.type = PORT_UNKNOWN; 1167 + port->type = PORT_UNKNOWN; 1147 1168 break; 1148 1169 case 2: 1149 - up->port.type = PORT_16550; 1170 + port->type = PORT_16550; 1150 1171 break; 1151 1172 case 3: 1152 1173 autoconfig_16550a(up); ··· 1157 1178 /* 1158 1179 * Only probe for RSA ports if we got the region. 1159 1180 */ 1160 - if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) { 1181 + if (port->type == PORT_16550A && probeflags & PROBE_RSA) { 1161 1182 int i; 1162 1183 1163 1184 for (i = 0 ; i < probe_rsa_count; ++i) { 1164 - if (probe_rsa[i] == up->port.iobase && 1165 - __enable_rsa(up)) { 1166 - up->port.type = PORT_RSA; 1185 + if (probe_rsa[i] == port->iobase && __enable_rsa(up)) { 1186 + port->type = PORT_RSA; 1167 1187 break; 1168 1188 } 1169 1189 } 1170 1190 } 1171 1191 #endif 1172 1192 1173 - serial_outp(up, UART_LCR, save_lcr); 1193 + serial_out(up, UART_LCR, save_lcr); 1174 1194 1175 - if (up->capabilities != uart_config[up->port.type].flags) { 1195 + if (up->capabilities != uart_config[port->type].flags) { 1176 1196 printk(KERN_WARNING 1177 1197 "ttyS%d: detected caps %08x should be %08x\n", 1178 - serial_index(&up->port), up->capabilities, 1179 - uart_config[up->port.type].flags); 1198 + serial_index(port), up->capabilities, 1199 + uart_config[port->type].flags); 1180 1200 } 1181 1201 1182 - up->port.fifosize = uart_config[up->port.type].fifo_size; 1183 - up->capabilities = uart_config[up->port.type].flags; 1184 - up->tx_loadsz = uart_config[up->port.type].tx_loadsz; 1202 + port->fifosize = uart_config[up->port.type].fifo_size; 1203 + up->capabilities = uart_config[port->type].flags; 1204 + up->tx_loadsz = uart_config[port->type].tx_loadsz; 1185 1205 1186 - if (up->port.type == PORT_UNKNOWN) 1206 + if (port->type == PORT_UNKNOWN) 1187 1207 goto out; 1188 1208 1189 1209 /* 1190 1210 * Reset the UART. 1191 1211 */ 1192 1212 #ifdef CONFIG_SERIAL_8250_RSA 1193 - if (up->port.type == PORT_RSA) 1194 - serial_outp(up, UART_RSA_FRR, 0); 1213 + if (port->type == PORT_RSA) 1214 + serial_out(up, UART_RSA_FRR, 0); 1195 1215 #endif 1196 - serial_outp(up, UART_MCR, save_mcr); 1216 + serial_out(up, UART_MCR, save_mcr); 1197 1217 serial8250_clear_fifos(up); 1198 1218 serial_in(up, UART_RX); 1199 1219 if (up->capabilities & UART_CAP_UUE) 1200 - serial_outp(up, UART_IER, UART_IER_UUE); 1220 + serial_out(up, UART_IER, UART_IER_UUE); 1201 1221 else 1202 - serial_outp(up, UART_IER, 0); 1222 + serial_out(up, UART_IER, 0); 1203 1223 1204 1224 out: 1205 - spin_unlock_irqrestore(&up->port.lock, flags); 1206 - DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name); 1225 + spin_unlock_irqrestore(&port->lock, flags); 1226 + DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name); 1207 1227 } 1208 1228 1209 1229 static void autoconfig_irq(struct uart_8250_port *up) 1210 1230 { 1231 + struct uart_port *port = &up->port; 1211 1232 unsigned char save_mcr, save_ier; 1212 1233 unsigned char save_ICP = 0; 1213 1234 unsigned int ICP = 0; 1214 1235 unsigned long irqs; 1215 1236 int irq; 1216 1237 1217 - if (up->port.flags & UPF_FOURPORT) { 1218 - ICP = (up->port.iobase & 0xfe0) | 0x1f; 1238 + if (port->flags & UPF_FOURPORT) { 1239 + ICP = (port->iobase & 0xfe0) | 0x1f; 1219 1240 save_ICP = inb_p(ICP); 1220 1241 outb_p(0x80, ICP); 1221 - (void) inb_p(ICP); 1242 + inb_p(ICP); 1222 1243 } 1223 1244 1224 1245 /* forget possible initially masked and pending IRQ */ 1225 1246 probe_irq_off(probe_irq_on()); 1226 - save_mcr = serial_inp(up, UART_MCR); 1227 - save_ier = serial_inp(up, UART_IER); 1228 - serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); 1247 + save_mcr = serial_in(up, UART_MCR); 1248 + save_ier = serial_in(up, UART_IER); 1249 + serial_out(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2); 1229 1250 1230 1251 irqs = probe_irq_on(); 1231 - serial_outp(up, UART_MCR, 0); 1252 + serial_out(up, UART_MCR, 0); 1232 1253 udelay(10); 1233 - if (up->port.flags & UPF_FOURPORT) { 1234 - serial_outp(up, UART_MCR, 1254 + if (port->flags & UPF_FOURPORT) { 1255 + serial_out(up, UART_MCR, 1235 1256 UART_MCR_DTR | UART_MCR_RTS); 1236 1257 } else { 1237 - serial_outp(up, UART_MCR, 1258 + serial_out(up, UART_MCR, 1238 1259 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); 1239 1260 } 1240 - serial_outp(up, UART_IER, 0x0f); /* enable all intrs */ 1241 - (void)serial_inp(up, UART_LSR); 1242 - (void)serial_inp(up, UART_RX); 1243 - (void)serial_inp(up, UART_IIR); 1244 - (void)serial_inp(up, UART_MSR); 1245 - serial_outp(up, UART_TX, 0xFF); 1261 + serial_out(up, UART_IER, 0x0f); /* enable all intrs */ 1262 + serial_in(up, UART_LSR); 1263 + serial_in(up, UART_RX); 1264 + serial_in(up, UART_IIR); 1265 + serial_in(up, UART_MSR); 1266 + serial_out(up, UART_TX, 0xFF); 1246 1267 udelay(20); 1247 1268 irq = probe_irq_off(irqs); 1248 1269 1249 - serial_outp(up, UART_MCR, save_mcr); 1250 - serial_outp(up, UART_IER, save_ier); 1270 + serial_out(up, UART_MCR, save_mcr); 1271 + serial_out(up, UART_IER, save_ier); 1251 1272 1252 - if (up->port.flags & UPF_FOURPORT) 1273 + if (port->flags & UPF_FOURPORT) 1253 1274 outb_p(save_ICP, ICP); 1254 1275 1255 - up->port.irq = (irq > 0) ? irq : 0; 1276 + port->irq = (irq > 0) ? irq : 0; 1256 1277 } 1257 1278 1258 1279 static inline void __stop_tx(struct uart_8250_port *p) ··· 1273 1294 /* 1274 1295 * We really want to stop the transmitter from sending. 1275 1296 */ 1276 - if (up->port.type == PORT_16C950) { 1297 + if (port->type == PORT_16C950) { 1277 1298 up->acr |= UART_ACR_TXDIS; 1278 1299 serial_icr_write(up, UART_ACR, up->acr); 1279 1300 } ··· 1286 1307 1287 1308 if (!(up->ier & UART_IER_THRI)) { 1288 1309 up->ier |= UART_IER_THRI; 1289 - serial_out(up, UART_IER, up->ier); 1310 + serial_port_out(port, UART_IER, up->ier); 1290 1311 1291 1312 if (up->bugs & UART_BUG_TXEN) { 1292 1313 unsigned char lsr; 1293 1314 lsr = serial_in(up, UART_LSR); 1294 1315 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 1295 - if ((up->port.type == PORT_RM9000) ? 1316 + if ((port->type == PORT_RM9000) ? 1296 1317 (lsr & UART_LSR_THRE) : 1297 1318 (lsr & UART_LSR_TEMT)) 1298 1319 serial8250_tx_chars(up); ··· 1302 1323 /* 1303 1324 * Re-enable the transmitter if we disabled it. 1304 1325 */ 1305 - if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { 1326 + if (port->type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { 1306 1327 up->acr &= ~UART_ACR_TXDIS; 1307 1328 serial_icr_write(up, UART_ACR, up->acr); 1308 1329 } ··· 1315 1336 1316 1337 up->ier &= ~UART_IER_RLSI; 1317 1338 up->port.read_status_mask &= ~UART_LSR_DR; 1318 - serial_out(up, UART_IER, up->ier); 1339 + serial_port_out(port, UART_IER, up->ier); 1319 1340 } 1320 1341 1321 1342 static void serial8250_enable_ms(struct uart_port *port) ··· 1328 1349 return; 1329 1350 1330 1351 up->ier |= UART_IER_MSI; 1331 - serial_out(up, UART_IER, up->ier); 1352 + serial_port_out(port, UART_IER, up->ier); 1332 1353 } 1333 1354 1334 1355 /* ··· 1360 1381 unsigned char 1361 1382 serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr) 1362 1383 { 1363 - struct tty_struct *tty = up->port.state->port.tty; 1384 + struct uart_port *port = &up->port; 1385 + struct tty_struct *tty = port->state->port.tty; 1364 1386 unsigned char ch; 1365 1387 int max_count = 256; 1366 1388 char flag; 1367 1389 1368 1390 do { 1369 1391 if (likely(lsr & UART_LSR_DR)) 1370 - ch = serial_inp(up, UART_RX); 1392 + ch = serial_in(up, UART_RX); 1371 1393 else 1372 1394 /* 1373 1395 * Intel 82571 has a Serial Over Lan device that will ··· 1380 1400 ch = 0; 1381 1401 1382 1402 flag = TTY_NORMAL; 1383 - up->port.icount.rx++; 1403 + port->icount.rx++; 1384 1404 1385 1405 lsr |= up->lsr_saved_flags; 1386 1406 up->lsr_saved_flags = 0; ··· 1391 1411 */ 1392 1412 if (lsr & UART_LSR_BI) { 1393 1413 lsr &= ~(UART_LSR_FE | UART_LSR_PE); 1394 - up->port.icount.brk++; 1414 + port->icount.brk++; 1395 1415 /* 1396 1416 * If tegra port then clear the rx fifo to 1397 1417 * accept another break/character. 1398 1418 */ 1399 - if (up->port.type == PORT_TEGRA) 1419 + if (port->type == PORT_TEGRA) 1400 1420 clear_rx_fifo(up); 1401 1421 1402 1422 /* ··· 1405 1425 * may get masked by ignore_status_mask 1406 1426 * or read_status_mask. 1407 1427 */ 1408 - if (uart_handle_break(&up->port)) 1428 + if (uart_handle_break(port)) 1409 1429 goto ignore_char; 1410 1430 } else if (lsr & UART_LSR_PE) 1411 - up->port.icount.parity++; 1431 + port->icount.parity++; 1412 1432 else if (lsr & UART_LSR_FE) 1413 - up->port.icount.frame++; 1433 + port->icount.frame++; 1414 1434 if (lsr & UART_LSR_OE) 1415 - up->port.icount.overrun++; 1435 + port->icount.overrun++; 1416 1436 1417 1437 /* 1418 1438 * Mask off conditions which should be ignored. 1419 1439 */ 1420 - lsr &= up->port.read_status_mask; 1440 + lsr &= port->read_status_mask; 1421 1441 1422 1442 if (lsr & UART_LSR_BI) { 1423 1443 DEBUG_INTR("handling break...."); ··· 1427 1447 else if (lsr & UART_LSR_FE) 1428 1448 flag = TTY_FRAME; 1429 1449 } 1430 - if (uart_handle_sysrq_char(&up->port, ch)) 1450 + if (uart_handle_sysrq_char(port, ch)) 1431 1451 goto ignore_char; 1432 1452 1433 - uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag); 1453 + uart_insert_char(port, lsr, UART_LSR_OE, ch, flag); 1434 1454 1435 1455 ignore_char: 1436 - lsr = serial_inp(up, UART_LSR); 1456 + lsr = serial_in(up, UART_LSR); 1437 1457 } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0)); 1438 - spin_unlock(&up->port.lock); 1458 + spin_unlock(&port->lock); 1439 1459 tty_flip_buffer_push(tty); 1440 - spin_lock(&up->port.lock); 1460 + spin_lock(&port->lock); 1441 1461 return lsr; 1442 1462 } 1443 1463 EXPORT_SYMBOL_GPL(serial8250_rx_chars); 1444 1464 1445 1465 void serial8250_tx_chars(struct uart_8250_port *up) 1446 1466 { 1447 - struct circ_buf *xmit = &up->port.state->xmit; 1467 + struct uart_port *port = &up->port; 1468 + struct circ_buf *xmit = &port->state->xmit; 1448 1469 int count; 1449 1470 1450 - if (up->port.x_char) { 1451 - serial_outp(up, UART_TX, up->port.x_char); 1452 - up->port.icount.tx++; 1453 - up->port.x_char = 0; 1471 + if (port->x_char) { 1472 + serial_out(up, UART_TX, port->x_char); 1473 + port->icount.tx++; 1474 + port->x_char = 0; 1454 1475 return; 1455 1476 } 1456 - if (uart_tx_stopped(&up->port)) { 1457 - serial8250_stop_tx(&up->port); 1477 + if (uart_tx_stopped(port)) { 1478 + serial8250_stop_tx(port); 1458 1479 return; 1459 1480 } 1460 1481 if (uart_circ_empty(xmit)) { ··· 1467 1486 do { 1468 1487 serial_out(up, UART_TX, xmit->buf[xmit->tail]); 1469 1488 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 1470 - up->port.icount.tx++; 1489 + port->icount.tx++; 1471 1490 if (uart_circ_empty(xmit)) 1472 1491 break; 1473 1492 } while (--count > 0); 1474 1493 1475 1494 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 1476 - uart_write_wakeup(&up->port); 1495 + uart_write_wakeup(port); 1477 1496 1478 1497 DEBUG_INTR("THRE..."); 1479 1498 ··· 1484 1503 1485 1504 unsigned int serial8250_modem_status(struct uart_8250_port *up) 1486 1505 { 1506 + struct uart_port *port = &up->port; 1487 1507 unsigned int status = serial_in(up, UART_MSR); 1488 1508 1489 1509 status |= up->msr_saved_flags; 1490 1510 up->msr_saved_flags = 0; 1491 1511 if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && 1492 - up->port.state != NULL) { 1512 + port->state != NULL) { 1493 1513 if (status & UART_MSR_TERI) 1494 - up->port.icount.rng++; 1514 + port->icount.rng++; 1495 1515 if (status & UART_MSR_DDSR) 1496 - up->port.icount.dsr++; 1516 + port->icount.dsr++; 1497 1517 if (status & UART_MSR_DDCD) 1498 - uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); 1518 + uart_handle_dcd_change(port, status & UART_MSR_DCD); 1499 1519 if (status & UART_MSR_DCTS) 1500 - uart_handle_cts_change(&up->port, status & UART_MSR_CTS); 1520 + uart_handle_cts_change(port, status & UART_MSR_CTS); 1501 1521 1502 - wake_up_interruptible(&up->port.state->port.delta_msr_wait); 1522 + wake_up_interruptible(&port->state->port.delta_msr_wait); 1503 1523 } 1504 1524 1505 1525 return status; ··· 1520 1538 if (iir & UART_IIR_NO_INT) 1521 1539 return 0; 1522 1540 1523 - spin_lock_irqsave(&up->port.lock, flags); 1541 + spin_lock_irqsave(&port->lock, flags); 1524 1542 1525 - status = serial_inp(up, UART_LSR); 1543 + status = serial_port_in(port, UART_LSR); 1526 1544 1527 1545 DEBUG_INTR("status = %x...", status); 1528 1546 ··· 1532 1550 if (status & UART_LSR_THRE) 1533 1551 serial8250_tx_chars(up); 1534 1552 1535 - spin_unlock_irqrestore(&up->port.lock, flags); 1553 + spin_unlock_irqrestore(&port->lock, flags); 1536 1554 return 1; 1537 1555 } 1538 1556 EXPORT_SYMBOL_GPL(serial8250_handle_irq); 1539 1557 1540 1558 static int serial8250_default_handle_irq(struct uart_port *port) 1541 1559 { 1542 - struct uart_8250_port *up = 1543 - container_of(port, struct uart_8250_port, port); 1544 - unsigned int iir = serial_in(up, UART_IIR); 1560 + unsigned int iir = serial_port_in(port, UART_IIR); 1545 1561 1546 1562 return serial8250_handle_irq(port, iir); 1547 1563 } ··· 1730 1750 * Must disable interrupts or else we risk racing with the interrupt 1731 1751 * based handler. 1732 1752 */ 1733 - if (is_real_interrupt(up->port.irq)) { 1753 + if (up->port.irq) { 1734 1754 ier = serial_in(up, UART_IER); 1735 1755 serial_out(up, UART_IER, 0); 1736 1756 } ··· 1755 1775 if (!(iir & UART_IIR_NO_INT)) 1756 1776 serial8250_tx_chars(up); 1757 1777 1758 - if (is_real_interrupt(up->port.irq)) 1778 + if (up->port.irq) 1759 1779 serial_out(up, UART_IER, ier); 1760 1780 1761 1781 spin_unlock_irqrestore(&up->port.lock, flags); ··· 1772 1792 unsigned long flags; 1773 1793 unsigned int lsr; 1774 1794 1775 - spin_lock_irqsave(&up->port.lock, flags); 1776 - lsr = serial_in(up, UART_LSR); 1795 + spin_lock_irqsave(&port->lock, flags); 1796 + lsr = serial_port_in(port, UART_LSR); 1777 1797 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; 1778 - spin_unlock_irqrestore(&up->port.lock, flags); 1798 + spin_unlock_irqrestore(&port->lock, flags); 1779 1799 1780 1800 return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; 1781 1801 } ··· 1820 1840 1821 1841 mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; 1822 1842 1823 - serial_out(up, UART_MCR, mcr); 1843 + serial_port_out(port, UART_MCR, mcr); 1824 1844 } 1825 1845 1826 1846 static void serial8250_break_ctl(struct uart_port *port, int break_state) ··· 1829 1849 container_of(port, struct uart_8250_port, port); 1830 1850 unsigned long flags; 1831 1851 1832 - spin_lock_irqsave(&up->port.lock, flags); 1852 + spin_lock_irqsave(&port->lock, flags); 1833 1853 if (break_state == -1) 1834 1854 up->lcr |= UART_LCR_SBC; 1835 1855 else 1836 1856 up->lcr &= ~UART_LCR_SBC; 1837 - serial_out(up, UART_LCR, up->lcr); 1838 - spin_unlock_irqrestore(&up->port.lock, flags); 1857 + serial_port_out(port, UART_LCR, up->lcr); 1858 + spin_unlock_irqrestore(&port->lock, flags); 1839 1859 } 1840 1860 1841 1861 /* ··· 1880 1900 1881 1901 static int serial8250_get_poll_char(struct uart_port *port) 1882 1902 { 1883 - struct uart_8250_port *up = 1884 - container_of(port, struct uart_8250_port, port); 1885 - unsigned char lsr = serial_inp(up, UART_LSR); 1903 + unsigned char lsr = serial_port_in(port, UART_LSR); 1886 1904 1887 1905 if (!(lsr & UART_LSR_DR)) 1888 1906 return NO_POLL_CHAR; 1889 1907 1890 - return serial_inp(up, UART_RX); 1908 + return serial_port_in(port, UART_RX); 1891 1909 } 1892 1910 1893 1911 ··· 1899 1921 /* 1900 1922 * First save the IER then disable the interrupts 1901 1923 */ 1902 - ier = serial_in(up, UART_IER); 1924 + ier = serial_port_in(port, UART_IER); 1903 1925 if (up->capabilities & UART_CAP_UUE) 1904 - serial_out(up, UART_IER, UART_IER_UUE); 1926 + serial_port_out(port, UART_IER, UART_IER_UUE); 1905 1927 else 1906 - serial_out(up, UART_IER, 0); 1928 + serial_port_out(port, UART_IER, 0); 1907 1929 1908 1930 wait_for_xmitr(up, BOTH_EMPTY); 1909 1931 /* 1910 1932 * Send the character out. 1911 1933 * If a LF, also do CR... 1912 1934 */ 1913 - serial_out(up, UART_TX, c); 1935 + serial_port_out(port, UART_TX, c); 1914 1936 if (c == 10) { 1915 1937 wait_for_xmitr(up, BOTH_EMPTY); 1916 - serial_out(up, UART_TX, 13); 1938 + serial_port_out(port, UART_TX, 13); 1917 1939 } 1918 1940 1919 1941 /* ··· 1921 1943 * and restore the IER 1922 1944 */ 1923 1945 wait_for_xmitr(up, BOTH_EMPTY); 1924 - serial_out(up, UART_IER, ier); 1946 + serial_port_out(port, UART_IER, ier); 1925 1947 } 1926 1948 1927 1949 #endif /* CONFIG_CONSOLE_POLL */ ··· 1934 1956 unsigned char lsr, iir; 1935 1957 int retval; 1936 1958 1937 - up->port.fifosize = uart_config[up->port.type].fifo_size; 1959 + port->fifosize = uart_config[up->port.type].fifo_size; 1938 1960 up->tx_loadsz = uart_config[up->port.type].tx_loadsz; 1939 1961 up->capabilities = uart_config[up->port.type].flags; 1940 1962 up->mcr = 0; 1941 1963 1942 - if (up->port.iotype != up->cur_iotype) 1964 + if (port->iotype != up->cur_iotype) 1943 1965 set_io_from_upio(port); 1944 1966 1945 - if (up->port.type == PORT_16C950) { 1967 + if (port->type == PORT_16C950) { 1946 1968 /* Wake up and initialize UART */ 1947 1969 up->acr = 0; 1948 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 1949 - serial_outp(up, UART_EFR, UART_EFR_ECB); 1950 - serial_outp(up, UART_IER, 0); 1951 - serial_outp(up, UART_LCR, 0); 1970 + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 1971 + serial_port_out(port, UART_EFR, UART_EFR_ECB); 1972 + serial_port_out(port, UART_IER, 0); 1973 + serial_port_out(port, UART_LCR, 0); 1952 1974 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 1953 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 1954 - serial_outp(up, UART_EFR, UART_EFR_ECB); 1955 - serial_outp(up, UART_LCR, 0); 1975 + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 1976 + serial_port_out(port, UART_EFR, UART_EFR_ECB); 1977 + serial_port_out(port, UART_LCR, 0); 1956 1978 } 1957 1979 1958 1980 #ifdef CONFIG_SERIAL_8250_RSA ··· 1972 1994 /* 1973 1995 * Clear the interrupt registers. 1974 1996 */ 1975 - (void) serial_inp(up, UART_LSR); 1976 - (void) serial_inp(up, UART_RX); 1977 - (void) serial_inp(up, UART_IIR); 1978 - (void) serial_inp(up, UART_MSR); 1997 + serial_port_in(port, UART_LSR); 1998 + serial_port_in(port, UART_RX); 1999 + serial_port_in(port, UART_IIR); 2000 + serial_port_in(port, UART_MSR); 1979 2001 1980 2002 /* 1981 2003 * At this point, there's no way the LSR could still be 0xff; 1982 2004 * if it is, then bail out, because there's likely no UART 1983 2005 * here. 1984 2006 */ 1985 - if (!(up->port.flags & UPF_BUGGY_UART) && 1986 - (serial_inp(up, UART_LSR) == 0xff)) { 2007 + if (!(port->flags & UPF_BUGGY_UART) && 2008 + (serial_port_in(port, UART_LSR) == 0xff)) { 1987 2009 printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n", 1988 - serial_index(&up->port)); 2010 + serial_index(port)); 1989 2011 return -ENODEV; 1990 2012 } 1991 2013 1992 2014 /* 1993 2015 * For a XR16C850, we need to set the trigger levels 1994 2016 */ 1995 - if (up->port.type == PORT_16850) { 2017 + if (port->type == PORT_16850) { 1996 2018 unsigned char fctr; 1997 2019 1998 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 2020 + serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 1999 2021 2000 - fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); 2001 - serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX); 2002 - serial_outp(up, UART_TRG, UART_TRG_96); 2003 - serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX); 2004 - serial_outp(up, UART_TRG, UART_TRG_96); 2022 + fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); 2023 + serial_port_out(port, UART_FCTR, 2024 + fctr | UART_FCTR_TRGD | UART_FCTR_RX); 2025 + serial_port_out(port, UART_TRG, UART_TRG_96); 2026 + serial_port_out(port, UART_FCTR, 2027 + fctr | UART_FCTR_TRGD | UART_FCTR_TX); 2028 + serial_port_out(port, UART_TRG, UART_TRG_96); 2005 2029 2006 - serial_outp(up, UART_LCR, 0); 2030 + serial_port_out(port, UART_LCR, 0); 2007 2031 } 2008 2032 2009 - if (is_real_interrupt(up->port.irq)) { 2033 + if (port->irq) { 2010 2034 unsigned char iir1; 2011 2035 /* 2012 2036 * Test for UARTs that do not reassert THRE when the ··· 2018 2038 * the interrupt is enabled. Delays are necessary to 2019 2039 * allow register changes to become visible. 2020 2040 */ 2021 - spin_lock_irqsave(&up->port.lock, flags); 2041 + spin_lock_irqsave(&port->lock, flags); 2022 2042 if (up->port.irqflags & IRQF_SHARED) 2023 - disable_irq_nosync(up->port.irq); 2043 + disable_irq_nosync(port->irq); 2024 2044 2025 2045 wait_for_xmitr(up, UART_LSR_THRE); 2026 - serial_out_sync(up, UART_IER, UART_IER_THRI); 2046 + serial_port_out_sync(port, UART_IER, UART_IER_THRI); 2027 2047 udelay(1); /* allow THRE to set */ 2028 - iir1 = serial_in(up, UART_IIR); 2029 - serial_out(up, UART_IER, 0); 2030 - serial_out_sync(up, UART_IER, UART_IER_THRI); 2048 + iir1 = serial_port_in(port, UART_IIR); 2049 + serial_port_out(port, UART_IER, 0); 2050 + serial_port_out_sync(port, UART_IER, UART_IER_THRI); 2031 2051 udelay(1); /* allow a working UART time to re-assert THRE */ 2032 - iir = serial_in(up, UART_IIR); 2033 - serial_out(up, UART_IER, 0); 2052 + iir = serial_port_in(port, UART_IIR); 2053 + serial_port_out(port, UART_IER, 0); 2034 2054 2035 - if (up->port.irqflags & IRQF_SHARED) 2036 - enable_irq(up->port.irq); 2037 - spin_unlock_irqrestore(&up->port.lock, flags); 2055 + if (port->irqflags & IRQF_SHARED) 2056 + enable_irq(port->irq); 2057 + spin_unlock_irqrestore(&port->lock, flags); 2038 2058 2039 2059 /* 2040 2060 * If the interrupt is not reasserted, setup a timer to ··· 2063 2083 * hardware interrupt, we use a timer-based system. The original 2064 2084 * driver used to do this with IRQ0. 2065 2085 */ 2066 - if (!is_real_interrupt(up->port.irq)) { 2086 + if (!port->irq) { 2067 2087 up->timer.data = (unsigned long)up; 2068 2088 mod_timer(&up->timer, jiffies + uart_poll_timeout(port)); 2069 2089 } else { ··· 2075 2095 /* 2076 2096 * Now, initialize the UART 2077 2097 */ 2078 - serial_outp(up, UART_LCR, UART_LCR_WLEN8); 2098 + serial_port_out(port, UART_LCR, UART_LCR_WLEN8); 2079 2099 2080 - spin_lock_irqsave(&up->port.lock, flags); 2100 + spin_lock_irqsave(&port->lock, flags); 2081 2101 if (up->port.flags & UPF_FOURPORT) { 2082 - if (!is_real_interrupt(up->port.irq)) 2102 + if (!up->port.irq) 2083 2103 up->port.mctrl |= TIOCM_OUT1; 2084 2104 } else 2085 2105 /* 2086 2106 * Most PC uarts need OUT2 raised to enable interrupts. 2087 2107 */ 2088 - if (is_real_interrupt(up->port.irq)) 2108 + if (port->irq) 2089 2109 up->port.mctrl |= TIOCM_OUT2; 2090 2110 2091 - serial8250_set_mctrl(&up->port, up->port.mctrl); 2111 + serial8250_set_mctrl(port, port->mctrl); 2092 2112 2093 2113 /* Serial over Lan (SoL) hack: 2094 2114 Intel 8257x Gigabit ethernet chips have a ··· 2108 2128 * Do a quick test to see if we receive an 2109 2129 * interrupt when we enable the TX irq. 2110 2130 */ 2111 - serial_outp(up, UART_IER, UART_IER_THRI); 2112 - lsr = serial_in(up, UART_LSR); 2113 - iir = serial_in(up, UART_IIR); 2114 - serial_outp(up, UART_IER, 0); 2131 + serial_port_out(port, UART_IER, UART_IER_THRI); 2132 + lsr = serial_port_in(port, UART_LSR); 2133 + iir = serial_port_in(port, UART_IIR); 2134 + serial_port_out(port, UART_IER, 0); 2115 2135 2116 2136 if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { 2117 2137 if (!(up->bugs & UART_BUG_TXEN)) { ··· 2124 2144 } 2125 2145 2126 2146 dont_test_tx_en: 2127 - spin_unlock_irqrestore(&up->port.lock, flags); 2147 + spin_unlock_irqrestore(&port->lock, flags); 2128 2148 2129 2149 /* 2130 2150 * Clear the interrupt registers again for luck, and clear the 2131 2151 * saved flags to avoid getting false values from polling 2132 2152 * routines or the previous session. 2133 2153 */ 2134 - serial_inp(up, UART_LSR); 2135 - serial_inp(up, UART_RX); 2136 - serial_inp(up, UART_IIR); 2137 - serial_inp(up, UART_MSR); 2154 + serial_port_in(port, UART_LSR); 2155 + serial_port_in(port, UART_RX); 2156 + serial_port_in(port, UART_IIR); 2157 + serial_port_in(port, UART_MSR); 2138 2158 up->lsr_saved_flags = 0; 2139 2159 up->msr_saved_flags = 0; 2140 2160 ··· 2144 2164 * anyway, so we don't enable them here. 2145 2165 */ 2146 2166 up->ier = UART_IER_RLSI | UART_IER_RDI; 2147 - serial_outp(up, UART_IER, up->ier); 2167 + serial_port_out(port, UART_IER, up->ier); 2148 2168 2149 - if (up->port.flags & UPF_FOURPORT) { 2169 + if (port->flags & UPF_FOURPORT) { 2150 2170 unsigned int icp; 2151 2171 /* 2152 2172 * Enable interrupts on the AST Fourport board 2153 2173 */ 2154 - icp = (up->port.iobase & 0xfe0) | 0x01f; 2174 + icp = (port->iobase & 0xfe0) | 0x01f; 2155 2175 outb_p(0x80, icp); 2156 - (void) inb_p(icp); 2176 + inb_p(icp); 2157 2177 } 2158 2178 2159 2179 return 0; ··· 2169 2189 * Disable interrupts from this port 2170 2190 */ 2171 2191 up->ier = 0; 2172 - serial_outp(up, UART_IER, 0); 2192 + serial_port_out(port, UART_IER, 0); 2173 2193 2174 - spin_lock_irqsave(&up->port.lock, flags); 2175 - if (up->port.flags & UPF_FOURPORT) { 2194 + spin_lock_irqsave(&port->lock, flags); 2195 + if (port->flags & UPF_FOURPORT) { 2176 2196 /* reset interrupts on the AST Fourport board */ 2177 - inb((up->port.iobase & 0xfe0) | 0x1f); 2178 - up->port.mctrl |= TIOCM_OUT1; 2197 + inb((port->iobase & 0xfe0) | 0x1f); 2198 + port->mctrl |= TIOCM_OUT1; 2179 2199 } else 2180 - up->port.mctrl &= ~TIOCM_OUT2; 2200 + port->mctrl &= ~TIOCM_OUT2; 2181 2201 2182 - serial8250_set_mctrl(&up->port, up->port.mctrl); 2183 - spin_unlock_irqrestore(&up->port.lock, flags); 2202 + serial8250_set_mctrl(port, port->mctrl); 2203 + spin_unlock_irqrestore(&port->lock, flags); 2184 2204 2185 2205 /* 2186 2206 * Disable break condition and FIFOs 2187 2207 */ 2188 - serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); 2208 + serial_port_out(port, UART_LCR, 2209 + serial_port_in(port, UART_LCR) & ~UART_LCR_SBC); 2189 2210 serial8250_clear_fifos(up); 2190 2211 2191 2212 #ifdef CONFIG_SERIAL_8250_RSA ··· 2200 2219 * Read data port to reset things, and then unlink from 2201 2220 * the IRQ chain. 2202 2221 */ 2203 - (void) serial_in(up, UART_RX); 2222 + serial_port_in(port, UART_RX); 2204 2223 2205 2224 del_timer_sync(&up->timer); 2206 2225 up->timer.function = serial8250_timeout; 2207 - if (is_real_interrupt(up->port.irq)) 2226 + if (port->irq) 2208 2227 serial_unlink_irq_chain(up); 2209 2228 } 2210 2229 ··· 2279 2298 if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) 2280 2299 quot++; 2281 2300 2282 - if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) { 2301 + if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { 2283 2302 if (baud < 2400) 2284 2303 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; 2285 2304 else 2286 - fcr = uart_config[up->port.type].fcr; 2305 + fcr = uart_config[port->type].fcr; 2287 2306 } 2288 2307 2289 2308 /* ··· 2294 2313 * have sufficient FIFO entries for the latency of the remote 2295 2314 * UART to respond. IOW, at least 32 bytes of FIFO. 2296 2315 */ 2297 - if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) { 2316 + if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) { 2298 2317 up->mcr &= ~UART_MCR_AFE; 2299 2318 if (termios->c_cflag & CRTSCTS) 2300 2319 up->mcr |= UART_MCR_AFE; ··· 2304 2323 * Ok, we're now changing the port state. Do it with 2305 2324 * interrupts disabled. 2306 2325 */ 2307 - spin_lock_irqsave(&up->port.lock, flags); 2326 + spin_lock_irqsave(&port->lock, flags); 2308 2327 2309 2328 /* 2310 2329 * Update the per-port timeout. 2311 2330 */ 2312 2331 uart_update_timeout(port, termios->c_cflag, baud); 2313 2332 2314 - up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 2333 + port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 2315 2334 if (termios->c_iflag & INPCK) 2316 - up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; 2335 + port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 2317 2336 if (termios->c_iflag & (BRKINT | PARMRK)) 2318 - up->port.read_status_mask |= UART_LSR_BI; 2337 + port->read_status_mask |= UART_LSR_BI; 2319 2338 2320 2339 /* 2321 2340 * Characteres to ignore 2322 2341 */ 2323 - up->port.ignore_status_mask = 0; 2342 + port->ignore_status_mask = 0; 2324 2343 if (termios->c_iflag & IGNPAR) 2325 - up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 2344 + port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 2326 2345 if (termios->c_iflag & IGNBRK) { 2327 - up->port.ignore_status_mask |= UART_LSR_BI; 2346 + port->ignore_status_mask |= UART_LSR_BI; 2328 2347 /* 2329 2348 * If we're ignoring parity and break indicators, 2330 2349 * ignore overruns too (for real raw support). 2331 2350 */ 2332 2351 if (termios->c_iflag & IGNPAR) 2333 - up->port.ignore_status_mask |= UART_LSR_OE; 2352 + port->ignore_status_mask |= UART_LSR_OE; 2334 2353 } 2335 2354 2336 2355 /* 2337 2356 * ignore all characters if CREAD is not set 2338 2357 */ 2339 2358 if ((termios->c_cflag & CREAD) == 0) 2340 - up->port.ignore_status_mask |= UART_LSR_DR; 2359 + port->ignore_status_mask |= UART_LSR_DR; 2341 2360 2342 2361 /* 2343 2362 * CTS flow control flag and modem status interrupts ··· 2351 2370 if (up->capabilities & UART_CAP_RTOIE) 2352 2371 up->ier |= UART_IER_RTOIE; 2353 2372 2354 - serial_out(up, UART_IER, up->ier); 2373 + serial_port_out(port, UART_IER, up->ier); 2355 2374 2356 2375 if (up->capabilities & UART_CAP_EFR) { 2357 2376 unsigned char efr = 0; ··· 2363 2382 if (termios->c_cflag & CRTSCTS) 2364 2383 efr |= UART_EFR_CTS; 2365 2384 2366 - serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B); 2367 - if (up->port.flags & UPF_EXAR_EFR) 2368 - serial_outp(up, UART_XR_EFR, efr); 2385 + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 2386 + if (port->flags & UPF_EXAR_EFR) 2387 + serial_port_out(port, UART_XR_EFR, efr); 2369 2388 else 2370 - serial_outp(up, UART_EFR, efr); 2389 + serial_port_out(port, UART_EFR, efr); 2371 2390 } 2372 2391 2373 2392 #ifdef CONFIG_ARCH_OMAP ··· 2375 2394 if (cpu_is_omap1510() && is_omap_port(up)) { 2376 2395 if (baud == 115200) { 2377 2396 quot = 1; 2378 - serial_out(up, UART_OMAP_OSC_12M_SEL, 1); 2397 + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); 2379 2398 } else 2380 - serial_out(up, UART_OMAP_OSC_12M_SEL, 0); 2399 + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); 2381 2400 } 2382 2401 #endif 2383 2402 2384 - if (up->capabilities & UART_NATSEMI) { 2385 - /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */ 2386 - serial_outp(up, UART_LCR, 0xe0); 2387 - } else { 2388 - serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ 2389 - } 2403 + /* 2404 + * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, 2405 + * otherwise just set DLAB 2406 + */ 2407 + if (up->capabilities & UART_NATSEMI) 2408 + serial_port_out(port, UART_LCR, 0xe0); 2409 + else 2410 + serial_port_out(port, UART_LCR, cval | UART_LCR_DLAB); 2390 2411 2391 2412 serial_dl_write(up, quot); 2392 2413 ··· 2396 2413 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR 2397 2414 * is written without DLAB set, this mode will be disabled. 2398 2415 */ 2399 - if (up->port.type == PORT_16750) 2400 - serial_outp(up, UART_FCR, fcr); 2416 + if (port->type == PORT_16750) 2417 + serial_port_out(port, UART_FCR, fcr); 2401 2418 2402 - serial_outp(up, UART_LCR, cval); /* reset DLAB */ 2419 + serial_port_out(port, UART_LCR, cval); /* reset DLAB */ 2403 2420 up->lcr = cval; /* Save LCR */ 2404 - if (up->port.type != PORT_16750) { 2405 - if (fcr & UART_FCR_ENABLE_FIFO) { 2406 - /* emulated UARTs (Lucent Venus 167x) need two steps */ 2407 - serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 2408 - } 2409 - serial_outp(up, UART_FCR, fcr); /* set fcr */ 2421 + if (port->type != PORT_16750) { 2422 + /* emulated UARTs (Lucent Venus 167x) need two steps */ 2423 + if (fcr & UART_FCR_ENABLE_FIFO) 2424 + serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); 2425 + serial_port_out(port, UART_FCR, fcr); /* set fcr */ 2410 2426 } 2411 - serial8250_set_mctrl(&up->port, up->port.mctrl); 2412 - spin_unlock_irqrestore(&up->port.lock, flags); 2427 + serial8250_set_mctrl(port, port->mctrl); 2428 + spin_unlock_irqrestore(&port->lock, flags); 2413 2429 /* Don't rewrite B0 */ 2414 2430 if (tty_termios_baud_rate(termios)) 2415 2431 tty_termios_encode_baud_rate(termios, baud, baud); ··· 2473 2491 static int serial8250_request_std_resource(struct uart_8250_port *up) 2474 2492 { 2475 2493 unsigned int size = serial8250_port_size(up); 2494 + struct uart_port *port = &up->port; 2476 2495 int ret = 0; 2477 2496 2478 - switch (up->port.iotype) { 2497 + switch (port->iotype) { 2479 2498 case UPIO_AU: 2480 2499 case UPIO_TSI: 2481 2500 case UPIO_MEM32: 2482 2501 case UPIO_MEM: 2483 - if (!up->port.mapbase) 2502 + if (!port->mapbase) 2484 2503 break; 2485 2504 2486 - if (!request_mem_region(up->port.mapbase, size, "serial")) { 2505 + if (!request_mem_region(port->mapbase, size, "serial")) { 2487 2506 ret = -EBUSY; 2488 2507 break; 2489 2508 } 2490 2509 2491 - if (up->port.flags & UPF_IOREMAP) { 2492 - up->port.membase = ioremap_nocache(up->port.mapbase, 2493 - size); 2494 - if (!up->port.membase) { 2495 - release_mem_region(up->port.mapbase, size); 2510 + if (port->flags & UPF_IOREMAP) { 2511 + port->membase = ioremap_nocache(port->mapbase, size); 2512 + if (!port->membase) { 2513 + release_mem_region(port->mapbase, size); 2496 2514 ret = -ENOMEM; 2497 2515 } 2498 2516 } ··· 2500 2518 2501 2519 case UPIO_HUB6: 2502 2520 case UPIO_PORT: 2503 - if (!request_region(up->port.iobase, size, "serial")) 2521 + if (!request_region(port->iobase, size, "serial")) 2504 2522 ret = -EBUSY; 2505 2523 break; 2506 2524 } ··· 2510 2528 static void serial8250_release_std_resource(struct uart_8250_port *up) 2511 2529 { 2512 2530 unsigned int size = serial8250_port_size(up); 2531 + struct uart_port *port = &up->port; 2513 2532 2514 - switch (up->port.iotype) { 2533 + switch (port->iotype) { 2515 2534 case UPIO_AU: 2516 2535 case UPIO_TSI: 2517 2536 case UPIO_MEM32: 2518 2537 case UPIO_MEM: 2519 - if (!up->port.mapbase) 2538 + if (!port->mapbase) 2520 2539 break; 2521 2540 2522 - if (up->port.flags & UPF_IOREMAP) { 2523 - iounmap(up->port.membase); 2524 - up->port.membase = NULL; 2541 + if (port->flags & UPF_IOREMAP) { 2542 + iounmap(port->membase); 2543 + port->membase = NULL; 2525 2544 } 2526 2545 2527 - release_mem_region(up->port.mapbase, size); 2546 + release_mem_region(port->mapbase, size); 2528 2547 break; 2529 2548 2530 2549 case UPIO_HUB6: 2531 2550 case UPIO_PORT: 2532 - release_region(up->port.iobase, size); 2551 + release_region(port->iobase, size); 2533 2552 break; 2534 2553 } 2535 2554 } ··· 2539 2556 { 2540 2557 unsigned long start = UART_RSA_BASE << up->port.regshift; 2541 2558 unsigned int size = 8 << up->port.regshift; 2559 + struct uart_port *port = &up->port; 2542 2560 int ret = -EINVAL; 2543 2561 2544 - switch (up->port.iotype) { 2562 + switch (port->iotype) { 2545 2563 case UPIO_HUB6: 2546 2564 case UPIO_PORT: 2547 - start += up->port.iobase; 2565 + start += port->iobase; 2548 2566 if (request_region(start, size, "serial-rsa")) 2549 2567 ret = 0; 2550 2568 else ··· 2560 2576 { 2561 2577 unsigned long offset = UART_RSA_BASE << up->port.regshift; 2562 2578 unsigned int size = 8 << up->port.regshift; 2579 + struct uart_port *port = &up->port; 2563 2580 2564 - switch (up->port.iotype) { 2581 + switch (port->iotype) { 2565 2582 case UPIO_HUB6: 2566 2583 case UPIO_PORT: 2567 - release_region(up->port.iobase + offset, size); 2584 + release_region(port->iobase + offset, size); 2568 2585 break; 2569 2586 } 2570 2587 } ··· 2576 2591 container_of(port, struct uart_8250_port, port); 2577 2592 2578 2593 serial8250_release_std_resource(up); 2579 - if (up->port.type == PORT_RSA) 2594 + if (port->type == PORT_RSA) 2580 2595 serial8250_release_rsa_resource(up); 2581 2596 } 2582 2597 ··· 2587 2602 int ret = 0; 2588 2603 2589 2604 ret = serial8250_request_std_resource(up); 2590 - if (ret == 0 && up->port.type == PORT_RSA) { 2605 + if (ret == 0 && port->type == PORT_RSA) { 2591 2606 ret = serial8250_request_rsa_resource(up); 2592 2607 if (ret < 0) 2593 2608 serial8250_release_std_resource(up); ··· 2615 2630 if (ret < 0) 2616 2631 probeflags &= ~PROBE_RSA; 2617 2632 2618 - if (up->port.iotype != up->cur_iotype) 2633 + if (port->iotype != up->cur_iotype) 2619 2634 set_io_from_upio(port); 2620 2635 2621 2636 if (flags & UART_CONFIG_TYPE) 2622 2637 autoconfig(up, probeflags); 2623 2638 2624 2639 /* if access method is AU, it is a 16550 with a quirk */ 2625 - if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU) 2640 + if (port->type == PORT_16550A && port->iotype == UPIO_AU) 2626 2641 up->bugs |= UART_BUG_NOMSR; 2627 2642 2628 - if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) 2643 + if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) 2629 2644 autoconfig_irq(up); 2630 2645 2631 - if (up->port.type != PORT_RSA && probeflags & PROBE_RSA) 2646 + if (port->type != PORT_RSA && probeflags & PROBE_RSA) 2632 2647 serial8250_release_rsa_resource(up); 2633 - if (up->port.type == PORT_UNKNOWN) 2648 + if (port->type == PORT_UNKNOWN) 2634 2649 serial8250_release_std_resource(up); 2635 2650 } 2636 2651 ··· 2704 2719 2705 2720 for (i = 0; i < nr_uarts; i++) { 2706 2721 struct uart_8250_port *up = &serial8250_ports[i]; 2722 + struct uart_port *port = &up->port; 2707 2723 2708 - up->port.line = i; 2709 - spin_lock_init(&up->port.lock); 2724 + port->line = i; 2725 + spin_lock_init(&port->lock); 2710 2726 2711 2727 init_timer(&up->timer); 2712 2728 up->timer.function = serial8250_timeout; ··· 2718 2732 up->mcr_mask = ~ALPHA_KLUDGE_MCR; 2719 2733 up->mcr_force = ALPHA_KLUDGE_MCR; 2720 2734 2721 - up->port.ops = &serial8250_pops; 2735 + port->ops = &serial8250_pops; 2722 2736 } 2723 2737 2724 2738 if (share_irqs) ··· 2727 2741 for (i = 0, up = serial8250_ports; 2728 2742 i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; 2729 2743 i++, up++) { 2730 - up->port.iobase = old_serial_port[i].port; 2731 - up->port.irq = irq_canonicalize(old_serial_port[i].irq); 2732 - up->port.irqflags = old_serial_port[i].irqflags; 2733 - up->port.uartclk = old_serial_port[i].baud_base * 16; 2734 - up->port.flags = old_serial_port[i].flags; 2735 - up->port.hub6 = old_serial_port[i].hub6; 2736 - up->port.membase = old_serial_port[i].iomem_base; 2737 - up->port.iotype = old_serial_port[i].io_type; 2738 - up->port.regshift = old_serial_port[i].iomem_reg_shift; 2739 - set_io_from_upio(&up->port); 2740 - up->port.irqflags |= irqflag; 2744 + struct uart_port *port = &up->port; 2745 + 2746 + port->iobase = old_serial_port[i].port; 2747 + port->irq = irq_canonicalize(old_serial_port[i].irq); 2748 + port->irqflags = old_serial_port[i].irqflags; 2749 + port->uartclk = old_serial_port[i].baud_base * 16; 2750 + port->flags = old_serial_port[i].flags; 2751 + port->hub6 = old_serial_port[i].hub6; 2752 + port->membase = old_serial_port[i].iomem_base; 2753 + port->iotype = old_serial_port[i].io_type; 2754 + port->regshift = old_serial_port[i].iomem_reg_shift; 2755 + set_io_from_upio(port); 2756 + port->irqflags |= irqflag; 2741 2757 if (serial8250_isa_config != NULL) 2742 2758 serial8250_isa_config(i, &up->port, &up->capabilities); 2743 2759 ··· 2787 2799 container_of(port, struct uart_8250_port, port); 2788 2800 2789 2801 wait_for_xmitr(up, UART_LSR_THRE); 2790 - serial_out(up, UART_TX, ch); 2802 + serial_port_out(port, UART_TX, ch); 2791 2803 } 2792 2804 2793 2805 /* ··· 2800 2812 serial8250_console_write(struct console *co, const char *s, unsigned int count) 2801 2813 { 2802 2814 struct uart_8250_port *up = &serial8250_ports[co->index]; 2815 + struct uart_port *port = &up->port; 2803 2816 unsigned long flags; 2804 2817 unsigned int ier; 2805 2818 int locked = 1; ··· 2808 2819 touch_nmi_watchdog(); 2809 2820 2810 2821 local_irq_save(flags); 2811 - if (up->port.sysrq) { 2822 + if (port->sysrq) { 2812 2823 /* serial8250_handle_irq() already took the lock */ 2813 2824 locked = 0; 2814 2825 } else if (oops_in_progress) { 2815 - locked = spin_trylock(&up->port.lock); 2826 + locked = spin_trylock(&port->lock); 2816 2827 } else 2817 - spin_lock(&up->port.lock); 2828 + spin_lock(&port->lock); 2818 2829 2819 2830 /* 2820 2831 * First save the IER then disable the interrupts 2821 2832 */ 2822 - ier = serial_in(up, UART_IER); 2833 + ier = serial_port_in(port, UART_IER); 2823 2834 2824 2835 if (up->capabilities & UART_CAP_UUE) 2825 - serial_out(up, UART_IER, UART_IER_UUE); 2836 + serial_port_out(port, UART_IER, UART_IER_UUE); 2826 2837 else 2827 - serial_out(up, UART_IER, 0); 2838 + serial_port_out(port, UART_IER, 0); 2828 2839 2829 - uart_console_write(&up->port, s, count, serial8250_console_putchar); 2840 + uart_console_write(port, s, count, serial8250_console_putchar); 2830 2841 2831 2842 /* 2832 2843 * Finally, wait for transmitter to become empty 2833 2844 * and restore the IER 2834 2845 */ 2835 2846 wait_for_xmitr(up, BOTH_EMPTY); 2836 - serial_out(up, UART_IER, ier); 2847 + serial_port_out(port, UART_IER, ier); 2837 2848 2838 2849 /* 2839 2850 * The receive handling will happen properly because the ··· 2846 2857 serial8250_modem_status(up); 2847 2858 2848 2859 if (locked) 2849 - spin_unlock(&up->port.lock); 2860 + spin_unlock(&port->lock); 2850 2861 local_irq_restore(flags); 2851 2862 } 2852 2863 ··· 2991 3002 void serial8250_resume_port(int line) 2992 3003 { 2993 3004 struct uart_8250_port *up = &serial8250_ports[line]; 3005 + struct uart_port *port = &up->port; 2994 3006 2995 3007 if (up->capabilities & UART_NATSEMI) { 2996 3008 /* Ensure it's still in high speed mode */ 2997 - serial_outp(up, UART_LCR, 0xE0); 3009 + serial_port_out(port, UART_LCR, 0xE0); 2998 3010 2999 3011 ns16550a_goto_highspeed(up); 3000 3012 3001 - serial_outp(up, UART_LCR, 0); 3002 - up->port.uartclk = 921600*16; 3013 + serial_port_out(port, UART_LCR, 0); 3014 + port->uartclk = 921600*16; 3003 3015 } 3004 - uart_resume_port(&serial8250_reg, &up->port); 3016 + uart_resume_port(&serial8250_reg, port); 3005 3017 } 3006 3018 3007 3019 /*
+10
drivers/tty/serial/8250/8250.h
··· 86 86 #define SERIAL8250_SHARE_IRQS 0 87 87 #endif 88 88 89 + static inline int serial_in(struct uart_8250_port *up, int offset) 90 + { 91 + return up->port.serial_in(&up->port, offset); 92 + } 93 + 94 + static inline void serial_out(struct uart_8250_port *up, int offset, int value) 95 + { 96 + up->port.serial_out(&up->port, offset, value); 97 + } 98 + 89 99 #if defined(__alpha__) && !defined(CONFIG_PCI) 90 100 /* 91 101 * Digital did something really horribly wrong with the OUT1 and OUT2
+13
drivers/tty/serial/Kconfig
··· 1347 1347 Set this to the number of serial ports you want the driver 1348 1348 to support. 1349 1349 1350 + config SERIAL_EFM32_UART 1351 + tristate "EFM32 UART/USART port." 1352 + depends on ARCH_EFM32 1353 + select SERIAL_CORE 1354 + help 1355 + This driver support the USART and UART ports on 1356 + Energy Micro's efm32 SoCs. 1357 + 1358 + config SERIAL_EFM32_UART_CONSOLE 1359 + bool "EFM32 UART/USART console support" 1360 + depends on SERIAL_EFM32_UART=y 1361 + select SERIAL_CORE_CONSOLE 1362 + 1350 1363 endmenu
+2 -1
drivers/tty/serial/Makefile
··· 61 61 obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o 62 62 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o 63 63 obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o 64 + obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o 64 65 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o 65 66 obj-$(CONFIG_SERIAL_QE) += ucc_uart.o 66 67 obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o 67 68 obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o 68 69 obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o 69 - obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o 70 70 obj-$(CONFIG_SERIAL_VT8500) += vt8500_serial.o 71 71 obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o 72 72 obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o ··· 78 78 obj-$(CONFIG_SERIAL_XILINX_PS_UART) += xilinx_uartps.o 79 79 obj-$(CONFIG_SERIAL_SIRFSOC) += sirfsoc_uart.o 80 80 obj-$(CONFIG_SERIAL_AR933X) += ar933x_uart.o 81 + obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o
+24 -23
drivers/tty/serial/altera_uart.c
··· 377 377 return 0; 378 378 } 379 379 380 + #ifdef CONFIG_CONSOLE_POLL 381 + static int altera_uart_poll_get_char(struct uart_port *port) 382 + { 383 + while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) & 384 + ALTERA_UART_STATUS_RRDY_MSK)) 385 + cpu_relax(); 386 + 387 + return altera_uart_readl(port, ALTERA_UART_RXDATA_REG); 388 + } 389 + 390 + static void altera_uart_poll_put_char(struct uart_port *port, unsigned char c) 391 + { 392 + while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) & 393 + ALTERA_UART_STATUS_TRDY_MSK)) 394 + cpu_relax(); 395 + 396 + altera_uart_writel(port, c, ALTERA_UART_TXDATA_REG); 397 + } 398 + #endif 399 + 380 400 /* 381 401 * Define the basic serial functions we support. 382 402 */ ··· 417 397 .release_port = altera_uart_release_port, 418 398 .config_port = altera_uart_config_port, 419 399 .verify_port = altera_uart_verify_port, 400 + #ifdef CONFIG_CONSOLE_POLL 401 + .poll_get_char = altera_uart_poll_get_char, 402 + .poll_put_char = altera_uart_poll_put_char, 403 + #endif 420 404 }; 421 405 422 406 static struct altera_uart altera_uart_ports[CONFIG_SERIAL_ALTERA_UART_MAXPORTS]; 423 407 424 408 #if defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE) 425 - 426 - int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp) 427 - { 428 - struct uart_port *port; 429 - int i; 430 - 431 - for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS && platp[i].mapbase; i++) { 432 - port = &altera_uart_ports[i].port; 433 - 434 - port->line = i; 435 - port->type = PORT_ALTERA_UART; 436 - port->mapbase = platp[i].mapbase; 437 - port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE); 438 - port->iotype = SERIAL_IO_MEM; 439 - port->irq = platp[i].irq; 440 - port->uartclk = platp[i].uartclk; 441 - port->flags = UPF_BOOT_AUTOCONF; 442 - port->ops = &altera_uart_ops; 443 - port->private_data = platp; 444 - } 445 - 446 - return 0; 447 - } 448 409 449 410 static void altera_uart_console_putc(struct uart_port *port, const char c) 450 411 {
+27 -5
drivers/tty/serial/amba-pl011.c
··· 827 827 { 828 828 struct uart_amba_port *uap = data; 829 829 struct pl011_dmarx_data *dmarx = &uap->dmarx; 830 + struct dma_chan *rxchan = dmarx->chan; 830 831 bool lastbuf = dmarx->use_buf_b; 832 + struct pl011_sgbuf *sgbuf = dmarx->use_buf_b ? 833 + &dmarx->sgbuf_b : &dmarx->sgbuf_a; 834 + size_t pending; 835 + struct dma_tx_state state; 831 836 int ret; 832 837 833 838 /* ··· 843 838 * we immediately trigger the next DMA job. 844 839 */ 845 840 spin_lock_irq(&uap->port.lock); 841 + /* 842 + * Rx data can be taken by the UART interrupts during 843 + * the DMA irq handler. So we check the residue here. 844 + */ 845 + rxchan->device->device_tx_status(rxchan, dmarx->cookie, &state); 846 + pending = sgbuf->sg.length - state.residue; 847 + BUG_ON(pending > PL011_DMA_BUFFER_SIZE); 848 + /* Then we terminate the transfer - we now know our residue */ 849 + dmaengine_terminate_all(rxchan); 850 + 846 851 uap->dmarx.running = false; 847 852 dmarx->use_buf_b = !lastbuf; 848 853 ret = pl011_dma_rx_trigger_dma(uap); 849 854 850 - pl011_dma_rx_chars(uap, PL011_DMA_BUFFER_SIZE, lastbuf, false); 855 + pl011_dma_rx_chars(uap, pending, lastbuf, false); 851 856 spin_unlock_irq(&uap->port.lock); 852 857 /* 853 858 * Do this check after we picked the DMA chars so we don't ··· 1396 1381 1397 1382 uap->port.uartclk = clk_get_rate(uap->clk); 1398 1383 1384 + /* Clear pending error and receive interrupts */ 1385 + writew(UART011_OEIS | UART011_BEIS | UART011_PEIS | UART011_FEIS | 1386 + UART011_RTIS | UART011_RXIS, uap->port.membase + UART011_ICR); 1387 + 1399 1388 /* 1400 1389 * Allocate the IRQ 1401 1390 */ ··· 1436 1417 cr |= UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE; 1437 1418 writew(cr, uap->port.membase + UART011_CR); 1438 1419 1439 - /* Clear pending error interrupts */ 1440 - writew(UART011_OEIS | UART011_BEIS | UART011_PEIS | UART011_FEIS, 1441 - uap->port.membase + UART011_ICR); 1442 - 1443 1420 /* 1444 1421 * initialise the old status of the modem signals 1445 1422 */ ··· 1450 1435 * as well. 1451 1436 */ 1452 1437 spin_lock_irq(&uap->port.lock); 1438 + /* Clear out any spuriously appearing RX interrupts */ 1439 + writew(UART011_RTIS | UART011_RXIS, 1440 + uap->port.membase + UART011_ICR); 1453 1441 uap->im = UART011_RTIM; 1454 1442 if (!pl011_dma_rx_running(uap)) 1455 1443 uap->im |= UART011_RXIM; ··· 1944 1926 ret = PTR_ERR(uap->clk); 1945 1927 goto unmap; 1946 1928 } 1929 + 1930 + /* Ensure interrupts from this UART are masked and cleared */ 1931 + writew(0, uap->port.membase + UART011_IMSC); 1932 + writew(0xffff, uap->port.membase + UART011_ICR); 1947 1933 1948 1934 uap->vendor = vendor; 1949 1935 uap->lcrh_rx = vendor->lcrh_rx;
+5 -3
drivers/tty/serial/bfin_uart.c
··· 535 535 * when start a new tx. 536 536 */ 537 537 UART_CLEAR_IER(uart, ETBEI); 538 - xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); 539 538 uart->port.icount.tx += uart->tx_count; 539 + if (!uart_circ_empty(xmit)) { 540 + xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); 540 541 541 - if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 542 - uart_write_wakeup(&uart->port); 542 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 543 + uart_write_wakeup(&uart->port); 544 + } 543 545 544 546 bfin_serial_dma_tx_chars(uart); 545 547 }
+3 -12
drivers/tty/serial/crisv10.c
··· 4105 4105 rs_open(struct tty_struct *tty, struct file * filp) 4106 4106 { 4107 4107 struct e100_serial *info; 4108 - int retval, line; 4108 + int retval; 4109 4109 unsigned long page; 4110 4110 int allocated_resources = 0; 4111 4111 4112 - /* find which port we want to open */ 4113 - line = tty->index; 4114 - 4115 - if (line < 0 || line >= NR_PORTS) 4116 - return -ENODEV; 4117 - 4118 - /* find the corresponding e100_serial struct in the table */ 4119 - info = rs_table + line; 4120 - 4121 - /* don't allow the opening of ports that are not enabled in the HW config */ 4112 + info = rs_table + tty->index; 4122 4113 if (!info->enabled) 4123 4114 return -ENODEV; 4124 4115 ··· 4122 4131 tty->driver_data = info; 4123 4132 info->port.tty = tty; 4124 4133 4125 - info->port.tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 4134 + tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY); 4126 4135 4127 4136 if (!tmp_buf) { 4128 4137 page = get_zeroed_page(GFP_KERNEL);
+830
drivers/tty/serial/efm32-uart.c
··· 1 + #if defined(CONFIG_SERIAL_EFM32_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 2 + #define SUPPORT_SYSRQ 3 + #endif 4 + 5 + #include <linux/kernel.h> 6 + #include <linux/module.h> 7 + #include <linux/io.h> 8 + #include <linux/platform_device.h> 9 + #include <linux/console.h> 10 + #include <linux/sysrq.h> 11 + #include <linux/serial_core.h> 12 + #include <linux/tty_flip.h> 13 + #include <linux/slab.h> 14 + #include <linux/clk.h> 15 + #include <linux/of.h> 16 + #include <linux/of_device.h> 17 + 18 + #include <linux/platform_data/efm32-uart.h> 19 + 20 + #define DRIVER_NAME "efm32-uart" 21 + #define DEV_NAME "ttyefm" 22 + 23 + #define UARTn_CTRL 0x00 24 + #define UARTn_CTRL_SYNC 0x0001 25 + #define UARTn_CTRL_TXBIL 0x1000 26 + 27 + #define UARTn_FRAME 0x04 28 + #define UARTn_FRAME_DATABITS__MASK 0x000f 29 + #define UARTn_FRAME_DATABITS(n) ((n) - 3) 30 + #define UARTn_FRAME_PARITY_NONE 0x0000 31 + #define UARTn_FRAME_PARITY_EVEN 0x0200 32 + #define UARTn_FRAME_PARITY_ODD 0x0300 33 + #define UARTn_FRAME_STOPBITS_HALF 0x0000 34 + #define UARTn_FRAME_STOPBITS_ONE 0x1000 35 + #define UARTn_FRAME_STOPBITS_TWO 0x3000 36 + 37 + #define UARTn_CMD 0x0c 38 + #define UARTn_CMD_RXEN 0x0001 39 + #define UARTn_CMD_RXDIS 0x0002 40 + #define UARTn_CMD_TXEN 0x0004 41 + #define UARTn_CMD_TXDIS 0x0008 42 + 43 + #define UARTn_STATUS 0x10 44 + #define UARTn_STATUS_TXENS 0x0002 45 + #define UARTn_STATUS_TXC 0x0020 46 + #define UARTn_STATUS_TXBL 0x0040 47 + #define UARTn_STATUS_RXDATAV 0x0080 48 + 49 + #define UARTn_CLKDIV 0x14 50 + 51 + #define UARTn_RXDATAX 0x18 52 + #define UARTn_RXDATAX_RXDATA__MASK 0x01ff 53 + #define UARTn_RXDATAX_PERR 0x4000 54 + #define UARTn_RXDATAX_FERR 0x8000 55 + /* 56 + * This is a software only flag used for ignore_status_mask and 57 + * read_status_mask! It's used for breaks that the hardware doesn't report 58 + * explicitly. 59 + */ 60 + #define SW_UARTn_RXDATAX_BERR 0x2000 61 + 62 + #define UARTn_TXDATA 0x34 63 + 64 + #define UARTn_IF 0x40 65 + #define UARTn_IF_TXC 0x0001 66 + #define UARTn_IF_TXBL 0x0002 67 + #define UARTn_IF_RXDATAV 0x0004 68 + #define UARTn_IF_RXOF 0x0010 69 + 70 + #define UARTn_IFS 0x44 71 + #define UARTn_IFC 0x48 72 + #define UARTn_IEN 0x4c 73 + 74 + #define UARTn_ROUTE 0x54 75 + #define UARTn_ROUTE_LOCATION__MASK 0x0700 76 + #define UARTn_ROUTE_LOCATION(n) (((n) << 8) & UARTn_ROUTE_LOCATION__MASK) 77 + #define UARTn_ROUTE_RXPEN 0x0001 78 + #define UARTn_ROUTE_TXPEN 0x0002 79 + 80 + struct efm32_uart_port { 81 + struct uart_port port; 82 + unsigned int txirq; 83 + struct clk *clk; 84 + }; 85 + #define to_efm_port(_port) container_of(_port, struct efm32_uart_port, port) 86 + #define efm_debug(efm_port, format, arg...) \ 87 + dev_dbg(efm_port->port.dev, format, ##arg) 88 + 89 + static void efm32_uart_write32(struct efm32_uart_port *efm_port, 90 + u32 value, unsigned offset) 91 + { 92 + writel_relaxed(value, efm_port->port.membase + offset); 93 + } 94 + 95 + static u32 efm32_uart_read32(struct efm32_uart_port *efm_port, 96 + unsigned offset) 97 + { 98 + return readl_relaxed(efm_port->port.membase + offset); 99 + } 100 + 101 + static unsigned int efm32_uart_tx_empty(struct uart_port *port) 102 + { 103 + struct efm32_uart_port *efm_port = to_efm_port(port); 104 + u32 status = efm32_uart_read32(efm_port, UARTn_STATUS); 105 + 106 + if (status & UARTn_STATUS_TXC) 107 + return TIOCSER_TEMT; 108 + else 109 + return 0; 110 + } 111 + 112 + static void efm32_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 113 + { 114 + /* sorry, neither handshaking lines nor loop functionallity */ 115 + } 116 + 117 + static unsigned int efm32_uart_get_mctrl(struct uart_port *port) 118 + { 119 + /* sorry, no handshaking lines available */ 120 + return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR; 121 + } 122 + 123 + static void efm32_uart_stop_tx(struct uart_port *port) 124 + { 125 + struct efm32_uart_port *efm_port = to_efm_port(port); 126 + u32 ien = efm32_uart_read32(efm_port, UARTn_IEN); 127 + 128 + efm32_uart_write32(efm_port, UARTn_CMD_TXDIS, UARTn_CMD); 129 + ien &= ~(UARTn_IF_TXC | UARTn_IF_TXBL); 130 + efm32_uart_write32(efm_port, ien, UARTn_IEN); 131 + } 132 + 133 + static void efm32_uart_tx_chars(struct efm32_uart_port *efm_port) 134 + { 135 + struct uart_port *port = &efm_port->port; 136 + struct circ_buf *xmit = &port->state->xmit; 137 + 138 + while (efm32_uart_read32(efm_port, UARTn_STATUS) & 139 + UARTn_STATUS_TXBL) { 140 + if (port->x_char) { 141 + port->icount.tx++; 142 + efm32_uart_write32(efm_port, port->x_char, 143 + UARTn_TXDATA); 144 + port->x_char = 0; 145 + continue; 146 + } 147 + if (!uart_circ_empty(xmit) && !uart_tx_stopped(port)) { 148 + port->icount.tx++; 149 + efm32_uart_write32(efm_port, xmit->buf[xmit->tail], 150 + UARTn_TXDATA); 151 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 152 + } else 153 + break; 154 + } 155 + 156 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 157 + uart_write_wakeup(port); 158 + 159 + if (!port->x_char && uart_circ_empty(xmit) && 160 + efm32_uart_read32(efm_port, UARTn_STATUS) & 161 + UARTn_STATUS_TXC) 162 + efm32_uart_stop_tx(port); 163 + } 164 + 165 + static void efm32_uart_start_tx(struct uart_port *port) 166 + { 167 + struct efm32_uart_port *efm_port = to_efm_port(port); 168 + u32 ien; 169 + 170 + efm32_uart_write32(efm_port, 171 + UARTn_IF_TXBL | UARTn_IF_TXC, UARTn_IFC); 172 + ien = efm32_uart_read32(efm_port, UARTn_IEN); 173 + efm32_uart_write32(efm_port, 174 + ien | UARTn_IF_TXBL | UARTn_IF_TXC, UARTn_IEN); 175 + efm32_uart_write32(efm_port, UARTn_CMD_TXEN, UARTn_CMD); 176 + 177 + efm32_uart_tx_chars(efm_port); 178 + } 179 + 180 + static void efm32_uart_stop_rx(struct uart_port *port) 181 + { 182 + struct efm32_uart_port *efm_port = to_efm_port(port); 183 + 184 + efm32_uart_write32(efm_port, UARTn_CMD_RXDIS, UARTn_CMD); 185 + } 186 + 187 + static void efm32_uart_enable_ms(struct uart_port *port) 188 + { 189 + /* no handshake lines, no modem status interrupts */ 190 + } 191 + 192 + static void efm32_uart_break_ctl(struct uart_port *port, int ctl) 193 + { 194 + /* not possible without fiddling with gpios */ 195 + } 196 + 197 + static void efm32_uart_rx_chars(struct efm32_uart_port *efm_port, 198 + struct tty_struct *tty) 199 + { 200 + struct uart_port *port = &efm_port->port; 201 + 202 + while (efm32_uart_read32(efm_port, UARTn_STATUS) & 203 + UARTn_STATUS_RXDATAV) { 204 + u32 rxdata = efm32_uart_read32(efm_port, UARTn_RXDATAX); 205 + int flag = 0; 206 + 207 + /* 208 + * This is a reserved bit and I only saw it read as 0. But to be 209 + * sure not to be confused too much by new devices adhere to the 210 + * warning in the reference manual that reserverd bits might 211 + * read as 1 in the future. 212 + */ 213 + rxdata &= ~SW_UARTn_RXDATAX_BERR; 214 + 215 + port->icount.rx++; 216 + 217 + if ((rxdata & UARTn_RXDATAX_FERR) && 218 + !(rxdata & UARTn_RXDATAX_RXDATA__MASK)) { 219 + rxdata |= SW_UARTn_RXDATAX_BERR; 220 + port->icount.brk++; 221 + if (uart_handle_break(port)) 222 + continue; 223 + } else if (rxdata & UARTn_RXDATAX_PERR) 224 + port->icount.parity++; 225 + else if (rxdata & UARTn_RXDATAX_FERR) 226 + port->icount.frame++; 227 + 228 + rxdata &= port->read_status_mask; 229 + 230 + if (rxdata & SW_UARTn_RXDATAX_BERR) 231 + flag = TTY_BREAK; 232 + else if (rxdata & UARTn_RXDATAX_PERR) 233 + flag = TTY_PARITY; 234 + else if (rxdata & UARTn_RXDATAX_FERR) 235 + flag = TTY_FRAME; 236 + else if (uart_handle_sysrq_char(port, 237 + rxdata & UARTn_RXDATAX_RXDATA__MASK)) 238 + continue; 239 + 240 + if (tty && (rxdata & port->ignore_status_mask) == 0) 241 + tty_insert_flip_char(tty, 242 + rxdata & UARTn_RXDATAX_RXDATA__MASK, flag); 243 + } 244 + } 245 + 246 + static irqreturn_t efm32_uart_rxirq(int irq, void *data) 247 + { 248 + struct efm32_uart_port *efm_port = data; 249 + u32 irqflag = efm32_uart_read32(efm_port, UARTn_IF); 250 + int handled = IRQ_NONE; 251 + struct uart_port *port = &efm_port->port; 252 + struct tty_struct *tty; 253 + 254 + spin_lock(&port->lock); 255 + 256 + tty = tty_kref_get(port->state->port.tty); 257 + 258 + if (irqflag & UARTn_IF_RXDATAV) { 259 + efm32_uart_write32(efm_port, UARTn_IF_RXDATAV, UARTn_IFC); 260 + efm32_uart_rx_chars(efm_port, tty); 261 + 262 + handled = IRQ_HANDLED; 263 + } 264 + 265 + if (irqflag & UARTn_IF_RXOF) { 266 + efm32_uart_write32(efm_port, UARTn_IF_RXOF, UARTn_IFC); 267 + port->icount.overrun++; 268 + if (tty) 269 + tty_insert_flip_char(tty, 0, TTY_OVERRUN); 270 + 271 + handled = IRQ_HANDLED; 272 + } 273 + 274 + if (tty) { 275 + tty_flip_buffer_push(tty); 276 + tty_kref_put(tty); 277 + } 278 + 279 + spin_unlock(&port->lock); 280 + 281 + return handled; 282 + } 283 + 284 + static irqreturn_t efm32_uart_txirq(int irq, void *data) 285 + { 286 + struct efm32_uart_port *efm_port = data; 287 + u32 irqflag = efm32_uart_read32(efm_port, UARTn_IF); 288 + 289 + /* TXBL doesn't need to be cleared */ 290 + if (irqflag & UARTn_IF_TXC) 291 + efm32_uart_write32(efm_port, UARTn_IF_TXC, UARTn_IFC); 292 + 293 + if (irqflag & (UARTn_IF_TXC | UARTn_IF_TXBL)) { 294 + efm32_uart_tx_chars(efm_port); 295 + return IRQ_HANDLED; 296 + } else 297 + return IRQ_NONE; 298 + } 299 + 300 + static int efm32_uart_startup(struct uart_port *port) 301 + { 302 + struct efm32_uart_port *efm_port = to_efm_port(port); 303 + u32 location = 0; 304 + struct efm32_uart_pdata *pdata = dev_get_platdata(port->dev); 305 + int ret; 306 + 307 + if (pdata) 308 + location = UARTn_ROUTE_LOCATION(pdata->location); 309 + 310 + ret = clk_enable(efm_port->clk); 311 + if (ret) { 312 + efm_debug(efm_port, "failed to enable clk\n"); 313 + goto err_clk_enable; 314 + } 315 + port->uartclk = clk_get_rate(efm_port->clk); 316 + 317 + /* Enable pins at configured location */ 318 + efm32_uart_write32(efm_port, location | UARTn_ROUTE_RXPEN | UARTn_ROUTE_TXPEN, 319 + UARTn_ROUTE); 320 + 321 + ret = request_irq(port->irq, efm32_uart_rxirq, 0, 322 + DRIVER_NAME, efm_port); 323 + if (ret) { 324 + efm_debug(efm_port, "failed to register rxirq\n"); 325 + goto err_request_irq_rx; 326 + } 327 + 328 + /* disable all irqs */ 329 + efm32_uart_write32(efm_port, 0, UARTn_IEN); 330 + 331 + ret = request_irq(efm_port->txirq, efm32_uart_txirq, 0, 332 + DRIVER_NAME, efm_port); 333 + if (ret) { 334 + efm_debug(efm_port, "failed to register txirq\n"); 335 + free_irq(port->irq, efm_port); 336 + err_request_irq_rx: 337 + 338 + clk_disable(efm_port->clk); 339 + } else { 340 + efm32_uart_write32(efm_port, 341 + UARTn_IF_RXDATAV | UARTn_IF_RXOF, UARTn_IEN); 342 + efm32_uart_write32(efm_port, UARTn_CMD_RXEN, UARTn_CMD); 343 + } 344 + 345 + err_clk_enable: 346 + return ret; 347 + } 348 + 349 + static void efm32_uart_shutdown(struct uart_port *port) 350 + { 351 + struct efm32_uart_port *efm_port = to_efm_port(port); 352 + 353 + efm32_uart_write32(efm_port, 0, UARTn_IEN); 354 + free_irq(port->irq, efm_port); 355 + 356 + clk_disable(efm_port->clk); 357 + } 358 + 359 + static void efm32_uart_set_termios(struct uart_port *port, 360 + struct ktermios *new, struct ktermios *old) 361 + { 362 + struct efm32_uart_port *efm_port = to_efm_port(port); 363 + unsigned long flags; 364 + unsigned baud; 365 + u32 clkdiv; 366 + u32 frame = 0; 367 + 368 + /* no modem control lines */ 369 + new->c_cflag &= ~(CRTSCTS | CMSPAR); 370 + 371 + baud = uart_get_baud_rate(port, new, old, 372 + DIV_ROUND_CLOSEST(port->uartclk, 16 * 8192), 373 + DIV_ROUND_CLOSEST(port->uartclk, 16)); 374 + 375 + switch (new->c_cflag & CSIZE) { 376 + case CS5: 377 + frame |= UARTn_FRAME_DATABITS(5); 378 + break; 379 + case CS6: 380 + frame |= UARTn_FRAME_DATABITS(6); 381 + break; 382 + case CS7: 383 + frame |= UARTn_FRAME_DATABITS(7); 384 + break; 385 + case CS8: 386 + frame |= UARTn_FRAME_DATABITS(8); 387 + break; 388 + } 389 + 390 + if (new->c_cflag & CSTOPB) 391 + /* the receiver only verifies the first stop bit */ 392 + frame |= UARTn_FRAME_STOPBITS_TWO; 393 + else 394 + frame |= UARTn_FRAME_STOPBITS_ONE; 395 + 396 + if (new->c_cflag & PARENB) { 397 + if (new->c_cflag & PARODD) 398 + frame |= UARTn_FRAME_PARITY_ODD; 399 + else 400 + frame |= UARTn_FRAME_PARITY_EVEN; 401 + } else 402 + frame |= UARTn_FRAME_PARITY_NONE; 403 + 404 + /* 405 + * the 6 lowest bits of CLKDIV are dc, bit 6 has value 0.25. 406 + * port->uartclk <= 14e6, so 4 * port->uartclk doesn't overflow. 407 + */ 408 + clkdiv = (DIV_ROUND_CLOSEST(4 * port->uartclk, 16 * baud) - 4) << 6; 409 + 410 + spin_lock_irqsave(&port->lock, flags); 411 + 412 + efm32_uart_write32(efm_port, 413 + UARTn_CMD_TXDIS | UARTn_CMD_RXDIS, UARTn_CMD); 414 + 415 + port->read_status_mask = UARTn_RXDATAX_RXDATA__MASK; 416 + if (new->c_iflag & INPCK) 417 + port->read_status_mask |= 418 + UARTn_RXDATAX_FERR | UARTn_RXDATAX_PERR; 419 + if (new->c_iflag & (BRKINT | PARMRK)) 420 + port->read_status_mask |= SW_UARTn_RXDATAX_BERR; 421 + 422 + port->ignore_status_mask = 0; 423 + if (new->c_iflag & IGNPAR) 424 + port->ignore_status_mask |= 425 + UARTn_RXDATAX_FERR | UARTn_RXDATAX_PERR; 426 + if (new->c_iflag & IGNBRK) 427 + port->ignore_status_mask |= SW_UARTn_RXDATAX_BERR; 428 + 429 + uart_update_timeout(port, new->c_cflag, baud); 430 + 431 + efm32_uart_write32(efm_port, UARTn_CTRL_TXBIL, UARTn_CTRL); 432 + efm32_uart_write32(efm_port, frame, UARTn_FRAME); 433 + efm32_uart_write32(efm_port, clkdiv, UARTn_CLKDIV); 434 + 435 + efm32_uart_write32(efm_port, UARTn_CMD_TXEN | UARTn_CMD_RXEN, 436 + UARTn_CMD); 437 + 438 + spin_unlock_irqrestore(&port->lock, flags); 439 + } 440 + 441 + static const char *efm32_uart_type(struct uart_port *port) 442 + { 443 + return port->type == PORT_EFMUART ? "efm32-uart" : NULL; 444 + } 445 + 446 + static void efm32_uart_release_port(struct uart_port *port) 447 + { 448 + struct efm32_uart_port *efm_port = to_efm_port(port); 449 + 450 + clk_unprepare(efm_port->clk); 451 + clk_put(efm_port->clk); 452 + iounmap(port->membase); 453 + } 454 + 455 + static int efm32_uart_request_port(struct uart_port *port) 456 + { 457 + struct efm32_uart_port *efm_port = to_efm_port(port); 458 + int ret; 459 + 460 + port->membase = ioremap(port->mapbase, 60); 461 + if (!efm_port->port.membase) { 462 + ret = -ENOMEM; 463 + efm_debug(efm_port, "failed to remap\n"); 464 + goto err_ioremap; 465 + } 466 + 467 + efm_port->clk = clk_get(port->dev, NULL); 468 + if (IS_ERR(efm_port->clk)) { 469 + ret = PTR_ERR(efm_port->clk); 470 + efm_debug(efm_port, "failed to get clock\n"); 471 + goto err_clk_get; 472 + } 473 + 474 + ret = clk_prepare(efm_port->clk); 475 + if (ret) { 476 + clk_put(efm_port->clk); 477 + err_clk_get: 478 + 479 + iounmap(port->membase); 480 + err_ioremap: 481 + return ret; 482 + } 483 + return 0; 484 + } 485 + 486 + static void efm32_uart_config_port(struct uart_port *port, int type) 487 + { 488 + if (type & UART_CONFIG_TYPE && 489 + !efm32_uart_request_port(port)) 490 + port->type = PORT_EFMUART; 491 + } 492 + 493 + static int efm32_uart_verify_port(struct uart_port *port, 494 + struct serial_struct *serinfo) 495 + { 496 + int ret = 0; 497 + 498 + if (serinfo->type != PORT_UNKNOWN && serinfo->type != PORT_EFMUART) 499 + ret = -EINVAL; 500 + 501 + return ret; 502 + } 503 + 504 + static struct uart_ops efm32_uart_pops = { 505 + .tx_empty = efm32_uart_tx_empty, 506 + .set_mctrl = efm32_uart_set_mctrl, 507 + .get_mctrl = efm32_uart_get_mctrl, 508 + .stop_tx = efm32_uart_stop_tx, 509 + .start_tx = efm32_uart_start_tx, 510 + .stop_rx = efm32_uart_stop_rx, 511 + .enable_ms = efm32_uart_enable_ms, 512 + .break_ctl = efm32_uart_break_ctl, 513 + .startup = efm32_uart_startup, 514 + .shutdown = efm32_uart_shutdown, 515 + .set_termios = efm32_uart_set_termios, 516 + .type = efm32_uart_type, 517 + .release_port = efm32_uart_release_port, 518 + .request_port = efm32_uart_request_port, 519 + .config_port = efm32_uart_config_port, 520 + .verify_port = efm32_uart_verify_port, 521 + }; 522 + 523 + static struct efm32_uart_port *efm32_uart_ports[5]; 524 + 525 + #ifdef CONFIG_SERIAL_EFM32_UART_CONSOLE 526 + static void efm32_uart_console_putchar(struct uart_port *port, int ch) 527 + { 528 + struct efm32_uart_port *efm_port = to_efm_port(port); 529 + unsigned int timeout = 0x400; 530 + u32 status; 531 + 532 + while (1) { 533 + status = efm32_uart_read32(efm_port, UARTn_STATUS); 534 + 535 + if (status & UARTn_STATUS_TXBL) 536 + break; 537 + if (!timeout--) 538 + return; 539 + } 540 + efm32_uart_write32(efm_port, ch, UARTn_TXDATA); 541 + } 542 + 543 + static void efm32_uart_console_write(struct console *co, const char *s, 544 + unsigned int count) 545 + { 546 + struct efm32_uart_port *efm_port = efm32_uart_ports[co->index]; 547 + u32 status = efm32_uart_read32(efm_port, UARTn_STATUS); 548 + unsigned int timeout = 0x400; 549 + 550 + if (!(status & UARTn_STATUS_TXENS)) 551 + efm32_uart_write32(efm_port, UARTn_CMD_TXEN, UARTn_CMD); 552 + 553 + uart_console_write(&efm_port->port, s, count, 554 + efm32_uart_console_putchar); 555 + 556 + /* Wait for the transmitter to become empty */ 557 + while (1) { 558 + u32 status = efm32_uart_read32(efm_port, UARTn_STATUS); 559 + if (status & UARTn_STATUS_TXC) 560 + break; 561 + if (!timeout--) 562 + break; 563 + } 564 + 565 + if (!(status & UARTn_STATUS_TXENS)) 566 + efm32_uart_write32(efm_port, UARTn_CMD_TXDIS, UARTn_CMD); 567 + } 568 + 569 + static void efm32_uart_console_get_options(struct efm32_uart_port *efm_port, 570 + int *baud, int *parity, int *bits) 571 + { 572 + u32 ctrl = efm32_uart_read32(efm_port, UARTn_CTRL); 573 + u32 route, clkdiv, frame; 574 + 575 + if (ctrl & UARTn_CTRL_SYNC) 576 + /* not operating in async mode */ 577 + return; 578 + 579 + route = efm32_uart_read32(efm_port, UARTn_ROUTE); 580 + if (!(route & UARTn_ROUTE_TXPEN)) 581 + /* tx pin not routed */ 582 + return; 583 + 584 + clkdiv = efm32_uart_read32(efm_port, UARTn_CLKDIV); 585 + 586 + *baud = DIV_ROUND_CLOSEST(4 * efm_port->port.uartclk, 587 + 16 * (4 + (clkdiv >> 6))); 588 + 589 + frame = efm32_uart_read32(efm_port, UARTn_FRAME); 590 + if (frame & UARTn_FRAME_PARITY_ODD) 591 + *parity = 'o'; 592 + else if (frame & UARTn_FRAME_PARITY_EVEN) 593 + *parity = 'e'; 594 + else 595 + *parity = 'n'; 596 + 597 + *bits = (frame & UARTn_FRAME_DATABITS__MASK) - 598 + UARTn_FRAME_DATABITS(4) + 4; 599 + 600 + efm_debug(efm_port, "get_opts: options=%d%c%d\n", 601 + *baud, *parity, *bits); 602 + } 603 + 604 + static int efm32_uart_console_setup(struct console *co, char *options) 605 + { 606 + struct efm32_uart_port *efm_port; 607 + int baud = 115200; 608 + int bits = 8; 609 + int parity = 'n'; 610 + int flow = 'n'; 611 + int ret; 612 + 613 + if (co->index < 0 || co->index >= ARRAY_SIZE(efm32_uart_ports)) { 614 + unsigned i; 615 + for (i = 0; i < ARRAY_SIZE(efm32_uart_ports); ++i) { 616 + if (efm32_uart_ports[i]) { 617 + pr_warn("efm32-console: fall back to console index %u (from %hhi)\n", 618 + i, co->index); 619 + co->index = i; 620 + break; 621 + } 622 + } 623 + } 624 + 625 + efm_port = efm32_uart_ports[co->index]; 626 + if (!efm_port) { 627 + pr_warn("efm32-console: No port at %d\n", co->index); 628 + return -ENODEV; 629 + } 630 + 631 + ret = clk_prepare(efm_port->clk); 632 + if (ret) { 633 + dev_warn(efm_port->port.dev, 634 + "console: clk_prepare failed: %d\n", ret); 635 + return ret; 636 + } 637 + 638 + efm_port->port.uartclk = clk_get_rate(efm_port->clk); 639 + 640 + if (options) 641 + uart_parse_options(options, &baud, &parity, &bits, &flow); 642 + else 643 + efm32_uart_console_get_options(efm_port, 644 + &baud, &parity, &bits); 645 + 646 + return uart_set_options(&efm_port->port, co, baud, parity, bits, flow); 647 + } 648 + 649 + static struct uart_driver efm32_uart_reg; 650 + 651 + static struct console efm32_uart_console = { 652 + .name = DEV_NAME, 653 + .write = efm32_uart_console_write, 654 + .device = uart_console_device, 655 + .setup = efm32_uart_console_setup, 656 + .flags = CON_PRINTBUFFER, 657 + .index = -1, 658 + .data = &efm32_uart_reg, 659 + }; 660 + 661 + #else 662 + #define efm32_uart_console (*(struct console *)NULL) 663 + #endif /* ifdef CONFIG_SERIAL_EFM32_UART_CONSOLE / else */ 664 + 665 + static struct uart_driver efm32_uart_reg = { 666 + .owner = THIS_MODULE, 667 + .driver_name = DRIVER_NAME, 668 + .dev_name = DEV_NAME, 669 + .nr = ARRAY_SIZE(efm32_uart_ports), 670 + .cons = &efm32_uart_console, 671 + }; 672 + 673 + static int efm32_uart_probe_dt(struct platform_device *pdev, 674 + struct efm32_uart_port *efm_port) 675 + { 676 + struct device_node *np = pdev->dev.of_node; 677 + int ret; 678 + 679 + if (!np) 680 + return 1; 681 + 682 + ret = of_alias_get_id(np, "serial"); 683 + if (ret < 0) { 684 + dev_err(&pdev->dev, "failed to get alias id: %d\n", ret); 685 + return ret; 686 + } else { 687 + efm_port->port.line = ret; 688 + return 0; 689 + } 690 + 691 + } 692 + 693 + static int __devinit efm32_uart_probe(struct platform_device *pdev) 694 + { 695 + struct efm32_uart_port *efm_port; 696 + struct resource *res; 697 + int ret; 698 + 699 + efm_port = kzalloc(sizeof(*efm_port), GFP_KERNEL); 700 + if (!efm_port) { 701 + dev_dbg(&pdev->dev, "failed to allocate private data\n"); 702 + return -ENOMEM; 703 + } 704 + 705 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 706 + if (!res) { 707 + ret = -ENODEV; 708 + dev_dbg(&pdev->dev, "failed to determine base address\n"); 709 + goto err_get_base; 710 + } 711 + 712 + if (resource_size(res) < 60) { 713 + ret = -EINVAL; 714 + dev_dbg(&pdev->dev, "memory resource too small\n"); 715 + goto err_too_small; 716 + } 717 + 718 + ret = platform_get_irq(pdev, 0); 719 + if (ret <= 0) { 720 + dev_dbg(&pdev->dev, "failed to get rx irq\n"); 721 + goto err_get_rxirq; 722 + } 723 + 724 + efm_port->port.irq = ret; 725 + 726 + ret = platform_get_irq(pdev, 1); 727 + if (ret <= 0) 728 + ret = efm_port->port.irq + 1; 729 + 730 + efm_port->txirq = ret; 731 + 732 + efm_port->port.dev = &pdev->dev; 733 + efm_port->port.mapbase = res->start; 734 + efm_port->port.type = PORT_EFMUART; 735 + efm_port->port.iotype = UPIO_MEM32; 736 + efm_port->port.fifosize = 2; 737 + efm_port->port.ops = &efm32_uart_pops; 738 + efm_port->port.flags = UPF_BOOT_AUTOCONF; 739 + 740 + ret = efm32_uart_probe_dt(pdev, efm_port); 741 + if (ret > 0) 742 + /* not created by device tree */ 743 + efm_port->port.line = pdev->id; 744 + 745 + if (efm_port->port.line >= 0 && 746 + efm_port->port.line < ARRAY_SIZE(efm32_uart_ports)) 747 + efm32_uart_ports[efm_port->port.line] = efm_port; 748 + 749 + ret = uart_add_one_port(&efm32_uart_reg, &efm_port->port); 750 + if (ret) { 751 + dev_dbg(&pdev->dev, "failed to add port: %d\n", ret); 752 + 753 + if (pdev->id >= 0 && pdev->id < ARRAY_SIZE(efm32_uart_ports)) 754 + efm32_uart_ports[pdev->id] = NULL; 755 + err_get_rxirq: 756 + err_too_small: 757 + err_get_base: 758 + kfree(efm_port); 759 + } else { 760 + platform_set_drvdata(pdev, efm_port); 761 + dev_dbg(&pdev->dev, "\\o/\n"); 762 + } 763 + 764 + return ret; 765 + } 766 + 767 + static int __devexit efm32_uart_remove(struct platform_device *pdev) 768 + { 769 + struct efm32_uart_port *efm_port = platform_get_drvdata(pdev); 770 + 771 + platform_set_drvdata(pdev, NULL); 772 + 773 + uart_remove_one_port(&efm32_uart_reg, &efm_port->port); 774 + 775 + if (pdev->id >= 0 && pdev->id < ARRAY_SIZE(efm32_uart_ports)) 776 + efm32_uart_ports[pdev->id] = NULL; 777 + 778 + kfree(efm_port); 779 + 780 + return 0; 781 + } 782 + 783 + static struct of_device_id efm32_uart_dt_ids[] = { 784 + { 785 + .compatible = "efm32,uart", 786 + }, { 787 + /* sentinel */ 788 + } 789 + }; 790 + MODULE_DEVICE_TABLE(of, efm32_uart_dt_ids); 791 + 792 + static struct platform_driver efm32_uart_driver = { 793 + .probe = efm32_uart_probe, 794 + .remove = __devexit_p(efm32_uart_remove), 795 + 796 + .driver = { 797 + .name = DRIVER_NAME, 798 + .owner = THIS_MODULE, 799 + .of_match_table = efm32_uart_dt_ids, 800 + }, 801 + }; 802 + 803 + static int __init efm32_uart_init(void) 804 + { 805 + int ret; 806 + 807 + ret = uart_register_driver(&efm32_uart_reg); 808 + if (ret) 809 + return ret; 810 + 811 + ret = platform_driver_register(&efm32_uart_driver); 812 + if (ret) 813 + uart_unregister_driver(&efm32_uart_reg); 814 + 815 + pr_info("EFM32 UART/USART driver\n"); 816 + 817 + return ret; 818 + } 819 + module_init(efm32_uart_init); 820 + 821 + static void __exit efm32_uart_exit(void) 822 + { 823 + platform_driver_unregister(&efm32_uart_driver); 824 + uart_unregister_driver(&efm32_uart_reg); 825 + } 826 + 827 + MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>"); 828 + MODULE_DESCRIPTION("EFM32 UART/USART driver"); 829 + MODULE_LICENSE("GPL v2"); 830 + MODULE_ALIAS("platform:" DRIVER_NAME);
-3
drivers/tty/serial/ifx6x60.c
··· 1375 1375 return -ENOMEM; 1376 1376 } 1377 1377 1378 - tty_drv->magic = TTY_DRIVER_MAGIC; 1379 - tty_drv->owner = THIS_MODULE; 1380 1378 tty_drv->driver_name = DRVNAME; 1381 1379 tty_drv->name = TTYNAME; 1382 1380 tty_drv->minor_start = IFX_SPI_TTY_ID; 1383 - tty_drv->num = 1; 1384 1381 tty_drv->type = TTY_DRIVER_TYPE_SERIAL; 1385 1382 tty_drv->subtype = SERIAL_TYPE_NORMAL; 1386 1383 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+1 -2
drivers/tty/serial/ioc4_serial.c
··· 16 16 #include <linux/tty.h> 17 17 #include <linux/tty_flip.h> 18 18 #include <linux/serial.h> 19 - #include <linux/serialP.h> 20 19 #include <linux/circ_buf.h> 21 20 #include <linux/serial_reg.h> 22 21 #include <linux/module.h> ··· 974 975 BUG_ON(!((type == IOC4_SIO_INTR_TYPE) 975 976 || (type == IOC4_OTHER_INTR_TYPE))); 976 977 977 - i = atomic_inc(&soft-> is_intr_type[type].is_num_intrs) - 1; 978 + i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1; 978 979 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0))); 979 980 980 981 /* Save off the lower level interrupt handler */
+2 -10
drivers/tty/serial/m32r_sio.c
··· 38 38 #include <linux/console.h> 39 39 #include <linux/sysrq.h> 40 40 #include <linux/serial.h> 41 - #include <linux/serialP.h> 42 41 #include <linux/delay.h> 43 42 44 43 #include <asm/m32r.h> ··· 68 69 #endif 69 70 70 71 #define PASS_LIMIT 256 71 - 72 - /* 73 - * We default to IRQ0 for the "no irq" hack. Some 74 - * machine types want others as well - they're free 75 - * to redefine this in their header file. 76 - */ 77 - #define is_real_interrupt(irq) ((irq) != 0) 78 72 79 73 #define BASE_BAUD 115200 80 74 ··· 632 640 * hardware interrupt, we use a timer-based system. The original 633 641 * driver used to do this with IRQ0. 634 642 */ 635 - if (!is_real_interrupt(up->port.irq)) { 643 + if (!up->port.irq) { 636 644 unsigned int timeout = up->port.timeout; 637 645 638 646 timeout = timeout > 6 ? (timeout / 2 - 2) : 1; ··· 679 687 680 688 sio_init(); 681 689 682 - if (!is_real_interrupt(up->port.irq)) 690 + if (!up->port.irq) 683 691 del_timer_sync(&up->timer); 684 692 else 685 693 serial_unlink_irq_chain(up);
+1
drivers/tty/serial/m32r_sio.h
··· 15 15 * (at your option) any later version. 16 16 */ 17 17 18 + #include <linux/pci.h> 18 19 19 20 struct m32r_sio_probe { 20 21 struct module *owner;
+5 -4
drivers/tty/serial/mpc52xx_uart.c
··· 262 262 port->uartclk / 4); 263 263 divisor = (port->uartclk + 2 * baud) / (4 * baud); 264 264 265 - /* select the proper prescaler and set the divisor */ 266 - if (divisor > 0xffff) { 265 + /* select the proper prescaler and set the divisor 266 + * prefer high prescaler for more tolerance on low baudrates */ 267 + if (divisor > 0xffff || baud <= 115200) { 267 268 divisor = (divisor + 4) / 8; 268 269 prescaler = 0xdd00; /* /32 */ 269 270 } else ··· 508 507 509 508 psc_fifoc_irq = irq_of_parse_and_map(np, 0); 510 509 of_node_put(np); 511 - if (psc_fifoc_irq == NO_IRQ) { 510 + if (psc_fifoc_irq == 0) { 512 511 pr_err("%s: Can't get FIFOC irq\n", __func__); 513 512 iounmap(psc_fifoc); 514 513 return -ENODEV; ··· 1355 1354 } 1356 1355 1357 1356 psc_ops->get_irq(port, op->dev.of_node); 1358 - if (port->irq == NO_IRQ) { 1357 + if (port->irq == 0) { 1359 1358 dev_dbg(&op->dev, "Could not get irq\n"); 1360 1359 return -EINVAL; 1361 1360 }
-1
drivers/tty/serial/msm_smd_tty.c
··· 203 203 if (smd_tty_driver == 0) 204 204 return -ENOMEM; 205 205 206 - smd_tty_driver->owner = THIS_MODULE; 207 206 smd_tty_driver->driver_name = "smd_tty_driver"; 208 207 smd_tty_driver->name = "smd"; 209 208 smd_tty_driver->major = 0;
+1 -2
drivers/tty/serial/mux.c
··· 17 17 */ 18 18 19 19 #include <linux/module.h> 20 - #include <linux/tty.h> 21 20 #include <linux/ioport.h> 22 21 #include <linux/init.h> 23 22 #include <linux/serial.h> ··· 498 499 port->membase = ioremap_nocache(port->mapbase, MUX_LINE_OFFSET); 499 500 port->iotype = UPIO_MEM; 500 501 port->type = PORT_MUX; 501 - port->irq = NO_IRQ; 502 + port->irq = 0; 502 503 port->uartclk = 0; 503 504 port->fifosize = MUX_FIFO_SIZE; 504 505 port->ops = &mux_pops;
+3 -3
drivers/tty/serial/omap-serial.c
··· 159 159 serial_out(up, UART_IER, up->ier); 160 160 } 161 161 162 - if (!up->use_dma && pdata->set_forceidle) 162 + if (!up->use_dma && pdata && pdata->set_forceidle) 163 163 pdata->set_forceidle(up->pdev); 164 164 165 165 pm_runtime_mark_last_busy(&up->pdev->dev); ··· 298 298 if (!up->use_dma) { 299 299 pm_runtime_get_sync(&up->pdev->dev); 300 300 serial_omap_enable_ier_thri(up); 301 - if (pdata->set_noidle) 301 + if (pdata && pdata->set_noidle) 302 302 pdata->set_noidle(up->pdev); 303 303 pm_runtime_mark_last_busy(&up->pdev->dev); 304 304 pm_runtime_put_autosuspend(&up->pdev->dev); ··· 1613 1613 struct uart_omap_port *up = dev_get_drvdata(dev); 1614 1614 struct omap_uart_port_info *pdata = dev->platform_data; 1615 1615 1616 - if (up) { 1616 + if (up && pdata) { 1617 1617 if (pdata->get_context_loss_count) { 1618 1618 u32 loss_cnt = pdata->get_context_loss_count(dev); 1619 1619
+129 -45
drivers/tty/serial/pch_uart.c
··· 29 29 #include <linux/nmi.h> 30 30 #include <linux/delay.h> 31 31 32 + #include <linux/debugfs.h> 32 33 #include <linux/dmaengine.h> 33 34 #include <linux/pch_dma.h> 34 35 ··· 145 144 #define PCH_UART_DLL 0x00 146 145 #define PCH_UART_DLM 0x01 147 146 147 + #define PCH_UART_BRCSR 0x0E 148 + 148 149 #define PCH_UART_IID_RLS (PCH_UART_IIR_REI) 149 150 #define PCH_UART_IID_RDR (PCH_UART_IIR_RRI) 150 151 #define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI) ··· 206 203 207 204 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 208 205 209 - #define DEFAULT_BAUD_RATE 1843200 /* 1.8432MHz */ 206 + #define DEFAULT_UARTCLK 1843200 /* 1.8432 MHz */ 207 + #define CMITC_UARTCLK 192000000 /* 192.0000 MHz */ 208 + #define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */ 209 + #define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */ 210 210 211 211 struct pch_uart_buffer { 212 212 unsigned char *buf; ··· 224 218 unsigned int iobase; 225 219 struct pci_dev *pdev; 226 220 int fifo_size; 227 - int base_baud; 221 + int uartclk; 228 222 int start_tx; 229 223 int start_rx; 230 224 int tx_empty; ··· 249 243 int tx_dma_use; 250 244 void *rx_buf_virt; 251 245 dma_addr_t rx_buf_dma; 246 + 247 + struct dentry *debugfs; 252 248 }; 253 249 254 250 /** ··· 295 287 static struct eg20t_port *pch_uart_ports[PCH_UART_NR]; 296 288 #endif 297 289 static unsigned int default_baud = 9600; 290 + static unsigned int user_uartclk = 0; 298 291 static const int trigger_level_256[4] = { 1, 64, 128, 224 }; 299 292 static const int trigger_level_64[4] = { 1, 16, 32, 56 }; 300 293 static const int trigger_level_16[4] = { 1, 4, 8, 14 }; 301 294 static const int trigger_level_1[4] = { 1, 1, 1, 1 }; 302 295 303 - static void pch_uart_hal_request(struct pci_dev *pdev, int fifosize, 304 - int base_baud) 305 - { 306 - struct eg20t_port *priv = pci_get_drvdata(pdev); 296 + #ifdef CONFIG_DEBUG_FS 307 297 308 - priv->trigger_level = 1; 309 - priv->fcr = 0; 298 + #define PCH_REGS_BUFSIZE 1024 299 + static int pch_show_regs_open(struct inode *inode, struct file *file) 300 + { 301 + file->private_data = inode->i_private; 302 + return 0; 310 303 } 311 304 312 - static unsigned int get_msr(struct eg20t_port *priv, void __iomem *base) 305 + static ssize_t port_show_regs(struct file *file, char __user *user_buf, 306 + size_t count, loff_t *ppos) 313 307 { 314 - unsigned int msr = ioread8(base + UART_MSR); 315 - priv->dmsr |= msr & PCH_UART_MSR_DELTA; 308 + struct eg20t_port *priv = file->private_data; 309 + char *buf; 310 + u32 len = 0; 311 + ssize_t ret; 312 + unsigned char lcr; 316 313 317 - return msr; 314 + buf = kzalloc(PCH_REGS_BUFSIZE, GFP_KERNEL); 315 + if (!buf) 316 + return 0; 317 + 318 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 319 + "PCH EG20T port[%d] regs:\n", priv->port.line); 320 + 321 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 322 + "=================================\n"); 323 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 324 + "IER: \t0x%02x\n", ioread8(priv->membase + UART_IER)); 325 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 326 + "IIR: \t0x%02x\n", ioread8(priv->membase + UART_IIR)); 327 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 328 + "LCR: \t0x%02x\n", ioread8(priv->membase + UART_LCR)); 329 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 330 + "MCR: \t0x%02x\n", ioread8(priv->membase + UART_MCR)); 331 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 332 + "LSR: \t0x%02x\n", ioread8(priv->membase + UART_LSR)); 333 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 334 + "MSR: \t0x%02x\n", ioread8(priv->membase + UART_MSR)); 335 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 336 + "BRCSR: \t0x%02x\n", 337 + ioread8(priv->membase + PCH_UART_BRCSR)); 338 + 339 + lcr = ioread8(priv->membase + UART_LCR); 340 + iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR); 341 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 342 + "DLL: \t0x%02x\n", ioread8(priv->membase + UART_DLL)); 343 + len += snprintf(buf + len, PCH_REGS_BUFSIZE - len, 344 + "DLM: \t0x%02x\n", ioread8(priv->membase + UART_DLM)); 345 + iowrite8(lcr, priv->membase + UART_LCR); 346 + 347 + if (len > PCH_REGS_BUFSIZE) 348 + len = PCH_REGS_BUFSIZE; 349 + 350 + ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); 351 + kfree(buf); 352 + return ret; 353 + } 354 + 355 + static const struct file_operations port_regs_ops = { 356 + .owner = THIS_MODULE, 357 + .open = pch_show_regs_open, 358 + .read = port_show_regs, 359 + .llseek = default_llseek, 360 + }; 361 + #endif /* CONFIG_DEBUG_FS */ 362 + 363 + /* Return UART clock, checking for board specific clocks. */ 364 + static int pch_uart_get_uartclk(void) 365 + { 366 + const char *cmp; 367 + 368 + if (user_uartclk) 369 + return user_uartclk; 370 + 371 + cmp = dmi_get_system_info(DMI_BOARD_NAME); 372 + if (cmp && strstr(cmp, "CM-iTC")) 373 + return CMITC_UARTCLK; 374 + 375 + cmp = dmi_get_system_info(DMI_BIOS_VERSION); 376 + if (cmp && strnstr(cmp, "FRI2", 4)) 377 + return FRI2_64_UARTCLK; 378 + 379 + cmp = dmi_get_system_info(DMI_PRODUCT_NAME); 380 + if (cmp && strstr(cmp, "Fish River Island II")) 381 + return FRI2_48_UARTCLK; 382 + 383 + return DEFAULT_UARTCLK; 318 384 } 319 385 320 386 static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv, ··· 414 332 unsigned int dll, dlm, lcr; 415 333 int div; 416 334 417 - div = DIV_ROUND_CLOSEST(priv->base_baud / 16, baud); 335 + div = DIV_ROUND_CLOSEST(priv->uartclk / 16, baud); 418 336 if (div < 0 || USHRT_MAX <= div) { 419 337 dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div); 420 338 return -EINVAL; ··· 524 442 525 443 static u8 pch_uart_hal_get_modem(struct eg20t_port *priv) 526 444 { 527 - priv->dmsr = 0; 528 - return get_msr(priv, priv->membase); 445 + unsigned int msr = ioread8(priv->membase + UART_MSR); 446 + priv->dmsr = msr & PCH_UART_MSR_DELTA; 447 + return (u8)msr; 529 448 } 530 449 531 450 static void pch_uart_hal_write(struct eg20t_port *priv, ··· 607 524 608 525 static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf) 609 526 { 610 - int ret; 527 + int ret = 0; 611 528 struct uart_port *port = &priv->port; 612 529 613 530 if (port->x_char) { ··· 616 533 buf[0] = port->x_char; 617 534 port->x_char = 0; 618 535 ret = 1; 619 - } else { 620 - ret = 0; 621 536 } 622 537 623 538 return ret; ··· 1113 1032 static unsigned int pch_uart_tx_empty(struct uart_port *port) 1114 1033 { 1115 1034 struct eg20t_port *priv; 1116 - int ret; 1035 + 1117 1036 priv = container_of(port, struct eg20t_port, port); 1118 1037 if (priv->tx_empty) 1119 - ret = TIOCSER_TEMT; 1038 + return TIOCSER_TEMT; 1120 1039 else 1121 - ret = 0; 1122 - 1123 - return ret; 1040 + return 0; 1124 1041 } 1125 1042 1126 1043 /* Returns the current state of modem control inputs. */ ··· 1232 1153 priv->tx_empty = 1; 1233 1154 1234 1155 if (port->uartclk) 1235 - priv->base_baud = port->uartclk; 1156 + priv->uartclk = port->uartclk; 1236 1157 else 1237 - port->uartclk = priv->base_baud; 1158 + port->uartclk = priv->uartclk; 1238 1159 1239 1160 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT); 1240 1161 ret = pch_uart_hal_set_line(priv, default_baud, ··· 1352 1273 else 1353 1274 parity = PCH_UART_HAL_PARITY_EVEN; 1354 1275 1355 - } else { 1276 + } else 1356 1277 parity = PCH_UART_HAL_PARITY_NONE; 1357 - } 1358 1278 1359 1279 /* Only UART0 has auto hardware flow function */ 1360 1280 if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256)) ··· 1525 1447 pch_console_write(struct console *co, const char *s, unsigned int count) 1526 1448 { 1527 1449 struct eg20t_port *priv; 1528 - 1529 1450 unsigned long flags; 1530 1451 u8 ier; 1531 1452 int locked = 1; ··· 1566 1489 static int __init pch_console_setup(struct console *co, char *options) 1567 1490 { 1568 1491 struct uart_port *port; 1569 - int baud = 9600; 1492 + int baud = default_baud; 1570 1493 int bits = 8; 1571 1494 int parity = 'n'; 1572 1495 int flow = 'n'; ··· 1583 1506 if (!port || (!port->iobase && !port->membase)) 1584 1507 return -ENODEV; 1585 1508 1586 - /* setup uartclock */ 1587 - port->uartclk = DEFAULT_BAUD_RATE; 1509 + port->uartclk = pch_uart_get_uartclk(); 1588 1510 1589 1511 if (options) 1590 1512 uart_parse_options(options, &baud, &parity, &bits, &flow); ··· 1626 1550 unsigned int iobase; 1627 1551 unsigned int mapbase; 1628 1552 unsigned char *rxbuf; 1629 - int fifosize, base_baud; 1553 + int fifosize; 1630 1554 int port_type; 1631 1555 struct pch_uart_driver_data *board; 1632 - const char *board_name; 1556 + char name[32]; /* for debugfs file name */ 1633 1557 1634 1558 board = &drv_dat[id->driver_data]; 1635 1559 port_type = board->port_type; ··· 1641 1565 rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL); 1642 1566 if (!rxbuf) 1643 1567 goto init_port_free_txbuf; 1644 - 1645 - base_baud = DEFAULT_BAUD_RATE; 1646 - 1647 - /* quirk for CM-iTC board */ 1648 - board_name = dmi_get_system_info(DMI_BOARD_NAME); 1649 - if (board_name && strstr(board_name, "CM-iTC")) 1650 - base_baud = 192000000; /* 192.0MHz */ 1651 1568 1652 1569 switch (port_type) { 1653 1570 case PORT_UNKNOWN: ··· 1666 1597 priv->rxbuf.size = PAGE_SIZE; 1667 1598 1668 1599 priv->fifo_size = fifosize; 1669 - priv->base_baud = base_baud; 1600 + priv->uartclk = pch_uart_get_uartclk(); 1670 1601 priv->port_type = PORT_MAX_8250 + port_type + 1; 1671 1602 priv->port.dev = &pdev->dev; 1672 1603 priv->port.iobase = iobase; ··· 1683 1614 spin_lock_init(&priv->port.lock); 1684 1615 1685 1616 pci_set_drvdata(pdev, priv); 1686 - pch_uart_hal_request(pdev, fifosize, base_baud); 1617 + priv->trigger_level = 1; 1618 + priv->fcr = 0; 1687 1619 1688 1620 #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE 1689 1621 pch_uart_ports[board->line_no] = priv; ··· 1692 1622 ret = uart_add_one_port(&pch_uart_driver, &priv->port); 1693 1623 if (ret < 0) 1694 1624 goto init_port_hal_free; 1625 + 1626 + #ifdef CONFIG_DEBUG_FS 1627 + snprintf(name, sizeof(name), "uart%d_regs", board->line_no); 1628 + priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO, 1629 + NULL, priv, &port_regs_ops); 1630 + #endif 1695 1631 1696 1632 return priv; 1697 1633 ··· 1715 1639 1716 1640 static void pch_uart_exit_port(struct eg20t_port *priv) 1717 1641 { 1642 + 1643 + #ifdef CONFIG_DEBUG_FS 1644 + if (priv->debugfs) 1645 + debugfs_remove(priv->debugfs); 1646 + #endif 1718 1647 uart_remove_one_port(&pch_uart_driver, &priv->port); 1719 1648 pci_set_drvdata(priv->pdev, NULL); 1720 1649 free_page((unsigned long)priv->rxbuf.buf); ··· 1727 1646 1728 1647 static void pch_uart_pci_remove(struct pci_dev *pdev) 1729 1648 { 1730 - struct eg20t_port *priv; 1731 - 1732 - priv = (struct eg20t_port *)pci_get_drvdata(pdev); 1649 + struct eg20t_port *priv = pci_get_drvdata(pdev); 1733 1650 1734 1651 pci_disable_msi(pdev); 1735 1652 ··· 1864 1785 MODULE_LICENSE("GPL v2"); 1865 1786 MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver"); 1866 1787 module_param(default_baud, uint, S_IRUGO); 1788 + MODULE_PARM_DESC(default_baud, 1789 + "Default BAUD for initial driver state and console (default 9600)"); 1790 + module_param(user_uartclk, uint, S_IRUGO); 1791 + MODULE_PARM_DESC(user_uartclk, 1792 + "Override UART default or board specific UART clock");
+1 -1
drivers/tty/serial/pmac_zilog.c
··· 1506 1506 * fixed up interrupt info, but we use the device-tree directly 1507 1507 * here due to early probing so we need the fixup too. 1508 1508 */ 1509 - if (uap->port.irq == NO_IRQ && 1509 + if (uap->port.irq == 0 && 1510 1510 np->parent && np->parent->parent && 1511 1511 of_device_is_compatible(np->parent->parent, "gatwick")) { 1512 1512 /* IRQs on gatwick are offset by 64 */
+4 -4
drivers/tty/serial/pxa.c
··· 579 579 struct uart_pxa_port *up = (struct uart_pxa_port *)port; 580 580 581 581 if (!state) 582 - clk_enable(up->clk); 582 + clk_prepare_enable(up->clk); 583 583 else 584 - clk_disable(up->clk); 584 + clk_disable_unprepare(up->clk); 585 585 } 586 586 587 587 static void serial_pxa_release_port(struct uart_port *port) ··· 668 668 struct uart_pxa_port *up = serial_pxa_ports[co->index]; 669 669 unsigned int ier; 670 670 671 - clk_enable(up->clk); 671 + clk_prepare_enable(up->clk); 672 672 673 673 /* 674 674 * First save the IER then disable the interrupts ··· 685 685 wait_for_xmitr(up); 686 686 serial_out(up, UART_IER, ier); 687 687 688 - clk_disable(up->clk); 688 + clk_disable_unprepare(up->clk); 689 689 } 690 690 691 691 static int __init
+1 -1
drivers/tty/serial/samsung.c
··· 1507 1507 #endif 1508 1508 1509 1509 #if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \ 1510 - defined(CONFIG_CPU_S3C2443) 1510 + defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442) 1511 1511 static struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = { 1512 1512 .info = &(struct s3c24xx_uart_info) { 1513 1513 .name = "Samsung S3C2440 UART",
-1
drivers/tty/serial/serial_core.c
··· 2230 2230 2231 2231 drv->tty_driver = normal; 2232 2232 2233 - normal->owner = drv->owner; 2234 2233 normal->driver_name = drv->driver_name; 2235 2234 normal->name = drv->dev_name; 2236 2235 normal->major = drv->major;
+2 -2
drivers/tty/serial/sn_console.c
··· 461 461 struct tty_struct *tty; 462 462 463 463 if (!port) { 464 - printk(KERN_ERR "sn_receive_chars - port NULL so can't receieve\n"); 464 + printk(KERN_ERR "sn_receive_chars - port NULL so can't receive\n"); 465 465 return; 466 466 } 467 467 468 468 if (!port->sc_ops) { 469 - printk(KERN_ERR "sn_receive_chars - port->sc_ops NULL so can't receieve\n"); 469 + printk(KERN_ERR "sn_receive_chars - port->sc_ops NULL so can't receive\n"); 470 470 return; 471 471 } 472 472
+1 -1
drivers/tty/serial/suncore.c
··· 17 17 #include <linux/errno.h> 18 18 #include <linux/string.h> 19 19 #include <linux/serial_core.h> 20 + #include <linux/sunserialcore.h> 20 21 #include <linux/init.h> 21 22 22 23 #include <asm/prom.h> 23 24 24 - #include "suncore.h" 25 25 26 26 static int sunserial_current_minor = 64; 27 27
+1 -1
drivers/tty/serial/suncore.h include/linux/sunserialcore.h
··· 1 - /* suncore.h 1 + /* sunserialcore.h 2 2 * 3 3 * Generic SUN serial/kbd/ms layer. Based entirely 4 4 * upon drivers/sbus/char/sunserial.h which is:
+1 -2
drivers/tty/serial/sunhv.c
··· 29 29 #endif 30 30 31 31 #include <linux/serial_core.h> 32 - 33 - #include "suncore.h" 32 + #include <linux/sunserialcore.h> 34 33 35 34 #define CON_BREAK ((long)-1) 36 35 #define CON_HUP ((long)-2)
+1 -1
drivers/tty/serial/sunsab.c
··· 43 43 #endif 44 44 45 45 #include <linux/serial_core.h> 46 + #include <linux/sunserialcore.h> 46 47 47 - #include "suncore.h" 48 48 #include "sunsab.h" 49 49 50 50 struct uart_sunsab_port {
+1 -2
drivers/tty/serial/sunsu.c
··· 47 47 #endif 48 48 49 49 #include <linux/serial_core.h> 50 - 51 - #include "suncore.h" 50 + #include <linux/sunserialcore.h> 52 51 53 52 /* We are on a NS PC87303 clocked with 24.0 MHz, which results 54 53 * in a UART clock of 1.8462 MHz.
+6 -6
drivers/tty/serial/sunzilog.c
··· 43 43 #endif 44 44 45 45 #include <linux/serial_core.h> 46 + #include <linux/sunserialcore.h> 46 47 47 - #include "suncore.h" 48 48 #include "sunzilog.h" 49 49 50 50 /* On 32-bit sparcs we need to delay after register accesses ··· 1397 1397 #endif 1398 1398 } 1399 1399 1400 - static int zilog_irq = -1; 1400 + static int zilog_irq; 1401 1401 1402 1402 static int __devinit zs_probe(struct platform_device *op) 1403 1403 { ··· 1425 1425 1426 1426 rp = sunzilog_chip_regs[inst]; 1427 1427 1428 - if (zilog_irq == -1) 1428 + if (!zilog_irq) 1429 1429 zilog_irq = op->archdata.irqs[0]; 1430 1430 1431 1431 up = &sunzilog_port_table[inst * 2]; ··· 1580 1580 if (err) 1581 1581 goto out_unregister_uart; 1582 1582 1583 - if (zilog_irq != -1) { 1583 + if (!zilog_irq) { 1584 1584 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1585 1585 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED, 1586 1586 "zs", sunzilog_irq_chain); ··· 1621 1621 { 1622 1622 platform_driver_unregister(&zs_driver); 1623 1623 1624 - if (zilog_irq != -1) { 1624 + if (!zilog_irq) { 1625 1625 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1626 1626 1627 1627 /* Disable Interrupts */ ··· 1637 1637 } 1638 1638 1639 1639 free_irq(zilog_irq, sunzilog_irq_chain); 1640 - zilog_irq = -1; 1640 + zilog_irq = 0; 1641 1641 } 1642 1642 1643 1643 if (sunzilog_reg.nr) {
+1 -1
drivers/tty/serial/ucc_uart.c
··· 1360 1360 } 1361 1361 1362 1362 qe_port->port.irq = irq_of_parse_and_map(np, 0); 1363 - if (qe_port->port.irq == NO_IRQ) { 1363 + if (qe_port->port.irq == 0) { 1364 1364 dev_err(&ofdev->dev, "could not map IRQ for UCC%u\n", 1365 1365 qe_port->ucc_num + 1); 1366 1366 ret = -EINVAL;
+2 -2
drivers/tty/serial/vr41xx_siu.c
··· 61 61 static struct uart_port siu_uart_ports[SIU_PORTS_MAX] = { 62 62 [0 ... SIU_PORTS_MAX-1] = { 63 63 .lock = __SPIN_LOCK_UNLOCKED(siu_uart_ports->lock), 64 - .irq = -1, 64 + .irq = 0, 65 65 }, 66 66 }; 67 67 ··· 171 171 { 172 172 if (port->line == 0) 173 173 return PORT_VR41XX_SIU; 174 - if (port->line == 1 && port->irq != -1) 174 + if (port->line == 1 && port->irq) 175 175 return PORT_VR41XX_DSIU; 176 176 177 177 return PORT_UNKNOWN;
+2 -2
drivers/tty/serial/vt8500_serial.c
··· 544 544 .cons = VT8500_CONSOLE, 545 545 }; 546 546 547 - static int __init vt8500_serial_probe(struct platform_device *pdev) 547 + static int __devinit vt8500_serial_probe(struct platform_device *pdev) 548 548 { 549 549 struct vt8500_port *vt8500_port; 550 550 struct resource *mmres, *irqres; ··· 605 605 606 606 static struct platform_driver vt8500_platform_driver = { 607 607 .probe = vt8500_serial_probe, 608 - .remove = vt8500_serial_remove, 608 + .remove = __devexit_p(vt8500_serial_remove), 609 609 .driver = { 610 610 .name = "vt8500_serial", 611 611 .owner = THIS_MODULE,
+1 -2
drivers/tty/synclink.c
··· 3381 3381 3382 3382 /* verify range of specified line number */ 3383 3383 line = tty->index; 3384 - if ((line < 0) || (line >= mgsl_device_count)) { 3384 + if (line >= mgsl_device_count) { 3385 3385 printk("%s(%d):mgsl_open with invalid line #%d.\n", 3386 3386 __FILE__,__LINE__,line); 3387 3387 return -ENODEV; ··· 4333 4333 if (!serial_driver) 4334 4334 return -ENOMEM; 4335 4335 4336 - serial_driver->owner = THIS_MODULE; 4337 4336 serial_driver->driver_name = "synclink"; 4338 4337 serial_driver->name = "ttySL"; 4339 4338 serial_driver->major = ttymajor;
+1 -2
drivers/tty/synclinkmp.c
··· 721 721 unsigned long flags; 722 722 723 723 line = tty->index; 724 - if ((line < 0) || (line >= synclinkmp_device_count)) { 724 + if (line >= synclinkmp_device_count) { 725 725 printk("%s(%d): open with invalid line #%d.\n", 726 726 __FILE__,__LINE__,line); 727 727 return -ENODEV; ··· 3977 3977 3978 3978 /* Initialize the tty_driver structure */ 3979 3979 3980 - serial_driver->owner = THIS_MODULE; 3981 3980 serial_driver->driver_name = "synclinkmp"; 3982 3981 serial_driver->name = "ttySLM"; 3983 3982 serial_driver->major = ttymajor;
+10 -7
drivers/tty/sysrq.c
··· 110 110 #ifdef CONFIG_VT 111 111 static void sysrq_handle_unraw(int key) 112 112 { 113 - struct kbd_struct *kbd = &kbd_table[fg_console]; 114 - 115 - if (kbd) 116 - kbd->kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE; 113 + vt_reset_unicode(fg_console); 117 114 } 115 + 118 116 static struct sysrq_key_op sysrq_unraw_op = { 119 117 .handler = sysrq_handle_unraw, 120 118 .help_msg = "unRaw", ··· 320 322 { 321 323 struct task_struct *p; 322 324 325 + read_lock(&tasklist_lock); 323 326 for_each_process(p) { 324 - if (p->mm && !is_global_init(p)) 325 - /* Not swapper, init nor kernel thread */ 326 - force_sig(sig, p); 327 + if (p->flags & PF_KTHREAD) 328 + continue; 329 + if (is_global_init(p)) 330 + continue; 331 + 332 + force_sig(sig, p); 327 333 } 334 + read_unlock(&tasklist_lock); 328 335 } 329 336 330 337 static void sysrq_handle_term(int key)
+21 -33
drivers/tty/tty_io.c
··· 1230 1230 static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, 1231 1231 struct inode *inode, int idx) 1232 1232 { 1233 - struct tty_struct *tty; 1234 - 1235 1233 if (driver->ops->lookup) 1236 1234 return driver->ops->lookup(driver, inode, idx); 1237 1235 1238 - tty = driver->ttys[idx]; 1239 - return tty; 1236 + return driver->ttys[idx]; 1240 1237 } 1241 1238 1242 1239 /** ··· 1268 1271 } 1269 1272 EXPORT_SYMBOL_GPL(tty_init_termios); 1270 1273 1274 + int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty) 1275 + { 1276 + int ret = tty_init_termios(tty); 1277 + if (ret) 1278 + return ret; 1279 + 1280 + tty_driver_kref_get(driver); 1281 + tty->count++; 1282 + driver->ttys[tty->index] = tty; 1283 + return 0; 1284 + } 1285 + EXPORT_SYMBOL_GPL(tty_standard_install); 1286 + 1271 1287 /** 1272 1288 * tty_driver_install_tty() - install a tty entry in the driver 1273 1289 * @driver: the driver for the tty ··· 1296 1286 static int tty_driver_install_tty(struct tty_driver *driver, 1297 1287 struct tty_struct *tty) 1298 1288 { 1299 - int idx = tty->index; 1300 - int ret; 1301 - 1302 - if (driver->ops->install) { 1303 - ret = driver->ops->install(driver, tty); 1304 - return ret; 1305 - } 1306 - 1307 - if (tty_init_termios(tty) == 0) { 1308 - tty_driver_kref_get(driver); 1309 - tty->count++; 1310 - driver->ttys[idx] = tty; 1311 - return 0; 1312 - } 1313 - return -ENOMEM; 1289 + return driver->ops->install ? driver->ops->install(driver, tty) : 1290 + tty_standard_install(driver, tty); 1314 1291 } 1315 1292 1316 1293 /** ··· 1348 1351 tty->link->count++; 1349 1352 } 1350 1353 tty->count++; 1351 - tty->driver = driver; /* N.B. why do this every time?? */ 1352 1354 1353 1355 mutex_lock(&tty->ldisc_mutex); 1354 1356 WARN_ON(!test_bit(TTY_LDISC, &tty->flags)); ··· 1361 1365 * @driver: tty driver we are opening a device on 1362 1366 * @idx: device index 1363 1367 * @ret_tty: returned tty structure 1364 - * @first_ok: ok to open a new device (used by ptmx) 1365 1368 * 1366 1369 * Prepare a tty device. This may not be a "new" clean device but 1367 1370 * could also be an active device. The pty drivers require special ··· 1380 1385 * relaxed for the (most common) case of reopening a tty. 1381 1386 */ 1382 1387 1383 - struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, 1384 - int first_ok) 1388 + struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) 1385 1389 { 1386 1390 struct tty_struct *tty; 1387 1391 int retval; 1388 - 1389 - /* Check if pty master is being opened multiple times */ 1390 - if (driver->subtype == PTY_TYPE_MASTER && 1391 - (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) { 1392 - return ERR_PTR(-EIO); 1393 - } 1394 1392 1395 1393 /* 1396 1394 * First time open is complex, especially for PTY devices. ··· 1938 1950 if (retval) 1939 1951 tty = ERR_PTR(retval); 1940 1952 } else 1941 - tty = tty_init_dev(driver, index, 0); 1953 + tty = tty_init_dev(driver, index); 1942 1954 1943 1955 mutex_unlock(&tty_mutex); 1944 1956 if (driver) ··· 2929 2941 tty->session = NULL; 2930 2942 tty->pgrp = NULL; 2931 2943 tty->overrun_time = jiffies; 2932 - tty->buf.head = tty->buf.tail = NULL; 2933 2944 tty_buffer_init(tty); 2934 2945 mutex_init(&tty->termios_mutex); 2935 2946 mutex_init(&tty->ldisc_mutex); ··· 3045 3058 } 3046 3059 EXPORT_SYMBOL(tty_unregister_device); 3047 3060 3048 - struct tty_driver *alloc_tty_driver(int lines) 3061 + struct tty_driver *__alloc_tty_driver(int lines, struct module *owner) 3049 3062 { 3050 3063 struct tty_driver *driver; 3051 3064 ··· 3054 3067 kref_init(&driver->kref); 3055 3068 driver->magic = TTY_DRIVER_MAGIC; 3056 3069 driver->num = lines; 3070 + driver->owner = owner; 3057 3071 /* later we'll move allocation of tables here */ 3058 3072 } 3059 3073 return driver; 3060 3074 } 3061 - EXPORT_SYMBOL(alloc_tty_driver); 3075 + EXPORT_SYMBOL(__alloc_tty_driver); 3062 3076 3063 3077 static void destruct_tty_driver(struct kref *kref) 3064 3078 {
+43 -8
drivers/tty/vt/consolemap.c
··· 516 516 int err = 0, err1, i; 517 517 struct uni_pagedir *p, *q; 518 518 519 + /* Save original vc_unipagdir_loc in case we allocate a new one */ 519 520 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 520 521 if (p->readonly) return -EIO; 521 522 ··· 529 528 err1 = con_clear_unimap(vc, NULL); 530 529 if (err1) return err1; 531 530 531 + /* 532 + * Since refcount was > 1, con_clear_unimap() allocated a 533 + * a new uni_pagedir for this vc. Re: p != q 534 + */ 532 535 q = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 533 - for (i = 0, l = 0; i < 32; i++) 536 + 537 + /* 538 + * uni_pgdir is a 32*32*64 table with rows allocated 539 + * when its first entry is added. The unicode value must 540 + * still be incremented for empty rows. We are copying 541 + * entries from "p" (old) to "q" (new). 542 + */ 543 + l = 0; /* unicode value */ 544 + for (i = 0; i < 32; i++) 534 545 if ((p1 = p->uni_pgdir[i])) 535 546 for (j = 0; j < 32; j++) 536 - if ((p2 = p1[j])) 547 + if ((p2 = p1[j])) { 537 548 for (k = 0; k < 64; k++, l++) 538 549 if (p2[k] != 0xffff) { 550 + /* 551 + * Found one, copy entry for unicode 552 + * l with fontpos value p2[k]. 553 + */ 539 554 err1 = con_insert_unipair(q, l, p2[k]); 540 555 if (err1) { 541 556 p->refcount++; 542 557 *vc->vc_uni_pagedir_loc = (unsigned long)p; 543 558 con_release_unimap(q); 544 559 kfree(q); 545 - return err1; 560 + return err1; 546 561 } 547 - } 548 - p = q; 549 - } else if (p == dflt) 562 + } 563 + } else { 564 + /* Account for row of 64 empty entries */ 565 + l += 64; 566 + } 567 + else 568 + /* Account for empty table */ 569 + l += 32 * 64; 570 + 571 + /* 572 + * Finished copying font table, set vc_uni_pagedir to new table 573 + */ 574 + p = q; 575 + } else if (p == dflt) { 550 576 dflt = NULL; 551 - 577 + } 578 + 579 + /* 580 + * Insert user specified unicode pairs into new table. 581 + */ 552 582 while (ct--) { 553 583 unsigned short unicode, fontpos; 554 584 __get_user(unicode, &list->unicode); ··· 589 557 list++; 590 558 } 591 559 560 + /* 561 + * Merge with fontmaps of any other virtual consoles. 562 + */ 592 563 if (con_unify_unimap(vc, p)) 593 564 return err; 594 565 595 566 for (i = 0; i <= 3; i++) 596 - set_inverse_transl(vc, p, i); /* Update all inverse translations */ 567 + set_inverse_transl(vc, p, i); /* Update inverse translations */ 597 568 set_inverse_trans_unicode(vc, p); 598 569 599 570 return err;
+768 -35
drivers/tty/vt/keyboard.c
··· 41 41 #include <linux/reboot.h> 42 42 #include <linux/notifier.h> 43 43 #include <linux/jiffies.h> 44 + #include <linux/uaccess.h> 44 45 45 46 #include <asm/irq_regs.h> 46 47 ··· 56 55 /* 57 56 * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on. 58 57 * This seems a good reason to start with NumLock off. On HIL keyboards 59 - * of PARISC machines however there is no NumLock key and everyone expects the keypad 60 - * to be used for numbers. 58 + * of PARISC machines however there is no NumLock key and everyone expects the 59 + * keypad to be used for numbers. 61 60 */ 62 61 63 62 #if defined(CONFIG_PARISC) && (defined(CONFIG_KEYBOARD_HIL) || defined(CONFIG_KEYBOARD_HIL_OLD)) ··· 67 66 #endif 68 67 69 68 #define KBD_DEFLOCK 0 70 - 71 - void compute_shiftstate(void); 72 69 73 70 /* 74 71 * Handler Tables. ··· 98 99 * Variables exported for vt_ioctl.c 99 100 */ 100 101 101 - /* maximum values each key_handler can handle */ 102 - const int max_vals[] = { 103 - 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1, 104 - NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1, 105 - 255, NR_LOCK - 1, 255, NR_BRL - 1 106 - }; 107 - 108 - const int NR_TYPES = ARRAY_SIZE(max_vals); 109 - 110 - struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 111 - EXPORT_SYMBOL_GPL(kbd_table); 112 - static struct kbd_struct *kbd = kbd_table; 113 - 114 102 struct vt_spawn_console vt_spawn_con = { 115 103 .lock = __SPIN_LOCK_UNLOCKED(vt_spawn_con.lock), 116 104 .pid = NULL, 117 105 .sig = 0, 118 106 }; 119 107 120 - /* 121 - * Variables exported for vt.c 122 - */ 123 - 124 - int shift_state = 0; 125 108 126 109 /* 127 110 * Internal Data. 128 111 */ 112 + 113 + static struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 114 + static struct kbd_struct *kbd = kbd_table; 115 + 116 + /* maximum values each key_handler can handle */ 117 + static const int max_vals[] = { 118 + 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1, 119 + NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1, 120 + 255, NR_LOCK - 1, 255, NR_BRL - 1 121 + }; 122 + 123 + static const int NR_TYPES = ARRAY_SIZE(max_vals); 129 124 130 125 static struct input_handler kbd_handler; 131 126 static DEFINE_SPINLOCK(kbd_event_lock); ··· 129 136 static int npadch = -1; /* -1 or number assembled on pad */ 130 137 static unsigned int diacr; 131 138 static char rep; /* flag telling character repeat */ 139 + 140 + static int shift_state = 0; 132 141 133 142 static unsigned char ledstate = 0xff; /* undefined */ 134 143 static unsigned char ledioctl; ··· 182 187 return d->error == 0; /* stop as soon as we successfully get one */ 183 188 } 184 189 185 - int getkeycode(unsigned int scancode) 190 + static int getkeycode(unsigned int scancode) 186 191 { 187 192 struct getset_keycode_data d = { 188 193 .ke = { ··· 209 214 return d->error == 0; /* stop as soon as we successfully set one */ 210 215 } 211 216 212 - int setkeycode(unsigned int scancode, unsigned int keycode) 217 + static int setkeycode(unsigned int scancode, unsigned int keycode) 213 218 { 214 219 struct getset_keycode_data d = { 215 220 .ke = { ··· 377 382 /* 378 383 * Called after returning from RAW mode or when changing consoles - recompute 379 384 * shift_down[] and shift_state from key_down[] maybe called when keymap is 380 - * undefined, so that shiftkey release is seen 385 + * undefined, so that shiftkey release is seen. The caller must hold the 386 + * kbd_event_lock. 381 387 */ 382 - void compute_shiftstate(void) 388 + 389 + static void do_compute_shiftstate(void) 383 390 { 384 391 unsigned int i, j, k, sym, val; 385 392 ··· 412 415 shift_state |= (1 << val); 413 416 } 414 417 } 418 + } 419 + 420 + /* We still have to export this method to vt.c */ 421 + void compute_shiftstate(void) 422 + { 423 + unsigned long flags; 424 + spin_lock_irqsave(&kbd_event_lock, flags); 425 + do_compute_shiftstate(); 426 + spin_unlock_irqrestore(&kbd_event_lock, flags); 415 427 } 416 428 417 429 /* ··· 642 636 643 637 static void fn_null(struct vc_data *vc) 644 638 { 645 - compute_shiftstate(); 639 + do_compute_shiftstate(); 646 640 } 647 641 648 642 /* ··· 995 989 996 990 void setledstate(struct kbd_struct *kbd, unsigned int led) 997 991 { 992 + unsigned long flags; 993 + spin_lock_irqsave(&kbd_event_lock, flags); 998 994 if (!(led & ~7)) { 999 995 ledioctl = led; 1000 996 kbd->ledmode = LED_SHOW_IOCTL; ··· 1004 996 kbd->ledmode = LED_SHOW_FLAGS; 1005 997 1006 998 set_leds(); 999 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1007 1000 } 1008 1001 1009 1002 static inline unsigned char getleds(void) ··· 1042 1033 } 1043 1034 1044 1035 return 0; 1036 + } 1037 + 1038 + /** 1039 + * vt_get_leds - helper for braille console 1040 + * @console: console to read 1041 + * @flag: flag we want to check 1042 + * 1043 + * Check the status of a keyboard led flag and report it back 1044 + */ 1045 + int vt_get_leds(int console, int flag) 1046 + { 1047 + unsigned long flags; 1048 + struct kbd_struct * kbd = kbd_table + console; 1049 + int ret; 1050 + 1051 + spin_lock_irqsave(&kbd_event_lock, flags); 1052 + ret = vc_kbd_led(kbd, flag); 1053 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1054 + 1055 + return ret; 1056 + } 1057 + EXPORT_SYMBOL_GPL(vt_get_leds); 1058 + 1059 + /** 1060 + * vt_set_led_state - set LED state of a console 1061 + * @console: console to set 1062 + * @leds: LED bits 1063 + * 1064 + * Set the LEDs on a console. This is a wrapper for the VT layer 1065 + * so that we can keep kbd knowledge internal 1066 + */ 1067 + void vt_set_led_state(int console, int leds) 1068 + { 1069 + struct kbd_struct * kbd = kbd_table + console; 1070 + setledstate(kbd, leds); 1071 + } 1072 + 1073 + /** 1074 + * vt_kbd_con_start - Keyboard side of console start 1075 + * @console: console 1076 + * 1077 + * Handle console start. This is a wrapper for the VT layer 1078 + * so that we can keep kbd knowledge internal 1079 + */ 1080 + void vt_kbd_con_start(int console) 1081 + { 1082 + struct kbd_struct * kbd = kbd_table + console; 1083 + unsigned long flags; 1084 + spin_lock_irqsave(&kbd_event_lock, flags); 1085 + clr_vc_kbd_led(kbd, VC_SCROLLOCK); 1086 + set_leds(); 1087 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1088 + } 1089 + 1090 + /** 1091 + * vt_kbd_con_stop - Keyboard side of console stop 1092 + * @console: console 1093 + * 1094 + * Handle console stop. This is a wrapper for the VT layer 1095 + * so that we can keep kbd knowledge internal 1096 + */ 1097 + void vt_kbd_con_stop(int console) 1098 + { 1099 + struct kbd_struct * kbd = kbd_table + console; 1100 + unsigned long flags; 1101 + spin_lock_irqsave(&kbd_event_lock, flags); 1102 + set_vc_kbd_led(kbd, VC_SCROLLOCK); 1103 + set_leds(); 1104 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1045 1105 } 1046 1106 1047 1107 /* ··· 1332 1254 if (rc == NOTIFY_STOP || !key_map) { 1333 1255 atomic_notifier_call_chain(&keyboard_notifier_list, 1334 1256 KBD_UNBOUND_KEYCODE, &param); 1335 - compute_shiftstate(); 1257 + do_compute_shiftstate(); 1336 1258 kbd->slockstate = 0; 1337 1259 return; 1338 1260 } ··· 1482 1404 1483 1405 static const struct input_device_id kbd_ids[] = { 1484 1406 { 1485 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1486 - .evbit = { BIT_MASK(EV_KEY) }, 1487 - }, 1407 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1408 + .evbit = { BIT_MASK(EV_KEY) }, 1409 + }, 1488 1410 1489 1411 { 1490 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1491 - .evbit = { BIT_MASK(EV_SND) }, 1492 - }, 1412 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1413 + .evbit = { BIT_MASK(EV_SND) }, 1414 + }, 1493 1415 1494 1416 { }, /* Terminating entry */ 1495 1417 }; ··· 1511 1433 int i; 1512 1434 int error; 1513 1435 1514 - for (i = 0; i < MAX_NR_CONSOLES; i++) { 1436 + for (i = 0; i < MAX_NR_CONSOLES; i++) { 1515 1437 kbd_table[i].ledflagstate = KBD_DEFLEDS; 1516 1438 kbd_table[i].default_ledflagstate = KBD_DEFLEDS; 1517 1439 kbd_table[i].ledmode = LED_SHOW_FLAGS; ··· 1529 1451 tasklet_schedule(&keyboard_tasklet); 1530 1452 1531 1453 return 0; 1454 + } 1455 + 1456 + /* Ioctl support code */ 1457 + 1458 + /** 1459 + * vt_do_diacrit - diacritical table updates 1460 + * @cmd: ioctl request 1461 + * @up: pointer to user data for ioctl 1462 + * @perm: permissions check computed by caller 1463 + * 1464 + * Update the diacritical tables atomically and safely. Lock them 1465 + * against simultaneous keypresses 1466 + */ 1467 + int vt_do_diacrit(unsigned int cmd, void __user *up, int perm) 1468 + { 1469 + struct kbdiacrs __user *a = up; 1470 + unsigned long flags; 1471 + int asize; 1472 + int ret = 0; 1473 + 1474 + switch (cmd) { 1475 + case KDGKBDIACR: 1476 + { 1477 + struct kbdiacr *diacr; 1478 + int i; 1479 + 1480 + diacr = kmalloc(MAX_DIACR * sizeof(struct kbdiacr), 1481 + GFP_KERNEL); 1482 + if (diacr == NULL) 1483 + return -ENOMEM; 1484 + 1485 + /* Lock the diacriticals table, make a copy and then 1486 + copy it after we unlock */ 1487 + spin_lock_irqsave(&kbd_event_lock, flags); 1488 + 1489 + asize = accent_table_size; 1490 + for (i = 0; i < asize; i++) { 1491 + diacr[i].diacr = conv_uni_to_8bit( 1492 + accent_table[i].diacr); 1493 + diacr[i].base = conv_uni_to_8bit( 1494 + accent_table[i].base); 1495 + diacr[i].result = conv_uni_to_8bit( 1496 + accent_table[i].result); 1497 + } 1498 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1499 + 1500 + if (put_user(asize, &a->kb_cnt)) 1501 + ret = -EFAULT; 1502 + else if (copy_to_user(a->kbdiacr, diacr, 1503 + asize * sizeof(struct kbdiacr))) 1504 + ret = -EFAULT; 1505 + kfree(diacr); 1506 + return ret; 1507 + } 1508 + case KDGKBDIACRUC: 1509 + { 1510 + struct kbdiacrsuc __user *a = up; 1511 + void *buf; 1512 + 1513 + buf = kmalloc(MAX_DIACR * sizeof(struct kbdiacruc), 1514 + GFP_KERNEL); 1515 + if (buf == NULL) 1516 + return -ENOMEM; 1517 + 1518 + /* Lock the diacriticals table, make a copy and then 1519 + copy it after we unlock */ 1520 + spin_lock_irqsave(&kbd_event_lock, flags); 1521 + 1522 + asize = accent_table_size; 1523 + memcpy(buf, accent_table, asize * sizeof(struct kbdiacruc)); 1524 + 1525 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1526 + 1527 + if (put_user(asize, &a->kb_cnt)) 1528 + ret = -EFAULT; 1529 + else if (copy_to_user(a->kbdiacruc, buf, 1530 + asize*sizeof(struct kbdiacruc))) 1531 + ret = -EFAULT; 1532 + kfree(buf); 1533 + return ret; 1534 + } 1535 + 1536 + case KDSKBDIACR: 1537 + { 1538 + struct kbdiacrs __user *a = up; 1539 + struct kbdiacr *diacr = NULL; 1540 + unsigned int ct; 1541 + int i; 1542 + 1543 + if (!perm) 1544 + return -EPERM; 1545 + if (get_user(ct, &a->kb_cnt)) 1546 + return -EFAULT; 1547 + if (ct >= MAX_DIACR) 1548 + return -EINVAL; 1549 + 1550 + if (ct) { 1551 + diacr = kmalloc(sizeof(struct kbdiacr) * ct, 1552 + GFP_KERNEL); 1553 + if (diacr == NULL) 1554 + return -ENOMEM; 1555 + 1556 + if (copy_from_user(diacr, a->kbdiacr, 1557 + sizeof(struct kbdiacr) * ct)) { 1558 + kfree(diacr); 1559 + return -EFAULT; 1560 + } 1561 + } 1562 + 1563 + spin_lock_irqsave(&kbd_event_lock, flags); 1564 + accent_table_size = ct; 1565 + for (i = 0; i < ct; i++) { 1566 + accent_table[i].diacr = 1567 + conv_8bit_to_uni(diacr[i].diacr); 1568 + accent_table[i].base = 1569 + conv_8bit_to_uni(diacr[i].base); 1570 + accent_table[i].result = 1571 + conv_8bit_to_uni(diacr[i].result); 1572 + } 1573 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1574 + kfree(diacr); 1575 + return 0; 1576 + } 1577 + 1578 + case KDSKBDIACRUC: 1579 + { 1580 + struct kbdiacrsuc __user *a = up; 1581 + unsigned int ct; 1582 + void *buf = NULL; 1583 + 1584 + if (!perm) 1585 + return -EPERM; 1586 + 1587 + if (get_user(ct, &a->kb_cnt)) 1588 + return -EFAULT; 1589 + 1590 + if (ct >= MAX_DIACR) 1591 + return -EINVAL; 1592 + 1593 + if (ct) { 1594 + buf = kmalloc(ct * sizeof(struct kbdiacruc), 1595 + GFP_KERNEL); 1596 + if (buf == NULL) 1597 + return -ENOMEM; 1598 + 1599 + if (copy_from_user(buf, a->kbdiacruc, 1600 + ct * sizeof(struct kbdiacruc))) { 1601 + kfree(buf); 1602 + return -EFAULT; 1603 + } 1604 + } 1605 + spin_lock_irqsave(&kbd_event_lock, flags); 1606 + if (ct) 1607 + memcpy(accent_table, buf, 1608 + ct * sizeof(struct kbdiacruc)); 1609 + accent_table_size = ct; 1610 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1611 + kfree(buf); 1612 + return 0; 1613 + } 1614 + } 1615 + return ret; 1616 + } 1617 + 1618 + /** 1619 + * vt_do_kdskbmode - set keyboard mode ioctl 1620 + * @console: the console to use 1621 + * @arg: the requested mode 1622 + * 1623 + * Update the keyboard mode bits while holding the correct locks. 1624 + * Return 0 for success or an error code. 1625 + */ 1626 + int vt_do_kdskbmode(int console, unsigned int arg) 1627 + { 1628 + struct kbd_struct * kbd = kbd_table + console; 1629 + int ret = 0; 1630 + unsigned long flags; 1631 + 1632 + spin_lock_irqsave(&kbd_event_lock, flags); 1633 + switch(arg) { 1634 + case K_RAW: 1635 + kbd->kbdmode = VC_RAW; 1636 + break; 1637 + case K_MEDIUMRAW: 1638 + kbd->kbdmode = VC_MEDIUMRAW; 1639 + break; 1640 + case K_XLATE: 1641 + kbd->kbdmode = VC_XLATE; 1642 + do_compute_shiftstate(); 1643 + break; 1644 + case K_UNICODE: 1645 + kbd->kbdmode = VC_UNICODE; 1646 + do_compute_shiftstate(); 1647 + break; 1648 + case K_OFF: 1649 + kbd->kbdmode = VC_OFF; 1650 + break; 1651 + default: 1652 + ret = -EINVAL; 1653 + } 1654 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1655 + return ret; 1656 + } 1657 + 1658 + /** 1659 + * vt_do_kdskbmeta - set keyboard meta state 1660 + * @console: the console to use 1661 + * @arg: the requested meta state 1662 + * 1663 + * Update the keyboard meta bits while holding the correct locks. 1664 + * Return 0 for success or an error code. 1665 + */ 1666 + int vt_do_kdskbmeta(int console, unsigned int arg) 1667 + { 1668 + struct kbd_struct * kbd = kbd_table + console; 1669 + int ret = 0; 1670 + unsigned long flags; 1671 + 1672 + spin_lock_irqsave(&kbd_event_lock, flags); 1673 + switch(arg) { 1674 + case K_METABIT: 1675 + clr_vc_kbd_mode(kbd, VC_META); 1676 + break; 1677 + case K_ESCPREFIX: 1678 + set_vc_kbd_mode(kbd, VC_META); 1679 + break; 1680 + default: 1681 + ret = -EINVAL; 1682 + } 1683 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1684 + return ret; 1685 + } 1686 + 1687 + int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, 1688 + int perm) 1689 + { 1690 + struct kbkeycode tmp; 1691 + int kc = 0; 1692 + 1693 + if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode))) 1694 + return -EFAULT; 1695 + switch (cmd) { 1696 + case KDGETKEYCODE: 1697 + kc = getkeycode(tmp.scancode); 1698 + if (kc >= 0) 1699 + kc = put_user(kc, &user_kbkc->keycode); 1700 + break; 1701 + case KDSETKEYCODE: 1702 + if (!perm) 1703 + return -EPERM; 1704 + kc = setkeycode(tmp.scancode, tmp.keycode); 1705 + break; 1706 + } 1707 + return kc; 1708 + } 1709 + 1710 + #define i (tmp.kb_index) 1711 + #define s (tmp.kb_table) 1712 + #define v (tmp.kb_value) 1713 + 1714 + int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, 1715 + int console) 1716 + { 1717 + struct kbd_struct * kbd = kbd_table + console; 1718 + struct kbentry tmp; 1719 + ushort *key_map, *new_map, val, ov; 1720 + unsigned long flags; 1721 + 1722 + if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry))) 1723 + return -EFAULT; 1724 + 1725 + if (!capable(CAP_SYS_TTY_CONFIG)) 1726 + perm = 0; 1727 + 1728 + switch (cmd) { 1729 + case KDGKBENT: 1730 + /* Ensure another thread doesn't free it under us */ 1731 + spin_lock_irqsave(&kbd_event_lock, flags); 1732 + key_map = key_maps[s]; 1733 + if (key_map) { 1734 + val = U(key_map[i]); 1735 + if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES) 1736 + val = K_HOLE; 1737 + } else 1738 + val = (i ? K_HOLE : K_NOSUCHMAP); 1739 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1740 + return put_user(val, &user_kbe->kb_value); 1741 + case KDSKBENT: 1742 + if (!perm) 1743 + return -EPERM; 1744 + if (!i && v == K_NOSUCHMAP) { 1745 + spin_lock_irqsave(&kbd_event_lock, flags); 1746 + /* deallocate map */ 1747 + key_map = key_maps[s]; 1748 + if (s && key_map) { 1749 + key_maps[s] = NULL; 1750 + if (key_map[0] == U(K_ALLOCATED)) { 1751 + kfree(key_map); 1752 + keymap_count--; 1753 + } 1754 + } 1755 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1756 + break; 1757 + } 1758 + 1759 + if (KTYP(v) < NR_TYPES) { 1760 + if (KVAL(v) > max_vals[KTYP(v)]) 1761 + return -EINVAL; 1762 + } else 1763 + if (kbd->kbdmode != VC_UNICODE) 1764 + return -EINVAL; 1765 + 1766 + /* ++Geert: non-PC keyboards may generate keycode zero */ 1767 + #if !defined(__mc68000__) && !defined(__powerpc__) 1768 + /* assignment to entry 0 only tests validity of args */ 1769 + if (!i) 1770 + break; 1771 + #endif 1772 + 1773 + new_map = kmalloc(sizeof(plain_map), GFP_KERNEL); 1774 + if (!new_map) 1775 + return -ENOMEM; 1776 + spin_lock_irqsave(&kbd_event_lock, flags); 1777 + key_map = key_maps[s]; 1778 + if (key_map == NULL) { 1779 + int j; 1780 + 1781 + if (keymap_count >= MAX_NR_OF_USER_KEYMAPS && 1782 + !capable(CAP_SYS_RESOURCE)) { 1783 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1784 + kfree(new_map); 1785 + return -EPERM; 1786 + } 1787 + key_maps[s] = new_map; 1788 + key_map = new_map; 1789 + key_map[0] = U(K_ALLOCATED); 1790 + for (j = 1; j < NR_KEYS; j++) 1791 + key_map[j] = U(K_HOLE); 1792 + keymap_count++; 1793 + } else 1794 + kfree(new_map); 1795 + 1796 + ov = U(key_map[i]); 1797 + if (v == ov) 1798 + goto out; 1799 + /* 1800 + * Attention Key. 1801 + */ 1802 + if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN)) { 1803 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1804 + return -EPERM; 1805 + } 1806 + key_map[i] = U(v); 1807 + if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT)) 1808 + do_compute_shiftstate(); 1809 + out: 1810 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1811 + break; 1812 + } 1813 + return 0; 1814 + } 1815 + #undef i 1816 + #undef s 1817 + #undef v 1818 + 1819 + /* FIXME: This one needs untangling and locking */ 1820 + int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) 1821 + { 1822 + struct kbsentry *kbs; 1823 + char *p; 1824 + u_char *q; 1825 + u_char __user *up; 1826 + int sz; 1827 + int delta; 1828 + char *first_free, *fj, *fnw; 1829 + int i, j, k; 1830 + int ret; 1831 + 1832 + if (!capable(CAP_SYS_TTY_CONFIG)) 1833 + perm = 0; 1834 + 1835 + kbs = kmalloc(sizeof(*kbs), GFP_KERNEL); 1836 + if (!kbs) { 1837 + ret = -ENOMEM; 1838 + goto reterr; 1839 + } 1840 + 1841 + /* we mostly copy too much here (512bytes), but who cares ;) */ 1842 + if (copy_from_user(kbs, user_kdgkb, sizeof(struct kbsentry))) { 1843 + ret = -EFAULT; 1844 + goto reterr; 1845 + } 1846 + kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0'; 1847 + i = kbs->kb_func; 1848 + 1849 + switch (cmd) { 1850 + case KDGKBSENT: 1851 + sz = sizeof(kbs->kb_string) - 1; /* sz should have been 1852 + a struct member */ 1853 + up = user_kdgkb->kb_string; 1854 + p = func_table[i]; 1855 + if(p) 1856 + for ( ; *p && sz; p++, sz--) 1857 + if (put_user(*p, up++)) { 1858 + ret = -EFAULT; 1859 + goto reterr; 1860 + } 1861 + if (put_user('\0', up)) { 1862 + ret = -EFAULT; 1863 + goto reterr; 1864 + } 1865 + kfree(kbs); 1866 + return ((p && *p) ? -EOVERFLOW : 0); 1867 + case KDSKBSENT: 1868 + if (!perm) { 1869 + ret = -EPERM; 1870 + goto reterr; 1871 + } 1872 + 1873 + q = func_table[i]; 1874 + first_free = funcbufptr + (funcbufsize - funcbufleft); 1875 + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++) 1876 + ; 1877 + if (j < MAX_NR_FUNC) 1878 + fj = func_table[j]; 1879 + else 1880 + fj = first_free; 1881 + 1882 + delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string); 1883 + if (delta <= funcbufleft) { /* it fits in current buf */ 1884 + if (j < MAX_NR_FUNC) { 1885 + memmove(fj + delta, fj, first_free - fj); 1886 + for (k = j; k < MAX_NR_FUNC; k++) 1887 + if (func_table[k]) 1888 + func_table[k] += delta; 1889 + } 1890 + if (!q) 1891 + func_table[i] = fj; 1892 + funcbufleft -= delta; 1893 + } else { /* allocate a larger buffer */ 1894 + sz = 256; 1895 + while (sz < funcbufsize - funcbufleft + delta) 1896 + sz <<= 1; 1897 + fnw = kmalloc(sz, GFP_KERNEL); 1898 + if(!fnw) { 1899 + ret = -ENOMEM; 1900 + goto reterr; 1901 + } 1902 + 1903 + if (!q) 1904 + func_table[i] = fj; 1905 + if (fj > funcbufptr) 1906 + memmove(fnw, funcbufptr, fj - funcbufptr); 1907 + for (k = 0; k < j; k++) 1908 + if (func_table[k]) 1909 + func_table[k] = fnw + (func_table[k] - funcbufptr); 1910 + 1911 + if (first_free > fj) { 1912 + memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj); 1913 + for (k = j; k < MAX_NR_FUNC; k++) 1914 + if (func_table[k]) 1915 + func_table[k] = fnw + (func_table[k] - funcbufptr) + delta; 1916 + } 1917 + if (funcbufptr != func_buf) 1918 + kfree(funcbufptr); 1919 + funcbufptr = fnw; 1920 + funcbufleft = funcbufleft - delta + sz - funcbufsize; 1921 + funcbufsize = sz; 1922 + } 1923 + strcpy(func_table[i], kbs->kb_string); 1924 + break; 1925 + } 1926 + ret = 0; 1927 + reterr: 1928 + kfree(kbs); 1929 + return ret; 1930 + } 1931 + 1932 + int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm) 1933 + { 1934 + struct kbd_struct * kbd = kbd_table + console; 1935 + unsigned long flags; 1936 + unsigned char ucval; 1937 + 1938 + switch(cmd) { 1939 + /* the ioctls below read/set the flags usually shown in the leds */ 1940 + /* don't use them - they will go away without warning */ 1941 + case KDGKBLED: 1942 + spin_lock_irqsave(&kbd_event_lock, flags); 1943 + ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4); 1944 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1945 + return put_user(ucval, (char __user *)arg); 1946 + 1947 + case KDSKBLED: 1948 + if (!perm) 1949 + return -EPERM; 1950 + if (arg & ~0x77) 1951 + return -EINVAL; 1952 + spin_lock_irqsave(&kbd_event_lock, flags); 1953 + kbd->ledflagstate = (arg & 7); 1954 + kbd->default_ledflagstate = ((arg >> 4) & 7); 1955 + set_leds(); 1956 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1957 + break; 1958 + 1959 + /* the ioctls below only set the lights, not the functions */ 1960 + /* for those, see KDGKBLED and KDSKBLED above */ 1961 + case KDGETLED: 1962 + ucval = getledstate(); 1963 + return put_user(ucval, (char __user *)arg); 1964 + 1965 + case KDSETLED: 1966 + if (!perm) 1967 + return -EPERM; 1968 + setledstate(kbd, arg); 1969 + return 0; 1970 + } 1971 + return -ENOIOCTLCMD; 1972 + } 1973 + 1974 + int vt_do_kdgkbmode(int console) 1975 + { 1976 + struct kbd_struct * kbd = kbd_table + console; 1977 + /* This is a spot read so needs no locking */ 1978 + switch (kbd->kbdmode) { 1979 + case VC_RAW: 1980 + return K_RAW; 1981 + case VC_MEDIUMRAW: 1982 + return K_MEDIUMRAW; 1983 + case VC_UNICODE: 1984 + return K_UNICODE; 1985 + case VC_OFF: 1986 + return K_OFF; 1987 + default: 1988 + return K_XLATE; 1989 + } 1990 + } 1991 + 1992 + /** 1993 + * vt_do_kdgkbmeta - report meta status 1994 + * @console: console to report 1995 + * 1996 + * Report the meta flag status of this console 1997 + */ 1998 + int vt_do_kdgkbmeta(int console) 1999 + { 2000 + struct kbd_struct * kbd = kbd_table + console; 2001 + /* Again a spot read so no locking */ 2002 + return vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT; 2003 + } 2004 + 2005 + /** 2006 + * vt_reset_unicode - reset the unicode status 2007 + * @console: console being reset 2008 + * 2009 + * Restore the unicode console state to its default 2010 + */ 2011 + void vt_reset_unicode(int console) 2012 + { 2013 + unsigned long flags; 2014 + 2015 + spin_lock_irqsave(&kbd_event_lock, flags); 2016 + kbd_table[console].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE; 2017 + spin_unlock_irqrestore(&kbd_event_lock, flags); 2018 + } 2019 + 2020 + /** 2021 + * vt_get_shiftstate - shift bit state 2022 + * 2023 + * Report the shift bits from the keyboard state. We have to export 2024 + * this to support some oddities in the vt layer. 2025 + */ 2026 + int vt_get_shift_state(void) 2027 + { 2028 + /* Don't lock as this is a transient report */ 2029 + return shift_state; 2030 + } 2031 + 2032 + /** 2033 + * vt_reset_keyboard - reset keyboard state 2034 + * @console: console to reset 2035 + * 2036 + * Reset the keyboard bits for a console as part of a general console 2037 + * reset event 2038 + */ 2039 + void vt_reset_keyboard(int console) 2040 + { 2041 + struct kbd_struct * kbd = kbd_table + console; 2042 + unsigned long flags; 2043 + 2044 + spin_lock_irqsave(&kbd_event_lock, flags); 2045 + set_vc_kbd_mode(kbd, VC_REPEAT); 2046 + clr_vc_kbd_mode(kbd, VC_CKMODE); 2047 + clr_vc_kbd_mode(kbd, VC_APPLIC); 2048 + clr_vc_kbd_mode(kbd, VC_CRLF); 2049 + kbd->lockstate = 0; 2050 + kbd->slockstate = 0; 2051 + kbd->ledmode = LED_SHOW_FLAGS; 2052 + kbd->ledflagstate = kbd->default_ledflagstate; 2053 + /* do not do set_leds here because this causes an endless tasklet loop 2054 + when the keyboard hasn't been initialized yet */ 2055 + spin_unlock_irqrestore(&kbd_event_lock, flags); 2056 + } 2057 + 2058 + /** 2059 + * vt_get_kbd_mode_bit - read keyboard status bits 2060 + * @console: console to read from 2061 + * @bit: mode bit to read 2062 + * 2063 + * Report back a vt mode bit. We do this without locking so the 2064 + * caller must be sure that there are no synchronization needs 2065 + */ 2066 + 2067 + int vt_get_kbd_mode_bit(int console, int bit) 2068 + { 2069 + struct kbd_struct * kbd = kbd_table + console; 2070 + return vc_kbd_mode(kbd, bit); 2071 + } 2072 + 2073 + /** 2074 + * vt_set_kbd_mode_bit - read keyboard status bits 2075 + * @console: console to read from 2076 + * @bit: mode bit to read 2077 + * 2078 + * Set a vt mode bit. We do this without locking so the 2079 + * caller must be sure that there are no synchronization needs 2080 + */ 2081 + 2082 + void vt_set_kbd_mode_bit(int console, int bit) 2083 + { 2084 + struct kbd_struct * kbd = kbd_table + console; 2085 + unsigned long flags; 2086 + 2087 + spin_lock_irqsave(&kbd_event_lock, flags); 2088 + set_vc_kbd_mode(kbd, bit); 2089 + spin_unlock_irqrestore(&kbd_event_lock, flags); 2090 + } 2091 + 2092 + /** 2093 + * vt_clr_kbd_mode_bit - read keyboard status bits 2094 + * @console: console to read from 2095 + * @bit: mode bit to read 2096 + * 2097 + * Report back a vt mode bit. We do this without locking so the 2098 + * caller must be sure that there are no synchronization needs 2099 + */ 2100 + 2101 + void vt_clr_kbd_mode_bit(int console, int bit) 2102 + { 2103 + struct kbd_struct * kbd = kbd_table + console; 2104 + unsigned long flags; 2105 + 2106 + spin_lock_irqsave(&kbd_event_lock, flags); 2107 + clr_vc_kbd_mode(kbd, bit); 2108 + spin_unlock_irqrestore(&kbd_event_lock, flags); 1532 2109 }
+43 -15
drivers/tty/vt/selection.c
··· 30 30 31 31 extern void poke_blanked_console(void); 32 32 33 + /* FIXME: all this needs locking */ 33 34 /* Variables for selection control. */ 34 35 /* Use a dynamic buffer, instead of static (Dec 1994) */ 35 36 struct vc_data *sel_cons; /* must not be deallocated */ ··· 62 61 use_unicode); 63 62 } 64 63 65 - /* remove the current selection highlight, if any, 66 - from the console holding the selection. */ 67 - void 68 - clear_selection(void) { 64 + /** 65 + * clear_selection - remove current selection 66 + * 67 + * Remove the current selection highlight, if any from the console 68 + * holding the selection. The caller must hold the console lock. 69 + */ 70 + void clear_selection(void) 71 + { 69 72 highlight_pointer(-1); /* hide the pointer */ 70 73 if (sel_start != -1) { 71 74 highlight(sel_start, sel_end); ··· 79 74 80 75 /* 81 76 * User settable table: what characters are to be considered alphabetic? 82 - * 256 bits 77 + * 256 bits. Locked by the console lock. 83 78 */ 84 79 static u32 inwordLut[8]={ 85 80 0x00000000, /* control chars */ ··· 96 91 return c > 0xff || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1); 97 92 } 98 93 99 - /* set inwordLut contents. Invoked by ioctl(). */ 94 + /** 95 + * set loadlut - load the LUT table 96 + * @p: user table 97 + * 98 + * Load the LUT table from user space. The caller must hold the console 99 + * lock. Make a temporary copy so a partial update doesn't make a mess. 100 + */ 100 101 int sel_loadlut(char __user *p) 101 102 { 102 - return copy_from_user(inwordLut, (u32 __user *)(p+4), 32) ? -EFAULT : 0; 103 + u32 tmplut[8]; 104 + if (copy_from_user(tmplut, (u32 __user *)(p+4), 32)) 105 + return -EFAULT; 106 + memcpy(inwordLut, tmplut, 32); 107 + return 0; 103 108 } 104 109 105 110 /* does screen address p correspond to character at LH/RH edge of screen? */ ··· 145 130 } 146 131 } 147 132 148 - /* set the current selection. Invoked by ioctl() or by kernel code. */ 133 + /** 134 + * set_selection - set the current selection. 135 + * @sel: user selection info 136 + * @tty: the console tty 137 + * 138 + * Invoked by the ioctl handle for the vt layer. 139 + * 140 + * The entire selection process is managed under the console_lock. It's 141 + * a lot under the lock but its hardly a performance path 142 + */ 149 143 int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty) 150 144 { 151 145 struct vc_data *vc = vc_cons[fg_console].d; ··· 162 138 char *bp, *obp; 163 139 int i, ps, pe, multiplier; 164 140 u16 c; 165 - struct kbd_struct *kbd = kbd_table + fg_console; 141 + int mode; 166 142 167 143 poke_blanked_console(); 168 144 ··· 206 182 clear_selection(); 207 183 sel_cons = vc_cons[fg_console].d; 208 184 } 209 - use_unicode = kbd && kbd->kbdmode == VC_UNICODE; 185 + mode = vt_do_kdgkbmode(fg_console); 186 + if (mode == K_UNICODE) 187 + use_unicode = 1; 188 + else 189 + use_unicode = 0; 210 190 211 191 switch (sel_mode) 212 192 { ··· 330 302 * queue of the tty associated with the current console. 331 303 * Invoked by ioctl(). 332 304 * 333 - * Locking: always called with BTM from vt_ioctl 305 + * Locking: called without locks. Calls the ldisc wrongly with 306 + * unsafe methods, 334 307 */ 335 308 int paste_selection(struct tty_struct *tty) 336 309 { ··· 346 317 poke_blanked_console(); 347 318 console_unlock(); 348 319 320 + /* FIXME: wtf is this supposed to achieve ? */ 349 321 ld = tty_ldisc_ref(tty); 350 - if (!ld) { 351 - tty_unlock(); 322 + if (!ld) 352 323 ld = tty_ldisc_ref_wait(tty); 353 - tty_lock(); 354 - } 355 324 325 + /* FIXME: this is completely unsafe */ 356 326 add_wait_queue(&vc->paste_wait, &wait); 357 327 while (sel_buffer && sel_buffer_lth > pasted) { 358 328 set_current_state(TASK_INTERRUPTIBLE);
+2 -2
drivers/tty/vt/vc_screen.c
··· 608 608 unsigned int currcons = iminor(inode) & 127; 609 609 int ret = 0; 610 610 611 - tty_lock(); 611 + console_lock(); 612 612 if(currcons && !vc_cons_allocated(currcons-1)) 613 613 ret = -ENXIO; 614 - tty_unlock(); 614 + console_unlock(); 615 615 return ret; 616 616 } 617 617
+36 -30
drivers/tty/vt/vt.c
··· 1028 1028 * VT102 emulator 1029 1029 */ 1030 1030 1031 - #define set_kbd(vc, x) set_vc_kbd_mode(kbd_table + (vc)->vc_num, (x)) 1032 - #define clr_kbd(vc, x) clr_vc_kbd_mode(kbd_table + (vc)->vc_num, (x)) 1033 - #define is_kbd(vc, x) vc_kbd_mode(kbd_table + (vc)->vc_num, (x)) 1031 + #define set_kbd(vc, x) vt_set_kbd_mode_bit((vc)->vc_num, (x)) 1032 + #define clr_kbd(vc, x) vt_clr_kbd_mode_bit((vc)->vc_num, (x)) 1033 + #define is_kbd(vc, x) vt_get_kbd_mode_bit((vc)->vc_num, (x)) 1034 1034 1035 1035 #define decarm VC_REPEAT 1036 1036 #define decckm VC_CKMODE ··· 1652 1652 vc->vc_deccm = global_cursor_default; 1653 1653 vc->vc_decim = 0; 1654 1654 1655 - set_kbd(vc, decarm); 1656 - clr_kbd(vc, decckm); 1657 - clr_kbd(vc, kbdapplic); 1658 - clr_kbd(vc, lnm); 1659 - kbd_table[vc->vc_num].lockstate = 0; 1660 - kbd_table[vc->vc_num].slockstate = 0; 1661 - kbd_table[vc->vc_num].ledmode = LED_SHOW_FLAGS; 1662 - kbd_table[vc->vc_num].ledflagstate = kbd_table[vc->vc_num].default_ledflagstate; 1663 - /* do not do set_leds here because this causes an endless tasklet loop 1664 - when the keyboard hasn't been initialized yet */ 1655 + vt_reset_keyboard(vc->vc_num); 1665 1656 1666 1657 vc->vc_cursor_type = cur_default; 1667 1658 vc->vc_complement_mask = vc->vc_s_complement_mask; ··· 1970 1979 case 'q': /* DECLL - but only 3 leds */ 1971 1980 /* map 0,1,2,3 to 0,1,2,4 */ 1972 1981 if (vc->vc_par[0] < 4) 1973 - setledstate(kbd_table + vc->vc_num, 1982 + vt_set_led_state(vc->vc_num, 1974 1983 (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); 1975 1984 return; 1976 1985 case 'r': ··· 2623 2632 console_unlock(); 2624 2633 break; 2625 2634 case TIOCL_SELLOADLUT: 2635 + console_lock(); 2626 2636 ret = sel_loadlut(p); 2637 + console_unlock(); 2627 2638 break; 2628 2639 case TIOCL_GETSHIFTSTATE: 2629 2640 ··· 2635 2642 * kernel-internal variable; programs not closely 2636 2643 * related to the kernel should not use this. 2637 2644 */ 2638 - data = shift_state; 2645 + data = vt_get_shift_state(); 2639 2646 ret = __put_user(data, p); 2640 2647 break; 2641 2648 case TIOCL_GETMOUSEREPORTING: 2649 + console_lock(); /* May be overkill */ 2642 2650 data = mouse_reporting(); 2651 + console_unlock(); 2643 2652 ret = __put_user(data, p); 2644 2653 break; 2645 2654 case TIOCL_SETVESABLANK: 2655 + console_lock(); 2646 2656 ret = set_vesa_blanking(p); 2657 + console_unlock(); 2647 2658 break; 2648 2659 case TIOCL_GETKMSGREDIRECT: 2649 2660 data = vt_get_kmsg_redirect(); ··· 2664 2667 } 2665 2668 break; 2666 2669 case TIOCL_GETFGCONSOLE: 2670 + /* No locking needed as this is a transiently 2671 + correct return anyway if the caller hasn't 2672 + disabled switching */ 2667 2673 ret = fg_console; 2668 2674 break; 2669 2675 case TIOCL_SCROLLCONSOLE: 2670 2676 if (get_user(lines, (s32 __user *)(p+4))) { 2671 2677 ret = -EFAULT; 2672 2678 } else { 2679 + /* Need the console lock here. Note that lots 2680 + of other calls need fixing before the lock 2681 + is actually useful ! */ 2682 + console_lock(); 2673 2683 scrollfront(vc_cons[fg_console].d, lines); 2684 + console_unlock(); 2674 2685 ret = 0; 2675 2686 } 2676 2687 break; ··· 2758 2753 console_num = tty->index; 2759 2754 if (!vc_cons_allocated(console_num)) 2760 2755 return; 2761 - set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK); 2762 - set_leds(); 2756 + vt_kbd_con_stop(console_num); 2763 2757 } 2764 2758 2765 2759 /* ··· 2772 2768 console_num = tty->index; 2773 2769 if (!vc_cons_allocated(console_num)) 2774 2770 return; 2775 - clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK); 2776 - set_leds(); 2771 + vt_kbd_con_start(console_num); 2777 2772 } 2778 2773 2779 2774 static void con_flush_chars(struct tty_struct *tty) ··· 2994 2991 console_driver = alloc_tty_driver(MAX_NR_CONSOLES); 2995 2992 if (!console_driver) 2996 2993 panic("Couldn't allocate console driver\n"); 2997 - console_driver->owner = THIS_MODULE; 2994 + 2998 2995 console_driver->name = "tty"; 2999 2996 console_driver->name_base = 1; 3000 2997 console_driver->major = TTY_MAJOR; ··· 3983 3980 int rc = -EINVAL; 3984 3981 int c; 3985 3982 3986 - if (vc->vc_mode != KD_TEXT) 3987 - return -EINVAL; 3988 - 3989 3983 if (op->data) { 3990 3984 font.data = kmalloc(max_font_size, GFP_KERNEL); 3991 3985 if (!font.data) ··· 3991 3991 font.data = NULL; 3992 3992 3993 3993 console_lock(); 3994 - if (vc->vc_sw->con_font_get) 3994 + if (vc->vc_mode != KD_TEXT) 3995 + rc = -EINVAL; 3996 + else if (vc->vc_sw->con_font_get) 3995 3997 rc = vc->vc_sw->con_font_get(vc, &font); 3996 3998 else 3997 3999 rc = -ENOSYS; ··· 4075 4073 if (IS_ERR(font.data)) 4076 4074 return PTR_ERR(font.data); 4077 4075 console_lock(); 4078 - if (vc->vc_sw->con_font_set) 4076 + if (vc->vc_mode != KD_TEXT) 4077 + rc = -EINVAL; 4078 + else if (vc->vc_sw->con_font_set) 4079 4079 rc = vc->vc_sw->con_font_set(vc, &font, op->flags); 4080 4080 else 4081 4081 rc = -ENOSYS; ··· 4093 4089 char *s = name; 4094 4090 int rc; 4095 4091 4096 - if (vc->vc_mode != KD_TEXT) 4097 - return -EINVAL; 4098 4092 4099 4093 if (!op->data) 4100 4094 s = NULL; ··· 4102 4100 name[MAX_FONT_NAME - 1] = 0; 4103 4101 4104 4102 console_lock(); 4103 + if (vc->vc_mode != KD_TEXT) { 4104 + console_unlock(); 4105 + return -EINVAL; 4106 + } 4105 4107 if (vc->vc_sw->con_font_default) 4106 4108 rc = vc->vc_sw->con_font_default(vc, &font, s); 4107 4109 else ··· 4123 4117 int con = op->height; 4124 4118 int rc; 4125 4119 4126 - if (vc->vc_mode != KD_TEXT) 4127 - return -EINVAL; 4128 4120 4129 4121 console_lock(); 4130 - if (!vc->vc_sw->con_font_copy) 4122 + if (vc->vc_mode != KD_TEXT) 4123 + rc = -EINVAL; 4124 + else if (!vc->vc_sw->con_font_copy) 4131 4125 rc = -ENOSYS; 4132 4126 else if (con < 0 || !vc_cons_allocated(con)) 4133 4127 rc = -ENOTTY;
+71 -424
drivers/tty/vt/vt_ioctl.c
··· 130 130 list_add(&vw->list, &vt_events); 131 131 spin_unlock_irqrestore(&vt_event_lock, flags); 132 132 /* Wait for it to pass */ 133 - wait_event_interruptible_tty(vt_event_waitqueue, vw->done); 133 + wait_event_interruptible(vt_event_waitqueue, vw->done); 134 134 /* Dequeue it */ 135 135 spin_lock_irqsave(&vt_event_lock, flags); 136 136 list_del(&vw->list); ··· 195 195 #define GPLAST 0x3df 196 196 #define GPNUM (GPLAST - GPFIRST + 1) 197 197 198 - #define i (tmp.kb_index) 199 - #define s (tmp.kb_table) 200 - #define v (tmp.kb_value) 201 - static inline int 202 - do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_struct *kbd) 203 - { 204 - struct kbentry tmp; 205 - ushort *key_map, val, ov; 206 198 207 - if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry))) 208 - return -EFAULT; 209 - 210 - if (!capable(CAP_SYS_TTY_CONFIG)) 211 - perm = 0; 212 - 213 - switch (cmd) { 214 - case KDGKBENT: 215 - key_map = key_maps[s]; 216 - if (key_map) { 217 - val = U(key_map[i]); 218 - if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES) 219 - val = K_HOLE; 220 - } else 221 - val = (i ? K_HOLE : K_NOSUCHMAP); 222 - return put_user(val, &user_kbe->kb_value); 223 - case KDSKBENT: 224 - if (!perm) 225 - return -EPERM; 226 - if (!i && v == K_NOSUCHMAP) { 227 - /* deallocate map */ 228 - key_map = key_maps[s]; 229 - if (s && key_map) { 230 - key_maps[s] = NULL; 231 - if (key_map[0] == U(K_ALLOCATED)) { 232 - kfree(key_map); 233 - keymap_count--; 234 - } 235 - } 236 - break; 237 - } 238 - 239 - if (KTYP(v) < NR_TYPES) { 240 - if (KVAL(v) > max_vals[KTYP(v)]) 241 - return -EINVAL; 242 - } else 243 - if (kbd->kbdmode != VC_UNICODE) 244 - return -EINVAL; 245 - 246 - /* ++Geert: non-PC keyboards may generate keycode zero */ 247 - #if !defined(__mc68000__) && !defined(__powerpc__) 248 - /* assignment to entry 0 only tests validity of args */ 249 - if (!i) 250 - break; 251 - #endif 252 - 253 - if (!(key_map = key_maps[s])) { 254 - int j; 255 - 256 - if (keymap_count >= MAX_NR_OF_USER_KEYMAPS && 257 - !capable(CAP_SYS_RESOURCE)) 258 - return -EPERM; 259 - 260 - key_map = kmalloc(sizeof(plain_map), 261 - GFP_KERNEL); 262 - if (!key_map) 263 - return -ENOMEM; 264 - key_maps[s] = key_map; 265 - key_map[0] = U(K_ALLOCATED); 266 - for (j = 1; j < NR_KEYS; j++) 267 - key_map[j] = U(K_HOLE); 268 - keymap_count++; 269 - } 270 - ov = U(key_map[i]); 271 - if (v == ov) 272 - break; /* nothing to do */ 273 - /* 274 - * Attention Key. 275 - */ 276 - if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN)) 277 - return -EPERM; 278 - key_map[i] = U(v); 279 - if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT)) 280 - compute_shiftstate(); 281 - break; 282 - } 283 - return 0; 284 - } 285 - #undef i 286 - #undef s 287 - #undef v 288 - 289 - static inline int 290 - do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, int perm) 291 - { 292 - struct kbkeycode tmp; 293 - int kc = 0; 294 - 295 - if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode))) 296 - return -EFAULT; 297 - switch (cmd) { 298 - case KDGETKEYCODE: 299 - kc = getkeycode(tmp.scancode); 300 - if (kc >= 0) 301 - kc = put_user(kc, &user_kbkc->keycode); 302 - break; 303 - case KDSETKEYCODE: 304 - if (!perm) 305 - return -EPERM; 306 - kc = setkeycode(tmp.scancode, tmp.keycode); 307 - break; 308 - } 309 - return kc; 310 - } 311 - 312 - static inline int 313 - do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) 314 - { 315 - struct kbsentry *kbs; 316 - char *p; 317 - u_char *q; 318 - u_char __user *up; 319 - int sz; 320 - int delta; 321 - char *first_free, *fj, *fnw; 322 - int i, j, k; 323 - int ret; 324 - 325 - if (!capable(CAP_SYS_TTY_CONFIG)) 326 - perm = 0; 327 - 328 - kbs = kmalloc(sizeof(*kbs), GFP_KERNEL); 329 - if (!kbs) { 330 - ret = -ENOMEM; 331 - goto reterr; 332 - } 333 - 334 - /* we mostly copy too much here (512bytes), but who cares ;) */ 335 - if (copy_from_user(kbs, user_kdgkb, sizeof(struct kbsentry))) { 336 - ret = -EFAULT; 337 - goto reterr; 338 - } 339 - kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0'; 340 - i = kbs->kb_func; 341 - 342 - switch (cmd) { 343 - case KDGKBSENT: 344 - sz = sizeof(kbs->kb_string) - 1; /* sz should have been 345 - a struct member */ 346 - up = user_kdgkb->kb_string; 347 - p = func_table[i]; 348 - if(p) 349 - for ( ; *p && sz; p++, sz--) 350 - if (put_user(*p, up++)) { 351 - ret = -EFAULT; 352 - goto reterr; 353 - } 354 - if (put_user('\0', up)) { 355 - ret = -EFAULT; 356 - goto reterr; 357 - } 358 - kfree(kbs); 359 - return ((p && *p) ? -EOVERFLOW : 0); 360 - case KDSKBSENT: 361 - if (!perm) { 362 - ret = -EPERM; 363 - goto reterr; 364 - } 365 - 366 - q = func_table[i]; 367 - first_free = funcbufptr + (funcbufsize - funcbufleft); 368 - for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++) 369 - ; 370 - if (j < MAX_NR_FUNC) 371 - fj = func_table[j]; 372 - else 373 - fj = first_free; 374 - 375 - delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string); 376 - if (delta <= funcbufleft) { /* it fits in current buf */ 377 - if (j < MAX_NR_FUNC) { 378 - memmove(fj + delta, fj, first_free - fj); 379 - for (k = j; k < MAX_NR_FUNC; k++) 380 - if (func_table[k]) 381 - func_table[k] += delta; 382 - } 383 - if (!q) 384 - func_table[i] = fj; 385 - funcbufleft -= delta; 386 - } else { /* allocate a larger buffer */ 387 - sz = 256; 388 - while (sz < funcbufsize - funcbufleft + delta) 389 - sz <<= 1; 390 - fnw = kmalloc(sz, GFP_KERNEL); 391 - if(!fnw) { 392 - ret = -ENOMEM; 393 - goto reterr; 394 - } 395 - 396 - if (!q) 397 - func_table[i] = fj; 398 - if (fj > funcbufptr) 399 - memmove(fnw, funcbufptr, fj - funcbufptr); 400 - for (k = 0; k < j; k++) 401 - if (func_table[k]) 402 - func_table[k] = fnw + (func_table[k] - funcbufptr); 403 - 404 - if (first_free > fj) { 405 - memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj); 406 - for (k = j; k < MAX_NR_FUNC; k++) 407 - if (func_table[k]) 408 - func_table[k] = fnw + (func_table[k] - funcbufptr) + delta; 409 - } 410 - if (funcbufptr != func_buf) 411 - kfree(funcbufptr); 412 - funcbufptr = fnw; 413 - funcbufleft = funcbufleft - delta + sz - funcbufsize; 414 - funcbufsize = sz; 415 - } 416 - strcpy(func_table[i], kbs->kb_string); 417 - break; 418 - } 419 - ret = 0; 420 - reterr: 421 - kfree(kbs); 422 - return ret; 423 - } 424 199 425 200 static inline int 426 201 do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op) ··· 272 497 { 273 498 struct vc_data *vc = tty->driver_data; 274 499 struct console_font_op op; /* used in multiple places here */ 275 - struct kbd_struct * kbd; 276 500 unsigned int console; 277 501 unsigned char ucval; 278 502 unsigned int uival; ··· 281 507 282 508 console = vc->vc_num; 283 509 284 - tty_lock(); 285 510 286 511 if (!vc_cons_allocated(console)) { /* impossible? */ 287 512 ret = -ENOIOCTLCMD; ··· 296 523 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG)) 297 524 perm = 1; 298 525 299 - kbd = kbd_table + console; 300 526 switch (cmd) { 301 527 case TIOCLINUX: 302 528 ret = tioclinux(tty, arg); 303 529 break; 304 530 case KIOCSOUND: 305 531 if (!perm) 306 - goto eperm; 532 + return -EPERM; 307 533 /* 308 534 * The use of PIT_TICK_RATE is historic, it used to be 309 535 * the platform-dependent CLOCK_TICK_RATE between 2.6.12 310 536 * and 2.6.36, which was a minor but unfortunate ABI 311 - * change. 537 + * change. kd_mksound is locked by the input layer. 312 538 */ 313 539 if (arg) 314 540 arg = PIT_TICK_RATE / arg; ··· 316 544 317 545 case KDMKTONE: 318 546 if (!perm) 319 - goto eperm; 547 + return -EPERM; 320 548 { 321 549 unsigned int ticks, count; 322 550 ··· 334 562 335 563 case KDGKBTYPE: 336 564 /* 337 - * this is naive. 565 + * this is naïve. 338 566 */ 339 567 ucval = KB_101; 340 - goto setchar; 568 + ret = put_user(ucval, (char __user *)arg); 569 + break; 341 570 342 571 /* 343 572 * These cannot be implemented on any machine that implements ··· 352 579 /* 353 580 * KDADDIO and KDDELIO may be able to add ports beyond what 354 581 * we reject here, but to be safe... 582 + * 583 + * These are locked internally via sys_ioperm 355 584 */ 356 585 if (arg < GPFIRST || arg > GPLAST) { 357 586 ret = -EINVAL; ··· 376 601 struct kbd_repeat kbrep; 377 602 378 603 if (!capable(CAP_SYS_TTY_CONFIG)) 379 - goto eperm; 604 + return -EPERM; 380 605 381 606 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) { 382 607 ret = -EFAULT; ··· 400 625 * need to restore their engine state. --BenH 401 626 */ 402 627 if (!perm) 403 - goto eperm; 628 + return -EPERM; 404 629 switch (arg) { 405 630 case KD_GRAPHICS: 406 631 break; ··· 413 638 ret = -EINVAL; 414 639 goto out; 415 640 } 641 + /* FIXME: this needs the console lock extending */ 416 642 if (vc->vc_mode == (unsigned char) arg) 417 643 break; 418 644 vc->vc_mode = (unsigned char) arg; ··· 445 669 446 670 case KDSKBMODE: 447 671 if (!perm) 448 - goto eperm; 449 - switch(arg) { 450 - case K_RAW: 451 - kbd->kbdmode = VC_RAW; 452 - break; 453 - case K_MEDIUMRAW: 454 - kbd->kbdmode = VC_MEDIUMRAW; 455 - break; 456 - case K_XLATE: 457 - kbd->kbdmode = VC_XLATE; 458 - compute_shiftstate(); 459 - break; 460 - case K_UNICODE: 461 - kbd->kbdmode = VC_UNICODE; 462 - compute_shiftstate(); 463 - break; 464 - case K_OFF: 465 - kbd->kbdmode = VC_OFF; 466 - break; 467 - default: 468 - ret = -EINVAL; 469 - goto out; 470 - } 471 - tty_ldisc_flush(tty); 672 + return -EPERM; 673 + ret = vt_do_kdskbmode(console, arg); 674 + if (ret == 0) 675 + tty_ldisc_flush(tty); 472 676 break; 473 677 474 678 case KDGKBMODE: 475 - switch (kbd->kbdmode) { 476 - case VC_RAW: 477 - uival = K_RAW; 478 - break; 479 - case VC_MEDIUMRAW: 480 - uival = K_MEDIUMRAW; 481 - break; 482 - case VC_UNICODE: 483 - uival = K_UNICODE; 484 - break; 485 - case VC_OFF: 486 - uival = K_OFF; 487 - break; 488 - default: 489 - uival = K_XLATE; 490 - break; 491 - } 492 - goto setint; 679 + uival = vt_do_kdgkbmode(console); 680 + ret = put_user(uival, (int __user *)arg); 681 + break; 493 682 494 683 /* this could be folded into KDSKBMODE, but for compatibility 495 684 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */ 496 685 case KDSKBMETA: 497 - switch(arg) { 498 - case K_METABIT: 499 - clr_vc_kbd_mode(kbd, VC_META); 500 - break; 501 - case K_ESCPREFIX: 502 - set_vc_kbd_mode(kbd, VC_META); 503 - break; 504 - default: 505 - ret = -EINVAL; 506 - } 686 + ret = vt_do_kdskbmeta(console, arg); 507 687 break; 508 688 509 689 case KDGKBMETA: 510 - uival = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT); 690 + /* FIXME: should review whether this is worth locking */ 691 + uival = vt_do_kdgkbmeta(console); 511 692 setint: 512 693 ret = put_user(uival, (int __user *)arg); 513 694 break; ··· 473 740 case KDSETKEYCODE: 474 741 if(!capable(CAP_SYS_TTY_CONFIG)) 475 742 perm = 0; 476 - ret = do_kbkeycode_ioctl(cmd, up, perm); 743 + ret = vt_do_kbkeycode_ioctl(cmd, up, perm); 477 744 break; 478 745 479 746 case KDGKBENT: 480 747 case KDSKBENT: 481 - ret = do_kdsk_ioctl(cmd, up, perm, kbd); 748 + ret = vt_do_kdsk_ioctl(cmd, up, perm, console); 482 749 break; 483 750 484 751 case KDGKBSENT: 485 752 case KDSKBSENT: 486 - ret = do_kdgkb_ioctl(cmd, up, perm); 753 + ret = vt_do_kdgkb_ioctl(cmd, up, perm); 487 754 break; 488 755 756 + /* Diacritical processing. Handled in keyboard.c as it has 757 + to operate on the keyboard locks and structures */ 489 758 case KDGKBDIACR: 490 - { 491 - struct kbdiacrs __user *a = up; 492 - struct kbdiacr diacr; 493 - int i; 494 - 495 - if (put_user(accent_table_size, &a->kb_cnt)) { 496 - ret = -EFAULT; 497 - break; 498 - } 499 - for (i = 0; i < accent_table_size; i++) { 500 - diacr.diacr = conv_uni_to_8bit(accent_table[i].diacr); 501 - diacr.base = conv_uni_to_8bit(accent_table[i].base); 502 - diacr.result = conv_uni_to_8bit(accent_table[i].result); 503 - if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) { 504 - ret = -EFAULT; 505 - break; 506 - } 507 - } 508 - break; 509 - } 510 759 case KDGKBDIACRUC: 511 - { 512 - struct kbdiacrsuc __user *a = up; 513 - 514 - if (put_user(accent_table_size, &a->kb_cnt)) 515 - ret = -EFAULT; 516 - else if (copy_to_user(a->kbdiacruc, accent_table, 517 - accent_table_size*sizeof(struct kbdiacruc))) 518 - ret = -EFAULT; 519 - break; 520 - } 521 - 522 760 case KDSKBDIACR: 523 - { 524 - struct kbdiacrs __user *a = up; 525 - struct kbdiacr diacr; 526 - unsigned int ct; 527 - int i; 528 - 529 - if (!perm) 530 - goto eperm; 531 - if (get_user(ct,&a->kb_cnt)) { 532 - ret = -EFAULT; 533 - break; 534 - } 535 - if (ct >= MAX_DIACR) { 536 - ret = -EINVAL; 537 - break; 538 - } 539 - accent_table_size = ct; 540 - for (i = 0; i < ct; i++) { 541 - if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) { 542 - ret = -EFAULT; 543 - break; 544 - } 545 - accent_table[i].diacr = conv_8bit_to_uni(diacr.diacr); 546 - accent_table[i].base = conv_8bit_to_uni(diacr.base); 547 - accent_table[i].result = conv_8bit_to_uni(diacr.result); 548 - } 549 - break; 550 - } 551 - 552 761 case KDSKBDIACRUC: 553 - { 554 - struct kbdiacrsuc __user *a = up; 555 - unsigned int ct; 556 - 557 - if (!perm) 558 - goto eperm; 559 - if (get_user(ct,&a->kb_cnt)) { 560 - ret = -EFAULT; 561 - break; 562 - } 563 - if (ct >= MAX_DIACR) { 564 - ret = -EINVAL; 565 - break; 566 - } 567 - accent_table_size = ct; 568 - if (copy_from_user(accent_table, a->kbdiacruc, ct*sizeof(struct kbdiacruc))) 569 - ret = -EFAULT; 762 + ret = vt_do_diacrit(cmd, up, perm); 570 763 break; 571 - } 572 764 573 765 /* the ioctls below read/set the flags usually shown in the leds */ 574 766 /* don't use them - they will go away without warning */ 575 767 case KDGKBLED: 576 - ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4); 577 - goto setchar; 578 - 579 768 case KDSKBLED: 580 - if (!perm) 581 - goto eperm; 582 - if (arg & ~0x77) { 583 - ret = -EINVAL; 584 - break; 585 - } 586 - kbd->ledflagstate = (arg & 7); 587 - kbd->default_ledflagstate = ((arg >> 4) & 7); 588 - set_leds(); 589 - break; 590 - 591 - /* the ioctls below only set the lights, not the functions */ 592 - /* for those, see KDGKBLED and KDSKBLED above */ 593 769 case KDGETLED: 594 - ucval = getledstate(); 595 - setchar: 596 - ret = put_user(ucval, (char __user *)arg); 597 - break; 598 - 599 770 case KDSETLED: 600 - if (!perm) 601 - goto eperm; 602 - setledstate(kbd, arg); 771 + ret = vt_do_kdskled(console, cmd, arg, perm); 603 772 break; 604 773 605 774 /* ··· 514 879 case KDSIGACCEPT: 515 880 { 516 881 if (!perm || !capable(CAP_KILL)) 517 - goto eperm; 882 + return -EPERM; 518 883 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL) 519 884 ret = -EINVAL; 520 885 else { ··· 532 897 struct vt_mode tmp; 533 898 534 899 if (!perm) 535 - goto eperm; 900 + return -EPERM; 536 901 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) { 537 902 ret = -EFAULT; 538 903 goto out; ··· 578 943 struct vt_stat __user *vtstat = up; 579 944 unsigned short state, mask; 580 945 946 + /* Review: FIXME: Console lock ? */ 581 947 if (put_user(fg_console + 1, &vtstat->v_active)) 582 948 ret = -EFAULT; 583 949 else { ··· 596 960 * Returns the first available (non-opened) console. 597 961 */ 598 962 case VT_OPENQRY: 963 + /* FIXME: locking ? - but then this is a stupid API */ 599 964 for (i = 0; i < MAX_NR_CONSOLES; ++i) 600 965 if (! VT_IS_IN_USE(i)) 601 966 break; ··· 610 973 */ 611 974 case VT_ACTIVATE: 612 975 if (!perm) 613 - goto eperm; 976 + return -EPERM; 614 977 if (arg == 0 || arg > MAX_NR_CONSOLES) 615 978 ret = -ENXIO; 616 979 else { ··· 629 992 struct vt_setactivate vsa; 630 993 631 994 if (!perm) 632 - goto eperm; 995 + return -EPERM; 633 996 634 997 if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg, 635 998 sizeof(struct vt_setactivate))) { ··· 657 1020 if (ret) 658 1021 break; 659 1022 /* Commence switch and lock */ 1023 + /* Review set_console locks */ 660 1024 set_console(vsa.console); 661 1025 } 662 1026 break; ··· 668 1030 */ 669 1031 case VT_WAITACTIVE: 670 1032 if (!perm) 671 - goto eperm; 1033 + return -EPERM; 672 1034 if (arg == 0 || arg > MAX_NR_CONSOLES) 673 1035 ret = -ENXIO; 674 1036 else ··· 687 1049 */ 688 1050 case VT_RELDISP: 689 1051 if (!perm) 690 - goto eperm; 1052 + return -EPERM; 691 1053 1054 + console_lock(); 692 1055 if (vc->vt_mode.mode != VT_PROCESS) { 1056 + console_unlock(); 693 1057 ret = -EINVAL; 694 1058 break; 695 1059 } 696 1060 /* 697 1061 * Switching-from response 698 1062 */ 699 - console_lock(); 700 1063 if (vc->vt_newvt >= 0) { 701 1064 if (arg == 0) 702 1065 /* ··· 774 1135 775 1136 ushort ll,cc; 776 1137 if (!perm) 777 - goto eperm; 1138 + return -EPERM; 778 1139 if (get_user(ll, &vtsizes->v_rows) || 779 1140 get_user(cc, &vtsizes->v_cols)) 780 1141 ret = -EFAULT; ··· 785 1146 786 1147 if (vc) { 787 1148 vc->vc_resize_user = 1; 1149 + /* FIXME: review v tty lock */ 788 1150 vc_resize(vc_cons[i].d, cc, ll); 789 1151 } 790 1152 } ··· 799 1159 struct vt_consize __user *vtconsize = up; 800 1160 ushort ll,cc,vlin,clin,vcol,ccol; 801 1161 if (!perm) 802 - goto eperm; 1162 + return -EPERM; 803 1163 if (!access_ok(VERIFY_READ, vtconsize, 804 1164 sizeof(struct vt_consize))) { 805 1165 ret = -EFAULT; ··· 855 1215 856 1216 case PIO_FONT: { 857 1217 if (!perm) 858 - goto eperm; 1218 + return -EPERM; 859 1219 op.op = KD_FONT_OP_SET; 860 1220 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */ 861 1221 op.width = 8; ··· 896 1256 case PIO_FONTRESET: 897 1257 { 898 1258 if (!perm) 899 - goto eperm; 1259 + return -EPERM; 900 1260 901 1261 #ifdef BROKEN_GRAPHICS_PROGRAMS 902 1262 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default ··· 922 1282 break; 923 1283 } 924 1284 if (!perm && op.op != KD_FONT_OP_GET) 925 - goto eperm; 1285 + return -EPERM; 926 1286 ret = con_font_op(vc, &op); 927 1287 if (ret) 928 1288 break; ··· 934 1294 case PIO_SCRNMAP: 935 1295 if (!perm) 936 1296 ret = -EPERM; 937 - else 1297 + else { 1298 + tty_lock(); 938 1299 ret = con_set_trans_old(up); 1300 + tty_unlock(); 1301 + } 939 1302 break; 940 1303 941 1304 case GIO_SCRNMAP: 1305 + tty_lock(); 942 1306 ret = con_get_trans_old(up); 1307 + tty_unlock(); 943 1308 break; 944 1309 945 1310 case PIO_UNISCRNMAP: 946 1311 if (!perm) 947 1312 ret = -EPERM; 948 - else 1313 + else { 1314 + tty_lock(); 949 1315 ret = con_set_trans_new(up); 1316 + tty_unlock(); 1317 + } 950 1318 break; 951 1319 952 1320 case GIO_UNISCRNMAP: 1321 + tty_lock(); 953 1322 ret = con_get_trans_new(up); 1323 + tty_unlock(); 954 1324 break; 955 1325 956 1326 case PIO_UNIMAPCLR: 957 1327 { struct unimapinit ui; 958 1328 if (!perm) 959 - goto eperm; 1329 + return -EPERM; 960 1330 ret = copy_from_user(&ui, up, sizeof(struct unimapinit)); 961 1331 if (ret) 962 1332 ret = -EFAULT; 963 - else 1333 + else { 1334 + tty_lock(); 964 1335 con_clear_unimap(vc, &ui); 1336 + tty_unlock(); 1337 + } 965 1338 break; 966 1339 } 967 1340 968 1341 case PIO_UNIMAP: 969 1342 case GIO_UNIMAP: 1343 + tty_lock(); 970 1344 ret = do_unimap_ioctl(cmd, up, perm, vc); 1345 + tty_unlock(); 971 1346 break; 972 1347 973 1348 case VT_LOCKSWITCH: 974 1349 if (!capable(CAP_SYS_TTY_CONFIG)) 975 - goto eperm; 1350 + return -EPERM; 976 1351 vt_dont_switch = 1; 977 1352 break; 978 1353 case VT_UNLOCKSWITCH: 979 1354 if (!capable(CAP_SYS_TTY_CONFIG)) 980 - goto eperm; 1355 + return -EPERM; 981 1356 vt_dont_switch = 0; 982 1357 break; 983 1358 case VT_GETHIFONTMASK: ··· 1006 1351 ret = -ENOIOCTLCMD; 1007 1352 } 1008 1353 out: 1009 - tty_unlock(); 1010 1354 return ret; 1011 - eperm: 1012 - ret = -EPERM; 1013 - goto out; 1014 1355 } 1015 1356 1016 1357 void reset_vc(struct vc_data *vc) 1017 1358 { 1018 1359 vc->vc_mode = KD_TEXT; 1019 - kbd_table[vc->vc_num].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE; 1360 + vt_reset_unicode(vc->vc_num); 1020 1361 vc->vt_mode.mode = VT_AUTO; 1021 1362 vc->vt_mode.waitv = 0; 1022 1363 vc->vt_mode.relsig = 0; ··· 1035 1384 console_lock(); 1036 1385 vc = vc_con->d; 1037 1386 if (vc) { 1387 + /* FIXME: review tty ref counting */ 1038 1388 tty = vc->port.tty; 1039 1389 /* 1040 1390 * SAK should also work in all raw modes and reset ··· 1168 1516 1169 1517 console = vc->vc_num; 1170 1518 1171 - tty_lock(); 1172 - 1173 1519 if (!vc_cons_allocated(console)) { /* impossible? */ 1174 1520 ret = -ENOIOCTLCMD; 1175 1521 goto out; ··· 1196 1546 1197 1547 case PIO_UNIMAP: 1198 1548 case GIO_UNIMAP: 1549 + tty_lock(); 1199 1550 ret = compat_unimap_ioctl(cmd, up, perm, vc); 1551 + tty_unlock(); 1200 1552 break; 1201 1553 1202 1554 /* ··· 1235 1583 goto fallback; 1236 1584 } 1237 1585 out: 1238 - tty_unlock(); 1239 1586 return ret; 1240 1587 1241 1588 fallback: 1242 - tty_unlock(); 1243 1589 return vt_ioctl(tty, cmd, arg); 1244 1590 } 1245 1591 ··· 1423 1773 return -EIO; 1424 1774 } 1425 1775 console_unlock(); 1426 - tty_lock(); 1427 1776 if (vt_waitactive(vt + 1)) { 1428 1777 pr_debug("Suspend: Can't switch VCs."); 1429 - tty_unlock(); 1430 1778 return -EINTR; 1431 1779 } 1432 - tty_unlock(); 1433 1780 return prev; 1434 1781 } 1435 1782
+1 -7
drivers/usb/class/cdc-acm.c
··· 508 508 if (!acm) 509 509 return -ENODEV; 510 510 511 - retval = tty_init_termios(tty); 511 + retval = tty_standard_install(driver, tty); 512 512 if (retval) 513 513 goto error_init_termios; 514 514 515 515 tty->driver_data = acm; 516 - 517 - /* Final install (we use the default method) */ 518 - tty_driver_kref_get(driver); 519 - tty->count++; 520 - driver->ttys[tty->index] = tty; 521 516 522 517 return 0; 523 518 ··· 1670 1675 acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS); 1671 1676 if (!acm_tty_driver) 1672 1677 return -ENOMEM; 1673 - acm_tty_driver->owner = THIS_MODULE, 1674 1678 acm_tty_driver->driver_name = "acm", 1675 1679 acm_tty_driver->name = "ttyACM", 1676 1680 acm_tty_driver->major = ACM_TTY_MAJOR,
-4
drivers/usb/gadget/u_serial.c
··· 725 725 struct gs_port *port; 726 726 int status; 727 727 728 - if (port_num < 0 || port_num >= n_ports) 729 - return -ENXIO; 730 - 731 728 do { 732 729 mutex_lock(&ports[port_num].lock); 733 730 port = ports[port_num].port; ··· 1084 1087 if (!gs_tty_driver) 1085 1088 return -ENOMEM; 1086 1089 1087 - gs_tty_driver->owner = THIS_MODULE; 1088 1090 gs_tty_driver->driver_name = "g_serial"; 1089 1091 gs_tty_driver->name = PREFIX; 1090 1092 /* uses dynamically assigned dev_t values */
+6 -11
drivers/usb/serial/usb-serial.c
··· 214 214 if (!try_module_get(serial->type->driver.owner)) 215 215 goto error_module_get; 216 216 217 - /* perform the standard setup */ 218 - retval = tty_init_termios(tty); 219 - if (retval) 220 - goto error_init_termios; 221 - 222 217 retval = usb_autopm_get_interface(serial->interface); 223 218 if (retval) 224 219 goto error_get_interface; 220 + 221 + retval = tty_standard_install(driver, tty); 222 + if (retval) 223 + goto error_init_termios; 225 224 226 225 mutex_unlock(&serial->disc_mutex); 227 226 ··· 230 231 231 232 tty->driver_data = port; 232 233 233 - /* Final install (we use the default method) */ 234 - tty_driver_kref_get(driver); 235 - tty->count++; 236 - driver->ttys[idx] = tty; 237 234 return retval; 238 235 239 - error_get_interface: 240 236 error_init_termios: 237 + usb_autopm_put_interface(serial->interface); 238 + error_get_interface: 241 239 module_put(serial->type->driver.owner); 242 240 error_module_get: 243 241 error_no_port: ··· 1235 1239 goto exit_bus; 1236 1240 } 1237 1241 1238 - usb_serial_tty_driver->owner = THIS_MODULE; 1239 1242 usb_serial_tty_driver->driver_name = "usbserial"; 1240 1243 usb_serial_tty_driver->name = "ttyUSB"; 1241 1244 usb_serial_tty_driver->major = SERIAL_TTY_MAJOR;
+81 -4
fs/devpts/inode.c
··· 36 36 #define DEVPTS_DEFAULT_PTMX_MODE 0000 37 37 #define PTMX_MINOR 2 38 38 39 - extern int pty_limit; /* Config limit on Unix98 ptys */ 39 + /* 40 + * sysctl support for setting limits on the number of Unix98 ptys allocated. 41 + * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly. 42 + */ 43 + static int pty_limit = NR_UNIX98_PTY_DEFAULT; 44 + static int pty_reserve = NR_UNIX98_PTY_RESERVE; 45 + static int pty_limit_min; 46 + static int pty_limit_max = INT_MAX; 47 + static int pty_count; 48 + 49 + static struct ctl_table pty_table[] = { 50 + { 51 + .procname = "max", 52 + .maxlen = sizeof(int), 53 + .mode = 0644, 54 + .data = &pty_limit, 55 + .proc_handler = proc_dointvec_minmax, 56 + .extra1 = &pty_limit_min, 57 + .extra2 = &pty_limit_max, 58 + }, { 59 + .procname = "reserve", 60 + .maxlen = sizeof(int), 61 + .mode = 0644, 62 + .data = &pty_reserve, 63 + .proc_handler = proc_dointvec_minmax, 64 + .extra1 = &pty_limit_min, 65 + .extra2 = &pty_limit_max, 66 + }, { 67 + .procname = "nr", 68 + .maxlen = sizeof(int), 69 + .mode = 0444, 70 + .data = &pty_count, 71 + .proc_handler = proc_dointvec, 72 + }, 73 + {} 74 + }; 75 + 76 + static struct ctl_table pty_kern_table[] = { 77 + { 78 + .procname = "pty", 79 + .mode = 0555, 80 + .child = pty_table, 81 + }, 82 + {} 83 + }; 84 + 85 + static struct ctl_table pty_root_table[] = { 86 + { 87 + .procname = "kernel", 88 + .mode = 0555, 89 + .child = pty_kern_table, 90 + }, 91 + {} 92 + }; 93 + 40 94 static DEFINE_MUTEX(allocated_ptys_lock); 41 95 42 96 static struct vfsmount *devpts_mnt; ··· 103 49 umode_t mode; 104 50 umode_t ptmxmode; 105 51 int newinstance; 52 + int max; 106 53 }; 107 54 108 55 enum { 109 - Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_newinstance, 56 + Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_newinstance, Opt_max, 110 57 Opt_err 111 58 }; 112 59 ··· 118 63 #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES 119 64 {Opt_ptmxmode, "ptmxmode=%o"}, 120 65 {Opt_newinstance, "newinstance"}, 66 + {Opt_max, "max=%d"}, 121 67 #endif 122 68 {Opt_err, NULL} 123 69 }; ··· 165 109 opts->gid = 0; 166 110 opts->mode = DEVPTS_DEFAULT_MODE; 167 111 opts->ptmxmode = DEVPTS_DEFAULT_PTMX_MODE; 112 + opts->max = NR_UNIX98_PTY_MAX; 168 113 169 114 /* newinstance makes sense only on initial mount */ 170 115 if (op == PARSE_MOUNT) ··· 208 151 /* newinstance makes sense only on initial mount */ 209 152 if (op == PARSE_MOUNT) 210 153 opts->newinstance = 1; 154 + break; 155 + case Opt_max: 156 + if (match_int(&args[0], &option) || 157 + option < 0 || option > NR_UNIX98_PTY_MAX) 158 + return -EINVAL; 159 + opts->max = option; 211 160 break; 212 161 #endif 213 162 default: ··· 321 258 seq_printf(seq, ",mode=%03o", opts->mode); 322 259 #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES 323 260 seq_printf(seq, ",ptmxmode=%03o", opts->ptmxmode); 261 + if (opts->max < NR_UNIX98_PTY_MAX) 262 + seq_printf(seq, ",max=%d", opts->max); 324 263 #endif 325 264 326 265 return 0; ··· 503 438 return -ENOMEM; 504 439 505 440 mutex_lock(&allocated_ptys_lock); 441 + if (pty_count >= pty_limit - 442 + (fsi->mount_opts.newinstance ? pty_reserve : 0)) { 443 + mutex_unlock(&allocated_ptys_lock); 444 + return -ENOSPC; 445 + } 446 + 506 447 ida_ret = ida_get_new(&fsi->allocated_ptys, &index); 507 448 if (ida_ret < 0) { 508 449 mutex_unlock(&allocated_ptys_lock); ··· 517 446 return -EIO; 518 447 } 519 448 520 - if (index >= pty_limit) { 449 + if (index >= fsi->mount_opts.max) { 521 450 ida_remove(&fsi->allocated_ptys, index); 522 451 mutex_unlock(&allocated_ptys_lock); 523 - return -EIO; 452 + return -ENOSPC; 524 453 } 454 + pty_count++; 525 455 mutex_unlock(&allocated_ptys_lock); 526 456 return index; 527 457 } ··· 534 462 535 463 mutex_lock(&allocated_ptys_lock); 536 464 ida_remove(&fsi->allocated_ptys, idx); 465 + pty_count--; 537 466 mutex_unlock(&allocated_ptys_lock); 538 467 } 539 468 ··· 631 558 static int __init init_devpts_fs(void) 632 559 { 633 560 int err = register_filesystem(&devpts_fs_type); 561 + struct ctl_table_header *table; 562 + 634 563 if (!err) { 564 + table = register_sysctl_table(pty_root_table); 635 565 devpts_mnt = kern_mount(&devpts_fs_type); 636 566 if (IS_ERR(devpts_mnt)) { 637 567 err = PTR_ERR(devpts_mnt); 638 568 unregister_filesystem(&devpts_fs_type); 569 + unregister_sysctl_table(table); 639 570 } 640 571 } 641 572 return err;
-4
include/linux/altera_uart.h
··· 5 5 #ifndef __ALTUART_H 6 6 #define __ALTUART_H 7 7 8 - #include <linux/init.h> 9 - 10 8 struct altera_uart_platform_uart { 11 9 unsigned long mapbase; /* Physical address base */ 12 10 unsigned int irq; /* Interrupt vector */ 13 11 unsigned int uartclk; /* UART clock rate */ 14 12 unsigned int bus_shift; /* Bus shift (address stride) */ 15 13 }; 16 - 17 - int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp); 18 14 19 15 #endif /* __ALTUART_H */
+1 -6
include/linux/kbd_kern.h
··· 7 7 8 8 extern struct tasklet_struct keyboard_tasklet; 9 9 10 - extern int shift_state; 11 - 12 10 extern char *func_table[MAX_NR_FUNC]; 13 11 extern char func_buf[]; 14 12 extern char *funcbufptr; ··· 63 65 #define VC_META 4 /* 0 - meta, 1 - meta=prefix with ESC */ 64 66 }; 65 67 66 - extern struct kbd_struct kbd_table[]; 67 - 68 68 extern int kbd_init(void); 69 69 70 70 extern unsigned char getledstate(void); ··· 75 79 extern int set_console(int nr); 76 80 extern void schedule_console_callback(void); 77 81 82 + /* FIXME: review locking for vt.c callers */ 78 83 static inline void set_leds(void) 79 84 { 80 85 tasklet_schedule(&keyboard_tasklet); ··· 139 142 140 143 struct console; 141 144 142 - int getkeycode(unsigned int scancode); 143 - int setkeycode(unsigned int scancode, unsigned int keycode); 144 145 void compute_shiftstate(void); 145 146 146 147 /* defkeymap.c */
-2
include/linux/keyboard.h
··· 24 24 25 25 #ifdef __KERNEL__ 26 26 struct notifier_block; 27 - extern const int NR_TYPES; 28 - extern const int max_vals[]; 29 27 extern unsigned short *key_maps[MAX_NR_KEYMAPS]; 30 28 extern unsigned short plain_map[NR_KEYS]; 31 29
+18
include/linux/platform_data/efm32-uart.h
··· 1 + /* 2 + * 3 + * 4 + */ 5 + #ifndef __LINUX_PLATFORM_DATA_EFM32_UART_H__ 6 + #define __LINUX_PLATFORM_DATA_EFM32_UART_H__ 7 + 8 + #include <linux/types.h> 9 + 10 + /** 11 + * struct efm32_uart_pdata 12 + * @location: pinmux location for the I/O pins (to be written to the ROUTE 13 + * register) 14 + */ 15 + struct efm32_uart_pdata { 16 + u8 location; 17 + }; 18 + #endif /* ifndef __LINUX_PLATFORM_DATA_EFM32_UART_H__ */
+2 -2
include/linux/serial.h
··· 152 152 #define ASYNC_AUTOPROBE (1U << ASYNCB_AUTOPROBE) 153 153 154 154 #define ASYNC_FLAGS ((1U << (ASYNCB_LAST_USER + 1)) - 1) 155 - #define ASYNC_USR_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI| \ 156 - ASYNC_CALLOUT_NOHUP|ASYNC_SPD_SHI|ASYNC_LOW_LATENCY) 155 + #define ASYNC_USR_MASK (ASYNC_SPD_MASK|ASYNC_CALLOUT_NOHUP| \ 156 + ASYNC_LOW_LATENCY) 157 157 #define ASYNC_SPD_CUST (ASYNC_SPD_HI|ASYNC_SPD_VHI) 158 158 #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI) 159 159 #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI)
-142
include/linux/serialP.h
··· 1 - /* 2 - * Private header file for the (dumb) serial driver 3 - * 4 - * Copyright (C) 1997 by Theodore Ts'o. 5 - * 6 - * Redistribution of this file is permitted under the terms of the GNU 7 - * Public License (GPL) 8 - */ 9 - 10 - #ifndef _LINUX_SERIALP_H 11 - #define _LINUX_SERIALP_H 12 - 13 - /* 14 - * This is our internal structure for each serial port's state. 15 - * 16 - * Many fields are paralleled by the structure used by the serial_struct 17 - * structure. 18 - * 19 - * For definitions of the flags field, see tty.h 20 - */ 21 - 22 - #include <linux/termios.h> 23 - #include <linux/workqueue.h> 24 - #include <linux/interrupt.h> 25 - #include <linux/circ_buf.h> 26 - #include <linux/wait.h> 27 - 28 - struct serial_state { 29 - int magic; 30 - int baud_base; 31 - unsigned long port; 32 - int irq; 33 - int flags; 34 - int hub6; 35 - int type; 36 - int line; 37 - int revision; /* Chip revision (950) */ 38 - int xmit_fifo_size; 39 - int custom_divisor; 40 - int count; 41 - u8 *iomem_base; 42 - u16 iomem_reg_shift; 43 - unsigned short close_delay; 44 - unsigned short closing_wait; /* time to wait before closing */ 45 - struct async_icount icount; 46 - int io_type; 47 - struct async_struct *info; 48 - struct pci_dev *dev; 49 - }; 50 - 51 - struct async_struct { 52 - int magic; 53 - unsigned long port; 54 - int hub6; 55 - int flags; 56 - int xmit_fifo_size; 57 - struct serial_state *state; 58 - struct tty_struct *tty; 59 - int read_status_mask; 60 - int ignore_status_mask; 61 - int timeout; 62 - int quot; 63 - int x_char; /* xon/xoff character */ 64 - int close_delay; 65 - unsigned short closing_wait; 66 - unsigned short closing_wait2; /* obsolete */ 67 - int IER; /* Interrupt Enable Register */ 68 - int MCR; /* Modem control register */ 69 - int LCR; /* Line control register */ 70 - int ACR; /* 16950 Additional Control Reg. */ 71 - unsigned long event; 72 - unsigned long last_active; 73 - int line; 74 - int blocked_open; /* # of blocked opens */ 75 - struct circ_buf xmit; 76 - spinlock_t xmit_lock; 77 - u8 *iomem_base; 78 - u16 iomem_reg_shift; 79 - int io_type; 80 - struct work_struct work; 81 - struct tasklet_struct tlet; 82 - #ifdef DECLARE_WAITQUEUE 83 - wait_queue_head_t open_wait; 84 - wait_queue_head_t close_wait; 85 - wait_queue_head_t delta_msr_wait; 86 - #else 87 - struct wait_queue *open_wait; 88 - struct wait_queue *close_wait; 89 - struct wait_queue *delta_msr_wait; 90 - #endif 91 - struct async_struct *next_port; /* For the linked list */ 92 - struct async_struct *prev_port; 93 - }; 94 - 95 - #define CONFIGURED_SERIAL_PORT(info) ((info)->port || ((info)->iomem_base)) 96 - 97 - #define SERIAL_MAGIC 0x5301 98 - #define SSTATE_MAGIC 0x5302 99 - 100 - /* 101 - * Events are used to schedule things to happen at timer-interrupt 102 - * time, instead of at rs interrupt time. 103 - */ 104 - #define RS_EVENT_WRITE_WAKEUP 0 105 - 106 - /* 107 - * Multiport serial configuration structure --- internal structure 108 - */ 109 - struct rs_multiport_struct { 110 - int port1; 111 - unsigned char mask1, match1; 112 - int port2; 113 - unsigned char mask2, match2; 114 - int port3; 115 - unsigned char mask3, match3; 116 - int port4; 117 - unsigned char mask4, match4; 118 - int port_monitor; 119 - }; 120 - 121 - #if defined(__alpha__) && !defined(CONFIG_PCI) 122 - /* 123 - * Digital did something really horribly wrong with the OUT1 and OUT2 124 - * lines on at least some ALPHA's. The failure mode is that if either 125 - * is cleared, the machine locks up with endless interrupts. 126 - * 127 - * This is still used by arch/mips/au1000/common/serial.c for some weird 128 - * reason (mips != alpha!) 129 - */ 130 - #define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1) 131 - #elif defined(CONFIG_SBC8560) 132 - /* 133 - * WindRiver did something similarly broken on their SBC8560 board. The 134 - * UART tristates its IRQ output while OUT2 is clear, but they pulled 135 - * the interrupt line _up_ instead of down, so if we register the IRQ 136 - * while the UART is in that state, we die in an IRQ storm. */ 137 - #define ALPHA_KLUDGE_MCR (UART_MCR_OUT2) 138 - #else 139 - #define ALPHA_KLUDGE_MCR 0 140 - #endif 141 - 142 - #endif /* _LINUX_SERIAL_H */
+12
include/linux/serial_core.h
··· 210 210 /* Atheros AR933X SoC */ 211 211 #define PORT_AR933X 99 212 212 213 + /* Energy Micro efm32 SoC */ 214 + #define PORT_EFMUART 100 213 215 214 216 #ifdef __KERNEL__ 215 217 ··· 382 380 unsigned char unused[2]; 383 381 void *private_data; /* generic platform data pointer */ 384 382 }; 383 + 384 + static inline int serial_port_in(struct uart_port *up, int offset) 385 + { 386 + return up->serial_in(up, offset); 387 + } 388 + 389 + static inline void serial_port_out(struct uart_port *up, int offset, int value) 390 + { 391 + up->serial_out(up, offset, value); 392 + } 385 393 386 394 /* 387 395 * This is the state information which is persistent across opens.
+4 -2
include/linux/tty.h
··· 52 52 * hardcoded at present.) 53 53 */ 54 54 #define NR_UNIX98_PTY_DEFAULT 4096 /* Default maximum for Unix98 ptys */ 55 + #define NR_UNIX98_PTY_RESERVE 1024 /* Default reserve for main devpts */ 55 56 #define NR_UNIX98_PTY_MAX (1 << MINORBITS) /* Absolute limit */ 56 57 57 58 /* ··· 481 480 extern void initialize_tty_struct(struct tty_struct *tty, 482 481 struct tty_driver *driver, int idx); 483 482 extern void deinitialize_tty_struct(struct tty_struct *tty); 484 - extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, 485 - int first_ok); 483 + extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx); 486 484 extern int tty_release(struct inode *inode, struct file *filp); 487 485 extern int tty_init_termios(struct tty_struct *tty); 486 + extern int tty_standard_install(struct tty_driver *driver, 487 + struct tty_struct *tty); 488 488 489 489 extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty); 490 490 extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty);
+6 -2
include/linux/tty_driver.h
··· 50 50 * Note that tty_shutdown() is not called if ops->shutdown is defined. 51 51 * This means one is responsible to take care of calling ops->remove (e.g. 52 52 * via tty_driver_remove_tty) and releasing tty->termios. 53 + * Note that this hook may be called from *all* the contexts where one 54 + * uses tty refcounting (e.g. tty_port_tty_get). 53 55 * 54 56 * 55 57 * void (*cleanup)(struct tty_struct * tty); ··· 236 234 * if provided (otherwise EINVAL will be returned). 237 235 */ 238 236 237 + #include <linux/export.h> 239 238 #include <linux/fs.h> 240 239 #include <linux/list.h> 241 240 #include <linux/cdev.h> ··· 301 298 int name_base; /* offset of printed name */ 302 299 int major; /* major device number */ 303 300 int minor_start; /* start of minor device number */ 304 - int minor_num; /* number of *possible* devices */ 305 301 int num; /* number of devices allocated */ 306 302 short type; /* type of tty driver */ 307 303 short subtype; /* subtype of tty driver */ ··· 326 324 327 325 extern struct list_head tty_drivers; 328 326 329 - extern struct tty_driver *alloc_tty_driver(int lines); 327 + extern struct tty_driver *__alloc_tty_driver(int lines, struct module *owner); 330 328 extern void put_tty_driver(struct tty_driver *driver); 331 329 extern void tty_set_operations(struct tty_driver *driver, 332 330 const struct tty_operations *op); 333 331 extern struct tty_driver *tty_find_polling_driver(char *name, int *line); 334 332 335 333 extern void tty_driver_kref_put(struct tty_driver *driver); 334 + 335 + #define alloc_tty_driver(lines) __alloc_tty_driver(lines, THIS_MODULE) 336 336 337 337 static inline struct tty_driver *tty_driver_kref_get(struct tty_driver *d) 338 338 {
+26
include/linux/vt_kern.h
··· 167 167 168 168 extern void hide_boot_cursor(bool hide); 169 169 170 + /* keyboard provided interfaces */ 171 + extern int vt_do_diacrit(unsigned int cmd, void __user *up, int eperm); 172 + extern int vt_do_kdskbmode(int console, unsigned int arg); 173 + extern int vt_do_kdskbmeta(int console, unsigned int arg); 174 + extern int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, 175 + int perm); 176 + extern int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, 177 + int perm, int console); 178 + extern int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, 179 + int perm); 180 + extern int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm); 181 + extern int vt_do_kdgkbmode(int console); 182 + extern int vt_do_kdgkbmeta(int console); 183 + extern void vt_reset_unicode(int console); 184 + extern int vt_get_shift_state(void); 185 + extern void vt_reset_keyboard(int console); 186 + extern int vt_get_leds(int console, int flag); 187 + extern int vt_get_kbd_mode_bit(int console, int bit); 188 + extern void vt_set_kbd_mode_bit(int console, int bit); 189 + extern void vt_clr_kbd_mode_bit(int console, int bit); 190 + extern void vt_set_led_state(int console, int leds); 191 + extern void vt_set_led_state(int console, int leds); 192 + extern void vt_kbd_con_start(int console); 193 + extern void vt_kbd_con_stop(int console); 194 + 195 + 170 196 #endif /* _VT_KERN_H */
-1
net/bluetooth/rfcomm/tty.c
··· 1157 1157 if (!rfcomm_tty_driver) 1158 1158 return -ENOMEM; 1159 1159 1160 - rfcomm_tty_driver->owner = THIS_MODULE; 1161 1160 rfcomm_tty_driver->driver_name = "rfcomm"; 1162 1161 rfcomm_tty_driver->name = "rfcomm"; 1163 1162 rfcomm_tty_driver->major = RFCOMM_TTY_MAJOR;
+1 -6
net/irda/ircomm/ircomm_tty.c
··· 122 122 return -ENOMEM; 123 123 } 124 124 125 - driver->owner = THIS_MODULE; 126 125 driver->driver_name = "ircomm"; 127 126 driver->name = "ircomm"; 128 127 driver->major = IRCOMM_TTY_MAJOR; ··· 365 366 static int ircomm_tty_open(struct tty_struct *tty, struct file *filp) 366 367 { 367 368 struct ircomm_tty_cb *self; 368 - unsigned int line; 369 + unsigned int line = tty->index; 369 370 unsigned long flags; 370 371 int ret; 371 372 372 373 IRDA_DEBUG(2, "%s()\n", __func__ ); 373 - 374 - line = tty->index; 375 - if (line >= IRCOMM_TTY_PORTS) 376 - return -ENODEV; 377 374 378 375 /* Check if instance already exists */ 379 376 self = hashbin_lock_find(ircomm_tty, line, NULL);