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; |
| 95 | struct drm_framebuffer *fb = crtc->fb; |
| 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; |
| 100 | int plane, 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 | plane = intel_crtc->plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB; |
| 113 | |
| 114 | /* Clear old tags */ |
| 115 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 116 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 117 | |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 118 | if (IS_GEN4(dev)) { |
| 119 | u32 fbc_ctl2; |
| 120 | |
| 121 | /* Set it up... */ |
| 122 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
| 123 | fbc_ctl2 |= plane; |
| 124 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 125 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 126 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 127 | |
| 128 | /* enable it... */ |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 129 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 130 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 131 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 132 | if (IS_I945GM(dev)) |
| 133 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 134 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 135 | fbc_ctl |= obj->fence_reg; |
| 136 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 137 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 138 | DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %c, ", |
| 139 | cfb_pitch, crtc->y, plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 140 | } |
| 141 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 142 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 143 | { |
| 144 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 145 | |
| 146 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 147 | } |
| 148 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 149 | static void g4x_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 150 | { |
| 151 | struct drm_device *dev = crtc->dev; |
| 152 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 153 | struct drm_framebuffer *fb = crtc->fb; |
| 154 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 155 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 156 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 157 | int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 158 | u32 dpfc_ctl; |
| 159 | |
| 160 | dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X; |
| 161 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 162 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 163 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 164 | |
| 165 | /* enable it... */ |
| 166 | I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN); |
| 167 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 168 | 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] | 169 | } |
| 170 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 171 | static void g4x_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 172 | { |
| 173 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 174 | u32 dpfc_ctl; |
| 175 | |
| 176 | /* Disable compression */ |
| 177 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 178 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 179 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 180 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 181 | |
| 182 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 183 | } |
| 184 | } |
| 185 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 186 | static bool g4x_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 187 | { |
| 188 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 189 | |
| 190 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 191 | } |
| 192 | |
| 193 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 194 | { |
| 195 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 196 | u32 blt_ecoskpd; |
| 197 | |
| 198 | /* Make sure blitter notifies FBC of writes */ |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 199 | |
| 200 | /* Blitter is part of Media powerwell on VLV. No impact of |
| 201 | * his param in other platforms for now */ |
| 202 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 203 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 204 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 205 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 206 | GEN6_BLITTER_LOCK_SHIFT; |
| 207 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 208 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 209 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 210 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 211 | GEN6_BLITTER_LOCK_SHIFT); |
| 212 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 213 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 214 | |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 215 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_MEDIA); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 216 | } |
| 217 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 218 | static void ironlake_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 219 | { |
| 220 | struct drm_device *dev = crtc->dev; |
| 221 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 222 | struct drm_framebuffer *fb = crtc->fb; |
| 223 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 224 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 225 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 226 | int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 227 | u32 dpfc_ctl; |
| 228 | |
| 229 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 230 | dpfc_ctl &= DPFC_RESERVED; |
| 231 | dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X); |
Ville Syrjälä | d629336 | 2013-11-21 21:29:45 +0200 | [diff] [blame] | 232 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
| 233 | if (IS_GEN5(dev)) |
| 234 | dpfc_ctl |= obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 235 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 236 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 237 | 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] | 238 | /* enable it... */ |
| 239 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 240 | |
| 241 | if (IS_GEN6(dev)) { |
| 242 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 243 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 244 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 245 | sandybridge_blit_fbc_update(dev); |
| 246 | } |
| 247 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 248 | 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] | 249 | } |
| 250 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 251 | static void ironlake_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 252 | { |
| 253 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 254 | u32 dpfc_ctl; |
| 255 | |
| 256 | /* Disable compression */ |
| 257 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 258 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 259 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 260 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 261 | |
| 262 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 263 | } |
| 264 | } |
| 265 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 266 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 267 | { |
| 268 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 269 | |
| 270 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 271 | } |
| 272 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 273 | static void gen7_enable_fbc(struct drm_crtc *crtc) |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 274 | { |
| 275 | struct drm_device *dev = crtc->dev; |
| 276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 277 | struct drm_framebuffer *fb = crtc->fb; |
| 278 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 279 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 280 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 281 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 282 | I915_WRITE(ILK_DPFC_CONTROL, DPFC_CTL_EN | DPFC_CTL_LIMIT_1X | |
| 283 | IVB_DPFC_CTL_FENCE_EN | |
| 284 | intel_crtc->plane << IVB_DPFC_CTL_PLANE_SHIFT); |
| 285 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 286 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 287 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 288 | I915_WRITE(ILK_DISPLAY_CHICKEN1, ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 289 | } else { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 290 | /* WaFbcAsynchFlipDisableFbcQueue:hsw */ |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 291 | I915_WRITE(HSW_PIPE_SLICE_CHICKEN_1(intel_crtc->pipe), |
| 292 | HSW_BYPASS_FBC_QUEUE); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 293 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 294 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 295 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 296 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 297 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 298 | |
| 299 | sandybridge_blit_fbc_update(dev); |
| 300 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 301 | 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] | 302 | } |
| 303 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 304 | bool intel_fbc_enabled(struct drm_device *dev) |
| 305 | { |
| 306 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 307 | |
| 308 | if (!dev_priv->display.fbc_enabled) |
| 309 | return false; |
| 310 | |
| 311 | return dev_priv->display.fbc_enabled(dev); |
| 312 | } |
| 313 | |
| 314 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 315 | { |
| 316 | struct intel_fbc_work *work = |
| 317 | container_of(to_delayed_work(__work), |
| 318 | struct intel_fbc_work, work); |
| 319 | struct drm_device *dev = work->crtc->dev; |
| 320 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 321 | |
| 322 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 323 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 324 | /* Double check that we haven't switched fb without cancelling |
| 325 | * the prior work. |
| 326 | */ |
| 327 | if (work->crtc->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 328 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 329 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 330 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
| 331 | dev_priv->fbc.fb_id = work->crtc->fb->base.id; |
| 332 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 333 | } |
| 334 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 335 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 336 | } |
| 337 | mutex_unlock(&dev->struct_mutex); |
| 338 | |
| 339 | kfree(work); |
| 340 | } |
| 341 | |
| 342 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 343 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 344 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 345 | return; |
| 346 | |
| 347 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 348 | |
| 349 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 350 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 351 | * entirely asynchronously. |
| 352 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 353 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 354 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 355 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 356 | |
| 357 | /* Mark the work as no longer wanted so that if it does |
| 358 | * wake-up (because the work was already running and waiting |
| 359 | * for our mutex), it will discover that is no longer |
| 360 | * necessary to run. |
| 361 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 362 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 363 | } |
| 364 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 365 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 366 | { |
| 367 | struct intel_fbc_work *work; |
| 368 | struct drm_device *dev = crtc->dev; |
| 369 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 370 | |
| 371 | if (!dev_priv->display.enable_fbc) |
| 372 | return; |
| 373 | |
| 374 | intel_cancel_fbc_work(dev_priv); |
| 375 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 376 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 377 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 378 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 379 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 380 | return; |
| 381 | } |
| 382 | |
| 383 | work->crtc = crtc; |
| 384 | work->fb = crtc->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 385 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 386 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 387 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 388 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 389 | /* Delay the actual enabling to let pageflipping cease and the |
| 390 | * display to settle before starting the compression. Note that |
| 391 | * this delay also serves a second purpose: it allows for a |
| 392 | * vblank to pass after disabling the FBC before we attempt |
| 393 | * to modify the control registers. |
| 394 | * |
| 395 | * A more complicated solution would involve tracking vblanks |
| 396 | * following the termination of the page-flipping sequence |
| 397 | * and indeed performing the enable as a co-routine and not |
| 398 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 399 | * |
| 400 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 401 | */ |
| 402 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 403 | } |
| 404 | |
| 405 | void intel_disable_fbc(struct drm_device *dev) |
| 406 | { |
| 407 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 408 | |
| 409 | intel_cancel_fbc_work(dev_priv); |
| 410 | |
| 411 | if (!dev_priv->display.disable_fbc) |
| 412 | return; |
| 413 | |
| 414 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 415 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 416 | } |
| 417 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 418 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 419 | enum no_fbc_reason reason) |
| 420 | { |
| 421 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 422 | return false; |
| 423 | |
| 424 | dev_priv->fbc.no_fbc_reason = reason; |
| 425 | return true; |
| 426 | } |
| 427 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 428 | /** |
| 429 | * intel_update_fbc - enable/disable FBC as needed |
| 430 | * @dev: the drm_device |
| 431 | * |
| 432 | * Set up the framebuffer compression hardware at mode set time. We |
| 433 | * enable it if possible: |
| 434 | * - plane A only (on pre-965) |
| 435 | * - no pixel mulitply/line duplication |
| 436 | * - no alpha buffer discard |
| 437 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 438 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 439 | * |
| 440 | * We can't assume that any compression will take place (worst case), |
| 441 | * so the compressed buffer has to be the same size as the uncompressed |
| 442 | * one. It also must reside (along with the line length buffer) in |
| 443 | * stolen memory. |
| 444 | * |
| 445 | * We need to enable/disable FBC on a global basis. |
| 446 | */ |
| 447 | void intel_update_fbc(struct drm_device *dev) |
| 448 | { |
| 449 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 450 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 451 | struct intel_crtc *intel_crtc; |
| 452 | struct drm_framebuffer *fb; |
| 453 | struct intel_framebuffer *intel_fb; |
| 454 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 455 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 456 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 457 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 458 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 459 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 460 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 461 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 462 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 463 | if (!i915_powersave) { |
| 464 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 465 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 466 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 467 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 468 | |
| 469 | /* |
| 470 | * If FBC is already on, we just have to verify that we can |
| 471 | * keep it that way... |
| 472 | * Need to disable if: |
| 473 | * - more than one pipe is active |
| 474 | * - changing FBC params (stride, fence, mode) |
| 475 | * - new fb is too large to fit in compressed buffer |
| 476 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 477 | */ |
| 478 | list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 479 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 480 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 481 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 482 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 483 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 484 | goto out_disable; |
| 485 | } |
| 486 | crtc = tmp_crtc; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | if (!crtc || crtc->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 491 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 492 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 493 | goto out_disable; |
| 494 | } |
| 495 | |
| 496 | intel_crtc = to_intel_crtc(crtc); |
| 497 | fb = crtc->fb; |
| 498 | intel_fb = to_intel_framebuffer(fb); |
| 499 | obj = intel_fb->obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 500 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 501 | |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 502 | if (i915_enable_fbc < 0 && |
| 503 | INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 504 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 505 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 506 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 507 | } |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 508 | if (!i915_enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 509 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 510 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 511 | goto out_disable; |
| 512 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 513 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 514 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 515 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 516 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 517 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 518 | goto out_disable; |
| 519 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 520 | |
| 521 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 522 | max_width = 4096; |
| 523 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 524 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 525 | max_width = 2048; |
| 526 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 527 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 528 | if (intel_crtc->config.pipe_src_w > max_width || |
| 529 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 530 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 531 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 532 | goto out_disable; |
| 533 | } |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 534 | if ((INTEL_INFO(dev)->gen < 4 || IS_HASWELL(dev)) && |
| 535 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 536 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 537 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 538 | goto out_disable; |
| 539 | } |
| 540 | |
| 541 | /* The use of a CPU fence is mandatory in order to detect writes |
| 542 | * by the CPU to the scanout and trigger updates to the FBC. |
| 543 | */ |
| 544 | if (obj->tiling_mode != I915_TILING_X || |
| 545 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 546 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 547 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 548 | goto out_disable; |
| 549 | } |
| 550 | |
| 551 | /* If the kernel debugger is active, always disable compression */ |
| 552 | if (in_dbg_master()) |
| 553 | goto out_disable; |
| 554 | |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 555 | if (i915_gem_stolen_setup_compression(dev, intel_fb->obj->base.size)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 556 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 557 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 558 | goto out_disable; |
| 559 | } |
| 560 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 561 | /* If the scanout has not changed, don't modify the FBC settings. |
| 562 | * Note that we make the fundamental assumption that the fb->obj |
| 563 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 564 | * without first being decoupled from the scanout and FBC disabled. |
| 565 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 566 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 567 | dev_priv->fbc.fb_id == fb->base.id && |
| 568 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 569 | return; |
| 570 | |
| 571 | if (intel_fbc_enabled(dev)) { |
| 572 | /* We update FBC along two paths, after changing fb/crtc |
| 573 | * configuration (modeswitching) and after page-flipping |
| 574 | * finishes. For the latter, we know that not only did |
| 575 | * we disable the FBC at the start of the page-flip |
| 576 | * sequence, but also more than one vblank has passed. |
| 577 | * |
| 578 | * For the former case of modeswitching, it is possible |
| 579 | * to switch between two FBC valid configurations |
| 580 | * instantaneously so we do need to disable the FBC |
| 581 | * before we can modify its control registers. We also |
| 582 | * have to wait for the next vblank for that to take |
| 583 | * effect. However, since we delay enabling FBC we can |
| 584 | * assume that a vblank has passed since disabling and |
| 585 | * that we can safely alter the registers in the deferred |
| 586 | * callback. |
| 587 | * |
| 588 | * In the scenario that we go from a valid to invalid |
| 589 | * and then back to valid FBC configuration we have |
| 590 | * no strict enforcement that a vblank occurred since |
| 591 | * disabling the FBC. However, along all current pipe |
| 592 | * disabling paths we do need to wait for a vblank at |
| 593 | * some point. And we wait before enabling FBC anyway. |
| 594 | */ |
| 595 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 596 | intel_disable_fbc(dev); |
| 597 | } |
| 598 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 599 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 600 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 601 | return; |
| 602 | |
| 603 | out_disable: |
| 604 | /* Multiple disables should be harmless */ |
| 605 | if (intel_fbc_enabled(dev)) { |
| 606 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 607 | intel_disable_fbc(dev); |
| 608 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 609 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 610 | } |
| 611 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 612 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 613 | { |
| 614 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 615 | u32 tmp; |
| 616 | |
| 617 | tmp = I915_READ(CLKCFG); |
| 618 | |
| 619 | switch (tmp & CLKCFG_FSB_MASK) { |
| 620 | case CLKCFG_FSB_533: |
| 621 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 622 | break; |
| 623 | case CLKCFG_FSB_800: |
| 624 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 625 | break; |
| 626 | case CLKCFG_FSB_667: |
| 627 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 628 | break; |
| 629 | case CLKCFG_FSB_400: |
| 630 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 631 | break; |
| 632 | } |
| 633 | |
| 634 | switch (tmp & CLKCFG_MEM_MASK) { |
| 635 | case CLKCFG_MEM_533: |
| 636 | dev_priv->mem_freq = 533; |
| 637 | break; |
| 638 | case CLKCFG_MEM_667: |
| 639 | dev_priv->mem_freq = 667; |
| 640 | break; |
| 641 | case CLKCFG_MEM_800: |
| 642 | dev_priv->mem_freq = 800; |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | /* detect pineview DDR3 setting */ |
| 647 | tmp = I915_READ(CSHRDDR3CTL); |
| 648 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 649 | } |
| 650 | |
| 651 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 652 | { |
| 653 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 654 | u16 ddrpll, csipll; |
| 655 | |
| 656 | ddrpll = I915_READ16(DDRMPLL1); |
| 657 | csipll = I915_READ16(CSIPLL0); |
| 658 | |
| 659 | switch (ddrpll & 0xff) { |
| 660 | case 0xc: |
| 661 | dev_priv->mem_freq = 800; |
| 662 | break; |
| 663 | case 0x10: |
| 664 | dev_priv->mem_freq = 1066; |
| 665 | break; |
| 666 | case 0x14: |
| 667 | dev_priv->mem_freq = 1333; |
| 668 | break; |
| 669 | case 0x18: |
| 670 | dev_priv->mem_freq = 1600; |
| 671 | break; |
| 672 | default: |
| 673 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 674 | ddrpll & 0xff); |
| 675 | dev_priv->mem_freq = 0; |
| 676 | break; |
| 677 | } |
| 678 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 679 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 680 | |
| 681 | switch (csipll & 0x3ff) { |
| 682 | case 0x00c: |
| 683 | dev_priv->fsb_freq = 3200; |
| 684 | break; |
| 685 | case 0x00e: |
| 686 | dev_priv->fsb_freq = 3733; |
| 687 | break; |
| 688 | case 0x010: |
| 689 | dev_priv->fsb_freq = 4266; |
| 690 | break; |
| 691 | case 0x012: |
| 692 | dev_priv->fsb_freq = 4800; |
| 693 | break; |
| 694 | case 0x014: |
| 695 | dev_priv->fsb_freq = 5333; |
| 696 | break; |
| 697 | case 0x016: |
| 698 | dev_priv->fsb_freq = 5866; |
| 699 | break; |
| 700 | case 0x018: |
| 701 | dev_priv->fsb_freq = 6400; |
| 702 | break; |
| 703 | default: |
| 704 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 705 | csipll & 0x3ff); |
| 706 | dev_priv->fsb_freq = 0; |
| 707 | break; |
| 708 | } |
| 709 | |
| 710 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 711 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 712 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 713 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 714 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 715 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 719 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 720 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 721 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 722 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 723 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 724 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 725 | |
| 726 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 727 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 728 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 729 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 730 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 731 | |
| 732 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 733 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 734 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 735 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 736 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 737 | |
| 738 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 739 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 740 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 741 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 742 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 743 | |
| 744 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 745 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 746 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 747 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 748 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 749 | |
| 750 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 751 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 752 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 753 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 754 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 755 | }; |
| 756 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 757 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 758 | int is_ddr3, |
| 759 | int fsb, |
| 760 | int mem) |
| 761 | { |
| 762 | const struct cxsr_latency *latency; |
| 763 | int i; |
| 764 | |
| 765 | if (fsb == 0 || mem == 0) |
| 766 | return NULL; |
| 767 | |
| 768 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 769 | latency = &cxsr_latency_table[i]; |
| 770 | if (is_desktop == latency->is_desktop && |
| 771 | is_ddr3 == latency->is_ddr3 && |
| 772 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 773 | return latency; |
| 774 | } |
| 775 | |
| 776 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 777 | |
| 778 | return NULL; |
| 779 | } |
| 780 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 781 | static void pineview_disable_cxsr(struct drm_device *dev) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 782 | { |
| 783 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 784 | |
| 785 | /* deactivate cxsr */ |
| 786 | I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN); |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | * Latency for FIFO fetches is dependent on several factors: |
| 791 | * - memory configuration (speed, channels) |
| 792 | * - chipset |
| 793 | * - current MCH state |
| 794 | * It can be fairly high in some situations, so here we assume a fairly |
| 795 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 796 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 797 | * and power consumption (set it too low to save power and we might see |
| 798 | * FIFO underruns and display "flicker"). |
| 799 | * |
| 800 | * A value of 5us seems to be a good balance; safe for very low end |
| 801 | * platforms but not overly aggressive on lower latency configs. |
| 802 | */ |
| 803 | static const int latency_ns = 5000; |
| 804 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 805 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 806 | { |
| 807 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 808 | uint32_t dsparb = I915_READ(DSPARB); |
| 809 | int size; |
| 810 | |
| 811 | size = dsparb & 0x7f; |
| 812 | if (plane) |
| 813 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 814 | |
| 815 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 816 | plane ? "B" : "A", size); |
| 817 | |
| 818 | return size; |
| 819 | } |
| 820 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 821 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 822 | { |
| 823 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 824 | uint32_t dsparb = I915_READ(DSPARB); |
| 825 | int size; |
| 826 | |
| 827 | size = dsparb & 0x1ff; |
| 828 | if (plane) |
| 829 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 830 | size >>= 1; /* Convert to cachelines */ |
| 831 | |
| 832 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 833 | plane ? "B" : "A", size); |
| 834 | |
| 835 | return size; |
| 836 | } |
| 837 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 838 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 839 | { |
| 840 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 841 | uint32_t dsparb = I915_READ(DSPARB); |
| 842 | int size; |
| 843 | |
| 844 | size = dsparb & 0x7f; |
| 845 | size >>= 2; /* Convert to cachelines */ |
| 846 | |
| 847 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 848 | plane ? "B" : "A", |
| 849 | size); |
| 850 | |
| 851 | return size; |
| 852 | } |
| 853 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 854 | /* Pineview has different values for various configs */ |
| 855 | static const struct intel_watermark_params pineview_display_wm = { |
| 856 | PINEVIEW_DISPLAY_FIFO, |
| 857 | PINEVIEW_MAX_WM, |
| 858 | PINEVIEW_DFT_WM, |
| 859 | PINEVIEW_GUARD_WM, |
| 860 | PINEVIEW_FIFO_LINE_SIZE |
| 861 | }; |
| 862 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
| 863 | PINEVIEW_DISPLAY_FIFO, |
| 864 | PINEVIEW_MAX_WM, |
| 865 | PINEVIEW_DFT_HPLLOFF_WM, |
| 866 | PINEVIEW_GUARD_WM, |
| 867 | PINEVIEW_FIFO_LINE_SIZE |
| 868 | }; |
| 869 | static const struct intel_watermark_params pineview_cursor_wm = { |
| 870 | PINEVIEW_CURSOR_FIFO, |
| 871 | PINEVIEW_CURSOR_MAX_WM, |
| 872 | PINEVIEW_CURSOR_DFT_WM, |
| 873 | PINEVIEW_CURSOR_GUARD_WM, |
| 874 | PINEVIEW_FIFO_LINE_SIZE, |
| 875 | }; |
| 876 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
| 877 | PINEVIEW_CURSOR_FIFO, |
| 878 | PINEVIEW_CURSOR_MAX_WM, |
| 879 | PINEVIEW_CURSOR_DFT_WM, |
| 880 | PINEVIEW_CURSOR_GUARD_WM, |
| 881 | PINEVIEW_FIFO_LINE_SIZE |
| 882 | }; |
| 883 | static const struct intel_watermark_params g4x_wm_info = { |
| 884 | G4X_FIFO_SIZE, |
| 885 | G4X_MAX_WM, |
| 886 | G4X_MAX_WM, |
| 887 | 2, |
| 888 | G4X_FIFO_LINE_SIZE, |
| 889 | }; |
| 890 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
| 891 | I965_CURSOR_FIFO, |
| 892 | I965_CURSOR_MAX_WM, |
| 893 | I965_CURSOR_DFT_WM, |
| 894 | 2, |
| 895 | G4X_FIFO_LINE_SIZE, |
| 896 | }; |
| 897 | static const struct intel_watermark_params valleyview_wm_info = { |
| 898 | VALLEYVIEW_FIFO_SIZE, |
| 899 | VALLEYVIEW_MAX_WM, |
| 900 | VALLEYVIEW_MAX_WM, |
| 901 | 2, |
| 902 | G4X_FIFO_LINE_SIZE, |
| 903 | }; |
| 904 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
| 905 | I965_CURSOR_FIFO, |
| 906 | VALLEYVIEW_CURSOR_MAX_WM, |
| 907 | I965_CURSOR_DFT_WM, |
| 908 | 2, |
| 909 | G4X_FIFO_LINE_SIZE, |
| 910 | }; |
| 911 | static const struct intel_watermark_params i965_cursor_wm_info = { |
| 912 | I965_CURSOR_FIFO, |
| 913 | I965_CURSOR_MAX_WM, |
| 914 | I965_CURSOR_DFT_WM, |
| 915 | 2, |
| 916 | I915_FIFO_LINE_SIZE, |
| 917 | }; |
| 918 | static const struct intel_watermark_params i945_wm_info = { |
| 919 | I945_FIFO_SIZE, |
| 920 | I915_MAX_WM, |
| 921 | 1, |
| 922 | 2, |
| 923 | I915_FIFO_LINE_SIZE |
| 924 | }; |
| 925 | static const struct intel_watermark_params i915_wm_info = { |
| 926 | I915_FIFO_SIZE, |
| 927 | I915_MAX_WM, |
| 928 | 1, |
| 929 | 2, |
| 930 | I915_FIFO_LINE_SIZE |
| 931 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 932 | static const struct intel_watermark_params i830_wm_info = { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 933 | I855GM_FIFO_SIZE, |
| 934 | I915_MAX_WM, |
| 935 | 1, |
| 936 | 2, |
| 937 | I830_FIFO_LINE_SIZE |
| 938 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 939 | static const struct intel_watermark_params i845_wm_info = { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 940 | I830_FIFO_SIZE, |
| 941 | I915_MAX_WM, |
| 942 | 1, |
| 943 | 2, |
| 944 | I830_FIFO_LINE_SIZE |
| 945 | }; |
| 946 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 947 | /** |
| 948 | * intel_calculate_wm - calculate watermark level |
| 949 | * @clock_in_khz: pixel clock |
| 950 | * @wm: chip FIFO params |
| 951 | * @pixel_size: display pixel size |
| 952 | * @latency_ns: memory latency for the platform |
| 953 | * |
| 954 | * Calculate the watermark level (the level at which the display plane will |
| 955 | * start fetching from memory again). Each chip has a different display |
| 956 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 957 | * in the correct intel_watermark_params structure. |
| 958 | * |
| 959 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 960 | * on the pixel size. When it reaches the watermark level, it'll start |
| 961 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 962 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 963 | * will occur, and a display engine hang could result. |
| 964 | */ |
| 965 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 966 | const struct intel_watermark_params *wm, |
| 967 | int fifo_size, |
| 968 | int pixel_size, |
| 969 | unsigned long latency_ns) |
| 970 | { |
| 971 | long entries_required, wm_size; |
| 972 | |
| 973 | /* |
| 974 | * Note: we need to make sure we don't overflow for various clock & |
| 975 | * latency values. |
| 976 | * clocks go from a few thousand to several hundred thousand. |
| 977 | * latency is usually a few thousand |
| 978 | */ |
| 979 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 980 | 1000; |
| 981 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 982 | |
| 983 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 984 | |
| 985 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 986 | |
| 987 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 988 | |
| 989 | /* Don't promote wm_size to unsigned... */ |
| 990 | if (wm_size > (long)wm->max_wm) |
| 991 | wm_size = wm->max_wm; |
| 992 | if (wm_size <= 0) |
| 993 | wm_size = wm->default_wm; |
| 994 | return wm_size; |
| 995 | } |
| 996 | |
| 997 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 998 | { |
| 999 | struct drm_crtc *crtc, *enabled = NULL; |
| 1000 | |
| 1001 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1002 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1003 | if (enabled) |
| 1004 | return NULL; |
| 1005 | enabled = crtc; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | return enabled; |
| 1010 | } |
| 1011 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1012 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1013 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1014 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1015 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1016 | struct drm_crtc *crtc; |
| 1017 | const struct cxsr_latency *latency; |
| 1018 | u32 reg; |
| 1019 | unsigned long wm; |
| 1020 | |
| 1021 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1022 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1023 | if (!latency) { |
| 1024 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 1025 | pineview_disable_cxsr(dev); |
| 1026 | return; |
| 1027 | } |
| 1028 | |
| 1029 | crtc = single_enabled_crtc(dev); |
| 1030 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1031 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1032 | int pixel_size = crtc->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1033 | int clock; |
| 1034 | |
| 1035 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1036 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1037 | |
| 1038 | /* Display SR */ |
| 1039 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1040 | pineview_display_wm.fifo_size, |
| 1041 | pixel_size, latency->display_sr); |
| 1042 | reg = I915_READ(DSPFW1); |
| 1043 | reg &= ~DSPFW_SR_MASK; |
| 1044 | reg |= wm << DSPFW_SR_SHIFT; |
| 1045 | I915_WRITE(DSPFW1, reg); |
| 1046 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1047 | |
| 1048 | /* cursor SR */ |
| 1049 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1050 | pineview_display_wm.fifo_size, |
| 1051 | pixel_size, latency->cursor_sr); |
| 1052 | reg = I915_READ(DSPFW3); |
| 1053 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1054 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1055 | I915_WRITE(DSPFW3, reg); |
| 1056 | |
| 1057 | /* Display HPLL off SR */ |
| 1058 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1059 | pineview_display_hplloff_wm.fifo_size, |
| 1060 | pixel_size, latency->display_hpll_disable); |
| 1061 | reg = I915_READ(DSPFW3); |
| 1062 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1063 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1064 | I915_WRITE(DSPFW3, reg); |
| 1065 | |
| 1066 | /* cursor HPLL off SR */ |
| 1067 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1068 | pineview_display_hplloff_wm.fifo_size, |
| 1069 | pixel_size, latency->cursor_hpll_disable); |
| 1070 | reg = I915_READ(DSPFW3); |
| 1071 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1072 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1073 | I915_WRITE(DSPFW3, reg); |
| 1074 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1075 | |
| 1076 | /* activate cxsr */ |
| 1077 | I915_WRITE(DSPFW3, |
| 1078 | I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN); |
| 1079 | DRM_DEBUG_KMS("Self-refresh is enabled\n"); |
| 1080 | } else { |
| 1081 | pineview_disable_cxsr(dev); |
| 1082 | DRM_DEBUG_KMS("Self-refresh is disabled\n"); |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1087 | int plane, |
| 1088 | const struct intel_watermark_params *display, |
| 1089 | int display_latency_ns, |
| 1090 | const struct intel_watermark_params *cursor, |
| 1091 | int cursor_latency_ns, |
| 1092 | int *plane_wm, |
| 1093 | int *cursor_wm) |
| 1094 | { |
| 1095 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1096 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1097 | int htotal, hdisplay, clock, pixel_size; |
| 1098 | int line_time_us, line_count; |
| 1099 | int entries, tlb_miss; |
| 1100 | |
| 1101 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1102 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1103 | *cursor_wm = cursor->guard_size; |
| 1104 | *plane_wm = display->guard_size; |
| 1105 | return false; |
| 1106 | } |
| 1107 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1108 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1109 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1110 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1111 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1112 | pixel_size = crtc->fb->bits_per_pixel / 8; |
| 1113 | |
| 1114 | /* Use the small buffer method to calculate plane watermark */ |
| 1115 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1116 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1117 | if (tlb_miss > 0) |
| 1118 | entries += tlb_miss; |
| 1119 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1120 | *plane_wm = entries + display->guard_size; |
| 1121 | if (*plane_wm > (int)display->max_wm) |
| 1122 | *plane_wm = display->max_wm; |
| 1123 | |
| 1124 | /* Use the large buffer method to calculate cursor watermark */ |
| 1125 | line_time_us = ((htotal * 1000) / clock); |
| 1126 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
| 1127 | entries = line_count * 64 * pixel_size; |
| 1128 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1129 | if (tlb_miss > 0) |
| 1130 | entries += tlb_miss; |
| 1131 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1132 | *cursor_wm = entries + cursor->guard_size; |
| 1133 | if (*cursor_wm > (int)cursor->max_wm) |
| 1134 | *cursor_wm = (int)cursor->max_wm; |
| 1135 | |
| 1136 | return true; |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | * Check the wm result. |
| 1141 | * |
| 1142 | * If any calculated watermark values is larger than the maximum value that |
| 1143 | * can be programmed into the associated watermark register, that watermark |
| 1144 | * must be disabled. |
| 1145 | */ |
| 1146 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1147 | int display_wm, int cursor_wm, |
| 1148 | const struct intel_watermark_params *display, |
| 1149 | const struct intel_watermark_params *cursor) |
| 1150 | { |
| 1151 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1152 | display_wm, cursor_wm); |
| 1153 | |
| 1154 | if (display_wm > display->max_wm) { |
| 1155 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1156 | display_wm, display->max_wm); |
| 1157 | return false; |
| 1158 | } |
| 1159 | |
| 1160 | if (cursor_wm > cursor->max_wm) { |
| 1161 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1162 | cursor_wm, cursor->max_wm); |
| 1163 | return false; |
| 1164 | } |
| 1165 | |
| 1166 | if (!(display_wm || cursor_wm)) { |
| 1167 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1168 | return false; |
| 1169 | } |
| 1170 | |
| 1171 | return true; |
| 1172 | } |
| 1173 | |
| 1174 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1175 | int plane, |
| 1176 | int latency_ns, |
| 1177 | const struct intel_watermark_params *display, |
| 1178 | const struct intel_watermark_params *cursor, |
| 1179 | int *display_wm, int *cursor_wm) |
| 1180 | { |
| 1181 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1182 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1183 | int hdisplay, htotal, pixel_size, clock; |
| 1184 | unsigned long line_time_us; |
| 1185 | int line_count, line_size; |
| 1186 | int small, large; |
| 1187 | int entries; |
| 1188 | |
| 1189 | if (!latency_ns) { |
| 1190 | *display_wm = *cursor_wm = 0; |
| 1191 | return false; |
| 1192 | } |
| 1193 | |
| 1194 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1195 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1196 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1197 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1198 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1199 | pixel_size = crtc->fb->bits_per_pixel / 8; |
| 1200 | |
| 1201 | line_time_us = (htotal * 1000) / clock; |
| 1202 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1203 | line_size = hdisplay * pixel_size; |
| 1204 | |
| 1205 | /* Use the minimum of the small and large buffer method for primary */ |
| 1206 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1207 | large = line_count * line_size; |
| 1208 | |
| 1209 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1210 | *display_wm = entries + display->guard_size; |
| 1211 | |
| 1212 | /* calculate the self-refresh watermark for display cursor */ |
| 1213 | entries = line_count * pixel_size * 64; |
| 1214 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1215 | *cursor_wm = entries + cursor->guard_size; |
| 1216 | |
| 1217 | return g4x_check_srwm(dev, |
| 1218 | *display_wm, *cursor_wm, |
| 1219 | display, cursor); |
| 1220 | } |
| 1221 | |
| 1222 | static bool vlv_compute_drain_latency(struct drm_device *dev, |
| 1223 | int plane, |
| 1224 | int *plane_prec_mult, |
| 1225 | int *plane_dl, |
| 1226 | int *cursor_prec_mult, |
| 1227 | int *cursor_dl) |
| 1228 | { |
| 1229 | struct drm_crtc *crtc; |
| 1230 | int clock, pixel_size; |
| 1231 | int entries; |
| 1232 | |
| 1233 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1234 | if (!intel_crtc_active(crtc)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1235 | return false; |
| 1236 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1237 | clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1238 | pixel_size = crtc->fb->bits_per_pixel / 8; /* BPP */ |
| 1239 | |
| 1240 | entries = (clock / 1000) * pixel_size; |
| 1241 | *plane_prec_mult = (entries > 256) ? |
| 1242 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1243 | *plane_dl = (64 * (*plane_prec_mult) * 4) / ((clock / 1000) * |
| 1244 | pixel_size); |
| 1245 | |
| 1246 | entries = (clock / 1000) * 4; /* BPP is always 4 for cursor */ |
| 1247 | *cursor_prec_mult = (entries > 256) ? |
| 1248 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1249 | *cursor_dl = (64 * (*cursor_prec_mult) * 4) / ((clock / 1000) * 4); |
| 1250 | |
| 1251 | return true; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * Update drain latency registers of memory arbiter |
| 1256 | * |
| 1257 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1258 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1259 | * latency value. |
| 1260 | */ |
| 1261 | |
| 1262 | static void vlv_update_drain_latency(struct drm_device *dev) |
| 1263 | { |
| 1264 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1265 | int planea_prec, planea_dl, planeb_prec, planeb_dl; |
| 1266 | int cursora_prec, cursora_dl, cursorb_prec, cursorb_dl; |
| 1267 | int plane_prec_mult, cursor_prec_mult; /* Precision multiplier is |
| 1268 | either 16 or 32 */ |
| 1269 | |
| 1270 | /* For plane A, Cursor A */ |
| 1271 | if (vlv_compute_drain_latency(dev, 0, &plane_prec_mult, &planea_dl, |
| 1272 | &cursor_prec_mult, &cursora_dl)) { |
| 1273 | cursora_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1274 | DDL_CURSORA_PRECISION_32 : DDL_CURSORA_PRECISION_16; |
| 1275 | planea_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1276 | DDL_PLANEA_PRECISION_32 : DDL_PLANEA_PRECISION_16; |
| 1277 | |
| 1278 | I915_WRITE(VLV_DDL1, cursora_prec | |
| 1279 | (cursora_dl << DDL_CURSORA_SHIFT) | |
| 1280 | planea_prec | planea_dl); |
| 1281 | } |
| 1282 | |
| 1283 | /* For plane B, Cursor B */ |
| 1284 | if (vlv_compute_drain_latency(dev, 1, &plane_prec_mult, &planeb_dl, |
| 1285 | &cursor_prec_mult, &cursorb_dl)) { |
| 1286 | cursorb_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1287 | DDL_CURSORB_PRECISION_32 : DDL_CURSORB_PRECISION_16; |
| 1288 | planeb_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1289 | DDL_PLANEB_PRECISION_32 : DDL_PLANEB_PRECISION_16; |
| 1290 | |
| 1291 | I915_WRITE(VLV_DDL2, cursorb_prec | |
| 1292 | (cursorb_dl << DDL_CURSORB_SHIFT) | |
| 1293 | planeb_prec | planeb_dl); |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1298 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1299 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1300 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1301 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1302 | static const int sr_latency_ns = 12000; |
| 1303 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1304 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1305 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1306 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1307 | unsigned int enabled = 0; |
| 1308 | |
| 1309 | vlv_update_drain_latency(dev); |
| 1310 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1311 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1312 | &valleyview_wm_info, latency_ns, |
| 1313 | &valleyview_cursor_wm_info, latency_ns, |
| 1314 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1315 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1316 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1317 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1318 | &valleyview_wm_info, latency_ns, |
| 1319 | &valleyview_cursor_wm_info, latency_ns, |
| 1320 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1321 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1322 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1323 | if (single_plane_enabled(enabled) && |
| 1324 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1325 | sr_latency_ns, |
| 1326 | &valleyview_wm_info, |
| 1327 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1328 | &plane_sr, &ignore_cursor_sr) && |
| 1329 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1330 | 2*sr_latency_ns, |
| 1331 | &valleyview_wm_info, |
| 1332 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1333 | &ignore_plane_sr, &cursor_sr)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1334 | I915_WRITE(FW_BLC_SELF_VLV, FW_CSPWRDWNEN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1335 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1336 | I915_WRITE(FW_BLC_SELF_VLV, |
| 1337 | I915_READ(FW_BLC_SELF_VLV) & ~FW_CSPWRDWNEN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1338 | plane_sr = cursor_sr = 0; |
| 1339 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1340 | |
| 1341 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1342 | planea_wm, cursora_wm, |
| 1343 | planeb_wm, cursorb_wm, |
| 1344 | plane_sr, cursor_sr); |
| 1345 | |
| 1346 | I915_WRITE(DSPFW1, |
| 1347 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1348 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1349 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1350 | planea_wm); |
| 1351 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1352 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1353 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1354 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1355 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1356 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1357 | } |
| 1358 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1359 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1360 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1361 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1362 | static const int sr_latency_ns = 12000; |
| 1363 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1364 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1365 | int plane_sr, cursor_sr; |
| 1366 | unsigned int enabled = 0; |
| 1367 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1368 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1369 | &g4x_wm_info, latency_ns, |
| 1370 | &g4x_cursor_wm_info, latency_ns, |
| 1371 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1372 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1373 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1374 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1375 | &g4x_wm_info, latency_ns, |
| 1376 | &g4x_cursor_wm_info, latency_ns, |
| 1377 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1378 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1379 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1380 | if (single_plane_enabled(enabled) && |
| 1381 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1382 | sr_latency_ns, |
| 1383 | &g4x_wm_info, |
| 1384 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1385 | &plane_sr, &cursor_sr)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1386 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1387 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1388 | I915_WRITE(FW_BLC_SELF, |
| 1389 | I915_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1390 | plane_sr = cursor_sr = 0; |
| 1391 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1392 | |
| 1393 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1394 | planea_wm, cursora_wm, |
| 1395 | planeb_wm, cursorb_wm, |
| 1396 | plane_sr, cursor_sr); |
| 1397 | |
| 1398 | I915_WRITE(DSPFW1, |
| 1399 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1400 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1401 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1402 | planea_wm); |
| 1403 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1404 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1405 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1406 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1407 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1408 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1409 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1410 | } |
| 1411 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1412 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1413 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1414 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1415 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1416 | struct drm_crtc *crtc; |
| 1417 | int srwm = 1; |
| 1418 | int cursor_sr = 16; |
| 1419 | |
| 1420 | /* Calc sr entries for one plane configs */ |
| 1421 | crtc = single_enabled_crtc(dev); |
| 1422 | if (crtc) { |
| 1423 | /* self-refresh has much higher latency */ |
| 1424 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1425 | const struct drm_display_mode *adjusted_mode = |
| 1426 | &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1427 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1428 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1429 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1430 | int pixel_size = crtc->fb->bits_per_pixel / 8; |
| 1431 | unsigned long line_time_us; |
| 1432 | int entries; |
| 1433 | |
| 1434 | line_time_us = ((htotal * 1000) / clock); |
| 1435 | |
| 1436 | /* Use ns/us then divide to preserve precision */ |
| 1437 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1438 | pixel_size * hdisplay; |
| 1439 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1440 | srwm = I965_FIFO_SIZE - entries; |
| 1441 | if (srwm < 0) |
| 1442 | srwm = 1; |
| 1443 | srwm &= 0x1ff; |
| 1444 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1445 | entries, srwm); |
| 1446 | |
| 1447 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1448 | pixel_size * 64; |
| 1449 | entries = DIV_ROUND_UP(entries, |
| 1450 | i965_cursor_wm_info.cacheline_size); |
| 1451 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1452 | (entries + i965_cursor_wm_info.guard_size); |
| 1453 | |
| 1454 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1455 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1456 | |
| 1457 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1458 | "cursor %d\n", srwm, cursor_sr); |
| 1459 | |
| 1460 | if (IS_CRESTLINE(dev)) |
| 1461 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); |
| 1462 | } else { |
| 1463 | /* Turn off self refresh if both pipes are enabled */ |
| 1464 | if (IS_CRESTLINE(dev)) |
| 1465 | I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) |
| 1466 | & ~FW_BLC_SELF_EN); |
| 1467 | } |
| 1468 | |
| 1469 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1470 | srwm); |
| 1471 | |
| 1472 | /* 965 has limitations... */ |
| 1473 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
| 1474 | (8 << 16) | (8 << 8) | (8 << 0)); |
| 1475 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); |
| 1476 | /* update cursor SR watermark */ |
| 1477 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1478 | } |
| 1479 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1480 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1481 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1482 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1483 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1484 | const struct intel_watermark_params *wm_info; |
| 1485 | uint32_t fwater_lo; |
| 1486 | uint32_t fwater_hi; |
| 1487 | int cwm, srwm = 1; |
| 1488 | int fifo_size; |
| 1489 | int planea_wm, planeb_wm; |
| 1490 | struct drm_crtc *crtc, *enabled = NULL; |
| 1491 | |
| 1492 | if (IS_I945GM(dev)) |
| 1493 | wm_info = &i945_wm_info; |
| 1494 | else if (!IS_GEN2(dev)) |
| 1495 | wm_info = &i915_wm_info; |
| 1496 | else |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1497 | wm_info = &i830_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1498 | |
| 1499 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1500 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1501 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1502 | const struct drm_display_mode *adjusted_mode; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1503 | int cpp = crtc->fb->bits_per_pixel / 8; |
| 1504 | if (IS_GEN2(dev)) |
| 1505 | cpp = 4; |
| 1506 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1507 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1508 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1509 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1510 | latency_ns); |
| 1511 | enabled = crtc; |
| 1512 | } else |
| 1513 | planea_wm = fifo_size - wm_info->guard_size; |
| 1514 | |
| 1515 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1516 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1517 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1518 | const struct drm_display_mode *adjusted_mode; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1519 | int cpp = crtc->fb->bits_per_pixel / 8; |
| 1520 | if (IS_GEN2(dev)) |
| 1521 | cpp = 4; |
| 1522 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1523 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1524 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1525 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1526 | latency_ns); |
| 1527 | if (enabled == NULL) |
| 1528 | enabled = crtc; |
| 1529 | else |
| 1530 | enabled = NULL; |
| 1531 | } else |
| 1532 | planeb_wm = fifo_size - wm_info->guard_size; |
| 1533 | |
| 1534 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1535 | |
| 1536 | /* |
| 1537 | * Overlay gets an aggressive default since video jitter is bad. |
| 1538 | */ |
| 1539 | cwm = 2; |
| 1540 | |
| 1541 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
| 1542 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1543 | I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | 0); |
| 1544 | else if (IS_I915GM(dev)) |
Ville Syrjälä | 3f2dc5a | 2014-01-10 14:06:47 +0200 | [diff] [blame] | 1545 | I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_SELF_EN)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1546 | |
| 1547 | /* Calc sr entries for one plane configs */ |
| 1548 | if (HAS_FW_BLC(dev) && enabled) { |
| 1549 | /* self-refresh has much higher latency */ |
| 1550 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1551 | const struct drm_display_mode *adjusted_mode = |
| 1552 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1553 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1554 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1555 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1556 | int pixel_size = enabled->fb->bits_per_pixel / 8; |
| 1557 | unsigned long line_time_us; |
| 1558 | int entries; |
| 1559 | |
| 1560 | line_time_us = (htotal * 1000) / clock; |
| 1561 | |
| 1562 | /* Use ns/us then divide to preserve precision */ |
| 1563 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1564 | pixel_size * hdisplay; |
| 1565 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1566 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1567 | srwm = wm_info->fifo_size - entries; |
| 1568 | if (srwm < 0) |
| 1569 | srwm = 1; |
| 1570 | |
| 1571 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1572 | I915_WRITE(FW_BLC_SELF, |
| 1573 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1574 | else if (IS_I915GM(dev)) |
| 1575 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1576 | } |
| 1577 | |
| 1578 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1579 | planea_wm, planeb_wm, cwm, srwm); |
| 1580 | |
| 1581 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1582 | fwater_hi = (cwm & 0x1f); |
| 1583 | |
| 1584 | /* Set request length to 8 cachelines per fetch */ |
| 1585 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1586 | fwater_hi = fwater_hi | (1 << 8); |
| 1587 | |
| 1588 | I915_WRITE(FW_BLC, fwater_lo); |
| 1589 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1590 | |
| 1591 | if (HAS_FW_BLC(dev)) { |
| 1592 | if (enabled) { |
| 1593 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1594 | I915_WRITE(FW_BLC_SELF, |
| 1595 | FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN); |
| 1596 | else if (IS_I915GM(dev)) |
Ville Syrjälä | 3f2dc5a | 2014-01-10 14:06:47 +0200 | [diff] [blame] | 1597 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_SELF_EN)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1598 | DRM_DEBUG_KMS("memory self refresh enabled\n"); |
| 1599 | } else |
| 1600 | DRM_DEBUG_KMS("memory self refresh disabled\n"); |
| 1601 | } |
| 1602 | } |
| 1603 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1604 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1605 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1606 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1607 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1608 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1609 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1610 | uint32_t fwater_lo; |
| 1611 | int planea_wm; |
| 1612 | |
| 1613 | crtc = single_enabled_crtc(dev); |
| 1614 | if (crtc == NULL) |
| 1615 | return; |
| 1616 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1617 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1618 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1619 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1620 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1621 | 4, latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1622 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1623 | fwater_lo |= (3<<8) | planea_wm; |
| 1624 | |
| 1625 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1626 | |
| 1627 | I915_WRITE(FW_BLC, fwater_lo); |
| 1628 | } |
| 1629 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1630 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1631 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1632 | { |
| 1633 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1634 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1635 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1636 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1637 | |
| 1638 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1639 | * adjust the pixel_rate here. */ |
| 1640 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1641 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1642 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1643 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1644 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1645 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1646 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1647 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1648 | pfit_h = pfit_size & 0xFFFF; |
| 1649 | if (pipe_w < pfit_w) |
| 1650 | pipe_w = pfit_w; |
| 1651 | if (pipe_h < pfit_h) |
| 1652 | pipe_h = pfit_h; |
| 1653 | |
| 1654 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1655 | pfit_w * pfit_h); |
| 1656 | } |
| 1657 | |
| 1658 | return pixel_rate; |
| 1659 | } |
| 1660 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1661 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1662 | 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] | 1663 | uint32_t latency) |
| 1664 | { |
| 1665 | uint64_t ret; |
| 1666 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1667 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1668 | return UINT_MAX; |
| 1669 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1670 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1671 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1672 | |
| 1673 | return ret; |
| 1674 | } |
| 1675 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1676 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1677 | 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] | 1678 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1679 | uint32_t latency) |
| 1680 | { |
| 1681 | uint32_t ret; |
| 1682 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1683 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1684 | return UINT_MAX; |
| 1685 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1686 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1687 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1688 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1689 | return ret; |
| 1690 | } |
| 1691 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1692 | 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] | 1693 | uint8_t bytes_per_pixel) |
| 1694 | { |
| 1695 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1696 | } |
| 1697 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1698 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1699 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1700 | uint32_t pipe_htotal; |
| 1701 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1702 | struct intel_plane_wm_parameters pri; |
| 1703 | struct intel_plane_wm_parameters spr; |
| 1704 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1705 | }; |
| 1706 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1707 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1708 | uint16_t pri; |
| 1709 | uint16_t spr; |
| 1710 | uint16_t cur; |
| 1711 | uint16_t fbc; |
| 1712 | }; |
| 1713 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1714 | /* used in computing the new watermarks state */ |
| 1715 | struct intel_wm_config { |
| 1716 | unsigned int num_pipes_active; |
| 1717 | bool sprites_enabled; |
| 1718 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1719 | }; |
| 1720 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1721 | /* |
| 1722 | * For both WM_PIPE and WM_LP. |
| 1723 | * mem_value must be in 0.1us units. |
| 1724 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1725 | 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] | 1726 | uint32_t mem_value, |
| 1727 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1728 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1729 | uint32_t method1, method2; |
| 1730 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1731 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1732 | return 0; |
| 1733 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1734 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1735 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1736 | mem_value); |
| 1737 | |
| 1738 | if (!is_lp) |
| 1739 | return method1; |
| 1740 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1741 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1742 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1743 | params->pri.horiz_pixels, |
| 1744 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1745 | mem_value); |
| 1746 | |
| 1747 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1748 | } |
| 1749 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1750 | /* |
| 1751 | * For both WM_PIPE and WM_LP. |
| 1752 | * mem_value must be in 0.1us units. |
| 1753 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1754 | 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] | 1755 | uint32_t mem_value) |
| 1756 | { |
| 1757 | uint32_t method1, method2; |
| 1758 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1759 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1760 | return 0; |
| 1761 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1762 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1763 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1764 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1765 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1766 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1767 | params->spr.horiz_pixels, |
| 1768 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1769 | mem_value); |
| 1770 | return min(method1, method2); |
| 1771 | } |
| 1772 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1773 | /* |
| 1774 | * For both WM_PIPE and WM_LP. |
| 1775 | * mem_value must be in 0.1us units. |
| 1776 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1777 | 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] | 1778 | uint32_t mem_value) |
| 1779 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1780 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1781 | return 0; |
| 1782 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1783 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1784 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1785 | params->cur.horiz_pixels, |
| 1786 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1787 | mem_value); |
| 1788 | } |
| 1789 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1790 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1791 | 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] | 1792 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1793 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1794 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1795 | return 0; |
| 1796 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1797 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1798 | params->pri.horiz_pixels, |
| 1799 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1800 | } |
| 1801 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1802 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1803 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1804 | if (INTEL_INFO(dev)->gen >= 8) |
| 1805 | return 3072; |
| 1806 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1807 | return 768; |
| 1808 | else |
| 1809 | return 512; |
| 1810 | } |
| 1811 | |
| 1812 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1813 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1814 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1815 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1816 | enum intel_ddb_partitioning ddb_partitioning, |
| 1817 | bool is_sprite) |
| 1818 | { |
| 1819 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
| 1820 | unsigned int max; |
| 1821 | |
| 1822 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1823 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1824 | return 0; |
| 1825 | |
| 1826 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1827 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1828 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1829 | |
| 1830 | /* |
| 1831 | * For some reason the non self refresh |
| 1832 | * FIFO size is only half of the self |
| 1833 | * refresh FIFO size on ILK/SNB. |
| 1834 | */ |
| 1835 | if (INTEL_INFO(dev)->gen <= 6) |
| 1836 | fifo_size /= 2; |
| 1837 | } |
| 1838 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1839 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1840 | /* level 0 is always calculated with 1:1 split */ |
| 1841 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1842 | if (is_sprite) |
| 1843 | fifo_size *= 5; |
| 1844 | fifo_size /= 6; |
| 1845 | } else { |
| 1846 | fifo_size /= 2; |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1851 | if (INTEL_INFO(dev)->gen >= 8) |
| 1852 | max = level == 0 ? 255 : 2047; |
| 1853 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1854 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1855 | max = level == 0 ? 127 : 1023; |
| 1856 | else if (!is_sprite) |
| 1857 | /* ILK/SNB primary plane watermarks */ |
| 1858 | max = level == 0 ? 127 : 511; |
| 1859 | else |
| 1860 | /* ILK/SNB sprite plane watermarks */ |
| 1861 | max = level == 0 ? 63 : 255; |
| 1862 | |
| 1863 | return min(fifo_size, max); |
| 1864 | } |
| 1865 | |
| 1866 | /* Calculate the maximum cursor plane watermark */ |
| 1867 | 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] | 1868 | int level, |
| 1869 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1870 | { |
| 1871 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1872 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1873 | return 64; |
| 1874 | |
| 1875 | /* otherwise just report max that registers can hold */ |
| 1876 | if (INTEL_INFO(dev)->gen >= 7) |
| 1877 | return level == 0 ? 63 : 255; |
| 1878 | else |
| 1879 | return level == 0 ? 31 : 63; |
| 1880 | } |
| 1881 | |
| 1882 | /* Calculate the maximum FBC watermark */ |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1883 | static unsigned int ilk_fbc_wm_max(struct drm_device *dev) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1884 | { |
| 1885 | /* max that registers can hold */ |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1886 | if (INTEL_INFO(dev)->gen >= 8) |
| 1887 | return 31; |
| 1888 | else |
| 1889 | return 15; |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1890 | } |
| 1891 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1892 | static void ilk_compute_wm_maximums(struct drm_device *dev, |
| 1893 | int level, |
| 1894 | const struct intel_wm_config *config, |
| 1895 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1896 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1897 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1898 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1899 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1900 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1901 | max->fbc = ilk_fbc_wm_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1902 | } |
| 1903 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1904 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1905 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1906 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1907 | { |
| 1908 | bool ret; |
| 1909 | |
| 1910 | /* already determined to be invalid? */ |
| 1911 | if (!result->enable) |
| 1912 | return false; |
| 1913 | |
| 1914 | result->enable = result->pri_val <= max->pri && |
| 1915 | result->spr_val <= max->spr && |
| 1916 | result->cur_val <= max->cur; |
| 1917 | |
| 1918 | ret = result->enable; |
| 1919 | |
| 1920 | /* |
| 1921 | * HACK until we can pre-compute everything, |
| 1922 | * and thus fail gracefully if LP0 watermarks |
| 1923 | * are exceeded... |
| 1924 | */ |
| 1925 | if (level == 0 && !result->enable) { |
| 1926 | if (result->pri_val > max->pri) |
| 1927 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1928 | level, result->pri_val, max->pri); |
| 1929 | if (result->spr_val > max->spr) |
| 1930 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1931 | level, result->spr_val, max->spr); |
| 1932 | if (result->cur_val > max->cur) |
| 1933 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1934 | level, result->cur_val, max->cur); |
| 1935 | |
| 1936 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1937 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1938 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1939 | result->enable = true; |
| 1940 | } |
| 1941 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1942 | return ret; |
| 1943 | } |
| 1944 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1945 | static void ilk_compute_wm_level(struct drm_i915_private *dev_priv, |
| 1946 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1947 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1948 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1949 | { |
| 1950 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1951 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1952 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1953 | |
| 1954 | /* WM1+ latency values stored in 0.5us units */ |
| 1955 | if (level > 0) { |
| 1956 | pri_latency *= 5; |
| 1957 | spr_latency *= 5; |
| 1958 | cur_latency *= 5; |
| 1959 | } |
| 1960 | |
| 1961 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1962 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1963 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1964 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1965 | result->enable = true; |
| 1966 | } |
| 1967 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1968 | static uint32_t |
| 1969 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1970 | { |
| 1971 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1972 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1973 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1974 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1975 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1976 | if (!intel_crtc_active(crtc)) |
| 1977 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1978 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1979 | /* The WM are computed with base on how long it takes to fill a single |
| 1980 | * row at the given clock rate, multiplied by 8. |
| 1981 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1982 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1983 | mode->crtc_clock); |
| 1984 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1985 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1986 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1987 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1988 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1989 | } |
| 1990 | |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1991 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1992 | { |
| 1993 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1994 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 1995 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1996 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1997 | |
| 1998 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1999 | if (wm[0] == 0) |
| 2000 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2001 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2002 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2003 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2004 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2005 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2006 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2007 | |
| 2008 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2009 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2010 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2011 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2012 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2013 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2014 | |
| 2015 | /* ILK primary LP0 latency is 700 ns */ |
| 2016 | wm[0] = 7; |
| 2017 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2018 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2022 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2023 | { |
| 2024 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2025 | if (INTEL_INFO(dev)->gen == 5) |
| 2026 | wm[0] = 13; |
| 2027 | } |
| 2028 | |
| 2029 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2030 | { |
| 2031 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2032 | if (INTEL_INFO(dev)->gen == 5) |
| 2033 | wm[0] = 13; |
| 2034 | |
| 2035 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2036 | if (IS_IVYBRIDGE(dev)) |
| 2037 | wm[3] *= 2; |
| 2038 | } |
| 2039 | |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2040 | static int ilk_wm_max_level(const struct drm_device *dev) |
| 2041 | { |
| 2042 | /* how many WM levels are we expecting */ |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2043 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2044 | return 4; |
| 2045 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2046 | return 3; |
| 2047 | else |
| 2048 | return 2; |
| 2049 | } |
| 2050 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2051 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2052 | const char *name, |
| 2053 | const uint16_t wm[5]) |
| 2054 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2055 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2056 | |
| 2057 | for (level = 0; level <= max_level; level++) { |
| 2058 | unsigned int latency = wm[level]; |
| 2059 | |
| 2060 | if (latency == 0) { |
| 2061 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2062 | name, level); |
| 2063 | continue; |
| 2064 | } |
| 2065 | |
| 2066 | /* WM1+ latency values in 0.5us units */ |
| 2067 | if (level > 0) |
| 2068 | latency *= 5; |
| 2069 | |
| 2070 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2071 | name, level, wm[level], |
| 2072 | latency / 10, latency % 10); |
| 2073 | } |
| 2074 | } |
| 2075 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2076 | static void intel_setup_wm_latency(struct drm_device *dev) |
| 2077 | { |
| 2078 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2079 | |
| 2080 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2081 | |
| 2082 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2083 | sizeof(dev_priv->wm.pri_latency)); |
| 2084 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2085 | sizeof(dev_priv->wm.pri_latency)); |
| 2086 | |
| 2087 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2088 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2089 | |
| 2090 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2091 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2092 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2093 | } |
| 2094 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2095 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
| 2096 | struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2097 | struct intel_wm_config *config) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2098 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2099 | struct drm_device *dev = crtc->dev; |
| 2100 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2101 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2102 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2103 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2104 | p->active = intel_crtc_active(crtc); |
| 2105 | if (p->active) { |
Jesse Barnes | 576b259 | 2013-12-20 13:08:00 -0800 | [diff] [blame] | 2106 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 2107 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2108 | p->pri.bytes_per_pixel = crtc->fb->bits_per_pixel / 8; |
| 2109 | p->cur.bytes_per_pixel = 4; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 2110 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2111 | p->cur.horiz_pixels = 64; |
| 2112 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2113 | p->pri.enabled = true; |
| 2114 | p->cur.enabled = true; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2115 | } |
| 2116 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2117 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2118 | config->num_pipes_active += intel_crtc_active(crtc); |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2119 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2120 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2121 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2122 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2123 | if (intel_plane->pipe == pipe) |
| 2124 | p->spr = intel_plane->wm; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2125 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2126 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2127 | config->sprites_scaled |= intel_plane->wm.scaled; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2131 | /* Compute new watermarks for the pipe */ |
| 2132 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2133 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2134 | struct intel_pipe_wm *pipe_wm) |
| 2135 | { |
| 2136 | struct drm_device *dev = crtc->dev; |
| 2137 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2138 | int level, max_level = ilk_wm_max_level(dev); |
| 2139 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2140 | struct intel_wm_config config = { |
| 2141 | .num_pipes_active = 1, |
| 2142 | .sprites_enabled = params->spr.enabled, |
| 2143 | .sprites_scaled = params->spr.scaled, |
| 2144 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2145 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2146 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2147 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2148 | 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] | 2149 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2150 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2151 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2152 | max_level = 1; |
| 2153 | |
| 2154 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2155 | if (params->spr.scaled) |
| 2156 | max_level = 0; |
| 2157 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2158 | for (level = 0; level <= max_level; level++) |
| 2159 | ilk_compute_wm_level(dev_priv, level, params, |
| 2160 | &pipe_wm->wm[level]); |
| 2161 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2162 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2163 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2164 | |
| 2165 | /* At least LP0 must be valid */ |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2166 | return ilk_validate_wm_level(0, &max, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | /* |
| 2170 | * Merge the watermarks from all active pipes for a specific level. |
| 2171 | */ |
| 2172 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2173 | int level, |
| 2174 | struct intel_wm_level *ret_wm) |
| 2175 | { |
| 2176 | const struct intel_crtc *intel_crtc; |
| 2177 | |
| 2178 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head) { |
| 2179 | const struct intel_wm_level *wm = |
| 2180 | &intel_crtc->wm.active.wm[level]; |
| 2181 | |
| 2182 | if (!wm->enable) |
| 2183 | return; |
| 2184 | |
| 2185 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2186 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2187 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2188 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2189 | } |
| 2190 | |
| 2191 | ret_wm->enable = true; |
| 2192 | } |
| 2193 | |
| 2194 | /* |
| 2195 | * Merge all low power watermarks for all active pipes. |
| 2196 | */ |
| 2197 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2198 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2199 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2200 | struct intel_pipe_wm *merged) |
| 2201 | { |
| 2202 | int level, max_level = ilk_wm_max_level(dev); |
| 2203 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2204 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2205 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2206 | config->num_pipes_active > 1) |
| 2207 | return; |
| 2208 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2209 | /* ILK: FBC WM must be disabled always */ |
| 2210 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2211 | |
| 2212 | /* merge each WM1+ level */ |
| 2213 | for (level = 1; level <= max_level; level++) { |
| 2214 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2215 | |
| 2216 | ilk_merge_wm_level(dev, level, wm); |
| 2217 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2218 | if (!ilk_validate_wm_level(level, max, wm)) |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2219 | break; |
| 2220 | |
| 2221 | /* |
| 2222 | * The spec says it is preferred to disable |
| 2223 | * FBC WMs instead of disabling a WM level. |
| 2224 | */ |
| 2225 | if (wm->fbc_val > max->fbc) { |
| 2226 | merged->fbc_wm_enabled = false; |
| 2227 | wm->fbc_val = 0; |
| 2228 | } |
| 2229 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2230 | |
| 2231 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2232 | /* |
| 2233 | * FIXME this is racy. FBC might get enabled later. |
| 2234 | * What we should check here is whether FBC can be |
| 2235 | * enabled sometime later. |
| 2236 | */ |
| 2237 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2238 | for (level = 2; level <= max_level; level++) { |
| 2239 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2240 | |
| 2241 | wm->enable = false; |
| 2242 | } |
| 2243 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2244 | } |
| 2245 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2246 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2247 | { |
| 2248 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2249 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2250 | } |
| 2251 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2252 | /* The value we need to program into the WM_LPx latency field */ |
| 2253 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2254 | { |
| 2255 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2256 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2257 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2258 | return 2 * level; |
| 2259 | else |
| 2260 | return dev_priv->wm.pri_latency[level]; |
| 2261 | } |
| 2262 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2263 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2264 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2265 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2266 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2267 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2268 | struct intel_crtc *intel_crtc; |
| 2269 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2270 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2271 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2272 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2273 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2274 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2275 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2276 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2277 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2278 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2279 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2280 | r = &merged->wm[level]; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2281 | if (!r->enable) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2282 | break; |
| 2283 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2284 | results->wm_lp[wm_lp - 1] = WM3_LP_EN | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2285 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2286 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2287 | r->cur_val; |
| 2288 | |
| 2289 | if (INTEL_INFO(dev)->gen >= 8) |
| 2290 | results->wm_lp[wm_lp - 1] |= |
| 2291 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2292 | else |
| 2293 | results->wm_lp[wm_lp - 1] |= |
| 2294 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2295 | |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2296 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2297 | WARN_ON(wm_lp != 1); |
| 2298 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2299 | } else |
| 2300 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2301 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2302 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2303 | /* LP0 register values */ |
| 2304 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head) { |
| 2305 | enum pipe pipe = intel_crtc->pipe; |
| 2306 | const struct intel_wm_level *r = |
| 2307 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2308 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2309 | if (WARN_ON(!r->enable)) |
| 2310 | continue; |
| 2311 | |
| 2312 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2313 | |
| 2314 | results->wm_pipe[pipe] = |
| 2315 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2316 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2317 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2318 | } |
| 2319 | } |
| 2320 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2321 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2322 | * 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] | 2323 | 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] | 2324 | struct intel_pipe_wm *r1, |
| 2325 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2326 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2327 | int level, max_level = ilk_wm_max_level(dev); |
| 2328 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2329 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2330 | for (level = 1; level <= max_level; level++) { |
| 2331 | if (r1->wm[level].enable) |
| 2332 | level1 = level; |
| 2333 | if (r2->wm[level].enable) |
| 2334 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2335 | } |
| 2336 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2337 | if (level1 == level2) { |
| 2338 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2339 | return r2; |
| 2340 | else |
| 2341 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2342 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2343 | return r1; |
| 2344 | } else { |
| 2345 | return r2; |
| 2346 | } |
| 2347 | } |
| 2348 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2349 | /* dirty bits used to track which watermarks need changes */ |
| 2350 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2351 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2352 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2353 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2354 | #define WM_DIRTY_FBC (1 << 24) |
| 2355 | #define WM_DIRTY_DDB (1 << 25) |
| 2356 | |
| 2357 | static unsigned int ilk_compute_wm_dirty(struct drm_device *dev, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2358 | const struct ilk_wm_values *old, |
| 2359 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2360 | { |
| 2361 | unsigned int dirty = 0; |
| 2362 | enum pipe pipe; |
| 2363 | int wm_lp; |
| 2364 | |
| 2365 | for_each_pipe(pipe) { |
| 2366 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2367 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2368 | /* Must disable LP1+ watermarks too */ |
| 2369 | dirty |= WM_DIRTY_LP_ALL; |
| 2370 | } |
| 2371 | |
| 2372 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2373 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2374 | /* Must disable LP1+ watermarks too */ |
| 2375 | dirty |= WM_DIRTY_LP_ALL; |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2380 | dirty |= WM_DIRTY_FBC; |
| 2381 | /* Must disable LP1+ watermarks too */ |
| 2382 | dirty |= WM_DIRTY_LP_ALL; |
| 2383 | } |
| 2384 | |
| 2385 | if (old->partitioning != new->partitioning) { |
| 2386 | dirty |= WM_DIRTY_DDB; |
| 2387 | /* Must disable LP1+ watermarks too */ |
| 2388 | dirty |= WM_DIRTY_LP_ALL; |
| 2389 | } |
| 2390 | |
| 2391 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2392 | if (dirty & WM_DIRTY_LP_ALL) |
| 2393 | return dirty; |
| 2394 | |
| 2395 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2396 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2397 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2398 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2399 | break; |
| 2400 | } |
| 2401 | |
| 2402 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2403 | for (; wm_lp <= 3; wm_lp++) |
| 2404 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2405 | |
| 2406 | return dirty; |
| 2407 | } |
| 2408 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2409 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2410 | unsigned int dirty) |
| 2411 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2412 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2413 | bool changed = false; |
| 2414 | |
| 2415 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2416 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2417 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2418 | changed = true; |
| 2419 | } |
| 2420 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2421 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2422 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2423 | changed = true; |
| 2424 | } |
| 2425 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2426 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2427 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2428 | changed = true; |
| 2429 | } |
| 2430 | |
| 2431 | /* |
| 2432 | * Don't touch WM1S_LP_EN here. |
| 2433 | * Doing so could cause underruns. |
| 2434 | */ |
| 2435 | |
| 2436 | return changed; |
| 2437 | } |
| 2438 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2439 | /* |
| 2440 | * The spec says we shouldn't write when we don't need, because every write |
| 2441 | * causes WMs to be re-evaluated, expending some power. |
| 2442 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2443 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2444 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2445 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2446 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2447 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2448 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2449 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2450 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2451 | dirty = ilk_compute_wm_dirty(dev, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2452 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2453 | return; |
| 2454 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2455 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2456 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2457 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2458 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2459 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2460 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2461 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2462 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2463 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2464 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2465 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2466 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2467 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2468 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2469 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2470 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2471 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2472 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2473 | val = I915_READ(WM_MISC); |
| 2474 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2475 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2476 | else |
| 2477 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2478 | I915_WRITE(WM_MISC, val); |
| 2479 | } else { |
| 2480 | val = I915_READ(DISP_ARB_CTL2); |
| 2481 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2482 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2483 | else |
| 2484 | val |= DISP_DATA_PARTITION_5_6; |
| 2485 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2486 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2487 | } |
| 2488 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2489 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2490 | val = I915_READ(DISP_ARB_CTL); |
| 2491 | if (results->enable_fbc_wm) |
| 2492 | val &= ~DISP_FBC_WM_DIS; |
| 2493 | else |
| 2494 | val |= DISP_FBC_WM_DIS; |
| 2495 | I915_WRITE(DISP_ARB_CTL, val); |
| 2496 | } |
| 2497 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2498 | if (dirty & WM_DIRTY_LP(1) && |
| 2499 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2500 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2501 | |
| 2502 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2503 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2504 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2505 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2506 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2507 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2508 | |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2509 | 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] | 2510 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2511 | 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] | 2512 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2513 | 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] | 2514 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2515 | |
| 2516 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2517 | } |
| 2518 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2519 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2520 | { |
| 2521 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2522 | |
| 2523 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2524 | } |
| 2525 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2526 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2527 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2528 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2529 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2531 | struct ilk_wm_maximums max; |
| 2532 | struct ilk_pipe_wm_parameters params = {}; |
| 2533 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2534 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2535 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2536 | 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] | 2537 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2538 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2539 | ilk_compute_wm_parameters(crtc, ¶ms, &config); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2540 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2541 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 2542 | |
| 2543 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 2544 | return; |
| 2545 | |
| 2546 | intel_crtc->wm.active = pipe_wm; |
| 2547 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2548 | 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] | 2549 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2550 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2551 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 2552 | if (INTEL_INFO(dev)->gen >= 7 && |
| 2553 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2554 | 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] | 2555 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2556 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2557 | 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] | 2558 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2559 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2560 | } |
| 2561 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2562 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2563 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2564 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2565 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2566 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2567 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2568 | } |
| 2569 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2570 | static void ilk_update_sprite_wm(struct drm_plane *plane, |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2571 | struct drm_crtc *crtc, |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2572 | uint32_t sprite_width, int pixel_size, |
Ville Syrjälä | bdd57d0 | 2013-07-05 11:57:13 +0300 | [diff] [blame] | 2573 | bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2574 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2575 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2576 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2577 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2578 | intel_plane->wm.enabled = enabled; |
| 2579 | intel_plane->wm.scaled = scaled; |
| 2580 | intel_plane->wm.horiz_pixels = sprite_width; |
| 2581 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2582 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2583 | /* |
| 2584 | * IVB workaround: must disable low power watermarks for at least |
| 2585 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 2586 | * when scaling is disabled. |
| 2587 | * |
| 2588 | * WaCxSRDisabledForSpriteScaling:ivb |
| 2589 | */ |
| 2590 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 2591 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 2592 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2593 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2594 | } |
| 2595 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2596 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 2597 | { |
| 2598 | struct drm_device *dev = crtc->dev; |
| 2599 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2600 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2601 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2602 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2603 | enum pipe pipe = intel_crtc->pipe; |
| 2604 | static const unsigned int wm0_pipe_reg[] = { |
| 2605 | [PIPE_A] = WM0_PIPEA_ILK, |
| 2606 | [PIPE_B] = WM0_PIPEB_ILK, |
| 2607 | [PIPE_C] = WM0_PIPEC_IVB, |
| 2608 | }; |
| 2609 | |
| 2610 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2611 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2612 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2613 | |
| 2614 | if (intel_crtc_active(crtc)) { |
| 2615 | u32 tmp = hw->wm_pipe[pipe]; |
| 2616 | |
| 2617 | /* |
| 2618 | * For active pipes LP0 watermark is marked as |
| 2619 | * enabled, and LP1+ watermaks as disabled since |
| 2620 | * we can't really reverse compute them in case |
| 2621 | * multiple pipes are active. |
| 2622 | */ |
| 2623 | active->wm[0].enable = true; |
| 2624 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 2625 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 2626 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 2627 | active->linetime = hw->wm_linetime[pipe]; |
| 2628 | } else { |
| 2629 | int level, max_level = ilk_wm_max_level(dev); |
| 2630 | |
| 2631 | /* |
| 2632 | * For inactive pipes, all watermark levels |
| 2633 | * should be marked as enabled but zeroed, |
| 2634 | * which is what we'd compute them to. |
| 2635 | */ |
| 2636 | for (level = 0; level <= max_level; level++) |
| 2637 | active->wm[level].enable = true; |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 2642 | { |
| 2643 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2644 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2645 | struct drm_crtc *crtc; |
| 2646 | |
| 2647 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 2648 | ilk_pipe_wm_get_hw_state(crtc); |
| 2649 | |
| 2650 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 2651 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 2652 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 2653 | |
| 2654 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
| 2655 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 2656 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 2657 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2658 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2659 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 2660 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 2661 | else if (IS_IVYBRIDGE(dev)) |
| 2662 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 2663 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2664 | |
| 2665 | hw->enable_fbc_wm = |
| 2666 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 2667 | } |
| 2668 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2669 | /** |
| 2670 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 2671 | * |
| 2672 | * Calculate watermark values for the various WM regs based on current mode |
| 2673 | * and plane configuration. |
| 2674 | * |
| 2675 | * There are several cases to deal with here: |
| 2676 | * - normal (i.e. non-self-refresh) |
| 2677 | * - self-refresh (SR) mode |
| 2678 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 2679 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 2680 | * lines), so need to account for TLB latency |
| 2681 | * |
| 2682 | * The normal calculation is: |
| 2683 | * watermark = dotclock * bytes per pixel * latency |
| 2684 | * where latency is platform & configuration dependent (we assume pessimal |
| 2685 | * values here). |
| 2686 | * |
| 2687 | * The SR calculation is: |
| 2688 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 2689 | * bytes per pixel |
| 2690 | * where |
| 2691 | * line time = htotal / dotclock |
| 2692 | * surface width = hdisplay for normal plane and 64 for cursor |
| 2693 | * and latency is assumed to be high, as above. |
| 2694 | * |
| 2695 | * The final value programmed to the register should always be rounded up, |
| 2696 | * and include an extra 2 entries to account for clock crossings. |
| 2697 | * |
| 2698 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 2699 | * to set the non-SR watermarks to 8. |
| 2700 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2701 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2702 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2703 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2704 | |
| 2705 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2706 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2707 | } |
| 2708 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2709 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 2710 | struct drm_crtc *crtc, |
Paulo Zanoni | 4c4ff43 | 2013-05-24 11:59:17 -0300 | [diff] [blame] | 2711 | uint32_t sprite_width, int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2712 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2713 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2714 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2715 | |
| 2716 | if (dev_priv->display.update_sprite_wm) |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2717 | dev_priv->display.update_sprite_wm(plane, crtc, sprite_width, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2718 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2719 | } |
| 2720 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2721 | static struct drm_i915_gem_object * |
| 2722 | intel_alloc_context_page(struct drm_device *dev) |
| 2723 | { |
| 2724 | struct drm_i915_gem_object *ctx; |
| 2725 | int ret; |
| 2726 | |
| 2727 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2728 | |
| 2729 | ctx = i915_gem_alloc_object(dev, 4096); |
| 2730 | if (!ctx) { |
| 2731 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 2732 | return NULL; |
| 2733 | } |
| 2734 | |
Ben Widawsky | c37e220 | 2013-07-31 16:59:58 -0700 | [diff] [blame] | 2735 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, true, false); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2736 | if (ret) { |
| 2737 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 2738 | goto err_unref; |
| 2739 | } |
| 2740 | |
| 2741 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 2742 | if (ret) { |
| 2743 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 2744 | goto err_unpin; |
| 2745 | } |
| 2746 | |
| 2747 | return ctx; |
| 2748 | |
| 2749 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 2750 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2751 | err_unref: |
| 2752 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2753 | return NULL; |
| 2754 | } |
| 2755 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2756 | /** |
| 2757 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2758 | */ |
| 2759 | DEFINE_SPINLOCK(mchdev_lock); |
| 2760 | |
| 2761 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 2762 | * mchdev_lock. */ |
| 2763 | static struct drm_i915_private *i915_mch_dev; |
| 2764 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2765 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 2766 | { |
| 2767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2768 | u16 rgvswctl; |
| 2769 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2770 | assert_spin_locked(&mchdev_lock); |
| 2771 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2772 | rgvswctl = I915_READ16(MEMSWCTL); |
| 2773 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 2774 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 2775 | return false; /* still busy with another command */ |
| 2776 | } |
| 2777 | |
| 2778 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 2779 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 2780 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2781 | POSTING_READ16(MEMSWCTL); |
| 2782 | |
| 2783 | rgvswctl |= MEMCTL_CMD_STS; |
| 2784 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2785 | |
| 2786 | return true; |
| 2787 | } |
| 2788 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 2789 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2790 | { |
| 2791 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2792 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 2793 | u8 fmax, fmin, fstart, vstart; |
| 2794 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2795 | spin_lock_irq(&mchdev_lock); |
| 2796 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2797 | /* Enable temp reporting */ |
| 2798 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 2799 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 2800 | |
| 2801 | /* 100ms RC evaluation intervals */ |
| 2802 | I915_WRITE(RCUPEI, 100000); |
| 2803 | I915_WRITE(RCDNEI, 100000); |
| 2804 | |
| 2805 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 2806 | I915_WRITE(RCBMAXAVG, 90000); |
| 2807 | I915_WRITE(RCBMINAVG, 80000); |
| 2808 | |
| 2809 | I915_WRITE(MEMIHYST, 1); |
| 2810 | |
| 2811 | /* Set up min, max, and cur for interrupt handling */ |
| 2812 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 2813 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 2814 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 2815 | MEMMODE_FSTART_SHIFT; |
| 2816 | |
| 2817 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 2818 | PXVFREQ_PX_SHIFT; |
| 2819 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2820 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 2821 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2822 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2823 | dev_priv->ips.max_delay = fstart; |
| 2824 | dev_priv->ips.min_delay = fmin; |
| 2825 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2826 | |
| 2827 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 2828 | fmax, fmin, fstart); |
| 2829 | |
| 2830 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 2831 | |
| 2832 | /* |
| 2833 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 2834 | */ |
| 2835 | |
| 2836 | I915_WRITE(VIDSTART, vstart); |
| 2837 | POSTING_READ(VIDSTART); |
| 2838 | |
| 2839 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 2840 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 2841 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2842 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2843 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2844 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2845 | |
| 2846 | ironlake_set_drps(dev, fstart); |
| 2847 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2848 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2849 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2850 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 2851 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
| 2852 | getrawmonotonic(&dev_priv->ips.last_time2); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2853 | |
| 2854 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2855 | } |
| 2856 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 2857 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2858 | { |
| 2859 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2860 | u16 rgvswctl; |
| 2861 | |
| 2862 | spin_lock_irq(&mchdev_lock); |
| 2863 | |
| 2864 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2865 | |
| 2866 | /* Ack interrupts, disable EFC interrupt */ |
| 2867 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 2868 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 2869 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 2870 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 2871 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 2872 | |
| 2873 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 2874 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2875 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2876 | rgvswctl |= MEMCTL_CMD_STS; |
| 2877 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2878 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2879 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2880 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2881 | } |
| 2882 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 2883 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 2884 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 2885 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 2886 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 2887 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 2888 | 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] | 2889 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 2890 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2891 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 2892 | /* Only set the down limit when we've reached the lowest level to avoid |
| 2893 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 2894 | * race in the hw when coming out of rc6: There's a tiny window where |
| 2895 | * the hw runs at the minimal clock before selecting the desired |
| 2896 | * frequency, if the down threshold expires in that window we will not |
| 2897 | * receive a down interrupt. */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 2898 | limits = dev_priv->rps.max_delay << 24; |
| 2899 | if (val <= dev_priv->rps.min_delay) |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 2900 | limits |= dev_priv->rps.min_delay << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 2901 | |
| 2902 | return limits; |
| 2903 | } |
| 2904 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 2905 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 2906 | { |
| 2907 | int new_power; |
| 2908 | |
| 2909 | new_power = dev_priv->rps.power; |
| 2910 | switch (dev_priv->rps.power) { |
| 2911 | case LOW_POWER: |
| 2912 | if (val > dev_priv->rps.rpe_delay + 1 && val > dev_priv->rps.cur_delay) |
| 2913 | new_power = BETWEEN; |
| 2914 | break; |
| 2915 | |
| 2916 | case BETWEEN: |
| 2917 | if (val <= dev_priv->rps.rpe_delay && val < dev_priv->rps.cur_delay) |
| 2918 | new_power = LOW_POWER; |
| 2919 | else if (val >= dev_priv->rps.rp0_delay && val > dev_priv->rps.cur_delay) |
| 2920 | new_power = HIGH_POWER; |
| 2921 | break; |
| 2922 | |
| 2923 | case HIGH_POWER: |
| 2924 | if (val < (dev_priv->rps.rp1_delay + dev_priv->rps.rp0_delay) >> 1 && val < dev_priv->rps.cur_delay) |
| 2925 | new_power = BETWEEN; |
| 2926 | break; |
| 2927 | } |
| 2928 | /* Max/min bins are special */ |
| 2929 | if (val == dev_priv->rps.min_delay) |
| 2930 | new_power = LOW_POWER; |
| 2931 | if (val == dev_priv->rps.max_delay) |
| 2932 | new_power = HIGH_POWER; |
| 2933 | if (new_power == dev_priv->rps.power) |
| 2934 | return; |
| 2935 | |
| 2936 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 2937 | switch (new_power) { |
| 2938 | case LOW_POWER: |
| 2939 | /* Upclock if more than 95% busy over 16ms */ |
| 2940 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 2941 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 2942 | |
| 2943 | /* Downclock if less than 85% busy over 32ms */ |
| 2944 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 2945 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 2946 | |
| 2947 | I915_WRITE(GEN6_RP_CONTROL, |
| 2948 | GEN6_RP_MEDIA_TURBO | |
| 2949 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 2950 | GEN6_RP_MEDIA_IS_GFX | |
| 2951 | GEN6_RP_ENABLE | |
| 2952 | GEN6_RP_UP_BUSY_AVG | |
| 2953 | GEN6_RP_DOWN_IDLE_AVG); |
| 2954 | break; |
| 2955 | |
| 2956 | case BETWEEN: |
| 2957 | /* Upclock if more than 90% busy over 13ms */ |
| 2958 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 2959 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 2960 | |
| 2961 | /* Downclock if less than 75% busy over 32ms */ |
| 2962 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 2963 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 2964 | |
| 2965 | I915_WRITE(GEN6_RP_CONTROL, |
| 2966 | GEN6_RP_MEDIA_TURBO | |
| 2967 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 2968 | GEN6_RP_MEDIA_IS_GFX | |
| 2969 | GEN6_RP_ENABLE | |
| 2970 | GEN6_RP_UP_BUSY_AVG | |
| 2971 | GEN6_RP_DOWN_IDLE_AVG); |
| 2972 | break; |
| 2973 | |
| 2974 | case HIGH_POWER: |
| 2975 | /* Upclock if more than 85% busy over 10ms */ |
| 2976 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 2977 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 2978 | |
| 2979 | /* Downclock if less than 60% busy over 32ms */ |
| 2980 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 2981 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 2982 | |
| 2983 | I915_WRITE(GEN6_RP_CONTROL, |
| 2984 | GEN6_RP_MEDIA_TURBO | |
| 2985 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 2986 | GEN6_RP_MEDIA_IS_GFX | |
| 2987 | GEN6_RP_ENABLE | |
| 2988 | GEN6_RP_UP_BUSY_AVG | |
| 2989 | GEN6_RP_DOWN_IDLE_AVG); |
| 2990 | break; |
| 2991 | } |
| 2992 | |
| 2993 | dev_priv->rps.power = new_power; |
| 2994 | dev_priv->rps.last_adj = 0; |
| 2995 | } |
| 2996 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 2997 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 2998 | { |
| 2999 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3000 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3001 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 7924963 | 2012-09-07 19:43:42 -0700 | [diff] [blame] | 3002 | WARN_ON(val > dev_priv->rps.max_delay); |
| 3003 | WARN_ON(val < dev_priv->rps.min_delay); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3004 | |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3005 | if (val == dev_priv->rps.cur_delay) |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3006 | return; |
| 3007 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3008 | gen6_set_rps_thresholds(dev_priv, val); |
| 3009 | |
Rodrigo Vivi | 92bd1bf | 2013-03-25 17:55:49 -0300 | [diff] [blame] | 3010 | if (IS_HASWELL(dev)) |
| 3011 | I915_WRITE(GEN6_RPNSWREQ, |
| 3012 | HSW_FREQUENCY(val)); |
| 3013 | else |
| 3014 | I915_WRITE(GEN6_RPNSWREQ, |
| 3015 | GEN6_FREQUENCY(val) | |
| 3016 | GEN6_OFFSET(0) | |
| 3017 | GEN6_AGGRESSIVE_TURBO); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3018 | |
| 3019 | /* Make sure we continue to get interrupts |
| 3020 | * until we hit the minimum or maximum frequencies. |
| 3021 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3022 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 3023 | gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3024 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3025 | POSTING_READ(GEN6_RPNSWREQ); |
| 3026 | |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3027 | dev_priv->rps.cur_delay = val; |
Daniel Vetter | be2cde9 | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3028 | |
| 3029 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3030 | } |
| 3031 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3032 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3033 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3034 | struct drm_device *dev = dev_priv->dev; |
| 3035 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3036 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3037 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3038 | if (IS_VALLEYVIEW(dev)) |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3039 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_delay); |
| 3040 | else |
| 3041 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_delay); |
| 3042 | dev_priv->rps.last_adj = 0; |
| 3043 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3044 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3045 | } |
| 3046 | |
| 3047 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3048 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3049 | struct drm_device *dev = dev_priv->dev; |
| 3050 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3051 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3052 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3053 | if (IS_VALLEYVIEW(dev)) |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3054 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_delay); |
| 3055 | else |
| 3056 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_delay); |
| 3057 | dev_priv->rps.last_adj = 0; |
| 3058 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3059 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3060 | } |
| 3061 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3062 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3063 | { |
| 3064 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 3065 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3066 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 3067 | WARN_ON(val > dev_priv->rps.max_delay); |
| 3068 | WARN_ON(val < dev_priv->rps.min_delay); |
| 3069 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3070 | DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n", |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3071 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_delay), |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3072 | dev_priv->rps.cur_delay, |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3073 | vlv_gpu_freq(dev_priv, val), val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3074 | |
| 3075 | if (val == dev_priv->rps.cur_delay) |
| 3076 | return; |
| 3077 | |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 3078 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3079 | |
Ville Syrjälä | 80814ae | 2013-06-25 19:21:02 +0300 | [diff] [blame] | 3080 | dev_priv->rps.cur_delay = val; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3081 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3082 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3085 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3086 | { |
| 3087 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3088 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3089 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Ben Widawsky | 4848405 | 2013-05-28 19:22:27 -0700 | [diff] [blame] | 3090 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & ~GEN6_PM_RPS_EVENTS); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3091 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3092 | * item again unmasking PM interrupts because that is using a different |
| 3093 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 3094 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 3095 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3096 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3097 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3098 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3099 | |
Ben Widawsky | 4848405 | 2013-05-28 19:22:27 -0700 | [diff] [blame] | 3100 | I915_WRITE(GEN6_PMIIR, GEN6_PM_RPS_EVENTS); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3101 | } |
| 3102 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3103 | static void gen6_disable_rps(struct drm_device *dev) |
| 3104 | { |
| 3105 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3106 | |
| 3107 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3108 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 3109 | |
| 3110 | gen6_disable_rps_interrupts(dev); |
| 3111 | } |
| 3112 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3113 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3114 | { |
| 3115 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3116 | |
| 3117 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3118 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3119 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3120 | |
| 3121 | if (dev_priv->vlv_pctx) { |
| 3122 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 3123 | dev_priv->vlv_pctx = NULL; |
| 3124 | } |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3127 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3128 | { |
| 3129 | if (IS_GEN6(dev)) |
| 3130 | DRM_DEBUG_DRIVER("Sandybridge: deep RC6 disabled\n"); |
| 3131 | |
| 3132 | if (IS_HASWELL(dev)) |
| 3133 | DRM_DEBUG_DRIVER("Haswell: only RC6 available\n"); |
| 3134 | |
| 3135 | DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n", |
| 3136 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3137 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3138 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 3139 | } |
| 3140 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3141 | int intel_enable_rc6(const struct drm_device *dev) |
| 3142 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3143 | /* No RC6 before Ironlake */ |
| 3144 | if (INTEL_INFO(dev)->gen < 5) |
| 3145 | return 0; |
| 3146 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3147 | /* Respect the kernel parameter if it is set */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3148 | if (i915_enable_rc6 >= 0) |
| 3149 | return i915_enable_rc6; |
| 3150 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3151 | /* Disable RC6 on Ironlake */ |
| 3152 | if (INTEL_INFO(dev)->gen == 5) |
| 3153 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3154 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3155 | if (IS_HASWELL(dev)) |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3156 | return INTEL_RC6_ENABLE; |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3157 | |
| 3158 | /* snb/ivb have more than one rc6 state. */ |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3159 | if (INTEL_INFO(dev)->gen == 6) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3160 | return INTEL_RC6_ENABLE; |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3161 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3162 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
| 3163 | } |
| 3164 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3165 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 3166 | { |
| 3167 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | a9c1f90 | 2013-08-22 21:09:00 +0300 | [diff] [blame] | 3168 | u32 enabled_intrs; |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3169 | |
| 3170 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 3171 | WARN_ON(dev_priv->rps.pm_iir); |
Paulo Zanoni | edbfdb4 | 2013-08-06 18:57:13 -0300 | [diff] [blame] | 3172 | snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3173 | I915_WRITE(GEN6_PMIIR, GEN6_PM_RPS_EVENTS); |
| 3174 | spin_unlock_irq(&dev_priv->irq_lock); |
Mika Kuoppala | a9c1f90 | 2013-08-22 21:09:00 +0300 | [diff] [blame] | 3175 | |
Vinit Azad | fd547d2 | 2013-08-14 13:34:33 -0700 | [diff] [blame] | 3176 | /* only unmask PM interrupts we need. Mask all others. */ |
Mika Kuoppala | a9c1f90 | 2013-08-22 21:09:00 +0300 | [diff] [blame] | 3177 | enabled_intrs = GEN6_PM_RPS_EVENTS; |
| 3178 | |
| 3179 | /* IVB and SNB hard hangs on looping batchbuffer |
| 3180 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 3181 | */ |
| 3182 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 3183 | enabled_intrs |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 3184 | |
| 3185 | I915_WRITE(GEN6_PMINTRMSK, ~enabled_intrs); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3186 | } |
| 3187 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3188 | static void gen8_enable_rps(struct drm_device *dev) |
| 3189 | { |
| 3190 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3191 | struct intel_ring_buffer *ring; |
| 3192 | uint32_t rc6_mask = 0, rp_state_cap; |
| 3193 | int unused; |
| 3194 | |
| 3195 | /* 1a: Software RC state - RC0 */ |
| 3196 | I915_WRITE(GEN6_RC_STATE, 0); |
| 3197 | |
| 3198 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 3199 | * 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] | 3200 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3201 | |
| 3202 | /* 2a: Disable RC states. */ |
| 3203 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3204 | |
| 3205 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
| 3206 | |
| 3207 | /* 2b: Program RC6 thresholds.*/ |
| 3208 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 3209 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 3210 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 3211 | for_each_ring(ring, dev_priv, unused) |
| 3212 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3213 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3214 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 3215 | |
| 3216 | /* 3: Enable RC6 */ |
| 3217 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 3218 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 3219 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
| 3220 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3221 | GEN6_RC_CTL_EI_MODE(1) | |
| 3222 | rc6_mask); |
| 3223 | |
| 3224 | /* 4 Program defaults and thresholds for RPS*/ |
| 3225 | I915_WRITE(GEN6_RPNSWREQ, HSW_FREQUENCY(10)); /* Request 500 MHz */ |
| 3226 | I915_WRITE(GEN6_RC_VIDEO_FREQ, HSW_FREQUENCY(12)); /* Request 600 MHz */ |
| 3227 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 3228 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
| 3229 | |
| 3230 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 3231 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 3232 | dev_priv->rps.max_delay << 24 | |
| 3233 | dev_priv->rps.min_delay << 16); |
| 3234 | |
| 3235 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 3236 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 3237 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 3238 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
| 3239 | |
| 3240 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3241 | |
| 3242 | /* 5: Enable RPS */ |
| 3243 | I915_WRITE(GEN6_RP_CONTROL, |
| 3244 | GEN6_RP_MEDIA_TURBO | |
| 3245 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3246 | GEN6_RP_MEDIA_IS_GFX | |
| 3247 | GEN6_RP_ENABLE | |
| 3248 | GEN6_RP_UP_BUSY_AVG | |
| 3249 | GEN6_RP_DOWN_IDLE_AVG); |
| 3250 | |
| 3251 | /* 6: Ring frequency + overclocking (our driver does this later */ |
| 3252 | |
| 3253 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
| 3254 | |
| 3255 | gen6_enable_rps_interrupts(dev); |
| 3256 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3257 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3260 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3261 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3262 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3263 | struct intel_ring_buffer *ring; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3264 | u32 rp_state_cap; |
| 3265 | u32 gt_perf_status; |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 3266 | u32 rc6vids, pcu_mbox, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3267 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3268 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3269 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3270 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3271 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3272 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3273 | /* Here begins a magic sequence of register writes to enable |
| 3274 | * auto-downclocking. |
| 3275 | * |
| 3276 | * Perhaps there might be some value in exposing these to |
| 3277 | * userspace... |
| 3278 | */ |
| 3279 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3280 | |
| 3281 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 3282 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 3283 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 3284 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3285 | } |
| 3286 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3287 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3288 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3289 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
| 3290 | gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS); |
| 3291 | |
Ben Widawsky | 31c7738 | 2013-04-05 14:29:22 -0700 | [diff] [blame] | 3292 | /* In units of 50MHz */ |
| 3293 | dev_priv->rps.hw_max = dev_priv->rps.max_delay = rp_state_cap & 0xff; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3294 | dev_priv->rps.min_delay = (rp_state_cap >> 16) & 0xff; |
| 3295 | dev_priv->rps.rp1_delay = (rp_state_cap >> 8) & 0xff; |
| 3296 | dev_priv->rps.rp0_delay = (rp_state_cap >> 0) & 0xff; |
| 3297 | dev_priv->rps.rpe_delay = dev_priv->rps.rp1_delay; |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3298 | dev_priv->rps.cur_delay = 0; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3299 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3300 | /* disable the counters and set deterministic thresholds */ |
| 3301 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3302 | |
| 3303 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 3304 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 3305 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 3306 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3307 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3308 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3309 | for_each_ring(ring, dev_priv, i) |
| 3310 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3311 | |
| 3312 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3313 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 3314 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 3315 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 3316 | else |
| 3317 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 3318 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3319 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 3320 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3321 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3322 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 3323 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 3324 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 3325 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3326 | /* We don't use those on Haswell */ |
| 3327 | if (!IS_HASWELL(dev)) { |
| 3328 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 3329 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3330 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3331 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 3332 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 3333 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3334 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3335 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3336 | |
| 3337 | I915_WRITE(GEN6_RC_CONTROL, |
| 3338 | rc6_mask | |
| 3339 | GEN6_RC_CTL_EI_MODE(1) | |
| 3340 | GEN6_RC_CTL_HW_ENABLE); |
| 3341 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3342 | /* Power down if completely idle for over 50ms */ |
| 3343 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3344 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3345 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3346 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_MIN_FREQ_TABLE, 0); |
Ben Widawsky | 988b36e | 2013-04-23 17:33:02 -0700 | [diff] [blame] | 3347 | if (!ret) { |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3348 | pcu_mbox = 0; |
| 3349 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
Ben Widawsky | a2b3fc0 | 2013-03-19 20:19:56 -0700 | [diff] [blame] | 3350 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
Ben Widawsky | 10e0849 | 2013-04-05 14:29:23 -0700 | [diff] [blame] | 3351 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | a2b3fc0 | 2013-03-19 20:19:56 -0700 | [diff] [blame] | 3352 | (dev_priv->rps.max_delay & 0xff) * 50, |
| 3353 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | 31c7738 | 2013-04-05 14:29:22 -0700 | [diff] [blame] | 3354 | dev_priv->rps.hw_max = pcu_mbox & 0xff; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3355 | } |
| 3356 | } else { |
| 3357 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3358 | } |
| 3359 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3360 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 3361 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_delay); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3362 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3363 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3364 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 3365 | rc6vids = 0; |
| 3366 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 3367 | if (IS_GEN6(dev) && ret) { |
| 3368 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 3369 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 3370 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 3371 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 3372 | rc6vids &= 0xffff00; |
| 3373 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 3374 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 3375 | if (ret) |
| 3376 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 3377 | } |
| 3378 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3379 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3380 | } |
| 3381 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 3382 | void gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3383 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3384 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3385 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3386 | unsigned int gpu_freq; |
| 3387 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3388 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3389 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3390 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3391 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3392 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3393 | policy = cpufreq_cpu_get(0); |
| 3394 | if (policy) { |
| 3395 | max_ia_freq = policy->cpuinfo.max_freq; |
| 3396 | cpufreq_cpu_put(policy); |
| 3397 | } else { |
| 3398 | /* |
| 3399 | * Default to measured freq if none found, PCU will ensure we |
| 3400 | * don't go over |
| 3401 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3402 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3403 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3404 | |
| 3405 | /* Convert from kHz to MHz */ |
| 3406 | max_ia_freq /= 1000; |
| 3407 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 3408 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3409 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 3410 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3411 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3412 | /* |
| 3413 | * For each potential GPU frequency, load a ring frequency we'd like |
| 3414 | * to use for memory access. We do this by specifying the IA frequency |
| 3415 | * the PCU should use as a reference to determine the ring frequency. |
| 3416 | */ |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3417 | for (gpu_freq = dev_priv->rps.max_delay; gpu_freq >= dev_priv->rps.min_delay; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3418 | gpu_freq--) { |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3419 | int diff = dev_priv->rps.max_delay - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3420 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3421 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 3422 | if (INTEL_INFO(dev)->gen >= 8) { |
| 3423 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 3424 | ring_freq = max(min_ring_freq, gpu_freq); |
| 3425 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3426 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3427 | ring_freq = max(min_ring_freq, ring_freq); |
| 3428 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 3429 | } else { |
| 3430 | /* On older processors, there is no separate ring |
| 3431 | * clock domain, so in order to boost the bandwidth |
| 3432 | * of the ring, we need to upclock the CPU (ia_freq). |
| 3433 | * |
| 3434 | * For GPU frequencies less than 750MHz, |
| 3435 | * just use the lowest ring freq. |
| 3436 | */ |
| 3437 | if (gpu_freq < min_freq) |
| 3438 | ia_freq = 800; |
| 3439 | else |
| 3440 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 3441 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 3442 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3443 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3444 | sandybridge_pcode_write(dev_priv, |
| 3445 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3446 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 3447 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 3448 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3449 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3450 | } |
| 3451 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3452 | int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
| 3453 | { |
| 3454 | u32 val, rp0; |
| 3455 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3456 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3457 | |
| 3458 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 3459 | /* Clamp to max */ |
| 3460 | rp0 = min_t(u32, rp0, 0xea); |
| 3461 | |
| 3462 | return rp0; |
| 3463 | } |
| 3464 | |
| 3465 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 3466 | { |
| 3467 | u32 val, rpe; |
| 3468 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3469 | 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] | 3470 | 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] | 3471 | 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] | 3472 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 3473 | |
| 3474 | return rpe; |
| 3475 | } |
| 3476 | |
| 3477 | int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 3478 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3479 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3482 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 3483 | { |
| 3484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3485 | struct drm_i915_gem_object *pctx; |
| 3486 | unsigned long pctx_paddr; |
| 3487 | u32 pcbr; |
| 3488 | int pctx_size = 24*1024; |
| 3489 | |
| 3490 | pcbr = I915_READ(VLV_PCBR); |
| 3491 | if (pcbr) { |
| 3492 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 3493 | int pcbr_offset; |
| 3494 | |
| 3495 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 3496 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 3497 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 3498 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3499 | pctx_size); |
| 3500 | goto out; |
| 3501 | } |
| 3502 | |
| 3503 | /* |
| 3504 | * From the Gunit register HAS: |
| 3505 | * The Gfx driver is expected to program this register and ensure |
| 3506 | * proper allocation within Gfx stolen memory. For example, this |
| 3507 | * register should be programmed such than the PCBR range does not |
| 3508 | * overlap with other ranges, such as the frame buffer, protected |
| 3509 | * memory, or any other relevant ranges. |
| 3510 | */ |
| 3511 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 3512 | if (!pctx) { |
| 3513 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 3514 | return; |
| 3515 | } |
| 3516 | |
| 3517 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 3518 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 3519 | |
| 3520 | out: |
| 3521 | dev_priv->vlv_pctx = pctx; |
| 3522 | } |
| 3523 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3524 | static void valleyview_enable_rps(struct drm_device *dev) |
| 3525 | { |
| 3526 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3527 | struct intel_ring_buffer *ring; |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 3528 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3529 | int i; |
| 3530 | |
| 3531 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 3532 | |
| 3533 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 3534 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 3535 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3536 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3537 | } |
| 3538 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3539 | valleyview_setup_pctx(dev); |
| 3540 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3541 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 3542 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3543 | |
| 3544 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 3545 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 3546 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 3547 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 3548 | |
| 3549 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3550 | |
| 3551 | I915_WRITE(GEN6_RP_CONTROL, |
| 3552 | GEN6_RP_MEDIA_TURBO | |
| 3553 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3554 | GEN6_RP_MEDIA_IS_GFX | |
| 3555 | GEN6_RP_ENABLE | |
| 3556 | GEN6_RP_UP_BUSY_AVG | |
| 3557 | GEN6_RP_DOWN_IDLE_CONT); |
| 3558 | |
| 3559 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 3560 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3561 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3562 | |
| 3563 | for_each_ring(ring, dev_priv, i) |
| 3564 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3565 | |
Jesse Barnes | 2f0aa30 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 3566 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3567 | |
| 3568 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 3569 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 3570 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 3571 | VLV_MEDIA_RC6_COUNT_EN | |
| 3572 | VLV_RENDER_RC6_COUNT_EN)); |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 3573 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 3574 | 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] | 3575 | |
| 3576 | intel_print_rc6_info(dev, rc6_mode); |
| 3577 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 3578 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3579 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3580 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3581 | |
| 3582 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 3583 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 3584 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3585 | dev_priv->rps.cur_delay = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3586 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3587 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_delay), |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3588 | dev_priv->rps.cur_delay); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3589 | |
| 3590 | dev_priv->rps.max_delay = valleyview_rps_max_freq(dev_priv); |
| 3591 | dev_priv->rps.hw_max = dev_priv->rps.max_delay; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3592 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3593 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_delay), |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3594 | dev_priv->rps.max_delay); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3595 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3596 | dev_priv->rps.rpe_delay = valleyview_rps_rpe_freq(dev_priv); |
| 3597 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3598 | vlv_gpu_freq(dev_priv, dev_priv->rps.rpe_delay), |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3599 | dev_priv->rps.rpe_delay); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3600 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3601 | dev_priv->rps.min_delay = valleyview_rps_min_freq(dev_priv); |
| 3602 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3603 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_delay), |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3604 | dev_priv->rps.min_delay); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3605 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3606 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3607 | vlv_gpu_freq(dev_priv, dev_priv->rps.rpe_delay), |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3608 | dev_priv->rps.rpe_delay); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3609 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3610 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.rpe_delay); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3611 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3612 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3613 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3614 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 3617 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3618 | { |
| 3619 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3620 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3621 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3622 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3623 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 3624 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3625 | } |
| 3626 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3627 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3628 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3629 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 3630 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 3634 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3635 | { |
| 3636 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3637 | |
| 3638 | if (I915_READ(PWRCTXA)) { |
| 3639 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 3640 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 3641 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 3642 | 50); |
| 3643 | |
| 3644 | I915_WRITE(PWRCTXA, 0); |
| 3645 | POSTING_READ(PWRCTXA); |
| 3646 | |
| 3647 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 3648 | POSTING_READ(RSTDBYCTL); |
| 3649 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 3653 | { |
| 3654 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3655 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3656 | if (dev_priv->ips.renderctx == NULL) |
| 3657 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 3658 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3659 | return -ENOMEM; |
| 3660 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 3661 | if (dev_priv->ips.pwrctx == NULL) |
| 3662 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 3663 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3664 | ironlake_teardown_rc6(dev); |
| 3665 | return -ENOMEM; |
| 3666 | } |
| 3667 | |
| 3668 | return 0; |
| 3669 | } |
| 3670 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 3671 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3672 | { |
| 3673 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3674 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3675 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3676 | int ret; |
| 3677 | |
| 3678 | /* rc6 disabled by default due to repeated reports of hanging during |
| 3679 | * boot and resume. |
| 3680 | */ |
| 3681 | if (!intel_enable_rc6(dev)) |
| 3682 | return; |
| 3683 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3684 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3685 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3686 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3687 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3688 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3689 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3690 | was_interruptible = dev_priv->mm.interruptible; |
| 3691 | dev_priv->mm.interruptible = false; |
| 3692 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3693 | /* |
| 3694 | * GPU can automatically power down the render unit if given a page |
| 3695 | * to save state. |
| 3696 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3697 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3698 | if (ret) { |
| 3699 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3700 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3701 | return; |
| 3702 | } |
| 3703 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 3704 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 3705 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 3706 | 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] | 3707 | MI_MM_SPACE_GTT | |
| 3708 | MI_SAVE_EXT_STATE_EN | |
| 3709 | MI_RESTORE_EXT_STATE_EN | |
| 3710 | MI_RESTORE_INHIBIT); |
| 3711 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 3712 | intel_ring_emit(ring, MI_NOOP); |
| 3713 | intel_ring_emit(ring, MI_FLUSH); |
| 3714 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3715 | |
| 3716 | /* |
| 3717 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 3718 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 3719 | * safe to assume that renderctx is valid |
| 3720 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 3721 | ret = intel_ring_idle(ring); |
| 3722 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3723 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 3724 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3725 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3726 | return; |
| 3727 | } |
| 3728 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 3729 | 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] | 3730 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3731 | |
| 3732 | intel_print_rc6_info(dev, INTEL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3733 | } |
| 3734 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 3735 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 3736 | { |
| 3737 | unsigned long freq; |
| 3738 | int div = (vidfreq & 0x3f0000) >> 16; |
| 3739 | int post = (vidfreq & 0x3000) >> 12; |
| 3740 | int pre = (vidfreq & 0x7); |
| 3741 | |
| 3742 | if (!pre) |
| 3743 | return 0; |
| 3744 | |
| 3745 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 3746 | |
| 3747 | return freq; |
| 3748 | } |
| 3749 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3750 | static const struct cparams { |
| 3751 | u16 i; |
| 3752 | u16 t; |
| 3753 | u16 m; |
| 3754 | u16 c; |
| 3755 | } cparams[] = { |
| 3756 | { 1, 1333, 301, 28664 }, |
| 3757 | { 1, 1066, 294, 24460 }, |
| 3758 | { 1, 800, 294, 25192 }, |
| 3759 | { 0, 1333, 276, 27605 }, |
| 3760 | { 0, 1066, 276, 27605 }, |
| 3761 | { 0, 800, 231, 23784 }, |
| 3762 | }; |
| 3763 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 3764 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3765 | { |
| 3766 | u64 total_count, diff, ret; |
| 3767 | u32 count1, count2, count3, m = 0, c = 0; |
| 3768 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 3769 | int i; |
| 3770 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 3771 | assert_spin_locked(&mchdev_lock); |
| 3772 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3773 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3774 | |
| 3775 | /* Prevent division-by-zero if we are asking too fast. |
| 3776 | * Also, we don't get interesting results if we are polling |
| 3777 | * faster than once in 10ms, so just return the saved value |
| 3778 | * in such cases. |
| 3779 | */ |
| 3780 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3781 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3782 | |
| 3783 | count1 = I915_READ(DMIEC); |
| 3784 | count2 = I915_READ(DDREC); |
| 3785 | count3 = I915_READ(CSIEC); |
| 3786 | |
| 3787 | total_count = count1 + count2 + count3; |
| 3788 | |
| 3789 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3790 | if (total_count < dev_priv->ips.last_count1) { |
| 3791 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3792 | diff += total_count; |
| 3793 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3794 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3798 | if (cparams[i].i == dev_priv->ips.c_m && |
| 3799 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3800 | m = cparams[i].m; |
| 3801 | c = cparams[i].c; |
| 3802 | break; |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | diff = div_u64(diff, diff1); |
| 3807 | ret = ((m * diff) + c); |
| 3808 | ret = div_u64(ret, 10); |
| 3809 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3810 | dev_priv->ips.last_count1 = total_count; |
| 3811 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3812 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3813 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3814 | |
| 3815 | return ret; |
| 3816 | } |
| 3817 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 3818 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 3819 | { |
| 3820 | unsigned long val; |
| 3821 | |
| 3822 | if (dev_priv->info->gen != 5) |
| 3823 | return 0; |
| 3824 | |
| 3825 | spin_lock_irq(&mchdev_lock); |
| 3826 | |
| 3827 | val = __i915_chipset_val(dev_priv); |
| 3828 | |
| 3829 | spin_unlock_irq(&mchdev_lock); |
| 3830 | |
| 3831 | return val; |
| 3832 | } |
| 3833 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3834 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 3835 | { |
| 3836 | unsigned long m, x, b; |
| 3837 | u32 tsfs; |
| 3838 | |
| 3839 | tsfs = I915_READ(TSFS); |
| 3840 | |
| 3841 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 3842 | x = I915_READ8(TR1); |
| 3843 | |
| 3844 | b = tsfs & TSFS_INTR_MASK; |
| 3845 | |
| 3846 | return ((m * x) / 127) - b; |
| 3847 | } |
| 3848 | |
| 3849 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 3850 | { |
| 3851 | static const struct v_table { |
| 3852 | u16 vd; /* in .1 mil */ |
| 3853 | u16 vm; /* in .1 mil */ |
| 3854 | } v_table[] = { |
| 3855 | { 0, 0, }, |
| 3856 | { 375, 0, }, |
| 3857 | { 500, 0, }, |
| 3858 | { 625, 0, }, |
| 3859 | { 750, 0, }, |
| 3860 | { 875, 0, }, |
| 3861 | { 1000, 0, }, |
| 3862 | { 1125, 0, }, |
| 3863 | { 4125, 3000, }, |
| 3864 | { 4125, 3000, }, |
| 3865 | { 4125, 3000, }, |
| 3866 | { 4125, 3000, }, |
| 3867 | { 4125, 3000, }, |
| 3868 | { 4125, 3000, }, |
| 3869 | { 4125, 3000, }, |
| 3870 | { 4125, 3000, }, |
| 3871 | { 4125, 3000, }, |
| 3872 | { 4125, 3000, }, |
| 3873 | { 4125, 3000, }, |
| 3874 | { 4125, 3000, }, |
| 3875 | { 4125, 3000, }, |
| 3876 | { 4125, 3000, }, |
| 3877 | { 4125, 3000, }, |
| 3878 | { 4125, 3000, }, |
| 3879 | { 4125, 3000, }, |
| 3880 | { 4125, 3000, }, |
| 3881 | { 4125, 3000, }, |
| 3882 | { 4125, 3000, }, |
| 3883 | { 4125, 3000, }, |
| 3884 | { 4125, 3000, }, |
| 3885 | { 4125, 3000, }, |
| 3886 | { 4125, 3000, }, |
| 3887 | { 4250, 3125, }, |
| 3888 | { 4375, 3250, }, |
| 3889 | { 4500, 3375, }, |
| 3890 | { 4625, 3500, }, |
| 3891 | { 4750, 3625, }, |
| 3892 | { 4875, 3750, }, |
| 3893 | { 5000, 3875, }, |
| 3894 | { 5125, 4000, }, |
| 3895 | { 5250, 4125, }, |
| 3896 | { 5375, 4250, }, |
| 3897 | { 5500, 4375, }, |
| 3898 | { 5625, 4500, }, |
| 3899 | { 5750, 4625, }, |
| 3900 | { 5875, 4750, }, |
| 3901 | { 6000, 4875, }, |
| 3902 | { 6125, 5000, }, |
| 3903 | { 6250, 5125, }, |
| 3904 | { 6375, 5250, }, |
| 3905 | { 6500, 5375, }, |
| 3906 | { 6625, 5500, }, |
| 3907 | { 6750, 5625, }, |
| 3908 | { 6875, 5750, }, |
| 3909 | { 7000, 5875, }, |
| 3910 | { 7125, 6000, }, |
| 3911 | { 7250, 6125, }, |
| 3912 | { 7375, 6250, }, |
| 3913 | { 7500, 6375, }, |
| 3914 | { 7625, 6500, }, |
| 3915 | { 7750, 6625, }, |
| 3916 | { 7875, 6750, }, |
| 3917 | { 8000, 6875, }, |
| 3918 | { 8125, 7000, }, |
| 3919 | { 8250, 7125, }, |
| 3920 | { 8375, 7250, }, |
| 3921 | { 8500, 7375, }, |
| 3922 | { 8625, 7500, }, |
| 3923 | { 8750, 7625, }, |
| 3924 | { 8875, 7750, }, |
| 3925 | { 9000, 7875, }, |
| 3926 | { 9125, 8000, }, |
| 3927 | { 9250, 8125, }, |
| 3928 | { 9375, 8250, }, |
| 3929 | { 9500, 8375, }, |
| 3930 | { 9625, 8500, }, |
| 3931 | { 9750, 8625, }, |
| 3932 | { 9875, 8750, }, |
| 3933 | { 10000, 8875, }, |
| 3934 | { 10125, 9000, }, |
| 3935 | { 10250, 9125, }, |
| 3936 | { 10375, 9250, }, |
| 3937 | { 10500, 9375, }, |
| 3938 | { 10625, 9500, }, |
| 3939 | { 10750, 9625, }, |
| 3940 | { 10875, 9750, }, |
| 3941 | { 11000, 9875, }, |
| 3942 | { 11125, 10000, }, |
| 3943 | { 11250, 10125, }, |
| 3944 | { 11375, 10250, }, |
| 3945 | { 11500, 10375, }, |
| 3946 | { 11625, 10500, }, |
| 3947 | { 11750, 10625, }, |
| 3948 | { 11875, 10750, }, |
| 3949 | { 12000, 10875, }, |
| 3950 | { 12125, 11000, }, |
| 3951 | { 12250, 11125, }, |
| 3952 | { 12375, 11250, }, |
| 3953 | { 12500, 11375, }, |
| 3954 | { 12625, 11500, }, |
| 3955 | { 12750, 11625, }, |
| 3956 | { 12875, 11750, }, |
| 3957 | { 13000, 11875, }, |
| 3958 | { 13125, 12000, }, |
| 3959 | { 13250, 12125, }, |
| 3960 | { 13375, 12250, }, |
| 3961 | { 13500, 12375, }, |
| 3962 | { 13625, 12500, }, |
| 3963 | { 13750, 12625, }, |
| 3964 | { 13875, 12750, }, |
| 3965 | { 14000, 12875, }, |
| 3966 | { 14125, 13000, }, |
| 3967 | { 14250, 13125, }, |
| 3968 | { 14375, 13250, }, |
| 3969 | { 14500, 13375, }, |
| 3970 | { 14625, 13500, }, |
| 3971 | { 14750, 13625, }, |
| 3972 | { 14875, 13750, }, |
| 3973 | { 15000, 13875, }, |
| 3974 | { 15125, 14000, }, |
| 3975 | { 15250, 14125, }, |
| 3976 | { 15375, 14250, }, |
| 3977 | { 15500, 14375, }, |
| 3978 | { 15625, 14500, }, |
| 3979 | { 15750, 14625, }, |
| 3980 | { 15875, 14750, }, |
| 3981 | { 16000, 14875, }, |
| 3982 | { 16125, 15000, }, |
| 3983 | }; |
| 3984 | if (dev_priv->info->is_mobile) |
| 3985 | return v_table[pxvid].vm; |
| 3986 | else |
| 3987 | return v_table[pxvid].vd; |
| 3988 | } |
| 3989 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 3990 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3991 | { |
| 3992 | struct timespec now, diff1; |
| 3993 | u64 diff; |
| 3994 | unsigned long diffms; |
| 3995 | u32 count; |
| 3996 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 3997 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 3998 | |
| 3999 | getrawmonotonic(&now); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4000 | diff1 = timespec_sub(now, dev_priv->ips.last_time2); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4001 | |
| 4002 | /* Don't divide by 0 */ |
| 4003 | diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; |
| 4004 | if (!diffms) |
| 4005 | return; |
| 4006 | |
| 4007 | count = I915_READ(GFXEC); |
| 4008 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4009 | if (count < dev_priv->ips.last_count2) { |
| 4010 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4011 | diff += count; |
| 4012 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4013 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4014 | } |
| 4015 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4016 | dev_priv->ips.last_count2 = count; |
| 4017 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4018 | |
| 4019 | /* More magic constants... */ |
| 4020 | diff = diff * 1181; |
| 4021 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4022 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4023 | } |
| 4024 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4025 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 4026 | { |
| 4027 | if (dev_priv->info->gen != 5) |
| 4028 | return; |
| 4029 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4030 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4031 | |
| 4032 | __i915_update_gfx_val(dev_priv); |
| 4033 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4034 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4035 | } |
| 4036 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4037 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4038 | { |
| 4039 | unsigned long t, corr, state1, corr2, state2; |
| 4040 | u32 pxvid, ext_v; |
| 4041 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4042 | assert_spin_locked(&mchdev_lock); |
| 4043 | |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 4044 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_delay * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4045 | pxvid = (pxvid >> 24) & 0x7f; |
| 4046 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 4047 | |
| 4048 | state1 = ext_v; |
| 4049 | |
| 4050 | t = i915_mch_val(dev_priv); |
| 4051 | |
| 4052 | /* Revel in the empirically derived constants */ |
| 4053 | |
| 4054 | /* Correction factor in 1/100000 units */ |
| 4055 | if (t > 80) |
| 4056 | corr = ((t * 2349) + 135940); |
| 4057 | else if (t >= 50) |
| 4058 | corr = ((t * 964) + 29317); |
| 4059 | else /* < 50 */ |
| 4060 | corr = ((t * 301) + 1004); |
| 4061 | |
| 4062 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 4063 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4064 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4065 | |
| 4066 | state2 = (corr2 * state1) / 10000; |
| 4067 | state2 /= 100; /* convert to mW */ |
| 4068 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4069 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4070 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4071 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4072 | } |
| 4073 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4074 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 4075 | { |
| 4076 | unsigned long val; |
| 4077 | |
| 4078 | if (dev_priv->info->gen != 5) |
| 4079 | return 0; |
| 4080 | |
| 4081 | spin_lock_irq(&mchdev_lock); |
| 4082 | |
| 4083 | val = __i915_gfx_val(dev_priv); |
| 4084 | |
| 4085 | spin_unlock_irq(&mchdev_lock); |
| 4086 | |
| 4087 | return val; |
| 4088 | } |
| 4089 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4090 | /** |
| 4091 | * i915_read_mch_val - return value for IPS use |
| 4092 | * |
| 4093 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 4094 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 4095 | */ |
| 4096 | unsigned long i915_read_mch_val(void) |
| 4097 | { |
| 4098 | struct drm_i915_private *dev_priv; |
| 4099 | unsigned long chipset_val, graphics_val, ret = 0; |
| 4100 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4101 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4102 | if (!i915_mch_dev) |
| 4103 | goto out_unlock; |
| 4104 | dev_priv = i915_mch_dev; |
| 4105 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4106 | chipset_val = __i915_chipset_val(dev_priv); |
| 4107 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4108 | |
| 4109 | ret = chipset_val + graphics_val; |
| 4110 | |
| 4111 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4112 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4113 | |
| 4114 | return ret; |
| 4115 | } |
| 4116 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 4117 | |
| 4118 | /** |
| 4119 | * i915_gpu_raise - raise GPU frequency limit |
| 4120 | * |
| 4121 | * Raise the limit; IPS indicates we have thermal headroom. |
| 4122 | */ |
| 4123 | bool i915_gpu_raise(void) |
| 4124 | { |
| 4125 | struct drm_i915_private *dev_priv; |
| 4126 | bool ret = true; |
| 4127 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4128 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4129 | if (!i915_mch_dev) { |
| 4130 | ret = false; |
| 4131 | goto out_unlock; |
| 4132 | } |
| 4133 | dev_priv = i915_mch_dev; |
| 4134 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4135 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 4136 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4137 | |
| 4138 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4139 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4140 | |
| 4141 | return ret; |
| 4142 | } |
| 4143 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 4144 | |
| 4145 | /** |
| 4146 | * i915_gpu_lower - lower GPU frequency limit |
| 4147 | * |
| 4148 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 4149 | * frequency maximum. |
| 4150 | */ |
| 4151 | bool i915_gpu_lower(void) |
| 4152 | { |
| 4153 | struct drm_i915_private *dev_priv; |
| 4154 | bool ret = true; |
| 4155 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4156 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4157 | if (!i915_mch_dev) { |
| 4158 | ret = false; |
| 4159 | goto out_unlock; |
| 4160 | } |
| 4161 | dev_priv = i915_mch_dev; |
| 4162 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4163 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 4164 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4165 | |
| 4166 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4167 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4168 | |
| 4169 | return ret; |
| 4170 | } |
| 4171 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 4172 | |
| 4173 | /** |
| 4174 | * i915_gpu_busy - indicate GPU business to IPS |
| 4175 | * |
| 4176 | * Tell the IPS driver whether or not the GPU is busy. |
| 4177 | */ |
| 4178 | bool i915_gpu_busy(void) |
| 4179 | { |
| 4180 | struct drm_i915_private *dev_priv; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4181 | struct intel_ring_buffer *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4182 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4183 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4184 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4185 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4186 | if (!i915_mch_dev) |
| 4187 | goto out_unlock; |
| 4188 | dev_priv = i915_mch_dev; |
| 4189 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4190 | for_each_ring(ring, dev_priv, i) |
| 4191 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4192 | |
| 4193 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4194 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4195 | |
| 4196 | return ret; |
| 4197 | } |
| 4198 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 4199 | |
| 4200 | /** |
| 4201 | * i915_gpu_turbo_disable - disable graphics turbo |
| 4202 | * |
| 4203 | * Disable graphics turbo by resetting the max frequency and setting the |
| 4204 | * current frequency to the default. |
| 4205 | */ |
| 4206 | bool i915_gpu_turbo_disable(void) |
| 4207 | { |
| 4208 | struct drm_i915_private *dev_priv; |
| 4209 | bool ret = true; |
| 4210 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4211 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4212 | if (!i915_mch_dev) { |
| 4213 | ret = false; |
| 4214 | goto out_unlock; |
| 4215 | } |
| 4216 | dev_priv = i915_mch_dev; |
| 4217 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4218 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4219 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4220 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4221 | ret = false; |
| 4222 | |
| 4223 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4224 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4225 | |
| 4226 | return ret; |
| 4227 | } |
| 4228 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 4229 | |
| 4230 | /** |
| 4231 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 4232 | * IPS got loaded first. |
| 4233 | * |
| 4234 | * This awkward dance is so that neither module has to depend on the |
| 4235 | * other in order for IPS to do the appropriate communication of |
| 4236 | * GPU turbo limits to i915. |
| 4237 | */ |
| 4238 | static void |
| 4239 | ips_ping_for_i915_load(void) |
| 4240 | { |
| 4241 | void (*link)(void); |
| 4242 | |
| 4243 | link = symbol_get(ips_link_to_i915_driver); |
| 4244 | if (link) { |
| 4245 | link(); |
| 4246 | symbol_put(ips_link_to_i915_driver); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 4251 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4252 | /* We only register the i915 ips part with intel-ips once everything is |
| 4253 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4254 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4255 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4256 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4257 | |
| 4258 | ips_ping_for_i915_load(); |
| 4259 | } |
| 4260 | |
| 4261 | void intel_gpu_ips_teardown(void) |
| 4262 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4263 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4264 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4265 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4266 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4267 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4268 | { |
| 4269 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4270 | u32 lcfuse; |
| 4271 | u8 pxw[16]; |
| 4272 | int i; |
| 4273 | |
| 4274 | /* Disable to program */ |
| 4275 | I915_WRITE(ECR, 0); |
| 4276 | POSTING_READ(ECR); |
| 4277 | |
| 4278 | /* Program energy weights for various events */ |
| 4279 | I915_WRITE(SDEW, 0x15040d00); |
| 4280 | I915_WRITE(CSIEW0, 0x007f0000); |
| 4281 | I915_WRITE(CSIEW1, 0x1e220004); |
| 4282 | I915_WRITE(CSIEW2, 0x04000004); |
| 4283 | |
| 4284 | for (i = 0; i < 5; i++) |
| 4285 | I915_WRITE(PEW + (i * 4), 0); |
| 4286 | for (i = 0; i < 3; i++) |
| 4287 | I915_WRITE(DEW + (i * 4), 0); |
| 4288 | |
| 4289 | /* Program P-state weights to account for frequency power adjustment */ |
| 4290 | for (i = 0; i < 16; i++) { |
| 4291 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 4292 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 4293 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 4294 | PXVFREQ_PX_SHIFT; |
| 4295 | unsigned long val; |
| 4296 | |
| 4297 | val = vid * vid; |
| 4298 | val *= (freq / 1000); |
| 4299 | val *= 255; |
| 4300 | val /= (127*127*900); |
| 4301 | if (val > 0xff) |
| 4302 | DRM_ERROR("bad pxval: %ld\n", val); |
| 4303 | pxw[i] = val; |
| 4304 | } |
| 4305 | /* Render standby states get 0 weight */ |
| 4306 | pxw[14] = 0; |
| 4307 | pxw[15] = 0; |
| 4308 | |
| 4309 | for (i = 0; i < 4; i++) { |
| 4310 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 4311 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 4312 | I915_WRITE(PXW + (i * 4), val); |
| 4313 | } |
| 4314 | |
| 4315 | /* Adjust magic regs to magic values (more experimental results) */ |
| 4316 | I915_WRITE(OGW0, 0); |
| 4317 | I915_WRITE(OGW1, 0); |
| 4318 | I915_WRITE(EG0, 0x00007f00); |
| 4319 | I915_WRITE(EG1, 0x0000000e); |
| 4320 | I915_WRITE(EG2, 0x000e0000); |
| 4321 | I915_WRITE(EG3, 0x68000300); |
| 4322 | I915_WRITE(EG4, 0x42000000); |
| 4323 | I915_WRITE(EG5, 0x00140031); |
| 4324 | I915_WRITE(EG6, 0); |
| 4325 | I915_WRITE(EG7, 0); |
| 4326 | |
| 4327 | for (i = 0; i < 8; i++) |
| 4328 | I915_WRITE(PXWL + (i * 4), 0); |
| 4329 | |
| 4330 | /* Enable PMON + select events */ |
| 4331 | I915_WRITE(ECR, 0x80000019); |
| 4332 | |
| 4333 | lcfuse = I915_READ(LCFUSE02); |
| 4334 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4335 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4336 | } |
| 4337 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4338 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 4339 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4340 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4341 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 4342 | /* Interrupts should be disabled already to avoid re-arming. */ |
| 4343 | WARN_ON(dev->irq_enabled); |
| 4344 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4345 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4346 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4347 | ironlake_disable_rc6(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4348 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4349 | cancel_delayed_work_sync(&dev_priv->rps.delayed_resume_work); |
Jesse Barnes | 250848c | 2013-04-23 10:09:27 -0700 | [diff] [blame] | 4350 | cancel_work_sync(&dev_priv->rps.work); |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4351 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4352 | if (IS_VALLEYVIEW(dev)) |
| 4353 | valleyview_disable_rps(dev); |
| 4354 | else |
| 4355 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4356 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4357 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4358 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4359 | } |
| 4360 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4361 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 4362 | { |
| 4363 | struct drm_i915_private *dev_priv = |
| 4364 | container_of(work, struct drm_i915_private, |
| 4365 | rps.delayed_resume_work.work); |
| 4366 | struct drm_device *dev = dev_priv->dev; |
| 4367 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4368 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4369 | |
| 4370 | if (IS_VALLEYVIEW(dev)) { |
| 4371 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4372 | } else if (IS_BROADWELL(dev)) { |
| 4373 | gen8_enable_rps(dev); |
| 4374 | gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4375 | } else { |
| 4376 | gen6_enable_rps(dev); |
| 4377 | gen6_update_ring_freq(dev); |
| 4378 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4379 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4380 | mutex_unlock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4383 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 4384 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4385 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4386 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4387 | if (IS_IRONLAKE_M(dev)) { |
| 4388 | ironlake_enable_drps(dev); |
| 4389 | ironlake_enable_rc6(dev); |
| 4390 | intel_init_emon(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4391 | } else if (IS_GEN6(dev) || IS_GEN7(dev)) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4392 | /* |
| 4393 | * PCU communication is slow and this doesn't need to be |
| 4394 | * done at any specific time, so do this out of our fast path |
| 4395 | * to make resume and init faster. |
| 4396 | */ |
| 4397 | schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 4398 | round_jiffies_up_relative(HZ)); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4399 | } |
| 4400 | } |
| 4401 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4402 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 4403 | { |
| 4404 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4405 | |
| 4406 | /* |
| 4407 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 4408 | * gating for the panel power sequencer or it will fail to |
| 4409 | * start up when no ports are active. |
| 4410 | */ |
| 4411 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 4412 | } |
| 4413 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4414 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 4415 | { |
| 4416 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4417 | int pipe; |
| 4418 | |
| 4419 | for_each_pipe(pipe) { |
| 4420 | I915_WRITE(DSPCNTR(pipe), |
| 4421 | I915_READ(DSPCNTR(pipe)) | |
| 4422 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 4423 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4427 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 4428 | { |
| 4429 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4430 | |
| 4431 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 4432 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 4433 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 4434 | |
| 4435 | /* |
| 4436 | * Don't touch WM1S_LP_EN here. |
| 4437 | * Doing so could cause underruns. |
| 4438 | */ |
| 4439 | } |
| 4440 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4441 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4442 | { |
| 4443 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4444 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4445 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 4446 | /* |
| 4447 | * Required for FBC |
| 4448 | * WaFbcDisableDpfcClockGating:ilk |
| 4449 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 4450 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 4451 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 4452 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4453 | |
| 4454 | I915_WRITE(PCH_3DCGDIS0, |
| 4455 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 4456 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 4457 | I915_WRITE(PCH_3DCGDIS1, |
| 4458 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 4459 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4460 | /* |
| 4461 | * According to the spec the following bits should be set in |
| 4462 | * order to enable memory self-refresh |
| 4463 | * The bit 22/21 of 0x42004 |
| 4464 | * The bit 5 of 0x42020 |
| 4465 | * The bit 15 of 0x45000 |
| 4466 | */ |
| 4467 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4468 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4469 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 4470 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4471 | I915_WRITE(DISP_ARB_CTL, |
| 4472 | (I915_READ(DISP_ARB_CTL) | |
| 4473 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4474 | |
| 4475 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4476 | |
| 4477 | /* |
| 4478 | * Based on the document from hardware guys the following bits |
| 4479 | * should be set unconditionally in order to enable FBC. |
| 4480 | * The bit 22 of 0x42000 |
| 4481 | * The bit 22 of 0x42004 |
| 4482 | * The bit 7,8,9 of 0x42020. |
| 4483 | */ |
| 4484 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 4485 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4486 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 4487 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 4488 | ILK_FBCQ_DIS); |
| 4489 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4490 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4491 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4492 | } |
| 4493 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 4494 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 4495 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4496 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4497 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4498 | ILK_ELPIN_409_SELECT); |
| 4499 | I915_WRITE(_3D_CHICKEN2, |
| 4500 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 4501 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 4502 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4503 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 4504 | I915_WRITE(CACHE_MODE_0, |
| 4505 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4506 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4507 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 4508 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4509 | ibx_init_clock_gating(dev); |
| 4510 | } |
| 4511 | |
| 4512 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 4513 | { |
| 4514 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4515 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4516 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4517 | |
| 4518 | /* |
| 4519 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 4520 | * gating for the panel power sequencer or it will fail to |
| 4521 | * start up when no ports are active. |
| 4522 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 4523 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 4524 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 4525 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4526 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 4527 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 4528 | /* The below fixes the weird display corruption, a few pixels shifted |
| 4529 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 4530 | */ |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4531 | for_each_pipe(pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 4532 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 4533 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 4534 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 4535 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4536 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 4537 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 4538 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 4539 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 4540 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 4541 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4542 | /* WADP0ClockGatingDisable */ |
| 4543 | for_each_pipe(pipe) { |
| 4544 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 4545 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 4546 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4547 | } |
| 4548 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 4549 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 4550 | { |
| 4551 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4552 | uint32_t tmp; |
| 4553 | |
| 4554 | tmp = I915_READ(MCH_SSKPD); |
| 4555 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) { |
| 4556 | DRM_INFO("Wrong MCH_SSKPD value: 0x%08x\n", tmp); |
| 4557 | DRM_INFO("This can cause pipe underruns and display issues.\n"); |
| 4558 | DRM_INFO("Please upgrade your BIOS to fix this.\n"); |
| 4559 | } |
| 4560 | } |
| 4561 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4562 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4563 | { |
| 4564 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4565 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4566 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4567 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4568 | |
| 4569 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4570 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4571 | ILK_ELPIN_409_SELECT); |
| 4572 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4573 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 4574 | I915_WRITE(_3D_CHICKEN, |
| 4575 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 4576 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4577 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 4578 | if (IS_SNB_GT1(dev)) |
| 4579 | I915_WRITE(GEN6_GT_MODE, |
| 4580 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 4581 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4582 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4583 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4584 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 4585 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4586 | |
| 4587 | I915_WRITE(GEN6_UCGCTL1, |
| 4588 | I915_READ(GEN6_UCGCTL1) | |
| 4589 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 4590 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 4591 | |
| 4592 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 4593 | * gating disable must be set. Failure to set it results in |
| 4594 | * flickering pixels due to Z write ordering failures after |
| 4595 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 4596 | * Sanctuary and Tropics, and apparently anything else with |
| 4597 | * alpha test or pixel discard. |
| 4598 | * |
| 4599 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 4600 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4601 | * |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4602 | * Also apply WaDisableVDSUnitClockGating:snb and |
| 4603 | * WaDisableRCPBUnitClockGating:snb. |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4604 | */ |
| 4605 | I915_WRITE(GEN6_UCGCTL2, |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4606 | GEN7_VDSUNIT_CLOCK_GATE_DISABLE | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4607 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 4608 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 4609 | |
| 4610 | /* Bspec says we need to always set all mask bits. */ |
Kenneth Graunke | 26b6e44 | 2012-10-07 08:51:07 -0700 | [diff] [blame] | 4611 | I915_WRITE(_3D_CHICKEN3, (0xFFFF << 16) | |
| 4612 | _3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4613 | |
| 4614 | /* |
| 4615 | * According to the spec the following bits should be |
| 4616 | * set in order to enable memory self-refresh and fbc: |
| 4617 | * The bit21 and bit22 of 0x42000 |
| 4618 | * The bit21 and bit22 of 0x42004 |
| 4619 | * The bit5 and bit7 of 0x42020 |
| 4620 | * The bit14 of 0x70180 |
| 4621 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 4622 | * |
| 4623 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4624 | */ |
| 4625 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 4626 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 4627 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 4628 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 4629 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 4630 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4631 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 4632 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 4633 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 4634 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4635 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4636 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 4637 | |
| 4638 | /* The default value should be 0x200 according to docs, but the two |
| 4639 | * platforms I checked have a 0 for this. (Maybe BIOS overrides?) */ |
| 4640 | I915_WRITE(GEN6_GT_MODE, _MASKED_BIT_DISABLE(0xffff)); |
| 4641 | I915_WRITE(GEN6_GT_MODE, _MASKED_BIT_ENABLE(GEN6_GT_MODE_HI)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4642 | |
| 4643 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 4644 | |
| 4645 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 4649 | { |
| 4650 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 4651 | |
| 4652 | reg &= ~GEN7_FF_SCHED_MASK; |
| 4653 | reg |= GEN7_FF_TS_SCHED_HW; |
| 4654 | reg |= GEN7_FF_VS_SCHED_HW; |
| 4655 | reg |= GEN7_FF_DS_SCHED_HW; |
| 4656 | |
Ben Widawsky | 41c0b3a | 2013-01-26 11:52:00 -0800 | [diff] [blame] | 4657 | if (IS_HASWELL(dev_priv->dev)) |
| 4658 | reg &= ~GEN7_FF_VS_REF_CNT_FFME; |
| 4659 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4660 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 4661 | } |
| 4662 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 4663 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 4664 | { |
| 4665 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4666 | |
| 4667 | /* |
| 4668 | * TODO: this bit should only be enabled when really needed, then |
| 4669 | * disabled when not needed anymore in order to save power. |
| 4670 | */ |
| 4671 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 4672 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 4673 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 4674 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 4675 | |
| 4676 | /* WADPOClockGatingDisable:hsw */ |
| 4677 | I915_WRITE(_TRANSA_CHICKEN1, |
| 4678 | I915_READ(_TRANSA_CHICKEN1) | |
| 4679 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 4680 | } |
| 4681 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 4682 | static void lpt_suspend_hw(struct drm_device *dev) |
| 4683 | { |
| 4684 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4685 | |
| 4686 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 4687 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 4688 | |
| 4689 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 4690 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 4691 | } |
| 4692 | } |
| 4693 | |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 4694 | static void gen8_init_clock_gating(struct drm_device *dev) |
| 4695 | { |
| 4696 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 4697 | enum pipe i; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 4698 | |
| 4699 | I915_WRITE(WM3_LP_ILK, 0); |
| 4700 | I915_WRITE(WM2_LP_ILK, 0); |
| 4701 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 4702 | |
| 4703 | /* FIXME(BDW): Check all the w/a, some might only apply to |
| 4704 | * pre-production hw. */ |
| 4705 | |
Damien Lespiau | 4167e32 | 2014-01-16 16:51:35 +0000 | [diff] [blame] | 4706 | /* |
| 4707 | * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for |
| 4708 | * pre-production hardware |
| 4709 | */ |
Ben Widawsky | fd392b6 | 2013-11-04 22:52:39 -0800 | [diff] [blame] | 4710 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 4711 | _MASKED_BIT_ENABLE(GEN8_CENTROID_PIXEL_OPT_DIS)); |
Ben Widawsky | bf66347 | 2013-11-02 21:07:57 -0700 | [diff] [blame] | 4712 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 4713 | _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS)); |
Ben Widawsky | 4afe8d3 | 2013-11-02 21:07:55 -0700 | [diff] [blame] | 4714 | I915_WRITE(GAMTARBMODE, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE)); |
| 4715 | |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 4716 | I915_WRITE(_3D_CHICKEN3, |
| 4717 | _3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2)); |
| 4718 | |
Ben Widawsky | a75f362 | 2013-11-02 21:07:59 -0700 | [diff] [blame] | 4719 | I915_WRITE(COMMON_SLICE_CHICKEN2, |
| 4720 | _MASKED_BIT_ENABLE(GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE)); |
| 4721 | |
Ben Widawsky | 4c2e7a5 | 2013-11-02 21:08:00 -0700 | [diff] [blame] | 4722 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 4723 | _MASKED_BIT_ENABLE(GEN7_SINGLE_SUBSCAN_DISPATCH_ENABLE)); |
| 4724 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4725 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 4726 | 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] | 4727 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4728 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 4729 | I915_WRITE(CHICKEN_PAR1_1, |
| 4730 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 4731 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4732 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 4733 | for_each_pipe(i) { |
| 4734 | I915_WRITE(CHICKEN_PIPESL_1(i), |
| 4735 | I915_READ(CHICKEN_PIPESL_1(i) | |
| 4736 | DPRS_MASK_VBLANK_SRD)); |
| 4737 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 4738 | |
| 4739 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
| 4740 | * workaround for for a possible hang in the unlikely event a TLB |
| 4741 | * invalidation occurs during a PSD flush. |
| 4742 | */ |
| 4743 | I915_WRITE(HDC_CHICKEN0, |
| 4744 | I915_READ(HDC_CHICKEN0) | |
| 4745 | _MASKED_BIT_ENABLE(HDC_FORCE_NON_COHERENT)); |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 4746 | |
| 4747 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 4748 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 4749 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 4750 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 4751 | ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME)); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 4752 | } |
| 4753 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4754 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 4755 | { |
| 4756 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4757 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4758 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4759 | |
| 4760 | /* According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4761 | * This implements the WaDisableRCZUnitClockGating:hsw workaround. |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4762 | */ |
| 4763 | I915_WRITE(GEN6_UCGCTL2, GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
| 4764 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4765 | /* Apply the WaDisableRHWOOptimizationForRenderHang:hsw workaround. */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4766 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 4767 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 4768 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4769 | /* WaApplyL3ControlAndL3ChickenMode:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4770 | I915_WRITE(GEN7_L3CNTLREG1, |
| 4771 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 4772 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
| 4773 | GEN7_WA_L3_CHICKEN_MODE); |
| 4774 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 4775 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 4776 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 4777 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 4778 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 4779 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4780 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4781 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 4782 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 4783 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 4784 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4785 | /* WaVSRefCountFullforceMissDisable:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4786 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 4787 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4788 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4789 | I915_WRITE(CACHE_MODE_1, |
| 4790 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 4791 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4792 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 4793 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 4794 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 4795 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 4796 | I915_WRITE(CHICKEN_PAR1_1, |
| 4797 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 4798 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 4799 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 4800 | } |
| 4801 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4802 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4803 | { |
| 4804 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 4805 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4806 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 4807 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4808 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 4809 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4810 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4811 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 4812 | I915_WRITE(_3D_CHICKEN3, |
| 4813 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 4814 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4815 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4816 | I915_WRITE(IVB_CHICKEN3, |
| 4817 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 4818 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 4819 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4820 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 4821 | if (IS_IVB_GT1(dev)) |
| 4822 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 4823 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
| 4824 | else |
| 4825 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1_GT2, |
| 4826 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
| 4827 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4828 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4829 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 4830 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 4831 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4832 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4833 | I915_WRITE(GEN7_L3CNTLREG1, |
| 4834 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 4835 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 4836 | GEN7_WA_L3_CHICKEN_MODE); |
| 4837 | if (IS_IVB_GT1(dev)) |
| 4838 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 4839 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 4840 | else |
| 4841 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 4842 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 4843 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4844 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4845 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 4846 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 4847 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 4848 | |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4849 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 4850 | * gating disable must be set. Failure to set it results in |
| 4851 | * flickering pixels due to Z write ordering failures after |
| 4852 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 4853 | * Sanctuary and Tropics, and apparently anything else with |
| 4854 | * alpha test or pixel discard. |
| 4855 | * |
| 4856 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 4857 | * but we didn't debug actual testcases to find it out. |
| 4858 | * |
| 4859 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4860 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4861 | */ |
| 4862 | I915_WRITE(GEN6_UCGCTL2, |
| 4863 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE | |
| 4864 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 4865 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4866 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4867 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 4868 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 4869 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 4870 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 4871 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4872 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4873 | /* WaVSRefCountFullforceMissDisable:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4874 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 4875 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4876 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 4877 | I915_WRITE(CACHE_MODE_1, |
| 4878 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 4879 | |
| 4880 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 4881 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 4882 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 4883 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 4884 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 4885 | if (!HAS_PCH_NOP(dev)) |
| 4886 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 4887 | |
| 4888 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4889 | } |
| 4890 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4891 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4892 | { |
| 4893 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 4894 | u32 val; |
| 4895 | |
| 4896 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4897 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4898 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4899 | switch ((val >> 6) & 3) { |
| 4900 | case 0: |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 4901 | dev_priv->mem_freq = 800; |
| 4902 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 4903 | case 1: |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 4904 | dev_priv->mem_freq = 1066; |
| 4905 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 4906 | case 2: |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 4907 | dev_priv->mem_freq = 1333; |
| 4908 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 4909 | case 3: |
Chon Ming Lee | 2325991 | 2013-11-07 15:23:26 +0800 | [diff] [blame] | 4910 | dev_priv->mem_freq = 1333; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 4911 | break; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 4912 | } |
| 4913 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4914 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 4915 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4916 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4917 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 4918 | I915_WRITE(_3D_CHICKEN3, |
| 4919 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 4920 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4921 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4922 | I915_WRITE(IVB_CHICKEN3, |
| 4923 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 4924 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 4925 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4926 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 4927 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 4928 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 4929 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 4930 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4931 | /* Apply the WaDisableRHWOOptimizationForRenderHang:vlv workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4932 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 4933 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 4934 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4935 | /* WaApplyL3ControlAndL3ChickenMode:vlv */ |
Jesse Barnes | d0cf5ea | 2012-10-25 12:15:41 -0700 | [diff] [blame] | 4936 | I915_WRITE(GEN7_L3CNTLREG1, I915_READ(GEN7_L3CNTLREG1) | GEN7_L3AGDIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4937 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, GEN7_WA_L3_CHICKEN_MODE); |
| 4938 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4939 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 4940 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 4941 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 4942 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4943 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 4944 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 4945 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 4946 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4947 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4948 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 4949 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 4950 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 4951 | |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4952 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 4953 | * gating disable must be set. Failure to set it results in |
| 4954 | * flickering pixels due to Z write ordering failures after |
| 4955 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 4956 | * Sanctuary and Tropics, and apparently anything else with |
| 4957 | * alpha test or pixel discard. |
| 4958 | * |
| 4959 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 4960 | * but we didn't debug actual testcases to find it out. |
| 4961 | * |
| 4962 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4963 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4964 | * |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4965 | * Also apply WaDisableVDSUnitClockGating:vlv and |
| 4966 | * WaDisableRCPBUnitClockGating:vlv. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4967 | */ |
| 4968 | I915_WRITE(GEN6_UCGCTL2, |
| 4969 | GEN7_VDSUNIT_CLOCK_GATE_DISABLE | |
Jesse Barnes | 6edaa7f | 2012-06-14 11:04:49 -0700 | [diff] [blame] | 4970 | GEN7_TDLUNIT_CLOCK_GATE_DISABLE | |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 4971 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE | |
| 4972 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 4973 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 4974 | |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 4975 | I915_WRITE(GEN7_UCGCTL4, GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
| 4976 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 4977 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4978 | |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 4979 | I915_WRITE(CACHE_MODE_1, |
| 4980 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 4981 | |
| 4982 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 4983 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 4984 | * Disable clock gating on th GCFG unit to prevent a delay |
| 4985 | * in the reporting of vblank events. |
| 4986 | */ |
Jesse Barnes | 4e8c84a | 2013-03-08 10:45:54 -0800 | [diff] [blame] | 4987 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, 0xffffffff); |
| 4988 | |
| 4989 | /* Conservative clock gating settings for now */ |
| 4990 | I915_WRITE(0x9400, 0xffffffff); |
| 4991 | I915_WRITE(0x9404, 0xffffffff); |
| 4992 | I915_WRITE(0x9408, 0xffffffff); |
| 4993 | I915_WRITE(0x940c, 0xffffffff); |
| 4994 | I915_WRITE(0x9410, 0xffffffff); |
| 4995 | I915_WRITE(0x9414, 0xffffffff); |
| 4996 | I915_WRITE(0x9418, 0xffffffff); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 4997 | } |
| 4998 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 4999 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5000 | { |
| 5001 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5002 | uint32_t dspclk_gate; |
| 5003 | |
| 5004 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 5005 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 5006 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 5007 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 5008 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5009 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 5010 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 5011 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 5012 | if (IS_GM45(dev)) |
| 5013 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 5014 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5015 | |
| 5016 | /* WaDisableRenderCachePipelinedFlush */ |
| 5017 | I915_WRITE(CACHE_MODE_0, |
| 5018 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 5019 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5020 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5021 | } |
| 5022 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5023 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5024 | { |
| 5025 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5026 | |
| 5027 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 5028 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 5029 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 5030 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5031 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5032 | I915_WRITE(MI_ARB_STATE, |
| 5033 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5034 | } |
| 5035 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5036 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5037 | { |
| 5038 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5039 | |
| 5040 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 5041 | I965_RCC_CLOCK_GATE_DISABLE | |
| 5042 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 5043 | I965_ISC_CLOCK_GATE_DISABLE | |
| 5044 | I965_FBC_CLOCK_GATE_DISABLE); |
| 5045 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5046 | I915_WRITE(MI_ARB_STATE, |
| 5047 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5048 | } |
| 5049 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5050 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5051 | { |
| 5052 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5053 | u32 dstate = I915_READ(D_STATE); |
| 5054 | |
| 5055 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 5056 | DSTATE_DOT_CLOCK_GATING; |
| 5057 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 5058 | |
| 5059 | if (IS_PINEVIEW(dev)) |
| 5060 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 5061 | |
| 5062 | /* IIR "flip pending" means done if this bit is set */ |
| 5063 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5064 | } |
| 5065 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5066 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5067 | { |
| 5068 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5069 | |
| 5070 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
| 5071 | } |
| 5072 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5073 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5074 | { |
| 5075 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5076 | |
| 5077 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
| 5078 | } |
| 5079 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5080 | void intel_init_clock_gating(struct drm_device *dev) |
| 5081 | { |
| 5082 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5083 | |
| 5084 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5085 | } |
| 5086 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5087 | void intel_suspend_hw(struct drm_device *dev) |
| 5088 | { |
| 5089 | if (HAS_PCH_LPT(dev)) |
| 5090 | lpt_suspend_hw(dev); |
| 5091 | } |
| 5092 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5093 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 5094 | for (i = 0; \ |
| 5095 | i < (power_domains)->power_well_count && \ |
| 5096 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 5097 | i++) \ |
| 5098 | if ((power_well)->domains & (domain_mask)) |
| 5099 | |
| 5100 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 5101 | for (i = (power_domains)->power_well_count - 1; \ |
| 5102 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 5103 | i--) \ |
| 5104 | if ((power_well)->domains & (domain_mask)) |
| 5105 | |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5106 | /** |
| 5107 | * We should only use the power well if we explicitly asked the hardware to |
| 5108 | * enable it, so check if it's enabled and also check if we've requested it to |
| 5109 | * be enabled. |
| 5110 | */ |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5111 | static bool hsw_power_well_enabled(struct drm_device *dev, |
| 5112 | struct i915_power_well *power_well) |
| 5113 | { |
| 5114 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5115 | |
| 5116 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 5117 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 5118 | } |
| 5119 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5120 | bool intel_display_power_enabled_sw(struct drm_device *dev, |
| 5121 | enum intel_display_power_domain domain) |
| 5122 | { |
| 5123 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5124 | struct i915_power_domains *power_domains; |
| 5125 | |
| 5126 | power_domains = &dev_priv->power_domains; |
| 5127 | |
| 5128 | return power_domains->domain_use_count[domain]; |
| 5129 | } |
| 5130 | |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 5131 | bool intel_display_power_enabled(struct drm_device *dev, |
| 5132 | enum intel_display_power_domain domain) |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5133 | { |
| 5134 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5135 | struct i915_power_domains *power_domains; |
| 5136 | struct i915_power_well *power_well; |
| 5137 | bool is_enabled; |
| 5138 | int i; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5139 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5140 | power_domains = &dev_priv->power_domains; |
| 5141 | |
| 5142 | is_enabled = true; |
| 5143 | |
| 5144 | mutex_lock(&power_domains->lock); |
| 5145 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5146 | if (power_well->always_on) |
| 5147 | continue; |
| 5148 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5149 | if (!power_well->is_enabled(dev, power_well)) { |
| 5150 | is_enabled = false; |
| 5151 | break; |
| 5152 | } |
| 5153 | } |
| 5154 | mutex_unlock(&power_domains->lock); |
| 5155 | |
| 5156 | return is_enabled; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5157 | } |
| 5158 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5159 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 5160 | { |
| 5161 | struct drm_device *dev = dev_priv->dev; |
| 5162 | unsigned long irqflags; |
| 5163 | |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 5164 | /* |
| 5165 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 5166 | * we'll get unclaimed register interrupts. This stops after we write |
| 5167 | * anything to the VGA MSR register. The vgacon module uses this |
| 5168 | * register all the time, so if we unbind our driver and, as a |
| 5169 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 5170 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 5171 | * sure vgacon can keep working normally without triggering interrupts |
| 5172 | * and error messages. |
| 5173 | */ |
| 5174 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 5175 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
| 5176 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 5177 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5178 | if (IS_BROADWELL(dev)) { |
| 5179 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 5180 | I915_WRITE(GEN8_DE_PIPE_IMR(PIPE_B), |
| 5181 | dev_priv->de_irq_mask[PIPE_B]); |
| 5182 | I915_WRITE(GEN8_DE_PIPE_IER(PIPE_B), |
| 5183 | ~dev_priv->de_irq_mask[PIPE_B] | |
| 5184 | GEN8_PIPE_VBLANK); |
| 5185 | I915_WRITE(GEN8_DE_PIPE_IMR(PIPE_C), |
| 5186 | dev_priv->de_irq_mask[PIPE_C]); |
| 5187 | I915_WRITE(GEN8_DE_PIPE_IER(PIPE_C), |
| 5188 | ~dev_priv->de_irq_mask[PIPE_C] | |
| 5189 | GEN8_PIPE_VBLANK); |
| 5190 | POSTING_READ(GEN8_DE_PIPE_IER(PIPE_C)); |
| 5191 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | static void hsw_power_well_post_disable(struct drm_i915_private *dev_priv) |
| 5196 | { |
| 5197 | struct drm_device *dev = dev_priv->dev; |
| 5198 | enum pipe p; |
| 5199 | unsigned long irqflags; |
| 5200 | |
| 5201 | /* |
| 5202 | * After this, the registers on the pipes that are part of the power |
| 5203 | * well will become zero, so we have to adjust our counters according to |
| 5204 | * that. |
| 5205 | * |
| 5206 | * FIXME: Should we do this in general in drm_vblank_post_modeset? |
| 5207 | */ |
| 5208 | spin_lock_irqsave(&dev->vbl_lock, irqflags); |
| 5209 | for_each_pipe(p) |
| 5210 | if (p != PIPE_A) |
| 5211 | dev->vblank[p].last = 0; |
| 5212 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
| 5213 | } |
| 5214 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5215 | static void hsw_set_power_well(struct drm_device *dev, |
| 5216 | struct i915_power_well *power_well, bool enable) |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5217 | { |
| 5218 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5219 | bool is_enabled, enable_requested; |
| 5220 | uint32_t tmp; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5221 | |
Paulo Zanoni | d62292c | 2013-11-27 17:59:22 -0200 | [diff] [blame] | 5222 | WARN_ON(dev_priv->pc8.enabled); |
| 5223 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5224 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5225 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 5226 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5227 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5228 | if (enable) { |
| 5229 | if (!enable_requested) |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5230 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 5231 | HSW_PWR_WELL_ENABLE_REQUEST); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5232 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5233 | if (!is_enabled) { |
| 5234 | DRM_DEBUG_KMS("Enabling power well\n"); |
| 5235 | if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) & |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5236 | HSW_PWR_WELL_STATE_ENABLED), 20)) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5237 | DRM_ERROR("Timeout enabling power well\n"); |
| 5238 | } |
Ben Widawsky | 596cc11 | 2013-11-11 14:46:28 -0800 | [diff] [blame] | 5239 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5240 | hsw_power_well_post_enable(dev_priv); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5241 | } else { |
| 5242 | if (enable_requested) { |
| 5243 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 5244 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5245 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 5246 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5247 | hsw_power_well_post_disable(dev_priv); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5248 | } |
| 5249 | } |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5250 | } |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5251 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5252 | static void __intel_power_well_get(struct drm_device *dev, |
| 5253 | struct i915_power_well *power_well) |
Ville Syrjälä | 2d66aef | 2013-09-16 17:38:29 +0300 | [diff] [blame] | 5254 | { |
Paulo Zanoni | d62292c | 2013-11-27 17:59:22 -0200 | [diff] [blame] | 5255 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5256 | |
| 5257 | if (!power_well->count++ && power_well->set) { |
| 5258 | hsw_disable_package_c8(dev_priv); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5259 | power_well->set(dev, power_well, true); |
Paulo Zanoni | d62292c | 2013-11-27 17:59:22 -0200 | [diff] [blame] | 5260 | } |
Ville Syrjälä | 2d66aef | 2013-09-16 17:38:29 +0300 | [diff] [blame] | 5261 | } |
| 5262 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5263 | static void __intel_power_well_put(struct drm_device *dev, |
| 5264 | struct i915_power_well *power_well) |
Ville Syrjälä | 2d66aef | 2013-09-16 17:38:29 +0300 | [diff] [blame] | 5265 | { |
Paulo Zanoni | d62292c | 2013-11-27 17:59:22 -0200 | [diff] [blame] | 5266 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5267 | |
Ville Syrjälä | 2d66aef | 2013-09-16 17:38:29 +0300 | [diff] [blame] | 5268 | WARN_ON(!power_well->count); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5269 | |
Paulo Zanoni | d62292c | 2013-11-27 17:59:22 -0200 | [diff] [blame] | 5270 | if (!--power_well->count && power_well->set && |
| 5271 | i915_disable_power_well) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5272 | power_well->set(dev, power_well, false); |
Paulo Zanoni | d62292c | 2013-11-27 17:59:22 -0200 | [diff] [blame] | 5273 | hsw_enable_package_c8(dev_priv); |
| 5274 | } |
Ville Syrjälä | 2d66aef | 2013-09-16 17:38:29 +0300 | [diff] [blame] | 5275 | } |
| 5276 | |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5277 | void intel_display_power_get(struct drm_device *dev, |
| 5278 | enum intel_display_power_domain domain) |
| 5279 | { |
| 5280 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5281 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5282 | struct i915_power_well *power_well; |
| 5283 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5284 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5285 | power_domains = &dev_priv->power_domains; |
| 5286 | |
| 5287 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5288 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5289 | for_each_power_well(i, power_well, BIT(domain), power_domains) |
| 5290 | __intel_power_well_get(dev, power_well); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5291 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5292 | power_domains->domain_use_count[domain]++; |
| 5293 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5294 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | void intel_display_power_put(struct drm_device *dev, |
| 5298 | enum intel_display_power_domain domain) |
| 5299 | { |
| 5300 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5301 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5302 | struct i915_power_well *power_well; |
| 5303 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5304 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5305 | power_domains = &dev_priv->power_domains; |
| 5306 | |
| 5307 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5308 | |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5309 | WARN_ON(!power_domains->domain_use_count[domain]); |
| 5310 | power_domains->domain_use_count[domain]--; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5311 | |
| 5312 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) |
| 5313 | __intel_power_well_put(dev, power_well); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 5314 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5315 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 5316 | } |
| 5317 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5318 | static struct i915_power_domains *hsw_pwr; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5319 | |
| 5320 | /* Display audio driver power well request */ |
| 5321 | void i915_request_power_well(void) |
| 5322 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5323 | struct drm_i915_private *dev_priv; |
| 5324 | |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5325 | if (WARN_ON(!hsw_pwr)) |
| 5326 | return; |
| 5327 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5328 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 5329 | power_domains); |
Imre Deak | fbeeaa2 | 2013-11-25 17:15:28 +0200 | [diff] [blame] | 5330 | intel_display_power_get(dev_priv->dev, POWER_DOMAIN_AUDIO); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5331 | } |
| 5332 | EXPORT_SYMBOL_GPL(i915_request_power_well); |
| 5333 | |
| 5334 | /* Display audio driver power well release */ |
| 5335 | void i915_release_power_well(void) |
| 5336 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5337 | struct drm_i915_private *dev_priv; |
| 5338 | |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5339 | if (WARN_ON(!hsw_pwr)) |
| 5340 | return; |
| 5341 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 5342 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 5343 | power_domains); |
Imre Deak | fbeeaa2 | 2013-11-25 17:15:28 +0200 | [diff] [blame] | 5344 | intel_display_power_put(dev_priv->dev, POWER_DOMAIN_AUDIO); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5345 | } |
| 5346 | EXPORT_SYMBOL_GPL(i915_release_power_well); |
| 5347 | |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 5348 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 5349 | { |
| 5350 | .name = "always-on", |
| 5351 | .always_on = 1, |
| 5352 | .domains = POWER_DOMAIN_MASK, |
| 5353 | }, |
| 5354 | }; |
| 5355 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5356 | static struct i915_power_well hsw_power_wells[] = { |
| 5357 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5358 | .name = "always-on", |
| 5359 | .always_on = 1, |
| 5360 | .domains = HSW_ALWAYS_ON_POWER_DOMAINS, |
| 5361 | }, |
| 5362 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5363 | .name = "display", |
| 5364 | .domains = POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS, |
| 5365 | .is_enabled = hsw_power_well_enabled, |
| 5366 | .set = hsw_set_power_well, |
| 5367 | }, |
| 5368 | }; |
| 5369 | |
| 5370 | static struct i915_power_well bdw_power_wells[] = { |
| 5371 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 5372 | .name = "always-on", |
| 5373 | .always_on = 1, |
| 5374 | .domains = BDW_ALWAYS_ON_POWER_DOMAINS, |
| 5375 | }, |
| 5376 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5377 | .name = "display", |
| 5378 | .domains = POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS, |
| 5379 | .is_enabled = hsw_power_well_enabled, |
| 5380 | .set = hsw_set_power_well, |
| 5381 | }, |
| 5382 | }; |
| 5383 | |
| 5384 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 5385 | (power_domains)->power_wells = (__power_wells); \ |
| 5386 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 5387 | }) |
| 5388 | |
Imre Deak | ddb642f | 2013-10-28 17:20:35 +0200 | [diff] [blame] | 5389 | int intel_power_domains_init(struct drm_device *dev) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5390 | { |
| 5391 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5392 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5393 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5394 | mutex_init(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5395 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5396 | /* |
| 5397 | * The enabling order will be from lower to higher indexed wells, |
| 5398 | * the disabling order is reversed. |
| 5399 | */ |
| 5400 | if (IS_HASWELL(dev)) { |
| 5401 | set_power_wells(power_domains, hsw_power_wells); |
| 5402 | hsw_pwr = power_domains; |
| 5403 | } else if (IS_BROADWELL(dev)) { |
| 5404 | set_power_wells(power_domains, bdw_power_wells); |
| 5405 | hsw_pwr = power_domains; |
| 5406 | } else { |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 5407 | set_power_wells(power_domains, i9xx_always_on_power_well); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5408 | } |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5409 | |
| 5410 | return 0; |
| 5411 | } |
| 5412 | |
Imre Deak | ddb642f | 2013-10-28 17:20:35 +0200 | [diff] [blame] | 5413 | void intel_power_domains_remove(struct drm_device *dev) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5414 | { |
| 5415 | hsw_pwr = NULL; |
| 5416 | } |
| 5417 | |
Imre Deak | ddb642f | 2013-10-28 17:20:35 +0200 | [diff] [blame] | 5418 | static void intel_power_domains_resume(struct drm_device *dev) |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 5419 | { |
| 5420 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5421 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 5422 | struct i915_power_well *power_well; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5423 | int i; |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 5424 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5425 | mutex_lock(&power_domains->lock); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5426 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
| 5427 | if (power_well->set) |
| 5428 | power_well->set(dev, power_well, power_well->count > 0); |
| 5429 | } |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 5430 | mutex_unlock(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 5431 | } |
| 5432 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5433 | /* |
| 5434 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 5435 | * when not needed anymore. We have 4 registers that can request the power well |
| 5436 | * to be enabled, and it will only be disabled if none of the registers is |
| 5437 | * requesting it to be enabled. |
| 5438 | */ |
Imre Deak | ddb642f | 2013-10-28 17:20:35 +0200 | [diff] [blame] | 5439 | void intel_power_domains_init_hw(struct drm_device *dev) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5440 | { |
| 5441 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5442 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5443 | /* For now, we need the power well to be always enabled. */ |
Imre Deak | baa7070 | 2013-10-25 17:36:48 +0300 | [diff] [blame] | 5444 | intel_display_set_init_power(dev, true); |
Imre Deak | ddb642f | 2013-10-28 17:20:35 +0200 | [diff] [blame] | 5445 | intel_power_domains_resume(dev); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5446 | |
Imre Deak | f7243ac | 2013-11-25 17:15:33 +0200 | [diff] [blame] | 5447 | if (!(IS_HASWELL(dev) || IS_BROADWELL(dev))) |
| 5448 | return; |
| 5449 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5450 | /* We're taking over the BIOS, so clear any requests made by it since |
| 5451 | * the driver is in charge now. */ |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5452 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5453 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5454 | } |
| 5455 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 5456 | /* Disables PC8 so we can use the GMBUS and DP AUX interrupts. */ |
| 5457 | void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv) |
| 5458 | { |
| 5459 | hsw_disable_package_c8(dev_priv); |
| 5460 | } |
| 5461 | |
| 5462 | void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv) |
| 5463 | { |
| 5464 | hsw_enable_package_c8(dev_priv); |
| 5465 | } |
| 5466 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 5467 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 5468 | { |
| 5469 | struct drm_device *dev = dev_priv->dev; |
| 5470 | struct device *device = &dev->pdev->dev; |
| 5471 | |
| 5472 | if (!HAS_RUNTIME_PM(dev)) |
| 5473 | return; |
| 5474 | |
| 5475 | pm_runtime_get_sync(device); |
| 5476 | WARN(dev_priv->pm.suspended, "Device still suspended.\n"); |
| 5477 | } |
| 5478 | |
| 5479 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 5480 | { |
| 5481 | struct drm_device *dev = dev_priv->dev; |
| 5482 | struct device *device = &dev->pdev->dev; |
| 5483 | |
| 5484 | if (!HAS_RUNTIME_PM(dev)) |
| 5485 | return; |
| 5486 | |
| 5487 | pm_runtime_mark_last_busy(device); |
| 5488 | pm_runtime_put_autosuspend(device); |
| 5489 | } |
| 5490 | |
| 5491 | void intel_init_runtime_pm(struct drm_i915_private *dev_priv) |
| 5492 | { |
| 5493 | struct drm_device *dev = dev_priv->dev; |
| 5494 | struct device *device = &dev->pdev->dev; |
| 5495 | |
| 5496 | dev_priv->pm.suspended = false; |
| 5497 | |
| 5498 | if (!HAS_RUNTIME_PM(dev)) |
| 5499 | return; |
| 5500 | |
| 5501 | pm_runtime_set_active(device); |
| 5502 | |
| 5503 | pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */ |
| 5504 | pm_runtime_mark_last_busy(device); |
| 5505 | pm_runtime_use_autosuspend(device); |
| 5506 | } |
| 5507 | |
| 5508 | void intel_fini_runtime_pm(struct drm_i915_private *dev_priv) |
| 5509 | { |
| 5510 | struct drm_device *dev = dev_priv->dev; |
| 5511 | struct device *device = &dev->pdev->dev; |
| 5512 | |
| 5513 | if (!HAS_RUNTIME_PM(dev)) |
| 5514 | return; |
| 5515 | |
| 5516 | /* Make sure we're not suspended first. */ |
| 5517 | pm_runtime_get_sync(device); |
| 5518 | pm_runtime_disable(device); |
| 5519 | } |
| 5520 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5521 | /* Set up chip specific power management-related functions */ |
| 5522 | void intel_init_pm(struct drm_device *dev) |
| 5523 | { |
| 5524 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5525 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 5526 | if (HAS_FBC(dev)) { |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 5527 | if (INTEL_INFO(dev)->gen >= 7) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5528 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 5529 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 5530 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 5531 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 5532 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 5533 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5534 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 5535 | } else if (IS_GM45(dev)) { |
| 5536 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 5537 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 5538 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 5539 | } else { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5540 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 5541 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 5542 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 5543 | |
| 5544 | /* This value was pulled out of someone's hat */ |
| 5545 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5546 | } |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5547 | } |
| 5548 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 5549 | /* For cxsr */ |
| 5550 | if (IS_PINEVIEW(dev)) |
| 5551 | i915_pineview_get_mem_freq(dev); |
| 5552 | else if (IS_GEN5(dev)) |
| 5553 | i915_ironlake_get_mem_freq(dev); |
| 5554 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5555 | /* For FIFO watermark updates */ |
| 5556 | if (HAS_PCH_SPLIT(dev)) { |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 5557 | intel_setup_wm_latency(dev); |
| 5558 | |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 5559 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 5560 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 5561 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 5562 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 5563 | dev_priv->display.update_wm = ilk_update_wm; |
| 5564 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 5565 | } else { |
| 5566 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 5567 | "Disable CxSR\n"); |
| 5568 | } |
| 5569 | |
| 5570 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5571 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 5572 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5573 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 5574 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5575 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 5576 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5577 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd602544 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 5578 | else if (INTEL_INFO(dev)->gen == 8) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5579 | dev_priv->display.init_clock_gating = gen8_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5580 | } else if (IS_VALLEYVIEW(dev)) { |
| 5581 | dev_priv->display.update_wm = valleyview_update_wm; |
| 5582 | dev_priv->display.init_clock_gating = |
| 5583 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5584 | } else if (IS_PINEVIEW(dev)) { |
| 5585 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 5586 | dev_priv->is_ddr3, |
| 5587 | dev_priv->fsb_freq, |
| 5588 | dev_priv->mem_freq)) { |
| 5589 | DRM_INFO("failed to find known CxSR latency " |
| 5590 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 5591 | "disabling CxSR\n", |
| 5592 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 5593 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 5594 | /* Disable CxSR and never update its watermark again */ |
| 5595 | pineview_disable_cxsr(dev); |
| 5596 | dev_priv->display.update_wm = NULL; |
| 5597 | } else |
| 5598 | dev_priv->display.update_wm = pineview_update_wm; |
| 5599 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 5600 | } else if (IS_G4X(dev)) { |
| 5601 | dev_priv->display.update_wm = g4x_update_wm; |
| 5602 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 5603 | } else if (IS_GEN4(dev)) { |
| 5604 | dev_priv->display.update_wm = i965_update_wm; |
| 5605 | if (IS_CRESTLINE(dev)) |
| 5606 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 5607 | else if (IS_BROADWATER(dev)) |
| 5608 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 5609 | } else if (IS_GEN3(dev)) { |
| 5610 | dev_priv->display.update_wm = i9xx_update_wm; |
| 5611 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 5612 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 5613 | } else if (IS_GEN2(dev)) { |
| 5614 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 5615 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5616 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 5617 | } else { |
| 5618 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5619 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 5623 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 5624 | else |
| 5625 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 5626 | } else { |
| 5627 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5628 | } |
| 5629 | } |
| 5630 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 5631 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 5632 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5633 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 5634 | |
| 5635 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 5636 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 5637 | return -EAGAIN; |
| 5638 | } |
| 5639 | |
| 5640 | I915_WRITE(GEN6_PCODE_DATA, *val); |
| 5641 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 5642 | |
| 5643 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 5644 | 500)) { |
| 5645 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 5646 | return -ETIMEDOUT; |
| 5647 | } |
| 5648 | |
| 5649 | *val = I915_READ(GEN6_PCODE_DATA); |
| 5650 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 5651 | |
| 5652 | return 0; |
| 5653 | } |
| 5654 | |
| 5655 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 5656 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5657 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 5658 | |
| 5659 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 5660 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 5661 | return -EAGAIN; |
| 5662 | } |
| 5663 | |
| 5664 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 5665 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 5666 | |
| 5667 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 5668 | 500)) { |
| 5669 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 5670 | return -ETIMEDOUT; |
| 5671 | } |
| 5672 | |
| 5673 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 5674 | |
| 5675 | return 0; |
| 5676 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 5677 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 5678 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5679 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5680 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5681 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5682 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 5683 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5684 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5685 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5686 | break; |
| 5687 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5688 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5689 | break; |
| 5690 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5691 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5692 | break; |
| 5693 | default: |
| 5694 | return -1; |
| 5695 | } |
| 5696 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 5697 | 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] | 5698 | } |
| 5699 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 5700 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5701 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5702 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5703 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5704 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 5705 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5706 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5707 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5708 | break; |
| 5709 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5710 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5711 | break; |
| 5712 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 5713 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 5714 | break; |
| 5715 | default: |
| 5716 | return -1; |
| 5717 | } |
| 5718 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 5719 | 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] | 5720 | } |
| 5721 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 5722 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 5723 | { |
| 5724 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5725 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 5726 | mutex_init(&dev_priv->rps.hw_lock); |
| 5727 | |
| 5728 | mutex_init(&dev_priv->pc8.lock); |
| 5729 | dev_priv->pc8.requirements_met = false; |
| 5730 | dev_priv->pc8.gpu_idle = false; |
| 5731 | dev_priv->pc8.irqs_disabled = false; |
| 5732 | dev_priv->pc8.enabled = false; |
| 5733 | dev_priv->pc8.disable_count = 2; /* requirements_met + gpu_idle */ |
| 5734 | INIT_DELAYED_WORK(&dev_priv->pc8.enable_work, hsw_enable_pc8_work); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 5735 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 5736 | intel_gen6_powersave_work); |
| 5737 | } |