Merged drmfntbl-0-0-1
[platform/upstream/libdrm.git] / linux-core / drm_fops.c
1 /**
2  * \file drm_fops.h 
3  * File operations for DRM
4  * 
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Daryll Strauss <daryll@valinux.com>
7  * \author Gareth Hughes <gareth@valinux.com>
8  */
9
10 /*
11  * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
12  *
13  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
14  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
15  * All Rights Reserved.
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining a
18  * copy of this software and associated documentation files (the "Software"),
19  * to deal in the Software without restriction, including without limitation
20  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21  * and/or sell copies of the Software, and to permit persons to whom the
22  * Software is furnished to do so, subject to the following conditions:
23  *
24  * The above copyright notice and this permission notice (including the next
25  * paragraph) shall be included in all copies or substantial portions of the
26  * Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
31  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
32  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
33  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  * OTHER DEALINGS IN THE SOFTWARE.
35  */
36
37 #define __NO_VERSION__
38 #include "drmP.h"
39 #include <linux/poll.h>
40
41
42 /**
43  * Called whenever a process opens /dev/drm. 
44  *
45  * \param inode device inode.
46  * \param filp file pointer.
47  * \param dev device.
48  * \return zero on success or a negative number on failure.
49  * 
50  * Creates and initializes a drm_file structure for the file private data in \p
51  * filp and add it into the double linked list in \p dev.
52  */
53 int DRM(open_helper)(struct inode *inode, struct file *filp, drm_device_t *dev)
54 {
55         int          minor = iminor(inode);
56         drm_file_t   *priv;
57
58         if (filp->f_flags & O_EXCL)   return -EBUSY; /* No exclusive opens */
59         if (!DRM(cpu_valid)())        return -EINVAL;
60
61         DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
62
63         priv                = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
64         if(!priv) return -ENOMEM;
65
66         memset(priv, 0, sizeof(*priv));
67         filp->private_data  = priv;
68         priv->uid           = current->euid;
69         priv->pid           = current->pid;
70         priv->minor         = minor;
71         priv->dev           = dev;
72         priv->ioctl_count   = 0;
73         priv->authenticated = capable(CAP_SYS_ADMIN);
74         priv->lock_count    = 0;
75
76         if (dev->fn_tbl.open_helper)
77           dev->fn_tbl.open_helper(dev, priv);
78
79         down(&dev->struct_sem);
80         if (!dev->file_last) {
81                 priv->next      = NULL;
82                 priv->prev      = NULL;
83                 dev->file_first = priv;
84                 dev->file_last  = priv;
85         } else {
86                 priv->next           = NULL;
87                 priv->prev           = dev->file_last;
88                 dev->file_last->next = priv;
89                 dev->file_last       = priv;
90         }
91         up(&dev->struct_sem);
92
93 #ifdef __alpha__
94         /*
95          * Default the hose
96          */
97         if (!dev->hose) {
98                 struct pci_dev *pci_dev;
99                 pci_dev = pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
100                 if (pci_dev) dev->hose = pci_dev->sysdata;
101                 if (!dev->hose) {
102                         struct pci_bus *b = pci_bus_b(pci_root_buses.next);
103                         if (b) dev->hose = b->sysdata;
104                 }
105         }
106 #endif
107
108         return 0;
109 }
110
111 /** No-op. */
112 int DRM(flush)(struct file *filp)
113 {
114         drm_file_t    *priv   = filp->private_data;
115         drm_device_t  *dev    = priv->dev;
116
117         DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
118                   current->pid, (long)old_encode_dev(dev->device), dev->open_count);
119         return 0;
120 }
121
122 /** No-op. */
123 int DRM(fasync)(int fd, struct file *filp, int on)
124 {
125         drm_file_t    *priv   = filp->private_data;
126         drm_device_t  *dev    = priv->dev;
127         int           retcode;
128
129         DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, (long)old_encode_dev(dev->device));
130         retcode = fasync_helper(fd, filp, on, &dev->buf_async);
131         if (retcode < 0) return retcode;
132         return 0;
133 }
134
135 /** No-op. */
136 unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
137 {
138         return 0;
139 }
140
141
142 /** No-op. */
143 ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count, loff_t *off)
144 {
145         return 0;
146 }