Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 31 | #include "../../../platform/x86/intel_ips.h" |
| 32 | #include <linux/module.h> |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Damien Lespiau | f4db932 | 2013-06-24 22:59:50 +0100 | [diff] [blame] | 34 | #include <drm/i915_powerwell.h> |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 35 | #include <linux/pm_runtime.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 36 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 37 | /** |
| 38 | * RC6 is a special power stage which allows the GPU to enter an very |
| 39 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 40 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 41 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 42 | * |
| 43 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 44 | * among each other with the latency required to enter and leave RC6 and |
| 45 | * voltage consumed by the GPU in different states. |
| 46 | * |
| 47 | * The combination of the following flags define which states GPU is allowed |
| 48 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 49 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 50 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 51 | * which brings the most power savings; deeper states save more power, but |
| 52 | * require higher latency to switch to and wake up. |
| 53 | */ |
| 54 | #define INTEL_RC6_ENABLE (1<<0) |
| 55 | #define INTEL_RC6p_ENABLE (1<<1) |
| 56 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 57 | |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 58 | /* FBC, or Frame Buffer Compression, is a technique employed to compress the |
| 59 | * framebuffer contents in-memory, aiming at reducing the required bandwidth |
| 60 | * during in-memory transfers and, therefore, reduce the power packet. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 61 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 62 | * The benefits of FBC are mostly visible with solid backgrounds and |
| 63 | * variation-less patterns. |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 64 | * |
Eugeni Dodonov | f6750b3 | 2012-04-18 11:51:14 -0300 | [diff] [blame] | 65 | * FBC-related functionality can be enabled by the means of the |
| 66 | * i915.i915_enable_fbc parameter |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 67 | */ |
| 68 | |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 69 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 70 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame^] | 71 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 72 | |
| 73 | /* |
| 74 | * WaDisableSDEUnitClockGating:skl |
| 75 | * This seems to be a pre-production w/a. |
| 76 | */ |
| 77 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 78 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 81 | static void i8xx_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 82 | { |
| 83 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 84 | u32 fbc_ctl; |
| 85 | |
| 86 | /* Disable compression */ |
| 87 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 88 | if ((fbc_ctl & FBC_CTL_EN) == 0) |
| 89 | return; |
| 90 | |
| 91 | fbc_ctl &= ~FBC_CTL_EN; |
| 92 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 93 | |
| 94 | /* Wait for compressing bit to clear */ |
| 95 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { |
| 96 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 101 | } |
| 102 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 103 | static void i8xx_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 104 | { |
| 105 | struct drm_device *dev = crtc->dev; |
| 106 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 107 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 108 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 109 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 110 | int cfb_pitch; |
Ville Syrjälä | 7f2cf22 | 2014-01-23 16:49:11 +0200 | [diff] [blame] | 111 | int i; |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 112 | u32 fbc_ctl; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 113 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 114 | cfb_pitch = dev_priv->fbc.size / FBC_LL_SIZE; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 115 | if (fb->pitches[0] < cfb_pitch) |
| 116 | cfb_pitch = fb->pitches[0]; |
| 117 | |
Ville Syrjälä | 42a430f | 2013-11-28 17:29:56 +0200 | [diff] [blame] | 118 | /* FBC_CTL wants 32B or 64B units */ |
| 119 | if (IS_GEN2(dev)) |
| 120 | cfb_pitch = (cfb_pitch / 32) - 1; |
| 121 | else |
| 122 | cfb_pitch = (cfb_pitch / 64) - 1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 123 | |
| 124 | /* Clear old tags */ |
| 125 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 126 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 127 | |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 128 | if (IS_GEN4(dev)) { |
| 129 | u32 fbc_ctl2; |
| 130 | |
| 131 | /* Set it up... */ |
| 132 | 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] | 133 | fbc_ctl2 |= FBC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 159f987 | 2013-11-28 17:29:57 +0200 | [diff] [blame] | 134 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
| 135 | I915_WRITE(FBC_FENCE_OFF, crtc->y); |
| 136 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 137 | |
| 138 | /* enable it... */ |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 139 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 140 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 141 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 142 | if (IS_I945GM(dev)) |
| 143 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 144 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 145 | fbc_ctl |= obj->fence_reg; |
| 146 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 147 | |
Ville Syrjälä | 5cd5410 | 2014-01-23 16:49:16 +0200 | [diff] [blame] | 148 | 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] | 149 | cfb_pitch, crtc->y, plane_name(intel_crtc->plane)); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 150 | } |
| 151 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 152 | static bool i8xx_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 153 | { |
| 154 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 155 | |
| 156 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 157 | } |
| 158 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 159 | static void g4x_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 160 | { |
| 161 | struct drm_device *dev = crtc->dev; |
| 162 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 163 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 164 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 165 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 166 | u32 dpfc_ctl; |
| 167 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 168 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane) | DPFC_SR_EN; |
| 169 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 170 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 171 | else |
| 172 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 173 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 174 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 175 | I915_WRITE(DPFC_FENCE_YOFF, crtc->y); |
| 176 | |
| 177 | /* enable it... */ |
Ville Syrjälä | fe74c1a | 2014-01-23 16:49:13 +0200 | [diff] [blame] | 178 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 179 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 180 | 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] | 181 | } |
| 182 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 183 | static void g4x_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 184 | { |
| 185 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 186 | u32 dpfc_ctl; |
| 187 | |
| 188 | /* Disable compression */ |
| 189 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 190 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 191 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 192 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 193 | |
| 194 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 195 | } |
| 196 | } |
| 197 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 198 | static bool g4x_fbc_enabled(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 | |
| 202 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 203 | } |
| 204 | |
| 205 | static void sandybridge_blit_fbc_update(struct drm_device *dev) |
| 206 | { |
| 207 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 208 | u32 blt_ecoskpd; |
| 209 | |
| 210 | /* Make sure blitter notifies FBC of writes */ |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 211 | |
| 212 | /* Blitter is part of Media powerwell on VLV. No impact of |
| 213 | * his param in other platforms for now */ |
| 214 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_MEDIA); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 215 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 216 | blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD); |
| 217 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY << |
| 218 | GEN6_BLITTER_LOCK_SHIFT; |
| 219 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 220 | blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY; |
| 221 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 222 | blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY << |
| 223 | GEN6_BLITTER_LOCK_SHIFT); |
| 224 | I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd); |
| 225 | POSTING_READ(GEN6_BLITTER_ECOSKPD); |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 226 | |
Deepak S | 940aece | 2013-11-23 14:55:43 +0530 | [diff] [blame] | 227 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_MEDIA); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 228 | } |
| 229 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 230 | static void ironlake_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 231 | { |
| 232 | struct drm_device *dev = crtc->dev; |
| 233 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 234 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 235 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 236 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 237 | u32 dpfc_ctl; |
| 238 | |
Ville Syrjälä | 46f3dab | 2014-01-23 16:49:14 +0200 | [diff] [blame] | 239 | dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 240 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 241 | dev_priv->fbc.threshold++; |
| 242 | |
| 243 | switch (dev_priv->fbc.threshold) { |
| 244 | case 4: |
| 245 | case 3: |
| 246 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 247 | break; |
| 248 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 249 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 250 | break; |
| 251 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 252 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 253 | break; |
| 254 | } |
Ville Syrjälä | d629336 | 2013-11-21 21:29:45 +0200 | [diff] [blame] | 255 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
| 256 | if (IS_GEN5(dev)) |
| 257 | dpfc_ctl |= obj->fence_reg; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 258 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 259 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 260 | 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] | 261 | /* enable it... */ |
| 262 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 263 | |
| 264 | if (IS_GEN6(dev)) { |
| 265 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 266 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 267 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 268 | sandybridge_blit_fbc_update(dev); |
| 269 | } |
| 270 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 271 | 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] | 272 | } |
| 273 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 274 | static void ironlake_disable_fbc(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 275 | { |
| 276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 277 | u32 dpfc_ctl; |
| 278 | |
| 279 | /* Disable compression */ |
| 280 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 281 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 282 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 283 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 284 | |
| 285 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 286 | } |
| 287 | } |
| 288 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 289 | static bool ironlake_fbc_enabled(struct drm_device *dev) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 290 | { |
| 291 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 292 | |
| 293 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 294 | } |
| 295 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 296 | static void gen7_enable_fbc(struct drm_crtc *crtc) |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 297 | { |
| 298 | struct drm_device *dev = crtc->dev; |
| 299 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 300 | struct drm_framebuffer *fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 301 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 302 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 303 | u32 dpfc_ctl; |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 304 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 305 | dpfc_ctl = IVB_DPFC_CTL_PLANE(intel_crtc->plane); |
| 306 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 307 | dev_priv->fbc.threshold++; |
| 308 | |
| 309 | switch (dev_priv->fbc.threshold) { |
| 310 | case 4: |
| 311 | case 3: |
| 312 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 313 | break; |
| 314 | case 2: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 315 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 316 | break; |
| 317 | case 1: |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 318 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 322 | dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN; |
| 323 | |
Rodrigo Vivi | da46f93 | 2014-08-01 02:04:45 -0700 | [diff] [blame] | 324 | if (dev_priv->fbc.false_color) |
| 325 | dpfc_ctl |= FBC_CTL_FALSE_COLOR; |
| 326 | |
Ville Syrjälä | 3fa2e0e | 2014-01-23 16:49:12 +0200 | [diff] [blame] | 327 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 328 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 329 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 7dd23ba | 2013-05-10 14:33:17 +0100 | [diff] [blame] | 330 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 331 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 332 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 333 | ILK_FBCQ_DIS); |
Rodrigo Vivi | 2855416 | 2013-05-06 19:37:37 -0300 | [diff] [blame] | 334 | } else { |
Ville Syrjälä | 2adb6db | 2014-03-05 13:05:46 +0200 | [diff] [blame] | 335 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 336 | I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe), |
| 337 | I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) | |
| 338 | HSW_FBCQ_DIS); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 339 | } |
Rodrigo Vivi | b74ea10 | 2013-05-09 14:08:38 -0300 | [diff] [blame] | 340 | |
Rodrigo Vivi | abe959c | 2013-05-06 19:37:33 -0300 | [diff] [blame] | 341 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 342 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
| 343 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y); |
| 344 | |
| 345 | sandybridge_blit_fbc_update(dev); |
| 346 | |
Ville Syrjälä | b19870e | 2013-11-06 23:02:25 +0200 | [diff] [blame] | 347 | 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] | 348 | } |
| 349 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 350 | bool intel_fbc_enabled(struct drm_device *dev) |
| 351 | { |
| 352 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 353 | |
| 354 | if (!dev_priv->display.fbc_enabled) |
| 355 | return false; |
| 356 | |
| 357 | return dev_priv->display.fbc_enabled(dev); |
| 358 | } |
| 359 | |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 360 | void gen8_fbc_sw_flush(struct drm_device *dev, u32 value) |
| 361 | { |
| 362 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 363 | |
| 364 | if (!IS_GEN8(dev)) |
| 365 | return; |
| 366 | |
| 367 | I915_WRITE(MSG_FBC_REND_STATE, value); |
| 368 | } |
| 369 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 370 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 371 | { |
| 372 | struct intel_fbc_work *work = |
| 373 | container_of(to_delayed_work(__work), |
| 374 | struct intel_fbc_work, work); |
| 375 | struct drm_device *dev = work->crtc->dev; |
| 376 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 377 | |
| 378 | mutex_lock(&dev->struct_mutex); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 379 | if (work == dev_priv->fbc.fbc_work) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 380 | /* Double check that we haven't switched fb without cancelling |
| 381 | * the prior work. |
| 382 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 383 | if (work->crtc->primary->fb == work->fb) { |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 384 | dev_priv->display.enable_fbc(work->crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 385 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 386 | dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 387 | dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id; |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 388 | dev_priv->fbc.y = work->crtc->y; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 389 | } |
| 390 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 391 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 392 | } |
| 393 | mutex_unlock(&dev->struct_mutex); |
| 394 | |
| 395 | kfree(work); |
| 396 | } |
| 397 | |
| 398 | static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv) |
| 399 | { |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 400 | if (dev_priv->fbc.fbc_work == NULL) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 401 | return; |
| 402 | |
| 403 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 404 | |
| 405 | /* Synchronisation is provided by struct_mutex and checking of |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 406 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 407 | * entirely asynchronously. |
| 408 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 409 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 410 | /* tasklet was killed before being run, clean up */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 411 | kfree(dev_priv->fbc.fbc_work); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 412 | |
| 413 | /* Mark the work as no longer wanted so that if it does |
| 414 | * wake-up (because the work was already running and waiting |
| 415 | * for our mutex), it will discover that is no longer |
| 416 | * necessary to run. |
| 417 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 418 | dev_priv->fbc.fbc_work = NULL; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 419 | } |
| 420 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 421 | static void intel_enable_fbc(struct drm_crtc *crtc) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 422 | { |
| 423 | struct intel_fbc_work *work; |
| 424 | struct drm_device *dev = crtc->dev; |
| 425 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 426 | |
| 427 | if (!dev_priv->display.enable_fbc) |
| 428 | return; |
| 429 | |
| 430 | intel_cancel_fbc_work(dev_priv); |
| 431 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 432 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 433 | if (work == NULL) { |
Paulo Zanoni | 6cdcb5e | 2013-06-12 17:27:29 -0300 | [diff] [blame] | 434 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 435 | dev_priv->display.enable_fbc(crtc); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | |
| 439 | work->crtc = crtc; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 440 | work->fb = crtc->primary->fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 441 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 442 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 443 | dev_priv->fbc.fbc_work = work; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 444 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 445 | /* Delay the actual enabling to let pageflipping cease and the |
| 446 | * display to settle before starting the compression. Note that |
| 447 | * this delay also serves a second purpose: it allows for a |
| 448 | * vblank to pass after disabling the FBC before we attempt |
| 449 | * to modify the control registers. |
| 450 | * |
| 451 | * A more complicated solution would involve tracking vblanks |
| 452 | * following the termination of the page-flipping sequence |
| 453 | * and indeed performing the enable as a co-routine and not |
| 454 | * waiting synchronously upon the vblank. |
Damien Lespiau | 7457d61 | 2013-06-07 17:41:07 +0100 | [diff] [blame] | 455 | * |
| 456 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 457 | */ |
| 458 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 459 | } |
| 460 | |
| 461 | void intel_disable_fbc(struct drm_device *dev) |
| 462 | { |
| 463 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 464 | |
| 465 | intel_cancel_fbc_work(dev_priv); |
| 466 | |
| 467 | if (!dev_priv->display.disable_fbc) |
| 468 | return; |
| 469 | |
| 470 | dev_priv->display.disable_fbc(dev); |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 471 | dev_priv->fbc.plane = -1; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 472 | } |
| 473 | |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 474 | static bool set_no_fbc_reason(struct drm_i915_private *dev_priv, |
| 475 | enum no_fbc_reason reason) |
| 476 | { |
| 477 | if (dev_priv->fbc.no_fbc_reason == reason) |
| 478 | return false; |
| 479 | |
| 480 | dev_priv->fbc.no_fbc_reason = reason; |
| 481 | return true; |
| 482 | } |
| 483 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 484 | /** |
| 485 | * intel_update_fbc - enable/disable FBC as needed |
| 486 | * @dev: the drm_device |
| 487 | * |
| 488 | * Set up the framebuffer compression hardware at mode set time. We |
| 489 | * enable it if possible: |
| 490 | * - plane A only (on pre-965) |
| 491 | * - no pixel mulitply/line duplication |
| 492 | * - no alpha buffer discard |
| 493 | * - no dual wide |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 494 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 495 | * |
| 496 | * We can't assume that any compression will take place (worst case), |
| 497 | * so the compressed buffer has to be the same size as the uncompressed |
| 498 | * one. It also must reside (along with the line length buffer) in |
| 499 | * stolen memory. |
| 500 | * |
| 501 | * We need to enable/disable FBC on a global basis. |
| 502 | */ |
| 503 | void intel_update_fbc(struct drm_device *dev) |
| 504 | { |
| 505 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 506 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
| 507 | struct intel_crtc *intel_crtc; |
| 508 | struct drm_framebuffer *fb; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 509 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 510 | const struct drm_display_mode *adjusted_mode; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 511 | unsigned int max_width, max_height; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 512 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 513 | if (!HAS_FBC(dev)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 514 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 515 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 516 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 517 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 518 | if (!i915.powersave) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 519 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 520 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 521 | return; |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 522 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 523 | |
| 524 | /* |
| 525 | * If FBC is already on, we just have to verify that we can |
| 526 | * keep it that way... |
| 527 | * Need to disable if: |
| 528 | * - more than one pipe is active |
| 529 | * - changing FBC params (stride, fence, mode) |
| 530 | * - new fb is too large to fit in compressed buffer |
| 531 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 532 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 533 | for_each_crtc(dev, tmp_crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 534 | if (intel_crtc_active(tmp_crtc) && |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 535 | to_intel_crtc(tmp_crtc)->primary_enabled) { |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 536 | if (crtc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 537 | if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES)) |
| 538 | DRM_DEBUG_KMS("more than one pipe active, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 539 | goto out_disable; |
| 540 | } |
| 541 | crtc = tmp_crtc; |
| 542 | } |
| 543 | } |
| 544 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 545 | if (!crtc || crtc->primary->fb == NULL) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 546 | if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT)) |
| 547 | DRM_DEBUG_KMS("no output, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 548 | goto out_disable; |
| 549 | } |
| 550 | |
| 551 | intel_crtc = to_intel_crtc(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 552 | fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 553 | obj = intel_fb_obj(fb); |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 554 | adjusted_mode = &intel_crtc->config.adjusted_mode; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 555 | |
Chris Wilson | 0368920 | 2014-06-06 10:37:11 +0100 | [diff] [blame] | 556 | if (i915.enable_fbc < 0) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 557 | if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT)) |
| 558 | DRM_DEBUG_KMS("disabled per chip default\n"); |
Damien Lespiau | 8a5729a | 2013-06-24 16:22:02 +0100 | [diff] [blame] | 559 | goto out_disable; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 560 | } |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 561 | if (!i915.enable_fbc) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 562 | if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM)) |
| 563 | DRM_DEBUG_KMS("fbc disabled per module param\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 564 | goto out_disable; |
| 565 | } |
Ville Syrjälä | ef644fd | 2013-09-04 18:25:21 +0300 | [diff] [blame] | 566 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 567 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 568 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 569 | DRM_DEBUG_KMS("mode incompatible with compression, " |
| 570 | "disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 571 | goto out_disable; |
| 572 | } |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 573 | |
Daisy Sun | 032843a | 2014-06-16 15:48:18 -0700 | [diff] [blame] | 574 | if (INTEL_INFO(dev)->gen >= 8 || IS_HASWELL(dev)) { |
| 575 | max_width = 4096; |
| 576 | max_height = 4096; |
| 577 | } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 578 | max_width = 4096; |
| 579 | max_height = 2048; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 580 | } else { |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 581 | max_width = 2048; |
| 582 | max_height = 1536; |
Paulo Zanoni | f85da86 | 2013-06-04 16:53:39 -0300 | [diff] [blame] | 583 | } |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 584 | if (intel_crtc->config.pipe_src_w > max_width || |
| 585 | intel_crtc->config.pipe_src_h > max_height) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 586 | if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE)) |
| 587 | DRM_DEBUG_KMS("mode too large for compression, disabling\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 588 | goto out_disable; |
| 589 | } |
Ben Widawsky | 8f94d24 | 2014-02-20 16:01:20 -0800 | [diff] [blame] | 590 | if ((INTEL_INFO(dev)->gen < 4 || HAS_DDI(dev)) && |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 591 | intel_crtc->plane != PLANE_A) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 592 | if (set_no_fbc_reason(dev_priv, FBC_BAD_PLANE)) |
Ville Syrjälä | c5a44aa | 2013-11-28 17:29:58 +0200 | [diff] [blame] | 593 | DRM_DEBUG_KMS("plane not A, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 594 | goto out_disable; |
| 595 | } |
| 596 | |
| 597 | /* The use of a CPU fence is mandatory in order to detect writes |
| 598 | * by the CPU to the scanout and trigger updates to the FBC. |
| 599 | */ |
| 600 | if (obj->tiling_mode != I915_TILING_X || |
| 601 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 602 | if (set_no_fbc_reason(dev_priv, FBC_NOT_TILED)) |
| 603 | DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n"); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 604 | goto out_disable; |
| 605 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 606 | if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
| 607 | to_intel_plane(crtc->primary)->rotation != BIT(DRM_ROTATE_0)) { |
| 608 | if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) |
| 609 | DRM_DEBUG_KMS("Rotation unsupported, disabling\n"); |
| 610 | goto out_disable; |
| 611 | } |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 612 | |
| 613 | /* If the kernel debugger is active, always disable compression */ |
| 614 | if (in_dbg_master()) |
| 615 | goto out_disable; |
| 616 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 617 | if (i915_gem_stolen_setup_compression(dev, obj->base.size, |
Ben Widawsky | 5e59f71 | 2014-06-30 10:41:24 -0700 | [diff] [blame] | 618 | drm_format_plane_cpp(fb->pixel_format, 0))) { |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 619 | if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL)) |
| 620 | DRM_DEBUG_KMS("framebuffer too large, disabling compression\n"); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 621 | goto out_disable; |
| 622 | } |
| 623 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 624 | /* If the scanout has not changed, don't modify the FBC settings. |
| 625 | * Note that we make the fundamental assumption that the fb->obj |
| 626 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 627 | * without first being decoupled from the scanout and FBC disabled. |
| 628 | */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 629 | if (dev_priv->fbc.plane == intel_crtc->plane && |
| 630 | dev_priv->fbc.fb_id == fb->base.id && |
| 631 | dev_priv->fbc.y == crtc->y) |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 632 | return; |
| 633 | |
| 634 | if (intel_fbc_enabled(dev)) { |
| 635 | /* We update FBC along two paths, after changing fb/crtc |
| 636 | * configuration (modeswitching) and after page-flipping |
| 637 | * finishes. For the latter, we know that not only did |
| 638 | * we disable the FBC at the start of the page-flip |
| 639 | * sequence, but also more than one vblank has passed. |
| 640 | * |
| 641 | * For the former case of modeswitching, it is possible |
| 642 | * to switch between two FBC valid configurations |
| 643 | * instantaneously so we do need to disable the FBC |
| 644 | * before we can modify its control registers. We also |
| 645 | * have to wait for the next vblank for that to take |
| 646 | * effect. However, since we delay enabling FBC we can |
| 647 | * assume that a vblank has passed since disabling and |
| 648 | * that we can safely alter the registers in the deferred |
| 649 | * callback. |
| 650 | * |
| 651 | * In the scenario that we go from a valid to invalid |
| 652 | * and then back to valid FBC configuration we have |
| 653 | * no strict enforcement that a vblank occurred since |
| 654 | * disabling the FBC. However, along all current pipe |
| 655 | * disabling paths we do need to wait for a vblank at |
| 656 | * some point. And we wait before enabling FBC anyway. |
| 657 | */ |
| 658 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
| 659 | intel_disable_fbc(dev); |
| 660 | } |
| 661 | |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 662 | intel_enable_fbc(crtc); |
Chris Wilson | 29ebf90 | 2013-07-27 17:23:55 +0100 | [diff] [blame] | 663 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 664 | return; |
| 665 | |
| 666 | out_disable: |
| 667 | /* Multiple disables should be harmless */ |
| 668 | if (intel_fbc_enabled(dev)) { |
| 669 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
| 670 | intel_disable_fbc(dev); |
| 671 | } |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 672 | i915_gem_stolen_cleanup_compression(dev); |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 673 | } |
| 674 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 675 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 676 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 677 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 678 | u32 tmp; |
| 679 | |
| 680 | tmp = I915_READ(CLKCFG); |
| 681 | |
| 682 | switch (tmp & CLKCFG_FSB_MASK) { |
| 683 | case CLKCFG_FSB_533: |
| 684 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 685 | break; |
| 686 | case CLKCFG_FSB_800: |
| 687 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 688 | break; |
| 689 | case CLKCFG_FSB_667: |
| 690 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 691 | break; |
| 692 | case CLKCFG_FSB_400: |
| 693 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 694 | break; |
| 695 | } |
| 696 | |
| 697 | switch (tmp & CLKCFG_MEM_MASK) { |
| 698 | case CLKCFG_MEM_533: |
| 699 | dev_priv->mem_freq = 533; |
| 700 | break; |
| 701 | case CLKCFG_MEM_667: |
| 702 | dev_priv->mem_freq = 667; |
| 703 | break; |
| 704 | case CLKCFG_MEM_800: |
| 705 | dev_priv->mem_freq = 800; |
| 706 | break; |
| 707 | } |
| 708 | |
| 709 | /* detect pineview DDR3 setting */ |
| 710 | tmp = I915_READ(CSHRDDR3CTL); |
| 711 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 712 | } |
| 713 | |
| 714 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 715 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 716 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 717 | u16 ddrpll, csipll; |
| 718 | |
| 719 | ddrpll = I915_READ16(DDRMPLL1); |
| 720 | csipll = I915_READ16(CSIPLL0); |
| 721 | |
| 722 | switch (ddrpll & 0xff) { |
| 723 | case 0xc: |
| 724 | dev_priv->mem_freq = 800; |
| 725 | break; |
| 726 | case 0x10: |
| 727 | dev_priv->mem_freq = 1066; |
| 728 | break; |
| 729 | case 0x14: |
| 730 | dev_priv->mem_freq = 1333; |
| 731 | break; |
| 732 | case 0x18: |
| 733 | dev_priv->mem_freq = 1600; |
| 734 | break; |
| 735 | default: |
| 736 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 737 | ddrpll & 0xff); |
| 738 | dev_priv->mem_freq = 0; |
| 739 | break; |
| 740 | } |
| 741 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 742 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 743 | |
| 744 | switch (csipll & 0x3ff) { |
| 745 | case 0x00c: |
| 746 | dev_priv->fsb_freq = 3200; |
| 747 | break; |
| 748 | case 0x00e: |
| 749 | dev_priv->fsb_freq = 3733; |
| 750 | break; |
| 751 | case 0x010: |
| 752 | dev_priv->fsb_freq = 4266; |
| 753 | break; |
| 754 | case 0x012: |
| 755 | dev_priv->fsb_freq = 4800; |
| 756 | break; |
| 757 | case 0x014: |
| 758 | dev_priv->fsb_freq = 5333; |
| 759 | break; |
| 760 | case 0x016: |
| 761 | dev_priv->fsb_freq = 5866; |
| 762 | break; |
| 763 | case 0x018: |
| 764 | dev_priv->fsb_freq = 6400; |
| 765 | break; |
| 766 | default: |
| 767 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 768 | csipll & 0x3ff); |
| 769 | dev_priv->fsb_freq = 0; |
| 770 | break; |
| 771 | } |
| 772 | |
| 773 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 774 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 775 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 776 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 777 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 778 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 782 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 783 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 784 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 785 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 786 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 787 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 788 | |
| 789 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 790 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 791 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 792 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 793 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 794 | |
| 795 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 796 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 797 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 798 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 799 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 800 | |
| 801 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 802 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 803 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 804 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 805 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 806 | |
| 807 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 808 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 809 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 810 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 811 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 812 | |
| 813 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 814 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 815 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 816 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 817 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 818 | }; |
| 819 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 820 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 821 | int is_ddr3, |
| 822 | int fsb, |
| 823 | int mem) |
| 824 | { |
| 825 | const struct cxsr_latency *latency; |
| 826 | int i; |
| 827 | |
| 828 | if (fsb == 0 || mem == 0) |
| 829 | return NULL; |
| 830 | |
| 831 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 832 | latency = &cxsr_latency_table[i]; |
| 833 | if (is_desktop == latency->is_desktop && |
| 834 | is_ddr3 == latency->is_ddr3 && |
| 835 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 836 | return latency; |
| 837 | } |
| 838 | |
| 839 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 840 | |
| 841 | return NULL; |
| 842 | } |
| 843 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 844 | 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] | 845 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 846 | struct drm_device *dev = dev_priv->dev; |
| 847 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 848 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 849 | if (IS_VALLEYVIEW(dev)) { |
| 850 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 851 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 852 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 853 | } else if (IS_PINEVIEW(dev)) { |
| 854 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 855 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 856 | I915_WRITE(DSPFW3, val); |
| 857 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 858 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 859 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 860 | I915_WRITE(FW_BLC_SELF, val); |
| 861 | } else if (IS_I915GM(dev)) { |
| 862 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 863 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 864 | I915_WRITE(INSTPM, val); |
| 865 | } else { |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 870 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /* |
| 874 | * Latency for FIFO fetches is dependent on several factors: |
| 875 | * - memory configuration (speed, channels) |
| 876 | * - chipset |
| 877 | * - current MCH state |
| 878 | * It can be fairly high in some situations, so here we assume a fairly |
| 879 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 880 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 881 | * and power consumption (set it too low to save power and we might see |
| 882 | * FIFO underruns and display "flicker"). |
| 883 | * |
| 884 | * A value of 5us seems to be a good balance; safe for very low end |
| 885 | * platforms but not overly aggressive on lower latency configs. |
| 886 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 887 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 888 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 889 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 890 | { |
| 891 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 892 | uint32_t dsparb = I915_READ(DSPARB); |
| 893 | int size; |
| 894 | |
| 895 | size = dsparb & 0x7f; |
| 896 | if (plane) |
| 897 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 898 | |
| 899 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 900 | plane ? "B" : "A", size); |
| 901 | |
| 902 | return size; |
| 903 | } |
| 904 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 905 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 906 | { |
| 907 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 908 | uint32_t dsparb = I915_READ(DSPARB); |
| 909 | int size; |
| 910 | |
| 911 | size = dsparb & 0x1ff; |
| 912 | if (plane) |
| 913 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 914 | size >>= 1; /* Convert to cachelines */ |
| 915 | |
| 916 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 917 | plane ? "B" : "A", size); |
| 918 | |
| 919 | return size; |
| 920 | } |
| 921 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 922 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 923 | { |
| 924 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 925 | uint32_t dsparb = I915_READ(DSPARB); |
| 926 | int size; |
| 927 | |
| 928 | size = dsparb & 0x7f; |
| 929 | size >>= 2; /* Convert to cachelines */ |
| 930 | |
| 931 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 932 | plane ? "B" : "A", |
| 933 | size); |
| 934 | |
| 935 | return size; |
| 936 | } |
| 937 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 938 | /* Pineview has different values for various configs */ |
| 939 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 940 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 941 | .max_wm = PINEVIEW_MAX_WM, |
| 942 | .default_wm = PINEVIEW_DFT_WM, |
| 943 | .guard_size = PINEVIEW_GUARD_WM, |
| 944 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 945 | }; |
| 946 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 947 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 948 | .max_wm = PINEVIEW_MAX_WM, |
| 949 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 950 | .guard_size = PINEVIEW_GUARD_WM, |
| 951 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 952 | }; |
| 953 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 954 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 955 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 956 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 957 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 958 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 959 | }; |
| 960 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 961 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 962 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 963 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 964 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 965 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 966 | }; |
| 967 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 968 | .fifo_size = G4X_FIFO_SIZE, |
| 969 | .max_wm = G4X_MAX_WM, |
| 970 | .default_wm = G4X_MAX_WM, |
| 971 | .guard_size = 2, |
| 972 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 973 | }; |
| 974 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 975 | .fifo_size = I965_CURSOR_FIFO, |
| 976 | .max_wm = I965_CURSOR_MAX_WM, |
| 977 | .default_wm = I965_CURSOR_DFT_WM, |
| 978 | .guard_size = 2, |
| 979 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 980 | }; |
| 981 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 982 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 983 | .max_wm = VALLEYVIEW_MAX_WM, |
| 984 | .default_wm = VALLEYVIEW_MAX_WM, |
| 985 | .guard_size = 2, |
| 986 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 987 | }; |
| 988 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 989 | .fifo_size = I965_CURSOR_FIFO, |
| 990 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 991 | .default_wm = I965_CURSOR_DFT_WM, |
| 992 | .guard_size = 2, |
| 993 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 994 | }; |
| 995 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 996 | .fifo_size = I965_CURSOR_FIFO, |
| 997 | .max_wm = I965_CURSOR_MAX_WM, |
| 998 | .default_wm = I965_CURSOR_DFT_WM, |
| 999 | .guard_size = 2, |
| 1000 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1001 | }; |
| 1002 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1003 | .fifo_size = I945_FIFO_SIZE, |
| 1004 | .max_wm = I915_MAX_WM, |
| 1005 | .default_wm = 1, |
| 1006 | .guard_size = 2, |
| 1007 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1008 | }; |
| 1009 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1010 | .fifo_size = I915_FIFO_SIZE, |
| 1011 | .max_wm = I915_MAX_WM, |
| 1012 | .default_wm = 1, |
| 1013 | .guard_size = 2, |
| 1014 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1015 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1016 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1017 | .fifo_size = I855GM_FIFO_SIZE, |
| 1018 | .max_wm = I915_MAX_WM, |
| 1019 | .default_wm = 1, |
| 1020 | .guard_size = 2, |
| 1021 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1022 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1023 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 1024 | .fifo_size = I855GM_FIFO_SIZE, |
| 1025 | .max_wm = I915_MAX_WM/2, |
| 1026 | .default_wm = 1, |
| 1027 | .guard_size = 2, |
| 1028 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 1029 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1030 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 1031 | .fifo_size = I830_FIFO_SIZE, |
| 1032 | .max_wm = I915_MAX_WM, |
| 1033 | .default_wm = 1, |
| 1034 | .guard_size = 2, |
| 1035 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1036 | }; |
| 1037 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1038 | /** |
| 1039 | * intel_calculate_wm - calculate watermark level |
| 1040 | * @clock_in_khz: pixel clock |
| 1041 | * @wm: chip FIFO params |
| 1042 | * @pixel_size: display pixel size |
| 1043 | * @latency_ns: memory latency for the platform |
| 1044 | * |
| 1045 | * Calculate the watermark level (the level at which the display plane will |
| 1046 | * start fetching from memory again). Each chip has a different display |
| 1047 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 1048 | * in the correct intel_watermark_params structure. |
| 1049 | * |
| 1050 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 1051 | * on the pixel size. When it reaches the watermark level, it'll start |
| 1052 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 1053 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 1054 | * will occur, and a display engine hang could result. |
| 1055 | */ |
| 1056 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 1057 | const struct intel_watermark_params *wm, |
| 1058 | int fifo_size, |
| 1059 | int pixel_size, |
| 1060 | unsigned long latency_ns) |
| 1061 | { |
| 1062 | long entries_required, wm_size; |
| 1063 | |
| 1064 | /* |
| 1065 | * Note: we need to make sure we don't overflow for various clock & |
| 1066 | * latency values. |
| 1067 | * clocks go from a few thousand to several hundred thousand. |
| 1068 | * latency is usually a few thousand |
| 1069 | */ |
| 1070 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 1071 | 1000; |
| 1072 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 1073 | |
| 1074 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 1075 | |
| 1076 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 1077 | |
| 1078 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 1079 | |
| 1080 | /* Don't promote wm_size to unsigned... */ |
| 1081 | if (wm_size > (long)wm->max_wm) |
| 1082 | wm_size = wm->max_wm; |
| 1083 | if (wm_size <= 0) |
| 1084 | wm_size = wm->default_wm; |
| 1085 | return wm_size; |
| 1086 | } |
| 1087 | |
| 1088 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 1089 | { |
| 1090 | struct drm_crtc *crtc, *enabled = NULL; |
| 1091 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 1092 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1093 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1094 | if (enabled) |
| 1095 | return NULL; |
| 1096 | enabled = crtc; |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | return enabled; |
| 1101 | } |
| 1102 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1103 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1104 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1105 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1106 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1107 | struct drm_crtc *crtc; |
| 1108 | const struct cxsr_latency *latency; |
| 1109 | u32 reg; |
| 1110 | unsigned long wm; |
| 1111 | |
| 1112 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 1113 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 1114 | if (!latency) { |
| 1115 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1116 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1117 | return; |
| 1118 | } |
| 1119 | |
| 1120 | crtc = single_enabled_crtc(dev); |
| 1121 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1122 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1123 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1124 | int clock; |
| 1125 | |
| 1126 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1127 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1128 | |
| 1129 | /* Display SR */ |
| 1130 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 1131 | pineview_display_wm.fifo_size, |
| 1132 | pixel_size, latency->display_sr); |
| 1133 | reg = I915_READ(DSPFW1); |
| 1134 | reg &= ~DSPFW_SR_MASK; |
| 1135 | reg |= wm << DSPFW_SR_SHIFT; |
| 1136 | I915_WRITE(DSPFW1, reg); |
| 1137 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 1138 | |
| 1139 | /* cursor SR */ |
| 1140 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 1141 | pineview_display_wm.fifo_size, |
| 1142 | pixel_size, latency->cursor_sr); |
| 1143 | reg = I915_READ(DSPFW3); |
| 1144 | reg &= ~DSPFW_CURSOR_SR_MASK; |
| 1145 | reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; |
| 1146 | I915_WRITE(DSPFW3, reg); |
| 1147 | |
| 1148 | /* Display HPLL off SR */ |
| 1149 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 1150 | pineview_display_hplloff_wm.fifo_size, |
| 1151 | pixel_size, latency->display_hpll_disable); |
| 1152 | reg = I915_READ(DSPFW3); |
| 1153 | reg &= ~DSPFW_HPLL_SR_MASK; |
| 1154 | reg |= wm & DSPFW_HPLL_SR_MASK; |
| 1155 | I915_WRITE(DSPFW3, reg); |
| 1156 | |
| 1157 | /* cursor HPLL off SR */ |
| 1158 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 1159 | pineview_display_hplloff_wm.fifo_size, |
| 1160 | pixel_size, latency->cursor_hpll_disable); |
| 1161 | reg = I915_READ(DSPFW3); |
| 1162 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
| 1163 | reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; |
| 1164 | I915_WRITE(DSPFW3, reg); |
| 1165 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 1166 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1167 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1168 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1169 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 1174 | int plane, |
| 1175 | const struct intel_watermark_params *display, |
| 1176 | int display_latency_ns, |
| 1177 | const struct intel_watermark_params *cursor, |
| 1178 | int cursor_latency_ns, |
| 1179 | int *plane_wm, |
| 1180 | int *cursor_wm) |
| 1181 | { |
| 1182 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1183 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1184 | int htotal, hdisplay, clock, pixel_size; |
| 1185 | int line_time_us, line_count; |
| 1186 | int entries, tlb_miss; |
| 1187 | |
| 1188 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1189 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1190 | *cursor_wm = cursor->guard_size; |
| 1191 | *plane_wm = display->guard_size; |
| 1192 | return false; |
| 1193 | } |
| 1194 | |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1195 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1196 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1197 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1198 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1199 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1200 | |
| 1201 | /* Use the small buffer method to calculate plane watermark */ |
| 1202 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 1203 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 1204 | if (tlb_miss > 0) |
| 1205 | entries += tlb_miss; |
| 1206 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 1207 | *plane_wm = entries + display->guard_size; |
| 1208 | if (*plane_wm > (int)display->max_wm) |
| 1209 | *plane_wm = display->max_wm; |
| 1210 | |
| 1211 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1212 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1213 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1214 | entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1215 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 1216 | if (tlb_miss > 0) |
| 1217 | entries += tlb_miss; |
| 1218 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1219 | *cursor_wm = entries + cursor->guard_size; |
| 1220 | if (*cursor_wm > (int)cursor->max_wm) |
| 1221 | *cursor_wm = (int)cursor->max_wm; |
| 1222 | |
| 1223 | return true; |
| 1224 | } |
| 1225 | |
| 1226 | /* |
| 1227 | * Check the wm result. |
| 1228 | * |
| 1229 | * If any calculated watermark values is larger than the maximum value that |
| 1230 | * can be programmed into the associated watermark register, that watermark |
| 1231 | * must be disabled. |
| 1232 | */ |
| 1233 | static bool g4x_check_srwm(struct drm_device *dev, |
| 1234 | int display_wm, int cursor_wm, |
| 1235 | const struct intel_watermark_params *display, |
| 1236 | const struct intel_watermark_params *cursor) |
| 1237 | { |
| 1238 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 1239 | display_wm, cursor_wm); |
| 1240 | |
| 1241 | if (display_wm > display->max_wm) { |
| 1242 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 1243 | display_wm, display->max_wm); |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
| 1247 | if (cursor_wm > cursor->max_wm) { |
| 1248 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 1249 | cursor_wm, cursor->max_wm); |
| 1250 | return false; |
| 1251 | } |
| 1252 | |
| 1253 | if (!(display_wm || cursor_wm)) { |
| 1254 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
| 1258 | return true; |
| 1259 | } |
| 1260 | |
| 1261 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 1262 | int plane, |
| 1263 | int latency_ns, |
| 1264 | const struct intel_watermark_params *display, |
| 1265 | const struct intel_watermark_params *cursor, |
| 1266 | int *display_wm, int *cursor_wm) |
| 1267 | { |
| 1268 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1269 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1270 | int hdisplay, htotal, pixel_size, clock; |
| 1271 | unsigned long line_time_us; |
| 1272 | int line_count, line_size; |
| 1273 | int small, large; |
| 1274 | int entries; |
| 1275 | |
| 1276 | if (!latency_ns) { |
| 1277 | *display_wm = *cursor_wm = 0; |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1282 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1283 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1284 | htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1285 | hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1286 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1287 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1288 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1289 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 1290 | line_size = hdisplay * pixel_size; |
| 1291 | |
| 1292 | /* Use the minimum of the small and large buffer method for primary */ |
| 1293 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 1294 | large = line_count * line_size; |
| 1295 | |
| 1296 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 1297 | *display_wm = entries + display->guard_size; |
| 1298 | |
| 1299 | /* calculate the self-refresh watermark for display cursor */ |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1300 | entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1301 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 1302 | *cursor_wm = entries + cursor->guard_size; |
| 1303 | |
| 1304 | return g4x_check_srwm(dev, |
| 1305 | *display_wm, *cursor_wm, |
| 1306 | display, cursor); |
| 1307 | } |
| 1308 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1309 | static bool vlv_compute_drain_latency(struct drm_crtc *crtc, |
| 1310 | int pixel_size, |
| 1311 | int *prec_mult, |
| 1312 | int *drain_latency) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1313 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1314 | int entries; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1315 | int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1316 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1317 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1318 | return false; |
| 1319 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1320 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
| 1321 | return false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1322 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 1323 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1324 | *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_64 : |
| 1325 | DRAIN_LATENCY_PRECISION_32; |
| 1326 | *drain_latency = (64 * (*prec_mult) * 4) / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1327 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 1328 | if (*drain_latency > DRAIN_LATENCY_MASK) |
| 1329 | *drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1330 | |
| 1331 | return true; |
| 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * Update drain latency registers of memory arbiter |
| 1336 | * |
| 1337 | * Valleyview SoC has a new memory arbiter and needs drain latency registers |
| 1338 | * to be programmed. Each plane has a drain latency multiplier and a drain |
| 1339 | * latency value. |
| 1340 | */ |
| 1341 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 1342 | static void vlv_update_drain_latency(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1343 | { |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1344 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1345 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1346 | int pixel_size; |
| 1347 | int drain_latency; |
| 1348 | enum pipe pipe = intel_crtc->pipe; |
| 1349 | int plane_prec, prec_mult, plane_dl; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1350 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1351 | plane_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_PLANE_PRECISION_64 | |
| 1352 | DRAIN_LATENCY_MASK | DDL_CURSOR_PRECISION_64 | |
| 1353 | (DRAIN_LATENCY_MASK << DDL_CURSOR_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1354 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1355 | if (!intel_crtc_active(crtc)) { |
| 1356 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
| 1357 | return; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1358 | } |
| 1359 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1360 | /* Primary plane Drain Latency */ |
| 1361 | pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */ |
| 1362 | if (vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
| 1363 | plane_prec = (prec_mult == DRAIN_LATENCY_PRECISION_64) ? |
| 1364 | DDL_PLANE_PRECISION_64 : |
| 1365 | DDL_PLANE_PRECISION_32; |
| 1366 | plane_dl |= plane_prec | drain_latency; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1367 | } |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1368 | |
| 1369 | /* Cursor Drain Latency |
| 1370 | * BPP is always 4 for cursor |
| 1371 | */ |
| 1372 | pixel_size = 4; |
| 1373 | |
| 1374 | /* Program cursor DL only if it is enabled */ |
| 1375 | if (intel_crtc->cursor_base && |
| 1376 | vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) { |
| 1377 | plane_prec = (prec_mult == DRAIN_LATENCY_PRECISION_64) ? |
| 1378 | DDL_CURSOR_PRECISION_64 : |
| 1379 | DDL_CURSOR_PRECISION_32; |
| 1380 | plane_dl |= plane_prec | (drain_latency << DDL_CURSOR_SHIFT); |
| 1381 | } |
| 1382 | |
| 1383 | I915_WRITE(VLV_DDL(pipe), plane_dl); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1387 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1388 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1389 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1390 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1391 | static const int sr_latency_ns = 12000; |
| 1392 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1393 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1394 | int plane_sr, cursor_sr; |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1395 | int ignore_plane_sr, ignore_cursor_sr; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1396 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1397 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1398 | |
Gajanan Bhat | 41aad81 | 2014-07-16 18:24:03 +0530 | [diff] [blame] | 1399 | vlv_update_drain_latency(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1400 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1401 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1402 | &valleyview_wm_info, pessimal_latency_ns, |
| 1403 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1404 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1405 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1406 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1407 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1408 | &valleyview_wm_info, pessimal_latency_ns, |
| 1409 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1410 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1411 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1412 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1413 | if (single_plane_enabled(enabled) && |
| 1414 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1415 | sr_latency_ns, |
| 1416 | &valleyview_wm_info, |
| 1417 | &valleyview_cursor_wm_info, |
Chris Wilson | af6c457 | 2012-12-11 12:01:43 +0000 | [diff] [blame] | 1418 | &plane_sr, &ignore_cursor_sr) && |
| 1419 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1420 | 2*sr_latency_ns, |
| 1421 | &valleyview_wm_info, |
| 1422 | &valleyview_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1423 | &ignore_plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1424 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1425 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1426 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1427 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1428 | plane_sr = cursor_sr = 0; |
| 1429 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1430 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1431 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1432 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1433 | planea_wm, cursora_wm, |
| 1434 | planeb_wm, cursorb_wm, |
| 1435 | plane_sr, cursor_sr); |
| 1436 | |
| 1437 | I915_WRITE(DSPFW1, |
| 1438 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1439 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1440 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1441 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1442 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1443 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1444 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1445 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1446 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1447 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1448 | |
| 1449 | if (cxsr_enabled) |
| 1450 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1451 | } |
| 1452 | |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1453 | static void cherryview_update_wm(struct drm_crtc *crtc) |
| 1454 | { |
| 1455 | struct drm_device *dev = crtc->dev; |
| 1456 | static const int sr_latency_ns = 12000; |
| 1457 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1458 | int planea_wm, planeb_wm, planec_wm; |
| 1459 | int cursora_wm, cursorb_wm, cursorc_wm; |
| 1460 | int plane_sr, cursor_sr; |
| 1461 | int ignore_plane_sr, ignore_cursor_sr; |
| 1462 | unsigned int enabled = 0; |
| 1463 | bool cxsr_enabled; |
| 1464 | |
| 1465 | vlv_update_drain_latency(crtc); |
| 1466 | |
| 1467 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1468 | &valleyview_wm_info, pessimal_latency_ns, |
| 1469 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1470 | &planea_wm, &cursora_wm)) |
| 1471 | enabled |= 1 << PIPE_A; |
| 1472 | |
| 1473 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1474 | &valleyview_wm_info, pessimal_latency_ns, |
| 1475 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1476 | &planeb_wm, &cursorb_wm)) |
| 1477 | enabled |= 1 << PIPE_B; |
| 1478 | |
| 1479 | if (g4x_compute_wm0(dev, PIPE_C, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1480 | &valleyview_wm_info, pessimal_latency_ns, |
| 1481 | &valleyview_cursor_wm_info, pessimal_latency_ns, |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1482 | &planec_wm, &cursorc_wm)) |
| 1483 | enabled |= 1 << PIPE_C; |
| 1484 | |
| 1485 | if (single_plane_enabled(enabled) && |
| 1486 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1487 | sr_latency_ns, |
| 1488 | &valleyview_wm_info, |
| 1489 | &valleyview_cursor_wm_info, |
| 1490 | &plane_sr, &ignore_cursor_sr) && |
| 1491 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1492 | 2*sr_latency_ns, |
| 1493 | &valleyview_wm_info, |
| 1494 | &valleyview_cursor_wm_info, |
| 1495 | &ignore_plane_sr, &cursor_sr)) { |
| 1496 | cxsr_enabled = true; |
| 1497 | } else { |
| 1498 | cxsr_enabled = false; |
| 1499 | intel_set_memory_cxsr(dev_priv, false); |
| 1500 | plane_sr = cursor_sr = 0; |
| 1501 | } |
| 1502 | |
| 1503 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1504 | "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, " |
| 1505 | "SR: plane=%d, cursor=%d\n", |
| 1506 | planea_wm, cursora_wm, |
| 1507 | planeb_wm, cursorb_wm, |
| 1508 | planec_wm, cursorc_wm, |
| 1509 | plane_sr, cursor_sr); |
| 1510 | |
| 1511 | I915_WRITE(DSPFW1, |
| 1512 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1513 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1514 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
| 1515 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
| 1516 | I915_WRITE(DSPFW2, |
| 1517 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
| 1518 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1519 | I915_WRITE(DSPFW3, |
| 1520 | (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) | |
| 1521 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
| 1522 | I915_WRITE(DSPFW9_CHV, |
| 1523 | (I915_READ(DSPFW9_CHV) & ~(DSPFW_PLANEC_MASK | |
| 1524 | DSPFW_CURSORC_MASK)) | |
| 1525 | (planec_wm << DSPFW_PLANEC_SHIFT) | |
| 1526 | (cursorc_wm << DSPFW_CURSORC_SHIFT)); |
| 1527 | |
| 1528 | if (cxsr_enabled) |
| 1529 | intel_set_memory_cxsr(dev_priv, true); |
| 1530 | } |
| 1531 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1532 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1533 | struct drm_crtc *crtc, |
| 1534 | uint32_t sprite_width, |
| 1535 | uint32_t sprite_height, |
| 1536 | int pixel_size, |
| 1537 | bool enabled, bool scaled) |
| 1538 | { |
| 1539 | struct drm_device *dev = crtc->dev; |
| 1540 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1541 | int pipe = to_intel_plane(plane)->pipe; |
| 1542 | int sprite = to_intel_plane(plane)->plane; |
| 1543 | int drain_latency; |
| 1544 | int plane_prec; |
| 1545 | int sprite_dl; |
| 1546 | int prec_mult; |
| 1547 | |
| 1548 | sprite_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_SPRITE_PRECISION_64(sprite) | |
| 1549 | (DRAIN_LATENCY_MASK << DDL_SPRITE_SHIFT(sprite))); |
| 1550 | |
| 1551 | if (enabled && vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, |
| 1552 | &drain_latency)) { |
| 1553 | plane_prec = (prec_mult == DRAIN_LATENCY_PRECISION_64) ? |
| 1554 | DDL_SPRITE_PRECISION_64(sprite) : |
| 1555 | DDL_SPRITE_PRECISION_32(sprite); |
| 1556 | sprite_dl |= plane_prec | |
| 1557 | (drain_latency << DDL_SPRITE_SHIFT(sprite)); |
| 1558 | } |
| 1559 | |
| 1560 | I915_WRITE(VLV_DDL(pipe), sprite_dl); |
| 1561 | } |
| 1562 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1563 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1564 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1565 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1566 | static const int sr_latency_ns = 12000; |
| 1567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1568 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1569 | int plane_sr, cursor_sr; |
| 1570 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1571 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1572 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1573 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1574 | &g4x_wm_info, pessimal_latency_ns, |
| 1575 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1576 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1577 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1578 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1579 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1580 | &g4x_wm_info, pessimal_latency_ns, |
| 1581 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1582 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1583 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1584 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1585 | if (single_plane_enabled(enabled) && |
| 1586 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1587 | sr_latency_ns, |
| 1588 | &g4x_wm_info, |
| 1589 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1590 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1591 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1592 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1593 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1594 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1595 | plane_sr = cursor_sr = 0; |
| 1596 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1597 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1598 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1599 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1600 | planea_wm, cursora_wm, |
| 1601 | planeb_wm, cursorb_wm, |
| 1602 | plane_sr, cursor_sr); |
| 1603 | |
| 1604 | I915_WRITE(DSPFW1, |
| 1605 | (plane_sr << DSPFW_SR_SHIFT) | |
| 1606 | (cursorb_wm << DSPFW_CURSORB_SHIFT) | |
| 1607 | (planeb_wm << DSPFW_PLANEB_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1608 | (planea_wm << DSPFW_PLANEA_SHIFT)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1609 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1610 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1611 | (cursora_wm << DSPFW_CURSORA_SHIFT)); |
| 1612 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1613 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1614 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1615 | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1616 | |
| 1617 | if (cxsr_enabled) |
| 1618 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1619 | } |
| 1620 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1621 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1622 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1623 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1624 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1625 | struct drm_crtc *crtc; |
| 1626 | int srwm = 1; |
| 1627 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1628 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1629 | |
| 1630 | /* Calc sr entries for one plane configs */ |
| 1631 | crtc = single_enabled_crtc(dev); |
| 1632 | if (crtc) { |
| 1633 | /* self-refresh has much higher latency */ |
| 1634 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1635 | const struct drm_display_mode *adjusted_mode = |
| 1636 | &to_intel_crtc(crtc)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1637 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1638 | int htotal = adjusted_mode->crtc_htotal; |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1639 | int hdisplay = to_intel_crtc(crtc)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1640 | int pixel_size = crtc->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1641 | unsigned long line_time_us; |
| 1642 | int entries; |
| 1643 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1644 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1645 | |
| 1646 | /* Use ns/us then divide to preserve precision */ |
| 1647 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1648 | pixel_size * hdisplay; |
| 1649 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1650 | srwm = I965_FIFO_SIZE - entries; |
| 1651 | if (srwm < 0) |
| 1652 | srwm = 1; |
| 1653 | srwm &= 0x1ff; |
| 1654 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1655 | entries, srwm); |
| 1656 | |
| 1657 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Chris Wilson | 7bb836d | 2014-03-26 12:38:14 +0000 | [diff] [blame] | 1658 | pixel_size * to_intel_crtc(crtc)->cursor_width; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1659 | entries = DIV_ROUND_UP(entries, |
| 1660 | i965_cursor_wm_info.cacheline_size); |
| 1661 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1662 | (entries + i965_cursor_wm_info.guard_size); |
| 1663 | |
| 1664 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1665 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1666 | |
| 1667 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1668 | "cursor %d\n", srwm, cursor_sr); |
| 1669 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1670 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1671 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1672 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1673 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1674 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1678 | srwm); |
| 1679 | |
| 1680 | /* 965 has limitations... */ |
| 1681 | I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) | |
Ville Syrjälä | 0a56067 | 2014-06-11 16:51:18 +0300 | [diff] [blame] | 1682 | (8 << DSPFW_CURSORB_SHIFT) | |
| 1683 | (8 << DSPFW_PLANEB_SHIFT) | |
| 1684 | (8 << DSPFW_PLANEA_SHIFT)); |
| 1685 | I915_WRITE(DSPFW2, (8 << DSPFW_CURSORA_SHIFT) | |
| 1686 | (8 << DSPFW_PLANEC_SHIFT_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1687 | /* update cursor SR watermark */ |
| 1688 | I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1689 | |
| 1690 | if (cxsr_enabled) |
| 1691 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1692 | } |
| 1693 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1694 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1695 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1696 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1697 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1698 | const struct intel_watermark_params *wm_info; |
| 1699 | uint32_t fwater_lo; |
| 1700 | uint32_t fwater_hi; |
| 1701 | int cwm, srwm = 1; |
| 1702 | int fifo_size; |
| 1703 | int planea_wm, planeb_wm; |
| 1704 | struct drm_crtc *crtc, *enabled = NULL; |
| 1705 | |
| 1706 | if (IS_I945GM(dev)) |
| 1707 | wm_info = &i945_wm_info; |
| 1708 | else if (!IS_GEN2(dev)) |
| 1709 | wm_info = &i915_wm_info; |
| 1710 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1711 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1712 | |
| 1713 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1714 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1715 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1716 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1717 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1718 | if (IS_GEN2(dev)) |
| 1719 | cpp = 4; |
| 1720 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1721 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1722 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1723 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1724 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1725 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1726 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1727 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1728 | if (planea_wm > (long)wm_info->max_wm) |
| 1729 | planea_wm = wm_info->max_wm; |
| 1730 | } |
| 1731 | |
| 1732 | if (IS_GEN2(dev)) |
| 1733 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1734 | |
| 1735 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1736 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1737 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1738 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1739 | int cpp = crtc->primary->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1740 | if (IS_GEN2(dev)) |
| 1741 | cpp = 4; |
| 1742 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1743 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1744 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1745 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1746 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1747 | if (enabled == NULL) |
| 1748 | enabled = crtc; |
| 1749 | else |
| 1750 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1751 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1752 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1753 | if (planeb_wm > (long)wm_info->max_wm) |
| 1754 | planeb_wm = wm_info->max_wm; |
| 1755 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1756 | |
| 1757 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1758 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1759 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1760 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1761 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1762 | obj = intel_fb_obj(enabled->primary->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1763 | |
| 1764 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1765 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1766 | enabled = NULL; |
| 1767 | } |
| 1768 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1769 | /* |
| 1770 | * Overlay gets an aggressive default since video jitter is bad. |
| 1771 | */ |
| 1772 | cwm = 2; |
| 1773 | |
| 1774 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1775 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1776 | |
| 1777 | /* Calc sr entries for one plane configs */ |
| 1778 | if (HAS_FW_BLC(dev) && enabled) { |
| 1779 | /* self-refresh has much higher latency */ |
| 1780 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1781 | const struct drm_display_mode *adjusted_mode = |
| 1782 | &to_intel_crtc(enabled)->config.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1783 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1784 | int htotal = adjusted_mode->crtc_htotal; |
Daniel Vetter | f727b49 | 2013-11-20 15:02:10 +0100 | [diff] [blame] | 1785 | int hdisplay = to_intel_crtc(enabled)->config.pipe_src_w; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1786 | int pixel_size = enabled->primary->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1787 | unsigned long line_time_us; |
| 1788 | int entries; |
| 1789 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1790 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1791 | |
| 1792 | /* Use ns/us then divide to preserve precision */ |
| 1793 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1794 | pixel_size * hdisplay; |
| 1795 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1796 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1797 | srwm = wm_info->fifo_size - entries; |
| 1798 | if (srwm < 0) |
| 1799 | srwm = 1; |
| 1800 | |
| 1801 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1802 | I915_WRITE(FW_BLC_SELF, |
| 1803 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1804 | else if (IS_I915GM(dev)) |
| 1805 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1806 | } |
| 1807 | |
| 1808 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1809 | planea_wm, planeb_wm, cwm, srwm); |
| 1810 | |
| 1811 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1812 | fwater_hi = (cwm & 0x1f); |
| 1813 | |
| 1814 | /* Set request length to 8 cachelines per fetch */ |
| 1815 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1816 | fwater_hi = fwater_hi | (1 << 8); |
| 1817 | |
| 1818 | I915_WRITE(FW_BLC, fwater_lo); |
| 1819 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1820 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1821 | if (enabled) |
| 1822 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1823 | } |
| 1824 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1825 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1826 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1827 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1828 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1829 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1830 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1831 | uint32_t fwater_lo; |
| 1832 | int planea_wm; |
| 1833 | |
| 1834 | crtc = single_enabled_crtc(dev); |
| 1835 | if (crtc == NULL) |
| 1836 | return; |
| 1837 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1838 | adjusted_mode = &to_intel_crtc(crtc)->config.adjusted_mode; |
| 1839 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1840 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1841 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1842 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1843 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1844 | fwater_lo |= (3<<8) | planea_wm; |
| 1845 | |
| 1846 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1847 | |
| 1848 | I915_WRITE(FW_BLC, fwater_lo); |
| 1849 | } |
| 1850 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1851 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1852 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1853 | { |
| 1854 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1855 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1856 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1857 | pixel_rate = intel_crtc->config.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1858 | |
| 1859 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1860 | * adjust the pixel_rate here. */ |
| 1861 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1862 | if (intel_crtc->config.pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1863 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1864 | uint32_t pfit_size = intel_crtc->config.pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1865 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 1866 | pipe_w = intel_crtc->config.pipe_src_w; |
| 1867 | pipe_h = intel_crtc->config.pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1868 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1869 | pfit_h = pfit_size & 0xFFFF; |
| 1870 | if (pipe_w < pfit_w) |
| 1871 | pipe_w = pfit_w; |
| 1872 | if (pipe_h < pfit_h) |
| 1873 | pipe_h = pfit_h; |
| 1874 | |
| 1875 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1876 | pfit_w * pfit_h); |
| 1877 | } |
| 1878 | |
| 1879 | return pixel_rate; |
| 1880 | } |
| 1881 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1882 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1883 | 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] | 1884 | uint32_t latency) |
| 1885 | { |
| 1886 | uint64_t ret; |
| 1887 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1888 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1889 | return UINT_MAX; |
| 1890 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1891 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1892 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1893 | |
| 1894 | return ret; |
| 1895 | } |
| 1896 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1897 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1898 | 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] | 1899 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1900 | uint32_t latency) |
| 1901 | { |
| 1902 | uint32_t ret; |
| 1903 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1904 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1905 | return UINT_MAX; |
| 1906 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1907 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1908 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1909 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1910 | return ret; |
| 1911 | } |
| 1912 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1913 | 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] | 1914 | uint8_t bytes_per_pixel) |
| 1915 | { |
| 1916 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1917 | } |
| 1918 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1919 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1920 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1921 | uint32_t pipe_htotal; |
| 1922 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1923 | struct intel_plane_wm_parameters pri; |
| 1924 | struct intel_plane_wm_parameters spr; |
| 1925 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1926 | }; |
| 1927 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1928 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1929 | uint16_t pri; |
| 1930 | uint16_t spr; |
| 1931 | uint16_t cur; |
| 1932 | uint16_t fbc; |
| 1933 | }; |
| 1934 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1935 | /* used in computing the new watermarks state */ |
| 1936 | struct intel_wm_config { |
| 1937 | unsigned int num_pipes_active; |
| 1938 | bool sprites_enabled; |
| 1939 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1940 | }; |
| 1941 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1942 | /* |
| 1943 | * For both WM_PIPE and WM_LP. |
| 1944 | * mem_value must be in 0.1us units. |
| 1945 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1946 | 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] | 1947 | uint32_t mem_value, |
| 1948 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1949 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1950 | uint32_t method1, method2; |
| 1951 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1952 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1953 | return 0; |
| 1954 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1955 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1956 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1957 | mem_value); |
| 1958 | |
| 1959 | if (!is_lp) |
| 1960 | return method1; |
| 1961 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1962 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1963 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1964 | params->pri.horiz_pixels, |
| 1965 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1966 | mem_value); |
| 1967 | |
| 1968 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1969 | } |
| 1970 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1971 | /* |
| 1972 | * For both WM_PIPE and WM_LP. |
| 1973 | * mem_value must be in 0.1us units. |
| 1974 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1975 | 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] | 1976 | uint32_t mem_value) |
| 1977 | { |
| 1978 | uint32_t method1, method2; |
| 1979 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1980 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1981 | return 0; |
| 1982 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1983 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1984 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1985 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1986 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1987 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1988 | params->spr.horiz_pixels, |
| 1989 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1990 | mem_value); |
| 1991 | return min(method1, method2); |
| 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_cur_wm(const struct ilk_pipe_wm_parameters *params, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1999 | uint32_t mem_value) |
| 2000 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2001 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2002 | return 0; |
| 2003 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2004 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2005 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2006 | params->cur.horiz_pixels, |
| 2007 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2008 | mem_value); |
| 2009 | } |
| 2010 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2011 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2012 | 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] | 2013 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2014 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2015 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2016 | return 0; |
| 2017 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 2018 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 2019 | params->pri.horiz_pixels, |
| 2020 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2021 | } |
| 2022 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2023 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 2024 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2025 | if (INTEL_INFO(dev)->gen >= 8) |
| 2026 | return 3072; |
| 2027 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2028 | return 768; |
| 2029 | else |
| 2030 | return 512; |
| 2031 | } |
| 2032 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2033 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 2034 | int level, bool is_sprite) |
| 2035 | { |
| 2036 | if (INTEL_INFO(dev)->gen >= 8) |
| 2037 | /* BDW primary/sprite plane watermarks */ |
| 2038 | return level == 0 ? 255 : 2047; |
| 2039 | else if (INTEL_INFO(dev)->gen >= 7) |
| 2040 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2041 | return level == 0 ? 127 : 1023; |
| 2042 | else if (!is_sprite) |
| 2043 | /* ILK/SNB primary plane watermarks */ |
| 2044 | return level == 0 ? 127 : 511; |
| 2045 | else |
| 2046 | /* ILK/SNB sprite plane watermarks */ |
| 2047 | return level == 0 ? 63 : 255; |
| 2048 | } |
| 2049 | |
| 2050 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 2051 | int level) |
| 2052 | { |
| 2053 | if (INTEL_INFO(dev)->gen >= 7) |
| 2054 | return level == 0 ? 63 : 255; |
| 2055 | else |
| 2056 | return level == 0 ? 31 : 63; |
| 2057 | } |
| 2058 | |
| 2059 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 2060 | { |
| 2061 | if (INTEL_INFO(dev)->gen >= 8) |
| 2062 | return 31; |
| 2063 | else |
| 2064 | return 15; |
| 2065 | } |
| 2066 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2067 | /* Calculate the maximum primary/sprite plane watermark */ |
| 2068 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 2069 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2070 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2071 | enum intel_ddb_partitioning ddb_partitioning, |
| 2072 | bool is_sprite) |
| 2073 | { |
| 2074 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2075 | |
| 2076 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2077 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2078 | return 0; |
| 2079 | |
| 2080 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2081 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2082 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 2083 | |
| 2084 | /* |
| 2085 | * For some reason the non self refresh |
| 2086 | * FIFO size is only half of the self |
| 2087 | * refresh FIFO size on ILK/SNB. |
| 2088 | */ |
| 2089 | if (INTEL_INFO(dev)->gen <= 6) |
| 2090 | fifo_size /= 2; |
| 2091 | } |
| 2092 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2093 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2094 | /* level 0 is always calculated with 1:1 split */ |
| 2095 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2096 | if (is_sprite) |
| 2097 | fifo_size *= 5; |
| 2098 | fifo_size /= 6; |
| 2099 | } else { |
| 2100 | fifo_size /= 2; |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2105 | 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] | 2106 | } |
| 2107 | |
| 2108 | /* Calculate the maximum cursor plane watermark */ |
| 2109 | 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] | 2110 | int level, |
| 2111 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2112 | { |
| 2113 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2114 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2115 | return 64; |
| 2116 | |
| 2117 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2118 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2119 | } |
| 2120 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2121 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2122 | int level, |
| 2123 | const struct intel_wm_config *config, |
| 2124 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2125 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2126 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2127 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 2128 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 2129 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2130 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2131 | } |
| 2132 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2133 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 2134 | int level, |
| 2135 | struct ilk_wm_maximums *max) |
| 2136 | { |
| 2137 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 2138 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 2139 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 2140 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 2141 | } |
| 2142 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2143 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2144 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2145 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2146 | { |
| 2147 | bool ret; |
| 2148 | |
| 2149 | /* already determined to be invalid? */ |
| 2150 | if (!result->enable) |
| 2151 | return false; |
| 2152 | |
| 2153 | result->enable = result->pri_val <= max->pri && |
| 2154 | result->spr_val <= max->spr && |
| 2155 | result->cur_val <= max->cur; |
| 2156 | |
| 2157 | ret = result->enable; |
| 2158 | |
| 2159 | /* |
| 2160 | * HACK until we can pre-compute everything, |
| 2161 | * and thus fail gracefully if LP0 watermarks |
| 2162 | * are exceeded... |
| 2163 | */ |
| 2164 | if (level == 0 && !result->enable) { |
| 2165 | if (result->pri_val > max->pri) |
| 2166 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2167 | level, result->pri_val, max->pri); |
| 2168 | if (result->spr_val > max->spr) |
| 2169 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2170 | level, result->spr_val, max->spr); |
| 2171 | if (result->cur_val > max->cur) |
| 2172 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2173 | level, result->cur_val, max->cur); |
| 2174 | |
| 2175 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 2176 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 2177 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 2178 | result->enable = true; |
| 2179 | } |
| 2180 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2181 | return ret; |
| 2182 | } |
| 2183 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2184 | 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] | 2185 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2186 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2187 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2188 | { |
| 2189 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 2190 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 2191 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 2192 | |
| 2193 | /* WM1+ latency values stored in 0.5us units */ |
| 2194 | if (level > 0) { |
| 2195 | pri_latency *= 5; |
| 2196 | spr_latency *= 5; |
| 2197 | cur_latency *= 5; |
| 2198 | } |
| 2199 | |
| 2200 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 2201 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 2202 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 2203 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 2204 | result->enable = true; |
| 2205 | } |
| 2206 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2207 | static uint32_t |
| 2208 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2209 | { |
| 2210 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2211 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2212 | struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2213 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2214 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2215 | if (!intel_crtc_active(crtc)) |
| 2216 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2217 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2218 | /* The WM are computed with base on how long it takes to fill a single |
| 2219 | * row at the given clock rate, multiplied by 8. |
| 2220 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 2221 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 2222 | mode->crtc_clock); |
| 2223 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 2224 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2225 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2226 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 2227 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 2228 | } |
| 2229 | |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2230 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2231 | { |
| 2232 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2233 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2234 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2235 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 2236 | |
| 2237 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2238 | if (wm[0] == 0) |
| 2239 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2240 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2241 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2242 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2243 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2244 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 2245 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 2246 | |
| 2247 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2248 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2249 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2250 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2251 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 2252 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 2253 | |
| 2254 | /* ILK primary LP0 latency is 700 ns */ |
| 2255 | wm[0] = 7; |
| 2256 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2257 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2261 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2262 | { |
| 2263 | /* ILK sprite LP0 latency is 1300 ns */ |
| 2264 | if (INTEL_INFO(dev)->gen == 5) |
| 2265 | wm[0] = 13; |
| 2266 | } |
| 2267 | |
| 2268 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 2269 | { |
| 2270 | /* ILK cursor LP0 latency is 1300 ns */ |
| 2271 | if (INTEL_INFO(dev)->gen == 5) |
| 2272 | wm[0] = 13; |
| 2273 | |
| 2274 | /* WaDoubleCursorLP3Latency:ivb */ |
| 2275 | if (IS_IVYBRIDGE(dev)) |
| 2276 | wm[3] *= 2; |
| 2277 | } |
| 2278 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 2279 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2280 | { |
| 2281 | /* how many WM levels are we expecting */ |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2282 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2283 | return 4; |
| 2284 | else if (INTEL_INFO(dev)->gen >= 6) |
| 2285 | return 3; |
| 2286 | else |
| 2287 | return 2; |
| 2288 | } |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2289 | static void intel_print_wm_latency(struct drm_device *dev, |
| 2290 | const char *name, |
| 2291 | const uint16_t wm[5]) |
| 2292 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 2293 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2294 | |
| 2295 | for (level = 0; level <= max_level; level++) { |
| 2296 | unsigned int latency = wm[level]; |
| 2297 | |
| 2298 | if (latency == 0) { |
| 2299 | DRM_ERROR("%s WM%d latency not provided\n", |
| 2300 | name, level); |
| 2301 | continue; |
| 2302 | } |
| 2303 | |
| 2304 | /* WM1+ latency values in 0.5us units */ |
| 2305 | if (level > 0) |
| 2306 | latency *= 5; |
| 2307 | |
| 2308 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 2309 | name, level, wm[level], |
| 2310 | latency / 10, latency % 10); |
| 2311 | } |
| 2312 | } |
| 2313 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2314 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 2315 | uint16_t wm[5], uint16_t min) |
| 2316 | { |
| 2317 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 2318 | |
| 2319 | if (wm[0] >= min) |
| 2320 | return false; |
| 2321 | |
| 2322 | wm[0] = max(wm[0], min); |
| 2323 | for (level = 1; level <= max_level; level++) |
| 2324 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 2325 | |
| 2326 | return true; |
| 2327 | } |
| 2328 | |
| 2329 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 2330 | { |
| 2331 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2332 | bool changed; |
| 2333 | |
| 2334 | /* |
| 2335 | * The BIOS provided WM memory latency values are often |
| 2336 | * inadequate for high resolution displays. Adjust them. |
| 2337 | */ |
| 2338 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2339 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2340 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2341 | |
| 2342 | if (!changed) |
| 2343 | return; |
| 2344 | |
| 2345 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2346 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2347 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2348 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2349 | } |
| 2350 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2351 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2352 | { |
| 2353 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2354 | |
| 2355 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2356 | |
| 2357 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2358 | sizeof(dev_priv->wm.pri_latency)); |
| 2359 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2360 | sizeof(dev_priv->wm.pri_latency)); |
| 2361 | |
| 2362 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2363 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2364 | |
| 2365 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2366 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2367 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2368 | |
| 2369 | if (IS_GEN6(dev)) |
| 2370 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2371 | } |
| 2372 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2373 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2374 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2375 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2376 | struct drm_device *dev = crtc->dev; |
| 2377 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2378 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2379 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2380 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2381 | if (!intel_crtc_active(crtc)) |
| 2382 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2383 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2384 | p->active = true; |
| 2385 | p->pipe_htotal = intel_crtc->config.adjusted_mode.crtc_htotal; |
| 2386 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
| 2387 | p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8; |
| 2388 | p->cur.bytes_per_pixel = 4; |
| 2389 | p->pri.horiz_pixels = intel_crtc->config.pipe_src_w; |
| 2390 | p->cur.horiz_pixels = intel_crtc->cursor_width; |
| 2391 | /* TODO: for now, assume primary and cursor planes are always enabled. */ |
| 2392 | p->pri.enabled = true; |
| 2393 | p->cur.enabled = true; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2394 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2395 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2396 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2397 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2398 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2399 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2400 | break; |
| 2401 | } |
| 2402 | } |
| 2403 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2404 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2405 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2406 | struct intel_wm_config *config) |
| 2407 | { |
| 2408 | struct intel_crtc *intel_crtc; |
| 2409 | |
| 2410 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2411 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2412 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2413 | |
| 2414 | if (!wm->pipe_enabled) |
| 2415 | continue; |
| 2416 | |
| 2417 | config->sprites_enabled |= wm->sprites_enabled; |
| 2418 | config->sprites_scaled |= wm->sprites_scaled; |
| 2419 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2423 | /* Compute new watermarks for the pipe */ |
| 2424 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2425 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2426 | struct intel_pipe_wm *pipe_wm) |
| 2427 | { |
| 2428 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2429 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2430 | int level, max_level = ilk_wm_max_level(dev); |
| 2431 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2432 | struct intel_wm_config config = { |
| 2433 | .num_pipes_active = 1, |
| 2434 | .sprites_enabled = params->spr.enabled, |
| 2435 | .sprites_scaled = params->spr.scaled, |
| 2436 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2437 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2438 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2439 | pipe_wm->pipe_enabled = params->active; |
| 2440 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2441 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2442 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2443 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2444 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2445 | max_level = 1; |
| 2446 | |
| 2447 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2448 | if (params->spr.scaled) |
| 2449 | max_level = 0; |
| 2450 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2451 | 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] | 2452 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2453 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2454 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2455 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2456 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2457 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2458 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2459 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2460 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2461 | return false; |
| 2462 | |
| 2463 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2464 | |
| 2465 | for (level = 1; level <= max_level; level++) { |
| 2466 | struct intel_wm_level wm = {}; |
| 2467 | |
| 2468 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2469 | |
| 2470 | /* |
| 2471 | * Disable any watermark level that exceeds the |
| 2472 | * register maximums since such watermarks are |
| 2473 | * always invalid. |
| 2474 | */ |
| 2475 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2476 | break; |
| 2477 | |
| 2478 | pipe_wm->wm[level] = wm; |
| 2479 | } |
| 2480 | |
| 2481 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | /* |
| 2485 | * Merge the watermarks from all active pipes for a specific level. |
| 2486 | */ |
| 2487 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2488 | int level, |
| 2489 | struct intel_wm_level *ret_wm) |
| 2490 | { |
| 2491 | const struct intel_crtc *intel_crtc; |
| 2492 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2493 | ret_wm->enable = true; |
| 2494 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2495 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2496 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2497 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2498 | |
| 2499 | if (!active->pipe_enabled) |
| 2500 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2501 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2502 | /* |
| 2503 | * The watermark values may have been used in the past, |
| 2504 | * so we must maintain them in the registers for some |
| 2505 | * time even if the level is now disabled. |
| 2506 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2507 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2508 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2509 | |
| 2510 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2511 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2512 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2513 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2514 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | /* |
| 2518 | * Merge all low power watermarks for all active pipes. |
| 2519 | */ |
| 2520 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2521 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2522 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2523 | struct intel_pipe_wm *merged) |
| 2524 | { |
| 2525 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2526 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2527 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2528 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2529 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2530 | config->num_pipes_active > 1) |
| 2531 | return; |
| 2532 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2533 | /* ILK: FBC WM must be disabled always */ |
| 2534 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2535 | |
| 2536 | /* merge each WM1+ level */ |
| 2537 | for (level = 1; level <= max_level; level++) { |
| 2538 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2539 | |
| 2540 | ilk_merge_wm_level(dev, level, wm); |
| 2541 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2542 | if (level > last_enabled_level) |
| 2543 | wm->enable = false; |
| 2544 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2545 | /* make sure all following levels get disabled */ |
| 2546 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2547 | |
| 2548 | /* |
| 2549 | * The spec says it is preferred to disable |
| 2550 | * FBC WMs instead of disabling a WM level. |
| 2551 | */ |
| 2552 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2553 | if (wm->enable) |
| 2554 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2555 | wm->fbc_val = 0; |
| 2556 | } |
| 2557 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2558 | |
| 2559 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2560 | /* |
| 2561 | * FIXME this is racy. FBC might get enabled later. |
| 2562 | * What we should check here is whether FBC can be |
| 2563 | * enabled sometime later. |
| 2564 | */ |
| 2565 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2566 | for (level = 2; level <= max_level; level++) { |
| 2567 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2568 | |
| 2569 | wm->enable = false; |
| 2570 | } |
| 2571 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2572 | } |
| 2573 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2574 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2575 | { |
| 2576 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2577 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2578 | } |
| 2579 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2580 | /* The value we need to program into the WM_LPx latency field */ |
| 2581 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2582 | { |
| 2583 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2584 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2585 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2586 | return 2 * level; |
| 2587 | else |
| 2588 | return dev_priv->wm.pri_latency[level]; |
| 2589 | } |
| 2590 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2591 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2592 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2593 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2594 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2595 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2596 | struct intel_crtc *intel_crtc; |
| 2597 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2598 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2599 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2600 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2601 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2602 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2603 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2604 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2605 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2606 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2607 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2608 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2609 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2610 | /* |
| 2611 | * Maintain the watermark values even if the level is |
| 2612 | * disabled. Doing otherwise could cause underruns. |
| 2613 | */ |
| 2614 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2615 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2616 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2617 | r->cur_val; |
| 2618 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2619 | if (r->enable) |
| 2620 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2621 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2622 | if (INTEL_INFO(dev)->gen >= 8) |
| 2623 | results->wm_lp[wm_lp - 1] |= |
| 2624 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2625 | else |
| 2626 | results->wm_lp[wm_lp - 1] |= |
| 2627 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2628 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2629 | /* |
| 2630 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2631 | * level is disabled. Doing otherwise could cause underruns. |
| 2632 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2633 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2634 | WARN_ON(wm_lp != 1); |
| 2635 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2636 | } else |
| 2637 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2638 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2639 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2640 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2641 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2642 | enum pipe pipe = intel_crtc->pipe; |
| 2643 | const struct intel_wm_level *r = |
| 2644 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2645 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2646 | if (WARN_ON(!r->enable)) |
| 2647 | continue; |
| 2648 | |
| 2649 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2650 | |
| 2651 | results->wm_pipe[pipe] = |
| 2652 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2653 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2654 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2655 | } |
| 2656 | } |
| 2657 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2658 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2659 | * 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] | 2660 | 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] | 2661 | struct intel_pipe_wm *r1, |
| 2662 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2663 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2664 | int level, max_level = ilk_wm_max_level(dev); |
| 2665 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2666 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2667 | for (level = 1; level <= max_level; level++) { |
| 2668 | if (r1->wm[level].enable) |
| 2669 | level1 = level; |
| 2670 | if (r2->wm[level].enable) |
| 2671 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2672 | } |
| 2673 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2674 | if (level1 == level2) { |
| 2675 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2676 | return r2; |
| 2677 | else |
| 2678 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2679 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2680 | return r1; |
| 2681 | } else { |
| 2682 | return r2; |
| 2683 | } |
| 2684 | } |
| 2685 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2686 | /* dirty bits used to track which watermarks need changes */ |
| 2687 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2688 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2689 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2690 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2691 | #define WM_DIRTY_FBC (1 << 24) |
| 2692 | #define WM_DIRTY_DDB (1 << 25) |
| 2693 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2694 | 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] | 2695 | const struct ilk_wm_values *old, |
| 2696 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2697 | { |
| 2698 | unsigned int dirty = 0; |
| 2699 | enum pipe pipe; |
| 2700 | int wm_lp; |
| 2701 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2702 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2703 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2704 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2705 | /* Must disable LP1+ watermarks too */ |
| 2706 | dirty |= WM_DIRTY_LP_ALL; |
| 2707 | } |
| 2708 | |
| 2709 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2710 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2711 | /* Must disable LP1+ watermarks too */ |
| 2712 | dirty |= WM_DIRTY_LP_ALL; |
| 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2717 | dirty |= WM_DIRTY_FBC; |
| 2718 | /* Must disable LP1+ watermarks too */ |
| 2719 | dirty |= WM_DIRTY_LP_ALL; |
| 2720 | } |
| 2721 | |
| 2722 | if (old->partitioning != new->partitioning) { |
| 2723 | dirty |= WM_DIRTY_DDB; |
| 2724 | /* Must disable LP1+ watermarks too */ |
| 2725 | dirty |= WM_DIRTY_LP_ALL; |
| 2726 | } |
| 2727 | |
| 2728 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2729 | if (dirty & WM_DIRTY_LP_ALL) |
| 2730 | return dirty; |
| 2731 | |
| 2732 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2733 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2734 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2735 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2736 | break; |
| 2737 | } |
| 2738 | |
| 2739 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2740 | for (; wm_lp <= 3; wm_lp++) |
| 2741 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2742 | |
| 2743 | return dirty; |
| 2744 | } |
| 2745 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2746 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2747 | unsigned int dirty) |
| 2748 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2749 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2750 | bool changed = false; |
| 2751 | |
| 2752 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2753 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2754 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2755 | changed = true; |
| 2756 | } |
| 2757 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2758 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2759 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2760 | changed = true; |
| 2761 | } |
| 2762 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2763 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2764 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2765 | changed = true; |
| 2766 | } |
| 2767 | |
| 2768 | /* |
| 2769 | * Don't touch WM1S_LP_EN here. |
| 2770 | * Doing so could cause underruns. |
| 2771 | */ |
| 2772 | |
| 2773 | return changed; |
| 2774 | } |
| 2775 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2776 | /* |
| 2777 | * The spec says we shouldn't write when we don't need, because every write |
| 2778 | * causes WMs to be re-evaluated, expending some power. |
| 2779 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2780 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2781 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2782 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2783 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2784 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2785 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2786 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2787 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2788 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2789 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2790 | return; |
| 2791 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2792 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2793 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2794 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2795 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2796 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2797 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2798 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2799 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2800 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2801 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2802 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2803 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2804 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2805 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2806 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2807 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2808 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2809 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2810 | val = I915_READ(WM_MISC); |
| 2811 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2812 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2813 | else |
| 2814 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2815 | I915_WRITE(WM_MISC, val); |
| 2816 | } else { |
| 2817 | val = I915_READ(DISP_ARB_CTL2); |
| 2818 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2819 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2820 | else |
| 2821 | val |= DISP_DATA_PARTITION_5_6; |
| 2822 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2823 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2824 | } |
| 2825 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2826 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2827 | val = I915_READ(DISP_ARB_CTL); |
| 2828 | if (results->enable_fbc_wm) |
| 2829 | val &= ~DISP_FBC_WM_DIS; |
| 2830 | else |
| 2831 | val |= DISP_FBC_WM_DIS; |
| 2832 | I915_WRITE(DISP_ARB_CTL, val); |
| 2833 | } |
| 2834 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2835 | if (dirty & WM_DIRTY_LP(1) && |
| 2836 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2837 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2838 | |
| 2839 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2840 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2841 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2842 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2843 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2844 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2845 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2846 | 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] | 2847 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2848 | 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] | 2849 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2850 | 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] | 2851 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2852 | |
| 2853 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2854 | } |
| 2855 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2856 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2857 | { |
| 2858 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2859 | |
| 2860 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2861 | } |
| 2862 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2863 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2864 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2865 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 2866 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2867 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2868 | struct ilk_wm_maximums max; |
| 2869 | struct ilk_pipe_wm_parameters params = {}; |
| 2870 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2871 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2872 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2873 | 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] | 2874 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2875 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2876 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2877 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2878 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 2879 | |
| 2880 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 2881 | return; |
| 2882 | |
| 2883 | intel_crtc->wm.active = pipe_wm; |
| 2884 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2885 | ilk_compute_wm_config(dev, &config); |
| 2886 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2887 | 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] | 2888 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2889 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2890 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 2891 | if (INTEL_INFO(dev)->gen >= 7 && |
| 2892 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 2893 | 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] | 2894 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 2895 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2896 | 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] | 2897 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2898 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2899 | } |
| 2900 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2901 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 2902 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2903 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2904 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2905 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2906 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2907 | } |
| 2908 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2909 | static void |
| 2910 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 2911 | struct drm_crtc *crtc, |
| 2912 | uint32_t sprite_width, uint32_t sprite_height, |
| 2913 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2914 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2915 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2916 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2917 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2918 | intel_plane->wm.enabled = enabled; |
| 2919 | intel_plane->wm.scaled = scaled; |
| 2920 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 2921 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 2922 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2923 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2924 | /* |
| 2925 | * IVB workaround: must disable low power watermarks for at least |
| 2926 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 2927 | * when scaling is disabled. |
| 2928 | * |
| 2929 | * WaCxSRDisabledForSpriteScaling:ivb |
| 2930 | */ |
| 2931 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 2932 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 2933 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2934 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 2935 | } |
| 2936 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2937 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 2938 | { |
| 2939 | struct drm_device *dev = crtc->dev; |
| 2940 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2941 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2942 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2943 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2944 | enum pipe pipe = intel_crtc->pipe; |
| 2945 | static const unsigned int wm0_pipe_reg[] = { |
| 2946 | [PIPE_A] = WM0_PIPEA_ILK, |
| 2947 | [PIPE_B] = WM0_PIPEB_ILK, |
| 2948 | [PIPE_C] = WM0_PIPEC_IVB, |
| 2949 | }; |
| 2950 | |
| 2951 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2952 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2953 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2954 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2955 | active->pipe_enabled = intel_crtc_active(crtc); |
| 2956 | |
| 2957 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2958 | u32 tmp = hw->wm_pipe[pipe]; |
| 2959 | |
| 2960 | /* |
| 2961 | * For active pipes LP0 watermark is marked as |
| 2962 | * enabled, and LP1+ watermaks as disabled since |
| 2963 | * we can't really reverse compute them in case |
| 2964 | * multiple pipes are active. |
| 2965 | */ |
| 2966 | active->wm[0].enable = true; |
| 2967 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 2968 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 2969 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 2970 | active->linetime = hw->wm_linetime[pipe]; |
| 2971 | } else { |
| 2972 | int level, max_level = ilk_wm_max_level(dev); |
| 2973 | |
| 2974 | /* |
| 2975 | * For inactive pipes, all watermark levels |
| 2976 | * should be marked as enabled but zeroed, |
| 2977 | * which is what we'd compute them to. |
| 2978 | */ |
| 2979 | for (level = 0; level <= max_level; level++) |
| 2980 | active->wm[level].enable = true; |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 2985 | { |
| 2986 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2987 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2988 | struct drm_crtc *crtc; |
| 2989 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2990 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 2991 | ilk_pipe_wm_get_hw_state(crtc); |
| 2992 | |
| 2993 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 2994 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 2995 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 2996 | |
| 2997 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 2998 | if (INTEL_INFO(dev)->gen >= 7) { |
| 2999 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3000 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3001 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3002 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3003 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3004 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3005 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3006 | else if (IS_IVYBRIDGE(dev)) |
| 3007 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3008 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3009 | |
| 3010 | hw->enable_fbc_wm = |
| 3011 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3012 | } |
| 3013 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3014 | /** |
| 3015 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3016 | * |
| 3017 | * Calculate watermark values for the various WM regs based on current mode |
| 3018 | * and plane configuration. |
| 3019 | * |
| 3020 | * There are several cases to deal with here: |
| 3021 | * - normal (i.e. non-self-refresh) |
| 3022 | * - self-refresh (SR) mode |
| 3023 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3024 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3025 | * lines), so need to account for TLB latency |
| 3026 | * |
| 3027 | * The normal calculation is: |
| 3028 | * watermark = dotclock * bytes per pixel * latency |
| 3029 | * where latency is platform & configuration dependent (we assume pessimal |
| 3030 | * values here). |
| 3031 | * |
| 3032 | * The SR calculation is: |
| 3033 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3034 | * bytes per pixel |
| 3035 | * where |
| 3036 | * line time = htotal / dotclock |
| 3037 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3038 | * and latency is assumed to be high, as above. |
| 3039 | * |
| 3040 | * The final value programmed to the register should always be rounded up, |
| 3041 | * and include an extra 2 entries to account for clock crossings. |
| 3042 | * |
| 3043 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3044 | * to set the non-SR watermarks to 8. |
| 3045 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3046 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3047 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3048 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3049 | |
| 3050 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3051 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3052 | } |
| 3053 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3054 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3055 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3056 | uint32_t sprite_width, |
| 3057 | uint32_t sprite_height, |
| 3058 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3059 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3060 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3061 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3062 | |
| 3063 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3064 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3065 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3066 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3067 | } |
| 3068 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3069 | static struct drm_i915_gem_object * |
| 3070 | intel_alloc_context_page(struct drm_device *dev) |
| 3071 | { |
| 3072 | struct drm_i915_gem_object *ctx; |
| 3073 | int ret; |
| 3074 | |
| 3075 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 3076 | |
| 3077 | ctx = i915_gem_alloc_object(dev, 4096); |
| 3078 | if (!ctx) { |
| 3079 | DRM_DEBUG("failed to alloc power context, RC6 disabled\n"); |
| 3080 | return NULL; |
| 3081 | } |
| 3082 | |
Daniel Vetter | c69766f | 2014-02-14 14:01:17 +0100 | [diff] [blame] | 3083 | ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3084 | if (ret) { |
| 3085 | DRM_ERROR("failed to pin power context: %d\n", ret); |
| 3086 | goto err_unref; |
| 3087 | } |
| 3088 | |
| 3089 | ret = i915_gem_object_set_to_gtt_domain(ctx, 1); |
| 3090 | if (ret) { |
| 3091 | DRM_ERROR("failed to set-domain on power context: %d\n", ret); |
| 3092 | goto err_unpin; |
| 3093 | } |
| 3094 | |
| 3095 | return ctx; |
| 3096 | |
| 3097 | err_unpin: |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 3098 | i915_gem_object_ggtt_unpin(ctx); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3099 | err_unref: |
| 3100 | drm_gem_object_unreference(&ctx->base); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3101 | return NULL; |
| 3102 | } |
| 3103 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3104 | /** |
| 3105 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3106 | */ |
| 3107 | DEFINE_SPINLOCK(mchdev_lock); |
| 3108 | |
| 3109 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3110 | * mchdev_lock. */ |
| 3111 | static struct drm_i915_private *i915_mch_dev; |
| 3112 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3113 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3114 | { |
| 3115 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3116 | u16 rgvswctl; |
| 3117 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3118 | assert_spin_locked(&mchdev_lock); |
| 3119 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3120 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3121 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3122 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3123 | return false; /* still busy with another command */ |
| 3124 | } |
| 3125 | |
| 3126 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3127 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3128 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3129 | POSTING_READ16(MEMSWCTL); |
| 3130 | |
| 3131 | rgvswctl |= MEMCTL_CMD_STS; |
| 3132 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3133 | |
| 3134 | return true; |
| 3135 | } |
| 3136 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3137 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3138 | { |
| 3139 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3140 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3141 | u8 fmax, fmin, fstart, vstart; |
| 3142 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3143 | spin_lock_irq(&mchdev_lock); |
| 3144 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3145 | /* Enable temp reporting */ |
| 3146 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3147 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3148 | |
| 3149 | /* 100ms RC evaluation intervals */ |
| 3150 | I915_WRITE(RCUPEI, 100000); |
| 3151 | I915_WRITE(RCDNEI, 100000); |
| 3152 | |
| 3153 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3154 | I915_WRITE(RCBMAXAVG, 90000); |
| 3155 | I915_WRITE(RCBMINAVG, 80000); |
| 3156 | |
| 3157 | I915_WRITE(MEMIHYST, 1); |
| 3158 | |
| 3159 | /* Set up min, max, and cur for interrupt handling */ |
| 3160 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3161 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3162 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3163 | MEMMODE_FSTART_SHIFT; |
| 3164 | |
| 3165 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3166 | PXVFREQ_PX_SHIFT; |
| 3167 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3168 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3169 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3170 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3171 | dev_priv->ips.max_delay = fstart; |
| 3172 | dev_priv->ips.min_delay = fmin; |
| 3173 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3174 | |
| 3175 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3176 | fmax, fmin, fstart); |
| 3177 | |
| 3178 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3179 | |
| 3180 | /* |
| 3181 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3182 | */ |
| 3183 | |
| 3184 | I915_WRITE(VIDSTART, vstart); |
| 3185 | POSTING_READ(VIDSTART); |
| 3186 | |
| 3187 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3188 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3189 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3190 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3191 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3192 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3193 | |
| 3194 | ironlake_set_drps(dev, fstart); |
| 3195 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3196 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3197 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3198 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3199 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3200 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3201 | |
| 3202 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3203 | } |
| 3204 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3205 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3206 | { |
| 3207 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3208 | u16 rgvswctl; |
| 3209 | |
| 3210 | spin_lock_irq(&mchdev_lock); |
| 3211 | |
| 3212 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3213 | |
| 3214 | /* Ack interrupts, disable EFC interrupt */ |
| 3215 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3216 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3217 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3218 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3219 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3220 | |
| 3221 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3222 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3223 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3224 | rgvswctl |= MEMCTL_CMD_STS; |
| 3225 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3226 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3227 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3228 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3229 | } |
| 3230 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3231 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3232 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3233 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3234 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3235 | */ |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 3236 | 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] | 3237 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3238 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3239 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3240 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3241 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3242 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3243 | * the hw runs at the minimal clock before selecting the desired |
| 3244 | * frequency, if the down threshold expires in that window we will not |
| 3245 | * receive a down interrupt. */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3246 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3247 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3248 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3249 | |
| 3250 | return limits; |
| 3251 | } |
| 3252 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3253 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3254 | { |
| 3255 | int new_power; |
| 3256 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3257 | if (dev_priv->rps.is_bdw_sw_turbo) |
| 3258 | return; |
| 3259 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3260 | new_power = dev_priv->rps.power; |
| 3261 | switch (dev_priv->rps.power) { |
| 3262 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3263 | 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] | 3264 | new_power = BETWEEN; |
| 3265 | break; |
| 3266 | |
| 3267 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3268 | 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] | 3269 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3270 | 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] | 3271 | new_power = HIGH_POWER; |
| 3272 | break; |
| 3273 | |
| 3274 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3275 | 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] | 3276 | new_power = BETWEEN; |
| 3277 | break; |
| 3278 | } |
| 3279 | /* Max/min bins are special */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3280 | if (val == dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3281 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3282 | if (val == dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3283 | new_power = HIGH_POWER; |
| 3284 | if (new_power == dev_priv->rps.power) |
| 3285 | return; |
| 3286 | |
| 3287 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3288 | switch (new_power) { |
| 3289 | case LOW_POWER: |
| 3290 | /* Upclock if more than 95% busy over 16ms */ |
| 3291 | I915_WRITE(GEN6_RP_UP_EI, 12500); |
| 3292 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800); |
| 3293 | |
| 3294 | /* Downclock if less than 85% busy over 32ms */ |
| 3295 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3296 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250); |
| 3297 | |
| 3298 | I915_WRITE(GEN6_RP_CONTROL, |
| 3299 | GEN6_RP_MEDIA_TURBO | |
| 3300 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3301 | GEN6_RP_MEDIA_IS_GFX | |
| 3302 | GEN6_RP_ENABLE | |
| 3303 | GEN6_RP_UP_BUSY_AVG | |
| 3304 | GEN6_RP_DOWN_IDLE_AVG); |
| 3305 | break; |
| 3306 | |
| 3307 | case BETWEEN: |
| 3308 | /* Upclock if more than 90% busy over 13ms */ |
| 3309 | I915_WRITE(GEN6_RP_UP_EI, 10250); |
| 3310 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225); |
| 3311 | |
| 3312 | /* Downclock if less than 75% busy over 32ms */ |
| 3313 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3314 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750); |
| 3315 | |
| 3316 | I915_WRITE(GEN6_RP_CONTROL, |
| 3317 | GEN6_RP_MEDIA_TURBO | |
| 3318 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3319 | GEN6_RP_MEDIA_IS_GFX | |
| 3320 | GEN6_RP_ENABLE | |
| 3321 | GEN6_RP_UP_BUSY_AVG | |
| 3322 | GEN6_RP_DOWN_IDLE_AVG); |
| 3323 | break; |
| 3324 | |
| 3325 | case HIGH_POWER: |
| 3326 | /* Upclock if more than 85% busy over 10ms */ |
| 3327 | I915_WRITE(GEN6_RP_UP_EI, 8000); |
| 3328 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800); |
| 3329 | |
| 3330 | /* Downclock if less than 60% busy over 32ms */ |
| 3331 | I915_WRITE(GEN6_RP_DOWN_EI, 25000); |
| 3332 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000); |
| 3333 | |
| 3334 | I915_WRITE(GEN6_RP_CONTROL, |
| 3335 | GEN6_RP_MEDIA_TURBO | |
| 3336 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3337 | GEN6_RP_MEDIA_IS_GFX | |
| 3338 | GEN6_RP_ENABLE | |
| 3339 | GEN6_RP_UP_BUSY_AVG | |
| 3340 | GEN6_RP_DOWN_IDLE_AVG); |
| 3341 | break; |
| 3342 | } |
| 3343 | |
| 3344 | dev_priv->rps.power = new_power; |
| 3345 | dev_priv->rps.last_adj = 0; |
| 3346 | } |
| 3347 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3348 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3349 | { |
| 3350 | u32 mask = 0; |
| 3351 | |
| 3352 | if (val > dev_priv->rps.min_freq_softlimit) |
| 3353 | mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
| 3354 | if (val < dev_priv->rps.max_freq_softlimit) |
| 3355 | mask |= GEN6_PM_RP_UP_THRESHOLD; |
| 3356 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3357 | mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED); |
| 3358 | mask &= dev_priv->pm_rps_events; |
| 3359 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3360 | /* IVB and SNB hard hangs on looping batchbuffer |
| 3361 | * if GEN6_PM_UP_EI_EXPIRED is masked. |
| 3362 | */ |
| 3363 | if (INTEL_INFO(dev_priv->dev)->gen <= 7 && !IS_HASWELL(dev_priv->dev)) |
| 3364 | mask |= GEN6_PM_RP_UP_EI_EXPIRED; |
| 3365 | |
Deepak S | baccd45 | 2014-05-15 20:58:09 +0300 | [diff] [blame] | 3366 | if (IS_GEN8(dev_priv->dev)) |
| 3367 | mask |= GEN8_PMINTR_REDIRECT_TO_NON_DISP; |
| 3368 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3369 | return ~mask; |
| 3370 | } |
| 3371 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3372 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3373 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3374 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3375 | void gen6_set_rps(struct drm_device *dev, u8 val) |
| 3376 | { |
| 3377 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3378 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3379 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3380 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3381 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3382 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3383 | /* min/max delay may still have been modified so be sure to |
| 3384 | * write the limits value. |
| 3385 | */ |
| 3386 | if (val != dev_priv->rps.cur_freq) { |
| 3387 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3388 | |
Ben Widawsky | 50e6a2a | 2014-03-31 17:16:43 -0700 | [diff] [blame] | 3389 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3390 | I915_WRITE(GEN6_RPNSWREQ, |
| 3391 | HSW_FREQUENCY(val)); |
| 3392 | else |
| 3393 | I915_WRITE(GEN6_RPNSWREQ, |
| 3394 | GEN6_FREQUENCY(val) | |
| 3395 | GEN6_OFFSET(0) | |
| 3396 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3397 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3398 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3399 | /* Make sure we continue to get interrupts |
| 3400 | * until we hit the minimum or maximum frequencies. |
| 3401 | */ |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3402 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3403 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3404 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3405 | POSTING_READ(GEN6_RPNSWREQ); |
| 3406 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3407 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3408 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3409 | } |
| 3410 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3411 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 3412 | * |
| 3413 | * * If Gfx is Idle, then |
| 3414 | * 1. Mask Turbo interrupts |
| 3415 | * 2. Bring up Gfx clock |
| 3416 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 3417 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 3418 | * 5. Unmask Turbo interrupts |
| 3419 | */ |
| 3420 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 3421 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 3422 | struct drm_device *dev = dev_priv->dev; |
| 3423 | |
| 3424 | /* Latest VLV doesn't need to force the gfx clock */ |
| 3425 | if (dev->pdev->revision >= 0xd) { |
| 3426 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3427 | return; |
| 3428 | } |
| 3429 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3430 | /* |
| 3431 | * When we are idle. Drop to min voltage state. |
| 3432 | */ |
| 3433 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3434 | if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3435 | return; |
| 3436 | |
| 3437 | /* Mask turbo interrupt so that they will not come in between */ |
| 3438 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
| 3439 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3440 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3441 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3442 | dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3443 | |
| 3444 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3445 | dev_priv->rps.min_freq_softlimit); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3446 | |
| 3447 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
| 3448 | & GENFREQSTATUS) == 0, 5)) |
| 3449 | DRM_ERROR("timed out waiting for Punit\n"); |
| 3450 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 3451 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3452 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3453 | I915_WRITE(GEN6_PMINTRMSK, |
| 3454 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3455 | } |
| 3456 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3457 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 3458 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3459 | struct drm_device *dev = dev_priv->dev; |
| 3460 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3461 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3462 | if (dev_priv->rps.enabled) { |
Deepak S | 3463811 | 2014-06-28 11:26:26 +0530 | [diff] [blame] | 3463 | if (IS_CHERRYVIEW(dev)) |
| 3464 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
| 3465 | else if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 3466 | vlv_set_rps_idle(dev_priv); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3467 | else if (!dev_priv->rps.is_bdw_sw_turbo |
| 3468 | || atomic_read(&dev_priv->rps.sw_turbo.flip_received)){ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3469 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3472 | dev_priv->rps.last_adj = 0; |
| 3473 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3474 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3475 | } |
| 3476 | |
| 3477 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 3478 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3479 | struct drm_device *dev = dev_priv->dev; |
| 3480 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3481 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3482 | if (dev_priv->rps.enabled) { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 3483 | if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3484 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3485 | else if (!dev_priv->rps.is_bdw_sw_turbo |
| 3486 | || atomic_read(&dev_priv->rps.sw_turbo.flip_received)){ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3487 | gen6_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 3490 | dev_priv->rps.last_adj = 0; |
| 3491 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 3492 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3493 | } |
| 3494 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3495 | void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 3496 | { |
| 3497 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7a67092 | 2013-06-25 19:21:06 +0300 | [diff] [blame] | 3498 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3499 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3500 | WARN_ON(val > dev_priv->rps.max_freq_softlimit); |
| 3501 | WARN_ON(val < dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3502 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 3503 | DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3504 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 3505 | dev_priv->rps.cur_freq, |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3506 | vlv_gpu_freq(dev_priv, val), val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3507 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 3508 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 3509 | "Odd GPU freq value\n")) |
| 3510 | val &= ~1; |
| 3511 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3512 | if (val != dev_priv->rps.cur_freq) |
| 3513 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3514 | |
Imre Deak | 09c87db | 2014-04-03 20:02:42 +0300 | [diff] [blame] | 3515 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3516 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3517 | dev_priv->rps.cur_freq = val; |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 3518 | trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv, val)); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3521 | static void gen8_disable_rps_interrupts(struct drm_device *dev) |
| 3522 | { |
| 3523 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3524 | if (IS_BROADWELL(dev) && dev_priv->rps.is_bdw_sw_turbo){ |
| 3525 | if (atomic_read(&dev_priv->rps.sw_turbo.flip_received)) |
| 3526 | del_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3527 | dev_priv-> rps.is_bdw_sw_turbo = false; |
| 3528 | } else { |
| 3529 | I915_WRITE(GEN6_PMINTRMSK, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP); |
| 3530 | I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) & |
| 3531 | ~dev_priv->pm_rps_events); |
| 3532 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3533 | * item again unmasking PM interrupts because that is using a different |
| 3534 | * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in |
| 3535 | * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which |
| 3536 | * gen8_enable_rps will clean up. */ |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3537 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3538 | spin_lock_irq(&dev_priv->irq_lock); |
| 3539 | dev_priv->rps.pm_iir = 0; |
| 3540 | spin_unlock_irq(&dev_priv->irq_lock); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3541 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3542 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3543 | } |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3544 | } |
| 3545 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3546 | static void gen6_disable_rps_interrupts(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3547 | { |
| 3548 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3549 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3550 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3551 | I915_WRITE(GEN6_PMIER, I915_READ(GEN6_PMIER) & |
| 3552 | ~dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3553 | /* Complete PM interrupt masking here doesn't race with the rps work |
| 3554 | * item again unmasking PM interrupts because that is using a different |
| 3555 | * register (PMIMR) to mask PM interrupts. The only risk is in leaving |
| 3556 | * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */ |
| 3557 | |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3558 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 3559 | dev_priv->rps.pm_iir = 0; |
Daniel Vetter | 59cdb63 | 2013-07-04 23:35:28 +0200 | [diff] [blame] | 3560 | spin_unlock_irq(&dev_priv->irq_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3561 | |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3562 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3563 | } |
| 3564 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3565 | static void gen6_disable_rps(struct drm_device *dev) |
| 3566 | { |
| 3567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3568 | |
| 3569 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3570 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
| 3571 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3572 | if (IS_BROADWELL(dev)) |
| 3573 | gen8_disable_rps_interrupts(dev); |
| 3574 | else |
| 3575 | gen6_disable_rps_interrupts(dev); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3576 | } |
| 3577 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3578 | static void cherryview_disable_rps(struct drm_device *dev) |
| 3579 | { |
| 3580 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3581 | |
| 3582 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 3583 | |
| 3584 | gen8_disable_rps_interrupts(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 3585 | } |
| 3586 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3587 | static void valleyview_disable_rps(struct drm_device *dev) |
| 3588 | { |
| 3589 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3590 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3591 | /* we're doing forcewake before Disabling RC6, |
| 3592 | * This what the BIOS expects when going into suspend */ |
| 3593 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 3594 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3595 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3596 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 3597 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 3598 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3599 | gen6_disable_rps_interrupts(dev); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3602 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 3603 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 3604 | if (IS_VALLEYVIEW(dev)) { |
| 3605 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 3606 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 3607 | else |
| 3608 | mode = 0; |
| 3609 | } |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3610 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n", |
| 3611 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 3612 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 3613 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3614 | } |
| 3615 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3616 | 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] | 3617 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 3618 | /* No RC6 before Ironlake */ |
| 3619 | if (INTEL_INFO(dev)->gen < 5) |
| 3620 | return 0; |
| 3621 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3622 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 3623 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 3624 | return 0; |
| 3625 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 3626 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3627 | if (enable_rc6 >= 0) { |
| 3628 | int mask; |
| 3629 | |
| 3630 | if (INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev)) |
| 3631 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 3632 | INTEL_RC6pp_ENABLE; |
| 3633 | else |
| 3634 | mask = INTEL_RC6_ENABLE; |
| 3635 | |
| 3636 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 3637 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 3638 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3639 | |
| 3640 | return enable_rc6 & mask; |
| 3641 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3642 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 3643 | /* Disable RC6 on Ironlake */ |
| 3644 | if (INTEL_INFO(dev)->gen == 5) |
| 3645 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3646 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3647 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 3648 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 3649 | |
| 3650 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3651 | } |
| 3652 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 3653 | int intel_enable_rc6(const struct drm_device *dev) |
| 3654 | { |
| 3655 | return i915.enable_rc6; |
| 3656 | } |
| 3657 | |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3658 | static void gen8_enable_rps_interrupts(struct drm_device *dev) |
| 3659 | { |
| 3660 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3661 | |
| 3662 | spin_lock_irq(&dev_priv->irq_lock); |
| 3663 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 3664 | gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Ben Widawsky | 0961021 | 2014-05-15 20:58:08 +0300 | [diff] [blame] | 3665 | I915_WRITE(GEN8_GT_IIR(2), dev_priv->pm_rps_events); |
| 3666 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3667 | } |
| 3668 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3669 | static void gen6_enable_rps_interrupts(struct drm_device *dev) |
| 3670 | { |
| 3671 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3672 | |
| 3673 | spin_lock_irq(&dev_priv->irq_lock); |
Daniel Vetter | a0b3335 | 2013-07-04 23:35:34 +0200 | [diff] [blame] | 3674 | WARN_ON(dev_priv->rps.pm_iir); |
Daniel Vetter | 480c803 | 2014-07-16 09:49:40 +0200 | [diff] [blame] | 3675 | gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events); |
Deepak S | a6706b4 | 2014-03-15 20:23:22 +0530 | [diff] [blame] | 3676 | I915_WRITE(GEN6_PMIIR, dev_priv->pm_rps_events); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3677 | spin_unlock_irq(&dev_priv->irq_lock); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 3678 | } |
| 3679 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3680 | static void parse_rp_state_cap(struct drm_i915_private *dev_priv, u32 rp_state_cap) |
| 3681 | { |
| 3682 | /* All of these values are in units of 50MHz */ |
| 3683 | dev_priv->rps.cur_freq = 0; |
| 3684 | /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */ |
| 3685 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
| 3686 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
| 3687 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
| 3688 | /* XXX: only BYT has a special efficient freq */ |
| 3689 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 3690 | /* hw_max = RP0 until we check for overclocking */ |
| 3691 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 3692 | |
| 3693 | /* Preserve min/max settings in case of re-init */ |
| 3694 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 3695 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 3696 | |
| 3697 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 3698 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 3699 | } |
| 3700 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3701 | static void bdw_sw_calculate_freq(struct drm_device *dev, |
| 3702 | struct intel_rps_bdw_cal *c, u32 *cur_time, u32 *c0) |
| 3703 | { |
| 3704 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3705 | u64 busy = 0; |
| 3706 | u32 busyness_pct = 0; |
| 3707 | u32 elapsed_time = 0; |
| 3708 | u16 new_freq = 0; |
| 3709 | |
| 3710 | if (!c || !cur_time || !c0) |
| 3711 | return; |
| 3712 | |
| 3713 | if (0 == c->last_c0) |
| 3714 | goto out; |
| 3715 | |
| 3716 | /* Check Evaluation interval */ |
| 3717 | elapsed_time = *cur_time - c->last_ts; |
| 3718 | if (elapsed_time < c->eval_interval) |
| 3719 | return; |
| 3720 | |
| 3721 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3722 | |
| 3723 | /* |
| 3724 | * c0 unit in 32*1.28 usec, elapsed_time unit in 1 usec. |
| 3725 | * Whole busyness_pct calculation should be |
| 3726 | * busy = ((u64)(*c0 - c->last_c0) << 5 << 7) / 100; |
| 3727 | * busyness_pct = (u32)(busy * 100 / elapsed_time); |
| 3728 | * The final formula is to simplify CPU calculation |
| 3729 | */ |
| 3730 | busy = (u64)(*c0 - c->last_c0) << 12; |
| 3731 | do_div(busy, elapsed_time); |
| 3732 | busyness_pct = (u32)busy; |
| 3733 | |
| 3734 | if (c->is_up && busyness_pct >= c->it_threshold_pct) |
| 3735 | new_freq = (u16)dev_priv->rps.cur_freq + 3; |
| 3736 | if (!c->is_up && busyness_pct <= c->it_threshold_pct) |
| 3737 | new_freq = (u16)dev_priv->rps.cur_freq - 1; |
| 3738 | |
| 3739 | /* Adjust to new frequency busyness and compare with threshold */ |
| 3740 | if (0 != new_freq) { |
| 3741 | if (new_freq > dev_priv->rps.max_freq_softlimit) |
| 3742 | new_freq = dev_priv->rps.max_freq_softlimit; |
| 3743 | else if (new_freq < dev_priv->rps.min_freq_softlimit) |
| 3744 | new_freq = dev_priv->rps.min_freq_softlimit; |
| 3745 | |
| 3746 | gen6_set_rps(dev, new_freq); |
| 3747 | } |
| 3748 | |
| 3749 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3750 | |
| 3751 | out: |
| 3752 | c->last_c0 = *c0; |
| 3753 | c->last_ts = *cur_time; |
| 3754 | } |
| 3755 | |
| 3756 | static void gen8_set_frequency_RP0(struct work_struct *work) |
| 3757 | { |
| 3758 | struct intel_rps_bdw_turbo *p_bdw_turbo = |
| 3759 | container_of(work, struct intel_rps_bdw_turbo, work_max_freq); |
| 3760 | struct intel_gen6_power_mgmt *p_power_mgmt = |
| 3761 | container_of(p_bdw_turbo, struct intel_gen6_power_mgmt, sw_turbo); |
| 3762 | struct drm_i915_private *dev_priv = |
| 3763 | container_of(p_power_mgmt, struct drm_i915_private, rps); |
| 3764 | |
| 3765 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3766 | gen6_set_rps(dev_priv->dev, dev_priv->rps.rp0_freq); |
| 3767 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3768 | } |
| 3769 | |
| 3770 | static void flip_active_timeout_handler(unsigned long var) |
| 3771 | { |
| 3772 | struct drm_i915_private *dev_priv = (struct drm_i915_private *) var; |
| 3773 | |
| 3774 | del_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3775 | atomic_set(&dev_priv->rps.sw_turbo.flip_received, false); |
| 3776 | |
| 3777 | queue_work(dev_priv->wq, &dev_priv->rps.sw_turbo.work_max_freq); |
| 3778 | } |
| 3779 | |
| 3780 | void bdw_software_turbo(struct drm_device *dev) |
| 3781 | { |
| 3782 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3783 | |
| 3784 | u32 current_time = I915_READ(TIMESTAMP_CTR); /* unit in usec */ |
| 3785 | u32 current_c0 = I915_READ(MCHBAR_PCU_C0); /* unit in 32*1.28 usec */ |
| 3786 | |
| 3787 | bdw_sw_calculate_freq(dev, &dev_priv->rps.sw_turbo.up, |
| 3788 | ¤t_time, ¤t_c0); |
| 3789 | bdw_sw_calculate_freq(dev, &dev_priv->rps.sw_turbo.down, |
| 3790 | ¤t_time, ¤t_c0); |
| 3791 | } |
| 3792 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3793 | static void gen8_enable_rps(struct drm_device *dev) |
| 3794 | { |
| 3795 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3796 | struct intel_engine_cs *ring; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3797 | uint32_t rc6_mask = 0, rp_state_cap; |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3798 | uint32_t threshold_up_pct, threshold_down_pct; |
| 3799 | uint32_t ei_up, ei_down; /* up and down evaluation interval */ |
| 3800 | u32 rp_ctl_flag; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3801 | int unused; |
| 3802 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3803 | /* Use software Turbo for BDW */ |
| 3804 | dev_priv->rps.is_bdw_sw_turbo = IS_BROADWELL(dev); |
| 3805 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3806 | /* 1a: Software RC state - RC0 */ |
| 3807 | I915_WRITE(GEN6_RC_STATE, 0); |
| 3808 | |
| 3809 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 3810 | * 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] | 3811 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3812 | |
| 3813 | /* 2a: Disable RC states. */ |
| 3814 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3815 | |
| 3816 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3817 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3818 | |
| 3819 | /* 2b: Program RC6 thresholds.*/ |
| 3820 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 3821 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 3822 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 3823 | for_each_ring(ring, dev_priv, unused) |
| 3824 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 3825 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3826 | if (IS_BROADWELL(dev)) |
| 3827 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 3828 | else |
| 3829 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3830 | |
| 3831 | /* 3: Enable RC6 */ |
| 3832 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 3833 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 3834 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 3835 | if (IS_BROADWELL(dev)) |
| 3836 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3837 | GEN7_RC_CTL_TO_MODE | |
| 3838 | rc6_mask); |
| 3839 | else |
| 3840 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 3841 | GEN6_RC_CTL_EI_MODE(1) | |
| 3842 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3843 | |
| 3844 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 3845 | I915_WRITE(GEN6_RPNSWREQ, |
| 3846 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 3847 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 3848 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3849 | ei_up = 84480; /* 84.48ms */ |
| 3850 | ei_down = 448000; |
| 3851 | threshold_up_pct = 90; /* x percent busy */ |
| 3852 | threshold_down_pct = 70; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3853 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3854 | if (dev_priv->rps.is_bdw_sw_turbo) { |
| 3855 | dev_priv->rps.sw_turbo.up.it_threshold_pct = threshold_up_pct; |
| 3856 | dev_priv->rps.sw_turbo.up.eval_interval = ei_up; |
| 3857 | dev_priv->rps.sw_turbo.up.is_up = true; |
| 3858 | dev_priv->rps.sw_turbo.up.last_ts = 0; |
| 3859 | dev_priv->rps.sw_turbo.up.last_c0 = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3860 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3861 | dev_priv->rps.sw_turbo.down.it_threshold_pct = threshold_down_pct; |
| 3862 | dev_priv->rps.sw_turbo.down.eval_interval = ei_down; |
| 3863 | dev_priv->rps.sw_turbo.down.is_up = false; |
| 3864 | dev_priv->rps.sw_turbo.down.last_ts = 0; |
| 3865 | dev_priv->rps.sw_turbo.down.last_c0 = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3866 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3867 | /* Start the timer to track if flip comes*/ |
| 3868 | dev_priv->rps.sw_turbo.timeout = 200*1000; /* in us */ |
| 3869 | |
| 3870 | init_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3871 | dev_priv->rps.sw_turbo.flip_timer.function = flip_active_timeout_handler; |
| 3872 | dev_priv->rps.sw_turbo.flip_timer.data = (unsigned long) dev_priv; |
| 3873 | dev_priv->rps.sw_turbo.flip_timer.expires = |
| 3874 | usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies; |
| 3875 | add_timer(&dev_priv->rps.sw_turbo.flip_timer); |
| 3876 | INIT_WORK(&dev_priv->rps.sw_turbo.work_max_freq, gen8_set_frequency_RP0); |
| 3877 | |
| 3878 | atomic_set(&dev_priv->rps.sw_turbo.flip_received, true); |
| 3879 | } else { |
| 3880 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent |
| 3881 | * 1 second timeout*/ |
| 3882 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, FREQ_1_28_US(1000000)); |
| 3883 | |
| 3884 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 3885 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 3886 | dev_priv->rps.max_freq_softlimit << 24 | |
| 3887 | dev_priv->rps.min_freq_softlimit << 16); |
| 3888 | |
| 3889 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
| 3890 | FREQ_1_28_US(ei_up * threshold_up_pct / 100)); |
| 3891 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
| 3892 | FREQ_1_28_US(ei_down * threshold_down_pct / 100)); |
| 3893 | I915_WRITE(GEN6_RP_UP_EI, |
| 3894 | FREQ_1_28_US(ei_up)); |
| 3895 | I915_WRITE(GEN6_RP_DOWN_EI, |
| 3896 | FREQ_1_28_US(ei_down)); |
| 3897 | |
| 3898 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 3899 | } |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3900 | |
| 3901 | /* 5: Enable RPS */ |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3902 | rp_ctl_flag = GEN6_RP_MEDIA_TURBO | |
| 3903 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3904 | GEN6_RP_MEDIA_IS_GFX | |
| 3905 | GEN6_RP_UP_BUSY_AVG | |
| 3906 | GEN6_RP_DOWN_IDLE_AVG; |
| 3907 | if (!dev_priv->rps.is_bdw_sw_turbo) |
| 3908 | rp_ctl_flag |= GEN6_RP_ENABLE; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3909 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3910 | I915_WRITE(GEN6_RP_CONTROL, rp_ctl_flag); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3911 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3912 | /* 6: Ring frequency + overclocking |
| 3913 | * (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3914 | gen6_set_rps(dev, (I915_READ(GEN6_GT_PERF_STATUS) & 0xff00) >> 8); |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 3915 | if (!dev_priv->rps.is_bdw_sw_turbo) |
| 3916 | gen8_enable_rps_interrupts(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3917 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3918 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3921 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3922 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3923 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 3924 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 3925 | u32 rp_state_cap; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 3926 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3927 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3928 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3929 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3930 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3931 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 3932 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3933 | /* Here begins a magic sequence of register writes to enable |
| 3934 | * auto-downclocking. |
| 3935 | * |
| 3936 | * Perhaps there might be some value in exposing these to |
| 3937 | * userspace... |
| 3938 | */ |
| 3939 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3940 | |
| 3941 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 3942 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 3943 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 3944 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 3945 | } |
| 3946 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 3947 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3948 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3949 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3950 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 3951 | parse_rp_state_cap(dev_priv, rp_state_cap); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 3952 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3953 | /* disable the counters and set deterministic thresholds */ |
| 3954 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 3955 | |
| 3956 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 3957 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 3958 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 3959 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 3960 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 3961 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 3962 | for_each_ring(ring, dev_priv, i) |
| 3963 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3964 | |
| 3965 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 3966 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 3967 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 3968 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 3969 | else |
| 3970 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 3971 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3972 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 3973 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3974 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3975 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 3976 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 3977 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 3978 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3979 | /* We don't use those on Haswell */ |
| 3980 | if (!IS_HASWELL(dev)) { |
| 3981 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 3982 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3983 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 3984 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 3985 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 3986 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3987 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 3988 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3989 | |
| 3990 | I915_WRITE(GEN6_RC_CONTROL, |
| 3991 | rc6_mask | |
| 3992 | GEN6_RC_CTL_EI_MODE(1) | |
| 3993 | GEN6_RC_CTL_HW_ENABLE); |
| 3994 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3995 | /* Power down if completely idle for over 50ms */ |
| 3996 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3997 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3998 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 3999 | 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] | 4000 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4001 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4002 | |
| 4003 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4004 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4005 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4006 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4007 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4008 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4009 | } |
| 4010 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4011 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4012 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4013 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4014 | gen6_enable_rps_interrupts(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4015 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4016 | rc6vids = 0; |
| 4017 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4018 | if (IS_GEN6(dev) && ret) { |
| 4019 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4020 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4021 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4022 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4023 | rc6vids &= 0xffff00; |
| 4024 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4025 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4026 | if (ret) |
| 4027 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4028 | } |
| 4029 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4030 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4031 | } |
| 4032 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4033 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4034 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4035 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4036 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4037 | unsigned int gpu_freq; |
| 4038 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4039 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4040 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4041 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4042 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4043 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4044 | policy = cpufreq_cpu_get(0); |
| 4045 | if (policy) { |
| 4046 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4047 | cpufreq_cpu_put(policy); |
| 4048 | } else { |
| 4049 | /* |
| 4050 | * Default to measured freq if none found, PCU will ensure we |
| 4051 | * don't go over |
| 4052 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4053 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4054 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4055 | |
| 4056 | /* Convert from kHz to MHz */ |
| 4057 | max_ia_freq /= 1000; |
| 4058 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4059 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4060 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4061 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4062 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4063 | /* |
| 4064 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4065 | * to use for memory access. We do this by specifying the IA frequency |
| 4066 | * the PCU should use as a reference to determine the ring frequency. |
| 4067 | */ |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4068 | 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] | 4069 | gpu_freq--) { |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4070 | int diff = dev_priv->rps.max_freq_softlimit - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4071 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4072 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4073 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4074 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4075 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4076 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4077 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4078 | ring_freq = max(min_ring_freq, ring_freq); |
| 4079 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4080 | } else { |
| 4081 | /* On older processors, there is no separate ring |
| 4082 | * clock domain, so in order to boost the bandwidth |
| 4083 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4084 | * |
| 4085 | * For GPU frequencies less than 750MHz, |
| 4086 | * just use the lowest ring freq. |
| 4087 | */ |
| 4088 | if (gpu_freq < min_freq) |
| 4089 | ia_freq = 800; |
| 4090 | else |
| 4091 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4092 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4093 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4094 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4095 | sandybridge_pcode_write(dev_priv, |
| 4096 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4097 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4098 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4099 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4100 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4101 | } |
| 4102 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4103 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4104 | { |
| 4105 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4106 | |
| 4107 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4108 | return; |
| 4109 | |
| 4110 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4111 | __gen6_update_ring_freq(dev); |
| 4112 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4113 | } |
| 4114 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4115 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4116 | { |
| 4117 | u32 val, rp0; |
| 4118 | |
| 4119 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4120 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4121 | |
| 4122 | return rp0; |
| 4123 | } |
| 4124 | |
| 4125 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4126 | { |
| 4127 | u32 val, rpe; |
| 4128 | |
| 4129 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4130 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4131 | |
| 4132 | return rpe; |
| 4133 | } |
| 4134 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4135 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4136 | { |
| 4137 | u32 val, rp1; |
| 4138 | |
| 4139 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4140 | rp1 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4141 | |
| 4142 | return rp1; |
| 4143 | } |
| 4144 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4145 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4146 | { |
| 4147 | u32 val, rpn; |
| 4148 | |
| 4149 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4150 | rpn = (val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK; |
| 4151 | return rpn; |
| 4152 | } |
| 4153 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4154 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4155 | { |
| 4156 | u32 val, rp1; |
| 4157 | |
| 4158 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4159 | |
| 4160 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4161 | |
| 4162 | return rp1; |
| 4163 | } |
| 4164 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4165 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4166 | { |
| 4167 | u32 val, rp0; |
| 4168 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4169 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4170 | |
| 4171 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4172 | /* Clamp to max */ |
| 4173 | rp0 = min_t(u32, rp0, 0xea); |
| 4174 | |
| 4175 | return rp0; |
| 4176 | } |
| 4177 | |
| 4178 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4179 | { |
| 4180 | u32 val, rpe; |
| 4181 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4182 | 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] | 4183 | 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] | 4184 | 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] | 4185 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4186 | |
| 4187 | return rpe; |
| 4188 | } |
| 4189 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4190 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4191 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4192 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4195 | /* Check that the pctx buffer wasn't move under us. */ |
| 4196 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4197 | { |
| 4198 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4199 | |
| 4200 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4201 | dev_priv->vlv_pctx->stolen->start); |
| 4202 | } |
| 4203 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4204 | |
| 4205 | /* Check that the pcbr address is not empty. */ |
| 4206 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4207 | { |
| 4208 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4209 | |
| 4210 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4211 | } |
| 4212 | |
| 4213 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4214 | { |
| 4215 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4216 | unsigned long pctx_paddr, paddr; |
| 4217 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4218 | u32 pcbr; |
| 4219 | int pctx_size = 32*1024; |
| 4220 | |
| 4221 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4222 | |
| 4223 | pcbr = I915_READ(VLV_PCBR); |
| 4224 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
| 4225 | paddr = (dev_priv->mm.stolen_base + |
| 4226 | (gtt->stolen_size - pctx_size)); |
| 4227 | |
| 4228 | pctx_paddr = (paddr & (~4095)); |
| 4229 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4230 | } |
| 4231 | } |
| 4232 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4233 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4234 | { |
| 4235 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4236 | struct drm_i915_gem_object *pctx; |
| 4237 | unsigned long pctx_paddr; |
| 4238 | u32 pcbr; |
| 4239 | int pctx_size = 24*1024; |
| 4240 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4241 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4242 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4243 | pcbr = I915_READ(VLV_PCBR); |
| 4244 | if (pcbr) { |
| 4245 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4246 | int pcbr_offset; |
| 4247 | |
| 4248 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4249 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4250 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4251 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4252 | pctx_size); |
| 4253 | goto out; |
| 4254 | } |
| 4255 | |
| 4256 | /* |
| 4257 | * From the Gunit register HAS: |
| 4258 | * The Gfx driver is expected to program this register and ensure |
| 4259 | * proper allocation within Gfx stolen memory. For example, this |
| 4260 | * register should be programmed such than the PCBR range does not |
| 4261 | * overlap with other ranges, such as the frame buffer, protected |
| 4262 | * memory, or any other relevant ranges. |
| 4263 | */ |
| 4264 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4265 | if (!pctx) { |
| 4266 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4267 | return; |
| 4268 | } |
| 4269 | |
| 4270 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4271 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4272 | |
| 4273 | out: |
| 4274 | dev_priv->vlv_pctx = pctx; |
| 4275 | } |
| 4276 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4277 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4278 | { |
| 4279 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4280 | |
| 4281 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4282 | return; |
| 4283 | |
| 4284 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4285 | dev_priv->vlv_pctx = NULL; |
| 4286 | } |
| 4287 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4288 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4289 | { |
| 4290 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4291 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4292 | |
| 4293 | valleyview_setup_pctx(dev); |
| 4294 | |
| 4295 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4296 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4297 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4298 | switch ((val >> 6) & 3) { |
| 4299 | case 0: |
| 4300 | case 1: |
| 4301 | dev_priv->mem_freq = 800; |
| 4302 | break; |
| 4303 | case 2: |
| 4304 | dev_priv->mem_freq = 1066; |
| 4305 | break; |
| 4306 | case 3: |
| 4307 | dev_priv->mem_freq = 1333; |
| 4308 | break; |
| 4309 | } |
| 4310 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
| 4311 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4312 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4313 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4314 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 4315 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 4316 | dev_priv->rps.max_freq); |
| 4317 | |
| 4318 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4319 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 4320 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4321 | dev_priv->rps.efficient_freq); |
| 4322 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4323 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4324 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
| 4325 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 4326 | dev_priv->rps.rp1_freq); |
| 4327 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4328 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4329 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 4330 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 4331 | dev_priv->rps.min_freq); |
| 4332 | |
| 4333 | /* Preserve min/max settings in case of re-init */ |
| 4334 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4335 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4336 | |
| 4337 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4338 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4339 | |
| 4340 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4341 | } |
| 4342 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4343 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4344 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4345 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4346 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4347 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4348 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4349 | |
| 4350 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4351 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4352 | val = vlv_punit_read(dev_priv, CCK_FUSE_REG); |
| 4353 | switch ((val >> 2) & 0x7) { |
| 4354 | case 0: |
| 4355 | case 1: |
| 4356 | dev_priv->rps.cz_freq = 200; |
| 4357 | dev_priv->mem_freq = 1600; |
| 4358 | break; |
| 4359 | case 2: |
| 4360 | dev_priv->rps.cz_freq = 267; |
| 4361 | dev_priv->mem_freq = 1600; |
| 4362 | break; |
| 4363 | case 3: |
| 4364 | dev_priv->rps.cz_freq = 333; |
| 4365 | dev_priv->mem_freq = 2000; |
| 4366 | break; |
| 4367 | case 4: |
| 4368 | dev_priv->rps.cz_freq = 320; |
| 4369 | dev_priv->mem_freq = 1600; |
| 4370 | break; |
| 4371 | case 5: |
| 4372 | dev_priv->rps.cz_freq = 400; |
| 4373 | dev_priv->mem_freq = 1600; |
| 4374 | break; |
| 4375 | } |
| 4376 | DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv->mem_freq); |
| 4377 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4378 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4379 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4380 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
| 4381 | vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
| 4382 | dev_priv->rps.max_freq); |
| 4383 | |
| 4384 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4385 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
| 4386 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4387 | dev_priv->rps.efficient_freq); |
| 4388 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4389 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4390 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
| 4391 | vlv_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
| 4392 | dev_priv->rps.rp1_freq); |
| 4393 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4394 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4395 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
| 4396 | vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
| 4397 | dev_priv->rps.min_freq); |
| 4398 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4399 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4400 | dev_priv->rps.efficient_freq | |
| 4401 | dev_priv->rps.rp1_freq | |
| 4402 | dev_priv->rps.min_freq) & 1, |
| 4403 | "Odd GPU freq values\n"); |
| 4404 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4405 | /* Preserve min/max settings in case of re-init */ |
| 4406 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4407 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4408 | |
| 4409 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4410 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4411 | |
| 4412 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4413 | } |
| 4414 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4415 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4416 | { |
| 4417 | valleyview_cleanup_pctx(dev); |
| 4418 | } |
| 4419 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4420 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4421 | { |
| 4422 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4423 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4424 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4425 | int i; |
| 4426 | |
| 4427 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4428 | |
| 4429 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4430 | if (gtfifodbg) { |
| 4431 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4432 | gtfifodbg); |
| 4433 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4434 | } |
| 4435 | |
| 4436 | cherryview_check_pctx(dev_priv); |
| 4437 | |
| 4438 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4439 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
| 4440 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 4441 | |
| 4442 | /* 2a: Program RC6 thresholds.*/ |
| 4443 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4444 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4445 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4446 | |
| 4447 | for_each_ring(ring, dev_priv, i) |
| 4448 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4449 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4450 | |
| 4451 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
| 4452 | |
| 4453 | /* allows RC6 residency counter to work */ |
| 4454 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 4455 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 4456 | VLV_MEDIA_RC6_COUNT_EN | |
| 4457 | VLV_RENDER_RC6_COUNT_EN)); |
| 4458 | |
| 4459 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 4460 | pcbr = I915_READ(VLV_PCBR); |
| 4461 | |
| 4462 | DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr); |
| 4463 | |
| 4464 | /* 3: Enable RC6 */ |
| 4465 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 4466 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
| 4467 | rc6_mode = GEN6_RC_CTL_EI_MODE(1); |
| 4468 | |
| 4469 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 4470 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4471 | /* 4 Program defaults and thresholds for RPS*/ |
| 4472 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4473 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4474 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4475 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4476 | |
| 4477 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 4478 | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4479 | /* WaDisablePwrmtrEvent:chv (pre-production hw) */ |
| 4480 | I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff); |
| 4481 | I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00); |
| 4482 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4483 | /* 5: Enable RPS */ |
| 4484 | I915_WRITE(GEN6_RP_CONTROL, |
| 4485 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Tom O'Rourke | 7405f42 | 2014-06-10 16:26:34 -0700 | [diff] [blame] | 4486 | GEN6_RP_MEDIA_IS_GFX | /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */ |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4487 | GEN6_RP_ENABLE | |
| 4488 | GEN6_RP_UP_BUSY_AVG | |
| 4489 | GEN6_RP_DOWN_IDLE_AVG); |
| 4490 | |
| 4491 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4492 | |
| 4493 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4494 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4495 | |
| 4496 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 4497 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
| 4498 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4499 | dev_priv->rps.cur_freq); |
| 4500 | |
| 4501 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
| 4502 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4503 | dev_priv->rps.efficient_freq); |
| 4504 | |
| 4505 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 4506 | |
Deepak S | 3497a56 | 2014-07-10 13:16:26 +0530 | [diff] [blame] | 4507 | gen8_enable_rps_interrupts(dev); |
| 4508 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4509 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 4510 | } |
| 4511 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4512 | static void valleyview_enable_rps(struct drm_device *dev) |
| 4513 | { |
| 4514 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4515 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 4516 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4517 | int i; |
| 4518 | |
| 4519 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4520 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4521 | valleyview_check_pctx(dev_priv); |
| 4522 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4523 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 4524 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4525 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4526 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4527 | } |
| 4528 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4529 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
| 4530 | gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4531 | |
| 4532 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 4533 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 4534 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 4535 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 4536 | |
| 4537 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4538 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4539 | |
| 4540 | I915_WRITE(GEN6_RP_CONTROL, |
| 4541 | GEN6_RP_MEDIA_TURBO | |
| 4542 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4543 | GEN6_RP_MEDIA_IS_GFX | |
| 4544 | GEN6_RP_ENABLE | |
| 4545 | GEN6_RP_UP_BUSY_AVG | |
| 4546 | GEN6_RP_DOWN_IDLE_CONT); |
| 4547 | |
| 4548 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 4549 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4550 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4551 | |
| 4552 | for_each_ring(ring, dev_priv, i) |
| 4553 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4554 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 4555 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4556 | |
| 4557 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4558 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4559 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 4560 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 4561 | VLV_MEDIA_RC6_COUNT_EN | |
| 4562 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 4563 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4564 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 4565 | 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] | 4566 | |
| 4567 | intel_print_rc6_info(dev, rc6_mode); |
| 4568 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 4569 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4570 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4571 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4572 | |
| 4573 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & 0x10 ? "yes" : "no"); |
| 4574 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 4575 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4576 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4577 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4578 | vlv_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
| 4579 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4580 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 4581 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4582 | vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
| 4583 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4584 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4585 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4586 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4587 | gen6_enable_rps_interrupts(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4588 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 4589 | gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4590 | } |
| 4591 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4592 | void ironlake_teardown_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4593 | { |
| 4594 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4595 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4596 | if (dev_priv->ips.renderctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4597 | i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4598 | drm_gem_object_unreference(&dev_priv->ips.renderctx->base); |
| 4599 | dev_priv->ips.renderctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4600 | } |
| 4601 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4602 | if (dev_priv->ips.pwrctx) { |
Ben Widawsky | d7f46fc | 2013-12-06 14:10:55 -0800 | [diff] [blame] | 4603 | i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx); |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4604 | drm_gem_object_unreference(&dev_priv->ips.pwrctx->base); |
| 4605 | dev_priv->ips.pwrctx = NULL; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4609 | static void ironlake_disable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4610 | { |
| 4611 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4612 | |
| 4613 | if (I915_READ(PWRCTXA)) { |
| 4614 | /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */ |
| 4615 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT); |
| 4616 | wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON), |
| 4617 | 50); |
| 4618 | |
| 4619 | I915_WRITE(PWRCTXA, 0); |
| 4620 | POSTING_READ(PWRCTXA); |
| 4621 | |
| 4622 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
| 4623 | POSTING_READ(RSTDBYCTL); |
| 4624 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | static int ironlake_setup_rc6(struct drm_device *dev) |
| 4628 | { |
| 4629 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4630 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4631 | if (dev_priv->ips.renderctx == NULL) |
| 4632 | dev_priv->ips.renderctx = intel_alloc_context_page(dev); |
| 4633 | if (!dev_priv->ips.renderctx) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4634 | return -ENOMEM; |
| 4635 | |
Daniel Vetter | 3e37394 | 2012-11-02 19:55:04 +0100 | [diff] [blame] | 4636 | if (dev_priv->ips.pwrctx == NULL) |
| 4637 | dev_priv->ips.pwrctx = intel_alloc_context_page(dev); |
| 4638 | if (!dev_priv->ips.pwrctx) { |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4639 | ironlake_teardown_rc6(dev); |
| 4640 | return -ENOMEM; |
| 4641 | } |
| 4642 | |
| 4643 | return 0; |
| 4644 | } |
| 4645 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 4646 | static void ironlake_enable_rc6(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4647 | { |
| 4648 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4649 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4650 | bool was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4651 | int ret; |
| 4652 | |
| 4653 | /* rc6 disabled by default due to repeated reports of hanging during |
| 4654 | * boot and resume. |
| 4655 | */ |
| 4656 | if (!intel_enable_rc6(dev)) |
| 4657 | return; |
| 4658 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4659 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4660 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4661 | ret = ironlake_setup_rc6(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4662 | if (ret) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4663 | return; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4664 | |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4665 | was_interruptible = dev_priv->mm.interruptible; |
| 4666 | dev_priv->mm.interruptible = false; |
| 4667 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4668 | /* |
| 4669 | * GPU can automatically power down the render unit if given a page |
| 4670 | * to save state. |
| 4671 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4672 | ret = intel_ring_begin(ring, 6); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4673 | if (ret) { |
| 4674 | ironlake_teardown_rc6(dev); |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4675 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4676 | return; |
| 4677 | } |
| 4678 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 4679 | intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN); |
| 4680 | intel_ring_emit(ring, MI_SET_CONTEXT); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4681 | 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] | 4682 | MI_MM_SPACE_GTT | |
| 4683 | MI_SAVE_EXT_STATE_EN | |
| 4684 | MI_RESTORE_EXT_STATE_EN | |
| 4685 | MI_RESTORE_INHIBIT); |
| 4686 | intel_ring_emit(ring, MI_SUSPEND_FLUSH); |
| 4687 | intel_ring_emit(ring, MI_NOOP); |
| 4688 | intel_ring_emit(ring, MI_FLUSH); |
| 4689 | intel_ring_advance(ring); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4690 | |
| 4691 | /* |
| 4692 | * Wait for the command parser to advance past MI_SET_CONTEXT. The HW |
| 4693 | * does an implicit flush, combined with MI_FLUSH above, it should be |
| 4694 | * safe to assume that renderctx is valid |
| 4695 | */ |
Chris Wilson | 3e96050 | 2012-11-27 16:22:54 +0000 | [diff] [blame] | 4696 | ret = intel_ring_idle(ring); |
| 4697 | dev_priv->mm.interruptible = was_interruptible; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4698 | if (ret) { |
Jani Nikula | def27a5 | 2013-03-12 10:49:19 +0200 | [diff] [blame] | 4699 | DRM_ERROR("failed to enable ironlake power savings\n"); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4700 | ironlake_teardown_rc6(dev); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4701 | return; |
| 4702 | } |
| 4703 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 4704 | 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] | 4705 | I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4706 | |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4707 | intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4708 | } |
| 4709 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 4710 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 4711 | { |
| 4712 | unsigned long freq; |
| 4713 | int div = (vidfreq & 0x3f0000) >> 16; |
| 4714 | int post = (vidfreq & 0x3000) >> 12; |
| 4715 | int pre = (vidfreq & 0x7); |
| 4716 | |
| 4717 | if (!pre) |
| 4718 | return 0; |
| 4719 | |
| 4720 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 4721 | |
| 4722 | return freq; |
| 4723 | } |
| 4724 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4725 | static const struct cparams { |
| 4726 | u16 i; |
| 4727 | u16 t; |
| 4728 | u16 m; |
| 4729 | u16 c; |
| 4730 | } cparams[] = { |
| 4731 | { 1, 1333, 301, 28664 }, |
| 4732 | { 1, 1066, 294, 24460 }, |
| 4733 | { 1, 800, 294, 25192 }, |
| 4734 | { 0, 1333, 276, 27605 }, |
| 4735 | { 0, 1066, 276, 27605 }, |
| 4736 | { 0, 800, 231, 23784 }, |
| 4737 | }; |
| 4738 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4739 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4740 | { |
| 4741 | u64 total_count, diff, ret; |
| 4742 | u32 count1, count2, count3, m = 0, c = 0; |
| 4743 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 4744 | int i; |
| 4745 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4746 | assert_spin_locked(&mchdev_lock); |
| 4747 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4748 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4749 | |
| 4750 | /* Prevent division-by-zero if we are asking too fast. |
| 4751 | * Also, we don't get interesting results if we are polling |
| 4752 | * faster than once in 10ms, so just return the saved value |
| 4753 | * in such cases. |
| 4754 | */ |
| 4755 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4756 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4757 | |
| 4758 | count1 = I915_READ(DMIEC); |
| 4759 | count2 = I915_READ(DDREC); |
| 4760 | count3 = I915_READ(CSIEC); |
| 4761 | |
| 4762 | total_count = count1 + count2 + count3; |
| 4763 | |
| 4764 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4765 | if (total_count < dev_priv->ips.last_count1) { |
| 4766 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4767 | diff += total_count; |
| 4768 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4769 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4773 | if (cparams[i].i == dev_priv->ips.c_m && |
| 4774 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4775 | m = cparams[i].m; |
| 4776 | c = cparams[i].c; |
| 4777 | break; |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | diff = div_u64(diff, diff1); |
| 4782 | ret = ((m * diff) + c); |
| 4783 | ret = div_u64(ret, 10); |
| 4784 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4785 | dev_priv->ips.last_count1 = total_count; |
| 4786 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4787 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4788 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4789 | |
| 4790 | return ret; |
| 4791 | } |
| 4792 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4793 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 4794 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4795 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4796 | unsigned long val; |
| 4797 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4798 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 4799 | return 0; |
| 4800 | |
| 4801 | spin_lock_irq(&mchdev_lock); |
| 4802 | |
| 4803 | val = __i915_chipset_val(dev_priv); |
| 4804 | |
| 4805 | spin_unlock_irq(&mchdev_lock); |
| 4806 | |
| 4807 | return val; |
| 4808 | } |
| 4809 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4810 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 4811 | { |
| 4812 | unsigned long m, x, b; |
| 4813 | u32 tsfs; |
| 4814 | |
| 4815 | tsfs = I915_READ(TSFS); |
| 4816 | |
| 4817 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 4818 | x = I915_READ8(TR1); |
| 4819 | |
| 4820 | b = tsfs & TSFS_INTR_MASK; |
| 4821 | |
| 4822 | return ((m * x) / 127) - b; |
| 4823 | } |
| 4824 | |
| 4825 | static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
| 4826 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4827 | struct drm_device *dev = dev_priv->dev; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4828 | static const struct v_table { |
| 4829 | u16 vd; /* in .1 mil */ |
| 4830 | u16 vm; /* in .1 mil */ |
| 4831 | } v_table[] = { |
| 4832 | { 0, 0, }, |
| 4833 | { 375, 0, }, |
| 4834 | { 500, 0, }, |
| 4835 | { 625, 0, }, |
| 4836 | { 750, 0, }, |
| 4837 | { 875, 0, }, |
| 4838 | { 1000, 0, }, |
| 4839 | { 1125, 0, }, |
| 4840 | { 4125, 3000, }, |
| 4841 | { 4125, 3000, }, |
| 4842 | { 4125, 3000, }, |
| 4843 | { 4125, 3000, }, |
| 4844 | { 4125, 3000, }, |
| 4845 | { 4125, 3000, }, |
| 4846 | { 4125, 3000, }, |
| 4847 | { 4125, 3000, }, |
| 4848 | { 4125, 3000, }, |
| 4849 | { 4125, 3000, }, |
| 4850 | { 4125, 3000, }, |
| 4851 | { 4125, 3000, }, |
| 4852 | { 4125, 3000, }, |
| 4853 | { 4125, 3000, }, |
| 4854 | { 4125, 3000, }, |
| 4855 | { 4125, 3000, }, |
| 4856 | { 4125, 3000, }, |
| 4857 | { 4125, 3000, }, |
| 4858 | { 4125, 3000, }, |
| 4859 | { 4125, 3000, }, |
| 4860 | { 4125, 3000, }, |
| 4861 | { 4125, 3000, }, |
| 4862 | { 4125, 3000, }, |
| 4863 | { 4125, 3000, }, |
| 4864 | { 4250, 3125, }, |
| 4865 | { 4375, 3250, }, |
| 4866 | { 4500, 3375, }, |
| 4867 | { 4625, 3500, }, |
| 4868 | { 4750, 3625, }, |
| 4869 | { 4875, 3750, }, |
| 4870 | { 5000, 3875, }, |
| 4871 | { 5125, 4000, }, |
| 4872 | { 5250, 4125, }, |
| 4873 | { 5375, 4250, }, |
| 4874 | { 5500, 4375, }, |
| 4875 | { 5625, 4500, }, |
| 4876 | { 5750, 4625, }, |
| 4877 | { 5875, 4750, }, |
| 4878 | { 6000, 4875, }, |
| 4879 | { 6125, 5000, }, |
| 4880 | { 6250, 5125, }, |
| 4881 | { 6375, 5250, }, |
| 4882 | { 6500, 5375, }, |
| 4883 | { 6625, 5500, }, |
| 4884 | { 6750, 5625, }, |
| 4885 | { 6875, 5750, }, |
| 4886 | { 7000, 5875, }, |
| 4887 | { 7125, 6000, }, |
| 4888 | { 7250, 6125, }, |
| 4889 | { 7375, 6250, }, |
| 4890 | { 7500, 6375, }, |
| 4891 | { 7625, 6500, }, |
| 4892 | { 7750, 6625, }, |
| 4893 | { 7875, 6750, }, |
| 4894 | { 8000, 6875, }, |
| 4895 | { 8125, 7000, }, |
| 4896 | { 8250, 7125, }, |
| 4897 | { 8375, 7250, }, |
| 4898 | { 8500, 7375, }, |
| 4899 | { 8625, 7500, }, |
| 4900 | { 8750, 7625, }, |
| 4901 | { 8875, 7750, }, |
| 4902 | { 9000, 7875, }, |
| 4903 | { 9125, 8000, }, |
| 4904 | { 9250, 8125, }, |
| 4905 | { 9375, 8250, }, |
| 4906 | { 9500, 8375, }, |
| 4907 | { 9625, 8500, }, |
| 4908 | { 9750, 8625, }, |
| 4909 | { 9875, 8750, }, |
| 4910 | { 10000, 8875, }, |
| 4911 | { 10125, 9000, }, |
| 4912 | { 10250, 9125, }, |
| 4913 | { 10375, 9250, }, |
| 4914 | { 10500, 9375, }, |
| 4915 | { 10625, 9500, }, |
| 4916 | { 10750, 9625, }, |
| 4917 | { 10875, 9750, }, |
| 4918 | { 11000, 9875, }, |
| 4919 | { 11125, 10000, }, |
| 4920 | { 11250, 10125, }, |
| 4921 | { 11375, 10250, }, |
| 4922 | { 11500, 10375, }, |
| 4923 | { 11625, 10500, }, |
| 4924 | { 11750, 10625, }, |
| 4925 | { 11875, 10750, }, |
| 4926 | { 12000, 10875, }, |
| 4927 | { 12125, 11000, }, |
| 4928 | { 12250, 11125, }, |
| 4929 | { 12375, 11250, }, |
| 4930 | { 12500, 11375, }, |
| 4931 | { 12625, 11500, }, |
| 4932 | { 12750, 11625, }, |
| 4933 | { 12875, 11750, }, |
| 4934 | { 13000, 11875, }, |
| 4935 | { 13125, 12000, }, |
| 4936 | { 13250, 12125, }, |
| 4937 | { 13375, 12250, }, |
| 4938 | { 13500, 12375, }, |
| 4939 | { 13625, 12500, }, |
| 4940 | { 13750, 12625, }, |
| 4941 | { 13875, 12750, }, |
| 4942 | { 14000, 12875, }, |
| 4943 | { 14125, 13000, }, |
| 4944 | { 14250, 13125, }, |
| 4945 | { 14375, 13250, }, |
| 4946 | { 14500, 13375, }, |
| 4947 | { 14625, 13500, }, |
| 4948 | { 14750, 13625, }, |
| 4949 | { 14875, 13750, }, |
| 4950 | { 15000, 13875, }, |
| 4951 | { 15125, 14000, }, |
| 4952 | { 15250, 14125, }, |
| 4953 | { 15375, 14250, }, |
| 4954 | { 15500, 14375, }, |
| 4955 | { 15625, 14500, }, |
| 4956 | { 15750, 14625, }, |
| 4957 | { 15875, 14750, }, |
| 4958 | { 16000, 14875, }, |
| 4959 | { 16125, 15000, }, |
| 4960 | }; |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 4961 | if (INTEL_INFO(dev)->is_mobile) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4962 | return v_table[pxvid].vm; |
| 4963 | else |
| 4964 | return v_table[pxvid].vd; |
| 4965 | } |
| 4966 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4967 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4968 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 4969 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4970 | u32 count; |
| 4971 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 4972 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4973 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 4974 | now = ktime_get_raw_ns(); |
| 4975 | diffms = now - dev_priv->ips.last_time2; |
| 4976 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4977 | |
| 4978 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4979 | if (!diffms) |
| 4980 | return; |
| 4981 | |
| 4982 | count = I915_READ(GFXEC); |
| 4983 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4984 | if (count < dev_priv->ips.last_count2) { |
| 4985 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4986 | diff += count; |
| 4987 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4988 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4989 | } |
| 4990 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4991 | dev_priv->ips.last_count2 = count; |
| 4992 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4993 | |
| 4994 | /* More magic constants... */ |
| 4995 | diff = diff * 1181; |
| 4996 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 4997 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 4998 | } |
| 4999 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5000 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5001 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5002 | struct drm_device *dev = dev_priv->dev; |
| 5003 | |
| 5004 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5005 | return; |
| 5006 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5007 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5008 | |
| 5009 | __i915_update_gfx_val(dev_priv); |
| 5010 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5011 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5012 | } |
| 5013 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5014 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5015 | { |
| 5016 | unsigned long t, corr, state1, corr2, state2; |
| 5017 | u32 pxvid, ext_v; |
| 5018 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5019 | assert_spin_locked(&mchdev_lock); |
| 5020 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5021 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5022 | pxvid = (pxvid >> 24) & 0x7f; |
| 5023 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5024 | |
| 5025 | state1 = ext_v; |
| 5026 | |
| 5027 | t = i915_mch_val(dev_priv); |
| 5028 | |
| 5029 | /* Revel in the empirically derived constants */ |
| 5030 | |
| 5031 | /* Correction factor in 1/100000 units */ |
| 5032 | if (t > 80) |
| 5033 | corr = ((t * 2349) + 135940); |
| 5034 | else if (t >= 50) |
| 5035 | corr = ((t * 964) + 29317); |
| 5036 | else /* < 50 */ |
| 5037 | corr = ((t * 301) + 1004); |
| 5038 | |
| 5039 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5040 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5041 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5042 | |
| 5043 | state2 = (corr2 * state1) / 10000; |
| 5044 | state2 /= 100; /* convert to mW */ |
| 5045 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5046 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5047 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5048 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5049 | } |
| 5050 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5051 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5052 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5053 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5054 | unsigned long val; |
| 5055 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5056 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5057 | return 0; |
| 5058 | |
| 5059 | spin_lock_irq(&mchdev_lock); |
| 5060 | |
| 5061 | val = __i915_gfx_val(dev_priv); |
| 5062 | |
| 5063 | spin_unlock_irq(&mchdev_lock); |
| 5064 | |
| 5065 | return val; |
| 5066 | } |
| 5067 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5068 | /** |
| 5069 | * i915_read_mch_val - return value for IPS use |
| 5070 | * |
| 5071 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5072 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5073 | */ |
| 5074 | unsigned long i915_read_mch_val(void) |
| 5075 | { |
| 5076 | struct drm_i915_private *dev_priv; |
| 5077 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5078 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5079 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5080 | if (!i915_mch_dev) |
| 5081 | goto out_unlock; |
| 5082 | dev_priv = i915_mch_dev; |
| 5083 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5084 | chipset_val = __i915_chipset_val(dev_priv); |
| 5085 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5086 | |
| 5087 | ret = chipset_val + graphics_val; |
| 5088 | |
| 5089 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5090 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5091 | |
| 5092 | return ret; |
| 5093 | } |
| 5094 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5095 | |
| 5096 | /** |
| 5097 | * i915_gpu_raise - raise GPU frequency limit |
| 5098 | * |
| 5099 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5100 | */ |
| 5101 | bool i915_gpu_raise(void) |
| 5102 | { |
| 5103 | struct drm_i915_private *dev_priv; |
| 5104 | bool ret = true; |
| 5105 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5106 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5107 | if (!i915_mch_dev) { |
| 5108 | ret = false; |
| 5109 | goto out_unlock; |
| 5110 | } |
| 5111 | dev_priv = i915_mch_dev; |
| 5112 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5113 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5114 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5115 | |
| 5116 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5117 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5118 | |
| 5119 | return ret; |
| 5120 | } |
| 5121 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5122 | |
| 5123 | /** |
| 5124 | * i915_gpu_lower - lower GPU frequency limit |
| 5125 | * |
| 5126 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5127 | * frequency maximum. |
| 5128 | */ |
| 5129 | bool i915_gpu_lower(void) |
| 5130 | { |
| 5131 | struct drm_i915_private *dev_priv; |
| 5132 | bool ret = true; |
| 5133 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5134 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5135 | if (!i915_mch_dev) { |
| 5136 | ret = false; |
| 5137 | goto out_unlock; |
| 5138 | } |
| 5139 | dev_priv = i915_mch_dev; |
| 5140 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5141 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5142 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5143 | |
| 5144 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5145 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5146 | |
| 5147 | return ret; |
| 5148 | } |
| 5149 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5150 | |
| 5151 | /** |
| 5152 | * i915_gpu_busy - indicate GPU business to IPS |
| 5153 | * |
| 5154 | * Tell the IPS driver whether or not the GPU is busy. |
| 5155 | */ |
| 5156 | bool i915_gpu_busy(void) |
| 5157 | { |
| 5158 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5159 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5160 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5161 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5162 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5163 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5164 | if (!i915_mch_dev) |
| 5165 | goto out_unlock; |
| 5166 | dev_priv = i915_mch_dev; |
| 5167 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5168 | for_each_ring(ring, dev_priv, i) |
| 5169 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5170 | |
| 5171 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5172 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5173 | |
| 5174 | return ret; |
| 5175 | } |
| 5176 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5177 | |
| 5178 | /** |
| 5179 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5180 | * |
| 5181 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5182 | * current frequency to the default. |
| 5183 | */ |
| 5184 | bool i915_gpu_turbo_disable(void) |
| 5185 | { |
| 5186 | struct drm_i915_private *dev_priv; |
| 5187 | bool ret = true; |
| 5188 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5189 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5190 | if (!i915_mch_dev) { |
| 5191 | ret = false; |
| 5192 | goto out_unlock; |
| 5193 | } |
| 5194 | dev_priv = i915_mch_dev; |
| 5195 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5196 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5197 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5198 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5199 | ret = false; |
| 5200 | |
| 5201 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5202 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5203 | |
| 5204 | return ret; |
| 5205 | } |
| 5206 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5207 | |
| 5208 | /** |
| 5209 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5210 | * IPS got loaded first. |
| 5211 | * |
| 5212 | * This awkward dance is so that neither module has to depend on the |
| 5213 | * other in order for IPS to do the appropriate communication of |
| 5214 | * GPU turbo limits to i915. |
| 5215 | */ |
| 5216 | static void |
| 5217 | ips_ping_for_i915_load(void) |
| 5218 | { |
| 5219 | void (*link)(void); |
| 5220 | |
| 5221 | link = symbol_get(ips_link_to_i915_driver); |
| 5222 | if (link) { |
| 5223 | link(); |
| 5224 | symbol_put(ips_link_to_i915_driver); |
| 5225 | } |
| 5226 | } |
| 5227 | |
| 5228 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5229 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5230 | /* We only register the i915 ips part with intel-ips once everything is |
| 5231 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5232 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5233 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5234 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5235 | |
| 5236 | ips_ping_for_i915_load(); |
| 5237 | } |
| 5238 | |
| 5239 | void intel_gpu_ips_teardown(void) |
| 5240 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5241 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5242 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5243 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5244 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5245 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5246 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5247 | { |
| 5248 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5249 | u32 lcfuse; |
| 5250 | u8 pxw[16]; |
| 5251 | int i; |
| 5252 | |
| 5253 | /* Disable to program */ |
| 5254 | I915_WRITE(ECR, 0); |
| 5255 | POSTING_READ(ECR); |
| 5256 | |
| 5257 | /* Program energy weights for various events */ |
| 5258 | I915_WRITE(SDEW, 0x15040d00); |
| 5259 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5260 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5261 | I915_WRITE(CSIEW2, 0x04000004); |
| 5262 | |
| 5263 | for (i = 0; i < 5; i++) |
| 5264 | I915_WRITE(PEW + (i * 4), 0); |
| 5265 | for (i = 0; i < 3; i++) |
| 5266 | I915_WRITE(DEW + (i * 4), 0); |
| 5267 | |
| 5268 | /* Program P-state weights to account for frequency power adjustment */ |
| 5269 | for (i = 0; i < 16; i++) { |
| 5270 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5271 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5272 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5273 | PXVFREQ_PX_SHIFT; |
| 5274 | unsigned long val; |
| 5275 | |
| 5276 | val = vid * vid; |
| 5277 | val *= (freq / 1000); |
| 5278 | val *= 255; |
| 5279 | val /= (127*127*900); |
| 5280 | if (val > 0xff) |
| 5281 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5282 | pxw[i] = val; |
| 5283 | } |
| 5284 | /* Render standby states get 0 weight */ |
| 5285 | pxw[14] = 0; |
| 5286 | pxw[15] = 0; |
| 5287 | |
| 5288 | for (i = 0; i < 4; i++) { |
| 5289 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5290 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5291 | I915_WRITE(PXW + (i * 4), val); |
| 5292 | } |
| 5293 | |
| 5294 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5295 | I915_WRITE(OGW0, 0); |
| 5296 | I915_WRITE(OGW1, 0); |
| 5297 | I915_WRITE(EG0, 0x00007f00); |
| 5298 | I915_WRITE(EG1, 0x0000000e); |
| 5299 | I915_WRITE(EG2, 0x000e0000); |
| 5300 | I915_WRITE(EG3, 0x68000300); |
| 5301 | I915_WRITE(EG4, 0x42000000); |
| 5302 | I915_WRITE(EG5, 0x00140031); |
| 5303 | I915_WRITE(EG6, 0); |
| 5304 | I915_WRITE(EG7, 0); |
| 5305 | |
| 5306 | for (i = 0; i < 8; i++) |
| 5307 | I915_WRITE(PXWL + (i * 4), 0); |
| 5308 | |
| 5309 | /* Enable PMON + select events */ |
| 5310 | I915_WRITE(ECR, 0x80000019); |
| 5311 | |
| 5312 | lcfuse = I915_READ(LCFUSE02); |
| 5313 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5314 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5315 | } |
| 5316 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5317 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5318 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5319 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5320 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5321 | if (IS_CHERRYVIEW(dev)) |
| 5322 | cherryview_init_gt_powersave(dev); |
| 5323 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5324 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5328 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5329 | if (IS_CHERRYVIEW(dev)) |
| 5330 | return; |
| 5331 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5332 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5333 | } |
| 5334 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5335 | /** |
| 5336 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5337 | * @dev: drm device |
| 5338 | * |
| 5339 | * We don't want to disable RC6 or other features here, we just want |
| 5340 | * to make sure any work we've queued has finished and won't bother |
| 5341 | * us while we're suspended. |
| 5342 | */ |
| 5343 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5344 | { |
| 5345 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5346 | |
| 5347 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 5348 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5349 | |
| 5350 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5351 | |
| 5352 | cancel_work_sync(&dev_priv->rps.work); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5353 | |
| 5354 | /* Force GPU to min freq during suspend */ |
| 5355 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5358 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5359 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5360 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5361 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 5362 | /* Interrupts should be disabled already to avoid re-arming. */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 5363 | WARN_ON(intel_irqs_enabled(dev_priv)); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 5364 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5365 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5366 | ironlake_disable_drps(dev); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5367 | ironlake_disable_rc6(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5368 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5369 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5370 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5371 | mutex_lock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5372 | if (IS_CHERRYVIEW(dev)) |
| 5373 | cherryview_disable_rps(dev); |
| 5374 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5375 | valleyview_disable_rps(dev); |
| 5376 | else |
| 5377 | gen6_disable_rps(dev); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5378 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5379 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5380 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5381 | } |
| 5382 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5383 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5384 | { |
| 5385 | struct drm_i915_private *dev_priv = |
| 5386 | container_of(work, struct drm_i915_private, |
| 5387 | rps.delayed_resume_work.work); |
| 5388 | struct drm_device *dev = dev_priv->dev; |
| 5389 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 5390 | dev_priv->rps.is_bdw_sw_turbo = false; |
| 5391 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5392 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5393 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5394 | if (IS_CHERRYVIEW(dev)) { |
| 5395 | cherryview_enable_rps(dev); |
| 5396 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5397 | valleyview_enable_rps(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5398 | } else if (IS_BROADWELL(dev)) { |
| 5399 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5400 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5401 | } else { |
| 5402 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5403 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5404 | } |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5405 | dev_priv->rps.enabled = true; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5406 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5407 | |
| 5408 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5409 | } |
| 5410 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5411 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5412 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5413 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5414 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5415 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5416 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5417 | ironlake_enable_drps(dev); |
| 5418 | ironlake_enable_rc6(dev); |
| 5419 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5420 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5421 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5422 | /* |
| 5423 | * PCU communication is slow and this doesn't need to be |
| 5424 | * done at any specific time, so do this out of our fast path |
| 5425 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5426 | * |
| 5427 | * We depend on the HW RC6 power context save/restore |
| 5428 | * mechanism when entering D3 through runtime PM suspend. So |
| 5429 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5430 | * get here via the driver load/system resume/runtime resume |
| 5431 | * paths, so the _noresume version is enough (and in case of |
| 5432 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5433 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5434 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5435 | round_jiffies_up_relative(HZ))) |
| 5436 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5437 | } |
| 5438 | } |
| 5439 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5440 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5441 | { |
| 5442 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5443 | |
| 5444 | dev_priv->rps.enabled = false; |
| 5445 | intel_enable_gt_powersave(dev); |
| 5446 | } |
| 5447 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5448 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5449 | { |
| 5450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5451 | |
| 5452 | /* |
| 5453 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5454 | * gating for the panel power sequencer or it will fail to |
| 5455 | * start up when no ports are active. |
| 5456 | */ |
| 5457 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5458 | } |
| 5459 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5460 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5461 | { |
| 5462 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5463 | int pipe; |
| 5464 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5465 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5466 | I915_WRITE(DSPCNTR(pipe), |
| 5467 | I915_READ(DSPCNTR(pipe)) | |
| 5468 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5469 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5470 | } |
| 5471 | } |
| 5472 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5473 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5474 | { |
| 5475 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5476 | |
| 5477 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5478 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5479 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5480 | |
| 5481 | /* |
| 5482 | * Don't touch WM1S_LP_EN here. |
| 5483 | * Doing so could cause underruns. |
| 5484 | */ |
| 5485 | } |
| 5486 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5487 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5488 | { |
| 5489 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5490 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5491 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5492 | /* |
| 5493 | * Required for FBC |
| 5494 | * WaFbcDisableDpfcClockGating:ilk |
| 5495 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5496 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5497 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5498 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5499 | |
| 5500 | I915_WRITE(PCH_3DCGDIS0, |
| 5501 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5502 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5503 | I915_WRITE(PCH_3DCGDIS1, |
| 5504 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5505 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5506 | /* |
| 5507 | * According to the spec the following bits should be set in |
| 5508 | * order to enable memory self-refresh |
| 5509 | * The bit 22/21 of 0x42004 |
| 5510 | * The bit 5 of 0x42020 |
| 5511 | * The bit 15 of 0x45000 |
| 5512 | */ |
| 5513 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5514 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5515 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5516 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5517 | I915_WRITE(DISP_ARB_CTL, |
| 5518 | (I915_READ(DISP_ARB_CTL) | |
| 5519 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5520 | |
| 5521 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5522 | |
| 5523 | /* |
| 5524 | * Based on the document from hardware guys the following bits |
| 5525 | * should be set unconditionally in order to enable FBC. |
| 5526 | * The bit 22 of 0x42000 |
| 5527 | * The bit 22 of 0x42004 |
| 5528 | * The bit 7,8,9 of 0x42020. |
| 5529 | */ |
| 5530 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5531 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5532 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5533 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5534 | ILK_FBCQ_DIS); |
| 5535 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5536 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5537 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5538 | } |
| 5539 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5540 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5541 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5542 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5543 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5544 | ILK_ELPIN_409_SELECT); |
| 5545 | I915_WRITE(_3D_CHICKEN2, |
| 5546 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5547 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5548 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5549 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5550 | I915_WRITE(CACHE_MODE_0, |
| 5551 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5552 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5553 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5554 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5555 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5556 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5557 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5558 | ibx_init_clock_gating(dev); |
| 5559 | } |
| 5560 | |
| 5561 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5562 | { |
| 5563 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5564 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5565 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5566 | |
| 5567 | /* |
| 5568 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5569 | * gating for the panel power sequencer or it will fail to |
| 5570 | * start up when no ports are active. |
| 5571 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5572 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5573 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5574 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5575 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5576 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5577 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5578 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5579 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5580 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5581 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5582 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5583 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5584 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5585 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5586 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5587 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5588 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5589 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5590 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5591 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5592 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5593 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5594 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5595 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5596 | } |
| 5597 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5598 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5599 | { |
| 5600 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5601 | uint32_t tmp; |
| 5602 | |
| 5603 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5604 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5605 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5606 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5607 | } |
| 5608 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5609 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5610 | { |
| 5611 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5612 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5613 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5614 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5615 | |
| 5616 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5617 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5618 | ILK_ELPIN_409_SELECT); |
| 5619 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5620 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5621 | I915_WRITE(_3D_CHICKEN, |
| 5622 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5623 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5624 | /* WaSetupGtModeTdRowDispatch:snb */ |
Daniel Vetter | 6547fbd | 2012-12-14 23:38:29 +0100 | [diff] [blame] | 5625 | if (IS_SNB_GT1(dev)) |
| 5626 | I915_WRITE(GEN6_GT_MODE, |
| 5627 | _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE)); |
| 5628 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5629 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5630 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5631 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5632 | /* |
| 5633 | * BSpec recoomends 8x4 when MSAA is used, |
| 5634 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5635 | * |
| 5636 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5637 | * disable bit, which we don't touch here, but it's good |
| 5638 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5639 | */ |
| 5640 | I915_WRITE(GEN6_GT_MODE, |
| 5641 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5642 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5643 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5644 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5645 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5646 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5647 | |
| 5648 | I915_WRITE(GEN6_UCGCTL1, |
| 5649 | I915_READ(GEN6_UCGCTL1) | |
| 5650 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5651 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5652 | |
| 5653 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5654 | * gating disable must be set. Failure to set it results in |
| 5655 | * flickering pixels due to Z write ordering failures after |
| 5656 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5657 | * Sanctuary and Tropics, and apparently anything else with |
| 5658 | * alpha test or pixel discard. |
| 5659 | * |
| 5660 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 5661 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5662 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 5663 | * WaDisableRCCUnitClockGating:snb |
| 5664 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5665 | */ |
| 5666 | I915_WRITE(GEN6_UCGCTL2, |
| 5667 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 5668 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 5669 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 5670 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 5671 | I915_WRITE(_3D_CHICKEN3, |
| 5672 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5673 | |
| 5674 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 5675 | * Bspec says: |
| 5676 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 5677 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 5678 | */ |
| 5679 | I915_WRITE(_3D_CHICKEN3, |
| 5680 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 5681 | |
| 5682 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5683 | * According to the spec the following bits should be |
| 5684 | * set in order to enable memory self-refresh and fbc: |
| 5685 | * The bit21 and bit22 of 0x42000 |
| 5686 | * The bit21 and bit22 of 0x42004 |
| 5687 | * The bit5 and bit7 of 0x42020 |
| 5688 | * The bit14 of 0x70180 |
| 5689 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5690 | * |
| 5691 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5692 | */ |
| 5693 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5694 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5695 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 5696 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5697 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5698 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5699 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 5700 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 5701 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 5702 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5703 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5704 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 5705 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5706 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5707 | |
| 5708 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 5712 | { |
| 5713 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 5714 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5715 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5716 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 5717 | * |
| 5718 | * This actually overrides the dispatch |
| 5719 | * mode for all thread types. |
| 5720 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5721 | reg &= ~GEN7_FF_SCHED_MASK; |
| 5722 | reg |= GEN7_FF_TS_SCHED_HW; |
| 5723 | reg |= GEN7_FF_VS_SCHED_HW; |
| 5724 | reg |= GEN7_FF_DS_SCHED_HW; |
| 5725 | |
| 5726 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 5727 | } |
| 5728 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5729 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 5730 | { |
| 5731 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5732 | |
| 5733 | /* |
| 5734 | * TODO: this bit should only be enabled when really needed, then |
| 5735 | * disabled when not needed anymore in order to save power. |
| 5736 | */ |
| 5737 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 5738 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 5739 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 5740 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 5741 | |
| 5742 | /* WADPOClockGatingDisable:hsw */ |
| 5743 | I915_WRITE(_TRANSA_CHICKEN1, |
| 5744 | I915_READ(_TRANSA_CHICKEN1) | |
| 5745 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5746 | } |
| 5747 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 5748 | static void lpt_suspend_hw(struct drm_device *dev) |
| 5749 | { |
| 5750 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5751 | |
| 5752 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 5753 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 5754 | |
| 5755 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 5756 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 5757 | } |
| 5758 | } |
| 5759 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 5760 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5761 | { |
| 5762 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5763 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5764 | |
| 5765 | I915_WRITE(WM3_LP_ILK, 0); |
| 5766 | I915_WRITE(WM2_LP_ILK, 0); |
| 5767 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5768 | |
| 5769 | /* FIXME(BDW): Check all the w/a, some might only apply to |
| 5770 | * pre-production hw. */ |
| 5771 | |
Kenneth Graunke | c8966e1 | 2014-02-26 23:59:30 -0800 | [diff] [blame] | 5772 | |
Ben Widawsky | 4afe8d3 | 2013-11-02 21:07:55 -0700 | [diff] [blame] | 5773 | I915_WRITE(GAMTARBMODE, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE)); |
| 5774 | |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5775 | I915_WRITE(_3D_CHICKEN3, |
Michel Thierry | b3f9ad9 | 2014-07-07 12:40:17 +0100 | [diff] [blame] | 5776 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2))); |
Ben Widawsky | 7f88da0 | 2013-11-02 21:07:58 -0700 | [diff] [blame] | 5777 | |
Ben Widawsky | 242a401 | 2014-04-18 18:04:29 -0300 | [diff] [blame] | 5778 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5779 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 5780 | 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] | 5781 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5782 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5783 | I915_WRITE(CHICKEN_PAR1_1, |
| 5784 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 5785 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5786 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5787 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 5788 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 5789 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 5790 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 5791 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 5792 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 5793 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 5794 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 5795 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5796 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 5797 | ~(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] | 5798 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 5799 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 5800 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 5801 | |
| 5802 | /* WaDisableSDEUnitClockGating:bdw */ |
| 5803 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 5804 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 5805 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 5806 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5809 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 5810 | { |
| 5811 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5812 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5813 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5814 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 5815 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 5816 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 5817 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 5818 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 5819 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5820 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5821 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5822 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5823 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5824 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 5825 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 5826 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 5827 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5828 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5829 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 5830 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5831 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 5832 | /* enable HiZ Raw Stall Optimization */ |
| 5833 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5834 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5835 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5836 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5837 | I915_WRITE(CACHE_MODE_1, |
| 5838 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5839 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5840 | /* |
| 5841 | * BSpec recommends 8x4 when MSAA is used, |
| 5842 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5843 | * |
| 5844 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5845 | * disable bit, which we don't touch here, but it's good |
| 5846 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 5847 | */ |
| 5848 | I915_WRITE(GEN7_GT_MODE, |
| 5849 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5850 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5851 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 5852 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 5853 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 5854 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 5855 | I915_WRITE(CHICKEN_PAR1_1, |
| 5856 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 5857 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 5858 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 5859 | } |
| 5860 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5861 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5862 | { |
| 5863 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5864 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5865 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5866 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5867 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5868 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5869 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5870 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5871 | I915_WRITE(_3D_CHICKEN3, |
| 5872 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5873 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5874 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5875 | I915_WRITE(IVB_CHICKEN3, |
| 5876 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5877 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5878 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5879 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5880 | if (IS_IVB_GT1(dev)) |
| 5881 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 5882 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5883 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5884 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 5885 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5886 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5887 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5888 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 5889 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 5890 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5891 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5892 | I915_WRITE(GEN7_L3CNTLREG1, |
| 5893 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 5894 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5895 | GEN7_WA_L3_CHICKEN_MODE); |
| 5896 | if (IS_IVB_GT1(dev)) |
| 5897 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5898 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5899 | else { |
| 5900 | /* must write both registers */ |
| 5901 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5902 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5903 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 5904 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 5905 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5906 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5907 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5908 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5909 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5910 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 5911 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5912 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5913 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5914 | */ |
| 5915 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 5916 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5917 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5918 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5919 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5920 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5921 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5922 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5923 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5924 | |
| 5925 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5926 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 5927 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 5928 | /* enable HiZ Raw Stall Optimization */ |
| 5929 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 5930 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 5931 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 5932 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5933 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 5934 | I915_WRITE(CACHE_MODE_1, |
| 5935 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5936 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5937 | /* |
| 5938 | * BSpec recommends 8x4 when MSAA is used, |
| 5939 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5940 | * |
| 5941 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5942 | * disable bit, which we don't touch here, but it's good |
| 5943 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 5944 | */ |
| 5945 | I915_WRITE(GEN7_GT_MODE, |
| 5946 | GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4); |
| 5947 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 5948 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 5949 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 5950 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 5951 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5952 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 5953 | if (!HAS_PCH_NOP(dev)) |
| 5954 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5955 | |
| 5956 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5957 | } |
| 5958 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5959 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5960 | { |
| 5961 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5962 | |
Ville Syrjälä | d7fe0cc | 2013-05-21 18:01:50 +0300 | [diff] [blame] | 5963 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5964 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5965 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 5966 | I915_WRITE(_3D_CHICKEN3, |
| 5967 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 5968 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5969 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5970 | I915_WRITE(IVB_CHICKEN3, |
| 5971 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 5972 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 5973 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 5974 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5975 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5976 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 5977 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 5978 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 5979 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5980 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 5981 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5982 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5983 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 5984 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 5985 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 5986 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5987 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 5988 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 5989 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 5990 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5991 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5992 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 5993 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 5994 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 5995 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 5996 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 5997 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 5998 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 5999 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6000 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6001 | */ |
| 6002 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6003 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6004 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6005 | /* WaDisableL3Bank2xClockGate:vlv |
| 6006 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6007 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6008 | I915_WRITE(GEN7_UCGCTL4, |
| 6009 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6010 | |
Ville Syrjälä | e0d8d59 | 2013-06-12 22:11:18 +0300 | [diff] [blame] | 6011 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6012 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6013 | /* |
| 6014 | * BSpec says this must be set, even though |
| 6015 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6016 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6017 | I915_WRITE(CACHE_MODE_1, |
| 6018 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6019 | |
| 6020 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6021 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6022 | * This is the hardware default actually. |
| 6023 | */ |
| 6024 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6025 | |
| 6026 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6027 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6028 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6029 | * in the reporting of vblank events. |
| 6030 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6031 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6032 | } |
| 6033 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6034 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6035 | { |
| 6036 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6037 | |
| 6038 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6039 | |
| 6040 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6041 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6042 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6043 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6044 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6045 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6046 | ~(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] | 6047 | |
| 6048 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6049 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6050 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6051 | |
| 6052 | /* WaDisableCSUnitClockGating:chv */ |
| 6053 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6054 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6055 | |
| 6056 | /* WaDisableSDEUnitClockGating:chv */ |
| 6057 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6058 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Rafael Barbalho | e0d34ce | 2014-04-09 13:28:40 +0300 | [diff] [blame] | 6059 | |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 6060 | /* WaDisableGunitClockGating:chv (pre-production hw) */ |
| 6061 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, I915_READ(VLV_GUNIT_CLOCK_GATE) | |
| 6062 | GINT_DIS); |
| 6063 | |
| 6064 | /* WaDisableFfDopClockGating:chv (pre-production hw) */ |
| 6065 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6066 | _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE)); |
| 6067 | |
| 6068 | /* WaDisableDopClockGating:chv (pre-production hw) */ |
Ville Syrjälä | e4443e4 | 2014-04-09 13:28:41 +0300 | [diff] [blame] | 6069 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6070 | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6071 | } |
| 6072 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6073 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6074 | { |
| 6075 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6076 | uint32_t dspclk_gate; |
| 6077 | |
| 6078 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6079 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6080 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6081 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6082 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6083 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6084 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6085 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6086 | if (IS_GM45(dev)) |
| 6087 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6088 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6089 | |
| 6090 | /* WaDisableRenderCachePipelinedFlush */ |
| 6091 | I915_WRITE(CACHE_MODE_0, |
| 6092 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6093 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6094 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6095 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6096 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6097 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6098 | } |
| 6099 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6100 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6101 | { |
| 6102 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6103 | |
| 6104 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6105 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6106 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6107 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6108 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6109 | I915_WRITE(MI_ARB_STATE, |
| 6110 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6111 | |
| 6112 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6113 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6114 | } |
| 6115 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6116 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6117 | { |
| 6118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6119 | |
| 6120 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6121 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6122 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6123 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6124 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6125 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6126 | I915_WRITE(MI_ARB_STATE, |
| 6127 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6128 | |
| 6129 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6130 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6131 | } |
| 6132 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6133 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6134 | { |
| 6135 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6136 | u32 dstate = I915_READ(D_STATE); |
| 6137 | |
| 6138 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6139 | DSTATE_DOT_CLOCK_GATING; |
| 6140 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6141 | |
| 6142 | if (IS_PINEVIEW(dev)) |
| 6143 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6144 | |
| 6145 | /* IIR "flip pending" means done if this bit is set */ |
| 6146 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6147 | |
| 6148 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6149 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6150 | |
| 6151 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6152 | 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] | 6153 | |
| 6154 | I915_WRITE(MI_ARB_STATE, |
| 6155 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6156 | } |
| 6157 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6158 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6159 | { |
| 6160 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6161 | |
| 6162 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6163 | |
| 6164 | /* interrupts should cause a wake up from C3 */ |
| 6165 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6166 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6167 | |
| 6168 | I915_WRITE(MEM_MODE, |
| 6169 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6170 | } |
| 6171 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6172 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6173 | { |
| 6174 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6175 | |
| 6176 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6177 | |
| 6178 | I915_WRITE(MEM_MODE, |
| 6179 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6180 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6181 | } |
| 6182 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6183 | void intel_init_clock_gating(struct drm_device *dev) |
| 6184 | { |
| 6185 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6186 | |
| 6187 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6188 | } |
| 6189 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6190 | void intel_suspend_hw(struct drm_device *dev) |
| 6191 | { |
| 6192 | if (HAS_PCH_LPT(dev)) |
| 6193 | lpt_suspend_hw(dev); |
| 6194 | } |
| 6195 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6196 | #define for_each_power_well(i, power_well, domain_mask, power_domains) \ |
| 6197 | for (i = 0; \ |
| 6198 | i < (power_domains)->power_well_count && \ |
| 6199 | ((power_well) = &(power_domains)->power_wells[i]); \ |
| 6200 | i++) \ |
| 6201 | if ((power_well)->domains & (domain_mask)) |
| 6202 | |
| 6203 | #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \ |
| 6204 | for (i = (power_domains)->power_well_count - 1; \ |
| 6205 | i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\ |
| 6206 | i--) \ |
| 6207 | if ((power_well)->domains & (domain_mask)) |
| 6208 | |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 6209 | /** |
| 6210 | * We should only use the power well if we explicitly asked the hardware to |
| 6211 | * enable it, so check if it's enabled and also check if we've requested it to |
| 6212 | * be enabled. |
| 6213 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6214 | static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6215 | struct i915_power_well *power_well) |
| 6216 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6217 | return I915_READ(HSW_PWR_WELL_DRIVER) == |
| 6218 | (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED); |
| 6219 | } |
| 6220 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6221 | bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv, |
| 6222 | enum intel_display_power_domain domain) |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6223 | { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6224 | struct i915_power_domains *power_domains; |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6225 | struct i915_power_well *power_well; |
| 6226 | bool is_enabled; |
| 6227 | int i; |
| 6228 | |
| 6229 | if (dev_priv->pm.suspended) |
| 6230 | return false; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6231 | |
| 6232 | power_domains = &dev_priv->power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6233 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6234 | is_enabled = true; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6235 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6236 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 6237 | if (power_well->always_on) |
| 6238 | continue; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6239 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6240 | if (!power_well->hw_enabled) { |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6241 | is_enabled = false; |
| 6242 | break; |
| 6243 | } |
| 6244 | } |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6245 | |
Imre Deak | b8c000d | 2014-06-02 14:21:10 +0300 | [diff] [blame] | 6246 | return is_enabled; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6247 | } |
| 6248 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6249 | bool intel_display_power_enabled(struct drm_i915_private *dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 6250 | enum intel_display_power_domain domain) |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 6251 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6252 | struct i915_power_domains *power_domains; |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6253 | bool ret; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 6254 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6255 | power_domains = &dev_priv->power_domains; |
| 6256 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6257 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6258 | ret = intel_display_power_enabled_unlocked(dev_priv, domain); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6259 | mutex_unlock(&power_domains->lock); |
| 6260 | |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6261 | return ret; |
Paulo Zanoni | 15d199e | 2013-03-22 14:14:13 -0300 | [diff] [blame] | 6262 | } |
| 6263 | |
Imre Deak | 93c73e8 | 2014-02-18 00:02:19 +0200 | [diff] [blame] | 6264 | /* |
| 6265 | * Starting with Haswell, we have a "Power Down Well" that can be turned off |
| 6266 | * when not needed anymore. We have 4 registers that can request the power well |
| 6267 | * to be enabled, and it will only be disabled if none of the registers is |
| 6268 | * requesting it to be enabled. |
| 6269 | */ |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6270 | static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv) |
| 6271 | { |
| 6272 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6273 | |
Paulo Zanoni | f9dcb0d | 2013-12-11 18:50:10 -0200 | [diff] [blame] | 6274 | /* |
| 6275 | * After we re-enable the power well, if we touch VGA register 0x3d5 |
| 6276 | * we'll get unclaimed register interrupts. This stops after we write |
| 6277 | * anything to the VGA MSR register. The vgacon module uses this |
| 6278 | * register all the time, so if we unbind our driver and, as a |
| 6279 | * consequence, bind vgacon, we'll get stuck in an infinite loop at |
| 6280 | * console_unlock(). So make here we touch the VGA MSR register, making |
| 6281 | * sure vgacon can keep working normally without triggering interrupts |
| 6282 | * and error messages. |
| 6283 | */ |
| 6284 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6285 | outb(inb(VGA_MSR_READ), VGA_MSR_WRITE); |
| 6286 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 6287 | |
Satheeshakrishna M | 08524a9f | 2014-04-08 15:46:56 +0530 | [diff] [blame] | 6288 | if (IS_BROADWELL(dev) || (INTEL_INFO(dev)->gen >= 9)) |
Paulo Zanoni | d49bdb0 | 2014-07-04 11:50:31 -0300 | [diff] [blame] | 6289 | gen8_irq_power_well_post_enable(dev_priv); |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6290 | } |
| 6291 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6292 | static void hsw_set_power_well(struct drm_i915_private *dev_priv, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6293 | struct i915_power_well *power_well, bool enable) |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6294 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6295 | bool is_enabled, enable_requested; |
| 6296 | uint32_t tmp; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6297 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6298 | tmp = I915_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6299 | is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED; |
| 6300 | enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6301 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6302 | if (enable) { |
| 6303 | if (!enable_requested) |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6304 | I915_WRITE(HSW_PWR_WELL_DRIVER, |
| 6305 | HSW_PWR_WELL_ENABLE_REQUEST); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6306 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6307 | if (!is_enabled) { |
| 6308 | DRM_DEBUG_KMS("Enabling power well\n"); |
| 6309 | if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) & |
Paulo Zanoni | 6aedd1f | 2013-08-02 16:22:25 -0300 | [diff] [blame] | 6310 | HSW_PWR_WELL_STATE_ENABLED), 20)) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6311 | DRM_ERROR("Timeout enabling power well\n"); |
| 6312 | } |
Ben Widawsky | 596cc11 | 2013-11-11 14:46:28 -0800 | [diff] [blame] | 6313 | |
Paulo Zanoni | d5e8fdc | 2013-12-11 18:50:09 -0200 | [diff] [blame] | 6314 | hsw_power_well_post_enable(dev_priv); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6315 | } else { |
| 6316 | if (enable_requested) { |
| 6317 | I915_WRITE(HSW_PWR_WELL_DRIVER, 0); |
Paulo Zanoni | 9dbd8fe | 2013-07-23 10:48:11 -0300 | [diff] [blame] | 6318 | POSTING_READ(HSW_PWR_WELL_DRIVER); |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6319 | DRM_DEBUG_KMS("Requesting to disable the power well\n"); |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6320 | } |
| 6321 | } |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 6322 | } |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 6323 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6324 | static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6325 | struct i915_power_well *power_well) |
| 6326 | { |
| 6327 | hsw_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6328 | |
| 6329 | /* |
| 6330 | * We're taking over the BIOS, so clear any requests made by it since |
| 6331 | * the driver is in charge now. |
| 6332 | */ |
| 6333 | if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST) |
| 6334 | I915_WRITE(HSW_PWR_WELL_BIOS, 0); |
| 6335 | } |
| 6336 | |
| 6337 | static void hsw_power_well_enable(struct drm_i915_private *dev_priv, |
| 6338 | struct i915_power_well *power_well) |
| 6339 | { |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6340 | hsw_set_power_well(dev_priv, power_well, true); |
| 6341 | } |
| 6342 | |
| 6343 | static void hsw_power_well_disable(struct drm_i915_private *dev_priv, |
| 6344 | struct i915_power_well *power_well) |
| 6345 | { |
| 6346 | hsw_set_power_well(dev_priv, power_well, false); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6347 | } |
| 6348 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6349 | static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv, |
| 6350 | struct i915_power_well *power_well) |
| 6351 | { |
| 6352 | } |
| 6353 | |
| 6354 | static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6355 | struct i915_power_well *power_well) |
| 6356 | { |
| 6357 | return true; |
| 6358 | } |
| 6359 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6360 | static void vlv_set_power_well(struct drm_i915_private *dev_priv, |
| 6361 | struct i915_power_well *power_well, bool enable) |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6362 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 6363 | enum punit_power_well power_well_id = power_well->data; |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6364 | u32 mask; |
| 6365 | u32 state; |
| 6366 | u32 ctrl; |
| 6367 | |
| 6368 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6369 | state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) : |
| 6370 | PUNIT_PWRGT_PWR_GATE(power_well_id); |
| 6371 | |
| 6372 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6373 | |
| 6374 | #define COND \ |
| 6375 | ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state) |
| 6376 | |
| 6377 | if (COND) |
| 6378 | goto out; |
| 6379 | |
| 6380 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL); |
| 6381 | ctrl &= ~mask; |
| 6382 | ctrl |= state; |
| 6383 | vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl); |
| 6384 | |
| 6385 | if (wait_for(COND, 100)) |
| 6386 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 6387 | state, |
| 6388 | vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL)); |
| 6389 | |
| 6390 | #undef COND |
| 6391 | |
| 6392 | out: |
| 6393 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6394 | } |
| 6395 | |
| 6396 | static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6397 | struct i915_power_well *power_well) |
| 6398 | { |
| 6399 | vlv_set_power_well(dev_priv, power_well, power_well->count > 0); |
| 6400 | } |
| 6401 | |
| 6402 | static void vlv_power_well_enable(struct drm_i915_private *dev_priv, |
| 6403 | struct i915_power_well *power_well) |
| 6404 | { |
| 6405 | vlv_set_power_well(dev_priv, power_well, true); |
| 6406 | } |
| 6407 | |
| 6408 | static void vlv_power_well_disable(struct drm_i915_private *dev_priv, |
| 6409 | struct i915_power_well *power_well) |
| 6410 | { |
| 6411 | vlv_set_power_well(dev_priv, power_well, false); |
| 6412 | } |
| 6413 | |
| 6414 | static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6415 | struct i915_power_well *power_well) |
| 6416 | { |
| 6417 | int power_well_id = power_well->data; |
| 6418 | bool enabled = false; |
| 6419 | u32 mask; |
| 6420 | u32 state; |
| 6421 | u32 ctrl; |
| 6422 | |
| 6423 | mask = PUNIT_PWRGT_MASK(power_well_id); |
| 6424 | ctrl = PUNIT_PWRGT_PWR_ON(power_well_id); |
| 6425 | |
| 6426 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6427 | |
| 6428 | state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask; |
| 6429 | /* |
| 6430 | * We only ever set the power-on and power-gate states, anything |
| 6431 | * else is unexpected. |
| 6432 | */ |
| 6433 | WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) && |
| 6434 | state != PUNIT_PWRGT_PWR_GATE(power_well_id)); |
| 6435 | if (state == ctrl) |
| 6436 | enabled = true; |
| 6437 | |
| 6438 | /* |
| 6439 | * A transient state at this point would mean some unexpected party |
| 6440 | * is poking at the power controls too. |
| 6441 | */ |
| 6442 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask; |
| 6443 | WARN_ON(ctrl != state); |
| 6444 | |
| 6445 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6446 | |
| 6447 | return enabled; |
| 6448 | } |
| 6449 | |
| 6450 | static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, |
| 6451 | struct i915_power_well *power_well) |
| 6452 | { |
| 6453 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6454 | |
| 6455 | vlv_set_power_well(dev_priv, power_well, true); |
| 6456 | |
| 6457 | spin_lock_irq(&dev_priv->irq_lock); |
| 6458 | valleyview_enable_display_irqs(dev_priv); |
| 6459 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6460 | |
| 6461 | /* |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6462 | * During driver initialization/resume we can avoid restoring the |
| 6463 | * part of the HW/SW state that will be inited anyway explicitly. |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6464 | */ |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 6465 | if (dev_priv->power_domains.initializing) |
| 6466 | return; |
| 6467 | |
| 6468 | intel_hpd_init(dev_priv->dev); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6469 | |
| 6470 | i915_redisable_vga_power_on(dev_priv->dev); |
| 6471 | } |
| 6472 | |
| 6473 | static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv, |
| 6474 | struct i915_power_well *power_well) |
| 6475 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6476 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D); |
| 6477 | |
| 6478 | spin_lock_irq(&dev_priv->irq_lock); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6479 | valleyview_disable_display_irqs(dev_priv); |
| 6480 | spin_unlock_irq(&dev_priv->irq_lock); |
| 6481 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6482 | vlv_set_power_well(dev_priv, power_well, false); |
Ville Syrjälä | 773538e8 | 2014-09-04 14:54:56 +0300 | [diff] [blame] | 6483 | |
| 6484 | vlv_power_sequencer_reset(dev_priv); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6485 | } |
| 6486 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6487 | static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 6488 | struct i915_power_well *power_well) |
| 6489 | { |
| 6490 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6491 | |
| 6492 | /* |
| 6493 | * Enable the CRI clock source so we can get at the |
| 6494 | * display and the reference clock for VGA |
| 6495 | * hotplug / manual detection. |
| 6496 | */ |
| 6497 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6498 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6499 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 6500 | |
| 6501 | vlv_set_power_well(dev_priv, power_well, true); |
| 6502 | |
| 6503 | /* |
| 6504 | * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx - |
| 6505 | * 6. De-assert cmn_reset/side_reset. Same as VLV X0. |
| 6506 | * a. GUnit 0x2110 bit[0] set to 1 (def 0) |
| 6507 | * b. The other bits such as sfr settings / modesel may all |
| 6508 | * be set to 0. |
| 6509 | * |
| 6510 | * This should only be done on init and resume from S3 with |
| 6511 | * both PLLs disabled, or we risk losing DPIO and PLL |
| 6512 | * synchronization. |
| 6513 | */ |
| 6514 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST); |
| 6515 | } |
| 6516 | |
| 6517 | static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 6518 | struct i915_power_well *power_well) |
| 6519 | { |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6520 | enum pipe pipe; |
| 6521 | |
| 6522 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 6523 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6524 | for_each_pipe(dev_priv, pipe) |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6525 | assert_pll_disabled(dev_priv, pipe); |
| 6526 | |
| 6527 | /* Assert common reset */ |
| 6528 | I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST); |
| 6529 | |
| 6530 | vlv_set_power_well(dev_priv, power_well, false); |
| 6531 | } |
| 6532 | |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6533 | static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv, |
| 6534 | struct i915_power_well *power_well) |
| 6535 | { |
| 6536 | enum dpio_phy phy; |
| 6537 | |
| 6538 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC && |
| 6539 | power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D); |
| 6540 | |
| 6541 | /* |
| 6542 | * Enable the CRI clock source so we can get at the |
| 6543 | * display and the reference clock for VGA |
| 6544 | * hotplug / manual detection. |
| 6545 | */ |
| 6546 | if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
| 6547 | phy = DPIO_PHY0; |
| 6548 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6549 | DPLL_REFA_CLK_ENABLE_VLV); |
| 6550 | I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | |
| 6551 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6552 | } else { |
| 6553 | phy = DPIO_PHY1; |
| 6554 | I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) | |
| 6555 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV); |
| 6556 | } |
| 6557 | udelay(1); /* >10ns for cmnreset, >0ns for sidereset */ |
| 6558 | vlv_set_power_well(dev_priv, power_well, true); |
| 6559 | |
| 6560 | /* Poll for phypwrgood signal */ |
| 6561 | if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1)) |
| 6562 | DRM_ERROR("Display PHY %d is not power up\n", phy); |
| 6563 | |
Ville Syrjälä | efd814b | 2014-06-27 19:52:13 +0300 | [diff] [blame] | 6564 | I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) | |
| 6565 | PHY_COM_LANE_RESET_DEASSERT(phy)); |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv, |
| 6569 | struct i915_power_well *power_well) |
| 6570 | { |
| 6571 | enum dpio_phy phy; |
| 6572 | |
| 6573 | WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC && |
| 6574 | power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D); |
| 6575 | |
| 6576 | if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) { |
| 6577 | phy = DPIO_PHY0; |
| 6578 | assert_pll_disabled(dev_priv, PIPE_A); |
| 6579 | assert_pll_disabled(dev_priv, PIPE_B); |
| 6580 | } else { |
| 6581 | phy = DPIO_PHY1; |
| 6582 | assert_pll_disabled(dev_priv, PIPE_C); |
| 6583 | } |
| 6584 | |
Ville Syrjälä | efd814b | 2014-06-27 19:52:13 +0300 | [diff] [blame] | 6585 | I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) & |
| 6586 | ~PHY_COM_LANE_RESET_DEASSERT(phy)); |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6587 | |
| 6588 | vlv_set_power_well(dev_priv, power_well, false); |
| 6589 | } |
| 6590 | |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 6591 | static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv, |
| 6592 | struct i915_power_well *power_well) |
| 6593 | { |
| 6594 | enum pipe pipe = power_well->data; |
| 6595 | bool enabled; |
| 6596 | u32 state, ctrl; |
| 6597 | |
| 6598 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6599 | |
| 6600 | state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe); |
| 6601 | /* |
| 6602 | * We only ever set the power-on and power-gate states, anything |
| 6603 | * else is unexpected. |
| 6604 | */ |
| 6605 | WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe)); |
| 6606 | enabled = state == DP_SSS_PWR_ON(pipe); |
| 6607 | |
| 6608 | /* |
| 6609 | * A transient state at this point would mean some unexpected party |
| 6610 | * is poking at the power controls too. |
| 6611 | */ |
| 6612 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe); |
| 6613 | WARN_ON(ctrl << 16 != state); |
| 6614 | |
| 6615 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6616 | |
| 6617 | return enabled; |
| 6618 | } |
| 6619 | |
| 6620 | static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv, |
| 6621 | struct i915_power_well *power_well, |
| 6622 | bool enable) |
| 6623 | { |
| 6624 | enum pipe pipe = power_well->data; |
| 6625 | u32 state; |
| 6626 | u32 ctrl; |
| 6627 | |
| 6628 | state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe); |
| 6629 | |
| 6630 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6631 | |
| 6632 | #define COND \ |
| 6633 | ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state) |
| 6634 | |
| 6635 | if (COND) |
| 6636 | goto out; |
| 6637 | |
| 6638 | ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 6639 | ctrl &= ~DP_SSC_MASK(pipe); |
| 6640 | ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe); |
| 6641 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl); |
| 6642 | |
| 6643 | if (wait_for(COND, 100)) |
| 6644 | DRM_ERROR("timout setting power well state %08x (%08x)\n", |
| 6645 | state, |
| 6646 | vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ)); |
| 6647 | |
| 6648 | #undef COND |
| 6649 | |
| 6650 | out: |
| 6651 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6652 | } |
| 6653 | |
| 6654 | static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv, |
| 6655 | struct i915_power_well *power_well) |
| 6656 | { |
| 6657 | chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0); |
| 6658 | } |
| 6659 | |
| 6660 | static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv, |
| 6661 | struct i915_power_well *power_well) |
| 6662 | { |
| 6663 | WARN_ON_ONCE(power_well->data != PIPE_A && |
| 6664 | power_well->data != PIPE_B && |
| 6665 | power_well->data != PIPE_C); |
| 6666 | |
| 6667 | chv_set_pipe_power_well(dev_priv, power_well, true); |
| 6668 | } |
| 6669 | |
| 6670 | static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv, |
| 6671 | struct i915_power_well *power_well) |
| 6672 | { |
| 6673 | WARN_ON_ONCE(power_well->data != PIPE_A && |
| 6674 | power_well->data != PIPE_B && |
| 6675 | power_well->data != PIPE_C); |
| 6676 | |
| 6677 | chv_set_pipe_power_well(dev_priv, power_well, false); |
| 6678 | } |
| 6679 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6680 | static void check_power_well_state(struct drm_i915_private *dev_priv, |
| 6681 | struct i915_power_well *power_well) |
| 6682 | { |
| 6683 | bool enabled = power_well->ops->is_enabled(dev_priv, power_well); |
| 6684 | |
| 6685 | if (power_well->always_on || !i915.disable_power_well) { |
| 6686 | if (!enabled) |
| 6687 | goto mismatch; |
| 6688 | |
| 6689 | return; |
| 6690 | } |
| 6691 | |
| 6692 | if (enabled != (power_well->count > 0)) |
| 6693 | goto mismatch; |
| 6694 | |
| 6695 | return; |
| 6696 | |
| 6697 | mismatch: |
| 6698 | WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n", |
| 6699 | power_well->name, power_well->always_on, enabled, |
| 6700 | power_well->count, i915.disable_power_well); |
| 6701 | } |
| 6702 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6703 | void intel_display_power_get(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6704 | enum intel_display_power_domain domain) |
| 6705 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6706 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6707 | struct i915_power_well *power_well; |
| 6708 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6709 | |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6710 | intel_runtime_pm_get(dev_priv); |
| 6711 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6712 | power_domains = &dev_priv->power_domains; |
| 6713 | |
| 6714 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6715 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6716 | for_each_power_well(i, power_well, BIT(domain), power_domains) { |
| 6717 | if (!power_well->count++) { |
| 6718 | DRM_DEBUG_KMS("enabling %s\n", power_well->name); |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6719 | power_well->ops->enable(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6720 | power_well->hw_enabled = true; |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | check_power_well_state(dev_priv, power_well); |
| 6724 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6725 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6726 | power_domains->domain_use_count[domain]++; |
| 6727 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6728 | mutex_unlock(&power_domains->lock); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6729 | } |
| 6730 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6731 | void intel_display_power_put(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6732 | enum intel_display_power_domain domain) |
| 6733 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6734 | struct i915_power_domains *power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6735 | struct i915_power_well *power_well; |
| 6736 | int i; |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6737 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6738 | power_domains = &dev_priv->power_domains; |
| 6739 | |
| 6740 | mutex_lock(&power_domains->lock); |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6741 | |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6742 | WARN_ON(!power_domains->domain_use_count[domain]); |
| 6743 | power_domains->domain_use_count[domain]--; |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 6744 | |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6745 | for_each_power_well_rev(i, power_well, BIT(domain), power_domains) { |
| 6746 | WARN_ON(!power_well->count); |
| 6747 | |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6748 | if (!--power_well->count && i915.disable_power_well) { |
| 6749 | DRM_DEBUG_KMS("disabling %s\n", power_well->name); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 6750 | power_well->hw_enabled = false; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6751 | power_well->ops->disable(dev_priv, power_well); |
Imre Deak | 25eaa00 | 2014-03-04 19:23:06 +0200 | [diff] [blame] | 6752 | } |
| 6753 | |
| 6754 | check_power_well_state(dev_priv, power_well); |
Imre Deak | 70bf407 | 2014-03-04 19:22:51 +0200 | [diff] [blame] | 6755 | } |
Imre Deak | 1da5158 | 2013-11-25 17:15:35 +0200 | [diff] [blame] | 6756 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6757 | mutex_unlock(&power_domains->lock); |
Paulo Zanoni | 9e6ea71 | 2014-03-07 20:08:06 -0300 | [diff] [blame] | 6758 | |
| 6759 | intel_runtime_pm_put(dev_priv); |
Ville Syrjälä | 6765625 | 2013-09-16 17:38:28 +0300 | [diff] [blame] | 6760 | } |
| 6761 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 6762 | static struct i915_power_domains *hsw_pwr; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6763 | |
| 6764 | /* Display audio driver power well request */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6765 | int i915_request_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6766 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6767 | struct drm_i915_private *dev_priv; |
| 6768 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6769 | if (!hsw_pwr) |
| 6770 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6771 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6772 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6773 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6774 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6775 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6776 | } |
| 6777 | EXPORT_SYMBOL_GPL(i915_request_power_well); |
| 6778 | |
| 6779 | /* Display audio driver power well release */ |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6780 | int i915_release_power_well(void) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6781 | { |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6782 | struct drm_i915_private *dev_priv; |
| 6783 | |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6784 | if (!hsw_pwr) |
| 6785 | return -ENODEV; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6786 | |
Imre Deak | b4ed448 | 2013-10-25 17:36:49 +0300 | [diff] [blame] | 6787 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6788 | power_domains); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 6789 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
Takashi Iwai | 74b0c2d | 2014-06-13 15:14:34 +0200 | [diff] [blame] | 6790 | return 0; |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 6791 | } |
| 6792 | EXPORT_SYMBOL_GPL(i915_release_power_well); |
| 6793 | |
Jani Nikula | c149dcb | 2014-07-04 10:00:37 +0800 | [diff] [blame] | 6794 | /* |
| 6795 | * Private interface for the audio driver to get CDCLK in kHz. |
| 6796 | * |
| 6797 | * Caller must request power well using i915_request_power_well() prior to |
| 6798 | * making the call. |
| 6799 | */ |
| 6800 | int i915_get_cdclk_freq(void) |
| 6801 | { |
| 6802 | struct drm_i915_private *dev_priv; |
| 6803 | |
| 6804 | if (!hsw_pwr) |
| 6805 | return -ENODEV; |
| 6806 | |
| 6807 | dev_priv = container_of(hsw_pwr, struct drm_i915_private, |
| 6808 | power_domains); |
| 6809 | |
| 6810 | return intel_ddi_get_cdclk_freq(dev_priv); |
| 6811 | } |
| 6812 | EXPORT_SYMBOL_GPL(i915_get_cdclk_freq); |
| 6813 | |
| 6814 | |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6815 | #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1) |
| 6816 | |
| 6817 | #define HSW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6818 | BIT(POWER_DOMAIN_PIPE_A) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6819 | BIT(POWER_DOMAIN_TRANSCODER_EDP) | \ |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6820 | BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \ |
| 6821 | BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \ |
| 6822 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6823 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6824 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6825 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6826 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6827 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6828 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 6829 | BIT(POWER_DOMAIN_PLLS) | \ |
Imre Deak | f5938f3 | 2014-03-04 19:22:54 +0200 | [diff] [blame] | 6830 | BIT(POWER_DOMAIN_INIT)) |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6831 | #define HSW_DISPLAY_POWER_DOMAINS ( \ |
| 6832 | (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6833 | BIT(POWER_DOMAIN_INIT)) |
| 6834 | |
| 6835 | #define BDW_ALWAYS_ON_POWER_DOMAINS ( \ |
| 6836 | HSW_ALWAYS_ON_POWER_DOMAINS | \ |
| 6837 | BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER)) |
| 6838 | #define BDW_DISPLAY_POWER_DOMAINS ( \ |
| 6839 | (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \ |
| 6840 | BIT(POWER_DOMAIN_INIT)) |
| 6841 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6842 | #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT) |
| 6843 | #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK |
| 6844 | |
| 6845 | #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 6846 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6847 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6848 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6849 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6850 | BIT(POWER_DOMAIN_PORT_CRT) | \ |
| 6851 | BIT(POWER_DOMAIN_INIT)) |
| 6852 | |
| 6853 | #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \ |
| 6854 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6855 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6856 | BIT(POWER_DOMAIN_INIT)) |
| 6857 | |
| 6858 | #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \ |
| 6859 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6860 | BIT(POWER_DOMAIN_INIT)) |
| 6861 | |
| 6862 | #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \ |
| 6863 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6864 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6865 | BIT(POWER_DOMAIN_INIT)) |
| 6866 | |
| 6867 | #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \ |
| 6868 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6869 | BIT(POWER_DOMAIN_INIT)) |
| 6870 | |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 6871 | #define CHV_PIPE_A_POWER_DOMAINS ( \ |
| 6872 | BIT(POWER_DOMAIN_PIPE_A) | \ |
| 6873 | BIT(POWER_DOMAIN_INIT)) |
| 6874 | |
| 6875 | #define CHV_PIPE_B_POWER_DOMAINS ( \ |
| 6876 | BIT(POWER_DOMAIN_PIPE_B) | \ |
| 6877 | BIT(POWER_DOMAIN_INIT)) |
| 6878 | |
| 6879 | #define CHV_PIPE_C_POWER_DOMAINS ( \ |
| 6880 | BIT(POWER_DOMAIN_PIPE_C) | \ |
| 6881 | BIT(POWER_DOMAIN_INIT)) |
| 6882 | |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6883 | #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \ |
| 6884 | BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \ |
| 6885 | BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \ |
| 6886 | BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \ |
| 6887 | BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \ |
| 6888 | BIT(POWER_DOMAIN_INIT)) |
| 6889 | |
| 6890 | #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \ |
| 6891 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6892 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6893 | BIT(POWER_DOMAIN_INIT)) |
| 6894 | |
Ville Syrjälä | 2ce147f | 2014-06-28 02:04:13 +0300 | [diff] [blame] | 6895 | #define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \ |
| 6896 | BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \ |
| 6897 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6898 | BIT(POWER_DOMAIN_INIT)) |
| 6899 | |
| 6900 | #define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \ |
| 6901 | BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \ |
| 6902 | BIT(POWER_DOMAIN_INIT)) |
| 6903 | |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 6904 | static const struct i915_power_well_ops i9xx_always_on_power_well_ops = { |
| 6905 | .sync_hw = i9xx_always_on_power_well_noop, |
| 6906 | .enable = i9xx_always_on_power_well_noop, |
| 6907 | .disable = i9xx_always_on_power_well_noop, |
| 6908 | .is_enabled = i9xx_always_on_power_well_enabled, |
| 6909 | }; |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6910 | |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 6911 | static const struct i915_power_well_ops chv_pipe_power_well_ops = { |
| 6912 | .sync_hw = chv_pipe_power_well_sync_hw, |
| 6913 | .enable = chv_pipe_power_well_enable, |
| 6914 | .disable = chv_pipe_power_well_disable, |
| 6915 | .is_enabled = chv_pipe_power_well_enabled, |
| 6916 | }; |
| 6917 | |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 6918 | static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = { |
| 6919 | .sync_hw = vlv_power_well_sync_hw, |
| 6920 | .enable = chv_dpio_cmn_power_well_enable, |
| 6921 | .disable = chv_dpio_cmn_power_well_disable, |
| 6922 | .is_enabled = vlv_power_well_enabled, |
| 6923 | }; |
| 6924 | |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6925 | static struct i915_power_well i9xx_always_on_power_well[] = { |
| 6926 | { |
| 6927 | .name = "always-on", |
| 6928 | .always_on = 1, |
| 6929 | .domains = POWER_DOMAIN_MASK, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6930 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 6931 | }, |
| 6932 | }; |
| 6933 | |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6934 | static const struct i915_power_well_ops hsw_power_well_ops = { |
| 6935 | .sync_hw = hsw_power_well_sync_hw, |
| 6936 | .enable = hsw_power_well_enable, |
| 6937 | .disable = hsw_power_well_disable, |
| 6938 | .is_enabled = hsw_power_well_enabled, |
| 6939 | }; |
| 6940 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6941 | static struct i915_power_well hsw_power_wells[] = { |
| 6942 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6943 | .name = "always-on", |
| 6944 | .always_on = 1, |
| 6945 | .domains = HSW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6946 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6947 | }, |
| 6948 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6949 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6950 | .domains = HSW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6951 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6952 | }, |
| 6953 | }; |
| 6954 | |
| 6955 | static struct i915_power_well bdw_power_wells[] = { |
| 6956 | { |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6957 | .name = "always-on", |
| 6958 | .always_on = 1, |
| 6959 | .domains = BDW_ALWAYS_ON_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6960 | .ops = &i9xx_always_on_power_well_ops, |
Imre Deak | 6f3ef5d | 2013-11-25 17:15:30 +0200 | [diff] [blame] | 6961 | }, |
| 6962 | { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6963 | .name = "display", |
Imre Deak | efcad91 | 2014-03-04 19:22:53 +0200 | [diff] [blame] | 6964 | .domains = BDW_DISPLAY_POWER_DOMAINS, |
Imre Deak | c6cb582 | 2014-03-04 19:22:55 +0200 | [diff] [blame] | 6965 | .ops = &hsw_power_well_ops, |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 6966 | }, |
| 6967 | }; |
| 6968 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6969 | static const struct i915_power_well_ops vlv_display_power_well_ops = { |
| 6970 | .sync_hw = vlv_power_well_sync_hw, |
| 6971 | .enable = vlv_display_power_well_enable, |
| 6972 | .disable = vlv_display_power_well_disable, |
| 6973 | .is_enabled = vlv_power_well_enabled, |
| 6974 | }; |
| 6975 | |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 6976 | static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = { |
| 6977 | .sync_hw = vlv_power_well_sync_hw, |
| 6978 | .enable = vlv_dpio_cmn_power_well_enable, |
| 6979 | .disable = vlv_dpio_cmn_power_well_disable, |
| 6980 | .is_enabled = vlv_power_well_enabled, |
| 6981 | }; |
| 6982 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 6983 | static const struct i915_power_well_ops vlv_dpio_power_well_ops = { |
| 6984 | .sync_hw = vlv_power_well_sync_hw, |
| 6985 | .enable = vlv_power_well_enable, |
| 6986 | .disable = vlv_power_well_disable, |
| 6987 | .is_enabled = vlv_power_well_enabled, |
| 6988 | }; |
| 6989 | |
| 6990 | static struct i915_power_well vlv_power_wells[] = { |
| 6991 | { |
| 6992 | .name = "always-on", |
| 6993 | .always_on = 1, |
| 6994 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 6995 | .ops = &i9xx_always_on_power_well_ops, |
| 6996 | }, |
| 6997 | { |
| 6998 | .name = "display", |
| 6999 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 7000 | .data = PUNIT_POWER_WELL_DISP2D, |
| 7001 | .ops = &vlv_display_power_well_ops, |
| 7002 | }, |
| 7003 | { |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 7004 | .name = "dpio-tx-b-01", |
| 7005 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7006 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7007 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7008 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7009 | .ops = &vlv_dpio_power_well_ops, |
| 7010 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 7011 | }, |
| 7012 | { |
| 7013 | .name = "dpio-tx-b-23", |
| 7014 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7015 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7016 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7017 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7018 | .ops = &vlv_dpio_power_well_ops, |
| 7019 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 7020 | }, |
| 7021 | { |
| 7022 | .name = "dpio-tx-c-01", |
| 7023 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7024 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7025 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7026 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7027 | .ops = &vlv_dpio_power_well_ops, |
| 7028 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 7029 | }, |
| 7030 | { |
| 7031 | .name = "dpio-tx-c-23", |
| 7032 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7033 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS | |
| 7034 | VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7035 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7036 | .ops = &vlv_dpio_power_well_ops, |
| 7037 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 7038 | }, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 7039 | { |
| 7040 | .name = "dpio-common", |
| 7041 | .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS, |
| 7042 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
Ville Syrjälä | aa519f2 | 2014-06-13 13:37:55 +0300 | [diff] [blame] | 7043 | .ops = &vlv_dpio_cmn_power_well_ops, |
Jesse Barnes | f099a3c | 2014-05-23 13:16:43 -0700 | [diff] [blame] | 7044 | }, |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 7045 | }; |
| 7046 | |
Ville Syrjälä | 4811ff4 | 2014-06-28 02:04:07 +0300 | [diff] [blame] | 7047 | static struct i915_power_well chv_power_wells[] = { |
| 7048 | { |
| 7049 | .name = "always-on", |
| 7050 | .always_on = 1, |
| 7051 | .domains = VLV_ALWAYS_ON_POWER_DOMAINS, |
| 7052 | .ops = &i9xx_always_on_power_well_ops, |
| 7053 | }, |
Ville Syrjälä | f07057d | 2014-06-28 02:04:10 +0300 | [diff] [blame] | 7054 | #if 0 |
| 7055 | { |
| 7056 | .name = "display", |
| 7057 | .domains = VLV_DISPLAY_POWER_DOMAINS, |
| 7058 | .data = PUNIT_POWER_WELL_DISP2D, |
| 7059 | .ops = &vlv_display_power_well_ops, |
| 7060 | }, |
Ville Syrjälä | 26972b0 | 2014-06-28 02:04:11 +0300 | [diff] [blame] | 7061 | { |
| 7062 | .name = "pipe-a", |
| 7063 | .domains = CHV_PIPE_A_POWER_DOMAINS, |
| 7064 | .data = PIPE_A, |
| 7065 | .ops = &chv_pipe_power_well_ops, |
| 7066 | }, |
| 7067 | { |
| 7068 | .name = "pipe-b", |
| 7069 | .domains = CHV_PIPE_B_POWER_DOMAINS, |
| 7070 | .data = PIPE_B, |
| 7071 | .ops = &chv_pipe_power_well_ops, |
| 7072 | }, |
| 7073 | { |
| 7074 | .name = "pipe-c", |
| 7075 | .domains = CHV_PIPE_C_POWER_DOMAINS, |
| 7076 | .data = PIPE_C, |
| 7077 | .ops = &chv_pipe_power_well_ops, |
| 7078 | }, |
Ville Syrjälä | f07057d | 2014-06-28 02:04:10 +0300 | [diff] [blame] | 7079 | #endif |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 7080 | { |
| 7081 | .name = "dpio-common-bc", |
Ville Syrjälä | 3dd7b974 | 2014-06-27 19:49:57 +0300 | [diff] [blame] | 7082 | /* |
| 7083 | * XXX: cmnreset for one PHY seems to disturb the other. |
| 7084 | * As a workaround keep both powered on at the same |
| 7085 | * time for now. |
| 7086 | */ |
| 7087 | .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS, |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 7088 | .data = PUNIT_POWER_WELL_DPIO_CMN_BC, |
| 7089 | .ops = &chv_dpio_cmn_power_well_ops, |
| 7090 | }, |
| 7091 | { |
| 7092 | .name = "dpio-common-d", |
Ville Syrjälä | 3dd7b974 | 2014-06-27 19:49:57 +0300 | [diff] [blame] | 7093 | /* |
| 7094 | * XXX: cmnreset for one PHY seems to disturb the other. |
| 7095 | * As a workaround keep both powered on at the same |
| 7096 | * time for now. |
| 7097 | */ |
| 7098 | .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS, |
Ville Syrjälä | 5d6f7ea | 2014-06-28 02:04:08 +0300 | [diff] [blame] | 7099 | .data = PUNIT_POWER_WELL_DPIO_CMN_D, |
| 7100 | .ops = &chv_dpio_cmn_power_well_ops, |
| 7101 | }, |
Ville Syrjälä | 8258356 | 2014-06-28 02:04:12 +0300 | [diff] [blame] | 7102 | #if 0 |
| 7103 | { |
| 7104 | .name = "dpio-tx-b-01", |
| 7105 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7106 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS, |
| 7107 | .ops = &vlv_dpio_power_well_ops, |
| 7108 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01, |
| 7109 | }, |
| 7110 | { |
| 7111 | .name = "dpio-tx-b-23", |
| 7112 | .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS | |
| 7113 | VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS, |
| 7114 | .ops = &vlv_dpio_power_well_ops, |
| 7115 | .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23, |
| 7116 | }, |
| 7117 | { |
| 7118 | .name = "dpio-tx-c-01", |
| 7119 | .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7120 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7121 | .ops = &vlv_dpio_power_well_ops, |
| 7122 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01, |
| 7123 | }, |
| 7124 | { |
| 7125 | .name = "dpio-tx-c-23", |
| 7126 | .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS | |
| 7127 | VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS, |
| 7128 | .ops = &vlv_dpio_power_well_ops, |
| 7129 | .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23, |
| 7130 | }, |
Ville Syrjälä | 2ce147f | 2014-06-28 02:04:13 +0300 | [diff] [blame] | 7131 | { |
| 7132 | .name = "dpio-tx-d-01", |
| 7133 | .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS | |
| 7134 | CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS, |
| 7135 | .ops = &vlv_dpio_power_well_ops, |
| 7136 | .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_01, |
| 7137 | }, |
| 7138 | { |
| 7139 | .name = "dpio-tx-d-23", |
| 7140 | .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS | |
| 7141 | CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS, |
| 7142 | .ops = &vlv_dpio_power_well_ops, |
| 7143 | .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_23, |
| 7144 | }, |
Ville Syrjälä | 8258356 | 2014-06-28 02:04:12 +0300 | [diff] [blame] | 7145 | #endif |
Ville Syrjälä | 4811ff4 | 2014-06-28 02:04:07 +0300 | [diff] [blame] | 7146 | }; |
| 7147 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7148 | static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv, |
| 7149 | enum punit_power_well power_well_id) |
| 7150 | { |
| 7151 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 7152 | struct i915_power_well *power_well; |
| 7153 | int i; |
| 7154 | |
| 7155 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
| 7156 | if (power_well->data == power_well_id) |
| 7157 | return power_well; |
| 7158 | } |
| 7159 | |
| 7160 | return NULL; |
| 7161 | } |
| 7162 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7163 | #define set_power_wells(power_domains, __power_wells) ({ \ |
| 7164 | (power_domains)->power_wells = (__power_wells); \ |
| 7165 | (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \ |
| 7166 | }) |
| 7167 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7168 | int intel_power_domains_init(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7169 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7170 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7171 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7172 | mutex_init(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7173 | |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7174 | /* |
| 7175 | * The enabling order will be from lower to higher indexed wells, |
| 7176 | * the disabling order is reversed. |
| 7177 | */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7178 | if (IS_HASWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7179 | set_power_wells(power_domains, hsw_power_wells); |
| 7180 | hsw_pwr = power_domains; |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7181 | } else if (IS_BROADWELL(dev_priv->dev)) { |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7182 | set_power_wells(power_domains, bdw_power_wells); |
| 7183 | hsw_pwr = power_domains; |
Ville Syrjälä | 4811ff4 | 2014-06-28 02:04:07 +0300 | [diff] [blame] | 7184 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 7185 | set_power_wells(power_domains, chv_power_wells); |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 7186 | } else if (IS_VALLEYVIEW(dev_priv->dev)) { |
| 7187 | set_power_wells(power_domains, vlv_power_wells); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7188 | } else { |
Imre Deak | 1c2256d | 2013-11-25 17:15:34 +0200 | [diff] [blame] | 7189 | set_power_wells(power_domains, i9xx_always_on_power_well); |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7190 | } |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7191 | |
| 7192 | return 0; |
| 7193 | } |
| 7194 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7195 | void intel_power_domains_remove(struct drm_i915_private *dev_priv) |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7196 | { |
| 7197 | hsw_pwr = NULL; |
| 7198 | } |
| 7199 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7200 | static void intel_power_domains_resume(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 7201 | { |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7202 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 7203 | struct i915_power_well *power_well; |
Imre Deak | c1ca727 | 2013-11-25 17:15:29 +0200 | [diff] [blame] | 7204 | int i; |
Ville Syrjälä | 9cdb826 | 2013-09-16 17:38:27 +0300 | [diff] [blame] | 7205 | |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7206 | mutex_lock(&power_domains->lock); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 7207 | for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) { |
Imre Deak | a45f4466 | 2014-03-04 19:22:56 +0200 | [diff] [blame] | 7208 | power_well->ops->sync_hw(dev_priv, power_well); |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 7209 | power_well->hw_enabled = power_well->ops->is_enabled(dev_priv, |
| 7210 | power_well); |
| 7211 | } |
Imre Deak | 83c00f5 | 2013-10-25 17:36:47 +0300 | [diff] [blame] | 7212 | mutex_unlock(&power_domains->lock); |
Wang Xingchao | a38911a | 2013-05-30 22:07:11 +0800 | [diff] [blame] | 7213 | } |
| 7214 | |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7215 | static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv) |
| 7216 | { |
| 7217 | struct i915_power_well *cmn = |
| 7218 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC); |
| 7219 | struct i915_power_well *disp2d = |
| 7220 | lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D); |
| 7221 | |
| 7222 | /* nothing to do if common lane is already off */ |
| 7223 | if (!cmn->ops->is_enabled(dev_priv, cmn)) |
| 7224 | return; |
| 7225 | |
| 7226 | /* If the display might be already active skip this */ |
| 7227 | if (disp2d->ops->is_enabled(dev_priv, disp2d) && |
| 7228 | I915_READ(DPIO_CTL) & DPIO_CMNRST) |
| 7229 | return; |
| 7230 | |
| 7231 | DRM_DEBUG_KMS("toggling display PHY side reset\n"); |
| 7232 | |
| 7233 | /* cmnlane needs DPLL registers */ |
| 7234 | disp2d->ops->enable(dev_priv, disp2d); |
| 7235 | |
| 7236 | /* |
| 7237 | * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx: |
| 7238 | * Need to assert and de-assert PHY SB reset by gating the |
| 7239 | * common lane power, then un-gating it. |
| 7240 | * Simply ungating isn't enough to reset the PHY enough to get |
| 7241 | * ports and lanes running. |
| 7242 | */ |
| 7243 | cmn->ops->disable(dev_priv, cmn); |
| 7244 | } |
| 7245 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7246 | void intel_power_domains_init_hw(struct drm_i915_private *dev_priv) |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 7247 | { |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7248 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 7249 | struct i915_power_domains *power_domains = &dev_priv->power_domains; |
| 7250 | |
| 7251 | power_domains->initializing = true; |
Ville Syrjälä | d2011dc | 2014-06-13 13:37:56 +0300 | [diff] [blame] | 7252 | |
| 7253 | if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
| 7254 | mutex_lock(&power_domains->lock); |
| 7255 | vlv_cmnlane_wa(dev_priv); |
| 7256 | mutex_unlock(&power_domains->lock); |
| 7257 | } |
| 7258 | |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 7259 | /* For now, we need the power well to be always enabled. */ |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7260 | intel_display_set_init_power(dev_priv, true); |
| 7261 | intel_power_domains_resume(dev_priv); |
Imre Deak | 0d116a2 | 2014-04-25 13:19:05 +0300 | [diff] [blame] | 7262 | power_domains->initializing = false; |
Eugeni Dodonov | d0d3e51 | 2012-05-09 15:37:16 -0300 | [diff] [blame] | 7263 | } |
| 7264 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7265 | void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv) |
| 7266 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 7267 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7268 | } |
| 7269 | |
| 7270 | void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv) |
| 7271 | { |
Paulo Zanoni | d361ae2 | 2014-03-07 20:08:12 -0300 | [diff] [blame] | 7272 | intel_runtime_pm_put(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7273 | } |
| 7274 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7275 | void intel_runtime_pm_get(struct drm_i915_private *dev_priv) |
| 7276 | { |
| 7277 | struct drm_device *dev = dev_priv->dev; |
| 7278 | struct device *device = &dev->pdev->dev; |
| 7279 | |
| 7280 | if (!HAS_RUNTIME_PM(dev)) |
| 7281 | return; |
| 7282 | |
| 7283 | pm_runtime_get_sync(device); |
| 7284 | WARN(dev_priv->pm.suspended, "Device still suspended.\n"); |
| 7285 | } |
| 7286 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 7287 | void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv) |
| 7288 | { |
| 7289 | struct drm_device *dev = dev_priv->dev; |
| 7290 | struct device *device = &dev->pdev->dev; |
| 7291 | |
| 7292 | if (!HAS_RUNTIME_PM(dev)) |
| 7293 | return; |
| 7294 | |
| 7295 | WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n"); |
| 7296 | pm_runtime_get_noresume(device); |
| 7297 | } |
| 7298 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7299 | void intel_runtime_pm_put(struct drm_i915_private *dev_priv) |
| 7300 | { |
| 7301 | struct drm_device *dev = dev_priv->dev; |
| 7302 | struct device *device = &dev->pdev->dev; |
| 7303 | |
| 7304 | if (!HAS_RUNTIME_PM(dev)) |
| 7305 | return; |
| 7306 | |
| 7307 | pm_runtime_mark_last_busy(device); |
| 7308 | pm_runtime_put_autosuspend(device); |
| 7309 | } |
| 7310 | |
| 7311 | void intel_init_runtime_pm(struct drm_i915_private *dev_priv) |
| 7312 | { |
| 7313 | struct drm_device *dev = dev_priv->dev; |
| 7314 | struct device *device = &dev->pdev->dev; |
| 7315 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7316 | if (!HAS_RUNTIME_PM(dev)) |
| 7317 | return; |
| 7318 | |
| 7319 | pm_runtime_set_active(device); |
| 7320 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 7321 | /* |
| 7322 | * RPM depends on RC6 to save restore the GT HW context, so make RC6 a |
| 7323 | * requirement. |
| 7324 | */ |
| 7325 | if (!intel_enable_rc6(dev)) { |
| 7326 | DRM_INFO("RC6 disabled, disabling runtime PM support\n"); |
| 7327 | return; |
| 7328 | } |
| 7329 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7330 | pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */ |
| 7331 | pm_runtime_mark_last_busy(device); |
| 7332 | pm_runtime_use_autosuspend(device); |
Paulo Zanoni | ba0239e | 2014-03-07 20:08:07 -0300 | [diff] [blame] | 7333 | |
| 7334 | pm_runtime_put_autosuspend(device); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7335 | } |
| 7336 | |
| 7337 | void intel_fini_runtime_pm(struct drm_i915_private *dev_priv) |
| 7338 | { |
| 7339 | struct drm_device *dev = dev_priv->dev; |
| 7340 | struct device *device = &dev->pdev->dev; |
| 7341 | |
| 7342 | if (!HAS_RUNTIME_PM(dev)) |
| 7343 | return; |
| 7344 | |
Imre Deak | aeab0b5 | 2014-04-14 20:24:36 +0300 | [diff] [blame] | 7345 | if (!intel_enable_rc6(dev)) |
| 7346 | return; |
| 7347 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 7348 | /* Make sure we're not suspended first. */ |
| 7349 | pm_runtime_get_sync(device); |
| 7350 | pm_runtime_disable(device); |
| 7351 | } |
| 7352 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7353 | /* Set up chip specific power management-related functions */ |
| 7354 | void intel_init_pm(struct drm_device *dev) |
| 7355 | { |
| 7356 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7357 | |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 7358 | if (HAS_FBC(dev)) { |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 7359 | if (INTEL_INFO(dev)->gen >= 7) { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7360 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 7361 | dev_priv->display.enable_fbc = gen7_enable_fbc; |
| 7362 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 7363 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 7364 | dev_priv->display.fbc_enabled = ironlake_fbc_enabled; |
| 7365 | dev_priv->display.enable_fbc = ironlake_enable_fbc; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7366 | dev_priv->display.disable_fbc = ironlake_disable_fbc; |
| 7367 | } else if (IS_GM45(dev)) { |
| 7368 | dev_priv->display.fbc_enabled = g4x_fbc_enabled; |
| 7369 | dev_priv->display.enable_fbc = g4x_enable_fbc; |
| 7370 | dev_priv->display.disable_fbc = g4x_disable_fbc; |
Ville Syrjälä | 4004546 | 2013-11-28 17:29:59 +0200 | [diff] [blame] | 7371 | } else { |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7372 | dev_priv->display.fbc_enabled = i8xx_fbc_enabled; |
| 7373 | dev_priv->display.enable_fbc = i8xx_enable_fbc; |
| 7374 | dev_priv->display.disable_fbc = i8xx_disable_fbc; |
Ville Syrjälä | 993495a | 2013-12-12 17:27:40 +0200 | [diff] [blame] | 7375 | |
| 7376 | /* This value was pulled out of someone's hat */ |
| 7377 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7378 | } |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7379 | } |
| 7380 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 7381 | /* For cxsr */ |
| 7382 | if (IS_PINEVIEW(dev)) |
| 7383 | i915_pineview_get_mem_freq(dev); |
| 7384 | else if (IS_GEN5(dev)) |
| 7385 | i915_ironlake_get_mem_freq(dev); |
| 7386 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7387 | /* For FIFO watermark updates */ |
| 7388 | if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 7389 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 7390 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7391 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 7392 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 7393 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 7394 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 7395 | dev_priv->display.update_wm = ilk_update_wm; |
| 7396 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 7397 | } else { |
| 7398 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 7399 | "Disable CxSR\n"); |
| 7400 | } |
| 7401 | |
| 7402 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7403 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7404 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7405 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7406 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7407 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7408 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7409 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 7410 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 7411 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 7412 | else if (INTEL_INFO(dev)->gen == 9) |
| 7413 | dev_priv->display.init_clock_gating = gen9_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7414 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 7415 | dev_priv->display.update_wm = cherryview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 7416 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7417 | dev_priv->display.init_clock_gating = |
| 7418 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7419 | } else if (IS_VALLEYVIEW(dev)) { |
| 7420 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 7421 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7422 | dev_priv->display.init_clock_gating = |
| 7423 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7424 | } else if (IS_PINEVIEW(dev)) { |
| 7425 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 7426 | dev_priv->is_ddr3, |
| 7427 | dev_priv->fsb_freq, |
| 7428 | dev_priv->mem_freq)) { |
| 7429 | DRM_INFO("failed to find known CxSR latency " |
| 7430 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 7431 | "disabling CxSR\n", |
| 7432 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 7433 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 7434 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 7435 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7436 | dev_priv->display.update_wm = NULL; |
| 7437 | } else |
| 7438 | dev_priv->display.update_wm = pineview_update_wm; |
| 7439 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 7440 | } else if (IS_G4X(dev)) { |
| 7441 | dev_priv->display.update_wm = g4x_update_wm; |
| 7442 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 7443 | } else if (IS_GEN4(dev)) { |
| 7444 | dev_priv->display.update_wm = i965_update_wm; |
| 7445 | if (IS_CRESTLINE(dev)) |
| 7446 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 7447 | else if (IS_BROADWATER(dev)) |
| 7448 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 7449 | } else if (IS_GEN3(dev)) { |
| 7450 | dev_priv->display.update_wm = i9xx_update_wm; |
| 7451 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 7452 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7453 | } else if (IS_GEN2(dev)) { |
| 7454 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 7455 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7456 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7457 | } else { |
| 7458 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7459 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 7460 | } |
| 7461 | |
| 7462 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 7463 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 7464 | else |
| 7465 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 7466 | } else { |
| 7467 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 7468 | } |
| 7469 | } |
| 7470 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7471 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u8 mbox, u32 *val) |
| 7472 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7473 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7474 | |
| 7475 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 7476 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 7477 | return -EAGAIN; |
| 7478 | } |
| 7479 | |
| 7480 | I915_WRITE(GEN6_PCODE_DATA, *val); |
| 7481 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 7482 | |
| 7483 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 7484 | 500)) { |
| 7485 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 7486 | return -ETIMEDOUT; |
| 7487 | } |
| 7488 | |
| 7489 | *val = I915_READ(GEN6_PCODE_DATA); |
| 7490 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 7491 | |
| 7492 | return 0; |
| 7493 | } |
| 7494 | |
| 7495 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u8 mbox, u32 val) |
| 7496 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 7497 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 7498 | |
| 7499 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 7500 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 7501 | return -EAGAIN; |
| 7502 | } |
| 7503 | |
| 7504 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 7505 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 7506 | |
| 7507 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 7508 | 500)) { |
| 7509 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 7510 | return -ETIMEDOUT; |
| 7511 | } |
| 7512 | |
| 7513 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 7514 | |
| 7515 | return 0; |
| 7516 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 7517 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7518 | 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] | 7519 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7520 | int div; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7521 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7522 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7523 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7524 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7525 | div = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7526 | break; |
| 7527 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7528 | div = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7529 | break; |
| 7530 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7531 | div = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7532 | break; |
| 7533 | default: |
| 7534 | return -1; |
| 7535 | } |
| 7536 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7537 | 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] | 7538 | } |
| 7539 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7540 | 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] | 7541 | { |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7542 | int mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7543 | |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7544 | /* 4 x czclk */ |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7545 | switch (dev_priv->mem_freq) { |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7546 | case 800: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7547 | mul = 10; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7548 | break; |
| 7549 | case 1066: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7550 | mul = 12; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7551 | break; |
| 7552 | case 1333: |
Ville Syrjälä | 07ab118 | 2013-11-05 22:42:28 +0200 | [diff] [blame] | 7553 | mul = 16; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 7554 | break; |
| 7555 | default: |
| 7556 | return -1; |
| 7557 | } |
| 7558 | |
Ville Syrjälä | 2ec3815 | 2013-11-05 22:42:29 +0200 | [diff] [blame] | 7559 | 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] | 7560 | } |
| 7561 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7562 | 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] | 7563 | { |
| 7564 | int div, freq; |
| 7565 | |
| 7566 | switch (dev_priv->rps.cz_freq) { |
| 7567 | case 200: |
| 7568 | div = 5; |
| 7569 | break; |
| 7570 | case 267: |
| 7571 | div = 6; |
| 7572 | break; |
| 7573 | case 320: |
| 7574 | case 333: |
| 7575 | case 400: |
| 7576 | div = 8; |
| 7577 | break; |
| 7578 | default: |
| 7579 | return -1; |
| 7580 | } |
| 7581 | |
| 7582 | freq = (DIV_ROUND_CLOSEST((dev_priv->rps.cz_freq * val), 2 * div) / 2); |
| 7583 | |
| 7584 | return freq; |
| 7585 | } |
| 7586 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 7587 | 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] | 7588 | { |
| 7589 | int mul, opcode; |
| 7590 | |
| 7591 | switch (dev_priv->rps.cz_freq) { |
| 7592 | case 200: |
| 7593 | mul = 5; |
| 7594 | break; |
| 7595 | case 267: |
| 7596 | mul = 6; |
| 7597 | break; |
| 7598 | case 320: |
| 7599 | case 333: |
| 7600 | case 400: |
| 7601 | mul = 8; |
| 7602 | break; |
| 7603 | default: |
| 7604 | return -1; |
| 7605 | } |
| 7606 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 7607 | /* CHV needs even values */ |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 7608 | opcode = (DIV_ROUND_CLOSEST((val * 2 * mul), dev_priv->rps.cz_freq) * 2); |
| 7609 | |
| 7610 | return opcode; |
| 7611 | } |
| 7612 | |
| 7613 | int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 7614 | { |
| 7615 | int ret = -1; |
| 7616 | |
| 7617 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7618 | ret = chv_gpu_freq(dev_priv, val); |
| 7619 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7620 | ret = byt_gpu_freq(dev_priv, val); |
| 7621 | |
| 7622 | return ret; |
| 7623 | } |
| 7624 | |
| 7625 | int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 7626 | { |
| 7627 | int ret = -1; |
| 7628 | |
| 7629 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 7630 | ret = chv_freq_opcode(dev_priv, val); |
| 7631 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 7632 | ret = byt_freq_opcode(dev_priv, val); |
| 7633 | |
| 7634 | return ret; |
| 7635 | } |
| 7636 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7637 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7638 | { |
| 7639 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7640 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 7641 | mutex_init(&dev_priv->rps.hw_lock); |
| 7642 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7643 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 7644 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 7645 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 7646 | dev_priv->pm.suspended = false; |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 7647 | dev_priv->pm._irqs_disabled = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 7648 | } |