No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / mga_drv.c
blobe615114e995cc76c05e72fb18f7067cc7cc9a3b3
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.
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:
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.
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.
28 * Authors:
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
34 #include "drmP.h"
35 #include "drm.h"
36 #include "mga_drm.h"
37 #include "mga_drv.h"
38 #include "drm_pciids.h"
40 #ifdef __NetBSD__
41 #include <dev/pci/pcivar.h>
42 #include <dev/pci/pcidevs.h>
43 #endif
45 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
46 static drm_pci_id_list_t mga_pciidlist[] = {
47 mga_PCI_IDS
50 #ifdef __NetBSD__
51 static int mgadev_match(struct pci_attach_args *pa);
52 static int
53 mgadev_match(struct pci_attach_args *pa)
56 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_HINT &&
57 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_HINT_HB1)
58 return 1;
59 return 0;
61 #endif
64 /**
65 * Determine if the device really is AGP or not.
67 * In addition to the usual tests performed by \c drm_device_is_agp, this
68 * function detects PCI G450 cards that appear to the system exactly like
69 * AGP G450 cards.
71 * \param dev The device to be tested.
73 * \returns
74 * If the device is a PCI G450, zero is returned. Otherwise non-zero is
75 * returned.
77 * \bug
78 * This function needs to be filled in! The implementation in
79 * linux-core/mga_drv.c shows what needs to be done.
81 static int mga_driver_device_is_agp(struct drm_device * dev)
83 /* There are PCI versions of the G450. These cards have the
84 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
85 * bridge chip. We detect these cards, which are not currently
86 * supported by this driver, by looking at the device ID of the
87 * bus the "card" is on. If vendor is 0x3388 (Hint Corp) and the
88 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
89 * device.
91 #if defined(__FreeBSD__)
92 device_t bus;
94 #if __FreeBSD_version >= 700010
95 bus = device_get_parent(device_get_parent(dev->device));
96 #else
97 bus = device_get_parent(dev->device);
98 #endif
99 if (pci_get_device(dev->device) == 0x0525 &&
100 pci_get_vendor(bus) == 0x3388 &&
101 pci_get_device(bus) == 0x0021)
102 #else
103 struct pci_attach_args pa;
105 if (PCI_PRODUCT(dev->pa.pa_id) == PCI_PRODUCT_MATROX_G400_AGP &&
106 pci_find_device(&pa, mgadev_match))
107 #endif
108 return DRM_IS_NOT_AGP;
109 else
110 return DRM_MIGHT_BE_AGP;
113 static void mga_configure(struct drm_device *dev)
115 dev->driver->driver_features =
116 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
117 DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
119 dev->driver->buf_priv_size = sizeof(drm_mga_buf_priv_t);
120 dev->driver->load = mga_driver_load;
121 dev->driver->unload = mga_driver_unload;
122 dev->driver->lastclose = mga_driver_lastclose;
123 dev->driver->get_vblank_counter = mga_get_vblank_counter;
124 dev->driver->enable_vblank = mga_enable_vblank;
125 dev->driver->disable_vblank = mga_disable_vblank;
126 dev->driver->irq_preinstall = mga_driver_irq_preinstall;
127 dev->driver->irq_postinstall = mga_driver_irq_postinstall;
128 dev->driver->irq_uninstall = mga_driver_irq_uninstall;
129 dev->driver->irq_handler = mga_driver_irq_handler;
130 dev->driver->dma_ioctl = mga_dma_buffers;
131 dev->driver->dma_quiescent = mga_driver_dma_quiescent;
132 dev->driver->device_is_agp = mga_driver_device_is_agp;
134 dev->driver->ioctls = mga_ioctls;
135 dev->driver->max_ioctl = mga_max_ioctl;
137 dev->driver->name = DRIVER_NAME;
138 dev->driver->desc = DRIVER_DESC;
139 dev->driver->date = DRIVER_DATE;
140 dev->driver->major = DRIVER_MAJOR;
141 dev->driver->minor = DRIVER_MINOR;
142 dev->driver->patchlevel = DRIVER_PATCHLEVEL;
145 #if defined(__FreeBSD__)
147 static int
148 mga_probe(device_t kdev)
150 return drm_probe(kdev, mga_pciidlist);
153 static int
154 mga_attach(device_t kdev)
156 struct drm_device *dev = device_get_softc(kdev);
158 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
159 M_WAITOK | M_ZERO);
161 mga_configure(dev);
163 return drm_attach(kdev, mga_pciidlist);
166 static int
167 mga_detach(device_t kdev)
169 struct drm_device *dev = device_get_softc(kdev);
170 int ret;
172 ret = drm_detach(kdev);
174 free(dev->driver, DRM_MEM_DRIVER);
176 return ret;
179 static device_method_t mga_methods[] = {
180 /* Device interface */
181 DEVMETHOD(device_probe, mga_probe),
182 DEVMETHOD(device_attach, mga_attach),
183 DEVMETHOD(device_detach, mga_detach),
185 { 0, 0 }
188 static driver_t mga_driver = {
189 "drm",
190 mga_methods,
191 sizeof(struct drm_device)
194 extern devclass_t drm_devclass;
195 #if __FreeBSD_version >= 700010
196 DRIVER_MODULE(mga, vgapci, mga_driver, drm_devclass, 0, 0);
197 #else
198 DRIVER_MODULE(mga, pci, mga_driver, drm_devclass, 0, 0);
199 #endif
200 MODULE_DEPEND(mga, drm, 1, 1, 1);
202 #elif defined(__NetBSD__)
204 static int
205 mgadrm_probe(device_t parent, cfdata_t match, void *aux)
207 struct pci_attach_args *pa = aux;
209 return drm_probe(pa, mga_pciidlist);
212 static void
213 mgadrm_attach(device_t parent, device_t self, void *aux)
215 struct pci_attach_args *pa = aux;
216 struct drm_device *dev = device_private(self);
218 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
219 M_WAITOK | M_ZERO);
221 mga_configure(dev);
223 drm_attach(self, pa, mga_pciidlist);
226 CFATTACH_DECL_NEW(mgadrm, sizeof(struct drm_device),
227 mgadrm_probe, mgadrm_attach, drm_detach, NULL);
229 #ifdef _MODULE
231 MODULE(MODULE_CLASS_DRIVER, mgadrm, NULL);
233 CFDRIVER_DECL(mgadrm, DV_DULL, NULL);
234 extern struct cfattach mgadrm_ca;
235 static int drmloc[] = { -1 };
236 static struct cfparent drmparent = {
237 "drm", "vga", DVUNIT_ANY
239 static struct cfdata mgadrm_cfdata[] = {
241 .cf_name = "mgadrm",
242 .cf_atname = "mgadrm",
243 .cf_unit = 0,
244 .cf_fstate = FSTATE_STAR,
245 .cf_loc = drmloc,
246 .cf_flags = 0,
247 .cf_pspec = &drmparent,
249 { NULL }
252 static int
253 mgadrm_modcmd(modcmd_t cmd, void *arg)
255 int err;
257 switch (cmd) {
258 case MODULE_CMD_INIT:
259 err = config_cfdriver_attach(&mgadrm_cd);
260 if (err)
261 return err;
262 err = config_cfattach_attach("mgadrm", &mgadrm_ca);
263 if (err) {
264 config_cfdriver_detach(&mgadrm_cd);
265 return err;
267 err = config_cfdata_attach(mgadrm_cfdata, 1);
268 if (err) {
269 config_cfattach_detach("mgadrm", &mgadrm_ca);
270 config_cfdriver_detach(&mgadrm_cd);
271 return err;
273 return 0;
274 case MODULE_CMD_FINI:
275 err = config_cfdata_detach(mgadrm_cfdata);
276 if (err)
277 return err;
278 config_cfattach_detach("mgadrm", &mgadrm_ca);
279 config_cfdriver_detach(&mgadrm_cd);
280 return 0;
281 default:
282 return ENOTTY;
285 #endif /* _MODULE */
287 #endif