]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/drm/drm_fops.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / drm / 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 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 /** @file drm_fops.c
36  * Support code for dealing with the file privates associated with each
37  * open of the DRM device.
38  */
39
40 #include "dev/drm/drmP.h"
41
42 /* drm_open_helper is called whenever a process opens /dev/drm. */
43 int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
44                     struct drm_device *dev)
45 {
46         struct drm_file *priv;
47         int m = dev2unit(kdev);
48         int retcode;
49
50         if (flags & O_EXCL)
51                 return EBUSY; /* No exclusive opens */
52         dev->flags = flags;
53
54         DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
55
56         priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO);
57         if (priv == NULL) {
58                 return ENOMEM;
59         }
60
61         retcode = devfs_set_cdevpriv(priv, drm_close);
62         if (retcode != 0) {
63                 free(priv, DRM_MEM_FILES);
64                 return retcode;
65         }
66
67         DRM_LOCK();
68         priv->dev               = dev;
69         priv->uid               = p->td_ucred->cr_svuid;
70         priv->pid               = p->td_proc->p_pid;
71         priv->minor             = m;
72         priv->ioctl_count       = 0;
73
74         /* for compatibility root is always authenticated */
75         priv->authenticated     = DRM_SUSER(p);
76
77         if (dev->driver->open) {
78                 /* shared code returns -errno */
79                 retcode = -dev->driver->open(dev, priv);
80                 if (retcode != 0) {
81                         devfs_clear_cdevpriv();
82                         free(priv, DRM_MEM_FILES);
83                         DRM_UNLOCK();
84                         return retcode;
85                 }
86         }
87
88         /* first opener automatically becomes master */
89         priv->master = TAILQ_EMPTY(&dev->files);
90
91         TAILQ_INSERT_TAIL(&dev->files, priv, link);
92         DRM_UNLOCK();
93         kdev->si_drv1 = dev;
94         return 0;
95 }
96
97
98 /* The drm_read and drm_poll are stubs to prevent spurious errors
99  * on older X Servers (4.3.0 and earlier) */
100
101 int drm_read(struct cdev *kdev, struct uio *uio, int ioflag)
102 {
103         return 0;
104 }
105
106 int drm_poll(struct cdev *kdev, int events, DRM_STRUCTPROC *p)
107 {
108         return 0;
109 }