2006-12-07 02:58:29 -07:00
|
|
|
/*
|
|
|
|
* drivers/uio/uio.c
|
|
|
|
*
|
|
|
|
* Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
|
|
|
|
* Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
|
2010-10-29 16:36:47 -06:00
|
|
|
* Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
|
2006-12-07 02:58:29 -07:00
|
|
|
* Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
|
|
|
|
*
|
|
|
|
* Userspace IO
|
|
|
|
*
|
|
|
|
* Base Functions
|
|
|
|
*
|
|
|
|
* Licensed under the GPLv2 only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2006-12-07 02:58:29 -07:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/idr.h>
|
2009-10-07 07:09:06 -06:00
|
|
|
#include <linux/sched.h>
|
2006-12-07 02:58:29 -07:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kobject.h>
|
2010-09-14 12:38:06 -06:00
|
|
|
#include <linux/cdev.h>
|
2006-12-07 02:58:29 -07:00
|
|
|
#include <linux/uio_driver.h>
|
|
|
|
|
2010-09-14 12:38:06 -06:00
|
|
|
#define UIO_MAX_DEVICES (1U << MINORBITS)
|
2006-12-07 02:58:29 -07:00
|
|
|
|
|
|
|
struct uio_device {
|
|
|
|
struct module *owner;
|
|
|
|
struct device *dev;
|
|
|
|
int minor;
|
|
|
|
atomic_t event;
|
|
|
|
struct fasync_struct *async_queue;
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
int vma_count;
|
|
|
|
struct uio_info *info;
|
2007-12-04 15:41:54 -07:00
|
|
|
struct kobject *map_dir;
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
struct kobject *portio_dir;
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int uio_major;
|
2010-09-14 12:38:06 -06:00
|
|
|
static struct cdev *uio_cdev;
|
2006-12-07 02:58:29 -07:00
|
|
|
static DEFINE_IDR(uio_idr);
|
2008-01-22 12:50:54 -07:00
|
|
|
static const struct file_operations uio_fops;
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2008-08-26 17:15:45 -06:00
|
|
|
/* Protect idr accesses */
|
|
|
|
static DEFINE_MUTEX(minor_lock);
|
|
|
|
|
2006-12-07 02:58:29 -07:00
|
|
|
/*
|
|
|
|
* attributes
|
|
|
|
*/
|
|
|
|
|
2007-12-04 15:41:54 -07:00
|
|
|
struct uio_map {
|
|
|
|
struct kobject kobj;
|
|
|
|
struct uio_mem *mem;
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
2007-12-04 15:41:54 -07:00
|
|
|
#define to_map(map) container_of(map, struct uio_map, kobj)
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2009-01-06 16:15:39 -07:00
|
|
|
static ssize_t map_name_show(struct uio_mem *mem, char *buf)
|
|
|
|
{
|
|
|
|
if (unlikely(!mem->name))
|
|
|
|
mem->name = "";
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", mem->name);
|
|
|
|
}
|
|
|
|
|
2008-02-19 02:55:05 -07:00
|
|
|
static ssize_t map_addr_show(struct uio_mem *mem, char *buf)
|
2006-12-07 02:58:29 -07:00
|
|
|
{
|
2011-10-17 12:50:20 -06:00
|
|
|
return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr);
|
2008-02-19 02:55:05 -07:00
|
|
|
}
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2008-02-19 02:55:05 -07:00
|
|
|
static ssize_t map_size_show(struct uio_mem *mem, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "0x%lx\n", mem->size);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
2008-09-18 15:53:18 -06:00
|
|
|
static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
|
|
|
|
{
|
2011-10-17 12:50:20 -06:00
|
|
|
return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & ~PAGE_MASK);
|
2008-09-18 15:53:18 -06:00
|
|
|
}
|
|
|
|
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
struct map_sysfs_entry {
|
2008-02-19 02:55:05 -07:00
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct uio_mem *, char *);
|
|
|
|
ssize_t (*store)(struct uio_mem *, const char *, size_t);
|
|
|
|
};
|
|
|
|
|
2009-01-06 16:15:39 -07:00
|
|
|
static struct map_sysfs_entry name_attribute =
|
|
|
|
__ATTR(name, S_IRUGO, map_name_show, NULL);
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
static struct map_sysfs_entry addr_attribute =
|
2008-02-19 02:55:05 -07:00
|
|
|
__ATTR(addr, S_IRUGO, map_addr_show, NULL);
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
static struct map_sysfs_entry size_attribute =
|
2008-02-19 02:55:05 -07:00
|
|
|
__ATTR(size, S_IRUGO, map_size_show, NULL);
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
static struct map_sysfs_entry offset_attribute =
|
2008-09-18 15:53:18 -06:00
|
|
|
__ATTR(offset, S_IRUGO, map_offset_show, NULL);
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2007-12-04 15:41:54 -07:00
|
|
|
static struct attribute *attrs[] = {
|
2009-01-06 16:15:39 -07:00
|
|
|
&name_attribute.attr,
|
2008-02-19 02:55:05 -07:00
|
|
|
&addr_attribute.attr,
|
2007-12-04 15:41:54 -07:00
|
|
|
&size_attribute.attr,
|
2008-09-18 15:53:18 -06:00
|
|
|
&offset_attribute.attr,
|
2007-12-04 15:41:54 -07:00
|
|
|
NULL, /* need to NULL terminate the list of attributes */
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
2007-12-04 15:41:54 -07:00
|
|
|
static void map_release(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
struct uio_map *map = to_map(kobj);
|
|
|
|
kfree(map);
|
|
|
|
}
|
|
|
|
|
2008-02-19 02:55:05 -07:00
|
|
|
static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct uio_map *map = to_map(kobj);
|
|
|
|
struct uio_mem *mem = map->mem;
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
struct map_sysfs_entry *entry;
|
2008-02-19 02:55:05 -07:00
|
|
|
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
entry = container_of(attr, struct map_sysfs_entry, attr);
|
2008-02-19 02:55:05 -07:00
|
|
|
|
|
|
|
if (!entry->show)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return entry->show(mem, buf);
|
|
|
|
}
|
|
|
|
|
2010-01-18 18:58:23 -07:00
|
|
|
static const struct sysfs_ops map_sysfs_ops = {
|
2008-02-19 02:55:05 -07:00
|
|
|
.show = map_type_show,
|
|
|
|
};
|
|
|
|
|
2006-12-07 02:58:29 -07:00
|
|
|
static struct kobj_type map_attr_type = {
|
2007-12-04 15:41:54 -07:00
|
|
|
.release = map_release,
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
.sysfs_ops = &map_sysfs_ops,
|
2007-12-04 15:41:54 -07:00
|
|
|
.default_attrs = attrs,
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
struct uio_portio {
|
|
|
|
struct kobject kobj;
|
|
|
|
struct uio_port *port;
|
|
|
|
};
|
|
|
|
#define to_portio(portio) container_of(portio, struct uio_portio, kobj)
|
|
|
|
|
2009-01-06 16:15:39 -07:00
|
|
|
static ssize_t portio_name_show(struct uio_port *port, char *buf)
|
|
|
|
{
|
|
|
|
if (unlikely(!port->name))
|
|
|
|
port->name = "";
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", port->name);
|
|
|
|
}
|
|
|
|
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
static ssize_t portio_start_show(struct uio_port *port, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "0x%lx\n", port->start);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t portio_size_show(struct uio_port *port, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "0x%lx\n", port->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t portio_porttype_show(struct uio_port *port, char *buf)
|
|
|
|
{
|
|
|
|
const char *porttypes[] = {"none", "x86", "gpio", "other"};
|
|
|
|
|
|
|
|
if ((port->porttype < 0) || (port->porttype > UIO_PORT_OTHER))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return sprintf(buf, "port_%s\n", porttypes[port->porttype]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct portio_sysfs_entry {
|
|
|
|
struct attribute attr;
|
|
|
|
ssize_t (*show)(struct uio_port *, char *);
|
|
|
|
ssize_t (*store)(struct uio_port *, const char *, size_t);
|
|
|
|
};
|
|
|
|
|
2009-01-06 16:15:39 -07:00
|
|
|
static struct portio_sysfs_entry portio_name_attribute =
|
|
|
|
__ATTR(name, S_IRUGO, portio_name_show, NULL);
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
static struct portio_sysfs_entry portio_start_attribute =
|
|
|
|
__ATTR(start, S_IRUGO, portio_start_show, NULL);
|
|
|
|
static struct portio_sysfs_entry portio_size_attribute =
|
|
|
|
__ATTR(size, S_IRUGO, portio_size_show, NULL);
|
|
|
|
static struct portio_sysfs_entry portio_porttype_attribute =
|
|
|
|
__ATTR(porttype, S_IRUGO, portio_porttype_show, NULL);
|
|
|
|
|
|
|
|
static struct attribute *portio_attrs[] = {
|
2009-01-06 16:15:39 -07:00
|
|
|
&portio_name_attribute.attr,
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
&portio_start_attribute.attr,
|
|
|
|
&portio_size_attribute.attr,
|
|
|
|
&portio_porttype_attribute.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void portio_release(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
struct uio_portio *portio = to_portio(kobj);
|
|
|
|
kfree(portio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct uio_portio *portio = to_portio(kobj);
|
|
|
|
struct uio_port *port = portio->port;
|
|
|
|
struct portio_sysfs_entry *entry;
|
|
|
|
|
|
|
|
entry = container_of(attr, struct portio_sysfs_entry, attr);
|
|
|
|
|
|
|
|
if (!entry->show)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return entry->show(port, buf);
|
|
|
|
}
|
|
|
|
|
2010-01-18 18:58:23 -07:00
|
|
|
static const struct sysfs_ops portio_sysfs_ops = {
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
.show = portio_type_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kobj_type portio_attr_type = {
|
|
|
|
.release = portio_release,
|
|
|
|
.sysfs_ops = &portio_sysfs_ops,
|
|
|
|
.default_attrs = portio_attrs,
|
|
|
|
};
|
|
|
|
|
2006-12-07 02:58:29 -07:00
|
|
|
static ssize_t show_name(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = dev_get_drvdata(dev);
|
2010-09-14 12:36:54 -06:00
|
|
|
return sprintf(buf, "%s\n", idev->info->name);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_version(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = dev_get_drvdata(dev);
|
2010-09-14 12:36:54 -06:00
|
|
|
return sprintf(buf, "%s\n", idev->info->version);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_event(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = dev_get_drvdata(dev);
|
2010-09-14 12:36:54 -06:00
|
|
|
return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
2010-09-14 12:38:36 -06:00
|
|
|
static struct device_attribute uio_class_attributes[] = {
|
|
|
|
__ATTR(name, S_IRUGO, show_name, NULL),
|
|
|
|
__ATTR(version, S_IRUGO, show_version, NULL),
|
|
|
|
__ATTR(event, S_IRUGO, show_event, NULL),
|
|
|
|
{}
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
2010-09-14 12:38:36 -06:00
|
|
|
/* UIO class infrastructure */
|
|
|
|
static struct class uio_class = {
|
|
|
|
.name = "uio",
|
|
|
|
.dev_attrs = uio_class_attributes,
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* device functions
|
|
|
|
*/
|
|
|
|
static int uio_dev_add_attributes(struct uio_device *idev)
|
|
|
|
{
|
|
|
|
int ret;
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
int mi, pi;
|
2006-12-07 02:58:29 -07:00
|
|
|
int map_found = 0;
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
int portio_found = 0;
|
2006-12-07 02:58:29 -07:00
|
|
|
struct uio_mem *mem;
|
2007-12-04 15:41:54 -07:00
|
|
|
struct uio_map *map;
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
struct uio_port *port;
|
|
|
|
struct uio_portio *portio;
|
2006-12-07 02:58:29 -07:00
|
|
|
|
|
|
|
for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
|
|
|
|
mem = &idev->info->mem[mi];
|
|
|
|
if (mem->size == 0)
|
|
|
|
break;
|
|
|
|
if (!map_found) {
|
|
|
|
map_found = 1;
|
2007-12-04 15:41:54 -07:00
|
|
|
idev->map_dir = kobject_create_and_add("maps",
|
|
|
|
&idev->dev->kobj);
|
|
|
|
if (!idev->map_dir)
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
goto err_map;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
2007-12-04 15:41:54 -07:00
|
|
|
map = kzalloc(sizeof(*map), GFP_KERNEL);
|
|
|
|
if (!map)
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
goto err_map;
|
2007-12-17 23:05:35 -07:00
|
|
|
kobject_init(&map->kobj, &map_attr_type);
|
2007-12-04 15:41:54 -07:00
|
|
|
map->mem = mem;
|
|
|
|
mem->map = map;
|
2007-12-17 23:05:35 -07:00
|
|
|
ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
|
2007-12-04 15:41:54 -07:00
|
|
|
if (ret)
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
goto err_map;
|
2007-12-04 15:41:54 -07:00
|
|
|
ret = kobject_uevent(&map->kobj, KOBJ_ADD);
|
2006-12-07 02:58:29 -07:00
|
|
|
if (ret)
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
goto err_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pi = 0; pi < MAX_UIO_PORT_REGIONS; pi++) {
|
|
|
|
port = &idev->info->port[pi];
|
|
|
|
if (port->size == 0)
|
|
|
|
break;
|
|
|
|
if (!portio_found) {
|
|
|
|
portio_found = 1;
|
|
|
|
idev->portio_dir = kobject_create_and_add("portio",
|
|
|
|
&idev->dev->kobj);
|
|
|
|
if (!idev->portio_dir)
|
|
|
|
goto err_portio;
|
|
|
|
}
|
|
|
|
portio = kzalloc(sizeof(*portio), GFP_KERNEL);
|
|
|
|
if (!portio)
|
|
|
|
goto err_portio;
|
|
|
|
kobject_init(&portio->kobj, &portio_attr_type);
|
|
|
|
portio->port = port;
|
|
|
|
port->portio = portio;
|
|
|
|
ret = kobject_add(&portio->kobj, idev->portio_dir,
|
|
|
|
"port%d", pi);
|
|
|
|
if (ret)
|
|
|
|
goto err_portio;
|
|
|
|
ret = kobject_uevent(&portio->kobj, KOBJ_ADD);
|
|
|
|
if (ret)
|
|
|
|
goto err_portio;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
err_portio:
|
|
|
|
for (pi--; pi >= 0; pi--) {
|
|
|
|
port = &idev->info->port[pi];
|
|
|
|
portio = port->portio;
|
|
|
|
kobject_put(&portio->kobj);
|
|
|
|
}
|
|
|
|
kobject_put(idev->portio_dir);
|
|
|
|
err_map:
|
2006-12-07 02:58:29 -07:00
|
|
|
for (mi--; mi>=0; mi--) {
|
|
|
|
mem = &idev->info->mem[mi];
|
2007-12-04 15:41:54 -07:00
|
|
|
map = mem->map;
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(&map->kobj);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(idev->map_dir);
|
2006-12-07 02:58:29 -07:00
|
|
|
dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uio_dev_del_attributes(struct uio_device *idev)
|
|
|
|
{
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
int i;
|
2006-12-07 02:58:29 -07:00
|
|
|
struct uio_mem *mem;
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
struct uio_port *port;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_UIO_MAPS; i++) {
|
|
|
|
mem = &idev->info->mem[i];
|
2006-12-07 02:58:29 -07:00
|
|
|
if (mem->size == 0)
|
|
|
|
break;
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(&mem->map->kobj);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
2007-12-20 09:13:05 -07:00
|
|
|
kobject_put(idev->map_dir);
|
UIO: Pass information about ioports to userspace (V2)
Devices sometimes have memory where all or parts of it can not be mapped to
userspace. But it might still be possible to access this memory from
userspace by other means. An example are PCI cards that advertise not only
mappable memory but also ioport ranges. On x86 architectures, these can be
accessed with ioperm, iopl, inb, outb, and friends. Mike Frysinger (CCed)
reported a similar problem on Blackfin arch where it doesn't seem to be easy
to mmap non-cached memory but it can still be accessed from userspace.
This patch allows kernel drivers to pass information about such ports to
userspace. Similar to the existing mem[] array, it adds a port[] array to
struct uio_info. Each port range is described by start, size, and porttype.
If a driver fills in at least one such port range, the UIO core will simply
pass this information to userspace by creating a new directory "portio"
underneath /sys/class/uio/uioN/. Similar to the "mem" directory, it will
contain a subdirectory (portX) for each port range given.
Note that UIO simply passes this information to userspace, it performs no
action whatsoever with this data. It's userspace's responsibility to obtain
access to these ports and to solve arch dependent issues. The "porttype"
attribute tells userspace what kind of port it is dealing with.
This mechanism could also be used to give userspace information about GPIOs
related to a device. You frequently find such hardware in embedded devices,
so I added a UIO_PORT_GPIO definition. I'm not really sure if this is a good
idea since there are other solutions to this problem, but it won't hurt much
anyway.
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-12-05 18:23:13 -07:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_UIO_PORT_REGIONS; i++) {
|
|
|
|
port = &idev->info->port[i];
|
|
|
|
if (port->size == 0)
|
|
|
|
break;
|
|
|
|
kobject_put(&port->portio->kobj);
|
|
|
|
}
|
|
|
|
kobject_put(idev->portio_dir);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int uio_get_minor(struct uio_device *idev)
|
|
|
|
{
|
|
|
|
int retval = -ENOMEM;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
mutex_lock(&minor_lock);
|
|
|
|
if (idr_pre_get(&uio_idr, GFP_KERNEL) == 0)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
retval = idr_get_new(&uio_idr, idev, &id);
|
|
|
|
if (retval < 0) {
|
|
|
|
if (retval == -EAGAIN)
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto exit;
|
|
|
|
}
|
2011-03-31 06:38:47 -06:00
|
|
|
if (id < UIO_MAX_DEVICES) {
|
|
|
|
idev->minor = id;
|
|
|
|
} else {
|
|
|
|
dev_err(idev->dev, "too many uio devices\n");
|
|
|
|
retval = -EINVAL;
|
|
|
|
idr_remove(&uio_idr, id);
|
|
|
|
}
|
2006-12-07 02:58:29 -07:00
|
|
|
exit:
|
|
|
|
mutex_unlock(&minor_lock);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uio_free_minor(struct uio_device *idev)
|
|
|
|
{
|
2008-08-26 17:15:45 -06:00
|
|
|
mutex_lock(&minor_lock);
|
2006-12-07 02:58:29 -07:00
|
|
|
idr_remove(&uio_idr, idev->minor);
|
2008-08-26 17:15:45 -06:00
|
|
|
mutex_unlock(&minor_lock);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* uio_event_notify - trigger an interrupt event
|
|
|
|
* @info: UIO device capabilities
|
|
|
|
*/
|
|
|
|
void uio_event_notify(struct uio_info *info)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = info->uio_dev;
|
|
|
|
|
|
|
|
atomic_inc(&idev->event);
|
|
|
|
wake_up_interruptible(&idev->wait);
|
|
|
|
kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(uio_event_notify);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* uio_interrupt - hardware interrupt handler
|
|
|
|
* @irq: IRQ number, can be UIO_IRQ_CYCLIC for cyclic timer
|
|
|
|
* @dev_id: Pointer to the devices uio_device structure
|
|
|
|
*/
|
|
|
|
static irqreturn_t uio_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = (struct uio_device *)dev_id;
|
|
|
|
irqreturn_t ret = idev->info->handler(irq, idev->info);
|
|
|
|
|
|
|
|
if (ret == IRQ_HANDLED)
|
|
|
|
uio_event_notify(idev->info);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct uio_listener {
|
|
|
|
struct uio_device *dev;
|
|
|
|
s32 event_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int uio_open(struct inode *inode, struct file *filep)
|
|
|
|
{
|
|
|
|
struct uio_device *idev;
|
|
|
|
struct uio_listener *listener;
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-08-26 17:15:45 -06:00
|
|
|
mutex_lock(&minor_lock);
|
2006-12-07 02:58:29 -07:00
|
|
|
idev = idr_find(&uio_idr, iminor(inode));
|
2008-08-26 17:15:45 -06:00
|
|
|
mutex_unlock(&minor_lock);
|
2008-05-15 10:39:37 -06:00
|
|
|
if (!idev) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2008-05-15 10:39:37 -06:00
|
|
|
if (!try_module_get(idev->owner)) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-04-11 03:07:39 -06:00
|
|
|
|
2006-12-07 02:58:29 -07:00
|
|
|
listener = kmalloc(sizeof(*listener), GFP_KERNEL);
|
2008-04-11 03:07:39 -06:00
|
|
|
if (!listener) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_alloc_listener;
|
|
|
|
}
|
2006-12-07 02:58:29 -07:00
|
|
|
|
|
|
|
listener->dev = idev;
|
|
|
|
listener->event_count = atomic_read(&idev->event);
|
|
|
|
filep->private_data = listener;
|
|
|
|
|
|
|
|
if (idev->info->open) {
|
|
|
|
ret = idev->info->open(idev->info, inode);
|
2008-04-11 03:07:39 -06:00
|
|
|
if (ret)
|
|
|
|
goto err_infoopen;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
2008-04-11 03:07:39 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_infoopen:
|
|
|
|
kfree(listener);
|
|
|
|
|
2008-08-26 17:15:45 -06:00
|
|
|
err_alloc_listener:
|
2008-04-11 03:07:39 -06:00
|
|
|
module_put(idev->owner);
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2008-05-15 10:39:37 -06:00
|
|
|
out:
|
2006-12-07 02:58:29 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uio_fasync(int fd, struct file *filep, int on)
|
|
|
|
{
|
|
|
|
struct uio_listener *listener = filep->private_data;
|
|
|
|
struct uio_device *idev = listener->dev;
|
|
|
|
|
|
|
|
return fasync_helper(fd, filep, on, &idev->async_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uio_release(struct inode *inode, struct file *filep)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct uio_listener *listener = filep->private_data;
|
|
|
|
struct uio_device *idev = listener->dev;
|
|
|
|
|
2008-04-11 03:07:39 -06:00
|
|
|
if (idev->info->release)
|
2006-12-07 02:58:29 -07:00
|
|
|
ret = idev->info->release(idev->info, inode);
|
2008-04-11 03:07:39 -06:00
|
|
|
|
|
|
|
module_put(idev->owner);
|
2006-12-07 02:58:29 -07:00
|
|
|
kfree(listener);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int uio_poll(struct file *filep, poll_table *wait)
|
|
|
|
{
|
|
|
|
struct uio_listener *listener = filep->private_data;
|
|
|
|
struct uio_device *idev = listener->dev;
|
|
|
|
|
2010-09-14 12:37:36 -06:00
|
|
|
if (!idev->info->irq)
|
2006-12-07 02:58:29 -07:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
poll_wait(filep, &idev->wait, wait);
|
|
|
|
if (listener->event_count != atomic_read(&idev->event))
|
|
|
|
return POLLIN | POLLRDNORM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t uio_read(struct file *filep, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct uio_listener *listener = filep->private_data;
|
|
|
|
struct uio_device *idev = listener->dev;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
ssize_t retval;
|
|
|
|
s32 event_count;
|
|
|
|
|
2010-09-14 12:37:36 -06:00
|
|
|
if (!idev->info->irq)
|
2006-12-07 02:58:29 -07:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (count != sizeof(s32))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
add_wait_queue(&idev->wait, &wait);
|
|
|
|
|
|
|
|
do {
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
|
|
|
|
event_count = atomic_read(&idev->event);
|
|
|
|
if (event_count != listener->event_count) {
|
|
|
|
if (copy_to_user(buf, &event_count, count))
|
|
|
|
retval = -EFAULT;
|
|
|
|
else {
|
|
|
|
listener->event_count = event_count;
|
|
|
|
retval = count;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filep->f_flags & O_NONBLOCK) {
|
|
|
|
retval = -EAGAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
retval = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
schedule();
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
remove_wait_queue(&idev->wait, &wait);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-05-23 05:50:14 -06:00
|
|
|
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;
|
|
|
|
|
2010-09-14 12:37:36 -06:00
|
|
|
if (!idev->info->irq)
|
2008-05-23 05:50:14 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-12-07 02:58:29 -07:00
|
|
|
static int uio_find_mem_index(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = vma->vm_private_data;
|
|
|
|
|
2011-03-28 15:33:26 -06:00
|
|
|
if (vma->vm_pgoff < MAX_UIO_MAPS) {
|
|
|
|
if (idev->info->mem[vma->vm_pgoff].size == 0)
|
2006-12-07 02:58:29 -07:00
|
|
|
return -1;
|
2011-03-28 15:33:26 -06:00
|
|
|
return (int)vma->vm_pgoff;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uio_vma_open(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = vma->vm_private_data;
|
|
|
|
idev->vma_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uio_vma_close(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = vma->vm_private_data;
|
|
|
|
idev->vma_count--;
|
|
|
|
}
|
|
|
|
|
2008-02-06 02:37:35 -07:00
|
|
|
static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
2006-12-07 02:58:29 -07:00
|
|
|
{
|
|
|
|
struct uio_device *idev = vma->vm_private_data;
|
2008-02-06 02:37:35 -07:00
|
|
|
struct page *page;
|
2008-09-23 17:10:02 -06:00
|
|
|
unsigned long offset;
|
2006-12-07 02:58:29 -07:00
|
|
|
|
|
|
|
int mi = uio_find_mem_index(vma);
|
|
|
|
if (mi < 0)
|
2008-02-06 02:37:35 -07:00
|
|
|
return VM_FAULT_SIGBUS;
|
2006-12-07 02:58:29 -07:00
|
|
|
|
2008-09-23 17:10:02 -06:00
|
|
|
/*
|
|
|
|
* We need to subtract mi because userspace uses offset = N*PAGE_SIZE
|
|
|
|
* to use mem[N].
|
|
|
|
*/
|
|
|
|
offset = (vmf->pgoff - mi) << PAGE_SHIFT;
|
|
|
|
|
2006-12-07 02:58:29 -07:00
|
|
|
if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL)
|
2008-09-23 17:10:02 -06:00
|
|
|
page = virt_to_page(idev->info->mem[mi].addr + offset);
|
2006-12-07 02:58:29 -07:00
|
|
|
else
|
2011-10-17 12:50:20 -06:00
|
|
|
page = vmalloc_to_page((void *)(unsigned long)idev->info->mem[mi].addr + offset);
|
2006-12-07 02:58:29 -07:00
|
|
|
get_page(page);
|
2008-02-06 02:37:35 -07:00
|
|
|
vmf->page = page;
|
|
|
|
return 0;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
2009-09-27 12:29:37 -06:00
|
|
|
static const struct vm_operations_struct uio_vm_ops = {
|
2006-12-07 02:58:29 -07:00
|
|
|
.open = uio_vma_open,
|
|
|
|
.close = uio_vma_close,
|
2008-02-06 02:37:35 -07:00
|
|
|
.fault = uio_vma_fault,
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int uio_mmap_physical(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct uio_device *idev = vma->vm_private_data;
|
|
|
|
int mi = uio_find_mem_index(vma);
|
|
|
|
if (mi < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-03-14 04:28:36 -06:00
|
|
|
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
2006-12-07 02:58:29 -07:00
|
|
|
|
|
|
|
return remap_pfn_range(vma,
|
|
|
|
vma->vm_start,
|
|
|
|
idev->info->mem[mi].addr >> PAGE_SHIFT,
|
|
|
|
vma->vm_end - vma->vm_start,
|
|
|
|
vma->vm_page_prot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uio_mmap_logical(struct vm_area_struct *vma)
|
|
|
|
{
|
mm: kill vma flag VM_RESERVED and mm->reserved_vm counter
A long time ago, in v2.4, VM_RESERVED kept swapout process off VMA,
currently it lost original meaning but still has some effects:
| effect | alternative flags
-+------------------------+---------------------------------------------
1| account as reserved_vm | VM_IO
2| skip in core dump | VM_IO, VM_DONTDUMP
3| do not merge or expand | VM_IO, VM_DONTEXPAND, VM_HUGETLB, VM_PFNMAP
4| do not mlock | VM_IO, VM_DONTEXPAND, VM_HUGETLB, VM_PFNMAP
This patch removes reserved_vm counter from mm_struct. Seems like nobody
cares about it, it does not exported into userspace directly, it only
reduces total_vm showed in proc.
Thus VM_RESERVED can be replaced with VM_IO or pair VM_DONTEXPAND | VM_DONTDUMP.
remap_pfn_range() and io_remap_pfn_range() set VM_IO|VM_DONTEXPAND|VM_DONTDUMP.
remap_vmalloc_range() set VM_DONTEXPAND | VM_DONTDUMP.
[akpm@linux-foundation.org: drivers/vfio/pci/vfio_pci.c fixup]
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Carsten Otte <cotte@de.ibm.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Eric Paris <eparis@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
Cc: Matt Helsley <matthltc@us.ibm.com>
Cc: Nick Piggin <npiggin@kernel.dk>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Venkatesh Pallipadi <venki@google.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-10-08 17:29:02 -06:00
|
|
|
vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
|
2006-12-07 02:58:29 -07:00
|
|
|
vma->vm_ops = &uio_vm_ops;
|
|
|
|
uio_vma_open(vma);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct uio_listener *listener = filep->private_data;
|
|
|
|
struct uio_device *idev = listener->dev;
|
|
|
|
int mi;
|
|
|
|
unsigned long requested_pages, actual_pages;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (vma->vm_end < vma->vm_start)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vma->vm_private_data = idev;
|
|
|
|
|
|
|
|
mi = uio_find_mem_index(vma);
|
|
|
|
if (mi < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
requested_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
|
2009-02-24 10:22:59 -07:00
|
|
|
actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK)
|
|
|
|
+ idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT;
|
2006-12-07 02:58:29 -07:00
|
|
|
if (requested_pages > actual_pages)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (idev->info->mmap) {
|
|
|
|
ret = idev->info->mmap(idev->info, vma);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (idev->info->mem[mi].memtype) {
|
|
|
|
case UIO_MEM_PHYS:
|
|
|
|
return uio_mmap_physical(vma);
|
|
|
|
case UIO_MEM_LOGICAL:
|
|
|
|
case UIO_MEM_VIRTUAL:
|
|
|
|
return uio_mmap_logical(vma);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-22 12:50:54 -07:00
|
|
|
static const struct file_operations uio_fops = {
|
2006-12-07 02:58:29 -07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = uio_open,
|
|
|
|
.release = uio_release,
|
|
|
|
.read = uio_read,
|
2008-05-23 05:50:14 -06:00
|
|
|
.write = uio_write,
|
2006-12-07 02:58:29 -07:00
|
|
|
.mmap = uio_mmap,
|
|
|
|
.poll = uio_poll,
|
|
|
|
.fasync = uio_fasync,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 10:52:59 -06:00
|
|
|
.llseek = noop_llseek,
|
2006-12-07 02:58:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int uio_major_init(void)
|
|
|
|
{
|
2010-09-14 12:38:06 -06:00
|
|
|
static const char name[] = "uio";
|
|
|
|
struct cdev *cdev = NULL;
|
|
|
|
dev_t uio_dev = 0;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = alloc_chrdev_region(&uio_dev, 0, UIO_MAX_DEVICES, name);
|
|
|
|
if (result)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
result = -ENOMEM;
|
|
|
|
cdev = cdev_alloc();
|
|
|
|
if (!cdev)
|
|
|
|
goto out_unregister;
|
|
|
|
|
|
|
|
cdev->owner = THIS_MODULE;
|
|
|
|
cdev->ops = &uio_fops;
|
|
|
|
kobject_set_name(&cdev->kobj, "%s", name);
|
|
|
|
|
|
|
|
result = cdev_add(cdev, uio_dev, UIO_MAX_DEVICES);
|
|
|
|
if (result)
|
|
|
|
goto out_put;
|
|
|
|
|
|
|
|
uio_major = MAJOR(uio_dev);
|
|
|
|
uio_cdev = cdev;
|
2011-08-19 22:12:08 -06:00
|
|
|
return 0;
|
2010-09-14 12:38:06 -06:00
|
|
|
out_put:
|
|
|
|
kobject_put(&cdev->kobj);
|
|
|
|
out_unregister:
|
|
|
|
unregister_chrdev_region(uio_dev, UIO_MAX_DEVICES);
|
2011-08-19 22:12:08 -06:00
|
|
|
out:
|
|
|
|
return result;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uio_major_cleanup(void)
|
|
|
|
{
|
2010-09-14 12:38:06 -06:00
|
|
|
unregister_chrdev_region(MKDEV(uio_major, 0), UIO_MAX_DEVICES);
|
|
|
|
cdev_del(uio_cdev);
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int init_uio_class(void)
|
|
|
|
{
|
2010-09-14 12:36:27 -06:00
|
|
|
int ret;
|
2006-12-07 02:58:29 -07:00
|
|
|
|
|
|
|
/* This is the first time in here, set everything up properly */
|
|
|
|
ret = uio_major_init();
|
|
|
|
if (ret)
|
|
|
|
goto exit;
|
|
|
|
|
2010-09-14 12:38:36 -06:00
|
|
|
ret = class_register(&uio_class);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "class_register failed for uio\n");
|
|
|
|
goto err_class_register;
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
2010-09-14 12:38:36 -06:00
|
|
|
err_class_register:
|
2006-12-07 02:58:29 -07:00
|
|
|
uio_major_cleanup();
|
|
|
|
exit:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-14 12:36:27 -06:00
|
|
|
static void release_uio_class(void)
|
2006-12-07 02:58:29 -07:00
|
|
|
{
|
2010-09-14 12:38:36 -06:00
|
|
|
class_unregister(&uio_class);
|
2006-12-07 02:58:29 -07:00
|
|
|
uio_major_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* uio_register_device - register a new userspace IO device
|
|
|
|
* @owner: module that creates the new device
|
|
|
|
* @parent: parent device
|
|
|
|
* @info: UIO device capabilities
|
|
|
|
*
|
|
|
|
* returns zero on success or a negative error code.
|
|
|
|
*/
|
|
|
|
int __uio_register_device(struct module *owner,
|
|
|
|
struct device *parent,
|
|
|
|
struct uio_info *info)
|
|
|
|
{
|
|
|
|
struct uio_device *idev;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!parent || !info || !info->name || !info->version)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
info->uio_dev = NULL;
|
|
|
|
|
|
|
|
idev = kzalloc(sizeof(*idev), GFP_KERNEL);
|
|
|
|
if (!idev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_kzalloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
idev->owner = owner;
|
|
|
|
idev->info = info;
|
|
|
|
init_waitqueue_head(&idev->wait);
|
|
|
|
atomic_set(&idev->event, 0);
|
|
|
|
|
|
|
|
ret = uio_get_minor(idev);
|
|
|
|
if (ret)
|
|
|
|
goto err_get_minor;
|
|
|
|
|
2010-09-14 12:38:36 -06:00
|
|
|
idev->dev = device_create(&uio_class, parent,
|
2008-07-21 21:03:34 -06:00
|
|
|
MKDEV(uio_major, idev->minor), idev,
|
|
|
|
"uio%d", idev->minor);
|
2006-12-07 02:58:29 -07:00
|
|
|
if (IS_ERR(idev->dev)) {
|
|
|
|
printk(KERN_ERR "UIO: device register failed\n");
|
|
|
|
ret = PTR_ERR(idev->dev);
|
|
|
|
goto err_device_create;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = uio_dev_add_attributes(idev);
|
|
|
|
if (ret)
|
|
|
|
goto err_uio_dev_add_attributes;
|
|
|
|
|
|
|
|
info->uio_dev = idev;
|
|
|
|
|
2010-09-14 12:37:36 -06:00
|
|
|
if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) {
|
|
|
|
ret = request_irq(info->irq, uio_interrupt,
|
|
|
|
info->irq_flags, info->name, idev);
|
2006-12-07 02:58:29 -07:00
|
|
|
if (ret)
|
|
|
|
goto err_request_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_request_irq:
|
|
|
|
uio_dev_del_attributes(idev);
|
|
|
|
err_uio_dev_add_attributes:
|
2010-09-14 12:38:36 -06:00
|
|
|
device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
|
2006-12-07 02:58:29 -07:00
|
|
|
err_device_create:
|
|
|
|
uio_free_minor(idev);
|
|
|
|
err_get_minor:
|
|
|
|
kfree(idev);
|
|
|
|
err_kzalloc:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__uio_register_device);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* uio_unregister_device - unregister a industrial IO device
|
|
|
|
* @info: UIO device capabilities
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void uio_unregister_device(struct uio_info *info)
|
|
|
|
{
|
|
|
|
struct uio_device *idev;
|
|
|
|
|
|
|
|
if (!info || !info->uio_dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
idev = info->uio_dev;
|
|
|
|
|
|
|
|
uio_free_minor(idev);
|
|
|
|
|
2010-09-14 12:37:36 -06:00
|
|
|
if (info->irq && (info->irq != UIO_IRQ_CUSTOM))
|
2006-12-07 02:58:29 -07:00
|
|
|
free_irq(info->irq, idev);
|
|
|
|
|
|
|
|
uio_dev_del_attributes(idev);
|
|
|
|
|
2010-09-14 12:38:36 -06:00
|
|
|
device_destroy(&uio_class, MKDEV(uio_major, idev->minor));
|
2006-12-07 02:58:29 -07:00
|
|
|
kfree(idev);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(uio_unregister_device);
|
|
|
|
|
|
|
|
static int __init uio_init(void)
|
|
|
|
{
|
2010-09-14 12:36:27 -06:00
|
|
|
return init_uio_class();
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit uio_exit(void)
|
|
|
|
{
|
2010-09-14 12:36:27 -06:00
|
|
|
release_uio_class();
|
2006-12-07 02:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(uio_init)
|
|
|
|
module_exit(uio_exit)
|
|
|
|
MODULE_LICENSE("GPL v2");
|