mga_drv.c revision 183604
112794Styan/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
212794Styan * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
312794Styan */
412794Styan/*-
512794Styan * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
612794Styan * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
712794Styan * All Rights Reserved.
812794Styan *
912794Styan * Permission is hereby granted, free of charge, to any person obtaining a
1012794Styan * copy of this software and associated documentation files (the "Software"),
1112794Styan * to deal in the Software without restriction, including without limitation
1212794Styan * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1312794Styan * and/or sell copies of the Software, and to permit persons to whom the
1412794Styan * Software is furnished to do so, subject to the following conditions:
1512794Styan *
1612794Styan * The above copyright notice and this permission notice (including the next
1712794Styan * paragraph) shall be included in all copies or substantial portions of the
1812794Styan * Software.
1912794Styan *
2012794Styan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2112794Styan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2212794Styan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2312794Styan * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
2412794Styan * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2512794Styan * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2612794Styan * OTHER DEALINGS IN THE SOFTWARE.
2712794Styan *
2812794Styan * Authors:
2912794Styan *    Rickard E. (Rik) Faith <faith@valinux.com>
3012794Styan *    Gareth Hughes <gareth@valinux.com>
3112794Styan *
3212794Styan */
3312794Styan
3412794Styan#include <sys/cdefs.h>
3512794Styan__FBSDID("$FreeBSD: head/sys/dev/drm/mga_drv.c 183604 2008-10-04 14:48:40Z rnoland $");
3612794Styan
3712794Styan#include "dev/drm/drmP.h"
3812794Styan#include "dev/drm/drm.h"
3912794Styan#include "dev/drm/mga_drm.h"
4012794Styan#include "dev/drm/mga_drv.h"
4112794Styan#include "dev/drm/drm_pciids.h"
4212794Styan
4312794Styan/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
4412794Styanstatic drm_pci_id_list_t mga_pciidlist[] = {
4512794Styan	mga_PCI_IDS
4612794Styan};
4712794Styan
4812794Styan/**
4912794Styan * Determine if the device really is AGP or not.
5012794Styan *
5112794Styan * In addition to the usual tests performed by \c drm_device_is_agp, this
5212794Styan * function detects PCI G450 cards that appear to the system exactly like
5312794Styan * AGP G450 cards.
5412794Styan *
5512794Styan * \param dev   The device to be tested.
5612794Styan *
5712794Styan * \returns
5812794Styan * If the device is a PCI G450, zero is returned.  Otherwise non-zero is
59 * returned.
60 *
61 * \bug
62 * This function needs to be filled in!  The implementation in
63 * linux-core/mga_drv.c shows what needs to be done.
64 */
65static int mga_driver_device_is_agp(struct drm_device * dev)
66{
67	device_t bus;
68
69	/* There are PCI versions of the G450.  These cards have the
70	 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
71	 * bridge chip.  We detect these cards, which are not currently
72	 * supported by this driver, by looking at the device ID of the
73	 * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
74	 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
75	 * device.
76	 */
77#if __FreeBSD_version >= 700010
78	bus = device_get_parent(device_get_parent(dev->device));
79#else
80	bus = device_get_parent(dev->device);
81#endif
82	if (pci_get_device(dev->device) == 0x0525 &&
83	    pci_get_vendor(bus) == 0x3388 &&
84	    pci_get_device(bus) == 0x0021)
85		return DRM_IS_NOT_AGP;
86	else
87		return DRM_MIGHT_BE_AGP;
88}
89
90static void mga_configure(struct drm_device *dev)
91{
92	dev->driver->driver_features =
93	    DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
94	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
95
96	dev->driver->buf_priv_size	= sizeof(drm_mga_buf_priv_t);
97	dev->driver->load		= mga_driver_load;
98	dev->driver->unload		= mga_driver_unload;
99	dev->driver->lastclose		= mga_driver_lastclose;
100	dev->driver->get_vblank_counter	= mga_get_vblank_counter;
101	dev->driver->enable_vblank	= mga_enable_vblank;
102	dev->driver->disable_vblank	= mga_disable_vblank;
103	dev->driver->irq_preinstall	= mga_driver_irq_preinstall;
104	dev->driver->irq_postinstall	= mga_driver_irq_postinstall;
105	dev->driver->irq_uninstall	= mga_driver_irq_uninstall;
106	dev->driver->irq_handler	= mga_driver_irq_handler;
107	dev->driver->dma_ioctl		= mga_dma_buffers;
108	dev->driver->dma_quiescent	= mga_driver_dma_quiescent;
109	dev->driver->device_is_agp	= mga_driver_device_is_agp;
110
111	dev->driver->ioctls		= mga_ioctls;
112	dev->driver->max_ioctl		= mga_max_ioctl;
113
114	dev->driver->name		= DRIVER_NAME;
115	dev->driver->desc		= DRIVER_DESC;
116	dev->driver->date		= DRIVER_DATE;
117	dev->driver->major		= DRIVER_MAJOR;
118	dev->driver->minor		= DRIVER_MINOR;
119	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
120}
121
122static int
123mga_probe(device_t dev)
124{
125	return drm_probe(dev, mga_pciidlist);
126}
127
128static int
129mga_attach(device_t nbdev)
130{
131	struct drm_device *dev = device_get_softc(nbdev);
132
133	bzero(dev, sizeof(struct drm_device));
134
135	dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM,
136	    M_WAITOK | M_ZERO);
137
138	mga_configure(dev);
139
140	return drm_attach(nbdev, mga_pciidlist);
141}
142
143static int
144mga_detach(device_t nbdev)
145{
146	struct drm_device *dev = device_get_softc(nbdev);
147	int ret;
148
149	ret = drm_detach(nbdev);
150
151	free(dev->driver, M_DRM);
152
153	return ret;
154}
155
156static device_method_t mga_methods[] = {
157	/* Device interface */
158	DEVMETHOD(device_probe,		mga_probe),
159	DEVMETHOD(device_attach,	mga_attach),
160	DEVMETHOD(device_detach,	mga_detach),
161
162	{ 0, 0 }
163};
164
165static driver_t mga_driver = {
166	"drm",
167	mga_methods,
168	sizeof(struct drm_device)
169};
170
171extern devclass_t drm_devclass;
172#if __FreeBSD_version >= 700010
173DRIVER_MODULE(mga, vgapci, mga_driver, drm_devclass, 0, 0);
174#else
175DRIVER_MODULE(mga, pci, mga_driver, drm_devclass, 0, 0);
176#endif
177MODULE_DEPEND(mga, drm, 1, 1, 1);
178