xref: /dragonfly/sys/dev/drm/i915/i915_drv.c (revision e8c03636)
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 "dev/drm/drmP.h"
33 #include "dev/drm/drm.h"
34 #include "dev/drm/drm_mm.h"
35 #include "dev/drm/i915_drm.h"
36 #include "i915_drv.h"
37 #include "dev/drm/drm_pciids.h"
38 
39 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
40 static drm_pci_id_list_t i915_pciidlist[] = {
41 	i915_PCI_IDS
42 };
43 
44 static int i915_suspend(device_t kdev)
45 {
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 
53 	DRM_LOCK();
54 	DRM_DEBUG("starting suspend\n");
55 	i915_save_state(dev);
56 	DRM_UNLOCK();
57 
58 	return (bus_generic_suspend(kdev));
59 }
60 
61 static int i915_resume(device_t kdev)
62 {
63 	struct drm_device *dev = device_get_softc(kdev);
64 
65 	DRM_LOCK();
66 	i915_restore_state(dev);
67 	DRM_DEBUG("finished resume\n");
68 	DRM_UNLOCK();
69 
70 	return (bus_generic_resume(kdev));
71 }
72 
73 static 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;
101 }
102 
103 static int
104 i915_probe(device_t kdev)
105 {
106 	return drm_probe(kdev, i915_pciidlist);
107 }
108 
109 static int
110 i915_attach(device_t kdev)
111 {
112 	struct drm_device *dev = device_get_softc(kdev);
113 
114 	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
115 	    M_WAITOK | M_ZERO);
116 
117 	i915_configure(dev);
118 
119 	return drm_attach(kdev, i915_pciidlist);
120 }
121 
122 static int
123 i915_detach(device_t kdev)
124 {
125 	struct drm_device *dev = device_get_softc(kdev);
126 	int ret;
127 
128 	ret = drm_detach(kdev);
129 
130 	free(dev->driver, DRM_MEM_DRIVER);
131 
132 	return ret;
133 }
134 
135 static device_method_t i915_methods[] = {
136 	/* Device interface */
137 	DEVMETHOD(device_probe,		i915_probe),
138 	DEVMETHOD(device_attach,	i915_attach),
139 	DEVMETHOD(device_suspend,	i915_suspend),
140 	DEVMETHOD(device_resume,	i915_resume),
141 	DEVMETHOD(device_detach,	i915_detach),
142 
143 	DEVMETHOD_END
144 };
145 
146 static driver_t i915_driver = {
147 	"drm",
148 	i915_methods,
149 	sizeof(struct drm_device)
150 };
151 
152 extern devclass_t drm_devclass;
153 DRIVER_MODULE(i915, vgapci, i915_driver, drm_devclass, NULL, NULL);
154 MODULE_DEPEND(i915, drm, 1, 1, 1);
155