1 /* $NetBSD: r128_drv.c,v 1.5 2021/12/18 23:45:42 riastradh Exp $ */
2
3 /* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
4 * Created: Mon Dec 13 09:47:27 1999 by faith@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: r128_drv.c,v 1.5 2021/12/18 23:45:42 riastradh Exp $");
36
37 #include <linux/module.h>
38 #include <linux/pci.h>
39
40 #include <drm/drm_drv.h>
41 #include <drm/drm_file.h>
42 #include <drm/drm_pciids.h>
43 #include <drm/drm_vblank.h>
44 #include <drm/r128_drm.h>
45
46 #include "r128_drv.h"
47
48 static struct pci_device_id pciidlist[] = {
49 r128_PCI_IDS
50 };
51
52 static const struct file_operations r128_driver_fops = {
53 .owner = THIS_MODULE,
54 .open = drm_open,
55 .release = drm_release,
56 .unlocked_ioctl = drm_ioctl,
57 .mmap = drm_legacy_mmap,
58 .poll = drm_poll,
59 #ifdef CONFIG_COMPAT
60 .compat_ioctl = r128_compat_ioctl,
61 #endif
62 .llseek = noop_llseek,
63 };
64
65 static struct drm_driver driver = {
66 .driver_features =
67 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG | DRIVER_LEGACY |
68 DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ,
69 .dev_priv_size = sizeof(drm_r128_buf_priv_t),
70 .load = r128_driver_load,
71 .preclose = r128_driver_preclose,
72 .lastclose = r128_driver_lastclose,
73 .get_vblank_counter = r128_get_vblank_counter,
74 .enable_vblank = r128_enable_vblank,
75 .disable_vblank = r128_disable_vblank,
76 .irq_preinstall = r128_driver_irq_preinstall,
77 .irq_postinstall = r128_driver_irq_postinstall,
78 .irq_uninstall = r128_driver_irq_uninstall,
79 .irq_handler = r128_driver_irq_handler,
80 #ifdef __NetBSD__
81 .request_irq = drm_pci_request_irq,
82 .free_irq = drm_pci_free_irq,
83 #endif
84 .ioctls = r128_ioctls,
85 .dma_ioctl = r128_cce_buffers,
86 .fops = &r128_driver_fops,
87 .name = DRIVER_NAME,
88 .desc = DRIVER_DESC,
89 .date = DRIVER_DATE,
90 .major = DRIVER_MAJOR,
91 .minor = DRIVER_MINOR,
92 .patchlevel = DRIVER_PATCHLEVEL,
93 };
94
r128_driver_load(struct drm_device * dev,unsigned long flags)95 int r128_driver_load(struct drm_device *dev, unsigned long flags)
96 {
97 pci_set_master(dev->pdev);
98 return drm_vblank_init(dev, 1);
99 }
100
101 static struct pci_driver r128_pci_driver = {
102 .name = DRIVER_NAME,
103 .id_table = pciidlist,
104 };
105
r128_init(void)106 static int __init r128_init(void)
107 {
108 driver.num_ioctls = r128_max_ioctl;
109
110 return drm_legacy_pci_init(&driver, &r128_pci_driver);
111 }
112
r128_exit(void)113 static void __exit r128_exit(void)
114 {
115 drm_legacy_pci_exit(&driver, &r128_pci_driver);
116 }
117
118 module_init(r128_init);
119 module_exit(r128_exit);
120
121 MODULE_AUTHOR(DRIVER_AUTHOR);
122 MODULE_DESCRIPTION(DRIVER_DESC);
123 MODULE_LICENSE("GPL and additional rights");
124