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);
57 if (filp->f_flags & O_EXCL) return -EBUSY; /* No exclusive opens */
58 if (!DRM(cpu_valid)()) return -EINVAL;
60 DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
62 priv = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
63 if(!priv) return -ENOMEM;
65 memset(priv, 0, sizeof(*priv));
66 filp->private_data = priv;
67 priv->uid = current->euid;
68 priv->pid = current->pid;
71 priv->ioctl_count = 0;
72 priv->authenticated = capable(CAP_SYS_ADMIN);
75 down(&dev->struct_sem);
76 if (!dev->file_last) {
79 dev->file_first = priv;
80 dev->file_last = priv;
83 priv->prev = dev->file_last;
84 dev->file_last->next = priv;
85 dev->file_last = priv;
94 struct pci_dev *pci_dev;
95 pci_dev = pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
96 if (pci_dev) dev->hose = pci_dev->sysdata;
98 struct pci_bus *b = pci_bus_b(pci_root_buses.next);
99 if (b) dev->hose = b->sysdata;
108 int DRM(flush)(struct file *filp)
110 drm_file_t *priv = filp->private_data;
111 drm_device_t *dev = priv->dev;
113 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
114 current->pid, (long)old_encode_dev(dev->device), dev->open_count);
119 int DRM(fasync)(int fd, struct file *filp, int on)
121 drm_file_t *priv = filp->private_data;
122 drm_device_t *dev = priv->dev;
125 DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, (long)old_encode_dev(dev->device));
126 retcode = fasync_helper(fd, filp, on, &dev->buf_async);
127 if (retcode < 0) return retcode;
131 #if !__HAVE_DRIVER_FOPS_POLL
133 unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
140 #if !__HAVE_DRIVER_FOPS_READ
142 ssize_t DRM(read)(struct file *filp, char *buf, size_t count, loff_t *off)