From fbc8a81d66bbbce3f0b4d5752f8bc8bb3c1fc439 Mon Sep 17 00:00:00 2001 From: Jonathan Corbet Date: Thu, 15 May 2008 10:39:37 -0600 Subject: UIO: cdev lock_kernel() pushdown Signed-off-by: Jonathan Corbet --- drivers/uio/uio.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'drivers/uio') diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 55cc7b80422..1a0415e77a3 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -297,12 +297,17 @@ static int uio_open(struct inode *inode, struct file *filep) struct uio_listener *listener; int ret = 0; + lock_kernel(); idev = idr_find(&uio_idr, iminor(inode)); - if (!idev) - return -ENODEV; + if (!idev) { + ret = -ENODEV; + goto out; + } - if (!try_module_get(idev->owner)) - return -ENODEV; + if (!try_module_get(idev->owner)) { + ret = -ENODEV; + goto out; + } listener = kmalloc(sizeof(*listener), GFP_KERNEL); if (!listener) { @@ -319,7 +324,7 @@ static int uio_open(struct inode *inode, struct file *filep) if (ret) goto err_infoopen; } - + unlock_kernel(); return 0; err_infoopen: @@ -329,6 +334,8 @@ err_alloc_listener: module_put(idev->owner); +out: + unlock_kernel(); return ret; } -- cgit v1.2.3 From 934da4766e5f72797118f7c014efaef567a812fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Sat, 31 May 2008 11:37:27 +0200 Subject: UIO: fix UIO Kconfig dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ae210f188614bb3d1ee3f19c64e28e3cdd44877c introduced a big "if UIO"/"endif" where all uio drivers are defined. So know there is no need for them to depend explicitly on UIO. Signed-off-by: Uwe Kleine-König Signed-off-by: Hans J. Koch Signed-off-by: Greg Kroah-Hartman --- drivers/uio/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/uio') diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig index a4aaab9c7dd..78e139c935e 100644 --- a/drivers/uio/Kconfig +++ b/drivers/uio/Kconfig @@ -15,7 +15,7 @@ if UIO config UIO_CIF tristate "generic Hilscher CIF Card driver" - depends on UIO && PCI + depends on PCI default n help Driver for Hilscher CIF DeviceNet and Profibus cards. This @@ -28,7 +28,6 @@ config UIO_CIF config UIO_SMX tristate "SMX cryptengine UIO interface" - depends on UIO default n help Userspace IO interface to the Cryptography engine found on the -- cgit v1.2.3 From 328a14e70e7f46997cb50d4258dd93d5377f98c6 Mon Sep 17 00:00:00 2001 From: "Hans J. Koch" Date: Fri, 23 May 2008 13:50:14 +0200 Subject: UIO: Add write function to allow irq masking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes it is necessary to enable/disable the interrupt of a UIO device from the userspace part of the driver. With this patch, the UIO kernel driver can implement an "irqcontrol()" function that does this. Userspace can write an s32 value to /dev/uioX (usually 0 or 1 to turn the irq off or on). The UIO core will then call the driver's irqcontrol function. Signed-off-by: Hans J. Koch Acked-by: Uwe Kleine-König Acked-by: Magnus Damm Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers/uio') diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 5a7ca2e6094..3a6934bf713 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -427,6 +427,31 @@ static ssize_t uio_read(struct file *filep, char __user *buf, return retval; } +static ssize_t uio_write(struct file *filep, const char __user *buf, + size_t count, loff_t *ppos) +{ + struct uio_listener *listener = filep->private_data; + struct uio_device *idev = listener->dev; + ssize_t retval; + s32 irq_on; + + if (idev->info->irq == UIO_IRQ_NONE) + return -EIO; + + if (count != sizeof(s32)) + return -EINVAL; + + if (!idev->info->irqcontrol) + return -ENOSYS; + + if (copy_from_user(&irq_on, buf, count)) + return -EFAULT; + + retval = idev->info->irqcontrol(idev->info, irq_on); + + return retval ? retval : sizeof(s32); +} + static int uio_find_mem_index(struct vm_area_struct *vma) { int mi; @@ -546,6 +571,7 @@ static const struct file_operations uio_fops = { .open = uio_open, .release = uio_release, .read = uio_read, + .write = uio_write, .mmap = uio_mmap, .poll = uio_poll, .fasync = uio_fasync, -- cgit v1.2.3 From 4d80d59437247075029534adec8d69fce2cfb87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Sat, 31 May 2008 11:37:27 +0200 Subject: UIO: add generic UIO platform driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a generic UIO platform driver. It eliminates the need for a dedicated kernel module for simple platform devices. Users only need to implement their irq handler in platform code and fill a struct uio_info there. This helps avoiding code duplication as UIO platform drivers often share a lot of common code. Signed-off-by: Uwe Kleine-König Signed-off-by: Hans J. Koch Signed-off-by: Greg Kroah-Hartman --- drivers/uio/Kconfig | 7 +++ drivers/uio/Makefile | 1 + drivers/uio/uio_pdrv.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 drivers/uio/uio_pdrv.c (limited to 'drivers/uio') diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig index 78e139c935e..2e9079df26b 100644 --- a/drivers/uio/Kconfig +++ b/drivers/uio/Kconfig @@ -26,6 +26,13 @@ config UIO_CIF To compile this driver as a module, choose M here: the module will be called uio_cif. +config UIO_PDRV + tristate "Userspace I/O platform driver" + help + Generic platform driver for Userspace I/O devices. + + If you don't know what to do here, say N. + config UIO_SMX tristate "SMX cryptengine UIO interface" default n diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile index 18c45662431..e00ce0def1a 100644 --- a/drivers/uio/Makefile +++ b/drivers/uio/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_UIO) += uio.o obj-$(CONFIG_UIO_CIF) += uio_cif.o +obj-$(CONFIG_UIO_PDRV) += uio_pdrv.o obj-$(CONFIG_UIO_SMX) += uio_smx.o diff --git a/drivers/uio/uio_pdrv.c b/drivers/uio/uio_pdrv.c new file mode 100644 index 00000000000..5d0d2e85d98 --- /dev/null +++ b/drivers/uio/uio_pdrv.c @@ -0,0 +1,118 @@ +/* + * drivers/uio/uio_pdrv.c + * + * Copyright (C) 2008 by Digi International Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ +#include +#include +#include + +#define DRIVER_NAME "uio" + +struct uio_platdata { + struct uio_info *uioinfo; +}; + +static int uio_pdrv_probe(struct platform_device *pdev) +{ + struct uio_info *uioinfo = pdev->dev.platform_data; + struct uio_platdata *pdata; + struct uio_mem *uiomem; + int ret = -ENODEV; + int i; + + if (!uioinfo || !uioinfo->name || !uioinfo->version) { + dev_dbg(&pdev->dev, "%s: err_uioinfo\n", __func__); + goto err_uioinfo; + } + + pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + ret = -ENOMEM; + dev_dbg(&pdev->dev, "%s: err_alloc_pdata\n", __func__); + goto err_alloc_pdata; + } + + pdata->uioinfo = uioinfo; + + uiomem = &uioinfo->mem[0]; + + for (i = 0; i < pdev->num_resources; ++i) { + struct resource *r = &pdev->resource[i]; + + if (r->flags != IORESOURCE_MEM) + continue; + + if (uiomem >= &uioinfo->mem[MAX_UIO_MAPS]) { + dev_warn(&pdev->dev, "device has more than " + __stringify(MAX_UIO_MAPS) + " I/O memory resources.\n"); + break; + } + + uiomem->memtype = UIO_MEM_PHYS; + uiomem->addr = r->start; + uiomem->size = r->end - r->start + 1; + ++uiomem; + } + + while (uiomem < &uioinfo->mem[MAX_UIO_MAPS]) { + uiomem->size = 0; + ++uiomem; + } + + pdata->uioinfo->priv = pdata; + + ret = uio_register_device(&pdev->dev, pdata->uioinfo); + + if (ret) { + kfree(pdata); +err_alloc_pdata: +err_uioinfo: + return ret; + } + + platform_set_drvdata(pdev, pdata); + + return 0; +} + +static int uio_pdrv_remove(struct platform_device *pdev) +{ + struct uio_platdata *pdata = platform_get_drvdata(pdev); + + uio_unregister_device(pdata->uioinfo); + + return 0; +} + +static struct platform_driver uio_pdrv = { + .probe = uio_pdrv_probe, + .remove = uio_pdrv_remove, + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + }, +}; + +static int __init uio_pdrv_init(void) +{ + return platform_driver_register(&uio_pdrv); +} + +static void __exit uio_pdrv_exit(void) +{ + platform_driver_unregister(&uio_pdrv); +} +module_init(uio_pdrv_init); +module_exit(uio_pdrv_exit); + +MODULE_AUTHOR("Uwe Kleine-Koenig"); +MODULE_DESCRIPTION("Userspace I/O platform driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:" DRIVER_NAME); -- cgit v1.2.3