Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / i915_drv.c
blobecbb518e21dc2e2616e974cc86e69f759014960e
1 /* i915_drv.c -- Intel i915 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 "i915_drm.h"
35 #include "i915_drv.h"
36 #include "drm_pciids.h"
38 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
39 static drm_pci_id_list_t i915_pciidlist[] = {
40 i915_PCI_IDS
43 #if defined(__FreeBSD__)
44 static int i915_suspend(device_t kdev)
46 struct drm_device *dev = device_get_softc(kdev);
47 struct drm_i915_private *dev_priv = dev->dev_private;
49 if (!dev || !dev_priv) {
50 DRM_ERROR("dev: 0x%lx, dev_priv: 0x%lx\n",
51 (unsigned long) dev, (unsigned long) dev_priv);
52 DRM_ERROR("DRM not initialized, aborting suspend.\n");
53 return -ENODEV;
56 i915_save_state(dev);
58 return (bus_generic_suspend(kdev));
61 static int i915_resume(device_t kdev)
63 struct drm_device *dev = device_get_softc(kdev);
65 i915_restore_state(dev);
67 return (bus_generic_resume(kdev));
69 #endif
71 static void i915_configure(struct drm_device *dev)
73 dev->driver->driver_features =
74 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
75 DRIVER_HAVE_IRQ;
77 dev->driver->buf_priv_size = sizeof(drm_i915_private_t);
78 dev->driver->load = i915_driver_load;
79 dev->driver->unload = i915_driver_unload;
80 dev->driver->preclose = i915_driver_preclose;
81 dev->driver->lastclose = i915_driver_lastclose;
82 dev->driver->device_is_agp = i915_driver_device_is_agp;
83 dev->driver->enable_vblank = i915_enable_vblank;
84 dev->driver->disable_vblank = i915_disable_vblank;
85 dev->driver->irq_preinstall = i915_driver_irq_preinstall;
86 dev->driver->irq_postinstall = i915_driver_irq_postinstall;
87 dev->driver->irq_uninstall = i915_driver_irq_uninstall;
88 dev->driver->irq_handler = i915_driver_irq_handler;
90 dev->driver->ioctls = i915_ioctls;
91 dev->driver->max_ioctl = i915_max_ioctl;
93 dev->driver->name = DRIVER_NAME;
94 dev->driver->desc = DRIVER_DESC;
95 dev->driver->date = DRIVER_DATE;
96 dev->driver->major = DRIVER_MAJOR;
97 dev->driver->minor = DRIVER_MINOR;
98 dev->driver->patchlevel = DRIVER_PATCHLEVEL;
101 #if defined(__FreeBSD__)
102 static int
103 i915_probe(device_t kdev)
105 return drm_probe(kdev, i915_pciidlist);
108 static int
109 i915_attach(device_t kdev)
111 struct drm_device *dev = device_get_softc(kdev);
113 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
114 M_WAITOK | M_ZERO);
116 i915_configure(dev);
118 return drm_attach(kdev, i915_pciidlist);
121 static int
122 i915_detach(device_t kdev)
124 struct drm_device *dev = device_get_softc(kdev);
125 int ret;
127 ret = drm_detach(kdev);
129 free(dev->driver, DRM_MEM_DRIVER);
131 return ret;
134 static device_method_t i915_methods[] = {
135 /* Device interface */
136 DEVMETHOD(device_probe, i915_probe),
137 DEVMETHOD(device_attach, i915_attach),
138 DEVMETHOD(device_suspend, i915_suspend),
139 DEVMETHOD(device_resume, i915_resume),
140 DEVMETHOD(device_detach, i915_detach),
142 { 0, 0 }
145 static driver_t i915_driver = {
146 #if __FreeBSD_version >= 700010
147 "drm",
148 #else
149 "drmsub",
150 #endif
151 i915_methods,
152 sizeof(struct drm_device)
155 extern devclass_t drm_devclass;
156 #if __FreeBSD_version >= 700010
157 DRIVER_MODULE(i915, vgapci, i915_driver, drm_devclass, 0, 0);
158 #else
159 DRIVER_MODULE(i915, agp, i915_driver, drm_devclass, 0, 0);
160 #endif
161 MODULE_DEPEND(i915, drm, 1, 1, 1);
163 #elif defined(__NetBSD__)
165 static bool
166 i915drm_suspend(device_t self, pmf_qual_t qual)
168 struct drm_device *dev = device_private(self);
170 i915_save_state(dev);
171 return true;
174 static bool
175 i915drm_resume(device_t self, pmf_qual_t qual)
177 struct drm_device *dev = device_private(self);
179 i915_restore_state(dev);
180 return true;
183 static int
184 i915drm_probe(device_t parent, cfdata_t match, void *aux)
186 struct pci_attach_args *pa = aux;
187 return drm_probe(pa, i915_pciidlist);
190 static void
191 i915drm_attach(device_t parent, device_t self, void *aux)
193 struct pci_attach_args *pa = aux;
194 struct drm_device *dev = device_private(self);
196 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
197 M_WAITOK | M_ZERO);
199 i915_configure(dev);
201 pmf_device_register(self, i915drm_suspend, i915drm_resume);
203 drm_attach(self, pa, i915_pciidlist);
206 static int
207 i915drm_detach(device_t self, int flags)
209 pmf_device_deregister(self);
211 return drm_detach(self, flags);
214 CFATTACH_DECL_NEW(i915drm, sizeof(struct drm_device), i915drm_probe,
215 i915drm_attach, i915drm_detach, NULL);
217 #ifdef _MODULE
219 MODULE(MODULE_CLASS_DRIVER, i915drm, "drm");
221 CFDRIVER_DECL(i915drm, DV_DULL, NULL);
222 extern struct cfattach i915drm_ca;
223 static int drmloc[] = { -1 };
224 static struct cfparent drmparent = {
225 "drm", "vga", DVUNIT_ANY
227 static struct cfdata i915drm_cfdata[] = {
229 .cf_name = "i915drm",
230 .cf_atname = "i915drm",
231 .cf_unit = 0,
232 .cf_fstate = FSTATE_STAR,
233 .cf_loc = drmloc,
234 .cf_flags = 0,
235 .cf_pspec = &drmparent,
237 { NULL }
240 static int
241 i915drm_modcmd(modcmd_t cmd, void *arg)
243 int err;
245 switch (cmd) {
246 case MODULE_CMD_INIT:
247 err = config_cfdriver_attach(&i915drm_cd);
248 if (err)
249 return err;
250 err = config_cfattach_attach("i915drm", &i915drm_ca);
251 if (err) {
252 config_cfdriver_detach(&i915drm_cd);
253 return err;
255 err = config_cfdata_attach(i915drm_cfdata, 1);
256 if (err) {
257 config_cfattach_detach("i915drm", &i915drm_ca);
258 config_cfdriver_detach(&i915drm_cd);
259 return err;
261 return 0;
262 case MODULE_CMD_FINI:
263 err = config_cfdata_detach(i915drm_cfdata);
264 if (err)
265 return err;
266 config_cfattach_detach("i915drm", &i915drm_ca);
267 config_cfdriver_detach(&i915drm_cd);
268 return 0;
269 default:
270 return ENOTTY;
273 #endif /* _MODULE */
275 #endif