drm: Use an include directory hierarchy similar to the Linux one
[dragonfly.git] / sys / dev / drm / mga / mga_drv.c
1 /* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
2  * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
3  */
4 /*-
5  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7  * All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the next
17  * paragraph) shall be included in all copies or substantial portions of the
18  * Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * Authors:
29  *    Rickard E. (Rik) Faith <faith@valinux.com>
30  *    Gareth Hughes <gareth@valinux.com>
31  *
32  */
33
34 #include <drm/drmP.h>
35 #include "mga_drm.h"
36 #include "mga_drv.h"
37 #include <drm/drm_pciids.h>
38
39 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
40 static drm_pci_id_list_t mga_pciidlist[] = {
41         mga_PCI_IDS
42 };
43
44 /**
45  * Determine if the device really is AGP or not.
46  *
47  * In addition to the usual tests performed by \c drm_device_is_agp, this
48  * function detects PCI G450 cards that appear to the system exactly like
49  * AGP G450 cards.
50  *
51  * \param dev   The device to be tested.
52  *
53  * \returns
54  * If the device is a PCI G450, zero is returned.  Otherwise non-zero is
55  * returned.
56  *
57  * \bug
58  * This function needs to be filled in!  The implementation in
59  * linux-core/mga_drv.c shows what needs to be done.
60  */
61 static int mga_driver_device_is_agp(struct drm_device * dev)
62 {
63         device_t bus;
64
65         /* There are PCI versions of the G450.  These cards have the
66          * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
67          * bridge chip.  We detect these cards, which are not currently
68          * supported by this driver, by looking at the device ID of the
69          * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
70          * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
71          * device.
72          */
73         bus = device_get_parent(device_get_parent(dev->device));
74         if (pci_get_device(dev->device) == 0x0525 &&
75             pci_get_vendor(bus) == 0x3388 &&
76             pci_get_device(bus) == 0x0021)
77                 return DRM_IS_NOT_AGP;
78         else
79                 return DRM_MIGHT_BE_AGP;
80 }
81
82 static void mga_configure(struct drm_device *dev)
83 {
84         dev->driver->driver_features =
85             DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
86             DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
87
88         dev->driver->buf_priv_size      = sizeof(drm_mga_buf_priv_t);
89         dev->driver->load               = mga_driver_load;
90         dev->driver->unload             = mga_driver_unload;
91         dev->driver->lastclose          = mga_driver_lastclose;
92         dev->driver->get_vblank_counter = mga_get_vblank_counter;
93         dev->driver->enable_vblank      = mga_enable_vblank;
94         dev->driver->disable_vblank     = mga_disable_vblank;
95         dev->driver->irq_preinstall     = mga_driver_irq_preinstall;
96         dev->driver->irq_postinstall    = mga_driver_irq_postinstall;
97         dev->driver->irq_uninstall      = mga_driver_irq_uninstall;
98         dev->driver->irq_handler        = mga_driver_irq_handler;
99         dev->driver->dma_ioctl          = mga_dma_buffers;
100         dev->driver->dma_quiescent      = mga_driver_dma_quiescent;
101         dev->driver->device_is_agp      = mga_driver_device_is_agp;
102
103         dev->driver->ioctls             = mga_ioctls;
104         dev->driver->max_ioctl          = mga_max_ioctl;
105
106         dev->driver->name               = DRIVER_NAME;
107         dev->driver->desc               = DRIVER_DESC;
108         dev->driver->date               = DRIVER_DATE;
109         dev->driver->major              = DRIVER_MAJOR;
110         dev->driver->minor              = DRIVER_MINOR;
111         dev->driver->patchlevel         = DRIVER_PATCHLEVEL;
112 }
113
114 static int
115 mga_probe(device_t kdev)
116 {
117         return drm_probe(kdev, mga_pciidlist);
118 }
119
120 static int
121 mga_attach(device_t kdev)
122 {
123         struct drm_device *dev = device_get_softc(kdev);
124
125         dev->driver = kmalloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
126             M_WAITOK | M_ZERO);
127
128         mga_configure(dev);
129
130         return drm_attach(kdev, mga_pciidlist);
131 }
132
133 static int
134 mga_detach(device_t kdev)
135 {
136         struct drm_device *dev = device_get_softc(kdev);
137         int ret;
138
139         ret = drm_detach(kdev);
140
141         kfree(dev->driver, DRM_MEM_DRIVER);
142
143         return ret;
144 }
145
146 static device_method_t mga_methods[] = {
147         /* Device interface */
148         DEVMETHOD(device_probe,         mga_probe),
149         DEVMETHOD(device_attach,        mga_attach),
150         DEVMETHOD(device_detach,        mga_detach),
151
152         DEVMETHOD_END
153 };
154
155 static driver_t mga_driver = {
156         "drm",
157         mga_methods,
158         sizeof(struct drm_device)
159 };
160
161 extern devclass_t drm_devclass;
162 DRIVER_MODULE(mga, vgapci, mga_driver, drm_devclass, NULL, NULL);
163 MODULE_DEPEND(mga, drm, 1, 1, 1);