drm/linux/drm_fops.h

154 lines
4.2 KiB
C
Raw Normal View History

2003-05-26 18:37:33 -06:00
/**
* \file drm_fops.h
* File operations for DRM
*
* \author Rickard E. (Rik) Faith <faith@valinux.com>
* \author Daryll Strauss <daryll@valinux.com>
* \author Gareth Hughes <gareth@valinux.com>
*/
/*
2001-02-15 01:12:14 -07:00
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
1999-12-05 16:10:37 -07:00
*
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
2000-06-08 08:38:22 -06:00
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
1999-12-05 16:10:37 -07:00
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
2001-02-15 01:12:14 -07:00
*
1999-12-05 16:10:37 -07:00
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
2001-02-15 01:12:14 -07:00
*
1999-12-05 16:10:37 -07:00
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2001-02-15 01:12:14 -07:00
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1999-12-05 16:10:37 -07:00
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2001-02-15 01:12:14 -07:00
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
1999-12-05 16:10:37 -07:00
*/
#include "drmP.h"
2000-02-22 15:10:28 -07:00
#include <linux/poll.h>
1999-12-05 16:10:37 -07:00
2003-05-26 18:37:33 -06:00
/**
* Called whenever a process opens /dev/drm.
*
* \param inode device inode.
* \param filp file pointer.
* \param dev device.
* \return zero on success or a negative number on failure.
*
* Creates and initializes a drm_file structure for the file private data in \p
* filp and add it into the double linked list in \p dev.
*/
2001-02-15 01:12:14 -07:00
int DRM(open_helper)(struct inode *inode, struct file *filp, drm_device_t *dev)
1999-12-05 16:10:37 -07:00
{
2004-04-08 06:25:31 -06:00
int minor = iminor(inode);
1999-12-05 16:10:37 -07:00
drm_file_t *priv;
2004-08-24 05:15:53 -06:00
int ret;
1999-12-05 16:10:37 -07:00
if (filp->f_flags & O_EXCL) return -EBUSY; /* No exclusive opens */
2001-02-15 01:12:14 -07:00
if (!DRM(cpu_valid)()) return -EINVAL;
1999-12-05 16:10:37 -07:00
DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
2001-02-15 01:12:14 -07:00
priv = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
if(!priv) return -ENOMEM;
1999-12-05 16:10:37 -07:00
memset(priv, 0, sizeof(*priv));
filp->private_data = priv;
priv->uid = current->euid;
priv->pid = current->pid;
priv->minor = minor;
priv->dev = dev;
priv->ioctl_count = 0;
priv->authenticated = capable(CAP_SYS_ADMIN);
priv->lock_count = 0;
1999-12-05 16:10:37 -07:00
2004-08-17 07:10:05 -06:00
if (dev->fn_tbl.open_helper)
2004-08-24 05:15:53 -06:00
{
ret=dev->fn_tbl.open_helper(dev, priv);
if (ret < 0)
goto out_free;
}
1999-12-05 16:10:37 -07:00
down(&dev->struct_sem);
if (!dev->file_last) {
priv->next = NULL;
priv->prev = NULL;
dev->file_first = priv;
dev->file_last = priv;
} else {
priv->next = NULL;
priv->prev = dev->file_last;
dev->file_last->next = priv;
dev->file_last = priv;
}
up(&dev->struct_sem);
2001-02-15 01:12:14 -07:00
2001-05-01 11:07:59 -06:00
#ifdef __alpha__
/*
* Default the hose
*/
if (!dev->hose) {
struct pci_dev *pci_dev;
pci_dev = pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
if (pci_dev) dev->hose = pci_dev->sysdata;
if (!dev->hose) {
struct pci_bus *b = pci_bus_b(pci_root_buses.next);
if (b) dev->hose = b->sysdata;
}
}
#endif
1999-12-05 16:10:37 -07:00
return 0;
2004-08-24 05:15:53 -06:00
out_free:
DRM(free)(priv, sizeof(*priv), DRM_MEM_FILES);
return ret;
1999-12-05 16:10:37 -07:00
}
2003-05-26 18:37:33 -06:00
/** No-op. */
2001-02-15 01:12:14 -07:00
int DRM(flush)(struct file *filp)
1999-12-05 16:10:37 -07:00
{
drm_file_t *priv = filp->private_data;
drm_device_t *dev = priv->dev;
2003-03-25 04:36:43 -07:00
DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
2004-04-08 06:25:31 -06:00
current->pid, (long)old_encode_dev(dev->device), dev->open_count);
1999-12-05 16:10:37 -07:00
return 0;
}
2003-05-26 18:37:33 -06:00
/** No-op. */
2001-02-15 01:12:14 -07:00
int DRM(fasync)(int fd, struct file *filp, int on)
1999-12-05 16:10:37 -07:00
{
drm_file_t *priv = filp->private_data;
drm_device_t *dev = priv->dev;
int retcode;
2001-02-15 01:12:14 -07:00
2004-04-08 06:25:31 -06:00
DRM_DEBUG("fd = %d, device = 0x%lx\n", fd, (long)old_encode_dev(dev->device));
1999-12-05 16:10:37 -07:00
retcode = fasync_helper(fd, filp, on, &dev->buf_async);
if (retcode < 0) return retcode;
return 0;
}
2003-05-26 18:37:33 -06:00
/** No-op. */
unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
{
return 0;
}
1999-12-05 16:10:37 -07:00
2003-05-26 18:37:33 -06:00
/** No-op. */
ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count, loff_t *off)
{
return 0;
}