mach64_drv.c revision 183833
1145132Sanholt/* mach64_drv.c -- ATI Rage 128 driver -*- linux-c -*-
2145132Sanholt * Created: Mon Dec 13 09:47:27 1999 by faith@precisioninsight.com
3145132Sanholt */
4145132Sanholt/*-
5145132Sanholt * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6145132Sanholt * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7145132Sanholt * All Rights Reserved.
8145132Sanholt *
9145132Sanholt * Permission is hereby granted, free of charge, to any person obtaining a
10145132Sanholt * copy of this software and associated documentation files (the "Software"),
11145132Sanholt * to deal in the Software without restriction, including without limitation
12145132Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13145132Sanholt * and/or sell copies of the Software, and to permit persons to whom the
14145132Sanholt * Software is furnished to do so, subject to the following conditions:
15145132Sanholt *
16145132Sanholt * The above copyright notice and this permission notice (including the next
17145132Sanholt * paragraph) shall be included in all copies or substantial portions of the
18145132Sanholt * Software.
19145132Sanholt *
20145132Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21145132Sanholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22145132Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23145132Sanholt * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24145132Sanholt * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25145132Sanholt * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26145132Sanholt * OTHER DEALINGS IN THE SOFTWARE.
27145132Sanholt *
28145132Sanholt * Authors:
29145132Sanholt *    Rickard E. (Rik) Faith <faith@valinux.com>
30145132Sanholt *    Gareth Hughes <gareth@valinux.com>
31145132Sanholt */
32145132Sanholt
33152909Sanholt#include <sys/cdefs.h>
34152909Sanholt__FBSDID("$FreeBSD: head/sys/dev/drm/mach64_drv.c 183833 2008-10-13 18:03:27Z rnoland $");
35145132Sanholt
36152909Sanholt
37145132Sanholt#include <sys/types.h>
38145132Sanholt
39145132Sanholt#include "dev/drm/drmP.h"
40145132Sanholt#include "dev/drm/drm.h"
41145132Sanholt#include "dev/drm/mach64_drm.h"
42145132Sanholt#include "dev/drm/mach64_drv.h"
43145132Sanholt#include "dev/drm/drm_pciids.h"
44145132Sanholt
45145132Sanholt/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
46145132Sanholtstatic drm_pci_id_list_t mach64_pciidlist[] = {
47145132Sanholt	mach64_PCI_IDS
48145132Sanholt};
49145132Sanholt
50182080Srnolandstatic void mach64_configure(struct drm_device *dev)
51145132Sanholt{
52183573Srnoland	dev->driver->driver_features =
53183573Srnoland	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
54183573Srnoland	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
55145132Sanholt
56183573Srnoland	dev->driver->buf_priv_size	= 1; /* No dev_priv */
57183573Srnoland	dev->driver->lastclose		= mach64_driver_lastclose;
58183573Srnoland	dev->driver->get_vblank_counter	= mach64_get_vblank_counter;
59183573Srnoland	dev->driver->enable_vblank	= mach64_enable_vblank;
60183573Srnoland	dev->driver->disable_vblank	= mach64_disable_vblank;
61183573Srnoland	dev->driver->irq_preinstall	= mach64_driver_irq_preinstall;
62183573Srnoland	dev->driver->irq_postinstall	= mach64_driver_irq_postinstall;
63183573Srnoland	dev->driver->irq_uninstall	= mach64_driver_irq_uninstall;
64183573Srnoland	dev->driver->irq_handler	= mach64_driver_irq_handler;
65183573Srnoland	dev->driver->dma_ioctl		= mach64_dma_buffers;
66145132Sanholt
67183573Srnoland	dev->driver->ioctls		= mach64_ioctls;
68183573Srnoland	dev->driver->max_ioctl		= mach64_max_ioctl;
69145132Sanholt
70183573Srnoland	dev->driver->name		= DRIVER_NAME;
71183573Srnoland	dev->driver->desc		= DRIVER_DESC;
72183573Srnoland	dev->driver->date		= DRIVER_DATE;
73183573Srnoland	dev->driver->major		= DRIVER_MAJOR;
74183573Srnoland	dev->driver->minor		= DRIVER_MINOR;
75183573Srnoland	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
76145132Sanholt}
77145132Sanholt
78145132Sanholtstatic int
79145132Sanholtmach64_probe(device_t dev)
80145132Sanholt{
81145132Sanholt	return drm_probe(dev, mach64_pciidlist);
82145132Sanholt}
83145132Sanholt
84145132Sanholtstatic int
85145132Sanholtmach64_attach(device_t nbdev)
86145132Sanholt{
87182080Srnoland	struct drm_device *dev = device_get_softc(nbdev);
88145132Sanholt
89183833Srnoland	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
90183604Srnoland	    M_WAITOK | M_ZERO);
91183604Srnoland
92145132Sanholt	mach64_configure(dev);
93183573Srnoland
94145132Sanholt	return drm_attach(nbdev, mach64_pciidlist);
95145132Sanholt}
96145132Sanholt
97183573Srnolandstatic int
98183573Srnolandmach64_detach(device_t nbdev)
99183573Srnoland{
100183573Srnoland	struct drm_device *dev = device_get_softc(nbdev);
101183573Srnoland	int ret;
102183573Srnoland
103183573Srnoland	ret = drm_detach(nbdev);
104183573Srnoland
105183833Srnoland	free(dev->driver, DRM_MEM_DRIVER);
106183573Srnoland
107183573Srnoland	return ret;
108183573Srnoland}
109183573Srnoland
110145132Sanholtstatic device_method_t mach64_methods[] = {
111145132Sanholt	/* Device interface */
112145132Sanholt	DEVMETHOD(device_probe,		mach64_probe),
113145132Sanholt	DEVMETHOD(device_attach,	mach64_attach),
114183573Srnoland	DEVMETHOD(device_detach,	mach64_detach),
115145132Sanholt
116145132Sanholt	{ 0, 0 }
117145132Sanholt};
118145132Sanholt
119145132Sanholtstatic driver_t mach64_driver = {
120145132Sanholt	"drm",
121145132Sanholt	mach64_methods,
122182080Srnoland	sizeof(struct drm_device)
123145132Sanholt};
124145132Sanholt
125145132Sanholtextern devclass_t drm_devclass;
126153579Sjhb#if __FreeBSD_version >= 700010
127153579SjhbDRIVER_MODULE(mach64, vgapci, mach64_driver, drm_devclass, 0, 0);
128153579Sjhb#else
129145132SanholtDRIVER_MODULE(mach64, pci, mach64_driver, drm_devclass, 0, 0);
130153579Sjhb#endif
131145132SanholtMODULE_DEPEND(mach64, drm, 1, 1, 1);
132