Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / radeon_drv.c
blob28899251c6fb5986f93a105429fc2f4817127768
1 /* radeon_drv.c -- ATI Radeon driver -*- linux-c -*-
2 * Created: Wed Feb 14 17:10:04 2001 by gareth@valinux.com
3 */
4 /*-
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
27 * Authors:
28 * Gareth Hughes <gareth@valinux.com>
32 #include "drmP.h"
33 #include "drm.h"
34 #include "radeon_drm.h"
35 #include "radeon_drv.h"
36 #include "drm_pciids.h"
38 int radeon_no_wb;
40 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
41 static drm_pci_id_list_t radeon_pciidlist[] = {
42 radeon_PCI_IDS
45 static void radeon_configure(struct drm_device *dev)
47 dev->driver->driver_features =
48 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
49 DRIVER_SG | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
51 dev->driver->buf_priv_size = sizeof(drm_radeon_buf_priv_t);
52 dev->driver->load = radeon_driver_load;
53 dev->driver->unload = radeon_driver_unload;
54 dev->driver->firstopen = radeon_driver_firstopen;
55 dev->driver->open = radeon_driver_open;
56 dev->driver->preclose = radeon_driver_preclose;
57 dev->driver->postclose = radeon_driver_postclose;
58 dev->driver->lastclose = radeon_driver_lastclose;
59 dev->driver->get_vblank_counter = radeon_get_vblank_counter;
60 dev->driver->enable_vblank = radeon_enable_vblank;
61 dev->driver->disable_vblank = radeon_disable_vblank;
62 dev->driver->irq_preinstall = radeon_driver_irq_preinstall;
63 dev->driver->irq_postinstall = radeon_driver_irq_postinstall;
64 dev->driver->irq_uninstall = radeon_driver_irq_uninstall;
65 dev->driver->irq_handler = radeon_driver_irq_handler;
66 dev->driver->dma_ioctl = radeon_cp_buffers;
68 dev->driver->ioctls = radeon_ioctls;
69 dev->driver->max_ioctl = radeon_max_ioctl;
71 dev->driver->name = DRIVER_NAME;
72 dev->driver->desc = DRIVER_DESC;
73 dev->driver->date = DRIVER_DATE;
74 dev->driver->major = DRIVER_MAJOR;
75 dev->driver->minor = DRIVER_MINOR;
76 dev->driver->patchlevel = DRIVER_PATCHLEVEL;
79 #if defined(__FreeBSD__)
80 static int
81 radeon_probe(device_t kdev)
83 return drm_probe(kdev, radeon_pciidlist);
86 static int
87 radeon_attach(device_t kdev)
89 struct drm_device *dev = device_get_softc(kdev);
91 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
92 M_WAITOK | M_ZERO);
94 radeon_configure(dev);
96 return drm_attach(kdev, radeon_pciidlist);
99 static int
100 radeon_detach(device_t kdev)
102 struct drm_device *dev = device_get_softc(kdev);
103 int ret;
105 ret = drm_detach(kdev);
107 free(dev->driver, DRM_MEM_DRIVER);
109 return ret;
112 static device_method_t radeon_methods[] = {
113 /* Device interface */
114 DEVMETHOD(device_probe, radeon_probe),
115 DEVMETHOD(device_attach, radeon_attach),
116 DEVMETHOD(device_detach, radeon_detach),
118 { 0, 0 }
121 static driver_t radeon_driver = {
122 "drm",
123 radeon_methods,
124 sizeof(struct drm_device)
127 extern devclass_t drm_devclass;
128 #if __FreeBSD_version >= 700010
129 DRIVER_MODULE(radeon, vgapci, radeon_driver, drm_devclass, 0, 0);
130 #else
131 DRIVER_MODULE(radeon, pci, radeon_driver, drm_devclass, 0, 0);
132 #endif
133 MODULE_DEPEND(radeon, drm, 1, 1, 1);
135 #elif defined(__NetBSD__)
137 static bool
138 radeondrm_suspend(device_t self, pmf_qual_t qual)
140 struct drm_device *rad_dev = device_private(self);
141 drm_radeon_cp_stop_t stop_args;
143 stop_args.flush = stop_args.idle = 0;
144 if (radeon_cp_stop(rad_dev, &stop_args, rad_dev->lock.file_priv) != 0)
145 return false;
147 return true;
150 static bool
151 radeondrm_resume(device_t self, pmf_qual_t qual)
153 struct drm_device *rad_dev = device_private(self);
154 if (radeon_cp_resume(rad_dev, NULL, NULL) != 0)
155 return false;
157 return true;
160 static int
161 radeondrm_probe(device_t parent, cfdata_t match, void *aux)
163 struct pci_attach_args *pa = aux;
164 return drm_probe(pa, radeon_pciidlist);
167 static void
168 radeondrm_attach(device_t parent, device_t self, void *aux)
170 struct pci_attach_args *pa = aux;
171 struct drm_device *dev = device_private(self);
173 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
174 M_WAITOK | M_ZERO);
176 radeon_configure(dev);
178 if (!pmf_device_register(self, radeondrm_suspend, radeondrm_resume))
179 aprint_error_dev(self, "couldn't establish power handler\n");
181 drm_attach(self, pa, radeon_pciidlist);
184 static int
185 radeondrm_detach(device_t self, int flags)
187 pmf_device_deregister(self);
189 return drm_detach(self, flags);
192 CFATTACH_DECL_NEW(radeondrm, sizeof(struct drm_device),
193 radeondrm_probe, radeondrm_attach, radeondrm_detach, NULL);
195 #ifdef _MODULE
197 MODULE(MODULE_CLASS_DRIVER, radeondrm, NULL);
199 CFDRIVER_DECL(radeondrm, DV_DULL, NULL);
200 extern struct cfattach radeondrm_ca;
201 static int drmloc[] = { -1 };
202 static struct cfparent drmparent = {
203 "drm", "vga", DVUNIT_ANY
205 static struct cfdata radeondrm_cfdata[] = {
207 .cf_name = "radeondrm",
208 .cf_atname = "radeondrm",
209 .cf_unit = 0,
210 .cf_fstate = FSTATE_STAR,
211 .cf_loc = drmloc,
212 .cf_flags = 0,
213 .cf_pspec = &drmparent,
215 { NULL }
218 static int
219 radeondrm_modcmd(modcmd_t cmd, void *arg)
221 int err;
223 switch (cmd) {
224 case MODULE_CMD_INIT:
225 err = config_cfdriver_attach(&radeondrm_cd);
226 if (err)
227 return err;
228 err = config_cfattach_attach("radeondrm", &radeondrm_ca);
229 if (err) {
230 config_cfdriver_detach(&radeondrm_cd);
231 return err;
233 err = config_cfdata_attach(radeondrm_cfdata, 1);
234 if (err) {
235 config_cfattach_detach("radeondrm", &radeondrm_ca);
236 config_cfdriver_detach(&radeondrm_cd);
237 return err;
239 return 0;
240 case MODULE_CMD_FINI:
241 err = config_cfdata_detach(radeondrm_cfdata);
242 if (err)
243 return err;
244 config_cfattach_detach("radeondrm", &radeondrm_ca);
245 config_cfdriver_detach(&radeondrm_cd);
246 return 0;
247 default:
248 return ENOTTY;
251 #endif /* _MODULE */
253 #endif