add a bunch of fixes mostly from rafal@.
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / mach64_drv.c
blob10e2ec714827057aa04019a0837b6718b7dac973
1 /* mach64_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.
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:
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.
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.
28 * Authors:
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
34 #include <sys/types.h>
36 #include "drmP.h"
37 #include "drm.h"
38 #include "mach64_drm.h"
39 #include "mach64_drv.h"
40 #include "drm_pciids.h"
42 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
43 static drm_pci_id_list_t mach64_pciidlist[] = {
44 mach64_PCI_IDS
47 int
48 mach64_driver_load(struct drm_device * dev, unsigned long flags)
50 return drm_vblank_init(dev, 1);
53 static void mach64_configure(struct drm_device *dev)
55 dev->driver->driver_features =
56 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
57 DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
59 dev->driver->buf_priv_size = 1; /* No dev_priv */
60 dev->driver->load = mach64_driver_load;
61 dev->driver->lastclose = mach64_driver_lastclose;
62 dev->driver->get_vblank_counter = mach64_get_vblank_counter;
63 dev->driver->enable_vblank = mach64_enable_vblank;
64 dev->driver->disable_vblank = mach64_disable_vblank;
65 dev->driver->irq_preinstall = mach64_driver_irq_preinstall;
66 dev->driver->irq_postinstall = mach64_driver_irq_postinstall;
67 dev->driver->irq_uninstall = mach64_driver_irq_uninstall;
68 dev->driver->irq_handler = mach64_driver_irq_handler;
69 dev->driver->dma_ioctl = mach64_dma_buffers;
71 dev->driver->ioctls = mach64_ioctls;
72 dev->driver->max_ioctl = mach64_max_ioctl;
74 dev->driver->name = DRIVER_NAME;
75 dev->driver->desc = DRIVER_DESC;
76 dev->driver->date = DRIVER_DATE;
77 dev->driver->major = DRIVER_MAJOR;
78 dev->driver->minor = DRIVER_MINOR;
79 dev->driver->patchlevel = DRIVER_PATCHLEVEL;
82 #if defined(__FreeBSD__)
84 static int
85 mach64_probe(device_t kdev)
87 return drm_probe(kdev, mach64_pciidlist);
90 static int
91 mach64_attach(device_t kdev)
93 struct drm_device *dev = device_get_softc(kdev);
95 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
96 M_WAITOK | M_ZERO);
98 mach64_configure(dev);
100 return drm_attach(kdev, mach64_pciidlist);
103 static int
104 mach64_detach(device_t kdev)
106 struct drm_device *dev = device_get_softc(kdev);
107 int ret;
109 ret = drm_detach(kdev);
111 free(dev->driver, DRM_MEM_DRIVER);
113 return ret;
116 static device_method_t mach64_methods[] = {
117 /* Device interface */
118 DEVMETHOD(device_probe, mach64_probe),
119 DEVMETHOD(device_attach, mach64_attach),
120 DEVMETHOD(device_detach, mach64_detach),
122 { 0, 0 }
125 static driver_t mach64_driver = {
126 "drm",
127 mach64_methods,
128 sizeof(struct drm_device)
131 extern devclass_t drm_devclass;
132 #if __FreeBSD_version >= 700010
133 DRIVER_MODULE(mach64, vgapci, mach64_driver, drm_devclass, 0, 0);
134 #else
135 DRIVER_MODULE(mach64, pci, mach64_driver, drm_devclass, 0, 0);
136 #endif
137 MODULE_DEPEND(mach64, drm, 1, 1, 1);
139 #elif defined(__NetBSD__)
141 static int
142 mach64drm_probe(device_t parent, cfdata_t match, void *aux)
144 struct pci_attach_args *pa = aux;
146 return drm_probe(pa, mach64_pciidlist);
149 static void
150 mach64drm_attach(device_t parent, device_t self, void *aux)
152 struct pci_attach_args *pa = aux;
153 struct drm_device *dev = device_private(self);
155 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
156 M_WAITOK | M_ZERO);
158 mach64_configure(dev);
160 drm_attach(self, pa, mach64_pciidlist);
163 CFATTACH_DECL_NEW(mach64drm, sizeof(struct drm_device),
164 mach64drm_probe, mach64drm_attach, drm_detach, drm_activate);
166 #ifdef _MODULE
168 MODULE(MODULE_CLASS_DRIVER, mach64drm, NULL);
170 CFDRIVER_DECL(mach64drm, DV_DULL, NULL);
171 extern struct cfattach mach64drm_ca;
172 static int drmloc[] = { -1 };
173 static struct cfparent drmparent = {
174 "drm", "vga", DVUNIT_ANY
176 static struct cfdata mach64drm_cfdata[] = {
178 .cf_name = "mach64drm",
179 .cf_atname = "mach64drm",
180 .cf_unit = 0,
181 .cf_fstate = FSTATE_STAR,
182 .cf_loc = drmloc,
183 .cf_flags = 0,
184 .cf_pspec = &drmparent,
186 { NULL }
189 static int
190 mach64drm_modcmd(modcmd_t cmd, void *arg)
192 int err;
194 switch (cmd) {
195 case MODULE_CMD_INIT:
196 err = config_cfdriver_attach(&mach64drm_cd);
197 if (err)
198 return err;
199 err = config_cfattach_attach("mach64drm", &mach64drm_ca);
200 if (err) {
201 config_cfdriver_detach(&mach64drm_cd);
202 return err;
204 err = config_cfdata_attach(mach64drm_cfdata, 1);
205 if (err) {
206 config_cfattach_detach("mach64drm", &mach64drm_ca);
207 config_cfdriver_detach(&mach64drm_cd);
208 return err;
210 return 0;
211 case MODULE_CMD_FINI:
212 err = config_cfdata_detach(mach64drm_cfdata);
213 if (err)
214 return err;
215 config_cfattach_detach("mach64drm", &mach64drm_ca);
216 config_cfdriver_detach(&mach64drm_cd);
217 return 0;
218 default:
219 return ENOTTY;
222 #endif /* _MODULE */
224 #endif