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 | { |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame^] | 99 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 100 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 101 | gen9_init_clock_gating(dev); |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame^] | 102 | |
| 103 | /* |
| 104 | * FIXME: |
| 105 | * GEN8_SDEUNIT_CLOCK_GATE_DISABLE applies on A0 only. |
| 106 | */ |
| 107 | /* WaDisableSDEUnitClockGating:bxt */ |
| 108 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 109 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 110 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 113 | static void i915_pineview_get_mem_freq(struct drm_device *dev) |
| 114 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 115 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 116 | u32 tmp; |
| 117 | |
| 118 | tmp = I915_READ(CLKCFG); |
| 119 | |
| 120 | switch (tmp & CLKCFG_FSB_MASK) { |
| 121 | case CLKCFG_FSB_533: |
| 122 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 123 | break; |
| 124 | case CLKCFG_FSB_800: |
| 125 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 126 | break; |
| 127 | case CLKCFG_FSB_667: |
| 128 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 129 | break; |
| 130 | case CLKCFG_FSB_400: |
| 131 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | switch (tmp & CLKCFG_MEM_MASK) { |
| 136 | case CLKCFG_MEM_533: |
| 137 | dev_priv->mem_freq = 533; |
| 138 | break; |
| 139 | case CLKCFG_MEM_667: |
| 140 | dev_priv->mem_freq = 667; |
| 141 | break; |
| 142 | case CLKCFG_MEM_800: |
| 143 | dev_priv->mem_freq = 800; |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | /* detect pineview DDR3 setting */ |
| 148 | tmp = I915_READ(CSHRDDR3CTL); |
| 149 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 150 | } |
| 151 | |
| 152 | static void i915_ironlake_get_mem_freq(struct drm_device *dev) |
| 153 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 154 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 155 | u16 ddrpll, csipll; |
| 156 | |
| 157 | ddrpll = I915_READ16(DDRMPLL1); |
| 158 | csipll = I915_READ16(CSIPLL0); |
| 159 | |
| 160 | switch (ddrpll & 0xff) { |
| 161 | case 0xc: |
| 162 | dev_priv->mem_freq = 800; |
| 163 | break; |
| 164 | case 0x10: |
| 165 | dev_priv->mem_freq = 1066; |
| 166 | break; |
| 167 | case 0x14: |
| 168 | dev_priv->mem_freq = 1333; |
| 169 | break; |
| 170 | case 0x18: |
| 171 | dev_priv->mem_freq = 1600; |
| 172 | break; |
| 173 | default: |
| 174 | DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n", |
| 175 | ddrpll & 0xff); |
| 176 | dev_priv->mem_freq = 0; |
| 177 | break; |
| 178 | } |
| 179 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 180 | dev_priv->ips.r_t = dev_priv->mem_freq; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 181 | |
| 182 | switch (csipll & 0x3ff) { |
| 183 | case 0x00c: |
| 184 | dev_priv->fsb_freq = 3200; |
| 185 | break; |
| 186 | case 0x00e: |
| 187 | dev_priv->fsb_freq = 3733; |
| 188 | break; |
| 189 | case 0x010: |
| 190 | dev_priv->fsb_freq = 4266; |
| 191 | break; |
| 192 | case 0x012: |
| 193 | dev_priv->fsb_freq = 4800; |
| 194 | break; |
| 195 | case 0x014: |
| 196 | dev_priv->fsb_freq = 5333; |
| 197 | break; |
| 198 | case 0x016: |
| 199 | dev_priv->fsb_freq = 5866; |
| 200 | break; |
| 201 | case 0x018: |
| 202 | dev_priv->fsb_freq = 6400; |
| 203 | break; |
| 204 | default: |
| 205 | DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n", |
| 206 | csipll & 0x3ff); |
| 207 | dev_priv->fsb_freq = 0; |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | if (dev_priv->fsb_freq == 3200) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 212 | dev_priv->ips.c_m = 0; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 213 | } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 214 | dev_priv->ips.c_m = 1; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 215 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 216 | dev_priv->ips.c_m = 2; |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 220 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 221 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 222 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 223 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 224 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 225 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 226 | |
| 227 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 228 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 229 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 230 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 231 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 232 | |
| 233 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 234 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 235 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 236 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 237 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 238 | |
| 239 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 240 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 241 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 242 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 243 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 244 | |
| 245 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 246 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 247 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 248 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 249 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 250 | |
| 251 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 252 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 253 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 254 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 255 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 256 | }; |
| 257 | |
Daniel Vetter | 63c6227 | 2012-04-21 23:17:55 +0200 | [diff] [blame] | 258 | static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 259 | int is_ddr3, |
| 260 | int fsb, |
| 261 | int mem) |
| 262 | { |
| 263 | const struct cxsr_latency *latency; |
| 264 | int i; |
| 265 | |
| 266 | if (fsb == 0 || mem == 0) |
| 267 | return NULL; |
| 268 | |
| 269 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 270 | latency = &cxsr_latency_table[i]; |
| 271 | if (is_desktop == latency->is_desktop && |
| 272 | is_ddr3 == latency->is_ddr3 && |
| 273 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 274 | return latency; |
| 275 | } |
| 276 | |
| 277 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 278 | |
| 279 | return NULL; |
| 280 | } |
| 281 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 282 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 283 | { |
| 284 | u32 val; |
| 285 | |
| 286 | mutex_lock(&dev_priv->rps.hw_lock); |
| 287 | |
| 288 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 289 | if (enable) |
| 290 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 291 | else |
| 292 | val |= FORCE_DDR_HIGH_FREQ; |
| 293 | val &= ~FORCE_DDR_LOW_FREQ; |
| 294 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 295 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 296 | |
| 297 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 298 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
| 299 | DRM_ERROR("timed out waiting for Punit DDR DVFS request\n"); |
| 300 | |
| 301 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 302 | } |
| 303 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 304 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 305 | { |
| 306 | u32 val; |
| 307 | |
| 308 | mutex_lock(&dev_priv->rps.hw_lock); |
| 309 | |
| 310 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 311 | if (enable) |
| 312 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 313 | else |
| 314 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
| 315 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 316 | |
| 317 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 318 | } |
| 319 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 320 | #define FW_WM(value, plane) \ |
| 321 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 322 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 323 | 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] | 324 | { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 325 | struct drm_device *dev = dev_priv->dev; |
| 326 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 327 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 328 | if (IS_VALLEYVIEW(dev)) { |
| 329 | I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 330 | if (IS_CHERRYVIEW(dev)) |
| 331 | chv_set_memory_pm5(dev_priv, enable); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 332 | } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) { |
| 333 | I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 334 | } else if (IS_PINEVIEW(dev)) { |
| 335 | val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN; |
| 336 | val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0; |
| 337 | I915_WRITE(DSPFW3, val); |
| 338 | } else if (IS_I945G(dev) || IS_I945GM(dev)) { |
| 339 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 340 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
| 341 | I915_WRITE(FW_BLC_SELF, val); |
| 342 | } else if (IS_I915GM(dev)) { |
| 343 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 344 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
| 345 | I915_WRITE(INSTPM, val); |
| 346 | } else { |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | DRM_DEBUG_KMS("memory self-refresh is %s\n", |
| 351 | enable ? "enabled" : "disabled"); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 352 | } |
| 353 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 354 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 355 | /* |
| 356 | * Latency for FIFO fetches is dependent on several factors: |
| 357 | * - memory configuration (speed, channels) |
| 358 | * - chipset |
| 359 | * - current MCH state |
| 360 | * It can be fairly high in some situations, so here we assume a fairly |
| 361 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 362 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 363 | * and power consumption (set it too low to save power and we might see |
| 364 | * FIFO underruns and display "flicker"). |
| 365 | * |
| 366 | * A value of 5us seems to be a good balance; safe for very low end |
| 367 | * platforms but not overly aggressive on lower latency configs. |
| 368 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 369 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 370 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 371 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 372 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 373 | |
| 374 | static int vlv_get_fifo_size(struct drm_device *dev, |
| 375 | enum pipe pipe, int plane) |
| 376 | { |
| 377 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 378 | int sprite0_start, sprite1_start, size; |
| 379 | |
| 380 | switch (pipe) { |
| 381 | uint32_t dsparb, dsparb2, dsparb3; |
| 382 | case PIPE_A: |
| 383 | dsparb = I915_READ(DSPARB); |
| 384 | dsparb2 = I915_READ(DSPARB2); |
| 385 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 386 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 387 | break; |
| 388 | case PIPE_B: |
| 389 | dsparb = I915_READ(DSPARB); |
| 390 | dsparb2 = I915_READ(DSPARB2); |
| 391 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 392 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 393 | break; |
| 394 | case PIPE_C: |
| 395 | dsparb2 = I915_READ(DSPARB2); |
| 396 | dsparb3 = I915_READ(DSPARB3); |
| 397 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 398 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 399 | break; |
| 400 | default: |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | switch (plane) { |
| 405 | case 0: |
| 406 | size = sprite0_start; |
| 407 | break; |
| 408 | case 1: |
| 409 | size = sprite1_start - sprite0_start; |
| 410 | break; |
| 411 | case 2: |
| 412 | size = 512 - 1 - sprite1_start; |
| 413 | break; |
| 414 | default: |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | DRM_DEBUG_KMS("Pipe %c %s %c FIFO size: %d\n", |
| 419 | pipe_name(pipe), plane == 0 ? "primary" : "sprite", |
| 420 | plane == 0 ? plane_name(pipe) : sprite_name(pipe, plane - 1), |
| 421 | size); |
| 422 | |
| 423 | return size; |
| 424 | } |
| 425 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 426 | static int i9xx_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 427 | { |
| 428 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 429 | uint32_t dsparb = I915_READ(DSPARB); |
| 430 | int size; |
| 431 | |
| 432 | size = dsparb & 0x7f; |
| 433 | if (plane) |
| 434 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 435 | |
| 436 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 437 | plane ? "B" : "A", size); |
| 438 | |
| 439 | return size; |
| 440 | } |
| 441 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 442 | static int i830_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 443 | { |
| 444 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 445 | uint32_t dsparb = I915_READ(DSPARB); |
| 446 | int size; |
| 447 | |
| 448 | size = dsparb & 0x1ff; |
| 449 | if (plane) |
| 450 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 451 | size >>= 1; /* Convert to cachelines */ |
| 452 | |
| 453 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 454 | plane ? "B" : "A", size); |
| 455 | |
| 456 | return size; |
| 457 | } |
| 458 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 459 | static int i845_get_fifo_size(struct drm_device *dev, int plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 460 | { |
| 461 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 462 | uint32_t dsparb = I915_READ(DSPARB); |
| 463 | int size; |
| 464 | |
| 465 | size = dsparb & 0x7f; |
| 466 | size >>= 2; /* Convert to cachelines */ |
| 467 | |
| 468 | DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb, |
| 469 | plane ? "B" : "A", |
| 470 | size); |
| 471 | |
| 472 | return size; |
| 473 | } |
| 474 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 475 | /* Pineview has different values for various configs */ |
| 476 | static const struct intel_watermark_params pineview_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 477 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 478 | .max_wm = PINEVIEW_MAX_WM, |
| 479 | .default_wm = PINEVIEW_DFT_WM, |
| 480 | .guard_size = PINEVIEW_GUARD_WM, |
| 481 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 482 | }; |
| 483 | static const struct intel_watermark_params pineview_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 484 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 485 | .max_wm = PINEVIEW_MAX_WM, |
| 486 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 487 | .guard_size = PINEVIEW_GUARD_WM, |
| 488 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 489 | }; |
| 490 | static const struct intel_watermark_params pineview_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 491 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 492 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 493 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 494 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 495 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 496 | }; |
| 497 | static const struct intel_watermark_params pineview_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 498 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 499 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 500 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 501 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 502 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 503 | }; |
| 504 | static const struct intel_watermark_params g4x_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 505 | .fifo_size = G4X_FIFO_SIZE, |
| 506 | .max_wm = G4X_MAX_WM, |
| 507 | .default_wm = G4X_MAX_WM, |
| 508 | .guard_size = 2, |
| 509 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 510 | }; |
| 511 | static const struct intel_watermark_params g4x_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 512 | .fifo_size = I965_CURSOR_FIFO, |
| 513 | .max_wm = I965_CURSOR_MAX_WM, |
| 514 | .default_wm = I965_CURSOR_DFT_WM, |
| 515 | .guard_size = 2, |
| 516 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 517 | }; |
| 518 | static const struct intel_watermark_params valleyview_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 519 | .fifo_size = VALLEYVIEW_FIFO_SIZE, |
| 520 | .max_wm = VALLEYVIEW_MAX_WM, |
| 521 | .default_wm = VALLEYVIEW_MAX_WM, |
| 522 | .guard_size = 2, |
| 523 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 524 | }; |
| 525 | static const struct intel_watermark_params valleyview_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 526 | .fifo_size = I965_CURSOR_FIFO, |
| 527 | .max_wm = VALLEYVIEW_CURSOR_MAX_WM, |
| 528 | .default_wm = I965_CURSOR_DFT_WM, |
| 529 | .guard_size = 2, |
| 530 | .cacheline_size = G4X_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 531 | }; |
| 532 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 533 | .fifo_size = I965_CURSOR_FIFO, |
| 534 | .max_wm = I965_CURSOR_MAX_WM, |
| 535 | .default_wm = I965_CURSOR_DFT_WM, |
| 536 | .guard_size = 2, |
| 537 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 538 | }; |
| 539 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 540 | .fifo_size = I945_FIFO_SIZE, |
| 541 | .max_wm = I915_MAX_WM, |
| 542 | .default_wm = 1, |
| 543 | .guard_size = 2, |
| 544 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | }; |
| 546 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 547 | .fifo_size = I915_FIFO_SIZE, |
| 548 | .max_wm = I915_MAX_WM, |
| 549 | .default_wm = 1, |
| 550 | .guard_size = 2, |
| 551 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 552 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 553 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 554 | .fifo_size = I855GM_FIFO_SIZE, |
| 555 | .max_wm = I915_MAX_WM, |
| 556 | .default_wm = 1, |
| 557 | .guard_size = 2, |
| 558 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 559 | }; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 560 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 561 | .fifo_size = I855GM_FIFO_SIZE, |
| 562 | .max_wm = I915_MAX_WM/2, |
| 563 | .default_wm = 1, |
| 564 | .guard_size = 2, |
| 565 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 566 | }; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 567 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 568 | .fifo_size = I830_FIFO_SIZE, |
| 569 | .max_wm = I915_MAX_WM, |
| 570 | .default_wm = 1, |
| 571 | .guard_size = 2, |
| 572 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 573 | }; |
| 574 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 575 | /** |
| 576 | * intel_calculate_wm - calculate watermark level |
| 577 | * @clock_in_khz: pixel clock |
| 578 | * @wm: chip FIFO params |
| 579 | * @pixel_size: display pixel size |
| 580 | * @latency_ns: memory latency for the platform |
| 581 | * |
| 582 | * Calculate the watermark level (the level at which the display plane will |
| 583 | * start fetching from memory again). Each chip has a different display |
| 584 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 585 | * in the correct intel_watermark_params structure. |
| 586 | * |
| 587 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 588 | * on the pixel size. When it reaches the watermark level, it'll start |
| 589 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 590 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 591 | * will occur, and a display engine hang could result. |
| 592 | */ |
| 593 | static unsigned long intel_calculate_wm(unsigned long clock_in_khz, |
| 594 | const struct intel_watermark_params *wm, |
| 595 | int fifo_size, |
| 596 | int pixel_size, |
| 597 | unsigned long latency_ns) |
| 598 | { |
| 599 | long entries_required, wm_size; |
| 600 | |
| 601 | /* |
| 602 | * Note: we need to make sure we don't overflow for various clock & |
| 603 | * latency values. |
| 604 | * clocks go from a few thousand to several hundred thousand. |
| 605 | * latency is usually a few thousand |
| 606 | */ |
| 607 | entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) / |
| 608 | 1000; |
| 609 | entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size); |
| 610 | |
| 611 | DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required); |
| 612 | |
| 613 | wm_size = fifo_size - (entries_required + wm->guard_size); |
| 614 | |
| 615 | DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size); |
| 616 | |
| 617 | /* Don't promote wm_size to unsigned... */ |
| 618 | if (wm_size > (long)wm->max_wm) |
| 619 | wm_size = wm->max_wm; |
| 620 | if (wm_size <= 0) |
| 621 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 622 | |
| 623 | /* |
| 624 | * Bspec seems to indicate that the value shouldn't be lower than |
| 625 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 626 | * Lets go for 8 which is the burst size since certain platforms |
| 627 | * already use a hardcoded 8 (which is what the spec says should be |
| 628 | * done). |
| 629 | */ |
| 630 | if (wm_size <= 8) |
| 631 | wm_size = 8; |
| 632 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 633 | return wm_size; |
| 634 | } |
| 635 | |
| 636 | static struct drm_crtc *single_enabled_crtc(struct drm_device *dev) |
| 637 | { |
| 638 | struct drm_crtc *crtc, *enabled = NULL; |
| 639 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 640 | for_each_crtc(dev, crtc) { |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 641 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 642 | if (enabled) |
| 643 | return NULL; |
| 644 | enabled = crtc; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | return enabled; |
| 649 | } |
| 650 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 651 | static void pineview_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 652 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 653 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 654 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 655 | struct drm_crtc *crtc; |
| 656 | const struct cxsr_latency *latency; |
| 657 | u32 reg; |
| 658 | unsigned long wm; |
| 659 | |
| 660 | latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3, |
| 661 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 662 | if (!latency) { |
| 663 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 664 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 665 | return; |
| 666 | } |
| 667 | |
| 668 | crtc = single_enabled_crtc(dev); |
| 669 | if (crtc) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 670 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 671 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 672 | int clock; |
| 673 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 674 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 675 | clock = adjusted_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 676 | |
| 677 | /* Display SR */ |
| 678 | wm = intel_calculate_wm(clock, &pineview_display_wm, |
| 679 | pineview_display_wm.fifo_size, |
| 680 | pixel_size, latency->display_sr); |
| 681 | reg = I915_READ(DSPFW1); |
| 682 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 683 | reg |= FW_WM(wm, SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 684 | I915_WRITE(DSPFW1, reg); |
| 685 | DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); |
| 686 | |
| 687 | /* cursor SR */ |
| 688 | wm = intel_calculate_wm(clock, &pineview_cursor_wm, |
| 689 | pineview_display_wm.fifo_size, |
| 690 | pixel_size, latency->cursor_sr); |
| 691 | reg = I915_READ(DSPFW3); |
| 692 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 693 | reg |= FW_WM(wm, CURSOR_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 694 | I915_WRITE(DSPFW3, reg); |
| 695 | |
| 696 | /* Display HPLL off SR */ |
| 697 | wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, |
| 698 | pineview_display_hplloff_wm.fifo_size, |
| 699 | pixel_size, latency->display_hpll_disable); |
| 700 | reg = I915_READ(DSPFW3); |
| 701 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 702 | reg |= FW_WM(wm, HPLL_SR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 703 | I915_WRITE(DSPFW3, reg); |
| 704 | |
| 705 | /* cursor HPLL off SR */ |
| 706 | wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, |
| 707 | pineview_display_hplloff_wm.fifo_size, |
| 708 | pixel_size, latency->cursor_hpll_disable); |
| 709 | reg = I915_READ(DSPFW3); |
| 710 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 711 | reg |= FW_WM(wm, HPLL_CURSOR); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 712 | I915_WRITE(DSPFW3, reg); |
| 713 | DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); |
| 714 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 715 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 716 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 717 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | static bool g4x_compute_wm0(struct drm_device *dev, |
| 722 | int plane, |
| 723 | const struct intel_watermark_params *display, |
| 724 | int display_latency_ns, |
| 725 | const struct intel_watermark_params *cursor, |
| 726 | int cursor_latency_ns, |
| 727 | int *plane_wm, |
| 728 | int *cursor_wm) |
| 729 | { |
| 730 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 731 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 732 | int htotal, hdisplay, clock, pixel_size; |
| 733 | int line_time_us, line_count; |
| 734 | int entries, tlb_miss; |
| 735 | |
| 736 | crtc = intel_get_crtc_for_plane(dev, plane); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 737 | if (!intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 738 | *cursor_wm = cursor->guard_size; |
| 739 | *plane_wm = display->guard_size; |
| 740 | return false; |
| 741 | } |
| 742 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 743 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 744 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 745 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 746 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 747 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 748 | |
| 749 | /* Use the small buffer method to calculate plane watermark */ |
| 750 | entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000; |
| 751 | tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8; |
| 752 | if (tlb_miss > 0) |
| 753 | entries += tlb_miss; |
| 754 | entries = DIV_ROUND_UP(entries, display->cacheline_size); |
| 755 | *plane_wm = entries + display->guard_size; |
| 756 | if (*plane_wm > (int)display->max_wm) |
| 757 | *plane_wm = display->max_wm; |
| 758 | |
| 759 | /* Use the large buffer method to calculate cursor watermark */ |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 760 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 761 | line_count = (cursor_latency_ns / line_time_us + 1000) / 1000; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 762 | entries = line_count * crtc->cursor->state->crtc_w * pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 763 | tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8; |
| 764 | if (tlb_miss > 0) |
| 765 | entries += tlb_miss; |
| 766 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 767 | *cursor_wm = entries + cursor->guard_size; |
| 768 | if (*cursor_wm > (int)cursor->max_wm) |
| 769 | *cursor_wm = (int)cursor->max_wm; |
| 770 | |
| 771 | return true; |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Check the wm result. |
| 776 | * |
| 777 | * If any calculated watermark values is larger than the maximum value that |
| 778 | * can be programmed into the associated watermark register, that watermark |
| 779 | * must be disabled. |
| 780 | */ |
| 781 | static bool g4x_check_srwm(struct drm_device *dev, |
| 782 | int display_wm, int cursor_wm, |
| 783 | const struct intel_watermark_params *display, |
| 784 | const struct intel_watermark_params *cursor) |
| 785 | { |
| 786 | DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n", |
| 787 | display_wm, cursor_wm); |
| 788 | |
| 789 | if (display_wm > display->max_wm) { |
| 790 | DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n", |
| 791 | display_wm, display->max_wm); |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | if (cursor_wm > cursor->max_wm) { |
| 796 | DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n", |
| 797 | cursor_wm, cursor->max_wm); |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | if (!(display_wm || cursor_wm)) { |
| 802 | DRM_DEBUG_KMS("SR latency is 0, disabling\n"); |
| 803 | return false; |
| 804 | } |
| 805 | |
| 806 | return true; |
| 807 | } |
| 808 | |
| 809 | static bool g4x_compute_srwm(struct drm_device *dev, |
| 810 | int plane, |
| 811 | int latency_ns, |
| 812 | const struct intel_watermark_params *display, |
| 813 | const struct intel_watermark_params *cursor, |
| 814 | int *display_wm, int *cursor_wm) |
| 815 | { |
| 816 | struct drm_crtc *crtc; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 817 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 818 | int hdisplay, htotal, pixel_size, clock; |
| 819 | unsigned long line_time_us; |
| 820 | int line_count, line_size; |
| 821 | int small, large; |
| 822 | int entries; |
| 823 | |
| 824 | if (!latency_ns) { |
| 825 | *display_wm = *cursor_wm = 0; |
| 826 | return false; |
| 827 | } |
| 828 | |
| 829 | crtc = intel_get_crtc_for_plane(dev, plane); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 830 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 831 | clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 832 | htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 833 | hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 834 | pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 835 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 836 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 837 | line_count = (latency_ns / line_time_us + 1000) / 1000; |
| 838 | line_size = hdisplay * pixel_size; |
| 839 | |
| 840 | /* Use the minimum of the small and large buffer method for primary */ |
| 841 | small = ((clock * pixel_size / 1000) * latency_ns) / 1000; |
| 842 | large = line_count * line_size; |
| 843 | |
| 844 | entries = DIV_ROUND_UP(min(small, large), display->cacheline_size); |
| 845 | *display_wm = entries + display->guard_size; |
| 846 | |
| 847 | /* calculate the self-refresh watermark for display cursor */ |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 848 | entries = line_count * pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 849 | entries = DIV_ROUND_UP(entries, cursor->cacheline_size); |
| 850 | *cursor_wm = entries + cursor->guard_size; |
| 851 | |
| 852 | return g4x_check_srwm(dev, |
| 853 | *display_wm, *cursor_wm, |
| 854 | display, cursor); |
| 855 | } |
| 856 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 857 | #define FW_WM_VLV(value, plane) \ |
| 858 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 859 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 860 | static void vlv_write_wm_values(struct intel_crtc *crtc, |
| 861 | const struct vlv_wm_values *wm) |
| 862 | { |
| 863 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 864 | enum pipe pipe = crtc->pipe; |
| 865 | |
| 866 | I915_WRITE(VLV_DDL(pipe), |
| 867 | (wm->ddl[pipe].cursor << DDL_CURSOR_SHIFT) | |
| 868 | (wm->ddl[pipe].sprite[1] << DDL_SPRITE_SHIFT(1)) | |
| 869 | (wm->ddl[pipe].sprite[0] << DDL_SPRITE_SHIFT(0)) | |
| 870 | (wm->ddl[pipe].primary << DDL_PLANE_SHIFT)); |
| 871 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 872 | I915_WRITE(DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 873 | FW_WM(wm->sr.plane, SR) | |
| 874 | FW_WM(wm->pipe[PIPE_B].cursor, CURSORB) | |
| 875 | FW_WM_VLV(wm->pipe[PIPE_B].primary, PLANEB) | |
| 876 | FW_WM_VLV(wm->pipe[PIPE_A].primary, PLANEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 877 | I915_WRITE(DSPFW2, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 878 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[1], SPRITEB) | |
| 879 | FW_WM(wm->pipe[PIPE_A].cursor, CURSORA) | |
| 880 | FW_WM_VLV(wm->pipe[PIPE_A].sprite[0], SPRITEA)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 881 | I915_WRITE(DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 882 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 883 | |
| 884 | if (IS_CHERRYVIEW(dev_priv)) { |
| 885 | I915_WRITE(DSPFW7_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 886 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 887 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 888 | I915_WRITE(DSPFW8_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 889 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[1], SPRITEF) | |
| 890 | FW_WM_VLV(wm->pipe[PIPE_C].sprite[0], SPRITEE)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 891 | I915_WRITE(DSPFW9_CHV, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 892 | FW_WM_VLV(wm->pipe[PIPE_C].primary, PLANEC) | |
| 893 | FW_WM(wm->pipe[PIPE_C].cursor, CURSORC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 894 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 895 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 896 | FW_WM(wm->pipe[PIPE_C].sprite[1] >> 8, SPRITEF_HI) | |
| 897 | FW_WM(wm->pipe[PIPE_C].sprite[0] >> 8, SPRITEE_HI) | |
| 898 | FW_WM(wm->pipe[PIPE_C].primary >> 8, PLANEC_HI) | |
| 899 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 900 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 901 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 902 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 903 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 904 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 905 | } else { |
| 906 | I915_WRITE(DSPFW7, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 907 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) | |
| 908 | FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 909 | I915_WRITE(DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 910 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
| 911 | FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) | |
| 912 | FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) | |
| 913 | FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) | |
| 914 | FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) | |
| 915 | FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) | |
| 916 | FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | POSTING_READ(DSPFW1); |
| 920 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 921 | dev_priv->wm.vlv = *wm; |
| 922 | } |
| 923 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 924 | #undef FW_WM_VLV |
| 925 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 926 | static uint8_t vlv_compute_drain_latency(struct drm_crtc *crtc, |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 927 | struct drm_plane *plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 928 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 929 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 930 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 931 | int entries, prec_mult, drain_latency, pixel_size; |
| 932 | int clock = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 933 | const int high_precision = IS_CHERRYVIEW(dev) ? 16 : 64; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 934 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 935 | /* |
| 936 | * FIXME the plane might have an fb |
| 937 | * but be invisible (eg. due to clipping) |
| 938 | */ |
| 939 | if (!intel_crtc->active || !plane->state->fb) |
| 940 | return 0; |
| 941 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 942 | if (WARN(clock == 0, "Pixel clock is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 943 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 944 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 945 | pixel_size = drm_format_plane_cpp(plane->state->fb->pixel_format, 0); |
| 946 | |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 947 | if (WARN(pixel_size == 0, "Pixel size is zero!\n")) |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 948 | return 0; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 949 | |
Gajanan Bhat | a398e9c | 2014-08-05 23:15:54 +0530 | [diff] [blame] | 950 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 951 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 952 | prec_mult = high_precision; |
| 953 | drain_latency = 64 * prec_mult * 4 / entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 954 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 955 | if (drain_latency > DRAIN_LATENCY_MASK) { |
| 956 | prec_mult /= 2; |
| 957 | drain_latency = 64 * prec_mult * 4 / entries; |
Ville Syrjälä | abfc00b | 2015-03-05 21:19:43 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 960 | if (drain_latency > DRAIN_LATENCY_MASK) |
| 961 | drain_latency = DRAIN_LATENCY_MASK; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 962 | |
Ville Syrjälä | 341c526 | 2015-03-05 21:19:44 +0200 | [diff] [blame] | 963 | return drain_latency | (prec_mult == high_precision ? |
| 964 | DDL_PRECISION_HIGH : DDL_PRECISION_LOW); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 965 | } |
| 966 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 967 | static int vlv_compute_wm(struct intel_crtc *crtc, |
| 968 | struct intel_plane *plane, |
| 969 | int fifo_size) |
| 970 | { |
| 971 | int clock, entries, pixel_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 972 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 973 | /* |
| 974 | * FIXME the plane might have an fb |
| 975 | * but be invisible (eg. due to clipping) |
| 976 | */ |
| 977 | if (!crtc->active || !plane->base.state->fb) |
| 978 | return 0; |
| 979 | |
| 980 | pixel_size = drm_format_plane_cpp(plane->base.state->fb->pixel_format, 0); |
| 981 | clock = crtc->config->base.adjusted_mode.crtc_clock; |
| 982 | |
| 983 | entries = DIV_ROUND_UP(clock, 1000) * pixel_size; |
| 984 | |
| 985 | /* |
| 986 | * Set up the watermark such that we don't start issuing memory |
| 987 | * requests until we are within PND's max deadline value (256us). |
| 988 | * Idea being to be idle as long as possible while still taking |
| 989 | * advatange of PND's deadline scheduling. The limit of 8 |
| 990 | * cachelines (used when the FIFO will anyway drain in less time |
| 991 | * than 256us) should match what we would be done if trickle |
| 992 | * feed were enabled. |
| 993 | */ |
| 994 | return fifo_size - clamp(DIV_ROUND_UP(256 * entries, 64), 0, fifo_size - 8); |
| 995 | } |
| 996 | |
| 997 | static bool vlv_compute_sr_wm(struct drm_device *dev, |
| 998 | struct vlv_wm_values *wm) |
| 999 | { |
| 1000 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 1001 | struct drm_crtc *crtc; |
| 1002 | enum pipe pipe = INVALID_PIPE; |
| 1003 | int num_planes = 0; |
| 1004 | int fifo_size = 0; |
| 1005 | struct intel_plane *plane; |
| 1006 | |
| 1007 | wm->sr.cursor = wm->sr.plane = 0; |
| 1008 | |
| 1009 | crtc = single_enabled_crtc(dev); |
| 1010 | /* maxfifo not supported on pipe C */ |
| 1011 | if (crtc && to_intel_crtc(crtc)->pipe != PIPE_C) { |
| 1012 | pipe = to_intel_crtc(crtc)->pipe; |
| 1013 | num_planes = !!wm->pipe[pipe].primary + |
| 1014 | !!wm->pipe[pipe].sprite[0] + |
| 1015 | !!wm->pipe[pipe].sprite[1]; |
| 1016 | fifo_size = INTEL_INFO(dev_priv)->num_pipes * 512 - 1; |
| 1017 | } |
| 1018 | |
| 1019 | if (fifo_size == 0 || num_planes > 1) |
| 1020 | return false; |
| 1021 | |
| 1022 | wm->sr.cursor = vlv_compute_wm(to_intel_crtc(crtc), |
| 1023 | to_intel_plane(crtc->cursor), 0x3f); |
| 1024 | |
| 1025 | list_for_each_entry(plane, &dev->mode_config.plane_list, base.head) { |
| 1026 | if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 1027 | continue; |
| 1028 | |
| 1029 | if (plane->pipe != pipe) |
| 1030 | continue; |
| 1031 | |
| 1032 | wm->sr.plane = vlv_compute_wm(to_intel_crtc(crtc), |
| 1033 | plane, fifo_size); |
| 1034 | if (wm->sr.plane != 0) |
| 1035 | break; |
| 1036 | } |
| 1037 | |
| 1038 | return true; |
| 1039 | } |
| 1040 | |
| 1041 | static void valleyview_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1042 | { |
Rodrigo Vivi | 5e56ba4 | 2014-10-17 08:05:08 -0700 | [diff] [blame] | 1043 | struct drm_device *dev = crtc->dev; |
| 1044 | struct drm_i915_private *dev_priv = dev->dev_private; |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1045 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1046 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1047 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1048 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1049 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1050 | wm.ddl[pipe].primary = vlv_compute_drain_latency(crtc, crtc->primary); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1051 | wm.pipe[pipe].primary = vlv_compute_wm(intel_crtc, |
| 1052 | to_intel_plane(crtc->primary), |
| 1053 | vlv_get_fifo_size(dev, pipe, 0)); |
| 1054 | |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1055 | wm.ddl[pipe].cursor = vlv_compute_drain_latency(crtc, crtc->cursor); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1056 | wm.pipe[pipe].cursor = vlv_compute_wm(intel_crtc, |
| 1057 | to_intel_plane(crtc->cursor), |
| 1058 | 0x3f); |
| 1059 | |
| 1060 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1061 | |
| 1062 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1063 | return; |
| 1064 | |
| 1065 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: plane=%d, cursor=%d, " |
| 1066 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1067 | wm.pipe[pipe].primary, wm.pipe[pipe].cursor, |
| 1068 | wm.sr.plane, wm.sr.cursor); |
| 1069 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 1070 | /* |
| 1071 | * FIXME DDR DVFS introduces massive memory latencies which |
| 1072 | * are not known to system agent so any deadline specified |
| 1073 | * by the display may not be respected. To support DDR DVFS |
| 1074 | * the watermark code needs to be rewritten to essentially |
| 1075 | * bypass deadline mechanism and rely solely on the |
| 1076 | * watermarks. For now disable DDR DVFS. |
| 1077 | */ |
| 1078 | if (IS_CHERRYVIEW(dev_priv)) |
| 1079 | chv_set_memory_dvfs(dev_priv, false); |
| 1080 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1081 | if (!cxsr_enabled) |
| 1082 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 0948c26 | 2014-08-07 01:58:24 +0530 | [diff] [blame] | 1083 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1084 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 1085 | |
| 1086 | if (cxsr_enabled) |
| 1087 | intel_set_memory_cxsr(dev_priv, true); |
| 1088 | } |
| 1089 | |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1090 | static void valleyview_update_sprite_wm(struct drm_plane *plane, |
| 1091 | struct drm_crtc *crtc, |
| 1092 | uint32_t sprite_width, |
| 1093 | uint32_t sprite_height, |
| 1094 | int pixel_size, |
| 1095 | bool enabled, bool scaled) |
| 1096 | { |
| 1097 | struct drm_device *dev = crtc->dev; |
| 1098 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1099 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1100 | enum pipe pipe = intel_crtc->pipe; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1101 | int sprite = to_intel_plane(plane)->plane; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1102 | bool cxsr_enabled; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1103 | struct vlv_wm_values wm = dev_priv->wm.vlv; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1104 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1105 | if (enabled) { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1106 | wm.ddl[pipe].sprite[sprite] = |
Ville Syrjälä | 883a3d2 | 2015-03-05 21:19:46 +0200 | [diff] [blame] | 1107 | vlv_compute_drain_latency(crtc, plane); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1108 | |
| 1109 | wm.pipe[pipe].sprite[sprite] = |
| 1110 | vlv_compute_wm(intel_crtc, |
| 1111 | to_intel_plane(plane), |
| 1112 | vlv_get_fifo_size(dev, pipe, sprite+1)); |
| 1113 | } else { |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1114 | wm.ddl[pipe].sprite[sprite] = 0; |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1115 | wm.pipe[pipe].sprite[sprite] = 0; |
| 1116 | } |
| 1117 | |
| 1118 | cxsr_enabled = vlv_compute_sr_wm(dev, &wm); |
| 1119 | |
| 1120 | if (memcmp(&wm, &dev_priv->wm.vlv, sizeof(wm)) == 0) |
| 1121 | return; |
| 1122 | |
| 1123 | DRM_DEBUG_KMS("Setting FIFO watermarks - %c: sprite %c=%d, " |
| 1124 | "SR: plane=%d, cursor=%d\n", pipe_name(pipe), |
| 1125 | sprite_name(pipe, sprite), |
| 1126 | wm.pipe[pipe].sprite[sprite], |
| 1127 | wm.sr.plane, wm.sr.cursor); |
| 1128 | |
| 1129 | if (!cxsr_enabled) |
| 1130 | intel_set_memory_cxsr(dev_priv, false); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1131 | |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1132 | vlv_write_wm_values(intel_crtc, &wm); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1133 | |
| 1134 | if (cxsr_enabled) |
| 1135 | intel_set_memory_cxsr(dev_priv, true); |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 1136 | } |
| 1137 | |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1138 | #define single_plane_enabled(mask) is_power_of_2(mask) |
| 1139 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1140 | static void g4x_update_wm(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1141 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1142 | struct drm_device *dev = crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1143 | static const int sr_latency_ns = 12000; |
| 1144 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1145 | int planea_wm, planeb_wm, cursora_wm, cursorb_wm; |
| 1146 | int plane_sr, cursor_sr; |
| 1147 | unsigned int enabled = 0; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1148 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1149 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1150 | if (g4x_compute_wm0(dev, PIPE_A, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1151 | &g4x_wm_info, pessimal_latency_ns, |
| 1152 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1153 | &planea_wm, &cursora_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1154 | enabled |= 1 << PIPE_A; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1155 | |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1156 | if (g4x_compute_wm0(dev, PIPE_B, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1157 | &g4x_wm_info, pessimal_latency_ns, |
| 1158 | &g4x_cursor_wm_info, pessimal_latency_ns, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1159 | &planeb_wm, &cursorb_wm)) |
Ville Syrjälä | 51cea1f | 2013-03-21 13:10:44 +0200 | [diff] [blame] | 1160 | enabled |= 1 << PIPE_B; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1161 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1162 | if (single_plane_enabled(enabled) && |
| 1163 | g4x_compute_srwm(dev, ffs(enabled) - 1, |
| 1164 | sr_latency_ns, |
| 1165 | &g4x_wm_info, |
| 1166 | &g4x_cursor_wm_info, |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1167 | &plane_sr, &cursor_sr)) { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1168 | cxsr_enabled = true; |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1169 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1170 | cxsr_enabled = false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1171 | intel_set_memory_cxsr(dev_priv, false); |
Chris Wilson | 52bd02d | 2012-12-07 10:43:24 +0000 | [diff] [blame] | 1172 | plane_sr = cursor_sr = 0; |
| 1173 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1174 | |
Ville Syrjälä | a504345 | 2014-06-28 02:04:18 +0300 | [diff] [blame] | 1175 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, " |
| 1176 | "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n", |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1177 | planea_wm, cursora_wm, |
| 1178 | planeb_wm, cursorb_wm, |
| 1179 | plane_sr, cursor_sr); |
| 1180 | |
| 1181 | I915_WRITE(DSPFW1, |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1182 | FW_WM(plane_sr, SR) | |
| 1183 | FW_WM(cursorb_wm, CURSORB) | |
| 1184 | FW_WM(planeb_wm, PLANEB) | |
| 1185 | FW_WM(planea_wm, PLANEA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1186 | I915_WRITE(DSPFW2, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1187 | (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1188 | FW_WM(cursora_wm, CURSORA)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1189 | /* HPLL off in SR has some issues on G4x... disable it */ |
| 1190 | I915_WRITE(DSPFW3, |
Chris Wilson | 8c919b2 | 2012-12-04 16:33:19 +0000 | [diff] [blame] | 1191 | (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1192 | FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1193 | |
| 1194 | if (cxsr_enabled) |
| 1195 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1196 | } |
| 1197 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1198 | static void i965_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1199 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1200 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1201 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1202 | struct drm_crtc *crtc; |
| 1203 | int srwm = 1; |
| 1204 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1205 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1206 | |
| 1207 | /* Calc sr entries for one plane configs */ |
| 1208 | crtc = single_enabled_crtc(dev); |
| 1209 | if (crtc) { |
| 1210 | /* self-refresh has much higher latency */ |
| 1211 | static const int sr_latency_ns = 12000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1212 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1213 | &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1214 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1215 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1216 | int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1217 | int pixel_size = crtc->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1218 | unsigned long line_time_us; |
| 1219 | int entries; |
| 1220 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1221 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1222 | |
| 1223 | /* Use ns/us then divide to preserve precision */ |
| 1224 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1225 | pixel_size * hdisplay; |
| 1226 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 1227 | srwm = I965_FIFO_SIZE - entries; |
| 1228 | if (srwm < 0) |
| 1229 | srwm = 1; |
| 1230 | srwm &= 0x1ff; |
| 1231 | DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n", |
| 1232 | entries, srwm); |
| 1233 | |
| 1234 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 1235 | pixel_size * crtc->cursor->state->crtc_w; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1236 | entries = DIV_ROUND_UP(entries, |
| 1237 | i965_cursor_wm_info.cacheline_size); |
| 1238 | cursor_sr = i965_cursor_wm_info.fifo_size - |
| 1239 | (entries + i965_cursor_wm_info.guard_size); |
| 1240 | |
| 1241 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 1242 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 1243 | |
| 1244 | DRM_DEBUG_KMS("self-refresh watermark: display plane %d " |
| 1245 | "cursor %d\n", srwm, cursor_sr); |
| 1246 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1247 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1248 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1249 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1250 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1251 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 1255 | srwm); |
| 1256 | |
| 1257 | /* 965 has limitations... */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1258 | I915_WRITE(DSPFW1, FW_WM(srwm, SR) | |
| 1259 | FW_WM(8, CURSORB) | |
| 1260 | FW_WM(8, PLANEB) | |
| 1261 | FW_WM(8, PLANEA)); |
| 1262 | I915_WRITE(DSPFW2, FW_WM(8, CURSORA) | |
| 1263 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1264 | /* update cursor SR watermark */ |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1265 | I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR)); |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 1266 | |
| 1267 | if (cxsr_enabled) |
| 1268 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1269 | } |
| 1270 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 1271 | #undef FW_WM |
| 1272 | |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1273 | static void i9xx_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1274 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1275 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1277 | const struct intel_watermark_params *wm_info; |
| 1278 | uint32_t fwater_lo; |
| 1279 | uint32_t fwater_hi; |
| 1280 | int cwm, srwm = 1; |
| 1281 | int fifo_size; |
| 1282 | int planea_wm, planeb_wm; |
| 1283 | struct drm_crtc *crtc, *enabled = NULL; |
| 1284 | |
| 1285 | if (IS_I945GM(dev)) |
| 1286 | wm_info = &i945_wm_info; |
| 1287 | else if (!IS_GEN2(dev)) |
| 1288 | wm_info = &i915_wm_info; |
| 1289 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1290 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1291 | |
| 1292 | fifo_size = dev_priv->display.get_fifo_size(dev, 0); |
| 1293 | crtc = intel_get_crtc_for_plane(dev, 0); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1294 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1295 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1296 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1297 | if (IS_GEN2(dev)) |
| 1298 | cpp = 4; |
| 1299 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1300 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1301 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1302 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1303 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1304 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1305 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1306 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1307 | if (planea_wm > (long)wm_info->max_wm) |
| 1308 | planea_wm = wm_info->max_wm; |
| 1309 | } |
| 1310 | |
| 1311 | if (IS_GEN2(dev)) |
| 1312 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1313 | |
| 1314 | fifo_size = dev_priv->display.get_fifo_size(dev, 1); |
| 1315 | crtc = intel_get_crtc_for_plane(dev, 1); |
Chris Wilson | 3490ea5 | 2013-01-07 10:11:40 +0000 | [diff] [blame] | 1316 | if (intel_crtc_active(crtc)) { |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1317 | const struct drm_display_mode *adjusted_mode; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1318 | int cpp = crtc->primary->state->fb->bits_per_pixel / 8; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1319 | if (IS_GEN2(dev)) |
| 1320 | cpp = 4; |
| 1321 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1322 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1323 | planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 1324 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1325 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1326 | if (enabled == NULL) |
| 1327 | enabled = crtc; |
| 1328 | else |
| 1329 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1330 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1331 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 1332 | if (planeb_wm > (long)wm_info->max_wm) |
| 1333 | planeb_wm = wm_info->max_wm; |
| 1334 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1335 | |
| 1336 | DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
| 1337 | |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1338 | if (IS_I915GM(dev) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1339 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1340 | |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1341 | obj = intel_fb_obj(enabled->primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1342 | |
| 1343 | /* self-refresh seems busted with untiled */ |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 1344 | if (obj->tiling_mode == I915_TILING_NONE) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 1345 | enabled = NULL; |
| 1346 | } |
| 1347 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1348 | /* |
| 1349 | * Overlay gets an aggressive default since video jitter is bad. |
| 1350 | */ |
| 1351 | cwm = 2; |
| 1352 | |
| 1353 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1354 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1355 | |
| 1356 | /* Calc sr entries for one plane configs */ |
| 1357 | if (HAS_FW_BLC(dev) && enabled) { |
| 1358 | /* self-refresh has much higher latency */ |
| 1359 | static const int sr_latency_ns = 6000; |
Ville Syrjälä | 4fe8590 | 2013-09-04 18:25:22 +0300 | [diff] [blame] | 1360 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1361 | &to_intel_crtc(enabled)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1362 | int clock = adjusted_mode->crtc_clock; |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1363 | int htotal = adjusted_mode->crtc_htotal; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1364 | int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w; |
Matt Roper | 59bea88 | 2015-02-27 10:12:01 -0800 | [diff] [blame] | 1365 | int pixel_size = enabled->primary->state->fb->bits_per_pixel / 8; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1366 | unsigned long line_time_us; |
| 1367 | int entries; |
| 1368 | |
Ville Syrjälä | 922044c | 2014-02-14 14:18:57 +0200 | [diff] [blame] | 1369 | line_time_us = max(htotal * 1000 / clock, 1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1370 | |
| 1371 | /* Use ns/us then divide to preserve precision */ |
| 1372 | entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) * |
| 1373 | pixel_size * hdisplay; |
| 1374 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
| 1375 | DRM_DEBUG_KMS("self-refresh entries: %d\n", entries); |
| 1376 | srwm = wm_info->fifo_size - entries; |
| 1377 | if (srwm < 0) |
| 1378 | srwm = 1; |
| 1379 | |
| 1380 | if (IS_I945G(dev) || IS_I945GM(dev)) |
| 1381 | I915_WRITE(FW_BLC_SELF, |
| 1382 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
| 1383 | else if (IS_I915GM(dev)) |
| 1384 | I915_WRITE(FW_BLC_SELF, srwm & 0x3f); |
| 1385 | } |
| 1386 | |
| 1387 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 1388 | planea_wm, planeb_wm, cwm, srwm); |
| 1389 | |
| 1390 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 1391 | fwater_hi = (cwm & 0x1f); |
| 1392 | |
| 1393 | /* Set request length to 8 cachelines per fetch */ |
| 1394 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 1395 | fwater_hi = fwater_hi | (1 << 8); |
| 1396 | |
| 1397 | I915_WRITE(FW_BLC, fwater_lo); |
| 1398 | I915_WRITE(FW_BLC2, fwater_hi); |
| 1399 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 1400 | if (enabled) |
| 1401 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1402 | } |
| 1403 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1404 | static void i845_update_wm(struct drm_crtc *unused_crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1405 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 1406 | struct drm_device *dev = unused_crtc->dev; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1407 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1408 | struct drm_crtc *crtc; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1409 | const struct drm_display_mode *adjusted_mode; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1410 | uint32_t fwater_lo; |
| 1411 | int planea_wm; |
| 1412 | |
| 1413 | crtc = single_enabled_crtc(dev); |
| 1414 | if (crtc == NULL) |
| 1415 | return; |
| 1416 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1417 | adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1418 | planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 1419 | &i845_wm_info, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1420 | dev_priv->display.get_fifo_size(dev, 0), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 1421 | 4, pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1422 | fwater_lo = I915_READ(FW_BLC) & ~0xfff; |
| 1423 | fwater_lo |= (3<<8) | planea_wm; |
| 1424 | |
| 1425 | DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm); |
| 1426 | |
| 1427 | I915_WRITE(FW_BLC, fwater_lo); |
| 1428 | } |
| 1429 | |
Ville Syrjälä | 3658729 | 2013-07-05 11:57:16 +0300 | [diff] [blame] | 1430 | static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev, |
| 1431 | struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1432 | { |
| 1433 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 1434 | uint32_t pixel_rate; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1435 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1436 | pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1437 | |
| 1438 | /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to |
| 1439 | * adjust the pixel_rate here. */ |
| 1440 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1441 | if (intel_crtc->config->pch_pfit.enabled) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1442 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1443 | uint32_t pfit_size = intel_crtc->config->pch_pfit.size; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1444 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1445 | pipe_w = intel_crtc->config->pipe_src_w; |
| 1446 | pipe_h = intel_crtc->config->pipe_src_h; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1447 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 1448 | pfit_h = pfit_size & 0xFFFF; |
| 1449 | if (pipe_w < pfit_w) |
| 1450 | pipe_w = pfit_w; |
| 1451 | if (pipe_h < pfit_h) |
| 1452 | pipe_h = pfit_h; |
| 1453 | |
| 1454 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 1455 | pfit_w * pfit_h); |
| 1456 | } |
| 1457 | |
| 1458 | return pixel_rate; |
| 1459 | } |
| 1460 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1461 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1462 | 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] | 1463 | uint32_t latency) |
| 1464 | { |
| 1465 | uint64_t ret; |
| 1466 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1467 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1468 | return UINT_MAX; |
| 1469 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1470 | ret = (uint64_t) pixel_rate * bytes_per_pixel * latency; |
| 1471 | ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2; |
| 1472 | |
| 1473 | return ret; |
| 1474 | } |
| 1475 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1476 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1477 | 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] | 1478 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
| 1479 | uint32_t latency) |
| 1480 | { |
| 1481 | uint32_t ret; |
| 1482 | |
Ville Syrjälä | 3312ba6 | 2013-08-01 16:18:53 +0300 | [diff] [blame] | 1483 | if (WARN(latency == 0, "Latency value missing\n")) |
| 1484 | return UINT_MAX; |
| 1485 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1486 | ret = (latency * pixel_rate) / (pipe_htotal * 10000); |
| 1487 | ret = (ret + 1) * horiz_pixels * bytes_per_pixel; |
| 1488 | ret = DIV_ROUND_UP(ret, 64) + 2; |
| 1489 | return ret; |
| 1490 | } |
| 1491 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1492 | 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] | 1493 | uint8_t bytes_per_pixel) |
| 1494 | { |
| 1495 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2; |
| 1496 | } |
| 1497 | |
Pradeep Bhat | 2ac96d2 | 2014-11-04 17:06:40 +0000 | [diff] [blame] | 1498 | struct skl_pipe_wm_parameters { |
| 1499 | bool active; |
| 1500 | uint32_t pipe_htotal; |
| 1501 | uint32_t pixel_rate; /* in KHz */ |
| 1502 | struct intel_plane_wm_parameters plane[I915_MAX_PLANES]; |
| 1503 | struct intel_plane_wm_parameters cursor; |
| 1504 | }; |
| 1505 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1506 | struct ilk_pipe_wm_parameters { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1507 | bool active; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1508 | uint32_t pipe_htotal; |
| 1509 | uint32_t pixel_rate; |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1510 | struct intel_plane_wm_parameters pri; |
| 1511 | struct intel_plane_wm_parameters spr; |
| 1512 | struct intel_plane_wm_parameters cur; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1513 | }; |
| 1514 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1515 | struct ilk_wm_maximums { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1516 | uint16_t pri; |
| 1517 | uint16_t spr; |
| 1518 | uint16_t cur; |
| 1519 | uint16_t fbc; |
| 1520 | }; |
| 1521 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1522 | /* used in computing the new watermarks state */ |
| 1523 | struct intel_wm_config { |
| 1524 | unsigned int num_pipes_active; |
| 1525 | bool sprites_enabled; |
| 1526 | bool sprites_scaled; |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1527 | }; |
| 1528 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1529 | /* |
| 1530 | * For both WM_PIPE and WM_LP. |
| 1531 | * mem_value must be in 0.1us units. |
| 1532 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1533 | 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] | 1534 | uint32_t mem_value, |
| 1535 | bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1536 | { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1537 | uint32_t method1, method2; |
| 1538 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1539 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1540 | return 0; |
| 1541 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1542 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1543 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1544 | mem_value); |
| 1545 | |
| 1546 | if (!is_lp) |
| 1547 | return method1; |
| 1548 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1549 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1550 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1551 | params->pri.horiz_pixels, |
| 1552 | params->pri.bytes_per_pixel, |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1553 | mem_value); |
| 1554 | |
| 1555 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1556 | } |
| 1557 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1558 | /* |
| 1559 | * For both WM_PIPE and WM_LP. |
| 1560 | * mem_value must be in 0.1us units. |
| 1561 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1562 | 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] | 1563 | uint32_t mem_value) |
| 1564 | { |
| 1565 | uint32_t method1, method2; |
| 1566 | |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1567 | if (!params->active || !params->spr.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1568 | return 0; |
| 1569 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1570 | method1 = ilk_wm_method1(params->pixel_rate, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1571 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1572 | mem_value); |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1573 | method2 = ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1574 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1575 | params->spr.horiz_pixels, |
| 1576 | params->spr.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1577 | mem_value); |
| 1578 | return min(method1, method2); |
| 1579 | } |
| 1580 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 1581 | /* |
| 1582 | * For both WM_PIPE and WM_LP. |
| 1583 | * mem_value must be in 0.1us units. |
| 1584 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1585 | 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] | 1586 | uint32_t mem_value) |
| 1587 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1588 | if (!params->active || !params->cur.enabled) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1589 | return 0; |
| 1590 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1591 | return ilk_wm_method2(params->pixel_rate, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1592 | params->pipe_htotal, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1593 | params->cur.horiz_pixels, |
| 1594 | params->cur.bytes_per_pixel, |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1595 | mem_value); |
| 1596 | } |
| 1597 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1598 | /* Only for WM_LP. */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1599 | 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] | 1600 | uint32_t pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1601 | { |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1602 | if (!params->active || !params->pri.enabled) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1603 | return 0; |
| 1604 | |
Ville Syrjälä | 2329704 | 2013-07-05 11:57:17 +0300 | [diff] [blame] | 1605 | return ilk_wm_fbc(pri_val, |
Ville Syrjälä | c35426d | 2013-08-07 13:29:50 +0300 | [diff] [blame] | 1606 | params->pri.horiz_pixels, |
| 1607 | params->pri.bytes_per_pixel); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 1608 | } |
| 1609 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1610 | static unsigned int ilk_display_fifo_size(const struct drm_device *dev) |
| 1611 | { |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 1612 | if (INTEL_INFO(dev)->gen >= 8) |
| 1613 | return 3072; |
| 1614 | else if (INTEL_INFO(dev)->gen >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1615 | return 768; |
| 1616 | else |
| 1617 | return 512; |
| 1618 | } |
| 1619 | |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1620 | static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev, |
| 1621 | int level, bool is_sprite) |
| 1622 | { |
| 1623 | if (INTEL_INFO(dev)->gen >= 8) |
| 1624 | /* BDW primary/sprite plane watermarks */ |
| 1625 | return level == 0 ? 255 : 2047; |
| 1626 | else if (INTEL_INFO(dev)->gen >= 7) |
| 1627 | /* IVB/HSW primary/sprite plane watermarks */ |
| 1628 | return level == 0 ? 127 : 1023; |
| 1629 | else if (!is_sprite) |
| 1630 | /* ILK/SNB primary plane watermarks */ |
| 1631 | return level == 0 ? 127 : 511; |
| 1632 | else |
| 1633 | /* ILK/SNB sprite plane watermarks */ |
| 1634 | return level == 0 ? 63 : 255; |
| 1635 | } |
| 1636 | |
| 1637 | static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev, |
| 1638 | int level) |
| 1639 | { |
| 1640 | if (INTEL_INFO(dev)->gen >= 7) |
| 1641 | return level == 0 ? 63 : 255; |
| 1642 | else |
| 1643 | return level == 0 ? 31 : 63; |
| 1644 | } |
| 1645 | |
| 1646 | static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev) |
| 1647 | { |
| 1648 | if (INTEL_INFO(dev)->gen >= 8) |
| 1649 | return 31; |
| 1650 | else |
| 1651 | return 15; |
| 1652 | } |
| 1653 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1654 | /* Calculate the maximum primary/sprite plane watermark */ |
| 1655 | static unsigned int ilk_plane_wm_max(const struct drm_device *dev, |
| 1656 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1657 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1658 | enum intel_ddb_partitioning ddb_partitioning, |
| 1659 | bool is_sprite) |
| 1660 | { |
| 1661 | unsigned int fifo_size = ilk_display_fifo_size(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1662 | |
| 1663 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1664 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1665 | return 0; |
| 1666 | |
| 1667 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1668 | if (level == 0 || config->num_pipes_active > 1) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1669 | fifo_size /= INTEL_INFO(dev)->num_pipes; |
| 1670 | |
| 1671 | /* |
| 1672 | * For some reason the non self refresh |
| 1673 | * FIFO size is only half of the self |
| 1674 | * refresh FIFO size on ILK/SNB. |
| 1675 | */ |
| 1676 | if (INTEL_INFO(dev)->gen <= 6) |
| 1677 | fifo_size /= 2; |
| 1678 | } |
| 1679 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1680 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1681 | /* level 0 is always calculated with 1:1 split */ |
| 1682 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 1683 | if (is_sprite) |
| 1684 | fifo_size *= 5; |
| 1685 | fifo_size /= 6; |
| 1686 | } else { |
| 1687 | fifo_size /= 2; |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | /* clamp to max that the registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1692 | 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] | 1693 | } |
| 1694 | |
| 1695 | /* Calculate the maximum cursor plane watermark */ |
| 1696 | 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] | 1697 | int level, |
| 1698 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1699 | { |
| 1700 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1701 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1702 | return 64; |
| 1703 | |
| 1704 | /* otherwise just report max that registers can hold */ |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1705 | return ilk_cursor_wm_reg_max(dev, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1706 | } |
| 1707 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1708 | static void ilk_compute_wm_maximums(const struct drm_device *dev, |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 1709 | int level, |
| 1710 | const struct intel_wm_config *config, |
| 1711 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1712 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1713 | { |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 1714 | max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false); |
| 1715 | max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true); |
| 1716 | max->cur = ilk_cursor_wm_max(dev, level, config); |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 1717 | max->fbc = ilk_fbc_wm_reg_max(dev); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 1718 | } |
| 1719 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 1720 | static void ilk_compute_wm_reg_maximums(struct drm_device *dev, |
| 1721 | int level, |
| 1722 | struct ilk_wm_maximums *max) |
| 1723 | { |
| 1724 | max->pri = ilk_plane_wm_reg_max(dev, level, false); |
| 1725 | max->spr = ilk_plane_wm_reg_max(dev, level, true); |
| 1726 | max->cur = ilk_cursor_wm_reg_max(dev, level); |
| 1727 | max->fbc = ilk_fbc_wm_reg_max(dev); |
| 1728 | } |
| 1729 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1730 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1731 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 1732 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1733 | { |
| 1734 | bool ret; |
| 1735 | |
| 1736 | /* already determined to be invalid? */ |
| 1737 | if (!result->enable) |
| 1738 | return false; |
| 1739 | |
| 1740 | result->enable = result->pri_val <= max->pri && |
| 1741 | result->spr_val <= max->spr && |
| 1742 | result->cur_val <= max->cur; |
| 1743 | |
| 1744 | ret = result->enable; |
| 1745 | |
| 1746 | /* |
| 1747 | * HACK until we can pre-compute everything, |
| 1748 | * and thus fail gracefully if LP0 watermarks |
| 1749 | * are exceeded... |
| 1750 | */ |
| 1751 | if (level == 0 && !result->enable) { |
| 1752 | if (result->pri_val > max->pri) |
| 1753 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 1754 | level, result->pri_val, max->pri); |
| 1755 | if (result->spr_val > max->spr) |
| 1756 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 1757 | level, result->spr_val, max->spr); |
| 1758 | if (result->cur_val > max->cur) |
| 1759 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 1760 | level, result->cur_val, max->cur); |
| 1761 | |
| 1762 | result->pri_val = min_t(uint32_t, result->pri_val, max->pri); |
| 1763 | result->spr_val = min_t(uint32_t, result->spr_val, max->spr); |
| 1764 | result->cur_val = min_t(uint32_t, result->cur_val, max->cur); |
| 1765 | result->enable = true; |
| 1766 | } |
| 1767 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 1768 | return ret; |
| 1769 | } |
| 1770 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 1771 | 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] | 1772 | int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 1773 | const struct ilk_pipe_wm_parameters *p, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 1774 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 1775 | { |
| 1776 | uint16_t pri_latency = dev_priv->wm.pri_latency[level]; |
| 1777 | uint16_t spr_latency = dev_priv->wm.spr_latency[level]; |
| 1778 | uint16_t cur_latency = dev_priv->wm.cur_latency[level]; |
| 1779 | |
| 1780 | /* WM1+ latency values stored in 0.5us units */ |
| 1781 | if (level > 0) { |
| 1782 | pri_latency *= 5; |
| 1783 | spr_latency *= 5; |
| 1784 | cur_latency *= 5; |
| 1785 | } |
| 1786 | |
| 1787 | result->pri_val = ilk_compute_pri_wm(p, pri_latency, level); |
| 1788 | result->spr_val = ilk_compute_spr_wm(p, spr_latency); |
| 1789 | result->cur_val = ilk_compute_cur_wm(p, cur_latency); |
| 1790 | result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val); |
| 1791 | result->enable = true; |
| 1792 | } |
| 1793 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1794 | static uint32_t |
| 1795 | hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc) |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1796 | { |
| 1797 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1798 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1799 | struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode; |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1800 | u32 linetime, ips_linetime; |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1801 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 1802 | if (!intel_crtc->active) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1803 | return 0; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 1804 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1805 | /* The WM are computed with base on how long it takes to fill a single |
| 1806 | * row at the given clock rate, multiplied by 8. |
| 1807 | * */ |
Jesse Barnes | fec8cba | 2013-11-27 11:10:26 -0800 | [diff] [blame] | 1808 | linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
| 1809 | mode->crtc_clock); |
| 1810 | ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8, |
Paulo Zanoni | 85a02de | 2013-05-03 17:23:43 -0300 | [diff] [blame] | 1811 | intel_ddi_get_cdclk_freq(dev_priv)); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1812 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 1813 | return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) | |
| 1814 | PIPE_WM_LINETIME_TIME(linetime); |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 1815 | } |
| 1816 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1817 | 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] | 1818 | { |
| 1819 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1820 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1821 | if (IS_GEN9(dev)) { |
| 1822 | uint32_t val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1823 | int ret, i; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1824 | int level, max_level = ilk_wm_max_level(dev); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1825 | |
| 1826 | /* read the first set of memory latencies[0:3] */ |
| 1827 | val = 0; /* data0 to be programmed to 0 for first set */ |
| 1828 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1829 | ret = sandybridge_pcode_read(dev_priv, |
| 1830 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1831 | &val); |
| 1832 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1833 | |
| 1834 | if (ret) { |
| 1835 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1836 | return; |
| 1837 | } |
| 1838 | |
| 1839 | wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1840 | wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1841 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1842 | wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1843 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1844 | wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1845 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1846 | |
| 1847 | /* read the second set of memory latencies[4:7] */ |
| 1848 | val = 1; /* data0 to be programmed to 1 for second set */ |
| 1849 | mutex_lock(&dev_priv->rps.hw_lock); |
| 1850 | ret = sandybridge_pcode_read(dev_priv, |
| 1851 | GEN9_PCODE_READ_MEM_LATENCY, |
| 1852 | &val); |
| 1853 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 1854 | if (ret) { |
| 1855 | DRM_ERROR("SKL Mailbox read error = %d\n", ret); |
| 1856 | return; |
| 1857 | } |
| 1858 | |
| 1859 | wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1860 | wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 1861 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1862 | wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 1863 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1864 | wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 1865 | GEN9_MEM_LATENCY_LEVEL_MASK; |
| 1866 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1867 | /* |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 1868 | * WaWmMemoryReadLatency:skl |
| 1869 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1870 | * punit doesn't take into account the read latency so we need |
| 1871 | * to add 2us to the various latency levels we retrieve from |
| 1872 | * the punit. |
| 1873 | * - W0 is a bit special in that it's the only level that |
| 1874 | * can't be disabled if we want to have display working, so |
| 1875 | * we always add 2us there. |
| 1876 | * - For levels >=1, punit returns 0us latency when they are |
| 1877 | * disabled, so we respect that and don't add 2us then |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1878 | * |
| 1879 | * Additionally, if a level n (n > 1) has a 0us latency, all |
| 1880 | * levels m (m >= n) need to be disabled. We make sure to |
| 1881 | * sanitize the values out of the punit to satisfy this |
| 1882 | * requirement. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1883 | */ |
| 1884 | wm[0] += 2; |
| 1885 | for (level = 1; level <= max_level; level++) |
| 1886 | if (wm[level] != 0) |
| 1887 | wm[level] += 2; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1888 | else { |
| 1889 | for (i = level + 1; i <= max_level; i++) |
| 1890 | wm[i] = 0; |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 1891 | |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 1892 | break; |
| 1893 | } |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1894 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1895 | uint64_t sskpd = I915_READ64(MCH_SSKPD); |
| 1896 | |
| 1897 | wm[0] = (sskpd >> 56) & 0xFF; |
| 1898 | if (wm[0] == 0) |
| 1899 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 1900 | wm[1] = (sskpd >> 4) & 0xFF; |
| 1901 | wm[2] = (sskpd >> 12) & 0xFF; |
| 1902 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 1903 | wm[4] = (sskpd >> 32) & 0x1FF; |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 1904 | } else if (INTEL_INFO(dev)->gen >= 6) { |
| 1905 | uint32_t sskpd = I915_READ(MCH_SSKPD); |
| 1906 | |
| 1907 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 1908 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 1909 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 1910 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 1911 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1912 | uint32_t mltr = I915_READ(MLTR_ILK); |
| 1913 | |
| 1914 | /* ILK primary LP0 latency is 700 ns */ |
| 1915 | wm[0] = 7; |
| 1916 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 1917 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 1921 | static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1922 | { |
| 1923 | /* ILK sprite LP0 latency is 1300 ns */ |
| 1924 | if (INTEL_INFO(dev)->gen == 5) |
| 1925 | wm[0] = 13; |
| 1926 | } |
| 1927 | |
| 1928 | static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5]) |
| 1929 | { |
| 1930 | /* ILK cursor LP0 latency is 1300 ns */ |
| 1931 | if (INTEL_INFO(dev)->gen == 5) |
| 1932 | wm[0] = 13; |
| 1933 | |
| 1934 | /* WaDoubleCursorLP3Latency:ivb */ |
| 1935 | if (IS_IVYBRIDGE(dev)) |
| 1936 | wm[3] *= 2; |
| 1937 | } |
| 1938 | |
Damien Lespiau | 546c81f | 2014-05-13 15:30:26 +0100 | [diff] [blame] | 1939 | int ilk_wm_max_level(const struct drm_device *dev) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1940 | { |
| 1941 | /* how many WM levels are we expecting */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1942 | if (IS_GEN9(dev)) |
| 1943 | return 7; |
| 1944 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1945 | return 4; |
| 1946 | else if (INTEL_INFO(dev)->gen >= 6) |
| 1947 | return 3; |
| 1948 | else |
| 1949 | return 2; |
| 1950 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 1951 | |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1952 | static void intel_print_wm_latency(struct drm_device *dev, |
| 1953 | const char *name, |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1954 | const uint16_t wm[8]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1955 | { |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 1956 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1957 | |
| 1958 | for (level = 0; level <= max_level; level++) { |
| 1959 | unsigned int latency = wm[level]; |
| 1960 | |
| 1961 | if (latency == 0) { |
| 1962 | DRM_ERROR("%s WM%d latency not provided\n", |
| 1963 | name, level); |
| 1964 | continue; |
| 1965 | } |
| 1966 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 1967 | /* |
| 1968 | * - latencies are in us on gen9. |
| 1969 | * - before then, WM1+ latency values are in 0.5us units |
| 1970 | */ |
| 1971 | if (IS_GEN9(dev)) |
| 1972 | latency *= 10; |
| 1973 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 1974 | latency *= 5; |
| 1975 | |
| 1976 | DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n", |
| 1977 | name, level, wm[level], |
| 1978 | latency / 10, latency % 10); |
| 1979 | } |
| 1980 | } |
| 1981 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 1982 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
| 1983 | uint16_t wm[5], uint16_t min) |
| 1984 | { |
| 1985 | int level, max_level = ilk_wm_max_level(dev_priv->dev); |
| 1986 | |
| 1987 | if (wm[0] >= min) |
| 1988 | return false; |
| 1989 | |
| 1990 | wm[0] = max(wm[0], min); |
| 1991 | for (level = 1; level <= max_level; level++) |
| 1992 | wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5)); |
| 1993 | |
| 1994 | return true; |
| 1995 | } |
| 1996 | |
| 1997 | static void snb_wm_latency_quirk(struct drm_device *dev) |
| 1998 | { |
| 1999 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2000 | bool changed; |
| 2001 | |
| 2002 | /* |
| 2003 | * The BIOS provided WM memory latency values are often |
| 2004 | * inadequate for high resolution displays. Adjust them. |
| 2005 | */ |
| 2006 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) | |
| 2007 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) | |
| 2008 | ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
| 2009 | |
| 2010 | if (!changed) |
| 2011 | return; |
| 2012 | |
| 2013 | DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n"); |
| 2014 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2015 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2016 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
| 2017 | } |
| 2018 | |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 2019 | static void ilk_setup_wm_latency(struct drm_device *dev) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2020 | { |
| 2021 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2022 | |
| 2023 | intel_read_wm_latency(dev, dev_priv->wm.pri_latency); |
| 2024 | |
| 2025 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 2026 | sizeof(dev_priv->wm.pri_latency)); |
| 2027 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 2028 | sizeof(dev_priv->wm.pri_latency)); |
| 2029 | |
| 2030 | intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency); |
| 2031 | intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 2032 | |
| 2033 | intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency); |
| 2034 | intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency); |
| 2035 | intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 2036 | |
| 2037 | if (IS_GEN6(dev)) |
| 2038 | snb_wm_latency_quirk(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2039 | } |
| 2040 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2041 | static void skl_setup_wm_latency(struct drm_device *dev) |
| 2042 | { |
| 2043 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2044 | |
| 2045 | intel_read_wm_latency(dev, dev_priv->wm.skl_latency); |
| 2046 | intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency); |
| 2047 | } |
| 2048 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2049 | static void ilk_compute_wm_parameters(struct drm_crtc *crtc, |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2050 | struct ilk_pipe_wm_parameters *p) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2051 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2052 | struct drm_device *dev = crtc->dev; |
| 2053 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2054 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2055 | struct drm_plane *plane; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2056 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2057 | if (!intel_crtc->active) |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2058 | return; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2059 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2060 | p->active = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2061 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2062 | p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc); |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2063 | |
| 2064 | if (crtc->primary->state->fb) { |
| 2065 | p->pri.enabled = true; |
| 2066 | p->pri.bytes_per_pixel = |
| 2067 | crtc->primary->state->fb->bits_per_pixel / 8; |
| 2068 | } else { |
| 2069 | p->pri.enabled = false; |
| 2070 | p->pri.bytes_per_pixel = 0; |
| 2071 | } |
| 2072 | |
| 2073 | if (crtc->cursor->state->fb) { |
| 2074 | p->cur.enabled = true; |
| 2075 | p->cur.bytes_per_pixel = 4; |
| 2076 | } else { |
| 2077 | p->cur.enabled = false; |
| 2078 | p->cur.bytes_per_pixel = 0; |
| 2079 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2080 | p->pri.horiz_pixels = intel_crtc->config->pipe_src_w; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 2081 | p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2082 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 2083 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2084 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2085 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2086 | if (intel_plane->pipe == pipe) { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 2087 | p->spr = intel_plane->wm; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2088 | break; |
| 2089 | } |
| 2090 | } |
| 2091 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2092 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2093 | static void ilk_compute_wm_config(struct drm_device *dev, |
| 2094 | struct intel_wm_config *config) |
| 2095 | { |
| 2096 | struct intel_crtc *intel_crtc; |
| 2097 | |
| 2098 | /* Compute the currently _active_ config */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2099 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2100 | const struct intel_pipe_wm *wm = &intel_crtc->wm.active; |
| 2101 | |
| 2102 | if (!wm->pipe_enabled) |
| 2103 | continue; |
| 2104 | |
| 2105 | config->sprites_enabled |= wm->sprites_enabled; |
| 2106 | config->sprites_scaled |= wm->sprites_scaled; |
| 2107 | config->num_pipes_active++; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2111 | /* Compute new watermarks for the pipe */ |
| 2112 | static bool intel_compute_pipe_wm(struct drm_crtc *crtc, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2113 | const struct ilk_pipe_wm_parameters *params, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2114 | struct intel_pipe_wm *pipe_wm) |
| 2115 | { |
| 2116 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2117 | const struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2118 | int level, max_level = ilk_wm_max_level(dev); |
| 2119 | /* LP0 watermark maximums depend on this pipe alone */ |
| 2120 | struct intel_wm_config config = { |
| 2121 | .num_pipes_active = 1, |
| 2122 | .sprites_enabled = params->spr.enabled, |
| 2123 | .sprites_scaled = params->spr.scaled, |
| 2124 | }; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2125 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2126 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 2127 | pipe_wm->pipe_enabled = params->active; |
| 2128 | pipe_wm->sprites_enabled = params->spr.enabled; |
| 2129 | pipe_wm->sprites_scaled = params->spr.scaled; |
| 2130 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 2131 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
| 2132 | if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled) |
| 2133 | max_level = 1; |
| 2134 | |
| 2135 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
| 2136 | if (params->spr.scaled) |
| 2137 | max_level = 0; |
| 2138 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2139 | 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] | 2140 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2141 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 2142 | pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2143 | |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2144 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
| 2145 | ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max); |
| 2146 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2147 | /* At least LP0 must be valid */ |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2148 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) |
| 2149 | return false; |
| 2150 | |
| 2151 | ilk_compute_wm_reg_maximums(dev, 1, &max); |
| 2152 | |
| 2153 | for (level = 1; level <= max_level; level++) { |
| 2154 | struct intel_wm_level wm = {}; |
| 2155 | |
| 2156 | ilk_compute_wm_level(dev_priv, level, params, &wm); |
| 2157 | |
| 2158 | /* |
| 2159 | * Disable any watermark level that exceeds the |
| 2160 | * register maximums since such watermarks are |
| 2161 | * always invalid. |
| 2162 | */ |
| 2163 | if (!ilk_validate_wm_level(level, &max, &wm)) |
| 2164 | break; |
| 2165 | |
| 2166 | pipe_wm->wm[level] = wm; |
| 2167 | } |
| 2168 | |
| 2169 | return true; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /* |
| 2173 | * Merge the watermarks from all active pipes for a specific level. |
| 2174 | */ |
| 2175 | static void ilk_merge_wm_level(struct drm_device *dev, |
| 2176 | int level, |
| 2177 | struct intel_wm_level *ret_wm) |
| 2178 | { |
| 2179 | const struct intel_crtc *intel_crtc; |
| 2180 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2181 | ret_wm->enable = true; |
| 2182 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2183 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 2184 | const struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 2185 | const struct intel_wm_level *wm = &active->wm[level]; |
| 2186 | |
| 2187 | if (!active->pipe_enabled) |
| 2188 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2189 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2190 | /* |
| 2191 | * The watermark values may have been used in the past, |
| 2192 | * so we must maintain them in the registers for some |
| 2193 | * time even if the level is now disabled. |
| 2194 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2195 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2196 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2197 | |
| 2198 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 2199 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 2200 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 2201 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 2202 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | /* |
| 2206 | * Merge all low power watermarks for all active pipes. |
| 2207 | */ |
| 2208 | static void ilk_wm_merge(struct drm_device *dev, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2209 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2210 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2211 | struct intel_pipe_wm *merged) |
| 2212 | { |
| 2213 | int level, max_level = ilk_wm_max_level(dev); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2214 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2215 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 2216 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
| 2217 | if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) && |
| 2218 | config->num_pipes_active > 1) |
| 2219 | return; |
| 2220 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2221 | /* ILK: FBC WM must be disabled always */ |
| 2222 | merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2223 | |
| 2224 | /* merge each WM1+ level */ |
| 2225 | for (level = 1; level <= max_level; level++) { |
| 2226 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2227 | |
| 2228 | ilk_merge_wm_level(dev, level, wm); |
| 2229 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2230 | if (level > last_enabled_level) |
| 2231 | wm->enable = false; |
| 2232 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 2233 | /* make sure all following levels get disabled */ |
| 2234 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2235 | |
| 2236 | /* |
| 2237 | * The spec says it is preferred to disable |
| 2238 | * FBC WMs instead of disabling a WM level. |
| 2239 | */ |
| 2240 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2241 | if (wm->enable) |
| 2242 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2243 | wm->fbc_val = 0; |
| 2244 | } |
| 2245 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 2246 | |
| 2247 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
| 2248 | /* |
| 2249 | * FIXME this is racy. FBC might get enabled later. |
| 2250 | * What we should check here is whether FBC can be |
| 2251 | * enabled sometime later. |
| 2252 | */ |
| 2253 | if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) { |
| 2254 | for (level = 2; level <= max_level; level++) { |
| 2255 | struct intel_wm_level *wm = &merged->wm[level]; |
| 2256 | |
| 2257 | wm->enable = false; |
| 2258 | } |
| 2259 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2260 | } |
| 2261 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2262 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 2263 | { |
| 2264 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 2265 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 2266 | } |
| 2267 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2268 | /* The value we need to program into the WM_LPx latency field */ |
| 2269 | static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level) |
| 2270 | { |
| 2271 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2272 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2273 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2274 | return 2 * level; |
| 2275 | else |
| 2276 | return dev_priv->wm.pri_latency[level]; |
| 2277 | } |
| 2278 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2279 | static void ilk_compute_wm_results(struct drm_device *dev, |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2280 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2281 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2282 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2283 | { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2284 | struct intel_crtc *intel_crtc; |
| 2285 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2286 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2287 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2288 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2289 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2290 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2291 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2292 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2293 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 2294 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2295 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 2296 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2297 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2298 | /* |
| 2299 | * Maintain the watermark values even if the level is |
| 2300 | * disabled. Doing otherwise could cause underruns. |
| 2301 | */ |
| 2302 | results->wm_lp[wm_lp - 1] = |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 2303 | (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2304 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 2305 | r->cur_val; |
| 2306 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2307 | if (r->enable) |
| 2308 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 2309 | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2310 | if (INTEL_INFO(dev)->gen >= 8) |
| 2311 | results->wm_lp[wm_lp - 1] |= |
| 2312 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 2313 | else |
| 2314 | results->wm_lp[wm_lp - 1] |= |
| 2315 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 2316 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 2317 | /* |
| 2318 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 2319 | * level is disabled. Doing otherwise could cause underruns. |
| 2320 | */ |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2321 | if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) { |
| 2322 | WARN_ON(wm_lp != 1); |
| 2323 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 2324 | } else |
| 2325 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2326 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2327 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2328 | /* LP0 register values */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 2329 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2330 | enum pipe pipe = intel_crtc->pipe; |
| 2331 | const struct intel_wm_level *r = |
| 2332 | &intel_crtc->wm.active.wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2333 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 2334 | if (WARN_ON(!r->enable)) |
| 2335 | continue; |
| 2336 | |
| 2337 | results->wm_linetime[pipe] = intel_crtc->wm.active.linetime; |
| 2338 | |
| 2339 | results->wm_pipe[pipe] = |
| 2340 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 2341 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 2342 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2346 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 2347 | * 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] | 2348 | 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] | 2349 | struct intel_pipe_wm *r1, |
| 2350 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2351 | { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2352 | int level, max_level = ilk_wm_max_level(dev); |
| 2353 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2354 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2355 | for (level = 1; level <= max_level; level++) { |
| 2356 | if (r1->wm[level].enable) |
| 2357 | level1 = level; |
| 2358 | if (r2->wm[level].enable) |
| 2359 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2360 | } |
| 2361 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2362 | if (level1 == level2) { |
| 2363 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2364 | return r2; |
| 2365 | else |
| 2366 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 2367 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 2368 | return r1; |
| 2369 | } else { |
| 2370 | return r2; |
| 2371 | } |
| 2372 | } |
| 2373 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2374 | /* dirty bits used to track which watermarks need changes */ |
| 2375 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
| 2376 | #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe))) |
| 2377 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 2378 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 2379 | #define WM_DIRTY_FBC (1 << 24) |
| 2380 | #define WM_DIRTY_DDB (1 << 25) |
| 2381 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2382 | 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] | 2383 | const struct ilk_wm_values *old, |
| 2384 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2385 | { |
| 2386 | unsigned int dirty = 0; |
| 2387 | enum pipe pipe; |
| 2388 | int wm_lp; |
| 2389 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2390 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2391 | if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) { |
| 2392 | dirty |= WM_DIRTY_LINETIME(pipe); |
| 2393 | /* Must disable LP1+ watermarks too */ |
| 2394 | dirty |= WM_DIRTY_LP_ALL; |
| 2395 | } |
| 2396 | |
| 2397 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 2398 | dirty |= WM_DIRTY_PIPE(pipe); |
| 2399 | /* Must disable LP1+ watermarks too */ |
| 2400 | dirty |= WM_DIRTY_LP_ALL; |
| 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 2405 | dirty |= WM_DIRTY_FBC; |
| 2406 | /* Must disable LP1+ watermarks too */ |
| 2407 | dirty |= WM_DIRTY_LP_ALL; |
| 2408 | } |
| 2409 | |
| 2410 | if (old->partitioning != new->partitioning) { |
| 2411 | dirty |= WM_DIRTY_DDB; |
| 2412 | /* Must disable LP1+ watermarks too */ |
| 2413 | dirty |= WM_DIRTY_LP_ALL; |
| 2414 | } |
| 2415 | |
| 2416 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 2417 | if (dirty & WM_DIRTY_LP_ALL) |
| 2418 | return dirty; |
| 2419 | |
| 2420 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 2421 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 2422 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 2423 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 2424 | break; |
| 2425 | } |
| 2426 | |
| 2427 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 2428 | for (; wm_lp <= 3; wm_lp++) |
| 2429 | dirty |= WM_DIRTY_LP(wm_lp); |
| 2430 | |
| 2431 | return dirty; |
| 2432 | } |
| 2433 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2434 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 2435 | unsigned int dirty) |
| 2436 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2437 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2438 | bool changed = false; |
| 2439 | |
| 2440 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 2441 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
| 2442 | I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]); |
| 2443 | changed = true; |
| 2444 | } |
| 2445 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 2446 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
| 2447 | I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]); |
| 2448 | changed = true; |
| 2449 | } |
| 2450 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 2451 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
| 2452 | I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]); |
| 2453 | changed = true; |
| 2454 | } |
| 2455 | |
| 2456 | /* |
| 2457 | * Don't touch WM1S_LP_EN here. |
| 2458 | * Doing so could cause underruns. |
| 2459 | */ |
| 2460 | |
| 2461 | return changed; |
| 2462 | } |
| 2463 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2464 | /* |
| 2465 | * The spec says we shouldn't write when we don't need, because every write |
| 2466 | * causes WMs to be re-evaluated, expending some power. |
| 2467 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2468 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 2469 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2470 | { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2471 | struct drm_device *dev = dev_priv->dev; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2472 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2473 | unsigned int dirty; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2474 | uint32_t val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2475 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 2476 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2477 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2478 | return; |
| 2479 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2480 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2481 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2482 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2483 | I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2484 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2485 | I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2486 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2487 | I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]); |
| 2488 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2489 | if (dirty & WM_DIRTY_LINETIME(PIPE_A)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2490 | I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2491 | if (dirty & WM_DIRTY_LINETIME(PIPE_B)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2492 | I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2493 | if (dirty & WM_DIRTY_LINETIME(PIPE_C)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2494 | I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]); |
| 2495 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2496 | if (dirty & WM_DIRTY_DDB) { |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 2497 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 2498 | val = I915_READ(WM_MISC); |
| 2499 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2500 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 2501 | else |
| 2502 | val |= WM_MISC_DATA_PARTITION_5_6; |
| 2503 | I915_WRITE(WM_MISC, val); |
| 2504 | } else { |
| 2505 | val = I915_READ(DISP_ARB_CTL2); |
| 2506 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 2507 | val &= ~DISP_DATA_PARTITION_5_6; |
| 2508 | else |
| 2509 | val |= DISP_DATA_PARTITION_5_6; |
| 2510 | I915_WRITE(DISP_ARB_CTL2, val); |
| 2511 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 2512 | } |
| 2513 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 2514 | if (dirty & WM_DIRTY_FBC) { |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2515 | val = I915_READ(DISP_ARB_CTL); |
| 2516 | if (results->enable_fbc_wm) |
| 2517 | val &= ~DISP_FBC_WM_DIS; |
| 2518 | else |
| 2519 | val |= DISP_FBC_WM_DIS; |
| 2520 | I915_WRITE(DISP_ARB_CTL, val); |
| 2521 | } |
| 2522 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 2523 | if (dirty & WM_DIRTY_LP(1) && |
| 2524 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
| 2525 | I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]); |
| 2526 | |
| 2527 | if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 2528 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1]) |
| 2529 | I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]); |
| 2530 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2]) |
| 2531 | I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]); |
| 2532 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2533 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2534 | 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] | 2535 | I915_WRITE(WM1_LP_ILK, results->wm_lp[0]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2536 | 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] | 2537 | I915_WRITE(WM2_LP_ILK, results->wm_lp[1]); |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 2538 | 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] | 2539 | I915_WRITE(WM3_LP_ILK, results->wm_lp[2]); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 2540 | |
| 2541 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2542 | } |
| 2543 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 2544 | static bool ilk_disable_lp_wm(struct drm_device *dev) |
| 2545 | { |
| 2546 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2547 | |
| 2548 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 2549 | } |
| 2550 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2551 | /* |
| 2552 | * On gen9, we need to allocate Display Data Buffer (DDB) portions to the |
| 2553 | * different active planes. |
| 2554 | */ |
| 2555 | |
| 2556 | #define SKL_DDB_SIZE 896 /* in blocks */ |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2557 | #define BXT_DDB_SIZE 512 |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2558 | |
| 2559 | static void |
| 2560 | skl_ddb_get_pipe_allocation_limits(struct drm_device *dev, |
| 2561 | struct drm_crtc *for_crtc, |
| 2562 | const struct intel_wm_config *config, |
| 2563 | const struct skl_pipe_wm_parameters *params, |
| 2564 | struct skl_ddb_entry *alloc /* out */) |
| 2565 | { |
| 2566 | struct drm_crtc *crtc; |
| 2567 | unsigned int pipe_size, ddb_size; |
| 2568 | int nth_active_pipe; |
| 2569 | |
| 2570 | if (!params->active) { |
| 2571 | alloc->start = 0; |
| 2572 | alloc->end = 0; |
| 2573 | return; |
| 2574 | } |
| 2575 | |
Damien Lespiau | 43d735a | 2015-03-17 11:39:34 +0200 | [diff] [blame] | 2576 | if (IS_BROXTON(dev)) |
| 2577 | ddb_size = BXT_DDB_SIZE; |
| 2578 | else |
| 2579 | ddb_size = SKL_DDB_SIZE; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2580 | |
| 2581 | ddb_size -= 4; /* 4 blocks for bypass path allocation */ |
| 2582 | |
| 2583 | nth_active_pipe = 0; |
| 2584 | for_each_crtc(dev, crtc) { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2585 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2586 | continue; |
| 2587 | |
| 2588 | if (crtc == for_crtc) |
| 2589 | break; |
| 2590 | |
| 2591 | nth_active_pipe++; |
| 2592 | } |
| 2593 | |
| 2594 | pipe_size = ddb_size / config->num_pipes_active; |
| 2595 | alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2596 | alloc->end = alloc->start + pipe_size; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | static unsigned int skl_cursor_allocation(const struct intel_wm_config *config) |
| 2600 | { |
| 2601 | if (config->num_pipes_active == 1) |
| 2602 | return 32; |
| 2603 | |
| 2604 | return 8; |
| 2605 | } |
| 2606 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2607 | static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg) |
| 2608 | { |
| 2609 | entry->start = reg & 0x3ff; |
| 2610 | entry->end = (reg >> 16) & 0x3ff; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2611 | if (entry->end) |
| 2612 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2613 | } |
| 2614 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 2615 | void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv, |
| 2616 | struct skl_ddb_allocation *ddb /* out */) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2617 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2618 | enum pipe pipe; |
| 2619 | int plane; |
| 2620 | u32 val; |
| 2621 | |
| 2622 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2623 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 2624 | val = I915_READ(PLANE_BUF_CFG(pipe, plane)); |
| 2625 | skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane], |
| 2626 | val); |
| 2627 | } |
| 2628 | |
| 2629 | val = I915_READ(CUR_BUF_CFG(pipe)); |
| 2630 | skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val); |
| 2631 | } |
| 2632 | } |
| 2633 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2634 | static unsigned int |
| 2635 | skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p) |
| 2636 | { |
| 2637 | return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel; |
| 2638 | } |
| 2639 | |
| 2640 | /* |
| 2641 | * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching |
| 2642 | * a 8192x4096@32bpp framebuffer: |
| 2643 | * 3 * 4096 * 8192 * 4 < 2^32 |
| 2644 | */ |
| 2645 | static unsigned int |
| 2646 | skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc, |
| 2647 | const struct skl_pipe_wm_parameters *params) |
| 2648 | { |
| 2649 | unsigned int total_data_rate = 0; |
| 2650 | int plane; |
| 2651 | |
| 2652 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2653 | const struct intel_plane_wm_parameters *p; |
| 2654 | |
| 2655 | p = ¶ms->plane[plane]; |
| 2656 | if (!p->enabled) |
| 2657 | continue; |
| 2658 | |
| 2659 | total_data_rate += skl_plane_relative_data_rate(p); |
| 2660 | } |
| 2661 | |
| 2662 | return total_data_rate; |
| 2663 | } |
| 2664 | |
| 2665 | static void |
| 2666 | skl_allocate_pipe_ddb(struct drm_crtc *crtc, |
| 2667 | const struct intel_wm_config *config, |
| 2668 | const struct skl_pipe_wm_parameters *params, |
| 2669 | struct skl_ddb_allocation *ddb /* out */) |
| 2670 | { |
| 2671 | struct drm_device *dev = crtc->dev; |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2672 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2673 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2674 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2675 | struct skl_ddb_entry *alloc = &ddb->pipe[pipe]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2676 | uint16_t alloc_size, start, cursor_blocks; |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2677 | uint16_t minimum[I915_MAX_PLANES]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2678 | unsigned int total_data_rate; |
| 2679 | int plane; |
| 2680 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2681 | skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc); |
| 2682 | alloc_size = skl_ddb_entry_size(alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2683 | if (alloc_size == 0) { |
| 2684 | memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe])); |
| 2685 | memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe])); |
| 2686 | return; |
| 2687 | } |
| 2688 | |
| 2689 | cursor_blocks = skl_cursor_allocation(config); |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2690 | ddb->cursor[pipe].start = alloc->end - cursor_blocks; |
| 2691 | ddb->cursor[pipe].end = alloc->end; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2692 | |
| 2693 | alloc_size -= cursor_blocks; |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2694 | alloc->end -= cursor_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2695 | |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2696 | /* 1. Allocate the mininum required blocks for each active plane */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 2697 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2698 | const struct intel_plane_wm_parameters *p; |
| 2699 | |
| 2700 | p = ¶ms->plane[plane]; |
| 2701 | if (!p->enabled) |
| 2702 | continue; |
| 2703 | |
| 2704 | minimum[plane] = 8; |
| 2705 | alloc_size -= minimum[plane]; |
| 2706 | } |
| 2707 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2708 | /* |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2709 | * 2. Distribute the remaining space in proportion to the amount of |
| 2710 | * data each plane needs to fetch from memory. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2711 | * |
| 2712 | * FIXME: we may not allocate every single block here. |
| 2713 | */ |
| 2714 | total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params); |
| 2715 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 2716 | start = alloc->start; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2717 | for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) { |
| 2718 | const struct intel_plane_wm_parameters *p; |
| 2719 | unsigned int data_rate; |
| 2720 | uint16_t plane_blocks; |
| 2721 | |
| 2722 | p = ¶ms->plane[plane]; |
| 2723 | if (!p->enabled) |
| 2724 | continue; |
| 2725 | |
| 2726 | data_rate = skl_plane_relative_data_rate(p); |
| 2727 | |
| 2728 | /* |
| 2729 | * promote the expression to 64 bits to avoid overflowing, the |
| 2730 | * result is < available as data_rate / total_data_rate < 1 |
| 2731 | */ |
Damien Lespiau | 8095815 | 2015-02-09 13:35:10 +0000 | [diff] [blame] | 2732 | plane_blocks = minimum[plane]; |
| 2733 | plane_blocks += div_u64((uint64_t)alloc_size * data_rate, |
| 2734 | total_data_rate); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2735 | |
| 2736 | ddb->plane[pipe][plane].start = start; |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 2737 | ddb->plane[pipe][plane].end = start + plane_blocks; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 2738 | |
| 2739 | start += plane_blocks; |
| 2740 | } |
| 2741 | |
| 2742 | } |
| 2743 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2744 | 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] | 2745 | { |
| 2746 | /* TODO: Take into account the scalers once we support them */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2747 | return config->base.adjusted_mode.crtc_clock; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | /* |
| 2751 | * The max latency should be 257 (max the punit can code is 255 and we add 2us |
| 2752 | * for the read latency) and bytes_per_pixel should always be <= 8, so that |
| 2753 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 2754 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 2755 | */ |
| 2756 | static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel, |
| 2757 | uint32_t latency) |
| 2758 | { |
| 2759 | uint32_t wm_intermediate_val, ret; |
| 2760 | |
| 2761 | if (latency == 0) |
| 2762 | return UINT_MAX; |
| 2763 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2764 | wm_intermediate_val = latency * pixel_rate * bytes_per_pixel / 512; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2765 | ret = DIV_ROUND_UP(wm_intermediate_val, 1000); |
| 2766 | |
| 2767 | return ret; |
| 2768 | } |
| 2769 | |
| 2770 | static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal, |
| 2771 | uint32_t horiz_pixels, uint8_t bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2772 | uint64_t tiling, uint32_t latency) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2773 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2774 | uint32_t ret; |
| 2775 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2776 | uint32_t wm_intermediate_val; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2777 | |
| 2778 | if (latency == 0) |
| 2779 | return UINT_MAX; |
| 2780 | |
| 2781 | plane_bytes_per_line = horiz_pixels * bytes_per_pixel; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2782 | |
| 2783 | if (tiling == I915_FORMAT_MOD_Y_TILED || |
| 2784 | tiling == I915_FORMAT_MOD_Yf_TILED) { |
| 2785 | plane_bytes_per_line *= 4; |
| 2786 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2787 | plane_blocks_per_line /= 4; |
| 2788 | } else { |
| 2789 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
| 2790 | } |
| 2791 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2792 | wm_intermediate_val = latency * pixel_rate; |
| 2793 | ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) * |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2794 | plane_blocks_per_line; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2795 | |
| 2796 | return ret; |
| 2797 | } |
| 2798 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2799 | static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb, |
| 2800 | const struct intel_crtc *intel_crtc) |
| 2801 | { |
| 2802 | struct drm_device *dev = intel_crtc->base.dev; |
| 2803 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2804 | const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 2805 | enum pipe pipe = intel_crtc->pipe; |
| 2806 | |
| 2807 | if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe], |
| 2808 | sizeof(new_ddb->plane[pipe]))) |
| 2809 | return true; |
| 2810 | |
| 2811 | if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe], |
| 2812 | sizeof(new_ddb->cursor[pipe]))) |
| 2813 | return true; |
| 2814 | |
| 2815 | return false; |
| 2816 | } |
| 2817 | |
| 2818 | static void skl_compute_wm_global_parameters(struct drm_device *dev, |
| 2819 | struct intel_wm_config *config) |
| 2820 | { |
| 2821 | struct drm_crtc *crtc; |
| 2822 | struct drm_plane *plane; |
| 2823 | |
| 2824 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2825 | config->num_pipes_active += to_intel_crtc(crtc)->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2826 | |
| 2827 | /* FIXME: I don't think we need those two global parameters on SKL */ |
| 2828 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2829 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2830 | |
| 2831 | config->sprites_enabled |= intel_plane->wm.enabled; |
| 2832 | config->sprites_scaled |= intel_plane->wm.scaled; |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc, |
| 2837 | struct skl_pipe_wm_parameters *p) |
| 2838 | { |
| 2839 | struct drm_device *dev = crtc->dev; |
| 2840 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2841 | enum pipe pipe = intel_crtc->pipe; |
| 2842 | struct drm_plane *plane; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2843 | struct drm_framebuffer *fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2844 | int i = 1; /* Index for sprite planes start */ |
| 2845 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2846 | p->active = intel_crtc->active; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2847 | if (p->active) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2848 | p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal; |
| 2849 | p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2850 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2851 | fb = crtc->primary->state->fb; |
| 2852 | if (fb) { |
| 2853 | p->plane[0].enabled = true; |
| 2854 | p->plane[0].bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2855 | p->plane[0].tiling = fb->modifier[0]; |
| 2856 | } else { |
| 2857 | p->plane[0].enabled = false; |
| 2858 | p->plane[0].bytes_per_pixel = 0; |
| 2859 | p->plane[0].tiling = DRM_FORMAT_MOD_NONE; |
| 2860 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2861 | p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w; |
| 2862 | p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2863 | p->plane[0].rotation = crtc->primary->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2864 | |
Matt Roper | c9f038a | 2015-03-09 11:06:02 -0700 | [diff] [blame] | 2865 | fb = crtc->cursor->state->fb; |
| 2866 | if (fb) { |
| 2867 | p->cursor.enabled = true; |
| 2868 | p->cursor.bytes_per_pixel = fb->bits_per_pixel / 8; |
| 2869 | p->cursor.horiz_pixels = crtc->cursor->state->crtc_w; |
| 2870 | p->cursor.vert_pixels = crtc->cursor->state->crtc_h; |
| 2871 | } else { |
| 2872 | p->cursor.enabled = false; |
| 2873 | p->cursor.bytes_per_pixel = 0; |
| 2874 | p->cursor.horiz_pixels = 64; |
| 2875 | p->cursor.vert_pixels = 64; |
| 2876 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 2880 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 2881 | |
Sonika Jindal | a712f8e | 2014-12-09 10:59:15 +0530 | [diff] [blame] | 2882 | if (intel_plane->pipe == pipe && |
| 2883 | plane->type == DRM_PLANE_TYPE_OVERLAY) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2884 | p->plane[i++] = intel_plane->wm; |
| 2885 | } |
| 2886 | } |
| 2887 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2888 | static bool skl_compute_plane_wm(const struct drm_i915_private *dev_priv, |
| 2889 | struct skl_pipe_wm_parameters *p, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2890 | struct intel_plane_wm_parameters *p_params, |
| 2891 | uint16_t ddb_allocation, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2892 | int level, |
Damien Lespiau | afb024a | 2014-11-04 17:06:59 +0000 | [diff] [blame] | 2893 | uint16_t *out_blocks, /* out */ |
| 2894 | uint8_t *out_lines /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2895 | { |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2896 | uint32_t latency = dev_priv->wm.skl_latency[level]; |
| 2897 | uint32_t method1, method2; |
| 2898 | uint32_t plane_bytes_per_line, plane_blocks_per_line; |
| 2899 | uint32_t res_blocks, res_lines; |
| 2900 | uint32_t selected_result; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2901 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2902 | if (latency == 0 || !p->active || !p_params->enabled) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2903 | return false; |
| 2904 | |
| 2905 | method1 = skl_wm_method1(p->pixel_rate, |
| 2906 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2907 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2908 | method2 = skl_wm_method2(p->pixel_rate, |
| 2909 | p->pipe_htotal, |
| 2910 | p_params->horiz_pixels, |
| 2911 | p_params->bytes_per_pixel, |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2912 | p_params->tiling, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2913 | latency); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2914 | |
| 2915 | plane_bytes_per_line = p_params->horiz_pixels * |
| 2916 | p_params->bytes_per_pixel; |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2917 | plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2918 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2919 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2920 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) { |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2921 | uint32_t min_scanlines = 4; |
| 2922 | uint32_t y_tile_minimum; |
| 2923 | if (intel_rotation_90_or_270(p_params->rotation)) { |
| 2924 | switch (p_params->bytes_per_pixel) { |
| 2925 | case 1: |
| 2926 | min_scanlines = 16; |
| 2927 | break; |
| 2928 | case 2: |
| 2929 | min_scanlines = 8; |
| 2930 | break; |
| 2931 | case 8: |
| 2932 | WARN(1, "Unsupported pixel depth for rotation"); |
kbuild test robot | 2f0b579 | 2015-03-26 22:30:21 +0800 | [diff] [blame] | 2933 | } |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 2934 | } |
| 2935 | y_tile_minimum = plane_blocks_per_line * min_scanlines; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2936 | selected_result = max(method2, y_tile_minimum); |
| 2937 | } else { |
| 2938 | if ((ddb_allocation / plane_blocks_per_line) >= 1) |
| 2939 | selected_result = min(method1, method2); |
| 2940 | else |
| 2941 | selected_result = method1; |
| 2942 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2943 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2944 | res_blocks = selected_result + 1; |
| 2945 | res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2946 | |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 2947 | if (level >= 1 && level <= 7) { |
| 2948 | if (p_params->tiling == I915_FORMAT_MOD_Y_TILED || |
| 2949 | p_params->tiling == I915_FORMAT_MOD_Yf_TILED) |
| 2950 | res_lines += 4; |
| 2951 | else |
| 2952 | res_blocks++; |
| 2953 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2954 | |
| 2955 | if (res_blocks >= ddb_allocation || res_lines > 31) |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 2956 | return false; |
| 2957 | |
| 2958 | *out_blocks = res_blocks; |
| 2959 | *out_lines = res_lines; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2960 | |
| 2961 | return true; |
| 2962 | } |
| 2963 | |
| 2964 | static void skl_compute_wm_level(const struct drm_i915_private *dev_priv, |
| 2965 | struct skl_ddb_allocation *ddb, |
| 2966 | struct skl_pipe_wm_parameters *p, |
| 2967 | enum pipe pipe, |
| 2968 | int level, |
| 2969 | int num_planes, |
| 2970 | struct skl_wm_level *result) |
| 2971 | { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2972 | uint16_t ddb_blocks; |
| 2973 | int i; |
| 2974 | |
| 2975 | for (i = 0; i < num_planes; i++) { |
| 2976 | ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]); |
| 2977 | |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2978 | result->plane_en[i] = skl_compute_plane_wm(dev_priv, |
| 2979 | p, &p->plane[i], |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2980 | ddb_blocks, |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2981 | level, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2982 | &result->plane_res_b[i], |
| 2983 | &result->plane_res_l[i]); |
| 2984 | } |
| 2985 | |
| 2986 | ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]); |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 2987 | result->cursor_en = skl_compute_plane_wm(dev_priv, p, &p->cursor, |
| 2988 | ddb_blocks, level, |
| 2989 | &result->cursor_res_b, |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 2990 | &result->cursor_res_l); |
| 2991 | } |
| 2992 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2993 | static uint32_t |
| 2994 | skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p) |
| 2995 | { |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 2996 | if (!to_intel_crtc(crtc)->active) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 2997 | return 0; |
| 2998 | |
| 2999 | return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate); |
| 3000 | |
| 3001 | } |
| 3002 | |
| 3003 | static void skl_compute_transition_wm(struct drm_crtc *crtc, |
| 3004 | struct skl_pipe_wm_parameters *params, |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3005 | struct skl_wm_level *trans_wm /* out */) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3006 | { |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3007 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3008 | int i; |
| 3009 | |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3010 | if (!params->active) |
| 3011 | return; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3012 | |
| 3013 | /* Until we know more, just disable transition WMs */ |
| 3014 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3015 | trans_wm->plane_en[i] = false; |
| 3016 | trans_wm->cursor_en = false; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3019 | static void skl_compute_pipe_wm(struct drm_crtc *crtc, |
| 3020 | struct skl_ddb_allocation *ddb, |
| 3021 | struct skl_pipe_wm_parameters *params, |
| 3022 | struct skl_pipe_wm *pipe_wm) |
| 3023 | { |
| 3024 | struct drm_device *dev = crtc->dev; |
| 3025 | const struct drm_i915_private *dev_priv = dev->dev_private; |
| 3026 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3027 | int level, max_level = ilk_wm_max_level(dev); |
| 3028 | |
| 3029 | for (level = 0; level <= max_level; level++) { |
| 3030 | skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe, |
| 3031 | level, intel_num_planes(intel_crtc), |
| 3032 | &pipe_wm->wm[level]); |
| 3033 | } |
| 3034 | pipe_wm->linetime = skl_compute_linetime_wm(crtc, params); |
| 3035 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3036 | skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | static void skl_compute_wm_results(struct drm_device *dev, |
| 3040 | struct skl_pipe_wm_parameters *p, |
| 3041 | struct skl_pipe_wm *p_wm, |
| 3042 | struct skl_wm_values *r, |
| 3043 | struct intel_crtc *intel_crtc) |
| 3044 | { |
| 3045 | int level, max_level = ilk_wm_max_level(dev); |
| 3046 | enum pipe pipe = intel_crtc->pipe; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3047 | uint32_t temp; |
| 3048 | int i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3049 | |
| 3050 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3051 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3052 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3053 | |
| 3054 | temp |= p_wm->wm[level].plane_res_l[i] << |
| 3055 | PLANE_WM_LINES_SHIFT; |
| 3056 | temp |= p_wm->wm[level].plane_res_b[i]; |
| 3057 | if (p_wm->wm[level].plane_en[i]) |
| 3058 | temp |= PLANE_WM_EN; |
| 3059 | |
| 3060 | r->plane[pipe][i][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | temp = 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3064 | |
| 3065 | temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3066 | temp |= p_wm->wm[level].cursor_res_b; |
| 3067 | |
| 3068 | if (p_wm->wm[level].cursor_en) |
| 3069 | temp |= PLANE_WM_EN; |
| 3070 | |
| 3071 | r->cursor[pipe][level] = temp; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3072 | |
| 3073 | } |
| 3074 | |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 3075 | /* transition WMs */ |
| 3076 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3077 | temp = 0; |
| 3078 | temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT; |
| 3079 | temp |= p_wm->trans_wm.plane_res_b[i]; |
| 3080 | if (p_wm->trans_wm.plane_en[i]) |
| 3081 | temp |= PLANE_WM_EN; |
| 3082 | |
| 3083 | r->plane_trans[pipe][i] = temp; |
| 3084 | } |
| 3085 | |
| 3086 | temp = 0; |
| 3087 | temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT; |
| 3088 | temp |= p_wm->trans_wm.cursor_res_b; |
| 3089 | if (p_wm->trans_wm.cursor_en) |
| 3090 | temp |= PLANE_WM_EN; |
| 3091 | |
| 3092 | r->cursor_trans[pipe] = temp; |
| 3093 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3094 | r->wm_linetime[pipe] = p_wm->linetime; |
| 3095 | } |
| 3096 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 3097 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg, |
| 3098 | const struct skl_ddb_entry *entry) |
| 3099 | { |
| 3100 | if (entry->end) |
| 3101 | I915_WRITE(reg, (entry->end - 1) << 16 | entry->start); |
| 3102 | else |
| 3103 | I915_WRITE(reg, 0); |
| 3104 | } |
| 3105 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3106 | static void skl_write_wm_values(struct drm_i915_private *dev_priv, |
| 3107 | const struct skl_wm_values *new) |
| 3108 | { |
| 3109 | struct drm_device *dev = dev_priv->dev; |
| 3110 | struct intel_crtc *crtc; |
| 3111 | |
| 3112 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 3113 | int i, level, max_level = ilk_wm_max_level(dev); |
| 3114 | enum pipe pipe = crtc->pipe; |
| 3115 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3116 | if (!new->dirty[pipe]) |
| 3117 | continue; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3118 | |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3119 | I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]); |
| 3120 | |
| 3121 | for (level = 0; level <= max_level; level++) { |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3122 | for (i = 0; i < intel_num_planes(crtc); i++) |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3123 | I915_WRITE(PLANE_WM(pipe, i, level), |
| 3124 | new->plane[pipe][i][level]); |
| 3125 | I915_WRITE(CUR_WM(pipe, level), |
| 3126 | new->cursor[pipe][level]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3127 | } |
Damien Lespiau | 5d374d9 | 2014-11-04 17:07:00 +0000 | [diff] [blame] | 3128 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3129 | I915_WRITE(PLANE_WM_TRANS(pipe, i), |
| 3130 | new->plane_trans[pipe][i]); |
| 3131 | I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]); |
| 3132 | |
| 3133 | for (i = 0; i < intel_num_planes(crtc); i++) |
| 3134 | skl_ddb_entry_write(dev_priv, |
| 3135 | PLANE_BUF_CFG(pipe, i), |
| 3136 | &new->ddb.plane[pipe][i]); |
| 3137 | |
| 3138 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), |
| 3139 | &new->ddb.cursor[pipe]); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3140 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3143 | /* |
| 3144 | * When setting up a new DDB allocation arrangement, we need to correctly |
| 3145 | * sequence the times at which the new allocations for the pipes are taken into |
| 3146 | * account or we'll have pipes fetching from space previously allocated to |
| 3147 | * another pipe. |
| 3148 | * |
| 3149 | * Roughly the sequence looks like: |
| 3150 | * 1. re-allocate the pipe(s) with the allocation being reduced and not |
| 3151 | * overlapping with a previous light-up pipe (another way to put it is: |
| 3152 | * pipes with their new allocation strickly included into their old ones). |
| 3153 | * 2. re-allocate the other pipes that get their allocation reduced |
| 3154 | * 3. allocate the pipes having their allocation increased |
| 3155 | * |
| 3156 | * Steps 1. and 2. are here to take care of the following case: |
| 3157 | * - Initially DDB looks like this: |
| 3158 | * | B | C | |
| 3159 | * - enable pipe A. |
| 3160 | * - pipe B has a reduced DDB allocation that overlaps with the old pipe C |
| 3161 | * allocation |
| 3162 | * | A | B | C | |
| 3163 | * |
| 3164 | * We need to sequence the re-allocation: C, B, A (and not B, C, A). |
| 3165 | */ |
| 3166 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3167 | static void |
| 3168 | 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] | 3169 | { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3170 | int plane; |
| 3171 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3172 | DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass); |
| 3173 | |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 3174 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3175 | I915_WRITE(PLANE_SURF(pipe, plane), |
| 3176 | I915_READ(PLANE_SURF(pipe, plane))); |
| 3177 | } |
| 3178 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 3179 | } |
| 3180 | |
| 3181 | static bool |
| 3182 | skl_ddb_allocation_included(const struct skl_ddb_allocation *old, |
| 3183 | const struct skl_ddb_allocation *new, |
| 3184 | enum pipe pipe) |
| 3185 | { |
| 3186 | uint16_t old_size, new_size; |
| 3187 | |
| 3188 | old_size = skl_ddb_entry_size(&old->pipe[pipe]); |
| 3189 | new_size = skl_ddb_entry_size(&new->pipe[pipe]); |
| 3190 | |
| 3191 | return old_size != new_size && |
| 3192 | new->pipe[pipe].start >= old->pipe[pipe].start && |
| 3193 | new->pipe[pipe].end <= old->pipe[pipe].end; |
| 3194 | } |
| 3195 | |
| 3196 | static void skl_flush_wm_values(struct drm_i915_private *dev_priv, |
| 3197 | struct skl_wm_values *new_values) |
| 3198 | { |
| 3199 | struct drm_device *dev = dev_priv->dev; |
| 3200 | struct skl_ddb_allocation *cur_ddb, *new_ddb; |
| 3201 | bool reallocated[I915_MAX_PIPES] = {false, false, false}; |
| 3202 | struct intel_crtc *crtc; |
| 3203 | enum pipe pipe; |
| 3204 | |
| 3205 | new_ddb = &new_values->ddb; |
| 3206 | cur_ddb = &dev_priv->wm.skl_hw.ddb; |
| 3207 | |
| 3208 | /* |
| 3209 | * First pass: flush the pipes with the new allocation contained into |
| 3210 | * the old space. |
| 3211 | * |
| 3212 | * We'll wait for the vblank on those pipes to ensure we can safely |
| 3213 | * re-allocate the freed space without this pipe fetching from it. |
| 3214 | */ |
| 3215 | for_each_intel_crtc(dev, crtc) { |
| 3216 | if (!crtc->active) |
| 3217 | continue; |
| 3218 | |
| 3219 | pipe = crtc->pipe; |
| 3220 | |
| 3221 | if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe)) |
| 3222 | continue; |
| 3223 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3224 | skl_wm_flush_pipe(dev_priv, pipe, 1); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3225 | intel_wait_for_vblank(dev, pipe); |
| 3226 | |
| 3227 | reallocated[pipe] = true; |
| 3228 | } |
| 3229 | |
| 3230 | |
| 3231 | /* |
| 3232 | * Second pass: flush the pipes that are having their allocation |
| 3233 | * reduced, but overlapping with a previous allocation. |
| 3234 | * |
| 3235 | * Here as well we need to wait for the vblank to make sure the freed |
| 3236 | * space is not used anymore. |
| 3237 | */ |
| 3238 | for_each_intel_crtc(dev, crtc) { |
| 3239 | if (!crtc->active) |
| 3240 | continue; |
| 3241 | |
| 3242 | pipe = crtc->pipe; |
| 3243 | |
| 3244 | if (reallocated[pipe]) |
| 3245 | continue; |
| 3246 | |
| 3247 | if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) < |
| 3248 | skl_ddb_entry_size(&cur_ddb->pipe[pipe])) { |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3249 | skl_wm_flush_pipe(dev_priv, pipe, 2); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3250 | intel_wait_for_vblank(dev, pipe); |
Sonika Jindal | d9d8e6b | 2014-12-11 17:58:15 +0530 | [diff] [blame] | 3251 | reallocated[pipe] = true; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3252 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | /* |
| 3256 | * Third pass: flush the pipes that got more space allocated. |
| 3257 | * |
| 3258 | * We don't need to actively wait for the update here, next vblank |
| 3259 | * will just get more DDB space with the correct WM values. |
| 3260 | */ |
| 3261 | for_each_intel_crtc(dev, crtc) { |
| 3262 | if (!crtc->active) |
| 3263 | continue; |
| 3264 | |
| 3265 | pipe = crtc->pipe; |
| 3266 | |
| 3267 | /* |
| 3268 | * At this point, only the pipes more space than before are |
| 3269 | * left to re-allocate. |
| 3270 | */ |
| 3271 | if (reallocated[pipe]) |
| 3272 | continue; |
| 3273 | |
Damien Lespiau | d21b795 | 2014-11-04 17:07:03 +0000 | [diff] [blame] | 3274 | skl_wm_flush_pipe(dev_priv, pipe, 3); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3275 | } |
| 3276 | } |
| 3277 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3278 | static bool skl_update_pipe_wm(struct drm_crtc *crtc, |
| 3279 | struct skl_pipe_wm_parameters *params, |
| 3280 | struct intel_wm_config *config, |
| 3281 | struct skl_ddb_allocation *ddb, /* out */ |
| 3282 | struct skl_pipe_wm *pipe_wm /* out */) |
| 3283 | { |
| 3284 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3285 | |
| 3286 | skl_compute_wm_pipe_parameters(crtc, params); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 3287 | skl_allocate_pipe_ddb(crtc, config, params, ddb); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3288 | skl_compute_pipe_wm(crtc, ddb, params, pipe_wm); |
| 3289 | |
| 3290 | if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm))) |
| 3291 | return false; |
| 3292 | |
| 3293 | intel_crtc->wm.skl_active = *pipe_wm; |
| 3294 | return true; |
| 3295 | } |
| 3296 | |
| 3297 | static void skl_update_other_pipe_wm(struct drm_device *dev, |
| 3298 | struct drm_crtc *crtc, |
| 3299 | struct intel_wm_config *config, |
| 3300 | struct skl_wm_values *r) |
| 3301 | { |
| 3302 | struct intel_crtc *intel_crtc; |
| 3303 | struct intel_crtc *this_crtc = to_intel_crtc(crtc); |
| 3304 | |
| 3305 | /* |
| 3306 | * If the WM update hasn't changed the allocation for this_crtc (the |
| 3307 | * crtc we are currently computing the new WM values for), other |
| 3308 | * enabled crtcs will keep the same allocation and we don't need to |
| 3309 | * recompute anything for them. |
| 3310 | */ |
| 3311 | if (!skl_ddb_allocation_changed(&r->ddb, this_crtc)) |
| 3312 | return; |
| 3313 | |
| 3314 | /* |
| 3315 | * Otherwise, because of this_crtc being freshly enabled/disabled, the |
| 3316 | * other active pipes need new DDB allocation and WM values. |
| 3317 | */ |
| 3318 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 3319 | base.head) { |
| 3320 | struct skl_pipe_wm_parameters params = {}; |
| 3321 | struct skl_pipe_wm pipe_wm = {}; |
| 3322 | bool wm_changed; |
| 3323 | |
| 3324 | if (this_crtc->pipe == intel_crtc->pipe) |
| 3325 | continue; |
| 3326 | |
| 3327 | if (!intel_crtc->active) |
| 3328 | continue; |
| 3329 | |
| 3330 | wm_changed = skl_update_pipe_wm(&intel_crtc->base, |
| 3331 | ¶ms, config, |
| 3332 | &r->ddb, &pipe_wm); |
| 3333 | |
| 3334 | /* |
| 3335 | * If we end up re-computing the other pipe WM values, it's |
| 3336 | * because it was really needed, so we expect the WM values to |
| 3337 | * be different. |
| 3338 | */ |
| 3339 | WARN_ON(!wm_changed); |
| 3340 | |
| 3341 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, r, intel_crtc); |
| 3342 | r->dirty[intel_crtc->pipe] = true; |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | static void skl_update_wm(struct drm_crtc *crtc) |
| 3347 | { |
| 3348 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3349 | struct drm_device *dev = crtc->dev; |
| 3350 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3351 | struct skl_pipe_wm_parameters params = {}; |
| 3352 | struct skl_wm_values *results = &dev_priv->wm.skl_results; |
| 3353 | struct skl_pipe_wm pipe_wm = {}; |
| 3354 | struct intel_wm_config config = {}; |
| 3355 | |
| 3356 | memset(results, 0, sizeof(*results)); |
| 3357 | |
| 3358 | skl_compute_wm_global_parameters(dev, &config); |
| 3359 | |
| 3360 | if (!skl_update_pipe_wm(crtc, ¶ms, &config, |
| 3361 | &results->ddb, &pipe_wm)) |
| 3362 | return; |
| 3363 | |
| 3364 | skl_compute_wm_results(dev, ¶ms, &pipe_wm, results, intel_crtc); |
| 3365 | results->dirty[intel_crtc->pipe] = true; |
| 3366 | |
| 3367 | skl_update_other_pipe_wm(dev, crtc, &config, results); |
| 3368 | skl_write_wm_values(dev_priv, results); |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 3369 | skl_flush_wm_values(dev_priv, results); |
Damien Lespiau | 53b0deb | 2014-11-04 17:06:48 +0000 | [diff] [blame] | 3370 | |
| 3371 | /* store the new configuration */ |
| 3372 | dev_priv->wm.skl_hw = *results; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | static void |
| 3376 | skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc, |
| 3377 | uint32_t sprite_width, uint32_t sprite_height, |
| 3378 | int pixel_size, bool enabled, bool scaled) |
| 3379 | { |
| 3380 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3381 | struct drm_framebuffer *fb = plane->state->fb; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3382 | |
| 3383 | intel_plane->wm.enabled = enabled; |
| 3384 | intel_plane->wm.scaled = scaled; |
| 3385 | intel_plane->wm.horiz_pixels = sprite_width; |
| 3386 | intel_plane->wm.vert_pixels = sprite_height; |
| 3387 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 3388 | intel_plane->wm.tiling = DRM_FORMAT_MOD_NONE; |
| 3389 | /* |
| 3390 | * Framebuffer can be NULL on plane disable, but it does not |
| 3391 | * matter for watermarks if we assume no tiling in that case. |
| 3392 | */ |
| 3393 | if (fb) |
| 3394 | intel_plane->wm.tiling = fb->modifier[0]; |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 3395 | intel_plane->wm.rotation = plane->state->rotation; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 3396 | |
| 3397 | skl_update_wm(crtc); |
| 3398 | } |
| 3399 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3400 | static void ilk_update_wm(struct drm_crtc *crtc) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3401 | { |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3402 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3403 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3404 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3405 | struct ilk_wm_maximums max; |
| 3406 | struct ilk_pipe_wm_parameters params = {}; |
| 3407 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3408 | enum intel_ddb_partitioning partitioning; |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3409 | struct intel_pipe_wm pipe_wm = {}; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3410 | 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] | 3411 | struct intel_wm_config config = {}; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3412 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3413 | ilk_compute_wm_parameters(crtc, ¶ms); |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3414 | |
Ville Syrjälä | 7c4a395 | 2013-10-09 19:17:56 +0300 | [diff] [blame] | 3415 | intel_compute_pipe_wm(crtc, ¶ms, &pipe_wm); |
| 3416 | |
| 3417 | if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm))) |
| 3418 | return; |
| 3419 | |
| 3420 | intel_crtc->wm.active = pipe_wm; |
| 3421 | |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3422 | ilk_compute_wm_config(dev, &config); |
| 3423 | |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3424 | 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] | 3425 | ilk_wm_merge(dev, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3426 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3427 | /* 5/6 split only in single pipe config on IVB+ */ |
Ville Syrjälä | ec98c8d | 2013-10-11 15:26:26 +0300 | [diff] [blame] | 3428 | if (INTEL_INFO(dev)->gen >= 7 && |
| 3429 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Ville Syrjälä | 34982fe | 2013-10-09 19:18:09 +0300 | [diff] [blame] | 3430 | 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] | 3431 | ilk_wm_merge(dev, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 3432 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3433 | 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] | 3434 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3435 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3436 | } |
| 3437 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3438 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 3439 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3440 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3441 | ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3442 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3443 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3444 | } |
| 3445 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3446 | static void |
| 3447 | ilk_update_sprite_wm(struct drm_plane *plane, |
| 3448 | struct drm_crtc *crtc, |
| 3449 | uint32_t sprite_width, uint32_t sprite_height, |
| 3450 | int pixel_size, bool enabled, bool scaled) |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3451 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3452 | struct drm_device *dev = plane->dev; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3453 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3454 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3455 | intel_plane->wm.enabled = enabled; |
| 3456 | intel_plane->wm.scaled = scaled; |
| 3457 | intel_plane->wm.horiz_pixels = sprite_width; |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3458 | intel_plane->wm.vert_pixels = sprite_width; |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3459 | intel_plane->wm.bytes_per_pixel = pixel_size; |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3460 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3461 | /* |
| 3462 | * IVB workaround: must disable low power watermarks for at least |
| 3463 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 3464 | * when scaling is disabled. |
| 3465 | * |
| 3466 | * WaCxSRDisabledForSpriteScaling:ivb |
| 3467 | */ |
| 3468 | if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev)) |
| 3469 | intel_wait_for_vblank(dev, intel_plane->pipe); |
| 3470 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3471 | ilk_update_wm(crtc); |
Paulo Zanoni | 526682e | 2013-05-24 11:59:18 -0300 | [diff] [blame] | 3472 | } |
| 3473 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3474 | static void skl_pipe_wm_active_state(uint32_t val, |
| 3475 | struct skl_pipe_wm *active, |
| 3476 | bool is_transwm, |
| 3477 | bool is_cursor, |
| 3478 | int i, |
| 3479 | int level) |
| 3480 | { |
| 3481 | bool is_enabled = (val & PLANE_WM_EN) != 0; |
| 3482 | |
| 3483 | if (!is_transwm) { |
| 3484 | if (!is_cursor) { |
| 3485 | active->wm[level].plane_en[i] = is_enabled; |
| 3486 | active->wm[level].plane_res_b[i] = |
| 3487 | val & PLANE_WM_BLOCKS_MASK; |
| 3488 | active->wm[level].plane_res_l[i] = |
| 3489 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3490 | PLANE_WM_LINES_MASK; |
| 3491 | } else { |
| 3492 | active->wm[level].cursor_en = is_enabled; |
| 3493 | active->wm[level].cursor_res_b = |
| 3494 | val & PLANE_WM_BLOCKS_MASK; |
| 3495 | active->wm[level].cursor_res_l = |
| 3496 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3497 | PLANE_WM_LINES_MASK; |
| 3498 | } |
| 3499 | } else { |
| 3500 | if (!is_cursor) { |
| 3501 | active->trans_wm.plane_en[i] = is_enabled; |
| 3502 | active->trans_wm.plane_res_b[i] = |
| 3503 | val & PLANE_WM_BLOCKS_MASK; |
| 3504 | active->trans_wm.plane_res_l[i] = |
| 3505 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3506 | PLANE_WM_LINES_MASK; |
| 3507 | } else { |
| 3508 | active->trans_wm.cursor_en = is_enabled; |
| 3509 | active->trans_wm.cursor_res_b = |
| 3510 | val & PLANE_WM_BLOCKS_MASK; |
| 3511 | active->trans_wm.cursor_res_l = |
| 3512 | (val >> PLANE_WM_LINES_SHIFT) & |
| 3513 | PLANE_WM_LINES_MASK; |
| 3514 | } |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3519 | { |
| 3520 | struct drm_device *dev = crtc->dev; |
| 3521 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3522 | struct skl_wm_values *hw = &dev_priv->wm.skl_hw; |
| 3523 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3524 | struct skl_pipe_wm *active = &intel_crtc->wm.skl_active; |
| 3525 | enum pipe pipe = intel_crtc->pipe; |
| 3526 | int level, i, max_level; |
| 3527 | uint32_t temp; |
| 3528 | |
| 3529 | max_level = ilk_wm_max_level(dev); |
| 3530 | |
| 3531 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
| 3532 | |
| 3533 | for (level = 0; level <= max_level; level++) { |
| 3534 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3535 | hw->plane[pipe][i][level] = |
| 3536 | I915_READ(PLANE_WM(pipe, i, level)); |
| 3537 | hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level)); |
| 3538 | } |
| 3539 | |
| 3540 | for (i = 0; i < intel_num_planes(intel_crtc); i++) |
| 3541 | hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i)); |
| 3542 | hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe)); |
| 3543 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3544 | if (!intel_crtc->active) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3545 | return; |
| 3546 | |
| 3547 | hw->dirty[pipe] = true; |
| 3548 | |
| 3549 | active->linetime = hw->wm_linetime[pipe]; |
| 3550 | |
| 3551 | for (level = 0; level <= max_level; level++) { |
| 3552 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3553 | temp = hw->plane[pipe][i][level]; |
| 3554 | skl_pipe_wm_active_state(temp, active, false, |
| 3555 | false, i, level); |
| 3556 | } |
| 3557 | temp = hw->cursor[pipe][level]; |
| 3558 | skl_pipe_wm_active_state(temp, active, false, true, i, level); |
| 3559 | } |
| 3560 | |
| 3561 | for (i = 0; i < intel_num_planes(intel_crtc); i++) { |
| 3562 | temp = hw->plane_trans[pipe][i]; |
| 3563 | skl_pipe_wm_active_state(temp, active, true, false, i, 0); |
| 3564 | } |
| 3565 | |
| 3566 | temp = hw->cursor_trans[pipe]; |
| 3567 | skl_pipe_wm_active_state(temp, active, true, true, i, 0); |
| 3568 | } |
| 3569 | |
| 3570 | void skl_wm_get_hw_state(struct drm_device *dev) |
| 3571 | { |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3572 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3573 | struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3574 | struct drm_crtc *crtc; |
| 3575 | |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 3576 | skl_ddb_get_hw_state(dev_priv, ddb); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 3577 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3578 | skl_pipe_wm_get_hw_state(crtc); |
| 3579 | } |
| 3580 | |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3581 | static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc) |
| 3582 | { |
| 3583 | struct drm_device *dev = crtc->dev; |
| 3584 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3585 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3586 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3587 | struct intel_pipe_wm *active = &intel_crtc->wm.active; |
| 3588 | enum pipe pipe = intel_crtc->pipe; |
| 3589 | static const unsigned int wm0_pipe_reg[] = { |
| 3590 | [PIPE_A] = WM0_PIPEA_ILK, |
| 3591 | [PIPE_B] = WM0_PIPEB_ILK, |
| 3592 | [PIPE_C] = WM0_PIPEC_IVB, |
| 3593 | }; |
| 3594 | |
| 3595 | hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]); |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3596 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ce0e071 | 2013-12-05 15:51:36 +0200 | [diff] [blame] | 3597 | hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe)); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3598 | |
Matt Roper | 3ef0028 | 2015-03-09 10:19:24 -0700 | [diff] [blame] | 3599 | active->pipe_enabled = intel_crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 3600 | |
| 3601 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3602 | u32 tmp = hw->wm_pipe[pipe]; |
| 3603 | |
| 3604 | /* |
| 3605 | * For active pipes LP0 watermark is marked as |
| 3606 | * enabled, and LP1+ watermaks as disabled since |
| 3607 | * we can't really reverse compute them in case |
| 3608 | * multiple pipes are active. |
| 3609 | */ |
| 3610 | active->wm[0].enable = true; |
| 3611 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 3612 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 3613 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
| 3614 | active->linetime = hw->wm_linetime[pipe]; |
| 3615 | } else { |
| 3616 | int level, max_level = ilk_wm_max_level(dev); |
| 3617 | |
| 3618 | /* |
| 3619 | * For inactive pipes, all watermark levels |
| 3620 | * should be marked as enabled but zeroed, |
| 3621 | * which is what we'd compute them to. |
| 3622 | */ |
| 3623 | for (level = 0; level <= max_level; level++) |
| 3624 | active->wm[level].enable = true; |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | void ilk_wm_get_hw_state(struct drm_device *dev) |
| 3629 | { |
| 3630 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3631 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3632 | struct drm_crtc *crtc; |
| 3633 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3634 | for_each_crtc(dev, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3635 | ilk_pipe_wm_get_hw_state(crtc); |
| 3636 | |
| 3637 | hw->wm_lp[0] = I915_READ(WM1_LP_ILK); |
| 3638 | hw->wm_lp[1] = I915_READ(WM2_LP_ILK); |
| 3639 | hw->wm_lp[2] = I915_READ(WM3_LP_ILK); |
| 3640 | |
| 3641 | hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK); |
Ville Syrjälä | cfa7698 | 2014-03-07 18:32:08 +0200 | [diff] [blame] | 3642 | if (INTEL_INFO(dev)->gen >= 7) { |
| 3643 | hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB); |
| 3644 | hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB); |
| 3645 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3646 | |
Ville Syrjälä | a42a571 | 2014-01-07 16:14:08 +0200 | [diff] [blame] | 3647 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3648 | hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ? |
| 3649 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
| 3650 | else if (IS_IVYBRIDGE(dev)) |
| 3651 | hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ? |
| 3652 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 3653 | |
| 3654 | hw->enable_fbc_wm = |
| 3655 | !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS); |
| 3656 | } |
| 3657 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3658 | /** |
| 3659 | * intel_update_watermarks - update FIFO watermark values based on current modes |
| 3660 | * |
| 3661 | * Calculate watermark values for the various WM regs based on current mode |
| 3662 | * and plane configuration. |
| 3663 | * |
| 3664 | * There are several cases to deal with here: |
| 3665 | * - normal (i.e. non-self-refresh) |
| 3666 | * - self-refresh (SR) mode |
| 3667 | * - lines are large relative to FIFO size (buffer can hold up to 2) |
| 3668 | * - lines are small relative to FIFO size (buffer can hold more than 2 |
| 3669 | * lines), so need to account for TLB latency |
| 3670 | * |
| 3671 | * The normal calculation is: |
| 3672 | * watermark = dotclock * bytes per pixel * latency |
| 3673 | * where latency is platform & configuration dependent (we assume pessimal |
| 3674 | * values here). |
| 3675 | * |
| 3676 | * The SR calculation is: |
| 3677 | * watermark = (trunc(latency/line time)+1) * surface width * |
| 3678 | * bytes per pixel |
| 3679 | * where |
| 3680 | * line time = htotal / dotclock |
| 3681 | * surface width = hdisplay for normal plane and 64 for cursor |
| 3682 | * and latency is assumed to be high, as above. |
| 3683 | * |
| 3684 | * The final value programmed to the register should always be rounded up, |
| 3685 | * and include an extra 2 entries to account for clock crossings. |
| 3686 | * |
| 3687 | * We don't use the sprite, so we can ignore that. And on Crestline we have |
| 3688 | * to set the non-SR watermarks to 8. |
| 3689 | */ |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3690 | void intel_update_watermarks(struct drm_crtc *crtc) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3691 | { |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3692 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3693 | |
| 3694 | if (dev_priv->display.update_wm) |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 3695 | dev_priv->display.update_wm(crtc); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3696 | } |
| 3697 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3698 | void intel_update_sprite_watermarks(struct drm_plane *plane, |
| 3699 | struct drm_crtc *crtc, |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3700 | uint32_t sprite_width, |
| 3701 | uint32_t sprite_height, |
| 3702 | int pixel_size, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3703 | bool enabled, bool scaled) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3704 | { |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 3705 | struct drm_i915_private *dev_priv = plane->dev->dev_private; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3706 | |
| 3707 | if (dev_priv->display.update_sprite_wm) |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 3708 | dev_priv->display.update_sprite_wm(plane, crtc, |
| 3709 | sprite_width, sprite_height, |
Ville Syrjälä | 39db4a4 | 2013-08-06 22:24:00 +0300 | [diff] [blame] | 3710 | pixel_size, enabled, scaled); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 3711 | } |
| 3712 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3713 | /** |
| 3714 | * Lock protecting IPS related data structures |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3715 | */ |
| 3716 | DEFINE_SPINLOCK(mchdev_lock); |
| 3717 | |
| 3718 | /* Global for IPS driver to get at the current i915 device. Protected by |
| 3719 | * mchdev_lock. */ |
| 3720 | static struct drm_i915_private *i915_mch_dev; |
| 3721 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3722 | bool ironlake_set_drps(struct drm_device *dev, u8 val) |
| 3723 | { |
| 3724 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3725 | u16 rgvswctl; |
| 3726 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3727 | assert_spin_locked(&mchdev_lock); |
| 3728 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3729 | rgvswctl = I915_READ16(MEMSWCTL); |
| 3730 | if (rgvswctl & MEMCTL_CMD_STS) { |
| 3731 | DRM_DEBUG("gpu busy, RCS change rejected\n"); |
| 3732 | return false; /* still busy with another command */ |
| 3733 | } |
| 3734 | |
| 3735 | rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | |
| 3736 | (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; |
| 3737 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3738 | POSTING_READ16(MEMSWCTL); |
| 3739 | |
| 3740 | rgvswctl |= MEMCTL_CMD_STS; |
| 3741 | I915_WRITE16(MEMSWCTL, rgvswctl); |
| 3742 | |
| 3743 | return true; |
| 3744 | } |
| 3745 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3746 | static void ironlake_enable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3747 | { |
| 3748 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3749 | u32 rgvmodectl = I915_READ(MEMMODECTL); |
| 3750 | u8 fmax, fmin, fstart, vstart; |
| 3751 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3752 | spin_lock_irq(&mchdev_lock); |
| 3753 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3754 | /* Enable temp reporting */ |
| 3755 | I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN); |
| 3756 | I915_WRITE16(TSC1, I915_READ(TSC1) | TSE); |
| 3757 | |
| 3758 | /* 100ms RC evaluation intervals */ |
| 3759 | I915_WRITE(RCUPEI, 100000); |
| 3760 | I915_WRITE(RCDNEI, 100000); |
| 3761 | |
| 3762 | /* Set max/min thresholds to 90ms and 80ms respectively */ |
| 3763 | I915_WRITE(RCBMAXAVG, 90000); |
| 3764 | I915_WRITE(RCBMINAVG, 80000); |
| 3765 | |
| 3766 | I915_WRITE(MEMIHYST, 1); |
| 3767 | |
| 3768 | /* Set up min, max, and cur for interrupt handling */ |
| 3769 | fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; |
| 3770 | fmin = (rgvmodectl & MEMMODE_FMIN_MASK); |
| 3771 | fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> |
| 3772 | MEMMODE_FSTART_SHIFT; |
| 3773 | |
| 3774 | vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> |
| 3775 | PXVFREQ_PX_SHIFT; |
| 3776 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3777 | dev_priv->ips.fmax = fmax; /* IPS callback will increase this */ |
| 3778 | dev_priv->ips.fstart = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3779 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3780 | dev_priv->ips.max_delay = fstart; |
| 3781 | dev_priv->ips.min_delay = fmin; |
| 3782 | dev_priv->ips.cur_delay = fstart; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3783 | |
| 3784 | DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n", |
| 3785 | fmax, fmin, fstart); |
| 3786 | |
| 3787 | I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); |
| 3788 | |
| 3789 | /* |
| 3790 | * Interrupts will be enabled in ironlake_irq_postinstall |
| 3791 | */ |
| 3792 | |
| 3793 | I915_WRITE(VIDSTART, vstart); |
| 3794 | POSTING_READ(VIDSTART); |
| 3795 | |
| 3796 | rgvmodectl |= MEMMODE_SWMODE_EN; |
| 3797 | I915_WRITE(MEMMODECTL, rgvmodectl); |
| 3798 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3799 | if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10)) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3800 | DRM_ERROR("stuck trying to change perf mode\n"); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3801 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3802 | |
| 3803 | ironlake_set_drps(dev, fstart); |
| 3804 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3805 | dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) + |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3806 | I915_READ(0x112e0); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3807 | dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies); |
| 3808 | dev_priv->ips.last_count2 = I915_READ(0x112f4); |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 3809 | dev_priv->ips.last_time2 = ktime_get_raw_ns(); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3810 | |
| 3811 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3812 | } |
| 3813 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 3814 | static void ironlake_disable_drps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3815 | { |
| 3816 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3817 | u16 rgvswctl; |
| 3818 | |
| 3819 | spin_lock_irq(&mchdev_lock); |
| 3820 | |
| 3821 | rgvswctl = I915_READ16(MEMSWCTL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3822 | |
| 3823 | /* Ack interrupts, disable EFC interrupt */ |
| 3824 | I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); |
| 3825 | I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); |
| 3826 | I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); |
| 3827 | I915_WRITE(DEIIR, DE_PCU_EVENT); |
| 3828 | I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); |
| 3829 | |
| 3830 | /* Go back to the starting frequency */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 3831 | ironlake_set_drps(dev, dev_priv->ips.fstart); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3832 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3833 | rgvswctl |= MEMCTL_CMD_STS; |
| 3834 | I915_WRITE(MEMSWCTL, rgvswctl); |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3835 | mdelay(1); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3836 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 3837 | spin_unlock_irq(&mchdev_lock); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3838 | } |
| 3839 | |
Daniel Vetter | acbe947 | 2012-07-26 11:50:05 +0200 | [diff] [blame] | 3840 | /* There's a funny hw issue where the hw returns all 0 when reading from |
| 3841 | * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value |
| 3842 | * ourselves, instead of doing a rmw cycle (which might result in us clearing |
| 3843 | * all limits and the gpu stuck at whatever frequency it is at atm). |
| 3844 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3845 | 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] | 3846 | { |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3847 | u32 limits; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 3848 | |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3849 | /* Only set the down limit when we've reached the lowest level to avoid |
| 3850 | * getting more interrupts, otherwise leave this clear. This prevents a |
| 3851 | * race in the hw when coming out of rc6: There's a tiny window where |
| 3852 | * the hw runs at the minimal clock before selecting the desired |
| 3853 | * frequency, if the down threshold expires in that window we will not |
| 3854 | * receive a down interrupt. */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 3855 | if (IS_GEN9(dev_priv->dev)) { |
| 3856 | limits = (dev_priv->rps.max_freq_softlimit) << 23; |
| 3857 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3858 | limits |= (dev_priv->rps.min_freq_softlimit) << 14; |
| 3859 | } else { |
| 3860 | limits = dev_priv->rps.max_freq_softlimit << 24; |
| 3861 | if (val <= dev_priv->rps.min_freq_softlimit) |
| 3862 | limits |= dev_priv->rps.min_freq_softlimit << 16; |
| 3863 | } |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3864 | |
| 3865 | return limits; |
| 3866 | } |
| 3867 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3868 | static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val) |
| 3869 | { |
| 3870 | int new_power; |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3871 | u32 threshold_up = 0, threshold_down = 0; /* in % */ |
| 3872 | u32 ei_up = 0, ei_down = 0; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3873 | |
| 3874 | new_power = dev_priv->rps.power; |
| 3875 | switch (dev_priv->rps.power) { |
| 3876 | case LOW_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3877 | 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] | 3878 | new_power = BETWEEN; |
| 3879 | break; |
| 3880 | |
| 3881 | case BETWEEN: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3882 | 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] | 3883 | new_power = LOW_POWER; |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3884 | 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] | 3885 | new_power = HIGH_POWER; |
| 3886 | break; |
| 3887 | |
| 3888 | case HIGH_POWER: |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 3889 | 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] | 3890 | new_power = BETWEEN; |
| 3891 | break; |
| 3892 | } |
| 3893 | /* Max/min bins are special */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3894 | if (val <= dev_priv->rps.min_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3895 | new_power = LOW_POWER; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3896 | if (val >= dev_priv->rps.max_freq_softlimit) |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3897 | new_power = HIGH_POWER; |
| 3898 | if (new_power == dev_priv->rps.power) |
| 3899 | return; |
| 3900 | |
| 3901 | /* Note the units here are not exactly 1us, but 1280ns. */ |
| 3902 | switch (new_power) { |
| 3903 | case LOW_POWER: |
| 3904 | /* Upclock if more than 95% busy over 16ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3905 | ei_up = 16000; |
| 3906 | threshold_up = 95; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3907 | |
| 3908 | /* Downclock if less than 85% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3909 | ei_down = 32000; |
| 3910 | threshold_down = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3911 | break; |
| 3912 | |
| 3913 | case BETWEEN: |
| 3914 | /* Upclock if more than 90% busy over 13ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3915 | ei_up = 13000; |
| 3916 | threshold_up = 90; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3917 | |
| 3918 | /* Downclock if less than 75% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3919 | ei_down = 32000; |
| 3920 | threshold_down = 75; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3921 | break; |
| 3922 | |
| 3923 | case HIGH_POWER: |
| 3924 | /* Upclock if more than 85% busy over 10ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3925 | ei_up = 10000; |
| 3926 | threshold_up = 85; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3927 | |
| 3928 | /* Downclock if less than 60% busy over 32ms */ |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3929 | ei_down = 32000; |
| 3930 | threshold_down = 60; |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3931 | break; |
| 3932 | } |
| 3933 | |
Akash Goel | 8a58643 | 2015-03-06 11:07:18 +0530 | [diff] [blame] | 3934 | I915_WRITE(GEN6_RP_UP_EI, |
| 3935 | GT_INTERVAL_FROM_US(dev_priv, ei_up)); |
| 3936 | I915_WRITE(GEN6_RP_UP_THRESHOLD, |
| 3937 | GT_INTERVAL_FROM_US(dev_priv, (ei_up * threshold_up / 100))); |
| 3938 | |
| 3939 | I915_WRITE(GEN6_RP_DOWN_EI, |
| 3940 | GT_INTERVAL_FROM_US(dev_priv, ei_down)); |
| 3941 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, |
| 3942 | GT_INTERVAL_FROM_US(dev_priv, (ei_down * threshold_down / 100))); |
| 3943 | |
| 3944 | I915_WRITE(GEN6_RP_CONTROL, |
| 3945 | GEN6_RP_MEDIA_TURBO | |
| 3946 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 3947 | GEN6_RP_MEDIA_IS_GFX | |
| 3948 | GEN6_RP_ENABLE | |
| 3949 | GEN6_RP_UP_BUSY_AVG | |
| 3950 | GEN6_RP_DOWN_IDLE_AVG); |
| 3951 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 3952 | dev_priv->rps.power = new_power; |
| 3953 | dev_priv->rps.last_adj = 0; |
| 3954 | } |
| 3955 | |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3956 | static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val) |
| 3957 | { |
| 3958 | u32 mask = 0; |
| 3959 | |
| 3960 | if (val > dev_priv->rps.min_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3961 | 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] | 3962 | if (val < dev_priv->rps.max_freq_softlimit) |
Chris Wilson | 6f4b12f8 | 2015-03-18 09:48:23 +0000 | [diff] [blame] | 3963 | mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD; |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3964 | |
Chris Wilson | 7b3c29f | 2014-07-10 20:31:19 +0100 | [diff] [blame] | 3965 | mask &= dev_priv->pm_rps_events; |
| 3966 | |
Imre Deak | 59d02a1 | 2014-12-19 19:33:26 +0200 | [diff] [blame] | 3967 | return gen6_sanitize_rps_pm_mask(dev_priv, ~mask); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3970 | /* gen6_set_rps is called to update the frequency request, but should also be |
| 3971 | * called when the range (min_delay and max_delay) is modified so that we can |
| 3972 | * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */ |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 3973 | static void gen6_set_rps(struct drm_device *dev, u8 val) |
Daniel Vetter | 20b46e5 | 2012-07-26 11:16:14 +0200 | [diff] [blame] | 3974 | { |
| 3975 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3976 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 3977 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 3978 | WARN_ON(val > dev_priv->rps.max_freq); |
| 3979 | WARN_ON(val < dev_priv->rps.min_freq); |
Daniel Vetter | 004777c | 2012-08-09 15:07:01 +0200 | [diff] [blame] | 3980 | |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3981 | /* min/max delay may still have been modified so be sure to |
| 3982 | * write the limits value. |
| 3983 | */ |
| 3984 | if (val != dev_priv->rps.cur_freq) { |
| 3985 | gen6_set_rps_thresholds(dev_priv, val); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3986 | |
Akash Goel | 5704195 | 2015-03-06 11:07:17 +0530 | [diff] [blame] | 3987 | if (IS_GEN9(dev)) |
| 3988 | I915_WRITE(GEN6_RPNSWREQ, |
| 3989 | GEN9_FREQUENCY(val)); |
| 3990 | else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Chris Wilson | eb64cad | 2014-03-27 08:24:20 +0000 | [diff] [blame] | 3991 | I915_WRITE(GEN6_RPNSWREQ, |
| 3992 | HSW_FREQUENCY(val)); |
| 3993 | else |
| 3994 | I915_WRITE(GEN6_RPNSWREQ, |
| 3995 | GEN6_FREQUENCY(val) | |
| 3996 | GEN6_OFFSET(0) | |
| 3997 | GEN6_AGGRESSIVE_TURBO); |
Jeff McGee | b8a5ff8 | 2014-02-04 11:37:01 -0600 | [diff] [blame] | 3998 | } |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 3999 | |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4000 | /* Make sure we continue to get interrupts |
| 4001 | * until we hit the minimum or maximum frequencies. |
| 4002 | */ |
Akash Goel | 74ef117 | 2015-03-06 11:07:19 +0530 | [diff] [blame] | 4003 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val)); |
Chris Wilson | 2876ce7 | 2014-03-28 08:03:34 +0000 | [diff] [blame] | 4004 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Chris Wilson | 7b9e0ae | 2012-04-28 08:56:39 +0100 | [diff] [blame] | 4005 | |
Ben Widawsky | d5570a7 | 2012-09-07 19:43:41 -0700 | [diff] [blame] | 4006 | POSTING_READ(GEN6_RPNSWREQ); |
| 4007 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4008 | dev_priv->rps.cur_freq = val; |
Daniel Vetter | be2cde9a | 2012-08-30 13:26:48 +0200 | [diff] [blame] | 4009 | trace_intel_gpu_freq_change(val * 50); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4010 | } |
| 4011 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4012 | static void valleyview_set_rps(struct drm_device *dev, u8 val) |
| 4013 | { |
| 4014 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4015 | |
| 4016 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4017 | WARN_ON(val > dev_priv->rps.max_freq); |
| 4018 | WARN_ON(val < dev_priv->rps.min_freq); |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4019 | |
| 4020 | if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1), |
| 4021 | "Odd GPU freq value\n")) |
| 4022 | val &= ~1; |
| 4023 | |
| 4024 | if (val != dev_priv->rps.cur_freq) |
| 4025 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
| 4026 | |
| 4027 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
| 4028 | |
| 4029 | dev_priv->rps.cur_freq = val; |
| 4030 | trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val)); |
| 4031 | } |
| 4032 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4033 | /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down |
| 4034 | * |
| 4035 | * * If Gfx is Idle, then |
| 4036 | * 1. Mask Turbo interrupts |
| 4037 | * 2. Bring up Gfx clock |
| 4038 | * 3. Change the freq to Rpn and wait till P-Unit updates freq |
| 4039 | * 4. Clear the Force GFX CLK ON bit so that Gfx can down |
| 4040 | * 5. Unmask Turbo interrupts |
| 4041 | */ |
| 4042 | static void vlv_set_rps_idle(struct drm_i915_private *dev_priv) |
| 4043 | { |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4044 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4045 | u32 val = dev_priv->rps.idle_freq; |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4046 | |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4047 | /* CHV and latest VLV don't need to force the gfx clock */ |
| 4048 | if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) { |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4049 | valleyview_set_rps(dev_priv->dev, val); |
Deepak S | 5549d25 | 2014-06-28 11:26:11 +0530 | [diff] [blame] | 4050 | return; |
| 4051 | } |
| 4052 | |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4053 | /* |
| 4054 | * When we are idle. Drop to min voltage state. |
| 4055 | */ |
| 4056 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4057 | if (dev_priv->rps.cur_freq <= val) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4058 | return; |
| 4059 | |
| 4060 | /* Mask turbo interrupt so that they will not come in between */ |
Imre Deak | f24eeb1 | 2014-12-19 19:33:27 +0200 | [diff] [blame] | 4061 | I915_WRITE(GEN6_PMINTRMSK, |
| 4062 | gen6_sanitize_rps_pm_mask(dev_priv, ~0)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4063 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4064 | vlv_force_gfx_clock(dev_priv, true); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4065 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4066 | dev_priv->rps.cur_freq = val; |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4067 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4068 | vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4069 | |
| 4070 | 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] | 4071 | & GENFREQSTATUS) == 0, 100)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4072 | DRM_ERROR("timed out waiting for Punit\n"); |
| 4073 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 4074 | vlv_force_gfx_clock(dev_priv, false); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4075 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4076 | I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val)); |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4077 | } |
| 4078 | |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4079 | void gen6_rps_busy(struct drm_i915_private *dev_priv) |
| 4080 | { |
| 4081 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4082 | if (dev_priv->rps.enabled) { |
| 4083 | if (dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) |
| 4084 | gen6_rps_reset_ei(dev_priv); |
| 4085 | I915_WRITE(GEN6_PMINTRMSK, |
| 4086 | gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq)); |
| 4087 | } |
| 4088 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4089 | } |
| 4090 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4091 | void gen6_rps_idle(struct drm_i915_private *dev_priv) |
| 4092 | { |
Damien Lespiau | 691bb71 | 2013-12-12 14:36:36 +0000 | [diff] [blame] | 4093 | struct drm_device *dev = dev_priv->dev; |
| 4094 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4095 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4096 | if (dev_priv->rps.enabled) { |
Ville Syrjälä | 21a11ff | 2015-01-27 16:36:15 +0200 | [diff] [blame] | 4097 | if (IS_VALLEYVIEW(dev)) |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 4098 | vlv_set_rps_idle(dev_priv); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4099 | else |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4100 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4101 | dev_priv->rps.last_adj = 0; |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4102 | I915_WRITE(GEN6_PMINTRMSK, 0xffffffff); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4103 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4104 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4105 | } |
| 4106 | |
| 4107 | void gen6_rps_boost(struct drm_i915_private *dev_priv) |
| 4108 | { |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4109 | u32 val; |
| 4110 | |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4111 | mutex_lock(&dev_priv->rps.hw_lock); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 4112 | val = dev_priv->rps.max_freq_softlimit; |
| 4113 | if (dev_priv->rps.enabled && |
| 4114 | dev_priv->mm.busy && |
| 4115 | dev_priv->rps.cur_freq < val) { |
| 4116 | intel_set_rps(dev_priv->dev, val); |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 4117 | dev_priv->rps.last_adj = 0; |
| 4118 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 4119 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4120 | } |
| 4121 | |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4122 | void intel_set_rps(struct drm_device *dev, u8 val) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4123 | { |
Ville Syrjälä | ffe02b4 | 2015-02-02 19:09:50 +0200 | [diff] [blame] | 4124 | if (IS_VALLEYVIEW(dev)) |
| 4125 | valleyview_set_rps(dev, val); |
| 4126 | else |
| 4127 | gen6_set_rps(dev, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4130 | static void gen9_disable_rps(struct drm_device *dev) |
| 4131 | { |
| 4132 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4133 | |
| 4134 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4135 | I915_WRITE(GEN9_PG_ENABLE, 0); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4136 | } |
| 4137 | |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4138 | static void gen6_disable_rps(struct drm_device *dev) |
| 4139 | { |
| 4140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4141 | |
| 4142 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4143 | I915_WRITE(GEN6_RPNSWREQ, 1 << 31); |
Daniel Vetter | 44fc7d5 | 2013-07-12 22:43:27 +0200 | [diff] [blame] | 4144 | } |
| 4145 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4146 | static void cherryview_disable_rps(struct drm_device *dev) |
| 4147 | { |
| 4148 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4149 | |
| 4150 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4151 | } |
| 4152 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4153 | static void valleyview_disable_rps(struct drm_device *dev) |
| 4154 | { |
| 4155 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4156 | |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4157 | /* we're doing forcewake before Disabling RC6, |
| 4158 | * This what the BIOS expects when going into suspend */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4159 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 98a2e5f | 2014-08-18 10:35:27 -0700 | [diff] [blame] | 4160 | |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4161 | I915_WRITE(GEN6_RC_CONTROL, 0); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4162 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4163 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4166 | static void intel_print_rc6_info(struct drm_device *dev, u32 mode) |
| 4167 | { |
Imre Deak | 91ca689 | 2014-04-14 20:24:25 +0300 | [diff] [blame] | 4168 | if (IS_VALLEYVIEW(dev)) { |
| 4169 | if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1))) |
| 4170 | mode = GEN6_RC_CTL_RC6_ENABLE; |
| 4171 | else |
| 4172 | mode = 0; |
| 4173 | } |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4174 | if (HAS_RC6p(dev)) |
| 4175 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n", |
| 4176 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off", |
| 4177 | (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off", |
| 4178 | (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off"); |
| 4179 | |
| 4180 | else |
| 4181 | DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n", |
| 4182 | (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off"); |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4183 | } |
| 4184 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4185 | 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] | 4186 | { |
Damien Lespiau | eb4926e | 2013-06-07 17:41:14 +0100 | [diff] [blame] | 4187 | /* No RC6 before Ironlake */ |
| 4188 | if (INTEL_INFO(dev)->gen < 5) |
| 4189 | return 0; |
| 4190 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4191 | /* RC6 is only on Ironlake mobile not on desktop */ |
| 4192 | if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev)) |
| 4193 | return 0; |
| 4194 | |
Daniel Vetter | 456470e | 2012-08-08 23:35:40 +0200 | [diff] [blame] | 4195 | /* Respect the kernel parameter if it is set */ |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4196 | if (enable_rc6 >= 0) { |
| 4197 | int mask; |
| 4198 | |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 4199 | if (HAS_RC6p(dev)) |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4200 | mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE | |
| 4201 | INTEL_RC6pp_ENABLE; |
| 4202 | else |
| 4203 | mask = INTEL_RC6_ENABLE; |
| 4204 | |
| 4205 | if ((enable_rc6 & mask) != enable_rc6) |
Daniel Vetter | 8dfd1f0 | 2014-08-04 11:15:56 +0200 | [diff] [blame] | 4206 | DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n", |
| 4207 | enable_rc6 & mask, enable_rc6, mask); |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4208 | |
| 4209 | return enable_rc6 & mask; |
| 4210 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4211 | |
Chris Wilson | 6567d74 | 2012-11-10 10:00:06 +0000 | [diff] [blame] | 4212 | /* Disable RC6 on Ironlake */ |
| 4213 | if (INTEL_INFO(dev)->gen == 5) |
| 4214 | return 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4215 | |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4216 | if (IS_IVYBRIDGE(dev)) |
Ben Widawsky | cca84a1 | 2014-01-28 20:25:38 -0800 | [diff] [blame] | 4217 | return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE); |
Ben Widawsky | 8bade1a | 2014-01-28 20:25:39 -0800 | [diff] [blame] | 4218 | |
| 4219 | return INTEL_RC6_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4220 | } |
| 4221 | |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 4222 | int intel_enable_rc6(const struct drm_device *dev) |
| 4223 | { |
| 4224 | return i915.enable_rc6; |
| 4225 | } |
| 4226 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4227 | static void gen6_init_rps_frequencies(struct drm_device *dev) |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4228 | { |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4229 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4230 | uint32_t rp_state_cap; |
| 4231 | u32 ddcc_status = 0; |
| 4232 | int ret; |
| 4233 | |
| 4234 | rp_state_cap = I915_READ(GEN6_RP_STATE_CAP); |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4235 | /* All of these values are in units of 50MHz */ |
| 4236 | dev_priv->rps.cur_freq = 0; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4237 | /* static values from HW: RP0 > RP1 > RPn (min_freq) */ |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4238 | dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4239 | dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff; |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4240 | dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff; |
Akash Goel | cee991c | 2015-03-06 11:07:16 +0530 | [diff] [blame] | 4241 | if (IS_SKYLAKE(dev)) { |
| 4242 | /* Store the frequency values in 16.66 MHZ units, which is |
| 4243 | the natural hardware unit for SKL */ |
| 4244 | dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER; |
| 4245 | dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER; |
| 4246 | dev_priv->rps.min_freq *= GEN9_FREQ_SCALER; |
| 4247 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4248 | /* hw_max = RP0 until we check for overclocking */ |
| 4249 | dev_priv->rps.max_freq = dev_priv->rps.rp0_freq; |
| 4250 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4251 | dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq; |
| 4252 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 4253 | ret = sandybridge_pcode_read(dev_priv, |
| 4254 | HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL, |
| 4255 | &ddcc_status); |
| 4256 | if (0 == ret) |
| 4257 | dev_priv->rps.efficient_freq = |
Tom O'Rourke | 46efa4a | 2015-02-10 23:06:46 -0800 | [diff] [blame] | 4258 | clamp_t(u8, |
| 4259 | ((ddcc_status >> 8) & 0xff), |
| 4260 | dev_priv->rps.min_freq, |
| 4261 | dev_priv->rps.max_freq); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4262 | } |
| 4263 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4264 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4265 | |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4266 | /* Preserve min/max settings in case of re-init */ |
| 4267 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4268 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4269 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4270 | if (dev_priv->rps.min_freq_softlimit == 0) { |
| 4271 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 4272 | dev_priv->rps.min_freq_softlimit = |
Tom O'Rourke | f4ab408 | 2014-11-19 14:21:53 -0800 | [diff] [blame] | 4273 | /* max(RPe, 450 MHz) */ |
| 4274 | max(dev_priv->rps.efficient_freq, (u8) 9); |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4275 | else |
| 4276 | dev_priv->rps.min_freq_softlimit = |
| 4277 | dev_priv->rps.min_freq; |
| 4278 | } |
Ben Widawsky | 3280e8b | 2014-03-31 17:16:42 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4281 | /* See the Gen9_GT_PM_Programming_Guide doc for the below */ |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4282 | static void gen9_enable_rps(struct drm_device *dev) |
| 4283 | { |
| 4284 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4285 | |
| 4286 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 4287 | |
Damien Lespiau | ba1c554 | 2015-01-16 18:07:26 +0000 | [diff] [blame] | 4288 | gen6_init_rps_frequencies(dev); |
| 4289 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4290 | /* Program defaults and thresholds for RPS*/ |
| 4291 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4292 | GEN9_FREQUENCY(dev_priv->rps.rp1_freq)); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4293 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4294 | /* 1 second timeout*/ |
| 4295 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, |
| 4296 | GT_INTERVAL_FROM_US(dev_priv, 1000000)); |
| 4297 | |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4298 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4299 | |
Akash Goel | 0beb059 | 2015-03-06 11:07:20 +0530 | [diff] [blame] | 4300 | /* Leaning on the below call to gen6_set_rps to program/setup the |
| 4301 | * Up/Down EI & threshold registers, as well as the RP_CONTROL, |
| 4302 | * RP_INTERRUPT_LIMITS & RPNSWREQ registers */ |
| 4303 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
| 4304 | gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 4305 | |
| 4306 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
| 4307 | } |
| 4308 | |
| 4309 | static void gen9_enable_rc6(struct drm_device *dev) |
| 4310 | { |
| 4311 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4312 | struct intel_engine_cs *ring; |
| 4313 | uint32_t rc6_mask = 0; |
| 4314 | int unused; |
| 4315 | |
| 4316 | /* 1a: Software RC state - RC0 */ |
| 4317 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4318 | |
| 4319 | /* 1b: Get forcewake during program sequence. Although the driver |
| 4320 | * 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] | 4321 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4322 | |
| 4323 | /* 2a: Disable RC states. */ |
| 4324 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4325 | |
| 4326 | /* 2b: Program RC6 thresholds.*/ |
| 4327 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16); |
| 4328 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4329 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4330 | for_each_ring(ring, dev_priv, unused) |
| 4331 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4332 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4333 | I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */ |
| 4334 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4335 | /* 2c: Program Coarse Power Gating Policies. */ |
| 4336 | I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25); |
| 4337 | I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25); |
| 4338 | |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4339 | /* 3a: Enable RC6 */ |
| 4340 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4341 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
| 4342 | DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? |
| 4343 | "on" : "off"); |
| 4344 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4345 | GEN6_RC_CTL_EI_MODE(1) | |
| 4346 | rc6_mask); |
| 4347 | |
Zhe Wang | 38c2352 | 2015-01-20 12:23:04 +0000 | [diff] [blame] | 4348 | /* 3b: Enable Coarse Power Gating only when RC6 is enabled */ |
| 4349 | I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? 3 : 0); |
| 4350 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4351 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 4352 | |
| 4353 | } |
| 4354 | |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4355 | static void gen8_enable_rps(struct drm_device *dev) |
| 4356 | { |
| 4357 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4358 | struct intel_engine_cs *ring; |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4359 | uint32_t rc6_mask = 0; |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4360 | int unused; |
| 4361 | |
| 4362 | /* 1a: Software RC state - RC0 */ |
| 4363 | I915_WRITE(GEN6_RC_STATE, 0); |
| 4364 | |
| 4365 | /* 1c & 1d: Get forcewake during program sequence. Although the driver |
| 4366 | * 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] | 4367 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4368 | |
| 4369 | /* 2a: Disable RC states. */ |
| 4370 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4371 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4372 | /* Initialize rps frequencies */ |
| 4373 | gen6_init_rps_frequencies(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4374 | |
| 4375 | /* 2b: Program RC6 thresholds.*/ |
| 4376 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 4377 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 4378 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 4379 | for_each_ring(ring, dev_priv, unused) |
| 4380 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 4381 | I915_WRITE(GEN6_RC_SLEEP, 0); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4382 | if (IS_BROADWELL(dev)) |
| 4383 | I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */ |
| 4384 | else |
| 4385 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4386 | |
| 4387 | /* 3: Enable RC6 */ |
| 4388 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
| 4389 | rc6_mask = GEN6_RC_CTL_RC6_ENABLE; |
Ben Widawsky | abbf9d2 | 2014-01-28 20:25:41 -0800 | [diff] [blame] | 4390 | intel_print_rc6_info(dev, rc6_mask); |
Tom O'Rourke | 0d68b25 | 2014-04-09 11:44:06 -0700 | [diff] [blame] | 4391 | if (IS_BROADWELL(dev)) |
| 4392 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4393 | GEN7_RC_CTL_TO_MODE | |
| 4394 | rc6_mask); |
| 4395 | else |
| 4396 | I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE | |
| 4397 | GEN6_RC_CTL_EI_MODE(1) | |
| 4398 | rc6_mask); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4399 | |
| 4400 | /* 4 Program defaults and thresholds for RPS*/ |
Ben Widawsky | f9bdc58 | 2014-03-31 17:16:41 -0700 | [diff] [blame] | 4401 | I915_WRITE(GEN6_RPNSWREQ, |
| 4402 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
| 4403 | I915_WRITE(GEN6_RC_VIDEO_FREQ, |
| 4404 | HSW_FREQUENCY(dev_priv->rps.rp1_freq)); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4405 | /* NB: Docs say 1s, and 1000000 - which aren't equivalent */ |
| 4406 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4407 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4408 | /* Docs recommend 900MHz, and 300 MHz respectively */ |
| 4409 | I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, |
| 4410 | dev_priv->rps.max_freq_softlimit << 24 | |
| 4411 | dev_priv->rps.min_freq_softlimit << 16); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4412 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4413 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */ |
| 4414 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/ |
| 4415 | I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */ |
| 4416 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */ |
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 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4419 | |
| 4420 | /* 5: Enable RPS */ |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4421 | I915_WRITE(GEN6_RP_CONTROL, |
| 4422 | GEN6_RP_MEDIA_TURBO | |
| 4423 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 4424 | GEN6_RP_MEDIA_IS_GFX | |
| 4425 | GEN6_RP_ENABLE | |
| 4426 | GEN6_RP_UP_BUSY_AVG | |
| 4427 | GEN6_RP_DOWN_IDLE_AVG); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4428 | |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4429 | /* 6: Ring frequency + overclocking (our driver does this later */ |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4430 | |
Tom O'Rourke | c7f3153 | 2014-11-19 14:21:54 -0800 | [diff] [blame] | 4431 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4432 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 4433 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4434 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4437 | static void gen6_enable_rps(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4438 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4439 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 4440 | struct intel_engine_cs *ring; |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4441 | u32 rc6vids, pcu_mbox = 0, rc6_mask = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4442 | u32 gtfifodbg; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4443 | int rc6_mode; |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4444 | int i, ret; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4445 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4446 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4447 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4448 | /* Here begins a magic sequence of register writes to enable |
| 4449 | * auto-downclocking. |
| 4450 | * |
| 4451 | * Perhaps there might be some value in exposing these to |
| 4452 | * userspace... |
| 4453 | */ |
| 4454 | I915_WRITE(GEN6_RC_STATE, 0); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4455 | |
| 4456 | /* Clear the DBG now so we don't confuse earlier errors */ |
| 4457 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
| 4458 | DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg); |
| 4459 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4460 | } |
| 4461 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4462 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4463 | |
Tom O'Rourke | 93ee292 | 2014-11-19 14:21:52 -0800 | [diff] [blame] | 4464 | /* Initialize rps frequencies */ |
| 4465 | gen6_init_rps_frequencies(dev); |
Jeff McGee | dd0a1aa | 2014-02-04 11:32:31 -0600 | [diff] [blame] | 4466 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4467 | /* disable the counters and set deterministic thresholds */ |
| 4468 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 4469 | |
| 4470 | I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16); |
| 4471 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30); |
| 4472 | I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30); |
| 4473 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 4474 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 4475 | |
Chris Wilson | b451951 | 2012-05-11 14:29:30 +0100 | [diff] [blame] | 4476 | for_each_ring(ring, dev_priv, i) |
| 4477 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4478 | |
| 4479 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 4480 | I915_WRITE(GEN6_RC1e_THRESHOLD, 1000); |
Daniel Vetter | 29c78f6 | 2013-11-16 16:04:26 +0100 | [diff] [blame] | 4481 | if (IS_IVYBRIDGE(dev)) |
Stéphane Marchesin | 351aa56 | 2013-08-13 11:55:17 -0700 | [diff] [blame] | 4482 | I915_WRITE(GEN6_RC6_THRESHOLD, 125000); |
| 4483 | else |
| 4484 | I915_WRITE(GEN6_RC6_THRESHOLD, 50000); |
Stéphane Marchesin | 0920a48 | 2013-01-29 19:41:59 -0800 | [diff] [blame] | 4485 | I915_WRITE(GEN6_RC6p_THRESHOLD, 150000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4486 | I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */ |
| 4487 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4488 | /* Check if we are enabling RC6 */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4489 | rc6_mode = intel_enable_rc6(dev_priv->dev); |
| 4490 | if (rc6_mode & INTEL_RC6_ENABLE) |
| 4491 | rc6_mask |= GEN6_RC_CTL_RC6_ENABLE; |
| 4492 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4493 | /* We don't use those on Haswell */ |
| 4494 | if (!IS_HASWELL(dev)) { |
| 4495 | if (rc6_mode & INTEL_RC6p_ENABLE) |
| 4496 | rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4497 | |
Eugeni Dodonov | 5a7dc92 | 2012-07-02 11:51:05 -0300 | [diff] [blame] | 4498 | if (rc6_mode & INTEL_RC6pp_ENABLE) |
| 4499 | rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE; |
| 4500 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4501 | |
Ben Widawsky | dc39fff | 2013-10-18 12:32:07 -0700 | [diff] [blame] | 4502 | intel_print_rc6_info(dev, rc6_mask); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4503 | |
| 4504 | I915_WRITE(GEN6_RC_CONTROL, |
| 4505 | rc6_mask | |
| 4506 | GEN6_RC_CTL_EI_MODE(1) | |
| 4507 | GEN6_RC_CTL_HW_ENABLE); |
| 4508 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4509 | /* Power down if completely idle for over 50ms */ |
| 4510 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4511 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4512 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4513 | 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] | 4514 | if (ret) |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4515 | DRM_DEBUG_DRIVER("Failed to set the min frequency\n"); |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4516 | |
| 4517 | ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox); |
| 4518 | if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */ |
| 4519 | DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n", |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4520 | (dev_priv->rps.max_freq_softlimit & 0xff) * 50, |
Ben Widawsky | d060c16 | 2014-03-19 18:31:08 -0700 | [diff] [blame] | 4521 | (pcu_mbox & 0xff) * 50); |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 4522 | dev_priv->rps.max_freq = pcu_mbox & 0xff; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4523 | } |
| 4524 | |
Chris Wilson | dd75fdc | 2013-09-25 17:34:57 +0100 | [diff] [blame] | 4525 | dev_priv->rps.power = HIGH_POWER; /* force a reset */ |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4526 | gen6_set_rps(dev_priv->dev, dev_priv->rps.idle_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4527 | |
Ben Widawsky | 31643d5 | 2012-09-26 10:34:01 -0700 | [diff] [blame] | 4528 | rc6vids = 0; |
| 4529 | ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids); |
| 4530 | if (IS_GEN6(dev) && ret) { |
| 4531 | DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n"); |
| 4532 | } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { |
| 4533 | DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", |
| 4534 | GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450); |
| 4535 | rc6vids &= 0xffff00; |
| 4536 | rc6vids |= GEN6_ENCODE_RC6_VID(450); |
| 4537 | ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids); |
| 4538 | if (ret) |
| 4539 | DRM_ERROR("Couldn't fix incorrect rc6 voltage\n"); |
| 4540 | } |
| 4541 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 4542 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4543 | } |
| 4544 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4545 | static void __gen6_update_ring_freq(struct drm_device *dev) |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4546 | { |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4547 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4548 | int min_freq = 15; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4549 | unsigned int gpu_freq; |
| 4550 | unsigned int max_ia_freq, min_ring_freq; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4551 | int scaling_factor = 180; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4552 | struct cpufreq_policy *policy; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4553 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 4554 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 4555 | |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4556 | policy = cpufreq_cpu_get(0); |
| 4557 | if (policy) { |
| 4558 | max_ia_freq = policy->cpuinfo.max_freq; |
| 4559 | cpufreq_cpu_put(policy); |
| 4560 | } else { |
| 4561 | /* |
| 4562 | * Default to measured freq if none found, PCU will ensure we |
| 4563 | * don't go over |
| 4564 | */ |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4565 | max_ia_freq = tsc_khz; |
Ben Widawsky | eda7964 | 2013-10-07 17:15:48 -0300 | [diff] [blame] | 4566 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4567 | |
| 4568 | /* Convert from kHz to MHz */ |
| 4569 | max_ia_freq /= 1000; |
| 4570 | |
Ben Widawsky | 153b4b95 | 2013-10-22 22:05:09 -0700 | [diff] [blame] | 4571 | min_ring_freq = I915_READ(DCLK) & 0xf; |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4572 | /* convert DDR frequency from units of 266.6MHz to bandwidth */ |
| 4573 | min_ring_freq = mult_frac(min_ring_freq, 8, 3); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4574 | |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4575 | /* |
| 4576 | * For each potential GPU frequency, load a ring frequency we'd like |
| 4577 | * to use for memory access. We do this by specifying the IA frequency |
| 4578 | * the PCU should use as a reference to determine the ring frequency. |
| 4579 | */ |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4580 | 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] | 4581 | gpu_freq--) { |
Tom O'Rourke | 6985b35 | 2014-11-19 14:21:55 -0800 | [diff] [blame] | 4582 | int diff = dev_priv->rps.max_freq - gpu_freq; |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4583 | unsigned int ia_freq = 0, ring_freq = 0; |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4584 | |
Ben Widawsky | 46c764d | 2013-11-02 21:07:49 -0700 | [diff] [blame] | 4585 | if (INTEL_INFO(dev)->gen >= 8) { |
| 4586 | /* max(2 * GT, DDR). NB: GT is 50MHz units */ |
| 4587 | ring_freq = max(min_ring_freq, gpu_freq); |
| 4588 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | f6aca45 | 2013-10-02 09:25:02 -0700 | [diff] [blame] | 4589 | ring_freq = mult_frac(gpu_freq, 5, 4); |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4590 | ring_freq = max(min_ring_freq, ring_freq); |
| 4591 | /* leave ia_freq as the default, chosen by cpufreq */ |
| 4592 | } else { |
| 4593 | /* On older processors, there is no separate ring |
| 4594 | * clock domain, so in order to boost the bandwidth |
| 4595 | * of the ring, we need to upclock the CPU (ia_freq). |
| 4596 | * |
| 4597 | * For GPU frequencies less than 750MHz, |
| 4598 | * just use the lowest ring freq. |
| 4599 | */ |
| 4600 | if (gpu_freq < min_freq) |
| 4601 | ia_freq = 800; |
| 4602 | else |
| 4603 | ia_freq = max_ia_freq - ((diff * scaling_factor) / 2); |
| 4604 | ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100); |
| 4605 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4606 | |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 4607 | sandybridge_pcode_write(dev_priv, |
| 4608 | GEN6_PCODE_WRITE_MIN_FREQ_TABLE, |
Chris Wilson | 3ebecd0 | 2013-04-12 19:10:13 +0100 | [diff] [blame] | 4609 | ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT | |
| 4610 | ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT | |
| 4611 | gpu_freq); |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4612 | } |
Eugeni Dodonov | 2b4e57b | 2012-04-18 15:29:23 -0300 | [diff] [blame] | 4613 | } |
| 4614 | |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 4615 | void gen6_update_ring_freq(struct drm_device *dev) |
| 4616 | { |
| 4617 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4618 | |
| 4619 | if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev)) |
| 4620 | return; |
| 4621 | |
| 4622 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4623 | __gen6_update_ring_freq(dev); |
| 4624 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4625 | } |
| 4626 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4627 | static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4628 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4629 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4630 | u32 val, rp0; |
| 4631 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4632 | if (dev->pdev->revision >= 0x20) { |
| 4633 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4634 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4635 | switch (INTEL_INFO(dev)->eu_total) { |
| 4636 | case 8: |
| 4637 | /* (2 * 4) config */ |
| 4638 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT); |
| 4639 | break; |
| 4640 | case 12: |
| 4641 | /* (2 * 6) config */ |
| 4642 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT); |
| 4643 | break; |
| 4644 | case 16: |
| 4645 | /* (2 * 8) config */ |
| 4646 | default: |
| 4647 | /* Setting (2 * 8) Min RP0 for any other combination */ |
| 4648 | rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT); |
| 4649 | break; |
| 4650 | } |
| 4651 | rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK); |
| 4652 | } else { |
| 4653 | /* For pre-production hardware */ |
| 4654 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4655 | rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4656 | PUNIT_GPU_STATUS_MAX_FREQ_MASK; |
| 4657 | } |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4658 | return rp0; |
| 4659 | } |
| 4660 | |
| 4661 | static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4662 | { |
| 4663 | u32 val, rpe; |
| 4664 | |
| 4665 | val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG); |
| 4666 | rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK; |
| 4667 | |
| 4668 | return rpe; |
| 4669 | } |
| 4670 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4671 | static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4672 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4673 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4674 | u32 val, rp1; |
| 4675 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4676 | if (dev->pdev->revision >= 0x20) { |
| 4677 | val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE); |
| 4678 | rp1 = (val & FB_GFX_FREQ_FUSE_MASK); |
| 4679 | } else { |
| 4680 | /* For pre-production hardware */ |
| 4681 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4682 | rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) & |
| 4683 | PUNIT_GPU_STATUS_MAX_FREQ_MASK); |
| 4684 | } |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4685 | return rp1; |
| 4686 | } |
| 4687 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4688 | static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv) |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4689 | { |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4690 | struct drm_device *dev = dev_priv->dev; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4691 | u32 val, rpn; |
| 4692 | |
Deepak S | 095acd5 | 2015-01-17 11:05:59 +0530 | [diff] [blame] | 4693 | if (dev->pdev->revision >= 0x20) { |
| 4694 | val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE); |
| 4695 | rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) & |
| 4696 | FB_GFX_FREQ_FUSE_MASK); |
| 4697 | } else { /* For pre-production hardware */ |
| 4698 | val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG); |
| 4699 | rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) & |
| 4700 | PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK); |
| 4701 | } |
| 4702 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4703 | return rpn; |
| 4704 | } |
| 4705 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4706 | static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv) |
| 4707 | { |
| 4708 | u32 val, rp1; |
| 4709 | |
| 4710 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
| 4711 | |
| 4712 | rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT; |
| 4713 | |
| 4714 | return rp1; |
| 4715 | } |
| 4716 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4717 | static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4718 | { |
| 4719 | u32 val, rp0; |
| 4720 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4721 | val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4722 | |
| 4723 | rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT; |
| 4724 | /* Clamp to max */ |
| 4725 | rp0 = min_t(u32, rp0, 0xea); |
| 4726 | |
| 4727 | return rp0; |
| 4728 | } |
| 4729 | |
| 4730 | static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv) |
| 4731 | { |
| 4732 | u32 val, rpe; |
| 4733 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4734 | 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] | 4735 | 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] | 4736 | 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] | 4737 | rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5; |
| 4738 | |
| 4739 | return rpe; |
| 4740 | } |
| 4741 | |
Ville Syrjälä | 03af204 | 2014-06-28 02:03:53 +0300 | [diff] [blame] | 4742 | static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv) |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4743 | { |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 4744 | return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4747 | /* Check that the pctx buffer wasn't move under us. */ |
| 4748 | static void valleyview_check_pctx(struct drm_i915_private *dev_priv) |
| 4749 | { |
| 4750 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4751 | |
| 4752 | WARN_ON(pctx_addr != dev_priv->mm.stolen_base + |
| 4753 | dev_priv->vlv_pctx->stolen->start); |
| 4754 | } |
| 4755 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4756 | |
| 4757 | /* Check that the pcbr address is not empty. */ |
| 4758 | static void cherryview_check_pctx(struct drm_i915_private *dev_priv) |
| 4759 | { |
| 4760 | unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095; |
| 4761 | |
| 4762 | WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0); |
| 4763 | } |
| 4764 | |
| 4765 | static void cherryview_setup_pctx(struct drm_device *dev) |
| 4766 | { |
| 4767 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4768 | unsigned long pctx_paddr, paddr; |
| 4769 | struct i915_gtt *gtt = &dev_priv->gtt; |
| 4770 | u32 pcbr; |
| 4771 | int pctx_size = 32*1024; |
| 4772 | |
| 4773 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4774 | |
| 4775 | pcbr = I915_READ(VLV_PCBR); |
| 4776 | if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4777 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4778 | paddr = (dev_priv->mm.stolen_base + |
| 4779 | (gtt->stolen_size - pctx_size)); |
| 4780 | |
| 4781 | pctx_paddr = (paddr & (~4095)); |
| 4782 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4783 | } |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4784 | |
| 4785 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4786 | } |
| 4787 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4788 | static void valleyview_setup_pctx(struct drm_device *dev) |
| 4789 | { |
| 4790 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4791 | struct drm_i915_gem_object *pctx; |
| 4792 | unsigned long pctx_paddr; |
| 4793 | u32 pcbr; |
| 4794 | int pctx_size = 24*1024; |
| 4795 | |
Imre Deak | 17b0c1f | 2014-02-11 21:39:06 +0200 | [diff] [blame] | 4796 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 4797 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4798 | pcbr = I915_READ(VLV_PCBR); |
| 4799 | if (pcbr) { |
| 4800 | /* BIOS set it up already, grab the pre-alloc'd space */ |
| 4801 | int pcbr_offset; |
| 4802 | |
| 4803 | pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base; |
| 4804 | pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev, |
| 4805 | pcbr_offset, |
Daniel Vetter | 190d6cd | 2013-07-04 13:06:28 +0200 | [diff] [blame] | 4806 | I915_GTT_OFFSET_NONE, |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4807 | pctx_size); |
| 4808 | goto out; |
| 4809 | } |
| 4810 | |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4811 | DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); |
| 4812 | |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4813 | /* |
| 4814 | * From the Gunit register HAS: |
| 4815 | * The Gfx driver is expected to program this register and ensure |
| 4816 | * proper allocation within Gfx stolen memory. For example, this |
| 4817 | * register should be programmed such than the PCBR range does not |
| 4818 | * overlap with other ranges, such as the frame buffer, protected |
| 4819 | * memory, or any other relevant ranges. |
| 4820 | */ |
| 4821 | pctx = i915_gem_object_create_stolen(dev, pctx_size); |
| 4822 | if (!pctx) { |
| 4823 | DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); |
| 4824 | return; |
| 4825 | } |
| 4826 | |
| 4827 | pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; |
| 4828 | I915_WRITE(VLV_PCBR, pctx_paddr); |
| 4829 | |
| 4830 | out: |
Ville Syrjälä | ce611ef | 2014-11-07 21:33:46 +0200 | [diff] [blame] | 4831 | DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); |
Jesse Barnes | c9cddff | 2013-05-08 10:45:13 -0700 | [diff] [blame] | 4832 | dev_priv->vlv_pctx = pctx; |
| 4833 | } |
| 4834 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 4835 | static void valleyview_cleanup_pctx(struct drm_device *dev) |
| 4836 | { |
| 4837 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4838 | |
| 4839 | if (WARN_ON(!dev_priv->vlv_pctx)) |
| 4840 | return; |
| 4841 | |
| 4842 | drm_gem_object_unreference(&dev_priv->vlv_pctx->base); |
| 4843 | dev_priv->vlv_pctx = NULL; |
| 4844 | } |
| 4845 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4846 | static void valleyview_init_gt_powersave(struct drm_device *dev) |
| 4847 | { |
| 4848 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4849 | u32 val; |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4850 | |
| 4851 | valleyview_setup_pctx(dev); |
| 4852 | |
| 4853 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4854 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4855 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 4856 | switch ((val >> 6) & 3) { |
| 4857 | case 0: |
| 4858 | case 1: |
| 4859 | dev_priv->mem_freq = 800; |
| 4860 | break; |
| 4861 | case 2: |
| 4862 | dev_priv->mem_freq = 1066; |
| 4863 | break; |
| 4864 | case 3: |
| 4865 | dev_priv->mem_freq = 1333; |
| 4866 | break; |
| 4867 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4868 | 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] | 4869 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4870 | dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv); |
| 4871 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4872 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4873 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4874 | dev_priv->rps.max_freq); |
| 4875 | |
| 4876 | dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv); |
| 4877 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4878 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4879 | dev_priv->rps.efficient_freq); |
| 4880 | |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4881 | dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv); |
| 4882 | 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] | 4883 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | f8f2b00 | 2014-07-10 13:16:21 +0530 | [diff] [blame] | 4884 | dev_priv->rps.rp1_freq); |
| 4885 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4886 | dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv); |
| 4887 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4888 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4889 | dev_priv->rps.min_freq); |
| 4890 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4891 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4892 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4893 | /* Preserve min/max settings in case of re-init */ |
| 4894 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4895 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4896 | |
| 4897 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4898 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4899 | |
| 4900 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4901 | } |
| 4902 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4903 | static void cherryview_init_gt_powersave(struct drm_device *dev) |
| 4904 | { |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4905 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4906 | u32 val; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4907 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4908 | cherryview_setup_pctx(dev); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4909 | |
| 4910 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4911 | |
Ville Syrjälä | c6e8f39 | 2014-11-07 21:33:43 +0200 | [diff] [blame] | 4912 | mutex_lock(&dev_priv->dpio_lock); |
| 4913 | val = vlv_cck_read(dev_priv, CCK_FUSE_REG); |
| 4914 | mutex_unlock(&dev_priv->dpio_lock); |
| 4915 | |
Ville Syrjälä | 2bb25c1 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 4916 | switch ((val >> 2) & 0x7) { |
| 4917 | case 0: |
| 4918 | case 1: |
| 4919 | dev_priv->rps.cz_freq = 200; |
| 4920 | dev_priv->mem_freq = 1600; |
| 4921 | break; |
| 4922 | case 2: |
| 4923 | dev_priv->rps.cz_freq = 267; |
| 4924 | dev_priv->mem_freq = 1600; |
| 4925 | break; |
| 4926 | case 3: |
| 4927 | dev_priv->rps.cz_freq = 333; |
| 4928 | dev_priv->mem_freq = 2000; |
| 4929 | break; |
| 4930 | case 4: |
| 4931 | dev_priv->rps.cz_freq = 320; |
| 4932 | dev_priv->mem_freq = 1600; |
| 4933 | break; |
| 4934 | case 5: |
| 4935 | dev_priv->rps.cz_freq = 400; |
| 4936 | dev_priv->mem_freq = 1600; |
| 4937 | break; |
| 4938 | } |
Ville Syrjälä | 80b83b6 | 2014-11-10 22:55:14 +0200 | [diff] [blame] | 4939 | 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] | 4940 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4941 | dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv); |
| 4942 | dev_priv->rps.rp0_freq = dev_priv->rps.max_freq; |
| 4943 | DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4944 | intel_gpu_freq(dev_priv, dev_priv->rps.max_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4945 | dev_priv->rps.max_freq); |
| 4946 | |
| 4947 | dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv); |
| 4948 | DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4949 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4950 | dev_priv->rps.efficient_freq); |
| 4951 | |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4952 | dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv); |
| 4953 | DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4954 | intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq), |
Deepak S | 7707df4 | 2014-07-12 18:46:14 +0530 | [diff] [blame] | 4955 | dev_priv->rps.rp1_freq); |
| 4956 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4957 | dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv); |
| 4958 | DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 4959 | intel_gpu_freq(dev_priv, dev_priv->rps.min_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4960 | dev_priv->rps.min_freq); |
| 4961 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 4962 | WARN_ONCE((dev_priv->rps.max_freq | |
| 4963 | dev_priv->rps.efficient_freq | |
| 4964 | dev_priv->rps.rp1_freq | |
| 4965 | dev_priv->rps.min_freq) & 1, |
| 4966 | "Odd GPU freq values\n"); |
| 4967 | |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 4968 | dev_priv->rps.idle_freq = dev_priv->rps.min_freq; |
| 4969 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4970 | /* Preserve min/max settings in case of re-init */ |
| 4971 | if (dev_priv->rps.max_freq_softlimit == 0) |
| 4972 | dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq; |
| 4973 | |
| 4974 | if (dev_priv->rps.min_freq_softlimit == 0) |
| 4975 | dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq; |
| 4976 | |
| 4977 | mutex_unlock(&dev_priv->rps.hw_lock); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4978 | } |
| 4979 | |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 4980 | static void valleyview_cleanup_gt_powersave(struct drm_device *dev) |
| 4981 | { |
| 4982 | valleyview_cleanup_pctx(dev); |
| 4983 | } |
| 4984 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4985 | static void cherryview_enable_rps(struct drm_device *dev) |
| 4986 | { |
| 4987 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4988 | struct intel_engine_cs *ring; |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 4989 | u32 gtfifodbg, val, rc6_mode = 0, pcbr; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 4990 | int i; |
| 4991 | |
| 4992 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 4993 | |
| 4994 | gtfifodbg = I915_READ(GTFIFODBG); |
| 4995 | if (gtfifodbg) { |
| 4996 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 4997 | gtfifodbg); |
| 4998 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 4999 | } |
| 5000 | |
| 5001 | cherryview_check_pctx(dev_priv); |
| 5002 | |
| 5003 | /* 1a & 1b: Get forcewake during program sequence. Although the driver |
| 5004 | * 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] | 5005 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5006 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5007 | /* Disable RC states. */ |
| 5008 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5009 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5010 | /* 2a: Program RC6 thresholds.*/ |
| 5011 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16); |
| 5012 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */ |
| 5013 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */ |
| 5014 | |
| 5015 | for_each_ring(ring, dev_priv, i) |
| 5016 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5017 | I915_WRITE(GEN6_RC_SLEEP, 0); |
| 5018 | |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5019 | /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */ |
| 5020 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5021 | |
| 5022 | /* allows RC6 residency counter to work */ |
| 5023 | I915_WRITE(VLV_COUNTER_CONTROL, |
| 5024 | _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH | |
| 5025 | VLV_MEDIA_RC6_COUNT_EN | |
| 5026 | VLV_RENDER_RC6_COUNT_EN)); |
| 5027 | |
| 5028 | /* For now we assume BIOS is allocating and populating the PCBR */ |
| 5029 | pcbr = I915_READ(VLV_PCBR); |
| 5030 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5031 | /* 3: Enable RC6 */ |
| 5032 | if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && |
| 5033 | (pcbr >> VLV_PCBR_ADDR_SHIFT)) |
Ville Syrjälä | af5a75a | 2015-01-19 13:50:50 +0200 | [diff] [blame] | 5034 | rc6_mode = GEN7_RC_CTL_TO_MODE; |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5035 | |
| 5036 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
| 5037 | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5038 | /* 4 Program defaults and thresholds for RPS*/ |
Ville Syrjälä | 3cbdb48 | 2015-01-19 13:50:49 +0200 | [diff] [blame] | 5039 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5040 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5041 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5042 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5043 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5044 | |
| 5045 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5046 | |
| 5047 | /* 5: Enable RPS */ |
| 5048 | I915_WRITE(GEN6_RP_CONTROL, |
| 5049 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
Ville Syrjälä | eb973a5 | 2015-01-21 19:37:59 +0200 | [diff] [blame] | 5050 | GEN6_RP_MEDIA_IS_GFX | |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5051 | GEN6_RP_ENABLE | |
| 5052 | GEN6_RP_UP_BUSY_AVG | |
| 5053 | GEN6_RP_DOWN_IDLE_AVG); |
| 5054 | |
| 5055 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
| 5056 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5057 | /* RPS code assumes GPLL is used */ |
| 5058 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5059 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5060 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5061 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5062 | |
| 5063 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
| 5064 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5065 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5066 | dev_priv->rps.cur_freq); |
| 5067 | |
| 5068 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5069 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Deepak S | 2b6b3a0 | 2014-05-27 15:59:30 +0530 | [diff] [blame] | 5070 | dev_priv->rps.efficient_freq); |
| 5071 | |
| 5072 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
| 5073 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5074 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5075 | } |
| 5076 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5077 | static void valleyview_enable_rps(struct drm_device *dev) |
| 5078 | { |
| 5079 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5080 | struct intel_engine_cs *ring; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 5081 | u32 gtfifodbg, val, rc6_mode = 0; |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5082 | int i; |
| 5083 | |
| 5084 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
| 5085 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5086 | valleyview_check_pctx(dev_priv); |
| 5087 | |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5088 | if ((gtfifodbg = I915_READ(GTFIFODBG))) { |
Jesse Barnes | f7d85c1 | 2013-09-27 10:40:54 -0700 | [diff] [blame] | 5089 | DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n", |
| 5090 | gtfifodbg); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5091 | I915_WRITE(GTFIFODBG, gtfifodbg); |
| 5092 | } |
| 5093 | |
Deepak S | c8d9a59 | 2013-11-23 14:55:42 +0530 | [diff] [blame] | 5094 | /* If VLV, Forcewake all wells, else re-direct to regular path */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5095 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5096 | |
Ville Syrjälä | 160614a | 2015-01-19 13:50:47 +0200 | [diff] [blame] | 5097 | /* Disable RC states. */ |
| 5098 | I915_WRITE(GEN6_RC_CONTROL, 0); |
| 5099 | |
Ville Syrjälä | cad725f | 2015-01-19 13:50:48 +0200 | [diff] [blame] | 5100 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5101 | I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400); |
| 5102 | I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000); |
| 5103 | I915_WRITE(GEN6_RP_UP_EI, 66000); |
| 5104 | I915_WRITE(GEN6_RP_DOWN_EI, 350000); |
| 5105 | |
| 5106 | I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10); |
| 5107 | |
| 5108 | I915_WRITE(GEN6_RP_CONTROL, |
| 5109 | GEN6_RP_MEDIA_TURBO | |
| 5110 | GEN6_RP_MEDIA_HW_NORMAL_MODE | |
| 5111 | GEN6_RP_MEDIA_IS_GFX | |
| 5112 | GEN6_RP_ENABLE | |
| 5113 | GEN6_RP_UP_BUSY_AVG | |
| 5114 | GEN6_RP_DOWN_IDLE_CONT); |
| 5115 | |
| 5116 | I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000); |
| 5117 | I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); |
| 5118 | I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); |
| 5119 | |
| 5120 | for_each_ring(ring, dev_priv, i) |
| 5121 | I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); |
| 5122 | |
Jesse Barnes | 2f0aa304 | 2013-11-15 09:32:11 -0800 | [diff] [blame] | 5123 | I915_WRITE(GEN6_RC6_THRESHOLD, 0x557); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5124 | |
| 5125 | /* allows RC6 residency counter to work */ |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5126 | I915_WRITE(VLV_COUNTER_CONTROL, |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5127 | _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN | |
| 5128 | VLV_RENDER_RC0_COUNT_EN | |
Jesse Barnes | 49798eb | 2013-09-26 17:55:57 -0700 | [diff] [blame] | 5129 | VLV_MEDIA_RC6_COUNT_EN | |
| 5130 | VLV_RENDER_RC6_COUNT_EN)); |
Deepak S | 31685c2 | 2014-07-03 17:33:01 -0400 | [diff] [blame] | 5131 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5132 | if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE) |
Jesse Barnes | 6b88f29 | 2013-11-15 09:32:12 -0800 | [diff] [blame] | 5133 | 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] | 5134 | |
| 5135 | intel_print_rc6_info(dev, rc6_mode); |
| 5136 | |
Jesse Barnes | a2b23fe | 2013-09-19 09:33:13 -0700 | [diff] [blame] | 5137 | I915_WRITE(GEN6_RC_CONTROL, rc6_mode); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5138 | |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 5139 | val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5140 | |
Ville Syrjälä | 8d40c3a | 2014-11-07 21:33:45 +0200 | [diff] [blame] | 5141 | /* RPS code assumes GPLL is used */ |
| 5142 | WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n"); |
| 5143 | |
Ville Syrjälä | c8e9627 | 2014-11-07 21:33:44 +0200 | [diff] [blame] | 5144 | DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no"); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5145 | DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val); |
| 5146 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5147 | dev_priv->rps.cur_freq = (val >> 8) & 0xff; |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5148 | DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5149 | intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5150 | dev_priv->rps.cur_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5151 | |
Ville Syrjälä | 73008b9 | 2013-06-25 19:21:01 +0300 | [diff] [blame] | 5152 | DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 5153 | intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq), |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5154 | dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5155 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5156 | valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5157 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 5158 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5161 | static unsigned long intel_pxfreq(u32 vidfreq) |
| 5162 | { |
| 5163 | unsigned long freq; |
| 5164 | int div = (vidfreq & 0x3f0000) >> 16; |
| 5165 | int post = (vidfreq & 0x3000) >> 12; |
| 5166 | int pre = (vidfreq & 0x7); |
| 5167 | |
| 5168 | if (!pre) |
| 5169 | return 0; |
| 5170 | |
| 5171 | freq = ((div * 133333) / ((1<<post) * pre)); |
| 5172 | |
| 5173 | return freq; |
| 5174 | } |
| 5175 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5176 | static const struct cparams { |
| 5177 | u16 i; |
| 5178 | u16 t; |
| 5179 | u16 m; |
| 5180 | u16 c; |
| 5181 | } cparams[] = { |
| 5182 | { 1, 1333, 301, 28664 }, |
| 5183 | { 1, 1066, 294, 24460 }, |
| 5184 | { 1, 800, 294, 25192 }, |
| 5185 | { 0, 1333, 276, 27605 }, |
| 5186 | { 0, 1066, 276, 27605 }, |
| 5187 | { 0, 800, 231, 23784 }, |
| 5188 | }; |
| 5189 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5190 | static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5191 | { |
| 5192 | u64 total_count, diff, ret; |
| 5193 | u32 count1, count2, count3, m = 0, c = 0; |
| 5194 | unsigned long now = jiffies_to_msecs(jiffies), diff1; |
| 5195 | int i; |
| 5196 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5197 | assert_spin_locked(&mchdev_lock); |
| 5198 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5199 | diff1 = now - dev_priv->ips.last_time1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5200 | |
| 5201 | /* Prevent division-by-zero if we are asking too fast. |
| 5202 | * Also, we don't get interesting results if we are polling |
| 5203 | * faster than once in 10ms, so just return the saved value |
| 5204 | * in such cases. |
| 5205 | */ |
| 5206 | if (diff1 <= 10) |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5207 | return dev_priv->ips.chipset_power; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5208 | |
| 5209 | count1 = I915_READ(DMIEC); |
| 5210 | count2 = I915_READ(DDREC); |
| 5211 | count3 = I915_READ(CSIEC); |
| 5212 | |
| 5213 | total_count = count1 + count2 + count3; |
| 5214 | |
| 5215 | /* FIXME: handle per-counter overflow */ |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5216 | if (total_count < dev_priv->ips.last_count1) { |
| 5217 | diff = ~0UL - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5218 | diff += total_count; |
| 5219 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5220 | diff = total_count - dev_priv->ips.last_count1; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5221 | } |
| 5222 | |
| 5223 | for (i = 0; i < ARRAY_SIZE(cparams); i++) { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5224 | if (cparams[i].i == dev_priv->ips.c_m && |
| 5225 | cparams[i].t == dev_priv->ips.r_t) { |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5226 | m = cparams[i].m; |
| 5227 | c = cparams[i].c; |
| 5228 | break; |
| 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | diff = div_u64(diff, diff1); |
| 5233 | ret = ((m * diff) + c); |
| 5234 | ret = div_u64(ret, 10); |
| 5235 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5236 | dev_priv->ips.last_count1 = total_count; |
| 5237 | dev_priv->ips.last_time1 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5238 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5239 | dev_priv->ips.chipset_power = ret; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5240 | |
| 5241 | return ret; |
| 5242 | } |
| 5243 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5244 | unsigned long i915_chipset_val(struct drm_i915_private *dev_priv) |
| 5245 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5246 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5247 | unsigned long val; |
| 5248 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5249 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5250 | return 0; |
| 5251 | |
| 5252 | spin_lock_irq(&mchdev_lock); |
| 5253 | |
| 5254 | val = __i915_chipset_val(dev_priv); |
| 5255 | |
| 5256 | spin_unlock_irq(&mchdev_lock); |
| 5257 | |
| 5258 | return val; |
| 5259 | } |
| 5260 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5261 | unsigned long i915_mch_val(struct drm_i915_private *dev_priv) |
| 5262 | { |
| 5263 | unsigned long m, x, b; |
| 5264 | u32 tsfs; |
| 5265 | |
| 5266 | tsfs = I915_READ(TSFS); |
| 5267 | |
| 5268 | m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT); |
| 5269 | x = I915_READ8(TR1); |
| 5270 | |
| 5271 | b = tsfs & TSFS_INTR_MASK; |
| 5272 | |
| 5273 | return ((m * x) / 127) - b; |
| 5274 | } |
| 5275 | |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5276 | static int _pxvid_to_vd(u8 pxvid) |
| 5277 | { |
| 5278 | if (pxvid == 0) |
| 5279 | return 0; |
| 5280 | |
| 5281 | if (pxvid >= 8 && pxvid < 31) |
| 5282 | pxvid = 31; |
| 5283 | |
| 5284 | return (pxvid + 2) * 125; |
| 5285 | } |
| 5286 | |
| 5287 | 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] | 5288 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5289 | struct drm_device *dev = dev_priv->dev; |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5290 | const int vd = _pxvid_to_vd(pxvid); |
| 5291 | const int vm = vd - 1125; |
| 5292 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5293 | if (INTEL_INFO(dev)->is_mobile) |
Mika Kuoppala | d972d6e | 2014-12-01 18:01:05 +0200 | [diff] [blame] | 5294 | return vm > 0 ? vm : 0; |
| 5295 | |
| 5296 | return vd; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5297 | } |
| 5298 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5299 | static void __i915_update_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5300 | { |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5301 | u64 now, diff, diffms; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5302 | u32 count; |
| 5303 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5304 | assert_spin_locked(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5305 | |
Thomas Gleixner | 5ed0bdf | 2014-07-16 21:05:06 +0000 | [diff] [blame] | 5306 | now = ktime_get_raw_ns(); |
| 5307 | diffms = now - dev_priv->ips.last_time2; |
| 5308 | do_div(diffms, NSEC_PER_MSEC); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5309 | |
| 5310 | /* Don't divide by 0 */ |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5311 | if (!diffms) |
| 5312 | return; |
| 5313 | |
| 5314 | count = I915_READ(GFXEC); |
| 5315 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5316 | if (count < dev_priv->ips.last_count2) { |
| 5317 | diff = ~0UL - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5318 | diff += count; |
| 5319 | } else { |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5320 | diff = count - dev_priv->ips.last_count2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5321 | } |
| 5322 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5323 | dev_priv->ips.last_count2 = count; |
| 5324 | dev_priv->ips.last_time2 = now; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5325 | |
| 5326 | /* More magic constants... */ |
| 5327 | diff = diff * 1181; |
| 5328 | diff = div_u64(diff, diffms * 10); |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5329 | dev_priv->ips.gfx_power = diff; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5330 | } |
| 5331 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5332 | void i915_update_gfx_val(struct drm_i915_private *dev_priv) |
| 5333 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5334 | struct drm_device *dev = dev_priv->dev; |
| 5335 | |
| 5336 | if (INTEL_INFO(dev)->gen != 5) |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5337 | return; |
| 5338 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5339 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5340 | |
| 5341 | __i915_update_gfx_val(dev_priv); |
| 5342 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5343 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5344 | } |
| 5345 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5346 | static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5347 | { |
| 5348 | unsigned long t, corr, state1, corr2, state2; |
| 5349 | u32 pxvid, ext_v; |
| 5350 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5351 | assert_spin_locked(&mchdev_lock); |
| 5352 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 5353 | pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4)); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5354 | pxvid = (pxvid >> 24) & 0x7f; |
| 5355 | ext_v = pvid_to_extvid(dev_priv, pxvid); |
| 5356 | |
| 5357 | state1 = ext_v; |
| 5358 | |
| 5359 | t = i915_mch_val(dev_priv); |
| 5360 | |
| 5361 | /* Revel in the empirically derived constants */ |
| 5362 | |
| 5363 | /* Correction factor in 1/100000 units */ |
| 5364 | if (t > 80) |
| 5365 | corr = ((t * 2349) + 135940); |
| 5366 | else if (t >= 50) |
| 5367 | corr = ((t * 964) + 29317); |
| 5368 | else /* < 50 */ |
| 5369 | corr = ((t * 301) + 1004); |
| 5370 | |
| 5371 | corr = corr * ((150142 * state1) / 10000 - 78642); |
| 5372 | corr /= 100000; |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5373 | corr2 = (corr * dev_priv->ips.corr); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5374 | |
| 5375 | state2 = (corr2 * state1) / 10000; |
| 5376 | state2 /= 100; /* convert to mW */ |
| 5377 | |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5378 | __i915_update_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5379 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5380 | return dev_priv->ips.gfx_power + state2; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5381 | } |
| 5382 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5383 | unsigned long i915_gfx_val(struct drm_i915_private *dev_priv) |
| 5384 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5385 | struct drm_device *dev = dev_priv->dev; |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5386 | unsigned long val; |
| 5387 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 5388 | if (INTEL_INFO(dev)->gen != 5) |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5389 | return 0; |
| 5390 | |
| 5391 | spin_lock_irq(&mchdev_lock); |
| 5392 | |
| 5393 | val = __i915_gfx_val(dev_priv); |
| 5394 | |
| 5395 | spin_unlock_irq(&mchdev_lock); |
| 5396 | |
| 5397 | return val; |
| 5398 | } |
| 5399 | |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5400 | /** |
| 5401 | * i915_read_mch_val - return value for IPS use |
| 5402 | * |
| 5403 | * Calculate and return a value for the IPS driver to use when deciding whether |
| 5404 | * we have thermal and power headroom to increase CPU or GPU power budget. |
| 5405 | */ |
| 5406 | unsigned long i915_read_mch_val(void) |
| 5407 | { |
| 5408 | struct drm_i915_private *dev_priv; |
| 5409 | unsigned long chipset_val, graphics_val, ret = 0; |
| 5410 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5411 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5412 | if (!i915_mch_dev) |
| 5413 | goto out_unlock; |
| 5414 | dev_priv = i915_mch_dev; |
| 5415 | |
Chris Wilson | f531dcb2 | 2012-09-25 10:16:12 +0100 | [diff] [blame] | 5416 | chipset_val = __i915_chipset_val(dev_priv); |
| 5417 | graphics_val = __i915_gfx_val(dev_priv); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5418 | |
| 5419 | ret = chipset_val + graphics_val; |
| 5420 | |
| 5421 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5422 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5423 | |
| 5424 | return ret; |
| 5425 | } |
| 5426 | EXPORT_SYMBOL_GPL(i915_read_mch_val); |
| 5427 | |
| 5428 | /** |
| 5429 | * i915_gpu_raise - raise GPU frequency limit |
| 5430 | * |
| 5431 | * Raise the limit; IPS indicates we have thermal headroom. |
| 5432 | */ |
| 5433 | bool i915_gpu_raise(void) |
| 5434 | { |
| 5435 | struct drm_i915_private *dev_priv; |
| 5436 | bool ret = true; |
| 5437 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5438 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5439 | if (!i915_mch_dev) { |
| 5440 | ret = false; |
| 5441 | goto out_unlock; |
| 5442 | } |
| 5443 | dev_priv = i915_mch_dev; |
| 5444 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5445 | if (dev_priv->ips.max_delay > dev_priv->ips.fmax) |
| 5446 | dev_priv->ips.max_delay--; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5447 | |
| 5448 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5449 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5450 | |
| 5451 | return ret; |
| 5452 | } |
| 5453 | EXPORT_SYMBOL_GPL(i915_gpu_raise); |
| 5454 | |
| 5455 | /** |
| 5456 | * i915_gpu_lower - lower GPU frequency limit |
| 5457 | * |
| 5458 | * IPS indicates we're close to a thermal limit, so throttle back the GPU |
| 5459 | * frequency maximum. |
| 5460 | */ |
| 5461 | bool i915_gpu_lower(void) |
| 5462 | { |
| 5463 | struct drm_i915_private *dev_priv; |
| 5464 | bool ret = true; |
| 5465 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5466 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5467 | if (!i915_mch_dev) { |
| 5468 | ret = false; |
| 5469 | goto out_unlock; |
| 5470 | } |
| 5471 | dev_priv = i915_mch_dev; |
| 5472 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5473 | if (dev_priv->ips.max_delay < dev_priv->ips.min_delay) |
| 5474 | dev_priv->ips.max_delay++; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5475 | |
| 5476 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5477 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5478 | |
| 5479 | return ret; |
| 5480 | } |
| 5481 | EXPORT_SYMBOL_GPL(i915_gpu_lower); |
| 5482 | |
| 5483 | /** |
| 5484 | * i915_gpu_busy - indicate GPU business to IPS |
| 5485 | * |
| 5486 | * Tell the IPS driver whether or not the GPU is busy. |
| 5487 | */ |
| 5488 | bool i915_gpu_busy(void) |
| 5489 | { |
| 5490 | struct drm_i915_private *dev_priv; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 5491 | struct intel_engine_cs *ring; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5492 | bool ret = false; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5493 | int i; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5494 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5495 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5496 | if (!i915_mch_dev) |
| 5497 | goto out_unlock; |
| 5498 | dev_priv = i915_mch_dev; |
| 5499 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 5500 | for_each_ring(ring, dev_priv, i) |
| 5501 | ret |= !list_empty(&ring->request_list); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5502 | |
| 5503 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5504 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5505 | |
| 5506 | return ret; |
| 5507 | } |
| 5508 | EXPORT_SYMBOL_GPL(i915_gpu_busy); |
| 5509 | |
| 5510 | /** |
| 5511 | * i915_gpu_turbo_disable - disable graphics turbo |
| 5512 | * |
| 5513 | * Disable graphics turbo by resetting the max frequency and setting the |
| 5514 | * current frequency to the default. |
| 5515 | */ |
| 5516 | bool i915_gpu_turbo_disable(void) |
| 5517 | { |
| 5518 | struct drm_i915_private *dev_priv; |
| 5519 | bool ret = true; |
| 5520 | |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5521 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5522 | if (!i915_mch_dev) { |
| 5523 | ret = false; |
| 5524 | goto out_unlock; |
| 5525 | } |
| 5526 | dev_priv = i915_mch_dev; |
| 5527 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5528 | dev_priv->ips.max_delay = dev_priv->ips.fstart; |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5529 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5530 | if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart)) |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5531 | ret = false; |
| 5532 | |
| 5533 | out_unlock: |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5534 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5535 | |
| 5536 | return ret; |
| 5537 | } |
| 5538 | EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable); |
| 5539 | |
| 5540 | /** |
| 5541 | * Tells the intel_ips driver that the i915 driver is now loaded, if |
| 5542 | * IPS got loaded first. |
| 5543 | * |
| 5544 | * This awkward dance is so that neither module has to depend on the |
| 5545 | * other in order for IPS to do the appropriate communication of |
| 5546 | * GPU turbo limits to i915. |
| 5547 | */ |
| 5548 | static void |
| 5549 | ips_ping_for_i915_load(void) |
| 5550 | { |
| 5551 | void (*link)(void); |
| 5552 | |
| 5553 | link = symbol_get(ips_link_to_i915_driver); |
| 5554 | if (link) { |
| 5555 | link(); |
| 5556 | symbol_put(ips_link_to_i915_driver); |
| 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | void intel_gpu_ips_init(struct drm_i915_private *dev_priv) |
| 5561 | { |
Daniel Vetter | 02d7195 | 2012-08-09 16:44:54 +0200 | [diff] [blame] | 5562 | /* We only register the i915 ips part with intel-ips once everything is |
| 5563 | * set up, to avoid intel-ips sneaking in and reading bogus values. */ |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5564 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5565 | i915_mch_dev = dev_priv; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5566 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5567 | |
| 5568 | ips_ping_for_i915_load(); |
| 5569 | } |
| 5570 | |
| 5571 | void intel_gpu_ips_teardown(void) |
| 5572 | { |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5573 | spin_lock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5574 | i915_mch_dev = NULL; |
Daniel Vetter | 9270388 | 2012-08-09 16:46:01 +0200 | [diff] [blame] | 5575 | spin_unlock_irq(&mchdev_lock); |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 5576 | } |
Deepak S | 76c3552f | 2014-01-30 23:08:16 +0530 | [diff] [blame] | 5577 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5578 | static void intel_init_emon(struct drm_device *dev) |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5579 | { |
| 5580 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5581 | u32 lcfuse; |
| 5582 | u8 pxw[16]; |
| 5583 | int i; |
| 5584 | |
| 5585 | /* Disable to program */ |
| 5586 | I915_WRITE(ECR, 0); |
| 5587 | POSTING_READ(ECR); |
| 5588 | |
| 5589 | /* Program energy weights for various events */ |
| 5590 | I915_WRITE(SDEW, 0x15040d00); |
| 5591 | I915_WRITE(CSIEW0, 0x007f0000); |
| 5592 | I915_WRITE(CSIEW1, 0x1e220004); |
| 5593 | I915_WRITE(CSIEW2, 0x04000004); |
| 5594 | |
| 5595 | for (i = 0; i < 5; i++) |
| 5596 | I915_WRITE(PEW + (i * 4), 0); |
| 5597 | for (i = 0; i < 3; i++) |
| 5598 | I915_WRITE(DEW + (i * 4), 0); |
| 5599 | |
| 5600 | /* Program P-state weights to account for frequency power adjustment */ |
| 5601 | for (i = 0; i < 16; i++) { |
| 5602 | u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4)); |
| 5603 | unsigned long freq = intel_pxfreq(pxvidfreq); |
| 5604 | unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >> |
| 5605 | PXVFREQ_PX_SHIFT; |
| 5606 | unsigned long val; |
| 5607 | |
| 5608 | val = vid * vid; |
| 5609 | val *= (freq / 1000); |
| 5610 | val *= 255; |
| 5611 | val /= (127*127*900); |
| 5612 | if (val > 0xff) |
| 5613 | DRM_ERROR("bad pxval: %ld\n", val); |
| 5614 | pxw[i] = val; |
| 5615 | } |
| 5616 | /* Render standby states get 0 weight */ |
| 5617 | pxw[14] = 0; |
| 5618 | pxw[15] = 0; |
| 5619 | |
| 5620 | for (i = 0; i < 4; i++) { |
| 5621 | u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) | |
| 5622 | (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]); |
| 5623 | I915_WRITE(PXW + (i * 4), val); |
| 5624 | } |
| 5625 | |
| 5626 | /* Adjust magic regs to magic values (more experimental results) */ |
| 5627 | I915_WRITE(OGW0, 0); |
| 5628 | I915_WRITE(OGW1, 0); |
| 5629 | I915_WRITE(EG0, 0x00007f00); |
| 5630 | I915_WRITE(EG1, 0x0000000e); |
| 5631 | I915_WRITE(EG2, 0x000e0000); |
| 5632 | I915_WRITE(EG3, 0x68000300); |
| 5633 | I915_WRITE(EG4, 0x42000000); |
| 5634 | I915_WRITE(EG5, 0x00140031); |
| 5635 | I915_WRITE(EG6, 0); |
| 5636 | I915_WRITE(EG7, 0); |
| 5637 | |
| 5638 | for (i = 0; i < 8; i++) |
| 5639 | I915_WRITE(PXWL + (i * 4), 0); |
| 5640 | |
| 5641 | /* Enable PMON + select events */ |
| 5642 | I915_WRITE(ECR, 0x80000019); |
| 5643 | |
| 5644 | lcfuse = I915_READ(LCFUSE02); |
| 5645 | |
Daniel Vetter | 20e4d40 | 2012-08-08 23:35:39 +0200 | [diff] [blame] | 5646 | dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK); |
Eugeni Dodonov | dde1888 | 2012-04-18 15:29:24 -0300 | [diff] [blame] | 5647 | } |
| 5648 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5649 | void intel_init_gt_powersave(struct drm_device *dev) |
| 5650 | { |
Imre Deak | e6069ca | 2014-04-18 16:01:02 +0300 | [diff] [blame] | 5651 | i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6); |
| 5652 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5653 | if (IS_CHERRYVIEW(dev)) |
| 5654 | cherryview_init_gt_powersave(dev); |
| 5655 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5656 | valleyview_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | void intel_cleanup_gt_powersave(struct drm_device *dev) |
| 5660 | { |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5661 | if (IS_CHERRYVIEW(dev)) |
| 5662 | return; |
| 5663 | else if (IS_VALLEYVIEW(dev)) |
Imre Deak | 4e80519 | 2014-04-14 20:24:41 +0300 | [diff] [blame] | 5664 | valleyview_cleanup_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 5665 | } |
| 5666 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5667 | static void gen6_suspend_rps(struct drm_device *dev) |
| 5668 | { |
| 5669 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5670 | |
| 5671 | flush_delayed_work(&dev_priv->rps.delayed_resume_work); |
| 5672 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5673 | gen6_disable_rps_interrupts(dev); |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5674 | } |
| 5675 | |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5676 | /** |
| 5677 | * intel_suspend_gt_powersave - suspend PM work and helper threads |
| 5678 | * @dev: drm device |
| 5679 | * |
| 5680 | * We don't want to disable RC6 or other features here, we just want |
| 5681 | * to make sure any work we've queued has finished and won't bother |
| 5682 | * us while we're suspended. |
| 5683 | */ |
| 5684 | void intel_suspend_gt_powersave(struct drm_device *dev) |
| 5685 | { |
| 5686 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5687 | |
Imre Deak | d4d70aa | 2014-11-19 15:30:04 +0200 | [diff] [blame] | 5688 | if (INTEL_INFO(dev)->gen < 6) |
| 5689 | return; |
| 5690 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5691 | gen6_suspend_rps(dev); |
Deepak S | b47adc1 | 2014-06-20 20:03:02 +0530 | [diff] [blame] | 5692 | |
| 5693 | /* Force GPU to min freq during suspend */ |
| 5694 | gen6_rps_idle(dev_priv); |
Jesse Barnes | 156c7ca | 2014-06-12 08:35:45 -0700 | [diff] [blame] | 5695 | } |
| 5696 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5697 | void intel_disable_gt_powersave(struct drm_device *dev) |
| 5698 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5699 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5700 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5701 | if (IS_IRONLAKE_M(dev)) { |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5702 | ironlake_disable_drps(dev); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5703 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Daniel Vetter | 10d8d36 | 2014-06-12 17:48:52 +0200 | [diff] [blame] | 5704 | intel_suspend_gt_powersave(dev); |
Imre Deak | e494837 | 2014-05-12 18:35:04 +0300 | [diff] [blame] | 5705 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5706 | mutex_lock(&dev_priv->rps.hw_lock); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5707 | if (INTEL_INFO(dev)->gen >= 9) |
| 5708 | gen9_disable_rps(dev); |
| 5709 | else if (IS_CHERRYVIEW(dev)) |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5710 | cherryview_disable_rps(dev); |
| 5711 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | d20d4f0 | 2013-04-23 10:09:28 -0700 | [diff] [blame] | 5712 | valleyview_disable_rps(dev); |
| 5713 | else |
| 5714 | gen6_disable_rps(dev); |
Imre Deak | e534770 | 2014-11-19 15:30:02 +0200 | [diff] [blame] | 5715 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5716 | dev_priv->rps.enabled = false; |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5717 | mutex_unlock(&dev_priv->rps.hw_lock); |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 5718 | } |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5719 | } |
| 5720 | |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5721 | static void intel_gen6_powersave_work(struct work_struct *work) |
| 5722 | { |
| 5723 | struct drm_i915_private *dev_priv = |
| 5724 | container_of(work, struct drm_i915_private, |
| 5725 | rps.delayed_resume_work.work); |
| 5726 | struct drm_device *dev = dev_priv->dev; |
| 5727 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5728 | mutex_lock(&dev_priv->rps.hw_lock); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5729 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5730 | gen6_reset_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5731 | |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5732 | if (IS_CHERRYVIEW(dev)) { |
| 5733 | cherryview_enable_rps(dev); |
| 5734 | } else if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5735 | valleyview_enable_rps(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5736 | } else if (INTEL_INFO(dev)->gen >= 9) { |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5737 | gen9_enable_rc6(dev); |
Zhe Wang | 20e4936 | 2014-11-04 17:07:05 +0000 | [diff] [blame] | 5738 | gen9_enable_rps(dev); |
Jesse Barnes | b6fef0e | 2015-01-16 18:07:25 +0000 | [diff] [blame] | 5739 | __gen6_update_ring_freq(dev); |
Ben Widawsky | 6edee7f | 2013-11-02 21:07:52 -0700 | [diff] [blame] | 5740 | } else if (IS_BROADWELL(dev)) { |
| 5741 | gen8_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5742 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5743 | } else { |
| 5744 | gen6_enable_rps(dev); |
Imre Deak | c2bc2fc | 2014-04-18 16:16:23 +0300 | [diff] [blame] | 5745 | __gen6_update_ring_freq(dev); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 5746 | } |
Chris Wilson | aed242f | 2015-03-18 09:48:21 +0000 | [diff] [blame] | 5747 | |
| 5748 | WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq); |
| 5749 | WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq); |
| 5750 | |
| 5751 | WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq); |
| 5752 | WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq); |
| 5753 | |
Chris Wilson | c0951f0 | 2013-10-10 21:58:50 +0100 | [diff] [blame] | 5754 | dev_priv->rps.enabled = true; |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5755 | |
Akash Goel | 4c2a889 | 2015-03-06 11:07:24 +0530 | [diff] [blame] | 5756 | gen6_enable_rps_interrupts(dev); |
Imre Deak | 3cc134e | 2014-11-19 15:30:03 +0200 | [diff] [blame] | 5757 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 5758 | mutex_unlock(&dev_priv->rps.hw_lock); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5759 | |
| 5760 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5761 | } |
| 5762 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5763 | void intel_enable_gt_powersave(struct drm_device *dev) |
| 5764 | { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5765 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5766 | |
Yu Zhang | f61018b | 2015-02-10 19:05:52 +0800 | [diff] [blame] | 5767 | /* Powersaving is controlled by the host when inside a VM */ |
| 5768 | if (intel_vgpu_active(dev)) |
| 5769 | return; |
| 5770 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5771 | if (IS_IRONLAKE_M(dev)) { |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5772 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5773 | ironlake_enable_drps(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5774 | intel_init_emon(dev); |
Imre Deak | dc1d013 | 2014-04-14 20:24:28 +0300 | [diff] [blame] | 5775 | mutex_unlock(&dev->struct_mutex); |
Deepak S | 3880774 | 2014-05-23 21:00:15 +0530 | [diff] [blame] | 5776 | } else if (INTEL_INFO(dev)->gen >= 6) { |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5777 | /* |
| 5778 | * PCU communication is slow and this doesn't need to be |
| 5779 | * done at any specific time, so do this out of our fast path |
| 5780 | * to make resume and init faster. |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5781 | * |
| 5782 | * We depend on the HW RC6 power context save/restore |
| 5783 | * mechanism when entering D3 through runtime PM suspend. So |
| 5784 | * disable RPM until RPS/RC6 is properly setup. We can only |
| 5785 | * get here via the driver load/system resume/runtime resume |
| 5786 | * paths, so the _noresume version is enough (and in case of |
| 5787 | * runtime resume it's necessary). |
Jesse Barnes | 1a01ab3 | 2012-11-02 11:14:00 -0700 | [diff] [blame] | 5788 | */ |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5789 | if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work, |
| 5790 | round_jiffies_up_relative(HZ))) |
| 5791 | intel_runtime_pm_get_noresume(dev_priv); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 5792 | } |
| 5793 | } |
| 5794 | |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5795 | void intel_reset_gt_powersave(struct drm_device *dev) |
| 5796 | { |
| 5797 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5798 | |
Imre Deak | dbea3ce | 2014-12-15 18:59:28 +0200 | [diff] [blame] | 5799 | if (INTEL_INFO(dev)->gen < 6) |
| 5800 | return; |
| 5801 | |
| 5802 | gen6_suspend_rps(dev); |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5803 | dev_priv->rps.enabled = false; |
Imre Deak | c6df39b | 2014-04-14 20:24:29 +0300 | [diff] [blame] | 5804 | } |
| 5805 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5806 | static void ibx_init_clock_gating(struct drm_device *dev) |
| 5807 | { |
| 5808 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5809 | |
| 5810 | /* |
| 5811 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5812 | * gating for the panel power sequencer or it will fail to |
| 5813 | * start up when no ports are active. |
| 5814 | */ |
| 5815 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); |
| 5816 | } |
| 5817 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5818 | static void g4x_disable_trickle_feed(struct drm_device *dev) |
| 5819 | { |
| 5820 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5821 | int pipe; |
| 5822 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5823 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5824 | I915_WRITE(DSPCNTR(pipe), |
| 5825 | I915_READ(DSPCNTR(pipe)) | |
| 5826 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 5827 | intel_flush_primary_plane(dev_priv, pipe); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5828 | } |
| 5829 | } |
| 5830 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5831 | static void ilk_init_lp_watermarks(struct drm_device *dev) |
| 5832 | { |
| 5833 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5834 | |
| 5835 | I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 5836 | I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 5837 | I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); |
| 5838 | |
| 5839 | /* |
| 5840 | * Don't touch WM1S_LP_EN here. |
| 5841 | * Doing so could cause underruns. |
| 5842 | */ |
| 5843 | } |
| 5844 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5845 | static void ironlake_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5846 | { |
| 5847 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5848 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5849 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 5850 | /* |
| 5851 | * Required for FBC |
| 5852 | * WaFbcDisableDpfcClockGating:ilk |
| 5853 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5854 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 5855 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 5856 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5857 | |
| 5858 | I915_WRITE(PCH_3DCGDIS0, |
| 5859 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 5860 | SVSMUNIT_CLOCK_GATE_DISABLE); |
| 5861 | I915_WRITE(PCH_3DCGDIS1, |
| 5862 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 5863 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5864 | /* |
| 5865 | * According to the spec the following bits should be set in |
| 5866 | * order to enable memory self-refresh |
| 5867 | * The bit 22/21 of 0x42004 |
| 5868 | * The bit 5 of 0x42020 |
| 5869 | * The bit 15 of 0x45000 |
| 5870 | */ |
| 5871 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5872 | (I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5873 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5874 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5875 | I915_WRITE(DISP_ARB_CTL, |
| 5876 | (I915_READ(DISP_ARB_CTL) | |
| 5877 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5878 | |
| 5879 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5880 | |
| 5881 | /* |
| 5882 | * Based on the document from hardware guys the following bits |
| 5883 | * should be set unconditionally in order to enable FBC. |
| 5884 | * The bit 22 of 0x42000 |
| 5885 | * The bit 22 of 0x42004 |
| 5886 | * The bit 7,8,9 of 0x42020. |
| 5887 | */ |
| 5888 | if (IS_IRONLAKE_M(dev)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 5889 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5890 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 5891 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 5892 | ILK_FBCQ_DIS); |
| 5893 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5894 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5895 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5896 | } |
| 5897 | |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 5898 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
| 5899 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5900 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5901 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5902 | ILK_ELPIN_409_SELECT); |
| 5903 | I915_WRITE(_3D_CHICKEN2, |
| 5904 | _3D_CHICKEN2_WM_READ_PIPELINED << 16 | |
| 5905 | _3D_CHICKEN2_WM_READ_PIPELINED); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5906 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5907 | /* WaDisableRenderCachePipelinedFlush:ilk */ |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 5908 | I915_WRITE(CACHE_MODE_0, |
| 5909 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5910 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5911 | /* WaDisable_RenderCache_OperationalFlush:ilk */ |
| 5912 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5913 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 5914 | g4x_disable_trickle_feed(dev); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 5915 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5916 | ibx_init_clock_gating(dev); |
| 5917 | } |
| 5918 | |
| 5919 | static void cpt_init_clock_gating(struct drm_device *dev) |
| 5920 | { |
| 5921 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5922 | int pipe; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5923 | uint32_t val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5924 | |
| 5925 | /* |
| 5926 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 5927 | * gating for the panel power sequencer or it will fail to |
| 5928 | * start up when no ports are active. |
| 5929 | */ |
Jesse Barnes | cd66407 | 2013-10-02 10:34:19 -0700 | [diff] [blame] | 5930 | I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE | |
| 5931 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 5932 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5933 | I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | |
| 5934 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 5935 | /* The below fixes the weird display corruption, a few pixels shifted |
| 5936 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 5937 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5938 | for_each_pipe(dev_priv, pipe) { |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5939 | val = I915_READ(TRANS_CHICKEN2(pipe)); |
| 5940 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 5941 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5942 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5943 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 5944 | val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK; |
| 5945 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 5946 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 5947 | I915_WRITE(TRANS_CHICKEN2(pipe), val); |
| 5948 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5949 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 5950 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 5951 | I915_WRITE(TRANS_CHICKEN1(pipe), |
| 5952 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 5953 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5954 | } |
| 5955 | |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5956 | static void gen6_check_mch_setup(struct drm_device *dev) |
| 5957 | { |
| 5958 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5959 | uint32_t tmp; |
| 5960 | |
| 5961 | tmp = I915_READ(MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 5962 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
| 5963 | DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 5964 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 5965 | } |
| 5966 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 5967 | static void gen6_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5968 | { |
| 5969 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5970 | uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5971 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 5972 | I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5973 | |
| 5974 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 5975 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 5976 | ILK_ELPIN_409_SELECT); |
| 5977 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 5978 | /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ |
Daniel Vetter | 4283908 | 2012-12-14 23:38:28 +0100 | [diff] [blame] | 5979 | I915_WRITE(_3D_CHICKEN, |
| 5980 | _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); |
| 5981 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 5982 | /* WaDisable_RenderCache_OperationalFlush:snb */ |
| 5983 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 5984 | |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5985 | /* |
| 5986 | * BSpec recoomends 8x4 when MSAA is used, |
| 5987 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 5988 | * |
| 5989 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 5990 | * disable bit, which we don't touch here, but it's good |
| 5991 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5992 | */ |
| 5993 | I915_WRITE(GEN6_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 5994 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | 8d85d27 | 2014-02-04 21:59:15 +0200 | [diff] [blame] | 5995 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 5996 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5997 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 5998 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5074329 | 2012-04-26 22:02:54 +0200 | [diff] [blame] | 5999 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6000 | |
| 6001 | I915_WRITE(GEN6_UCGCTL1, |
| 6002 | I915_READ(GEN6_UCGCTL1) | |
| 6003 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 6004 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 6005 | |
| 6006 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 6007 | * gating disable must be set. Failure to set it results in |
| 6008 | * flickering pixels due to Z write ordering failures after |
| 6009 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 6010 | * Sanctuary and Tropics, and apparently anything else with |
| 6011 | * alpha test or pixel discard. |
| 6012 | * |
| 6013 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 6014 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6015 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 6016 | * WaDisableRCCUnitClockGating:snb |
| 6017 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6018 | */ |
| 6019 | I915_WRITE(GEN6_UCGCTL2, |
| 6020 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 6021 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 6022 | |
Ville Syrjälä | 5eb146d | 2014-02-04 21:59:16 +0200 | [diff] [blame] | 6023 | /* WaStripsFansDisableFastClipPerformanceFix:snb */ |
Ville Syrjälä | 743b57d | 2014-02-04 21:59:17 +0200 | [diff] [blame] | 6024 | I915_WRITE(_3D_CHICKEN3, |
| 6025 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6026 | |
| 6027 | /* |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 6028 | * Bspec says: |
| 6029 | * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and |
| 6030 | * 3DSTATE_SF number of SF output attributes is more than 16." |
| 6031 | */ |
| 6032 | I915_WRITE(_3D_CHICKEN3, |
| 6033 | _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH)); |
| 6034 | |
| 6035 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6036 | * According to the spec the following bits should be |
| 6037 | * set in order to enable memory self-refresh and fbc: |
| 6038 | * The bit21 and bit22 of 0x42000 |
| 6039 | * The bit21 and bit22 of 0x42004 |
| 6040 | * The bit5 and bit7 of 0x42020 |
| 6041 | * The bit14 of 0x70180 |
| 6042 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 6043 | * |
| 6044 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6045 | */ |
| 6046 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 6047 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 6048 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
| 6049 | I915_WRITE(ILK_DISPLAY_CHICKEN2, |
| 6050 | I915_READ(ILK_DISPLAY_CHICKEN2) | |
| 6051 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6052 | I915_WRITE(ILK_DSPCLK_GATE_D, |
| 6053 | I915_READ(ILK_DSPCLK_GATE_D) | |
| 6054 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 6055 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6056 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6057 | g4x_disable_trickle_feed(dev); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 6058 | |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6059 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6060 | |
| 6061 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv) |
| 6065 | { |
| 6066 | uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE); |
| 6067 | |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6068 | /* |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6069 | * WaVSThreadDispatchOverride:ivb,vlv |
Ville Syrjälä | 3aad905 | 2014-01-22 21:32:59 +0200 | [diff] [blame] | 6070 | * |
| 6071 | * This actually overrides the dispatch |
| 6072 | * mode for all thread types. |
| 6073 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6074 | reg &= ~GEN7_FF_SCHED_MASK; |
| 6075 | reg |= GEN7_FF_TS_SCHED_HW; |
| 6076 | reg |= GEN7_FF_VS_SCHED_HW; |
| 6077 | reg |= GEN7_FF_DS_SCHED_HW; |
| 6078 | |
| 6079 | I915_WRITE(GEN7_FF_THREAD_MODE, reg); |
| 6080 | } |
| 6081 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6082 | static void lpt_init_clock_gating(struct drm_device *dev) |
| 6083 | { |
| 6084 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6085 | |
| 6086 | /* |
| 6087 | * TODO: this bit should only be enabled when really needed, then |
| 6088 | * disabled when not needed anymore in order to save power. |
| 6089 | */ |
| 6090 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) |
| 6091 | I915_WRITE(SOUTH_DSPCLK_GATE_D, |
| 6092 | I915_READ(SOUTH_DSPCLK_GATE_D) | |
| 6093 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 6094 | |
| 6095 | /* WADPOClockGatingDisable:hsw */ |
| 6096 | I915_WRITE(_TRANSA_CHICKEN1, |
| 6097 | I915_READ(_TRANSA_CHICKEN1) | |
| 6098 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6099 | } |
| 6100 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6101 | static void lpt_suspend_hw(struct drm_device *dev) |
| 6102 | { |
| 6103 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6104 | |
| 6105 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 6106 | uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 6107 | |
| 6108 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 6109 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 6110 | } |
| 6111 | } |
| 6112 | |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6113 | static void broadwell_init_clock_gating(struct drm_device *dev) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6114 | { |
| 6115 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6116 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6117 | |
| 6118 | I915_WRITE(WM3_LP_ILK, 0); |
| 6119 | I915_WRITE(WM2_LP_ILK, 0); |
| 6120 | I915_WRITE(WM1_LP_ILK, 0); |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6121 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6122 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Ben Widawsky | 50ed5fb | 2013-11-02 21:07:40 -0700 | [diff] [blame] | 6123 | 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] | 6124 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6125 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6126 | I915_WRITE(CHICKEN_PAR1_1, |
| 6127 | I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD); |
| 6128 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6129 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 6130 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 6131 | I915_WRITE(CHICKEN_PIPESL_1(pipe), |
Ville Syrjälä | c7c6562 | 2014-03-05 13:05:45 +0200 | [diff] [blame] | 6132 | I915_READ(CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 6133 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 6134 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 6135 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 6136 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 6137 | /* WaDSRefCountFullforceMissDisable:bdw */ |
| 6138 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6139 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6140 | ~(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] | 6141 | |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 6142 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6143 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 6144 | |
| 6145 | /* WaDisableSDEUnitClockGating:bdw */ |
| 6146 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6147 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 6148 | |
Paulo Zanoni | 89d6b2b | 2014-08-21 17:09:36 -0300 | [diff] [blame] | 6149 | lpt_init_clock_gating(dev); |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 6150 | } |
| 6151 | |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6152 | static void haswell_init_clock_gating(struct drm_device *dev) |
| 6153 | { |
| 6154 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6155 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6156 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6157 | |
Francisco Jerez | f3fc488 | 2013-10-02 15:53:16 -0700 | [diff] [blame] | 6158 | /* L3 caching of data atomics doesn't work -- disable it. */ |
| 6159 | I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); |
| 6160 | I915_WRITE(HSW_ROW_CHICKEN3, |
| 6161 | _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE)); |
| 6162 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6163 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6164 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6165 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6166 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6167 | |
Ville Syrjälä | e36ea7f | 2014-01-22 21:33:00 +0200 | [diff] [blame] | 6168 | /* WaVSRefCountFullforceMissDisable:hsw */ |
| 6169 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6170 | I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6171 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6172 | /* WaDisable_RenderCache_OperationalFlush:hsw */ |
| 6173 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6174 | |
Chia-I Wu | fe27c60 | 2014-01-28 13:29:33 +0800 | [diff] [blame] | 6175 | /* enable HiZ Raw Stall Optimization */ |
| 6176 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6177 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6178 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6179 | /* WaDisable4x2SubspanOptimization:hsw */ |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6180 | I915_WRITE(CACHE_MODE_1, |
| 6181 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6182 | |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6183 | /* |
| 6184 | * BSpec recommends 8x4 when MSAA is used, |
| 6185 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6186 | * |
| 6187 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6188 | * disable bit, which we don't touch here, but it's good |
| 6189 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6190 | */ |
| 6191 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6192 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a12c496 | 2014-02-04 21:59:20 +0200 | [diff] [blame] | 6193 | |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 6194 | /* WaSampleCChickenBitEnable:hsw */ |
| 6195 | I915_WRITE(HALF_SLICE_CHICKEN3, |
| 6196 | _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE)); |
| 6197 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6198 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Ben Widawsky | e3dff58 | 2013-03-20 14:49:14 -0700 | [diff] [blame] | 6199 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); |
| 6200 | |
Paulo Zanoni | 90a8864 | 2013-05-03 17:23:45 -0300 | [diff] [blame] | 6201 | /* WaRsPkgCStateDisplayPMReq:hsw */ |
| 6202 | I915_WRITE(CHICKEN_PAR1_1, |
| 6203 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
Eugeni Dodonov | 1544d9d | 2012-07-02 11:51:10 -0300 | [diff] [blame] | 6204 | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 6205 | lpt_init_clock_gating(dev); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6206 | } |
| 6207 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6208 | static void ivybridge_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6209 | { |
| 6210 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6211 | uint32_t snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6212 | |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 6213 | ilk_init_lp_watermarks(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6214 | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 6215 | I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6216 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6217 | /* WaDisableEarlyCull:ivb */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6218 | I915_WRITE(_3D_CHICKEN3, |
| 6219 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6220 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6221 | /* WaDisableBackToBackFlipFix:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6222 | I915_WRITE(IVB_CHICKEN3, |
| 6223 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6224 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6225 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6226 | /* WaDisablePSDDualDispatchEnable:ivb */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6227 | if (IS_IVB_GT1(dev)) |
| 6228 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
| 6229 | _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6230 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6231 | /* WaDisable_RenderCache_OperationalFlush:ivb */ |
| 6232 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6233 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6234 | /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6235 | I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1, |
| 6236 | GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); |
| 6237 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6238 | /* WaApplyL3ControlAndL3ChickenMode:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6239 | I915_WRITE(GEN7_L3CNTLREG1, |
| 6240 | GEN7_WA_FOR_GEN7_L3_CONTROL); |
| 6241 | I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6242 | GEN7_WA_L3_CHICKEN_MODE); |
| 6243 | if (IS_IVB_GT1(dev)) |
| 6244 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6245 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6246 | else { |
| 6247 | /* must write both registers */ |
| 6248 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6249 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6250 | I915_WRITE(GEN7_ROW_CHICKEN2_GT2, |
| 6251 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 6252 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6253 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6254 | /* WaForceL3Serialization:ivb */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6255 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6256 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6257 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 6258 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6259 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6260 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6261 | */ |
| 6262 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 6263 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6264 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6265 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6266 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6267 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6268 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6269 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6270 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6271 | |
| 6272 | gen7_setup_fixed_func_scheduler(dev_priv); |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6273 | |
Chris Wilson | 2272134 | 2014-03-04 09:41:43 +0000 | [diff] [blame] | 6274 | if (0) { /* causes HiZ corruption on ivb:gt1 */ |
| 6275 | /* enable HiZ Raw Stall Optimization */ |
| 6276 | I915_WRITE(CACHE_MODE_0_GEN7, |
| 6277 | _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE)); |
| 6278 | } |
Chia-I Wu | 116f2b6 | 2014-01-28 13:29:34 +0800 | [diff] [blame] | 6279 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6280 | /* WaDisable4x2SubspanOptimization:ivb */ |
Daniel Vetter | 97e1930 | 2012-04-24 16:00:21 +0200 | [diff] [blame] | 6281 | I915_WRITE(CACHE_MODE_1, |
| 6282 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6283 | |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6284 | /* |
| 6285 | * BSpec recommends 8x4 when MSAA is used, |
| 6286 | * however in practice 16x4 seems fastest. |
Ville Syrjälä | c5c98a5 | 2014-02-05 12:43:47 +0200 | [diff] [blame] | 6287 | * |
| 6288 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6289 | * disable bit, which we don't touch here, but it's good |
| 6290 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6291 | */ |
| 6292 | I915_WRITE(GEN7_GT_MODE, |
Damien Lespiau | 9853325 | 2014-12-08 17:33:51 +0000 | [diff] [blame] | 6293 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
Ville Syrjälä | a607c1a | 2014-02-04 21:59:19 +0200 | [diff] [blame] | 6294 | |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 6295 | snpcr = I915_READ(GEN6_MBCUNIT_SNPCR); |
| 6296 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 6297 | snpcr |= GEN6_MBC_SNPCR_MED; |
| 6298 | I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 6299 | |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 6300 | if (!HAS_PCH_NOP(dev)) |
| 6301 | cpt_init_clock_gating(dev); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 6302 | |
| 6303 | gen6_check_mch_setup(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6304 | } |
| 6305 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6306 | static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv) |
| 6307 | { |
| 6308 | I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE); |
| 6309 | |
| 6310 | /* |
| 6311 | * Disable trickle feed and enable pnd deadline calculation |
| 6312 | */ |
| 6313 | I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE); |
| 6314 | I915_WRITE(CBR1_VLV, 0); |
| 6315 | } |
| 6316 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6317 | static void valleyview_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6318 | { |
| 6319 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6320 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6321 | vlv_init_display_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6322 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6323 | /* WaDisableEarlyCull:vlv */ |
Jesse Barnes | 87f8020 | 2012-10-02 17:43:41 -0500 | [diff] [blame] | 6324 | I915_WRITE(_3D_CHICKEN3, |
| 6325 | _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL)); |
| 6326 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6327 | /* WaDisableBackToBackFlipFix:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6328 | I915_WRITE(IVB_CHICKEN3, |
| 6329 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 6330 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 6331 | |
Ville Syrjälä | fad7d36 | 2014-01-22 21:32:39 +0200 | [diff] [blame] | 6332 | /* WaPsdDispatchEnable:vlv */ |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6333 | /* WaDisablePSDDualDispatchEnable:vlv */ |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6334 | I915_WRITE(GEN7_HALF_SLICE_CHICKEN1, |
Jesse Barnes | d3bc030 | 2013-03-08 10:45:51 -0800 | [diff] [blame] | 6335 | _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP | |
| 6336 | GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE)); |
Jesse Barnes | 12f3382 | 2012-10-25 12:15:45 -0700 | [diff] [blame] | 6337 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6338 | /* WaDisable_RenderCache_OperationalFlush:vlv */ |
| 6339 | I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6340 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6341 | /* WaForceL3Serialization:vlv */ |
Jesse Barnes | 61939d9 | 2012-10-02 17:43:38 -0500 | [diff] [blame] | 6342 | I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) & |
| 6343 | ~L3SQ_URB_READ_CAM_MATCH_DISABLE); |
| 6344 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6345 | /* WaDisableDopClockGating:vlv */ |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 6346 | I915_WRITE(GEN7_ROW_CHICKEN2, |
| 6347 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 6348 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6349 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6350 | I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 6351 | I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
| 6352 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 6353 | |
Ville Syrjälä | 46680e0 | 2014-01-22 21:33:01 +0200 | [diff] [blame] | 6354 | gen7_setup_fixed_func_scheduler(dev_priv); |
| 6355 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6356 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6357 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6358 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6359 | */ |
| 6360 | I915_WRITE(GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 6361 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 6362 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 6363 | /* WaDisableL3Bank2xClockGate:vlv |
| 6364 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 6365 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
| 6366 | I915_WRITE(GEN7_UCGCTL4, |
| 6367 | I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE); |
Jesse Barnes | e3f33d4 | 2012-06-14 11:04:50 -0700 | [diff] [blame] | 6368 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 6369 | /* |
| 6370 | * BSpec says this must be set, even though |
| 6371 | * WaDisable4x2SubspanOptimization isn't listed for VLV. |
| 6372 | */ |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 6373 | I915_WRITE(CACHE_MODE_1, |
| 6374 | _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE)); |
Jesse Barnes | 7983117 | 2012-06-20 10:53:12 -0700 | [diff] [blame] | 6375 | |
| 6376 | /* |
Ville Syrjälä | da2518f | 2015-01-21 19:38:01 +0200 | [diff] [blame] | 6377 | * BSpec recommends 8x4 when MSAA is used, |
| 6378 | * however in practice 16x4 seems fastest. |
| 6379 | * |
| 6380 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 6381 | * disable bit, which we don't touch here, but it's good |
| 6382 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 6383 | */ |
| 6384 | I915_WRITE(GEN7_GT_MODE, |
| 6385 | _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); |
| 6386 | |
| 6387 | /* |
Ville Syrjälä | 031994e | 2014-01-22 21:32:46 +0200 | [diff] [blame] | 6388 | * WaIncreaseL3CreditsForVLVB0:vlv |
| 6389 | * This is the hardware default actually. |
| 6390 | */ |
| 6391 | I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); |
| 6392 | |
| 6393 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 6394 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 6395 | * Disable clock gating on th GCFG unit to prevent a delay |
| 6396 | * in the reporting of vblank events. |
| 6397 | */ |
Ville Syrjälä | 7a0d1ee | 2014-01-22 21:33:04 +0200 | [diff] [blame] | 6398 | I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6399 | } |
| 6400 | |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6401 | static void cherryview_init_clock_gating(struct drm_device *dev) |
| 6402 | { |
| 6403 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6404 | |
Ville Syrjälä | c6beb13 | 2015-03-05 21:19:48 +0200 | [diff] [blame] | 6405 | vlv_init_display_clock_gating(dev_priv); |
Ville Syrjälä | dd811e7 | 2014-04-09 13:28:33 +0300 | [diff] [blame] | 6406 | |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 6407 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 6408 | /* WaDSRefCountFullforceMissDisable:chv */ |
| 6409 | I915_WRITE(GEN7_FF_THREAD_MODE, |
| 6410 | I915_READ(GEN7_FF_THREAD_MODE) & |
| 6411 | ~(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] | 6412 | |
| 6413 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
| 6414 | I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL, |
| 6415 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 6416 | |
| 6417 | /* WaDisableCSUnitClockGating:chv */ |
| 6418 | I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) | |
| 6419 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 6420 | |
| 6421 | /* WaDisableSDEUnitClockGating:chv */ |
| 6422 | I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) | |
| 6423 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6424 | } |
| 6425 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6426 | static void g4x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6427 | { |
| 6428 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6429 | uint32_t dspclk_gate; |
| 6430 | |
| 6431 | I915_WRITE(RENCLK_GATE_D1, 0); |
| 6432 | I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE | |
| 6433 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 6434 | CL_UNIT_CLOCK_GATE_DISABLE); |
| 6435 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6436 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 6437 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 6438 | OVCUNIT_CLOCK_GATE_DISABLE; |
| 6439 | if (IS_GM45(dev)) |
| 6440 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
| 6441 | I915_WRITE(DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 6442 | |
| 6443 | /* WaDisableRenderCachePipelinedFlush */ |
| 6444 | I915_WRITE(CACHE_MODE_0, |
| 6445 | _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE)); |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 6446 | |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6447 | /* WaDisable_RenderCache_OperationalFlush:g4x */ |
| 6448 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
| 6449 | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 6450 | g4x_disable_trickle_feed(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6451 | } |
| 6452 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6453 | static void crestline_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6454 | { |
| 6455 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6456 | |
| 6457 | I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 6458 | I915_WRITE(RENCLK_GATE_D2, 0); |
| 6459 | I915_WRITE(DSPCLK_GATE_D, 0); |
| 6460 | I915_WRITE(RAMCLK_GATE_D, 0); |
| 6461 | I915_WRITE16(DEUC, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6462 | I915_WRITE(MI_ARB_STATE, |
| 6463 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6464 | |
| 6465 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6466 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6467 | } |
| 6468 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6469 | static void broadwater_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6470 | { |
| 6471 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6472 | |
| 6473 | I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE | |
| 6474 | I965_RCC_CLOCK_GATE_DISABLE | |
| 6475 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 6476 | I965_ISC_CLOCK_GATE_DISABLE | |
| 6477 | I965_FBC_CLOCK_GATE_DISABLE); |
| 6478 | I915_WRITE(RENCLK_GATE_D2, 0); |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 6479 | I915_WRITE(MI_ARB_STATE, |
| 6480 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 6481 | |
| 6482 | /* WaDisable_RenderCache_OperationalFlush:gen4 */ |
| 6483 | I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6484 | } |
| 6485 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6486 | static void gen3_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6487 | { |
| 6488 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6489 | u32 dstate = I915_READ(D_STATE); |
| 6490 | |
| 6491 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 6492 | DSTATE_DOT_CLOCK_GATING; |
| 6493 | I915_WRITE(D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 6494 | |
| 6495 | if (IS_PINEVIEW(dev)) |
| 6496 | I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY)); |
Daniel Vetter | 974a3b0 | 2012-09-09 11:54:16 +0200 | [diff] [blame] | 6497 | |
| 6498 | /* IIR "flip pending" means done if this bit is set */ |
| 6499 | I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE)); |
Ville Syrjälä | 12fabbcb9 | 2014-02-25 15:13:38 +0200 | [diff] [blame] | 6500 | |
| 6501 | /* interrupts should cause a wake up from C3 */ |
Ville Syrjälä | 3299254 | 2014-02-25 15:13:39 +0200 | [diff] [blame] | 6502 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN)); |
Ville Syrjälä | dbb4274 | 2014-02-25 15:13:41 +0200 | [diff] [blame] | 6503 | |
| 6504 | /* On GEN3 we really need to make sure the ARB C3 LP bit is set */ |
| 6505 | 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] | 6506 | |
| 6507 | I915_WRITE(MI_ARB_STATE, |
| 6508 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6509 | } |
| 6510 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6511 | static void i85x_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6512 | { |
| 6513 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6514 | |
| 6515 | I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 54e472a | 2014-02-25 15:13:40 +0200 | [diff] [blame] | 6516 | |
| 6517 | /* interrupts should cause a wake up from C3 */ |
| 6518 | I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) | |
| 6519 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6520 | |
| 6521 | I915_WRITE(MEM_MODE, |
| 6522 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6523 | } |
| 6524 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6525 | static void i830_init_clock_gating(struct drm_device *dev) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6526 | { |
| 6527 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6528 | |
| 6529 | I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 6530 | |
| 6531 | I915_WRITE(MEM_MODE, |
| 6532 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 6533 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6534 | } |
| 6535 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6536 | void intel_init_clock_gating(struct drm_device *dev) |
| 6537 | { |
| 6538 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6539 | |
Damien Lespiau | c57e355 | 2015-02-09 19:33:05 +0000 | [diff] [blame] | 6540 | if (dev_priv->display.init_clock_gating) |
| 6541 | dev_priv->display.init_clock_gating(dev); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 6542 | } |
| 6543 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 6544 | void intel_suspend_hw(struct drm_device *dev) |
| 6545 | { |
| 6546 | if (HAS_PCH_LPT(dev)) |
| 6547 | lpt_suspend_hw(dev); |
| 6548 | } |
| 6549 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6550 | /* Set up chip specific power management-related functions */ |
| 6551 | void intel_init_pm(struct drm_device *dev) |
| 6552 | { |
| 6553 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6554 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 6555 | intel_fbc_init(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6556 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 6557 | /* For cxsr */ |
| 6558 | if (IS_PINEVIEW(dev)) |
| 6559 | i915_pineview_get_mem_freq(dev); |
| 6560 | else if (IS_GEN5(dev)) |
| 6561 | i915_ironlake_get_mem_freq(dev); |
| 6562 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6563 | /* For FIFO watermark updates */ |
Damien Lespiau | f5ed50c | 2014-11-13 17:51:52 +0000 | [diff] [blame] | 6564 | if (INTEL_INFO(dev)->gen >= 9) { |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 6565 | skl_setup_wm_latency(dev); |
| 6566 | |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 6567 | if (IS_BROXTON(dev)) |
| 6568 | dev_priv->display.init_clock_gating = |
| 6569 | bxt_init_clock_gating; |
| 6570 | else if (IS_SKYLAKE(dev)) |
| 6571 | dev_priv->display.init_clock_gating = |
| 6572 | skl_init_clock_gating; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 6573 | dev_priv->display.update_wm = skl_update_wm; |
| 6574 | dev_priv->display.update_sprite_wm = skl_update_sprite_wm; |
Damien Lespiau | c83155a | 2014-03-28 00:18:35 +0530 | [diff] [blame] | 6575 | } else if (HAS_PCH_SPLIT(dev)) { |
Damien Lespiau | fa50ad6 | 2014-03-17 18:01:16 +0000 | [diff] [blame] | 6576 | ilk_setup_wm_latency(dev); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 6577 | |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6578 | if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] && |
| 6579 | dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) || |
| 6580 | (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] && |
| 6581 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
| 6582 | dev_priv->display.update_wm = ilk_update_wm; |
| 6583 | dev_priv->display.update_sprite_wm = ilk_update_sprite_wm; |
| 6584 | } else { |
| 6585 | DRM_DEBUG_KMS("Failed to read display plane latency. " |
| 6586 | "Disable CxSR\n"); |
| 6587 | } |
| 6588 | |
| 6589 | if (IS_GEN5(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6590 | dev_priv->display.init_clock_gating = ironlake_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6591 | else if (IS_GEN6(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6592 | dev_priv->display.init_clock_gating = gen6_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6593 | else if (IS_IVYBRIDGE(dev)) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6594 | dev_priv->display.init_clock_gating = ivybridge_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6595 | else if (IS_HASWELL(dev)) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 6596 | dev_priv->display.init_clock_gating = haswell_init_clock_gating; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 6597 | else if (INTEL_INFO(dev)->gen == 8) |
Paulo Zanoni | 47c2bd9 | 2014-08-21 17:09:37 -0300 | [diff] [blame] | 6598 | dev_priv->display.init_clock_gating = broadwell_init_clock_gating; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6599 | } else if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 6600 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6601 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 6602 | dev_priv->display.init_clock_gating = |
| 6603 | cherryview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6604 | } else if (IS_VALLEYVIEW(dev)) { |
| 6605 | dev_priv->display.update_wm = valleyview_update_wm; |
Gajanan Bhat | 01e184c | 2014-08-07 17:03:30 +0530 | [diff] [blame] | 6606 | dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6607 | dev_priv->display.init_clock_gating = |
| 6608 | valleyview_init_clock_gating; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6609 | } else if (IS_PINEVIEW(dev)) { |
| 6610 | if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), |
| 6611 | dev_priv->is_ddr3, |
| 6612 | dev_priv->fsb_freq, |
| 6613 | dev_priv->mem_freq)) { |
| 6614 | DRM_INFO("failed to find known CxSR latency " |
| 6615 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 6616 | "disabling CxSR\n", |
| 6617 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 6618 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 6619 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 6620 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6621 | dev_priv->display.update_wm = NULL; |
| 6622 | } else |
| 6623 | dev_priv->display.update_wm = pineview_update_wm; |
| 6624 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
| 6625 | } else if (IS_G4X(dev)) { |
| 6626 | dev_priv->display.update_wm = g4x_update_wm; |
| 6627 | dev_priv->display.init_clock_gating = g4x_init_clock_gating; |
| 6628 | } else if (IS_GEN4(dev)) { |
| 6629 | dev_priv->display.update_wm = i965_update_wm; |
| 6630 | if (IS_CRESTLINE(dev)) |
| 6631 | dev_priv->display.init_clock_gating = crestline_init_clock_gating; |
| 6632 | else if (IS_BROADWATER(dev)) |
| 6633 | dev_priv->display.init_clock_gating = broadwater_init_clock_gating; |
| 6634 | } else if (IS_GEN3(dev)) { |
| 6635 | dev_priv->display.update_wm = i9xx_update_wm; |
| 6636 | dev_priv->display.get_fifo_size = i9xx_get_fifo_size; |
| 6637 | dev_priv->display.init_clock_gating = gen3_init_clock_gating; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6638 | } else if (IS_GEN2(dev)) { |
| 6639 | if (INTEL_INFO(dev)->num_pipes == 1) { |
| 6640 | dev_priv->display.update_wm = i845_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6641 | dev_priv->display.get_fifo_size = i845_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6642 | } else { |
| 6643 | dev_priv->display.update_wm = i9xx_update_wm; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6644 | dev_priv->display.get_fifo_size = i830_get_fifo_size; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | if (IS_I85X(dev) || IS_I865G(dev)) |
| 6648 | dev_priv->display.init_clock_gating = i85x_init_clock_gating; |
| 6649 | else |
| 6650 | dev_priv->display.init_clock_gating = i830_init_clock_gating; |
| 6651 | } else { |
| 6652 | DRM_ERROR("unexpected fall-through in intel_init_pm\n"); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 6653 | } |
| 6654 | } |
| 6655 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6656 | 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] | 6657 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6658 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6659 | |
| 6660 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6661 | DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n"); |
| 6662 | return -EAGAIN; |
| 6663 | } |
| 6664 | |
| 6665 | I915_WRITE(GEN6_PCODE_DATA, *val); |
Damien Lespiau | dddab34 | 2014-11-13 17:51:50 +0000 | [diff] [blame] | 6666 | I915_WRITE(GEN6_PCODE_DATA1, 0); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6667 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6668 | |
| 6669 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6670 | 500)) { |
| 6671 | DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox); |
| 6672 | return -ETIMEDOUT; |
| 6673 | } |
| 6674 | |
| 6675 | *val = I915_READ(GEN6_PCODE_DATA); |
| 6676 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6677 | |
| 6678 | return 0; |
| 6679 | } |
| 6680 | |
Tom O'Rourke | 151a49d | 2014-11-13 18:50:10 -0800 | [diff] [blame] | 6681 | 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] | 6682 | { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 6683 | WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock)); |
Ben Widawsky | 42c0526 | 2012-09-26 10:34:00 -0700 | [diff] [blame] | 6684 | |
| 6685 | if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) { |
| 6686 | DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n"); |
| 6687 | return -EAGAIN; |
| 6688 | } |
| 6689 | |
| 6690 | I915_WRITE(GEN6_PCODE_DATA, val); |
| 6691 | I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox); |
| 6692 | |
| 6693 | if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0, |
| 6694 | 500)) { |
| 6695 | DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox); |
| 6696 | return -ETIMEDOUT; |
| 6697 | } |
| 6698 | |
| 6699 | I915_WRITE(GEN6_PCODE_DATA, 0); |
| 6700 | |
| 6701 | return 0; |
| 6702 | } |
Jesse Barnes | a0e4e19 | 2013-04-02 11:23:05 -0700 | [diff] [blame] | 6703 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6704 | static int vlv_gpu_freq_div(unsigned int czclk_freq) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6705 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6706 | switch (czclk_freq) { |
| 6707 | case 200: |
| 6708 | return 10; |
| 6709 | case 267: |
| 6710 | return 12; |
| 6711 | case 320: |
| 6712 | case 333: |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6713 | return 16; |
Ville Syrjälä | ab3fb15 | 2014-11-10 22:55:15 +0200 | [diff] [blame] | 6714 | case 400: |
| 6715 | return 20; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6716 | default: |
| 6717 | return -1; |
| 6718 | } |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6719 | } |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6720 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6721 | static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6722 | { |
| 6723 | int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
| 6724 | |
| 6725 | div = vlv_gpu_freq_div(czclk_freq); |
| 6726 | if (div < 0) |
| 6727 | return div; |
| 6728 | |
| 6729 | return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div); |
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 byt_freq_opcode(struct drm_i915_private *dev_priv, int val) |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6733 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6734 | int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4); |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6735 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6736 | mul = vlv_gpu_freq_div(czclk_freq); |
| 6737 | if (mul < 0) |
| 6738 | return mul; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6739 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6740 | return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6; |
Jesse Barnes | 855ba3b | 2013-04-17 15:54:57 -0700 | [diff] [blame] | 6741 | } |
| 6742 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6743 | 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] | 6744 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6745 | int div, 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 | div = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6748 | if (div < 0) |
| 6749 | return div; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6750 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6751 | return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6752 | } |
| 6753 | |
Fengguang Wu | b55dd64 | 2014-07-12 11:21:39 +0200 | [diff] [blame] | 6754 | 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] | 6755 | { |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6756 | int mul, czclk_freq = dev_priv->rps.cz_freq; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6757 | |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6758 | mul = vlv_gpu_freq_div(czclk_freq) / 2; |
| 6759 | if (mul < 0) |
| 6760 | return mul; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6761 | |
Ville Syrjälä | 1c14762 | 2014-08-18 14:42:43 +0300 | [diff] [blame] | 6762 | /* CHV needs even values */ |
Ville Syrjälä | dd06f88 | 2014-11-10 22:55:12 +0200 | [diff] [blame] | 6763 | return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6764 | } |
| 6765 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6766 | int intel_gpu_freq(struct drm_i915_private *dev_priv, int val) |
| 6767 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6768 | if (IS_GEN9(dev_priv->dev)) |
| 6769 | return (val * GT_FREQUENCY_MULTIPLIER) / GEN9_FREQ_SCALER; |
| 6770 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6771 | return chv_gpu_freq(dev_priv, val); |
| 6772 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
| 6773 | return byt_gpu_freq(dev_priv, val); |
| 6774 | else |
| 6775 | return val * GT_FREQUENCY_MULTIPLIER; |
| 6776 | } |
| 6777 | |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6778 | int intel_freq_opcode(struct drm_i915_private *dev_priv, int val) |
| 6779 | { |
Akash Goel | 80b6dda | 2015-03-06 11:07:15 +0530 | [diff] [blame] | 6780 | if (IS_GEN9(dev_priv->dev)) |
| 6781 | return (val * GEN9_FREQ_SCALER) / GT_FREQUENCY_MULTIPLIER; |
| 6782 | else if (IS_CHERRYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6783 | return chv_freq_opcode(dev_priv, val); |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6784 | else if (IS_VALLEYVIEW(dev_priv->dev)) |
Ville Syrjälä | 616bc82 | 2015-01-23 21:04:25 +0200 | [diff] [blame] | 6785 | return byt_freq_opcode(dev_priv, val); |
| 6786 | else |
| 6787 | return val / GT_FREQUENCY_MULTIPLIER; |
Deepak S | 22b1b2f | 2014-07-12 14:54:33 +0530 | [diff] [blame] | 6788 | } |
| 6789 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6790 | void intel_pm_setup(struct drm_device *dev) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6791 | { |
| 6792 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6793 | |
Daniel Vetter | f742a55 | 2013-12-06 10:17:53 +0100 | [diff] [blame] | 6794 | mutex_init(&dev_priv->rps.hw_lock); |
| 6795 | |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6796 | INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work, |
| 6797 | intel_gen6_powersave_work); |
Paulo Zanoni | 5d584b2 | 2014-03-07 20:08:15 -0300 | [diff] [blame] | 6798 | |
Paulo Zanoni | 33688d9 | 2014-03-07 20:08:19 -0300 | [diff] [blame] | 6799 | dev_priv->pm.suspended = false; |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 6800 | } |