blob: a0af170062b1ea859f3d2297a500a8937f7b72df [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
Keith Packardd70bed12011-06-29 00:30:34 -070032static void i915_save_display(struct drm_device *dev)
Zhao Yakuifccdaba2009-07-08 14:13:14 +080033{
Chris Wilsonfac5e232016-07-04 11:34:36 +010034 struct drm_i915_private *dev_priv = to_i915(dev);
Zhao Yakuifccdaba2009-07-08 14:13:14 +080035
36 /* Display arbitration control */
Paulo Zanoni8de0add2013-01-18 18:29:03 -020037 if (INTEL_INFO(dev)->gen <= 4)
38 dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
Zhao Yakuifccdaba2009-07-08 14:13:14 +080039
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020040 /* save FBC interval */
41 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
42 dev_priv->regfile.saveFBC_CONTROL = I915_READ(FBC_CONTROL);
Jesse Barnes317c35d2008-08-25 15:11:06 -070043}
44
Keith Packardd70bed12011-06-29 00:30:34 -070045static void i915_restore_display(struct drm_device *dev)
Jesse Barnes317c35d2008-08-25 15:11:06 -070046{
Chris Wilsonfac5e232016-07-04 11:34:36 +010047 struct drm_i915_private *dev_priv = to_i915(dev);
Peng Li461cba22008-11-18 12:39:02 +080048
Keith Packard881ee982008-11-02 23:08:44 -080049 /* Display arbitration */
Paulo Zanoni8de0add2013-01-18 18:29:03 -020050 if (INTEL_INFO(dev)->gen <= 4)
51 I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
Jesse Barnes317c35d2008-08-25 15:11:06 -070052
Zhao Yakuia2c459e2010-03-19 17:05:10 +080053 /* only restore FBC info on the platform that supports FBC*/
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020054 intel_fbc_global_disable(dev_priv);
Ville Syrjälä768cf7f2014-01-23 16:49:15 +020055
56 /* restore FBC interval */
57 if (HAS_FBC(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev))
58 I915_WRITE(FBC_CONTROL, dev_priv->regfile.saveFBC_CONTROL);
Daniel Vettera65e8272013-01-25 17:53:22 +010059
Daniel Vetter8634bd42015-02-23 12:03:30 +010060 i915_redisable_vga(dev);
Ben Gamari1341d652009-09-14 17:48:42 -040061}
62
63int i915_save_state(struct drm_device *dev)
64{
Chris Wilsonfac5e232016-07-04 11:34:36 +010065 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehall52a05c32016-08-22 13:32:44 +030066 struct pci_dev *pdev = dev_priv->drm.pdev;
Ben Gamari1341d652009-09-14 17:48:42 -040067 int i;
68
Keith Packardd70bed12011-06-29 00:30:34 -070069 mutex_lock(&dev->struct_mutex);
70
Ben Gamari1341d652009-09-14 17:48:42 -040071 i915_save_display(dev);
72
Jesse Barnes9f49c372014-12-10 12:16:05 -080073 if (IS_GEN4(dev))
David Weinehall52a05c32016-08-22 13:32:44 +030074 pci_read_config_word(pdev, GCDGMBUS,
Jesse Barnes9f49c372014-12-10 12:16:05 -080075 &dev_priv->regfile.saveGCDGMBUS);
76
Ben Gamari1341d652009-09-14 17:48:42 -040077 /* Cache mode state */
Jesse Barnese8cde232013-10-11 12:09:29 -070078 if (INTEL_INFO(dev)->gen < 7)
79 dev_priv->regfile.saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
Ben Gamari1341d652009-09-14 17:48:42 -040080
81 /* Memory Arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +010082 dev_priv->regfile.saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
Ben Gamari1341d652009-09-14 17:48:42 -040083
84 /* Scratch space */
Ville Syrjälä85fa7922015-09-18 20:03:43 +030085 if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) {
86 for (i = 0; i < 7; i++) {
87 dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
88 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
89 }
90 for (i = 0; i < 3; i++)
91 dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
92 } else if (IS_GEN2(dev_priv)) {
93 for (i = 0; i < 7; i++)
94 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
95 } else if (HAS_GMCH_DISPLAY(dev_priv)) {
96 for (i = 0; i < 16; i++) {
97 dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
98 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
99 }
100 for (i = 0; i < 3; i++)
101 dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
Ben Gamari1341d652009-09-14 17:48:42 -0400102 }
Ben Gamari1341d652009-09-14 17:48:42 -0400103
Keith Packardd70bed12011-06-29 00:30:34 -0700104 mutex_unlock(&dev->struct_mutex);
105
Ben Gamari1341d652009-09-14 17:48:42 -0400106 return 0;
107}
108
109int i915_restore_state(struct drm_device *dev)
110{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100111 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehall52a05c32016-08-22 13:32:44 +0300112 struct pci_dev *pdev = dev_priv->drm.pdev;
Ben Gamari1341d652009-09-14 17:48:42 -0400113 int i;
114
Keith Packardd70bed12011-06-29 00:30:34 -0700115 mutex_lock(&dev->struct_mutex);
116
Chris Wilson19b2dbd2013-06-12 10:15:12 +0100117 i915_gem_restore_fences(dev);
Jesse Barnes9f49c372014-12-10 12:16:05 -0800118
119 if (IS_GEN4(dev))
David Weinehall52a05c32016-08-22 13:32:44 +0300120 pci_write_config_word(pdev, GCDGMBUS,
Jesse Barnes9f49c372014-12-10 12:16:05 -0800121 dev_priv->regfile.saveGCDGMBUS);
Ben Gamari1341d652009-09-14 17:48:42 -0400122 i915_restore_display(dev);
123
Jesse Barnes317c35d2008-08-25 15:11:06 -0700124 /* Cache mode state */
Jesse Barnese8cde232013-10-11 12:09:29 -0700125 if (INTEL_INFO(dev)->gen < 7)
126 I915_WRITE(CACHE_MODE_0, dev_priv->regfile.saveCACHE_MODE_0 |
127 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700128
129 /* Memory arbitration state */
Daniel Vetterf4c956a2012-11-02 19:55:02 +0100130 I915_WRITE(MI_ARB_STATE, dev_priv->regfile.saveMI_ARB_STATE | 0xffff0000);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700131
Ville Syrjälä85fa7922015-09-18 20:03:43 +0300132 /* Scratch space */
133 if (IS_GEN2(dev_priv) && IS_MOBILE(dev_priv)) {
134 for (i = 0; i < 7; i++) {
135 I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
136 I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
137 }
138 for (i = 0; i < 3; i++)
139 I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
140 } else if (IS_GEN2(dev_priv)) {
141 for (i = 0; i < 7; i++)
142 I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
143 } else if (HAS_GMCH_DISPLAY(dev_priv)) {
144 for (i = 0; i < 16; i++) {
145 I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
146 I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
147 }
148 for (i = 0; i < 3; i++)
149 I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
Jesse Barnes317c35d2008-08-25 15:11:06 -0700150 }
Jesse Barnes317c35d2008-08-25 15:11:06 -0700151
Keith Packardd70bed12011-06-29 00:30:34 -0700152 mutex_unlock(&dev->struct_mutex);
153
Chris Wilsonf899fc62010-07-20 15:44:45 -0700154 intel_i2c_reset(dev);
Eric Anholtf0217c42009-12-01 11:56:30 -0800155
Jesse Barnes317c35d2008-08-25 15:11:06 -0700156 return 0;
157}