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$");
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 */
57189130Srnoland	dev->driver->load		= mach64_driver_load;
58183573Srnoland	dev->driver->lastclose		= mach64_driver_lastclose;
59183573Srnoland	dev->driver->get_vblank_counter	= mach64_get_vblank_counter;
60183573Srnoland	dev->driver->enable_vblank	= mach64_enable_vblank;
61183573Srnoland	dev->driver->disable_vblank	= mach64_disable_vblank;
62183573Srnoland	dev->driver->irq_preinstall	= mach64_driver_irq_preinstall;
63183573Srnoland	dev->driver->irq_postinstall	= mach64_driver_irq_postinstall;
64183573Srnoland	dev->driver->irq_uninstall	= mach64_driver_irq_uninstall;
65183573Srnoland	dev->driver->irq_handler	= mach64_driver_irq_handler;
66183573Srnoland	dev->driver->dma_ioctl		= mach64_dma_buffers;
67145132Sanholt
68183573Srnoland	dev->driver->ioctls		= mach64_ioctls;
69183573Srnoland	dev->driver->max_ioctl		= mach64_max_ioctl;
70145132Sanholt
71183573Srnoland	dev->driver->name		= DRIVER_NAME;
72183573Srnoland	dev->driver->desc		= DRIVER_DESC;
73183573Srnoland	dev->driver->date		= DRIVER_DATE;
74183573Srnoland	dev->driver->major		= DRIVER_MAJOR;
75183573Srnoland	dev->driver->minor		= DRIVER_MINOR;
76183573Srnoland	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
77145132Sanholt}
78145132Sanholt
79145132Sanholtstatic int
80189563Srnolandmach64_probe(device_t kdev)
81145132Sanholt{
82189563Srnoland	return drm_probe(kdev, mach64_pciidlist);
83145132Sanholt}
84145132Sanholt
85145132Sanholtstatic int
86189563Srnolandmach64_attach(device_t kdev)
87145132Sanholt{
88189563Srnoland	struct drm_device *dev = device_get_softc(kdev);
89145132Sanholt
90183833Srnoland	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
91183604Srnoland	    M_WAITOK | M_ZERO);
92183604Srnoland
93145132Sanholt	mach64_configure(dev);
94183573Srnoland
95189563Srnoland	return drm_attach(kdev, mach64_pciidlist);
96145132Sanholt}
97145132Sanholt
98189130Srnolandint
99189130Srnolandmach64_driver_load(struct drm_device * dev, unsigned long flags)
100189130Srnoland{
101189130Srnoland        return drm_vblank_init(dev, 1);
102189130Srnoland}
103189130Srnoland
104183573Srnolandstatic int
105189563Srnolandmach64_detach(device_t kdev)
106183573Srnoland{
107189563Srnoland	struct drm_device *dev = device_get_softc(kdev);
108183573Srnoland	int ret;
109183573Srnoland
110189563Srnoland	ret = drm_detach(kdev);
111183573Srnoland
112183833Srnoland	free(dev->driver, DRM_MEM_DRIVER);
113183573Srnoland
114183573Srnoland	return ret;
115183573Srnoland}
116183573Srnoland
117145132Sanholtstatic device_method_t mach64_methods[] = {
118145132Sanholt	/* Device interface */
119145132Sanholt	DEVMETHOD(device_probe,		mach64_probe),
120145132Sanholt	DEVMETHOD(device_attach,	mach64_attach),
121183573Srnoland	DEVMETHOD(device_detach,	mach64_detach),
122145132Sanholt
123145132Sanholt	{ 0, 0 }
124145132Sanholt};
125145132Sanholt
126145132Sanholtstatic driver_t mach64_driver = {
127145132Sanholt	"drm",
128145132Sanholt	mach64_methods,
129182080Srnoland	sizeof(struct drm_device)
130145132Sanholt};
131145132Sanholt
132145132Sanholtextern devclass_t drm_devclass;
133153579SjhbDRIVER_MODULE(mach64, vgapci, mach64_driver, drm_devclass, 0, 0);
134145132SanholtMODULE_DEPEND(mach64, drm, 1, 1, 1);
135