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> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 33 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 34 | /** |
| 35 | * RC6 is a special power stage which allows the GPU to enter an very |
| 36 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 37 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 38 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 39 | * |
| 40 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 41 | * among each other with the latency required to enter and leave RC6 and |
| 42 | * voltage consumed by the GPU in different states. |
| 43 | * |
| 44 | * The combination of the following flags define which states GPU is allowed |
| 45 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 46 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 47 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 48 | * which brings the most power savings; deeper states save more power, but |
| 49 | * require higher latency to switch to and wake up. |
| 50 | */ |
| 51 | #define INTEL_RC6_ENABLE (1<<0) |
| 52 | #define INTEL_RC6p_ENABLE (1<<1) |
| 53 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 54 | |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 55 | /* FBC, or Frame Buffer Compression, is a technique employed to compress the |
| 56 | * framebuffer contents in-memory, aiming at reducing the required bandwidth |
| 57 | * during in-memory transfers and, therefore, reduce the power packet. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 58 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 59 | * The benefits of FBC are mostly visible with solid backgrounds and |
| 60 | * variation-less patterns. |
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 | * FBC-related functionality can be enabled by the means of the |
| 63 | * i915.i915_enable_fbc parameter |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 64 | */ |
| 65 | |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 66 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 67 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 68 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 69 | |
| 70 | /* |
| 71 | * WaDisableSDEUnitClockGating:skl |
| 72 | * This seems to be a pre-production w/a. |
| 73 | */ |
| 74 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 75 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 91e41d1 | 2014-03-26 17:42:50 +0000 | [diff] [blame] | 76 | |
Damien Lespiau | 3ca5da4 | 2014-03-26 18:18:01 +0000 | [diff] [blame] | 77 | /* |
| 78 | * WaDisableDgMirrorFixInHalfSliceChicken5:skl |
| 79 | * This is a pre-production w/a. |
| 80 | */ |
| 81 | I915_WRITE(GEN9_HALF_SLICE_CHICKEN5, |
| 82 | I915_READ(GEN9_HALF_SLICE_CHICKEN5) & |
| 83 | ~GEN9_DG_MIRROR_FIX_ENABLE); |
| 84 | |
Damien Lespiau | 91e41d1 | 2014-03-26 17:42:50 +0000 | [diff] [blame] | 85 | /* Wa4x4STCOptimizationDisable:skl */ |
| 86 | I915_WRITE(CACHE_MODE_1, |
| 87 | _MASKED_BIT_ENABLE(GEN8_4x4_STC_OPTIMIZATION_DISABLE)); |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 90 | static void i8xx_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 91 | { |
| 92 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 93 | u32 fbc_ctl; |
| 94 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 95 | dev_priv->fbc.enabled = false; |
| 96 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 97 | /* Disable compression */ |
| 98 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 99 | if ((fbc_ctl & FBC_CTL_EN) == 0) |
| 100 | return; |
| 101 | |
| 102 | fbc_ctl &= ~FBC_CTL_EN; |
| 103 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 104 | |
| 105 | /* Wait for compressing bit to clear */ |
| 106 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { |
| 107 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 112 | } |
| 113 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 114 | static void i8xx_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 115 | { |
| 116 | struct drm_device *dev = crtc->dev; |
| 117 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 118 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 119 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 120 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 121 | int cfb_pitch; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 122 | int i; |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 123 | u32 fbc_ctl; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 124 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 125 | dev_priv->fbc.enabled = true; |
| 126 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 127 | cfb_pitch = dev_priv->fbc.size / FBC_LL_SIZE; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 128 | if (fb->pitches[0] < cfb_pitch) |
| 129 | cfb_pitch = fb->pitches[0]; |
| 130 | |
Ville Syrjälä | 42a430f | 2013-11-28 17:29:56 +0200 | [diff] [blame] | 131 | /* FBC_CTL wants 32B or 64B units */ |
| 132 | if (IS_GEN2(dev)) |
| 133 | cfb_pitch = (cfb_pitch / 32) - 1; |
| 134 | else |
| 135 | cfb_pitch = (cfb_pitch / 64) - 1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 136 | |
| 137 | /* Clear old tags */ |
| 138 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 139 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 140 | |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 141 | if (IS_GEN4(dev)) { |
| 142 | u32 fbc_ctl2; |
| 143 | |
| 144 | /* Set it up... */ |
| 145 | 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] | 146 | fbc_ctl2 |= FBC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 147 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 148 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 149 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 150 | |
| 151 | /* enable it... */ |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 152 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 153 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 154 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 155 | if (IS_I945GM(dev)) |
| 156 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 157 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 158 | fbc_ctl |= obj->fence_reg; |
| 159 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 160 | |
Ville Syrjälä | 5cd5410 | 2014-01-23 16:49:16 +0200 | [diff] [blame] | 161 | 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] | 162 | cfb_pitch, crtc->y, plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 163 | } |
| 164 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 165 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 166 | { |
| 167 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 168 | |
| 169 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 170 | } |
| 171 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 172 | static void g4x_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 173 | { |
| 174 | struct drm_device *dev = crtc->dev; |
| 175 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 176 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 177 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 178 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 179 | u32 dpfc_ctl; |
| 180 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 181 | dev_priv->fbc.enabled = true; |
| 182 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 183 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane) | DPFC_SR_EN; |
| 184 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 185 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 186 | else |
| 187 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 188 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 189 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 190 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 191 | |
| 192 | /* enable it... */ |
Ville Syrjälä | fe74c1a | 2014-01-23 16:49:13 +0200 | [diff] [blame] | 193 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 194 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 195 | 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] | 196 | } |
| 197 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 198 | static void g4x_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 199 | { |
| 200 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 201 | u32 dpfc_ctl; |
| 202 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 203 | dev_priv->fbc.enabled = false; |
| 204 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 205 | /* Disable compression */ |
| 206 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 207 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 208 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 209 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 210 | |
| 211 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 212 | } |
| 213 | } |
| 214 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 215 | static bool g4x_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 216 | { |
| 217 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 218 | |
| 219 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 220 | } |
| 221 | |
| 222 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 223 | { |
| 224 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 225 | u32 blt_ecoskpd; |
| 226 | |
| 227 | /* Make sure blitter notifies FBC of writes */ |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 228 | |
| 229 | /* Blitter is part of Media powerwell on VLV. No impact of |
| 230 | * his param in other platforms for now */ |
| 231 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 232 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 233 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 234 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 235 | GEN6_BLITTER_LOCK_SHIFT; |
| 236 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 237 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 238 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 239 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 240 | GEN6_BLITTER_LOCK_SHIFT); |
| 241 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 242 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 243 | |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 244 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_MEDIA); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 245 | } |
| 246 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 247 | static void ironlake_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 248 | { |
| 249 | struct drm_device *dev = crtc->dev; |
| 250 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 251 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 252 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 253 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 254 | u32 dpfc_ctl; |
| 255 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 256 | dev_priv->fbc.enabled = true; |
| 257 | |
Ville Syrjälä | 46f3dab | 2014-01-23 16:49:14 +0200 | [diff] [blame] | 258 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 259 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 260 | dev_priv->fbc.threshold++; |
| 261 | |
| 262 | switch (dev_priv->fbc.threshold) { |
| 263 | case 4: |
| 264 | case 3: |
| 265 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 266 | break; |
| 267 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 268 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 269 | break; |
| 270 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 271 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 272 | break; |
| 273 | } |
Ville Syrjälä | d629336 | 2013-11-21 21:29:45 +0200 | [diff] [blame] | 274 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
| 275 | if (IS_GEN5(dev)) |
| 276 | dpfc_ctl |= obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 277 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 278 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 279 | 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] | 280 | /* enable it... */ |
| 281 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 282 | |
| 283 | if (IS_GEN6(dev)) { |
| 284 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 285 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 286 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 287 | sandybridge_blit_fbc_update(dev); |
| 288 | } |
| 289 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 290 | 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] | 291 | } |
| 292 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 293 | static void ironlake_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 294 | { |
| 295 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 296 | u32 dpfc_ctl; |
| 297 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 298 | dev_priv->fbc.enabled = false; |
| 299 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 300 | /* Disable compression */ |
| 301 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 302 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 303 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 304 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 305 | |
| 306 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 307 | } |
| 308 | } |
| 309 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 310 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 311 | { |
| 312 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 313 | |
| 314 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 315 | } |
| 316 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 317 | static void gen7_enable_fbc(struct drm_crtc *crtc) |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 318 | { |
| 319 | struct drm_device *dev = crtc->dev; |
| 320 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 321 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 322 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 323 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 324 | u32 dpfc_ctl; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 325 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 326 | dev_priv->fbc.enabled = true; |
| 327 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 328 | dpfc_ctl = IVB_DPFC_CTL_PLANE(intel_crtc->plane); |
| 329 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 330 | dev_priv->fbc.threshold++; |
| 331 | |
| 332 | switch (dev_priv->fbc.threshold) { |
| 333 | case 4: |
| 334 | case 3: |
| 335 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 336 | break; |
| 337 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 338 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 339 | break; |
| 340 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 341 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 342 | break; |
| 343 | } |
| 344 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 345 | dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN; |
| 346 | |
Rodrigo Vivi | da46f93 | 2014-08-01 02:04:45 -0700 | [diff] [blame] | 347 | if (dev_priv->fbc.false_color) |
| 348 | dpfc_ctl |= FBC_CTL_FALSE_COLOR; |
| 349 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 350 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 351 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 352 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 353 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 354 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 355 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 356 | ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 357 | } else { |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 358 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 359 | I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe), |
| 360 | I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) | |
| 361 | HSW_FBCQ_DIS); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 362 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 363 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 364 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 365 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 366 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 367 | |
| 368 | sandybridge_blit_fbc_update(dev); |
| 369 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 370 | 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] | 371 | } |
| 372 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 373 | bool intel_fbc_enabled(struct drm_device *dev) |
| 374 | { |
| 375 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 376 | |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 377 | return dev_priv->fbc.enabled; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 378 | } |
| 379 | |
Rodrigo Vivi | 1d73c2a | 2014-09-24 19:50:59 -0400 | [diff] [blame] | 380 | void bdw_fbc_sw_flush(struct drm_device *dev, u32 value) |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 381 | { |
| 382 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 383 | |
| 384 | if (!IS_GEN8(dev)) |
| 385 | return; |
| 386 | |
Rodrigo Vivi | 01d06e9 | 2014-09-05 16:57:20 -0400 | [diff] [blame] | 387 | if (!intel_fbc_enabled(dev)) |
| 388 | return; |
| 389 | |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 390 | I915_WRITE(MSG_FBC_REND_STATE, value); |
| 391 | } |
| 392 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 393 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 394 | { |
| 395 | struct intel_fbc_work *work = |
| 396 | container_of(to_delayed_work(__work), |
| 397 | struct intel_fbc_work, work); |
| 398 | struct drm_device *dev = work->crtc->dev; |
| 399 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 400 | |
| 401 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 402 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 403 | /* Double check that we haven't switched fb without cancelling |
| 404 | * the prior work. |
| 405 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 406 | if (work->crtc->primary->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 407 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 408 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 409 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 410 | dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id; |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 411 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 412 | } |
| 413 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 414 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 415 | } |
| 416 | mutex_unlock(&dev->struct_mutex); |
| 417 | |
| 418 | kfree(work); |
| 419 | } |
| 420 | |
| 421 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 422 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 423 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 424 | return; |
| 425 | |
| 426 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 427 | |
| 428 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 429 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 430 | * entirely asynchronously. |
| 431 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 432 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 433 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 434 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 435 | |
| 436 | /* Mark the work as no longer wanted so that if it does |
| 437 | * wake-up (because the work was already running and waiting |
| 438 | * for our mutex), it will discover that is no longer |
| 439 | * necessary to run. |
| 440 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 441 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 442 | } |
| 443 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 444 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 445 | { |
| 446 | struct intel_fbc_work *work; |
| 447 | struct drm_device *dev = crtc->dev; |
| 448 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 449 | |
| 450 | if (!dev_priv->display.enable_fbc) |
| 451 | return; |
| 452 | |
| 453 | intel_cancel_fbc_work(dev_priv); |
| 454 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 455 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 456 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 457 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 458 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | |
| 462 | work->crtc = crtc; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 463 | work->fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 464 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 465 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 466 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 467 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 468 | /* Delay the actual enabling to let pageflipping cease and the |
| 469 | * display to settle before starting the compression. Note that |
| 470 | * this delay also serves a second purpose: it allows for a |
| 471 | * vblank to pass after disabling the FBC before we attempt |
| 472 | * to modify the control registers. |
| 473 | * |
| 474 | * A more complicated solution would involve tracking vblanks |
| 475 | * following the termination of the page-flipping sequence |
| 476 | * and indeed performing the enable as a co-routine and not |
| 477 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 478 | * |
| 479 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 480 | */ |
| 481 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 482 | } |
| 483 | |
| 484 | void intel_disable_fbc(struct drm_device *dev) |
| 485 | { |
| 486 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 487 | |
| 488 | intel_cancel_fbc_work(dev_priv); |
| 489 | |
| 490 | if (!dev_priv->display.disable_fbc) |
| 491 | return; |
| 492 | |
| 493 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 494 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 495 | } |
| 496 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 497 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 498 | enum no_fbc_reason reason) |
| 499 | { |
| 500 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 501 | return false; |
| 502 | |
| 503 | dev_priv->fbc.no_fbc_reason = reason; |
| 504 | return true; |
| 505 | } |
| 506 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 507 | /** |
| 508 | * intel_update_fbc - enable/disable FBC as needed |
| 509 | * @dev: the drm_device |
| 510 | * |
| 511 | * Set up the framebuffer compression hardware at mode set time. We |
| 512 | * enable it if possible: |
| 513 | * - plane A only (on pre-965) |
| 514 | * - no pixel mulitply/line duplication |
| 515 | * - no alpha buffer discard |
| 516 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 517 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 518 | * |
| 519 | * We can't assume that any compression will take place (worst case), |
| 520 | * so the compressed buffer has to be the same size as the uncompressed |
| 521 | * one. It also must reside (along with the line length buffer) in |
| 522 | * stolen memory. |
| 523 | * |
| 524 | * We need to enable/disable FBC on a global basis. |
| 525 | */ |
| 526 | void intel_update_fbc(struct drm_device *dev) |
| 527 | { |
| 528 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 529 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 530 | struct intel_crtc *intel_crtc; |
| 531 | struct drm_framebuffer *fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 532 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 533 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 534 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 535 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 536 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 537 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 538 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 539 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 540 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 541 | if (!i915.powersave) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 542 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 543 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 544 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 545 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * If FBC is already on, we just have to verify that we can |
| 549 | * keep it that way... |
| 550 | * Need to disable if: |
| 551 | * - more than one pipe is active |
| 552 | * - changing FBC params (stride, fence, mode) |
| 553 | * - new fb is too large to fit in compressed buffer |
| 554 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 555 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 556 | for_each_crtc(dev, tmp_crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 557 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 558 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 559 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 560 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 561 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 562 | goto out_disable; |
| 563 | } |
| 564 | crtc = tmp_crtc; |
| 565 | } |
| 566 | } |
| 567 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 568 | if (!crtc || crtc->primary->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 569 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 570 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 571 | goto out_disable; |
| 572 | } |
| 573 | |
| 574 | intel_crtc = to_intel_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 575 | fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 576 | obj = intel_fb_obj(fb); |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 577 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 578 | |
Chris Wilson | 0368920 | 2014-06-06 10:37:11 +0100 | [diff] [blame] | 579 | if (i915.enable_fbc < 0) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 580 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 581 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 582 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 583 | } |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 584 | if (!i915.enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 585 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 586 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 587 | goto out_disable; |
| 588 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 589 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 590 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 591 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 592 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 593 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 594 | goto out_disable; |
| 595 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 596 | |
Daisy Sun | 032843a | 2014-06-16 15:48:18 -0700 | [diff] [blame] | 597 | if (INTEL_INFO(dev)->gen >= 8 || IS_HASWELL(dev)) { |
| 598 | max_width = 4096; |
| 599 | max_height = 4096; |
| 600 | } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 601 | max_width = 4096; |
| 602 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 603 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 604 | max_width = 2048; |
| 605 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 606 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 607 | if (intel_crtc->config.pipe_src_w > max_width || |
| 608 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 609 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 610 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 611 | goto out_disable; |
| 612 | } |
Ben Widawsky | 8f94d24 | 2014-02-20 16:01:20 -0800 | [diff] [blame] | 613 | if ((INTEL_INFO(dev)->gen < 4 || HAS_DDI(dev)) && |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 614 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 615 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 616 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 617 | goto out_disable; |
| 618 | } |
| 619 | |
| 620 | /* The use of a CPU fence is mandatory in order to detect writes |
| 621 | * by the CPU to the scanout and trigger updates to the FBC. |
| 622 | */ |
| 623 | if (obj->tiling_mode != I915_TILING_X || |
| 624 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 625 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 626 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 627 | goto out_disable; |
| 628 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 629 | if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
| 630 | to_intel_plane(crtc->primary)->rotation != BIT(DRM_ROTATE_0)) { |
| 631 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 632 | DRM_DEBUG_KMS("Rotation unsupported, disabling\n"); |
| 633 | goto out_disable; |
| 634 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 635 | |
| 636 | /* If the kernel debugger is active, always disable compression */ |
| 637 | if (in_dbg_master()) |
| 638 | goto out_disable; |
| 639 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 640 | if (i915_gem_stolen_setup_compression(dev, obj->base.size, |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 641 | drm_format_plane_cpp(fb->pixel_format, 0))) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 642 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 643 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 644 | goto out_disable; |
| 645 | } |
| 646 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 647 | /* If the scanout has not changed, don't modify the FBC settings. |
| 648 | * Note that we make the fundamental assumption that the fb->obj |
| 649 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 650 | * without first being decoupled from the scanout and FBC disabled. |
| 651 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 652 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 653 | dev_priv->fbc.fb_id == fb->base.id && |
| 654 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 655 | return; |
| 656 | |
| 657 | if (intel_fbc_enabled(dev)) { |
| 658 | /* We update FBC along two paths, after changing fb/crtc |
| 659 | * configuration (modeswitching) and after page-flipping |
| 660 | * finishes. For the latter, we know that not only did |
| 661 | * we disable the FBC at the start of the page-flip |
| 662 | * sequence, but also more than one vblank has passed. |
| 663 | * |
| 664 | * For the former case of modeswitching, it is possible |
| 665 | * to switch between two FBC valid configurations |
| 666 | * instantaneously so we do need to disable the FBC |
| 667 | * before we can modify its control registers. We also |
| 668 | * have to wait for the next vblank for that to take |
| 669 | * effect. However, since we delay enabling FBC we can |
| 670 | * assume that a vblank has passed since disabling and |
| 671 | * that we can safely alter the registers in the deferred |
| 672 | * callback. |
| 673 | * |
| 674 | * In the scenario that we go from a valid to invalid |
| 675 | * and then back to valid FBC configuration we have |
| 676 | * no strict enforcement that a vblank occurred since |
| 677 | * disabling the FBC. However, along all current pipe |
| 678 | * disabling paths we do need to wait for a vblank at |
| 679 | * some point. And we wait before enabling FBC anyway. |
| 680 | */ |
| 681 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 682 | intel_disable_fbc(dev); |
| 683 | } |
| 684 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 685 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 686 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 687 | return; |
| 688 | |
| 689 | out_disable: |
| 690 | /* Multiple disables should be harmless */ |
| 691 | if (intel_fbc_enabled(dev)) { |
| 692 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 693 | intel_disable_fbc(dev); |
| 694 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 695 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 696 | } |
| 697 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 698 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 699 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 700 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 701 | u32 tmp; |
| 702 | |
| 703 | tmp = I915_READ(CLKCFG); |
| 704 | |
| 705 | switch (tmp & CLKCFG_FSB_MASK) { |
| 706 | case CLKCFG_FSB_533: |
| 707 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 708 | break; |
| 709 | case CLKCFG_FSB_800: |
| 710 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 711 | break; |
| 712 | case CLKCFG_FSB_667: |
| 713 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 714 | break; |
| 715 | case CLKCFG_FSB_400: |
| 716 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 717 | break; |
| 718 | } |
| 719 | |
| 720 | switch (tmp & CLKCFG_MEM_MASK) { |
| 721 | case CLKCFG_MEM_533: |
| 722 | dev_priv->mem_freq = 533; |
| 723 | break; |
| 724 | case CLKCFG_MEM_667: |
| 725 | dev_priv->mem_freq = 667; |
| 726 | break; |
| 727 | case CLKCFG_MEM_800: |
| 728 | dev_priv->mem_freq = 800; |
| 729 | break; |
| 730 | } |
| 731 | |
| 732 | /* detect pineview DDR3 setting */ |
| 733 | tmp = I915_READ(CSHRDDR3CTL); |
| 734 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 735 | } |
| 736 | |
| 737 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 738 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 739 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 740 | u16 ddrpll, csipll; |
| 741 | |
| 742 | ddrpll = I915_READ16(DDRMPLL1); |
| 743 | csipll = I915_READ16(CSIPLL0); |
| 744 | |
| 745 | switch (ddrpll & 0xff) { |
| 746 | case 0xc: |
| 747 | dev_priv->mem_freq = 800; |
| 748 | break; |
| 749 | case 0x10: |
| 750 | dev_priv->mem_freq = 1066; |
| 751 | break; |
| 752 | case 0x14: |
| 753 | dev_priv->mem_freq = 1333; |
| 754 | break; |
| 755 | case 0x18: |
| 756 | dev_priv->mem_freq = 1600; |
| 757 | break; |
| 758 | default: |
| 759 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 760 | ddrpll & 0xff); |
| 761 | dev_priv->mem_freq = 0; |
| 762 | break; |
| 763 | } |
| 764 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 765 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 766 | |
| 767 | switch (csipll & 0x3ff) { |
| 768 | case 0x00c: |
| 769 | dev_priv->fsb_freq = 3200; |
| 770 | break; |
| 771 | case 0x00e: |
| 772 | dev_priv->fsb_freq = 3733; |
| 773 | break; |
| 774 | case 0x010: |
| 775 | dev_priv->fsb_freq = 4266; |
| 776 | break; |
| 777 | case 0x012: |
| 778 | dev_priv->fsb_freq = 4800; |
| 779 | break; |
| 780 | case 0x014: |
| 781 | dev_priv->fsb_freq = 5333; |
| 782 | break; |
| 783 | case 0x016: |
| 784 | dev_priv->fsb_freq = 5866; |
| 785 | break; |
| 786 | case 0x018: |
| 787 | dev_priv->fsb_freq = 6400; |
| 788 | break; |
| 789 | default: |
| 790 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 791 | csipll & 0x3ff); |
| 792 | dev_priv->fsb_freq = 0; |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 797 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 798 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 799 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 800 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 801 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 805 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 806 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 807 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 808 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 809 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 810 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 811 | |
| 812 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 813 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 814 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 815 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 816 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 817 | |
| 818 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 819 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 820 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 821 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 822 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 823 | |
| 824 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 825 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 826 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 827 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 828 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 829 | |
| 830 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 831 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 832 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 833 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 834 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 835 | |
| 836 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 837 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 838 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 839 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 840 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 841 | }; |
| 842 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 843 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 844 | int is_ddr3, |
| 845 | int fsb, |
| 846 | int mem) |
| 847 | { |
| 848 | const struct cxsr_latency *latency; |
| 849 | int i; |
| 850 | |
| 851 | if (fsb == 0 || mem == 0) |
| 852 | return NULL; |
| 853 | |
| 854 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 855 | latency = &cxsr_latency_table[i]; |
| 856 | if (is_desktop == latency->is_desktop && |
| 857 | is_ddr3 == latency->is_ddr3 && |
| 858 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 859 | return latency; |
| 860 | } |
| 861 | |
| 862 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 863 | |
| 864 | return NULL; |
| 865 | } |
| 866 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 867 | 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] | 868 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 869 | struct drm_device *dev = dev_priv->dev; |
| 870 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 871 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 872 | if (IS_VALLEYVIEW(dev)) { |
| 873 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 874 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 875 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 876 | } else if (IS_PINEVIEW(dev)) { |
| 877 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 878 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 879 | I915_WRITE(DSPFW3, val); |
| 880 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 881 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 882 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 883 | I915_WRITE(FW_BLC_SELF, val); |
| 884 | } else if (IS_I915GM(dev)) { |
| 885 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 886 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 887 | I915_WRITE(INSTPM, val); |
| 888 | } else { |
| 889 | return; |
| 890 | } |
| 891 | |
| 892 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 893 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | /* |
| 897 | * Latency for FIFO fetches is dependent on several factors: |
| 898 | * - memory configuration (speed, channels) |
| 899 | * - chipset |
| 900 | * - current MCH state |
| 901 | * It can be fairly high in some situations, so here we assume a fairly |
| 902 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 903 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 904 | * and power consumption (set it too low to save power and we might see |
| 905 | * FIFO underruns and display "flicker"). |
| 906 | * |
| 907 | * A value of 5us seems to be a good balance; safe for very low end |
| 908 | * platforms but not overly aggressive on lower latency configs. |
| 909 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 910 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 911 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 912 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | { |
| 914 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 915 | uint32_t dsparb = I915_READ(DSPARB); |
| 916 | int size; |
| 917 | |
| 918 | size = dsparb & 0x7f; |
| 919 | if (plane) |
| 920 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 921 | |
| 922 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 923 | plane ? "B" : "A", size); |
| 924 | |
| 925 | return size; |
| 926 | } |
| 927 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 928 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 929 | { |
| 930 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 931 | uint32_t dsparb = I915_READ(DSPARB); |
| 932 | int size; |
| 933 | |
| 934 | size = dsparb & 0x1ff; |
| 935 | if (plane) |
| 936 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 937 | size >>= 1; /* Convert to cachelines */ |
| 938 | |
| 939 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 940 | plane ? "B" : "A", size); |
| 941 | |
| 942 | return size; |
| 943 | } |
| 944 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 945 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 946 | { |
| 947 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 948 | uint32_t dsparb = I915_READ(DSPARB); |
| 949 | int size; |
| 950 | |
| 951 | size = dsparb & 0x7f; |
| 952 | size >>= 2; /* Convert to cachelines */ |
| 953 | |
| 954 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 955 | plane ? "B" : "A", |
| 956 | size); |
| 957 | |
| 958 | return size; |
| 959 | } |
| 960 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 961 | /* Pineview has different values for various configs */ |
| 962 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 963 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 964 | .max_wm = PINEVIEW_MAX_WM, |
| 965 | .default_wm = PINEVIEW_DFT_WM, |
| 966 | .guard_size = PINEVIEW_GUARD_WM, |
| 967 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 968 | }; |
| 969 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 970 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 971 | .max_wm = PINEVIEW_MAX_WM, |
| 972 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 973 | .guard_size = PINEVIEW_GUARD_WM, |
| 974 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 975 | }; |
| 976 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 977 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 978 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 979 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 980 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 981 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 982 | }; |
| 983 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 984 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 985 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 986 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 987 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 988 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 989 | }; |
| 990 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 991 | .fifo_size = G4X_FIFO_SIZE, |
| 992 | .max_wm = G4X_MAX_WM, |
| 993 | .default_wm = G4X_MAX_WM, |
| 994 | .guard_size = 2, |
| 995 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 996 | }; |
| 997 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 998 | .fifo_size = I965_CURSOR_FIFO, |
| 999 | .max_wm = I965_CURSOR_MAX_WM, |
| 1000 | .default_wm = I965_CURSOR_DFT_WM, |
| 1001 | .guard_size = 2, |
| 1002 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1003 | }; |
| 1004 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1005 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 1006 | .max_wm = VALLEYVIEW_MAX_WM, |
| 1007 | .default_wm = VALLEYVIEW_MAX_WM, |
| 1008 | .guard_size = 2, |
| 1009 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1010 | }; |
| 1011 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1012 | .fifo_size = I965_CURSOR_FIFO, |
| 1013 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 1014 | .default_wm = I965_CURSOR_DFT_WM, |
| 1015 | .guard_size = 2, |
| 1016 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1017 | }; |
| 1018 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1019 | .fifo_size = I965_CURSOR_FIFO, |
| 1020 | .max_wm = I965_CURSOR_MAX_WM, |
| 1021 | .default_wm = I965_CURSOR_DFT_WM, |
| 1022 | .guard_size = 2, |
| 1023 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1024 | }; |
| 1025 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1026 | .fifo_size = I945_FIFO_SIZE, |
| 1027 | .max_wm = I915_MAX_WM, |
| 1028 | .default_wm = 1, |
| 1029 | .guard_size = 2, |
| 1030 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1031 | }; |
| 1032 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1033 | .fifo_size = I915_FIFO_SIZE, |
| 1034 | .max_wm = I915_MAX_WM, |
| 1035 | .default_wm = 1, |
| 1036 | .guard_size = 2, |
| 1037 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1038 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1039 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1040 | .fifo_size = I855GM_FIFO_SIZE, |
| 1041 | .max_wm = I915_MAX_WM, |
| 1042 | .default_wm = 1, |
| 1043 | .guard_size = 2, |
| 1044 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1045 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1046 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 1047 | .fifo_size = I855GM_FIFO_SIZE, |
| 1048 | .max_wm = I915_MAX_WM/2, |
| 1049 | .default_wm = 1, |
| 1050 | .guard_size = 2, |
| 1051 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 1052 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1053 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1054 | .fifo_size = I830_FIFO_SIZE, |
| 1055 | .max_wm = I915_MAX_WM, |
| 1056 | .default_wm = 1, |
| 1057 | .guard_size = 2, |
| 1058 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1059 | }; |
| 1060 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1061 | /** |
| 1062 | * intel_calculate_wm - calculate watermark level |
| 1063 | * @clock_in_khz: pixel clock |
| 1064 | * @wm: chip FIFO params |
| 1065 | * @pixel_size: display pixel size |
| 1066 | * @latency_ns: memory latency for the platform |
| 1067 | * |
| 1068 | * Calculate the watermark level (the level at which the display plane will |
| 1069 | * start fetching from memory again). Each chip has a different display |
| 1070 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 1071 | * in the correct intel_watermark_params structure. |
| 1072 | * |
| 1073 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 1074 | * on the pixel size. When it reaches the watermark level, it'll start |
| 1075 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 1076 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 1077 | * will occur, and a display engine hang could result. |
| 1078 | */ |
| 1079 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 1080 | const struct intel_watermark_params *wm, |
| 1081 | int fifo_size, |
| 1082 | int pixel_size, |
| 1083 | unsigned long latency_ns) |
| 1084 | { |
| 1085 | long entries_required, wm_size; |
| 1086 | |
| 1087 | /* |
| 1088 | * Note: we need to make sure we don't overflow for various clock & |
| 1089 | * latency values. |
| 1090 | * clocks go from a few thousand to several hundred thousand. |
| 1091 | * latency is usually a few thousand |
| 1092 | */ |
| 1093 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 1094 | 1000; |
| 1095 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 1096 | |
| 1097 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 1098 | |
| 1099 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 1100 | |
| 1101 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 1102 | |
| 1103 | /* Don't promote wm_size to unsigned... */ |
| 1104 | if (wm_size > (long)wm->max_wm) |
| 1105 | wm_size = wm->max_wm; |
| 1106 | if (wm_size <= 0) |
| 1107 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 1108 | |
| 1109 | /* |
| 1110 | * Bspec seems to indicate that the value shouldn't be lower than |
| 1111 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 1112 | * Lets go for 8 which is the burst size since certain platforms |
| 1113 | * already use a hardcoded 8 (which is what the spec says should be |
| 1114 | * done). |
| 1115 | */ |
| 1116 | if (wm_size <= 8) |
| 1117 | wm_size = 8; |
| 1118 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1119 | return wm_size; |
| 1120 | } |
| 1121 | |
| 1122 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 1123 | { |
| 1124 | struct drm_crtc *crtc, *enabled = NULL; |
| 1125 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 1126 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1127 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1128 | if (enabled) |
| 1129 | return NULL; |
| 1130 | enabled = crtc; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | return enabled; |
| 1135 | } |
| 1136 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1137 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1138 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1139 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1141 | struct drm_crtc *crtc; |
| 1142 | const struct cxsr_latency *latency; |
| 1143 | u32 reg; |
| 1144 | unsigned long wm; |
| 1145 | |
| 1146 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1147 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1148 | if (!latency) { |
| 1149 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1150 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1151 | return; |
| 1152 | } |
| 1153 | |
| 1154 | crtc = single_enabled_crtc(dev); |
| 1155 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1156 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1157 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1158 | int clock; |
| 1159 | |
| 1160 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1161 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1162 | |
| 1163 | /* Display SR */ |
| 1164 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1165 | pineview_display_wm.fifo_size, |
| 1166 | pixel_size, latency->display_sr); |
| 1167 | reg = I915_READ(DSPFW1); |
| 1168 | reg &= ~DSPFW_SR_MASK; |
| 1169 | reg |= wm << DSPFW_SR_SHIFT; |
| 1170 | I915_WRITE(DSPFW1, reg); |
| 1171 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1172 | |
| 1173 | /* cursor SR */ |
| 1174 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1175 | pineview_display_wm.fifo_size, |
| 1176 | pixel_size, latency->cursor_sr); |
| 1177 | reg = I915_READ(DSPFW3); |
| 1178 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1179 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1180 | I915_WRITE(DSPFW3, reg); |
| 1181 | |
| 1182 | /* Display HPLL off SR */ |
| 1183 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1184 | pineview_display_hplloff_wm.fifo_size, |
| 1185 | pixel_size, latency->display_hpll_disable); |
| 1186 | reg = I915_READ(DSPFW3); |
| 1187 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1188 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1189 | I915_WRITE(DSPFW3, reg); |
| 1190 | |
| 1191 | /* cursor HPLL off SR */ |
| 1192 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1193 | pineview_display_hplloff_wm.fifo_size, |
| 1194 | pixel_size, latency->cursor_hpll_disable); |
| 1195 | reg = I915_READ(DSPFW3); |
| 1196 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1197 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1198 | I915_WRITE(DSPFW3, reg); |
| 1199 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1200 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1201 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1202 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1203 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1208 | int plane, |
| 1209 | const struct intel_watermark_params *display, |
| 1210 | int display_latency_ns, |
| 1211 | const struct intel_watermark_params *cursor, |
| 1212 | int cursor_latency_ns, |
| 1213 | int *plane_wm, |
| 1214 | int *cursor_wm) |
| 1215 | { |
| 1216 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1217 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1218 | int htotal, hdisplay, clock, pixel_size; |
| 1219 | int line_time_us, line_count; |
| 1220 | int entries, tlb_miss; |
| 1221 | |
| 1222 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1223 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1224 | *cursor_wm = cursor->guard_size; |
| 1225 | *plane_wm = display->guard_size; |
| 1226 | return false; |
| 1227 | } |
| 1228 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1229 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1230 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1231 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1232 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1233 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1234 | |
| 1235 | /* Use the small buffer method to calculate plane watermark */ |
| 1236 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1237 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1238 | if (tlb_miss > 0) |
| 1239 | entries += tlb_miss; |
| 1240 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1241 | *plane_wm = entries + display->guard_size; |
| 1242 | if (*plane_wm > (int)display->max_wm) |
| 1243 | *plane_wm = display->max_wm; |
| 1244 | |
| 1245 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1246 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1247 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1248 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1249 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1250 | if (tlb_miss > 0) |
| 1251 | entries += tlb_miss; |
| 1252 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1253 | *cursor_wm = entries + cursor->guard_size; |
| 1254 | if (*cursor_wm > (int)cursor->max_wm) |
| 1255 | *cursor_wm = (int)cursor->max_wm; |
| 1256 | |
| 1257 | return true; |
| 1258 | } |
| 1259 | |
| 1260 | /* |
| 1261 | * Check the wm result. |
| 1262 | * |
| 1263 | * If any calculated watermark values is larger than the maximum value that |
| 1264 | * can be programmed into the associated watermark register, that watermark |
| 1265 | * must be disabled. |
| 1266 | */ |
| 1267 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1268 | int display_wm, int cursor_wm, |
| 1269 | const struct intel_watermark_params *display, |
| 1270 | const struct intel_watermark_params *cursor) |
| 1271 | { |
| 1272 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1273 | display_wm, cursor_wm); |
| 1274 | |
| 1275 | if (display_wm > display->max_wm) { |
| 1276 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1277 | display_wm, display->max_wm); |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | if (cursor_wm > cursor->max_wm) { |
| 1282 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1283 | cursor_wm, cursor->max_wm); |
| 1284 | return false; |
| 1285 | } |
| 1286 | |
| 1287 | if (!(display_wm || cursor_wm)) { |
| 1288 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1289 | return false; |
| 1290 | } |
| 1291 | |
| 1292 | return true; |
| 1293 | } |
| 1294 | |
| 1295 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1296 | int plane, |
| 1297 | int latency_ns, |
| 1298 | const struct intel_watermark_params *display, |
| 1299 | const struct intel_watermark_params *cursor, |
| 1300 | int *display_wm, int *cursor_wm) |
| 1301 | { |
| 1302 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1303 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1304 | int hdisplay, htotal, pixel_size, clock; |
| 1305 | unsigned long line_time_us; |
| 1306 | int line_count, line_size; |
| 1307 | int small, large; |
| 1308 | int entries; |
| 1309 | |
| 1310 | if (!latency_ns) { |
| 1311 | *display_wm = *cursor_wm = 0; |
| 1312 | return false; |
| 1313 | } |
| 1314 | |
| 1315 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1316 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1317 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1318 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1319 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1320 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1321 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1322 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1323 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1324 | line_size = hdisplay * pixel_size; |
| 1325 | |
| 1326 | /* Use the minimum of the small and large buffer method for primary */ |
| 1327 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1328 | large = line_count * line_size; |
| 1329 | |
| 1330 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1331 | *display_wm = entries + display->guard_size; |
| 1332 | |
| 1333 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1334 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1335 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1336 | *cursor_wm = entries + cursor->guard_size; |
| 1337 | |
| 1338 | return g4x_check_srwm(dev, |
| 1339 | *display_wm, *cursor_wm, |
| 1340 | display, cursor); |
| 1341 | } |
| 1342 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1343 | static bool vlv_compute_drain_latency(struct drm_crtc *crtc, |
| 1344 | int pixel_size, |
| 1345 | int *prec_mult, |
| 1346 | int *drain_latency) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1347 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1348 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1349 | int entries; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1350 | int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1351 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1352 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1353 | return false; |
| 1354 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1355 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
| 1356 | return false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1357 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 1358 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1359 | if (IS_CHERRYVIEW(dev)) |
| 1360 | *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_32 : |
| 1361 | DRAIN_LATENCY_PRECISION_16; |
| 1362 | else |
| 1363 | *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_64 : |
| 1364 | DRAIN_LATENCY_PRECISION_32; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1365 | *drain_latency = (64 * (*prec_mult) * 4) / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1366 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 1367 | if (*drain_latency > DRAIN_LATENCY_MASK) |
| 1368 | *drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1369 | |
| 1370 | return true; |
| 1371 | } |
| 1372 | |
| 1373 | /* |
| 1374 | * Update drain latency registers of memory arbiter |
| 1375 | * |
| 1376 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1377 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1378 | * latency value. |
| 1379 | */ |
| 1380 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 1381 | static void vlv_update_drain_latency(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1382 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1383 | struct drm_device *dev = crtc->dev; |
| 1384 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1385 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1386 | int pixel_size; |
| 1387 | int drain_latency; |
| 1388 | enum pipe pipe = intel_crtc->pipe; |
| 1389 | int plane_prec, prec_mult, plane_dl; |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1390 | const int high_precision = IS_CHERRYVIEW(dev) ? |
| 1391 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1392 | |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1393 | plane_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_PLANE_PRECISION_HIGH | |
| 1394 | DRAIN_LATENCY_MASK | DDL_CURSOR_PRECISION_HIGH | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1395 | (DRAIN_LATENCY_MASK << DDL_CURSOR_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1396 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1397 | if (!intel_crtc_active(crtc)) { |
| 1398 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
| 1399 | return; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1400 | } |
| 1401 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1402 | /* Primary plane Drain Latency */ |
| 1403 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
| 1404 | if (vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1405 | plane_prec = (prec_mult == high_precision) ? |
| 1406 | DDL_PLANE_PRECISION_HIGH : |
| 1407 | DDL_PLANE_PRECISION_LOW; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1408 | plane_dl |= plane_prec | drain_latency; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1409 | } |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1410 | |
| 1411 | /* Cursor Drain Latency |
| 1412 | * BPP is always 4 for cursor |
| 1413 | */ |
| 1414 | pixel_size = 4; |
| 1415 | |
| 1416 | /* Program cursor DL only if it is enabled */ |
| 1417 | if (intel_crtc->cursor_base && |
| 1418 | vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1419 | plane_prec = (prec_mult == high_precision) ? |
| 1420 | DDL_CURSOR_PRECISION_HIGH : |
| 1421 | DDL_CURSOR_PRECISION_LOW; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1422 | plane_dl |= plane_prec | (drain_latency << DDL_CURSOR_SHIFT); |
| 1423 | } |
| 1424 | |
| 1425 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1429 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1430 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1431 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1432 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1433 | static const int sr_latency_ns = 12000; |
| 1434 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1435 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1436 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1437 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1438 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1439 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1440 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 1441 | vlv_update_drain_latency(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1442 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1443 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1444 | &valleyview_wm_info, pessimal_latency_ns, |
| 1445 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1446 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1447 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1448 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1449 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1450 | &valleyview_wm_info, pessimal_latency_ns, |
| 1451 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1452 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1453 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1454 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1455 | if (single_plane_enabled(enabled) && |
| 1456 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1457 | sr_latency_ns, |
| 1458 | &valleyview_wm_info, |
| 1459 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1460 | &plane_sr, &ignore_cursor_sr) && |
| 1461 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1462 | 2*sr_latency_ns, |
| 1463 | &valleyview_wm_info, |
| 1464 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1465 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1466 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1467 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1468 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1469 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1470 | plane_sr = cursor_sr = 0; |
| 1471 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1472 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1473 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1474 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1475 | planea_wm, cursora_wm, |
| 1476 | planeb_wm, cursorb_wm, |
| 1477 | plane_sr, cursor_sr); |
| 1478 | |
| 1479 | I915_WRITE(DSPFW1, |
| 1480 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1481 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1482 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1483 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1484 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1485 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1486 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1487 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1488 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1489 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1490 | |
| 1491 | if (cxsr_enabled) |
| 1492 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1493 | } |
| 1494 | |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1495 | static void cherryview_update_wm(struct drm_crtc *crtc) |
| 1496 | { |
| 1497 | struct drm_device *dev = crtc->dev; |
| 1498 | static const int sr_latency_ns = 12000; |
| 1499 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1500 | int planea_wm, planeb_wm, planec_wm; |
| 1501 | int cursora_wm, cursorb_wm, cursorc_wm; |
| 1502 | int plane_sr, cursor_sr; |
| 1503 | int ignore_plane_sr, ignore_cursor_sr; |
| 1504 | unsigned int enabled = 0; |
| 1505 | bool cxsr_enabled; |
| 1506 | |
| 1507 | vlv_update_drain_latency(crtc); |
| 1508 | |
| 1509 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1510 | &valleyview_wm_info, pessimal_latency_ns, |
| 1511 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1512 | &planea_wm, &cursora_wm)) |
| 1513 | enabled |= 1 << PIPE_A; |
| 1514 | |
| 1515 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1516 | &valleyview_wm_info, pessimal_latency_ns, |
| 1517 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1518 | &planeb_wm, &cursorb_wm)) |
| 1519 | enabled |= 1 << PIPE_B; |
| 1520 | |
| 1521 | if (g4x_compute_wm0(dev, PIPE_C, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1522 | &valleyview_wm_info, pessimal_latency_ns, |
| 1523 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1524 | &planec_wm, &cursorc_wm)) |
| 1525 | enabled |= 1 << PIPE_C; |
| 1526 | |
| 1527 | if (single_plane_enabled(enabled) && |
| 1528 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1529 | sr_latency_ns, |
| 1530 | &valleyview_wm_info, |
| 1531 | &valleyview_cursor_wm_info, |
| 1532 | &plane_sr, &ignore_cursor_sr) && |
| 1533 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1534 | 2*sr_latency_ns, |
| 1535 | &valleyview_wm_info, |
| 1536 | &valleyview_cursor_wm_info, |
| 1537 | &ignore_plane_sr, &cursor_sr)) { |
| 1538 | cxsr_enabled = true; |
| 1539 | } else { |
| 1540 | cxsr_enabled = false; |
| 1541 | intel_set_memory_cxsr(dev_priv, false); |
| 1542 | plane_sr = cursor_sr = 0; |
| 1543 | } |
| 1544 | |
| 1545 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1546 | "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, " |
| 1547 | "SR: plane=%d, cursor=%d\n", |
| 1548 | planea_wm, cursora_wm, |
| 1549 | planeb_wm, cursorb_wm, |
| 1550 | planec_wm, cursorc_wm, |
| 1551 | plane_sr, cursor_sr); |
| 1552 | |
| 1553 | I915_WRITE(DSPFW1, |
| 1554 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1555 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1556 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1557 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
| 1558 | I915_WRITE(DSPFW2, |
| 1559 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
| 1560 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1561 | I915_WRITE(DSPFW3, |
| 1562 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1563 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1564 | I915_WRITE(DSPFW9_CHV, |
| 1565 | (I915_READ(DSPFW9_CHV) & ~(DSPFW_PLANEC_MASK | |
| 1566 | DSPFW_CURSORC_MASK)) | |
| 1567 | (planec_wm << DSPFW_PLANEC_SHIFT) | |
| 1568 | (cursorc_wm << DSPFW_CURSORC_SHIFT)); |
| 1569 | |
| 1570 | if (cxsr_enabled) |
| 1571 | intel_set_memory_cxsr(dev_priv, true); |
| 1572 | } |
| 1573 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1574 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1575 | struct drm_crtc *crtc, |
| 1576 | uint32_t sprite_width, |
| 1577 | uint32_t sprite_height, |
| 1578 | int pixel_size, |
| 1579 | bool enabled, bool scaled) |
| 1580 | { |
| 1581 | struct drm_device *dev = crtc->dev; |
| 1582 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1583 | int pipe = to_intel_plane(plane)->pipe; |
| 1584 | int sprite = to_intel_plane(plane)->plane; |
| 1585 | int drain_latency; |
| 1586 | int plane_prec; |
| 1587 | int sprite_dl; |
| 1588 | int prec_mult; |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1589 | const int high_precision = IS_CHERRYVIEW(dev) ? |
| 1590 | DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_64; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1591 | |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1592 | sprite_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_SPRITE_PRECISION_HIGH(sprite) | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1593 | (DRAIN_LATENCY_MASK << DDL_SPRITE_SHIFT(sprite))); |
| 1594 | |
| 1595 | if (enabled && vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, |
| 1596 | &drain_latency)) { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1597 | plane_prec = (prec_mult == high_precision) ? |
| 1598 | DDL_SPRITE_PRECISION_HIGH(sprite) : |
| 1599 | DDL_SPRITE_PRECISION_LOW(sprite); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1600 | sprite_dl |= plane_prec | |
| 1601 | (drain_latency << DDL_SPRITE_SHIFT(sprite)); |
| 1602 | } |
| 1603 | |
| 1604 | I915_WRITE(VLV_DDL(pipe), sprite_dl); |
| 1605 | } |
| 1606 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1607 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1608 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1609 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1610 | static const int sr_latency_ns = 12000; |
| 1611 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1612 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1613 | int plane_sr, cursor_sr; |
| 1614 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1615 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1616 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1617 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1618 | &g4x_wm_info, pessimal_latency_ns, |
| 1619 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1620 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1621 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1622 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1623 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1624 | &g4x_wm_info, pessimal_latency_ns, |
| 1625 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1626 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1627 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1628 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1629 | if (single_plane_enabled(enabled) && |
| 1630 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1631 | sr_latency_ns, |
| 1632 | &g4x_wm_info, |
| 1633 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1634 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1635 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1636 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1637 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1638 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1639 | plane_sr = cursor_sr = 0; |
| 1640 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1641 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1642 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1643 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1644 | planea_wm, cursora_wm, |
| 1645 | planeb_wm, cursorb_wm, |
| 1646 | plane_sr, cursor_sr); |
| 1647 | |
| 1648 | I915_WRITE(DSPFW1, |
| 1649 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1650 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1651 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1652 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1653 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1654 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1655 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1656 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1657 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1658 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1659 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1660 | |
| 1661 | if (cxsr_enabled) |
| 1662 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1663 | } |
| 1664 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1665 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1666 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1667 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1668 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1669 | struct drm_crtc *crtc; |
| 1670 | int srwm = 1; |
| 1671 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1672 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1673 | |
| 1674 | /* Calc sr entries for one plane configs */ |
| 1675 | crtc = single_enabled_crtc(dev); |
| 1676 | if (crtc) { |
| 1677 | /* self-refresh has much higher latency */ |
| 1678 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1679 | const struct drm_display_mode *adjusted_mode = |
| 1680 | &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1681 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1682 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1683 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1684 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1685 | unsigned long line_time_us; |
| 1686 | int entries; |
| 1687 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1688 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1689 | |
| 1690 | /* Use ns/us then divide to preserve precision */ |
| 1691 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1692 | pixel_size * hdisplay; |
| 1693 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1694 | srwm = I965_FIFO_SIZE - entries; |
| 1695 | if (srwm < 0) |
| 1696 | srwm = 1; |
| 1697 | srwm &= 0x1ff; |
| 1698 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1699 | entries, srwm); |
| 1700 | |
| 1701 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1702 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1703 | entries = DIV_ROUND_UP(entries, |
| 1704 | i965_cursor_wm_info.cacheline_size); |
| 1705 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1706 | (entries + i965_cursor_wm_info.guard_size); |
| 1707 | |
| 1708 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1709 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1710 | |
| 1711 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1712 | "cursor %d\n", srwm, cursor_sr); |
| 1713 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1714 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1715 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1716 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1717 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1718 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1722 | srwm); |
| 1723 | |
| 1724 | /* 965 has limitations... */ |
| 1725 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1726 | (8 << DSPFW_CURSORB_SHIFT) | |
| 1727 | (8 << DSPFW_PLANEB_SHIFT) | |
| 1728 | (8 << DSPFW_PLANEA_SHIFT)); |
| 1729 | I915_WRITE(DSPFW2, (8 << DSPFW_CURSORA_SHIFT) | |
| 1730 | (8 << DSPFW_PLANEC_SHIFT_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1731 | /* update cursor SR watermark */ |
| 1732 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1733 | |
| 1734 | if (cxsr_enabled) |
| 1735 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1736 | } |
| 1737 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1738 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1739 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1740 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1741 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1742 | const struct intel_watermark_params *wm_info; |
| 1743 | uint32_t fwater_lo; |
| 1744 | uint32_t fwater_hi; |
| 1745 | int cwm, srwm = 1; |
| 1746 | int fifo_size; |
| 1747 | int planea_wm, planeb_wm; |
| 1748 | struct drm_crtc *crtc, *enabled = NULL; |
| 1749 | |
| 1750 | if (IS_I945GM(dev)) |
| 1751 | wm_info = &i945_wm_info; |
| 1752 | else if (!IS_GEN2(dev)) |
| 1753 | wm_info = &i915_wm_info; |
| 1754 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1755 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1756 | |
| 1757 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1758 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1759 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1760 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1761 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1762 | if (IS_GEN2(dev)) |
| 1763 | cpp = 4; |
| 1764 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1765 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1766 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1767 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1768 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1769 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1770 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1771 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1772 | if (planea_wm > (long)wm_info->max_wm) |
| 1773 | planea_wm = wm_info->max_wm; |
| 1774 | } |
| 1775 | |
| 1776 | if (IS_GEN2(dev)) |
| 1777 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1778 | |
| 1779 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1780 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1781 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1782 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1783 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1784 | if (IS_GEN2(dev)) |
| 1785 | cpp = 4; |
| 1786 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1787 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1788 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1789 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1790 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1791 | if (enabled == NULL) |
| 1792 | enabled = crtc; |
| 1793 | else |
| 1794 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1795 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1796 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1797 | if (planeb_wm > (long)wm_info->max_wm) |
| 1798 | planeb_wm = wm_info->max_wm; |
| 1799 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1800 | |
| 1801 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1802 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1803 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1804 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1805 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1806 | obj = intel_fb_obj(enabled->primary->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1807 | |
| 1808 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1809 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1810 | enabled = NULL; |
| 1811 | } |
| 1812 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1813 | /* |
| 1814 | * Overlay gets an aggressive default since video jitter is bad. |
| 1815 | */ |
| 1816 | cwm = 2; |
| 1817 | |
| 1818 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1819 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1820 | |
| 1821 | /* Calc sr entries for one plane configs */ |
| 1822 | if (HAS_FW_BLC(dev) && enabled) { |
| 1823 | /* self-refresh has much higher latency */ |
| 1824 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1825 | const struct drm_display_mode *adjusted_mode = |
| 1826 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1827 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1828 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1829 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1830 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1831 | unsigned long line_time_us; |
| 1832 | int entries; |
| 1833 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1834 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1835 | |
| 1836 | /* Use ns/us then divide to preserve precision */ |
| 1837 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1838 | pixel_size * hdisplay; |
| 1839 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1840 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1841 | srwm = wm_info->fifo_size - entries; |
| 1842 | if (srwm < 0) |
| 1843 | srwm = 1; |
| 1844 | |
| 1845 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1846 | I915_WRITE(FW_BLC_SELF, |
| 1847 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1848 | else if (IS_I915GM(dev)) |
| 1849 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1850 | } |
| 1851 | |
| 1852 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1853 | planea_wm, planeb_wm, cwm, srwm); |
| 1854 | |
| 1855 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1856 | fwater_hi = (cwm & 0x1f); |
| 1857 | |
| 1858 | /* Set request length to 8 cachelines per fetch */ |
| 1859 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1860 | fwater_hi = fwater_hi | (1 << 8); |
| 1861 | |
| 1862 | I915_WRITE(FW_BLC, fwater_lo); |
| 1863 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1864 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1865 | if (enabled) |
| 1866 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1867 | } |
| 1868 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1869 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1870 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1871 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1872 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1873 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1874 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1875 | uint32_t fwater_lo; |
| 1876 | int planea_wm; |
| 1877 | |
| 1878 | crtc = single_enabled_crtc(dev); |
| 1879 | if (crtc == NULL) |
| 1880 | return; |
| 1881 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1882 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1883 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1884 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1885 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1886 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1887 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1888 | fwater_lo |= (3<<8) | planea_wm; |
| 1889 | |
| 1890 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1891 | |
| 1892 | I915_WRITE(FW_BLC, fwater_lo); |
| 1893 | } |
| 1894 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1895 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1896 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1897 | { |
| 1898 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1899 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1900 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1901 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1902 | |
| 1903 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1904 | * adjust the pixel_rate here. */ |
| 1905 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1906 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1907 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1908 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1909 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1910 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1911 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1912 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1913 | pfit_h = pfit_size & 0xFFFF; |
| 1914 | if (pipe_w < pfit_w) |
| 1915 | pipe_w = pfit_w; |
| 1916 | if (pipe_h < pfit_h) |
| 1917 | pipe_h = pfit_h; |
| 1918 | |
| 1919 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1920 | pfit_w * pfit_h); |
| 1921 | } |
| 1922 | |
| 1923 | return pixel_rate; |
| 1924 | } |
| 1925 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1926 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1927 | 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] | 1928 | uint32_t latency) |
| 1929 | { |
| 1930 | uint64_t ret; |
| 1931 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1932 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1933 | return UINT_MAX; |
| 1934 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1935 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1936 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1937 | |
| 1938 | return ret; |
| 1939 | } |
| 1940 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1941 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1942 | 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] | 1943 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1944 | uint32_t latency) |
| 1945 | { |
| 1946 | uint32_t ret; |
| 1947 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1948 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1949 | return UINT_MAX; |
| 1950 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1951 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1952 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1953 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1954 | return ret; |
| 1955 | } |
| 1956 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1957 | 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] | 1958 | uint8_t bytes_per_pixel) |
| 1959 | { |
| 1960 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1961 | } |
| 1962 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1963 | struct skl_pipe_wm_parameters { |
| 1964 | bool active; |
| 1965 | uint32_t pipe_htotal; |
| 1966 | uint32_t pixel_rate; /* in KHz */ |
| 1967 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1968 | struct intel_plane_wm_parameters cursor; |
| 1969 | }; |
| 1970 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1971 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1972 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1973 | uint32_t pipe_htotal; |
| 1974 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1975 | struct intel_plane_wm_parameters pri; |
| 1976 | struct intel_plane_wm_parameters spr; |
| 1977 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1978 | }; |
| 1979 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1980 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1981 | uint16_t pri; |
| 1982 | uint16_t spr; |
| 1983 | uint16_t cur; |
| 1984 | uint16_t fbc; |
| 1985 | }; |
| 1986 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1987 | /* used in computing the new watermarks state */ |
| 1988 | struct intel_wm_config { |
| 1989 | unsigned int num_pipes_active; |
| 1990 | bool sprites_enabled; |
| 1991 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1992 | }; |
| 1993 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1994 | /* |
| 1995 | * For both WM_PIPE and WM_LP. |
| 1996 | * mem_value must be in 0.1us units. |
| 1997 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1998 | 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] | 1999 | uint32_t mem_value, |
| 2000 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2001 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2002 | uint32_t method1, method2; |
| 2003 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2004 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2005 | return 0; |
| 2006 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2007 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2008 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2009 | mem_value); |
| 2010 | |
| 2011 | if (!is_lp) |
| 2012 | return method1; |
| 2013 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2014 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2015 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2016 | params->pri.horiz_pixels, |
| 2017 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2018 | mem_value); |
| 2019 | |
| 2020 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2021 | } |
| 2022 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2023 | /* |
| 2024 | * For both WM_PIPE and WM_LP. |
| 2025 | * mem_value must be in 0.1us units. |
| 2026 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2027 | 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] | 2028 | uint32_t mem_value) |
| 2029 | { |
| 2030 | uint32_t method1, method2; |
| 2031 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2032 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2033 | return 0; |
| 2034 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2035 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2036 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2037 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2038 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2039 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2040 | params->spr.horiz_pixels, |
| 2041 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2042 | mem_value); |
| 2043 | return min(method1, method2); |
| 2044 | } |
| 2045 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2046 | /* |
| 2047 | * For both WM_PIPE and WM_LP. |
| 2048 | * mem_value must be in 0.1us units. |
| 2049 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2050 | 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] | 2051 | uint32_t mem_value) |
| 2052 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2053 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2054 | return 0; |
| 2055 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2056 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2057 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2058 | params->cur.horiz_pixels, |
| 2059 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2060 | mem_value); |
| 2061 | } |
| 2062 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2063 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2064 | 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] | 2065 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2066 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2067 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2068 | return 0; |
| 2069 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2070 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2071 | params->pri.horiz_pixels, |
| 2072 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2073 | } |
| 2074 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2075 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 2076 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2077 | if (INTEL_INFO(dev)->gen >= 8) |
| 2078 | return 3072; |
| 2079 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2080 | return 768; |
| 2081 | else |
| 2082 | return 512; |
| 2083 | } |
| 2084 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2085 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 2086 | int level, bool is_sprite) |
| 2087 | { |
| 2088 | if (INTEL_INFO(dev)->gen >= 8) |
| 2089 | /* BDW primary/sprite plane watermarks */ |
| 2090 | return level == 0 ? 255 : 2047; |
| 2091 | else if (INTEL_INFO(dev)->gen >= 7) |
| 2092 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2093 | return level == 0 ? 127 : 1023; |
| 2094 | else if (!is_sprite) |
| 2095 | /* ILK/SNB primary plane watermarks */ |
| 2096 | return level == 0 ? 127 : 511; |
| 2097 | else |
| 2098 | /* ILK/SNB sprite plane watermarks */ |
| 2099 | return level == 0 ? 63 : 255; |
| 2100 | } |
| 2101 | |
| 2102 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 2103 | int level) |
| 2104 | { |
| 2105 | if (INTEL_INFO(dev)->gen >= 7) |
| 2106 | return level == 0 ? 63 : 255; |
| 2107 | else |
| 2108 | return level == 0 ? 31 : 63; |
| 2109 | } |
| 2110 | |
| 2111 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 2112 | { |
| 2113 | if (INTEL_INFO(dev)->gen >= 8) |
| 2114 | return 31; |
| 2115 | else |
| 2116 | return 15; |
| 2117 | } |
| 2118 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2119 | /* Calculate the maximum primary/sprite plane watermark */ |
| 2120 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 2121 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2122 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2123 | enum intel_ddb_partitioning ddb_partitioning, |
| 2124 | bool is_sprite) |
| 2125 | { |
| 2126 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2127 | |
| 2128 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2129 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2130 | return 0; |
| 2131 | |
| 2132 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2133 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2134 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 2135 | |
| 2136 | /* |
| 2137 | * For some reason the non self refresh |
| 2138 | * FIFO size is only half of the self |
| 2139 | * refresh FIFO size on ILK/SNB. |
| 2140 | */ |
| 2141 | if (INTEL_INFO(dev)->gen <= 6) |
| 2142 | fifo_size /= 2; |
| 2143 | } |
| 2144 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2145 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2146 | /* level 0 is always calculated with 1:1 split */ |
| 2147 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2148 | if (is_sprite) |
| 2149 | fifo_size *= 5; |
| 2150 | fifo_size /= 6; |
| 2151 | } else { |
| 2152 | fifo_size /= 2; |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2157 | 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] | 2158 | } |
| 2159 | |
| 2160 | /* Calculate the maximum cursor plane watermark */ |
| 2161 | 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] | 2162 | int level, |
| 2163 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2164 | { |
| 2165 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2166 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2167 | return 64; |
| 2168 | |
| 2169 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2170 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2171 | } |
| 2172 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2173 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2174 | int level, |
| 2175 | const struct intel_wm_config *config, |
| 2176 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2177 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2178 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2179 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 2180 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 2181 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2182 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2183 | } |
| 2184 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2185 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 2186 | int level, |
| 2187 | struct ilk_wm_maximums *max) |
| 2188 | { |
| 2189 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 2190 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 2191 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 2192 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 2193 | } |
| 2194 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2195 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2196 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2197 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2198 | { |
| 2199 | bool ret; |
| 2200 | |
| 2201 | /* already determined to be invalid? */ |
| 2202 | if (!result->enable) |
| 2203 | return false; |
| 2204 | |
| 2205 | result->enable = result->pri_val <= max->pri && |
| 2206 | result->spr_val <= max->spr && |
| 2207 | result->cur_val <= max->cur; |
| 2208 | |
| 2209 | ret = result->enable; |
| 2210 | |
| 2211 | /* |
| 2212 | * HACK until we can pre-compute everything, |
| 2213 | * and thus fail gracefully if LP0 watermarks |
| 2214 | * are exceeded... |
| 2215 | */ |
| 2216 | if (level == 0 && !result->enable) { |
| 2217 | if (result->pri_val > max->pri) |
| 2218 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2219 | level, result->pri_val, max->pri); |
| 2220 | if (result->spr_val > max->spr) |
| 2221 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2222 | level, result->spr_val, max->spr); |
| 2223 | if (result->cur_val > max->cur) |
| 2224 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2225 | level, result->cur_val, max->cur); |
| 2226 | |
| 2227 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2228 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2229 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2230 | result->enable = true; |
| 2231 | } |
| 2232 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2233 | return ret; |
| 2234 | } |
| 2235 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2236 | 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] | 2237 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2238 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2239 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2240 | { |
| 2241 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2242 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2243 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2244 | |
| 2245 | /* WM1+ latency values stored in 0.5us units */ |
| 2246 | if (level > 0) { |
| 2247 | pri_latency *= 5; |
| 2248 | spr_latency *= 5; |
| 2249 | cur_latency *= 5; |
| 2250 | } |
| 2251 | |
| 2252 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 2253 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 2254 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 2255 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 2256 | result->enable = true; |
| 2257 | } |
| 2258 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2259 | static uint32_t |
| 2260 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2261 | { |
| 2262 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2263 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2264 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2265 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2266 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2267 | if (!intel_crtc_active(crtc)) |
| 2268 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2269 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2270 | /* The WM are computed with base on how long it takes to fill a single |
| 2271 | * row at the given clock rate, multiplied by 8. |
| 2272 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2273 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 2274 | mode->crtc_clock); |
| 2275 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2276 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2277 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2278 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2279 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2280 | } |
| 2281 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2282 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2283 | { |
| 2284 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2285 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2286 | if (IS_GEN9(dev)) { |
| 2287 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2288 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2289 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2290 | |
| 2291 | /* read the first set of memory latencies[0:3] */ |
| 2292 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 2293 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2294 | ret = sandybridge_pcode_read(dev_priv, |
| 2295 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2296 | &val); |
| 2297 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2298 | |
| 2299 | if (ret) { |
| 2300 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2301 | return; |
| 2302 | } |
| 2303 | |
| 2304 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2305 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2306 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2307 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2308 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2309 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2310 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2311 | |
| 2312 | /* read the second set of memory latencies[4:7] */ |
| 2313 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 2314 | mutex_lock(&dev_priv->rps.hw_lock); |
| 2315 | ret = sandybridge_pcode_read(dev_priv, |
| 2316 | GEN9_PCODE_READ_MEM_LATENCY, |
| 2317 | &val); |
| 2318 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 2319 | if (ret) { |
| 2320 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 2321 | return; |
| 2322 | } |
| 2323 | |
| 2324 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2325 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2326 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2327 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2328 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2329 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2330 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 2331 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2332 | /* |
| 2333 | * punit doesn't take into account the read latency so we need |
| 2334 | * to add 2us to the various latency levels we retrieve from |
| 2335 | * the punit. |
| 2336 | * - W0 is a bit special in that it's the only level that |
| 2337 | * can't be disabled if we want to have display working, so |
| 2338 | * we always add 2us there. |
| 2339 | * - For levels >=1, punit returns 0us latency when they are |
| 2340 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2341 | * |
| 2342 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 2343 | * levels m (m >= n) need to be disabled. We make sure to |
| 2344 | * sanitize the values out of the punit to satisfy this |
| 2345 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2346 | */ |
| 2347 | wm[0] += 2; |
| 2348 | for (level = 1; level <= max_level; level++) |
| 2349 | if (wm[level] != 0) |
| 2350 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2351 | else { |
| 2352 | for (i = level + 1; i <= max_level; i++) |
| 2353 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2354 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2357 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2358 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2359 | |
| 2360 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2361 | if (wm[0] == 0) |
| 2362 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2363 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2364 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2365 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2366 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2367 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2368 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2369 | |
| 2370 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2371 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2372 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2373 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2374 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2375 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2376 | |
| 2377 | /* ILK primary LP0 latency is 700 ns */ |
| 2378 | wm[0] = 7; |
| 2379 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2380 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2384 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2385 | { |
| 2386 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2387 | if (INTEL_INFO(dev)->gen == 5) |
| 2388 | wm[0] = 13; |
| 2389 | } |
| 2390 | |
| 2391 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2392 | { |
| 2393 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2394 | if (INTEL_INFO(dev)->gen == 5) |
| 2395 | wm[0] = 13; |
| 2396 | |
| 2397 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2398 | if (IS_IVYBRIDGE(dev)) |
| 2399 | wm[3] *= 2; |
| 2400 | } |
| 2401 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 2402 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2403 | { |
| 2404 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2405 | if (IS_GEN9(dev)) |
| 2406 | return 7; |
| 2407 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2408 | return 4; |
| 2409 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2410 | return 3; |
| 2411 | else |
| 2412 | return 2; |
| 2413 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 2414 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2415 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2416 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2417 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2418 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2419 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2420 | |
| 2421 | for (level = 0; level <= max_level; level++) { |
| 2422 | unsigned int latency = wm[level]; |
| 2423 | |
| 2424 | if (latency == 0) { |
| 2425 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2426 | name, level); |
| 2427 | continue; |
| 2428 | } |
| 2429 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2430 | /* |
| 2431 | * - latencies are in us on gen9. |
| 2432 | * - before then, WM1+ latency values are in 0.5us units |
| 2433 | */ |
| 2434 | if (IS_GEN9(dev)) |
| 2435 | latency *= 10; |
| 2436 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2437 | latency *= 5; |
| 2438 | |
| 2439 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2440 | name, level, wm[level], |
| 2441 | latency / 10, latency % 10); |
| 2442 | } |
| 2443 | } |
| 2444 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2445 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2446 | uint16_t wm[5], uint16_t min) |
| 2447 | { |
| 2448 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 2449 | |
| 2450 | if (wm[0] >= min) |
| 2451 | return false; |
| 2452 | |
| 2453 | wm[0] = max(wm[0], min); |
| 2454 | for (level = 1; level <= max_level; level++) |
| 2455 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2456 | |
| 2457 | return true; |
| 2458 | } |
| 2459 | |
| 2460 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2461 | { |
| 2462 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2463 | bool changed; |
| 2464 | |
| 2465 | /* |
| 2466 | * The BIOS provided WM memory latency values are often |
| 2467 | * inadequate for high resolution displays. Adjust them. |
| 2468 | */ |
| 2469 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2470 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2471 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2472 | |
| 2473 | if (!changed) |
| 2474 | return; |
| 2475 | |
| 2476 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2477 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2478 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2479 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2480 | } |
| 2481 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2482 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2483 | { |
| 2484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2485 | |
| 2486 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2487 | |
| 2488 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2489 | sizeof(dev_priv->wm.pri_latency)); |
| 2490 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2491 | sizeof(dev_priv->wm.pri_latency)); |
| 2492 | |
| 2493 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2494 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2495 | |
| 2496 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2497 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2498 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2499 | |
| 2500 | if (IS_GEN6(dev)) |
| 2501 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2502 | } |
| 2503 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2504 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 2505 | { |
| 2506 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2507 | |
| 2508 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 2509 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 2510 | } |
| 2511 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2512 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2513 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2514 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2515 | struct drm_device *dev = crtc->dev; |
| 2516 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2517 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2518 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2519 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2520 | if (!intel_crtc_active(crtc)) |
| 2521 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2522 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2523 | p->active = true; |
| 2524 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 2525 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 2526 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 2527 | p->cur.bytes_per_pixel = 4; |
| 2528 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
| 2529 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 2530 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2531 | p->pri.enabled = true; |
| 2532 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2533 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2534 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2535 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2536 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2537 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2538 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2539 | break; |
| 2540 | } |
| 2541 | } |
| 2542 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2543 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2544 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2545 | struct intel_wm_config *config) |
| 2546 | { |
| 2547 | struct intel_crtc *intel_crtc; |
| 2548 | |
| 2549 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2550 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2551 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2552 | |
| 2553 | if (!wm->pipe_enabled) |
| 2554 | continue; |
| 2555 | |
| 2556 | config->sprites_enabled |= wm->sprites_enabled; |
| 2557 | config->sprites_scaled |= wm->sprites_scaled; |
| 2558 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2559 | } |
| 2560 | } |
| 2561 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2562 | /* Compute new watermarks for the pipe */ |
| 2563 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2564 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2565 | struct intel_pipe_wm *pipe_wm) |
| 2566 | { |
| 2567 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2568 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2569 | int level, max_level = ilk_wm_max_level(dev); |
| 2570 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2571 | struct intel_wm_config config = { |
| 2572 | .num_pipes_active = 1, |
| 2573 | .sprites_enabled = params->spr.enabled, |
| 2574 | .sprites_scaled = params->spr.scaled, |
| 2575 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2576 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2577 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2578 | pipe_wm->pipe_enabled = params->active; |
| 2579 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2580 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2581 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2582 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2583 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2584 | max_level = 1; |
| 2585 | |
| 2586 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2587 | if (params->spr.scaled) |
| 2588 | max_level = 0; |
| 2589 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2590 | 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] | 2591 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2592 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2593 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2594 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2595 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2596 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2597 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2598 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2599 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2600 | return false; |
| 2601 | |
| 2602 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2603 | |
| 2604 | for (level = 1; level <= max_level; level++) { |
| 2605 | struct intel_wm_level wm = {}; |
| 2606 | |
| 2607 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2608 | |
| 2609 | /* |
| 2610 | * Disable any watermark level that exceeds the |
| 2611 | * register maximums since such watermarks are |
| 2612 | * always invalid. |
| 2613 | */ |
| 2614 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2615 | break; |
| 2616 | |
| 2617 | pipe_wm->wm[level] = wm; |
| 2618 | } |
| 2619 | |
| 2620 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | /* |
| 2624 | * Merge the watermarks from all active pipes for a specific level. |
| 2625 | */ |
| 2626 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2627 | int level, |
| 2628 | struct intel_wm_level *ret_wm) |
| 2629 | { |
| 2630 | const struct intel_crtc *intel_crtc; |
| 2631 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2632 | ret_wm->enable = true; |
| 2633 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2634 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2635 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2636 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2637 | |
| 2638 | if (!active->pipe_enabled) |
| 2639 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2640 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2641 | /* |
| 2642 | * The watermark values may have been used in the past, |
| 2643 | * so we must maintain them in the registers for some |
| 2644 | * time even if the level is now disabled. |
| 2645 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2646 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2647 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2648 | |
| 2649 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2650 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2651 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2652 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2653 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | /* |
| 2657 | * Merge all low power watermarks for all active pipes. |
| 2658 | */ |
| 2659 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2660 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2661 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2662 | struct intel_pipe_wm *merged) |
| 2663 | { |
| 2664 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2665 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2666 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2667 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2668 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2669 | config->num_pipes_active > 1) |
| 2670 | return; |
| 2671 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2672 | /* ILK: FBC WM must be disabled always */ |
| 2673 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2674 | |
| 2675 | /* merge each WM1+ level */ |
| 2676 | for (level = 1; level <= max_level; level++) { |
| 2677 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2678 | |
| 2679 | ilk_merge_wm_level(dev, level, wm); |
| 2680 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2681 | if (level > last_enabled_level) |
| 2682 | wm->enable = false; |
| 2683 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2684 | /* make sure all following levels get disabled */ |
| 2685 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2686 | |
| 2687 | /* |
| 2688 | * The spec says it is preferred to disable |
| 2689 | * FBC WMs instead of disabling a WM level. |
| 2690 | */ |
| 2691 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2692 | if (wm->enable) |
| 2693 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2694 | wm->fbc_val = 0; |
| 2695 | } |
| 2696 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2697 | |
| 2698 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2699 | /* |
| 2700 | * FIXME this is racy. FBC might get enabled later. |
| 2701 | * What we should check here is whether FBC can be |
| 2702 | * enabled sometime later. |
| 2703 | */ |
| 2704 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2705 | for (level = 2; level <= max_level; level++) { |
| 2706 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2707 | |
| 2708 | wm->enable = false; |
| 2709 | } |
| 2710 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2711 | } |
| 2712 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2713 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2714 | { |
| 2715 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2716 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2717 | } |
| 2718 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2719 | /* The value we need to program into the WM_LPx latency field */ |
| 2720 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2721 | { |
| 2722 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2723 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2724 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2725 | return 2 * level; |
| 2726 | else |
| 2727 | return dev_priv->wm.pri_latency[level]; |
| 2728 | } |
| 2729 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2730 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2731 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2732 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2733 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2734 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2735 | struct intel_crtc *intel_crtc; |
| 2736 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2737 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2738 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2739 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2740 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2741 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2742 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2743 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2744 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2745 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2746 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2747 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2748 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2749 | /* |
| 2750 | * Maintain the watermark values even if the level is |
| 2751 | * disabled. Doing otherwise could cause underruns. |
| 2752 | */ |
| 2753 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2754 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2755 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2756 | r->cur_val; |
| 2757 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2758 | if (r->enable) |
| 2759 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2760 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2761 | if (INTEL_INFO(dev)->gen >= 8) |
| 2762 | results->wm_lp[wm_lp - 1] |= |
| 2763 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2764 | else |
| 2765 | results->wm_lp[wm_lp - 1] |= |
| 2766 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2767 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2768 | /* |
| 2769 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2770 | * level is disabled. Doing otherwise could cause underruns. |
| 2771 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2772 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2773 | WARN_ON(wm_lp != 1); |
| 2774 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2775 | } else |
| 2776 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2777 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2778 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2779 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2780 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2781 | enum pipe pipe = intel_crtc->pipe; |
| 2782 | const struct intel_wm_level *r = |
| 2783 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2784 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2785 | if (WARN_ON(!r->enable)) |
| 2786 | continue; |
| 2787 | |
| 2788 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2789 | |
| 2790 | results->wm_pipe[pipe] = |
| 2791 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2792 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2793 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2797 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2798 | * 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] | 2799 | 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] | 2800 | struct intel_pipe_wm *r1, |
| 2801 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2802 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2803 | int level, max_level = ilk_wm_max_level(dev); |
| 2804 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2805 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2806 | for (level = 1; level <= max_level; level++) { |
| 2807 | if (r1->wm[level].enable) |
| 2808 | level1 = level; |
| 2809 | if (r2->wm[level].enable) |
| 2810 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2811 | } |
| 2812 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2813 | if (level1 == level2) { |
| 2814 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2815 | return r2; |
| 2816 | else |
| 2817 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2818 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2819 | return r1; |
| 2820 | } else { |
| 2821 | return r2; |
| 2822 | } |
| 2823 | } |
| 2824 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2825 | /* dirty bits used to track which watermarks need changes */ |
| 2826 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2827 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2828 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2829 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2830 | #define WM_DIRTY_FBC (1 << 24) |
| 2831 | #define WM_DIRTY_DDB (1 << 25) |
| 2832 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2833 | static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2834 | const struct ilk_wm_values *old, |
| 2835 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2836 | { |
| 2837 | unsigned int dirty = 0; |
| 2838 | enum pipe pipe; |
| 2839 | int wm_lp; |
| 2840 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2841 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2842 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2843 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2844 | /* Must disable LP1+ watermarks too */ |
| 2845 | dirty |= WM_DIRTY_LP_ALL; |
| 2846 | } |
| 2847 | |
| 2848 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2849 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2850 | /* Must disable LP1+ watermarks too */ |
| 2851 | dirty |= WM_DIRTY_LP_ALL; |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2856 | dirty |= WM_DIRTY_FBC; |
| 2857 | /* Must disable LP1+ watermarks too */ |
| 2858 | dirty |= WM_DIRTY_LP_ALL; |
| 2859 | } |
| 2860 | |
| 2861 | if (old->partitioning != new->partitioning) { |
| 2862 | dirty |= WM_DIRTY_DDB; |
| 2863 | /* Must disable LP1+ watermarks too */ |
| 2864 | dirty |= WM_DIRTY_LP_ALL; |
| 2865 | } |
| 2866 | |
| 2867 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2868 | if (dirty & WM_DIRTY_LP_ALL) |
| 2869 | return dirty; |
| 2870 | |
| 2871 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2872 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2873 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2874 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2875 | break; |
| 2876 | } |
| 2877 | |
| 2878 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2879 | for (; wm_lp <= 3; wm_lp++) |
| 2880 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2881 | |
| 2882 | return dirty; |
| 2883 | } |
| 2884 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2885 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2886 | unsigned int dirty) |
| 2887 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2888 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2889 | bool changed = false; |
| 2890 | |
| 2891 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2892 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2893 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2894 | changed = true; |
| 2895 | } |
| 2896 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2897 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2898 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2899 | changed = true; |
| 2900 | } |
| 2901 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2902 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2903 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2904 | changed = true; |
| 2905 | } |
| 2906 | |
| 2907 | /* |
| 2908 | * Don't touch WM1S_LP_EN here. |
| 2909 | * Doing so could cause underruns. |
| 2910 | */ |
| 2911 | |
| 2912 | return changed; |
| 2913 | } |
| 2914 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2915 | /* |
| 2916 | * The spec says we shouldn't write when we don't need, because every write |
| 2917 | * causes WMs to be re-evaluated, expending some power. |
| 2918 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2919 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2920 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2921 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2922 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2923 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2924 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2925 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2926 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2927 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2928 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2929 | return; |
| 2930 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2931 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2932 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2933 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2934 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2935 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2936 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2937 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2938 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2939 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2940 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2941 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2942 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2943 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2944 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2945 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2946 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2947 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2948 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2949 | val = I915_READ(WM_MISC); |
| 2950 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2951 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2952 | else |
| 2953 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2954 | I915_WRITE(WM_MISC, val); |
| 2955 | } else { |
| 2956 | val = I915_READ(DISP_ARB_CTL2); |
| 2957 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2958 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2959 | else |
| 2960 | val |= DISP_DATA_PARTITION_5_6; |
| 2961 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2962 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2963 | } |
| 2964 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2965 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2966 | val = I915_READ(DISP_ARB_CTL); |
| 2967 | if (results->enable_fbc_wm) |
| 2968 | val &= ~DISP_FBC_WM_DIS; |
| 2969 | else |
| 2970 | val |= DISP_FBC_WM_DIS; |
| 2971 | I915_WRITE(DISP_ARB_CTL, val); |
| 2972 | } |
| 2973 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2974 | if (dirty & WM_DIRTY_LP(1) && |
| 2975 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2976 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2977 | |
| 2978 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2979 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2980 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2981 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2982 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2983 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2984 | |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2985 | 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] | 2986 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2987 | 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] | 2988 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619 | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2989 | 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] | 2990 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2991 | |
| 2992 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2993 | } |
| 2994 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2995 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2996 | { |
| 2997 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2998 | |
| 2999 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3000 | } |
| 3001 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3002 | /* |
| 3003 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 3004 | * different active planes. |
| 3005 | */ |
| 3006 | |
| 3007 | #define SKL_DDB_SIZE 896 /* in blocks */ |
| 3008 | |
| 3009 | static void |
| 3010 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 3011 | struct drm_crtc *for_crtc, |
| 3012 | const struct intel_wm_config *config, |
| 3013 | const struct skl_pipe_wm_parameters *params, |
| 3014 | struct skl_ddb_entry *alloc /* out */) |
| 3015 | { |
| 3016 | struct drm_crtc *crtc; |
| 3017 | unsigned int pipe_size, ddb_size; |
| 3018 | int nth_active_pipe; |
| 3019 | |
| 3020 | if (!params->active) { |
| 3021 | alloc->start = 0; |
| 3022 | alloc->end = 0; |
| 3023 | return; |
| 3024 | } |
| 3025 | |
| 3026 | ddb_size = SKL_DDB_SIZE; |
| 3027 | |
| 3028 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 3029 | |
| 3030 | nth_active_pipe = 0; |
| 3031 | for_each_crtc(dev, crtc) { |
| 3032 | if (!intel_crtc_active(crtc)) |
| 3033 | continue; |
| 3034 | |
| 3035 | if (crtc == for_crtc) |
| 3036 | break; |
| 3037 | |
| 3038 | nth_active_pipe++; |
| 3039 | } |
| 3040 | |
| 3041 | pipe_size = ddb_size / config->num_pipes_active; |
| 3042 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3043 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 3047 | { |
| 3048 | if (config->num_pipes_active == 1) |
| 3049 | return 32; |
| 3050 | |
| 3051 | return 8; |
| 3052 | } |
| 3053 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3054 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 3055 | { |
| 3056 | entry->start = reg & 0x3ff; |
| 3057 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3058 | if (entry->end) |
| 3059 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 3062 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 3063 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3064 | { |
| 3065 | struct drm_device *dev = dev_priv->dev; |
| 3066 | enum pipe pipe; |
| 3067 | int plane; |
| 3068 | u32 val; |
| 3069 | |
| 3070 | for_each_pipe(dev_priv, pipe) { |
| 3071 | for_each_plane(pipe, plane) { |
| 3072 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 3073 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 3074 | val); |
| 3075 | } |
| 3076 | |
| 3077 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 3078 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 3079 | } |
| 3080 | } |
| 3081 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3082 | static unsigned int |
| 3083 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 3084 | { |
| 3085 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 3086 | } |
| 3087 | |
| 3088 | /* |
| 3089 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 3090 | * a 8192x4096@32bpp framebuffer: |
| 3091 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 3092 | */ |
| 3093 | static unsigned int |
| 3094 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 3095 | const struct skl_pipe_wm_parameters *params) |
| 3096 | { |
| 3097 | unsigned int total_data_rate = 0; |
| 3098 | int plane; |
| 3099 | |
| 3100 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 3101 | const struct intel_plane_wm_parameters *p; |
| 3102 | |
| 3103 | p = ¶ms->plane[plane]; |
| 3104 | if (!p->enabled) |
| 3105 | continue; |
| 3106 | |
| 3107 | total_data_rate += skl_plane_relative_data_rate(p); |
| 3108 | } |
| 3109 | |
| 3110 | return total_data_rate; |
| 3111 | } |
| 3112 | |
| 3113 | static void |
| 3114 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 3115 | const struct intel_wm_config *config, |
| 3116 | const struct skl_pipe_wm_parameters *params, |
| 3117 | struct skl_ddb_allocation *ddb /* out */) |
| 3118 | { |
| 3119 | struct drm_device *dev = crtc->dev; |
| 3120 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3121 | enum pipe pipe = intel_crtc->pipe; |
| 3122 | struct skl_ddb_entry alloc; |
| 3123 | uint16_t alloc_size, start, cursor_blocks; |
| 3124 | unsigned int total_data_rate; |
| 3125 | int plane; |
| 3126 | |
| 3127 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, &alloc); |
| 3128 | alloc_size = skl_ddb_entry_size(&alloc); |
| 3129 | if (alloc_size == 0) { |
| 3130 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 3131 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 3132 | return; |
| 3133 | } |
| 3134 | |
| 3135 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3136 | ddb->cursor[pipe].start = alloc.end - cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3137 | ddb->cursor[pipe].end = alloc.end; |
| 3138 | |
| 3139 | alloc_size -= cursor_blocks; |
| 3140 | alloc.end -= cursor_blocks; |
| 3141 | |
| 3142 | /* |
| 3143 | * Each active plane get a portion of the remaining space, in |
| 3144 | * proportion to the amount of data they need to fetch from memory. |
| 3145 | * |
| 3146 | * FIXME: we may not allocate every single block here. |
| 3147 | */ |
| 3148 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 3149 | |
| 3150 | start = alloc.start; |
| 3151 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 3152 | const struct intel_plane_wm_parameters *p; |
| 3153 | unsigned int data_rate; |
| 3154 | uint16_t plane_blocks; |
| 3155 | |
| 3156 | p = ¶ms->plane[plane]; |
| 3157 | if (!p->enabled) |
| 3158 | continue; |
| 3159 | |
| 3160 | data_rate = skl_plane_relative_data_rate(p); |
| 3161 | |
| 3162 | /* |
| 3163 | * promote the expression to 64 bits to avoid overflowing, the |
| 3164 | * result is < available as data_rate / total_data_rate < 1 |
| 3165 | */ |
| 3166 | plane_blocks = div_u64((uint64_t)alloc_size * data_rate, |
| 3167 | total_data_rate); |
| 3168 | |
| 3169 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3170 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3171 | |
| 3172 | start += plane_blocks; |
| 3173 | } |
| 3174 | |
| 3175 | } |
| 3176 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3177 | static uint32_t skl_pipe_pixel_rate(const struct intel_crtc_config *config) |
| 3178 | { |
| 3179 | /* TODO: Take into account the scalers once we support them */ |
| 3180 | return config->adjusted_mode.crtc_clock; |
| 3181 | } |
| 3182 | |
| 3183 | /* |
| 3184 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 3185 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 3186 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 3187 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 3188 | */ |
| 3189 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 3190 | uint32_t latency) |
| 3191 | { |
| 3192 | uint32_t wm_intermediate_val, ret; |
| 3193 | |
| 3194 | if (latency == 0) |
| 3195 | return UINT_MAX; |
| 3196 | |
| 3197 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel; |
| 3198 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 3199 | |
| 3200 | return ret; |
| 3201 | } |
| 3202 | |
| 3203 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 3204 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 3205 | uint32_t latency) |
| 3206 | { |
| 3207 | uint32_t ret, plane_bytes_per_line, wm_intermediate_val; |
| 3208 | |
| 3209 | if (latency == 0) |
| 3210 | return UINT_MAX; |
| 3211 | |
| 3212 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
| 3213 | wm_intermediate_val = latency * pixel_rate; |
| 3214 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
| 3215 | plane_bytes_per_line; |
| 3216 | |
| 3217 | return ret; |
| 3218 | } |
| 3219 | |
| 3220 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 3221 | struct skl_pipe_wm_parameters *params, |
| 3222 | struct skl_pipe_wm *pipe_wm) |
| 3223 | { |
| 3224 | /* |
| 3225 | * For now it is suggested to use the LP0 wm val of corresponding |
| 3226 | * plane as transition wm val. This is done while computing results. |
| 3227 | */ |
| 3228 | if (!params->active) |
| 3229 | return; |
| 3230 | } |
| 3231 | |
| 3232 | static uint32_t |
| 3233 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 3234 | { |
| 3235 | if (!intel_crtc_active(crtc)) |
| 3236 | return 0; |
| 3237 | |
| 3238 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 3239 | |
| 3240 | } |
| 3241 | |
| 3242 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 3243 | const struct intel_crtc *intel_crtc) |
| 3244 | { |
| 3245 | struct drm_device *dev = intel_crtc->base.dev; |
| 3246 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3247 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 3248 | enum pipe pipe = intel_crtc->pipe; |
| 3249 | |
| 3250 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 3251 | sizeof(new_ddb->plane[pipe]))) |
| 3252 | return true; |
| 3253 | |
| 3254 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 3255 | sizeof(new_ddb->cursor[pipe]))) |
| 3256 | return true; |
| 3257 | |
| 3258 | return false; |
| 3259 | } |
| 3260 | |
| 3261 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 3262 | struct intel_wm_config *config) |
| 3263 | { |
| 3264 | struct drm_crtc *crtc; |
| 3265 | struct drm_plane *plane; |
| 3266 | |
| 3267 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3268 | config->num_pipes_active += intel_crtc_active(crtc); |
| 3269 | |
| 3270 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 3271 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 3272 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 3273 | |
| 3274 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 3275 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 3280 | struct skl_pipe_wm_parameters *p) |
| 3281 | { |
| 3282 | struct drm_device *dev = crtc->dev; |
| 3283 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3284 | enum pipe pipe = intel_crtc->pipe; |
| 3285 | struct drm_plane *plane; |
| 3286 | int i = 1; /* Index for sprite planes start */ |
| 3287 | |
| 3288 | p->active = intel_crtc_active(crtc); |
| 3289 | if (p->active) { |
| 3290 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 3291 | p->pixel_rate = skl_pipe_pixel_rate(&intel_crtc->config); |
| 3292 | |
| 3293 | /* |
| 3294 | * For now, assume primary and cursor planes are always enabled. |
| 3295 | */ |
| 3296 | p->plane[0].enabled = true; |
| 3297 | p->plane[0].bytes_per_pixel = |
| 3298 | crtc->primary->fb->bits_per_pixel / 8; |
| 3299 | p->plane[0].horiz_pixels = intel_crtc->config.pipe_src_w; |
| 3300 | p->plane[0].vert_pixels = intel_crtc->config.pipe_src_h; |
| 3301 | |
| 3302 | p->cursor.enabled = true; |
| 3303 | p->cursor.bytes_per_pixel = 4; |
| 3304 | p->cursor.horiz_pixels = intel_crtc->cursor_width ? |
| 3305 | intel_crtc->cursor_width : 64; |
| 3306 | } |
| 3307 | |
| 3308 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 3309 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 3310 | |
| 3311 | if (intel_plane->pipe == pipe) |
| 3312 | p->plane[i++] = intel_plane->wm; |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | static bool skl_compute_plane_wm(struct skl_pipe_wm_parameters *p, |
| 3317 | struct intel_plane_wm_parameters *p_params, |
| 3318 | uint16_t max_page_buff_alloc, |
| 3319 | uint32_t mem_value, |
| 3320 | uint16_t *res_blocks, /* out */ |
| 3321 | uint8_t *res_lines /* out */) |
| 3322 | { |
| 3323 | uint32_t method1, method2, plane_bytes_per_line; |
| 3324 | uint32_t result_bytes; |
| 3325 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 3326 | if (mem_value == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3327 | return false; |
| 3328 | |
| 3329 | method1 = skl_wm_method1(p->pixel_rate, |
| 3330 | p_params->bytes_per_pixel, |
| 3331 | mem_value); |
| 3332 | method2 = skl_wm_method2(p->pixel_rate, |
| 3333 | p->pipe_htotal, |
| 3334 | p_params->horiz_pixels, |
| 3335 | p_params->bytes_per_pixel, |
| 3336 | mem_value); |
| 3337 | |
| 3338 | plane_bytes_per_line = p_params->horiz_pixels * |
| 3339 | p_params->bytes_per_pixel; |
| 3340 | |
| 3341 | /* For now xtile and linear */ |
| 3342 | if (((max_page_buff_alloc * 512) / plane_bytes_per_line) >= 1) |
| 3343 | result_bytes = min(method1, method2); |
| 3344 | else |
| 3345 | result_bytes = method1; |
| 3346 | |
| 3347 | *res_blocks = DIV_ROUND_UP(result_bytes, 512) + 1; |
| 3348 | *res_lines = DIV_ROUND_UP(result_bytes, plane_bytes_per_line); |
| 3349 | |
| 3350 | return true; |
| 3351 | } |
| 3352 | |
| 3353 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 3354 | struct skl_ddb_allocation *ddb, |
| 3355 | struct skl_pipe_wm_parameters *p, |
| 3356 | enum pipe pipe, |
| 3357 | int level, |
| 3358 | int num_planes, |
| 3359 | struct skl_wm_level *result) |
| 3360 | { |
| 3361 | uint16_t latency = dev_priv->wm.skl_latency[level]; |
| 3362 | uint16_t ddb_blocks; |
| 3363 | int i; |
| 3364 | |
| 3365 | for (i = 0; i < num_planes; i++) { |
| 3366 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 3367 | |
| 3368 | result->plane_en[i] = skl_compute_plane_wm(p, &p->plane[i], |
| 3369 | ddb_blocks, |
| 3370 | latency, |
| 3371 | &result->plane_res_b[i], |
| 3372 | &result->plane_res_l[i]); |
| 3373 | } |
| 3374 | |
| 3375 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
| 3376 | result->cursor_en = skl_compute_plane_wm(p, &p->cursor, ddb_blocks, |
| 3377 | latency, &result->cursor_res_b, |
| 3378 | &result->cursor_res_l); |
| 3379 | } |
| 3380 | |
| 3381 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 3382 | struct skl_ddb_allocation *ddb, |
| 3383 | struct skl_pipe_wm_parameters *params, |
| 3384 | struct skl_pipe_wm *pipe_wm) |
| 3385 | { |
| 3386 | struct drm_device *dev = crtc->dev; |
| 3387 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 3388 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3389 | int level, max_level = ilk_wm_max_level(dev); |
| 3390 | |
| 3391 | for (level = 0; level <= max_level; level++) { |
| 3392 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 3393 | level, intel_num_planes(intel_crtc), |
| 3394 | &pipe_wm->wm[level]); |
| 3395 | } |
| 3396 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 3397 | |
| 3398 | skl_compute_transition_wm(crtc, params, pipe_wm); |
| 3399 | } |
| 3400 | |
| 3401 | static void skl_compute_wm_results(struct drm_device *dev, |
| 3402 | struct skl_pipe_wm_parameters *p, |
| 3403 | struct skl_pipe_wm *p_wm, |
| 3404 | struct skl_wm_values *r, |
| 3405 | struct intel_crtc *intel_crtc) |
| 3406 | { |
| 3407 | int level, max_level = ilk_wm_max_level(dev); |
| 3408 | enum pipe pipe = intel_crtc->pipe; |
| 3409 | |
| 3410 | for (level = 0; level <= max_level; level++) { |
| 3411 | uint16_t ddb_blocks; |
| 3412 | uint32_t temp; |
| 3413 | int i; |
| 3414 | |
| 3415 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3416 | temp = 0; |
| 3417 | ddb_blocks = skl_ddb_entry_size(&r->ddb.plane[pipe][i]); |
| 3418 | |
| 3419 | if ((p_wm->wm[level].plane_res_b[i] > ddb_blocks) || |
| 3420 | (p_wm->wm[level].plane_res_l[i] > 31)) |
| 3421 | p_wm->wm[level].plane_en[i] = false; |
| 3422 | |
| 3423 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 3424 | PLANE_WM_LINES_SHIFT; |
| 3425 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 3426 | if (p_wm->wm[level].plane_en[i]) |
| 3427 | temp |= PLANE_WM_EN; |
| 3428 | |
| 3429 | r->plane[pipe][i][level] = temp; |
| 3430 | /* Use the LP0 WM value for transition WM for now. */ |
| 3431 | if (level == 0) |
| 3432 | r->plane_trans[pipe][i] = temp; |
| 3433 | } |
| 3434 | |
| 3435 | temp = 0; |
| 3436 | ddb_blocks = skl_ddb_entry_size(&r->ddb.cursor[pipe]); |
| 3437 | |
| 3438 | if ((p_wm->wm[level].cursor_res_b > ddb_blocks) || |
| 3439 | (p_wm->wm[level].cursor_res_l > 31)) |
| 3440 | p_wm->wm[level].cursor_en = false; |
| 3441 | |
| 3442 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3443 | temp |= p_wm->wm[level].cursor_res_b; |
| 3444 | |
| 3445 | if (p_wm->wm[level].cursor_en) |
| 3446 | temp |= PLANE_WM_EN; |
| 3447 | |
| 3448 | r->cursor[pipe][level] = temp; |
| 3449 | /* Use the LP0 WM value for transition WM for now. */ |
| 3450 | if (level == 0) |
| 3451 | r->cursor_trans[pipe] = temp; |
| 3452 | |
| 3453 | } |
| 3454 | |
| 3455 | r->wm_linetime[pipe] = p_wm->linetime; |
| 3456 | } |
| 3457 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3458 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 3459 | const struct skl_ddb_entry *entry) |
| 3460 | { |
| 3461 | if (entry->end) |
| 3462 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 3463 | else |
| 3464 | I915_WRITE(reg, 0); |
| 3465 | } |
| 3466 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3467 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 3468 | const struct skl_wm_values *new) |
| 3469 | { |
| 3470 | struct drm_device *dev = dev_priv->dev; |
| 3471 | struct intel_crtc *crtc; |
| 3472 | |
| 3473 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 3474 | int i, level, max_level = ilk_wm_max_level(dev); |
| 3475 | enum pipe pipe = crtc->pipe; |
| 3476 | |
| 3477 | if (new->dirty[pipe]) { |
| 3478 | I915_WRITE(PIPE_WM_LINETIME(pipe), |
| 3479 | new->wm_linetime[pipe]); |
| 3480 | |
| 3481 | for (level = 0; level <= max_level; level++) { |
| 3482 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3483 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 3484 | new->plane[pipe][i][level]); |
| 3485 | I915_WRITE(CUR_WM(pipe, level), |
| 3486 | new->cursor[pipe][level]); |
| 3487 | } |
| 3488 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3489 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 3490 | new->plane_trans[pipe][i]); |
| 3491 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
Damien Lespiau | 8211bd5 | 2014-11-04 17:06:44 +0000 | [diff] [blame] | 3492 | |
| 3493 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3494 | skl_ddb_entry_write(dev_priv, |
| 3495 | PLANE_BUF_CFG(pipe, i), |
| 3496 | &new->ddb.plane[pipe][i]); |
Damien Lespiau | 8211bd5 | 2014-11-04 17:06:44 +0000 | [diff] [blame] | 3497 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame^] | 3498 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 3499 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3500 | } |
| 3501 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3505 | struct skl_pipe_wm_parameters *params, |
| 3506 | struct intel_wm_config *config, |
| 3507 | struct skl_ddb_allocation *ddb, /* out */ |
| 3508 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3509 | { |
| 3510 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3511 | |
| 3512 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3513 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3514 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3515 | |
| 3516 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3517 | return false; |
| 3518 | |
| 3519 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3520 | return true; |
| 3521 | } |
| 3522 | |
| 3523 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3524 | struct drm_crtc *crtc, |
| 3525 | struct intel_wm_config *config, |
| 3526 | struct skl_wm_values *r) |
| 3527 | { |
| 3528 | struct intel_crtc *intel_crtc; |
| 3529 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3530 | |
| 3531 | /* |
| 3532 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3533 | * crtc we are currently computing the new WM values for), other |
| 3534 | * enabled crtcs will keep the same allocation and we don't need to |
| 3535 | * recompute anything for them. |
| 3536 | */ |
| 3537 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3538 | return; |
| 3539 | |
| 3540 | /* |
| 3541 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3542 | * other active pipes need new DDB allocation and WM values. |
| 3543 | */ |
| 3544 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3545 | base.head) { |
| 3546 | struct skl_pipe_wm_parameters params = {}; |
| 3547 | struct skl_pipe_wm pipe_wm = {}; |
| 3548 | bool wm_changed; |
| 3549 | |
| 3550 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3551 | continue; |
| 3552 | |
| 3553 | if (!intel_crtc->active) |
| 3554 | continue; |
| 3555 | |
| 3556 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3557 | ¶ms, config, |
| 3558 | &r->ddb, &pipe_wm); |
| 3559 | |
| 3560 | /* |
| 3561 | * If we end up re-computing the other pipe WM values, it's |
| 3562 | * because it was really needed, so we expect the WM values to |
| 3563 | * be different. |
| 3564 | */ |
| 3565 | WARN_ON(!wm_changed); |
| 3566 | |
| 3567 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3568 | r->dirty[intel_crtc->pipe] = true; |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3573 | { |
| 3574 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3575 | struct drm_device *dev = crtc->dev; |
| 3576 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3577 | struct skl_pipe_wm_parameters params = {}; |
| 3578 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3579 | struct skl_pipe_wm pipe_wm = {}; |
| 3580 | struct intel_wm_config config = {}; |
| 3581 | |
| 3582 | memset(results, 0, sizeof(*results)); |
| 3583 | |
| 3584 | skl_compute_wm_global_parameters(dev, &config); |
| 3585 | |
| 3586 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3587 | &results->ddb, &pipe_wm)) |
| 3588 | return; |
| 3589 | |
| 3590 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3591 | results->dirty[intel_crtc->pipe] = true; |
| 3592 | |
| 3593 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3594 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3595 | |
| 3596 | /* store the new configuration */ |
| 3597 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | static void |
| 3601 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3602 | uint32_t sprite_width, uint32_t sprite_height, |
| 3603 | int pixel_size, bool enabled, bool scaled) |
| 3604 | { |
| 3605 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 3606 | |
| 3607 | intel_plane->wm.enabled = enabled; |
| 3608 | intel_plane->wm.scaled = scaled; |
| 3609 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3610 | intel_plane->wm.vert_pixels = sprite_height; |
| 3611 | intel_plane->wm.bytes_per_pixel = pixel_size; |
| 3612 | |
| 3613 | skl_update_wm(crtc); |
| 3614 | } |
| 3615 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3616 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3617 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3618 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3619 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3620 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3621 | struct ilk_wm_maximums max; |
| 3622 | struct ilk_pipe_wm_parameters params = {}; |
| 3623 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3624 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3625 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3626 | 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] | 3627 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3628 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3629 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3630 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3631 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3632 | |
| 3633 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3634 | return; |
| 3635 | |
| 3636 | intel_crtc->wm.active = pipe_wm; |
| 3637 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3638 | ilk_compute_wm_config(dev, &config); |
| 3639 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3640 | 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] | 3641 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3642 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3643 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3644 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3645 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3646 | 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] | 3647 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3648 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3649 | 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] | 3650 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3651 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3652 | } |
| 3653 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3654 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3655 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3656 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3657 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3658 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3659 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3660 | } |
| 3661 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3662 | static void |
| 3663 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3664 | struct drm_crtc *crtc, |
| 3665 | uint32_t sprite_width, uint32_t sprite_height, |
| 3666 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3667 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3668 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3669 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3670 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3671 | intel_plane->wm.enabled = enabled; |
| 3672 | intel_plane->wm.scaled = scaled; |
| 3673 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3674 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3675 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3676 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3677 | /* |
| 3678 | * IVB workaround: must disable low power watermarks for at least |
| 3679 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3680 | * when scaling is disabled. |
| 3681 | * |
| 3682 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3683 | */ |
| 3684 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3685 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3686 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3687 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3688 | } |
| 3689 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3690 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3691 | struct skl_pipe_wm *active, |
| 3692 | bool is_transwm, |
| 3693 | bool is_cursor, |
| 3694 | int i, |
| 3695 | int level) |
| 3696 | { |
| 3697 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3698 | |
| 3699 | if (!is_transwm) { |
| 3700 | if (!is_cursor) { |
| 3701 | active->wm[level].plane_en[i] = is_enabled; |
| 3702 | active->wm[level].plane_res_b[i] = |
| 3703 | val & PLANE_WM_BLOCKS_MASK; |
| 3704 | active->wm[level].plane_res_l[i] = |
| 3705 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3706 | PLANE_WM_LINES_MASK; |
| 3707 | } else { |
| 3708 | active->wm[level].cursor_en = is_enabled; |
| 3709 | active->wm[level].cursor_res_b = |
| 3710 | val & PLANE_WM_BLOCKS_MASK; |
| 3711 | active->wm[level].cursor_res_l = |
| 3712 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3713 | PLANE_WM_LINES_MASK; |
| 3714 | } |
| 3715 | } else { |
| 3716 | if (!is_cursor) { |
| 3717 | active->trans_wm.plane_en[i] = is_enabled; |
| 3718 | active->trans_wm.plane_res_b[i] = |
| 3719 | val & PLANE_WM_BLOCKS_MASK; |
| 3720 | active->trans_wm.plane_res_l[i] = |
| 3721 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3722 | PLANE_WM_LINES_MASK; |
| 3723 | } else { |
| 3724 | active->trans_wm.cursor_en = is_enabled; |
| 3725 | active->trans_wm.cursor_res_b = |
| 3726 | val & PLANE_WM_BLOCKS_MASK; |
| 3727 | active->trans_wm.cursor_res_l = |
| 3728 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3729 | PLANE_WM_LINES_MASK; |
| 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | |
| 3734 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3735 | { |
| 3736 | struct drm_device *dev = crtc->dev; |
| 3737 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3738 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3739 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3740 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3741 | enum pipe pipe = intel_crtc->pipe; |
| 3742 | int level, i, max_level; |
| 3743 | uint32_t temp; |
| 3744 | |
| 3745 | max_level = ilk_wm_max_level(dev); |
| 3746 | |
| 3747 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3748 | |
| 3749 | for (level = 0; level <= max_level; level++) { |
| 3750 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3751 | hw->plane[pipe][i][level] = |
| 3752 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3753 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3754 | } |
| 3755 | |
| 3756 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3757 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3758 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3759 | |
| 3760 | if (!intel_crtc_active(crtc)) |
| 3761 | return; |
| 3762 | |
| 3763 | hw->dirty[pipe] = true; |
| 3764 | |
| 3765 | active->linetime = hw->wm_linetime[pipe]; |
| 3766 | |
| 3767 | for (level = 0; level <= max_level; level++) { |
| 3768 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3769 | temp = hw->plane[pipe][i][level]; |
| 3770 | skl_pipe_wm_active_state(temp, active, false, |
| 3771 | false, i, level); |
| 3772 | } |
| 3773 | temp = hw->cursor[pipe][level]; |
| 3774 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3775 | } |
| 3776 | |
| 3777 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3778 | temp = hw->plane_trans[pipe][i]; |
| 3779 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3780 | } |
| 3781 | |
| 3782 | temp = hw->cursor_trans[pipe]; |
| 3783 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3784 | } |
| 3785 | |
| 3786 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3787 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3788 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3789 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3790 | struct drm_crtc *crtc; |
| 3791 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3792 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3793 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3794 | skl_pipe_wm_get_hw_state(crtc); |
| 3795 | } |
| 3796 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3797 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3798 | { |
| 3799 | struct drm_device *dev = crtc->dev; |
| 3800 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3801 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3802 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3803 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3804 | enum pipe pipe = intel_crtc->pipe; |
| 3805 | static const unsigned int wm0_pipe_reg[] = { |
| 3806 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3807 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3808 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3809 | }; |
| 3810 | |
| 3811 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3812 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3813 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3814 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3815 | active->pipe_enabled = intel_crtc_active(crtc); |
| 3816 | |
| 3817 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3818 | u32 tmp = hw->wm_pipe[pipe]; |
| 3819 | |
| 3820 | /* |
| 3821 | * For active pipes LP0 watermark is marked as |
| 3822 | * enabled, and LP1+ watermaks as disabled since |
| 3823 | * we can't really reverse compute them in case |
| 3824 | * multiple pipes are active. |
| 3825 | */ |
| 3826 | active->wm[0].enable = true; |
| 3827 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3828 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3829 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3830 | active->linetime = hw->wm_linetime[pipe]; |
| 3831 | } else { |
| 3832 | int level, max_level = ilk_wm_max_level(dev); |
| 3833 | |
| 3834 | /* |
| 3835 | * For inactive pipes, all watermark levels |
| 3836 | * should be marked as enabled but zeroed, |
| 3837 | * which is what we'd compute them to. |
| 3838 | */ |
| 3839 | for (level = 0; level <= max_level; level++) |
| 3840 | active->wm[level].enable = true; |
| 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3845 | { |
| 3846 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3847 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3848 | struct drm_crtc *crtc; |
| 3849 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3850 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3851 | ilk_pipe_wm_get_hw_state(crtc); |
| 3852 | |
| 3853 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3854 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3855 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3856 | |
| 3857 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3858 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3859 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3860 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3861 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3862 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3863 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3864 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3865 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3866 | else if (IS_IVYBRIDGE(dev)) |
| 3867 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3868 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3869 | |
| 3870 | hw->enable_fbc_wm = |
| 3871 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3872 | } |
| 3873 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3874 | /** |
| 3875 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3876 | * |
| 3877 | * Calculate watermark values for the various WM regs based on current mode |
| 3878 | * and plane configuration. |
| 3879 | * |
| 3880 | * There are several cases to deal with here: |
| 3881 | * - normal (i.e. non-self-refresh) |
| 3882 | * - self-refresh (SR) mode |
| 3883 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3884 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3885 | * lines), so need to account for TLB latency |
| 3886 | * |
| 3887 | * The normal calculation is: |
| 3888 | * watermark = dotclock * bytes per pixel * latency |
| 3889 | * where latency is platform & configuration dependent (we assume pessimal |
| 3890 | * values here). |
| 3891 | * |
| 3892 | * The SR calculation is: |
| 3893 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3894 | * bytes per pixel |
| 3895 | * where |
| 3896 | * line time = htotal / dotclock |
| 3897 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3898 | * and latency is assumed to be high, as above. |
| 3899 | * |
| 3900 | * The final value programmed to the register should always be rounded up, |
| 3901 | * and include an extra 2 entries to account for clock crossings. |
| 3902 | * |
| 3903 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3904 | * to set the non-SR watermarks to 8. |
| 3905 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3906 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3907 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3908 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3909 | |
| 3910 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3911 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3912 | } |
| 3913 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3914 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3915 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3916 | uint32_t sprite_width, |
| 3917 | uint32_t sprite_height, |
| 3918 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3919 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3920 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3921 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3922 | |
| 3923 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3924 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3925 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3926 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3927 | } |
| 3928 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3929 | static struct drm_i915_gem_object * |
| 3930 | intel_alloc_context_page(struct drm_device *dev) |
| 3931 | { |
| 3932 | struct drm_i915_gem_object *ctx; |
| 3933 | int ret; |
| 3934 | |
| 3935 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3936 | |
| 3937 | ctx = i915_gem_alloc_object(dev, 4096); |
| 3938 | if (!ctx) { |
| 3939 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 3940 | return NULL; |
| 3941 | } |
| 3942 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 3943 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3944 | if (ret) { |
| 3945 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 3946 | goto err_unref; |
| 3947 | } |
| 3948 | |
| 3949 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 3950 | if (ret) { |
| 3951 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 3952 | goto err_unpin; |
| 3953 | } |
| 3954 | |
| 3955 | return ctx; |
| 3956 | |
| 3957 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3958 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3959 | err_unref: |
| 3960 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3961 | return NULL; |
| 3962 | } |
| 3963 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3964 | /** |
| 3965 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3966 | */ |
| 3967 | DEFINE_SPINLOCK(mchdev_lock); |
| 3968 | |
| 3969 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3970 | * mchdev_lock. */ |
| 3971 | static struct drm_i915_private *i915_mch_dev; |
| 3972 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3973 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3974 | { |
| 3975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3976 | u16 rgvswctl; |
| 3977 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3978 | assert_spin_locked(&mchdev_lock); |
| 3979 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3980 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3981 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3982 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3983 | return false; /* still busy with another command */ |
| 3984 | } |
| 3985 | |
| 3986 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3987 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3988 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3989 | POSTING_READ16(MEMSWCTL); |
| 3990 | |
| 3991 | rgvswctl |= MEMCTL_CMD_STS; |
| 3992 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3993 | |
| 3994 | return true; |
| 3995 | } |
| 3996 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3997 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3998 | { |
| 3999 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4000 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 4001 | u8 fmax, fmin, fstart, vstart; |
| 4002 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4003 | spin_lock_irq(&mchdev_lock); |
| 4004 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4005 | /* Enable temp reporting */ |
| 4006 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 4007 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 4008 | |
| 4009 | /* 100ms RC evaluation intervals */ |
| 4010 | I915_WRITE(RCUPEI, 100000); |
| 4011 | I915_WRITE(RCDNEI, 100000); |
| 4012 | |
| 4013 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 4014 | I915_WRITE(RCBMAXAVG, 90000); |
| 4015 | I915_WRITE(RCBMINAVG, 80000); |
| 4016 | |
| 4017 | I915_WRITE(MEMIHYST, 1); |
| 4018 | |
| 4019 | /* Set up min, max, and cur for interrupt handling */ |
| 4020 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 4021 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 4022 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 4023 | MEMMODE_FSTART_SHIFT; |
| 4024 | |
| 4025 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 4026 | PXVFREQ_PX_SHIFT; |
| 4027 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4028 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 4029 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4030 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4031 | dev_priv->ips.max_delay = fstart; |
| 4032 | dev_priv->ips.min_delay = fmin; |
| 4033 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4034 | |
| 4035 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 4036 | fmax, fmin, fstart); |
| 4037 | |
| 4038 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 4039 | |
| 4040 | /* |
| 4041 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 4042 | */ |
| 4043 | |
| 4044 | I915_WRITE(VIDSTART, vstart); |
| 4045 | POSTING_READ(VIDSTART); |
| 4046 | |
| 4047 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 4048 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 4049 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4050 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4051 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4052 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4053 | |
| 4054 | ironlake_set_drps(dev, fstart); |
| 4055 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4056 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4057 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4058 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 4059 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 4060 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4061 | |
| 4062 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4063 | } |
| 4064 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 4065 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4066 | { |
| 4067 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4068 | u16 rgvswctl; |
| 4069 | |
| 4070 | spin_lock_irq(&mchdev_lock); |
| 4071 | |
| 4072 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4073 | |
| 4074 | /* Ack interrupts, disable EFC interrupt */ |
| 4075 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 4076 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 4077 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 4078 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 4079 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 4080 | |
| 4081 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4082 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4083 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4084 | rgvswctl |= MEMCTL_CMD_STS; |
| 4085 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4086 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4087 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 4088 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4089 | } |
| 4090 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 4091 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 4092 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 4093 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 4094 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 4095 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 4096 | 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] | 4097 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4098 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4099 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 4100 | /* Only set the down limit when we've reached the lowest level to avoid |
| 4101 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 4102 | * race in the hw when coming out of rc6: There's a tiny window where |
| 4103 | * the hw runs at the minimal clock before selecting the desired |
| 4104 | * frequency, if the down threshold expires in that window we will not |
| 4105 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4106 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 4107 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 4108 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 4109 | |
| 4110 | return limits; |
| 4111 | } |
| 4112 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4113 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 4114 | { |
| 4115 | int new_power; |
| 4116 | |
| 4117 | new_power = dev_priv->rps.power; |
| 4118 | switch (dev_priv->rps.power) { |
| 4119 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4120 | 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] | 4121 | new_power = BETWEEN; |
| 4122 | break; |
| 4123 | |
| 4124 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4125 | 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] | 4126 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4127 | 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] | 4128 | new_power = HIGH_POWER; |
| 4129 | break; |
| 4130 | |
| 4131 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4132 | 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] | 4133 | new_power = BETWEEN; |
| 4134 | break; |
| 4135 | } |
| 4136 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4137 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4138 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4139 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4140 | new_power = HIGH_POWER; |
| 4141 | if (new_power == dev_priv->rps.power) |
| 4142 | return; |
| 4143 | |
| 4144 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 4145 | switch (new_power) { |
| 4146 | case LOW_POWER: |
| 4147 | /* Upclock if more than 95% busy over 16ms */ |
| 4148 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 4149 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 4150 | |
| 4151 | /* Downclock if less than 85% busy over 32ms */ |
| 4152 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 4153 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 4154 | |
| 4155 | I915_WRITE(GEN6_RP_CONTROL, |
| 4156 | GEN6_RP_MEDIA_TURBO | |
| 4157 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4158 | GEN6_RP_MEDIA_IS_GFX | |
| 4159 | GEN6_RP_ENABLE | |
| 4160 | GEN6_RP_UP_BUSY_AVG | |
| 4161 | GEN6_RP_DOWN_IDLE_AVG); |
| 4162 | break; |
| 4163 | |
| 4164 | case BETWEEN: |
| 4165 | /* Upclock if more than 90% busy over 13ms */ |
| 4166 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 4167 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 4168 | |
| 4169 | /* Downclock if less than 75% busy over 32ms */ |
| 4170 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 4171 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 4172 | |
| 4173 | I915_WRITE(GEN6_RP_CONTROL, |
| 4174 | GEN6_RP_MEDIA_TURBO | |
| 4175 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4176 | GEN6_RP_MEDIA_IS_GFX | |
| 4177 | GEN6_RP_ENABLE | |
| 4178 | GEN6_RP_UP_BUSY_AVG | |
| 4179 | GEN6_RP_DOWN_IDLE_AVG); |
| 4180 | break; |
| 4181 | |
| 4182 | case HIGH_POWER: |
| 4183 | /* Upclock if more than 85% busy over 10ms */ |
| 4184 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 4185 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 4186 | |
| 4187 | /* Downclock if less than 60% busy over 32ms */ |
| 4188 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 4189 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 4190 | |
| 4191 | I915_WRITE(GEN6_RP_CONTROL, |
| 4192 | GEN6_RP_MEDIA_TURBO | |
| 4193 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4194 | GEN6_RP_MEDIA_IS_GFX | |
| 4195 | GEN6_RP_ENABLE | |
| 4196 | GEN6_RP_UP_BUSY_AVG | |
| 4197 | GEN6_RP_DOWN_IDLE_AVG); |
| 4198 | break; |
| 4199 | } |
| 4200 | |
| 4201 | dev_priv->rps.power = new_power; |
| 4202 | dev_priv->rps.last_adj = 0; |
| 4203 | } |
| 4204 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4205 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 4206 | { |
| 4207 | u32 mask = 0; |
| 4208 | |
| 4209 | if (val > dev_priv->rps.min_freq_softlimit) |
| 4210 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 4211 | if (val < dev_priv->rps.max_freq_softlimit) |
| 4212 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 4213 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 4214 | mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED); |
| 4215 | mask &= dev_priv->pm_rps_events; |
| 4216 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4217 | /* IVB and SNB hard hangs on looping batchbuffer |
| 4218 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 4219 | */ |
| 4220 | if (INTEL_INFO(dev_priv->dev)->gen <= 7 && !IS_HASWELL(dev_priv->dev)) |
| 4221 | mask |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 4222 | |
Deepak S | baccd45 | 2014-05-15 20:58:09 +0300 | [diff] [blame] | 4223 | if (IS_GEN8(dev_priv->dev)) |
| 4224 | mask |= GEN8_PMINTR_REDIRECT_TO_NON_DISP; |
| 4225 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4226 | return ~mask; |
| 4227 | } |
| 4228 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4229 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 4230 | * called when the range (min_delay and max_delay) is modified so that we can |
| 4231 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 4232 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 4233 | { |
| 4234 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4235 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4236 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4237 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 4238 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 4239 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 4240 | /* min/max delay may still have been modified so be sure to |
| 4241 | * write the limits value. |
| 4242 | */ |
| 4243 | if (val != dev_priv->rps.cur_freq) { |
| 4244 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4245 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 4246 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 4247 | I915_WRITE(GEN6_RPNSWREQ, |
| 4248 | HSW_FREQUENCY(val)); |
| 4249 | else |
| 4250 | I915_WRITE(GEN6_RPNSWREQ, |
| 4251 | GEN6_FREQUENCY(val) | |
| 4252 | GEN6_OFFSET(0) | |
| 4253 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 4254 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4255 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4256 | /* Make sure we continue to get interrupts |
| 4257 | * until we hit the minimum or maximum frequencies. |
| 4258 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 4259 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4260 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4261 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 4262 | POSTING_READ(GEN6_RPNSWREQ); |
| 4263 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4264 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9 | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 4265 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4266 | } |
| 4267 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4268 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 4269 | * |
| 4270 | * * If Gfx is Idle, then |
| 4271 | * 1. Mask Turbo interrupts |
| 4272 | * 2. Bring up Gfx clock |
| 4273 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 4274 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 4275 | * 5. Unmask Turbo interrupts |
| 4276 | */ |
| 4277 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 4278 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4279 | struct drm_device *dev = dev_priv->dev; |
| 4280 | |
| 4281 | /* Latest VLV doesn't need to force the gfx clock */ |
| 4282 | if (dev->pdev->revision >= 0xd) { |
| 4283 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 4284 | return; |
| 4285 | } |
| 4286 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4287 | /* |
| 4288 | * When we are idle. Drop to min voltage state. |
| 4289 | */ |
| 4290 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4291 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4292 | return; |
| 4293 | |
| 4294 | /* Mask turbo interrupt so that they will not come in between */ |
| 4295 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 4296 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4297 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4298 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4299 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4300 | |
| 4301 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4302 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4303 | |
| 4304 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
| 4305 | & GENFREQSTATUS) == 0, 5)) |
| 4306 | DRM_ERROR("timed out waiting for Punit\n"); |
| 4307 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4308 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4309 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4310 | I915_WRITE(GEN6_PMINTRMSK, |
| 4311 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4312 | } |
| 4313 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4314 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 4315 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4316 | struct drm_device *dev = dev_priv->dev; |
| 4317 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4318 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4319 | if (dev_priv->rps.enabled) { |
Deepak S | 3463811 | 2014-06-28 11:26:26 +0530 | [diff] [blame] | 4320 | if (IS_CHERRYVIEW(dev)) |
| 4321 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 4322 | else if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4323 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4324 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4325 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4326 | dev_priv->rps.last_adj = 0; |
| 4327 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4328 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4329 | } |
| 4330 | |
| 4331 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 4332 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4333 | struct drm_device *dev = dev_priv->dev; |
| 4334 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4335 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4336 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4337 | if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4338 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4339 | else |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4340 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4341 | dev_priv->rps.last_adj = 0; |
| 4342 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4343 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4344 | } |
| 4345 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4346 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 4347 | { |
| 4348 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 4349 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4350 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4351 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 4352 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4353 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4354 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 4355 | "Odd GPU freq value\n")) |
| 4356 | val &= ~1; |
| 4357 | |
Ville Syrjälä | 6795686 | 2014-09-02 15:12:17 +0300 | [diff] [blame] | 4358 | if (val != dev_priv->rps.cur_freq) { |
| 4359 | DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n", |
| 4360 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4361 | dev_priv->rps.cur_freq, |
| 4362 | vlv_gpu_freq(dev_priv, val), val); |
| 4363 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4364 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Ville Syrjälä | 6795686 | 2014-09-02 15:12:17 +0300 | [diff] [blame] | 4365 | } |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4366 | |
Imre Deak | 09c87db | 2014-04-03 20:02:42 +0300 | [diff] [blame] | 4367 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4368 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4369 | dev_priv->rps.cur_freq = val; |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 4370 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4371 | } |
| 4372 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 4373 | static void gen8_disable_rps_interrupts(struct drm_device *dev) |
| 4374 | { |
| 4375 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4376 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4377 | I915_WRITE(GEN6_PMINTRMSK, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP); |
| 4378 | I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) & |
| 4379 | ~dev_priv->pm_rps_events); |
| 4380 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 4381 | * item again unmasking PM interrupts because that is using a different |
| 4382 | * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in |
| 4383 | * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which |
| 4384 | * gen8_enable_rps will clean up. */ |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 4385 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4386 | spin_lock_irq(&dev_priv->irq_lock); |
| 4387 | dev_priv->rps.pm_iir = 0; |
| 4388 | spin_unlock_irq(&dev_priv->irq_lock); |
| 4389 | |
| 4390 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 4391 | } |
| 4392 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4393 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4394 | { |
| 4395 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4396 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4397 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 4398 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & |
| 4399 | ~dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4400 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 4401 | * item again unmasking PM interrupts because that is using a different |
| 4402 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 4403 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 4404 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 4405 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 4406 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 4407 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4408 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 4409 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4410 | } |
| 4411 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4412 | static void gen6_disable_rps(struct drm_device *dev) |
| 4413 | { |
| 4414 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4415 | |
| 4416 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4417 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 4418 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 4419 | if (IS_BROADWELL(dev)) |
| 4420 | gen8_disable_rps_interrupts(dev); |
| 4421 | else |
| 4422 | gen6_disable_rps_interrupts(dev); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4423 | } |
| 4424 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4425 | static void cherryview_disable_rps(struct drm_device *dev) |
| 4426 | { |
| 4427 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4428 | |
| 4429 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 4430 | |
| 4431 | gen8_disable_rps_interrupts(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4432 | } |
| 4433 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4434 | static void valleyview_disable_rps(struct drm_device *dev) |
| 4435 | { |
| 4436 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4437 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4438 | /* we're doing forcewake before Disabling RC6, |
| 4439 | * This what the BIOS expects when going into suspend */ |
| 4440 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 4441 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4442 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4443 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4444 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 4445 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4446 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4449 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 4450 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4451 | if (IS_VALLEYVIEW(dev)) { |
| 4452 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 4453 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 4454 | else |
| 4455 | mode = 0; |
| 4456 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4457 | if (HAS_RC6p(dev)) |
| 4458 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 4459 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 4460 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 4461 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 4462 | |
| 4463 | else |
| 4464 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 4465 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4468 | 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] | 4469 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 4470 | /* No RC6 before Ironlake */ |
| 4471 | if (INTEL_INFO(dev)->gen < 5) |
| 4472 | return 0; |
| 4473 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4474 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 4475 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 4476 | return 0; |
| 4477 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 4478 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4479 | if (enable_rc6 >= 0) { |
| 4480 | int mask; |
| 4481 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4482 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4483 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 4484 | INTEL_RC6pp_ENABLE; |
| 4485 | else |
| 4486 | mask = INTEL_RC6_ENABLE; |
| 4487 | |
| 4488 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 4489 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 4490 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4491 | |
| 4492 | return enable_rc6 & mask; |
| 4493 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4494 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 4495 | /* Disable RC6 on Ironlake */ |
| 4496 | if (INTEL_INFO(dev)->gen == 5) |
| 4497 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4498 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4499 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4500 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4501 | |
| 4502 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4503 | } |
| 4504 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4505 | int intel_enable_rc6(const struct drm_device *dev) |
| 4506 | { |
| 4507 | return i915.enable_rc6; |
| 4508 | } |
| 4509 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 4510 | static void gen8_enable_rps_interrupts(struct drm_device *dev) |
| 4511 | { |
| 4512 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4513 | |
| 4514 | spin_lock_irq(&dev_priv->irq_lock); |
| 4515 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 4516 | gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 4517 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 4518 | spin_unlock_irq(&dev_priv->irq_lock); |
| 4519 | } |
| 4520 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4521 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 4522 | { |
| 4523 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4524 | |
| 4525 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 4526 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 4527 | gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 4528 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4529 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4530 | } |
| 4531 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4532 | static void parse_rp_state_cap(struct drm_i915_private *dev_priv, u32 rp_state_cap) |
| 4533 | { |
| 4534 | /* All of these values are in units of 50MHz */ |
| 4535 | dev_priv->rps.cur_freq = 0; |
| 4536 | /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */ |
| 4537 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 4538 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 4539 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 4540 | /* XXX: only BYT has a special efficient freq */ |
| 4541 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4542 | /* hw_max = RP0 until we check for overclocking */ |
| 4543 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4544 | |
| 4545 | /* Preserve min/max settings in case of re-init */ |
| 4546 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4547 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4548 | |
| 4549 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4550 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4551 | } |
| 4552 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4553 | static void gen8_enable_rps(struct drm_device *dev) |
| 4554 | { |
| 4555 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4556 | struct intel_engine_cs *ring; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4557 | uint32_t rc6_mask = 0, rp_state_cap; |
| 4558 | int unused; |
| 4559 | |
| 4560 | /* 1a: Software RC state - RC0 */ |
| 4561 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4562 | |
| 4563 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4564 | * 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] | 4565 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4566 | |
| 4567 | /* 2a: Disable RC states. */ |
| 4568 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4569 | |
| 4570 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4571 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4572 | |
| 4573 | /* 2b: Program RC6 thresholds.*/ |
| 4574 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4575 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4576 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4577 | for_each_ring(ring, dev_priv, unused) |
| 4578 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4579 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4580 | if (IS_BROADWELL(dev)) |
| 4581 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4582 | else |
| 4583 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4584 | |
| 4585 | /* 3: Enable RC6 */ |
| 4586 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4587 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4588 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4589 | if (IS_BROADWELL(dev)) |
| 4590 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4591 | GEN7_RC_CTL_TO_MODE | |
| 4592 | rc6_mask); |
| 4593 | else |
| 4594 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4595 | GEN6_RC_CTL_EI_MODE(1) | |
| 4596 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4597 | |
| 4598 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4599 | I915_WRITE(GEN6_RPNSWREQ, |
| 4600 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4601 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4602 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4603 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4604 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4605 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4606 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4607 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4608 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4609 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4610 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4611 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4612 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4613 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4614 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4615 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4616 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4617 | |
| 4618 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4619 | I915_WRITE(GEN6_RP_CONTROL, |
| 4620 | GEN6_RP_MEDIA_TURBO | |
| 4621 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4622 | GEN6_RP_MEDIA_IS_GFX | |
| 4623 | GEN6_RP_ENABLE | |
| 4624 | GEN6_RP_UP_BUSY_AVG | |
| 4625 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4626 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4627 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4628 | |
| 4629 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4630 | |
| 4631 | gen8_enable_rps_interrupts(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4632 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4633 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4636 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4637 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4638 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4639 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4640 | u32 rp_state_cap; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4641 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4642 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4643 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4644 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4645 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4646 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4647 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4648 | /* Here begins a magic sequence of register writes to enable |
| 4649 | * auto-downclocking. |
| 4650 | * |
| 4651 | * Perhaps there might be some value in exposing these to |
| 4652 | * userspace... |
| 4653 | */ |
| 4654 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4655 | |
| 4656 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4657 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4658 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4659 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4660 | } |
| 4661 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4662 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4663 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4664 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4665 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4666 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4667 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4668 | /* disable the counters and set deterministic thresholds */ |
| 4669 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4670 | |
| 4671 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4672 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4673 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4674 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4675 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4676 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4677 | for_each_ring(ring, dev_priv, i) |
| 4678 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4679 | |
| 4680 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4681 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4682 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4683 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4684 | else |
| 4685 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4686 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4687 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4688 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4689 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4690 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4691 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4692 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4693 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4694 | /* We don't use those on Haswell */ |
| 4695 | if (!IS_HASWELL(dev)) { |
| 4696 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4697 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4698 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4699 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4700 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4701 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4702 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4703 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4704 | |
| 4705 | I915_WRITE(GEN6_RC_CONTROL, |
| 4706 | rc6_mask | |
| 4707 | GEN6_RC_CTL_EI_MODE(1) | |
| 4708 | GEN6_RC_CTL_HW_ENABLE); |
| 4709 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4710 | /* Power down if completely idle for over 50ms */ |
| 4711 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4712 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4713 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4714 | 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] | 4715 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4716 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4717 | |
| 4718 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4719 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4720 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4721 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4722 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4723 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4724 | } |
| 4725 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4726 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4727 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4728 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4729 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4730 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4731 | rc6vids = 0; |
| 4732 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4733 | if (IS_GEN6(dev) && ret) { |
| 4734 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4735 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4736 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4737 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4738 | rc6vids &= 0xffff00; |
| 4739 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4740 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4741 | if (ret) |
| 4742 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4743 | } |
| 4744 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4745 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4746 | } |
| 4747 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4748 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4749 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4750 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4751 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4752 | unsigned int gpu_freq; |
| 4753 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4754 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4755 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4756 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4757 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4758 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4759 | policy = cpufreq_cpu_get(0); |
| 4760 | if (policy) { |
| 4761 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4762 | cpufreq_cpu_put(policy); |
| 4763 | } else { |
| 4764 | /* |
| 4765 | * Default to measured freq if none found, PCU will ensure we |
| 4766 | * don't go over |
| 4767 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4768 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4769 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4770 | |
| 4771 | /* Convert from kHz to MHz */ |
| 4772 | max_ia_freq /= 1000; |
| 4773 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4774 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4775 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4776 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4777 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4778 | /* |
| 4779 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4780 | * to use for memory access. We do this by specifying the IA frequency |
| 4781 | * the PCU should use as a reference to determine the ring frequency. |
| 4782 | */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4783 | 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] | 4784 | gpu_freq--) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4785 | int diff = dev_priv->rps.max_freq_softlimit - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4786 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4787 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4788 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4789 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4790 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4791 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4792 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4793 | ring_freq = max(min_ring_freq, ring_freq); |
| 4794 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4795 | } else { |
| 4796 | /* On older processors, there is no separate ring |
| 4797 | * clock domain, so in order to boost the bandwidth |
| 4798 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4799 | * |
| 4800 | * For GPU frequencies less than 750MHz, |
| 4801 | * just use the lowest ring freq. |
| 4802 | */ |
| 4803 | if (gpu_freq < min_freq) |
| 4804 | ia_freq = 800; |
| 4805 | else |
| 4806 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4807 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4808 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4809 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4810 | sandybridge_pcode_write(dev_priv, |
| 4811 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4812 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4813 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4814 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4815 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4816 | } |
| 4817 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4818 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4819 | { |
| 4820 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4821 | |
| 4822 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4823 | return; |
| 4824 | |
| 4825 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4826 | __gen6_update_ring_freq(dev); |
| 4827 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4828 | } |
| 4829 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4830 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4831 | { |
| 4832 | u32 val, rp0; |
| 4833 | |
| 4834 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4835 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4836 | |
| 4837 | return rp0; |
| 4838 | } |
| 4839 | |
| 4840 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4841 | { |
| 4842 | u32 val, rpe; |
| 4843 | |
| 4844 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4845 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4846 | |
| 4847 | return rpe; |
| 4848 | } |
| 4849 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4850 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4851 | { |
| 4852 | u32 val, rp1; |
| 4853 | |
| 4854 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4855 | rp1 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4856 | |
| 4857 | return rp1; |
| 4858 | } |
| 4859 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4860 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4861 | { |
| 4862 | u32 val, rpn; |
| 4863 | |
| 4864 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4865 | rpn = (val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK; |
| 4866 | return rpn; |
| 4867 | } |
| 4868 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4869 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4870 | { |
| 4871 | u32 val, rp1; |
| 4872 | |
| 4873 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4874 | |
| 4875 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4876 | |
| 4877 | return rp1; |
| 4878 | } |
| 4879 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4880 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4881 | { |
| 4882 | u32 val, rp0; |
| 4883 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4884 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4885 | |
| 4886 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4887 | /* Clamp to max */ |
| 4888 | rp0 = min_t(u32, rp0, 0xea); |
| 4889 | |
| 4890 | return rp0; |
| 4891 | } |
| 4892 | |
| 4893 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4894 | { |
| 4895 | u32 val, rpe; |
| 4896 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4897 | 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] | 4898 | 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] | 4899 | 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] | 4900 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4901 | |
| 4902 | return rpe; |
| 4903 | } |
| 4904 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4905 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4906 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4907 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4910 | /* Check that the pctx buffer wasn't move under us. */ |
| 4911 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4912 | { |
| 4913 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4914 | |
| 4915 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4916 | dev_priv->vlv_pctx->stolen->start); |
| 4917 | } |
| 4918 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4919 | |
| 4920 | /* Check that the pcbr address is not empty. */ |
| 4921 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4922 | { |
| 4923 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4924 | |
| 4925 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4926 | } |
| 4927 | |
| 4928 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4929 | { |
| 4930 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4931 | unsigned long pctx_paddr, paddr; |
| 4932 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4933 | u32 pcbr; |
| 4934 | int pctx_size = 32*1024; |
| 4935 | |
| 4936 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4937 | |
| 4938 | pcbr = I915_READ(VLV_PCBR); |
| 4939 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
| 4940 | paddr = (dev_priv->mm.stolen_base + |
| 4941 | (gtt->stolen_size - pctx_size)); |
| 4942 | |
| 4943 | pctx_paddr = (paddr & (~4095)); |
| 4944 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4945 | } |
| 4946 | } |
| 4947 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4948 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4949 | { |
| 4950 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4951 | struct drm_i915_gem_object *pctx; |
| 4952 | unsigned long pctx_paddr; |
| 4953 | u32 pcbr; |
| 4954 | int pctx_size = 24*1024; |
| 4955 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4956 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4957 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4958 | pcbr = I915_READ(VLV_PCBR); |
| 4959 | if (pcbr) { |
| 4960 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4961 | int pcbr_offset; |
| 4962 | |
| 4963 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4964 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4965 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4966 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4967 | pctx_size); |
| 4968 | goto out; |
| 4969 | } |
| 4970 | |
| 4971 | /* |
| 4972 | * From the Gunit register HAS: |
| 4973 | * The Gfx driver is expected to program this register and ensure |
| 4974 | * proper allocation within Gfx stolen memory. For example, this |
| 4975 | * register should be programmed such than the PCBR range does not |
| 4976 | * overlap with other ranges, such as the frame buffer, protected |
| 4977 | * memory, or any other relevant ranges. |
| 4978 | */ |
| 4979 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4980 | if (!pctx) { |
| 4981 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4982 | return; |
| 4983 | } |
| 4984 | |
| 4985 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4986 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4987 | |
| 4988 | out: |
| 4989 | dev_priv->vlv_pctx = pctx; |
| 4990 | } |
| 4991 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4992 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4993 | { |
| 4994 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4995 | |
| 4996 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4997 | return; |
| 4998 | |
| 4999 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 5000 | dev_priv->vlv_pctx = NULL; |
| 5001 | } |
| 5002 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5003 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 5004 | { |
| 5005 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5006 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5007 | |
| 5008 | valleyview_setup_pctx(dev); |
| 5009 | |
| 5010 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5011 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5012 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5013 | switch ((val >> 6) & 3) { |
| 5014 | case 0: |
| 5015 | case 1: |
| 5016 | dev_priv->mem_freq = 800; |
| 5017 | break; |
| 5018 | case 2: |
| 5019 | dev_priv->mem_freq = 1066; |
| 5020 | break; |
| 5021 | case 3: |
| 5022 | dev_priv->mem_freq = 1333; |
| 5023 | break; |
| 5024 | } |
| 5025 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
| 5026 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5027 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 5028 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 5029 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 5030 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 5031 | dev_priv->rps.max_freq); |
| 5032 | |
| 5033 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 5034 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 5035 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 5036 | dev_priv->rps.efficient_freq); |
| 5037 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 5038 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 5039 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
| 5040 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 5041 | dev_priv->rps.rp1_freq); |
| 5042 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5043 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 5044 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 5045 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 5046 | dev_priv->rps.min_freq); |
| 5047 | |
| 5048 | /* Preserve min/max settings in case of re-init */ |
| 5049 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 5050 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 5051 | |
| 5052 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 5053 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 5054 | |
| 5055 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5056 | } |
| 5057 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5058 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 5059 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5060 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5061 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5062 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5063 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5064 | |
| 5065 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5066 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 5067 | val = vlv_punit_read(dev_priv, CCK_FUSE_REG); |
| 5068 | switch ((val >> 2) & 0x7) { |
| 5069 | case 0: |
| 5070 | case 1: |
| 5071 | dev_priv->rps.cz_freq = 200; |
| 5072 | dev_priv->mem_freq = 1600; |
| 5073 | break; |
| 5074 | case 2: |
| 5075 | dev_priv->rps.cz_freq = 267; |
| 5076 | dev_priv->mem_freq = 1600; |
| 5077 | break; |
| 5078 | case 3: |
| 5079 | dev_priv->rps.cz_freq = 333; |
| 5080 | dev_priv->mem_freq = 2000; |
| 5081 | break; |
| 5082 | case 4: |
| 5083 | dev_priv->rps.cz_freq = 320; |
| 5084 | dev_priv->mem_freq = 1600; |
| 5085 | break; |
| 5086 | case 5: |
| 5087 | dev_priv->rps.cz_freq = 400; |
| 5088 | dev_priv->mem_freq = 1600; |
| 5089 | break; |
| 5090 | } |
| 5091 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
| 5092 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5093 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 5094 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 5095 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 5096 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 5097 | dev_priv->rps.max_freq); |
| 5098 | |
| 5099 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 5100 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 5101 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 5102 | dev_priv->rps.efficient_freq); |
| 5103 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 5104 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 5105 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
| 5106 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 5107 | dev_priv->rps.rp1_freq); |
| 5108 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5109 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 5110 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 5111 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 5112 | dev_priv->rps.min_freq); |
| 5113 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 5114 | WARN_ONCE((dev_priv->rps.max_freq | |
| 5115 | dev_priv->rps.efficient_freq | |
| 5116 | dev_priv->rps.rp1_freq | |
| 5117 | dev_priv->rps.min_freq) & 1, |
| 5118 | "Odd GPU freq values\n"); |
| 5119 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5120 | /* Preserve min/max settings in case of re-init */ |
| 5121 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 5122 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 5123 | |
| 5124 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 5125 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 5126 | |
| 5127 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5128 | } |
| 5129 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5130 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 5131 | { |
| 5132 | valleyview_cleanup_pctx(dev); |
| 5133 | } |
| 5134 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5135 | static void cherryview_enable_rps(struct drm_device *dev) |
| 5136 | { |
| 5137 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5138 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5139 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5140 | int i; |
| 5141 | |
| 5142 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5143 | |
| 5144 | gtfifodbg = I915_READ(GTFIFODBG); |
| 5145 | if (gtfifodbg) { |
| 5146 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5147 | gtfifodbg); |
| 5148 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5149 | } |
| 5150 | |
| 5151 | cherryview_check_pctx(dev_priv); |
| 5152 | |
| 5153 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 5154 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
| 5155 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 5156 | |
| 5157 | /* 2a: Program RC6 thresholds.*/ |
| 5158 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 5159 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5160 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 5161 | |
| 5162 | for_each_ring(ring, dev_priv, i) |
| 5163 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5164 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 5165 | |
| 5166 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 5167 | |
| 5168 | /* allows RC6 residency counter to work */ |
| 5169 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 5170 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 5171 | VLV_MEDIA_RC6_COUNT_EN | |
| 5172 | VLV_RENDER_RC6_COUNT_EN)); |
| 5173 | |
| 5174 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 5175 | pcbr = I915_READ(VLV_PCBR); |
| 5176 | |
| 5177 | DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr); |
| 5178 | |
| 5179 | /* 3: Enable RC6 */ |
| 5180 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 5181 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
| 5182 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 5183 | |
| 5184 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 5185 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5186 | /* 4 Program defaults and thresholds for RPS*/ |
| 5187 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5188 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5189 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5190 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5191 | |
| 5192 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5193 | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 5194 | /* WaDisablePwrmtrEvent:chv (pre-production hw) */ |
| 5195 | I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff); |
| 5196 | I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00); |
| 5197 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5198 | /* 5: Enable RPS */ |
| 5199 | I915_WRITE(GEN6_RP_CONTROL, |
| 5200 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 5201 | GEN6_RP_MEDIA_IS_GFX | /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5202 | GEN6_RP_ENABLE | |
| 5203 | GEN6_RP_UP_BUSY_AVG | |
| 5204 | GEN6_RP_DOWN_IDLE_AVG); |
| 5205 | |
| 5206 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5207 | |
| 5208 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 5209 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5210 | |
| 5211 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 5212 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
| 5213 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 5214 | dev_priv->rps.cur_freq); |
| 5215 | |
| 5216 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
| 5217 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 5218 | dev_priv->rps.efficient_freq); |
| 5219 | |
| 5220 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 5221 | |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 5222 | gen8_enable_rps_interrupts(dev); |
| 5223 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5224 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 5225 | } |
| 5226 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5227 | static void valleyview_enable_rps(struct drm_device *dev) |
| 5228 | { |
| 5229 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5230 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 5231 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5232 | int i; |
| 5233 | |
| 5234 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5235 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5236 | valleyview_check_pctx(dev_priv); |
| 5237 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5238 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 5239 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5240 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5241 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5242 | } |
| 5243 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 5244 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 5245 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5246 | |
| 5247 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5248 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5249 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5250 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5251 | |
| 5252 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5253 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5254 | |
| 5255 | I915_WRITE(GEN6_RP_CONTROL, |
| 5256 | GEN6_RP_MEDIA_TURBO | |
| 5257 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5258 | GEN6_RP_MEDIA_IS_GFX | |
| 5259 | GEN6_RP_ENABLE | |
| 5260 | GEN6_RP_UP_BUSY_AVG | |
| 5261 | GEN6_RP_DOWN_IDLE_CONT); |
| 5262 | |
| 5263 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 5264 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 5265 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 5266 | |
| 5267 | for_each_ring(ring, dev_priv, i) |
| 5268 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5269 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 5270 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5271 | |
| 5272 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5273 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5274 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 5275 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5276 | VLV_MEDIA_RC6_COUNT_EN | |
| 5277 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5278 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5279 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 5280 | 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] | 5281 | |
| 5282 | intel_print_rc6_info(dev, rc6_mode); |
| 5283 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5284 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5285 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5286 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5287 | |
| 5288 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 5289 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5290 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5291 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5292 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5293 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 5294 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5295 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5296 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5297 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 5298 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5299 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5300 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5301 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 5302 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5303 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 5304 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5307 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5308 | { |
| 5309 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5310 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 5311 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 5312 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 5313 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 5314 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5315 | } |
| 5316 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 5317 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 5318 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 5319 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 5320 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5324 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5325 | { |
| 5326 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5327 | |
| 5328 | if (I915_READ(PWRCTXA)) { |
| 5329 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 5330 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 5331 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 5332 | 50); |
| 5333 | |
| 5334 | I915_WRITE(PWRCTXA, 0); |
| 5335 | POSTING_READ(PWRCTXA); |
| 5336 | |
| 5337 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 5338 | POSTING_READ(RSTDBYCTL); |
| 5339 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 5343 | { |
| 5344 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5345 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 5346 | if (dev_priv->ips.renderctx == NULL) |
| 5347 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 5348 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5349 | return -ENOMEM; |
| 5350 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 5351 | if (dev_priv->ips.pwrctx == NULL) |
| 5352 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 5353 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5354 | ironlake_teardown_rc6(dev); |
| 5355 | return -ENOMEM; |
| 5356 | } |
| 5357 | |
| 5358 | return 0; |
| 5359 | } |
| 5360 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5361 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5362 | { |
| 5363 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5364 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5365 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5366 | int ret; |
| 5367 | |
| 5368 | /* rc6 disabled by default due to repeated reports of hanging during |
| 5369 | * boot and resume. |
| 5370 | */ |
| 5371 | if (!intel_enable_rc6(dev)) |
| 5372 | return; |
| 5373 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 5374 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 5375 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5376 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 5377 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5378 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5379 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5380 | was_interruptible = dev_priv->mm.interruptible; |
| 5381 | dev_priv->mm.interruptible = false; |
| 5382 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5383 | /* |
| 5384 | * GPU can automatically power down the render unit if given a page |
| 5385 | * to save state. |
| 5386 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 5387 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5388 | if (ret) { |
| 5389 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5390 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5391 | return; |
| 5392 | } |
| 5393 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 5394 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 5395 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 5396 | 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] | 5397 | MI_MM_SPACE_GTT | |
| 5398 | MI_SAVE_EXT_STATE_EN | |
| 5399 | MI_RESTORE_EXT_STATE_EN | |
| 5400 | MI_RESTORE_INHIBIT); |
| 5401 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 5402 | intel_ring_emit(ring, MI_NOOP); |
| 5403 | intel_ring_emit(ring, MI_FLUSH); |
| 5404 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5405 | |
| 5406 | /* |
| 5407 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 5408 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 5409 | * safe to assume that renderctx is valid |
| 5410 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 5411 | ret = intel_ring_idle(ring); |
| 5412 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5413 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 5414 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5415 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5416 | return; |
| 5417 | } |
| 5418 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 5419 | 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] | 5420 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 5421 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 5422 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 5423 | } |
| 5424 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5425 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 5426 | { |
| 5427 | unsigned long freq; |
| 5428 | int div = (vidfreq & 0x3f0000) >> 16; |
| 5429 | int post = (vidfreq & 0x3000) >> 12; |
| 5430 | int pre = (vidfreq & 0x7); |
| 5431 | |
| 5432 | if (!pre) |
| 5433 | return 0; |
| 5434 | |
| 5435 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 5436 | |
| 5437 | return freq; |
| 5438 | } |
| 5439 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5440 | static const struct cparams { |
| 5441 | u16 i; |
| 5442 | u16 t; |
| 5443 | u16 m; |
| 5444 | u16 c; |
| 5445 | } cparams[] = { |
| 5446 | { 1, 1333, 301, 28664 }, |
| 5447 | { 1, 1066, 294, 24460 }, |
| 5448 | { 1, 800, 294, 25192 }, |
| 5449 | { 0, 1333, 276, 27605 }, |
| 5450 | { 0, 1066, 276, 27605 }, |
| 5451 | { 0, 800, 231, 23784 }, |
| 5452 | }; |
| 5453 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5454 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5455 | { |
| 5456 | u64 total_count, diff, ret; |
| 5457 | u32 count1, count2, count3, m = 0, c = 0; |
| 5458 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 5459 | int i; |
| 5460 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5461 | assert_spin_locked(&mchdev_lock); |
| 5462 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5463 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5464 | |
| 5465 | /* Prevent division-by-zero if we are asking too fast. |
| 5466 | * Also, we don't get interesting results if we are polling |
| 5467 | * faster than once in 10ms, so just return the saved value |
| 5468 | * in such cases. |
| 5469 | */ |
| 5470 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5471 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5472 | |
| 5473 | count1 = I915_READ(DMIEC); |
| 5474 | count2 = I915_READ(DDREC); |
| 5475 | count3 = I915_READ(CSIEC); |
| 5476 | |
| 5477 | total_count = count1 + count2 + count3; |
| 5478 | |
| 5479 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5480 | if (total_count < dev_priv->ips.last_count1) { |
| 5481 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5482 | diff += total_count; |
| 5483 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5484 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5488 | if (cparams[i].i == dev_priv->ips.c_m && |
| 5489 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5490 | m = cparams[i].m; |
| 5491 | c = cparams[i].c; |
| 5492 | break; |
| 5493 | } |
| 5494 | } |
| 5495 | |
| 5496 | diff = div_u64(diff, diff1); |
| 5497 | ret = ((m * diff) + c); |
| 5498 | ret = div_u64(ret, 10); |
| 5499 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5500 | dev_priv->ips.last_count1 = total_count; |
| 5501 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5502 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5503 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5504 | |
| 5505 | return ret; |
| 5506 | } |
| 5507 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5508 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5509 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5510 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5511 | unsigned long val; |
| 5512 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5513 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5514 | return 0; |
| 5515 | |
| 5516 | spin_lock_irq(&mchdev_lock); |
| 5517 | |
| 5518 | val = __i915_chipset_val(dev_priv); |
| 5519 | |
| 5520 | spin_unlock_irq(&mchdev_lock); |
| 5521 | |
| 5522 | return val; |
| 5523 | } |
| 5524 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5525 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5526 | { |
| 5527 | unsigned long m, x, b; |
| 5528 | u32 tsfs; |
| 5529 | |
| 5530 | tsfs = I915_READ(TSFS); |
| 5531 | |
| 5532 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5533 | x = I915_READ8(TR1); |
| 5534 | |
| 5535 | b = tsfs & TSFS_INTR_MASK; |
| 5536 | |
| 5537 | return ((m * x) / 127) - b; |
| 5538 | } |
| 5539 | |
| 5540 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 5541 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5542 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5543 | static const struct v_table { |
| 5544 | u16 vd; /* in .1 mil */ |
| 5545 | u16 vm; /* in .1 mil */ |
| 5546 | } v_table[] = { |
| 5547 | { 0, 0, }, |
| 5548 | { 375, 0, }, |
| 5549 | { 500, 0, }, |
| 5550 | { 625, 0, }, |
| 5551 | { 750, 0, }, |
| 5552 | { 875, 0, }, |
| 5553 | { 1000, 0, }, |
| 5554 | { 1125, 0, }, |
| 5555 | { 4125, 3000, }, |
| 5556 | { 4125, 3000, }, |
| 5557 | { 4125, 3000, }, |
| 5558 | { 4125, 3000, }, |
| 5559 | { 4125, 3000, }, |
| 5560 | { 4125, 3000, }, |
| 5561 | { 4125, 3000, }, |
| 5562 | { 4125, 3000, }, |
| 5563 | { 4125, 3000, }, |
| 5564 | { 4125, 3000, }, |
| 5565 | { 4125, 3000, }, |
| 5566 | { 4125, 3000, }, |
| 5567 | { 4125, 3000, }, |
| 5568 | { 4125, 3000, }, |
| 5569 | { 4125, 3000, }, |
| 5570 | { 4125, 3000, }, |
| 5571 | { 4125, 3000, }, |
| 5572 | { 4125, 3000, }, |
| 5573 | { 4125, 3000, }, |
| 5574 | { 4125, 3000, }, |
| 5575 | { 4125, 3000, }, |
| 5576 | { 4125, 3000, }, |
| 5577 | { 4125, 3000, }, |
| 5578 | { 4125, 3000, }, |
| 5579 | { 4250, 3125, }, |
| 5580 | { 4375, 3250, }, |
| 5581 | { 4500, 3375, }, |
| 5582 | { 4625, 3500, }, |
| 5583 | { 4750, 3625, }, |
| 5584 | { 4875, 3750, }, |
| 5585 | { 5000, 3875, }, |
| 5586 | { 5125, 4000, }, |
| 5587 | { 5250, 4125, }, |
| 5588 | { 5375, 4250, }, |
| 5589 | { 5500, 4375, }, |
| 5590 | { 5625, 4500, }, |
| 5591 | { 5750, 4625, }, |
| 5592 | { 5875, 4750, }, |
| 5593 | { 6000, 4875, }, |
| 5594 | { 6125, 5000, }, |
| 5595 | { 6250, 5125, }, |
| 5596 | { 6375, 5250, }, |
| 5597 | { 6500, 5375, }, |
| 5598 | { 6625, 5500, }, |
| 5599 | { 6750, 5625, }, |
| 5600 | { 6875, 5750, }, |
| 5601 | { 7000, 5875, }, |
| 5602 | { 7125, 6000, }, |
| 5603 | { 7250, 6125, }, |
| 5604 | { 7375, 6250, }, |
| 5605 | { 7500, 6375, }, |
| 5606 | { 7625, 6500, }, |
| 5607 | { 7750, 6625, }, |
| 5608 | { 7875, 6750, }, |
| 5609 | { 8000, 6875, }, |
| 5610 | { 8125, 7000, }, |
| 5611 | { 8250, 7125, }, |
| 5612 | { 8375, 7250, }, |
| 5613 | { 8500, 7375, }, |
| 5614 | { 8625, 7500, }, |
| 5615 | { 8750, 7625, }, |
| 5616 | { 8875, 7750, }, |
| 5617 | { 9000, 7875, }, |
| 5618 | { 9125, 8000, }, |
| 5619 | { 9250, 8125, }, |
| 5620 | { 9375, 8250, }, |
| 5621 | { 9500, 8375, }, |
| 5622 | { 9625, 8500, }, |
| 5623 | { 9750, 8625, }, |
| 5624 | { 9875, 8750, }, |
| 5625 | { 10000, 8875, }, |
| 5626 | { 10125, 9000, }, |
| 5627 | { 10250, 9125, }, |
| 5628 | { 10375, 9250, }, |
| 5629 | { 10500, 9375, }, |
| 5630 | { 10625, 9500, }, |
| 5631 | { 10750, 9625, }, |
| 5632 | { 10875, 9750, }, |
| 5633 | { 11000, 9875, }, |
| 5634 | { 11125, 10000, }, |
| 5635 | { 11250, 10125, }, |
| 5636 | { 11375, 10250, }, |
| 5637 | { 11500, 10375, }, |
| 5638 | { 11625, 10500, }, |
| 5639 | { 11750, 10625, }, |
| 5640 | { 11875, 10750, }, |
| 5641 | { 12000, 10875, }, |
| 5642 | { 12125, 11000, }, |
| 5643 | { 12250, 11125, }, |
| 5644 | { 12375, 11250, }, |
| 5645 | { 12500, 11375, }, |
| 5646 | { 12625, 11500, }, |
| 5647 | { 12750, 11625, }, |
| 5648 | { 12875, 11750, }, |
| 5649 | { 13000, 11875, }, |
| 5650 | { 13125, 12000, }, |
| 5651 | { 13250, 12125, }, |
| 5652 | { 13375, 12250, }, |
| 5653 | { 13500, 12375, }, |
| 5654 | { 13625, 12500, }, |
| 5655 | { 13750, 12625, }, |
| 5656 | { 13875, 12750, }, |
| 5657 | { 14000, 12875, }, |
| 5658 | { 14125, 13000, }, |
| 5659 | { 14250, 13125, }, |
| 5660 | { 14375, 13250, }, |
| 5661 | { 14500, 13375, }, |
| 5662 | { 14625, 13500, }, |
| 5663 | { 14750, 13625, }, |
| 5664 | { 14875, 13750, }, |
| 5665 | { 15000, 13875, }, |
| 5666 | { 15125, 14000, }, |
| 5667 | { 15250, 14125, }, |
| 5668 | { 15375, 14250, }, |
| 5669 | { 15500, 14375, }, |
| 5670 | { 15625, 14500, }, |
| 5671 | { 15750, 14625, }, |
| 5672 | { 15875, 14750, }, |
| 5673 | { 16000, 14875, }, |
| 5674 | { 16125, 15000, }, |
| 5675 | }; |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5676 | if (INTEL_INFO(dev)->is_mobile) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5677 | return v_table[pxvid].vm; |
| 5678 | else |
| 5679 | return v_table[pxvid].vd; |
| 5680 | } |
| 5681 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5682 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5683 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5684 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5685 | u32 count; |
| 5686 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5687 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5688 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5689 | now = ktime_get_raw_ns(); |
| 5690 | diffms = now - dev_priv->ips.last_time2; |
| 5691 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5692 | |
| 5693 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5694 | if (!diffms) |
| 5695 | return; |
| 5696 | |
| 5697 | count = I915_READ(GFXEC); |
| 5698 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5699 | if (count < dev_priv->ips.last_count2) { |
| 5700 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5701 | diff += count; |
| 5702 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5703 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5704 | } |
| 5705 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5706 | dev_priv->ips.last_count2 = count; |
| 5707 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5708 | |
| 5709 | /* More magic constants... */ |
| 5710 | diff = diff * 1181; |
| 5711 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5712 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5713 | } |
| 5714 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5715 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5716 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5717 | struct drm_device *dev = dev_priv->dev; |
| 5718 | |
| 5719 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5720 | return; |
| 5721 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5722 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5723 | |
| 5724 | __i915_update_gfx_val(dev_priv); |
| 5725 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5726 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5727 | } |
| 5728 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5729 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5730 | { |
| 5731 | unsigned long t, corr, state1, corr2, state2; |
| 5732 | u32 pxvid, ext_v; |
| 5733 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5734 | assert_spin_locked(&mchdev_lock); |
| 5735 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5736 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5737 | pxvid = (pxvid >> 24) & 0x7f; |
| 5738 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5739 | |
| 5740 | state1 = ext_v; |
| 5741 | |
| 5742 | t = i915_mch_val(dev_priv); |
| 5743 | |
| 5744 | /* Revel in the empirically derived constants */ |
| 5745 | |
| 5746 | /* Correction factor in 1/100000 units */ |
| 5747 | if (t > 80) |
| 5748 | corr = ((t * 2349) + 135940); |
| 5749 | else if (t >= 50) |
| 5750 | corr = ((t * 964) + 29317); |
| 5751 | else /* < 50 */ |
| 5752 | corr = ((t * 301) + 1004); |
| 5753 | |
| 5754 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5755 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5756 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5757 | |
| 5758 | state2 = (corr2 * state1) / 10000; |
| 5759 | state2 /= 100; /* convert to mW */ |
| 5760 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5761 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5762 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5763 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5764 | } |
| 5765 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5766 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5767 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5768 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5769 | unsigned long val; |
| 5770 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5771 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5772 | return 0; |
| 5773 | |
| 5774 | spin_lock_irq(&mchdev_lock); |
| 5775 | |
| 5776 | val = __i915_gfx_val(dev_priv); |
| 5777 | |
| 5778 | spin_unlock_irq(&mchdev_lock); |
| 5779 | |
| 5780 | return val; |
| 5781 | } |
| 5782 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5783 | /** |
| 5784 | * i915_read_mch_val - return value for IPS use |
| 5785 | * |
| 5786 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5787 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5788 | */ |
| 5789 | unsigned long i915_read_mch_val(void) |
| 5790 | { |
| 5791 | struct drm_i915_private *dev_priv; |
| 5792 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5793 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5794 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5795 | if (!i915_mch_dev) |
| 5796 | goto out_unlock; |
| 5797 | dev_priv = i915_mch_dev; |
| 5798 | |
Chris Wilson | f531dcb | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5799 | chipset_val = __i915_chipset_val(dev_priv); |
| 5800 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5801 | |
| 5802 | ret = chipset_val + graphics_val; |
| 5803 | |
| 5804 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5805 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5806 | |
| 5807 | return ret; |
| 5808 | } |
| 5809 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5810 | |
| 5811 | /** |
| 5812 | * i915_gpu_raise - raise GPU frequency limit |
| 5813 | * |
| 5814 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5815 | */ |
| 5816 | bool i915_gpu_raise(void) |
| 5817 | { |
| 5818 | struct drm_i915_private *dev_priv; |
| 5819 | bool ret = true; |
| 5820 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5821 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5822 | if (!i915_mch_dev) { |
| 5823 | ret = false; |
| 5824 | goto out_unlock; |
| 5825 | } |
| 5826 | dev_priv = i915_mch_dev; |
| 5827 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5828 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5829 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5830 | |
| 5831 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5832 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5833 | |
| 5834 | return ret; |
| 5835 | } |
| 5836 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5837 | |
| 5838 | /** |
| 5839 | * i915_gpu_lower - lower GPU frequency limit |
| 5840 | * |
| 5841 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5842 | * frequency maximum. |
| 5843 | */ |
| 5844 | bool i915_gpu_lower(void) |
| 5845 | { |
| 5846 | struct drm_i915_private *dev_priv; |
| 5847 | bool ret = true; |
| 5848 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5849 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5850 | if (!i915_mch_dev) { |
| 5851 | ret = false; |
| 5852 | goto out_unlock; |
| 5853 | } |
| 5854 | dev_priv = i915_mch_dev; |
| 5855 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5856 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5857 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5858 | |
| 5859 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5860 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5861 | |
| 5862 | return ret; |
| 5863 | } |
| 5864 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5865 | |
| 5866 | /** |
| 5867 | * i915_gpu_busy - indicate GPU business to IPS |
| 5868 | * |
| 5869 | * Tell the IPS driver whether or not the GPU is busy. |
| 5870 | */ |
| 5871 | bool i915_gpu_busy(void) |
| 5872 | { |
| 5873 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5874 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5875 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5876 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5877 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5878 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5879 | if (!i915_mch_dev) |
| 5880 | goto out_unlock; |
| 5881 | dev_priv = i915_mch_dev; |
| 5882 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5883 | for_each_ring(ring, dev_priv, i) |
| 5884 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5885 | |
| 5886 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5887 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5888 | |
| 5889 | return ret; |
| 5890 | } |
| 5891 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5892 | |
| 5893 | /** |
| 5894 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5895 | * |
| 5896 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5897 | * current frequency to the default. |
| 5898 | */ |
| 5899 | bool i915_gpu_turbo_disable(void) |
| 5900 | { |
| 5901 | struct drm_i915_private *dev_priv; |
| 5902 | bool ret = true; |
| 5903 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5904 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5905 | if (!i915_mch_dev) { |
| 5906 | ret = false; |
| 5907 | goto out_unlock; |
| 5908 | } |
| 5909 | dev_priv = i915_mch_dev; |
| 5910 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5911 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5912 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5913 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5914 | ret = false; |
| 5915 | |
| 5916 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5917 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5918 | |
| 5919 | return ret; |
| 5920 | } |
| 5921 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5922 | |
| 5923 | /** |
| 5924 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5925 | * IPS got loaded first. |
| 5926 | * |
| 5927 | * This awkward dance is so that neither module has to depend on the |
| 5928 | * other in order for IPS to do the appropriate communication of |
| 5929 | * GPU turbo limits to i915. |
| 5930 | */ |
| 5931 | static void |
| 5932 | ips_ping_for_i915_load(void) |
| 5933 | { |
| 5934 | void (*link)(void); |
| 5935 | |
| 5936 | link = symbol_get(ips_link_to_i915_driver); |
| 5937 | if (link) { |
| 5938 | link(); |
| 5939 | symbol_put(ips_link_to_i915_driver); |
| 5940 | } |
| 5941 | } |
| 5942 | |
| 5943 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5944 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5945 | /* We only register the i915 ips part with intel-ips once everything is |
| 5946 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5947 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5948 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5949 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5950 | |
| 5951 | ips_ping_for_i915_load(); |
| 5952 | } |
| 5953 | |
| 5954 | void intel_gpu_ips_teardown(void) |
| 5955 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5956 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5957 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5958 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5959 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5960 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5961 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5962 | { |
| 5963 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5964 | u32 lcfuse; |
| 5965 | u8 pxw[16]; |
| 5966 | int i; |
| 5967 | |
| 5968 | /* Disable to program */ |
| 5969 | I915_WRITE(ECR, 0); |
| 5970 | POSTING_READ(ECR); |
| 5971 | |
| 5972 | /* Program energy weights for various events */ |
| 5973 | I915_WRITE(SDEW, 0x15040d00); |
| 5974 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5975 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5976 | I915_WRITE(CSIEW2, 0x04000004); |
| 5977 | |
| 5978 | for (i = 0; i < 5; i++) |
| 5979 | I915_WRITE(PEW + (i * 4), 0); |
| 5980 | for (i = 0; i < 3; i++) |
| 5981 | I915_WRITE(DEW + (i * 4), 0); |
| 5982 | |
| 5983 | /* Program P-state weights to account for frequency power adjustment */ |
| 5984 | for (i = 0; i < 16; i++) { |
| 5985 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5986 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5987 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5988 | PXVFREQ_PX_SHIFT; |
| 5989 | unsigned long val; |
| 5990 | |
| 5991 | val = vid * vid; |
| 5992 | val *= (freq / 1000); |
| 5993 | val *= 255; |
| 5994 | val /= (127*127*900); |
| 5995 | if (val > 0xff) |
| 5996 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5997 | pxw[i] = val; |
| 5998 | } |
| 5999 | /* Render standby states get 0 weight */ |
| 6000 | pxw[14] = 0; |
| 6001 | pxw[15] = 0; |
| 6002 | |
| 6003 | for (i = 0; i < 4; i++) { |
| 6004 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 6005 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 6006 | I915_WRITE(PXW + (i * 4), val); |
| 6007 | } |
| 6008 | |
| 6009 | /* Adjust magic regs to magic values (more experimental results) */ |
| 6010 | I915_WRITE(OGW0, 0); |
| 6011 | I915_WRITE(OGW1, 0); |
| 6012 | I915_WRITE(EG0, 0x00007f00); |
| 6013 | I915_WRITE(EG1, 0x0000000e); |
| 6014 | I915_WRITE(EG2, 0x000e0000); |
| 6015 | I915_WRITE(EG3, 0x68000300); |
| 6016 | I915_WRITE(EG4, 0x42000000); |
| 6017 | I915_WRITE(EG5, 0x00140031); |
| 6018 | I915_WRITE(EG6, 0); |
| 6019 | I915_WRITE(EG7, 0); |
| 6020 | |
| 6021 | for (i = 0; i < 8; i++) |
| 6022 | I915_WRITE(PXWL + (i * 4), 0); |
| 6023 | |
| 6024 | /* Enable PMON + select events */ |
| 6025 | I915_WRITE(ECR, 0x80000019); |
| 6026 | |
| 6027 | lcfuse = I915_READ(LCFUSE02); |
| 6028 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 6029 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 6030 | } |
| 6031 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6032 | void intel_init_gt_powersave(struct drm_device *dev) |
| 6033 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 6034 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 6035 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6036 | if (IS_CHERRYVIEW(dev)) |
| 6037 | cherryview_init_gt_powersave(dev); |
| 6038 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6039 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 6043 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6044 | if (IS_CHERRYVIEW(dev)) |
| 6045 | return; |
| 6046 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 6047 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 6048 | } |
| 6049 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 6050 | /** |
| 6051 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 6052 | * @dev: drm device |
| 6053 | * |
| 6054 | * We don't want to disable RC6 or other features here, we just want |
| 6055 | * to make sure any work we've queued has finished and won't bother |
| 6056 | * us while we're suspended. |
| 6057 | */ |
| 6058 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 6059 | { |
| 6060 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6061 | |
| 6062 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 6063 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 6064 | |
| 6065 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 6066 | |
| 6067 | cancel_work_sync(&dev_priv->rps.work); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 6068 | |
| 6069 | /* Force GPU to min freq during suspend */ |
| 6070 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 6071 | } |
| 6072 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6073 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 6074 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6075 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6076 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 6077 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 6078 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 6079 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 6080 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6081 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 6082 | ironlake_disable_rc6(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6083 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 6084 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 6085 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6086 | mutex_lock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6087 | if (IS_CHERRYVIEW(dev)) |
| 6088 | cherryview_disable_rps(dev); |
| 6089 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 6090 | valleyview_disable_rps(dev); |
| 6091 | else |
| 6092 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6093 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6094 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 6095 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6096 | } |
| 6097 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6098 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 6099 | { |
| 6100 | struct drm_i915_private *dev_priv = |
| 6101 | container_of(work, struct drm_i915_private, |
| 6102 | rps.delayed_resume_work.work); |
| 6103 | struct drm_device *dev = dev_priv->dev; |
| 6104 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6105 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6106 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6107 | if (IS_CHERRYVIEW(dev)) { |
| 6108 | cherryview_enable_rps(dev); |
| 6109 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6110 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 6111 | } else if (IS_BROADWELL(dev)) { |
| 6112 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 6113 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6114 | } else { |
| 6115 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 6116 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 6117 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 6118 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6119 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6120 | |
| 6121 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6122 | } |
| 6123 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6124 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 6125 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6126 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6127 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6128 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 6129 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6130 | ironlake_enable_drps(dev); |
| 6131 | ironlake_enable_rc6(dev); |
| 6132 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 6133 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 6134 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6135 | /* |
| 6136 | * PCU communication is slow and this doesn't need to be |
| 6137 | * done at any specific time, so do this out of our fast path |
| 6138 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6139 | * |
| 6140 | * We depend on the HW RC6 power context save/restore |
| 6141 | * mechanism when entering D3 through runtime PM suspend. So |
| 6142 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 6143 | * get here via the driver load/system resume/runtime resume |
| 6144 | * paths, so the _noresume version is enough (and in case of |
| 6145 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 6146 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6147 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 6148 | round_jiffies_up_relative(HZ))) |
| 6149 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 6150 | } |
| 6151 | } |
| 6152 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 6153 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 6154 | { |
| 6155 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6156 | |
| 6157 | dev_priv->rps.enabled = false; |
| 6158 | intel_enable_gt_powersave(dev); |
| 6159 | } |
| 6160 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6161 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 6162 | { |
| 6163 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6164 | |
| 6165 | /* |
| 6166 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6167 | * gating for the panel power sequencer or it will fail to |
| 6168 | * start up when no ports are active. |
| 6169 | */ |
| 6170 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 6171 | } |
| 6172 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6173 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 6174 | { |
| 6175 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6176 | int pipe; |
| 6177 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6178 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6179 | I915_WRITE(DSPCNTR(pipe), |
| 6180 | I915_READ(DSPCNTR(pipe)) | |
| 6181 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 6182 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6183 | } |
| 6184 | } |
| 6185 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6186 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 6187 | { |
| 6188 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6189 | |
| 6190 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 6191 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 6192 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 6193 | |
| 6194 | /* |
| 6195 | * Don't touch WM1S_LP_EN here. |
| 6196 | * Doing so could cause underruns. |
| 6197 | */ |
| 6198 | } |
| 6199 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6200 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6201 | { |
| 6202 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6203 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6204 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 6205 | /* |
| 6206 | * Required for FBC |
| 6207 | * WaFbcDisableDpfcClockGating:ilk |
| 6208 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6209 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 6210 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 6211 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6212 | |
| 6213 | I915_WRITE(PCH_3DCGDIS0, |
| 6214 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 6215 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 6216 | I915_WRITE(PCH_3DCGDIS1, |
| 6217 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 6218 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6219 | /* |
| 6220 | * According to the spec the following bits should be set in |
| 6221 | * order to enable memory self-refresh |
| 6222 | * The bit 22/21 of 0x42004 |
| 6223 | * The bit 5 of 0x42020 |
| 6224 | * The bit 15 of 0x45000 |
| 6225 | */ |
| 6226 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6227 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6228 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6229 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6230 | I915_WRITE(DISP_ARB_CTL, |
| 6231 | (I915_READ(DISP_ARB_CTL) | |
| 6232 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6233 | |
| 6234 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6235 | |
| 6236 | /* |
| 6237 | * Based on the document from hardware guys the following bits |
| 6238 | * should be set unconditionally in order to enable FBC. |
| 6239 | * The bit 22 of 0x42000 |
| 6240 | * The bit 22 of 0x42004 |
| 6241 | * The bit 7,8,9 of 0x42020. |
| 6242 | */ |
| 6243 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6244 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6245 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6246 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6247 | ILK_FBCQ_DIS); |
| 6248 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6249 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6250 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6251 | } |
| 6252 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 6253 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 6254 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6255 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6256 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6257 | ILK_ELPIN_409_SELECT); |
| 6258 | I915_WRITE(_3D_CHICKEN2, |
| 6259 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 6260 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6261 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6262 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6263 | I915_WRITE(CACHE_MODE_0, |
| 6264 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6265 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6266 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 6267 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6268 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6269 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 6270 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6271 | ibx_init_clock_gating(dev); |
| 6272 | } |
| 6273 | |
| 6274 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 6275 | { |
| 6276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6277 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6278 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6279 | |
| 6280 | /* |
| 6281 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 6282 | * gating for the panel power sequencer or it will fail to |
| 6283 | * start up when no ports are active. |
| 6284 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 6285 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 6286 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 6287 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6288 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 6289 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 6290 | /* The below fixes the weird display corruption, a few pixels shifted |
| 6291 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 6292 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6293 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 6294 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 6295 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 6296 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6297 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6298 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 6299 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 6300 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 6301 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 6302 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 6303 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6304 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6305 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6306 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 6307 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 6308 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6309 | } |
| 6310 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6311 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 6312 | { |
| 6313 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6314 | uint32_t tmp; |
| 6315 | |
| 6316 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 6317 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 6318 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 6319 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6320 | } |
| 6321 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6322 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6323 | { |
| 6324 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6325 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6326 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6327 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6328 | |
| 6329 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6330 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6331 | ILK_ELPIN_409_SELECT); |
| 6332 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6333 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 6334 | I915_WRITE(_3D_CHICKEN, |
| 6335 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 6336 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6337 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 6338 | if (IS_SNB_GT1(dev)) |
| 6339 | I915_WRITE(GEN6_GT_MODE, |
| 6340 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 6341 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6342 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 6343 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6344 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6345 | /* |
| 6346 | * BSpec recoomends 8x4 when MSAA is used, |
| 6347 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6348 | * |
| 6349 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6350 | * disable bit, which we don't touch here, but it's good |
| 6351 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 6352 | */ |
| 6353 | I915_WRITE(GEN6_GT_MODE, |
| 6354 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 6355 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6356 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6357 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6358 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 6359 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6360 | |
| 6361 | I915_WRITE(GEN6_UCGCTL1, |
| 6362 | I915_READ(GEN6_UCGCTL1) | |
| 6363 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 6364 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 6365 | |
| 6366 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 6367 | * gating disable must be set. Failure to set it results in |
| 6368 | * flickering pixels due to Z write ordering failures after |
| 6369 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 6370 | * Sanctuary and Tropics, and apparently anything else with |
| 6371 | * alpha test or pixel discard. |
| 6372 | * |
| 6373 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 6374 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6375 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 6376 | * WaDisableRCCUnitClockGating:snb |
| 6377 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6378 | */ |
| 6379 | I915_WRITE(GEN6_UCGCTL2, |
| 6380 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 6381 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 6382 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 6383 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 6384 | I915_WRITE(_3D_CHICKEN3, |
| 6385 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6386 | |
| 6387 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 6388 | * Bspec says: |
| 6389 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 6390 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 6391 | */ |
| 6392 | I915_WRITE(_3D_CHICKEN3, |
| 6393 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 6394 | |
| 6395 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6396 | * According to the spec the following bits should be |
| 6397 | * set in order to enable memory self-refresh and fbc: |
| 6398 | * The bit21 and bit22 of 0x42000 |
| 6399 | * The bit21 and bit22 of 0x42004 |
| 6400 | * The bit5 and bit7 of 0x42020 |
| 6401 | * The bit14 of 0x70180 |
| 6402 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6403 | * |
| 6404 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6405 | */ |
| 6406 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6407 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6408 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6409 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6410 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6411 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6412 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 6413 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 6414 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 6415 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6416 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6417 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 6418 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6419 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6420 | |
| 6421 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 6425 | { |
| 6426 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 6427 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6428 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6429 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6430 | * |
| 6431 | * This actually overrides the dispatch |
| 6432 | * mode for all thread types. |
| 6433 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6434 | reg &= ~GEN7_FF_SCHED_MASK; |
| 6435 | reg |= GEN7_FF_TS_SCHED_HW; |
| 6436 | reg |= GEN7_FF_VS_SCHED_HW; |
| 6437 | reg |= GEN7_FF_DS_SCHED_HW; |
| 6438 | |
| 6439 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 6440 | } |
| 6441 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6442 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 6443 | { |
| 6444 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6445 | |
| 6446 | /* |
| 6447 | * TODO: this bit should only be enabled when really needed, then |
| 6448 | * disabled when not needed anymore in order to save power. |
| 6449 | */ |
| 6450 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 6451 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 6452 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6453 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6454 | |
| 6455 | /* WADPOClockGatingDisable:hsw */ |
| 6456 | I915_WRITE(_TRANSA_CHICKEN1, |
| 6457 | I915_READ(_TRANSA_CHICKEN1) | |
| 6458 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6459 | } |
| 6460 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6461 | static void lpt_suspend_hw(struct drm_device *dev) |
| 6462 | { |
| 6463 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6464 | |
| 6465 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 6466 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 6467 | |
| 6468 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6469 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6470 | } |
| 6471 | } |
| 6472 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6473 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6474 | { |
| 6475 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6476 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6477 | |
| 6478 | I915_WRITE(WM3_LP_ILK, 0); |
| 6479 | I915_WRITE(WM2_LP_ILK, 0); |
| 6480 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6481 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6482 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6483 | 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] | 6484 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6485 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6486 | I915_WRITE(CHICKEN_PAR1_1, |
| 6487 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6488 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6489 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6490 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6491 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6492 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6493 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6494 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6495 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6496 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6497 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6498 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6499 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6500 | ~(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] | 6501 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6502 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6503 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6504 | |
| 6505 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6506 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6507 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6508 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 6509 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6510 | } |
| 6511 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6512 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 6513 | { |
| 6514 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6515 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6516 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6517 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6518 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6519 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6520 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6521 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6522 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6523 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6524 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6525 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6526 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6527 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6528 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6529 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6530 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6531 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6532 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6533 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6534 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6535 | /* enable HiZ Raw Stall Optimization */ |
| 6536 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6537 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6538 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6539 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6540 | I915_WRITE(CACHE_MODE_1, |
| 6541 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6542 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6543 | /* |
| 6544 | * BSpec recommends 8x4 when MSAA is used, |
| 6545 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6546 | * |
| 6547 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6548 | * disable bit, which we don't touch here, but it's good |
| 6549 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6550 | */ |
| 6551 | I915_WRITE(GEN7_GT_MODE, |
| 6552 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 6553 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6554 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6555 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6556 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 6557 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 6558 | I915_WRITE(CHICKEN_PAR1_1, |
| 6559 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6560 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6561 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6562 | } |
| 6563 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6564 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6565 | { |
| 6566 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6567 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6568 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6569 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6570 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6571 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6572 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6573 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6574 | I915_WRITE(_3D_CHICKEN3, |
| 6575 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6576 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6577 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6578 | I915_WRITE(IVB_CHICKEN3, |
| 6579 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6580 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6581 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6582 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6583 | if (IS_IVB_GT1(dev)) |
| 6584 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6585 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6586 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6587 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6588 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6589 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6590 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6591 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6592 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6593 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6594 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6595 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6596 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6597 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6598 | GEN7_WA_L3_CHICKEN_MODE); |
| 6599 | if (IS_IVB_GT1(dev)) |
| 6600 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6601 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6602 | else { |
| 6603 | /* must write both registers */ |
| 6604 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6605 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6606 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6607 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6608 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6609 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6610 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6611 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6612 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6613 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6614 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6615 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6616 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6617 | */ |
| 6618 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6619 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6620 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6621 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6622 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6623 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6624 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6625 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6626 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6627 | |
| 6628 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6629 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6630 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6631 | /* enable HiZ Raw Stall Optimization */ |
| 6632 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6633 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6634 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6635 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6636 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6637 | I915_WRITE(CACHE_MODE_1, |
| 6638 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6639 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6640 | /* |
| 6641 | * BSpec recommends 8x4 when MSAA is used, |
| 6642 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6643 | * |
| 6644 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6645 | * disable bit, which we don't touch here, but it's good |
| 6646 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6647 | */ |
| 6648 | I915_WRITE(GEN7_GT_MODE, |
| 6649 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 6650 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6651 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6652 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6653 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6654 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6655 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6656 | if (!HAS_PCH_NOP(dev)) |
| 6657 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6658 | |
| 6659 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6660 | } |
| 6661 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6662 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6663 | { |
| 6664 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6665 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 6666 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6667 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6668 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6669 | I915_WRITE(_3D_CHICKEN3, |
| 6670 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6671 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6672 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6673 | I915_WRITE(IVB_CHICKEN3, |
| 6674 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6675 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6676 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6677 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6678 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6679 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6680 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6681 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6682 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6683 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6684 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6685 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6686 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6687 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6688 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6689 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6690 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6691 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6692 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6693 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6694 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6695 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6696 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6697 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6698 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6699 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6700 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6701 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6702 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6703 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6704 | */ |
| 6705 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6706 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6707 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6708 | /* WaDisableL3Bank2xClockGate:vlv |
| 6709 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6710 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6711 | I915_WRITE(GEN7_UCGCTL4, |
| 6712 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6713 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 6714 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6715 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6716 | /* |
| 6717 | * BSpec says this must be set, even though |
| 6718 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6719 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6720 | I915_WRITE(CACHE_MODE_1, |
| 6721 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6722 | |
| 6723 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6724 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6725 | * This is the hardware default actually. |
| 6726 | */ |
| 6727 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6728 | |
| 6729 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6730 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6731 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6732 | * in the reporting of vblank events. |
| 6733 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6734 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6735 | } |
| 6736 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6737 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6738 | { |
| 6739 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6740 | |
| 6741 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6742 | |
| 6743 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6744 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6745 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6746 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6747 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6748 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6749 | ~(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] | 6750 | |
| 6751 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6752 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6753 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6754 | |
| 6755 | /* WaDisableCSUnitClockGating:chv */ |
| 6756 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6757 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6758 | |
| 6759 | /* WaDisableSDEUnitClockGating:chv */ |
| 6760 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6761 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Rafael Barbalho | e0d34ce | 2014-04-09 13:28:40 +0300 | [diff] [blame] | 6762 | |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 6763 | /* WaDisableGunitClockGating:chv (pre-production hw) */ |
| 6764 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, I915_READ(VLV_GUNIT_CLOCK_GATE) | |
| 6765 | GINT_DIS); |
| 6766 | |
| 6767 | /* WaDisableFfDopClockGating:chv (pre-production hw) */ |
| 6768 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6769 | _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE)); |
| 6770 | |
| 6771 | /* WaDisableDopClockGating:chv (pre-production hw) */ |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 6772 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6773 | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6774 | } |
| 6775 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6776 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6777 | { |
| 6778 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6779 | uint32_t dspclk_gate; |
| 6780 | |
| 6781 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6782 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6783 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6784 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6785 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6786 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6787 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6788 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6789 | if (IS_GM45(dev)) |
| 6790 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6791 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6792 | |
| 6793 | /* WaDisableRenderCachePipelinedFlush */ |
| 6794 | I915_WRITE(CACHE_MODE_0, |
| 6795 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6796 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6797 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6798 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6799 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6800 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6801 | } |
| 6802 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6803 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6804 | { |
| 6805 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6806 | |
| 6807 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6808 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6809 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6810 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6811 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6812 | I915_WRITE(MI_ARB_STATE, |
| 6813 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6814 | |
| 6815 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6816 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6817 | } |
| 6818 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6819 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6820 | { |
| 6821 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6822 | |
| 6823 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6824 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6825 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6826 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6827 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6828 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6829 | I915_WRITE(MI_ARB_STATE, |
| 6830 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6831 | |
| 6832 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6833 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6834 | } |
| 6835 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6836 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6837 | { |
| 6838 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6839 | u32 dstate = I915_READ(D_STATE); |
| 6840 | |
| 6841 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6842 | DSTATE_DOT_CLOCK_GATING; |
| 6843 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6844 | |
| 6845 | if (IS_PINEVIEW(dev)) |
| 6846 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6847 | |
| 6848 | /* IIR "flip pending" means done if this bit is set */ |
| 6849 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6850 | |
| 6851 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6852 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6853 | |
| 6854 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6855 | I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6856 | |
| 6857 | I915_WRITE(MI_ARB_STATE, |
| 6858 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6859 | } |
| 6860 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6861 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6862 | { |
| 6863 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6864 | |
| 6865 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6866 | |
| 6867 | /* interrupts should cause a wake up from C3 */ |
| 6868 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6869 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6870 | |
| 6871 | I915_WRITE(MEM_MODE, |
| 6872 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6873 | } |
| 6874 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6875 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6876 | { |
| 6877 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6878 | |
| 6879 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6880 | |
| 6881 | I915_WRITE(MEM_MODE, |
| 6882 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6883 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6884 | } |
| 6885 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6886 | void intel_init_clock_gating(struct drm_device *dev) |
| 6887 | { |
| 6888 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6889 | |
| 6890 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6891 | } |
| 6892 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6893 | void intel_suspend_hw(struct drm_device *dev) |
| 6894 | { |
| 6895 | if (HAS_PCH_LPT(dev)) |
| 6896 | lpt_suspend_hw(dev); |
| 6897 | } |
| 6898 | |
Paulo Zanoni | d2dee86 | 2014-09-19 16:04:54 -0300 | [diff] [blame] | 6899 | static void intel_init_fbc(struct drm_i915_private *dev_priv) |
| 6900 | { |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 6901 | if (!HAS_FBC(dev_priv)) { |
| 6902 | dev_priv->fbc.enabled = false; |
Paulo Zanoni | d2dee86 | 2014-09-19 16:04:54 -0300 | [diff] [blame] | 6903 | return; |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 6904 | } |
Paulo Zanoni | d2dee86 | 2014-09-19 16:04:54 -0300 | [diff] [blame] | 6905 | |
| 6906 | if (INTEL_INFO(dev_priv)->gen >= 7) { |
| 6907 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 6908 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 6909 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6910 | } else if (INTEL_INFO(dev_priv)->gen >= 5) { |
| 6911 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 6912 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
| 6913 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 6914 | } else if (IS_GM45(dev_priv)) { |
| 6915 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 6916 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 6917 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
| 6918 | } else { |
| 6919 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 6920 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 6921 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
| 6922 | |
| 6923 | /* This value was pulled out of someone's hat */ |
| 6924 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
| 6925 | } |
Paulo Zanoni | 9adccc6 | 2014-09-19 16:04:55 -0300 | [diff] [blame] | 6926 | |
| 6927 | dev_priv->fbc.enabled = dev_priv->display.fbc_enabled(dev_priv->dev); |
Paulo Zanoni | d2dee86 | 2014-09-19 16:04:54 -0300 | [diff] [blame] | 6928 | } |
| 6929 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6930 | /* Set up chip specific power management-related functions */ |
| 6931 | void intel_init_pm(struct drm_device *dev) |
| 6932 | { |
| 6933 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6934 | |
Paulo Zanoni | d2dee86 | 2014-09-19 16:04:54 -0300 | [diff] [blame] | 6935 | intel_init_fbc(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6936 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6937 | /* For cxsr */ |
| 6938 | if (IS_PINEVIEW(dev)) |
| 6939 | i915_pineview_get_mem_freq(dev); |
| 6940 | else if (IS_GEN5(dev)) |
| 6941 | i915_ironlake_get_mem_freq(dev); |
| 6942 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6943 | /* For FIFO watermark updates */ |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6944 | if (IS_GEN9(dev)) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6945 | skl_setup_wm_latency(dev); |
| 6946 | |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6947 | dev_priv->display.init_clock_gating = gen9_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6948 | dev_priv->display.update_wm = skl_update_wm; |
| 6949 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6950 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6951 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6952 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6953 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6954 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6955 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6956 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6957 | dev_priv->display.update_wm = ilk_update_wm; |
| 6958 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6959 | } else { |
| 6960 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6961 | "Disable CxSR\n"); |
| 6962 | } |
| 6963 | |
| 6964 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6965 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6966 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6967 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6968 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6969 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6970 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6971 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6972 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6973 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6974 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 6975 | dev_priv->display.update_wm = cherryview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6976 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6977 | dev_priv->display.init_clock_gating = |
| 6978 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6979 | } else if (IS_VALLEYVIEW(dev)) { |
| 6980 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6981 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6982 | dev_priv->display.init_clock_gating = |
| 6983 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6984 | } else if (IS_PINEVIEW(dev)) { |
| 6985 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6986 | dev_priv->is_ddr3, |
| 6987 | dev_priv->fsb_freq, |
| 6988 | dev_priv->mem_freq)) { |
| 6989 | DRM_INFO("failed to find known CxSR latency " |
| 6990 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6991 | "disabling CxSR\n", |
| 6992 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6993 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6994 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6995 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6996 | dev_priv->display.update_wm = NULL; |
| 6997 | } else |
| 6998 | dev_priv->display.update_wm = pineview_update_wm; |
| 6999 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7000 | } else if (IS_G4X(dev)) { |
| 7001 | dev_priv->display.update_wm = g4x_update_wm; |
| 7002 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 7003 | } else if (IS_GEN4(dev)) { |
| 7004 | dev_priv->display.update_wm = i965_update_wm; |
| 7005 | if (IS_CRESTLINE(dev)) |
| 7006 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 7007 | else if (IS_BROADWATER(dev)) |
| 7008 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 7009 | } else if (IS_GEN3(dev)) { |
| 7010 | dev_priv->display.update_wm = i9xx_update_wm; |
| 7011 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 7012 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7013 | } else if (IS_GEN2(dev)) { |
| 7014 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 7015 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7016 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7017 | } else { |
| 7018 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7019 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7020 | } |
| 7021 | |
| 7022 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 7023 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 7024 | else |
| 7025 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7026 | } else { |
| 7027 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7028 | } |
| 7029 | } |
| 7030 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7031 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 7032 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7033 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7034 | |
| 7035 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 7036 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 7037 | return -EAGAIN; |
| 7038 | } |
| 7039 | |
| 7040 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 7041 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 7042 | I915_WRITE(GEN9_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7043 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 7044 | |
| 7045 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 7046 | 500)) { |
| 7047 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 7048 | return -ETIMEDOUT; |
| 7049 | } |
| 7050 | |
| 7051 | *val = I915_READ(GEN6_PCODE_DATA); |
| 7052 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 7053 | |
| 7054 | return 0; |
| 7055 | } |
| 7056 | |
| 7057 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 7058 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7059 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7060 | |
| 7061 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 7062 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 7063 | return -EAGAIN; |
| 7064 | } |
| 7065 | |
| 7066 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 7067 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 7068 | |
| 7069 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 7070 | 500)) { |
| 7071 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 7072 | return -ETIMEDOUT; |
| 7073 | } |
| 7074 | |
| 7075 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 7076 | |
| 7077 | return 0; |
| 7078 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 7079 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7080 | 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] | 7081 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7082 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7083 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7084 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7085 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7086 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7087 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7088 | break; |
| 7089 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7090 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7091 | break; |
| 7092 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7093 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7094 | break; |
| 7095 | default: |
| 7096 | return -1; |
| 7097 | } |
| 7098 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7099 | 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] | 7100 | } |
| 7101 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7102 | 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] | 7103 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7104 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7105 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7106 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7107 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7108 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7109 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7110 | break; |
| 7111 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7112 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7113 | break; |
| 7114 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7115 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7116 | break; |
| 7117 | default: |
| 7118 | return -1; |
| 7119 | } |
| 7120 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7121 | 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] | 7122 | } |
| 7123 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7124 | 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] | 7125 | { |
| 7126 | int div, freq; |
| 7127 | |
| 7128 | switch (dev_priv->rps.cz_freq) { |
| 7129 | case 200: |
| 7130 | div = 5; |
| 7131 | break; |
| 7132 | case 267: |
| 7133 | div = 6; |
| 7134 | break; |
| 7135 | case 320: |
| 7136 | case 333: |
| 7137 | case 400: |
| 7138 | div = 8; |
| 7139 | break; |
| 7140 | default: |
| 7141 | return -1; |
| 7142 | } |
| 7143 | |
| 7144 | freq = (DIV_ROUND_CLOSEST((dev_priv->rps.cz_freq * val), 2 * div) / 2); |
| 7145 | |
| 7146 | return freq; |
| 7147 | } |
| 7148 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7149 | 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] | 7150 | { |
| 7151 | int mul, opcode; |
| 7152 | |
| 7153 | switch (dev_priv->rps.cz_freq) { |
| 7154 | case 200: |
| 7155 | mul = 5; |
| 7156 | break; |
| 7157 | case 267: |
| 7158 | mul = 6; |
| 7159 | break; |
| 7160 | case 320: |
| 7161 | case 333: |
| 7162 | case 400: |
| 7163 | mul = 8; |
| 7164 | break; |
| 7165 | default: |
| 7166 | return -1; |
| 7167 | } |
| 7168 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7169 | /* CHV needs even values */ |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7170 | opcode = (DIV_ROUND_CLOSEST((val * 2 * mul), dev_priv->rps.cz_freq) * 2); |
| 7171 | |
| 7172 | return opcode; |
| 7173 | } |
| 7174 | |
| 7175 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 7176 | { |
| 7177 | int ret = -1; |
| 7178 | |
| 7179 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7180 | ret = chv_gpu_freq(dev_priv, val); |
| 7181 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7182 | ret = byt_gpu_freq(dev_priv, val); |
| 7183 | |
| 7184 | return ret; |
| 7185 | } |
| 7186 | |
| 7187 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 7188 | { |
| 7189 | int ret = -1; |
| 7190 | |
| 7191 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7192 | ret = chv_freq_opcode(dev_priv, val); |
| 7193 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7194 | ret = byt_freq_opcode(dev_priv, val); |
| 7195 | |
| 7196 | return ret; |
| 7197 | } |
| 7198 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7199 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7200 | { |
| 7201 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7202 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7203 | mutex_init(&dev_priv->rps.hw_lock); |
| 7204 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7205 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 7206 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 7207 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 7208 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7209 | } |