1 /* drm_fops.h -- File operations for DRM -*- linux-c -*-
2 * Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Daryll Strauss <daryll@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
36 drm_file_t *drm_find_file_by_proc(drm_device_t *dev, DRM_STRUCTPROC *p)
38 #if __FreeBSD_version >= 500021
39 uid_t uid = p->td_ucred->cr_svuid;
40 pid_t pid = p->td_proc->p_pid;
42 uid_t uid = p->p_cred->p_svuid;
47 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
49 TAILQ_FOREACH(priv, &dev->files, link)
50 if (priv->pid == pid && priv->uid == uid)
55 /* drm_open_helper is called whenever a process opens /dev/drm. */
56 int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
64 return EBUSY; /* No exclusive opens */
67 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
70 priv = drm_find_file_by_proc(dev, p);
74 priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
77 return DRM_ERR(ENOMEM);
79 #if __FreeBSD_version >= 500000
80 priv->uid = p->td_ucred->cr_svuid;
81 priv->pid = p->td_proc->p_pid;
83 priv->uid = p->p_cred->p_svuid;
89 priv->ioctl_count = 0;
90 priv->authenticated = !DRM_SUSER(p);
92 if (dev->open_helper) {
93 retcode = dev->open_helper(dev, priv);
101 TAILQ_INSERT_TAIL(&dev->files, priv, link);
111 /* The drm_read and drm_poll are stubs to prevent spurious errors
112 * on older X Servers (4.3.0 and earlier) */
114 int drm_read(struct cdev *kdev, struct uio *uio, int ioflag)
119 int drm_poll(struct cdev *kdev, int events, DRM_STRUCTPROC *p)