vserver 1.9.3
[linux-2.6.git] / drivers / char / drm / drm_fops.h
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 #include "drmP.h"
38 #include <linux/poll.h>
39
40
41 /**
42  * Called whenever a process opens /dev/drm. 
43  *
44  * \param inode device inode.
45  * \param filp file pointer.
46  * \param dev device.
47  * \return zero on success or a negative number on failure.
48  * 
49  * Creates and initializes a drm_file structure for the file private data in \p
50  * filp and add it into the double linked list in \p dev.
51  */
52 int DRM(open_helper)(struct inode *inode, struct file *filp, drm_device_t *dev)
53 {
54         int          minor = iminor(inode);
55         drm_file_t   *priv;
56         int ret;
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                 ret=dev->fn_tbl.open_helper(dev, priv);
78                 if (ret < 0)
79                         goto out_free;
80         }
81
82         down(&dev->struct_sem);
83         if (!dev->file_last) {
84                 priv->next      = NULL;
85                 priv->prev      = NULL;
86                 dev->file_first = priv;
87                 dev->file_last  = priv;
88         } else {
89                 priv->next           = NULL;
90                 priv->prev           = dev->file_last;
91                 dev->file_last->next = priv;
92                 dev->file_last       = priv;
93         }
94         up(&dev->struct_sem);
95
96 #ifdef __alpha__
97         /*
98          * Default the hose
99          */
100         if (!dev->hose) {
101                 struct pci_dev *pci_dev;
102                 pci_dev = pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
103                 if (pci_dev) dev->hose = pci_dev->sysdata;
104                 if (!dev->hose) {
105                         struct pci_bus *b = pci_bus_b(pci_root_buses.next);
106                         if (b) dev->hose = b->sysdata;
107                 }
108         }
109 #endif
110
111         return 0;
112 out_free:
113         DRM(free)(priv, sizeof(*priv), DRM_MEM_FILES);
114         filp->private_data=NULL;
115         return ret;
116 }
117
118 /** No-op. */
119 int DRM(flush)(struct file *filp)
120 {
121         drm_file_t    *priv   = filp->private_data;
122         drm_device_t  *dev    = priv->dev;
123
124         DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
125                   current->pid, (long)old_encode_dev(dev->device), dev->open_count);
126         return 0;
127 }
128
129 /** No-op. */
130 int DRM(fasync)(int fd, struct file *filp, int on)
131 {
132         drm_file_t    *priv   = filp->private_data;
133         drm_device_t  *dev    = priv->dev;
134         int           retcode;
135
136         DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, (long)old_encode_dev(dev->device));
137         retcode = fasync_helper(fd, filp, on, &dev->buf_async);
138         if (retcode < 0) return retcode;
139         return 0;
140 }
141
142 /** No-op. */
143 unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
144 {
145         return 0;
146 }
147
148
149 /** No-op. */
150 ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count, loff_t *off)
151 {
152         return 0;
153 }