FreeBSD/sys/dev/drm/drm_fops.c
/* drm_open_helper is called whenever a process opens /dev/drm. */
drm_open_helper is called whenever a process opens /dev/drm.
drm_open_helper is called whenever a process opens / dev / drm .
int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
		    struct drm_device *dev)
{
	struct drm_file *priv;
	int retcode;
	if (flags & O_EXCL)
		return EBUSY; 
	dev->flags = flags;
	DRM_DEBUG("pid = %d, device = %s\n", DRM_CURRENTPID, devtoname(kdev));
	priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO);
	if (priv == NULL) {
		return ENOMEM;
	}
	DRM_LOCK();
	priv->dev		= dev;
	priv->uid		= p->td_ucred->cr_svuid;
	priv->pid		= p->td_proc->p_pid;
	priv->ioctl_count 	= 0;
	priv->authenticated	= DRM_SUSER(p);
	if (dev->driver->open) {
		retcode = -dev->driver->open(dev, priv);
		if (retcode != 0) {
			free(priv, DRM_MEM_FILES);
			DRM_UNLOCK();
			return retcode;
		}
	}
	priv->master = TAILQ_EMPTY(&dev->files);
	TAILQ_INSERT_TAIL(&dev->files, priv, link);
	DRM_UNLOCK();
	kdev->si_drv1 = dev;
	retcode = devfs_set_cdevpriv(priv, drm_close);
	if (retcode != 0)
		drm_close(priv);
	return (retcode);
}
int drm_open_helper ( struct cdev * kdev , int flags , int fmt , DRM_STRUCTPROC * p , struct drm_device * dev ) { struct drm_file * priv ; int retcode ; if ( flags & O_EXCL ) return EBUSY ; dev -> flags = flags ; DRM_DEBUG ( " \n " , DRM_CURRENTPID , devtoname ( kdev ) ) ; priv = malloc ( sizeof ( * priv ) , DRM_MEM_FILES , M_NOWAIT | M_ZERO ) ; if ( priv == NULL ) { return ENOMEM ; } DRM_LOCK ( ) ; priv -> dev = dev ; priv -> uid = p -> td_ucred -> cr_svuid ; priv -> pid = p -> td_proc -> p_pid ; priv -> ioctl_count = 0 ; priv -> authenticated = DRM_SUSER ( p ) ; if ( dev -> driver -> open ) { retcode = - dev -> driver -> open ( dev , priv ) ; if ( retcode != 0 ) { free ( priv , DRM_MEM_FILES ) ; DRM_UNLOCK ( ) ; return retcode ; } } priv -> master = TAILQ_EMPTY ( & dev -> files ) ; TAILQ_INSERT_TAIL ( & dev -> files , priv , link ) ; DRM_UNLOCK ( ) ; kdev -> si_drv1 = dev ; retcode = devfs_set_cdevpriv ( priv , drm_close ) ; if ( retcode != 0 ) drm_close ( priv ) ; return ( retcode ) ; }
drm_open_helper is called whenever a process opens /dev/drm.
drm_open_helper is called whenever a process opens / dev / drm .
/* No exclusive opens */ /* for compatibility root is always authenticated */ /* shared code returns -errno */ /* first opener automatically becomes master */