2009-07-31 10:28:17 +02:00
|
|
|
/*
|
|
|
|
* VMEbus User access driver
|
|
|
|
*
|
2010-02-18 16:12:52 +01:00
|
|
|
* Author: Martyn Welch <martyn.welch@ge.com>
|
|
|
|
* Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
|
2009-07-31 10:28:17 +02:00
|
|
|
*
|
|
|
|
* Based on work by:
|
|
|
|
* Tom Armistead and Ajit Prem
|
|
|
|
* Copyright 2004 Motorola Inc.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/semaphore.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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-07-31 10:28:17 +02:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/syscalls.h>
|
2010-07-11 23:18:52 +02:00
|
|
|
#include <linux/mutex.h>
|
2009-07-31 10:28:17 +02:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2010-05-28 12:54:45 +02:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.h>
|
2009-07-31 10:28:17 +02:00
|
|
|
|
|
|
|
#include "../vme.h"
|
|
|
|
#include "vme_user.h"
|
|
|
|
|
2010-07-11 23:18:52 +02:00
|
|
|
static DEFINE_MUTEX(vme_user_mutex);
|
2009-08-11 15:37:15 +02:00
|
|
|
static char driver_name[] = "vme_user";
|
|
|
|
|
|
|
|
static int bus[USER_BUS_MAX];
|
2010-11-12 12:15:21 +01:00
|
|
|
static unsigned int bus_num;
|
2009-08-11 15:37:15 +02:00
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
/* Currently Documentation/devices.txt defines the following for VME:
|
|
|
|
*
|
|
|
|
* 221 char VME bus
|
2010-05-28 12:54:45 +02:00
|
|
|
* 0 = /dev/bus/vme/m0 First master image
|
|
|
|
* 1 = /dev/bus/vme/m1 Second master image
|
|
|
|
* 2 = /dev/bus/vme/m2 Third master image
|
|
|
|
* 3 = /dev/bus/vme/m3 Fourth master image
|
|
|
|
* 4 = /dev/bus/vme/s0 First slave image
|
|
|
|
* 5 = /dev/bus/vme/s1 Second slave image
|
|
|
|
* 6 = /dev/bus/vme/s2 Third slave image
|
|
|
|
* 7 = /dev/bus/vme/s3 Fourth slave image
|
|
|
|
* 8 = /dev/bus/vme/ctl Control
|
2009-07-31 10:28:17 +02:00
|
|
|
*
|
2010-05-28 12:54:45 +02:00
|
|
|
* It is expected that all VME bus drivers will use the
|
|
|
|
* same interface. For interface documentation see
|
|
|
|
* http://www.vmelinux.org/.
|
2009-07-31 10:28:17 +02:00
|
|
|
*
|
|
|
|
* However the VME driver at http://www.vmelinux.org/ is rather old and doesn't
|
|
|
|
* even support the tsi148 chipset (which has 8 master and 8 slave windows).
|
|
|
|
* We'll run with this or now as far as possible, however it probably makes
|
|
|
|
* sense to get rid of the old mappings and just do everything dynamically.
|
|
|
|
*
|
|
|
|
* So for now, we'll restrict the driver to providing 4 masters and 4 slaves as
|
|
|
|
* defined above and try to support at least some of the interface from
|
|
|
|
* http://www.vmelinux.org/ as an alternative drive can be written providing a
|
|
|
|
* saner interface later.
|
2009-08-11 15:37:15 +02:00
|
|
|
*
|
|
|
|
* The vmelinux.org driver never supported slave images, the devices reserved
|
|
|
|
* for slaves were repurposed to support all 8 master images on the UniverseII!
|
|
|
|
* We shall support 4 masters and 4 slaves with this driver.
|
2009-07-31 10:28:17 +02:00
|
|
|
*/
|
|
|
|
#define VME_MAJOR 221 /* VME Major Device Number */
|
|
|
|
#define VME_DEVS 9 /* Number of dev entries */
|
|
|
|
|
|
|
|
#define MASTER_MINOR 0
|
|
|
|
#define MASTER_MAX 3
|
|
|
|
#define SLAVE_MINOR 4
|
|
|
|
#define SLAVE_MAX 7
|
|
|
|
#define CONTROL_MINOR 8
|
|
|
|
|
|
|
|
#define PCI_BUF_SIZE 0x20000 /* Size of one slave image buffer */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure to handle image related parameters.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2010-11-12 12:15:27 +01:00
|
|
|
void *kern_buf; /* Buffer address in kernel space */
|
2009-07-31 10:28:17 +02:00
|
|
|
dma_addr_t pci_buf; /* Buffer address in PCI address space */
|
|
|
|
unsigned long long size_buf; /* Buffer size */
|
|
|
|
struct semaphore sem; /* Semaphore for locking image */
|
|
|
|
struct device *device; /* Sysfs device */
|
|
|
|
struct vme_resource *resource; /* VME resource */
|
|
|
|
int users; /* Number of current users */
|
|
|
|
} image_desc_t;
|
|
|
|
static image_desc_t image[VME_DEVS];
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned long reads;
|
|
|
|
unsigned long writes;
|
|
|
|
unsigned long ioctls;
|
|
|
|
unsigned long irqs;
|
|
|
|
unsigned long berrs;
|
|
|
|
unsigned long dmaErrors;
|
|
|
|
unsigned long timeouts;
|
|
|
|
unsigned long external;
|
|
|
|
} driver_stats_t;
|
|
|
|
static driver_stats_t statistics;
|
|
|
|
|
2010-11-12 12:15:14 +01:00
|
|
|
static struct cdev *vme_user_cdev; /* Character device */
|
|
|
|
static struct class *vme_user_sysfs_class; /* Sysfs class */
|
|
|
|
static struct device *vme_user_bridge; /* Pointer to bridge device */
|
2009-07-31 10:28:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR,
|
|
|
|
MASTER_MINOR, MASTER_MINOR,
|
|
|
|
SLAVE_MINOR, SLAVE_MINOR,
|
|
|
|
SLAVE_MINOR, SLAVE_MINOR,
|
|
|
|
CONTROL_MINOR
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int vme_user_open(struct inode *, struct file *);
|
|
|
|
static int vme_user_release(struct inode *, struct file *);
|
2010-11-12 12:15:34 +01:00
|
|
|
static ssize_t vme_user_read(struct file *, char __user *, size_t, loff_t *);
|
|
|
|
static ssize_t vme_user_write(struct file *, const char __user *, size_t,
|
|
|
|
loff_t *);
|
2009-07-31 10:28:17 +02:00
|
|
|
static loff_t vme_user_llseek(struct file *, loff_t, int);
|
2010-04-27 20:15:07 +02:00
|
|
|
static long vme_user_unlocked_ioctl(struct file *, unsigned int, unsigned long);
|
2009-07-31 10:28:17 +02:00
|
|
|
|
2010-12-03 14:44:15 +01:00
|
|
|
static int __devinit vme_user_probe(struct device *, int, int);
|
|
|
|
static int __devexit vme_user_remove(struct device *, int, int);
|
2009-07-31 10:28:17 +02:00
|
|
|
|
|
|
|
static struct file_operations vme_user_fops = {
|
2010-05-28 12:54:45 +02:00
|
|
|
.open = vme_user_open,
|
|
|
|
.release = vme_user_release,
|
|
|
|
.read = vme_user_read,
|
|
|
|
.write = vme_user_write,
|
|
|
|
.llseek = vme_user_llseek,
|
|
|
|
.unlocked_ioctl = vme_user_unlocked_ioctl,
|
2009-07-31 10:28:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset all the statistic counters
|
|
|
|
*/
|
|
|
|
static void reset_counters(void)
|
|
|
|
{
|
2010-05-28 12:54:45 +02:00
|
|
|
statistics.reads = 0;
|
|
|
|
statistics.writes = 0;
|
|
|
|
statistics.ioctls = 0;
|
|
|
|
statistics.irqs = 0;
|
|
|
|
statistics.berrs = 0;
|
|
|
|
statistics.dmaErrors = 0;
|
|
|
|
statistics.timeouts = 0;
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vme_user_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
unsigned int minor = MINOR(inode->i_rdev);
|
|
|
|
|
|
|
|
down(&image[minor].sem);
|
|
|
|
/* Only allow device to be opened if a resource is allocated */
|
|
|
|
if (image[minor].resource == NULL) {
|
|
|
|
printk(KERN_ERR "No resources allocated for device\n");
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment user count */
|
|
|
|
image[minor].users++;
|
|
|
|
|
|
|
|
up(&image[minor].sem);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_res:
|
|
|
|
up(&image[minor].sem);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vme_user_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
unsigned int minor = MINOR(inode->i_rdev);
|
|
|
|
|
|
|
|
down(&image[minor].sem);
|
|
|
|
|
|
|
|
/* Decrement user count */
|
|
|
|
image[minor].users--;
|
|
|
|
|
|
|
|
up(&image[minor].sem);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are going ot alloc a page during init per window for small transfers.
|
|
|
|
* Small transfers will go VME -> buffer -> user space. Larger (more than a
|
|
|
|
* page) transfers will lock the user space buffer into memory and then
|
|
|
|
* transfer the data directly into the user space buffers.
|
|
|
|
*/
|
|
|
|
static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
ssize_t retval;
|
|
|
|
ssize_t copied = 0;
|
|
|
|
|
|
|
|
if (count <= image[minor].size_buf) {
|
|
|
|
/* We copy to kernel buffer */
|
|
|
|
copied = vme_master_read(image[minor].resource,
|
|
|
|
image[minor].kern_buf, count, *ppos);
|
2010-05-28 12:54:45 +02:00
|
|
|
if (copied < 0)
|
2009-07-31 10:28:17 +02:00
|
|
|
return (int)copied;
|
|
|
|
|
|
|
|
retval = __copy_to_user(buf, image[minor].kern_buf,
|
|
|
|
(unsigned long)copied);
|
|
|
|
if (retval != 0) {
|
|
|
|
copied = (copied - retval);
|
2010-05-28 12:54:45 +02:00
|
|
|
printk(KERN_INFO "User copy failed\n");
|
2009-07-31 10:28:17 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* XXX Need to write this */
|
2010-05-28 12:54:45 +02:00
|
|
|
printk(KERN_INFO "Currently don't support large transfers\n");
|
2009-07-31 10:28:17 +02:00
|
|
|
/* Map in pages from userspace */
|
|
|
|
|
|
|
|
/* Call vme_master_read to do the transfer */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are going ot alloc a page during init per window for small transfers.
|
|
|
|
* Small transfers will go user space -> buffer -> VME. Larger (more than a
|
|
|
|
* page) transfers will lock the user space buffer into memory and then
|
|
|
|
* transfer the data directly from the user space buffers out to VME.
|
|
|
|
*/
|
2010-11-12 12:15:34 +01:00
|
|
|
static ssize_t resource_from_user(unsigned int minor, const char __user *buf,
|
2009-07-31 10:28:17 +02:00
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
ssize_t retval;
|
|
|
|
ssize_t copied = 0;
|
|
|
|
|
|
|
|
if (count <= image[minor].size_buf) {
|
|
|
|
retval = __copy_from_user(image[minor].kern_buf, buf,
|
|
|
|
(unsigned long)count);
|
|
|
|
if (retval != 0)
|
|
|
|
copied = (copied - retval);
|
|
|
|
else
|
|
|
|
copied = count;
|
|
|
|
|
|
|
|
copied = vme_master_write(image[minor].resource,
|
|
|
|
image[minor].kern_buf, copied, *ppos);
|
|
|
|
} else {
|
|
|
|
/* XXX Need to write this */
|
2010-05-28 12:54:45 +02:00
|
|
|
printk(KERN_INFO "Currently don't support large transfers\n");
|
2009-07-31 10:28:17 +02:00
|
|
|
/* Map in pages from userspace */
|
|
|
|
|
|
|
|
/* Call vme_master_write to do the transfer */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2010-11-12 12:15:27 +01:00
|
|
|
void *image_ptr;
|
2009-07-31 10:28:17 +02:00
|
|
|
ssize_t retval;
|
|
|
|
|
|
|
|
image_ptr = image[minor].kern_buf + *ppos;
|
|
|
|
|
|
|
|
retval = __copy_to_user(buf, image_ptr, (unsigned long)count);
|
|
|
|
if (retval != 0) {
|
|
|
|
retval = (count - retval);
|
|
|
|
printk(KERN_WARNING "Partial copy to userspace\n");
|
|
|
|
} else
|
|
|
|
retval = count;
|
|
|
|
|
|
|
|
/* Return number of bytes successfully read */
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
|
2009-07-31 10:28:17 +02:00
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2010-11-12 12:15:27 +01:00
|
|
|
void *image_ptr;
|
2009-07-31 10:28:17 +02:00
|
|
|
size_t retval;
|
|
|
|
|
|
|
|
image_ptr = image[minor].kern_buf + *ppos;
|
|
|
|
|
|
|
|
retval = __copy_from_user(image_ptr, buf, (unsigned long)count);
|
|
|
|
if (retval != 0) {
|
|
|
|
retval = (count - retval);
|
|
|
|
printk(KERN_WARNING "Partial copy to userspace\n");
|
|
|
|
} else
|
|
|
|
retval = count;
|
|
|
|
|
|
|
|
/* Return number of bytes successfully read */
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
|
2010-05-28 12:54:45 +02:00
|
|
|
loff_t *ppos)
|
2009-07-31 10:28:17 +02:00
|
|
|
{
|
|
|
|
unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
|
|
|
|
ssize_t retval;
|
|
|
|
size_t image_size;
|
|
|
|
size_t okcount;
|
|
|
|
|
|
|
|
down(&image[minor].sem);
|
|
|
|
|
|
|
|
/* XXX Do we *really* want this helper - we can use vme_*_get ? */
|
|
|
|
image_size = vme_get_size(image[minor].resource);
|
|
|
|
|
|
|
|
/* Ensure we are starting at a valid location */
|
|
|
|
if ((*ppos < 0) || (*ppos > (image_size - 1))) {
|
|
|
|
up(&image[minor].sem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure not reading past end of the image */
|
|
|
|
if (*ppos + count > image_size)
|
|
|
|
okcount = image_size - *ppos;
|
|
|
|
else
|
|
|
|
okcount = count;
|
|
|
|
|
2010-05-28 12:54:45 +02:00
|
|
|
switch (type[minor]) {
|
2009-07-31 10:28:17 +02:00
|
|
|
case MASTER_MINOR:
|
|
|
|
retval = resource_to_user(minor, buf, okcount, ppos);
|
|
|
|
break;
|
|
|
|
case SLAVE_MINOR:
|
|
|
|
retval = buffer_to_user(minor, buf, okcount, ppos);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
retval = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
up(&image[minor].sem);
|
|
|
|
|
|
|
|
if (retval > 0)
|
|
|
|
*ppos += retval;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
static ssize_t vme_user_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
2009-07-31 10:28:17 +02:00
|
|
|
{
|
|
|
|
unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
|
|
|
|
ssize_t retval;
|
|
|
|
size_t image_size;
|
|
|
|
size_t okcount;
|
|
|
|
|
|
|
|
down(&image[minor].sem);
|
|
|
|
|
|
|
|
image_size = vme_get_size(image[minor].resource);
|
|
|
|
|
|
|
|
/* Ensure we are starting at a valid location */
|
|
|
|
if ((*ppos < 0) || (*ppos > (image_size - 1))) {
|
|
|
|
up(&image[minor].sem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure not reading past end of the image */
|
|
|
|
if (*ppos + count > image_size)
|
|
|
|
okcount = image_size - *ppos;
|
|
|
|
else
|
|
|
|
okcount = count;
|
|
|
|
|
2010-05-28 12:54:45 +02:00
|
|
|
switch (type[minor]) {
|
2009-07-31 10:28:17 +02:00
|
|
|
case MASTER_MINOR:
|
|
|
|
retval = resource_from_user(minor, buf, okcount, ppos);
|
|
|
|
break;
|
|
|
|
case SLAVE_MINOR:
|
|
|
|
retval = buffer_from_user(minor, buf, okcount, ppos);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
retval = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
up(&image[minor].sem);
|
|
|
|
|
|
|
|
if (retval > 0)
|
|
|
|
*ppos += retval;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static loff_t vme_user_llseek(struct file *file, loff_t off, int whence)
|
|
|
|
{
|
2010-02-16 15:40:30 +01:00
|
|
|
loff_t absolute = -1;
|
|
|
|
unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
|
|
|
|
size_t image_size;
|
|
|
|
|
|
|
|
down(&image[minor].sem);
|
|
|
|
image_size = vme_get_size(image[minor].resource);
|
|
|
|
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
absolute = off;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
absolute = file->f_pos + off;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
absolute = image_size + off;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
up(&image[minor].sem);
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((absolute < 0) || (absolute >= image_size)) {
|
|
|
|
up(&image[minor].sem);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->f_pos = absolute;
|
|
|
|
|
|
|
|
up(&image[minor].sem);
|
|
|
|
|
|
|
|
return absolute;
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
/*
|
|
|
|
* The ioctls provided by the old VME access method (the one at vmelinux.org)
|
|
|
|
* are most certainly wrong as the effectively push the registers layout
|
|
|
|
* through to user space. Given that the VME core can handle multiple bridges,
|
|
|
|
* with different register layouts this is most certainly not the way to go.
|
|
|
|
*
|
|
|
|
* We aren't using the structures defined in the Motorola driver either - these
|
|
|
|
* are also quite low level, however we should use the definitions that have
|
|
|
|
* already been defined.
|
|
|
|
*/
|
2009-07-31 10:28:17 +02:00
|
|
|
static int vme_user_ioctl(struct inode *inode, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2009-08-11 15:37:15 +02:00
|
|
|
struct vme_master master;
|
|
|
|
struct vme_slave slave;
|
|
|
|
unsigned long copied;
|
2009-07-31 10:28:17 +02:00
|
|
|
unsigned int minor = MINOR(inode->i_rdev);
|
2009-08-11 15:37:15 +02:00
|
|
|
int retval;
|
|
|
|
dma_addr_t pci_addr;
|
2010-11-12 12:15:34 +01:00
|
|
|
void __user *argp = (void __user *)arg;
|
2009-07-31 10:28:17 +02:00
|
|
|
|
|
|
|
statistics.ioctls++;
|
2009-08-11 15:37:15 +02:00
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
switch (type[minor]) {
|
|
|
|
case CONTROL_MINOR:
|
|
|
|
break;
|
|
|
|
case MASTER_MINOR:
|
|
|
|
switch (cmd) {
|
2009-08-11 15:37:15 +02:00
|
|
|
case VME_GET_MASTER:
|
|
|
|
memset(&master, 0, sizeof(struct vme_master));
|
|
|
|
|
|
|
|
/* XXX We do not want to push aspace, cycle and width
|
|
|
|
* to userspace as they are
|
|
|
|
*/
|
|
|
|
retval = vme_master_get(image[minor].resource,
|
2010-11-12 12:14:07 +01:00
|
|
|
&master.enable, &master.vme_addr,
|
|
|
|
&master.size, &master.aspace,
|
|
|
|
&master.cycle, &master.dwidth);
|
2009-08-11 15:37:15 +02:00
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
copied = copy_to_user(argp, &master,
|
2009-08-11 15:37:15 +02:00
|
|
|
sizeof(struct vme_master));
|
|
|
|
if (copied != 0) {
|
|
|
|
printk(KERN_WARNING "Partial copy to "
|
|
|
|
"userspace\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2009-07-31 10:28:17 +02:00
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
return retval;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VME_SET_MASTER:
|
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
copied = copy_from_user(&master, argp, sizeof(master));
|
2009-08-11 15:37:15 +02:00
|
|
|
if (copied != 0) {
|
2009-07-31 10:28:17 +02:00
|
|
|
printk(KERN_WARNING "Partial copy from "
|
|
|
|
"userspace\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
/* XXX We do not want to push aspace, cycle and width
|
|
|
|
* to userspace as they are
|
|
|
|
*/
|
|
|
|
return vme_master_set(image[minor].resource,
|
|
|
|
master.enable, master.vme_addr, master.size,
|
|
|
|
master.aspace, master.cycle, master.dwidth);
|
2009-07-31 10:28:17 +02:00
|
|
|
|
|
|
|
break;
|
2009-08-11 15:37:15 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SLAVE_MINOR:
|
|
|
|
switch (cmd) {
|
2009-07-31 10:28:17 +02:00
|
|
|
case VME_GET_SLAVE:
|
2009-08-11 15:37:15 +02:00
|
|
|
memset(&slave, 0, sizeof(struct vme_slave));
|
|
|
|
|
|
|
|
/* XXX We do not want to push aspace, cycle and width
|
|
|
|
* to userspace as they are
|
|
|
|
*/
|
|
|
|
retval = vme_slave_get(image[minor].resource,
|
2010-11-12 12:14:07 +01:00
|
|
|
&slave.enable, &slave.vme_addr,
|
|
|
|
&slave.size, &pci_addr, &slave.aspace,
|
|
|
|
&slave.cycle);
|
2009-08-11 15:37:15 +02:00
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
copied = copy_to_user(argp, &slave,
|
2009-08-11 15:37:15 +02:00
|
|
|
sizeof(struct vme_slave));
|
|
|
|
if (copied != 0) {
|
|
|
|
printk(KERN_WARNING "Partial copy to "
|
|
|
|
"userspace\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
break;
|
2009-07-31 10:28:17 +02:00
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
case VME_SET_SLAVE:
|
2009-07-31 10:28:17 +02:00
|
|
|
|
2010-11-12 12:15:34 +01:00
|
|
|
copied = copy_from_user(&slave, argp, sizeof(slave));
|
2009-08-11 15:37:15 +02:00
|
|
|
if (copied != 0) {
|
|
|
|
printk(KERN_WARNING "Partial copy from "
|
2009-07-31 10:28:17 +02:00
|
|
|
"userspace\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
/* XXX We do not want to push aspace, cycle and width
|
|
|
|
* to userspace as they are
|
|
|
|
*/
|
|
|
|
return vme_slave_set(image[minor].resource,
|
|
|
|
slave.enable, slave.vme_addr, slave.size,
|
|
|
|
image[minor].pci_buf, slave.aspace,
|
|
|
|
slave.cycle);
|
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-04-27 20:15:07 +02:00
|
|
|
static long
|
|
|
|
vme_user_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-07-11 23:18:52 +02:00
|
|
|
mutex_lock(&vme_user_mutex);
|
2010-04-27 20:15:07 +02:00
|
|
|
ret = vme_user_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
|
2010-07-11 23:18:52 +02:00
|
|
|
mutex_unlock(&vme_user_mutex);
|
2010-04-27 20:15:07 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unallocate a previously allocated buffer
|
|
|
|
*/
|
2010-05-28 12:54:45 +02:00
|
|
|
static void buf_unalloc(int num)
|
2009-07-31 10:28:17 +02:00
|
|
|
{
|
|
|
|
if (image[num].kern_buf) {
|
|
|
|
#ifdef VME_DEBUG
|
|
|
|
printk(KERN_DEBUG "UniverseII:Releasing buffer at %p\n",
|
|
|
|
image[num].pci_buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vme_free_consistent(image[num].resource, image[num].size_buf,
|
|
|
|
image[num].kern_buf, image[num].pci_buf);
|
|
|
|
|
|
|
|
image[num].kern_buf = NULL;
|
|
|
|
image[num].pci_buf = 0;
|
|
|
|
image[num].size_buf = 0;
|
|
|
|
|
|
|
|
#ifdef VME_DEBUG
|
|
|
|
} else {
|
|
|
|
printk(KERN_DEBUG "UniverseII: Buffer not allocated\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vme_driver vme_user_driver = {
|
2010-05-28 12:54:45 +02:00
|
|
|
.name = driver_name,
|
|
|
|
.probe = vme_user_probe,
|
2010-12-03 14:44:15 +01:00
|
|
|
.remove = __devexit_p(vme_user_remove),
|
2009-07-31 10:28:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
static int __init vme_user_init(void)
|
2009-07-31 10:28:17 +02:00
|
|
|
{
|
2009-08-11 15:37:15 +02:00
|
|
|
int retval = 0;
|
|
|
|
int i;
|
|
|
|
struct vme_device_id *ids;
|
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
printk(KERN_INFO "VME User Space Access Driver\n");
|
2009-08-11 15:37:15 +02:00
|
|
|
|
|
|
|
if (bus_num == 0) {
|
|
|
|
printk(KERN_ERR "%s: No cards, skipping registration\n",
|
|
|
|
driver_name);
|
2010-11-12 12:14:14 +01:00
|
|
|
retval = -ENODEV;
|
2009-08-11 15:37:15 +02:00
|
|
|
goto err_nocard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Let's start by supporting one bus, we can support more than one
|
|
|
|
* in future revisions if that ever becomes necessary.
|
|
|
|
*/
|
|
|
|
if (bus_num > USER_BUS_MAX) {
|
2009-12-15 09:42:43 +01:00
|
|
|
printk(KERN_ERR "%s: Driver only able to handle %d buses\n",
|
|
|
|
driver_name, USER_BUS_MAX);
|
2009-08-11 15:37:15 +02:00
|
|
|
bus_num = USER_BUS_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Dynamically create the bind table based on module parameters */
|
|
|
|
ids = kmalloc(sizeof(struct vme_device_id) * (bus_num + 1), GFP_KERNEL);
|
|
|
|
if (ids == NULL) {
|
|
|
|
printk(KERN_ERR "%s: Unable to allocate ID table\n",
|
|
|
|
driver_name);
|
2010-11-12 12:14:14 +01:00
|
|
|
retval = -ENOMEM;
|
2009-08-11 15:37:15 +02:00
|
|
|
goto err_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(ids, 0, (sizeof(struct vme_device_id) * (bus_num + 1)));
|
|
|
|
|
|
|
|
for (i = 0; i < bus_num; i++) {
|
|
|
|
ids[i].bus = bus[i];
|
|
|
|
/*
|
|
|
|
* We register the driver against the slot occupied by *this*
|
|
|
|
* card, since it's really a low level way of controlling
|
|
|
|
* the VME bridge
|
|
|
|
*/
|
|
|
|
ids[i].slot = VME_SLOT_CURRENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
vme_user_driver.bind_table = ids;
|
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
retval = vme_register_driver(&vme_user_driver);
|
2009-08-11 15:37:15 +02:00
|
|
|
if (retval != 0)
|
|
|
|
goto err_reg;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
err_reg:
|
|
|
|
kfree(ids);
|
|
|
|
err_id:
|
|
|
|
err_nocard:
|
2009-07-31 10:28:17 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-08-11 15:37:15 +02:00
|
|
|
* In this simple access driver, the old behaviour is being preserved as much
|
|
|
|
* as practical. We will therefore reserve the buffers and request the images
|
|
|
|
* here so that we don't have to do it later.
|
2009-07-31 10:28:17 +02:00
|
|
|
*/
|
2010-12-03 14:44:15 +01:00
|
|
|
static int __devinit vme_user_probe(struct device *dev, int cur_bus,
|
|
|
|
int cur_slot)
|
2009-07-31 10:28:17 +02:00
|
|
|
{
|
|
|
|
int i, err;
|
2009-10-29 17:34:48 +01:00
|
|
|
char name[12];
|
2009-07-31 10:28:17 +02:00
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
/* Save pointer to the bridge device */
|
|
|
|
if (vme_user_bridge != NULL) {
|
|
|
|
printk(KERN_ERR "%s: Driver can only be loaded for 1 device\n",
|
|
|
|
driver_name);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_dev;
|
|
|
|
}
|
2009-07-31 10:28:17 +02:00
|
|
|
vme_user_bridge = dev;
|
|
|
|
|
|
|
|
/* Initialise descriptors */
|
|
|
|
for (i = 0; i < VME_DEVS; i++) {
|
|
|
|
image[i].kern_buf = NULL;
|
|
|
|
image[i].pci_buf = 0;
|
2010-11-12 12:14:07 +01:00
|
|
|
sema_init(&image[i].sem, 1);
|
2009-07-31 10:28:17 +02:00
|
|
|
image[i].device = NULL;
|
|
|
|
image[i].resource = NULL;
|
|
|
|
image[i].users = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialise statistics counters */
|
|
|
|
reset_counters();
|
|
|
|
|
|
|
|
/* Assign major and minor numbers for the driver */
|
|
|
|
err = register_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS,
|
|
|
|
driver_name);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_WARNING "%s: Error getting Major Number %d for "
|
|
|
|
"driver.\n", driver_name, VME_MAJOR);
|
|
|
|
goto err_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the driver as a char device */
|
|
|
|
vme_user_cdev = cdev_alloc();
|
|
|
|
vme_user_cdev->ops = &vme_user_fops;
|
|
|
|
vme_user_cdev->owner = THIS_MODULE;
|
|
|
|
err = cdev_add(vme_user_cdev, MKDEV(VME_MAJOR, 0), VME_DEVS);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_WARNING "%s: cdev_all failed\n", driver_name);
|
|
|
|
goto err_char;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request slave resources and allocate buffers (128kB wide) */
|
|
|
|
for (i = SLAVE_MINOR; i < (SLAVE_MAX + 1); i++) {
|
|
|
|
/* XXX Need to properly request attributes */
|
2010-02-16 15:40:58 +01:00
|
|
|
/* For ca91cx42 bridge there are only two slave windows
|
|
|
|
* supporting A16 addressing, so we request A24 supported
|
|
|
|
* by all windows.
|
|
|
|
*/
|
2009-07-31 10:28:17 +02:00
|
|
|
image[i].resource = vme_slave_request(vme_user_bridge,
|
2010-02-16 15:40:58 +01:00
|
|
|
VME_A24, VME_SCT);
|
2009-07-31 10:28:17 +02:00
|
|
|
if (image[i].resource == NULL) {
|
|
|
|
printk(KERN_WARNING "Unable to allocate slave "
|
|
|
|
"resource\n");
|
2009-08-11 15:37:15 +02:00
|
|
|
goto err_slave;
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
image[i].size_buf = PCI_BUF_SIZE;
|
|
|
|
image[i].kern_buf = vme_alloc_consistent(image[i].resource,
|
2010-11-12 12:14:07 +01:00
|
|
|
image[i].size_buf, &image[i].pci_buf);
|
2009-07-31 10:28:17 +02:00
|
|
|
if (image[i].kern_buf == NULL) {
|
|
|
|
printk(KERN_WARNING "Unable to allocate memory for "
|
|
|
|
"buffer\n");
|
|
|
|
image[i].pci_buf = 0;
|
|
|
|
vme_slave_free(image[i].resource);
|
|
|
|
err = -ENOMEM;
|
2009-08-11 15:37:15 +02:00
|
|
|
goto err_slave;
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request master resources allocate page sized buffers for small
|
|
|
|
* reads and writes
|
|
|
|
*/
|
|
|
|
for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) {
|
|
|
|
/* XXX Need to properly request attributes */
|
|
|
|
image[i].resource = vme_master_request(vme_user_bridge,
|
|
|
|
VME_A32, VME_SCT, VME_D32);
|
|
|
|
if (image[i].resource == NULL) {
|
|
|
|
printk(KERN_WARNING "Unable to allocate master "
|
|
|
|
"resource\n");
|
2009-08-11 15:37:15 +02:00
|
|
|
goto err_master;
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
2010-02-16 15:41:21 +01:00
|
|
|
image[i].size_buf = PCI_BUF_SIZE;
|
|
|
|
image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL);
|
|
|
|
if (image[i].kern_buf == NULL) {
|
|
|
|
printk(KERN_WARNING "Unable to allocate memory for "
|
|
|
|
"master window buffers\n");
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_master_buf;
|
|
|
|
}
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create sysfs entries - on udev systems this creates the dev files */
|
|
|
|
vme_user_sysfs_class = class_create(THIS_MODULE, driver_name);
|
|
|
|
if (IS_ERR(vme_user_sysfs_class)) {
|
|
|
|
printk(KERN_ERR "Error creating vme_user class.\n");
|
|
|
|
err = PTR_ERR(vme_user_sysfs_class);
|
|
|
|
goto err_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add sysfs Entries */
|
2010-05-28 12:54:45 +02:00
|
|
|
for (i = 0; i < VME_DEVS; i++) {
|
2009-07-31 10:28:17 +02:00
|
|
|
switch (type[i]) {
|
|
|
|
case MASTER_MINOR:
|
2010-05-28 12:54:45 +02:00
|
|
|
sprintf(name, "bus/vme/m%%d");
|
2009-07-31 10:28:17 +02:00
|
|
|
break;
|
|
|
|
case CONTROL_MINOR:
|
2010-05-28 12:54:45 +02:00
|
|
|
sprintf(name, "bus/vme/ctl");
|
2009-07-31 10:28:17 +02:00
|
|
|
break;
|
|
|
|
case SLAVE_MINOR:
|
2010-05-28 12:54:45 +02:00
|
|
|
sprintf(name, "bus/vme/s%%d");
|
2009-07-31 10:28:17 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_sysfs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
image[i].device =
|
|
|
|
device_create(vme_user_sysfs_class, NULL,
|
|
|
|
MKDEV(VME_MAJOR, i), NULL, name,
|
2010-05-28 12:54:45 +02:00
|
|
|
(type[i] == SLAVE_MINOR) ? i - (MASTER_MAX + 1) : i);
|
2009-07-31 10:28:17 +02:00
|
|
|
if (IS_ERR(image[i].device)) {
|
2010-05-28 12:54:45 +02:00
|
|
|
printk(KERN_INFO "%s: Error creating sysfs device\n",
|
2009-07-31 10:28:17 +02:00
|
|
|
driver_name);
|
|
|
|
err = PTR_ERR(image[i].device);
|
|
|
|
goto err_sysfs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Ensure counter set correcty to destroy all sysfs devices */
|
|
|
|
i = VME_DEVS;
|
|
|
|
err_sysfs:
|
2010-05-28 12:54:45 +02:00
|
|
|
while (i > 0) {
|
2009-07-31 10:28:17 +02:00
|
|
|
i--;
|
|
|
|
device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i));
|
|
|
|
}
|
|
|
|
class_destroy(vme_user_sysfs_class);
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
/* Ensure counter set correcty to unalloc all master windows */
|
|
|
|
i = MASTER_MAX + 1;
|
2010-02-16 15:41:21 +01:00
|
|
|
err_master_buf:
|
|
|
|
for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++)
|
|
|
|
kfree(image[i].kern_buf);
|
2009-08-11 15:37:15 +02:00
|
|
|
err_master:
|
|
|
|
while (i > MASTER_MINOR) {
|
|
|
|
i--;
|
|
|
|
vme_master_free(image[i].resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure counter set correcty to unalloc all slave windows and buffers
|
|
|
|
*/
|
2009-07-31 10:28:17 +02:00
|
|
|
i = SLAVE_MAX + 1;
|
2009-08-11 15:37:15 +02:00
|
|
|
err_slave:
|
|
|
|
while (i > SLAVE_MINOR) {
|
2009-07-31 10:28:17 +02:00
|
|
|
i--;
|
|
|
|
buf_unalloc(i);
|
2010-12-03 10:05:08 +01:00
|
|
|
vme_slave_free(image[i].resource);
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
err_class:
|
|
|
|
cdev_del(vme_user_cdev);
|
|
|
|
err_char:
|
|
|
|
unregister_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS);
|
|
|
|
err_region:
|
2009-08-11 15:37:15 +02:00
|
|
|
err_dev:
|
2009-07-31 10:28:17 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-12-03 14:44:15 +01:00
|
|
|
static int __devexit vme_user_remove(struct device *dev, int cur_bus,
|
|
|
|
int cur_slot)
|
2009-07-31 10:28:17 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Remove sysfs Entries */
|
2010-05-28 12:54:45 +02:00
|
|
|
for (i = 0; i < VME_DEVS; i++)
|
2009-07-31 10:28:17 +02:00
|
|
|
device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i));
|
|
|
|
class_destroy(vme_user_sysfs_class);
|
|
|
|
|
2010-12-03 15:20:51 +01:00
|
|
|
for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) {
|
2010-02-16 15:41:21 +01:00
|
|
|
kfree(image[i].kern_buf);
|
2010-12-03 15:20:51 +01:00
|
|
|
vme_master_free(image[i].resource);
|
|
|
|
}
|
2010-02-16 15:41:21 +01:00
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
for (i = SLAVE_MINOR; i < (SLAVE_MAX + 1); i++) {
|
2009-08-11 15:37:15 +02:00
|
|
|
vme_slave_set(image[i].resource, 0, 0, 0, 0, VME_A32, 0);
|
2009-07-31 10:28:17 +02:00
|
|
|
buf_unalloc(i);
|
2010-12-03 10:05:08 +01:00
|
|
|
vme_slave_free(image[i].resource);
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unregister device driver */
|
|
|
|
cdev_del(vme_user_cdev);
|
|
|
|
|
|
|
|
/* Unregiser the major and minor device numbers */
|
|
|
|
unregister_chrdev_region(MKDEV(VME_MAJOR, 0), VME_DEVS);
|
2009-08-11 15:37:15 +02:00
|
|
|
|
|
|
|
return 0;
|
2009-07-31 10:28:17 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
static void __exit vme_user_exit(void)
|
|
|
|
{
|
|
|
|
vme_unregister_driver(&vme_user_driver);
|
|
|
|
|
|
|
|
kfree(vme_user_driver.bind_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(bus, "Enumeration of VMEbus to which the driver is connected");
|
|
|
|
module_param_array(bus, int, &bus_num, 0);
|
|
|
|
|
2009-07-31 10:28:17 +02:00
|
|
|
MODULE_DESCRIPTION("VME User Space Access Driver");
|
2010-02-18 16:12:52 +01:00
|
|
|
MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
|
2009-07-31 10:28:17 +02:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-08-11 15:37:15 +02:00
|
|
|
module_init(vme_user_init);
|
|
|
|
module_exit(vme_user_exit);
|