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