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>
30 * $DragonFly: src/sys/dev/drm/drm_fops.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
34 * Support code for dealing with the file privates associated with each
35 * open of the DRM device.
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
;
49 uid_t uid
= p
->p_cred
->p_svuid
;
54 DRM_SPINLOCK_ASSERT(&dev
->dev_lock
);
56 TAILQ_FOREACH(priv
, &dev
->files
, link
)
57 if (priv
->pid
== pid
&& priv
->uid
== uid
)
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
,
71 return EBUSY
; /* No exclusive opens */
74 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID
, m
);
77 priv
= drm_find_file_by_proc(dev
, p
);
81 priv
= malloc(sizeof(*priv
), M_DRM
, M_NOWAIT
| M_ZERO
);
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
;
93 priv
->uid
= p
->p_cred
->p_svuid
;
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
);
114 /* first opener automatically becomes master */
115 priv
->master
= TAILQ_EMPTY(&dev
->files
);
117 TAILQ_INSERT_TAIL(&dev
->files
, priv
, link
);
120 #if defined(__FreeBSD__) || defined(__DragonFly__)
127 /* The drm_read and drm_poll are stubs to prevent spurious errors
128 * on older X Servers (4.3.0 and earlier) */
131 int drm_read(struct dev_read_args
*ap
)
136 int drm_poll(struct dev_poll_args
*ap
)
141 int drm_read(struct cdev
*kdev
, struct uio
*uio
, int ioflag
)
146 int drm_poll(struct cdev
*kdev
, int events
, DRM_STRUCTPROC
*p
)