xref: /freebsd-11-stable/sys/dev/drm/radeon_drv.c (revision 416ba5c74546f32a993436a99516d35008e9f384)
1 /* radeon_drv.c -- ATI Radeon driver -*- linux-c -*-
2  * Created: Wed Feb 14 17:10:04 2001 by gareth@valinux.com
3  */
4 /*-
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the next
16  * paragraph) shall be included in all copies or substantial portions of the
17  * Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Authors:
28  *    Gareth Hughes <gareth@valinux.com>
29  *
30  */
31 
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 
35 #include "dev/drm/drmP.h"
36 #include "dev/drm/drm.h"
37 #include "dev/drm/radeon_drm.h"
38 #include "dev/drm/radeon_drv.h"
39 #include "dev/drm/drm_pciids.h"
40 
41 int radeon_no_wb;
42 
43 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
44 static drm_pci_id_list_t radeon_pciidlist[] = {
45 	radeon_PCI_IDS
46 };
47 
radeon_configure(struct drm_device * dev)48 static void radeon_configure(struct drm_device *dev)
49 {
50 	dev->driver->driver_features =
51 	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
52 	    DRIVER_SG | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
53 
54 	dev->driver->buf_priv_size	= sizeof(drm_radeon_buf_priv_t);
55 	dev->driver->load		= radeon_driver_load;
56 	dev->driver->unload		= radeon_driver_unload;
57 	dev->driver->firstopen		= radeon_driver_firstopen;
58 	dev->driver->open		= radeon_driver_open;
59 	dev->driver->preclose		= radeon_driver_preclose;
60 	dev->driver->postclose		= radeon_driver_postclose;
61 	dev->driver->lastclose		= radeon_driver_lastclose;
62 	dev->driver->get_vblank_counter	= radeon_get_vblank_counter;
63 	dev->driver->enable_vblank	= radeon_enable_vblank;
64 	dev->driver->disable_vblank	= radeon_disable_vblank;
65 	dev->driver->irq_preinstall	= radeon_driver_irq_preinstall;
66 	dev->driver->irq_postinstall	= radeon_driver_irq_postinstall;
67 	dev->driver->irq_uninstall	= radeon_driver_irq_uninstall;
68 	dev->driver->irq_handler	= radeon_driver_irq_handler;
69 	dev->driver->dma_ioctl		= radeon_cp_buffers;
70 
71 	dev->driver->ioctls		= radeon_ioctls;
72 	dev->driver->max_ioctl		= radeon_max_ioctl;
73 
74 	dev->driver->name		= DRIVER_NAME;
75 	dev->driver->desc		= DRIVER_DESC;
76 	dev->driver->date		= DRIVER_DATE;
77 	dev->driver->major		= DRIVER_MAJOR;
78 	dev->driver->minor		= DRIVER_MINOR;
79 	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
80 }
81 
82 static int
radeon_probe(device_t kdev)83 radeon_probe(device_t kdev)
84 {
85 	return drm_probe(kdev, radeon_pciidlist);
86 }
87 
88 static int
radeon_attach(device_t kdev)89 radeon_attach(device_t kdev)
90 {
91 	struct drm_device *dev = device_get_softc(kdev);
92 
93 	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
94 	    M_WAITOK | M_ZERO);
95 
96 	radeon_configure(dev);
97 
98 	return drm_attach(kdev, radeon_pciidlist);
99 }
100 
101 static int
radeon_detach(device_t kdev)102 radeon_detach(device_t kdev)
103 {
104 	struct drm_device *dev = device_get_softc(kdev);
105 	int ret;
106 
107 	ret = drm_detach(kdev);
108 
109 	free(dev->driver, DRM_MEM_DRIVER);
110 
111 	return ret;
112 }
113 
114 static device_method_t radeon_methods[] = {
115 	/* Device interface */
116 	DEVMETHOD(device_probe,		radeon_probe),
117 	DEVMETHOD(device_attach,	radeon_attach),
118 	DEVMETHOD(device_detach,	radeon_detach),
119 
120 	{ 0, 0 }
121 };
122 
123 static driver_t radeon_driver = {
124 	"drm",
125 	radeon_methods,
126 	sizeof(struct drm_device)
127 };
128 
129 extern devclass_t drm_devclass;
130 DRIVER_MODULE(radeon, vgapci, radeon_driver, drm_devclass, 0, 0);
131 MODULE_DEPEND(radeon, drm, 1, 1, 1);
132