mga_drv.c revision 152909
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 <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/drm/mga_drv.c 152909 2005-11-28 23:13:57Z anholt $");
36
37#include "dev/drm/drmP.h"
38#include "dev/drm/drm.h"
39#include "dev/drm/mga_drm.h"
40#include "dev/drm/mga_drv.h"
41#include "dev/drm/drm_pciids.h"
42
43/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
44static drm_pci_id_list_t mga_pciidlist[] = {
45	mga_PCI_IDS
46};
47
48/**
49 * Determine if the device really is AGP or not.
50 *
51 * In addition to the usual tests performed by \c drm_device_is_agp, this
52 * function detects PCI G450 cards that appear to the system exactly like
53 * AGP G450 cards.
54 *
55 * \param dev   The device to be tested.
56 *
57 * \returns
58 * 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(drm_device_t * dev)
66{
67	/* There are PCI versions of the G450.  These cards have the
68	 * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
69	 * bridge chip.  We detect these cards, which are not currently
70	 * supported by this driver, by looking at the device ID of the
71	 * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
72	 * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
73	 * device.
74	 */
75	if (pci_get_device(dev->device) == 0x0525 &&
76	    pci_get_vendor(device_get_parent(dev->device)) == 0x3388 &&
77	    pci_get_device(device_get_parent(dev->device)) == 0x0021)
78		return 0;
79	else
80		return 2;
81}
82
83static void mga_configure(drm_device_t *dev)
84{
85	dev->driver.buf_priv_size	= sizeof(drm_mga_buf_priv_t);
86	dev->driver.load		= mga_driver_load;
87	dev->driver.unload		= mga_driver_unload;
88	dev->driver.lastclose		= mga_driver_lastclose;
89	dev->driver.vblank_wait		= mga_driver_vblank_wait;
90	dev->driver.irq_preinstall	= mga_driver_irq_preinstall;
91	dev->driver.irq_postinstall	= mga_driver_irq_postinstall;
92	dev->driver.irq_uninstall	= mga_driver_irq_uninstall;
93	dev->driver.irq_handler		= mga_driver_irq_handler;
94	dev->driver.dma_ioctl		= mga_dma_buffers;
95	dev->driver.dma_quiescent	= mga_driver_dma_quiescent;
96	dev->driver.device_is_agp	= mga_driver_device_is_agp;
97
98	dev->driver.ioctls		= mga_ioctls;
99	dev->driver.max_ioctl		= mga_max_ioctl;
100
101	dev->driver.name		= DRIVER_NAME;
102	dev->driver.desc		= DRIVER_DESC;
103	dev->driver.date		= DRIVER_DATE;
104	dev->driver.major		= DRIVER_MAJOR;
105	dev->driver.minor		= DRIVER_MINOR;
106	dev->driver.patchlevel		= DRIVER_PATCHLEVEL;
107
108	dev->driver.use_agp		= 1;
109	dev->driver.require_agp		= 1;
110	dev->driver.use_mtrr		= 1;
111	dev->driver.use_dma		= 1;
112	dev->driver.use_irq		= 1;
113	dev->driver.use_vbl_irq		= 1;
114}
115
116
117
118#ifdef __FreeBSD__
119static int
120mga_probe(device_t dev)
121{
122	return drm_probe(dev, mga_pciidlist);
123}
124
125static int
126mga_attach(device_t nbdev)
127{
128	drm_device_t *dev = device_get_softc(nbdev);
129
130	bzero(dev, sizeof(drm_device_t));
131	mga_configure(dev);
132	return drm_attach(nbdev, mga_pciidlist);
133}
134
135static device_method_t mga_methods[] = {
136	/* Device interface */
137	DEVMETHOD(device_probe,		mga_probe),
138	DEVMETHOD(device_attach,	mga_attach),
139	DEVMETHOD(device_detach,	drm_detach),
140
141	{ 0, 0 }
142};
143
144static driver_t mga_driver = {
145	"drm",
146	mga_methods,
147	sizeof(drm_device_t)
148};
149
150extern devclass_t drm_devclass;
151DRIVER_MODULE(mga, pci, mga_driver, drm_devclass, 0, 0);
152MODULE_DEPEND(mga, drm, 1, 1, 1);
153
154#elif defined(__NetBSD__) || defined(__OpenBSD__)
155#ifdef _LKM
156CFDRIVER_DECL(mga, DV_TTY, NULL);
157#else
158CFATTACH_DECL(mga, sizeof(drm_device_t), drm_probe, drm_attach, drm_detach,
159    drm_activate);
160#endif
161#endif
162