mga_drv.c revision 1.2
1/* $NetBSD: mga_drv.c,v 1.2 2018/08/27 04:58:24 riastradh Exp $ */ 2 3/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*- 4 * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com 5 * 6 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 7 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 8 * All Rights Reserved. 9 * 10 * Permission is hereby granted, free of charge, to any person obtaining a 11 * copy of this software and associated documentation files (the "Software"), 12 * to deal in the Software without restriction, including without limitation 13 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 * and/or sell copies of the Software, and to permit persons to whom the 15 * Software is furnished to do so, subject to the following conditions: 16 * 17 * The above copyright notice and this permission notice (including the next 18 * paragraph) shall be included in all copies or substantial portions of the 19 * Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 * OTHER DEALINGS IN THE SOFTWARE. 28 * 29 * Authors: 30 * Rickard E. (Rik) Faith <faith@valinux.com> 31 * Gareth Hughes <gareth@valinux.com> 32 */ 33 34#include <sys/cdefs.h> 35__KERNEL_RCSID(0, "$NetBSD: mga_drv.c,v 1.2 2018/08/27 04:58:24 riastradh Exp $"); 36 37#include <linux/module.h> 38 39#include <drm/drmP.h> 40#include <drm/mga_drm.h> 41#include "mga_drv.h" 42 43#include <drm/drm_pciids.h> 44 45static int mga_driver_device_is_agp(struct drm_device *dev); 46 47static struct pci_device_id pciidlist[] = { 48 mga_PCI_IDS 49}; 50 51static const struct file_operations mga_driver_fops = { 52 .owner = THIS_MODULE, 53 .open = drm_open, 54 .release = drm_release, 55 .unlocked_ioctl = drm_ioctl, 56 .mmap = drm_legacy_mmap, 57 .poll = drm_poll, 58#ifdef CONFIG_COMPAT 59 .compat_ioctl = mga_compat_ioctl, 60#endif 61 .llseek = noop_llseek, 62}; 63 64static struct drm_driver driver = { 65 .driver_features = 66 DRIVER_USE_AGP | DRIVER_PCI_DMA | 67 DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED, 68 .dev_priv_size = sizeof(drm_mga_buf_priv_t), 69 .load = mga_driver_load, 70 .unload = mga_driver_unload, 71 .lastclose = mga_driver_lastclose, 72 .set_busid = drm_pci_set_busid, 73 .dma_quiescent = mga_driver_dma_quiescent, 74 .device_is_agp = mga_driver_device_is_agp, 75 .get_vblank_counter = mga_get_vblank_counter, 76 .enable_vblank = mga_enable_vblank, 77 .disable_vblank = mga_disable_vblank, 78 .irq_preinstall = mga_driver_irq_preinstall, 79 .irq_postinstall = mga_driver_irq_postinstall, 80 .irq_uninstall = mga_driver_irq_uninstall, 81 .irq_handler = mga_driver_irq_handler, 82 .ioctls = mga_ioctls, 83 .dma_ioctl = mga_dma_buffers, 84 .fops = &mga_driver_fops, 85 .name = DRIVER_NAME, 86 .desc = DRIVER_DESC, 87 .date = DRIVER_DATE, 88 .major = DRIVER_MAJOR, 89 .minor = DRIVER_MINOR, 90 .patchlevel = DRIVER_PATCHLEVEL, 91}; 92 93static struct pci_driver mga_pci_driver = { 94 .name = DRIVER_NAME, 95 .id_table = pciidlist, 96}; 97 98static int __init mga_init(void) 99{ 100 driver.num_ioctls = mga_max_ioctl; 101 return drm_pci_init(&driver, &mga_pci_driver); 102} 103 104static void __exit mga_exit(void) 105{ 106 drm_pci_exit(&driver, &mga_pci_driver); 107} 108 109module_init(mga_init); 110module_exit(mga_exit); 111 112MODULE_AUTHOR(DRIVER_AUTHOR); 113MODULE_DESCRIPTION(DRIVER_DESC); 114MODULE_LICENSE("GPL and additional rights"); 115 116/** 117 * Determine if the device really is AGP or not. 118 * 119 * In addition to the usual tests performed by \c drm_device_is_agp, this 120 * function detects PCI G450 cards that appear to the system exactly like 121 * AGP G450 cards. 122 * 123 * \param dev The device to be tested. 124 * 125 * \returns 126 * If the device is a PCI G450, zero is returned. Otherwise 2 is returned. 127 */ 128static int mga_driver_device_is_agp(struct drm_device *dev) 129{ 130 const struct pci_dev *const pdev = dev->pdev; 131 132 /* There are PCI versions of the G450. These cards have the 133 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI 134 * bridge chip. We detect these cards, which are not currently 135 * supported by this driver, by looking at the device ID of the 136 * bus the "card" is on. If vendor is 0x3388 (Hint Corp) and the 137 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the 138 * device. 139 */ 140 141 if ((pdev->device == 0x0525) && pdev->bus->self 142 && (pdev->bus->self->vendor == 0x3388) 143 && (pdev->bus->self->device == 0x0021)) { 144 return 0; 145 } 146 147 return 2; 148} 149