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 27 #include "display/intel_fbc.h" 28 #include "display/intel_gmbus.h" 29 #include "display/intel_vga.h" 30 31 #include "i915_drv.h" 32 #include "i915_reg.h" 33 #include "i915_suspend.h" 34 35 static void intel_save_swf(struct drm_i915_private *dev_priv) 36 { 37 int i; 38 39 /* Scratch space */ 40 if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) { 41 for (i = 0; i < 7; i++) { 42 dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i)); 43 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); 44 } 45 for (i = 0; i < 3; i++) 46 dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i)); 47 } else if (IS_GEN(dev_priv, 2)) { 48 for (i = 0; i < 7; i++) 49 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); 50 } else if (HAS_GMCH(dev_priv)) { 51 for (i = 0; i < 16; i++) { 52 dev_priv->regfile.saveSWF0[i] = I915_READ(SWF0(i)); 53 dev_priv->regfile.saveSWF1[i] = I915_READ(SWF1(i)); 54 } 55 for (i = 0; i < 3; i++) 56 dev_priv->regfile.saveSWF3[i] = I915_READ(SWF3(i)); 57 } 58 } 59 60 static void intel_restore_swf(struct drm_i915_private *dev_priv) 61 { 62 int i; 63 64 /* Scratch space */ 65 if (IS_GEN(dev_priv, 2) && IS_MOBILE(dev_priv)) { 66 for (i = 0; i < 7; i++) { 67 I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]); 68 I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); 69 } 70 for (i = 0; i < 3; i++) 71 I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]); 72 } else if (IS_GEN(dev_priv, 2)) { 73 for (i = 0; i < 7; i++) 74 I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); 75 } else if (HAS_GMCH(dev_priv)) { 76 for (i = 0; i < 16; i++) { 77 I915_WRITE(SWF0(i), dev_priv->regfile.saveSWF0[i]); 78 I915_WRITE(SWF1(i), dev_priv->regfile.saveSWF1[i]); 79 } 80 for (i = 0; i < 3; i++) 81 I915_WRITE(SWF3(i), dev_priv->regfile.saveSWF3[i]); 82 } 83 } 84 85 void i915_save_display(struct drm_i915_private *dev_priv) 86 { 87 struct pci_dev *pdev = dev_priv->drm.pdev; 88 89 /* Display arbitration control */ 90 if (INTEL_GEN(dev_priv) <= 4) 91 dev_priv->regfile.saveDSPARB = I915_READ(DSPARB); 92 93 if (IS_GEN(dev_priv, 4)) 94 pci_read_config_word(pdev, GCDGMBUS, 95 &dev_priv->regfile.saveGCDGMBUS); 96 97 intel_save_swf(dev_priv); 98 } 99 100 void i915_restore_display(struct drm_i915_private *dev_priv) 101 { 102 struct pci_dev *pdev = dev_priv->drm.pdev; 103 104 intel_restore_swf(dev_priv); 105 106 if (IS_GEN(dev_priv, 4)) 107 pci_write_config_word(pdev, GCDGMBUS, 108 dev_priv->regfile.saveGCDGMBUS); 109 110 /* Display arbitration */ 111 if (INTEL_GEN(dev_priv) <= 4) 112 I915_WRITE(DSPARB, dev_priv->regfile.saveDSPARB); 113 114 /* only restore FBC info on the platform that supports FBC*/ 115 intel_fbc_global_disable(dev_priv); 116 117 intel_vga_redisable(dev_priv); 118 119 intel_gmbus_reset(dev_priv); 120 } 121