i915_drv.c revision 182080
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 182080 2008-08-23 20:59:12Z rnoland $");
34
35#include "dev/drm/drmP.h"
36#include "dev/drm/drm.h"
37#include "dev/drm/i915_drm.h"
38#include "dev/drm/i915_drv.h"
39#include "dev/drm/drm_pciids.h"
40
41/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
42static drm_pci_id_list_t i915_pciidlist[] = {
43	i915_PCI_IDS
44};
45
46static int i915_suspend(device_t nbdev)
47{
48	struct drm_device *dev = device_get_softc(nbdev);
49	struct drm_i915_private *dev_priv = dev->dev_private;
50
51	if (!dev || !dev_priv) {
52		DRM_ERROR("dev: 0x%lx, dev_priv: 0x%lx\n",
53			(unsigned long) dev, (unsigned long) dev_priv);
54		DRM_ERROR("DRM not initialized, aborting suspend.\n");
55		return -ENODEV;
56	}
57
58	i915_save_state(dev);
59
60	return (bus_generic_suspend(nbdev));
61}
62
63static int i915_resume(device_t nbdev)
64{
65	struct drm_device *dev = device_get_softc(nbdev);
66
67	i915_restore_state(dev);
68
69	return (bus_generic_resume(nbdev));
70}
71
72static void i915_configure(struct drm_device *dev)
73{
74	dev->driver.buf_priv_size	= sizeof(drm_i915_private_t);
75	dev->driver.load		= i915_driver_load;
76	dev->driver.unload		= i915_driver_unload;
77	dev->driver.firstopen		= i915_driver_firstopen;
78	dev->driver.preclose		= i915_driver_preclose;
79	dev->driver.lastclose		= i915_driver_lastclose;
80	dev->driver.device_is_agp	= i915_driver_device_is_agp;
81	dev->driver.get_vblank_counter	= i915_get_vblank_counter;
82	dev->driver.enable_vblank	= i915_enable_vblank;
83	dev->driver.disable_vblank	= i915_disable_vblank;
84	dev->driver.irq_preinstall	= i915_driver_irq_preinstall;
85	dev->driver.irq_postinstall	= i915_driver_irq_postinstall;
86	dev->driver.irq_uninstall	= i915_driver_irq_uninstall;
87	dev->driver.irq_handler		= i915_driver_irq_handler;
88
89	dev->driver.ioctls		= i915_ioctls;
90	dev->driver.max_ioctl		= i915_max_ioctl;
91
92	dev->driver.name		= DRIVER_NAME;
93	dev->driver.desc		= DRIVER_DESC;
94	dev->driver.date		= DRIVER_DATE;
95	dev->driver.major		= DRIVER_MAJOR;
96	dev->driver.minor		= DRIVER_MINOR;
97	dev->driver.patchlevel		= DRIVER_PATCHLEVEL;
98
99	dev->driver.use_agp		= 1;
100	dev->driver.require_agp		= 1;
101	dev->driver.use_mtrr		= 1;
102	dev->driver.use_irq		= 1;
103	dev->driver.use_vbl_irq		= 1;
104	dev->driver.use_vbl_irq2	= 1;
105}
106
107#ifdef __FreeBSD__
108static int
109i915_probe(device_t dev)
110{
111	return drm_probe(dev, i915_pciidlist);
112}
113
114static int
115i915_attach(device_t nbdev)
116{
117	struct drm_device *dev = device_get_softc(nbdev);
118
119	bzero(dev, sizeof(struct drm_device));
120	i915_configure(dev);
121	return drm_attach(nbdev, i915_pciidlist);
122}
123
124static device_method_t i915_methods[] = {
125	/* Device interface */
126	DEVMETHOD(device_probe,		i915_probe),
127	DEVMETHOD(device_attach,	i915_attach),
128	DEVMETHOD(device_suspend,	i915_suspend),
129	DEVMETHOD(device_resume,	i915_resume),
130	DEVMETHOD(device_detach,	drm_detach),
131
132	{ 0, 0 }
133};
134
135static driver_t i915_driver = {
136#if __FreeBSD_version >= 700010
137	"drm",
138#else
139	"drmsub",
140#endif
141	i915_methods,
142	sizeof(struct drm_device)
143};
144
145extern devclass_t drm_devclass;
146#if __FreeBSD_version >= 700010
147DRIVER_MODULE(i915, vgapci, i915_driver, drm_devclass, 0, 0);
148#else
149DRIVER_MODULE(i915, agp, i915_driver, drm_devclass, 0, 0);
150#endif
151MODULE_DEPEND(i915, drm, 1, 1, 1);
152
153#elif defined(__NetBSD__) || defined(__OpenBSD__)
154CFDRIVER_DECL(i915, DV_TTY, NULL);
155#endif
156