fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / sbus / char / vfc_dev.c
index 87d9928..386e7de 100644 (file)
@@ -137,7 +137,6 @@ int init_vfc_devstruct(struct vfc_dev *dev, int instance)
        dev->instance=instance;
        init_MUTEX(&dev->device_lock_sem);
        dev->control_reg=0;
-       init_waitqueue_head(&dev->poll_wait);
        dev->busy=0;
        return 0;
 }
@@ -150,7 +149,7 @@ int init_vfc_device(struct sbus_dev *sdev,struct vfc_dev *dev, int instance)
        }
        printk("Initializing vfc%d\n",instance);
        dev->regs = NULL;
-       dev->regs = (volatile struct vfc_regs *)
+       dev->regs = (volatile struct vfc_regs __iomem *)
                sbus_ioremap(&sdev->resource[0], 0,
                             sizeof(struct vfc_regs), vfcstr);
        dev->which_io = sdev->reg_addrs[0].which_io;
@@ -165,10 +164,6 @@ int init_vfc_device(struct sbus_dev *sdev,struct vfc_dev *dev, int instance)
                return -EINVAL;
        if (init_vfc_hw(dev))
                return -EIO;
-
-       devfs_mk_cdev(MKDEV(VFC_MAJOR, instance),
-                       S_IFCHR | S_IRUSR | S_IWUSR,
-                       "vfc/%d", instance);
        return 0;
 }
 
@@ -178,7 +173,7 @@ struct vfc_dev *vfc_get_dev_ptr(int instance)
        return vfc_dev_lst[instance];
 }
 
-static spinlock_t vfc_dev_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(vfc_dev_lock);
 
 static int vfc_open(struct inode *inode, struct file *file) 
 {
@@ -226,7 +221,7 @@ static int vfc_release(struct inode *inode,struct file *file)
        return 0;
 }
 
-static int vfc_debug(struct vfc_dev *dev, int cmd, unsigned long arg) 
+static int vfc_debug(struct vfc_dev *dev, int cmd, void __user *argp)
 {
        struct vfc_debug_inout inout;
        unsigned char *buffer;
@@ -236,15 +231,14 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, unsigned long arg)
 
        switch(cmd) {
        case VFC_I2C_SEND:
-               if(copy_from_user(&inout, (void *)arg, sizeof(inout)))
+               if(copy_from_user(&inout, argp, sizeof(inout)))
                        return -EFAULT;
 
-               buffer = kmalloc(inout.len*sizeof(char), GFP_KERNEL);
+               buffer = kmalloc(inout.len, GFP_KERNEL);
                if (buffer == NULL)
                        return -ENOMEM;
 
-               if(copy_from_user(buffer, inout.buffer, 
-                                 inout.len*sizeof(char))) {
+               if(copy_from_user(buffer, inout.buffer, inout.len)) {
                        kfree(buffer);
                        return -EFAULT;
                }
@@ -253,9 +247,9 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, unsigned long arg)
                vfc_lock_device(dev);
                inout.ret=
                        vfc_i2c_sendbuf(dev,inout.addr & 0xff,
-                                       inout.buffer,inout.len);
+                                       buffer,inout.len);
 
-               if (copy_to_user((void *)arg,&inout,sizeof(inout))) {
+               if (copy_to_user(argp,&inout,sizeof(inout))) {
                        kfree(buffer);
                        return -EFAULT;
                }
@@ -263,14 +257,14 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, unsigned long arg)
 
                break;
        case VFC_I2C_RECV:
-               if (copy_from_user(&inout, (void *)arg, sizeof(inout)))
+               if (copy_from_user(&inout, argp, sizeof(inout)))
                        return -EFAULT;
 
                buffer = kmalloc(inout.len, GFP_KERNEL);
                if (buffer == NULL)
                        return -ENOMEM;
 
