FreeBSD/sys/dev/drm2/drm_fops.c
/**
 * 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().
 */
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().
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 cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p)
{
	struct drm_device *dev = NULL;
	struct drm_minor *minor;
	int retcode = 0;
	int need_setup = 0;
	minor = kdev->si_drv1;
	if (!minor)
		return ENODEV;
	if (!(dev = minor->dev))
		return ENODEV;
	sx_xlock(&drm_global_mutex);
	if (!dev->open_count++)
		need_setup = 1;
	retcode = drm_open_helper(kdev, flags, fmt, p, dev);
	if (retcode) {
		sx_xunlock(&drm_global_mutex);
		return (-retcode);
	}
	atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
	if (need_setup) {
		retcode = drm_setup(dev);
		if (retcode)
			goto err_undo;
	}
	sx_xunlock(&drm_global_mutex);
	return 0;
err_undo:
	mtx_lock(&Giant); 
	device_unbusy(dev->dev);
	mtx_unlock(&Giant);
	dev->open_count--;
	sx_xunlock(&drm_global_mutex);
	return -retcode;
}
int drm_open ( struct cdev * kdev , int flags , int fmt , DRM_STRUCTPROC * p ) { struct drm_device * dev = NULL ; struct drm_minor * minor ; int retcode = 0 ; int need_setup = 0 ; minor = kdev -> si_drv1 ; if ( ! minor ) return ENODEV ; if ( ! ( dev = minor -> dev ) ) return ENODEV ; sx_xlock ( & drm_global_mutex ) ; if ( ! dev -> open_count ++ ) need_setup = 1 ; retcode = drm_open_helper ( kdev , flags , fmt , p , dev ) ; if ( retcode ) { sx_xunlock ( & drm_global_mutex ) ; return ( - retcode ) ; } atomic_inc ( & dev -> counts [ _DRM_STAT_OPENS ] ) ; if ( need_setup ) { retcode = drm_setup ( dev ) ; if ( retcode ) goto err_undo ; } sx_xunlock ( & drm_global_mutex ) ; return 0 ; err_undo : mtx_lock ( & Giant ) ; device_unbusy ( dev -> dev ) ; mtx_unlock ( & Giant ) ; dev -> open_count -- ; sx_xunlock ( & drm_global_mutex ) ; return - retcode ; }
Open file.
Open file .
/*
	 * FIXME Linux<->FreeBSD: On Linux, counter updated outside
	 * global mutex.
	 */ /* FIXME: Giant required? */