drm: Use an include directory hierarchy similar to the Linux one
[dragonfly.git] / sys / dev / drm / savage / 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 <drm/drmP.h>
30 #include "savage_drm.h"
31 #include "savage_drv.h"
32 #include <drm/drm_pciids.h>
33
34 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
35 static drm_pci_id_list_t savage_pciidlist[] = {
36         savage_PCI_IDS
37 };
38
39 static void savage_configure(struct drm_device *dev)
40 {
41         dev->driver->driver_features =
42             DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
43             DRIVER_HAVE_DMA;
44
45         dev->driver->buf_priv_size      = sizeof(drm_savage_buf_priv_t);
46         dev->driver->load               = savage_driver_load;
47         dev->driver->firstopen          = savage_driver_firstopen;
48         dev->driver->lastclose          = savage_driver_lastclose;
49         dev->driver->unload             = savage_driver_unload;
50         dev->driver->reclaim_buffers_locked = savage_reclaim_buffers;
51         dev->driver->dma_ioctl          = savage_bci_buffers;
52
53         dev->driver->ioctls             = savage_ioctls;
54         dev->driver->max_ioctl          = savage_max_ioctl;
55
56         dev->driver->name               = DRIVER_NAME;
57         dev->driver->desc               = DRIVER_DESC;
58         dev->driver->date               = DRIVER_DATE;
59         dev->driver->major              = DRIVER_MAJOR;
60         dev->driver->minor              = DRIVER_MINOR;
61         dev->driver->patchlevel         = DRIVER_PATCHLEVEL;
62 }
63
64 static int
65 savage_probe(device_t kdev)
66 {
67         return drm_probe(kdev, savage_pciidlist);
68 }
69
70 static int
71 savage_attach(device_t kdev)
72 {
73         struct drm_device *dev = device_get_softc(kdev);
74
75         dev->driver = kmalloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
76             M_WAITOK | M_ZERO);
77
78         savage_configure(dev);
79
80         return drm_attach(kdev, savage_pciidlist);
81 }
82
83 static int
84 savage_detach(device_t kdev)
85 {
86         struct drm_device *dev = device_get_softc(kdev);
87         int ret;
88
89         ret = drm_detach(kdev);
90
91         kfree(dev->driver, DRM_MEM_DRIVER);
92
93         return ret;
94 }
95
96 static device_method_t savage_methods[] = {
97         /* Device interface */
98         DEVMETHOD(device_probe,         savage_probe),
99         DEVMETHOD(device_attach,        savage_attach),
100         DEVMETHOD(device_detach,        savage_detach),
101
102         DEVMETHOD_END
103 };
104
105 static driver_t savage_driver = {
106         "drm",
107         savage_methods,
108         sizeof(struct drm_device)
109 };
110
111 extern devclass_t drm_devclass;
112 DRIVER_MODULE(savage, vgapci, savage_driver, drm_devclass, NULL, NULL);
113 MODULE_DEPEND(savage, drm, 1, 1, 1);