mga_drv.c revision 1.3
1/*	$NetBSD: mga_drv.c,v 1.3 2018/08/27 07:03:25 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.3 2018/08/27 07:03:25 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#ifdef __NetBSD__
83	.request_irq = drm_pci_request_irq,
84	.free_irq = drm_pci_free_irq,
85#endif
86	.ioctls = mga_ioctls,
87	.dma_ioctl = mga_dma_buffers,
88	.fops = &mga_driver_fops,
89	.name = DRIVER_NAME,
90	.desc = DRIVER_DESC,
91	.date = DRIVER_DATE,
92	.major = DRIVER_MAJOR,
93	.minor = DRIVER_MINOR,
94	.patchlevel = DRIVER_PATCHLEVEL,
95};
96
97static struct pci_driver mga_pci_driver = {
98	.name = DRIVER_NAME,
99	.id_table = pciidlist,
100};
101
102static int __init mga_init(void)
103{
104	driver.num_ioctls = mga_max_ioctl;
105	return drm_pci_init(&driver, &mga_pci_driver);
106}
107
108static void __exit mga_exit(void)
109{
110	drm_pci_exit(&driver, &mga_pci_driver);
111}
112
113module_init(mga_init);
114module_exit(mga_exit);
115
116MODULE_AUTHOR(DRIVER_AUTHOR);
117MODULE_DESCRIPTION(DRIVER_DESC);
118MODULE_LICENSE("GPL and additional rights");
119
120/**
121 * Determine if the device really is AGP or not.
122 *
123 * In addition to the usual tests performed by \c drm_device_is_agp, this
124 * function detects PCI G450 cards that appear to the system exactly like
125 * AGP G450 cards.
126 *
127 * \param dev   The device to be tested.
128 *
129 * \returns
130 * If the device is a PCI G450, zero is returned.  Otherwise 2 is returned.
131 */
132static int mga_driver_device_is_agp(struct drm_device *dev)
133{
134	const struct pci_dev *const pdev = dev->pdev;
135
136	/* There are PCI versions of the G450.  These cards have the
137	 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
138	 * bridge chip.  We detect these cards, which are not currently
139	 * supported by this driver, by looking at the device ID of the
140	 * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
141	 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
142	 * device.
143	 */
144
145	if ((pdev->device == 0x0525) && pdev->bus->self
146	    && (pdev->bus->self->vendor == 0x3388)
147	    && (pdev->bus->self->device == 0x0021)) {
148		return 0;
149	}
150
151	return 2;
152}
153