3 * File operations for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Daryll Strauss <daryll@valinux.com>
7 * \author Gareth Hughes <gareth@valinux.com>
11 * Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
13 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
14 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
15 * All Rights Reserved.
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:
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
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.
38 #include <linux/poll.h>
42 * Called whenever a process opens /dev/drm.
44 * \param inode device inode.
45 * \param filp file pointer.
47 * \return zero on success or a negative number on failure.
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.
52 int DRM(open_helper)(struct inode *inode, struct file *filp, drm_device_t *dev)
54 int minor = iminor(inode);
58 if (filp->f_flags & O_EXCL) return -EBUSY; /* No exclusive opens */
59 if (!DRM(cpu_valid)()) return -EINVAL;
61 DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
63 priv = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
64 if(!priv) return -ENOMEM;
66 memset(priv, 0, sizeof(*priv));
67 filp->private_data = priv;
68 priv->uid = current->euid;
69 priv->pid = current->pid;
72 priv->ioctl_count = 0;
73 priv->authenticated = capable(CAP_SYS_ADMIN);
76 if (dev->fn_tbl.open_helper) {
77 ret=dev->fn_tbl.open_helper(dev, priv);
82 down(&dev->struct_sem);
83 if (!dev->file_last) {
86 dev->file_first = priv;
87 dev->file_last = priv;
90 priv->prev = dev->file_last;
91 dev->file_last->next = priv;
92 dev->file_last = priv;
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;
105 struct pci_bus *b = pci_bus_b(pci_root_buses.next);
106 if (b) dev->hose = b->sysdata;
113 DRM(free)(priv, sizeof(*priv), DRM_MEM_FILES);
114 filp->private_data=NULL;
119 int DRM(flush)(struct file *filp)
121 drm_file_t *priv = filp->private_data;
122 drm_device_t *dev = priv->dev;
124 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
125 current->pid, (long)old_encode_dev(dev->device), dev->open_count);
130 int DRM(fasync)(int fd, struct file *filp, int on)
132 drm_file_t *priv = filp->private_data;
133 drm_device_t *dev = priv->dev;
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;
143 unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
150 ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count, loff_t *off)