From 30004ac9c090dcdcca99556b4587b3bad828731a Mon Sep 17 00:00:00 2001 From: Dmitry Eremin-Solenikov Date: Mon, 9 Aug 2010 18:22:49 +0400 Subject: tty: add tty_struct->dev pointer to corresponding device instance Some device drivers (mostly tty line disciplines) would like to have way know a struct device instance corresponding to passed tty_struct. Add a struct device pointer to struct tty_struct and populate it during initialize_tty_struct(). Signed-off-by: Dmitry Eremin-Solenikov Acked-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/char/tty_io.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 613c852ee0fe..dc184d4b5638 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -183,6 +183,8 @@ struct tty_struct *alloc_tty_struct(void) void free_tty_struct(struct tty_struct *tty) { + if (tty->dev) + put_device(tty->dev); kfree(tty->write_buf); tty_buffer_free_all(tty); kfree(tty); @@ -2783,6 +2785,20 @@ void do_SAK(struct tty_struct *tty) EXPORT_SYMBOL(do_SAK); +static int dev_match_devt(struct device *dev, void *data) +{ + dev_t *devt = data; + return dev->devt == *devt; +} + +/* Must put_device() after it's unused! */ +static struct device *tty_get_device(struct tty_struct *tty) +{ + dev_t devt = tty_devnum(tty); + return class_find_device(tty_class, NULL, &devt, dev_match_devt); +} + + /** * initialize_tty_struct * @tty: tty to initialize @@ -2823,6 +2839,7 @@ void initialize_tty_struct(struct tty_struct *tty, tty->ops = driver->ops; tty->index = idx; tty_line_name(driver, idx, tty->name); + tty->dev = tty_get_device(tty); } /** -- cgit v1.2.3 From f573bd1764f0f3f47754ca1ae7b2eb2909798a60 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Tue, 24 Aug 2010 07:48:34 +0300 Subject: tty: Remove __GFP_NOFAIL from tty_add_file() This patch removes __GFP_NOFAIL use from tty_add_file() and adds proper error handling to the call-sites of the function. Cc: Andrew Morton Cc: Alan Cox Cc: Arnd Bergmann Signed-off-by: Pekka Enberg Acked-by: David Rientjes Signed-off-by: Greg Kroah-Hartman --- drivers/char/pty.c | 4 +++- drivers/char/tty_io.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pty.c b/drivers/char/pty.c index c350d01716bd..923a48585501 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c @@ -676,7 +676,9 @@ static int ptmx_open(struct inode *inode, struct file *filp) set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ - tty_add_file(tty, filp); + retval = tty_add_file(tty, filp); + if (retval) + goto out; retval = devpts_pty_new(inode, tty->link); if (retval) diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index dc184d4b5638..d6c659f2f659 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -196,12 +196,13 @@ static inline struct tty_struct *file_tty(struct file *file) } /* Associate a new file with the tty structure */ -void tty_add_file(struct tty_struct *tty, struct file *file) +int tty_add_file(struct tty_struct *tty, struct file *file) { struct tty_file_private *priv; - /* XXX: must implement proper error handling in callers */ - priv = kmalloc(sizeof(*priv), GFP_KERNEL|__GFP_NOFAIL); + priv = kmalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; priv->tty = tty; priv->file = file; @@ -210,6 +211,8 @@ void tty_add_file(struct tty_struct *tty, struct file *file) spin_lock(&tty_files_lock); list_add(&priv->list, &tty->tty_files); spin_unlock(&tty_files_lock); + + return 0; } /* Delete file from its tty */ @@ -1877,7 +1880,11 @@ got_driver: return PTR_ERR(tty); } - tty_add_file(tty, filp); + retval = tty_add_file(tty, filp); + if (retval) { + tty_unlock(); + return retval; + } check_tty_count(tty, "tty_open"); if (tty->driver->type == TTY_DRIVER_TYPE_PTY && -- cgit v1.2.3 From 24b4b67d17c308aaa956b73ab1e88190f6642bbe Mon Sep 17 00:00:00 2001 From: Samo Pogacnik Date: Wed, 25 Aug 2010 20:44:07 +0200 Subject: add ttyprintk driver Ttyprintk is a pseudo TTY driver, which allows users to make printk messages, via output to ttyprintk device. It is possible to store "console" messages inline with kernel messages for better analyses of the boot process, for example. Signed-off-by: Samo Pogacnik Acked-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/char/Kconfig | 15 ++++ drivers/char/Makefile | 1 + drivers/char/ttyprintk.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 drivers/char/ttyprintk.c (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 3d44ec724c17..43d3395325c5 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -493,6 +493,21 @@ config LEGACY_PTY_COUNT When not in use, each legacy PTY occupies 12 bytes on 32-bit architectures and 24 bytes on 64-bit architectures. +config TTY_PRINTK + bool "TTY driver to output user messages via printk" + depends on EMBEDDED + default n + ---help--- + If you say Y here, the support for writing user messages (i.e. + console messages) via printk is available. + + The feature is useful to inline user messages with kernel + messages. + In order to use this feature, you should output user messages + to /dev/ttyprintk or redirect console to this TTY. + + If unsure, say N. + config BRIQ_PANEL tristate 'Total Impact briQ front panel driver' depends on PPC_CHRP diff --git a/drivers/char/Makefile b/drivers/char/Makefile index dc9641660605..3a9c01416839 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -12,6 +12,7 @@ obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o t obj-y += tty_mutex.o obj-$(CONFIG_LEGACY_PTYS) += pty.o obj-$(CONFIG_UNIX98_PTYS) += pty.o +obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o obj-y += misc.o obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c new file mode 100644 index 000000000000..c40c1612c8a7 --- /dev/null +++ b/drivers/char/ttyprintk.c @@ -0,0 +1,225 @@ +/* + * linux/drivers/char/ttyprintk.c + * + * Copyright (C) 2010 Samo Pogacnik + * + * This program is free software; you can redistribute it and/or modify + * it under the smems of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + */ + +/* + * This pseudo device allows user to make printk messages. It is possible + * to store "console" messages inline with kernel messages for better analyses + * of the boot process, for example. + */ + +#include +#include +#include + +struct ttyprintk_port { + struct tty_port port; + struct mutex port_write_mutex; +}; + +static struct ttyprintk_port tpk_port; + +/* + * Our simple preformatting supports transparent output of (time-stamped) + * printk messages (also suitable for logging service): + * - any cr is replaced by nl + * - adds a ttyprintk source tag in front of each line + * - too long message is fragmeted, with '\'nl between fragments + * - TPK_STR_SIZE isn't really the write_room limiting factor, bcause + * it is emptied on the fly during preformatting. + */ +#define TPK_STR_SIZE 508 /* should be bigger then max expected line length */ +#define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */ +static const char *tpk_tag = "[U] "; /* U for User */ +static int tpk_curr; + +static int tpk_printk(const unsigned char *buf, int count) +{ + static char tmp[TPK_STR_SIZE + 4]; + int i = tpk_curr; + + if (buf == NULL) { + /* flush tmp[] */ + if (tpk_curr > 0) { + /* non nl or cr terminated message - add nl */ + tmp[tpk_curr + 0] = '\n'; + tmp[tpk_curr + 1] = '\0'; + printk(KERN_INFO "%s%s", tpk_tag, tmp); + tpk_curr = 0; + } + return i; + } + + for (i = 0; i < count; i++) { + tmp[tpk_curr] = buf[i]; + if (tpk_curr < TPK_STR_SIZE) { + switch (buf[i]) { + case '\r': + /* replace cr with nl */ + tmp[tpk_curr + 0] = '\n'; + tmp[tpk_curr + 1] = '\0'; + printk(KERN_INFO "%s%s", tpk_tag, tmp); + tpk_curr = 0; + if (buf[i + 1] == '\n') + i++; + break; + case '\n': + tmp[tpk_curr + 1] = '\0'; + printk(KERN_INFO "%s%s", tpk_tag, tmp); + tpk_curr = 0; + break; + default: + tpk_curr++; + } + } else { + /* end of tmp buffer reached: cut the message in two */ + tmp[tpk_curr + 1] = '\\'; + tmp[tpk_curr + 2] = '\n'; + tmp[tpk_curr + 3] = '\0'; + printk(KERN_INFO "%s%s", tpk_tag, tmp); + tpk_curr = 0; + } + } + + return count; +} + +/* + * TTY operations open function. + */ +static int tpk_open(struct tty_struct *tty, struct file *filp) +{ + tty->driver_data = &tpk_port; + + return tty_port_open(&tpk_port.port, tty, filp); +} + +/* + * TTY operations close function. + */ +static void tpk_close(struct tty_struct *tty, struct file *filp) +{ + struct ttyprintk_port *tpkp = tty->driver_data; + + mutex_lock(&tpkp->port_write_mutex); + /* flush tpk_printk buffer */ + tpk_printk(NULL, 0); + mutex_unlock(&tpkp->port_write_mutex); + + tty_port_close(&tpkp->port, tty, filp); +} + +/* + * TTY operations write function. + */ +static int tpk_write(struct tty_struct *tty, + const unsigned char *buf, int count) +{ + struct ttyprintk_port *tpkp = tty->driver_data; + int ret; + + + /* exclusive use of tpk_printk within this tty */ + mutex_lock(&tpkp->port_write_mutex); + ret = tpk_printk(buf, count); + mutex_unlock(&tpkp->port_write_mutex); + + return ret; +} + +/* + * TTY operations write_room function. + */ +static int tpk_write_room(struct tty_struct *tty) +{ + return TPK_MAX_ROOM; +} + +/* + * TTY operations ioctl function. + */ +static int tpk_ioctl(struct tty_struct *tty, struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct ttyprintk_port *tpkp = tty->driver_data; + + if (!tpkp) + return -EINVAL; + + switch (cmd) { + /* Stop TIOCCONS */ + case TIOCCONS: + return -EOPNOTSUPP; + default: + return -ENOIOCTLCMD; + } + return 0; +} + +static const struct tty_operations ttyprintk_ops = { + .open = tpk_open, + .close = tpk_close, + .write = tpk_write, + .write_room = tpk_write_room, + .ioctl = tpk_ioctl, +}; + +struct tty_port_operations null_ops = { }; + +static struct tty_driver *ttyprintk_driver; + +static int __init ttyprintk_init(void) +{ + int ret = -ENOMEM; + void *rp; + + ttyprintk_driver = alloc_tty_driver(1); + if (!ttyprintk_driver) + return ret; + + ttyprintk_driver->owner = THIS_MODULE; + ttyprintk_driver->driver_name = "ttyprintk"; + ttyprintk_driver->name = "ttyprintk"; + ttyprintk_driver->major = TTYAUX_MAJOR; + ttyprintk_driver->minor_start = 3; + ttyprintk_driver->num = 1; + ttyprintk_driver->type = TTY_DRIVER_TYPE_CONSOLE; + ttyprintk_driver->init_termios = tty_std_termios; + ttyprintk_driver->init_termios.c_oflag = OPOST | OCRNL | ONOCR | ONLRET; + ttyprintk_driver->flags = TTY_DRIVER_RESET_TERMIOS | + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; + tty_set_operations(ttyprintk_driver, &ttyprintk_ops); + + ret = tty_register_driver(ttyprintk_driver); + if (ret < 0) { + printk(KERN_ERR "Couldn't register ttyprintk driver\n"); + goto error; + } + + /* create our unnumbered device */ + rp = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 3), NULL, + ttyprintk_driver->name); + if (IS_ERR(rp)) { + printk(KERN_ERR "Couldn't create ttyprintk device\n"); + ret = PTR_ERR(rp); + goto error; + } + + tty_port_init(&tpk_port.port); + tpk_port.port.ops = &null_ops; + mutex_init(&tpk_port.port_write_mutex); + + return 0; + +error: + put_tty_driver(ttyprintk_driver); + ttyprintk_driver = NULL; + return ret; +} +module_init(ttyprintk_init); -- cgit v1.2.3 From df480518a688f0d28f7e7de69abe6a441d1c2c64 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Fri, 3 Sep 2010 10:31:37 +0200 Subject: Char: mxser, call pci_disable_device from probe/remove Vasiliy found that pci_disable_device is not called on fail paths in mxser_probe. Actually, it is called from nowhere in the driver. There are three changes needed: 1) don't use pseudo-generic mxser_release_res. Let's use it only from ISA paths from now on. All the pci stuff is moved to probe and remove PCI-related functions. 2) reorder fail-paths in the probe function so that it makes sense and we can call them from the sequential code naturally (the further we are the earlier label we go to). 3) add pci_disable_device both to mxser_probe and mxser_remove. There is a nit of adding CONFIG_PCI ifdef to mxser_remove. it is because this driver supports ISA-only compilations and it would choke up on the newly added calls now. Signed-off-by: Jiri Slaby Cc: Kulikov Vasiliy Signed-off-by: Greg Kroah-Hartman --- drivers/char/mxser.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index 3fc89da856ae..9d243de795df 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -2339,20 +2339,11 @@ struct tty_port_operations mxser_port_ops = { * The MOXA Smartio/Industio serial driver boot-time initialization code! */ -static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev, - unsigned int irq) +static void mxser_release_ISA_res(struct mxser_board *brd) { - if (irq) - free_irq(brd->irq, brd); - if (pdev != NULL) { /* PCI */ -#ifdef CONFIG_PCI - pci_release_region(pdev, 2); - pci_release_region(pdev, 3); -#endif - } else { - release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); - release_region(brd->vector, 1); - } + free_irq(brd->irq, brd); + release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); + release_region(brd->vector, 1); } static int __devinit mxser_initbrd(struct mxser_board *brd, @@ -2397,13 +2388,11 @@ static int __devinit mxser_initbrd(struct mxser_board *brd, retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser", brd); - if (retval) { + if (retval) printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may " "conflict with another device.\n", brd->info->name, brd->irq); - /* We hold resources, we need to release them. */ - mxser_release_res(brd, pdev, 0); - } + return retval; } @@ -2555,7 +2544,7 @@ static int __devinit mxser_probe(struct pci_dev *pdev, ioaddress = pci_resource_start(pdev, 2); retval = pci_request_region(pdev, 2, "mxser(IO)"); if (retval) - goto err; + goto err_dis; brd->info = &mxser_cards[ent->driver_data]; for (i = 0; i < brd->info->nports; i++) @@ -2565,7 +2554,7 @@ static int __devinit mxser_probe(struct pci_dev *pdev, ioaddress = pci_resource_start(pdev, 3); retval = pci_request_region(pdev, 3, "mxser(vector)"); if (retval) - goto err_relio; + goto err_zero; brd->vector = ioaddress; /* irq */ @@ -2608,7 +2597,7 @@ static int __devinit mxser_probe(struct pci_dev *pdev, /* mxser_initbrd will hook ISR. */ retval = mxser_initbrd(brd, pdev); if (retval) - goto err_null; + goto err_rel3; for (i = 0; i < brd->info->nports; i++) tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev); @@ -2616,10 +2605,13 @@ static int __devinit mxser_probe(struct pci_dev *pdev, pci_set_drvdata(pdev, brd); return 0; -err_relio: - pci_release_region(pdev, 2); -err_null: +err_rel3: + pci_release_region(pdev, 3); +err_zero: brd->info = NULL; + pci_release_region(pdev, 2); +err_dis: + pci_disable_device(pdev); err: return retval; #else @@ -2629,14 +2621,19 @@ err: static void __devexit mxser_remove(struct pci_dev *pdev) { +#ifdef CONFIG_PCI struct mxser_board *brd = pci_get_drvdata(pdev); unsigned int i; for (i = 0; i < brd->info->nports; i++) tty_unregister_device(mxvar_sdriver, brd->idx + i); - mxser_release_res(brd, pdev, 1); + free_irq(pdev->irq, brd); + pci_release_region(pdev, 2); + pci_release_region(pdev, 3); + pci_disable_device(pdev); brd->info = NULL; +#endif } static struct pci_driver mxser_driver = { @@ -2741,7 +2738,7 @@ static void __exit mxser_module_exit(void) for (i = 0; i < MXSER_BOARDS; i++) if (mxser_boards[i].info != NULL) - mxser_release_res(&mxser_boards[i], NULL, 1); + mxser_release_ISA_res(&mxser_boards[i]); } module_init(mxser_module_init); -- cgit v1.2.3 From b670bde0b2497966d76154cfb9706c38cf8348f9 Mon Sep 17 00:00:00 2001 From: Vasiliy Kulikov Date: Sun, 5 Sep 2010 22:32:22 +0400 Subject: tty_io: check return code of tty_register_device Function tty_register_device may return ERR_PTR(...). Check for it. Signed-off-by: Vasiliy Kulikov Signed-off-by: Greg Kroah-Hartman --- drivers/char/tty_io.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index d6c659f2f659..e185db36f8ad 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -3004,6 +3004,7 @@ int tty_register_driver(struct tty_driver *driver) int i; dev_t dev; void **p = NULL; + struct device *d; if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) { p = kzalloc(driver->num * 2 * sizeof(void *), GFP_KERNEL); @@ -3051,12 +3052,31 @@ int tty_register_driver(struct tty_driver *driver) mutex_unlock(&tty_mutex); if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) { - for (i = 0; i < driver->num; i++) - tty_register_device(driver, i, NULL); + for (i = 0; i < driver->num; i++) { + d = tty_register_device(driver, i, NULL); + if (IS_ERR(d)) { + error = PTR_ERR(d); + goto err; + } + } } proc_tty_register_driver(driver); driver->flags |= TTY_DRIVER_INSTALLED; return 0; + +err: + for (i--; i >= 0; i--) + tty_unregister_device(driver, i); + + mutex_lock(&tty_mutex); + list_del(&driver->tty_drivers); + mutex_unlock(&tty_mutex); + + unregister_chrdev_region(dev, driver->num); + driver->ttys = NULL; + driver->termios = NULL; + kfree(p); + return error; } EXPORT_SYMBOL(tty_register_driver); -- cgit v1.2.3 From d281da7ff6f70efca0553c288bb883e8605b3862 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 16 Sep 2010 18:21:24 +0100 Subject: tty: Make tiocgicount a handler Dan Rosenberg noted that various drivers return the struct with uncleared fields. Instead of spending forever trying to stomp all the drivers that get it wrong (and every new driver) do the job in one place. This first patch adds the needed operations and hooks them up, including the needed USB midlayer and serial core plumbing. Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/char/tty_io.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index e185db36f8ad..c05c5af5aa04 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c @@ -96,6 +96,7 @@ #include #include #include +#include #include #include @@ -2511,6 +2512,20 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int return tty->ops->tiocmset(tty, file, set, clear); } +static int tty_tiocgicount(struct tty_struct *tty, void __user *arg) +{ + int retval = -EINVAL; + struct serial_icounter_struct icount; + memset(&icount, 0, sizeof(icount)); + if (tty->ops->get_icount) + retval = tty->ops->get_icount(tty, &icount); + if (retval != 0) + return retval; + if (copy_to_user(arg, &icount, sizeof(icount))) + return -EFAULT; + return 0; +} + struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) { if (tty->driver->type == TTY_DRIVER_TYPE_PTY && @@ -2631,6 +2646,12 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case TIOCMBIC: case TIOCMBIS: return tty_tiocmset(tty, file, cmd, p); + case TIOCGICOUNT: + retval = tty_tiocgicount(tty, p); + /* For the moment allow fall through to the old method */ + if (retval != -EINVAL) + return retval; + break; case TCFLSH: switch (arg) { case TCIFLUSH: -- cgit v1.2.3 From 0587102cf9f427c185bfdeb2cef41e13ee0264b1 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 16 Sep 2010 18:21:52 +0100 Subject: tty: icount changeover for other main devices Again basically cut and paste Convert the main driver set to use the hooks for GICOUNT Signed-off-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/char/amiserial.c | 56 ++++++++++++++++-------------- drivers/char/cyclades.c | 49 ++++++++++++++------------ drivers/char/ip2/ip2main.c | 72 ++++++++++++++++++++++---------------- drivers/char/mxser.c | 62 ++++++++++++++++++--------------- drivers/char/nozomi.c | 37 ++++++++++---------- drivers/char/pcmcia/synclink_cs.c | 60 +++++++++++++++----------------- drivers/char/synclink.c | 73 ++++++++++++++++++--------------------- drivers/char/synclink_gt.c | 55 +++++++++++++++-------------- drivers/char/synclinkmp.c | 61 +++++++++++++++----------------- 9 files changed, 271 insertions(+), 254 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c index a11c8c9ca3d4..b0a70461a12c 100644 --- a/drivers/char/amiserial.c +++ b/drivers/char/amiserial.c @@ -1263,6 +1263,36 @@ static int rs_break(struct tty_struct *tty, int break_state) return 0; } +/* + * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) + * Return: write counters to the user passed counter struct + * NB: both 1->0 and 0->1 transitions are counted except for + * RI where only 0->1 is counted. + */ +static int rs_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) +{ + struct async_struct *info = tty->driver_data; + struct async_icount cnow; + unsigned long flags; + + local_irq_save(flags); + cnow = info->state->icount; + local_irq_restore(flags); + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + + return 0; +} static int rs_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) @@ -1332,31 +1362,6 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file, } /* NOTREACHED */ - /* - * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) - * Return: write counters to the user passed counter struct - * NB: both 1->0 and 0->1 transitions are counted except for - * RI where only 0->1 is counted. - */ - case TIOCGICOUNT: - local_irq_save(flags); - cnow = info->state->icount; - local_irq_restore(flags); - icount.cts = cnow.cts; - icount.dsr = cnow.dsr; - icount.rng = cnow.rng; - icount.dcd = cnow.dcd; - icount.rx = cnow.rx; - icount.tx = cnow.tx; - icount.frame = cnow.frame; - icount.overrun = cnow.overrun; - icount.parity = cnow.parity; - icount.brk = cnow.brk; - icount.buf_overrun = cnow.buf_overrun; - - if (copy_to_user(argp, &icount, sizeof(icount))) - return -EFAULT; - return 0; case TIOCSERGWILD: case TIOCSERSWILD: /* "setserial -W" is called in Debian boot */ @@ -1958,6 +1963,7 @@ static const struct tty_operations serial_ops = { .wait_until_sent = rs_wait_until_sent, .tiocmget = rs_tiocmget, .tiocmset = rs_tiocmset, + .get_icount = rs_get_icount, .proc_fops = &rs_proc_fops, }; diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c index 27aad9422332..4f152c28f40e 100644 --- a/drivers/char/cyclades.c +++ b/drivers/char/cyclades.c @@ -2790,29 +2790,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file, * NB: both 1->0 and 0->1 transitions are counted except for * RI where only 0->1 is counted. */ - case TIOCGICOUNT: { - struct serial_icounter_struct sic = { }; - - spin_lock_irqsave(&info->card->card_lock, flags); - cnow = info->icount; - spin_unlock_irqrestore(&info->card->card_lock, flags); - - sic.cts = cnow.cts; - sic.dsr = cnow.dsr; - sic.rng = cnow.rng; - sic.dcd = cnow.dcd; - sic.rx = cnow.rx; - sic.tx = cnow.tx; - sic.frame = cnow.frame; - sic.overrun = cnow.overrun; - sic.parity = cnow.parity; - sic.brk = cnow.brk; - sic.buf_overrun = cnow.buf_overrun; - - if (copy_to_user(argp, &sic, sizeof(sic))) - ret_val = -EFAULT; - break; - } default: ret_val = -ENOIOCTLCMD; } @@ -2823,6 +2800,31 @@ cy_ioctl(struct tty_struct *tty, struct file *file, return ret_val; } /* cy_ioctl */ +static int cy_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *sic) +{ + struct cyclades_port *info = tty->driver_data; + struct cyclades_icount cnow; /* Used to snapshot */ + unsigned long flags; + + spin_lock_irqsave(&info->card->card_lock, flags); + cnow = info->icount; + spin_unlock_irqrestore(&info->card->card_lock, flags); + + sic->cts = cnow.cts; + sic->dsr = cnow.dsr; + sic->rng = cnow.rng; + sic->dcd = cnow.dcd; + sic->rx = cnow.rx; + sic->tx = cnow.tx; + sic->frame = cnow.frame; + sic->overrun = cnow.overrun; + sic->parity = cnow.parity; + sic->brk = cnow.brk; + sic->buf_overrun = cnow.buf_overrun; + return 0; +} + /* * This routine allows the tty driver to be notified when * device's termios settings have changed. Note that a @@ -4084,6 +4086,7 @@ static const struct tty_operations cy_ops = { .wait_until_sent = cy_wait_until_sent, .tiocmget = cy_tiocmget, .tiocmset = cy_tiocmset, + .get_icount = cy_get_icount, .proc_fops = &cyclades_proc_fops, }; diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c index d4b71e8d0d23..438272ca9e08 100644 --- a/drivers/char/ip2/ip2main.c +++ b/drivers/char/ip2/ip2main.c @@ -183,6 +183,8 @@ static void ip2_hangup(PTTY); static int ip2_tiocmget(struct tty_struct *tty, struct file *file); static int ip2_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear); +static int ip2_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount); static void set_irq(int, int); static void ip2_interrupt_bh(struct work_struct *work); @@ -454,6 +456,7 @@ static const struct tty_operations ip2_ops = { .hangup = ip2_hangup, .tiocmget = ip2_tiocmget, .tiocmset = ip2_tiocmset, + .get_icount = ip2_get_icount, .proc_fops = &ip2_proc_fops, }; @@ -2128,7 +2131,6 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg ) i2ChanStrPtr pCh = DevTable[tty->index]; i2eBordStrPtr pB; struct async_icount cprev, cnow; /* kernel counter temps */ - struct serial_icounter_struct __user *p_cuser; int rc = 0; unsigned long flags; void __user *argp = (void __user *)arg; @@ -2296,34 +2298,6 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg ) return rc; break; - /* - * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) - * Return: write counters to the user passed counter struct - * NB: both 1->0 and 0->1 transitions are counted except for RI where - * only 0->1 is counted. The controller is quite capable of counting - * both, but this done to preserve compatibility with the standard - * serial driver. - */ - case TIOCGICOUNT: - ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc ); - - write_lock_irqsave(&pB->read_fifo_spinlock, flags); - cnow = pCh->icount; - write_unlock_irqrestore(&pB->read_fifo_spinlock, flags); - p_cuser = argp; - rc = put_user(cnow.cts, &p_cuser->cts); - rc = put_user(cnow.dsr, &p_cuser->dsr); - rc = put_user(cnow.rng, &p_cuser->rng); - rc = put_user(cnow.dcd, &p_cuser->dcd); - rc = put_user(cnow.rx, &p_cuser->rx); - rc = put_user(cnow.tx, &p_cuser->tx); - rc = put_user(cnow.frame, &p_cuser->frame); - rc = put_user(cnow.overrun, &p_cuser->overrun); - rc = put_user(cnow.parity, &p_cuser->parity); - rc = put_user(cnow.brk, &p_cuser->brk); - rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun); - break; - /* * The rest are not supported by this driver. By returning -ENOIOCTLCMD they * will be passed to the line discipline for it to handle. @@ -2348,6 +2322,46 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg ) return rc; } +static int ip2_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) +{ + i2ChanStrPtr pCh = DevTable[tty->index]; + i2eBordStrPtr pB; + struct async_icount cnow; /* kernel counter temp */ + unsigned long flags; + + if ( pCh == NULL ) + return -ENODEV; + + pB = pCh->pMyBord; + + /* + * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) + * Return: write counters to the user passed counter struct + * NB: both 1->0 and 0->1 transitions are counted except for RI where + * only 0->1 is counted. The controller is quite capable of counting + * both, but this done to preserve compatibility with the standard + * serial driver. + */ + + write_lock_irqsave(&pB->read_fifo_spinlock, flags); + cnow = pCh->icount; + write_unlock_irqrestore(&pB->read_fifo_spinlock, flags); + + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + return 0; +} + /******************************************************************************/ /* Function: GetSerialInfo() */ /* Parameters: Pointer to channel structure */ diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index 9d243de795df..463df27494bd 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c @@ -1700,7 +1700,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file, return 0; } - if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT && + if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && test_bit(TTY_IO_ERROR, &tty->flags)) return -EIO; @@ -1730,32 +1730,6 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file, return wait_event_interruptible(info->port.delta_msr_wait, mxser_cflags_changed(info, arg, &cnow)); - /* - * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) - * Return: write counters to the user passed counter struct - * NB: both 1->0 and 0->1 transitions are counted except for - * RI where only 0->1 is counted. - */ - case TIOCGICOUNT: { - struct serial_icounter_struct icnt = { 0 }; - spin_lock_irqsave(&info->slock, flags); - cnow = info->icount; - spin_unlock_irqrestore(&info->slock, flags); - - icnt.frame = cnow.frame; - icnt.brk = cnow.brk; - icnt.overrun = cnow.overrun; - icnt.buf_overrun = cnow.buf_overrun; - icnt.parity = cnow.parity; - icnt.rx = cnow.rx; - icnt.tx = cnow.tx; - icnt.cts = cnow.cts; - icnt.dsr = cnow.dsr; - icnt.rng = cnow.rng; - icnt.dcd = cnow.dcd; - - return copy_to_user(argp, &icnt, sizeof(icnt)) ? -EFAULT : 0; - } case MOXA_HighSpeedOn: return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp); case MOXA_SDS_RSTICOUNTER: @@ -1828,6 +1802,39 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file, return 0; } + /* + * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) + * Return: write counters to the user passed counter struct + * NB: both 1->0 and 0->1 transitions are counted except for + * RI where only 0->1 is counted. + */ + +static int mxser_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) + +{ + struct mxser_port *info = tty->driver_data; + struct async_icount cnow; + unsigned long flags; + + spin_lock_irqsave(&info->slock, flags); + cnow = info->icount; + spin_unlock_irqrestore(&info->slock, flags); + + icount->frame = cnow.frame; + icount->brk = cnow.brk; + icount->overrun = cnow.overrun; + icount->buf_overrun = cnow.buf_overrun; + icount->parity = cnow.parity; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + return 0; +} + static void mxser_stoprx(struct tty_struct *tty) { struct mxser_port *info = tty->driver_data; @@ -2326,6 +2333,7 @@ static const struct tty_operations mxser_ops = { .wait_until_sent = mxser_wait_until_sent, .tiocmget = mxser_tiocmget, .tiocmset = mxser_tiocmset, + .get_icount = mxser_get_icount, }; struct tty_port_operations mxser_port_ops = { diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c index 817169cbb245..dd3f9b1f11b4 100644 --- a/drivers/char/nozomi.c +++ b/drivers/char/nozomi.c @@ -1804,24 +1804,24 @@ static int ntty_cflags_changed(struct port *port, unsigned long flags, return ret; } -static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp) +static int ntty_tiocgicount(struct tty_struct *tty, + struct serial_icounter_struct *icount) { + struct port *port = tty->driver_data; const struct async_icount cnow = port->tty_icount; - struct serial_icounter_struct icount; - - icount.cts = cnow.cts; - icount.dsr = cnow.dsr; - icount.rng = cnow.rng; - icount.dcd = cnow.dcd; - icount.rx = cnow.rx; - icount.tx = cnow.tx; - icount.frame = cnow.frame; - icount.overrun = cnow.overrun; - icount.parity = cnow.parity; - icount.brk = cnow.brk; - icount.buf_overrun = cnow.buf_overrun; - - return copy_to_user(argp, &icount, sizeof(icount)) ? -EFAULT : 0; + + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + return 0; } static int ntty_ioctl(struct tty_struct *tty, struct file *file, @@ -1840,9 +1840,7 @@ static int ntty_ioctl(struct tty_struct *tty, struct file *file, rval = wait_event_interruptible(port->tty_wait, ntty_cflags_changed(port, arg, &cprev)); break; - } case TIOCGICOUNT: - rval = ntty_ioctl_tiocgicount(port, argp); - break; + } default: DBG1("ERR: 0x%08X, %d", cmd, cmd); break; @@ -1922,6 +1920,7 @@ static const struct tty_operations tty_ops = { .chars_in_buffer = ntty_chars_in_buffer, .tiocmget = ntty_tiocmget, .tiocmset = ntty_tiocmset, + .get_icount = ntty_tiocgicount, .install = ntty_install, .cleanup = ntty_cleanup, }; diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 9ecd6bef5d3b..8e7c78131e32 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -2215,6 +2215,32 @@ static int mgslpc_break(struct tty_struct *tty, int break_state) return 0; } +static int mgslpc_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) +{ + MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; + struct mgsl_icount cnow; /* kernel counter temps */ + unsigned long flags; + + spin_lock_irqsave(&info->lock,flags); + cnow = info->icount; + spin_unlock_irqrestore(&info->lock,flags); + + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + + return 0; +} + /* Service an IOCTL request * * Arguments: @@ -2230,11 +2256,7 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; - int error; - struct mgsl_icount cnow; /* kernel counter temps */ - struct serial_icounter_struct __user *p_cuser; /* user space */ void __user *argp = (void __user *)arg; - unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__, @@ -2244,7 +2266,7 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file, return -ENODEV; if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && - (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { + (cmd != TIOCMIWAIT)) { if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; } @@ -2274,34 +2296,6 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file, return wait_events(info, argp); case TIOCMIWAIT: return modem_input_wait(info,(int)arg); - case TIOCGICOUNT: - spin_lock_irqsave(&info->lock,flags); - cnow = info->icount; - spin_unlock_irqrestore(&info->lock,flags); - p_cuser = argp; - PUT_USER(error,cnow.cts, &p_cuser->cts); - if (error) return error; - PUT_USER(error,cnow.dsr, &p_cuser->dsr); - if (error) return error; - PUT_USER(error,cnow.rng, &p_cuser->rng); - if (error) return error; - PUT_USER(error,cnow.dcd, &p_cuser->dcd); - if (error) return error; - PUT_USER(error,cnow.rx, &p_cuser->rx); - if (error) return error; - PUT_USER(error,cnow.tx, &p_cuser->tx); - if (error) return error; - PUT_USER(error,cnow.frame, &p_cuser->frame); - if (error) return error; - PUT_USER(error,cnow.overrun, &p_cuser->overrun); - if (error) return error; - PUT_USER(error,cnow.parity, &p_cuser->parity); - if (error) return error; - PUT_USER(error,cnow.brk, &p_cuser->brk); - if (error) return error; - PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun); - if (error) return error; - return 0; default: return -ENOIOCTLCMD; } diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index a2a58004e188..3a6824f12be2 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c @@ -2925,6 +2925,38 @@ static int mgsl_break(struct tty_struct *tty, int break_state) } /* end of mgsl_break() */ +/* + * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) + * Return: write counters to the user passed counter struct + * NB: both 1->0 and 0->1 transitions are counted except for + * RI where only 0->1 is counted. + */ +static int msgl_get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) + +{ + struct mgsl_struct * info = tty->driver_data; + struct mgsl_icount cnow; /* kernel counter temps */ + unsigned long flags; + + spin_lock_irqsave(&info->irq_spinlock,flags); + cnow = info->icount; + spin_unlock_irqrestore(&info->irq_spinlock,flags); + + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + return 0; +} + /* mgsl_ioctl() Service an IOCTL request * * Arguments: @@ -2949,7 +2981,7 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file, return -ENODEV; if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && - (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { + (cmd != TIOCMIWAIT)) { if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; } @@ -2959,11 +2991,7 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file, static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg) { - int error; - struct mgsl_icount cnow; /* kernel counter temps */ void __user *argp = (void __user *)arg; - struct serial_icounter_struct __user *p_cuser; /* user space */ - unsigned long flags; switch (cmd) { case MGSL_IOCGPARAMS: @@ -2992,40 +3020,6 @@ static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigne case TIOCMIWAIT: return modem_input_wait(info,(int)arg); - /* - * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) - * Return: write counters to the user passed counter struct - * NB: both 1->0 and 0->1 transitions are counted except for - * RI where only 0->1 is counted. - */ - case TIOCGICOUNT: - spin_lock_irqsave(&info->irq_spinlock,flags); - cnow = info->icount; - spin_unlock_irqrestore(&info->irq_spinlock,flags); - p_cuser = argp; - PUT_USER(error,cnow.cts, &p_cuser->cts); - if (error) return error; - PUT_USER(error,cnow.dsr, &p_cuser->dsr); - if (error) return error; - PUT_USER(error,cnow.rng, &p_cuser->rng); - if (error) return error; - PUT_USER(error,cnow.dcd, &p_cuser->dcd); - if (error) return error; - PUT_USER(error,cnow.rx, &p_cuser->rx); - if (error) return error; - PUT_USER(error,cnow.tx, &p_cuser->tx); - if (error) return error; - PUT_USER(error,cnow.frame, &p_cuser->frame); - if (error) return error; - PUT_USER(error,cnow.overrun, &p_cuser->overrun); - if (error) return error; - PUT_USER(error,cnow.parity, &p_cuser->parity); - if (error) return error; - PUT_USER(error,cnow.brk, &p_cuser->brk); - if (error) return error; - PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun); - if (error) return error; - return 0; default: return -ENOIOCTLCMD; } @@ -4328,6 +4322,7 @@ static const struct tty_operations mgsl_ops = { .hangup = mgsl_hangup, .tiocmget = tiocmget, .tiocmset = tiocmset, + .get_icount = msgl_get_icount, .proc_fops = &mgsl_proc_fops, }; diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index e63b830c86cc..1746d91205f7 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c @@ -1032,9 +1032,6 @@ static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct slgt_info *info = tty->driver_data; - struct mgsl_icount cnow; /* kernel counter temps */ - struct serial_icounter_struct __user *p_cuser; /* user space */ - unsigned long flags; void __user *argp = (void __user *)arg; int ret; @@ -1043,7 +1040,7 @@ static int ioctl(struct tty_struct *tty, struct file *file, DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && - (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { + (cmd != TIOCMIWAIT)) { if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; } @@ -1053,24 +1050,6 @@ static int ioctl(struct tty_struct *tty, struct file *file, return wait_mgsl_event(info, argp); case TIOCMIWAIT: return modem_input_wait(info,(int)arg); - case TIOCGICOUNT: - spin_lock_irqsave(&info->lock,flags); - cnow = info->icount; - spin_unlock_irqrestore(&info->lock,flags); - p_cuser = argp; - if (put_user(cnow.cts, &p_cuser->cts) || - put_user(cnow.dsr, &p_cuser->dsr) || - put_user(cnow.rng, &p_cuser->rng) || - put_user(cnow.dcd, &p_cuser->dcd) || - put_user(cnow.rx, &p_cuser->rx) || - put_user(cnow.tx, &p_cuser->tx) || - put_user(cnow.frame, &p_cuser->frame) || - put_user(cnow.overrun, &p_cuser->overrun) || - put_user(cnow.parity, &p_cuser->parity) || - put_user(cnow.brk, &p_cuser->brk) || - put_user(cnow.buf_overrun, &p_cuser->buf_overrun)) - return -EFAULT; - return 0; case MGSL_IOCSGPIO: return set_gpio(info, argp); case MGSL_IOCGGPIO: @@ -1117,6 +1096,33 @@ static int ioctl(struct tty_struct *tty, struct file *file, return ret; } +static int get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) + +{ + struct slgt_info *info = tty->driver_data; + struct mgsl_icount cnow; /* kernel counter temps */ + unsigned long flags; + + spin_lock_irqsave(&info->lock,flags); + cnow = info->icount; + spin_unlock_irqrestore(&info->lock,flags); + + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + + return 0; +} + /* * support for 32 bit ioctl calls on 64 bit systems */ @@ -1206,10 +1212,6 @@ static long slgt_compat_ioctl(struct tty_struct *tty, struct file *file, case MGSL_IOCSGPIO: case MGSL_IOCGGPIO: case MGSL_IOCWAITGPIO: - case TIOCGICOUNT: - rc = ioctl(tty, file, cmd, (unsigned long)(compat_ptr(arg))); - break; - case MGSL_IOCSTXIDLE: case MGSL_IOCTXENABLE: case MGSL_IOCRXENABLE: @@ -3642,6 +3644,7 @@ static const struct tty_operations ops = { .hangup = hangup, .tiocmget = tiocmget, .tiocmset = tiocmset, + .get_icount = get_icount, .proc_fops = &synclink_gt_proc_fops, }; diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c index e56caf7d82aa..2f9eb4b0dec1 100644 --- a/drivers/char/synclinkmp.c +++ b/drivers/char/synclinkmp.c @@ -1258,10 +1258,6 @@ static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { SLMP_INFO *info = tty->driver_data; - int error; - struct mgsl_icount cnow; /* kernel counter temps */ - struct serial_icounter_struct __user *p_cuser; /* user space */ - unsigned long flags; void __user *argp = (void __user *)arg; if (debug_level >= DEBUG_LEVEL_INFO) @@ -1272,7 +1268,7 @@ static int ioctl(struct tty_struct *tty, struct file *file, return -ENODEV; if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && - (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { + (cmd != TIOCMIWAIT)) { if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; } @@ -1310,40 +1306,38 @@ static int ioctl(struct tty_struct *tty, struct file *file, * NB: both 1->0 and 0->1 transitions are counted except for * RI where only 0->1 is counted. */ - case TIOCGICOUNT: - spin_lock_irqsave(&info->lock,flags); - cnow = info->icount; - spin_unlock_irqrestore(&info->lock,flags); - p_cuser = argp; - PUT_USER(error,cnow.cts, &p_cuser->cts); - if (error) return error; - PUT_USER(error,cnow.dsr, &p_cuser->dsr); - if (error) return error; - PUT_USER(error,cnow.rng, &p_cuser->rng); - if (error) return error; - PUT_USER(error,cnow.dcd, &p_cuser->dcd); - if (error) return error; - PUT_USER(error,cnow.rx, &p_cuser->rx); - if (error) return error; - PUT_USER(error,cnow.tx, &p_cuser->tx); - if (error) return error; - PUT_USER(error,cnow.frame, &p_cuser->frame); - if (error) return error; - PUT_USER(error,cnow.overrun, &p_cuser->overrun); - if (error) return error; - PUT_USER(error,cnow.parity, &p_cuser->parity); - if (error) return error; - PUT_USER(error,cnow.brk, &p_cuser->brk); - if (error) return error; - PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun); - if (error) return error; - return 0; default: return -ENOIOCTLCMD; } return 0; } +static int get_icount(struct tty_struct *tty, + struct serial_icounter_struct *icount) +{ + SLMP_INFO *info = tty->driver_data; + struct mgsl_icount cnow; /* kernel counter temps */ + unsigned long flags; + + spin_lock_irqsave(&info->lock,flags); + cnow = info->icount; + spin_unlock_irqrestore(&info->lock,flags); + + icount->cts = cnow.cts; + icount->dsr = cnow.dsr; + icount->rng = cnow.rng; + icount->dcd = cnow.dcd; + icount->rx = cnow.rx; + icount->tx = cnow.tx; + icount->frame = cnow.frame; + icount->overrun = cnow.overrun; + icount->parity = cnow.parity; + icount->brk = cnow.brk; + icount->buf_overrun = cnow.buf_overrun; + + return 0; +} + /* * /proc fs routines.... */ @@ -3909,6 +3903,7 @@ static const struct tty_operations ops = { .hangup = hangup, .tiocmget = tiocmget, .tiocmset = tiocmset, + .get_icount = get_icount, .proc_fops = &synclinkmp_proc_fops, }; -- cgit v1.2.3 From 47725ac76f51328d467b1430dfd027aba8706a11 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 5 Oct 2010 14:22:37 -0400 Subject: vcs: add poll/fasync support The /dev/vcs* devices are used, amongst other things, by accessibility applications such as BRLTTY to display the screen content onto refreshable braille displays. Currently this is performed by constantly reading from /dev/vcsa0 whether or not the screen content has changed. Given the default braille refresh rate of 25 times per second, this easily qualifies as the biggest source of wake-up events preventing laptops from entering deeper power saving states. To avoid this periodic polling, let's add support for select()/poll() and SIGIO with the /dev/vcs* devices. The implemented semantic is to report data availability whenever the corresponding vt has seen some update after the last read() operation. The application still has to lseek() back as usual in order to read() the new data. Not to create unwanted overhead, the needed data structure is allocated and the vt notification callback is registered only when the poll or fasync method is invoked for the first time per file instance. Signed-off-by: Nicolas Pitre Cc: Andrew Morton Acked-by: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/char/vc_screen.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c index bcce46c96b88..6f7054e1a516 100644 --- a/drivers/char/vc_screen.c +++ b/drivers/char/vc_screen.c @@ -35,6 +35,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include @@ -45,6 +51,86 @@ #undef addr #define HEADER_SIZE 4 +struct vcs_poll_data { + struct notifier_block notifier; + unsigned int cons_num; + bool seen_last_update; + wait_queue_head_t waitq; + struct fasync_struct *fasync; +}; + +static int +vcs_notifier(struct notifier_block *nb, unsigned long code, void *_param) +{ + struct vt_notifier_param *param = _param; + struct vc_data *vc = param->vc; + struct vcs_poll_data *poll = + container_of(nb, struct vcs_poll_data, notifier); + int currcons = poll->cons_num; + + if (code != VT_UPDATE) + return NOTIFY_DONE; + + if (currcons == 0) + currcons = fg_console; + else + currcons--; + if (currcons != vc->vc_num) + return NOTIFY_DONE; + + poll->seen_last_update = false; + wake_up_interruptible(&poll->waitq); + kill_fasync(&poll->fasync, SIGIO, POLL_IN); + return NOTIFY_OK; +} + +static void +vcs_poll_data_free(struct vcs_poll_data *poll) +{ + unregister_vt_notifier(&poll->notifier); + kfree(poll); +} + +static struct vcs_poll_data * +vcs_poll_data_get(struct file *file) +{ + struct vcs_poll_data *poll = file->private_data; + + if (poll) + return poll; + + poll = kzalloc(sizeof(*poll), GFP_KERNEL); + if (!poll) + return NULL; + poll->cons_num = iminor(file->f_path.dentry->d_inode) & 127; + init_waitqueue_head(&poll->waitq); + poll->notifier.notifier_call = vcs_notifier; + if (register_vt_notifier(&poll->notifier) != 0) { + kfree(poll); + return NULL; + } + + /* + * This code may be called either through ->poll() or ->fasync(). + * If we have two threads using the same file descriptor, they could + * both enter this function, both notice that the structure hasn't + * been allocated yet and go ahead allocating it in parallel, but + * only one of them must survive and be shared otherwise we'd leak + * memory with a dangling notifier callback. + */ + spin_lock(&file->f_lock); + if (!file->private_data) { + file->private_data = poll; + } else { + /* someone else raced ahead of us */ + vcs_poll_data_free(poll); + poll = file->private_data; + } + spin_unlock(&file->f_lock); + + return poll; +} + static int vcs_size(struct inode *inode) { @@ -102,6 +188,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) struct inode *inode = file->f_path.dentry->d_inode; unsigned int currcons = iminor(inode); struct vc_data *vc; + struct vcs_poll_data *poll; long pos; long viewed, attr, read; int col, maxcol; @@ -134,6 +221,9 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) ret = -EINVAL; if (pos < 0) goto unlock_out; + poll = file->private_data; + if (count && poll) + poll->seen_last_update = true; read = 0; ret = 0; while (count) { @@ -457,6 +547,37 @@ unlock_out: return ret; } +static unsigned int +vcs_poll(struct file *file, poll_table *wait) +{ + struct vcs_poll_data *poll = vcs_poll_data_get(file); + int ret = 0; + + if (poll) { + poll_wait(file, &poll->waitq, wait); + if (!poll->seen_last_update) + ret = POLLIN | POLLRDNORM; + } + return ret; +} + +static int +vcs_fasync(int fd, struct file *file, int on) +{ + struct vcs_poll_data *poll = file->private_data; + + if (!poll) { + /* don't allocate anything if all we want is disable fasync */ + if (!on) + return 0; + poll = vcs_poll_data_get(file); + if (!poll) + return -ENOMEM; + } + + return fasync_helper(fd, file, on, &poll->fasync); +} + static int vcs_open(struct inode *inode, struct file *filp) { @@ -470,11 +591,23 @@ vcs_open(struct inode *inode, struct file *filp) return ret; } +static int vcs_release(struct inode *inode, struct file *file) +{ + struct vcs_poll_data *poll = file->private_data; + + if (poll) + vcs_poll_data_free(poll); + return 0; +} + static const struct file_operations vcs_fops = { .llseek = vcs_lseek, .read = vcs_read, .write = vcs_write, + .poll = vcs_poll, + .fasync = vcs_fasync, .open = vcs_open, + .release = vcs_release, }; static struct class *vc_class; -- cgit v1.2.3 From 432c9ed22aff641039ccd400cdabf983fabc285e Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 1 Oct 2010 00:10:44 -0400 Subject: vcs: invoke the vt update callback when /dev/vcs* is written to A notifier chain is called whenever the vt code modifies a terminal content, except for one case which is when the modification comes through writes to /dev/vcs* devices. Let's add the missing notifier invocation at the end of vcs_write() for that case too. Signed-off-by: Nicolas Pitre Cc: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/char/vc_screen.c | 2 ++ drivers/char/vt.c | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c index 6f7054e1a516..273ab44cc91d 100644 --- a/drivers/char/vc_screen.c +++ b/drivers/char/vc_screen.c @@ -538,6 +538,8 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) } *ppos += written; ret = written; + if (written) + vcs_scr_updated(vc); unlock_out: release_console_sem(); diff --git a/drivers/char/vt.c b/drivers/char/vt.c index 281aada7b4a1..a8ec48ed14d9 100644 --- a/drivers/char/vt.c +++ b/drivers/char/vt.c @@ -4182,6 +4182,11 @@ void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org) } } +void vcs_scr_updated(struct vc_data *vc) +{ + notify_update(vc); +} + /* * Visible symbols for modules */ -- cgit v1.2.3