Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
| 28 | #include <drm/i915_drm.h> |
Eric Anholt | f0217c4 | 2009-12-01 11:56:30 -0800 | [diff] [blame] | 29 | #include "intel_drv.h" |
Eugeni Dodonov | 5e5b7fa | 2012-01-07 23:40:34 -0200 | [diff] [blame] | 30 | #include "i915_reg.h" |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 31 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 32 | static void i915_save_display(struct drm_i915_private *dev_priv) |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 33 | { |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 34 | /* Display arbitration control */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 35 | if (INTEL_GEN(dev_priv) <= 4) |
Paulo Zanoni | 8de0add | 2013-01-18 18:29:03 -0200 | [diff] [blame] | 36 | dev_priv->regfile.saveDSPARB = I915_READ(DSPARB); |
Zhao Yakui | fccdaba | 2009-07-08 14:13:14 +0800 | [diff] [blame] | 37 | |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 38 | /* save FBC interval */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 39 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) <= 4 && !IS_G4X(dev_priv)) |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 40 | dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 43 | static void i915_restore_display(struct drm_i915_private *dev_priv) |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 44 | { |
Keith Packard | 881ee98 | 2008-11-02 23:08:44 -0800 | [diff] [blame] | 45 | /* Display arbitration */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 46 | if (INTEL_GEN(dev_priv) <= 4) |
Paulo Zanoni | 8de0add | 2013-01-18 18:29:03 -0200 | [diff] [blame] | 47 | I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 48 | |
Zhao Yakui | a2c459e | 2010-03-19 17:05:10 +0800 | [diff] [blame] | 49 | /* only restore FBC info on the platform that supports FBC*/ |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 50 | intel_fbc_global_disable(dev_priv); |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 51 | |
| 52 | /* restore FBC interval */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 53 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) <= 4 && !IS_G4X(dev_priv)) |
Ville Syrjälä | 768cf7f | 2014-01-23 16:49:15 +0200 | [diff] [blame] | 54 | I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL); |
Daniel Vetter | a65e827 | 2013-01-25 17:53:22 +0100 | [diff] [blame] | 55 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 56 | i915_redisable_vga(dev_priv); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 59 | int i915_save_state(struct drm_i915_private *dev_priv) |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 60 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 61 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 62 | int i; |
| 63 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 64 | mutex_lock(&dev_priv->drm.struct_mutex); |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 65 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 66 | i915_save_display(dev_priv); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 67 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 68 | if (IS_GEN4(dev_priv)) |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 69 | pci_read_config_word(pdev, GCDGMBUS, |
Jesse Barnes | 9f49c37 | 2014-12-10 12:16:05 -0800 | [diff] [blame] | 70 | &dev_priv->regfile.saveGCDGMBUS); |
| 71 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 72 | /* Cache mode state */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 73 | if (INTEL_GEN(dev_priv) < 7) |
Jesse Barnes | e8cde23 | 2013-10-11 12:09:29 -0700 | [diff] [blame] | 74 | dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 75 | |
| 76 | /* Memory Arbitration state */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 77 | dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 78 | |
| 79 | /* Scratch space */ |
Ville Syrjälä | 85fa792 | 2015-09-18 20:03:43 +0300 | [diff] [blame] | 80 | if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) { |
| 81 | for (i = 0; i < 7; i++) { |
| 82 | dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i)); |
| 83 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); |
| 84 | } |
| 85 | for (i = 0; i < 3; i++) |
| 86 | dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i)); |
| 87 | } else if (IS_GEN2(dev_priv)) { |
| 88 | for (i = 0; i < 7; i++) |
| 89 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); |
| 90 | } else if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 91 | for (i = 0; i < 16; i++) { |
| 92 | dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i)); |
| 93 | dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); |
| 94 | } |
| 95 | for (i = 0; i < 3; i++) |
| 96 | dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i)); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 97 | } |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 98 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 99 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 100 | |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 101 | return 0; |
| 102 | } |
| 103 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 104 | int i915_restore_state(struct drm_i915_private *dev_priv) |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 105 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 106 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 107 | int i; |
| 108 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 109 | mutex_lock(&dev_priv->drm.struct_mutex); |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 110 | |
Tvrtko Ursulin | 4362f4f | 2016-11-16 08:55:33 +0000 | [diff] [blame] | 111 | i915_gem_restore_fences(dev_priv); |
Jesse Barnes | 9f49c37 | 2014-12-10 12:16:05 -0800 | [diff] [blame] | 112 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 113 | if (IS_GEN4(dev_priv)) |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 114 | pci_write_config_word(pdev, GCDGMBUS, |
Jesse Barnes | 9f49c37 | 2014-12-10 12:16:05 -0800 | [diff] [blame] | 115 | dev_priv->regfile.saveGCDGMBUS); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 116 | i915_restore_display(dev_priv); |
Ben Gamari | 1341d65 | 2009-09-14 17:48:42 -0400 | [diff] [blame] | 117 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 118 | /* Cache mode state */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 119 | if (INTEL_GEN(dev_priv) < 7) |
Jesse Barnes | e8cde23 | 2013-10-11 12:09:29 -0700 | [diff] [blame] | 120 | I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 | |
| 121 | 0xffff0000); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 122 | |
| 123 | /* Memory arbitration state */ |
Daniel Vetter | f4c956a | 2012-11-02 19:55:02 +0100 | [diff] [blame] | 124 | I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 125 | |
Ville Syrjälä | 85fa792 | 2015-09-18 20:03:43 +0300 | [diff] [blame] | 126 | /* Scratch space */ |
| 127 | if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) { |
| 128 | for (i = 0; i < 7; i++) { |
| 129 | I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]); |
| 130 | I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); |
| 131 | } |
| 132 | for (i = 0; i < 3; i++) |
| 133 | I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]); |
| 134 | } else if (IS_GEN2(dev_priv)) { |
| 135 | for (i = 0; i < 7; i++) |
| 136 | I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); |
| 137 | } else if (HAS_GMCH_DISPLAY(dev_priv)) { |
| 138 | for (i = 0; i < 16; i++) { |
| 139 | I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]); |
| 140 | I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); |
| 141 | } |
| 142 | for (i = 0; i < 3; i++) |
| 143 | I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]); |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 144 | } |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 145 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 146 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Keith Packard | d70bed1 | 2011-06-29 00:30:34 -0700 | [diff] [blame] | 147 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 148 | intel_i2c_reset(dev_priv); |
Eric Anholt | f0217c4 | 2009-12-01 11:56:30 -0800 | [diff] [blame] | 149 | |
Jesse Barnes | 317c35d | 2008-08-25 15:11:06 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | } |