Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 28 | #include <linux/cpufreq.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 31 | #include "../../../platform/x86/intel_ips.h" |
| 32 | #include <linux/module.h> |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 33 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 34 | /** |
| 35 | * RC6 is a special power stage which allows the GPU to enter an very |
| 36 | * low-voltage mode when idle, using down to 0V while at this stage. This |
| 37 | * stage is entered automatically when the GPU is idle when RC6 support is |
| 38 | * enabled, and as soon as new workload arises GPU wakes up automatically as well. |
| 39 | * |
| 40 | * There are different RC6 modes available in Intel GPU, which differentiate |
| 41 | * among each other with the latency required to enter and leave RC6 and |
| 42 | * voltage consumed by the GPU in different states. |
| 43 | * |
| 44 | * The combination of the following flags define which states GPU is allowed |
| 45 | * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and |
| 46 | * RC6pp is deepest RC6. Their support by hardware varies according to the |
| 47 | * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one |
| 48 | * which brings the most power savings; deeper states save more power, but |
| 49 | * require higher latency to switch to and wake up. |
| 50 | */ |
| 51 | #define INTEL_RC6_ENABLE (1<<0) |
| 52 | #define INTEL_RC6p_ENABLE (1<<1) |
| 53 | #define INTEL_RC6pp_ENABLE (1<<2) |
| 54 | |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 55 | static void gen9_init_clock_gating(struct drm_device *dev) |
| 56 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 57 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 58 | |
Damien Lespiau | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 59 | /* WaEnableLbsSlaRetryTimerDecrement:skl */ |
| 60 | I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) | |
| 61 | GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); |
| 62 | } |
Damien Lespiau | 91e41d1 | 2014-03-26 17:42:50 +0000 | [diff] [blame] | 63 | |
Damien Lespiau | 45db219 | 2015-02-09 19:33:09 +0000 | [diff] [blame] | 64 | static void skl_init_clock_gating(struct drm_device *dev) |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 65 | { |
Damien Lespiau | acd5c34 | 2014-03-26 16:55:46 +0000 | [diff] [blame] | 66 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 3ca5da4 | 2014-03-26 18:18:01 +0000 | [diff] [blame] | 67 | |
Damien Lespiau | 77719d2 | 2015-02-09 19:33:13 +0000 | [diff] [blame] | 68 | gen9_init_clock_gating(dev); |
| 69 | |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 70 | if (INTEL_REVID(dev) == SKL_REVID_A0) { |
| 71 | /* |
| 72 | * WaDisableSDEUnitClockGating:skl |
Damien Lespiau | 9253c2e | 2015-02-09 19:33:10 +0000 | [diff] [blame] | 73 | * WaSetGAPSunitClckGateDisable:skl |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 74 | */ |
| 75 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
Damien Lespiau | 9253c2e | 2015-02-09 19:33:10 +0000 | [diff] [blame] | 76 | GEN8_GAPSUNIT_CLOCK_GATE_DISABLE | |
Hoath, Nicholas | 3dcd020 | 2015-02-05 10:47:21 +0000 | [diff] [blame] | 77 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 78 | } |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 79 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 80 | if (INTEL_REVID(dev) <= SKL_REVID_D0) { |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 81 | /* WaDisableHDCInvalidation:skl */ |
| 82 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | |
| 83 | BDW_DISABLE_HDC_INVALIDATION); |
| 84 | |
Damien Lespiau | 2caa3b2 | 2015-02-09 19:33:20 +0000 | [diff] [blame] | 85 | /* WaDisableChickenBitTSGBarrierAckForFFSliceCS:skl */ |
| 86 | I915_WRITE(FF_SLICE_CS_CHICKEN2, |
| 87 | I915_READ(FF_SLICE_CS_CHICKEN2) | |
| 88 | GEN9_TSG_BARRIER_ACK_DISABLE); |
| 89 | } |
Damien Lespiau | 81e231a | 2015-02-09 19:33:19 +0000 | [diff] [blame] | 90 | |
Damien Lespiau | 8bc0ccf | 2015-02-09 19:33:18 +0000 | [diff] [blame] | 91 | if (INTEL_REVID(dev) <= SKL_REVID_E0) |
| 92 | /* WaDisableLSQCROPERFforOCL:skl */ |
| 93 | I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | |
| 94 | GEN8_LQSC_RO_PERF_DIS); |
Damien Lespiau | da2078c | 2013-02-13 15:27:27 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame^] | 97 | static void bxt_init_clock_gating(struct drm_device *dev) |
| 98 | { |
| 99 | gen9_init_clock_gating(dev); |
| 100 | } |
| 101 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 102 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 103 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 104 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 105 | u32 tmp; |
| 106 | |
| 107 | tmp = I915_READ(CLKCFG); |
| 108 | |
| 109 | switch (tmp & CLKCFG_FSB_MASK) { |
| 110 | case CLKCFG_FSB_533: |
| 111 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 112 | break; |
| 113 | case CLKCFG_FSB_800: |
| 114 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 115 | break; |
| 116 | case CLKCFG_FSB_667: |
| 117 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 118 | break; |
| 119 | case CLKCFG_FSB_400: |
| 120 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | switch (tmp & CLKCFG_MEM_MASK) { |
| 125 | case CLKCFG_MEM_533: |
| 126 | dev_priv->mem_freq = 533; |
| 127 | break; |
| 128 | case CLKCFG_MEM_667: |
| 129 | dev_priv->mem_freq = 667; |
| 130 | break; |
| 131 | case CLKCFG_MEM_800: |
| 132 | dev_priv->mem_freq = 800; |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | /* detect pineview DDR3 setting */ |
| 137 | tmp = I915_READ(CSHRDDR3CTL); |
| 138 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 139 | } |
| 140 | |
| 141 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 142 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 143 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 144 | u16 ddrpll, csipll; |
| 145 | |
| 146 | ddrpll = I915_READ16(DDRMPLL1); |
| 147 | csipll = I915_READ16(CSIPLL0); |
| 148 | |
| 149 | switch (ddrpll & 0xff) { |
| 150 | case 0xc: |
| 151 | dev_priv->mem_freq = 800; |
| 152 | break; |
| 153 | case 0x10: |
| 154 | dev_priv->mem_freq = 1066; |
| 155 | break; |
| 156 | case 0x14: |
| 157 | dev_priv->mem_freq = 1333; |
| 158 | break; |
| 159 | case 0x18: |
| 160 | dev_priv->mem_freq = 1600; |
| 161 | break; |
| 162 | default: |
| 163 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 164 | ddrpll & 0xff); |
| 165 | dev_priv->mem_freq = 0; |
| 166 | break; |
| 167 | } |
| 168 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 169 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 170 | |
| 171 | switch (csipll & 0x3ff) { |
| 172 | case 0x00c: |
| 173 | dev_priv->fsb_freq = 3200; |
| 174 | break; |
| 175 | case 0x00e: |
| 176 | dev_priv->fsb_freq = 3733; |
| 177 | break; |
| 178 | case 0x010: |
| 179 | dev_priv->fsb_freq = 4266; |
| 180 | break; |
| 181 | case 0x012: |
| 182 | dev_priv->fsb_freq = 4800; |
| 183 | break; |
| 184 | case 0x014: |
| 185 | dev_priv->fsb_freq = 5333; |
| 186 | break; |
| 187 | case 0x016: |
| 188 | dev_priv->fsb_freq = 5866; |
| 189 | break; |
| 190 | case 0x018: |
| 191 | dev_priv->fsb_freq = 6400; |
| 192 | break; |
| 193 | default: |
| 194 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 195 | csipll & 0x3ff); |
| 196 | dev_priv->fsb_freq = 0; |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 201 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 202 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 203 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 204 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 205 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 209 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 210 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 211 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 212 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 213 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 214 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 215 | |
| 216 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 217 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 218 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 219 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 220 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 221 | |
| 222 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 223 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 224 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 225 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 226 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 227 | |
| 228 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 229 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 230 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 231 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 232 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 233 | |
| 234 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 235 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 236 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 237 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 238 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 239 | |
| 240 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 241 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 242 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 243 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 244 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 245 | }; |
| 246 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 247 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 248 | int is_ddr3, |
| 249 | int fsb, |
| 250 | int mem) |
| 251 | { |
| 252 | const struct cxsr_latency *latency; |
| 253 | int i; |
| 254 | |
| 255 | if (fsb == 0 || mem == 0) |
| 256 | return NULL; |
| 257 | |
| 258 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 259 | latency = &cxsr_latency_table[i]; |
| 260 | if (is_desktop == latency->is_desktop && |
| 261 | is_ddr3 == latency->is_ddr3 && |
| 262 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 263 | return latency; |
| 264 | } |
| 265 | |
| 266 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 267 | |
| 268 | return NULL; |
| 269 | } |
| 270 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 271 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 272 | { |
| 273 | u32 val; |
| 274 | |
| 275 | mutex_lock(&dev_priv->rps.hw_lock); |
| 276 | |
| 277 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 278 | if (enable) |
| 279 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 280 | else |
| 281 | val |= FORCE_DDR_HIGH_FREQ; |
| 282 | val &= ~FORCE_DDR_LOW_FREQ; |
| 283 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 284 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 285 | |
| 286 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 287 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 288 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 289 | |
| 290 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 291 | } |
| 292 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 293 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 294 | { |
| 295 | u32 val; |
| 296 | |
| 297 | mutex_lock(&dev_priv->rps.hw_lock); |
| 298 | |
| 299 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 300 | if (enable) |
| 301 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 302 | else |
| 303 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 304 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 305 | |
| 306 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 307 | } |
| 308 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 309 | #define FW_WM(value, plane) \ |
| 310 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 311 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 312 | 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] | 313 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 314 | struct drm_device *dev = dev_priv->dev; |
| 315 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 316 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 317 | if (IS_VALLEYVIEW(dev)) { |
| 318 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 319 | if (IS_CHERRYVIEW(dev)) |
| 320 | chv_set_memory_pm5(dev_priv, enable); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 321 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 322 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 323 | } else if (IS_PINEVIEW(dev)) { |
| 324 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 325 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 326 | I915_WRITE(DSPFW3, val); |
| 327 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 328 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 329 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 330 | I915_WRITE(FW_BLC_SELF, val); |
| 331 | } else if (IS_I915GM(dev)) { |
| 332 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 333 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 334 | I915_WRITE(INSTPM, val); |
| 335 | } else { |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 340 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 341 | } |
| 342 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 343 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 344 | /* |
| 345 | * Latency for FIFO fetches is dependent on several factors: |
| 346 | * - memory configuration (speed, channels) |
| 347 | * - chipset |
| 348 | * - current MCH state |
| 349 | * It can be fairly high in some situations, so here we assume a fairly |
| 350 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 351 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 352 | * and power consumption (set it too low to save power and we might see |
| 353 | * FIFO underruns and display "flicker"). |
| 354 | * |
| 355 | * A value of 5us seems to be a good balance; safe for very low end |
| 356 | * platforms but not overly aggressive on lower latency configs. |
| 357 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 358 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 359 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 360 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 361 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 362 | |
| 363 | static int vlv_get_fifo_size(struct drm_device *dev, |
| 364 | enum pipe pipe, int plane) |
| 365 | { |
| 366 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 367 | int sprite0_start, sprite1_start, size; |
| 368 | |
| 369 | switch (pipe) { |
| 370 | uint32_t dsparb, dsparb2, dsparb3; |
| 371 | case PIPE_A: |
| 372 | dsparb = I915_READ(DSPARB); |
| 373 | dsparb2 = I915_READ(DSPARB2); |
| 374 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 375 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 376 | break; |
| 377 | case PIPE_B: |
| 378 | dsparb = I915_READ(DSPARB); |
| 379 | dsparb2 = I915_READ(DSPARB2); |
| 380 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 381 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 382 | break; |
| 383 | case PIPE_C: |
| 384 | dsparb2 = I915_READ(DSPARB2); |
| 385 | dsparb3 = I915_READ(DSPARB3); |
| 386 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 387 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 388 | break; |
| 389 | default: |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | switch (plane) { |
| 394 | case 0: |
| 395 | size = sprite0_start; |
| 396 | break; |
| 397 | case 1: |
| 398 | size = sprite1_start - sprite0_start; |
| 399 | break; |
| 400 | case 2: |
| 401 | size = 512 - 1 - sprite1_start; |
| 402 | break; |
| 403 | default: |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | DRM_DEBUG_KMS("Pipe %c %s %c FIFO size: %d\n", |
| 408 | pipe_name(pipe), plane == 0 ? "primary" : "sprite", |
| 409 | plane == 0 ? plane_name(pipe) : sprite_name(pipe, plane - 1), |
| 410 | size); |
| 411 | |
| 412 | return size; |
| 413 | } |
| 414 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 415 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 416 | { |
| 417 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 418 | uint32_t dsparb = I915_READ(DSPARB); |
| 419 | int size; |
| 420 | |
| 421 | size = dsparb & 0x7f; |
| 422 | if (plane) |
| 423 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 424 | |
| 425 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 426 | plane ? "B" : "A", size); |
| 427 | |
| 428 | return size; |
| 429 | } |
| 430 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 431 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 432 | { |
| 433 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 434 | uint32_t dsparb = I915_READ(DSPARB); |
| 435 | int size; |
| 436 | |
| 437 | size = dsparb & 0x1ff; |
| 438 | if (plane) |
| 439 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 440 | size >>= 1; /* Convert to cachelines */ |
| 441 | |
| 442 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 443 | plane ? "B" : "A", size); |
| 444 | |
| 445 | return size; |
| 446 | } |
| 447 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 448 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 449 | { |
| 450 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 451 | uint32_t dsparb = I915_READ(DSPARB); |
| 452 | int size; |
| 453 | |
| 454 | size = dsparb & 0x7f; |
| 455 | size >>= 2; /* Convert to cachelines */ |
| 456 | |
| 457 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 458 | plane ? "B" : "A", |
| 459 | size); |
| 460 | |
| 461 | return size; |
| 462 | } |
| 463 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 464 | /* Pineview has different values for various configs */ |
| 465 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 466 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 467 | .max_wm = PINEVIEW_MAX_WM, |
| 468 | .default_wm = PINEVIEW_DFT_WM, |
| 469 | .guard_size = PINEVIEW_GUARD_WM, |
| 470 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 471 | }; |
| 472 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 473 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 474 | .max_wm = PINEVIEW_MAX_WM, |
| 475 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 476 | .guard_size = PINEVIEW_GUARD_WM, |
| 477 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 478 | }; |
| 479 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 480 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 481 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 482 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 483 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 484 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 485 | }; |
| 486 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 487 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 488 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 489 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 490 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 491 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 492 | }; |
| 493 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 494 | .fifo_size = G4X_FIFO_SIZE, |
| 495 | .max_wm = G4X_MAX_WM, |
| 496 | .default_wm = G4X_MAX_WM, |
| 497 | .guard_size = 2, |
| 498 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 499 | }; |
| 500 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 501 | .fifo_size = I965_CURSOR_FIFO, |
| 502 | .max_wm = I965_CURSOR_MAX_WM, |
| 503 | .default_wm = I965_CURSOR_DFT_WM, |
| 504 | .guard_size = 2, |
| 505 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 506 | }; |
| 507 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 508 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 509 | .max_wm = VALLEYVIEW_MAX_WM, |
| 510 | .default_wm = VALLEYVIEW_MAX_WM, |
| 511 | .guard_size = 2, |
| 512 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 513 | }; |
| 514 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 515 | .fifo_size = I965_CURSOR_FIFO, |
| 516 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 517 | .default_wm = I965_CURSOR_DFT_WM, |
| 518 | .guard_size = 2, |
| 519 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 520 | }; |
| 521 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 522 | .fifo_size = I965_CURSOR_FIFO, |
| 523 | .max_wm = I965_CURSOR_MAX_WM, |
| 524 | .default_wm = I965_CURSOR_DFT_WM, |
| 525 | .guard_size = 2, |
| 526 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 527 | }; |
| 528 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 529 | .fifo_size = I945_FIFO_SIZE, |
| 530 | .max_wm = I915_MAX_WM, |
| 531 | .default_wm = 1, |
| 532 | .guard_size = 2, |
| 533 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 534 | }; |
| 535 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 536 | .fifo_size = I915_FIFO_SIZE, |
| 537 | .max_wm = I915_MAX_WM, |
| 538 | .default_wm = 1, |
| 539 | .guard_size = 2, |
| 540 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 541 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 542 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 543 | .fifo_size = I855GM_FIFO_SIZE, |
| 544 | .max_wm = I915_MAX_WM, |
| 545 | .default_wm = 1, |
| 546 | .guard_size = 2, |
| 547 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 548 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 549 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 550 | .fifo_size = I855GM_FIFO_SIZE, |
| 551 | .max_wm = I915_MAX_WM/2, |
| 552 | .default_wm = 1, |
| 553 | .guard_size = 2, |
| 554 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 555 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 556 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 557 | .fifo_size = I830_FIFO_SIZE, |
| 558 | .max_wm = I915_MAX_WM, |
| 559 | .default_wm = 1, |
| 560 | .guard_size = 2, |
| 561 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 562 | }; |
| 563 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 564 | /** |
| 565 | * intel_calculate_wm - calculate watermark level |
| 566 | * @clock_in_khz: pixel clock |
| 567 | * @wm: chip FIFO params |
| 568 | * @pixel_size: display pixel size |
| 569 | * @latency_ns: memory latency for the platform |
| 570 | * |
| 571 | * Calculate the watermark level (the level at which the display plane will |
| 572 | * start fetching from memory again). Each chip has a different display |
| 573 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 574 | * in the correct intel_watermark_params structure. |
| 575 | * |
| 576 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 577 | * on the pixel size. When it reaches the watermark level, it'll start |
| 578 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 579 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 580 | * will occur, and a display engine hang could result. |
| 581 | */ |
| 582 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 583 | const struct intel_watermark_params *wm, |
| 584 | int fifo_size, |
| 585 | int pixel_size, |
| 586 | unsigned long latency_ns) |
| 587 | { |
| 588 | long entries_required, wm_size; |
| 589 | |
| 590 | /* |
| 591 | * Note: we need to make sure we don't overflow for various clock & |
| 592 | * latency values. |
| 593 | * clocks go from a few thousand to several hundred thousand. |
| 594 | * latency is usually a few thousand |
| 595 | */ |
| 596 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 597 | 1000; |
| 598 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 599 | |
| 600 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 601 | |
| 602 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 603 | |
| 604 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 605 | |
| 606 | /* Don't promote wm_size to unsigned... */ |
| 607 | if (wm_size > (long)wm->max_wm) |
| 608 | wm_size = wm->max_wm; |
| 609 | if (wm_size <= 0) |
| 610 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 611 | |
| 612 | /* |
| 613 | * Bspec seems to indicate that the value shouldn't be lower than |
| 614 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 615 | * Lets go for 8 which is the burst size since certain platforms |
| 616 | * already use a hardcoded 8 (which is what the spec says should be |
| 617 | * done). |
| 618 | */ |
| 619 | if (wm_size <= 8) |
| 620 | wm_size = 8; |
| 621 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 622 | return wm_size; |
| 623 | } |
| 624 | |
| 625 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 626 | { |
| 627 | struct drm_crtc *crtc, *enabled = NULL; |
| 628 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 629 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 630 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 631 | if (enabled) |
| 632 | return NULL; |
| 633 | enabled = crtc; |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | return enabled; |
| 638 | } |
| 639 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 640 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 641 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 642 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 643 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 644 | struct drm_crtc *crtc; |
| 645 | const struct cxsr_latency *latency; |
| 646 | u32 reg; |
| 647 | unsigned long wm; |
| 648 | |
| 649 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 650 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 651 | if (!latency) { |
| 652 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 653 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 654 | return; |
| 655 | } |
| 656 | |
| 657 | crtc = single_enabled_crtc(dev); |
| 658 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 659 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 660 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 661 | int clock; |
| 662 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 663 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 664 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 665 | |
| 666 | /* Display SR */ |
| 667 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 668 | pineview_display_wm.fifo_size, |
| 669 | pixel_size, latency->display_sr); |
| 670 | reg = I915_READ(DSPFW1); |
| 671 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 672 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 673 | I915_WRITE(DSPFW1, reg); |
| 674 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 675 | |
| 676 | /* cursor SR */ |
| 677 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 678 | pineview_display_wm.fifo_size, |
| 679 | pixel_size, latency->cursor_sr); |
| 680 | reg = I915_READ(DSPFW3); |
| 681 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 682 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 683 | I915_WRITE(DSPFW3, reg); |
| 684 | |
| 685 | /* Display HPLL off SR */ |
| 686 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 687 | pineview_display_hplloff_wm.fifo_size, |
| 688 | pixel_size, latency->display_hpll_disable); |
| 689 | reg = I915_READ(DSPFW3); |
| 690 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 691 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 692 | I915_WRITE(DSPFW3, reg); |
| 693 | |
| 694 | /* cursor HPLL off SR */ |
| 695 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 696 | pineview_display_hplloff_wm.fifo_size, |
| 697 | pixel_size, latency->cursor_hpll_disable); |
| 698 | reg = I915_READ(DSPFW3); |
| 699 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 700 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 701 | I915_WRITE(DSPFW3, reg); |
| 702 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 703 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 704 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 705 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 706 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 711 | int plane, |
| 712 | const struct intel_watermark_params *display, |
| 713 | int display_latency_ns, |
| 714 | const struct intel_watermark_params *cursor, |
| 715 | int cursor_latency_ns, |
| 716 | int *plane_wm, |
| 717 | int *cursor_wm) |
| 718 | { |
| 719 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 720 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 721 | int htotal, hdisplay, clock, pixel_size; |
| 722 | int line_time_us, line_count; |
| 723 | int entries, tlb_miss; |
| 724 | |
| 725 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 726 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 727 | *cursor_wm = cursor->guard_size; |
| 728 | *plane_wm = display->guard_size; |
| 729 | return false; |
| 730 | } |
| 731 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 732 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 733 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 734 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 735 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 736 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 737 | |
| 738 | /* Use the small buffer method to calculate plane watermark */ |
| 739 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 740 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 741 | if (tlb_miss > 0) |
| 742 | entries += tlb_miss; |
| 743 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 744 | *plane_wm = entries + display->guard_size; |
| 745 | if (*plane_wm > (int)display->max_wm) |
| 746 | *plane_wm = display->max_wm; |
| 747 | |
| 748 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 749 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 750 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 751 | entries = line_count * crtc->cursor->state->crtc_w * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 752 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 753 | if (tlb_miss > 0) |
| 754 | entries += tlb_miss; |
| 755 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 756 | *cursor_wm = entries + cursor->guard_size; |
| 757 | if (*cursor_wm > (int)cursor->max_wm) |
| 758 | *cursor_wm = (int)cursor->max_wm; |
| 759 | |
| 760 | return true; |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * Check the wm result. |
| 765 | * |
| 766 | * If any calculated watermark values is larger than the maximum value that |
| 767 | * can be programmed into the associated watermark register, that watermark |
| 768 | * must be disabled. |
| 769 | */ |
| 770 | static bool g4x_check_srwm(struct drm_device *dev, |
| 771 | int display_wm, int cursor_wm, |
| 772 | const struct intel_watermark_params *display, |
| 773 | const struct intel_watermark_params *cursor) |
| 774 | { |
| 775 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 776 | display_wm, cursor_wm); |
| 777 | |
| 778 | if (display_wm > display->max_wm) { |
| 779 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 780 | display_wm, display->max_wm); |
| 781 | return false; |
| 782 | } |
| 783 | |
| 784 | if (cursor_wm > cursor->max_wm) { |
| 785 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 786 | cursor_wm, cursor->max_wm); |
| 787 | return false; |
| 788 | } |
| 789 | |
| 790 | if (!(display_wm || cursor_wm)) { |
| 791 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | return true; |
| 796 | } |
| 797 | |
| 798 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 799 | int plane, |
| 800 | int latency_ns, |
| 801 | const struct intel_watermark_params *display, |
| 802 | const struct intel_watermark_params *cursor, |
| 803 | int *display_wm, int *cursor_wm) |
| 804 | { |
| 805 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 806 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 807 | int hdisplay, htotal, pixel_size, clock; |
| 808 | unsigned long line_time_us; |
| 809 | int line_count, line_size; |
| 810 | int small, large; |
| 811 | int entries; |
| 812 | |
| 813 | if (!latency_ns) { |
| 814 | *display_wm = *cursor_wm = 0; |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 819 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 820 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 821 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 822 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 823 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 824 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 825 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 826 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 827 | line_size = hdisplay * pixel_size; |
| 828 | |
| 829 | /* Use the minimum of the small and large buffer method for primary */ |
| 830 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 831 | large = line_count * line_size; |
| 832 | |
| 833 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 834 | *display_wm = entries + display->guard_size; |
| 835 | |
| 836 | /* calculate the self-refresh watermark for display cursor */ |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 837 | entries = line_count * pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 838 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 839 | *cursor_wm = entries + cursor->guard_size; |
| 840 | |
| 841 | return g4x_check_srwm(dev, |
| 842 | *display_wm, *cursor_wm, |
| 843 | display, cursor); |
| 844 | } |
| 845 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 846 | #define FW_WM_VLV(value, plane) \ |
| 847 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 848 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 849 | static void vlv_write_wm_values(struct intel_crtc *crtc, |
| 850 | const struct vlv_wm_values *wm) |
| 851 | { |
| 852 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 853 | enum pipe pipe = crtc->pipe; |
| 854 | |
| 855 | I915_WRITE(VLV_DDL(pipe), |
| 856 | (wm->ddl[pipe].cursor << DDL_CURSOR_SHIFT) | |
| 857 | (wm->ddl[pipe].sprite[1] << DDL_SPRITE_SHIFT(1)) | |
| 858 | (wm->ddl[pipe].sprite[0] << DDL_SPRITE_SHIFT(0)) | |
| 859 | (wm->ddl[pipe].primary << DDL_PLANE_SHIFT)); |
| 860 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 861 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 862 | FW_WM(wm->sr.plane, SR) | |
| 863 | FW_WM(wm->pipe[PIPE_B].cursor, CURSORB) | |
| 864 | FW_WM_VLV(wm->pipe[PIPE_B].primary, PLANEB) | |
| 865 | FW_WM_VLV(wm->pipe[PIPE_A].primary, PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 866 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 867 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[1], SPRITEB) | |
| 868 | FW_WM(wm->pipe[PIPE_A].cursor, CURSORA) | |
| 869 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 870 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 871 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 872 | |
| 873 | if (IS_CHERRYVIEW(dev_priv)) { |
| 874 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 875 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 876 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 877 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 878 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[1], SPRITEF) | |
| 879 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 880 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 881 | FW_WM_VLV(wm->pipe[PIPE_C].primary, PLANEC) | |
| 882 | FW_WM(wm->pipe[PIPE_C].cursor, CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 883 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 884 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 885 | FW_WM(wm->pipe[PIPE_C].sprite[1] >> 8, SPRITEF_HI) | |
| 886 | FW_WM(wm->pipe[PIPE_C].sprite[0] >> 8, SPRITEE_HI) | |
| 887 | FW_WM(wm->pipe[PIPE_C].primary >> 8, PLANEC_HI) | |
| 888 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 889 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 890 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 891 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 892 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 893 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 894 | } else { |
| 895 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 896 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 897 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 898 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 899 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 900 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 901 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 902 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 903 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 904 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 905 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | POSTING_READ(DSPFW1); |
| 909 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 910 | dev_priv->wm.vlv = *wm; |
| 911 | } |
| 912 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 913 | #undef FW_WM_VLV |
| 914 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 915 | static uint8_t vlv_compute_drain_latency(struct drm_crtc *crtc, |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 916 | struct drm_plane *plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 917 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 918 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 919 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 920 | int entries, prec_mult, drain_latency, pixel_size; |
| 921 | int clock = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 922 | const int high_precision = IS_CHERRYVIEW(dev) ? 16 : 64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 923 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 924 | /* |
| 925 | * FIXME the plane might have an fb |
| 926 | * but be invisible (eg. due to clipping) |
| 927 | */ |
| 928 | if (!intel_crtc->active || !plane->state->fb) |
| 929 | return 0; |
| 930 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 931 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 932 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 933 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 934 | pixel_size = drm_format_plane_cpp(plane->state->fb->pixel_format, 0); |
| 935 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 936 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 937 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 938 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 939 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 940 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 941 | prec_mult = high_precision; |
| 942 | drain_latency = 64 * prec_mult * 4 / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 943 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 944 | if (drain_latency > DRAIN_LATENCY_MASK) { |
| 945 | prec_mult /= 2; |
| 946 | drain_latency = 64 * prec_mult * 4 / entries; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 947 | } |
| 948 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 949 | if (drain_latency > DRAIN_LATENCY_MASK) |
| 950 | drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 951 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 952 | return drain_latency | (prec_mult == high_precision ? |
| 953 | DDL_PRECISION_HIGH : DDL_PRECISION_LOW); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 954 | } |
| 955 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 956 | static int vlv_compute_wm(struct intel_crtc *crtc, |
| 957 | struct intel_plane *plane, |
| 958 | int fifo_size) |
| 959 | { |
| 960 | int clock, entries, pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 961 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 962 | /* |
| 963 | * FIXME the plane might have an fb |
| 964 | * but be invisible (eg. due to clipping) |
| 965 | */ |
| 966 | if (!crtc->active || !plane->base.state->fb) |
| 967 | return 0; |
| 968 | |
| 969 | pixel_size = drm_format_plane_cpp(plane->base.state->fb->pixel_format, 0); |
| 970 | clock = crtc->config->base.adjusted_mode.crtc_clock; |
| 971 | |
| 972 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
| 973 | |
| 974 | /* |
| 975 | * Set up the watermark such that we don't start issuing memory |
| 976 | * requests until we are within PND's max deadline value (256us). |
| 977 | * Idea being to be idle as long as possible while still taking |
| 978 | * advatange of PND's deadline scheduling. The limit of 8 |
| 979 | * cachelines (used when the FIFO will anyway drain in less time |
| 980 | * than 256us) should match what we would be done if trickle |
| 981 | * feed were enabled. |
| 982 | */ |
| 983 | return fifo_size - clamp(DIV_ROUND_UP(256 * entries, 64), 0, fifo_size - 8); |
| 984 | } |
| 985 | |
| 986 | static bool vlv_compute_sr_wm(struct drm_device *dev, |
| 987 | struct vlv_wm_values *wm) |
| 988 | { |
| 989 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 990 | struct drm_crtc *crtc; |
| 991 | enum pipe pipe = INVALID_PIPE; |
| 992 | int num_planes = 0; |
| 993 | int fifo_size = 0; |
| 994 | struct intel_plane *plane; |
| 995 | |
| 996 | wm->sr.cursor = wm->sr.plane = 0; |
| 997 | |
| 998 | crtc = single_enabled_crtc(dev); |
| 999 | /* maxfifo not supported on pipe C */ |
| 1000 | if (crtc && to_intel_crtc(crtc)->pipe != PIPE_C) { |
| 1001 | pipe = to_intel_crtc(crtc)->pipe; |
| 1002 | num_planes = !!wm->pipe[pipe].primary + |
| 1003 | !!wm->pipe[pipe].sprite[0] + |
| 1004 | !!wm->pipe[pipe].sprite[1]; |
| 1005 | fifo_size = INTEL_INFO(dev_priv)->num_pipes * 512 - 1; |
| 1006 | } |
| 1007 | |
| 1008 | if (fifo_size == 0 || num_planes > 1) |
| 1009 | return false; |
| 1010 | |
| 1011 | wm->sr.cursor = vlv_compute_wm(to_intel_crtc(crtc), |
| 1012 | to_intel_plane(crtc->cursor), 0x3f); |
| 1013 | |
| 1014 | list_for_each_entry(plane, &dev->mode_config.plane_list, base.head) { |
| 1015 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 1016 | continue; |
| 1017 | |
| 1018 | if (plane->pipe != pipe) |
| 1019 | continue; |
| 1020 | |
| 1021 | wm->sr.plane = vlv_compute_wm(to_intel_crtc(crtc), |
| 1022 | plane, fifo_size); |
| 1023 | if (wm->sr.plane != 0) |
| 1024 | break; |
| 1025 | } |
| 1026 | |
| 1027 | return true; |
| 1028 | } |
| 1029 | |
| 1030 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1031 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1032 | struct drm_device *dev = crtc->dev; |
| 1033 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1034 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1035 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1036 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1037 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1038 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1039 | wm.ddl[pipe].primary = vlv_compute_drain_latency(crtc, crtc->primary); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1040 | wm.pipe[pipe].primary = vlv_compute_wm(intel_crtc, |
| 1041 | to_intel_plane(crtc->primary), |
| 1042 | vlv_get_fifo_size(dev, pipe, 0)); |
| 1043 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1044 | wm.ddl[pipe].cursor = vlv_compute_drain_latency(crtc, crtc->cursor); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1045 | wm.pipe[pipe].cursor = vlv_compute_wm(intel_crtc, |
| 1046 | to_intel_plane(crtc->cursor), |
| 1047 | 0x3f); |
| 1048 | |
| 1049 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1050 | |
| 1051 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1052 | return; |
| 1053 | |
| 1054 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: plane=%d, cursor=%d, " |
| 1055 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1056 | wm.pipe[pipe].primary, wm.pipe[pipe].cursor, |
| 1057 | wm.sr.plane, wm.sr.cursor); |
| 1058 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 1059 | /* |
| 1060 | * FIXME DDR DVFS introduces massive memory latencies which |
| 1061 | * are not known to system agent so any deadline specified |
| 1062 | * by the display may not be respected. To support DDR DVFS |
| 1063 | * the watermark code needs to be rewritten to essentially |
| 1064 | * bypass deadline mechanism and rely solely on the |
| 1065 | * watermarks. For now disable DDR DVFS. |
| 1066 | */ |
| 1067 | if (IS_CHERRYVIEW(dev_priv)) |
| 1068 | chv_set_memory_dvfs(dev_priv, false); |
| 1069 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1070 | if (!cxsr_enabled) |
| 1071 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1072 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1073 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1074 | |
| 1075 | if (cxsr_enabled) |
| 1076 | intel_set_memory_cxsr(dev_priv, true); |
| 1077 | } |
| 1078 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1079 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1080 | struct drm_crtc *crtc, |
| 1081 | uint32_t sprite_width, |
| 1082 | uint32_t sprite_height, |
| 1083 | int pixel_size, |
| 1084 | bool enabled, bool scaled) |
| 1085 | { |
| 1086 | struct drm_device *dev = crtc->dev; |
| 1087 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1088 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1089 | enum pipe pipe = intel_crtc->pipe; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1090 | int sprite = to_intel_plane(plane)->plane; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1091 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1092 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1093 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1094 | if (enabled) { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1095 | wm.ddl[pipe].sprite[sprite] = |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1096 | vlv_compute_drain_latency(crtc, plane); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1097 | |
| 1098 | wm.pipe[pipe].sprite[sprite] = |
| 1099 | vlv_compute_wm(intel_crtc, |
| 1100 | to_intel_plane(plane), |
| 1101 | vlv_get_fifo_size(dev, pipe, sprite+1)); |
| 1102 | } else { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1103 | wm.ddl[pipe].sprite[sprite] = 0; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1104 | wm.pipe[pipe].sprite[sprite] = 0; |
| 1105 | } |
| 1106 | |
| 1107 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1108 | |
| 1109 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1110 | return; |
| 1111 | |
| 1112 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: sprite %c=%d, " |
| 1113 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1114 | sprite_name(pipe, sprite), |
| 1115 | wm.pipe[pipe].sprite[sprite], |
| 1116 | wm.sr.plane, wm.sr.cursor); |
| 1117 | |
| 1118 | if (!cxsr_enabled) |
| 1119 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1120 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1121 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1122 | |
| 1123 | if (cxsr_enabled) |
| 1124 | intel_set_memory_cxsr(dev_priv, true); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1125 | } |
| 1126 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1127 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1128 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1129 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1130 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1131 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1132 | static const int sr_latency_ns = 12000; |
| 1133 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1134 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1135 | int plane_sr, cursor_sr; |
| 1136 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1137 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1138 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1139 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1140 | &g4x_wm_info, pessimal_latency_ns, |
| 1141 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1142 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1143 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1144 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1145 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1146 | &g4x_wm_info, pessimal_latency_ns, |
| 1147 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1148 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1149 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1150 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1151 | if (single_plane_enabled(enabled) && |
| 1152 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1153 | sr_latency_ns, |
| 1154 | &g4x_wm_info, |
| 1155 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1156 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1157 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1158 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1159 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1160 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1161 | plane_sr = cursor_sr = 0; |
| 1162 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1163 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1164 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1165 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1166 | planea_wm, cursora_wm, |
| 1167 | planeb_wm, cursorb_wm, |
| 1168 | plane_sr, cursor_sr); |
| 1169 | |
| 1170 | I915_WRITE(DSPFW1, |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1171 | FW_WM(plane_sr, SR) | |
| 1172 | FW_WM(cursorb_wm, CURSORB) | |
| 1173 | FW_WM(planeb_wm, PLANEB) | |
| 1174 | FW_WM(planea_wm, PLANEA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1175 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1176 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1177 | FW_WM(cursora_wm, CURSORA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1178 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1179 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1180 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1181 | FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1182 | |
| 1183 | if (cxsr_enabled) |
| 1184 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1185 | } |
| 1186 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1187 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1188 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1189 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1190 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1191 | struct drm_crtc *crtc; |
| 1192 | int srwm = 1; |
| 1193 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1194 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1195 | |
| 1196 | /* Calc sr entries for one plane configs */ |
| 1197 | crtc = single_enabled_crtc(dev); |
| 1198 | if (crtc) { |
| 1199 | /* self-refresh has much higher latency */ |
| 1200 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1201 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1202 | &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1203 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1204 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1205 | int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1206 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1207 | unsigned long line_time_us; |
| 1208 | int entries; |
| 1209 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1210 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1211 | |
| 1212 | /* Use ns/us then divide to preserve precision */ |
| 1213 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1214 | pixel_size * hdisplay; |
| 1215 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1216 | srwm = I965_FIFO_SIZE - entries; |
| 1217 | if (srwm < 0) |
| 1218 | srwm = 1; |
| 1219 | srwm &= 0x1ff; |
| 1220 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1221 | entries, srwm); |
| 1222 | |
| 1223 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 1224 | pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1225 | entries = DIV_ROUND_UP(entries, |
| 1226 | i965_cursor_wm_info.cacheline_size); |
| 1227 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1228 | (entries + i965_cursor_wm_info.guard_size); |
| 1229 | |
| 1230 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1231 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1232 | |
| 1233 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1234 | "cursor %d\n", srwm, cursor_sr); |
| 1235 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1236 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1237 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1238 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1239 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1240 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1244 | srwm); |
| 1245 | |
| 1246 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1247 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 1248 | FW_WM(8, CURSORB) | |
| 1249 | FW_WM(8, PLANEB) | |
| 1250 | FW_WM(8, PLANEA)); |
| 1251 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 1252 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1253 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1254 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1255 | |
| 1256 | if (cxsr_enabled) |
| 1257 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1258 | } |
| 1259 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1260 | #undef FW_WM |
| 1261 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1262 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1263 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1264 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1265 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1266 | const struct intel_watermark_params *wm_info; |
| 1267 | uint32_t fwater_lo; |
| 1268 | uint32_t fwater_hi; |
| 1269 | int cwm, srwm = 1; |
| 1270 | int fifo_size; |
| 1271 | int planea_wm, planeb_wm; |
| 1272 | struct drm_crtc *crtc, *enabled = NULL; |
| 1273 | |
| 1274 | if (IS_I945GM(dev)) |
| 1275 | wm_info = &i945_wm_info; |
| 1276 | else if (!IS_GEN2(dev)) |
| 1277 | wm_info = &i915_wm_info; |
| 1278 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1279 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1280 | |
| 1281 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1282 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1283 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1284 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1285 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1286 | if (IS_GEN2(dev)) |
| 1287 | cpp = 4; |
| 1288 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1289 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1290 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1291 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1292 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1293 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1294 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1295 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1296 | if (planea_wm > (long)wm_info->max_wm) |
| 1297 | planea_wm = wm_info->max_wm; |
| 1298 | } |
| 1299 | |
| 1300 | if (IS_GEN2(dev)) |
| 1301 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1302 | |
| 1303 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1304 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1305 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1306 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1307 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1308 | if (IS_GEN2(dev)) |
| 1309 | cpp = 4; |
| 1310 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1311 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1312 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1313 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1314 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1315 | if (enabled == NULL) |
| 1316 | enabled = crtc; |
| 1317 | else |
| 1318 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1319 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1320 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1321 | if (planeb_wm > (long)wm_info->max_wm) |
| 1322 | planeb_wm = wm_info->max_wm; |
| 1323 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1324 | |
| 1325 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1326 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1327 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1328 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1329 | |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1330 | obj = intel_fb_obj(enabled->primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1331 | |
| 1332 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1333 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1334 | enabled = NULL; |
| 1335 | } |
| 1336 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1337 | /* |
| 1338 | * Overlay gets an aggressive default since video jitter is bad. |
| 1339 | */ |
| 1340 | cwm = 2; |
| 1341 | |
| 1342 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1343 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1344 | |
| 1345 | /* Calc sr entries for one plane configs */ |
| 1346 | if (HAS_FW_BLC(dev) && enabled) { |
| 1347 | /* self-refresh has much higher latency */ |
| 1348 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1349 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1350 | &to_intel_crtc(enabled)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1351 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1352 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1353 | int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1354 | int pixel_size = enabled->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1355 | unsigned long line_time_us; |
| 1356 | int entries; |
| 1357 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1358 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1359 | |
| 1360 | /* Use ns/us then divide to preserve precision */ |
| 1361 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1362 | pixel_size * hdisplay; |
| 1363 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1364 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1365 | srwm = wm_info->fifo_size - entries; |
| 1366 | if (srwm < 0) |
| 1367 | srwm = 1; |
| 1368 | |
| 1369 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1370 | I915_WRITE(FW_BLC_SELF, |
| 1371 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1372 | else if (IS_I915GM(dev)) |
| 1373 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1374 | } |
| 1375 | |
| 1376 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1377 | planea_wm, planeb_wm, cwm, srwm); |
| 1378 | |
| 1379 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1380 | fwater_hi = (cwm & 0x1f); |
| 1381 | |
| 1382 | /* Set request length to 8 cachelines per fetch */ |
| 1383 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1384 | fwater_hi = fwater_hi | (1 << 8); |
| 1385 | |
| 1386 | I915_WRITE(FW_BLC, fwater_lo); |
| 1387 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1388 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1389 | if (enabled) |
| 1390 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1391 | } |
| 1392 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1393 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1394 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1395 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1396 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1397 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1398 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1399 | uint32_t fwater_lo; |
| 1400 | int planea_wm; |
| 1401 | |
| 1402 | crtc = single_enabled_crtc(dev); |
| 1403 | if (crtc == NULL) |
| 1404 | return; |
| 1405 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1406 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1407 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1408 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1409 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1410 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1411 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1412 | fwater_lo |= (3<<8) | planea_wm; |
| 1413 | |
| 1414 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1415 | |
| 1416 | I915_WRITE(FW_BLC, fwater_lo); |
| 1417 | } |
| 1418 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1419 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1420 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1421 | { |
| 1422 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1423 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1424 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1425 | pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1426 | |
| 1427 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1428 | * adjust the pixel_rate here. */ |
| 1429 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1430 | if (intel_crtc->config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1431 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1432 | uint32_t pfit_size = intel_crtc->config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1433 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1434 | pipe_w = intel_crtc->config->pipe_src_w; |
| 1435 | pipe_h = intel_crtc->config->pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1436 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1437 | pfit_h = pfit_size & 0xFFFF; |
| 1438 | if (pipe_w < pfit_w) |
| 1439 | pipe_w = pfit_w; |
| 1440 | if (pipe_h < pfit_h) |
| 1441 | pipe_h = pfit_h; |
| 1442 | |
| 1443 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1444 | pfit_w * pfit_h); |
| 1445 | } |
| 1446 | |
| 1447 | return pixel_rate; |
| 1448 | } |
| 1449 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1450 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1451 | 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] | 1452 | uint32_t latency) |
| 1453 | { |
| 1454 | uint64_t ret; |
| 1455 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1456 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1457 | return UINT_MAX; |
| 1458 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1459 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1460 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1461 | |
| 1462 | return ret; |
| 1463 | } |
| 1464 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1465 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1466 | 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] | 1467 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1468 | uint32_t latency) |
| 1469 | { |
| 1470 | uint32_t ret; |
| 1471 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1472 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1473 | return UINT_MAX; |
| 1474 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1475 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1476 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1477 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1478 | return ret; |
| 1479 | } |
| 1480 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1481 | 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] | 1482 | uint8_t bytes_per_pixel) |
| 1483 | { |
| 1484 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1485 | } |
| 1486 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1487 | struct skl_pipe_wm_parameters { |
| 1488 | bool active; |
| 1489 | uint32_t pipe_htotal; |
| 1490 | uint32_t pixel_rate; /* in KHz */ |
| 1491 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1492 | struct intel_plane_wm_parameters cursor; |
| 1493 | }; |
| 1494 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1495 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1496 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1497 | uint32_t pipe_htotal; |
| 1498 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1499 | struct intel_plane_wm_parameters pri; |
| 1500 | struct intel_plane_wm_parameters spr; |
| 1501 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1502 | }; |
| 1503 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1504 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1505 | uint16_t pri; |
| 1506 | uint16_t spr; |
| 1507 | uint16_t cur; |
| 1508 | uint16_t fbc; |
| 1509 | }; |
| 1510 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1511 | /* used in computing the new watermarks state */ |
| 1512 | struct intel_wm_config { |
| 1513 | unsigned int num_pipes_active; |
| 1514 | bool sprites_enabled; |
| 1515 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1516 | }; |
| 1517 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1518 | /* |
| 1519 | * For both WM_PIPE and WM_LP. |
| 1520 | * mem_value must be in 0.1us units. |
| 1521 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1522 | 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] | 1523 | uint32_t mem_value, |
| 1524 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1525 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1526 | uint32_t method1, method2; |
| 1527 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1528 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1529 | return 0; |
| 1530 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1531 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1532 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1533 | mem_value); |
| 1534 | |
| 1535 | if (!is_lp) |
| 1536 | return method1; |
| 1537 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1538 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1539 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1540 | params->pri.horiz_pixels, |
| 1541 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1542 | mem_value); |
| 1543 | |
| 1544 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1545 | } |
| 1546 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1547 | /* |
| 1548 | * For both WM_PIPE and WM_LP. |
| 1549 | * mem_value must be in 0.1us units. |
| 1550 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1551 | 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] | 1552 | uint32_t mem_value) |
| 1553 | { |
| 1554 | uint32_t method1, method2; |
| 1555 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1556 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1557 | return 0; |
| 1558 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1559 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1560 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1561 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1562 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1563 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1564 | params->spr.horiz_pixels, |
| 1565 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1566 | mem_value); |
| 1567 | return min(method1, method2); |
| 1568 | } |
| 1569 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1570 | /* |
| 1571 | * For both WM_PIPE and WM_LP. |
| 1572 | * mem_value must be in 0.1us units. |
| 1573 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1574 | 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] | 1575 | uint32_t mem_value) |
| 1576 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1577 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1578 | return 0; |
| 1579 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1580 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1581 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1582 | params->cur.horiz_pixels, |
| 1583 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1584 | mem_value); |
| 1585 | } |
| 1586 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1587 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1588 | 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] | 1589 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1590 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1591 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1592 | return 0; |
| 1593 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1594 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1595 | params->pri.horiz_pixels, |
| 1596 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1597 | } |
| 1598 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1599 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1600 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1601 | if (INTEL_INFO(dev)->gen >= 8) |
| 1602 | return 3072; |
| 1603 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1604 | return 768; |
| 1605 | else |
| 1606 | return 512; |
| 1607 | } |
| 1608 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1609 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1610 | int level, bool is_sprite) |
| 1611 | { |
| 1612 | if (INTEL_INFO(dev)->gen >= 8) |
| 1613 | /* BDW primary/sprite plane watermarks */ |
| 1614 | return level == 0 ? 255 : 2047; |
| 1615 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1616 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1617 | return level == 0 ? 127 : 1023; |
| 1618 | else if (!is_sprite) |
| 1619 | /* ILK/SNB primary plane watermarks */ |
| 1620 | return level == 0 ? 127 : 511; |
| 1621 | else |
| 1622 | /* ILK/SNB sprite plane watermarks */ |
| 1623 | return level == 0 ? 63 : 255; |
| 1624 | } |
| 1625 | |
| 1626 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1627 | int level) |
| 1628 | { |
| 1629 | if (INTEL_INFO(dev)->gen >= 7) |
| 1630 | return level == 0 ? 63 : 255; |
| 1631 | else |
| 1632 | return level == 0 ? 31 : 63; |
| 1633 | } |
| 1634 | |
| 1635 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1636 | { |
| 1637 | if (INTEL_INFO(dev)->gen >= 8) |
| 1638 | return 31; |
| 1639 | else |
| 1640 | return 15; |
| 1641 | } |
| 1642 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1643 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1644 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1645 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1646 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1647 | enum intel_ddb_partitioning ddb_partitioning, |
| 1648 | bool is_sprite) |
| 1649 | { |
| 1650 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1651 | |
| 1652 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1653 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1654 | return 0; |
| 1655 | |
| 1656 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1657 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1658 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1659 | |
| 1660 | /* |
| 1661 | * For some reason the non self refresh |
| 1662 | * FIFO size is only half of the self |
| 1663 | * refresh FIFO size on ILK/SNB. |
| 1664 | */ |
| 1665 | if (INTEL_INFO(dev)->gen <= 6) |
| 1666 | fifo_size /= 2; |
| 1667 | } |
| 1668 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1669 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1670 | /* level 0 is always calculated with 1:1 split */ |
| 1671 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1672 | if (is_sprite) |
| 1673 | fifo_size *= 5; |
| 1674 | fifo_size /= 6; |
| 1675 | } else { |
| 1676 | fifo_size /= 2; |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1681 | 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] | 1682 | } |
| 1683 | |
| 1684 | /* Calculate the maximum cursor plane watermark */ |
| 1685 | 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] | 1686 | int level, |
| 1687 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1688 | { |
| 1689 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1690 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1691 | return 64; |
| 1692 | |
| 1693 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1694 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1695 | } |
| 1696 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1697 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1698 | int level, |
| 1699 | const struct intel_wm_config *config, |
| 1700 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1701 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1702 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1703 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1704 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1705 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1706 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1707 | } |
| 1708 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1709 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1710 | int level, |
| 1711 | struct ilk_wm_maximums *max) |
| 1712 | { |
| 1713 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1714 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1715 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1716 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1717 | } |
| 1718 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1719 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1720 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1721 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1722 | { |
| 1723 | bool ret; |
| 1724 | |
| 1725 | /* already determined to be invalid? */ |
| 1726 | if (!result->enable) |
| 1727 | return false; |
| 1728 | |
| 1729 | result->enable = result->pri_val <= max->pri && |
| 1730 | result->spr_val <= max->spr && |
| 1731 | result->cur_val <= max->cur; |
| 1732 | |
| 1733 | ret = result->enable; |
| 1734 | |
| 1735 | /* |
| 1736 | * HACK until we can pre-compute everything, |
| 1737 | * and thus fail gracefully if LP0 watermarks |
| 1738 | * are exceeded... |
| 1739 | */ |
| 1740 | if (level == 0 && !result->enable) { |
| 1741 | if (result->pri_val > max->pri) |
| 1742 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1743 | level, result->pri_val, max->pri); |
| 1744 | if (result->spr_val > max->spr) |
| 1745 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1746 | level, result->spr_val, max->spr); |
| 1747 | if (result->cur_val > max->cur) |
| 1748 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1749 | level, result->cur_val, max->cur); |
| 1750 | |
| 1751 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1752 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1753 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1754 | result->enable = true; |
| 1755 | } |
| 1756 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1757 | return ret; |
| 1758 | } |
| 1759 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1760 | 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] | 1761 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1762 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1763 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1764 | { |
| 1765 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1766 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1767 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1768 | |
| 1769 | /* WM1+ latency values stored in 0.5us units */ |
| 1770 | if (level > 0) { |
| 1771 | pri_latency *= 5; |
| 1772 | spr_latency *= 5; |
| 1773 | cur_latency *= 5; |
| 1774 | } |
| 1775 | |
| 1776 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1777 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1778 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1779 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1780 | result->enable = true; |
| 1781 | } |
| 1782 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1783 | static uint32_t |
| 1784 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1785 | { |
| 1786 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1787 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1788 | struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1789 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1790 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 1791 | if (!intel_crtc->active) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1792 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1793 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1794 | /* The WM are computed with base on how long it takes to fill a single |
| 1795 | * row at the given clock rate, multiplied by 8. |
| 1796 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1797 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1798 | mode->crtc_clock); |
| 1799 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1800 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1801 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1802 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1803 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1804 | } |
| 1805 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1806 | static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1807 | { |
| 1808 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1809 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1810 | if (IS_GEN9(dev)) { |
| 1811 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1812 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1813 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1814 | |
| 1815 | /* read the first set of memory latencies[0:3] */ |
| 1816 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 1817 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1818 | ret = sandybridge_pcode_read(dev_priv, |
| 1819 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1820 | &val); |
| 1821 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1822 | |
| 1823 | if (ret) { |
| 1824 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1825 | return; |
| 1826 | } |
| 1827 | |
| 1828 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1829 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1830 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1831 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1832 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1833 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1834 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1835 | |
| 1836 | /* read the second set of memory latencies[4:7] */ |
| 1837 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 1838 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1839 | ret = sandybridge_pcode_read(dev_priv, |
| 1840 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1841 | &val); |
| 1842 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1843 | if (ret) { |
| 1844 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1845 | return; |
| 1846 | } |
| 1847 | |
| 1848 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1849 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1850 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1851 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1852 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1853 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1854 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1855 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1856 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 1857 | * WaWmMemoryReadLatency:skl |
| 1858 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1859 | * punit doesn't take into account the read latency so we need |
| 1860 | * to add 2us to the various latency levels we retrieve from |
| 1861 | * the punit. |
| 1862 | * - W0 is a bit special in that it's the only level that |
| 1863 | * can't be disabled if we want to have display working, so |
| 1864 | * we always add 2us there. |
| 1865 | * - For levels >=1, punit returns 0us latency when they are |
| 1866 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1867 | * |
| 1868 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 1869 | * levels m (m >= n) need to be disabled. We make sure to |
| 1870 | * sanitize the values out of the punit to satisfy this |
| 1871 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1872 | */ |
| 1873 | wm[0] += 2; |
| 1874 | for (level = 1; level <= max_level; level++) |
| 1875 | if (wm[level] != 0) |
| 1876 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1877 | else { |
| 1878 | for (i = level + 1; i <= max_level; i++) |
| 1879 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1880 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1881 | break; |
| 1882 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1883 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1884 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1885 | |
| 1886 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1887 | if (wm[0] == 0) |
| 1888 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 1889 | wm[1] = (sskpd >> 4) & 0xFF; |
| 1890 | wm[2] = (sskpd >> 12) & 0xFF; |
| 1891 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 1892 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 1893 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 1894 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 1895 | |
| 1896 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 1897 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 1898 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 1899 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 1900 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1901 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 1902 | |
| 1903 | /* ILK primary LP0 latency is 700 ns */ |
| 1904 | wm[0] = 7; |
| 1905 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 1906 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1910 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1911 | { |
| 1912 | /* ILK sprite LP0 latency is 1300 ns */ |
| 1913 | if (INTEL_INFO(dev)->gen == 5) |
| 1914 | wm[0] = 13; |
| 1915 | } |
| 1916 | |
| 1917 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1918 | { |
| 1919 | /* ILK cursor LP0 latency is 1300 ns */ |
| 1920 | if (INTEL_INFO(dev)->gen == 5) |
| 1921 | wm[0] = 13; |
| 1922 | |
| 1923 | /* WaDoubleCursorLP3Latency:ivb */ |
| 1924 | if (IS_IVYBRIDGE(dev)) |
| 1925 | wm[3] *= 2; |
| 1926 | } |
| 1927 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 1928 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1929 | { |
| 1930 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1931 | if (IS_GEN9(dev)) |
| 1932 | return 7; |
| 1933 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1934 | return 4; |
| 1935 | else if (INTEL_INFO(dev)->gen >= 6) |
| 1936 | return 3; |
| 1937 | else |
| 1938 | return 2; |
| 1939 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 1940 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1941 | static void intel_print_wm_latency(struct drm_device *dev, |
| 1942 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1943 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1944 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1945 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1946 | |
| 1947 | for (level = 0; level <= max_level; level++) { |
| 1948 | unsigned int latency = wm[level]; |
| 1949 | |
| 1950 | if (latency == 0) { |
| 1951 | DRM_ERROR("%s WM%d latency not provided\n", |
| 1952 | name, level); |
| 1953 | continue; |
| 1954 | } |
| 1955 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1956 | /* |
| 1957 | * - latencies are in us on gen9. |
| 1958 | * - before then, WM1+ latency values are in 0.5us units |
| 1959 | */ |
| 1960 | if (IS_GEN9(dev)) |
| 1961 | latency *= 10; |
| 1962 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1963 | latency *= 5; |
| 1964 | |
| 1965 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 1966 | name, level, wm[level], |
| 1967 | latency / 10, latency % 10); |
| 1968 | } |
| 1969 | } |
| 1970 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1971 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 1972 | uint16_t wm[5], uint16_t min) |
| 1973 | { |
| 1974 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 1975 | |
| 1976 | if (wm[0] >= min) |
| 1977 | return false; |
| 1978 | |
| 1979 | wm[0] = max(wm[0], min); |
| 1980 | for (level = 1; level <= max_level; level++) |
| 1981 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 1982 | |
| 1983 | return true; |
| 1984 | } |
| 1985 | |
| 1986 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 1987 | { |
| 1988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1989 | bool changed; |
| 1990 | |
| 1991 | /* |
| 1992 | * The BIOS provided WM memory latency values are often |
| 1993 | * inadequate for high resolution displays. Adjust them. |
| 1994 | */ |
| 1995 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 1996 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 1997 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 1998 | |
| 1999 | if (!changed) |
| 2000 | return; |
| 2001 | |
| 2002 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2003 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2004 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2005 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2006 | } |
| 2007 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2008 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2009 | { |
| 2010 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2011 | |
| 2012 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2013 | |
| 2014 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2015 | sizeof(dev_priv->wm.pri_latency)); |
| 2016 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2017 | sizeof(dev_priv->wm.pri_latency)); |
| 2018 | |
| 2019 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2020 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2021 | |
| 2022 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2023 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2024 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2025 | |
| 2026 | if (IS_GEN6(dev)) |
| 2027 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2028 | } |
| 2029 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2030 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 2031 | { |
| 2032 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2033 | |
| 2034 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 2035 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 2036 | } |
| 2037 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2038 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2039 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2040 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2041 | struct drm_device *dev = crtc->dev; |
| 2042 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2043 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2044 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2045 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2046 | if (!intel_crtc->active) |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2047 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2048 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2049 | p->active = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2050 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2051 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2052 | |
| 2053 | if (crtc->primary->state->fb) { |
| 2054 | p->pri.enabled = true; |
| 2055 | p->pri.bytes_per_pixel = |
| 2056 | crtc->primary->state->fb->bits_per_pixel / 8; |
| 2057 | } else { |
| 2058 | p->pri.enabled = false; |
| 2059 | p->pri.bytes_per_pixel = 0; |
| 2060 | } |
| 2061 | |
| 2062 | if (crtc->cursor->state->fb) { |
| 2063 | p->cur.enabled = true; |
| 2064 | p->cur.bytes_per_pixel = 4; |
| 2065 | } else { |
| 2066 | p->cur.enabled = false; |
| 2067 | p->cur.bytes_per_pixel = 0; |
| 2068 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2069 | p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 2070 | p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2071 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2072 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2073 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2074 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2075 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2076 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2077 | break; |
| 2078 | } |
| 2079 | } |
| 2080 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2081 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2082 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2083 | struct intel_wm_config *config) |
| 2084 | { |
| 2085 | struct intel_crtc *intel_crtc; |
| 2086 | |
| 2087 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2088 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2089 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2090 | |
| 2091 | if (!wm->pipe_enabled) |
| 2092 | continue; |
| 2093 | |
| 2094 | config->sprites_enabled |= wm->sprites_enabled; |
| 2095 | config->sprites_scaled |= wm->sprites_scaled; |
| 2096 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2100 | /* Compute new watermarks for the pipe */ |
| 2101 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2102 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2103 | struct intel_pipe_wm *pipe_wm) |
| 2104 | { |
| 2105 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2106 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2107 | int level, max_level = ilk_wm_max_level(dev); |
| 2108 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2109 | struct intel_wm_config config = { |
| 2110 | .num_pipes_active = 1, |
| 2111 | .sprites_enabled = params->spr.enabled, |
| 2112 | .sprites_scaled = params->spr.scaled, |
| 2113 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2114 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2115 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2116 | pipe_wm->pipe_enabled = params->active; |
| 2117 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2118 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2119 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2120 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2121 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2122 | max_level = 1; |
| 2123 | |
| 2124 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2125 | if (params->spr.scaled) |
| 2126 | max_level = 0; |
| 2127 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2128 | 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] | 2129 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2130 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2131 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2132 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2133 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2134 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2135 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2136 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2137 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2138 | return false; |
| 2139 | |
| 2140 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2141 | |
| 2142 | for (level = 1; level <= max_level; level++) { |
| 2143 | struct intel_wm_level wm = {}; |
| 2144 | |
| 2145 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2146 | |
| 2147 | /* |
| 2148 | * Disable any watermark level that exceeds the |
| 2149 | * register maximums since such watermarks are |
| 2150 | * always invalid. |
| 2151 | */ |
| 2152 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2153 | break; |
| 2154 | |
| 2155 | pipe_wm->wm[level] = wm; |
| 2156 | } |
| 2157 | |
| 2158 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /* |
| 2162 | * Merge the watermarks from all active pipes for a specific level. |
| 2163 | */ |
| 2164 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2165 | int level, |
| 2166 | struct intel_wm_level *ret_wm) |
| 2167 | { |
| 2168 | const struct intel_crtc *intel_crtc; |
| 2169 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2170 | ret_wm->enable = true; |
| 2171 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2172 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2173 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2174 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2175 | |
| 2176 | if (!active->pipe_enabled) |
| 2177 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2178 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2179 | /* |
| 2180 | * The watermark values may have been used in the past, |
| 2181 | * so we must maintain them in the registers for some |
| 2182 | * time even if the level is now disabled. |
| 2183 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2184 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2185 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2186 | |
| 2187 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2188 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2189 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2190 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2191 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | /* |
| 2195 | * Merge all low power watermarks for all active pipes. |
| 2196 | */ |
| 2197 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2198 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2199 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2200 | struct intel_pipe_wm *merged) |
| 2201 | { |
| 2202 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2203 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2204 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2205 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2206 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2207 | config->num_pipes_active > 1) |
| 2208 | return; |
| 2209 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2210 | /* ILK: FBC WM must be disabled always */ |
| 2211 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2212 | |
| 2213 | /* merge each WM1+ level */ |
| 2214 | for (level = 1; level <= max_level; level++) { |
| 2215 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2216 | |
| 2217 | ilk_merge_wm_level(dev, level, wm); |
| 2218 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2219 | if (level > last_enabled_level) |
| 2220 | wm->enable = false; |
| 2221 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2222 | /* make sure all following levels get disabled */ |
| 2223 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2224 | |
| 2225 | /* |
| 2226 | * The spec says it is preferred to disable |
| 2227 | * FBC WMs instead of disabling a WM level. |
| 2228 | */ |
| 2229 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2230 | if (wm->enable) |
| 2231 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2232 | wm->fbc_val = 0; |
| 2233 | } |
| 2234 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2235 | |
| 2236 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2237 | /* |
| 2238 | * FIXME this is racy. FBC might get enabled later. |
| 2239 | * What we should check here is whether FBC can be |
| 2240 | * enabled sometime later. |
| 2241 | */ |
| 2242 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2243 | for (level = 2; level <= max_level; level++) { |
| 2244 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2245 | |
| 2246 | wm->enable = false; |
| 2247 | } |
| 2248 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2249 | } |
| 2250 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2251 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2252 | { |
| 2253 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2254 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2255 | } |
| 2256 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2257 | /* The value we need to program into the WM_LPx latency field */ |
| 2258 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2259 | { |
| 2260 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2261 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2262 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2263 | return 2 * level; |
| 2264 | else |
| 2265 | return dev_priv->wm.pri_latency[level]; |
| 2266 | } |
| 2267 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2268 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2269 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2270 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2271 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2272 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2273 | struct intel_crtc *intel_crtc; |
| 2274 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2275 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2276 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2277 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2278 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2279 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2280 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2281 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2282 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2283 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2284 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2285 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2286 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2287 | /* |
| 2288 | * Maintain the watermark values even if the level is |
| 2289 | * disabled. Doing otherwise could cause underruns. |
| 2290 | */ |
| 2291 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2292 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2293 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2294 | r->cur_val; |
| 2295 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2296 | if (r->enable) |
| 2297 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2298 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2299 | if (INTEL_INFO(dev)->gen >= 8) |
| 2300 | results->wm_lp[wm_lp - 1] |= |
| 2301 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2302 | else |
| 2303 | results->wm_lp[wm_lp - 1] |= |
| 2304 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2305 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2306 | /* |
| 2307 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2308 | * level is disabled. Doing otherwise could cause underruns. |
| 2309 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2310 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2311 | WARN_ON(wm_lp != 1); |
| 2312 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2313 | } else |
| 2314 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2315 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2316 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2317 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2318 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2319 | enum pipe pipe = intel_crtc->pipe; |
| 2320 | const struct intel_wm_level *r = |
| 2321 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2322 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2323 | if (WARN_ON(!r->enable)) |
| 2324 | continue; |
| 2325 | |
| 2326 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2327 | |
| 2328 | results->wm_pipe[pipe] = |
| 2329 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2330 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2331 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2335 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2336 | * 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] | 2337 | 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] | 2338 | struct intel_pipe_wm *r1, |
| 2339 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2340 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2341 | int level, max_level = ilk_wm_max_level(dev); |
| 2342 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2343 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2344 | for (level = 1; level <= max_level; level++) { |
| 2345 | if (r1->wm[level].enable) |
| 2346 | level1 = level; |
| 2347 | if (r2->wm[level].enable) |
| 2348 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2349 | } |
| 2350 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2351 | if (level1 == level2) { |
| 2352 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2353 | return r2; |
| 2354 | else |
| 2355 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2356 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2357 | return r1; |
| 2358 | } else { |
| 2359 | return r2; |
| 2360 | } |
| 2361 | } |
| 2362 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2363 | /* dirty bits used to track which watermarks need changes */ |
| 2364 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2365 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2366 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2367 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2368 | #define WM_DIRTY_FBC (1 << 24) |
| 2369 | #define WM_DIRTY_DDB (1 << 25) |
| 2370 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2371 | 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] | 2372 | const struct ilk_wm_values *old, |
| 2373 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2374 | { |
| 2375 | unsigned int dirty = 0; |
| 2376 | enum pipe pipe; |
| 2377 | int wm_lp; |
| 2378 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2379 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2380 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2381 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2382 | /* Must disable LP1+ watermarks too */ |
| 2383 | dirty |= WM_DIRTY_LP_ALL; |
| 2384 | } |
| 2385 | |
| 2386 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2387 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2388 | /* Must disable LP1+ watermarks too */ |
| 2389 | dirty |= WM_DIRTY_LP_ALL; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2394 | dirty |= WM_DIRTY_FBC; |
| 2395 | /* Must disable LP1+ watermarks too */ |
| 2396 | dirty |= WM_DIRTY_LP_ALL; |
| 2397 | } |
| 2398 | |
| 2399 | if (old->partitioning != new->partitioning) { |
| 2400 | dirty |= WM_DIRTY_DDB; |
| 2401 | /* Must disable LP1+ watermarks too */ |
| 2402 | dirty |= WM_DIRTY_LP_ALL; |
| 2403 | } |
| 2404 | |
| 2405 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2406 | if (dirty & WM_DIRTY_LP_ALL) |
| 2407 | return dirty; |
| 2408 | |
| 2409 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2410 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2411 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2412 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2413 | break; |
| 2414 | } |
| 2415 | |
| 2416 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2417 | for (; wm_lp <= 3; wm_lp++) |
| 2418 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2419 | |
| 2420 | return dirty; |
| 2421 | } |
| 2422 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2423 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2424 | unsigned int dirty) |
| 2425 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2426 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2427 | bool changed = false; |
| 2428 | |
| 2429 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2430 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2431 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2432 | changed = true; |
| 2433 | } |
| 2434 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2435 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2436 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2437 | changed = true; |
| 2438 | } |
| 2439 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2440 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2441 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2442 | changed = true; |
| 2443 | } |
| 2444 | |
| 2445 | /* |
| 2446 | * Don't touch WM1S_LP_EN here. |
| 2447 | * Doing so could cause underruns. |
| 2448 | */ |
| 2449 | |
| 2450 | return changed; |
| 2451 | } |
| 2452 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2453 | /* |
| 2454 | * The spec says we shouldn't write when we don't need, because every write |
| 2455 | * causes WMs to be re-evaluated, expending some power. |
| 2456 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2457 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2458 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2459 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2460 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2461 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2462 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2463 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2464 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2465 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2466 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2467 | return; |
| 2468 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2469 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2470 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2471 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2472 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2473 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2474 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2475 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2476 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2477 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2478 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2479 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2480 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2481 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2482 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2483 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2484 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2485 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2486 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2487 | val = I915_READ(WM_MISC); |
| 2488 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2489 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2490 | else |
| 2491 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2492 | I915_WRITE(WM_MISC, val); |
| 2493 | } else { |
| 2494 | val = I915_READ(DISP_ARB_CTL2); |
| 2495 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2496 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2497 | else |
| 2498 | val |= DISP_DATA_PARTITION_5_6; |
| 2499 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2500 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2501 | } |
| 2502 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2503 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2504 | val = I915_READ(DISP_ARB_CTL); |
| 2505 | if (results->enable_fbc_wm) |
| 2506 | val &= ~DISP_FBC_WM_DIS; |
| 2507 | else |
| 2508 | val |= DISP_FBC_WM_DIS; |
| 2509 | I915_WRITE(DISP_ARB_CTL, val); |
| 2510 | } |
| 2511 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2512 | if (dirty & WM_DIRTY_LP(1) && |
| 2513 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2514 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2515 | |
| 2516 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2517 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2518 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2519 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2520 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2521 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2522 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2523 | 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] | 2524 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2525 | 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] | 2526 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2527 | 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] | 2528 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2529 | |
| 2530 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2531 | } |
| 2532 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2533 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2534 | { |
| 2535 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2536 | |
| 2537 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2538 | } |
| 2539 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2540 | /* |
| 2541 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 2542 | * different active planes. |
| 2543 | */ |
| 2544 | |
| 2545 | #define SKL_DDB_SIZE 896 /* in blocks */ |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2546 | #define BXT_DDB_SIZE 512 |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2547 | |
| 2548 | static void |
| 2549 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 2550 | struct drm_crtc *for_crtc, |
| 2551 | const struct intel_wm_config *config, |
| 2552 | const struct skl_pipe_wm_parameters *params, |
| 2553 | struct skl_ddb_entry *alloc /* out */) |
| 2554 | { |
| 2555 | struct drm_crtc *crtc; |
| 2556 | unsigned int pipe_size, ddb_size; |
| 2557 | int nth_active_pipe; |
| 2558 | |
| 2559 | if (!params->active) { |
| 2560 | alloc->start = 0; |
| 2561 | alloc->end = 0; |
| 2562 | return; |
| 2563 | } |
| 2564 | |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2565 | if (IS_BROXTON(dev)) |
| 2566 | ddb_size = BXT_DDB_SIZE; |
| 2567 | else |
| 2568 | ddb_size = SKL_DDB_SIZE; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2569 | |
| 2570 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 2571 | |
| 2572 | nth_active_pipe = 0; |
| 2573 | for_each_crtc(dev, crtc) { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2574 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2575 | continue; |
| 2576 | |
| 2577 | if (crtc == for_crtc) |
| 2578 | break; |
| 2579 | |
| 2580 | nth_active_pipe++; |
| 2581 | } |
| 2582 | |
| 2583 | pipe_size = ddb_size / config->num_pipes_active; |
| 2584 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2585 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 2589 | { |
| 2590 | if (config->num_pipes_active == 1) |
| 2591 | return 32; |
| 2592 | |
| 2593 | return 8; |
| 2594 | } |
| 2595 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2596 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 2597 | { |
| 2598 | entry->start = reg & 0x3ff; |
| 2599 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2600 | if (entry->end) |
| 2601 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 2604 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 2605 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2606 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2607 | enum pipe pipe; |
| 2608 | int plane; |
| 2609 | u32 val; |
| 2610 | |
| 2611 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2612 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2613 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 2614 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 2615 | val); |
| 2616 | } |
| 2617 | |
| 2618 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 2619 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 2620 | } |
| 2621 | } |
| 2622 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2623 | static unsigned int |
| 2624 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 2625 | { |
| 2626 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 2627 | } |
| 2628 | |
| 2629 | /* |
| 2630 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 2631 | * a 8192x4096@32bpp framebuffer: |
| 2632 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 2633 | */ |
| 2634 | static unsigned int |
| 2635 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 2636 | const struct skl_pipe_wm_parameters *params) |
| 2637 | { |
| 2638 | unsigned int total_data_rate = 0; |
| 2639 | int plane; |
| 2640 | |
| 2641 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2642 | const struct intel_plane_wm_parameters *p; |
| 2643 | |
| 2644 | p = ¶ms->plane[plane]; |
| 2645 | if (!p->enabled) |
| 2646 | continue; |
| 2647 | |
| 2648 | total_data_rate += skl_plane_relative_data_rate(p); |
| 2649 | } |
| 2650 | |
| 2651 | return total_data_rate; |
| 2652 | } |
| 2653 | |
| 2654 | static void |
| 2655 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 2656 | const struct intel_wm_config *config, |
| 2657 | const struct skl_pipe_wm_parameters *params, |
| 2658 | struct skl_ddb_allocation *ddb /* out */) |
| 2659 | { |
| 2660 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2661 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2662 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2663 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2664 | struct skl_ddb_entry *alloc = &ddb->pipe[pipe]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2665 | uint16_t alloc_size, start, cursor_blocks; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2666 | uint16_t minimum[I915_MAX_PLANES]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2667 | unsigned int total_data_rate; |
| 2668 | int plane; |
| 2669 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2670 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc); |
| 2671 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2672 | if (alloc_size == 0) { |
| 2673 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 2674 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 2675 | return; |
| 2676 | } |
| 2677 | |
| 2678 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2679 | ddb->cursor[pipe].start = alloc->end - cursor_blocks; |
| 2680 | ddb->cursor[pipe].end = alloc->end; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2681 | |
| 2682 | alloc_size -= cursor_blocks; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2683 | alloc->end -= cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2684 | |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2685 | /* 1. Allocate the mininum required blocks for each active plane */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2686 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2687 | const struct intel_plane_wm_parameters *p; |
| 2688 | |
| 2689 | p = ¶ms->plane[plane]; |
| 2690 | if (!p->enabled) |
| 2691 | continue; |
| 2692 | |
| 2693 | minimum[plane] = 8; |
| 2694 | alloc_size -= minimum[plane]; |
| 2695 | } |
| 2696 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2697 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2698 | * 2. Distribute the remaining space in proportion to the amount of |
| 2699 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2700 | * |
| 2701 | * FIXME: we may not allocate every single block here. |
| 2702 | */ |
| 2703 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 2704 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2705 | start = alloc->start; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2706 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2707 | const struct intel_plane_wm_parameters *p; |
| 2708 | unsigned int data_rate; |
| 2709 | uint16_t plane_blocks; |
| 2710 | |
| 2711 | p = ¶ms->plane[plane]; |
| 2712 | if (!p->enabled) |
| 2713 | continue; |
| 2714 | |
| 2715 | data_rate = skl_plane_relative_data_rate(p); |
| 2716 | |
| 2717 | /* |
| 2718 | * promote the expression to 64 bits to avoid overflowing, the |
| 2719 | * result is < available as data_rate / total_data_rate < 1 |
| 2720 | */ |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2721 | plane_blocks = minimum[plane]; |
| 2722 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 2723 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2724 | |
| 2725 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2726 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2727 | |
| 2728 | start += plane_blocks; |
| 2729 | } |
| 2730 | |
| 2731 | } |
| 2732 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2733 | static uint32_t skl_pipe_pixel_rate(const struct intel_crtc_state *config) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2734 | { |
| 2735 | /* TODO: Take into account the scalers once we support them */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2736 | return config->base.adjusted_mode.crtc_clock; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | /* |
| 2740 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 2741 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 2742 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 2743 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 2744 | */ |
| 2745 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 2746 | uint32_t latency) |
| 2747 | { |
| 2748 | uint32_t wm_intermediate_val, ret; |
| 2749 | |
| 2750 | if (latency == 0) |
| 2751 | return UINT_MAX; |
| 2752 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2753 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel / 512; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2754 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 2755 | |
| 2756 | return ret; |
| 2757 | } |
| 2758 | |
| 2759 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 2760 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2761 | uint64_t tiling, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2762 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2763 | uint32_t ret; |
| 2764 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2765 | uint32_t wm_intermediate_val; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2766 | |
| 2767 | if (latency == 0) |
| 2768 | return UINT_MAX; |
| 2769 | |
| 2770 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2771 | |
| 2772 | if (tiling == I915_FORMAT_MOD_Y_TILED || |
| 2773 | tiling == I915_FORMAT_MOD_Yf_TILED) { |
| 2774 | plane_bytes_per_line *= 4; |
| 2775 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2776 | plane_blocks_per_line /= 4; |
| 2777 | } else { |
| 2778 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2779 | } |
| 2780 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2781 | wm_intermediate_val = latency * pixel_rate; |
| 2782 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2783 | plane_blocks_per_line; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2784 | |
| 2785 | return ret; |
| 2786 | } |
| 2787 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2788 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 2789 | const struct intel_crtc *intel_crtc) |
| 2790 | { |
| 2791 | struct drm_device *dev = intel_crtc->base.dev; |
| 2792 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2793 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2794 | enum pipe pipe = intel_crtc->pipe; |
| 2795 | |
| 2796 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 2797 | sizeof(new_ddb->plane[pipe]))) |
| 2798 | return true; |
| 2799 | |
| 2800 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 2801 | sizeof(new_ddb->cursor[pipe]))) |
| 2802 | return true; |
| 2803 | |
| 2804 | return false; |
| 2805 | } |
| 2806 | |
| 2807 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 2808 | struct intel_wm_config *config) |
| 2809 | { |
| 2810 | struct drm_crtc *crtc; |
| 2811 | struct drm_plane *plane; |
| 2812 | |
| 2813 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2814 | config->num_pipes_active += to_intel_crtc(crtc)->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2815 | |
| 2816 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 2817 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2818 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2819 | |
| 2820 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2821 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 2826 | struct skl_pipe_wm_parameters *p) |
| 2827 | { |
| 2828 | struct drm_device *dev = crtc->dev; |
| 2829 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2830 | enum pipe pipe = intel_crtc->pipe; |
| 2831 | struct drm_plane *plane; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2832 | struct drm_framebuffer *fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2833 | int i = 1; /* Index for sprite planes start */ |
| 2834 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2835 | p->active = intel_crtc->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2836 | if (p->active) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2837 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
| 2838 | p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2839 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2840 | fb = crtc->primary->state->fb; |
| 2841 | if (fb) { |
| 2842 | p->plane[0].enabled = true; |
| 2843 | p->plane[0].bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2844 | p->plane[0].tiling = fb->modifier[0]; |
| 2845 | } else { |
| 2846 | p->plane[0].enabled = false; |
| 2847 | p->plane[0].bytes_per_pixel = 0; |
| 2848 | p->plane[0].tiling = DRM_FORMAT_MOD_NONE; |
| 2849 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2850 | p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w; |
| 2851 | p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2852 | p->plane[0].rotation = crtc->primary->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2853 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2854 | fb = crtc->cursor->state->fb; |
| 2855 | if (fb) { |
| 2856 | p->cursor.enabled = true; |
| 2857 | p->cursor.bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2858 | p->cursor.horiz_pixels = crtc->cursor->state->crtc_w; |
| 2859 | p->cursor.vert_pixels = crtc->cursor->state->crtc_h; |
| 2860 | } else { |
| 2861 | p->cursor.enabled = false; |
| 2862 | p->cursor.bytes_per_pixel = 0; |
| 2863 | p->cursor.horiz_pixels = 64; |
| 2864 | p->cursor.vert_pixels = 64; |
| 2865 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2869 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2870 | |
Sonika Jindal | a712f8e | 2014-12-09 10:59:15 +0530 | [diff] [blame] | 2871 | if (intel_plane->pipe == pipe && |
| 2872 | plane->type == DRM_PLANE_TYPE_OVERLAY) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2873 | p->plane[i++] = intel_plane->wm; |
| 2874 | } |
| 2875 | } |
| 2876 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2877 | static bool skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 2878 | struct skl_pipe_wm_parameters *p, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2879 | struct intel_plane_wm_parameters *p_params, |
| 2880 | uint16_t ddb_allocation, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2881 | int level, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2882 | uint16_t *out_blocks, /* out */ |
| 2883 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2884 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2885 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
| 2886 | uint32_t method1, method2; |
| 2887 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2888 | uint32_t res_blocks, res_lines; |
| 2889 | uint32_t selected_result; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2890 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2891 | if (latency == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2892 | return false; |
| 2893 | |
| 2894 | method1 = skl_wm_method1(p->pixel_rate, |
| 2895 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2896 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2897 | method2 = skl_wm_method2(p->pixel_rate, |
| 2898 | p->pipe_htotal, |
| 2899 | p_params->horiz_pixels, |
| 2900 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2901 | p_params->tiling, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2902 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2903 | |
| 2904 | plane_bytes_per_line = p_params->horiz_pixels * |
| 2905 | p_params->bytes_per_pixel; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2906 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2907 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2908 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2909 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) { |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2910 | uint32_t min_scanlines = 4; |
| 2911 | uint32_t y_tile_minimum; |
| 2912 | if (intel_rotation_90_or_270(p_params->rotation)) { |
| 2913 | switch (p_params->bytes_per_pixel) { |
| 2914 | case 1: |
| 2915 | min_scanlines = 16; |
| 2916 | break; |
| 2917 | case 2: |
| 2918 | min_scanlines = 8; |
| 2919 | break; |
| 2920 | case 8: |
| 2921 | WARN(1, "Unsupported pixel depth for rotation"); |
kbuild test robot | 2f0b579 | 2015-03-26 22:30:21 +0800 | [diff] [blame] | 2922 | } |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2923 | } |
| 2924 | y_tile_minimum = plane_blocks_per_line * min_scanlines; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2925 | selected_result = max(method2, y_tile_minimum); |
| 2926 | } else { |
| 2927 | if ((ddb_allocation / plane_blocks_per_line) >= 1) |
| 2928 | selected_result = min(method1, method2); |
| 2929 | else |
| 2930 | selected_result = method1; |
| 2931 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2932 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2933 | res_blocks = selected_result + 1; |
| 2934 | res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2935 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2936 | if (level >= 1 && level <= 7) { |
| 2937 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2938 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) |
| 2939 | res_lines += 4; |
| 2940 | else |
| 2941 | res_blocks++; |
| 2942 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2943 | |
| 2944 | if (res_blocks >= ddb_allocation || res_lines > 31) |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2945 | return false; |
| 2946 | |
| 2947 | *out_blocks = res_blocks; |
| 2948 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2949 | |
| 2950 | return true; |
| 2951 | } |
| 2952 | |
| 2953 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 2954 | struct skl_ddb_allocation *ddb, |
| 2955 | struct skl_pipe_wm_parameters *p, |
| 2956 | enum pipe pipe, |
| 2957 | int level, |
| 2958 | int num_planes, |
| 2959 | struct skl_wm_level *result) |
| 2960 | { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2961 | uint16_t ddb_blocks; |
| 2962 | int i; |
| 2963 | |
| 2964 | for (i = 0; i < num_planes; i++) { |
| 2965 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 2966 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2967 | result->plane_en[i] = skl_compute_plane_wm(dev_priv, |
| 2968 | p, &p->plane[i], |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2969 | ddb_blocks, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2970 | level, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2971 | &result->plane_res_b[i], |
| 2972 | &result->plane_res_l[i]); |
| 2973 | } |
| 2974 | |
| 2975 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2976 | result->cursor_en = skl_compute_plane_wm(dev_priv, p, &p->cursor, |
| 2977 | ddb_blocks, level, |
| 2978 | &result->cursor_res_b, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2979 | &result->cursor_res_l); |
| 2980 | } |
| 2981 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2982 | static uint32_t |
| 2983 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 2984 | { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2985 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2986 | return 0; |
| 2987 | |
| 2988 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 2989 | |
| 2990 | } |
| 2991 | |
| 2992 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 2993 | struct skl_pipe_wm_parameters *params, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2994 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2995 | { |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 2996 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2997 | int i; |
| 2998 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2999 | if (!params->active) |
| 3000 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3001 | |
| 3002 | /* Until we know more, just disable transition WMs */ |
| 3003 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3004 | trans_wm->plane_en[i] = false; |
| 3005 | trans_wm->cursor_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3008 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 3009 | struct skl_ddb_allocation *ddb, |
| 3010 | struct skl_pipe_wm_parameters *params, |
| 3011 | struct skl_pipe_wm *pipe_wm) |
| 3012 | { |
| 3013 | struct drm_device *dev = crtc->dev; |
| 3014 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 3015 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3016 | int level, max_level = ilk_wm_max_level(dev); |
| 3017 | |
| 3018 | for (level = 0; level <= max_level; level++) { |
| 3019 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 3020 | level, intel_num_planes(intel_crtc), |
| 3021 | &pipe_wm->wm[level]); |
| 3022 | } |
| 3023 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 3024 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3025 | skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | static void skl_compute_wm_results(struct drm_device *dev, |
| 3029 | struct skl_pipe_wm_parameters *p, |
| 3030 | struct skl_pipe_wm *p_wm, |
| 3031 | struct skl_wm_values *r, |
| 3032 | struct intel_crtc *intel_crtc) |
| 3033 | { |
| 3034 | int level, max_level = ilk_wm_max_level(dev); |
| 3035 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3036 | uint32_t temp; |
| 3037 | int i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3038 | |
| 3039 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3040 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3041 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3042 | |
| 3043 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 3044 | PLANE_WM_LINES_SHIFT; |
| 3045 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 3046 | if (p_wm->wm[level].plane_en[i]) |
| 3047 | temp |= PLANE_WM_EN; |
| 3048 | |
| 3049 | r->plane[pipe][i][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3053 | |
| 3054 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3055 | temp |= p_wm->wm[level].cursor_res_b; |
| 3056 | |
| 3057 | if (p_wm->wm[level].cursor_en) |
| 3058 | temp |= PLANE_WM_EN; |
| 3059 | |
| 3060 | r->cursor[pipe][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3061 | |
| 3062 | } |
| 3063 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3064 | /* transition WMs */ |
| 3065 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3066 | temp = 0; |
| 3067 | temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT; |
| 3068 | temp |= p_wm->trans_wm.plane_res_b[i]; |
| 3069 | if (p_wm->trans_wm.plane_en[i]) |
| 3070 | temp |= PLANE_WM_EN; |
| 3071 | |
| 3072 | r->plane_trans[pipe][i] = temp; |
| 3073 | } |
| 3074 | |
| 3075 | temp = 0; |
| 3076 | temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3077 | temp |= p_wm->trans_wm.cursor_res_b; |
| 3078 | if (p_wm->trans_wm.cursor_en) |
| 3079 | temp |= PLANE_WM_EN; |
| 3080 | |
| 3081 | r->cursor_trans[pipe] = temp; |
| 3082 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3083 | r->wm_linetime[pipe] = p_wm->linetime; |
| 3084 | } |
| 3085 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3086 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 3087 | const struct skl_ddb_entry *entry) |
| 3088 | { |
| 3089 | if (entry->end) |
| 3090 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 3091 | else |
| 3092 | I915_WRITE(reg, 0); |
| 3093 | } |
| 3094 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3095 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 3096 | const struct skl_wm_values *new) |
| 3097 | { |
| 3098 | struct drm_device *dev = dev_priv->dev; |
| 3099 | struct intel_crtc *crtc; |
| 3100 | |
| 3101 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 3102 | int i, level, max_level = ilk_wm_max_level(dev); |
| 3103 | enum pipe pipe = crtc->pipe; |
| 3104 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3105 | if (!new->dirty[pipe]) |
| 3106 | continue; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3107 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3108 | I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]); |
| 3109 | |
| 3110 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3111 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3112 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 3113 | new->plane[pipe][i][level]); |
| 3114 | I915_WRITE(CUR_WM(pipe, level), |
| 3115 | new->cursor[pipe][level]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3116 | } |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3117 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3118 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 3119 | new->plane_trans[pipe][i]); |
| 3120 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
| 3121 | |
| 3122 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3123 | skl_ddb_entry_write(dev_priv, |
| 3124 | PLANE_BUF_CFG(pipe, i), |
| 3125 | &new->ddb.plane[pipe][i]); |
| 3126 | |
| 3127 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 3128 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3129 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3132 | /* |
| 3133 | * When setting up a new DDB allocation arrangement, we need to correctly |
| 3134 | * sequence the times at which the new allocations for the pipes are taken into |
| 3135 | * account or we'll have pipes fetching from space previously allocated to |
| 3136 | * another pipe. |
| 3137 | * |
| 3138 | * Roughly the sequence looks like: |
| 3139 | * 1. re-allocate the pipe(s) with the allocation being reduced and not |
| 3140 | * overlapping with a previous light-up pipe (another way to put it is: |
| 3141 | * pipes with their new allocation strickly included into their old ones). |
| 3142 | * 2. re-allocate the other pipes that get their allocation reduced |
| 3143 | * 3. allocate the pipes having their allocation increased |
| 3144 | * |
| 3145 | * Steps 1. and 2. are here to take care of the following case: |
| 3146 | * - Initially DDB looks like this: |
| 3147 | * | B | C | |
| 3148 | * - enable pipe A. |
| 3149 | * - pipe B has a reduced DDB allocation that overlaps with the old pipe C |
| 3150 | * allocation |
| 3151 | * | A | B | C | |
| 3152 | * |
| 3153 | * We need to sequence the re-allocation: C, B, A (and not B, C, A). |
| 3154 | */ |
| 3155 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3156 | static void |
| 3157 | skl_wm_flush_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, int pass) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3158 | { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3159 | int plane; |
| 3160 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3161 | DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass); |
| 3162 | |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 3163 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3164 | I915_WRITE(PLANE_SURF(pipe, plane), |
| 3165 | I915_READ(PLANE_SURF(pipe, plane))); |
| 3166 | } |
| 3167 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 3168 | } |
| 3169 | |
| 3170 | static bool |
| 3171 | skl_ddb_allocation_included(const struct skl_ddb_allocation *old, |
| 3172 | const struct skl_ddb_allocation *new, |
| 3173 | enum pipe pipe) |
| 3174 | { |
| 3175 | uint16_t old_size, new_size; |
| 3176 | |
| 3177 | old_size = skl_ddb_entry_size(&old->pipe[pipe]); |
| 3178 | new_size = skl_ddb_entry_size(&new->pipe[pipe]); |
| 3179 | |
| 3180 | return old_size != new_size && |
| 3181 | new->pipe[pipe].start >= old->pipe[pipe].start && |
| 3182 | new->pipe[pipe].end <= old->pipe[pipe].end; |
| 3183 | } |
| 3184 | |
| 3185 | static void skl_flush_wm_values(struct drm_i915_private *dev_priv, |
| 3186 | struct skl_wm_values *new_values) |
| 3187 | { |
| 3188 | struct drm_device *dev = dev_priv->dev; |
| 3189 | struct skl_ddb_allocation *cur_ddb, *new_ddb; |
| 3190 | bool reallocated[I915_MAX_PIPES] = {false, false, false}; |
| 3191 | struct intel_crtc *crtc; |
| 3192 | enum pipe pipe; |
| 3193 | |
| 3194 | new_ddb = &new_values->ddb; |
| 3195 | cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 3196 | |
| 3197 | /* |
| 3198 | * First pass: flush the pipes with the new allocation contained into |
| 3199 | * the old space. |
| 3200 | * |
| 3201 | * We'll wait for the vblank on those pipes to ensure we can safely |
| 3202 | * re-allocate the freed space without this pipe fetching from it. |
| 3203 | */ |
| 3204 | for_each_intel_crtc(dev, crtc) { |
| 3205 | if (!crtc->active) |
| 3206 | continue; |
| 3207 | |
| 3208 | pipe = crtc->pipe; |
| 3209 | |
| 3210 | if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe)) |
| 3211 | continue; |
| 3212 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3213 | skl_wm_flush_pipe(dev_priv, pipe, 1); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3214 | intel_wait_for_vblank(dev, pipe); |
| 3215 | |
| 3216 | reallocated[pipe] = true; |
| 3217 | } |
| 3218 | |
| 3219 | |
| 3220 | /* |
| 3221 | * Second pass: flush the pipes that are having their allocation |
| 3222 | * reduced, but overlapping with a previous allocation. |
| 3223 | * |
| 3224 | * Here as well we need to wait for the vblank to make sure the freed |
| 3225 | * space is not used anymore. |
| 3226 | */ |
| 3227 | for_each_intel_crtc(dev, crtc) { |
| 3228 | if (!crtc->active) |
| 3229 | continue; |
| 3230 | |
| 3231 | pipe = crtc->pipe; |
| 3232 | |
| 3233 | if (reallocated[pipe]) |
| 3234 | continue; |
| 3235 | |
| 3236 | if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) < |
| 3237 | skl_ddb_entry_size(&cur_ddb->pipe[pipe])) { |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3238 | skl_wm_flush_pipe(dev_priv, pipe, 2); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3239 | intel_wait_for_vblank(dev, pipe); |
Sonika Jindal | d9d8e6b | 2014-12-11 17:58:15 +0530 | [diff] [blame] | 3240 | reallocated[pipe] = true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3241 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | /* |
| 3245 | * Third pass: flush the pipes that got more space allocated. |
| 3246 | * |
| 3247 | * We don't need to actively wait for the update here, next vblank |
| 3248 | * will just get more DDB space with the correct WM values. |
| 3249 | */ |
| 3250 | for_each_intel_crtc(dev, crtc) { |
| 3251 | if (!crtc->active) |
| 3252 | continue; |
| 3253 | |
| 3254 | pipe = crtc->pipe; |
| 3255 | |
| 3256 | /* |
| 3257 | * At this point, only the pipes more space than before are |
| 3258 | * left to re-allocate. |
| 3259 | */ |
| 3260 | if (reallocated[pipe]) |
| 3261 | continue; |
| 3262 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3263 | skl_wm_flush_pipe(dev_priv, pipe, 3); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3267 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3268 | struct skl_pipe_wm_parameters *params, |
| 3269 | struct intel_wm_config *config, |
| 3270 | struct skl_ddb_allocation *ddb, /* out */ |
| 3271 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3272 | { |
| 3273 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3274 | |
| 3275 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3276 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3277 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3278 | |
| 3279 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3280 | return false; |
| 3281 | |
| 3282 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3283 | return true; |
| 3284 | } |
| 3285 | |
| 3286 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3287 | struct drm_crtc *crtc, |
| 3288 | struct intel_wm_config *config, |
| 3289 | struct skl_wm_values *r) |
| 3290 | { |
| 3291 | struct intel_crtc *intel_crtc; |
| 3292 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3293 | |
| 3294 | /* |
| 3295 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3296 | * crtc we are currently computing the new WM values for), other |
| 3297 | * enabled crtcs will keep the same allocation and we don't need to |
| 3298 | * recompute anything for them. |
| 3299 | */ |
| 3300 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3301 | return; |
| 3302 | |
| 3303 | /* |
| 3304 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3305 | * other active pipes need new DDB allocation and WM values. |
| 3306 | */ |
| 3307 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3308 | base.head) { |
| 3309 | struct skl_pipe_wm_parameters params = {}; |
| 3310 | struct skl_pipe_wm pipe_wm = {}; |
| 3311 | bool wm_changed; |
| 3312 | |
| 3313 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3314 | continue; |
| 3315 | |
| 3316 | if (!intel_crtc->active) |
| 3317 | continue; |
| 3318 | |
| 3319 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3320 | ¶ms, config, |
| 3321 | &r->ddb, &pipe_wm); |
| 3322 | |
| 3323 | /* |
| 3324 | * If we end up re-computing the other pipe WM values, it's |
| 3325 | * because it was really needed, so we expect the WM values to |
| 3326 | * be different. |
| 3327 | */ |
| 3328 | WARN_ON(!wm_changed); |
| 3329 | |
| 3330 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3331 | r->dirty[intel_crtc->pipe] = true; |
| 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3336 | { |
| 3337 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3338 | struct drm_device *dev = crtc->dev; |
| 3339 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3340 | struct skl_pipe_wm_parameters params = {}; |
| 3341 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3342 | struct skl_pipe_wm pipe_wm = {}; |
| 3343 | struct intel_wm_config config = {}; |
| 3344 | |
| 3345 | memset(results, 0, sizeof(*results)); |
| 3346 | |
| 3347 | skl_compute_wm_global_parameters(dev, &config); |
| 3348 | |
| 3349 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3350 | &results->ddb, &pipe_wm)) |
| 3351 | return; |
| 3352 | |
| 3353 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3354 | results->dirty[intel_crtc->pipe] = true; |
| 3355 | |
| 3356 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3357 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3358 | skl_flush_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3359 | |
| 3360 | /* store the new configuration */ |
| 3361 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | static void |
| 3365 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3366 | uint32_t sprite_width, uint32_t sprite_height, |
| 3367 | int pixel_size, bool enabled, bool scaled) |
| 3368 | { |
| 3369 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3370 | struct drm_framebuffer *fb = plane->state->fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3371 | |
| 3372 | intel_plane->wm.enabled = enabled; |
| 3373 | intel_plane->wm.scaled = scaled; |
| 3374 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3375 | intel_plane->wm.vert_pixels = sprite_height; |
| 3376 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3377 | intel_plane->wm.tiling = DRM_FORMAT_MOD_NONE; |
| 3378 | /* |
| 3379 | * Framebuffer can be NULL on plane disable, but it does not |
| 3380 | * matter for watermarks if we assume no tiling in that case. |
| 3381 | */ |
| 3382 | if (fb) |
| 3383 | intel_plane->wm.tiling = fb->modifier[0]; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 3384 | intel_plane->wm.rotation = plane->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3385 | |
| 3386 | skl_update_wm(crtc); |
| 3387 | } |
| 3388 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3389 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3390 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3391 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3392 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3393 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3394 | struct ilk_wm_maximums max; |
| 3395 | struct ilk_pipe_wm_parameters params = {}; |
| 3396 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3397 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3398 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3399 | 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] | 3400 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3401 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3402 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3403 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3404 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3405 | |
| 3406 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3407 | return; |
| 3408 | |
| 3409 | intel_crtc->wm.active = pipe_wm; |
| 3410 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3411 | ilk_compute_wm_config(dev, &config); |
| 3412 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3413 | 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] | 3414 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3415 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3416 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3417 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3418 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3419 | 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] | 3420 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3421 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3422 | 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] | 3423 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3424 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3425 | } |
| 3426 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3427 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3428 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3429 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3430 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3431 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3432 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3433 | } |
| 3434 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3435 | static void |
| 3436 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3437 | struct drm_crtc *crtc, |
| 3438 | uint32_t sprite_width, uint32_t sprite_height, |
| 3439 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3440 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3441 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3442 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3443 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3444 | intel_plane->wm.enabled = enabled; |
| 3445 | intel_plane->wm.scaled = scaled; |
| 3446 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3447 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3448 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3449 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3450 | /* |
| 3451 | * IVB workaround: must disable low power watermarks for at least |
| 3452 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3453 | * when scaling is disabled. |
| 3454 | * |
| 3455 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3456 | */ |
| 3457 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3458 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3459 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3460 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3461 | } |
| 3462 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3463 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3464 | struct skl_pipe_wm *active, |
| 3465 | bool is_transwm, |
| 3466 | bool is_cursor, |
| 3467 | int i, |
| 3468 | int level) |
| 3469 | { |
| 3470 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3471 | |
| 3472 | if (!is_transwm) { |
| 3473 | if (!is_cursor) { |
| 3474 | active->wm[level].plane_en[i] = is_enabled; |
| 3475 | active->wm[level].plane_res_b[i] = |
| 3476 | val & PLANE_WM_BLOCKS_MASK; |
| 3477 | active->wm[level].plane_res_l[i] = |
| 3478 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3479 | PLANE_WM_LINES_MASK; |
| 3480 | } else { |
| 3481 | active->wm[level].cursor_en = is_enabled; |
| 3482 | active->wm[level].cursor_res_b = |
| 3483 | val & PLANE_WM_BLOCKS_MASK; |
| 3484 | active->wm[level].cursor_res_l = |
| 3485 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3486 | PLANE_WM_LINES_MASK; |
| 3487 | } |
| 3488 | } else { |
| 3489 | if (!is_cursor) { |
| 3490 | active->trans_wm.plane_en[i] = is_enabled; |
| 3491 | active->trans_wm.plane_res_b[i] = |
| 3492 | val & PLANE_WM_BLOCKS_MASK; |
| 3493 | active->trans_wm.plane_res_l[i] = |
| 3494 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3495 | PLANE_WM_LINES_MASK; |
| 3496 | } else { |
| 3497 | active->trans_wm.cursor_en = is_enabled; |
| 3498 | active->trans_wm.cursor_res_b = |
| 3499 | val & PLANE_WM_BLOCKS_MASK; |
| 3500 | active->trans_wm.cursor_res_l = |
| 3501 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3502 | PLANE_WM_LINES_MASK; |
| 3503 | } |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3508 | { |
| 3509 | struct drm_device *dev = crtc->dev; |
| 3510 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3511 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3512 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3513 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3514 | enum pipe pipe = intel_crtc->pipe; |
| 3515 | int level, i, max_level; |
| 3516 | uint32_t temp; |
| 3517 | |
| 3518 | max_level = ilk_wm_max_level(dev); |
| 3519 | |
| 3520 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3521 | |
| 3522 | for (level = 0; level <= max_level; level++) { |
| 3523 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3524 | hw->plane[pipe][i][level] = |
| 3525 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3526 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3527 | } |
| 3528 | |
| 3529 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3530 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3531 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3532 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3533 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3534 | return; |
| 3535 | |
| 3536 | hw->dirty[pipe] = true; |
| 3537 | |
| 3538 | active->linetime = hw->wm_linetime[pipe]; |
| 3539 | |
| 3540 | for (level = 0; level <= max_level; level++) { |
| 3541 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3542 | temp = hw->plane[pipe][i][level]; |
| 3543 | skl_pipe_wm_active_state(temp, active, false, |
| 3544 | false, i, level); |
| 3545 | } |
| 3546 | temp = hw->cursor[pipe][level]; |
| 3547 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3548 | } |
| 3549 | |
| 3550 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3551 | temp = hw->plane_trans[pipe][i]; |
| 3552 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3553 | } |
| 3554 | |
| 3555 | temp = hw->cursor_trans[pipe]; |
| 3556 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3557 | } |
| 3558 | |
| 3559 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3560 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3561 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3562 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3563 | struct drm_crtc *crtc; |
| 3564 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3565 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3566 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3567 | skl_pipe_wm_get_hw_state(crtc); |
| 3568 | } |
| 3569 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3570 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3571 | { |
| 3572 | struct drm_device *dev = crtc->dev; |
| 3573 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3574 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3575 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3576 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3577 | enum pipe pipe = intel_crtc->pipe; |
| 3578 | static const unsigned int wm0_pipe_reg[] = { |
| 3579 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3580 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3581 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3582 | }; |
| 3583 | |
| 3584 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3585 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3586 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3587 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3588 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3589 | |
| 3590 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3591 | u32 tmp = hw->wm_pipe[pipe]; |
| 3592 | |
| 3593 | /* |
| 3594 | * For active pipes LP0 watermark is marked as |
| 3595 | * enabled, and LP1+ watermaks as disabled since |
| 3596 | * we can't really reverse compute them in case |
| 3597 | * multiple pipes are active. |
| 3598 | */ |
| 3599 | active->wm[0].enable = true; |
| 3600 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3601 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3602 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3603 | active->linetime = hw->wm_linetime[pipe]; |
| 3604 | } else { |
| 3605 | int level, max_level = ilk_wm_max_level(dev); |
| 3606 | |
| 3607 | /* |
| 3608 | * For inactive pipes, all watermark levels |
| 3609 | * should be marked as enabled but zeroed, |
| 3610 | * which is what we'd compute them to. |
| 3611 | */ |
| 3612 | for (level = 0; level <= max_level; level++) |
| 3613 | active->wm[level].enable = true; |
| 3614 | } |
| 3615 | } |
| 3616 | |
| 3617 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3618 | { |
| 3619 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3620 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3621 | struct drm_crtc *crtc; |
| 3622 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3623 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3624 | ilk_pipe_wm_get_hw_state(crtc); |
| 3625 | |
| 3626 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3627 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3628 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3629 | |
| 3630 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3631 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3632 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3633 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3634 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3635 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3636 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3637 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3638 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3639 | else if (IS_IVYBRIDGE(dev)) |
| 3640 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3641 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3642 | |
| 3643 | hw->enable_fbc_wm = |
| 3644 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3645 | } |
| 3646 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3647 | /** |
| 3648 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3649 | * |
| 3650 | * Calculate watermark values for the various WM regs based on current mode |
| 3651 | * and plane configuration. |
| 3652 | * |
| 3653 | * There are several cases to deal with here: |
| 3654 | * - normal (i.e. non-self-refresh) |
| 3655 | * - self-refresh (SR) mode |
| 3656 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3657 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3658 | * lines), so need to account for TLB latency |
| 3659 | * |
| 3660 | * The normal calculation is: |
| 3661 | * watermark = dotclock * bytes per pixel * latency |
| 3662 | * where latency is platform & configuration dependent (we assume pessimal |
| 3663 | * values here). |
| 3664 | * |
| 3665 | * The SR calculation is: |
| 3666 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3667 | * bytes per pixel |
| 3668 | * where |
| 3669 | * line time = htotal / dotclock |
| 3670 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3671 | * and latency is assumed to be high, as above. |
| 3672 | * |
| 3673 | * The final value programmed to the register should always be rounded up, |
| 3674 | * and include an extra 2 entries to account for clock crossings. |
| 3675 | * |
| 3676 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3677 | * to set the non-SR watermarks to 8. |
| 3678 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3679 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3680 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3681 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3682 | |
| 3683 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3684 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3685 | } |
| 3686 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3687 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3688 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3689 | uint32_t sprite_width, |
| 3690 | uint32_t sprite_height, |
| 3691 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3692 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3693 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3694 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3695 | |
| 3696 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3697 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3698 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3699 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3700 | } |
| 3701 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3702 | /** |
| 3703 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3704 | */ |
| 3705 | DEFINE_SPINLOCK(mchdev_lock); |
| 3706 | |
| 3707 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3708 | * mchdev_lock. */ |
| 3709 | static struct drm_i915_private *i915_mch_dev; |
| 3710 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3711 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3712 | { |
| 3713 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3714 | u16 rgvswctl; |
| 3715 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3716 | assert_spin_locked(&mchdev_lock); |
| 3717 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3718 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3719 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3720 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3721 | return false; /* still busy with another command */ |
| 3722 | } |
| 3723 | |
| 3724 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3725 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3726 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3727 | POSTING_READ16(MEMSWCTL); |
| 3728 | |
| 3729 | rgvswctl |= MEMCTL_CMD_STS; |
| 3730 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3731 | |
| 3732 | return true; |
| 3733 | } |
| 3734 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3735 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3736 | { |
| 3737 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3738 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3739 | u8 fmax, fmin, fstart, vstart; |
| 3740 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3741 | spin_lock_irq(&mchdev_lock); |
| 3742 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3743 | /* Enable temp reporting */ |
| 3744 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3745 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3746 | |
| 3747 | /* 100ms RC evaluation intervals */ |
| 3748 | I915_WRITE(RCUPEI, 100000); |
| 3749 | I915_WRITE(RCDNEI, 100000); |
| 3750 | |
| 3751 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3752 | I915_WRITE(RCBMAXAVG, 90000); |
| 3753 | I915_WRITE(RCBMINAVG, 80000); |
| 3754 | |
| 3755 | I915_WRITE(MEMIHYST, 1); |
| 3756 | |
| 3757 | /* Set up min, max, and cur for interrupt handling */ |
| 3758 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3759 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3760 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3761 | MEMMODE_FSTART_SHIFT; |
| 3762 | |
| 3763 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3764 | PXVFREQ_PX_SHIFT; |
| 3765 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3766 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3767 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3768 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3769 | dev_priv->ips.max_delay = fstart; |
| 3770 | dev_priv->ips.min_delay = fmin; |
| 3771 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3772 | |
| 3773 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3774 | fmax, fmin, fstart); |
| 3775 | |
| 3776 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3777 | |
| 3778 | /* |
| 3779 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3780 | */ |
| 3781 | |
| 3782 | I915_WRITE(VIDSTART, vstart); |
| 3783 | POSTING_READ(VIDSTART); |
| 3784 | |
| 3785 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3786 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3787 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3788 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3789 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3790 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3791 | |
| 3792 | ironlake_set_drps(dev, fstart); |
| 3793 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3794 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3795 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3796 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3797 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3798 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3799 | |
| 3800 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3801 | } |
| 3802 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3803 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3804 | { |
| 3805 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3806 | u16 rgvswctl; |
| 3807 | |
| 3808 | spin_lock_irq(&mchdev_lock); |
| 3809 | |
| 3810 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3811 | |
| 3812 | /* Ack interrupts, disable EFC interrupt */ |
| 3813 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3814 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3815 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3816 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3817 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3818 | |
| 3819 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3820 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3821 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3822 | rgvswctl |= MEMCTL_CMD_STS; |
| 3823 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3824 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3825 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3826 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3827 | } |
| 3828 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3829 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3830 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3831 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3832 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3833 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3834 | static u32 intel_rps_limits(struct drm_i915_private *dev_priv, u8 val) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3835 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3836 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3837 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3838 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3839 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3840 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3841 | * the hw runs at the minimal clock before selecting the desired |
| 3842 | * frequency, if the down threshold expires in that window we will not |
| 3843 | * receive a down interrupt. */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3844 | if (IS_GEN9(dev_priv->dev)) { |
| 3845 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 3846 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3847 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 3848 | } else { |
| 3849 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3850 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3851 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 3852 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3853 | |
| 3854 | return limits; |
| 3855 | } |
| 3856 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3857 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3858 | { |
| 3859 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3860 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 3861 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3862 | |
| 3863 | new_power = dev_priv->rps.power; |
| 3864 | switch (dev_priv->rps.power) { |
| 3865 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3866 | 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] | 3867 | new_power = BETWEEN; |
| 3868 | break; |
| 3869 | |
| 3870 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3871 | 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] | 3872 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3873 | 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] | 3874 | new_power = HIGH_POWER; |
| 3875 | break; |
| 3876 | |
| 3877 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3878 | 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] | 3879 | new_power = BETWEEN; |
| 3880 | break; |
| 3881 | } |
| 3882 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3883 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3884 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3885 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3886 | new_power = HIGH_POWER; |
| 3887 | if (new_power == dev_priv->rps.power) |
| 3888 | return; |
| 3889 | |
| 3890 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3891 | switch (new_power) { |
| 3892 | case LOW_POWER: |
| 3893 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3894 | ei_up = 16000; |
| 3895 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3896 | |
| 3897 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3898 | ei_down = 32000; |
| 3899 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3900 | break; |
| 3901 | |
| 3902 | case BETWEEN: |
| 3903 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3904 | ei_up = 13000; |
| 3905 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3906 | |
| 3907 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3908 | ei_down = 32000; |
| 3909 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3910 | break; |
| 3911 | |
| 3912 | case HIGH_POWER: |
| 3913 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3914 | ei_up = 10000; |
| 3915 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3916 | |
| 3917 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3918 | ei_down = 32000; |
| 3919 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3920 | break; |
| 3921 | } |
| 3922 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3923 | I915_WRITE(GEN6_RP_UP_EI, |
| 3924 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
| 3925 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
| 3926 | GT_INTERVAL_FROM_US(dev_priv, (ei_up * threshold_up / 100))); |
| 3927 | |
| 3928 | I915_WRITE(GEN6_RP_DOWN_EI, |
| 3929 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
| 3930 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
| 3931 | GT_INTERVAL_FROM_US(dev_priv, (ei_down * threshold_down / 100))); |
| 3932 | |
| 3933 | I915_WRITE(GEN6_RP_CONTROL, |
| 3934 | GEN6_RP_MEDIA_TURBO | |
| 3935 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3936 | GEN6_RP_MEDIA_IS_GFX | |
| 3937 | GEN6_RP_ENABLE | |
| 3938 | GEN6_RP_UP_BUSY_AVG | |
| 3939 | GEN6_RP_DOWN_IDLE_AVG); |
| 3940 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3941 | dev_priv->rps.power = new_power; |
| 3942 | dev_priv->rps.last_adj = 0; |
| 3943 | } |
| 3944 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3945 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3946 | { |
| 3947 | u32 mask = 0; |
| 3948 | |
| 3949 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3950 | mask |= GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3951 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3952 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3953 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3954 | mask &= dev_priv->pm_rps_events; |
| 3955 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 3956 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3959 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3960 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3961 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3962 | static void gen6_set_rps(struct drm_device *dev, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3963 | { |
| 3964 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3965 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3966 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3967 | WARN_ON(val > dev_priv->rps.max_freq); |
| 3968 | WARN_ON(val < dev_priv->rps.min_freq); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3969 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3970 | /* min/max delay may still have been modified so be sure to |
| 3971 | * write the limits value. |
| 3972 | */ |
| 3973 | if (val != dev_priv->rps.cur_freq) { |
| 3974 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3975 | |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 3976 | if (IS_GEN9(dev)) |
| 3977 | I915_WRITE(GEN6_RPNSWREQ, |
| 3978 | GEN9_FREQUENCY(val)); |
| 3979 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3980 | I915_WRITE(GEN6_RPNSWREQ, |
| 3981 | HSW_FREQUENCY(val)); |
| 3982 | else |
| 3983 | I915_WRITE(GEN6_RPNSWREQ, |
| 3984 | GEN6_FREQUENCY(val) | |
| 3985 | GEN6_OFFSET(0) | |
| 3986 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3987 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3988 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3989 | /* Make sure we continue to get interrupts |
| 3990 | * until we hit the minimum or maximum frequencies. |
| 3991 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3992 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3993 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3994 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 3995 | POSTING_READ(GEN6_RPNSWREQ); |
| 3996 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3997 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 3998 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3999 | } |
| 4000 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4001 | static void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 4002 | { |
| 4003 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4004 | |
| 4005 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4006 | WARN_ON(val > dev_priv->rps.max_freq); |
| 4007 | WARN_ON(val < dev_priv->rps.min_freq); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4008 | |
| 4009 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 4010 | "Odd GPU freq value\n")) |
| 4011 | val &= ~1; |
| 4012 | |
| 4013 | if (val != dev_priv->rps.cur_freq) |
| 4014 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 4015 | |
| 4016 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 4017 | |
| 4018 | dev_priv->rps.cur_freq = val; |
| 4019 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 4020 | } |
| 4021 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4022 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 4023 | * |
| 4024 | * * If Gfx is Idle, then |
| 4025 | * 1. Mask Turbo interrupts |
| 4026 | * 2. Bring up Gfx clock |
| 4027 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 4028 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 4029 | * 5. Unmask Turbo interrupts |
| 4030 | */ |
| 4031 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 4032 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4033 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4034 | u32 val = dev_priv->rps.idle_freq; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4035 | |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4036 | /* CHV and latest VLV don't need to force the gfx clock */ |
| 4037 | if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4038 | valleyview_set_rps(dev_priv->dev, val); |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4039 | return; |
| 4040 | } |
| 4041 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4042 | /* |
| 4043 | * When we are idle. Drop to min voltage state. |
| 4044 | */ |
| 4045 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4046 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4047 | return; |
| 4048 | |
| 4049 | /* Mask turbo interrupt so that they will not come in between */ |
Imre Deak | f24eeb1 | 2014-12-19 19:33:27 +0200 | [diff] [blame] | 4050 | I915_WRITE(GEN6_PMINTRMSK, |
| 4051 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4052 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4053 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4054 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4055 | dev_priv->rps.cur_freq = val; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4056 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4057 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4058 | |
| 4059 | if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS)) |
Imre Deak | 2837ac4 | 2014-11-19 16:25:38 +0200 | [diff] [blame] | 4060 | & GENFREQSTATUS) == 0, 100)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4061 | DRM_ERROR("timed out waiting for Punit\n"); |
| 4062 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4063 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4064 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4065 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4066 | } |
| 4067 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4068 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 4069 | { |
| 4070 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4071 | if (dev_priv->rps.enabled) { |
| 4072 | if (dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) |
| 4073 | gen6_rps_reset_ei(dev_priv); |
| 4074 | I915_WRITE(GEN6_PMINTRMSK, |
| 4075 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
| 4076 | } |
| 4077 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4078 | } |
| 4079 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4080 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 4081 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4082 | struct drm_device *dev = dev_priv->dev; |
| 4083 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4084 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4085 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4086 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4087 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4088 | else |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4089 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4090 | dev_priv->rps.last_adj = 0; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4091 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4092 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4093 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4094 | } |
| 4095 | |
| 4096 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 4097 | { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4098 | u32 val; |
| 4099 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4100 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4101 | val = dev_priv->rps.max_freq_softlimit; |
| 4102 | if (dev_priv->rps.enabled && |
| 4103 | dev_priv->mm.busy && |
| 4104 | dev_priv->rps.cur_freq < val) { |
| 4105 | intel_set_rps(dev_priv->dev, val); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4106 | dev_priv->rps.last_adj = 0; |
| 4107 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4108 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4109 | } |
| 4110 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4111 | void intel_set_rps(struct drm_device *dev, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4112 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4113 | if (IS_VALLEYVIEW(dev)) |
| 4114 | valleyview_set_rps(dev, val); |
| 4115 | else |
| 4116 | gen6_set_rps(dev, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4119 | static void gen9_disable_rps(struct drm_device *dev) |
| 4120 | { |
| 4121 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4122 | |
| 4123 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4124 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4127 | static void gen6_disable_rps(struct drm_device *dev) |
| 4128 | { |
| 4129 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4130 | |
| 4131 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4132 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4133 | } |
| 4134 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4135 | static void cherryview_disable_rps(struct drm_device *dev) |
| 4136 | { |
| 4137 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4138 | |
| 4139 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4140 | } |
| 4141 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4142 | static void valleyview_disable_rps(struct drm_device *dev) |
| 4143 | { |
| 4144 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4145 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4146 | /* we're doing forcewake before Disabling RC6, |
| 4147 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4148 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4149 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4150 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4151 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4152 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4155 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 4156 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4157 | if (IS_VALLEYVIEW(dev)) { |
| 4158 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 4159 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 4160 | else |
| 4161 | mode = 0; |
| 4162 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4163 | if (HAS_RC6p(dev)) |
| 4164 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 4165 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 4166 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 4167 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 4168 | |
| 4169 | else |
| 4170 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 4171 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4172 | } |
| 4173 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4174 | 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] | 4175 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 4176 | /* No RC6 before Ironlake */ |
| 4177 | if (INTEL_INFO(dev)->gen < 5) |
| 4178 | return 0; |
| 4179 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4180 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 4181 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 4182 | return 0; |
| 4183 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 4184 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4185 | if (enable_rc6 >= 0) { |
| 4186 | int mask; |
| 4187 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4188 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4189 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 4190 | INTEL_RC6pp_ENABLE; |
| 4191 | else |
| 4192 | mask = INTEL_RC6_ENABLE; |
| 4193 | |
| 4194 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 4195 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 4196 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4197 | |
| 4198 | return enable_rc6 & mask; |
| 4199 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4200 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 4201 | /* Disable RC6 on Ironlake */ |
| 4202 | if (INTEL_INFO(dev)->gen == 5) |
| 4203 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4204 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4205 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4206 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4207 | |
| 4208 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4209 | } |
| 4210 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4211 | int intel_enable_rc6(const struct drm_device *dev) |
| 4212 | { |
| 4213 | return i915.enable_rc6; |
| 4214 | } |
| 4215 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4216 | static void gen6_init_rps_frequencies(struct drm_device *dev) |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4217 | { |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4218 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4219 | uint32_t rp_state_cap; |
| 4220 | u32 ddcc_status = 0; |
| 4221 | int ret; |
| 4222 | |
| 4223 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4224 | /* All of these values are in units of 50MHz */ |
| 4225 | dev_priv->rps.cur_freq = 0; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4226 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4227 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4228 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4229 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
Akash Goel | cee991c | 2015-03-06 11:07:16 +0530 | [diff] [blame] | 4230 | if (IS_SKYLAKE(dev)) { |
| 4231 | /* Store the frequency values in 16.66 MHZ units, which is |
| 4232 | the natural hardware unit for SKL */ |
| 4233 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 4234 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 4235 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 4236 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4237 | /* hw_max = RP0 until we check for overclocking */ |
| 4238 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4239 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4240 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4241 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 4242 | ret = sandybridge_pcode_read(dev_priv, |
| 4243 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 4244 | &ddcc_status); |
| 4245 | if (0 == ret) |
| 4246 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 4247 | clamp_t(u8, |
| 4248 | ((ddcc_status >> 8) & 0xff), |
| 4249 | dev_priv->rps.min_freq, |
| 4250 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4253 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4254 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4255 | /* Preserve min/max settings in case of re-init */ |
| 4256 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4257 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4258 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4259 | if (dev_priv->rps.min_freq_softlimit == 0) { |
| 4260 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 4261 | dev_priv->rps.min_freq_softlimit = |
Tom O'Rourke | f4ab408 | 2014-11-19 14:21:53 -0800 | [diff] [blame] | 4262 | /* max(RPe, 450 MHz) */ |
| 4263 | max(dev_priv->rps.efficient_freq, (u8) 9); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4264 | else |
| 4265 | dev_priv->rps.min_freq_softlimit = |
| 4266 | dev_priv->rps.min_freq; |
| 4267 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4270 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4271 | static void gen9_enable_rps(struct drm_device *dev) |
| 4272 | { |
| 4273 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4274 | |
| 4275 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 4276 | |
Damien Lespiau | ba1c554 | 2015-01-16 18:07:26 +0000 | [diff] [blame] | 4277 | gen6_init_rps_frequencies(dev); |
| 4278 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4279 | /* Program defaults and thresholds for RPS*/ |
| 4280 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4281 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4282 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4283 | /* 1 second timeout*/ |
| 4284 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 4285 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 4286 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4287 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4288 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4289 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 4290 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 4291 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
| 4292 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 4293 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4294 | |
| 4295 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 4296 | } |
| 4297 | |
| 4298 | static void gen9_enable_rc6(struct drm_device *dev) |
| 4299 | { |
| 4300 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4301 | struct intel_engine_cs *ring; |
| 4302 | uint32_t rc6_mask = 0; |
| 4303 | int unused; |
| 4304 | |
| 4305 | /* 1a: Software RC state - RC0 */ |
| 4306 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4307 | |
| 4308 | /* 1b: Get forcewake during program sequence. Although the driver |
| 4309 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4310 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4311 | |
| 4312 | /* 2a: Disable RC states. */ |
| 4313 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4314 | |
| 4315 | /* 2b: Program RC6 thresholds.*/ |
| 4316 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
| 4317 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4318 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4319 | for_each_ring(ring, dev_priv, unused) |
| 4320 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4321 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4322 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 4323 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4324 | /* 2c: Program Coarse Power Gating Policies. */ |
| 4325 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 4326 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 4327 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4328 | /* 3a: Enable RC6 */ |
| 4329 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4330 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 4331 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 4332 | "on" : "off"); |
| 4333 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4334 | GEN6_RC_CTL_EI_MODE(1) | |
| 4335 | rc6_mask); |
| 4336 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4337 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled */ |
| 4338 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? 3 : 0); |
| 4339 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4340 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4341 | |
| 4342 | } |
| 4343 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4344 | static void gen8_enable_rps(struct drm_device *dev) |
| 4345 | { |
| 4346 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4347 | struct intel_engine_cs *ring; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4348 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4349 | int unused; |
| 4350 | |
| 4351 | /* 1a: Software RC state - RC0 */ |
| 4352 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4353 | |
| 4354 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4355 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4356 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4357 | |
| 4358 | /* 2a: Disable RC states. */ |
| 4359 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4360 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4361 | /* Initialize rps frequencies */ |
| 4362 | gen6_init_rps_frequencies(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4363 | |
| 4364 | /* 2b: Program RC6 thresholds.*/ |
| 4365 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4366 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4367 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4368 | for_each_ring(ring, dev_priv, unused) |
| 4369 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4370 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4371 | if (IS_BROADWELL(dev)) |
| 4372 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4373 | else |
| 4374 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4375 | |
| 4376 | /* 3: Enable RC6 */ |
| 4377 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4378 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4379 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4380 | if (IS_BROADWELL(dev)) |
| 4381 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4382 | GEN7_RC_CTL_TO_MODE | |
| 4383 | rc6_mask); |
| 4384 | else |
| 4385 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4386 | GEN6_RC_CTL_EI_MODE(1) | |
| 4387 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4388 | |
| 4389 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4390 | I915_WRITE(GEN6_RPNSWREQ, |
| 4391 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4392 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4393 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4394 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4395 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4396 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4397 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4398 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4399 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4400 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4401 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4402 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4403 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4404 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4405 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4406 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4407 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4408 | |
| 4409 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4410 | I915_WRITE(GEN6_RP_CONTROL, |
| 4411 | GEN6_RP_MEDIA_TURBO | |
| 4412 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4413 | GEN6_RP_MEDIA_IS_GFX | |
| 4414 | GEN6_RP_ENABLE | |
| 4415 | GEN6_RP_UP_BUSY_AVG | |
| 4416 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4417 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4418 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4419 | |
Tom O'Rourke | c7f3153 | 2014-11-19 14:21:54 -0800 | [diff] [blame] | 4420 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4421 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4422 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4423 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4426 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4427 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4428 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4429 | struct intel_engine_cs *ring; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4430 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4431 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4432 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4433 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4434 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4435 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4436 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4437 | /* Here begins a magic sequence of register writes to enable |
| 4438 | * auto-downclocking. |
| 4439 | * |
| 4440 | * Perhaps there might be some value in exposing these to |
| 4441 | * userspace... |
| 4442 | */ |
| 4443 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4444 | |
| 4445 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4446 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4447 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4448 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4449 | } |
| 4450 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4451 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4452 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4453 | /* Initialize rps frequencies */ |
| 4454 | gen6_init_rps_frequencies(dev); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4455 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4456 | /* disable the counters and set deterministic thresholds */ |
| 4457 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4458 | |
| 4459 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4460 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4461 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4462 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4463 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4464 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4465 | for_each_ring(ring, dev_priv, i) |
| 4466 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4467 | |
| 4468 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4469 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4470 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4471 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4472 | else |
| 4473 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4474 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4475 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4476 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4477 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4478 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4479 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4480 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4481 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4482 | /* We don't use those on Haswell */ |
| 4483 | if (!IS_HASWELL(dev)) { |
| 4484 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4485 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4486 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4487 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4488 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4489 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4490 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4491 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4492 | |
| 4493 | I915_WRITE(GEN6_RC_CONTROL, |
| 4494 | rc6_mask | |
| 4495 | GEN6_RC_CTL_EI_MODE(1) | |
| 4496 | GEN6_RC_CTL_HW_ENABLE); |
| 4497 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4498 | /* Power down if completely idle for over 50ms */ |
| 4499 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4500 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4501 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4502 | 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] | 4503 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4504 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4505 | |
| 4506 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4507 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4508 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4509 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4510 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4511 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4512 | } |
| 4513 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4514 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4515 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4516 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4517 | rc6vids = 0; |
| 4518 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4519 | if (IS_GEN6(dev) && ret) { |
| 4520 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4521 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4522 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4523 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4524 | rc6vids &= 0xffff00; |
| 4525 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4526 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4527 | if (ret) |
| 4528 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4529 | } |
| 4530 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4531 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4532 | } |
| 4533 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4534 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4535 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4536 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4537 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4538 | unsigned int gpu_freq; |
| 4539 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4540 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4541 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4542 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4543 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4544 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4545 | policy = cpufreq_cpu_get(0); |
| 4546 | if (policy) { |
| 4547 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4548 | cpufreq_cpu_put(policy); |
| 4549 | } else { |
| 4550 | /* |
| 4551 | * Default to measured freq if none found, PCU will ensure we |
| 4552 | * don't go over |
| 4553 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4554 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4555 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4556 | |
| 4557 | /* Convert from kHz to MHz */ |
| 4558 | max_ia_freq /= 1000; |
| 4559 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4560 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4561 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4562 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4563 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4564 | /* |
| 4565 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4566 | * to use for memory access. We do this by specifying the IA frequency |
| 4567 | * the PCU should use as a reference to determine the ring frequency. |
| 4568 | */ |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4569 | for (gpu_freq = dev_priv->rps.max_freq; gpu_freq >= dev_priv->rps.min_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4570 | gpu_freq--) { |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4571 | int diff = dev_priv->rps.max_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4572 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4573 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4574 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4575 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4576 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4577 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4578 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4579 | ring_freq = max(min_ring_freq, ring_freq); |
| 4580 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4581 | } else { |
| 4582 | /* On older processors, there is no separate ring |
| 4583 | * clock domain, so in order to boost the bandwidth |
| 4584 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4585 | * |
| 4586 | * For GPU frequencies less than 750MHz, |
| 4587 | * just use the lowest ring freq. |
| 4588 | */ |
| 4589 | if (gpu_freq < min_freq) |
| 4590 | ia_freq = 800; |
| 4591 | else |
| 4592 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4593 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4594 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4595 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4596 | sandybridge_pcode_write(dev_priv, |
| 4597 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4598 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4599 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4600 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4601 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4602 | } |
| 4603 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4604 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4605 | { |
| 4606 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4607 | |
| 4608 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4609 | return; |
| 4610 | |
| 4611 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4612 | __gen6_update_ring_freq(dev); |
| 4613 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4614 | } |
| 4615 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4616 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4617 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4618 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4619 | u32 val, rp0; |
| 4620 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4621 | if (dev->pdev->revision >= 0x20) { |
| 4622 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4623 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4624 | switch (INTEL_INFO(dev)->eu_total) { |
| 4625 | case 8: |
| 4626 | /* (2 * 4) config */ |
| 4627 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 4628 | break; |
| 4629 | case 12: |
| 4630 | /* (2 * 6) config */ |
| 4631 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 4632 | break; |
| 4633 | case 16: |
| 4634 | /* (2 * 8) config */ |
| 4635 | default: |
| 4636 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 4637 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 4638 | break; |
| 4639 | } |
| 4640 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 4641 | } else { |
| 4642 | /* For pre-production hardware */ |
| 4643 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4644 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4645 | PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4646 | } |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4647 | return rp0; |
| 4648 | } |
| 4649 | |
| 4650 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4651 | { |
| 4652 | u32 val, rpe; |
| 4653 | |
| 4654 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4655 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4656 | |
| 4657 | return rpe; |
| 4658 | } |
| 4659 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4660 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4661 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4662 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4663 | u32 val, rp1; |
| 4664 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4665 | if (dev->pdev->revision >= 0x20) { |
| 4666 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 4667 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 4668 | } else { |
| 4669 | /* For pre-production hardware */ |
| 4670 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4671 | rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4672 | PUNIT_GPU_STATUS_MAX_FREQ_MASK); |
| 4673 | } |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4674 | return rp1; |
| 4675 | } |
| 4676 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4677 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4678 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4679 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4680 | u32 val, rpn; |
| 4681 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4682 | if (dev->pdev->revision >= 0x20) { |
| 4683 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 4684 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 4685 | FB_GFX_FREQ_FUSE_MASK); |
| 4686 | } else { /* For pre-production hardware */ |
| 4687 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4688 | rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & |
| 4689 | PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK); |
| 4690 | } |
| 4691 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4692 | return rpn; |
| 4693 | } |
| 4694 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4695 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4696 | { |
| 4697 | u32 val, rp1; |
| 4698 | |
| 4699 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4700 | |
| 4701 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4702 | |
| 4703 | return rp1; |
| 4704 | } |
| 4705 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4706 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4707 | { |
| 4708 | u32 val, rp0; |
| 4709 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4710 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4711 | |
| 4712 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4713 | /* Clamp to max */ |
| 4714 | rp0 = min_t(u32, rp0, 0xea); |
| 4715 | |
| 4716 | return rp0; |
| 4717 | } |
| 4718 | |
| 4719 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4720 | { |
| 4721 | u32 val, rpe; |
| 4722 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4723 | 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] | 4724 | 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] | 4725 | 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] | 4726 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4727 | |
| 4728 | return rpe; |
| 4729 | } |
| 4730 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4731 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4732 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4733 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4734 | } |
| 4735 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4736 | /* Check that the pctx buffer wasn't move under us. */ |
| 4737 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4738 | { |
| 4739 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4740 | |
| 4741 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4742 | dev_priv->vlv_pctx->stolen->start); |
| 4743 | } |
| 4744 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4745 | |
| 4746 | /* Check that the pcbr address is not empty. */ |
| 4747 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4748 | { |
| 4749 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4750 | |
| 4751 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4752 | } |
| 4753 | |
| 4754 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4755 | { |
| 4756 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4757 | unsigned long pctx_paddr, paddr; |
| 4758 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4759 | u32 pcbr; |
| 4760 | int pctx_size = 32*1024; |
| 4761 | |
| 4762 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4763 | |
| 4764 | pcbr = I915_READ(VLV_PCBR); |
| 4765 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4766 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4767 | paddr = (dev_priv->mm.stolen_base + |
| 4768 | (gtt->stolen_size - pctx_size)); |
| 4769 | |
| 4770 | pctx_paddr = (paddr & (~4095)); |
| 4771 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4772 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4773 | |
| 4774 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4775 | } |
| 4776 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4777 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4778 | { |
| 4779 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4780 | struct drm_i915_gem_object *pctx; |
| 4781 | unsigned long pctx_paddr; |
| 4782 | u32 pcbr; |
| 4783 | int pctx_size = 24*1024; |
| 4784 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4785 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4786 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4787 | pcbr = I915_READ(VLV_PCBR); |
| 4788 | if (pcbr) { |
| 4789 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4790 | int pcbr_offset; |
| 4791 | |
| 4792 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4793 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4794 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4795 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4796 | pctx_size); |
| 4797 | goto out; |
| 4798 | } |
| 4799 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4800 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 4801 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4802 | /* |
| 4803 | * From the Gunit register HAS: |
| 4804 | * The Gfx driver is expected to program this register and ensure |
| 4805 | * proper allocation within Gfx stolen memory. For example, this |
| 4806 | * register should be programmed such than the PCBR range does not |
| 4807 | * overlap with other ranges, such as the frame buffer, protected |
| 4808 | * memory, or any other relevant ranges. |
| 4809 | */ |
| 4810 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4811 | if (!pctx) { |
| 4812 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4813 | return; |
| 4814 | } |
| 4815 | |
| 4816 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4817 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4818 | |
| 4819 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4820 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4821 | dev_priv->vlv_pctx = pctx; |
| 4822 | } |
| 4823 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4824 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4825 | { |
| 4826 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4827 | |
| 4828 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4829 | return; |
| 4830 | |
| 4831 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4832 | dev_priv->vlv_pctx = NULL; |
| 4833 | } |
| 4834 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4835 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4836 | { |
| 4837 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4838 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4839 | |
| 4840 | valleyview_setup_pctx(dev); |
| 4841 | |
| 4842 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4843 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4844 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4845 | switch ((val >> 6) & 3) { |
| 4846 | case 0: |
| 4847 | case 1: |
| 4848 | dev_priv->mem_freq = 800; |
| 4849 | break; |
| 4850 | case 2: |
| 4851 | dev_priv->mem_freq = 1066; |
| 4852 | break; |
| 4853 | case 3: |
| 4854 | dev_priv->mem_freq = 1333; |
| 4855 | break; |
| 4856 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4857 | DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq); |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4858 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4859 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4860 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4861 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4862 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4863 | dev_priv->rps.max_freq); |
| 4864 | |
| 4865 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4866 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4867 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4868 | dev_priv->rps.efficient_freq); |
| 4869 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4870 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4871 | DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4872 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4873 | dev_priv->rps.rp1_freq); |
| 4874 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4875 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4876 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4877 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4878 | dev_priv->rps.min_freq); |
| 4879 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4880 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4881 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4882 | /* Preserve min/max settings in case of re-init */ |
| 4883 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4884 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4885 | |
| 4886 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4887 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4888 | |
| 4889 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4890 | } |
| 4891 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4892 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4893 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4894 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4895 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4896 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4897 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4898 | |
| 4899 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4900 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 4901 | mutex_lock(&dev_priv->dpio_lock); |
| 4902 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
| 4903 | mutex_unlock(&dev_priv->dpio_lock); |
| 4904 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4905 | switch ((val >> 2) & 0x7) { |
| 4906 | case 0: |
| 4907 | case 1: |
| 4908 | dev_priv->rps.cz_freq = 200; |
| 4909 | dev_priv->mem_freq = 1600; |
| 4910 | break; |
| 4911 | case 2: |
| 4912 | dev_priv->rps.cz_freq = 267; |
| 4913 | dev_priv->mem_freq = 1600; |
| 4914 | break; |
| 4915 | case 3: |
| 4916 | dev_priv->rps.cz_freq = 333; |
| 4917 | dev_priv->mem_freq = 2000; |
| 4918 | break; |
| 4919 | case 4: |
| 4920 | dev_priv->rps.cz_freq = 320; |
| 4921 | dev_priv->mem_freq = 1600; |
| 4922 | break; |
| 4923 | case 5: |
| 4924 | dev_priv->rps.cz_freq = 400; |
| 4925 | dev_priv->mem_freq = 1600; |
| 4926 | break; |
| 4927 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4928 | DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq); |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4929 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4930 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4931 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4932 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4933 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4934 | dev_priv->rps.max_freq); |
| 4935 | |
| 4936 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4937 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4938 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4939 | dev_priv->rps.efficient_freq); |
| 4940 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4941 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4942 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4943 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4944 | dev_priv->rps.rp1_freq); |
| 4945 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4946 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4947 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4948 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4949 | dev_priv->rps.min_freq); |
| 4950 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4951 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4952 | dev_priv->rps.efficient_freq | |
| 4953 | dev_priv->rps.rp1_freq | |
| 4954 | dev_priv->rps.min_freq) & 1, |
| 4955 | "Odd GPU freq values\n"); |
| 4956 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4957 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4958 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4959 | /* Preserve min/max settings in case of re-init */ |
| 4960 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4961 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4962 | |
| 4963 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4964 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4965 | |
| 4966 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4967 | } |
| 4968 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4969 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4970 | { |
| 4971 | valleyview_cleanup_pctx(dev); |
| 4972 | } |
| 4973 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4974 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4975 | { |
| 4976 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4977 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4978 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4979 | int i; |
| 4980 | |
| 4981 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4982 | |
| 4983 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4984 | if (gtfifodbg) { |
| 4985 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4986 | gtfifodbg); |
| 4987 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4988 | } |
| 4989 | |
| 4990 | cherryview_check_pctx(dev_priv); |
| 4991 | |
| 4992 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 4993 | * hasn't enabled a state yet where we need forcewake, BIOS may have.*/ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4994 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4995 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 4996 | /* Disable RC states. */ |
| 4997 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4998 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4999 | /* 2a: Program RC6 thresholds.*/ |
| 5000 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 5001 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5002 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 5003 | |
| 5004 | for_each_ring(ring, dev_priv, i) |
| 5005 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5006 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 5007 | |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5008 | /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */ |
| 5009 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5010 | |
| 5011 | /* allows RC6 residency counter to work */ |
| 5012 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 5013 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 5014 | VLV_MEDIA_RC6_COUNT_EN | |
| 5015 | VLV_RENDER_RC6_COUNT_EN)); |
| 5016 | |
| 5017 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 5018 | pcbr = I915_READ(VLV_PCBR); |
| 5019 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5020 | /* 3: Enable RC6 */ |
| 5021 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 5022 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5023 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5024 | |
| 5025 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 5026 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5027 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 5028 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5029 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5030 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5031 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5032 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5033 | |
| 5034 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5035 | |
| 5036 | /* 5: Enable RPS */ |
| 5037 | I915_WRITE(GEN6_RP_CONTROL, |
| 5038 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 5039 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5040 | GEN6_RP_ENABLE | |
| 5041 | GEN6_RP_UP_BUSY_AVG | |
| 5042 | GEN6_RP_DOWN_IDLE_AVG); |
| 5043 | |
| 5044 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5045 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5046 | /* RPS code assumes GPLL is used */ |
| 5047 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5048 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5049 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5050 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5051 | |
| 5052 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 5053 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5054 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5055 | dev_priv->rps.cur_freq); |
| 5056 | |
| 5057 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5058 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5059 | dev_priv->rps.efficient_freq); |
| 5060 | |
| 5061 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 5062 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5063 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5064 | } |
| 5065 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5066 | static void valleyview_enable_rps(struct drm_device *dev) |
| 5067 | { |
| 5068 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5069 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 5070 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5071 | int i; |
| 5072 | |
| 5073 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5074 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5075 | valleyview_check_pctx(dev_priv); |
| 5076 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5077 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 5078 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5079 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5080 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5081 | } |
| 5082 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 5083 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5084 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5085 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5086 | /* Disable RC states. */ |
| 5087 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5088 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 5089 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5090 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5091 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5092 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5093 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5094 | |
| 5095 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5096 | |
| 5097 | I915_WRITE(GEN6_RP_CONTROL, |
| 5098 | GEN6_RP_MEDIA_TURBO | |
| 5099 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5100 | GEN6_RP_MEDIA_IS_GFX | |
| 5101 | GEN6_RP_ENABLE | |
| 5102 | GEN6_RP_UP_BUSY_AVG | |
| 5103 | GEN6_RP_DOWN_IDLE_CONT); |
| 5104 | |
| 5105 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 5106 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 5107 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 5108 | |
| 5109 | for_each_ring(ring, dev_priv, i) |
| 5110 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5111 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 5112 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5113 | |
| 5114 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5115 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5116 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 5117 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5118 | VLV_MEDIA_RC6_COUNT_EN | |
| 5119 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5120 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5121 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 5122 | 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] | 5123 | |
| 5124 | intel_print_rc6_info(dev, rc6_mode); |
| 5125 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5126 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5127 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5128 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5129 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5130 | /* RPS code assumes GPLL is used */ |
| 5131 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5132 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5133 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5134 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5135 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5136 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5137 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5138 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5139 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5140 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5141 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5142 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5143 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5144 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5145 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5146 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5147 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5150 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 5151 | { |
| 5152 | unsigned long freq; |
| 5153 | int div = (vidfreq & 0x3f0000) >> 16; |
| 5154 | int post = (vidfreq & 0x3000) >> 12; |
| 5155 | int pre = (vidfreq & 0x7); |
| 5156 | |
| 5157 | if (!pre) |
| 5158 | return 0; |
| 5159 | |
| 5160 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 5161 | |
| 5162 | return freq; |
| 5163 | } |
| 5164 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5165 | static const struct cparams { |
| 5166 | u16 i; |
| 5167 | u16 t; |
| 5168 | u16 m; |
| 5169 | u16 c; |
| 5170 | } cparams[] = { |
| 5171 | { 1, 1333, 301, 28664 }, |
| 5172 | { 1, 1066, 294, 24460 }, |
| 5173 | { 1, 800, 294, 25192 }, |
| 5174 | { 0, 1333, 276, 27605 }, |
| 5175 | { 0, 1066, 276, 27605 }, |
| 5176 | { 0, 800, 231, 23784 }, |
| 5177 | }; |
| 5178 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5179 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5180 | { |
| 5181 | u64 total_count, diff, ret; |
| 5182 | u32 count1, count2, count3, m = 0, c = 0; |
| 5183 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 5184 | int i; |
| 5185 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5186 | assert_spin_locked(&mchdev_lock); |
| 5187 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5188 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5189 | |
| 5190 | /* Prevent division-by-zero if we are asking too fast. |
| 5191 | * Also, we don't get interesting results if we are polling |
| 5192 | * faster than once in 10ms, so just return the saved value |
| 5193 | * in such cases. |
| 5194 | */ |
| 5195 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5196 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5197 | |
| 5198 | count1 = I915_READ(DMIEC); |
| 5199 | count2 = I915_READ(DDREC); |
| 5200 | count3 = I915_READ(CSIEC); |
| 5201 | |
| 5202 | total_count = count1 + count2 + count3; |
| 5203 | |
| 5204 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5205 | if (total_count < dev_priv->ips.last_count1) { |
| 5206 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5207 | diff += total_count; |
| 5208 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5209 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5213 | if (cparams[i].i == dev_priv->ips.c_m && |
| 5214 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5215 | m = cparams[i].m; |
| 5216 | c = cparams[i].c; |
| 5217 | break; |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | diff = div_u64(diff, diff1); |
| 5222 | ret = ((m * diff) + c); |
| 5223 | ret = div_u64(ret, 10); |
| 5224 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5225 | dev_priv->ips.last_count1 = total_count; |
| 5226 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5227 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5228 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5229 | |
| 5230 | return ret; |
| 5231 | } |
| 5232 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5233 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5234 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5235 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5236 | unsigned long val; |
| 5237 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5238 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5239 | return 0; |
| 5240 | |
| 5241 | spin_lock_irq(&mchdev_lock); |
| 5242 | |
| 5243 | val = __i915_chipset_val(dev_priv); |
| 5244 | |
| 5245 | spin_unlock_irq(&mchdev_lock); |
| 5246 | |
| 5247 | return val; |
| 5248 | } |
| 5249 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5250 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5251 | { |
| 5252 | unsigned long m, x, b; |
| 5253 | u32 tsfs; |
| 5254 | |
| 5255 | tsfs = I915_READ(TSFS); |
| 5256 | |
| 5257 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5258 | x = I915_READ8(TR1); |
| 5259 | |
| 5260 | b = tsfs & TSFS_INTR_MASK; |
| 5261 | |
| 5262 | return ((m * x) / 127) - b; |
| 5263 | } |
| 5264 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5265 | static int _pxvid_to_vd(u8 pxvid) |
| 5266 | { |
| 5267 | if (pxvid == 0) |
| 5268 | return 0; |
| 5269 | |
| 5270 | if (pxvid >= 8 && pxvid < 31) |
| 5271 | pxvid = 31; |
| 5272 | |
| 5273 | return (pxvid + 2) * 125; |
| 5274 | } |
| 5275 | |
| 5276 | static u32 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5277 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5278 | struct drm_device *dev = dev_priv->dev; |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5279 | const int vd = _pxvid_to_vd(pxvid); |
| 5280 | const int vm = vd - 1125; |
| 5281 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5282 | if (INTEL_INFO(dev)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5283 | return vm > 0 ? vm : 0; |
| 5284 | |
| 5285 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5286 | } |
| 5287 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5288 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5289 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5290 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5291 | u32 count; |
| 5292 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5293 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5294 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5295 | now = ktime_get_raw_ns(); |
| 5296 | diffms = now - dev_priv->ips.last_time2; |
| 5297 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5298 | |
| 5299 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5300 | if (!diffms) |
| 5301 | return; |
| 5302 | |
| 5303 | count = I915_READ(GFXEC); |
| 5304 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5305 | if (count < dev_priv->ips.last_count2) { |
| 5306 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5307 | diff += count; |
| 5308 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5309 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5310 | } |
| 5311 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5312 | dev_priv->ips.last_count2 = count; |
| 5313 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5314 | |
| 5315 | /* More magic constants... */ |
| 5316 | diff = diff * 1181; |
| 5317 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5318 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5319 | } |
| 5320 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5321 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5322 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5323 | struct drm_device *dev = dev_priv->dev; |
| 5324 | |
| 5325 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5326 | return; |
| 5327 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5328 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5329 | |
| 5330 | __i915_update_gfx_val(dev_priv); |
| 5331 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5332 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5333 | } |
| 5334 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5335 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5336 | { |
| 5337 | unsigned long t, corr, state1, corr2, state2; |
| 5338 | u32 pxvid, ext_v; |
| 5339 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5340 | assert_spin_locked(&mchdev_lock); |
| 5341 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5342 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5343 | pxvid = (pxvid >> 24) & 0x7f; |
| 5344 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5345 | |
| 5346 | state1 = ext_v; |
| 5347 | |
| 5348 | t = i915_mch_val(dev_priv); |
| 5349 | |
| 5350 | /* Revel in the empirically derived constants */ |
| 5351 | |
| 5352 | /* Correction factor in 1/100000 units */ |
| 5353 | if (t > 80) |
| 5354 | corr = ((t * 2349) + 135940); |
| 5355 | else if (t >= 50) |
| 5356 | corr = ((t * 964) + 29317); |
| 5357 | else /* < 50 */ |
| 5358 | corr = ((t * 301) + 1004); |
| 5359 | |
| 5360 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5361 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5362 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5363 | |
| 5364 | state2 = (corr2 * state1) / 10000; |
| 5365 | state2 /= 100; /* convert to mW */ |
| 5366 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5367 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5368 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5369 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5370 | } |
| 5371 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5372 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5373 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5374 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5375 | unsigned long val; |
| 5376 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5377 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5378 | return 0; |
| 5379 | |
| 5380 | spin_lock_irq(&mchdev_lock); |
| 5381 | |
| 5382 | val = __i915_gfx_val(dev_priv); |
| 5383 | |
| 5384 | spin_unlock_irq(&mchdev_lock); |
| 5385 | |
| 5386 | return val; |
| 5387 | } |
| 5388 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5389 | /** |
| 5390 | * i915_read_mch_val - return value for IPS use |
| 5391 | * |
| 5392 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5393 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5394 | */ |
| 5395 | unsigned long i915_read_mch_val(void) |
| 5396 | { |
| 5397 | struct drm_i915_private *dev_priv; |
| 5398 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5399 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5400 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5401 | if (!i915_mch_dev) |
| 5402 | goto out_unlock; |
| 5403 | dev_priv = i915_mch_dev; |
| 5404 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5405 | chipset_val = __i915_chipset_val(dev_priv); |
| 5406 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5407 | |
| 5408 | ret = chipset_val + graphics_val; |
| 5409 | |
| 5410 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5411 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5412 | |
| 5413 | return ret; |
| 5414 | } |
| 5415 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5416 | |
| 5417 | /** |
| 5418 | * i915_gpu_raise - raise GPU frequency limit |
| 5419 | * |
| 5420 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5421 | */ |
| 5422 | bool i915_gpu_raise(void) |
| 5423 | { |
| 5424 | struct drm_i915_private *dev_priv; |
| 5425 | bool ret = true; |
| 5426 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5427 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5428 | if (!i915_mch_dev) { |
| 5429 | ret = false; |
| 5430 | goto out_unlock; |
| 5431 | } |
| 5432 | dev_priv = i915_mch_dev; |
| 5433 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5434 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5435 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5436 | |
| 5437 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5438 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5439 | |
| 5440 | return ret; |
| 5441 | } |
| 5442 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5443 | |
| 5444 | /** |
| 5445 | * i915_gpu_lower - lower GPU frequency limit |
| 5446 | * |
| 5447 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5448 | * frequency maximum. |
| 5449 | */ |
| 5450 | bool i915_gpu_lower(void) |
| 5451 | { |
| 5452 | struct drm_i915_private *dev_priv; |
| 5453 | bool ret = true; |
| 5454 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5455 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5456 | if (!i915_mch_dev) { |
| 5457 | ret = false; |
| 5458 | goto out_unlock; |
| 5459 | } |
| 5460 | dev_priv = i915_mch_dev; |
| 5461 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5462 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5463 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5464 | |
| 5465 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5466 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5467 | |
| 5468 | return ret; |
| 5469 | } |
| 5470 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5471 | |
| 5472 | /** |
| 5473 | * i915_gpu_busy - indicate GPU business to IPS |
| 5474 | * |
| 5475 | * Tell the IPS driver whether or not the GPU is busy. |
| 5476 | */ |
| 5477 | bool i915_gpu_busy(void) |
| 5478 | { |
| 5479 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5480 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5481 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5482 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5483 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5484 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5485 | if (!i915_mch_dev) |
| 5486 | goto out_unlock; |
| 5487 | dev_priv = i915_mch_dev; |
| 5488 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5489 | for_each_ring(ring, dev_priv, i) |
| 5490 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5491 | |
| 5492 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5493 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5494 | |
| 5495 | return ret; |
| 5496 | } |
| 5497 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5498 | |
| 5499 | /** |
| 5500 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5501 | * |
| 5502 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5503 | * current frequency to the default. |
| 5504 | */ |
| 5505 | bool i915_gpu_turbo_disable(void) |
| 5506 | { |
| 5507 | struct drm_i915_private *dev_priv; |
| 5508 | bool ret = true; |
| 5509 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5510 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5511 | if (!i915_mch_dev) { |
| 5512 | ret = false; |
| 5513 | goto out_unlock; |
| 5514 | } |
| 5515 | dev_priv = i915_mch_dev; |
| 5516 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5517 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5518 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5519 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5520 | ret = false; |
| 5521 | |
| 5522 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5523 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5524 | |
| 5525 | return ret; |
| 5526 | } |
| 5527 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5528 | |
| 5529 | /** |
| 5530 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5531 | * IPS got loaded first. |
| 5532 | * |
| 5533 | * This awkward dance is so that neither module has to depend on the |
| 5534 | * other in order for IPS to do the appropriate communication of |
| 5535 | * GPU turbo limits to i915. |
| 5536 | */ |
| 5537 | static void |
| 5538 | ips_ping_for_i915_load(void) |
| 5539 | { |
| 5540 | void (*link)(void); |
| 5541 | |
| 5542 | link = symbol_get(ips_link_to_i915_driver); |
| 5543 | if (link) { |
| 5544 | link(); |
| 5545 | symbol_put(ips_link_to_i915_driver); |
| 5546 | } |
| 5547 | } |
| 5548 | |
| 5549 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5550 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5551 | /* We only register the i915 ips part with intel-ips once everything is |
| 5552 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5553 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5554 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5555 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5556 | |
| 5557 | ips_ping_for_i915_load(); |
| 5558 | } |
| 5559 | |
| 5560 | void intel_gpu_ips_teardown(void) |
| 5561 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5562 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5563 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5564 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5565 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5566 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5567 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5568 | { |
| 5569 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5570 | u32 lcfuse; |
| 5571 | u8 pxw[16]; |
| 5572 | int i; |
| 5573 | |
| 5574 | /* Disable to program */ |
| 5575 | I915_WRITE(ECR, 0); |
| 5576 | POSTING_READ(ECR); |
| 5577 | |
| 5578 | /* Program energy weights for various events */ |
| 5579 | I915_WRITE(SDEW, 0x15040d00); |
| 5580 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5581 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5582 | I915_WRITE(CSIEW2, 0x04000004); |
| 5583 | |
| 5584 | for (i = 0; i < 5; i++) |
| 5585 | I915_WRITE(PEW + (i * 4), 0); |
| 5586 | for (i = 0; i < 3; i++) |
| 5587 | I915_WRITE(DEW + (i * 4), 0); |
| 5588 | |
| 5589 | /* Program P-state weights to account for frequency power adjustment */ |
| 5590 | for (i = 0; i < 16; i++) { |
| 5591 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5592 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5593 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5594 | PXVFREQ_PX_SHIFT; |
| 5595 | unsigned long val; |
| 5596 | |
| 5597 | val = vid * vid; |
| 5598 | val *= (freq / 1000); |
| 5599 | val *= 255; |
| 5600 | val /= (127*127*900); |
| 5601 | if (val > 0xff) |
| 5602 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5603 | pxw[i] = val; |
| 5604 | } |
| 5605 | /* Render standby states get 0 weight */ |
| 5606 | pxw[14] = 0; |
| 5607 | pxw[15] = 0; |
| 5608 | |
| 5609 | for (i = 0; i < 4; i++) { |
| 5610 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5611 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5612 | I915_WRITE(PXW + (i * 4), val); |
| 5613 | } |
| 5614 | |
| 5615 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5616 | I915_WRITE(OGW0, 0); |
| 5617 | I915_WRITE(OGW1, 0); |
| 5618 | I915_WRITE(EG0, 0x00007f00); |
| 5619 | I915_WRITE(EG1, 0x0000000e); |
| 5620 | I915_WRITE(EG2, 0x000e0000); |
| 5621 | I915_WRITE(EG3, 0x68000300); |
| 5622 | I915_WRITE(EG4, 0x42000000); |
| 5623 | I915_WRITE(EG5, 0x00140031); |
| 5624 | I915_WRITE(EG6, 0); |
| 5625 | I915_WRITE(EG7, 0); |
| 5626 | |
| 5627 | for (i = 0; i < 8; i++) |
| 5628 | I915_WRITE(PXWL + (i * 4), 0); |
| 5629 | |
| 5630 | /* Enable PMON + select events */ |
| 5631 | I915_WRITE(ECR, 0x80000019); |
| 5632 | |
| 5633 | lcfuse = I915_READ(LCFUSE02); |
| 5634 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5635 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5636 | } |
| 5637 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5638 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5639 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5640 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5641 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5642 | if (IS_CHERRYVIEW(dev)) |
| 5643 | cherryview_init_gt_powersave(dev); |
| 5644 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5645 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5646 | } |
| 5647 | |
| 5648 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5649 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5650 | if (IS_CHERRYVIEW(dev)) |
| 5651 | return; |
| 5652 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5653 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5654 | } |
| 5655 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5656 | static void gen6_suspend_rps(struct drm_device *dev) |
| 5657 | { |
| 5658 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5659 | |
| 5660 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5661 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5662 | gen6_disable_rps_interrupts(dev); |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5663 | } |
| 5664 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5665 | /** |
| 5666 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5667 | * @dev: drm device |
| 5668 | * |
| 5669 | * We don't want to disable RC6 or other features here, we just want |
| 5670 | * to make sure any work we've queued has finished and won't bother |
| 5671 | * us while we're suspended. |
| 5672 | */ |
| 5673 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5674 | { |
| 5675 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5676 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 5677 | if (INTEL_INFO(dev)->gen < 6) |
| 5678 | return; |
| 5679 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5680 | gen6_suspend_rps(dev); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5681 | |
| 5682 | /* Force GPU to min freq during suspend */ |
| 5683 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5686 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5687 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5688 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5689 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5690 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5691 | ironlake_disable_drps(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5692 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5693 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5694 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5695 | mutex_lock(&dev_priv->rps.hw_lock); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5696 | if (INTEL_INFO(dev)->gen >= 9) |
| 5697 | gen9_disable_rps(dev); |
| 5698 | else if (IS_CHERRYVIEW(dev)) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5699 | cherryview_disable_rps(dev); |
| 5700 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5701 | valleyview_disable_rps(dev); |
| 5702 | else |
| 5703 | gen6_disable_rps(dev); |
Imre Deak | e534770 | 2014-11-19 15:30:02 +0200 | [diff] [blame] | 5704 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5705 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5706 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5707 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5708 | } |
| 5709 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5710 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5711 | { |
| 5712 | struct drm_i915_private *dev_priv = |
| 5713 | container_of(work, struct drm_i915_private, |
| 5714 | rps.delayed_resume_work.work); |
| 5715 | struct drm_device *dev = dev_priv->dev; |
| 5716 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5717 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5718 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5719 | gen6_reset_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5720 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5721 | if (IS_CHERRYVIEW(dev)) { |
| 5722 | cherryview_enable_rps(dev); |
| 5723 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5724 | valleyview_enable_rps(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5725 | } else if (INTEL_INFO(dev)->gen >= 9) { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5726 | gen9_enable_rc6(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5727 | gen9_enable_rps(dev); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5728 | __gen6_update_ring_freq(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5729 | } else if (IS_BROADWELL(dev)) { |
| 5730 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5731 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5732 | } else { |
| 5733 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5734 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5735 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5736 | |
| 5737 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 5738 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 5739 | |
| 5740 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 5741 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 5742 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5743 | dev_priv->rps.enabled = true; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5744 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5745 | gen6_enable_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5746 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5747 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5748 | |
| 5749 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5750 | } |
| 5751 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5752 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5753 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5754 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5755 | |
Yu Zhang | f61018b | 2015-02-10 19:05:52 +0800 | [diff] [blame] | 5756 | /* Powersaving is controlled by the host when inside a VM */ |
| 5757 | if (intel_vgpu_active(dev)) |
| 5758 | return; |
| 5759 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5760 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5761 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5762 | ironlake_enable_drps(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5763 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5764 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5765 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5766 | /* |
| 5767 | * PCU communication is slow and this doesn't need to be |
| 5768 | * done at any specific time, so do this out of our fast path |
| 5769 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5770 | * |
| 5771 | * We depend on the HW RC6 power context save/restore |
| 5772 | * mechanism when entering D3 through runtime PM suspend. So |
| 5773 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5774 | * get here via the driver load/system resume/runtime resume |
| 5775 | * paths, so the _noresume version is enough (and in case of |
| 5776 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5777 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5778 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5779 | round_jiffies_up_relative(HZ))) |
| 5780 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5781 | } |
| 5782 | } |
| 5783 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5784 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5785 | { |
| 5786 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5787 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5788 | if (INTEL_INFO(dev)->gen < 6) |
| 5789 | return; |
| 5790 | |
| 5791 | gen6_suspend_rps(dev); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5792 | dev_priv->rps.enabled = false; |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5793 | } |
| 5794 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5795 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5796 | { |
| 5797 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5798 | |
| 5799 | /* |
| 5800 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5801 | * gating for the panel power sequencer or it will fail to |
| 5802 | * start up when no ports are active. |
| 5803 | */ |
| 5804 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5805 | } |
| 5806 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5807 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5808 | { |
| 5809 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5810 | int pipe; |
| 5811 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5812 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5813 | I915_WRITE(DSPCNTR(pipe), |
| 5814 | I915_READ(DSPCNTR(pipe)) | |
| 5815 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5816 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5817 | } |
| 5818 | } |
| 5819 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5820 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5821 | { |
| 5822 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5823 | |
| 5824 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5825 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5826 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5827 | |
| 5828 | /* |
| 5829 | * Don't touch WM1S_LP_EN here. |
| 5830 | * Doing so could cause underruns. |
| 5831 | */ |
| 5832 | } |
| 5833 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5834 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5835 | { |
| 5836 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5837 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5838 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5839 | /* |
| 5840 | * Required for FBC |
| 5841 | * WaFbcDisableDpfcClockGating:ilk |
| 5842 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5843 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5844 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5845 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5846 | |
| 5847 | I915_WRITE(PCH_3DCGDIS0, |
| 5848 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5849 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5850 | I915_WRITE(PCH_3DCGDIS1, |
| 5851 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5852 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5853 | /* |
| 5854 | * According to the spec the following bits should be set in |
| 5855 | * order to enable memory self-refresh |
| 5856 | * The bit 22/21 of 0x42004 |
| 5857 | * The bit 5 of 0x42020 |
| 5858 | * The bit 15 of 0x45000 |
| 5859 | */ |
| 5860 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5861 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5862 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5863 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5864 | I915_WRITE(DISP_ARB_CTL, |
| 5865 | (I915_READ(DISP_ARB_CTL) | |
| 5866 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5867 | |
| 5868 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5869 | |
| 5870 | /* |
| 5871 | * Based on the document from hardware guys the following bits |
| 5872 | * should be set unconditionally in order to enable FBC. |
| 5873 | * The bit 22 of 0x42000 |
| 5874 | * The bit 22 of 0x42004 |
| 5875 | * The bit 7,8,9 of 0x42020. |
| 5876 | */ |
| 5877 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5878 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5879 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5880 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5881 | ILK_FBCQ_DIS); |
| 5882 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5883 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5884 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5885 | } |
| 5886 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5887 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5888 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5889 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5890 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5891 | ILK_ELPIN_409_SELECT); |
| 5892 | I915_WRITE(_3D_CHICKEN2, |
| 5893 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5894 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5895 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5896 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5897 | I915_WRITE(CACHE_MODE_0, |
| 5898 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5899 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5900 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5901 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5902 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5903 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5904 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5905 | ibx_init_clock_gating(dev); |
| 5906 | } |
| 5907 | |
| 5908 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5909 | { |
| 5910 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5911 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5912 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5913 | |
| 5914 | /* |
| 5915 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5916 | * gating for the panel power sequencer or it will fail to |
| 5917 | * start up when no ports are active. |
| 5918 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5919 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5920 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5921 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5922 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5923 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5924 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5925 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5926 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5927 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5928 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5929 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5930 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5931 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5932 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5933 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5934 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5935 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5936 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5937 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5938 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5939 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5940 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5941 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5942 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5943 | } |
| 5944 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5945 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5946 | { |
| 5947 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5948 | uint32_t tmp; |
| 5949 | |
| 5950 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5951 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5952 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5953 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5956 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5957 | { |
| 5958 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5959 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5960 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5961 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5962 | |
| 5963 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5964 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5965 | ILK_ELPIN_409_SELECT); |
| 5966 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5967 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5968 | I915_WRITE(_3D_CHICKEN, |
| 5969 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5970 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5971 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5972 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5973 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5974 | /* |
| 5975 | * BSpec recoomends 8x4 when MSAA is used, |
| 5976 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5977 | * |
| 5978 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5979 | * disable bit, which we don't touch here, but it's good |
| 5980 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5981 | */ |
| 5982 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 5983 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5984 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5985 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5986 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5987 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5988 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5989 | |
| 5990 | I915_WRITE(GEN6_UCGCTL1, |
| 5991 | I915_READ(GEN6_UCGCTL1) | |
| 5992 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 5993 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 5994 | |
| 5995 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 5996 | * gating disable must be set. Failure to set it results in |
| 5997 | * flickering pixels due to Z write ordering failures after |
| 5998 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 5999 | * Sanctuary and Tropics, and apparently anything else with |
| 6000 | * alpha test or pixel discard. |
| 6001 | * |
| 6002 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 6003 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6004 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 6005 | * WaDisableRCCUnitClockGating:snb |
| 6006 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6007 | */ |
| 6008 | I915_WRITE(GEN6_UCGCTL2, |
| 6009 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 6010 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 6011 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 6012 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 6013 | I915_WRITE(_3D_CHICKEN3, |
| 6014 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6015 | |
| 6016 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 6017 | * Bspec says: |
| 6018 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 6019 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 6020 | */ |
| 6021 | I915_WRITE(_3D_CHICKEN3, |
| 6022 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 6023 | |
| 6024 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6025 | * According to the spec the following bits should be |
| 6026 | * set in order to enable memory self-refresh and fbc: |
| 6027 | * The bit21 and bit22 of 0x42000 |
| 6028 | * The bit21 and bit22 of 0x42004 |
| 6029 | * The bit5 and bit7 of 0x42020 |
| 6030 | * The bit14 of 0x70180 |
| 6031 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6032 | * |
| 6033 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6034 | */ |
| 6035 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6036 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6037 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6038 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6039 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6040 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6041 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 6042 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 6043 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 6044 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6045 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6046 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 6047 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6048 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6049 | |
| 6050 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 6054 | { |
| 6055 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 6056 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6057 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6058 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6059 | * |
| 6060 | * This actually overrides the dispatch |
| 6061 | * mode for all thread types. |
| 6062 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6063 | reg &= ~GEN7_FF_SCHED_MASK; |
| 6064 | reg |= GEN7_FF_TS_SCHED_HW; |
| 6065 | reg |= GEN7_FF_VS_SCHED_HW; |
| 6066 | reg |= GEN7_FF_DS_SCHED_HW; |
| 6067 | |
| 6068 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 6069 | } |
| 6070 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6071 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 6072 | { |
| 6073 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6074 | |
| 6075 | /* |
| 6076 | * TODO: this bit should only be enabled when really needed, then |
| 6077 | * disabled when not needed anymore in order to save power. |
| 6078 | */ |
| 6079 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 6080 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 6081 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6082 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6083 | |
| 6084 | /* WADPOClockGatingDisable:hsw */ |
| 6085 | I915_WRITE(_TRANSA_CHICKEN1, |
| 6086 | I915_READ(_TRANSA_CHICKEN1) | |
| 6087 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6088 | } |
| 6089 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6090 | static void lpt_suspend_hw(struct drm_device *dev) |
| 6091 | { |
| 6092 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6093 | |
| 6094 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 6095 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 6096 | |
| 6097 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6098 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6099 | } |
| 6100 | } |
| 6101 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6102 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6103 | { |
| 6104 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6105 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6106 | |
| 6107 | I915_WRITE(WM3_LP_ILK, 0); |
| 6108 | I915_WRITE(WM2_LP_ILK, 0); |
| 6109 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6110 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6111 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6112 | 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] | 6113 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6114 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6115 | I915_WRITE(CHICKEN_PAR1_1, |
| 6116 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6117 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6118 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6119 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6120 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6121 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6122 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6123 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6124 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6125 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6126 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6127 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6128 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6129 | ~(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] | 6130 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6131 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6132 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6133 | |
| 6134 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6135 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6136 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6137 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 6138 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6139 | } |
| 6140 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6141 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 6142 | { |
| 6143 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6144 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6145 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6146 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6147 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6148 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6149 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6150 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6151 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6152 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6153 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6154 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6155 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6156 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6157 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6158 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6159 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6160 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6161 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6162 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6163 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6164 | /* enable HiZ Raw Stall Optimization */ |
| 6165 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6166 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6167 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6168 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6169 | I915_WRITE(CACHE_MODE_1, |
| 6170 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6171 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6172 | /* |
| 6173 | * BSpec recommends 8x4 when MSAA is used, |
| 6174 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6175 | * |
| 6176 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6177 | * disable bit, which we don't touch here, but it's good |
| 6178 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6179 | */ |
| 6180 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6181 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6182 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 6183 | /* WaSampleCChickenBitEnable:hsw */ |
| 6184 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 6185 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 6186 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6187 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6188 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6189 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 6190 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 6191 | I915_WRITE(CHICKEN_PAR1_1, |
| 6192 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6193 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6194 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6195 | } |
| 6196 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6197 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6198 | { |
| 6199 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6200 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6201 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6202 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6203 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6204 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6205 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6206 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6207 | I915_WRITE(_3D_CHICKEN3, |
| 6208 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6209 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6210 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6211 | I915_WRITE(IVB_CHICKEN3, |
| 6212 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6213 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6214 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6215 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6216 | if (IS_IVB_GT1(dev)) |
| 6217 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6218 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6219 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6220 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6221 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6222 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6223 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6224 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6225 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6226 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6227 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6228 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6229 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6230 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6231 | GEN7_WA_L3_CHICKEN_MODE); |
| 6232 | if (IS_IVB_GT1(dev)) |
| 6233 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6234 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6235 | else { |
| 6236 | /* must write both registers */ |
| 6237 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6238 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6239 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6240 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6241 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6242 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6243 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6244 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6245 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6246 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6247 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6248 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6249 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6250 | */ |
| 6251 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6252 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6253 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6254 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6255 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6256 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6257 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6258 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6259 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6260 | |
| 6261 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6262 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6263 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6264 | /* enable HiZ Raw Stall Optimization */ |
| 6265 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6266 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6267 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6268 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6269 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6270 | I915_WRITE(CACHE_MODE_1, |
| 6271 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6272 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6273 | /* |
| 6274 | * BSpec recommends 8x4 when MSAA is used, |
| 6275 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6276 | * |
| 6277 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6278 | * disable bit, which we don't touch here, but it's good |
| 6279 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6280 | */ |
| 6281 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6282 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6283 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6284 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6285 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6286 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6287 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6288 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6289 | if (!HAS_PCH_NOP(dev)) |
| 6290 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6291 | |
| 6292 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6293 | } |
| 6294 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6295 | static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv) |
| 6296 | { |
| 6297 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6298 | |
| 6299 | /* |
| 6300 | * Disable trickle feed and enable pnd deadline calculation |
| 6301 | */ |
| 6302 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
| 6303 | I915_WRITE(CBR1_VLV, 0); |
| 6304 | } |
| 6305 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6306 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6307 | { |
| 6308 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6309 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6310 | vlv_init_display_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6311 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6312 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6313 | I915_WRITE(_3D_CHICKEN3, |
| 6314 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6315 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6316 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6317 | I915_WRITE(IVB_CHICKEN3, |
| 6318 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6319 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6320 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6321 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6322 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6323 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6324 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6325 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6326 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6327 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6328 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6329 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6330 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6331 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6332 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6333 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6334 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6335 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6336 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6337 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6338 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6339 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6340 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6341 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6342 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6343 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6344 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6345 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6346 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6347 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6348 | */ |
| 6349 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6350 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6351 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6352 | /* WaDisableL3Bank2xClockGate:vlv |
| 6353 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6354 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6355 | I915_WRITE(GEN7_UCGCTL4, |
| 6356 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6357 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6358 | /* |
| 6359 | * BSpec says this must be set, even though |
| 6360 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6361 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6362 | I915_WRITE(CACHE_MODE_1, |
| 6363 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6364 | |
| 6365 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6366 | * BSpec recommends 8x4 when MSAA is used, |
| 6367 | * however in practice 16x4 seems fastest. |
| 6368 | * |
| 6369 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6370 | * disable bit, which we don't touch here, but it's good |
| 6371 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6372 | */ |
| 6373 | I915_WRITE(GEN7_GT_MODE, |
| 6374 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6375 | |
| 6376 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6377 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6378 | * This is the hardware default actually. |
| 6379 | */ |
| 6380 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6381 | |
| 6382 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6383 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6384 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6385 | * in the reporting of vblank events. |
| 6386 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6387 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6388 | } |
| 6389 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6390 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6391 | { |
| 6392 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6393 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6394 | vlv_init_display_clock_gating(dev_priv); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6395 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6396 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6397 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6398 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6399 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6400 | ~(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] | 6401 | |
| 6402 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6403 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6404 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6405 | |
| 6406 | /* WaDisableCSUnitClockGating:chv */ |
| 6407 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6408 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6409 | |
| 6410 | /* WaDisableSDEUnitClockGating:chv */ |
| 6411 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6412 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6413 | } |
| 6414 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6415 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6416 | { |
| 6417 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6418 | uint32_t dspclk_gate; |
| 6419 | |
| 6420 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6421 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6422 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6423 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6424 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6425 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6426 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6427 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6428 | if (IS_GM45(dev)) |
| 6429 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6430 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6431 | |
| 6432 | /* WaDisableRenderCachePipelinedFlush */ |
| 6433 | I915_WRITE(CACHE_MODE_0, |
| 6434 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6435 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6436 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6437 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6438 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6439 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6440 | } |
| 6441 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6442 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6443 | { |
| 6444 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6445 | |
| 6446 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6447 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6448 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6449 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6450 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6451 | I915_WRITE(MI_ARB_STATE, |
| 6452 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6453 | |
| 6454 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6455 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6456 | } |
| 6457 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6458 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6459 | { |
| 6460 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6461 | |
| 6462 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6463 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6464 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6465 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6466 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6467 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6468 | I915_WRITE(MI_ARB_STATE, |
| 6469 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6470 | |
| 6471 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6472 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6473 | } |
| 6474 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6475 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6476 | { |
| 6477 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6478 | u32 dstate = I915_READ(D_STATE); |
| 6479 | |
| 6480 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6481 | DSTATE_DOT_CLOCK_GATING; |
| 6482 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6483 | |
| 6484 | if (IS_PINEVIEW(dev)) |
| 6485 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6486 | |
| 6487 | /* IIR "flip pending" means done if this bit is set */ |
| 6488 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6489 | |
| 6490 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6491 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6492 | |
| 6493 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6494 | 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] | 6495 | |
| 6496 | I915_WRITE(MI_ARB_STATE, |
| 6497 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6498 | } |
| 6499 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6500 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6501 | { |
| 6502 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6503 | |
| 6504 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6505 | |
| 6506 | /* interrupts should cause a wake up from C3 */ |
| 6507 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6508 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6509 | |
| 6510 | I915_WRITE(MEM_MODE, |
| 6511 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6512 | } |
| 6513 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6514 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6515 | { |
| 6516 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6517 | |
| 6518 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6519 | |
| 6520 | I915_WRITE(MEM_MODE, |
| 6521 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6522 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6523 | } |
| 6524 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6525 | void intel_init_clock_gating(struct drm_device *dev) |
| 6526 | { |
| 6527 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6528 | |
Damien Lespiau | c57e355 | 2015-02-09 19:33:05 +0000 | [diff] [blame] | 6529 | if (dev_priv->display.init_clock_gating) |
| 6530 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6531 | } |
| 6532 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6533 | void intel_suspend_hw(struct drm_device *dev) |
| 6534 | { |
| 6535 | if (HAS_PCH_LPT(dev)) |
| 6536 | lpt_suspend_hw(dev); |
| 6537 | } |
| 6538 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6539 | /* Set up chip specific power management-related functions */ |
| 6540 | void intel_init_pm(struct drm_device *dev) |
| 6541 | { |
| 6542 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6543 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6544 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6545 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6546 | /* For cxsr */ |
| 6547 | if (IS_PINEVIEW(dev)) |
| 6548 | i915_pineview_get_mem_freq(dev); |
| 6549 | else if (IS_GEN5(dev)) |
| 6550 | i915_ironlake_get_mem_freq(dev); |
| 6551 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6552 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 6553 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6554 | skl_setup_wm_latency(dev); |
| 6555 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame^] | 6556 | if (IS_BROXTON(dev)) |
| 6557 | dev_priv->display.init_clock_gating = |
| 6558 | bxt_init_clock_gating; |
| 6559 | else if (IS_SKYLAKE(dev)) |
| 6560 | dev_priv->display.init_clock_gating = |
| 6561 | skl_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6562 | dev_priv->display.update_wm = skl_update_wm; |
| 6563 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6564 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6565 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6566 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6567 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6568 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6569 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6570 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6571 | dev_priv->display.update_wm = ilk_update_wm; |
| 6572 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6573 | } else { |
| 6574 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6575 | "Disable CxSR\n"); |
| 6576 | } |
| 6577 | |
| 6578 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6579 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6580 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6581 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6582 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6583 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6584 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6585 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6586 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6587 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6588 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 6589 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6590 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6591 | dev_priv->display.init_clock_gating = |
| 6592 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6593 | } else if (IS_VALLEYVIEW(dev)) { |
| 6594 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6595 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6596 | dev_priv->display.init_clock_gating = |
| 6597 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6598 | } else if (IS_PINEVIEW(dev)) { |
| 6599 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6600 | dev_priv->is_ddr3, |
| 6601 | dev_priv->fsb_freq, |
| 6602 | dev_priv->mem_freq)) { |
| 6603 | DRM_INFO("failed to find known CxSR latency " |
| 6604 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6605 | "disabling CxSR\n", |
| 6606 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6607 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6608 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6609 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6610 | dev_priv->display.update_wm = NULL; |
| 6611 | } else |
| 6612 | dev_priv->display.update_wm = pineview_update_wm; |
| 6613 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6614 | } else if (IS_G4X(dev)) { |
| 6615 | dev_priv->display.update_wm = g4x_update_wm; |
| 6616 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6617 | } else if (IS_GEN4(dev)) { |
| 6618 | dev_priv->display.update_wm = i965_update_wm; |
| 6619 | if (IS_CRESTLINE(dev)) |
| 6620 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6621 | else if (IS_BROADWATER(dev)) |
| 6622 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6623 | } else if (IS_GEN3(dev)) { |
| 6624 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6625 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6626 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6627 | } else if (IS_GEN2(dev)) { |
| 6628 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6629 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6630 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6631 | } else { |
| 6632 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6633 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6634 | } |
| 6635 | |
| 6636 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6637 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6638 | else |
| 6639 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6640 | } else { |
| 6641 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6642 | } |
| 6643 | } |
| 6644 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6645 | int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6646 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6647 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6648 | |
| 6649 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6650 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6651 | return -EAGAIN; |
| 6652 | } |
| 6653 | |
| 6654 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Damien Lespiau | dddab34 | 2014-11-13 17:51:50 +0000 | [diff] [blame] | 6655 | I915_WRITE(GEN6_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6656 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6657 | |
| 6658 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6659 | 500)) { |
| 6660 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6661 | return -ETIMEDOUT; |
| 6662 | } |
| 6663 | |
| 6664 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6665 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6666 | |
| 6667 | return 0; |
| 6668 | } |
| 6669 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6670 | int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6671 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6672 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6673 | |
| 6674 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6675 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6676 | return -EAGAIN; |
| 6677 | } |
| 6678 | |
| 6679 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6680 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6681 | |
| 6682 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6683 | 500)) { |
| 6684 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6685 | return -ETIMEDOUT; |
| 6686 | } |
| 6687 | |
| 6688 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6689 | |
| 6690 | return 0; |
| 6691 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6692 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6693 | static int vlv_gpu_freq_div(unsigned int czclk_freq) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6694 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6695 | switch (czclk_freq) { |
| 6696 | case 200: |
| 6697 | return 10; |
| 6698 | case 267: |
| 6699 | return 12; |
| 6700 | case 320: |
| 6701 | case 333: |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6702 | return 16; |
Ville Syrjälä | ab3fb15 | 2014-11-10 22:55:15 +0200 | [diff] [blame] | 6703 | case 400: |
| 6704 | return 20; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6705 | default: |
| 6706 | return -1; |
| 6707 | } |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6708 | } |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6709 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6710 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6711 | { |
| 6712 | int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
| 6713 | |
| 6714 | div = vlv_gpu_freq_div(czclk_freq); |
| 6715 | if (div < 0) |
| 6716 | return div; |
| 6717 | |
| 6718 | return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6719 | } |
| 6720 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6721 | 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] | 6722 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6723 | int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6724 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6725 | mul = vlv_gpu_freq_div(czclk_freq); |
| 6726 | if (mul < 0) |
| 6727 | return mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6728 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6729 | return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6730 | } |
| 6731 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6732 | 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] | 6733 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6734 | int div, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6735 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6736 | div = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6737 | if (div < 0) |
| 6738 | return div; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6739 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6740 | return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6741 | } |
| 6742 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6743 | 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] | 6744 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6745 | int mul, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6746 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6747 | mul = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6748 | if (mul < 0) |
| 6749 | return mul; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6750 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6751 | /* CHV needs even values */ |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6752 | return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6753 | } |
| 6754 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6755 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6756 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6757 | if (IS_GEN9(dev_priv->dev)) |
| 6758 | return (val * GT_FREQUENCY_MULTIPLIER) / GEN9_FREQ_SCALER; |
| 6759 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6760 | return chv_gpu_freq(dev_priv, val); |
| 6761 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 6762 | return byt_gpu_freq(dev_priv, val); |
| 6763 | else |
| 6764 | return val * GT_FREQUENCY_MULTIPLIER; |
| 6765 | } |
| 6766 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6767 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 6768 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6769 | if (IS_GEN9(dev_priv->dev)) |
| 6770 | return (val * GEN9_FREQ_SCALER) / GT_FREQUENCY_MULTIPLIER; |
| 6771 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6772 | return chv_freq_opcode(dev_priv, val); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6773 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6774 | return byt_freq_opcode(dev_priv, val); |
| 6775 | else |
| 6776 | return val / GT_FREQUENCY_MULTIPLIER; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6777 | } |
| 6778 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6779 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6780 | { |
| 6781 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6782 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6783 | mutex_init(&dev_priv->rps.hw_lock); |
| 6784 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6785 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6786 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6787 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6788 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6789 | } |