blob: 5c86925a029438d795e07d4f72f7da56e2605b23 [file] [log] [blame]
Jesse Barnes317c35d2008-08-25 15:11:06 -07001/*
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 Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/i915_drm.h>
Eric Anholtf0217c42009-12-01 11:56:30 -080029#include "intel_drv.h"
Eugeni Dodonov5e5b7fa2012-01-07 23:40:34 -020030#include "i915_reg.h"
Jesse Barnes317c35d2008-08-25 15:11:06 -070031
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000032static void i915_save_display(struct drm_i915_private *dev_priv)
Zhao Yakuifccdaba2009-07-08 14:13:14 +080033{
Zhao Yakuifccdaba2009-07-08 14:13:14 +080034 /* Display arbitration control */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000035 if (INTEL_GEN(dev_priv) <= 4)
Paulo Zanoni8de0add2013-01-18 18:29:03 -020036 dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
Zhao Yakuifccdaba2009-07-08 14:13:14 +080037
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020038 /* save FBC interval */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010039 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) <= 4 && !IS_G4X(dev_priv))
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020040 dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL);
Jesse Barnes317c35d2008-08-25 15:11:06 -070041}
42
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000043static void i915_restore_display(struct drm_i915_private *dev_priv)
Jesse Barnes317c35d2008-08-25 15:11:06 -070044{
Keith Packard881ee982008-11-02 23:08:44 -080045 /* Display arbitration */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000046 if (INTEL_GEN(dev_priv) <= 4)
Paulo Zanoni8de0add2013-01-18 18:29:03 -020047 I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
Jesse Barnes317c35d2008-08-25 15:11:06 -070048
Zhao Yakuia2c459e2010-03-19 17:05:10 +080049 /* only restore FBC info on the platform that supports FBC*/
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020050 intel_fbc_global_disable(dev_priv);
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020051
52 /* restore FBC interval */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010053 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) <= 4 && !IS_G4X(dev_priv))
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020054 I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL);
Daniel Vettera65e8272013-01-25 17:53:22 +010055
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000056 i915_redisable_vga(dev_priv);
Ben Gamari1341d652009-09-14 17:48:42 -040057}
58
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +000059int i915_save_state(struct drm_i915_private *dev_priv)
Ben Gamari1341d652009-09-14 17:48:42 -040060{
David Weinehall52a05c32016-08-22 13:32:44 +030061 struct pci_dev *pdev = dev_priv->drm.pdev;
Ben Gamari1341d652009-09-14 17:48:42 -040062 int i;
63
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +000064 mutex_lock(&dev_priv->drm.struct_mutex);
Keith Packardd70bed12011-06-29 00:30:34 -070065
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000066 i915_save_display(dev_priv);
Ben Gamari1341d652009-09-14 17:48:42 -040067
Tvrtko Ursulin5db94012016-10-13 11:03:10 +010068 if (IS_GEN4(dev_priv))
David Weinehall52a05c32016-08-22 13:32:44 +030069 pci_read_config_word(pdev, GCDGMBUS,
Jesse Barnes9f49c372014-12-10 12:16:05 -080070 &dev_priv->regfile.saveGCDGMBUS);
71
Ben Gamari1341d652009-09-14 17:48:42 -040072 /* Cache mode state */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000073 if (INTEL_GEN(dev_priv) < 7)
Jesse Barnese8cde232013-10-11 12:09:29 -070074 dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
Ben Gamari1341d652009-09-14 17:48:42 -040075
76 /* Memory Arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +010077 dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
Ben Gamari1341d652009-09-14 17:48:42 -040078
79 /* Scratch space */
Ville Syrjälä85fa7922015-09-18 20:03:43 +030080 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 Gamari1341d652009-09-14 17:48:42 -040097 }
Ben Gamari1341d652009-09-14 17:48:42 -040098
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +000099 mutex_unlock(&dev_priv->drm.struct_mutex);
Keith Packardd70bed12011-06-29 00:30:34 -0700100
Ben Gamari1341d652009-09-14 17:48:42 -0400101 return 0;
102}
103
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +0000104int i915_restore_state(struct drm_i915_private *dev_priv)
Ben Gamari1341d652009-09-14 17:48:42 -0400105{
David Weinehall52a05c32016-08-22 13:32:44 +0300106 struct pci_dev *pdev = dev_priv->drm.pdev;
Ben Gamari1341d652009-09-14 17:48:42 -0400107 int i;
108
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +0000109 mutex_lock(&dev_priv->drm.struct_mutex);
Keith Packardd70bed12011-06-29 00:30:34 -0700110
Tvrtko Ursulin4362f4f2016-11-16 08:55:33 +0000111 i915_gem_restore_fences(dev_priv);
Jesse Barnes9f49c372014-12-10 12:16:05 -0800112
Tvrtko Ursulin5db94012016-10-13 11:03:10 +0100113 if (IS_GEN4(dev_priv))
David Weinehall52a05c32016-08-22 13:32:44 +0300114 pci_write_config_word(pdev, GCDGMBUS,
Jesse Barnes9f49c372014-12-10 12:16:05 -0800115 dev_priv->regfile.saveGCDGMBUS);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +0000116 i915_restore_display(dev_priv);
Ben Gamari1341d652009-09-14 17:48:42 -0400117
Jesse Barnes317c35d2008-08-25 15:11:06 -0700118 /* Cache mode state */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +0000119 if (INTEL_GEN(dev_priv) < 7)
Jesse Barnese8cde232013-10-11 12:09:29 -0700120 I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 |
121 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700122
123 /* Memory arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100124 I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700125
Ville Syrjälä85fa7922015-09-18 20:03:43 +0300126 /* 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 Barnes317c35d2008-08-25 15:11:06 -0700144 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700145
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +0000146 mutex_unlock(&dev_priv->drm.struct_mutex);
Keith Packardd70bed12011-06-29 00:30:34 -0700147
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +0000148 intel_i2c_reset(dev_priv);
Eric Anholtf0217c42009-12-01 11:56:30 -0800149
Jesse Barnes317c35d2008-08-25 15:11:06 -0700150 return 0;
151}