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