OSDN Git Service

[915]: more registers for S3 (DSPCLK_GATE_D, CACHE_MODE_0, MI_ARB_STATE)
[android-x86/external-libdrm.git] / bsd-core / drm_fops.c
1 /*-
2  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4  * All Rights Reserved.
5  *
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:
12  *
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.
16  *
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.
24  *
25  * Authors:
26  *    Rickard E. (Rik) Faith <faith@valinux.com>
27  *    Daryll Strauss <daryll@valinux.com>
28  *    Gareth Hughes <gareth@valinux.com>
29  *
30  */
31
32 /** @file drm_fops.c
33  * Support code for dealing with the file privates associated with each
34  * open of the DRM device.
35  */
36
37 #include "drmP.h"
38
39 drm_file_t *drm_find_file_by_proc(drm_device_t *dev, DRM_STRUCTPROC *p)
40 {
41 #if __FreeBSD_version >= 500021
42         uid_t uid = p->td_ucred->cr_svuid;
43         pid_t pid = p->td_proc->p_pid;
44 #else
45         uid_t uid = p->p_cred->p_svuid;
46         pid_t pid = p->p_pid;
47 #endif
48         drm_file_t *priv;
49
50         DRM_SPINLOCK_ASSERT(&dev->dev_lock);
51
52         TAILQ_FOREACH(priv, &dev->files, link)
53                 if (priv->pid == pid && priv->uid == uid)
54                         return priv;
55         return NULL;
56 }
57
58 /* drm_open_helper is called whenever a process opens /dev/drm. */
59 int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
60                     drm_device_t *dev)
61 {
62         int          m = minor(kdev);
63         drm_file_t   *priv;
64         int retcode;
65
66         if (flags & O_EXCL)
67                 return EBUSY; /* No exclusive opens */
68         dev->flags = flags;
69
70         DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
71
72         DRM_LOCK();
73         priv = drm_find_file_by_proc(dev, p);
74         if (priv) {
75                 priv->refs++;
76         } else {
77                 priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
78                 if (priv == NULL) {
79                         DRM_UNLOCK();
80                         return ENOMEM;
81                 }
82 #if __FreeBSD_version >= 500000
83                 priv->uid               = p->td_ucred->cr_svuid;
84                 priv->pid               = p->td_proc->p_pid;
85 #else
86                 priv->uid               = p->p_cred->p_svuid;
87                 priv->pid               = p->p_pid;
88 #endif
89
90                 priv->refs              = 1;
91                 priv->minor             = m;
92                 priv->ioctl_count       = 0;
93
94                 /* for compatibility root is always authenticated */
95                 priv->authenticated     = DRM_SUSER(p);
96
97                 if (dev->driver.open) {
98                         /* shared code returns -errno */
99                         retcode = -dev->driver.open(dev, priv);
100                         if (retcode != 0) {
101                                 free(priv, M_DRM);
102                                 DRM_UNLOCK();
103                                 return retcode;
104                         }
105                 }
106
107                 /* first opener automatically becomes master */
108                 priv->master = TAILQ_EMPTY(&dev->files);
109
110                 TAILQ_INSERT_TAIL(&dev->files, priv, link);
111         }
112         DRM_UNLOCK();
113 #ifdef __FreeBSD__
114         kdev->si_drv1 = dev;
115 #endif
116         return 0;
117 }
118
119
120 /* The drm_read and drm_poll are stubs to prevent spurious errors
121  * on older X Servers (4.3.0 and earlier) */
122
123 int drm_read(struct cdev *kdev, struct uio *uio, int ioflag)
124 {
125         return 0;
126 }
127
128 int drm_poll(struct cdev *kdev, int events, DRM_STRUCTPROC *p)
129 {
130         return 0;
131 }