Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 31 | #include "../../../platform/x86/intel_ips.h" |
| 32 | #include <linux/module.h> |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Damien Lespiau | f4db932 | 2013-06-24 22:59:50 +0100 | [diff] [blame] | 34 | #include <drm/i915_powerwell.h> |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 35 | #include <linux/pm_runtime.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 36 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 37 | /** |
| 38 | * RC6 is a special power stage which allows the GPU to enter an very |
| 39 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 40 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 41 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 42 | * |
| 43 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 44 | * among each other with the latency required to enter and leave RC6 and |
| 45 | * voltage consumed by the GPU in different states. |
| 46 | * |
| 47 | * The combination of the following flags define which states GPU is allowed |
| 48 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 49 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 50 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 51 | * which brings the most power savings; deeper states save more power, but |
| 52 | * require higher latency to switch to and wake up. |
| 53 | */ |
| 54 | #define INTEL_RC6_ENABLE (1<<0) |
| 55 | #define INTEL_RC6p_ENABLE (1<<1) |
| 56 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 57 | |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 58 | /* FBC, or Frame Buffer Compression, is a technique employed to compress the |
| 59 | * framebuffer contents in-memory, aiming at reducing the required bandwidth |
| 60 | * during in-memory transfers and, therefore, reduce the power packet. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 61 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 62 | * The benefits of FBC are mostly visible with solid backgrounds and |
| 63 | * variation-less patterns. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 64 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 65 | * FBC-related functionality can be enabled by the means of the |
| 66 | * i915.i915_enable_fbc parameter |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 67 | */ |
| 68 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 69 | static void i8xx_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 70 | { |
| 71 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 72 | u32 fbc_ctl; |
| 73 | |
| 74 | /* Disable compression */ |
| 75 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 76 | if ((fbc_ctl & FBC_CTL_EN) == 0) |
| 77 | return; |
| 78 | |
| 79 | fbc_ctl &= ~FBC_CTL_EN; |
| 80 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 81 | |
| 82 | /* Wait for compressing bit to clear */ |
| 83 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { |
| 84 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 89 | } |
| 90 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 91 | static void i8xx_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 92 | { |
| 93 | struct drm_device *dev = crtc->dev; |
| 94 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 95 | struct drm_framebuffer *fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 96 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 97 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 98 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 99 | int cfb_pitch; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 100 | int i; |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 101 | u32 fbc_ctl; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 102 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 103 | cfb_pitch = dev_priv->fbc.size / FBC_LL_SIZE; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 104 | if (fb->pitches[0] < cfb_pitch) |
| 105 | cfb_pitch = fb->pitches[0]; |
| 106 | |
Ville Syrjälä | 42a430f | 2013-11-28 17:29:56 +0200 | [diff] [blame] | 107 | /* FBC_CTL wants 32B or 64B units */ |
| 108 | if (IS_GEN2(dev)) |
| 109 | cfb_pitch = (cfb_pitch / 32) - 1; |
| 110 | else |
| 111 | cfb_pitch = (cfb_pitch / 64) - 1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 112 | |
| 113 | /* Clear old tags */ |
| 114 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 115 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 116 | |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 117 | if (IS_GEN4(dev)) { |
| 118 | u32 fbc_ctl2; |
| 119 | |
| 120 | /* Set it up... */ |
| 121 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 122 | fbc_ctl2 |= FBC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 123 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 124 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 125 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 126 | |
| 127 | /* enable it... */ |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 128 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 129 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 130 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 131 | if (IS_I945GM(dev)) |
| 132 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 133 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 134 | fbc_ctl |= obj->fence_reg; |
| 135 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 136 | |
Ville Syrjälä | 5cd5410 | 2014-01-23 16:49:16 +0200 | [diff] [blame] | 137 | DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %c\n", |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 138 | cfb_pitch, crtc->y, plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 139 | } |
| 140 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 141 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 142 | { |
| 143 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 144 | |
| 145 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 146 | } |
| 147 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 148 | static void g4x_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 149 | { |
| 150 | struct drm_device *dev = crtc->dev; |
| 151 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 152 | struct drm_framebuffer *fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 153 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 154 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 155 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 156 | u32 dpfc_ctl; |
| 157 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 158 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane) | DPFC_SR_EN; |
| 159 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 160 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 161 | else |
| 162 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 163 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 164 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 165 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 166 | |
| 167 | /* enable it... */ |
Ville Syrjälä | fe74c1a | 2014-01-23 16:49:13 +0200 | [diff] [blame] | 168 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 169 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 170 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 171 | } |
| 172 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 173 | static void g4x_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 174 | { |
| 175 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 176 | u32 dpfc_ctl; |
| 177 | |
| 178 | /* Disable compression */ |
| 179 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 180 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 181 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 182 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 183 | |
| 184 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 185 | } |
| 186 | } |
| 187 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 188 | static bool g4x_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 189 | { |
| 190 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 191 | |
| 192 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 193 | } |
| 194 | |
| 195 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 196 | { |
| 197 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 198 | u32 blt_ecoskpd; |
| 199 | |
| 200 | /* Make sure blitter notifies FBC of writes */ |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 201 | |
| 202 | /* Blitter is part of Media powerwell on VLV. No impact of |
| 203 | * his param in other platforms for now */ |
| 204 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 205 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 206 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 207 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 208 | GEN6_BLITTER_LOCK_SHIFT; |
| 209 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 210 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 211 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 212 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 213 | GEN6_BLITTER_LOCK_SHIFT); |
| 214 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 215 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 216 | |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 217 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_MEDIA); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 218 | } |
| 219 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 220 | static void ironlake_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 221 | { |
| 222 | struct drm_device *dev = crtc->dev; |
| 223 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 224 | struct drm_framebuffer *fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 225 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 226 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 227 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 228 | u32 dpfc_ctl; |
| 229 | |
Ville Syrjälä | 46f3dab | 2014-01-23 16:49:14 +0200 | [diff] [blame] | 230 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 231 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 232 | dev_priv->fbc.threshold++; |
| 233 | |
| 234 | switch (dev_priv->fbc.threshold) { |
| 235 | case 4: |
| 236 | case 3: |
| 237 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 238 | break; |
| 239 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 240 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 241 | break; |
| 242 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 243 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 244 | break; |
| 245 | } |
Ville Syrjälä | d629336 | 2013-11-21 21:29:45 +0200 | [diff] [blame] | 246 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
| 247 | if (IS_GEN5(dev)) |
| 248 | dpfc_ctl |= obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 249 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 250 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 251 | 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] | 252 | /* enable it... */ |
| 253 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 254 | |
| 255 | if (IS_GEN6(dev)) { |
| 256 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 257 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 258 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 259 | sandybridge_blit_fbc_update(dev); |
| 260 | } |
| 261 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 262 | 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] | 263 | } |
| 264 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 265 | static void ironlake_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 266 | { |
| 267 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 268 | u32 dpfc_ctl; |
| 269 | |
| 270 | /* Disable compression */ |
| 271 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 272 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 273 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 274 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 275 | |
| 276 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 277 | } |
| 278 | } |
| 279 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 280 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 281 | { |
| 282 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 283 | |
| 284 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 285 | } |
| 286 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 287 | static void gen7_enable_fbc(struct drm_crtc *crtc) |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 288 | { |
| 289 | struct drm_device *dev = crtc->dev; |
| 290 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 291 | struct drm_framebuffer *fb = crtc->primary->fb; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 292 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 293 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 294 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 295 | u32 dpfc_ctl; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 296 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 297 | dpfc_ctl = IVB_DPFC_CTL_PLANE(intel_crtc->plane); |
| 298 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 299 | dev_priv->fbc.threshold++; |
| 300 | |
| 301 | switch (dev_priv->fbc.threshold) { |
| 302 | case 4: |
| 303 | case 3: |
| 304 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 305 | break; |
| 306 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 307 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 308 | break; |
| 309 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 310 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 311 | break; |
| 312 | } |
| 313 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 314 | dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN; |
| 315 | |
| 316 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 317 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 318 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 319 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 320 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 321 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 322 | ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 323 | } else { |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 324 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 325 | I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe), |
| 326 | I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) | |
| 327 | HSW_FBCQ_DIS); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 328 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 329 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 330 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 331 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 332 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 333 | |
| 334 | sandybridge_blit_fbc_update(dev); |
| 335 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 336 | 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] | 337 | } |
| 338 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 339 | bool intel_fbc_enabled(struct drm_device *dev) |
| 340 | { |
| 341 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 342 | |
| 343 | if (!dev_priv->display.fbc_enabled) |
| 344 | return false; |
| 345 | |
| 346 | return dev_priv->display.fbc_enabled(dev); |
| 347 | } |
| 348 | |
| 349 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 350 | { |
| 351 | struct intel_fbc_work *work = |
| 352 | container_of(to_delayed_work(__work), |
| 353 | struct intel_fbc_work, work); |
| 354 | struct drm_device *dev = work->crtc->dev; |
| 355 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 356 | |
| 357 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 358 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 359 | /* Double check that we haven't switched fb without cancelling |
| 360 | * the prior work. |
| 361 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 362 | if (work->crtc->primary->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 363 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 364 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 365 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 366 | dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id; |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 367 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 368 | } |
| 369 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 370 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 371 | } |
| 372 | mutex_unlock(&dev->struct_mutex); |
| 373 | |
| 374 | kfree(work); |
| 375 | } |
| 376 | |
| 377 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 378 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 379 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 380 | return; |
| 381 | |
| 382 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 383 | |
| 384 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 385 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 386 | * entirely asynchronously. |
| 387 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 388 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 389 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 390 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 391 | |
| 392 | /* Mark the work as no longer wanted so that if it does |
| 393 | * wake-up (because the work was already running and waiting |
| 394 | * for our mutex), it will discover that is no longer |
| 395 | * necessary to run. |
| 396 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 397 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 398 | } |
| 399 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 400 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 401 | { |
| 402 | struct intel_fbc_work *work; |
| 403 | struct drm_device *dev = crtc->dev; |
| 404 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 405 | |
| 406 | if (!dev_priv->display.enable_fbc) |
| 407 | return; |
| 408 | |
| 409 | intel_cancel_fbc_work(dev_priv); |
| 410 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 411 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 412 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 413 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 414 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 415 | return; |
| 416 | } |
| 417 | |
| 418 | work->crtc = crtc; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 419 | work->fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 420 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 421 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 422 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 423 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 424 | /* Delay the actual enabling to let pageflipping cease and the |
| 425 | * display to settle before starting the compression. Note that |
| 426 | * this delay also serves a second purpose: it allows for a |
| 427 | * vblank to pass after disabling the FBC before we attempt |
| 428 | * to modify the control registers. |
| 429 | * |
| 430 | * A more complicated solution would involve tracking vblanks |
| 431 | * following the termination of the page-flipping sequence |
| 432 | * and indeed performing the enable as a co-routine and not |
| 433 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 434 | * |
| 435 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 436 | */ |
| 437 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 438 | } |
| 439 | |
| 440 | void intel_disable_fbc(struct drm_device *dev) |
| 441 | { |
| 442 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 443 | |
| 444 | intel_cancel_fbc_work(dev_priv); |
| 445 | |
| 446 | if (!dev_priv->display.disable_fbc) |
| 447 | return; |
| 448 | |
| 449 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 450 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 451 | } |
| 452 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 453 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 454 | enum no_fbc_reason reason) |
| 455 | { |
| 456 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 457 | return false; |
| 458 | |
| 459 | dev_priv->fbc.no_fbc_reason = reason; |
| 460 | return true; |
| 461 | } |
| 462 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 463 | /** |
| 464 | * intel_update_fbc - enable/disable FBC as needed |
| 465 | * @dev: the drm_device |
| 466 | * |
| 467 | * Set up the framebuffer compression hardware at mode set time. We |
| 468 | * enable it if possible: |
| 469 | * - plane A only (on pre-965) |
| 470 | * - no pixel mulitply/line duplication |
| 471 | * - no alpha buffer discard |
| 472 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 473 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 474 | * |
| 475 | * We can't assume that any compression will take place (worst case), |
| 476 | * so the compressed buffer has to be the same size as the uncompressed |
| 477 | * one. It also must reside (along with the line length buffer) in |
| 478 | * stolen memory. |
| 479 | * |
| 480 | * We need to enable/disable FBC on a global basis. |
| 481 | */ |
| 482 | void intel_update_fbc(struct drm_device *dev) |
| 483 | { |
| 484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 485 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 486 | struct intel_crtc *intel_crtc; |
| 487 | struct drm_framebuffer *fb; |
| 488 | struct intel_framebuffer *intel_fb; |
| 489 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 490 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 491 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 492 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 493 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 494 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 495 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 496 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 497 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 498 | if (!i915.powersave) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 499 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 500 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 501 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 502 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 503 | |
| 504 | /* |
| 505 | * If FBC is already on, we just have to verify that we can |
| 506 | * keep it that way... |
| 507 | * Need to disable if: |
| 508 | * - more than one pipe is active |
| 509 | * - changing FBC params (stride, fence, mode) |
| 510 | * - new fb is too large to fit in compressed buffer |
| 511 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 512 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 513 | for_each_crtc(dev, tmp_crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 514 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 515 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 516 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 517 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 518 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 519 | goto out_disable; |
| 520 | } |
| 521 | crtc = tmp_crtc; |
| 522 | } |
| 523 | } |
| 524 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 525 | if (!crtc || crtc->primary->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 526 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 527 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 528 | goto out_disable; |
| 529 | } |
| 530 | |
| 531 | intel_crtc = to_intel_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 532 | fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 533 | intel_fb = to_intel_framebuffer(fb); |
| 534 | obj = intel_fb->obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 535 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 536 | |
Chris Wilson | 0368920 | 2014-06-06 10:37:11 +0100 | [diff] [blame] | 537 | if (i915.enable_fbc < 0) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 538 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 539 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 540 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 541 | } |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 542 | if (!i915.enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 543 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 544 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 545 | goto out_disable; |
| 546 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 547 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 548 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 549 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 550 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 551 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 552 | goto out_disable; |
| 553 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 554 | |
Daisy Sun | 032843a | 2014-06-16 15:48:18 -0700 | [diff] [blame] | 555 | if (INTEL_INFO(dev)->gen >= 8 || IS_HASWELL(dev)) { |
| 556 | max_width = 4096; |
| 557 | max_height = 4096; |
| 558 | } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 559 | max_width = 4096; |
| 560 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 561 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 562 | max_width = 2048; |
| 563 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 564 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 565 | if (intel_crtc->config.pipe_src_w > max_width || |
| 566 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 567 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 568 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 569 | goto out_disable; |
| 570 | } |
Ben Widawsky | 8f94d24 | 2014-02-20 16:01:20 -0800 | [diff] [blame] | 571 | if ((INTEL_INFO(dev)->gen < 4 || HAS_DDI(dev)) && |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 572 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 573 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 574 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 575 | goto out_disable; |
| 576 | } |
| 577 | |
| 578 | /* The use of a CPU fence is mandatory in order to detect writes |
| 579 | * by the CPU to the scanout and trigger updates to the FBC. |
| 580 | */ |
| 581 | if (obj->tiling_mode != I915_TILING_X || |
| 582 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 583 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 584 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 585 | goto out_disable; |
| 586 | } |
| 587 | |
| 588 | /* If the kernel debugger is active, always disable compression */ |
| 589 | if (in_dbg_master()) |
| 590 | goto out_disable; |
| 591 | |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 592 | if (i915_gem_stolen_setup_compression(dev, intel_fb->obj->base.size, |
| 593 | drm_format_plane_cpp(fb->pixel_format, 0))) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 594 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 595 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 596 | goto out_disable; |
| 597 | } |
| 598 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 599 | /* If the scanout has not changed, don't modify the FBC settings. |
| 600 | * Note that we make the fundamental assumption that the fb->obj |
| 601 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 602 | * without first being decoupled from the scanout and FBC disabled. |
| 603 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 604 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 605 | dev_priv->fbc.fb_id == fb->base.id && |
| 606 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 607 | return; |
| 608 | |
| 609 | if (intel_fbc_enabled(dev)) { |
| 610 | /* We update FBC along two paths, after changing fb/crtc |
| 611 | * configuration (modeswitching) and after page-flipping |
| 612 | * finishes. For the latter, we know that not only did |
| 613 | * we disable the FBC at the start of the page-flip |
| 614 | * sequence, but also more than one vblank has passed. |
| 615 | * |
| 616 | * For the former case of modeswitching, it is possible |
| 617 | * to switch between two FBC valid configurations |
| 618 | * instantaneously so we do need to disable the FBC |
| 619 | * before we can modify its control registers. We also |
| 620 | * have to wait for the next vblank for that to take |
| 621 | * effect. However, since we delay enabling FBC we can |
| 622 | * assume that a vblank has passed since disabling and |
| 623 | * that we can safely alter the registers in the deferred |
| 624 | * callback. |
| 625 | * |
| 626 | * In the scenario that we go from a valid to invalid |
| 627 | * and then back to valid FBC configuration we have |
| 628 | * no strict enforcement that a vblank occurred since |
| 629 | * disabling the FBC. However, along all current pipe |
| 630 | * disabling paths we do need to wait for a vblank at |
| 631 | * some point. And we wait before enabling FBC anyway. |
| 632 | */ |
| 633 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 634 | intel_disable_fbc(dev); |
| 635 | } |
| 636 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 637 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 638 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 639 | return; |
| 640 | |
| 641 | out_disable: |
| 642 | /* Multiple disables should be harmless */ |
| 643 | if (intel_fbc_enabled(dev)) { |
| 644 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 645 | intel_disable_fbc(dev); |
| 646 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 647 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 648 | } |
| 649 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 650 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 651 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 652 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 653 | u32 tmp; |
| 654 | |
| 655 | tmp = I915_READ(CLKCFG); |
| 656 | |
| 657 | switch (tmp & CLKCFG_FSB_MASK) { |
| 658 | case CLKCFG_FSB_533: |
| 659 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 660 | break; |
| 661 | case CLKCFG_FSB_800: |
| 662 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 663 | break; |
| 664 | case CLKCFG_FSB_667: |
| 665 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 666 | break; |
| 667 | case CLKCFG_FSB_400: |
| 668 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 669 | break; |
| 670 | } |
| 671 | |
| 672 | switch (tmp & CLKCFG_MEM_MASK) { |
| 673 | case CLKCFG_MEM_533: |
| 674 | dev_priv->mem_freq = 533; |
| 675 | break; |
| 676 | case CLKCFG_MEM_667: |
| 677 | dev_priv->mem_freq = 667; |
| 678 | break; |
| 679 | case CLKCFG_MEM_800: |
| 680 | dev_priv->mem_freq = 800; |
| 681 | break; |
| 682 | } |
| 683 | |
| 684 | /* detect pineview DDR3 setting */ |
| 685 | tmp = I915_READ(CSHRDDR3CTL); |
| 686 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 687 | } |
| 688 | |
| 689 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 690 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 691 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 692 | u16 ddrpll, csipll; |
| 693 | |
| 694 | ddrpll = I915_READ16(DDRMPLL1); |
| 695 | csipll = I915_READ16(CSIPLL0); |
| 696 | |
| 697 | switch (ddrpll & 0xff) { |
| 698 | case 0xc: |
| 699 | dev_priv->mem_freq = 800; |
| 700 | break; |
| 701 | case 0x10: |
| 702 | dev_priv->mem_freq = 1066; |
| 703 | break; |
| 704 | case 0x14: |
| 705 | dev_priv->mem_freq = 1333; |
| 706 | break; |
| 707 | case 0x18: |
| 708 | dev_priv->mem_freq = 1600; |
| 709 | break; |
| 710 | default: |
| 711 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 712 | ddrpll & 0xff); |
| 713 | dev_priv->mem_freq = 0; |
| 714 | break; |
| 715 | } |
| 716 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 717 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 718 | |
| 719 | switch (csipll & 0x3ff) { |
| 720 | case 0x00c: |
| 721 | dev_priv->fsb_freq = 3200; |
| 722 | break; |
| 723 | case 0x00e: |
| 724 | dev_priv->fsb_freq = 3733; |
| 725 | break; |
| 726 | case 0x010: |
| 727 | dev_priv->fsb_freq = 4266; |
| 728 | break; |
| 729 | case 0x012: |
| 730 | dev_priv->fsb_freq = 4800; |
| 731 | break; |
| 732 | case 0x014: |
| 733 | dev_priv->fsb_freq = 5333; |
| 734 | break; |
| 735 | case 0x016: |
| 736 | dev_priv->fsb_freq = 5866; |
| 737 | break; |
| 738 | case 0x018: |
| 739 | dev_priv->fsb_freq = 6400; |
| 740 | break; |
| 741 | default: |
| 742 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 743 | csipll & 0x3ff); |
| 744 | dev_priv->fsb_freq = 0; |
| 745 | break; |
| 746 | } |
| 747 | |
| 748 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 749 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 750 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 751 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 752 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 753 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 757 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 758 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 759 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 760 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 761 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 762 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 763 | |
| 764 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 765 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 766 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 767 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 768 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 769 | |
| 770 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 771 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 772 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 773 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 774 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 775 | |
| 776 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 777 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 778 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 779 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 780 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 781 | |
| 782 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 783 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 784 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 785 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 786 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 787 | |
| 788 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 789 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 790 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 791 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 792 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 793 | }; |
| 794 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 795 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 796 | int is_ddr3, |
| 797 | int fsb, |
| 798 | int mem) |
| 799 | { |
| 800 | const struct cxsr_latency *latency; |
| 801 | int i; |
| 802 | |
| 803 | if (fsb == 0 || mem == 0) |
| 804 | return NULL; |
| 805 | |
| 806 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 807 | latency = &cxsr_latency_table[i]; |
| 808 | if (is_desktop == latency->is_desktop && |
| 809 | is_ddr3 == latency->is_ddr3 && |
| 810 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 811 | return latency; |
| 812 | } |
| 813 | |
| 814 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 815 | |
| 816 | return NULL; |
| 817 | } |
| 818 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 819 | void intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 820 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 821 | struct drm_device *dev = dev_priv->dev; |
| 822 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 823 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 824 | if (IS_VALLEYVIEW(dev)) { |
| 825 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 826 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 827 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 828 | } else if (IS_PINEVIEW(dev)) { |
| 829 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 830 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 831 | I915_WRITE(DSPFW3, val); |
| 832 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 833 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 834 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 835 | I915_WRITE(FW_BLC_SELF, val); |
| 836 | } else if (IS_I915GM(dev)) { |
| 837 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 838 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 839 | I915_WRITE(INSTPM, val); |
| 840 | } else { |
| 841 | return; |
| 842 | } |
| 843 | |
| 844 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 845 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | /* |
| 849 | * Latency for FIFO fetches is dependent on several factors: |
| 850 | * - memory configuration (speed, channels) |
| 851 | * - chipset |
| 852 | * - current MCH state |
| 853 | * It can be fairly high in some situations, so here we assume a fairly |
| 854 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 855 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 856 | * and power consumption (set it too low to save power and we might see |
| 857 | * FIFO underruns and display "flicker"). |
| 858 | * |
| 859 | * A value of 5us seems to be a good balance; safe for very low end |
| 860 | * platforms but not overly aggressive on lower latency configs. |
| 861 | */ |
| 862 | static const int latency_ns = 5000; |
| 863 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 864 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 865 | { |
| 866 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 867 | uint32_t dsparb = I915_READ(DSPARB); |
| 868 | int size; |
| 869 | |
| 870 | size = dsparb & 0x7f; |
| 871 | if (plane) |
| 872 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 873 | |
| 874 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 875 | plane ? "B" : "A", size); |
| 876 | |
| 877 | return size; |
| 878 | } |
| 879 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 880 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 881 | { |
| 882 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 883 | uint32_t dsparb = I915_READ(DSPARB); |
| 884 | int size; |
| 885 | |
| 886 | size = dsparb & 0x1ff; |
| 887 | if (plane) |
| 888 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 889 | size >>= 1; /* Convert to cachelines */ |
| 890 | |
| 891 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 892 | plane ? "B" : "A", size); |
| 893 | |
| 894 | return size; |
| 895 | } |
| 896 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 897 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 898 | { |
| 899 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 900 | uint32_t dsparb = I915_READ(DSPARB); |
| 901 | int size; |
| 902 | |
| 903 | size = dsparb & 0x7f; |
| 904 | size >>= 2; /* Convert to cachelines */ |
| 905 | |
| 906 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 907 | plane ? "B" : "A", |
| 908 | size); |
| 909 | |
| 910 | return size; |
| 911 | } |
| 912 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | /* Pineview has different values for various configs */ |
| 914 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 915 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 916 | .max_wm = PINEVIEW_MAX_WM, |
| 917 | .default_wm = PINEVIEW_DFT_WM, |
| 918 | .guard_size = PINEVIEW_GUARD_WM, |
| 919 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 920 | }; |
| 921 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 922 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 923 | .max_wm = PINEVIEW_MAX_WM, |
| 924 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 925 | .guard_size = PINEVIEW_GUARD_WM, |
| 926 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 927 | }; |
| 928 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 929 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 930 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 931 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 932 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 933 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 934 | }; |
| 935 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 936 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 937 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 938 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 939 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 940 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 941 | }; |
| 942 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 943 | .fifo_size = G4X_FIFO_SIZE, |
| 944 | .max_wm = G4X_MAX_WM, |
| 945 | .default_wm = G4X_MAX_WM, |
| 946 | .guard_size = 2, |
| 947 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 948 | }; |
| 949 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 950 | .fifo_size = I965_CURSOR_FIFO, |
| 951 | .max_wm = I965_CURSOR_MAX_WM, |
| 952 | .default_wm = I965_CURSOR_DFT_WM, |
| 953 | .guard_size = 2, |
| 954 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 955 | }; |
| 956 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 957 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 958 | .max_wm = VALLEYVIEW_MAX_WM, |
| 959 | .default_wm = VALLEYVIEW_MAX_WM, |
| 960 | .guard_size = 2, |
| 961 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 962 | }; |
| 963 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 964 | .fifo_size = I965_CURSOR_FIFO, |
| 965 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 966 | .default_wm = I965_CURSOR_DFT_WM, |
| 967 | .guard_size = 2, |
| 968 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 969 | }; |
| 970 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 971 | .fifo_size = I965_CURSOR_FIFO, |
| 972 | .max_wm = I965_CURSOR_MAX_WM, |
| 973 | .default_wm = I965_CURSOR_DFT_WM, |
| 974 | .guard_size = 2, |
| 975 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 976 | }; |
| 977 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 978 | .fifo_size = I945_FIFO_SIZE, |
| 979 | .max_wm = I915_MAX_WM, |
| 980 | .default_wm = 1, |
| 981 | .guard_size = 2, |
| 982 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 983 | }; |
| 984 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 985 | .fifo_size = I915_FIFO_SIZE, |
| 986 | .max_wm = I915_MAX_WM, |
| 987 | .default_wm = 1, |
| 988 | .guard_size = 2, |
| 989 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 990 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 991 | static const struct intel_watermark_params i830_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 992 | .fifo_size = I855GM_FIFO_SIZE, |
| 993 | .max_wm = I915_MAX_WM, |
| 994 | .default_wm = 1, |
| 995 | .guard_size = 2, |
| 996 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 997 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 998 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 999 | .fifo_size = I830_FIFO_SIZE, |
| 1000 | .max_wm = I915_MAX_WM, |
| 1001 | .default_wm = 1, |
| 1002 | .guard_size = 2, |
| 1003 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1004 | }; |
| 1005 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1006 | /** |
| 1007 | * intel_calculate_wm - calculate watermark level |
| 1008 | * @clock_in_khz: pixel clock |
| 1009 | * @wm: chip FIFO params |
| 1010 | * @pixel_size: display pixel size |
| 1011 | * @latency_ns: memory latency for the platform |
| 1012 | * |
| 1013 | * Calculate the watermark level (the level at which the display plane will |
| 1014 | * start fetching from memory again). Each chip has a different display |
| 1015 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 1016 | * in the correct intel_watermark_params structure. |
| 1017 | * |
| 1018 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 1019 | * on the pixel size. When it reaches the watermark level, it'll start |
| 1020 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 1021 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 1022 | * will occur, and a display engine hang could result. |
| 1023 | */ |
| 1024 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 1025 | const struct intel_watermark_params *wm, |
| 1026 | int fifo_size, |
| 1027 | int pixel_size, |
| 1028 | unsigned long latency_ns) |
| 1029 | { |
| 1030 | long entries_required, wm_size; |
| 1031 | |
| 1032 | /* |
| 1033 | * Note: we need to make sure we don't overflow for various clock & |
| 1034 | * latency values. |
| 1035 | * clocks go from a few thousand to several hundred thousand. |
| 1036 | * latency is usually a few thousand |
| 1037 | */ |
| 1038 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 1039 | 1000; |
| 1040 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 1041 | |
| 1042 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 1043 | |
| 1044 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 1045 | |
| 1046 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 1047 | |
| 1048 | /* Don't promote wm_size to unsigned... */ |
| 1049 | if (wm_size > (long)wm->max_wm) |
| 1050 | wm_size = wm->max_wm; |
| 1051 | if (wm_size <= 0) |
| 1052 | wm_size = wm->default_wm; |
| 1053 | return wm_size; |
| 1054 | } |
| 1055 | |
| 1056 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 1057 | { |
| 1058 | struct drm_crtc *crtc, *enabled = NULL; |
| 1059 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 1060 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1061 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1062 | if (enabled) |
| 1063 | return NULL; |
| 1064 | enabled = crtc; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | return enabled; |
| 1069 | } |
| 1070 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1071 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1072 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1073 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1074 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1075 | struct drm_crtc *crtc; |
| 1076 | const struct cxsr_latency *latency; |
| 1077 | u32 reg; |
| 1078 | unsigned long wm; |
| 1079 | |
| 1080 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1081 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1082 | if (!latency) { |
| 1083 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1084 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1085 | return; |
| 1086 | } |
| 1087 | |
| 1088 | crtc = single_enabled_crtc(dev); |
| 1089 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1090 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1091 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1092 | int clock; |
| 1093 | |
| 1094 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1095 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1096 | |
| 1097 | /* Display SR */ |
| 1098 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1099 | pineview_display_wm.fifo_size, |
| 1100 | pixel_size, latency->display_sr); |
| 1101 | reg = I915_READ(DSPFW1); |
| 1102 | reg &= ~DSPFW_SR_MASK; |
| 1103 | reg |= wm << DSPFW_SR_SHIFT; |
| 1104 | I915_WRITE(DSPFW1, reg); |
| 1105 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1106 | |
| 1107 | /* cursor SR */ |
| 1108 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1109 | pineview_display_wm.fifo_size, |
| 1110 | pixel_size, latency->cursor_sr); |
| 1111 | reg = I915_READ(DSPFW3); |
| 1112 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1113 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1114 | I915_WRITE(DSPFW3, reg); |
| 1115 | |
| 1116 | /* Display HPLL off SR */ |
| 1117 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1118 | pineview_display_hplloff_wm.fifo_size, |
| 1119 | pixel_size, latency->display_hpll_disable); |
| 1120 | reg = I915_READ(DSPFW3); |
| 1121 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1122 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1123 | I915_WRITE(DSPFW3, reg); |
| 1124 | |
| 1125 | /* cursor HPLL off SR */ |
| 1126 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1127 | pineview_display_hplloff_wm.fifo_size, |
| 1128 | pixel_size, latency->cursor_hpll_disable); |
| 1129 | reg = I915_READ(DSPFW3); |
| 1130 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1131 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1132 | I915_WRITE(DSPFW3, reg); |
| 1133 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1134 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1135 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1136 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1137 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1142 | int plane, |
| 1143 | const struct intel_watermark_params *display, |
| 1144 | int display_latency_ns, |
| 1145 | const struct intel_watermark_params *cursor, |
| 1146 | int cursor_latency_ns, |
| 1147 | int *plane_wm, |
| 1148 | int *cursor_wm) |
| 1149 | { |
| 1150 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1151 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1152 | int htotal, hdisplay, clock, pixel_size; |
| 1153 | int line_time_us, line_count; |
| 1154 | int entries, tlb_miss; |
| 1155 | |
| 1156 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1157 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1158 | *cursor_wm = cursor->guard_size; |
| 1159 | *plane_wm = display->guard_size; |
| 1160 | return false; |
| 1161 | } |
| 1162 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1163 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1164 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1165 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1166 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1167 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1168 | |
| 1169 | /* Use the small buffer method to calculate plane watermark */ |
| 1170 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1171 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1172 | if (tlb_miss > 0) |
| 1173 | entries += tlb_miss; |
| 1174 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1175 | *plane_wm = entries + display->guard_size; |
| 1176 | if (*plane_wm > (int)display->max_wm) |
| 1177 | *plane_wm = display->max_wm; |
| 1178 | |
| 1179 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1180 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1181 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1182 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1183 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1184 | if (tlb_miss > 0) |
| 1185 | entries += tlb_miss; |
| 1186 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1187 | *cursor_wm = entries + cursor->guard_size; |
| 1188 | if (*cursor_wm > (int)cursor->max_wm) |
| 1189 | *cursor_wm = (int)cursor->max_wm; |
| 1190 | |
| 1191 | return true; |
| 1192 | } |
| 1193 | |
| 1194 | /* |
| 1195 | * Check the wm result. |
| 1196 | * |
| 1197 | * If any calculated watermark values is larger than the maximum value that |
| 1198 | * can be programmed into the associated watermark register, that watermark |
| 1199 | * must be disabled. |
| 1200 | */ |
| 1201 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1202 | int display_wm, int cursor_wm, |
| 1203 | const struct intel_watermark_params *display, |
| 1204 | const struct intel_watermark_params *cursor) |
| 1205 | { |
| 1206 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1207 | display_wm, cursor_wm); |
| 1208 | |
| 1209 | if (display_wm > display->max_wm) { |
| 1210 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1211 | display_wm, display->max_wm); |
| 1212 | return false; |
| 1213 | } |
| 1214 | |
| 1215 | if (cursor_wm > cursor->max_wm) { |
| 1216 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1217 | cursor_wm, cursor->max_wm); |
| 1218 | return false; |
| 1219 | } |
| 1220 | |
| 1221 | if (!(display_wm || cursor_wm)) { |
| 1222 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1223 | return false; |
| 1224 | } |
| 1225 | |
| 1226 | return true; |
| 1227 | } |
| 1228 | |
| 1229 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1230 | int plane, |
| 1231 | int latency_ns, |
| 1232 | const struct intel_watermark_params *display, |
| 1233 | const struct intel_watermark_params *cursor, |
| 1234 | int *display_wm, int *cursor_wm) |
| 1235 | { |
| 1236 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1237 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1238 | int hdisplay, htotal, pixel_size, clock; |
| 1239 | unsigned long line_time_us; |
| 1240 | int line_count, line_size; |
| 1241 | int small, large; |
| 1242 | int entries; |
| 1243 | |
| 1244 | if (!latency_ns) { |
| 1245 | *display_wm = *cursor_wm = 0; |
| 1246 | return false; |
| 1247 | } |
| 1248 | |
| 1249 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1250 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1251 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1252 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1253 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1254 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1255 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1256 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1257 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1258 | line_size = hdisplay * pixel_size; |
| 1259 | |
| 1260 | /* Use the minimum of the small and large buffer method for primary */ |
| 1261 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1262 | large = line_count * line_size; |
| 1263 | |
| 1264 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1265 | *display_wm = entries + display->guard_size; |
| 1266 | |
| 1267 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1268 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1269 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1270 | *cursor_wm = entries + cursor->guard_size; |
| 1271 | |
| 1272 | return g4x_check_srwm(dev, |
| 1273 | *display_wm, *cursor_wm, |
| 1274 | display, cursor); |
| 1275 | } |
| 1276 | |
| 1277 | static bool vlv_compute_drain_latency(struct drm_device *dev, |
| 1278 | int plane, |
| 1279 | int *plane_prec_mult, |
| 1280 | int *plane_dl, |
| 1281 | int *cursor_prec_mult, |
| 1282 | int *cursor_dl) |
| 1283 | { |
| 1284 | struct drm_crtc *crtc; |
| 1285 | int clock, pixel_size; |
| 1286 | int entries; |
| 1287 | |
| 1288 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1289 | if (!intel_crtc_active(crtc)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1290 | return false; |
| 1291 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1292 | clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1293 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1294 | |
| 1295 | entries = (clock / 1000) * pixel_size; |
| 1296 | *plane_prec_mult = (entries > 256) ? |
| 1297 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1298 | *plane_dl = (64 * (*plane_prec_mult) * 4) / ((clock / 1000) * |
| 1299 | pixel_size); |
| 1300 | |
| 1301 | entries = (clock / 1000) * 4; /* BPP is always 4 for cursor */ |
| 1302 | *cursor_prec_mult = (entries > 256) ? |
| 1303 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1304 | *cursor_dl = (64 * (*cursor_prec_mult) * 4) / ((clock / 1000) * 4); |
| 1305 | |
| 1306 | return true; |
| 1307 | } |
| 1308 | |
| 1309 | /* |
| 1310 | * Update drain latency registers of memory arbiter |
| 1311 | * |
| 1312 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1313 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1314 | * latency value. |
| 1315 | */ |
| 1316 | |
| 1317 | static void vlv_update_drain_latency(struct drm_device *dev) |
| 1318 | { |
| 1319 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1320 | int planea_prec, planea_dl, planeb_prec, planeb_dl; |
| 1321 | int cursora_prec, cursora_dl, cursorb_prec, cursorb_dl; |
| 1322 | int plane_prec_mult, cursor_prec_mult; /* Precision multiplier is |
| 1323 | either 16 or 32 */ |
| 1324 | |
| 1325 | /* For plane A, Cursor A */ |
| 1326 | if (vlv_compute_drain_latency(dev, 0, &plane_prec_mult, &planea_dl, |
| 1327 | &cursor_prec_mult, &cursora_dl)) { |
| 1328 | cursora_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1329 | DDL_CURSORA_PRECISION_32 : DDL_CURSORA_PRECISION_16; |
| 1330 | planea_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1331 | DDL_PLANEA_PRECISION_32 : DDL_PLANEA_PRECISION_16; |
| 1332 | |
| 1333 | I915_WRITE(VLV_DDL1, cursora_prec | |
| 1334 | (cursora_dl << DDL_CURSORA_SHIFT) | |
| 1335 | planea_prec | planea_dl); |
| 1336 | } |
| 1337 | |
| 1338 | /* For plane B, Cursor B */ |
| 1339 | if (vlv_compute_drain_latency(dev, 1, &plane_prec_mult, &planeb_dl, |
| 1340 | &cursor_prec_mult, &cursorb_dl)) { |
| 1341 | cursorb_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1342 | DDL_CURSORB_PRECISION_32 : DDL_CURSORB_PRECISION_16; |
| 1343 | planeb_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1344 | DDL_PLANEB_PRECISION_32 : DDL_PLANEB_PRECISION_16; |
| 1345 | |
| 1346 | I915_WRITE(VLV_DDL2, cursorb_prec | |
| 1347 | (cursorb_dl << DDL_CURSORB_SHIFT) | |
| 1348 | planeb_prec | planeb_dl); |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1353 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1354 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1355 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1356 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1357 | static const int sr_latency_ns = 12000; |
| 1358 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1359 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1360 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1361 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1362 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1363 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1364 | |
| 1365 | vlv_update_drain_latency(dev); |
| 1366 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1367 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1368 | &valleyview_wm_info, latency_ns, |
| 1369 | &valleyview_cursor_wm_info, latency_ns, |
| 1370 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1371 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1372 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1373 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1374 | &valleyview_wm_info, latency_ns, |
| 1375 | &valleyview_cursor_wm_info, latency_ns, |
| 1376 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1377 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1378 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1379 | if (single_plane_enabled(enabled) && |
| 1380 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1381 | sr_latency_ns, |
| 1382 | &valleyview_wm_info, |
| 1383 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1384 | &plane_sr, &ignore_cursor_sr) && |
| 1385 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1386 | 2*sr_latency_ns, |
| 1387 | &valleyview_wm_info, |
| 1388 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1389 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1390 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1391 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1392 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1393 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1394 | plane_sr = cursor_sr = 0; |
| 1395 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1396 | |
| 1397 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1398 | planea_wm, cursora_wm, |
| 1399 | planeb_wm, cursorb_wm, |
| 1400 | plane_sr, cursor_sr); |
| 1401 | |
| 1402 | I915_WRITE(DSPFW1, |
| 1403 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1404 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1405 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1406 | planea_wm); |
| 1407 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1408 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1409 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1410 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1411 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1412 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1413 | |
| 1414 | if (cxsr_enabled) |
| 1415 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1416 | } |
| 1417 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1418 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1419 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1420 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1421 | static const int sr_latency_ns = 12000; |
| 1422 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1423 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1424 | int plane_sr, cursor_sr; |
| 1425 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1426 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1427 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1428 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1429 | &g4x_wm_info, latency_ns, |
| 1430 | &g4x_cursor_wm_info, latency_ns, |
| 1431 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1432 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1433 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1434 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1435 | &g4x_wm_info, latency_ns, |
| 1436 | &g4x_cursor_wm_info, latency_ns, |
| 1437 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1438 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1439 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1440 | if (single_plane_enabled(enabled) && |
| 1441 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1442 | sr_latency_ns, |
| 1443 | &g4x_wm_info, |
| 1444 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1445 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1446 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1447 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1448 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1449 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1450 | plane_sr = cursor_sr = 0; |
| 1451 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1452 | |
| 1453 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1454 | planea_wm, cursora_wm, |
| 1455 | planeb_wm, cursorb_wm, |
| 1456 | plane_sr, cursor_sr); |
| 1457 | |
| 1458 | I915_WRITE(DSPFW1, |
| 1459 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1460 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1461 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1462 | planea_wm); |
| 1463 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1464 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1465 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1466 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1467 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1468 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1469 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1470 | |
| 1471 | if (cxsr_enabled) |
| 1472 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1473 | } |
| 1474 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1475 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1476 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1477 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1478 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1479 | struct drm_crtc *crtc; |
| 1480 | int srwm = 1; |
| 1481 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1482 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1483 | |
| 1484 | /* Calc sr entries for one plane configs */ |
| 1485 | crtc = single_enabled_crtc(dev); |
| 1486 | if (crtc) { |
| 1487 | /* self-refresh has much higher latency */ |
| 1488 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1489 | const struct drm_display_mode *adjusted_mode = |
| 1490 | &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1491 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1492 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1493 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1494 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1495 | unsigned long line_time_us; |
| 1496 | int entries; |
| 1497 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1498 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1499 | |
| 1500 | /* Use ns/us then divide to preserve precision */ |
| 1501 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1502 | pixel_size * hdisplay; |
| 1503 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1504 | srwm = I965_FIFO_SIZE - entries; |
| 1505 | if (srwm < 0) |
| 1506 | srwm = 1; |
| 1507 | srwm &= 0x1ff; |
| 1508 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1509 | entries, srwm); |
| 1510 | |
| 1511 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1512 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1513 | entries = DIV_ROUND_UP(entries, |
| 1514 | i965_cursor_wm_info.cacheline_size); |
| 1515 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1516 | (entries + i965_cursor_wm_info.guard_size); |
| 1517 | |
| 1518 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1519 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1520 | |
| 1521 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1522 | "cursor %d\n", srwm, cursor_sr); |
| 1523 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1524 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1525 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1526 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1527 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1528 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1532 | srwm); |
| 1533 | |
| 1534 | /* 965 has limitations... */ |
| 1535 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
| 1536 | (8 << 16) | (8 << 8) | (8 << 0)); |
| 1537 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); |
| 1538 | /* update cursor SR watermark */ |
| 1539 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame^] | 1540 | |
| 1541 | if (cxsr_enabled) |
| 1542 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1543 | } |
| 1544 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1545 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1546 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1547 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1548 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1549 | const struct intel_watermark_params *wm_info; |
| 1550 | uint32_t fwater_lo; |
| 1551 | uint32_t fwater_hi; |
| 1552 | int cwm, srwm = 1; |
| 1553 | int fifo_size; |
| 1554 | int planea_wm, planeb_wm; |
| 1555 | struct drm_crtc *crtc, *enabled = NULL; |
| 1556 | |
| 1557 | if (IS_I945GM(dev)) |
| 1558 | wm_info = &i945_wm_info; |
| 1559 | else if (!IS_GEN2(dev)) |
| 1560 | wm_info = &i915_wm_info; |
| 1561 | else |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1562 | wm_info = &i830_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1563 | |
| 1564 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1565 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1566 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1567 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1568 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1569 | if (IS_GEN2(dev)) |
| 1570 | cpp = 4; |
| 1571 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1572 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1573 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1574 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1575 | latency_ns); |
| 1576 | enabled = crtc; |
| 1577 | } else |
| 1578 | planea_wm = fifo_size - wm_info->guard_size; |
| 1579 | |
| 1580 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1581 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1582 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1583 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1584 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1585 | if (IS_GEN2(dev)) |
| 1586 | cpp = 4; |
| 1587 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1588 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1589 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1590 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1591 | latency_ns); |
| 1592 | if (enabled == NULL) |
| 1593 | enabled = crtc; |
| 1594 | else |
| 1595 | enabled = NULL; |
| 1596 | } else |
| 1597 | planeb_wm = fifo_size - wm_info->guard_size; |
| 1598 | |
| 1599 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1600 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1601 | if (IS_I915GM(dev) && enabled) { |
| 1602 | struct intel_framebuffer *fb; |
| 1603 | |
| 1604 | fb = to_intel_framebuffer(enabled->primary->fb); |
| 1605 | |
| 1606 | /* self-refresh seems busted with untiled */ |
| 1607 | if (fb->obj->tiling_mode == I915_TILING_NONE) |
| 1608 | enabled = NULL; |
| 1609 | } |
| 1610 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1611 | /* |
| 1612 | * Overlay gets an aggressive default since video jitter is bad. |
| 1613 | */ |
| 1614 | cwm = 2; |
| 1615 | |
| 1616 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1617 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1618 | |
| 1619 | /* Calc sr entries for one plane configs */ |
| 1620 | if (HAS_FW_BLC(dev) && enabled) { |
| 1621 | /* self-refresh has much higher latency */ |
| 1622 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1623 | const struct drm_display_mode *adjusted_mode = |
| 1624 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1625 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1626 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1627 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1628 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1629 | unsigned long line_time_us; |
| 1630 | int entries; |
| 1631 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1632 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1633 | |
| 1634 | /* Use ns/us then divide to preserve precision */ |
| 1635 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1636 | pixel_size * hdisplay; |
| 1637 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1638 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1639 | srwm = wm_info->fifo_size - entries; |
| 1640 | if (srwm < 0) |
| 1641 | srwm = 1; |
| 1642 | |
| 1643 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1644 | I915_WRITE(FW_BLC_SELF, |
| 1645 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1646 | else if (IS_I915GM(dev)) |
| 1647 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1648 | } |
| 1649 | |
| 1650 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1651 | planea_wm, planeb_wm, cwm, srwm); |
| 1652 | |
| 1653 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1654 | fwater_hi = (cwm & 0x1f); |
| 1655 | |
| 1656 | /* Set request length to 8 cachelines per fetch */ |
| 1657 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1658 | fwater_hi = fwater_hi | (1 << 8); |
| 1659 | |
| 1660 | I915_WRITE(FW_BLC, fwater_lo); |
| 1661 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1662 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1663 | if (enabled) |
| 1664 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1665 | } |
| 1666 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1667 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1668 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1669 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1670 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1671 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1672 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1673 | uint32_t fwater_lo; |
| 1674 | int planea_wm; |
| 1675 | |
| 1676 | crtc = single_enabled_crtc(dev); |
| 1677 | if (crtc == NULL) |
| 1678 | return; |
| 1679 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1680 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1681 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1682 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1683 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1684 | 4, latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1685 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1686 | fwater_lo |= (3<<8) | planea_wm; |
| 1687 | |
| 1688 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1689 | |
| 1690 | I915_WRITE(FW_BLC, fwater_lo); |
| 1691 | } |
| 1692 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1693 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1694 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1695 | { |
| 1696 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1697 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1698 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1699 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1700 | |
| 1701 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1702 | * adjust the pixel_rate here. */ |
| 1703 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1704 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1705 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1706 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1707 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1708 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1709 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1710 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1711 | pfit_h = pfit_size & 0xFFFF; |
| 1712 | if (pipe_w < pfit_w) |
| 1713 | pipe_w = pfit_w; |
| 1714 | if (pipe_h < pfit_h) |
| 1715 | pipe_h = pfit_h; |
| 1716 | |
| 1717 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1718 | pfit_w * pfit_h); |
| 1719 | } |
| 1720 | |
| 1721 | return pixel_rate; |
| 1722 | } |
| 1723 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1724 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1725 | 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] | 1726 | uint32_t latency) |
| 1727 | { |
| 1728 | uint64_t ret; |
| 1729 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1730 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1731 | return UINT_MAX; |
| 1732 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1733 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1734 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1735 | |
| 1736 | return ret; |
| 1737 | } |
| 1738 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1739 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1740 | 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] | 1741 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1742 | uint32_t latency) |
| 1743 | { |
| 1744 | uint32_t ret; |
| 1745 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1746 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1747 | return UINT_MAX; |
| 1748 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1749 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1750 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1751 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1752 | return ret; |
| 1753 | } |
| 1754 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1755 | 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] | 1756 | uint8_t bytes_per_pixel) |
| 1757 | { |
| 1758 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1759 | } |
| 1760 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1761 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1762 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1763 | uint32_t pipe_htotal; |
| 1764 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1765 | struct intel_plane_wm_parameters pri; |
| 1766 | struct intel_plane_wm_parameters spr; |
| 1767 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1768 | }; |
| 1769 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1770 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1771 | uint16_t pri; |
| 1772 | uint16_t spr; |
| 1773 | uint16_t cur; |
| 1774 | uint16_t fbc; |
| 1775 | }; |
| 1776 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1777 | /* used in computing the new watermarks state */ |
| 1778 | struct intel_wm_config { |
| 1779 | unsigned int num_pipes_active; |
| 1780 | bool sprites_enabled; |
| 1781 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1782 | }; |
| 1783 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1784 | /* |
| 1785 | * For both WM_PIPE and WM_LP. |
| 1786 | * mem_value must be in 0.1us units. |
| 1787 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1788 | 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] | 1789 | uint32_t mem_value, |
| 1790 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1791 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1792 | uint32_t method1, method2; |
| 1793 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1794 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1795 | return 0; |
| 1796 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1797 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1798 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1799 | mem_value); |
| 1800 | |
| 1801 | if (!is_lp) |
| 1802 | return method1; |
| 1803 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1804 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1805 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1806 | params->pri.horiz_pixels, |
| 1807 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1808 | mem_value); |
| 1809 | |
| 1810 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1811 | } |
| 1812 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1813 | /* |
| 1814 | * For both WM_PIPE and WM_LP. |
| 1815 | * mem_value must be in 0.1us units. |
| 1816 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1817 | 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] | 1818 | uint32_t mem_value) |
| 1819 | { |
| 1820 | uint32_t method1, method2; |
| 1821 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1822 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1823 | return 0; |
| 1824 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1825 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1826 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1827 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1828 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1829 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1830 | params->spr.horiz_pixels, |
| 1831 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1832 | mem_value); |
| 1833 | return min(method1, method2); |
| 1834 | } |
| 1835 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1836 | /* |
| 1837 | * For both WM_PIPE and WM_LP. |
| 1838 | * mem_value must be in 0.1us units. |
| 1839 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1840 | 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] | 1841 | uint32_t mem_value) |
| 1842 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1843 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1844 | return 0; |
| 1845 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1846 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1847 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1848 | params->cur.horiz_pixels, |
| 1849 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1850 | mem_value); |
| 1851 | } |
| 1852 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1853 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1854 | 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] | 1855 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1856 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1857 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1858 | return 0; |
| 1859 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1860 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1861 | params->pri.horiz_pixels, |
| 1862 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1863 | } |
| 1864 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1865 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1866 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1867 | if (INTEL_INFO(dev)->gen >= 8) |
| 1868 | return 3072; |
| 1869 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1870 | return 768; |
| 1871 | else |
| 1872 | return 512; |
| 1873 | } |
| 1874 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1875 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1876 | int level, bool is_sprite) |
| 1877 | { |
| 1878 | if (INTEL_INFO(dev)->gen >= 8) |
| 1879 | /* BDW primary/sprite plane watermarks */ |
| 1880 | return level == 0 ? 255 : 2047; |
| 1881 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1882 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1883 | return level == 0 ? 127 : 1023; |
| 1884 | else if (!is_sprite) |
| 1885 | /* ILK/SNB primary plane watermarks */ |
| 1886 | return level == 0 ? 127 : 511; |
| 1887 | else |
| 1888 | /* ILK/SNB sprite plane watermarks */ |
| 1889 | return level == 0 ? 63 : 255; |
| 1890 | } |
| 1891 | |
| 1892 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1893 | int level) |
| 1894 | { |
| 1895 | if (INTEL_INFO(dev)->gen >= 7) |
| 1896 | return level == 0 ? 63 : 255; |
| 1897 | else |
| 1898 | return level == 0 ? 31 : 63; |
| 1899 | } |
| 1900 | |
| 1901 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1902 | { |
| 1903 | if (INTEL_INFO(dev)->gen >= 8) |
| 1904 | return 31; |
| 1905 | else |
| 1906 | return 15; |
| 1907 | } |
| 1908 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1909 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1910 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1911 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1912 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1913 | enum intel_ddb_partitioning ddb_partitioning, |
| 1914 | bool is_sprite) |
| 1915 | { |
| 1916 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1917 | |
| 1918 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1919 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1920 | return 0; |
| 1921 | |
| 1922 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1923 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1924 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1925 | |
| 1926 | /* |
| 1927 | * For some reason the non self refresh |
| 1928 | * FIFO size is only half of the self |
| 1929 | * refresh FIFO size on ILK/SNB. |
| 1930 | */ |
| 1931 | if (INTEL_INFO(dev)->gen <= 6) |
| 1932 | fifo_size /= 2; |
| 1933 | } |
| 1934 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1935 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1936 | /* level 0 is always calculated with 1:1 split */ |
| 1937 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1938 | if (is_sprite) |
| 1939 | fifo_size *= 5; |
| 1940 | fifo_size /= 6; |
| 1941 | } else { |
| 1942 | fifo_size /= 2; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1947 | return min(fifo_size, ilk_plane_wm_reg_max(dev, level, is_sprite)); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | /* Calculate the maximum cursor plane watermark */ |
| 1951 | 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] | 1952 | int level, |
| 1953 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1954 | { |
| 1955 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1956 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1957 | return 64; |
| 1958 | |
| 1959 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1960 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1961 | } |
| 1962 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1963 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1964 | int level, |
| 1965 | const struct intel_wm_config *config, |
| 1966 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1967 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1968 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1969 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1970 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1971 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1972 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1973 | } |
| 1974 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1975 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1976 | int level, |
| 1977 | struct ilk_wm_maximums *max) |
| 1978 | { |
| 1979 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1980 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1981 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1982 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1983 | } |
| 1984 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1985 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1986 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1987 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1988 | { |
| 1989 | bool ret; |
| 1990 | |
| 1991 | /* already determined to be invalid? */ |
| 1992 | if (!result->enable) |
| 1993 | return false; |
| 1994 | |
| 1995 | result->enable = result->pri_val <= max->pri && |
| 1996 | result->spr_val <= max->spr && |
| 1997 | result->cur_val <= max->cur; |
| 1998 | |
| 1999 | ret = result->enable; |
| 2000 | |
| 2001 | /* |
| 2002 | * HACK until we can pre-compute everything, |
| 2003 | * and thus fail gracefully if LP0 watermarks |
| 2004 | * are exceeded... |
| 2005 | */ |
| 2006 | if (level == 0 && !result->enable) { |
| 2007 | if (result->pri_val > max->pri) |
| 2008 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2009 | level, result->pri_val, max->pri); |
| 2010 | if (result->spr_val > max->spr) |
| 2011 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2012 | level, result->spr_val, max->spr); |
| 2013 | if (result->cur_val > max->cur) |
| 2014 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2015 | level, result->cur_val, max->cur); |
| 2016 | |
| 2017 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2018 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2019 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2020 | result->enable = true; |
| 2021 | } |
| 2022 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2023 | return ret; |
| 2024 | } |
| 2025 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2026 | static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2027 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2028 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2029 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2030 | { |
| 2031 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2032 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2033 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2034 | |
| 2035 | /* WM1+ latency values stored in 0.5us units */ |
| 2036 | if (level > 0) { |
| 2037 | pri_latency *= 5; |
| 2038 | spr_latency *= 5; |
| 2039 | cur_latency *= 5; |
| 2040 | } |
| 2041 | |
| 2042 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 2043 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 2044 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 2045 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 2046 | result->enable = true; |
| 2047 | } |
| 2048 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2049 | static uint32_t |
| 2050 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2051 | { |
| 2052 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2053 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2054 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2055 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2056 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2057 | if (!intel_crtc_active(crtc)) |
| 2058 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2059 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2060 | /* The WM are computed with base on how long it takes to fill a single |
| 2061 | * row at the given clock rate, multiplied by 8. |
| 2062 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2063 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 2064 | mode->crtc_clock); |
| 2065 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2066 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2067 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2068 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2069 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2070 | } |
| 2071 | |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2072 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2073 | { |
| 2074 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2075 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2076 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2077 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2078 | |
| 2079 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2080 | if (wm[0] == 0) |
| 2081 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2082 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2083 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2084 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2085 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2086 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2087 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2088 | |
| 2089 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2090 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2091 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2092 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2093 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2094 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2095 | |
| 2096 | /* ILK primary LP0 latency is 700 ns */ |
| 2097 | wm[0] = 7; |
| 2098 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2099 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2103 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2104 | { |
| 2105 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2106 | if (INTEL_INFO(dev)->gen == 5) |
| 2107 | wm[0] = 13; |
| 2108 | } |
| 2109 | |
| 2110 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2111 | { |
| 2112 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2113 | if (INTEL_INFO(dev)->gen == 5) |
| 2114 | wm[0] = 13; |
| 2115 | |
| 2116 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2117 | if (IS_IVYBRIDGE(dev)) |
| 2118 | wm[3] *= 2; |
| 2119 | } |
| 2120 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 2121 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2122 | { |
| 2123 | /* how many WM levels are we expecting */ |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2124 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2125 | return 4; |
| 2126 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2127 | return 3; |
| 2128 | else |
| 2129 | return 2; |
| 2130 | } |
| 2131 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2132 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2133 | const char *name, |
| 2134 | const uint16_t wm[5]) |
| 2135 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2136 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2137 | |
| 2138 | for (level = 0; level <= max_level; level++) { |
| 2139 | unsigned int latency = wm[level]; |
| 2140 | |
| 2141 | if (latency == 0) { |
| 2142 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2143 | name, level); |
| 2144 | continue; |
| 2145 | } |
| 2146 | |
| 2147 | /* WM1+ latency values in 0.5us units */ |
| 2148 | if (level > 0) |
| 2149 | latency *= 5; |
| 2150 | |
| 2151 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2152 | name, level, wm[level], |
| 2153 | latency / 10, latency % 10); |
| 2154 | } |
| 2155 | } |
| 2156 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2157 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2158 | uint16_t wm[5], uint16_t min) |
| 2159 | { |
| 2160 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 2161 | |
| 2162 | if (wm[0] >= min) |
| 2163 | return false; |
| 2164 | |
| 2165 | wm[0] = max(wm[0], min); |
| 2166 | for (level = 1; level <= max_level; level++) |
| 2167 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2168 | |
| 2169 | return true; |
| 2170 | } |
| 2171 | |
| 2172 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2173 | { |
| 2174 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2175 | bool changed; |
| 2176 | |
| 2177 | /* |
| 2178 | * The BIOS provided WM memory latency values are often |
| 2179 | * inadequate for high resolution displays. Adjust them. |
| 2180 | */ |
| 2181 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2182 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2183 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2184 | |
| 2185 | if (!changed) |
| 2186 | return; |
| 2187 | |
| 2188 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2189 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2190 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2191 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2192 | } |
| 2193 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2194 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2195 | { |
| 2196 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2197 | |
| 2198 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2199 | |
| 2200 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2201 | sizeof(dev_priv->wm.pri_latency)); |
| 2202 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2203 | sizeof(dev_priv->wm.pri_latency)); |
| 2204 | |
| 2205 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2206 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2207 | |
| 2208 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2209 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2210 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2211 | |
| 2212 | if (IS_GEN6(dev)) |
| 2213 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2214 | } |
| 2215 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2216 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2217 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2218 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2219 | struct drm_device *dev = crtc->dev; |
| 2220 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2221 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2222 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2223 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2224 | if (!intel_crtc_active(crtc)) |
| 2225 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2226 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2227 | p->active = true; |
| 2228 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 2229 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 2230 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 2231 | p->cur.bytes_per_pixel = 4; |
| 2232 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
| 2233 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 2234 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2235 | p->pri.enabled = true; |
| 2236 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2237 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2238 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2239 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2240 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2241 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2242 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2243 | break; |
| 2244 | } |
| 2245 | } |
| 2246 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2247 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2248 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2249 | struct intel_wm_config *config) |
| 2250 | { |
| 2251 | struct intel_crtc *intel_crtc; |
| 2252 | |
| 2253 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2254 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2255 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2256 | |
| 2257 | if (!wm->pipe_enabled) |
| 2258 | continue; |
| 2259 | |
| 2260 | config->sprites_enabled |= wm->sprites_enabled; |
| 2261 | config->sprites_scaled |= wm->sprites_scaled; |
| 2262 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2263 | } |
| 2264 | } |
| 2265 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2266 | /* Compute new watermarks for the pipe */ |
| 2267 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2268 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2269 | struct intel_pipe_wm *pipe_wm) |
| 2270 | { |
| 2271 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2272 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2273 | int level, max_level = ilk_wm_max_level(dev); |
| 2274 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2275 | struct intel_wm_config config = { |
| 2276 | .num_pipes_active = 1, |
| 2277 | .sprites_enabled = params->spr.enabled, |
| 2278 | .sprites_scaled = params->spr.scaled, |
| 2279 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2280 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2281 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2282 | pipe_wm->pipe_enabled = params->active; |
| 2283 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2284 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2285 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2286 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2287 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2288 | max_level = 1; |
| 2289 | |
| 2290 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2291 | if (params->spr.scaled) |
| 2292 | max_level = 0; |
| 2293 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2294 | ilk_compute_wm_level(dev_priv, 0, params, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2295 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2296 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2297 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2298 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2299 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2300 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2301 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2302 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2303 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2304 | return false; |
| 2305 | |
| 2306 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2307 | |
| 2308 | for (level = 1; level <= max_level; level++) { |
| 2309 | struct intel_wm_level wm = {}; |
| 2310 | |
| 2311 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2312 | |
| 2313 | /* |
| 2314 | * Disable any watermark level that exceeds the |
| 2315 | * register maximums since such watermarks are |
| 2316 | * always invalid. |
| 2317 | */ |
| 2318 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2319 | break; |
| 2320 | |
| 2321 | pipe_wm->wm[level] = wm; |
| 2322 | } |
| 2323 | |
| 2324 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | /* |
| 2328 | * Merge the watermarks from all active pipes for a specific level. |
| 2329 | */ |
| 2330 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2331 | int level, |
| 2332 | struct intel_wm_level *ret_wm) |
| 2333 | { |
| 2334 | const struct intel_crtc *intel_crtc; |
| 2335 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2336 | ret_wm->enable = true; |
| 2337 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2338 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2339 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2340 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2341 | |
| 2342 | if (!active->pipe_enabled) |
| 2343 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2344 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2345 | /* |
| 2346 | * The watermark values may have been used in the past, |
| 2347 | * so we must maintain them in the registers for some |
| 2348 | * time even if the level is now disabled. |
| 2349 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2350 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2351 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2352 | |
| 2353 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2354 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2355 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2356 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2357 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | /* |
| 2361 | * Merge all low power watermarks for all active pipes. |
| 2362 | */ |
| 2363 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2364 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2365 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2366 | struct intel_pipe_wm *merged) |
| 2367 | { |
| 2368 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2369 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2370 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2371 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2372 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2373 | config->num_pipes_active > 1) |
| 2374 | return; |
| 2375 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2376 | /* ILK: FBC WM must be disabled always */ |
| 2377 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2378 | |
| 2379 | /* merge each WM1+ level */ |
| 2380 | for (level = 1; level <= max_level; level++) { |
| 2381 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2382 | |
| 2383 | ilk_merge_wm_level(dev, level, wm); |
| 2384 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2385 | if (level > last_enabled_level) |
| 2386 | wm->enable = false; |
| 2387 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2388 | /* make sure all following levels get disabled */ |
| 2389 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2390 | |
| 2391 | /* |
| 2392 | * The spec says it is preferred to disable |
| 2393 | * FBC WMs instead of disabling a WM level. |
| 2394 | */ |
| 2395 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2396 | if (wm->enable) |
| 2397 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2398 | wm->fbc_val = 0; |
| 2399 | } |
| 2400 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2401 | |
| 2402 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2403 | /* |
| 2404 | * FIXME this is racy. FBC might get enabled later. |
| 2405 | * What we should check here is whether FBC can be |
| 2406 | * enabled sometime later. |
| 2407 | */ |
| 2408 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2409 | for (level = 2; level <= max_level; level++) { |
| 2410 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2411 | |
| 2412 | wm->enable = false; |
| 2413 | } |
| 2414 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2415 | } |
| 2416 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2417 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2418 | { |
| 2419 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2420 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2421 | } |
| 2422 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2423 | /* The value we need to program into the WM_LPx latency field */ |
| 2424 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2425 | { |
| 2426 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2427 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2428 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2429 | return 2 * level; |
| 2430 | else |
| 2431 | return dev_priv->wm.pri_latency[level]; |
| 2432 | } |
| 2433 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2434 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2435 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2436 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2437 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2438 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2439 | struct intel_crtc *intel_crtc; |
| 2440 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2441 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2442 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2443 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2444 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2445 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2446 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2447 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2448 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2449 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2450 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2451 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2452 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2453 | /* |
| 2454 | * Maintain the watermark values even if the level is |
| 2455 | * disabled. Doing otherwise could cause underruns. |
| 2456 | */ |
| 2457 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2458 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2459 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2460 | r->cur_val; |
| 2461 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2462 | if (r->enable) |
| 2463 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2464 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2465 | if (INTEL_INFO(dev)->gen >= 8) |
| 2466 | results->wm_lp[wm_lp - 1] |= |
| 2467 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2468 | else |
| 2469 | results->wm_lp[wm_lp - 1] |= |
| 2470 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2471 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2472 | /* |
| 2473 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2474 | * level is disabled. Doing otherwise could cause underruns. |
| 2475 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2476 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2477 | WARN_ON(wm_lp != 1); |
| 2478 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2479 | } else |
| 2480 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2481 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2482 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2483 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2484 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2485 | enum pipe pipe = intel_crtc->pipe; |
| 2486 | const struct intel_wm_level *r = |
| 2487 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2488 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2489 | if (WARN_ON(!r->enable)) |
| 2490 | continue; |
| 2491 | |
| 2492 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2493 | |
| 2494 | results->wm_pipe[pipe] = |
| 2495 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2496 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2497 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2498 | } |
| 2499 | } |
| 2500 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2501 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2502 | * 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] | 2503 | 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] | 2504 | struct intel_pipe_wm *r1, |
| 2505 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2506 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2507 | int level, max_level = ilk_wm_max_level(dev); |
| 2508 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2509 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2510 | for (level = 1; level <= max_level; level++) { |
| 2511 | if (r1->wm[level].enable) |
| 2512 | level1 = level; |
| 2513 | if (r2->wm[level].enable) |
| 2514 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2515 | } |
| 2516 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2517 | if (level1 == level2) { |
| 2518 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2519 | return r2; |
| 2520 | else |
| 2521 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2522 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2523 | return r1; |
| 2524 | } else { |
| 2525 | return r2; |
| 2526 | } |
| 2527 | } |
| 2528 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2529 | /* dirty bits used to track which watermarks need changes */ |
| 2530 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2531 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2532 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2533 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2534 | #define WM_DIRTY_FBC (1 << 24) |
| 2535 | #define WM_DIRTY_DDB (1 << 25) |
| 2536 | |
| 2537 | static unsigned int ilk_compute_wm_dirty(struct drm_device *dev, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2538 | const struct ilk_wm_values *old, |
| 2539 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2540 | { |
| 2541 | unsigned int dirty = 0; |
| 2542 | enum pipe pipe; |
| 2543 | int wm_lp; |
| 2544 | |
| 2545 | for_each_pipe(pipe) { |
| 2546 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2547 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2548 | /* Must disable LP1+ watermarks too */ |
| 2549 | dirty |= WM_DIRTY_LP_ALL; |
| 2550 | } |
| 2551 | |
| 2552 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2553 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2554 | /* Must disable LP1+ watermarks too */ |
| 2555 | dirty |= WM_DIRTY_LP_ALL; |
| 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2560 | dirty |= WM_DIRTY_FBC; |
| 2561 | /* Must disable LP1+ watermarks too */ |
| 2562 | dirty |= WM_DIRTY_LP_ALL; |
| 2563 | } |
| 2564 | |
| 2565 | if (old->partitioning != new->partitioning) { |
| 2566 | dirty |= WM_DIRTY_DDB; |
| 2567 | /* Must disable LP1+ watermarks too */ |
| 2568 | dirty |= WM_DIRTY_LP_ALL; |
| 2569 | } |
| 2570 | |
| 2571 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2572 | if (dirty & WM_DIRTY_LP_ALL) |
| 2573 | return dirty; |
| 2574 | |
| 2575 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2576 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2577 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2578 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2579 | break; |
| 2580 | } |
| 2581 | |
| 2582 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2583 | for (; wm_lp <= 3; wm_lp++) |
| 2584 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2585 | |
| 2586 | return dirty; |
| 2587 | } |
| 2588 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2589 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2590 | unsigned int dirty) |
| 2591 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2592 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2593 | bool changed = false; |
| 2594 | |
| 2595 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2596 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2597 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2598 | changed = true; |
| 2599 | } |
| 2600 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2601 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2602 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2603 | changed = true; |
| 2604 | } |
| 2605 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2606 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2607 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2608 | changed = true; |
| 2609 | } |
| 2610 | |
| 2611 | /* |
| 2612 | * Don't touch WM1S_LP_EN here. |
| 2613 | * Doing so could cause underruns. |
| 2614 | */ |
| 2615 | |
| 2616 | return changed; |
| 2617 | } |
| 2618 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2619 | /* |
| 2620 | * The spec says we shouldn't write when we don't need, because every write |
| 2621 | * causes WMs to be re-evaluated, expending some power. |
| 2622 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2623 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2624 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2625 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2626 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2627 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2628 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2629 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2630 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2631 | dirty = ilk_compute_wm_dirty(dev, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2632 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2633 | return; |
| 2634 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2635 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2636 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2637 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2638 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2639 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2640 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2641 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2642 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2643 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2644 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2645 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2646 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2647 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2648 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2649 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2650 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2651 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2652 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2653 | val = I915_READ(WM_MISC); |
| 2654 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2655 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2656 | else |
| 2657 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2658 | I915_WRITE(WM_MISC, val); |
| 2659 | } else { |
| 2660 | val = I915_READ(DISP_ARB_CTL2); |
| 2661 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2662 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2663 | else |
| 2664 | val |= DISP_DATA_PARTITION_5_6; |
| 2665 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2666 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2667 | } |
| 2668 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2669 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2670 | val = I915_READ(DISP_ARB_CTL); |
| 2671 | if (results->enable_fbc_wm) |
| 2672 | val &= ~DISP_FBC_WM_DIS; |
| 2673 | else |
| 2674 | val |= DISP_FBC_WM_DIS; |
| 2675 | I915_WRITE(DISP_ARB_CTL, val); |
| 2676 | } |
| 2677 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2678 | if (dirty & WM_DIRTY_LP(1) && |
| 2679 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2680 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2681 | |
| 2682 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2683 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2684 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2685 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2686 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2687 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2688 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2689 | 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] | 2690 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2691 | 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] | 2692 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2693 | 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] | 2694 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2695 | |
| 2696 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2697 | } |
| 2698 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2699 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2700 | { |
| 2701 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2702 | |
| 2703 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2704 | } |
| 2705 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2706 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2707 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2708 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2709 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2710 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2711 | struct ilk_wm_maximums max; |
| 2712 | struct ilk_pipe_wm_parameters params = {}; |
| 2713 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2714 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2715 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2716 | 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] | 2717 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2718 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2719 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2720 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2721 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 2722 | |
| 2723 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 2724 | return; |
| 2725 | |
| 2726 | intel_crtc->wm.active = pipe_wm; |
| 2727 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2728 | ilk_compute_wm_config(dev, &config); |
| 2729 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2730 | 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] | 2731 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2732 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2733 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 2734 | if (INTEL_INFO(dev)->gen >= 7 && |
| 2735 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2736 | 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] | 2737 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2738 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2739 | 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] | 2740 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2741 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2742 | } |
| 2743 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2744 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2745 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2746 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2747 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2748 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2749 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2750 | } |
| 2751 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2752 | static void ilk_update_sprite_wm(struct drm_plane *plane, |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2753 | struct drm_crtc *crtc, |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2754 | uint32_t sprite_width, int pixel_size, |
Ville Syrjälä | bdd57d0 | 2013-07-05 11:57:13 +0300 | [diff] [blame] | 2755 | bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2756 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2757 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2758 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2759 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2760 | intel_plane->wm.enabled = enabled; |
| 2761 | intel_plane->wm.scaled = scaled; |
| 2762 | intel_plane->wm.horiz_pixels = sprite_width; |
| 2763 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2764 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2765 | /* |
| 2766 | * IVB workaround: must disable low power watermarks for at least |
| 2767 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 2768 | * when scaling is disabled. |
| 2769 | * |
| 2770 | * WaCxSRDisabledForSpriteScaling:ivb |
| 2771 | */ |
| 2772 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 2773 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 2774 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2775 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2776 | } |
| 2777 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2778 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 2779 | { |
| 2780 | struct drm_device *dev = crtc->dev; |
| 2781 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2782 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2783 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2784 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2785 | enum pipe pipe = intel_crtc->pipe; |
| 2786 | static const unsigned int wm0_pipe_reg[] = { |
| 2787 | [PIPE_A] = WM0_PIPEA_ILK, |
| 2788 | [PIPE_B] = WM0_PIPEB_ILK, |
| 2789 | [PIPE_C] = WM0_PIPEC_IVB, |
| 2790 | }; |
| 2791 | |
| 2792 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2793 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2794 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2795 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2796 | active->pipe_enabled = intel_crtc_active(crtc); |
| 2797 | |
| 2798 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2799 | u32 tmp = hw->wm_pipe[pipe]; |
| 2800 | |
| 2801 | /* |
| 2802 | * For active pipes LP0 watermark is marked as |
| 2803 | * enabled, and LP1+ watermaks as disabled since |
| 2804 | * we can't really reverse compute them in case |
| 2805 | * multiple pipes are active. |
| 2806 | */ |
| 2807 | active->wm[0].enable = true; |
| 2808 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 2809 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 2810 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 2811 | active->linetime = hw->wm_linetime[pipe]; |
| 2812 | } else { |
| 2813 | int level, max_level = ilk_wm_max_level(dev); |
| 2814 | |
| 2815 | /* |
| 2816 | * For inactive pipes, all watermark levels |
| 2817 | * should be marked as enabled but zeroed, |
| 2818 | * which is what we'd compute them to. |
| 2819 | */ |
| 2820 | for (level = 0; level <= max_level; level++) |
| 2821 | active->wm[level].enable = true; |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 2826 | { |
| 2827 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2828 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2829 | struct drm_crtc *crtc; |
| 2830 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2831 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2832 | ilk_pipe_wm_get_hw_state(crtc); |
| 2833 | |
| 2834 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 2835 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 2836 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 2837 | |
| 2838 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 2839 | if (INTEL_INFO(dev)->gen >= 7) { |
| 2840 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 2841 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 2842 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2843 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2844 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2845 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 2846 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 2847 | else if (IS_IVYBRIDGE(dev)) |
| 2848 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 2849 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2850 | |
| 2851 | hw->enable_fbc_wm = |
| 2852 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 2853 | } |
| 2854 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2855 | /** |
| 2856 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 2857 | * |
| 2858 | * Calculate watermark values for the various WM regs based on current mode |
| 2859 | * and plane configuration. |
| 2860 | * |
| 2861 | * There are several cases to deal with here: |
| 2862 | * - normal (i.e. non-self-refresh) |
| 2863 | * - self-refresh (SR) mode |
| 2864 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 2865 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 2866 | * lines), so need to account for TLB latency |
| 2867 | * |
| 2868 | * The normal calculation is: |
| 2869 | * watermark = dotclock * bytes per pixel * latency |
| 2870 | * where latency is platform & configuration dependent (we assume pessimal |
| 2871 | * values here). |
| 2872 | * |
| 2873 | * The SR calculation is: |
| 2874 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 2875 | * bytes per pixel |
| 2876 | * where |
| 2877 | * line time = htotal / dotclock |
| 2878 | * surface width = hdisplay for normal plane and 64 for cursor |
| 2879 | * and latency is assumed to be high, as above. |
| 2880 | * |
| 2881 | * The final value programmed to the register should always be rounded up, |
| 2882 | * and include an extra 2 entries to account for clock crossings. |
| 2883 | * |
| 2884 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 2885 | * to set the non-SR watermarks to 8. |
| 2886 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2887 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2888 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2889 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2890 | |
| 2891 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2892 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2893 | } |
| 2894 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2895 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 2896 | struct drm_crtc *crtc, |
Paulo Zanoni | 4c4ff43 | 2013-05-24 11:59:17 -0300 | [diff] [blame] | 2897 | uint32_t sprite_width, int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2898 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2899 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2900 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2901 | |
| 2902 | if (dev_priv->display.update_sprite_wm) |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2903 | dev_priv->display.update_sprite_wm(plane, crtc, sprite_width, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2904 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2905 | } |
| 2906 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2907 | static struct drm_i915_gem_object * |
| 2908 | intel_alloc_context_page(struct drm_device *dev) |
| 2909 | { |
| 2910 | struct drm_i915_gem_object *ctx; |
| 2911 | int ret; |
| 2912 | |
| 2913 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2914 | |
| 2915 | ctx = i915_gem_alloc_object(dev, 4096); |
| 2916 | if (!ctx) { |
| 2917 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 2918 | return NULL; |
| 2919 | } |
| 2920 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 2921 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2922 | if (ret) { |
| 2923 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 2924 | goto err_unref; |
| 2925 | } |
| 2926 | |
| 2927 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 2928 | if (ret) { |
| 2929 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 2930 | goto err_unpin; |
| 2931 | } |
| 2932 | |
| 2933 | return ctx; |
| 2934 | |
| 2935 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 2936 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2937 | err_unref: |
| 2938 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2939 | return NULL; |
| 2940 | } |
| 2941 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2942 | /** |
| 2943 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2944 | */ |
| 2945 | DEFINE_SPINLOCK(mchdev_lock); |
| 2946 | |
| 2947 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 2948 | * mchdev_lock. */ |
| 2949 | static struct drm_i915_private *i915_mch_dev; |
| 2950 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2951 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 2952 | { |
| 2953 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2954 | u16 rgvswctl; |
| 2955 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2956 | assert_spin_locked(&mchdev_lock); |
| 2957 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2958 | rgvswctl = I915_READ16(MEMSWCTL); |
| 2959 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 2960 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 2961 | return false; /* still busy with another command */ |
| 2962 | } |
| 2963 | |
| 2964 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 2965 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 2966 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2967 | POSTING_READ16(MEMSWCTL); |
| 2968 | |
| 2969 | rgvswctl |= MEMCTL_CMD_STS; |
| 2970 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2971 | |
| 2972 | return true; |
| 2973 | } |
| 2974 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 2975 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2976 | { |
| 2977 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2978 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 2979 | u8 fmax, fmin, fstart, vstart; |
| 2980 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2981 | spin_lock_irq(&mchdev_lock); |
| 2982 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2983 | /* Enable temp reporting */ |
| 2984 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 2985 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 2986 | |
| 2987 | /* 100ms RC evaluation intervals */ |
| 2988 | I915_WRITE(RCUPEI, 100000); |
| 2989 | I915_WRITE(RCDNEI, 100000); |
| 2990 | |
| 2991 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 2992 | I915_WRITE(RCBMAXAVG, 90000); |
| 2993 | I915_WRITE(RCBMINAVG, 80000); |
| 2994 | |
| 2995 | I915_WRITE(MEMIHYST, 1); |
| 2996 | |
| 2997 | /* Set up min, max, and cur for interrupt handling */ |
| 2998 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 2999 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3000 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3001 | MEMMODE_FSTART_SHIFT; |
| 3002 | |
| 3003 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3004 | PXVFREQ_PX_SHIFT; |
| 3005 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3006 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3007 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3008 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3009 | dev_priv->ips.max_delay = fstart; |
| 3010 | dev_priv->ips.min_delay = fmin; |
| 3011 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3012 | |
| 3013 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3014 | fmax, fmin, fstart); |
| 3015 | |
| 3016 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3017 | |
| 3018 | /* |
| 3019 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3020 | */ |
| 3021 | |
| 3022 | I915_WRITE(VIDSTART, vstart); |
| 3023 | POSTING_READ(VIDSTART); |
| 3024 | |
| 3025 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3026 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3027 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3028 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3029 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3030 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3031 | |
| 3032 | ironlake_set_drps(dev, fstart); |
| 3033 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3034 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3035 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3036 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3037 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
| 3038 | getrawmonotonic(&dev_priv->ips.last_time2); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3039 | |
| 3040 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3041 | } |
| 3042 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3043 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3044 | { |
| 3045 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3046 | u16 rgvswctl; |
| 3047 | |
| 3048 | spin_lock_irq(&mchdev_lock); |
| 3049 | |
| 3050 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3051 | |
| 3052 | /* Ack interrupts, disable EFC interrupt */ |
| 3053 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3054 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3055 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3056 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3057 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3058 | |
| 3059 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3060 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3061 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3062 | rgvswctl |= MEMCTL_CMD_STS; |
| 3063 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3064 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3065 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3066 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3067 | } |
| 3068 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3069 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3070 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3071 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3072 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3073 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3074 | 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] | 3075 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3076 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3077 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3078 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3079 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3080 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3081 | * the hw runs at the minimal clock before selecting the desired |
| 3082 | * frequency, if the down threshold expires in that window we will not |
| 3083 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3084 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3085 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3086 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3087 | |
| 3088 | return limits; |
| 3089 | } |
| 3090 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3091 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3092 | { |
| 3093 | int new_power; |
| 3094 | |
| 3095 | new_power = dev_priv->rps.power; |
| 3096 | switch (dev_priv->rps.power) { |
| 3097 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3098 | if (val > dev_priv->rps.efficient_freq + 1 && val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3099 | new_power = BETWEEN; |
| 3100 | break; |
| 3101 | |
| 3102 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3103 | if (val <= dev_priv->rps.efficient_freq && val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3104 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3105 | else if (val >= dev_priv->rps.rp0_freq && val > dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3106 | new_power = HIGH_POWER; |
| 3107 | break; |
| 3108 | |
| 3109 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3110 | if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 && val < dev_priv->rps.cur_freq) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3111 | new_power = BETWEEN; |
| 3112 | break; |
| 3113 | } |
| 3114 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3115 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3116 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3117 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3118 | new_power = HIGH_POWER; |
| 3119 | if (new_power == dev_priv->rps.power) |
| 3120 | return; |
| 3121 | |
| 3122 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3123 | switch (new_power) { |
| 3124 | case LOW_POWER: |
| 3125 | /* Upclock if more than 95% busy over 16ms */ |
| 3126 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 3127 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 3128 | |
| 3129 | /* Downclock if less than 85% busy over 32ms */ |
| 3130 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3131 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3132 | |
| 3133 | I915_WRITE(GEN6_RP_CONTROL, |
| 3134 | GEN6_RP_MEDIA_TURBO | |
| 3135 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3136 | GEN6_RP_MEDIA_IS_GFX | |
| 3137 | GEN6_RP_ENABLE | |
| 3138 | GEN6_RP_UP_BUSY_AVG | |
| 3139 | GEN6_RP_DOWN_IDLE_AVG); |
| 3140 | break; |
| 3141 | |
| 3142 | case BETWEEN: |
| 3143 | /* Upclock if more than 90% busy over 13ms */ |
| 3144 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3145 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3146 | |
| 3147 | /* Downclock if less than 75% busy over 32ms */ |
| 3148 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3149 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3150 | |
| 3151 | I915_WRITE(GEN6_RP_CONTROL, |
| 3152 | GEN6_RP_MEDIA_TURBO | |
| 3153 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3154 | GEN6_RP_MEDIA_IS_GFX | |
| 3155 | GEN6_RP_ENABLE | |
| 3156 | GEN6_RP_UP_BUSY_AVG | |
| 3157 | GEN6_RP_DOWN_IDLE_AVG); |
| 3158 | break; |
| 3159 | |
| 3160 | case HIGH_POWER: |
| 3161 | /* Upclock if more than 85% busy over 10ms */ |
| 3162 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3163 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3164 | |
| 3165 | /* Downclock if less than 60% busy over 32ms */ |
| 3166 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3167 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3168 | |
| 3169 | I915_WRITE(GEN6_RP_CONTROL, |
| 3170 | GEN6_RP_MEDIA_TURBO | |
| 3171 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3172 | GEN6_RP_MEDIA_IS_GFX | |
| 3173 | GEN6_RP_ENABLE | |
| 3174 | GEN6_RP_UP_BUSY_AVG | |
| 3175 | GEN6_RP_DOWN_IDLE_AVG); |
| 3176 | break; |
| 3177 | } |
| 3178 | |
| 3179 | dev_priv->rps.power = new_power; |
| 3180 | dev_priv->rps.last_adj = 0; |
| 3181 | } |
| 3182 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3183 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3184 | { |
| 3185 | u32 mask = 0; |
| 3186 | |
| 3187 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3188 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3189 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3190 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3191 | |
| 3192 | /* IVB and SNB hard hangs on looping batchbuffer |
| 3193 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 3194 | */ |
| 3195 | if (INTEL_INFO(dev_priv->dev)->gen <= 7 && !IS_HASWELL(dev_priv->dev)) |
| 3196 | mask |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 3197 | |
Deepak S | baccd45 | 2014-05-15 20:58:09 +0300 | [diff] [blame] | 3198 | if (IS_GEN8(dev_priv->dev)) |
| 3199 | mask |= GEN8_PMINTR_REDIRECT_TO_NON_DISP; |
| 3200 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3201 | return ~mask; |
| 3202 | } |
| 3203 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3204 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3205 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3206 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3207 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 3208 | { |
| 3209 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3210 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3211 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3212 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3213 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3214 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3215 | /* min/max delay may still have been modified so be sure to |
| 3216 | * write the limits value. |
| 3217 | */ |
| 3218 | if (val != dev_priv->rps.cur_freq) { |
| 3219 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3220 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3221 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3222 | I915_WRITE(GEN6_RPNSWREQ, |
| 3223 | HSW_FREQUENCY(val)); |
| 3224 | else |
| 3225 | I915_WRITE(GEN6_RPNSWREQ, |
| 3226 | GEN6_FREQUENCY(val) | |
| 3227 | GEN6_OFFSET(0) | |
| 3228 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3229 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3230 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3231 | /* Make sure we continue to get interrupts |
| 3232 | * until we hit the minimum or maximum frequencies. |
| 3233 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3234 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3235 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3236 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3237 | POSTING_READ(GEN6_RPNSWREQ); |
| 3238 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3239 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3240 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3241 | } |
| 3242 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3243 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3244 | * |
| 3245 | * * If Gfx is Idle, then |
| 3246 | * 1. Mask Turbo interrupts |
| 3247 | * 2. Bring up Gfx clock |
| 3248 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3249 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3250 | * 5. Unmask Turbo interrupts |
| 3251 | */ |
| 3252 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3253 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3254 | struct drm_device *dev = dev_priv->dev; |
| 3255 | |
| 3256 | /* Latest VLV doesn't need to force the gfx clock */ |
| 3257 | if (dev->pdev->revision >= 0xd) { |
| 3258 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3259 | return; |
| 3260 | } |
| 3261 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3262 | /* |
| 3263 | * When we are idle. Drop to min voltage state. |
| 3264 | */ |
| 3265 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3266 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3267 | return; |
| 3268 | |
| 3269 | /* Mask turbo interrupt so that they will not come in between */ |
| 3270 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 3271 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3272 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3273 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3274 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3275 | |
| 3276 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3277 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3278 | |
| 3279 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
| 3280 | & GENFREQSTATUS) == 0, 5)) |
| 3281 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3282 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3283 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3284 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3285 | I915_WRITE(GEN6_PMINTRMSK, |
| 3286 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3287 | } |
| 3288 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3289 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3290 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3291 | struct drm_device *dev = dev_priv->dev; |
| 3292 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3293 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3294 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3295 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3296 | vlv_set_rps_idle(dev_priv); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3297 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3298 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3299 | dev_priv->rps.last_adj = 0; |
| 3300 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3301 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3302 | } |
| 3303 | |
| 3304 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3305 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3306 | struct drm_device *dev = dev_priv->dev; |
| 3307 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3308 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3309 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3310 | if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3311 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3312 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3313 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3314 | dev_priv->rps.last_adj = 0; |
| 3315 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3316 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3317 | } |
| 3318 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3319 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3320 | { |
| 3321 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 3322 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3323 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3324 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3325 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3326 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3327 | DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3328 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 3329 | dev_priv->rps.cur_freq, |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3330 | vlv_gpu_freq(dev_priv, val), val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3331 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3332 | if (val != dev_priv->rps.cur_freq) |
| 3333 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3334 | |
Imre Deak | 09c87db | 2014-04-03 20:02:42 +0300 | [diff] [blame] | 3335 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3336 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3337 | dev_priv->rps.cur_freq = val; |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3338 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3341 | static void gen8_disable_rps_interrupts(struct drm_device *dev) |
| 3342 | { |
| 3343 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3344 | |
Mika Kuoppala | 992f191 | 2014-05-16 13:44:12 +0300 | [diff] [blame] | 3345 | I915_WRITE(GEN6_PMINTRMSK, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3346 | I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) & |
| 3347 | ~dev_priv->pm_rps_events); |
| 3348 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3349 | * item again unmasking PM interrupts because that is using a different |
| 3350 | * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in |
| 3351 | * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which |
| 3352 | * gen8_enable_rps will clean up. */ |
| 3353 | |
| 3354 | spin_lock_irq(&dev_priv->irq_lock); |
| 3355 | dev_priv->rps.pm_iir = 0; |
| 3356 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3357 | |
| 3358 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3359 | } |
| 3360 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3361 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3362 | { |
| 3363 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3364 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3365 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3366 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & |
| 3367 | ~dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3368 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3369 | * item again unmasking PM interrupts because that is using a different |
| 3370 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 3371 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 3372 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3373 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3374 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3375 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3376 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3377 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3378 | } |
| 3379 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3380 | static void gen6_disable_rps(struct drm_device *dev) |
| 3381 | { |
| 3382 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3383 | |
| 3384 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3385 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 3386 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3387 | if (IS_BROADWELL(dev)) |
| 3388 | gen8_disable_rps_interrupts(dev); |
| 3389 | else |
| 3390 | gen6_disable_rps_interrupts(dev); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3391 | } |
| 3392 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3393 | static void cherryview_disable_rps(struct drm_device *dev) |
| 3394 | { |
| 3395 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3396 | |
| 3397 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3398 | } |
| 3399 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3400 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3401 | { |
| 3402 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3403 | |
| 3404 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3405 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3406 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3409 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3410 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3411 | if (IS_VALLEYVIEW(dev)) { |
| 3412 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3413 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3414 | else |
| 3415 | mode = 0; |
| 3416 | } |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3417 | DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n", |
Ben Widawsky | 1c79b42 | 2014-01-28 20:25:40 -0800 | [diff] [blame] | 3418 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3419 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3420 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3423 | static int sanitize_rc6_option(const struct drm_device *dev, int enable_rc6) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3424 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3425 | /* No RC6 before Ironlake */ |
| 3426 | if (INTEL_INFO(dev)->gen < 5) |
| 3427 | return 0; |
| 3428 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3429 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3430 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3431 | return 0; |
| 3432 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3433 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3434 | if (enable_rc6 >= 0) { |
| 3435 | int mask; |
| 3436 | |
| 3437 | if (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev)) |
| 3438 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3439 | INTEL_RC6pp_ENABLE; |
| 3440 | else |
| 3441 | mask = INTEL_RC6_ENABLE; |
| 3442 | |
| 3443 | if ((enable_rc6 & mask) != enable_rc6) |
| 3444 | DRM_INFO("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
Mika Kuoppala | 8fd9c1a9 | 2014-05-15 20:58:10 +0300 | [diff] [blame] | 3445 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3446 | |
| 3447 | return enable_rc6 & mask; |
| 3448 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3449 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3450 | /* Disable RC6 on Ironlake */ |
| 3451 | if (INTEL_INFO(dev)->gen == 5) |
| 3452 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3453 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3454 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 3455 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3456 | |
| 3457 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3458 | } |
| 3459 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3460 | int intel_enable_rc6(const struct drm_device *dev) |
| 3461 | { |
| 3462 | return i915.enable_rc6; |
| 3463 | } |
| 3464 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3465 | static void gen8_enable_rps_interrupts(struct drm_device *dev) |
| 3466 | { |
| 3467 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3468 | |
| 3469 | spin_lock_irq(&dev_priv->irq_lock); |
| 3470 | WARN_ON(dev_priv->rps.pm_iir); |
| 3471 | bdw_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
| 3472 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3473 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3474 | } |
| 3475 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3476 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 3477 | { |
| 3478 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3479 | |
| 3480 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 3481 | WARN_ON(dev_priv->rps.pm_iir); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3482 | snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
| 3483 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3484 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3485 | } |
| 3486 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3487 | static void parse_rp_state_cap(struct drm_i915_private *dev_priv, u32 rp_state_cap) |
| 3488 | { |
| 3489 | /* All of these values are in units of 50MHz */ |
| 3490 | dev_priv->rps.cur_freq = 0; |
| 3491 | /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */ |
| 3492 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 3493 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 3494 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 3495 | /* XXX: only BYT has a special efficient freq */ |
| 3496 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 3497 | /* hw_max = RP0 until we check for overclocking */ |
| 3498 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 3499 | |
| 3500 | /* Preserve min/max settings in case of re-init */ |
| 3501 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3502 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3503 | |
| 3504 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 3505 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 3506 | } |
| 3507 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3508 | static void gen8_enable_rps(struct drm_device *dev) |
| 3509 | { |
| 3510 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3511 | struct intel_engine_cs *ring; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3512 | uint32_t rc6_mask = 0, rp_state_cap; |
| 3513 | int unused; |
| 3514 | |
| 3515 | /* 1a: Software RC state - RC0 */ |
| 3516 | I915_WRITE(GEN6_RC_STATE, 0); |
| 3517 | |
| 3518 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 3519 | * 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] | 3520 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3521 | |
| 3522 | /* 2a: Disable RC states. */ |
| 3523 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3524 | |
| 3525 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3526 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3527 | |
| 3528 | /* 2b: Program RC6 thresholds.*/ |
| 3529 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 3530 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 3531 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 3532 | for_each_ring(ring, dev_priv, unused) |
| 3533 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3534 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3535 | if (IS_BROADWELL(dev)) |
| 3536 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 3537 | else |
| 3538 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3539 | |
| 3540 | /* 3: Enable RC6 */ |
| 3541 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 3542 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 3543 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3544 | if (IS_BROADWELL(dev)) |
| 3545 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3546 | GEN7_RC_CTL_TO_MODE | |
| 3547 | rc6_mask); |
| 3548 | else |
| 3549 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3550 | GEN6_RC_CTL_EI_MODE(1) | |
| 3551 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3552 | |
| 3553 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 3554 | I915_WRITE(GEN6_RPNSWREQ, |
| 3555 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 3556 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 3557 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3558 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 3559 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
| 3560 | |
| 3561 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 3562 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3563 | dev_priv->rps.max_freq_softlimit << 24 | |
| 3564 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3565 | |
| 3566 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 3567 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 3568 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 3569 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
| 3570 | |
| 3571 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3572 | |
| 3573 | /* 5: Enable RPS */ |
| 3574 | I915_WRITE(GEN6_RP_CONTROL, |
| 3575 | GEN6_RP_MEDIA_TURBO | |
| 3576 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 3577 | GEN6_RP_MEDIA_IS_GFX | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3578 | GEN6_RP_ENABLE | |
| 3579 | GEN6_RP_UP_BUSY_AVG | |
| 3580 | GEN6_RP_DOWN_IDLE_AVG); |
| 3581 | |
| 3582 | /* 6: Ring frequency + overclocking (our driver does this later */ |
| 3583 | |
| 3584 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
| 3585 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3586 | gen8_enable_rps_interrupts(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3587 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3588 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3591 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3592 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3593 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3594 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3595 | u32 rp_state_cap; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3596 | u32 gt_perf_status; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3597 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3598 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3599 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3600 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3601 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3602 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3603 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3604 | /* Here begins a magic sequence of register writes to enable |
| 3605 | * auto-downclocking. |
| 3606 | * |
| 3607 | * Perhaps there might be some value in exposing these to |
| 3608 | * userspace... |
| 3609 | */ |
| 3610 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3611 | |
| 3612 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 3613 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 3614 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 3615 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3616 | } |
| 3617 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3618 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3619 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3620 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
| 3621 | gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS); |
| 3622 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3623 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3624 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3625 | /* disable the counters and set deterministic thresholds */ |
| 3626 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3627 | |
| 3628 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 3629 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 3630 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 3631 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3632 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3633 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3634 | for_each_ring(ring, dev_priv, i) |
| 3635 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3636 | |
| 3637 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3638 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 3639 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 3640 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 3641 | else |
| 3642 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 3643 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3644 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 3645 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3646 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3647 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 3648 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 3649 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 3650 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3651 | /* We don't use those on Haswell */ |
| 3652 | if (!IS_HASWELL(dev)) { |
| 3653 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 3654 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3655 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3656 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 3657 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 3658 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3659 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3660 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3661 | |
| 3662 | I915_WRITE(GEN6_RC_CONTROL, |
| 3663 | rc6_mask | |
| 3664 | GEN6_RC_CTL_EI_MODE(1) | |
| 3665 | GEN6_RC_CTL_HW_ENABLE); |
| 3666 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3667 | /* Power down if completely idle for over 50ms */ |
| 3668 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3669 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3670 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3671 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_MIN_FREQ_TABLE, 0); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3672 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3673 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3674 | |
| 3675 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 3676 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 3677 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3678 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3679 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3680 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3681 | } |
| 3682 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3683 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3684 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3685 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3686 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3687 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 3688 | rc6vids = 0; |
| 3689 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 3690 | if (IS_GEN6(dev) && ret) { |
| 3691 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 3692 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 3693 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 3694 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 3695 | rc6vids &= 0xffff00; |
| 3696 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 3697 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 3698 | if (ret) |
| 3699 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 3700 | } |
| 3701 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3702 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3703 | } |
| 3704 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 3705 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3706 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3707 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3708 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3709 | unsigned int gpu_freq; |
| 3710 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3711 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3712 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3713 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3714 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3715 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3716 | policy = cpufreq_cpu_get(0); |
| 3717 | if (policy) { |
| 3718 | max_ia_freq = policy->cpuinfo.max_freq; |
| 3719 | cpufreq_cpu_put(policy); |
| 3720 | } else { |
| 3721 | /* |
| 3722 | * Default to measured freq if none found, PCU will ensure we |
| 3723 | * don't go over |
| 3724 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3725 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3726 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3727 | |
| 3728 | /* Convert from kHz to MHz */ |
| 3729 | max_ia_freq /= 1000; |
| 3730 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 3731 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3732 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 3733 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3734 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3735 | /* |
| 3736 | * For each potential GPU frequency, load a ring frequency we'd like |
| 3737 | * to use for memory access. We do this by specifying the IA frequency |
| 3738 | * the PCU should use as a reference to determine the ring frequency. |
| 3739 | */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3740 | for (gpu_freq = dev_priv->rps.max_freq_softlimit; gpu_freq >= dev_priv->rps.min_freq_softlimit; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3741 | gpu_freq--) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3742 | int diff = dev_priv->rps.max_freq_softlimit - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3743 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3744 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 3745 | if (INTEL_INFO(dev)->gen >= 8) { |
| 3746 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 3747 | ring_freq = max(min_ring_freq, gpu_freq); |
| 3748 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3749 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3750 | ring_freq = max(min_ring_freq, ring_freq); |
| 3751 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 3752 | } else { |
| 3753 | /* On older processors, there is no separate ring |
| 3754 | * clock domain, so in order to boost the bandwidth |
| 3755 | * of the ring, we need to upclock the CPU (ia_freq). |
| 3756 | * |
| 3757 | * For GPU frequencies less than 750MHz, |
| 3758 | * just use the lowest ring freq. |
| 3759 | */ |
| 3760 | if (gpu_freq < min_freq) |
| 3761 | ia_freq = 800; |
| 3762 | else |
| 3763 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 3764 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 3765 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3766 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3767 | sandybridge_pcode_write(dev_priv, |
| 3768 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3769 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 3770 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 3771 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3772 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3773 | } |
| 3774 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 3775 | void gen6_update_ring_freq(struct drm_device *dev) |
| 3776 | { |
| 3777 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3778 | |
| 3779 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 3780 | return; |
| 3781 | |
| 3782 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3783 | __gen6_update_ring_freq(dev); |
| 3784 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3785 | } |
| 3786 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 3787 | int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
| 3788 | { |
| 3789 | u32 val, rp0; |
| 3790 | |
| 3791 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 3792 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 3793 | |
| 3794 | return rp0; |
| 3795 | } |
| 3796 | |
| 3797 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 3798 | { |
| 3799 | u32 val, rpe; |
| 3800 | |
| 3801 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 3802 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 3803 | |
| 3804 | return rpe; |
| 3805 | } |
| 3806 | |
| 3807 | int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 3808 | { |
| 3809 | u32 val, rpn; |
| 3810 | |
| 3811 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 3812 | rpn = (val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK; |
| 3813 | return rpn; |
| 3814 | } |
| 3815 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3816 | int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
| 3817 | { |
| 3818 | u32 val, rp0; |
| 3819 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3820 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3821 | |
| 3822 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 3823 | /* Clamp to max */ |
| 3824 | rp0 = min_t(u32, rp0, 0xea); |
| 3825 | |
| 3826 | return rp0; |
| 3827 | } |
| 3828 | |
| 3829 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 3830 | { |
| 3831 | u32 val, rpe; |
| 3832 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3833 | 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] | 3834 | 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] | 3835 | 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] | 3836 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 3837 | |
| 3838 | return rpe; |
| 3839 | } |
| 3840 | |
| 3841 | int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
| 3842 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3843 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3844 | } |
| 3845 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3846 | /* Check that the pctx buffer wasn't move under us. */ |
| 3847 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 3848 | { |
| 3849 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 3850 | |
| 3851 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 3852 | dev_priv->vlv_pctx->stolen->start); |
| 3853 | } |
| 3854 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3855 | |
| 3856 | /* Check that the pcbr address is not empty. */ |
| 3857 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 3858 | { |
| 3859 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 3860 | |
| 3861 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 3862 | } |
| 3863 | |
| 3864 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 3865 | { |
| 3866 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3867 | unsigned long pctx_paddr, paddr; |
| 3868 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 3869 | u32 pcbr; |
| 3870 | int pctx_size = 32*1024; |
| 3871 | |
| 3872 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3873 | |
| 3874 | pcbr = I915_READ(VLV_PCBR); |
| 3875 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
| 3876 | paddr = (dev_priv->mm.stolen_base + |
| 3877 | (gtt->stolen_size - pctx_size)); |
| 3878 | |
| 3879 | pctx_paddr = (paddr & (~4095)); |
| 3880 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 3881 | } |
| 3882 | } |
| 3883 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3884 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 3885 | { |
| 3886 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3887 | struct drm_i915_gem_object *pctx; |
| 3888 | unsigned long pctx_paddr; |
| 3889 | u32 pcbr; |
| 3890 | int pctx_size = 24*1024; |
| 3891 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 3892 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3893 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3894 | pcbr = I915_READ(VLV_PCBR); |
| 3895 | if (pcbr) { |
| 3896 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 3897 | int pcbr_offset; |
| 3898 | |
| 3899 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 3900 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 3901 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 3902 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3903 | pctx_size); |
| 3904 | goto out; |
| 3905 | } |
| 3906 | |
| 3907 | /* |
| 3908 | * From the Gunit register HAS: |
| 3909 | * The Gfx driver is expected to program this register and ensure |
| 3910 | * proper allocation within Gfx stolen memory. For example, this |
| 3911 | * register should be programmed such than the PCBR range does not |
| 3912 | * overlap with other ranges, such as the frame buffer, protected |
| 3913 | * memory, or any other relevant ranges. |
| 3914 | */ |
| 3915 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 3916 | if (!pctx) { |
| 3917 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 3918 | return; |
| 3919 | } |
| 3920 | |
| 3921 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 3922 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 3923 | |
| 3924 | out: |
| 3925 | dev_priv->vlv_pctx = pctx; |
| 3926 | } |
| 3927 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3928 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 3929 | { |
| 3930 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3931 | |
| 3932 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 3933 | return; |
| 3934 | |
| 3935 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 3936 | dev_priv->vlv_pctx = NULL; |
| 3937 | } |
| 3938 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 3939 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 3940 | { |
| 3941 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3942 | |
| 3943 | valleyview_setup_pctx(dev); |
| 3944 | |
| 3945 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3946 | |
| 3947 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 3948 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 3949 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 3950 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 3951 | dev_priv->rps.max_freq); |
| 3952 | |
| 3953 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 3954 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 3955 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 3956 | dev_priv->rps.efficient_freq); |
| 3957 | |
| 3958 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 3959 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 3960 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 3961 | dev_priv->rps.min_freq); |
| 3962 | |
| 3963 | /* Preserve min/max settings in case of re-init */ |
| 3964 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3965 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3966 | |
| 3967 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 3968 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 3969 | |
| 3970 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3971 | } |
| 3972 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3973 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 3974 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 3975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3976 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3977 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 3978 | |
| 3979 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3980 | |
| 3981 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 3982 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 3983 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 3984 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 3985 | dev_priv->rps.max_freq); |
| 3986 | |
| 3987 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 3988 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 3989 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 3990 | dev_priv->rps.efficient_freq); |
| 3991 | |
| 3992 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 3993 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 3994 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 3995 | dev_priv->rps.min_freq); |
| 3996 | |
| 3997 | /* Preserve min/max settings in case of re-init */ |
| 3998 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3999 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4000 | |
| 4001 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4002 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4003 | |
| 4004 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4005 | } |
| 4006 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4007 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4008 | { |
| 4009 | valleyview_cleanup_pctx(dev); |
| 4010 | } |
| 4011 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4012 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4013 | { |
| 4014 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4015 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4016 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4017 | int i; |
| 4018 | |
| 4019 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4020 | |
| 4021 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4022 | if (gtfifodbg) { |
| 4023 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4024 | gtfifodbg); |
| 4025 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4026 | } |
| 4027 | |
| 4028 | cherryview_check_pctx(dev_priv); |
| 4029 | |
| 4030 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4031 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
| 4032 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 4033 | |
| 4034 | /* 2a: Program RC6 thresholds.*/ |
| 4035 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4036 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4037 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4038 | |
| 4039 | for_each_ring(ring, dev_priv, i) |
| 4040 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4041 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4042 | |
| 4043 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 4044 | |
| 4045 | /* allows RC6 residency counter to work */ |
| 4046 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4047 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4048 | VLV_MEDIA_RC6_COUNT_EN | |
| 4049 | VLV_RENDER_RC6_COUNT_EN)); |
| 4050 | |
| 4051 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 4052 | pcbr = I915_READ(VLV_PCBR); |
| 4053 | |
| 4054 | DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr); |
| 4055 | |
| 4056 | /* 3: Enable RC6 */ |
| 4057 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 4058 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
| 4059 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 4060 | |
| 4061 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 4062 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4063 | /* 4 Program defaults and thresholds for RPS*/ |
| 4064 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4065 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4066 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4067 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4068 | |
| 4069 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4070 | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4071 | /* WaDisablePwrmtrEvent:chv (pre-production hw) */ |
| 4072 | I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff); |
| 4073 | I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00); |
| 4074 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4075 | /* 5: Enable RPS */ |
| 4076 | I915_WRITE(GEN6_RP_CONTROL, |
| 4077 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4078 | GEN6_RP_MEDIA_IS_GFX | /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4079 | GEN6_RP_ENABLE | |
| 4080 | GEN6_RP_UP_BUSY_AVG | |
| 4081 | GEN6_RP_DOWN_IDLE_AVG); |
| 4082 | |
| 4083 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4084 | |
| 4085 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4086 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4087 | |
| 4088 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 4089 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
| 4090 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4091 | dev_priv->rps.cur_freq); |
| 4092 | |
| 4093 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
| 4094 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4095 | dev_priv->rps.efficient_freq); |
| 4096 | |
| 4097 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 4098 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4099 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 4100 | } |
| 4101 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4102 | static void valleyview_enable_rps(struct drm_device *dev) |
| 4103 | { |
| 4104 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4105 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4106 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4107 | int i; |
| 4108 | |
| 4109 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4110 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4111 | valleyview_check_pctx(dev_priv); |
| 4112 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4113 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 4114 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4115 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4116 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4117 | } |
| 4118 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4119 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 4120 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4121 | |
| 4122 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4123 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4124 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4125 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4126 | |
| 4127 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4128 | |
| 4129 | I915_WRITE(GEN6_RP_CONTROL, |
| 4130 | GEN6_RP_MEDIA_TURBO | |
| 4131 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4132 | GEN6_RP_MEDIA_IS_GFX | |
| 4133 | GEN6_RP_ENABLE | |
| 4134 | GEN6_RP_UP_BUSY_AVG | |
| 4135 | GEN6_RP_DOWN_IDLE_CONT); |
| 4136 | |
| 4137 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 4138 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4139 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4140 | |
| 4141 | for_each_ring(ring, dev_priv, i) |
| 4142 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4143 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 4144 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4145 | |
| 4146 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4147 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4148 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4149 | VLV_MEDIA_RC6_COUNT_EN | |
| 4150 | VLV_RENDER_RC6_COUNT_EN)); |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4151 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 4152 | 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] | 4153 | |
| 4154 | intel_print_rc6_info(dev, rc6_mode); |
| 4155 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4156 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4157 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4158 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4159 | |
| 4160 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4161 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4162 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4163 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4164 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4165 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4166 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4167 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4168 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4169 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4170 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4171 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4172 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4173 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4174 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4175 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4176 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4177 | } |
| 4178 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4179 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4180 | { |
| 4181 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4182 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4183 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4184 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4185 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 4186 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4187 | } |
| 4188 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4189 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4190 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4191 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 4192 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4193 | } |
| 4194 | } |
| 4195 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4196 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4197 | { |
| 4198 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4199 | |
| 4200 | if (I915_READ(PWRCTXA)) { |
| 4201 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 4202 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 4203 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 4204 | 50); |
| 4205 | |
| 4206 | I915_WRITE(PWRCTXA, 0); |
| 4207 | POSTING_READ(PWRCTXA); |
| 4208 | |
| 4209 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 4210 | POSTING_READ(RSTDBYCTL); |
| 4211 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 4215 | { |
| 4216 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4217 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4218 | if (dev_priv->ips.renderctx == NULL) |
| 4219 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 4220 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4221 | return -ENOMEM; |
| 4222 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4223 | if (dev_priv->ips.pwrctx == NULL) |
| 4224 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 4225 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4226 | ironlake_teardown_rc6(dev); |
| 4227 | return -ENOMEM; |
| 4228 | } |
| 4229 | |
| 4230 | return 0; |
| 4231 | } |
| 4232 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4233 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4234 | { |
| 4235 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4236 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4237 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4238 | int ret; |
| 4239 | |
| 4240 | /* rc6 disabled by default due to repeated reports of hanging during |
| 4241 | * boot and resume. |
| 4242 | */ |
| 4243 | if (!intel_enable_rc6(dev)) |
| 4244 | return; |
| 4245 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4246 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4247 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4248 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4249 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4250 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4251 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4252 | was_interruptible = dev_priv->mm.interruptible; |
| 4253 | dev_priv->mm.interruptible = false; |
| 4254 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4255 | /* |
| 4256 | * GPU can automatically power down the render unit if given a page |
| 4257 | * to save state. |
| 4258 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4259 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4260 | if (ret) { |
| 4261 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4262 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4263 | return; |
| 4264 | } |
| 4265 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4266 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 4267 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4268 | 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] | 4269 | MI_MM_SPACE_GTT | |
| 4270 | MI_SAVE_EXT_STATE_EN | |
| 4271 | MI_RESTORE_EXT_STATE_EN | |
| 4272 | MI_RESTORE_INHIBIT); |
| 4273 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 4274 | intel_ring_emit(ring, MI_NOOP); |
| 4275 | intel_ring_emit(ring, MI_FLUSH); |
| 4276 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4277 | |
| 4278 | /* |
| 4279 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 4280 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 4281 | * safe to assume that renderctx is valid |
| 4282 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4283 | ret = intel_ring_idle(ring); |
| 4284 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4285 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 4286 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4287 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4288 | return; |
| 4289 | } |
| 4290 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4291 | 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] | 4292 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4293 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4294 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4295 | } |
| 4296 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4297 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 4298 | { |
| 4299 | unsigned long freq; |
| 4300 | int div = (vidfreq & 0x3f0000) >> 16; |
| 4301 | int post = (vidfreq & 0x3000) >> 12; |
| 4302 | int pre = (vidfreq & 0x7); |
| 4303 | |
| 4304 | if (!pre) |
| 4305 | return 0; |
| 4306 | |
| 4307 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 4308 | |
| 4309 | return freq; |
| 4310 | } |
| 4311 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4312 | static const struct cparams { |
| 4313 | u16 i; |
| 4314 | u16 t; |
| 4315 | u16 m; |
| 4316 | u16 c; |
| 4317 | } cparams[] = { |
| 4318 | { 1, 1333, 301, 28664 }, |
| 4319 | { 1, 1066, 294, 24460 }, |
| 4320 | { 1, 800, 294, 25192 }, |
| 4321 | { 0, 1333, 276, 27605 }, |
| 4322 | { 0, 1066, 276, 27605 }, |
| 4323 | { 0, 800, 231, 23784 }, |
| 4324 | }; |
| 4325 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4326 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4327 | { |
| 4328 | u64 total_count, diff, ret; |
| 4329 | u32 count1, count2, count3, m = 0, c = 0; |
| 4330 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 4331 | int i; |
| 4332 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4333 | assert_spin_locked(&mchdev_lock); |
| 4334 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4335 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4336 | |
| 4337 | /* Prevent division-by-zero if we are asking too fast. |
| 4338 | * Also, we don't get interesting results if we are polling |
| 4339 | * faster than once in 10ms, so just return the saved value |
| 4340 | * in such cases. |
| 4341 | */ |
| 4342 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4343 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4344 | |
| 4345 | count1 = I915_READ(DMIEC); |
| 4346 | count2 = I915_READ(DDREC); |
| 4347 | count3 = I915_READ(CSIEC); |
| 4348 | |
| 4349 | total_count = count1 + count2 + count3; |
| 4350 | |
| 4351 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4352 | if (total_count < dev_priv->ips.last_count1) { |
| 4353 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4354 | diff += total_count; |
| 4355 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4356 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4360 | if (cparams[i].i == dev_priv->ips.c_m && |
| 4361 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4362 | m = cparams[i].m; |
| 4363 | c = cparams[i].c; |
| 4364 | break; |
| 4365 | } |
| 4366 | } |
| 4367 | |
| 4368 | diff = div_u64(diff, diff1); |
| 4369 | ret = ((m * diff) + c); |
| 4370 | ret = div_u64(ret, 10); |
| 4371 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4372 | dev_priv->ips.last_count1 = total_count; |
| 4373 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4374 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4375 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4376 | |
| 4377 | return ret; |
| 4378 | } |
| 4379 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4380 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 4381 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4382 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4383 | unsigned long val; |
| 4384 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4385 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4386 | return 0; |
| 4387 | |
| 4388 | spin_lock_irq(&mchdev_lock); |
| 4389 | |
| 4390 | val = __i915_chipset_val(dev_priv); |
| 4391 | |
| 4392 | spin_unlock_irq(&mchdev_lock); |
| 4393 | |
| 4394 | return val; |
| 4395 | } |
| 4396 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4397 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 4398 | { |
| 4399 | unsigned long m, x, b; |
| 4400 | u32 tsfs; |
| 4401 | |
| 4402 | tsfs = I915_READ(TSFS); |
| 4403 | |
| 4404 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 4405 | x = I915_READ8(TR1); |
| 4406 | |
| 4407 | b = tsfs & TSFS_INTR_MASK; |
| 4408 | |
| 4409 | return ((m * x) / 127) - b; |
| 4410 | } |
| 4411 | |
| 4412 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 4413 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4414 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4415 | static const struct v_table { |
| 4416 | u16 vd; /* in .1 mil */ |
| 4417 | u16 vm; /* in .1 mil */ |
| 4418 | } v_table[] = { |
| 4419 | { 0, 0, }, |
| 4420 | { 375, 0, }, |
| 4421 | { 500, 0, }, |
| 4422 | { 625, 0, }, |
| 4423 | { 750, 0, }, |
| 4424 | { 875, 0, }, |
| 4425 | { 1000, 0, }, |
| 4426 | { 1125, 0, }, |
| 4427 | { 4125, 3000, }, |
| 4428 | { 4125, 3000, }, |
| 4429 | { 4125, 3000, }, |
| 4430 | { 4125, 3000, }, |
| 4431 | { 4125, 3000, }, |
| 4432 | { 4125, 3000, }, |
| 4433 | { 4125, 3000, }, |
| 4434 | { 4125, 3000, }, |
| 4435 | { 4125, 3000, }, |
| 4436 | { 4125, 3000, }, |
| 4437 | { 4125, 3000, }, |
| 4438 | { 4125, 3000, }, |
| 4439 | { 4125, 3000, }, |
| 4440 | { 4125, 3000, }, |
| 4441 | { 4125, 3000, }, |
| 4442 | { 4125, 3000, }, |
| 4443 | { 4125, 3000, }, |
| 4444 | { 4125, 3000, }, |
| 4445 | { 4125, 3000, }, |
| 4446 | { 4125, 3000, }, |
| 4447 | { 4125, 3000, }, |
| 4448 | { 4125, 3000, }, |
| 4449 | { 4125, 3000, }, |
| 4450 | { 4125, 3000, }, |
| 4451 | { 4250, 3125, }, |
| 4452 | { 4375, 3250, }, |
| 4453 | { 4500, 3375, }, |
| 4454 | { 4625, 3500, }, |
| 4455 | { 4750, 3625, }, |
| 4456 | { 4875, 3750, }, |
| 4457 | { 5000, 3875, }, |
| 4458 | { 5125, 4000, }, |
| 4459 | { 5250, 4125, }, |
| 4460 | { 5375, 4250, }, |
| 4461 | { 5500, 4375, }, |
| 4462 | { 5625, 4500, }, |
| 4463 | { 5750, 4625, }, |
| 4464 | { 5875, 4750, }, |
| 4465 | { 6000, 4875, }, |
| 4466 | { 6125, 5000, }, |
| 4467 | { 6250, 5125, }, |
| 4468 | { 6375, 5250, }, |
| 4469 | { 6500, 5375, }, |
| 4470 | { 6625, 5500, }, |
| 4471 | { 6750, 5625, }, |
| 4472 | { 6875, 5750, }, |
| 4473 | { 7000, 5875, }, |
| 4474 | { 7125, 6000, }, |
| 4475 | { 7250, 6125, }, |
| 4476 | { 7375, 6250, }, |
| 4477 | { 7500, 6375, }, |
| 4478 | { 7625, 6500, }, |
| 4479 | { 7750, 6625, }, |
| 4480 | { 7875, 6750, }, |
| 4481 | { 8000, 6875, }, |
| 4482 | { 8125, 7000, }, |
| 4483 | { 8250, 7125, }, |
| 4484 | { 8375, 7250, }, |
| 4485 | { 8500, 7375, }, |
| 4486 | { 8625, 7500, }, |
| 4487 | { 8750, 7625, }, |
| 4488 | { 8875, 7750, }, |
| 4489 | { 9000, 7875, }, |
| 4490 | { 9125, 8000, }, |
| 4491 | { 9250, 8125, }, |
| 4492 | { 9375, 8250, }, |
| 4493 | { 9500, 8375, }, |
| 4494 | { 9625, 8500, }, |
| 4495 | { 9750, 8625, }, |
| 4496 | { 9875, 8750, }, |
| 4497 | { 10000, 8875, }, |
| 4498 | { 10125, 9000, }, |
| 4499 | { 10250, 9125, }, |
| 4500 | { 10375, 9250, }, |
| 4501 | { 10500, 9375, }, |
| 4502 | { 10625, 9500, }, |
| 4503 | { 10750, 9625, }, |
| 4504 | { 10875, 9750, }, |
| 4505 | { 11000, 9875, }, |
| 4506 | { 11125, 10000, }, |
| 4507 | { 11250, 10125, }, |
| 4508 | { 11375, 10250, }, |
| 4509 | { 11500, 10375, }, |
| 4510 | { 11625, 10500, }, |
| 4511 | { 11750, 10625, }, |
| 4512 | { 11875, 10750, }, |
| 4513 | { 12000, 10875, }, |
| 4514 | { 12125, 11000, }, |
| 4515 | { 12250, 11125, }, |
| 4516 | { 12375, 11250, }, |
| 4517 | { 12500, 11375, }, |
| 4518 | { 12625, 11500, }, |
| 4519 | { 12750, 11625, }, |
| 4520 | { 12875, 11750, }, |
| 4521 | { 13000, 11875, }, |
| 4522 | { 13125, 12000, }, |
| 4523 | { 13250, 12125, }, |
| 4524 | { 13375, 12250, }, |
| 4525 | { 13500, 12375, }, |
| 4526 | { 13625, 12500, }, |
| 4527 | { 13750, 12625, }, |
| 4528 | { 13875, 12750, }, |
| 4529 | { 14000, 12875, }, |
| 4530 | { 14125, 13000, }, |
| 4531 | { 14250, 13125, }, |
| 4532 | { 14375, 13250, }, |
| 4533 | { 14500, 13375, }, |
| 4534 | { 14625, 13500, }, |
| 4535 | { 14750, 13625, }, |
| 4536 | { 14875, 13750, }, |
| 4537 | { 15000, 13875, }, |
| 4538 | { 15125, 14000, }, |
| 4539 | { 15250, 14125, }, |
| 4540 | { 15375, 14250, }, |
| 4541 | { 15500, 14375, }, |
| 4542 | { 15625, 14500, }, |
| 4543 | { 15750, 14625, }, |
| 4544 | { 15875, 14750, }, |
| 4545 | { 16000, 14875, }, |
| 4546 | { 16125, 15000, }, |
| 4547 | }; |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4548 | if (INTEL_INFO(dev)->is_mobile) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4549 | return v_table[pxvid].vm; |
| 4550 | else |
| 4551 | return v_table[pxvid].vd; |
| 4552 | } |
| 4553 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4554 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4555 | { |
| 4556 | struct timespec now, diff1; |
| 4557 | u64 diff; |
| 4558 | unsigned long diffms; |
| 4559 | u32 count; |
| 4560 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4561 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4562 | |
| 4563 | getrawmonotonic(&now); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4564 | diff1 = timespec_sub(now, dev_priv->ips.last_time2); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4565 | |
| 4566 | /* Don't divide by 0 */ |
| 4567 | diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; |
| 4568 | if (!diffms) |
| 4569 | return; |
| 4570 | |
| 4571 | count = I915_READ(GFXEC); |
| 4572 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4573 | if (count < dev_priv->ips.last_count2) { |
| 4574 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4575 | diff += count; |
| 4576 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4577 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4578 | } |
| 4579 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4580 | dev_priv->ips.last_count2 = count; |
| 4581 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4582 | |
| 4583 | /* More magic constants... */ |
| 4584 | diff = diff * 1181; |
| 4585 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4586 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4587 | } |
| 4588 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4589 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 4590 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4591 | struct drm_device *dev = dev_priv->dev; |
| 4592 | |
| 4593 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4594 | return; |
| 4595 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4596 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4597 | |
| 4598 | __i915_update_gfx_val(dev_priv); |
| 4599 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4600 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4601 | } |
| 4602 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4603 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4604 | { |
| 4605 | unsigned long t, corr, state1, corr2, state2; |
| 4606 | u32 pxvid, ext_v; |
| 4607 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4608 | assert_spin_locked(&mchdev_lock); |
| 4609 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4610 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4611 | pxvid = (pxvid >> 24) & 0x7f; |
| 4612 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 4613 | |
| 4614 | state1 = ext_v; |
| 4615 | |
| 4616 | t = i915_mch_val(dev_priv); |
| 4617 | |
| 4618 | /* Revel in the empirically derived constants */ |
| 4619 | |
| 4620 | /* Correction factor in 1/100000 units */ |
| 4621 | if (t > 80) |
| 4622 | corr = ((t * 2349) + 135940); |
| 4623 | else if (t >= 50) |
| 4624 | corr = ((t * 964) + 29317); |
| 4625 | else /* < 50 */ |
| 4626 | corr = ((t * 301) + 1004); |
| 4627 | |
| 4628 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 4629 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4630 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4631 | |
| 4632 | state2 = (corr2 * state1) / 10000; |
| 4633 | state2 /= 100; /* convert to mW */ |
| 4634 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4635 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4636 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4637 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4638 | } |
| 4639 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4640 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 4641 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4642 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4643 | unsigned long val; |
| 4644 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4645 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4646 | return 0; |
| 4647 | |
| 4648 | spin_lock_irq(&mchdev_lock); |
| 4649 | |
| 4650 | val = __i915_gfx_val(dev_priv); |
| 4651 | |
| 4652 | spin_unlock_irq(&mchdev_lock); |
| 4653 | |
| 4654 | return val; |
| 4655 | } |
| 4656 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4657 | /** |
| 4658 | * i915_read_mch_val - return value for IPS use |
| 4659 | * |
| 4660 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 4661 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 4662 | */ |
| 4663 | unsigned long i915_read_mch_val(void) |
| 4664 | { |
| 4665 | struct drm_i915_private *dev_priv; |
| 4666 | unsigned long chipset_val, graphics_val, ret = 0; |
| 4667 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4668 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4669 | if (!i915_mch_dev) |
| 4670 | goto out_unlock; |
| 4671 | dev_priv = i915_mch_dev; |
| 4672 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4673 | chipset_val = __i915_chipset_val(dev_priv); |
| 4674 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4675 | |
| 4676 | ret = chipset_val + graphics_val; |
| 4677 | |
| 4678 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4679 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4680 | |
| 4681 | return ret; |
| 4682 | } |
| 4683 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 4684 | |
| 4685 | /** |
| 4686 | * i915_gpu_raise - raise GPU frequency limit |
| 4687 | * |
| 4688 | * Raise the limit; IPS indicates we have thermal headroom. |
| 4689 | */ |
| 4690 | bool i915_gpu_raise(void) |
| 4691 | { |
| 4692 | struct drm_i915_private *dev_priv; |
| 4693 | bool ret = true; |
| 4694 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4695 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4696 | if (!i915_mch_dev) { |
| 4697 | ret = false; |
| 4698 | goto out_unlock; |
| 4699 | } |
| 4700 | dev_priv = i915_mch_dev; |
| 4701 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4702 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 4703 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4704 | |
| 4705 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4706 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4707 | |
| 4708 | return ret; |
| 4709 | } |
| 4710 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 4711 | |
| 4712 | /** |
| 4713 | * i915_gpu_lower - lower GPU frequency limit |
| 4714 | * |
| 4715 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 4716 | * frequency maximum. |
| 4717 | */ |
| 4718 | bool i915_gpu_lower(void) |
| 4719 | { |
| 4720 | struct drm_i915_private *dev_priv; |
| 4721 | bool ret = true; |
| 4722 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4723 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4724 | if (!i915_mch_dev) { |
| 4725 | ret = false; |
| 4726 | goto out_unlock; |
| 4727 | } |
| 4728 | dev_priv = i915_mch_dev; |
| 4729 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4730 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 4731 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4732 | |
| 4733 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4734 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4735 | |
| 4736 | return ret; |
| 4737 | } |
| 4738 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 4739 | |
| 4740 | /** |
| 4741 | * i915_gpu_busy - indicate GPU business to IPS |
| 4742 | * |
| 4743 | * Tell the IPS driver whether or not the GPU is busy. |
| 4744 | */ |
| 4745 | bool i915_gpu_busy(void) |
| 4746 | { |
| 4747 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4748 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4749 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4750 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4751 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4752 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4753 | if (!i915_mch_dev) |
| 4754 | goto out_unlock; |
| 4755 | dev_priv = i915_mch_dev; |
| 4756 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4757 | for_each_ring(ring, dev_priv, i) |
| 4758 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4759 | |
| 4760 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4761 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4762 | |
| 4763 | return ret; |
| 4764 | } |
| 4765 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 4766 | |
| 4767 | /** |
| 4768 | * i915_gpu_turbo_disable - disable graphics turbo |
| 4769 | * |
| 4770 | * Disable graphics turbo by resetting the max frequency and setting the |
| 4771 | * current frequency to the default. |
| 4772 | */ |
| 4773 | bool i915_gpu_turbo_disable(void) |
| 4774 | { |
| 4775 | struct drm_i915_private *dev_priv; |
| 4776 | bool ret = true; |
| 4777 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4778 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4779 | if (!i915_mch_dev) { |
| 4780 | ret = false; |
| 4781 | goto out_unlock; |
| 4782 | } |
| 4783 | dev_priv = i915_mch_dev; |
| 4784 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4785 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4786 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4787 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4788 | ret = false; |
| 4789 | |
| 4790 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4791 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4792 | |
| 4793 | return ret; |
| 4794 | } |
| 4795 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 4796 | |
| 4797 | /** |
| 4798 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 4799 | * IPS got loaded first. |
| 4800 | * |
| 4801 | * This awkward dance is so that neither module has to depend on the |
| 4802 | * other in order for IPS to do the appropriate communication of |
| 4803 | * GPU turbo limits to i915. |
| 4804 | */ |
| 4805 | static void |
| 4806 | ips_ping_for_i915_load(void) |
| 4807 | { |
| 4808 | void (*link)(void); |
| 4809 | |
| 4810 | link = symbol_get(ips_link_to_i915_driver); |
| 4811 | if (link) { |
| 4812 | link(); |
| 4813 | symbol_put(ips_link_to_i915_driver); |
| 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 4818 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4819 | /* We only register the i915 ips part with intel-ips once everything is |
| 4820 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4821 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4822 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4823 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4824 | |
| 4825 | ips_ping_for_i915_load(); |
| 4826 | } |
| 4827 | |
| 4828 | void intel_gpu_ips_teardown(void) |
| 4829 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4830 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4831 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4832 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4833 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4834 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4835 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4836 | { |
| 4837 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4838 | u32 lcfuse; |
| 4839 | u8 pxw[16]; |
| 4840 | int i; |
| 4841 | |
| 4842 | /* Disable to program */ |
| 4843 | I915_WRITE(ECR, 0); |
| 4844 | POSTING_READ(ECR); |
| 4845 | |
| 4846 | /* Program energy weights for various events */ |
| 4847 | I915_WRITE(SDEW, 0x15040d00); |
| 4848 | I915_WRITE(CSIEW0, 0x007f0000); |
| 4849 | I915_WRITE(CSIEW1, 0x1e220004); |
| 4850 | I915_WRITE(CSIEW2, 0x04000004); |
| 4851 | |
| 4852 | for (i = 0; i < 5; i++) |
| 4853 | I915_WRITE(PEW + (i * 4), 0); |
| 4854 | for (i = 0; i < 3; i++) |
| 4855 | I915_WRITE(DEW + (i * 4), 0); |
| 4856 | |
| 4857 | /* Program P-state weights to account for frequency power adjustment */ |
| 4858 | for (i = 0; i < 16; i++) { |
| 4859 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 4860 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 4861 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 4862 | PXVFREQ_PX_SHIFT; |
| 4863 | unsigned long val; |
| 4864 | |
| 4865 | val = vid * vid; |
| 4866 | val *= (freq / 1000); |
| 4867 | val *= 255; |
| 4868 | val /= (127*127*900); |
| 4869 | if (val > 0xff) |
| 4870 | DRM_ERROR("bad pxval: %ld\n", val); |
| 4871 | pxw[i] = val; |
| 4872 | } |
| 4873 | /* Render standby states get 0 weight */ |
| 4874 | pxw[14] = 0; |
| 4875 | pxw[15] = 0; |
| 4876 | |
| 4877 | for (i = 0; i < 4; i++) { |
| 4878 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 4879 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 4880 | I915_WRITE(PXW + (i * 4), val); |
| 4881 | } |
| 4882 | |
| 4883 | /* Adjust magic regs to magic values (more experimental results) */ |
| 4884 | I915_WRITE(OGW0, 0); |
| 4885 | I915_WRITE(OGW1, 0); |
| 4886 | I915_WRITE(EG0, 0x00007f00); |
| 4887 | I915_WRITE(EG1, 0x0000000e); |
| 4888 | I915_WRITE(EG2, 0x000e0000); |
| 4889 | I915_WRITE(EG3, 0x68000300); |
| 4890 | I915_WRITE(EG4, 0x42000000); |
| 4891 | I915_WRITE(EG5, 0x00140031); |
| 4892 | I915_WRITE(EG6, 0); |
| 4893 | I915_WRITE(EG7, 0); |
| 4894 | |
| 4895 | for (i = 0; i < 8; i++) |
| 4896 | I915_WRITE(PXWL + (i * 4), 0); |
| 4897 | |
| 4898 | /* Enable PMON + select events */ |
| 4899 | I915_WRITE(ECR, 0x80000019); |
| 4900 | |
| 4901 | lcfuse = I915_READ(LCFUSE02); |
| 4902 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4903 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4904 | } |
| 4905 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4906 | void intel_init_gt_powersave(struct drm_device *dev) |
| 4907 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4908 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 4909 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4910 | if (IS_CHERRYVIEW(dev)) |
| 4911 | cherryview_init_gt_powersave(dev); |
| 4912 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4913 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 4917 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4918 | if (IS_CHERRYVIEW(dev)) |
| 4919 | return; |
| 4920 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4921 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4922 | } |
| 4923 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 4924 | /** |
| 4925 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 4926 | * @dev: drm device |
| 4927 | * |
| 4928 | * We don't want to disable RC6 or other features here, we just want |
| 4929 | * to make sure any work we've queued has finished and won't bother |
| 4930 | * us while we're suspended. |
| 4931 | */ |
| 4932 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 4933 | { |
| 4934 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4935 | |
| 4936 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | e11aa36 | 2014-06-18 09:52:55 -0700 | [diff] [blame] | 4937 | WARN_ON(dev->irq_enabled && !dev_priv->pm.irqs_disabled); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 4938 | |
| 4939 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 4940 | |
| 4941 | cancel_work_sync(&dev_priv->rps.work); |
| 4942 | } |
| 4943 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4944 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 4945 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4946 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4947 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 4948 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | e11aa36 | 2014-06-18 09:52:55 -0700 | [diff] [blame] | 4949 | WARN_ON(dev->irq_enabled && !dev_priv->pm.irqs_disabled); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 4950 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4951 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4952 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4953 | ironlake_disable_rc6(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4954 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 4955 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 4956 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4957 | mutex_lock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4958 | if (IS_CHERRYVIEW(dev)) |
| 4959 | cherryview_disable_rps(dev); |
| 4960 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4961 | valleyview_disable_rps(dev); |
| 4962 | else |
| 4963 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4964 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4965 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4966 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4969 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 4970 | { |
| 4971 | struct drm_i915_private *dev_priv = |
| 4972 | container_of(work, struct drm_i915_private, |
| 4973 | rps.delayed_resume_work.work); |
| 4974 | struct drm_device *dev = dev_priv->dev; |
| 4975 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4976 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4977 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4978 | if (IS_CHERRYVIEW(dev)) { |
| 4979 | cherryview_enable_rps(dev); |
| 4980 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4981 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4982 | } else if (IS_BROADWELL(dev)) { |
| 4983 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4984 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4985 | } else { |
| 4986 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4987 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4988 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4989 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4990 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 4991 | |
| 4992 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4993 | } |
| 4994 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4995 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 4996 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4997 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4998 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4999 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5000 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5001 | ironlake_enable_drps(dev); |
| 5002 | ironlake_enable_rc6(dev); |
| 5003 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5004 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5005 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5006 | /* |
| 5007 | * PCU communication is slow and this doesn't need to be |
| 5008 | * done at any specific time, so do this out of our fast path |
| 5009 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5010 | * |
| 5011 | * We depend on the HW RC6 power context save/restore |
| 5012 | * mechanism when entering D3 through runtime PM suspend. So |
| 5013 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5014 | * get here via the driver load/system resume/runtime resume |
| 5015 | * paths, so the _noresume version is enough (and in case of |
| 5016 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5017 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5018 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5019 | round_jiffies_up_relative(HZ))) |
| 5020 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5021 | } |
| 5022 | } |
| 5023 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5024 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5025 | { |
| 5026 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5027 | |
| 5028 | dev_priv->rps.enabled = false; |
| 5029 | intel_enable_gt_powersave(dev); |
| 5030 | } |
| 5031 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5032 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5033 | { |
| 5034 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5035 | |
| 5036 | /* |
| 5037 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5038 | * gating for the panel power sequencer or it will fail to |
| 5039 | * start up when no ports are active. |
| 5040 | */ |
| 5041 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5042 | } |
| 5043 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5044 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5045 | { |
| 5046 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5047 | int pipe; |
| 5048 | |
| 5049 | for_each_pipe(pipe) { |
| 5050 | I915_WRITE(DSPCNTR(pipe), |
| 5051 | I915_READ(DSPCNTR(pipe)) | |
| 5052 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5053 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5054 | } |
| 5055 | } |
| 5056 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5057 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5058 | { |
| 5059 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5060 | |
| 5061 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5062 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5063 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5064 | |
| 5065 | /* |
| 5066 | * Don't touch WM1S_LP_EN here. |
| 5067 | * Doing so could cause underruns. |
| 5068 | */ |
| 5069 | } |
| 5070 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5071 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5072 | { |
| 5073 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5074 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5075 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5076 | /* |
| 5077 | * Required for FBC |
| 5078 | * WaFbcDisableDpfcClockGating:ilk |
| 5079 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5080 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5081 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5082 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5083 | |
| 5084 | I915_WRITE(PCH_3DCGDIS0, |
| 5085 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5086 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5087 | I915_WRITE(PCH_3DCGDIS1, |
| 5088 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5089 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5090 | /* |
| 5091 | * According to the spec the following bits should be set in |
| 5092 | * order to enable memory self-refresh |
| 5093 | * The bit 22/21 of 0x42004 |
| 5094 | * The bit 5 of 0x42020 |
| 5095 | * The bit 15 of 0x45000 |
| 5096 | */ |
| 5097 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5098 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5099 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5100 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5101 | I915_WRITE(DISP_ARB_CTL, |
| 5102 | (I915_READ(DISP_ARB_CTL) | |
| 5103 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5104 | |
| 5105 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5106 | |
| 5107 | /* |
| 5108 | * Based on the document from hardware guys the following bits |
| 5109 | * should be set unconditionally in order to enable FBC. |
| 5110 | * The bit 22 of 0x42000 |
| 5111 | * The bit 22 of 0x42004 |
| 5112 | * The bit 7,8,9 of 0x42020. |
| 5113 | */ |
| 5114 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5115 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5116 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5117 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5118 | ILK_FBCQ_DIS); |
| 5119 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5120 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5121 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5122 | } |
| 5123 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5124 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5125 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5126 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5127 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5128 | ILK_ELPIN_409_SELECT); |
| 5129 | I915_WRITE(_3D_CHICKEN2, |
| 5130 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5131 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5132 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5133 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5134 | I915_WRITE(CACHE_MODE_0, |
| 5135 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5136 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5137 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5138 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5139 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5140 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5141 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5142 | ibx_init_clock_gating(dev); |
| 5143 | } |
| 5144 | |
| 5145 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5146 | { |
| 5147 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5148 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5149 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5150 | |
| 5151 | /* |
| 5152 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5153 | * gating for the panel power sequencer or it will fail to |
| 5154 | * start up when no ports are active. |
| 5155 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5156 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5157 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5158 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5159 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5160 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5161 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5162 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5163 | */ |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5164 | for_each_pipe(pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5165 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5166 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5167 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5168 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5169 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5170 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5171 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5172 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5173 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5174 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5175 | /* WADP0ClockGatingDisable */ |
| 5176 | for_each_pipe(pipe) { |
| 5177 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5178 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5179 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5180 | } |
| 5181 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5182 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5183 | { |
| 5184 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5185 | uint32_t tmp; |
| 5186 | |
| 5187 | tmp = I915_READ(MCH_SSKPD); |
| 5188 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) { |
| 5189 | DRM_INFO("Wrong MCH_SSKPD value: 0x%08x\n", tmp); |
| 5190 | DRM_INFO("This can cause pipe underruns and display issues.\n"); |
| 5191 | DRM_INFO("Please upgrade your BIOS to fix this.\n"); |
| 5192 | } |
| 5193 | } |
| 5194 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5195 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5196 | { |
| 5197 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5198 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5199 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5200 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5201 | |
| 5202 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5203 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5204 | ILK_ELPIN_409_SELECT); |
| 5205 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5206 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5207 | I915_WRITE(_3D_CHICKEN, |
| 5208 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5209 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5210 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 5211 | if (IS_SNB_GT1(dev)) |
| 5212 | I915_WRITE(GEN6_GT_MODE, |
| 5213 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 5214 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5215 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5216 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5217 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5218 | /* |
| 5219 | * BSpec recoomends 8x4 when MSAA is used, |
| 5220 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5221 | * |
| 5222 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5223 | * disable bit, which we don't touch here, but it's good |
| 5224 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5225 | */ |
| 5226 | I915_WRITE(GEN6_GT_MODE, |
| 5227 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5228 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5229 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5230 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5231 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5232 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5233 | |
| 5234 | I915_WRITE(GEN6_UCGCTL1, |
| 5235 | I915_READ(GEN6_UCGCTL1) | |
| 5236 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5237 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5238 | |
| 5239 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5240 | * gating disable must be set. Failure to set it results in |
| 5241 | * flickering pixels due to Z write ordering failures after |
| 5242 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5243 | * Sanctuary and Tropics, and apparently anything else with |
| 5244 | * alpha test or pixel discard. |
| 5245 | * |
| 5246 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 5247 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5248 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 5249 | * WaDisableRCCUnitClockGating:snb |
| 5250 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5251 | */ |
| 5252 | I915_WRITE(GEN6_UCGCTL2, |
| 5253 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 5254 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 5255 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 5256 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 5257 | I915_WRITE(_3D_CHICKEN3, |
| 5258 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5259 | |
| 5260 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 5261 | * Bspec says: |
| 5262 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 5263 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 5264 | */ |
| 5265 | I915_WRITE(_3D_CHICKEN3, |
| 5266 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 5267 | |
| 5268 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5269 | * According to the spec the following bits should be |
| 5270 | * set in order to enable memory self-refresh and fbc: |
| 5271 | * The bit21 and bit22 of 0x42000 |
| 5272 | * The bit21 and bit22 of 0x42004 |
| 5273 | * The bit5 and bit7 of 0x42020 |
| 5274 | * The bit14 of 0x70180 |
| 5275 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5276 | * |
| 5277 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5278 | */ |
| 5279 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5280 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5281 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 5282 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5283 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5284 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5285 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 5286 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 5287 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 5288 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5289 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5290 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 5291 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5292 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5293 | |
| 5294 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 5298 | { |
| 5299 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 5300 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5301 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5302 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5303 | * |
| 5304 | * This actually overrides the dispatch |
| 5305 | * mode for all thread types. |
| 5306 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5307 | reg &= ~GEN7_FF_SCHED_MASK; |
| 5308 | reg |= GEN7_FF_TS_SCHED_HW; |
| 5309 | reg |= GEN7_FF_VS_SCHED_HW; |
| 5310 | reg |= GEN7_FF_DS_SCHED_HW; |
| 5311 | |
| 5312 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 5313 | } |
| 5314 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5315 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 5316 | { |
| 5317 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5318 | |
| 5319 | /* |
| 5320 | * TODO: this bit should only be enabled when really needed, then |
| 5321 | * disabled when not needed anymore in order to save power. |
| 5322 | */ |
| 5323 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 5324 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 5325 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 5326 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 5327 | |
| 5328 | /* WADPOClockGatingDisable:hsw */ |
| 5329 | I915_WRITE(_TRANSA_CHICKEN1, |
| 5330 | I915_READ(_TRANSA_CHICKEN1) | |
| 5331 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5332 | } |
| 5333 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5334 | static void lpt_suspend_hw(struct drm_device *dev) |
| 5335 | { |
| 5336 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5337 | |
| 5338 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 5339 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 5340 | |
| 5341 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 5342 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 5343 | } |
| 5344 | } |
| 5345 | |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5346 | static void gen8_init_clock_gating(struct drm_device *dev) |
| 5347 | { |
| 5348 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5349 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5350 | |
| 5351 | I915_WRITE(WM3_LP_ILK, 0); |
| 5352 | I915_WRITE(WM2_LP_ILK, 0); |
| 5353 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5354 | |
| 5355 | /* FIXME(BDW): Check all the w/a, some might only apply to |
| 5356 | * pre-production hw. */ |
| 5357 | |
Kenneth Graunke | c8966e1 | 2014-02-26 23:59:30 -0800 | [diff] [blame] | 5358 | /* WaDisablePartialInstShootdown:bdw */ |
| 5359 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5360 | _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE)); |
| 5361 | |
Kenneth Graunke | 1411e6a | 2014-02-26 23:59:31 -0800 | [diff] [blame] | 5362 | /* WaDisableThreadStallDopClockGating:bdw */ |
| 5363 | /* FIXME: Unclear whether we really need this on production bdw. */ |
| 5364 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5365 | _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE)); |
| 5366 | |
Damien Lespiau | 4167e32 | 2014-01-16 16:51:35 +0000 | [diff] [blame] | 5367 | /* |
| 5368 | * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for |
| 5369 | * pre-production hardware |
| 5370 | */ |
Ben Widawsky | fd392b6 | 2013-11-04 22:52:39 -0800 | [diff] [blame] | 5371 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5372 | _MASKED_BIT_ENABLE(GEN8_CENTROID_PIXEL_OPT_DIS)); |
Ben Widawsky | bf66347 | 2013-11-02 21:07:57 -0700 | [diff] [blame] | 5373 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5374 | _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS)); |
Ben Widawsky | 4afe8d3 | 2013-11-02 21:07:55 -0700 | [diff] [blame] | 5375 | I915_WRITE(GAMTARBMODE, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE)); |
| 5376 | |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5377 | I915_WRITE(_3D_CHICKEN3, |
| 5378 | _3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2)); |
| 5379 | |
Ben Widawsky | a75f362 | 2013-11-02 21:07:59 -0700 | [diff] [blame] | 5380 | I915_WRITE(COMMON_SLICE_CHICKEN2, |
| 5381 | _MASKED_BIT_ENABLE(GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE)); |
| 5382 | |
Ben Widawsky | 4c2e7a5 | 2013-11-02 21:08:00 -0700 | [diff] [blame] | 5383 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5384 | _MASKED_BIT_ENABLE(GEN7_SINGLE_SUBSCAN_DISPATCH_ENABLE)); |
| 5385 | |
Ben Widawsky | 242a401 | 2014-04-18 18:04:29 -0300 | [diff] [blame] | 5386 | /* WaDisableDopClockGating:bdw May not be needed for production */ |
| 5387 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5388 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5389 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5390 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5391 | 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] | 5392 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5393 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5394 | I915_WRITE(CHICKEN_PAR1_1, |
| 5395 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 5396 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5397 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5398 | for_each_pipe(pipe) { |
| 5399 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 5400 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 5401 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5402 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 5403 | |
| 5404 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
| 5405 | * workaround for for a possible hang in the unlikely event a TLB |
| 5406 | * invalidation occurs during a PSD flush. |
| 5407 | */ |
| 5408 | I915_WRITE(HDC_CHICKEN0, |
| 5409 | I915_READ(HDC_CHICKEN0) | |
| 5410 | _MASKED_BIT_ENABLE(HDC_FORCE_NON_COHERENT)); |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5411 | |
| 5412 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 5413 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 5414 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5415 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5416 | ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME)); |
Ville Syrjälä | 36075a4 | 2014-02-04 21:59:21 +0200 | [diff] [blame] | 5417 | |
| 5418 | /* |
| 5419 | * BSpec recommends 8x4 when MSAA is used, |
| 5420 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5421 | * |
| 5422 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5423 | * disable bit, which we don't touch here, but it's good |
| 5424 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 36075a4 | 2014-02-04 21:59:21 +0200 | [diff] [blame] | 5425 | */ |
| 5426 | I915_WRITE(GEN7_GT_MODE, |
| 5427 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 5428 | |
| 5429 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5430 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 5431 | |
| 5432 | /* WaDisableSDEUnitClockGating:bdw */ |
| 5433 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5434 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 5435 | |
| 5436 | /* Wa4x4STCOptimizationDisable:bdw */ |
| 5437 | I915_WRITE(CACHE_MODE_1, |
| 5438 | _MASKED_BIT_ENABLE(GEN8_4x4_STC_OPTIMIZATION_DISABLE)); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5439 | } |
| 5440 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5441 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 5442 | { |
| 5443 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5444 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5445 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5446 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 5447 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 5448 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 5449 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 5450 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 5451 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5452 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5453 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5454 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5455 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5456 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 5457 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 5458 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5459 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5460 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5461 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 5462 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5463 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 5464 | /* enable HiZ Raw Stall Optimization */ |
| 5465 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5466 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5467 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5468 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5469 | I915_WRITE(CACHE_MODE_1, |
| 5470 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5471 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5472 | /* |
| 5473 | * BSpec recommends 8x4 when MSAA is used, |
| 5474 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5475 | * |
| 5476 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5477 | * disable bit, which we don't touch here, but it's good |
| 5478 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5479 | */ |
| 5480 | I915_WRITE(GEN7_GT_MODE, |
| 5481 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5482 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5483 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 5484 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 5485 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 5486 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 5487 | I915_WRITE(CHICKEN_PAR1_1, |
| 5488 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5489 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5490 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5491 | } |
| 5492 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5493 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5494 | { |
| 5495 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5496 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5497 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5498 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5499 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5500 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5501 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5502 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5503 | I915_WRITE(_3D_CHICKEN3, |
| 5504 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5505 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5506 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5507 | I915_WRITE(IVB_CHICKEN3, |
| 5508 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5509 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5510 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5511 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5512 | if (IS_IVB_GT1(dev)) |
| 5513 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5514 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5515 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5516 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 5517 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5518 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5519 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5520 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 5521 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 5522 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5523 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5524 | I915_WRITE(GEN7_L3CNTLREG1, |
| 5525 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 5526 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5527 | GEN7_WA_L3_CHICKEN_MODE); |
| 5528 | if (IS_IVB_GT1(dev)) |
| 5529 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5530 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5531 | else { |
| 5532 | /* must write both registers */ |
| 5533 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5534 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5535 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 5536 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5537 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5538 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5539 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5540 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5541 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5542 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 5543 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5544 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5545 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5546 | */ |
| 5547 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 5548 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5549 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5550 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5551 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5552 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5553 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5554 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5555 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5556 | |
| 5557 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5558 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 5559 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 5560 | /* enable HiZ Raw Stall Optimization */ |
| 5561 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5562 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5563 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 5564 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5565 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5566 | I915_WRITE(CACHE_MODE_1, |
| 5567 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5568 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5569 | /* |
| 5570 | * BSpec recommends 8x4 when MSAA is used, |
| 5571 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5572 | * |
| 5573 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5574 | * disable bit, which we don't touch here, but it's good |
| 5575 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5576 | */ |
| 5577 | I915_WRITE(GEN7_GT_MODE, |
| 5578 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5579 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5580 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 5581 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 5582 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 5583 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5584 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 5585 | if (!HAS_PCH_NOP(dev)) |
| 5586 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5587 | |
| 5588 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5589 | } |
| 5590 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5591 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5592 | { |
| 5593 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5594 | u32 val; |
| 5595 | |
| 5596 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5597 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5598 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5599 | switch ((val >> 6) & 3) { |
| 5600 | case 0: |
Deepak S | f6d5194 | 2014-04-03 21:01:28 +0530 | [diff] [blame] | 5601 | case 1: |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5602 | dev_priv->mem_freq = 800; |
| 5603 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5604 | case 2: |
Deepak S | f6d5194 | 2014-04-03 21:01:28 +0530 | [diff] [blame] | 5605 | dev_priv->mem_freq = 1066; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5606 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5607 | case 3: |
Chon Ming Lee | 2325991 | 2013-11-07 15:23:26 +0800 | [diff] [blame] | 5608 | dev_priv->mem_freq = 1333; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5609 | break; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5610 | } |
| 5611 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5612 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 5613 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5614 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5615 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5616 | I915_WRITE(_3D_CHICKEN3, |
| 5617 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5618 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5619 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5620 | I915_WRITE(IVB_CHICKEN3, |
| 5621 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5622 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5623 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 5624 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5625 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5626 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 5627 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 5628 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5629 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5630 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 5631 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5632 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5633 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5634 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5635 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5636 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5637 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5638 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5639 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5640 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5641 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5642 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5643 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5644 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5645 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5646 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 5647 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5648 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5649 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5650 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5651 | */ |
| 5652 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5653 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5654 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 5655 | /* WaDisableL3Bank2xClockGate:vlv |
| 5656 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 5657 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 5658 | I915_WRITE(GEN7_UCGCTL4, |
| 5659 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 5660 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 5661 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5662 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 5663 | /* |
| 5664 | * BSpec says this must be set, even though |
| 5665 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 5666 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 5667 | I915_WRITE(CACHE_MODE_1, |
| 5668 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 5669 | |
| 5670 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 5671 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 5672 | * This is the hardware default actually. |
| 5673 | */ |
| 5674 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 5675 | |
| 5676 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5677 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 5678 | * Disable clock gating on th GCFG unit to prevent a delay |
| 5679 | * in the reporting of vblank events. |
| 5680 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 5681 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5682 | } |
| 5683 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 5684 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 5685 | { |
| 5686 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5687 | |
| 5688 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 5689 | |
| 5690 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 5691 | |
| 5692 | /* WaDisablePartialInstShootdown:chv */ |
| 5693 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5694 | _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE)); |
Ville Syrjälä | a706802 | 2014-04-09 13:28:34 +0300 | [diff] [blame] | 5695 | |
| 5696 | /* WaDisableThreadStallDopClockGating:chv */ |
| 5697 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5698 | _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE)); |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 5699 | |
| 5700 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 5701 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 5702 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5703 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5704 | ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME)); |
Ville Syrjälä | acea6f9 | 2014-04-09 13:28:36 +0300 | [diff] [blame] | 5705 | |
| 5706 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 5707 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5708 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 5709 | |
| 5710 | /* WaDisableCSUnitClockGating:chv */ |
| 5711 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 5712 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 5713 | |
| 5714 | /* WaDisableSDEUnitClockGating:chv */ |
| 5715 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5716 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Rafael Barbalho | e0d34ce | 2014-04-09 13:28:40 +0300 | [diff] [blame] | 5717 | |
| 5718 | /* WaDisableSamplerPowerBypass:chv (pre-production hw) */ |
| 5719 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5720 | _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS)); |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 5721 | |
| 5722 | /* WaDisableGunitClockGating:chv (pre-production hw) */ |
| 5723 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, I915_READ(VLV_GUNIT_CLOCK_GATE) | |
| 5724 | GINT_DIS); |
| 5725 | |
| 5726 | /* WaDisableFfDopClockGating:chv (pre-production hw) */ |
| 5727 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5728 | _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE)); |
| 5729 | |
| 5730 | /* WaDisableDopClockGating:chv (pre-production hw) */ |
| 5731 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5732 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5733 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 5734 | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 5735 | } |
| 5736 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5737 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5738 | { |
| 5739 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5740 | uint32_t dspclk_gate; |
| 5741 | |
| 5742 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 5743 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 5744 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 5745 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 5746 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5747 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 5748 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 5749 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 5750 | if (IS_GM45(dev)) |
| 5751 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 5752 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5753 | |
| 5754 | /* WaDisableRenderCachePipelinedFlush */ |
| 5755 | I915_WRITE(CACHE_MODE_0, |
| 5756 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 5757 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5758 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 5759 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5760 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5761 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5762 | } |
| 5763 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5764 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5765 | { |
| 5766 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5767 | |
| 5768 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 5769 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 5770 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 5771 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5772 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5773 | I915_WRITE(MI_ARB_STATE, |
| 5774 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5775 | |
| 5776 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 5777 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5778 | } |
| 5779 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5780 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5781 | { |
| 5782 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5783 | |
| 5784 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 5785 | I965_RCC_CLOCK_GATE_DISABLE | |
| 5786 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 5787 | I965_ISC_CLOCK_GATE_DISABLE | |
| 5788 | I965_FBC_CLOCK_GATE_DISABLE); |
| 5789 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5790 | I915_WRITE(MI_ARB_STATE, |
| 5791 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5792 | |
| 5793 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 5794 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5795 | } |
| 5796 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5797 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5798 | { |
| 5799 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5800 | u32 dstate = I915_READ(D_STATE); |
| 5801 | |
| 5802 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 5803 | DSTATE_DOT_CLOCK_GATING; |
| 5804 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 5805 | |
| 5806 | if (IS_PINEVIEW(dev)) |
| 5807 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 5808 | |
| 5809 | /* IIR "flip pending" means done if this bit is set */ |
| 5810 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 5811 | |
| 5812 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 5813 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 5814 | |
| 5815 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 5816 | I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5817 | } |
| 5818 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5819 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5820 | { |
| 5821 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5822 | |
| 5823 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 5824 | |
| 5825 | /* interrupts should cause a wake up from C3 */ |
| 5826 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 5827 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5828 | } |
| 5829 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5830 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5831 | { |
| 5832 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5833 | |
| 5834 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
| 5835 | } |
| 5836 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5837 | void intel_init_clock_gating(struct drm_device *dev) |
| 5838 | { |
| 5839 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5840 | |
| 5841 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5842 | } |
| 5843 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5844 | void intel_suspend_hw(struct drm_device *dev) |
| 5845 | { |
| 5846 | if (HAS_PCH_LPT(dev)) |
| 5847 | lpt_suspend_hw(dev); |
| 5848 | } |
| 5849 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5850 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 5851 | for (i = 0; \ |
| 5852 | i < (power_domains)->power_well_count && \ |
| 5853 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 5854 | i++) \ |
| 5855 | if ((power_well)->domains & (domain_mask)) |
| 5856 | |
| 5857 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 5858 | for (i = (power_domains)->power_well_count - 1; \ |
| 5859 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 5860 | i--) \ |
| 5861 | if ((power_well)->domains & (domain_mask)) |
| 5862 | |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5863 | /** |
| 5864 | * We should only use the power well if we explicitly asked the hardware to |
| 5865 | * enable it, so check if it's enabled and also check if we've requested it to |
| 5866 | * be enabled. |
| 5867 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5868 | static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5869 | struct i915_power_well *power_well) |
| 5870 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5871 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 5872 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 5873 | } |
| 5874 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5875 | bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv, |
| 5876 | enum intel_display_power_domain domain) |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5877 | { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5878 | struct i915_power_domains *power_domains; |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5879 | struct i915_power_well *power_well; |
| 5880 | bool is_enabled; |
| 5881 | int i; |
| 5882 | |
| 5883 | if (dev_priv->pm.suspended) |
| 5884 | return false; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5885 | |
| 5886 | power_domains = &dev_priv->power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5887 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5888 | is_enabled = true; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5889 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5890 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 5891 | if (power_well->always_on) |
| 5892 | continue; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5893 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5894 | if (!power_well->hw_enabled) { |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5895 | is_enabled = false; |
| 5896 | break; |
| 5897 | } |
| 5898 | } |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5899 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5900 | return is_enabled; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5901 | } |
| 5902 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5903 | bool intel_display_power_enabled(struct drm_i915_private *dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 5904 | enum intel_display_power_domain domain) |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5905 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5906 | struct i915_power_domains *power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5907 | bool ret; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 5908 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5909 | power_domains = &dev_priv->power_domains; |
| 5910 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5911 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5912 | ret = intel_display_power_enabled_unlocked(dev_priv, domain); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5913 | mutex_unlock(&power_domains->lock); |
| 5914 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5915 | return ret; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5916 | } |
| 5917 | |
Imre Deak | 93c73e8 | 2014-02-18 00:02:19 +0200 | [diff] [blame] | 5918 | /* |
| 5919 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 5920 | * when not needed anymore. We have 4 registers that can request the power well |
| 5921 | * to be enabled, and it will only be disabled if none of the registers is |
| 5922 | * requesting it to be enabled. |
| 5923 | */ |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5924 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 5925 | { |
| 5926 | struct drm_device *dev = dev_priv->dev; |
| 5927 | unsigned long irqflags; |
| 5928 | |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 5929 | /* |
| 5930 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 5931 | * we'll get unclaimed register interrupts. This stops after we write |
| 5932 | * anything to the VGA MSR register. The vgacon module uses this |
| 5933 | * register all the time, so if we unbind our driver and, as a |
| 5934 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 5935 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 5936 | * sure vgacon can keep working normally without triggering interrupts |
| 5937 | * and error messages. |
| 5938 | */ |
| 5939 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 5940 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
| 5941 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 5942 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5943 | if (IS_BROADWELL(dev)) { |
| 5944 | spin_lock_irqsave(&dev_priv->irq_lock, irqflags); |
| 5945 | I915_WRITE(GEN8_DE_PIPE_IMR(PIPE_B), |
| 5946 | dev_priv->de_irq_mask[PIPE_B]); |
| 5947 | I915_WRITE(GEN8_DE_PIPE_IER(PIPE_B), |
| 5948 | ~dev_priv->de_irq_mask[PIPE_B] | |
| 5949 | GEN8_PIPE_VBLANK); |
| 5950 | I915_WRITE(GEN8_DE_PIPE_IMR(PIPE_C), |
| 5951 | dev_priv->de_irq_mask[PIPE_C]); |
| 5952 | I915_WRITE(GEN8_DE_PIPE_IER(PIPE_C), |
| 5953 | ~dev_priv->de_irq_mask[PIPE_C] | |
| 5954 | GEN8_PIPE_VBLANK); |
| 5955 | POSTING_READ(GEN8_DE_PIPE_IER(PIPE_C)); |
| 5956 | spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); |
| 5957 | } |
| 5958 | } |
| 5959 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5960 | static void hsw_set_power_well(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5961 | struct i915_power_well *power_well, bool enable) |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5962 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5963 | bool is_enabled, enable_requested; |
| 5964 | uint32_t tmp; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5965 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5966 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5967 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 5968 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5969 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5970 | if (enable) { |
| 5971 | if (!enable_requested) |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5972 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 5973 | HSW_PWR_WELL_ENABLE_REQUEST); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5974 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5975 | if (!is_enabled) { |
| 5976 | DRM_DEBUG_KMS("Enabling power well\n"); |
| 5977 | if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) & |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 5978 | HSW_PWR_WELL_STATE_ENABLED), 20)) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5979 | DRM_ERROR("Timeout enabling power well\n"); |
| 5980 | } |
Ben Widawsky | 596cc11 | 2013-11-11 14:46:28 -0800 | [diff] [blame] | 5981 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5982 | hsw_power_well_post_enable(dev_priv); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5983 | } else { |
| 5984 | if (enable_requested) { |
| 5985 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 5986 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5987 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5988 | } |
| 5989 | } |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 5990 | } |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 5991 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 5992 | static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 5993 | struct i915_power_well *power_well) |
| 5994 | { |
| 5995 | hsw_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 5996 | |
| 5997 | /* |
| 5998 | * We're taking over the BIOS, so clear any requests made by it since |
| 5999 | * the driver is in charge now. |
| 6000 | */ |
| 6001 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
| 6002 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 6003 | } |
| 6004 | |
| 6005 | static void hsw_power_well_enable(struct drm_i915_private *dev_priv, |
| 6006 | struct i915_power_well *power_well) |
| 6007 | { |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6008 | hsw_set_power_well(dev_priv, power_well, true); |
| 6009 | } |
| 6010 | |
| 6011 | static void hsw_power_well_disable(struct drm_i915_private *dev_priv, |
| 6012 | struct i915_power_well *power_well) |
| 6013 | { |
| 6014 | hsw_set_power_well(dev_priv, power_well, false); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6015 | } |
| 6016 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6017 | static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv, |
| 6018 | struct i915_power_well *power_well) |
| 6019 | { |
| 6020 | } |
| 6021 | |
| 6022 | static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6023 | struct i915_power_well *power_well) |
| 6024 | { |
| 6025 | return true; |
| 6026 | } |
| 6027 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6028 | static void vlv_set_power_well(struct drm_i915_private *dev_priv, |
| 6029 | struct i915_power_well *power_well, bool enable) |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6030 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6031 | enum punit_power_well power_well_id = power_well->data; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6032 | u32 mask; |
| 6033 | u32 state; |
| 6034 | u32 ctrl; |
| 6035 | |
| 6036 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6037 | state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) : |
| 6038 | PUNIT_PWRGT_PWR_GATE(power_well_id); |
| 6039 | |
| 6040 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6041 | |
| 6042 | #define COND \ |
| 6043 | ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state) |
| 6044 | |
| 6045 | if (COND) |
| 6046 | goto out; |
| 6047 | |
| 6048 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL); |
| 6049 | ctrl &= ~mask; |
| 6050 | ctrl |= state; |
| 6051 | vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl); |
| 6052 | |
| 6053 | if (wait_for(COND, 100)) |
| 6054 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 6055 | state, |
| 6056 | vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL)); |
| 6057 | |
| 6058 | #undef COND |
| 6059 | |
| 6060 | out: |
| 6061 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6062 | } |
| 6063 | |
| 6064 | static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6065 | struct i915_power_well *power_well) |
| 6066 | { |
| 6067 | vlv_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6068 | } |
| 6069 | |
| 6070 | static void vlv_power_well_enable(struct drm_i915_private *dev_priv, |
| 6071 | struct i915_power_well *power_well) |
| 6072 | { |
| 6073 | vlv_set_power_well(dev_priv, power_well, true); |
| 6074 | } |
| 6075 | |
| 6076 | static void vlv_power_well_disable(struct drm_i915_private *dev_priv, |
| 6077 | struct i915_power_well *power_well) |
| 6078 | { |
| 6079 | vlv_set_power_well(dev_priv, power_well, false); |
| 6080 | } |
| 6081 | |
| 6082 | static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6083 | struct i915_power_well *power_well) |
| 6084 | { |
| 6085 | int power_well_id = power_well->data; |
| 6086 | bool enabled = false; |
| 6087 | u32 mask; |
| 6088 | u32 state; |
| 6089 | u32 ctrl; |
| 6090 | |
| 6091 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6092 | ctrl = PUNIT_PWRGT_PWR_ON(power_well_id); |
| 6093 | |
| 6094 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6095 | |
| 6096 | state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask; |
| 6097 | /* |
| 6098 | * We only ever set the power-on and power-gate states, anything |
| 6099 | * else is unexpected. |
| 6100 | */ |
| 6101 | WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) && |
| 6102 | state != PUNIT_PWRGT_PWR_GATE(power_well_id)); |
| 6103 | if (state == ctrl) |
| 6104 | enabled = true; |
| 6105 | |
| 6106 | /* |
| 6107 | * A transient state at this point would mean some unexpected party |
| 6108 | * is poking at the power controls too. |
| 6109 | */ |
| 6110 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask; |
| 6111 | WARN_ON(ctrl != state); |
| 6112 | |
| 6113 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6114 | |
| 6115 | return enabled; |
| 6116 | } |
| 6117 | |
| 6118 | static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, |
| 6119 | struct i915_power_well *power_well) |
| 6120 | { |
| 6121 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6122 | |
| 6123 | vlv_set_power_well(dev_priv, power_well, true); |
| 6124 | |
| 6125 | spin_lock_irq(&dev_priv->irq_lock); |
| 6126 | valleyview_enable_display_irqs(dev_priv); |
| 6127 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6128 | |
| 6129 | /* |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6130 | * During driver initialization/resume we can avoid restoring the |
| 6131 | * part of the HW/SW state that will be inited anyway explicitly. |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6132 | */ |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6133 | if (dev_priv->power_domains.initializing) |
| 6134 | return; |
| 6135 | |
| 6136 | intel_hpd_init(dev_priv->dev); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6137 | |
| 6138 | i915_redisable_vga_power_on(dev_priv->dev); |
| 6139 | } |
| 6140 | |
| 6141 | static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv, |
| 6142 | struct i915_power_well *power_well) |
| 6143 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6144 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6145 | |
| 6146 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6147 | valleyview_disable_display_irqs(dev_priv); |
| 6148 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6149 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6150 | vlv_set_power_well(dev_priv, power_well, false); |
| 6151 | } |
| 6152 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6153 | static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 6154 | struct i915_power_well *power_well) |
| 6155 | { |
| 6156 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6157 | |
| 6158 | /* |
| 6159 | * Enable the CRI clock source so we can get at the |
| 6160 | * display and the reference clock for VGA |
| 6161 | * hotplug / manual detection. |
| 6162 | */ |
| 6163 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6164 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6165 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 6166 | |
| 6167 | vlv_set_power_well(dev_priv, power_well, true); |
| 6168 | |
| 6169 | /* |
| 6170 | * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx - |
| 6171 | * 6. De-assert cmn_reset/side_reset. Same as VLV X0. |
| 6172 | * a. GUnit 0x2110 bit[0] set to 1 (def 0) |
| 6173 | * b. The other bits such as sfr settings / modesel may all |
| 6174 | * be set to 0. |
| 6175 | * |
| 6176 | * This should only be done on init and resume from S3 with |
| 6177 | * both PLLs disabled, or we risk losing DPIO and PLL |
| 6178 | * synchronization. |
| 6179 | */ |
| 6180 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST); |
| 6181 | } |
| 6182 | |
| 6183 | static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 6184 | struct i915_power_well *power_well) |
| 6185 | { |
| 6186 | struct drm_device *dev = dev_priv->dev; |
| 6187 | enum pipe pipe; |
| 6188 | |
| 6189 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6190 | |
| 6191 | for_each_pipe(pipe) |
| 6192 | assert_pll_disabled(dev_priv, pipe); |
| 6193 | |
| 6194 | /* Assert common reset */ |
| 6195 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST); |
| 6196 | |
| 6197 | vlv_set_power_well(dev_priv, power_well, false); |
| 6198 | } |
| 6199 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6200 | static void check_power_well_state(struct drm_i915_private *dev_priv, |
| 6201 | struct i915_power_well *power_well) |
| 6202 | { |
| 6203 | bool enabled = power_well->ops->is_enabled(dev_priv, power_well); |
| 6204 | |
| 6205 | if (power_well->always_on || !i915.disable_power_well) { |
| 6206 | if (!enabled) |
| 6207 | goto mismatch; |
| 6208 | |
| 6209 | return; |
| 6210 | } |
| 6211 | |
| 6212 | if (enabled != (power_well->count > 0)) |
| 6213 | goto mismatch; |
| 6214 | |
| 6215 | return; |
| 6216 | |
| 6217 | mismatch: |
| 6218 | WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n", |
| 6219 | power_well->name, power_well->always_on, enabled, |
| 6220 | power_well->count, i915.disable_power_well); |
| 6221 | } |
| 6222 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6223 | void intel_display_power_get(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6224 | enum intel_display_power_domain domain) |
| 6225 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6226 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6227 | struct i915_power_well *power_well; |
| 6228 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6229 | |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6230 | intel_runtime_pm_get(dev_priv); |
| 6231 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6232 | power_domains = &dev_priv->power_domains; |
| 6233 | |
| 6234 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6235 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6236 | for_each_power_well(i, power_well, BIT(domain), power_domains) { |
| 6237 | if (!power_well->count++) { |
| 6238 | DRM_DEBUG_KMS("enabling %s\n", power_well->name); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6239 | power_well->ops->enable(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6240 | power_well->hw_enabled = true; |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | check_power_well_state(dev_priv, power_well); |
| 6244 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6245 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6246 | power_domains->domain_use_count[domain]++; |
| 6247 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6248 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6249 | } |
| 6250 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6251 | void intel_display_power_put(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6252 | enum intel_display_power_domain domain) |
| 6253 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6254 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6255 | struct i915_power_well *power_well; |
| 6256 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6257 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6258 | power_domains = &dev_priv->power_domains; |
| 6259 | |
| 6260 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6261 | |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6262 | WARN_ON(!power_domains->domain_use_count[domain]); |
| 6263 | power_domains->domain_use_count[domain]--; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6264 | |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6265 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 6266 | WARN_ON(!power_well->count); |
| 6267 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6268 | if (!--power_well->count && i915.disable_power_well) { |
| 6269 | DRM_DEBUG_KMS("disabling %s\n", power_well->name); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6270 | power_well->hw_enabled = false; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6271 | power_well->ops->disable(dev_priv, power_well); |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6272 | } |
| 6273 | |
| 6274 | check_power_well_state(dev_priv, power_well); |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6275 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6276 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6277 | mutex_unlock(&power_domains->lock); |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6278 | |
| 6279 | intel_runtime_pm_put(dev_priv); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6280 | } |
| 6281 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6282 | static struct i915_power_domains *hsw_pwr; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6283 | |
| 6284 | /* Display audio driver power well request */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6285 | int i915_request_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6286 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6287 | struct drm_i915_private *dev_priv; |
| 6288 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6289 | if (!hsw_pwr) |
| 6290 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6291 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6292 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6293 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6294 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6295 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6296 | } |
| 6297 | EXPORT_SYMBOL_GPL(i915_request_power_well); |
| 6298 | |
| 6299 | /* Display audio driver power well release */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6300 | int i915_release_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6301 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6302 | struct drm_i915_private *dev_priv; |
| 6303 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6304 | if (!hsw_pwr) |
| 6305 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6306 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6307 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6308 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6309 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6310 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6311 | } |
| 6312 | EXPORT_SYMBOL_GPL(i915_release_power_well); |
| 6313 | |
Jani Nikula | c149dcb | 2014-07-04 10:00:37 +0800 | [diff] [blame] | 6314 | /* |
| 6315 | * Private interface for the audio driver to get CDCLK in kHz. |
| 6316 | * |
| 6317 | * Caller must request power well using i915_request_power_well() prior to |
| 6318 | * making the call. |
| 6319 | */ |
| 6320 | int i915_get_cdclk_freq(void) |
| 6321 | { |
| 6322 | struct drm_i915_private *dev_priv; |
| 6323 | |
| 6324 | if (!hsw_pwr) |
| 6325 | return -ENODEV; |
| 6326 | |
| 6327 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6328 | power_domains); |
| 6329 | |
| 6330 | return intel_ddi_get_cdclk_freq(dev_priv); |
| 6331 | } |
| 6332 | EXPORT_SYMBOL_GPL(i915_get_cdclk_freq); |
| 6333 | |
| 6334 | |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6335 | #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1) |
| 6336 | |
| 6337 | #define HSW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6338 | BIT(POWER_DOMAIN_PIPE_A) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6339 | BIT(POWER_DOMAIN_TRANSCODER_EDP) | \ |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6340 | BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \ |
| 6341 | BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \ |
| 6342 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6343 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6344 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6345 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6346 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6347 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6348 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6349 | BIT(POWER_DOMAIN_INIT)) |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6350 | #define HSW_DISPLAY_POWER_DOMAINS ( \ |
| 6351 | (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6352 | BIT(POWER_DOMAIN_INIT)) |
| 6353 | |
| 6354 | #define BDW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6355 | HSW_ALWAYS_ON_POWER_DOMAINS | \ |
| 6356 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER)) |
| 6357 | #define BDW_DISPLAY_POWER_DOMAINS ( \ |
| 6358 | (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6359 | BIT(POWER_DOMAIN_INIT)) |
| 6360 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6361 | #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT) |
| 6362 | #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK |
| 6363 | |
| 6364 | #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 6365 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6366 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6367 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6368 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6369 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
| 6370 | BIT(POWER_DOMAIN_INIT)) |
| 6371 | |
| 6372 | #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \ |
| 6373 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6374 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6375 | BIT(POWER_DOMAIN_INIT)) |
| 6376 | |
| 6377 | #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \ |
| 6378 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6379 | BIT(POWER_DOMAIN_INIT)) |
| 6380 | |
| 6381 | #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \ |
| 6382 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6383 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6384 | BIT(POWER_DOMAIN_INIT)) |
| 6385 | |
| 6386 | #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \ |
| 6387 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6388 | BIT(POWER_DOMAIN_INIT)) |
| 6389 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6390 | static const struct i915_power_well_ops i9xx_always_on_power_well_ops = { |
| 6391 | .sync_hw = i9xx_always_on_power_well_noop, |
| 6392 | .enable = i9xx_always_on_power_well_noop, |
| 6393 | .disable = i9xx_always_on_power_well_noop, |
| 6394 | .is_enabled = i9xx_always_on_power_well_enabled, |
| 6395 | }; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6396 | |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6397 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 6398 | { |
| 6399 | .name = "always-on", |
| 6400 | .always_on = 1, |
| 6401 | .domains = POWER_DOMAIN_MASK, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6402 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6403 | }, |
| 6404 | }; |
| 6405 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6406 | static const struct i915_power_well_ops hsw_power_well_ops = { |
| 6407 | .sync_hw = hsw_power_well_sync_hw, |
| 6408 | .enable = hsw_power_well_enable, |
| 6409 | .disable = hsw_power_well_disable, |
| 6410 | .is_enabled = hsw_power_well_enabled, |
| 6411 | }; |
| 6412 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6413 | static struct i915_power_well hsw_power_wells[] = { |
| 6414 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6415 | .name = "always-on", |
| 6416 | .always_on = 1, |
| 6417 | .domains = HSW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6418 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6419 | }, |
| 6420 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6421 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6422 | .domains = HSW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6423 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6424 | }, |
| 6425 | }; |
| 6426 | |
| 6427 | static struct i915_power_well bdw_power_wells[] = { |
| 6428 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6429 | .name = "always-on", |
| 6430 | .always_on = 1, |
| 6431 | .domains = BDW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6432 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6433 | }, |
| 6434 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6435 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6436 | .domains = BDW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6437 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6438 | }, |
| 6439 | }; |
| 6440 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6441 | static const struct i915_power_well_ops vlv_display_power_well_ops = { |
| 6442 | .sync_hw = vlv_power_well_sync_hw, |
| 6443 | .enable = vlv_display_power_well_enable, |
| 6444 | .disable = vlv_display_power_well_disable, |
| 6445 | .is_enabled = vlv_power_well_enabled, |
| 6446 | }; |
| 6447 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6448 | static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = { |
| 6449 | .sync_hw = vlv_power_well_sync_hw, |
| 6450 | .enable = vlv_dpio_cmn_power_well_enable, |
| 6451 | .disable = vlv_dpio_cmn_power_well_disable, |
| 6452 | .is_enabled = vlv_power_well_enabled, |
| 6453 | }; |
| 6454 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6455 | static const struct i915_power_well_ops vlv_dpio_power_well_ops = { |
| 6456 | .sync_hw = vlv_power_well_sync_hw, |
| 6457 | .enable = vlv_power_well_enable, |
| 6458 | .disable = vlv_power_well_disable, |
| 6459 | .is_enabled = vlv_power_well_enabled, |
| 6460 | }; |
| 6461 | |
| 6462 | static struct i915_power_well vlv_power_wells[] = { |
| 6463 | { |
| 6464 | .name = "always-on", |
| 6465 | .always_on = 1, |
| 6466 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 6467 | .ops = &i9xx_always_on_power_well_ops, |
| 6468 | }, |
| 6469 | { |
| 6470 | .name = "display", |
| 6471 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 6472 | .data = PUNIT_POWER_WELL_DISP2D, |
| 6473 | .ops = &vlv_display_power_well_ops, |
| 6474 | }, |
| 6475 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6476 | .name = "dpio-tx-b-01", |
| 6477 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6478 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6479 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6480 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6481 | .ops = &vlv_dpio_power_well_ops, |
| 6482 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 6483 | }, |
| 6484 | { |
| 6485 | .name = "dpio-tx-b-23", |
| 6486 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6487 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6488 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6489 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6490 | .ops = &vlv_dpio_power_well_ops, |
| 6491 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 6492 | }, |
| 6493 | { |
| 6494 | .name = "dpio-tx-c-01", |
| 6495 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6496 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6497 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6498 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6499 | .ops = &vlv_dpio_power_well_ops, |
| 6500 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 6501 | }, |
| 6502 | { |
| 6503 | .name = "dpio-tx-c-23", |
| 6504 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6505 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6506 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6507 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6508 | .ops = &vlv_dpio_power_well_ops, |
| 6509 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 6510 | }, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 6511 | { |
| 6512 | .name = "dpio-common", |
| 6513 | .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS, |
| 6514 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6515 | .ops = &vlv_dpio_cmn_power_well_ops, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 6516 | }, |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6517 | }; |
| 6518 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6519 | static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv, |
| 6520 | enum punit_power_well power_well_id) |
| 6521 | { |
| 6522 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6523 | struct i915_power_well *power_well; |
| 6524 | int i; |
| 6525 | |
| 6526 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
| 6527 | if (power_well->data == power_well_id) |
| 6528 | return power_well; |
| 6529 | } |
| 6530 | |
| 6531 | return NULL; |
| 6532 | } |
| 6533 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6534 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 6535 | (power_domains)->power_wells = (__power_wells); \ |
| 6536 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 6537 | }) |
| 6538 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6539 | int intel_power_domains_init(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6540 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6541 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6542 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6543 | mutex_init(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6544 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6545 | /* |
| 6546 | * The enabling order will be from lower to higher indexed wells, |
| 6547 | * the disabling order is reversed. |
| 6548 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6549 | if (IS_HASWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6550 | set_power_wells(power_domains, hsw_power_wells); |
| 6551 | hsw_pwr = power_domains; |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6552 | } else if (IS_BROADWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6553 | set_power_wells(power_domains, bdw_power_wells); |
| 6554 | hsw_pwr = power_domains; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6555 | } else if (IS_VALLEYVIEW(dev_priv->dev)) { |
| 6556 | set_power_wells(power_domains, vlv_power_wells); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6557 | } else { |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6558 | set_power_wells(power_domains, i9xx_always_on_power_well); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6559 | } |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6560 | |
| 6561 | return 0; |
| 6562 | } |
| 6563 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6564 | void intel_power_domains_remove(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6565 | { |
| 6566 | hsw_pwr = NULL; |
| 6567 | } |
| 6568 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6569 | static void intel_power_domains_resume(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 6570 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6571 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6572 | struct i915_power_well *power_well; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6573 | int i; |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 6574 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6575 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6576 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6577 | power_well->ops->sync_hw(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6578 | power_well->hw_enabled = power_well->ops->is_enabled(dev_priv, |
| 6579 | power_well); |
| 6580 | } |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6581 | mutex_unlock(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6582 | } |
| 6583 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6584 | static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv) |
| 6585 | { |
| 6586 | struct i915_power_well *cmn = |
| 6587 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6588 | struct i915_power_well *disp2d = |
| 6589 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D); |
| 6590 | |
| 6591 | /* nothing to do if common lane is already off */ |
| 6592 | if (!cmn->ops->is_enabled(dev_priv, cmn)) |
| 6593 | return; |
| 6594 | |
| 6595 | /* If the display might be already active skip this */ |
| 6596 | if (disp2d->ops->is_enabled(dev_priv, disp2d) && |
| 6597 | I915_READ(DPIO_CTL) & DPIO_CMNRST) |
| 6598 | return; |
| 6599 | |
| 6600 | DRM_DEBUG_KMS("toggling display PHY side reset\n"); |
| 6601 | |
| 6602 | /* cmnlane needs DPLL registers */ |
| 6603 | disp2d->ops->enable(dev_priv, disp2d); |
| 6604 | |
| 6605 | /* |
| 6606 | * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx: |
| 6607 | * Need to assert and de-assert PHY SB reset by gating the |
| 6608 | * common lane power, then un-gating it. |
| 6609 | * Simply ungating isn't enough to reset the PHY enough to get |
| 6610 | * ports and lanes running. |
| 6611 | */ |
| 6612 | cmn->ops->disable(dev_priv, cmn); |
| 6613 | } |
| 6614 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6615 | void intel_power_domains_init_hw(struct drm_i915_private *dev_priv) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6616 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6617 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6618 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6619 | |
| 6620 | power_domains->initializing = true; |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6621 | |
| 6622 | if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
| 6623 | mutex_lock(&power_domains->lock); |
| 6624 | vlv_cmnlane_wa(dev_priv); |
| 6625 | mutex_unlock(&power_domains->lock); |
| 6626 | } |
| 6627 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6628 | /* For now, we need the power well to be always enabled. */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6629 | intel_display_set_init_power(dev_priv, true); |
| 6630 | intel_power_domains_resume(dev_priv); |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6631 | power_domains->initializing = false; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6632 | } |
| 6633 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6634 | void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv) |
| 6635 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 6636 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6637 | } |
| 6638 | |
| 6639 | void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv) |
| 6640 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 6641 | intel_runtime_pm_put(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6642 | } |
| 6643 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6644 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 6645 | { |
| 6646 | struct drm_device *dev = dev_priv->dev; |
| 6647 | struct device *device = &dev->pdev->dev; |
| 6648 | |
| 6649 | if (!HAS_RUNTIME_PM(dev)) |
| 6650 | return; |
| 6651 | |
| 6652 | pm_runtime_get_sync(device); |
| 6653 | WARN(dev_priv->pm.suspended, "Device still suspended.\n"); |
| 6654 | } |
| 6655 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6656 | void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv) |
| 6657 | { |
| 6658 | struct drm_device *dev = dev_priv->dev; |
| 6659 | struct device *device = &dev->pdev->dev; |
| 6660 | |
| 6661 | if (!HAS_RUNTIME_PM(dev)) |
| 6662 | return; |
| 6663 | |
| 6664 | WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n"); |
| 6665 | pm_runtime_get_noresume(device); |
| 6666 | } |
| 6667 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6668 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 6669 | { |
| 6670 | struct drm_device *dev = dev_priv->dev; |
| 6671 | struct device *device = &dev->pdev->dev; |
| 6672 | |
| 6673 | if (!HAS_RUNTIME_PM(dev)) |
| 6674 | return; |
| 6675 | |
| 6676 | pm_runtime_mark_last_busy(device); |
| 6677 | pm_runtime_put_autosuspend(device); |
| 6678 | } |
| 6679 | |
| 6680 | void intel_init_runtime_pm(struct drm_i915_private *dev_priv) |
| 6681 | { |
| 6682 | struct drm_device *dev = dev_priv->dev; |
| 6683 | struct device *device = &dev->pdev->dev; |
| 6684 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6685 | if (!HAS_RUNTIME_PM(dev)) |
| 6686 | return; |
| 6687 | |
| 6688 | pm_runtime_set_active(device); |
| 6689 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 6690 | /* |
| 6691 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 6692 | * requirement. |
| 6693 | */ |
| 6694 | if (!intel_enable_rc6(dev)) { |
| 6695 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 6696 | return; |
| 6697 | } |
| 6698 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6699 | pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */ |
| 6700 | pm_runtime_mark_last_busy(device); |
| 6701 | pm_runtime_use_autosuspend(device); |
Paulo Zanoni | ba0239e | 2014-03-07 20:08:07 -0300 | [diff] [blame] | 6702 | |
| 6703 | pm_runtime_put_autosuspend(device); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | void intel_fini_runtime_pm(struct drm_i915_private *dev_priv) |
| 6707 | { |
| 6708 | struct drm_device *dev = dev_priv->dev; |
| 6709 | struct device *device = &dev->pdev->dev; |
| 6710 | |
| 6711 | if (!HAS_RUNTIME_PM(dev)) |
| 6712 | return; |
| 6713 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 6714 | if (!intel_enable_rc6(dev)) |
| 6715 | return; |
| 6716 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6717 | /* Make sure we're not suspended first. */ |
| 6718 | pm_runtime_get_sync(device); |
| 6719 | pm_runtime_disable(device); |
| 6720 | } |
| 6721 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6722 | /* Set up chip specific power management-related functions */ |
| 6723 | void intel_init_pm(struct drm_device *dev) |
| 6724 | { |
| 6725 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6726 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 6727 | if (HAS_FBC(dev)) { |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6728 | if (INTEL_INFO(dev)->gen >= 7) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6729 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6730 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 6731 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6732 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 6733 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 6734 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6735 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6736 | } else if (IS_GM45(dev)) { |
| 6737 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 6738 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 6739 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6740 | } else { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6741 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 6742 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 6743 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 6744 | |
| 6745 | /* This value was pulled out of someone's hat */ |
| 6746 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6747 | } |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6748 | } |
| 6749 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6750 | /* For cxsr */ |
| 6751 | if (IS_PINEVIEW(dev)) |
| 6752 | i915_pineview_get_mem_freq(dev); |
| 6753 | else if (IS_GEN5(dev)) |
| 6754 | i915_ironlake_get_mem_freq(dev); |
| 6755 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6756 | /* For FIFO watermark updates */ |
| 6757 | if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6758 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6759 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6760 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6761 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6762 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6763 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6764 | dev_priv->display.update_wm = ilk_update_wm; |
| 6765 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6766 | } else { |
| 6767 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6768 | "Disable CxSR\n"); |
| 6769 | } |
| 6770 | |
| 6771 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6772 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6773 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6774 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6775 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6776 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6777 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6778 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6779 | else if (INTEL_INFO(dev)->gen == 8) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6780 | dev_priv->display.init_clock_gating = gen8_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6781 | } else if (IS_CHERRYVIEW(dev)) { |
| 6782 | dev_priv->display.update_wm = valleyview_update_wm; |
| 6783 | dev_priv->display.init_clock_gating = |
| 6784 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6785 | } else if (IS_VALLEYVIEW(dev)) { |
| 6786 | dev_priv->display.update_wm = valleyview_update_wm; |
| 6787 | dev_priv->display.init_clock_gating = |
| 6788 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6789 | } else if (IS_PINEVIEW(dev)) { |
| 6790 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6791 | dev_priv->is_ddr3, |
| 6792 | dev_priv->fsb_freq, |
| 6793 | dev_priv->mem_freq)) { |
| 6794 | DRM_INFO("failed to find known CxSR latency " |
| 6795 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6796 | "disabling CxSR\n", |
| 6797 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6798 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6799 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6800 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6801 | dev_priv->display.update_wm = NULL; |
| 6802 | } else |
| 6803 | dev_priv->display.update_wm = pineview_update_wm; |
| 6804 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6805 | } else if (IS_G4X(dev)) { |
| 6806 | dev_priv->display.update_wm = g4x_update_wm; |
| 6807 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6808 | } else if (IS_GEN4(dev)) { |
| 6809 | dev_priv->display.update_wm = i965_update_wm; |
| 6810 | if (IS_CRESTLINE(dev)) |
| 6811 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6812 | else if (IS_BROADWATER(dev)) |
| 6813 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6814 | } else if (IS_GEN3(dev)) { |
| 6815 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6816 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6817 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6818 | } else if (IS_GEN2(dev)) { |
| 6819 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6820 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6821 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6822 | } else { |
| 6823 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6824 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6825 | } |
| 6826 | |
| 6827 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6828 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6829 | else |
| 6830 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6831 | } else { |
| 6832 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6833 | } |
| 6834 | } |
| 6835 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6836 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 6837 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6838 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6839 | |
| 6840 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6841 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6842 | return -EAGAIN; |
| 6843 | } |
| 6844 | |
| 6845 | I915_WRITE(GEN6_PCODE_DATA, *val); |
| 6846 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6847 | |
| 6848 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6849 | 500)) { |
| 6850 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6851 | return -ETIMEDOUT; |
| 6852 | } |
| 6853 | |
| 6854 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6855 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6856 | |
| 6857 | return 0; |
| 6858 | } |
| 6859 | |
| 6860 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 6861 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6862 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6863 | |
| 6864 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6865 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6866 | return -EAGAIN; |
| 6867 | } |
| 6868 | |
| 6869 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6870 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6871 | |
| 6872 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6873 | 500)) { |
| 6874 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6875 | return -ETIMEDOUT; |
| 6876 | } |
| 6877 | |
| 6878 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6879 | |
| 6880 | return 0; |
| 6881 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6882 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6883 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6884 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6885 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6886 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6887 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6888 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6889 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6890 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6891 | break; |
| 6892 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6893 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6894 | break; |
| 6895 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6896 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6897 | break; |
| 6898 | default: |
| 6899 | return -1; |
| 6900 | } |
| 6901 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6902 | 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] | 6903 | } |
| 6904 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6905 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6906 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6907 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6908 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6909 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6910 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6911 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6912 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6913 | break; |
| 6914 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6915 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6916 | break; |
| 6917 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6918 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6919 | break; |
| 6920 | default: |
| 6921 | return -1; |
| 6922 | } |
| 6923 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6924 | 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] | 6925 | } |
| 6926 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6927 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6928 | { |
| 6929 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6930 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6931 | mutex_init(&dev_priv->rps.hw_lock); |
| 6932 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6933 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6934 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6935 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6936 | dev_priv->pm.suspended = false; |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6937 | dev_priv->pm.irqs_disabled = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6938 | } |