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