Eliminate some dead initialization.
[dragonfly.git] / sys / dev / drm / drm_fops.c
bloba0948398ea5802f5d81efd03ed605aae62323a81
1 /*-
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 * Authors:
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Daryll Strauss <daryll@valinux.com>
28 * Gareth Hughes <gareth@valinux.com>
30 * $DragonFly: src/sys/dev/drm/drm_fops.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
33 /** @file drm_fops.c
34 * Support code for dealing with the file privates associated with each
35 * open of the DRM device.
38 #include "drmP.h"
40 drm_file_t *drm_find_file_by_proc(drm_device_t *dev, DRM_STRUCTPROC *p)
42 #if __FreeBSD_version >= 500021
43 uid_t uid = p->td_ucred->cr_svuid;
44 pid_t pid = p->td_proc->p_pid;
45 #elif defined(__DragonFly__)
46 uid_t uid = p->td_proc->p_ucred->cr_svuid;
47 pid_t pid = p->td_proc->p_pid;
48 #else
49 uid_t uid = p->p_cred->p_svuid;
50 pid_t pid = p->p_pid;
51 #endif
52 drm_file_t *priv;
54 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
56 TAILQ_FOREACH(priv, &dev->files, link)
57 if (priv->pid == pid && priv->uid == uid)
58 return priv;
59 return NULL;
62 /* drm_open_helper is called whenever a process opens /dev/drm. */
63 int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
64 drm_device_t *dev)
66 int m = minor(kdev);
67 drm_file_t *priv;
68 int retcode;
70 if (flags & O_EXCL)
71 return EBUSY; /* No exclusive opens */
72 dev->flags = flags;
74 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
76 DRM_LOCK();
77 priv = drm_find_file_by_proc(dev, p);
78 if (priv) {
79 priv->refs++;
80 } else {
81 priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
82 if (priv == NULL) {
83 DRM_UNLOCK();
84 return ENOMEM;
86 #if __FreeBSD_version >= 500000
87 priv->uid = p->td_ucred->cr_svuid;
88 priv->pid = p->td_proc->p_pid;
89 #elif defined(__DragonFly__)
90 priv->uid = p->td_proc->p_ucred->cr_svuid;
91 priv->pid = p->td_proc->p_pid;
92 #else
93 priv->uid = p->p_cred->p_svuid;
94 priv->pid = p->p_pid;
95 #endif
97 priv->refs = 1;
98 priv->minor = m;
99 priv->ioctl_count = 0;
101 /* for compatibility root is always authenticated */
102 priv->authenticated = DRM_SUSER(p);
104 if (dev->driver.open) {
105 /* shared code returns -errno */
106 retcode = -dev->driver.open(dev, priv);
107 if (retcode != 0) {
108 free(priv, M_DRM);
109 DRM_UNLOCK();
110 return retcode;
114 /* first opener automatically becomes master */
115 priv->master = TAILQ_EMPTY(&dev->files);
117 TAILQ_INSERT_TAIL(&dev->files, priv, link);
119 DRM_UNLOCK();
120 #if defined(__FreeBSD__) || defined(__DragonFly__)
121 kdev->si_drv1 = dev;
122 #endif
123 return 0;
127 /* The drm_read and drm_poll are stubs to prevent spurious errors
128 * on older X Servers (4.3.0 and earlier) */
130 #ifdef __DragonFly__
131 int drm_read(struct dev_read_args *ap)
133 return (0);
136 int drm_poll(struct dev_poll_args *ap)
138 return (0);
140 #else
141 int drm_read(struct cdev *kdev, struct uio *uio, int ioflag)
143 return 0;
146 int drm_poll(struct cdev *kdev, int events, DRM_STRUCTPROC *p)
148 return 0;
150 #endif