aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/drm/drm_fops.c
diff options
context:
space:
mode:
authorRobert Noland <rnoland@FreeBSD.org>2008-10-03 16:59:11 +0000
committerRobert Noland <rnoland@FreeBSD.org>2008-10-03 16:59:11 +0000
commit4cd2e9581f9232a2134d2617e65d372149694c53 (patch)
tree2d4185c3ec896efd0d1b2735041e6ddeb6a750f1 /sys/dev/drm/drm_fops.c
parent0b36cd25fcb6fd26726efb8d9fd80b9c9733174f (diff)
downloadsrc-4cd2e9581f9232a2134d2617e65d372149694c53.tar.gz
src-4cd2e9581f9232a2134d2617e65d372149694c53.zip
Notes
Diffstat (limited to 'sys/dev/drm/drm_fops.c')
-rw-r--r--sys/dev/drm/drm_fops.c91
1 files changed, 33 insertions, 58 deletions
diff --git a/sys/dev/drm/drm_fops.c b/sys/dev/drm/drm_fops.c
index f6eacd217fb5..9b7bc4068f8e 100644
--- a/sys/dev/drm/drm_fops.c
+++ b/sys/dev/drm/drm_fops.c
@@ -39,31 +39,12 @@ __FBSDID("$FreeBSD$");
#include "dev/drm/drmP.h"
-drm_file_t *drm_find_file_by_proc(struct drm_device *dev, DRM_STRUCTPROC *p)
-{
-#if __FreeBSD_version >= 500021
- uid_t uid = p->td_ucred->cr_svuid;
- pid_t pid = p->td_proc->p_pid;
-#else
- uid_t uid = p->p_cred->p_svuid;
- pid_t pid = p->p_pid;
-#endif
- drm_file_t *priv;
-
- DRM_SPINLOCK_ASSERT(&dev->dev_lock);
-
- TAILQ_FOREACH(priv, &dev->files, link)
- if (priv->pid == pid && priv->uid == uid)
- return priv;
- return NULL;
-}
-
/* 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)
{
- int m = dev2unit(kdev);
- drm_file_t *priv;
+ struct drm_file *priv;
+ int m = minor(kdev);
int retcode;
if (flags & O_EXCL)
@@ -72,50 +53,44 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
+ priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
+ if (priv == NULL) {
+ return ENOMEM;
+ }
+
+ retcode = devfs_set_cdevpriv(priv, drm_close);
+ if (retcode != 0) {
+ free(priv, M_DRM);
+ return retcode;
+ }
+
DRM_LOCK();
- priv = drm_find_file_by_proc(dev, p);
- if (priv) {
- priv->refs++;
- } else {
- priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
- if (priv == NULL) {
+ priv->dev = dev;
+ priv->uid = p->td_ucred->cr_svuid;
+ priv->pid = p->td_proc->p_pid;
+ priv->minor = m;
+ priv->ioctl_count = 0;
+
+ /* for compatibility root is always authenticated */
+ priv->authenticated = DRM_SUSER(p);
+
+ if (dev->driver->open) {
+ /* shared code returns -errno */
+ retcode = -dev->driver->open(dev, priv);
+ if (retcode != 0) {
+ devfs_clear_cdevpriv();
+ free(priv, M_DRM);
DRM_UNLOCK();
- return ENOMEM;
- }
-#if __FreeBSD_version >= 500000
- priv->uid = p->td_ucred->cr_svuid;
- priv->pid = p->td_proc->p_pid;
-#else
- priv->uid = p->p_cred->p_svuid;
- priv->pid = p->p_pid;
-#endif
-
- priv->refs = 1;
- priv->minor = m;
- priv->ioctl_count = 0;
-
- /* for compatibility root is always authenticated */
- priv->authenticated = DRM_SUSER(p);
-
- if (dev->driver.open) {
- /* shared code returns -errno */
- retcode = -dev->driver.open(dev, priv);
- if (retcode != 0) {
- free(priv, M_DRM);
- DRM_UNLOCK();
- return retcode;
- }
+ return retcode;
}
+ }
- /* first opener automatically becomes master */
- priv->master = TAILQ_EMPTY(&dev->files);
+ /* first opener automatically becomes master */
+ priv->master = TAILQ_EMPTY(&dev->files);
- TAILQ_INSERT_TAIL(&dev->files, priv, link);
- }
+ TAILQ_INSERT_TAIL(&dev->files, priv, link);
DRM_UNLOCK();
-#ifdef __FreeBSD__
kdev->si_drv1 = dev;
-#endif
return 0;
}