1 /* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
2 * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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
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.
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
38 #include "drm_pciids.h"
41 #include <dev/pci/pcivar.h>
42 #include <dev/pci/pcidevs.h>
45 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
46 static drm_pci_id_list_t mga_pciidlist
[] = {
51 static int mgadev_match(struct pci_attach_args
*pa
);
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
)
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
71 * \param dev The device to be tested.
74 * If the device is a PCI G450, zero is returned. Otherwise non-zero is
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
91 #if defined(__FreeBSD__)
94 #if __FreeBSD_version >= 700010
95 bus
= device_get_parent(device_get_parent(dev
->device
));
97 bus
= device_get_parent(dev
->device
);
99 if (pci_get_device(dev
->device
) == 0x0525 &&
100 pci_get_vendor(bus
) == 0x3388 &&
101 pci_get_device(bus
) == 0x0021)
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
))
108 return DRM_IS_NOT_AGP
;
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__)
148 mga_probe(device_t kdev
)
150 return drm_probe(kdev
, mga_pciidlist
);
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
,
163 return drm_attach(kdev
, mga_pciidlist
);
167 mga_detach(device_t kdev
)
169 struct drm_device
*dev
= device_get_softc(kdev
);
172 ret
= drm_detach(kdev
);
174 free(dev
->driver
, DRM_MEM_DRIVER
);
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
),
188 static driver_t mga_driver
= {
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);
198 DRIVER_MODULE(mga
, pci
, mga_driver
, drm_devclass
, 0, 0);
200 MODULE_DEPEND(mga
, drm
, 1, 1, 1);
202 #elif defined(__NetBSD__)
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
);
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
,
223 drm_attach(self
, pa
, mga_pciidlist
);
226 CFATTACH_DECL_NEW(mgadrm
, sizeof(struct drm_device
),
227 mgadrm_probe
, mgadrm_attach
, drm_detach
, NULL
);
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
[] = {
242 .cf_atname
= "mgadrm",
244 .cf_fstate
= FSTATE_STAR
,
247 .cf_pspec
= &drmparent
,
253 mgadrm_modcmd(modcmd_t cmd
, void *arg
)
258 case MODULE_CMD_INIT
:
259 err
= config_cfdriver_attach(&mgadrm_cd
);
262 err
= config_cfattach_attach("mgadrm", &mgadrm_ca
);
264 config_cfdriver_detach(&mgadrm_cd
);
267 err
= config_cfdata_attach(mgadrm_cfdata
, 1);
269 config_cfattach_detach("mgadrm", &mgadrm_ca
);
270 config_cfdriver_detach(&mgadrm_cd
);
274 case MODULE_CMD_FINI
:
275 err
= config_cfdata_detach(mgadrm_cfdata
);
278 config_cfattach_detach("mgadrm", &mgadrm_ca
);
279 config_cfdriver_detach(&mgadrm_cd
);