11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* sis.c -- sis driver -*- linux-c -*- 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * All Rights Reserved. 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Permission is hereby granted, free of charge, to any person obtaining a 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * copy of this software and associated documentation files (the "Software"), 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to deal in the Software without restriction, including without limitation 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the rights to use, copy, modify, merge, publish, distribute, sublicense, 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and/or sell copies of the Software, and to permit persons to whom the 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software is furnished to do so, subject to the following conditions: 13b5e89ed53ed8d24f83ba1941c07382af00ed238eDave Airlie * 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The above copyright notice and this permission notice (including the next 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * paragraph) shall be included in all copies or substantial portions of the 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software. 17b5e89ed53ed8d24f83ba1941c07382af00ed238eDave Airlie * 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DEALINGS IN THE SOFTWARE. 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 28e0cd3608135b2ed8eddbe3fdf048d22e0593d836Paul Gortmaker#include <linux/module.h> 29e0cd3608135b2ed8eddbe3fdf048d22e0593d836Paul Gortmaker 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "drmP.h" 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "sis_drm.h" 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "sis_drv.h" 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "drm_pciids.h" 35b5e89ed53ed8d24f83ba1941c07382af00ed238eDave Airlie 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct pci_device_id pciidlist[] = { 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sisdrv_PCI_IDS 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4084b1fd103dbbe01b5905db1444d3fc8afa9a7207Dave Airliestatic int sis_driver_load(struct drm_device *dev, unsigned long chipset) 41ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom{ 42ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom drm_sis_private_t *dev_priv; 43ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 44466e69b8b03b8c1987367912782bc12988ad8794Dave Airlie pci_set_master(dev->pdev); 45466e69b8b03b8c1987367912782bc12988ad8794Dave Airlie 469a298b2acd771d8a5c0004d8f8e4156c65b11f6bEric Anholt dev_priv = kzalloc(sizeof(drm_sis_private_t), GFP_KERNEL); 47ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom if (dev_priv == NULL) 4820caafa6ecb2487d9b223aa33e7cc704f912a758Eric Anholt return -ENOMEM; 49ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 50ebbd13c9d27ab013fdf7005829a80d504b0cb32eMárton Németh idr_init(&dev_priv->object_idr); 51ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom dev->dev_private = (void *)dev_priv; 52ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom dev_priv->chipset = chipset; 53ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 544e087a7a1f3884750790bda580e22e9eccd5f4faJesper Juhl return 0; 55ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom} 56ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 5784b1fd103dbbe01b5905db1444d3fc8afa9a7207Dave Airliestatic int sis_driver_unload(struct drm_device *dev) 58ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom{ 59ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom drm_sis_private_t *dev_priv = dev->dev_private; 60ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 616de8a748881f1cd9d795454da2b6db616d5ca3d7Daniel Vetter idr_remove_all(&dev_priv->object_idr); 626de8a748881f1cd9d795454da2b6db616d5ca3d7Daniel Vetter idr_destroy(&dev_priv->object_idr); 636de8a748881f1cd9d795454da2b6db616d5ca3d7Daniel Vetter 649a298b2acd771d8a5c0004d8f8e4156c65b11f6bEric Anholt kfree(dev_priv); 65ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 66ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom return 0; 67ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom} 68ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom 69e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Venstatic const struct file_operations sis_driver_fops = { 70e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .owner = THIS_MODULE, 71e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .open = drm_open, 72e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .release = drm_release, 73e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .unlocked_ioctl = drm_ioctl, 74e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .mmap = drm_mmap, 75e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .poll = drm_poll, 76e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .fasync = drm_fasync, 77e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .llseek = noop_llseek, 78e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven}; 79e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven 80fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetterstatic int sis_driver_open(struct drm_device *dev, struct drm_file *file) 81fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter{ 82fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter struct sis_file_private *file_priv; 83fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 84fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter DRM_DEBUG_DRIVER("\n"); 85fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL); 86fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter if (!file_priv) 87fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter return -ENOMEM; 88fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 89fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter file->driver_priv = file_priv; 90fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 91fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter INIT_LIST_HEAD(&file_priv->obj_list); 92fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 93fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter return 0; 94fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter} 95fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 96fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vettervoid sis_driver_postclose(struct drm_device *dev, struct drm_file *file) 97fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter{ 98fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter struct sis_file_private *file_priv = file->driver_priv; 99fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 100fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter kfree(file_priv); 101fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter} 102fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct drm_driver driver = { 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR, 105ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom .load = sis_driver_load, 106ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom .unload = sis_driver_unload, 107fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter .open = sis_driver_open, 108fdc0b8a63c1124bb025a2846d41531a123845740Daniel Vetter .postclose = sis_driver_postclose, 1097981bf7d494a6c4d45e22c54b0da887e5a67e705Thomas Hellstrom .dma_quiescent = sis_idle, 110ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom .reclaim_buffers = NULL, 111040ac32048d5efabd557c1e0a6ab8aec2c710c56Thomas Hellstrom .reclaim_buffers_idlelocked = sis_reclaim_buffers_locked, 112ce65a44de07f73ceda1749812b75086b7add408dThomas Hellstrom .lastclose = sis_lastclose, 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .ioctls = sis_ioctls, 114e08e96de986ceb2c6b683df0bd0c4ddd4f91dcfdArjan van de Ven .fops = &sis_driver_fops, 11522eae947bf76e236ba972f2f11cfd1b083b736adDave Airlie .name = DRIVER_NAME, 11622eae947bf76e236ba972f2f11cfd1b083b736adDave Airlie .desc = DRIVER_DESC, 11722eae947bf76e236ba972f2f11cfd1b083b736adDave Airlie .date = DRIVER_DATE, 11822eae947bf76e236ba972f2f11cfd1b083b736adDave Airlie .major = DRIVER_MAJOR, 11922eae947bf76e236ba972f2f11cfd1b083b736adDave Airlie .minor = DRIVER_MINOR, 12022eae947bf76e236ba972f2f11cfd1b083b736adDave Airlie .patchlevel = DRIVER_PATCHLEVEL, 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1238410ea3b95d105a5be5db501656f44bbb91197c1Dave Airliestatic struct pci_driver sis_pci_driver = { 1248410ea3b95d105a5be5db501656f44bbb91197c1Dave Airlie .name = DRIVER_NAME, 1258410ea3b95d105a5be5db501656f44bbb91197c1Dave Airlie .id_table = pciidlist, 1268410ea3b95d105a5be5db501656f44bbb91197c1Dave Airlie}; 1278410ea3b95d105a5be5db501656f44bbb91197c1Dave Airlie 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init sis_init(void) 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds driver.num_ioctls = sis_max_ioctl; 1318410ea3b95d105a5be5db501656f44bbb91197c1Dave Airlie return drm_pci_init(&driver, &sis_pci_driver); 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit sis_exit(void) 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1368410ea3b95d105a5be5db501656f44bbb91197c1Dave Airlie drm_pci_exit(&driver, &sis_pci_driver); 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(sis_init); 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(sis_exit); 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 142b5e89ed53ed8d24f83ba1941c07382af00ed238eDave AirlieMODULE_AUTHOR(DRIVER_AUTHOR); 143b5e89ed53ed8d24f83ba1941c07382af00ed238eDave AirlieMODULE_DESCRIPTION(DRIVER_DESC); 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL and additional rights"); 145