i915_drv.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
  2. */
  3. /*
  4. *
  5. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  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
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sub license, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial portions
  18. * of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. */
  29. #include <linux/device.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "i915_drm.h"
  33. #include "i915_drv.h"
  34. #include "drm_pciids.h"
  35. #include <linux/console.h>
  36. static unsigned int i915_modeset = -1;
  37. module_param_named(modeset, i915_modeset, int, 0400);
  38. unsigned int i915_fbpercrtc = 0;
  39. module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400);
  40. static struct pci_device_id pciidlist[] = {
  41. i915_PCI_IDS
  42. };
  43. #if defined(CONFIG_DRM_I915_KMS)
  44. MODULE_DEVICE_TABLE(pci, pciidlist);
  45. #endif
  46. static int i915_suspend(struct drm_device *dev, pm_message_t state)
  47. {
  48. struct drm_i915_private *dev_priv = dev->dev_private;
  49. if (!dev || !dev_priv) {
  50. printk(KERN_ERR "dev: %p, dev_priv: %p\n", dev, dev_priv);
  51. printk(KERN_ERR "DRM not initialized, aborting suspend.\n");
  52. return -ENODEV;
  53. }
  54. if (state.event == PM_EVENT_PRETHAW)
  55. return 0;
  56. pci_save_state(dev->pdev);
  57. i915_save_state(dev);
  58. /* If KMS is active, we do the leavevt stuff here */
  59. if (drm_core_check_feature(dev, DRIVER_MODESET) && i915_gem_idle(dev)) {
  60. dev_err(&dev->pdev->dev, "GEM idle failed, aborting suspend\n");
  61. return -EBUSY;
  62. }
  63. intel_opregion_free(dev);
  64. if (state.event == PM_EVENT_SUSPEND) {
  65. /* Shut down the device */
  66. pci_disable_device(dev->pdev);
  67. pci_set_power_state(dev->pdev, PCI_D3hot);
  68. }
  69. return 0;
  70. }
  71. static int i915_resume(struct drm_device *dev)
  72. {
  73. struct drm_i915_private *dev_priv = dev->dev_private;
  74. int ret = 0;
  75. pci_set_power_state(dev->pdev, PCI_D0);
  76. pci_restore_state(dev->pdev);
  77. if (pci_enable_device(dev->pdev))
  78. return -1;
  79. pci_set_master(dev->pdev);
  80. i915_restore_state(dev);
  81. intel_opregion_init(dev);
  82. /* KMS EnterVT equivalent */
  83. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  84. mutex_lock(&dev->struct_mutex);
  85. dev_priv->mm.suspended = 0;
  86. ret = i915_gem_init_ringbuffer(dev);
  87. if (ret != 0)
  88. ret = -1;
  89. mutex_unlock(&dev->struct_mutex);
  90. }
  91. return ret;
  92. }
  93. static struct vm_operations_struct i915_gem_vm_ops = {
  94. .fault = i915_gem_fault,
  95. .open = drm_gem_vm_open,
  96. .close = drm_gem_vm_close,
  97. };
  98. static struct drm_driver driver = {
  99. /* don't use mtrr's here, the Xserver or user space app should
  100. * deal with them for intel hardware.
  101. */
  102. .driver_features =
  103. DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
  104. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM,
  105. .load = i915_driver_load,
  106. .unload = i915_driver_unload,
  107. .open = i915_driver_open,
  108. .lastclose = i915_driver_lastclose,
  109. .preclose = i915_driver_preclose,
  110. .postclose = i915_driver_postclose,
  111. .suspend = i915_suspend,
  112. .resume = i915_resume,
  113. .device_is_agp = i915_driver_device_is_agp,
  114. .enable_vblank = i915_enable_vblank,
  115. .disable_vblank = i915_disable_vblank,
  116. .irq_preinstall = i915_driver_irq_preinstall,
  117. .irq_postinstall = i915_driver_irq_postinstall,
  118. .irq_uninstall = i915_driver_irq_uninstall,
  119. .irq_handler = i915_driver_irq_handler,
  120. .reclaim_buffers = drm_core_reclaim_buffers,
  121. .get_map_ofs = drm_core_get_map_ofs,
  122. .get_reg_ofs = drm_core_get_reg_ofs,
  123. .master_create = i915_master_create,
  124. .master_destroy = i915_master_destroy,
  125. .proc_init = i915_gem_proc_init,
  126. .proc_cleanup = i915_gem_proc_cleanup,
  127. .gem_init_object = i915_gem_init_object,
  128. .gem_free_object = i915_gem_free_object,
  129. .gem_vm_ops = &i915_gem_vm_ops,
  130. .ioctls = i915_ioctls,
  131. .fops = {
  132. .owner = THIS_MODULE,
  133. .open = drm_open,
  134. .release = drm_release,
  135. .ioctl = drm_ioctl,
  136. .mmap = drm_gem_mmap,
  137. .poll = drm_poll,
  138. .fasync = drm_fasync,
  139. #ifdef CONFIG_COMPAT
  140. .compat_ioctl = i915_compat_ioctl,
  141. #endif
  142. },
  143. .pci_driver = {
  144. .name = DRIVER_NAME,
  145. .id_table = pciidlist,
  146. },
  147. .name = DRIVER_NAME,
  148. .desc = DRIVER_DESC,
  149. .date = DRIVER_DATE,
  150. .major = DRIVER_MAJOR,
  151. .minor = DRIVER_MINOR,
  152. .patchlevel = DRIVER_PATCHLEVEL,
  153. };
  154. static int __init i915_init(void)
  155. {
  156. driver.num_ioctls = i915_max_ioctl;
  157. /*
  158. * If CONFIG_DRM_I915_KMS is set, default to KMS unless
  159. * explicitly disabled with the module pararmeter.
  160. *
  161. * Otherwise, just follow the parameter (defaulting to off).
  162. *
  163. * Allow optional vga_text_mode_force boot option to override
  164. * the default behavior.
  165. */
  166. #if defined(CONFIG_DRM_I915_KMS)
  167. if (i915_modeset != 0)
  168. driver.driver_features |= DRIVER_MODESET;
  169. #endif
  170. if (i915_modeset == 1)
  171. driver.driver_features |= DRIVER_MODESET;
  172. #ifdef CONFIG_VGA_CONSOLE
  173. if (vgacon_text_force() && i915_modeset == -1)
  174. driver.driver_features &= ~DRIVER_MODESET;
  175. #endif
  176. return drm_init(&driver);
  177. }
  178. static void __exit i915_exit(void)
  179. {
  180. drm_exit(&driver);
  181. }
  182. module_init(i915_init);
  183. module_exit(i915_exit);
  184. MODULE_AUTHOR(DRIVER_AUTHOR);
  185. MODULE_DESCRIPTION(DRIVER_DESC);
  186. MODULE_LICENSE("GPL and additional rights");