Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 31 | #include "../../../platform/x86/intel_ips.h" |
| 32 | #include <linux/module.h> |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Damien Lespiau | f4db932 | 2013-06-24 22:59:50 +0100 | [diff] [blame] | 34 | #include <drm/i915_powerwell.h> |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 35 | #include <linux/pm_runtime.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 36 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 37 | /** |
| 38 | * RC6 is a special power stage which allows the GPU to enter an very |
| 39 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 40 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 41 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 42 | * |
| 43 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 44 | * among each other with the latency required to enter and leave RC6 and |
| 45 | * voltage consumed by the GPU in different states. |
| 46 | * |
| 47 | * The combination of the following flags define which states GPU is allowed |
| 48 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 49 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 50 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 51 | * which brings the most power savings; deeper states save more power, but |
| 52 | * require higher latency to switch to and wake up. |
| 53 | */ |
| 54 | #define INTEL_RC6_ENABLE (1<<0) |
| 55 | #define INTEL_RC6p_ENABLE (1<<1) |
| 56 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 57 | |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 58 | /* FBC, or Frame Buffer Compression, is a technique employed to compress the |
| 59 | * framebuffer contents in-memory, aiming at reducing the required bandwidth |
| 60 | * during in-memory transfers and, therefore, reduce the power packet. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 61 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 62 | * The benefits of FBC are mostly visible with solid backgrounds and |
| 63 | * variation-less patterns. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 64 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 65 | * FBC-related functionality can be enabled by the means of the |
| 66 | * i915.i915_enable_fbc parameter |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 67 | */ |
| 68 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 69 | static void i8xx_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 70 | { |
| 71 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 72 | u32 fbc_ctl; |
| 73 | |
| 74 | /* Disable compression */ |
| 75 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 76 | if ((fbc_ctl & FBC_CTL_EN) == 0) |
| 77 | return; |
| 78 | |
| 79 | fbc_ctl &= ~FBC_CTL_EN; |
| 80 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 81 | |
| 82 | /* Wait for compressing bit to clear */ |
| 83 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { |
| 84 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 89 | } |
| 90 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 91 | static void i8xx_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 92 | { |
| 93 | struct drm_device *dev = crtc->dev; |
| 94 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 95 | struct drm_framebuffer *fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 96 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 97 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 98 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 99 | int cfb_pitch; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 100 | int i; |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 101 | u32 fbc_ctl; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 102 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 103 | cfb_pitch = dev_priv->fbc.size / FBC_LL_SIZE; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 104 | if (fb->pitches[0] < cfb_pitch) |
| 105 | cfb_pitch = fb->pitches[0]; |
| 106 | |
Ville Syrjälä | 42a430f | 2013-11-28 17:29:56 +0200 | [diff] [blame] | 107 | /* FBC_CTL wants 32B or 64B units */ |
| 108 | if (IS_GEN2(dev)) |
| 109 | cfb_pitch = (cfb_pitch / 32) - 1; |
| 110 | else |
| 111 | cfb_pitch = (cfb_pitch / 64) - 1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 112 | |
| 113 | /* Clear old tags */ |
| 114 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 115 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 116 | |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 117 | if (IS_GEN4(dev)) { |
| 118 | u32 fbc_ctl2; |
| 119 | |
| 120 | /* Set it up... */ |
| 121 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 122 | fbc_ctl2 |= FBC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 123 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 124 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 125 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 126 | |
| 127 | /* enable it... */ |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 128 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 129 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 130 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 131 | if (IS_I945GM(dev)) |
| 132 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 133 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 134 | fbc_ctl |= obj->fence_reg; |
| 135 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 136 | |
Ville Syrjälä | 5cd5410 | 2014-01-23 16:49:16 +0200 | [diff] [blame] | 137 | DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %c\n", |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 138 | cfb_pitch, crtc->y, plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 139 | } |
| 140 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 141 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 142 | { |
| 143 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 144 | |
| 145 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 146 | } |
| 147 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 148 | static void g4x_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 149 | { |
| 150 | struct drm_device *dev = crtc->dev; |
| 151 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 152 | struct drm_framebuffer *fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 153 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 154 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 155 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 156 | u32 dpfc_ctl; |
| 157 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 158 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane) | DPFC_SR_EN; |
| 159 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 160 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 161 | else |
| 162 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 163 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 164 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 165 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 166 | |
| 167 | /* enable it... */ |
Ville Syrjälä | fe74c1a | 2014-01-23 16:49:13 +0200 | [diff] [blame] | 168 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 169 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 170 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 171 | } |
| 172 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 173 | static void g4x_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 174 | { |
| 175 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 176 | u32 dpfc_ctl; |
| 177 | |
| 178 | /* Disable compression */ |
| 179 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 180 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 181 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 182 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 183 | |
| 184 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 185 | } |
| 186 | } |
| 187 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 188 | static bool g4x_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 189 | { |
| 190 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 191 | |
| 192 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 193 | } |
| 194 | |
| 195 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 196 | { |
| 197 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 198 | u32 blt_ecoskpd; |
| 199 | |
| 200 | /* Make sure blitter notifies FBC of writes */ |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 201 | |
| 202 | /* Blitter is part of Media powerwell on VLV. No impact of |
| 203 | * his param in other platforms for now */ |
| 204 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 205 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 206 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 207 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 208 | GEN6_BLITTER_LOCK_SHIFT; |
| 209 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 210 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 211 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 212 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 213 | GEN6_BLITTER_LOCK_SHIFT); |
| 214 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 215 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 216 | |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 217 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_MEDIA); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 218 | } |
| 219 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 220 | static void ironlake_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 221 | { |
| 222 | struct drm_device *dev = crtc->dev; |
| 223 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 224 | struct drm_framebuffer *fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 225 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 226 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 227 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 228 | u32 dpfc_ctl; |
| 229 | |
Ville Syrjälä | 46f3dab | 2014-01-23 16:49:14 +0200 | [diff] [blame] | 230 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 231 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 232 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 233 | else |
| 234 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ville Syrjälä | d629336 | 2013-11-21 21:29:45 +0200 | [diff] [blame] | 235 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
| 236 | if (IS_GEN5(dev)) |
| 237 | dpfc_ctl |= obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 238 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 239 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 240 | I915_WRITE(ILK_FBC_RT_BASE, i915_gem_obj_ggtt_offset(obj) | ILK_FBC_RT_VALID); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 241 | /* enable it... */ |
| 242 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 243 | |
| 244 | if (IS_GEN6(dev)) { |
| 245 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 246 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 247 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 248 | sandybridge_blit_fbc_update(dev); |
| 249 | } |
| 250 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 251 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 252 | } |
| 253 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 254 | static void ironlake_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 255 | { |
| 256 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 257 | u32 dpfc_ctl; |
| 258 | |
| 259 | /* Disable compression */ |
| 260 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 261 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 262 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 263 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 264 | |
| 265 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 266 | } |
| 267 | } |
| 268 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 269 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 270 | { |
| 271 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 272 | |
| 273 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 274 | } |
| 275 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 276 | static void gen7_enable_fbc(struct drm_crtc *crtc) |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 277 | { |
| 278 | struct drm_device *dev = crtc->dev; |
| 279 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 280 | struct drm_framebuffer *fb = crtc->primary->fb; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 281 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 282 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 283 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 284 | u32 dpfc_ctl; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 285 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 286 | dpfc_ctl = IVB_DPFC_CTL_PLANE(intel_crtc->plane); |
| 287 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 288 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 289 | else |
| 290 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
| 291 | dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN; |
| 292 | |
| 293 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 294 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 295 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 296 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 297 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 298 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 299 | ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 300 | } else { |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 301 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 302 | I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe), |
| 303 | I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) | |
| 304 | HSW_FBCQ_DIS); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 305 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 306 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 307 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 308 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 309 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 310 | |
| 311 | sandybridge_blit_fbc_update(dev); |
| 312 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 313 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane)); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 314 | } |
| 315 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 316 | bool intel_fbc_enabled(struct drm_device *dev) |
| 317 | { |
| 318 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 319 | |
| 320 | if (!dev_priv->display.fbc_enabled) |
| 321 | return false; |
| 322 | |
| 323 | return dev_priv->display.fbc_enabled(dev); |
| 324 | } |
| 325 | |
| 326 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 327 | { |
| 328 | struct intel_fbc_work *work = |
| 329 | container_of(to_delayed_work(__work), |
| 330 | struct intel_fbc_work, work); |
| 331 | struct drm_device *dev = work->crtc->dev; |
| 332 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 333 | |
| 334 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 335 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 336 | /* Double check that we haven't switched fb without cancelling |
| 337 | * the prior work. |
| 338 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 339 | if (work->crtc->primary->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 340 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 341 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 342 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 343 | dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id; |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 344 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 345 | } |
| 346 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 347 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 348 | } |
| 349 | mutex_unlock(&dev->struct_mutex); |
| 350 | |
| 351 | kfree(work); |
| 352 | } |
| 353 | |
| 354 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 355 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 356 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 357 | return; |
| 358 | |
| 359 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 360 | |
| 361 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 362 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 363 | * entirely asynchronously. |
| 364 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 365 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 366 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 367 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 368 | |
| 369 | /* Mark the work as no longer wanted so that if it does |
| 370 | * wake-up (because the work was already running and waiting |
| 371 | * for our mutex), it will discover that is no longer |
| 372 | * necessary to run. |
| 373 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 374 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 375 | } |
| 376 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 377 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 378 | { |
| 379 | struct intel_fbc_work *work; |
| 380 | struct drm_device *dev = crtc->dev; |
| 381 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 382 | |
| 383 | if (!dev_priv->display.enable_fbc) |
| 384 | return; |
| 385 | |
| 386 | intel_cancel_fbc_work(dev_priv); |
| 387 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 388 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 389 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 390 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 391 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 392 | return; |
| 393 | } |
| 394 | |
| 395 | work->crtc = crtc; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 396 | work->fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 397 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 398 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 399 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 400 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 401 | /* Delay the actual enabling to let pageflipping cease and the |
| 402 | * display to settle before starting the compression. Note that |
| 403 | * this delay also serves a second purpose: it allows for a |
| 404 | * vblank to pass after disabling the FBC before we attempt |
| 405 | * to modify the control registers. |
| 406 | * |
| 407 | * A more complicated solution would involve tracking vblanks |
| 408 | * following the termination of the page-flipping sequence |
| 409 | * and indeed performing the enable as a co-routine and not |
| 410 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 411 | * |
| 412 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 413 | */ |
| 414 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 415 | } |
| 416 | |
| 417 | void intel_disable_fbc(struct drm_device *dev) |
| 418 | { |
| 419 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 420 | |
| 421 | intel_cancel_fbc_work(dev_priv); |
| 422 | |
| 423 | if (!dev_priv->display.disable_fbc) |
| 424 | return; |
| 425 | |
| 426 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 427 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 428 | } |
| 429 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 430 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 431 | enum no_fbc_reason reason) |
| 432 | { |
| 433 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 434 | return false; |
| 435 | |
| 436 | dev_priv->fbc.no_fbc_reason = reason; |
| 437 | return true; |
| 438 | } |
| 439 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 440 | /** |
| 441 | * intel_update_fbc - enable/disable FBC as needed |
| 442 | * @dev: the drm_device |
| 443 | * |
| 444 | * Set up the framebuffer compression hardware at mode set time. We |
| 445 | * enable it if possible: |
| 446 | * - plane A only (on pre-965) |
| 447 | * - no pixel mulitply/line duplication |
| 448 | * - no alpha buffer discard |
| 449 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 450 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 451 | * |
| 452 | * We can't assume that any compression will take place (worst case), |
| 453 | * so the compressed buffer has to be the same size as the uncompressed |
| 454 | * one. It also must reside (along with the line length buffer) in |
| 455 | * stolen memory. |
| 456 | * |
| 457 | * We need to enable/disable FBC on a global basis. |
| 458 | */ |
| 459 | void intel_update_fbc(struct drm_device *dev) |
| 460 | { |
| 461 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 462 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 463 | struct intel_crtc *intel_crtc; |
| 464 | struct drm_framebuffer *fb; |
| 465 | struct intel_framebuffer *intel_fb; |
| 466 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 467 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 468 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 469 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 470 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 471 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 472 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 473 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 474 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 475 | if (!i915.powersave) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 476 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 477 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 478 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 479 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 480 | |
| 481 | /* |
| 482 | * If FBC is already on, we just have to verify that we can |
| 483 | * keep it that way... |
| 484 | * Need to disable if: |
| 485 | * - more than one pipe is active |
| 486 | * - changing FBC params (stride, fence, mode) |
| 487 | * - new fb is too large to fit in compressed buffer |
| 488 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 489 | */ |
| 490 | list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 491 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 492 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 493 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 494 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 495 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 496 | goto out_disable; |
| 497 | } |
| 498 | crtc = tmp_crtc; |
| 499 | } |
| 500 | } |
| 501 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 502 | if (!crtc || crtc->primary->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 503 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 504 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 505 | goto out_disable; |
| 506 | } |
| 507 | |
| 508 | intel_crtc = to_intel_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 509 | fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 510 | intel_fb = to_intel_framebuffer(fb); |
| 511 | obj = intel_fb->obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 512 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 513 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 514 | if (i915.enable_fbc < 0 && |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 515 | INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 516 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 517 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 518 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 519 | } |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 520 | if (!i915.enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 521 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 522 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 523 | goto out_disable; |
| 524 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 525 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 526 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 527 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 528 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 529 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 530 | goto out_disable; |
| 531 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 532 | |
| 533 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 534 | max_width = 4096; |
| 535 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 536 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 537 | max_width = 2048; |
| 538 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 539 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 540 | if (intel_crtc->config.pipe_src_w > max_width || |
| 541 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 542 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 543 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 544 | goto out_disable; |
| 545 | } |
Ben Widawsky | 8f94d24 | 2014-02-20 16:01:20 -0800 | [diff] [blame] | 546 | if ((INTEL_INFO(dev)->gen < 4 || HAS_DDI(dev)) && |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 547 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 548 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 549 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 550 | goto out_disable; |
| 551 | } |
| 552 | |
| 553 | /* The use of a CPU fence is mandatory in order to detect writes |
| 554 | * by the CPU to the scanout and trigger updates to the FBC. |
| 555 | */ |
| 556 | if (obj->tiling_mode != I915_TILING_X || |
| 557 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 558 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 559 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 560 | goto out_disable; |
| 561 | } |
| 562 | |
| 563 | /* If the kernel debugger is active, always disable compression */ |
| 564 | if (in_dbg_master()) |
| 565 | goto out_disable; |
| 566 | |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 567 | if (i915_gem_stolen_setup_compression(dev, intel_fb->obj->base.size)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 568 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 569 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 570 | goto out_disable; |
| 571 | } |
| 572 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 573 | /* If the scanout has not changed, don't modify the FBC settings. |
| 574 | * Note that we make the fundamental assumption that the fb->obj |
| 575 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 576 | * without first being decoupled from the scanout and FBC disabled. |
| 577 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 578 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 579 | dev_priv->fbc.fb_id == fb->base.id && |
| 580 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 581 | return; |
| 582 | |
| 583 | if (intel_fbc_enabled(dev)) { |
| 584 | /* We update FBC along two paths, after changing fb/crtc |
| 585 | * configuration (modeswitching) and after page-flipping |
| 586 | * finishes. For the latter, we know that not only did |
| 587 | * we disable the FBC at the start of the page-flip |
| 588 | * sequence, but also more than one vblank has passed. |
| 589 | * |
| 590 | * For the former case of modeswitching, it is possible |
| 591 | * to switch between two FBC valid configurations |
| 592 | * instantaneously so we do need to disable the FBC |
| 593 | * before we can modify its control registers. We also |
| 594 | * have to wait for the next vblank for that to take |
| 595 | * effect. However, since we delay enabling FBC we can |
| 596 | * assume that a vblank has passed since disabling and |
| 597 | * that we can safely alter the registers in the deferred |
| 598 | * callback. |
| 599 | * |
| 600 | * In the scenario that we go from a valid to invalid |
| 601 | * and then back to valid FBC configuration we have |
| 602 | * no strict enforcement that a vblank occurred since |
| 603 | * disabling the FBC. However, along all current pipe |
| 604 | * disabling paths we do need to wait for a vblank at |
| 605 | * some point. And we wait before enabling FBC anyway. |
| 606 | */ |
| 607 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 608 | intel_disable_fbc(dev); |
| 609 | } |
| 610 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 611 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 612 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 613 | return; |
| 614 | |
| 615 | out_disable: |
| 616 | /* Multiple disables should be harmless */ |
| 617 | if (intel_fbc_enabled(dev)) { |
| 618 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 619 | intel_disable_fbc(dev); |
| 620 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 621 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 622 | } |
| 623 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 624 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 625 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 626 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 627 | u32 tmp; |
| 628 | |
| 629 | tmp = I915_READ(CLKCFG); |
| 630 | |
| 631 | switch (tmp & CLKCFG_FSB_MASK) { |
| 632 | case CLKCFG_FSB_533: |
| 633 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 634 | break; |
| 635 | case CLKCFG_FSB_800: |
| 636 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 637 | break; |
| 638 | case CLKCFG_FSB_667: |
| 639 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 640 | break; |
| 641 | case CLKCFG_FSB_400: |
| 642 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | switch (tmp & CLKCFG_MEM_MASK) { |
| 647 | case CLKCFG_MEM_533: |
| 648 | dev_priv->mem_freq = 533; |
| 649 | break; |
| 650 | case CLKCFG_MEM_667: |
| 651 | dev_priv->mem_freq = 667; |
| 652 | break; |
| 653 | case CLKCFG_MEM_800: |
| 654 | dev_priv->mem_freq = 800; |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | /* detect pineview DDR3 setting */ |
| 659 | tmp = I915_READ(CSHRDDR3CTL); |
| 660 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 661 | } |
| 662 | |
| 663 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 664 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 665 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 666 | u16 ddrpll, csipll; |
| 667 | |
| 668 | ddrpll = I915_READ16(DDRMPLL1); |
| 669 | csipll = I915_READ16(CSIPLL0); |
| 670 | |
| 671 | switch (ddrpll & 0xff) { |
| 672 | case 0xc: |
| 673 | dev_priv->mem_freq = 800; |
| 674 | break; |
| 675 | case 0x10: |
| 676 | dev_priv->mem_freq = 1066; |
| 677 | break; |
| 678 | case 0x14: |
| 679 | dev_priv->mem_freq = 1333; |
| 680 | break; |
| 681 | case 0x18: |
| 682 | dev_priv->mem_freq = 1600; |
| 683 | break; |
| 684 | default: |
| 685 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 686 | ddrpll & 0xff); |
| 687 | dev_priv->mem_freq = 0; |
| 688 | break; |
| 689 | } |
| 690 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 691 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 692 | |
| 693 | switch (csipll & 0x3ff) { |
| 694 | case 0x00c: |
| 695 | dev_priv->fsb_freq = 3200; |
| 696 | break; |
| 697 | case 0x00e: |
| 698 | dev_priv->fsb_freq = 3733; |
| 699 | break; |
| 700 | case 0x010: |
| 701 | dev_priv->fsb_freq = 4266; |
| 702 | break; |
| 703 | case 0x012: |
| 704 | dev_priv->fsb_freq = 4800; |
| 705 | break; |
| 706 | case 0x014: |
| 707 | dev_priv->fsb_freq = 5333; |
| 708 | break; |
| 709 | case 0x016: |
| 710 | dev_priv->fsb_freq = 5866; |
| 711 | break; |
| 712 | case 0x018: |
| 713 | dev_priv->fsb_freq = 6400; |
| 714 | break; |
| 715 | default: |
| 716 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 717 | csipll & 0x3ff); |
| 718 | dev_priv->fsb_freq = 0; |
| 719 | break; |
| 720 | } |
| 721 | |
| 722 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 723 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 724 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 725 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 726 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 727 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 731 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 732 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 733 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 734 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 735 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 736 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 737 | |
| 738 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 739 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 740 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 741 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 742 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 743 | |
| 744 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 745 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 746 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 747 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 748 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 749 | |
| 750 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 751 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 752 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 753 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 754 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 755 | |
| 756 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 757 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 758 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 759 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 760 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 761 | |
| 762 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 763 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 764 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 765 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 766 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 767 | }; |
| 768 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 769 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 770 | int is_ddr3, |
| 771 | int fsb, |
| 772 | int mem) |
| 773 | { |
| 774 | const struct cxsr_latency *latency; |
| 775 | int i; |
| 776 | |
| 777 | if (fsb == 0 || mem == 0) |
| 778 | return NULL; |
| 779 | |
| 780 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 781 | latency = &cxsr_latency_table[i]; |
| 782 | if (is_desktop == latency->is_desktop && |
| 783 | is_ddr3 == latency->is_ddr3 && |
| 784 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 785 | return latency; |
| 786 | } |
| 787 | |
| 788 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 789 | |
| 790 | return NULL; |
| 791 | } |
| 792 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 793 | static void pineview_disable_cxsr(struct drm_device *dev) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 794 | { |
| 795 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 796 | |
| 797 | /* deactivate cxsr */ |
| 798 | I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN); |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * Latency for FIFO fetches is dependent on several factors: |
| 803 | * - memory configuration (speed, channels) |
| 804 | * - chipset |
| 805 | * - current MCH state |
| 806 | * It can be fairly high in some situations, so here we assume a fairly |
| 807 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 808 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 809 | * and power consumption (set it too low to save power and we might see |
| 810 | * FIFO underruns and display "flicker"). |
| 811 | * |
| 812 | * A value of 5us seems to be a good balance; safe for very low end |
| 813 | * platforms but not overly aggressive on lower latency configs. |
| 814 | */ |
| 815 | static const int latency_ns = 5000; |
| 816 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 817 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 818 | { |
| 819 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 820 | uint32_t dsparb = I915_READ(DSPARB); |
| 821 | int size; |
| 822 | |
| 823 | size = dsparb & 0x7f; |
| 824 | if (plane) |
| 825 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 826 | |
| 827 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 828 | plane ? "B" : "A", size); |
| 829 | |
| 830 | return size; |
| 831 | } |
| 832 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 833 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 834 | { |
| 835 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 836 | uint32_t dsparb = I915_READ(DSPARB); |
| 837 | int size; |
| 838 | |
| 839 | size = dsparb & 0x1ff; |
| 840 | if (plane) |
| 841 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 842 | size >>= 1; /* Convert to cachelines */ |
| 843 | |
| 844 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 845 | plane ? "B" : "A", size); |
| 846 | |
| 847 | return size; |
| 848 | } |
| 849 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 850 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 851 | { |
| 852 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 853 | uint32_t dsparb = I915_READ(DSPARB); |
| 854 | int size; |
| 855 | |
| 856 | size = dsparb & 0x7f; |
| 857 | size >>= 2; /* Convert to cachelines */ |
| 858 | |
| 859 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 860 | plane ? "B" : "A", |
| 861 | size); |
| 862 | |
| 863 | return size; |
| 864 | } |
| 865 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 866 | /* Pineview has different values for various configs */ |
| 867 | static const struct intel_watermark_params pineview_display_wm = { |
| 868 | PINEVIEW_DISPLAY_FIFO, |
| 869 | PINEVIEW_MAX_WM, |
| 870 | PINEVIEW_DFT_WM, |
| 871 | PINEVIEW_GUARD_WM, |
| 872 | PINEVIEW_FIFO_LINE_SIZE |
| 873 | }; |
| 874 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
| 875 | PINEVIEW_DISPLAY_FIFO, |
| 876 | PINEVIEW_MAX_WM, |
| 877 | PINEVIEW_DFT_HPLLOFF_WM, |
| 878 | PINEVIEW_GUARD_WM, |
| 879 | PINEVIEW_FIFO_LINE_SIZE |
| 880 | }; |
| 881 | static const struct intel_watermark_params pineview_cursor_wm = { |
| 882 | PINEVIEW_CURSOR_FIFO, |
| 883 | PINEVIEW_CURSOR_MAX_WM, |
| 884 | PINEVIEW_CURSOR_DFT_WM, |
| 885 | PINEVIEW_CURSOR_GUARD_WM, |
| 886 | PINEVIEW_FIFO_LINE_SIZE, |
| 887 | }; |
| 888 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
| 889 | PINEVIEW_CURSOR_FIFO, |
| 890 | PINEVIEW_CURSOR_MAX_WM, |
| 891 | PINEVIEW_CURSOR_DFT_WM, |
| 892 | PINEVIEW_CURSOR_GUARD_WM, |
| 893 | PINEVIEW_FIFO_LINE_SIZE |
| 894 | }; |
| 895 | static const struct intel_watermark_params g4x_wm_info = { |
| 896 | G4X_FIFO_SIZE, |
| 897 | G4X_MAX_WM, |
| 898 | G4X_MAX_WM, |
| 899 | 2, |
| 900 | G4X_FIFO_LINE_SIZE, |
| 901 | }; |
| 902 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
| 903 | I965_CURSOR_FIFO, |
| 904 | I965_CURSOR_MAX_WM, |
| 905 | I965_CURSOR_DFT_WM, |
| 906 | 2, |
| 907 | G4X_FIFO_LINE_SIZE, |
| 908 | }; |
| 909 | static const struct intel_watermark_params valleyview_wm_info = { |
| 910 | VALLEYVIEW_FIFO_SIZE, |
| 911 | VALLEYVIEW_MAX_WM, |
| 912 | VALLEYVIEW_MAX_WM, |
| 913 | 2, |
| 914 | G4X_FIFO_LINE_SIZE, |
| 915 | }; |
| 916 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
| 917 | I965_CURSOR_FIFO, |
| 918 | VALLEYVIEW_CURSOR_MAX_WM, |
| 919 | I965_CURSOR_DFT_WM, |
| 920 | 2, |
| 921 | G4X_FIFO_LINE_SIZE, |
| 922 | }; |
| 923 | static const struct intel_watermark_params i965_cursor_wm_info = { |
| 924 | I965_CURSOR_FIFO, |
| 925 | I965_CURSOR_MAX_WM, |
| 926 | I965_CURSOR_DFT_WM, |
| 927 | 2, |
| 928 | I915_FIFO_LINE_SIZE, |
| 929 | }; |
| 930 | static const struct intel_watermark_params i945_wm_info = { |
| 931 | I945_FIFO_SIZE, |
| 932 | I915_MAX_WM, |
| 933 | 1, |
| 934 | 2, |
| 935 | I915_FIFO_LINE_SIZE |
| 936 | }; |
| 937 | static const struct intel_watermark_params i915_wm_info = { |
| 938 | I915_FIFO_SIZE, |
| 939 | I915_MAX_WM, |
| 940 | 1, |
| 941 | 2, |
| 942 | I915_FIFO_LINE_SIZE |
| 943 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 944 | static const struct intel_watermark_params i830_wm_info = { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 945 | I855GM_FIFO_SIZE, |
| 946 | I915_MAX_WM, |
| 947 | 1, |
| 948 | 2, |
| 949 | I830_FIFO_LINE_SIZE |
| 950 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 951 | static const struct intel_watermark_params i845_wm_info = { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 952 | I830_FIFO_SIZE, |
| 953 | I915_MAX_WM, |
| 954 | 1, |
| 955 | 2, |
| 956 | I830_FIFO_LINE_SIZE |
| 957 | }; |
| 958 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 959 | /** |
| 960 | * intel_calculate_wm - calculate watermark level |
| 961 | * @clock_in_khz: pixel clock |
| 962 | * @wm: chip FIFO params |
| 963 | * @pixel_size: display pixel size |
| 964 | * @latency_ns: memory latency for the platform |
| 965 | * |
| 966 | * Calculate the watermark level (the level at which the display plane will |
| 967 | * start fetching from memory again). Each chip has a different display |
| 968 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 969 | * in the correct intel_watermark_params structure. |
| 970 | * |
| 971 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 972 | * on the pixel size. When it reaches the watermark level, it'll start |
| 973 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 974 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 975 | * will occur, and a display engine hang could result. |
| 976 | */ |
| 977 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 978 | const struct intel_watermark_params *wm, |
| 979 | int fifo_size, |
| 980 | int pixel_size, |
| 981 | unsigned long latency_ns) |
| 982 | { |
| 983 | long entries_required, wm_size; |
| 984 | |
| 985 | /* |
| 986 | * Note: we need to make sure we don't overflow for various clock & |
| 987 | * latency values. |
| 988 | * clocks go from a few thousand to several hundred thousand. |
| 989 | * latency is usually a few thousand |
| 990 | */ |
| 991 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 992 | 1000; |
| 993 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 994 | |
| 995 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 996 | |
| 997 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 998 | |
| 999 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 1000 | |
| 1001 | /* Don't promote wm_size to unsigned... */ |
| 1002 | if (wm_size > (long)wm->max_wm) |
| 1003 | wm_size = wm->max_wm; |
| 1004 | if (wm_size <= 0) |
| 1005 | wm_size = wm->default_wm; |
| 1006 | return wm_size; |
| 1007 | } |
| 1008 | |
| 1009 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 1010 | { |
| 1011 | struct drm_crtc *crtc, *enabled = NULL; |
| 1012 | |
| 1013 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1014 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1015 | if (enabled) |
| 1016 | return NULL; |
| 1017 | enabled = crtc; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | return enabled; |
| 1022 | } |
| 1023 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1024 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1025 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1026 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1027 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1028 | struct drm_crtc *crtc; |
| 1029 | const struct cxsr_latency *latency; |
| 1030 | u32 reg; |
| 1031 | unsigned long wm; |
| 1032 | |
| 1033 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1034 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1035 | if (!latency) { |
| 1036 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 1037 | pineview_disable_cxsr(dev); |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | crtc = single_enabled_crtc(dev); |
| 1042 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1043 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1044 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1045 | int clock; |
| 1046 | |
| 1047 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1048 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1049 | |
| 1050 | /* Display SR */ |
| 1051 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1052 | pineview_display_wm.fifo_size, |
| 1053 | pixel_size, latency->display_sr); |
| 1054 | reg = I915_READ(DSPFW1); |
| 1055 | reg &= ~DSPFW_SR_MASK; |
| 1056 | reg |= wm << DSPFW_SR_SHIFT; |
| 1057 | I915_WRITE(DSPFW1, reg); |
| 1058 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1059 | |
| 1060 | /* cursor SR */ |
| 1061 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1062 | pineview_display_wm.fifo_size, |
| 1063 | pixel_size, latency->cursor_sr); |
| 1064 | reg = I915_READ(DSPFW3); |
| 1065 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1066 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1067 | I915_WRITE(DSPFW3, reg); |
| 1068 | |
| 1069 | /* Display HPLL off SR */ |
| 1070 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1071 | pineview_display_hplloff_wm.fifo_size, |
| 1072 | pixel_size, latency->display_hpll_disable); |
| 1073 | reg = I915_READ(DSPFW3); |
| 1074 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1075 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1076 | I915_WRITE(DSPFW3, reg); |
| 1077 | |
| 1078 | /* cursor HPLL off SR */ |
| 1079 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1080 | pineview_display_hplloff_wm.fifo_size, |
| 1081 | pixel_size, latency->cursor_hpll_disable); |
| 1082 | reg = I915_READ(DSPFW3); |
| 1083 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1084 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1085 | I915_WRITE(DSPFW3, reg); |
| 1086 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1087 | |
| 1088 | /* activate cxsr */ |
| 1089 | I915_WRITE(DSPFW3, |
| 1090 | I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN); |
| 1091 | DRM_DEBUG_KMS("Self-refresh is enabled\n"); |
| 1092 | } else { |
| 1093 | pineview_disable_cxsr(dev); |
| 1094 | DRM_DEBUG_KMS("Self-refresh is disabled\n"); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1099 | int plane, |
| 1100 | const struct intel_watermark_params *display, |
| 1101 | int display_latency_ns, |
| 1102 | const struct intel_watermark_params *cursor, |
| 1103 | int cursor_latency_ns, |
| 1104 | int *plane_wm, |
| 1105 | int *cursor_wm) |
| 1106 | { |
| 1107 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1108 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1109 | int htotal, hdisplay, clock, pixel_size; |
| 1110 | int line_time_us, line_count; |
| 1111 | int entries, tlb_miss; |
| 1112 | |
| 1113 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1114 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1115 | *cursor_wm = cursor->guard_size; |
| 1116 | *plane_wm = display->guard_size; |
| 1117 | return false; |
| 1118 | } |
| 1119 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1120 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1121 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1122 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1123 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1124 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1125 | |
| 1126 | /* Use the small buffer method to calculate plane watermark */ |
| 1127 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1128 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1129 | if (tlb_miss > 0) |
| 1130 | entries += tlb_miss; |
| 1131 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1132 | *plane_wm = entries + display->guard_size; |
| 1133 | if (*plane_wm > (int)display->max_wm) |
| 1134 | *plane_wm = display->max_wm; |
| 1135 | |
| 1136 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1137 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1138 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1139 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1140 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1141 | if (tlb_miss > 0) |
| 1142 | entries += tlb_miss; |
| 1143 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1144 | *cursor_wm = entries + cursor->guard_size; |
| 1145 | if (*cursor_wm > (int)cursor->max_wm) |
| 1146 | *cursor_wm = (int)cursor->max_wm; |
| 1147 | |
| 1148 | return true; |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Check the wm result. |
| 1153 | * |
| 1154 | * If any calculated watermark values is larger than the maximum value that |
| 1155 | * can be programmed into the associated watermark register, that watermark |
| 1156 | * must be disabled. |
| 1157 | */ |
| 1158 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1159 | int display_wm, int cursor_wm, |
| 1160 | const struct intel_watermark_params *display, |
| 1161 | const struct intel_watermark_params *cursor) |
| 1162 | { |
| 1163 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1164 | display_wm, cursor_wm); |
| 1165 | |
| 1166 | if (display_wm > display->max_wm) { |
| 1167 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1168 | display_wm, display->max_wm); |
| 1169 | return false; |
| 1170 | } |
| 1171 | |
| 1172 | if (cursor_wm > cursor->max_wm) { |
| 1173 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1174 | cursor_wm, cursor->max_wm); |
| 1175 | return false; |
| 1176 | } |
| 1177 | |
| 1178 | if (!(display_wm || cursor_wm)) { |
| 1179 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1180 | return false; |
| 1181 | } |
| 1182 | |
| 1183 | return true; |
| 1184 | } |
| 1185 | |
| 1186 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1187 | int plane, |
| 1188 | int latency_ns, |
| 1189 | const struct intel_watermark_params *display, |
| 1190 | const struct intel_watermark_params *cursor, |
| 1191 | int *display_wm, int *cursor_wm) |
| 1192 | { |
| 1193 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1194 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1195 | int hdisplay, htotal, pixel_size, clock; |
| 1196 | unsigned long line_time_us; |
| 1197 | int line_count, line_size; |
| 1198 | int small, large; |
| 1199 | int entries; |
| 1200 | |
| 1201 | if (!latency_ns) { |
| 1202 | *display_wm = *cursor_wm = 0; |
| 1203 | return false; |
| 1204 | } |
| 1205 | |
| 1206 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1207 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1208 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1209 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1210 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1211 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1212 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1213 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1214 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1215 | line_size = hdisplay * pixel_size; |
| 1216 | |
| 1217 | /* Use the minimum of the small and large buffer method for primary */ |
| 1218 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1219 | large = line_count * line_size; |
| 1220 | |
| 1221 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1222 | *display_wm = entries + display->guard_size; |
| 1223 | |
| 1224 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1225 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1226 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1227 | *cursor_wm = entries + cursor->guard_size; |
| 1228 | |
| 1229 | return g4x_check_srwm(dev, |
| 1230 | *display_wm, *cursor_wm, |
| 1231 | display, cursor); |
| 1232 | } |
| 1233 | |
| 1234 | static bool vlv_compute_drain_latency(struct drm_device *dev, |
| 1235 | int plane, |
| 1236 | int *plane_prec_mult, |
| 1237 | int *plane_dl, |
| 1238 | int *cursor_prec_mult, |
| 1239 | int *cursor_dl) |
| 1240 | { |
| 1241 | struct drm_crtc *crtc; |
| 1242 | int clock, pixel_size; |
| 1243 | int entries; |
| 1244 | |
| 1245 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1246 | if (!intel_crtc_active(crtc)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1247 | return false; |
| 1248 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1249 | clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1250 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1251 | |
| 1252 | entries = (clock / 1000) * pixel_size; |
| 1253 | *plane_prec_mult = (entries > 256) ? |
| 1254 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1255 | *plane_dl = (64 * (*plane_prec_mult) * 4) / ((clock / 1000) * |
| 1256 | pixel_size); |
| 1257 | |
| 1258 | entries = (clock / 1000) * 4; /* BPP is always 4 for cursor */ |
| 1259 | *cursor_prec_mult = (entries > 256) ? |
| 1260 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1261 | *cursor_dl = (64 * (*cursor_prec_mult) * 4) / ((clock / 1000) * 4); |
| 1262 | |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * Update drain latency registers of memory arbiter |
| 1268 | * |
| 1269 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1270 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1271 | * latency value. |
| 1272 | */ |
| 1273 | |
| 1274 | static void vlv_update_drain_latency(struct drm_device *dev) |
| 1275 | { |
| 1276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1277 | int planea_prec, planea_dl, planeb_prec, planeb_dl; |
| 1278 | int cursora_prec, cursora_dl, cursorb_prec, cursorb_dl; |
| 1279 | int plane_prec_mult, cursor_prec_mult; /* Precision multiplier is |
| 1280 | either 16 or 32 */ |
| 1281 | |
| 1282 | /* For plane A, Cursor A */ |
| 1283 | if (vlv_compute_drain_latency(dev, 0, &plane_prec_mult, &planea_dl, |
| 1284 | &cursor_prec_mult, &cursora_dl)) { |
| 1285 | cursora_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1286 | DDL_CURSORA_PRECISION_32 : DDL_CURSORA_PRECISION_16; |
| 1287 | planea_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1288 | DDL_PLANEA_PRECISION_32 : DDL_PLANEA_PRECISION_16; |
| 1289 | |
| 1290 | I915_WRITE(VLV_DDL1, cursora_prec | |
| 1291 | (cursora_dl << DDL_CURSORA_SHIFT) | |
| 1292 | planea_prec | planea_dl); |
| 1293 | } |
| 1294 | |
| 1295 | /* For plane B, Cursor B */ |
| 1296 | if (vlv_compute_drain_latency(dev, 1, &plane_prec_mult, &planeb_dl, |
| 1297 | &cursor_prec_mult, &cursorb_dl)) { |
| 1298 | cursorb_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1299 | DDL_CURSORB_PRECISION_32 : DDL_CURSORB_PRECISION_16; |
| 1300 | planeb_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1301 | DDL_PLANEB_PRECISION_32 : DDL_PLANEB_PRECISION_16; |
| 1302 | |
| 1303 | I915_WRITE(VLV_DDL2, cursorb_prec | |
| 1304 | (cursorb_dl << DDL_CURSORB_SHIFT) | |
| 1305 | planeb_prec | planeb_dl); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1310 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1311 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1312 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1313 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1314 | static const int sr_latency_ns = 12000; |
| 1315 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1316 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1317 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1318 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1319 | unsigned int enabled = 0; |
| 1320 | |
| 1321 | vlv_update_drain_latency(dev); |
| 1322 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1323 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1324 | &valleyview_wm_info, latency_ns, |
| 1325 | &valleyview_cursor_wm_info, latency_ns, |
| 1326 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1327 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1328 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1329 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1330 | &valleyview_wm_info, latency_ns, |
| 1331 | &valleyview_cursor_wm_info, latency_ns, |
| 1332 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1333 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1334 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1335 | if (single_plane_enabled(enabled) && |
| 1336 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1337 | sr_latency_ns, |
| 1338 | &valleyview_wm_info, |
| 1339 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1340 | &plane_sr, &ignore_cursor_sr) && |
| 1341 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1342 | 2*sr_latency_ns, |
| 1343 | &valleyview_wm_info, |
| 1344 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1345 | &ignore_plane_sr, &cursor_sr)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1346 | I915_WRITE(FW_BLC_SELF_VLV, FW_CSPWRDWNEN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1347 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1348 | I915_WRITE(FW_BLC_SELF_VLV, |
| 1349 | I915_READ(FW_BLC_SELF_VLV) & ~FW_CSPWRDWNEN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1350 | plane_sr = cursor_sr = 0; |
| 1351 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1352 | |
| 1353 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1354 | planea_wm, cursora_wm, |
| 1355 | planeb_wm, cursorb_wm, |
| 1356 | plane_sr, cursor_sr); |
| 1357 | |
| 1358 | I915_WRITE(DSPFW1, |
| 1359 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1360 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1361 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1362 | planea_wm); |
| 1363 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1364 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1365 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1366 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1367 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1368 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1369 | } |
| 1370 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1371 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1372 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1373 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1374 | static const int sr_latency_ns = 12000; |
| 1375 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1376 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1377 | int plane_sr, cursor_sr; |
| 1378 | unsigned int enabled = 0; |
| 1379 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1380 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1381 | &g4x_wm_info, latency_ns, |
| 1382 | &g4x_cursor_wm_info, latency_ns, |
| 1383 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1384 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1385 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1386 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1387 | &g4x_wm_info, latency_ns, |
| 1388 | &g4x_cursor_wm_info, latency_ns, |
| 1389 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1390 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1391 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1392 | if (single_plane_enabled(enabled) && |
| 1393 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1394 | sr_latency_ns, |
| 1395 | &g4x_wm_info, |
| 1396 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1397 | &plane_sr, &cursor_sr)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1398 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1399 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1400 | I915_WRITE(FW_BLC_SELF, |
| 1401 | I915_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1402 | plane_sr = cursor_sr = 0; |
| 1403 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1404 | |
| 1405 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1406 | planea_wm, cursora_wm, |
| 1407 | planeb_wm, cursorb_wm, |
| 1408 | plane_sr, cursor_sr); |
| 1409 | |
| 1410 | I915_WRITE(DSPFW1, |
| 1411 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1412 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1413 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1414 | planea_wm); |
| 1415 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1416 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1417 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1418 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1419 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1420 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1421 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1422 | } |
| 1423 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1424 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1425 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1426 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1427 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1428 | struct drm_crtc *crtc; |
| 1429 | int srwm = 1; |
| 1430 | int cursor_sr = 16; |
| 1431 | |
| 1432 | /* Calc sr entries for one plane configs */ |
| 1433 | crtc = single_enabled_crtc(dev); |
| 1434 | if (crtc) { |
| 1435 | /* self-refresh has much higher latency */ |
| 1436 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1437 | const struct drm_display_mode *adjusted_mode = |
| 1438 | &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1439 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1440 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1441 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1442 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1443 | unsigned long line_time_us; |
| 1444 | int entries; |
| 1445 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1446 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1447 | |
| 1448 | /* Use ns/us then divide to preserve precision */ |
| 1449 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1450 | pixel_size * hdisplay; |
| 1451 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1452 | srwm = I965_FIFO_SIZE - entries; |
| 1453 | if (srwm < 0) |
| 1454 | srwm = 1; |
| 1455 | srwm &= 0x1ff; |
| 1456 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1457 | entries, srwm); |
| 1458 | |
| 1459 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1460 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1461 | entries = DIV_ROUND_UP(entries, |
| 1462 | i965_cursor_wm_info.cacheline_size); |
| 1463 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1464 | (entries + i965_cursor_wm_info.guard_size); |
| 1465 | |
| 1466 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1467 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1468 | |
| 1469 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1470 | "cursor %d\n", srwm, cursor_sr); |
| 1471 | |
| 1472 | if (IS_CRESTLINE(dev)) |
| 1473 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
| 1474 | } else { |
| 1475 | /* Turn off self refresh if both pipes are enabled */ |
| 1476 | if (IS_CRESTLINE(dev)) |
| 1477 | I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) |
| 1478 | & ~FW_BLC_SELF_EN); |
| 1479 | } |
| 1480 | |
| 1481 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1482 | srwm); |
| 1483 | |
| 1484 | /* 965 has limitations... */ |
| 1485 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
| 1486 | (8 << 16) | (8 << 8) | (8 << 0)); |
| 1487 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); |
| 1488 | /* update cursor SR watermark */ |
| 1489 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1490 | } |
| 1491 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1492 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1493 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1494 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1495 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1496 | const struct intel_watermark_params *wm_info; |
| 1497 | uint32_t fwater_lo; |
| 1498 | uint32_t fwater_hi; |
| 1499 | int cwm, srwm = 1; |
| 1500 | int fifo_size; |
| 1501 | int planea_wm, planeb_wm; |
| 1502 | struct drm_crtc *crtc, *enabled = NULL; |
| 1503 | |
| 1504 | if (IS_I945GM(dev)) |
| 1505 | wm_info = &i945_wm_info; |
| 1506 | else if (!IS_GEN2(dev)) |
| 1507 | wm_info = &i915_wm_info; |
| 1508 | else |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1509 | wm_info = &i830_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1510 | |
| 1511 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1512 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1513 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1514 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1515 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1516 | if (IS_GEN2(dev)) |
| 1517 | cpp = 4; |
| 1518 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1519 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1520 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1521 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1522 | latency_ns); |
| 1523 | enabled = crtc; |
| 1524 | } else |
| 1525 | planea_wm = fifo_size - wm_info->guard_size; |
| 1526 | |
| 1527 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1528 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1529 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1530 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1531 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1532 | if (IS_GEN2(dev)) |
| 1533 | cpp = 4; |
| 1534 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1535 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1536 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1537 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1538 | latency_ns); |
| 1539 | if (enabled == NULL) |
| 1540 | enabled = crtc; |
| 1541 | else |
| 1542 | enabled = NULL; |
| 1543 | } else |
| 1544 | planeb_wm = fifo_size - wm_info->guard_size; |
| 1545 | |
| 1546 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1547 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1548 | if (IS_I915GM(dev) && enabled) { |
| 1549 | struct intel_framebuffer *fb; |
| 1550 | |
| 1551 | fb = to_intel_framebuffer(enabled->primary->fb); |
| 1552 | |
| 1553 | /* self-refresh seems busted with untiled */ |
| 1554 | if (fb->obj->tiling_mode == I915_TILING_NONE) |
| 1555 | enabled = NULL; |
| 1556 | } |
| 1557 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1558 | /* |
| 1559 | * Overlay gets an aggressive default since video jitter is bad. |
| 1560 | */ |
| 1561 | cwm = 2; |
| 1562 | |
| 1563 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
| 1564 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1565 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | 0); |
| 1566 | else if (IS_I915GM(dev)) |
Ville Syrjälä | 3f2dc5a | 2014-01-10 14:06:47 +0200 | [diff] [blame] | 1567 | I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_SELF_EN)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1568 | |
| 1569 | /* Calc sr entries for one plane configs */ |
| 1570 | if (HAS_FW_BLC(dev) && enabled) { |
| 1571 | /* self-refresh has much higher latency */ |
| 1572 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1573 | const struct drm_display_mode *adjusted_mode = |
| 1574 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1575 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1576 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1577 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1578 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1579 | unsigned long line_time_us; |
| 1580 | int entries; |
| 1581 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1582 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1583 | |
| 1584 | /* Use ns/us then divide to preserve precision */ |
| 1585 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1586 | pixel_size * hdisplay; |
| 1587 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1588 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1589 | srwm = wm_info->fifo_size - entries; |
| 1590 | if (srwm < 0) |
| 1591 | srwm = 1; |
| 1592 | |
| 1593 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1594 | I915_WRITE(FW_BLC_SELF, |
| 1595 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1596 | else if (IS_I915GM(dev)) |
| 1597 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1598 | } |
| 1599 | |
| 1600 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1601 | planea_wm, planeb_wm, cwm, srwm); |
| 1602 | |
| 1603 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1604 | fwater_hi = (cwm & 0x1f); |
| 1605 | |
| 1606 | /* Set request length to 8 cachelines per fetch */ |
| 1607 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1608 | fwater_hi = fwater_hi | (1 << 8); |
| 1609 | |
| 1610 | I915_WRITE(FW_BLC, fwater_lo); |
| 1611 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1612 | |
| 1613 | if (HAS_FW_BLC(dev)) { |
| 1614 | if (enabled) { |
| 1615 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1616 | I915_WRITE(FW_BLC_SELF, |
| 1617 | FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN); |
| 1618 | else if (IS_I915GM(dev)) |
Ville Syrjälä | 3f2dc5a | 2014-01-10 14:06:47 +0200 | [diff] [blame] | 1619 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_SELF_EN)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1620 | DRM_DEBUG_KMS("memory self refresh enabled\n"); |
| 1621 | } else |
| 1622 | DRM_DEBUG_KMS("memory self refresh disabled\n"); |
| 1623 | } |
| 1624 | } |
| 1625 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1626 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1627 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1628 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1629 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1630 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1631 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1632 | uint32_t fwater_lo; |
| 1633 | int planea_wm; |
| 1634 | |
| 1635 | crtc = single_enabled_crtc(dev); |
| 1636 | if (crtc == NULL) |
| 1637 | return; |
| 1638 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1639 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1640 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1641 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1642 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1643 | 4, latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1644 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1645 | fwater_lo |= (3<<8) | planea_wm; |
| 1646 | |
| 1647 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1648 | |
| 1649 | I915_WRITE(FW_BLC, fwater_lo); |
| 1650 | } |
| 1651 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1652 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1653 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1654 | { |
| 1655 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1656 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1657 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1658 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1659 | |
| 1660 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1661 | * adjust the pixel_rate here. */ |
| 1662 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1663 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1664 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1665 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1666 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1667 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1668 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1669 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1670 | pfit_h = pfit_size & 0xFFFF; |
| 1671 | if (pipe_w < pfit_w) |
| 1672 | pipe_w = pfit_w; |
| 1673 | if (pipe_h < pfit_h) |
| 1674 | pipe_h = pfit_h; |
| 1675 | |
| 1676 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1677 | pfit_w * pfit_h); |
| 1678 | } |
| 1679 | |
| 1680 | return pixel_rate; |
| 1681 | } |
| 1682 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1683 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1684 | static uint32_t ilk_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1685 | uint32_t latency) |
| 1686 | { |
| 1687 | uint64_t ret; |
| 1688 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1689 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1690 | return UINT_MAX; |
| 1691 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1692 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1693 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1694 | |
| 1695 | return ret; |
| 1696 | } |
| 1697 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1698 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1699 | static uint32_t ilk_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1700 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1701 | uint32_t latency) |
| 1702 | { |
| 1703 | uint32_t ret; |
| 1704 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1705 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1706 | return UINT_MAX; |
| 1707 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1708 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1709 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1710 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1711 | return ret; |
| 1712 | } |
| 1713 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1714 | static uint32_t ilk_wm_fbc(uint32_t pri_val, uint32_t horiz_pixels, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1715 | uint8_t bytes_per_pixel) |
| 1716 | { |
| 1717 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1718 | } |
| 1719 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1720 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1721 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1722 | uint32_t pipe_htotal; |
| 1723 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1724 | struct intel_plane_wm_parameters pri; |
| 1725 | struct intel_plane_wm_parameters spr; |
| 1726 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1727 | }; |
| 1728 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1729 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1730 | uint16_t pri; |
| 1731 | uint16_t spr; |
| 1732 | uint16_t cur; |
| 1733 | uint16_t fbc; |
| 1734 | }; |
| 1735 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1736 | /* used in computing the new watermarks state */ |
| 1737 | struct intel_wm_config { |
| 1738 | unsigned int num_pipes_active; |
| 1739 | bool sprites_enabled; |
| 1740 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1741 | }; |
| 1742 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1743 | /* |
| 1744 | * For both WM_PIPE and WM_LP. |
| 1745 | * mem_value must be in 0.1us units. |
| 1746 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1747 | static uint32_t ilk_compute_pri_wm(const struct ilk_pipe_wm_parameters *params, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1748 | uint32_t mem_value, |
| 1749 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1750 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1751 | uint32_t method1, method2; |
| 1752 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1753 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1754 | return 0; |
| 1755 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1756 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1757 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1758 | mem_value); |
| 1759 | |
| 1760 | if (!is_lp) |
| 1761 | return method1; |
| 1762 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1763 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1764 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1765 | params->pri.horiz_pixels, |
| 1766 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1767 | mem_value); |
| 1768 | |
| 1769 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1770 | } |
| 1771 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1772 | /* |
| 1773 | * For both WM_PIPE and WM_LP. |
| 1774 | * mem_value must be in 0.1us units. |
| 1775 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1776 | static uint32_t ilk_compute_spr_wm(const struct ilk_pipe_wm_parameters *params, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1777 | uint32_t mem_value) |
| 1778 | { |
| 1779 | uint32_t method1, method2; |
| 1780 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1781 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1782 | return 0; |
| 1783 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1784 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1785 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1786 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1787 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1788 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1789 | params->spr.horiz_pixels, |
| 1790 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1791 | mem_value); |
| 1792 | return min(method1, method2); |
| 1793 | } |
| 1794 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1795 | /* |
| 1796 | * For both WM_PIPE and WM_LP. |
| 1797 | * mem_value must be in 0.1us units. |
| 1798 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1799 | static uint32_t ilk_compute_cur_wm(const struct ilk_pipe_wm_parameters *params, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1800 | uint32_t mem_value) |
| 1801 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1802 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1803 | return 0; |
| 1804 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1805 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1806 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1807 | params->cur.horiz_pixels, |
| 1808 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1809 | mem_value); |
| 1810 | } |
| 1811 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1812 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1813 | static uint32_t ilk_compute_fbc_wm(const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 1fda988 | 2013-07-05 11:57:19 +0300 | [diff] [blame] | 1814 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1815 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1816 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1817 | return 0; |
| 1818 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1819 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1820 | params->pri.horiz_pixels, |
| 1821 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1822 | } |
| 1823 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1824 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1825 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1826 | if (INTEL_INFO(dev)->gen >= 8) |
| 1827 | return 3072; |
| 1828 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1829 | return 768; |
| 1830 | else |
| 1831 | return 512; |
| 1832 | } |
| 1833 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1834 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1835 | int level, bool is_sprite) |
| 1836 | { |
| 1837 | if (INTEL_INFO(dev)->gen >= 8) |
| 1838 | /* BDW primary/sprite plane watermarks */ |
| 1839 | return level == 0 ? 255 : 2047; |
| 1840 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1841 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1842 | return level == 0 ? 127 : 1023; |
| 1843 | else if (!is_sprite) |
| 1844 | /* ILK/SNB primary plane watermarks */ |
| 1845 | return level == 0 ? 127 : 511; |
| 1846 | else |
| 1847 | /* ILK/SNB sprite plane watermarks */ |
| 1848 | return level == 0 ? 63 : 255; |
| 1849 | } |
| 1850 | |
| 1851 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1852 | int level) |
| 1853 | { |
| 1854 | if (INTEL_INFO(dev)->gen >= 7) |
| 1855 | return level == 0 ? 63 : 255; |
| 1856 | else |
| 1857 | return level == 0 ? 31 : 63; |
| 1858 | } |
| 1859 | |
| 1860 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1861 | { |
| 1862 | if (INTEL_INFO(dev)->gen >= 8) |
| 1863 | return 31; |
| 1864 | else |
| 1865 | return 15; |
| 1866 | } |
| 1867 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1868 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1869 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1870 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1871 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1872 | enum intel_ddb_partitioning ddb_partitioning, |
| 1873 | bool is_sprite) |
| 1874 | { |
| 1875 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1876 | |
| 1877 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1878 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1879 | return 0; |
| 1880 | |
| 1881 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1882 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1883 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1884 | |
| 1885 | /* |
| 1886 | * For some reason the non self refresh |
| 1887 | * FIFO size is only half of the self |
| 1888 | * refresh FIFO size on ILK/SNB. |
| 1889 | */ |
| 1890 | if (INTEL_INFO(dev)->gen <= 6) |
| 1891 | fifo_size /= 2; |
| 1892 | } |
| 1893 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1894 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1895 | /* level 0 is always calculated with 1:1 split */ |
| 1896 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1897 | if (is_sprite) |
| 1898 | fifo_size *= 5; |
| 1899 | fifo_size /= 6; |
| 1900 | } else { |
| 1901 | fifo_size /= 2; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1906 | return min(fifo_size, ilk_plane_wm_reg_max(dev, level, is_sprite)); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | /* Calculate the maximum cursor plane watermark */ |
| 1910 | static unsigned int ilk_cursor_wm_max(const struct drm_device *dev, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1911 | int level, |
| 1912 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1913 | { |
| 1914 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1915 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1916 | return 64; |
| 1917 | |
| 1918 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1919 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1920 | } |
| 1921 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1922 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1923 | int level, |
| 1924 | const struct intel_wm_config *config, |
| 1925 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1926 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1927 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1928 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1929 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1930 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1931 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1932 | } |
| 1933 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1934 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1935 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1936 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1937 | { |
| 1938 | bool ret; |
| 1939 | |
| 1940 | /* already determined to be invalid? */ |
| 1941 | if (!result->enable) |
| 1942 | return false; |
| 1943 | |
| 1944 | result->enable = result->pri_val <= max->pri && |
| 1945 | result->spr_val <= max->spr && |
| 1946 | result->cur_val <= max->cur; |
| 1947 | |
| 1948 | ret = result->enable; |
| 1949 | |
| 1950 | /* |
| 1951 | * HACK until we can pre-compute everything, |
| 1952 | * and thus fail gracefully if LP0 watermarks |
| 1953 | * are exceeded... |
| 1954 | */ |
| 1955 | if (level == 0 && !result->enable) { |
| 1956 | if (result->pri_val > max->pri) |
| 1957 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1958 | level, result->pri_val, max->pri); |
| 1959 | if (result->spr_val > max->spr) |
| 1960 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1961 | level, result->spr_val, max->spr); |
| 1962 | if (result->cur_val > max->cur) |
| 1963 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1964 | level, result->cur_val, max->cur); |
| 1965 | |
| 1966 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1967 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1968 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1969 | result->enable = true; |
| 1970 | } |
| 1971 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1972 | return ret; |
| 1973 | } |
| 1974 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1975 | static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1976 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1977 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1978 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1979 | { |
| 1980 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1981 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1982 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1983 | |
| 1984 | /* WM1+ latency values stored in 0.5us units */ |
| 1985 | if (level > 0) { |
| 1986 | pri_latency *= 5; |
| 1987 | spr_latency *= 5; |
| 1988 | cur_latency *= 5; |
| 1989 | } |
| 1990 | |
| 1991 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1992 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1993 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1994 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1995 | result->enable = true; |
| 1996 | } |
| 1997 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1998 | static uint32_t |
| 1999 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2000 | { |
| 2001 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2002 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2003 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2004 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2005 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2006 | if (!intel_crtc_active(crtc)) |
| 2007 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2008 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2009 | /* The WM are computed with base on how long it takes to fill a single |
| 2010 | * row at the given clock rate, multiplied by 8. |
| 2011 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2012 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 2013 | mode->crtc_clock); |
| 2014 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2015 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2016 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2017 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2018 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2019 | } |
| 2020 | |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2021 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2022 | { |
| 2023 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2024 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2025 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2026 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2027 | |
| 2028 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2029 | if (wm[0] == 0) |
| 2030 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2031 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2032 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2033 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2034 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2035 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2036 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2037 | |
| 2038 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2039 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2040 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2041 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2042 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2043 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2044 | |
| 2045 | /* ILK primary LP0 latency is 700 ns */ |
| 2046 | wm[0] = 7; |
| 2047 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2048 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2052 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2053 | { |
| 2054 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2055 | if (INTEL_INFO(dev)->gen == 5) |
| 2056 | wm[0] = 13; |
| 2057 | } |
| 2058 | |
| 2059 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2060 | { |
| 2061 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2062 | if (INTEL_INFO(dev)->gen == 5) |
| 2063 | wm[0] = 13; |
| 2064 | |
| 2065 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2066 | if (IS_IVYBRIDGE(dev)) |
| 2067 | wm[3] *= 2; |
| 2068 | } |
| 2069 | |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2070 | static int ilk_wm_max_level(const struct drm_device *dev) |
| 2071 | { |
| 2072 | /* how many WM levels are we expecting */ |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2073 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2074 | return 4; |
| 2075 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2076 | return 3; |
| 2077 | else |
| 2078 | return 2; |
| 2079 | } |
| 2080 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2081 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2082 | const char *name, |
| 2083 | const uint16_t wm[5]) |
| 2084 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2085 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2086 | |
| 2087 | for (level = 0; level <= max_level; level++) { |
| 2088 | unsigned int latency = wm[level]; |
| 2089 | |
| 2090 | if (latency == 0) { |
| 2091 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2092 | name, level); |
| 2093 | continue; |
| 2094 | } |
| 2095 | |
| 2096 | /* WM1+ latency values in 0.5us units */ |
| 2097 | if (level > 0) |
| 2098 | latency *= 5; |
| 2099 | |
| 2100 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2101 | name, level, wm[level], |
| 2102 | latency / 10, latency % 10); |
| 2103 | } |
| 2104 | } |
| 2105 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2106 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2107 | { |
| 2108 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2109 | |
| 2110 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2111 | |
| 2112 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2113 | sizeof(dev_priv->wm.pri_latency)); |
| 2114 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2115 | sizeof(dev_priv->wm.pri_latency)); |
| 2116 | |
| 2117 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2118 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2119 | |
| 2120 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2121 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2122 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2123 | } |
| 2124 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2125 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2126 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2127 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2128 | struct drm_device *dev = crtc->dev; |
| 2129 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2130 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2131 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2132 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2133 | if (!intel_crtc_active(crtc)) |
| 2134 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2135 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2136 | p->active = true; |
| 2137 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 2138 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 2139 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 2140 | p->cur.bytes_per_pixel = 4; |
| 2141 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
| 2142 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 2143 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2144 | p->pri.enabled = true; |
| 2145 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2146 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2147 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2148 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2149 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2150 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2151 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2152 | break; |
| 2153 | } |
| 2154 | } |
| 2155 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2156 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2157 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2158 | struct intel_wm_config *config) |
| 2159 | { |
| 2160 | struct intel_crtc *intel_crtc; |
| 2161 | |
| 2162 | /* Compute the currently _active_ config */ |
| 2163 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head) { |
| 2164 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2165 | |
| 2166 | if (!wm->pipe_enabled) |
| 2167 | continue; |
| 2168 | |
| 2169 | config->sprites_enabled |= wm->sprites_enabled; |
| 2170 | config->sprites_scaled |= wm->sprites_scaled; |
| 2171 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2172 | } |
| 2173 | } |
| 2174 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2175 | /* Compute new watermarks for the pipe */ |
| 2176 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2177 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2178 | struct intel_pipe_wm *pipe_wm) |
| 2179 | { |
| 2180 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2181 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2182 | int level, max_level = ilk_wm_max_level(dev); |
| 2183 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2184 | struct intel_wm_config config = { |
| 2185 | .num_pipes_active = 1, |
| 2186 | .sprites_enabled = params->spr.enabled, |
| 2187 | .sprites_scaled = params->spr.scaled, |
| 2188 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2189 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2190 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2191 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2192 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2193 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2194 | pipe_wm->pipe_enabled = params->active; |
| 2195 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2196 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2197 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2198 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2199 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2200 | max_level = 1; |
| 2201 | |
| 2202 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2203 | if (params->spr.scaled) |
| 2204 | max_level = 0; |
| 2205 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2206 | for (level = 0; level <= max_level; level++) |
| 2207 | ilk_compute_wm_level(dev_priv, level, params, |
| 2208 | &pipe_wm->wm[level]); |
| 2209 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2210 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2211 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2212 | |
| 2213 | /* At least LP0 must be valid */ |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2214 | return ilk_validate_wm_level(0, &max, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | /* |
| 2218 | * Merge the watermarks from all active pipes for a specific level. |
| 2219 | */ |
| 2220 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2221 | int level, |
| 2222 | struct intel_wm_level *ret_wm) |
| 2223 | { |
| 2224 | const struct intel_crtc *intel_crtc; |
| 2225 | |
| 2226 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2227 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2228 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2229 | |
| 2230 | if (!active->pipe_enabled) |
| 2231 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2232 | |
| 2233 | if (!wm->enable) |
| 2234 | return; |
| 2235 | |
| 2236 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2237 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2238 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2239 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2240 | } |
| 2241 | |
| 2242 | ret_wm->enable = true; |
| 2243 | } |
| 2244 | |
| 2245 | /* |
| 2246 | * Merge all low power watermarks for all active pipes. |
| 2247 | */ |
| 2248 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2249 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2250 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2251 | struct intel_pipe_wm *merged) |
| 2252 | { |
| 2253 | int level, max_level = ilk_wm_max_level(dev); |
| 2254 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2255 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2256 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2257 | config->num_pipes_active > 1) |
| 2258 | return; |
| 2259 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2260 | /* ILK: FBC WM must be disabled always */ |
| 2261 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2262 | |
| 2263 | /* merge each WM1+ level */ |
| 2264 | for (level = 1; level <= max_level; level++) { |
| 2265 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2266 | |
| 2267 | ilk_merge_wm_level(dev, level, wm); |
| 2268 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2269 | if (!ilk_validate_wm_level(level, max, wm)) |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2270 | break; |
| 2271 | |
| 2272 | /* |
| 2273 | * The spec says it is preferred to disable |
| 2274 | * FBC WMs instead of disabling a WM level. |
| 2275 | */ |
| 2276 | if (wm->fbc_val > max->fbc) { |
| 2277 | merged->fbc_wm_enabled = false; |
| 2278 | wm->fbc_val = 0; |
| 2279 | } |
| 2280 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2281 | |
| 2282 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2283 | /* |
| 2284 | * FIXME this is racy. FBC might get enabled later. |
| 2285 | * What we should check here is whether FBC can be |
| 2286 | * enabled sometime later. |
| 2287 | */ |
| 2288 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2289 | for (level = 2; level <= max_level; level++) { |
| 2290 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2291 | |
| 2292 | wm->enable = false; |
| 2293 | } |
| 2294 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2295 | } |
| 2296 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2297 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2298 | { |
| 2299 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2300 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2301 | } |
| 2302 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2303 | /* The value we need to program into the WM_LPx latency field */ |
| 2304 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2305 | { |
| 2306 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2307 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2308 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2309 | return 2 * level; |
| 2310 | else |
| 2311 | return dev_priv->wm.pri_latency[level]; |
| 2312 | } |
| 2313 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2314 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2315 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2316 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2317 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2318 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2319 | struct intel_crtc *intel_crtc; |
| 2320 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2321 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2322 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2323 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2324 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2325 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2326 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2327 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2328 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2329 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2330 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2331 | r = &merged->wm[level]; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2332 | if (!r->enable) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2333 | break; |
| 2334 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2335 | results->wm_lp[wm_lp - 1] = WM3_LP_EN | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2336 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2337 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2338 | r->cur_val; |
| 2339 | |
| 2340 | if (INTEL_INFO(dev)->gen >= 8) |
| 2341 | results->wm_lp[wm_lp - 1] |= |
| 2342 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2343 | else |
| 2344 | results->wm_lp[wm_lp - 1] |= |
| 2345 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2346 | |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2347 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2348 | WARN_ON(wm_lp != 1); |
| 2349 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2350 | } else |
| 2351 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2352 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2353 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2354 | /* LP0 register values */ |
| 2355 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head) { |
| 2356 | enum pipe pipe = intel_crtc->pipe; |
| 2357 | const struct intel_wm_level *r = |
| 2358 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2359 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2360 | if (WARN_ON(!r->enable)) |
| 2361 | continue; |
| 2362 | |
| 2363 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2364 | |
| 2365 | results->wm_pipe[pipe] = |
| 2366 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2367 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2368 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2369 | } |
| 2370 | } |
| 2371 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2372 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2373 | * case both are at the same level. Prefer r1 in case they're the same. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2374 | static struct intel_pipe_wm *ilk_find_best_result(struct drm_device *dev, |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2375 | struct intel_pipe_wm *r1, |
| 2376 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2377 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2378 | int level, max_level = ilk_wm_max_level(dev); |
| 2379 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2380 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2381 | for (level = 1; level <= max_level; level++) { |
| 2382 | if (r1->wm[level].enable) |
| 2383 | level1 = level; |
| 2384 | if (r2->wm[level].enable) |
| 2385 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2386 | } |
| 2387 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2388 | if (level1 == level2) { |
| 2389 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2390 | return r2; |
| 2391 | else |
| 2392 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2393 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2394 | return r1; |
| 2395 | } else { |
| 2396 | return r2; |
| 2397 | } |
| 2398 | } |
| 2399 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2400 | /* dirty bits used to track which watermarks need changes */ |
| 2401 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2402 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2403 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2404 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2405 | #define WM_DIRTY_FBC (1 << 24) |
| 2406 | #define WM_DIRTY_DDB (1 << 25) |
| 2407 | |
| 2408 | static unsigned int ilk_compute_wm_dirty(struct drm_device *dev, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2409 | const struct ilk_wm_values *old, |
| 2410 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2411 | { |
| 2412 | unsigned int dirty = 0; |
| 2413 | enum pipe pipe; |
| 2414 | int wm_lp; |
| 2415 | |
| 2416 | for_each_pipe(pipe) { |
| 2417 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2418 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2419 | /* Must disable LP1+ watermarks too */ |
| 2420 | dirty |= WM_DIRTY_LP_ALL; |
| 2421 | } |
| 2422 | |
| 2423 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2424 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2425 | /* Must disable LP1+ watermarks too */ |
| 2426 | dirty |= WM_DIRTY_LP_ALL; |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2431 | dirty |= WM_DIRTY_FBC; |
| 2432 | /* Must disable LP1+ watermarks too */ |
| 2433 | dirty |= WM_DIRTY_LP_ALL; |
| 2434 | } |
| 2435 | |
| 2436 | if (old->partitioning != new->partitioning) { |
| 2437 | dirty |= WM_DIRTY_DDB; |
| 2438 | /* Must disable LP1+ watermarks too */ |
| 2439 | dirty |= WM_DIRTY_LP_ALL; |
| 2440 | } |
| 2441 | |
| 2442 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2443 | if (dirty & WM_DIRTY_LP_ALL) |
| 2444 | return dirty; |
| 2445 | |
| 2446 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2447 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2448 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2449 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2450 | break; |
| 2451 | } |
| 2452 | |
| 2453 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2454 | for (; wm_lp <= 3; wm_lp++) |
| 2455 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2456 | |
| 2457 | return dirty; |
| 2458 | } |
| 2459 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2460 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2461 | unsigned int dirty) |
| 2462 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2463 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2464 | bool changed = false; |
| 2465 | |
| 2466 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2467 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2468 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2469 | changed = true; |
| 2470 | } |
| 2471 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2472 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2473 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2474 | changed = true; |
| 2475 | } |
| 2476 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2477 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2478 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2479 | changed = true; |
| 2480 | } |
| 2481 | |
| 2482 | /* |
| 2483 | * Don't touch WM1S_LP_EN here. |
| 2484 | * Doing so could cause underruns. |
| 2485 | */ |
| 2486 | |
| 2487 | return changed; |
| 2488 | } |
| 2489 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2490 | /* |
| 2491 | * The spec says we shouldn't write when we don't need, because every write |
| 2492 | * causes WMs to be re-evaluated, expending some power. |
| 2493 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2494 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2495 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2496 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2497 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2498 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2499 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2500 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2501 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2502 | dirty = ilk_compute_wm_dirty(dev, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2503 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2504 | return; |
| 2505 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2506 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2507 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2508 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2509 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2510 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2511 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2512 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2513 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2514 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2515 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2516 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2517 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2518 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2519 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2520 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2521 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2522 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2523 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2524 | val = I915_READ(WM_MISC); |
| 2525 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2526 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2527 | else |
| 2528 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2529 | I915_WRITE(WM_MISC, val); |
| 2530 | } else { |
| 2531 | val = I915_READ(DISP_ARB_CTL2); |
| 2532 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2533 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2534 | else |
| 2535 | val |= DISP_DATA_PARTITION_5_6; |
| 2536 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2537 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2538 | } |
| 2539 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2540 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2541 | val = I915_READ(DISP_ARB_CTL); |
| 2542 | if (results->enable_fbc_wm) |
| 2543 | val &= ~DISP_FBC_WM_DIS; |
| 2544 | else |
| 2545 | val |= DISP_FBC_WM_DIS; |
| 2546 | I915_WRITE(DISP_ARB_CTL, val); |
| 2547 | } |
| 2548 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2549 | if (dirty & WM_DIRTY_LP(1) && |
| 2550 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2551 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2552 | |
| 2553 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2554 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2555 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2556 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2557 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2558 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2559 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2560 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0]) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2561 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2562 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1]) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2563 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2564 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2]) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2565 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2566 | |
| 2567 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2568 | } |
| 2569 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2570 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2571 | { |
| 2572 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2573 | |
| 2574 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2575 | } |
| 2576 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2577 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2578 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2579 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2580 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2581 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2582 | struct ilk_wm_maximums max; |
| 2583 | struct ilk_pipe_wm_parameters params = {}; |
| 2584 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2585 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2586 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2587 | struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm; |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2588 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2589 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2590 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2591 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2592 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 2593 | |
| 2594 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 2595 | return; |
| 2596 | |
| 2597 | intel_crtc->wm.active = pipe_wm; |
| 2598 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2599 | ilk_compute_wm_config(dev, &config); |
| 2600 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2601 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max); |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2602 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2603 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2604 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 2605 | if (INTEL_INFO(dev)->gen >= 7 && |
| 2606 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2607 | ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max); |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2608 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2609 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2610 | best_lp_wm = ilk_find_best_result(dev, &lp_wm_1_2, &lp_wm_5_6); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2611 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2612 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2613 | } |
| 2614 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2615 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2616 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2617 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2618 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2619 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2620 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2621 | } |
| 2622 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2623 | static void ilk_update_sprite_wm(struct drm_plane *plane, |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2624 | struct drm_crtc *crtc, |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2625 | uint32_t sprite_width, int pixel_size, |
Ville Syrjälä | bdd57d0 | 2013-07-05 11:57:13 +0300 | [diff] [blame] | 2626 | bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2627 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2628 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2629 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2630 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2631 | intel_plane->wm.enabled = enabled; |
| 2632 | intel_plane->wm.scaled = scaled; |
| 2633 | intel_plane->wm.horiz_pixels = sprite_width; |
| 2634 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2635 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2636 | /* |
| 2637 | * IVB workaround: must disable low power watermarks for at least |
| 2638 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 2639 | * when scaling is disabled. |
| 2640 | * |
| 2641 | * WaCxSRDisabledForSpriteScaling:ivb |
| 2642 | */ |
| 2643 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 2644 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 2645 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2646 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2647 | } |
| 2648 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2649 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 2650 | { |
| 2651 | struct drm_device *dev = crtc->dev; |
| 2652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2653 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2654 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2655 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2656 | enum pipe pipe = intel_crtc->pipe; |
| 2657 | static const unsigned int wm0_pipe_reg[] = { |
| 2658 | [PIPE_A] = WM0_PIPEA_ILK, |
| 2659 | [PIPE_B] = WM0_PIPEB_ILK, |
| 2660 | [PIPE_C] = WM0_PIPEC_IVB, |
| 2661 | }; |
| 2662 | |
| 2663 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2664 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2665 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2666 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2667 | active->pipe_enabled = intel_crtc_active(crtc); |
| 2668 | |
| 2669 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2670 | u32 tmp = hw->wm_pipe[pipe]; |
| 2671 | |
| 2672 | /* |
| 2673 | * For active pipes LP0 watermark is marked as |
| 2674 | * enabled, and LP1+ watermaks as disabled since |
| 2675 | * we can't really reverse compute them in case |
| 2676 | * multiple pipes are active. |
| 2677 | */ |
| 2678 | active->wm[0].enable = true; |
| 2679 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 2680 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 2681 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 2682 | active->linetime = hw->wm_linetime[pipe]; |
| 2683 | } else { |
| 2684 | int level, max_level = ilk_wm_max_level(dev); |
| 2685 | |
| 2686 | /* |
| 2687 | * For inactive pipes, all watermark levels |
| 2688 | * should be marked as enabled but zeroed, |
| 2689 | * which is what we'd compute them to. |
| 2690 | */ |
| 2691 | for (level = 0; level <= max_level; level++) |
| 2692 | active->wm[level].enable = true; |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 2697 | { |
| 2698 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2699 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2700 | struct drm_crtc *crtc; |
| 2701 | |
| 2702 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 2703 | ilk_pipe_wm_get_hw_state(crtc); |
| 2704 | |
| 2705 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 2706 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 2707 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 2708 | |
| 2709 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 2710 | if (INTEL_INFO(dev)->gen >= 7) { |
| 2711 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 2712 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 2713 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2714 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2715 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2716 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 2717 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 2718 | else if (IS_IVYBRIDGE(dev)) |
| 2719 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 2720 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2721 | |
| 2722 | hw->enable_fbc_wm = |
| 2723 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 2724 | } |
| 2725 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2726 | /** |
| 2727 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 2728 | * |
| 2729 | * Calculate watermark values for the various WM regs based on current mode |
| 2730 | * and plane configuration. |
| 2731 | * |
| 2732 | * There are several cases to deal with here: |
| 2733 | * - normal (i.e. non-self-refresh) |
| 2734 | * - self-refresh (SR) mode |
| 2735 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 2736 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 2737 | * lines), so need to account for TLB latency |
| 2738 | * |
| 2739 | * The normal calculation is: |
| 2740 | * watermark = dotclock * bytes per pixel * latency |
| 2741 | * where latency is platform & configuration dependent (we assume pessimal |
| 2742 | * values here). |
| 2743 | * |
| 2744 | * The SR calculation is: |
| 2745 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 2746 | * bytes per pixel |
| 2747 | * where |
| 2748 | * line time = htotal / dotclock |
| 2749 | * surface width = hdisplay for normal plane and 64 for cursor |
| 2750 | * and latency is assumed to be high, as above. |
| 2751 | * |
| 2752 | * The final value programmed to the register should always be rounded up, |
| 2753 | * and include an extra 2 entries to account for clock crossings. |
| 2754 | * |
| 2755 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 2756 | * to set the non-SR watermarks to 8. |
| 2757 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2758 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2759 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2760 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2761 | |
| 2762 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2763 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2764 | } |
| 2765 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2766 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 2767 | struct drm_crtc *crtc, |
Paulo Zanoni | 4c4ff43 | 2013-05-24 11:59:17 -0300 | [diff] [blame] | 2768 | uint32_t sprite_width, int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2769 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2770 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2771 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2772 | |
| 2773 | if (dev_priv->display.update_sprite_wm) |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2774 | dev_priv->display.update_sprite_wm(plane, crtc, sprite_width, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2775 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2776 | } |
| 2777 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2778 | static struct drm_i915_gem_object * |
| 2779 | intel_alloc_context_page(struct drm_device *dev) |
| 2780 | { |
| 2781 | struct drm_i915_gem_object *ctx; |
| 2782 | int ret; |
| 2783 | |
| 2784 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2785 | |
| 2786 | ctx = i915_gem_alloc_object(dev, 4096); |
| 2787 | if (!ctx) { |
| 2788 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 2789 | return NULL; |
| 2790 | } |
| 2791 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 2792 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2793 | if (ret) { |
| 2794 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 2795 | goto err_unref; |
| 2796 | } |
| 2797 | |
| 2798 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 2799 | if (ret) { |
| 2800 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 2801 | goto err_unpin; |
| 2802 | } |
| 2803 | |
| 2804 | return ctx; |
| 2805 | |
| 2806 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 2807 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2808 | err_unref: |
| 2809 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2810 | return NULL; |
| 2811 | } |
| 2812 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2813 | /** |
| 2814 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2815 | */ |
| 2816 | DEFINE_SPINLOCK(mchdev_lock); |
| 2817 | |
| 2818 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 2819 | * mchdev_lock. */ |
| 2820 | static struct drm_i915_private *i915_mch_dev; |
| 2821 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2822 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 2823 | { |
| 2824 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2825 | u16 rgvswctl; |
| 2826 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2827 | assert_spin_locked(&mchdev_lock); |
| 2828 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2829 | rgvswctl = I915_READ16(MEMSWCTL); |
| 2830 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 2831 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 2832 | return false; /* still busy with another command */ |
| 2833 | } |
| 2834 | |
| 2835 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 2836 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 2837 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2838 | POSTING_READ16(MEMSWCTL); |
| 2839 | |
| 2840 | rgvswctl |= MEMCTL_CMD_STS; |
| 2841 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2842 | |
| 2843 | return true; |
| 2844 | } |
| 2845 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 2846 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2847 | { |
| 2848 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2849 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 2850 | u8 fmax, fmin, fstart, vstart; |
| 2851 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2852 | spin_lock_irq(&mchdev_lock); |
| 2853 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2854 | /* Enable temp reporting */ |
| 2855 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 2856 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 2857 | |
| 2858 | /* 100ms RC evaluation intervals */ |
| 2859 | I915_WRITE(RCUPEI, 100000); |
| 2860 | I915_WRITE(RCDNEI, 100000); |
| 2861 | |
| 2862 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 2863 | I915_WRITE(RCBMAXAVG, 90000); |
| 2864 | I915_WRITE(RCBMINAVG, 80000); |
| 2865 | |
| 2866 | I915_WRITE(MEMIHYST, 1); |
| 2867 | |
| 2868 | /* Set up min, max, and cur for interrupt handling */ |
| 2869 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 2870 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 2871 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 2872 | MEMMODE_FSTART_SHIFT; |
| 2873 | |
| 2874 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 2875 | PXVFREQ_PX_SHIFT; |
| 2876 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2877 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 2878 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2879 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2880 | dev_priv->ips.max_delay = fstart; |
| 2881 | dev_priv->ips.min_delay = fmin; |
| 2882 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2883 | |
| 2884 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 2885 | fmax, fmin, fstart); |
| 2886 | |
| 2887 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 2888 | |
| 2889 | /* |
| 2890 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 2891 | */ |
| 2892 | |
| 2893 | I915_WRITE(VIDSTART, vstart); |
| 2894 | POSTING_READ(VIDSTART); |
| 2895 | |
| 2896 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 2897 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 2898 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2899 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2900 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2901 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2902 | |
| 2903 | ironlake_set_drps(dev, fstart); |
| 2904 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2905 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2906 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2907 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 2908 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
| 2909 | getrawmonotonic(&dev_priv->ips.last_time2); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2910 | |
| 2911 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2912 | } |
| 2913 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 2914 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2915 | { |
| 2916 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2917 | u16 rgvswctl; |
| 2918 | |
| 2919 | spin_lock_irq(&mchdev_lock); |
| 2920 | |
| 2921 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2922 | |
| 2923 | /* Ack interrupts, disable EFC interrupt */ |
| 2924 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 2925 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 2926 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 2927 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 2928 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 2929 | |
| 2930 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2931 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2932 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2933 | rgvswctl |= MEMCTL_CMD_STS; |
| 2934 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2935 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2936 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2937 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2938 | } |
| 2939 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 2940 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 2941 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 2942 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 2943 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 2944 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 2945 | static u32 gen6_rps_limits(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2946 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 2947 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2948 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 2949 | /* Only set the down limit when we've reached the lowest level to avoid |
| 2950 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 2951 | * race in the hw when coming out of rc6: There's a tiny window where |
| 2952 | * the hw runs at the minimal clock before selecting the desired |
| 2953 | * frequency, if the down threshold expires in that window we will not |
| 2954 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2955 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 2956 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 2957 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 2958 | |
| 2959 | return limits; |
| 2960 | } |
| 2961 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2962 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 2963 | { |
| 2964 | int new_power; |
| 2965 | |
| 2966 | new_power = dev_priv->rps.power; |
| 2967 | switch (dev_priv->rps.power) { |
| 2968 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2969 | if (val > dev_priv->rps.efficient_freq + 1 && val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2970 | new_power = BETWEEN; |
| 2971 | break; |
| 2972 | |
| 2973 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2974 | if (val <= dev_priv->rps.efficient_freq && val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2975 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2976 | else if (val >= dev_priv->rps.rp0_freq && val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2977 | new_power = HIGH_POWER; |
| 2978 | break; |
| 2979 | |
| 2980 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2981 | if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 && val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2982 | new_power = BETWEEN; |
| 2983 | break; |
| 2984 | } |
| 2985 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2986 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2987 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 2988 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2989 | new_power = HIGH_POWER; |
| 2990 | if (new_power == dev_priv->rps.power) |
| 2991 | return; |
| 2992 | |
| 2993 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 2994 | switch (new_power) { |
| 2995 | case LOW_POWER: |
| 2996 | /* Upclock if more than 95% busy over 16ms */ |
| 2997 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 2998 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 2999 | |
| 3000 | /* Downclock if less than 85% busy over 32ms */ |
| 3001 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3002 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3003 | |
| 3004 | I915_WRITE(GEN6_RP_CONTROL, |
| 3005 | GEN6_RP_MEDIA_TURBO | |
| 3006 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3007 | GEN6_RP_MEDIA_IS_GFX | |
| 3008 | GEN6_RP_ENABLE | |
| 3009 | GEN6_RP_UP_BUSY_AVG | |
| 3010 | GEN6_RP_DOWN_IDLE_AVG); |
| 3011 | break; |
| 3012 | |
| 3013 | case BETWEEN: |
| 3014 | /* Upclock if more than 90% busy over 13ms */ |
| 3015 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3016 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3017 | |
| 3018 | /* Downclock if less than 75% busy over 32ms */ |
| 3019 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3020 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3021 | |
| 3022 | I915_WRITE(GEN6_RP_CONTROL, |
| 3023 | GEN6_RP_MEDIA_TURBO | |
| 3024 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3025 | GEN6_RP_MEDIA_IS_GFX | |
| 3026 | GEN6_RP_ENABLE | |
| 3027 | GEN6_RP_UP_BUSY_AVG | |
| 3028 | GEN6_RP_DOWN_IDLE_AVG); |
| 3029 | break; |
| 3030 | |
| 3031 | case HIGH_POWER: |
| 3032 | /* Upclock if more than 85% busy over 10ms */ |
| 3033 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3034 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3035 | |
| 3036 | /* Downclock if less than 60% busy over 32ms */ |
| 3037 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3038 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3039 | |
| 3040 | I915_WRITE(GEN6_RP_CONTROL, |
| 3041 | GEN6_RP_MEDIA_TURBO | |
| 3042 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3043 | GEN6_RP_MEDIA_IS_GFX | |
| 3044 | GEN6_RP_ENABLE | |
| 3045 | GEN6_RP_UP_BUSY_AVG | |
| 3046 | GEN6_RP_DOWN_IDLE_AVG); |
| 3047 | break; |
| 3048 | } |
| 3049 | |
| 3050 | dev_priv->rps.power = new_power; |
| 3051 | dev_priv->rps.last_adj = 0; |
| 3052 | } |
| 3053 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3054 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3055 | { |
| 3056 | u32 mask = 0; |
| 3057 | |
| 3058 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3059 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3060 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3061 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3062 | |
| 3063 | /* IVB and SNB hard hangs on looping batchbuffer |
| 3064 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 3065 | */ |
| 3066 | if (INTEL_INFO(dev_priv->dev)->gen <= 7 && !IS_HASWELL(dev_priv->dev)) |
| 3067 | mask |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 3068 | |
| 3069 | return ~mask; |
| 3070 | } |
| 3071 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3072 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3073 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3074 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3075 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 3076 | { |
| 3077 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3078 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3079 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3080 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3081 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3082 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3083 | /* min/max delay may still have been modified so be sure to |
| 3084 | * write the limits value. |
| 3085 | */ |
| 3086 | if (val != dev_priv->rps.cur_freq) { |
| 3087 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3088 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3089 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3090 | I915_WRITE(GEN6_RPNSWREQ, |
| 3091 | HSW_FREQUENCY(val)); |
| 3092 | else |
| 3093 | I915_WRITE(GEN6_RPNSWREQ, |
| 3094 | GEN6_FREQUENCY(val) | |
| 3095 | GEN6_OFFSET(0) | |
| 3096 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3097 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3098 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3099 | /* Make sure we continue to get interrupts |
| 3100 | * until we hit the minimum or maximum frequencies. |
| 3101 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3102 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3103 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3104 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3105 | POSTING_READ(GEN6_RPNSWREQ); |
| 3106 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3107 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3108 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3109 | } |
| 3110 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3111 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3112 | * |
| 3113 | * * If Gfx is Idle, then |
| 3114 | * 1. Mask Turbo interrupts |
| 3115 | * 2. Bring up Gfx clock |
| 3116 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3117 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3118 | * 5. Unmask Turbo interrupts |
| 3119 | */ |
| 3120 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3121 | { |
| 3122 | /* |
| 3123 | * When we are idle. Drop to min voltage state. |
| 3124 | */ |
| 3125 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3126 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3127 | return; |
| 3128 | |
| 3129 | /* Mask turbo interrupt so that they will not come in between */ |
| 3130 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 3131 | |
| 3132 | /* Bring up the Gfx clock */ |
| 3133 | I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, |
| 3134 | I915_READ(VLV_GTLC_SURVIVABILITY_REG) | |
| 3135 | VLV_GFX_CLK_FORCE_ON_BIT); |
| 3136 | |
| 3137 | if (wait_for(((VLV_GFX_CLK_STATUS_BIT & |
| 3138 | I915_READ(VLV_GTLC_SURVIVABILITY_REG)) != 0), 5)) { |
| 3139 | DRM_ERROR("GFX_CLK_ON request timed out\n"); |
| 3140 | return; |
| 3141 | } |
| 3142 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3143 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3144 | |
| 3145 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3146 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3147 | |
| 3148 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
| 3149 | & GENFREQSTATUS) == 0, 5)) |
| 3150 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3151 | |
| 3152 | /* Release the Gfx clock */ |
| 3153 | I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, |
| 3154 | I915_READ(VLV_GTLC_SURVIVABILITY_REG) & |
| 3155 | ~VLV_GFX_CLK_FORCE_ON_BIT); |
| 3156 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3157 | I915_WRITE(GEN6_PMINTRMSK, |
| 3158 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3159 | } |
| 3160 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3161 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3162 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3163 | struct drm_device *dev = dev_priv->dev; |
| 3164 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3165 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3166 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3167 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3168 | vlv_set_rps_idle(dev_priv); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3169 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3170 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3171 | dev_priv->rps.last_adj = 0; |
| 3172 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3173 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3174 | } |
| 3175 | |
| 3176 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3177 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3178 | struct drm_device *dev = dev_priv->dev; |
| 3179 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3180 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3181 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3182 | if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3183 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3184 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3185 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3186 | dev_priv->rps.last_adj = 0; |
| 3187 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3188 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3189 | } |
| 3190 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3191 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3192 | { |
| 3193 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 3194 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3195 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3196 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3197 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3198 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3199 | DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3200 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 3201 | dev_priv->rps.cur_freq, |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3202 | vlv_gpu_freq(dev_priv, val), val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3203 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3204 | if (val != dev_priv->rps.cur_freq) |
| 3205 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3206 | |
Imre Deak | 09c87db | 2014-04-03 20:02:42 +0300 | [diff] [blame] | 3207 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3208 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3209 | dev_priv->rps.cur_freq = val; |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3210 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3213 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3214 | { |
| 3215 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3216 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3217 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3218 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & |
| 3219 | ~dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3220 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3221 | * item again unmasking PM interrupts because that is using a different |
| 3222 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 3223 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 3224 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3225 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3226 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3227 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3228 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3229 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3230 | } |
| 3231 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3232 | static void gen6_disable_rps(struct drm_device *dev) |
| 3233 | { |
| 3234 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3235 | |
| 3236 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3237 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 3238 | |
| 3239 | gen6_disable_rps_interrupts(dev); |
| 3240 | } |
| 3241 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3242 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3243 | { |
| 3244 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3245 | |
| 3246 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3247 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3248 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3251 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3252 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3253 | if (IS_VALLEYVIEW(dev)) { |
| 3254 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3255 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3256 | else |
| 3257 | mode = 0; |
| 3258 | } |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3259 | DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n", |
Ben Widawsky | 1c79b42 | 2014-01-28 20:25:40 -0800 | [diff] [blame] | 3260 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3261 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3262 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3265 | static int sanitize_rc6_option(const struct drm_device *dev, int enable_rc6) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3266 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3267 | /* No RC6 before Ironlake */ |
| 3268 | if (INTEL_INFO(dev)->gen < 5) |
| 3269 | return 0; |
| 3270 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3271 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3272 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3273 | return 0; |
| 3274 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3275 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3276 | if (enable_rc6 >= 0) { |
| 3277 | int mask; |
| 3278 | |
| 3279 | if (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev)) |
| 3280 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3281 | INTEL_RC6pp_ENABLE; |
| 3282 | else |
| 3283 | mask = INTEL_RC6_ENABLE; |
| 3284 | |
| 3285 | if ((enable_rc6 & mask) != enable_rc6) |
| 3286 | DRM_INFO("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 3287 | enable_rc6, enable_rc6 & mask, mask); |
| 3288 | |
| 3289 | return enable_rc6 & mask; |
| 3290 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3291 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3292 | /* Disable RC6 on Ironlake */ |
| 3293 | if (INTEL_INFO(dev)->gen == 5) |
| 3294 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3295 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3296 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 3297 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3298 | |
| 3299 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3300 | } |
| 3301 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3302 | int intel_enable_rc6(const struct drm_device *dev) |
| 3303 | { |
| 3304 | return i915.enable_rc6; |
| 3305 | } |
| 3306 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3307 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 3308 | { |
| 3309 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3310 | |
| 3311 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 3312 | WARN_ON(dev_priv->rps.pm_iir); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3313 | snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
| 3314 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3315 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3316 | } |
| 3317 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3318 | static void parse_rp_state_cap(struct drm_i915_private *dev_priv, u32 rp_state_cap) |
| 3319 | { |
| 3320 | /* All of these values are in units of 50MHz */ |
| 3321 | dev_priv->rps.cur_freq = 0; |
| 3322 | /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */ |
| 3323 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 3324 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 3325 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 3326 | /* XXX: only BYT has a special efficient freq */ |
| 3327 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 3328 | /* hw_max = RP0 until we check for overclocking */ |
| 3329 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 3330 | |
| 3331 | /* Preserve min/max settings in case of re-init */ |
| 3332 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3333 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3334 | |
| 3335 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 3336 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 3337 | } |
| 3338 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3339 | static void gen8_enable_rps(struct drm_device *dev) |
| 3340 | { |
| 3341 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3342 | struct intel_ring_buffer *ring; |
| 3343 | uint32_t rc6_mask = 0, rp_state_cap; |
| 3344 | int unused; |
| 3345 | |
| 3346 | /* 1a: Software RC state - RC0 */ |
| 3347 | I915_WRITE(GEN6_RC_STATE, 0); |
| 3348 | |
| 3349 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 3350 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3351 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3352 | |
| 3353 | /* 2a: Disable RC states. */ |
| 3354 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3355 | |
| 3356 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3357 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3358 | |
| 3359 | /* 2b: Program RC6 thresholds.*/ |
| 3360 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 3361 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 3362 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 3363 | for_each_ring(ring, dev_priv, unused) |
| 3364 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3365 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3366 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 3367 | |
| 3368 | /* 3: Enable RC6 */ |
| 3369 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 3370 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 3371 | intel_print_rc6_info(dev, rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3372 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 3373 | GEN6_RC_CTL_EI_MODE(1) | |
| 3374 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3375 | |
| 3376 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 3377 | I915_WRITE(GEN6_RPNSWREQ, |
| 3378 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 3379 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 3380 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3381 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 3382 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
| 3383 | |
| 3384 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 3385 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3386 | dev_priv->rps.max_freq_softlimit << 24 | |
| 3387 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3388 | |
| 3389 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 3390 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 3391 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 3392 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
| 3393 | |
| 3394 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3395 | |
| 3396 | /* 5: Enable RPS */ |
| 3397 | I915_WRITE(GEN6_RP_CONTROL, |
| 3398 | GEN6_RP_MEDIA_TURBO | |
| 3399 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3400 | GEN6_RP_MEDIA_IS_GFX | |
| 3401 | GEN6_RP_ENABLE | |
| 3402 | GEN6_RP_UP_BUSY_AVG | |
| 3403 | GEN6_RP_DOWN_IDLE_AVG); |
| 3404 | |
| 3405 | /* 6: Ring frequency + overclocking (our driver does this later */ |
| 3406 | |
| 3407 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
| 3408 | |
| 3409 | gen6_enable_rps_interrupts(dev); |
| 3410 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3411 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3414 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3415 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3416 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3417 | struct intel_ring_buffer *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3418 | u32 rp_state_cap; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3419 | u32 gt_perf_status; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3420 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3421 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3422 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3423 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3424 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3425 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3426 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3427 | /* Here begins a magic sequence of register writes to enable |
| 3428 | * auto-downclocking. |
| 3429 | * |
| 3430 | * Perhaps there might be some value in exposing these to |
| 3431 | * userspace... |
| 3432 | */ |
| 3433 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3434 | |
| 3435 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 3436 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 3437 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 3438 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3439 | } |
| 3440 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3441 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3442 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3443 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
| 3444 | gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS); |
| 3445 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3446 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3447 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3448 | /* disable the counters and set deterministic thresholds */ |
| 3449 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3450 | |
| 3451 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 3452 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 3453 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 3454 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3455 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3456 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3457 | for_each_ring(ring, dev_priv, i) |
| 3458 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3459 | |
| 3460 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3461 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 3462 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 3463 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 3464 | else |
| 3465 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 3466 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3467 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 3468 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3469 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3470 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 3471 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 3472 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 3473 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3474 | /* We don't use those on Haswell */ |
| 3475 | if (!IS_HASWELL(dev)) { |
| 3476 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 3477 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3478 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3479 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 3480 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 3481 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3482 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3483 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3484 | |
| 3485 | I915_WRITE(GEN6_RC_CONTROL, |
| 3486 | rc6_mask | |
| 3487 | GEN6_RC_CTL_EI_MODE(1) | |
| 3488 | GEN6_RC_CTL_HW_ENABLE); |
| 3489 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3490 | /* Power down if completely idle for over 50ms */ |
| 3491 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3492 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3493 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3494 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_MIN_FREQ_TABLE, 0); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3495 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3496 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3497 | |
| 3498 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 3499 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 3500 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3501 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3502 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3503 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3504 | } |
| 3505 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3506 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3507 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3508 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3509 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3510 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 3511 | rc6vids = 0; |
| 3512 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 3513 | if (IS_GEN6(dev) && ret) { |
| 3514 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 3515 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 3516 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 3517 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 3518 | rc6vids &= 0xffff00; |
| 3519 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 3520 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 3521 | if (ret) |
| 3522 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 3523 | } |
| 3524 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3525 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3526 | } |
| 3527 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3528 | void gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3529 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3531 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3532 | unsigned int gpu_freq; |
| 3533 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3534 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3535 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3536 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3537 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3538 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3539 | policy = cpufreq_cpu_get(0); |
| 3540 | if (policy) { |
| 3541 | max_ia_freq = policy->cpuinfo.max_freq; |
| 3542 | cpufreq_cpu_put(policy); |
| 3543 | } else { |
| 3544 | /* |
| 3545 | * Default to measured freq if none found, PCU will ensure we |
| 3546 | * don't go over |
| 3547 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3548 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3549 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3550 | |
| 3551 | /* Convert from kHz to MHz */ |
| 3552 | max_ia_freq /= 1000; |
| 3553 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 3554 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3555 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 3556 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3557 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3558 | /* |
| 3559 | * For each potential GPU frequency, load a ring frequency we'd like |
| 3560 | * to use for memory access. We do this by specifying the IA frequency |
| 3561 | * the PCU should use as a reference to determine the ring frequency. |
| 3562 | */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3563 | for (gpu_freq = dev_priv->rps.max_freq_softlimit; gpu_freq >= dev_priv->rps.min_freq_softlimit; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3564 | gpu_freq--) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3565 | int diff = dev_priv->rps.max_freq_softlimit - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3566 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3567 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 3568 | if (INTEL_INFO(dev)->gen >= 8) { |
| 3569 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 3570 | ring_freq = max(min_ring_freq, gpu_freq); |
| 3571 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3572 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3573 | ring_freq = max(min_ring_freq, ring_freq); |
| 3574 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 3575 | } else { |
| 3576 | /* On older processors, there is no separate ring |
| 3577 | * clock domain, so in order to boost the bandwidth |
| 3578 | * of the ring, we need to upclock the CPU (ia_freq). |
| 3579 | * |
| 3580 | * For GPU frequencies less than 750MHz, |
| 3581 | * just use the lowest ring freq. |
| 3582 | */ |
| 3583 | if (gpu_freq < min_freq) |
| 3584 | ia_freq = 800; |
| 3585 | else |
| 3586 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 3587 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 3588 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3589 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3590 | sandybridge_pcode_write(dev_priv, |
| 3591 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3592 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 3593 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 3594 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3595 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3596 | } |
| 3597 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3598 | int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
| 3599 | { |
| 3600 | u32 val, rp0; |
| 3601 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3602 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3603 | |
| 3604 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 3605 | /* Clamp to max */ |
| 3606 | rp0 = min_t(u32, rp0, 0xea); |
| 3607 | |
| 3608 | return rp0; |
| 3609 | } |
| 3610 | |
| 3611 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 3612 | { |
| 3613 | u32 val, rpe; |
| 3614 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3615 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_LO); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3616 | rpe = (val & FB_FMAX_VMIN_FREQ_LO_MASK) >> FB_FMAX_VMIN_FREQ_LO_SHIFT; |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3617 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_HI); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3618 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 3619 | |
| 3620 | return rpe; |
| 3621 | } |
| 3622 | |
| 3623 | int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 3624 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3625 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3628 | /* Check that the pctx buffer wasn't move under us. */ |
| 3629 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 3630 | { |
| 3631 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 3632 | |
| 3633 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 3634 | dev_priv->vlv_pctx->stolen->start); |
| 3635 | } |
| 3636 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3637 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 3638 | { |
| 3639 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3640 | struct drm_i915_gem_object *pctx; |
| 3641 | unsigned long pctx_paddr; |
| 3642 | u32 pcbr; |
| 3643 | int pctx_size = 24*1024; |
| 3644 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 3645 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3646 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3647 | pcbr = I915_READ(VLV_PCBR); |
| 3648 | if (pcbr) { |
| 3649 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 3650 | int pcbr_offset; |
| 3651 | |
| 3652 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 3653 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 3654 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 3655 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3656 | pctx_size); |
| 3657 | goto out; |
| 3658 | } |
| 3659 | |
| 3660 | /* |
| 3661 | * From the Gunit register HAS: |
| 3662 | * The Gfx driver is expected to program this register and ensure |
| 3663 | * proper allocation within Gfx stolen memory. For example, this |
| 3664 | * register should be programmed such than the PCBR range does not |
| 3665 | * overlap with other ranges, such as the frame buffer, protected |
| 3666 | * memory, or any other relevant ranges. |
| 3667 | */ |
| 3668 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 3669 | if (!pctx) { |
| 3670 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 3671 | return; |
| 3672 | } |
| 3673 | |
| 3674 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 3675 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 3676 | |
| 3677 | out: |
| 3678 | dev_priv->vlv_pctx = pctx; |
| 3679 | } |
| 3680 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3681 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 3682 | { |
| 3683 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3684 | |
| 3685 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 3686 | return; |
| 3687 | |
| 3688 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 3689 | dev_priv->vlv_pctx = NULL; |
| 3690 | } |
| 3691 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3692 | static void valleyview_enable_rps(struct drm_device *dev) |
| 3693 | { |
| 3694 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3695 | struct intel_ring_buffer *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3696 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3697 | int i; |
| 3698 | |
| 3699 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 3700 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3701 | valleyview_check_pctx(dev_priv); |
| 3702 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3703 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 3704 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 3705 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3706 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3707 | } |
| 3708 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3709 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 3710 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3711 | |
| 3712 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 3713 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 3714 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 3715 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 3716 | |
| 3717 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3718 | |
| 3719 | I915_WRITE(GEN6_RP_CONTROL, |
| 3720 | GEN6_RP_MEDIA_TURBO | |
| 3721 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3722 | GEN6_RP_MEDIA_IS_GFX | |
| 3723 | GEN6_RP_ENABLE | |
| 3724 | GEN6_RP_UP_BUSY_AVG | |
| 3725 | GEN6_RP_DOWN_IDLE_CONT); |
| 3726 | |
| 3727 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 3728 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3729 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3730 | |
| 3731 | for_each_ring(ring, dev_priv, i) |
| 3732 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3733 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 3734 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3735 | |
| 3736 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 3737 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 3738 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 3739 | VLV_MEDIA_RC6_COUNT_EN | |
| 3740 | VLV_RENDER_RC6_COUNT_EN)); |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 3741 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 3742 | rc6_mode = GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL; |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3743 | |
| 3744 | intel_print_rc6_info(dev, rc6_mode); |
| 3745 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 3746 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3747 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3748 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3749 | |
| 3750 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 3751 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 3752 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3753 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3754 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3755 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 3756 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3757 | |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3758 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 3759 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3760 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3761 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 3762 | dev_priv->rps.max_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3763 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3764 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3765 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3766 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 3767 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3768 | |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3769 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3770 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3771 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 3772 | dev_priv->rps.min_freq); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3773 | |
| 3774 | /* Preserve min/max settings in case of re-init */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3775 | if (dev_priv->rps.max_freq_softlimit == 0) |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3776 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3777 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3778 | if (dev_priv->rps.min_freq_softlimit == 0) |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3779 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3780 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3781 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3782 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 3783 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3784 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3785 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3786 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3787 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3788 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3789 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 3792 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3793 | { |
| 3794 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3795 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3796 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3797 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3798 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 3799 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3800 | } |
| 3801 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3802 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3803 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3804 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 3805 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3806 | } |
| 3807 | } |
| 3808 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 3809 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3810 | { |
| 3811 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3812 | |
| 3813 | if (I915_READ(PWRCTXA)) { |
| 3814 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 3815 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 3816 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 3817 | 50); |
| 3818 | |
| 3819 | I915_WRITE(PWRCTXA, 0); |
| 3820 | POSTING_READ(PWRCTXA); |
| 3821 | |
| 3822 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 3823 | POSTING_READ(RSTDBYCTL); |
| 3824 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 3828 | { |
| 3829 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3830 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3831 | if (dev_priv->ips.renderctx == NULL) |
| 3832 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 3833 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3834 | return -ENOMEM; |
| 3835 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3836 | if (dev_priv->ips.pwrctx == NULL) |
| 3837 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 3838 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3839 | ironlake_teardown_rc6(dev); |
| 3840 | return -ENOMEM; |
| 3841 | } |
| 3842 | |
| 3843 | return 0; |
| 3844 | } |
| 3845 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 3846 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3847 | { |
| 3848 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3849 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3850 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3851 | int ret; |
| 3852 | |
| 3853 | /* rc6 disabled by default due to repeated reports of hanging during |
| 3854 | * boot and resume. |
| 3855 | */ |
| 3856 | if (!intel_enable_rc6(dev)) |
| 3857 | return; |
| 3858 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3859 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3860 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3861 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3862 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3863 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3864 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3865 | was_interruptible = dev_priv->mm.interruptible; |
| 3866 | dev_priv->mm.interruptible = false; |
| 3867 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3868 | /* |
| 3869 | * GPU can automatically power down the render unit if given a page |
| 3870 | * to save state. |
| 3871 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3872 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3873 | if (ret) { |
| 3874 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3875 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3876 | return; |
| 3877 | } |
| 3878 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3879 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 3880 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 3881 | intel_ring_emit(ring, i915_gem_obj_ggtt_offset(dev_priv->ips.renderctx) | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3882 | MI_MM_SPACE_GTT | |
| 3883 | MI_SAVE_EXT_STATE_EN | |
| 3884 | MI_RESTORE_EXT_STATE_EN | |
| 3885 | MI_RESTORE_INHIBIT); |
| 3886 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 3887 | intel_ring_emit(ring, MI_NOOP); |
| 3888 | intel_ring_emit(ring, MI_FLUSH); |
| 3889 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3890 | |
| 3891 | /* |
| 3892 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 3893 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 3894 | * safe to assume that renderctx is valid |
| 3895 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3896 | ret = intel_ring_idle(ring); |
| 3897 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3898 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 3899 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3900 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3901 | return; |
| 3902 | } |
| 3903 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 3904 | I915_WRITE(PWRCTXA, i915_gem_obj_ggtt_offset(dev_priv->ips.pwrctx) | PWRCTX_EN); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3905 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3906 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3907 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3908 | } |
| 3909 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 3910 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 3911 | { |
| 3912 | unsigned long freq; |
| 3913 | int div = (vidfreq & 0x3f0000) >> 16; |
| 3914 | int post = (vidfreq & 0x3000) >> 12; |
| 3915 | int pre = (vidfreq & 0x7); |
| 3916 | |
| 3917 | if (!pre) |
| 3918 | return 0; |
| 3919 | |
| 3920 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 3921 | |
| 3922 | return freq; |
| 3923 | } |
| 3924 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3925 | static const struct cparams { |
| 3926 | u16 i; |
| 3927 | u16 t; |
| 3928 | u16 m; |
| 3929 | u16 c; |
| 3930 | } cparams[] = { |
| 3931 | { 1, 1333, 301, 28664 }, |
| 3932 | { 1, 1066, 294, 24460 }, |
| 3933 | { 1, 800, 294, 25192 }, |
| 3934 | { 0, 1333, 276, 27605 }, |
| 3935 | { 0, 1066, 276, 27605 }, |
| 3936 | { 0, 800, 231, 23784 }, |
| 3937 | }; |
| 3938 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 3939 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3940 | { |
| 3941 | u64 total_count, diff, ret; |
| 3942 | u32 count1, count2, count3, m = 0, c = 0; |
| 3943 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 3944 | int i; |
| 3945 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 3946 | assert_spin_locked(&mchdev_lock); |
| 3947 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3948 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3949 | |
| 3950 | /* Prevent division-by-zero if we are asking too fast. |
| 3951 | * Also, we don't get interesting results if we are polling |
| 3952 | * faster than once in 10ms, so just return the saved value |
| 3953 | * in such cases. |
| 3954 | */ |
| 3955 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3956 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3957 | |
| 3958 | count1 = I915_READ(DMIEC); |
| 3959 | count2 = I915_READ(DDREC); |
| 3960 | count3 = I915_READ(CSIEC); |
| 3961 | |
| 3962 | total_count = count1 + count2 + count3; |
| 3963 | |
| 3964 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3965 | if (total_count < dev_priv->ips.last_count1) { |
| 3966 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3967 | diff += total_count; |
| 3968 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3969 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3973 | if (cparams[i].i == dev_priv->ips.c_m && |
| 3974 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3975 | m = cparams[i].m; |
| 3976 | c = cparams[i].c; |
| 3977 | break; |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | diff = div_u64(diff, diff1); |
| 3982 | ret = ((m * diff) + c); |
| 3983 | ret = div_u64(ret, 10); |
| 3984 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3985 | dev_priv->ips.last_count1 = total_count; |
| 3986 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3987 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3988 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3989 | |
| 3990 | return ret; |
| 3991 | } |
| 3992 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 3993 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 3994 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 3995 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 3996 | unsigned long val; |
| 3997 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 3998 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 3999 | return 0; |
| 4000 | |
| 4001 | spin_lock_irq(&mchdev_lock); |
| 4002 | |
| 4003 | val = __i915_chipset_val(dev_priv); |
| 4004 | |
| 4005 | spin_unlock_irq(&mchdev_lock); |
| 4006 | |
| 4007 | return val; |
| 4008 | } |
| 4009 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4010 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 4011 | { |
| 4012 | unsigned long m, x, b; |
| 4013 | u32 tsfs; |
| 4014 | |
| 4015 | tsfs = I915_READ(TSFS); |
| 4016 | |
| 4017 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 4018 | x = I915_READ8(TR1); |
| 4019 | |
| 4020 | b = tsfs & TSFS_INTR_MASK; |
| 4021 | |
| 4022 | return ((m * x) / 127) - b; |
| 4023 | } |
| 4024 | |
| 4025 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 4026 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4027 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4028 | static const struct v_table { |
| 4029 | u16 vd; /* in .1 mil */ |
| 4030 | u16 vm; /* in .1 mil */ |
| 4031 | } v_table[] = { |
| 4032 | { 0, 0, }, |
| 4033 | { 375, 0, }, |
| 4034 | { 500, 0, }, |
| 4035 | { 625, 0, }, |
| 4036 | { 750, 0, }, |
| 4037 | { 875, 0, }, |
| 4038 | { 1000, 0, }, |
| 4039 | { 1125, 0, }, |
| 4040 | { 4125, 3000, }, |
| 4041 | { 4125, 3000, }, |
| 4042 | { 4125, 3000, }, |
| 4043 | { 4125, 3000, }, |
| 4044 | { 4125, 3000, }, |
| 4045 | { 4125, 3000, }, |
| 4046 | { 4125, 3000, }, |
| 4047 | { 4125, 3000, }, |
| 4048 | { 4125, 3000, }, |
| 4049 | { 4125, 3000, }, |
| 4050 | { 4125, 3000, }, |
| 4051 | { 4125, 3000, }, |
| 4052 | { 4125, 3000, }, |
| 4053 | { 4125, 3000, }, |
| 4054 | { 4125, 3000, }, |
| 4055 | { 4125, 3000, }, |
| 4056 | { 4125, 3000, }, |
| 4057 | { 4125, 3000, }, |
| 4058 | { 4125, 3000, }, |
| 4059 | { 4125, 3000, }, |
| 4060 | { 4125, 3000, }, |
| 4061 | { 4125, 3000, }, |
| 4062 | { 4125, 3000, }, |
| 4063 | { 4125, 3000, }, |
| 4064 | { 4250, 3125, }, |
| 4065 | { 4375, 3250, }, |
| 4066 | { 4500, 3375, }, |
| 4067 | { 4625, 3500, }, |
| 4068 | { 4750, 3625, }, |
| 4069 | { 4875, 3750, }, |
| 4070 | { 5000, 3875, }, |
| 4071 | { 5125, 4000, }, |
| 4072 | { 5250, 4125, }, |
| 4073 | { 5375, 4250, }, |
| 4074 | { 5500, 4375, }, |
| 4075 | { 5625, 4500, }, |
| 4076 | { 5750, 4625, }, |
| 4077 | { 5875, 4750, }, |
| 4078 | { 6000, 4875, }, |
| 4079 | { 6125, 5000, }, |
| 4080 | { 6250, 5125, }, |
| 4081 | { 6375, 5250, }, |
| 4082 | { 6500, 5375, }, |
| 4083 | { 6625, 5500, }, |
| 4084 | { 6750, 5625, }, |
| 4085 | { 6875, 5750, }, |
| 4086 | { 7000, 5875, }, |
| 4087 | { 7125, 6000, }, |
| 4088 | { 7250, 6125, }, |
| 4089 | { 7375, 6250, }, |
| 4090 | { 7500, 6375, }, |
| 4091 | { 7625, 6500, }, |
| 4092 | { 7750, 6625, }, |
| 4093 | { 7875, 6750, }, |
| 4094 | { 8000, 6875, }, |
| 4095 | { 8125, 7000, }, |
| 4096 | { 8250, 7125, }, |
| 4097 | { 8375, 7250, }, |
| 4098 | { 8500, 7375, }, |
| 4099 | { 8625, 7500, }, |
| 4100 | { 8750, 7625, }, |
| 4101 | { 8875, 7750, }, |
| 4102 | { 9000, 7875, }, |
| 4103 | { 9125, 8000, }, |
| 4104 | { 9250, 8125, }, |
| 4105 | { 9375, 8250, }, |
| 4106 | { 9500, 8375, }, |
| 4107 | { 9625, 8500, }, |
| 4108 | { 9750, 8625, }, |
| 4109 | { 9875, 8750, }, |
| 4110 | { 10000, 8875, }, |
| 4111 | { 10125, 9000, }, |
| 4112 | { 10250, 9125, }, |
| 4113 | { 10375, 9250, }, |
| 4114 | { 10500, 9375, }, |
| 4115 | { 10625, 9500, }, |
| 4116 | { 10750, 9625, }, |
| 4117 | { 10875, 9750, }, |
| 4118 | { 11000, 9875, }, |
| 4119 | { 11125, 10000, }, |
| 4120 | { 11250, 10125, }, |
| 4121 | { 11375, 10250, }, |
| 4122 | { 11500, 10375, }, |
| 4123 | { 11625, 10500, }, |
| 4124 | { 11750, 10625, }, |
| 4125 | { 11875, 10750, }, |
| 4126 | { 12000, 10875, }, |
| 4127 | { 12125, 11000, }, |
| 4128 | { 12250, 11125, }, |
| 4129 | { 12375, 11250, }, |
| 4130 | { 12500, 11375, }, |
| 4131 | { 12625, 11500, }, |
| 4132 | { 12750, 11625, }, |
| 4133 | { 12875, 11750, }, |
| 4134 | { 13000, 11875, }, |
| 4135 | { 13125, 12000, }, |
| 4136 | { 13250, 12125, }, |
| 4137 | { 13375, 12250, }, |
| 4138 | { 13500, 12375, }, |
| 4139 | { 13625, 12500, }, |
| 4140 | { 13750, 12625, }, |
| 4141 | { 13875, 12750, }, |
| 4142 | { 14000, 12875, }, |
| 4143 | { 14125, 13000, }, |
| 4144 | { 14250, 13125, }, |
| 4145 | { 14375, 13250, }, |
| 4146 | { 14500, 13375, }, |
| 4147 | { 14625, 13500, }, |
| 4148 | { 14750, 13625, }, |
| 4149 | { 14875, 13750, }, |
| 4150 | { 15000, 13875, }, |
| 4151 | { 15125, 14000, }, |
| 4152 | { 15250, 14125, }, |
| 4153 | { 15375, 14250, }, |
| 4154 | { 15500, 14375, }, |
| 4155 | { 15625, 14500, }, |
| 4156 | { 15750, 14625, }, |
| 4157 | { 15875, 14750, }, |
| 4158 | { 16000, 14875, }, |
| 4159 | { 16125, 15000, }, |
| 4160 | }; |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4161 | if (INTEL_INFO(dev)->is_mobile) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4162 | return v_table[pxvid].vm; |
| 4163 | else |
| 4164 | return v_table[pxvid].vd; |
| 4165 | } |
| 4166 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4167 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4168 | { |
| 4169 | struct timespec now, diff1; |
| 4170 | u64 diff; |
| 4171 | unsigned long diffms; |
| 4172 | u32 count; |
| 4173 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4174 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4175 | |
| 4176 | getrawmonotonic(&now); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4177 | diff1 = timespec_sub(now, dev_priv->ips.last_time2); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4178 | |
| 4179 | /* Don't divide by 0 */ |
| 4180 | diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; |
| 4181 | if (!diffms) |
| 4182 | return; |
| 4183 | |
| 4184 | count = I915_READ(GFXEC); |
| 4185 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4186 | if (count < dev_priv->ips.last_count2) { |
| 4187 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4188 | diff += count; |
| 4189 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4190 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4191 | } |
| 4192 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4193 | dev_priv->ips.last_count2 = count; |
| 4194 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4195 | |
| 4196 | /* More magic constants... */ |
| 4197 | diff = diff * 1181; |
| 4198 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4199 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4202 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 4203 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4204 | struct drm_device *dev = dev_priv->dev; |
| 4205 | |
| 4206 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4207 | return; |
| 4208 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4209 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4210 | |
| 4211 | __i915_update_gfx_val(dev_priv); |
| 4212 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4213 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4214 | } |
| 4215 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4216 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4217 | { |
| 4218 | unsigned long t, corr, state1, corr2, state2; |
| 4219 | u32 pxvid, ext_v; |
| 4220 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4221 | assert_spin_locked(&mchdev_lock); |
| 4222 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4223 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4224 | pxvid = (pxvid >> 24) & 0x7f; |
| 4225 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 4226 | |
| 4227 | state1 = ext_v; |
| 4228 | |
| 4229 | t = i915_mch_val(dev_priv); |
| 4230 | |
| 4231 | /* Revel in the empirically derived constants */ |
| 4232 | |
| 4233 | /* Correction factor in 1/100000 units */ |
| 4234 | if (t > 80) |
| 4235 | corr = ((t * 2349) + 135940); |
| 4236 | else if (t >= 50) |
| 4237 | corr = ((t * 964) + 29317); |
| 4238 | else /* < 50 */ |
| 4239 | corr = ((t * 301) + 1004); |
| 4240 | |
| 4241 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 4242 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4243 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4244 | |
| 4245 | state2 = (corr2 * state1) / 10000; |
| 4246 | state2 /= 100; /* convert to mW */ |
| 4247 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4248 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4249 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4250 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4251 | } |
| 4252 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4253 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 4254 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4255 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4256 | unsigned long val; |
| 4257 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4258 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4259 | return 0; |
| 4260 | |
| 4261 | spin_lock_irq(&mchdev_lock); |
| 4262 | |
| 4263 | val = __i915_gfx_val(dev_priv); |
| 4264 | |
| 4265 | spin_unlock_irq(&mchdev_lock); |
| 4266 | |
| 4267 | return val; |
| 4268 | } |
| 4269 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4270 | /** |
| 4271 | * i915_read_mch_val - return value for IPS use |
| 4272 | * |
| 4273 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 4274 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 4275 | */ |
| 4276 | unsigned long i915_read_mch_val(void) |
| 4277 | { |
| 4278 | struct drm_i915_private *dev_priv; |
| 4279 | unsigned long chipset_val, graphics_val, ret = 0; |
| 4280 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4281 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4282 | if (!i915_mch_dev) |
| 4283 | goto out_unlock; |
| 4284 | dev_priv = i915_mch_dev; |
| 4285 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4286 | chipset_val = __i915_chipset_val(dev_priv); |
| 4287 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4288 | |
| 4289 | ret = chipset_val + graphics_val; |
| 4290 | |
| 4291 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4292 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4293 | |
| 4294 | return ret; |
| 4295 | } |
| 4296 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 4297 | |
| 4298 | /** |
| 4299 | * i915_gpu_raise - raise GPU frequency limit |
| 4300 | * |
| 4301 | * Raise the limit; IPS indicates we have thermal headroom. |
| 4302 | */ |
| 4303 | bool i915_gpu_raise(void) |
| 4304 | { |
| 4305 | struct drm_i915_private *dev_priv; |
| 4306 | bool ret = true; |
| 4307 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4308 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4309 | if (!i915_mch_dev) { |
| 4310 | ret = false; |
| 4311 | goto out_unlock; |
| 4312 | } |
| 4313 | dev_priv = i915_mch_dev; |
| 4314 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4315 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 4316 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4317 | |
| 4318 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4319 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4320 | |
| 4321 | return ret; |
| 4322 | } |
| 4323 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 4324 | |
| 4325 | /** |
| 4326 | * i915_gpu_lower - lower GPU frequency limit |
| 4327 | * |
| 4328 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 4329 | * frequency maximum. |
| 4330 | */ |
| 4331 | bool i915_gpu_lower(void) |
| 4332 | { |
| 4333 | struct drm_i915_private *dev_priv; |
| 4334 | bool ret = true; |
| 4335 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4336 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4337 | if (!i915_mch_dev) { |
| 4338 | ret = false; |
| 4339 | goto out_unlock; |
| 4340 | } |
| 4341 | dev_priv = i915_mch_dev; |
| 4342 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4343 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 4344 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4345 | |
| 4346 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4347 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4348 | |
| 4349 | return ret; |
| 4350 | } |
| 4351 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 4352 | |
| 4353 | /** |
| 4354 | * i915_gpu_busy - indicate GPU business to IPS |
| 4355 | * |
| 4356 | * Tell the IPS driver whether or not the GPU is busy. |
| 4357 | */ |
| 4358 | bool i915_gpu_busy(void) |
| 4359 | { |
| 4360 | struct drm_i915_private *dev_priv; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4361 | struct intel_ring_buffer *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4362 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4363 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4364 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4365 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4366 | if (!i915_mch_dev) |
| 4367 | goto out_unlock; |
| 4368 | dev_priv = i915_mch_dev; |
| 4369 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4370 | for_each_ring(ring, dev_priv, i) |
| 4371 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4372 | |
| 4373 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4374 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4375 | |
| 4376 | return ret; |
| 4377 | } |
| 4378 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 4379 | |
| 4380 | /** |
| 4381 | * i915_gpu_turbo_disable - disable graphics turbo |
| 4382 | * |
| 4383 | * Disable graphics turbo by resetting the max frequency and setting the |
| 4384 | * current frequency to the default. |
| 4385 | */ |
| 4386 | bool i915_gpu_turbo_disable(void) |
| 4387 | { |
| 4388 | struct drm_i915_private *dev_priv; |
| 4389 | bool ret = true; |
| 4390 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4391 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4392 | if (!i915_mch_dev) { |
| 4393 | ret = false; |
| 4394 | goto out_unlock; |
| 4395 | } |
| 4396 | dev_priv = i915_mch_dev; |
| 4397 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4398 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4399 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4400 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4401 | ret = false; |
| 4402 | |
| 4403 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4404 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4405 | |
| 4406 | return ret; |
| 4407 | } |
| 4408 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 4409 | |
| 4410 | /** |
| 4411 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 4412 | * IPS got loaded first. |
| 4413 | * |
| 4414 | * This awkward dance is so that neither module has to depend on the |
| 4415 | * other in order for IPS to do the appropriate communication of |
| 4416 | * GPU turbo limits to i915. |
| 4417 | */ |
| 4418 | static void |
| 4419 | ips_ping_for_i915_load(void) |
| 4420 | { |
| 4421 | void (*link)(void); |
| 4422 | |
| 4423 | link = symbol_get(ips_link_to_i915_driver); |
| 4424 | if (link) { |
| 4425 | link(); |
| 4426 | symbol_put(ips_link_to_i915_driver); |
| 4427 | } |
| 4428 | } |
| 4429 | |
| 4430 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 4431 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4432 | /* We only register the i915 ips part with intel-ips once everything is |
| 4433 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4434 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4435 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4436 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4437 | |
| 4438 | ips_ping_for_i915_load(); |
| 4439 | } |
| 4440 | |
| 4441 | void intel_gpu_ips_teardown(void) |
| 4442 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4443 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4444 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4445 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4446 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4447 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4448 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4449 | { |
| 4450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4451 | u32 lcfuse; |
| 4452 | u8 pxw[16]; |
| 4453 | int i; |
| 4454 | |
| 4455 | /* Disable to program */ |
| 4456 | I915_WRITE(ECR, 0); |
| 4457 | POSTING_READ(ECR); |
| 4458 | |
| 4459 | /* Program energy weights for various events */ |
| 4460 | I915_WRITE(SDEW, 0x15040d00); |
| 4461 | I915_WRITE(CSIEW0, 0x007f0000); |
| 4462 | I915_WRITE(CSIEW1, 0x1e220004); |
| 4463 | I915_WRITE(CSIEW2, 0x04000004); |
| 4464 | |
| 4465 | for (i = 0; i < 5; i++) |
| 4466 | I915_WRITE(PEW + (i * 4), 0); |
| 4467 | for (i = 0; i < 3; i++) |
| 4468 | I915_WRITE(DEW + (i * 4), 0); |
| 4469 | |
| 4470 | /* Program P-state weights to account for frequency power adjustment */ |
| 4471 | for (i = 0; i < 16; i++) { |
| 4472 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 4473 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 4474 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 4475 | PXVFREQ_PX_SHIFT; |
| 4476 | unsigned long val; |
| 4477 | |
| 4478 | val = vid * vid; |
| 4479 | val *= (freq / 1000); |
| 4480 | val *= 255; |
| 4481 | val /= (127*127*900); |
| 4482 | if (val > 0xff) |
| 4483 | DRM_ERROR("bad pxval: %ld\n", val); |
| 4484 | pxw[i] = val; |
| 4485 | } |
| 4486 | /* Render standby states get 0 weight */ |
| 4487 | pxw[14] = 0; |
| 4488 | pxw[15] = 0; |
| 4489 | |
| 4490 | for (i = 0; i < 4; i++) { |
| 4491 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 4492 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 4493 | I915_WRITE(PXW + (i * 4), val); |
| 4494 | } |
| 4495 | |
| 4496 | /* Adjust magic regs to magic values (more experimental results) */ |
| 4497 | I915_WRITE(OGW0, 0); |
| 4498 | I915_WRITE(OGW1, 0); |
| 4499 | I915_WRITE(EG0, 0x00007f00); |
| 4500 | I915_WRITE(EG1, 0x0000000e); |
| 4501 | I915_WRITE(EG2, 0x000e0000); |
| 4502 | I915_WRITE(EG3, 0x68000300); |
| 4503 | I915_WRITE(EG4, 0x42000000); |
| 4504 | I915_WRITE(EG5, 0x00140031); |
| 4505 | I915_WRITE(EG6, 0); |
| 4506 | I915_WRITE(EG7, 0); |
| 4507 | |
| 4508 | for (i = 0; i < 8; i++) |
| 4509 | I915_WRITE(PXWL + (i * 4), 0); |
| 4510 | |
| 4511 | /* Enable PMON + select events */ |
| 4512 | I915_WRITE(ECR, 0x80000019); |
| 4513 | |
| 4514 | lcfuse = I915_READ(LCFUSE02); |
| 4515 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4516 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4517 | } |
| 4518 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4519 | void intel_init_gt_powersave(struct drm_device *dev) |
| 4520 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4521 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 4522 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4523 | if (IS_VALLEYVIEW(dev)) |
| 4524 | valleyview_setup_pctx(dev); |
| 4525 | } |
| 4526 | |
| 4527 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 4528 | { |
| 4529 | if (IS_VALLEYVIEW(dev)) |
| 4530 | valleyview_cleanup_pctx(dev); |
| 4531 | } |
| 4532 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4533 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 4534 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4535 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4536 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 4537 | /* Interrupts should be disabled already to avoid re-arming. */ |
| 4538 | WARN_ON(dev->irq_enabled); |
| 4539 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4540 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4541 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4542 | ironlake_disable_rc6(dev); |
Imre Deak | 14dd0ea | 2014-04-14 20:24:34 +0300 | [diff] [blame] | 4543 | } else if (IS_GEN6(dev) || IS_GEN7(dev)) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4544 | cancel_delayed_work_sync(&dev_priv->rps.delayed_resume_work); |
Jesse Barnes | 250848c | 2013-04-23 10:09:27 -0700 | [diff] [blame] | 4545 | cancel_work_sync(&dev_priv->rps.work); |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4546 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4547 | if (IS_VALLEYVIEW(dev)) |
| 4548 | valleyview_disable_rps(dev); |
| 4549 | else |
| 4550 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4551 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4552 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4553 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4554 | } |
| 4555 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4556 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 4557 | { |
| 4558 | struct drm_i915_private *dev_priv = |
| 4559 | container_of(work, struct drm_i915_private, |
| 4560 | rps.delayed_resume_work.work); |
| 4561 | struct drm_device *dev = dev_priv->dev; |
| 4562 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4563 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4564 | |
| 4565 | if (IS_VALLEYVIEW(dev)) { |
| 4566 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4567 | } else if (IS_BROADWELL(dev)) { |
| 4568 | gen8_enable_rps(dev); |
| 4569 | gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4570 | } else { |
| 4571 | gen6_enable_rps(dev); |
| 4572 | gen6_update_ring_freq(dev); |
| 4573 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4574 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4575 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 4576 | |
| 4577 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4580 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 4581 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4582 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4583 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4584 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 4585 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4586 | ironlake_enable_drps(dev); |
| 4587 | ironlake_enable_rc6(dev); |
| 4588 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 4589 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4590 | } else if (IS_GEN6(dev) || IS_GEN7(dev)) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4591 | /* |
| 4592 | * PCU communication is slow and this doesn't need to be |
| 4593 | * done at any specific time, so do this out of our fast path |
| 4594 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 4595 | * |
| 4596 | * We depend on the HW RC6 power context save/restore |
| 4597 | * mechanism when entering D3 through runtime PM suspend. So |
| 4598 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 4599 | * get here via the driver load/system resume/runtime resume |
| 4600 | * paths, so the _noresume version is enough (and in case of |
| 4601 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4602 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 4603 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 4604 | round_jiffies_up_relative(HZ))) |
| 4605 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 4609 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 4610 | { |
| 4611 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4612 | |
| 4613 | dev_priv->rps.enabled = false; |
| 4614 | intel_enable_gt_powersave(dev); |
| 4615 | } |
| 4616 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4617 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 4618 | { |
| 4619 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4620 | |
| 4621 | /* |
| 4622 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 4623 | * gating for the panel power sequencer or it will fail to |
| 4624 | * start up when no ports are active. |
| 4625 | */ |
| 4626 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 4627 | } |
| 4628 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4629 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 4630 | { |
| 4631 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4632 | int pipe; |
| 4633 | |
| 4634 | for_each_pipe(pipe) { |
| 4635 | I915_WRITE(DSPCNTR(pipe), |
| 4636 | I915_READ(DSPCNTR(pipe)) | |
| 4637 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 4638 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4639 | } |
| 4640 | } |
| 4641 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4642 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 4643 | { |
| 4644 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4645 | |
| 4646 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 4647 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 4648 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 4649 | |
| 4650 | /* |
| 4651 | * Don't touch WM1S_LP_EN here. |
| 4652 | * Doing so could cause underruns. |
| 4653 | */ |
| 4654 | } |
| 4655 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4656 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4657 | { |
| 4658 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4659 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4660 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 4661 | /* |
| 4662 | * Required for FBC |
| 4663 | * WaFbcDisableDpfcClockGating:ilk |
| 4664 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 4665 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 4666 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 4667 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4668 | |
| 4669 | I915_WRITE(PCH_3DCGDIS0, |
| 4670 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 4671 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 4672 | I915_WRITE(PCH_3DCGDIS1, |
| 4673 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 4674 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4675 | /* |
| 4676 | * According to the spec the following bits should be set in |
| 4677 | * order to enable memory self-refresh |
| 4678 | * The bit 22/21 of 0x42004 |
| 4679 | * The bit 5 of 0x42020 |
| 4680 | * The bit 15 of 0x45000 |
| 4681 | */ |
| 4682 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4683 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4684 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 4685 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4686 | I915_WRITE(DISP_ARB_CTL, |
| 4687 | (I915_READ(DISP_ARB_CTL) | |
| 4688 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4689 | |
| 4690 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4691 | |
| 4692 | /* |
| 4693 | * Based on the document from hardware guys the following bits |
| 4694 | * should be set unconditionally in order to enable FBC. |
| 4695 | * The bit 22 of 0x42000 |
| 4696 | * The bit 22 of 0x42004 |
| 4697 | * The bit 7,8,9 of 0x42020. |
| 4698 | */ |
| 4699 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 4700 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4701 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 4702 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 4703 | ILK_FBCQ_DIS); |
| 4704 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4705 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4706 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4707 | } |
| 4708 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 4709 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 4710 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4711 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4712 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4713 | ILK_ELPIN_409_SELECT); |
| 4714 | I915_WRITE(_3D_CHICKEN2, |
| 4715 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 4716 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 4717 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4718 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 4719 | I915_WRITE(CACHE_MODE_0, |
| 4720 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4721 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 4722 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 4723 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 4724 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4725 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 4726 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4727 | ibx_init_clock_gating(dev); |
| 4728 | } |
| 4729 | |
| 4730 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 4731 | { |
| 4732 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4733 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4734 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4735 | |
| 4736 | /* |
| 4737 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 4738 | * gating for the panel power sequencer or it will fail to |
| 4739 | * start up when no ports are active. |
| 4740 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 4741 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 4742 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 4743 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4744 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 4745 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 4746 | /* The below fixes the weird display corruption, a few pixels shifted |
| 4747 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 4748 | */ |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4749 | for_each_pipe(pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 4750 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 4751 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 4752 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 4753 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4754 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 4755 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 4756 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 4757 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4758 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 4759 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4760 | /* WADP0ClockGatingDisable */ |
| 4761 | for_each_pipe(pipe) { |
| 4762 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 4763 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 4764 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4765 | } |
| 4766 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 4767 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 4768 | { |
| 4769 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4770 | uint32_t tmp; |
| 4771 | |
| 4772 | tmp = I915_READ(MCH_SSKPD); |
| 4773 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) { |
| 4774 | DRM_INFO("Wrong MCH_SSKPD value: 0x%08x\n", tmp); |
| 4775 | DRM_INFO("This can cause pipe underruns and display issues.\n"); |
| 4776 | DRM_INFO("Please upgrade your BIOS to fix this.\n"); |
| 4777 | } |
| 4778 | } |
| 4779 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4780 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4781 | { |
| 4782 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4783 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4784 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4785 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4786 | |
| 4787 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4788 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4789 | ILK_ELPIN_409_SELECT); |
| 4790 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4791 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 4792 | I915_WRITE(_3D_CHICKEN, |
| 4793 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 4794 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4795 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 4796 | if (IS_SNB_GT1(dev)) |
| 4797 | I915_WRITE(GEN6_GT_MODE, |
| 4798 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 4799 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 4800 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 4801 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 4802 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 4803 | /* |
| 4804 | * BSpec recoomends 8x4 when MSAA is used, |
| 4805 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 4806 | * |
| 4807 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 4808 | * disable bit, which we don't touch here, but it's good |
| 4809 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 4810 | */ |
| 4811 | I915_WRITE(GEN6_GT_MODE, |
| 4812 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 4813 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4814 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4815 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4816 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 4817 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4818 | |
| 4819 | I915_WRITE(GEN6_UCGCTL1, |
| 4820 | I915_READ(GEN6_UCGCTL1) | |
| 4821 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 4822 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 4823 | |
| 4824 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 4825 | * gating disable must be set. Failure to set it results in |
| 4826 | * flickering pixels due to Z write ordering failures after |
| 4827 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 4828 | * Sanctuary and Tropics, and apparently anything else with |
| 4829 | * alpha test or pixel discard. |
| 4830 | * |
| 4831 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 4832 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4833 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 4834 | * WaDisableRCCUnitClockGating:snb |
| 4835 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4836 | */ |
| 4837 | I915_WRITE(GEN6_UCGCTL2, |
| 4838 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 4839 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 4840 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 4841 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 4842 | I915_WRITE(_3D_CHICKEN3, |
| 4843 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4844 | |
| 4845 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 4846 | * Bspec says: |
| 4847 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 4848 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 4849 | */ |
| 4850 | I915_WRITE(_3D_CHICKEN3, |
| 4851 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 4852 | |
| 4853 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4854 | * According to the spec the following bits should be |
| 4855 | * set in order to enable memory self-refresh and fbc: |
| 4856 | * The bit21 and bit22 of 0x42000 |
| 4857 | * The bit21 and bit22 of 0x42004 |
| 4858 | * The bit5 and bit7 of 0x42020 |
| 4859 | * The bit14 of 0x70180 |
| 4860 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 4861 | * |
| 4862 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4863 | */ |
| 4864 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 4865 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 4866 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 4867 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4868 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4869 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4870 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 4871 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 4872 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 4873 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4874 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4875 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 4876 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4877 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 4878 | |
| 4879 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 4883 | { |
| 4884 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 4885 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 4886 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 4887 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 4888 | * |
| 4889 | * This actually overrides the dispatch |
| 4890 | * mode for all thread types. |
| 4891 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4892 | reg &= ~GEN7_FF_SCHED_MASK; |
| 4893 | reg |= GEN7_FF_TS_SCHED_HW; |
| 4894 | reg |= GEN7_FF_VS_SCHED_HW; |
| 4895 | reg |= GEN7_FF_DS_SCHED_HW; |
| 4896 | |
| 4897 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 4898 | } |
| 4899 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 4900 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 4901 | { |
| 4902 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4903 | |
| 4904 | /* |
| 4905 | * TODO: this bit should only be enabled when really needed, then |
| 4906 | * disabled when not needed anymore in order to save power. |
| 4907 | */ |
| 4908 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 4909 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 4910 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 4911 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 4912 | |
| 4913 | /* WADPOClockGatingDisable:hsw */ |
| 4914 | I915_WRITE(_TRANSA_CHICKEN1, |
| 4915 | I915_READ(_TRANSA_CHICKEN1) | |
| 4916 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 4917 | } |
| 4918 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 4919 | static void lpt_suspend_hw(struct drm_device *dev) |
| 4920 | { |
| 4921 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4922 | |
| 4923 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 4924 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 4925 | |
| 4926 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 4927 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 4928 | } |
| 4929 | } |
| 4930 | |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 4931 | static void gen8_init_clock_gating(struct drm_device *dev) |
| 4932 | { |
| 4933 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 4934 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 4935 | |
| 4936 | I915_WRITE(WM3_LP_ILK, 0); |
| 4937 | I915_WRITE(WM2_LP_ILK, 0); |
| 4938 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 4939 | |
| 4940 | /* FIXME(BDW): Check all the w/a, some might only apply to |
| 4941 | * pre-production hw. */ |
| 4942 | |
Kenneth Graunke | c8966e1 | 2014-02-26 23:59:30 -0800 | [diff] [blame] | 4943 | /* WaDisablePartialInstShootdown:bdw */ |
| 4944 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 4945 | _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE)); |
| 4946 | |
Kenneth Graunke | 1411e6a | 2014-02-26 23:59:31 -0800 | [diff] [blame] | 4947 | /* WaDisableThreadStallDopClockGating:bdw */ |
| 4948 | /* FIXME: Unclear whether we really need this on production bdw. */ |
| 4949 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 4950 | _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE)); |
| 4951 | |
Damien Lespiau | 4167e32 | 2014-01-16 16:51:35 +0000 | [diff] [blame] | 4952 | /* |
| 4953 | * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for |
| 4954 | * pre-production hardware |
| 4955 | */ |
Ben Widawsky | fd392b6 | 2013-11-04 22:52:39 -0800 | [diff] [blame] | 4956 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 4957 | _MASKED_BIT_ENABLE(GEN8_CENTROID_PIXEL_OPT_DIS)); |
Ben Widawsky | bf66347 | 2013-11-02 21:07:57 -0700 | [diff] [blame] | 4958 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 4959 | _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS)); |
Ben Widawsky | 4afe8d3 | 2013-11-02 21:07:55 -0700 | [diff] [blame] | 4960 | I915_WRITE(GAMTARBMODE, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE)); |
| 4961 | |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 4962 | I915_WRITE(_3D_CHICKEN3, |
| 4963 | _3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2)); |
| 4964 | |
Ben Widawsky | a75f362 | 2013-11-02 21:07:59 -0700 | [diff] [blame] | 4965 | I915_WRITE(COMMON_SLICE_CHICKEN2, |
| 4966 | _MASKED_BIT_ENABLE(GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE)); |
| 4967 | |
Ben Widawsky | 4c2e7a5 | 2013-11-02 21:08:00 -0700 | [diff] [blame] | 4968 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 4969 | _MASKED_BIT_ENABLE(GEN7_SINGLE_SUBSCAN_DISPATCH_ENABLE)); |
| 4970 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4971 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 4972 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 4973 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4974 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 4975 | I915_WRITE(CHICKEN_PAR1_1, |
| 4976 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 4977 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4978 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 4979 | for_each_pipe(pipe) { |
| 4980 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 4981 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 4982 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 4983 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 4984 | |
| 4985 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
| 4986 | * workaround for for a possible hang in the unlikely event a TLB |
| 4987 | * invalidation occurs during a PSD flush. |
| 4988 | */ |
| 4989 | I915_WRITE(HDC_CHICKEN0, |
| 4990 | I915_READ(HDC_CHICKEN0) | |
| 4991 | _MASKED_BIT_ENABLE(HDC_FORCE_NON_COHERENT)); |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4992 | |
| 4993 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 4994 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 4995 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 4996 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 4997 | ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME)); |
Ville Syrjälä | 36075a4 | 2014-02-04 21:59:21 +0200 | [diff] [blame] | 4998 | |
| 4999 | /* |
| 5000 | * BSpec recommends 8x4 when MSAA is used, |
| 5001 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5002 | * |
| 5003 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5004 | * disable bit, which we don't touch here, but it's good |
| 5005 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 36075a4 | 2014-02-04 21:59:21 +0200 | [diff] [blame] | 5006 | */ |
| 5007 | I915_WRITE(GEN7_GT_MODE, |
| 5008 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 5009 | |
| 5010 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5011 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 5012 | |
| 5013 | /* WaDisableSDEUnitClockGating:bdw */ |
| 5014 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5015 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 5016 | |
| 5017 | /* Wa4x4STCOptimizationDisable:bdw */ |
| 5018 | I915_WRITE(CACHE_MODE_1, |
| 5019 | _MASKED_BIT_ENABLE(GEN8_4x4_STC_OPTIMIZATION_DISABLE)); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5022 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 5023 | { |
| 5024 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5025 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5026 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5027 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 5028 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 5029 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 5030 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 5031 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 5032 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5033 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5034 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5035 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5036 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5037 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 5038 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 5039 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5040 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5041 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5042 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 5043 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5044 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 5045 | /* enable HiZ Raw Stall Optimization */ |
| 5046 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5047 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5048 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5049 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5050 | I915_WRITE(CACHE_MODE_1, |
| 5051 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5052 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5053 | /* |
| 5054 | * BSpec recommends 8x4 when MSAA is used, |
| 5055 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5056 | * |
| 5057 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5058 | * disable bit, which we don't touch here, but it's good |
| 5059 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5060 | */ |
| 5061 | I915_WRITE(GEN7_GT_MODE, |
| 5062 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5063 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5064 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 5065 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 5066 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 5067 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 5068 | I915_WRITE(CHICKEN_PAR1_1, |
| 5069 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5070 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5071 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5072 | } |
| 5073 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5074 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5075 | { |
| 5076 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5077 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5078 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5079 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5080 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5081 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5082 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5083 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5084 | I915_WRITE(_3D_CHICKEN3, |
| 5085 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5086 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5087 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5088 | I915_WRITE(IVB_CHICKEN3, |
| 5089 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5090 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5091 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5092 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5093 | if (IS_IVB_GT1(dev)) |
| 5094 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5095 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5096 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5097 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 5098 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5099 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5100 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5101 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 5102 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 5103 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5104 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5105 | I915_WRITE(GEN7_L3CNTLREG1, |
| 5106 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 5107 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5108 | GEN7_WA_L3_CHICKEN_MODE); |
| 5109 | if (IS_IVB_GT1(dev)) |
| 5110 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5111 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5112 | else { |
| 5113 | /* must write both registers */ |
| 5114 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5115 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5116 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 5117 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5118 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5119 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5120 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5121 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5122 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5123 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 5124 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5125 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5126 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5127 | */ |
| 5128 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 5129 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5130 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5131 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5132 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5133 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5134 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5135 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5136 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5137 | |
| 5138 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5139 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 5140 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 5141 | /* enable HiZ Raw Stall Optimization */ |
| 5142 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5143 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5144 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 5145 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5146 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5147 | I915_WRITE(CACHE_MODE_1, |
| 5148 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5149 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5150 | /* |
| 5151 | * BSpec recommends 8x4 when MSAA is used, |
| 5152 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5153 | * |
| 5154 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5155 | * disable bit, which we don't touch here, but it's good |
| 5156 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5157 | */ |
| 5158 | I915_WRITE(GEN7_GT_MODE, |
| 5159 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5160 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5161 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 5162 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 5163 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 5164 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5165 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 5166 | if (!HAS_PCH_NOP(dev)) |
| 5167 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5168 | |
| 5169 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5170 | } |
| 5171 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5172 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5173 | { |
| 5174 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5175 | u32 val; |
| 5176 | |
| 5177 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5178 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5179 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5180 | switch ((val >> 6) & 3) { |
| 5181 | case 0: |
Deepak S | f6d5194 | 2014-04-03 21:01:28 +0530 | [diff] [blame] | 5182 | case 1: |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5183 | dev_priv->mem_freq = 800; |
| 5184 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5185 | case 2: |
Deepak S | f6d5194 | 2014-04-03 21:01:28 +0530 | [diff] [blame] | 5186 | dev_priv->mem_freq = 1066; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5187 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5188 | case 3: |
Chon Ming Lee | 2325991 | 2013-11-07 15:23:26 +0800 | [diff] [blame] | 5189 | dev_priv->mem_freq = 1333; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5190 | break; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5191 | } |
| 5192 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5193 | |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5194 | dev_priv->vlv_cdclk_freq = valleyview_cur_cdclk(dev_priv); |
| 5195 | DRM_DEBUG_DRIVER("Current CD clock rate: %d MHz", |
| 5196 | dev_priv->vlv_cdclk_freq); |
| 5197 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 5198 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5199 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5200 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5201 | I915_WRITE(_3D_CHICKEN3, |
| 5202 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5203 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5204 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5205 | I915_WRITE(IVB_CHICKEN3, |
| 5206 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5207 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5208 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 5209 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5210 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5211 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 5212 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 5213 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5214 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5215 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 5216 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5217 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5218 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5219 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5220 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5221 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5222 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5223 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5224 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5225 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5226 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5227 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5228 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5229 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5230 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5231 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 5232 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5233 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5234 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5235 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5236 | */ |
| 5237 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5238 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5239 | |
Ville Syrjälä | c5c32cd | 2014-01-22 21:32:37 +0200 | [diff] [blame] | 5240 | /* WaDisableL3Bank2xClockGate:vlv */ |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 5241 | I915_WRITE(GEN7_UCGCTL4, GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
| 5242 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 5243 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5244 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 5245 | /* |
| 5246 | * BSpec says this must be set, even though |
| 5247 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 5248 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 5249 | I915_WRITE(CACHE_MODE_1, |
| 5250 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 5251 | |
| 5252 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 5253 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 5254 | * This is the hardware default actually. |
| 5255 | */ |
| 5256 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 5257 | |
| 5258 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5259 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 5260 | * Disable clock gating on th GCFG unit to prevent a delay |
| 5261 | * in the reporting of vblank events. |
| 5262 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 5263 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5264 | } |
| 5265 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5266 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5267 | { |
| 5268 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5269 | uint32_t dspclk_gate; |
| 5270 | |
| 5271 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 5272 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 5273 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 5274 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 5275 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5276 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 5277 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 5278 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 5279 | if (IS_GM45(dev)) |
| 5280 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 5281 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5282 | |
| 5283 | /* WaDisableRenderCachePipelinedFlush */ |
| 5284 | I915_WRITE(CACHE_MODE_0, |
| 5285 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 5286 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5287 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 5288 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5289 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5290 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5291 | } |
| 5292 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5293 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5294 | { |
| 5295 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5296 | |
| 5297 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 5298 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 5299 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 5300 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5301 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5302 | I915_WRITE(MI_ARB_STATE, |
| 5303 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5304 | |
| 5305 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 5306 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5307 | } |
| 5308 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5309 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5310 | { |
| 5311 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5312 | |
| 5313 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 5314 | I965_RCC_CLOCK_GATE_DISABLE | |
| 5315 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 5316 | I965_ISC_CLOCK_GATE_DISABLE | |
| 5317 | I965_FBC_CLOCK_GATE_DISABLE); |
| 5318 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5319 | I915_WRITE(MI_ARB_STATE, |
| 5320 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5321 | |
| 5322 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 5323 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5324 | } |
| 5325 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5326 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5327 | { |
| 5328 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5329 | u32 dstate = I915_READ(D_STATE); |
| 5330 | |
| 5331 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 5332 | DSTATE_DOT_CLOCK_GATING; |
| 5333 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 5334 | |
| 5335 | if (IS_PINEVIEW(dev)) |
| 5336 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 5337 | |
| 5338 | /* IIR "flip pending" means done if this bit is set */ |
| 5339 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5340 | } |
| 5341 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5342 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5343 | { |
| 5344 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5345 | |
| 5346 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
| 5347 | } |
| 5348 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5349 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5350 | { |
| 5351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5352 | |
| 5353 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
| 5354 | } |
| 5355 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5356 | void intel_init_clock_gating(struct drm_device *dev) |
| 5357 | { |
| 5358 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5359 | |
| 5360 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5361 | } |
| 5362 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5363 | void intel_suspend_hw(struct drm_device *dev) |
| 5364 | { |
| 5365 | if (HAS_PCH_LPT(dev)) |
| 5366 | lpt_suspend_hw(dev); |
| 5367 | } |
| 5368 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5369 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 5370 | for (i = 0; \ |
| 5371 | i < (power_domains)->power_well_count && \ |
| 5372 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 5373 | i++) \ |
| 5374 | if ((power_well)->domains & (domain_mask)) |
| 5375 | |
| 5376 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 5377 | for (i = (power_domains)->power_well_count - 1; \ |
| 5378 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 5379 | i--) \ |
| 5380 | if ((power_well)->domains & (domain_mask)) |
| 5381 | |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5382 | /** |
| 5383 | * We should only use the power well if we explicitly asked the hardware to |
| 5384 | * enable it, so check if it's enabled and also check if we've requested it to |
| 5385 | * be enabled. |
| 5386 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5387 | static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5388 | struct i915_power_well *power_well) |
| 5389 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5390 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 5391 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 5392 | } |
| 5393 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5394 | bool intel_display_power_enabled_sw(struct drm_i915_private *dev_priv, |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5395 | enum intel_display_power_domain domain) |
| 5396 | { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5397 | struct i915_power_domains *power_domains; |
| 5398 | |
| 5399 | power_domains = &dev_priv->power_domains; |
| 5400 | |
| 5401 | return power_domains->domain_use_count[domain]; |
| 5402 | } |
| 5403 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5404 | bool intel_display_power_enabled(struct drm_i915_private *dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 5405 | enum intel_display_power_domain domain) |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5406 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5407 | struct i915_power_domains *power_domains; |
| 5408 | struct i915_power_well *power_well; |
| 5409 | bool is_enabled; |
| 5410 | int i; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5411 | |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 5412 | if (dev_priv->pm.suspended) |
| 5413 | return false; |
| 5414 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5415 | power_domains = &dev_priv->power_domains; |
| 5416 | |
| 5417 | is_enabled = true; |
| 5418 | |
| 5419 | mutex_lock(&power_domains->lock); |
| 5420 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5421 | if (power_well->always_on) |
| 5422 | continue; |
| 5423 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5424 | if (!power_well->ops->is_enabled(dev_priv, power_well)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5425 | is_enabled = false; |
| 5426 | break; |
| 5427 | } |
| 5428 | } |
| 5429 | mutex_unlock(&power_domains->lock); |
| 5430 | |
| 5431 | return is_enabled; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5432 | } |
| 5433 | |
Imre Deak | 93c73e8 | 2014-02-18 00:02:19 +0200 | [diff] [blame] | 5434 | /* |
| 5435 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 5436 | * when not needed anymore. We have 4 registers that can request the power well |
| 5437 | * to be enabled, and it will only be disabled if none of the registers is |
| 5438 | * requesting it to be enabled. |
| 5439 | */ |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5440 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 5441 | { |
| 5442 | struct drm_device *dev = dev_priv->dev; |
| 5443 | unsigned long irqflags; |
| 5444 | |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 5445 | /* |
| 5446 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 5447 | * we'll get unclaimed register interrupts. This stops after we write |
| 5448 | * anything to the VGA MSR register. The vgacon module uses this |
| 5449 | * register all the time, so if we unbind our driver and, as a |
| 5450 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 5451 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 5452 | * sure vgacon can keep working normally without triggering interrupts |
| 5453 | * and error messages. |
| 5454 | */ |
| 5455 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 5456 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
| 5457 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 5458 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5459 | if (IS_BROADWELL(dev)) { |
| 5460 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 5461 | I915_WRITE(GEN8_DE_PIPE_IMR(PIPE_B), |
| 5462 | dev_priv->de_irq_mask[PIPE_B]); |
| 5463 | I915_WRITE(GEN8_DE_PIPE_IER(PIPE_B), |
| 5464 | ~dev_priv->de_irq_mask[PIPE_B] | |
| 5465 | GEN8_PIPE_VBLANK); |
| 5466 | I915_WRITE(GEN8_DE_PIPE_IMR(PIPE_C), |
| 5467 | dev_priv->de_irq_mask[PIPE_C]); |
| 5468 | I915_WRITE(GEN8_DE_PIPE_IER(PIPE_C), |
| 5469 | ~dev_priv->de_irq_mask[PIPE_C] | |
| 5470 | GEN8_PIPE_VBLANK); |
| 5471 | POSTING_READ(GEN8_DE_PIPE_IER(PIPE_C)); |
| 5472 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 5473 | } |
| 5474 | } |
| 5475 | |
Imre Deak | dd7c0b6 | 2014-03-04 19:23:03 +0200 | [diff] [blame] | 5476 | static void reset_vblank_counter(struct drm_device *dev, enum pipe pipe) |
| 5477 | { |
| 5478 | assert_spin_locked(&dev->vbl_lock); |
| 5479 | |
| 5480 | dev->vblank[pipe].last = 0; |
| 5481 | } |
| 5482 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5483 | static void hsw_power_well_post_disable(struct drm_i915_private *dev_priv) |
| 5484 | { |
| 5485 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5486 | enum pipe pipe; |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5487 | unsigned long irqflags; |
| 5488 | |
| 5489 | /* |
| 5490 | * After this, the registers on the pipes that are part of the power |
| 5491 | * well will become zero, so we have to adjust our counters according to |
| 5492 | * that. |
| 5493 | * |
| 5494 | * FIXME: Should we do this in general in drm_vblank_post_modeset? |
| 5495 | */ |
| 5496 | spin_lock_irqsave(&dev->vbl_lock, irqflags); |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5497 | for_each_pipe(pipe) |
| 5498 | if (pipe != PIPE_A) |
Imre Deak | dd7c0b6 | 2014-03-04 19:23:03 +0200 | [diff] [blame] | 5499 | reset_vblank_counter(dev, pipe); |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5500 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
| 5501 | } |
| 5502 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5503 | static void hsw_set_power_well(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5504 | struct i915_power_well *power_well, bool enable) |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5505 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5506 | bool is_enabled, enable_requested; |
| 5507 | uint32_t tmp; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5508 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5509 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5510 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 5511 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5512 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5513 | if (enable) { |
| 5514 | if (!enable_requested) |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5515 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 5516 | HSW_PWR_WELL_ENABLE_REQUEST); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5517 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5518 | if (!is_enabled) { |
| 5519 | DRM_DEBUG_KMS("Enabling power well\n"); |
| 5520 | if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) & |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5521 | HSW_PWR_WELL_STATE_ENABLED), 20)) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5522 | DRM_ERROR("Timeout enabling power well\n"); |
| 5523 | } |
Ben Widawsky | 596cc11 | 2013-11-11 14:46:28 -0800 | [diff] [blame] | 5524 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5525 | hsw_power_well_post_enable(dev_priv); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5526 | } else { |
| 5527 | if (enable_requested) { |
| 5528 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 5529 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5530 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 5531 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5532 | hsw_power_well_post_disable(dev_priv); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5533 | } |
| 5534 | } |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5535 | } |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5536 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5537 | static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 5538 | struct i915_power_well *power_well) |
| 5539 | { |
| 5540 | hsw_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 5541 | |
| 5542 | /* |
| 5543 | * We're taking over the BIOS, so clear any requests made by it since |
| 5544 | * the driver is in charge now. |
| 5545 | */ |
| 5546 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
| 5547 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 5548 | } |
| 5549 | |
| 5550 | static void hsw_power_well_enable(struct drm_i915_private *dev_priv, |
| 5551 | struct i915_power_well *power_well) |
| 5552 | { |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5553 | hsw_set_power_well(dev_priv, power_well, true); |
| 5554 | } |
| 5555 | |
| 5556 | static void hsw_power_well_disable(struct drm_i915_private *dev_priv, |
| 5557 | struct i915_power_well *power_well) |
| 5558 | { |
| 5559 | hsw_set_power_well(dev_priv, power_well, false); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5560 | } |
| 5561 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 5562 | static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv, |
| 5563 | struct i915_power_well *power_well) |
| 5564 | { |
| 5565 | } |
| 5566 | |
| 5567 | static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv, |
| 5568 | struct i915_power_well *power_well) |
| 5569 | { |
| 5570 | return true; |
| 5571 | } |
| 5572 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 5573 | static void vlv_set_power_well(struct drm_i915_private *dev_priv, |
| 5574 | struct i915_power_well *power_well, bool enable) |
| 5575 | { |
| 5576 | enum punit_power_well power_well_id = power_well->data; |
| 5577 | u32 mask; |
| 5578 | u32 state; |
| 5579 | u32 ctrl; |
| 5580 | |
| 5581 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 5582 | state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) : |
| 5583 | PUNIT_PWRGT_PWR_GATE(power_well_id); |
| 5584 | |
| 5585 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5586 | |
| 5587 | #define COND \ |
| 5588 | ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state) |
| 5589 | |
| 5590 | if (COND) |
| 5591 | goto out; |
| 5592 | |
| 5593 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL); |
| 5594 | ctrl &= ~mask; |
| 5595 | ctrl |= state; |
| 5596 | vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl); |
| 5597 | |
| 5598 | if (wait_for(COND, 100)) |
| 5599 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 5600 | state, |
| 5601 | vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL)); |
| 5602 | |
| 5603 | #undef COND |
| 5604 | |
| 5605 | out: |
| 5606 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5607 | } |
| 5608 | |
| 5609 | static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 5610 | struct i915_power_well *power_well) |
| 5611 | { |
| 5612 | vlv_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 5613 | } |
| 5614 | |
| 5615 | static void vlv_power_well_enable(struct drm_i915_private *dev_priv, |
| 5616 | struct i915_power_well *power_well) |
| 5617 | { |
| 5618 | vlv_set_power_well(dev_priv, power_well, true); |
| 5619 | } |
| 5620 | |
| 5621 | static void vlv_power_well_disable(struct drm_i915_private *dev_priv, |
| 5622 | struct i915_power_well *power_well) |
| 5623 | { |
| 5624 | vlv_set_power_well(dev_priv, power_well, false); |
| 5625 | } |
| 5626 | |
| 5627 | static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv, |
| 5628 | struct i915_power_well *power_well) |
| 5629 | { |
| 5630 | int power_well_id = power_well->data; |
| 5631 | bool enabled = false; |
| 5632 | u32 mask; |
| 5633 | u32 state; |
| 5634 | u32 ctrl; |
| 5635 | |
| 5636 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 5637 | ctrl = PUNIT_PWRGT_PWR_ON(power_well_id); |
| 5638 | |
| 5639 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5640 | |
| 5641 | state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask; |
| 5642 | /* |
| 5643 | * We only ever set the power-on and power-gate states, anything |
| 5644 | * else is unexpected. |
| 5645 | */ |
| 5646 | WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) && |
| 5647 | state != PUNIT_PWRGT_PWR_GATE(power_well_id)); |
| 5648 | if (state == ctrl) |
| 5649 | enabled = true; |
| 5650 | |
| 5651 | /* |
| 5652 | * A transient state at this point would mean some unexpected party |
| 5653 | * is poking at the power controls too. |
| 5654 | */ |
| 5655 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask; |
| 5656 | WARN_ON(ctrl != state); |
| 5657 | |
| 5658 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5659 | |
| 5660 | return enabled; |
| 5661 | } |
| 5662 | |
| 5663 | static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, |
| 5664 | struct i915_power_well *power_well) |
| 5665 | { |
| 5666 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 5667 | |
| 5668 | vlv_set_power_well(dev_priv, power_well, true); |
| 5669 | |
| 5670 | spin_lock_irq(&dev_priv->irq_lock); |
| 5671 | valleyview_enable_display_irqs(dev_priv); |
| 5672 | spin_unlock_irq(&dev_priv->irq_lock); |
| 5673 | |
| 5674 | /* |
| 5675 | * During driver initialization we need to defer enabling hotplug |
| 5676 | * processing until fbdev is set up. |
| 5677 | */ |
| 5678 | if (dev_priv->enable_hotplug_processing) |
| 5679 | intel_hpd_init(dev_priv->dev); |
| 5680 | |
| 5681 | i915_redisable_vga_power_on(dev_priv->dev); |
| 5682 | } |
| 5683 | |
| 5684 | static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv, |
| 5685 | struct i915_power_well *power_well) |
| 5686 | { |
| 5687 | struct drm_device *dev = dev_priv->dev; |
| 5688 | enum pipe pipe; |
| 5689 | |
| 5690 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 5691 | |
| 5692 | spin_lock_irq(&dev_priv->irq_lock); |
| 5693 | for_each_pipe(pipe) |
| 5694 | __intel_set_cpu_fifo_underrun_reporting(dev, pipe, false); |
| 5695 | |
| 5696 | valleyview_disable_display_irqs(dev_priv); |
| 5697 | spin_unlock_irq(&dev_priv->irq_lock); |
| 5698 | |
| 5699 | spin_lock_irq(&dev->vbl_lock); |
| 5700 | for_each_pipe(pipe) |
| 5701 | reset_vblank_counter(dev, pipe); |
| 5702 | spin_unlock_irq(&dev->vbl_lock); |
| 5703 | |
| 5704 | vlv_set_power_well(dev_priv, power_well, false); |
| 5705 | } |
| 5706 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 5707 | static void check_power_well_state(struct drm_i915_private *dev_priv, |
| 5708 | struct i915_power_well *power_well) |
| 5709 | { |
| 5710 | bool enabled = power_well->ops->is_enabled(dev_priv, power_well); |
| 5711 | |
| 5712 | if (power_well->always_on || !i915.disable_power_well) { |
| 5713 | if (!enabled) |
| 5714 | goto mismatch; |
| 5715 | |
| 5716 | return; |
| 5717 | } |
| 5718 | |
| 5719 | if (enabled != (power_well->count > 0)) |
| 5720 | goto mismatch; |
| 5721 | |
| 5722 | return; |
| 5723 | |
| 5724 | mismatch: |
| 5725 | WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n", |
| 5726 | power_well->name, power_well->always_on, enabled, |
| 5727 | power_well->count, i915.disable_power_well); |
| 5728 | } |
| 5729 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5730 | void intel_display_power_get(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5731 | enum intel_display_power_domain domain) |
| 5732 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5733 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5734 | struct i915_power_well *power_well; |
| 5735 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5736 | |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 5737 | intel_runtime_pm_get(dev_priv); |
| 5738 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5739 | power_domains = &dev_priv->power_domains; |
| 5740 | |
| 5741 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5742 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 5743 | for_each_power_well(i, power_well, BIT(domain), power_domains) { |
| 5744 | if (!power_well->count++) { |
| 5745 | DRM_DEBUG_KMS("enabling %s\n", power_well->name); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5746 | power_well->ops->enable(dev_priv, power_well); |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | check_power_well_state(dev_priv, power_well); |
| 5750 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5751 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5752 | power_domains->domain_use_count[domain]++; |
| 5753 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5754 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5755 | } |
| 5756 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5757 | void intel_display_power_put(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5758 | enum intel_display_power_domain domain) |
| 5759 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5760 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5761 | struct i915_power_well *power_well; |
| 5762 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5763 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5764 | power_domains = &dev_priv->power_domains; |
| 5765 | |
| 5766 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5767 | |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5768 | WARN_ON(!power_domains->domain_use_count[domain]); |
| 5769 | power_domains->domain_use_count[domain]--; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5770 | |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 5771 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 5772 | WARN_ON(!power_well->count); |
| 5773 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 5774 | if (!--power_well->count && i915.disable_power_well) { |
| 5775 | DRM_DEBUG_KMS("disabling %s\n", power_well->name); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5776 | power_well->ops->disable(dev_priv, power_well); |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | check_power_well_state(dev_priv, power_well); |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 5780 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5781 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5782 | mutex_unlock(&power_domains->lock); |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 5783 | |
| 5784 | intel_runtime_pm_put(dev_priv); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5785 | } |
| 5786 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5787 | static struct i915_power_domains *hsw_pwr; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5788 | |
| 5789 | /* Display audio driver power well request */ |
| 5790 | void i915_request_power_well(void) |
| 5791 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5792 | struct drm_i915_private *dev_priv; |
| 5793 | |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5794 | if (WARN_ON(!hsw_pwr)) |
| 5795 | return; |
| 5796 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5797 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 5798 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5799 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5800 | } |
| 5801 | EXPORT_SYMBOL_GPL(i915_request_power_well); |
| 5802 | |
| 5803 | /* Display audio driver power well release */ |
| 5804 | void i915_release_power_well(void) |
| 5805 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5806 | struct drm_i915_private *dev_priv; |
| 5807 | |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5808 | if (WARN_ON(!hsw_pwr)) |
| 5809 | return; |
| 5810 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5811 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 5812 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5813 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5814 | } |
| 5815 | EXPORT_SYMBOL_GPL(i915_release_power_well); |
| 5816 | |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 5817 | #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1) |
| 5818 | |
| 5819 | #define HSW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 5820 | BIT(POWER_DOMAIN_PIPE_A) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 5821 | BIT(POWER_DOMAIN_TRANSCODER_EDP) | \ |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5822 | BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \ |
| 5823 | BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \ |
| 5824 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 5825 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 5826 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 5827 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 5828 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 5829 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 5830 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 5831 | BIT(POWER_DOMAIN_INIT)) |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 5832 | #define HSW_DISPLAY_POWER_DOMAINS ( \ |
| 5833 | (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 5834 | BIT(POWER_DOMAIN_INIT)) |
| 5835 | |
| 5836 | #define BDW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 5837 | HSW_ALWAYS_ON_POWER_DOMAINS | \ |
| 5838 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER)) |
| 5839 | #define BDW_DISPLAY_POWER_DOMAINS ( \ |
| 5840 | (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 5841 | BIT(POWER_DOMAIN_INIT)) |
| 5842 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 5843 | #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT) |
| 5844 | #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK |
| 5845 | |
| 5846 | #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 5847 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 5848 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 5849 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 5850 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 5851 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
| 5852 | BIT(POWER_DOMAIN_INIT)) |
| 5853 | |
| 5854 | #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \ |
| 5855 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 5856 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 5857 | BIT(POWER_DOMAIN_INIT)) |
| 5858 | |
| 5859 | #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \ |
| 5860 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 5861 | BIT(POWER_DOMAIN_INIT)) |
| 5862 | |
| 5863 | #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \ |
| 5864 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 5865 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 5866 | BIT(POWER_DOMAIN_INIT)) |
| 5867 | |
| 5868 | #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \ |
| 5869 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 5870 | BIT(POWER_DOMAIN_INIT)) |
| 5871 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 5872 | static const struct i915_power_well_ops i9xx_always_on_power_well_ops = { |
| 5873 | .sync_hw = i9xx_always_on_power_well_noop, |
| 5874 | .enable = i9xx_always_on_power_well_noop, |
| 5875 | .disable = i9xx_always_on_power_well_noop, |
| 5876 | .is_enabled = i9xx_always_on_power_well_enabled, |
| 5877 | }; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5878 | |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 5879 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 5880 | { |
| 5881 | .name = "always-on", |
| 5882 | .always_on = 1, |
| 5883 | .domains = POWER_DOMAIN_MASK, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5884 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 5885 | }, |
| 5886 | }; |
| 5887 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5888 | static const struct i915_power_well_ops hsw_power_well_ops = { |
| 5889 | .sync_hw = hsw_power_well_sync_hw, |
| 5890 | .enable = hsw_power_well_enable, |
| 5891 | .disable = hsw_power_well_disable, |
| 5892 | .is_enabled = hsw_power_well_enabled, |
| 5893 | }; |
| 5894 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5895 | static struct i915_power_well hsw_power_wells[] = { |
| 5896 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5897 | .name = "always-on", |
| 5898 | .always_on = 1, |
| 5899 | .domains = HSW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5900 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5901 | }, |
| 5902 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5903 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 5904 | .domains = HSW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5905 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5906 | }, |
| 5907 | }; |
| 5908 | |
| 5909 | static struct i915_power_well bdw_power_wells[] = { |
| 5910 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5911 | .name = "always-on", |
| 5912 | .always_on = 1, |
| 5913 | .domains = BDW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5914 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5915 | }, |
| 5916 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5917 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 5918 | .domains = BDW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5919 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5920 | }, |
| 5921 | }; |
| 5922 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 5923 | static const struct i915_power_well_ops vlv_display_power_well_ops = { |
| 5924 | .sync_hw = vlv_power_well_sync_hw, |
| 5925 | .enable = vlv_display_power_well_enable, |
| 5926 | .disable = vlv_display_power_well_disable, |
| 5927 | .is_enabled = vlv_power_well_enabled, |
| 5928 | }; |
| 5929 | |
| 5930 | static const struct i915_power_well_ops vlv_dpio_power_well_ops = { |
| 5931 | .sync_hw = vlv_power_well_sync_hw, |
| 5932 | .enable = vlv_power_well_enable, |
| 5933 | .disable = vlv_power_well_disable, |
| 5934 | .is_enabled = vlv_power_well_enabled, |
| 5935 | }; |
| 5936 | |
| 5937 | static struct i915_power_well vlv_power_wells[] = { |
| 5938 | { |
| 5939 | .name = "always-on", |
| 5940 | .always_on = 1, |
| 5941 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 5942 | .ops = &i9xx_always_on_power_well_ops, |
| 5943 | }, |
| 5944 | { |
| 5945 | .name = "display", |
| 5946 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 5947 | .data = PUNIT_POWER_WELL_DISP2D, |
| 5948 | .ops = &vlv_display_power_well_ops, |
| 5949 | }, |
| 5950 | { |
| 5951 | .name = "dpio-common", |
| 5952 | .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS, |
| 5953 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
| 5954 | .ops = &vlv_dpio_power_well_ops, |
| 5955 | }, |
| 5956 | { |
| 5957 | .name = "dpio-tx-b-01", |
| 5958 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 5959 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 5960 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 5961 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 5962 | .ops = &vlv_dpio_power_well_ops, |
| 5963 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 5964 | }, |
| 5965 | { |
| 5966 | .name = "dpio-tx-b-23", |
| 5967 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 5968 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 5969 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 5970 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 5971 | .ops = &vlv_dpio_power_well_ops, |
| 5972 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 5973 | }, |
| 5974 | { |
| 5975 | .name = "dpio-tx-c-01", |
| 5976 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 5977 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 5978 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 5979 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 5980 | .ops = &vlv_dpio_power_well_ops, |
| 5981 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 5982 | }, |
| 5983 | { |
| 5984 | .name = "dpio-tx-c-23", |
| 5985 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 5986 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 5987 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 5988 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 5989 | .ops = &vlv_dpio_power_well_ops, |
| 5990 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 5991 | }, |
| 5992 | }; |
| 5993 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5994 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 5995 | (power_domains)->power_wells = (__power_wells); \ |
| 5996 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 5997 | }) |
| 5998 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5999 | int intel_power_domains_init(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6000 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6001 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6002 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6003 | mutex_init(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6004 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6005 | /* |
| 6006 | * The enabling order will be from lower to higher indexed wells, |
| 6007 | * the disabling order is reversed. |
| 6008 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6009 | if (IS_HASWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6010 | set_power_wells(power_domains, hsw_power_wells); |
| 6011 | hsw_pwr = power_domains; |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6012 | } else if (IS_BROADWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6013 | set_power_wells(power_domains, bdw_power_wells); |
| 6014 | hsw_pwr = power_domains; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6015 | } else if (IS_VALLEYVIEW(dev_priv->dev)) { |
| 6016 | set_power_wells(power_domains, vlv_power_wells); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6017 | } else { |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6018 | set_power_wells(power_domains, i9xx_always_on_power_well); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6019 | } |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6020 | |
| 6021 | return 0; |
| 6022 | } |
| 6023 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6024 | void intel_power_domains_remove(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6025 | { |
| 6026 | hsw_pwr = NULL; |
| 6027 | } |
| 6028 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6029 | static void intel_power_domains_resume(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 6030 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6031 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6032 | struct i915_power_well *power_well; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6033 | int i; |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 6034 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6035 | mutex_lock(&power_domains->lock); |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6036 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) |
| 6037 | power_well->ops->sync_hw(dev_priv, power_well); |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6038 | mutex_unlock(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6039 | } |
| 6040 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6041 | void intel_power_domains_init_hw(struct drm_i915_private *dev_priv) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6042 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6043 | /* For now, we need the power well to be always enabled. */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6044 | intel_display_set_init_power(dev_priv, true); |
| 6045 | intel_power_domains_resume(dev_priv); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6046 | } |
| 6047 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6048 | void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv) |
| 6049 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 6050 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv) |
| 6054 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 6055 | intel_runtime_pm_put(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6056 | } |
| 6057 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6058 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 6059 | { |
| 6060 | struct drm_device *dev = dev_priv->dev; |
| 6061 | struct device *device = &dev->pdev->dev; |
| 6062 | |
| 6063 | if (!HAS_RUNTIME_PM(dev)) |
| 6064 | return; |
| 6065 | |
| 6066 | pm_runtime_get_sync(device); |
| 6067 | WARN(dev_priv->pm.suspended, "Device still suspended.\n"); |
| 6068 | } |
| 6069 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6070 | void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv) |
| 6071 | { |
| 6072 | struct drm_device *dev = dev_priv->dev; |
| 6073 | struct device *device = &dev->pdev->dev; |
| 6074 | |
| 6075 | if (!HAS_RUNTIME_PM(dev)) |
| 6076 | return; |
| 6077 | |
| 6078 | WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n"); |
| 6079 | pm_runtime_get_noresume(device); |
| 6080 | } |
| 6081 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6082 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 6083 | { |
| 6084 | struct drm_device *dev = dev_priv->dev; |
| 6085 | struct device *device = &dev->pdev->dev; |
| 6086 | |
| 6087 | if (!HAS_RUNTIME_PM(dev)) |
| 6088 | return; |
| 6089 | |
| 6090 | pm_runtime_mark_last_busy(device); |
| 6091 | pm_runtime_put_autosuspend(device); |
| 6092 | } |
| 6093 | |
| 6094 | void intel_init_runtime_pm(struct drm_i915_private *dev_priv) |
| 6095 | { |
| 6096 | struct drm_device *dev = dev_priv->dev; |
| 6097 | struct device *device = &dev->pdev->dev; |
| 6098 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6099 | if (!HAS_RUNTIME_PM(dev)) |
| 6100 | return; |
| 6101 | |
| 6102 | pm_runtime_set_active(device); |
| 6103 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame^] | 6104 | /* |
| 6105 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 6106 | * requirement. |
| 6107 | */ |
| 6108 | if (!intel_enable_rc6(dev)) { |
| 6109 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 6110 | return; |
| 6111 | } |
| 6112 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6113 | pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */ |
| 6114 | pm_runtime_mark_last_busy(device); |
| 6115 | pm_runtime_use_autosuspend(device); |
Paulo Zanoni | ba0239e | 2014-03-07 20:08:07 -0300 | [diff] [blame] | 6116 | |
| 6117 | pm_runtime_put_autosuspend(device); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | void intel_fini_runtime_pm(struct drm_i915_private *dev_priv) |
| 6121 | { |
| 6122 | struct drm_device *dev = dev_priv->dev; |
| 6123 | struct device *device = &dev->pdev->dev; |
| 6124 | |
| 6125 | if (!HAS_RUNTIME_PM(dev)) |
| 6126 | return; |
| 6127 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame^] | 6128 | if (!intel_enable_rc6(dev)) |
| 6129 | return; |
| 6130 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6131 | /* Make sure we're not suspended first. */ |
| 6132 | pm_runtime_get_sync(device); |
| 6133 | pm_runtime_disable(device); |
| 6134 | } |
| 6135 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6136 | /* Set up chip specific power management-related functions */ |
| 6137 | void intel_init_pm(struct drm_device *dev) |
| 6138 | { |
| 6139 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6140 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 6141 | if (HAS_FBC(dev)) { |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6142 | if (INTEL_INFO(dev)->gen >= 7) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6143 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6144 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 6145 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6146 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 6147 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 6148 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6149 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6150 | } else if (IS_GM45(dev)) { |
| 6151 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 6152 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 6153 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6154 | } else { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6155 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 6156 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 6157 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 6158 | |
| 6159 | /* This value was pulled out of someone's hat */ |
| 6160 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6161 | } |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6162 | } |
| 6163 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6164 | /* For cxsr */ |
| 6165 | if (IS_PINEVIEW(dev)) |
| 6166 | i915_pineview_get_mem_freq(dev); |
| 6167 | else if (IS_GEN5(dev)) |
| 6168 | i915_ironlake_get_mem_freq(dev); |
| 6169 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6170 | /* For FIFO watermark updates */ |
| 6171 | if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6172 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6173 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6174 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6175 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6176 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6177 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6178 | dev_priv->display.update_wm = ilk_update_wm; |
| 6179 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6180 | } else { |
| 6181 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6182 | "Disable CxSR\n"); |
| 6183 | } |
| 6184 | |
| 6185 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6186 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6187 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6188 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6189 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6190 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6191 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6192 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6193 | else if (INTEL_INFO(dev)->gen == 8) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6194 | dev_priv->display.init_clock_gating = gen8_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6195 | } else if (IS_VALLEYVIEW(dev)) { |
| 6196 | dev_priv->display.update_wm = valleyview_update_wm; |
| 6197 | dev_priv->display.init_clock_gating = |
| 6198 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6199 | } else if (IS_PINEVIEW(dev)) { |
| 6200 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6201 | dev_priv->is_ddr3, |
| 6202 | dev_priv->fsb_freq, |
| 6203 | dev_priv->mem_freq)) { |
| 6204 | DRM_INFO("failed to find known CxSR latency " |
| 6205 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6206 | "disabling CxSR\n", |
| 6207 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6208 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6209 | /* Disable CxSR and never update its watermark again */ |
| 6210 | pineview_disable_cxsr(dev); |
| 6211 | dev_priv->display.update_wm = NULL; |
| 6212 | } else |
| 6213 | dev_priv->display.update_wm = pineview_update_wm; |
| 6214 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6215 | } else if (IS_G4X(dev)) { |
| 6216 | dev_priv->display.update_wm = g4x_update_wm; |
| 6217 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6218 | } else if (IS_GEN4(dev)) { |
| 6219 | dev_priv->display.update_wm = i965_update_wm; |
| 6220 | if (IS_CRESTLINE(dev)) |
| 6221 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6222 | else if (IS_BROADWATER(dev)) |
| 6223 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6224 | } else if (IS_GEN3(dev)) { |
| 6225 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6226 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6227 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6228 | } else if (IS_GEN2(dev)) { |
| 6229 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6230 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6231 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6232 | } else { |
| 6233 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6234 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6235 | } |
| 6236 | |
| 6237 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6238 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6239 | else |
| 6240 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6241 | } else { |
| 6242 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6243 | } |
| 6244 | } |
| 6245 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6246 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 6247 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6248 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6249 | |
| 6250 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6251 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6252 | return -EAGAIN; |
| 6253 | } |
| 6254 | |
| 6255 | I915_WRITE(GEN6_PCODE_DATA, *val); |
| 6256 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6257 | |
| 6258 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6259 | 500)) { |
| 6260 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6261 | return -ETIMEDOUT; |
| 6262 | } |
| 6263 | |
| 6264 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6265 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6266 | |
| 6267 | return 0; |
| 6268 | } |
| 6269 | |
| 6270 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 6271 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6272 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6273 | |
| 6274 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6275 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6276 | return -EAGAIN; |
| 6277 | } |
| 6278 | |
| 6279 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6280 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6281 | |
| 6282 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6283 | 500)) { |
| 6284 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6285 | return -ETIMEDOUT; |
| 6286 | } |
| 6287 | |
| 6288 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6289 | |
| 6290 | return 0; |
| 6291 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6292 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6293 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6294 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6295 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6296 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6297 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6298 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6299 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6300 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6301 | break; |
| 6302 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6303 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6304 | break; |
| 6305 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6306 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6307 | break; |
| 6308 | default: |
| 6309 | return -1; |
| 6310 | } |
| 6311 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6312 | return DIV_ROUND_CLOSEST(dev_priv->mem_freq * (val + 6 - 0xbd), 4 * div); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6313 | } |
| 6314 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6315 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6316 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6317 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6318 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6319 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6320 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6321 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6322 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6323 | break; |
| 6324 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6325 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6326 | break; |
| 6327 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6328 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6329 | break; |
| 6330 | default: |
| 6331 | return -1; |
| 6332 | } |
| 6333 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6334 | return DIV_ROUND_CLOSEST(4 * mul * val, dev_priv->mem_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6335 | } |
| 6336 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6337 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6338 | { |
| 6339 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6340 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6341 | mutex_init(&dev_priv->rps.hw_lock); |
| 6342 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6343 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6344 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6345 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6346 | dev_priv->pm.suspended = false; |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6347 | dev_priv->pm.irqs_disabled = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6348 | } |