Back to home page

OSCL-LXR

 
 

    


0001 /* sis.c -- sis driver -*- linux-c -*-
0002  *
0003  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
0004  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
0005  * All Rights Reserved.
0006  *
0007  * Permission is hereby granted, free of charge, to any person obtaining a
0008  * copy of this software and associated documentation files (the "Software"),
0009  * to deal in the Software without restriction, including without limitation
0010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0011  * and/or sell copies of the Software, and to permit persons to whom the
0012  * Software is furnished to do so, subject to the following conditions:
0013  *
0014  * The above copyright notice and this permission notice (including the next
0015  * paragraph) shall be included in all copies or substantial portions of the
0016  * Software.
0017  *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0021  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0022  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0023  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0024  * DEALINGS IN THE SOFTWARE.
0025  *
0026  */
0027 
0028 #include <linux/module.h>
0029 #include <linux/pci.h>
0030 
0031 #include <drm/drm_drv.h>
0032 #include <drm/drm_file.h>
0033 #include <drm/drm_pciids.h>
0034 #include <drm/sis_drm.h>
0035 
0036 #include "sis_drv.h"
0037 
0038 static struct pci_device_id pciidlist[] = {
0039     sisdrv_PCI_IDS
0040 };
0041 
0042 static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
0043 {
0044     struct pci_dev *pdev = to_pci_dev(dev->dev);
0045     drm_sis_private_t *dev_priv;
0046 
0047     pci_set_master(pdev);
0048 
0049     dev_priv = kzalloc(sizeof(drm_sis_private_t), GFP_KERNEL);
0050     if (dev_priv == NULL)
0051         return -ENOMEM;
0052 
0053     idr_init(&dev_priv->object_idr);
0054     dev->dev_private = (void *)dev_priv;
0055     dev_priv->chipset = chipset;
0056 
0057     return 0;
0058 }
0059 
0060 static void sis_driver_unload(struct drm_device *dev)
0061 {
0062     drm_sis_private_t *dev_priv = dev->dev_private;
0063 
0064     idr_destroy(&dev_priv->object_idr);
0065 
0066     kfree(dev_priv);
0067 }
0068 
0069 static const struct file_operations sis_driver_fops = {
0070     .owner = THIS_MODULE,
0071     .open = drm_open,
0072     .release = drm_release,
0073     .unlocked_ioctl = drm_ioctl,
0074     .mmap = drm_legacy_mmap,
0075     .poll = drm_poll,
0076     .compat_ioctl = drm_compat_ioctl,
0077     .llseek = noop_llseek,
0078 };
0079 
0080 static int sis_driver_open(struct drm_device *dev, struct drm_file *file)
0081 {
0082     struct sis_file_private *file_priv;
0083 
0084     DRM_DEBUG_DRIVER("\n");
0085     file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
0086     if (!file_priv)
0087         return -ENOMEM;
0088 
0089     file->driver_priv = file_priv;
0090 
0091     INIT_LIST_HEAD(&file_priv->obj_list);
0092 
0093     return 0;
0094 }
0095 
0096 static void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
0097 {
0098     struct sis_file_private *file_priv = file->driver_priv;
0099 
0100     kfree(file_priv);
0101 }
0102 
0103 static struct drm_driver driver = {
0104     .driver_features = DRIVER_USE_AGP | DRIVER_LEGACY,
0105     .load = sis_driver_load,
0106     .unload = sis_driver_unload,
0107     .open = sis_driver_open,
0108     .preclose = sis_reclaim_buffers_locked,
0109     .postclose = sis_driver_postclose,
0110     .dma_quiescent = sis_idle,
0111     .lastclose = sis_lastclose,
0112     .ioctls = sis_ioctls,
0113     .fops = &sis_driver_fops,
0114     .name = DRIVER_NAME,
0115     .desc = DRIVER_DESC,
0116     .date = DRIVER_DATE,
0117     .major = DRIVER_MAJOR,
0118     .minor = DRIVER_MINOR,
0119     .patchlevel = DRIVER_PATCHLEVEL,
0120 };
0121 
0122 static struct pci_driver sis_pci_driver = {
0123     .name = DRIVER_NAME,
0124     .id_table = pciidlist,
0125 };
0126 
0127 static int __init sis_init(void)
0128 {
0129     driver.num_ioctls = sis_max_ioctl;
0130     return drm_legacy_pci_init(&driver, &sis_pci_driver);
0131 }
0132 
0133 static void __exit sis_exit(void)
0134 {
0135     drm_legacy_pci_exit(&driver, &sis_pci_driver);
0136 }
0137 
0138 module_init(sis_init);
0139 module_exit(sis_exit);
0140 
0141 MODULE_AUTHOR(DRIVER_AUTHOR);
0142 MODULE_DESCRIPTION(DRIVER_DESC);
0143 MODULE_LICENSE("GPL and additional rights");