xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/mga/mga_drv.c (revision cef8759bd76c1b621f8eab8faa6f208faabc2e15)
1 /*	$NetBSD: mga_drv.c,v 1.4 2018/08/28 03:41:38 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.4 2018/08/28 03:41:38 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 
45 static int mga_driver_device_is_agp(struct drm_device *dev);
46 
47 static struct pci_device_id pciidlist[] = {
48 	mga_PCI_IDS
49 };
50 
51 static 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 
64 static 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 	.set_unique = drm_pci_set_unique,
74 	.dma_quiescent = mga_driver_dma_quiescent,
75 	.device_is_agp = mga_driver_device_is_agp,
76 	.get_vblank_counter = mga_get_vblank_counter,
77 	.enable_vblank = mga_enable_vblank,
78 	.disable_vblank = mga_disable_vblank,
79 	.irq_preinstall = mga_driver_irq_preinstall,
80 	.irq_postinstall = mga_driver_irq_postinstall,
81 	.irq_uninstall = mga_driver_irq_uninstall,
82 	.irq_handler = mga_driver_irq_handler,
83 #ifdef __NetBSD__
84 	.request_irq = drm_pci_request_irq,
85 	.free_irq = drm_pci_free_irq,
86 #endif
87 	.ioctls = mga_ioctls,
88 	.dma_ioctl = mga_dma_buffers,
89 	.fops = &mga_driver_fops,
90 	.name = DRIVER_NAME,
91 	.desc = DRIVER_DESC,
92 	.date = DRIVER_DATE,
93 	.major = DRIVER_MAJOR,
94 	.minor = DRIVER_MINOR,
95 	.patchlevel = DRIVER_PATCHLEVEL,
96 };
97 
98 static struct pci_driver mga_pci_driver = {
99 	.name = DRIVER_NAME,
100 	.id_table = pciidlist,
101 };
102 
103 static int __init mga_init(void)
104 {
105 	driver.num_ioctls = mga_max_ioctl;
106 	return drm_pci_init(&driver, &mga_pci_driver);
107 }
108 
109 static void __exit mga_exit(void)
110 {
111 	drm_pci_exit(&driver, &mga_pci_driver);
112 }
113 
114 module_init(mga_init);
115 module_exit(mga_exit);
116 
117 MODULE_AUTHOR(DRIVER_AUTHOR);
118 MODULE_DESCRIPTION(DRIVER_DESC);
119 MODULE_LICENSE("GPL and additional rights");
120 
121 /**
122  * Determine if the device really is AGP or not.
123  *
124  * In addition to the usual tests performed by \c drm_device_is_agp, this
125  * function detects PCI G450 cards that appear to the system exactly like
126  * AGP G450 cards.
127  *
128  * \param dev   The device to be tested.
129  *
130  * \returns
131  * If the device is a PCI G450, zero is returned.  Otherwise 2 is returned.
132  */
133 static int mga_driver_device_is_agp(struct drm_device *dev)
134 {
135 	const struct pci_dev *const pdev = dev->pdev;
136 
137 	/* There are PCI versions of the G450.  These cards have the
138 	 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
139 	 * bridge chip.  We detect these cards, which are not currently
140 	 * supported by this driver, by looking at the device ID of the
141 	 * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
142 	 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
143 	 * device.
144 	 */
145 
146 	if ((pdev->device == 0x0525) && pdev->bus->self
147 	    && (pdev->bus->self->vendor == 0x3388)
148 	    && (pdev->bus->self->device == 0x0021)) {
149 		return 0;
150 	}
151 
152 	return 2;
153 }
154