1/* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
2 * Created: Mon Dec 13 09:47:27 1999 by faith@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$");
36
37#include "dev/drm/drmP.h"
38#include "dev/drm/drm.h"
39#include "dev/drm/r128_drm.h"
40#include "dev/drm/r128_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 r128_pciidlist[] = {
45	r128_PCI_IDS
46};
47
48static void r128_configure(struct drm_device *dev)
49{
50	dev->driver->driver_features =
51	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
52	    DRIVER_SG | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
53
54	dev->driver->buf_priv_size	= sizeof(drm_r128_buf_priv_t);
55	dev->driver->load		= r128_driver_load;
56	dev->driver->preclose		= r128_driver_preclose;
57	dev->driver->lastclose		= r128_driver_lastclose;
58	dev->driver->get_vblank_counter	= r128_get_vblank_counter;
59	dev->driver->enable_vblank	= r128_enable_vblank;
60	dev->driver->disable_vblank	= r128_disable_vblank;
61	dev->driver->irq_preinstall	= r128_driver_irq_preinstall;
62	dev->driver->irq_postinstall	= r128_driver_irq_postinstall;
63	dev->driver->irq_uninstall	= r128_driver_irq_uninstall;
64	dev->driver->irq_handler	= r128_driver_irq_handler;
65	dev->driver->dma_ioctl		= r128_cce_buffers;
66
67	dev->driver->ioctls		= r128_ioctls;
68	dev->driver->max_ioctl		= r128_max_ioctl;
69
70	dev->driver->name		= DRIVER_NAME;
71	dev->driver->desc		= DRIVER_DESC;
72	dev->driver->date		= DRIVER_DATE;
73	dev->driver->major		= DRIVER_MAJOR;
74	dev->driver->minor		= DRIVER_MINOR;
75	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
76}
77
78static int
79r128_probe(device_t kdev)
80{
81	return drm_probe(kdev, r128_pciidlist);
82}
83
84static int
85r128_attach(device_t kdev)
86{
87	struct drm_device *dev = device_get_softc(kdev);
88
89	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
90	    M_WAITOK | M_ZERO);
91
92	r128_configure(dev);
93
94	return drm_attach(kdev, r128_pciidlist);
95}
96
97int r128_driver_load(struct drm_device * dev, unsigned long flags)
98{
99	return drm_vblank_init(dev, 1);
100}
101
102static int
103r128_detach(device_t kdev)
104{
105	struct drm_device *dev = device_get_softc(kdev);
106	int ret;
107
108	ret = drm_detach(kdev);
109
110	free(dev->driver, DRM_MEM_DRIVER);
111
112	return ret;
113}
114
115static device_method_t r128_methods[] = {
116	/* Device interface */
117	DEVMETHOD(device_probe,		r128_probe),
118	DEVMETHOD(device_attach,	r128_attach),
119	DEVMETHOD(device_detach,	r128_detach),
120
121	{ 0, 0 }
122};
123
124static driver_t r128_driver = {
125	"drm",
126	r128_methods,
127	sizeof(struct drm_device)
128};
129
130extern devclass_t drm_devclass;
131DRIVER_MODULE(r128, vgapci, r128_driver, drm_devclass, 0, 0);
132MODULE_DEPEND(r128, drm, 1, 1, 1);
133