1 /*        $NetBSD: mga_drv.c,v 1.5 2021/12/18 23:45:32 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.5 2021/12/18 23:45:32 riastradh Exp $");
36 
37 #include <linux/module.h>
38 
39 #include <drm/drm_drv.h>
40 #include <drm/drm_pciids.h>
41 
42 #include "mga_drv.h"
43 
44 static struct pci_device_id pciidlist[] = {
45           mga_PCI_IDS
46 };
47 
48 static const struct file_operations mga_driver_fops = {
49           .owner = THIS_MODULE,
50           .open = drm_open,
51           .release = drm_release,
52           .unlocked_ioctl = drm_ioctl,
53           .mmap = drm_legacy_mmap,
54           .poll = drm_poll,
55 #ifdef CONFIG_COMPAT
56           .compat_ioctl = mga_compat_ioctl,
57 #endif
58           .llseek = noop_llseek,
59 };
60 
61 static struct drm_driver driver = {
62           .driver_features =
63               DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_LEGACY |
64               DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ,
65           .dev_priv_size = sizeof(drm_mga_buf_priv_t),
66           .load = mga_driver_load,
67           .unload = mga_driver_unload,
68           .lastclose = mga_driver_lastclose,
69           .dma_quiescent = mga_driver_dma_quiescent,
70           .get_vblank_counter = mga_get_vblank_counter,
71           .enable_vblank = mga_enable_vblank,
72           .disable_vblank = mga_disable_vblank,
73           .irq_preinstall = mga_driver_irq_preinstall,
74           .irq_postinstall = mga_driver_irq_postinstall,
75           .irq_uninstall = mga_driver_irq_uninstall,
76           .irq_handler = mga_driver_irq_handler,
77 #ifdef __NetBSD__
78           .request_irq = drm_pci_request_irq,
79           .free_irq = drm_pci_free_irq,
80 #endif
81           .ioctls = mga_ioctls,
82           .dma_ioctl = mga_dma_buffers,
83           .fops = &mga_driver_fops,
84           .name = DRIVER_NAME,
85           .desc = DRIVER_DESC,
86           .date = DRIVER_DATE,
87           .major = DRIVER_MAJOR,
88           .minor = DRIVER_MINOR,
89           .patchlevel = DRIVER_PATCHLEVEL,
90 };
91 
92 static struct pci_driver mga_pci_driver = {
93           .name = DRIVER_NAME,
94           .id_table = pciidlist,
95 };
96 
mga_init(void)97 static int __init mga_init(void)
98 {
99           driver.num_ioctls = mga_max_ioctl;
100           return drm_legacy_pci_init(&driver, &mga_pci_driver);
101 }
102 
mga_exit(void)103 static void __exit mga_exit(void)
104 {
105           drm_legacy_pci_exit(&driver, &mga_pci_driver);
106 }
107 
108 module_init(mga_init);
109 module_exit(mga_exit);
110 
111 MODULE_AUTHOR(DRIVER_AUTHOR);
112 MODULE_DESCRIPTION(DRIVER_DESC);
113 MODULE_LICENSE("GPL and additional rights");
114