Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / dev / drm / drm_fops.h
... / ...
CommitLineData
1/* drm_fops.h -- File operations for DRM -*- linux-c -*-
2 * Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
3 *
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All Rights Reserved.
7 *
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:
14 *
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
17 * Software.
18 *
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.
26 *
27 * Authors:
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Daryll Strauss <daryll@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
31 *
32 * $FreeBSD: src/sys/dev/drm/drm_fops.h,v 1.7.2.1 2003/04/26 07:05:28 anholt Exp $
33 * $DragonFly: src/sys/dev/drm/Attic/drm_fops.h,v 1.6 2006/09/10 01:26:34 dillon Exp $
34 */
35
36#include "dev/drm/drmP.h"
37
38drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev, DRM_STRUCTPROC *p)
39{
40#if defined(__FreeBSD__) && __FreeBSD_version >= 500021
41 uid_t uid = p->td_ucred->cr_svuid;
42 pid_t pid = p->td_proc->p_pid;
43#else
44 uid_t uid = p->td_proc->p_ucred->cr_svuid;
45 pid_t pid = p->td_proc->p_pid;
46#endif
47 drm_file_t *priv;
48
49 TAILQ_FOREACH(priv, &dev->files, link)
50 if (priv->pid == pid && priv->uid == uid)
51 return priv;
52 return NULL;
53}
54
55/* DRM(open) is called whenever a process opens /dev/drm. */
56
57int DRM(open_helper)(cdev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p,
58 drm_device_t *dev)
59{
60 int m = minor(kdev);
61 drm_file_t *priv;
62
63 if (flags & O_EXCL)
64 return EBUSY; /* No exclusive opens */
65 dev->flags = flags;
66
67 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
68
69 /* FIXME: linux mallocs and bzeros here */
70 priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p);
71 if (priv) {
72 priv->refs++;
73 } else {
74 priv = (drm_file_t *) DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
75 bzero(priv, sizeof(*priv));
76#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
77 priv->uid = p->td_ucred->cr_svuid;
78 priv->pid = p->td_proc->p_pid;
79#else
80 priv->uid = p->td_proc->p_ucred->cr_svuid;
81 priv->pid = p->td_proc->p_pid;
82#endif
83
84 priv->refs = 1;
85 priv->minor = m;
86 priv->devXX = dev;
87 priv->ioctl_count = 0;
88 priv->authenticated = !DRM_SUSER(p);
89 DRM_LOCK;
90 TAILQ_INSERT_TAIL(&dev->files, priv, link);
91 DRM_UNLOCK;
92 }
93#if defined(__DragonFly__) || defined(__FreeBSD__)
94 kdev->si_drv1 = dev;
95#endif
96 return 0;
97}
98
99
100/* The DRM(read) and DRM(poll) are stubs to prevent spurious errors
101 * on older X Servers (4.3.0 and earlier) */
102
103int DRM(read)(struct dev_read_args *ap)
104{
105 return 0;
106}
107
108int DRM(poll)(struct dev_poll_args *ap)
109{
110 ap->a_events = 0;
111 return 0;
112}