i915_drv.c revision 183573
1145132Sanholt/* i915_drv.c -- Intel i915 driver -*- linux-c -*- 2145132Sanholt * Created: Wed Feb 14 17:10:04 2001 by gareth@valinux.com 3145132Sanholt */ 4145132Sanholt/*- 5145132Sanholt * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6145132Sanholt * All Rights Reserved. 7145132Sanholt * 8145132Sanholt * Permission is hereby granted, free of charge, to any person obtaining a 9145132Sanholt * copy of this software and associated documentation files (the "Software"), 10145132Sanholt * to deal in the Software without restriction, including without limitation 11145132Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12145132Sanholt * and/or sell copies of the Software, and to permit persons to whom the 13145132Sanholt * Software is furnished to do so, subject to the following conditions: 14145132Sanholt * 15145132Sanholt * The above copyright notice and this permission notice (including the next 16145132Sanholt * paragraph) shall be included in all copies or substantial portions of the 17145132Sanholt * Software. 18145132Sanholt * 19145132Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20145132Sanholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21145132Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22145132Sanholt * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23145132Sanholt * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24145132Sanholt * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25145132Sanholt * OTHER DEALINGS IN THE SOFTWARE. 26145132Sanholt * 27145132Sanholt * Authors: 28145132Sanholt * Gareth Hughes <gareth@valinux.com> 29145132Sanholt * 30145132Sanholt */ 31145132Sanholt 32152909Sanholt#include <sys/cdefs.h> 33152909Sanholt__FBSDID("$FreeBSD: head/sys/dev/drm/i915_drv.c 183573 2008-10-03 16:59:11Z rnoland $"); 34145132Sanholt 35152909Sanholt#include "dev/drm/drmP.h" 36152909Sanholt#include "dev/drm/drm.h" 37152909Sanholt#include "dev/drm/i915_drm.h" 38152909Sanholt#include "dev/drm/i915_drv.h" 39152909Sanholt#include "dev/drm/drm_pciids.h" 40152909Sanholt 41145132Sanholt/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */ 42145132Sanholtstatic drm_pci_id_list_t i915_pciidlist[] = { 43145132Sanholt i915_PCI_IDS 44145132Sanholt}; 45145132Sanholt 46145132Sanholtstatic int i915_suspend(device_t nbdev) 47145132Sanholt{ 48152909Sanholt struct drm_device *dev = device_get_softc(nbdev); 49152909Sanholt struct drm_i915_private *dev_priv = dev->dev_private; 50152909Sanholt 51152909Sanholt if (!dev || !dev_priv) { 52152909Sanholt DRM_ERROR("dev: 0x%lx, dev_priv: 0x%lx\n", 53152909Sanholt (unsigned long) dev, (unsigned long) dev_priv); 54152909Sanholt DRM_ERROR("DRM not initialized, aborting suspend.\n"); 55152909Sanholt return -ENODEV; 56152909Sanholt } 57145132Sanholt 58152909Sanholt i915_save_state(dev); 59152909Sanholt 60145132Sanholt return (bus_generic_suspend(nbdev)); 61152909Sanholt} 62152909Sanholt 63152909Sanholtstatic int i915_resume(device_t nbdev) 64152909Sanholt{ 65152909Sanholt struct drm_device *dev = device_get_softc(nbdev); 66152909Sanholt 67145132Sanholt i915_restore_state(dev); 68152909Sanholt 69152909Sanholt return (bus_generic_resume(nbdev)); 70152909Sanholt} 71152909Sanholt 72145132Sanholtstatic void i915_configure(struct drm_device *dev) 73145132Sanholt{ 74145132Sanholt dev->driver->driver_features = 75145132Sanholt DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR | 76145132Sanholt DRIVER_HAVE_IRQ; 77145132Sanholt 78145132Sanholt dev->driver->buf_priv_size = sizeof(drm_i915_private_t); 79145132Sanholt dev->driver->load = i915_driver_load; 80145132Sanholt dev->driver->unload = i915_driver_unload; 81145132Sanholt dev->driver->firstopen = i915_driver_firstopen; 82145132Sanholt dev->driver->preclose = i915_driver_preclose; 83145132Sanholt dev->driver->lastclose = i915_driver_lastclose; 84145132Sanholt dev->driver->device_is_agp = i915_driver_device_is_agp; 85145132Sanholt dev->driver->get_vblank_counter = i915_get_vblank_counter; 86145132Sanholt dev->driver->enable_vblank = i915_enable_vblank; 87145132Sanholt dev->driver->disable_vblank = i915_disable_vblank; 88145132Sanholt dev->driver->irq_preinstall = i915_driver_irq_preinstall; 89145132Sanholt dev->driver->irq_postinstall = i915_driver_irq_postinstall; 90145132Sanholt dev->driver->irq_uninstall = i915_driver_irq_uninstall; 91145132Sanholt dev->driver->irq_handler = i915_driver_irq_handler; 92145132Sanholt 93145132Sanholt dev->driver->ioctls = i915_ioctls; 94145132Sanholt dev->driver->max_ioctl = i915_max_ioctl; 95145132Sanholt 96145132Sanholt dev->driver->name = DRIVER_NAME; 97145132Sanholt dev->driver->desc = DRIVER_DESC; 98145132Sanholt dev->driver->date = DRIVER_DATE; 99145132Sanholt dev->driver->major = DRIVER_MAJOR; 100145132Sanholt dev->driver->minor = DRIVER_MINOR; 101145132Sanholt dev->driver->patchlevel = DRIVER_PATCHLEVEL; 102145132Sanholt} 103145132Sanholt 104145132Sanholtstatic int 105145132Sanholti915_probe(device_t dev) 106145132Sanholt{ 107145132Sanholt return drm_probe(dev, i915_pciidlist); 108145132Sanholt} 109145132Sanholt 110145132Sanholtstatic int 111145132Sanholti915_attach(device_t nbdev) 112145132Sanholt{ 113 struct drm_device *dev = device_get_softc(nbdev); 114 115 bzero(dev, sizeof(struct drm_device)); 116 117 dev->driver = malloc(sizeof(struct drm_driver_info), M_DRM, M_NOWAIT | M_ZERO); 118 i915_configure(dev); 119 120 return drm_attach(nbdev, i915_pciidlist); 121} 122 123static int 124i915_detach(device_t nbdev) 125{ 126 struct drm_device *dev = device_get_softc(nbdev); 127 int ret; 128 129 ret = drm_detach(nbdev); 130 131 free(dev->driver, M_DRM); 132 133 return ret; 134} 135 136static device_method_t i915_methods[] = { 137 /* Device interface */ 138 DEVMETHOD(device_probe, i915_probe), 139 DEVMETHOD(device_attach, i915_attach), 140 DEVMETHOD(device_suspend, i915_suspend), 141 DEVMETHOD(device_resume, i915_resume), 142 DEVMETHOD(device_detach, i915_detach), 143 144 { 0, 0 } 145}; 146 147static driver_t i915_driver = { 148#if __FreeBSD_version >= 700010 149 "drm", 150#else 151 "drmsub", 152#endif 153 i915_methods, 154 sizeof(struct drm_device) 155}; 156 157extern devclass_t drm_devclass; 158#if __FreeBSD_version >= 700010 159DRIVER_MODULE(i915, vgapci, i915_driver, drm_devclass, 0, 0); 160#else 161DRIVER_MODULE(i915, agp, i915_driver, drm_devclass, 0, 0); 162#endif 163MODULE_DEPEND(i915, drm, 1, 1, 1); 164