aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorOlof Johansson <olof@lixom.net>2012-11-05 13:09:12 -0500
committerOlof Johansson <olof@lixom.net>2012-11-05 13:09:12 -0500
commit6d06721570aa0c38d886e3036796d59983963a27 (patch)
treed674cf54e26837bee89095c211ffa362c8546f03 /drivers
parent148a8698763130c96004ef419b5f0d44a93d413c (diff)
parent54ec52b6dd3b0ba4bc4eb97e7e1b2534705b326c (diff)
Merge branch 'depends/tty' into next/headers
Merging in Greg's tty tree including a cleanup patch needed by the OMAP serial header cleanups. * depends/tty: (305 commits) tty/serial/8250: Make omap hardware workarounds local to 8250.h serial/8250/8250_early: Prevent rounding error in uartclk serial: samsung: use clk_prepare_enable and clk_disable_unprepare TTY: Report warning when low_latency flag is wrongly used console: use might_sleep in console_lock TTY: move tty buffers to tty_port TTY: add port -> tty link TTY: tty_buffer, cache pointer to tty->buf TTY: move TTY_FLUSH* flags to tty_port TTY: n_tty, propagate n_tty_data TTY: move ldisc data from tty_struct: locks TTY: move ldisc data from tty_struct: read_* and echo_* and canon_* stuff TTY: move ldisc data from tty_struct: bitmaps TTY: move ldisc data from tty_struct: simple members TTY: n_tty, add ldisc data to n_tty TTY: audit, stop accessing tty->icount TTY: n_tty, remove bogus checks TTY: n_tty, simplify read_buf+echo_buf allocation TTY: hci_ldisc, remove invalid check in open TTY: ldisc, wait for idle ldisc in release ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile4
-rw-r--r--drivers/acpi/Makefile5
-rw-r--r--drivers/bluetooth/hci_ldisc.c7
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/agp/intel-gtt.c2
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c2
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c36
-rw-r--r--drivers/firmware/memmap.c4
-rw-r--r--drivers/gpio/gpio-mvebu.c3
-rw-r--r--drivers/gpu/drm/drm_info.c2
-rw-r--r--drivers/gpu/drm/i915/dvo_ch7xxx.c6
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h9
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c19
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h2
-rw-r--r--drivers/gpu/drm/i915/intel_display.c47
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c3
-rw-r--r--drivers/gpu/drm/i915/intel_overlay.c72
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c4
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/bios/dcb.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/fb/nv50.c1
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/fan.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_pm.c6
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c8
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c7
-rw-r--r--drivers/gpu/drm/radeon/ni.c12
-rw-r--r--drivers/gpu/drm/radeon/r600.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon.h14
-rw-r--r--drivers/gpu/drm/radeon/radeon_acpi.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_atpx_handler.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c1
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_gart.c374
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c22
-rw-r--r--drivers/gpu/drm/radeon/radeon_legacy_encoders.c48
-rw-r--r--drivers/gpu/drm/radeon/radeon_ring.c2
-rw-r--r--drivers/gpu/drm/radeon/si.c7
-rw-r--r--drivers/hwmon/coretemp.c7
-rw-r--r--drivers/hwmon/pmbus/Kconfig2
-rw-r--r--drivers/media/Kconfig18
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c10
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c2
-rw-r--r--drivers/of/address.c24
-rw-r--r--drivers/of/irq.c8
-rw-r--r--drivers/of/platform.c2
-rw-r--r--drivers/pcmcia/pxa2xx_sharpsl.c2
-rw-r--r--drivers/pinctrl/pinctrl-bcm2835.c5
-rw-r--r--drivers/pinctrl/pinctrl-nomadik.c26
-rw-r--r--drivers/pinctrl/pinctrl-samsung.c10
-rw-r--r--drivers/pinctrl/pinctrl-sirf.c35
-rw-r--r--drivers/pinctrl/pinctrl-xway.c2
-rw-r--r--drivers/s390/net/qeth_l2_main.c11
-rw-r--r--drivers/s390/net/qeth_l3_main.c11
-rw-r--r--drivers/s390/net/smsgiucv.c2
-rw-r--r--drivers/scsi/arm/fas216.c2
-rw-r--r--drivers/scsi/arm/oak.c1
-rw-r--r--drivers/sh/intc/access.c45
-rw-r--r--drivers/sh/intc/chip.c4
-rw-r--r--drivers/spi/spi-s3c64xx.c6
-rw-r--r--drivers/staging/dgrp/dgrp_mon_ops.c1
-rw-r--r--drivers/staging/dgrp/dgrp_specproc.c7
-rw-r--r--drivers/staging/dgrp/dgrp_tty.c10
-rw-r--r--drivers/thermal/Kconfig2
-rw-r--r--drivers/tty/n_tty.c752
-rw-r--r--drivers/tty/pty.c30
-rw-r--r--drivers/tty/serial/8250/8250.c9
-rw-r--r--drivers/tty/serial/8250/8250.h36
-rw-r--r--drivers/tty/serial/8250/8250_early.c2
-rw-r--r--drivers/tty/serial/8250/8250_hp300.c20
-rw-r--r--drivers/tty/serial/Kconfig4
-rw-r--r--drivers/tty/serial/samsung.c16
-rw-r--r--drivers/tty/serial/sccnxp.c1
-rw-r--r--drivers/tty/serial/sh-sci.c3
-rw-r--r--drivers/tty/sysrq.c1
-rw-r--r--drivers/tty/tty_audit.c15
-rw-r--r--drivers/tty/tty_buffer.c228
-rw-r--r--drivers/tty/tty_io.c15
-rw-r--r--drivers/tty/tty_ldisc.c15
-rw-r--r--drivers/tty/tty_port.c2
-rw-r--r--drivers/tty/vt/selection.c9
-rw-r--r--drivers/usb/class/cdc-acm.c22
-rw-r--r--drivers/usb/core/devio.c1
-rw-r--r--drivers/usb/core/driver.c4
-rw-r--r--drivers/usb/core/hub.c36
-rw-r--r--drivers/usb/dwc3/core.c4
-rw-r--r--drivers/usb/dwc3/gadget.c2
-rw-r--r--drivers/usb/gadget/Kconfig1
-rw-r--r--drivers/usb/gadget/lpc32xx_udc.c4
-rw-r--r--drivers/usb/host/ehci-fsl.c2
-rw-r--r--drivers/usb/host/ehci-orion.c2
-rw-r--r--drivers/usb/host/ehci-vt8500.c10
-rw-r--r--drivers/usb/host/uhci-platform.c9
-rw-r--r--drivers/usb/host/xhci.c3
-rw-r--r--drivers/usb/musb/am35x.c6
-rw-r--r--drivers/usb/renesas_usbhs/mod.c6
-rw-r--r--drivers/usb/renesas_usbhs/pipe.h2
-rw-r--r--drivers/usb/serial/ark3116.c26
-rw-r--r--drivers/usb/serial/belkin_sa.c31
-rw-r--r--drivers/usb/serial/cp210x.c40
-rw-r--r--drivers/usb/serial/cyberjack.c49
-rw-r--r--drivers/usb/serial/cypress_m8.c75
-rw-r--r--drivers/usb/serial/f81232.c43
-rw-r--r--drivers/usb/serial/garmin_gps.c24
-rw-r--r--drivers/usb/serial/io_edgeport.c54
-rw-r--r--drivers/usb/serial/io_tables.h8
-rw-r--r--drivers/usb/serial/io_ti.c91
-rw-r--r--drivers/usb/serial/iuu_phoenix.c76
-rw-r--r--drivers/usb/serial/keyspan_pda.c30
-rw-r--r--drivers/usb/serial/kl5kusb105.c68
-rw-r--r--drivers/usb/serial/kobil_sct.c23
-rw-r--r--drivers/usb/serial/option.c84
-rw-r--r--drivers/usb/serial/oti6858.c68
-rw-r--r--drivers/usb/serial/pl2303.c90
-rw-r--r--drivers/usb/serial/spcp8x5.c46
-rw-r--r--drivers/usb/serial/ssu100.c34
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c88
-rw-r--r--drivers/video/backlight/lm3639_bl.c4
-rw-r--r--drivers/xen/xenbus/xenbus_xs.c2
119 files changed, 1880 insertions, 1457 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index 03da5b663aef..a16a8d001ae0 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -17,6 +17,10 @@ obj-$(CONFIG_PARISC) += parisc/
17obj-$(CONFIG_RAPIDIO) += rapidio/ 17obj-$(CONFIG_RAPIDIO) += rapidio/
18obj-y += video/ 18obj-y += video/
19obj-y += idle/ 19obj-y += idle/
20
21# IPMI must come before ACPI in order to provide IPMI opregion support
22obj-$(CONFIG_IPMI_HANDLER) += char/ipmi/
23
20obj-$(CONFIG_ACPI) += acpi/ 24obj-$(CONFIG_ACPI) += acpi/
21obj-$(CONFIG_SFI) += sfi/ 25obj-$(CONFIG_SFI) += sfi/
22# PnP must come after ACPI since it will eventually need to check if acpi 26# PnP must come after ACPI since it will eventually need to check if acpi
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 47199e2a9130..82422fe90f81 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -47,6 +47,10 @@ acpi-y += video_detect.o
47endif 47endif
48 48
49# These are (potentially) separate modules 49# These are (potentially) separate modules
50
51# IPMI may be used by other drivers, so it has to initialise before them
52obj-$(CONFIG_ACPI_IPMI) += acpi_ipmi.o
53
50obj-$(CONFIG_ACPI_AC) += ac.o 54obj-$(CONFIG_ACPI_AC) += ac.o
51obj-$(CONFIG_ACPI_BUTTON) += button.o 55obj-$(CONFIG_ACPI_BUTTON) += button.o
52obj-$(CONFIG_ACPI_FAN) += fan.o 56obj-$(CONFIG_ACPI_FAN) += fan.o
@@ -70,6 +74,5 @@ processor-y += processor_idle.o processor_thermal.o
70processor-$(CONFIG_CPU_FREQ) += processor_perflib.o 74processor-$(CONFIG_CPU_FREQ) += processor_perflib.o
71 75
72obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o 76obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o
73obj-$(CONFIG_ACPI_IPMI) += acpi_ipmi.o
74 77
75obj-$(CONFIG_ACPI_APEI) += apei/ 78obj-$(CONFIG_ACPI_APEI) += apei/
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index c8abce3d2d9c..ed0fade46aed 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -270,15 +270,10 @@ static int hci_uart_send_frame(struct sk_buff *skb)
270 */ 270 */
271static int hci_uart_tty_open(struct tty_struct *tty) 271static int hci_uart_tty_open(struct tty_struct *tty)
272{ 272{
273 struct hci_uart *hu = (void *) tty->disc_data; 273 struct hci_uart *hu;
274 274
275 BT_DBG("tty %p", tty); 275 BT_DBG("tty %p", tty);
276 276
277 /* FIXME: This btw is bogus, nothing requires the old ldisc to clear
278 the pointer */
279 if (hu)
280 return -EEXIST;
281
282 /* Error if the tty has no write op instead of leaving an exploitable 277 /* Error if the tty has no write op instead of leaving an exploitable
283 hole */ 278 hole */
284 if (tty->ops->write == NULL) 279 if (tty->ops->write == NULL)
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index d0b27a39f1d4..7ff1d0d208a7 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -52,7 +52,6 @@ obj-$(CONFIG_TELCLOCK) += tlclk.o
52obj-$(CONFIG_MWAVE) += mwave/ 52obj-$(CONFIG_MWAVE) += mwave/
53obj-$(CONFIG_AGP) += agp/ 53obj-$(CONFIG_AGP) += agp/
54obj-$(CONFIG_PCMCIA) += pcmcia/ 54obj-$(CONFIG_PCMCIA) += pcmcia/
55obj-$(CONFIG_IPMI_HANDLER) += ipmi/
56 55
57obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o 56obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
58obj-$(CONFIG_TCG_TPM) += tpm/ 57obj-$(CONFIG_TCG_TPM) += tpm/
diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index e01f5eaaec82..38390f7c6ab6 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -667,7 +667,7 @@ static int intel_gtt_init(void)
667 gtt_map_size = intel_private.base.gtt_total_entries * 4; 667 gtt_map_size = intel_private.base.gtt_total_entries * 4;
668 668
669 intel_private.gtt = NULL; 669 intel_private.gtt = NULL;
670 if (INTEL_GTT_GEN < 6) 670 if (INTEL_GTT_GEN < 6 && INTEL_GTT_GEN > 2)
671 intel_private.gtt = ioremap_wc(intel_private.gtt_bus_addr, 671 intel_private.gtt = ioremap_wc(intel_private.gtt_bus_addr,
672 gtt_map_size); 672 gtt_map_size);
673 if (intel_private.gtt == NULL) 673 if (intel_private.gtt == NULL)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 2c29942b1326..a0c84bb30856 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1880,7 +1880,7 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1880 struct ipmi_recv_msg *supplied_recv, 1880 struct ipmi_recv_msg *supplied_recv,
1881 int priority) 1881 int priority)
1882{ 1882{
1883 unsigned char saddr, lun; 1883 unsigned char saddr = 0, lun = 0;
1884 int rv; 1884 int rv;
1885 1885
1886 if (!user) 1886 if (!user)
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 83f85cf7fb1b..32a6c7e256bd 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2424,6 +2424,38 @@ static void ipmi_pci_cleanup(struct smi_info *info)
2424 pci_disable_device(pdev); 2424 pci_disable_device(pdev);
2425} 2425}
2426 2426
2427static int __devinit ipmi_pci_probe_regspacing(struct smi_info *info)
2428{
2429 if (info->si_type == SI_KCS) {
2430 unsigned char status;
2431 int regspacing;
2432
2433 info->io.regsize = DEFAULT_REGSIZE;
2434 info->io.regshift = 0;
2435 info->io_size = 2;
2436 info->handlers = &kcs_smi_handlers;
2437
2438 /* detect 1, 4, 16byte spacing */
2439 for (regspacing = DEFAULT_REGSPACING; regspacing <= 16;) {
2440 info->io.regspacing = regspacing;
2441 if (info->io_setup(info)) {
2442 dev_err(info->dev,
2443 "Could not setup I/O space\n");
2444 return DEFAULT_REGSPACING;
2445 }
2446 /* write invalid cmd */
2447 info->io.outputb(&info->io, 1, 0x10);
2448 /* read status back */
2449 status = info->io.inputb(&info->io, 1);
2450 info->io_cleanup(info);
2451 if (status)
2452 return regspacing;
2453 regspacing *= 4;
2454 }
2455 }
2456 return DEFAULT_REGSPACING;
2457}
2458
2427static int __devinit ipmi_pci_probe(struct pci_dev *pdev, 2459static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2428 const struct pci_device_id *ent) 2460 const struct pci_device_id *ent)
2429{ 2461{
@@ -2476,8 +2508,8 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2476 } 2508 }
2477 info->io.addr_data = pci_resource_start(pdev, 0); 2509 info->io.addr_data = pci_resource_start(pdev, 0);
2478 2510
2479 info->io.regspacing = DEFAULT_REGSPACING; 2511 info->io.regspacing = ipmi_pci_probe_regspacing(info);
2480 info->io.regsize = DEFAULT_REGSPACING; 2512 info->io.regsize = DEFAULT_REGSIZE;
2481 info->io.regshift = 0; 2513 info->io.regshift = 0;
2482 2514
2483 info->irq = pdev->irq; 2515 info->irq = pdev->irq;
diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
index c1cdc9236666..90723e65b081 100644
--- a/drivers/firmware/memmap.c
+++ b/drivers/firmware/memmap.c
@@ -237,7 +237,7 @@ static ssize_t memmap_attr_show(struct kobject *kobj,
237 * firmware_map_add() or firmware_map_add_early() afterwards, the entries 237 * firmware_map_add() or firmware_map_add_early() afterwards, the entries
238 * are not added to sysfs. 238 * are not added to sysfs.
239 */ 239 */
240static int __init memmap_init(void) 240static int __init firmware_memmap_init(void)
241{ 241{
242 struct firmware_map_entry *entry; 242 struct firmware_map_entry *entry;
243 243
@@ -246,5 +246,5 @@ static int __init memmap_init(void)
246 246
247 return 0; 247 return 0;
248} 248}
249late_initcall(memmap_init); 249late_initcall(firmware_memmap_init);
250 250
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 902af437eaf2..7a874129e5d8 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -381,11 +381,13 @@ static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type)
381 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 381 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
382 u &= ~(1 << pin); 382 u &= ~(1 << pin);
383 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); 383 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
384 break;
384 case IRQ_TYPE_EDGE_FALLING: 385 case IRQ_TYPE_EDGE_FALLING:
385 case IRQ_TYPE_LEVEL_LOW: 386 case IRQ_TYPE_LEVEL_LOW:
386 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 387 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
387 u |= 1 << pin; 388 u |= 1 << pin;
388 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); 389 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
390 break;
389 case IRQ_TYPE_EDGE_BOTH: { 391 case IRQ_TYPE_EDGE_BOTH: {
390 u32 v; 392 u32 v;
391 393
@@ -401,6 +403,7 @@ static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type)
401 else 403 else
402 u &= ~(1 << pin); /* rising */ 404 u &= ~(1 << pin); /* rising */
403 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); 405 writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
406 break;
404 } 407 }
405 } 408 }
406 return 0; 409 return 0;
diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
index cdf8b1e7602d..441ebc1bdbef 100644
--- a/drivers/gpu/drm/drm_info.c
+++ b/drivers/gpu/drm/drm_info.c
@@ -239,7 +239,7 @@ int drm_vma_info(struct seq_file *m, void *data)
239 mutex_lock(&dev->struct_mutex); 239 mutex_lock(&dev->struct_mutex);
240 seq_printf(m, "vma use count: %d, high_memory = %pK, 0x%pK\n", 240 seq_printf(m, "vma use count: %d, high_memory = %pK, 0x%pK\n",
241 atomic_read(&dev->vma_count), 241 atomic_read(&dev->vma_count),
242 high_memory, (void *)virt_to_phys(high_memory)); 242 high_memory, (void *)(unsigned long)virt_to_phys(high_memory));
243 243
244 list_for_each_entry(pt, &dev->vmalist, head) { 244 list_for_each_entry(pt, &dev->vmalist, head) {
245 vma = pt->vma; 245 vma = pt->vma;
diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
index 38f3a6cb8c7d..3edd981e0770 100644
--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
@@ -303,10 +303,10 @@ static bool ch7xxx_get_hw_state(struct intel_dvo_device *dvo)
303 303
304 ch7xxx_readb(dvo, CH7xxx_PM, &val); 304 ch7xxx_readb(dvo, CH7xxx_PM, &val);
305 305
306 if (val & CH7xxx_PM_FPD) 306 if (val & (CH7xxx_PM_DVIL | CH7xxx_PM_DVIP))
307 return false;
308 else
309 return true; 307 return true;
308 else
309 return false;
310} 310}
311 311
312static void ch7xxx_dump_regs(struct intel_dvo_device *dvo) 312static void ch7xxx_dump_regs(struct intel_dvo_device *dvo)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 4f2831aa5fed..b84f7861e438 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1341,9 +1341,14 @@ int __must_check i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
1341static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n) 1341static inline struct page *i915_gem_object_get_page(struct drm_i915_gem_object *obj, int n)
1342{ 1342{
1343 struct scatterlist *sg = obj->pages->sgl; 1343 struct scatterlist *sg = obj->pages->sgl;
1344 while (n >= SG_MAX_SINGLE_ALLOC) { 1344 int nents = obj->pages->nents;
1345 while (nents > SG_MAX_SINGLE_ALLOC) {
1346 if (n < SG_MAX_SINGLE_ALLOC - 1)
1347 break;
1348
1345 sg = sg_chain_ptr(sg + SG_MAX_SINGLE_ALLOC - 1); 1349 sg = sg_chain_ptr(sg + SG_MAX_SINGLE_ALLOC - 1);
1346 n -= SG_MAX_SINGLE_ALLOC - 1; 1350 n -= SG_MAX_SINGLE_ALLOC - 1;
1351 nents -= SG_MAX_SINGLE_ALLOC - 1;
1347 } 1352 }
1348 return sg_page(sg+n); 1353 return sg_page(sg+n);
1349} 1354}
@@ -1427,7 +1432,7 @@ int __must_check i915_gpu_idle(struct drm_device *dev);
1427int __must_check i915_gem_idle(struct drm_device *dev); 1432int __must_check i915_gem_idle(struct drm_device *dev);
1428int i915_add_request(struct intel_ring_buffer *ring, 1433int i915_add_request(struct intel_ring_buffer *ring,
1429 struct drm_file *file, 1434 struct drm_file *file,
1430 struct drm_i915_gem_request *request); 1435 u32 *seqno);
1431int __must_check i915_wait_seqno(struct intel_ring_buffer *ring, 1436int __must_check i915_wait_seqno(struct intel_ring_buffer *ring,
1432 uint32_t seqno); 1437 uint32_t seqno);
1433int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf); 1438int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 19dbdd7dd564..d33d02d13c96 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1955,11 +1955,12 @@ i915_gem_next_request_seqno(struct intel_ring_buffer *ring)
1955int 1955int
1956i915_add_request(struct intel_ring_buffer *ring, 1956i915_add_request(struct intel_ring_buffer *ring,
1957 struct drm_file *file, 1957 struct drm_file *file,
1958 struct drm_i915_gem_request *request) 1958 u32 *out_seqno)
1959{ 1959{
1960 drm_i915_private_t *dev_priv = ring->dev->dev_private; 1960 drm_i915_private_t *dev_priv = ring->dev->dev_private;
1961 uint32_t seqno; 1961 struct drm_i915_gem_request *request;
1962 u32 request_ring_position; 1962 u32 request_ring_position;
1963 u32 seqno;
1963 int was_empty; 1964 int was_empty;
1964 int ret; 1965 int ret;
1965 1966
@@ -1974,11 +1975,9 @@ i915_add_request(struct intel_ring_buffer *ring,
1974 if (ret) 1975 if (ret)
1975 return ret; 1976 return ret;
1976 1977
1977 if (request == NULL) { 1978 request = kmalloc(sizeof(*request), GFP_KERNEL);
1978 request = kmalloc(sizeof(*request), GFP_KERNEL); 1979 if (request == NULL)
1979 if (request == NULL) 1980 return -ENOMEM;
1980 return -ENOMEM;
1981 }
1982 1981
1983 seqno = i915_gem_next_request_seqno(ring); 1982 seqno = i915_gem_next_request_seqno(ring);
1984 1983
@@ -2030,6 +2029,8 @@ i915_add_request(struct intel_ring_buffer *ring,
2030 } 2029 }
2031 } 2030 }
2032 2031
2032 if (out_seqno)
2033 *out_seqno = seqno;
2033 return 0; 2034 return 0;
2034} 2035}
2035 2036
@@ -3959,6 +3960,9 @@ i915_gem_init_hw(struct drm_device *dev)
3959 if (!intel_enable_gtt()) 3960 if (!intel_enable_gtt())
3960 return -EIO; 3961 return -EIO;
3961 3962
3963 if (IS_HASWELL(dev) && (I915_READ(0x120010) == 1))
3964 I915_WRITE(0x9008, I915_READ(0x9008) | 0xf0000);
3965
3962 i915_gem_l3_remap(dev); 3966 i915_gem_l3_remap(dev);
3963 3967
3964 i915_gem_init_swizzling(dev); 3968 i915_gem_init_swizzling(dev);
@@ -4098,7 +4102,6 @@ i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
4098 } 4102 }
4099 4103
4100 BUG_ON(!list_empty(&dev_priv->mm.active_list)); 4104 BUG_ON(!list_empty(&dev_priv->mm.active_list));
4101 BUG_ON(!list_empty(&dev_priv->mm.inactive_list));
4102 mutex_unlock(&dev->struct_mutex); 4105 mutex_unlock(&dev->struct_mutex);
4103 4106
4104 ret = drm_irq_install(dev); 4107 ret = drm_irq_install(dev);
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 64c1be0a9cfd..a4162ddff6c5 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -521,7 +521,7 @@
521 */ 521 */
522# define _3D_CHICKEN2_WM_READ_PIPELINED (1 << 14) 522# define _3D_CHICKEN2_WM_READ_PIPELINED (1 << 14)
523#define _3D_CHICKEN3 0x02090 523#define _3D_CHICKEN3 0x02090
524#define _3D_CHICKEN_SF_DISABLE_FASTCLIP_CULL (1 << 5) 524#define _3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL (1 << 5)
525 525
526#define MI_MODE 0x0209c 526#define MI_MODE 0x0209c
527# define VS_TIMER_DISPATCH (1 << 6) 527# define VS_TIMER_DISPATCH (1 << 6)
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 2b6ce9b2674a..682bd3729baf 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -3253,6 +3253,16 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
3253 3253
3254 if (HAS_PCH_CPT(dev)) 3254 if (HAS_PCH_CPT(dev))
3255 intel_cpt_verify_modeset(dev, intel_crtc->pipe); 3255 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
3256
3257 /*
3258 * There seems to be a race in PCH platform hw (at least on some
3259 * outputs) where an enabled pipe still completes any pageflip right
3260 * away (as if the pipe is off) instead of waiting for vblank. As soon
3261 * as the first vblank happend, everything works as expected. Hence just
3262 * wait for one vblank before returning to avoid strange things
3263 * happening.
3264 */
3265 intel_wait_for_vblank(dev, intel_crtc->pipe);
3256} 3266}
3257 3267
3258static void ironlake_crtc_disable(struct drm_crtc *crtc) 3268static void ironlake_crtc_disable(struct drm_crtc *crtc)
@@ -7892,8 +7902,7 @@ static struct intel_quirk intel_quirks[] = {
7892 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ 7902 /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
7893 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, 7903 { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
7894 7904
7895 /* 855 & before need to leave pipe A & dpll A up */ 7905 /* 830/845 need to leave pipe A & dpll A up */
7896 { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
7897 { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, 7906 { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
7898 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, 7907 { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
7899 7908
@@ -8049,29 +8058,42 @@ static void intel_enable_pipe_a(struct drm_device *dev)
8049 8058
8050} 8059}
8051 8060
8061static bool
8062intel_check_plane_mapping(struct intel_crtc *crtc)
8063{
8064 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
8065 u32 reg, val;
8066
8067 if (dev_priv->num_pipe == 1)
8068 return true;
8069
8070 reg = DSPCNTR(!crtc->plane);
8071 val = I915_READ(reg);
8072
8073 if ((val & DISPLAY_PLANE_ENABLE) &&
8074 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
8075 return false;
8076
8077 return true;
8078}
8079
8052static void intel_sanitize_crtc(struct intel_crtc *crtc) 8080static void intel_sanitize_crtc(struct intel_crtc *crtc)
8053{ 8081{
8054 struct drm_device *dev = crtc->base.dev; 8082 struct drm_device *dev = crtc->base.dev;
8055 struct drm_i915_private *dev_priv = dev->dev_private; 8083 struct drm_i915_private *dev_priv = dev->dev_private;
8056 u32 reg, val; 8084 u32 reg;
8057 8085
8058 /* Clear any frame start delays used for debugging left by the BIOS */ 8086 /* Clear any frame start delays used for debugging left by the BIOS */
8059 reg = PIPECONF(crtc->pipe); 8087 reg = PIPECONF(crtc->pipe);
8060 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); 8088 I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
8061 8089
8062 /* We need to sanitize the plane -> pipe mapping first because this will 8090 /* We need to sanitize the plane -> pipe mapping first because this will
8063 * disable the crtc (and hence change the state) if it is wrong. */ 8091 * disable the crtc (and hence change the state) if it is wrong. Note
8064 if (!HAS_PCH_SPLIT(dev)) { 8092 * that gen4+ has a fixed plane -> pipe mapping. */
8093 if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
8065 struct intel_connector *connector; 8094 struct intel_connector *connector;
8066 bool plane; 8095 bool plane;
8067 8096
8068 reg = DSPCNTR(crtc->plane);
8069 val = I915_READ(reg);
8070
8071 if ((val & DISPLAY_PLANE_ENABLE) == 0 &&
8072 (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
8073 goto ok;
8074
8075 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", 8097 DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
8076 crtc->base.base.id); 8098 crtc->base.base.id);
8077 8099
@@ -8095,7 +8117,6 @@ static void intel_sanitize_crtc(struct intel_crtc *crtc)
8095 WARN_ON(crtc->active); 8117 WARN_ON(crtc->active);
8096 crtc->base.enabled = false; 8118 crtc->base.enabled = false;
8097 } 8119 }
8098ok:
8099 8120
8100 if (dev_priv->quirks & QUIRK_PIPEA_FORCE && 8121 if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
8101 crtc->pipe == PIPE_A && !crtc->active) { 8122 crtc->pipe == PIPE_A && !crtc->active) {
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index d1e8ddb2d6c0..1b727a5c9ee5 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -2369,8 +2369,9 @@ static void
2369intel_dp_destroy(struct drm_connector *connector) 2369intel_dp_destroy(struct drm_connector *connector)
2370{ 2370{
2371 struct drm_device *dev = connector->dev; 2371 struct drm_device *dev = connector->dev;
2372 struct intel_dp *intel_dp = intel_attached_dp(connector);
2372 2373
2373 if (intel_dpd_is_edp(dev)) 2374 if (is_edp(intel_dp))
2374 intel_panel_destroy_backlight(dev); 2375 intel_panel_destroy_backlight(dev);
2375 2376
2376 drm_sysfs_connector_remove(connector); 2377 drm_sysfs_connector_remove(connector);
diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c
index ebff850a9ab6..495625914e4a 100644
--- a/drivers/gpu/drm/i915/intel_overlay.c
+++ b/drivers/gpu/drm/i915/intel_overlay.c
@@ -209,7 +209,6 @@ static void intel_overlay_unmap_regs(struct intel_overlay *overlay,
209} 209}
210 210
211static int intel_overlay_do_wait_request(struct intel_overlay *overlay, 211static int intel_overlay_do_wait_request(struct intel_overlay *overlay,
212 struct drm_i915_gem_request *request,
213 void (*tail)(struct intel_overlay *)) 212 void (*tail)(struct intel_overlay *))
214{ 213{
215 struct drm_device *dev = overlay->dev; 214 struct drm_device *dev = overlay->dev;
@@ -218,12 +217,10 @@ static int intel_overlay_do_wait_request(struct intel_overlay *overlay,
218 int ret; 217 int ret;
219 218
220 BUG_ON(overlay->last_flip_req); 219 BUG_ON(overlay->last_flip_req);
221 ret = i915_add_request(ring, NULL, request); 220 ret = i915_add_request(ring, NULL, &overlay->last_flip_req);
222 if (ret) { 221 if (ret)
223 kfree(request); 222 return ret;
224 return ret; 223
225 }
226 overlay->last_flip_req = request->seqno;
227 overlay->flip_tail = tail; 224 overlay->flip_tail = tail;
228 ret = i915_wait_seqno(ring, overlay->last_flip_req); 225 ret = i915_wait_seqno(ring, overlay->last_flip_req);
229 if (ret) 226 if (ret)
@@ -240,7 +237,6 @@ static int intel_overlay_on(struct intel_overlay *overlay)
240 struct drm_device *dev = overlay->dev; 237 struct drm_device *dev = overlay->dev;
241 struct drm_i915_private *dev_priv = dev->dev_private; 238 struct drm_i915_private *dev_priv = dev->dev_private;
242 struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; 239 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
243 struct drm_i915_gem_request *request;
244 int ret; 240 int ret;
245 241
246 BUG_ON(overlay->active); 242 BUG_ON(overlay->active);
@@ -248,17 +244,9 @@ static int intel_overlay_on(struct intel_overlay *overlay)
248 244
249 WARN_ON(IS_I830(dev) && !(dev_priv->quirks & QUIRK_PIPEA_FORCE)); 245 WARN_ON(IS_I830(dev) && !(dev_priv->quirks & QUIRK_PIPEA_FORCE));
250 246
251 request = kzalloc(sizeof(*request), GFP_KERNEL);
252 if (request == NULL) {
253 ret = -ENOMEM;
254 goto out;
255 }
256
257 ret = intel_ring_begin(ring, 4); 247 ret = intel_ring_begin(ring, 4);
258 if (ret) { 248 if (ret)
259 kfree(request); 249 return ret;
260 goto out;
261 }
262 250
263 intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_ON); 251 intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_ON);
264 intel_ring_emit(ring, overlay->flip_addr | OFC_UPDATE); 252 intel_ring_emit(ring, overlay->flip_addr | OFC_UPDATE);
@@ -266,9 +254,7 @@ static int intel_overlay_on(struct intel_overlay *overlay)
266 intel_ring_emit(ring, MI_NOOP); 254 intel_ring_emit(ring, MI_NOOP);
267 intel_ring_advance(ring); 255 intel_ring_advance(ring);
268 256
269 ret = intel_overlay_do_wait_request(overlay, request, NULL); 257 return intel_overlay_do_wait_request(overlay, NULL);
270out:
271 return ret;
272} 258}
273 259
274/* overlay needs to be enabled in OCMD reg */ 260/* overlay needs to be enabled in OCMD reg */
@@ -278,17 +264,12 @@ static int intel_overlay_continue(struct intel_overlay *overlay,
278 struct drm_device *dev = overlay->dev; 264 struct drm_device *dev = overlay->dev;
279 drm_i915_private_t *dev_priv = dev->dev_private; 265 drm_i915_private_t *dev_priv = dev->dev_private;
280 struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; 266 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
281 struct drm_i915_gem_request *request;
282 u32 flip_addr = overlay->flip_addr; 267 u32 flip_addr = overlay->flip_addr;
283 u32 tmp; 268 u32 tmp;
284 int ret; 269 int ret;
285 270
286 BUG_ON(!overlay->active); 271 BUG_ON(!overlay->active);
287 272
288 request = kzalloc(sizeof(*request), GFP_KERNEL);
289 if (request == NULL)
290 return -ENOMEM;
291
292 if (load_polyphase_filter) 273 if (load_polyphase_filter)
293 flip_addr |= OFC_UPDATE; 274 flip_addr |= OFC_UPDATE;
294 275
@@ -298,22 +279,14 @@ static int intel_overlay_continue(struct intel_overlay *overlay,
298 DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp); 279 DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp);
299 280
300 ret = intel_ring_begin(ring, 2); 281 ret = intel_ring_begin(ring, 2);
301 if (ret) { 282 if (ret)
302 kfree(request);
303 return ret; 283 return ret;
304 } 284
305 intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); 285 intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE);
306 intel_ring_emit(ring, flip_addr); 286 intel_ring_emit(ring, flip_addr);
307 intel_ring_advance(ring); 287 intel_ring_advance(ring);
308 288
309 ret = i915_add_request(ring, NULL, request); 289 return i915_add_request(ring, NULL, &overlay->last_flip_req);
310 if (ret) {
311 kfree(request);
312 return ret;
313 }
314
315 overlay->last_flip_req = request->seqno;
316 return 0;
317} 290}
318 291
319static void intel_overlay_release_old_vid_tail(struct intel_overlay *overlay) 292static void intel_overlay_release_old_vid_tail(struct intel_overlay *overlay)
@@ -349,15 +322,10 @@ static int intel_overlay_off(struct intel_overlay *overlay)
349 struct drm_i915_private *dev_priv = dev->dev_private; 322 struct drm_i915_private *dev_priv = dev->dev_private;
350 struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; 323 struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
351 u32 flip_addr = overlay->flip_addr; 324 u32 flip_addr = overlay->flip_addr;
352 struct drm_i915_gem_request *request;
353 int ret; 325 int ret;
354 326
355 BUG_ON(!overlay->active); 327 BUG_ON(!overlay->active);
356 328
357 request = kzalloc(sizeof(*request), GFP_KERNEL);
358 if (request == NULL)
359 return -ENOMEM;
360
361 /* According to intel docs the overlay hw may hang (when switching 329 /* According to intel docs the overlay hw may hang (when switching
362 * off) without loading the filter coeffs. It is however unclear whether 330 * off) without loading the filter coeffs. It is however unclear whether
363 * this applies to the disabling of the overlay or to the switching off 331 * this applies to the disabling of the overlay or to the switching off
@@ -365,10 +333,9 @@ static int intel_overlay_off(struct intel_overlay *overlay)
365 flip_addr |= OFC_UPDATE; 333 flip_addr |= OFC_UPDATE;
366 334
367 ret = intel_ring_begin(ring, 6); 335 ret = intel_ring_begin(ring, 6);
368 if (ret) { 336 if (ret)
369 kfree(request);
370 return ret; 337 return ret;
371 } 338
372 /* wait for overlay to go idle */ 339 /* wait for overlay to go idle */
373 intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); 340 intel_ring_emit(ring, MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE);
374 intel_ring_emit(ring, flip_addr); 341 intel_ring_emit(ring, flip_addr);
@@ -379,8 +346,7 @@ static int intel_overlay_off(struct intel_overlay *overlay)
379 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); 346 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
380 intel_ring_advance(ring); 347 intel_ring_advance(ring);
381 348
382 return intel_overlay_do_wait_request(overlay, request, 349 return intel_overlay_do_wait_request(overlay, intel_overlay_off_tail);
383 intel_overlay_off_tail);
384} 350}
385 351
386/* recover from an interruption due to a signal 352/* recover from an interruption due to a signal
@@ -425,24 +391,16 @@ static int intel_overlay_release_old_vid(struct intel_overlay *overlay)
425 return 0; 391 return 0;
426 392
427 if (I915_READ(ISR) & I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT) { 393 if (I915_READ(ISR) & I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT) {
428 struct drm_i915_gem_request *request;
429
430 /* synchronous slowpath */ 394 /* synchronous slowpath */
431 request = kzalloc(sizeof(*request), GFP_KERNEL);
432 if (request == NULL)
433 return -ENOMEM;
434
435 ret = intel_ring_begin(ring, 2); 395 ret = intel_ring_begin(ring, 2);
436 if (ret) { 396 if (ret)
437 kfree(request);
438 return ret; 397 return ret;
439 }
440 398
441 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); 399 intel_ring_emit(ring, MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
442 intel_ring_emit(ring, MI_NOOP); 400 intel_ring_emit(ring, MI_NOOP);
443 intel_ring_advance(ring); 401 intel_ring_advance(ring);
444 402
445 ret = intel_overlay_do_wait_request(overlay, request, 403 ret = intel_overlay_do_wait_request(overlay,
446 intel_overlay_release_old_vid_tail); 404 intel_overlay_release_old_vid_tail);
447 if (ret) 405 if (ret)
448 return ret; 406 return ret;
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index b3b4b6cea8b0..72f41aaa71ff 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3442,8 +3442,8 @@ static void gen6_init_clock_gating(struct drm_device *dev)
3442 GEN6_RCCUNIT_CLOCK_GATE_DISABLE); 3442 GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
3443 3443
3444 /* Bspec says we need to always set all mask bits. */ 3444 /* Bspec says we need to always set all mask bits. */
3445 I915_WRITE(_3D_CHICKEN, (0xFFFF << 16) | 3445 I915_WRITE(_3D_CHICKEN3, (0xFFFF << 16) |
3446 _3D_CHICKEN_SF_DISABLE_FASTCLIP_CULL); 3446 _3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL);
3447 3447
3448 /* 3448 /*
3449 * According to the spec the following bits should be 3449 * According to the spec the following bits should be
diff --git a/drivers/gpu/drm/nouveau/core/subdev/bios/dcb.c b/drivers/gpu/drm/nouveau/core/subdev/bios/dcb.c
index 9ed6e728a94c..7d750382a833 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/bios/dcb.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/bios/dcb.c
@@ -43,7 +43,7 @@ dcb_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
43 *ver = nv_ro08(bios, dcb); 43 *ver = nv_ro08(bios, dcb);
44 44
45 if (*ver >= 0x41) { 45 if (*ver >= 0x41) {
46 nv_warn(bios, "DCB *ver 0x%02x unknown\n", *ver); 46 nv_warn(bios, "DCB version 0x%02x unknown\n", *ver);
47 return 0x0000; 47 return 0x0000;
48 } else 48 } else
49 if (*ver >= 0x30) { 49 if (*ver >= 0x30) {
diff --git a/drivers/gpu/drm/nouveau/core/subdev/fb/nv50.c b/drivers/gpu/drm/nouveau/core/subdev/fb/nv50.c
index 436e9efe7ef5..42d7539e6525 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/fb/nv50.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/fb/nv50.c
@@ -277,7 +277,6 @@ nv50_fb_dtor(struct nouveau_object *object)
277 __free_page(priv->r100c08_page); 277 __free_page(priv->r100c08_page);
278 } 278 }
279 279
280 nouveau_mm_fini(&priv->base.vram);
281 nouveau_fb_destroy(&priv->base); 280 nouveau_fb_destroy(&priv->base);
282} 281}
283 282
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c b/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
index b29237970fa0..523178685180 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
@@ -134,7 +134,7 @@ nouveau_therm_fan_sense(struct nouveau_therm *therm)
134 end = ptimer->read(ptimer); 134 end = ptimer->read(ptimer);
135 135
136 if (cycles == 5) { 136 if (cycles == 5) {
137 tach = (u64)60000000000; 137 tach = (u64)60000000000ULL;
138 do_div(tach, (end - start)); 138 do_div(tach, (end - start));
139 return tach; 139 return tach;
140 } else 140 } else
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 259e5f1adf47..35ac57f0aab6 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -456,6 +456,7 @@ static struct ttm_tt *
456nouveau_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, 456nouveau_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size,
457 uint32_t page_flags, struct page *dummy_read) 457 uint32_t page_flags, struct page *dummy_read)
458{ 458{
459#if __OS_HAS_AGP
459 struct nouveau_drm *drm = nouveau_bdev(bdev); 460 struct nouveau_drm *drm = nouveau_bdev(bdev);
460 struct drm_device *dev = drm->dev; 461 struct drm_device *dev = drm->dev;
461 462
@@ -463,6 +464,7 @@ nouveau_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size,
463 return ttm_agp_tt_create(bdev, dev->agp->bridge, size, 464 return ttm_agp_tt_create(bdev, dev->agp->bridge, size,
464 page_flags, dummy_read); 465 page_flags, dummy_read);
465 } 466 }
467#endif
466 468
467 return nouveau_sgdma_create_ttm(bdev, size, page_flags, dummy_read); 469 return nouveau_sgdma_create_ttm(bdev, size, page_flags, dummy_read);
468} 470}
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c
index 0bf64c90aa20..5566172774df 100644
--- a/drivers/gpu/drm/nouveau/nouveau_pm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_pm.c
@@ -52,7 +52,7 @@ nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl,
52{ 52{
53 struct nouveau_drm *drm = nouveau_drm(dev); 53 struct nouveau_drm *drm = nouveau_drm(dev);
54 struct nouveau_pm *pm = nouveau_pm(dev); 54 struct nouveau_pm *pm = nouveau_pm(dev);
55 struct nouveau_therm *therm = nouveau_therm(drm); 55 struct nouveau_therm *therm = nouveau_therm(drm->device);
56 int ret; 56 int ret;
57 57
58 /*XXX: not on all boards, we should control based on temperature 58 /*XXX: not on all boards, we should control based on temperature
@@ -64,7 +64,6 @@ nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl,
64 ret = therm->fan_set(therm, perflvl->fanspeed); 64 ret = therm->fan_set(therm, perflvl->fanspeed);
65 if (ret && ret != -ENODEV) { 65 if (ret && ret != -ENODEV) {
66 NV_ERROR(drm, "fanspeed set failed: %d\n", ret); 66 NV_ERROR(drm, "fanspeed set failed: %d\n", ret);
67 return ret;
68 } 67 }
69 } 68 }
70 69
@@ -706,8 +705,7 @@ nouveau_hwmon_init(struct drm_device *dev)
706 struct device *hwmon_dev; 705 struct device *hwmon_dev;
707 int ret = 0; 706 int ret = 0;
708 707
709 if (!therm || !therm->temp_get || !therm->attr_get || 708 if (!therm || !therm->temp_get || !therm->attr_get || !therm->attr_set)
710 !therm->attr_set || therm->temp_get(therm) < 0)
711 return -ENODEV; 709 return -ENODEV;
712 710
713 hwmon_dev = hwmon_device_register(&dev->pdev->dev); 711 hwmon_dev = hwmon_device_register(&dev->pdev->dev);
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 96184d02c8d9..2e566e123e9e 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1690,10 +1690,10 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1690 } 1690 }
1691 /* all other cases */ 1691 /* all other cases */
1692 pll_in_use = radeon_get_pll_use_mask(crtc); 1692 pll_in_use = radeon_get_pll_use_mask(crtc);
1693 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1694 return ATOM_PPLL2;
1695 if (!(pll_in_use & (1 << ATOM_PPLL1))) 1693 if (!(pll_in_use & (1 << ATOM_PPLL1)))
1696 return ATOM_PPLL1; 1694 return ATOM_PPLL1;
1695 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1696 return ATOM_PPLL2;
1697 DRM_ERROR("unable to allocate a PPLL\n"); 1697 DRM_ERROR("unable to allocate a PPLL\n");
1698 return ATOM_PPLL_INVALID; 1698 return ATOM_PPLL_INVALID;
1699 } else { 1699 } else {
@@ -1715,10 +1715,10 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1715 } 1715 }
1716 /* all other cases */ 1716 /* all other cases */
1717 pll_in_use = radeon_get_pll_use_mask(crtc); 1717 pll_in_use = radeon_get_pll_use_mask(crtc);
1718 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1719 return ATOM_PPLL2;
1720 if (!(pll_in_use & (1 << ATOM_PPLL1))) 1718 if (!(pll_in_use & (1 << ATOM_PPLL1)))
1721 return ATOM_PPLL1; 1719 return ATOM_PPLL1;
1720 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1721 return ATOM_PPLL2;
1722 DRM_ERROR("unable to allocate a PPLL\n"); 1722 DRM_ERROR("unable to allocate a PPLL\n");
1723 return ATOM_PPLL_INVALID; 1723 return ATOM_PPLL_INVALID;
1724 } else { 1724 } else {
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index a1f49c5fd74b..14313ad43b76 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -3431,9 +3431,14 @@ void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
3431 if (!(mask & DRM_PCIE_SPEED_50)) 3431 if (!(mask & DRM_PCIE_SPEED_50))
3432 return; 3432 return;
3433 3433
3434 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3435 if (speed_cntl & LC_CURRENT_DATA_RATE) {
3436 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
3437 return;
3438 }
3439
3434 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n"); 3440 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
3435 3441
3436 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3437 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) || 3442 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
3438 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) { 3443 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
3439 3444
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index 8bcb554ea0c5..8c74c729586d 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -770,9 +770,13 @@ static int cayman_pcie_gart_enable(struct radeon_device *rdev)
770 WREG32(0x15DC, 0); 770 WREG32(0x15DC, 0);
771 771
772 /* empty context1-7 */ 772 /* empty context1-7 */
773 /* Assign the pt base to something valid for now; the pts used for
774 * the VMs are determined by the application and setup and assigned
775 * on the fly in the vm part of radeon_gart.c
776 */
773 for (i = 1; i < 8; i++) { 777 for (i = 1; i < 8; i++) {
774 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0); 778 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
775 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), 0); 779 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), rdev->vm_manager.max_pfn);
776 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2), 780 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
777 rdev->gart.table_addr >> 12); 781 rdev->gart.table_addr >> 12);
778 } 782 }
@@ -1572,12 +1576,6 @@ void cayman_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
1572 if (vm == NULL) 1576 if (vm == NULL)
1573 return; 1577 return;
1574 1578
1575 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (vm->id << 2), 0));
1576 radeon_ring_write(ring, 0);
1577
1578 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (vm->id << 2), 0));
1579 radeon_ring_write(ring, vm->last_pfn);
1580
1581 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0)); 1579 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0));
1582 radeon_ring_write(ring, vm->pd_gpu_addr >> 12); 1580 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
1583 1581
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 70c800ff6190..cda280d157da 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -3703,6 +3703,12 @@ static void r600_pcie_gen2_enable(struct radeon_device *rdev)
3703 if (!(mask & DRM_PCIE_SPEED_50)) 3703 if (!(mask & DRM_PCIE_SPEED_50))
3704 return; 3704 return;
3705 3705
3706 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
3707 if (speed_cntl & LC_CURRENT_DATA_RATE) {
3708 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
3709 return;
3710 }
3711
3706 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n"); 3712 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
3707 3713
3708 /* 55 nm r6xx asics */ 3714 /* 55 nm r6xx asics */
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index b04c06444d8b..8c42d54c2e26 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -663,9 +663,14 @@ struct radeon_vm {
663 struct list_head list; 663 struct list_head list;
664 struct list_head va; 664 struct list_head va;
665 unsigned id; 665 unsigned id;
666 unsigned last_pfn; 666
667 u64 pd_gpu_addr; 667 /* contains the page directory */
668 struct radeon_sa_bo *sa_bo; 668 struct radeon_sa_bo *page_directory;
669 uint64_t pd_gpu_addr;
670
671 /* array of page tables, one for each page directory entry */
672 struct radeon_sa_bo **page_tables;
673
669 struct mutex mutex; 674 struct mutex mutex;
670 /* last fence for cs using this vm */ 675 /* last fence for cs using this vm */
671 struct radeon_fence *fence; 676 struct radeon_fence *fence;
@@ -1843,9 +1848,10 @@ extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size
1843 */ 1848 */
1844int radeon_vm_manager_init(struct radeon_device *rdev); 1849int radeon_vm_manager_init(struct radeon_device *rdev);
1845void radeon_vm_manager_fini(struct radeon_device *rdev); 1850void radeon_vm_manager_fini(struct radeon_device *rdev);
1846int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm); 1851void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
1847void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm); 1852void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
1848int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm); 1853int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
1854void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
1849struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev, 1855struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
1850 struct radeon_vm *vm, int ring); 1856 struct radeon_vm *vm, int ring);
1851void radeon_vm_fence(struct radeon_device *rdev, 1857void radeon_vm_fence(struct radeon_device *rdev,
diff --git a/drivers/gpu/drm/radeon/radeon_acpi.c b/drivers/gpu/drm/radeon/radeon_acpi.c
index b0a5688c67f8..196d28d99570 100644
--- a/drivers/gpu/drm/radeon/radeon_acpi.c
+++ b/drivers/gpu/drm/radeon/radeon_acpi.c
@@ -201,7 +201,7 @@ static int radeon_atif_verify_interface(acpi_handle handle,
201 201
202 size = *(u16 *) info->buffer.pointer; 202 size = *(u16 *) info->buffer.pointer;
203 if (size < 12) { 203 if (size < 12) {
204 DRM_INFO("ATIF buffer is too small: %lu\n", size); 204 DRM_INFO("ATIF buffer is too small: %zu\n", size);
205 err = -EINVAL; 205 err = -EINVAL;
206 goto out; 206 goto out;
207 } 207 }
@@ -370,6 +370,7 @@ int radeon_atif_handler(struct radeon_device *rdev,
370 370
371 radeon_set_backlight_level(rdev, enc, req.backlight_level); 371 radeon_set_backlight_level(rdev, enc, req.backlight_level);
372 372
373#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
373 if (rdev->is_atom_bios) { 374 if (rdev->is_atom_bios) {
374 struct radeon_encoder_atom_dig *dig = enc->enc_priv; 375 struct radeon_encoder_atom_dig *dig = enc->enc_priv;
375 backlight_force_update(dig->bl_dev, 376 backlight_force_update(dig->bl_dev,
@@ -379,6 +380,7 @@ int radeon_atif_handler(struct radeon_device *rdev,
379 backlight_force_update(dig->bl_dev, 380 backlight_force_update(dig->bl_dev,
380 BACKLIGHT_UPDATE_HOTKEY); 381 BACKLIGHT_UPDATE_HOTKEY);
381 } 382 }
383#endif
382 } 384 }
383 } 385 }
384 /* TODO: check other events */ 386 /* TODO: check other events */
@@ -485,7 +487,7 @@ static int radeon_atcs_verify_interface(acpi_handle handle,
485 487
486 size = *(u16 *) info->buffer.pointer; 488 size = *(u16 *) info->buffer.pointer;
487 if (size < 8) { 489 if (size < 8) {
488 DRM_INFO("ATCS buffer is too small: %lu\n", size); 490 DRM_INFO("ATCS buffer is too small: %zu\n", size);
489 err = -EINVAL; 491 err = -EINVAL;
490 goto out; 492 goto out;
491 } 493 }
diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
index 582e99449c12..1aa3f910b993 100644
--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c
+++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
@@ -148,7 +148,7 @@ static int radeon_atpx_verify_interface(struct radeon_atpx *atpx)
148 148
149 size = *(u16 *) info->buffer.pointer; 149 size = *(u16 *) info->buffer.pointer;
150 if (size < 8) { 150 if (size < 8) {
151 printk("ATPX buffer is too small: %lu\n", size); 151 printk("ATPX buffer is too small: %zu\n", size);
152 err = -EINVAL; 152 err = -EINVAL;
153 goto out; 153 goto out;
154 } 154 }
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index cb7b7c062fef..41672cc563fb 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -478,6 +478,7 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
478 } 478 }
479 479
480out: 480out:
481 radeon_vm_add_to_lru(rdev, vm);
481 mutex_unlock(&vm->mutex); 482 mutex_unlock(&vm->mutex);
482 mutex_unlock(&rdev->vm_manager.lock); 483 mutex_unlock(&rdev->vm_manager.lock);
483 return r; 484 return r;
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index 64a42647f08a..bd13ca09eb62 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -1018,6 +1018,10 @@ int radeon_device_init(struct radeon_device *rdev,
1018 return r; 1018 return r;
1019 /* initialize vm here */ 1019 /* initialize vm here */
1020 mutex_init(&rdev->vm_manager.lock); 1020 mutex_init(&rdev->vm_manager.lock);
1021 /* Adjust VM size here.
1022 * Currently set to 4GB ((1 << 20) 4k pages).
1023 * Max GPUVM size for cayman and SI is 40 bits.
1024 */
1021 rdev->vm_manager.max_pfn = 1 << 20; 1025 rdev->vm_manager.max_pfn = 1 << 20;
1022 INIT_LIST_HEAD(&rdev->vm_manager.lru_vm); 1026 INIT_LIST_HEAD(&rdev->vm_manager.lru_vm);
1023 1027
diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
index f0c06d196b75..a7677dd1ce98 100644
--- a/drivers/gpu/drm/radeon/radeon_gart.c
+++ b/drivers/gpu/drm/radeon/radeon_gart.c
@@ -423,6 +423,18 @@ void radeon_gart_fini(struct radeon_device *rdev)
423 */ 423 */
424 424
425/** 425/**
426 * radeon_vm_num_pde - return the number of page directory entries
427 *
428 * @rdev: radeon_device pointer
429 *
430 * Calculate the number of page directory entries (cayman+).
431 */
432static unsigned radeon_vm_num_pdes(struct radeon_device *rdev)
433{
434 return rdev->vm_manager.max_pfn >> RADEON_VM_BLOCK_SIZE;
435}
436
437/**
426 * radeon_vm_directory_size - returns the size of the page directory in bytes 438 * radeon_vm_directory_size - returns the size of the page directory in bytes
427 * 439 *
428 * @rdev: radeon_device pointer 440 * @rdev: radeon_device pointer
@@ -431,7 +443,7 @@ void radeon_gart_fini(struct radeon_device *rdev)
431 */ 443 */
432static unsigned radeon_vm_directory_size(struct radeon_device *rdev) 444static unsigned radeon_vm_directory_size(struct radeon_device *rdev)
433{ 445{
434 return (rdev->vm_manager.max_pfn >> RADEON_VM_BLOCK_SIZE) * 8; 446 return RADEON_GPU_PAGE_ALIGN(radeon_vm_num_pdes(rdev) * 8);
435} 447}
436 448
437/** 449/**
@@ -451,11 +463,11 @@ int radeon_vm_manager_init(struct radeon_device *rdev)
451 463
452 if (!rdev->vm_manager.enabled) { 464 if (!rdev->vm_manager.enabled) {
453 /* allocate enough for 2 full VM pts */ 465 /* allocate enough for 2 full VM pts */
454 size = RADEON_GPU_PAGE_ALIGN(radeon_vm_directory_size(rdev)); 466 size = radeon_vm_directory_size(rdev);
455 size += RADEON_GPU_PAGE_ALIGN(rdev->vm_manager.max_pfn * 8); 467 size += rdev->vm_manager.max_pfn * 8;
456 size *= 2; 468 size *= 2;
457 r = radeon_sa_bo_manager_init(rdev, &rdev->vm_manager.sa_manager, 469 r = radeon_sa_bo_manager_init(rdev, &rdev->vm_manager.sa_manager,
458 size, 470 RADEON_GPU_PAGE_ALIGN(size),
459 RADEON_GEM_DOMAIN_VRAM); 471 RADEON_GEM_DOMAIN_VRAM);
460 if (r) { 472 if (r) {
461 dev_err(rdev->dev, "failed to allocate vm bo (%dKB)\n", 473 dev_err(rdev->dev, "failed to allocate vm bo (%dKB)\n",
@@ -476,7 +488,7 @@ int radeon_vm_manager_init(struct radeon_device *rdev)
476 488
477 /* restore page table */ 489 /* restore page table */
478 list_for_each_entry(vm, &rdev->vm_manager.lru_vm, list) { 490 list_for_each_entry(vm, &rdev->vm_manager.lru_vm, list) {
479 if (vm->sa_bo == NULL) 491 if (vm->page_directory == NULL)
480 continue; 492 continue;
481 493
482 list_for_each_entry(bo_va, &vm->va, vm_list) { 494 list_for_each_entry(bo_va, &vm->va, vm_list) {
@@ -500,16 +512,25 @@ static void radeon_vm_free_pt(struct radeon_device *rdev,
500 struct radeon_vm *vm) 512 struct radeon_vm *vm)
501{ 513{
502 struct radeon_bo_va *bo_va; 514 struct radeon_bo_va *bo_va;
515 int i;
503 516
504 if (!vm->sa_bo) 517 if (!vm->page_directory)
505 return; 518 return;
506 519
507 list_del_init(&vm->list); 520 list_del_init(&vm->list);
508 radeon_sa_bo_free(rdev, &vm->sa_bo, vm->fence); 521 radeon_sa_bo_free(rdev, &vm->page_directory, vm->fence);
509 522
510 list_for_each_entry(bo_va, &vm->va, vm_list) { 523 list_for_each_entry(bo_va, &vm->va, vm_list) {
511 bo_va->valid = false; 524 bo_va->valid = false;
512 } 525 }
526
527 if (vm->page_tables == NULL)
528 return;
529
530 for (i = 0; i < radeon_vm_num_pdes(rdev); i++)
531 radeon_sa_bo_free(rdev, &vm->page_tables[i], vm->fence);
532
533 kfree(vm->page_tables);
513} 534}
514 535
515/** 536/**
@@ -546,63 +567,106 @@ void radeon_vm_manager_fini(struct radeon_device *rdev)
546} 567}
547 568
548/** 569/**
570 * radeon_vm_evict - evict page table to make room for new one
571 *
572 * @rdev: radeon_device pointer
573 * @vm: VM we want to allocate something for
574 *
575 * Evict a VM from the lru, making sure that it isn't @vm. (cayman+).
576 * Returns 0 for success, -ENOMEM for failure.
577 *
578 * Global and local mutex must be locked!
579 */
580int radeon_vm_evict(struct radeon_device *rdev, struct radeon_vm *vm)
581{
582 struct radeon_vm *vm_evict;
583
584 if (list_empty(&rdev->vm_manager.lru_vm))
585 return -ENOMEM;
586
587 vm_evict = list_first_entry(&rdev->vm_manager.lru_vm,
588 struct radeon_vm, list);
589 if (vm_evict == vm)
590 return -ENOMEM;
591
592 mutex_lock(&vm_evict->mutex);
593 radeon_vm_free_pt(rdev, vm_evict);
594 mutex_unlock(&vm_evict->mutex);
595 return 0;
596}
597
598/**
549 * radeon_vm_alloc_pt - allocates a page table for a VM 599 * radeon_vm_alloc_pt - allocates a page table for a VM
550 * 600 *
551 * @rdev: radeon_device pointer 601 * @rdev: radeon_device pointer
552 * @vm: vm to bind 602 * @vm: vm to bind
553 * 603 *
554 * Allocate a page table for the requested vm (cayman+). 604 * Allocate a page table for the requested vm (cayman+).
555 * Also starts to populate the page table.
556 * Returns 0 for success, error for failure. 605 * Returns 0 for success, error for failure.
557 * 606 *
558 * Global and local mutex must be locked! 607 * Global and local mutex must be locked!
559 */ 608 */
560int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm) 609int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm)
561{ 610{
562 struct radeon_vm *vm_evict; 611 unsigned pd_size, pts_size;
563 int r;
564 u64 *pd_addr; 612 u64 *pd_addr;
565 int tables_size; 613 int r;
566 614
567 if (vm == NULL) { 615 if (vm == NULL) {
568 return -EINVAL; 616 return -EINVAL;
569 } 617 }
570 618
571 /* allocate enough to cover the current VM size */ 619 if (vm->page_directory != NULL) {
572 tables_size = RADEON_GPU_PAGE_ALIGN(radeon_vm_directory_size(rdev));
573 tables_size += RADEON_GPU_PAGE_ALIGN(vm->last_pfn * 8);
574
575 if (vm->sa_bo != NULL) {
576 /* update lru */
577 list_del_init(&vm->list);
578 list_add_tail(&vm->list, &rdev->vm_manager.lru_vm);
579 return 0; 620 return 0;
580 } 621 }
581 622
582retry: 623retry:
583 r = radeon_sa_bo_new(rdev, &rdev->vm_manager.sa_manager, &vm->sa_bo, 624 pd_size = RADEON_GPU_PAGE_ALIGN(radeon_vm_directory_size(rdev));
584 tables_size, RADEON_GPU_PAGE_SIZE, false); 625 r = radeon_sa_bo_new(rdev, &rdev->vm_manager.sa_manager,
626 &vm->page_directory, pd_size,
627 RADEON_GPU_PAGE_SIZE, false);
585 if (r == -ENOMEM) { 628 if (r == -ENOMEM) {
586 if (list_empty(&rdev->vm_manager.lru_vm)) { 629 r = radeon_vm_evict(rdev, vm);
630 if (r)
587 return r; 631 return r;
588 }
589 vm_evict = list_first_entry(&rdev->vm_manager.lru_vm, struct radeon_vm, list);
590 mutex_lock(&vm_evict->mutex);
591 radeon_vm_free_pt(rdev, vm_evict);
592 mutex_unlock(&vm_evict->mutex);
593 goto retry; 632 goto retry;
594 633
595 } else if (r) { 634 } else if (r) {
596 return r; 635 return r;
597 } 636 }
598 637
599 pd_addr = radeon_sa_bo_cpu_addr(vm->sa_bo); 638 vm->pd_gpu_addr = radeon_sa_bo_gpu_addr(vm->page_directory);
600 vm->pd_gpu_addr = radeon_sa_bo_gpu_addr(vm->sa_bo); 639
601 memset(pd_addr, 0, tables_size); 640 /* Initially clear the page directory */
641 pd_addr = radeon_sa_bo_cpu_addr(vm->page_directory);
642 memset(pd_addr, 0, pd_size);
643
644 pts_size = radeon_vm_num_pdes(rdev) * sizeof(struct radeon_sa_bo *);
645 vm->page_tables = kzalloc(pts_size, GFP_KERNEL);
646
647 if (vm->page_tables == NULL) {
648 DRM_ERROR("Cannot allocate memory for page table array\n");
649 radeon_sa_bo_free(rdev, &vm->page_directory, vm->fence);
650 return -ENOMEM;
651 }
652
653 return 0;
654}
602 655
656/**
657 * radeon_vm_add_to_lru - add VMs page table to LRU list
658 *
659 * @rdev: radeon_device pointer
660 * @vm: vm to add to LRU
661 *
662 * Add the allocated page table to the LRU list (cayman+).
663 *
664 * Global mutex must be locked!
665 */
666void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm)
667{
668 list_del_init(&vm->list);
603 list_add_tail(&vm->list, &rdev->vm_manager.lru_vm); 669 list_add_tail(&vm->list, &rdev->vm_manager.lru_vm);
604 return radeon_vm_bo_update_pte(rdev, vm, rdev->ring_tmp_bo.bo,
605 &rdev->ring_tmp_bo.bo->tbo.mem);
606} 670}
607 671
608/** 672/**
@@ -793,20 +857,6 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
793 } 857 }
794 858
795 mutex_lock(&vm->mutex); 859 mutex_lock(&vm->mutex);
796 if (last_pfn > vm->last_pfn) {
797 /* release mutex and lock in right order */
798 mutex_unlock(&vm->mutex);
799 mutex_lock(&rdev->vm_manager.lock);
800 mutex_lock(&vm->mutex);
801 /* and check again */
802 if (last_pfn > vm->last_pfn) {
803 /* grow va space 32M by 32M */
804 unsigned align = ((32 << 20) >> 12) - 1;
805 radeon_vm_free_pt(rdev, vm);
806 vm->last_pfn = (last_pfn + align) & ~align;
807 }
808 mutex_unlock(&rdev->vm_manager.lock);
809 }
810 head = &vm->va; 860 head = &vm->va;
811 last_offset = 0; 861 last_offset = 0;
812 list_for_each_entry(tmp, &vm->va, vm_list) { 862 list_for_each_entry(tmp, &vm->va, vm_list) {
@@ -865,6 +915,155 @@ uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr)
865} 915}
866 916
867/** 917/**
918 * radeon_vm_update_pdes - make sure that page directory is valid
919 *
920 * @rdev: radeon_device pointer
921 * @vm: requested vm
922 * @start: start of GPU address range
923 * @end: end of GPU address range
924 *
925 * Allocates new page tables if necessary
926 * and updates the page directory (cayman+).
927 * Returns 0 for success, error for failure.
928 *
929 * Global and local mutex must be locked!
930 */
931static int radeon_vm_update_pdes(struct radeon_device *rdev,
932 struct radeon_vm *vm,
933 uint64_t start, uint64_t end)
934{
935 static const uint32_t incr = RADEON_VM_PTE_COUNT * 8;
936
937 uint64_t last_pde = ~0, last_pt = ~0;
938 unsigned count = 0;
939 uint64_t pt_idx;
940 int r;
941
942 start = (start / RADEON_GPU_PAGE_SIZE) >> RADEON_VM_BLOCK_SIZE;
943 end = (end / RADEON_GPU_PAGE_SIZE) >> RADEON_VM_BLOCK_SIZE;
944
945 /* walk over the address space and update the page directory */
946 for (pt_idx = start; pt_idx <= end; ++pt_idx) {
947 uint64_t pde, pt;
948
949 if (vm->page_tables[pt_idx])
950 continue;
951
952retry:
953 r = radeon_sa_bo_new(rdev, &rdev->vm_manager.sa_manager,
954 &vm->page_tables[pt_idx],
955 RADEON_VM_PTE_COUNT * 8,
956 RADEON_GPU_PAGE_SIZE, false);
957
958 if (r == -ENOMEM) {
959 r = radeon_vm_evict(rdev, vm);
960 if (r)
961 return r;
962 goto retry;
963 } else if (r) {
964 return r;
965 }
966
967 pde = vm->pd_gpu_addr + pt_idx * 8;
968
969 pt = radeon_sa_bo_gpu_addr(vm->page_tables[pt_idx]);
970
971 if (((last_pde + 8 * count) != pde) ||
972 ((last_pt + incr * count) != pt)) {
973
974 if (count) {
975 radeon_asic_vm_set_page(rdev, last_pde,
976 last_pt, count, incr,
977 RADEON_VM_PAGE_VALID);
978 }
979
980 count = 1;
981 last_pde = pde;
982 last_pt = pt;
983 } else {
984 ++count;
985 }
986 }
987
988 if (count) {
989 radeon_asic_vm_set_page(rdev, last_pde, last_pt, count,
990 incr, RADEON_VM_PAGE_VALID);
991
992 }
993
994 return 0;
995}
996
997/**
998 * radeon_vm_update_ptes - make sure that page tables are valid
999 *
1000 * @rdev: radeon_device pointer
1001 * @vm: requested vm
1002 * @start: start of GPU address range
1003 * @end: end of GPU address range
1004 * @dst: destination address to map to
1005 * @flags: mapping flags
1006 *
1007 * Update the page tables in the range @start - @end (cayman+).
1008 *
1009 * Global and local mutex must be locked!
1010 */
1011static void radeon_vm_update_ptes(struct radeon_device *rdev,
1012 struct radeon_vm *vm,
1013 uint64_t start, uint64_t end,
1014 uint64_t dst, uint32_t flags)
1015{
1016 static const uint64_t mask = RADEON_VM_PTE_COUNT - 1;
1017
1018 uint64_t last_pte = ~0, last_dst = ~0;
1019 unsigned count = 0;
1020 uint64_t addr;
1021
1022 start = start / RADEON_GPU_PAGE_SIZE;
1023 end = end / RADEON_GPU_PAGE_SIZE;
1024
1025 /* walk over the address space and update the page tables */
1026 for (addr = start; addr < end; ) {
1027 uint64_t pt_idx = addr >> RADEON_VM_BLOCK_SIZE;
1028 unsigned nptes;
1029 uint64_t pte;
1030
1031 if ((addr & ~mask) == (end & ~mask))
1032 nptes = end - addr;
1033 else
1034 nptes = RADEON_VM_PTE_COUNT - (addr & mask);
1035
1036 pte = radeon_sa_bo_gpu_addr(vm->page_tables[pt_idx]);
1037 pte += (addr & mask) * 8;
1038
1039 if (((last_pte + 8 * count) != pte) ||
1040 ((count + nptes) > 1 << 11)) {
1041
1042 if (count) {
1043 radeon_asic_vm_set_page(rdev, last_pte,
1044 last_dst, count,
1045 RADEON_GPU_PAGE_SIZE,
1046 flags);
1047 }
1048
1049 count = nptes;
1050 last_pte = pte;
1051 last_dst = dst;
1052 } else {
1053 count += nptes;
1054 }
1055
1056 addr += nptes;
1057 dst += nptes * RADEON_GPU_PAGE_SIZE;
1058 }
1059
1060 if (count) {
1061 radeon_asic_vm_set_page(rdev, last_pte, last_dst, count,
1062 RADEON_GPU_PAGE_SIZE, flags);
1063 }
1064}
1065
1066/**
868 * radeon_vm_bo_update_pte - map a bo into the vm page table 1067 * radeon_vm_bo_update_pte - map a bo into the vm page table
869 * 1068 *
870 * @rdev: radeon_device pointer 1069 * @rdev: radeon_device pointer
@@ -887,12 +1086,11 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
887 struct radeon_semaphore *sem = NULL; 1086 struct radeon_semaphore *sem = NULL;
888 struct radeon_bo_va *bo_va; 1087 struct radeon_bo_va *bo_va;
889 unsigned nptes, npdes, ndw; 1088 unsigned nptes, npdes, ndw;
890 uint64_t pe, addr; 1089 uint64_t addr;
891 uint64_t pfn;
892 int r; 1090 int r;
893 1091
894 /* nothing to do if vm isn't bound */ 1092 /* nothing to do if vm isn't bound */
895 if (vm->sa_bo == NULL) 1093 if (vm->page_directory == NULL)
896 return 0; 1094 return 0;
897 1095
898 bo_va = radeon_vm_bo_find(vm, bo); 1096 bo_va = radeon_vm_bo_find(vm, bo);
@@ -939,25 +1137,29 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
939 } 1137 }
940 } 1138 }
941 1139
942 /* estimate number of dw needed */
943 /* reserve space for 32-bit padding */
944 ndw = 32;
945
946 nptes = radeon_bo_ngpu_pages(bo); 1140 nptes = radeon_bo_ngpu_pages(bo);
947 1141
948 pfn = (bo_va->soffset / RADEON_GPU_PAGE_SIZE); 1142 /* assume two extra pdes in case the mapping overlaps the borders */
1143 npdes = (nptes >> RADEON_VM_BLOCK_SIZE) + 2;
949 1144
950 /* handle cases where a bo spans several pdes */ 1145 /* estimate number of dw needed */
951 npdes = (ALIGN(pfn + nptes, RADEON_VM_PTE_COUNT) - 1146 /* semaphore, fence and padding */
952 (pfn & ~(RADEON_VM_PTE_COUNT - 1))) >> RADEON_VM_BLOCK_SIZE; 1147 ndw = 32;
1148
1149 if (RADEON_VM_BLOCK_SIZE > 11)
1150 /* reserve space for one header for every 2k dwords */
1151 ndw += (nptes >> 11) * 3;
1152 else
1153 /* reserve space for one header for
1154 every (1 << BLOCK_SIZE) entries */
1155 ndw += (nptes >> RADEON_VM_BLOCK_SIZE) * 3;
953 1156
954 /* reserve space for one header for every 2k dwords */
955 ndw += (nptes >> 11) * 3;
956 /* reserve space for pte addresses */ 1157 /* reserve space for pte addresses */
957 ndw += nptes * 2; 1158 ndw += nptes * 2;
958 1159
959 /* reserve space for one header for every 2k dwords */ 1160 /* reserve space for one header for every 2k dwords */
960 ndw += (npdes >> 11) * 3; 1161 ndw += (npdes >> 11) * 3;
1162
961 /* reserve space for pde addresses */ 1163 /* reserve space for pde addresses */
962 ndw += npdes * 2; 1164 ndw += npdes * 2;
963 1165
@@ -971,22 +1173,14 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
971 radeon_fence_note_sync(vm->fence, ridx); 1173 radeon_fence_note_sync(vm->fence, ridx);
972 } 1174 }
973 1175
974 /* update page table entries */ 1176 r = radeon_vm_update_pdes(rdev, vm, bo_va->soffset, bo_va->eoffset);
975 pe = vm->pd_gpu_addr; 1177 if (r) {
976 pe += radeon_vm_directory_size(rdev); 1178 radeon_ring_unlock_undo(rdev, ring);
977 pe += (bo_va->soffset / RADEON_GPU_PAGE_SIZE) * 8; 1179 return r;
978 1180 }
979 radeon_asic_vm_set_page(rdev, pe, addr, nptes,
980 RADEON_GPU_PAGE_SIZE, bo_va->flags);
981
982 /* update page directory entries */
983 addr = pe;
984
985 pe = vm->pd_gpu_addr;
986 pe += ((bo_va->soffset / RADEON_GPU_PAGE_SIZE) >> RADEON_VM_BLOCK_SIZE) * 8;
987 1181
988 radeon_asic_vm_set_page(rdev, pe, addr, npdes, 1182 radeon_vm_update_ptes(rdev, vm, bo_va->soffset, bo_va->eoffset,
989 RADEON_VM_PTE_COUNT * 8, RADEON_VM_PAGE_VALID); 1183 addr, bo_va->flags);
990 1184
991 radeon_fence_unref(&vm->fence); 1185 radeon_fence_unref(&vm->fence);
992 r = radeon_fence_emit(rdev, &vm->fence, ridx); 1186 r = radeon_fence_emit(rdev, &vm->fence, ridx);
@@ -997,6 +1191,7 @@ int radeon_vm_bo_update_pte(struct radeon_device *rdev,
997 radeon_ring_unlock_commit(rdev, ring); 1191 radeon_ring_unlock_commit(rdev, ring);
998 radeon_semaphore_free(rdev, &sem, vm->fence); 1192 radeon_semaphore_free(rdev, &sem, vm->fence);
999 radeon_fence_unref(&vm->last_flush); 1193 radeon_fence_unref(&vm->last_flush);
1194
1000 return 0; 1195 return 0;
1001} 1196}
1002 1197
@@ -1056,31 +1251,15 @@ void radeon_vm_bo_invalidate(struct radeon_device *rdev,
1056 * @rdev: radeon_device pointer 1251 * @rdev: radeon_device pointer
1057 * @vm: requested vm 1252 * @vm: requested vm
1058 * 1253 *
1059 * Init @vm (cayman+). 1254 * Init @vm fields (cayman+).
1060 * Map the IB pool and any other shared objects into the VM
1061 * by default as it's used by all VMs.
1062 * Returns 0 for success, error for failure.
1063 */ 1255 */
1064int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm) 1256void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
1065{ 1257{
1066 struct radeon_bo_va *bo_va;
1067 int r;
1068
1069 vm->id = 0; 1258 vm->id = 0;
1070 vm->fence = NULL; 1259 vm->fence = NULL;
1071 vm->last_pfn = 0;
1072 mutex_init(&vm->mutex); 1260 mutex_init(&vm->mutex);
1073 INIT_LIST_HEAD(&vm->list); 1261 INIT_LIST_HEAD(&vm->list);
1074 INIT_LIST_HEAD(&vm->va); 1262 INIT_LIST_HEAD(&vm->va);
1075
1076 /* map the ib pool buffer at 0 in virtual address space, set
1077 * read only
1078 */
1079 bo_va = radeon_vm_bo_add(rdev, vm, rdev->ring_tmp_bo.bo);
1080 r = radeon_vm_bo_set_addr(rdev, bo_va, RADEON_VA_IB_OFFSET,
1081 RADEON_VM_PAGE_READABLE |
1082 RADEON_VM_PAGE_SNOOPED);
1083 return r;
1084} 1263}
1085 1264
1086/** 1265/**
@@ -1102,17 +1281,6 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm)
1102 radeon_vm_free_pt(rdev, vm); 1281 radeon_vm_free_pt(rdev, vm);
1103 mutex_unlock(&rdev->vm_manager.lock); 1282 mutex_unlock(&rdev->vm_manager.lock);
1104 1283
1105 /* remove all bo at this point non are busy any more because unbind
1106 * waited for the last vm fence to signal
1107 */
1108 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
1109 if (!r) {
1110 bo_va = radeon_vm_bo_find(vm, rdev->ring_tmp_bo.bo);
1111 list_del_init(&bo_va->bo_list);
1112 list_del_init(&bo_va->vm_list);
1113 radeon_bo_unreserve(rdev->ring_tmp_bo.bo);
1114 kfree(bo_va);
1115 }
1116 if (!list_empty(&vm->va)) { 1284 if (!list_empty(&vm->va)) {
1117 dev_err(rdev->dev, "still active bo inside vm\n"); 1285 dev_err(rdev->dev, "still active bo inside vm\n");
1118 } 1286 }
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 83b8d8aa71c0..dc781c49b96b 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -419,6 +419,7 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
419 /* new gpu have virtual address space support */ 419 /* new gpu have virtual address space support */
420 if (rdev->family >= CHIP_CAYMAN) { 420 if (rdev->family >= CHIP_CAYMAN) {
421 struct radeon_fpriv *fpriv; 421 struct radeon_fpriv *fpriv;
422 struct radeon_bo_va *bo_va;
422 int r; 423 int r;
423 424
424 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); 425 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
@@ -426,7 +427,15 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
426 return -ENOMEM; 427 return -ENOMEM;
427 } 428 }
428 429
429 r = radeon_vm_init(rdev, &fpriv->vm); 430 radeon_vm_init(rdev, &fpriv->vm);
431
432 /* map the ib pool buffer read only into
433 * virtual address space */
434 bo_va = radeon_vm_bo_add(rdev, &fpriv->vm,
435 rdev->ring_tmp_bo.bo);
436 r = radeon_vm_bo_set_addr(rdev, bo_va, RADEON_VA_IB_OFFSET,
437 RADEON_VM_PAGE_READABLE |
438 RADEON_VM_PAGE_SNOOPED);
430 if (r) { 439 if (r) {
431 radeon_vm_fini(rdev, &fpriv->vm); 440 radeon_vm_fini(rdev, &fpriv->vm);
432 kfree(fpriv); 441 kfree(fpriv);
@@ -454,6 +463,17 @@ void radeon_driver_postclose_kms(struct drm_device *dev,
454 /* new gpu have virtual address space support */ 463 /* new gpu have virtual address space support */
455 if (rdev->family >= CHIP_CAYMAN && file_priv->driver_priv) { 464 if (rdev->family >= CHIP_CAYMAN && file_priv->driver_priv) {
456 struct radeon_fpriv *fpriv = file_priv->driver_priv; 465 struct radeon_fpriv *fpriv = file_priv->driver_priv;
466 struct radeon_bo_va *bo_va;
467 int r;
468
469 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
470 if (!r) {
471 bo_va = radeon_vm_bo_find(&fpriv->vm,
472 rdev->ring_tmp_bo.bo);
473 if (bo_va)
474 radeon_vm_bo_rmv(rdev, bo_va);
475 radeon_bo_unreserve(rdev->ring_tmp_bo.bo);
476 }
457 477
458 radeon_vm_fini(rdev, &fpriv->vm); 478 radeon_vm_fini(rdev, &fpriv->vm);
459 kfree(fpriv); 479 kfree(fpriv);
diff --git a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
index 92487e614778..a13ad9d707cf 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_encoders.c
@@ -269,27 +269,6 @@ static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
269 .disable = radeon_legacy_encoder_disable, 269 .disable = radeon_legacy_encoder_disable,
270}; 270};
271 271
272#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
273
274static uint8_t radeon_legacy_lvds_level(struct backlight_device *bd)
275{
276 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
277 uint8_t level;
278
279 /* Convert brightness to hardware level */
280 if (bd->props.brightness < 0)
281 level = 0;
282 else if (bd->props.brightness > RADEON_MAX_BL_LEVEL)
283 level = RADEON_MAX_BL_LEVEL;
284 else
285 level = bd->props.brightness;
286
287 if (pdata->negative)
288 level = RADEON_MAX_BL_LEVEL - level;
289
290 return level;
291}
292
293u8 272u8
294radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder) 273radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder)
295{ 274{
@@ -331,6 +310,27 @@ radeon_legacy_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 leve
331 radeon_legacy_lvds_update(&radeon_encoder->base, dpms_mode); 310 radeon_legacy_lvds_update(&radeon_encoder->base, dpms_mode);
332} 311}
333 312
313#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
314
315static uint8_t radeon_legacy_lvds_level(struct backlight_device *bd)
316{
317 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
318 uint8_t level;
319
320 /* Convert brightness to hardware level */
321 if (bd->props.brightness < 0)
322 level = 0;
323 else if (bd->props.brightness > RADEON_MAX_BL_LEVEL)
324 level = RADEON_MAX_BL_LEVEL;
325 else
326 level = bd->props.brightness;
327
328 if (pdata->negative)
329 level = RADEON_MAX_BL_LEVEL - level;
330
331 return level;
332}
333
334static int radeon_legacy_backlight_update_status(struct backlight_device *bd) 334static int radeon_legacy_backlight_update_status(struct backlight_device *bd)
335{ 335{
336 struct radeon_backlight_privdata *pdata = bl_get_data(bd); 336 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
@@ -991,11 +991,7 @@ static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
991static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder) 991static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder)
992{ 992{
993 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 993 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
994 struct radeon_encoder_ext_tmds *tmds = radeon_encoder->enc_priv; 994 /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */
995 if (tmds) {
996 if (tmds->i2c_bus)
997 radeon_i2c_destroy(tmds->i2c_bus);
998 }
999 kfree(radeon_encoder->enc_priv); 995 kfree(radeon_encoder->enc_priv);
1000 drm_encoder_cleanup(encoder); 996 drm_encoder_cleanup(encoder);
1001 kfree(radeon_encoder); 997 kfree(radeon_encoder);
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index bba66902c83b..47634f27f2e5 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -305,7 +305,7 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
305{ 305{
306#if DRM_DEBUG_CODE 306#if DRM_DEBUG_CODE
307 if (ring->count_dw <= 0) { 307 if (ring->count_dw <= 0) {
308 DRM_ERROR("radeon: writting more dword to ring than expected !\n"); 308 DRM_ERROR("radeon: writing more dwords to the ring than expected!\n");
309 } 309 }
310#endif 310#endif
311 ring->ring[ring->wptr++] = v; 311 ring->ring[ring->wptr++] = v;
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index f79633a036c3..df8dd7701643 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -2407,12 +2407,13 @@ static int si_pcie_gart_enable(struct radeon_device *rdev)
2407 WREG32(0x15DC, 0); 2407 WREG32(0x15DC, 0);
2408 2408
2409 /* empty context1-15 */ 2409 /* empty context1-15 */
2410 /* FIXME start with 4G, once using 2 level pt switch to full
2411 * vm size space
2412 */
2413 /* set vm size, must be a multiple of 4 */ 2410 /* set vm size, must be a multiple of 4 */
2414 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0); 2411 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
2415 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn); 2412 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
2413 /* Assign the pt base to something valid for now; the pts used for
2414 * the VMs are determined by the application and setup and assigned
2415 * on the fly in the vm part of radeon_gart.c
2416 */
2416 for (i = 1; i < 16; i++) { 2417 for (i = 1; i < 16; i++) {
2417 if (i < 8) 2418 if (i < 8)
2418 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2), 2419 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 984a3f13923b..47b8d84b489d 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -205,8 +205,11 @@ static const struct tjmax __cpuinitconst tjmax_table[] = {
205 { "CPU N455", 100000 }, 205 { "CPU N455", 100000 },
206 { "CPU N470", 100000 }, 206 { "CPU N470", 100000 },
207 { "CPU N475", 100000 }, 207 { "CPU N475", 100000 },
208 { "CPU 230", 100000 }, 208 { "CPU 230", 100000 }, /* Model 0x1c, stepping 2 */
209 { "CPU 330", 125000 }, 209 { "CPU 330", 125000 }, /* Model 0x1c, stepping 2 */
210 { "CPU CE4110", 110000 }, /* Model 0x1c, stepping 10 */
211 { "CPU CE4150", 110000 }, /* Model 0x1c, stepping 10 */
212 { "CPU CE4170", 110000 }, /* Model 0x1c, stepping 10 */
210}; 213};
211 214
212static int __cpuinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, 215static int __cpuinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id,
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 2ca6a5a4f5a7..60745a535821 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -4,7 +4,7 @@
4 4
5menuconfig PMBUS 5menuconfig PMBUS
6 tristate "PMBus support" 6 tristate "PMBus support"
7 depends on I2C && EXPERIMENTAL 7 depends on I2C
8 default n 8 default n
9 help 9 help
10 Say yes here if you want to enable PMBus support. 10 Say yes here if you want to enable PMBus support.
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index dd13e3a4c272..4ef0d80b57f4 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -163,19 +163,21 @@ source "drivers/media/common/Kconfig"
163# 163#
164 164
165config MEDIA_SUBDRV_AUTOSELECT 165config MEDIA_SUBDRV_AUTOSELECT
166 bool "Autoselect analog and hybrid tuner modules to build" 166 bool "Autoselect tuners and i2c modules to build"
167 depends on MEDIA_TUNER 167 depends on MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT || MEDIA_CAMERA_SUPPORT
168 default y 168 default y
169 help 169 help
170 By default, a TV driver auto-selects all possible tuners 170 By default, a media driver auto-selects all possible i2c
171 thar could be used by the driver. 171 devices that are used by any of the supported devices.
172 172
173 This is generally the right thing to do, except when there 173 This is generally the right thing to do, except when there
174 are strict constraints with regards to the kernel size. 174 are strict constraints with regards to the kernel size,
175 like on embedded systems.
175 176
176 Use this option with care, as deselecting tuner drivers which 177 Use this option with care, as deselecting ancillary drivers which
177 are in fact necessary will result in TV devices which cannot 178 are, in fact, necessary will result in the lack of the needed
178 be tuned due to lack of the tuning driver. 179 functionality for your device (it may not tune or may not have
180 the need demodulers).
179 181
180 If unsure say Y. 182 If unsure say Y.
181 183
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b721902bb6b4..b2530b002125 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1519,7 +1519,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1519 /* no need to lock since we're protected by rtnl_lock */ 1519 /* no need to lock since we're protected by rtnl_lock */
1520 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { 1520 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
1521 pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name); 1521 pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
1522 if (bond_vlan_used(bond)) { 1522 if (vlan_uses_dev(bond_dev)) {
1523 pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n", 1523 pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n",
1524 bond_dev->name, slave_dev->name, bond_dev->name); 1524 bond_dev->name, slave_dev->name, bond_dev->name);
1525 return -EPERM; 1525 return -EPERM;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 24220992413f..4833b6a9031c 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -2957,9 +2957,13 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
2957 skb_shinfo(skb)->nr_frags + 2957 skb_shinfo(skb)->nr_frags +
2958 BDS_PER_TX_PKT + 2958 BDS_PER_TX_PKT +
2959 NEXT_CNT_PER_TX_PKT(MAX_BDS_PER_TX_PKT))) { 2959 NEXT_CNT_PER_TX_PKT(MAX_BDS_PER_TX_PKT))) {
2960 bnx2x_fp_qstats(bp, txdata->parent_fp)->driver_xoff++; 2960 /* Handle special storage cases separately */
2961 netif_tx_stop_queue(txq); 2961 if (txdata->tx_ring_size != 0) {
2962 BNX2X_ERR("BUG! Tx ring full when queue awake!\n"); 2962 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
2963 bnx2x_fp_qstats(bp, txdata->parent_fp)->driver_xoff++;
2964 netif_tx_stop_queue(txq);
2965 }
2966
2963 return NETDEV_TX_BUSY; 2967 return NETDEV_TX_BUSY;
2964 } 2968 }
2965 2969
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
index 71971a161bd1..614981c02264 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
@@ -126,7 +126,7 @@ static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
126 /* Check if this request is ok */ 126 /* Check if this request is ok */
127 rc = o->validate(bp, o->owner, elem); 127 rc = o->validate(bp, o->owner, elem);
128 if (rc) { 128 if (rc) {
129 BNX2X_ERR("Preamble failed: %d\n", rc); 129 DP(BNX2X_MSG_SP, "Preamble failed: %d\n", rc);
130 goto free_and_exit; 130 goto free_and_exit;
131 } 131 }
132 } 132 }
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 72e496f1e9b0..0125524c08c4 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -37,9 +37,9 @@ struct of_bus {
37 int (*match)(struct device_node *parent); 37 int (*match)(struct device_node *parent);
38 void (*count_cells)(struct device_node *child, 38 void (*count_cells)(struct device_node *child,
39 int *addrc, int *sizec); 39 int *addrc, int *sizec);
40 u64 (*map)(u32 *addr, const __be32 *range, 40 u64 (*map)(__be32 *addr, const __be32 *range,
41 int na, int ns, int pna); 41 int na, int ns, int pna);
42 int (*translate)(u32 *addr, u64 offset, int na); 42 int (*translate)(__be32 *addr, u64 offset, int na);
43 unsigned int (*get_flags)(const __be32 *addr); 43 unsigned int (*get_flags)(const __be32 *addr);
44}; 44};
45 45
@@ -56,7 +56,7 @@ static void of_bus_default_count_cells(struct device_node *dev,
56 *sizec = of_n_size_cells(dev); 56 *sizec = of_n_size_cells(dev);
57} 57}
58 58
59static u64 of_bus_default_map(u32 *addr, const __be32 *range, 59static u64 of_bus_default_map(__be32 *addr, const __be32 *range,
60 int na, int ns, int pna) 60 int na, int ns, int pna)
61{ 61{
62 u64 cp, s, da; 62 u64 cp, s, da;
@@ -82,7 +82,7 @@ static u64 of_bus_default_map(u32 *addr, const __be32 *range,
82 return da - cp; 82 return da - cp;
83} 83}
84 84
85static int of_bus_default_translate(u32 *addr, u64 offset, int na) 85static int of_bus_default_translate(__be32 *addr, u64 offset, int na)
86{ 86{
87 u64 a = of_read_number(addr, na); 87 u64 a = of_read_number(addr, na);
88 memset(addr, 0, na * 4); 88 memset(addr, 0, na * 4);
@@ -138,7 +138,7 @@ static unsigned int of_bus_pci_get_flags(const __be32 *addr)
138 return flags; 138 return flags;
139} 139}
140 140
141static u64 of_bus_pci_map(u32 *addr, const __be32 *range, int na, int ns, 141static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns,
142 int pna) 142 int pna)
143{ 143{
144 u64 cp, s, da; 144 u64 cp, s, da;
@@ -165,7 +165,7 @@ static u64 of_bus_pci_map(u32 *addr, const __be32 *range, int na, int ns,
165 return da - cp; 165 return da - cp;
166} 166}
167 167
168static int of_bus_pci_translate(u32 *addr, u64 offset, int na) 168static int of_bus_pci_translate(__be32 *addr, u64 offset, int na)
169{ 169{
170 return of_bus_default_translate(addr + 1, offset, na - 1); 170 return of_bus_default_translate(addr + 1, offset, na - 1);
171} 171}
@@ -247,7 +247,7 @@ static void of_bus_isa_count_cells(struct device_node *child,
247 *sizec = 1; 247 *sizec = 1;
248} 248}
249 249
250static u64 of_bus_isa_map(u32 *addr, const __be32 *range, int na, int ns, 250static u64 of_bus_isa_map(__be32 *addr, const __be32 *range, int na, int ns,
251 int pna) 251 int pna)
252{ 252{
253 u64 cp, s, da; 253 u64 cp, s, da;
@@ -270,7 +270,7 @@ static u64 of_bus_isa_map(u32 *addr, const __be32 *range, int na, int ns,
270 return da - cp; 270 return da - cp;
271} 271}
272 272
273static int of_bus_isa_translate(u32 *addr, u64 offset, int na) 273static int of_bus_isa_translate(__be32 *addr, u64 offset, int na)
274{ 274{
275 return of_bus_default_translate(addr + 1, offset, na - 1); 275 return of_bus_default_translate(addr + 1, offset, na - 1);
276} 276}
@@ -338,7 +338,7 @@ static struct of_bus *of_match_bus(struct device_node *np)
338} 338}
339 339
340static int of_translate_one(struct device_node *parent, struct of_bus *bus, 340static int of_translate_one(struct device_node *parent, struct of_bus *bus,
341 struct of_bus *pbus, u32 *addr, 341 struct of_bus *pbus, __be32 *addr,
342 int na, int ns, int pna, const char *rprop) 342 int na, int ns, int pna, const char *rprop)
343{ 343{
344 const __be32 *ranges; 344 const __be32 *ranges;
@@ -409,12 +409,12 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
409 * that can be mapped to a cpu physical address). This is not really specified 409 * that can be mapped to a cpu physical address). This is not really specified
410 * that way, but this is traditionally the way IBM at least do things 410 * that way, but this is traditionally the way IBM at least do things
411 */ 411 */
412u64 __of_translate_address(struct device_node *dev, const __be32 *in_addr, 412static u64 __of_translate_address(struct device_node *dev,
413 const char *rprop) 413 const __be32 *in_addr, const char *rprop)
414{ 414{
415 struct device_node *parent = NULL; 415 struct device_node *parent = NULL;
416 struct of_bus *bus, *pbus; 416 struct of_bus *bus, *pbus;
417 u32 addr[OF_MAX_ADDR_CELLS]; 417 __be32 addr[OF_MAX_ADDR_CELLS];
418 int na, ns, pna, pns; 418 int na, ns, pna, pns;
419 u64 result = OF_BAD_ADDR; 419 u64 result = OF_BAD_ADDR;
420 420
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index a23ec7779997..a3c1c5aae6a9 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -192,11 +192,13 @@ int of_irq_map_raw(struct device_node *parent, const __be32 *intspec,
192 /* Compare specifiers */ 192 /* Compare specifiers */
193 match = 1; 193 match = 1;
194 for (i = 0; i < addrsize && match; ++i) { 194 for (i = 0; i < addrsize && match; ++i) {
195 u32 mask = imask ? imask[i] : 0xffffffffu; 195 __be32 mask = imask ? imask[i]
196 : cpu_to_be32(0xffffffffu);
196 match = ((addr[i] ^ imap[i]) & mask) == 0; 197 match = ((addr[i] ^ imap[i]) & mask) == 0;
197 } 198 }
198 for (; i < (addrsize + intsize) && match; ++i) { 199 for (; i < (addrsize + intsize) && match; ++i) {
199 u32 mask = imask ? imask[i] : 0xffffffffu; 200 __be32 mask = imask ? imask[i]
201 : cpu_to_be32(0xffffffffu);
200 match = 202 match =
201 ((intspec[i-addrsize] ^ imap[i]) & mask) == 0; 203 ((intspec[i-addrsize] ^ imap[i]) & mask) == 0;
202 } 204 }
@@ -465,7 +467,7 @@ void __init of_irq_init(const struct of_device_id *matches)
465 pr_debug("of_irq_init: init %s @ %p, parent %p\n", 467 pr_debug("of_irq_init: init %s @ %p, parent %p\n",
466 match->compatible, 468 match->compatible,
467 desc->dev, desc->interrupt_parent); 469 desc->dev, desc->interrupt_parent);
468 irq_init_cb = match->data; 470 irq_init_cb = (of_irq_init_cb_t)match->data;
469 ret = irq_init_cb(desc->dev, desc->interrupt_parent); 471 ret = irq_init_cb(desc->dev, desc->interrupt_parent);
470 if (ret) { 472 if (ret) {
471 kfree(desc); 473 kfree(desc);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 9bdeaf30b17d..b80891b43816 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -76,7 +76,7 @@ void of_device_make_bus_id(struct device *dev)
76{ 76{
77 static atomic_t bus_no_reg_magic; 77 static atomic_t bus_no_reg_magic;
78 struct device_node *node = dev->of_node; 78 struct device_node *node = dev->of_node;
79 const u32 *reg; 79 const __be32 *reg;
80 u64 addr; 80 u64 addr;
81 const __be32 *addrp; 81 const __be32 *addrp;
82 int magic; 82 int magic;
diff --git a/drivers/pcmcia/pxa2xx_sharpsl.c b/drivers/pcmcia/pxa2xx_sharpsl.c
index b066273b6b4f..7dd879ce514d 100644
--- a/drivers/pcmcia/pxa2xx_sharpsl.c
+++ b/drivers/pcmcia/pxa2xx_sharpsl.c
@@ -194,7 +194,7 @@ static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
194 sharpsl_pcmcia_init_reset(skt); 194 sharpsl_pcmcia_init_reset(skt);
195} 195}
196 196
197static struct pcmcia_low_level sharpsl_pcmcia_ops __initdata = { 197static struct pcmcia_low_level sharpsl_pcmcia_ops = {
198 .owner = THIS_MODULE, 198 .owner = THIS_MODULE,
199 .hw_init = sharpsl_pcmcia_hw_init, 199 .hw_init = sharpsl_pcmcia_hw_init,
200 .socket_state = sharpsl_pcmcia_socket_state, 200 .socket_state = sharpsl_pcmcia_socket_state,
diff --git a/drivers/pinctrl/pinctrl-bcm2835.c b/drivers/pinctrl/pinctrl-bcm2835.c
index a4adee633fa9..7e9be18ec2d2 100644
--- a/drivers/pinctrl/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/pinctrl-bcm2835.c
@@ -29,7 +29,6 @@
29#include <linux/irq.h> 29#include <linux/irq.h>
30#include <linux/irqdesc.h> 30#include <linux/irqdesc.h>
31#include <linux/irqdomain.h> 31#include <linux/irqdomain.h>
32#include <linux/irq.h>
33#include <linux/module.h> 32#include <linux/module.h>
34#include <linux/of_address.h> 33#include <linux/of_address.h>
35#include <linux/of.h> 34#include <linux/of.h>
@@ -960,7 +959,7 @@ static int __devinit bcm2835_pinctrl_probe(struct platform_device *pdev)
960 return err; 959 return err;
961 } 960 }
962 961
963 pc->base = devm_request_and_ioremap(&pdev->dev, &iomem); 962 pc->base = devm_request_and_ioremap(dev, &iomem);
964 if (!pc->base) 963 if (!pc->base)
965 return -EADDRNOTAVAIL; 964 return -EADDRNOTAVAIL;
966 965
@@ -1032,7 +1031,7 @@ static int __devinit bcm2835_pinctrl_probe(struct platform_device *pdev)
1032 pc->pctl_dev = pinctrl_register(&bcm2835_pinctrl_desc, dev, pc); 1031 pc->pctl_dev = pinctrl_register(&bcm2835_pinctrl_desc, dev, pc);
1033 if (!pc->pctl_dev) { 1032 if (!pc->pctl_dev) {
1034 gpiochip_remove(&pc->gpio_chip); 1033 gpiochip_remove(&pc->gpio_chip);
1035 return PTR_ERR(pc->pctl_dev); 1034 return -EINVAL;
1036 } 1035 }
1037 1036
1038 pc->gpio_range = bcm2835_pinctrl_gpio_range; 1037 pc->gpio_range = bcm2835_pinctrl_gpio_range;
diff --git a/drivers/pinctrl/pinctrl-nomadik.c b/drivers/pinctrl/pinctrl-nomadik.c
index fec9c30133d4..01aea1c3b5fa 100644
--- a/drivers/pinctrl/pinctrl-nomadik.c
+++ b/drivers/pinctrl/pinctrl-nomadik.c
@@ -30,7 +30,20 @@
30#include <linux/pinctrl/pinconf.h> 30#include <linux/pinctrl/pinconf.h>
31/* Since we request GPIOs from ourself */ 31/* Since we request GPIOs from ourself */
32#include <linux/pinctrl/consumer.h> 32#include <linux/pinctrl/consumer.h>
33/*
34 * For the U8500 archs, use the PRCMU register interface, for the older
35 * Nomadik, provide some stubs. The functions using these will only be
36 * called on the U8500 series.
37 */
38#ifdef CONFIG_ARCH_U8500
33#include <linux/mfd/dbx500-prcmu.h> 39#include <linux/mfd/dbx500-prcmu.h>
40#else
41static inline u32 prcmu_read(unsigned int reg) {
42 return 0;
43}
44static inline void prcmu_write(unsigned int reg, u32 value) {}
45static inline void prcmu_write_masked(unsigned int reg, u32 mask, u32 value) {}
46#endif
34 47
35#include <asm/mach/irq.h> 48#include <asm/mach/irq.h>
36 49
@@ -1268,6 +1281,7 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
1268 struct clk *clk; 1281 struct clk *clk;
1269 int secondary_irq; 1282 int secondary_irq;
1270 void __iomem *base; 1283 void __iomem *base;
1284 int irq_start = -1;
1271 int irq; 1285 int irq;
1272 int ret; 1286 int ret;
1273 1287
@@ -1371,19 +1385,11 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
1371 1385
1372 platform_set_drvdata(dev, nmk_chip); 1386 platform_set_drvdata(dev, nmk_chip);
1373 1387
1374 if (np) { 1388 if (!np)
1375 /* The DT case will just grab a set of IRQ numbers */
1376 nmk_chip->domain = irq_domain_add_linear(np, NMK_GPIO_PER_CHIP,
1377 &nmk_gpio_irq_simple_ops, nmk_chip);
1378 } else {
1379 /* Non-DT legacy mode, use hardwired IRQ numbers */
1380 int irq_start;
1381
1382 irq_start = NOMADIK_GPIO_TO_IRQ(pdata->first_gpio); 1389 irq_start = NOMADIK_GPIO_TO_IRQ(pdata->first_gpio);
1383 nmk_chip->domain = irq_domain_add_simple(NULL, 1390 nmk_chip->domain = irq_domain_add_simple(NULL,
1384 NMK_GPIO_PER_CHIP, irq_start, 1391 NMK_GPIO_PER_CHIP, irq_start,
1385 &nmk_gpio_irq_simple_ops, nmk_chip); 1392 &nmk_gpio_irq_simple_ops, nmk_chip);
1386 }
1387 if (!nmk_chip->domain) { 1393 if (!nmk_chip->domain) {
1388 dev_err(&dev->dev, "failed to create irqdomain\n"); 1394 dev_err(&dev->dev, "failed to create irqdomain\n");
1389 ret = -ENOSYS; 1395 ret = -ENOSYS;
diff --git a/drivers/pinctrl/pinctrl-samsung.c b/drivers/pinctrl/pinctrl-samsung.c
index dd108a94acf9..861cd5f04d5e 100644
--- a/drivers/pinctrl/pinctrl-samsung.c
+++ b/drivers/pinctrl/pinctrl-samsung.c
@@ -513,7 +513,7 @@ static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
513 * Parse the pin names listed in the 'samsung,pins' property and convert it 513 * Parse the pin names listed in the 'samsung,pins' property and convert it
514 * into a list of gpio numbers are create a pin group from it. 514 * into a list of gpio numbers are create a pin group from it.
515 */ 515 */
516static int __init samsung_pinctrl_parse_dt_pins(struct platform_device *pdev, 516static int __devinit samsung_pinctrl_parse_dt_pins(struct platform_device *pdev,
517 struct device_node *cfg_np, struct pinctrl_desc *pctl, 517 struct device_node *cfg_np, struct pinctrl_desc *pctl,
518 unsigned int **pin_list, unsigned int *npins) 518 unsigned int **pin_list, unsigned int *npins)
519{ 519{
@@ -560,7 +560,7 @@ static int __init samsung_pinctrl_parse_dt_pins(struct platform_device *pdev,
560 * from device node of the pin-controller. A pin group is formed with all 560 * from device node of the pin-controller. A pin group is formed with all
561 * the pins listed in the "samsung,pins" property. 561 * the pins listed in the "samsung,pins" property.
562 */ 562 */
563static int __init samsung_pinctrl_parse_dt(struct platform_device *pdev, 563static int __devinit samsung_pinctrl_parse_dt(struct platform_device *pdev,
564 struct samsung_pinctrl_drv_data *drvdata) 564 struct samsung_pinctrl_drv_data *drvdata)
565{ 565{
566 struct device *dev = &pdev->dev; 566 struct device *dev = &pdev->dev;
@@ -655,7 +655,7 @@ static int __init samsung_pinctrl_parse_dt(struct platform_device *pdev,
655} 655}
656 656
657/* register the pinctrl interface with the pinctrl subsystem */ 657/* register the pinctrl interface with the pinctrl subsystem */
658static int __init samsung_pinctrl_register(struct platform_device *pdev, 658static int __devinit samsung_pinctrl_register(struct platform_device *pdev,
659 struct samsung_pinctrl_drv_data *drvdata) 659 struct samsung_pinctrl_drv_data *drvdata)
660{ 660{
661 struct pinctrl_desc *ctrldesc = &drvdata->pctl; 661 struct pinctrl_desc *ctrldesc = &drvdata->pctl;
@@ -729,7 +729,7 @@ static int __init samsung_pinctrl_register(struct platform_device *pdev,
729} 729}
730 730
731/* register the gpiolib interface with the gpiolib subsystem */ 731/* register the gpiolib interface with the gpiolib subsystem */
732static int __init samsung_gpiolib_register(struct platform_device *pdev, 732static int __devinit samsung_gpiolib_register(struct platform_device *pdev,
733 struct samsung_pinctrl_drv_data *drvdata) 733 struct samsung_pinctrl_drv_data *drvdata)
734{ 734{
735 struct gpio_chip *gc; 735 struct gpio_chip *gc;
@@ -762,7 +762,7 @@ static int __init samsung_gpiolib_register(struct platform_device *pdev,
762} 762}
763 763
764/* unregister the gpiolib interface with the gpiolib subsystem */ 764/* unregister the gpiolib interface with the gpiolib subsystem */
765static int __init samsung_gpiolib_unregister(struct platform_device *pdev, 765static int __devinit samsung_gpiolib_unregister(struct platform_device *pdev,
766 struct samsung_pinctrl_drv_data *drvdata) 766 struct samsung_pinctrl_drv_data *drvdata)
767{ 767{
768 int ret = gpiochip_remove(drvdata->gc); 768 int ret = gpiochip_remove(drvdata->gc);
diff --git a/drivers/pinctrl/pinctrl-sirf.c b/drivers/pinctrl/pinctrl-sirf.c
index 675497c15149..9ecacf3d0a75 100644
--- a/drivers/pinctrl/pinctrl-sirf.c
+++ b/drivers/pinctrl/pinctrl-sirf.c
@@ -1323,41 +1323,6 @@ static inline struct sirfsoc_gpio_bank *sirfsoc_gpio_to_bank(unsigned int gpio)
1323 return &sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE]; 1323 return &sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE];
1324} 1324}
1325 1325
1326void sirfsoc_gpio_set_pull(unsigned gpio, unsigned mode)
1327{
1328 struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(gpio);
1329 int idx = sirfsoc_gpio_to_offset(gpio);
1330 u32 val, offset;
1331 unsigned long flags;
1332
1333 offset = SIRFSOC_GPIO_CTRL(bank->id, idx);
1334
1335 spin_lock_irqsave(&sgpio_lock, flags);
1336
1337 val = readl(bank->chip.regs + offset);
1338
1339 switch (mode) {
1340 case SIRFSOC_GPIO_PULL_NONE:
1341 val &= ~SIRFSOC_GPIO_CTL_PULL_MASK;
1342 break;
1343 case SIRFSOC_GPIO_PULL_UP:
1344 val |= SIRFSOC_GPIO_CTL_PULL_MASK;
1345 val |= SIRFSOC_GPIO_CTL_PULL_HIGH;
1346 break;
1347 case SIRFSOC_GPIO_PULL_DOWN:
1348 val |= SIRFSOC_GPIO_CTL_PULL_MASK;
1349 val &= ~SIRFSOC_GPIO_CTL_PULL_HIGH;
1350 break;
1351 default:
1352 break;
1353 }
1354
1355 writel(val, bank->chip.regs + offset);
1356
1357 spin_unlock_irqrestore(&sgpio_lock, flags);
1358}
1359EXPORT_SYMBOL(sirfsoc_gpio_set_pull);
1360
1361static inline struct sirfsoc_gpio_bank *sirfsoc_irqchip_to_bank(struct gpio_chip *chip) 1326static inline struct sirfsoc_gpio_bank *sirfsoc_irqchip_to_bank(struct gpio_chip *chip)
1362{ 1327{
1363 return container_of(to_of_mm_gpio_chip(chip), struct sirfsoc_gpio_bank, chip); 1328 return container_of(to_of_mm_gpio_chip(chip), struct sirfsoc_gpio_bank, chip);
diff --git a/drivers/pinctrl/pinctrl-xway.c b/drivers/pinctrl/pinctrl-xway.c
index f8d917d40c92..b9bcaec66223 100644
--- a/drivers/pinctrl/pinctrl-xway.c
+++ b/drivers/pinctrl/pinctrl-xway.c
@@ -17,8 +17,6 @@
17#include <linux/ioport.h> 17#include <linux/ioport.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/module.h>
21#include <linux/io.h>
22#include <linux/platform_device.h> 20#include <linux/platform_device.h>
23 21
24#include "pinctrl-lantiq.h" 22#include "pinctrl-lantiq.h"
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 2db409330c21..e67e0258aec5 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -1141,11 +1141,12 @@ static int qeth_l2_recover(void *ptr)
1141 dev_info(&card->gdev->dev, 1141 dev_info(&card->gdev->dev,
1142 "Device successfully recovered!\n"); 1142 "Device successfully recovered!\n");
1143 else { 1143 else {
1144 rtnl_lock(); 1144 if (rtnl_trylock()) {
1145 dev_close(card->dev); 1145 dev_close(card->dev);
1146 rtnl_unlock(); 1146 rtnl_unlock();
1147 dev_warn(&card->gdev->dev, "The qeth device driver " 1147 dev_warn(&card->gdev->dev, "The qeth device driver "
1148 "failed to recover an error on the device\n"); 1148 "failed to recover an error on the device\n");
1149 }
1149 } 1150 }
1150 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); 1151 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1151 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); 1152 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 4cd310cb5bdf..5ba390658498 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -3510,11 +3510,12 @@ static int qeth_l3_recover(void *ptr)
3510 dev_info(&card->gdev->dev, 3510 dev_info(&card->gdev->dev,
3511 "Device successfully recovered!\n"); 3511 "Device successfully recovered!\n");
3512 else { 3512 else {
3513 rtnl_lock(); 3513 if (rtnl_trylock()) {
3514 dev_close(card->dev); 3514 dev_close(card->dev);
3515 rtnl_unlock(); 3515 rtnl_unlock();
3516 dev_warn(&card->gdev->dev, "The qeth device driver " 3516 dev_warn(&card->gdev->dev, "The qeth device driver "
3517 "failed to recover an error on the device\n"); 3517 "failed to recover an error on the device\n");
3518 }
3518 } 3519 }
3519 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); 3520 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
3520 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); 3521 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
diff --git a/drivers/s390/net/smsgiucv.c b/drivers/s390/net/smsgiucv.c
index 207b7d742443..d8f990b6b332 100644
--- a/drivers/s390/net/smsgiucv.c
+++ b/drivers/s390/net/smsgiucv.c
@@ -157,7 +157,7 @@ static int smsg_pm_restore_thaw(struct device *dev)
157#ifdef CONFIG_PM_DEBUG 157#ifdef CONFIG_PM_DEBUG
158 printk(KERN_WARNING "smsg_pm_restore_thaw\n"); 158 printk(KERN_WARNING "smsg_pm_restore_thaw\n");
159#endif 159#endif
160 if (smsg_path && iucv_path_connected) { 160 if (smsg_path && !iucv_path_connected) {
161 memset(smsg_path, 0, sizeof(*smsg_path)); 161 memset(smsg_path, 0, sizeof(*smsg_path));
162 smsg_path->msglim = 255; 162 smsg_path->msglim = 255;
163 smsg_path->flags = 0; 163 smsg_path->flags = 0;
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 6206a666a8ec..737554c37d9e 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -179,6 +179,7 @@ static void print_SCp(struct scsi_pointer *SCp, const char *prefix, const char *
179 SCp->buffers_residual, suffix); 179 SCp->buffers_residual, suffix);
180} 180}
181 181
182#ifdef CHECK_STRUCTURE
182static void fas216_dumpinfo(FAS216_Info *info) 183static void fas216_dumpinfo(FAS216_Info *info)
183{ 184{
184 static int used = 0; 185 static int used = 0;
@@ -223,7 +224,6 @@ static void fas216_dumpinfo(FAS216_Info *info)
223 info->internal_done, info->magic_end); 224 info->internal_done, info->magic_end);
224} 225}
225 226
226#ifdef CHECK_STRUCTURE
227static void __fas216_checkmagic(FAS216_Info *info, const char *func) 227static void __fas216_checkmagic(FAS216_Info *info, const char *func)
228{ 228{
229 int corruption = 0; 229 int corruption = 0;
diff --git a/drivers/scsi/arm/oak.c b/drivers/scsi/arm/oak.c
index d25f944b59c2..fc6a5aabf66e 100644
--- a/drivers/scsi/arm/oak.c
+++ b/drivers/scsi/arm/oak.c
@@ -21,6 +21,7 @@
21/*#define PSEUDO_DMA*/ 21/*#define PSEUDO_DMA*/
22 22
23#define OAKSCSI_PUBLIC_RELEASE 1 23#define OAKSCSI_PUBLIC_RELEASE 1
24#define DONT_USE_INTR
24 25
25#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata) 26#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
26#define NCR5380_local_declare() void __iomem *_base 27#define NCR5380_local_declare() void __iomem *_base
diff --git a/drivers/sh/intc/access.c b/drivers/sh/intc/access.c
index f892ae1d212a..114390f967d2 100644
--- a/drivers/sh/intc/access.c
+++ b/drivers/sh/intc/access.c
@@ -75,54 +75,61 @@ unsigned long intc_get_field_from_handle(unsigned int value, unsigned int handle
75static unsigned long test_8(unsigned long addr, unsigned long h, 75static unsigned long test_8(unsigned long addr, unsigned long h,
76 unsigned long ignore) 76 unsigned long ignore)
77{ 77{
78 return intc_get_field_from_handle(__raw_readb(addr), h); 78 void __iomem *ptr = (void __iomem *)addr;
79 return intc_get_field_from_handle(__raw_readb(ptr), h);
79} 80}
80 81
81static unsigned long test_16(unsigned long addr, unsigned long h, 82static unsigned long test_16(unsigned long addr, unsigned long h,
82 unsigned long ignore) 83 unsigned long ignore)
83{ 84{
84 return intc_get_field_from_handle(__raw_readw(addr), h); 85 void __iomem *ptr = (void __iomem *)addr;
86 return intc_get_field_from_handle(__raw_readw(ptr), h);
85} 87}
86 88
87static unsigned long test_32(unsigned long addr, unsigned long h, 89static unsigned long test_32(unsigned long addr, unsigned long h,
88 unsigned long ignore) 90 unsigned long ignore)
89{ 91{
90 return intc_get_field_from_handle(__raw_readl(addr), h); 92 void __iomem *ptr = (void __iomem *)addr;
93 return intc_get_field_from_handle(__raw_readl(ptr), h);
91} 94}
92 95
93static unsigned long write_8(unsigned long addr, unsigned long h, 96static unsigned long write_8(unsigned long addr, unsigned long h,
94 unsigned long data) 97 unsigned long data)
95{ 98{
96 __raw_writeb(intc_set_field_from_handle(0, data, h), addr); 99 void __iomem *ptr = (void __iomem *)addr;
97 (void)__raw_readb(addr); /* Defeat write posting */ 100 __raw_writeb(intc_set_field_from_handle(0, data, h), ptr);
101 (void)__raw_readb(ptr); /* Defeat write posting */
98 return 0; 102 return 0;
99} 103}
100 104
101static unsigned long write_16(unsigned long addr, unsigned long h, 105static unsigned long write_16(unsigned long addr, unsigned long h,
102 unsigned long data) 106 unsigned long data)
103{ 107{
104 __raw_writew(intc_set_field_from_handle(0, data, h), addr); 108 void __iomem *ptr = (void __iomem *)addr;
105 (void)__raw_readw(addr); /* Defeat write posting */ 109 __raw_writew(intc_set_field_from_handle(0, data, h), ptr);
110 (void)__raw_readw(ptr); /* Defeat write posting */
106 return 0; 111 return 0;
107} 112}
108 113
109static unsigned long write_32(unsigned long addr, unsigned long h, 114static unsigned long write_32(unsigned long addr, unsigned long h,
110 unsigned long data) 115 unsigned long data)
111{ 116{
112 __raw_writel(intc_set_field_from_handle(0, data, h), addr); 117 void __iomem *ptr = (void __iomem *)addr;
113 (void)__raw_readl(addr); /* Defeat write posting */ 118 __raw_writel(intc_set_field_from_handle(0, data, h), ptr);
119 (void)__raw_readl(ptr); /* Defeat write posting */
114 return 0; 120 return 0;
115} 121}
116 122
117static unsigned long modify_8(unsigned long addr, unsigned long h, 123static unsigned long modify_8(unsigned long addr, unsigned long h,
118 unsigned long data) 124 unsigned long data)
119{ 125{
126 void __iomem *ptr = (void __iomem *)addr;
120 unsigned long flags; 127 unsigned long flags;
121 unsigned int value; 128 unsigned int value;
122 local_irq_save(flags); 129 local_irq_save(flags);
123 value = intc_set_field_from_handle(__raw_readb(addr), data, h); 130 value = intc_set_field_from_handle(__raw_readb(ptr), data, h);
124 __raw_writeb(value, addr); 131 __raw_writeb(value, ptr);
125 (void)__raw_readb(addr); /* Defeat write posting */ 132 (void)__raw_readb(ptr); /* Defeat write posting */
126 local_irq_restore(flags); 133 local_irq_restore(flags);
127 return 0; 134 return 0;
128} 135}
@@ -130,12 +137,13 @@ static unsigned long modify_8(unsigned long addr, unsigned long h,
130static unsigned long modify_16(unsigned long addr, unsigned long h, 137static unsigned long modify_16(unsigned long addr, unsigned long h,
131 unsigned long data) 138 unsigned long data)
132{ 139{
140 void __iomem *ptr = (void __iomem *)addr;
133 unsigned long flags; 141 unsigned long flags;
134 unsigned int value; 142 unsigned int value;
135 local_irq_save(flags); 143 local_irq_save(flags);
136 value = intc_set_field_from_handle(__raw_readw(addr), data, h); 144 value = intc_set_field_from_handle(__raw_readw(ptr), data, h);
137 __raw_writew(value, addr); 145 __raw_writew(value, ptr);
138 (void)__raw_readw(addr); /* Defeat write posting */ 146 (void)__raw_readw(ptr); /* Defeat write posting */
139 local_irq_restore(flags); 147 local_irq_restore(flags);
140 return 0; 148 return 0;
141} 149}
@@ -143,12 +151,13 @@ static unsigned long modify_16(unsigned long addr, unsigned long h,
143static unsigned long modify_32(unsigned long addr, unsigned long h, 151static unsigned long modify_32(unsigned long addr, unsigned long h,
144 unsigned long data) 152 unsigned long data)
145{ 153{
154 void __iomem *ptr = (void __iomem *)addr;
146 unsigned long flags; 155 unsigned long flags;
147 unsigned int value; 156 unsigned int value;
148 local_irq_save(flags); 157 local_irq_save(flags);
149 value = intc_set_field_from_handle(__raw_readl(addr), data, h); 158 value = intc_set_field_from_handle(__raw_readl(ptr), data, h);
150 __raw_writel(value, addr); 159 __raw_writel(value, ptr);
151 (void)__raw_readl(addr); /* Defeat write posting */ 160 (void)__raw_readl(ptr); /* Defeat write posting */
152 local_irq_restore(flags); 161 local_irq_restore(flags);
153 return 0; 162 return 0;
154} 163}
diff --git a/drivers/sh/intc/chip.c b/drivers/sh/intc/chip.c
index 012df2676a26..46427b48e2f1 100644
--- a/drivers/sh/intc/chip.c
+++ b/drivers/sh/intc/chip.c
@@ -83,7 +83,7 @@ static void intc_mask_ack(struct irq_data *data)
83 unsigned int irq = data->irq; 83 unsigned int irq = data->irq;
84 struct intc_desc_int *d = get_intc_desc(irq); 84 struct intc_desc_int *d = get_intc_desc(irq);
85 unsigned long handle = intc_get_ack_handle(irq); 85 unsigned long handle = intc_get_ack_handle(irq);
86 unsigned long addr; 86 void __iomem *addr;
87 87
88 intc_disable(data); 88 intc_disable(data);
89 89
@@ -91,7 +91,7 @@ static void intc_mask_ack(struct irq_data *data)
91 if (handle) { 91 if (handle) {
92 unsigned int value; 92 unsigned int value;
93 93
94 addr = INTC_REG(d, _INTC_ADDR_D(handle), 0); 94 addr = (void __iomem *)INTC_REG(d, _INTC_ADDR_D(handle), 0);
95 value = intc_set_field_from_handle(0, 1, handle); 95 value = intc_set_field_from_handle(0, 1, handle);
96 96
97 switch (_INTC_FN(handle)) { 97 switch (_INTC_FN(handle)) {
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index 1a81c90a4a71..6e7a805d324d 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -132,7 +132,7 @@
132 132
133struct s3c64xx_spi_dma_data { 133struct s3c64xx_spi_dma_data {
134 unsigned ch; 134 unsigned ch;
135 enum dma_data_direction direction; 135 enum dma_transfer_direction direction;
136 enum dma_ch dmach; 136 enum dma_ch dmach;
137 struct property *dma_prop; 137 struct property *dma_prop;
138}; 138};
@@ -1067,11 +1067,11 @@ static int __devinit s3c64xx_spi_get_dmares(
1067 1067
1068 if (tx) { 1068 if (tx) {
1069 dma_data = &sdd->tx_dma; 1069 dma_data = &sdd->tx_dma;
1070 dma_data->direction = DMA_TO_DEVICE; 1070 dma_data->direction = DMA_MEM_TO_DEV;
1071 chan_str = "tx"; 1071 chan_str = "tx";
1072 } else { 1072 } else {
1073 dma_data = &sdd->rx_dma; 1073 dma_data = &sdd->rx_dma;
1074 dma_data->direction = DMA_FROM_DEVICE; 1074 dma_data->direction = DMA_DEV_TO_MEM;
1075 chan_str = "rx"; 1075 chan_str = "rx";
1076 } 1076 }
1077 1077
diff --git a/drivers/staging/dgrp/dgrp_mon_ops.c b/drivers/staging/dgrp/dgrp_mon_ops.c
index 268dcb95204b..4792d056a365 100644
--- a/drivers/staging/dgrp/dgrp_mon_ops.c
+++ b/drivers/staging/dgrp/dgrp_mon_ops.c
@@ -38,6 +38,7 @@
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <asm/unaligned.h> 39#include <asm/unaligned.h>
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/uaccess.h>
41 42
42#include "dgrp_common.h" 43#include "dgrp_common.h"
43 44
diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c
index 28f5c9ab6b43..24327c3bad83 100644
--- a/drivers/staging/dgrp/dgrp_specproc.c
+++ b/drivers/staging/dgrp/dgrp_specproc.c
@@ -39,6 +39,7 @@
39#include <linux/proc_fs.h> 39#include <linux/proc_fs.h>
40#include <linux/ctype.h> 40#include <linux/ctype.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/uaccess.h>
42#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
43 44
44#include "dgrp_common.h" 45#include "dgrp_common.h"
@@ -228,6 +229,9 @@ static void register_proc_table(struct dgrp_proc_entry *table,
228 int len; 229 int len;
229 mode_t mode; 230 mode_t mode;
230 231
232 if (table == NULL)
233 return;
234
231 for (; table->id; table++) { 235 for (; table->id; table++) {
232 /* Can't do anything without a proc name. */ 236 /* Can't do anything without a proc name. */
233 if (!table->name) 237 if (!table->name)
@@ -296,6 +300,9 @@ static void unregister_proc_table(struct dgrp_proc_entry *table,
296 struct proc_dir_entry *de; 300 struct proc_dir_entry *de;
297 struct nd_struct *tmp; 301 struct nd_struct *tmp;
298 302
303 if (table == NULL)
304 return;
305
299 list_for_each_entry(tmp, &nd_struct_list, list) { 306 list_for_each_entry(tmp, &nd_struct_list, list) {
300 if ((table == dgrp_net_table) && (tmp->nd_net_de)) { 307 if ((table == dgrp_net_table) && (tmp->nd_net_de)) {
301 unregister_dgrp_device(tmp->nd_net_de); 308 unregister_dgrp_device(tmp->nd_net_de);
diff --git a/drivers/staging/dgrp/dgrp_tty.c b/drivers/staging/dgrp/dgrp_tty.c
index 7d7de873870c..e125b03598d7 100644
--- a/drivers/staging/dgrp/dgrp_tty.c
+++ b/drivers/staging/dgrp/dgrp_tty.c
@@ -40,6 +40,7 @@
40#include <linux/tty.h> 40#include <linux/tty.h>
41#include <linux/tty_flip.h> 41#include <linux/tty_flip.h>
42#include <linux/sched.h> 42#include <linux/sched.h>
43#include <linux/uaccess.h>
43 44
44#include "dgrp_common.h" 45#include "dgrp_common.h"
45 46
@@ -3172,6 +3173,9 @@ dgrp_tty_init(struct nd_struct *nd)
3172 */ 3173 */
3173 3174
3174 nd->nd_serial_ttdriver = alloc_tty_driver(CHAN_MAX); 3175 nd->nd_serial_ttdriver = alloc_tty_driver(CHAN_MAX);
3176 if (!nd->nd_serial_ttdriver)
3177 return -ENOMEM;
3178
3175 sprintf(nd->nd_serial_name, "tty_dgrp_%s_", id); 3179 sprintf(nd->nd_serial_name, "tty_dgrp_%s_", id);
3176 3180
3177 nd->nd_serial_ttdriver->owner = THIS_MODULE; 3181 nd->nd_serial_ttdriver->owner = THIS_MODULE;
@@ -3231,6 +3235,9 @@ dgrp_tty_init(struct nd_struct *nd)
3231 } 3235 }
3232 3236
3233 nd->nd_callout_ttdriver = alloc_tty_driver(CHAN_MAX); 3237 nd->nd_callout_ttdriver = alloc_tty_driver(CHAN_MAX);
3238 if (!nd->nd_callout_ttdriver)
3239 return -ENOMEM;
3240
3234 sprintf(nd->nd_callout_name, "cu_dgrp_%s_", id); 3241 sprintf(nd->nd_callout_name, "cu_dgrp_%s_", id);
3235 3242
3236 nd->nd_callout_ttdriver->owner = THIS_MODULE; 3243 nd->nd_callout_ttdriver->owner = THIS_MODULE;
@@ -3268,6 +3275,9 @@ dgrp_tty_init(struct nd_struct *nd)
3268 3275
3269 3276
3270 nd->nd_xprint_ttdriver = alloc_tty_driver(CHAN_MAX); 3277 nd->nd_xprint_ttdriver = alloc_tty_driver(CHAN_MAX);
3278 if (!nd->nd_xprint_ttdriver)
3279 return -ENOMEM;
3280
3271 sprintf(nd->nd_xprint_name, "pr_dgrp_%s_", id); 3281 sprintf(nd->nd_xprint_name, "pr_dgrp_%s_", id);
3272 3282
3273 nd->nd_xprint_ttdriver->owner = THIS_MODULE; 3283 nd->nd_xprint_ttdriver->owner = THIS_MODULE;
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index edfd67d25013..e1cb6bd75f60 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -22,6 +22,7 @@ config THERMAL_HWMON
22config CPU_THERMAL 22config CPU_THERMAL
23 bool "generic cpu cooling support" 23 bool "generic cpu cooling support"
24 depends on THERMAL && CPU_FREQ 24 depends on THERMAL && CPU_FREQ
25 select CPU_FREQ_TABLE
25 help 26 help
26 This implements the generic cpu cooling mechanism through frequency 27 This implements the generic cpu cooling mechanism through frequency
27 reduction, cpu hotplug and any other ways of reducing temperature. An 28 reduction, cpu hotplug and any other ways of reducing temperature. An
@@ -50,6 +51,7 @@ config RCAR_THERMAL
50config EXYNOS_THERMAL 51config EXYNOS_THERMAL
51 tristate "Temperature sensor on Samsung EXYNOS" 52 tristate "Temperature sensor on Samsung EXYNOS"
52 depends on (ARCH_EXYNOS4 || ARCH_EXYNOS5) && THERMAL 53 depends on (ARCH_EXYNOS4 || ARCH_EXYNOS5) && THERMAL
54 select CPU_FREQ_TABLE
53 help 55 help
54 If you say yes here you get support for TMU (Thermal Managment 56 If you say yes here you get support for TMU (Thermal Managment
55 Unit) on SAMSUNG EXYNOS series of SoC. 57 Unit) on SAMSUNG EXYNOS series of SoC.
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 8c0b7b42319c..60b076cc4e20 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -73,10 +73,42 @@
73#define ECHO_OP_SET_CANON_COL 0x81 73#define ECHO_OP_SET_CANON_COL 0x81
74#define ECHO_OP_ERASE_TAB 0x82 74#define ECHO_OP_ERASE_TAB 0x82
75 75
76struct n_tty_data {
77 unsigned int column;
78 unsigned long overrun_time;
79 int num_overrun;
80
81 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
82 unsigned char echo_overrun:1;
83
84 DECLARE_BITMAP(process_char_map, 256);
85 DECLARE_BITMAP(read_flags, N_TTY_BUF_SIZE);
86
87 char *read_buf;
88 int read_head;
89 int read_tail;
90 int read_cnt;
91
92 unsigned char *echo_buf;
93 unsigned int echo_pos;
94 unsigned int echo_cnt;
95
96 int canon_data;
97 unsigned long canon_head;
98 unsigned int canon_column;
99
100 struct mutex atomic_read_lock;
101 struct mutex output_lock;
102 struct mutex echo_lock;
103 spinlock_t read_lock;
104};
105
76static inline int tty_put_user(struct tty_struct *tty, unsigned char x, 106static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
77 unsigned char __user *ptr) 107 unsigned char __user *ptr)
78{ 108{
79 tty_audit_add_data(tty, &x, 1); 109 struct n_tty_data *ldata = tty->disc_data;
110
111 tty_audit_add_data(tty, &x, 1, ldata->icanon);
80 return put_user(x, ptr); 112 return put_user(x, ptr);
81} 113}
82 114
@@ -92,17 +124,18 @@ static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
92 124
93static void n_tty_set_room(struct tty_struct *tty) 125static void n_tty_set_room(struct tty_struct *tty)
94{ 126{
127 struct n_tty_data *ldata = tty->disc_data;
95 int left; 128 int left;
96 int old_left; 129 int old_left;
97 130
98 /* tty->read_cnt is not read locked ? */ 131 /* ldata->read_cnt is not read locked ? */
99 if (I_PARMRK(tty)) { 132 if (I_PARMRK(tty)) {
100 /* Multiply read_cnt by 3, since each byte might take up to 133 /* Multiply read_cnt by 3, since each byte might take up to
101 * three times as many spaces when PARMRK is set (depending on 134 * three times as many spaces when PARMRK is set (depending on
102 * its flags, e.g. parity error). */ 135 * its flags, e.g. parity error). */
103 left = N_TTY_BUF_SIZE - tty->read_cnt * 3 - 1; 136 left = N_TTY_BUF_SIZE - ldata->read_cnt * 3 - 1;
104 } else 137 } else
105 left = N_TTY_BUF_SIZE - tty->read_cnt - 1; 138 left = N_TTY_BUF_SIZE - ldata->read_cnt - 1;
106 139
107 /* 140 /*
108 * If we are doing input canonicalization, and there are no 141 * If we are doing input canonicalization, and there are no
@@ -111,44 +144,47 @@ static void n_tty_set_room(struct tty_struct *tty)
111 * characters will be beeped. 144 * characters will be beeped.
112 */ 145 */
113 if (left <= 0) 146 if (left <= 0)
114 left = tty->icanon && !tty->canon_data; 147 left = ldata->icanon && !ldata->canon_data;
115 old_left = tty->receive_room; 148 old_left = tty->receive_room;
116 tty->receive_room = left; 149 tty->receive_room = left;
117 150
118 /* Did this open up the receive buffer? We may need to flip */ 151 /* Did this open up the receive buffer? We may need to flip */
119 if (left && !old_left) 152 if (left && !old_left) {
120 schedule_work(&tty->buf.work); 153 WARN_RATELIMIT(tty->port->itty == NULL,
154 "scheduling with invalid itty");
155 schedule_work(&tty->port->buf.work);
156 }
121} 157}
122 158
123static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty) 159static void put_tty_queue_nolock(unsigned char c, struct n_tty_data *ldata)
124{ 160{
125 if (tty->read_cnt < N_TTY_BUF_SIZE) { 161 if (ldata->read_cnt < N_TTY_BUF_SIZE) {
126 tty->read_buf[tty->read_head] = c; 162 ldata->read_buf[ldata->read_head] = c;
127 tty->read_head = (tty->read_head + 1) & (N_TTY_BUF_SIZE-1); 163 ldata->read_head = (ldata->read_head + 1) & (N_TTY_BUF_SIZE-1);
128 tty->read_cnt++; 164 ldata->read_cnt++;
129 } 165 }
130} 166}
131 167
132/** 168/**
133 * put_tty_queue - add character to tty 169 * put_tty_queue - add character to tty
134 * @c: character 170 * @c: character
135 * @tty: tty device 171 * @ldata: n_tty data
136 * 172 *
137 * Add a character to the tty read_buf queue. This is done under the 173 * Add a character to the tty read_buf queue. This is done under the
138 * read_lock to serialize character addition and also to protect us 174 * read_lock to serialize character addition and also to protect us
139 * against parallel reads or flushes 175 * against parallel reads or flushes
140 */ 176 */
141 177
142static void put_tty_queue(unsigned char c, struct tty_struct *tty) 178static void put_tty_queue(unsigned char c, struct n_tty_data *ldata)
143{ 179{
144 unsigned long flags; 180 unsigned long flags;
145 /* 181 /*
146 * The problem of stomping on the buffers ends here. 182 * The problem of stomping on the buffers ends here.
147 * Why didn't anyone see this one coming? --AJK 183 * Why didn't anyone see this one coming? --AJK
148 */ 184 */
149 spin_lock_irqsave(&tty->read_lock, flags); 185 spin_lock_irqsave(&ldata->read_lock, flags);
150 put_tty_queue_nolock(c, tty); 186 put_tty_queue_nolock(c, ldata);
151 spin_unlock_irqrestore(&tty->read_lock, flags); 187 spin_unlock_irqrestore(&ldata->read_lock, flags);
152} 188}
153 189
154/** 190/**
@@ -179,18 +215,19 @@ static void check_unthrottle(struct tty_struct *tty)
179 215
180static void reset_buffer_flags(struct tty_struct *tty) 216static void reset_buffer_flags(struct tty_struct *tty)
181{ 217{
218 struct n_tty_data *ldata = tty->disc_data;
182 unsigned long flags; 219 unsigned long flags;
183 220
184 spin_lock_irqsave(&tty->read_lock, flags); 221 spin_lock_irqsave(&ldata->read_lock, flags);
185 tty->read_head = tty->read_tail = tty->read_cnt = 0; 222 ldata->read_head = ldata->read_tail = ldata->read_cnt = 0;
186 spin_unlock_irqrestore(&tty->read_lock, flags); 223 spin_unlock_irqrestore(&ldata->read_lock, flags);
187 224
188 mutex_lock(&tty->echo_lock); 225 mutex_lock(&ldata->echo_lock);
189 tty->echo_pos = tty->echo_cnt = tty->echo_overrun = 0; 226 ldata->echo_pos = ldata->echo_cnt = ldata->echo_overrun = 0;
190 mutex_unlock(&tty->echo_lock); 227 mutex_unlock(&ldata->echo_lock);
191 228
192 tty->canon_head = tty->canon_data = tty->erasing = 0; 229 ldata->canon_head = ldata->canon_data = ldata->erasing = 0;
193 memset(&tty->read_flags, 0, sizeof tty->read_flags); 230 bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE);
194 n_tty_set_room(tty); 231 n_tty_set_room(tty);
195} 232}
196 233
@@ -235,18 +272,19 @@ static void n_tty_flush_buffer(struct tty_struct *tty)
235 272
236static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty) 273static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty)
237{ 274{
275 struct n_tty_data *ldata = tty->disc_data;
238 unsigned long flags; 276 unsigned long flags;
239 ssize_t n = 0; 277 ssize_t n = 0;
240 278
241 spin_lock_irqsave(&tty->read_lock, flags); 279 spin_lock_irqsave(&ldata->read_lock, flags);
242 if (!tty->icanon) { 280 if (!ldata->icanon) {
243 n = tty->read_cnt; 281 n = ldata->read_cnt;
244 } else if (tty->canon_data) { 282 } else if (ldata->canon_data) {
245 n = (tty->canon_head > tty->read_tail) ? 283 n = (ldata->canon_head > ldata->read_tail) ?
246 tty->canon_head - tty->read_tail : 284 ldata->canon_head - ldata->read_tail :
247 tty->canon_head + (N_TTY_BUF_SIZE - tty->read_tail); 285 ldata->canon_head + (N_TTY_BUF_SIZE - ldata->read_tail);
248 } 286 }
249 spin_unlock_irqrestore(&tty->read_lock, flags); 287 spin_unlock_irqrestore(&ldata->read_lock, flags);
250 return n; 288 return n;
251} 289}
252 290
@@ -301,6 +339,7 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
301 339
302static int do_output_char(unsigned char c, struct tty_struct *tty, int space) 340static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
303{ 341{
342 struct n_tty_data *ldata = tty->disc_data;
304 int spaces; 343 int spaces;
305 344
306 if (!space) 345 if (!space)
@@ -309,48 +348,48 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
309 switch (c) { 348 switch (c) {
310 case '\n': 349 case '\n':
311 if (O_ONLRET(tty)) 350 if (O_ONLRET(tty))
312 tty->column = 0; 351 ldata->column = 0;
313 if (O_ONLCR(tty)) { 352 if (O_ONLCR(tty)) {
314 if (space < 2) 353 if (space < 2)
315 return -1; 354 return -1;
316 tty->canon_column = tty->column = 0; 355 ldata->canon_column = ldata->column = 0;
317 tty->ops->write(tty, "\r\n", 2); 356 tty->ops->write(tty, "\r\n", 2);
318 return 2; 357 return 2;
319 } 358 }
320 tty->canon_column = tty->column; 359 ldata->canon_column = ldata->column;
321 break; 360 break;
322 case '\r': 361 case '\r':
323 if (O_ONOCR(tty) && tty->column == 0) 362 if (O_ONOCR(tty) && ldata->column == 0)
324 return 0; 363 return 0;
325 if (O_OCRNL(tty)) { 364 if (O_OCRNL(tty)) {
326 c = '\n'; 365 c = '\n';
327 if (O_ONLRET(tty)) 366 if (O_ONLRET(tty))
328 tty->canon_column = tty->column = 0; 367 ldata->canon_column = ldata->column = 0;
329 break; 368 break;
330 } 369 }
331 tty->canon_column = tty->column = 0; 370 ldata->canon_column = ldata->column = 0;
332 break; 371 break;
333 case '\t': 372 case '\t':
334 spaces = 8 - (tty->column & 7); 373 spaces = 8 - (ldata->column & 7);
335 if (O_TABDLY(tty) == XTABS) { 374 if (O_TABDLY(tty) == XTABS) {
336 if (space < spaces) 375 if (space < spaces)
337 return -1; 376 return -1;
338 tty->column += spaces; 377 ldata->column += spaces;
339 tty->ops->write(tty, " ", spaces); 378 tty->ops->write(tty, " ", spaces);
340 return spaces; 379 return spaces;
341 } 380 }
342 tty->column += spaces; 381 ldata->column += spaces;
343 break; 382 break;
344 case '\b': 383 case '\b':
345 if (tty->column > 0) 384 if (ldata->column > 0)
346 tty->column--; 385 ldata->column--;
347 break; 386 break;
348 default: 387 default:
349 if (!iscntrl(c)) { 388 if (!iscntrl(c)) {
350 if (O_OLCUC(tty)) 389 if (O_OLCUC(tty))
351 c = toupper(c); 390 c = toupper(c);
352 if (!is_continuation(c, tty)) 391 if (!is_continuation(c, tty))
353 tty->column++; 392 ldata->column++;
354 } 393 }
355 break; 394 break;
356 } 395 }
@@ -375,14 +414,15 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
375 414
376static int process_output(unsigned char c, struct tty_struct *tty) 415static int process_output(unsigned char c, struct tty_struct *tty)
377{ 416{
417 struct n_tty_data *ldata = tty->disc_data;
378 int space, retval; 418 int space, retval;
379 419
380 mutex_lock(&tty->output_lock); 420 mutex_lock(&ldata->output_lock);
381 421
382 space = tty_write_room(tty); 422 space = tty_write_room(tty);
383 retval = do_output_char(c, tty, space); 423 retval = do_output_char(c, tty, space);
384 424
385 mutex_unlock(&tty->output_lock); 425 mutex_unlock(&ldata->output_lock);
386 if (retval < 0) 426 if (retval < 0)
387 return -1; 427 return -1;
388 else 428 else
@@ -411,15 +451,16 @@ static int process_output(unsigned char c, struct tty_struct *tty)
411static ssize_t process_output_block(struct tty_struct *tty, 451static ssize_t process_output_block(struct tty_struct *tty,
412 const unsigned char *buf, unsigned int nr) 452 const unsigned char *buf, unsigned int nr)
413{ 453{
454 struct n_tty_data *ldata = tty->disc_data;
414 int space; 455 int space;
415 int i; 456 int i;
416 const unsigned char *cp; 457 const unsigned char *cp;
417 458
418 mutex_lock(&tty->output_lock); 459 mutex_lock(&ldata->output_lock);
419 460
420 space = tty_write_room(tty); 461 space = tty_write_room(tty);
421 if (!space) { 462 if (!space) {
422 mutex_unlock(&tty->output_lock); 463 mutex_unlock(&ldata->output_lock);
423 return 0; 464 return 0;
424 } 465 }
425 if (nr > space) 466 if (nr > space)
@@ -431,30 +472,30 @@ static ssize_t process_output_block(struct tty_struct *tty,
431 switch (c) { 472 switch (c) {
432 case '\n': 473 case '\n':
433 if (O_ONLRET(tty)) 474 if (O_ONLRET(tty))
434 tty->column = 0; 475 ldata->column = 0;
435 if (O_ONLCR(tty)) 476 if (O_ONLCR(tty))
436 goto break_out; 477 goto break_out;
437 tty->canon_column = tty->column; 478 ldata->canon_column = ldata->column;
438 break; 479 break;
439 case '\r': 480 case '\r':
440 if (O_ONOCR(tty) && tty->column == 0) 481 if (O_ONOCR(tty) && ldata->column == 0)
441 goto break_out; 482 goto break_out;
442 if (O_OCRNL(tty)) 483 if (O_OCRNL(tty))
443 goto break_out; 484 goto break_out;
444 tty->canon_column = tty->column = 0; 485 ldata->canon_column = ldata->column = 0;
445 break; 486 break;
446 case '\t': 487 case '\t':
447 goto break_out; 488 goto break_out;
448 case '\b': 489 case '\b':
449 if (tty->column > 0) 490 if (ldata->column > 0)
450 tty->column--; 491 ldata->column--;
451 break; 492 break;
452 default: 493 default:
453 if (!iscntrl(c)) { 494 if (!iscntrl(c)) {
454 if (O_OLCUC(tty)) 495 if (O_OLCUC(tty))
455 goto break_out; 496 goto break_out;
456 if (!is_continuation(c, tty)) 497 if (!is_continuation(c, tty))
457 tty->column++; 498 ldata->column++;
458 } 499 }
459 break; 500 break;
460 } 501 }
@@ -462,7 +503,7 @@ static ssize_t process_output_block(struct tty_struct *tty,
462break_out: 503break_out:
463 i = tty->ops->write(tty, buf, i); 504 i = tty->ops->write(tty, buf, i);
464 505
465 mutex_unlock(&tty->output_lock); 506 mutex_unlock(&ldata->output_lock);
466 return i; 507 return i;
467} 508}
468 509
@@ -494,21 +535,22 @@ break_out:
494 535
495static void process_echoes(struct tty_struct *tty) 536static void process_echoes(struct tty_struct *tty)
496{ 537{
538 struct n_tty_data *ldata = tty->disc_data;
497 int space, nr; 539 int space, nr;
498 unsigned char c; 540 unsigned char c;
499 unsigned char *cp, *buf_end; 541 unsigned char *cp, *buf_end;
500 542
501 if (!tty->echo_cnt) 543 if (!ldata->echo_cnt)
502 return; 544 return;
503 545
504 mutex_lock(&tty->output_lock); 546 mutex_lock(&ldata->output_lock);
505 mutex_lock(&tty->echo_lock); 547 mutex_lock(&ldata->echo_lock);
506 548
507 space = tty_write_room(tty); 549 space = tty_write_room(tty);
508 550
509 buf_end = tty->echo_buf + N_TTY_BUF_SIZE; 551 buf_end = ldata->echo_buf + N_TTY_BUF_SIZE;
510 cp = tty->echo_buf + tty->echo_pos; 552 cp = ldata->echo_buf + ldata->echo_pos;
511 nr = tty->echo_cnt; 553 nr = ldata->echo_cnt;
512 while (nr > 0) { 554 while (nr > 0) {
513 c = *cp; 555 c = *cp;
514 if (c == ECHO_OP_START) { 556 if (c == ECHO_OP_START) {
@@ -545,7 +587,7 @@ static void process_echoes(struct tty_struct *tty)
545 * Otherwise, tab spacing is normal. 587 * Otherwise, tab spacing is normal.
546 */ 588 */
547 if (!(num_chars & 0x80)) 589 if (!(num_chars & 0x80))
548 num_chars += tty->canon_column; 590 num_chars += ldata->canon_column;
549 num_bs = 8 - (num_chars & 7); 591 num_bs = 8 - (num_chars & 7);
550 592
551 if (num_bs > space) { 593 if (num_bs > space) {
@@ -555,22 +597,22 @@ static void process_echoes(struct tty_struct *tty)
555 space -= num_bs; 597 space -= num_bs;
556 while (num_bs--) { 598 while (num_bs--) {
557 tty_put_char(tty, '\b'); 599 tty_put_char(tty, '\b');
558 if (tty->column > 0) 600 if (ldata->column > 0)
559 tty->column--; 601 ldata->column--;
560 } 602 }
561 cp += 3; 603 cp += 3;
562 nr -= 3; 604 nr -= 3;
563 break; 605 break;
564 606
565 case ECHO_OP_SET_CANON_COL: 607 case ECHO_OP_SET_CANON_COL:
566 tty->canon_column = tty->column; 608 ldata->canon_column = ldata->column;
567 cp += 2; 609 cp += 2;
568 nr -= 2; 610 nr -= 2;
569 break; 611 break;
570 612
571 case ECHO_OP_MOVE_BACK_COL: 613 case ECHO_OP_MOVE_BACK_COL:
572 if (tty->column > 0) 614 if (ldata->column > 0)
573 tty->column--; 615 ldata->column--;
574 cp += 2; 616 cp += 2;
575 nr -= 2; 617 nr -= 2;
576 break; 618 break;
@@ -582,7 +624,7 @@ static void process_echoes(struct tty_struct *tty)
582 break; 624 break;
583 } 625 }
584 tty_put_char(tty, ECHO_OP_START); 626 tty_put_char(tty, ECHO_OP_START);
585 tty->column++; 627 ldata->column++;
586 space--; 628 space--;
587 cp += 2; 629 cp += 2;
588 nr -= 2; 630 nr -= 2;
@@ -604,7 +646,7 @@ static void process_echoes(struct tty_struct *tty)
604 } 646 }
605 tty_put_char(tty, '^'); 647 tty_put_char(tty, '^');
606 tty_put_char(tty, op ^ 0100); 648 tty_put_char(tty, op ^ 0100);
607 tty->column += 2; 649 ldata->column += 2;
608 space -= 2; 650 space -= 2;
609 cp += 2; 651 cp += 2;
610 nr -= 2; 652 nr -= 2;
@@ -635,20 +677,20 @@ static void process_echoes(struct tty_struct *tty)
635 } 677 }
636 678
637 if (nr == 0) { 679 if (nr == 0) {
638 tty->echo_pos = 0; 680 ldata->echo_pos = 0;
639 tty->echo_cnt = 0; 681 ldata->echo_cnt = 0;
640 tty->echo_overrun = 0; 682 ldata->echo_overrun = 0;
641 } else { 683 } else {
642 int num_processed = tty->echo_cnt - nr; 684 int num_processed = ldata->echo_cnt - nr;
643 tty->echo_pos += num_processed; 685 ldata->echo_pos += num_processed;
644 tty->echo_pos &= N_TTY_BUF_SIZE - 1; 686 ldata->echo_pos &= N_TTY_BUF_SIZE - 1;
645 tty->echo_cnt = nr; 687 ldata->echo_cnt = nr;
646 if (num_processed > 0) 688 if (num_processed > 0)
647 tty->echo_overrun = 0; 689 ldata->echo_overrun = 0;
648 } 690 }
649 691
650 mutex_unlock(&tty->echo_lock); 692 mutex_unlock(&ldata->echo_lock);
651 mutex_unlock(&tty->output_lock); 693 mutex_unlock(&ldata->output_lock);
652 694
653 if (tty->ops->flush_chars) 695 if (tty->ops->flush_chars)
654 tty->ops->flush_chars(tty); 696 tty->ops->flush_chars(tty);
@@ -657,72 +699,70 @@ static void process_echoes(struct tty_struct *tty)
657/** 699/**
658 * add_echo_byte - add a byte to the echo buffer 700 * add_echo_byte - add a byte to the echo buffer
659 * @c: unicode byte to echo 701 * @c: unicode byte to echo
660 * @tty: terminal device 702 * @ldata: n_tty data
661 * 703 *
662 * Add a character or operation byte to the echo buffer. 704 * Add a character or operation byte to the echo buffer.
663 * 705 *
664 * Should be called under the echo lock to protect the echo buffer. 706 * Should be called under the echo lock to protect the echo buffer.
665 */ 707 */
666 708
667static void add_echo_byte(unsigned char c, struct tty_struct *tty) 709static void add_echo_byte(unsigned char c, struct n_tty_data *ldata)
668{ 710{
669 int new_byte_pos; 711 int new_byte_pos;
670 712
671 if (tty->echo_cnt == N_TTY_BUF_SIZE) { 713 if (ldata->echo_cnt == N_TTY_BUF_SIZE) {
672 /* Circular buffer is already at capacity */ 714 /* Circular buffer is already at capacity */
673 new_byte_pos = tty->echo_pos; 715 new_byte_pos = ldata->echo_pos;
674 716
675 /* 717 /*
676 * Since the buffer start position needs to be advanced, 718 * Since the buffer start position needs to be advanced,
677 * be sure to step by a whole operation byte group. 719 * be sure to step by a whole operation byte group.
678 */ 720 */
679 if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) { 721 if (ldata->echo_buf[ldata->echo_pos] == ECHO_OP_START) {
680 if (tty->echo_buf[(tty->echo_pos + 1) & 722 if (ldata->echo_buf[(ldata->echo_pos + 1) &
681 (N_TTY_BUF_SIZE - 1)] == 723 (N_TTY_BUF_SIZE - 1)] ==
682 ECHO_OP_ERASE_TAB) { 724 ECHO_OP_ERASE_TAB) {
683 tty->echo_pos += 3; 725 ldata->echo_pos += 3;
684 tty->echo_cnt -= 2; 726 ldata->echo_cnt -= 2;
685 } else { 727 } else {
686 tty->echo_pos += 2; 728 ldata->echo_pos += 2;
687 tty->echo_cnt -= 1; 729 ldata->echo_cnt -= 1;
688 } 730 }
689 } else { 731 } else {
690 tty->echo_pos++; 732 ldata->echo_pos++;
691 } 733 }
692 tty->echo_pos &= N_TTY_BUF_SIZE - 1; 734 ldata->echo_pos &= N_TTY_BUF_SIZE - 1;
693 735
694 tty->echo_overrun = 1; 736 ldata->echo_overrun = 1;
695 } else { 737 } else {
696 new_byte_pos = tty->echo_pos + tty->echo_cnt; 738 new_byte_pos = ldata->echo_pos + ldata->echo_cnt;
697 new_byte_pos &= N_TTY_BUF_SIZE - 1; 739 new_byte_pos &= N_TTY_BUF_SIZE - 1;
698 tty->echo_cnt++; 740 ldata->echo_cnt++;
699 } 741 }
700 742
701 tty->echo_buf[new_byte_pos] = c; 743 ldata->echo_buf[new_byte_pos] = c;
702} 744}
703 745
704/** 746/**
705 * echo_move_back_col - add operation to move back a column 747 * echo_move_back_col - add operation to move back a column
706 * @tty: terminal device 748 * @ldata: n_tty data
707 * 749 *
708 * Add an operation to the echo buffer to move back one column. 750 * Add an operation to the echo buffer to move back one column.
709 * 751 *
710 * Locking: echo_lock to protect the echo buffer 752 * Locking: echo_lock to protect the echo buffer
711 */ 753 */
712 754
713static void echo_move_back_col(struct tty_struct *tty) 755static void echo_move_back_col(struct n_tty_data *ldata)
714{ 756{
715 mutex_lock(&tty->echo_lock); 757 mutex_lock(&ldata->echo_lock);
716 758 add_echo_byte(ECHO_OP_START, ldata);
717 add_echo_byte(ECHO_OP_START, tty); 759 add_echo_byte(ECHO_OP_MOVE_BACK_COL, ldata);
718 add_echo_byte(ECHO_OP_MOVE_BACK_COL, tty); 760 mutex_unlock(&ldata->echo_lock);
719
720 mutex_unlock(&tty->echo_lock);
721} 761}
722 762
723/** 763/**
724 * echo_set_canon_col - add operation to set the canon column 764 * echo_set_canon_col - add operation to set the canon column
725 * @tty: terminal device 765 * @ldata: n_tty data
726 * 766 *
727 * Add an operation to the echo buffer to set the canon column 767 * Add an operation to the echo buffer to set the canon column
728 * to the current column. 768 * to the current column.
@@ -730,21 +770,19 @@ static void echo_move_back_col(struct tty_struct *tty)
730 * Locking: echo_lock to protect the echo buffer 770 * Locking: echo_lock to protect the echo buffer
731 */ 771 */
732 772
733static void echo_set_canon_col(struct tty_struct *tty) 773static void echo_set_canon_col(struct n_tty_data *ldata)
734{ 774{
735 mutex_lock(&tty->echo_lock); 775 mutex_lock(&ldata->echo_lock);
736 776 add_echo_byte(ECHO_OP_START, ldata);
737 add_echo_byte(ECHO_OP_START, tty); 777 add_echo_byte(ECHO_OP_SET_CANON_COL, ldata);
738 add_echo_byte(ECHO_OP_SET_CANON_COL, tty); 778 mutex_unlock(&ldata->echo_lock);
739
740 mutex_unlock(&tty->echo_lock);
741} 779}
742 780
743/** 781/**
744 * echo_erase_tab - add operation to erase a tab 782 * echo_erase_tab - add operation to erase a tab
745 * @num_chars: number of character columns already used 783 * @num_chars: number of character columns already used
746 * @after_tab: true if num_chars starts after a previous tab 784 * @after_tab: true if num_chars starts after a previous tab
747 * @tty: terminal device 785 * @ldata: n_tty data
748 * 786 *
749 * Add an operation to the echo buffer to erase a tab. 787 * Add an operation to the echo buffer to erase a tab.
750 * 788 *
@@ -758,12 +796,12 @@ static void echo_set_canon_col(struct tty_struct *tty)
758 */ 796 */
759 797
760static void echo_erase_tab(unsigned int num_chars, int after_tab, 798static void echo_erase_tab(unsigned int num_chars, int after_tab,
761 struct tty_struct *tty) 799 struct n_tty_data *ldata)
762{ 800{
763 mutex_lock(&tty->echo_lock); 801 mutex_lock(&ldata->echo_lock);
764 802
765 add_echo_byte(ECHO_OP_START, tty); 803 add_echo_byte(ECHO_OP_START, ldata);
766 add_echo_byte(ECHO_OP_ERASE_TAB, tty); 804 add_echo_byte(ECHO_OP_ERASE_TAB, ldata);
767 805
768 /* We only need to know this modulo 8 (tab spacing) */ 806 /* We only need to know this modulo 8 (tab spacing) */
769 num_chars &= 7; 807 num_chars &= 7;
@@ -772,9 +810,9 @@ static void echo_erase_tab(unsigned int num_chars, int after_tab,
772 if (after_tab) 810 if (after_tab)
773 num_chars |= 0x80; 811 num_chars |= 0x80;
774 812
775 add_echo_byte(num_chars, tty); 813 add_echo_byte(num_chars, ldata);
776 814
777 mutex_unlock(&tty->echo_lock); 815 mutex_unlock(&ldata->echo_lock);
778} 816}
779 817
780/** 818/**
@@ -790,18 +828,16 @@ static void echo_erase_tab(unsigned int num_chars, int after_tab,
790 * Locking: echo_lock to protect the echo buffer 828 * Locking: echo_lock to protect the echo buffer
791 */ 829 */
792 830
793static void echo_char_raw(unsigned char c, struct tty_struct *tty) 831static void echo_char_raw(unsigned char c, struct n_tty_data *ldata)
794{ 832{
795 mutex_lock(&tty->echo_lock); 833 mutex_lock(&ldata->echo_lock);
796
797 if (c == ECHO_OP_START) { 834 if (c == ECHO_OP_START) {
798 add_echo_byte(ECHO_OP_START, tty); 835 add_echo_byte(ECHO_OP_START, ldata);
799 add_echo_byte(ECHO_OP_START, tty); 836 add_echo_byte(ECHO_OP_START, ldata);
800 } else { 837 } else {
801 add_echo_byte(c, tty); 838 add_echo_byte(c, ldata);
802 } 839 }
803 840 mutex_unlock(&ldata->echo_lock);
804 mutex_unlock(&tty->echo_lock);
805} 841}
806 842
807/** 843/**
@@ -820,30 +856,32 @@ static void echo_char_raw(unsigned char c, struct tty_struct *tty)
820 856
821static void echo_char(unsigned char c, struct tty_struct *tty) 857static void echo_char(unsigned char c, struct tty_struct *tty)
822{ 858{
823 mutex_lock(&tty->echo_lock); 859 struct n_tty_data *ldata = tty->disc_data;
860
861 mutex_lock(&ldata->echo_lock);
824 862
825 if (c == ECHO_OP_START) { 863 if (c == ECHO_OP_START) {
826 add_echo_byte(ECHO_OP_START, tty); 864 add_echo_byte(ECHO_OP_START, ldata);
827 add_echo_byte(ECHO_OP_START, tty); 865 add_echo_byte(ECHO_OP_START, ldata);
828 } else { 866 } else {
829 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') 867 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t')
830 add_echo_byte(ECHO_OP_START, tty); 868 add_echo_byte(ECHO_OP_START, ldata);
831 add_echo_byte(c, tty); 869 add_echo_byte(c, ldata);
832 } 870 }
833 871
834 mutex_unlock(&tty->echo_lock); 872 mutex_unlock(&ldata->echo_lock);
835} 873}
836 874
837/** 875/**
838 * finish_erasing - complete erase 876 * finish_erasing - complete erase
839 * @tty: tty doing the erase 877 * @ldata: n_tty data
840 */ 878 */
841 879
842static inline void finish_erasing(struct tty_struct *tty) 880static inline void finish_erasing(struct n_tty_data *ldata)
843{ 881{
844 if (tty->erasing) { 882 if (ldata->erasing) {
845 echo_char_raw('/', tty); 883 echo_char_raw('/', ldata);
846 tty->erasing = 0; 884 ldata->erasing = 0;
847 } 885 }
848} 886}
849 887
@@ -861,12 +899,13 @@ static inline void finish_erasing(struct tty_struct *tty)
861 899
862static void eraser(unsigned char c, struct tty_struct *tty) 900static void eraser(unsigned char c, struct tty_struct *tty)
863{ 901{
902 struct n_tty_data *ldata = tty->disc_data;
864 enum { ERASE, WERASE, KILL } kill_type; 903 enum { ERASE, WERASE, KILL } kill_type;
865 int head, seen_alnums, cnt; 904 int head, seen_alnums, cnt;
866 unsigned long flags; 905 unsigned long flags;
867 906
868 /* FIXME: locking needed ? */ 907 /* FIXME: locking needed ? */
869 if (tty->read_head == tty->canon_head) { 908 if (ldata->read_head == ldata->canon_head) {
870 /* process_output('\a', tty); */ /* what do you think? */ 909 /* process_output('\a', tty); */ /* what do you think? */
871 return; 910 return;
872 } 911 }
@@ -876,24 +915,24 @@ static void eraser(unsigned char c, struct tty_struct *tty)
876 kill_type = WERASE; 915 kill_type = WERASE;
877 else { 916 else {
878 if (!L_ECHO(tty)) { 917 if (!L_ECHO(tty)) {
879 spin_lock_irqsave(&tty->read_lock, flags); 918 spin_lock_irqsave(&ldata->read_lock, flags);
880 tty->read_cnt -= ((tty->read_head - tty->canon_head) & 919 ldata->read_cnt -= ((ldata->read_head - ldata->canon_head) &
881 (N_TTY_BUF_SIZE - 1)); 920 (N_TTY_BUF_SIZE - 1));
882 tty->read_head = tty->canon_head; 921 ldata->read_head = ldata->canon_head;
883 spin_unlock_irqrestore(&tty->read_lock, flags); 922 spin_unlock_irqrestore(&ldata->read_lock, flags);
884 return; 923 return;
885 } 924 }
886 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { 925 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) {
887 spin_lock_irqsave(&tty->read_lock, flags); 926 spin_lock_irqsave(&ldata->read_lock, flags);
888 tty->read_cnt -= ((tty->read_head - tty->canon_head) & 927 ldata->read_cnt -= ((ldata->read_head - ldata->canon_head) &
889 (N_TTY_BUF_SIZE - 1)); 928 (N_TTY_BUF_SIZE - 1));
890 tty->read_head = tty->canon_head; 929 ldata->read_head = ldata->canon_head;
891 spin_unlock_irqrestore(&tty->read_lock, flags); 930 spin_unlock_irqrestore(&ldata->read_lock, flags);
892 finish_erasing(tty); 931 finish_erasing(ldata);
893 echo_char(KILL_CHAR(tty), tty); 932 echo_char(KILL_CHAR(tty), tty);
894 /* Add a newline if ECHOK is on and ECHOKE is off. */ 933 /* Add a newline if ECHOK is on and ECHOKE is off. */
895 if (L_ECHOK(tty)) 934 if (L_ECHOK(tty))
896 echo_char_raw('\n', tty); 935 echo_char_raw('\n', ldata);
897 return; 936 return;
898 } 937 }
899 kill_type = KILL; 938 kill_type = KILL;
@@ -901,14 +940,14 @@ static void eraser(unsigned char c, struct tty_struct *tty)
901 940
902 seen_alnums = 0; 941 seen_alnums = 0;
903 /* FIXME: Locking ?? */ 942 /* FIXME: Locking ?? */
904 while (tty->read_head != tty->canon_head) { 943 while (ldata->read_head != ldata->canon_head) {
905 head = tty->read_head; 944 head = ldata->read_head;
906 945
907 /* erase a single possibly multibyte character */ 946 /* erase a single possibly multibyte character */
908 do { 947 do {
909 head = (head - 1) & (N_TTY_BUF_SIZE-1); 948 head = (head - 1) & (N_TTY_BUF_SIZE-1);
910 c = tty->read_buf[head]; 949 c = ldata->read_buf[head];
911 } while (is_continuation(c, tty) && head != tty->canon_head); 950 } while (is_continuation(c, tty) && head != ldata->canon_head);
912 951
913 /* do not partially erase */ 952 /* do not partially erase */
914 if (is_continuation(c, tty)) 953 if (is_continuation(c, tty))
@@ -921,30 +960,31 @@ static void eraser(unsigned char c, struct tty_struct *tty)
921 else if (seen_alnums) 960 else if (seen_alnums)
922 break; 961 break;
923 } 962 }
924 cnt = (tty->read_head - head) & (N_TTY_BUF_SIZE-1); 963 cnt = (ldata->read_head - head) & (N_TTY_BUF_SIZE-1);
925 spin_lock_irqsave(&tty->read_lock, flags); 964 spin_lock_irqsave(&ldata->read_lock, flags);
926 tty->read_head = head; 965 ldata->read_head = head;
927 tty->read_cnt -= cnt; 966 ldata->read_cnt -= cnt;
928 spin_unlock_irqrestore(&tty->read_lock, flags); 967 spin_unlock_irqrestore(&ldata->read_lock, flags);
929 if (L_ECHO(tty)) { 968 if (L_ECHO(tty)) {
930 if (L_ECHOPRT(tty)) { 969 if (L_ECHOPRT(tty)) {
931 if (!tty->erasing) { 970 if (!ldata->erasing) {
932 echo_char_raw('\\', tty); 971 echo_char_raw('\\', ldata);
933 tty->erasing = 1; 972 ldata->erasing = 1;
934 } 973 }
935 /* if cnt > 1, output a multi-byte character */ 974 /* if cnt > 1, output a multi-byte character */
936 echo_char(c, tty); 975 echo_char(c, tty);
937 while (--cnt > 0) { 976 while (--cnt > 0) {
938 head = (head+1) & (N_TTY_BUF_SIZE-1); 977 head = (head+1) & (N_TTY_BUF_SIZE-1);
939 echo_char_raw(tty->read_buf[head], tty); 978 echo_char_raw(ldata->read_buf[head],
940 echo_move_back_col(tty); 979 ldata);
980 echo_move_back_col(ldata);
941 } 981 }
942 } else if (kill_type == ERASE && !L_ECHOE(tty)) { 982 } else if (kill_type == ERASE && !L_ECHOE(tty)) {
943 echo_char(ERASE_CHAR(tty), tty); 983 echo_char(ERASE_CHAR(tty), tty);
944 } else if (c == '\t') { 984 } else if (c == '\t') {
945 unsigned int num_chars = 0; 985 unsigned int num_chars = 0;
946 int after_tab = 0; 986 int after_tab = 0;
947 unsigned long tail = tty->read_head; 987 unsigned long tail = ldata->read_head;
948 988
949 /* 989 /*
950 * Count the columns used for characters 990 * Count the columns used for characters
@@ -953,9 +993,9 @@ static void eraser(unsigned char c, struct tty_struct *tty)
953 * This info is used to go back the correct 993 * This info is used to go back the correct
954 * number of columns. 994 * number of columns.
955 */ 995 */
956 while (tail != tty->canon_head) { 996 while (tail != ldata->canon_head) {
957 tail = (tail-1) & (N_TTY_BUF_SIZE-1); 997 tail = (tail-1) & (N_TTY_BUF_SIZE-1);
958 c = tty->read_buf[tail]; 998 c = ldata->read_buf[tail];
959 if (c == '\t') { 999 if (c == '\t') {
960 after_tab = 1; 1000 after_tab = 1;
961 break; 1001 break;
@@ -966,25 +1006,25 @@ static void eraser(unsigned char c, struct tty_struct *tty)
966 num_chars++; 1006 num_chars++;
967 } 1007 }
968 } 1008 }
969 echo_erase_tab(num_chars, after_tab, tty); 1009 echo_erase_tab(num_chars, after_tab, ldata);
970 } else { 1010 } else {
971 if (iscntrl(c) && L_ECHOCTL(tty)) { 1011 if (iscntrl(c) && L_ECHOCTL(tty)) {
972 echo_char_raw('\b', tty); 1012 echo_char_raw('\b', ldata);
973 echo_char_raw(' ', tty); 1013 echo_char_raw(' ', ldata);
974 echo_char_raw('\b', tty); 1014 echo_char_raw('\b', ldata);
975 } 1015 }
976 if (!iscntrl(c) || L_ECHOCTL(tty)) { 1016 if (!iscntrl(c) || L_ECHOCTL(tty)) {
977 echo_char_raw('\b', tty); 1017 echo_char_raw('\b', ldata);
978 echo_char_raw(' ', tty); 1018 echo_char_raw(' ', ldata);
979 echo_char_raw('\b', tty); 1019 echo_char_raw('\b', ldata);
980 } 1020 }
981 } 1021 }
982 } 1022 }
983 if (kill_type == ERASE) 1023 if (kill_type == ERASE)
984 break; 1024 break;
985 } 1025 }
986 if (tty->read_head == tty->canon_head && L_ECHO(tty)) 1026 if (ldata->read_head == ldata->canon_head && L_ECHO(tty))
987 finish_erasing(tty); 1027 finish_erasing(ldata);
988} 1028}
989 1029
990/** 1030/**
@@ -1023,6 +1063,8 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
1023 1063
1024static inline void n_tty_receive_break(struct tty_struct *tty) 1064static inline void n_tty_receive_break(struct tty_struct *tty)
1025{ 1065{
1066 struct n_tty_data *ldata = tty->disc_data;
1067
1026 if (I_IGNBRK(tty)) 1068 if (I_IGNBRK(tty))
1027 return; 1069 return;
1028 if (I_BRKINT(tty)) { 1070 if (I_BRKINT(tty)) {
@@ -1030,10 +1072,10 @@ static inline void n_tty_receive_break(struct tty_struct *tty)
1030 return; 1072 return;
1031 } 1073 }
1032 if (I_PARMRK(tty)) { 1074 if (I_PARMRK(tty)) {
1033 put_tty_queue('\377', tty); 1075 put_tty_queue('\377', ldata);
1034 put_tty_queue('\0', tty); 1076 put_tty_queue('\0', ldata);
1035 } 1077 }
1036 put_tty_queue('\0', tty); 1078 put_tty_queue('\0', ldata);
1037 wake_up_interruptible(&tty->read_wait); 1079 wake_up_interruptible(&tty->read_wait);
1038} 1080}
1039 1081
@@ -1052,16 +1094,17 @@ static inline void n_tty_receive_break(struct tty_struct *tty)
1052 1094
1053static inline void n_tty_receive_overrun(struct tty_struct *tty) 1095static inline void n_tty_receive_overrun(struct tty_struct *tty)
1054{ 1096{
1097 struct n_tty_data *ldata = tty->disc_data;
1055 char buf[64]; 1098 char buf[64];
1056 1099
1057 tty->num_overrun++; 1100 ldata->num_overrun++;
1058 if (time_before(tty->overrun_time, jiffies - HZ) || 1101 if (time_after(jiffies, ldata->overrun_time + HZ) ||
1059 time_after(tty->overrun_time, jiffies)) { 1102 time_after(ldata->overrun_time, jiffies)) {
1060 printk(KERN_WARNING "%s: %d input overrun(s)\n", 1103 printk(KERN_WARNING "%s: %d input overrun(s)\n",
1061 tty_name(tty, buf), 1104 tty_name(tty, buf),
1062 tty->num_overrun); 1105 ldata->num_overrun);
1063 tty->overrun_time = jiffies; 1106 ldata->overrun_time = jiffies;
1064 tty->num_overrun = 0; 1107 ldata->num_overrun = 0;
1065 } 1108 }
1066} 1109}
1067 1110
@@ -1076,16 +1119,18 @@ static inline void n_tty_receive_overrun(struct tty_struct *tty)
1076static inline void n_tty_receive_parity_error(struct tty_struct *tty, 1119static inline void n_tty_receive_parity_error(struct tty_struct *tty,
1077 unsigned char c) 1120 unsigned char c)
1078{ 1121{
1122 struct n_tty_data *ldata = tty->disc_data;
1123
1079 if (I_IGNPAR(tty)) 1124 if (I_IGNPAR(tty))
1080 return; 1125 return;
1081 if (I_PARMRK(tty)) { 1126 if (I_PARMRK(tty)) {
1082 put_tty_queue('\377', tty); 1127 put_tty_queue('\377', ldata);
1083 put_tty_queue('\0', tty); 1128 put_tty_queue('\0', ldata);
1084 put_tty_queue(c, tty); 1129 put_tty_queue(c, ldata);
1085 } else if (I_INPCK(tty)) 1130 } else if (I_INPCK(tty))
1086 put_tty_queue('\0', tty); 1131 put_tty_queue('\0', ldata);
1087 else 1132 else
1088 put_tty_queue(c, tty); 1133 put_tty_queue(c, ldata);
1089 wake_up_interruptible(&tty->read_wait); 1134 wake_up_interruptible(&tty->read_wait);
1090} 1135}
1091 1136
@@ -1101,11 +1146,12 @@ static inline void n_tty_receive_parity_error(struct tty_struct *tty,
1101 1146
1102static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) 1147static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1103{ 1148{
1149 struct n_tty_data *ldata = tty->disc_data;
1104 unsigned long flags; 1150 unsigned long flags;
1105 int parmrk; 1151 int parmrk;
1106 1152
1107 if (tty->raw) { 1153 if (ldata->raw) {
1108 put_tty_queue(c, tty); 1154 put_tty_queue(c, ldata);
1109 return; 1155 return;
1110 } 1156 }
1111 1157
@@ -1115,7 +1161,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1115 c = tolower(c); 1161 c = tolower(c);
1116 1162
1117 if (L_EXTPROC(tty)) { 1163 if (L_EXTPROC(tty)) {
1118 put_tty_queue(c, tty); 1164 put_tty_queue(c, ldata);
1119 return; 1165 return;
1120 } 1166 }
1121 1167
@@ -1143,26 +1189,26 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1143 * handle specially, do shortcut processing to speed things 1189 * handle specially, do shortcut processing to speed things
1144 * up. 1190 * up.
1145 */ 1191 */
1146 if (!test_bit(c, tty->process_char_map) || tty->lnext) { 1192 if (!test_bit(c, ldata->process_char_map) || ldata->lnext) {
1147 tty->lnext = 0; 1193 ldata->lnext = 0;
1148 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; 1194 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1149 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { 1195 if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1150 /* beep if no space */ 1196 /* beep if no space */
1151 if (L_ECHO(tty)) 1197 if (L_ECHO(tty))
1152 process_output('\a', tty); 1198 process_output('\a', tty);
1153 return; 1199 return;
1154 } 1200 }
1155 if (L_ECHO(tty)) { 1201 if (L_ECHO(tty)) {
1156 finish_erasing(tty); 1202 finish_erasing(ldata);
1157 /* Record the column of first canon char. */ 1203 /* Record the column of first canon char. */
1158 if (tty->canon_head == tty->read_head) 1204 if (ldata->canon_head == ldata->read_head)
1159 echo_set_canon_col(tty); 1205 echo_set_canon_col(ldata);
1160 echo_char(c, tty); 1206 echo_char(c, tty);
1161 process_echoes(tty); 1207 process_echoes(tty);
1162 } 1208 }
1163 if (parmrk) 1209 if (parmrk)
1164 put_tty_queue(c, tty); 1210 put_tty_queue(c, ldata);
1165 put_tty_queue(c, tty); 1211 put_tty_queue(c, ldata);
1166 return; 1212 return;
1167 } 1213 }
1168 1214
@@ -1218,7 +1264,7 @@ send_signal:
1218 } else if (c == '\n' && I_INLCR(tty)) 1264 } else if (c == '\n' && I_INLCR(tty))
1219 c = '\r'; 1265 c = '\r';
1220 1266
1221 if (tty->icanon) { 1267 if (ldata->icanon) {
1222 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || 1268 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) ||
1223 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { 1269 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) {
1224 eraser(c, tty); 1270 eraser(c, tty);
@@ -1226,12 +1272,12 @@ send_signal:
1226 return; 1272 return;
1227 } 1273 }
1228 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { 1274 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) {
1229 tty->lnext = 1; 1275 ldata->lnext = 1;
1230 if (L_ECHO(tty)) { 1276 if (L_ECHO(tty)) {
1231 finish_erasing(tty); 1277 finish_erasing(ldata);
1232 if (L_ECHOCTL(tty)) { 1278 if (L_ECHOCTL(tty)) {
1233 echo_char_raw('^', tty); 1279 echo_char_raw('^', ldata);
1234 echo_char_raw('\b', tty); 1280 echo_char_raw('\b', ldata);
1235 process_echoes(tty); 1281 process_echoes(tty);
1236 } 1282 }
1237 } 1283 }
@@ -1239,34 +1285,34 @@ send_signal:
1239 } 1285 }
1240 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && 1286 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) &&
1241 L_IEXTEN(tty)) { 1287 L_IEXTEN(tty)) {
1242 unsigned long tail = tty->canon_head; 1288 unsigned long tail = ldata->canon_head;
1243 1289
1244 finish_erasing(tty); 1290 finish_erasing(ldata);
1245 echo_char(c, tty); 1291 echo_char(c, tty);
1246 echo_char_raw('\n', tty); 1292 echo_char_raw('\n', ldata);
1247 while (tail != tty->read_head) { 1293 while (tail != ldata->read_head) {
1248 echo_char(tty->read_buf[tail], tty); 1294 echo_char(ldata->read_buf[tail], tty);
1249 tail = (tail+1) & (N_TTY_BUF_SIZE-1); 1295 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
1250 } 1296 }
1251 process_echoes(tty); 1297 process_echoes(tty);
1252 return; 1298 return;
1253 } 1299 }
1254 if (c == '\n') { 1300 if (c == '\n') {
1255 if (tty->read_cnt >= N_TTY_BUF_SIZE) { 1301 if (ldata->read_cnt >= N_TTY_BUF_SIZE) {
1256 if (L_ECHO(tty)) 1302 if (L_ECHO(tty))
1257 process_output('\a', tty); 1303 process_output('\a', tty);
1258 return; 1304 return;
1259 } 1305 }
1260 if (L_ECHO(tty) || L_ECHONL(tty)) { 1306 if (L_ECHO(tty) || L_ECHONL(tty)) {
1261 echo_char_raw('\n', tty); 1307 echo_char_raw('\n', ldata);
1262 process_echoes(tty); 1308 process_echoes(tty);
1263 } 1309 }
1264 goto handle_newline; 1310 goto handle_newline;
1265 } 1311 }
1266 if (c == EOF_CHAR(tty)) { 1312 if (c == EOF_CHAR(tty)) {
1267 if (tty->read_cnt >= N_TTY_BUF_SIZE) 1313 if (ldata->read_cnt >= N_TTY_BUF_SIZE)
1268 return; 1314 return;
1269 if (tty->canon_head != tty->read_head) 1315 if (ldata->canon_head != ldata->read_head)
1270 set_bit(TTY_PUSH, &tty->flags); 1316 set_bit(TTY_PUSH, &tty->flags);
1271 c = __DISABLED_CHAR; 1317 c = __DISABLED_CHAR;
1272 goto handle_newline; 1318 goto handle_newline;
@@ -1275,7 +1321,7 @@ send_signal:
1275 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { 1321 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) {
1276 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) 1322 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty))
1277 ? 1 : 0; 1323 ? 1 : 0;
1278 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) { 1324 if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) {
1279 if (L_ECHO(tty)) 1325 if (L_ECHO(tty))
1280 process_output('\a', tty); 1326 process_output('\a', tty);
1281 return; 1327 return;
@@ -1285,8 +1331,8 @@ send_signal:
1285 */ 1331 */
1286 if (L_ECHO(tty)) { 1332 if (L_ECHO(tty)) {
1287 /* Record the column of first canon char. */ 1333 /* Record the column of first canon char. */
1288 if (tty->canon_head == tty->read_head) 1334 if (ldata->canon_head == ldata->read_head)
1289 echo_set_canon_col(tty); 1335 echo_set_canon_col(ldata);
1290 echo_char(c, tty); 1336 echo_char(c, tty);
1291 process_echoes(tty); 1337 process_echoes(tty);
1292 } 1338 }
@@ -1295,15 +1341,15 @@ send_signal:
1295 * EOL_CHAR and EOL2_CHAR? 1341 * EOL_CHAR and EOL2_CHAR?
1296 */ 1342 */
1297 if (parmrk) 1343 if (parmrk)
1298 put_tty_queue(c, tty); 1344 put_tty_queue(c, ldata);
1299 1345
1300handle_newline: 1346handle_newline:
1301 spin_lock_irqsave(&tty->read_lock, flags); 1347 spin_lock_irqsave(&ldata->read_lock, flags);
1302 set_bit(tty->read_head, tty->read_flags); 1348 set_bit(ldata->read_head, ldata->read_flags);
1303 put_tty_queue_nolock(c, tty); 1349 put_tty_queue_nolock(c, ldata);
1304 tty->canon_head = tty->read_head; 1350 ldata->canon_head = ldata->read_head;
1305 tty->canon_data++; 1351 ldata->canon_data++;
1306 spin_unlock_irqrestore(&tty->read_lock, flags); 1352 spin_unlock_irqrestore(&ldata->read_lock, flags);
1307 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1353 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1308 if (waitqueue_active(&tty->read_wait)) 1354 if (waitqueue_active(&tty->read_wait))
1309 wake_up_interruptible(&tty->read_wait); 1355 wake_up_interruptible(&tty->read_wait);
@@ -1312,29 +1358,29 @@ handle_newline:
1312 } 1358 }
1313 1359
1314 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; 1360 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1315 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { 1361 if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1316 /* beep if no space */ 1362 /* beep if no space */
1317 if (L_ECHO(tty)) 1363 if (L_ECHO(tty))
1318 process_output('\a', tty); 1364 process_output('\a', tty);
1319 return; 1365 return;
1320 } 1366 }
1321 if (L_ECHO(tty)) { 1367 if (L_ECHO(tty)) {
1322 finish_erasing(tty); 1368 finish_erasing(ldata);
1323 if (c == '\n') 1369 if (c == '\n')
1324 echo_char_raw('\n', tty); 1370 echo_char_raw('\n', ldata);
1325 else { 1371 else {
1326 /* Record the column of first canon char. */ 1372 /* Record the column of first canon char. */
1327 if (tty->canon_head == tty->read_head) 1373 if (ldata->canon_head == ldata->read_head)
1328 echo_set_canon_col(tty); 1374 echo_set_canon_col(ldata);
1329 echo_char(c, tty); 1375 echo_char(c, tty);
1330 } 1376 }
1331 process_echoes(tty); 1377 process_echoes(tty);
1332 } 1378 }
1333 1379
1334 if (parmrk) 1380 if (parmrk)
1335 put_tty_queue(c, tty); 1381 put_tty_queue(c, ldata);
1336 1382
1337 put_tty_queue(c, tty); 1383 put_tty_queue(c, ldata);
1338} 1384}
1339 1385
1340 1386
@@ -1369,33 +1415,31 @@ static void n_tty_write_wakeup(struct tty_struct *tty)
1369static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, 1415static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1370 char *fp, int count) 1416 char *fp, int count)
1371{ 1417{
1418 struct n_tty_data *ldata = tty->disc_data;
1372 const unsigned char *p; 1419 const unsigned char *p;
1373 char *f, flags = TTY_NORMAL; 1420 char *f, flags = TTY_NORMAL;
1374 int i; 1421 int i;
1375 char buf[64]; 1422 char buf[64];
1376 unsigned long cpuflags; 1423 unsigned long cpuflags;
1377 1424
1378 if (!tty->read_buf) 1425 if (ldata->real_raw) {
1379 return; 1426 spin_lock_irqsave(&ldata->read_lock, cpuflags);
1380 1427 i = min(N_TTY_BUF_SIZE - ldata->read_cnt,
1381 if (tty->real_raw) { 1428 N_TTY_BUF_SIZE - ldata->read_head);
1382 spin_lock_irqsave(&tty->read_lock, cpuflags);
1383 i = min(N_TTY_BUF_SIZE - tty->read_cnt,
1384 N_TTY_BUF_SIZE - tty->read_head);
1385 i = min(count, i); 1429 i = min(count, i);
1386 memcpy(tty->read_buf + tty->read_head, cp, i); 1430 memcpy(ldata->read_buf + ldata->read_head, cp, i);
1387 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1); 1431 ldata->read_head = (ldata->read_head + i) & (N_TTY_BUF_SIZE-1);
1388 tty->read_cnt += i; 1432 ldata->read_cnt += i;
1389 cp += i; 1433 cp += i;
1390 count -= i; 1434 count -= i;
1391 1435
1392 i = min(N_TTY_BUF_SIZE - tty->read_cnt, 1436 i = min(N_TTY_BUF_SIZE - ldata->read_cnt,
1393 N_TTY_BUF_SIZE - tty->read_head); 1437 N_TTY_BUF_SIZE - ldata->read_head);
1394 i = min(count, i); 1438 i = min(count, i);
1395 memcpy(tty->read_buf + tty->read_head, cp, i); 1439 memcpy(ldata->read_buf + ldata->read_head, cp, i);
1396 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1); 1440 ldata->read_head = (ldata->read_head + i) & (N_TTY_BUF_SIZE-1);
1397 tty->read_cnt += i; 1441 ldata->read_cnt += i;
1398 spin_unlock_irqrestore(&tty->read_lock, cpuflags); 1442 spin_unlock_irqrestore(&ldata->read_lock, cpuflags);
1399 } else { 1443 } else {
1400 for (i = count, p = cp, f = fp; i; i--, p++) { 1444 for (i = count, p = cp, f = fp; i; i--, p++) {
1401 if (f) 1445 if (f)
@@ -1426,7 +1470,7 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1426 1470
1427 n_tty_set_room(tty); 1471 n_tty_set_room(tty);
1428 1472
1429 if ((!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) || 1473 if ((!ldata->icanon && (ldata->read_cnt >= tty->minimum_to_wake)) ||
1430 L_EXTPROC(tty)) { 1474 L_EXTPROC(tty)) {
1431 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1475 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1432 if (waitqueue_active(&tty->read_wait)) 1476 if (waitqueue_active(&tty->read_wait))
@@ -1470,25 +1514,25 @@ int is_ignored(int sig)
1470 1514
1471static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) 1515static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1472{ 1516{
1517 struct n_tty_data *ldata = tty->disc_data;
1473 int canon_change = 1; 1518 int canon_change = 1;
1474 BUG_ON(!tty);
1475 1519
1476 if (old) 1520 if (old)
1477 canon_change = (old->c_lflag ^ tty->termios.c_lflag) & ICANON; 1521 canon_change = (old->c_lflag ^ tty->termios.c_lflag) & ICANON;
1478 if (canon_change) { 1522 if (canon_change) {
1479 memset(&tty->read_flags, 0, sizeof tty->read_flags); 1523 bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE);
1480 tty->canon_head = tty->read_tail; 1524 ldata->canon_head = ldata->read_tail;
1481 tty->canon_data = 0; 1525 ldata->canon_data = 0;
1482 tty->erasing = 0; 1526 ldata->erasing = 0;
1483 } 1527 }
1484 1528
1485 if (canon_change && !L_ICANON(tty) && tty->read_cnt) 1529 if (canon_change && !L_ICANON(tty) && ldata->read_cnt)
1486 wake_up_interruptible(&tty->read_wait); 1530 wake_up_interruptible(&tty->read_wait);
1487 1531
1488 tty->icanon = (L_ICANON(tty) != 0); 1532 ldata->icanon = (L_ICANON(tty) != 0);
1489 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) { 1533 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) {
1490 tty->raw = 1; 1534 ldata->raw = 1;
1491 tty->real_raw = 1; 1535 ldata->real_raw = 1;
1492 n_tty_set_room(tty); 1536 n_tty_set_room(tty);
1493 return; 1537 return;
1494 } 1538 }
@@ -1496,51 +1540,51 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1496 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || 1540 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) ||
1497 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || 1541 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) ||
1498 I_PARMRK(tty)) { 1542 I_PARMRK(tty)) {
1499 memset(tty->process_char_map, 0, 256/8); 1543 bitmap_zero(ldata->process_char_map, 256);
1500 1544
1501 if (I_IGNCR(tty) || I_ICRNL(tty)) 1545 if (I_IGNCR(tty) || I_ICRNL(tty))
1502 set_bit('\r', tty->process_char_map); 1546 set_bit('\r', ldata->process_char_map);
1503 if (I_INLCR(tty)) 1547 if (I_INLCR(tty))
1504 set_bit('\n', tty->process_char_map); 1548 set_bit('\n', ldata->process_char_map);
1505 1549
1506 if (L_ICANON(tty)) { 1550 if (L_ICANON(tty)) {
1507 set_bit(ERASE_CHAR(tty), tty->process_char_map); 1551 set_bit(ERASE_CHAR(tty), ldata->process_char_map);
1508 set_bit(KILL_CHAR(tty), tty->process_char_map); 1552 set_bit(KILL_CHAR(tty), ldata->process_char_map);
1509 set_bit(EOF_CHAR(tty), tty->process_char_map); 1553 set_bit(EOF_CHAR(tty), ldata->process_char_map);
1510 set_bit('\n', tty->process_char_map); 1554 set_bit('\n', ldata->process_char_map);
1511 set_bit(EOL_CHAR(tty), tty->process_char_map); 1555 set_bit(EOL_CHAR(tty), ldata->process_char_map);
1512 if (L_IEXTEN(tty)) { 1556 if (L_IEXTEN(tty)) {
1513 set_bit(WERASE_CHAR(tty), 1557 set_bit(WERASE_CHAR(tty),
1514 tty->process_char_map); 1558 ldata->process_char_map);
1515 set_bit(LNEXT_CHAR(tty), 1559 set_bit(LNEXT_CHAR(tty),
1516 tty->process_char_map); 1560 ldata->process_char_map);
1517 set_bit(EOL2_CHAR(tty), 1561 set_bit(EOL2_CHAR(tty),
1518 tty->process_char_map); 1562 ldata->process_char_map);
1519 if (L_ECHO(tty)) 1563 if (L_ECHO(tty))
1520 set_bit(REPRINT_CHAR(tty), 1564 set_bit(REPRINT_CHAR(tty),
1521 tty->process_char_map); 1565 ldata->process_char_map);
1522 } 1566 }
1523 } 1567 }
1524 if (I_IXON(tty)) { 1568 if (I_IXON(tty)) {
1525 set_bit(START_CHAR(tty), tty->process_char_map); 1569 set_bit(START_CHAR(tty), ldata->process_char_map);
1526 set_bit(STOP_CHAR(tty), tty->process_char_map); 1570 set_bit(STOP_CHAR(tty), ldata->process_char_map);
1527 } 1571 }
1528 if (L_ISIG(tty)) { 1572 if (L_ISIG(tty)) {
1529 set_bit(INTR_CHAR(tty), tty->process_char_map); 1573 set_bit(INTR_CHAR(tty), ldata->process_char_map);
1530 set_bit(QUIT_CHAR(tty), tty->process_char_map); 1574 set_bit(QUIT_CHAR(tty), ldata->process_char_map);
1531 set_bit(SUSP_CHAR(tty), tty->process_char_map); 1575 set_bit(SUSP_CHAR(tty), ldata->process_char_map);
1532 } 1576 }
1533 clear_bit(__DISABLED_CHAR, tty->process_char_map); 1577 clear_bit(__DISABLED_CHAR, ldata->process_char_map);
1534 tty->raw = 0; 1578 ldata->raw = 0;
1535 tty->real_raw = 0; 1579 ldata->real_raw = 0;
1536 } else { 1580 } else {
1537 tty->raw = 1; 1581 ldata->raw = 1;
1538 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && 1582 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) &&
1539 (I_IGNPAR(tty) || !I_INPCK(tty)) && 1583 (I_IGNPAR(tty) || !I_INPCK(tty)) &&
1540 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) 1584 (tty->driver->flags & TTY_DRIVER_REAL_RAW))
1541 tty->real_raw = 1; 1585 ldata->real_raw = 1;
1542 else 1586 else
1543 tty->real_raw = 0; 1587 ldata->real_raw = 0;
1544 } 1588 }
1545 n_tty_set_room(tty); 1589 n_tty_set_room(tty);
1546 /* The termios change make the tty ready for I/O */ 1590 /* The termios change make the tty ready for I/O */
@@ -1560,15 +1604,13 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1560 1604
1561static void n_tty_close(struct tty_struct *tty) 1605static void n_tty_close(struct tty_struct *tty)
1562{ 1606{
1607 struct n_tty_data *ldata = tty->disc_data;
1608
1563 n_tty_flush_buffer(tty); 1609 n_tty_flush_buffer(tty);
1564 if (tty->read_buf) { 1610 kfree(ldata->read_buf);
1565 kfree(tty->read_buf); 1611 kfree(ldata->echo_buf);
1566 tty->read_buf = NULL; 1612 kfree(ldata);
1567 } 1613 tty->disc_data = NULL;
1568 if (tty->echo_buf) {
1569 kfree(tty->echo_buf);
1570 tty->echo_buf = NULL;
1571 }
1572} 1614}
1573 1615
1574/** 1616/**
@@ -1583,37 +1625,50 @@ static void n_tty_close(struct tty_struct *tty)
1583 1625
1584static int n_tty_open(struct tty_struct *tty) 1626static int n_tty_open(struct tty_struct *tty)
1585{ 1627{
1586 if (!tty) 1628 struct n_tty_data *ldata;
1587 return -EINVAL; 1629
1630 ldata = kzalloc(sizeof(*ldata), GFP_KERNEL);
1631 if (!ldata)
1632 goto err;
1633
1634 ldata->overrun_time = jiffies;
1635 mutex_init(&ldata->atomic_read_lock);
1636 mutex_init(&ldata->output_lock);
1637 mutex_init(&ldata->echo_lock);
1638 spin_lock_init(&ldata->read_lock);
1588 1639
1589 /* These are ugly. Currently a malloc failure here can panic */ 1640 /* These are ugly. Currently a malloc failure here can panic */
1590 if (!tty->read_buf) { 1641 ldata->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1591 tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); 1642 ldata->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1592 if (!tty->read_buf) 1643 if (!ldata->read_buf || !ldata->echo_buf)
1593 return -ENOMEM; 1644 goto err_free_bufs;
1594 }
1595 if (!tty->echo_buf) {
1596 tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1597 1645
1598 if (!tty->echo_buf) 1646 tty->disc_data = ldata;
1599 return -ENOMEM;
1600 }
1601 reset_buffer_flags(tty); 1647 reset_buffer_flags(tty);
1602 tty_unthrottle(tty); 1648 tty_unthrottle(tty);
1603 tty->column = 0; 1649 ldata->column = 0;
1604 n_tty_set_termios(tty, NULL); 1650 n_tty_set_termios(tty, NULL);
1605 tty->minimum_to_wake = 1; 1651 tty->minimum_to_wake = 1;
1606 tty->closing = 0; 1652 tty->closing = 0;
1653
1607 return 0; 1654 return 0;
1655err_free_bufs:
1656 kfree(ldata->read_buf);
1657 kfree(ldata->echo_buf);
1658 kfree(ldata);
1659err:
1660 return -ENOMEM;
1608} 1661}
1609 1662
1610static inline int input_available_p(struct tty_struct *tty, int amt) 1663static inline int input_available_p(struct tty_struct *tty, int amt)
1611{ 1664{
1665 struct n_tty_data *ldata = tty->disc_data;
1666
1612 tty_flush_to_ldisc(tty); 1667 tty_flush_to_ldisc(tty);
1613 if (tty->icanon && !L_EXTPROC(tty)) { 1668 if (ldata->icanon && !L_EXTPROC(tty)) {
1614 if (tty->canon_data) 1669 if (ldata->canon_data)
1615 return 1; 1670 return 1;
1616 } else if (tty->read_cnt >= (amt ? amt : 1)) 1671 } else if (ldata->read_cnt >= (amt ? amt : 1))
1617 return 1; 1672 return 1;
1618 1673
1619 return 0; 1674 return 0;
@@ -1632,7 +1687,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
1632 * buffer, and once to drain the space from the (physical) beginning of 1687 * buffer, and once to drain the space from the (physical) beginning of
1633 * the buffer to head pointer. 1688 * the buffer to head pointer.
1634 * 1689 *
1635 * Called under the tty->atomic_read_lock sem 1690 * Called under the ldata->atomic_read_lock sem
1636 * 1691 *
1637 */ 1692 */
1638 1693
@@ -1641,29 +1696,31 @@ static int copy_from_read_buf(struct tty_struct *tty,
1641 size_t *nr) 1696 size_t *nr)
1642 1697
1643{ 1698{
1699 struct n_tty_data *ldata = tty->disc_data;
1644 int retval; 1700 int retval;
1645 size_t n; 1701 size_t n;
1646 unsigned long flags; 1702 unsigned long flags;
1647 bool is_eof; 1703 bool is_eof;
1648 1704
1649 retval = 0; 1705 retval = 0;
1650 spin_lock_irqsave(&tty->read_lock, flags); 1706 spin_lock_irqsave(&ldata->read_lock, flags);
1651 n = min(tty->read_cnt, N_TTY_BUF_SIZE - tty->read_tail); 1707 n = min(ldata->read_cnt, N_TTY_BUF_SIZE - ldata->read_tail);
1652 n = min(*nr, n); 1708 n = min(*nr, n);
1653 spin_unlock_irqrestore(&tty->read_lock, flags); 1709 spin_unlock_irqrestore(&ldata->read_lock, flags);
1654 if (n) { 1710 if (n) {
1655 retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n); 1711 retval = copy_to_user(*b, &ldata->read_buf[ldata->read_tail], n);
1656 n -= retval; 1712 n -= retval;
1657 is_eof = n == 1 && 1713 is_eof = n == 1 &&
1658 tty->read_buf[tty->read_tail] == EOF_CHAR(tty); 1714 ldata->read_buf[ldata->read_tail] == EOF_CHAR(tty);
1659 tty_audit_add_data(tty, &tty->read_buf[tty->read_tail], n); 1715 tty_audit_add_data(tty, &ldata->read_buf[ldata->read_tail], n,
1660 spin_lock_irqsave(&tty->read_lock, flags); 1716 ldata->icanon);
1661 tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1); 1717 spin_lock_irqsave(&ldata->read_lock, flags);
1662 tty->read_cnt -= n; 1718 ldata->read_tail = (ldata->read_tail + n) & (N_TTY_BUF_SIZE-1);
1719 ldata->read_cnt -= n;
1663 /* Turn single EOF into zero-length read */ 1720 /* Turn single EOF into zero-length read */
1664 if (L_EXTPROC(tty) && tty->icanon && is_eof && !tty->read_cnt) 1721 if (L_EXTPROC(tty) && ldata->icanon && is_eof && !ldata->read_cnt)
1665 n = 0; 1722 n = 0;
1666 spin_unlock_irqrestore(&tty->read_lock, flags); 1723 spin_unlock_irqrestore(&ldata->read_lock, flags);
1667 *b += n; 1724 *b += n;
1668 *nr -= n; 1725 *nr -= n;
1669 } 1726 }
@@ -1730,6 +1787,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
1730static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, 1787static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
1731 unsigned char __user *buf, size_t nr) 1788 unsigned char __user *buf, size_t nr)
1732{ 1789{
1790 struct n_tty_data *ldata = tty->disc_data;
1733 unsigned char __user *b = buf; 1791 unsigned char __user *b = buf;
1734 DECLARE_WAITQUEUE(wait, current); 1792 DECLARE_WAITQUEUE(wait, current);
1735 int c; 1793 int c;
@@ -1741,17 +1799,13 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
1741 int packet; 1799 int packet;
1742 1800
1743do_it_again: 1801do_it_again:
1744
1745 if (WARN_ON(!tty->read_buf))
1746 return -EAGAIN;
1747
1748 c = job_control(tty, file); 1802 c = job_control(tty, file);
1749 if (c < 0) 1803 if (c < 0)
1750 return c; 1804 return c;
1751 1805
1752 minimum = time = 0; 1806 minimum = time = 0;
1753 timeout = MAX_SCHEDULE_TIMEOUT; 1807 timeout = MAX_SCHEDULE_TIMEOUT;
1754 if (!tty->icanon) { 1808 if (!ldata->icanon) {
1755 time = (HZ / 10) * TIME_CHAR(tty); 1809 time = (HZ / 10) * TIME_CHAR(tty);
1756 minimum = MIN_CHAR(tty); 1810 minimum = MIN_CHAR(tty);
1757 if (minimum) { 1811 if (minimum) {
@@ -1774,10 +1828,10 @@ do_it_again:
1774 * Internal serialization of reads. 1828 * Internal serialization of reads.
1775 */ 1829 */
1776 if (file->f_flags & O_NONBLOCK) { 1830 if (file->f_flags & O_NONBLOCK) {
1777 if (!mutex_trylock(&tty->atomic_read_lock)) 1831 if (!mutex_trylock(&ldata->atomic_read_lock))
1778 return -EAGAIN; 1832 return -EAGAIN;
1779 } else { 1833 } else {
1780 if (mutex_lock_interruptible(&tty->atomic_read_lock)) 1834 if (mutex_lock_interruptible(&ldata->atomic_read_lock))
1781 return -ERESTARTSYS; 1835 return -ERESTARTSYS;
1782 } 1836 }
1783 packet = tty->packet; 1837 packet = tty->packet;
@@ -1830,7 +1884,6 @@ do_it_again:
1830 /* FIXME: does n_tty_set_room need locking ? */ 1884 /* FIXME: does n_tty_set_room need locking ? */
1831 n_tty_set_room(tty); 1885 n_tty_set_room(tty);
1832 timeout = schedule_timeout(timeout); 1886 timeout = schedule_timeout(timeout);
1833 BUG_ON(!tty->read_buf);
1834 continue; 1887 continue;
1835 } 1888 }
1836 __set_current_state(TASK_RUNNING); 1889 __set_current_state(TASK_RUNNING);
@@ -1845,45 +1898,45 @@ do_it_again:
1845 nr--; 1898 nr--;
1846 } 1899 }
1847 1900
1848 if (tty->icanon && !L_EXTPROC(tty)) { 1901 if (ldata->icanon && !L_EXTPROC(tty)) {
1849 /* N.B. avoid overrun if nr == 0 */ 1902 /* N.B. avoid overrun if nr == 0 */
1850 spin_lock_irqsave(&tty->read_lock, flags); 1903 spin_lock_irqsave(&ldata->read_lock, flags);
1851 while (nr && tty->read_cnt) { 1904 while (nr && ldata->read_cnt) {
1852 int eol; 1905 int eol;
1853 1906
1854 eol = test_and_clear_bit(tty->read_tail, 1907 eol = test_and_clear_bit(ldata->read_tail,
1855 tty->read_flags); 1908 ldata->read_flags);
1856 c = tty->read_buf[tty->read_tail]; 1909 c = ldata->read_buf[ldata->read_tail];
1857 tty->read_tail = ((tty->read_tail+1) & 1910 ldata->read_tail = ((ldata->read_tail+1) &
1858 (N_TTY_BUF_SIZE-1)); 1911 (N_TTY_BUF_SIZE-1));
1859 tty->read_cnt--; 1912 ldata->read_cnt--;
1860 if (eol) { 1913 if (eol) {
1861 /* this test should be redundant: 1914 /* this test should be redundant:
1862 * we shouldn't be reading data if 1915 * we shouldn't be reading data if
1863 * canon_data is 0 1916 * canon_data is 0
1864 */ 1917 */
1865 if (--tty->canon_data < 0) 1918 if (--ldata->canon_data < 0)
1866 tty->canon_data = 0; 1919 ldata->canon_data = 0;
1867 } 1920 }
1868 spin_unlock_irqrestore(&tty->read_lock, flags); 1921 spin_unlock_irqrestore(&ldata->read_lock, flags);
1869 1922
1870 if (!eol || (c != __DISABLED_CHAR)) { 1923 if (!eol || (c != __DISABLED_CHAR)) {
1871 if (tty_put_user(tty, c, b++)) { 1924 if (tty_put_user(tty, c, b++)) {
1872 retval = -EFAULT; 1925 retval = -EFAULT;
1873 b--; 1926 b--;
1874 spin_lock_irqsave(&tty->read_lock, flags); 1927 spin_lock_irqsave(&ldata->read_lock, flags);
1875 break; 1928 break;
1876 } 1929 }
1877 nr--; 1930 nr--;
1878 } 1931 }
1879 if (eol) { 1932 if (eol) {
1880 tty_audit_push(tty); 1933 tty_audit_push(tty);
1881 spin_lock_irqsave(&tty->read_lock, flags); 1934 spin_lock_irqsave(&ldata->read_lock, flags);
1882 break; 1935 break;
1883 } 1936 }
1884 spin_lock_irqsave(&tty->read_lock, flags); 1937 spin_lock_irqsave(&ldata->read_lock, flags);
1885 } 1938 }
1886 spin_unlock_irqrestore(&tty->read_lock, flags); 1939 spin_unlock_irqrestore(&ldata->read_lock, flags);
1887 if (retval) 1940 if (retval)
1888 break; 1941 break;
1889 } else { 1942 } else {
@@ -1915,7 +1968,7 @@ do_it_again:
1915 if (time) 1968 if (time)
1916 timeout = time; 1969 timeout = time;
1917 } 1970 }
1918 mutex_unlock(&tty->atomic_read_lock); 1971 mutex_unlock(&ldata->atomic_read_lock);
1919 remove_wait_queue(&tty->read_wait, &wait); 1972 remove_wait_queue(&tty->read_wait, &wait);
1920 1973
1921 if (!waitqueue_active(&tty->read_wait)) 1974 if (!waitqueue_active(&tty->read_wait))
@@ -2076,19 +2129,19 @@ static unsigned int n_tty_poll(struct tty_struct *tty, struct file *file,
2076 return mask; 2129 return mask;
2077} 2130}
2078 2131
2079static unsigned long inq_canon(struct tty_struct *tty) 2132static unsigned long inq_canon(struct n_tty_data *ldata)
2080{ 2133{
2081 int nr, head, tail; 2134 int nr, head, tail;
2082 2135
2083 if (!tty->canon_data) 2136 if (!ldata->canon_data)
2084 return 0; 2137 return 0;
2085 head = tty->canon_head; 2138 head = ldata->canon_head;
2086 tail = tty->read_tail; 2139 tail = ldata->read_tail;
2087 nr = (head - tail) & (N_TTY_BUF_SIZE-1); 2140 nr = (head - tail) & (N_TTY_BUF_SIZE-1);
2088 /* Skip EOF-chars.. */ 2141 /* Skip EOF-chars.. */
2089 while (head != tail) { 2142 while (head != tail) {
2090 if (test_bit(tail, tty->read_flags) && 2143 if (test_bit(tail, ldata->read_flags) &&
2091 tty->read_buf[tail] == __DISABLED_CHAR) 2144 ldata->read_buf[tail] == __DISABLED_CHAR)
2092 nr--; 2145 nr--;
2093 tail = (tail+1) & (N_TTY_BUF_SIZE-1); 2146 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
2094 } 2147 }
@@ -2098,6 +2151,7 @@ static unsigned long inq_canon(struct tty_struct *tty)
2098static int n_tty_ioctl(struct tty_struct *tty, struct file *file, 2151static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
2099 unsigned int cmd, unsigned long arg) 2152 unsigned int cmd, unsigned long arg)
2100{ 2153{
2154 struct n_tty_data *ldata = tty->disc_data;
2101 int retval; 2155 int retval;
2102 2156
2103 switch (cmd) { 2157 switch (cmd) {
@@ -2105,9 +2159,9 @@ static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
2105 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); 2159 return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
2106 case TIOCINQ: 2160 case TIOCINQ:
2107 /* FIXME: Locking */ 2161 /* FIXME: Locking */
2108 retval = tty->read_cnt; 2162 retval = ldata->read_cnt;
2109 if (L_ICANON(tty)) 2163 if (L_ICANON(tty))
2110 retval = inq_canon(tty); 2164 retval = inq_canon(ldata);
2111 return put_user(retval, (unsigned int __user *) arg); 2165 return put_user(retval, (unsigned int __user *) arg);
2112 default: 2166 default:
2113 return n_tty_ioctl_helper(tty, file, cmd, arg); 2167 return n_tty_ioctl_helper(tty, file, cmd, arg);
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index a82b39939a9c..4219f040adb8 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -4,9 +4,6 @@
4 * Added support for a Unix98-style ptmx device. 4 * Added support for a Unix98-style ptmx device.
5 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998 5 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998
6 * 6 *
7 * When reading this code see also fs/devpts. In particular note that the
8 * driver_data field is used by the devpts side as a binding to the devpts
9 * inode.
10 */ 7 */
11 8
12#include <linux/module.h> 9#include <linux/module.h>
@@ -59,7 +56,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
59#ifdef CONFIG_UNIX98_PTYS 56#ifdef CONFIG_UNIX98_PTYS
60 if (tty->driver == ptm_driver) { 57 if (tty->driver == ptm_driver) {
61 mutex_lock(&devpts_mutex); 58 mutex_lock(&devpts_mutex);
62 devpts_pty_kill(tty->link); 59 devpts_pty_kill(tty->link->driver_data);
63 mutex_unlock(&devpts_mutex); 60 mutex_unlock(&devpts_mutex);
64 } 61 }
65#endif 62#endif
@@ -96,7 +93,7 @@ static void pty_unthrottle(struct tty_struct *tty)
96 93
97static int pty_space(struct tty_struct *to) 94static int pty_space(struct tty_struct *to)
98{ 95{
99 int n = 8192 - to->buf.memory_used; 96 int n = 8192 - to->port->buf.memory_used;
100 if (n < 0) 97 if (n < 0)
101 return 0; 98 return 0;
102 return n; 99 return n;
@@ -348,6 +345,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
348 tty_port_init(ports[1]); 345 tty_port_init(ports[1]);
349 o_tty->port = ports[0]; 346 o_tty->port = ports[0];
350 tty->port = ports[1]; 347 tty->port = ports[1];
348 o_tty->port->itty = o_tty;
351 349
352 tty_driver_kref_get(driver); 350 tty_driver_kref_get(driver);
353 tty->count++; 351 tty->count++;
@@ -366,8 +364,15 @@ err:
366 return retval; 364 return retval;
367} 365}
368 366
367/* this is called once with whichever end is closed last */
368static void pty_unix98_shutdown(struct tty_struct *tty)
369{
370 devpts_kill_index(tty->driver_data, tty->index);
371}
372
369static void pty_cleanup(struct tty_struct *tty) 373static void pty_cleanup(struct tty_struct *tty)
370{ 374{
375 tty->port->itty = NULL;
371 kfree(tty->port); 376 kfree(tty->port);
372} 377}
373 378
@@ -547,7 +552,7 @@ static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
547 struct tty_struct *tty; 552 struct tty_struct *tty;
548 553
549 mutex_lock(&devpts_mutex); 554 mutex_lock(&devpts_mutex);
550 tty = devpts_get_tty(pts_inode, idx); 555 tty = devpts_get_priv(pts_inode);
551 mutex_unlock(&devpts_mutex); 556 mutex_unlock(&devpts_mutex);
552 /* Master must be open before slave */ 557 /* Master must be open before slave */
553 if (!tty) 558 if (!tty)
@@ -581,6 +586,7 @@ static const struct tty_operations ptm_unix98_ops = {
581 .set_termios = pty_set_termios, 586 .set_termios = pty_set_termios,
582 .ioctl = pty_unix98_ioctl, 587 .ioctl = pty_unix98_ioctl,
583 .resize = pty_resize, 588 .resize = pty_resize,
589 .shutdown = pty_unix98_shutdown,
584 .cleanup = pty_cleanup 590 .cleanup = pty_cleanup
585}; 591};
586 592
@@ -596,6 +602,7 @@ static const struct tty_operations pty_unix98_ops = {
596 .chars_in_buffer = pty_chars_in_buffer, 602 .chars_in_buffer = pty_chars_in_buffer,
597 .unthrottle = pty_unthrottle, 603 .unthrottle = pty_unthrottle,
598 .set_termios = pty_set_termios, 604 .set_termios = pty_set_termios,
605 .shutdown = pty_unix98_shutdown,
599 .cleanup = pty_cleanup, 606 .cleanup = pty_cleanup,
600}; 607};
601 608
@@ -614,6 +621,7 @@ static const struct tty_operations pty_unix98_ops = {
614static int ptmx_open(struct inode *inode, struct file *filp) 621static int ptmx_open(struct inode *inode, struct file *filp)
615{ 622{
616 struct tty_struct *tty; 623 struct tty_struct *tty;
624 struct inode *slave_inode;
617 int retval; 625 int retval;
618 int index; 626 int index;
619 627
@@ -650,15 +658,21 @@ static int ptmx_open(struct inode *inode, struct file *filp)
650 658
651 tty_add_file(tty, filp); 659 tty_add_file(tty, filp);
652 660
653 retval = devpts_pty_new(inode, tty->link); 661 slave_inode = devpts_pty_new(inode,
654 if (retval) 662 MKDEV(UNIX98_PTY_SLAVE_MAJOR, index), index,
663 tty->link);
664 if (IS_ERR(slave_inode)) {
665 retval = PTR_ERR(slave_inode);
655 goto err_release; 666 goto err_release;
667 }
656 668
657 retval = ptm_driver->ops->open(tty, filp); 669 retval = ptm_driver->ops->open(tty, filp);
658 if (retval) 670 if (retval)
659 goto err_release; 671 goto err_release;
660 672
661 tty_unlock(tty); 673 tty_unlock(tty);
674 tty->driver_data = inode;
675 tty->link->driver_data = slave_inode;
662 return 0; 676 return 0;
663err_release: 677err_release:
664 tty_unlock(tty); 678 tty_unlock(tty);
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c
index 3ba4234592bc..5ccbd90540cf 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250.c
@@ -2349,16 +2349,14 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2349 serial_port_out(port, UART_EFR, efr); 2349 serial_port_out(port, UART_EFR, efr);
2350 } 2350 }
2351 2351
2352#ifdef CONFIG_ARCH_OMAP1
2353 /* Workaround to enable 115200 baud on OMAP1510 internal ports */ 2352 /* Workaround to enable 115200 baud on OMAP1510 internal ports */
2354 if (cpu_is_omap1510() && is_omap_port(up)) { 2353 if (is_omap1510_8250(up)) {
2355 if (baud == 115200) { 2354 if (baud == 115200) {
2356 quot = 1; 2355 quot = 1;
2357 serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); 2356 serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1);
2358 } else 2357 } else
2359 serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); 2358 serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0);
2360 } 2359 }
2361#endif
2362 2360
2363 /* 2361 /*
2364 * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, 2362 * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2,
@@ -2439,10 +2437,9 @@ static unsigned int serial8250_port_size(struct uart_8250_port *pt)
2439{ 2437{
2440 if (pt->port.iotype == UPIO_AU) 2438 if (pt->port.iotype == UPIO_AU)
2441 return 0x1000; 2439 return 0x1000;
2442#ifdef CONFIG_ARCH_OMAP1 2440 if (is_omap1_8250(pt))
2443 if (is_omap_port(pt))
2444 return 0x16 << pt->port.regshift; 2441 return 0x16 << pt->port.regshift;
2445#endif 2442
2446 return 8 << pt->port.regshift; 2443 return 8 << pt->port.regshift;
2447} 2444}
2448 2445
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index 5a76f9c8d36b..3b4ea84898c2 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -106,3 +106,39 @@ static inline int serial8250_pnp_init(void) { return 0; }
106static inline void serial8250_pnp_exit(void) { } 106static inline void serial8250_pnp_exit(void) { }
107#endif 107#endif
108 108
109#ifdef CONFIG_ARCH_OMAP1
110static inline int is_omap1_8250(struct uart_8250_port *pt)
111{
112 int res;
113
114 switch (pt->port.mapbase) {
115 case OMAP1_UART1_BASE:
116 case OMAP1_UART2_BASE:
117 case OMAP1_UART3_BASE:
118 res = 1;
119 break;
120 default:
121 res = 0;
122 break;
123 }
124
125 return res;
126}
127
128static inline int is_omap1510_8250(struct uart_8250_port *pt)
129{
130 if (!cpu_is_omap1510())
131 return 0;
132
133 return is_omap1_8250(pt);
134}
135#else
136static inline int is_omap1_8250(struct uart_8250_port *pt)
137{
138 return 0;
139}
140static inline int is_omap1510_8250(struct uart_8250_port *pt)
141{
142 return 0;
143}
144#endif
diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c
index eaafb98debed..843a150ba105 100644
--- a/drivers/tty/serial/8250/8250_early.c
+++ b/drivers/tty/serial/8250/8250_early.c
@@ -140,7 +140,7 @@ static void __init init_port(struct early_serial8250_device *device)
140 serial_out(port, UART_FCR, 0); /* no fifo */ 140 serial_out(port, UART_FCR, 0); /* no fifo */
141 serial_out(port, UART_MCR, 0x3); /* DTR + RTS */ 141 serial_out(port, UART_MCR, 0x3); /* DTR + RTS */
142 142
143 divisor = port->uartclk / (16 * device->baud); 143 divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud);
144 c = serial_in(port, UART_LCR); 144 c = serial_in(port, UART_LCR);
145 serial_out(port, UART_LCR, c | UART_LCR_DLAB); 145 serial_out(port, UART_LCR, c | UART_LCR_DLAB);
146 serial_out(port, UART_DLL, divisor & 0xff); 146 serial_out(port, UART_DLL, divisor & 0xff);
diff --git a/drivers/tty/serial/8250/8250_hp300.c b/drivers/tty/serial/8250/8250_hp300.c
index 8f1dd2cc00a8..f3d0edf46644 100644
--- a/drivers/tty/serial/8250/8250_hp300.c
+++ b/drivers/tty/serial/8250/8250_hp300.c
@@ -162,7 +162,7 @@ int __init hp300_setup_serial_console(void)
162static int __devinit hpdca_init_one(struct dio_dev *d, 162static int __devinit hpdca_init_one(struct dio_dev *d,
163 const struct dio_device_id *ent) 163 const struct dio_device_id *ent)
164{ 164{
165 struct uart_port port; 165 struct uart_8250_port uart;
166 int line; 166 int line;
167 167
168#ifdef CONFIG_SERIAL_8250_CONSOLE 168#ifdef CONFIG_SERIAL_8250_CONSOLE
@@ -174,19 +174,19 @@ static int __devinit hpdca_init_one(struct dio_dev *d,
174 memset(&uart, 0, sizeof(uart)); 174 memset(&uart, 0, sizeof(uart));
175 175
176 /* Memory mapped I/O */ 176 /* Memory mapped I/O */
177 port.iotype = UPIO_MEM; 177 uart.port.iotype = UPIO_MEM;
178 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF; 178 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
179 port.irq = d->ipl; 179 uart.port.irq = d->ipl;
180 port.uartclk = HPDCA_BAUD_BASE * 16; 180 uart.port.uartclk = HPDCA_BAUD_BASE * 16;
181 port.mapbase = (d->resource.start + UART_OFFSET); 181 uart.port.mapbase = (d->resource.start + UART_OFFSET);
182 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE); 182 uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE);
183 port.regshift = 1; 183 uart.port.regshift = 1;
184 port.dev = &d->dev; 184 uart.port.dev = &d->dev;
185 line = serial8250_register_8250_port(&uart); 185 line = serial8250_register_8250_port(&uart);
186 186
187 if (line < 0) { 187 if (line < 0) {
188 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d" 188 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
189 " irq %d failed\n", d->scode, port.irq); 189 " irq %d failed\n", d->scode, uart.port.irq);
190 return -ENOMEM; 190 return -ENOMEM;
191 } 191 }
192 192
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 233fbaaf2559..2a53be5f010d 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1150,7 +1150,7 @@ config SERIAL_SC26XX_CONSOLE
1150 Support for Console on SC2681/SC2692 serial ports. 1150 Support for Console on SC2681/SC2692 serial ports.
1151 1151
1152config SERIAL_SCCNXP 1152config SERIAL_SCCNXP
1153 bool "SCCNXP serial port support" 1153 tristate "SCCNXP serial port support"
1154 depends on !SERIAL_SC26XX 1154 depends on !SERIAL_SC26XX
1155 select SERIAL_CORE 1155 select SERIAL_CORE
1156 default n 1156 default n
@@ -1162,7 +1162,7 @@ config SERIAL_SCCNXP
1162 1162
1163config SERIAL_SCCNXP_CONSOLE 1163config SERIAL_SCCNXP_CONSOLE
1164 bool "Console on SCCNXP serial port" 1164 bool "Console on SCCNXP serial port"
1165 depends on SERIAL_SCCNXP 1165 depends on SERIAL_SCCNXP=y
1166 select SERIAL_CORE_CONSOLE 1166 select SERIAL_CORE_CONSOLE
1167 help 1167 help
1168 Support for console on SCCNXP serial ports. 1168 Support for console on SCCNXP serial ports.
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index 7f04717176aa..740458ca62cc 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -530,16 +530,16 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
530 switch (level) { 530 switch (level) {
531 case 3: 531 case 3:
532 if (!IS_ERR(ourport->baudclk)) 532 if (!IS_ERR(ourport->baudclk))
533 clk_disable(ourport->baudclk); 533 clk_disable_unprepare(ourport->baudclk);
534 534
535 clk_disable(ourport->clk); 535 clk_disable_unprepare(ourport->clk);
536 break; 536 break;
537 537
538 case 0: 538 case 0:
539 clk_enable(ourport->clk); 539 clk_prepare_enable(ourport->clk);
540 540
541 if (!IS_ERR(ourport->baudclk)) 541 if (!IS_ERR(ourport->baudclk))
542 clk_enable(ourport->baudclk); 542 clk_prepare_enable(ourport->baudclk);
543 543
544 break; 544 break;
545 default: 545 default:
@@ -713,11 +713,11 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
713 s3c24xx_serial_setsource(port, clk_sel); 713 s3c24xx_serial_setsource(port, clk_sel);
714 714
715 if (!IS_ERR(ourport->baudclk)) { 715 if (!IS_ERR(ourport->baudclk)) {
716 clk_disable(ourport->baudclk); 716 clk_disable_unprepare(ourport->baudclk);
717 ourport->baudclk = ERR_PTR(-EINVAL); 717 ourport->baudclk = ERR_PTR(-EINVAL);
718 } 718 }
719 719
720 clk_enable(clk); 720 clk_prepare_enable(clk);
721 721
722 ourport->baudclk = clk; 722 ourport->baudclk = clk;
723 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0; 723 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
@@ -1287,9 +1287,9 @@ static int s3c24xx_serial_resume(struct device *dev)
1287 struct s3c24xx_uart_port *ourport = to_ourport(port); 1287 struct s3c24xx_uart_port *ourport = to_ourport(port);
1288 1288
1289 if (port) { 1289 if (port) {
1290 clk_enable(ourport->clk); 1290 clk_prepare_enable(ourport->clk);
1291 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port)); 1291 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
1292 clk_disable(ourport->clk); 1292 clk_disable_unprepare(ourport->clk);
1293 1293
1294 uart_resume_port(&s3c24xx_uart_drv, port); 1294 uart_resume_port(&s3c24xx_uart_drv, port);
1295 } 1295 }
diff --git a/drivers/tty/serial/sccnxp.c b/drivers/tty/serial/sccnxp.c
index b7086d004f5f..e821068cd95b 100644
--- a/drivers/tty/serial/sccnxp.c
+++ b/drivers/tty/serial/sccnxp.c
@@ -971,6 +971,7 @@ static const struct platform_device_id sccnxp_id_table[] = {
971 { "sc28202", SCCNXP_TYPE_SC28202 }, 971 { "sc28202", SCCNXP_TYPE_SC28202 },
972 { "sc68681", SCCNXP_TYPE_SC68681 }, 972 { "sc68681", SCCNXP_TYPE_SC68681 },
973 { "sc68692", SCCNXP_TYPE_SC68692 }, 973 { "sc68692", SCCNXP_TYPE_SC68692 },
974 { },
974}; 975};
975MODULE_DEVICE_TABLE(platform, sccnxp_id_table); 976MODULE_DEVICE_TABLE(platform, sccnxp_id_table);
976 977
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 9be296cf7295..6ee59001d61d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -530,7 +530,8 @@ static inline int sci_rxd_in(struct uart_port *port)
530 if (s->cfg->port_reg <= 0) 530 if (s->cfg->port_reg <= 0)
531 return 1; 531 return 1;
532 532
533 return !!__raw_readb(s->cfg->port_reg); 533 /* Cast for ARM damage */
534 return !!__raw_readb((void __iomem *)s->cfg->port_reg);
534} 535}
535 536
536/* ********************************************************************** * 537/* ********************************************************************** *
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 05728894a88c..16ee6cee07da 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -452,6 +452,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
452 NULL, /* v */ 452 NULL, /* v */
453 &sysrq_showstate_blocked_op, /* w */ 453 &sysrq_showstate_blocked_op, /* w */
454 /* x: May be registered on ppc/powerpc for xmon */ 454 /* x: May be registered on ppc/powerpc for xmon */
455 /* x: May be registered on sparc64 for global PMU dump */
455 NULL, /* x */ 456 NULL, /* x */
456 /* y: May be registered on sparc64 for global register dump */ 457 /* y: May be registered on sparc64 for global register dump */
457 NULL, /* y */ 458 NULL, /* y */
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index b0b39b823ccf..6953dc82850c 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -23,7 +23,7 @@ struct tty_audit_buf {
23}; 23};
24 24
25static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor, 25static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
26 int icanon) 26 unsigned icanon)
27{ 27{
28 struct tty_audit_buf *buf; 28 struct tty_audit_buf *buf;
29 29
@@ -239,7 +239,8 @@ int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid)
239 * if TTY auditing is disabled or out of memory. Otherwise, return a new 239 * if TTY auditing is disabled or out of memory. Otherwise, return a new
240 * reference to the buffer. 240 * reference to the buffer.
241 */ 241 */
242static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty) 242static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
243 unsigned icanon)
243{ 244{
244 struct tty_audit_buf *buf, *buf2; 245 struct tty_audit_buf *buf, *buf2;
245 246
@@ -257,7 +258,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty)
257 258
258 buf2 = tty_audit_buf_alloc(tty->driver->major, 259 buf2 = tty_audit_buf_alloc(tty->driver->major,
259 tty->driver->minor_start + tty->index, 260 tty->driver->minor_start + tty->index,
260 tty->icanon); 261 icanon);
261 if (buf2 == NULL) { 262 if (buf2 == NULL) {
262 audit_log_lost("out of memory in TTY auditing"); 263 audit_log_lost("out of memory in TTY auditing");
263 return NULL; 264 return NULL;
@@ -287,7 +288,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty)
287 * Audit @data of @size from @tty, if necessary. 288 * Audit @data of @size from @tty, if necessary.
288 */ 289 */
289void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, 290void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
290 size_t size) 291 size_t size, unsigned icanon)
291{ 292{
292 struct tty_audit_buf *buf; 293 struct tty_audit_buf *buf;
293 int major, minor; 294 int major, minor;
@@ -299,7 +300,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
299 && tty->driver->subtype == PTY_TYPE_MASTER) 300 && tty->driver->subtype == PTY_TYPE_MASTER)
300 return; 301 return;
301 302
302 buf = tty_audit_buf_get(tty); 303 buf = tty_audit_buf_get(tty, icanon);
303 if (!buf) 304 if (!buf)
304 return; 305 return;
305 306
@@ -307,11 +308,11 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
307 major = tty->driver->major; 308 major = tty->driver->major;
308 minor = tty->driver->minor_start + tty->index; 309 minor = tty->driver->minor_start + tty->index;
309 if (buf->major != major || buf->minor != minor 310 if (buf->major != major || buf->minor != minor
310 || buf->icanon != tty->icanon) { 311 || buf->icanon != icanon) {
311 tty_audit_buf_push_current(buf); 312 tty_audit_buf_push_current(buf);
312 buf->major = major; 313 buf->major = major;
313 buf->minor = minor; 314 buf->minor = minor;
314 buf->icanon = tty->icanon; 315 buf->icanon = icanon;
315 } 316 }
316 do { 317 do {
317 size_t run; 318 size_t run;
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 91e326ffe7db..6cf87d7afb7e 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -27,19 +27,21 @@
27 * Locking: none 27 * Locking: none
28 */ 28 */
29 29
30void tty_buffer_free_all(struct tty_struct *tty) 30void tty_buffer_free_all(struct tty_port *port)
31{ 31{
32 struct tty_bufhead *buf = &port->buf;
32 struct tty_buffer *thead; 33 struct tty_buffer *thead;
33 while ((thead = tty->buf.head) != NULL) { 34
34 tty->buf.head = thead->next; 35 while ((thead = buf->head) != NULL) {
36 buf->head = thead->next;
35 kfree(thead); 37 kfree(thead);
36 } 38 }
37 while ((thead = tty->buf.free) != NULL) { 39 while ((thead = buf->free) != NULL) {
38 tty->buf.free = thead->next; 40 buf->free = thead->next;
39 kfree(thead); 41 kfree(thead);
40 } 42 }
41 tty->buf.tail = NULL; 43 buf->tail = NULL;
42 tty->buf.memory_used = 0; 44 buf->memory_used = 0;
43} 45}
44 46
45/** 47/**
@@ -54,11 +56,11 @@ void tty_buffer_free_all(struct tty_struct *tty)
54 * Locking: Caller must hold tty->buf.lock 56 * Locking: Caller must hold tty->buf.lock
55 */ 57 */
56 58
57static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size) 59static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
58{ 60{
59 struct tty_buffer *p; 61 struct tty_buffer *p;
60 62
61 if (tty->buf.memory_used + size > 65536) 63 if (port->buf.memory_used + size > 65536)
62 return NULL; 64 return NULL;
63 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC); 65 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
64 if (p == NULL) 66 if (p == NULL)
@@ -70,7 +72,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
70 p->read = 0; 72 p->read = 0;
71 p->char_buf_ptr = (char *)(p->data); 73 p->char_buf_ptr = (char *)(p->data);
72 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size; 74 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
73 tty->buf.memory_used += size; 75 port->buf.memory_used += size;
74 return p; 76 return p;
75} 77}
76 78
@@ -85,17 +87,19 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
85 * Locking: Caller must hold tty->buf.lock 87 * Locking: Caller must hold tty->buf.lock
86 */ 88 */
87 89
88static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b) 90static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b)
89{ 91{
92 struct tty_bufhead *buf = &port->buf;
93
90 /* Dumb strategy for now - should keep some stats */ 94 /* Dumb strategy for now - should keep some stats */
91 tty->buf.memory_used -= b->size; 95 buf->memory_used -= b->size;
92 WARN_ON(tty->buf.memory_used < 0); 96 WARN_ON(buf->memory_used < 0);
93 97
94 if (b->size >= 512) 98 if (b->size >= 512)
95 kfree(b); 99 kfree(b);
96 else { 100 else {
97 b->next = tty->buf.free; 101 b->next = buf->free;
98 tty->buf.free = b; 102 buf->free = b;
99 } 103 }
100} 104}
101 105
@@ -110,15 +114,16 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
110 * Locking: Caller must hold tty->buf.lock 114 * Locking: Caller must hold tty->buf.lock
111 */ 115 */
112 116
113static void __tty_buffer_flush(struct tty_struct *tty) 117static void __tty_buffer_flush(struct tty_port *port)
114{ 118{
119 struct tty_bufhead *buf = &port->buf;
115 struct tty_buffer *thead; 120 struct tty_buffer *thead;
116 121
117 while ((thead = tty->buf.head) != NULL) { 122 while ((thead = buf->head) != NULL) {
118 tty->buf.head = thead->next; 123 buf->head = thead->next;
119 tty_buffer_free(tty, thead); 124 tty_buffer_free(port, thead);
120 } 125 }
121 tty->buf.tail = NULL; 126 buf->tail = NULL;
122} 127}
123 128
124/** 129/**
@@ -134,21 +139,24 @@ static void __tty_buffer_flush(struct tty_struct *tty)
134 139
135void tty_buffer_flush(struct tty_struct *tty) 140void tty_buffer_flush(struct tty_struct *tty)
136{ 141{
142 struct tty_port *port = tty->port;
143 struct tty_bufhead *buf = &port->buf;
137 unsigned long flags; 144 unsigned long flags;
138 spin_lock_irqsave(&tty->buf.lock, flags); 145
146 spin_lock_irqsave(&buf->lock, flags);
139 147
140 /* If the data is being pushed to the tty layer then we can't 148 /* If the data is being pushed to the tty layer then we can't
141 process it here. Instead set a flag and the flush_to_ldisc 149 process it here. Instead set a flag and the flush_to_ldisc
142 path will process the flush request before it exits */ 150 path will process the flush request before it exits */
143 if (test_bit(TTY_FLUSHING, &tty->flags)) { 151 if (test_bit(TTYP_FLUSHING, &port->iflags)) {
144 set_bit(TTY_FLUSHPENDING, &tty->flags); 152 set_bit(TTYP_FLUSHPENDING, &port->iflags);
145 spin_unlock_irqrestore(&tty->buf.lock, flags); 153 spin_unlock_irqrestore(&buf->lock, flags);
146 wait_event(tty->read_wait, 154 wait_event(tty->read_wait,
147 test_bit(TTY_FLUSHPENDING, &tty->flags) == 0); 155 test_bit(TTYP_FLUSHPENDING, &port->iflags) == 0);
148 return; 156 return;
149 } else 157 } else
150 __tty_buffer_flush(tty); 158 __tty_buffer_flush(port);
151 spin_unlock_irqrestore(&tty->buf.lock, flags); 159 spin_unlock_irqrestore(&buf->lock, flags);
152} 160}
153 161
154/** 162/**
@@ -163,9 +171,9 @@ void tty_buffer_flush(struct tty_struct *tty)
163 * Locking: Caller must hold tty->buf.lock 171 * Locking: Caller must hold tty->buf.lock
164 */ 172 */
165 173
166static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size) 174static struct tty_buffer *tty_buffer_find(struct tty_port *port, size_t size)
167{ 175{
168 struct tty_buffer **tbh = &tty->buf.free; 176 struct tty_buffer **tbh = &port->buf.free;
169 while ((*tbh) != NULL) { 177 while ((*tbh) != NULL) {
170 struct tty_buffer *t = *tbh; 178 struct tty_buffer *t = *tbh;
171 if (t->size >= size) { 179 if (t->size >= size) {
@@ -174,14 +182,14 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
174 t->used = 0; 182 t->used = 0;
175 t->commit = 0; 183 t->commit = 0;
176 t->read = 0; 184 t->read = 0;
177 tty->buf.memory_used += t->size; 185 port->buf.memory_used += t->size;
178 return t; 186 return t;
179 } 187 }
180 tbh = &((*tbh)->next); 188 tbh = &((*tbh)->next);
181 } 189 }
182 /* Round the buffer size out */ 190 /* Round the buffer size out */
183 size = (size + 0xFF) & ~0xFF; 191 size = (size + 0xFF) & ~0xFF;
184 return tty_buffer_alloc(tty, size); 192 return tty_buffer_alloc(port, size);
185 /* Should possibly check if this fails for the largest buffer we 193 /* Should possibly check if this fails for the largest buffer we
186 have queued and recycle that ? */ 194 have queued and recycle that ? */
187} 195}
@@ -192,29 +200,31 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
192 * 200 *
193 * Make at least size bytes of linear space available for the tty 201 * Make at least size bytes of linear space available for the tty
194 * buffer. If we fail return the size we managed to find. 202 * buffer. If we fail return the size we managed to find.
195 * Locking: Caller must hold tty->buf.lock 203 * Locking: Caller must hold port->buf.lock
196 */ 204 */
197static int __tty_buffer_request_room(struct tty_struct *tty, size_t size) 205static int __tty_buffer_request_room(struct tty_port *port, size_t size)
198{ 206{
207 struct tty_bufhead *buf = &port->buf;
199 struct tty_buffer *b, *n; 208 struct tty_buffer *b, *n;
200 int left; 209 int left;
201 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to 210 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
202 remove this conditional if its worth it. This would be invisible 211 remove this conditional if its worth it. This would be invisible
203 to the callers */ 212 to the callers */
204 if ((b = tty->buf.tail) != NULL) 213 b = buf->tail;
214 if (b != NULL)
205 left = b->size - b->used; 215 left = b->size - b->used;
206 else 216 else
207 left = 0; 217 left = 0;
208 218
209 if (left < size) { 219 if (left < size) {
210 /* This is the slow path - looking for new buffers to use */ 220 /* This is the slow path - looking for new buffers to use */
211 if ((n = tty_buffer_find(tty, size)) != NULL) { 221 if ((n = tty_buffer_find(port, size)) != NULL) {
212 if (b != NULL) { 222 if (b != NULL) {
213 b->next = n; 223 b->next = n;
214 b->commit = b->used; 224 b->commit = b->used;
215 } else 225 } else
216 tty->buf.head = n; 226 buf->head = n;
217 tty->buf.tail = n; 227 buf->tail = n;
218 } else 228 } else
219 size = left; 229 size = left;
220 } 230 }
@@ -231,16 +241,17 @@ static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)
231 * Make at least size bytes of linear space available for the tty 241 * Make at least size bytes of linear space available for the tty
232 * buffer. If we fail return the size we managed to find. 242 * buffer. If we fail return the size we managed to find.
233 * 243 *
234 * Locking: Takes tty->buf.lock 244 * Locking: Takes port->buf.lock
235 */ 245 */
236int tty_buffer_request_room(struct tty_struct *tty, size_t size) 246int tty_buffer_request_room(struct tty_struct *tty, size_t size)
237{ 247{
248 struct tty_port *port = tty->port;
238 unsigned long flags; 249 unsigned long flags;
239 int length; 250 int length;
240 251
241 spin_lock_irqsave(&tty->buf.lock, flags); 252 spin_lock_irqsave(&port->buf.lock, flags);
242 length = __tty_buffer_request_room(tty, size); 253 length = __tty_buffer_request_room(port, size);
243 spin_unlock_irqrestore(&tty->buf.lock, flags); 254 spin_unlock_irqrestore(&port->buf.lock, flags);
244 return length; 255 return length;
245} 256}
246EXPORT_SYMBOL_GPL(tty_buffer_request_room); 257EXPORT_SYMBOL_GPL(tty_buffer_request_room);
@@ -255,12 +266,13 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
255 * Queue a series of bytes to the tty buffering. All the characters 266 * Queue a series of bytes to the tty buffering. All the characters
256 * passed are marked with the supplied flag. Returns the number added. 267 * passed are marked with the supplied flag. Returns the number added.
257 * 268 *
258 * Locking: Called functions may take tty->buf.lock 269 * Locking: Called functions may take port->buf.lock
259 */ 270 */
260 271
261int tty_insert_flip_string_fixed_flag(struct tty_struct *tty, 272int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
262 const unsigned char *chars, char flag, size_t size) 273 const unsigned char *chars, char flag, size_t size)
263{ 274{
275 struct tty_bufhead *buf = &tty->port->buf;
264 int copied = 0; 276 int copied = 0;
265 do { 277 do {
266 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 278 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
@@ -268,18 +280,18 @@ int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
268 unsigned long flags; 280 unsigned long flags;
269 struct tty_buffer *tb; 281 struct tty_buffer *tb;
270 282
271 spin_lock_irqsave(&tty->buf.lock, flags); 283 spin_lock_irqsave(&buf->lock, flags);
272 space = __tty_buffer_request_room(tty, goal); 284 space = __tty_buffer_request_room(tty->port, goal);
273 tb = tty->buf.tail; 285 tb = buf->tail;
274 /* If there is no space then tb may be NULL */ 286 /* If there is no space then tb may be NULL */
275 if (unlikely(space == 0)) { 287 if (unlikely(space == 0)) {
276 spin_unlock_irqrestore(&tty->buf.lock, flags); 288 spin_unlock_irqrestore(&buf->lock, flags);
277 break; 289 break;
278 } 290 }
279 memcpy(tb->char_buf_ptr + tb->used, chars, space); 291 memcpy(tb->char_buf_ptr + tb->used, chars, space);
280 memset(tb->flag_buf_ptr + tb->used, flag, space); 292 memset(tb->flag_buf_ptr + tb->used, flag, space);
281 tb->used += space; 293 tb->used += space;
282 spin_unlock_irqrestore(&tty->buf.lock, flags); 294 spin_unlock_irqrestore(&buf->lock, flags);
283 copied += space; 295 copied += space;
284 chars += space; 296 chars += space;
285 /* There is a small chance that we need to split the data over 297 /* There is a small chance that we need to split the data over
@@ -300,12 +312,13 @@ EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
300 * the flags array indicates the status of the character. Returns the 312 * the flags array indicates the status of the character. Returns the
301 * number added. 313 * number added.
302 * 314 *
303 * Locking: Called functions may take tty->buf.lock 315 * Locking: Called functions may take port->buf.lock
304 */ 316 */
305 317
306int tty_insert_flip_string_flags(struct tty_struct *tty, 318int tty_insert_flip_string_flags(struct tty_struct *tty,
307 const unsigned char *chars, const char *flags, size_t size) 319 const unsigned char *chars, const char *flags, size_t size)
308{ 320{
321 struct tty_bufhead *buf = &tty->port->buf;
309 int copied = 0; 322 int copied = 0;
310 do { 323 do {
311 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 324 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
@@ -313,18 +326,18 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
313 unsigned long __flags; 326 unsigned long __flags;
314 struct tty_buffer *tb; 327 struct tty_buffer *tb;
315 328
316 spin_lock_irqsave(&tty->buf.lock, __flags); 329 spin_lock_irqsave(&buf->lock, __flags);
317 space = __tty_buffer_request_room(tty, goal); 330 space = __tty_buffer_request_room(tty->port, goal);
318 tb = tty->buf.tail; 331 tb = buf->tail;
319 /* If there is no space then tb may be NULL */ 332 /* If there is no space then tb may be NULL */
320 if (unlikely(space == 0)) { 333 if (unlikely(space == 0)) {
321 spin_unlock_irqrestore(&tty->buf.lock, __flags); 334 spin_unlock_irqrestore(&buf->lock, __flags);
322 break; 335 break;
323 } 336 }
324 memcpy(tb->char_buf_ptr + tb->used, chars, space); 337 memcpy(tb->char_buf_ptr + tb->used, chars, space);
325 memcpy(tb->flag_buf_ptr + tb->used, flags, space); 338 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
326 tb->used += space; 339 tb->used += space;
327 spin_unlock_irqrestore(&tty->buf.lock, __flags); 340 spin_unlock_irqrestore(&buf->lock, __flags);
328 copied += space; 341 copied += space;
329 chars += space; 342 chars += space;
330 flags += space; 343 flags += space;
@@ -342,18 +355,23 @@ EXPORT_SYMBOL(tty_insert_flip_string_flags);
342 * Takes any pending buffers and transfers their ownership to the 355 * Takes any pending buffers and transfers their ownership to the
343 * ldisc side of the queue. It then schedules those characters for 356 * ldisc side of the queue. It then schedules those characters for
344 * processing by the line discipline. 357 * processing by the line discipline.
358 * Note that this function can only be used when the low_latency flag
359 * is unset. Otherwise the workqueue won't be flushed.
345 * 360 *
346 * Locking: Takes tty->buf.lock 361 * Locking: Takes port->buf.lock
347 */ 362 */
348 363
349void tty_schedule_flip(struct tty_struct *tty) 364void tty_schedule_flip(struct tty_struct *tty)
350{ 365{
366 struct tty_bufhead *buf = &tty->port->buf;
351 unsigned long flags; 367 unsigned long flags;
352 spin_lock_irqsave(&tty->buf.lock, flags); 368 WARN_ON(tty->low_latency);
353 if (tty->buf.tail != NULL) 369
354 tty->buf.tail->commit = tty->buf.tail->used; 370 spin_lock_irqsave(&buf->lock, flags);
355 spin_unlock_irqrestore(&tty->buf.lock, flags); 371 if (buf->tail != NULL)
356 schedule_work(&tty->buf.work); 372 buf->tail->commit = buf->tail->used;
373 spin_unlock_irqrestore(&buf->lock, flags);
374 schedule_work(&buf->work);
357} 375}
358EXPORT_SYMBOL(tty_schedule_flip); 376EXPORT_SYMBOL(tty_schedule_flip);
359 377
@@ -369,26 +387,27 @@ EXPORT_SYMBOL(tty_schedule_flip);
369 * that need their own block copy routines into the buffer. There is no 387 * that need their own block copy routines into the buffer. There is no
370 * guarantee the buffer is a DMA target! 388 * guarantee the buffer is a DMA target!
371 * 389 *
372 * Locking: May call functions taking tty->buf.lock 390 * Locking: May call functions taking port->buf.lock
373 */ 391 */
374 392
375int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, 393int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
376 size_t size) 394 size_t size)
377{ 395{
396 struct tty_bufhead *buf = &tty->port->buf;
378 int space; 397 int space;
379 unsigned long flags; 398 unsigned long flags;
380 struct tty_buffer *tb; 399 struct tty_buffer *tb;
381 400
382 spin_lock_irqsave(&tty->buf.lock, flags); 401 spin_lock_irqsave(&buf->lock, flags);
383 space = __tty_buffer_request_room(tty, size); 402 space = __tty_buffer_request_room(tty->port, size);
384 403
385 tb = tty->buf.tail; 404 tb = buf->tail;
386 if (likely(space)) { 405 if (likely(space)) {
387 *chars = tb->char_buf_ptr + tb->used; 406 *chars = tb->char_buf_ptr + tb->used;
388 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); 407 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
389 tb->used += space; 408 tb->used += space;
390 } 409 }
391 spin_unlock_irqrestore(&tty->buf.lock, flags); 410 spin_unlock_irqrestore(&buf->lock, flags);
392 return space; 411 return space;
393} 412}
394EXPORT_SYMBOL_GPL(tty_prepare_flip_string); 413EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
@@ -406,26 +425,27 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
406 * that need their own block copy routines into the buffer. There is no 425 * that need their own block copy routines into the buffer. There is no
407 * guarantee the buffer is a DMA target! 426 * guarantee the buffer is a DMA target!
408 * 427 *
409 * Locking: May call functions taking tty->buf.lock 428 * Locking: May call functions taking port->buf.lock
410 */ 429 */
411 430
412int tty_prepare_flip_string_flags(struct tty_struct *tty, 431int tty_prepare_flip_string_flags(struct tty_struct *tty,
413 unsigned char **chars, char **flags, size_t size) 432 unsigned char **chars, char **flags, size_t size)
414{ 433{
434 struct tty_bufhead *buf = &tty->port->buf;
415 int space; 435 int space;
416 unsigned long __flags; 436 unsigned long __flags;
417 struct tty_buffer *tb; 437 struct tty_buffer *tb;
418 438
419 spin_lock_irqsave(&tty->buf.lock, __flags); 439 spin_lock_irqsave(&buf->lock, __flags);
420 space = __tty_buffer_request_room(tty, size); 440 space = __tty_buffer_request_room(tty->port, size);
421 441
422 tb = tty->buf.tail; 442 tb = buf->tail;
423 if (likely(space)) { 443 if (likely(space)) {
424 *chars = tb->char_buf_ptr + tb->used; 444 *chars = tb->char_buf_ptr + tb->used;
425 *flags = tb->flag_buf_ptr + tb->used; 445 *flags = tb->flag_buf_ptr + tb->used;
426 tb->used += space; 446 tb->used += space;
427 } 447 }
428 spin_unlock_irqrestore(&tty->buf.lock, __flags); 448 spin_unlock_irqrestore(&buf->lock, __flags);
429 return space; 449 return space;
430} 450}
431EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); 451EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
@@ -446,20 +466,25 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
446 466
447static void flush_to_ldisc(struct work_struct *work) 467static void flush_to_ldisc(struct work_struct *work)
448{ 468{
449 struct tty_struct *tty = 469 struct tty_port *port = container_of(work, struct tty_port, buf.work);
450 container_of(work, struct tty_struct, buf.work); 470 struct tty_bufhead *buf = &port->buf;
471 struct tty_struct *tty;
451 unsigned long flags; 472 unsigned long flags;
452 struct tty_ldisc *disc; 473 struct tty_ldisc *disc;
453 474
475 tty = port->itty;
476 if (WARN_RATELIMIT(tty == NULL, "tty is NULL"))
477 return;
478
454 disc = tty_ldisc_ref(tty); 479 disc = tty_ldisc_ref(tty);
455 if (disc == NULL) /* !TTY_LDISC */ 480 if (disc == NULL) /* !TTY_LDISC */
456 return; 481 return;
457 482
458 spin_lock_irqsave(&tty->buf.lock, flags); 483 spin_lock_irqsave(&buf->lock, flags);
459 484
460 if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) { 485 if (!test_and_set_bit(TTYP_FLUSHING, &port->iflags)) {
461 struct tty_buffer *head; 486 struct tty_buffer *head;
462 while ((head = tty->buf.head) != NULL) { 487 while ((head = buf->head) != NULL) {
463 int count; 488 int count;
464 char *char_buf; 489 char *char_buf;
465 unsigned char *flag_buf; 490 unsigned char *flag_buf;
@@ -468,14 +493,14 @@ static void flush_to_ldisc(struct work_struct *work)
468 if (!count) { 493 if (!count) {
469 if (head->next == NULL) 494 if (head->next == NULL)
470 break; 495 break;
471 tty->buf.head = head->next; 496 buf->head = head->next;
472 tty_buffer_free(tty, head); 497 tty_buffer_free(port, head);
473 continue; 498 continue;
474 } 499 }
475 /* Ldisc or user is trying to flush the buffers 500 /* Ldisc or user is trying to flush the buffers
476 we are feeding to the ldisc, stop feeding the 501 we are feeding to the ldisc, stop feeding the
477 line discipline as we want to empty the queue */ 502 line discipline as we want to empty the queue */
478 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) 503 if (test_bit(TTYP_FLUSHPENDING, &port->iflags))
479 break; 504 break;
480 if (!tty->receive_room) 505 if (!tty->receive_room)
481 break; 506 break;
@@ -484,22 +509,22 @@ static void flush_to_ldisc(struct work_struct *work)
484 char_buf = head->char_buf_ptr + head->read; 509 char_buf = head->char_buf_ptr + head->read;
485 flag_buf = head->flag_buf_ptr + head->read; 510 flag_buf = head->flag_buf_ptr + head->read;
486 head->read += count; 511 head->read += count;
487 spin_unlock_irqrestore(&tty->buf.lock, flags); 512 spin_unlock_irqrestore(&buf->lock, flags);
488 disc->ops->receive_buf(tty, char_buf, 513 disc->ops->receive_buf(tty, char_buf,
489 flag_buf, count); 514 flag_buf, count);
490 spin_lock_irqsave(&tty->buf.lock, flags); 515 spin_lock_irqsave(&buf->lock, flags);
491 } 516 }
492 clear_bit(TTY_FLUSHING, &tty->flags); 517 clear_bit(TTYP_FLUSHING, &port->iflags);
493 } 518 }
494 519
495 /* We may have a deferred request to flush the input buffer, 520 /* We may have a deferred request to flush the input buffer,
496 if so pull the chain under the lock and empty the queue */ 521 if so pull the chain under the lock and empty the queue */
497 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) { 522 if (test_bit(TTYP_FLUSHPENDING, &port->iflags)) {
498 __tty_buffer_flush(tty); 523 __tty_buffer_flush(port);
499 clear_bit(TTY_FLUSHPENDING, &tty->flags); 524 clear_bit(TTYP_FLUSHPENDING, &port->iflags);
500 wake_up(&tty->read_wait); 525 wake_up(&tty->read_wait);
501 } 526 }
502 spin_unlock_irqrestore(&tty->buf.lock, flags); 527 spin_unlock_irqrestore(&buf->lock, flags);
503 528
504 tty_ldisc_deref(disc); 529 tty_ldisc_deref(disc);
505} 530}
@@ -514,7 +539,8 @@ static void flush_to_ldisc(struct work_struct *work)
514 */ 539 */
515void tty_flush_to_ldisc(struct tty_struct *tty) 540void tty_flush_to_ldisc(struct tty_struct *tty)
516{ 541{
517 flush_work(&tty->buf.work); 542 if (!tty->low_latency)
543 flush_work(&tty->port->buf.work);
518} 544}
519 545
520/** 546/**
@@ -532,16 +558,18 @@ void tty_flush_to_ldisc(struct tty_struct *tty)
532 558
533void tty_flip_buffer_push(struct tty_struct *tty) 559void tty_flip_buffer_push(struct tty_struct *tty)
534{ 560{
561 struct tty_bufhead *buf = &tty->port->buf;
535 unsigned long flags; 562 unsigned long flags;
536 spin_lock_irqsave(&tty->buf.lock, flags); 563
537 if (tty->buf.tail != NULL) 564 spin_lock_irqsave(&buf->lock, flags);
538 tty->buf.tail->commit = tty->buf.tail->used; 565 if (buf->tail != NULL)
539 spin_unlock_irqrestore(&tty->buf.lock, flags); 566 buf->tail->commit = buf->tail->used;
567 spin_unlock_irqrestore(&buf->lock, flags);
540 568
541 if (tty->low_latency) 569 if (tty->low_latency)
542 flush_to_ldisc(&tty->buf.work); 570 flush_to_ldisc(&buf->work);
543 else 571 else
544 schedule_work(&tty->buf.work); 572 schedule_work(&buf->work);
545} 573}
546EXPORT_SYMBOL(tty_flip_buffer_push); 574EXPORT_SYMBOL(tty_flip_buffer_push);
547 575
@@ -555,13 +583,15 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
555 * Locking: none 583 * Locking: none
556 */ 584 */
557 585
558void tty_buffer_init(struct tty_struct *tty) 586void tty_buffer_init(struct tty_port *port)
559{ 587{
560 spin_lock_init(&tty->buf.lock); 588 struct tty_bufhead *buf = &port->buf;
561 tty->buf.head = NULL; 589
562 tty->buf.tail = NULL; 590 spin_lock_init(&buf->lock);
563 tty->buf.free = NULL; 591 buf->head = NULL;
564 tty->buf.memory_used = 0; 592 buf->tail = NULL;
565 INIT_WORK(&tty->buf.work, flush_to_ldisc); 593 buf->free = NULL;
594 buf->memory_used = 0;
595 INIT_WORK(&buf->work, flush_to_ldisc);
566} 596}
567 597
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 2ea176b2280e..a3eba7f359ed 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -186,7 +186,6 @@ void free_tty_struct(struct tty_struct *tty)
186 if (tty->dev) 186 if (tty->dev)
187 put_device(tty->dev); 187 put_device(tty->dev);
188 kfree(tty->write_buf); 188 kfree(tty->write_buf);
189 tty_buffer_free_all(tty);
190 tty->magic = 0xDEADDEAD; 189 tty->magic = 0xDEADDEAD;
191 kfree(tty); 190 kfree(tty);
192} 191}
@@ -1417,6 +1416,8 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1417 "%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n", 1416 "%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
1418 __func__, tty->driver->name); 1417 __func__, tty->driver->name);
1419 1418
1419 tty->port->itty = tty;
1420
1420 /* 1421 /*
1421 * Structures all installed ... call the ldisc open routines. 1422 * Structures all installed ... call the ldisc open routines.
1422 * If we fail here just call release_tty to clean up. No need 1423 * If we fail here just call release_tty to clean up. No need
@@ -1552,6 +1553,7 @@ static void release_tty(struct tty_struct *tty, int idx)
1552 tty->ops->shutdown(tty); 1553 tty->ops->shutdown(tty);
1553 tty_free_termios(tty); 1554 tty_free_termios(tty);
1554 tty_driver_remove_tty(tty->driver, tty); 1555 tty_driver_remove_tty(tty->driver, tty);
1556 tty->port->itty = NULL;
1555 1557
1556 if (tty->link) 1558 if (tty->link)
1557 tty_kref_put(tty->link); 1559 tty_kref_put(tty->link);
@@ -1625,7 +1627,6 @@ int tty_release(struct inode *inode, struct file *filp)
1625 struct tty_struct *tty = file_tty(filp); 1627 struct tty_struct *tty = file_tty(filp);
1626 struct tty_struct *o_tty; 1628 struct tty_struct *o_tty;
1627 int pty_master, tty_closing, o_tty_closing, do_sleep; 1629 int pty_master, tty_closing, o_tty_closing, do_sleep;
1628 int devpts;
1629 int idx; 1630 int idx;
1630 char buf[64]; 1631 char buf[64];
1631 1632
@@ -1640,7 +1641,6 @@ int tty_release(struct inode *inode, struct file *filp)
1640 idx = tty->index; 1641 idx = tty->index;
1641 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1642 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1642 tty->driver->subtype == PTY_TYPE_MASTER); 1643 tty->driver->subtype == PTY_TYPE_MASTER);
1643 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1644 /* Review: parallel close */ 1644 /* Review: parallel close */
1645 o_tty = tty->link; 1645 o_tty = tty->link;
1646 1646
@@ -1799,9 +1799,6 @@ int tty_release(struct inode *inode, struct file *filp)
1799 release_tty(tty, idx); 1799 release_tty(tty, idx);
1800 mutex_unlock(&tty_mutex); 1800 mutex_unlock(&tty_mutex);
1801 1801
1802 /* Make this pty number available for reallocation */
1803 if (devpts)
1804 devpts_kill_index(inode, idx);
1805 return 0; 1802 return 0;
1806} 1803}
1807 1804
@@ -2937,19 +2934,13 @@ void initialize_tty_struct(struct tty_struct *tty,
2937 tty_ldisc_init(tty); 2934 tty_ldisc_init(tty);
2938 tty->session = NULL; 2935 tty->session = NULL;
2939 tty->pgrp = NULL; 2936 tty->pgrp = NULL;
2940 tty->overrun_time = jiffies;
2941 tty_buffer_init(tty);
2942 mutex_init(&tty->legacy_mutex); 2937 mutex_init(&tty->legacy_mutex);
2943 mutex_init(&tty->termios_mutex); 2938 mutex_init(&tty->termios_mutex);
2944 mutex_init(&tty->ldisc_mutex); 2939 mutex_init(&tty->ldisc_mutex);
2945 init_waitqueue_head(&tty->write_wait); 2940 init_waitqueue_head(&tty->write_wait);
2946 init_waitqueue_head(&tty->read_wait); 2941 init_waitqueue_head(&tty->read_wait);
2947 INIT_WORK(&tty->hangup_work, do_tty_hangup); 2942 INIT_WORK(&tty->hangup_work, do_tty_hangup);
2948 mutex_init(&tty->atomic_read_lock);
2949 mutex_init(&tty->atomic_write_lock); 2943 mutex_init(&tty->atomic_write_lock);
2950 mutex_init(&tty->output_lock);
2951 mutex_init(&tty->echo_lock);
2952 spin_lock_init(&tty->read_lock);
2953 spin_lock_init(&tty->ctrl_lock); 2944 spin_lock_init(&tty->ctrl_lock);
2954 INIT_LIST_HEAD(&tty->tty_files); 2945 INIT_LIST_HEAD(&tty->tty_files);
2955 INIT_WORK(&tty->SAK_work, do_SAK_work); 2946 INIT_WORK(&tty->SAK_work, do_SAK_work);
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 0f2a2c5e704c..f4e6754525dc 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -512,7 +512,7 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
512static int tty_ldisc_halt(struct tty_struct *tty) 512static int tty_ldisc_halt(struct tty_struct *tty)
513{ 513{
514 clear_bit(TTY_LDISC, &tty->flags); 514 clear_bit(TTY_LDISC, &tty->flags);
515 return cancel_work_sync(&tty->buf.work); 515 return cancel_work_sync(&tty->port->buf.work);
516} 516}
517 517
518/** 518/**
@@ -525,7 +525,7 @@ static void tty_ldisc_flush_works(struct tty_struct *tty)
525{ 525{
526 flush_work(&tty->hangup_work); 526 flush_work(&tty->hangup_work);
527 flush_work(&tty->SAK_work); 527 flush_work(&tty->SAK_work);
528 flush_work(&tty->buf.work); 528 flush_work(&tty->port->buf.work);
529} 529}
530 530
531/** 531/**
@@ -704,9 +704,9 @@ enable:
704 /* Restart the work queue in case no characters kick it off. Safe if 704 /* Restart the work queue in case no characters kick it off. Safe if
705 already running */ 705 already running */
706 if (work) 706 if (work)
707 schedule_work(&tty->buf.work); 707 schedule_work(&tty->port->buf.work);
708 if (o_work) 708 if (o_work)
709 schedule_work(&o_tty->buf.work); 709 schedule_work(&o_tty->port->buf.work);
710 mutex_unlock(&tty->ldisc_mutex); 710 mutex_unlock(&tty->ldisc_mutex);
711 tty_unlock(tty); 711 tty_unlock(tty);
712 return retval; 712 return retval;
@@ -817,7 +817,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
817 */ 817 */
818 clear_bit(TTY_LDISC, &tty->flags); 818 clear_bit(TTY_LDISC, &tty->flags);
819 tty_unlock(tty); 819 tty_unlock(tty);
820 cancel_work_sync(&tty->buf.work); 820 cancel_work_sync(&tty->port->buf.work);
821 mutex_unlock(&tty->ldisc_mutex); 821 mutex_unlock(&tty->ldisc_mutex);
822retry: 822retry:
823 tty_lock(tty); 823 tty_lock(tty);
@@ -897,6 +897,11 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
897 897
898static void tty_ldisc_kill(struct tty_struct *tty) 898static void tty_ldisc_kill(struct tty_struct *tty)
899{ 899{
900 /* There cannot be users from userspace now. But there still might be
901 * drivers holding a reference via tty_ldisc_ref. Do not steal them the
902 * ldisc until they are done. */
903 tty_ldisc_wait_idle(tty, MAX_SCHEDULE_TIMEOUT);
904
900 mutex_lock(&tty->ldisc_mutex); 905 mutex_lock(&tty->ldisc_mutex);
901 /* 906 /*
902 * Now kill off the ldisc 907 * Now kill off the ldisc
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index d7bdd8d0c23f..416b42f7c346 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -21,6 +21,7 @@
21void tty_port_init(struct tty_port *port) 21void tty_port_init(struct tty_port *port)
22{ 22{
23 memset(port, 0, sizeof(*port)); 23 memset(port, 0, sizeof(*port));
24 tty_buffer_init(port);
24 init_waitqueue_head(&port->open_wait); 25 init_waitqueue_head(&port->open_wait);
25 init_waitqueue_head(&port->close_wait); 26 init_waitqueue_head(&port->close_wait);
26 init_waitqueue_head(&port->delta_msr_wait); 27 init_waitqueue_head(&port->delta_msr_wait);
@@ -126,6 +127,7 @@ static void tty_port_destructor(struct kref *kref)
126 struct tty_port *port = container_of(kref, struct tty_port, kref); 127 struct tty_port *port = container_of(kref, struct tty_port, kref);
127 if (port->xmit_buf) 128 if (port->xmit_buf)
128 free_page((unsigned long)port->xmit_buf); 129 free_page((unsigned long)port->xmit_buf);
130 tty_buffer_free_all(port);
129 if (port->ops->destruct) 131 if (port->ops->destruct)
130 port->ops->destruct(port); 132 port->ops->destruct(port);
131 else 133 else
diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 8e9b4be97a2d..60b7b6926059 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -341,15 +341,11 @@ int paste_selection(struct tty_struct *tty)
341 struct tty_ldisc *ld; 341 struct tty_ldisc *ld;
342 DECLARE_WAITQUEUE(wait, current); 342 DECLARE_WAITQUEUE(wait, current);
343 343
344
345 console_lock(); 344 console_lock();
346 poke_blanked_console(); 345 poke_blanked_console();
347 console_unlock(); 346 console_unlock();
348 347
349 /* FIXME: wtf is this supposed to achieve ? */ 348 ld = tty_ldisc_ref_wait(tty);
350 ld = tty_ldisc_ref(tty);
351 if (!ld)
352 ld = tty_ldisc_ref_wait(tty);
353 349
354 /* FIXME: this is completely unsafe */ 350 /* FIXME: this is completely unsafe */
355 add_wait_queue(&vc->paste_wait, &wait); 351 add_wait_queue(&vc->paste_wait, &wait);
@@ -361,8 +357,7 @@ int paste_selection(struct tty_struct *tty)
361 } 357 }
362 count = sel_buffer_lth - pasted; 358 count = sel_buffer_lth - pasted;
363 count = min(count, tty->receive_room); 359 count = min(count, tty->receive_room);
364 tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted, 360 ld->ops->receive_buf(tty, sel_buffer + pasted, NULL, count);
365 NULL, count);
366 pasted += count; 361 pasted += count;
367 } 362 }
368 remove_wait_queue(&vc->paste_wait, &wait); 363 remove_wait_queue(&vc->paste_wait, &wait);
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 981f2132d128..6e49ec6f3adc 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -817,10 +817,6 @@ static const __u32 acm_tty_speed[] = {
817 2500000, 3000000, 3500000, 4000000 817 2500000, 3000000, 3500000, 4000000
818}; 818};
819 819
820static const __u8 acm_tty_size[] = {
821 5, 6, 7, 8
822};
823
824static void acm_tty_set_termios(struct tty_struct *tty, 820static void acm_tty_set_termios(struct tty_struct *tty,
825 struct ktermios *termios_old) 821 struct ktermios *termios_old)
826{ 822{
@@ -834,7 +830,21 @@ static void acm_tty_set_termios(struct tty_struct *tty,
834 newline.bParityType = termios->c_cflag & PARENB ? 830 newline.bParityType = termios->c_cflag & PARENB ?
835 (termios->c_cflag & PARODD ? 1 : 2) + 831 (termios->c_cflag & PARODD ? 1 : 2) +
836 (termios->c_cflag & CMSPAR ? 2 : 0) : 0; 832 (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
837 newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; 833 switch (termios->c_cflag & CSIZE) {
834 case CS5:
835 newline.bDataBits = 5;
836 break;
837 case CS6:
838 newline.bDataBits = 6;
839 break;
840 case CS7:
841 newline.bDataBits = 7;
842 break;
843 case CS8:
844 default:
845 newline.bDataBits = 8;
846 break;
847 }
838 /* FIXME: Needs to clear unsupported bits in the termios */ 848 /* FIXME: Needs to clear unsupported bits in the termios */
839 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); 849 acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
840 850
@@ -1233,7 +1243,7 @@ made_compressed_probe:
1233 1243
1234 if (usb_endpoint_xfer_int(epwrite)) 1244 if (usb_endpoint_xfer_int(epwrite))
1235 usb_fill_int_urb(snd->urb, usb_dev, 1245 usb_fill_int_urb(snd->urb, usb_dev,
1236 usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), 1246 usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),
1237 NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); 1247 NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval);
1238 else 1248 else
1239 usb_fill_bulk_urb(snd->urb, usb_dev, 1249 usb_fill_bulk_urb(snd->urb, usb_dev,
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index e0356cb859b5..b78fbe222b72 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1348,6 +1348,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1348 ret = -EFAULT; 1348 ret = -EFAULT;
1349 goto error; 1349 goto error;
1350 } 1350 }
1351 uurb->buffer += u;
1351 } 1352 }
1352 totlen -= u; 1353 totlen -= u;
1353 } 1354 }
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index ddd820d25288..6056db7af410 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -367,6 +367,10 @@ static int usb_probe_interface(struct device *dev)
367 intf->condition = USB_INTERFACE_UNBOUND; 367 intf->condition = USB_INTERFACE_UNBOUND;
368 usb_cancel_queued_reset(intf); 368 usb_cancel_queued_reset(intf);
369 369
370 /* If the LPM disable succeeded, balance the ref counts. */
371 if (!lpm_disable_error)
372 usb_unlocked_enable_lpm(udev);
373
370 /* Unbound interfaces are always runtime-PM-disabled and -suspended */ 374 /* Unbound interfaces are always runtime-PM-disabled and -suspended */
371 if (driver->supports_autosuspend) 375 if (driver->supports_autosuspend)
372 pm_runtime_disable(dev); 376 pm_runtime_disable(dev);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 673ee4696262..64854d76f529 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -3241,8 +3241,7 @@ static int usb_req_set_sel(struct usb_device *udev, enum usb3_link_state state)
3241 (state == USB3_LPM_U2 && 3241 (state == USB3_LPM_U2 &&
3242 (u2_sel > USB3_LPM_MAX_U2_SEL_PEL || 3242 (u2_sel > USB3_LPM_MAX_U2_SEL_PEL ||
3243 u2_pel > USB3_LPM_MAX_U2_SEL_PEL))) { 3243 u2_pel > USB3_LPM_MAX_U2_SEL_PEL))) {
3244 dev_dbg(&udev->dev, "Device-initiated %s disabled due " 3244 dev_dbg(&udev->dev, "Device-initiated %s disabled due to long SEL %llu us or PEL %llu us\n",
3245 "to long SEL %llu ms or PEL %llu ms\n",
3246 usb3_lpm_names[state], u1_sel, u1_pel); 3245 usb3_lpm_names[state], u1_sel, u1_pel);
3247 return -EINVAL; 3246 return -EINVAL;
3248 } 3247 }
@@ -3320,16 +3319,6 @@ static int usb_set_device_initiated_lpm(struct usb_device *udev,
3320 3319
3321 if (enable) { 3320 if (enable) {
3322 /* 3321 /*
3323 * First, let the device know about the exit latencies
3324 * associated with the link state we're about to enable.
3325 */
3326 ret = usb_req_set_sel(udev, state);
3327 if (ret < 0) {
3328 dev_warn(&udev->dev, "Set SEL for device-initiated "
3329 "%s failed.\n", usb3_lpm_names[state]);
3330 return -EBUSY;
3331 }
3332 /*
3333 * Now send the control transfer to enable device-initiated LPM 3322 * Now send the control transfer to enable device-initiated LPM
3334 * for either U1 or U2. 3323 * for either U1 or U2.
3335 */ 3324 */
@@ -3414,7 +3403,28 @@ static int usb_set_lpm_timeout(struct usb_device *udev,
3414static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, 3403static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev,
3415 enum usb3_link_state state) 3404 enum usb3_link_state state)
3416{ 3405{
3417 int timeout; 3406 int timeout, ret;
3407 __u8 u1_mel = udev->bos->ss_cap->bU1devExitLat;
3408 __le16 u2_mel = udev->bos->ss_cap->bU2DevExitLat;
3409
3410 /* If the device says it doesn't have *any* exit latency to come out of
3411 * U1 or U2, it's probably lying. Assume it doesn't implement that link
3412 * state.
3413 */
3414 if ((state == USB3_LPM_U1 && u1_mel == 0) ||
3415 (state == USB3_LPM_U2 && u2_mel == 0))
3416 return;
3417
3418 /*
3419 * First, let the device know about the exit latencies
3420 * associated with the link state we're about to enable.
3421 */
3422 ret = usb_req_set_sel(udev, state);
3423 if (ret < 0) {
3424 dev_warn(&udev->dev, "Set SEL for device-initiated %s failed.\n",
3425 usb3_lpm_names[state]);
3426 return;
3427 }
3418 3428
3419 /* We allow the host controller to set the U1/U2 timeout internally 3429 /* We allow the host controller to set the U1/U2 timeout internally
3420 * first, so that it can change its schedule to account for the 3430 * first, so that it can change its schedule to account for the
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index b415c0c859d3..c14ebc975ba4 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -409,6 +409,10 @@ static void dwc3_core_exit(struct dwc3 *dwc)
409{ 409{
410 dwc3_event_buffers_cleanup(dwc); 410 dwc3_event_buffers_cleanup(dwc);
411 dwc3_free_event_buffers(dwc); 411 dwc3_free_event_buffers(dwc);
412
413 usb_phy_shutdown(dwc->usb2_phy);
414 usb_phy_shutdown(dwc->usb3_phy);
415
412} 416}
413 417
414#define DWC3_ALIGN_MASK (16 - 1) 418#define DWC3_ALIGN_MASK (16 - 1)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c9e729a4bf65..7b7deddf6a52 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1904,7 +1904,7 @@ static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum)
1904 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 1904 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params);
1905 WARN_ON_ONCE(ret); 1905 WARN_ON_ONCE(ret);
1906 dep->resource_index = 0; 1906 dep->resource_index = 0;
1907 1907 dep->flags &= ~DWC3_EP_BUSY;
1908 udelay(100); 1908 udelay(100);
1909} 1909}
1910 1910
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index dfb51a45496c..e0ff51b89529 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -952,6 +952,7 @@ endif
952config USB_G_WEBCAM 952config USB_G_WEBCAM
953 tristate "USB Webcam Gadget" 953 tristate "USB Webcam Gadget"
954 depends on VIDEO_DEV 954 depends on VIDEO_DEV
955 select USB_LIBCOMPOSITE
955 help 956 help
956 The Webcam Gadget acts as a composite USB Audio and Video Class 957 The Webcam Gadget acts as a composite USB Audio and Video Class
957 device. It provides a userspace API to process UVC control requests 958 device. It provides a userspace API to process UVC control requests
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index f696fb9b136d..21a9861dabf0 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -2930,10 +2930,10 @@ static void vbus_work(struct work_struct *work)
2930 2930
2931 /* Get the VBUS status from the transceiver */ 2931 /* Get the VBUS status from the transceiver */
2932 value = i2c_smbus_read_byte_data(udc->isp1301_i2c_client, 2932 value = i2c_smbus_read_byte_data(udc->isp1301_i2c_client,
2933 ISP1301_I2C_OTG_CONTROL_2); 2933 ISP1301_I2C_INTERRUPT_SOURCE);
2934 2934
2935 /* VBUS on or off? */ 2935 /* VBUS on or off? */
2936 if (value & OTG_B_SESS_VLD) 2936 if (value & INT_SESS_VLD)
2937 udc->vbus = 1; 2937 udc->vbus = 1;
2938 else 2938 else
2939 udc->vbus = 0; 2939 udc->vbus = 0;
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 9bfde82078ec..0d2f35ca93f1 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -222,7 +222,7 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
222 222
223 if (pdata->controller_ver < 0) { 223 if (pdata->controller_ver < 0) {
224 dev_warn(hcd->self.controller, "Could not get controller version\n"); 224 dev_warn(hcd->self.controller, "Could not get controller version\n");
225 return; 225 return -ENODEV;
226 } 226 }
227 227
228 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]); 228 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]);
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 8e7eca62f169..9c2717d66730 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -160,7 +160,7 @@ static const struct hc_driver ehci_orion_hc_driver = {
160 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 160 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
161}; 161};
162 162
163static void __init 163static void __devinit
164ehci_orion_conf_mbus_windows(struct usb_hcd *hcd, 164ehci_orion_conf_mbus_windows(struct usb_hcd *hcd,
165 const struct mbus_dram_target_info *dram) 165 const struct mbus_dram_target_info *dram)
166{ 166{
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c
index 96722bfebc84..d3c9a3e397b9 100644
--- a/drivers/usb/host/ehci-vt8500.c
+++ b/drivers/usb/host/ehci-vt8500.c
@@ -85,6 +85,8 @@ static const struct hc_driver vt8500_ehci_hc_driver = {
85 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 85 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
86}; 86};
87 87
88static u64 vt8500_ehci_dma_mask = DMA_BIT_MASK(32);
89
88static int vt8500_ehci_drv_probe(struct platform_device *pdev) 90static int vt8500_ehci_drv_probe(struct platform_device *pdev)
89{ 91{
90 struct usb_hcd *hcd; 92 struct usb_hcd *hcd;
@@ -95,6 +97,14 @@ static int vt8500_ehci_drv_probe(struct platform_device *pdev)
95 if (usb_disabled()) 97 if (usb_disabled())
96 return -ENODEV; 98 return -ENODEV;
97 99
100 /*
101 * Right now device-tree probed devices don't get dma_mask set.
102 * Since shared usb code relies on it, set it here for now.
103 * Once we have dma capability bindings this can go away.
104 */
105 if (!pdev->dev.dma_mask)
106 pdev->dev.dma_mask = &vt8500_ehci_dma_mask;
107
98 if (pdev->resource[1].flags != IORESOURCE_IRQ) { 108 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
99 pr_debug("resource[1] is not IORESOURCE_IRQ"); 109 pr_debug("resource[1] is not IORESOURCE_IRQ");
100 return -ENOMEM; 110 return -ENOMEM;
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
index e4780491df4a..68ebf20e1519 100644
--- a/drivers/usb/host/uhci-platform.c
+++ b/drivers/usb/host/uhci-platform.c
@@ -60,6 +60,7 @@ static const struct hc_driver uhci_platform_hc_driver = {
60 .hub_control = uhci_hub_control, 60 .hub_control = uhci_hub_control,
61}; 61};
62 62
63static u64 platform_uhci_dma_mask = DMA_BIT_MASK(32);
63 64
64static int __devinit uhci_hcd_platform_probe(struct platform_device *pdev) 65static int __devinit uhci_hcd_platform_probe(struct platform_device *pdev)
65{ 66{
@@ -71,6 +72,14 @@ static int __devinit uhci_hcd_platform_probe(struct platform_device *pdev)
71 if (usb_disabled()) 72 if (usb_disabled())
72 return -ENODEV; 73 return -ENODEV;
73 74
75 /*
76 * Right now device-tree probed devices don't get dma_mask set.
77 * Since shared usb code relies on it, set it here for now.
78 * Once we have dma capability bindings this can go away.
79 */
80 if (!pdev->dev.dma_mask)
81 pdev->dev.dma_mask = &platform_uhci_dma_mask;
82
74 hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev, 83 hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
75 pdev->name); 84 pdev->name);
76 if (!hcd) 85 if (!hcd)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 8d7fcbbe6ade..7d462bf20092 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -479,7 +479,8 @@ static bool compliance_mode_recovery_timer_quirk_check(void)
479 479
480 if (strstr(dmi_product_name, "Z420") || 480 if (strstr(dmi_product_name, "Z420") ||
481 strstr(dmi_product_name, "Z620") || 481 strstr(dmi_product_name, "Z620") ||
482 strstr(dmi_product_name, "Z820")) 482 strstr(dmi_product_name, "Z820") ||
483 strstr(dmi_product_name, "Z1"))
483 return true; 484 return true;
484 485
485 return false; 486 return false;
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 457f25e62c51..c964d6af178b 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -305,6 +305,12 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
305 ret = IRQ_HANDLED; 305 ret = IRQ_HANDLED;
306 } 306 }
307 307
308 /* Drop spurious RX and TX if device is disconnected */
309 if (musb->int_usb & MUSB_INTR_DISCONNECT) {
310 musb->int_tx = 0;
311 musb->int_rx = 0;
312 }
313
308 if (musb->int_tx || musb->int_rx || musb->int_usb) 314 if (musb->int_tx || musb->int_rx || musb->int_usb)
309 ret |= musb_interrupt(musb); 315 ret |= musb_interrupt(musb);
310 316
diff --git a/drivers/usb/renesas_usbhs/mod.c b/drivers/usb/renesas_usbhs/mod.c
index 35c5208f3249..61933a90e5bf 100644
--- a/drivers/usb/renesas_usbhs/mod.c
+++ b/drivers/usb/renesas_usbhs/mod.c
@@ -273,9 +273,9 @@ static irqreturn_t usbhs_interrupt(int irq, void *data)
273 usbhs_write(priv, INTSTS0, ~irq_state.intsts0 & INTSTS0_MAGIC); 273 usbhs_write(priv, INTSTS0, ~irq_state.intsts0 & INTSTS0_MAGIC);
274 usbhs_write(priv, INTSTS1, ~irq_state.intsts1 & INTSTS1_MAGIC); 274 usbhs_write(priv, INTSTS1, ~irq_state.intsts1 & INTSTS1_MAGIC);
275 275
276 usbhs_write(priv, BRDYSTS, 0); 276 usbhs_write(priv, BRDYSTS, ~irq_state.brdysts);
277 usbhs_write(priv, NRDYSTS, 0); 277 usbhs_write(priv, NRDYSTS, ~irq_state.nrdysts);
278 usbhs_write(priv, BEMPSTS, 0); 278 usbhs_write(priv, BEMPSTS, ~irq_state.bempsts);
279 279
280 /* 280 /*
281 * call irq callback functions 281 * call irq callback functions
diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h
index 08786c06dcf1..3d80c7b1fd1b 100644
--- a/drivers/usb/renesas_usbhs/pipe.h
+++ b/drivers/usb/renesas_usbhs/pipe.h
@@ -54,7 +54,7 @@ struct usbhs_pipe_info {
54 * pipe list 54 * pipe list
55 */ 55 */
56#define __usbhs_for_each_pipe(start, pos, info, i) \ 56#define __usbhs_for_each_pipe(start, pos, info, i) \
57 for (i = start, pos = (info)->pipe; \ 57 for (i = start, pos = (info)->pipe + i; \
58 i < (info)->size; \ 58 i < (info)->size; \
59 i++, pos = (info)->pipe + i) 59 i++, pos = (info)->pipe + i)
60 60
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index cf2522c397d3..bd50a8a41a0f 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -125,9 +125,6 @@ static inline int calc_divisor(int bps)
125 125
126static int ark3116_attach(struct usb_serial *serial) 126static int ark3116_attach(struct usb_serial *serial)
127{ 127{
128 struct usb_serial_port *port = serial->port[0];
129 struct ark3116_private *priv;
130
131 /* make sure we have our end-points */ 128 /* make sure we have our end-points */
132 if ((serial->num_bulk_in == 0) || 129 if ((serial->num_bulk_in == 0) ||
133 (serial->num_bulk_out == 0) || 130 (serial->num_bulk_out == 0) ||
@@ -142,8 +139,15 @@ static int ark3116_attach(struct usb_serial *serial)
142 return -EINVAL; 139 return -EINVAL;
143 } 140 }
144 141
145 priv = kzalloc(sizeof(struct ark3116_private), 142 return 0;
146 GFP_KERNEL); 143}
144
145static int ark3116_port_probe(struct usb_serial_port *port)
146{
147 struct usb_serial *serial = port->serial;
148 struct ark3116_private *priv;
149
150 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
147 if (!priv) 151 if (!priv)
148 return -ENOMEM; 152 return -ENOMEM;
149 153
@@ -198,18 +202,15 @@ static int ark3116_attach(struct usb_serial *serial)
198 return 0; 202 return 0;
199} 203}
200 204
201static void ark3116_release(struct usb_serial *serial) 205static int ark3116_port_remove(struct usb_serial_port *port)
202{ 206{
203 struct usb_serial_port *port = serial->port[0];
204 struct ark3116_private *priv = usb_get_serial_port_data(port); 207 struct ark3116_private *priv = usb_get_serial_port_data(port);
205 208
206 /* device is closed, so URBs and DMA should be down */ 209 /* device is closed, so URBs and DMA should be down */
207
208 usb_set_serial_port_data(port, NULL);
209
210 mutex_destroy(&priv->hw_lock); 210 mutex_destroy(&priv->hw_lock);
211
212 kfree(priv); 211 kfree(priv);
212
213 return 0;
213} 214}
214 215
215static void ark3116_init_termios(struct tty_struct *tty) 216static void ark3116_init_termios(struct tty_struct *tty)
@@ -723,7 +724,8 @@ static struct usb_serial_driver ark3116_device = {
723 .id_table = id_table, 724 .id_table = id_table,
724 .num_ports = 1, 725 .num_ports = 1,
725 .attach = ark3116_attach, 726 .attach = ark3116_attach,
726 .release = ark3116_release, 727 .port_probe = ark3116_port_probe,
728 .port_remove = ark3116_port_remove,
727 .set_termios = ark3116_set_termios, 729 .set_termios = ark3116_set_termios,
728 .init_termios = ark3116_init_termios, 730 .init_termios = ark3116_init_termios,
729 .ioctl = ark3116_ioctl, 731 .ioctl = ark3116_ioctl,
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 99449424193f..ea29556f0d72 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -45,8 +45,8 @@
45#define DRIVER_DESC "USB Belkin Serial converter driver" 45#define DRIVER_DESC "USB Belkin Serial converter driver"
46 46
47/* function prototypes for a Belkin USB Serial Adapter F5U103 */ 47/* function prototypes for a Belkin USB Serial Adapter F5U103 */
48static int belkin_sa_startup(struct usb_serial *serial); 48static int belkin_sa_port_probe(struct usb_serial_port *port);
49static void belkin_sa_release(struct usb_serial *serial); 49static int belkin_sa_port_remove(struct usb_serial_port *port);
50static int belkin_sa_open(struct tty_struct *tty, 50static int belkin_sa_open(struct tty_struct *tty,
51 struct usb_serial_port *port); 51 struct usb_serial_port *port);
52static void belkin_sa_close(struct usb_serial_port *port); 52static void belkin_sa_close(struct usb_serial_port *port);
@@ -88,8 +88,8 @@ static struct usb_serial_driver belkin_device = {
88 .break_ctl = belkin_sa_break_ctl, 88 .break_ctl = belkin_sa_break_ctl,
89 .tiocmget = belkin_sa_tiocmget, 89 .tiocmget = belkin_sa_tiocmget,
90 .tiocmset = belkin_sa_tiocmset, 90 .tiocmset = belkin_sa_tiocmset,
91 .attach = belkin_sa_startup, 91 .port_probe = belkin_sa_port_probe,
92 .release = belkin_sa_release, 92 .port_remove = belkin_sa_port_remove,
93}; 93};
94 94
95static struct usb_serial_driver * const serial_drivers[] = { 95static struct usb_serial_driver * const serial_drivers[] = {
@@ -118,17 +118,15 @@ struct belkin_sa_private {
118 (c), BELKIN_SA_SET_REQUEST_TYPE, \ 118 (c), BELKIN_SA_SET_REQUEST_TYPE, \
119 (v), 0, NULL, 0, WDR_TIMEOUT) 119 (v), 0, NULL, 0, WDR_TIMEOUT)
120 120
121/* do some startup allocations not currently performed by usb_serial_probe() */ 121static int belkin_sa_port_probe(struct usb_serial_port *port)
122static int belkin_sa_startup(struct usb_serial *serial)
123{ 122{
124 struct usb_device *dev = serial->dev; 123 struct usb_device *dev = port->serial->dev;
125 struct belkin_sa_private *priv; 124 struct belkin_sa_private *priv;
126 125
127 /* allocate the private data structure */
128 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL); 126 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL);
129 if (!priv) 127 if (!priv)
130 return -1; /* error */ 128 return -ENOMEM;
131 /* set initial values for control structures */ 129
132 spin_lock_init(&priv->lock); 130 spin_lock_init(&priv->lock);
133 priv->control_state = 0; 131 priv->control_state = 0;
134 priv->last_lsr = 0; 132 priv->last_lsr = 0;
@@ -140,18 +138,19 @@ static int belkin_sa_startup(struct usb_serial *serial)
140 le16_to_cpu(dev->descriptor.bcdDevice), 138 le16_to_cpu(dev->descriptor.bcdDevice),
141 priv->bad_flow_control); 139 priv->bad_flow_control);
142 140
143 init_waitqueue_head(&serial->port[0]->write_wait); 141 usb_set_serial_port_data(port, priv);
144 usb_set_serial_port_data(serial->port[0], priv);
145 142
146 return 0; 143 return 0;
147} 144}
148 145
149static void belkin_sa_release(struct usb_serial *serial) 146static int belkin_sa_port_remove(struct usb_serial_port *port)
150{ 147{
151 int i; 148 struct belkin_sa_private *priv;
152 149
153 for (i = 0; i < serial->num_ports; ++i) 150 priv = usb_get_serial_port_data(port);
154 kfree(usb_get_serial_port_data(serial->port[i])); 151 kfree(priv);
152
153 return 0;
155} 154}
156 155
157static int belkin_sa_open(struct tty_struct *tty, 156static int belkin_sa_open(struct tty_struct *tty,
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 28af5acc3360..eb033fc92a15 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -162,7 +162,7 @@ static const struct usb_device_id id_table[] = {
162 162
163MODULE_DEVICE_TABLE(usb, id_table); 163MODULE_DEVICE_TABLE(usb, id_table);
164 164
165struct cp210x_port_private { 165struct cp210x_serial_private {
166 __u8 bInterfaceNumber; 166 __u8 bInterfaceNumber;
167}; 167};
168 168
@@ -276,7 +276,7 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request,
276 unsigned int *data, int size) 276 unsigned int *data, int size)
277{ 277{
278 struct usb_serial *serial = port->serial; 278 struct usb_serial *serial = port->serial;
279 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 279 struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
280 __le32 *buf; 280 __le32 *buf;
281 int result, i, length; 281 int result, i, length;
282 282
@@ -292,7 +292,7 @@ static int cp210x_get_config(struct usb_serial_port *port, u8 request,
292 /* Issue the request, attempting to read 'size' bytes */ 292 /* Issue the request, attempting to read 'size' bytes */
293 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 293 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
294 request, REQTYPE_INTERFACE_TO_HOST, 0x0000, 294 request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
295 port_priv->bInterfaceNumber, buf, size, 295 spriv->bInterfaceNumber, buf, size,
296 USB_CTRL_GET_TIMEOUT); 296 USB_CTRL_GET_TIMEOUT);
297 297
298 /* Convert data into an array of integers */ 298 /* Convert data into an array of integers */
@@ -323,7 +323,7 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request,
323 unsigned int *data, int size) 323 unsigned int *data, int size)
324{ 324{
325 struct usb_serial *serial = port->serial; 325 struct usb_serial *serial = port->serial;
326 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 326 struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
327 __le32 *buf; 327 __le32 *buf;
328 int result, i, length; 328 int result, i, length;
329 329
@@ -345,13 +345,13 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request,
345 result = usb_control_msg(serial->dev, 345 result = usb_control_msg(serial->dev,
346 usb_sndctrlpipe(serial->dev, 0), 346 usb_sndctrlpipe(serial->dev, 0),
347 request, REQTYPE_HOST_TO_INTERFACE, 0x0000, 347 request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
348 port_priv->bInterfaceNumber, buf, size, 348 spriv->bInterfaceNumber, buf, size,
349 USB_CTRL_SET_TIMEOUT); 349 USB_CTRL_SET_TIMEOUT);
350 } else { 350 } else {
351 result = usb_control_msg(serial->dev, 351 result = usb_control_msg(serial->dev,
352 usb_sndctrlpipe(serial->dev, 0), 352 usb_sndctrlpipe(serial->dev, 0),
353 request, REQTYPE_HOST_TO_INTERFACE, data[0], 353 request, REQTYPE_HOST_TO_INTERFACE, data[0],
354 port_priv->bInterfaceNumber, NULL, 0, 354 spriv->bInterfaceNumber, NULL, 0,
355 USB_CTRL_SET_TIMEOUT); 355 USB_CTRL_SET_TIMEOUT);
356 } 356 }
357 357
@@ -845,36 +845,30 @@ static void cp210x_break_ctl (struct tty_struct *tty, int break_state)
845 845
846static int cp210x_startup(struct usb_serial *serial) 846static int cp210x_startup(struct usb_serial *serial)
847{ 847{
848 struct cp210x_port_private *port_priv; 848 struct usb_host_interface *cur_altsetting;
849 int i; 849 struct cp210x_serial_private *spriv;
850 850
851 /* cp210x buffers behave strangely unless device is reset */ 851 /* cp210x buffers behave strangely unless device is reset */
852 usb_reset_device(serial->dev); 852 usb_reset_device(serial->dev);
853 853
854 for (i = 0; i < serial->num_ports; i++) { 854 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
855 port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); 855 if (!spriv)
856 if (!port_priv) 856 return -ENOMEM;
857 return -ENOMEM;
858 857
859 port_priv->bInterfaceNumber = 858 cur_altsetting = serial->interface->cur_altsetting;
860 serial->interface->cur_altsetting->desc.bInterfaceNumber; 859 spriv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber;
861 860
862 usb_set_serial_port_data(serial->port[i], port_priv); 861 usb_set_serial_data(serial, spriv);
863 }
864 862
865 return 0; 863 return 0;
866} 864}
867 865
868static void cp210x_release(struct usb_serial *serial) 866static void cp210x_release(struct usb_serial *serial)
869{ 867{
870 struct cp210x_port_private *port_priv; 868 struct cp210x_serial_private *spriv;
871 int i;
872 869
873 for (i = 0; i < serial->num_ports; i++) { 870 spriv = usb_get_serial_data(serial);
874 port_priv = usb_get_serial_port_data(serial->port[i]); 871 kfree(spriv);
875 kfree(port_priv);
876 usb_set_serial_port_data(serial->port[i], NULL);
877 }
878} 872}
879 873
880module_usb_serial_driver(serial_drivers, id_table); 874module_usb_serial_driver(serial_drivers, id_table);
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 2a7aecc72237..4ee77dcbe690 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -55,9 +55,9 @@
55#define CYBERJACK_PRODUCT_ID 0x0100 55#define CYBERJACK_PRODUCT_ID 0x0100
56 56
57/* Function prototypes */ 57/* Function prototypes */
58static int cyberjack_startup(struct usb_serial *serial);
59static void cyberjack_disconnect(struct usb_serial *serial); 58static void cyberjack_disconnect(struct usb_serial *serial);
60static void cyberjack_release(struct usb_serial *serial); 59static int cyberjack_port_probe(struct usb_serial_port *port);
60static int cyberjack_port_remove(struct usb_serial_port *port);
61static int cyberjack_open(struct tty_struct *tty, 61static int cyberjack_open(struct tty_struct *tty,
62 struct usb_serial_port *port); 62 struct usb_serial_port *port);
63static void cyberjack_close(struct usb_serial_port *port); 63static void cyberjack_close(struct usb_serial_port *port);
@@ -83,9 +83,9 @@ static struct usb_serial_driver cyberjack_device = {
83 .description = "Reiner SCT Cyberjack USB card reader", 83 .description = "Reiner SCT Cyberjack USB card reader",
84 .id_table = id_table, 84 .id_table = id_table,
85 .num_ports = 1, 85 .num_ports = 1,
86 .attach = cyberjack_startup,
87 .disconnect = cyberjack_disconnect, 86 .disconnect = cyberjack_disconnect,
88 .release = cyberjack_release, 87 .port_probe = cyberjack_port_probe,
88 .port_remove = cyberjack_port_remove,
89 .open = cyberjack_open, 89 .open = cyberjack_open,
90 .close = cyberjack_close, 90 .close = cyberjack_close,
91 .write = cyberjack_write, 91 .write = cyberjack_write,
@@ -107,56 +107,45 @@ struct cyberjack_private {
107 short wrsent; /* Data already sent */ 107 short wrsent; /* Data already sent */
108}; 108};
109 109
110/* do some startup allocations not currently performed by usb_serial_probe() */ 110static int cyberjack_port_probe(struct usb_serial_port *port)
111static int cyberjack_startup(struct usb_serial *serial)
112{ 111{
113 struct cyberjack_private *priv; 112 struct cyberjack_private *priv;
114 int i; 113 int result;
115 114
116 /* allocate the private data structure */
117 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL); 115 priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
118 if (!priv) 116 if (!priv)
119 return -ENOMEM; 117 return -ENOMEM;
120 118
121 /* set initial values */
122 spin_lock_init(&priv->lock); 119 spin_lock_init(&priv->lock);
123 priv->rdtodo = 0; 120 priv->rdtodo = 0;
124 priv->wrfilled = 0; 121 priv->wrfilled = 0;
125 priv->wrsent = 0; 122 priv->wrsent = 0;
126 usb_set_serial_port_data(serial->port[0], priv);
127 123
128 init_waitqueue_head(&serial->port[0]->write_wait); 124 usb_set_serial_port_data(port, priv);
129 125
130 for (i = 0; i < serial->num_ports; ++i) { 126 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
131 int result; 127 if (result)
132 result = usb_submit_urb(serial->port[i]->interrupt_in_urb, 128 dev_err(&port->dev, "usb_submit_urb(read int) failed\n");
133 GFP_KERNEL);
134 if (result)
135 dev_err(&serial->dev->dev,
136 "usb_submit_urb(read int) failed\n");
137 dev_dbg(&serial->dev->dev, "%s - usb_submit_urb(int urb)\n",
138 __func__);
139 }
140 129
141 return 0; 130 return 0;
142} 131}
143 132
144static void cyberjack_disconnect(struct usb_serial *serial) 133static int cyberjack_port_remove(struct usb_serial_port *port)
145{ 134{
146 int i; 135 struct cyberjack_private *priv;
147 136
148 for (i = 0; i < serial->num_ports; ++i) 137 priv = usb_get_serial_port_data(port);
149 usb_kill_urb(serial->port[i]->interrupt_in_urb); 138 kfree(priv);
139
140 return 0;
150} 141}
151 142
152static void cyberjack_release(struct usb_serial *serial) 143static void cyberjack_disconnect(struct usb_serial *serial)
153{ 144{
154 int i; 145 int i;
155 146
156 for (i = 0; i < serial->num_ports; ++i) { 147 for (i = 0; i < serial->num_ports; ++i)
157 /* My special items, the standard routines free my urbs */ 148 usb_kill_urb(serial->port[i]->interrupt_in_urb);
158 kfree(usb_get_serial_port_data(serial->port[i]));
159 }
160} 149}
161 150
162static int cyberjack_open(struct tty_struct *tty, 151static int cyberjack_open(struct tty_struct *tty,
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 1befce21e173..f0da1279c114 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -123,10 +123,10 @@ struct cypress_private {
123}; 123};
124 124
125/* function prototypes for the Cypress USB to serial device */ 125/* function prototypes for the Cypress USB to serial device */
126static int cypress_earthmate_startup(struct usb_serial *serial); 126static int cypress_earthmate_port_probe(struct usb_serial_port *port);
127static int cypress_hidcom_startup(struct usb_serial *serial); 127static int cypress_hidcom_port_probe(struct usb_serial_port *port);
128static int cypress_ca42v2_startup(struct usb_serial *serial); 128static int cypress_ca42v2_port_probe(struct usb_serial_port *port);
129static void cypress_release(struct usb_serial *serial); 129static int cypress_port_remove(struct usb_serial_port *port);
130static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port); 130static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port);
131static void cypress_close(struct usb_serial_port *port); 131static void cypress_close(struct usb_serial_port *port);
132static void cypress_dtr_rts(struct usb_serial_port *port, int on); 132static void cypress_dtr_rts(struct usb_serial_port *port, int on);
@@ -156,8 +156,8 @@ static struct usb_serial_driver cypress_earthmate_device = {
156 .description = "DeLorme Earthmate USB", 156 .description = "DeLorme Earthmate USB",
157 .id_table = id_table_earthmate, 157 .id_table = id_table_earthmate,
158 .num_ports = 1, 158 .num_ports = 1,
159 .attach = cypress_earthmate_startup, 159 .port_probe = cypress_earthmate_port_probe,
160 .release = cypress_release, 160 .port_remove = cypress_port_remove,
161 .open = cypress_open, 161 .open = cypress_open,
162 .close = cypress_close, 162 .close = cypress_close,
163 .dtr_rts = cypress_dtr_rts, 163 .dtr_rts = cypress_dtr_rts,
@@ -182,8 +182,8 @@ static struct usb_serial_driver cypress_hidcom_device = {
182 .description = "HID->COM RS232 Adapter", 182 .description = "HID->COM RS232 Adapter",
183 .id_table = id_table_cyphidcomrs232, 183 .id_table = id_table_cyphidcomrs232,
184 .num_ports = 1, 184 .num_ports = 1,
185 .attach = cypress_hidcom_startup, 185 .port_probe = cypress_hidcom_port_probe,
186 .release = cypress_release, 186 .port_remove = cypress_port_remove,
187 .open = cypress_open, 187 .open = cypress_open,
188 .close = cypress_close, 188 .close = cypress_close,
189 .dtr_rts = cypress_dtr_rts, 189 .dtr_rts = cypress_dtr_rts,
@@ -208,8 +208,8 @@ static struct usb_serial_driver cypress_ca42v2_device = {
208 .description = "Nokia CA-42 V2 Adapter", 208 .description = "Nokia CA-42 V2 Adapter",
209 .id_table = id_table_nokiaca42v2, 209 .id_table = id_table_nokiaca42v2,
210 .num_ports = 1, 210 .num_ports = 1,
211 .attach = cypress_ca42v2_startup, 211 .port_probe = cypress_ca42v2_port_probe,
212 .release = cypress_release, 212 .port_remove = cypress_port_remove,
213 .open = cypress_open, 213 .open = cypress_open,
214 .close = cypress_close, 214 .close = cypress_close,
215 .dtr_rts = cypress_dtr_rts, 215 .dtr_rts = cypress_dtr_rts,
@@ -438,10 +438,10 @@ static void cypress_set_dead(struct usb_serial_port *port)
438 *****************************************************************************/ 438 *****************************************************************************/
439 439
440 440
441static int generic_startup(struct usb_serial *serial) 441static int cypress_generic_port_probe(struct usb_serial_port *port)
442{ 442{
443 struct usb_serial *serial = port->serial;
443 struct cypress_private *priv; 444 struct cypress_private *priv;
444 struct usb_serial_port *port = serial->port[0];
445 445
446 priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL); 446 priv = kzalloc(sizeof(struct cypress_private), GFP_KERNEL);
447 if (!priv) 447 if (!priv)
@@ -490,14 +490,16 @@ static int generic_startup(struct usb_serial *serial)
490} 490}
491 491
492 492
493static int cypress_earthmate_startup(struct usb_serial *serial) 493static int cypress_earthmate_port_probe(struct usb_serial_port *port)
494{ 494{
495 struct usb_serial *serial = port->serial;
495 struct cypress_private *priv; 496 struct cypress_private *priv;
496 struct usb_serial_port *port = serial->port[0]; 497 int ret;
497 498
498 if (generic_startup(serial)) { 499 ret = cypress_generic_port_probe(port);
500 if (ret) {
499 dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__); 501 dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
500 return 1; 502 return ret;
501 } 503 }
502 504
503 priv = usb_get_serial_port_data(port); 505 priv = usb_get_serial_port_data(port);
@@ -518,56 +520,53 @@ static int cypress_earthmate_startup(struct usb_serial *serial)
518 } 520 }
519 521
520 return 0; 522 return 0;
521} /* cypress_earthmate_startup */ 523}
522
523 524
524static int cypress_hidcom_startup(struct usb_serial *serial) 525static int cypress_hidcom_port_probe(struct usb_serial_port *port)
525{ 526{
526 struct cypress_private *priv; 527 struct cypress_private *priv;
527 struct usb_serial_port *port = serial->port[0]; 528 int ret;
528 529
529 if (generic_startup(serial)) { 530 ret = cypress_generic_port_probe(port);
531 if (ret) {
530 dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__); 532 dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
531 return 1; 533 return ret;
532 } 534 }
533 535
534 priv = usb_get_serial_port_data(port); 536 priv = usb_get_serial_port_data(port);
535 priv->chiptype = CT_CYPHIDCOM; 537 priv->chiptype = CT_CYPHIDCOM;
536 538
537 return 0; 539 return 0;
538} /* cypress_hidcom_startup */ 540}
539
540 541
541static int cypress_ca42v2_startup(struct usb_serial *serial) 542static int cypress_ca42v2_port_probe(struct usb_serial_port *port)
542{ 543{
543 struct cypress_private *priv; 544 struct cypress_private *priv;
544 struct usb_serial_port *port = serial->port[0]; 545 int ret;
545 546
546 if (generic_startup(serial)) { 547 ret = cypress_generic_port_probe(port);
548 if (ret) {
547 dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__); 549 dev_dbg(&port->dev, "%s - Failed setting up port\n", __func__);
548 return 1; 550 return ret;
549 } 551 }
550 552
551 priv = usb_get_serial_port_data(port); 553 priv = usb_get_serial_port_data(port);
552 priv->chiptype = CT_CA42V2; 554 priv->chiptype = CT_CA42V2;
553 555
554 return 0; 556 return 0;
555} /* cypress_ca42v2_startup */ 557}
556
557 558
558static void cypress_release(struct usb_serial *serial) 559static int cypress_port_remove(struct usb_serial_port *port)
559{ 560{
560 struct cypress_private *priv; 561 struct cypress_private *priv;
561 562
562 /* all open ports are closed at this point */ 563 priv = usb_get_serial_port_data(port);
563 priv = usb_get_serial_port_data(serial->port[0]);
564 564
565 if (priv) { 565 kfifo_free(&priv->write_fifo);
566 kfifo_free(&priv->write_fifo); 566 kfree(priv);
567 kfree(priv);
568 }
569}
570 567
568 return 0;
569}
571 570
572static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port) 571static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
573{ 572{
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index 244477107e2f..6e4eb57d0177 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -318,39 +318,30 @@ static int f81232_ioctl(struct tty_struct *tty,
318 return -ENOIOCTLCMD; 318 return -ENOIOCTLCMD;
319} 319}
320 320
321static int f81232_startup(struct usb_serial *serial) 321static int f81232_port_probe(struct usb_serial_port *port)
322{ 322{
323 struct f81232_private *priv; 323 struct f81232_private *priv;
324 int i;
325 324
326 for (i = 0; i < serial->num_ports; ++i) { 325 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
327 priv = kzalloc(sizeof(struct f81232_private), GFP_KERNEL); 326 if (!priv)
328 if (!priv) 327 return -ENOMEM;
329 goto cleanup;
330 spin_lock_init(&priv->lock);
331 init_waitqueue_head(&priv->delta_msr_wait);
332 usb_set_serial_port_data(serial->port[i], priv);
333 }
334 return 0;
335 328
336cleanup: 329 spin_lock_init(&priv->lock);
337 for (--i; i >= 0; --i) { 330 init_waitqueue_head(&priv->delta_msr_wait);
338 priv = usb_get_serial_port_data(serial->port[i]); 331
339 kfree(priv); 332 usb_set_serial_port_data(port, priv);
340 usb_set_serial_port_data(serial->port[i], NULL); 333
341 } 334 return 0;
342 return -ENOMEM;
343} 335}
344 336
345static void f81232_release(struct usb_serial *serial) 337static int f81232_port_remove(struct usb_serial_port *port)
346{ 338{
347 int i;
348 struct f81232_private *priv; 339 struct f81232_private *priv;
349 340
350 for (i = 0; i < serial->num_ports; ++i) { 341 priv = usb_get_serial_port_data(port);
351 priv = usb_get_serial_port_data(serial->port[i]); 342 kfree(priv);
352 kfree(priv); 343
353 } 344 return 0;
354} 345}
355 346
356static struct usb_serial_driver f81232_device = { 347static struct usb_serial_driver f81232_device = {
@@ -373,8 +364,8 @@ static struct usb_serial_driver f81232_device = {
373 .tiocmset = f81232_tiocmset, 364 .tiocmset = f81232_tiocmset,
374 .process_read_urb = f81232_process_read_urb, 365 .process_read_urb = f81232_process_read_urb,
375 .read_int_callback = f81232_read_int_callback, 366 .read_int_callback = f81232_read_int_callback,
376 .attach = f81232_startup, 367 .port_probe = f81232_port_probe,
377 .release = f81232_release, 368 .port_remove = f81232_port_remove,
378}; 369};
379 370
380static struct usb_serial_driver * const serial_drivers[] = { 371static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 3ee92648c02d..203358d7e7bc 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1405,11 +1405,10 @@ static void timeout_handler(unsigned long data)
1405 1405
1406 1406
1407 1407
1408static int garmin_attach(struct usb_serial *serial) 1408static int garmin_port_probe(struct usb_serial_port *port)
1409{ 1409{
1410 int status = 0; 1410 int status;
1411 struct usb_serial_port *port = serial->port[0]; 1411 struct garmin_data *garmin_data_p;
1412 struct garmin_data *garmin_data_p = NULL;
1413 1412
1414 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL); 1413 garmin_data_p = kzalloc(sizeof(struct garmin_data), GFP_KERNEL);
1415 if (garmin_data_p == NULL) { 1414 if (garmin_data_p == NULL) {
@@ -1434,22 +1433,14 @@ static int garmin_attach(struct usb_serial *serial)
1434} 1433}
1435 1434
1436 1435
1437static void garmin_disconnect(struct usb_serial *serial) 1436static int garmin_port_remove(struct usb_serial_port *port)
1438{ 1437{
1439 struct usb_serial_port *port = serial->port[0];
1440 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 1438 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1441 1439
1442 usb_kill_urb(port->interrupt_in_urb); 1440 usb_kill_urb(port->interrupt_in_urb);
1443 del_timer_sync(&garmin_data_p->timer); 1441 del_timer_sync(&garmin_data_p->timer);
1444}
1445
1446
1447static void garmin_release(struct usb_serial *serial)
1448{
1449 struct usb_serial_port *port = serial->port[0];
1450 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1451
1452 kfree(garmin_data_p); 1442 kfree(garmin_data_p);
1443 return 0;
1453} 1444}
1454 1445
1455 1446
@@ -1466,9 +1457,8 @@ static struct usb_serial_driver garmin_device = {
1466 .close = garmin_close, 1457 .close = garmin_close,
1467 .throttle = garmin_throttle, 1458 .throttle = garmin_throttle,
1468 .unthrottle = garmin_unthrottle, 1459 .unthrottle = garmin_unthrottle,
1469 .attach = garmin_attach, 1460 .port_probe = garmin_port_probe,
1470 .disconnect = garmin_disconnect, 1461 .port_remove = garmin_port_remove,
1471 .release = garmin_release,
1472 .write = garmin_write, 1462 .write = garmin_write,
1473 .write_room = garmin_write_room, 1463 .write_room = garmin_write_room,
1474 .write_bulk_callback = garmin_write_bulk_callback, 1464 .write_bulk_callback = garmin_write_bulk_callback,
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 8e6faaf3580c..5acc0d13864a 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -225,6 +225,8 @@ static int edge_get_icount(struct tty_struct *tty,
225static int edge_startup(struct usb_serial *serial); 225static int edge_startup(struct usb_serial *serial);
226static void edge_disconnect(struct usb_serial *serial); 226static void edge_disconnect(struct usb_serial *serial);
227static void edge_release(struct usb_serial *serial); 227static void edge_release(struct usb_serial *serial);
228static int edge_port_probe(struct usb_serial_port *port);
229static int edge_port_remove(struct usb_serial_port *port);
228 230
229#include "io_tables.h" /* all of the devices that this driver supports */ 231#include "io_tables.h" /* all of the devices that this driver supports */
230 232
@@ -2875,10 +2877,9 @@ static void load_application_firmware(struct edgeport_serial *edge_serial)
2875static int edge_startup(struct usb_serial *serial) 2877static int edge_startup(struct usb_serial *serial)
2876{ 2878{
2877 struct edgeport_serial *edge_serial; 2879 struct edgeport_serial *edge_serial;
2878 struct edgeport_port *edge_port;
2879 struct usb_device *dev; 2880 struct usb_device *dev;
2880 struct device *ddev = &serial->dev->dev; 2881 struct device *ddev = &serial->dev->dev;
2881 int i, j; 2882 int i;
2882 int response; 2883 int response;
2883 bool interrupt_in_found; 2884 bool interrupt_in_found;
2884 bool bulk_in_found; 2885 bool bulk_in_found;
@@ -2961,25 +2962,6 @@ static int edge_startup(struct usb_serial *serial)
2961 /* we set up the pointers to the endpoints in the edge_open function, 2962 /* we set up the pointers to the endpoints in the edge_open function,
2962 * as the structures aren't created yet. */ 2963 * as the structures aren't created yet. */
2963 2964
2964 /* set up our port private structures */
2965 for (i = 0; i < serial->num_ports; ++i) {
2966 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2967 if (edge_port == NULL) {
2968 dev_err(ddev, "%s - Out of memory\n", __func__);
2969 for (j = 0; j < i; ++j) {
2970 kfree(usb_get_serial_port_data(serial->port[j]));
2971 usb_set_serial_port_data(serial->port[j],
2972 NULL);
2973 }
2974 usb_set_serial_data(serial, NULL);
2975 kfree(edge_serial);
2976 return -ENOMEM;
2977 }
2978 spin_lock_init(&edge_port->ep_lock);
2979 edge_port->port = serial->port[i];
2980 usb_set_serial_port_data(serial->port[i], edge_port);
2981 }
2982
2983 response = 0; 2965 response = 0;
2984 2966
2985 if (edge_serial->is_epic) { 2967 if (edge_serial->is_epic) {
@@ -3120,14 +3102,36 @@ static void edge_disconnect(struct usb_serial *serial)
3120static void edge_release(struct usb_serial *serial) 3102static void edge_release(struct usb_serial *serial)
3121{ 3103{
3122 struct edgeport_serial *edge_serial = usb_get_serial_data(serial); 3104 struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
3123 int i;
3124
3125 for (i = 0; i < serial->num_ports; ++i)
3126 kfree(usb_get_serial_port_data(serial->port[i]));
3127 3105
3128 kfree(edge_serial); 3106 kfree(edge_serial);
3129} 3107}
3130 3108
3109static int edge_port_probe(struct usb_serial_port *port)
3110{
3111 struct edgeport_port *edge_port;
3112
3113 edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
3114 if (!edge_port)
3115 return -ENOMEM;
3116
3117 spin_lock_init(&edge_port->ep_lock);
3118 edge_port->port = port;
3119
3120 usb_set_serial_port_data(port, edge_port);
3121
3122 return 0;
3123}
3124
3125static int edge_port_remove(struct usb_serial_port *port)
3126{
3127 struct edgeport_port *edge_port;
3128
3129 edge_port = usb_get_serial_port_data(port);
3130 kfree(edge_port);
3131
3132 return 0;
3133}
3134
3131module_usb_serial_driver(serial_drivers, id_table_combined); 3135module_usb_serial_driver(serial_drivers, id_table_combined);
3132 3136
3133MODULE_AUTHOR(DRIVER_AUTHOR); 3137MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 350afddb55ba..1511dd0ad324 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -110,6 +110,8 @@ static struct usb_serial_driver edgeport_2port_device = {
110 .attach = edge_startup, 110 .attach = edge_startup,
111 .disconnect = edge_disconnect, 111 .disconnect = edge_disconnect,
112 .release = edge_release, 112 .release = edge_release,
113 .port_probe = edge_port_probe,
114 .port_remove = edge_port_remove,
113 .ioctl = edge_ioctl, 115 .ioctl = edge_ioctl,
114 .set_termios = edge_set_termios, 116 .set_termios = edge_set_termios,
115 .tiocmget = edge_tiocmget, 117 .tiocmget = edge_tiocmget,
@@ -139,6 +141,8 @@ static struct usb_serial_driver edgeport_4port_device = {
139 .attach = edge_startup, 141 .attach = edge_startup,
140 .disconnect = edge_disconnect, 142 .disconnect = edge_disconnect,
141 .release = edge_release, 143 .release = edge_release,
144 .port_probe = edge_port_probe,
145 .port_remove = edge_port_remove,
142 .ioctl = edge_ioctl, 146 .ioctl = edge_ioctl,
143 .set_termios = edge_set_termios, 147 .set_termios = edge_set_termios,
144 .tiocmget = edge_tiocmget, 148 .tiocmget = edge_tiocmget,
@@ -168,6 +172,8 @@ static struct usb_serial_driver edgeport_8port_device = {
168 .attach = edge_startup, 172 .attach = edge_startup,
169 .disconnect = edge_disconnect, 173 .disconnect = edge_disconnect,
170 .release = edge_release, 174 .release = edge_release,
175 .port_probe = edge_port_probe,
176 .port_remove = edge_port_remove,
171 .ioctl = edge_ioctl, 177 .ioctl = edge_ioctl,
172 .set_termios = edge_set_termios, 178 .set_termios = edge_set_termios,
173 .tiocmget = edge_tiocmget, 179 .tiocmget = edge_tiocmget,
@@ -197,6 +203,8 @@ static struct usb_serial_driver epic_device = {
197 .attach = edge_startup, 203 .attach = edge_startup,
198 .disconnect = edge_disconnect, 204 .disconnect = edge_disconnect,
199 .release = edge_release, 205 .release = edge_release,
206 .port_probe = edge_port_probe,
207 .port_remove = edge_port_remove,
200 .ioctl = edge_ioctl, 208 .ioctl = edge_ioctl,
201 .set_termios = edge_set_termios, 209 .set_termios = edge_set_termios,
202 .tiocmget = edge_tiocmget, 210 .tiocmget = edge_tiocmget,
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index a2209cd45093..60023c2d2a31 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2532,12 +2532,7 @@ static void edge_break(struct tty_struct *tty, int break_state)
2532static int edge_startup(struct usb_serial *serial) 2532static int edge_startup(struct usb_serial *serial)
2533{ 2533{
2534 struct edgeport_serial *edge_serial; 2534 struct edgeport_serial *edge_serial;
2535 struct edgeport_port *edge_port;
2536 struct usb_device *dev;
2537 int status; 2535 int status;
2538 int i;
2539
2540 dev = serial->dev;
2541 2536
2542 /* create our private serial structure */ 2537 /* create our private serial structure */
2543 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); 2538 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
@@ -2555,40 +2550,7 @@ static int edge_startup(struct usb_serial *serial)
2555 return status; 2550 return status;
2556 } 2551 }
2557 2552
2558 /* set up our port private structures */
2559 for (i = 0; i < serial->num_ports; ++i) {
2560 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2561 if (edge_port == NULL) {
2562 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2563 __func__);
2564 goto cleanup;
2565 }
2566 spin_lock_init(&edge_port->ep_lock);
2567 if (kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2568 GFP_KERNEL)) {
2569 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2570 __func__);
2571 kfree(edge_port);
2572 goto cleanup;
2573 }
2574 edge_port->port = serial->port[i];
2575 edge_port->edge_serial = edge_serial;
2576 usb_set_serial_port_data(serial->port[i], edge_port);
2577 edge_port->bUartMode = default_uart_mode;
2578 }
2579
2580 return 0; 2553 return 0;
2581
2582cleanup:
2583 for (--i; i >= 0; --i) {
2584 edge_port = usb_get_serial_port_data(serial->port[i]);
2585 kfifo_free(&edge_port->write_fifo);
2586 kfree(edge_port);
2587 usb_set_serial_port_data(serial->port[i], NULL);
2588 }
2589 kfree(edge_serial);
2590 usb_set_serial_data(serial, NULL);
2591 return -ENOMEM;
2592} 2554}
2593 2555
2594static void edge_disconnect(struct usb_serial *serial) 2556static void edge_disconnect(struct usb_serial *serial)
@@ -2597,17 +2559,54 @@ static void edge_disconnect(struct usb_serial *serial)
2597 2559
2598static void edge_release(struct usb_serial *serial) 2560static void edge_release(struct usb_serial *serial)
2599{ 2561{
2600 int i; 2562 kfree(usb_get_serial_data(serial));
2563}
2564
2565static int edge_port_probe(struct usb_serial_port *port)
2566{
2601 struct edgeport_port *edge_port; 2567 struct edgeport_port *edge_port;
2568 int ret;
2602 2569
2603 for (i = 0; i < serial->num_ports; ++i) { 2570 edge_port = kzalloc(sizeof(*edge_port), GFP_KERNEL);
2604 edge_port = usb_get_serial_port_data(serial->port[i]); 2571 if (!edge_port)
2572 return -ENOMEM;
2573
2574 ret = kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2575 GFP_KERNEL);
2576 if (ret) {
2577 kfree(edge_port);
2578 return -ENOMEM;
2579 }
2580
2581 spin_lock_init(&edge_port->ep_lock);
2582 edge_port->port = port;
2583 edge_port->edge_serial = usb_get_serial_data(port->serial);
2584 edge_port->bUartMode = default_uart_mode;
2585
2586 usb_set_serial_port_data(port, edge_port);
2587
2588 ret = edge_create_sysfs_attrs(port);
2589 if (ret) {
2605 kfifo_free(&edge_port->write_fifo); 2590 kfifo_free(&edge_port->write_fifo);
2606 kfree(edge_port); 2591 kfree(edge_port);
2592 return ret;
2607 } 2593 }
2608 kfree(usb_get_serial_data(serial)); 2594
2595 return 0;
2609} 2596}
2610 2597
2598static int edge_port_remove(struct usb_serial_port *port)
2599{
2600 struct edgeport_port *edge_port;
2601
2602 edge_port = usb_get_serial_port_data(port);
2603
2604 edge_remove_sysfs_attrs(port);
2605 kfifo_free(&edge_port->write_fifo);
2606 kfree(edge_port);
2607
2608 return 0;
2609}
2611 2610
2612/* Sysfs Attributes */ 2611/* Sysfs Attributes */
2613 2612
@@ -2667,8 +2666,8 @@ static struct usb_serial_driver edgeport_1port_device = {
2667 .attach = edge_startup, 2666 .attach = edge_startup,
2668 .disconnect = edge_disconnect, 2667 .disconnect = edge_disconnect,
2669 .release = edge_release, 2668 .release = edge_release,
2670 .port_probe = edge_create_sysfs_attrs, 2669 .port_probe = edge_port_probe,
2671 .port_remove = edge_remove_sysfs_attrs, 2670 .port_remove = edge_port_remove,
2672 .ioctl = edge_ioctl, 2671 .ioctl = edge_ioctl,
2673 .set_termios = edge_set_termios, 2672 .set_termios = edge_set_termios,
2674 .tiocmget = edge_tiocmget, 2673 .tiocmget = edge_tiocmget,
@@ -2698,8 +2697,8 @@ static struct usb_serial_driver edgeport_2port_device = {
2698 .attach = edge_startup, 2697 .attach = edge_startup,
2699 .disconnect = edge_disconnect, 2698 .disconnect = edge_disconnect,
2700 .release = edge_release, 2699 .release = edge_release,
2701 .port_probe = edge_create_sysfs_attrs, 2700 .port_probe = edge_port_probe,
2702 .port_remove = edge_remove_sysfs_attrs, 2701 .port_remove = edge_port_remove,
2703 .ioctl = edge_ioctl, 2702 .ioctl = edge_ioctl,
2704 .set_termios = edge_set_termios, 2703 .set_termios = edge_set_termios,
2705 .tiocmget = edge_tiocmget, 2704 .tiocmget = edge_tiocmget,
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 01da3ea36e89..cd5533e81de7 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -53,6 +53,8 @@ static int iuu_cardout;
53static bool xmas; 53static bool xmas;
54static int vcc_default = 5; 54static int vcc_default = 5;
55 55
56static int iuu_create_sysfs_attrs(struct usb_serial_port *port);
57static int iuu_remove_sysfs_attrs(struct usb_serial_port *port);
56static void read_rxcmd_callback(struct urb *urb); 58static void read_rxcmd_callback(struct urb *urb);
57 59
58struct iuu_private { 60struct iuu_private {
@@ -72,63 +74,55 @@ struct iuu_private {
72 u32 clk; 74 u32 clk;
73}; 75};
74 76
75 77static int iuu_port_probe(struct usb_serial_port *port)
76static void iuu_free_buf(struct iuu_private *priv)
77{
78 kfree(priv->buf);
79 kfree(priv->writebuf);
80}
81
82static int iuu_alloc_buf(struct usb_serial *serial, struct iuu_private *priv)
83{
84 priv->buf = kzalloc(256, GFP_KERNEL);
85 priv->writebuf = kzalloc(256, GFP_KERNEL);
86 if (!priv->buf || !priv->writebuf) {
87 iuu_free_buf(priv);
88 dev_dbg(&serial->dev->dev, "%s problem allocation buffer\n", __func__);
89 return -ENOMEM;
90 }
91 dev_dbg(&serial->dev->dev, "%s - Privates buffers allocation success\n", __func__);
92 return 0;
93}
94
95static int iuu_startup(struct usb_serial *serial)
96{ 78{
97 struct iuu_private *priv; 79 struct iuu_private *priv;
80 int ret;
98 81
99 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL); 82 priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL);
100 dev_dbg(&serial->dev->dev, "%s- priv allocation success\n", __func__);
101 if (!priv) 83 if (!priv)
102 return -ENOMEM; 84 return -ENOMEM;
103 if (iuu_alloc_buf(serial, priv)) { 85
86 priv->buf = kzalloc(256, GFP_KERNEL);
87 if (!priv->buf) {
88 kfree(priv);
89 return -ENOMEM;
90 }
91
92 priv->writebuf = kzalloc(256, GFP_KERNEL);
93 if (!priv->writebuf) {
94 kfree(priv->buf);
104 kfree(priv); 95 kfree(priv);
105 return -ENOMEM; 96 return -ENOMEM;
106 } 97 }
98
107 priv->vcc = vcc_default; 99 priv->vcc = vcc_default;
108 spin_lock_init(&priv->lock); 100 spin_lock_init(&priv->lock);
109 init_waitqueue_head(&priv->delta_msr_wait); 101 init_waitqueue_head(&priv->delta_msr_wait);
110 usb_set_serial_port_data(serial->port[0], priv); 102
103 usb_set_serial_port_data(port, priv);
104
105 ret = iuu_create_sysfs_attrs(port);
106 if (ret) {
107 kfree(priv->writebuf);
108 kfree(priv->buf);
109 kfree(priv);
110 return ret;
111 }
112
111 return 0; 113 return 0;
112} 114}
113 115
114/* Release function */ 116static int iuu_port_remove(struct usb_serial_port *port)
115static void iuu_release(struct usb_serial *serial)
116{ 117{
117 struct usb_serial_port *port = serial->port[0];
118 struct iuu_private *priv = usb_get_serial_port_data(port); 118 struct iuu_private *priv = usb_get_serial_port_data(port);
119 if (!port)
120 return;
121 119
122 if (priv) { 120 iuu_remove_sysfs_attrs(port);
123 iuu_free_buf(priv); 121 kfree(priv->writebuf);
124 dev_dbg(&port->dev, "%s - I will free all\n", __func__); 122 kfree(priv->buf);
125 usb_set_serial_port_data(port, NULL); 123 kfree(priv);
126
127 dev_dbg(&port->dev, "%s - priv is not anymore in port structure\n", __func__);
128 kfree(priv);
129 124
130 dev_dbg(&port->dev, "%s priv is now kfree\n", __func__); 125 return 0;
131 }
132} 126}
133 127
134static int iuu_tiocmset(struct tty_struct *tty, 128static int iuu_tiocmset(struct tty_struct *tty,
@@ -1215,8 +1209,6 @@ static struct usb_serial_driver iuu_device = {
1215 .num_ports = 1, 1209 .num_ports = 1,
1216 .bulk_in_size = 512, 1210 .bulk_in_size = 512,
1217 .bulk_out_size = 512, 1211 .bulk_out_size = 512,
1218 .port_probe = iuu_create_sysfs_attrs,
1219 .port_remove = iuu_remove_sysfs_attrs,
1220 .open = iuu_open, 1212 .open = iuu_open,
1221 .close = iuu_close, 1213 .close = iuu_close,
1222 .write = iuu_uart_write, 1214 .write = iuu_uart_write,
@@ -1225,8 +1217,8 @@ static struct usb_serial_driver iuu_device = {
1225 .tiocmset = iuu_tiocmset, 1217 .tiocmset = iuu_tiocmset,
1226 .set_termios = iuu_set_termios, 1218 .set_termios = iuu_set_termios,
1227 .init_termios = iuu_init_termios, 1219 .init_termios = iuu_init_termios,
1228 .attach = iuu_startup, 1220 .port_probe = iuu_port_probe,
1229 .release = iuu_release, 1221 .port_remove = iuu_port_remove,
1230}; 1222};
1231 1223
1232static struct usb_serial_driver * const serial_drivers[] = { 1224static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index ca43ecb4a2bd..bb87e29c4ac2 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -713,29 +713,33 @@ MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
713MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw"); 713MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
714#endif 714#endif
715 715
716static int keyspan_pda_startup(struct usb_serial *serial) 716static int keyspan_pda_port_probe(struct usb_serial_port *port)
717{ 717{
718 718
719 struct keyspan_pda_private *priv; 719 struct keyspan_pda_private *priv;
720 720
721 /* allocate the private data structures for all ports. Well, for all
722 one ports. */
723
724 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL); 721 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
725 if (!priv) 722 if (!priv)
726 return 1; /* error */ 723 return -ENOMEM;
727 usb_set_serial_port_data(serial->port[0], priv); 724
728 init_waitqueue_head(&serial->port[0]->write_wait);
729 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write); 725 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
730 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); 726 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
731 priv->serial = serial; 727 priv->serial = port->serial;
732 priv->port = serial->port[0]; 728 priv->port = port;
729
730 usb_set_serial_port_data(port, priv);
731
733 return 0; 732 return 0;
734} 733}
735 734
736static void keyspan_pda_release(struct usb_serial *serial) 735static int keyspan_pda_port_remove(struct usb_serial_port *port)
737{ 736{
738 kfree(usb_get_serial_port_data(serial->port[0])); 737 struct keyspan_pda_private *priv;
738
739 priv = usb_get_serial_port_data(port);
740 kfree(priv);
741
742 return 0;
739} 743}
740 744
741#ifdef KEYSPAN 745#ifdef KEYSPAN
@@ -786,8 +790,8 @@ static struct usb_serial_driver keyspan_pda_device = {
786 .break_ctl = keyspan_pda_break_ctl, 790 .break_ctl = keyspan_pda_break_ctl,
787 .tiocmget = keyspan_pda_tiocmget, 791 .tiocmget = keyspan_pda_tiocmget,
788 .tiocmset = keyspan_pda_tiocmset, 792 .tiocmset = keyspan_pda_tiocmset,
789 .attach = keyspan_pda_startup, 793 .port_probe = keyspan_pda_port_probe,
790 .release = keyspan_pda_release, 794 .port_remove = keyspan_pda_port_remove,
791}; 795};
792 796
793static struct usb_serial_driver * const serial_drivers[] = { 797static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 3f6d7376c02d..1f4517864cd2 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -60,8 +60,8 @@
60/* 60/*
61 * Function prototypes 61 * Function prototypes
62 */ 62 */
63static int klsi_105_startup(struct usb_serial *serial); 63static int klsi_105_port_probe(struct usb_serial_port *port);
64static void klsi_105_release(struct usb_serial *serial); 64static int klsi_105_port_remove(struct usb_serial_port *port);
65static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port); 65static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port);
66static void klsi_105_close(struct usb_serial_port *port); 66static void klsi_105_close(struct usb_serial_port *port);
67static void klsi_105_set_termios(struct tty_struct *tty, 67static void klsi_105_set_termios(struct tty_struct *tty,
@@ -99,8 +99,8 @@ static struct usb_serial_driver kl5kusb105d_device = {
99 /*.break_ctl = klsi_105_break_ctl,*/ 99 /*.break_ctl = klsi_105_break_ctl,*/
100 .tiocmget = klsi_105_tiocmget, 100 .tiocmget = klsi_105_tiocmget,
101 .tiocmset = klsi_105_tiocmset, 101 .tiocmset = klsi_105_tiocmset,
102 .attach = klsi_105_startup, 102 .port_probe = klsi_105_port_probe,
103 .release = klsi_105_release, 103 .port_remove = klsi_105_port_remove,
104 .throttle = usb_serial_generic_throttle, 104 .throttle = usb_serial_generic_throttle,
105 .unthrottle = usb_serial_generic_unthrottle, 105 .unthrottle = usb_serial_generic_unthrottle,
106 .process_read_urb = klsi_105_process_read_urb, 106 .process_read_urb = klsi_105_process_read_urb,
@@ -223,60 +223,40 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
223 * Driver's tty interface functions 223 * Driver's tty interface functions
224 */ 224 */
225 225
226static int klsi_105_startup(struct usb_serial *serial) 226static int klsi_105_port_probe(struct usb_serial_port *port)
227{ 227{
228 struct klsi_105_private *priv; 228 struct klsi_105_private *priv;
229 int i;
230 229
231 /* check if we support the product id (see keyspan.c) 230 priv = kmalloc(sizeof(*priv), GFP_KERNEL);
232 * FIXME 231 if (!priv)
233 */ 232 return -ENOMEM;
234 233
235 /* allocate the private data structure */ 234 /* set initial values for control structures */
236 for (i = 0; i < serial->num_ports; i++) { 235 priv->cfg.pktlen = 5;
237 priv = kmalloc(sizeof(struct klsi_105_private), 236 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
238 GFP_KERNEL); 237 priv->cfg.databits = kl5kusb105a_dtb_8;
239 if (!priv) { 238 priv->cfg.unknown1 = 0;
240 dev_dbg(&serial->interface->dev, 239 priv->cfg.unknown2 = 1;
241 "%s - kmalloc for klsi_105_private failed.\n",
242 __func__);
243 i--;
244 goto err_cleanup;
245 }
246 /* set initial values for control structures */
247 priv->cfg.pktlen = 5;
248 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
249 priv->cfg.databits = kl5kusb105a_dtb_8;
250 priv->cfg.unknown1 = 0;
251 priv->cfg.unknown2 = 1;
252 240
253 priv->line_state = 0; 241 priv->line_state = 0;
254 242
255 usb_set_serial_port_data(serial->port[i], priv); 243 spin_lock_init(&priv->lock);
256 244
257 spin_lock_init(&priv->lock); 245 /* priv->termios is left uninitialized until port opening */
258 246
259 /* priv->termios is left uninitialized until port opening */ 247 usb_set_serial_port_data(port, priv);
260 init_waitqueue_head(&serial->port[i]->write_wait);
261 }
262 248
263 return 0; 249 return 0;
264
265err_cleanup:
266 for (; i >= 0; i--) {
267 priv = usb_get_serial_port_data(serial->port[i]);
268 kfree(priv);
269 usb_set_serial_port_data(serial->port[i], NULL);
270 }
271 return -ENOMEM;
272} 250}
273 251
274static void klsi_105_release(struct usb_serial *serial) 252static int klsi_105_port_remove(struct usb_serial_port *port)
275{ 253{
276 int i; 254 struct klsi_105_private *priv;
255
256 priv = usb_get_serial_port_data(port);
257 kfree(priv);
277 258
278 for (i = 0; i < serial->num_ports; ++i) 259 return 0;
279 kfree(usb_get_serial_port_data(serial->port[i]));
280} 260}
281 261
282static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) 262static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 5c4d2fbd4e11..c9ca7a5b12e0 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -54,8 +54,8 @@
54 54
55 55
56/* Function prototypes */ 56/* Function prototypes */
57static int kobil_startup(struct usb_serial *serial); 57static int kobil_port_probe(struct usb_serial_port *probe);
58static void kobil_release(struct usb_serial *serial); 58static int kobil_port_remove(struct usb_serial_port *probe);
59static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); 59static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port);
60static void kobil_close(struct usb_serial_port *port); 60static void kobil_close(struct usb_serial_port *port);
61static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, 61static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -89,8 +89,8 @@ static struct usb_serial_driver kobil_device = {
89 .description = "KOBIL USB smart card terminal", 89 .description = "KOBIL USB smart card terminal",
90 .id_table = id_table, 90 .id_table = id_table,
91 .num_ports = 1, 91 .num_ports = 1,
92 .attach = kobil_startup, 92 .port_probe = kobil_port_probe,
93 .release = kobil_release, 93 .port_remove = kobil_port_remove,
94 .ioctl = kobil_ioctl, 94 .ioctl = kobil_ioctl,
95 .set_termios = kobil_set_termios, 95 .set_termios = kobil_set_termios,
96 .init_termios = kobil_init_termios, 96 .init_termios = kobil_init_termios,
@@ -117,9 +117,10 @@ struct kobil_private {
117}; 117};
118 118
119 119
120static int kobil_startup(struct usb_serial *serial) 120static int kobil_port_probe(struct usb_serial_port *port)
121{ 121{
122 int i; 122 int i;
123 struct usb_serial *serial = port->serial;
123 struct kobil_private *priv; 124 struct kobil_private *priv;
124 struct usb_device *pdev; 125 struct usb_device *pdev;
125 struct usb_host_config *actconfig; 126 struct usb_host_config *actconfig;
@@ -149,7 +150,7 @@ static int kobil_startup(struct usb_serial *serial)
149 dev_dbg(&serial->dev->dev, "KOBIL KAAN SIM detected\n"); 150 dev_dbg(&serial->dev->dev, "KOBIL KAAN SIM detected\n");
150 break; 151 break;
151 } 152 }
152 usb_set_serial_port_data(serial->port[0], priv); 153 usb_set_serial_port_data(port, priv);
153 154
154 /* search for the necessary endpoints */ 155 /* search for the necessary endpoints */
155 pdev = serial->dev; 156 pdev = serial->dev;
@@ -179,12 +180,14 @@ static int kobil_startup(struct usb_serial *serial)
179} 180}
180 181
181 182
182static void kobil_release(struct usb_serial *serial) 183static int kobil_port_remove(struct usb_serial_port *port)
183{ 184{
184 int i; 185 struct kobil_private *priv;
185 186
186 for (i = 0; i < serial->num_ports; ++i) 187 priv = usb_get_serial_port_data(port);
187 kfree(usb_get_serial_port_data(serial->port[i])); 188 kfree(priv);
189
190 return 0;
188} 191}
189 192
190static void kobil_init_termios(struct tty_struct *tty) 193static void kobil_init_termios(struct tty_struct *tty)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 30cff03e9f01..54d4148d01d1 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -503,11 +503,19 @@ static const struct option_blacklist_info net_intf5_blacklist = {
503 .reserved = BIT(5), 503 .reserved = BIT(5),
504}; 504};
505 505
506static const struct option_blacklist_info net_intf6_blacklist = {
507 .reserved = BIT(6),
508};
509
506static const struct option_blacklist_info zte_mf626_blacklist = { 510static const struct option_blacklist_info zte_mf626_blacklist = {
507 .sendsetup = BIT(0) | BIT(1), 511 .sendsetup = BIT(0) | BIT(1),
508 .reserved = BIT(4), 512 .reserved = BIT(4),
509}; 513};
510 514
515static const struct option_blacklist_info zte_1255_blacklist = {
516 .reserved = BIT(3) | BIT(4),
517};
518
511static const struct usb_device_id option_ids[] = { 519static const struct usb_device_id option_ids[] = {
512 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) }, 520 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
513 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) }, 521 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
@@ -853,13 +861,19 @@ static const struct usb_device_id option_ids[] = {
853 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0113, 0xff, 0xff, 0xff), 861 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0113, 0xff, 0xff, 0xff),
854 .driver_info = (kernel_ulong_t)&net_intf5_blacklist }, 862 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
855 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0117, 0xff, 0xff, 0xff) }, 863 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0117, 0xff, 0xff, 0xff) },
856 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0118, 0xff, 0xff, 0xff) }, 864 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0118, 0xff, 0xff, 0xff),
857 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0121, 0xff, 0xff, 0xff) }, 865 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
866 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0121, 0xff, 0xff, 0xff),
867 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
858 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0122, 0xff, 0xff, 0xff) }, 868 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0122, 0xff, 0xff, 0xff) },
859 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0123, 0xff, 0xff, 0xff) }, 869 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0123, 0xff, 0xff, 0xff),
860 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0124, 0xff, 0xff, 0xff) }, 870 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
861 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0125, 0xff, 0xff, 0xff) }, 871 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0124, 0xff, 0xff, 0xff),
862 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0126, 0xff, 0xff, 0xff) }, 872 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
873 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0125, 0xff, 0xff, 0xff),
874 .driver_info = (kernel_ulong_t)&net_intf6_blacklist },
875 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0126, 0xff, 0xff, 0xff),
876 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
863 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0128, 0xff, 0xff, 0xff) }, 877 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0128, 0xff, 0xff, 0xff) },
864 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0142, 0xff, 0xff, 0xff) }, 878 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0142, 0xff, 0xff, 0xff) },
865 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0143, 0xff, 0xff, 0xff) }, 879 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0143, 0xff, 0xff, 0xff) },
@@ -872,7 +886,8 @@ static const struct usb_device_id option_ids[] = {
872 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0156, 0xff, 0xff, 0xff) }, 886 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0156, 0xff, 0xff, 0xff) },
873 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0157, 0xff, 0xff, 0xff), 887 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0157, 0xff, 0xff, 0xff),
874 .driver_info = (kernel_ulong_t)&net_intf5_blacklist }, 888 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
875 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0158, 0xff, 0xff, 0xff) }, 889 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0158, 0xff, 0xff, 0xff),
890 .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
876 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0159, 0xff, 0xff, 0xff) }, 891 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0159, 0xff, 0xff, 0xff) },
877 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0161, 0xff, 0xff, 0xff) }, 892 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0161, 0xff, 0xff, 0xff) },
878 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0162, 0xff, 0xff, 0xff) }, 893 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0162, 0xff, 0xff, 0xff) },
@@ -880,13 +895,22 @@ static const struct usb_device_id option_ids[] = {
880 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0165, 0xff, 0xff, 0xff) }, 895 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0165, 0xff, 0xff, 0xff) },
881 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0167, 0xff, 0xff, 0xff), 896 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0167, 0xff, 0xff, 0xff),
882 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 897 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
898 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0191, 0xff, 0xff, 0xff), /* ZTE EuFi890 */
899 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
900 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0199, 0xff, 0xff, 0xff), /* ZTE MF820S */
901 .driver_info = (kernel_ulong_t)&net_intf1_blacklist },
902 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0257, 0xff, 0xff, 0xff), /* ZTE MF821 */
903 .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
883 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0326, 0xff, 0xff, 0xff), 904 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0326, 0xff, 0xff, 0xff),
884 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 905 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
885 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1008, 0xff, 0xff, 0xff), 906 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1008, 0xff, 0xff, 0xff),
886 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 907 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
887 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1010, 0xff, 0xff, 0xff), 908 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1010, 0xff, 0xff, 0xff),
888 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 909 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
889 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1012, 0xff, 0xff, 0xff) }, 910 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1012, 0xff, 0xff, 0xff),
911 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
912 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1021, 0xff, 0xff, 0xff),
913 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
890 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1057, 0xff, 0xff, 0xff) }, 914 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1057, 0xff, 0xff, 0xff) },
891 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1058, 0xff, 0xff, 0xff) }, 915 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1058, 0xff, 0xff, 0xff) },
892 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1059, 0xff, 0xff, 0xff) }, 916 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1059, 0xff, 0xff, 0xff) },
@@ -1002,18 +1026,24 @@ static const struct usb_device_id option_ids[] = {
1002 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1169, 0xff, 0xff, 0xff) }, 1026 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1169, 0xff, 0xff, 0xff) },
1003 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1170, 0xff, 0xff, 0xff) }, 1027 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1170, 0xff, 0xff, 0xff) },
1004 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1244, 0xff, 0xff, 0xff) }, 1028 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1244, 0xff, 0xff, 0xff) },
1005 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1245, 0xff, 0xff, 0xff) }, 1029 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1245, 0xff, 0xff, 0xff),
1030 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1006 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1246, 0xff, 0xff, 0xff) }, 1031 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1246, 0xff, 0xff, 0xff) },
1007 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1247, 0xff, 0xff, 0xff) }, 1032 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1247, 0xff, 0xff, 0xff),
1033 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1008 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1248, 0xff, 0xff, 0xff) }, 1034 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1248, 0xff, 0xff, 0xff) },
1009 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1249, 0xff, 0xff, 0xff) }, 1035 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1249, 0xff, 0xff, 0xff) },
1010 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1250, 0xff, 0xff, 0xff) }, 1036 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1250, 0xff, 0xff, 0xff) },
1011 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1251, 0xff, 0xff, 0xff) }, 1037 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1251, 0xff, 0xff, 0xff) },
1012 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1252, 0xff, 0xff, 0xff) }, 1038 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1252, 0xff, 0xff, 0xff),
1039 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1013 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1253, 0xff, 0xff, 0xff) }, 1040 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1253, 0xff, 0xff, 0xff) },
1014 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1254, 0xff, 0xff, 0xff) }, 1041 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1254, 0xff, 0xff, 0xff),
1015 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1255, 0xff, 0xff, 0xff) }, 1042 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1016 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1256, 0xff, 0xff, 0xff) }, 1043 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1255, 0xff, 0xff, 0xff),
1044 .driver_info = (kernel_ulong_t)&zte_1255_blacklist },
1045 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1256, 0xff, 0xff, 0xff),
1046 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1017 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1257, 0xff, 0xff, 0xff) }, 1047 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1257, 0xff, 0xff, 0xff) },
1018 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1258, 0xff, 0xff, 0xff) }, 1048 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1258, 0xff, 0xff, 0xff) },
1019 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1259, 0xff, 0xff, 0xff) }, 1049 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1259, 0xff, 0xff, 0xff) },
@@ -1058,8 +1088,16 @@ static const struct usb_device_id option_ids[] = {
1058 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1298, 0xff, 0xff, 0xff) }, 1088 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1298, 0xff, 0xff, 0xff) },
1059 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1299, 0xff, 0xff, 0xff) }, 1089 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1299, 0xff, 0xff, 0xff) },
1060 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1300, 0xff, 0xff, 0xff) }, 1090 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1300, 0xff, 0xff, 0xff) },
1091 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1401, 0xff, 0xff, 0xff),
1092 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1061 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1402, 0xff, 0xff, 0xff), 1093 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1402, 0xff, 0xff, 0xff),
1062 .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, 1094 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1095 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1424, 0xff, 0xff, 0xff),
1096 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1097 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1425, 0xff, 0xff, 0xff),
1098 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1099 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */
1100 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1063 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 1101 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff,
1064 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist }, 1102 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist },
1065 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, 1103 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
@@ -1071,15 +1109,21 @@ static const struct usb_device_id option_ids[] = {
1071 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0070, 0xff, 0xff, 0xff) }, 1109 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0070, 0xff, 0xff, 0xff) },
1072 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, 1110 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) },
1073 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0094, 0xff, 0xff, 0xff) }, 1111 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0094, 0xff, 0xff, 0xff) },
1074 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0130, 0xff, 0xff, 0xff) }, 1112 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0130, 0xff, 0xff, 0xff),
1075 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0133, 0xff, 0xff, 0xff) }, 1113 .driver_info = (kernel_ulong_t)&net_intf1_blacklist },
1076 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0141, 0xff, 0xff, 0xff) }, 1114 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0133, 0xff, 0xff, 0xff),
1115 .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
1116 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0141, 0xff, 0xff, 0xff),
1117 .driver_info = (kernel_ulong_t)&net_intf5_blacklist },
1077 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0147, 0xff, 0xff, 0xff) }, 1118 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0147, 0xff, 0xff, 0xff) },
1078 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0152, 0xff, 0xff, 0xff) }, 1119 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0152, 0xff, 0xff, 0xff) },
1079 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0168, 0xff, 0xff, 0xff) }, 1120 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0168, 0xff, 0xff, 0xff),
1121 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1080 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0170, 0xff, 0xff, 0xff) }, 1122 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0170, 0xff, 0xff, 0xff) },
1081 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0176, 0xff, 0xff, 0xff) }, 1123 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0176, 0xff, 0xff, 0xff),
1082 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0178, 0xff, 0xff, 0xff) }, 1124 .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
1125 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0178, 0xff, 0xff, 0xff),
1126 .driver_info = (kernel_ulong_t)&net_intf3_blacklist },
1083 1127
1084 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, 1128 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) },
1085 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, 1129 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 933241f03fd8..cee9a52ca891 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -137,8 +137,8 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty);
137static int oti6858_tiocmget(struct tty_struct *tty); 137static int oti6858_tiocmget(struct tty_struct *tty);
138static int oti6858_tiocmset(struct tty_struct *tty, 138static int oti6858_tiocmset(struct tty_struct *tty,
139 unsigned int set, unsigned int clear); 139 unsigned int set, unsigned int clear);
140static int oti6858_startup(struct usb_serial *serial); 140static int oti6858_port_probe(struct usb_serial_port *port);
141static void oti6858_release(struct usb_serial *serial); 141static int oti6858_port_remove(struct usb_serial_port *port);
142 142
143/* device info */ 143/* device info */
144static struct usb_serial_driver oti6858_device = { 144static struct usb_serial_driver oti6858_device = {
@@ -161,8 +161,8 @@ static struct usb_serial_driver oti6858_device = {
161 .write_bulk_callback = oti6858_write_bulk_callback, 161 .write_bulk_callback = oti6858_write_bulk_callback,
162 .write_room = oti6858_write_room, 162 .write_room = oti6858_write_room,
163 .chars_in_buffer = oti6858_chars_in_buffer, 163 .chars_in_buffer = oti6858_chars_in_buffer,
164 .attach = oti6858_startup, 164 .port_probe = oti6858_port_probe,
165 .release = oti6858_release, 165 .port_remove = oti6858_port_remove,
166}; 166};
167 167
168static struct usb_serial_driver * const serial_drivers[] = { 168static struct usb_serial_driver * const serial_drivers[] = {
@@ -331,36 +331,33 @@ static void send_data(struct work_struct *work)
331 usb_serial_port_softint(port); 331 usb_serial_port_softint(port);
332} 332}
333 333
334static int oti6858_startup(struct usb_serial *serial) 334static int oti6858_port_probe(struct usb_serial_port *port)
335{ 335{
336 struct usb_serial_port *port = serial->port[0];
337 struct oti6858_private *priv; 336 struct oti6858_private *priv;
338 int i;
339
340 for (i = 0; i < serial->num_ports; ++i) {
341 priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL);
342 if (!priv)
343 break;
344
345 spin_lock_init(&priv->lock);
346 init_waitqueue_head(&priv->intr_wait);
347/* INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); */
348/* INIT_WORK(&priv->write_work, send_data, serial->port[i]); */
349 priv->port = port;
350 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
351 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
352
353 usb_set_serial_port_data(serial->port[i], priv);
354 }
355 if (i == serial->num_ports)
356 return 0;
357 337
358 for (--i; i >= 0; --i) { 338 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
359 priv = usb_get_serial_port_data(serial->port[i]); 339 if (!priv)
360 kfree(priv); 340 return -ENOMEM;
361 usb_set_serial_port_data(serial->port[i], NULL); 341
362 } 342 spin_lock_init(&priv->lock);
363 return -ENOMEM; 343 init_waitqueue_head(&priv->intr_wait);
344 priv->port = port;
345 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
346 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
347
348 usb_set_serial_port_data(port, priv);
349
350 return 0;
351}
352
353static int oti6858_port_remove(struct usb_serial_port *port)
354{
355 struct oti6858_private *priv;
356
357 priv = usb_get_serial_port_data(port);
358 kfree(priv);
359
360 return 0;
364} 361}
365 362
366static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port, 363static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -709,15 +706,6 @@ static int oti6858_ioctl(struct tty_struct *tty,
709 return -ENOIOCTLCMD; 706 return -ENOIOCTLCMD;
710} 707}
711 708
712
713static void oti6858_release(struct usb_serial *serial)
714{
715 int i;
716
717 for (i = 0; i < serial->num_ports; ++i)
718 kfree(usb_get_serial_port_data(serial->port[i]));
719}
720
721static void oti6858_read_int_callback(struct urb *urb) 709static void oti6858_read_int_callback(struct urb *urb)
722{ 710{
723 struct usb_serial_port *port = urb->context; 711 struct usb_serial_port *port = urb->context;
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 892ebdc7a364..600241901361 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -133,12 +133,15 @@ enum pl2303_type {
133 HX, /* HX version of the pl2303 chip */ 133 HX, /* HX version of the pl2303 chip */
134}; 134};
135 135
136struct pl2303_serial_private {
137 enum pl2303_type type;
138};
139
136struct pl2303_private { 140struct pl2303_private {
137 spinlock_t lock; 141 spinlock_t lock;
138 wait_queue_head_t delta_msr_wait; 142 wait_queue_head_t delta_msr_wait;
139 u8 line_control; 143 u8 line_control;
140 u8 line_status; 144 u8 line_status;
141 enum pl2303_type type;
142}; 145};
143 146
144static int pl2303_vendor_read(__u16 value, __u16 index, 147static int pl2303_vendor_read(__u16 value, __u16 index,
@@ -167,14 +170,19 @@ static int pl2303_vendor_write(__u16 value, __u16 index,
167 170
168static int pl2303_startup(struct usb_serial *serial) 171static int pl2303_startup(struct usb_serial *serial)
169{ 172{
170 struct pl2303_private *priv; 173 struct pl2303_serial_private *spriv;
171 enum pl2303_type type = type_0; 174 enum pl2303_type type = type_0;
172 unsigned char *buf; 175 unsigned char *buf;
173 int i; 176
177 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
178 if (!spriv)
179 return -ENOMEM;
174 180
175 buf = kmalloc(10, GFP_KERNEL); 181 buf = kmalloc(10, GFP_KERNEL);
176 if (buf == NULL) 182 if (!buf) {
183 kfree(spriv);
177 return -ENOMEM; 184 return -ENOMEM;
185 }
178 186
179 if (serial->dev->descriptor.bDeviceClass == 0x02) 187 if (serial->dev->descriptor.bDeviceClass == 0x02)
180 type = type_0; 188 type = type_0;
@@ -186,15 +194,8 @@ static int pl2303_startup(struct usb_serial *serial)
186 type = type_1; 194 type = type_1;
187 dev_dbg(&serial->interface->dev, "device type: %d\n", type); 195 dev_dbg(&serial->interface->dev, "device type: %d\n", type);
188 196
189 for (i = 0; i < serial->num_ports; ++i) { 197 spriv->type = type;
190 priv = kzalloc(sizeof(struct pl2303_private), GFP_KERNEL); 198 usb_set_serial_data(serial, spriv);
191 if (!priv)
192 goto cleanup;
193 spin_lock_init(&priv->lock);
194 init_waitqueue_head(&priv->delta_msr_wait);
195 priv->type = type;
196 usb_set_serial_port_data(serial->port[i], priv);
197 }
198 199
199 pl2303_vendor_read(0x8484, 0, serial, buf); 200 pl2303_vendor_read(0x8484, 0, serial, buf);
200 pl2303_vendor_write(0x0404, 0, serial); 201 pl2303_vendor_write(0x0404, 0, serial);
@@ -213,15 +214,40 @@ static int pl2303_startup(struct usb_serial *serial)
213 214
214 kfree(buf); 215 kfree(buf);
215 return 0; 216 return 0;
217}
216 218
217cleanup: 219static void pl2303_release(struct usb_serial *serial)
218 kfree(buf); 220{
219 for (--i; i >= 0; --i) { 221 struct pl2303_serial_private *spriv;
220 priv = usb_get_serial_port_data(serial->port[i]); 222
221 kfree(priv); 223 spriv = usb_get_serial_data(serial);
222 usb_set_serial_port_data(serial->port[i], NULL); 224 kfree(spriv);
223 } 225}
224 return -ENOMEM; 226
227static int pl2303_port_probe(struct usb_serial_port *port)
228{
229 struct pl2303_private *priv;
230
231 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
232 if (!priv)
233 return -ENOMEM;
234
235 spin_lock_init(&priv->lock);
236 init_waitqueue_head(&priv->delta_msr_wait);
237
238 usb_set_serial_port_data(port, priv);
239
240 return 0;
241}
242
243static int pl2303_port_remove(struct usb_serial_port *port)
244{
245 struct pl2303_private *priv;
246
247 priv = usb_get_serial_port_data(port);
248 kfree(priv);
249
250 return 0;
225} 251}
226 252
227static int set_control_lines(struct usb_device *dev, u8 value) 253static int set_control_lines(struct usb_device *dev, u8 value)
@@ -240,6 +266,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
240 struct usb_serial_port *port, struct ktermios *old_termios) 266 struct usb_serial_port *port, struct ktermios *old_termios)
241{ 267{
242 struct usb_serial *serial = port->serial; 268 struct usb_serial *serial = port->serial;
269 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
243 struct pl2303_private *priv = usb_get_serial_port_data(port); 270 struct pl2303_private *priv = usb_get_serial_port_data(port);
244 unsigned long flags; 271 unsigned long flags;
245 unsigned int cflag; 272 unsigned int cflag;
@@ -323,7 +350,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
323 } 350 }
324 if (baud > 1228800) { 351 if (baud > 1228800) {
325 /* type_0, type_1 only support up to 1228800 baud */ 352 /* type_0, type_1 only support up to 1228800 baud */
326 if (priv->type != HX) 353 if (spriv->type != HX)
327 baud = 1228800; 354 baud = 1228800;
328 else if (baud > 6000000) 355 else if (baud > 6000000)
329 baud = 6000000; 356 baud = 6000000;
@@ -426,7 +453,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
426 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); 453 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
427 454
428 if (cflag & CRTSCTS) { 455 if (cflag & CRTSCTS) {
429 if (priv->type == HX) 456 if (spriv->type == HX)
430 pl2303_vendor_write(0x0, 0x61, serial); 457 pl2303_vendor_write(0x0, 0x61, serial);
431 else 458 else
432 pl2303_vendor_write(0x0, 0x41, serial); 459 pl2303_vendor_write(0x0, 0x41, serial);
@@ -468,10 +495,10 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
468{ 495{
469 struct ktermios tmp_termios; 496 struct ktermios tmp_termios;
470 struct usb_serial *serial = port->serial; 497 struct usb_serial *serial = port->serial;
471 struct pl2303_private *priv = usb_get_serial_port_data(port); 498 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
472 int result; 499 int result;
473 500
474 if (priv->type != HX) { 501 if (spriv->type != HX) {
475 usb_clear_halt(serial->dev, port->write_urb->pipe); 502 usb_clear_halt(serial->dev, port->write_urb->pipe);
476 usb_clear_halt(serial->dev, port->read_urb->pipe); 503 usb_clear_halt(serial->dev, port->read_urb->pipe);
477 } else { 504 } else {
@@ -655,17 +682,6 @@ static void pl2303_break_ctl(struct tty_struct *tty, int break_state)
655 dev_err(&port->dev, "error sending break = %d\n", result); 682 dev_err(&port->dev, "error sending break = %d\n", result);
656} 683}
657 684
658static void pl2303_release(struct usb_serial *serial)
659{
660 int i;
661 struct pl2303_private *priv;
662
663 for (i = 0; i < serial->num_ports; ++i) {
664 priv = usb_get_serial_port_data(serial->port[i]);
665 kfree(priv);
666 }
667}
668
669static void pl2303_update_line_status(struct usb_serial_port *port, 685static void pl2303_update_line_status(struct usb_serial_port *port,
670 unsigned char *data, 686 unsigned char *data,
671 unsigned int actual_length) 687 unsigned int actual_length)
@@ -827,6 +843,8 @@ static struct usb_serial_driver pl2303_device = {
827 .read_int_callback = pl2303_read_int_callback, 843 .read_int_callback = pl2303_read_int_callback,
828 .attach = pl2303_startup, 844 .attach = pl2303_startup,
829 .release = pl2303_release, 845 .release = pl2303_release,
846 .port_probe = pl2303_port_probe,
847 .port_remove = pl2303_port_remove,
830}; 848};
831 849
832static struct usb_serial_driver * const serial_drivers[] = { 850static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 9716efe92955..769c137f8975 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -157,13 +157,10 @@ struct spcp8x5_private {
157 u8 line_status; 157 u8 line_status;
158}; 158};
159 159
160/* desc : when device plug in,this function would be called. 160static int spcp8x5_port_probe(struct usb_serial_port *port)
161 * thanks to usb_serial subsystem,then do almost every things for us. And what
162 * we should do just alloc the buffer */
163static int spcp8x5_startup(struct usb_serial *serial)
164{ 161{
162 struct usb_serial *serial = port->serial;
165 struct spcp8x5_private *priv; 163 struct spcp8x5_private *priv;
166 int i;
167 enum spcp8x5_type type = SPCP825_007_TYPE; 164 enum spcp8x5_type type = SPCP825_007_TYPE;
168 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 165 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
169 166
@@ -180,34 +177,27 @@ static int spcp8x5_startup(struct usb_serial *serial)
180 type = SPCP825_PHILIP_TYPE; 177 type = SPCP825_PHILIP_TYPE;
181 dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type); 178 dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type);
182 179
183 for (i = 0; i < serial->num_ports; ++i) { 180 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
184 priv = kzalloc(sizeof(struct spcp8x5_private), GFP_KERNEL); 181 if (!priv)
185 if (!priv) 182 return -ENOMEM;
186 goto cleanup;
187 183
188 spin_lock_init(&priv->lock); 184 spin_lock_init(&priv->lock);
189 init_waitqueue_head(&priv->delta_msr_wait); 185 init_waitqueue_head(&priv->delta_msr_wait);
190 priv->type = type; 186 priv->type = type;
191 usb_set_serial_port_data(serial->port[i] , priv); 187
192 } 188 usb_set_serial_port_data(port , priv);
193 189
194 return 0; 190 return 0;
195cleanup:
196 for (--i; i >= 0; --i) {
197 priv = usb_get_serial_port_data(serial->port[i]);
198 kfree(priv);
199 usb_set_serial_port_data(serial->port[i] , NULL);
200 }
201 return -ENOMEM;
202} 191}
203 192
204/* call when the device plug out. free all the memory alloced by probe */ 193static int spcp8x5_port_remove(struct usb_serial_port *port)
205static void spcp8x5_release(struct usb_serial *serial)
206{ 194{
207 int i; 195 struct spcp8x5_private *priv;
208 196
209 for (i = 0; i < serial->num_ports; i++) 197 priv = usb_get_serial_port_data(port);
210 kfree(usb_get_serial_port_data(serial->port[i])); 198 kfree(priv);
199
200 return 0;
211} 201}
212 202
213/* set the modem control line of the device. 203/* set the modem control line of the device.
@@ -649,8 +639,8 @@ static struct usb_serial_driver spcp8x5_device = {
649 .ioctl = spcp8x5_ioctl, 639 .ioctl = spcp8x5_ioctl,
650 .tiocmget = spcp8x5_tiocmget, 640 .tiocmget = spcp8x5_tiocmget,
651 .tiocmset = spcp8x5_tiocmset, 641 .tiocmset = spcp8x5_tiocmset,
652 .attach = spcp8x5_startup, 642 .port_probe = spcp8x5_port_probe,
653 .release = spcp8x5_release, 643 .port_remove = spcp8x5_port_remove,
654 .process_read_urb = spcp8x5_process_read_urb, 644 .process_read_urb = spcp8x5_process_read_urb,
655}; 645};
656 646
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index 015810b3785b..868d1e6852e2 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -67,13 +67,6 @@ struct ssu100_port_private {
67 struct async_icount icount; 67 struct async_icount icount;
68}; 68};
69 69
70static void ssu100_release(struct usb_serial *serial)
71{
72 struct ssu100_port_private *priv = usb_get_serial_port_data(*serial->port);
73
74 kfree(priv);
75}
76
77static inline int ssu100_control_msg(struct usb_device *dev, 70static inline int ssu100_control_msg(struct usb_device *dev,
78 u8 request, u16 data, u16 index) 71 u8 request, u16 data, u16 index)
79{ 72{
@@ -442,21 +435,33 @@ static int ssu100_ioctl(struct tty_struct *tty,
442 435
443static int ssu100_attach(struct usb_serial *serial) 436static int ssu100_attach(struct usb_serial *serial)
444{ 437{
438 return ssu100_initdevice(serial->dev);
439}
440
441static int ssu100_port_probe(struct usb_serial_port *port)
442{
445 struct ssu100_port_private *priv; 443 struct ssu100_port_private *priv;
446 struct usb_serial_port *port = *serial->port;
447 444
448 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 445 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
449 if (!priv) { 446 if (!priv)
450 dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
451 sizeof(*priv));
452 return -ENOMEM; 447 return -ENOMEM;
453 }
454 448
455 spin_lock_init(&priv->status_lock); 449 spin_lock_init(&priv->status_lock);
456 init_waitqueue_head(&priv->delta_msr_wait); 450 init_waitqueue_head(&priv->delta_msr_wait);
451
457 usb_set_serial_port_data(port, priv); 452 usb_set_serial_port_data(port, priv);
458 453
459 return ssu100_initdevice(serial->dev); 454 return 0;
455}
456
457static int ssu100_port_remove(struct usb_serial_port *port)
458{
459 struct ssu100_port_private *priv;
460
461 priv = usb_get_serial_port_data(port);
462 kfree(priv);
463
464 return 0;
460} 465}
461 466
462static int ssu100_tiocmget(struct tty_struct *tty) 467static int ssu100_tiocmget(struct tty_struct *tty)
@@ -647,7 +652,8 @@ static struct usb_serial_driver ssu100_device = {
647 .open = ssu100_open, 652 .open = ssu100_open,
648 .close = ssu100_close, 653 .close = ssu100_close,
649 .attach = ssu100_attach, 654 .attach = ssu100_attach,
650 .release = ssu100_release, 655 .port_probe = ssu100_port_probe,
656 .port_remove = ssu100_port_remove,
651 .dtr_rts = ssu100_dtr_rts, 657 .dtr_rts = ssu100_dtr_rts,
652 .process_read_urb = ssu100_process_read_urb, 658 .process_read_urb = ssu100_process_read_urb,
653 .tiocmget = ssu100_tiocmget, 659 .tiocmget = ssu100_tiocmget,
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 6f49392cda5b..f2530d2ef3c4 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -97,6 +97,8 @@ struct ti_device {
97 97
98static int ti_startup(struct usb_serial *serial); 98static int ti_startup(struct usb_serial *serial);
99static void ti_release(struct usb_serial *serial); 99static void ti_release(struct usb_serial *serial);
100static int ti_port_probe(struct usb_serial_port *port);
101static int ti_port_remove(struct usb_serial_port *port);
100static int ti_open(struct tty_struct *tty, struct usb_serial_port *port); 102static int ti_open(struct tty_struct *tty, struct usb_serial_port *port);
101static void ti_close(struct usb_serial_port *port); 103static void ti_close(struct usb_serial_port *port);
102static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, 104static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -221,6 +223,8 @@ static struct usb_serial_driver ti_1port_device = {
221 .num_ports = 1, 223 .num_ports = 1,
222 .attach = ti_startup, 224 .attach = ti_startup,
223 .release = ti_release, 225 .release = ti_release,
226 .port_probe = ti_port_probe,
227 .port_remove = ti_port_remove,
224 .open = ti_open, 228 .open = ti_open,
225 .close = ti_close, 229 .close = ti_close,
226 .write = ti_write, 230 .write = ti_write,
@@ -249,6 +253,8 @@ static struct usb_serial_driver ti_2port_device = {
249 .num_ports = 2, 253 .num_ports = 2,
250 .attach = ti_startup, 254 .attach = ti_startup,
251 .release = ti_release, 255 .release = ti_release,
256 .port_probe = ti_port_probe,
257 .port_remove = ti_port_remove,
252 .open = ti_open, 258 .open = ti_open,
253 .close = ti_close, 259 .close = ti_close,
254 .write = ti_write, 260 .write = ti_write,
@@ -347,11 +353,8 @@ module_exit(ti_exit);
347static int ti_startup(struct usb_serial *serial) 353static int ti_startup(struct usb_serial *serial)
348{ 354{
349 struct ti_device *tdev; 355 struct ti_device *tdev;
350 struct ti_port *tport;
351 struct usb_device *dev = serial->dev; 356 struct usb_device *dev = serial->dev;
352 int status; 357 int status;
353 int i;
354
355 358
356 dev_dbg(&dev->dev, 359 dev_dbg(&dev->dev,
357 "%s - product 0x%4X, num configurations %d, configuration value %d", 360 "%s - product 0x%4X, num configurations %d, configuration value %d",
@@ -399,42 +402,8 @@ static int ti_startup(struct usb_serial *serial)
399 goto free_tdev; 402 goto free_tdev;
400 } 403 }
401 404
402 /* set up port structures */
403 for (i = 0; i < serial->num_ports; ++i) {
404 tport = kzalloc(sizeof(struct ti_port), GFP_KERNEL);
405 if (tport == NULL) {
406 dev_err(&dev->dev, "%s - out of memory\n", __func__);
407 status = -ENOMEM;
408 goto free_tports;
409 }
410 spin_lock_init(&tport->tp_lock);
411 tport->tp_uart_base_addr = (i == 0 ?
412 TI_UART1_BASE_ADDR : TI_UART2_BASE_ADDR);
413 tport->tp_closing_wait = closing_wait;
414 init_waitqueue_head(&tport->tp_msr_wait);
415 init_waitqueue_head(&tport->tp_write_wait);
416 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE,
417 GFP_KERNEL)) {
418 dev_err(&dev->dev, "%s - out of memory\n", __func__);
419 kfree(tport);
420 status = -ENOMEM;
421 goto free_tports;
422 }
423 tport->tp_port = serial->port[i];
424 tport->tp_tdev = tdev;
425 usb_set_serial_port_data(serial->port[i], tport);
426 tport->tp_uart_mode = 0; /* default is RS232 */
427 }
428
429 return 0; 405 return 0;
430 406
431free_tports:
432 for (--i; i >= 0; --i) {
433 tport = usb_get_serial_port_data(serial->port[i]);
434 kfifo_free(&tport->write_fifo);
435 kfree(tport);
436 usb_set_serial_port_data(serial->port[i], NULL);
437 }
438free_tdev: 407free_tdev:
439 kfree(tdev); 408 kfree(tdev);
440 usb_set_serial_data(serial, NULL); 409 usb_set_serial_data(serial, NULL);
@@ -444,21 +413,50 @@ free_tdev:
444 413
445static void ti_release(struct usb_serial *serial) 414static void ti_release(struct usb_serial *serial)
446{ 415{
447 int i;
448 struct ti_device *tdev = usb_get_serial_data(serial); 416 struct ti_device *tdev = usb_get_serial_data(serial);
417
418 kfree(tdev);
419}
420
421static int ti_port_probe(struct usb_serial_port *port)
422{
449 struct ti_port *tport; 423 struct ti_port *tport;
450 424
451 for (i = 0; i < serial->num_ports; ++i) { 425 tport = kzalloc(sizeof(*tport), GFP_KERNEL);
452 tport = usb_get_serial_port_data(serial->port[i]); 426 if (!tport)
453 if (tport) { 427 return -ENOMEM;
454 kfifo_free(&tport->write_fifo); 428
455 kfree(tport); 429 spin_lock_init(&tport->tp_lock);
456 } 430 if (port == port->serial->port[0])
431 tport->tp_uart_base_addr = TI_UART1_BASE_ADDR;
432 else
433 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR;
434 tport->tp_closing_wait = closing_wait;
435 init_waitqueue_head(&tport->tp_msr_wait);
436 init_waitqueue_head(&tport->tp_write_wait);
437 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) {
438 kfree(tport);
439 return -ENOMEM;
457 } 440 }
441 tport->tp_port = port;
442 tport->tp_tdev = usb_get_serial_data(port->serial);
443 tport->tp_uart_mode = 0; /* default is RS232 */
458 444
459 kfree(tdev); 445 usb_set_serial_port_data(port, tport);
446
447 return 0;
460} 448}
461 449
450static int ti_port_remove(struct usb_serial_port *port)
451{
452 struct ti_port *tport;
453
454 tport = usb_get_serial_port_data(port);
455 kfifo_free(&tport->write_fifo);
456 kfree(tport);
457
458 return 0;
459}
462 460
463static int ti_open(struct tty_struct *tty, struct usb_serial_port *port) 461static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
464{ 462{
diff --git a/drivers/video/backlight/lm3639_bl.c b/drivers/video/backlight/lm3639_bl.c
index c6915c6c3cd1..585949b57055 100644
--- a/drivers/video/backlight/lm3639_bl.c
+++ b/drivers/video/backlight/lm3639_bl.c
@@ -206,11 +206,11 @@ static ssize_t lm3639_bled_mode_store(struct device *dev,
206 206
207out: 207out:
208 dev_err(pchip->dev, "%s:i2c access fail to register\n", __func__); 208 dev_err(pchip->dev, "%s:i2c access fail to register\n", __func__);
209 return size; 209 return ret;
210 210
211out_input: 211out_input:
212 dev_err(pchip->dev, "%s:input conversion fail\n", __func__); 212 dev_err(pchip->dev, "%s:input conversion fail\n", __func__);
213 return size; 213 return ret;
214 214
215} 215}
216 216
diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
index 48220e129f85..f5dda83ad7a5 100644
--- a/drivers/xen/xenbus/xenbus_xs.c
+++ b/drivers/xen/xenbus/xenbus_xs.c
@@ -625,7 +625,7 @@ static struct xenbus_watch *find_watch(const char *token)
625 * so if we are running on anything older than 4 do not attempt to read 625 * so if we are running on anything older than 4 do not attempt to read
626 * control/platform-feature-xs_reset_watches. 626 * control/platform-feature-xs_reset_watches.
627 */ 627 */
628static bool xen_strict_xenbus_quirk() 628static bool xen_strict_xenbus_quirk(void)
629{ 629{
630 uint32_t eax, ebx, ecx, edx, base; 630 uint32_t eax, ebx, ecx, edx, base;
631 631