i915_suspend.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. *
  3. * Copyright 2008 (c) Intel Corporation
  4. * Jesse Barnes <jbarnes@virtuousgeek.org>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/i915_drm.h>
  28. #include "intel_drv.h"
  29. #include "i915_reg.h"
  30. static void i915_save_display(struct drm_device *dev)
  31. {
  32. struct drm_i915_private *dev_priv = to_i915(dev);
  33. /* Display arbitration control */
  34. if (INTEL_INFO(dev)->gen <= 4)
  35. dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
  36. /* save FBC interval */
  37. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
  38. dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL);
  39. }
  40. static void i915_restore_display(struct drm_device *dev)
  41. {
  42. struct drm_i915_private *dev_priv = to_i915(dev);
  43. /* Display arbitration */
  44. if (INTEL_INFO(dev)->gen <= 4)
  45. I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
  46. /* only restore FBC info on the platform that supports FBC*/
  47. intel_fbc_global_disable(dev_priv);
  48. /* restore FBC interval */
  49. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
  50. I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL);
  51. i915_redisable_vga(dev);
  52. }
  53. int i915_save_state(struct drm_device *dev)
  54. {
  55. struct drm_i915_private *dev_priv = to_i915(dev);
  56. struct pci_dev *pdev = dev_priv->drm.pdev;
  57. int i;
  58. mutex_lock(&dev->struct_mutex);
  59. i915_save_display(dev);
  60. if (IS_GEN4(dev))
  61. pci_read_config_word(pdev, GCDGMBUS,
  62. &dev_priv->regfile.saveGCDGMBUS);
  63. /* Cache mode state */
  64. if (INTEL_INFO(dev)->gen < 7)
  65. dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
  66. /* Memory Arbitration state */
  67. dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
  68. /* Scratch space */
  69. if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) {
  70. for (i = 0; i < 7; i++) {
  71. dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
  72. dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
  73. }
  74. for (i = 0; i < 3; i++)
  75. dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
  76. } else if (IS_GEN2(dev_priv)) {
  77. for (i = 0; i < 7; i++)
  78. dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
  79. } else if (HAS_GMCH_DISPLAY(dev_priv)) {
  80. for (i = 0; i < 16; i++) {
  81. dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
  82. dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
  83. }
  84. for (i = 0; i < 3; i++)
  85. dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
  86. }
  87. mutex_unlock(&dev->struct_mutex);
  88. return 0;
  89. }
  90. int i915_restore_state(struct drm_device *dev)
  91. {
  92. struct drm_i915_private *dev_priv = to_i915(dev);
  93. struct pci_dev *pdev = dev_priv->drm.pdev;
  94. int i;
  95. mutex_lock(&dev->struct_mutex);
  96. i915_gem_restore_fences(dev);
  97. if (IS_GEN4(dev))
  98. pci_write_config_word(pdev, GCDGMBUS,
  99. dev_priv->regfile.saveGCDGMBUS);
  100. i915_restore_display(dev);
  101. /* Cache mode state */
  102. if (INTEL_INFO(dev)->gen < 7)
  103. I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 |
  104. 0xffff0000);
  105. /* Memory arbitration state */
  106. I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000);
  107. /* Scratch space */
  108. if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) {
  109. for (i = 0; i < 7; i++) {
  110. I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
  111. I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
  112. }
  113. for (i = 0; i < 3; i++)
  114. I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
  115. } else if (IS_GEN2(dev_priv)) {
  116. for (i = 0; i < 7; i++)
  117. I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
  118. } else if (HAS_GMCH_DISPLAY(dev_priv)) {
  119. for (i = 0; i < 16; i++) {
  120. I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
  121. I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
  122. }
  123. for (i = 0; i < 3; i++)
  124. I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
  125. }
  126. mutex_unlock(&dev->struct_mutex);
  127. intel_i2c_reset(dev);
  128. return 0;
  129. }