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; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 96 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 97 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 98 | int cfb_pitch; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 99 | int i; |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 100 | u32 fbc_ctl; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 101 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 102 | cfb_pitch = dev_priv->fbc.size / FBC_LL_SIZE; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 103 | if (fb->pitches[0] < cfb_pitch) |
| 104 | cfb_pitch = fb->pitches[0]; |
| 105 | |
Ville Syrjälä | 42a430f | 2013-11-28 17:29:56 +0200 | [diff] [blame] | 106 | /* FBC_CTL wants 32B or 64B units */ |
| 107 | if (IS_GEN2(dev)) |
| 108 | cfb_pitch = (cfb_pitch / 32) - 1; |
| 109 | else |
| 110 | cfb_pitch = (cfb_pitch / 64) - 1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 111 | |
| 112 | /* Clear old tags */ |
| 113 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 114 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 115 | |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 116 | if (IS_GEN4(dev)) { |
| 117 | u32 fbc_ctl2; |
| 118 | |
| 119 | /* Set it up... */ |
| 120 | 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] | 121 | fbc_ctl2 |= FBC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 122 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 123 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 124 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 125 | |
| 126 | /* enable it... */ |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 127 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 128 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 129 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 130 | if (IS_I945GM(dev)) |
| 131 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 132 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 133 | fbc_ctl |= obj->fence_reg; |
| 134 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 135 | |
Ville Syrjälä | 5cd5410 | 2014-01-23 16:49:16 +0200 | [diff] [blame] | 136 | 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] | 137 | cfb_pitch, crtc->y, plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 138 | } |
| 139 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 140 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 141 | { |
| 142 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 143 | |
| 144 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 145 | } |
| 146 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 147 | static void g4x_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 148 | { |
| 149 | struct drm_device *dev = crtc->dev; |
| 150 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 151 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 152 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 153 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 154 | u32 dpfc_ctl; |
| 155 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 156 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane) | DPFC_SR_EN; |
| 157 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 158 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 159 | else |
| 160 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 161 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 162 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 163 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 164 | |
| 165 | /* enable it... */ |
Ville Syrjälä | fe74c1a | 2014-01-23 16:49:13 +0200 | [diff] [blame] | 166 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 167 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 168 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 169 | } |
| 170 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 171 | static void g4x_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 172 | { |
| 173 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 174 | u32 dpfc_ctl; |
| 175 | |
| 176 | /* Disable compression */ |
| 177 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 178 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 179 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 180 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 181 | |
| 182 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 183 | } |
| 184 | } |
| 185 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 186 | static bool g4x_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 187 | { |
| 188 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 189 | |
| 190 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 191 | } |
| 192 | |
| 193 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 194 | { |
| 195 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 196 | u32 blt_ecoskpd; |
| 197 | |
| 198 | /* Make sure blitter notifies FBC of writes */ |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 199 | |
| 200 | /* Blitter is part of Media powerwell on VLV. No impact of |
| 201 | * his param in other platforms for now */ |
| 202 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 203 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 204 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 205 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 206 | GEN6_BLITTER_LOCK_SHIFT; |
| 207 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 208 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 209 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 210 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 211 | GEN6_BLITTER_LOCK_SHIFT); |
| 212 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 213 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 214 | |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 215 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_MEDIA); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 216 | } |
| 217 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 218 | static void ironlake_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 219 | { |
| 220 | struct drm_device *dev = crtc->dev; |
| 221 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 222 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 223 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 224 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 225 | u32 dpfc_ctl; |
| 226 | |
Ville Syrjälä | 46f3dab | 2014-01-23 16:49:14 +0200 | [diff] [blame] | 227 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 228 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 229 | dev_priv->fbc.threshold++; |
| 230 | |
| 231 | switch (dev_priv->fbc.threshold) { |
| 232 | case 4: |
| 233 | case 3: |
| 234 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 235 | break; |
| 236 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 237 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 238 | break; |
| 239 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 240 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 241 | break; |
| 242 | } |
Ville Syrjälä | d629336 | 2013-11-21 21:29:45 +0200 | [diff] [blame] | 243 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
| 244 | if (IS_GEN5(dev)) |
| 245 | dpfc_ctl |= obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 246 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 247 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 248 | 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] | 249 | /* enable it... */ |
| 250 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 251 | |
| 252 | if (IS_GEN6(dev)) { |
| 253 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 254 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 255 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 256 | sandybridge_blit_fbc_update(dev); |
| 257 | } |
| 258 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 259 | 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] | 260 | } |
| 261 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 262 | static void ironlake_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 263 | { |
| 264 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 265 | u32 dpfc_ctl; |
| 266 | |
| 267 | /* Disable compression */ |
| 268 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 269 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 270 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 271 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 272 | |
| 273 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 274 | } |
| 275 | } |
| 276 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 277 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 278 | { |
| 279 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 280 | |
| 281 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 282 | } |
| 283 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 284 | static void gen7_enable_fbc(struct drm_crtc *crtc) |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 285 | { |
| 286 | struct drm_device *dev = crtc->dev; |
| 287 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 288 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 289 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 290 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 291 | u32 dpfc_ctl; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 292 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 293 | dpfc_ctl = IVB_DPFC_CTL_PLANE(intel_crtc->plane); |
| 294 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 295 | dev_priv->fbc.threshold++; |
| 296 | |
| 297 | switch (dev_priv->fbc.threshold) { |
| 298 | case 4: |
| 299 | case 3: |
| 300 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 301 | break; |
| 302 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 303 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 304 | break; |
| 305 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 306 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 307 | break; |
| 308 | } |
| 309 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 310 | dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN; |
| 311 | |
Rodrigo Vivi | da46f93 | 2014-08-01 02:04:45 -0700 | [diff] [blame] | 312 | if (dev_priv->fbc.false_color) |
| 313 | dpfc_ctl |= FBC_CTL_FALSE_COLOR; |
| 314 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 315 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 316 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 317 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 318 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 319 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 320 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 321 | ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 322 | } else { |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 323 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 324 | I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe), |
| 325 | I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) | |
| 326 | HSW_FBCQ_DIS); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 327 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 328 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 329 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 330 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 331 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 332 | |
| 333 | sandybridge_blit_fbc_update(dev); |
| 334 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 335 | 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] | 336 | } |
| 337 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 338 | bool intel_fbc_enabled(struct drm_device *dev) |
| 339 | { |
| 340 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 341 | |
| 342 | if (!dev_priv->display.fbc_enabled) |
| 343 | return false; |
| 344 | |
| 345 | return dev_priv->display.fbc_enabled(dev); |
| 346 | } |
| 347 | |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 348 | void gen8_fbc_sw_flush(struct drm_device *dev, u32 value) |
| 349 | { |
| 350 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 351 | |
| 352 | if (!IS_GEN8(dev)) |
| 353 | return; |
| 354 | |
| 355 | I915_WRITE(MSG_FBC_REND_STATE, value); |
| 356 | } |
| 357 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 358 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 359 | { |
| 360 | struct intel_fbc_work *work = |
| 361 | container_of(to_delayed_work(__work), |
| 362 | struct intel_fbc_work, work); |
| 363 | struct drm_device *dev = work->crtc->dev; |
| 364 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 365 | |
| 366 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 367 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 368 | /* Double check that we haven't switched fb without cancelling |
| 369 | * the prior work. |
| 370 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 371 | if (work->crtc->primary->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 372 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 373 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 374 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 375 | dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id; |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 376 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 377 | } |
| 378 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 379 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 380 | } |
| 381 | mutex_unlock(&dev->struct_mutex); |
| 382 | |
| 383 | kfree(work); |
| 384 | } |
| 385 | |
| 386 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 387 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 388 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 389 | return; |
| 390 | |
| 391 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 392 | |
| 393 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 394 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 395 | * entirely asynchronously. |
| 396 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 397 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 398 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 399 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 400 | |
| 401 | /* Mark the work as no longer wanted so that if it does |
| 402 | * wake-up (because the work was already running and waiting |
| 403 | * for our mutex), it will discover that is no longer |
| 404 | * necessary to run. |
| 405 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 406 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 407 | } |
| 408 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 409 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 410 | { |
| 411 | struct intel_fbc_work *work; |
| 412 | struct drm_device *dev = crtc->dev; |
| 413 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 414 | |
| 415 | if (!dev_priv->display.enable_fbc) |
| 416 | return; |
| 417 | |
| 418 | intel_cancel_fbc_work(dev_priv); |
| 419 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 420 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 421 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 422 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 423 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 424 | return; |
| 425 | } |
| 426 | |
| 427 | work->crtc = crtc; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 428 | work->fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 429 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 430 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 431 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 432 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 433 | /* Delay the actual enabling to let pageflipping cease and the |
| 434 | * display to settle before starting the compression. Note that |
| 435 | * this delay also serves a second purpose: it allows for a |
| 436 | * vblank to pass after disabling the FBC before we attempt |
| 437 | * to modify the control registers. |
| 438 | * |
| 439 | * A more complicated solution would involve tracking vblanks |
| 440 | * following the termination of the page-flipping sequence |
| 441 | * and indeed performing the enable as a co-routine and not |
| 442 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 443 | * |
| 444 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 445 | */ |
| 446 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 447 | } |
| 448 | |
| 449 | void intel_disable_fbc(struct drm_device *dev) |
| 450 | { |
| 451 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 452 | |
| 453 | intel_cancel_fbc_work(dev_priv); |
| 454 | |
| 455 | if (!dev_priv->display.disable_fbc) |
| 456 | return; |
| 457 | |
| 458 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 459 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 460 | } |
| 461 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 462 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 463 | enum no_fbc_reason reason) |
| 464 | { |
| 465 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 466 | return false; |
| 467 | |
| 468 | dev_priv->fbc.no_fbc_reason = reason; |
| 469 | return true; |
| 470 | } |
| 471 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 472 | /** |
| 473 | * intel_update_fbc - enable/disable FBC as needed |
| 474 | * @dev: the drm_device |
| 475 | * |
| 476 | * Set up the framebuffer compression hardware at mode set time. We |
| 477 | * enable it if possible: |
| 478 | * - plane A only (on pre-965) |
| 479 | * - no pixel mulitply/line duplication |
| 480 | * - no alpha buffer discard |
| 481 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 482 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 483 | * |
| 484 | * We can't assume that any compression will take place (worst case), |
| 485 | * so the compressed buffer has to be the same size as the uncompressed |
| 486 | * one. It also must reside (along with the line length buffer) in |
| 487 | * stolen memory. |
| 488 | * |
| 489 | * We need to enable/disable FBC on a global basis. |
| 490 | */ |
| 491 | void intel_update_fbc(struct drm_device *dev) |
| 492 | { |
| 493 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 494 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 495 | struct intel_crtc *intel_crtc; |
| 496 | struct drm_framebuffer *fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 497 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 498 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 499 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 500 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 501 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 502 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 503 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 504 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 505 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 506 | if (!i915.powersave) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 507 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 508 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 509 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 510 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 511 | |
| 512 | /* |
| 513 | * If FBC is already on, we just have to verify that we can |
| 514 | * keep it that way... |
| 515 | * Need to disable if: |
| 516 | * - more than one pipe is active |
| 517 | * - changing FBC params (stride, fence, mode) |
| 518 | * - new fb is too large to fit in compressed buffer |
| 519 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 520 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 521 | for_each_crtc(dev, tmp_crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 522 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 523 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 524 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 525 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 526 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 527 | goto out_disable; |
| 528 | } |
| 529 | crtc = tmp_crtc; |
| 530 | } |
| 531 | } |
| 532 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 533 | if (!crtc || crtc->primary->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 534 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 535 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 536 | goto out_disable; |
| 537 | } |
| 538 | |
| 539 | intel_crtc = to_intel_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 540 | fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 541 | obj = intel_fb_obj(fb); |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 542 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 543 | |
Chris Wilson | 0368920 | 2014-06-06 10:37:11 +0100 | [diff] [blame] | 544 | if (i915.enable_fbc < 0) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 545 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 546 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 547 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 548 | } |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 549 | if (!i915.enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 550 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 551 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 552 | goto out_disable; |
| 553 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 554 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 555 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 556 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 557 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 558 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 559 | goto out_disable; |
| 560 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 561 | |
Daisy Sun | 032843a | 2014-06-16 15:48:18 -0700 | [diff] [blame] | 562 | if (INTEL_INFO(dev)->gen >= 8 || IS_HASWELL(dev)) { |
| 563 | max_width = 4096; |
| 564 | max_height = 4096; |
| 565 | } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 566 | max_width = 4096; |
| 567 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 568 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 569 | max_width = 2048; |
| 570 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 571 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 572 | if (intel_crtc->config.pipe_src_w > max_width || |
| 573 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 574 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 575 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 576 | goto out_disable; |
| 577 | } |
Ben Widawsky | 8f94d24 | 2014-02-20 16:01:20 -0800 | [diff] [blame] | 578 | if ((INTEL_INFO(dev)->gen < 4 || HAS_DDI(dev)) && |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 579 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 580 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 581 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 582 | goto out_disable; |
| 583 | } |
| 584 | |
| 585 | /* The use of a CPU fence is mandatory in order to detect writes |
| 586 | * by the CPU to the scanout and trigger updates to the FBC. |
| 587 | */ |
| 588 | if (obj->tiling_mode != I915_TILING_X || |
| 589 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 590 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 591 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 592 | goto out_disable; |
| 593 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 594 | if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
| 595 | to_intel_plane(crtc->primary)->rotation != BIT(DRM_ROTATE_0)) { |
| 596 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 597 | DRM_DEBUG_KMS("Rotation unsupported, disabling\n"); |
| 598 | goto out_disable; |
| 599 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 600 | |
| 601 | /* If the kernel debugger is active, always disable compression */ |
| 602 | if (in_dbg_master()) |
| 603 | goto out_disable; |
| 604 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 605 | if (i915_gem_stolen_setup_compression(dev, obj->base.size, |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 606 | drm_format_plane_cpp(fb->pixel_format, 0))) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 607 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 608 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 609 | goto out_disable; |
| 610 | } |
| 611 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 612 | /* If the scanout has not changed, don't modify the FBC settings. |
| 613 | * Note that we make the fundamental assumption that the fb->obj |
| 614 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 615 | * without first being decoupled from the scanout and FBC disabled. |
| 616 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 617 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 618 | dev_priv->fbc.fb_id == fb->base.id && |
| 619 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 620 | return; |
| 621 | |
| 622 | if (intel_fbc_enabled(dev)) { |
| 623 | /* We update FBC along two paths, after changing fb/crtc |
| 624 | * configuration (modeswitching) and after page-flipping |
| 625 | * finishes. For the latter, we know that not only did |
| 626 | * we disable the FBC at the start of the page-flip |
| 627 | * sequence, but also more than one vblank has passed. |
| 628 | * |
| 629 | * For the former case of modeswitching, it is possible |
| 630 | * to switch between two FBC valid configurations |
| 631 | * instantaneously so we do need to disable the FBC |
| 632 | * before we can modify its control registers. We also |
| 633 | * have to wait for the next vblank for that to take |
| 634 | * effect. However, since we delay enabling FBC we can |
| 635 | * assume that a vblank has passed since disabling and |
| 636 | * that we can safely alter the registers in the deferred |
| 637 | * callback. |
| 638 | * |
| 639 | * In the scenario that we go from a valid to invalid |
| 640 | * and then back to valid FBC configuration we have |
| 641 | * no strict enforcement that a vblank occurred since |
| 642 | * disabling the FBC. However, along all current pipe |
| 643 | * disabling paths we do need to wait for a vblank at |
| 644 | * some point. And we wait before enabling FBC anyway. |
| 645 | */ |
| 646 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 647 | intel_disable_fbc(dev); |
| 648 | } |
| 649 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 650 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 651 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 652 | return; |
| 653 | |
| 654 | out_disable: |
| 655 | /* Multiple disables should be harmless */ |
| 656 | if (intel_fbc_enabled(dev)) { |
| 657 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 658 | intel_disable_fbc(dev); |
| 659 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 660 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 661 | } |
| 662 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 663 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 664 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 665 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 666 | u32 tmp; |
| 667 | |
| 668 | tmp = I915_READ(CLKCFG); |
| 669 | |
| 670 | switch (tmp & CLKCFG_FSB_MASK) { |
| 671 | case CLKCFG_FSB_533: |
| 672 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 673 | break; |
| 674 | case CLKCFG_FSB_800: |
| 675 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 676 | break; |
| 677 | case CLKCFG_FSB_667: |
| 678 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 679 | break; |
| 680 | case CLKCFG_FSB_400: |
| 681 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 682 | break; |
| 683 | } |
| 684 | |
| 685 | switch (tmp & CLKCFG_MEM_MASK) { |
| 686 | case CLKCFG_MEM_533: |
| 687 | dev_priv->mem_freq = 533; |
| 688 | break; |
| 689 | case CLKCFG_MEM_667: |
| 690 | dev_priv->mem_freq = 667; |
| 691 | break; |
| 692 | case CLKCFG_MEM_800: |
| 693 | dev_priv->mem_freq = 800; |
| 694 | break; |
| 695 | } |
| 696 | |
| 697 | /* detect pineview DDR3 setting */ |
| 698 | tmp = I915_READ(CSHRDDR3CTL); |
| 699 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 700 | } |
| 701 | |
| 702 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 703 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 704 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 705 | u16 ddrpll, csipll; |
| 706 | |
| 707 | ddrpll = I915_READ16(DDRMPLL1); |
| 708 | csipll = I915_READ16(CSIPLL0); |
| 709 | |
| 710 | switch (ddrpll & 0xff) { |
| 711 | case 0xc: |
| 712 | dev_priv->mem_freq = 800; |
| 713 | break; |
| 714 | case 0x10: |
| 715 | dev_priv->mem_freq = 1066; |
| 716 | break; |
| 717 | case 0x14: |
| 718 | dev_priv->mem_freq = 1333; |
| 719 | break; |
| 720 | case 0x18: |
| 721 | dev_priv->mem_freq = 1600; |
| 722 | break; |
| 723 | default: |
| 724 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 725 | ddrpll & 0xff); |
| 726 | dev_priv->mem_freq = 0; |
| 727 | break; |
| 728 | } |
| 729 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 730 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 731 | |
| 732 | switch (csipll & 0x3ff) { |
| 733 | case 0x00c: |
| 734 | dev_priv->fsb_freq = 3200; |
| 735 | break; |
| 736 | case 0x00e: |
| 737 | dev_priv->fsb_freq = 3733; |
| 738 | break; |
| 739 | case 0x010: |
| 740 | dev_priv->fsb_freq = 4266; |
| 741 | break; |
| 742 | case 0x012: |
| 743 | dev_priv->fsb_freq = 4800; |
| 744 | break; |
| 745 | case 0x014: |
| 746 | dev_priv->fsb_freq = 5333; |
| 747 | break; |
| 748 | case 0x016: |
| 749 | dev_priv->fsb_freq = 5866; |
| 750 | break; |
| 751 | case 0x018: |
| 752 | dev_priv->fsb_freq = 6400; |
| 753 | break; |
| 754 | default: |
| 755 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 756 | csipll & 0x3ff); |
| 757 | dev_priv->fsb_freq = 0; |
| 758 | break; |
| 759 | } |
| 760 | |
| 761 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 762 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 763 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 764 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 765 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 766 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 770 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 771 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 772 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 773 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 774 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 775 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 776 | |
| 777 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 778 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 779 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 780 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 781 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 782 | |
| 783 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 784 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 785 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 786 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 787 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 788 | |
| 789 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 790 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 791 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 792 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 793 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 794 | |
| 795 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 796 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 797 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 798 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 799 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 800 | |
| 801 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 802 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 803 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 804 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 805 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 806 | }; |
| 807 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 808 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 809 | int is_ddr3, |
| 810 | int fsb, |
| 811 | int mem) |
| 812 | { |
| 813 | const struct cxsr_latency *latency; |
| 814 | int i; |
| 815 | |
| 816 | if (fsb == 0 || mem == 0) |
| 817 | return NULL; |
| 818 | |
| 819 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 820 | latency = &cxsr_latency_table[i]; |
| 821 | if (is_desktop == latency->is_desktop && |
| 822 | is_ddr3 == latency->is_ddr3 && |
| 823 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 824 | return latency; |
| 825 | } |
| 826 | |
| 827 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 828 | |
| 829 | return NULL; |
| 830 | } |
| 831 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 832 | 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] | 833 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 834 | struct drm_device *dev = dev_priv->dev; |
| 835 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 836 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 837 | if (IS_VALLEYVIEW(dev)) { |
| 838 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 839 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 840 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 841 | } else if (IS_PINEVIEW(dev)) { |
| 842 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 843 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 844 | I915_WRITE(DSPFW3, val); |
| 845 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 846 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 847 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 848 | I915_WRITE(FW_BLC_SELF, val); |
| 849 | } else if (IS_I915GM(dev)) { |
| 850 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 851 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 852 | I915_WRITE(INSTPM, val); |
| 853 | } else { |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 858 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /* |
| 862 | * Latency for FIFO fetches is dependent on several factors: |
| 863 | * - memory configuration (speed, channels) |
| 864 | * - chipset |
| 865 | * - current MCH state |
| 866 | * It can be fairly high in some situations, so here we assume a fairly |
| 867 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 868 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 869 | * and power consumption (set it too low to save power and we might see |
| 870 | * FIFO underruns and display "flicker"). |
| 871 | * |
| 872 | * A value of 5us seems to be a good balance; safe for very low end |
| 873 | * platforms but not overly aggressive on lower latency configs. |
| 874 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 875 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 876 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 877 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 878 | { |
| 879 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 880 | uint32_t dsparb = I915_READ(DSPARB); |
| 881 | int size; |
| 882 | |
| 883 | size = dsparb & 0x7f; |
| 884 | if (plane) |
| 885 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 886 | |
| 887 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 888 | plane ? "B" : "A", size); |
| 889 | |
| 890 | return size; |
| 891 | } |
| 892 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 893 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 894 | { |
| 895 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 896 | uint32_t dsparb = I915_READ(DSPARB); |
| 897 | int size; |
| 898 | |
| 899 | size = dsparb & 0x1ff; |
| 900 | if (plane) |
| 901 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 902 | size >>= 1; /* Convert to cachelines */ |
| 903 | |
| 904 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 905 | plane ? "B" : "A", size); |
| 906 | |
| 907 | return size; |
| 908 | } |
| 909 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 910 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 911 | { |
| 912 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 913 | uint32_t dsparb = I915_READ(DSPARB); |
| 914 | int size; |
| 915 | |
| 916 | size = dsparb & 0x7f; |
| 917 | size >>= 2; /* Convert to cachelines */ |
| 918 | |
| 919 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 920 | plane ? "B" : "A", |
| 921 | size); |
| 922 | |
| 923 | return size; |
| 924 | } |
| 925 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 926 | /* Pineview has different values for various configs */ |
| 927 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 928 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 929 | .max_wm = PINEVIEW_MAX_WM, |
| 930 | .default_wm = PINEVIEW_DFT_WM, |
| 931 | .guard_size = PINEVIEW_GUARD_WM, |
| 932 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 933 | }; |
| 934 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 935 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 936 | .max_wm = PINEVIEW_MAX_WM, |
| 937 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 938 | .guard_size = PINEVIEW_GUARD_WM, |
| 939 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 940 | }; |
| 941 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 942 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 943 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 944 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 945 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 946 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 947 | }; |
| 948 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 949 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 950 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 951 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 952 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 953 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 954 | }; |
| 955 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 956 | .fifo_size = G4X_FIFO_SIZE, |
| 957 | .max_wm = G4X_MAX_WM, |
| 958 | .default_wm = G4X_MAX_WM, |
| 959 | .guard_size = 2, |
| 960 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 961 | }; |
| 962 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 963 | .fifo_size = I965_CURSOR_FIFO, |
| 964 | .max_wm = I965_CURSOR_MAX_WM, |
| 965 | .default_wm = I965_CURSOR_DFT_WM, |
| 966 | .guard_size = 2, |
| 967 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 968 | }; |
| 969 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 970 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 971 | .max_wm = VALLEYVIEW_MAX_WM, |
| 972 | .default_wm = VALLEYVIEW_MAX_WM, |
| 973 | .guard_size = 2, |
| 974 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 975 | }; |
| 976 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 977 | .fifo_size = I965_CURSOR_FIFO, |
| 978 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 979 | .default_wm = I965_CURSOR_DFT_WM, |
| 980 | .guard_size = 2, |
| 981 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 982 | }; |
| 983 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 984 | .fifo_size = I965_CURSOR_FIFO, |
| 985 | .max_wm = I965_CURSOR_MAX_WM, |
| 986 | .default_wm = I965_CURSOR_DFT_WM, |
| 987 | .guard_size = 2, |
| 988 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 989 | }; |
| 990 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 991 | .fifo_size = I945_FIFO_SIZE, |
| 992 | .max_wm = I915_MAX_WM, |
| 993 | .default_wm = 1, |
| 994 | .guard_size = 2, |
| 995 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 996 | }; |
| 997 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 998 | .fifo_size = I915_FIFO_SIZE, |
| 999 | .max_wm = I915_MAX_WM, |
| 1000 | .default_wm = 1, |
| 1001 | .guard_size = 2, |
| 1002 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1003 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1004 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1005 | .fifo_size = I855GM_FIFO_SIZE, |
| 1006 | .max_wm = I915_MAX_WM, |
| 1007 | .default_wm = 1, |
| 1008 | .guard_size = 2, |
| 1009 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1010 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1011 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 1012 | .fifo_size = I855GM_FIFO_SIZE, |
| 1013 | .max_wm = I915_MAX_WM/2, |
| 1014 | .default_wm = 1, |
| 1015 | .guard_size = 2, |
| 1016 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 1017 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1018 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1019 | .fifo_size = I830_FIFO_SIZE, |
| 1020 | .max_wm = I915_MAX_WM, |
| 1021 | .default_wm = 1, |
| 1022 | .guard_size = 2, |
| 1023 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1024 | }; |
| 1025 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1026 | /** |
| 1027 | * intel_calculate_wm - calculate watermark level |
| 1028 | * @clock_in_khz: pixel clock |
| 1029 | * @wm: chip FIFO params |
| 1030 | * @pixel_size: display pixel size |
| 1031 | * @latency_ns: memory latency for the platform |
| 1032 | * |
| 1033 | * Calculate the watermark level (the level at which the display plane will |
| 1034 | * start fetching from memory again). Each chip has a different display |
| 1035 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 1036 | * in the correct intel_watermark_params structure. |
| 1037 | * |
| 1038 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 1039 | * on the pixel size. When it reaches the watermark level, it'll start |
| 1040 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 1041 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 1042 | * will occur, and a display engine hang could result. |
| 1043 | */ |
| 1044 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 1045 | const struct intel_watermark_params *wm, |
| 1046 | int fifo_size, |
| 1047 | int pixel_size, |
| 1048 | unsigned long latency_ns) |
| 1049 | { |
| 1050 | long entries_required, wm_size; |
| 1051 | |
| 1052 | /* |
| 1053 | * Note: we need to make sure we don't overflow for various clock & |
| 1054 | * latency values. |
| 1055 | * clocks go from a few thousand to several hundred thousand. |
| 1056 | * latency is usually a few thousand |
| 1057 | */ |
| 1058 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 1059 | 1000; |
| 1060 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 1061 | |
| 1062 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 1063 | |
| 1064 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 1065 | |
| 1066 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 1067 | |
| 1068 | /* Don't promote wm_size to unsigned... */ |
| 1069 | if (wm_size > (long)wm->max_wm) |
| 1070 | wm_size = wm->max_wm; |
| 1071 | if (wm_size <= 0) |
| 1072 | wm_size = wm->default_wm; |
| 1073 | return wm_size; |
| 1074 | } |
| 1075 | |
| 1076 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 1077 | { |
| 1078 | struct drm_crtc *crtc, *enabled = NULL; |
| 1079 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 1080 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1081 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1082 | if (enabled) |
| 1083 | return NULL; |
| 1084 | enabled = crtc; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | return enabled; |
| 1089 | } |
| 1090 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1091 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1092 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1093 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1094 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1095 | struct drm_crtc *crtc; |
| 1096 | const struct cxsr_latency *latency; |
| 1097 | u32 reg; |
| 1098 | unsigned long wm; |
| 1099 | |
| 1100 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1101 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1102 | if (!latency) { |
| 1103 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1104 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1105 | return; |
| 1106 | } |
| 1107 | |
| 1108 | crtc = single_enabled_crtc(dev); |
| 1109 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1110 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1111 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1112 | int clock; |
| 1113 | |
| 1114 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1115 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1116 | |
| 1117 | /* Display SR */ |
| 1118 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1119 | pineview_display_wm.fifo_size, |
| 1120 | pixel_size, latency->display_sr); |
| 1121 | reg = I915_READ(DSPFW1); |
| 1122 | reg &= ~DSPFW_SR_MASK; |
| 1123 | reg |= wm << DSPFW_SR_SHIFT; |
| 1124 | I915_WRITE(DSPFW1, reg); |
| 1125 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1126 | |
| 1127 | /* cursor SR */ |
| 1128 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1129 | pineview_display_wm.fifo_size, |
| 1130 | pixel_size, latency->cursor_sr); |
| 1131 | reg = I915_READ(DSPFW3); |
| 1132 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1133 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1134 | I915_WRITE(DSPFW3, reg); |
| 1135 | |
| 1136 | /* Display HPLL off SR */ |
| 1137 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1138 | pineview_display_hplloff_wm.fifo_size, |
| 1139 | pixel_size, latency->display_hpll_disable); |
| 1140 | reg = I915_READ(DSPFW3); |
| 1141 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1142 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1143 | I915_WRITE(DSPFW3, reg); |
| 1144 | |
| 1145 | /* cursor HPLL off SR */ |
| 1146 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1147 | pineview_display_hplloff_wm.fifo_size, |
| 1148 | pixel_size, latency->cursor_hpll_disable); |
| 1149 | reg = I915_READ(DSPFW3); |
| 1150 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1151 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1152 | I915_WRITE(DSPFW3, reg); |
| 1153 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1154 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1155 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1156 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1157 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1162 | int plane, |
| 1163 | const struct intel_watermark_params *display, |
| 1164 | int display_latency_ns, |
| 1165 | const struct intel_watermark_params *cursor, |
| 1166 | int cursor_latency_ns, |
| 1167 | int *plane_wm, |
| 1168 | int *cursor_wm) |
| 1169 | { |
| 1170 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1171 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1172 | int htotal, hdisplay, clock, pixel_size; |
| 1173 | int line_time_us, line_count; |
| 1174 | int entries, tlb_miss; |
| 1175 | |
| 1176 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1177 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1178 | *cursor_wm = cursor->guard_size; |
| 1179 | *plane_wm = display->guard_size; |
| 1180 | return false; |
| 1181 | } |
| 1182 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1183 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1184 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1185 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1186 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1187 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1188 | |
| 1189 | /* Use the small buffer method to calculate plane watermark */ |
| 1190 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1191 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1192 | if (tlb_miss > 0) |
| 1193 | entries += tlb_miss; |
| 1194 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1195 | *plane_wm = entries + display->guard_size; |
| 1196 | if (*plane_wm > (int)display->max_wm) |
| 1197 | *plane_wm = display->max_wm; |
| 1198 | |
| 1199 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1200 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1201 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1202 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1203 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1204 | if (tlb_miss > 0) |
| 1205 | entries += tlb_miss; |
| 1206 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1207 | *cursor_wm = entries + cursor->guard_size; |
| 1208 | if (*cursor_wm > (int)cursor->max_wm) |
| 1209 | *cursor_wm = (int)cursor->max_wm; |
| 1210 | |
| 1211 | return true; |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | * Check the wm result. |
| 1216 | * |
| 1217 | * If any calculated watermark values is larger than the maximum value that |
| 1218 | * can be programmed into the associated watermark register, that watermark |
| 1219 | * must be disabled. |
| 1220 | */ |
| 1221 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1222 | int display_wm, int cursor_wm, |
| 1223 | const struct intel_watermark_params *display, |
| 1224 | const struct intel_watermark_params *cursor) |
| 1225 | { |
| 1226 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1227 | display_wm, cursor_wm); |
| 1228 | |
| 1229 | if (display_wm > display->max_wm) { |
| 1230 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1231 | display_wm, display->max_wm); |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | if (cursor_wm > cursor->max_wm) { |
| 1236 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1237 | cursor_wm, cursor->max_wm); |
| 1238 | return false; |
| 1239 | } |
| 1240 | |
| 1241 | if (!(display_wm || cursor_wm)) { |
| 1242 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | return true; |
| 1247 | } |
| 1248 | |
| 1249 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1250 | int plane, |
| 1251 | int latency_ns, |
| 1252 | const struct intel_watermark_params *display, |
| 1253 | const struct intel_watermark_params *cursor, |
| 1254 | int *display_wm, int *cursor_wm) |
| 1255 | { |
| 1256 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1257 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1258 | int hdisplay, htotal, pixel_size, clock; |
| 1259 | unsigned long line_time_us; |
| 1260 | int line_count, line_size; |
| 1261 | int small, large; |
| 1262 | int entries; |
| 1263 | |
| 1264 | if (!latency_ns) { |
| 1265 | *display_wm = *cursor_wm = 0; |
| 1266 | return false; |
| 1267 | } |
| 1268 | |
| 1269 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1270 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1271 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1272 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1273 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1274 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1275 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1276 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1277 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1278 | line_size = hdisplay * pixel_size; |
| 1279 | |
| 1280 | /* Use the minimum of the small and large buffer method for primary */ |
| 1281 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1282 | large = line_count * line_size; |
| 1283 | |
| 1284 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1285 | *display_wm = entries + display->guard_size; |
| 1286 | |
| 1287 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1288 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1289 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1290 | *cursor_wm = entries + cursor->guard_size; |
| 1291 | |
| 1292 | return g4x_check_srwm(dev, |
| 1293 | *display_wm, *cursor_wm, |
| 1294 | display, cursor); |
| 1295 | } |
| 1296 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1297 | static bool vlv_compute_drain_latency(struct drm_crtc *crtc, |
| 1298 | int pixel_size, |
| 1299 | int *prec_mult, |
| 1300 | int *drain_latency) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1301 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1302 | int entries; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1303 | int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1304 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1305 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1306 | return false; |
| 1307 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1308 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
| 1309 | return false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1310 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 1311 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1312 | *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_64 : |
| 1313 | DRAIN_LATENCY_PRECISION_32; |
| 1314 | *drain_latency = (64 * (*prec_mult) * 4) / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1315 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 1316 | if (*drain_latency > DRAIN_LATENCY_MASK) |
| 1317 | *drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1318 | |
| 1319 | return true; |
| 1320 | } |
| 1321 | |
| 1322 | /* |
| 1323 | * Update drain latency registers of memory arbiter |
| 1324 | * |
| 1325 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1326 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1327 | * latency value. |
| 1328 | */ |
| 1329 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 1330 | static void vlv_update_drain_latency(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1331 | { |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1332 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1333 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1334 | int pixel_size; |
| 1335 | int drain_latency; |
| 1336 | enum pipe pipe = intel_crtc->pipe; |
| 1337 | int plane_prec, prec_mult, plane_dl; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1338 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1339 | plane_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_PLANE_PRECISION_64 | |
| 1340 | DRAIN_LATENCY_MASK | DDL_CURSOR_PRECISION_64 | |
| 1341 | (DRAIN_LATENCY_MASK << DDL_CURSOR_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1342 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1343 | if (!intel_crtc_active(crtc)) { |
| 1344 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
| 1345 | return; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1346 | } |
| 1347 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1348 | /* Primary plane Drain Latency */ |
| 1349 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
| 1350 | if (vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
| 1351 | plane_prec = (prec_mult == DRAIN_LATENCY_PRECISION_64) ? |
| 1352 | DDL_PLANE_PRECISION_64 : |
| 1353 | DDL_PLANE_PRECISION_32; |
| 1354 | plane_dl |= plane_prec | drain_latency; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1355 | } |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1356 | |
| 1357 | /* Cursor Drain Latency |
| 1358 | * BPP is always 4 for cursor |
| 1359 | */ |
| 1360 | pixel_size = 4; |
| 1361 | |
| 1362 | /* Program cursor DL only if it is enabled */ |
| 1363 | if (intel_crtc->cursor_base && |
| 1364 | vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
| 1365 | plane_prec = (prec_mult == DRAIN_LATENCY_PRECISION_64) ? |
| 1366 | DDL_CURSOR_PRECISION_64 : |
| 1367 | DDL_CURSOR_PRECISION_32; |
| 1368 | plane_dl |= plane_prec | (drain_latency << DDL_CURSOR_SHIFT); |
| 1369 | } |
| 1370 | |
| 1371 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1375 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1376 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1377 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1378 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1379 | static const int sr_latency_ns = 12000; |
| 1380 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1381 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1382 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1383 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1384 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1385 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1386 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 1387 | vlv_update_drain_latency(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1388 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1389 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1390 | &valleyview_wm_info, pessimal_latency_ns, |
| 1391 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1392 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1393 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1394 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1395 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1396 | &valleyview_wm_info, pessimal_latency_ns, |
| 1397 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1398 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1399 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1400 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1401 | if (single_plane_enabled(enabled) && |
| 1402 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1403 | sr_latency_ns, |
| 1404 | &valleyview_wm_info, |
| 1405 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1406 | &plane_sr, &ignore_cursor_sr) && |
| 1407 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1408 | 2*sr_latency_ns, |
| 1409 | &valleyview_wm_info, |
| 1410 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1411 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1412 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1413 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1414 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1415 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1416 | plane_sr = cursor_sr = 0; |
| 1417 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1418 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1419 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1420 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1421 | planea_wm, cursora_wm, |
| 1422 | planeb_wm, cursorb_wm, |
| 1423 | plane_sr, cursor_sr); |
| 1424 | |
| 1425 | I915_WRITE(DSPFW1, |
| 1426 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1427 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1428 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1429 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1430 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1431 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1432 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1433 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1434 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1435 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1436 | |
| 1437 | if (cxsr_enabled) |
| 1438 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1439 | } |
| 1440 | |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1441 | static void cherryview_update_wm(struct drm_crtc *crtc) |
| 1442 | { |
| 1443 | struct drm_device *dev = crtc->dev; |
| 1444 | static const int sr_latency_ns = 12000; |
| 1445 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1446 | int planea_wm, planeb_wm, planec_wm; |
| 1447 | int cursora_wm, cursorb_wm, cursorc_wm; |
| 1448 | int plane_sr, cursor_sr; |
| 1449 | int ignore_plane_sr, ignore_cursor_sr; |
| 1450 | unsigned int enabled = 0; |
| 1451 | bool cxsr_enabled; |
| 1452 | |
| 1453 | vlv_update_drain_latency(crtc); |
| 1454 | |
| 1455 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1456 | &valleyview_wm_info, pessimal_latency_ns, |
| 1457 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1458 | &planea_wm, &cursora_wm)) |
| 1459 | enabled |= 1 << PIPE_A; |
| 1460 | |
| 1461 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1462 | &valleyview_wm_info, pessimal_latency_ns, |
| 1463 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1464 | &planeb_wm, &cursorb_wm)) |
| 1465 | enabled |= 1 << PIPE_B; |
| 1466 | |
| 1467 | if (g4x_compute_wm0(dev, PIPE_C, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1468 | &valleyview_wm_info, pessimal_latency_ns, |
| 1469 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1470 | &planec_wm, &cursorc_wm)) |
| 1471 | enabled |= 1 << PIPE_C; |
| 1472 | |
| 1473 | if (single_plane_enabled(enabled) && |
| 1474 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1475 | sr_latency_ns, |
| 1476 | &valleyview_wm_info, |
| 1477 | &valleyview_cursor_wm_info, |
| 1478 | &plane_sr, &ignore_cursor_sr) && |
| 1479 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1480 | 2*sr_latency_ns, |
| 1481 | &valleyview_wm_info, |
| 1482 | &valleyview_cursor_wm_info, |
| 1483 | &ignore_plane_sr, &cursor_sr)) { |
| 1484 | cxsr_enabled = true; |
| 1485 | } else { |
| 1486 | cxsr_enabled = false; |
| 1487 | intel_set_memory_cxsr(dev_priv, false); |
| 1488 | plane_sr = cursor_sr = 0; |
| 1489 | } |
| 1490 | |
| 1491 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1492 | "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, " |
| 1493 | "SR: plane=%d, cursor=%d\n", |
| 1494 | planea_wm, cursora_wm, |
| 1495 | planeb_wm, cursorb_wm, |
| 1496 | planec_wm, cursorc_wm, |
| 1497 | plane_sr, cursor_sr); |
| 1498 | |
| 1499 | I915_WRITE(DSPFW1, |
| 1500 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1501 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1502 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1503 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
| 1504 | I915_WRITE(DSPFW2, |
| 1505 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
| 1506 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1507 | I915_WRITE(DSPFW3, |
| 1508 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1509 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1510 | I915_WRITE(DSPFW9_CHV, |
| 1511 | (I915_READ(DSPFW9_CHV) & ~(DSPFW_PLANEC_MASK | |
| 1512 | DSPFW_CURSORC_MASK)) | |
| 1513 | (planec_wm << DSPFW_PLANEC_SHIFT) | |
| 1514 | (cursorc_wm << DSPFW_CURSORC_SHIFT)); |
| 1515 | |
| 1516 | if (cxsr_enabled) |
| 1517 | intel_set_memory_cxsr(dev_priv, true); |
| 1518 | } |
| 1519 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1520 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1521 | struct drm_crtc *crtc, |
| 1522 | uint32_t sprite_width, |
| 1523 | uint32_t sprite_height, |
| 1524 | int pixel_size, |
| 1525 | bool enabled, bool scaled) |
| 1526 | { |
| 1527 | struct drm_device *dev = crtc->dev; |
| 1528 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1529 | int pipe = to_intel_plane(plane)->pipe; |
| 1530 | int sprite = to_intel_plane(plane)->plane; |
| 1531 | int drain_latency; |
| 1532 | int plane_prec; |
| 1533 | int sprite_dl; |
| 1534 | int prec_mult; |
| 1535 | |
| 1536 | sprite_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_SPRITE_PRECISION_64(sprite) | |
| 1537 | (DRAIN_LATENCY_MASK << DDL_SPRITE_SHIFT(sprite))); |
| 1538 | |
| 1539 | if (enabled && vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, |
| 1540 | &drain_latency)) { |
| 1541 | plane_prec = (prec_mult == DRAIN_LATENCY_PRECISION_64) ? |
| 1542 | DDL_SPRITE_PRECISION_64(sprite) : |
| 1543 | DDL_SPRITE_PRECISION_32(sprite); |
| 1544 | sprite_dl |= plane_prec | |
| 1545 | (drain_latency << DDL_SPRITE_SHIFT(sprite)); |
| 1546 | } |
| 1547 | |
| 1548 | I915_WRITE(VLV_DDL(pipe), sprite_dl); |
| 1549 | } |
| 1550 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1551 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1552 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1553 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1554 | static const int sr_latency_ns = 12000; |
| 1555 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1556 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1557 | int plane_sr, cursor_sr; |
| 1558 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1559 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1560 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1561 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1562 | &g4x_wm_info, pessimal_latency_ns, |
| 1563 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1564 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1565 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1566 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1567 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1568 | &g4x_wm_info, pessimal_latency_ns, |
| 1569 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1570 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1571 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1572 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1573 | if (single_plane_enabled(enabled) && |
| 1574 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1575 | sr_latency_ns, |
| 1576 | &g4x_wm_info, |
| 1577 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1578 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1579 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1580 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1581 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1582 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1583 | plane_sr = cursor_sr = 0; |
| 1584 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1585 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1586 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1587 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1588 | planea_wm, cursora_wm, |
| 1589 | planeb_wm, cursorb_wm, |
| 1590 | plane_sr, cursor_sr); |
| 1591 | |
| 1592 | I915_WRITE(DSPFW1, |
| 1593 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1594 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1595 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1596 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1597 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1598 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1599 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1600 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1601 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1602 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1603 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1604 | |
| 1605 | if (cxsr_enabled) |
| 1606 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1607 | } |
| 1608 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1609 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1610 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1611 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1612 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1613 | struct drm_crtc *crtc; |
| 1614 | int srwm = 1; |
| 1615 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1616 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1617 | |
| 1618 | /* Calc sr entries for one plane configs */ |
| 1619 | crtc = single_enabled_crtc(dev); |
| 1620 | if (crtc) { |
| 1621 | /* self-refresh has much higher latency */ |
| 1622 | static const int sr_latency_ns = 12000; |
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(crtc)->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; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1627 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1628 | int pixel_size = crtc->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, I915_FIFO_LINE_SIZE); |
| 1638 | srwm = I965_FIFO_SIZE - entries; |
| 1639 | if (srwm < 0) |
| 1640 | srwm = 1; |
| 1641 | srwm &= 0x1ff; |
| 1642 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1643 | entries, srwm); |
| 1644 | |
| 1645 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1646 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1647 | entries = DIV_ROUND_UP(entries, |
| 1648 | i965_cursor_wm_info.cacheline_size); |
| 1649 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1650 | (entries + i965_cursor_wm_info.guard_size); |
| 1651 | |
| 1652 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1653 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1654 | |
| 1655 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1656 | "cursor %d\n", srwm, cursor_sr); |
| 1657 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1658 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1659 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1660 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1661 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1662 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1666 | srwm); |
| 1667 | |
| 1668 | /* 965 has limitations... */ |
| 1669 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1670 | (8 << DSPFW_CURSORB_SHIFT) | |
| 1671 | (8 << DSPFW_PLANEB_SHIFT) | |
| 1672 | (8 << DSPFW_PLANEA_SHIFT)); |
| 1673 | I915_WRITE(DSPFW2, (8 << DSPFW_CURSORA_SHIFT) | |
| 1674 | (8 << DSPFW_PLANEC_SHIFT_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1675 | /* update cursor SR watermark */ |
| 1676 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1677 | |
| 1678 | if (cxsr_enabled) |
| 1679 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1680 | } |
| 1681 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1682 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1683 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1684 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1685 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1686 | const struct intel_watermark_params *wm_info; |
| 1687 | uint32_t fwater_lo; |
| 1688 | uint32_t fwater_hi; |
| 1689 | int cwm, srwm = 1; |
| 1690 | int fifo_size; |
| 1691 | int planea_wm, planeb_wm; |
| 1692 | struct drm_crtc *crtc, *enabled = NULL; |
| 1693 | |
| 1694 | if (IS_I945GM(dev)) |
| 1695 | wm_info = &i945_wm_info; |
| 1696 | else if (!IS_GEN2(dev)) |
| 1697 | wm_info = &i915_wm_info; |
| 1698 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1699 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1700 | |
| 1701 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1702 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1703 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1704 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1705 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1706 | if (IS_GEN2(dev)) |
| 1707 | cpp = 4; |
| 1708 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1709 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1710 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1711 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1712 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1713 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1714 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1715 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1716 | if (planea_wm > (long)wm_info->max_wm) |
| 1717 | planea_wm = wm_info->max_wm; |
| 1718 | } |
| 1719 | |
| 1720 | if (IS_GEN2(dev)) |
| 1721 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1722 | |
| 1723 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1724 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1725 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1726 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1727 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1728 | if (IS_GEN2(dev)) |
| 1729 | cpp = 4; |
| 1730 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1731 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1732 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1733 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1734 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1735 | if (enabled == NULL) |
| 1736 | enabled = crtc; |
| 1737 | else |
| 1738 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1739 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1740 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1741 | if (planeb_wm > (long)wm_info->max_wm) |
| 1742 | planeb_wm = wm_info->max_wm; |
| 1743 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1744 | |
| 1745 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1746 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1747 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1748 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1749 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1750 | obj = intel_fb_obj(enabled->primary->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1751 | |
| 1752 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1753 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1754 | enabled = NULL; |
| 1755 | } |
| 1756 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1757 | /* |
| 1758 | * Overlay gets an aggressive default since video jitter is bad. |
| 1759 | */ |
| 1760 | cwm = 2; |
| 1761 | |
| 1762 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1763 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1764 | |
| 1765 | /* Calc sr entries for one plane configs */ |
| 1766 | if (HAS_FW_BLC(dev) && enabled) { |
| 1767 | /* self-refresh has much higher latency */ |
| 1768 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1769 | const struct drm_display_mode *adjusted_mode = |
| 1770 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1771 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1772 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1773 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1774 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1775 | unsigned long line_time_us; |
| 1776 | int entries; |
| 1777 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1778 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1779 | |
| 1780 | /* Use ns/us then divide to preserve precision */ |
| 1781 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1782 | pixel_size * hdisplay; |
| 1783 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1784 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1785 | srwm = wm_info->fifo_size - entries; |
| 1786 | if (srwm < 0) |
| 1787 | srwm = 1; |
| 1788 | |
| 1789 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1790 | I915_WRITE(FW_BLC_SELF, |
| 1791 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1792 | else if (IS_I915GM(dev)) |
| 1793 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1794 | } |
| 1795 | |
| 1796 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1797 | planea_wm, planeb_wm, cwm, srwm); |
| 1798 | |
| 1799 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1800 | fwater_hi = (cwm & 0x1f); |
| 1801 | |
| 1802 | /* Set request length to 8 cachelines per fetch */ |
| 1803 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1804 | fwater_hi = fwater_hi | (1 << 8); |
| 1805 | |
| 1806 | I915_WRITE(FW_BLC, fwater_lo); |
| 1807 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1808 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1809 | if (enabled) |
| 1810 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1811 | } |
| 1812 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1813 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1814 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1815 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1816 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1817 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1818 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1819 | uint32_t fwater_lo; |
| 1820 | int planea_wm; |
| 1821 | |
| 1822 | crtc = single_enabled_crtc(dev); |
| 1823 | if (crtc == NULL) |
| 1824 | return; |
| 1825 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1826 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1827 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1828 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1829 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame^] | 1830 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1831 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1832 | fwater_lo |= (3<<8) | planea_wm; |
| 1833 | |
| 1834 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1835 | |
| 1836 | I915_WRITE(FW_BLC, fwater_lo); |
| 1837 | } |
| 1838 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1839 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1840 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1841 | { |
| 1842 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1843 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1844 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1845 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1846 | |
| 1847 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1848 | * adjust the pixel_rate here. */ |
| 1849 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1850 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1851 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1852 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1853 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1854 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1855 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1856 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1857 | pfit_h = pfit_size & 0xFFFF; |
| 1858 | if (pipe_w < pfit_w) |
| 1859 | pipe_w = pfit_w; |
| 1860 | if (pipe_h < pfit_h) |
| 1861 | pipe_h = pfit_h; |
| 1862 | |
| 1863 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1864 | pfit_w * pfit_h); |
| 1865 | } |
| 1866 | |
| 1867 | return pixel_rate; |
| 1868 | } |
| 1869 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1870 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1871 | 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] | 1872 | uint32_t latency) |
| 1873 | { |
| 1874 | uint64_t ret; |
| 1875 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1876 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1877 | return UINT_MAX; |
| 1878 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1879 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1880 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1881 | |
| 1882 | return ret; |
| 1883 | } |
| 1884 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1885 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1886 | 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] | 1887 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1888 | uint32_t latency) |
| 1889 | { |
| 1890 | uint32_t ret; |
| 1891 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1892 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1893 | return UINT_MAX; |
| 1894 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1895 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1896 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1897 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1898 | return ret; |
| 1899 | } |
| 1900 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1901 | 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] | 1902 | uint8_t bytes_per_pixel) |
| 1903 | { |
| 1904 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1905 | } |
| 1906 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1907 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1908 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1909 | uint32_t pipe_htotal; |
| 1910 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1911 | struct intel_plane_wm_parameters pri; |
| 1912 | struct intel_plane_wm_parameters spr; |
| 1913 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1914 | }; |
| 1915 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1916 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1917 | uint16_t pri; |
| 1918 | uint16_t spr; |
| 1919 | uint16_t cur; |
| 1920 | uint16_t fbc; |
| 1921 | }; |
| 1922 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1923 | /* used in computing the new watermarks state */ |
| 1924 | struct intel_wm_config { |
| 1925 | unsigned int num_pipes_active; |
| 1926 | bool sprites_enabled; |
| 1927 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1928 | }; |
| 1929 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1930 | /* |
| 1931 | * For both WM_PIPE and WM_LP. |
| 1932 | * mem_value must be in 0.1us units. |
| 1933 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1934 | 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] | 1935 | uint32_t mem_value, |
| 1936 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1937 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1938 | uint32_t method1, method2; |
| 1939 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1940 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1941 | return 0; |
| 1942 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1943 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1944 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1945 | mem_value); |
| 1946 | |
| 1947 | if (!is_lp) |
| 1948 | return method1; |
| 1949 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1950 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1951 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1952 | params->pri.horiz_pixels, |
| 1953 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1954 | mem_value); |
| 1955 | |
| 1956 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1957 | } |
| 1958 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1959 | /* |
| 1960 | * For both WM_PIPE and WM_LP. |
| 1961 | * mem_value must be in 0.1us units. |
| 1962 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1963 | 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] | 1964 | uint32_t mem_value) |
| 1965 | { |
| 1966 | uint32_t method1, method2; |
| 1967 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1968 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1969 | return 0; |
| 1970 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1971 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1972 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1973 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1974 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1975 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1976 | params->spr.horiz_pixels, |
| 1977 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1978 | mem_value); |
| 1979 | return min(method1, method2); |
| 1980 | } |
| 1981 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1982 | /* |
| 1983 | * For both WM_PIPE and WM_LP. |
| 1984 | * mem_value must be in 0.1us units. |
| 1985 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1986 | 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] | 1987 | uint32_t mem_value) |
| 1988 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1989 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1990 | return 0; |
| 1991 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1992 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1993 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1994 | params->cur.horiz_pixels, |
| 1995 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1996 | mem_value); |
| 1997 | } |
| 1998 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1999 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2000 | 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] | 2001 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2002 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2003 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2004 | return 0; |
| 2005 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2006 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2007 | params->pri.horiz_pixels, |
| 2008 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2009 | } |
| 2010 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2011 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 2012 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2013 | if (INTEL_INFO(dev)->gen >= 8) |
| 2014 | return 3072; |
| 2015 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2016 | return 768; |
| 2017 | else |
| 2018 | return 512; |
| 2019 | } |
| 2020 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2021 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 2022 | int level, bool is_sprite) |
| 2023 | { |
| 2024 | if (INTEL_INFO(dev)->gen >= 8) |
| 2025 | /* BDW primary/sprite plane watermarks */ |
| 2026 | return level == 0 ? 255 : 2047; |
| 2027 | else if (INTEL_INFO(dev)->gen >= 7) |
| 2028 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2029 | return level == 0 ? 127 : 1023; |
| 2030 | else if (!is_sprite) |
| 2031 | /* ILK/SNB primary plane watermarks */ |
| 2032 | return level == 0 ? 127 : 511; |
| 2033 | else |
| 2034 | /* ILK/SNB sprite plane watermarks */ |
| 2035 | return level == 0 ? 63 : 255; |
| 2036 | } |
| 2037 | |
| 2038 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 2039 | int level) |
| 2040 | { |
| 2041 | if (INTEL_INFO(dev)->gen >= 7) |
| 2042 | return level == 0 ? 63 : 255; |
| 2043 | else |
| 2044 | return level == 0 ? 31 : 63; |
| 2045 | } |
| 2046 | |
| 2047 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 2048 | { |
| 2049 | if (INTEL_INFO(dev)->gen >= 8) |
| 2050 | return 31; |
| 2051 | else |
| 2052 | return 15; |
| 2053 | } |
| 2054 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2055 | /* Calculate the maximum primary/sprite plane watermark */ |
| 2056 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 2057 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2058 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2059 | enum intel_ddb_partitioning ddb_partitioning, |
| 2060 | bool is_sprite) |
| 2061 | { |
| 2062 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2063 | |
| 2064 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2065 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2066 | return 0; |
| 2067 | |
| 2068 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2069 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2070 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 2071 | |
| 2072 | /* |
| 2073 | * For some reason the non self refresh |
| 2074 | * FIFO size is only half of the self |
| 2075 | * refresh FIFO size on ILK/SNB. |
| 2076 | */ |
| 2077 | if (INTEL_INFO(dev)->gen <= 6) |
| 2078 | fifo_size /= 2; |
| 2079 | } |
| 2080 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2081 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2082 | /* level 0 is always calculated with 1:1 split */ |
| 2083 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2084 | if (is_sprite) |
| 2085 | fifo_size *= 5; |
| 2086 | fifo_size /= 6; |
| 2087 | } else { |
| 2088 | fifo_size /= 2; |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2093 | 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] | 2094 | } |
| 2095 | |
| 2096 | /* Calculate the maximum cursor plane watermark */ |
| 2097 | 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] | 2098 | int level, |
| 2099 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2100 | { |
| 2101 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2102 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2103 | return 64; |
| 2104 | |
| 2105 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2106 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2107 | } |
| 2108 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2109 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2110 | int level, |
| 2111 | const struct intel_wm_config *config, |
| 2112 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2113 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2114 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2115 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 2116 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 2117 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2118 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2119 | } |
| 2120 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2121 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 2122 | int level, |
| 2123 | struct ilk_wm_maximums *max) |
| 2124 | { |
| 2125 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 2126 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 2127 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 2128 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 2129 | } |
| 2130 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2131 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2132 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2133 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2134 | { |
| 2135 | bool ret; |
| 2136 | |
| 2137 | /* already determined to be invalid? */ |
| 2138 | if (!result->enable) |
| 2139 | return false; |
| 2140 | |
| 2141 | result->enable = result->pri_val <= max->pri && |
| 2142 | result->spr_val <= max->spr && |
| 2143 | result->cur_val <= max->cur; |
| 2144 | |
| 2145 | ret = result->enable; |
| 2146 | |
| 2147 | /* |
| 2148 | * HACK until we can pre-compute everything, |
| 2149 | * and thus fail gracefully if LP0 watermarks |
| 2150 | * are exceeded... |
| 2151 | */ |
| 2152 | if (level == 0 && !result->enable) { |
| 2153 | if (result->pri_val > max->pri) |
| 2154 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2155 | level, result->pri_val, max->pri); |
| 2156 | if (result->spr_val > max->spr) |
| 2157 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2158 | level, result->spr_val, max->spr); |
| 2159 | if (result->cur_val > max->cur) |
| 2160 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2161 | level, result->cur_val, max->cur); |
| 2162 | |
| 2163 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2164 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2165 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2166 | result->enable = true; |
| 2167 | } |
| 2168 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2169 | return ret; |
| 2170 | } |
| 2171 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2172 | 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] | 2173 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2174 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2175 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2176 | { |
| 2177 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2178 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2179 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2180 | |
| 2181 | /* WM1+ latency values stored in 0.5us units */ |
| 2182 | if (level > 0) { |
| 2183 | pri_latency *= 5; |
| 2184 | spr_latency *= 5; |
| 2185 | cur_latency *= 5; |
| 2186 | } |
| 2187 | |
| 2188 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 2189 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 2190 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 2191 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 2192 | result->enable = true; |
| 2193 | } |
| 2194 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2195 | static uint32_t |
| 2196 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2197 | { |
| 2198 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2199 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2200 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2201 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2202 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2203 | if (!intel_crtc_active(crtc)) |
| 2204 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2205 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2206 | /* The WM are computed with base on how long it takes to fill a single |
| 2207 | * row at the given clock rate, multiplied by 8. |
| 2208 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2209 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 2210 | mode->crtc_clock); |
| 2211 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2212 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2213 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2214 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2215 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2216 | } |
| 2217 | |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2218 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2219 | { |
| 2220 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2221 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2222 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2223 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2224 | |
| 2225 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2226 | if (wm[0] == 0) |
| 2227 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2228 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2229 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2230 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2231 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2232 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2233 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2234 | |
| 2235 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2236 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2237 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2238 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2239 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2240 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2241 | |
| 2242 | /* ILK primary LP0 latency is 700 ns */ |
| 2243 | wm[0] = 7; |
| 2244 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2245 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2249 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2250 | { |
| 2251 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2252 | if (INTEL_INFO(dev)->gen == 5) |
| 2253 | wm[0] = 13; |
| 2254 | } |
| 2255 | |
| 2256 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2257 | { |
| 2258 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2259 | if (INTEL_INFO(dev)->gen == 5) |
| 2260 | wm[0] = 13; |
| 2261 | |
| 2262 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2263 | if (IS_IVYBRIDGE(dev)) |
| 2264 | wm[3] *= 2; |
| 2265 | } |
| 2266 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 2267 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2268 | { |
| 2269 | /* how many WM levels are we expecting */ |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2270 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2271 | return 4; |
| 2272 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2273 | return 3; |
| 2274 | else |
| 2275 | return 2; |
| 2276 | } |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2277 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2278 | const char *name, |
| 2279 | const uint16_t wm[5]) |
| 2280 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2281 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2282 | |
| 2283 | for (level = 0; level <= max_level; level++) { |
| 2284 | unsigned int latency = wm[level]; |
| 2285 | |
| 2286 | if (latency == 0) { |
| 2287 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2288 | name, level); |
| 2289 | continue; |
| 2290 | } |
| 2291 | |
| 2292 | /* WM1+ latency values in 0.5us units */ |
| 2293 | if (level > 0) |
| 2294 | latency *= 5; |
| 2295 | |
| 2296 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2297 | name, level, wm[level], |
| 2298 | latency / 10, latency % 10); |
| 2299 | } |
| 2300 | } |
| 2301 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2302 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2303 | uint16_t wm[5], uint16_t min) |
| 2304 | { |
| 2305 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 2306 | |
| 2307 | if (wm[0] >= min) |
| 2308 | return false; |
| 2309 | |
| 2310 | wm[0] = max(wm[0], min); |
| 2311 | for (level = 1; level <= max_level; level++) |
| 2312 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2313 | |
| 2314 | return true; |
| 2315 | } |
| 2316 | |
| 2317 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2318 | { |
| 2319 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2320 | bool changed; |
| 2321 | |
| 2322 | /* |
| 2323 | * The BIOS provided WM memory latency values are often |
| 2324 | * inadequate for high resolution displays. Adjust them. |
| 2325 | */ |
| 2326 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2327 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2328 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2329 | |
| 2330 | if (!changed) |
| 2331 | return; |
| 2332 | |
| 2333 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2334 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2335 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2336 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2337 | } |
| 2338 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2339 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2340 | { |
| 2341 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2342 | |
| 2343 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2344 | |
| 2345 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2346 | sizeof(dev_priv->wm.pri_latency)); |
| 2347 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2348 | sizeof(dev_priv->wm.pri_latency)); |
| 2349 | |
| 2350 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2351 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2352 | |
| 2353 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2354 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2355 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2356 | |
| 2357 | if (IS_GEN6(dev)) |
| 2358 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2359 | } |
| 2360 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2361 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2362 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2363 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2364 | struct drm_device *dev = crtc->dev; |
| 2365 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2366 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2367 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2368 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2369 | if (!intel_crtc_active(crtc)) |
| 2370 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2371 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2372 | p->active = true; |
| 2373 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 2374 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 2375 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 2376 | p->cur.bytes_per_pixel = 4; |
| 2377 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
| 2378 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 2379 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2380 | p->pri.enabled = true; |
| 2381 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2382 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2383 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2384 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2385 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2386 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2387 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2388 | break; |
| 2389 | } |
| 2390 | } |
| 2391 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2392 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2393 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2394 | struct intel_wm_config *config) |
| 2395 | { |
| 2396 | struct intel_crtc *intel_crtc; |
| 2397 | |
| 2398 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2399 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2400 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2401 | |
| 2402 | if (!wm->pipe_enabled) |
| 2403 | continue; |
| 2404 | |
| 2405 | config->sprites_enabled |= wm->sprites_enabled; |
| 2406 | config->sprites_scaled |= wm->sprites_scaled; |
| 2407 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2411 | /* Compute new watermarks for the pipe */ |
| 2412 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2413 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2414 | struct intel_pipe_wm *pipe_wm) |
| 2415 | { |
| 2416 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2417 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2418 | int level, max_level = ilk_wm_max_level(dev); |
| 2419 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2420 | struct intel_wm_config config = { |
| 2421 | .num_pipes_active = 1, |
| 2422 | .sprites_enabled = params->spr.enabled, |
| 2423 | .sprites_scaled = params->spr.scaled, |
| 2424 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2425 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2426 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2427 | pipe_wm->pipe_enabled = params->active; |
| 2428 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2429 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2430 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2431 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2432 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2433 | max_level = 1; |
| 2434 | |
| 2435 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2436 | if (params->spr.scaled) |
| 2437 | max_level = 0; |
| 2438 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2439 | 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] | 2440 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2441 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2442 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2443 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2444 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2445 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2446 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2447 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2448 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2449 | return false; |
| 2450 | |
| 2451 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2452 | |
| 2453 | for (level = 1; level <= max_level; level++) { |
| 2454 | struct intel_wm_level wm = {}; |
| 2455 | |
| 2456 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2457 | |
| 2458 | /* |
| 2459 | * Disable any watermark level that exceeds the |
| 2460 | * register maximums since such watermarks are |
| 2461 | * always invalid. |
| 2462 | */ |
| 2463 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2464 | break; |
| 2465 | |
| 2466 | pipe_wm->wm[level] = wm; |
| 2467 | } |
| 2468 | |
| 2469 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | /* |
| 2473 | * Merge the watermarks from all active pipes for a specific level. |
| 2474 | */ |
| 2475 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2476 | int level, |
| 2477 | struct intel_wm_level *ret_wm) |
| 2478 | { |
| 2479 | const struct intel_crtc *intel_crtc; |
| 2480 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2481 | ret_wm->enable = true; |
| 2482 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2483 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2484 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2485 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2486 | |
| 2487 | if (!active->pipe_enabled) |
| 2488 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2489 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2490 | /* |
| 2491 | * The watermark values may have been used in the past, |
| 2492 | * so we must maintain them in the registers for some |
| 2493 | * time even if the level is now disabled. |
| 2494 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2495 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2496 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2497 | |
| 2498 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2499 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2500 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2501 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2502 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | /* |
| 2506 | * Merge all low power watermarks for all active pipes. |
| 2507 | */ |
| 2508 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2509 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2510 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2511 | struct intel_pipe_wm *merged) |
| 2512 | { |
| 2513 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2514 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2515 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2516 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2517 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2518 | config->num_pipes_active > 1) |
| 2519 | return; |
| 2520 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2521 | /* ILK: FBC WM must be disabled always */ |
| 2522 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2523 | |
| 2524 | /* merge each WM1+ level */ |
| 2525 | for (level = 1; level <= max_level; level++) { |
| 2526 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2527 | |
| 2528 | ilk_merge_wm_level(dev, level, wm); |
| 2529 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2530 | if (level > last_enabled_level) |
| 2531 | wm->enable = false; |
| 2532 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2533 | /* make sure all following levels get disabled */ |
| 2534 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2535 | |
| 2536 | /* |
| 2537 | * The spec says it is preferred to disable |
| 2538 | * FBC WMs instead of disabling a WM level. |
| 2539 | */ |
| 2540 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2541 | if (wm->enable) |
| 2542 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2543 | wm->fbc_val = 0; |
| 2544 | } |
| 2545 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2546 | |
| 2547 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2548 | /* |
| 2549 | * FIXME this is racy. FBC might get enabled later. |
| 2550 | * What we should check here is whether FBC can be |
| 2551 | * enabled sometime later. |
| 2552 | */ |
| 2553 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2554 | for (level = 2; level <= max_level; level++) { |
| 2555 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2556 | |
| 2557 | wm->enable = false; |
| 2558 | } |
| 2559 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2560 | } |
| 2561 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2562 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2563 | { |
| 2564 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2565 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2566 | } |
| 2567 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2568 | /* The value we need to program into the WM_LPx latency field */ |
| 2569 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2570 | { |
| 2571 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2572 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2573 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2574 | return 2 * level; |
| 2575 | else |
| 2576 | return dev_priv->wm.pri_latency[level]; |
| 2577 | } |
| 2578 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2579 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2580 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2581 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2582 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2583 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2584 | struct intel_crtc *intel_crtc; |
| 2585 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2586 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2587 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2588 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2589 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2590 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2591 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2592 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2593 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2594 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2595 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2596 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2597 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2598 | /* |
| 2599 | * Maintain the watermark values even if the level is |
| 2600 | * disabled. Doing otherwise could cause underruns. |
| 2601 | */ |
| 2602 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2603 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2604 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2605 | r->cur_val; |
| 2606 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2607 | if (r->enable) |
| 2608 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2609 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2610 | if (INTEL_INFO(dev)->gen >= 8) |
| 2611 | results->wm_lp[wm_lp - 1] |= |
| 2612 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2613 | else |
| 2614 | results->wm_lp[wm_lp - 1] |= |
| 2615 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2616 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2617 | /* |
| 2618 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2619 | * level is disabled. Doing otherwise could cause underruns. |
| 2620 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2621 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2622 | WARN_ON(wm_lp != 1); |
| 2623 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2624 | } else |
| 2625 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2626 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2627 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2628 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2629 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2630 | enum pipe pipe = intel_crtc->pipe; |
| 2631 | const struct intel_wm_level *r = |
| 2632 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2633 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2634 | if (WARN_ON(!r->enable)) |
| 2635 | continue; |
| 2636 | |
| 2637 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2638 | |
| 2639 | results->wm_pipe[pipe] = |
| 2640 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2641 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2642 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2643 | } |
| 2644 | } |
| 2645 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2646 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2647 | * 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] | 2648 | 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] | 2649 | struct intel_pipe_wm *r1, |
| 2650 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2651 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2652 | int level, max_level = ilk_wm_max_level(dev); |
| 2653 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2654 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2655 | for (level = 1; level <= max_level; level++) { |
| 2656 | if (r1->wm[level].enable) |
| 2657 | level1 = level; |
| 2658 | if (r2->wm[level].enable) |
| 2659 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2660 | } |
| 2661 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2662 | if (level1 == level2) { |
| 2663 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2664 | return r2; |
| 2665 | else |
| 2666 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2667 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2668 | return r1; |
| 2669 | } else { |
| 2670 | return r2; |
| 2671 | } |
| 2672 | } |
| 2673 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2674 | /* dirty bits used to track which watermarks need changes */ |
| 2675 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2676 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2677 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2678 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2679 | #define WM_DIRTY_FBC (1 << 24) |
| 2680 | #define WM_DIRTY_DDB (1 << 25) |
| 2681 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2682 | static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2683 | const struct ilk_wm_values *old, |
| 2684 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2685 | { |
| 2686 | unsigned int dirty = 0; |
| 2687 | enum pipe pipe; |
| 2688 | int wm_lp; |
| 2689 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2690 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2691 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2692 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2693 | /* Must disable LP1+ watermarks too */ |
| 2694 | dirty |= WM_DIRTY_LP_ALL; |
| 2695 | } |
| 2696 | |
| 2697 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2698 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2699 | /* Must disable LP1+ watermarks too */ |
| 2700 | dirty |= WM_DIRTY_LP_ALL; |
| 2701 | } |
| 2702 | } |
| 2703 | |
| 2704 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2705 | dirty |= WM_DIRTY_FBC; |
| 2706 | /* Must disable LP1+ watermarks too */ |
| 2707 | dirty |= WM_DIRTY_LP_ALL; |
| 2708 | } |
| 2709 | |
| 2710 | if (old->partitioning != new->partitioning) { |
| 2711 | dirty |= WM_DIRTY_DDB; |
| 2712 | /* Must disable LP1+ watermarks too */ |
| 2713 | dirty |= WM_DIRTY_LP_ALL; |
| 2714 | } |
| 2715 | |
| 2716 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2717 | if (dirty & WM_DIRTY_LP_ALL) |
| 2718 | return dirty; |
| 2719 | |
| 2720 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2721 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2722 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2723 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2724 | break; |
| 2725 | } |
| 2726 | |
| 2727 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2728 | for (; wm_lp <= 3; wm_lp++) |
| 2729 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2730 | |
| 2731 | return dirty; |
| 2732 | } |
| 2733 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2734 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2735 | unsigned int dirty) |
| 2736 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2737 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2738 | bool changed = false; |
| 2739 | |
| 2740 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2741 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2742 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2743 | changed = true; |
| 2744 | } |
| 2745 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2746 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2747 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2748 | changed = true; |
| 2749 | } |
| 2750 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2751 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2752 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2753 | changed = true; |
| 2754 | } |
| 2755 | |
| 2756 | /* |
| 2757 | * Don't touch WM1S_LP_EN here. |
| 2758 | * Doing so could cause underruns. |
| 2759 | */ |
| 2760 | |
| 2761 | return changed; |
| 2762 | } |
| 2763 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2764 | /* |
| 2765 | * The spec says we shouldn't write when we don't need, because every write |
| 2766 | * causes WMs to be re-evaluated, expending some power. |
| 2767 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2768 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2769 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2770 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2771 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2772 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2773 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2774 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2775 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2776 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2777 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2778 | return; |
| 2779 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2780 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2781 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2782 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2783 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2784 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2785 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2786 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2787 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2788 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2789 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2790 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2791 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2792 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2793 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2794 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2795 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2796 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2797 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2798 | val = I915_READ(WM_MISC); |
| 2799 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2800 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2801 | else |
| 2802 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2803 | I915_WRITE(WM_MISC, val); |
| 2804 | } else { |
| 2805 | val = I915_READ(DISP_ARB_CTL2); |
| 2806 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2807 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2808 | else |
| 2809 | val |= DISP_DATA_PARTITION_5_6; |
| 2810 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2811 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2812 | } |
| 2813 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2814 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2815 | val = I915_READ(DISP_ARB_CTL); |
| 2816 | if (results->enable_fbc_wm) |
| 2817 | val &= ~DISP_FBC_WM_DIS; |
| 2818 | else |
| 2819 | val |= DISP_FBC_WM_DIS; |
| 2820 | I915_WRITE(DISP_ARB_CTL, val); |
| 2821 | } |
| 2822 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2823 | if (dirty & WM_DIRTY_LP(1) && |
| 2824 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2825 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2826 | |
| 2827 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2828 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2829 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2830 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2831 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2832 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2833 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2834 | 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] | 2835 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2836 | 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] | 2837 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2838 | 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] | 2839 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2840 | |
| 2841 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2842 | } |
| 2843 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2844 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2845 | { |
| 2846 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2847 | |
| 2848 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2849 | } |
| 2850 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2851 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2852 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2853 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2854 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2855 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2856 | struct ilk_wm_maximums max; |
| 2857 | struct ilk_pipe_wm_parameters params = {}; |
| 2858 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2859 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2860 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2861 | 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] | 2862 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2863 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2864 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2865 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2866 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 2867 | |
| 2868 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 2869 | return; |
| 2870 | |
| 2871 | intel_crtc->wm.active = pipe_wm; |
| 2872 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2873 | ilk_compute_wm_config(dev, &config); |
| 2874 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2875 | 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] | 2876 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2877 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2878 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 2879 | if (INTEL_INFO(dev)->gen >= 7 && |
| 2880 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2881 | 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] | 2882 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2883 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2884 | 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] | 2885 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2886 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2887 | } |
| 2888 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2889 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2890 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2891 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2892 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2893 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2894 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2895 | } |
| 2896 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2897 | static void |
| 2898 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 2899 | struct drm_crtc *crtc, |
| 2900 | uint32_t sprite_width, uint32_t sprite_height, |
| 2901 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2902 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2903 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2904 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2905 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2906 | intel_plane->wm.enabled = enabled; |
| 2907 | intel_plane->wm.scaled = scaled; |
| 2908 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2909 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2910 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2911 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2912 | /* |
| 2913 | * IVB workaround: must disable low power watermarks for at least |
| 2914 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 2915 | * when scaling is disabled. |
| 2916 | * |
| 2917 | * WaCxSRDisabledForSpriteScaling:ivb |
| 2918 | */ |
| 2919 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 2920 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 2921 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2922 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2923 | } |
| 2924 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2925 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 2926 | { |
| 2927 | struct drm_device *dev = crtc->dev; |
| 2928 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2929 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2930 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2931 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2932 | enum pipe pipe = intel_crtc->pipe; |
| 2933 | static const unsigned int wm0_pipe_reg[] = { |
| 2934 | [PIPE_A] = WM0_PIPEA_ILK, |
| 2935 | [PIPE_B] = WM0_PIPEB_ILK, |
| 2936 | [PIPE_C] = WM0_PIPEC_IVB, |
| 2937 | }; |
| 2938 | |
| 2939 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2940 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2941 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2942 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2943 | active->pipe_enabled = intel_crtc_active(crtc); |
| 2944 | |
| 2945 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2946 | u32 tmp = hw->wm_pipe[pipe]; |
| 2947 | |
| 2948 | /* |
| 2949 | * For active pipes LP0 watermark is marked as |
| 2950 | * enabled, and LP1+ watermaks as disabled since |
| 2951 | * we can't really reverse compute them in case |
| 2952 | * multiple pipes are active. |
| 2953 | */ |
| 2954 | active->wm[0].enable = true; |
| 2955 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 2956 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 2957 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 2958 | active->linetime = hw->wm_linetime[pipe]; |
| 2959 | } else { |
| 2960 | int level, max_level = ilk_wm_max_level(dev); |
| 2961 | |
| 2962 | /* |
| 2963 | * For inactive pipes, all watermark levels |
| 2964 | * should be marked as enabled but zeroed, |
| 2965 | * which is what we'd compute them to. |
| 2966 | */ |
| 2967 | for (level = 0; level <= max_level; level++) |
| 2968 | active->wm[level].enable = true; |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 2973 | { |
| 2974 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2975 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2976 | struct drm_crtc *crtc; |
| 2977 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2978 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2979 | ilk_pipe_wm_get_hw_state(crtc); |
| 2980 | |
| 2981 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 2982 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 2983 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 2984 | |
| 2985 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 2986 | if (INTEL_INFO(dev)->gen >= 7) { |
| 2987 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 2988 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 2989 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2990 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2991 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2992 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 2993 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 2994 | else if (IS_IVYBRIDGE(dev)) |
| 2995 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 2996 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2997 | |
| 2998 | hw->enable_fbc_wm = |
| 2999 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3000 | } |
| 3001 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3002 | /** |
| 3003 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3004 | * |
| 3005 | * Calculate watermark values for the various WM regs based on current mode |
| 3006 | * and plane configuration. |
| 3007 | * |
| 3008 | * There are several cases to deal with here: |
| 3009 | * - normal (i.e. non-self-refresh) |
| 3010 | * - self-refresh (SR) mode |
| 3011 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3012 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3013 | * lines), so need to account for TLB latency |
| 3014 | * |
| 3015 | * The normal calculation is: |
| 3016 | * watermark = dotclock * bytes per pixel * latency |
| 3017 | * where latency is platform & configuration dependent (we assume pessimal |
| 3018 | * values here). |
| 3019 | * |
| 3020 | * The SR calculation is: |
| 3021 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3022 | * bytes per pixel |
| 3023 | * where |
| 3024 | * line time = htotal / dotclock |
| 3025 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3026 | * and latency is assumed to be high, as above. |
| 3027 | * |
| 3028 | * The final value programmed to the register should always be rounded up, |
| 3029 | * and include an extra 2 entries to account for clock crossings. |
| 3030 | * |
| 3031 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3032 | * to set the non-SR watermarks to 8. |
| 3033 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3034 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3035 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3036 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3037 | |
| 3038 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3039 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3040 | } |
| 3041 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3042 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3043 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3044 | uint32_t sprite_width, |
| 3045 | uint32_t sprite_height, |
| 3046 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3047 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3048 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3049 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3050 | |
| 3051 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3052 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3053 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3054 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3055 | } |
| 3056 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3057 | static struct drm_i915_gem_object * |
| 3058 | intel_alloc_context_page(struct drm_device *dev) |
| 3059 | { |
| 3060 | struct drm_i915_gem_object *ctx; |
| 3061 | int ret; |
| 3062 | |
| 3063 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3064 | |
| 3065 | ctx = i915_gem_alloc_object(dev, 4096); |
| 3066 | if (!ctx) { |
| 3067 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 3068 | return NULL; |
| 3069 | } |
| 3070 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 3071 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3072 | if (ret) { |
| 3073 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 3074 | goto err_unref; |
| 3075 | } |
| 3076 | |
| 3077 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 3078 | if (ret) { |
| 3079 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 3080 | goto err_unpin; |
| 3081 | } |
| 3082 | |
| 3083 | return ctx; |
| 3084 | |
| 3085 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3086 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3087 | err_unref: |
| 3088 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3089 | return NULL; |
| 3090 | } |
| 3091 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3092 | /** |
| 3093 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3094 | */ |
| 3095 | DEFINE_SPINLOCK(mchdev_lock); |
| 3096 | |
| 3097 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3098 | * mchdev_lock. */ |
| 3099 | static struct drm_i915_private *i915_mch_dev; |
| 3100 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3101 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3102 | { |
| 3103 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3104 | u16 rgvswctl; |
| 3105 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3106 | assert_spin_locked(&mchdev_lock); |
| 3107 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3108 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3109 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3110 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3111 | return false; /* still busy with another command */ |
| 3112 | } |
| 3113 | |
| 3114 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3115 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3116 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3117 | POSTING_READ16(MEMSWCTL); |
| 3118 | |
| 3119 | rgvswctl |= MEMCTL_CMD_STS; |
| 3120 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3121 | |
| 3122 | return true; |
| 3123 | } |
| 3124 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3125 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3126 | { |
| 3127 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3128 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3129 | u8 fmax, fmin, fstart, vstart; |
| 3130 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3131 | spin_lock_irq(&mchdev_lock); |
| 3132 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3133 | /* Enable temp reporting */ |
| 3134 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3135 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3136 | |
| 3137 | /* 100ms RC evaluation intervals */ |
| 3138 | I915_WRITE(RCUPEI, 100000); |
| 3139 | I915_WRITE(RCDNEI, 100000); |
| 3140 | |
| 3141 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3142 | I915_WRITE(RCBMAXAVG, 90000); |
| 3143 | I915_WRITE(RCBMINAVG, 80000); |
| 3144 | |
| 3145 | I915_WRITE(MEMIHYST, 1); |
| 3146 | |
| 3147 | /* Set up min, max, and cur for interrupt handling */ |
| 3148 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3149 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3150 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3151 | MEMMODE_FSTART_SHIFT; |
| 3152 | |
| 3153 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3154 | PXVFREQ_PX_SHIFT; |
| 3155 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3156 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3157 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3158 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3159 | dev_priv->ips.max_delay = fstart; |
| 3160 | dev_priv->ips.min_delay = fmin; |
| 3161 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3162 | |
| 3163 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3164 | fmax, fmin, fstart); |
| 3165 | |
| 3166 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3167 | |
| 3168 | /* |
| 3169 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3170 | */ |
| 3171 | |
| 3172 | I915_WRITE(VIDSTART, vstart); |
| 3173 | POSTING_READ(VIDSTART); |
| 3174 | |
| 3175 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3176 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3177 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3178 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3179 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3180 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3181 | |
| 3182 | ironlake_set_drps(dev, fstart); |
| 3183 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3184 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3185 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3186 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3187 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3188 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3189 | |
| 3190 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3191 | } |
| 3192 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3193 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3194 | { |
| 3195 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3196 | u16 rgvswctl; |
| 3197 | |
| 3198 | spin_lock_irq(&mchdev_lock); |
| 3199 | |
| 3200 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3201 | |
| 3202 | /* Ack interrupts, disable EFC interrupt */ |
| 3203 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3204 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3205 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3206 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3207 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3208 | |
| 3209 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3210 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3211 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3212 | rgvswctl |= MEMCTL_CMD_STS; |
| 3213 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3214 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3215 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3216 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3217 | } |
| 3218 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3219 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3220 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3221 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3222 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3223 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3224 | 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] | 3225 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3226 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3227 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3228 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3229 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3230 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3231 | * the hw runs at the minimal clock before selecting the desired |
| 3232 | * frequency, if the down threshold expires in that window we will not |
| 3233 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3234 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3235 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3236 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3237 | |
| 3238 | return limits; |
| 3239 | } |
| 3240 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3241 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3242 | { |
| 3243 | int new_power; |
| 3244 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3245 | if (dev_priv->rps.is_bdw_sw_turbo) |
| 3246 | return; |
| 3247 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3248 | new_power = dev_priv->rps.power; |
| 3249 | switch (dev_priv->rps.power) { |
| 3250 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3251 | 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] | 3252 | new_power = BETWEEN; |
| 3253 | break; |
| 3254 | |
| 3255 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3256 | 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] | 3257 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3258 | 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] | 3259 | new_power = HIGH_POWER; |
| 3260 | break; |
| 3261 | |
| 3262 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3263 | 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] | 3264 | new_power = BETWEEN; |
| 3265 | break; |
| 3266 | } |
| 3267 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3268 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3269 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3270 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3271 | new_power = HIGH_POWER; |
| 3272 | if (new_power == dev_priv->rps.power) |
| 3273 | return; |
| 3274 | |
| 3275 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3276 | switch (new_power) { |
| 3277 | case LOW_POWER: |
| 3278 | /* Upclock if more than 95% busy over 16ms */ |
| 3279 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 3280 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 3281 | |
| 3282 | /* Downclock if less than 85% busy over 32ms */ |
| 3283 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3284 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3285 | |
| 3286 | I915_WRITE(GEN6_RP_CONTROL, |
| 3287 | GEN6_RP_MEDIA_TURBO | |
| 3288 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3289 | GEN6_RP_MEDIA_IS_GFX | |
| 3290 | GEN6_RP_ENABLE | |
| 3291 | GEN6_RP_UP_BUSY_AVG | |
| 3292 | GEN6_RP_DOWN_IDLE_AVG); |
| 3293 | break; |
| 3294 | |
| 3295 | case BETWEEN: |
| 3296 | /* Upclock if more than 90% busy over 13ms */ |
| 3297 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3298 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3299 | |
| 3300 | /* Downclock if less than 75% busy over 32ms */ |
| 3301 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3302 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3303 | |
| 3304 | I915_WRITE(GEN6_RP_CONTROL, |
| 3305 | GEN6_RP_MEDIA_TURBO | |
| 3306 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3307 | GEN6_RP_MEDIA_IS_GFX | |
| 3308 | GEN6_RP_ENABLE | |
| 3309 | GEN6_RP_UP_BUSY_AVG | |
| 3310 | GEN6_RP_DOWN_IDLE_AVG); |
| 3311 | break; |
| 3312 | |
| 3313 | case HIGH_POWER: |
| 3314 | /* Upclock if more than 85% busy over 10ms */ |
| 3315 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3316 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3317 | |
| 3318 | /* Downclock if less than 60% busy over 32ms */ |
| 3319 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3320 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3321 | |
| 3322 | I915_WRITE(GEN6_RP_CONTROL, |
| 3323 | GEN6_RP_MEDIA_TURBO | |
| 3324 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3325 | GEN6_RP_MEDIA_IS_GFX | |
| 3326 | GEN6_RP_ENABLE | |
| 3327 | GEN6_RP_UP_BUSY_AVG | |
| 3328 | GEN6_RP_DOWN_IDLE_AVG); |
| 3329 | break; |
| 3330 | } |
| 3331 | |
| 3332 | dev_priv->rps.power = new_power; |
| 3333 | dev_priv->rps.last_adj = 0; |
| 3334 | } |
| 3335 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3336 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3337 | { |
| 3338 | u32 mask = 0; |
| 3339 | |
| 3340 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3341 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3342 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3343 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3344 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3345 | mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED); |
| 3346 | mask &= dev_priv->pm_rps_events; |
| 3347 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3348 | /* IVB and SNB hard hangs on looping batchbuffer |
| 3349 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 3350 | */ |
| 3351 | if (INTEL_INFO(dev_priv->dev)->gen <= 7 && !IS_HASWELL(dev_priv->dev)) |
| 3352 | mask |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 3353 | |
Deepak S | baccd45 | 2014-05-15 20:58:09 +0300 | [diff] [blame] | 3354 | if (IS_GEN8(dev_priv->dev)) |
| 3355 | mask |= GEN8_PMINTR_REDIRECT_TO_NON_DISP; |
| 3356 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3357 | return ~mask; |
| 3358 | } |
| 3359 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3360 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3361 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3362 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3363 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 3364 | { |
| 3365 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3366 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3367 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3368 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3369 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3370 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3371 | /* min/max delay may still have been modified so be sure to |
| 3372 | * write the limits value. |
| 3373 | */ |
| 3374 | if (val != dev_priv->rps.cur_freq) { |
| 3375 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3376 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3377 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3378 | I915_WRITE(GEN6_RPNSWREQ, |
| 3379 | HSW_FREQUENCY(val)); |
| 3380 | else |
| 3381 | I915_WRITE(GEN6_RPNSWREQ, |
| 3382 | GEN6_FREQUENCY(val) | |
| 3383 | GEN6_OFFSET(0) | |
| 3384 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3385 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3386 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3387 | /* Make sure we continue to get interrupts |
| 3388 | * until we hit the minimum or maximum frequencies. |
| 3389 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3390 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3391 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3392 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3393 | POSTING_READ(GEN6_RPNSWREQ); |
| 3394 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3395 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3396 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3397 | } |
| 3398 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3399 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3400 | * |
| 3401 | * * If Gfx is Idle, then |
| 3402 | * 1. Mask Turbo interrupts |
| 3403 | * 2. Bring up Gfx clock |
| 3404 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3405 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3406 | * 5. Unmask Turbo interrupts |
| 3407 | */ |
| 3408 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3409 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3410 | struct drm_device *dev = dev_priv->dev; |
| 3411 | |
| 3412 | /* Latest VLV doesn't need to force the gfx clock */ |
| 3413 | if (dev->pdev->revision >= 0xd) { |
| 3414 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3415 | return; |
| 3416 | } |
| 3417 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3418 | /* |
| 3419 | * When we are idle. Drop to min voltage state. |
| 3420 | */ |
| 3421 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3422 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3423 | return; |
| 3424 | |
| 3425 | /* Mask turbo interrupt so that they will not come in between */ |
| 3426 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 3427 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3428 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3429 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3430 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3431 | |
| 3432 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3433 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3434 | |
| 3435 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
| 3436 | & GENFREQSTATUS) == 0, 5)) |
| 3437 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3438 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3439 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3440 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3441 | I915_WRITE(GEN6_PMINTRMSK, |
| 3442 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3443 | } |
| 3444 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3445 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3446 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3447 | struct drm_device *dev = dev_priv->dev; |
| 3448 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3449 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3450 | if (dev_priv->rps.enabled) { |
Deepak S | 3463811 | 2014-06-28 11:26:26 +0530 | [diff] [blame] | 3451 | if (IS_CHERRYVIEW(dev)) |
| 3452 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3453 | else if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3454 | vlv_set_rps_idle(dev_priv); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3455 | else if (!dev_priv->rps.is_bdw_sw_turbo |
| 3456 | || atomic_read(&dev_priv->rps.sw_turbo.flip_received)){ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3457 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3460 | dev_priv->rps.last_adj = 0; |
| 3461 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3462 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3463 | } |
| 3464 | |
| 3465 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3466 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3467 | struct drm_device *dev = dev_priv->dev; |
| 3468 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3469 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3470 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3471 | if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3472 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3473 | else if (!dev_priv->rps.is_bdw_sw_turbo |
| 3474 | || atomic_read(&dev_priv->rps.sw_turbo.flip_received)){ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3475 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3478 | dev_priv->rps.last_adj = 0; |
| 3479 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3480 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3481 | } |
| 3482 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3483 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3484 | { |
| 3485 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 3486 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3487 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3488 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3489 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3490 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3491 | 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] | 3492 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 3493 | dev_priv->rps.cur_freq, |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3494 | vlv_gpu_freq(dev_priv, val), val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3495 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 3496 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 3497 | "Odd GPU freq value\n")) |
| 3498 | val &= ~1; |
| 3499 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3500 | if (val != dev_priv->rps.cur_freq) |
| 3501 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3502 | |
Imre Deak | 09c87db | 2014-04-03 20:02:42 +0300 | [diff] [blame] | 3503 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3504 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3505 | dev_priv->rps.cur_freq = val; |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3506 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3509 | static void gen8_disable_rps_interrupts(struct drm_device *dev) |
| 3510 | { |
| 3511 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3512 | if (IS_BROADWELL(dev) && dev_priv->rps.is_bdw_sw_turbo){ |
| 3513 | if (atomic_read(&dev_priv->rps.sw_turbo.flip_received)) |
| 3514 | del_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3515 | dev_priv-> rps.is_bdw_sw_turbo = false; |
| 3516 | } else { |
| 3517 | I915_WRITE(GEN6_PMINTRMSK, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP); |
| 3518 | I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) & |
| 3519 | ~dev_priv->pm_rps_events); |
| 3520 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3521 | * item again unmasking PM interrupts because that is using a different |
| 3522 | * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in |
| 3523 | * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which |
| 3524 | * gen8_enable_rps will clean up. */ |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3525 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3526 | spin_lock_irq(&dev_priv->irq_lock); |
| 3527 | dev_priv->rps.pm_iir = 0; |
| 3528 | spin_unlock_irq(&dev_priv->irq_lock); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3529 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3530 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3531 | } |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3532 | } |
| 3533 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3534 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3535 | { |
| 3536 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3537 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3538 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3539 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & |
| 3540 | ~dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3541 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3542 | * item again unmasking PM interrupts because that is using a different |
| 3543 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 3544 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 3545 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3546 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3547 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3548 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3549 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3550 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3551 | } |
| 3552 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3553 | static void gen6_disable_rps(struct drm_device *dev) |
| 3554 | { |
| 3555 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3556 | |
| 3557 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3558 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 3559 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3560 | if (IS_BROADWELL(dev)) |
| 3561 | gen8_disable_rps_interrupts(dev); |
| 3562 | else |
| 3563 | gen6_disable_rps_interrupts(dev); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3564 | } |
| 3565 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3566 | static void cherryview_disable_rps(struct drm_device *dev) |
| 3567 | { |
| 3568 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3569 | |
| 3570 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 3571 | |
| 3572 | gen8_disable_rps_interrupts(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3573 | } |
| 3574 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3575 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3576 | { |
| 3577 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3578 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3579 | /* we're doing forcewake before Disabling RC6, |
| 3580 | * This what the BIOS expects when going into suspend */ |
| 3581 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 3582 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3583 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3584 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3585 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 3586 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3587 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3590 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3591 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3592 | if (IS_VALLEYVIEW(dev)) { |
| 3593 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3594 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3595 | else |
| 3596 | mode = 0; |
| 3597 | } |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3598 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n", |
| 3599 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3600 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3601 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3604 | 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] | 3605 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3606 | /* No RC6 before Ironlake */ |
| 3607 | if (INTEL_INFO(dev)->gen < 5) |
| 3608 | return 0; |
| 3609 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3610 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3611 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3612 | return 0; |
| 3613 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3614 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3615 | if (enable_rc6 >= 0) { |
| 3616 | int mask; |
| 3617 | |
| 3618 | if (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev)) |
| 3619 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3620 | INTEL_RC6pp_ENABLE; |
| 3621 | else |
| 3622 | mask = INTEL_RC6_ENABLE; |
| 3623 | |
| 3624 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3625 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 3626 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3627 | |
| 3628 | return enable_rc6 & mask; |
| 3629 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3630 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3631 | /* Disable RC6 on Ironlake */ |
| 3632 | if (INTEL_INFO(dev)->gen == 5) |
| 3633 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3634 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3635 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 3636 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3637 | |
| 3638 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3639 | } |
| 3640 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3641 | int intel_enable_rc6(const struct drm_device *dev) |
| 3642 | { |
| 3643 | return i915.enable_rc6; |
| 3644 | } |
| 3645 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3646 | static void gen8_enable_rps_interrupts(struct drm_device *dev) |
| 3647 | { |
| 3648 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3649 | |
| 3650 | spin_lock_irq(&dev_priv->irq_lock); |
| 3651 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 3652 | gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3653 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3654 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3655 | } |
| 3656 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3657 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 3658 | { |
| 3659 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3660 | |
| 3661 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 3662 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 3663 | gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3664 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3665 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3666 | } |
| 3667 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3668 | static void parse_rp_state_cap(struct drm_i915_private *dev_priv, u32 rp_state_cap) |
| 3669 | { |
| 3670 | /* All of these values are in units of 50MHz */ |
| 3671 | dev_priv->rps.cur_freq = 0; |
| 3672 | /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */ |
| 3673 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 3674 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 3675 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 3676 | /* XXX: only BYT has a special efficient freq */ |
| 3677 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 3678 | /* hw_max = RP0 until we check for overclocking */ |
| 3679 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 3680 | |
| 3681 | /* Preserve min/max settings in case of re-init */ |
| 3682 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3683 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3684 | |
| 3685 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 3686 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 3687 | } |
| 3688 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3689 | static void bdw_sw_calculate_freq(struct drm_device *dev, |
| 3690 | struct intel_rps_bdw_cal *c, u32 *cur_time, u32 *c0) |
| 3691 | { |
| 3692 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3693 | u64 busy = 0; |
| 3694 | u32 busyness_pct = 0; |
| 3695 | u32 elapsed_time = 0; |
| 3696 | u16 new_freq = 0; |
| 3697 | |
| 3698 | if (!c || !cur_time || !c0) |
| 3699 | return; |
| 3700 | |
| 3701 | if (0 == c->last_c0) |
| 3702 | goto out; |
| 3703 | |
| 3704 | /* Check Evaluation interval */ |
| 3705 | elapsed_time = *cur_time - c->last_ts; |
| 3706 | if (elapsed_time < c->eval_interval) |
| 3707 | return; |
| 3708 | |
| 3709 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3710 | |
| 3711 | /* |
| 3712 | * c0 unit in 32*1.28 usec, elapsed_time unit in 1 usec. |
| 3713 | * Whole busyness_pct calculation should be |
| 3714 | * busy = ((u64)(*c0 - c->last_c0) << 5 << 7) / 100; |
| 3715 | * busyness_pct = (u32)(busy * 100 / elapsed_time); |
| 3716 | * The final formula is to simplify CPU calculation |
| 3717 | */ |
| 3718 | busy = (u64)(*c0 - c->last_c0) << 12; |
| 3719 | do_div(busy, elapsed_time); |
| 3720 | busyness_pct = (u32)busy; |
| 3721 | |
| 3722 | if (c->is_up && busyness_pct >= c->it_threshold_pct) |
| 3723 | new_freq = (u16)dev_priv->rps.cur_freq + 3; |
| 3724 | if (!c->is_up && busyness_pct <= c->it_threshold_pct) |
| 3725 | new_freq = (u16)dev_priv->rps.cur_freq - 1; |
| 3726 | |
| 3727 | /* Adjust to new frequency busyness and compare with threshold */ |
| 3728 | if (0 != new_freq) { |
| 3729 | if (new_freq > dev_priv->rps.max_freq_softlimit) |
| 3730 | new_freq = dev_priv->rps.max_freq_softlimit; |
| 3731 | else if (new_freq < dev_priv->rps.min_freq_softlimit) |
| 3732 | new_freq = dev_priv->rps.min_freq_softlimit; |
| 3733 | |
| 3734 | gen6_set_rps(dev, new_freq); |
| 3735 | } |
| 3736 | |
| 3737 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3738 | |
| 3739 | out: |
| 3740 | c->last_c0 = *c0; |
| 3741 | c->last_ts = *cur_time; |
| 3742 | } |
| 3743 | |
| 3744 | static void gen8_set_frequency_RP0(struct work_struct *work) |
| 3745 | { |
| 3746 | struct intel_rps_bdw_turbo *p_bdw_turbo = |
| 3747 | container_of(work, struct intel_rps_bdw_turbo, work_max_freq); |
| 3748 | struct intel_gen6_power_mgmt *p_power_mgmt = |
| 3749 | container_of(p_bdw_turbo, struct intel_gen6_power_mgmt, sw_turbo); |
| 3750 | struct drm_i915_private *dev_priv = |
| 3751 | container_of(p_power_mgmt, struct drm_i915_private, rps); |
| 3752 | |
| 3753 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3754 | gen6_set_rps(dev_priv->dev, dev_priv->rps.rp0_freq); |
| 3755 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3756 | } |
| 3757 | |
| 3758 | static void flip_active_timeout_handler(unsigned long var) |
| 3759 | { |
| 3760 | struct drm_i915_private *dev_priv = (struct drm_i915_private *) var; |
| 3761 | |
| 3762 | del_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3763 | atomic_set(&dev_priv->rps.sw_turbo.flip_received, false); |
| 3764 | |
| 3765 | queue_work(dev_priv->wq, &dev_priv->rps.sw_turbo.work_max_freq); |
| 3766 | } |
| 3767 | |
| 3768 | void bdw_software_turbo(struct drm_device *dev) |
| 3769 | { |
| 3770 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3771 | |
| 3772 | u32 current_time = I915_READ(TIMESTAMP_CTR); /* unit in usec */ |
| 3773 | u32 current_c0 = I915_READ(MCHBAR_PCU_C0); /* unit in 32*1.28 usec */ |
| 3774 | |
| 3775 | bdw_sw_calculate_freq(dev, &dev_priv->rps.sw_turbo.up, |
| 3776 | ¤t_time, ¤t_c0); |
| 3777 | bdw_sw_calculate_freq(dev, &dev_priv->rps.sw_turbo.down, |
| 3778 | ¤t_time, ¤t_c0); |
| 3779 | } |
| 3780 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3781 | static void gen8_enable_rps(struct drm_device *dev) |
| 3782 | { |
| 3783 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3784 | struct intel_engine_cs *ring; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3785 | uint32_t rc6_mask = 0, rp_state_cap; |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3786 | uint32_t threshold_up_pct, threshold_down_pct; |
| 3787 | uint32_t ei_up, ei_down; /* up and down evaluation interval */ |
| 3788 | u32 rp_ctl_flag; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3789 | int unused; |
| 3790 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3791 | /* Use software Turbo for BDW */ |
| 3792 | dev_priv->rps.is_bdw_sw_turbo = IS_BROADWELL(dev); |
| 3793 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3794 | /* 1a: Software RC state - RC0 */ |
| 3795 | I915_WRITE(GEN6_RC_STATE, 0); |
| 3796 | |
| 3797 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 3798 | * 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] | 3799 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3800 | |
| 3801 | /* 2a: Disable RC states. */ |
| 3802 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3803 | |
| 3804 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3805 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3806 | |
| 3807 | /* 2b: Program RC6 thresholds.*/ |
| 3808 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 3809 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 3810 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 3811 | for_each_ring(ring, dev_priv, unused) |
| 3812 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3813 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3814 | if (IS_BROADWELL(dev)) |
| 3815 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 3816 | else |
| 3817 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3818 | |
| 3819 | /* 3: Enable RC6 */ |
| 3820 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 3821 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 3822 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3823 | if (IS_BROADWELL(dev)) |
| 3824 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3825 | GEN7_RC_CTL_TO_MODE | |
| 3826 | rc6_mask); |
| 3827 | else |
| 3828 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3829 | GEN6_RC_CTL_EI_MODE(1) | |
| 3830 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3831 | |
| 3832 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 3833 | I915_WRITE(GEN6_RPNSWREQ, |
| 3834 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 3835 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 3836 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3837 | ei_up = 84480; /* 84.48ms */ |
| 3838 | ei_down = 448000; |
| 3839 | threshold_up_pct = 90; /* x percent busy */ |
| 3840 | threshold_down_pct = 70; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3841 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3842 | if (dev_priv->rps.is_bdw_sw_turbo) { |
| 3843 | dev_priv->rps.sw_turbo.up.it_threshold_pct = threshold_up_pct; |
| 3844 | dev_priv->rps.sw_turbo.up.eval_interval = ei_up; |
| 3845 | dev_priv->rps.sw_turbo.up.is_up = true; |
| 3846 | dev_priv->rps.sw_turbo.up.last_ts = 0; |
| 3847 | dev_priv->rps.sw_turbo.up.last_c0 = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3848 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3849 | dev_priv->rps.sw_turbo.down.it_threshold_pct = threshold_down_pct; |
| 3850 | dev_priv->rps.sw_turbo.down.eval_interval = ei_down; |
| 3851 | dev_priv->rps.sw_turbo.down.is_up = false; |
| 3852 | dev_priv->rps.sw_turbo.down.last_ts = 0; |
| 3853 | dev_priv->rps.sw_turbo.down.last_c0 = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3854 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3855 | /* Start the timer to track if flip comes*/ |
| 3856 | dev_priv->rps.sw_turbo.timeout = 200*1000; /* in us */ |
| 3857 | |
| 3858 | init_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3859 | dev_priv->rps.sw_turbo.flip_timer.function = flip_active_timeout_handler; |
| 3860 | dev_priv->rps.sw_turbo.flip_timer.data = (unsigned long) dev_priv; |
| 3861 | dev_priv->rps.sw_turbo.flip_timer.expires = |
| 3862 | usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies; |
| 3863 | add_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3864 | INIT_WORK(&dev_priv->rps.sw_turbo.work_max_freq, gen8_set_frequency_RP0); |
| 3865 | |
| 3866 | atomic_set(&dev_priv->rps.sw_turbo.flip_received, true); |
| 3867 | } else { |
| 3868 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent |
| 3869 | * 1 second timeout*/ |
| 3870 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, FREQ_1_28_US(1000000)); |
| 3871 | |
| 3872 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 3873 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 3874 | dev_priv->rps.max_freq_softlimit << 24 | |
| 3875 | dev_priv->rps.min_freq_softlimit << 16); |
| 3876 | |
| 3877 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
| 3878 | FREQ_1_28_US(ei_up * threshold_up_pct / 100)); |
| 3879 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
| 3880 | FREQ_1_28_US(ei_down * threshold_down_pct / 100)); |
| 3881 | I915_WRITE(GEN6_RP_UP_EI, |
| 3882 | FREQ_1_28_US(ei_up)); |
| 3883 | I915_WRITE(GEN6_RP_DOWN_EI, |
| 3884 | FREQ_1_28_US(ei_down)); |
| 3885 | |
| 3886 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3887 | } |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3888 | |
| 3889 | /* 5: Enable RPS */ |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3890 | rp_ctl_flag = GEN6_RP_MEDIA_TURBO | |
| 3891 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3892 | GEN6_RP_MEDIA_IS_GFX | |
| 3893 | GEN6_RP_UP_BUSY_AVG | |
| 3894 | GEN6_RP_DOWN_IDLE_AVG; |
| 3895 | if (!dev_priv->rps.is_bdw_sw_turbo) |
| 3896 | rp_ctl_flag |= GEN6_RP_ENABLE; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3897 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3898 | I915_WRITE(GEN6_RP_CONTROL, rp_ctl_flag); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3899 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3900 | /* 6: Ring frequency + overclocking |
| 3901 | * (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3902 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3903 | if (!dev_priv->rps.is_bdw_sw_turbo) |
| 3904 | gen8_enable_rps_interrupts(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3905 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3906 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3909 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3910 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3911 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3912 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3913 | u32 rp_state_cap; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3914 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3915 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3916 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3917 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3918 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3919 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3920 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3921 | /* Here begins a magic sequence of register writes to enable |
| 3922 | * auto-downclocking. |
| 3923 | * |
| 3924 | * Perhaps there might be some value in exposing these to |
| 3925 | * userspace... |
| 3926 | */ |
| 3927 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3928 | |
| 3929 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 3930 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 3931 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 3932 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3933 | } |
| 3934 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3935 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3936 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3937 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3938 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3939 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3940 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3941 | /* disable the counters and set deterministic thresholds */ |
| 3942 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3943 | |
| 3944 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 3945 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 3946 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 3947 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3948 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3949 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3950 | for_each_ring(ring, dev_priv, i) |
| 3951 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3952 | |
| 3953 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3954 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 3955 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 3956 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 3957 | else |
| 3958 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 3959 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3960 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 3961 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3962 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3963 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 3964 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 3965 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 3966 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3967 | /* We don't use those on Haswell */ |
| 3968 | if (!IS_HASWELL(dev)) { |
| 3969 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 3970 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3971 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3972 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 3973 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 3974 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3975 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3976 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3977 | |
| 3978 | I915_WRITE(GEN6_RC_CONTROL, |
| 3979 | rc6_mask | |
| 3980 | GEN6_RC_CTL_EI_MODE(1) | |
| 3981 | GEN6_RC_CTL_HW_ENABLE); |
| 3982 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3983 | /* Power down if completely idle for over 50ms */ |
| 3984 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3985 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3986 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3987 | 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] | 3988 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3989 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3990 | |
| 3991 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 3992 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 3993 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3994 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3995 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3996 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3997 | } |
| 3998 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3999 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4000 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4001 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4002 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4003 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4004 | rc6vids = 0; |
| 4005 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4006 | if (IS_GEN6(dev) && ret) { |
| 4007 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4008 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4009 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4010 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4011 | rc6vids &= 0xffff00; |
| 4012 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4013 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4014 | if (ret) |
| 4015 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4016 | } |
| 4017 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4018 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4019 | } |
| 4020 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4021 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4022 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4023 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4024 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4025 | unsigned int gpu_freq; |
| 4026 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4027 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4028 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4029 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4030 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4031 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4032 | policy = cpufreq_cpu_get(0); |
| 4033 | if (policy) { |
| 4034 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4035 | cpufreq_cpu_put(policy); |
| 4036 | } else { |
| 4037 | /* |
| 4038 | * Default to measured freq if none found, PCU will ensure we |
| 4039 | * don't go over |
| 4040 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4041 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4042 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4043 | |
| 4044 | /* Convert from kHz to MHz */ |
| 4045 | max_ia_freq /= 1000; |
| 4046 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4047 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4048 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4049 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4050 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4051 | /* |
| 4052 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4053 | * to use for memory access. We do this by specifying the IA frequency |
| 4054 | * the PCU should use as a reference to determine the ring frequency. |
| 4055 | */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4056 | 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] | 4057 | gpu_freq--) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4058 | int diff = dev_priv->rps.max_freq_softlimit - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4059 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4060 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4061 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4062 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4063 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4064 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4065 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4066 | ring_freq = max(min_ring_freq, ring_freq); |
| 4067 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4068 | } else { |
| 4069 | /* On older processors, there is no separate ring |
| 4070 | * clock domain, so in order to boost the bandwidth |
| 4071 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4072 | * |
| 4073 | * For GPU frequencies less than 750MHz, |
| 4074 | * just use the lowest ring freq. |
| 4075 | */ |
| 4076 | if (gpu_freq < min_freq) |
| 4077 | ia_freq = 800; |
| 4078 | else |
| 4079 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4080 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4081 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4082 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4083 | sandybridge_pcode_write(dev_priv, |
| 4084 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4085 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4086 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4087 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4088 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4089 | } |
| 4090 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4091 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4092 | { |
| 4093 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4094 | |
| 4095 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4096 | return; |
| 4097 | |
| 4098 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4099 | __gen6_update_ring_freq(dev); |
| 4100 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4101 | } |
| 4102 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4103 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4104 | { |
| 4105 | u32 val, rp0; |
| 4106 | |
| 4107 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4108 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4109 | |
| 4110 | return rp0; |
| 4111 | } |
| 4112 | |
| 4113 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4114 | { |
| 4115 | u32 val, rpe; |
| 4116 | |
| 4117 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4118 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4119 | |
| 4120 | return rpe; |
| 4121 | } |
| 4122 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4123 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4124 | { |
| 4125 | u32 val, rp1; |
| 4126 | |
| 4127 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4128 | rp1 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4129 | |
| 4130 | return rp1; |
| 4131 | } |
| 4132 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4133 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4134 | { |
| 4135 | u32 val, rpn; |
| 4136 | |
| 4137 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4138 | rpn = (val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK; |
| 4139 | return rpn; |
| 4140 | } |
| 4141 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4142 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4143 | { |
| 4144 | u32 val, rp1; |
| 4145 | |
| 4146 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4147 | |
| 4148 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4149 | |
| 4150 | return rp1; |
| 4151 | } |
| 4152 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4153 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4154 | { |
| 4155 | u32 val, rp0; |
| 4156 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4157 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4158 | |
| 4159 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4160 | /* Clamp to max */ |
| 4161 | rp0 = min_t(u32, rp0, 0xea); |
| 4162 | |
| 4163 | return rp0; |
| 4164 | } |
| 4165 | |
| 4166 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4167 | { |
| 4168 | u32 val, rpe; |
| 4169 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4170 | 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] | 4171 | 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] | 4172 | 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] | 4173 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4174 | |
| 4175 | return rpe; |
| 4176 | } |
| 4177 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4178 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4179 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4180 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4183 | /* Check that the pctx buffer wasn't move under us. */ |
| 4184 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4185 | { |
| 4186 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4187 | |
| 4188 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4189 | dev_priv->vlv_pctx->stolen->start); |
| 4190 | } |
| 4191 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4192 | |
| 4193 | /* Check that the pcbr address is not empty. */ |
| 4194 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4195 | { |
| 4196 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4197 | |
| 4198 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4199 | } |
| 4200 | |
| 4201 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4202 | { |
| 4203 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4204 | unsigned long pctx_paddr, paddr; |
| 4205 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4206 | u32 pcbr; |
| 4207 | int pctx_size = 32*1024; |
| 4208 | |
| 4209 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4210 | |
| 4211 | pcbr = I915_READ(VLV_PCBR); |
| 4212 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
| 4213 | paddr = (dev_priv->mm.stolen_base + |
| 4214 | (gtt->stolen_size - pctx_size)); |
| 4215 | |
| 4216 | pctx_paddr = (paddr & (~4095)); |
| 4217 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4218 | } |
| 4219 | } |
| 4220 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4221 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4222 | { |
| 4223 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4224 | struct drm_i915_gem_object *pctx; |
| 4225 | unsigned long pctx_paddr; |
| 4226 | u32 pcbr; |
| 4227 | int pctx_size = 24*1024; |
| 4228 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4229 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4230 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4231 | pcbr = I915_READ(VLV_PCBR); |
| 4232 | if (pcbr) { |
| 4233 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4234 | int pcbr_offset; |
| 4235 | |
| 4236 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4237 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4238 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4239 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4240 | pctx_size); |
| 4241 | goto out; |
| 4242 | } |
| 4243 | |
| 4244 | /* |
| 4245 | * From the Gunit register HAS: |
| 4246 | * The Gfx driver is expected to program this register and ensure |
| 4247 | * proper allocation within Gfx stolen memory. For example, this |
| 4248 | * register should be programmed such than the PCBR range does not |
| 4249 | * overlap with other ranges, such as the frame buffer, protected |
| 4250 | * memory, or any other relevant ranges. |
| 4251 | */ |
| 4252 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4253 | if (!pctx) { |
| 4254 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4255 | return; |
| 4256 | } |
| 4257 | |
| 4258 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4259 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4260 | |
| 4261 | out: |
| 4262 | dev_priv->vlv_pctx = pctx; |
| 4263 | } |
| 4264 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4265 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4266 | { |
| 4267 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4268 | |
| 4269 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4270 | return; |
| 4271 | |
| 4272 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4273 | dev_priv->vlv_pctx = NULL; |
| 4274 | } |
| 4275 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4276 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4277 | { |
| 4278 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4279 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4280 | |
| 4281 | valleyview_setup_pctx(dev); |
| 4282 | |
| 4283 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4284 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4285 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4286 | switch ((val >> 6) & 3) { |
| 4287 | case 0: |
| 4288 | case 1: |
| 4289 | dev_priv->mem_freq = 800; |
| 4290 | break; |
| 4291 | case 2: |
| 4292 | dev_priv->mem_freq = 1066; |
| 4293 | break; |
| 4294 | case 3: |
| 4295 | dev_priv->mem_freq = 1333; |
| 4296 | break; |
| 4297 | } |
| 4298 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
| 4299 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4300 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4301 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4302 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 4303 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 4304 | dev_priv->rps.max_freq); |
| 4305 | |
| 4306 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4307 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 4308 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4309 | dev_priv->rps.efficient_freq); |
| 4310 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4311 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4312 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
| 4313 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 4314 | dev_priv->rps.rp1_freq); |
| 4315 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4316 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4317 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 4318 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 4319 | dev_priv->rps.min_freq); |
| 4320 | |
| 4321 | /* Preserve min/max settings in case of re-init */ |
| 4322 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4323 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4324 | |
| 4325 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4326 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4327 | |
| 4328 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4329 | } |
| 4330 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4331 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4332 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4333 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4334 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4335 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4336 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4337 | |
| 4338 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4339 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4340 | val = vlv_punit_read(dev_priv, CCK_FUSE_REG); |
| 4341 | switch ((val >> 2) & 0x7) { |
| 4342 | case 0: |
| 4343 | case 1: |
| 4344 | dev_priv->rps.cz_freq = 200; |
| 4345 | dev_priv->mem_freq = 1600; |
| 4346 | break; |
| 4347 | case 2: |
| 4348 | dev_priv->rps.cz_freq = 267; |
| 4349 | dev_priv->mem_freq = 1600; |
| 4350 | break; |
| 4351 | case 3: |
| 4352 | dev_priv->rps.cz_freq = 333; |
| 4353 | dev_priv->mem_freq = 2000; |
| 4354 | break; |
| 4355 | case 4: |
| 4356 | dev_priv->rps.cz_freq = 320; |
| 4357 | dev_priv->mem_freq = 1600; |
| 4358 | break; |
| 4359 | case 5: |
| 4360 | dev_priv->rps.cz_freq = 400; |
| 4361 | dev_priv->mem_freq = 1600; |
| 4362 | break; |
| 4363 | } |
| 4364 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
| 4365 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4366 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4367 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4368 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 4369 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 4370 | dev_priv->rps.max_freq); |
| 4371 | |
| 4372 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4373 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 4374 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4375 | dev_priv->rps.efficient_freq); |
| 4376 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4377 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4378 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
| 4379 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 4380 | dev_priv->rps.rp1_freq); |
| 4381 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4382 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4383 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 4384 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 4385 | dev_priv->rps.min_freq); |
| 4386 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4387 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4388 | dev_priv->rps.efficient_freq | |
| 4389 | dev_priv->rps.rp1_freq | |
| 4390 | dev_priv->rps.min_freq) & 1, |
| 4391 | "Odd GPU freq values\n"); |
| 4392 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4393 | /* Preserve min/max settings in case of re-init */ |
| 4394 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4395 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4396 | |
| 4397 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4398 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4399 | |
| 4400 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4401 | } |
| 4402 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4403 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4404 | { |
| 4405 | valleyview_cleanup_pctx(dev); |
| 4406 | } |
| 4407 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4408 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4409 | { |
| 4410 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4411 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4412 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4413 | int i; |
| 4414 | |
| 4415 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4416 | |
| 4417 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4418 | if (gtfifodbg) { |
| 4419 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4420 | gtfifodbg); |
| 4421 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4422 | } |
| 4423 | |
| 4424 | cherryview_check_pctx(dev_priv); |
| 4425 | |
| 4426 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4427 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
| 4428 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 4429 | |
| 4430 | /* 2a: Program RC6 thresholds.*/ |
| 4431 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4432 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4433 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4434 | |
| 4435 | for_each_ring(ring, dev_priv, i) |
| 4436 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4437 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4438 | |
| 4439 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 4440 | |
| 4441 | /* allows RC6 residency counter to work */ |
| 4442 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4443 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4444 | VLV_MEDIA_RC6_COUNT_EN | |
| 4445 | VLV_RENDER_RC6_COUNT_EN)); |
| 4446 | |
| 4447 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 4448 | pcbr = I915_READ(VLV_PCBR); |
| 4449 | |
| 4450 | DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr); |
| 4451 | |
| 4452 | /* 3: Enable RC6 */ |
| 4453 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 4454 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
| 4455 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 4456 | |
| 4457 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 4458 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4459 | /* 4 Program defaults and thresholds for RPS*/ |
| 4460 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4461 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4462 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4463 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4464 | |
| 4465 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4466 | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4467 | /* WaDisablePwrmtrEvent:chv (pre-production hw) */ |
| 4468 | I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff); |
| 4469 | I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00); |
| 4470 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4471 | /* 5: Enable RPS */ |
| 4472 | I915_WRITE(GEN6_RP_CONTROL, |
| 4473 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4474 | GEN6_RP_MEDIA_IS_GFX | /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4475 | GEN6_RP_ENABLE | |
| 4476 | GEN6_RP_UP_BUSY_AVG | |
| 4477 | GEN6_RP_DOWN_IDLE_AVG); |
| 4478 | |
| 4479 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4480 | |
| 4481 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4482 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4483 | |
| 4484 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 4485 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
| 4486 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4487 | dev_priv->rps.cur_freq); |
| 4488 | |
| 4489 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
| 4490 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4491 | dev_priv->rps.efficient_freq); |
| 4492 | |
| 4493 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 4494 | |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 4495 | gen8_enable_rps_interrupts(dev); |
| 4496 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4497 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 4498 | } |
| 4499 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4500 | static void valleyview_enable_rps(struct drm_device *dev) |
| 4501 | { |
| 4502 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4503 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4504 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4505 | int i; |
| 4506 | |
| 4507 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4508 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4509 | valleyview_check_pctx(dev_priv); |
| 4510 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4511 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 4512 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4513 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4514 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4515 | } |
| 4516 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4517 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 4518 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4519 | |
| 4520 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4521 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4522 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4523 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4524 | |
| 4525 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4526 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4527 | |
| 4528 | I915_WRITE(GEN6_RP_CONTROL, |
| 4529 | GEN6_RP_MEDIA_TURBO | |
| 4530 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4531 | GEN6_RP_MEDIA_IS_GFX | |
| 4532 | GEN6_RP_ENABLE | |
| 4533 | GEN6_RP_UP_BUSY_AVG | |
| 4534 | GEN6_RP_DOWN_IDLE_CONT); |
| 4535 | |
| 4536 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 4537 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4538 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4539 | |
| 4540 | for_each_ring(ring, dev_priv, i) |
| 4541 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4542 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 4543 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4544 | |
| 4545 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4546 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4547 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 4548 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4549 | VLV_MEDIA_RC6_COUNT_EN | |
| 4550 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4551 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4552 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 4553 | 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] | 4554 | |
| 4555 | intel_print_rc6_info(dev, rc6_mode); |
| 4556 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4557 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4558 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4559 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4560 | |
| 4561 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4562 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4563 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4564 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4565 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4566 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4567 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4568 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4569 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4570 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4571 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4572 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4573 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4574 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4575 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4576 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4577 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4578 | } |
| 4579 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4580 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4581 | { |
| 4582 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4583 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4584 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4585 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4586 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 4587 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4588 | } |
| 4589 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4590 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4591 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4592 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 4593 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4594 | } |
| 4595 | } |
| 4596 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4597 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4598 | { |
| 4599 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4600 | |
| 4601 | if (I915_READ(PWRCTXA)) { |
| 4602 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 4603 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 4604 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 4605 | 50); |
| 4606 | |
| 4607 | I915_WRITE(PWRCTXA, 0); |
| 4608 | POSTING_READ(PWRCTXA); |
| 4609 | |
| 4610 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 4611 | POSTING_READ(RSTDBYCTL); |
| 4612 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 4616 | { |
| 4617 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4618 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4619 | if (dev_priv->ips.renderctx == NULL) |
| 4620 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 4621 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4622 | return -ENOMEM; |
| 4623 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4624 | if (dev_priv->ips.pwrctx == NULL) |
| 4625 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 4626 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4627 | ironlake_teardown_rc6(dev); |
| 4628 | return -ENOMEM; |
| 4629 | } |
| 4630 | |
| 4631 | return 0; |
| 4632 | } |
| 4633 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4634 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4635 | { |
| 4636 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4637 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4638 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4639 | int ret; |
| 4640 | |
| 4641 | /* rc6 disabled by default due to repeated reports of hanging during |
| 4642 | * boot and resume. |
| 4643 | */ |
| 4644 | if (!intel_enable_rc6(dev)) |
| 4645 | return; |
| 4646 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4647 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4648 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4649 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4650 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4651 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4652 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4653 | was_interruptible = dev_priv->mm.interruptible; |
| 4654 | dev_priv->mm.interruptible = false; |
| 4655 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4656 | /* |
| 4657 | * GPU can automatically power down the render unit if given a page |
| 4658 | * to save state. |
| 4659 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4660 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4661 | if (ret) { |
| 4662 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4663 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4664 | return; |
| 4665 | } |
| 4666 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4667 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 4668 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4669 | 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] | 4670 | MI_MM_SPACE_GTT | |
| 4671 | MI_SAVE_EXT_STATE_EN | |
| 4672 | MI_RESTORE_EXT_STATE_EN | |
| 4673 | MI_RESTORE_INHIBIT); |
| 4674 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 4675 | intel_ring_emit(ring, MI_NOOP); |
| 4676 | intel_ring_emit(ring, MI_FLUSH); |
| 4677 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4678 | |
| 4679 | /* |
| 4680 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 4681 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 4682 | * safe to assume that renderctx is valid |
| 4683 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4684 | ret = intel_ring_idle(ring); |
| 4685 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4686 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 4687 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4688 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4689 | return; |
| 4690 | } |
| 4691 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4692 | 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] | 4693 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4694 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4695 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4696 | } |
| 4697 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4698 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 4699 | { |
| 4700 | unsigned long freq; |
| 4701 | int div = (vidfreq & 0x3f0000) >> 16; |
| 4702 | int post = (vidfreq & 0x3000) >> 12; |
| 4703 | int pre = (vidfreq & 0x7); |
| 4704 | |
| 4705 | if (!pre) |
| 4706 | return 0; |
| 4707 | |
| 4708 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 4709 | |
| 4710 | return freq; |
| 4711 | } |
| 4712 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4713 | static const struct cparams { |
| 4714 | u16 i; |
| 4715 | u16 t; |
| 4716 | u16 m; |
| 4717 | u16 c; |
| 4718 | } cparams[] = { |
| 4719 | { 1, 1333, 301, 28664 }, |
| 4720 | { 1, 1066, 294, 24460 }, |
| 4721 | { 1, 800, 294, 25192 }, |
| 4722 | { 0, 1333, 276, 27605 }, |
| 4723 | { 0, 1066, 276, 27605 }, |
| 4724 | { 0, 800, 231, 23784 }, |
| 4725 | }; |
| 4726 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4727 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4728 | { |
| 4729 | u64 total_count, diff, ret; |
| 4730 | u32 count1, count2, count3, m = 0, c = 0; |
| 4731 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 4732 | int i; |
| 4733 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4734 | assert_spin_locked(&mchdev_lock); |
| 4735 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4736 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4737 | |
| 4738 | /* Prevent division-by-zero if we are asking too fast. |
| 4739 | * Also, we don't get interesting results if we are polling |
| 4740 | * faster than once in 10ms, so just return the saved value |
| 4741 | * in such cases. |
| 4742 | */ |
| 4743 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4744 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4745 | |
| 4746 | count1 = I915_READ(DMIEC); |
| 4747 | count2 = I915_READ(DDREC); |
| 4748 | count3 = I915_READ(CSIEC); |
| 4749 | |
| 4750 | total_count = count1 + count2 + count3; |
| 4751 | |
| 4752 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4753 | if (total_count < dev_priv->ips.last_count1) { |
| 4754 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4755 | diff += total_count; |
| 4756 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4757 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4761 | if (cparams[i].i == dev_priv->ips.c_m && |
| 4762 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4763 | m = cparams[i].m; |
| 4764 | c = cparams[i].c; |
| 4765 | break; |
| 4766 | } |
| 4767 | } |
| 4768 | |
| 4769 | diff = div_u64(diff, diff1); |
| 4770 | ret = ((m * diff) + c); |
| 4771 | ret = div_u64(ret, 10); |
| 4772 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4773 | dev_priv->ips.last_count1 = total_count; |
| 4774 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4775 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4776 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4777 | |
| 4778 | return ret; |
| 4779 | } |
| 4780 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4781 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 4782 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4783 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4784 | unsigned long val; |
| 4785 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4786 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4787 | return 0; |
| 4788 | |
| 4789 | spin_lock_irq(&mchdev_lock); |
| 4790 | |
| 4791 | val = __i915_chipset_val(dev_priv); |
| 4792 | |
| 4793 | spin_unlock_irq(&mchdev_lock); |
| 4794 | |
| 4795 | return val; |
| 4796 | } |
| 4797 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4798 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 4799 | { |
| 4800 | unsigned long m, x, b; |
| 4801 | u32 tsfs; |
| 4802 | |
| 4803 | tsfs = I915_READ(TSFS); |
| 4804 | |
| 4805 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 4806 | x = I915_READ8(TR1); |
| 4807 | |
| 4808 | b = tsfs & TSFS_INTR_MASK; |
| 4809 | |
| 4810 | return ((m * x) / 127) - b; |
| 4811 | } |
| 4812 | |
| 4813 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 4814 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4815 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4816 | static const struct v_table { |
| 4817 | u16 vd; /* in .1 mil */ |
| 4818 | u16 vm; /* in .1 mil */ |
| 4819 | } v_table[] = { |
| 4820 | { 0, 0, }, |
| 4821 | { 375, 0, }, |
| 4822 | { 500, 0, }, |
| 4823 | { 625, 0, }, |
| 4824 | { 750, 0, }, |
| 4825 | { 875, 0, }, |
| 4826 | { 1000, 0, }, |
| 4827 | { 1125, 0, }, |
| 4828 | { 4125, 3000, }, |
| 4829 | { 4125, 3000, }, |
| 4830 | { 4125, 3000, }, |
| 4831 | { 4125, 3000, }, |
| 4832 | { 4125, 3000, }, |
| 4833 | { 4125, 3000, }, |
| 4834 | { 4125, 3000, }, |
| 4835 | { 4125, 3000, }, |
| 4836 | { 4125, 3000, }, |
| 4837 | { 4125, 3000, }, |
| 4838 | { 4125, 3000, }, |
| 4839 | { 4125, 3000, }, |
| 4840 | { 4125, 3000, }, |
| 4841 | { 4125, 3000, }, |
| 4842 | { 4125, 3000, }, |
| 4843 | { 4125, 3000, }, |
| 4844 | { 4125, 3000, }, |
| 4845 | { 4125, 3000, }, |
| 4846 | { 4125, 3000, }, |
| 4847 | { 4125, 3000, }, |
| 4848 | { 4125, 3000, }, |
| 4849 | { 4125, 3000, }, |
| 4850 | { 4125, 3000, }, |
| 4851 | { 4125, 3000, }, |
| 4852 | { 4250, 3125, }, |
| 4853 | { 4375, 3250, }, |
| 4854 | { 4500, 3375, }, |
| 4855 | { 4625, 3500, }, |
| 4856 | { 4750, 3625, }, |
| 4857 | { 4875, 3750, }, |
| 4858 | { 5000, 3875, }, |
| 4859 | { 5125, 4000, }, |
| 4860 | { 5250, 4125, }, |
| 4861 | { 5375, 4250, }, |
| 4862 | { 5500, 4375, }, |
| 4863 | { 5625, 4500, }, |
| 4864 | { 5750, 4625, }, |
| 4865 | { 5875, 4750, }, |
| 4866 | { 6000, 4875, }, |
| 4867 | { 6125, 5000, }, |
| 4868 | { 6250, 5125, }, |
| 4869 | { 6375, 5250, }, |
| 4870 | { 6500, 5375, }, |
| 4871 | { 6625, 5500, }, |
| 4872 | { 6750, 5625, }, |
| 4873 | { 6875, 5750, }, |
| 4874 | { 7000, 5875, }, |
| 4875 | { 7125, 6000, }, |
| 4876 | { 7250, 6125, }, |
| 4877 | { 7375, 6250, }, |
| 4878 | { 7500, 6375, }, |
| 4879 | { 7625, 6500, }, |
| 4880 | { 7750, 6625, }, |
| 4881 | { 7875, 6750, }, |
| 4882 | { 8000, 6875, }, |
| 4883 | { 8125, 7000, }, |
| 4884 | { 8250, 7125, }, |
| 4885 | { 8375, 7250, }, |
| 4886 | { 8500, 7375, }, |
| 4887 | { 8625, 7500, }, |
| 4888 | { 8750, 7625, }, |
| 4889 | { 8875, 7750, }, |
| 4890 | { 9000, 7875, }, |
| 4891 | { 9125, 8000, }, |
| 4892 | { 9250, 8125, }, |
| 4893 | { 9375, 8250, }, |
| 4894 | { 9500, 8375, }, |
| 4895 | { 9625, 8500, }, |
| 4896 | { 9750, 8625, }, |
| 4897 | { 9875, 8750, }, |
| 4898 | { 10000, 8875, }, |
| 4899 | { 10125, 9000, }, |
| 4900 | { 10250, 9125, }, |
| 4901 | { 10375, 9250, }, |
| 4902 | { 10500, 9375, }, |
| 4903 | { 10625, 9500, }, |
| 4904 | { 10750, 9625, }, |
| 4905 | { 10875, 9750, }, |
| 4906 | { 11000, 9875, }, |
| 4907 | { 11125, 10000, }, |
| 4908 | { 11250, 10125, }, |
| 4909 | { 11375, 10250, }, |
| 4910 | { 11500, 10375, }, |
| 4911 | { 11625, 10500, }, |
| 4912 | { 11750, 10625, }, |
| 4913 | { 11875, 10750, }, |
| 4914 | { 12000, 10875, }, |
| 4915 | { 12125, 11000, }, |
| 4916 | { 12250, 11125, }, |
| 4917 | { 12375, 11250, }, |
| 4918 | { 12500, 11375, }, |
| 4919 | { 12625, 11500, }, |
| 4920 | { 12750, 11625, }, |
| 4921 | { 12875, 11750, }, |
| 4922 | { 13000, 11875, }, |
| 4923 | { 13125, 12000, }, |
| 4924 | { 13250, 12125, }, |
| 4925 | { 13375, 12250, }, |
| 4926 | { 13500, 12375, }, |
| 4927 | { 13625, 12500, }, |
| 4928 | { 13750, 12625, }, |
| 4929 | { 13875, 12750, }, |
| 4930 | { 14000, 12875, }, |
| 4931 | { 14125, 13000, }, |
| 4932 | { 14250, 13125, }, |
| 4933 | { 14375, 13250, }, |
| 4934 | { 14500, 13375, }, |
| 4935 | { 14625, 13500, }, |
| 4936 | { 14750, 13625, }, |
| 4937 | { 14875, 13750, }, |
| 4938 | { 15000, 13875, }, |
| 4939 | { 15125, 14000, }, |
| 4940 | { 15250, 14125, }, |
| 4941 | { 15375, 14250, }, |
| 4942 | { 15500, 14375, }, |
| 4943 | { 15625, 14500, }, |
| 4944 | { 15750, 14625, }, |
| 4945 | { 15875, 14750, }, |
| 4946 | { 16000, 14875, }, |
| 4947 | { 16125, 15000, }, |
| 4948 | }; |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4949 | if (INTEL_INFO(dev)->is_mobile) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4950 | return v_table[pxvid].vm; |
| 4951 | else |
| 4952 | return v_table[pxvid].vd; |
| 4953 | } |
| 4954 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4955 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4956 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 4957 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4958 | u32 count; |
| 4959 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4960 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4961 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 4962 | now = ktime_get_raw_ns(); |
| 4963 | diffms = now - dev_priv->ips.last_time2; |
| 4964 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4965 | |
| 4966 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4967 | if (!diffms) |
| 4968 | return; |
| 4969 | |
| 4970 | count = I915_READ(GFXEC); |
| 4971 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4972 | if (count < dev_priv->ips.last_count2) { |
| 4973 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4974 | diff += count; |
| 4975 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4976 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4977 | } |
| 4978 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4979 | dev_priv->ips.last_count2 = count; |
| 4980 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4981 | |
| 4982 | /* More magic constants... */ |
| 4983 | diff = diff * 1181; |
| 4984 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4985 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4986 | } |
| 4987 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4988 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 4989 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4990 | struct drm_device *dev = dev_priv->dev; |
| 4991 | |
| 4992 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4993 | return; |
| 4994 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4995 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4996 | |
| 4997 | __i915_update_gfx_val(dev_priv); |
| 4998 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4999 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5000 | } |
| 5001 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5002 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5003 | { |
| 5004 | unsigned long t, corr, state1, corr2, state2; |
| 5005 | u32 pxvid, ext_v; |
| 5006 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5007 | assert_spin_locked(&mchdev_lock); |
| 5008 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5009 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5010 | pxvid = (pxvid >> 24) & 0x7f; |
| 5011 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5012 | |
| 5013 | state1 = ext_v; |
| 5014 | |
| 5015 | t = i915_mch_val(dev_priv); |
| 5016 | |
| 5017 | /* Revel in the empirically derived constants */ |
| 5018 | |
| 5019 | /* Correction factor in 1/100000 units */ |
| 5020 | if (t > 80) |
| 5021 | corr = ((t * 2349) + 135940); |
| 5022 | else if (t >= 50) |
| 5023 | corr = ((t * 964) + 29317); |
| 5024 | else /* < 50 */ |
| 5025 | corr = ((t * 301) + 1004); |
| 5026 | |
| 5027 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5028 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5029 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5030 | |
| 5031 | state2 = (corr2 * state1) / 10000; |
| 5032 | state2 /= 100; /* convert to mW */ |
| 5033 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5034 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5035 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5036 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5037 | } |
| 5038 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5039 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5040 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5041 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5042 | unsigned long val; |
| 5043 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5044 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5045 | return 0; |
| 5046 | |
| 5047 | spin_lock_irq(&mchdev_lock); |
| 5048 | |
| 5049 | val = __i915_gfx_val(dev_priv); |
| 5050 | |
| 5051 | spin_unlock_irq(&mchdev_lock); |
| 5052 | |
| 5053 | return val; |
| 5054 | } |
| 5055 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5056 | /** |
| 5057 | * i915_read_mch_val - return value for IPS use |
| 5058 | * |
| 5059 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5060 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5061 | */ |
| 5062 | unsigned long i915_read_mch_val(void) |
| 5063 | { |
| 5064 | struct drm_i915_private *dev_priv; |
| 5065 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5066 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5067 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5068 | if (!i915_mch_dev) |
| 5069 | goto out_unlock; |
| 5070 | dev_priv = i915_mch_dev; |
| 5071 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5072 | chipset_val = __i915_chipset_val(dev_priv); |
| 5073 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5074 | |
| 5075 | ret = chipset_val + graphics_val; |
| 5076 | |
| 5077 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5078 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5079 | |
| 5080 | return ret; |
| 5081 | } |
| 5082 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5083 | |
| 5084 | /** |
| 5085 | * i915_gpu_raise - raise GPU frequency limit |
| 5086 | * |
| 5087 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5088 | */ |
| 5089 | bool i915_gpu_raise(void) |
| 5090 | { |
| 5091 | struct drm_i915_private *dev_priv; |
| 5092 | bool ret = true; |
| 5093 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5094 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5095 | if (!i915_mch_dev) { |
| 5096 | ret = false; |
| 5097 | goto out_unlock; |
| 5098 | } |
| 5099 | dev_priv = i915_mch_dev; |
| 5100 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5101 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5102 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5103 | |
| 5104 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5105 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5106 | |
| 5107 | return ret; |
| 5108 | } |
| 5109 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5110 | |
| 5111 | /** |
| 5112 | * i915_gpu_lower - lower GPU frequency limit |
| 5113 | * |
| 5114 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5115 | * frequency maximum. |
| 5116 | */ |
| 5117 | bool i915_gpu_lower(void) |
| 5118 | { |
| 5119 | struct drm_i915_private *dev_priv; |
| 5120 | bool ret = true; |
| 5121 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5122 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5123 | if (!i915_mch_dev) { |
| 5124 | ret = false; |
| 5125 | goto out_unlock; |
| 5126 | } |
| 5127 | dev_priv = i915_mch_dev; |
| 5128 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5129 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5130 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5131 | |
| 5132 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5133 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5134 | |
| 5135 | return ret; |
| 5136 | } |
| 5137 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5138 | |
| 5139 | /** |
| 5140 | * i915_gpu_busy - indicate GPU business to IPS |
| 5141 | * |
| 5142 | * Tell the IPS driver whether or not the GPU is busy. |
| 5143 | */ |
| 5144 | bool i915_gpu_busy(void) |
| 5145 | { |
| 5146 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5147 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5148 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5149 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5150 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5151 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5152 | if (!i915_mch_dev) |
| 5153 | goto out_unlock; |
| 5154 | dev_priv = i915_mch_dev; |
| 5155 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5156 | for_each_ring(ring, dev_priv, i) |
| 5157 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5158 | |
| 5159 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5160 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5161 | |
| 5162 | return ret; |
| 5163 | } |
| 5164 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5165 | |
| 5166 | /** |
| 5167 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5168 | * |
| 5169 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5170 | * current frequency to the default. |
| 5171 | */ |
| 5172 | bool i915_gpu_turbo_disable(void) |
| 5173 | { |
| 5174 | struct drm_i915_private *dev_priv; |
| 5175 | bool ret = true; |
| 5176 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5177 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5178 | if (!i915_mch_dev) { |
| 5179 | ret = false; |
| 5180 | goto out_unlock; |
| 5181 | } |
| 5182 | dev_priv = i915_mch_dev; |
| 5183 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5184 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5185 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5186 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5187 | ret = false; |
| 5188 | |
| 5189 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5190 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5191 | |
| 5192 | return ret; |
| 5193 | } |
| 5194 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5195 | |
| 5196 | /** |
| 5197 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5198 | * IPS got loaded first. |
| 5199 | * |
| 5200 | * This awkward dance is so that neither module has to depend on the |
| 5201 | * other in order for IPS to do the appropriate communication of |
| 5202 | * GPU turbo limits to i915. |
| 5203 | */ |
| 5204 | static void |
| 5205 | ips_ping_for_i915_load(void) |
| 5206 | { |
| 5207 | void (*link)(void); |
| 5208 | |
| 5209 | link = symbol_get(ips_link_to_i915_driver); |
| 5210 | if (link) { |
| 5211 | link(); |
| 5212 | symbol_put(ips_link_to_i915_driver); |
| 5213 | } |
| 5214 | } |
| 5215 | |
| 5216 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5217 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5218 | /* We only register the i915 ips part with intel-ips once everything is |
| 5219 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5220 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5221 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5222 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5223 | |
| 5224 | ips_ping_for_i915_load(); |
| 5225 | } |
| 5226 | |
| 5227 | void intel_gpu_ips_teardown(void) |
| 5228 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5229 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5230 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5231 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5232 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5233 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5234 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5235 | { |
| 5236 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5237 | u32 lcfuse; |
| 5238 | u8 pxw[16]; |
| 5239 | int i; |
| 5240 | |
| 5241 | /* Disable to program */ |
| 5242 | I915_WRITE(ECR, 0); |
| 5243 | POSTING_READ(ECR); |
| 5244 | |
| 5245 | /* Program energy weights for various events */ |
| 5246 | I915_WRITE(SDEW, 0x15040d00); |
| 5247 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5248 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5249 | I915_WRITE(CSIEW2, 0x04000004); |
| 5250 | |
| 5251 | for (i = 0; i < 5; i++) |
| 5252 | I915_WRITE(PEW + (i * 4), 0); |
| 5253 | for (i = 0; i < 3; i++) |
| 5254 | I915_WRITE(DEW + (i * 4), 0); |
| 5255 | |
| 5256 | /* Program P-state weights to account for frequency power adjustment */ |
| 5257 | for (i = 0; i < 16; i++) { |
| 5258 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5259 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5260 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5261 | PXVFREQ_PX_SHIFT; |
| 5262 | unsigned long val; |
| 5263 | |
| 5264 | val = vid * vid; |
| 5265 | val *= (freq / 1000); |
| 5266 | val *= 255; |
| 5267 | val /= (127*127*900); |
| 5268 | if (val > 0xff) |
| 5269 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5270 | pxw[i] = val; |
| 5271 | } |
| 5272 | /* Render standby states get 0 weight */ |
| 5273 | pxw[14] = 0; |
| 5274 | pxw[15] = 0; |
| 5275 | |
| 5276 | for (i = 0; i < 4; i++) { |
| 5277 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5278 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5279 | I915_WRITE(PXW + (i * 4), val); |
| 5280 | } |
| 5281 | |
| 5282 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5283 | I915_WRITE(OGW0, 0); |
| 5284 | I915_WRITE(OGW1, 0); |
| 5285 | I915_WRITE(EG0, 0x00007f00); |
| 5286 | I915_WRITE(EG1, 0x0000000e); |
| 5287 | I915_WRITE(EG2, 0x000e0000); |
| 5288 | I915_WRITE(EG3, 0x68000300); |
| 5289 | I915_WRITE(EG4, 0x42000000); |
| 5290 | I915_WRITE(EG5, 0x00140031); |
| 5291 | I915_WRITE(EG6, 0); |
| 5292 | I915_WRITE(EG7, 0); |
| 5293 | |
| 5294 | for (i = 0; i < 8; i++) |
| 5295 | I915_WRITE(PXWL + (i * 4), 0); |
| 5296 | |
| 5297 | /* Enable PMON + select events */ |
| 5298 | I915_WRITE(ECR, 0x80000019); |
| 5299 | |
| 5300 | lcfuse = I915_READ(LCFUSE02); |
| 5301 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5302 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5303 | } |
| 5304 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5305 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5306 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5307 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5308 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5309 | if (IS_CHERRYVIEW(dev)) |
| 5310 | cherryview_init_gt_powersave(dev); |
| 5311 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5312 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5316 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5317 | if (IS_CHERRYVIEW(dev)) |
| 5318 | return; |
| 5319 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5320 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5321 | } |
| 5322 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5323 | /** |
| 5324 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5325 | * @dev: drm device |
| 5326 | * |
| 5327 | * We don't want to disable RC6 or other features here, we just want |
| 5328 | * to make sure any work we've queued has finished and won't bother |
| 5329 | * us while we're suspended. |
| 5330 | */ |
| 5331 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5332 | { |
| 5333 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5334 | |
| 5335 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 5336 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5337 | |
| 5338 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5339 | |
| 5340 | cancel_work_sync(&dev_priv->rps.work); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5341 | |
| 5342 | /* Force GPU to min freq during suspend */ |
| 5343 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5344 | } |
| 5345 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5346 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5347 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5348 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5349 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 5350 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 5351 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 5352 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5353 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5354 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5355 | ironlake_disable_rc6(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5356 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5357 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5358 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5359 | mutex_lock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5360 | if (IS_CHERRYVIEW(dev)) |
| 5361 | cherryview_disable_rps(dev); |
| 5362 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5363 | valleyview_disable_rps(dev); |
| 5364 | else |
| 5365 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5366 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5367 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5368 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5369 | } |
| 5370 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5371 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5372 | { |
| 5373 | struct drm_i915_private *dev_priv = |
| 5374 | container_of(work, struct drm_i915_private, |
| 5375 | rps.delayed_resume_work.work); |
| 5376 | struct drm_device *dev = dev_priv->dev; |
| 5377 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 5378 | dev_priv->rps.is_bdw_sw_turbo = false; |
| 5379 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5380 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5381 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5382 | if (IS_CHERRYVIEW(dev)) { |
| 5383 | cherryview_enable_rps(dev); |
| 5384 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5385 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5386 | } else if (IS_BROADWELL(dev)) { |
| 5387 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5388 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5389 | } else { |
| 5390 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5391 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5392 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5393 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5394 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5395 | |
| 5396 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5399 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5400 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5401 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5402 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5403 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5404 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5405 | ironlake_enable_drps(dev); |
| 5406 | ironlake_enable_rc6(dev); |
| 5407 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5408 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5409 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5410 | /* |
| 5411 | * PCU communication is slow and this doesn't need to be |
| 5412 | * done at any specific time, so do this out of our fast path |
| 5413 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5414 | * |
| 5415 | * We depend on the HW RC6 power context save/restore |
| 5416 | * mechanism when entering D3 through runtime PM suspend. So |
| 5417 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5418 | * get here via the driver load/system resume/runtime resume |
| 5419 | * paths, so the _noresume version is enough (and in case of |
| 5420 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5421 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5422 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5423 | round_jiffies_up_relative(HZ))) |
| 5424 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5428 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5429 | { |
| 5430 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5431 | |
| 5432 | dev_priv->rps.enabled = false; |
| 5433 | intel_enable_gt_powersave(dev); |
| 5434 | } |
| 5435 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5436 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5437 | { |
| 5438 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5439 | |
| 5440 | /* |
| 5441 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5442 | * gating for the panel power sequencer or it will fail to |
| 5443 | * start up when no ports are active. |
| 5444 | */ |
| 5445 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5446 | } |
| 5447 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5448 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5449 | { |
| 5450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5451 | int pipe; |
| 5452 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5453 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5454 | I915_WRITE(DSPCNTR(pipe), |
| 5455 | I915_READ(DSPCNTR(pipe)) | |
| 5456 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5457 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5458 | } |
| 5459 | } |
| 5460 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5461 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5462 | { |
| 5463 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5464 | |
| 5465 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5466 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5467 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5468 | |
| 5469 | /* |
| 5470 | * Don't touch WM1S_LP_EN here. |
| 5471 | * Doing so could cause underruns. |
| 5472 | */ |
| 5473 | } |
| 5474 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5475 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5476 | { |
| 5477 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5478 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5479 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5480 | /* |
| 5481 | * Required for FBC |
| 5482 | * WaFbcDisableDpfcClockGating:ilk |
| 5483 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5484 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5485 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5486 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5487 | |
| 5488 | I915_WRITE(PCH_3DCGDIS0, |
| 5489 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5490 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5491 | I915_WRITE(PCH_3DCGDIS1, |
| 5492 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5493 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5494 | /* |
| 5495 | * According to the spec the following bits should be set in |
| 5496 | * order to enable memory self-refresh |
| 5497 | * The bit 22/21 of 0x42004 |
| 5498 | * The bit 5 of 0x42020 |
| 5499 | * The bit 15 of 0x45000 |
| 5500 | */ |
| 5501 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5502 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5503 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5504 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5505 | I915_WRITE(DISP_ARB_CTL, |
| 5506 | (I915_READ(DISP_ARB_CTL) | |
| 5507 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5508 | |
| 5509 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5510 | |
| 5511 | /* |
| 5512 | * Based on the document from hardware guys the following bits |
| 5513 | * should be set unconditionally in order to enable FBC. |
| 5514 | * The bit 22 of 0x42000 |
| 5515 | * The bit 22 of 0x42004 |
| 5516 | * The bit 7,8,9 of 0x42020. |
| 5517 | */ |
| 5518 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5519 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5520 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5521 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5522 | ILK_FBCQ_DIS); |
| 5523 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5524 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5525 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5526 | } |
| 5527 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5528 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5529 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5530 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5531 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5532 | ILK_ELPIN_409_SELECT); |
| 5533 | I915_WRITE(_3D_CHICKEN2, |
| 5534 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5535 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5536 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5537 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5538 | I915_WRITE(CACHE_MODE_0, |
| 5539 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5540 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5541 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5542 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5543 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5544 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5545 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5546 | ibx_init_clock_gating(dev); |
| 5547 | } |
| 5548 | |
| 5549 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5550 | { |
| 5551 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5552 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5553 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5554 | |
| 5555 | /* |
| 5556 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5557 | * gating for the panel power sequencer or it will fail to |
| 5558 | * start up when no ports are active. |
| 5559 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5560 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5561 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5562 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5563 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5564 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5565 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5566 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5567 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5568 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5569 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5570 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5571 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5572 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5573 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5574 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5575 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5576 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5577 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5578 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5579 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5580 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5581 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5582 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5583 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5584 | } |
| 5585 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5586 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5587 | { |
| 5588 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5589 | uint32_t tmp; |
| 5590 | |
| 5591 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5592 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5593 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5594 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5595 | } |
| 5596 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5597 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5598 | { |
| 5599 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5600 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5601 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5602 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5603 | |
| 5604 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5605 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5606 | ILK_ELPIN_409_SELECT); |
| 5607 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5608 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5609 | I915_WRITE(_3D_CHICKEN, |
| 5610 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5611 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5612 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 5613 | if (IS_SNB_GT1(dev)) |
| 5614 | I915_WRITE(GEN6_GT_MODE, |
| 5615 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 5616 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5617 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5618 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5619 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5620 | /* |
| 5621 | * BSpec recoomends 8x4 when MSAA is used, |
| 5622 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5623 | * |
| 5624 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5625 | * disable bit, which we don't touch here, but it's good |
| 5626 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5627 | */ |
| 5628 | I915_WRITE(GEN6_GT_MODE, |
| 5629 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5630 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5631 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5632 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5633 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5634 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5635 | |
| 5636 | I915_WRITE(GEN6_UCGCTL1, |
| 5637 | I915_READ(GEN6_UCGCTL1) | |
| 5638 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5639 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5640 | |
| 5641 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5642 | * gating disable must be set. Failure to set it results in |
| 5643 | * flickering pixels due to Z write ordering failures after |
| 5644 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5645 | * Sanctuary and Tropics, and apparently anything else with |
| 5646 | * alpha test or pixel discard. |
| 5647 | * |
| 5648 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 5649 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5650 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 5651 | * WaDisableRCCUnitClockGating:snb |
| 5652 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5653 | */ |
| 5654 | I915_WRITE(GEN6_UCGCTL2, |
| 5655 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 5656 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 5657 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 5658 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 5659 | I915_WRITE(_3D_CHICKEN3, |
| 5660 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5661 | |
| 5662 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 5663 | * Bspec says: |
| 5664 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 5665 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 5666 | */ |
| 5667 | I915_WRITE(_3D_CHICKEN3, |
| 5668 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 5669 | |
| 5670 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5671 | * According to the spec the following bits should be |
| 5672 | * set in order to enable memory self-refresh and fbc: |
| 5673 | * The bit21 and bit22 of 0x42000 |
| 5674 | * The bit21 and bit22 of 0x42004 |
| 5675 | * The bit5 and bit7 of 0x42020 |
| 5676 | * The bit14 of 0x70180 |
| 5677 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5678 | * |
| 5679 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5680 | */ |
| 5681 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5682 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5683 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 5684 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5685 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5686 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5687 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 5688 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 5689 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 5690 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5691 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5692 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 5693 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5694 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5695 | |
| 5696 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5697 | } |
| 5698 | |
| 5699 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 5700 | { |
| 5701 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 5702 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5703 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5704 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5705 | * |
| 5706 | * This actually overrides the dispatch |
| 5707 | * mode for all thread types. |
| 5708 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5709 | reg &= ~GEN7_FF_SCHED_MASK; |
| 5710 | reg |= GEN7_FF_TS_SCHED_HW; |
| 5711 | reg |= GEN7_FF_VS_SCHED_HW; |
| 5712 | reg |= GEN7_FF_DS_SCHED_HW; |
| 5713 | |
| 5714 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 5715 | } |
| 5716 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5717 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 5718 | { |
| 5719 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5720 | |
| 5721 | /* |
| 5722 | * TODO: this bit should only be enabled when really needed, then |
| 5723 | * disabled when not needed anymore in order to save power. |
| 5724 | */ |
| 5725 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 5726 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 5727 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 5728 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 5729 | |
| 5730 | /* WADPOClockGatingDisable:hsw */ |
| 5731 | I915_WRITE(_TRANSA_CHICKEN1, |
| 5732 | I915_READ(_TRANSA_CHICKEN1) | |
| 5733 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5734 | } |
| 5735 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5736 | static void lpt_suspend_hw(struct drm_device *dev) |
| 5737 | { |
| 5738 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5739 | |
| 5740 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 5741 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 5742 | |
| 5743 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 5744 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 5745 | } |
| 5746 | } |
| 5747 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 5748 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5749 | { |
| 5750 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5751 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5752 | |
| 5753 | I915_WRITE(WM3_LP_ILK, 0); |
| 5754 | I915_WRITE(WM2_LP_ILK, 0); |
| 5755 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5756 | |
| 5757 | /* FIXME(BDW): Check all the w/a, some might only apply to |
| 5758 | * pre-production hw. */ |
| 5759 | |
Kenneth Graunke | c8966e1 | 2014-02-26 23:59:30 -0800 | [diff] [blame] | 5760 | |
Ben Widawsky | 4afe8d3 | 2013-11-02 21:07:55 -0700 | [diff] [blame] | 5761 | I915_WRITE(GAMTARBMODE, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE)); |
| 5762 | |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5763 | I915_WRITE(_3D_CHICKEN3, |
Michel Thierry | b3f9ad9 | 2014-07-07 12:40:17 +0100 | [diff] [blame] | 5764 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2))); |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5765 | |
Ben Widawsky | 242a401 | 2014-04-18 18:04:29 -0300 | [diff] [blame] | 5766 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5767 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5768 | 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] | 5769 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5770 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5771 | I915_WRITE(CHICKEN_PAR1_1, |
| 5772 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 5773 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5774 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5775 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5776 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 5777 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 5778 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5779 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 5780 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5781 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 5782 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 5783 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5784 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5785 | ~(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] | 5786 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 5787 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5788 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 5789 | |
| 5790 | /* WaDisableSDEUnitClockGating:bdw */ |
| 5791 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5792 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 5793 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 5794 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5797 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 5798 | { |
| 5799 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5800 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5801 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5802 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 5803 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 5804 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 5805 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 5806 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 5807 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5808 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5809 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5810 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5811 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5812 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 5813 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 5814 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5815 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5816 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5817 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 5818 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5819 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 5820 | /* enable HiZ Raw Stall Optimization */ |
| 5821 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5822 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5823 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5824 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5825 | I915_WRITE(CACHE_MODE_1, |
| 5826 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5827 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5828 | /* |
| 5829 | * BSpec recommends 8x4 when MSAA is used, |
| 5830 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5831 | * |
| 5832 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5833 | * disable bit, which we don't touch here, but it's good |
| 5834 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5835 | */ |
| 5836 | I915_WRITE(GEN7_GT_MODE, |
| 5837 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5838 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5839 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 5840 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 5841 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 5842 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 5843 | I915_WRITE(CHICKEN_PAR1_1, |
| 5844 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5845 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5846 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5847 | } |
| 5848 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5849 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5850 | { |
| 5851 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5852 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5853 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5854 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5855 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5856 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5857 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5858 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5859 | I915_WRITE(_3D_CHICKEN3, |
| 5860 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5861 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5862 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5863 | I915_WRITE(IVB_CHICKEN3, |
| 5864 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5865 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5866 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5867 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5868 | if (IS_IVB_GT1(dev)) |
| 5869 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5870 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5871 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5872 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 5873 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5874 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5875 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5876 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 5877 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 5878 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5879 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5880 | I915_WRITE(GEN7_L3CNTLREG1, |
| 5881 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 5882 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5883 | GEN7_WA_L3_CHICKEN_MODE); |
| 5884 | if (IS_IVB_GT1(dev)) |
| 5885 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5886 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5887 | else { |
| 5888 | /* must write both registers */ |
| 5889 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5890 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5891 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 5892 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5893 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5894 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5895 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5896 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5897 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5898 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 5899 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5900 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5901 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5902 | */ |
| 5903 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 5904 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5905 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5906 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5907 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5908 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5909 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5910 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5911 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5912 | |
| 5913 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5914 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 5915 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 5916 | /* enable HiZ Raw Stall Optimization */ |
| 5917 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5918 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5919 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 5920 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5921 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5922 | I915_WRITE(CACHE_MODE_1, |
| 5923 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5924 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5925 | /* |
| 5926 | * BSpec recommends 8x4 when MSAA is used, |
| 5927 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5928 | * |
| 5929 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5930 | * disable bit, which we don't touch here, but it's good |
| 5931 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5932 | */ |
| 5933 | I915_WRITE(GEN7_GT_MODE, |
| 5934 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5935 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5936 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 5937 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 5938 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 5939 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5940 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 5941 | if (!HAS_PCH_NOP(dev)) |
| 5942 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5943 | |
| 5944 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5945 | } |
| 5946 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5947 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5948 | { |
| 5949 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5950 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 5951 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5952 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5953 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5954 | I915_WRITE(_3D_CHICKEN3, |
| 5955 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5956 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5957 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5958 | I915_WRITE(IVB_CHICKEN3, |
| 5959 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5960 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5961 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 5962 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5963 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5964 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 5965 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 5966 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5967 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5968 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 5969 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5970 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5971 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5972 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5973 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5974 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5975 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5976 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5977 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5978 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5979 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5980 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5981 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5982 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5983 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5984 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 5985 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5986 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5987 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5988 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5989 | */ |
| 5990 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5991 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5992 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 5993 | /* WaDisableL3Bank2xClockGate:vlv |
| 5994 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 5995 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 5996 | I915_WRITE(GEN7_UCGCTL4, |
| 5997 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 5998 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 5999 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6000 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6001 | /* |
| 6002 | * BSpec says this must be set, even though |
| 6003 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6004 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6005 | I915_WRITE(CACHE_MODE_1, |
| 6006 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6007 | |
| 6008 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6009 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6010 | * This is the hardware default actually. |
| 6011 | */ |
| 6012 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6013 | |
| 6014 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6015 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6016 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6017 | * in the reporting of vblank events. |
| 6018 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6019 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6020 | } |
| 6021 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6022 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6023 | { |
| 6024 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6025 | |
| 6026 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6027 | |
| 6028 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6029 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6030 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6031 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6032 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6033 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6034 | ~(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] | 6035 | |
| 6036 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6037 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6038 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6039 | |
| 6040 | /* WaDisableCSUnitClockGating:chv */ |
| 6041 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6042 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6043 | |
| 6044 | /* WaDisableSDEUnitClockGating:chv */ |
| 6045 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6046 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Rafael Barbalho | e0d34ce | 2014-04-09 13:28:40 +0300 | [diff] [blame] | 6047 | |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 6048 | /* WaDisableGunitClockGating:chv (pre-production hw) */ |
| 6049 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, I915_READ(VLV_GUNIT_CLOCK_GATE) | |
| 6050 | GINT_DIS); |
| 6051 | |
| 6052 | /* WaDisableFfDopClockGating:chv (pre-production hw) */ |
| 6053 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6054 | _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE)); |
| 6055 | |
| 6056 | /* WaDisableDopClockGating:chv (pre-production hw) */ |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 6057 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6058 | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6059 | } |
| 6060 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6061 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6062 | { |
| 6063 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6064 | uint32_t dspclk_gate; |
| 6065 | |
| 6066 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6067 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6068 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6069 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6070 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6071 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6072 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6073 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6074 | if (IS_GM45(dev)) |
| 6075 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6076 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6077 | |
| 6078 | /* WaDisableRenderCachePipelinedFlush */ |
| 6079 | I915_WRITE(CACHE_MODE_0, |
| 6080 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6081 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6082 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6083 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6084 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6085 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6086 | } |
| 6087 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6088 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6089 | { |
| 6090 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6091 | |
| 6092 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6093 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6094 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6095 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6096 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6097 | I915_WRITE(MI_ARB_STATE, |
| 6098 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6099 | |
| 6100 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6101 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6102 | } |
| 6103 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6104 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6105 | { |
| 6106 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6107 | |
| 6108 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6109 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6110 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6111 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6112 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6113 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6114 | I915_WRITE(MI_ARB_STATE, |
| 6115 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6116 | |
| 6117 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6118 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6119 | } |
| 6120 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6121 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6122 | { |
| 6123 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6124 | u32 dstate = I915_READ(D_STATE); |
| 6125 | |
| 6126 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6127 | DSTATE_DOT_CLOCK_GATING; |
| 6128 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6129 | |
| 6130 | if (IS_PINEVIEW(dev)) |
| 6131 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6132 | |
| 6133 | /* IIR "flip pending" means done if this bit is set */ |
| 6134 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6135 | |
| 6136 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6137 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6138 | |
| 6139 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6140 | I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6141 | |
| 6142 | I915_WRITE(MI_ARB_STATE, |
| 6143 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6144 | } |
| 6145 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6146 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6147 | { |
| 6148 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6149 | |
| 6150 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6151 | |
| 6152 | /* interrupts should cause a wake up from C3 */ |
| 6153 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6154 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6155 | |
| 6156 | I915_WRITE(MEM_MODE, |
| 6157 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6158 | } |
| 6159 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6160 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6161 | { |
| 6162 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6163 | |
| 6164 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6165 | |
| 6166 | I915_WRITE(MEM_MODE, |
| 6167 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6168 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6169 | } |
| 6170 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6171 | void intel_init_clock_gating(struct drm_device *dev) |
| 6172 | { |
| 6173 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6174 | |
| 6175 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6176 | } |
| 6177 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6178 | void intel_suspend_hw(struct drm_device *dev) |
| 6179 | { |
| 6180 | if (HAS_PCH_LPT(dev)) |
| 6181 | lpt_suspend_hw(dev); |
| 6182 | } |
| 6183 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6184 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 6185 | for (i = 0; \ |
| 6186 | i < (power_domains)->power_well_count && \ |
| 6187 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 6188 | i++) \ |
| 6189 | if ((power_well)->domains & (domain_mask)) |
| 6190 | |
| 6191 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 6192 | for (i = (power_domains)->power_well_count - 1; \ |
| 6193 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 6194 | i--) \ |
| 6195 | if ((power_well)->domains & (domain_mask)) |
| 6196 | |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 6197 | /** |
| 6198 | * We should only use the power well if we explicitly asked the hardware to |
| 6199 | * enable it, so check if it's enabled and also check if we've requested it to |
| 6200 | * be enabled. |
| 6201 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6202 | static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6203 | struct i915_power_well *power_well) |
| 6204 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6205 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 6206 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 6207 | } |
| 6208 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6209 | bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv, |
| 6210 | enum intel_display_power_domain domain) |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6211 | { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6212 | struct i915_power_domains *power_domains; |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6213 | struct i915_power_well *power_well; |
| 6214 | bool is_enabled; |
| 6215 | int i; |
| 6216 | |
| 6217 | if (dev_priv->pm.suspended) |
| 6218 | return false; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6219 | |
| 6220 | power_domains = &dev_priv->power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6221 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6222 | is_enabled = true; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6223 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6224 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 6225 | if (power_well->always_on) |
| 6226 | continue; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6227 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6228 | if (!power_well->hw_enabled) { |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6229 | is_enabled = false; |
| 6230 | break; |
| 6231 | } |
| 6232 | } |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6233 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6234 | return is_enabled; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6235 | } |
| 6236 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6237 | bool intel_display_power_enabled(struct drm_i915_private *dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 6238 | enum intel_display_power_domain domain) |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 6239 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6240 | struct i915_power_domains *power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6241 | bool ret; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 6242 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6243 | power_domains = &dev_priv->power_domains; |
| 6244 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6245 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6246 | ret = intel_display_power_enabled_unlocked(dev_priv, domain); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6247 | mutex_unlock(&power_domains->lock); |
| 6248 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6249 | return ret; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 6250 | } |
| 6251 | |
Imre Deak | 93c73e8 | 2014-02-18 00:02:19 +0200 | [diff] [blame] | 6252 | /* |
| 6253 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 6254 | * when not needed anymore. We have 4 registers that can request the power well |
| 6255 | * to be enabled, and it will only be disabled if none of the registers is |
| 6256 | * requesting it to be enabled. |
| 6257 | */ |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6258 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 6259 | { |
| 6260 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6261 | |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 6262 | /* |
| 6263 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 6264 | * we'll get unclaimed register interrupts. This stops after we write |
| 6265 | * anything to the VGA MSR register. The vgacon module uses this |
| 6266 | * register all the time, so if we unbind our driver and, as a |
| 6267 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 6268 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 6269 | * sure vgacon can keep working normally without triggering interrupts |
| 6270 | * and error messages. |
| 6271 | */ |
| 6272 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6273 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
| 6274 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6275 | |
Paulo Zanoni | d49bdb0 | 2014-07-04 11:50:31 -0300 | [diff] [blame] | 6276 | if (IS_BROADWELL(dev)) |
| 6277 | gen8_irq_power_well_post_enable(dev_priv); |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6278 | } |
| 6279 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6280 | static void hsw_set_power_well(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6281 | struct i915_power_well *power_well, bool enable) |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6282 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6283 | bool is_enabled, enable_requested; |
| 6284 | uint32_t tmp; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6285 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6286 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6287 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 6288 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6289 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6290 | if (enable) { |
| 6291 | if (!enable_requested) |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6292 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 6293 | HSW_PWR_WELL_ENABLE_REQUEST); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6294 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6295 | if (!is_enabled) { |
| 6296 | DRM_DEBUG_KMS("Enabling power well\n"); |
| 6297 | if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) & |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6298 | HSW_PWR_WELL_STATE_ENABLED), 20)) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6299 | DRM_ERROR("Timeout enabling power well\n"); |
| 6300 | } |
Ben Widawsky | 596cc11 | 2013-11-11 14:46:28 -0800 | [diff] [blame] | 6301 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6302 | hsw_power_well_post_enable(dev_priv); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6303 | } else { |
| 6304 | if (enable_requested) { |
| 6305 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 6306 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6307 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6308 | } |
| 6309 | } |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6310 | } |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6311 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6312 | static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6313 | struct i915_power_well *power_well) |
| 6314 | { |
| 6315 | hsw_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6316 | |
| 6317 | /* |
| 6318 | * We're taking over the BIOS, so clear any requests made by it since |
| 6319 | * the driver is in charge now. |
| 6320 | */ |
| 6321 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
| 6322 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 6323 | } |
| 6324 | |
| 6325 | static void hsw_power_well_enable(struct drm_i915_private *dev_priv, |
| 6326 | struct i915_power_well *power_well) |
| 6327 | { |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6328 | hsw_set_power_well(dev_priv, power_well, true); |
| 6329 | } |
| 6330 | |
| 6331 | static void hsw_power_well_disable(struct drm_i915_private *dev_priv, |
| 6332 | struct i915_power_well *power_well) |
| 6333 | { |
| 6334 | hsw_set_power_well(dev_priv, power_well, false); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6335 | } |
| 6336 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6337 | static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv, |
| 6338 | struct i915_power_well *power_well) |
| 6339 | { |
| 6340 | } |
| 6341 | |
| 6342 | static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6343 | struct i915_power_well *power_well) |
| 6344 | { |
| 6345 | return true; |
| 6346 | } |
| 6347 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6348 | static void vlv_set_power_well(struct drm_i915_private *dev_priv, |
| 6349 | struct i915_power_well *power_well, bool enable) |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6350 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6351 | enum punit_power_well power_well_id = power_well->data; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6352 | u32 mask; |
| 6353 | u32 state; |
| 6354 | u32 ctrl; |
| 6355 | |
| 6356 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6357 | state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) : |
| 6358 | PUNIT_PWRGT_PWR_GATE(power_well_id); |
| 6359 | |
| 6360 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6361 | |
| 6362 | #define COND \ |
| 6363 | ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state) |
| 6364 | |
| 6365 | if (COND) |
| 6366 | goto out; |
| 6367 | |
| 6368 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL); |
| 6369 | ctrl &= ~mask; |
| 6370 | ctrl |= state; |
| 6371 | vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl); |
| 6372 | |
| 6373 | if (wait_for(COND, 100)) |
| 6374 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 6375 | state, |
| 6376 | vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL)); |
| 6377 | |
| 6378 | #undef COND |
| 6379 | |
| 6380 | out: |
| 6381 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6382 | } |
| 6383 | |
| 6384 | static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6385 | struct i915_power_well *power_well) |
| 6386 | { |
| 6387 | vlv_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6388 | } |
| 6389 | |
| 6390 | static void vlv_power_well_enable(struct drm_i915_private *dev_priv, |
| 6391 | struct i915_power_well *power_well) |
| 6392 | { |
| 6393 | vlv_set_power_well(dev_priv, power_well, true); |
| 6394 | } |
| 6395 | |
| 6396 | static void vlv_power_well_disable(struct drm_i915_private *dev_priv, |
| 6397 | struct i915_power_well *power_well) |
| 6398 | { |
| 6399 | vlv_set_power_well(dev_priv, power_well, false); |
| 6400 | } |
| 6401 | |
| 6402 | static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6403 | struct i915_power_well *power_well) |
| 6404 | { |
| 6405 | int power_well_id = power_well->data; |
| 6406 | bool enabled = false; |
| 6407 | u32 mask; |
| 6408 | u32 state; |
| 6409 | u32 ctrl; |
| 6410 | |
| 6411 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6412 | ctrl = PUNIT_PWRGT_PWR_ON(power_well_id); |
| 6413 | |
| 6414 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6415 | |
| 6416 | state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask; |
| 6417 | /* |
| 6418 | * We only ever set the power-on and power-gate states, anything |
| 6419 | * else is unexpected. |
| 6420 | */ |
| 6421 | WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) && |
| 6422 | state != PUNIT_PWRGT_PWR_GATE(power_well_id)); |
| 6423 | if (state == ctrl) |
| 6424 | enabled = true; |
| 6425 | |
| 6426 | /* |
| 6427 | * A transient state at this point would mean some unexpected party |
| 6428 | * is poking at the power controls too. |
| 6429 | */ |
| 6430 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask; |
| 6431 | WARN_ON(ctrl != state); |
| 6432 | |
| 6433 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6434 | |
| 6435 | return enabled; |
| 6436 | } |
| 6437 | |
| 6438 | static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, |
| 6439 | struct i915_power_well *power_well) |
| 6440 | { |
| 6441 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6442 | |
| 6443 | vlv_set_power_well(dev_priv, power_well, true); |
| 6444 | |
| 6445 | spin_lock_irq(&dev_priv->irq_lock); |
| 6446 | valleyview_enable_display_irqs(dev_priv); |
| 6447 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6448 | |
| 6449 | /* |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6450 | * During driver initialization/resume we can avoid restoring the |
| 6451 | * part of the HW/SW state that will be inited anyway explicitly. |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6452 | */ |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6453 | if (dev_priv->power_domains.initializing) |
| 6454 | return; |
| 6455 | |
| 6456 | intel_hpd_init(dev_priv->dev); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6457 | |
| 6458 | i915_redisable_vga_power_on(dev_priv->dev); |
| 6459 | } |
| 6460 | |
| 6461 | static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv, |
| 6462 | struct i915_power_well *power_well) |
| 6463 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6464 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6465 | |
| 6466 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6467 | valleyview_disable_display_irqs(dev_priv); |
| 6468 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6469 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6470 | vlv_set_power_well(dev_priv, power_well, false); |
| 6471 | } |
| 6472 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6473 | static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 6474 | struct i915_power_well *power_well) |
| 6475 | { |
| 6476 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6477 | |
| 6478 | /* |
| 6479 | * Enable the CRI clock source so we can get at the |
| 6480 | * display and the reference clock for VGA |
| 6481 | * hotplug / manual detection. |
| 6482 | */ |
| 6483 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6484 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6485 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 6486 | |
| 6487 | vlv_set_power_well(dev_priv, power_well, true); |
| 6488 | |
| 6489 | /* |
| 6490 | * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx - |
| 6491 | * 6. De-assert cmn_reset/side_reset. Same as VLV X0. |
| 6492 | * a. GUnit 0x2110 bit[0] set to 1 (def 0) |
| 6493 | * b. The other bits such as sfr settings / modesel may all |
| 6494 | * be set to 0. |
| 6495 | * |
| 6496 | * This should only be done on init and resume from S3 with |
| 6497 | * both PLLs disabled, or we risk losing DPIO and PLL |
| 6498 | * synchronization. |
| 6499 | */ |
| 6500 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST); |
| 6501 | } |
| 6502 | |
| 6503 | static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 6504 | struct i915_power_well *power_well) |
| 6505 | { |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6506 | enum pipe pipe; |
| 6507 | |
| 6508 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6509 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6510 | for_each_pipe(dev_priv, pipe) |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6511 | assert_pll_disabled(dev_priv, pipe); |
| 6512 | |
| 6513 | /* Assert common reset */ |
| 6514 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST); |
| 6515 | |
| 6516 | vlv_set_power_well(dev_priv, power_well, false); |
| 6517 | } |
| 6518 | |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6519 | static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 6520 | struct i915_power_well *power_well) |
| 6521 | { |
| 6522 | enum dpio_phy phy; |
| 6523 | |
| 6524 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC && |
| 6525 | power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D); |
| 6526 | |
| 6527 | /* |
| 6528 | * Enable the CRI clock source so we can get at the |
| 6529 | * display and the reference clock for VGA |
| 6530 | * hotplug / manual detection. |
| 6531 | */ |
| 6532 | if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
| 6533 | phy = DPIO_PHY0; |
| 6534 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6535 | DPLL_REFA_CLK_ENABLE_VLV); |
| 6536 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6537 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6538 | } else { |
| 6539 | phy = DPIO_PHY1; |
| 6540 | I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) | |
| 6541 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6542 | } |
| 6543 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 6544 | vlv_set_power_well(dev_priv, power_well, true); |
| 6545 | |
| 6546 | /* Poll for phypwrgood signal */ |
| 6547 | if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1)) |
| 6548 | DRM_ERROR("Display PHY %d is not power up\n", phy); |
| 6549 | |
Ville Syrjälä | efd814b | 2014-06-27 19:52:13 +0300 | [diff] [blame] | 6550 | I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) | |
| 6551 | PHY_COM_LANE_RESET_DEASSERT(phy)); |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 6555 | struct i915_power_well *power_well) |
| 6556 | { |
| 6557 | enum dpio_phy phy; |
| 6558 | |
| 6559 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC && |
| 6560 | power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D); |
| 6561 | |
| 6562 | if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
| 6563 | phy = DPIO_PHY0; |
| 6564 | assert_pll_disabled(dev_priv, PIPE_A); |
| 6565 | assert_pll_disabled(dev_priv, PIPE_B); |
| 6566 | } else { |
| 6567 | phy = DPIO_PHY1; |
| 6568 | assert_pll_disabled(dev_priv, PIPE_C); |
| 6569 | } |
| 6570 | |
Ville Syrjälä | efd814b | 2014-06-27 19:52:13 +0300 | [diff] [blame] | 6571 | I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) & |
| 6572 | ~PHY_COM_LANE_RESET_DEASSERT(phy)); |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6573 | |
| 6574 | vlv_set_power_well(dev_priv, power_well, false); |
| 6575 | } |
| 6576 | |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 6577 | static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6578 | struct i915_power_well *power_well) |
| 6579 | { |
| 6580 | enum pipe pipe = power_well->data; |
| 6581 | bool enabled; |
| 6582 | u32 state, ctrl; |
| 6583 | |
| 6584 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6585 | |
| 6586 | state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe); |
| 6587 | /* |
| 6588 | * We only ever set the power-on and power-gate states, anything |
| 6589 | * else is unexpected. |
| 6590 | */ |
| 6591 | WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe)); |
| 6592 | enabled = state == DP_SSS_PWR_ON(pipe); |
| 6593 | |
| 6594 | /* |
| 6595 | * A transient state at this point would mean some unexpected party |
| 6596 | * is poking at the power controls too. |
| 6597 | */ |
| 6598 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe); |
| 6599 | WARN_ON(ctrl << 16 != state); |
| 6600 | |
| 6601 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6602 | |
| 6603 | return enabled; |
| 6604 | } |
| 6605 | |
| 6606 | static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv, |
| 6607 | struct i915_power_well *power_well, |
| 6608 | bool enable) |
| 6609 | { |
| 6610 | enum pipe pipe = power_well->data; |
| 6611 | u32 state; |
| 6612 | u32 ctrl; |
| 6613 | |
| 6614 | state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe); |
| 6615 | |
| 6616 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6617 | |
| 6618 | #define COND \ |
| 6619 | ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state) |
| 6620 | |
| 6621 | if (COND) |
| 6622 | goto out; |
| 6623 | |
| 6624 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 6625 | ctrl &= ~DP_SSC_MASK(pipe); |
| 6626 | ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe); |
| 6627 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl); |
| 6628 | |
| 6629 | if (wait_for(COND, 100)) |
| 6630 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 6631 | state, |
| 6632 | vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ)); |
| 6633 | |
| 6634 | #undef COND |
| 6635 | |
| 6636 | out: |
| 6637 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6638 | } |
| 6639 | |
| 6640 | static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6641 | struct i915_power_well *power_well) |
| 6642 | { |
| 6643 | chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0); |
| 6644 | } |
| 6645 | |
| 6646 | static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv, |
| 6647 | struct i915_power_well *power_well) |
| 6648 | { |
| 6649 | WARN_ON_ONCE(power_well->data != PIPE_A && |
| 6650 | power_well->data != PIPE_B && |
| 6651 | power_well->data != PIPE_C); |
| 6652 | |
| 6653 | chv_set_pipe_power_well(dev_priv, power_well, true); |
| 6654 | } |
| 6655 | |
| 6656 | static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv, |
| 6657 | struct i915_power_well *power_well) |
| 6658 | { |
| 6659 | WARN_ON_ONCE(power_well->data != PIPE_A && |
| 6660 | power_well->data != PIPE_B && |
| 6661 | power_well->data != PIPE_C); |
| 6662 | |
| 6663 | chv_set_pipe_power_well(dev_priv, power_well, false); |
| 6664 | } |
| 6665 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6666 | static void check_power_well_state(struct drm_i915_private *dev_priv, |
| 6667 | struct i915_power_well *power_well) |
| 6668 | { |
| 6669 | bool enabled = power_well->ops->is_enabled(dev_priv, power_well); |
| 6670 | |
| 6671 | if (power_well->always_on || !i915.disable_power_well) { |
| 6672 | if (!enabled) |
| 6673 | goto mismatch; |
| 6674 | |
| 6675 | return; |
| 6676 | } |
| 6677 | |
| 6678 | if (enabled != (power_well->count > 0)) |
| 6679 | goto mismatch; |
| 6680 | |
| 6681 | return; |
| 6682 | |
| 6683 | mismatch: |
| 6684 | WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n", |
| 6685 | power_well->name, power_well->always_on, enabled, |
| 6686 | power_well->count, i915.disable_power_well); |
| 6687 | } |
| 6688 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6689 | void intel_display_power_get(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6690 | enum intel_display_power_domain domain) |
| 6691 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6692 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6693 | struct i915_power_well *power_well; |
| 6694 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6695 | |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6696 | intel_runtime_pm_get(dev_priv); |
| 6697 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6698 | power_domains = &dev_priv->power_domains; |
| 6699 | |
| 6700 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6701 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6702 | for_each_power_well(i, power_well, BIT(domain), power_domains) { |
| 6703 | if (!power_well->count++) { |
| 6704 | DRM_DEBUG_KMS("enabling %s\n", power_well->name); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6705 | power_well->ops->enable(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6706 | power_well->hw_enabled = true; |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | check_power_well_state(dev_priv, power_well); |
| 6710 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6711 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6712 | power_domains->domain_use_count[domain]++; |
| 6713 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6714 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6715 | } |
| 6716 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6717 | void intel_display_power_put(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6718 | enum intel_display_power_domain domain) |
| 6719 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6720 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6721 | struct i915_power_well *power_well; |
| 6722 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6723 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6724 | power_domains = &dev_priv->power_domains; |
| 6725 | |
| 6726 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6727 | |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6728 | WARN_ON(!power_domains->domain_use_count[domain]); |
| 6729 | power_domains->domain_use_count[domain]--; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6730 | |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6731 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 6732 | WARN_ON(!power_well->count); |
| 6733 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6734 | if (!--power_well->count && i915.disable_power_well) { |
| 6735 | DRM_DEBUG_KMS("disabling %s\n", power_well->name); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6736 | power_well->hw_enabled = false; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6737 | power_well->ops->disable(dev_priv, power_well); |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | check_power_well_state(dev_priv, power_well); |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6741 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6742 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6743 | mutex_unlock(&power_domains->lock); |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6744 | |
| 6745 | intel_runtime_pm_put(dev_priv); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6746 | } |
| 6747 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6748 | static struct i915_power_domains *hsw_pwr; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6749 | |
| 6750 | /* Display audio driver power well request */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6751 | int i915_request_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6752 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6753 | struct drm_i915_private *dev_priv; |
| 6754 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6755 | if (!hsw_pwr) |
| 6756 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6757 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6758 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6759 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6760 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6761 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6762 | } |
| 6763 | EXPORT_SYMBOL_GPL(i915_request_power_well); |
| 6764 | |
| 6765 | /* Display audio driver power well release */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6766 | int i915_release_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6767 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6768 | struct drm_i915_private *dev_priv; |
| 6769 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6770 | if (!hsw_pwr) |
| 6771 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6772 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6773 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6774 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6775 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6776 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6777 | } |
| 6778 | EXPORT_SYMBOL_GPL(i915_release_power_well); |
| 6779 | |
Jani Nikula | c149dcb | 2014-07-04 10:00:37 +0800 | [diff] [blame] | 6780 | /* |
| 6781 | * Private interface for the audio driver to get CDCLK in kHz. |
| 6782 | * |
| 6783 | * Caller must request power well using i915_request_power_well() prior to |
| 6784 | * making the call. |
| 6785 | */ |
| 6786 | int i915_get_cdclk_freq(void) |
| 6787 | { |
| 6788 | struct drm_i915_private *dev_priv; |
| 6789 | |
| 6790 | if (!hsw_pwr) |
| 6791 | return -ENODEV; |
| 6792 | |
| 6793 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6794 | power_domains); |
| 6795 | |
| 6796 | return intel_ddi_get_cdclk_freq(dev_priv); |
| 6797 | } |
| 6798 | EXPORT_SYMBOL_GPL(i915_get_cdclk_freq); |
| 6799 | |
| 6800 | |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6801 | #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1) |
| 6802 | |
| 6803 | #define HSW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6804 | BIT(POWER_DOMAIN_PIPE_A) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6805 | BIT(POWER_DOMAIN_TRANSCODER_EDP) | \ |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6806 | BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \ |
| 6807 | BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \ |
| 6808 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6809 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6810 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6811 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6812 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6813 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6814 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 6815 | BIT(POWER_DOMAIN_PLLS) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6816 | BIT(POWER_DOMAIN_INIT)) |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6817 | #define HSW_DISPLAY_POWER_DOMAINS ( \ |
| 6818 | (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6819 | BIT(POWER_DOMAIN_INIT)) |
| 6820 | |
| 6821 | #define BDW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6822 | HSW_ALWAYS_ON_POWER_DOMAINS | \ |
| 6823 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER)) |
| 6824 | #define BDW_DISPLAY_POWER_DOMAINS ( \ |
| 6825 | (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6826 | BIT(POWER_DOMAIN_INIT)) |
| 6827 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6828 | #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT) |
| 6829 | #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK |
| 6830 | |
| 6831 | #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 6832 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6833 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6834 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6835 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6836 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
| 6837 | BIT(POWER_DOMAIN_INIT)) |
| 6838 | |
| 6839 | #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \ |
| 6840 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6841 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6842 | BIT(POWER_DOMAIN_INIT)) |
| 6843 | |
| 6844 | #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \ |
| 6845 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6846 | BIT(POWER_DOMAIN_INIT)) |
| 6847 | |
| 6848 | #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \ |
| 6849 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6850 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6851 | BIT(POWER_DOMAIN_INIT)) |
| 6852 | |
| 6853 | #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \ |
| 6854 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6855 | BIT(POWER_DOMAIN_INIT)) |
| 6856 | |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 6857 | #define CHV_PIPE_A_POWER_DOMAINS ( \ |
| 6858 | BIT(POWER_DOMAIN_PIPE_A) | \ |
| 6859 | BIT(POWER_DOMAIN_INIT)) |
| 6860 | |
| 6861 | #define CHV_PIPE_B_POWER_DOMAINS ( \ |
| 6862 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 6863 | BIT(POWER_DOMAIN_INIT)) |
| 6864 | |
| 6865 | #define CHV_PIPE_C_POWER_DOMAINS ( \ |
| 6866 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 6867 | BIT(POWER_DOMAIN_INIT)) |
| 6868 | |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6869 | #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 6870 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6871 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6872 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6873 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6874 | BIT(POWER_DOMAIN_INIT)) |
| 6875 | |
| 6876 | #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \ |
| 6877 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6878 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6879 | BIT(POWER_DOMAIN_INIT)) |
| 6880 | |
Ville Syrjälä | 2ce147f | 2014-06-28 02:04:13 +0300 | [diff] [blame] | 6881 | #define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \ |
| 6882 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6883 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6884 | BIT(POWER_DOMAIN_INIT)) |
| 6885 | |
| 6886 | #define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \ |
| 6887 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6888 | BIT(POWER_DOMAIN_INIT)) |
| 6889 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6890 | static const struct i915_power_well_ops i9xx_always_on_power_well_ops = { |
| 6891 | .sync_hw = i9xx_always_on_power_well_noop, |
| 6892 | .enable = i9xx_always_on_power_well_noop, |
| 6893 | .disable = i9xx_always_on_power_well_noop, |
| 6894 | .is_enabled = i9xx_always_on_power_well_enabled, |
| 6895 | }; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6896 | |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 6897 | static const struct i915_power_well_ops chv_pipe_power_well_ops = { |
| 6898 | .sync_hw = chv_pipe_power_well_sync_hw, |
| 6899 | .enable = chv_pipe_power_well_enable, |
| 6900 | .disable = chv_pipe_power_well_disable, |
| 6901 | .is_enabled = chv_pipe_power_well_enabled, |
| 6902 | }; |
| 6903 | |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6904 | static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = { |
| 6905 | .sync_hw = vlv_power_well_sync_hw, |
| 6906 | .enable = chv_dpio_cmn_power_well_enable, |
| 6907 | .disable = chv_dpio_cmn_power_well_disable, |
| 6908 | .is_enabled = vlv_power_well_enabled, |
| 6909 | }; |
| 6910 | |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6911 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 6912 | { |
| 6913 | .name = "always-on", |
| 6914 | .always_on = 1, |
| 6915 | .domains = POWER_DOMAIN_MASK, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6916 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6917 | }, |
| 6918 | }; |
| 6919 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6920 | static const struct i915_power_well_ops hsw_power_well_ops = { |
| 6921 | .sync_hw = hsw_power_well_sync_hw, |
| 6922 | .enable = hsw_power_well_enable, |
| 6923 | .disable = hsw_power_well_disable, |
| 6924 | .is_enabled = hsw_power_well_enabled, |
| 6925 | }; |
| 6926 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6927 | static struct i915_power_well hsw_power_wells[] = { |
| 6928 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6929 | .name = "always-on", |
| 6930 | .always_on = 1, |
| 6931 | .domains = HSW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6932 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6933 | }, |
| 6934 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6935 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6936 | .domains = HSW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6937 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6938 | }, |
| 6939 | }; |
| 6940 | |
| 6941 | static struct i915_power_well bdw_power_wells[] = { |
| 6942 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6943 | .name = "always-on", |
| 6944 | .always_on = 1, |
| 6945 | .domains = BDW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6946 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6947 | }, |
| 6948 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6949 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6950 | .domains = BDW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6951 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6952 | }, |
| 6953 | }; |
| 6954 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6955 | static const struct i915_power_well_ops vlv_display_power_well_ops = { |
| 6956 | .sync_hw = vlv_power_well_sync_hw, |
| 6957 | .enable = vlv_display_power_well_enable, |
| 6958 | .disable = vlv_display_power_well_disable, |
| 6959 | .is_enabled = vlv_power_well_enabled, |
| 6960 | }; |
| 6961 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6962 | static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = { |
| 6963 | .sync_hw = vlv_power_well_sync_hw, |
| 6964 | .enable = vlv_dpio_cmn_power_well_enable, |
| 6965 | .disable = vlv_dpio_cmn_power_well_disable, |
| 6966 | .is_enabled = vlv_power_well_enabled, |
| 6967 | }; |
| 6968 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6969 | static const struct i915_power_well_ops vlv_dpio_power_well_ops = { |
| 6970 | .sync_hw = vlv_power_well_sync_hw, |
| 6971 | .enable = vlv_power_well_enable, |
| 6972 | .disable = vlv_power_well_disable, |
| 6973 | .is_enabled = vlv_power_well_enabled, |
| 6974 | }; |
| 6975 | |
| 6976 | static struct i915_power_well vlv_power_wells[] = { |
| 6977 | { |
| 6978 | .name = "always-on", |
| 6979 | .always_on = 1, |
| 6980 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 6981 | .ops = &i9xx_always_on_power_well_ops, |
| 6982 | }, |
| 6983 | { |
| 6984 | .name = "display", |
| 6985 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 6986 | .data = PUNIT_POWER_WELL_DISP2D, |
| 6987 | .ops = &vlv_display_power_well_ops, |
| 6988 | }, |
| 6989 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6990 | .name = "dpio-tx-b-01", |
| 6991 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6992 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6993 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6994 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6995 | .ops = &vlv_dpio_power_well_ops, |
| 6996 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 6997 | }, |
| 6998 | { |
| 6999 | .name = "dpio-tx-b-23", |
| 7000 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7001 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7002 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7003 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7004 | .ops = &vlv_dpio_power_well_ops, |
| 7005 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 7006 | }, |
| 7007 | { |
| 7008 | .name = "dpio-tx-c-01", |
| 7009 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7010 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7011 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7012 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7013 | .ops = &vlv_dpio_power_well_ops, |
| 7014 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 7015 | }, |
| 7016 | { |
| 7017 | .name = "dpio-tx-c-23", |
| 7018 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7019 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7020 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7021 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7022 | .ops = &vlv_dpio_power_well_ops, |
| 7023 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 7024 | }, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 7025 | { |
| 7026 | .name = "dpio-common", |
| 7027 | .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS, |
| 7028 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 7029 | .ops = &vlv_dpio_cmn_power_well_ops, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 7030 | }, |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 7031 | }; |
| 7032 | |
Ville Syrjälä | 4811ff4 | 2014-06-28 02:04:07 +0300 | [diff] [blame] | 7033 | static struct i915_power_well chv_power_wells[] = { |
| 7034 | { |
| 7035 | .name = "always-on", |
| 7036 | .always_on = 1, |
| 7037 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 7038 | .ops = &i9xx_always_on_power_well_ops, |
| 7039 | }, |
Ville Syrjälä | f07057d | 2014-06-28 02:04:10 +0300 | [diff] [blame] | 7040 | #if 0 |
| 7041 | { |
| 7042 | .name = "display", |
| 7043 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 7044 | .data = PUNIT_POWER_WELL_DISP2D, |
| 7045 | .ops = &vlv_display_power_well_ops, |
| 7046 | }, |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 7047 | { |
| 7048 | .name = "pipe-a", |
| 7049 | .domains = CHV_PIPE_A_POWER_DOMAINS, |
| 7050 | .data = PIPE_A, |
| 7051 | .ops = &chv_pipe_power_well_ops, |
| 7052 | }, |
| 7053 | { |
| 7054 | .name = "pipe-b", |
| 7055 | .domains = CHV_PIPE_B_POWER_DOMAINS, |
| 7056 | .data = PIPE_B, |
| 7057 | .ops = &chv_pipe_power_well_ops, |
| 7058 | }, |
| 7059 | { |
| 7060 | .name = "pipe-c", |
| 7061 | .domains = CHV_PIPE_C_POWER_DOMAINS, |
| 7062 | .data = PIPE_C, |
| 7063 | .ops = &chv_pipe_power_well_ops, |
| 7064 | }, |
Ville Syrjälä | f07057d | 2014-06-28 02:04:10 +0300 | [diff] [blame] | 7065 | #endif |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 7066 | { |
| 7067 | .name = "dpio-common-bc", |
Ville Syrjälä | 3dd7b974 | 2014-06-27 19:49:57 +0300 | [diff] [blame] | 7068 | /* |
| 7069 | * XXX: cmnreset for one PHY seems to disturb the other. |
| 7070 | * As a workaround keep both powered on at the same |
| 7071 | * time for now. |
| 7072 | */ |
| 7073 | .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS, |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 7074 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
| 7075 | .ops = &chv_dpio_cmn_power_well_ops, |
| 7076 | }, |
| 7077 | { |
| 7078 | .name = "dpio-common-d", |
Ville Syrjälä | 3dd7b974 | 2014-06-27 19:49:57 +0300 | [diff] [blame] | 7079 | /* |
| 7080 | * XXX: cmnreset for one PHY seems to disturb the other. |
| 7081 | * As a workaround keep both powered on at the same |
| 7082 | * time for now. |
| 7083 | */ |
| 7084 | .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS, |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 7085 | .data = PUNIT_POWER_WELL_DPIO_CMN_D, |
| 7086 | .ops = &chv_dpio_cmn_power_well_ops, |
| 7087 | }, |
Ville Syrjälä | 8258356 | 2014-06-28 02:04:12 +0300 | [diff] [blame] | 7088 | #if 0 |
| 7089 | { |
| 7090 | .name = "dpio-tx-b-01", |
| 7091 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7092 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS, |
| 7093 | .ops = &vlv_dpio_power_well_ops, |
| 7094 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 7095 | }, |
| 7096 | { |
| 7097 | .name = "dpio-tx-b-23", |
| 7098 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7099 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS, |
| 7100 | .ops = &vlv_dpio_power_well_ops, |
| 7101 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 7102 | }, |
| 7103 | { |
| 7104 | .name = "dpio-tx-c-01", |
| 7105 | .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7106 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7107 | .ops = &vlv_dpio_power_well_ops, |
| 7108 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 7109 | }, |
| 7110 | { |
| 7111 | .name = "dpio-tx-c-23", |
| 7112 | .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7113 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7114 | .ops = &vlv_dpio_power_well_ops, |
| 7115 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 7116 | }, |
Ville Syrjälä | 2ce147f | 2014-06-28 02:04:13 +0300 | [diff] [blame] | 7117 | { |
| 7118 | .name = "dpio-tx-d-01", |
| 7119 | .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS | |
| 7120 | CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS, |
| 7121 | .ops = &vlv_dpio_power_well_ops, |
| 7122 | .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_01, |
| 7123 | }, |
| 7124 | { |
| 7125 | .name = "dpio-tx-d-23", |
| 7126 | .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS | |
| 7127 | CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS, |
| 7128 | .ops = &vlv_dpio_power_well_ops, |
| 7129 | .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_23, |
| 7130 | }, |
Ville Syrjälä | 8258356 | 2014-06-28 02:04:12 +0300 | [diff] [blame] | 7131 | #endif |
Ville Syrjälä | 4811ff4 | 2014-06-28 02:04:07 +0300 | [diff] [blame] | 7132 | }; |
| 7133 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7134 | static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv, |
| 7135 | enum punit_power_well power_well_id) |
| 7136 | { |
| 7137 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 7138 | struct i915_power_well *power_well; |
| 7139 | int i; |
| 7140 | |
| 7141 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
| 7142 | if (power_well->data == power_well_id) |
| 7143 | return power_well; |
| 7144 | } |
| 7145 | |
| 7146 | return NULL; |
| 7147 | } |
| 7148 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7149 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 7150 | (power_domains)->power_wells = (__power_wells); \ |
| 7151 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 7152 | }) |
| 7153 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7154 | int intel_power_domains_init(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7155 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7156 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7157 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7158 | mutex_init(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7159 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7160 | /* |
| 7161 | * The enabling order will be from lower to higher indexed wells, |
| 7162 | * the disabling order is reversed. |
| 7163 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7164 | if (IS_HASWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7165 | set_power_wells(power_domains, hsw_power_wells); |
| 7166 | hsw_pwr = power_domains; |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7167 | } else if (IS_BROADWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7168 | set_power_wells(power_domains, bdw_power_wells); |
| 7169 | hsw_pwr = power_domains; |
Ville Syrjälä | 4811ff4 | 2014-06-28 02:04:07 +0300 | [diff] [blame] | 7170 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 7171 | set_power_wells(power_domains, chv_power_wells); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 7172 | } else if (IS_VALLEYVIEW(dev_priv->dev)) { |
| 7173 | set_power_wells(power_domains, vlv_power_wells); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7174 | } else { |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 7175 | set_power_wells(power_domains, i9xx_always_on_power_well); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7176 | } |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7177 | |
| 7178 | return 0; |
| 7179 | } |
| 7180 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7181 | void intel_power_domains_remove(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7182 | { |
| 7183 | hsw_pwr = NULL; |
| 7184 | } |
| 7185 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7186 | 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] | 7187 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7188 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 7189 | struct i915_power_well *power_well; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7190 | int i; |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 7191 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7192 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 7193 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 7194 | power_well->ops->sync_hw(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 7195 | power_well->hw_enabled = power_well->ops->is_enabled(dev_priv, |
| 7196 | power_well); |
| 7197 | } |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7198 | mutex_unlock(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7199 | } |
| 7200 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7201 | static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv) |
| 7202 | { |
| 7203 | struct i915_power_well *cmn = |
| 7204 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 7205 | struct i915_power_well *disp2d = |
| 7206 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D); |
| 7207 | |
| 7208 | /* nothing to do if common lane is already off */ |
| 7209 | if (!cmn->ops->is_enabled(dev_priv, cmn)) |
| 7210 | return; |
| 7211 | |
| 7212 | /* If the display might be already active skip this */ |
| 7213 | if (disp2d->ops->is_enabled(dev_priv, disp2d) && |
| 7214 | I915_READ(DPIO_CTL) & DPIO_CMNRST) |
| 7215 | return; |
| 7216 | |
| 7217 | DRM_DEBUG_KMS("toggling display PHY side reset\n"); |
| 7218 | |
| 7219 | /* cmnlane needs DPLL registers */ |
| 7220 | disp2d->ops->enable(dev_priv, disp2d); |
| 7221 | |
| 7222 | /* |
| 7223 | * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx: |
| 7224 | * Need to assert and de-assert PHY SB reset by gating the |
| 7225 | * common lane power, then un-gating it. |
| 7226 | * Simply ungating isn't enough to reset the PHY enough to get |
| 7227 | * ports and lanes running. |
| 7228 | */ |
| 7229 | cmn->ops->disable(dev_priv, cmn); |
| 7230 | } |
| 7231 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7232 | void intel_power_domains_init_hw(struct drm_i915_private *dev_priv) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 7233 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7234 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 7235 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 7236 | |
| 7237 | power_domains->initializing = true; |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7238 | |
| 7239 | if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
| 7240 | mutex_lock(&power_domains->lock); |
| 7241 | vlv_cmnlane_wa(dev_priv); |
| 7242 | mutex_unlock(&power_domains->lock); |
| 7243 | } |
| 7244 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 7245 | /* For now, we need the power well to be always enabled. */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7246 | intel_display_set_init_power(dev_priv, true); |
| 7247 | intel_power_domains_resume(dev_priv); |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 7248 | power_domains->initializing = false; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 7249 | } |
| 7250 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7251 | void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv) |
| 7252 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 7253 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7254 | } |
| 7255 | |
| 7256 | void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv) |
| 7257 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 7258 | intel_runtime_pm_put(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7259 | } |
| 7260 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7261 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 7262 | { |
| 7263 | struct drm_device *dev = dev_priv->dev; |
| 7264 | struct device *device = &dev->pdev->dev; |
| 7265 | |
| 7266 | if (!HAS_RUNTIME_PM(dev)) |
| 7267 | return; |
| 7268 | |
| 7269 | pm_runtime_get_sync(device); |
| 7270 | WARN(dev_priv->pm.suspended, "Device still suspended.\n"); |
| 7271 | } |
| 7272 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 7273 | void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv) |
| 7274 | { |
| 7275 | struct drm_device *dev = dev_priv->dev; |
| 7276 | struct device *device = &dev->pdev->dev; |
| 7277 | |
| 7278 | if (!HAS_RUNTIME_PM(dev)) |
| 7279 | return; |
| 7280 | |
| 7281 | WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n"); |
| 7282 | pm_runtime_get_noresume(device); |
| 7283 | } |
| 7284 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7285 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 7286 | { |
| 7287 | struct drm_device *dev = dev_priv->dev; |
| 7288 | struct device *device = &dev->pdev->dev; |
| 7289 | |
| 7290 | if (!HAS_RUNTIME_PM(dev)) |
| 7291 | return; |
| 7292 | |
| 7293 | pm_runtime_mark_last_busy(device); |
| 7294 | pm_runtime_put_autosuspend(device); |
| 7295 | } |
| 7296 | |
| 7297 | void intel_init_runtime_pm(struct drm_i915_private *dev_priv) |
| 7298 | { |
| 7299 | struct drm_device *dev = dev_priv->dev; |
| 7300 | struct device *device = &dev->pdev->dev; |
| 7301 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7302 | if (!HAS_RUNTIME_PM(dev)) |
| 7303 | return; |
| 7304 | |
| 7305 | pm_runtime_set_active(device); |
| 7306 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 7307 | /* |
| 7308 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 7309 | * requirement. |
| 7310 | */ |
| 7311 | if (!intel_enable_rc6(dev)) { |
| 7312 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 7313 | return; |
| 7314 | } |
| 7315 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7316 | pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */ |
| 7317 | pm_runtime_mark_last_busy(device); |
| 7318 | pm_runtime_use_autosuspend(device); |
Paulo Zanoni | ba0239e | 2014-03-07 20:08:07 -0300 | [diff] [blame] | 7319 | |
| 7320 | pm_runtime_put_autosuspend(device); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7321 | } |
| 7322 | |
| 7323 | void intel_fini_runtime_pm(struct drm_i915_private *dev_priv) |
| 7324 | { |
| 7325 | struct drm_device *dev = dev_priv->dev; |
| 7326 | struct device *device = &dev->pdev->dev; |
| 7327 | |
| 7328 | if (!HAS_RUNTIME_PM(dev)) |
| 7329 | return; |
| 7330 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 7331 | if (!intel_enable_rc6(dev)) |
| 7332 | return; |
| 7333 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7334 | /* Make sure we're not suspended first. */ |
| 7335 | pm_runtime_get_sync(device); |
| 7336 | pm_runtime_disable(device); |
| 7337 | } |
| 7338 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7339 | /* Set up chip specific power management-related functions */ |
| 7340 | void intel_init_pm(struct drm_device *dev) |
| 7341 | { |
| 7342 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7343 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 7344 | if (HAS_FBC(dev)) { |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 7345 | if (INTEL_INFO(dev)->gen >= 7) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7346 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 7347 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 7348 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 7349 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 7350 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 7351 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7352 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 7353 | } else if (IS_GM45(dev)) { |
| 7354 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 7355 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 7356 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 7357 | } else { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7358 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 7359 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 7360 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 7361 | |
| 7362 | /* This value was pulled out of someone's hat */ |
| 7363 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7364 | } |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7365 | } |
| 7366 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7367 | /* For cxsr */ |
| 7368 | if (IS_PINEVIEW(dev)) |
| 7369 | i915_pineview_get_mem_freq(dev); |
| 7370 | else if (IS_GEN5(dev)) |
| 7371 | i915_ironlake_get_mem_freq(dev); |
| 7372 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7373 | /* For FIFO watermark updates */ |
| 7374 | if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 7375 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 7376 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7377 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 7378 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 7379 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 7380 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 7381 | dev_priv->display.update_wm = ilk_update_wm; |
| 7382 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 7383 | } else { |
| 7384 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 7385 | "Disable CxSR\n"); |
| 7386 | } |
| 7387 | |
| 7388 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7389 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7390 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7391 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7392 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7393 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7394 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7395 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7396 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 7397 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7398 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 7399 | dev_priv->display.update_wm = cherryview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 7400 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7401 | dev_priv->display.init_clock_gating = |
| 7402 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7403 | } else if (IS_VALLEYVIEW(dev)) { |
| 7404 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 7405 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7406 | dev_priv->display.init_clock_gating = |
| 7407 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7408 | } else if (IS_PINEVIEW(dev)) { |
| 7409 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 7410 | dev_priv->is_ddr3, |
| 7411 | dev_priv->fsb_freq, |
| 7412 | dev_priv->mem_freq)) { |
| 7413 | DRM_INFO("failed to find known CxSR latency " |
| 7414 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 7415 | "disabling CxSR\n", |
| 7416 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 7417 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 7418 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 7419 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7420 | dev_priv->display.update_wm = NULL; |
| 7421 | } else |
| 7422 | dev_priv->display.update_wm = pineview_update_wm; |
| 7423 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7424 | } else if (IS_G4X(dev)) { |
| 7425 | dev_priv->display.update_wm = g4x_update_wm; |
| 7426 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 7427 | } else if (IS_GEN4(dev)) { |
| 7428 | dev_priv->display.update_wm = i965_update_wm; |
| 7429 | if (IS_CRESTLINE(dev)) |
| 7430 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 7431 | else if (IS_BROADWATER(dev)) |
| 7432 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 7433 | } else if (IS_GEN3(dev)) { |
| 7434 | dev_priv->display.update_wm = i9xx_update_wm; |
| 7435 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 7436 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7437 | } else if (IS_GEN2(dev)) { |
| 7438 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 7439 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7440 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7441 | } else { |
| 7442 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7443 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7444 | } |
| 7445 | |
| 7446 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 7447 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 7448 | else |
| 7449 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7450 | } else { |
| 7451 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7452 | } |
| 7453 | } |
| 7454 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7455 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 7456 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7457 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7458 | |
| 7459 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 7460 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 7461 | return -EAGAIN; |
| 7462 | } |
| 7463 | |
| 7464 | I915_WRITE(GEN6_PCODE_DATA, *val); |
| 7465 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 7466 | |
| 7467 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 7468 | 500)) { |
| 7469 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 7470 | return -ETIMEDOUT; |
| 7471 | } |
| 7472 | |
| 7473 | *val = I915_READ(GEN6_PCODE_DATA); |
| 7474 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 7475 | |
| 7476 | return 0; |
| 7477 | } |
| 7478 | |
| 7479 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 7480 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7481 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7482 | |
| 7483 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 7484 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 7485 | return -EAGAIN; |
| 7486 | } |
| 7487 | |
| 7488 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 7489 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 7490 | |
| 7491 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 7492 | 500)) { |
| 7493 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 7494 | return -ETIMEDOUT; |
| 7495 | } |
| 7496 | |
| 7497 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 7498 | |
| 7499 | return 0; |
| 7500 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 7501 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7502 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7503 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7504 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7505 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7506 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7507 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7508 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7509 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7510 | break; |
| 7511 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7512 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7513 | break; |
| 7514 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7515 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7516 | break; |
| 7517 | default: |
| 7518 | return -1; |
| 7519 | } |
| 7520 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7521 | 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] | 7522 | } |
| 7523 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7524 | static int byt_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7525 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7526 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7527 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7528 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7529 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7530 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7531 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7532 | break; |
| 7533 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7534 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7535 | break; |
| 7536 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7537 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7538 | break; |
| 7539 | default: |
| 7540 | return -1; |
| 7541 | } |
| 7542 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7543 | 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] | 7544 | } |
| 7545 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7546 | static int chv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7547 | { |
| 7548 | int div, freq; |
| 7549 | |
| 7550 | switch (dev_priv->rps.cz_freq) { |
| 7551 | case 200: |
| 7552 | div = 5; |
| 7553 | break; |
| 7554 | case 267: |
| 7555 | div = 6; |
| 7556 | break; |
| 7557 | case 320: |
| 7558 | case 333: |
| 7559 | case 400: |
| 7560 | div = 8; |
| 7561 | break; |
| 7562 | default: |
| 7563 | return -1; |
| 7564 | } |
| 7565 | |
| 7566 | freq = (DIV_ROUND_CLOSEST((dev_priv->rps.cz_freq * val), 2 * div) / 2); |
| 7567 | |
| 7568 | return freq; |
| 7569 | } |
| 7570 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7571 | static int chv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7572 | { |
| 7573 | int mul, opcode; |
| 7574 | |
| 7575 | switch (dev_priv->rps.cz_freq) { |
| 7576 | case 200: |
| 7577 | mul = 5; |
| 7578 | break; |
| 7579 | case 267: |
| 7580 | mul = 6; |
| 7581 | break; |
| 7582 | case 320: |
| 7583 | case 333: |
| 7584 | case 400: |
| 7585 | mul = 8; |
| 7586 | break; |
| 7587 | default: |
| 7588 | return -1; |
| 7589 | } |
| 7590 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7591 | /* CHV needs even values */ |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7592 | opcode = (DIV_ROUND_CLOSEST((val * 2 * mul), dev_priv->rps.cz_freq) * 2); |
| 7593 | |
| 7594 | return opcode; |
| 7595 | } |
| 7596 | |
| 7597 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 7598 | { |
| 7599 | int ret = -1; |
| 7600 | |
| 7601 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7602 | ret = chv_gpu_freq(dev_priv, val); |
| 7603 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7604 | ret = byt_gpu_freq(dev_priv, val); |
| 7605 | |
| 7606 | return ret; |
| 7607 | } |
| 7608 | |
| 7609 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 7610 | { |
| 7611 | int ret = -1; |
| 7612 | |
| 7613 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7614 | ret = chv_freq_opcode(dev_priv, val); |
| 7615 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7616 | ret = byt_freq_opcode(dev_priv, val); |
| 7617 | |
| 7618 | return ret; |
| 7619 | } |
| 7620 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7621 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7622 | { |
| 7623 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7624 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7625 | mutex_init(&dev_priv->rps.hw_lock); |
| 7626 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7627 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 7628 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 7629 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 7630 | dev_priv->pm.suspended = false; |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 7631 | dev_priv->pm._irqs_disabled = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7632 | } |