Hold the lock while we save/restore register for suspend/resume.
[dragonfly.git] / sys / dev / drm / i915_drv.c
CommitLineData
7f3c3d6f
HT
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.
7 *
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:
14 *
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.
18 *
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.
26 *
27 * Authors:
28 * Gareth Hughes <gareth@valinux.com>
29 *
7f3c3d6f
HT
30 */
31
b3705d71
HT
32#include "dev/drm/drmP.h"
33#include "dev/drm/drm.h"
34#include "dev/drm/i915_drm.h"
35#include "dev/drm/i915_drv.h"
36#include "dev/drm/drm_pciids.h"
7f3c3d6f
HT
37
38/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
39static drm_pci_id_list_t i915_pciidlist[] = {
40 i915_PCI_IDS
41};
42
b3705d71 43static int i915_suspend(device_t kdev)
7f3c3d6f 44{
b3705d71
HT
45 struct drm_device *dev = device_get_softc(kdev);
46
47 if (!dev || !dev->dev_private) {
48 DRM_ERROR("DRM not initialized, aborting suspend.\n");
49 return -ENODEV;
50 }
51
01468c6d
HT
52 DRM_LOCK();
53 DRM_DEBUG("starting suspend\n");
b3705d71 54 i915_save_state(dev);
01468c6d 55 DRM_UNLOCK();
b3705d71
HT
56
57 return (bus_generic_suspend(kdev));
58}
59
60static int i915_resume(device_t kdev)
61{
62 struct drm_device *dev = device_get_softc(kdev);
63
01468c6d 64 DRM_LOCK();
b3705d71 65 i915_restore_state(dev);
01468c6d
HT
66 DRM_DEBUG("finished resume\n");
67 DRM_UNLOCK();
b3705d71
HT
68
69 return (bus_generic_resume(kdev));
70}
71
72static void i915_configure(struct drm_device *dev)
73{
74 dev->driver->driver_features =
75 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
76 DRIVER_HAVE_IRQ;
77
78 dev->driver->buf_priv_size = sizeof(drm_i915_private_t);
79 dev->driver->load = i915_driver_load;
80 dev->driver->unload = i915_driver_unload;
81 dev->driver->preclose = i915_driver_preclose;
82 dev->driver->lastclose = i915_driver_lastclose;
83 dev->driver->device_is_agp = i915_driver_device_is_agp;
84 dev->driver->enable_vblank = i915_enable_vblank;
85 dev->driver->disable_vblank = i915_disable_vblank;
86 dev->driver->irq_preinstall = i915_driver_irq_preinstall;
87 dev->driver->irq_postinstall = i915_driver_irq_postinstall;
88 dev->driver->irq_uninstall = i915_driver_irq_uninstall;
89 dev->driver->irq_handler = i915_driver_irq_handler;
90
91 dev->driver->ioctls = i915_ioctls;
92 dev->driver->max_ioctl = i915_max_ioctl;
93
94 dev->driver->name = DRIVER_NAME;
95 dev->driver->desc = DRIVER_DESC;
96 dev->driver->date = DRIVER_DATE;
97 dev->driver->major = DRIVER_MAJOR;
98 dev->driver->minor = DRIVER_MINOR;
99 dev->driver->patchlevel = DRIVER_PATCHLEVEL;
7f3c3d6f
HT
100}
101
7f3c3d6f 102static int
b3705d71 103i915_probe(device_t kdev)
7f3c3d6f 104{
b3705d71 105 return drm_probe(kdev, i915_pciidlist);
7f3c3d6f
HT
106}
107
108static int
b3705d71 109i915_attach(device_t kdev)
7f3c3d6f 110{
b3705d71
HT
111 struct drm_device *dev = device_get_softc(kdev);
112
113 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
114 M_WAITOK | M_ZERO);
7f3c3d6f 115
7f3c3d6f 116 i915_configure(dev);
b3705d71
HT
117
118 return drm_attach(kdev, i915_pciidlist);
119}
120
121static int
122i915_detach(device_t kdev)
123{
124 struct drm_device *dev = device_get_softc(kdev);
125 int ret;
126
127 ret = drm_detach(kdev);
128
129 free(dev->driver, DRM_MEM_DRIVER);
130
131 return ret;
7f3c3d6f
HT
132}
133
134static device_method_t i915_methods[] = {
135 /* Device interface */
136 DEVMETHOD(device_probe, i915_probe),
137 DEVMETHOD(device_attach, i915_attach),
b3705d71
HT
138 DEVMETHOD(device_suspend, i915_suspend),
139 DEVMETHOD(device_resume, i915_resume),
140 DEVMETHOD(device_detach, i915_detach),
7f3c3d6f
HT
141
142 { 0, 0 }
143};
144
145static driver_t i915_driver = {
146#if __FreeBSD_version >= 700010
147 "drm",
148#else
149 "drmsub",
150#endif
151 i915_methods,
b3705d71 152 sizeof(struct drm_device)
7f3c3d6f
HT
153};
154
155extern devclass_t drm_devclass;
156#if __FreeBSD_version >= 700010
157DRIVER_MODULE(i915, vgapci, i915_driver, drm_devclass, 0, 0);
158#else
159DRIVER_MODULE(i915, agp, i915_driver, drm_devclass, 0, 0);
160#endif
161MODULE_DEPEND(i915, drm, 1, 1, 1);