patch-2_6_7-vs1_9_1_12
[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
57         if (filp->f_flags & O_EXCL)   return -EBUSY; /* No exclusive opens */
58         if (!DRM(cpu_valid)())        return -EINVAL;
59
60         DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
61
62         priv                = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
63         if(!priv) return -ENOMEM;
64
65         memset(priv, 0, sizeof(*priv));
66         filp->private_data  = priv;
67         priv->uid           = current->euid;
68         priv->pid           = current->pid;
69         priv->minor         = minor;
70         priv->dev           = dev;
71         priv->ioctl_count   = 0;
72         priv->authenticated = capable(CAP_SYS_ADMIN);
73         priv->lock_count    = 0;
74
75         DRIVER_OPEN_HELPER( priv, dev );
76
77         down(&dev->struct_sem);
78         if (!dev->file_last) {
79                 priv->next      = NULL;
80                 priv->prev      = NULL;
81                 dev->file_first = priv;
82                 dev->file_last  = priv;
83         } else {
84                 priv->next           = NULL;
85                 priv->prev           = dev->file_last;
86                 dev->file_last->next = priv;
87                 dev->file_last       = priv;
88         }
89         up(&dev->struct_sem);
90
91 #ifdef __alpha__
92         /*
93          * Default the hose
94          */
95         if (!dev->hose) {
96                 struct pci_dev *pci_dev;
97                 pci_dev = pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
98                 if (pci_dev) dev->hose = pci_dev->sysdata;
99                 if (!dev->hose) {
100                         struct pci_bus *b = pci_bus_b(pci_root_buses.next);
101                         if (b) dev->hose = b->sysdata;
102                 }
103         }
104 #endif
105
106         return 0;
107 }
108
109 /** No-op. */
110 int DRM(flush)(struct file *filp)
111 {
112         drm_file_t    *priv   = filp->private_data;
113         drm_device_t  *dev    = priv->dev;
114
115         DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
116                   current->pid, (long)old_encode_dev(dev->device), dev->open_count);
117         return 0;
118 }
119
120 /** No-op. */
121 int DRM(fasync)(int fd, struct file *filp, int on)
122 {
123         drm_file_t    *priv   = filp->private_data;
124         drm_device_t  *dev    = priv->dev;
125         int           retcode;
126
127         DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, (long)old_encode_dev(dev->device));
128         retcode = fasync_helper(fd, filp, on, &dev->buf_async);
129         if (retcode < 0) return retcode;
130         return 0;
131 }
132
133 #if !__HAVE_DRIVER_FOPS_POLL
134 /** No-op. */
135 unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
136 {
137         return 0;
138 }
139 #endif
140
141
142 #if !__HAVE_DRIVER_FOPS_READ
143 /** No-op. */
144 ssize_t DRM(read)(struct file *filp, char *buf, size_t count, loff_t *off)
145 {
146         return 0;
147 }
148 #endif