18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2008 (c) Intel Corporation
48c2ecf20Sopenharmony_ci *   Jesse Barnes <jbarnes@virtuousgeek.org>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
198c2ecf20Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
208c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
218c2ecf20Sopenharmony_ci * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
228c2ecf20Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
238c2ecf20Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
248c2ecf20Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include "display/intel_fbc.h"
288c2ecf20Sopenharmony_ci#include "display/intel_gmbus.h"
298c2ecf20Sopenharmony_ci#include "display/intel_vga.h"
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include "i915_drv.h"
328c2ecf20Sopenharmony_ci#include "i915_reg.h"
338c2ecf20Sopenharmony_ci#include "i915_suspend.h"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic void i915_save_display(struct drm_i915_private *dev_priv)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	struct pci_dev *pdev = dev_priv->drm.pdev;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	/* Display arbitration control */
408c2ecf20Sopenharmony_ci	if (INTEL_GEN(dev_priv) <= 4)
418c2ecf20Sopenharmony_ci		dev_priv->regfile.saveDSPARB = I915_READ(DSPARB);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	if (IS_GEN(dev_priv, 4))
448c2ecf20Sopenharmony_ci		pci_read_config_word(pdev, GCDGMBUS,
458c2ecf20Sopenharmony_ci				     &dev_priv->regfile.saveGCDGMBUS);
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic void i915_restore_display(struct drm_i915_private *dev_priv)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	struct pci_dev *pdev = dev_priv->drm.pdev;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	if (IS_GEN(dev_priv, 4))
538c2ecf20Sopenharmony_ci		pci_write_config_word(pdev, GCDGMBUS,
548c2ecf20Sopenharmony_ci				      dev_priv->regfile.saveGCDGMBUS);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* Display arbitration */
578c2ecf20Sopenharmony_ci	if (INTEL_GEN(dev_priv) <= 4)
588c2ecf20Sopenharmony_ci		I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	/* only restore FBC info on the platform that supports FBC*/
618c2ecf20Sopenharmony_ci	intel_fbc_global_disable(dev_priv);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	intel_vga_redisable(dev_priv);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	intel_gmbus_reset(dev_priv);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciint i915_save_state(struct drm_i915_private *dev_priv)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	int i;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	i915_save_display(dev_priv);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	/* Scratch space */
758c2ecf20Sopenharmony_ci	if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) {
768c2ecf20Sopenharmony_ci		for (i = 0; i < 7; i++) {
778c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
788c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
798c2ecf20Sopenharmony_ci		}
808c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++)
818c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
828c2ecf20Sopenharmony_ci	} else if (IS_GEN(dev_priv, 2)) {
838c2ecf20Sopenharmony_ci		for (i = 0; i < 7; i++)
848c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
858c2ecf20Sopenharmony_ci	} else if (HAS_GMCH(dev_priv)) {
868c2ecf20Sopenharmony_ci		for (i = 0; i < 16; i++) {
878c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i));
888c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i));
898c2ecf20Sopenharmony_ci		}
908c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++)
918c2ecf20Sopenharmony_ci			dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i));
928c2ecf20Sopenharmony_ci	}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	return 0;
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciint i915_restore_state(struct drm_i915_private *dev_priv)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	int i;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	i915_restore_display(dev_priv);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	/* Scratch space */
1048c2ecf20Sopenharmony_ci	if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) {
1058c2ecf20Sopenharmony_ci		for (i = 0; i < 7; i++) {
1068c2ecf20Sopenharmony_ci			I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
1078c2ecf20Sopenharmony_ci			I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
1088c2ecf20Sopenharmony_ci		}
1098c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++)
1108c2ecf20Sopenharmony_ci			I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
1118c2ecf20Sopenharmony_ci	} else if (IS_GEN(dev_priv, 2)) {
1128c2ecf20Sopenharmony_ci		for (i = 0; i < 7; i++)
1138c2ecf20Sopenharmony_ci			I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
1148c2ecf20Sopenharmony_ci	} else if (HAS_GMCH(dev_priv)) {
1158c2ecf20Sopenharmony_ci		for (i = 0; i < 16; i++) {
1168c2ecf20Sopenharmony_ci			I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]);
1178c2ecf20Sopenharmony_ci			I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]);
1188c2ecf20Sopenharmony_ci		}
1198c2ecf20Sopenharmony_ci		for (i = 0; i < 3; i++)
1208c2ecf20Sopenharmony_ci			I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]);
1218c2ecf20Sopenharmony_ci	}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	return 0;
1248c2ecf20Sopenharmony_ci}
125