2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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
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.
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Daryll Strauss <daryll@valinux.com>
28 * Gareth Hughes <gareth@valinux.com>
33 * Support code for dealing with the file privates associated with each
34 * open of the DRM device.
39 #if defined(__NetBSD__)
41 drm_find_file_by_proc(struct drm_device
*dev
, struct proc
*p
)
43 uid_t uid
= kauth_cred_getsvuid(p
->p_cred
);
45 struct drm_file
*priv
;
47 DRM_SPINLOCK_ASSERT(&dev
->dev_lock
);
49 TAILQ_FOREACH(priv
, &dev
->files
, link
) {
50 if (priv
->pid
== pid
&& priv
->uid
== uid
)
57 /* drm_open_helper is called whenever a process opens /dev/drm. */
58 int drm_open_helper(dev_t kdev
, int flags
, int fmt
, struct proc
*p
,
59 struct drm_device
*dev
)
62 struct drm_file
*priv
;
66 return EBUSY
; /* No exclusive opens */
69 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID
, m
);
72 priv
= drm_find_file_by_proc(dev
, p
);
74 priv
= malloc(sizeof(*priv
), DRM_MEM_FILES
, M_NOWAIT
| M_ZERO
);
79 priv
->uid
= kauth_cred_getsvuid(p
->p_cred
);
83 priv
->ioctl_count
= 0;
85 /* for compatibility root is always authenticated */
86 priv
->authenticated
= DRM_SUSER(p
);
88 if (dev
->driver
->open
) {
89 /* shared code returns -errno */
90 retcode
= -dev
->driver
->open(dev
, priv
);
92 free(priv
, DRM_MEM_FILES
);
98 /* first opener automatically becomes master */
99 priv
->master
= TAILQ_EMPTY(&dev
->files
);
101 TAILQ_INSERT_TAIL(&dev
->files
, priv
, link
);
108 #elif defined(__FreeBSD__)
110 /* drm_open_helper is called whenever a process opens /dev/drm. */
111 int drm_open_helper(struct cdev
*kdev
, int flags
, int fmt
, DRM_STRUCTPROC
*p
,
112 struct drm_device
*dev
)
114 struct drm_file
*priv
;
119 return EBUSY
; /* No exclusive opens */
122 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID
, m
);
124 priv
= malloc(sizeof(*priv
), DRM_MEM_FILES
, M_NOWAIT
| M_ZERO
);
129 retcode
= devfs_set_cdevpriv(priv
, drm_close
);
131 free(priv
, DRM_MEM_FILES
);
137 priv
->uid
= p
->td_ucred
->cr_svuid
;
138 priv
->pid
= p
->td_proc
->p_pid
;
140 priv
->ioctl_count
= 0;
142 /* for compatibility root is always authenticated */
143 priv
->authenticated
= DRM_SUSER(p
);
145 if (dev
->driver
->open
) {
146 /* shared code returns -errno */
147 retcode
= -dev
->driver
->open(dev
, priv
);
149 devfs_clear_cdevpriv();
150 free(priv
, DRM_MEM_FILES
);
156 /* first opener automatically becomes master */
157 priv
->master
= TAILQ_EMPTY(&dev
->files
);
159 TAILQ_INSERT_TAIL(&dev
->files
, priv
, link
);
166 /* The drm_read and drm_poll are stubs to prevent spurious errors
167 * on older X Servers (4.3.0 and earlier) */
169 int drm_read(DRM_CDEV kdev
, struct uio
*uio
, int ioflag
)
174 int drm_poll(DRM_CDEV kdev
, int events
, DRM_STRUCTCDEVPROC
*p
)