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 | |
| 312 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 313 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 314 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 315 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 316 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 317 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 318 | ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 319 | } else { |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 320 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 321 | I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe), |
| 322 | I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) | |
| 323 | HSW_FBCQ_DIS); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 324 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 325 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 326 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 327 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 328 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 329 | |
| 330 | sandybridge_blit_fbc_update(dev); |
| 331 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 332 | 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] | 333 | } |
| 334 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 335 | bool intel_fbc_enabled(struct drm_device *dev) |
| 336 | { |
| 337 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 338 | |
| 339 | if (!dev_priv->display.fbc_enabled) |
| 340 | return false; |
| 341 | |
| 342 | return dev_priv->display.fbc_enabled(dev); |
| 343 | } |
| 344 | |
| 345 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 346 | { |
| 347 | struct intel_fbc_work *work = |
| 348 | container_of(to_delayed_work(__work), |
| 349 | struct intel_fbc_work, work); |
| 350 | struct drm_device *dev = work->crtc->dev; |
| 351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 352 | |
| 353 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 354 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 355 | /* Double check that we haven't switched fb without cancelling |
| 356 | * the prior work. |
| 357 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 358 | if (work->crtc->primary->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 359 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 360 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 361 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 362 | dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id; |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 363 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 364 | } |
| 365 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 366 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 367 | } |
| 368 | mutex_unlock(&dev->struct_mutex); |
| 369 | |
| 370 | kfree(work); |
| 371 | } |
| 372 | |
| 373 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 374 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 375 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 376 | return; |
| 377 | |
| 378 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 379 | |
| 380 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 381 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 382 | * entirely asynchronously. |
| 383 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 384 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 385 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 386 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 387 | |
| 388 | /* Mark the work as no longer wanted so that if it does |
| 389 | * wake-up (because the work was already running and waiting |
| 390 | * for our mutex), it will discover that is no longer |
| 391 | * necessary to run. |
| 392 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 393 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 394 | } |
| 395 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 396 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 397 | { |
| 398 | struct intel_fbc_work *work; |
| 399 | struct drm_device *dev = crtc->dev; |
| 400 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 401 | |
| 402 | if (!dev_priv->display.enable_fbc) |
| 403 | return; |
| 404 | |
| 405 | intel_cancel_fbc_work(dev_priv); |
| 406 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 407 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 408 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 409 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 410 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 411 | return; |
| 412 | } |
| 413 | |
| 414 | work->crtc = crtc; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 415 | work->fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 416 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 417 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 418 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 419 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 420 | /* Delay the actual enabling to let pageflipping cease and the |
| 421 | * display to settle before starting the compression. Note that |
| 422 | * this delay also serves a second purpose: it allows for a |
| 423 | * vblank to pass after disabling the FBC before we attempt |
| 424 | * to modify the control registers. |
| 425 | * |
| 426 | * A more complicated solution would involve tracking vblanks |
| 427 | * following the termination of the page-flipping sequence |
| 428 | * and indeed performing the enable as a co-routine and not |
| 429 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 430 | * |
| 431 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 432 | */ |
| 433 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 434 | } |
| 435 | |
| 436 | void intel_disable_fbc(struct drm_device *dev) |
| 437 | { |
| 438 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 439 | |
| 440 | intel_cancel_fbc_work(dev_priv); |
| 441 | |
| 442 | if (!dev_priv->display.disable_fbc) |
| 443 | return; |
| 444 | |
| 445 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 446 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 447 | } |
| 448 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 449 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 450 | enum no_fbc_reason reason) |
| 451 | { |
| 452 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 453 | return false; |
| 454 | |
| 455 | dev_priv->fbc.no_fbc_reason = reason; |
| 456 | return true; |
| 457 | } |
| 458 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 459 | /** |
| 460 | * intel_update_fbc - enable/disable FBC as needed |
| 461 | * @dev: the drm_device |
| 462 | * |
| 463 | * Set up the framebuffer compression hardware at mode set time. We |
| 464 | * enable it if possible: |
| 465 | * - plane A only (on pre-965) |
| 466 | * - no pixel mulitply/line duplication |
| 467 | * - no alpha buffer discard |
| 468 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 469 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 470 | * |
| 471 | * We can't assume that any compression will take place (worst case), |
| 472 | * so the compressed buffer has to be the same size as the uncompressed |
| 473 | * one. It also must reside (along with the line length buffer) in |
| 474 | * stolen memory. |
| 475 | * |
| 476 | * We need to enable/disable FBC on a global basis. |
| 477 | */ |
| 478 | void intel_update_fbc(struct drm_device *dev) |
| 479 | { |
| 480 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 481 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 482 | struct intel_crtc *intel_crtc; |
| 483 | struct drm_framebuffer *fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 484 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 485 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 486 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 487 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 488 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 489 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 490 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 491 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 492 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 493 | if (!i915.powersave) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 494 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 495 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 496 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 497 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 498 | |
| 499 | /* |
| 500 | * If FBC is already on, we just have to verify that we can |
| 501 | * keep it that way... |
| 502 | * Need to disable if: |
| 503 | * - more than one pipe is active |
| 504 | * - changing FBC params (stride, fence, mode) |
| 505 | * - new fb is too large to fit in compressed buffer |
| 506 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 507 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 508 | for_each_crtc(dev, tmp_crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 509 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 510 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 511 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 512 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 513 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 514 | goto out_disable; |
| 515 | } |
| 516 | crtc = tmp_crtc; |
| 517 | } |
| 518 | } |
| 519 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 520 | if (!crtc || crtc->primary->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 521 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 522 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 523 | goto out_disable; |
| 524 | } |
| 525 | |
| 526 | intel_crtc = to_intel_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 527 | fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 528 | obj = intel_fb_obj(fb); |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 529 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 530 | |
Chris Wilson | 0368920 | 2014-06-06 10:37:11 +0100 | [diff] [blame] | 531 | if (i915.enable_fbc < 0) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 532 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 533 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 534 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 535 | } |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 536 | if (!i915.enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 537 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 538 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 539 | goto out_disable; |
| 540 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 541 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 542 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 543 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 544 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 545 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 546 | goto out_disable; |
| 547 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 548 | |
Daisy Sun | 032843a | 2014-06-16 15:48:18 -0700 | [diff] [blame] | 549 | if (INTEL_INFO(dev)->gen >= 8 || IS_HASWELL(dev)) { |
| 550 | max_width = 4096; |
| 551 | max_height = 4096; |
| 552 | } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 553 | max_width = 4096; |
| 554 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 555 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 556 | max_width = 2048; |
| 557 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 558 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 559 | if (intel_crtc->config.pipe_src_w > max_width || |
| 560 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 561 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 562 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 563 | goto out_disable; |
| 564 | } |
Ben Widawsky | 8f94d24 | 2014-02-20 16:01:20 -0800 | [diff] [blame] | 565 | if ((INTEL_INFO(dev)->gen < 4 || HAS_DDI(dev)) && |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 566 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 567 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 568 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 569 | goto out_disable; |
| 570 | } |
| 571 | |
| 572 | /* The use of a CPU fence is mandatory in order to detect writes |
| 573 | * by the CPU to the scanout and trigger updates to the FBC. |
| 574 | */ |
| 575 | if (obj->tiling_mode != I915_TILING_X || |
| 576 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 577 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 578 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 579 | goto out_disable; |
| 580 | } |
| 581 | |
| 582 | /* If the kernel debugger is active, always disable compression */ |
| 583 | if (in_dbg_master()) |
| 584 | goto out_disable; |
| 585 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 586 | if (i915_gem_stolen_setup_compression(dev, obj->base.size, |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 587 | drm_format_plane_cpp(fb->pixel_format, 0))) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 588 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 589 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 590 | goto out_disable; |
| 591 | } |
| 592 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 593 | /* If the scanout has not changed, don't modify the FBC settings. |
| 594 | * Note that we make the fundamental assumption that the fb->obj |
| 595 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 596 | * without first being decoupled from the scanout and FBC disabled. |
| 597 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 598 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 599 | dev_priv->fbc.fb_id == fb->base.id && |
| 600 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 601 | return; |
| 602 | |
| 603 | if (intel_fbc_enabled(dev)) { |
| 604 | /* We update FBC along two paths, after changing fb/crtc |
| 605 | * configuration (modeswitching) and after page-flipping |
| 606 | * finishes. For the latter, we know that not only did |
| 607 | * we disable the FBC at the start of the page-flip |
| 608 | * sequence, but also more than one vblank has passed. |
| 609 | * |
| 610 | * For the former case of modeswitching, it is possible |
| 611 | * to switch between two FBC valid configurations |
| 612 | * instantaneously so we do need to disable the FBC |
| 613 | * before we can modify its control registers. We also |
| 614 | * have to wait for the next vblank for that to take |
| 615 | * effect. However, since we delay enabling FBC we can |
| 616 | * assume that a vblank has passed since disabling and |
| 617 | * that we can safely alter the registers in the deferred |
| 618 | * callback. |
| 619 | * |
| 620 | * In the scenario that we go from a valid to invalid |
| 621 | * and then back to valid FBC configuration we have |
| 622 | * no strict enforcement that a vblank occurred since |
| 623 | * disabling the FBC. However, along all current pipe |
| 624 | * disabling paths we do need to wait for a vblank at |
| 625 | * some point. And we wait before enabling FBC anyway. |
| 626 | */ |
| 627 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 628 | intel_disable_fbc(dev); |
| 629 | } |
| 630 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 631 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 632 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 633 | return; |
| 634 | |
| 635 | out_disable: |
| 636 | /* Multiple disables should be harmless */ |
| 637 | if (intel_fbc_enabled(dev)) { |
| 638 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 639 | intel_disable_fbc(dev); |
| 640 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 641 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 642 | } |
| 643 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 644 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 645 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 646 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 647 | u32 tmp; |
| 648 | |
| 649 | tmp = I915_READ(CLKCFG); |
| 650 | |
| 651 | switch (tmp & CLKCFG_FSB_MASK) { |
| 652 | case CLKCFG_FSB_533: |
| 653 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 654 | break; |
| 655 | case CLKCFG_FSB_800: |
| 656 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 657 | break; |
| 658 | case CLKCFG_FSB_667: |
| 659 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 660 | break; |
| 661 | case CLKCFG_FSB_400: |
| 662 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | switch (tmp & CLKCFG_MEM_MASK) { |
| 667 | case CLKCFG_MEM_533: |
| 668 | dev_priv->mem_freq = 533; |
| 669 | break; |
| 670 | case CLKCFG_MEM_667: |
| 671 | dev_priv->mem_freq = 667; |
| 672 | break; |
| 673 | case CLKCFG_MEM_800: |
| 674 | dev_priv->mem_freq = 800; |
| 675 | break; |
| 676 | } |
| 677 | |
| 678 | /* detect pineview DDR3 setting */ |
| 679 | tmp = I915_READ(CSHRDDR3CTL); |
| 680 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 681 | } |
| 682 | |
| 683 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 684 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 685 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 686 | u16 ddrpll, csipll; |
| 687 | |
| 688 | ddrpll = I915_READ16(DDRMPLL1); |
| 689 | csipll = I915_READ16(CSIPLL0); |
| 690 | |
| 691 | switch (ddrpll & 0xff) { |
| 692 | case 0xc: |
| 693 | dev_priv->mem_freq = 800; |
| 694 | break; |
| 695 | case 0x10: |
| 696 | dev_priv->mem_freq = 1066; |
| 697 | break; |
| 698 | case 0x14: |
| 699 | dev_priv->mem_freq = 1333; |
| 700 | break; |
| 701 | case 0x18: |
| 702 | dev_priv->mem_freq = 1600; |
| 703 | break; |
| 704 | default: |
| 705 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 706 | ddrpll & 0xff); |
| 707 | dev_priv->mem_freq = 0; |
| 708 | break; |
| 709 | } |
| 710 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 711 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 712 | |
| 713 | switch (csipll & 0x3ff) { |
| 714 | case 0x00c: |
| 715 | dev_priv->fsb_freq = 3200; |
| 716 | break; |
| 717 | case 0x00e: |
| 718 | dev_priv->fsb_freq = 3733; |
| 719 | break; |
| 720 | case 0x010: |
| 721 | dev_priv->fsb_freq = 4266; |
| 722 | break; |
| 723 | case 0x012: |
| 724 | dev_priv->fsb_freq = 4800; |
| 725 | break; |
| 726 | case 0x014: |
| 727 | dev_priv->fsb_freq = 5333; |
| 728 | break; |
| 729 | case 0x016: |
| 730 | dev_priv->fsb_freq = 5866; |
| 731 | break; |
| 732 | case 0x018: |
| 733 | dev_priv->fsb_freq = 6400; |
| 734 | break; |
| 735 | default: |
| 736 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 737 | csipll & 0x3ff); |
| 738 | dev_priv->fsb_freq = 0; |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 743 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 744 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 745 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 746 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 747 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 751 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 752 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 753 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 754 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 755 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 756 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 757 | |
| 758 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 759 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 760 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 761 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 762 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 763 | |
| 764 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 765 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 766 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 767 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 768 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 769 | |
| 770 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 771 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 772 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 773 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 774 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 775 | |
| 776 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 777 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 778 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 779 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 780 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 781 | |
| 782 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 783 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 784 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 785 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 786 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 787 | }; |
| 788 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 789 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 790 | int is_ddr3, |
| 791 | int fsb, |
| 792 | int mem) |
| 793 | { |
| 794 | const struct cxsr_latency *latency; |
| 795 | int i; |
| 796 | |
| 797 | if (fsb == 0 || mem == 0) |
| 798 | return NULL; |
| 799 | |
| 800 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 801 | latency = &cxsr_latency_table[i]; |
| 802 | if (is_desktop == latency->is_desktop && |
| 803 | is_ddr3 == latency->is_ddr3 && |
| 804 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 805 | return latency; |
| 806 | } |
| 807 | |
| 808 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 809 | |
| 810 | return NULL; |
| 811 | } |
| 812 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 813 | 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] | 814 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 815 | struct drm_device *dev = dev_priv->dev; |
| 816 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 817 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 818 | if (IS_VALLEYVIEW(dev)) { |
| 819 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 820 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 821 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 822 | } else if (IS_PINEVIEW(dev)) { |
| 823 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 824 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 825 | I915_WRITE(DSPFW3, val); |
| 826 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 827 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 828 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 829 | I915_WRITE(FW_BLC_SELF, val); |
| 830 | } else if (IS_I915GM(dev)) { |
| 831 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 832 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 833 | I915_WRITE(INSTPM, val); |
| 834 | } else { |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 839 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | /* |
| 843 | * Latency for FIFO fetches is dependent on several factors: |
| 844 | * - memory configuration (speed, channels) |
| 845 | * - chipset |
| 846 | * - current MCH state |
| 847 | * It can be fairly high in some situations, so here we assume a fairly |
| 848 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 849 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 850 | * and power consumption (set it too low to save power and we might see |
| 851 | * FIFO underruns and display "flicker"). |
| 852 | * |
| 853 | * A value of 5us seems to be a good balance; safe for very low end |
| 854 | * platforms but not overly aggressive on lower latency configs. |
| 855 | */ |
| 856 | static const int latency_ns = 5000; |
| 857 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 858 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 859 | { |
| 860 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 861 | uint32_t dsparb = I915_READ(DSPARB); |
| 862 | int size; |
| 863 | |
| 864 | size = dsparb & 0x7f; |
| 865 | if (plane) |
| 866 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 867 | |
| 868 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 869 | plane ? "B" : "A", size); |
| 870 | |
| 871 | return size; |
| 872 | } |
| 873 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 874 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 875 | { |
| 876 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 877 | uint32_t dsparb = I915_READ(DSPARB); |
| 878 | int size; |
| 879 | |
| 880 | size = dsparb & 0x1ff; |
| 881 | if (plane) |
| 882 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 883 | size >>= 1; /* Convert to cachelines */ |
| 884 | |
| 885 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 886 | plane ? "B" : "A", size); |
| 887 | |
| 888 | return size; |
| 889 | } |
| 890 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 891 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 892 | { |
| 893 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 894 | uint32_t dsparb = I915_READ(DSPARB); |
| 895 | int size; |
| 896 | |
| 897 | size = dsparb & 0x7f; |
| 898 | size >>= 2; /* Convert to cachelines */ |
| 899 | |
| 900 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 901 | plane ? "B" : "A", |
| 902 | size); |
| 903 | |
| 904 | return size; |
| 905 | } |
| 906 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 907 | /* Pineview has different values for various configs */ |
| 908 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 909 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 910 | .max_wm = PINEVIEW_MAX_WM, |
| 911 | .default_wm = PINEVIEW_DFT_WM, |
| 912 | .guard_size = PINEVIEW_GUARD_WM, |
| 913 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 914 | }; |
| 915 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 916 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 917 | .max_wm = PINEVIEW_MAX_WM, |
| 918 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 919 | .guard_size = PINEVIEW_GUARD_WM, |
| 920 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 921 | }; |
| 922 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 923 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 924 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 925 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 926 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 927 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 928 | }; |
| 929 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 930 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 931 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 932 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 933 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 934 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 935 | }; |
| 936 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 937 | .fifo_size = G4X_FIFO_SIZE, |
| 938 | .max_wm = G4X_MAX_WM, |
| 939 | .default_wm = G4X_MAX_WM, |
| 940 | .guard_size = 2, |
| 941 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 942 | }; |
| 943 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 944 | .fifo_size = I965_CURSOR_FIFO, |
| 945 | .max_wm = I965_CURSOR_MAX_WM, |
| 946 | .default_wm = I965_CURSOR_DFT_WM, |
| 947 | .guard_size = 2, |
| 948 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 949 | }; |
| 950 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 951 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 952 | .max_wm = VALLEYVIEW_MAX_WM, |
| 953 | .default_wm = VALLEYVIEW_MAX_WM, |
| 954 | .guard_size = 2, |
| 955 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 956 | }; |
| 957 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 958 | .fifo_size = I965_CURSOR_FIFO, |
| 959 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 960 | .default_wm = I965_CURSOR_DFT_WM, |
| 961 | .guard_size = 2, |
| 962 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 963 | }; |
| 964 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 965 | .fifo_size = I965_CURSOR_FIFO, |
| 966 | .max_wm = I965_CURSOR_MAX_WM, |
| 967 | .default_wm = I965_CURSOR_DFT_WM, |
| 968 | .guard_size = 2, |
| 969 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 970 | }; |
| 971 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 972 | .fifo_size = I945_FIFO_SIZE, |
| 973 | .max_wm = I915_MAX_WM, |
| 974 | .default_wm = 1, |
| 975 | .guard_size = 2, |
| 976 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 977 | }; |
| 978 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 979 | .fifo_size = I915_FIFO_SIZE, |
| 980 | .max_wm = I915_MAX_WM, |
| 981 | .default_wm = 1, |
| 982 | .guard_size = 2, |
| 983 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 984 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 985 | static const struct intel_watermark_params i830_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 986 | .fifo_size = I855GM_FIFO_SIZE, |
| 987 | .max_wm = I915_MAX_WM, |
| 988 | .default_wm = 1, |
| 989 | .guard_size = 2, |
| 990 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 991 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 992 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 993 | .fifo_size = I830_FIFO_SIZE, |
| 994 | .max_wm = I915_MAX_WM, |
| 995 | .default_wm = 1, |
| 996 | .guard_size = 2, |
| 997 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 998 | }; |
| 999 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1000 | /** |
| 1001 | * intel_calculate_wm - calculate watermark level |
| 1002 | * @clock_in_khz: pixel clock |
| 1003 | * @wm: chip FIFO params |
| 1004 | * @pixel_size: display pixel size |
| 1005 | * @latency_ns: memory latency for the platform |
| 1006 | * |
| 1007 | * Calculate the watermark level (the level at which the display plane will |
| 1008 | * start fetching from memory again). Each chip has a different display |
| 1009 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 1010 | * in the correct intel_watermark_params structure. |
| 1011 | * |
| 1012 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 1013 | * on the pixel size. When it reaches the watermark level, it'll start |
| 1014 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 1015 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 1016 | * will occur, and a display engine hang could result. |
| 1017 | */ |
| 1018 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 1019 | const struct intel_watermark_params *wm, |
| 1020 | int fifo_size, |
| 1021 | int pixel_size, |
| 1022 | unsigned long latency_ns) |
| 1023 | { |
| 1024 | long entries_required, wm_size; |
| 1025 | |
| 1026 | /* |
| 1027 | * Note: we need to make sure we don't overflow for various clock & |
| 1028 | * latency values. |
| 1029 | * clocks go from a few thousand to several hundred thousand. |
| 1030 | * latency is usually a few thousand |
| 1031 | */ |
| 1032 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 1033 | 1000; |
| 1034 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 1035 | |
| 1036 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 1037 | |
| 1038 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 1039 | |
| 1040 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 1041 | |
| 1042 | /* Don't promote wm_size to unsigned... */ |
| 1043 | if (wm_size > (long)wm->max_wm) |
| 1044 | wm_size = wm->max_wm; |
| 1045 | if (wm_size <= 0) |
| 1046 | wm_size = wm->default_wm; |
| 1047 | return wm_size; |
| 1048 | } |
| 1049 | |
| 1050 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 1051 | { |
| 1052 | struct drm_crtc *crtc, *enabled = NULL; |
| 1053 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 1054 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1055 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1056 | if (enabled) |
| 1057 | return NULL; |
| 1058 | enabled = crtc; |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | return enabled; |
| 1063 | } |
| 1064 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1065 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1066 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1067 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1068 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1069 | struct drm_crtc *crtc; |
| 1070 | const struct cxsr_latency *latency; |
| 1071 | u32 reg; |
| 1072 | unsigned long wm; |
| 1073 | |
| 1074 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1075 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1076 | if (!latency) { |
| 1077 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1078 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1079 | return; |
| 1080 | } |
| 1081 | |
| 1082 | crtc = single_enabled_crtc(dev); |
| 1083 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1084 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1085 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1086 | int clock; |
| 1087 | |
| 1088 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1089 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1090 | |
| 1091 | /* Display SR */ |
| 1092 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1093 | pineview_display_wm.fifo_size, |
| 1094 | pixel_size, latency->display_sr); |
| 1095 | reg = I915_READ(DSPFW1); |
| 1096 | reg &= ~DSPFW_SR_MASK; |
| 1097 | reg |= wm << DSPFW_SR_SHIFT; |
| 1098 | I915_WRITE(DSPFW1, reg); |
| 1099 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1100 | |
| 1101 | /* cursor SR */ |
| 1102 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1103 | pineview_display_wm.fifo_size, |
| 1104 | pixel_size, latency->cursor_sr); |
| 1105 | reg = I915_READ(DSPFW3); |
| 1106 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1107 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1108 | I915_WRITE(DSPFW3, reg); |
| 1109 | |
| 1110 | /* Display HPLL off SR */ |
| 1111 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1112 | pineview_display_hplloff_wm.fifo_size, |
| 1113 | pixel_size, latency->display_hpll_disable); |
| 1114 | reg = I915_READ(DSPFW3); |
| 1115 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1116 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1117 | I915_WRITE(DSPFW3, reg); |
| 1118 | |
| 1119 | /* cursor HPLL off SR */ |
| 1120 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1121 | pineview_display_hplloff_wm.fifo_size, |
| 1122 | pixel_size, latency->cursor_hpll_disable); |
| 1123 | reg = I915_READ(DSPFW3); |
| 1124 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1125 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1126 | I915_WRITE(DSPFW3, reg); |
| 1127 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1128 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1129 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1130 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1131 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1136 | int plane, |
| 1137 | const struct intel_watermark_params *display, |
| 1138 | int display_latency_ns, |
| 1139 | const struct intel_watermark_params *cursor, |
| 1140 | int cursor_latency_ns, |
| 1141 | int *plane_wm, |
| 1142 | int *cursor_wm) |
| 1143 | { |
| 1144 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1145 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1146 | int htotal, hdisplay, clock, pixel_size; |
| 1147 | int line_time_us, line_count; |
| 1148 | int entries, tlb_miss; |
| 1149 | |
| 1150 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1151 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1152 | *cursor_wm = cursor->guard_size; |
| 1153 | *plane_wm = display->guard_size; |
| 1154 | return false; |
| 1155 | } |
| 1156 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1157 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1158 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1159 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1160 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1161 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1162 | |
| 1163 | /* Use the small buffer method to calculate plane watermark */ |
| 1164 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1165 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1166 | if (tlb_miss > 0) |
| 1167 | entries += tlb_miss; |
| 1168 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1169 | *plane_wm = entries + display->guard_size; |
| 1170 | if (*plane_wm > (int)display->max_wm) |
| 1171 | *plane_wm = display->max_wm; |
| 1172 | |
| 1173 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1174 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1175 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1176 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1177 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1178 | if (tlb_miss > 0) |
| 1179 | entries += tlb_miss; |
| 1180 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1181 | *cursor_wm = entries + cursor->guard_size; |
| 1182 | if (*cursor_wm > (int)cursor->max_wm) |
| 1183 | *cursor_wm = (int)cursor->max_wm; |
| 1184 | |
| 1185 | return true; |
| 1186 | } |
| 1187 | |
| 1188 | /* |
| 1189 | * Check the wm result. |
| 1190 | * |
| 1191 | * If any calculated watermark values is larger than the maximum value that |
| 1192 | * can be programmed into the associated watermark register, that watermark |
| 1193 | * must be disabled. |
| 1194 | */ |
| 1195 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1196 | int display_wm, int cursor_wm, |
| 1197 | const struct intel_watermark_params *display, |
| 1198 | const struct intel_watermark_params *cursor) |
| 1199 | { |
| 1200 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1201 | display_wm, cursor_wm); |
| 1202 | |
| 1203 | if (display_wm > display->max_wm) { |
| 1204 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1205 | display_wm, display->max_wm); |
| 1206 | return false; |
| 1207 | } |
| 1208 | |
| 1209 | if (cursor_wm > cursor->max_wm) { |
| 1210 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1211 | cursor_wm, cursor->max_wm); |
| 1212 | return false; |
| 1213 | } |
| 1214 | |
| 1215 | if (!(display_wm || cursor_wm)) { |
| 1216 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1217 | return false; |
| 1218 | } |
| 1219 | |
| 1220 | return true; |
| 1221 | } |
| 1222 | |
| 1223 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1224 | int plane, |
| 1225 | int latency_ns, |
| 1226 | const struct intel_watermark_params *display, |
| 1227 | const struct intel_watermark_params *cursor, |
| 1228 | int *display_wm, int *cursor_wm) |
| 1229 | { |
| 1230 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1231 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1232 | int hdisplay, htotal, pixel_size, clock; |
| 1233 | unsigned long line_time_us; |
| 1234 | int line_count, line_size; |
| 1235 | int small, large; |
| 1236 | int entries; |
| 1237 | |
| 1238 | if (!latency_ns) { |
| 1239 | *display_wm = *cursor_wm = 0; |
| 1240 | return false; |
| 1241 | } |
| 1242 | |
| 1243 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1244 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1245 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1246 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1247 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1248 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1249 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1250 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1251 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1252 | line_size = hdisplay * pixel_size; |
| 1253 | |
| 1254 | /* Use the minimum of the small and large buffer method for primary */ |
| 1255 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1256 | large = line_count * line_size; |
| 1257 | |
| 1258 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1259 | *display_wm = entries + display->guard_size; |
| 1260 | |
| 1261 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1262 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1263 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1264 | *cursor_wm = entries + cursor->guard_size; |
| 1265 | |
| 1266 | return g4x_check_srwm(dev, |
| 1267 | *display_wm, *cursor_wm, |
| 1268 | display, cursor); |
| 1269 | } |
| 1270 | |
| 1271 | static bool vlv_compute_drain_latency(struct drm_device *dev, |
| 1272 | int plane, |
| 1273 | int *plane_prec_mult, |
| 1274 | int *plane_dl, |
| 1275 | int *cursor_prec_mult, |
| 1276 | int *cursor_dl) |
| 1277 | { |
| 1278 | struct drm_crtc *crtc; |
| 1279 | int clock, pixel_size; |
| 1280 | int entries; |
| 1281 | |
| 1282 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1283 | if (!intel_crtc_active(crtc)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1284 | return false; |
| 1285 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1286 | clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1287 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1288 | |
| 1289 | entries = (clock / 1000) * pixel_size; |
| 1290 | *plane_prec_mult = (entries > 256) ? |
| 1291 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1292 | *plane_dl = (64 * (*plane_prec_mult) * 4) / ((clock / 1000) * |
| 1293 | pixel_size); |
| 1294 | |
| 1295 | entries = (clock / 1000) * 4; /* BPP is always 4 for cursor */ |
| 1296 | *cursor_prec_mult = (entries > 256) ? |
| 1297 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16; |
| 1298 | *cursor_dl = (64 * (*cursor_prec_mult) * 4) / ((clock / 1000) * 4); |
| 1299 | |
| 1300 | return true; |
| 1301 | } |
| 1302 | |
| 1303 | /* |
| 1304 | * Update drain latency registers of memory arbiter |
| 1305 | * |
| 1306 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1307 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1308 | * latency value. |
| 1309 | */ |
| 1310 | |
| 1311 | static void vlv_update_drain_latency(struct drm_device *dev) |
| 1312 | { |
| 1313 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1314 | int planea_prec, planea_dl, planeb_prec, planeb_dl; |
| 1315 | int cursora_prec, cursora_dl, cursorb_prec, cursorb_dl; |
| 1316 | int plane_prec_mult, cursor_prec_mult; /* Precision multiplier is |
| 1317 | either 16 or 32 */ |
| 1318 | |
| 1319 | /* For plane A, Cursor A */ |
| 1320 | if (vlv_compute_drain_latency(dev, 0, &plane_prec_mult, &planea_dl, |
| 1321 | &cursor_prec_mult, &cursora_dl)) { |
| 1322 | cursora_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1323 | DDL_CURSORA_PRECISION_32 : DDL_CURSORA_PRECISION_16; |
| 1324 | planea_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1325 | DDL_PLANEA_PRECISION_32 : DDL_PLANEA_PRECISION_16; |
| 1326 | |
| 1327 | I915_WRITE(VLV_DDL1, cursora_prec | |
| 1328 | (cursora_dl << DDL_CURSORA_SHIFT) | |
| 1329 | planea_prec | planea_dl); |
| 1330 | } |
| 1331 | |
| 1332 | /* For plane B, Cursor B */ |
| 1333 | if (vlv_compute_drain_latency(dev, 1, &plane_prec_mult, &planeb_dl, |
| 1334 | &cursor_prec_mult, &cursorb_dl)) { |
| 1335 | cursorb_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1336 | DDL_CURSORB_PRECISION_32 : DDL_CURSORB_PRECISION_16; |
| 1337 | planeb_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ? |
| 1338 | DDL_PLANEB_PRECISION_32 : DDL_PLANEB_PRECISION_16; |
| 1339 | |
| 1340 | I915_WRITE(VLV_DDL2, cursorb_prec | |
| 1341 | (cursorb_dl << DDL_CURSORB_SHIFT) | |
| 1342 | planeb_prec | planeb_dl); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1347 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1348 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1349 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1350 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1351 | static const int sr_latency_ns = 12000; |
| 1352 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1353 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1354 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1355 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1356 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1357 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1358 | |
| 1359 | vlv_update_drain_latency(dev); |
| 1360 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1361 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1362 | &valleyview_wm_info, latency_ns, |
| 1363 | &valleyview_cursor_wm_info, latency_ns, |
| 1364 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1365 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1366 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1367 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1368 | &valleyview_wm_info, latency_ns, |
| 1369 | &valleyview_cursor_wm_info, latency_ns, |
| 1370 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1371 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1372 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1373 | if (single_plane_enabled(enabled) && |
| 1374 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1375 | sr_latency_ns, |
| 1376 | &valleyview_wm_info, |
| 1377 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1378 | &plane_sr, &ignore_cursor_sr) && |
| 1379 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1380 | 2*sr_latency_ns, |
| 1381 | &valleyview_wm_info, |
| 1382 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1383 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1384 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1385 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1386 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1387 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1388 | plane_sr = cursor_sr = 0; |
| 1389 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1390 | |
| 1391 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1392 | planea_wm, cursora_wm, |
| 1393 | planeb_wm, cursorb_wm, |
| 1394 | plane_sr, cursor_sr); |
| 1395 | |
| 1396 | I915_WRITE(DSPFW1, |
| 1397 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1398 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1399 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1400 | planea_wm); |
| 1401 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1402 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1403 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1404 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1405 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1406 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1407 | |
| 1408 | if (cxsr_enabled) |
| 1409 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1410 | } |
| 1411 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1412 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1413 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1414 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1415 | static const int sr_latency_ns = 12000; |
| 1416 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1417 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1418 | int plane_sr, cursor_sr; |
| 1419 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1420 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1421 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1422 | if (g4x_compute_wm0(dev, PIPE_A, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1423 | &g4x_wm_info, latency_ns, |
| 1424 | &g4x_cursor_wm_info, latency_ns, |
| 1425 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1426 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1427 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1428 | if (g4x_compute_wm0(dev, PIPE_B, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1429 | &g4x_wm_info, latency_ns, |
| 1430 | &g4x_cursor_wm_info, latency_ns, |
| 1431 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1432 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1433 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1434 | if (single_plane_enabled(enabled) && |
| 1435 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1436 | sr_latency_ns, |
| 1437 | &g4x_wm_info, |
| 1438 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1439 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1440 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1441 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1442 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1443 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1444 | plane_sr = cursor_sr = 0; |
| 1445 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1446 | |
| 1447 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
| 1448 | planea_wm, cursora_wm, |
| 1449 | planeb_wm, cursorb_wm, |
| 1450 | plane_sr, cursor_sr); |
| 1451 | |
| 1452 | I915_WRITE(DSPFW1, |
| 1453 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1454 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1455 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1456 | planea_wm); |
| 1457 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1458 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1459 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1460 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1461 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1462 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1463 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1464 | |
| 1465 | if (cxsr_enabled) |
| 1466 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1467 | } |
| 1468 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1469 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1470 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1471 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1472 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1473 | struct drm_crtc *crtc; |
| 1474 | int srwm = 1; |
| 1475 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1476 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1477 | |
| 1478 | /* Calc sr entries for one plane configs */ |
| 1479 | crtc = single_enabled_crtc(dev); |
| 1480 | if (crtc) { |
| 1481 | /* self-refresh has much higher latency */ |
| 1482 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1483 | const struct drm_display_mode *adjusted_mode = |
| 1484 | &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1485 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1486 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1487 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1488 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1489 | unsigned long line_time_us; |
| 1490 | int entries; |
| 1491 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1492 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1493 | |
| 1494 | /* Use ns/us then divide to preserve precision */ |
| 1495 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1496 | pixel_size * hdisplay; |
| 1497 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1498 | srwm = I965_FIFO_SIZE - entries; |
| 1499 | if (srwm < 0) |
| 1500 | srwm = 1; |
| 1501 | srwm &= 0x1ff; |
| 1502 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1503 | entries, srwm); |
| 1504 | |
| 1505 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1506 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1507 | entries = DIV_ROUND_UP(entries, |
| 1508 | i965_cursor_wm_info.cacheline_size); |
| 1509 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1510 | (entries + i965_cursor_wm_info.guard_size); |
| 1511 | |
| 1512 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1513 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1514 | |
| 1515 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1516 | "cursor %d\n", srwm, cursor_sr); |
| 1517 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1518 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1519 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1520 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1521 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1522 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1526 | srwm); |
| 1527 | |
| 1528 | /* 965 has limitations... */ |
| 1529 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
| 1530 | (8 << 16) | (8 << 8) | (8 << 0)); |
| 1531 | I915_WRITE(DSPFW2, (8 << 8) | (8 << 0)); |
| 1532 | /* update cursor SR watermark */ |
| 1533 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1534 | |
| 1535 | if (cxsr_enabled) |
| 1536 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1537 | } |
| 1538 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1539 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1540 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1541 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1542 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1543 | const struct intel_watermark_params *wm_info; |
| 1544 | uint32_t fwater_lo; |
| 1545 | uint32_t fwater_hi; |
| 1546 | int cwm, srwm = 1; |
| 1547 | int fifo_size; |
| 1548 | int planea_wm, planeb_wm; |
| 1549 | struct drm_crtc *crtc, *enabled = NULL; |
| 1550 | |
| 1551 | if (IS_I945GM(dev)) |
| 1552 | wm_info = &i945_wm_info; |
| 1553 | else if (!IS_GEN2(dev)) |
| 1554 | wm_info = &i915_wm_info; |
| 1555 | else |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1556 | wm_info = &i830_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1557 | |
| 1558 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1559 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1560 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1561 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1562 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1563 | if (IS_GEN2(dev)) |
| 1564 | cpp = 4; |
| 1565 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1566 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1567 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1568 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1569 | latency_ns); |
| 1570 | enabled = crtc; |
| 1571 | } else |
| 1572 | planea_wm = fifo_size - wm_info->guard_size; |
| 1573 | |
| 1574 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1575 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1576 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1577 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1578 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1579 | if (IS_GEN2(dev)) |
| 1580 | cpp = 4; |
| 1581 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1582 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1583 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1584 | wm_info, fifo_size, cpp, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1585 | latency_ns); |
| 1586 | if (enabled == NULL) |
| 1587 | enabled = crtc; |
| 1588 | else |
| 1589 | enabled = NULL; |
| 1590 | } else |
| 1591 | planeb_wm = fifo_size - wm_info->guard_size; |
| 1592 | |
| 1593 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1594 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1595 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1596 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1597 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1598 | obj = intel_fb_obj(enabled->primary->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1599 | |
| 1600 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1601 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1602 | enabled = NULL; |
| 1603 | } |
| 1604 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1605 | /* |
| 1606 | * Overlay gets an aggressive default since video jitter is bad. |
| 1607 | */ |
| 1608 | cwm = 2; |
| 1609 | |
| 1610 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1611 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1612 | |
| 1613 | /* Calc sr entries for one plane configs */ |
| 1614 | if (HAS_FW_BLC(dev) && enabled) { |
| 1615 | /* self-refresh has much higher latency */ |
| 1616 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1617 | const struct drm_display_mode *adjusted_mode = |
| 1618 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1619 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1620 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1621 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1622 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1623 | unsigned long line_time_us; |
| 1624 | int entries; |
| 1625 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1626 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1627 | |
| 1628 | /* Use ns/us then divide to preserve precision */ |
| 1629 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1630 | pixel_size * hdisplay; |
| 1631 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1632 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1633 | srwm = wm_info->fifo_size - entries; |
| 1634 | if (srwm < 0) |
| 1635 | srwm = 1; |
| 1636 | |
| 1637 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1638 | I915_WRITE(FW_BLC_SELF, |
| 1639 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1640 | else if (IS_I915GM(dev)) |
| 1641 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1642 | } |
| 1643 | |
| 1644 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1645 | planea_wm, planeb_wm, cwm, srwm); |
| 1646 | |
| 1647 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1648 | fwater_hi = (cwm & 0x1f); |
| 1649 | |
| 1650 | /* Set request length to 8 cachelines per fetch */ |
| 1651 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1652 | fwater_hi = fwater_hi | (1 << 8); |
| 1653 | |
| 1654 | I915_WRITE(FW_BLC, fwater_lo); |
| 1655 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1656 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1657 | if (enabled) |
| 1658 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1659 | } |
| 1660 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1661 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1662 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1663 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1664 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1665 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1666 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1667 | uint32_t fwater_lo; |
| 1668 | int planea_wm; |
| 1669 | |
| 1670 | crtc = single_enabled_crtc(dev); |
| 1671 | if (crtc == NULL) |
| 1672 | return; |
| 1673 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1674 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1675 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1676 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1677 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1678 | 4, latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1679 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1680 | fwater_lo |= (3<<8) | planea_wm; |
| 1681 | |
| 1682 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1683 | |
| 1684 | I915_WRITE(FW_BLC, fwater_lo); |
| 1685 | } |
| 1686 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1687 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1688 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1689 | { |
| 1690 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1691 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1692 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1693 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1694 | |
| 1695 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1696 | * adjust the pixel_rate here. */ |
| 1697 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1698 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1699 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1700 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1701 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1702 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1703 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1704 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1705 | pfit_h = pfit_size & 0xFFFF; |
| 1706 | if (pipe_w < pfit_w) |
| 1707 | pipe_w = pfit_w; |
| 1708 | if (pipe_h < pfit_h) |
| 1709 | pipe_h = pfit_h; |
| 1710 | |
| 1711 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1712 | pfit_w * pfit_h); |
| 1713 | } |
| 1714 | |
| 1715 | return pixel_rate; |
| 1716 | } |
| 1717 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1718 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1719 | 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] | 1720 | uint32_t latency) |
| 1721 | { |
| 1722 | uint64_t ret; |
| 1723 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1724 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1725 | return UINT_MAX; |
| 1726 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1727 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1728 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1729 | |
| 1730 | return ret; |
| 1731 | } |
| 1732 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1733 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1734 | 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] | 1735 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1736 | uint32_t latency) |
| 1737 | { |
| 1738 | uint32_t ret; |
| 1739 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1740 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1741 | return UINT_MAX; |
| 1742 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1743 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1744 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1745 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1746 | return ret; |
| 1747 | } |
| 1748 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1749 | 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] | 1750 | uint8_t bytes_per_pixel) |
| 1751 | { |
| 1752 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1753 | } |
| 1754 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1755 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1756 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1757 | uint32_t pipe_htotal; |
| 1758 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1759 | struct intel_plane_wm_parameters pri; |
| 1760 | struct intel_plane_wm_parameters spr; |
| 1761 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1762 | }; |
| 1763 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1764 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1765 | uint16_t pri; |
| 1766 | uint16_t spr; |
| 1767 | uint16_t cur; |
| 1768 | uint16_t fbc; |
| 1769 | }; |
| 1770 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1771 | /* used in computing the new watermarks state */ |
| 1772 | struct intel_wm_config { |
| 1773 | unsigned int num_pipes_active; |
| 1774 | bool sprites_enabled; |
| 1775 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1776 | }; |
| 1777 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1778 | /* |
| 1779 | * For both WM_PIPE and WM_LP. |
| 1780 | * mem_value must be in 0.1us units. |
| 1781 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1782 | 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] | 1783 | uint32_t mem_value, |
| 1784 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1785 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1786 | uint32_t method1, method2; |
| 1787 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1788 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1789 | return 0; |
| 1790 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1791 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1792 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1793 | mem_value); |
| 1794 | |
| 1795 | if (!is_lp) |
| 1796 | return method1; |
| 1797 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1798 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1799 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1800 | params->pri.horiz_pixels, |
| 1801 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1802 | mem_value); |
| 1803 | |
| 1804 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1805 | } |
| 1806 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1807 | /* |
| 1808 | * For both WM_PIPE and WM_LP. |
| 1809 | * mem_value must be in 0.1us units. |
| 1810 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1811 | 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] | 1812 | uint32_t mem_value) |
| 1813 | { |
| 1814 | uint32_t method1, method2; |
| 1815 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1816 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1817 | return 0; |
| 1818 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1819 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1820 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1821 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1822 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1823 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1824 | params->spr.horiz_pixels, |
| 1825 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1826 | mem_value); |
| 1827 | return min(method1, method2); |
| 1828 | } |
| 1829 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1830 | /* |
| 1831 | * For both WM_PIPE and WM_LP. |
| 1832 | * mem_value must be in 0.1us units. |
| 1833 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1834 | 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] | 1835 | uint32_t mem_value) |
| 1836 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1837 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1838 | return 0; |
| 1839 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1840 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1841 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1842 | params->cur.horiz_pixels, |
| 1843 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1844 | mem_value); |
| 1845 | } |
| 1846 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1847 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1848 | 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] | 1849 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1850 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1851 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1852 | return 0; |
| 1853 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1854 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1855 | params->pri.horiz_pixels, |
| 1856 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1857 | } |
| 1858 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1859 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1860 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1861 | if (INTEL_INFO(dev)->gen >= 8) |
| 1862 | return 3072; |
| 1863 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1864 | return 768; |
| 1865 | else |
| 1866 | return 512; |
| 1867 | } |
| 1868 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1869 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1870 | int level, bool is_sprite) |
| 1871 | { |
| 1872 | if (INTEL_INFO(dev)->gen >= 8) |
| 1873 | /* BDW primary/sprite plane watermarks */ |
| 1874 | return level == 0 ? 255 : 2047; |
| 1875 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1876 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1877 | return level == 0 ? 127 : 1023; |
| 1878 | else if (!is_sprite) |
| 1879 | /* ILK/SNB primary plane watermarks */ |
| 1880 | return level == 0 ? 127 : 511; |
| 1881 | else |
| 1882 | /* ILK/SNB sprite plane watermarks */ |
| 1883 | return level == 0 ? 63 : 255; |
| 1884 | } |
| 1885 | |
| 1886 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1887 | int level) |
| 1888 | { |
| 1889 | if (INTEL_INFO(dev)->gen >= 7) |
| 1890 | return level == 0 ? 63 : 255; |
| 1891 | else |
| 1892 | return level == 0 ? 31 : 63; |
| 1893 | } |
| 1894 | |
| 1895 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1896 | { |
| 1897 | if (INTEL_INFO(dev)->gen >= 8) |
| 1898 | return 31; |
| 1899 | else |
| 1900 | return 15; |
| 1901 | } |
| 1902 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1903 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1904 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1905 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1906 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1907 | enum intel_ddb_partitioning ddb_partitioning, |
| 1908 | bool is_sprite) |
| 1909 | { |
| 1910 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1911 | |
| 1912 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1913 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1914 | return 0; |
| 1915 | |
| 1916 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1917 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1918 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1919 | |
| 1920 | /* |
| 1921 | * For some reason the non self refresh |
| 1922 | * FIFO size is only half of the self |
| 1923 | * refresh FIFO size on ILK/SNB. |
| 1924 | */ |
| 1925 | if (INTEL_INFO(dev)->gen <= 6) |
| 1926 | fifo_size /= 2; |
| 1927 | } |
| 1928 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1929 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1930 | /* level 0 is always calculated with 1:1 split */ |
| 1931 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1932 | if (is_sprite) |
| 1933 | fifo_size *= 5; |
| 1934 | fifo_size /= 6; |
| 1935 | } else { |
| 1936 | fifo_size /= 2; |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1941 | 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] | 1942 | } |
| 1943 | |
| 1944 | /* Calculate the maximum cursor plane watermark */ |
| 1945 | 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] | 1946 | int level, |
| 1947 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1948 | { |
| 1949 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1950 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1951 | return 64; |
| 1952 | |
| 1953 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1954 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1955 | } |
| 1956 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1957 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1958 | int level, |
| 1959 | const struct intel_wm_config *config, |
| 1960 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1961 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1962 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1963 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1964 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1965 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1966 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1967 | } |
| 1968 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1969 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1970 | int level, |
| 1971 | struct ilk_wm_maximums *max) |
| 1972 | { |
| 1973 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1974 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1975 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1976 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1977 | } |
| 1978 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1979 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1980 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1981 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1982 | { |
| 1983 | bool ret; |
| 1984 | |
| 1985 | /* already determined to be invalid? */ |
| 1986 | if (!result->enable) |
| 1987 | return false; |
| 1988 | |
| 1989 | result->enable = result->pri_val <= max->pri && |
| 1990 | result->spr_val <= max->spr && |
| 1991 | result->cur_val <= max->cur; |
| 1992 | |
| 1993 | ret = result->enable; |
| 1994 | |
| 1995 | /* |
| 1996 | * HACK until we can pre-compute everything, |
| 1997 | * and thus fail gracefully if LP0 watermarks |
| 1998 | * are exceeded... |
| 1999 | */ |
| 2000 | if (level == 0 && !result->enable) { |
| 2001 | if (result->pri_val > max->pri) |
| 2002 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2003 | level, result->pri_val, max->pri); |
| 2004 | if (result->spr_val > max->spr) |
| 2005 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2006 | level, result->spr_val, max->spr); |
| 2007 | if (result->cur_val > max->cur) |
| 2008 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2009 | level, result->cur_val, max->cur); |
| 2010 | |
| 2011 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2012 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2013 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2014 | result->enable = true; |
| 2015 | } |
| 2016 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2017 | return ret; |
| 2018 | } |
| 2019 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2020 | 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] | 2021 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2022 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2023 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2024 | { |
| 2025 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2026 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2027 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2028 | |
| 2029 | /* WM1+ latency values stored in 0.5us units */ |
| 2030 | if (level > 0) { |
| 2031 | pri_latency *= 5; |
| 2032 | spr_latency *= 5; |
| 2033 | cur_latency *= 5; |
| 2034 | } |
| 2035 | |
| 2036 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 2037 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 2038 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 2039 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 2040 | result->enable = true; |
| 2041 | } |
| 2042 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2043 | static uint32_t |
| 2044 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2045 | { |
| 2046 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2047 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2048 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2049 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2050 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2051 | if (!intel_crtc_active(crtc)) |
| 2052 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2053 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2054 | /* The WM are computed with base on how long it takes to fill a single |
| 2055 | * row at the given clock rate, multiplied by 8. |
| 2056 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2057 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 2058 | mode->crtc_clock); |
| 2059 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2060 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2061 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2062 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2063 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2064 | } |
| 2065 | |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2066 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2067 | { |
| 2068 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2069 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2070 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2071 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2072 | |
| 2073 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2074 | if (wm[0] == 0) |
| 2075 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2076 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2077 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2078 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2079 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2080 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2081 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2082 | |
| 2083 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2084 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2085 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2086 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2087 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2088 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2089 | |
| 2090 | /* ILK primary LP0 latency is 700 ns */ |
| 2091 | wm[0] = 7; |
| 2092 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2093 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2097 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2098 | { |
| 2099 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2100 | if (INTEL_INFO(dev)->gen == 5) |
| 2101 | wm[0] = 13; |
| 2102 | } |
| 2103 | |
| 2104 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2105 | { |
| 2106 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2107 | if (INTEL_INFO(dev)->gen == 5) |
| 2108 | wm[0] = 13; |
| 2109 | |
| 2110 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2111 | if (IS_IVYBRIDGE(dev)) |
| 2112 | wm[3] *= 2; |
| 2113 | } |
| 2114 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 2115 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2116 | { |
| 2117 | /* how many WM levels are we expecting */ |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2118 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2119 | return 4; |
| 2120 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2121 | return 3; |
| 2122 | else |
| 2123 | return 2; |
| 2124 | } |
| 2125 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2126 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2127 | const char *name, |
| 2128 | const uint16_t wm[5]) |
| 2129 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2130 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2131 | |
| 2132 | for (level = 0; level <= max_level; level++) { |
| 2133 | unsigned int latency = wm[level]; |
| 2134 | |
| 2135 | if (latency == 0) { |
| 2136 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2137 | name, level); |
| 2138 | continue; |
| 2139 | } |
| 2140 | |
| 2141 | /* WM1+ latency values in 0.5us units */ |
| 2142 | if (level > 0) |
| 2143 | latency *= 5; |
| 2144 | |
| 2145 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2146 | name, level, wm[level], |
| 2147 | latency / 10, latency % 10); |
| 2148 | } |
| 2149 | } |
| 2150 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2151 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2152 | uint16_t wm[5], uint16_t min) |
| 2153 | { |
| 2154 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 2155 | |
| 2156 | if (wm[0] >= min) |
| 2157 | return false; |
| 2158 | |
| 2159 | wm[0] = max(wm[0], min); |
| 2160 | for (level = 1; level <= max_level; level++) |
| 2161 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2162 | |
| 2163 | return true; |
| 2164 | } |
| 2165 | |
| 2166 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2167 | { |
| 2168 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2169 | bool changed; |
| 2170 | |
| 2171 | /* |
| 2172 | * The BIOS provided WM memory latency values are often |
| 2173 | * inadequate for high resolution displays. Adjust them. |
| 2174 | */ |
| 2175 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2176 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2177 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2178 | |
| 2179 | if (!changed) |
| 2180 | return; |
| 2181 | |
| 2182 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2183 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2184 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2185 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2186 | } |
| 2187 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2188 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2189 | { |
| 2190 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2191 | |
| 2192 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2193 | |
| 2194 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2195 | sizeof(dev_priv->wm.pri_latency)); |
| 2196 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2197 | sizeof(dev_priv->wm.pri_latency)); |
| 2198 | |
| 2199 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2200 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2201 | |
| 2202 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2203 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2204 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2205 | |
| 2206 | if (IS_GEN6(dev)) |
| 2207 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2208 | } |
| 2209 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2210 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2211 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2212 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2213 | struct drm_device *dev = crtc->dev; |
| 2214 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2215 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2216 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2217 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2218 | if (!intel_crtc_active(crtc)) |
| 2219 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2220 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2221 | p->active = true; |
| 2222 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 2223 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 2224 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 2225 | p->cur.bytes_per_pixel = 4; |
| 2226 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
| 2227 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 2228 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2229 | p->pri.enabled = true; |
| 2230 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2231 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2232 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2233 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2234 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2235 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2236 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2237 | break; |
| 2238 | } |
| 2239 | } |
| 2240 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2241 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2242 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2243 | struct intel_wm_config *config) |
| 2244 | { |
| 2245 | struct intel_crtc *intel_crtc; |
| 2246 | |
| 2247 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2248 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2249 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2250 | |
| 2251 | if (!wm->pipe_enabled) |
| 2252 | continue; |
| 2253 | |
| 2254 | config->sprites_enabled |= wm->sprites_enabled; |
| 2255 | config->sprites_scaled |= wm->sprites_scaled; |
| 2256 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2257 | } |
| 2258 | } |
| 2259 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2260 | /* Compute new watermarks for the pipe */ |
| 2261 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2262 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2263 | struct intel_pipe_wm *pipe_wm) |
| 2264 | { |
| 2265 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2266 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2267 | int level, max_level = ilk_wm_max_level(dev); |
| 2268 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2269 | struct intel_wm_config config = { |
| 2270 | .num_pipes_active = 1, |
| 2271 | .sprites_enabled = params->spr.enabled, |
| 2272 | .sprites_scaled = params->spr.scaled, |
| 2273 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2274 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2275 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2276 | pipe_wm->pipe_enabled = params->active; |
| 2277 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2278 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2279 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2280 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2281 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2282 | max_level = 1; |
| 2283 | |
| 2284 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2285 | if (params->spr.scaled) |
| 2286 | max_level = 0; |
| 2287 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2288 | 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] | 2289 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2290 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2291 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2292 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2293 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2294 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2295 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2296 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2297 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2298 | return false; |
| 2299 | |
| 2300 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2301 | |
| 2302 | for (level = 1; level <= max_level; level++) { |
| 2303 | struct intel_wm_level wm = {}; |
| 2304 | |
| 2305 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2306 | |
| 2307 | /* |
| 2308 | * Disable any watermark level that exceeds the |
| 2309 | * register maximums since such watermarks are |
| 2310 | * always invalid. |
| 2311 | */ |
| 2312 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2313 | break; |
| 2314 | |
| 2315 | pipe_wm->wm[level] = wm; |
| 2316 | } |
| 2317 | |
| 2318 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | /* |
| 2322 | * Merge the watermarks from all active pipes for a specific level. |
| 2323 | */ |
| 2324 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2325 | int level, |
| 2326 | struct intel_wm_level *ret_wm) |
| 2327 | { |
| 2328 | const struct intel_crtc *intel_crtc; |
| 2329 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2330 | ret_wm->enable = true; |
| 2331 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2332 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2333 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2334 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2335 | |
| 2336 | if (!active->pipe_enabled) |
| 2337 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2338 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2339 | /* |
| 2340 | * The watermark values may have been used in the past, |
| 2341 | * so we must maintain them in the registers for some |
| 2342 | * time even if the level is now disabled. |
| 2343 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2344 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2345 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2346 | |
| 2347 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2348 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2349 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2350 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2351 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /* |
| 2355 | * Merge all low power watermarks for all active pipes. |
| 2356 | */ |
| 2357 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2358 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2359 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2360 | struct intel_pipe_wm *merged) |
| 2361 | { |
| 2362 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2363 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2364 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2365 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2366 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2367 | config->num_pipes_active > 1) |
| 2368 | return; |
| 2369 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2370 | /* ILK: FBC WM must be disabled always */ |
| 2371 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2372 | |
| 2373 | /* merge each WM1+ level */ |
| 2374 | for (level = 1; level <= max_level; level++) { |
| 2375 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2376 | |
| 2377 | ilk_merge_wm_level(dev, level, wm); |
| 2378 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2379 | if (level > last_enabled_level) |
| 2380 | wm->enable = false; |
| 2381 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2382 | /* make sure all following levels get disabled */ |
| 2383 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2384 | |
| 2385 | /* |
| 2386 | * The spec says it is preferred to disable |
| 2387 | * FBC WMs instead of disabling a WM level. |
| 2388 | */ |
| 2389 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2390 | if (wm->enable) |
| 2391 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2392 | wm->fbc_val = 0; |
| 2393 | } |
| 2394 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2395 | |
| 2396 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2397 | /* |
| 2398 | * FIXME this is racy. FBC might get enabled later. |
| 2399 | * What we should check here is whether FBC can be |
| 2400 | * enabled sometime later. |
| 2401 | */ |
| 2402 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2403 | for (level = 2; level <= max_level; level++) { |
| 2404 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2405 | |
| 2406 | wm->enable = false; |
| 2407 | } |
| 2408 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2409 | } |
| 2410 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2411 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2412 | { |
| 2413 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2414 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2415 | } |
| 2416 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2417 | /* The value we need to program into the WM_LPx latency field */ |
| 2418 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2419 | { |
| 2420 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2421 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2422 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2423 | return 2 * level; |
| 2424 | else |
| 2425 | return dev_priv->wm.pri_latency[level]; |
| 2426 | } |
| 2427 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2428 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2429 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2430 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2431 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2432 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2433 | struct intel_crtc *intel_crtc; |
| 2434 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2435 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2436 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2437 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2438 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2439 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2440 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2441 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2442 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2443 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2444 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2445 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2446 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2447 | /* |
| 2448 | * Maintain the watermark values even if the level is |
| 2449 | * disabled. Doing otherwise could cause underruns. |
| 2450 | */ |
| 2451 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2452 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2453 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2454 | r->cur_val; |
| 2455 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2456 | if (r->enable) |
| 2457 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2458 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2459 | if (INTEL_INFO(dev)->gen >= 8) |
| 2460 | results->wm_lp[wm_lp - 1] |= |
| 2461 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2462 | else |
| 2463 | results->wm_lp[wm_lp - 1] |= |
| 2464 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2465 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2466 | /* |
| 2467 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2468 | * level is disabled. Doing otherwise could cause underruns. |
| 2469 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2470 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2471 | WARN_ON(wm_lp != 1); |
| 2472 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2473 | } else |
| 2474 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2475 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2476 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2477 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2478 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2479 | enum pipe pipe = intel_crtc->pipe; |
| 2480 | const struct intel_wm_level *r = |
| 2481 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2482 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2483 | if (WARN_ON(!r->enable)) |
| 2484 | continue; |
| 2485 | |
| 2486 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2487 | |
| 2488 | results->wm_pipe[pipe] = |
| 2489 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2490 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2491 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2492 | } |
| 2493 | } |
| 2494 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2495 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2496 | * 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] | 2497 | 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] | 2498 | struct intel_pipe_wm *r1, |
| 2499 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2500 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2501 | int level, max_level = ilk_wm_max_level(dev); |
| 2502 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2503 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2504 | for (level = 1; level <= max_level; level++) { |
| 2505 | if (r1->wm[level].enable) |
| 2506 | level1 = level; |
| 2507 | if (r2->wm[level].enable) |
| 2508 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2509 | } |
| 2510 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2511 | if (level1 == level2) { |
| 2512 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2513 | return r2; |
| 2514 | else |
| 2515 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2516 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2517 | return r1; |
| 2518 | } else { |
| 2519 | return r2; |
| 2520 | } |
| 2521 | } |
| 2522 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2523 | /* dirty bits used to track which watermarks need changes */ |
| 2524 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2525 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2526 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2527 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2528 | #define WM_DIRTY_FBC (1 << 24) |
| 2529 | #define WM_DIRTY_DDB (1 << 25) |
| 2530 | |
| 2531 | static unsigned int ilk_compute_wm_dirty(struct drm_device *dev, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2532 | const struct ilk_wm_values *old, |
| 2533 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2534 | { |
| 2535 | unsigned int dirty = 0; |
| 2536 | enum pipe pipe; |
| 2537 | int wm_lp; |
| 2538 | |
| 2539 | for_each_pipe(pipe) { |
| 2540 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2541 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2542 | /* Must disable LP1+ watermarks too */ |
| 2543 | dirty |= WM_DIRTY_LP_ALL; |
| 2544 | } |
| 2545 | |
| 2546 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2547 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2548 | /* Must disable LP1+ watermarks too */ |
| 2549 | dirty |= WM_DIRTY_LP_ALL; |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2554 | dirty |= WM_DIRTY_FBC; |
| 2555 | /* Must disable LP1+ watermarks too */ |
| 2556 | dirty |= WM_DIRTY_LP_ALL; |
| 2557 | } |
| 2558 | |
| 2559 | if (old->partitioning != new->partitioning) { |
| 2560 | dirty |= WM_DIRTY_DDB; |
| 2561 | /* Must disable LP1+ watermarks too */ |
| 2562 | dirty |= WM_DIRTY_LP_ALL; |
| 2563 | } |
| 2564 | |
| 2565 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2566 | if (dirty & WM_DIRTY_LP_ALL) |
| 2567 | return dirty; |
| 2568 | |
| 2569 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2570 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2571 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2572 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2573 | break; |
| 2574 | } |
| 2575 | |
| 2576 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2577 | for (; wm_lp <= 3; wm_lp++) |
| 2578 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2579 | |
| 2580 | return dirty; |
| 2581 | } |
| 2582 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2583 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2584 | unsigned int dirty) |
| 2585 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2586 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2587 | bool changed = false; |
| 2588 | |
| 2589 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2590 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2591 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2592 | changed = true; |
| 2593 | } |
| 2594 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2595 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2596 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2597 | changed = true; |
| 2598 | } |
| 2599 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2600 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2601 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2602 | changed = true; |
| 2603 | } |
| 2604 | |
| 2605 | /* |
| 2606 | * Don't touch WM1S_LP_EN here. |
| 2607 | * Doing so could cause underruns. |
| 2608 | */ |
| 2609 | |
| 2610 | return changed; |
| 2611 | } |
| 2612 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2613 | /* |
| 2614 | * The spec says we shouldn't write when we don't need, because every write |
| 2615 | * causes WMs to be re-evaluated, expending some power. |
| 2616 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2617 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2618 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2619 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2620 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2621 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2622 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2623 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2624 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2625 | dirty = ilk_compute_wm_dirty(dev, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2626 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2627 | return; |
| 2628 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2629 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2630 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2631 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2632 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2633 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2634 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2635 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2636 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2637 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2638 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2639 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2640 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2641 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2642 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2643 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2644 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2645 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2646 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2647 | val = I915_READ(WM_MISC); |
| 2648 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2649 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2650 | else |
| 2651 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2652 | I915_WRITE(WM_MISC, val); |
| 2653 | } else { |
| 2654 | val = I915_READ(DISP_ARB_CTL2); |
| 2655 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2656 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2657 | else |
| 2658 | val |= DISP_DATA_PARTITION_5_6; |
| 2659 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2660 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2661 | } |
| 2662 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2663 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2664 | val = I915_READ(DISP_ARB_CTL); |
| 2665 | if (results->enable_fbc_wm) |
| 2666 | val &= ~DISP_FBC_WM_DIS; |
| 2667 | else |
| 2668 | val |= DISP_FBC_WM_DIS; |
| 2669 | I915_WRITE(DISP_ARB_CTL, val); |
| 2670 | } |
| 2671 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2672 | if (dirty & WM_DIRTY_LP(1) && |
| 2673 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2674 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2675 | |
| 2676 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2677 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2678 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2679 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2680 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2681 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2682 | |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2683 | 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] | 2684 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2685 | 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] | 2686 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2687 | 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] | 2688 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2689 | |
| 2690 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2691 | } |
| 2692 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2693 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2694 | { |
| 2695 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2696 | |
| 2697 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2698 | } |
| 2699 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2700 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2701 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2702 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2703 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2704 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2705 | struct ilk_wm_maximums max; |
| 2706 | struct ilk_pipe_wm_parameters params = {}; |
| 2707 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2708 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2709 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2710 | 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] | 2711 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2712 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2713 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2714 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2715 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 2716 | |
| 2717 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 2718 | return; |
| 2719 | |
| 2720 | intel_crtc->wm.active = pipe_wm; |
| 2721 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2722 | ilk_compute_wm_config(dev, &config); |
| 2723 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2724 | 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] | 2725 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2726 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2727 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 2728 | if (INTEL_INFO(dev)->gen >= 7 && |
| 2729 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2730 | 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] | 2731 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2732 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2733 | 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] | 2734 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2735 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2736 | } |
| 2737 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2738 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2739 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2740 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2741 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2742 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2743 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2744 | } |
| 2745 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2746 | static void |
| 2747 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 2748 | struct drm_crtc *crtc, |
| 2749 | uint32_t sprite_width, uint32_t sprite_height, |
| 2750 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2751 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2752 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2753 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2754 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2755 | intel_plane->wm.enabled = enabled; |
| 2756 | intel_plane->wm.scaled = scaled; |
| 2757 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2758 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2759 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2760 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2761 | /* |
| 2762 | * IVB workaround: must disable low power watermarks for at least |
| 2763 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 2764 | * when scaling is disabled. |
| 2765 | * |
| 2766 | * WaCxSRDisabledForSpriteScaling:ivb |
| 2767 | */ |
| 2768 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 2769 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 2770 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2771 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2772 | } |
| 2773 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2774 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 2775 | { |
| 2776 | struct drm_device *dev = crtc->dev; |
| 2777 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2778 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2779 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2780 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2781 | enum pipe pipe = intel_crtc->pipe; |
| 2782 | static const unsigned int wm0_pipe_reg[] = { |
| 2783 | [PIPE_A] = WM0_PIPEA_ILK, |
| 2784 | [PIPE_B] = WM0_PIPEB_ILK, |
| 2785 | [PIPE_C] = WM0_PIPEC_IVB, |
| 2786 | }; |
| 2787 | |
| 2788 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2789 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2790 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2791 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2792 | active->pipe_enabled = intel_crtc_active(crtc); |
| 2793 | |
| 2794 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2795 | u32 tmp = hw->wm_pipe[pipe]; |
| 2796 | |
| 2797 | /* |
| 2798 | * For active pipes LP0 watermark is marked as |
| 2799 | * enabled, and LP1+ watermaks as disabled since |
| 2800 | * we can't really reverse compute them in case |
| 2801 | * multiple pipes are active. |
| 2802 | */ |
| 2803 | active->wm[0].enable = true; |
| 2804 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 2805 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 2806 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 2807 | active->linetime = hw->wm_linetime[pipe]; |
| 2808 | } else { |
| 2809 | int level, max_level = ilk_wm_max_level(dev); |
| 2810 | |
| 2811 | /* |
| 2812 | * For inactive pipes, all watermark levels |
| 2813 | * should be marked as enabled but zeroed, |
| 2814 | * which is what we'd compute them to. |
| 2815 | */ |
| 2816 | for (level = 0; level <= max_level; level++) |
| 2817 | active->wm[level].enable = true; |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 2822 | { |
| 2823 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2824 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2825 | struct drm_crtc *crtc; |
| 2826 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2827 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2828 | ilk_pipe_wm_get_hw_state(crtc); |
| 2829 | |
| 2830 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 2831 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 2832 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 2833 | |
| 2834 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 2835 | if (INTEL_INFO(dev)->gen >= 7) { |
| 2836 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 2837 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 2838 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2839 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2840 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2841 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 2842 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 2843 | else if (IS_IVYBRIDGE(dev)) |
| 2844 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 2845 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2846 | |
| 2847 | hw->enable_fbc_wm = |
| 2848 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 2849 | } |
| 2850 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2851 | /** |
| 2852 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 2853 | * |
| 2854 | * Calculate watermark values for the various WM regs based on current mode |
| 2855 | * and plane configuration. |
| 2856 | * |
| 2857 | * There are several cases to deal with here: |
| 2858 | * - normal (i.e. non-self-refresh) |
| 2859 | * - self-refresh (SR) mode |
| 2860 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 2861 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 2862 | * lines), so need to account for TLB latency |
| 2863 | * |
| 2864 | * The normal calculation is: |
| 2865 | * watermark = dotclock * bytes per pixel * latency |
| 2866 | * where latency is platform & configuration dependent (we assume pessimal |
| 2867 | * values here). |
| 2868 | * |
| 2869 | * The SR calculation is: |
| 2870 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 2871 | * bytes per pixel |
| 2872 | * where |
| 2873 | * line time = htotal / dotclock |
| 2874 | * surface width = hdisplay for normal plane and 64 for cursor |
| 2875 | * and latency is assumed to be high, as above. |
| 2876 | * |
| 2877 | * The final value programmed to the register should always be rounded up, |
| 2878 | * and include an extra 2 entries to account for clock crossings. |
| 2879 | * |
| 2880 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 2881 | * to set the non-SR watermarks to 8. |
| 2882 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2883 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2884 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2885 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2886 | |
| 2887 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2888 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2889 | } |
| 2890 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2891 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 2892 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2893 | uint32_t sprite_width, |
| 2894 | uint32_t sprite_height, |
| 2895 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2896 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2897 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2898 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2899 | |
| 2900 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2901 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 2902 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 2903 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2904 | } |
| 2905 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2906 | static struct drm_i915_gem_object * |
| 2907 | intel_alloc_context_page(struct drm_device *dev) |
| 2908 | { |
| 2909 | struct drm_i915_gem_object *ctx; |
| 2910 | int ret; |
| 2911 | |
| 2912 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2913 | |
| 2914 | ctx = i915_gem_alloc_object(dev, 4096); |
| 2915 | if (!ctx) { |
| 2916 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 2917 | return NULL; |
| 2918 | } |
| 2919 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 2920 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2921 | if (ret) { |
| 2922 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 2923 | goto err_unref; |
| 2924 | } |
| 2925 | |
| 2926 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 2927 | if (ret) { |
| 2928 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 2929 | goto err_unpin; |
| 2930 | } |
| 2931 | |
| 2932 | return ctx; |
| 2933 | |
| 2934 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 2935 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2936 | err_unref: |
| 2937 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2938 | return NULL; |
| 2939 | } |
| 2940 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2941 | /** |
| 2942 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2943 | */ |
| 2944 | DEFINE_SPINLOCK(mchdev_lock); |
| 2945 | |
| 2946 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 2947 | * mchdev_lock. */ |
| 2948 | static struct drm_i915_private *i915_mch_dev; |
| 2949 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2950 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 2951 | { |
| 2952 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2953 | u16 rgvswctl; |
| 2954 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2955 | assert_spin_locked(&mchdev_lock); |
| 2956 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2957 | rgvswctl = I915_READ16(MEMSWCTL); |
| 2958 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 2959 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 2960 | return false; /* still busy with another command */ |
| 2961 | } |
| 2962 | |
| 2963 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 2964 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 2965 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2966 | POSTING_READ16(MEMSWCTL); |
| 2967 | |
| 2968 | rgvswctl |= MEMCTL_CMD_STS; |
| 2969 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 2970 | |
| 2971 | return true; |
| 2972 | } |
| 2973 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 2974 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2975 | { |
| 2976 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2977 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 2978 | u8 fmax, fmin, fstart, vstart; |
| 2979 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 2980 | spin_lock_irq(&mchdev_lock); |
| 2981 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 2982 | /* Enable temp reporting */ |
| 2983 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 2984 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 2985 | |
| 2986 | /* 100ms RC evaluation intervals */ |
| 2987 | I915_WRITE(RCUPEI, 100000); |
| 2988 | I915_WRITE(RCDNEI, 100000); |
| 2989 | |
| 2990 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 2991 | I915_WRITE(RCBMAXAVG, 90000); |
| 2992 | I915_WRITE(RCBMINAVG, 80000); |
| 2993 | |
| 2994 | I915_WRITE(MEMIHYST, 1); |
| 2995 | |
| 2996 | /* Set up min, max, and cur for interrupt handling */ |
| 2997 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 2998 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 2999 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3000 | MEMMODE_FSTART_SHIFT; |
| 3001 | |
| 3002 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3003 | PXVFREQ_PX_SHIFT; |
| 3004 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3005 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3006 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3007 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3008 | dev_priv->ips.max_delay = fstart; |
| 3009 | dev_priv->ips.min_delay = fmin; |
| 3010 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3011 | |
| 3012 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3013 | fmax, fmin, fstart); |
| 3014 | |
| 3015 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3016 | |
| 3017 | /* |
| 3018 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3019 | */ |
| 3020 | |
| 3021 | I915_WRITE(VIDSTART, vstart); |
| 3022 | POSTING_READ(VIDSTART); |
| 3023 | |
| 3024 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3025 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3026 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3027 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3028 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3029 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3030 | |
| 3031 | ironlake_set_drps(dev, fstart); |
| 3032 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3033 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3034 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3035 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3036 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
| 3037 | getrawmonotonic(&dev_priv->ips.last_time2); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3038 | |
| 3039 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3040 | } |
| 3041 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3042 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3043 | { |
| 3044 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3045 | u16 rgvswctl; |
| 3046 | |
| 3047 | spin_lock_irq(&mchdev_lock); |
| 3048 | |
| 3049 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3050 | |
| 3051 | /* Ack interrupts, disable EFC interrupt */ |
| 3052 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3053 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3054 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3055 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3056 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3057 | |
| 3058 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3059 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3060 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3061 | rgvswctl |= MEMCTL_CMD_STS; |
| 3062 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3063 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3064 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3065 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3066 | } |
| 3067 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3068 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3069 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3070 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3071 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3072 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3073 | 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] | 3074 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3075 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3076 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3077 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3078 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3079 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3080 | * the hw runs at the minimal clock before selecting the desired |
| 3081 | * frequency, if the down threshold expires in that window we will not |
| 3082 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3083 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3084 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3085 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3086 | |
| 3087 | return limits; |
| 3088 | } |
| 3089 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3090 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3091 | { |
| 3092 | int new_power; |
| 3093 | |
| 3094 | new_power = dev_priv->rps.power; |
| 3095 | switch (dev_priv->rps.power) { |
| 3096 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3097 | 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] | 3098 | new_power = BETWEEN; |
| 3099 | break; |
| 3100 | |
| 3101 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3102 | 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] | 3103 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3104 | 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] | 3105 | new_power = HIGH_POWER; |
| 3106 | break; |
| 3107 | |
| 3108 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3109 | 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] | 3110 | new_power = BETWEEN; |
| 3111 | break; |
| 3112 | } |
| 3113 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3114 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3115 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3116 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3117 | new_power = HIGH_POWER; |
| 3118 | if (new_power == dev_priv->rps.power) |
| 3119 | return; |
| 3120 | |
| 3121 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3122 | switch (new_power) { |
| 3123 | case LOW_POWER: |
| 3124 | /* Upclock if more than 95% busy over 16ms */ |
| 3125 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 3126 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 3127 | |
| 3128 | /* Downclock if less than 85% busy over 32ms */ |
| 3129 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3130 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3131 | |
| 3132 | I915_WRITE(GEN6_RP_CONTROL, |
| 3133 | GEN6_RP_MEDIA_TURBO | |
| 3134 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3135 | GEN6_RP_MEDIA_IS_GFX | |
| 3136 | GEN6_RP_ENABLE | |
| 3137 | GEN6_RP_UP_BUSY_AVG | |
| 3138 | GEN6_RP_DOWN_IDLE_AVG); |
| 3139 | break; |
| 3140 | |
| 3141 | case BETWEEN: |
| 3142 | /* Upclock if more than 90% busy over 13ms */ |
| 3143 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3144 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3145 | |
| 3146 | /* Downclock if less than 75% busy over 32ms */ |
| 3147 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3148 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3149 | |
| 3150 | I915_WRITE(GEN6_RP_CONTROL, |
| 3151 | GEN6_RP_MEDIA_TURBO | |
| 3152 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3153 | GEN6_RP_MEDIA_IS_GFX | |
| 3154 | GEN6_RP_ENABLE | |
| 3155 | GEN6_RP_UP_BUSY_AVG | |
| 3156 | GEN6_RP_DOWN_IDLE_AVG); |
| 3157 | break; |
| 3158 | |
| 3159 | case HIGH_POWER: |
| 3160 | /* Upclock if more than 85% busy over 10ms */ |
| 3161 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3162 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3163 | |
| 3164 | /* Downclock if less than 60% busy over 32ms */ |
| 3165 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3166 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3167 | |
| 3168 | I915_WRITE(GEN6_RP_CONTROL, |
| 3169 | GEN6_RP_MEDIA_TURBO | |
| 3170 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3171 | GEN6_RP_MEDIA_IS_GFX | |
| 3172 | GEN6_RP_ENABLE | |
| 3173 | GEN6_RP_UP_BUSY_AVG | |
| 3174 | GEN6_RP_DOWN_IDLE_AVG); |
| 3175 | break; |
| 3176 | } |
| 3177 | |
| 3178 | dev_priv->rps.power = new_power; |
| 3179 | dev_priv->rps.last_adj = 0; |
| 3180 | } |
| 3181 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3182 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3183 | { |
| 3184 | u32 mask = 0; |
| 3185 | |
| 3186 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3187 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3188 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3189 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3190 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3191 | mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED); |
| 3192 | mask &= dev_priv->pm_rps_events; |
| 3193 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3194 | /* IVB and SNB hard hangs on looping batchbuffer |
| 3195 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 3196 | */ |
| 3197 | if (INTEL_INFO(dev_priv->dev)->gen <= 7 && !IS_HASWELL(dev_priv->dev)) |
| 3198 | mask |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 3199 | |
Deepak S | baccd45 | 2014-05-15 20:58:09 +0300 | [diff] [blame] | 3200 | if (IS_GEN8(dev_priv->dev)) |
| 3201 | mask |= GEN8_PMINTR_REDIRECT_TO_NON_DISP; |
| 3202 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3203 | return ~mask; |
| 3204 | } |
| 3205 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3206 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3207 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3208 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3209 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 3210 | { |
| 3211 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3212 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3213 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3214 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3215 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3216 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3217 | /* min/max delay may still have been modified so be sure to |
| 3218 | * write the limits value. |
| 3219 | */ |
| 3220 | if (val != dev_priv->rps.cur_freq) { |
| 3221 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3222 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3223 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3224 | I915_WRITE(GEN6_RPNSWREQ, |
| 3225 | HSW_FREQUENCY(val)); |
| 3226 | else |
| 3227 | I915_WRITE(GEN6_RPNSWREQ, |
| 3228 | GEN6_FREQUENCY(val) | |
| 3229 | GEN6_OFFSET(0) | |
| 3230 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3231 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3232 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3233 | /* Make sure we continue to get interrupts |
| 3234 | * until we hit the minimum or maximum frequencies. |
| 3235 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3236 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3237 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3238 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3239 | POSTING_READ(GEN6_RPNSWREQ); |
| 3240 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3241 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9 | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3242 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3243 | } |
| 3244 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3245 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3246 | * |
| 3247 | * * If Gfx is Idle, then |
| 3248 | * 1. Mask Turbo interrupts |
| 3249 | * 2. Bring up Gfx clock |
| 3250 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3251 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3252 | * 5. Unmask Turbo interrupts |
| 3253 | */ |
| 3254 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3255 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3256 | struct drm_device *dev = dev_priv->dev; |
| 3257 | |
| 3258 | /* Latest VLV doesn't need to force the gfx clock */ |
| 3259 | if (dev->pdev->revision >= 0xd) { |
| 3260 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3261 | return; |
| 3262 | } |
| 3263 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3264 | /* |
| 3265 | * When we are idle. Drop to min voltage state. |
| 3266 | */ |
| 3267 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3268 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3269 | return; |
| 3270 | |
| 3271 | /* Mask turbo interrupt so that they will not come in between */ |
| 3272 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 3273 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3274 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3275 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3276 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3277 | |
| 3278 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3279 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3280 | |
| 3281 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
| 3282 | & GENFREQSTATUS) == 0, 5)) |
| 3283 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3284 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3285 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3286 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3287 | I915_WRITE(GEN6_PMINTRMSK, |
| 3288 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3289 | } |
| 3290 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3291 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3292 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3293 | struct drm_device *dev = dev_priv->dev; |
| 3294 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3295 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3296 | if (dev_priv->rps.enabled) { |
Deepak S | 3463811 | 2014-06-28 11:26:26 +0530 | [diff] [blame] | 3297 | if (IS_CHERRYVIEW(dev)) |
| 3298 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3299 | else if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3300 | vlv_set_rps_idle(dev_priv); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3301 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3302 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3303 | dev_priv->rps.last_adj = 0; |
| 3304 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3305 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3306 | } |
| 3307 | |
| 3308 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3309 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3310 | struct drm_device *dev = dev_priv->dev; |
| 3311 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3312 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3313 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3314 | if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3315 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3316 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3317 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3318 | dev_priv->rps.last_adj = 0; |
| 3319 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3320 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3321 | } |
| 3322 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3323 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3324 | { |
| 3325 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 3326 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3327 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3328 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3329 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3330 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3331 | 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] | 3332 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 3333 | dev_priv->rps.cur_freq, |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3334 | vlv_gpu_freq(dev_priv, val), val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3335 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3336 | if (val != dev_priv->rps.cur_freq) |
| 3337 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3338 | |
Imre Deak | 09c87db | 2014-04-03 20:02:42 +0300 | [diff] [blame] | 3339 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3340 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3341 | dev_priv->rps.cur_freq = val; |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3342 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3345 | static void gen8_disable_rps_interrupts(struct drm_device *dev) |
| 3346 | { |
| 3347 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3348 | |
Mika Kuoppala | 992f191 | 2014-05-16 13:44:12 +0300 | [diff] [blame] | 3349 | I915_WRITE(GEN6_PMINTRMSK, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3350 | I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) & |
| 3351 | ~dev_priv->pm_rps_events); |
| 3352 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3353 | * item again unmasking PM interrupts because that is using a different |
| 3354 | * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in |
| 3355 | * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which |
| 3356 | * gen8_enable_rps will clean up. */ |
| 3357 | |
| 3358 | spin_lock_irq(&dev_priv->irq_lock); |
| 3359 | dev_priv->rps.pm_iir = 0; |
| 3360 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3361 | |
| 3362 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3363 | } |
| 3364 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3365 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3366 | { |
| 3367 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3368 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3369 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3370 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & |
| 3371 | ~dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3372 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3373 | * item again unmasking PM interrupts because that is using a different |
| 3374 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 3375 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 3376 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3377 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3378 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3379 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3380 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3381 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3382 | } |
| 3383 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3384 | static void gen6_disable_rps(struct drm_device *dev) |
| 3385 | { |
| 3386 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3387 | |
| 3388 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3389 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 3390 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3391 | if (IS_BROADWELL(dev)) |
| 3392 | gen8_disable_rps_interrupts(dev); |
| 3393 | else |
| 3394 | gen6_disable_rps_interrupts(dev); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3395 | } |
| 3396 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3397 | static void cherryview_disable_rps(struct drm_device *dev) |
| 3398 | { |
| 3399 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3400 | |
| 3401 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 3402 | |
| 3403 | gen8_disable_rps_interrupts(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3404 | } |
| 3405 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3406 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3407 | { |
| 3408 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3409 | |
| 3410 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3411 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3412 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3415 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3416 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3417 | if (IS_VALLEYVIEW(dev)) { |
| 3418 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3419 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3420 | else |
| 3421 | mode = 0; |
| 3422 | } |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3423 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n", |
| 3424 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3425 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3426 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3429 | 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] | 3430 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3431 | /* No RC6 before Ironlake */ |
| 3432 | if (INTEL_INFO(dev)->gen < 5) |
| 3433 | return 0; |
| 3434 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3435 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3436 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3437 | return 0; |
| 3438 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3439 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3440 | if (enable_rc6 >= 0) { |
| 3441 | int mask; |
| 3442 | |
| 3443 | if (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev)) |
| 3444 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3445 | INTEL_RC6pp_ENABLE; |
| 3446 | else |
| 3447 | mask = INTEL_RC6_ENABLE; |
| 3448 | |
| 3449 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3450 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 3451 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3452 | |
| 3453 | return enable_rc6 & mask; |
| 3454 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3455 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3456 | /* Disable RC6 on Ironlake */ |
| 3457 | if (INTEL_INFO(dev)->gen == 5) |
| 3458 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3459 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3460 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 3461 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3462 | |
| 3463 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3464 | } |
| 3465 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3466 | int intel_enable_rc6(const struct drm_device *dev) |
| 3467 | { |
| 3468 | return i915.enable_rc6; |
| 3469 | } |
| 3470 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3471 | static void gen8_enable_rps_interrupts(struct drm_device *dev) |
| 3472 | { |
| 3473 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3474 | |
| 3475 | spin_lock_irq(&dev_priv->irq_lock); |
| 3476 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 3477 | gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3478 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3479 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3480 | } |
| 3481 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3482 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 3483 | { |
| 3484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3485 | |
| 3486 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 3487 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 3488 | gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3489 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3490 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3491 | } |
| 3492 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3493 | static void parse_rp_state_cap(struct drm_i915_private *dev_priv, u32 rp_state_cap) |
| 3494 | { |
| 3495 | /* All of these values are in units of 50MHz */ |
| 3496 | dev_priv->rps.cur_freq = 0; |
| 3497 | /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */ |
| 3498 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 3499 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 3500 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 3501 | /* XXX: only BYT has a special efficient freq */ |
| 3502 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 3503 | /* hw_max = RP0 until we check for overclocking */ |
| 3504 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 3505 | |
| 3506 | /* Preserve min/max settings in case of re-init */ |
| 3507 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3508 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3509 | |
| 3510 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 3511 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 3512 | } |
| 3513 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3514 | static void gen8_enable_rps(struct drm_device *dev) |
| 3515 | { |
| 3516 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3517 | struct intel_engine_cs *ring; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3518 | uint32_t rc6_mask = 0, rp_state_cap; |
| 3519 | int unused; |
| 3520 | |
| 3521 | /* 1a: Software RC state - RC0 */ |
| 3522 | I915_WRITE(GEN6_RC_STATE, 0); |
| 3523 | |
| 3524 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 3525 | * 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] | 3526 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3527 | |
| 3528 | /* 2a: Disable RC states. */ |
| 3529 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3530 | |
| 3531 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3532 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3533 | |
| 3534 | /* 2b: Program RC6 thresholds.*/ |
| 3535 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 3536 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 3537 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 3538 | for_each_ring(ring, dev_priv, unused) |
| 3539 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3540 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3541 | if (IS_BROADWELL(dev)) |
| 3542 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 3543 | else |
| 3544 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3545 | |
| 3546 | /* 3: Enable RC6 */ |
| 3547 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 3548 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 3549 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3550 | if (IS_BROADWELL(dev)) |
| 3551 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3552 | GEN7_RC_CTL_TO_MODE | |
| 3553 | rc6_mask); |
| 3554 | else |
| 3555 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3556 | GEN6_RC_CTL_EI_MODE(1) | |
| 3557 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3558 | |
| 3559 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 3560 | I915_WRITE(GEN6_RPNSWREQ, |
| 3561 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 3562 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 3563 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3564 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 3565 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
| 3566 | |
| 3567 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 3568 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3569 | dev_priv->rps.max_freq_softlimit << 24 | |
| 3570 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3571 | |
| 3572 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 3573 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 3574 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 3575 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
| 3576 | |
| 3577 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3578 | |
| 3579 | /* 5: Enable RPS */ |
| 3580 | I915_WRITE(GEN6_RP_CONTROL, |
| 3581 | GEN6_RP_MEDIA_TURBO | |
| 3582 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 3583 | GEN6_RP_MEDIA_IS_GFX | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3584 | GEN6_RP_ENABLE | |
| 3585 | GEN6_RP_UP_BUSY_AVG | |
| 3586 | GEN6_RP_DOWN_IDLE_AVG); |
| 3587 | |
| 3588 | /* 6: Ring frequency + overclocking (our driver does this later */ |
| 3589 | |
| 3590 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
| 3591 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3592 | gen8_enable_rps_interrupts(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3593 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3594 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3597 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3598 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3599 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3600 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3601 | u32 rp_state_cap; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3602 | u32 gt_perf_status; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3603 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3604 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3605 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3606 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3607 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3608 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3609 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3610 | /* Here begins a magic sequence of register writes to enable |
| 3611 | * auto-downclocking. |
| 3612 | * |
| 3613 | * Perhaps there might be some value in exposing these to |
| 3614 | * userspace... |
| 3615 | */ |
| 3616 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3617 | |
| 3618 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 3619 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 3620 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 3621 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3622 | } |
| 3623 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3624 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3625 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3626 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
| 3627 | gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS); |
| 3628 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3629 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3630 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3631 | /* disable the counters and set deterministic thresholds */ |
| 3632 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3633 | |
| 3634 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 3635 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 3636 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 3637 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3638 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3639 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3640 | for_each_ring(ring, dev_priv, i) |
| 3641 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3642 | |
| 3643 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3644 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 3645 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 3646 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 3647 | else |
| 3648 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 3649 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3650 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 3651 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3652 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3653 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 3654 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 3655 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 3656 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3657 | /* We don't use those on Haswell */ |
| 3658 | if (!IS_HASWELL(dev)) { |
| 3659 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 3660 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3661 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3662 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 3663 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 3664 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3665 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3666 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3667 | |
| 3668 | I915_WRITE(GEN6_RC_CONTROL, |
| 3669 | rc6_mask | |
| 3670 | GEN6_RC_CTL_EI_MODE(1) | |
| 3671 | GEN6_RC_CTL_HW_ENABLE); |
| 3672 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3673 | /* Power down if completely idle for over 50ms */ |
| 3674 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3675 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3676 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3677 | 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] | 3678 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3679 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3680 | |
| 3681 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 3682 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 3683 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3684 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3685 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3686 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3687 | } |
| 3688 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3689 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3690 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3691 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3692 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3693 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 3694 | rc6vids = 0; |
| 3695 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 3696 | if (IS_GEN6(dev) && ret) { |
| 3697 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 3698 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 3699 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 3700 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 3701 | rc6vids &= 0xffff00; |
| 3702 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 3703 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 3704 | if (ret) |
| 3705 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 3706 | } |
| 3707 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3708 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3709 | } |
| 3710 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 3711 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3712 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3713 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3714 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3715 | unsigned int gpu_freq; |
| 3716 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3717 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3718 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3719 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3720 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3721 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3722 | policy = cpufreq_cpu_get(0); |
| 3723 | if (policy) { |
| 3724 | max_ia_freq = policy->cpuinfo.max_freq; |
| 3725 | cpufreq_cpu_put(policy); |
| 3726 | } else { |
| 3727 | /* |
| 3728 | * Default to measured freq if none found, PCU will ensure we |
| 3729 | * don't go over |
| 3730 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3731 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 3732 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3733 | |
| 3734 | /* Convert from kHz to MHz */ |
| 3735 | max_ia_freq /= 1000; |
| 3736 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 3737 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3738 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 3739 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3740 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3741 | /* |
| 3742 | * For each potential GPU frequency, load a ring frequency we'd like |
| 3743 | * to use for memory access. We do this by specifying the IA frequency |
| 3744 | * the PCU should use as a reference to determine the ring frequency. |
| 3745 | */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3746 | 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] | 3747 | gpu_freq--) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3748 | int diff = dev_priv->rps.max_freq_softlimit - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3749 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3750 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 3751 | if (INTEL_INFO(dev)->gen >= 8) { |
| 3752 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 3753 | ring_freq = max(min_ring_freq, gpu_freq); |
| 3754 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 3755 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3756 | ring_freq = max(min_ring_freq, ring_freq); |
| 3757 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 3758 | } else { |
| 3759 | /* On older processors, there is no separate ring |
| 3760 | * clock domain, so in order to boost the bandwidth |
| 3761 | * of the ring, we need to upclock the CPU (ia_freq). |
| 3762 | * |
| 3763 | * For GPU frequencies less than 750MHz, |
| 3764 | * just use the lowest ring freq. |
| 3765 | */ |
| 3766 | if (gpu_freq < min_freq) |
| 3767 | ia_freq = 800; |
| 3768 | else |
| 3769 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 3770 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 3771 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3772 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3773 | sandybridge_pcode_write(dev_priv, |
| 3774 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 3775 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 3776 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 3777 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3778 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3779 | } |
| 3780 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 3781 | void gen6_update_ring_freq(struct drm_device *dev) |
| 3782 | { |
| 3783 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3784 | |
| 3785 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 3786 | return; |
| 3787 | |
| 3788 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3789 | __gen6_update_ring_freq(dev); |
| 3790 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3791 | } |
| 3792 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 3793 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 3794 | { |
| 3795 | u32 val, rp0; |
| 3796 | |
| 3797 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 3798 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 3799 | |
| 3800 | return rp0; |
| 3801 | } |
| 3802 | |
| 3803 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 3804 | { |
| 3805 | u32 val, rpe; |
| 3806 | |
| 3807 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 3808 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 3809 | |
| 3810 | return rpe; |
| 3811 | } |
| 3812 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 3813 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 3814 | { |
| 3815 | u32 val, rp1; |
| 3816 | |
| 3817 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 3818 | rp1 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 3819 | |
| 3820 | return rp1; |
| 3821 | } |
| 3822 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 3823 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 3824 | { |
| 3825 | u32 val, rpn; |
| 3826 | |
| 3827 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 3828 | rpn = (val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK; |
| 3829 | return rpn; |
| 3830 | } |
| 3831 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 3832 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 3833 | { |
| 3834 | u32 val, rp1; |
| 3835 | |
| 3836 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 3837 | |
| 3838 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 3839 | |
| 3840 | return rp1; |
| 3841 | } |
| 3842 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 3843 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3844 | { |
| 3845 | u32 val, rp0; |
| 3846 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3847 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3848 | |
| 3849 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 3850 | /* Clamp to max */ |
| 3851 | rp0 = min_t(u32, rp0, 0xea); |
| 3852 | |
| 3853 | return rp0; |
| 3854 | } |
| 3855 | |
| 3856 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 3857 | { |
| 3858 | u32 val, rpe; |
| 3859 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3860 | 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] | 3861 | 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] | 3862 | 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] | 3863 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 3864 | |
| 3865 | return rpe; |
| 3866 | } |
| 3867 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 3868 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3869 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 3870 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3871 | } |
| 3872 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3873 | /* Check that the pctx buffer wasn't move under us. */ |
| 3874 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 3875 | { |
| 3876 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 3877 | |
| 3878 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 3879 | dev_priv->vlv_pctx->stolen->start); |
| 3880 | } |
| 3881 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3882 | |
| 3883 | /* Check that the pcbr address is not empty. */ |
| 3884 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 3885 | { |
| 3886 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 3887 | |
| 3888 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 3889 | } |
| 3890 | |
| 3891 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 3892 | { |
| 3893 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3894 | unsigned long pctx_paddr, paddr; |
| 3895 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 3896 | u32 pcbr; |
| 3897 | int pctx_size = 32*1024; |
| 3898 | |
| 3899 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3900 | |
| 3901 | pcbr = I915_READ(VLV_PCBR); |
| 3902 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
| 3903 | paddr = (dev_priv->mm.stolen_base + |
| 3904 | (gtt->stolen_size - pctx_size)); |
| 3905 | |
| 3906 | pctx_paddr = (paddr & (~4095)); |
| 3907 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 3908 | } |
| 3909 | } |
| 3910 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3911 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 3912 | { |
| 3913 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3914 | struct drm_i915_gem_object *pctx; |
| 3915 | unsigned long pctx_paddr; |
| 3916 | u32 pcbr; |
| 3917 | int pctx_size = 24*1024; |
| 3918 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 3919 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3920 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3921 | pcbr = I915_READ(VLV_PCBR); |
| 3922 | if (pcbr) { |
| 3923 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 3924 | int pcbr_offset; |
| 3925 | |
| 3926 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 3927 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 3928 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 3929 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 3930 | pctx_size); |
| 3931 | goto out; |
| 3932 | } |
| 3933 | |
| 3934 | /* |
| 3935 | * From the Gunit register HAS: |
| 3936 | * The Gfx driver is expected to program this register and ensure |
| 3937 | * proper allocation within Gfx stolen memory. For example, this |
| 3938 | * register should be programmed such than the PCBR range does not |
| 3939 | * overlap with other ranges, such as the frame buffer, protected |
| 3940 | * memory, or any other relevant ranges. |
| 3941 | */ |
| 3942 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 3943 | if (!pctx) { |
| 3944 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 3945 | return; |
| 3946 | } |
| 3947 | |
| 3948 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 3949 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 3950 | |
| 3951 | out: |
| 3952 | dev_priv->vlv_pctx = pctx; |
| 3953 | } |
| 3954 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 3955 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 3956 | { |
| 3957 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3958 | |
| 3959 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 3960 | return; |
| 3961 | |
| 3962 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 3963 | dev_priv->vlv_pctx = NULL; |
| 3964 | } |
| 3965 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 3966 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 3967 | { |
| 3968 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3969 | |
| 3970 | valleyview_setup_pctx(dev); |
| 3971 | |
| 3972 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3973 | |
| 3974 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 3975 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 3976 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 3977 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 3978 | dev_priv->rps.max_freq); |
| 3979 | |
| 3980 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 3981 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 3982 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 3983 | dev_priv->rps.efficient_freq); |
| 3984 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 3985 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 3986 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
| 3987 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 3988 | dev_priv->rps.rp1_freq); |
| 3989 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 3990 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 3991 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 3992 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 3993 | dev_priv->rps.min_freq); |
| 3994 | |
| 3995 | /* Preserve min/max settings in case of re-init */ |
| 3996 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3997 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3998 | |
| 3999 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4000 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4001 | |
| 4002 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4003 | } |
| 4004 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4005 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4006 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4007 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4008 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4009 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4010 | |
| 4011 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4012 | |
| 4013 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4014 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4015 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 4016 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 4017 | dev_priv->rps.max_freq); |
| 4018 | |
| 4019 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4020 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 4021 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4022 | dev_priv->rps.efficient_freq); |
| 4023 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4024 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4025 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
| 4026 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 4027 | dev_priv->rps.rp1_freq); |
| 4028 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4029 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4030 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 4031 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 4032 | dev_priv->rps.min_freq); |
| 4033 | |
| 4034 | /* Preserve min/max settings in case of re-init */ |
| 4035 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4036 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4037 | |
| 4038 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4039 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4040 | |
| 4041 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4042 | } |
| 4043 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4044 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4045 | { |
| 4046 | valleyview_cleanup_pctx(dev); |
| 4047 | } |
| 4048 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4049 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4050 | { |
| 4051 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4052 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4053 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4054 | int i; |
| 4055 | |
| 4056 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4057 | |
| 4058 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4059 | if (gtfifodbg) { |
| 4060 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4061 | gtfifodbg); |
| 4062 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4063 | } |
| 4064 | |
| 4065 | cherryview_check_pctx(dev_priv); |
| 4066 | |
| 4067 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4068 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
| 4069 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 4070 | |
| 4071 | /* 2a: Program RC6 thresholds.*/ |
| 4072 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4073 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4074 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4075 | |
| 4076 | for_each_ring(ring, dev_priv, i) |
| 4077 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4078 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4079 | |
| 4080 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 4081 | |
| 4082 | /* allows RC6 residency counter to work */ |
| 4083 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4084 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4085 | VLV_MEDIA_RC6_COUNT_EN | |
| 4086 | VLV_RENDER_RC6_COUNT_EN)); |
| 4087 | |
| 4088 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 4089 | pcbr = I915_READ(VLV_PCBR); |
| 4090 | |
| 4091 | DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr); |
| 4092 | |
| 4093 | /* 3: Enable RC6 */ |
| 4094 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 4095 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
| 4096 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 4097 | |
| 4098 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 4099 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4100 | /* 4 Program defaults and thresholds for RPS*/ |
| 4101 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4102 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4103 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4104 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4105 | |
| 4106 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4107 | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4108 | /* WaDisablePwrmtrEvent:chv (pre-production hw) */ |
| 4109 | I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff); |
| 4110 | I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00); |
| 4111 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4112 | /* 5: Enable RPS */ |
| 4113 | I915_WRITE(GEN6_RP_CONTROL, |
| 4114 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4115 | GEN6_RP_MEDIA_IS_GFX | /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4116 | GEN6_RP_ENABLE | |
| 4117 | GEN6_RP_UP_BUSY_AVG | |
| 4118 | GEN6_RP_DOWN_IDLE_AVG); |
| 4119 | |
| 4120 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4121 | |
| 4122 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4123 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4124 | |
| 4125 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 4126 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
| 4127 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4128 | dev_priv->rps.cur_freq); |
| 4129 | |
| 4130 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
| 4131 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4132 | dev_priv->rps.efficient_freq); |
| 4133 | |
| 4134 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 4135 | |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 4136 | gen8_enable_rps_interrupts(dev); |
| 4137 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4138 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 4139 | } |
| 4140 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4141 | static void valleyview_enable_rps(struct drm_device *dev) |
| 4142 | { |
| 4143 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4144 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4145 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4146 | int i; |
| 4147 | |
| 4148 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4149 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4150 | valleyview_check_pctx(dev_priv); |
| 4151 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4152 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 4153 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4154 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4155 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4156 | } |
| 4157 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4158 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 4159 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4160 | |
| 4161 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4162 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4163 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4164 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4165 | |
| 4166 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4167 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4168 | |
| 4169 | I915_WRITE(GEN6_RP_CONTROL, |
| 4170 | GEN6_RP_MEDIA_TURBO | |
| 4171 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4172 | GEN6_RP_MEDIA_IS_GFX | |
| 4173 | GEN6_RP_ENABLE | |
| 4174 | GEN6_RP_UP_BUSY_AVG | |
| 4175 | GEN6_RP_DOWN_IDLE_CONT); |
| 4176 | |
| 4177 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 4178 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4179 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4180 | |
| 4181 | for_each_ring(ring, dev_priv, i) |
| 4182 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4183 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 4184 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4185 | |
| 4186 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4187 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4188 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 4189 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4190 | VLV_MEDIA_RC6_COUNT_EN | |
| 4191 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4192 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4193 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 4194 | 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] | 4195 | |
| 4196 | intel_print_rc6_info(dev, rc6_mode); |
| 4197 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4198 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4199 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4200 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4201 | |
| 4202 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4203 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4204 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4205 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4206 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4207 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4208 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4209 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4210 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4211 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4212 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4213 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4214 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4215 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4216 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4217 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4218 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4221 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4222 | { |
| 4223 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4224 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4225 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4226 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4227 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 4228 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4229 | } |
| 4230 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4231 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4232 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4233 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 4234 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4235 | } |
| 4236 | } |
| 4237 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4238 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4239 | { |
| 4240 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4241 | |
| 4242 | if (I915_READ(PWRCTXA)) { |
| 4243 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 4244 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 4245 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 4246 | 50); |
| 4247 | |
| 4248 | I915_WRITE(PWRCTXA, 0); |
| 4249 | POSTING_READ(PWRCTXA); |
| 4250 | |
| 4251 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 4252 | POSTING_READ(RSTDBYCTL); |
| 4253 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 4257 | { |
| 4258 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4259 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4260 | if (dev_priv->ips.renderctx == NULL) |
| 4261 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 4262 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4263 | return -ENOMEM; |
| 4264 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4265 | if (dev_priv->ips.pwrctx == NULL) |
| 4266 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 4267 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4268 | ironlake_teardown_rc6(dev); |
| 4269 | return -ENOMEM; |
| 4270 | } |
| 4271 | |
| 4272 | return 0; |
| 4273 | } |
| 4274 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4275 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4276 | { |
| 4277 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4278 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4279 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4280 | int ret; |
| 4281 | |
| 4282 | /* rc6 disabled by default due to repeated reports of hanging during |
| 4283 | * boot and resume. |
| 4284 | */ |
| 4285 | if (!intel_enable_rc6(dev)) |
| 4286 | return; |
| 4287 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4288 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4289 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4290 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4291 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4292 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4293 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4294 | was_interruptible = dev_priv->mm.interruptible; |
| 4295 | dev_priv->mm.interruptible = false; |
| 4296 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4297 | /* |
| 4298 | * GPU can automatically power down the render unit if given a page |
| 4299 | * to save state. |
| 4300 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4301 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4302 | if (ret) { |
| 4303 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4304 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4305 | return; |
| 4306 | } |
| 4307 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4308 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 4309 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4310 | 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] | 4311 | MI_MM_SPACE_GTT | |
| 4312 | MI_SAVE_EXT_STATE_EN | |
| 4313 | MI_RESTORE_EXT_STATE_EN | |
| 4314 | MI_RESTORE_INHIBIT); |
| 4315 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 4316 | intel_ring_emit(ring, MI_NOOP); |
| 4317 | intel_ring_emit(ring, MI_FLUSH); |
| 4318 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4319 | |
| 4320 | /* |
| 4321 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 4322 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 4323 | * safe to assume that renderctx is valid |
| 4324 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4325 | ret = intel_ring_idle(ring); |
| 4326 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4327 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 4328 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4329 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4330 | return; |
| 4331 | } |
| 4332 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4333 | 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] | 4334 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4335 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4336 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4337 | } |
| 4338 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4339 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 4340 | { |
| 4341 | unsigned long freq; |
| 4342 | int div = (vidfreq & 0x3f0000) >> 16; |
| 4343 | int post = (vidfreq & 0x3000) >> 12; |
| 4344 | int pre = (vidfreq & 0x7); |
| 4345 | |
| 4346 | if (!pre) |
| 4347 | return 0; |
| 4348 | |
| 4349 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 4350 | |
| 4351 | return freq; |
| 4352 | } |
| 4353 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4354 | static const struct cparams { |
| 4355 | u16 i; |
| 4356 | u16 t; |
| 4357 | u16 m; |
| 4358 | u16 c; |
| 4359 | } cparams[] = { |
| 4360 | { 1, 1333, 301, 28664 }, |
| 4361 | { 1, 1066, 294, 24460 }, |
| 4362 | { 1, 800, 294, 25192 }, |
| 4363 | { 0, 1333, 276, 27605 }, |
| 4364 | { 0, 1066, 276, 27605 }, |
| 4365 | { 0, 800, 231, 23784 }, |
| 4366 | }; |
| 4367 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4368 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4369 | { |
| 4370 | u64 total_count, diff, ret; |
| 4371 | u32 count1, count2, count3, m = 0, c = 0; |
| 4372 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 4373 | int i; |
| 4374 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4375 | assert_spin_locked(&mchdev_lock); |
| 4376 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4377 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4378 | |
| 4379 | /* Prevent division-by-zero if we are asking too fast. |
| 4380 | * Also, we don't get interesting results if we are polling |
| 4381 | * faster than once in 10ms, so just return the saved value |
| 4382 | * in such cases. |
| 4383 | */ |
| 4384 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4385 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4386 | |
| 4387 | count1 = I915_READ(DMIEC); |
| 4388 | count2 = I915_READ(DDREC); |
| 4389 | count3 = I915_READ(CSIEC); |
| 4390 | |
| 4391 | total_count = count1 + count2 + count3; |
| 4392 | |
| 4393 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4394 | if (total_count < dev_priv->ips.last_count1) { |
| 4395 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4396 | diff += total_count; |
| 4397 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4398 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4402 | if (cparams[i].i == dev_priv->ips.c_m && |
| 4403 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4404 | m = cparams[i].m; |
| 4405 | c = cparams[i].c; |
| 4406 | break; |
| 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | diff = div_u64(diff, diff1); |
| 4411 | ret = ((m * diff) + c); |
| 4412 | ret = div_u64(ret, 10); |
| 4413 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4414 | dev_priv->ips.last_count1 = total_count; |
| 4415 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4416 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4417 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4418 | |
| 4419 | return ret; |
| 4420 | } |
| 4421 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4422 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 4423 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4424 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4425 | unsigned long val; |
| 4426 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4427 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4428 | return 0; |
| 4429 | |
| 4430 | spin_lock_irq(&mchdev_lock); |
| 4431 | |
| 4432 | val = __i915_chipset_val(dev_priv); |
| 4433 | |
| 4434 | spin_unlock_irq(&mchdev_lock); |
| 4435 | |
| 4436 | return val; |
| 4437 | } |
| 4438 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4439 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 4440 | { |
| 4441 | unsigned long m, x, b; |
| 4442 | u32 tsfs; |
| 4443 | |
| 4444 | tsfs = I915_READ(TSFS); |
| 4445 | |
| 4446 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 4447 | x = I915_READ8(TR1); |
| 4448 | |
| 4449 | b = tsfs & TSFS_INTR_MASK; |
| 4450 | |
| 4451 | return ((m * x) / 127) - b; |
| 4452 | } |
| 4453 | |
| 4454 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 4455 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4456 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4457 | static const struct v_table { |
| 4458 | u16 vd; /* in .1 mil */ |
| 4459 | u16 vm; /* in .1 mil */ |
| 4460 | } v_table[] = { |
| 4461 | { 0, 0, }, |
| 4462 | { 375, 0, }, |
| 4463 | { 500, 0, }, |
| 4464 | { 625, 0, }, |
| 4465 | { 750, 0, }, |
| 4466 | { 875, 0, }, |
| 4467 | { 1000, 0, }, |
| 4468 | { 1125, 0, }, |
| 4469 | { 4125, 3000, }, |
| 4470 | { 4125, 3000, }, |
| 4471 | { 4125, 3000, }, |
| 4472 | { 4125, 3000, }, |
| 4473 | { 4125, 3000, }, |
| 4474 | { 4125, 3000, }, |
| 4475 | { 4125, 3000, }, |
| 4476 | { 4125, 3000, }, |
| 4477 | { 4125, 3000, }, |
| 4478 | { 4125, 3000, }, |
| 4479 | { 4125, 3000, }, |
| 4480 | { 4125, 3000, }, |
| 4481 | { 4125, 3000, }, |
| 4482 | { 4125, 3000, }, |
| 4483 | { 4125, 3000, }, |
| 4484 | { 4125, 3000, }, |
| 4485 | { 4125, 3000, }, |
| 4486 | { 4125, 3000, }, |
| 4487 | { 4125, 3000, }, |
| 4488 | { 4125, 3000, }, |
| 4489 | { 4125, 3000, }, |
| 4490 | { 4125, 3000, }, |
| 4491 | { 4125, 3000, }, |
| 4492 | { 4125, 3000, }, |
| 4493 | { 4250, 3125, }, |
| 4494 | { 4375, 3250, }, |
| 4495 | { 4500, 3375, }, |
| 4496 | { 4625, 3500, }, |
| 4497 | { 4750, 3625, }, |
| 4498 | { 4875, 3750, }, |
| 4499 | { 5000, 3875, }, |
| 4500 | { 5125, 4000, }, |
| 4501 | { 5250, 4125, }, |
| 4502 | { 5375, 4250, }, |
| 4503 | { 5500, 4375, }, |
| 4504 | { 5625, 4500, }, |
| 4505 | { 5750, 4625, }, |
| 4506 | { 5875, 4750, }, |
| 4507 | { 6000, 4875, }, |
| 4508 | { 6125, 5000, }, |
| 4509 | { 6250, 5125, }, |
| 4510 | { 6375, 5250, }, |
| 4511 | { 6500, 5375, }, |
| 4512 | { 6625, 5500, }, |
| 4513 | { 6750, 5625, }, |
| 4514 | { 6875, 5750, }, |
| 4515 | { 7000, 5875, }, |
| 4516 | { 7125, 6000, }, |
| 4517 | { 7250, 6125, }, |
| 4518 | { 7375, 6250, }, |
| 4519 | { 7500, 6375, }, |
| 4520 | { 7625, 6500, }, |
| 4521 | { 7750, 6625, }, |
| 4522 | { 7875, 6750, }, |
| 4523 | { 8000, 6875, }, |
| 4524 | { 8125, 7000, }, |
| 4525 | { 8250, 7125, }, |
| 4526 | { 8375, 7250, }, |
| 4527 | { 8500, 7375, }, |
| 4528 | { 8625, 7500, }, |
| 4529 | { 8750, 7625, }, |
| 4530 | { 8875, 7750, }, |
| 4531 | { 9000, 7875, }, |
| 4532 | { 9125, 8000, }, |
| 4533 | { 9250, 8125, }, |
| 4534 | { 9375, 8250, }, |
| 4535 | { 9500, 8375, }, |
| 4536 | { 9625, 8500, }, |
| 4537 | { 9750, 8625, }, |
| 4538 | { 9875, 8750, }, |
| 4539 | { 10000, 8875, }, |
| 4540 | { 10125, 9000, }, |
| 4541 | { 10250, 9125, }, |
| 4542 | { 10375, 9250, }, |
| 4543 | { 10500, 9375, }, |
| 4544 | { 10625, 9500, }, |
| 4545 | { 10750, 9625, }, |
| 4546 | { 10875, 9750, }, |
| 4547 | { 11000, 9875, }, |
| 4548 | { 11125, 10000, }, |
| 4549 | { 11250, 10125, }, |
| 4550 | { 11375, 10250, }, |
| 4551 | { 11500, 10375, }, |
| 4552 | { 11625, 10500, }, |
| 4553 | { 11750, 10625, }, |
| 4554 | { 11875, 10750, }, |
| 4555 | { 12000, 10875, }, |
| 4556 | { 12125, 11000, }, |
| 4557 | { 12250, 11125, }, |
| 4558 | { 12375, 11250, }, |
| 4559 | { 12500, 11375, }, |
| 4560 | { 12625, 11500, }, |
| 4561 | { 12750, 11625, }, |
| 4562 | { 12875, 11750, }, |
| 4563 | { 13000, 11875, }, |
| 4564 | { 13125, 12000, }, |
| 4565 | { 13250, 12125, }, |
| 4566 | { 13375, 12250, }, |
| 4567 | { 13500, 12375, }, |
| 4568 | { 13625, 12500, }, |
| 4569 | { 13750, 12625, }, |
| 4570 | { 13875, 12750, }, |
| 4571 | { 14000, 12875, }, |
| 4572 | { 14125, 13000, }, |
| 4573 | { 14250, 13125, }, |
| 4574 | { 14375, 13250, }, |
| 4575 | { 14500, 13375, }, |
| 4576 | { 14625, 13500, }, |
| 4577 | { 14750, 13625, }, |
| 4578 | { 14875, 13750, }, |
| 4579 | { 15000, 13875, }, |
| 4580 | { 15125, 14000, }, |
| 4581 | { 15250, 14125, }, |
| 4582 | { 15375, 14250, }, |
| 4583 | { 15500, 14375, }, |
| 4584 | { 15625, 14500, }, |
| 4585 | { 15750, 14625, }, |
| 4586 | { 15875, 14750, }, |
| 4587 | { 16000, 14875, }, |
| 4588 | { 16125, 15000, }, |
| 4589 | }; |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4590 | if (INTEL_INFO(dev)->is_mobile) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4591 | return v_table[pxvid].vm; |
| 4592 | else |
| 4593 | return v_table[pxvid].vd; |
| 4594 | } |
| 4595 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4596 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4597 | { |
| 4598 | struct timespec now, diff1; |
| 4599 | u64 diff; |
| 4600 | unsigned long diffms; |
| 4601 | u32 count; |
| 4602 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4603 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4604 | |
| 4605 | getrawmonotonic(&now); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4606 | diff1 = timespec_sub(now, dev_priv->ips.last_time2); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4607 | |
| 4608 | /* Don't divide by 0 */ |
| 4609 | diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000; |
| 4610 | if (!diffms) |
| 4611 | return; |
| 4612 | |
| 4613 | count = I915_READ(GFXEC); |
| 4614 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4615 | if (count < dev_priv->ips.last_count2) { |
| 4616 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4617 | diff += count; |
| 4618 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4619 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4620 | } |
| 4621 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4622 | dev_priv->ips.last_count2 = count; |
| 4623 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4624 | |
| 4625 | /* More magic constants... */ |
| 4626 | diff = diff * 1181; |
| 4627 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4628 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4629 | } |
| 4630 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4631 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 4632 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4633 | struct drm_device *dev = dev_priv->dev; |
| 4634 | |
| 4635 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4636 | return; |
| 4637 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4638 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4639 | |
| 4640 | __i915_update_gfx_val(dev_priv); |
| 4641 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4642 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4643 | } |
| 4644 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4645 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4646 | { |
| 4647 | unsigned long t, corr, state1, corr2, state2; |
| 4648 | u32 pxvid, ext_v; |
| 4649 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4650 | assert_spin_locked(&mchdev_lock); |
| 4651 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4652 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4653 | pxvid = (pxvid >> 24) & 0x7f; |
| 4654 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 4655 | |
| 4656 | state1 = ext_v; |
| 4657 | |
| 4658 | t = i915_mch_val(dev_priv); |
| 4659 | |
| 4660 | /* Revel in the empirically derived constants */ |
| 4661 | |
| 4662 | /* Correction factor in 1/100000 units */ |
| 4663 | if (t > 80) |
| 4664 | corr = ((t * 2349) + 135940); |
| 4665 | else if (t >= 50) |
| 4666 | corr = ((t * 964) + 29317); |
| 4667 | else /* < 50 */ |
| 4668 | corr = ((t * 301) + 1004); |
| 4669 | |
| 4670 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 4671 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4672 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4673 | |
| 4674 | state2 = (corr2 * state1) / 10000; |
| 4675 | state2 /= 100; /* convert to mW */ |
| 4676 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4677 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4678 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4679 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4680 | } |
| 4681 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4682 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 4683 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4684 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4685 | unsigned long val; |
| 4686 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4687 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4688 | return 0; |
| 4689 | |
| 4690 | spin_lock_irq(&mchdev_lock); |
| 4691 | |
| 4692 | val = __i915_gfx_val(dev_priv); |
| 4693 | |
| 4694 | spin_unlock_irq(&mchdev_lock); |
| 4695 | |
| 4696 | return val; |
| 4697 | } |
| 4698 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4699 | /** |
| 4700 | * i915_read_mch_val - return value for IPS use |
| 4701 | * |
| 4702 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 4703 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 4704 | */ |
| 4705 | unsigned long i915_read_mch_val(void) |
| 4706 | { |
| 4707 | struct drm_i915_private *dev_priv; |
| 4708 | unsigned long chipset_val, graphics_val, ret = 0; |
| 4709 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4710 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4711 | if (!i915_mch_dev) |
| 4712 | goto out_unlock; |
| 4713 | dev_priv = i915_mch_dev; |
| 4714 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4715 | chipset_val = __i915_chipset_val(dev_priv); |
| 4716 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4717 | |
| 4718 | ret = chipset_val + graphics_val; |
| 4719 | |
| 4720 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4721 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4722 | |
| 4723 | return ret; |
| 4724 | } |
| 4725 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 4726 | |
| 4727 | /** |
| 4728 | * i915_gpu_raise - raise GPU frequency limit |
| 4729 | * |
| 4730 | * Raise the limit; IPS indicates we have thermal headroom. |
| 4731 | */ |
| 4732 | bool i915_gpu_raise(void) |
| 4733 | { |
| 4734 | struct drm_i915_private *dev_priv; |
| 4735 | bool ret = true; |
| 4736 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4737 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4738 | if (!i915_mch_dev) { |
| 4739 | ret = false; |
| 4740 | goto out_unlock; |
| 4741 | } |
| 4742 | dev_priv = i915_mch_dev; |
| 4743 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4744 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 4745 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4746 | |
| 4747 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4748 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4749 | |
| 4750 | return ret; |
| 4751 | } |
| 4752 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 4753 | |
| 4754 | /** |
| 4755 | * i915_gpu_lower - lower GPU frequency limit |
| 4756 | * |
| 4757 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 4758 | * frequency maximum. |
| 4759 | */ |
| 4760 | bool i915_gpu_lower(void) |
| 4761 | { |
| 4762 | struct drm_i915_private *dev_priv; |
| 4763 | bool ret = true; |
| 4764 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4765 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4766 | if (!i915_mch_dev) { |
| 4767 | ret = false; |
| 4768 | goto out_unlock; |
| 4769 | } |
| 4770 | dev_priv = i915_mch_dev; |
| 4771 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4772 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 4773 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4774 | |
| 4775 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4776 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4777 | |
| 4778 | return ret; |
| 4779 | } |
| 4780 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 4781 | |
| 4782 | /** |
| 4783 | * i915_gpu_busy - indicate GPU business to IPS |
| 4784 | * |
| 4785 | * Tell the IPS driver whether or not the GPU is busy. |
| 4786 | */ |
| 4787 | bool i915_gpu_busy(void) |
| 4788 | { |
| 4789 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4790 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4791 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4792 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4793 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4794 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4795 | if (!i915_mch_dev) |
| 4796 | goto out_unlock; |
| 4797 | dev_priv = i915_mch_dev; |
| 4798 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 4799 | for_each_ring(ring, dev_priv, i) |
| 4800 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4801 | |
| 4802 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4803 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4804 | |
| 4805 | return ret; |
| 4806 | } |
| 4807 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 4808 | |
| 4809 | /** |
| 4810 | * i915_gpu_turbo_disable - disable graphics turbo |
| 4811 | * |
| 4812 | * Disable graphics turbo by resetting the max frequency and setting the |
| 4813 | * current frequency to the default. |
| 4814 | */ |
| 4815 | bool i915_gpu_turbo_disable(void) |
| 4816 | { |
| 4817 | struct drm_i915_private *dev_priv; |
| 4818 | bool ret = true; |
| 4819 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4820 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4821 | if (!i915_mch_dev) { |
| 4822 | ret = false; |
| 4823 | goto out_unlock; |
| 4824 | } |
| 4825 | dev_priv = i915_mch_dev; |
| 4826 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4827 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4828 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4829 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4830 | ret = false; |
| 4831 | |
| 4832 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4833 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4834 | |
| 4835 | return ret; |
| 4836 | } |
| 4837 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 4838 | |
| 4839 | /** |
| 4840 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 4841 | * IPS got loaded first. |
| 4842 | * |
| 4843 | * This awkward dance is so that neither module has to depend on the |
| 4844 | * other in order for IPS to do the appropriate communication of |
| 4845 | * GPU turbo limits to i915. |
| 4846 | */ |
| 4847 | static void |
| 4848 | ips_ping_for_i915_load(void) |
| 4849 | { |
| 4850 | void (*link)(void); |
| 4851 | |
| 4852 | link = symbol_get(ips_link_to_i915_driver); |
| 4853 | if (link) { |
| 4854 | link(); |
| 4855 | symbol_put(ips_link_to_i915_driver); |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 4860 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4861 | /* We only register the i915 ips part with intel-ips once everything is |
| 4862 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4863 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4864 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4865 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4866 | |
| 4867 | ips_ping_for_i915_load(); |
| 4868 | } |
| 4869 | |
| 4870 | void intel_gpu_ips_teardown(void) |
| 4871 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4872 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4873 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4874 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4875 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4876 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4877 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4878 | { |
| 4879 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4880 | u32 lcfuse; |
| 4881 | u8 pxw[16]; |
| 4882 | int i; |
| 4883 | |
| 4884 | /* Disable to program */ |
| 4885 | I915_WRITE(ECR, 0); |
| 4886 | POSTING_READ(ECR); |
| 4887 | |
| 4888 | /* Program energy weights for various events */ |
| 4889 | I915_WRITE(SDEW, 0x15040d00); |
| 4890 | I915_WRITE(CSIEW0, 0x007f0000); |
| 4891 | I915_WRITE(CSIEW1, 0x1e220004); |
| 4892 | I915_WRITE(CSIEW2, 0x04000004); |
| 4893 | |
| 4894 | for (i = 0; i < 5; i++) |
| 4895 | I915_WRITE(PEW + (i * 4), 0); |
| 4896 | for (i = 0; i < 3; i++) |
| 4897 | I915_WRITE(DEW + (i * 4), 0); |
| 4898 | |
| 4899 | /* Program P-state weights to account for frequency power adjustment */ |
| 4900 | for (i = 0; i < 16; i++) { |
| 4901 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 4902 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 4903 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 4904 | PXVFREQ_PX_SHIFT; |
| 4905 | unsigned long val; |
| 4906 | |
| 4907 | val = vid * vid; |
| 4908 | val *= (freq / 1000); |
| 4909 | val *= 255; |
| 4910 | val /= (127*127*900); |
| 4911 | if (val > 0xff) |
| 4912 | DRM_ERROR("bad pxval: %ld\n", val); |
| 4913 | pxw[i] = val; |
| 4914 | } |
| 4915 | /* Render standby states get 0 weight */ |
| 4916 | pxw[14] = 0; |
| 4917 | pxw[15] = 0; |
| 4918 | |
| 4919 | for (i = 0; i < 4; i++) { |
| 4920 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 4921 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 4922 | I915_WRITE(PXW + (i * 4), val); |
| 4923 | } |
| 4924 | |
| 4925 | /* Adjust magic regs to magic values (more experimental results) */ |
| 4926 | I915_WRITE(OGW0, 0); |
| 4927 | I915_WRITE(OGW1, 0); |
| 4928 | I915_WRITE(EG0, 0x00007f00); |
| 4929 | I915_WRITE(EG1, 0x0000000e); |
| 4930 | I915_WRITE(EG2, 0x000e0000); |
| 4931 | I915_WRITE(EG3, 0x68000300); |
| 4932 | I915_WRITE(EG4, 0x42000000); |
| 4933 | I915_WRITE(EG5, 0x00140031); |
| 4934 | I915_WRITE(EG6, 0); |
| 4935 | I915_WRITE(EG7, 0); |
| 4936 | |
| 4937 | for (i = 0; i < 8; i++) |
| 4938 | I915_WRITE(PXWL + (i * 4), 0); |
| 4939 | |
| 4940 | /* Enable PMON + select events */ |
| 4941 | I915_WRITE(ECR, 0x80000019); |
| 4942 | |
| 4943 | lcfuse = I915_READ(LCFUSE02); |
| 4944 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4945 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4946 | } |
| 4947 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4948 | void intel_init_gt_powersave(struct drm_device *dev) |
| 4949 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4950 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 4951 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4952 | if (IS_CHERRYVIEW(dev)) |
| 4953 | cherryview_init_gt_powersave(dev); |
| 4954 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4955 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 4959 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4960 | if (IS_CHERRYVIEW(dev)) |
| 4961 | return; |
| 4962 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4963 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4964 | } |
| 4965 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 4966 | /** |
| 4967 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 4968 | * @dev: drm device |
| 4969 | * |
| 4970 | * We don't want to disable RC6 or other features here, we just want |
| 4971 | * to make sure any work we've queued has finished and won't bother |
| 4972 | * us while we're suspended. |
| 4973 | */ |
| 4974 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 4975 | { |
| 4976 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4977 | |
| 4978 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 4979 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 4980 | |
| 4981 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 4982 | |
| 4983 | cancel_work_sync(&dev_priv->rps.work); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 4984 | |
| 4985 | /* Force GPU to min freq during suspend */ |
| 4986 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 4987 | } |
| 4988 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4989 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 4990 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 4991 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4992 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 4993 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 4994 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 4995 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4996 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4997 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4998 | ironlake_disable_rc6(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4999 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5000 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5001 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5002 | mutex_lock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5003 | if (IS_CHERRYVIEW(dev)) |
| 5004 | cherryview_disable_rps(dev); |
| 5005 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5006 | valleyview_disable_rps(dev); |
| 5007 | else |
| 5008 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5009 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5010 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5011 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5012 | } |
| 5013 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5014 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5015 | { |
| 5016 | struct drm_i915_private *dev_priv = |
| 5017 | container_of(work, struct drm_i915_private, |
| 5018 | rps.delayed_resume_work.work); |
| 5019 | struct drm_device *dev = dev_priv->dev; |
| 5020 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5021 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5022 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5023 | if (IS_CHERRYVIEW(dev)) { |
| 5024 | cherryview_enable_rps(dev); |
| 5025 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5026 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5027 | } else if (IS_BROADWELL(dev)) { |
| 5028 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5029 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5030 | } else { |
| 5031 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5032 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5033 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5034 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5035 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5036 | |
| 5037 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5040 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5041 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5042 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5043 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5044 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5045 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5046 | ironlake_enable_drps(dev); |
| 5047 | ironlake_enable_rc6(dev); |
| 5048 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5049 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5050 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5051 | /* |
| 5052 | * PCU communication is slow and this doesn't need to be |
| 5053 | * done at any specific time, so do this out of our fast path |
| 5054 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5055 | * |
| 5056 | * We depend on the HW RC6 power context save/restore |
| 5057 | * mechanism when entering D3 through runtime PM suspend. So |
| 5058 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5059 | * get here via the driver load/system resume/runtime resume |
| 5060 | * paths, so the _noresume version is enough (and in case of |
| 5061 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5062 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5063 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5064 | round_jiffies_up_relative(HZ))) |
| 5065 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5066 | } |
| 5067 | } |
| 5068 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5069 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5070 | { |
| 5071 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5072 | |
| 5073 | dev_priv->rps.enabled = false; |
| 5074 | intel_enable_gt_powersave(dev); |
| 5075 | } |
| 5076 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5077 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5078 | { |
| 5079 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5080 | |
| 5081 | /* |
| 5082 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5083 | * gating for the panel power sequencer or it will fail to |
| 5084 | * start up when no ports are active. |
| 5085 | */ |
| 5086 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5087 | } |
| 5088 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5089 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5090 | { |
| 5091 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5092 | int pipe; |
| 5093 | |
| 5094 | for_each_pipe(pipe) { |
| 5095 | I915_WRITE(DSPCNTR(pipe), |
| 5096 | I915_READ(DSPCNTR(pipe)) | |
| 5097 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5098 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5099 | } |
| 5100 | } |
| 5101 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5102 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5103 | { |
| 5104 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5105 | |
| 5106 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5107 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5108 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5109 | |
| 5110 | /* |
| 5111 | * Don't touch WM1S_LP_EN here. |
| 5112 | * Doing so could cause underruns. |
| 5113 | */ |
| 5114 | } |
| 5115 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5116 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5117 | { |
| 5118 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5119 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5120 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5121 | /* |
| 5122 | * Required for FBC |
| 5123 | * WaFbcDisableDpfcClockGating:ilk |
| 5124 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5125 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5126 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5127 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5128 | |
| 5129 | I915_WRITE(PCH_3DCGDIS0, |
| 5130 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5131 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5132 | I915_WRITE(PCH_3DCGDIS1, |
| 5133 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5134 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5135 | /* |
| 5136 | * According to the spec the following bits should be set in |
| 5137 | * order to enable memory self-refresh |
| 5138 | * The bit 22/21 of 0x42004 |
| 5139 | * The bit 5 of 0x42020 |
| 5140 | * The bit 15 of 0x45000 |
| 5141 | */ |
| 5142 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5143 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5144 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5145 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5146 | I915_WRITE(DISP_ARB_CTL, |
| 5147 | (I915_READ(DISP_ARB_CTL) | |
| 5148 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5149 | |
| 5150 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5151 | |
| 5152 | /* |
| 5153 | * Based on the document from hardware guys the following bits |
| 5154 | * should be set unconditionally in order to enable FBC. |
| 5155 | * The bit 22 of 0x42000 |
| 5156 | * The bit 22 of 0x42004 |
| 5157 | * The bit 7,8,9 of 0x42020. |
| 5158 | */ |
| 5159 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5160 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5161 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5162 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5163 | ILK_FBCQ_DIS); |
| 5164 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5165 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5166 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5167 | } |
| 5168 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5169 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5170 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5171 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5172 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5173 | ILK_ELPIN_409_SELECT); |
| 5174 | I915_WRITE(_3D_CHICKEN2, |
| 5175 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5176 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5177 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5178 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5179 | I915_WRITE(CACHE_MODE_0, |
| 5180 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5181 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5182 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5183 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5184 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5185 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5186 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5187 | ibx_init_clock_gating(dev); |
| 5188 | } |
| 5189 | |
| 5190 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5191 | { |
| 5192 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5193 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5194 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5195 | |
| 5196 | /* |
| 5197 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5198 | * gating for the panel power sequencer or it will fail to |
| 5199 | * start up when no ports are active. |
| 5200 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5201 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5202 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5203 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5204 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5205 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5206 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5207 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5208 | */ |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5209 | for_each_pipe(pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5210 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5211 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5212 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5213 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5214 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5215 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5216 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5217 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5218 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5219 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5220 | /* WADP0ClockGatingDisable */ |
| 5221 | for_each_pipe(pipe) { |
| 5222 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5223 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5224 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5225 | } |
| 5226 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5227 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5228 | { |
| 5229 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5230 | uint32_t tmp; |
| 5231 | |
| 5232 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame^] | 5233 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5234 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5235 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5238 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5239 | { |
| 5240 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5241 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5242 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5243 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5244 | |
| 5245 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5246 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5247 | ILK_ELPIN_409_SELECT); |
| 5248 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5249 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5250 | I915_WRITE(_3D_CHICKEN, |
| 5251 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5252 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5253 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 5254 | if (IS_SNB_GT1(dev)) |
| 5255 | I915_WRITE(GEN6_GT_MODE, |
| 5256 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 5257 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5258 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5259 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5260 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5261 | /* |
| 5262 | * BSpec recoomends 8x4 when MSAA is used, |
| 5263 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5264 | * |
| 5265 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5266 | * disable bit, which we don't touch here, but it's good |
| 5267 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5268 | */ |
| 5269 | I915_WRITE(GEN6_GT_MODE, |
| 5270 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5271 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5272 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5273 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5274 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5275 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5276 | |
| 5277 | I915_WRITE(GEN6_UCGCTL1, |
| 5278 | I915_READ(GEN6_UCGCTL1) | |
| 5279 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5280 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5281 | |
| 5282 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5283 | * gating disable must be set. Failure to set it results in |
| 5284 | * flickering pixels due to Z write ordering failures after |
| 5285 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5286 | * Sanctuary and Tropics, and apparently anything else with |
| 5287 | * alpha test or pixel discard. |
| 5288 | * |
| 5289 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 5290 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5291 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 5292 | * WaDisableRCCUnitClockGating:snb |
| 5293 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5294 | */ |
| 5295 | I915_WRITE(GEN6_UCGCTL2, |
| 5296 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 5297 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 5298 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 5299 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 5300 | I915_WRITE(_3D_CHICKEN3, |
| 5301 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5302 | |
| 5303 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 5304 | * Bspec says: |
| 5305 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 5306 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 5307 | */ |
| 5308 | I915_WRITE(_3D_CHICKEN3, |
| 5309 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 5310 | |
| 5311 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5312 | * According to the spec the following bits should be |
| 5313 | * set in order to enable memory self-refresh and fbc: |
| 5314 | * The bit21 and bit22 of 0x42000 |
| 5315 | * The bit21 and bit22 of 0x42004 |
| 5316 | * The bit5 and bit7 of 0x42020 |
| 5317 | * The bit14 of 0x70180 |
| 5318 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5319 | * |
| 5320 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5321 | */ |
| 5322 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5323 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5324 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 5325 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5326 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5327 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5328 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 5329 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 5330 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 5331 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5332 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5333 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 5334 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5335 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5336 | |
| 5337 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 5341 | { |
| 5342 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 5343 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5344 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5345 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5346 | * |
| 5347 | * This actually overrides the dispatch |
| 5348 | * mode for all thread types. |
| 5349 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5350 | reg &= ~GEN7_FF_SCHED_MASK; |
| 5351 | reg |= GEN7_FF_TS_SCHED_HW; |
| 5352 | reg |= GEN7_FF_VS_SCHED_HW; |
| 5353 | reg |= GEN7_FF_DS_SCHED_HW; |
| 5354 | |
| 5355 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 5356 | } |
| 5357 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5358 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 5359 | { |
| 5360 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5361 | |
| 5362 | /* |
| 5363 | * TODO: this bit should only be enabled when really needed, then |
| 5364 | * disabled when not needed anymore in order to save power. |
| 5365 | */ |
| 5366 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 5367 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 5368 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 5369 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 5370 | |
| 5371 | /* WADPOClockGatingDisable:hsw */ |
| 5372 | I915_WRITE(_TRANSA_CHICKEN1, |
| 5373 | I915_READ(_TRANSA_CHICKEN1) | |
| 5374 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5375 | } |
| 5376 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5377 | static void lpt_suspend_hw(struct drm_device *dev) |
| 5378 | { |
| 5379 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5380 | |
| 5381 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 5382 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 5383 | |
| 5384 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 5385 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 5386 | } |
| 5387 | } |
| 5388 | |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5389 | static void gen8_init_clock_gating(struct drm_device *dev) |
| 5390 | { |
| 5391 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5392 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5393 | |
| 5394 | I915_WRITE(WM3_LP_ILK, 0); |
| 5395 | I915_WRITE(WM2_LP_ILK, 0); |
| 5396 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5397 | |
| 5398 | /* FIXME(BDW): Check all the w/a, some might only apply to |
| 5399 | * pre-production hw. */ |
| 5400 | |
Kenneth Graunke | c8966e1 | 2014-02-26 23:59:30 -0800 | [diff] [blame] | 5401 | /* WaDisablePartialInstShootdown:bdw */ |
| 5402 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5403 | _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE)); |
| 5404 | |
Kenneth Graunke | 1411e6a | 2014-02-26 23:59:31 -0800 | [diff] [blame] | 5405 | /* WaDisableThreadStallDopClockGating:bdw */ |
| 5406 | /* FIXME: Unclear whether we really need this on production bdw. */ |
| 5407 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5408 | _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE)); |
| 5409 | |
Damien Lespiau | 4167e32 | 2014-01-16 16:51:35 +0000 | [diff] [blame] | 5410 | /* |
| 5411 | * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for |
| 5412 | * pre-production hardware |
| 5413 | */ |
Ben Widawsky | fd392b6 | 2013-11-04 22:52:39 -0800 | [diff] [blame] | 5414 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5415 | _MASKED_BIT_ENABLE(GEN8_CENTROID_PIXEL_OPT_DIS)); |
Ben Widawsky | bf66347 | 2013-11-02 21:07:57 -0700 | [diff] [blame] | 5416 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5417 | _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS)); |
Ben Widawsky | 4afe8d3 | 2013-11-02 21:07:55 -0700 | [diff] [blame] | 5418 | I915_WRITE(GAMTARBMODE, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE)); |
| 5419 | |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5420 | I915_WRITE(_3D_CHICKEN3, |
Michel Thierry | b3f9ad9 | 2014-07-07 12:40:17 +0100 | [diff] [blame] | 5421 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2))); |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5422 | |
Ben Widawsky | a75f362 | 2013-11-02 21:07:59 -0700 | [diff] [blame] | 5423 | I915_WRITE(COMMON_SLICE_CHICKEN2, |
| 5424 | _MASKED_BIT_ENABLE(GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE)); |
| 5425 | |
Ben Widawsky | 4c2e7a5 | 2013-11-02 21:08:00 -0700 | [diff] [blame] | 5426 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5427 | _MASKED_BIT_ENABLE(GEN7_SINGLE_SUBSCAN_DISPATCH_ENABLE)); |
| 5428 | |
Ben Widawsky | 242a401 | 2014-04-18 18:04:29 -0300 | [diff] [blame] | 5429 | /* WaDisableDopClockGating:bdw May not be needed for production */ |
| 5430 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5431 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5432 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5433 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5434 | 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] | 5435 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5436 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5437 | I915_WRITE(CHICKEN_PAR1_1, |
| 5438 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 5439 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5440 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5441 | for_each_pipe(pipe) { |
| 5442 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 5443 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 5444 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5445 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 5446 | |
| 5447 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
| 5448 | * workaround for for a possible hang in the unlikely event a TLB |
| 5449 | * invalidation occurs during a PSD flush. |
| 5450 | */ |
| 5451 | I915_WRITE(HDC_CHICKEN0, |
| 5452 | I915_READ(HDC_CHICKEN0) | |
| 5453 | _MASKED_BIT_ENABLE(HDC_FORCE_NON_COHERENT)); |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5454 | |
| 5455 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 5456 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 5457 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5458 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5459 | ~(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] | 5460 | |
| 5461 | /* |
| 5462 | * BSpec recommends 8x4 when MSAA is used, |
| 5463 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5464 | * |
| 5465 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5466 | * disable bit, which we don't touch here, but it's good |
| 5467 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 36075a4 | 2014-02-04 21:59:21 +0200 | [diff] [blame] | 5468 | */ |
| 5469 | I915_WRITE(GEN7_GT_MODE, |
| 5470 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 5471 | |
| 5472 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5473 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 5474 | |
| 5475 | /* WaDisableSDEUnitClockGating:bdw */ |
| 5476 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5477 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 5478 | |
| 5479 | /* Wa4x4STCOptimizationDisable:bdw */ |
| 5480 | I915_WRITE(CACHE_MODE_1, |
| 5481 | _MASKED_BIT_ENABLE(GEN8_4x4_STC_OPTIMIZATION_DISABLE)); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5484 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 5485 | { |
| 5486 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5487 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5488 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5489 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 5490 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 5491 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 5492 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 5493 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 5494 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5495 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5496 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5497 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5498 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5499 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 5500 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 5501 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5502 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5503 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5504 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 5505 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5506 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 5507 | /* enable HiZ Raw Stall Optimization */ |
| 5508 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5509 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5510 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5511 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5512 | I915_WRITE(CACHE_MODE_1, |
| 5513 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5514 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5515 | /* |
| 5516 | * BSpec recommends 8x4 when MSAA is used, |
| 5517 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5518 | * |
| 5519 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5520 | * disable bit, which we don't touch here, but it's good |
| 5521 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5522 | */ |
| 5523 | I915_WRITE(GEN7_GT_MODE, |
| 5524 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5525 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5526 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 5527 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 5528 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 5529 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 5530 | I915_WRITE(CHICKEN_PAR1_1, |
| 5531 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5532 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5533 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5534 | } |
| 5535 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5536 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5537 | { |
| 5538 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5539 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5540 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5541 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5542 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5543 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5544 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5545 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5546 | I915_WRITE(_3D_CHICKEN3, |
| 5547 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5548 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5549 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5550 | I915_WRITE(IVB_CHICKEN3, |
| 5551 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5552 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5553 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5554 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5555 | if (IS_IVB_GT1(dev)) |
| 5556 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5557 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5558 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5559 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 5560 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5561 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5562 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5563 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 5564 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 5565 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5566 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5567 | I915_WRITE(GEN7_L3CNTLREG1, |
| 5568 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 5569 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5570 | GEN7_WA_L3_CHICKEN_MODE); |
| 5571 | if (IS_IVB_GT1(dev)) |
| 5572 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5573 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5574 | else { |
| 5575 | /* must write both registers */ |
| 5576 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5577 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5578 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 5579 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5580 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5581 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5582 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5583 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5584 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5585 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 5586 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5587 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5588 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5589 | */ |
| 5590 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 5591 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5592 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5593 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5594 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5595 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5596 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5597 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5598 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5599 | |
| 5600 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5601 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 5602 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 5603 | /* enable HiZ Raw Stall Optimization */ |
| 5604 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5605 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5606 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 5607 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5608 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5609 | I915_WRITE(CACHE_MODE_1, |
| 5610 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5611 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5612 | /* |
| 5613 | * BSpec recommends 8x4 when MSAA is used, |
| 5614 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5615 | * |
| 5616 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5617 | * disable bit, which we don't touch here, but it's good |
| 5618 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5619 | */ |
| 5620 | I915_WRITE(GEN7_GT_MODE, |
| 5621 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5622 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5623 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 5624 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 5625 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 5626 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5627 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 5628 | if (!HAS_PCH_NOP(dev)) |
| 5629 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5630 | |
| 5631 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5632 | } |
| 5633 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5634 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5635 | { |
| 5636 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5637 | u32 val; |
| 5638 | |
| 5639 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5640 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5641 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5642 | switch ((val >> 6) & 3) { |
| 5643 | case 0: |
Deepak S | f6d5194 | 2014-04-03 21:01:28 +0530 | [diff] [blame] | 5644 | case 1: |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5645 | dev_priv->mem_freq = 800; |
| 5646 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5647 | case 2: |
Deepak S | f6d5194 | 2014-04-03 21:01:28 +0530 | [diff] [blame] | 5648 | dev_priv->mem_freq = 1066; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5649 | break; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5650 | case 3: |
Chon Ming Lee | 2325991 | 2013-11-07 15:23:26 +0800 | [diff] [blame] | 5651 | dev_priv->mem_freq = 1333; |
Jesse Barnes | f64a28a | 2013-11-04 16:07:00 -0800 | [diff] [blame] | 5652 | break; |
Jesse Barnes | 85b1d7b | 2013-11-04 11:52:45 -0800 | [diff] [blame] | 5653 | } |
| 5654 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5655 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 5656 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5657 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5658 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5659 | I915_WRITE(_3D_CHICKEN3, |
| 5660 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5661 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5662 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5663 | I915_WRITE(IVB_CHICKEN3, |
| 5664 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5665 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5666 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 5667 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5668 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5669 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 5670 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 5671 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5672 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5673 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 5674 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5675 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5676 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5677 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5678 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5679 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5680 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5681 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5682 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5683 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5684 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5685 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5686 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5687 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5688 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5689 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 5690 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5691 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5692 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5693 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5694 | */ |
| 5695 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5696 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5697 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 5698 | /* WaDisableL3Bank2xClockGate:vlv |
| 5699 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 5700 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 5701 | I915_WRITE(GEN7_UCGCTL4, |
| 5702 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 5703 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 5704 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5705 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 5706 | /* |
| 5707 | * BSpec says this must be set, even though |
| 5708 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 5709 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 5710 | I915_WRITE(CACHE_MODE_1, |
| 5711 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 5712 | |
| 5713 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 5714 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 5715 | * This is the hardware default actually. |
| 5716 | */ |
| 5717 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 5718 | |
| 5719 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5720 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 5721 | * Disable clock gating on th GCFG unit to prevent a delay |
| 5722 | * in the reporting of vblank events. |
| 5723 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 5724 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5725 | } |
| 5726 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 5727 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 5728 | { |
| 5729 | struct drm_i915_private *dev_priv = dev->dev_private; |
Deepak S | 67c3bf6 | 2014-07-10 13:16:24 +0530 | [diff] [blame] | 5730 | u32 val; |
| 5731 | |
| 5732 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5733 | val = vlv_punit_read(dev_priv, CCK_FUSE_REG); |
| 5734 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5735 | switch ((val >> 2) & 0x7) { |
| 5736 | case 0: |
| 5737 | case 1: |
| 5738 | dev_priv->rps.cz_freq = CHV_CZ_CLOCK_FREQ_MODE_200; |
| 5739 | dev_priv->mem_freq = 1600; |
| 5740 | break; |
| 5741 | case 2: |
| 5742 | dev_priv->rps.cz_freq = CHV_CZ_CLOCK_FREQ_MODE_267; |
| 5743 | dev_priv->mem_freq = 1600; |
| 5744 | break; |
| 5745 | case 3: |
| 5746 | dev_priv->rps.cz_freq = CHV_CZ_CLOCK_FREQ_MODE_333; |
| 5747 | dev_priv->mem_freq = 2000; |
| 5748 | break; |
| 5749 | case 4: |
| 5750 | dev_priv->rps.cz_freq = CHV_CZ_CLOCK_FREQ_MODE_320; |
| 5751 | dev_priv->mem_freq = 1600; |
| 5752 | break; |
| 5753 | case 5: |
| 5754 | dev_priv->rps.cz_freq = CHV_CZ_CLOCK_FREQ_MODE_400; |
| 5755 | dev_priv->mem_freq = 1600; |
| 5756 | break; |
| 5757 | } |
| 5758 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 5759 | |
| 5760 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 5761 | |
| 5762 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 5763 | |
| 5764 | /* WaDisablePartialInstShootdown:chv */ |
| 5765 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5766 | _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE)); |
Ville Syrjälä | a706802 | 2014-04-09 13:28:34 +0300 | [diff] [blame] | 5767 | |
| 5768 | /* WaDisableThreadStallDopClockGating:chv */ |
| 5769 | I915_WRITE(GEN8_ROW_CHICKEN, |
| 5770 | _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE)); |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 5771 | |
| 5772 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 5773 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 5774 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5775 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5776 | ~(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] | 5777 | |
| 5778 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 5779 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5780 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 5781 | |
| 5782 | /* WaDisableCSUnitClockGating:chv */ |
| 5783 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 5784 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 5785 | |
| 5786 | /* WaDisableSDEUnitClockGating:chv */ |
| 5787 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5788 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Rafael Barbalho | e0d34ce | 2014-04-09 13:28:40 +0300 | [diff] [blame] | 5789 | |
| 5790 | /* WaDisableSamplerPowerBypass:chv (pre-production hw) */ |
| 5791 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 5792 | _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS)); |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 5793 | |
| 5794 | /* WaDisableGunitClockGating:chv (pre-production hw) */ |
| 5795 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, I915_READ(VLV_GUNIT_CLOCK_GATE) | |
| 5796 | GINT_DIS); |
| 5797 | |
| 5798 | /* WaDisableFfDopClockGating:chv (pre-production hw) */ |
| 5799 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5800 | _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE)); |
| 5801 | |
| 5802 | /* WaDisableDopClockGating:chv (pre-production hw) */ |
| 5803 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5804 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5805 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 5806 | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 5807 | } |
| 5808 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5809 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5810 | { |
| 5811 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5812 | uint32_t dspclk_gate; |
| 5813 | |
| 5814 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 5815 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 5816 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 5817 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 5818 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5819 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 5820 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 5821 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 5822 | if (IS_GM45(dev)) |
| 5823 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 5824 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5825 | |
| 5826 | /* WaDisableRenderCachePipelinedFlush */ |
| 5827 | I915_WRITE(CACHE_MODE_0, |
| 5828 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 5829 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5830 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 5831 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5832 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5833 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5834 | } |
| 5835 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5836 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5837 | { |
| 5838 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5839 | |
| 5840 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 5841 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 5842 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 5843 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 5844 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5845 | I915_WRITE(MI_ARB_STATE, |
| 5846 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5847 | |
| 5848 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 5849 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5850 | } |
| 5851 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5852 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5853 | { |
| 5854 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5855 | |
| 5856 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 5857 | I965_RCC_CLOCK_GATE_DISABLE | |
| 5858 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 5859 | I965_ISC_CLOCK_GATE_DISABLE | |
| 5860 | I965_FBC_CLOCK_GATE_DISABLE); |
| 5861 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 5862 | I915_WRITE(MI_ARB_STATE, |
| 5863 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5864 | |
| 5865 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 5866 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5867 | } |
| 5868 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5869 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5870 | { |
| 5871 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5872 | u32 dstate = I915_READ(D_STATE); |
| 5873 | |
| 5874 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 5875 | DSTATE_DOT_CLOCK_GATING; |
| 5876 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 5877 | |
| 5878 | if (IS_PINEVIEW(dev)) |
| 5879 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 5880 | |
| 5881 | /* IIR "flip pending" means done if this bit is set */ |
| 5882 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 5883 | |
| 5884 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 5885 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 5886 | |
| 5887 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 5888 | I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5889 | } |
| 5890 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5891 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5892 | { |
| 5893 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5894 | |
| 5895 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 5896 | |
| 5897 | /* interrupts should cause a wake up from C3 */ |
| 5898 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 5899 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5900 | } |
| 5901 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5902 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5903 | { |
| 5904 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5905 | |
| 5906 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
| 5907 | } |
| 5908 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5909 | void intel_init_clock_gating(struct drm_device *dev) |
| 5910 | { |
| 5911 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5912 | |
| 5913 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5914 | } |
| 5915 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5916 | void intel_suspend_hw(struct drm_device *dev) |
| 5917 | { |
| 5918 | if (HAS_PCH_LPT(dev)) |
| 5919 | lpt_suspend_hw(dev); |
| 5920 | } |
| 5921 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5922 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 5923 | for (i = 0; \ |
| 5924 | i < (power_domains)->power_well_count && \ |
| 5925 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 5926 | i++) \ |
| 5927 | if ((power_well)->domains & (domain_mask)) |
| 5928 | |
| 5929 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 5930 | for (i = (power_domains)->power_well_count - 1; \ |
| 5931 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 5932 | i--) \ |
| 5933 | if ((power_well)->domains & (domain_mask)) |
| 5934 | |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5935 | /** |
| 5936 | * We should only use the power well if we explicitly asked the hardware to |
| 5937 | * enable it, so check if it's enabled and also check if we've requested it to |
| 5938 | * be enabled. |
| 5939 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5940 | static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5941 | struct i915_power_well *power_well) |
| 5942 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5943 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 5944 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 5945 | } |
| 5946 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5947 | bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv, |
| 5948 | enum intel_display_power_domain domain) |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5949 | { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5950 | struct i915_power_domains *power_domains; |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5951 | struct i915_power_well *power_well; |
| 5952 | bool is_enabled; |
| 5953 | int i; |
| 5954 | |
| 5955 | if (dev_priv->pm.suspended) |
| 5956 | return false; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5957 | |
| 5958 | power_domains = &dev_priv->power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5959 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5960 | is_enabled = true; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5961 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5962 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 5963 | if (power_well->always_on) |
| 5964 | continue; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5965 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5966 | if (!power_well->hw_enabled) { |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5967 | is_enabled = false; |
| 5968 | break; |
| 5969 | } |
| 5970 | } |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5971 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 5972 | return is_enabled; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 5973 | } |
| 5974 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 5975 | bool intel_display_power_enabled(struct drm_i915_private *dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 5976 | enum intel_display_power_domain domain) |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5977 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5978 | struct i915_power_domains *power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5979 | bool ret; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 5980 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5981 | power_domains = &dev_priv->power_domains; |
| 5982 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5983 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5984 | ret = intel_display_power_enabled_unlocked(dev_priv, domain); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 5985 | mutex_unlock(&power_domains->lock); |
| 5986 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 5987 | return ret; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 5988 | } |
| 5989 | |
Imre Deak | 93c73e8 | 2014-02-18 00:02:19 +0200 | [diff] [blame] | 5990 | /* |
| 5991 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 5992 | * when not needed anymore. We have 4 registers that can request the power well |
| 5993 | * to be enabled, and it will only be disabled if none of the registers is |
| 5994 | * requesting it to be enabled. |
| 5995 | */ |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5996 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 5997 | { |
| 5998 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 5999 | |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 6000 | /* |
| 6001 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 6002 | * we'll get unclaimed register interrupts. This stops after we write |
| 6003 | * anything to the VGA MSR register. The vgacon module uses this |
| 6004 | * register all the time, so if we unbind our driver and, as a |
| 6005 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 6006 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 6007 | * sure vgacon can keep working normally without triggering interrupts |
| 6008 | * and error messages. |
| 6009 | */ |
| 6010 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6011 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
| 6012 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6013 | |
Paulo Zanoni | d49bdb0 | 2014-07-04 11:50:31 -0300 | [diff] [blame] | 6014 | if (IS_BROADWELL(dev)) |
| 6015 | gen8_irq_power_well_post_enable(dev_priv); |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6016 | } |
| 6017 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6018 | static void hsw_set_power_well(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6019 | struct i915_power_well *power_well, bool enable) |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6020 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6021 | bool is_enabled, enable_requested; |
| 6022 | uint32_t tmp; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6023 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6024 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6025 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 6026 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6027 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6028 | if (enable) { |
| 6029 | if (!enable_requested) |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6030 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 6031 | HSW_PWR_WELL_ENABLE_REQUEST); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6032 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6033 | if (!is_enabled) { |
| 6034 | DRM_DEBUG_KMS("Enabling power well\n"); |
| 6035 | if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) & |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6036 | HSW_PWR_WELL_STATE_ENABLED), 20)) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6037 | DRM_ERROR("Timeout enabling power well\n"); |
| 6038 | } |
Ben Widawsky | 596cc11 | 2013-11-11 14:46:28 -0800 | [diff] [blame] | 6039 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6040 | hsw_power_well_post_enable(dev_priv); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6041 | } else { |
| 6042 | if (enable_requested) { |
| 6043 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 6044 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6045 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6046 | } |
| 6047 | } |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6048 | } |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6049 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6050 | static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6051 | struct i915_power_well *power_well) |
| 6052 | { |
| 6053 | hsw_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6054 | |
| 6055 | /* |
| 6056 | * We're taking over the BIOS, so clear any requests made by it since |
| 6057 | * the driver is in charge now. |
| 6058 | */ |
| 6059 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
| 6060 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 6061 | } |
| 6062 | |
| 6063 | static void hsw_power_well_enable(struct drm_i915_private *dev_priv, |
| 6064 | struct i915_power_well *power_well) |
| 6065 | { |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6066 | hsw_set_power_well(dev_priv, power_well, true); |
| 6067 | } |
| 6068 | |
| 6069 | static void hsw_power_well_disable(struct drm_i915_private *dev_priv, |
| 6070 | struct i915_power_well *power_well) |
| 6071 | { |
| 6072 | hsw_set_power_well(dev_priv, power_well, false); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6073 | } |
| 6074 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6075 | static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv, |
| 6076 | struct i915_power_well *power_well) |
| 6077 | { |
| 6078 | } |
| 6079 | |
| 6080 | static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6081 | struct i915_power_well *power_well) |
| 6082 | { |
| 6083 | return true; |
| 6084 | } |
| 6085 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6086 | static void vlv_set_power_well(struct drm_i915_private *dev_priv, |
| 6087 | struct i915_power_well *power_well, bool enable) |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6088 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6089 | enum punit_power_well power_well_id = power_well->data; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6090 | u32 mask; |
| 6091 | u32 state; |
| 6092 | u32 ctrl; |
| 6093 | |
| 6094 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6095 | state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) : |
| 6096 | PUNIT_PWRGT_PWR_GATE(power_well_id); |
| 6097 | |
| 6098 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6099 | |
| 6100 | #define COND \ |
| 6101 | ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state) |
| 6102 | |
| 6103 | if (COND) |
| 6104 | goto out; |
| 6105 | |
| 6106 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL); |
| 6107 | ctrl &= ~mask; |
| 6108 | ctrl |= state; |
| 6109 | vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl); |
| 6110 | |
| 6111 | if (wait_for(COND, 100)) |
| 6112 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 6113 | state, |
| 6114 | vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL)); |
| 6115 | |
| 6116 | #undef COND |
| 6117 | |
| 6118 | out: |
| 6119 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6120 | } |
| 6121 | |
| 6122 | static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6123 | struct i915_power_well *power_well) |
| 6124 | { |
| 6125 | vlv_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6126 | } |
| 6127 | |
| 6128 | static void vlv_power_well_enable(struct drm_i915_private *dev_priv, |
| 6129 | struct i915_power_well *power_well) |
| 6130 | { |
| 6131 | vlv_set_power_well(dev_priv, power_well, true); |
| 6132 | } |
| 6133 | |
| 6134 | static void vlv_power_well_disable(struct drm_i915_private *dev_priv, |
| 6135 | struct i915_power_well *power_well) |
| 6136 | { |
| 6137 | vlv_set_power_well(dev_priv, power_well, false); |
| 6138 | } |
| 6139 | |
| 6140 | static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6141 | struct i915_power_well *power_well) |
| 6142 | { |
| 6143 | int power_well_id = power_well->data; |
| 6144 | bool enabled = false; |
| 6145 | u32 mask; |
| 6146 | u32 state; |
| 6147 | u32 ctrl; |
| 6148 | |
| 6149 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6150 | ctrl = PUNIT_PWRGT_PWR_ON(power_well_id); |
| 6151 | |
| 6152 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6153 | |
| 6154 | state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask; |
| 6155 | /* |
| 6156 | * We only ever set the power-on and power-gate states, anything |
| 6157 | * else is unexpected. |
| 6158 | */ |
| 6159 | WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) && |
| 6160 | state != PUNIT_PWRGT_PWR_GATE(power_well_id)); |
| 6161 | if (state == ctrl) |
| 6162 | enabled = true; |
| 6163 | |
| 6164 | /* |
| 6165 | * A transient state at this point would mean some unexpected party |
| 6166 | * is poking at the power controls too. |
| 6167 | */ |
| 6168 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask; |
| 6169 | WARN_ON(ctrl != state); |
| 6170 | |
| 6171 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6172 | |
| 6173 | return enabled; |
| 6174 | } |
| 6175 | |
| 6176 | static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, |
| 6177 | struct i915_power_well *power_well) |
| 6178 | { |
| 6179 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6180 | |
| 6181 | vlv_set_power_well(dev_priv, power_well, true); |
| 6182 | |
| 6183 | spin_lock_irq(&dev_priv->irq_lock); |
| 6184 | valleyview_enable_display_irqs(dev_priv); |
| 6185 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6186 | |
| 6187 | /* |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6188 | * During driver initialization/resume we can avoid restoring the |
| 6189 | * part of the HW/SW state that will be inited anyway explicitly. |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6190 | */ |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6191 | if (dev_priv->power_domains.initializing) |
| 6192 | return; |
| 6193 | |
| 6194 | intel_hpd_init(dev_priv->dev); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6195 | |
| 6196 | i915_redisable_vga_power_on(dev_priv->dev); |
| 6197 | } |
| 6198 | |
| 6199 | static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv, |
| 6200 | struct i915_power_well *power_well) |
| 6201 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6202 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6203 | |
| 6204 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6205 | valleyview_disable_display_irqs(dev_priv); |
| 6206 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6207 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6208 | vlv_set_power_well(dev_priv, power_well, false); |
| 6209 | } |
| 6210 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6211 | static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 6212 | struct i915_power_well *power_well) |
| 6213 | { |
| 6214 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6215 | |
| 6216 | /* |
| 6217 | * Enable the CRI clock source so we can get at the |
| 6218 | * display and the reference clock for VGA |
| 6219 | * hotplug / manual detection. |
| 6220 | */ |
| 6221 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6222 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6223 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 6224 | |
| 6225 | vlv_set_power_well(dev_priv, power_well, true); |
| 6226 | |
| 6227 | /* |
| 6228 | * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx - |
| 6229 | * 6. De-assert cmn_reset/side_reset. Same as VLV X0. |
| 6230 | * a. GUnit 0x2110 bit[0] set to 1 (def 0) |
| 6231 | * b. The other bits such as sfr settings / modesel may all |
| 6232 | * be set to 0. |
| 6233 | * |
| 6234 | * This should only be done on init and resume from S3 with |
| 6235 | * both PLLs disabled, or we risk losing DPIO and PLL |
| 6236 | * synchronization. |
| 6237 | */ |
| 6238 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST); |
| 6239 | } |
| 6240 | |
| 6241 | static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 6242 | struct i915_power_well *power_well) |
| 6243 | { |
| 6244 | struct drm_device *dev = dev_priv->dev; |
| 6245 | enum pipe pipe; |
| 6246 | |
| 6247 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6248 | |
| 6249 | for_each_pipe(pipe) |
| 6250 | assert_pll_disabled(dev_priv, pipe); |
| 6251 | |
| 6252 | /* Assert common reset */ |
| 6253 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST); |
| 6254 | |
| 6255 | vlv_set_power_well(dev_priv, power_well, false); |
| 6256 | } |
| 6257 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6258 | static void check_power_well_state(struct drm_i915_private *dev_priv, |
| 6259 | struct i915_power_well *power_well) |
| 6260 | { |
| 6261 | bool enabled = power_well->ops->is_enabled(dev_priv, power_well); |
| 6262 | |
| 6263 | if (power_well->always_on || !i915.disable_power_well) { |
| 6264 | if (!enabled) |
| 6265 | goto mismatch; |
| 6266 | |
| 6267 | return; |
| 6268 | } |
| 6269 | |
| 6270 | if (enabled != (power_well->count > 0)) |
| 6271 | goto mismatch; |
| 6272 | |
| 6273 | return; |
| 6274 | |
| 6275 | mismatch: |
| 6276 | WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n", |
| 6277 | power_well->name, power_well->always_on, enabled, |
| 6278 | power_well->count, i915.disable_power_well); |
| 6279 | } |
| 6280 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6281 | void intel_display_power_get(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6282 | enum intel_display_power_domain domain) |
| 6283 | { |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6284 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6285 | struct i915_power_well *power_well; |
| 6286 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6287 | |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6288 | intel_runtime_pm_get(dev_priv); |
| 6289 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6290 | power_domains = &dev_priv->power_domains; |
| 6291 | |
| 6292 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6293 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6294 | for_each_power_well(i, power_well, BIT(domain), power_domains) { |
| 6295 | if (!power_well->count++) { |
| 6296 | DRM_DEBUG_KMS("enabling %s\n", power_well->name); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6297 | power_well->ops->enable(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6298 | power_well->hw_enabled = true; |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | check_power_well_state(dev_priv, power_well); |
| 6302 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6303 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6304 | power_domains->domain_use_count[domain]++; |
| 6305 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6306 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6307 | } |
| 6308 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6309 | void intel_display_power_put(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6310 | enum intel_display_power_domain domain) |
| 6311 | { |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6312 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6313 | struct i915_power_well *power_well; |
| 6314 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6315 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6316 | power_domains = &dev_priv->power_domains; |
| 6317 | |
| 6318 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6319 | |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6320 | WARN_ON(!power_domains->domain_use_count[domain]); |
| 6321 | power_domains->domain_use_count[domain]--; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6322 | |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6323 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 6324 | WARN_ON(!power_well->count); |
| 6325 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6326 | if (!--power_well->count && i915.disable_power_well) { |
| 6327 | DRM_DEBUG_KMS("disabling %s\n", power_well->name); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6328 | power_well->hw_enabled = false; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6329 | power_well->ops->disable(dev_priv, power_well); |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | check_power_well_state(dev_priv, power_well); |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6333 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6334 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6335 | mutex_unlock(&power_domains->lock); |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6336 | |
| 6337 | intel_runtime_pm_put(dev_priv); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6338 | } |
| 6339 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6340 | static struct i915_power_domains *hsw_pwr; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6341 | |
| 6342 | /* Display audio driver power well request */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6343 | int i915_request_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6344 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6345 | struct drm_i915_private *dev_priv; |
| 6346 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6347 | if (!hsw_pwr) |
| 6348 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6349 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6350 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6351 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6352 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6353 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6354 | } |
| 6355 | EXPORT_SYMBOL_GPL(i915_request_power_well); |
| 6356 | |
| 6357 | /* Display audio driver power well release */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6358 | int i915_release_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6359 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6360 | struct drm_i915_private *dev_priv; |
| 6361 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6362 | if (!hsw_pwr) |
| 6363 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6364 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6365 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6366 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6367 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6368 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6369 | } |
| 6370 | EXPORT_SYMBOL_GPL(i915_release_power_well); |
| 6371 | |
Jani Nikula | c149dcb | 2014-07-04 10:00:37 +0800 | [diff] [blame] | 6372 | /* |
| 6373 | * Private interface for the audio driver to get CDCLK in kHz. |
| 6374 | * |
| 6375 | * Caller must request power well using i915_request_power_well() prior to |
| 6376 | * making the call. |
| 6377 | */ |
| 6378 | int i915_get_cdclk_freq(void) |
| 6379 | { |
| 6380 | struct drm_i915_private *dev_priv; |
| 6381 | |
| 6382 | if (!hsw_pwr) |
| 6383 | return -ENODEV; |
| 6384 | |
| 6385 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6386 | power_domains); |
| 6387 | |
| 6388 | return intel_ddi_get_cdclk_freq(dev_priv); |
| 6389 | } |
| 6390 | EXPORT_SYMBOL_GPL(i915_get_cdclk_freq); |
| 6391 | |
| 6392 | |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6393 | #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1) |
| 6394 | |
| 6395 | #define HSW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6396 | BIT(POWER_DOMAIN_PIPE_A) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6397 | BIT(POWER_DOMAIN_TRANSCODER_EDP) | \ |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6398 | BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \ |
| 6399 | BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \ |
| 6400 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6401 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6402 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6403 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6404 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6405 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6406 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 6407 | BIT(POWER_DOMAIN_PLLS) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6408 | BIT(POWER_DOMAIN_INIT)) |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6409 | #define HSW_DISPLAY_POWER_DOMAINS ( \ |
| 6410 | (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6411 | BIT(POWER_DOMAIN_INIT)) |
| 6412 | |
| 6413 | #define BDW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6414 | HSW_ALWAYS_ON_POWER_DOMAINS | \ |
| 6415 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER)) |
| 6416 | #define BDW_DISPLAY_POWER_DOMAINS ( \ |
| 6417 | (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6418 | BIT(POWER_DOMAIN_INIT)) |
| 6419 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6420 | #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT) |
| 6421 | #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK |
| 6422 | |
| 6423 | #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 6424 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6425 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6426 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6427 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6428 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
| 6429 | BIT(POWER_DOMAIN_INIT)) |
| 6430 | |
| 6431 | #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \ |
| 6432 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6433 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6434 | BIT(POWER_DOMAIN_INIT)) |
| 6435 | |
| 6436 | #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \ |
| 6437 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6438 | BIT(POWER_DOMAIN_INIT)) |
| 6439 | |
| 6440 | #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \ |
| 6441 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6442 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6443 | BIT(POWER_DOMAIN_INIT)) |
| 6444 | |
| 6445 | #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \ |
| 6446 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6447 | BIT(POWER_DOMAIN_INIT)) |
| 6448 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6449 | static const struct i915_power_well_ops i9xx_always_on_power_well_ops = { |
| 6450 | .sync_hw = i9xx_always_on_power_well_noop, |
| 6451 | .enable = i9xx_always_on_power_well_noop, |
| 6452 | .disable = i9xx_always_on_power_well_noop, |
| 6453 | .is_enabled = i9xx_always_on_power_well_enabled, |
| 6454 | }; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6455 | |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6456 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 6457 | { |
| 6458 | .name = "always-on", |
| 6459 | .always_on = 1, |
| 6460 | .domains = POWER_DOMAIN_MASK, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6461 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6462 | }, |
| 6463 | }; |
| 6464 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6465 | static const struct i915_power_well_ops hsw_power_well_ops = { |
| 6466 | .sync_hw = hsw_power_well_sync_hw, |
| 6467 | .enable = hsw_power_well_enable, |
| 6468 | .disable = hsw_power_well_disable, |
| 6469 | .is_enabled = hsw_power_well_enabled, |
| 6470 | }; |
| 6471 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6472 | static struct i915_power_well hsw_power_wells[] = { |
| 6473 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6474 | .name = "always-on", |
| 6475 | .always_on = 1, |
| 6476 | .domains = HSW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6477 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6478 | }, |
| 6479 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6480 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6481 | .domains = HSW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6482 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6483 | }, |
| 6484 | }; |
| 6485 | |
| 6486 | static struct i915_power_well bdw_power_wells[] = { |
| 6487 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6488 | .name = "always-on", |
| 6489 | .always_on = 1, |
| 6490 | .domains = BDW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6491 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6492 | }, |
| 6493 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6494 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6495 | .domains = BDW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6496 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6497 | }, |
| 6498 | }; |
| 6499 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6500 | static const struct i915_power_well_ops vlv_display_power_well_ops = { |
| 6501 | .sync_hw = vlv_power_well_sync_hw, |
| 6502 | .enable = vlv_display_power_well_enable, |
| 6503 | .disable = vlv_display_power_well_disable, |
| 6504 | .is_enabled = vlv_power_well_enabled, |
| 6505 | }; |
| 6506 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6507 | static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = { |
| 6508 | .sync_hw = vlv_power_well_sync_hw, |
| 6509 | .enable = vlv_dpio_cmn_power_well_enable, |
| 6510 | .disable = vlv_dpio_cmn_power_well_disable, |
| 6511 | .is_enabled = vlv_power_well_enabled, |
| 6512 | }; |
| 6513 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6514 | static const struct i915_power_well_ops vlv_dpio_power_well_ops = { |
| 6515 | .sync_hw = vlv_power_well_sync_hw, |
| 6516 | .enable = vlv_power_well_enable, |
| 6517 | .disable = vlv_power_well_disable, |
| 6518 | .is_enabled = vlv_power_well_enabled, |
| 6519 | }; |
| 6520 | |
| 6521 | static struct i915_power_well vlv_power_wells[] = { |
| 6522 | { |
| 6523 | .name = "always-on", |
| 6524 | .always_on = 1, |
| 6525 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 6526 | .ops = &i9xx_always_on_power_well_ops, |
| 6527 | }, |
| 6528 | { |
| 6529 | .name = "display", |
| 6530 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 6531 | .data = PUNIT_POWER_WELL_DISP2D, |
| 6532 | .ops = &vlv_display_power_well_ops, |
| 6533 | }, |
| 6534 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6535 | .name = "dpio-tx-b-01", |
| 6536 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6537 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6538 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6539 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6540 | .ops = &vlv_dpio_power_well_ops, |
| 6541 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 6542 | }, |
| 6543 | { |
| 6544 | .name = "dpio-tx-b-23", |
| 6545 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6546 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6547 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6548 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6549 | .ops = &vlv_dpio_power_well_ops, |
| 6550 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 6551 | }, |
| 6552 | { |
| 6553 | .name = "dpio-tx-c-01", |
| 6554 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6555 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6556 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6557 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6558 | .ops = &vlv_dpio_power_well_ops, |
| 6559 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 6560 | }, |
| 6561 | { |
| 6562 | .name = "dpio-tx-c-23", |
| 6563 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 6564 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 6565 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 6566 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 6567 | .ops = &vlv_dpio_power_well_ops, |
| 6568 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 6569 | }, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 6570 | { |
| 6571 | .name = "dpio-common", |
| 6572 | .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS, |
| 6573 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6574 | .ops = &vlv_dpio_cmn_power_well_ops, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 6575 | }, |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6576 | }; |
| 6577 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6578 | static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv, |
| 6579 | enum punit_power_well power_well_id) |
| 6580 | { |
| 6581 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6582 | struct i915_power_well *power_well; |
| 6583 | int i; |
| 6584 | |
| 6585 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
| 6586 | if (power_well->data == power_well_id) |
| 6587 | return power_well; |
| 6588 | } |
| 6589 | |
| 6590 | return NULL; |
| 6591 | } |
| 6592 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6593 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 6594 | (power_domains)->power_wells = (__power_wells); \ |
| 6595 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 6596 | }) |
| 6597 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6598 | int intel_power_domains_init(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6599 | { |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6600 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6601 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6602 | mutex_init(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6603 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6604 | /* |
| 6605 | * The enabling order will be from lower to higher indexed wells, |
| 6606 | * the disabling order is reversed. |
| 6607 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6608 | if (IS_HASWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6609 | set_power_wells(power_domains, hsw_power_wells); |
| 6610 | hsw_pwr = power_domains; |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6611 | } else if (IS_BROADWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6612 | set_power_wells(power_domains, bdw_power_wells); |
| 6613 | hsw_pwr = power_domains; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6614 | } else if (IS_VALLEYVIEW(dev_priv->dev)) { |
| 6615 | set_power_wells(power_domains, vlv_power_wells); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6616 | } else { |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6617 | set_power_wells(power_domains, i9xx_always_on_power_well); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6618 | } |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6619 | |
| 6620 | return 0; |
| 6621 | } |
| 6622 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6623 | void intel_power_domains_remove(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6624 | { |
| 6625 | hsw_pwr = NULL; |
| 6626 | } |
| 6627 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6628 | 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] | 6629 | { |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6630 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6631 | struct i915_power_well *power_well; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6632 | int i; |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 6633 | |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6634 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6635 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6636 | power_well->ops->sync_hw(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6637 | power_well->hw_enabled = power_well->ops->is_enabled(dev_priv, |
| 6638 | power_well); |
| 6639 | } |
Imre Deak | 83c00f55 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6640 | mutex_unlock(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6641 | } |
| 6642 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6643 | static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv) |
| 6644 | { |
| 6645 | struct i915_power_well *cmn = |
| 6646 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6647 | struct i915_power_well *disp2d = |
| 6648 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D); |
| 6649 | |
| 6650 | /* nothing to do if common lane is already off */ |
| 6651 | if (!cmn->ops->is_enabled(dev_priv, cmn)) |
| 6652 | return; |
| 6653 | |
| 6654 | /* If the display might be already active skip this */ |
| 6655 | if (disp2d->ops->is_enabled(dev_priv, disp2d) && |
| 6656 | I915_READ(DPIO_CTL) & DPIO_CMNRST) |
| 6657 | return; |
| 6658 | |
| 6659 | DRM_DEBUG_KMS("toggling display PHY side reset\n"); |
| 6660 | |
| 6661 | /* cmnlane needs DPLL registers */ |
| 6662 | disp2d->ops->enable(dev_priv, disp2d); |
| 6663 | |
| 6664 | /* |
| 6665 | * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx: |
| 6666 | * Need to assert and de-assert PHY SB reset by gating the |
| 6667 | * common lane power, then un-gating it. |
| 6668 | * Simply ungating isn't enough to reset the PHY enough to get |
| 6669 | * ports and lanes running. |
| 6670 | */ |
| 6671 | cmn->ops->disable(dev_priv, cmn); |
| 6672 | } |
| 6673 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6674 | void intel_power_domains_init_hw(struct drm_i915_private *dev_priv) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6675 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6676 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6677 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 6678 | |
| 6679 | power_domains->initializing = true; |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6680 | |
| 6681 | if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
| 6682 | mutex_lock(&power_domains->lock); |
| 6683 | vlv_cmnlane_wa(dev_priv); |
| 6684 | mutex_unlock(&power_domains->lock); |
| 6685 | } |
| 6686 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6687 | /* For now, we need the power well to be always enabled. */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6688 | intel_display_set_init_power(dev_priv, true); |
| 6689 | intel_power_domains_resume(dev_priv); |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6690 | power_domains->initializing = false; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6691 | } |
| 6692 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6693 | void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv) |
| 6694 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 6695 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6696 | } |
| 6697 | |
| 6698 | void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv) |
| 6699 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 6700 | intel_runtime_pm_put(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 6701 | } |
| 6702 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6703 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 6704 | { |
| 6705 | struct drm_device *dev = dev_priv->dev; |
| 6706 | struct device *device = &dev->pdev->dev; |
| 6707 | |
| 6708 | if (!HAS_RUNTIME_PM(dev)) |
| 6709 | return; |
| 6710 | |
| 6711 | pm_runtime_get_sync(device); |
| 6712 | WARN(dev_priv->pm.suspended, "Device still suspended.\n"); |
| 6713 | } |
| 6714 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6715 | void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv) |
| 6716 | { |
| 6717 | struct drm_device *dev = dev_priv->dev; |
| 6718 | struct device *device = &dev->pdev->dev; |
| 6719 | |
| 6720 | if (!HAS_RUNTIME_PM(dev)) |
| 6721 | return; |
| 6722 | |
| 6723 | WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n"); |
| 6724 | pm_runtime_get_noresume(device); |
| 6725 | } |
| 6726 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6727 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 6728 | { |
| 6729 | struct drm_device *dev = dev_priv->dev; |
| 6730 | struct device *device = &dev->pdev->dev; |
| 6731 | |
| 6732 | if (!HAS_RUNTIME_PM(dev)) |
| 6733 | return; |
| 6734 | |
| 6735 | pm_runtime_mark_last_busy(device); |
| 6736 | pm_runtime_put_autosuspend(device); |
| 6737 | } |
| 6738 | |
| 6739 | void intel_init_runtime_pm(struct drm_i915_private *dev_priv) |
| 6740 | { |
| 6741 | struct drm_device *dev = dev_priv->dev; |
| 6742 | struct device *device = &dev->pdev->dev; |
| 6743 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6744 | if (!HAS_RUNTIME_PM(dev)) |
| 6745 | return; |
| 6746 | |
| 6747 | pm_runtime_set_active(device); |
| 6748 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 6749 | /* |
| 6750 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 6751 | * requirement. |
| 6752 | */ |
| 6753 | if (!intel_enable_rc6(dev)) { |
| 6754 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 6755 | return; |
| 6756 | } |
| 6757 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6758 | pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */ |
| 6759 | pm_runtime_mark_last_busy(device); |
| 6760 | pm_runtime_use_autosuspend(device); |
Paulo Zanoni | ba0239e | 2014-03-07 20:08:07 -0300 | [diff] [blame] | 6761 | |
| 6762 | pm_runtime_put_autosuspend(device); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | void intel_fini_runtime_pm(struct drm_i915_private *dev_priv) |
| 6766 | { |
| 6767 | struct drm_device *dev = dev_priv->dev; |
| 6768 | struct device *device = &dev->pdev->dev; |
| 6769 | |
| 6770 | if (!HAS_RUNTIME_PM(dev)) |
| 6771 | return; |
| 6772 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 6773 | if (!intel_enable_rc6(dev)) |
| 6774 | return; |
| 6775 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 6776 | /* Make sure we're not suspended first. */ |
| 6777 | pm_runtime_get_sync(device); |
| 6778 | pm_runtime_disable(device); |
| 6779 | } |
| 6780 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6781 | /* Set up chip specific power management-related functions */ |
| 6782 | void intel_init_pm(struct drm_device *dev) |
| 6783 | { |
| 6784 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6785 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 6786 | if (HAS_FBC(dev)) { |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6787 | if (INTEL_INFO(dev)->gen >= 7) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6788 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6789 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 6790 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6791 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 6792 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 6793 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6794 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6795 | } else if (IS_GM45(dev)) { |
| 6796 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 6797 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 6798 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 6799 | } else { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6800 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 6801 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 6802 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 6803 | |
| 6804 | /* This value was pulled out of someone's hat */ |
| 6805 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6806 | } |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6807 | } |
| 6808 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6809 | /* For cxsr */ |
| 6810 | if (IS_PINEVIEW(dev)) |
| 6811 | i915_pineview_get_mem_freq(dev); |
| 6812 | else if (IS_GEN5(dev)) |
| 6813 | i915_ironlake_get_mem_freq(dev); |
| 6814 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6815 | /* For FIFO watermark updates */ |
| 6816 | if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6817 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6818 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6819 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6820 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6821 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6822 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6823 | dev_priv->display.update_wm = ilk_update_wm; |
| 6824 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6825 | } else { |
| 6826 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6827 | "Disable CxSR\n"); |
| 6828 | } |
| 6829 | |
| 6830 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6831 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6832 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6833 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6834 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6835 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6836 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6837 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6838 | else if (INTEL_INFO(dev)->gen == 8) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6839 | dev_priv->display.init_clock_gating = gen8_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6840 | } else if (IS_CHERRYVIEW(dev)) { |
| 6841 | dev_priv->display.update_wm = valleyview_update_wm; |
| 6842 | dev_priv->display.init_clock_gating = |
| 6843 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6844 | } else if (IS_VALLEYVIEW(dev)) { |
| 6845 | dev_priv->display.update_wm = valleyview_update_wm; |
| 6846 | dev_priv->display.init_clock_gating = |
| 6847 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6848 | } else if (IS_PINEVIEW(dev)) { |
| 6849 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6850 | dev_priv->is_ddr3, |
| 6851 | dev_priv->fsb_freq, |
| 6852 | dev_priv->mem_freq)) { |
| 6853 | DRM_INFO("failed to find known CxSR latency " |
| 6854 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6855 | "disabling CxSR\n", |
| 6856 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6857 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6858 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6859 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6860 | dev_priv->display.update_wm = NULL; |
| 6861 | } else |
| 6862 | dev_priv->display.update_wm = pineview_update_wm; |
| 6863 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6864 | } else if (IS_G4X(dev)) { |
| 6865 | dev_priv->display.update_wm = g4x_update_wm; |
| 6866 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6867 | } else if (IS_GEN4(dev)) { |
| 6868 | dev_priv->display.update_wm = i965_update_wm; |
| 6869 | if (IS_CRESTLINE(dev)) |
| 6870 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6871 | else if (IS_BROADWATER(dev)) |
| 6872 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6873 | } else if (IS_GEN3(dev)) { |
| 6874 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6875 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6876 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6877 | } else if (IS_GEN2(dev)) { |
| 6878 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6879 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6880 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6881 | } else { |
| 6882 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6883 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6887 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6888 | else |
| 6889 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6890 | } else { |
| 6891 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6892 | } |
| 6893 | } |
| 6894 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6895 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 6896 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6897 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6898 | |
| 6899 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6900 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6901 | return -EAGAIN; |
| 6902 | } |
| 6903 | |
| 6904 | I915_WRITE(GEN6_PCODE_DATA, *val); |
| 6905 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6906 | |
| 6907 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6908 | 500)) { |
| 6909 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6910 | return -ETIMEDOUT; |
| 6911 | } |
| 6912 | |
| 6913 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6914 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6915 | |
| 6916 | return 0; |
| 6917 | } |
| 6918 | |
| 6919 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 6920 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6921 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6922 | |
| 6923 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6924 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6925 | return -EAGAIN; |
| 6926 | } |
| 6927 | |
| 6928 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6929 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6930 | |
| 6931 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6932 | 500)) { |
| 6933 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6934 | return -ETIMEDOUT; |
| 6935 | } |
| 6936 | |
| 6937 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6938 | |
| 6939 | return 0; |
| 6940 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6941 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6942 | 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] | 6943 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6944 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6945 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6946 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6947 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6948 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6949 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6950 | break; |
| 6951 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6952 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6953 | break; |
| 6954 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6955 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6956 | break; |
| 6957 | default: |
| 6958 | return -1; |
| 6959 | } |
| 6960 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6961 | 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] | 6962 | } |
| 6963 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6964 | 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] | 6965 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6966 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6967 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6968 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6969 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6970 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6971 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6972 | break; |
| 6973 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6974 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6975 | break; |
| 6976 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 6977 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6978 | break; |
| 6979 | default: |
| 6980 | return -1; |
| 6981 | } |
| 6982 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 6983 | 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] | 6984 | } |
| 6985 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6986 | 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] | 6987 | { |
| 6988 | int div, freq; |
| 6989 | |
| 6990 | switch (dev_priv->rps.cz_freq) { |
| 6991 | case 200: |
| 6992 | div = 5; |
| 6993 | break; |
| 6994 | case 267: |
| 6995 | div = 6; |
| 6996 | break; |
| 6997 | case 320: |
| 6998 | case 333: |
| 6999 | case 400: |
| 7000 | div = 8; |
| 7001 | break; |
| 7002 | default: |
| 7003 | return -1; |
| 7004 | } |
| 7005 | |
| 7006 | freq = (DIV_ROUND_CLOSEST((dev_priv->rps.cz_freq * val), 2 * div) / 2); |
| 7007 | |
| 7008 | return freq; |
| 7009 | } |
| 7010 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7011 | 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] | 7012 | { |
| 7013 | int mul, opcode; |
| 7014 | |
| 7015 | switch (dev_priv->rps.cz_freq) { |
| 7016 | case 200: |
| 7017 | mul = 5; |
| 7018 | break; |
| 7019 | case 267: |
| 7020 | mul = 6; |
| 7021 | break; |
| 7022 | case 320: |
| 7023 | case 333: |
| 7024 | case 400: |
| 7025 | mul = 8; |
| 7026 | break; |
| 7027 | default: |
| 7028 | return -1; |
| 7029 | } |
| 7030 | |
| 7031 | opcode = (DIV_ROUND_CLOSEST((val * 2 * mul), dev_priv->rps.cz_freq) * 2); |
| 7032 | |
| 7033 | return opcode; |
| 7034 | } |
| 7035 | |
| 7036 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 7037 | { |
| 7038 | int ret = -1; |
| 7039 | |
| 7040 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7041 | ret = chv_gpu_freq(dev_priv, val); |
| 7042 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7043 | ret = byt_gpu_freq(dev_priv, val); |
| 7044 | |
| 7045 | return ret; |
| 7046 | } |
| 7047 | |
| 7048 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 7049 | { |
| 7050 | int ret = -1; |
| 7051 | |
| 7052 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7053 | ret = chv_freq_opcode(dev_priv, val); |
| 7054 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7055 | ret = byt_freq_opcode(dev_priv, val); |
| 7056 | |
| 7057 | return ret; |
| 7058 | } |
| 7059 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7060 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7061 | { |
| 7062 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7063 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7064 | mutex_init(&dev_priv->rps.hw_lock); |
| 7065 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7066 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 7067 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 7068 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 7069 | dev_priv->pm.suspended = false; |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 7070 | dev_priv->pm._irqs_disabled = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7071 | } |