/** * Open file. * * \param inode device inode * \param filp file pointer. * \return zero on success or a negative number on failure. * * Searches the DRM device with the same minor number, calls open_helper(), and * increments the device open count. If the open count was previous at zero, * i.e., it's the first that the device is open, then calls setup(). */ int drm_open(struct inode *inode, struct file *filp) { struct drm_device *dev = NULL; int minor_id = iminor(inode); struct drm_minor *minor; int retcode = 0; minor = idr_find(&drm_minors_idr, minor_id); if (!minor) return -ENODEV; if (!(dev = minor->dev)) return -ENODEV; if (drm_device_is_unplugged(dev)) return -ENODEV; retcode = drm_open_helper(inode, filp, dev); if (!retcode) { atomic_inc(&dev->counts[_DRM_STAT_OPENS]); if (!dev->open_count++) retcode = drm_setup(dev); } if (!retcode) { mutex_lock(&dev->struct_mutex); if (dev->dev_mapping == NULL) dev->dev_mapping = &inode->i_data; /* ihold ensures nobody can remove inode with our i_data */ ihold(container_of(dev->dev_mapping, struct inode, i_data)); inode->i_mapping = dev->dev_mapping; filp->f_mapping = dev->dev_mapping; mutex_unlock(&dev->struct_mutex); }
int drm_open(struct dev_open_args *ap) { struct cdev *kdev = ap->a_head.a_dev; int flags = ap->a_oflags; int fmt = 0; struct thread *p = curthread; struct drm_device *dev; int retcode; dev = DRIVER_SOFTC(minor(kdev)); if (dev == NULL) return (ENXIO); DRM_DEBUG("open_count = %d\n", dev->open_count); retcode = drm_open_helper(kdev, flags, fmt, p, dev, ap->a_fp); if (retcode == 0) { atomic_inc(&dev->counts[_DRM_STAT_OPENS]); DRM_LOCK(dev); device_busy(dev->dev); if (!dev->open_count++) retcode = drm_setup(dev); DRM_UNLOCK(dev); } DRM_DEBUG("return %d\n", retcode); return (retcode); }
int tdfx_open(struct inode *inode, struct file *filp) { drm_device_t *dev = &tdfx_device; int retcode = 0; DRM_DEBUG("open_count = %d\n", dev->open_count); if (!(retcode = drm_open_helper(inode, filp, dev))) { #if LINUX_VERSION_CODE < 0x020333 MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */ #endif atomic_inc(&dev->total_open); spin_lock(&dev->count_lock); if (!dev->open_count++) { spin_unlock(&dev->count_lock); return tdfx_setup(dev); } spin_unlock(&dev->count_lock); } return retcode; }
/** * Open file. * * \param inode device inode * \param filp file pointer. * \return zero on success or a negative number on failure. * * Searches the DRM device with the same minor number, calls open_helper(), and * increments the device open count. If the open count was previous at zero, * i.e., it's the first that the device is open, then calls setup(). */ int drm_open(struct inode *inode, struct file *filp) { struct drm_device *dev = NULL; int minor_id = iminor(inode); struct drm_minor *minor; int retcode = 0; minor = idr_find(&drm_minors_idr, minor_id); if (!minor) return -ENODEV; if (!(dev = minor->dev)) return -ENODEV; if (drm_device_is_unplugged(dev)) return -ENODEV; retcode = drm_open_helper(inode, filp, dev); if (!retcode) { atomic_inc(&dev->counts[_DRM_STAT_OPENS]); <<<<<<< HEAD