]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/drm/savage_drv.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / drm / savage_drv.c
1 /* savage_drv.c -- Savage DRI driver
2  */
3 /*-
4  * Copyright 2005 Eric Anholt
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Eric Anholt <anholt@FreeBSD.org>
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include "dev/drm/drmP.h"
33 #include "dev/drm/drm.h"
34 #include "dev/drm/savage_drm.h"
35 #include "dev/drm/savage_drv.h"
36 #include "dev/drm/drm_pciids.h"
37
38 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
39 static drm_pci_id_list_t savage_pciidlist[] = {
40         savage_PCI_IDS
41 };
42
43 static void savage_configure(struct drm_device *dev)
44 {
45         dev->driver->driver_features =
46             DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
47             DRIVER_HAVE_DMA;
48
49         dev->driver->buf_priv_size      = sizeof(drm_savage_buf_priv_t);
50         dev->driver->load               = savage_driver_load;
51         dev->driver->firstopen          = savage_driver_firstopen;
52         dev->driver->lastclose          = savage_driver_lastclose;
53         dev->driver->unload             = savage_driver_unload;
54         dev->driver->reclaim_buffers_locked = savage_reclaim_buffers;
55         dev->driver->dma_ioctl          = savage_bci_buffers;
56
57         dev->driver->ioctls             = savage_ioctls;
58         dev->driver->max_ioctl          = savage_max_ioctl;
59
60         dev->driver->name               = DRIVER_NAME;
61         dev->driver->desc               = DRIVER_DESC;
62         dev->driver->date               = DRIVER_DATE;
63         dev->driver->major              = DRIVER_MAJOR;
64         dev->driver->minor              = DRIVER_MINOR;
65         dev->driver->patchlevel         = DRIVER_PATCHLEVEL;
66 }
67
68 static int
69 savage_probe(device_t kdev)
70 {
71         return drm_probe(kdev, savage_pciidlist);
72 }
73
74 static int
75 savage_attach(device_t kdev)
76 {
77         struct drm_device *dev = device_get_softc(kdev);
78
79         dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
80             M_WAITOK | M_ZERO);
81
82         savage_configure(dev);
83
84         return drm_attach(kdev, savage_pciidlist);
85 }
86
87 static int
88 savage_detach(device_t kdev)
89 {
90         struct drm_device *dev = device_get_softc(kdev);
91         int ret;
92
93         ret = drm_detach(kdev);
94
95         free(dev->driver, DRM_MEM_DRIVER);
96
97         return ret;
98 }
99
100 static device_method_t savage_methods[] = {
101         /* Device interface */
102         DEVMETHOD(device_probe,         savage_probe),
103         DEVMETHOD(device_attach,        savage_attach),
104         DEVMETHOD(device_detach,        savage_detach),
105
106         { 0, 0 }
107 };
108
109 static driver_t savage_driver = {
110         "drm",
111         savage_methods,
112         sizeof(struct drm_device)
113 };
114
115 extern devclass_t drm_devclass;
116 #if __FreeBSD_version >= 700010
117 DRIVER_MODULE(savage, vgapci, savage_driver, drm_devclass, 0, 0);
118 #else
119 DRIVER_MODULE(savage, pci, savage_driver, drm_devclass, 0, 0);
120 #endif
121 MODULE_DEPEND(savage, drm, 1, 1, 1);