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