-               memset(buffer,0,inout.len*sizeof(char));
+               memset(buffer,0,inout.len);
                vfc_lock_device(dev);
                inout.ret=
                        vfc_i2c_recvbuf(dev,inout.addr & 0xff
@@ -281,7 +275,7 @@ static int vfc_debug(struct vfc_dev *dev, int cmd, unsigned long arg)
                        kfree(buffer);
                        return -EFAULT;
                }
-               if (copy_to_user((void *)arg,&inout,sizeof(inout))) {
+               if (copy_to_user(argp,&inout,sizeof(inout))) {
                        kfree(buffer);
                        return -EFAULT;
                }
@@ -321,7 +315,7 @@ int vfc_capture_poll(struct vfc_dev *dev)
        int timeout = 1000;
 
        while (!timeout--) {
-               if (dev->regs->control & VFC_STATUS_CAPTURE)
+               if (sbus_readl(&dev->regs->control) & VFC_STATUS_CAPTURE)
                        break;
                vfc_i2c_delay_no_busy(dev, 100);
        }
@@ -340,7 +334,7 @@ static int vfc_set_control_ioctl(struct inode *inode, struct file *file,
 {
        int setcmd, ret = 0;
 
-       if (copy_from_user(&setcmd,(void *)arg,sizeof(unsigned int)))
+       if (copy_from_user(&setcmd,(void __user *)arg,sizeof(unsigned int)))
                return -EFAULT;
 
        VFC_IOCTL_DEBUG_PRINTK(("vfc%d: IOCTL(VFCSCTRL) arg=0x%x\n",
@@ -398,7 +392,7 @@ int vfc_port_change_ioctl(struct inode *inode, struct file *file,
        int ret = 0;
        int cmd;
 
-       if(copy_from_user(&cmd, (void *)arg, sizeof(unsigned int))) {
+       if(copy_from_user(&cmd, (void __user *)arg, sizeof(unsigned int))) {
                VFC_IOCTL_DEBUG_PRINTK(("vfc%d: User passed bogus pointer to "
                                        "vfc_port_change_ioctl\n",
                                        dev->instance));
@@ -468,7 +462,7 @@ int vfc_set_video_ioctl(struct inode *inode, struct file *file,
        int ret = 0;
        int cmd;
 
-       if(copy_from_user(&cmd, (void *)arg, sizeof(unsigned int))) {
+       if(copy_from_user(&cmd, (void __user *)arg, sizeof(unsigned int))) {
                VFC_IOCTL_DEBUG_PRINTK(("vfc%d: User passed bogus pointer to "
                                        "vfc_set_video_ioctl\n",
                                        dev->instance));
@@ -542,7 +536,7 @@ int vfc_get_video_ioctl(struct inode *inode, struct file *file,
        VFC_IOCTL_DEBUG_PRINTK(("vfc%d: IOCTL(VFCGVID) returning status 0x%x; "
                                "buf[0]=%x\n", dev->instance, status, buf[0]));
 
-       if (copy_to_user((void *)arg,&status,sizeof(unsigned int))) {
+       if (copy_to_user((void __user *)arg,&status,sizeof(unsigned int))) {
                VFC_IOCTL_DEBUG_PRINTK(("vfc%d: User passed bogus pointer to "
                                        "vfc_get_video_ioctl\n",
                                        dev->instance));
@@ -557,6 +551,7 @@ static int vfc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
        int ret = 0;
        unsigned int tmp;
        struct vfc_dev *dev;
+       void __user *argp = (void __user *)arg;
 
        dev = vfc_get_dev_ptr(iminor(inode));
        if(dev == NULL)
@@ -568,7 +563,7 @@ static int vfc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                VFC_IOCTL_DEBUG_PRINTK(("vfc%d: IOCTL(VFCGCTRL)\n", dev->instance));
 #endif
                tmp = sbus_readl(&dev->regs->control);
-               if(copy_to_user((void *)arg, &tmp, sizeof(unsigned int))) {
+               if(copy_to_user(argp, &tmp, sizeof(unsigned int))) {
                        ret = -EFAULT;
                        break;
                }
@@ -585,7 +580,7 @@ static int vfc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                break;
        case VFCHUE:
                VFC_IOCTL_DEBUG_PRINTK(("vfc%d: IOCTL(VFCHUE)\n", dev->instance));
-               if(copy_from_user(&tmp,(void *)arg,sizeof(unsigned int))) {
+               if(copy_from_user(&tmp,argp,sizeof(unsigned int))) {
                        VFC_IOCTL_DEBUG_PRINTK(("vfc%d: User passed bogus pointer "
                                                "to IOCTL(VFCHUE)", dev->instance));
                        ret = -EFAULT;
@@ -603,21 +598,19 @@ static int vfc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                VFC_IOCTL_DEBUG_PRINTK(("vfc%d: IOCTL(VFCRDINFO)\n", dev->instance));
                break;
        default:
-               ret = vfc_debug(vfc_get_dev_ptr(iminor(inode)),
-                               cmd, arg);
+               ret = vfc_debug(vfc_get_dev_ptr(iminor(inode)), cmd, argp);
                break;
        };
 
        return ret;
 }
 
-static int vfc_mmap(struct inode *inode, struct file *file, 
-                   struct vm_area_struct *vma) 
+static int vfc_mmap(struct file *file, struct vm_area_struct *vma) 
 {
        unsigned int map_size, ret, map_offset;
        struct vfc_dev *dev;
        
-       dev = vfc_get_dev_ptr(iminor(inode));
+       dev = vfc_get_dev_ptr(iminor(file->f_path.dentry->d_inode));
        if(dev == NULL)
                return -ENODEV;
 
@@ -626,10 +619,12 @@ static int vfc_mmap(struct inode *inode, struct file *file,
                map_size = sizeof(struct vfc_regs);
 
        vma->vm_flags |=
-               (VM_SHM | VM_LOCKED | VM_IO | VM_MAYREAD | VM_MAYWRITE | VM_MAYSHARE);
+               (VM_MAYREAD | VM_MAYWRITE | VM_MAYSHARE);
        map_offset = (unsigned int) (long)dev->phys_regs;
-       ret = io_remap_page_range(vma, vma->vm_start, map_offset, map_size, 
-                                 vma->vm_page_prot, dev->which_io);
+       ret = io_remap_pfn_range(vma, vma->vm_start,
+                                 MK_IOSPACE_PFN(dev->which_io,
+                                       map_offset >> PAGE_SHIFT),
+                                 map_size, vma->vm_page_prot);
 
        if(ret)
                return -EAGAIN;
@@ -664,7 +659,7 @@ static int vfc_probe(void)
        if (!cards)
                return -ENODEV;
 
-       vfc_dev_lst = (struct vfc_dev **)kmalloc(sizeof(struct vfc_dev *) *
+       vfc_dev_lst = kmalloc(sizeof(struct vfc_dev *) *
                                                 (cards+1),
                                                 GFP_KERNEL);
        if (vfc_dev_lst == NULL)
@@ -678,7 +673,6 @@ static int vfc_probe(void)
                kfree(vfc_dev_lst);
                return -EIO;
        }
-       devfs_mk_dir("vfc");
        instance = 0;
        for_all_sbusdev(sdev, sbus) {
                if (strcmp(sdev->prom_name, "vfc") == 0) {
@@ -718,8 +712,7 @@ static void deinit_vfc_device(struct vfc_dev *dev)
 {
        if(dev == NULL)
                return;
-       devfs_remove("vfc/%d", dev->instance);
-       sbus_iounmap((unsigned long)dev->regs, sizeof(struct vfc_regs));
+       sbus_iounmap(dev->regs, sizeof(struct vfc_regs));
        kfree(dev);
 }
 
@@ -732,7 +725,6 @@ void cleanup_module(void)
        for (devp = vfc_dev_lst; *devp; devp++)
                deinit_vfc_device(*devp);
 
-       devfs_remove("vfc");
        kfree(vfc_dev_lst);
        return;
 }