20 #include <linux/device.h>
22 #include <linux/errno.h>
25 #include <linux/kernel.h>
27 #include <linux/module.h>
29 #include <linux/pci.h>
31 #include <linux/slab.h>
34 #include <linux/types.h>
46 static unsigned int bus_num;
82 #define MASTER_MINOR 0
86 #define CONTROL_MINOR 8
88 #define PCI_BUF_SIZE 0x20000
116 static struct cdev *vme_user_cdev;
117 static struct class *vme_user_sysfs_class;
118 static struct vme_dev *vme_user_bridge;
129 static int vme_user_open(
struct inode *,
struct file *);
130 static int vme_user_release(
struct inode *,
struct file *);
131 static ssize_t vme_user_read(
struct file *,
char __user *,
size_t, loff_t *);
132 static ssize_t vme_user_write(
struct file *,
const char __user *,
size_t,
134 static loff_t vme_user_llseek(
struct file *, loff_t,
int);
135 static long vme_user_unlocked_ioctl(
struct file *,
unsigned int,
unsigned long);
137 static int vme_user_match(
struct vme_dev *);
142 .open = vme_user_open,
143 .release = vme_user_release,
144 .read = vme_user_read,
145 .write = vme_user_write,
146 .llseek = vme_user_llseek,
147 .unlocked_ioctl = vme_user_unlocked_ioctl,
154 static void reset_counters(
void)
156 statistics.reads = 0;
157 statistics.writes = 0;
158 statistics.ioctls = 0;
160 statistics.berrs = 0;
161 statistics.dmaErrors = 0;
162 statistics.timeouts = 0;
179 image[minor].users++;
191 static int vme_user_release(
struct inode *inode,
struct file *file)
198 image[minor].users--;
211 static ssize_t resource_to_user(
int minor,
char __user *
buf,
size_t count,
217 if (count <=
image[minor].size_buf) {
220 image[minor].kern_buf, count, *ppos);
225 (
unsigned long)copied);
227 copied = (copied -
retval);
250 static ssize_t resource_from_user(
unsigned int minor,
const char __user *buf,
251 size_t count, loff_t *ppos)
256 if (count <=
image[minor].size_buf) {
258 (
unsigned long)count);
260 copied = (copied -
retval);
265 image[minor].kern_buf, copied, *ppos);
278 static ssize_t buffer_to_user(
unsigned int minor,
char __user *buf,
279 size_t count, loff_t *ppos)
284 image_ptr =
image[minor].kern_buf + *ppos;
288 retval = (count -
retval);
297 static ssize_t buffer_from_user(
unsigned int minor,
const char __user *buf,
298 size_t count, loff_t *ppos)
303 image_ptr =
image[minor].kern_buf + *ppos;
307 retval = (count -
retval);
316 static ssize_t vme_user_read(
struct file *file,
char __user *buf,
size_t count,
319 unsigned int minor =
MINOR(file->f_dentry->d_inode->i_rdev);
333 if ((*ppos < 0) || (*ppos > (image_size - 1))) {
339 if (*ppos + count > image_size)
340 okcount = image_size - *ppos;
344 switch (
type[minor]) {
346 retval = resource_to_user(minor, buf, okcount, ppos);
349 retval = buffer_to_user(minor, buf, okcount, ppos);
362 static ssize_t vme_user_write(
struct file *file,
const char __user *buf,
363 size_t count, loff_t *ppos)
365 unsigned int minor =
MINOR(file->f_dentry->d_inode->i_rdev);
378 if ((*ppos < 0) || (*ppos > (image_size - 1))) {
384 if (*ppos + count > image_size)
385 okcount = image_size - *ppos;
389 switch (
type[minor]) {
391 retval = resource_from_user(minor, buf, okcount, ppos);
394 retval = buffer_from_user(minor, buf, okcount, ppos);
408 static loff_t vme_user_llseek(
struct file *file, loff_t off,
int whence)
411 unsigned int minor =
MINOR(file->f_dentry->d_inode->i_rdev);
425 absolute = file->
f_pos + off;
428 absolute = image_size + off;
436 if ((absolute < 0) || (absolute >= image_size)) {
458 static int vme_user_ioctl(
struct inode *inode,
struct file *file,
459 unsigned int cmd,
unsigned long arg)
464 unsigned long copied;
472 switch (
type[minor]) {
499 &master.enable, &master.vme_addr,
500 &master.size, &master.aspace,
501 &master.cycle, &master.dwidth);
527 master.enable, master.vme_addr, master.size,
528 master.aspace, master.cycle, master.dwidth);
583 vme_user_unlocked_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
588 ret = vme_user_ioctl(file->
f_path.dentry->d_inode, file, cmd, arg);
598 static void buf_unalloc(
int num)
600 if (
image[num].kern_buf) {
610 image[num].pci_buf = 0;
611 image[num].size_buf = 0;
622 .match = vme_user_match,
623 .probe = vme_user_probe,
628 static int __init vme_user_init(
void)
667 static int vme_user_match(
struct vme_dev *vdev)
685 if (vme_user_bridge !=
NULL) {
691 vme_user_bridge = vdev;
717 vme_user_cdev->
ops = &vme_user_fops;
769 "master window buffers\n");
777 if (IS_ERR(vme_user_sysfs_class)) {
779 err = PTR_ERR(vme_user_sysfs_class);
808 err = PTR_ERR(
image[i].device);
885 static void __exit vme_user_exit(
void)